1 // Copyright (C) 2002-2012 Nikolaus Gebhardt
\r
2 // This file is part of the "Irrlicht Engine".
\r
3 // For conditions of distribution and use, see copyright notice in irrlicht.h
\r
5 #ifndef __C_ANIMATED_MESH_SCENE_NODE_H_INCLUDED__
\r
6 #define __C_ANIMATED_MESH_SCENE_NODE_H_INCLUDED__
\r
8 #include "IAnimatedMeshSceneNode.h"
\r
9 #include "IAnimatedMesh.h"
\r
11 #include "matrix4.h"
\r
18 class IDummyTransformationSceneNode;
\r
20 class CAnimatedMeshSceneNode : public IAnimatedMeshSceneNode
\r
25 CAnimatedMeshSceneNode(IAnimatedMesh* mesh, ISceneNode* parent, ISceneManager* mgr, s32 id,
\r
26 const core::vector3df& position = core::vector3df(0,0,0),
\r
27 const core::vector3df& rotation = core::vector3df(0,0,0),
\r
28 const core::vector3df& scale = core::vector3df(1.0f, 1.0f, 1.0f));
\r
31 virtual ~CAnimatedMeshSceneNode();
\r
33 //! sets the current frame. from now on the animation is played from this frame.
\r
34 void setCurrentFrame(f32 frame) override;
\r
37 void OnRegisterSceneNode() override;
\r
39 //! OnAnimate() is called just before rendering the whole scene.
\r
40 void OnAnimate(u32 timeMs) override;
\r
42 //! renders the node.
\r
43 void render() override;
\r
45 //! returns the axis aligned bounding box of this node
\r
46 const core::aabbox3d<f32>& getBoundingBox() const override;
\r
48 //! sets the frames between the animation is looped.
\r
49 //! the default is 0 - MaximalFrameCount of the mesh.
\r
50 //! NOTE: setMesh will also change this value and set it to the full range of animations of the mesh
\r
51 bool setFrameLoop(s32 begin, s32 end) override;
\r
53 //! Sets looping mode which is on by default. If set to false,
\r
54 //! animations will not be looped.
\r
55 void setLoopMode(bool playAnimationLooped) override;
\r
57 //! returns the current loop mode
\r
58 bool getLoopMode() const override;
\r
60 //! Sets a callback interface which will be called if an animation
\r
61 //! playback has ended. Set this to 0 to disable the callback again.
\r
62 void setAnimationEndCallback(IAnimationEndCallBack* callback=0) override;
\r
64 //! sets the speed with which the animation is played
\r
65 //! NOTE: setMesh will also change this value and set it to the default speed of the mesh
\r
66 void setAnimationSpeed(f32 framesPerSecond) override;
\r
68 //! gets the speed with which the animation is played
\r
69 f32 getAnimationSpeed() const override;
\r
71 //! returns the material based on the zero based index i. To get the amount
\r
72 //! of materials used by this scene node, use getMaterialCount().
\r
73 //! This function is needed for inserting the node into the scene hierarchy on a
\r
74 //! optimal position for minimizing renderstate changes, but can also be used
\r
75 //! to directly modify the material of a scene node.
\r
76 video::SMaterial& getMaterial(u32 i) override;
\r
78 //! returns amount of materials used by this scene node.
\r
79 u32 getMaterialCount() const override;
\r
81 //! Returns a pointer to a child node, which has the same transformation as
\r
82 //! the corresponding joint, if the mesh in this scene node is a skinned mesh.
\r
83 IBoneSceneNode* getJointNode(const c8* jointName) override;
\r
85 //! same as getJointNode(const c8* jointName), but based on id
\r
86 IBoneSceneNode* getJointNode(u32 jointID) override;
\r
88 //! Gets joint count.
\r
89 u32 getJointCount() const override;
\r
91 //! Removes a child from this scene node.
\r
92 //! Implemented here, to be able to remove the shadow properly, if there is one,
\r
93 //! or to remove attached child.
\r
94 bool removeChild(ISceneNode* child) override;
\r
96 //! Returns the current displayed frame number.
\r
97 f32 getFrameNr() const override;
\r
98 //! Returns the current start frame number.
\r
99 s32 getStartFrame() const override;
\r
100 //! Returns the current end frame number.
\r
101 s32 getEndFrame() const override;
\r
103 //! Sets if the scene node should not copy the materials of the mesh but use them in a read only style.
\r
104 /* In this way it is possible to change the materials a mesh causing all mesh scene nodes
\r
105 referencing this mesh to change too. */
\r
106 void setReadOnlyMaterials(bool readonly) override;
\r
108 //! Returns if the scene node should not copy the materials of the mesh but use them in a read only style
\r
109 bool isReadOnlyMaterials() const override;
\r
111 //! Sets a new mesh
\r
112 void setMesh(IAnimatedMesh* mesh) override;
\r
114 //! Returns the current mesh
\r
115 IAnimatedMesh* getMesh(void) override { return Mesh; }
\r
117 //! Returns type of the scene node
\r
118 ESCENE_NODE_TYPE getType() const override { return ESNT_ANIMATED_MESH; }
\r
120 //! updates the absolute position based on the relative and the parents position
\r
121 void updateAbsolutePosition() override;
\r
124 //! Set the joint update mode (0-unused, 1-get joints only, 2-set joints only, 3-move and set)
\r
125 void setJointMode(E_JOINT_UPDATE_ON_RENDER mode) override;
\r
127 //! Sets the transition time in seconds (note: This needs to enable joints, and setJointmode maybe set to 2)
\r
128 //! you must call animateJoints(), or the mesh will not animate
\r
129 void setTransitionTime(f32 Time) override;
\r
131 //! updates the joint positions of this mesh
\r
132 void animateJoints(bool CalculateAbsolutePositions=true) override;
\r
134 //! render mesh ignoring its transformation. Used with ragdolls. (culling is unaffected)
\r
135 void setRenderFromIdentity( bool On ) override;
\r
137 //! Creates a clone of this scene node and its children.
\r
138 /** \param newParent An optional new parent.
\r
139 \param newManager An optional new scene manager.
\r
140 \return The newly created clone of this node. */
\r
141 ISceneNode* clone(ISceneNode* newParent=0, ISceneManager* newManager=0) override;
\r
145 //! Get a static mesh for the current frame of this animated mesh
\r
146 IMesh* getMeshForCurrentFrame();
\r
148 void buildFrameNr(u32 timeMs);
\r
149 void checkJoints();
\r
150 void beginTransition();
\r
152 core::array<video::SMaterial> Materials;
\r
153 core::aabbox3d<f32> Box;
\r
154 IAnimatedMesh* Mesh;
\r
158 f32 FramesPerSecond;
\r
159 f32 CurrentFrameNr;
\r
162 u32 TransitionTime; //Transition time in millisecs
\r
163 f32 Transiting; //is mesh transiting (plus cache of TransitionTime)
\r
164 f32 TransitingBlend; //0-1, calculated on buildFrameNr
\r
166 //0-unused, 1-get joints only, 2-set joints only, 3-move and set
\r
167 E_JOINT_UPDATE_ON_RENDER JointMode;
\r
171 bool ReadOnlyMaterials;
\r
172 bool RenderFromIdentity;
\r
174 IAnimationEndCallBack* LoopCallBack;
\r
177 core::array<IBoneSceneNode* > JointChildSceneNodes;
\r
178 core::array<core::matrix4> PretransitingSave;
\r
181 } // end namespace scene
\r
182 } // end namespace irr
\r