Beispiel #1
0
 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)
Beispiel #2
0
 def _create_tmp_skindata(self):
     test_cube, test_joints, test_skincluster = self.create_skinned_cube()
     pm.skinPercent(test_skincluster,
                    test_cube.vtx,
                    transformValue=(test_joints[2], 1.0))
     self.skin_path = os.path.join(self.tmp_dir, 'test_skinning.ma')
     skinio.export_skinned_mesh(test_cube, self.skin_path)
     pm.delete(self.scene_nodes)
Beispiel #3
0
 def test_exports_skinned_mesh_and_skeleton(self):
     test_cube, test_joints, test_skincluster = self.create_skinned_cube()
     with tempfile.TemporaryDirectory() as tempdir_name:
         dest_filename = os.path.join(tempdir_name, 'test_weights.ma')
         skinio.export_skinned_mesh(test_cube, dest_filename)
         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()
         self.assertEqual(len(test_joints), len(result_joints))
Beispiel #4
0
 def test_does_not_export_extra_stuff(self):
     test_cube, test_joints, test_skincluster = self.create_skinned_cube()
     second_cube = self.create_cube()
     skinutils.bind_mesh_to_joints(second_cube, test_joints)
     sms = skinutils.get_skinned_meshes_from_scene()
     self.assertEqual(2, len(sms))
     fake_rig_controller = self.create_transform_node()
     pm.parentConstraint(fake_rig_controller, test_joints[0])
     with tempfile.TemporaryDirectory() as tempdir_name:
         dest_filename = os.path.join(tempdir_name, 'test_weights.ma')
         skinio.export_skinned_mesh(test_cube, dest_filename)
         pm.openFile(dest_filename, force=True)
         result_cube = skinutils.get_skinned_meshes_from_scene()
         self.assertEqual(1, len(result_cube))
         default_trash = [x.getParent() for x in pm.ls(cameras=True)]
         default_trash.extend(pm.ls(type='joint'))
         stuff = [
             x for x in pm.ls(type='transform') if x not in default_trash
         ]
         # [x for x in pm.ls(type='transform') if x not in pm.ls(defaultNodes=True, cameras=True)]
         self.assertEqual(1, len(stuff))
         constraints = pm.ls(type='parentConstraint')
         self.assertEqual(0, len(constraints))
Beispiel #5
0
 def test_create_weight_file(self):
     test_cube, test_joints, test_skincluster = self.create_skinned_cube()
     with tempfile.TemporaryDirectory() as tempdir_name:
         dest_filename = os.path.join(tempdir_name, 'test_weights.ma')
         skinio.export_skinned_mesh(test_cube, dest_filename)
         self.assertTrue(os.path.exists(dest_filename))