def test_copy_weights_vert_order_same_skeleton(self): source_cube, source_joints, source_skincluster = self.create_skinned_cube( ) target_cube = self.create_cube() target_skincluster = skinutils.bind_mesh_to_joints( target_cube, source_joints) transform_values = dict( itertools.zip_longest(source_joints[:4], [0.25], fillvalue=0.25)) transform_values[source_joints[-1]] = 0.0 pm.skinPercent(source_skincluster, source_cube.vtx[0], transformValue=transform_values.items()) source_weightedinfs = skinutils.get_weighted_influences( target_cube.vtx[0], target_skincluster) transform_values = dict( itertools.zip_longest(source_joints[1:], [0.25], fillvalue=0.25)) transform_values[source_joints[0]] = 0.0 pm.skinPercent(target_skincluster, target_cube.vtx[0], transformValue=transform_values.items()) target_weightedinfs = skinutils.get_weighted_influences( target_cube.vtx[0], target_skincluster) self.assertNotEqual(source_weightedinfs, target_weightedinfs) skinutils.copy_weights_vert_order_inf_order(source_cube, target_cube, source_skincluster, target_skincluster) expected = skinutils.get_weighted_influences(source_cube.vtx[0], source_skincluster) result = skinutils.get_weighted_influences(target_cube.vtx[0], target_skincluster) self.assertDictEqual(expected, result)
def test_modifies_skinning(self): test_cube = self.create_cube() test_joints = [self.create_joint() for _ in range(5)] [pm.move(j, (1, 0, 0)) for j in test_joints] skinutils.bind_mesh_to_joints(test_cube, test_joints, maximumInfluences=1) start_infs = skinutils.get_weighted_influences(test_cube.vtx[0]) self.assertEqual(1, len(start_infs)) skinutils.apply_delta_mush_skinning(test_cube, cleanup=True) after_infs = skinutils.get_weighted_influences(test_cube.vtx[0]) self.assertEqual(4, len(after_infs))
def test_prune_exceeding_influences(self): test_cube = self.create_cube() test_joints = [self.create_joint() for _ in range(5)] skincl = skinutils.bind_mesh_to_joints(test_cube, test_joints, maximumInfluences=5) influences_to_weights = skinutils.get_weighted_influences( test_cube.vtx[0], skincl) skinutils.prune_exceeding_influences(test_cube.vtx[0], skincl, influences_to_weights) result = skinutils.get_weighted_influences(test_cube.vtx[0], skincl) self.assertEqual(4, len(result))
def test_export_referenced_mesh(self): ref_cube, ref_joints, ref_skincluster = self.create_skinned_cube() ref_cube_name = ref_cube.nodeName() pm.skinPercent(ref_skincluster, ref_cube.vtx, transformValue=(ref_joints[2], 1.0)) with tempfile.TemporaryDirectory() as tempdir_name: # skin a cube and export it to a separate file ref_filename = os.path.join(tempdir_name, 'ref_test.ma') stuff = [ref_cube] + ref_joints pm.select(stuff, r=True) pm.exportSelected(ref_filename, type='mayaAscii', constructionHistory=True, force=True) # clean scene then reference in the file just exported self._clean_scene() file_reference = pm.createReference(ref_filename) ref_nodes = file_reference.nodes() ref_cube = [ r for r in ref_nodes if r.nodeName().endswith(ref_cube_name) ][0] # export the skin weights dest_filename = os.path.join(tempdir_name, 'test_weights.ma') skinio.export_skinned_mesh(ref_cube, dest_filename) # open the exported skin file pm.openFile(dest_filename, force=True) result_cube = skinutils.get_skinned_meshes_from_scene()[0] result_skincl = skinutils.get_skincluster(result_cube) result_joints = result_skincl.influenceObjects() result = skinutils.get_weighted_influences(result_cube.vtx[0]) expected = {result_joints[2]: 1.0} self.assertEqual(expected, result)
def test_get_non_zero_influences_from_vert(self): test_cube = self.create_cube() test_joints = [self.create_joint() for _ in range(5)] skincl = skinutils.bind_mesh_to_joints(test_cube, test_joints, maximumInfluences=5) non_zero_infs = skinutils.get_weighted_influences( test_cube.vtx[0], skincl) self.assertEqual(5, len(non_zero_infs))
def test_prune_exceeding_skinned_mesh(self): test_cube = self.create_cube() test_joints = [self.create_joint() for _ in range(5)] skincl = skinutils.bind_mesh_to_joints(test_cube, test_joints, maximumInfluences=5) initial_influences = [] for vert in test_cube.vtx: initial_inf = skinutils.get_weighted_influences(vert, skincl) initial_influences.append(len(initial_inf)) expected_initial = [5, 5, 5, 5, 5, 5, 5, 5] self.assertListEqual(expected_initial, initial_influences) skinutils.prune_exceeding_skinned_mesh(test_cube, skincluster=skincl) results = [] for vert in test_cube.vtx: result = skinutils.get_weighted_influences(vert, skincl) results.append(len(result)) expected = [4, 4, 4, 4, 4, 4, 4, 4] self.assertListEqual(expected, results)
def test_moves_weights_to_parent(self): test_cube, test_joints, skin_cluster = self.create_skinned_cube() values = [0, 0.25, 0.25, 0.25, 0.25] infs_to_wts = dict(zip(test_joints, values)) with skinutils.max_influences_normalize_weights_disabled(skin_cluster): for vertex in test_cube.vtx: pm.skinPercent(skin_cluster, vertex, transformValue=infs_to_wts.items()) skinutils.move_weight_and_remove_influence(test_joints[-1], test_joints[-2], skin_cluster) result = skinutils.get_weighted_influences(test_cube.vtx[0], skin_cluster) expected_values = [0.25, 0.25, 0.5] expected = dict(zip(test_joints[1:-1], expected_values)) self.assertDictEqual(expected, result)
def test_simple(self): source_test_cube, source_test_joints, source_skin_cluster = self.create_skinned_cube( ) target_test_cube, target_test_joints, target_skin_cluster = self.create_skinned_cube( ) inf_map = dict([ (sj, [tj]) for sj, tj in zip(source_test_joints, target_test_joints) ]) for vertex in source_test_cube.vtx: pm.skinPercent(source_skin_cluster, vertex, transformValue=(source_test_joints[0], 1.0)) skinutils.copy_weights_vert_order(source_test_cube, target_test_cube, inf_map) result = skinutils.get_weighted_influences(target_test_cube.vtx[0]) expected = {target_test_joints[0]: 1.0} self.assertDictEqual(expected, result)
def test_copies_weights(self): test_cube, test_joints, test_skincluster = self.create_skinned_cube() skinio.import_skinning(test_cube, self.skin_path) result = skinutils.get_weighted_influences(test_cube.vtx[0]) expected = {test_joints[2]: 1.0} self.assertEqual(expected, result)