Skip to content

Commit d2cf487

Browse files
committed
Make silhouette fixer use arc Quaternion constrructor instead look_at
1 parent 1b4ed4c commit d2cf487

File tree

1 file changed

+6
-22
lines changed

1 file changed

+6
-22
lines changed

editor/import/3d/post_import_plugin_skeleton_rest_fixer.cpp

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -367,31 +367,15 @@ void PostImportPluginSkeletonRestFixer::internal_process(InternalImportCategory
367367

368368
Vector3 prof_dir = prof_tail - prof_head;
369369
Vector3 src_dir = src_tail - src_head;
370+
if (Math::is_zero_approx(prof_dir.length_squared()) || Math::is_zero_approx(src_dir.length_squared())) {
371+
continue;
372+
}
373+
prof_dir.normalize();
374+
src_dir.normalize();
370375

371376
// Rotate rest.
372377
if (Math::abs(Math::rad_to_deg(src_dir.angle_to(prof_dir))) > float(p_options["retarget/rest_fixer/fix_silhouette/threshold"])) {
373-
// Get rotation difference.
374-
Vector3 up_vec; // Need to rotate other than roll axis.
375-
switch (Vector3(std::abs(src_dir.x), std::abs(src_dir.y), std::abs(src_dir.z)).min_axis_index()) {
376-
case Vector3::AXIS_X: {
377-
up_vec = Vector3(1, 0, 0);
378-
} break;
379-
case Vector3::AXIS_Y: {
380-
up_vec = Vector3(0, 1, 0);
381-
} break;
382-
case Vector3::AXIS_Z: {
383-
up_vec = Vector3(0, 0, 1);
384-
} break;
385-
}
386-
Basis src_b;
387-
src_b = src_b.looking_at(src_dir, up_vec);
388-
Basis prof_b;
389-
prof_b = src_b.looking_at(prof_dir, up_vec);
390-
if (prof_b.is_equal_approx(Basis())) {
391-
continue; // May not need to rotate.
392-
}
393-
Basis diff_b = prof_b * src_b.inverse();
394-
378+
Basis diff_b = Basis(Quaternion(src_dir, prof_dir));
395379
// Apply rotation difference as global transform to skeleton.
396380
Basis src_pg;
397381
int src_parent = src_skeleton->get_bone_parent(src_idx);

0 commit comments

Comments
 (0)