2008-05-22 04:51:37 -07:00
|
|
|
// Copyright (C) 2002-2008 Nikolaus Gebhardt
|
2007-05-20 11:03:49 -07:00
|
|
|
// This file is part of the "Irrlicht Engine".
|
|
|
|
// For conditions of distribution and use, see copyright notice in irrlicht.h
|
|
|
|
|
|
|
|
#ifndef __C_ANIMATED_MESH_SCENE_NODE_H_INCLUDED__
|
|
|
|
#define __C_ANIMATED_MESH_SCENE_NODE_H_INCLUDED__
|
|
|
|
|
|
|
|
#include "IAnimatedMeshSceneNode.h"
|
|
|
|
#include "IAnimatedMesh.h"
|
|
|
|
|
2007-09-04 11:51:42 -07:00
|
|
|
#include "matrix4.h"
|
|
|
|
|
|
|
|
|
2007-05-20 11:03:49 -07:00
|
|
|
namespace irr
|
|
|
|
{
|
|
|
|
namespace scene
|
|
|
|
{
|
|
|
|
class IDummyTransformationSceneNode;
|
|
|
|
|
|
|
|
class CAnimatedMeshSceneNode : public IAnimatedMeshSceneNode
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
//! constructor
|
|
|
|
CAnimatedMeshSceneNode(IAnimatedMesh* mesh, ISceneNode* parent, ISceneManager* mgr, s32 id,
|
|
|
|
const core::vector3df& position = core::vector3df(0,0,0),
|
|
|
|
const core::vector3df& rotation = core::vector3df(0,0,0),
|
|
|
|
const core::vector3df& scale = core::vector3df(1.0f, 1.0f, 1.0f));
|
|
|
|
|
|
|
|
//! destructor
|
|
|
|
virtual ~CAnimatedMeshSceneNode();
|
|
|
|
|
|
|
|
//! sets the current frame. from now on the animation is played from this frame.
|
2007-09-04 11:51:42 -07:00
|
|
|
virtual void setCurrentFrame(f32 frame);
|
2007-05-20 11:03:49 -07:00
|
|
|
|
|
|
|
//! frame
|
|
|
|
virtual void OnRegisterSceneNode();
|
|
|
|
|
|
|
|
//! OnAnimate() is called just before rendering the whole scene.
|
|
|
|
virtual void OnAnimate(u32 timeMs);
|
|
|
|
|
|
|
|
//! renders the node.
|
|
|
|
virtual void render();
|
|
|
|
|
|
|
|
//! returns the axis aligned bounding box of this node
|
|
|
|
virtual const core::aabbox3d<f32>& getBoundingBox() const;
|
|
|
|
|
|
|
|
//! sets the frames between the animation is looped.
|
|
|
|
//! the default is 0 - MaximalFrameCount of the mesh.
|
|
|
|
virtual bool setFrameLoop(s32 begin, s32 end);
|
|
|
|
|
|
|
|
//! Sets looping mode which is on by default. If set to false,
|
|
|
|
//! animations will not be looped.
|
|
|
|
virtual void setLoopMode(bool playAnimationLooped);
|
|
|
|
|
|
|
|
//! Sets a callback interface which will be called if an animation
|
|
|
|
//! playback has ended. Set this to 0 to disable the callback again.
|
|
|
|
virtual void setAnimationEndCallback(IAnimationEndCallBack* callback=0);
|
|
|
|
|
|
|
|
//! sets the speed with witch the animation is played
|
|
|
|
virtual void setAnimationSpeed(f32 framesPerSecond);
|
|
|
|
|
|
|
|
//! returns the material based on the zero based index i. To get the amount
|
|
|
|
//! of materials used by this scene node, use getMaterialCount().
|
|
|
|
//! This function is needed for inserting the node into the scene hirachy on a
|
|
|
|
//! optimal position for minimizing renderstate changes, but can also be used
|
|
|
|
//! to directly modify the material of a scene node.
|
|
|
|
virtual video::SMaterial& getMaterial(u32 i);
|
|
|
|
|
|
|
|
//! returns amount of materials used by this scene node.
|
2007-09-16 16:41:55 -07:00
|
|
|
virtual u32 getMaterialCount() const;
|
2007-05-20 11:03:49 -07:00
|
|
|
|
|
|
|
//! Creates shadow volume scene node as child of this node
|
|
|
|
//! and returns a pointer to it.
|
|
|
|
virtual IShadowVolumeSceneNode* addShadowVolumeSceneNode(s32 id,
|
|
|
|
bool zfailmethod=true, f32 infinity=10000.0f);
|
|
|
|
|
2007-09-04 11:51:42 -07:00
|
|
|
//! Returns a pointer to a child node, which has the same transformation as
|
|
|
|
//! the corrsesponding joint, if the mesh in this scene node is a skinned mesh.
|
|
|
|
virtual IBoneSceneNode* getJointNode(const c8* jointName);
|
|
|
|
|
2007-09-05 01:54:40 -07:00
|
|
|
//! same as getJointNode(const c8* jointName), but based on id
|
|
|
|
virtual IBoneSceneNode* getJointNode(u32 jointID);
|
|
|
|
|
2007-11-13 23:35:40 -08:00
|
|
|
//! Gets joint count.
|
|
|
|
virtual u32 getJointCount() const;
|
|
|
|
|
2007-09-05 01:54:40 -07:00
|
|
|
//! Redundant command, please use getJointNode.
|
2007-05-20 11:03:49 -07:00
|
|
|
virtual ISceneNode* getMS3DJointNode(const c8* jointName);
|
|
|
|
|
2007-09-05 01:54:40 -07:00
|
|
|
//! Redundant command, please use getJointNode.
|
2007-05-20 11:03:49 -07:00
|
|
|
virtual ISceneNode* getXJointNode(const c8* jointName);
|
|
|
|
|
|
|
|
//! Removes a child from this scene node.
|
|
|
|
//! Implemented here, to be able to remove the shadow properly, if there is one,
|
|
|
|
//! or to remove attached childs.
|
|
|
|
virtual bool removeChild(ISceneNode* child);
|
|
|
|
|
|
|
|
//! Starts a MD2 animation.
|
|
|
|
virtual bool setMD2Animation(EMD2_ANIMATION_TYPE anim);
|
|
|
|
|
|
|
|
//! Starts a special MD2 animation.
|
|
|
|
virtual bool setMD2Animation(const c8* animationName);
|
|
|
|
|
|
|
|
//! Returns the current displayed frame number.
|
2007-09-04 11:51:42 -07:00
|
|
|
virtual f32 getFrameNr() const;
|
2007-05-20 11:03:49 -07:00
|
|
|
//! Returns the current start frame number.
|
|
|
|
virtual s32 getStartFrame() const;
|
|
|
|
//! Returns the current end frame number.
|
|
|
|
virtual s32 getEndFrame() const;
|
|
|
|
|
|
|
|
//! Sets if the scene node should not copy the materials of the mesh but use them in a read only style.
|
|
|
|
/* In this way it is possible to change the materials a mesh causing all mesh scene nodes
|
|
|
|
referencing this mesh to change too. */
|
|
|
|
virtual void setReadOnlyMaterials(bool readonly);
|
|
|
|
|
|
|
|
//! Returns if the scene node should not copy the materials of the mesh but use them in a read only style
|
2007-09-14 15:25:59 -07:00
|
|
|
virtual bool isReadOnlyMaterials() const;
|
2007-05-20 11:03:49 -07:00
|
|
|
|
|
|
|
//! Sets a new mesh
|
|
|
|
virtual void setMesh(IAnimatedMesh* mesh);
|
|
|
|
|
|
|
|
//! Returns the current mesh
|
|
|
|
virtual IAnimatedMesh* getMesh(void) { return Mesh; }
|
|
|
|
|
|
|
|
//! Writes attributes of the scene node.
|
2007-09-14 15:25:59 -07:00
|
|
|
virtual void serializeAttributes(io::IAttributes* out, io::SAttributeReadWriteOptions* options=0) const;
|
2007-05-20 11:03:49 -07:00
|
|
|
|
|
|
|
//! Reads attributes of the scene node.
|
|
|
|
virtual void deserializeAttributes(io::IAttributes* in, io::SAttributeReadWriteOptions* options=0);
|
|
|
|
|
|
|
|
//! Returns type of the scene node
|
|
|
|
virtual ESCENE_NODE_TYPE getType() const { return ESNT_ANIMATED_MESH; }
|
|
|
|
|
|
|
|
// returns the absolute transformation for a special MD3 Tag if the mesh is a md3 mesh,
|
|
|
|
// or the absolutetransformation if it's a normal scenenode
|
2007-06-08 20:14:17 -07:00
|
|
|
const SMD3QuaterionTag& getMD3TagTransformation( const core::stringc & tagname);
|
2007-05-20 11:03:49 -07:00
|
|
|
|
|
|
|
//! updates the absolute position based on the relative and the parents position
|
|
|
|
virtual void updateAbsolutePosition();
|
|
|
|
|
2007-09-04 11:51:42 -07:00
|
|
|
|
|
|
|
//! Set the joint update mode (0-unused, 1-get joints only, 2-set joints only, 3-move and set)
|
2007-10-16 06:34:07 -07:00
|
|
|
virtual void setJointMode(E_JOINT_UPDATE_ON_RENDER mode);
|
2007-09-04 11:51:42 -07:00
|
|
|
|
|
|
|
//! Sets the transition time in seconds (note: This needs to enable joints, and setJointmode maybe set to 2)
|
|
|
|
//! you must call animateJoints(), or the mesh will not animate
|
|
|
|
virtual void setTransitionTime(f32 Time);
|
|
|
|
|
|
|
|
//! updates the joint positions of this mesh
|
2007-10-16 06:34:07 -07:00
|
|
|
virtual void animateJoints(bool CalculateAbsolutePositions=true);
|
2007-09-04 11:51:42 -07:00
|
|
|
|
2007-10-01 21:01:08 -07:00
|
|
|
//! render mesh ignoring it's transformation. Used with ragdolls. (culling is unaffected)
|
|
|
|
virtual void setRenderFromIdentity( bool On );
|
|
|
|
|
2007-05-20 11:03:49 -07:00
|
|
|
private:
|
|
|
|
|
2007-09-04 11:51:42 -07:00
|
|
|
f32 buildFrameNr( u32 timeMs);
|
|
|
|
void checkJoints();
|
|
|
|
void beginTransition();
|
2007-05-20 11:03:49 -07:00
|
|
|
|
|
|
|
core::array<video::SMaterial> Materials;
|
|
|
|
core::aabbox3d<f32> Box;
|
|
|
|
IAnimatedMesh* Mesh;
|
|
|
|
|
|
|
|
u32 BeginFrameTime;
|
|
|
|
s32 StartFrame;
|
|
|
|
s32 EndFrame;
|
|
|
|
f32 FramesPerSecond;
|
2007-09-04 11:51:42 -07:00
|
|
|
f32 CurrentFrameNr;
|
|
|
|
|
2007-10-16 06:34:07 -07:00
|
|
|
E_JOINT_UPDATE_ON_RENDER JointMode; //0-unused, 1-get joints only, 2-set joints only, 3-move and set
|
2007-09-04 11:51:42 -07:00
|
|
|
bool JointsUsed;
|
|
|
|
|
|
|
|
u32 TransitionTime; //Transition time in millisecs
|
|
|
|
|
|
|
|
f32 Transiting; //is mesh transiting (plus cache of TransitionTime)
|
|
|
|
f32 TransitingBlend; //0-1, calculated on buildFrameNr
|
2007-05-20 11:03:49 -07:00
|
|
|
|
|
|
|
bool Looping;
|
|
|
|
bool ReadOnlyMaterials;
|
|
|
|
|
|
|
|
IAnimationEndCallBack* LoopCallBack;
|
|
|
|
s32 PassCount;
|
|
|
|
|
|
|
|
IShadowVolumeSceneNode* Shadow;
|
|
|
|
|
2007-09-04 11:51:42 -07:00
|
|
|
core::array<IBoneSceneNode* > JointChildSceneNodes;
|
|
|
|
core::array<core::matrix4> PretransitingSave;
|
|
|
|
|
2007-10-01 21:01:08 -07:00
|
|
|
bool RenderFromIdentity;
|
2007-05-20 11:03:49 -07:00
|
|
|
|
|
|
|
struct SMD3Special
|
|
|
|
{
|
|
|
|
core::stringc Tagname;
|
|
|
|
SMD3QuaterionTagList AbsoluteTagList;
|
|
|
|
};
|
|
|
|
SMD3Special MD3Special;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
} // end namespace scene
|
|
|
|
} // end namespace irr
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|