Skip to content

Commit

Permalink
Renames job transform
Browse files Browse the repository at this point in the history
  • Loading branch information
guillaumeblanc committed May 20, 2024
1 parent e409377 commit a0520c5
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion include/ozz/animation/runtime/motion_blending_job.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ struct OZZ_ANIMATION_DLL MotionBlendingJob {
float weight = 0.f;

// The motion delta transform to be blended.
const math::Transform* transform = nullptr;
const math::Transform* delta = nullptr;
};

// Job input layers, can be empty or nullptr.
Expand Down
2 changes: 1 addition & 1 deletion samples/motion_blend/sample_motion_blend.cc
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ class MotionBlendSampleApplication : public ozz::sample::Application {
ozz::animation::MotionBlendingJob::Layer layers[kNumLayers];
for (size_t i = 0; i < kNumLayers; ++i) {
const auto& sampler = samplers_[i];
layers[i].transform = &sampler.motion_sampler.delta;
layers[i].delta = &sampler.motion_sampler.delta;
layers[i].weight = sampler.weight;
}

Expand Down
10 changes: 5 additions & 5 deletions src/animation/runtime/motion_blending_job.cc
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ bool MotionBlendingJob::Validate() const {

// Validates layers.
for (const Layer& layer : layers) {
valid &= layer.transform != nullptr;
valid &= layer.delta != nullptr;
}

return valid;
Expand All @@ -65,16 +65,16 @@ bool MotionBlendingJob::Run() const {

// Decomposes translation into a normalized vector and a length, to limit
// lerp error while interpolating vector length.
const float len = Length(layer.transform->translation);
const float len = Length(layer.delta->translation);
dl = dl + len * weight;
const float denom = (len == 0.f) ? 0.f : weight / len;
dt = dt + layer.transform->translation * denom;
dt = dt + layer.delta->translation * denom;

// Accumulates weighted rotation (NLerp). Makes sure quaternions are on the
// same hemisphere to lerp the shortest arc (using -Q otherwise).
const float signed_weight =
std::copysign(weight, Dot(dr, layer.transform->rotation));
dr = dr + layer.transform->rotation * signed_weight;
std::copysign(weight, Dot(dr, layer.delta->rotation));
dr = dr + layer.delta->rotation * signed_weight;
}

// Normalizes (weights) and fills output.
Expand Down
8 changes: 4 additions & 4 deletions test/animation/runtime/motion_blending_job_tests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@ TEST(Validate, MotionBlendingJob) {
EXPECT_FALSE(job.Validate());

ozz::math::Transform transforms[2];
layers[0].transform = &transforms[0];
layers[0].delta = &transforms[0];
EXPECT_FALSE(job.Validate());

layers[1].transform = &transforms[1];
layers[1].delta = &transforms[1];
EXPECT_TRUE(job.Validate());
}

Expand Down Expand Up @@ -86,8 +86,8 @@ TEST(Run, MotionBlendingJob) {
transforms[1].rotation = {-0.f, -.70710677f, -0.f, -.70710677f};

MotionBlendingJob::Layer layers[2];
layers[0].transform = &transforms[0];
layers[1].transform = &transforms[1];
layers[0].delta = &transforms[0];
layers[1].delta = &transforms[1];
job.layers = layers;

// 0 weights
Expand Down

0 comments on commit a0520c5

Please sign in to comment.