Merge pull request #53689 from reduz/remove-animation-transform3d-track
This commit is contained in:
commit
3e86ca5586
29 changed files with 1952 additions and 1419 deletions
|
|
@ -1011,9 +1011,7 @@ Node3D *EditorSceneImporterFBX::_generate_scene(
|
|||
// track count is 5.
|
||||
// next track id is 5.
|
||||
const uint64_t target_id = track.key;
|
||||
int track_idx = animation->add_track(Animation::TYPE_TRANSFORM3D);
|
||||
|
||||
// animation->track_set_path(track_idx, node_path);
|
||||
Ref<FBXBone> bone;
|
||||
|
||||
// note we must not run the below code if the entry doesn't exist, it will create dummy entries which is very bad.
|
||||
|
|
@ -1037,22 +1035,21 @@ Node3D *EditorSceneImporterFBX::_generate_scene(
|
|||
|
||||
// if this is a skeleton mapped track we can just set the path for the track.
|
||||
// todo: implement node paths here at some
|
||||
NodePath track_path;
|
||||
if (state.fbx_bone_map.size() > 0 && state.fbx_bone_map.has(target_id)) {
|
||||
if (bone->fbx_skeleton.is_valid() && bone.is_valid()) {
|
||||
Ref<FBXSkeleton> fbx_skeleton = bone->fbx_skeleton;
|
||||
String bone_path = state.root->get_path_to(fbx_skeleton->skeleton);
|
||||
bone_path += ":" + fbx_skeleton->skeleton->get_bone_name(bone->godot_bone_id);
|
||||
print_verbose("[doc] track bone path: " + bone_path);
|
||||
NodePath path = bone_path;
|
||||
animation->track_set_path(track_idx, path);
|
||||
track_path = bone_path;
|
||||
}
|
||||
} else if (state.fbx_target_map.has(target_id)) {
|
||||
//print_verbose("[doc] we have a valid target for a node animation");
|
||||
Ref<FBXNode> target_node = state.fbx_target_map[target_id];
|
||||
if (target_node.is_valid() && target_node->godot_node != nullptr) {
|
||||
String node_path = state.root->get_path_to(target_node->godot_node);
|
||||
NodePath path = node_path;
|
||||
animation->track_set_path(track_idx, path);
|
||||
track_path = node_path;
|
||||
//print_verbose("[doc] node animation path: " + node_path);
|
||||
}
|
||||
} else {
|
||||
|
|
@ -1186,6 +1183,30 @@ Node3D *EditorSceneImporterFBX::_generate_scene(
|
|||
const Vector3 def_scale = scale_keys.has_default ? scale_keys.default_value : bone_rest.basis.get_scale();
|
||||
print_verbose("track defaults: p(" + def_pos + ") s(" + def_scale + ") r(" + def_rot + ")");
|
||||
|
||||
int position_idx = -1;
|
||||
if (pos_values.size()) {
|
||||
position_idx = animation->get_track_count();
|
||||
animation->add_track(Animation::TYPE_POSITION_3D);
|
||||
animation->track_set_path(position_idx, track_path);
|
||||
animation->track_set_imported(position_idx, true);
|
||||
}
|
||||
|
||||
int rotation_idx = -1;
|
||||
if (pos_values.size()) {
|
||||
rotation_idx = animation->get_track_count();
|
||||
animation->add_track(Animation::TYPE_ROTATION_3D);
|
||||
animation->track_set_path(rotation_idx, track_path);
|
||||
animation->track_set_imported(rotation_idx, true);
|
||||
}
|
||||
|
||||
int scale_idx = -1;
|
||||
if (pos_values.size()) {
|
||||
scale_idx = animation->get_track_count();
|
||||
animation->add_track(Animation::TYPE_SCALE_3D);
|
||||
animation->track_set_path(scale_idx, track_path);
|
||||
animation->track_set_imported(scale_idx, true);
|
||||
}
|
||||
|
||||
while (true) {
|
||||
Vector3 pos = def_pos;
|
||||
Quaternion rot = def_rot;
|
||||
|
|
@ -1220,7 +1241,15 @@ Node3D *EditorSceneImporterFBX::_generate_scene(
|
|||
pos = t.origin;
|
||||
}
|
||||
|
||||
animation->transform_track_insert_key(track_idx, time, pos, rot, scale);
|
||||
if (position_idx >= 0) {
|
||||
animation->position_track_insert_key(position_idx, time, pos);
|
||||
}
|
||||
if (rotation_idx >= 0) {
|
||||
animation->rotation_track_insert_key(rotation_idx, time, rot);
|
||||
}
|
||||
if (scale_idx >= 0) {
|
||||
animation->scale_track_insert_key(scale_idx, time, scale);
|
||||
}
|
||||
|
||||
if (last) {
|
||||
break;
|
||||
|
|
|
|||
|
|
@ -5733,7 +5733,7 @@ struct EditorSceneImporterGLTFInterpolate<Quaternion> {
|
|||
template <class T>
|
||||
T GLTFDocument::_interpolate_track(const Vector<float> &p_times, const Vector<T> &p_values, const float p_time, const GLTFAnimation::Interpolation p_interp) {
|
||||
ERR_FAIL_COND_V(!p_values.size(), T());
|
||||
if (p_times.size() != p_values.size()) {
|
||||
if (p_times.size() != (p_values.size() / (p_interp == GLTFAnimation::INTERP_CUBIC_SPLINE ? 3 : 1))) {
|
||||
ERR_PRINT_ONCE("The interpolated values are not corresponding to its times.");
|
||||
return p_values[0];
|
||||
}
|
||||
|
|
@ -5868,9 +5868,67 @@ void GLTFDocument::_import_animation(Ref<GLTFState> state, AnimationPlayer *ap,
|
|||
const bool transform_affects_skinned_mesh_instance = gltf_node->skeleton < 0 && gltf_node->skin >= 0;
|
||||
if ((track.rotation_track.values.size() || track.position_track.values.size() || track.scale_track.values.size()) && !transform_affects_skinned_mesh_instance) {
|
||||
//make transform track
|
||||
int track_idx = animation->get_track_count();
|
||||
animation->add_track(Animation::TYPE_TRANSFORM3D);
|
||||
animation->track_set_path(track_idx, transform_node_path);
|
||||
int base_idx = animation->get_track_count();
|
||||
int position_idx = -1;
|
||||
int rotation_idx = -1;
|
||||
int scale_idx = -1;
|
||||
|
||||
if (track.position_track.values.size()) {
|
||||
Vector3 base_pos = state->nodes[track_i.key]->position;
|
||||
bool not_default = false; //discard the track if all it contains is default values
|
||||
for (int i = 0; i < track.position_track.times.size(); i++) {
|
||||
Vector3 value = track.position_track.values[track.position_track.interpolation == GLTFAnimation::INTERP_CUBIC_SPLINE ? (1 + i * 3) : i];
|
||||
if (!value.is_equal_approx(base_pos)) {
|
||||
not_default = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (not_default) {
|
||||
position_idx = base_idx;
|
||||
animation->add_track(Animation::TYPE_POSITION_3D);
|
||||
animation->track_set_path(position_idx, transform_node_path);
|
||||
animation->track_set_imported(position_idx, true); //helps merging later
|
||||
|
||||
base_idx++;
|
||||
}
|
||||
}
|
||||
if (track.rotation_track.values.size()) {
|
||||
Quaternion base_rot = state->nodes[track_i.key]->rotation.normalized();
|
||||
bool not_default = false; //discard the track if all it contains is default values
|
||||
for (int i = 0; i < track.rotation_track.times.size(); i++) {
|
||||
Quaternion value = track.rotation_track.values[track.rotation_track.interpolation == GLTFAnimation::INTERP_CUBIC_SPLINE ? (1 + i * 3) : i].normalized();
|
||||
if (!value.is_equal_approx(base_rot)) {
|
||||
not_default = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (not_default) {
|
||||
rotation_idx = base_idx;
|
||||
animation->add_track(Animation::TYPE_ROTATION_3D);
|
||||
animation->track_set_path(rotation_idx, transform_node_path);
|
||||
animation->track_set_imported(rotation_idx, true); //helps merging later
|
||||
base_idx++;
|
||||
}
|
||||
}
|
||||
if (track.scale_track.values.size()) {
|
||||
Vector3 base_scale = state->nodes[track_i.key]->scale;
|
||||
bool not_default = false; //discard the track if all it contains is default values
|
||||
for (int i = 0; i < track.scale_track.times.size(); i++) {
|
||||
Vector3 value = track.scale_track.values[track.scale_track.interpolation == GLTFAnimation::INTERP_CUBIC_SPLINE ? (1 + i * 3) : i];
|
||||
if (!value.is_equal_approx(base_scale)) {
|
||||
not_default = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (not_default) {
|
||||
scale_idx = base_idx;
|
||||
animation->add_track(Animation::TYPE_SCALE_3D);
|
||||
animation->track_set_path(scale_idx, transform_node_path);
|
||||
animation->track_set_imported(scale_idx, true); //helps merging later
|
||||
base_idx++;
|
||||
}
|
||||
}
|
||||
|
||||
//first determine animation length
|
||||
|
||||
const double increment = 1.0 / bake_fps;
|
||||
|
|
@ -5880,15 +5938,15 @@ void GLTFDocument::_import_animation(Ref<GLTFState> state, AnimationPlayer *ap,
|
|||
Quaternion base_rot;
|
||||
Vector3 base_scale = Vector3(1, 1, 1);
|
||||
|
||||
if (!track.rotation_track.values.size()) {
|
||||
if (rotation_idx == -1) {
|
||||
base_rot = state->nodes[track_i.key]->rotation.normalized();
|
||||
}
|
||||
|
||||
if (!track.position_track.values.size()) {
|
||||
if (position_idx == -1) {
|
||||
base_pos = state->nodes[track_i.key]->position;
|
||||
}
|
||||
|
||||
if (!track.scale_track.values.size()) {
|
||||
if (scale_idx == -1) {
|
||||
base_scale = state->nodes[track_i.key]->scale;
|
||||
}
|
||||
|
||||
|
|
@ -5898,15 +5956,15 @@ void GLTFDocument::_import_animation(Ref<GLTFState> state, AnimationPlayer *ap,
|
|||
Quaternion rot = base_rot;
|
||||
Vector3 scale = base_scale;
|
||||
|
||||
if (track.position_track.times.size()) {
|
||||
if (position_idx >= 0) {
|
||||
pos = _interpolate_track<Vector3>(track.position_track.times, track.position_track.values, time, track.position_track.interpolation);
|
||||
}
|
||||
|
||||
if (track.rotation_track.times.size()) {
|
||||
if (rotation_idx >= 0) {
|
||||
rot = _interpolate_track<Quaternion>(track.rotation_track.times, track.rotation_track.values, time, track.rotation_track.interpolation);
|
||||
}
|
||||
|
||||
if (track.scale_track.times.size()) {
|
||||
if (scale_idx >= 0) {
|
||||
scale = _interpolate_track<Vector3>(track.scale_track.times, track.scale_track.values, time, track.scale_track.interpolation);
|
||||
}
|
||||
|
||||
|
|
@ -5925,7 +5983,15 @@ void GLTFDocument::_import_animation(Ref<GLTFState> state, AnimationPlayer *ap,
|
|||
pos = xform.origin;
|
||||
}
|
||||
|
||||
animation->transform_track_insert_key(track_idx, time, pos, rot, scale);
|
||||
if (position_idx >= 0) {
|
||||
animation->position_track_insert_key(position_idx, time, pos);
|
||||
}
|
||||
if (rotation_idx >= 0) {
|
||||
animation->rotation_track_insert_key(rotation_idx, time, rot);
|
||||
}
|
||||
if (scale_idx >= 0) {
|
||||
animation->scale_track_insert_key(scale_idx, time, scale);
|
||||
}
|
||||
|
||||
if (last) {
|
||||
break;
|
||||
|
|
@ -6146,6 +6212,10 @@ void GLTFDocument::_process_mesh_instances(Ref<GLTFState> state, Node *scene_roo
|
|||
}
|
||||
|
||||
GLTFAnimation::Track GLTFDocument::_convert_animation_track(Ref<GLTFState> state, GLTFAnimation::Track p_track, Ref<Animation> p_animation, Transform3D p_bone_rest, int32_t p_track_i, GLTFNodeIndex p_node_i) {
|
||||
#ifndef _MSC_VER
|
||||
#warning this needs to be redone
|
||||
#endif
|
||||
#if 0
|
||||
Animation::InterpolationType interpolation = p_animation->track_get_interpolation_type(p_track_i);
|
||||
|
||||
GLTFAnimation::Interpolation gltf_interpolation = GLTFAnimation::INTERP_LINEAR;
|
||||
|
|
@ -6164,6 +6234,8 @@ GLTFAnimation::Track GLTFDocument::_convert_animation_track(Ref<GLTFState> state
|
|||
for (int32_t key_i = 0; key_i < key_count; key_i++) {
|
||||
times.write[key_i] = p_animation->track_get_key_time(p_track_i, key_i);
|
||||
}
|
||||
|
||||
|
||||
if (track_type == Animation::TYPE_TRANSFORM3D) {
|
||||
p_track.position_track.times = times;
|
||||
p_track.position_track.interpolation = gltf_interpolation;
|
||||
|
|
@ -6323,7 +6395,7 @@ GLTFAnimation::Track GLTFDocument::_convert_animation_track(Ref<GLTFState> state
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
return p_track;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue