1
0
mirror of https://github.com/luanti-org/luanti.git synced 2025-10-12 16:15:20 +02:00

Support floating-point animation frame numbers

This commit is contained in:
Lars Mueller
2024-09-02 21:11:08 +02:00
committed by Lars Müller
parent 323fc0a798
commit 06907aa99b
22 changed files with 111 additions and 105 deletions

View File

@@ -19,11 +19,8 @@ irr::scene::SMeshBuffer etc. */
class IAnimatedMesh : public IMesh
{
public:
//! Gets the frame count of the animated mesh.
/** Note that the play-time is usually getFrameCount()-1 as it stops as soon as the last frame-key is reached.
\return The amount of frames. If the amount is 1,
it is a static, non animated mesh. */
virtual u32 getFrameCount() const = 0;
//! Gets the maximum frame number, 0 if the mesh is static.
virtual f32 getMaxFrameNumber() const = 0;
//! Gets the animation speed of the animated mesh.
/** \return The number of frames per second to play the
@@ -39,19 +36,10 @@ public:
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;
\param detailLevel: Level of detail. 0 is the lowest, 255 the
highest level of detail. Most meshes will ignore the detail level.
\param startFrameLoop: Because some animated meshes (.MD2) are
blended between 2 static frames, and maybe animated in a loop,
the startFrameLoop and the endFrameLoop have to be defined, to
prevent the animation to be blended between frames which are
outside of this loop.
If startFrameLoop and endFrameLoop are both -1, they are ignored.
\param endFrameLoop: see startFrameLoop.
\return Returns the animated mesh based on a detail level. */
virtual IMesh *getMesh(s32 frame, s32 detailLevel = 255, s32 startFrameLoop = -1, s32 endFrameLoop = -1) = 0;
/** \param frame: Frame number, >= 0, <= getMaxFrameNumber()
Linear interpolation is used if this is between two frames.
\return Returns the animated mesh for the given frame */
virtual IMesh *getMesh(f32 frame) = 0;
//! Returns the type of the animated mesh.
/** In most cases it is not necessary to use this method.

View File

@@ -63,7 +63,7 @@ public:
virtual void setCurrentFrame(f32 frame) = 0;
//! Sets the frame numbers between the animation is looped.
/** The default is 0 to getFrameCount()-1 of the mesh.
/** The default is 0 to getMaxFrameNumber() of the mesh.
Number of played frames is end-start.
It interpolates toward the last frame but stops when it is reached.
It does not interpolate back to start even when looping.
@@ -71,7 +71,7 @@ public:
\param begin: Start frame number of the loop.
\param end: End frame number of the loop.
\return True if successful, false if not. */
virtual bool setFrameLoop(s32 begin, s32 end) = 0;
virtual bool setFrameLoop(f32 begin, f32 end) = 0;
//! Sets the speed with which the animation is played.
/** \param framesPerSecond: Frames per second played. */
@@ -108,9 +108,9 @@ public:
//! Returns the currently displayed frame number.
virtual f32 getFrameNr() const = 0;
//! Returns the current start frame number.
virtual s32 getStartFrame() const = 0;
virtual f32 getStartFrame() const = 0;
//! Returns the current end frame number.
virtual s32 getEndFrame() const = 0;
virtual f32 getEndFrame() const = 0;
//! Sets looping mode which is on by default.
/** If set to false, animations will not be played looped. */

View File

@@ -36,11 +36,9 @@ struct SAnimatedMesh final : public IAnimatedMesh
mesh->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. */
u32 getFrameCount() const override
f32 getMaxFrameNumber() const override
{
return static_cast<u32>(Meshes.size());
return static_cast<f32>(Meshes.size() - 1);
}
//! Gets the default animation speed of the animated mesh.
@@ -59,19 +57,14 @@ struct SAnimatedMesh final : public IAnimatedMesh
}
//! Returns the IMesh interface for a frame.
/** \param frame: Frame number as zero based index. The maximum frame number is
getFrameCount() - 1;
\param detailLevel: Level of detail. 0 is the lowest,
255 the highest level of detail. Most meshes will ignore the detail level.
\param startFrameLoop: start frame
\param endFrameLoop: end frame
\return The animated mesh based on a detail level. */
IMesh *getMesh(s32 frame, s32 detailLevel = 255, s32 startFrameLoop = -1, s32 endFrameLoop = -1) override
/** \param frame: Frame number as zero based index.
\return The animated mesh based for the given frame */
IMesh *getMesh(f32 frame) override
{
if (Meshes.empty())
return 0;
return nullptr;
return Meshes[frame];
return Meshes[static_cast<s32>(frame)];
}
//! adds a Mesh

View File

@@ -38,6 +38,12 @@ public:
explicit constexpr vector2d(const std::array<T, 2> &arr) :
X(arr[0]), Y(arr[1]) {}
template <class U>
constexpr static vector2d<T> from(const vector2d<U> &other)
{
return {static_cast<T>(other.X), static_cast<T>(other.Y)};
}
// operators
vector2d<T> operator-() const { return vector2d<T>(-X, -Y); }