Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Additive rotation fix #152

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/animation/offline/additive_animation_builder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ math::Float3 MakeDeltaTranslation(const math::Float3& _reference,

math::Quaternion MakeDeltaRotation(const math::Quaternion& _reference,
const math::Quaternion& _value) {
return _value * Conjugate(_reference);
return Conjugate(_reference) * _value;
}

math::Float3 MakeDeltaScale(const math::Float3& _reference,
Expand Down
4 changes: 2 additions & 2 deletions src/animation/runtime/blending_job.cc
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ namespace {
const math::SoaQuaternion interp_quat = { \
rotation.x * _simd_weight, rotation.y * _simd_weight, \
rotation.z * _simd_weight, (rotation.w - one) * _simd_weight + one}; \
_out.rotation = NormalizeEst(interp_quat) * _out.rotation; \
_out.rotation = _out.rotation * NormalizeEst(interp_quat); \
_out.scale = \
_out.scale * (one_minus_weight_f3 + (_in.scale * _simd_weight)); \
} while (void(0), 0)
Expand All @@ -147,7 +147,7 @@ namespace {
const math::SoaQuaternion interp_quat = { \
rotation.x * _simd_weight, rotation.y * _simd_weight, \
rotation.z * _simd_weight, (rotation.w - one) * _simd_weight + one}; \
_out.rotation = Conjugate(NormalizeEst(interp_quat)) * _out.rotation; \
_out.rotation = _out.rotation * Conjugate(NormalizeEst(interp_quat)); \
const math::SoaFloat3 rcp_scale = { \
math::RcpEst(math::MAdd(_in.scale.x, _simd_weight, one_minus_weight)), \
math::RcpEst(math::MAdd(_in.scale.y, _simd_weight, one_minus_weight)), \
Expand Down
53 changes: 53 additions & 0 deletions test/animation/runtime/blending_job_tests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -781,6 +781,59 @@ TEST(AdditiveWeight, BlendingJob) {
}
}

TEST(AdditiveRotationFromNonIdentity, BlendingJob) {
using ozz::math::GetW;
using ozz::math::GetX;
using ozz::math::GetY;
using ozz::math::GetZ;

const ozz::math::SoaTransform identity = ozz::math::SoaTransform::identity();

// Initialize rest pose.
ozz::math::SoaTransform rest_poses[1] = {identity};
rest_poses[0].rotation = ozz::math::SoaQuaternion::Load(
ozz::math::simd_float4::Load(0.f, .70710677f, .382683432f, 0.f),
ozz::math::simd_float4::Load(0.f, 0.f, 0.f, .70710677f),
ozz::math::simd_float4::Load(0.f, 0.f, 0.f, 0.f),
ozz::math::simd_float4::Load(1.f, .70710677f, .9238795f, -.70710677f));

// Initialize inputs.
ozz::math::SoaQuaternion input_half_rotation = ozz::math::SoaQuaternion::Load(
ozz::math::simd_float4::Load(.70710677f, 0.f, 0.f, .382683432f),
ozz::math::simd_float4::Load(0.f, 0.f, .70710677f, 0.f),
ozz::math::simd_float4::Load(0.f, 0.f, 0.f, 0.f),
ozz::math::simd_float4::Load(.70710677f, 1.f, -.70710677f, .9238795f));
ozz::math::SoaTransform input_transforms[1] = {identity};
input_transforms[0].rotation = input_half_rotation * input_half_rotation;

ozz::math::SoaQuaternion expected_rotation =
rest_poses[0].rotation *
Conjugate(input_half_rotation * input_half_rotation);
constexpr float weights[]{-1.0f, -0.5f, 0.0f, 0.5f, 1.0f};
for (float weight : weights) {
BlendingJob::Layer layers[1];
layers[0].transform = input_transforms;

ozz::math::SoaTransform output_transforms[1];

BlendingJob job;
job.additive_layers = layers;
job.rest_pose = rest_poses;
job.output = output_transforms;

layers[0].weight = weight;
EXPECT_TRUE(job.Run());

ozz::math::SimdFloat4 dot =
ozz::math::Dot(expected_rotation, output_transforms[0].rotation);
ozz::math::SimdFloat4 distance =
ozz::math::simd_float4::one() - (dot * dot);
EXPECT_SIMDFLOAT_EQ_EST(distance, 0.0f, 0.0f, 0.0f, 0.0f);

expected_rotation = expected_rotation * input_half_rotation;
}
}

TEST(AdditiveJointWeight, BlendingJob) {
const ozz::math::SoaTransform identity = ozz::math::SoaTransform::identity();

Expand Down