Repository navigation
Expand file tree
/
Copy pathtest_retarget_setup.gd
More file actions
210 lines (194 loc) · 9.97 KB
/
Copy pathtest_retarget_setup.gd
File metadata and controls
210 lines (194 loc) · 9.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
## Covers the dock's "Create Retarget Profile + Bone Map" action: the SkeletonProfile it
## exports from the Sidekick rig, and the name matching that fills the BoneMap. Matching
## is deliberately rig-agnostic - it is checked here against three naming conventions,
## including the Mixamo table published in demos/animations/README.md. Run headless:
## godot --headless -s tests/test_retarget_setup.gd
extends SceneTree
const Setup := preload("res://addons/kickdot/editor/sk_retarget_setup.gd")
const OUT_DIR := "user://test_retarget_setup"
## The mapping documented in demos/animations/README.md, which auto-matching must
## reproduce without containing any Mixamo-specific table.
const MIXAMO_EXPECTED := {
"pelvis": "mixamorig_Hips",
"spine_01": "mixamorig_Spine",
"spine_02": "mixamorig_Spine1",
"spine_03": "mixamorig_Spine2",
"neck_01": "mixamorig_Neck",
"head": "mixamorig_Head",
"clavicle_l": "mixamorig_LeftShoulder",
"upperarm_l": "mixamorig_LeftArm",
"lowerarm_l": "mixamorig_LeftForeArm",
"hand_l": "mixamorig_LeftHand",
"clavicle_r": "mixamorig_RightShoulder",
"upperarm_r": "mixamorig_RightArm",
"lowerarm_r": "mixamorig_RightForeArm",
"hand_r": "mixamorig_RightHand",
"thigh_l": "mixamorig_LeftUpLeg",
"calf_l": "mixamorig_LeftLeg",
"foot_l": "mixamorig_LeftFoot",
"ball_l": "mixamorig_LeftToeBase",
"thigh_r": "mixamorig_RightUpLeg",
"calf_r": "mixamorig_RightLeg",
"foot_r": "mixamorig_RightFoot",
"ball_r": "mixamorig_RightToeBase",
"thumb_01_l": "mixamorig_LeftHandThumb1",
"thumb_02_l": "mixamorig_LeftHandThumb2",
"thumb_03_l": "mixamorig_LeftHandThumb3",
"index_01_l": "mixamorig_LeftHandIndex1",
"index_02_l": "mixamorig_LeftHandIndex2",
"index_03_l": "mixamorig_LeftHandIndex3",
"middle_01_l": "mixamorig_LeftHandMiddle1",
"middle_02_l": "mixamorig_LeftHandMiddle2",
"middle_03_l": "mixamorig_LeftHandMiddle3",
"ring_01_l": "mixamorig_LeftHandRing1",
"ring_02_l": "mixamorig_LeftHandRing2",
"ring_03_l": "mixamorig_LeftHandRing3",
"pinky_01_l": "mixamorig_LeftHandPinky1",
"pinky_02_l": "mixamorig_LeftHandPinky2",
"pinky_03_l": "mixamorig_LeftHandPinky3",
"thumb_01_r": "mixamorig_RightHandThumb1",
"thumb_02_r": "mixamorig_RightHandThumb2",
"thumb_03_r": "mixamorig_RightHandThumb3",
"index_01_r": "mixamorig_RightHandIndex1",
"index_02_r": "mixamorig_RightHandIndex2",
"index_03_r": "mixamorig_RightHandIndex3",
"middle_01_r": "mixamorig_RightHandMiddle1",
"middle_02_r": "mixamorig_RightHandMiddle2",
"middle_03_r": "mixamorig_RightHandMiddle3",
"ring_01_r": "mixamorig_RightHandRing1",
"ring_02_r": "mixamorig_RightHandRing2",
"ring_03_r": "mixamorig_RightHandRing3",
"pinky_01_r": "mixamorig_RightHandPinky1",
"pinky_02_r": "mixamorig_RightHandPinky2",
"pinky_03_r": "mixamorig_RightHandPinky3"
}
const MIXAMO_BONES := ["mixamorig_Hips", "mixamorig_Spine", "mixamorig_Spine1", "mixamorig_Spine2", "mixamorig_Neck", "mixamorig_Head", "mixamorig_LeftShoulder", "mixamorig_LeftArm", "mixamorig_LeftForeArm", "mixamorig_LeftHand", "mixamorig_RightShoulder", "mixamorig_RightArm", "mixamorig_RightForeArm", "mixamorig_RightHand", "mixamorig_LeftUpLeg", "mixamorig_LeftLeg", "mixamorig_LeftFoot", "mixamorig_LeftToeBase", "mixamorig_RightUpLeg", "mixamorig_RightLeg", "mixamorig_RightFoot", "mixamorig_RightToeBase", "mixamorig_LeftHandThumb1", "mixamorig_LeftHandThumb2", "mixamorig_LeftHandThumb3", "mixamorig_LeftHandIndex1", "mixamorig_LeftHandIndex2", "mixamorig_LeftHandIndex3", "mixamorig_LeftHandMiddle1", "mixamorig_LeftHandMiddle2", "mixamorig_LeftHandMiddle3", "mixamorig_LeftHandRing1", "mixamorig_LeftHandRing2", "mixamorig_LeftHandRing3", "mixamorig_LeftHandPinky1", "mixamorig_LeftHandPinky2", "mixamorig_LeftHandPinky3", "mixamorig_RightHandThumb1", "mixamorig_RightHandThumb2", "mixamorig_RightHandThumb3", "mixamorig_RightHandIndex1", "mixamorig_RightHandIndex2", "mixamorig_RightHandIndex3", "mixamorig_RightHandMiddle1", "mixamorig_RightHandMiddle2", "mixamorig_RightHandMiddle3", "mixamorig_RightHandRing1", "mixamorig_RightHandRing2", "mixamorig_RightHandRing3", "mixamorig_RightHandPinky1", "mixamorig_RightHandPinky2", "mixamorig_RightHandPinky3"]
## Godot's own humanoid naming, as a second unrelated convention.
const HUMANOID_BONES := ["Hips", "Spine", "Chest", "UpperChest", "Neck", "Head",
"LeftShoulder", "LeftUpperArm", "LeftLowerArm", "LeftHand", "RightShoulder",
"RightUpperArm", "RightLowerArm", "RightHand", "LeftUpperLeg", "LeftLowerLeg",
"LeftFoot", "LeftToes", "RightUpperLeg", "RightLowerLeg", "RightFoot", "RightToes"]
## Synty's POLYGON rig, which their animation packs (A_*.fbx clips) are authored on -
## exactly as Godot imports it: "Shoulder" is the UPPER ARM (the chain is Clavicle >
## Shoulder > Elbow > Hand), fingers are zero-padded with no side marker, and the
## right hand's duplicates get a "_1" suffix from import dedup. Eyes/Eyebrows/Jaw,
## the *_04 finger tips, and Toes_* (past the ball) legitimately stay unmapped.
const SYNTY_ANIM_BONES := ["Root", "Hips", "Spine_01", "Spine_02", "Spine_03", "Neck",
"Head", "Eyes", "Eyebrows", "Jaw", "Clavicle_L", "Shoulder_L", "Elbow_L", "Hand_L",
"Thumb_01", "Thumb_02", "Thumb_03", "IndexFinger_01", "IndexFinger_02",
"IndexFinger_03", "IndexFinger_04", "Finger_01", "Finger_02", "Finger_03",
"Finger_04", "Prop_L", "Clavicle_R", "Shoulder_R", "Elbow_R", "Hand_R", "Thumb_01_1",
"Thumb_02_1", "Thumb_03_1", "IndexFinger_01_1", "IndexFinger_02_1",
"IndexFinger_03_1", "IndexFinger_04_1", "Finger_01_1", "Finger_02_1", "Finger_03_1",
"Finger_04_1", "Prop_R", "UpperLeg_R", "LowerLeg_R", "Ankle_R", "Ball_R", "Toes_R",
"UpperLeg_L", "LowerLeg_L", "Ankle_L", "Ball_L", "Toes_L"]
const SYNTY_ANIM_EXPECTED := {
"root": "Root",
"pelvis": "Hips",
"spine_01": "Spine_01",
"spine_02": "Spine_02",
"spine_03": "Spine_03",
"neck_01": "Neck",
"head": "Head",
"clavicle_l": "Clavicle_L",
"upperarm_l": "Shoulder_L",
"lowerarm_l": "Elbow_L",
"hand_l": "Hand_L",
"prop_l": "Prop_L",
"clavicle_r": "Clavicle_R",
"upperarm_r": "Shoulder_R",
"lowerarm_r": "Elbow_R",
"hand_r": "Hand_R",
"prop_r": "Prop_R",
"thigh_l": "UpperLeg_L",
"calf_l": "LowerLeg_L",
"foot_l": "Ankle_L",
"ball_l": "Ball_L",
"thigh_r": "UpperLeg_R",
"calf_r": "LowerLeg_R",
"foot_r": "Ankle_R",
"ball_r": "Ball_R",
"thumb_01_l": "Thumb_01",
"thumb_02_l": "Thumb_02",
"thumb_03_l": "Thumb_03",
"index_01_l": "IndexFinger_01",
"index_02_l": "IndexFinger_02",
"index_03_l": "IndexFinger_03",
"middle_01_l": "Finger_01",
"middle_02_l": "Finger_02",
"middle_03_l": "Finger_03",
"thumb_01_r": "Thumb_01_1",
"thumb_02_r": "Thumb_02_1",
"thumb_03_r": "Thumb_03_1",
"index_01_r": "IndexFinger_01_1",
"index_02_r": "IndexFinger_02_1",
"index_03_r": "IndexFinger_03_1",
"middle_01_r": "Finger_01_1",
"middle_02_r": "Finger_02_1",
"middle_03_r": "Finger_03_1"
}
var _failures := 0
func _init() -> void:
var model := load(ProjectSettings.get_setting(
SKCharacterBuilder.SETTING_BASE_MODEL, SKCharacterBuilder.DEFAULT_BASE_MODEL)) as PackedScene
var rig := Setup.skeleton_of(model)
_check(rig != null, "base model has a skeleton")
if rig == null:
_finish()
return
var profile := Setup.build_profile(rig)
_check(profile.bone_size == rig.get_bone_count(),
"profile covers every bone (%d)" % profile.bone_size)
_check(String(profile.get_bone_name(profile.find_bone(&"pelvis"))) == "pelvis",
"profile uses Synty bone names")
_check(String(profile.get_bone_parent(profile.find_bone(&"spine_02"))) == "spine_01",
"profile keeps the bone hierarchy")
_check(profile.get_reference_pose(profile.find_bone(&"spine_02")).origin .is_equal_approx(rig.get_bone_rest(rig.find_bone("spine_02")).origin),
"reference poses are the rig's local rests")
# A rig already using Unreal-mannequin names maps outright.
var matched: Array[String] = []
Setup.build_bone_map(profile, rig, matched)
_check(matched.size() == profile.bone_size,
"unreal-named rig maps every bone (%d/%d)" % [matched.size(), profile.bone_size])
_check_convention(profile, MIXAMO_BONES, "Mixamo", MIXAMO_EXPECTED)
_check_convention(profile, HUMANOID_BONES, "Godot humanoid", {})
_check_convention(profile, SYNTY_ANIM_BONES, "Synty animation rig", SYNTY_ANIM_EXPECTED,
SYNTY_ANIM_EXPECTED.size())
# The resources must survive a save/load round trip, since that is what the dock does.
DirAccess.make_dir_recursive_absolute(OUT_DIR)
var profile_path := OUT_DIR + "/profile.tres"
_check(ResourceSaver.save(profile, profile_path) == OK, "profile saves")
var reloaded := load(profile_path) as SkeletonProfile
_check(reloaded != null and reloaded.bone_size == profile.bone_size, "profile reloads intact")
rig.free()
_finish()
## Builds a skeleton with the given bone names and checks how the matcher does on it.
## `expected_matched` overrides the expected match count for rigs that carry bones the
## Sidekick skeleton has no counterpart for (default: every source bone maps).
func _check_convention(profile: SkeletonProfile, bones: Array, label: String,
expected: Dictionary, expected_matched := -1) -> void:
var skeleton := Skeleton3D.new()
for bone_name: String in bones:
skeleton.add_bone(bone_name)
var matched: Array[String] = []
var bone_map := Setup.build_bone_map(profile, skeleton, matched)
var want := bones.size() if expected_matched < 0 else expected_matched
_check(matched.size() == want,
"%s names map as expected (%d/%d)" % [label, matched.size(), want])
var wrong: Array[String] = []
for sidekick_bone: String in expected:
var got := String(bone_map.get_skeleton_bone_name(StringName(sidekick_bone)))
if got != String(expected[sidekick_bone]):
wrong.append("%s -> '%s' (want '%s')" % [sidekick_bone, got, expected[sidekick_bone]])
if not expected.is_empty():
_check(wrong.is_empty(),
"%s mapping matches the documented table (%d wrong: %s)"
% [label, wrong.size(), str(wrong.slice(0, 3))])
skeleton.free()
func _check(ok: bool, what: String) -> void:
if not ok:
_failures += 1
print(" %s %s" % ["ok " if ok else "FAIL", what])
func _finish() -> void:
print("RETARGET SETUP: %s" % ("ALL PASSED" if _failures == 0 else "%d FAILURES" % _failures))
quit(0 if _failures == 0 else 1)