@@ -18,7 +18,20 @@ namespace scene
1818/* * Used with SkinnedMesh and AnimatedMeshSceneNode. */
1919class BoneSceneNode : public ISceneNode
2020{
21+ private:
22+
23+ // ! For performance reasons, we prefer to store the rotation as quaternion
24+ // ! to avoid expensive conversions back and forth between Euler angles and quaternions.
25+ core::quaternion Rotation;
26+
27+ const u32 BoneIndex;
28+
2129public:
30+
31+ // ! Some file formats alternatively let bones specify a transformation matrix.
32+ // ! If this is set, it overrides the TRS properties.
33+ std::optional<core::matrix4> Matrix;
34+
2235 BoneSceneNode (ISceneNode *parent,
2336 ISceneManager *mgr,
2437 s32 id = -1 ,
@@ -27,8 +40,8 @@ class BoneSceneNode : public ISceneNode
2740 const core::Transform &transform = {},
2841 const std::optional<core::matrix4> &matrix = std::nullopt ) :
2942 ISceneNode (parent, mgr, id),
30- Matrix (matrix ),
31- BoneIndex (boneIndex )
43+ BoneIndex (boneIndex ),
44+ Matrix (matrix )
3245 {
3346 setName (boneName);
3447 setTransform (transform);
@@ -52,25 +65,32 @@ class BoneSceneNode : public ISceneNode
5265 /* * Does nothing as bones are not visible. */
5366 void render () override {}
5467
68+ void setRotation (const core::vector3df &rotation) override
69+ {
70+ Rotation = core::quaternion (rotation * core::DEGTORAD).makeInverse ();
71+ }
72+
73+ core::vector3df getRotation () const override
74+ {
75+ auto rot = Rotation;
76+ rot.makeInverse ();
77+ core::vector3df euler;
78+ rot.toEuler (euler);
79+ return euler * core::RADTODEG;
80+ }
81+
5582 void setTransform (const core::Transform &transform)
5683 {
5784 setPosition (transform.translation );
58- {
59- core::vector3df euler;
60- auto rot = transform.rotation ;
61- // Invert to be consistent with setRotationDegrees
62- rot.makeInverse ();
63- rot.toEuler (euler);
64- setRotation (euler * core::RADTODEG);
65- }
85+ Rotation = transform.rotation ;
6686 setScale (transform.scale );
6787 }
6888
6989 core::Transform getTransform () const
7090 {
7191 return {
7292 getPosition (),
73- core::quaternion ( getRotation () * core::DEGTORAD). makeInverse () ,
93+ Rotation ,
7494 getScale ()
7595 };
7696 }
@@ -79,16 +99,8 @@ class BoneSceneNode : public ISceneNode
7999 {
80100 if (Matrix)
81101 return *Matrix;
82- return ISceneNode::getRelativeTransformation ();
102+ return getTransform (). buildMatrix ();
83103 }
84-
85- // ! Some file formats alternatively let bones specify a transformation matrix.
86- // ! If this is set, it overrides the TRS properties.
87- std::optional<core::matrix4> Matrix;
88-
89- private:
90-
91- const u32 BoneIndex;
92104};
93105
94106} // end namespace scene
0 commit comments