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 __I_ANIMATED_MESH_SCENE_NODE_H_INCLUDED__
\r
6 #define __I_ANIMATED_MESH_SCENE_NODE_H_INCLUDED__
\r
8 #include "ISceneNode.h"
\r
9 #include "IBoneSceneNode.h"
\r
10 #include "IAnimatedMesh.h"
\r
16 class IShadowVolumeSceneNode;
\r
18 enum E_JOINT_UPDATE_ON_RENDER
\r
23 //! get joints positions from the mesh (for attached nodes, etc)
\r
26 //! control joint positions in the mesh (eg. ragdolls, or set the animation from animateJoints() )
\r
31 class IAnimatedMeshSceneNode;
\r
33 //! Callback interface for catching events of ended animations.
\r
34 /** Implement this interface and use
\r
35 IAnimatedMeshSceneNode::setAnimationEndCallback to be able to
\r
36 be notified if an animation playback has ended.
\r
38 class IAnimationEndCallBack : public virtual IReferenceCounted
\r
42 //! Will be called when the animation playback has ended.
\r
43 /** See IAnimatedMeshSceneNode::setAnimationEndCallback for
\r
45 \param node: Node of which the animation has ended. */
\r
46 virtual void OnAnimationEnd(IAnimatedMeshSceneNode* node) = 0;
\r
49 //! Scene node capable of displaying an animated mesh.
\r
50 class IAnimatedMeshSceneNode : public ISceneNode
\r
55 IAnimatedMeshSceneNode(ISceneNode* parent, ISceneManager* mgr, s32 id,
\r
56 const core::vector3df& position = core::vector3df(0,0,0),
\r
57 const core::vector3df& rotation = core::vector3df(0,0,0),
\r
58 const core::vector3df& scale = core::vector3df(1.0f, 1.0f, 1.0f))
\r
59 : ISceneNode(parent, mgr, id, position, rotation, scale) {}
\r
62 virtual ~IAnimatedMeshSceneNode() {}
\r
64 //! Sets the current frame number.
\r
65 /** From now on the animation is played from this frame.
\r
66 \param frame: Number of the frame to let the animation be started from.
\r
67 The frame number must be a valid frame number of the IMesh used by this
\r
68 scene node. Set IAnimatedMesh::getMesh() for details. */
\r
69 virtual void setCurrentFrame(f32 frame) = 0;
\r
71 //! Sets the frame numbers between the animation is looped.
\r
72 /** The default is 0 to getFrameCount()-1 of the mesh.
\r
73 Number of played frames is end-start.
\r
74 It interpolates toward the last frame but stops when it is reached.
\r
75 It does not interpolate back to start even when looping.
\r
76 Looping animations should ensure last and first frame-key are identical.
\r
77 \param begin: Start frame number of the loop.
\r
78 \param end: End frame number of the loop.
\r
79 \return True if successful, false if not. */
\r
80 virtual bool setFrameLoop(s32 begin, s32 end) = 0;
\r
82 //! Sets the speed with which the animation is played.
\r
83 /** \param framesPerSecond: Frames per second played. */
\r
84 virtual void setAnimationSpeed(f32 framesPerSecond) = 0;
\r
86 //! Gets the speed with which the animation is played.
\r
87 /** \return Frames per second played. */
\r
88 virtual f32 getAnimationSpeed() const =0;
\r
90 /** The shadow can be rendered using the ZPass or the zfail
\r
91 method. ZPass is a little bit faster because the shadow volume
\r
92 creation is easier, but with this method there occur ugly
\r
93 looking artifacts when the camera is inside the shadow volume.
\r
94 These error do not occur with the ZFail method, but it can
\r
95 have trouble with clipping to the far-plane (it usually works
\r
96 well in OpenGL and fails with other drivers).
\r
97 \param shadowMesh: Optional custom mesh for shadow volume.
\r
98 \param id: Id of the shadow scene node. This id can be used to
\r
99 identify the node later.
\r
100 \param zfailmethod: If set to true, the shadow will use the
\r
101 zfail method, if not, zpass is used.
\r
102 \param infinity: Value used by the shadow volume algorithm to
\r
103 scale the shadow volume. For zfail shadow volumes on some drivers
\r
104 only support finite shadows, so camera zfar must be larger than
\r
105 shadow back cap,which is depending on the infinity parameter).
\r
106 Infinity value also scales by the scaling factors of the model.
\r
107 If shadows don't show up with zfail then try reducing infinity.
\r
108 If shadows are cut-off then try increasing infinity.
\r
109 \return Pointer to the created shadow scene node. This pointer
\r
110 should not be dropped. See IReferenceCounted::drop() for more
\r
112 virtual IShadowVolumeSceneNode* addShadowVolumeSceneNode(const IMesh* shadowMesh=0,
\r
113 s32 id=-1, bool zfailmethod=true, f32 infinity=1000.0f) = 0;
\r
115 //! Get a pointer to a joint in the mesh (if the mesh is a bone based mesh).
\r
116 /** With this method it is possible to attach scene nodes to
\r
117 joints for example possible to attach a weapon to the left hand
\r
118 of an animated model. This example shows how:
\r
121 yourAnimatedMeshSceneNode->getJointNode("LeftHand");
\r
122 hand->addChild(weaponSceneNode);
\r
124 Please note that the joint returned by this method may not exist
\r
125 before this call and the joints in the node were created by it.
\r
126 \param jointName: Name of the joint.
\r
127 \return Pointer to the scene node which represents the joint
\r
128 with the specified name. Returns 0 if the contained mesh is not
\r
129 an skinned mesh or the name of the joint could not be found. */
\r
130 virtual IBoneSceneNode* getJointNode(const c8* jointName)=0;
\r
132 //! same as getJointNode(const c8* jointName), but based on id
\r
133 virtual IBoneSceneNode* getJointNode(u32 jointID) = 0;
\r
135 //! Gets joint count.
\r
136 /** \return Amount of joints in the mesh. */
\r
137 virtual u32 getJointCount() const = 0;
\r
139 //! Returns the currently displayed frame number.
\r
140 virtual f32 getFrameNr() const = 0;
\r
141 //! Returns the current start frame number.
\r
142 virtual s32 getStartFrame() const = 0;
\r
143 //! Returns the current end frame number.
\r
144 virtual s32 getEndFrame() const = 0;
\r
146 //! Sets looping mode which is on by default.
\r
147 /** If set to false, animations will not be played looped. */
\r
148 virtual void setLoopMode(bool playAnimationLooped) = 0;
\r
150 //! returns the current loop mode
\r
151 /** When true the animations are played looped */
\r
152 virtual bool getLoopMode() const = 0;
\r
154 //! Sets a callback interface which will be called if an animation playback has ended.
\r
155 /** Set this to 0 to disable the callback again.
\r
156 Please note that this will only be called when in non looped
\r
157 mode, see IAnimatedMeshSceneNode::setLoopMode(). */
\r
158 virtual void setAnimationEndCallback(IAnimationEndCallBack* callback=0) = 0;
\r
160 //! Sets if the scene node should not copy the materials of the mesh but use them in a read only style.
\r
161 /** In this way it is possible to change the materials a mesh
\r
162 causing all mesh scene nodes referencing this mesh to change
\r
164 virtual void setReadOnlyMaterials(bool readonly) = 0;
\r
166 //! Returns if the scene node should not copy the materials of the mesh but use them in a read only style
\r
167 virtual bool isReadOnlyMaterials() const = 0;
\r
169 //! Sets a new mesh
\r
170 virtual void setMesh(IAnimatedMesh* mesh) = 0;
\r
172 //! Returns the current mesh
\r
173 virtual IAnimatedMesh* getMesh(void) = 0;
\r
175 //! Set how the joints should be updated on render
\r
176 virtual void setJointMode(E_JOINT_UPDATE_ON_RENDER mode)=0;
\r
178 //! Sets the transition time in seconds
\r
179 /** Note: This needs to enable joints, and setJointmode set to
\r
180 EJUOR_CONTROL. You must call animateJoints(), or the mesh will
\r
182 virtual void setTransitionTime(f32 Time) =0;
\r
184 //! animates the joints in the mesh based on the current frame.
\r
185 /** Also takes in to account transitions. */
\r
186 virtual void animateJoints(bool CalculateAbsolutePositions=true) = 0;
\r
188 //! render mesh ignoring its transformation.
\r
189 /** Culling is unaffected. */
\r
190 virtual void setRenderFromIdentity( bool On )=0;
\r
192 //! Creates a clone of this scene node and its children.
\r
193 /** \param newParent An optional new parent.
\r
194 \param newManager An optional new scene manager.
\r
195 \return The newly created clone of this node. */
\r
196 virtual ISceneNode* clone(ISceneNode* newParent=0, ISceneManager* newManager=0) = 0;
\r
200 } // end namespace scene
\r
201 } // end namespace irr
\r