summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFrederico Linhares <fred@linhares.blue>2025-03-19 16:20:37 -0300
committerFrederico Linhares <fred@linhares.blue>2025-03-21 11:42:09 -0300
commit600a4f7586a31990cfdb02ab811768ca6afc909e (patch)
treece400e93af563e2049b85f604314773d1dae899d
parent96228c92004fefae3cb3392c20d90ec4ede753cd (diff)
fixt Use bone from mesh when animating model
* src/blu_cat/gra/skeletal_model.cpp (SkeletalModel::tick): Use bone position from mesh. Not using it was a bug.
-rw-r--r--src/blu_cat/com/binary_writer.cpp2
-rw-r--r--src/blu_cat/gra/skeletal_model.cpp75
-rw-r--r--test/meshes/cuboid.cgmeshbin2800 -> 2800 bytes
3 files changed, 39 insertions, 38 deletions
diff --git a/src/blu_cat/com/binary_writer.cpp b/src/blu_cat/com/binary_writer.cpp
index 0c4cace..7a987d4 100644
--- a/src/blu_cat/com/binary_writer.cpp
+++ b/src/blu_cat/com/binary_writer.cpp
@@ -16,8 +16,6 @@
#include "binary_writer.hpp"
-#include <iostream>
-
namespace
{
diff --git a/src/blu_cat/gra/skeletal_model.cpp b/src/blu_cat/gra/skeletal_model.cpp
index b58982d..4b44910 100644
--- a/src/blu_cat/gra/skeletal_model.cpp
+++ b/src/blu_cat/gra/skeletal_model.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright 2022-2024 Frederico de Oliveira Linhares
+ * Copyright 2022-2025 Frederico de Oliveira Linhares
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -192,47 +192,50 @@ SkeletalModel::tick(float delta)
for(int i{0}; i < current_animation->bone_transforms.size(); i++)
{
- BluCat::GRA::BoneTransform *bone_transform = &current_animation->bone_transforms[i];
+ BluCat::GRA::BoneTransform *bone_transform =
+ &current_animation->bone_transforms[i];
auto position{bone_transform->positions.interpolate(
- this->animation_time,
- [](glm::vec3 frame)
- {
- return glm::translate(glm::mat4(1.0f), frame);
- },
- [](glm::vec3 previous_frame, glm::vec3 next_frame, float scale_factor)
- {
- glm::vec3 final_position{glm::mix(
- previous_frame, next_frame, scale_factor)};
- return glm::translate(glm::mat4(1.0f), final_position);
- })};
+ this->animation_time,
+ [](glm::vec3 frame)
+ {
+ return glm::translate(glm::mat4(1.0f), frame);
+ },
+ [](glm::vec3 previous_frame, glm::vec3 next_frame, float scale_factor)
+ {
+ glm::vec3 final_position{glm::mix(
+ previous_frame, next_frame, scale_factor)};
+ return glm::translate(glm::mat4(1.0f), final_position);
+ })};
auto rotation{bone_transform->rotations.interpolate(
- this->animation_time,
- [](glm::quat frame)
- {
- return glm::toMat4(glm::normalize(frame));
- },
- [](glm::quat previous_frame, glm::quat next_frame, float scale_factor)
- {
- return glm::toMat4(glm::slerp(
- previous_frame, next_frame, scale_factor));
- })};
+ this->animation_time,
+ [](glm::quat frame)
+ {
+ return glm::toMat4(glm::normalize(frame));
+ },
+ [](glm::quat previous_frame, glm::quat next_frame, float scale_factor)
+ {
+ return glm::toMat4(glm::slerp(
+ previous_frame, next_frame, scale_factor));
+ })};
auto scale{bone_transform->scales.interpolate(
- this->animation_time,
- [](glm::vec3 frame)
- {
- return glm::scale(glm::mat4(1.0f), frame);
- },
- [](glm::vec3 previous_frame, glm::vec3 next_frame, float scale_factor)
- {
- glm::vec3 scale{glm::mix(
- previous_frame, next_frame, scale_factor)};
- return glm::scale(glm::mat4(1.0f), scale);
- })};
-
- this->bone_transforms[i] = position * rotation * scale;
+ this->animation_time,
+ [](glm::vec3 frame)
+ {
+ return glm::scale(glm::mat4(1.0f), frame);
+ },
+ [](glm::vec3 previous_frame, glm::vec3 next_frame, float scale_factor)
+ {
+ glm::vec3 scale{glm::mix(
+ previous_frame, next_frame, scale_factor)};
+ return glm::scale(glm::mat4(1.0f), scale);
+ })};
+
+ this->bone_transforms[i] =
+ this->skeletal_mesh->bones[i].offset_matrix *
+ (position * rotation * scale);
}
}
diff --git a/test/meshes/cuboid.cgmesh b/test/meshes/cuboid.cgmesh
index aa95118..79a643a 100644
--- a/test/meshes/cuboid.cgmesh
+++ b/test/meshes/cuboid.cgmesh
Binary files differ