| 369 | } |
| 370 | |
| 371 | void ConvertTransformModifier3D::_process_convert(int p_index, Skeleton3D *p_skeleton, int p_apply_bone, const Transform3D &p_destination, float p_amount) { |
| 372 | ConvertTransform3DSetting *setting = static_cast<ConvertTransform3DSetting *>(settings[p_index]); |
| 373 | |
| 374 | Transform3D destination = p_destination; |
| 375 | |
| 376 | // Retrieve point from reference. |
| 377 | double point = 0.0; |
| 378 | int axis = (int)setting->reference_axis; |
| 379 | switch (setting->reference_transform_mode) { |
| 380 | case TRANSFORM_MODE_POSITION: { |
| 381 | point = destination.origin[axis]; |
| 382 | } break; |
| 383 | case TRANSFORM_MODE_ROTATION: { |
| 384 | Quaternion tgt_rot = destination.basis.get_rotation_quaternion(); |
| 385 | point = get_roll_angle(tgt_rot, get_vector_from_axis(setting->reference_axis)); |
| 386 | } break; |
| 387 | case TRANSFORM_MODE_SCALE: { |
| 388 | point = destination.basis.get_scale()[axis]; |
| 389 | } break; |
| 390 | } |
| 391 | // Convert point to apply. |
| 392 | destination = p_skeleton->get_bone_pose(p_apply_bone); |
| 393 | if (Math::is_equal_approx(setting->reference_range_min, setting->reference_range_max)) { |
| 394 | point = point <= (double)setting->reference_range_min ? 0 : 1; |
| 395 | } else { |
| 396 | point = Math::inverse_lerp((double)setting->reference_range_min, (double)setting->reference_range_max, point); |
| 397 | } |
| 398 | point = Math::lerp((double)setting->apply_range_min, (double)setting->apply_range_max, CLAMP(point, 0, 1)); |
| 399 | axis = (int)setting->apply_axis; |
| 400 | switch (setting->apply_transform_mode) { |
| 401 | case TRANSFORM_MODE_POSITION: { |
| 402 | if (setting->additive) { |
| 403 | point = p_skeleton->get_bone_pose(p_apply_bone).origin[axis] + point; |
| 404 | } else if (setting->is_relative()) { |
| 405 | point = p_skeleton->get_bone_rest(p_apply_bone).origin[axis] + point; |
| 406 | } |
| 407 | destination.origin[axis] = point; |
| 408 | } break; |
| 409 | case TRANSFORM_MODE_ROTATION: { |
| 410 | Vector3 rot_axis = get_vector_from_axis(setting->apply_axis); |
| 411 | Vector3 dest_scl = destination.basis.get_scale(); |
| 412 | if (influence < 1.0 || p_amount < 1.0) { |
| 413 | point = CLAMP(point, CMP_EPSILON - Math::PI, Math::PI - CMP_EPSILON); /// @todo HACK to consistent slerp (interpolate_with) orientation since -180/180 deg rot is mixed in slerp. |
| 414 | } |
| 415 | Quaternion rot = Quaternion(rot_axis, point); |
| 416 | if (setting->additive) { |
| 417 | destination.basis = p_skeleton->get_bone_pose(p_apply_bone).basis.get_rotation_quaternion() * rot; |
| 418 | } else if (setting->is_relative()) { |
| 419 | destination.basis = p_skeleton->get_bone_rest(p_apply_bone).basis.get_rotation_quaternion() * rot; |
| 420 | } else { |
| 421 | destination.basis = rot; |
| 422 | } |
| 423 | // Scale may not have meaning, but it might affect when it is negative. |
| 424 | destination.basis.scale_local(dest_scl); |
| 425 | } break; |
| 426 | case TRANSFORM_MODE_SCALE: { |
| 427 | Vector3 dest_scl = Vector3(1, 1, 1); |
| 428 | if (setting->additive) { |
nothing calls this directly
no test coverage detected