Skip to content

Commit

Permalink
add rest fixer to importer retarget
Browse files Browse the repository at this point in the history
  • Loading branch information
TokageItLab committed Jul 16, 2022
1 parent 9904a9d commit f3af3ae
Show file tree
Hide file tree
Showing 13 changed files with 1,021 additions and 27 deletions.
79 changes: 79 additions & 0 deletions doc/classes/SkeletonProfile.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@
<tutorials>
</tutorials>
<methods>
<method name="find_bone" qualifiers="const">
<return type="int" />
<argument index="0" name="bone_name" type="StringName" />
<description>
Returns the bone index that matches [code]bone_name[/code] as its name.
</description>
</method>
<method name="get_bone_name" qualifiers="const">
<return type="StringName" />
<argument index="0" name="bone_idx" type="int" />
Expand All @@ -17,6 +24,20 @@
In the retargeting process, the returned bone name is the bone name of the target skeleton.
</description>
</method>
<method name="get_bone_parent" qualifiers="const">
<return type="StringName" />
<argument index="0" name="bone_idx" type="int" />
<description>
Returns the name of the bone which is the parent to the bone at [code]bone_idx[/code]. The result is empty if the bone has no parent.
</description>
</method>
<method name="get_bone_tail" qualifiers="const">
<return type="StringName" />
<argument index="0" name="bone_idx" type="int" />
<description>
Returns the name of the bone which is the tail of the bone at [code]bone_idx[/code].
</description>
</method>
<method name="get_group" qualifiers="const">
<return type="StringName" />
<argument index="0" name="bone_idx" type="int" />
Expand All @@ -39,6 +60,20 @@
This is the offset with origin at the top left corner of the square.
</description>
</method>
<method name="get_reference_pose" qualifiers="const">
<return type="Transform3D" />
<argument index="0" name="bone_idx" type="int" />
<description>
Returns the reference pose transform for bone [code]bone_idx[/code].
</description>
</method>
<method name="get_tail_direction" qualifiers="const">
<return type="int" enum="SkeletonProfile.TailDirection" />
<argument index="0" name="bone_idx" type="int" />
<description>
Returns the tail direction of the bone at [code]bone_idx[/code].
</description>
</method>
<method name="get_texture" qualifiers="const">
<return type="Texture2D" />
<argument index="0" name="group_idx" type="int" />
Expand All @@ -55,6 +90,22 @@
In the retargeting process, the setting bone name is the bone name of the target skeleton.
</description>
</method>
<method name="set_bone_parent">
<return type="void" />
<argument index="0" name="bone_idx" type="int" />
<argument index="1" name="bone_parent" type="StringName" />
<description>
Sets the bone with name [code]bone_parent[/code] as the parent of the bone at [code]bone_idx[/code]. If an empty string is passed, then the bone has no parent.
</description>
</method>
<method name="set_bone_tail">
<return type="void" />
<argument index="0" name="bone_idx" type="int" />
<argument index="1" name="bone_tail" type="StringName" />
<description>
Sets the bone with name [code]bone_tail[/code] as the tail of the bone at [code]bone_idx[/code].
</description>
</method>
<method name="set_group">
<return type="void" />
<argument index="0" name="bone_idx" type="int" />
Expand All @@ -80,6 +131,23 @@
This is the offset with origin at the top left corner of the square.
</description>
</method>
<method name="set_reference_pose">
<return type="void" />
<argument index="0" name="bone_idx" type="int" />
<argument index="1" name="bone_name" type="Transform3D" />
<description>
Sets the reference pose transform for bone [code]bone_idx[/code].
</description>
</method>
<method name="set_tail_direction">
<return type="void" />
<argument index="0" name="bone_idx" type="int" />
<argument index="1" name="tail_direction" type="int" enum="SkeletonProfile.TailDirection" />
<description>
Sets the tail direction of the bone at [code]bone_idx[/code].
[b]Note:[/b] This only specifies the method of calculation. The actual coordinates required should be stored in an external skeleton, so the calculation itself needs to be done externally.
</description>
</method>
<method name="set_texture">
<return type="void" />
<argument index="0" name="group_idx" type="int" />
Expand All @@ -103,4 +171,15 @@
</description>
</signal>
</signals>
<constants>
<constant name="TAIL_DIRECTION_AVERAGE_CHILDREN" value="0" enum="TailDirection">
Direction to the average coordinates of bone children.
</constant>
<constant name="TAIL_DIRECTION_SPECIFIC_CHILD" value="1" enum="TailDirection">
Direction to the coordinates of specified bone child.
</constant>
<constant name="TAIL_DIRECTION_END" value="2" enum="TailDirection">
Direction is not calculated.
</constant>
</constants>
</class>
34 changes: 34 additions & 0 deletions editor/import/post_import_plugin_skeleton_renamer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
void PostImportPluginSkeletonRenamer::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/bone_renamer/rename_bones"), true));
r_options->push_back(ResourceImporter::ImportOption(PropertyInfo(Variant::BOOL, "retarget/bone_renamer/unique_node/make_unique"), true));
r_options->push_back(ResourceImporter::ImportOption(PropertyInfo(Variant::STRING, "retarget/bone_renamer/unique_node/skeleton_name"), "GeneralSkeleton"));
}
}

Expand Down Expand Up @@ -137,6 +139,38 @@ void PostImportPluginSkeletonRenamer::internal_process(InternalImportCategory p_
nd->callp("_notify_skeleton_bones_renamed", argptrs, argcount, ce);
}
}

// Make unique skeleton.
if (bool(p_options["retarget/bone_renamer/unique_node/make_unique"])) {
String unique_name = String(p_options["retarget/bone_renamer/unique_node/skeleton_name"]);
ERR_FAIL_COND_MSG(unique_name == String(), "Skeleton unique name cannot be empty.");

TypedArray<Node> nodes = p_base_scene->find_children("*", "AnimationPlayer");
while (nodes.size()) {
AnimationPlayer *ap = Object::cast_to<AnimationPlayer>(nodes.pop_back());
List<StringName> anims;
ap->get_animation_list(&anims);
for (const StringName &name : anims) {
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 *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 == skeleton) {
anim->track_set_path(i, String("%") + unique_name + String(":") + anim->track_get_path(i).get_concatenated_subnames());
}
}
}
}
}
skeleton->set_name(unique_name);
skeleton->set_unique_name_in_owner(true);
}
}
}

Expand Down
Loading

0 comments on commit f3af3ae

Please sign in to comment.