1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-07-27 17:28:41 +00:00
This commit is contained in:
Lars Mueller 2025-01-16 17:13:59 +01:00
parent 769c472ceb
commit abc2e54c07
16 changed files with 137 additions and 224 deletions

View file

@ -135,7 +135,7 @@ public:
//! animates the joints in the mesh based on the current frame.
/** Also takes in to account transitions. */
virtual void animateJoints(bool CalculateAbsolutePositions = true) = 0;
virtual void animateJoints() = 0;
//! render mesh ignoring its transformation.
/** Culling is unaffected. */

View file

@ -28,15 +28,9 @@ public:
//! Returns the relative transformation of the scene node.
// virtual core::matrix4 getRelativeTransformation() const = 0;
//! The animation method.
void OnAnimate(u32 timeMs) override = 0;
//! The render method.
/** Does nothing as bones are not visible. */
void render() override {}
//! Updates the absolute position based on the relative and the parents position
virtual void updateAbsolutePositionOfAllChildren() = 0;
};
} // end namespace scene

View file

@ -94,16 +94,12 @@ public:
\param timeMs Current time in milliseconds. */
virtual void OnAnimate(u32 timeMs)
{
if (IsVisible) {
// update absolute position
updateAbsolutePosition();
if (!IsVisible && Children.empty())
return;
// perform the post render process on all children
ISceneNodeList::iterator it = Children.begin();
for (; it != Children.end(); ++it)
(*it)->OnAnimate(timeMs);
}
updateAbsolutePosition();
for (auto *child : Children)
child->OnAnimate(timeMs);
}
//! Renders the node.

View file

@ -8,11 +8,14 @@
#include "ISceneManager.h"
#include "SMeshBuffer.h"
#include "SSkinMeshBuffer.h"
#include "irrMath.h"
#include "matrix4.h"
#include "quaternion.h"
#include "vector3d.h"
#include <optional>
#include <string>
#include <variant>
namespace irr
{
@ -314,8 +317,56 @@ public:
//! The name of this joint
std::optional<std::string> Name;
//! Local matrix of this joint
core::matrix4 LocalMatrix;
struct Transform {
core::vector3df translation;
core::quaternion rotation;
core::vector3df scale{1};
core::matrix4 buildMatrix() const {
core::matrix4 T;
T.setTranslation(translation);
core::matrix4 R;
rotation.getMatrix_transposed(R);
core::matrix4 S;
S.setScale(scale);
return T * R * S;
}
};
//! 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!
std::variant<core::matrix4, Transform> transform = Transform{};
Transform &getAnimatableTransform() {
if (std::holds_alternative<Transform>(transform))
return std::get<Transform>(transform);
const auto &mat = std::get<core::matrix4>(transform);
Transform trs;
trs.translation = mat.getTranslation();
trs.scale = mat.getScale();
trs.rotation = core::quaternion(
mat.getRotationDegrees(trs.scale) * core::DEGTORAD);
transform = trs;
// TODO raise a warning if the recomposed matrix does not equal the decomposed.
return std::get<Transform>(transform);
}
void animate(f32 frame) {
if (keys.empty())
return;
auto &transform = getAnimatableTransform();
keys.updateTransform(frame,
transform.translation,
transform.rotation,
transform.scale);
}
core::matrix4 buildLocalMatrix() const {
if (std::holds_alternative<core::matrix4>(transform))
return std::get<core::matrix4>(transform);
return std::get<Transform>(transform).buildMatrix();
}
//! List of child joints
std::vector<SJoint *> Children;
@ -334,11 +385,6 @@ public:
core::matrix4 GlobalAnimatedMatrix;
core::matrix4 LocalAnimatedMatrix;
//! These should be set by loaders.
core::vector3df Animatedposition;
core::vector3df Animatedscale;
core::quaternion Animatedrotation;
// The .x and .gltf formats pre-calculate this
std::optional<core::matrix4> GlobalInversedMatrix;
private: