1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-06-27 16:36:03 +00:00

clean some remaining things up

This commit is contained in:
Lars Mueller 2025-04-02 15:40:06 +02:00
parent d1a46a8da5
commit cddd1a54f1
4 changed files with 17 additions and 29 deletions

View file

@ -306,8 +306,6 @@ public:
std::optional<std::string> Name; std::optional<std::string> Name;
//! Local transformation to be set by loaders. Mutated by animation. //! 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<core::Transform, core::matrix4>; using VariantTransform = std::variant<core::Transform, core::matrix4>;
VariantTransform transform{core::Transform{}}; VariantTransform transform{core::Transform{}};
@ -316,7 +314,10 @@ public:
return transform; return transform;
if (std::holds_alternative<core::matrix4>(transform)) { if (std::holds_alternative<core::matrix4>(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; core::Transform trs;
keys.updateTransform(frame, trs); keys.updateTransform(frame, trs);
return {trs}; return {trs};

View file

@ -15,18 +15,6 @@ struct Transform {
quaternion rotation; quaternion rotation;
vector3df scale{1}; 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 Transform interpolate(Transform to, f32 time) const
{ {
core::quaternion interpolated_rotation; core::quaternion interpolated_rotation;

View file

@ -4,7 +4,6 @@
#include "CAnimatedMeshSceneNode.h" #include "CAnimatedMeshSceneNode.h"
#include "CBoneSceneNode.h" #include "CBoneSceneNode.h"
#include "EDebugSceneTypes.h"
#include "IVideoDriver.h" #include "IVideoDriver.h"
#include "ISceneManager.h" #include "ISceneManager.h"
#include "S3DVertex.h" #include "S3DVertex.h"
@ -282,14 +281,15 @@ void CAnimatedMeshSceneNode::render()
if (DebugDataVisible & scene::EDS_SKELETON) { if (DebugDataVisible & scene::EDS_SKELETON) {
if (Mesh->getMeshType() == EAMT_SKINNED) { if (Mesh->getMeshType() == EAMT_SKINNED) {
// draw skeleton // draw skeleton
const auto &joints = (static_cast<SkinnedMesh *>(Mesh))->getAllJoints();
/*for (auto *joint : ((SkinnedMesh *)Mesh)->getAllJoints()) { for (u16 i = 0; i < PerJoint.GlobalMatrices.size(); ++i) {
for (const auto *childJoint : joint->Children) { const auto translation = PerJoint.GlobalMatrices[i].getTranslation();
driver->draw3DLine(joint->GlobalAnimatedMatrix.getTranslation(), if (auto pjid = joints[i]->ParentJointID) {
childJoint->GlobalAnimatedMatrix.getTranslation(), const auto parent_translation = PerJoint.GlobalMatrices[*pjid].getTranslation();
driver->draw3DLine(parent_translation, translation,
video::SColor(255, 51, 66, 255)); video::SColor(255, 51, 66, 255));
} }
}*/ }
} }
} }

View file

@ -13,7 +13,6 @@
#include "matrix4.h" #include "matrix4.h"
#include "os.h" #include "os.h"
#include "vector3d.h" #include "vector3d.h"
#include <cassert>
#include <cstddef> #include <cstddef>
#include <variant> #include <variant>
#include <vector> #include <vector>
@ -62,7 +61,7 @@ void SkinnedMesh::setAnimationSpeed(f32 fps)
using VariantTransform = SkinnedMesh::SJoint::VariantTransform; using VariantTransform = SkinnedMesh::SJoint::VariantTransform;
std::vector<VariantTransform> SkinnedMesh::animateMesh(f32 frame) std::vector<VariantTransform> SkinnedMesh::animateMesh(f32 frame)
{ {
assert(HasAnimation); _IRR_DEBUG_BREAK_IF(!HasAnimation);
std::vector<VariantTransform> result; std::vector<VariantTransform> result;
result.reserve(AllJoints.size()); result.reserve(AllJoints.size());
for (auto *joint : AllJoints) for (auto *joint : AllJoints)
@ -73,7 +72,7 @@ std::vector<VariantTransform> SkinnedMesh::animateMesh(f32 frame)
core::aabbox3df SkinnedMesh::calculateBoundingBox( core::aabbox3df SkinnedMesh::calculateBoundingBox(
const std::vector<core::matrix4> &global_transforms) const std::vector<core::matrix4> &global_transforms)
{ {
assert(global_transforms.size() == AllJoints.size()); _IRR_DEBUG_BREAK_IF(global_transforms.size() != AllJoints.size());
core::aabbox3df result = StaticPartsBox; core::aabbox3df result = StaticPartsBox;
// skeletal animation // skeletal animation
for (u16 i = 0; i < AllJoints.size(); ++i) { for (u16 i = 0; i < AllJoints.size(); ++i) {
@ -444,7 +443,7 @@ void SkinnedMesh::topoSortJoints()
for (u16 i = 0; i < n; ++i) { for (u16 i = 0; i < n; ++i) {
if (auto pjid = AllJoints[i]->ParentJointID) 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) void SkinnedMeshBuilder::addPositionKey(SJoint *joint, f32 frame, core::vector3df pos)
{ {
assert(joint); _IRR_DEBUG_BREAK_IF(!joint);
joint->keys.position.pushBack(frame, pos); joint->keys.position.pushBack(frame, pos);
} }
void SkinnedMeshBuilder::addScaleKey(SJoint *joint, f32 frame, core::vector3df scale) void SkinnedMeshBuilder::addScaleKey(SJoint *joint, f32 frame, core::vector3df scale)
{ {
assert(joint); _IRR_DEBUG_BREAK_IF(!joint);
joint->keys.scale.pushBack(frame, scale); joint->keys.scale.pushBack(frame, scale);
} }
void SkinnedMeshBuilder::addRotationKey(SJoint *joint, f32 frame, core::quaternion rot) void SkinnedMeshBuilder::addRotationKey(SJoint *joint, f32 frame, core::quaternion rot)
{ {
assert(joint); _IRR_DEBUG_BREAK_IF(!joint);
joint->keys.rotation.pushBack(frame, rot); joint->keys.rotation.pushBack(frame, rot);
} }