Skip to content
Closed
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ node_modules
cmake-build-debug
.idea
docs
/.vs
4 changes: 2 additions & 2 deletions include/Mesh.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class Mesh : public MeshUnmanaged {
other.indices = nullptr;
other.animVertices = nullptr;
other.animNormals = nullptr;
other.boneIds = nullptr;
other.boneIndices = nullptr;
other.boneWeights = nullptr;
other.vaoId = 0;
other.vboId = nullptr;
Expand All @@ -73,7 +73,7 @@ class Mesh : public MeshUnmanaged {
other.indices = nullptr;
other.animVertices = nullptr;
other.animNormals = nullptr;
other.boneIds = nullptr;
other.boneIndices = nullptr;
other.boneWeights = nullptr;
other.vaoId = 0;
other.vboId = nullptr;
Expand Down
8 changes: 3 additions & 5 deletions include/MeshUnmanaged.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,8 @@ class MeshUnmanaged : public ::Mesh {
indices = nullptr;
animVertices = nullptr;
animNormals = nullptr;
boneIds = nullptr;
boneIndices = nullptr;
boneWeights = nullptr;
boneMatrices = nullptr;
boneCount = 0;
vaoId = 0;
vboId = nullptr;
Expand Down Expand Up @@ -130,7 +129,7 @@ class MeshUnmanaged : public ::Mesh {
GETTERSETTER(unsigned short*, Indices, indices) // NOLINT
GETTERSETTER(float*, AnimVertices, animVertices)
GETTERSETTER(float*, AnimNormals, animNormals)
GETTERSETTER(unsigned char*, BoneIds, boneIds)
GETTERSETTER(unsigned char*, BoneIndices, boneIndices)
GETTERSETTER(float*, BoneWeights, boneWeights)
GETTERSETTER(unsigned int, VaoId, vaoId)
GETTERSETTER(unsigned int*, VboId, vboId)
Expand Down Expand Up @@ -242,9 +241,8 @@ class MeshUnmanaged : public ::Mesh {
indices = mesh.indices;
animVertices = mesh.animVertices;
animNormals = mesh.animNormals;
boneIds = mesh.boneIds;
boneIndices = mesh.boneIndices;
boneWeights = mesh.boneWeights;
boneMatrices = mesh.boneMatrices;
vaoId = mesh.vaoId;
vboId = mesh.vboId;
}
Expand Down
40 changes: 25 additions & 15 deletions include/Model.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,13 @@ class Model : public ::Model {
other.meshes = nullptr;
other.materials = nullptr;
other.meshMaterial = nullptr;
other.boneCount = 0;
other.bones = nullptr;
other.bindPose = nullptr;

other.skeleton.boneCount = 0;
other.skeleton.bones = nullptr;
other.skeleton.bindPose = nullptr;

ModelAnimPose currentPose;
Matrix *boneMatrices;
}

GETTERSETTER(::Matrix, Transform, transform)
Expand All @@ -69,9 +73,11 @@ class Model : public ::Model {
GETTERSETTER(::Mesh*, Meshes, meshes)
GETTERSETTER(::Material*, Materials, materials)
GETTERSETTER(int*, MeshMaterial, meshMaterial)
GETTERSETTER(int, BoneCount, boneCount)
GETTERSETTER(::BoneInfo*, Bones, bones)
GETTERSETTER(::Transform*, BindPose, bindPose)
GETTERSETTER(int, BoneCount, skeleton.boneCount)
GETTERSETTER(::BoneInfo*, Bones, skeleton.bones)
GETTERSETTER(::Transform*, BindPose, skeleton.bindPose)
GETTERSETTER(::ModelAnimPose, CurrentPose, currentPose)
GETTERSETTER(::Matrix*, BoneMatrices, boneMatrices)

Model& operator=(const ::Model& model) {
set(model);
Expand All @@ -93,9 +99,11 @@ class Model : public ::Model {
other.meshes = nullptr;
other.materials = nullptr;
other.meshMaterial = nullptr;
other.boneCount = 0;
other.bones = nullptr;
other.bindPose = nullptr;
other.skeleton.boneCount = 0;
other.skeleton.bones = nullptr;
other.skeleton.bindPose = nullptr;
other.currentPose = nullptr;
other.boneMatrices = nullptr;

return *this;
}
Expand All @@ -122,16 +130,16 @@ class Model : public ::Model {
/**
* Update model animation pose
*/
Model& UpdateAnimation(const ::ModelAnimation& anim, int frame) {
Model& UpdateAnimation(const ::ModelAnimation& anim, float frame) {
::UpdateModelAnimation(*this, anim, frame);
return *this;
}

/**
* Update model animation pose
*/
Model& UpdateAnimationBones(const ::ModelAnimation& anim, int frame) {
::UpdateModelAnimationBones(*this, anim, frame);
Model& UpdateAnimationsEx(const ::ModelAnimation& animA, float frameA, const ::ModelAnimation& animB, float frameB, float blend) {
::UpdateModelAnimationEx(*this, animA, frameA, animB, frameB, blend);
return *this;
}

Expand Down Expand Up @@ -240,9 +248,11 @@ class Model : public ::Model {
materials = model.materials;
meshMaterial = model.meshMaterial;

boneCount = model.boneCount;
bones = model.bones;
bindPose = model.bindPose;
skeleton.boneCount = model.skeleton.boneCount;
skeleton.bones = model.skeleton.bones;
skeleton.bindPose = model.skeleton.bindPose;
currentPose = model.currentPose;
boneMatrices = model.boneMatrices;
}
};

Expand Down
29 changes: 13 additions & 16 deletions include/ModelAnimation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ class ModelAnimation : public ::ModelAnimation {
set(other);

other.boneCount = 0;
other.frameCount = 0;
other.bones = nullptr;
other.framePoses = nullptr;
other.keyframeCount = 0;
other.keyframePoses = nullptr;
}

~ModelAnimation() { Unload(); }
// TODO: Implement a way to unload all animations at once, as the current Unload() only unloads one animation.
~ModelAnimation() { Unload(1); }

/**
* Load model animations from file
Expand All @@ -43,9 +43,8 @@ class ModelAnimation : public ::ModelAnimation {
}

GETTERSETTER(int, BoneCount, boneCount)
GETTERSETTER(::BoneInfo*, Bones, bones)
GETTERSETTER(int, FrameCount, frameCount)
GETTERSETTER(::Transform**, FramePoses, framePoses)
GETTERSETTER(int, KeyframeCount, keyframeCount)
GETTERSETTER(::Transform**, KeyframePoses, keyframePoses)

ModelAnimation& operator=(const ::ModelAnimation& model) {
set(model);
Expand All @@ -59,21 +58,20 @@ class ModelAnimation : public ::ModelAnimation {
return *this;
}

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

other.boneCount = 0;
other.frameCount = 0;
other.bones = nullptr;
other.framePoses = nullptr;
other.keyframeCount = 0;
other.keyframePoses = nullptr;

return *this;
}

/**
* Unload animation data
*/
void Unload() { ::UnloadModelAnimation(*this); }
void Unload(int animCount) { ::UnloadModelAnimations(this, animCount); }

/**
* Update model animation pose
Expand All @@ -87,7 +85,7 @@ class ModelAnimation : public ::ModelAnimation {
* Update model animation mesh bone matrices (GPU skinning)
*/
ModelAnimation& UpdateBones(const ::Model& model, int frame) {
::UpdateModelAnimationBones(model, *this, frame);
::UpdateModelAnimation(model, *this, frame);
return *this;
}

Expand All @@ -98,9 +96,8 @@ class ModelAnimation : public ::ModelAnimation {
protected:
void set(const ::ModelAnimation& model) {
boneCount = model.boneCount;
frameCount = model.frameCount;
bones = model.bones;
framePoses = model.framePoses;
keyframeCount = model.keyframeCount;
keyframePoses = model.keyframePoses;

// Duplicate the name. TextCopy() uses the null terminator, which we ignore here.
for (int i = 0; i < 32; i++) {
Expand Down
Loading