USD: Skeleton and blend shape import #110912
|
@ -342,6 +342,68 @@ class USDImportTest(AbstractUSDTest):
|
|||
bpy.context.scene.frame_set(60)
|
||||
self.assertAlmostEqual(key.value, .100, 3)
|
||||
|
||||
def test_import_usd_skel_joints(self):
|
||||
"""Test importing USD animated skeleton joints."""
|
||||
|
||||
infile = str(self.testdir / "arm.usda")
|
||||
res = bpy.ops.wm.usd_import(filepath=infile)
|
||||
self.assertEqual({'FINISHED'}, res)
|
||||
|
||||
# Verify armature was imported.
|
||||
arm_obj = bpy.data.objects["Skel"]
|
||||
self.assertEqual(arm_obj.type, "ARMATURE", "'Skel' object is not an armature")
|
||||
|
||||
arm = arm_obj.data
|
||||
bones = arm.bones
|
||||
|
||||
# Verify bone parenting.
|
||||
self.assertIsNone(bones['Shoulder'].parent, "Shoulder bone should not be parented")
|
||||
self.assertEqual(bones['Shoulder'], bones['Elbow'].parent, "Elbow bone should be child of Shoulder bone")
|
||||
self.assertEqual(bones['Elbow'], bones['Hand'].parent, "Hand bone should be child of Elbow bone")
|
||||
|
||||
# Verify armature modifier was created on the mesh.
|
||||
mesh_obj = bpy.data.objects['Arm']
|
||||
# Get all the armature modifiers on the mesh.
|
||||
arm_mods = [m for m in mesh_obj.modifiers if m.type == "ARMATURE"]
|
||||
self.assertEqual(len(arm_mods), 1, "Didn't get expected armatrue modifier")
|
||||
self.assertEqual(arm_mods[0].object, arm_obj, "Armature modifier does not reference the imported armature")
|
||||
|
||||
# Verify expected deform groups.
|
||||
# There are 4 points in each group.
|
||||
for i in range(4):
|
||||
self.assertAlmostEqual(mesh_obj.vertex_groups['Hand'].weight(i), 1.0, 2, "Unexpected weight for Hand deform vert")
|
||||
self.assertAlmostEqual(mesh_obj.vertex_groups['Shoulder'].weight(4 + i), 1.0, 2, "Unexpected weight for Shoulder deform vert")
|
||||
self.assertAlmostEqual(mesh_obj.vertex_groups['Elbow'].weight(8 + i), 1.0, 2, "Unexpected weight for Elbow deform vert")
|
||||
|
||||
action = bpy.data.actions['SkelAction']
|
||||
|
||||
# Verify the Elbow joint rotation animation.
|
||||
curve_path = 'pose.bones["Elbow"].rotation_quaternion'
|
||||
|
||||
# Quat W
|
||||
f = action.fcurves.find(curve_path, index=0)
|
||||
self.assertIsNotNone(f, "Couldn't find Elbow rotation quaternion W curve")
|
||||
self.assertAlmostEqual(f.evaluate(0), 1.0, 2, "Unexpected value for rotation quaternion W curve at frame 0")
|
||||
self.assertAlmostEqual(f.evaluate(10), 0.707, 2, "Unexpected value for rotation quaternion W curve at frame 10")
|
||||
|
||||
# Quat X
|
||||
f = action.fcurves.find(curve_path, index=1)
|
||||
self.assertIsNotNone(f, "Couldn't find Elbow rotation quaternion X curve")
|
||||
self.assertAlmostEqual(f.evaluate(0), 0.0, 2, "Unexpected value for rotation quaternion X curve at frame 0")
|
||||
self.assertAlmostEqual(f.evaluate(10), 0.707, 2, "Unexpected value for rotation quaternion X curve at frame 10")
|
||||
|
||||
# Quat Y
|
||||
f = action.fcurves.find(curve_path, index=2)
|
||||
self.assertIsNotNone(f, "Couldn't find Elbow rotation quaternion Y curve")
|
||||
self.assertAlmostEqual(f.evaluate(0), 0.0, 2, "Unexpected value for rotation quaternion Y curve at frame 0")
|
||||
self.assertAlmostEqual(f.evaluate(10), 0.0, 2, "Unexpected value for rotation quaternion Y curve at frame 10")
|
||||
|
||||
# Quat Z
|
||||
f = action.fcurves.find(curve_path, index=3)
|
||||
self.assertIsNotNone(f, "Couldn't find Elbow rotation quaternion Z curve")
|
||||
self.assertAlmostEqual(f.evaluate(0), 0.0, 2, "Unexpected value for rotation quaternion Z curve at frame 0")
|
||||
self.assertAlmostEqual(f.evaluate(10), 0.0, 2, "Unexpected value for rotation quaternion Z curve at frame 10")
|
||||
|
||||
|
||||
def main():
|
||||
global args
|
||||
|
|
Loading…
Reference in New Issue