Ver Fonte

Merge pull request #63543 from TokageItLab/fix-skeleton-renamer

Fix SkeletonRenamer & TrackOrganizer in ImporterRetarget for non bone animations such as BlendShape
Rémi Verschelde há 3 anos atrás
pai
commit
2f828135f8

+ 17 - 5
editor/import/post_import_plugin_skeleton_renamer.cpp

@@ -154,16 +154,28 @@ void PostImportPluginSkeletonRenamer::internal_process(InternalImportCategory p_
 					Ref<Animation> anim = ap->get_animation(name);
 					int track_len = anim->get_track_count();
 					for (int i = 0; i < track_len; i++) {
-						if (anim->track_get_path(i).get_subname_count() != 1 || !(anim->track_get_type(i) == Animation::TYPE_POSITION_3D || anim->track_get_type(i) == Animation::TYPE_ROTATION_3D || anim->track_get_type(i) == Animation::TYPE_SCALE_3D)) {
-							continue;
-						}
 						String track_path = String(anim->track_get_path(i).get_concatenated_names());
+						Node *orig_node = (ap->get_node(ap->get_root()))->get_node(NodePath(track_path));
 						Node *node = (ap->get_node(ap->get_root()))->get_node(NodePath(track_path));
-						if (node) {
+						while (node) {
 							Skeleton3D *track_skeleton = Object::cast_to<Skeleton3D>(node);
 							if (track_skeleton && track_skeleton == skeleton) {
-								anim->track_set_path(i, String("%") + unique_name + String(":") + anim->track_get_path(i).get_concatenated_subnames());
+								if (node == orig_node) {
+									if (anim->track_get_path(i).get_subname_count() > 0) {
+										anim->track_set_path(i, UNIQUE_NODE_PREFIX + unique_name + String(":") + anim->track_get_path(i).get_concatenated_subnames());
+									} else {
+										anim->track_set_path(i, UNIQUE_NODE_PREFIX + unique_name);
+									}
+								} else {
+									if (anim->track_get_path(i).get_subname_count() > 0) {
+										anim->track_set_path(i, UNIQUE_NODE_PREFIX + unique_name + "/" + node->get_path_to(orig_node) + String(":") + anim->track_get_path(i).get_concatenated_subnames());
+									} else {
+										anim->track_set_path(i, UNIQUE_NODE_PREFIX + unique_name + "/" + node->get_path_to(orig_node));
+									}
+								}
+								break;
 							}
+							node = node->get_parent();
 						}
 					}
 				}

+ 30 - 19
editor/import/post_import_plugin_skeleton_track_organizer.cpp

@@ -37,6 +37,7 @@
 
 void PostImportPluginSkeletonTrackOrganizer::get_internal_import_options(InternalImportCategory p_category, List<ResourceImporter::ImportOption> *r_options) {
 	if (p_category == INTERNAL_IMPORT_CATEGORY_SKELETON_3D_NODE) {
+		r_options->push_back(ResourceImporter::ImportOption(PropertyInfo(Variant::BOOL, "retarget/remove_tracks/except_bone_transform"), false));
 		r_options->push_back(ResourceImporter::ImportOption(PropertyInfo(Variant::BOOL, "retarget/remove_tracks/unimportant_positions"), true));
 		r_options->push_back(ResourceImporter::ImportOption(PropertyInfo(Variant::BOOL, "retarget/remove_tracks/unmapped_bones"), false));
 	}
@@ -58,6 +59,7 @@ void PostImportPluginSkeletonTrackOrganizer::internal_process(InternalImportCate
 		if (!src_skeleton) {
 			return;
 		}
+		bool remove_except_bone = bool(p_options["retarget/remove_tracks/except_bone_transform"]);
 		bool remove_positions = bool(p_options["retarget/remove_tracks/unimportant_positions"]);
 		bool remove_unmapped_bones = bool(p_options["retarget/remove_tracks/unmapped_bones"]);
 
@@ -75,32 +77,41 @@ void PostImportPluginSkeletonTrackOrganizer::internal_process(InternalImportCate
 				int track_len = anim->get_track_count();
 				Vector<int> remove_indices;
 				for (int i = 0; i < track_len; i++) {
-					if (anim->track_get_path(i).get_subname_count() != 1 || !(anim->track_get_type(i) == Animation::TYPE_POSITION_3D || anim->track_get_type(i) == Animation::TYPE_ROTATION_3D || anim->track_get_type(i) == Animation::TYPE_SCALE_3D)) {
-						continue;
-					}
-
 					String track_path = String(anim->track_get_path(i).get_concatenated_names());
 					Node *node = (ap->get_node(ap->get_root()))->get_node(NodePath(track_path));
-					if (node) {
-						Skeleton3D *track_skeleton = Object::cast_to<Skeleton3D>(node);
-						if (track_skeleton && track_skeleton == src_skeleton) {
-							StringName bn = anim->track_get_path(i).get_subname(0);
-							if (bn) {
-								int prof_idx = profile->find_bone(bone_map->find_profile_bone_name(bn));
-								if (remove_unmapped_bones && prof_idx < 0) {
-									remove_indices.push_back(i);
+					if (!node) {
+						if (remove_except_bone) {
+							remove_indices.push_back(i);
+						}
+						continue;
+					}
+					Skeleton3D *track_skeleton = Object::cast_to<Skeleton3D>(node);
+					if (track_skeleton && track_skeleton == src_skeleton) {
+						if (anim->track_get_path(i).get_subname_count() != 1 || !(anim->track_get_type(i) == Animation::TYPE_POSITION_3D || anim->track_get_type(i) == Animation::TYPE_ROTATION_3D || anim->track_get_type(i) == Animation::TYPE_SCALE_3D)) {
+							if (remove_except_bone) {
+								remove_indices.push_back(i);
+							}
+							continue;
+						}
+						StringName bn = anim->track_get_path(i).get_subname(0);
+						if (bn) {
+							int prof_idx = profile->find_bone(bone_map->find_profile_bone_name(bn));
+							if (remove_unmapped_bones && prof_idx < 0) {
+								remove_indices.push_back(i);
+								continue;
+							}
+							if (remove_positions && anim->track_get_type(i) == Animation::TYPE_POSITION_3D && prof_idx >= 0) {
+								StringName prof_bn = profile->get_bone_name(prof_idx);
+								if (prof_bn == profile->get_root_bone() || prof_bn == profile->get_scale_base_bone()) {
 									continue;
 								}
-								if (remove_positions && anim->track_get_type(i) == Animation::TYPE_POSITION_3D && prof_idx >= 0) {
-									StringName prof_bn = profile->get_bone_name(prof_idx);
-									if (prof_bn == profile->get_root_bone() || prof_bn == profile->get_scale_base_bone()) {
-										continue;
-									}
-									remove_indices.push_back(i);
-								}
+								remove_indices.push_back(i);
 							}
 						}
 					}
+					if (remove_except_bone) {
+						remove_indices.push_back(i);
+					}
 				}
 
 				remove_indices.reverse();