1 // Copyright (C) 2002-2012 Nikolaus Gebhardt 2 // This file is part of the "Irrlicht Engine". 3 // For conditions of distribution and use, see copyright notice in irrlicht.h 4 5 #ifndef __C_ANIMATED_MESH_SCENE_NODE_H_INCLUDED__ 6 #define __C_ANIMATED_MESH_SCENE_NODE_H_INCLUDED__ 7 8 #include "IAnimatedMeshSceneNode.h" 9 #include "IAnimatedMesh.h" 10 11 #include "matrix4.h" 12 13 14 namespace irr 15 { 16 namespace scene 17 { 18 class IDummyTransformationSceneNode; 19 20 class CAnimatedMeshSceneNode : public IAnimatedMeshSceneNode 21 { 22 private: 23 core::array<u32> m_animation_set; 24 public: 25 26 //! constructor 27 CAnimatedMeshSceneNode(IAnimatedMesh* mesh, ISceneNode* parent, ISceneManager* mgr, s32 id, 28 const core::vector3df& position = core::vector3df(0,0,0), 29 const core::vector3df& rotation = core::vector3df(0,0,0), 30 const core::vector3df& scale = core::vector3df(1.0f, 1.0f, 1.0f)); 31 32 //! destructor 33 virtual ~CAnimatedMeshSceneNode(); 34 35 //! sets the current frame. from now on the animation is played from this frame. 36 virtual void setCurrentFrame(f32 frame); 37 38 //! frame 39 virtual void OnRegisterSceneNode(); 40 41 //! OnAnimate() is called just before rendering the whole scene. 42 virtual void OnAnimate(u32 timeMs); 43 44 //! renders the node. 45 virtual void render(); 46 47 //! returns the axis aligned bounding box of this node 48 virtual const core::aabbox3d<f32>& getBoundingBox() const; 49 50 //! sets the frames between the animation is looped. 51 //! the default is 0 - MaximalFrameCount of the mesh. 52 virtual bool setFrameLoop(s32 begin, s32 end); 53 54 //! Sets looping mode which is on by default. If set to false, 55 //! animations will not be looped. 56 virtual void setLoopMode(bool playAnimationLooped); 57 58 //! returns the current loop mode 59 virtual bool getLoopMode() const; 60 61 //! Sets a callback interface which will be called if an animation 62 //! playback has ended. Set this to 0 to disable the callback again. 63 virtual void setAnimationEndCallback(IAnimationEndCallBack* callback=0); 64 65 //! sets the speed with which the animation is played 66 virtual void setAnimationSpeed(f32 framesPerSecond); 67 68 //! gets the speed with which the animation is played 69 virtual f32 getAnimationSpeed() const; 70 71 //! Sets the animation strength (how important the animation is) 72 /** \param strength: The importance of the animation: 1.f keeps the original animation, 0.f is no animation. */ 73 virtual void setAnimationStrength(f32 strength); 74 75 //! Gets the animation strength (how important the animation is) 76 /** \return The importance of the animation: 1.f keeps the original animation, 0.f is no animation. */ 77 virtual f32 getAnimationStrength() const; 78 79 //! returns the material based on the zero based index i. To get the amount 80 //! of materials used by this scene node, use getMaterialCount(). 81 //! This function is needed for inserting the node into the scene hirachy on a 82 //! optimal position for minimizing renderstate changes, but can also be used 83 //! to directly modify the material of a scene node. 84 virtual video::SMaterial& getMaterial(u32 i); 85 86 //! returns amount of materials used by this scene node. 87 virtual u32 getMaterialCount() const; 88 89 //! Returns a pointer to a child node, which has the same transformation as 90 //! the corrsesponding joint, if the mesh in this scene node is a skinned mesh. 91 virtual IBoneSceneNode* getJointNode(const c8* jointName); 92 93 //! same as getJointNode(const c8* jointName), but based on id 94 virtual IBoneSceneNode* getJointNode(u32 jointID); 95 96 //! Gets joint count. 97 virtual u32 getJointCount() const; 98 99 //! Deprecated command, please use getJointNode. 100 virtual ISceneNode* getMS3DJointNode(const c8* jointName); 101 102 //! Deprecated command, please use getJointNode. 103 virtual ISceneNode* getXJointNode(const c8* jointName); 104 105 //! Removes a child from this scene node. 106 //! Implemented here, to be able to remove the shadow properly, if there is one, 107 //! or to remove attached childs. 108 virtual bool removeChild(ISceneNode* child); 109 110 //! Returns the current displayed frame number. 111 virtual f32 getFrameNr() const; 112 //! Returns the current start frame number. 113 virtual s32 getStartFrame() const; 114 //! Returns the current end frame number. 115 virtual s32 getEndFrame() const; 116 117 //! Sets if the scene node should not copy the materials of the mesh but use them in a read only style. 118 /* In this way it is possible to change the materials a mesh causing all mesh scene nodes 119 referencing this mesh to change too. */ 120 virtual void setReadOnlyMaterials(bool readonly); 121 122 //! Returns if the scene node should not copy the materials of the mesh but use them in a read only style 123 virtual bool isReadOnlyMaterials() const; 124 125 //! Sets a new mesh 126 virtual void setMesh(IAnimatedMesh* mesh); 127 128 //! Returns the current mesh getMesh(void)129 virtual IAnimatedMesh* getMesh(void) { return Mesh; } 130 131 //! Writes attributes of the scene node. 132 virtual void serializeAttributes(io::IAttributes* out, io::SAttributeReadWriteOptions* options=0) const; 133 134 //! Reads attributes of the scene node. 135 virtual void deserializeAttributes(io::IAttributes* in, io::SAttributeReadWriteOptions* options=0); 136 137 //! Returns type of the scene node getType()138 virtual ESCENE_NODE_TYPE getType() const { return ESNT_ANIMATED_MESH; } 139 140 //! updates the absolute position based on the relative and the parents position 141 virtual void updateAbsolutePosition(); 142 143 144 //! Set the joint update mode (0-unused, 1-get joints only, 2-set joints only, 3-move and set) 145 virtual void setJointMode(E_JOINT_UPDATE_ON_RENDER mode); 146 147 //! Sets the transition time in seconds (note: This needs to enable joints, and setJointmode maybe set to 2) 148 //! you must call animateJoints(), or the mesh will not animate 149 virtual void setTransitionTime(f32 Time); 150 151 //! updates the joint positions of this mesh 152 virtual void animateJoints(bool CalculateAbsolutePositions=true); 153 154 //! render mesh ignoring its transformation. Used with ragdolls. (culling is unaffected) 155 virtual void setRenderFromIdentity( bool On ); 156 157 //! Creates a clone of this scene node and its children. 158 /** \param newParent An optional new parent. 159 \param newManager An optional new scene manager. 160 \return The newly created clone of this node. */ 161 virtual ISceneNode* clone(ISceneNode* newParent=0, ISceneManager* newManager=0); 162 getAnimationSetNum()163 virtual u32 getAnimationSetNum() { return m_animation_set.size() / 2; } 164 virtual s32 getAnimationSet() const; addAnimationSet(u32 start,u32 end)165 virtual void addAnimationSet(u32 start, u32 end) 166 { 167 m_animation_set.push_back(start); 168 m_animation_set.push_back(end); 169 } removeAllAnimationSet()170 virtual void removeAllAnimationSet() { m_animation_set.clear(); } 171 virtual void useAnimationSet(u32 set_num); 172 virtual void setFrameLoopOnce(s32 begin, s32 end); getAnimationSetFrames()173 virtual core::array<u32>& getAnimationSetFrames() { return m_animation_set; } 174 protected: 175 176 //! Get a static mesh for the current frame of this animated mesh 177 virtual IMesh* getMeshForCurrentFrame(); 178 179 void buildFrameNr(u32 timeMs); 180 virtual void checkJoints(); 181 void beginTransition(); 182 183 core::array<video::SMaterial> Materials; 184 core::aabbox3d<f32> Box; 185 IAnimatedMesh* Mesh; 186 187 s32 StartFrame; 188 s32 EndFrame; 189 f32 FramesPerSecond; 190 f32 CurrentFrameNr; 191 192 f32 AnimationStrength; 193 194 u32 LastTimeMs; 195 u32 TransitionTime; //Transition time in millisecs 196 f32 Transiting; //is mesh transiting (plus cache of TransitionTime) 197 f32 TransitingBlend; //0-1, calculated on buildFrameNr 198 199 //0-unused, 1-get joints only, 2-set joints only, 3-move and set 200 E_JOINT_UPDATE_ON_RENDER JointMode; 201 bool JointsUsed; 202 203 bool Looping; 204 bool ReadOnlyMaterials; 205 bool RenderFromIdentity; 206 207 IAnimationEndCallBack* LoopCallBack; 208 s32 PassCount; 209 210 core::array<IBoneSceneNode* > JointChildSceneNodes; 211 core::array<core::matrix4> PretransitingSave; 212 }; 213 214 } // end namespace scene 215 } // end namespace irr 216 217 #endif 218 219