Commit 7d6d371b authored by hybrid's avatar hybrid

Add a FPS setting for animated meshes. This allows to store an overall...

Add a FPS setting for animated meshes. This allows to store an overall animation speed for a mesh, which enables reading this information from the formats that support it and set the animation speed in scene nodes accordingly.

git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@4009 dfc29bdd-3216-0410-991c-e03cc46cb475
parent 6fbb1115
......@@ -64,10 +64,23 @@ namespace scene
public:
//! Gets the frame count of the animated mesh.
/** \return Returns the amount of frames. If the amount is 1,
/** \return The amount of frames. If the amount is 1,
it is a static, non animated mesh. */
virtual u32 getFrameCount() const = 0;
//! Gets the animation speed of the animated mesh.
/** \return The number of frames per second to play the
animation with by default. If the amount is 0,
it is a static, non animated mesh. */
virtual f32 getAnimationSpeed() const = 0;
//! Sets the animation speed of the animated mesh.
/** \param fps Number of frames per second to play the
animation with by default. If the amount is 0,
it is not animated. The actual speed is set in the
scene node the mesh is instantiated in.*/
virtual void setAnimationSpeed(f32 fps) =0;
//! Returns the IMesh interface for a frame.
/** \param frame: Frame number as zero based index. The maximum
frame number is getFrameCount() - 1;
......
......@@ -19,7 +19,7 @@ namespace scene
struct SAnimatedMesh : public IAnimatedMesh
{
//! constructor
SAnimatedMesh(scene::IMesh* mesh=0, scene::E_ANIMATED_MESH_TYPE type=scene::EAMT_UNKNOWN) : IAnimatedMesh(), Type(type)
SAnimatedMesh(scene::IMesh* mesh=0, scene::E_ANIMATED_MESH_TYPE type=scene::EAMT_UNKNOWN) : IAnimatedMesh(), FramesPerSecond(25.f), Type(type)
{
#ifdef _DEBUG
setDebugName("SAnimatedMesh");
......@@ -28,7 +28,6 @@ namespace scene
recalculateBoundingBox();
}
//! destructor
virtual ~SAnimatedMesh()
{
......@@ -37,7 +36,6 @@ namespace scene
Meshes[i]->drop();
}
//! Gets the frame count of the animated mesh.
/** \return Amount of frames. If the amount is 1, it is a static, non animated mesh. */
virtual u32 getFrameCount() const
......@@ -45,6 +43,20 @@ namespace scene
return Meshes.size();
}
//! Gets the default animation speed of the animated mesh.
/** \return Amount of frames per second. If the amount is 0, it is a static, non animated mesh. */
virtual f32 getAnimationSpeed() const
{
return FramesPerSecond;
}
//! Gets the frame count of the animated mesh.
/** \param fps Frames per second to play the animation with. If the amount is 0, it is not animated.
The actual speed is set in the scene node the mesh is instantiated in.*/
virtual void setAnimationSpeed(f32 fps)
{
FramesPerSecond=fps;
}
//! Returns the IMesh interface for a frame.
/** \param frame: Frame number as zero based index. The maximum frame number is
......@@ -54,7 +66,7 @@ namespace scene
\param startFrameLoop: start frame
\param endFrameLoop: end frame
\return The animated mesh based on a detail level. */
virtual IMesh* getMesh(s32 frame, s32 detailLevel, s32 startFrameLoop=-1, s32 endFrameLoop=-1)
virtual IMesh* getMesh(s32 frame, s32 detailLevel=255, s32 startFrameLoop=-1, s32 endFrameLoop=-1)
{
if (Meshes.empty())
return 0;
......@@ -62,7 +74,6 @@ namespace scene
return Meshes[frame];
}
//! adds a Mesh
void addMesh(IMesh* mesh)
{
......@@ -73,7 +84,6 @@ namespace scene
}
}
//! Returns an axis aligned bounding box of the mesh.
/** \return A bounding box of this mesh is returned. */
virtual const core::aabbox3d<f32>& getBoundingBox() const
......@@ -81,7 +91,6 @@ namespace scene
return Box;
}
//! set user axis aligned bounding box
virtual void setBoundingBox(const core::aabbox3df& box)
{
......@@ -102,14 +111,12 @@ namespace scene
Box.addInternalBox(Meshes[i]->getBoundingBox());
}
//! Returns the type of the animated mesh.
virtual E_ANIMATED_MESH_TYPE getMeshType() const
{
return Type;
}
//! returns amount of mesh buffers.
virtual u32 getMeshBufferCount() const
{
......@@ -119,7 +126,6 @@ namespace scene
return Meshes[0]->getMeshBufferCount();
}
//! returns pointer to a mesh buffer
virtual IMeshBuffer* getMeshBuffer(u32 nr) const
{
......@@ -129,7 +135,6 @@ namespace scene
return Meshes[0]->getMeshBuffer(nr);
}
//! Returns pointer to a mesh buffer which fits a material
/** \param material: material to search for
\return Returns the pointer to the mesh buffer or
......@@ -142,7 +147,6 @@ namespace scene
return Meshes[0]->getMeshBuffer(material);
}
//! Set a material flag for all meshbuffers of this mesh.
virtual void setMaterialFlag(video::E_MATERIAL_FLAG flag, bool newvalue)
{
......@@ -170,7 +174,10 @@ namespace scene
//! The bounding box of this mesh
core::aabbox3d<f32> Box;
//! Tyhe type fo the mesh.
//! Default animation speed of this mesh.
f32 FramesPerSecond;
//! The type of the mesh.
E_ANIMATED_MESH_TYPE Type;
};
......
......@@ -200,7 +200,7 @@ IAnimatedMesh* CHalflifeMDLMeshFileLoader::createMesh(io::IReadFile* file)
//! Constructor
CAnimatedMeshHalfLife::CAnimatedMeshHalfLife()
: FrameCount(0), MeshIPol(0), SceneManager(0), Header(0), TextureHeader(0),
OwnTexModel(false), SequenceIndex(0), CurrentFrame(0),
OwnTexModel(false), SequenceIndex(0), CurrentFrame(0), FramesPerSecond(25.f),
SkinGroupSelection(0)
#ifdef HL_TEXTURE_ATLAS
, TextureMaster(0)
......
......@@ -522,6 +522,21 @@ namespace scene
//! set user axis aligned bounding box
virtual void setBoundingBox(const core::aabbox3df& box);
//! Gets the default animation speed of the animated mesh.
/** \return Amount of frames per second. If the amount is 0, it is a static, non animated mesh. */
virtual f32 getAnimationSpeed() const
{
return FramesPerSecond;
}
//! Gets the frame count of the animated mesh.
/** \param fps Frames per second to play the animation with. If the amount is 0, it is not animated.
The actual speed is set in the scene node the mesh is instantiated in.*/
virtual void setAnimationSpeed(f32 fps)
{
FramesPerSecond=fps;
}
//! Get the Animation List
virtual IAnimationList* getAnimList () { return &AnimList; }
......@@ -554,6 +569,7 @@ namespace scene
u32 SequenceIndex; // sequence index
f32 CurrentFrame; // Current Frame
f32 FramesPerSecond;
#define MOUTH_CONTROLLER 4
u8 BoneController[4 + 1 ]; // bone controllers + mouth position
......
......@@ -219,7 +219,7 @@ static const SMD2AnimationType MD2AnimationTypeList[21] =
//! constructor
CAnimatedMeshMD2::CAnimatedMeshMD2()
: InterpolationBuffer(0), FrameList(0), FrameCount(0)
: InterpolationBuffer(0), FrameList(0), FrameCount(0), FramesPerSecond((f32)(MD2AnimationTypeList[0].fps << MD2_FRAME_SHIFT))
{
#ifdef _DEBUG
IAnimatedMesh::setDebugName("CAnimatedMeshMD2 IAnimatedMesh");
......@@ -455,4 +455,3 @@ const c8* CAnimatedMeshMD2::getAnimationName(s32 nr) const
} // end namespace irr
#endif // _IRR_COMPILE_WITH_MD2_LOADER_
......@@ -28,9 +28,24 @@ namespace scene
//! destructor
virtual ~CAnimatedMeshMD2();
//! returns the amount of frames in milliseconds. If the amount is 1, it is a static (=non animated) mesh.
//! returns the amount of frames. If the amount is 1, it is a static (=non animated) mesh.
virtual u32 getFrameCount() const;
//! Gets the default animation speed of the animated mesh.
/** \return Amount of frames per second. If the amount is 0, it is a static, non animated mesh. */
virtual f32 getAnimationSpeed() const
{
return FramesPerSecond;
}
//! Gets the frame count of the animated mesh.
/** \param fps Frames per second to play the animation with. If the amount is 0, it is not animated.
The actual speed is set in the scene node the mesh is instantiated in.*/
virtual void setAnimationSpeed(f32 fps)
{
FramesPerSecond=fps;
}
//! returns the animated mesh based on a detail level. 0 is the lowest, 255 the highest detail. Note, that some Meshes will ignore the detail level.
virtual IMesh* getMesh(s32 frame, s32 detailLevel=255, s32 startFrameLoop=-1, s32 endFrameLoop=-1);
......@@ -129,7 +144,7 @@ namespace scene
//! updates the interpolation buffer
void updateInterpolationBuffer(s32 frame, s32 startFrame, s32 endFrame);
f32 FramesPerSecond;
};
} // end namespace scene
......
......@@ -40,6 +40,22 @@ namespace scene
//IAnimatedMesh
virtual u32 getFrameCount() const;
//! Gets the default animation speed of the animated mesh.
/** \return Amount of frames per second. If the amount is 0, it is a static, non animated mesh. */
virtual f32 getAnimationSpeed() const
{
return FramesPerSecond;
}
//! Gets the frame count of the animated mesh.
/** \param fps Frames per second to play the animation with. If the amount is 0, it is not animated.
The actual speed is set in the scene node the mesh is instantiated in.*/
virtual void setAnimationSpeed(f32 fps)
{
FramesPerSecond=fps;
}
virtual IMesh* getMesh(s32 frame, s32 detailLevel,
s32 startFrameLoop, s32 endFrameLoop);
virtual const core::aabbox3d<f32>& getBoundingBox() const;
......@@ -108,6 +124,7 @@ namespace scene
SMeshBufferLightMap* dest);
void buildTagArray(u32 frameA, u32 frameB, f32 interpolate);
f32 FramesPerSecond;
};
......
......@@ -736,6 +736,9 @@ bool CB3DMeshFileLoader::readChunkANIM()
B3DFile->read(&animFlags, sizeof(s32));
B3DFile->read(&animFrames, sizeof(s32));
readFloats(&animFPS, 1);
if (animFPS>0.f)
AnimatedMesh->setAnimationSpeed(animFPS);
os::Printer::log("FPS", io::path(animFPS), ELL_DEBUG);
#ifdef __BIG_ENDIAN__
animFlags = os::Byteswap::byteswap(animFlags);
......
......@@ -403,6 +403,7 @@ bool CMS3DMeshFileLoader::load(io::IReadFile* file)
if (framesPerSecond<1.f)
framesPerSecond=1.f;
AnimatedMesh->setAnimationSpeed(framesPerSecond);
// ignore, calculated inside SkinnedMesh
// s32 frameCount = *(int*)pPtr;
......
......@@ -31,7 +31,8 @@ CQ3LevelMesh::CQ3LevelMesh(io::IFileSystem* fs, scene::ISceneManager* smgr,
Vertices(0), NumVertices(0), Faces(0), NumFaces(0), Models(0), NumModels(0),
Planes(0), NumPlanes(0), Nodes(0), NumNodes(0), Leafs(0), NumLeafs(0),
LeafFaces(0), NumLeafFaces(0), MeshVerts(0), NumMeshVerts(0),
Brushes(0), NumBrushes(0), BrushEntities(0), FileSystem(fs), SceneManager(smgr)
Brushes(0), NumBrushes(0), BrushEntities(0), FileSystem(fs),
SceneManager(smgr), FramesPerSecond(25.f)
{
#ifdef _DEBUG
IReferenceCounted::setDebugName("CQ3LevelMesh");
......
......@@ -38,6 +38,21 @@ namespace scene
//! is 1, it is a static (=non animated) mesh.
virtual u32 getFrameCount() const;
//! Gets the default animation speed of the animated mesh.
/** \return Amount of frames per second. If the amount is 0, it is a static, non animated mesh. */
virtual f32 getAnimationSpeed() const
{
return FramesPerSecond;
}
//! Gets the frame count of the animated mesh.
/** \param fps Frames per second to play the animation with. If the amount is 0, it is not animated.
The actual speed is set in the scene node the mesh is instantiated in.*/
virtual void setAnimationSpeed(f32 fps)
{
FramesPerSecond=fps;
}
//! returns the animated mesh based on a detail level. 0 is the
//! lowest, 255 the highest detail. Note, that some Meshes will
//! ignore the detail level.
......@@ -50,7 +65,6 @@ namespace scene
virtual void setBoundingBox( const core::aabbox3df& box);
//! Returns the type of the animated mesh.
virtual E_ANIMATED_MESH_TYPE getMeshType() const;
......@@ -467,6 +481,7 @@ namespace scene
void cleanLoader ();
void calcBoundingBoxes();
c8 buf[128];
f32 FramesPerSecond;
};
} // end namespace scene
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment