1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-06-27 16:36:03 +00:00
This commit is contained in:
Lars Mueller 2025-01-18 17:41:48 +01:00
parent abc2e54c07
commit a687a7a6e7
2 changed files with 72 additions and 63 deletions

View file

@ -163,9 +163,7 @@ IMesh *CAnimatedMeshSceneNode::getMeshForCurrentFrame()
SkinnedMesh *skinnedMesh = static_cast<SkinnedMesh *>(Mesh); SkinnedMesh *skinnedMesh = static_cast<SkinnedMesh *>(Mesh);
skinnedMesh->animateMesh(getFrameNr()); skinnedMesh->transferJointsToMesh(JointChildSceneNodes);
// skinnedMesh->transferJointsToMesh(JointChildSceneNodes);
// Update the skinned mesh for the current joint transforms. // Update the skinned mesh for the current joint transforms.
skinnedMesh->skinMesh(); skinnedMesh->skinMesh();
@ -174,8 +172,6 @@ IMesh *CAnimatedMeshSceneNode::getMeshForCurrentFrame()
Box = skinnedMesh->getBoundingBox(); Box = skinnedMesh->getBoundingBox();
setAutomaticCulling(EAC_OFF);
return skinnedMesh; return skinnedMesh;
} }
} }
@ -238,7 +234,6 @@ void CAnimatedMeshSceneNode::render()
driver->setTransform(video::ETS_WORLD, AbsoluteTransformation); driver->setTransform(video::ETS_WORLD, AbsoluteTransformation);
// for debug purposes only: // for debug purposes only:
// DebugDataVisible = ~0;
if (DebugDataVisible && PassCount == 1) { if (DebugDataVisible && PassCount == 1) {
video::SMaterial debug_mat; video::SMaterial debug_mat;
debug_mat.AntiAliasing = video::EAAM_OFF; debug_mat.AntiAliasing = video::EAAM_OFF;
@ -513,18 +508,15 @@ void CAnimatedMeshSceneNode::setMesh(IAnimatedMesh *mesh)
// get materials and bounding box // get materials and bounding box
Box = Mesh->getBoundingBox(); Box = Mesh->getBoundingBox();
IMesh *m = Mesh->getMesh(0); Materials.clear();
if (m) { Materials.reallocate(Mesh->getMeshBufferCount());
Materials.clear();
Materials.reallocate(m->getMeshBufferCount());
for (u32 i = 0; i < m->getMeshBufferCount(); ++i) { for (u32 i = 0; i < Mesh->getMeshBufferCount(); ++i) {
IMeshBuffer *mb = m->getMeshBuffer(i); IMeshBuffer *mb = Mesh->getMeshBuffer(i);
if (mb) if (mb)
Materials.push_back(mb->getMaterial()); Materials.push_back(mb->getMaterial());
else else
Materials.push_back(video::SMaterial()); Materials.push_back(video::SMaterial());
}
} }
// clean up joint nodes // clean up joint nodes
@ -563,58 +555,58 @@ void CAnimatedMeshSceneNode::setRenderFromIdentity(bool enable)
//! updates the joint positions of this mesh //! updates the joint positions of this mesh
void CAnimatedMeshSceneNode::animateJoints() void CAnimatedMeshSceneNode::animateJoints()
{ {
if (Mesh && Mesh->getMeshType() == EAMT_SKINNED) { if (!Mesh || Mesh->getMeshType() != EAMT_SKINNED)
checkJoints(); return;
const f32 frame = getFrameNr(); // old?
SkinnedMesh *skinnedMesh = static_cast<SkinnedMesh *>(Mesh); checkJoints();
skinnedMesh->animateMesh(frame); SkinnedMesh *skinnedMesh = static_cast<SkinnedMesh *>(Mesh);
skinnedMesh->recoverJointsFromMesh(JointChildSceneNodes);
//----------------------------------------- skinnedMesh->animateMesh(getFrameNr());
// Transition skinnedMesh->recoverJointsFromMesh(JointChildSceneNodes);
//-----------------------------------------
if (Transiting != 0.f) { //-----------------------------------------
// Init additional matrices // Transition
if (PretransitingSave.size() < JointChildSceneNodes.size()) { //-----------------------------------------
for (u32 n = PretransitingSave.size(); n < JointChildSceneNodes.size(); ++n)
PretransitingSave.push_back(core::matrix4());
}
for (u32 n = 0; n < JointChildSceneNodes.size(); ++n) { if (Transiting != 0.f) {
//------Position------ // Init additional matrices
if (PretransitingSave.size() < JointChildSceneNodes.size()) {
for (u32 n = PretransitingSave.size(); n < JointChildSceneNodes.size(); ++n)
PretransitingSave.push_back(core::matrix4());
}
JointChildSceneNodes[n]->setPosition( for (u32 n = 0; n < JointChildSceneNodes.size(); ++n) {
core::lerp( //------Position------
PretransitingSave[n].getTranslation(),
JointChildSceneNodes[n]->getPosition(),
TransitingBlend));
//------Rotation------ JointChildSceneNodes[n]->setPosition(
core::lerp(
PretransitingSave[n].getTranslation(),
JointChildSceneNodes[n]->getPosition(),
TransitingBlend));
// Code is slow, needs to be fixed up //------Rotation------
const core::quaternion RotationStart(PretransitingSave[n].getRotationRadians()); // Code is slow, needs to be fixed up
const core::quaternion RotationEnd(JointChildSceneNodes[n]->getRotation() * core::DEGTORAD);
core::quaternion QRotation; const core::quaternion RotationStart(PretransitingSave[n].getRotationDegrees() * core::DEGTORAD);
QRotation.slerp(RotationStart, RotationEnd, TransitingBlend); const core::quaternion RotationEnd(JointChildSceneNodes[n]->getRotation() * core::DEGTORAD);
core::vector3df tmpVector; core::quaternion QRotation;
QRotation.toEuler(tmpVector); QRotation.slerp(RotationStart, RotationEnd, TransitingBlend);
tmpVector *= core::RADTODEG; // convert from radians back to degrees
JointChildSceneNodes[n]->setRotation(tmpVector);
//------Scale------ core::vector3df tmpVector;
QRotation.toEuler(tmpVector);
tmpVector *= core::RADTODEG; // convert from radians back to degrees
JointChildSceneNodes[n]->setRotation(tmpVector);
// JointChildSceneNodes[n]->setScale( //------Scale------
// core::lerp(
// PretransitingSave[n].getScale(), // JointChildSceneNodes[n]->setScale(
// JointChildSceneNodes[n]->getScale(), // core::lerp(
// TransitingBlend)); // PretransitingSave[n].getScale(),
} // JointChildSceneNodes[n]->getScale(),
// TransitingBlend));
} }
} }
} }

View file

@ -636,11 +636,25 @@ void SkinnedMesh::recoverJointsFromMesh(std::vector<IBoneSceneNode *> &jointChil
for (u32 i = 0; i < AllJoints.size(); ++i) { for (u32 i = 0; i < AllJoints.size(); ++i) {
IBoneSceneNode *node = jointChildSceneNodes[i]; IBoneSceneNode *node = jointChildSceneNodes[i];
SJoint *joint = AllJoints[i]; SJoint *joint = AllJoints[i];
node->setPosition(joint->LocalAnimatedMatrix.getTranslation()); if (std::holds_alternative<SJoint::Transform>(joint->transform)) {
node->setRotation(joint->LocalAnimatedMatrix.getRotationDegrees()); auto transform = std::get<SJoint::Transform>(joint->transform);
node->setScale(joint->LocalAnimatedMatrix.getScale()); node->setPosition(transform.translation);
{
core::vector3df euler;
auto rot = transform.rotation;
// Invert to be consistent with setRotationDegrees
rot.makeInverse();
rot.toEuler(euler);
node->setRotation(euler * core::RADTODEG);
}
node->setScale(transform.scale);
} else {
node->setPosition(joint->LocalAnimatedMatrix.getTranslation());
node->setRotation(joint->LocalAnimatedMatrix.getRotationDegrees());
node->setScale(joint->LocalAnimatedMatrix.getScale());
}
node->updateAbsolutePosition(); // WTF // node->updateAbsolutePosition(); // WTF
} }
} }
@ -650,9 +664,12 @@ void SkinnedMesh::transferJointsToMesh(const std::vector<IBoneSceneNode *> &join
const IBoneSceneNode *const node = jointChildSceneNodes[i]; const IBoneSceneNode *const node = jointChildSceneNodes[i];
SJoint *joint = AllJoints[i]; SJoint *joint = AllJoints[i];
joint->LocalAnimatedMatrix.setRotationDegrees(node->getRotation()); if (std::holds_alternative<SJoint::Transform>(joint->transform)) {
joint->LocalAnimatedMatrix.setTranslation(node->getPosition()); joint->LocalAnimatedMatrix = core::matrix4();
joint->LocalAnimatedMatrix *= core::matrix4().setScale(node->getScale()); joint->LocalAnimatedMatrix.setRotationDegrees(node->getRotation());
joint->LocalAnimatedMatrix.setTranslation(node->getPosition());
joint->LocalAnimatedMatrix *= core::matrix4().setScale(node->getScale());
}
} }
// Make sure we recalc the next frame // Make sure we recalc the next frame
LastAnimatedFrame = -1; LastAnimatedFrame = -1;