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 virtual void setCurrentFrame(f32 frame) _IRR_OVERRIDE_;
\r
37 virtual void OnRegisterSceneNode() _IRR_OVERRIDE_;
\r
39 //! OnAnimate() is called just before rendering the whole scene.
\r
40 virtual void OnAnimate(u32 timeMs) _IRR_OVERRIDE_;
\r
42 //! renders the node.
\r
43 virtual void render() _IRR_OVERRIDE_;
\r
45 //! returns the axis aligned bounding box of this node
\r
46 virtual const core::aabbox3d<f32>& getBoundingBox() const _IRR_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 virtual bool setFrameLoop(s32 begin, s32 end) _IRR_OVERRIDE_;
\r
53 //! Sets looping mode which is on by default. If set to false,
\r
54 //! animations will not be looped.
\r
55 virtual void setLoopMode(bool playAnimationLooped) _IRR_OVERRIDE_;
\r
57 //! returns the current loop mode
\r
58 virtual bool getLoopMode() const _IRR_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 virtual void setAnimationEndCallback(IAnimationEndCallBack* callback=0) _IRR_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 virtual void setAnimationSpeed(f32 framesPerSecond) _IRR_OVERRIDE_;
\r
68 //! gets the speed with which the animation is played
\r
69 virtual f32 getAnimationSpeed() const _IRR_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 virtual video::SMaterial& getMaterial(u32 i) _IRR_OVERRIDE_;
\r
78 //! returns amount of materials used by this scene node.
\r
79 virtual u32 getMaterialCount() const _IRR_OVERRIDE_;
\r
81 //! Creates shadow volume scene node as child of this node
\r
82 //! and returns a pointer to it.
\r
83 virtual IShadowVolumeSceneNode* addShadowVolumeSceneNode(const IMesh* shadowMesh,
\r
84 s32 id, bool zfailmethod=true, f32 infinity=1000.0f) _IRR_OVERRIDE_;
\r
86 //! Returns a pointer to a child node, which has the same transformation as
\r
87 //! the corresponding joint, if the mesh in this scene node is a skinned mesh.
\r
88 virtual IBoneSceneNode* getJointNode(const c8* jointName) _IRR_OVERRIDE_;
\r
90 //! same as getJointNode(const c8* jointName), but based on id
\r
91 virtual IBoneSceneNode* getJointNode(u32 jointID) _IRR_OVERRIDE_;
\r
93 //! Gets joint count.
\r
94 virtual u32 getJointCount() const _IRR_OVERRIDE_;
\r
96 //! Removes a child from this scene node.
\r
97 //! Implemented here, to be able to remove the shadow properly, if there is one,
\r
98 //! or to remove attached child.
\r
99 virtual bool removeChild(ISceneNode* child) _IRR_OVERRIDE_;
\r
101 //! Starts a MD2 animation.
\r
102 virtual bool setMD2Animation(EMD2_ANIMATION_TYPE anim) _IRR_OVERRIDE_;
\r
104 //! Starts a special MD2 animation.
\r
105 virtual bool setMD2Animation(const c8* animationName) _IRR_OVERRIDE_;
\r
107 //! Returns the current displayed frame number.
\r
108 virtual f32 getFrameNr() const _IRR_OVERRIDE_;
\r
109 //! Returns the current start frame number.
\r
110 virtual s32 getStartFrame() const _IRR_OVERRIDE_;
\r
111 //! Returns the current end frame number.
\r
112 virtual s32 getEndFrame() const _IRR_OVERRIDE_;
\r
114 //! Sets if the scene node should not copy the materials of the mesh but use them in a read only style.
\r
115 /* In this way it is possible to change the materials a mesh causing all mesh scene nodes
\r
116 referencing this mesh to change too. */
\r
117 virtual void setReadOnlyMaterials(bool readonly) _IRR_OVERRIDE_;
\r
119 //! Returns if the scene node should not copy the materials of the mesh but use them in a read only style
\r
120 virtual bool isReadOnlyMaterials() const _IRR_OVERRIDE_;
\r
122 //! Sets a new mesh
\r
123 virtual void setMesh(IAnimatedMesh* mesh) _IRR_OVERRIDE_;
\r
125 //! Returns the current mesh
\r
126 virtual IAnimatedMesh* getMesh(void) _IRR_OVERRIDE_ { return Mesh; }
\r
128 //! Writes attributes of the scene node.
\r
129 virtual void serializeAttributes(io::IAttributes* out, io::SAttributeReadWriteOptions* options=0) const _IRR_OVERRIDE_;
\r
131 //! Reads attributes of the scene node.
\r
132 virtual void deserializeAttributes(io::IAttributes* in, io::SAttributeReadWriteOptions* options=0) _IRR_OVERRIDE_;
\r
134 //! Returns type of the scene node
\r
135 virtual ESCENE_NODE_TYPE getType() const _IRR_OVERRIDE_ { return ESNT_ANIMATED_MESH; }
\r
137 // returns the absolute transformation for a special MD3 Tag if the mesh is a md3 mesh,
\r
138 // or the absolutetransformation if it's a normal scenenode
\r
139 const SMD3QuaternionTag* getMD3TagTransformation( const core::stringc & tagname) _IRR_OVERRIDE_;
\r
141 //! updates the absolute position based on the relative and the parents position
\r
142 virtual void updateAbsolutePosition() _IRR_OVERRIDE_;
\r
145 //! Set the joint update mode (0-unused, 1-get joints only, 2-set joints only, 3-move and set)
\r
146 virtual void setJointMode(E_JOINT_UPDATE_ON_RENDER mode) _IRR_OVERRIDE_;
\r
148 //! Sets the transition time in seconds (note: This needs to enable joints, and setJointmode maybe set to 2)
\r
149 //! you must call animateJoints(), or the mesh will not animate
\r
150 virtual void setTransitionTime(f32 Time) _IRR_OVERRIDE_;
\r
152 //! updates the joint positions of this mesh
\r
153 virtual void animateJoints(bool CalculateAbsolutePositions=true) _IRR_OVERRIDE_;
\r
155 //! render mesh ignoring its transformation. Used with ragdolls. (culling is unaffected)
\r
156 virtual void setRenderFromIdentity( bool On ) _IRR_OVERRIDE_;
\r
158 //! Creates a clone of this scene node and its children.
\r
159 /** \param newParent An optional new parent.
\r
160 \param newManager An optional new scene manager.
\r
161 \return The newly created clone of this node. */
\r
162 virtual ISceneNode* clone(ISceneNode* newParent=0, ISceneManager* newManager=0) _IRR_OVERRIDE_;
\r
166 //! Get a static mesh for the current frame of this animated mesh
\r
167 IMesh* getMeshForCurrentFrame();
\r
169 void buildFrameNr(u32 timeMs);
\r
170 void checkJoints();
\r
171 void beginTransition();
\r
173 core::array<video::SMaterial> Materials;
\r
174 core::aabbox3d<f32> Box;
\r
175 IAnimatedMesh* Mesh;
\r
179 f32 FramesPerSecond;
\r
180 f32 CurrentFrameNr;
\r
183 u32 TransitionTime; //Transition time in millisecs
\r
184 f32 Transiting; //is mesh transiting (plus cache of TransitionTime)
\r
185 f32 TransitingBlend; //0-1, calculated on buildFrameNr
\r
187 //0-unused, 1-get joints only, 2-set joints only, 3-move and set
\r
188 E_JOINT_UPDATE_ON_RENDER JointMode;
\r
192 bool ReadOnlyMaterials;
\r
193 bool RenderFromIdentity;
\r
195 IAnimationEndCallBack* LoopCallBack;
\r
198 IShadowVolumeSceneNode* Shadow;
\r
200 core::array<IBoneSceneNode* > JointChildSceneNodes;
\r
201 core::array<core::matrix4> PretransitingSave;
\r
204 struct SMD3Special : public virtual IReferenceCounted
\r
206 core::stringc Tagname;
\r
207 SMD3QuaternionTagList AbsoluteTagList;
\r
209 SMD3Special & operator = (const SMD3Special & copyMe)
\r
211 Tagname = copyMe.Tagname;
\r
212 AbsoluteTagList = copyMe.AbsoluteTagList;
\r
216 SMD3Special *MD3Special;
\r
219 } // end namespace scene
\r
220 } // end namespace irr
\r