diff --git a/irr/include/SkinnedMesh.h b/irr/include/SkinnedMesh.h index 88caaf616..73d70dc8a 100644 --- a/irr/include/SkinnedMesh.h +++ b/irr/include/SkinnedMesh.h @@ -306,8 +306,6 @@ public: std::optional Name; //! Local transformation to be set by loaders. Mutated by animation. - //! If a matrix is used, this joint **must not** be animated, - //! because then the unique decomposition into translation, rotation and scale need not exist! using VariantTransform = std::variant; VariantTransform transform{core::Transform{}}; @@ -316,7 +314,10 @@ public: return transform; if (std::holds_alternative(transform)) { - // .x lets animations override matrix transforms entirely. + // .x lets animations override matrix transforms entirely, + // which is what we implement here. + // .gltf does not allow animation of nodes using matrix transforms. + // Note that a decomposition into a TRS transform need not exist! core::Transform trs; keys.updateTransform(frame, trs); return {trs}; diff --git a/irr/include/Transform.h b/irr/include/Transform.h index 522992443..1e96e183d 100644 --- a/irr/include/Transform.h +++ b/irr/include/Transform.h @@ -15,18 +15,6 @@ struct Transform { quaternion rotation; vector3df scale{1}; - // Tries to decompose the matrix, if there is one. - static Transform decompose(const core::matrix4 &mat) - { - auto scale = mat.getScale(); - return { - mat.getTranslation(), - quaternion(mat.getRotationRadians(scale)), - scale, - }; - } - - Transform interpolate(Transform to, f32 time) const { core::quaternion interpolated_rotation; diff --git a/irr/src/CAnimatedMeshSceneNode.cpp b/irr/src/CAnimatedMeshSceneNode.cpp index e5d9949a3..1b51b2585 100644 --- a/irr/src/CAnimatedMeshSceneNode.cpp +++ b/irr/src/CAnimatedMeshSceneNode.cpp @@ -4,7 +4,6 @@ #include "CAnimatedMeshSceneNode.h" #include "CBoneSceneNode.h" -#include "EDebugSceneTypes.h" #include "IVideoDriver.h" #include "ISceneManager.h" #include "S3DVertex.h" @@ -282,14 +281,15 @@ void CAnimatedMeshSceneNode::render() if (DebugDataVisible & scene::EDS_SKELETON) { if (Mesh->getMeshType() == EAMT_SKINNED) { // draw skeleton - - /*for (auto *joint : ((SkinnedMesh *)Mesh)->getAllJoints()) { - for (const auto *childJoint : joint->Children) { - driver->draw3DLine(joint->GlobalAnimatedMatrix.getTranslation(), - childJoint->GlobalAnimatedMatrix.getTranslation(), + const auto &joints = (static_cast(Mesh))->getAllJoints(); + for (u16 i = 0; i < PerJoint.GlobalMatrices.size(); ++i) { + const auto translation = PerJoint.GlobalMatrices[i].getTranslation(); + if (auto pjid = joints[i]->ParentJointID) { + const auto parent_translation = PerJoint.GlobalMatrices[*pjid].getTranslation(); + driver->draw3DLine(parent_translation, translation, video::SColor(255, 51, 66, 255)); } - }*/ + } } } diff --git a/irr/src/SkinnedMesh.cpp b/irr/src/SkinnedMesh.cpp index cf58121ba..87e4a8d78 100644 --- a/irr/src/SkinnedMesh.cpp +++ b/irr/src/SkinnedMesh.cpp @@ -13,7 +13,6 @@ #include "matrix4.h" #include "os.h" #include "vector3d.h" -#include #include #include #include @@ -62,7 +61,7 @@ void SkinnedMesh::setAnimationSpeed(f32 fps) using VariantTransform = SkinnedMesh::SJoint::VariantTransform; std::vector SkinnedMesh::animateMesh(f32 frame) { - assert(HasAnimation); + _IRR_DEBUG_BREAK_IF(!HasAnimation); std::vector result; result.reserve(AllJoints.size()); for (auto *joint : AllJoints) @@ -73,7 +72,7 @@ std::vector SkinnedMesh::animateMesh(f32 frame) core::aabbox3df SkinnedMesh::calculateBoundingBox( const std::vector &global_transforms) { - assert(global_transforms.size() == AllJoints.size()); + _IRR_DEBUG_BREAK_IF(global_transforms.size() != AllJoints.size()); core::aabbox3df result = StaticPartsBox; // skeletal animation for (u16 i = 0; i < AllJoints.size(); ++i) { @@ -444,7 +443,7 @@ void SkinnedMesh::topoSortJoints() for (u16 i = 0; i < n; ++i) { if (auto pjid = AllJoints[i]->ParentJointID) - assert(*pjid < i); + _IRR_DEBUG_BREAK_IF(*pjid >= i); } } @@ -518,19 +517,19 @@ SkinnedMesh::SJoint *SkinnedMeshBuilder::addJoint(SJoint *parent) void SkinnedMeshBuilder::addPositionKey(SJoint *joint, f32 frame, core::vector3df pos) { - assert(joint); + _IRR_DEBUG_BREAK_IF(!joint); joint->keys.position.pushBack(frame, pos); } void SkinnedMeshBuilder::addScaleKey(SJoint *joint, f32 frame, core::vector3df scale) { - assert(joint); + _IRR_DEBUG_BREAK_IF(!joint); joint->keys.scale.pushBack(frame, scale); } void SkinnedMeshBuilder::addRotationKey(SJoint *joint, f32 frame, core::quaternion rot) { - assert(joint); + _IRR_DEBUG_BREAK_IF(!joint); joint->keys.rotation.pushBack(frame, rot); }