Skip to content
4 changes: 4 additions & 0 deletions include/Matrix.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,12 @@ class Matrix : public ::Matrix {

[[nodiscard]] Matrix Multiply(const ::Matrix& right) const { return ::MatrixMultiply(*this, right); }

[[nodiscard]] Matrix Multiply(float value) const { return ::MatrixMultiplyValue(*this, value); }

Matrix operator*(const ::Matrix& matrix) { return ::MatrixMultiply(*this, matrix); }

Matrix operator*(float value) { return ::MatrixMultiplyValue(*this, value); }

static Matrix Frustum(double left, double right, double bottom, double top, double near, double far) {
return ::MatrixFrustum(left, right, bottom, top, near, far);
}
Expand Down
4 changes: 2 additions & 2 deletions include/Model.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,9 @@ class Model : public ::Model {
}

/**
* Update model animation pose
* Blend two model animation poses
*/
Model& UpdateAnimationsEx(const ::ModelAnimation& animA, float frameA, const ::ModelAnimation& animB, float frameB, float blend) {
Model& BlendAnimation(const ::ModelAnimation& animA, float frameA, const ::ModelAnimation& animB, float frameB, float blend) {
::UpdateModelAnimationEx(*this, animA, frameA, animB, frameB, blend);
return *this;
}
Expand Down
24 changes: 16 additions & 8 deletions include/ModelAnimation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,16 @@ class ModelAnimation : public ::ModelAnimation {
other.keyframePoses = nullptr;
}

// TODO: Implement a way to unload all animations at once, as the current Unload() only unloads one animation.
~ModelAnimation() { Unload(1); }
// Unloads animation data using populated animCount field, which is set by Load() method.
~ModelAnimation() { Unload(); }

/**
* Load model animations from file
*/
static std::vector<ModelAnimation> Load(const std::string& fileName) {
int count = 0;
::ModelAnimation* modelAnimations = ::LoadModelAnimations(fileName.c_str(), &count);

std::vector<ModelAnimation> mats(modelAnimations, modelAnimations + count);

RL_FREE(modelAnimations);
Expand All @@ -58,7 +59,7 @@ class ModelAnimation : public ::ModelAnimation {
return *this;
}

Unload(1);
Unload();
set(other);

other.boneCount = 0;
Expand All @@ -71,24 +72,31 @@ class ModelAnimation : public ::ModelAnimation {
/**
* Unload animation data
*/
void Unload(int animCount) { ::UnloadModelAnimations(this, animCount); }
void Unload() {
::UnloadModelAnimations(this, 1);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's an int* animCount that's returned when calling LoadModelAnimations(). Would there be a way for us to leverage that so that we don't have to worry about unloading 1 when there could be 10?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In order to use the populated int* animCount, we would have to make the Load() function a non-static method, such that it can store the object's animCount in an attribute and use in while unloading.

however, making it so requires a ModelAnimation object to call load, that may defeat the design philosphy of raylib. I will try to think of a workaround. The current workaround for this would be to use function overloading. Have the Unload() optionally accept an animCount. This assumes the programmer knows how many animations are loaded.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmmm, that is a challenge. Surprised it's not kept in the ModelAnimation struct itself.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After talking to raysan, it is my understanding that UnloadModelAnimations() is meant to unload an array of animations, and a ModelAnimation object would only have 1. In that case, i believe there should a UnloadAnimations(int animCount) static method can be called with an array of animations, along with Unload() to unload the animation data of the object that calls it.

I have implemented the same.

}

static void Unload(ModelAnimation *modelAnimation, int count) {
::UnloadModelAnimations(modelAnimation, count);
}

/**
* Update model animation pose
*/
ModelAnimation& Update(const ::Model& model, int frame) {
ModelAnimation& Update(const ::Model& model, float frame) {
::UpdateModelAnimation(model, *this, frame);
return *this;
}

/**
* Update model animation mesh bone matrices (GPU skinning)
* Blend two animation poses
*/
ModelAnimation& UpdateBones(const ::Model& model, int frame) {
::UpdateModelAnimation(model, *this, frame);
ModelAnimation& Blend(const ::Model& model, float frameA, const ::ModelAnimation& animB, float frameB, float blend) {
::UpdateModelAnimationEx(model, *this, frameA, animB, frameB, blend);
return *this;
}


/**
* Check model animation skeleton match
*/
Expand Down