def test_dup_to_parent_node(self): test_cube = self.create_cube() parent = self.create_transform_node() dups = namespaceutils.duplicate_to_namespace([test_cube], dup_parent=parent) self.assertEqual(len(dups), 1) self.assertEqual(parent, dups[0].getParent()) self.assertEqual(test_cube.nodeName(), dups[0].nodeName())
def test_basic(self): test_cube = self.create_cube() dups = namespaceutils.duplicate_to_namespace([test_cube]) self.assertEqual(len(dups), 1) result = dups[0].nodeName() expected = 'pCube' + str(int(test_cube.nodeName().split('pCube')[1])+1) self.assertEqual(expected, result)
def test_parent_to_world(self): parent = self.create_transform_node() test_cube = self.create_cube() test_cube.setParent(parent) dups = namespaceutils.duplicate_to_namespace([test_cube], dup_parent=namespaceutils.PARENT_WORLD) self.assertEqual(len(dups), 1) self.assertIsNone(dups[0].getParent()) self.assertEqual(test_cube.nodeName(), dups[0].nodeName())
def test_dup_to_namespace(self): test_cube = self.create_cube() pm.namespace(add='foo') dups = namespaceutils.duplicate_to_namespace([test_cube], dup_namespace='foo') self.assertEqual(len(dups), 1) result = dups[0].name() expected = 'foo:' + test_cube.nodeName() self.assertEqual(expected, result)
def duplicate_skeleton(root_joint, dup_parent=None, dup_namespace=None): dup_namespace = dup_namespace or pm.namespaceInfo(currentNamespace=True) dup_root = nsutils.duplicate_to_namespace([root_joint], dup_namespace=dup_namespace, dup_parent=dup_parent)[0] dup_hierarchy = get_hierarchy_from_root(dup_root) to_delete = get_extra_nodes_in_skeleton(dup_hierarchy) pm.delete(to_delete) return dup_root
def duplicate_triangulate_mesh(skinned_mesh, dup_namespace=None, dup_parent=None): dup_namespace = dup_namespace or pm.namespaceInfo(currentNamespace=True) with nsutils.preserve_namespace(dup_namespace): dup_skinned_mesh_tri = nsutils.duplicate_to_namespace( skinned_mesh, dup_namespace=dup_namespace, dup_parent=dup_parent)[0] pm.polyTriangulate(dup_skinned_mesh_tri, ch=True) pm.delete(dup_skinned_mesh_tri, constructionHistory=True) dup_skin_cluster = bind_mesh_like_mesh(skinned_mesh, dup_skinned_mesh_tri) copy_weights(skinned_mesh, dup_skinned_mesh_tri) return dup_skinned_mesh_tri, dup_skin_cluster
def test_all_the_things(self): parents = [self.create_transform_node() for x in range(2)] test_cubes = [self.create_cube() for _ in range(5)] [x.setParent(parents[0]) for x in test_cubes] pm.namespace(add='foo') dups = namespaceutils.duplicate_to_namespace(test_cubes, dup_namespace='foo', dup_parent=parents[1]) self.assertEqual(len(test_cubes), len(dups)) [self.assertEqual(parents[1], dup.getParent()) for dup in dups] [self.assertEqual(tc.nodeName(), dup.nodeName(stripNamespace=True)) for tc, dup in zip(test_cubes, dups)] [self.assertEqual(dup.parentNamespace(), 'foo') for dup in dups]
def test_dup_to_both(self): parents = [self.create_transform_node() for x in range(2)] test_cube = self.create_cube() test_cube.setParent(parents[0]) pm.namespace(add='foo') dups = namespaceutils.duplicate_to_namespace([test_cube], dup_namespace='foo', dup_parent=parents[1]) self.assertEqual(len(dups), 1) self.assertEqual(parents[1], dups[0].getParent()) self.assertEqual(test_cube.nodeName(), dups[0].nodeName(stripNamespace=True)) self.assertEqual(dups[0].parentNamespace(), 'foo')
def duplicate_skinned_mesh_to_influences(skinned_mesh, influences, copy_skinning=True, bind_method=bind_mesh_to_joints, dup_namespace=None, dup_parent=None): dup_namespace = dup_namespace or pm.namespaceInfo(currentNamespace=True) with nsutils.preserve_namespace(dup_namespace): skinned_mesh_duplicate = nsutils.duplicate_to_namespace( skinned_mesh, dup_namespace=dup_namespace, dup_parent=dup_parent)[0] skincluster_duplicate = bind_method(skinned_mesh_duplicate, influences) if copy_skinning: copy_weights(skinned_mesh, skinned_mesh_duplicate) # copy_weights_vert_order(skinned_mesh, skinned_mesh_duplicate) return skinned_mesh_duplicate, skincluster_duplicate
def test_passing_one_node(self): test_cube = self.create_cube() dups = namespaceutils.duplicate_to_namespace(test_cube) self.assertEqual(1, len(dups)) self.assertEqual(dups[0].type(), 'transform') self.assertTrue(dups[0].getShape())
def test_multiple_nodes(self): test_cubes = [self.create_cube() for _ in range(5)] dups = namespaceutils.duplicate_to_namespace(test_cubes) self.assertEqual(len(test_cubes), len(dups))