1
0
mirror of https://github.com/luanti-org/luanti.git synced 2025-11-08 03:05:18 +01:00

Refactor: Remove obsolete IAnimatedMeshSceneNode interface (#16631)

This commit is contained in:
Lars Müller
2025-10-30 17:34:45 +01:00
committed by GitHub
parent 4b41e20000
commit 1ead48c58b
22 changed files with 171 additions and 294 deletions

View File

@@ -0,0 +1,208 @@
// Copyright (C) 2002-2012 Nikolaus Gebhardt
// This file is part of the "Irrlicht Engine".
// For conditions of distribution and use, see copyright notice in irrlicht.h
#pragma once
#include "CBoneSceneNode.h"
#include "ISceneNode.h"
#include "IAnimatedMesh.h"
#include "SkinnedMesh.h"
#include "Transform.h"
#include "irr_ptr.h"
#include "matrix4.h"
namespace scene
{
class AnimatedMeshSceneNode : public ISceneNode
{
public:
//! constructor
AnimatedMeshSceneNode(IAnimatedMesh *mesh, ISceneNode *parent, ISceneManager *mgr, s32 id,
const core::vector3df &position = core::vector3df(0, 0, 0),
const core::vector3df &rotation = core::vector3df(0, 0, 0),
const core::vector3df &scale = core::vector3df(1.0f, 1.0f, 1.0f));
//! destructor
virtual ~AnimatedMeshSceneNode();
//! frame
void OnRegisterSceneNode() override;
//! OnAnimate() is called just before rendering the whole scene.
void OnAnimate(u32 timeMs) override;
//! renders the node.
void render() override;
//! returns the axis aligned bounding box of this node
const core::aabbox3d<f32> &getBoundingBox() const override;
//! returns the material based on the zero based index i. To get the amount
//! of materials used by this scene node, use getMaterialCount().
//! This function is needed for inserting the node into the scene hierarchy on a
//! optimal position for minimizing renderstate changes, but can also be used
//! to directly modify the material of a scene node.
video::SMaterial &getMaterial(u32 i) override;
//! returns amount of materials used by this scene node.
u32 getMaterialCount() const override;
//! Removes a child from this scene node.
//! Implemented here, to be able to remove the shadow properly, if there is one,
//! or to remove attached child.
bool removeChild(ISceneNode *child) override;
//! Returns type of the scene node
ESCENE_NODE_TYPE getType() const override { return ESNT_ANIMATED_MESH; }
//! Creates a clone of this scene node and its children.
/** \param newParent An optional new parent.
\param newManager An optional new scene manager.
\return The newly created clone of this node. */
ISceneNode *clone(ISceneNode *newParent = 0, ISceneManager *newManager = 0) override;
//! Sets the current frame number.
/** From now on the animation is played from this frame.
\param frame: Number of the frame to let the animation be started from.
The frame number must be a valid frame number of the IMesh used by this
scene node. Set IAnimatedMesh::getMesh() for details. */
void setCurrentFrame(f32 frame);
//! Sets the frame numbers between the animation is looped.
/** The default is 0 to getMaxFrameNumber() of the mesh.
Number of played frames is end-start.
It interpolates toward the last frame but stops when it is reached.
It does not interpolate back to start even when looping.
Looping animations should ensure last and first frame-key are identical.
\param begin: Start frame number of the loop.
\param end: End frame number of the loop.
\return True if successful, false if not. */
//! NOTE: setMesh will also change this value and set it to the full range of animations of the mesh
bool setFrameLoop(f32 begin, f32 end);
//! Sets looping mode which is on by default. If set to false,
//! animations will not be looped.
void setLoopMode(bool playAnimationLooped);
//! returns the current loop mode
bool getLoopMode() const;
//! Will be called right after the joints have been animated,
//! but before the transforms have been propagated recursively to children.
void setOnAnimateCallback(
const std::function<void(f32 dtime)> &cb)
{
OnAnimateCallback = cb;
}
//! Sets the speed with which the animation is played.
/** \param framesPerSecond: Frames per second played. */
void setAnimationSpeed(f32 framesPerSecond);
//! Gets the speed with which the animation is played.
/** \return Frames per second played. */
f32 getAnimationSpeed() const;
//! Returns a pointer to a child node (nullptr if not found),
//! which has the same transformation as
//! the corresponding joint, if the mesh in this scene node is a skinned mesh.
//! This can be used to attach children.
IBoneSceneNode *getJointNode(const c8 *jointName);
//! same as getJointNode(const c8* jointName), but based on id
IBoneSceneNode *getJointNode(u32 jointID);
//! Gets joint count.
u32 getJointCount() const;
//! Returns the currently displayed frame number.
f32 getFrameNr() const;
//! Returns the current start frame number.
f32 getStartFrame() const;
//! Returns the current end frame number.
f32 getEndFrame() const;
//! Sets if the scene node should not copy the materials of the mesh but use them in a read only style.
/* In this way it is possible to change the materials a mesh causing all mesh scene nodes
referencing this mesh to change too. */
void setReadOnlyMaterials(bool readonly);
//! Returns if the scene node should not copy the materials of the mesh but use them in a read only style
bool isReadOnlyMaterials() const;
//! Sets a new mesh
void setMesh(IAnimatedMesh *mesh);
//! Returns the current mesh
IAnimatedMesh *getMesh(void) { return Mesh; }
//! updates the absolute position based on the relative and the parents position
void updateAbsolutePosition() override;
//! Sets the transition time in seconds (note: This needs to enable joints)
//! you must call animateJoints(), or the mesh will not animate
void setTransitionTime(f32 Time);
void updateJointSceneNodes(const std::vector<SkinnedMesh::SJoint::VariantTransform> &transforms);
//! Updates the joint positions of this mesh, taking into accoutn transitions
void animateJoints();
void addJoints();
//! render mesh ignoring its transformation. Used with ragdolls. (culling is unaffected)
void setRenderFromIdentity(bool On);
private:
//! Get a static mesh for the current frame of this animated mesh
IMesh *getMeshForCurrentFrame();
void buildFrameNr(u32 timeMs);
void checkJoints();
void copyOldTransforms();
void beginTransition();
core::array<video::SMaterial> Materials;
core::aabbox3d<f32> Box{{0.0f, 0.0f, 0.0f}};
IAnimatedMesh *Mesh;
f32 StartFrame;
f32 EndFrame;
f32 FramesPerSecond;
f32 CurrentFrameNr;
u32 LastTimeMs;
u32 TransitionTime; // Transition time in millisecs
f32 Transiting; // is mesh transiting (plus cache of TransitionTime)
f32 TransitingBlend; // 0-1, calculated on buildFrameNr
bool JointsUsed;
bool Looping;
bool ReadOnlyMaterials;
bool RenderFromIdentity;
s32 PassCount;
std::function<void(f32)> OnAnimateCallback;
struct PerJointData {
std::vector<irr_ptr<CBoneSceneNode>> SceneNodes;
std::vector<core::matrix4> GlobalMatrices;
std::vector<std::optional<core::Transform>> PreTransSaves;
void setN(u16 n) {
SceneNodes.clear();
SceneNodes.resize(n);
GlobalMatrices.clear();
GlobalMatrices.resize(n);
PreTransSaves.clear();
PreTransSaves.resize(n);
}
};
PerJointData PerJoint;
};
} // end namespace scene

View File

@@ -0,0 +1,68 @@
// Copyright (C) 2002-2012 Nikolaus Gebhardt
// This file is part of the "Irrlicht Engine".
// For conditions of distribution and use, see copyright notice in irrlicht.h
#pragma once
// Used with SkinnedMesh and IAnimatedMeshSceneNode, for boned meshes
#include "IBoneSceneNode.h"
#include "Transform.h"
#include "matrix4.h"
#include <optional>
namespace scene
{
class CBoneSceneNode : public IBoneSceneNode
{
public:
//! constructor
CBoneSceneNode(ISceneNode *parent, ISceneManager *mgr,
s32 id = -1, u32 boneIndex = 0,
const std::optional<std::string> &boneName = std::nullopt,
const core::Transform &transform = {},
const std::optional<core::matrix4> &matrix = std::nullopt) :
IBoneSceneNode(parent, mgr, id, boneIndex, boneName),
Matrix(matrix)
{
setTransform(transform);
}
void setTransform(const core::Transform &transform)
{
setPosition(transform.translation);
{
core::vector3df euler;
auto rot = transform.rotation;
// Invert to be consistent with setRotationDegrees
rot.makeInverse();
rot.toEuler(euler);
setRotation(euler * core::RADTODEG);
}
setScale(transform.scale);
}
core::Transform getTransform() const
{
return {
getPosition(),
core::quaternion(getRotation() * core::DEGTORAD).makeInverse(),
getScale()
};
}
core::matrix4 getRelativeTransformation() const override
{
if (Matrix)
return *Matrix;
return IBoneSceneNode::getRelativeTransformation();
}
//! Some file formats alternatively let bones specify a transformation matrix.
//! If this is set, it overrides the TRS properties.
std::optional<core::matrix4> Matrix;
};
} // end namespace scene

View File

@@ -1,133 +0,0 @@
// Copyright (C) 2002-2012 Nikolaus Gebhardt
// This file is part of the "Irrlicht Engine".
// For conditions of distribution and use, see copyright notice in irrlicht.h
#pragma once
#include "ISceneNode.h"
#include "IBoneSceneNode.h"
#include "IAnimatedMesh.h"
namespace scene
{
class IAnimatedMeshSceneNode;
//! Scene node capable of displaying an animated mesh.
class IAnimatedMeshSceneNode : public ISceneNode
{
public:
//! Constructor
IAnimatedMeshSceneNode(ISceneNode *parent, ISceneManager *mgr, s32 id,
const core::vector3df &position = core::vector3df(0, 0, 0),
const core::vector3df &rotation = core::vector3df(0, 0, 0),
const core::vector3df &scale = core::vector3df(1.0f, 1.0f, 1.0f)) :
ISceneNode(parent, mgr, id, position, rotation, scale) {}
//! Destructor
virtual ~IAnimatedMeshSceneNode() {}
//! Sets the current frame number.
/** From now on the animation is played from this frame.
\param frame: Number of the frame to let the animation be started from.
The frame number must be a valid frame number of the IMesh used by this
scene node. Set IAnimatedMesh::getMesh() for details. */
virtual void setCurrentFrame(f32 frame) = 0;
//! Sets the frame numbers between the animation is looped.
/** The default is 0 to getMaxFrameNumber() of the mesh.
Number of played frames is end-start.
It interpolates toward the last frame but stops when it is reached.
It does not interpolate back to start even when looping.
Looping animations should ensure last and first frame-key are identical.
\param begin: Start frame number of the loop.
\param end: End frame number of the loop.
\return True if successful, false if not. */
virtual bool setFrameLoop(f32 begin, f32 end) = 0;
//! Sets the speed with which the animation is played.
/** \param framesPerSecond: Frames per second played. */
virtual void setAnimationSpeed(f32 framesPerSecond) = 0;
//! Gets the speed with which the animation is played.
/** \return Frames per second played. */
virtual f32 getAnimationSpeed() const = 0;
//! Get a pointer to a joint in the mesh (if the mesh is a bone based mesh).
/** With this method it is possible to attach scene nodes to
joints for example possible to attach a weapon to the left hand
of an animated model. This example shows how:
\code
ISceneNode* hand =
yourAnimatedMeshSceneNode->getJointNode("LeftHand");
hand->addChild(weaponSceneNode);
\endcode
Please note that the joint returned by this method may not exist
before this call and the joints in the node were created by it.
\param jointName: Name of the joint.
\return Pointer to the scene node which represents the joint
with the specified name. Returns 0 if the contained mesh is not
an skinned mesh or the name of the joint could not be found. */
virtual IBoneSceneNode *getJointNode(const c8 *jointName) = 0;
//! same as getJointNode(const c8* jointName), but based on id
virtual IBoneSceneNode *getJointNode(u32 jointID) = 0;
//! Gets joint count.
/** \return Amount of joints in the mesh. */
virtual u32 getJointCount() const = 0;
//! Returns the currently displayed frame number.
virtual f32 getFrameNr() const = 0;
//! Returns the current start frame number.
virtual f32 getStartFrame() const = 0;
//! Returns the current end frame number.
virtual f32 getEndFrame() const = 0;
//! Sets looping mode which is on by default.
/** If set to false, animations will not be played looped. */
virtual void setLoopMode(bool playAnimationLooped) = 0;
//! returns the current loop mode
/** When true the animations are played looped */
virtual bool getLoopMode() const = 0;
//! Will be called right after the joints have been animated,
//! but before the transforms have been propagated recursively to children.
virtual void setOnAnimateCallback(
const std::function<void(f32 dtime)> &cb) = 0;
//! Sets if the scene node should not copy the materials of the mesh but use them in a read only style.
/** In this way it is possible to change the materials a mesh
causing all mesh scene nodes referencing this mesh to change
too. */
virtual void setReadOnlyMaterials(bool readonly) = 0;
//! Returns if the scene node should not copy the materials of the mesh but use them in a read only style
virtual bool isReadOnlyMaterials() const = 0;
//! Sets a new mesh
virtual void setMesh(IAnimatedMesh *mesh) = 0;
//! Returns the current mesh
virtual IAnimatedMesh *getMesh() = 0;
//! Sets the transition time in seconds
/** Note: You must call animateJoints(), or the mesh will not animate. */
virtual void setTransitionTime(f32 Time) = 0;
//! animates the joints in the mesh based on the current frame.
/** Also takes in to account transitions. */
virtual void animateJoints() = 0;
//! render mesh ignoring its transformation.
/** Culling is unaffected. */
virtual void setRenderFromIdentity(bool On) = 0;
//! Creates a clone of this scene node and its children.
/** \param newParent An optional new parent.
\param newManager An optional new scene manager.
\return The newly created clone of this node. */
virtual ISceneNode *clone(ISceneNode *newParent = 0, ISceneManager *newManager = 0) = 0;
};
} // end namespace scene

View File

@@ -10,7 +10,7 @@ namespace scene
{
//! Interface for bones used for skeletal animation.
/** Used with SkinnedMesh and IAnimatedMeshSceneNode. */
/** Used with SkinnedMesh and AnimatedMeshSceneNode. */
class IBoneSceneNode : public ISceneNode
{
public:

View File

@@ -14,7 +14,7 @@ namespace scene
set/getRotation and set/getScale. Its just a simple scene node that takes a
matrix as relative transformation, making it possible to insert any transformation
anywhere into the scene graph.
This scene node is for example used by the IAnimatedMeshSceneNode for emulating
This scene node is for example used by the AnimatedMeshSceneNode for emulating
joint scene nodes when playing skeletal animations.
*/
class IDummyTransformationSceneNode : public ISceneNode

View File

@@ -71,7 +71,7 @@ enum E_SCENE_NODE_RENDER_PASS
};
class IAnimatedMesh;
class IAnimatedMeshSceneNode;
class AnimatedMeshSceneNode;
class IBillboardSceneNode;
class ICameraSceneNode;
class IDummyTransformationSceneNode;
@@ -133,7 +133,7 @@ public:
\param alsoAddIfMeshPointerZero: Add the scene node even if a 0 pointer is passed.
\return Pointer to the created scene node.
This pointer should not be dropped. See IReferenceCounted::drop() for more information. */
virtual IAnimatedMeshSceneNode *addAnimatedMeshSceneNode(IAnimatedMesh *mesh,
virtual AnimatedMeshSceneNode *addAnimatedMeshSceneNode(IAnimatedMesh *mesh,
ISceneNode *parent = 0, s32 id = -1,
const core::vector3df &position = core::vector3df(0, 0, 0),
const core::vector3df &rotation = core::vector3df(0, 0, 0),

View File

@@ -24,7 +24,7 @@
namespace scene
{
class IAnimatedMeshSceneNode;
class AnimatedMeshSceneNode;
class IBoneSceneNode;
class ISceneManager;
@@ -151,7 +151,7 @@ public:
//! Creates an array of joints from this mesh as children of node
std::vector<IBoneSceneNode *> addJoints(
IAnimatedMeshSceneNode *node, ISceneManager *smgr);
AnimatedMeshSceneNode *node, ISceneManager *smgr);
//! A vertex weight
struct SWeight