def setUpClass(cls): standalone.initialize('usd') # Stage with simple (non-nested) instancing. mayaFile = os.path.abspath('InstancedShading.ma') cmds.file(mayaFile, open=True, force=True) usdFilePath = os.path.abspath('InstancedShading.usda') cmds.loadPlugin('pxrUsd') cmds.usdExport(mergeTransformAndShape=True, file=usdFilePath, shadingMode='displayColor', exportInstances=True, materialsScopeName='Materials', exportCollectionBasedBindings=True, exportMaterialCollections=True, materialCollectionsPath="/World") cls._simpleStage = Usd.Stage.Open(usdFilePath) # Stage with nested instancing. mayaFile = os.path.abspath('NestedInstancedShading.ma') cmds.file(mayaFile, open=True, force=True) usdFilePath = os.path.abspath('NestedInstancedShading.usda') cmds.loadPlugin('pxrUsd') cmds.usdExport(mergeTransformAndShape=True, file=usdFilePath, shadingMode='displayColor', exportInstances=True, materialsScopeName='Materials', exportCollectionBasedBindings=True, exportMaterialCollections=True, materialCollectionsPath="/World") cls._nestedStage = Usd.Stage.Open(usdFilePath)
def testExportWithKindFlag(self): """ Tests exporting a Maya file with no USD_kind custom attributes and using the usdExport -kind flag. """ cmds.file(os.path.abspath('KindTest.ma'), open=True, force=True) cmds.loadPlugin('pxrUsd') usdFilePath = os.path.abspath('KindTest.usda') # Check the error mark; this ensures that we actually got a Tf error # (that was eventually converted into a Maya error, which Maya raises # in Python as a RuntimeError). mark = Tf.Error.Mark() mark.SetMark() with self.assertRaises(RuntimeError): cmds.usdExport(mergeTransformAndShape=True, file=usdFilePath, kind='assembly') errors = mark.GetErrors() self.assertEqual(len(errors), 1) self.assertIn( "</KindTest> has kind 'assembly', which is derived from 'assembly'", str(errors[0])) cmds.usdExport(mergeTransformAndShape=True, file=usdFilePath, kind='fakeKind') stage = Usd.Stage.Open(usdFilePath) self.assertTrue(stage) rootPrim = stage.GetPrimAtPath('/KindTest') self.assertTrue(Kind.Registry().IsA( Usd.ModelAPI(rootPrim).GetKind(), 'fakeKind'))
def testExportWithAssemblyAndMesh(self): """ Tests exporting a Maya file with a root prim containing an assembly and a mesh. """ cmds.file(os.path.abspath('KindTestAssemblyAndMesh.ma'), open=True, force=True) cmds.loadPlugin('pxrUsd') # Should fail due to the mesh. usdFilePath = os.path.abspath('KindTestAssemblyAndMesh.usda') with self.assertRaises(RuntimeError): cmds.usdExport(mergeTransformAndShape=True, file=usdFilePath, kind='assembly') # Should be 'component' because of the mesh usdFilePath = os.path.abspath('KindTestAssemblyAndMesh.usda') cmds.usdExport(mergeTransformAndShape=True, file=usdFilePath) stage = Usd.Stage.Open(usdFilePath) self.assertTrue(stage) rootPrim = stage.GetPrimAtPath('/KindTest') self.assertTrue(Kind.Registry().IsA( Usd.ModelAPI(rootPrim).GetKind(), 'component'))
def testExportWithAssemblies(self): """ Tests exporting a Maya file with a root prim containing an assembly. """ cmds.file(os.path.abspath('KindTestAssembly.ma'), open=True, force=True) cmds.loadPlugin('pxrUsd') usdFilePath = os.path.abspath('KindTestAssembly.usda') cmds.usdExport(mergeTransformAndShape=True, file=usdFilePath, kind='assembly') stage = Usd.Stage.Open(usdFilePath) self.assertTrue(stage) # Default kind without setting kind=assembly should still be assembly. usdFilePath = os.path.abspath('KindTestAssembly2.usda') cmds.usdExport(mergeTransformAndShape=True, file=usdFilePath) stage = Usd.Stage.Open(usdFilePath) self.assertTrue(stage) rootPrim = stage.GetPrimAtPath('/KindTest') self.assertTrue(Kind.Registry().IsA( Usd.ModelAPI(rootPrim).GetKind(), 'assembly'))
def testExport(self): """ Tests that the built-in metadata attribute converters can export USD_hidden, USD_instanceable, and USD_kind attributes by setting the correct metadata in the output USD file. """ newUsdFilePath = os.path.abspath('UsdAttrsNew.usda') cmds.usdExport(file=newUsdFilePath, shadingMode='none') newUsdStage = Usd.Stage.Open(newUsdFilePath) # pCube1 and pCube2 have USD_kind. prim1 = newUsdStage.GetPrimAtPath('/World/pCube1') self.assertEqual(Usd.ModelAPI(prim1).GetKind(), 'potato') prim2 = newUsdStage.GetPrimAtPath('/World/pCube2') self.assertEqual(Usd.ModelAPI(prim2).GetKind(), 'bakedpotato') # pCube2 and pCube4 have USD_hidden. self.assertTrue(newUsdStage.GetPrimAtPath('/World/pCube2').IsHidden()) self.assertTrue(newUsdStage.GetPrimAtPath('/World/pCube4').IsHidden()) # pCube3 and pCube4 have USD_instanceable. self.assertTrue( newUsdStage.GetPrimAtPath('/World/pCube3').IsInstanceable()) self.assertTrue( newUsdStage.GetPrimAtPath('/World/pCube4').IsInstanceable())
def testExportWithKindAttrAndKindFlag(self): """ Tests exporting a Maya file with both USD_kind custom attributes and using the usdExport -kind flag; there should be an error if the USD_kind is not derived from the kind specified in the -kind flag. """ cmds.file(os.path.abspath('KindTestUsdKindAttr.ma'), open=True, force=True) cmds.loadPlugin('pxrUsd') usdFilePath = os.path.abspath('KindTestUsdKindAttr.usda') with self.assertRaises(RuntimeError): cmds.usdExport(mergeTransformAndShape=True, file=usdFilePath, kind='assembly') cmds.usdExport(mergeTransformAndShape=True, file=usdFilePath, kind='model') stage = Usd.Stage.Open(usdFilePath) self.assertTrue(stage) rootPrim = stage.GetPrimAtPath('/KindTest') self.assertTrue(Kind.Registry().IsA( Usd.ModelAPI(rootPrim).GetKind(), 'component')) rootPrim2 = stage.GetPrimAtPath('/KindTest2') self.assertTrue(Kind.Registry().IsA( Usd.ModelAPI(rootPrim2).GetKind(), 'assembly'))
def testArKitCompatibility(self): '''Tests usdz package export with ARKit compatibility profile.''' usdFile = os.path.abspath('MyAwesomeArKitCompatibleFile.usdz') usdFileNoExt = os.path.abspath('MyAwesomeArKitCompatibleFile') # The usdExport command should automatically add "usdz" extension since # we're requestion appleArKit compatibility. cmds.usdExport( file=usdFileNoExt, mergeTransformAndShape=True, shadingMode='none', compatibility='appleArKit') # Lets make sure that the root layer is the first file and that all # the references were localized ok. # Note that the path of "card.png" in the usdz archive may have changed # because of the flattening step. zipFile = Usd.ZipFile.Open(usdFile) fileNames = zipFile.GetFileNames() self.assertEqual(len(fileNames), 2) self.assertEqual(fileNames[0], "MyAwesomeArKitCompatibleFile.usdc") self.assertTrue(fileNames[1].endswith("card.png")) # Open the usdz file up to verify that everything exported properly. stage = Usd.Stage.Open(usdFile) self._AssertExpectedStage(stage, fileNames[-1]) # Make sure there's no weird temp files sitting around. self._AssertNoTempFiles(usdFile)
def testExportCreases(self): cmds.file(self.meshTestFile, force=True, open=True) usdFile = os.path.abspath('UsdExportMesh_creases.usda') cmds.usdExport(mergeTransformAndShape=True, file=usdFile, shadingMode='none') stage = Usd.Stage.Open(usdFile) m = UsdGeom.Mesh.Get(stage, '/UsdExportMeshTest/creased') self.assertEqual(m.GetSubdivisionSchemeAttr().Get(), UsdGeom.Tokens.catmullClark) self.assertFalse(m.GetSubdivisionSchemeAttr().IsAuthored()) self.assertTrue(not m.GetNormalsAttr().Get()) expectedCreaseIndices = Vt.IntArray( [0, 1, 3, 2, 0, 3, 5, 4, 2, 5, 7, 6, 4, 7, 1, 0, 6]) creaseIndices = m.GetCreaseIndicesAttr().Get() self.assertEqual(creaseIndices, expectedCreaseIndices) expectedCreaseLengths = Vt.IntArray([5, 4, 4, 2, 2]) creaseLengths = m.GetCreaseLengthsAttr().Get() self.assertEqual(creaseLengths, expectedCreaseLengths) expectedCreaseSharpnesses = Vt.FloatArray([10, 10, 10, 10, 10]) creaseSharpnesses = m.GetCreaseSharpnessesAttr().Get() self.assertAlmostEqual(creaseSharpnesses, expectedCreaseSharpnesses, places=3)
def testSkelTransforms(self): """ Tests that the computed joint transforms in USD, when tarnsformed into world space, match the world space transforms of the Maya joints. """ mayaFile = os.path.join(self.inputPath, "UsdExportSkeletonTest", "UsdExportSkeleton.ma") cmds.file(mayaFile, force=True, open=True) # frameRange = [1, 30] frameRange = [1, 3] # TODO: The joint hierarchy intentionally includes non-joint nodes, # which are expected to be ignored. However, when we try to extract # restTransforms from the dagPose, the intermediate transforms cause # problems, since they are not members of the dagPose. As a result, # no dag pose is exported. Need to come up with a way to handle this # correctly in export. print("Expect warnings about invalid restTransforms") usdFile = os.path.abspath('UsdExportSkeleton.usda') cmds.usdExport(mergeTransformAndShape=True, file=usdFile, shadingMode='none', frameRange=frameRange, exportSkels='auto') stage = Usd.Stage.Open(usdFile) root = UsdSkel.Root.Get(stage, '/SkelChar') self.assertTrue(root) skelCache = UsdSkel.Cache() skelCache.Populate(root) skel = UsdSkel.Skeleton.Get(stage, '/SkelChar/Hips') self.assertTrue(skel) skelQuery = skelCache.GetSkelQuery(skel) self.assertTrue(skelQuery) xfCache = UsdGeom.XformCache() for frame in range(*frameRange): cmds.currentTime(frame, edit=True) xfCache.SetTime(frame) skelLocalToWorld = xfCache.GetLocalToWorldTransform(skelQuery.GetPrim()) usdJointXforms = skelQuery.ComputeJointSkelTransforms(frame) for joint,usdJointXf in zip(skelQuery.GetJointOrder(), usdJointXforms): usdJointWorldXf = usdJointXf * skelLocalToWorld selList = OM.MSelectionList() selList.add(Sdf.Path(joint).name) dagPath = selList.getDagPath(0) mayaJointWorldXf = Gf.Matrix4d(*dagPath.inclusiveMatrix()) self.assertTrue(Gf.IsClose(mayaJointWorldXf, usdJointWorldXf, 1e-5))
def testSkeletonTopology(self): """Tests that the joint topology is correct.""" usdFile = os.path.abspath('UsdExportSkeleton.usda') cmds.usdExport(mergeTransformAndShape=True, file=usdFile, shadingMode='none') stage = Usd.Stage.Open(usdFile) skeleton = UsdSkel.Skeleton.Get(stage, '/skeleton_Hip') self.assertTrue(skeleton) joints = skeleton.GetJointsAttr().Get() self.assertEqual( joints, Vt.TokenArray([ "Hip", "Hip/Spine", "Hip/Spine/Neck", "Hip/Spine/Neck/Head", "Hip/Spine/Neck/LArm", "Hip/Spine/Neck/LArm/LHand", # note: skips ExtraJoints because it's not a joint "Hip/Spine/Neck/LArm/LHand/ExtraJoints/ExtraJoint1", "Hip/Spine/Neck/LArm/LHand/ExtraJoints/ExtraJoint1/ExtraJoint2", "Hip/Spine/Neck/RArm", "Hip/Spine/Neck/RArm/RHand", "Hip/RLeg", "Hip/RLeg/RFoot", "Hip/LLeg", "Hip/LLeg/LFoot" ]))
def testReexportScope(self): cmds.usdImport(file=self.USD_FILE, primPath='/') cmds.usdExport(file=self.USD_FILE_OUT) stage = Usd.Stage.Open(self.USD_FILE_OUT) self.assertTrue(stage) self.assertTrue(stage.GetPrimAtPath('/A')) self.assertEqual(stage.GetPrimAtPath('/A').GetTypeName(), 'Xform') self.assertTrue(stage.GetPrimAtPath('/A/A_1')) self.assertEqual(stage.GetPrimAtPath('/A/A_1').GetTypeName(), 'Scope') self.assertTrue(stage.GetPrimAtPath('/A/A_1/A_1_I')) self.assertEqual(stage.GetPrimAtPath('/A/A_1/A_1_I').GetTypeName(), 'Mesh') self.assertTrue(stage.GetPrimAtPath('/A/A_1/A_1_II')) self.assertEqual(stage.GetPrimAtPath('/A/A_1/A_1_II').GetTypeName(), 'Camera') self.assertTrue(stage.GetPrimAtPath('/A/A_1/A_1_III')) self.assertEqual(stage.GetPrimAtPath('/A/A_1/A_1_III').GetTypeName(), 'Scope') self.assertTrue(stage.GetPrimAtPath('/A/A_2')) self.assertEqual(stage.GetPrimAtPath('/A/A_2').GetTypeName(), 'Scope') self.assertTrue(stage.GetPrimAtPath('/B')) self.assertEqual(stage.GetPrimAtPath('/B').GetTypeName(), 'Scope') self.assertTrue(stage.GetPrimAtPath('/B/B_1')) self.assertEqual(stage.GetPrimAtPath('/B/B_1').GetTypeName(), 'Xform')
def testReexport(self): cmds.usdImport(file=self.USD_FILE, primPath='/') cmds.usdExport(file=self.USD_FILE_OUT) stage = Usd.Stage.Open(self.USD_FILE_OUT) self.assertTrue(stage) self.assertTrue(stage.GetPrimAtPath('/A')) self.assertEqual(stage.GetPrimAtPath('/A').GetTypeName(), 'Xform') self.assertTrue(stage.GetPrimAtPath('/A/A_1')) self.assertEqual(stage.GetPrimAtPath('/A/A_1').GetTypeName(), '') self.assertTrue(stage.GetPrimAtPath('/A/A_1/A_1_I')) self.assertEqual(stage.GetPrimAtPath('/A/A_1/A_1_I').GetTypeName(), '') self.assertTrue(stage.GetPrimAtPath('/A/A_1/A_1_II')) self.assertEqual(stage.GetPrimAtPath('/A/A_1/A_1_II').GetTypeName(), '') # Originally Cube, but not on re-export! self.assertTrue(stage.GetPrimAtPath('/A/A_1/A_1_III')) self.assertEqual(stage.GetPrimAtPath('/A/A_1/A_1_III').GetTypeName(), 'Scope') self.assertTrue(stage.GetPrimAtPath('/A/A_2')) self.assertEqual(stage.GetPrimAtPath('/A/A_2').GetTypeName(), 'Scope') self.assertTrue(stage.GetPrimAtPath('/B')) self.assertEqual(stage.GetPrimAtPath('/B').GetTypeName(), '') self.assertTrue(stage.GetPrimAtPath('/B/B_1')) self.assertEqual(stage.GetPrimAtPath('/B/B_1').GetTypeName(), 'Xform')
def testExportAsPoly(self): usdFile = os.path.abspath('UsdExportMesh_none.usda') cmds.usdExport(mergeTransformAndShape=True, file=usdFile, shadingMode='none', defaultMeshScheme='none') stage = Usd.Stage.Open(usdFile) m = UsdGeom.Mesh.Get(stage, '/UsdExportMeshTest/unspecified') self.assertEqual(m.GetSubdivisionSchemeAttr().Get(), UsdGeom.Tokens.none) self.assertTrue(len(m.GetNormalsAttr().Get()) > 0) # XXX: For some reason, when the mesh export used the getNormal() # method on MItMeshFaceVertex, we would sometimes get incorrect normal # values. Instead, we had to get all of the normals off of the MFnMesh # and then use the iterator's normalId() method to do a lookup into the # normals. # This test ensures that we're getting correct normals. The mesh should # only have normals in the x or z direction. m = UsdGeom.Mesh.Get(stage, '/UsdExportMeshTest/TestNormalsMesh') normals = m.GetNormalsAttr().Get() self.assertTrue(normals) for n in normals: # we don't expect the normals to be pointed in the y-axis at all. self.assertAlmostEqual(n[1], 0.0, delta=1e-4) # make sure the other 2 values aren't both 0. self.assertNotAlmostEqual(abs(n[0]) + abs(n[2]), 0.0, delta=1e-4)
def testProxyShapeBoundingBox(self): mayaFile = os.path.abspath('ProxyShape.ma') cmds.file(mayaFile, open=True, force=True) # Verify that the proxy shape read something from the USD file. bboxSize = cmds.getAttr('Cube_usd.boundingBoxSize')[0] self.assertEqual(bboxSize, (1.0, 1.0, 1.0)) # The proxy shape is imaged by the pxrHdImagingShape, which should be # created by the proxy shape's postConstructor() method. Make sure the # pxrHdImagingShape (and its parent transform) exist. hdImagingTransformPath = '|HdImaging' hdImagingShapePath = '%s|HdImagingShape' % hdImagingTransformPath self.assertTrue(cmds.objExists(hdImagingTransformPath)) self.assertEqual(cmds.nodeType(hdImagingTransformPath), 'transform') self.assertTrue(cmds.objExists(hdImagingShapePath)) self.assertEqual(cmds.nodeType(hdImagingShapePath), 'pxrHdImagingShape') # The pxrHdImagingShape and its parent transform are set so that they # do not write to the Maya scene file and are not exported by # usdExport, so do a test export and make sure that's the case. usdFilePath = os.path.abspath('ProxyShapeExportTest.usda') cmds.usdExport(file=usdFilePath) usdStage = Usd.Stage.Open(usdFilePath) prim = usdStage.GetPrimAtPath('/HdImaging') self.assertFalse(prim) prim = usdStage.GetPrimAtPath('/HdImaging/HdImagingShape') self.assertFalse(prim)
def testExport_GeomModelAPI_MotionAPI(self): """Tests export with both the GeomModelAPI and MotionAPI.""" cmds.file(new=True, force=True) cmds.usdImport(file=self.inputUsdFile, shadingMode=[ ["none", "default"], ], apiSchema=['GeomModelAPI', 'MotionAPI']) newUsdFilePath = os.path.abspath('UsdAttrsNew_TwoAPIs.usda') # usdExport used to export all API schemas found as dynamic attributes. We now # require the list to be explicit, mirroring the way usdImport works. cmds.usdExport(file=newUsdFilePath, shadingMode='none', apiSchema=['GeomModelAPI', 'MotionAPI']) newUsdStage = Usd.Stage.Open(newUsdFilePath) world = newUsdStage.GetPrimAtPath('/World') self.assertEqual(world.GetAppliedSchemas(), ['MotionAPI', 'GeomModelAPI']) geomModelAPI = UsdGeom.ModelAPI(world) self.assertEqual(geomModelAPI.GetModelCardTextureXPosAttr().Get(), 'right.png') motionAPI = UsdGeom.MotionAPI(world) self.assertAlmostEqual(motionAPI.GetVelocityScaleAttr().Get(), 4.2, places=6)
def testExportWithClashStripping(self): mayaFilePath = os.path.abspath('UsdExportStripNamespaces.ma') cmds.file(mayaFilePath, new=True, force=True) node1 = cmds.polyCube( sx=5, sy=5, sz=5, name="cube1" ) cmds.namespace(add="foo") cmds.namespace(set="foo"); node2 = cmds.polyCube( sx=5, sy=5, sz=5, name="cube1" ) cmds.namespace(set=":"); usdFilePath = os.path.abspath('UsdExportStripNamespaces_EXPORTED.usda') errorRegexp = "Multiple dag nodes map to the same prim path" \ ".+|cube1 - |foo:cube1.*" with self.assertRaisesRegexp(RuntimeError, errorRegexp) as cm: cmds.usdExport(mergeTransformAndShape=True, selection=False, stripNamespaces=True, file=usdFilePath, shadingMode='none') with self.assertRaisesRegexp(RuntimeError,errorRegexp) as cm: cmds.usdExport(mergeTransformAndShape=False, selection=False, stripNamespaces=True, file=usdFilePath, shadingMode='none')
def setUpClass(cls): asFloat2 = mayaUsdLib.WriteUtil.WriteUVAsFloat2() suffix = "" if asFloat2: suffix += "Float" if mayaUsdLib.WriteUtil.WriteMap1AsST(): suffix += "ST" inputPath = fixturesUtils.setUpClass(__file__, suffix) if asFloat2: filePath = os.path.join(inputPath, 'UsdExportUVSetsFloatTest', 'UsdExportUVSetsTest_Float.ma') else: filePath = os.path.join(inputPath, 'UsdExportUVSetsTest', 'UsdExportUVSetsTest.ma') cmds.file(filePath, open=True, force=True) # Make some live edits to the box with weird UVs for the # testExportUvVersusUvIndexFromIterator test. cmds.select("box.map[0:299]", r=True) cmds.polyEditUV(u=1.0, v=1.0) usdFilePath = os.path.abspath('UsdExportUVSetsTest.usda') cmds.usdExport(mergeTransformAndShape=True, file=usdFilePath, shadingMode='none', exportColorSets=False, exportDisplayColor=False, exportUVs=True) cls._stage = Usd.Stage.Open(usdFilePath)
def testExportInstances_ModelHierarchyValidation(self): """Tests that model-hierarchy validation works with instances.""" usdFile = os.path.abspath('UsdExportInstances_kinds.usda') with self.assertRaises(RuntimeError): # Should fail because assembly |pCube1 contains gprims. cmds.usdExport(mergeTransformAndShape=True, exportInstances=True, shadingMode='none', kind='assembly', file=usdFile)
def testSkelTransformDecomposition(self): """ Tests that the decomposed transform values, when recomposed, recreate the correct Maya transformation matrix. """ usdFile = os.path.abspath('UsdExportSkeleton.usda') cmds.usdExport(mergeTransformAndShape=True, file=usdFile, shadingMode='none', frameRange=[1, 30]) stage = Usd.Stage.Open(usdFile) anim = UsdSkel.PackedJointAnimation.Get(stage, '/skeleton_Hip/Animation') self.assertEqual(anim.GetJointsAttr().Get()[8], "Hip/Spine/Neck/RArm") animT = anim.GetTranslationsAttr() animR = anim.GetRotationsAttr() animS = anim.GetScalesAttr() selList = OM.MSelectionList() selList.add("RArm") rArmDagPath = selList.getDagPath(0) fnTransform = OM.MFnTransform(rArmDagPath) for i in range(1, 31): cmds.currentTime(i, edit=True) mayaXf = fnTransform.transformation().asMatrix() usdT = animT.Get(i)[8] usdR = animR.Get(i)[8] usdS = animS.Get(i)[8] usdXf = UsdSkel.MakeTransform(usdT, usdR, usdS) self._AssertMatricesClose(usdXf, Gf.Matrix4d(*mayaXf))
def testExportAsCatmullClark(self): usdFile = os.path.abspath('UsdExportMesh_catmullClark.usda') cmds.usdExport(mergeTransformAndShape=True, file=usdFile, shadingMode='none', defaultMeshScheme='catmullClark') stage = Usd.Stage.Open(usdFile) m = UsdGeom.Mesh.Get(stage, '/UsdExportMeshTest/poly') self.assertEqual(m.GetSubdivisionSchemeAttr().Get(), UsdGeom.Tokens.none) self.assertTrue(len(m.GetNormalsAttr().Get()) > 0) m = UsdGeom.Mesh.Get(stage, '/UsdExportMeshTest/polyNoNormals') self.assertEqual(m.GetSubdivisionSchemeAttr().Get(), UsdGeom.Tokens.none) self.assertTrue(not m.GetNormalsAttr().Get()) m = UsdGeom.Mesh.Get(stage, '/UsdExportMeshTest/subdiv') self.assertEqual(m.GetSubdivisionSchemeAttr().Get(), UsdGeom.Tokens.catmullClark) self.assertTrue(not m.GetNormalsAttr().Get()) m = UsdGeom.Mesh.Get(stage, '/UsdExportMeshTest/unspecified') self.assertEqual(m.GetSubdivisionSchemeAttr().Get(), UsdGeom.Tokens.catmullClark) self.assertTrue(not m.GetNormalsAttr().Get())
def testExport(self): '''Tests standard usdz package export.''' usdFile = os.path.abspath('MyAwesomePackage.usdz') cmds.usdExport( file=usdFile, mergeTransformAndShape=True, shadingMode='none') # Lets make sure that the root layer is the first file and that all # the references were localized ok. zipFile = Usd.ZipFile.Open(usdFile) fileNames = zipFile.GetFileNames() self.assertEqual(fileNames, [ "MyAwesomePackage.usd", "ReferenceModel.usda", "BaseModel.usda", "card.png" ]) # Open the usdz file up to verify that everything exported properly. stage = Usd.Stage.Open(usdFile) self._AssertExpectedStage(stage, "./card.png") # Make sure there's no weird temp files sitting around. self._AssertNoTempFiles(usdFile)
def testExportToAnonymousLayer(self): """ Tests exporting to an existing anonymous layer. In normal (non-append) mode, this should completely overwrite the contents of the anonymous layer. """ cmds.file(new=True, force=True) cmds.polyCube(name='TestCube') stage = Usd.Stage.CreateInMemory() self.assertFalse(stage.GetPrimAtPath('/TestCube').IsValid()) cmds.usdExport( file=stage.GetRootLayer().identifier, mergeTransformAndShape=True, shadingMode='none') self.assertTrue(stage.GetPrimAtPath('/TestCube').IsValid()) cmds.rename('TestCube', 'TestThing') cmds.usdExport( file=stage.GetRootLayer().identifier, mergeTransformAndShape=True, shadingMode='none') self.assertFalse(stage.GetPrimAtPath('/TestCube').IsValid()) self.assertTrue(stage.GetPrimAtPath('/TestThing').IsValid())
def testExportSkin_Posed(self): """ Checks that the skeletal skinning works when the skeleton is exported in a non-rest pose. """ cmds.currentTime(1, edit=True) usdFile = os.path.abspath('UsdExportMesh_skelPosed.usda') cmds.usdExport(mergeTransformAndShape=True, file=usdFile, shadingMode='none', exportSkin='explicit') usdFileNoSkin = os.path.abspath('UsdExportMesh_skelPosed_noskin.usda') cmds.usdExport(mergeTransformAndShape=True, file=usdFileNoSkin, shadingMode='none', exportSkin='none') stage = Usd.Stage.Open(usdFile) stageNS = Usd.Stage.Open(usdFileNoSkin) m = UsdGeom.Mesh.Get(stage, '/ExplicitSkelRoot/mesh') mNS = UsdGeom.Mesh.Get(stageNS, '/ExplicitSkelRoot/mesh') # Check Maya's output mesh versus the UsdSkel-computed result. skelRoot = UsdSkel.Root.Get(stage, '/ExplicitSkelRoot') UsdSkel.BakeSkinningLBS(skelRoot) points = m.GetPointsAttr().Get() refSkinnedPoints = mNS.GetPointsAttr().Get() self._AssertVec3fArrayAlmostEqual(points, refSkinnedPoints)
def testExportToDiskLayer(self): """ Tests that exporting to an on-disk layer that is open elsewhere in the process still works. """ cmds.file(new=True, force=True) cmds.polyCube(name='TestCube') filePath = os.path.abspath("testStage.usda") stage = Usd.Stage.CreateNew(filePath) stage.Save() self.assertFalse(stage.GetPrimAtPath('/TestCube').IsValid()) cmds.usdExport( file=filePath, mergeTransformAndShape=True, shadingMode='none') self.assertTrue(stage.GetPrimAtPath('/TestCube').IsValid()) cmds.rename('TestCube', 'TestThing') cmds.usdExport( file=filePath, mergeTransformAndShape=True, shadingMode='none') self.assertFalse(stage.GetPrimAtPath('/TestCube').IsValid()) self.assertTrue(stage.GetPrimAtPath('/TestThing').IsValid())
def testExportWithStripAndMerge(self): mayaFilePath = os.path.abspath('UsdExportStripNamespaces.ma') cmds.file(mayaFilePath, new=True, force=True) cmds.namespace(add=":foo") cmds.namespace(add=":bar") node1 = cmds.polyCube(sx=5, sy=5, sz=5, name="cube1") cmds.namespace(set=":foo") node2 = cmds.polyCube(sx=5, sy=5, sz=5, name="cube2") cmds.namespace(set=":bar") node3 = cmds.polyCube(sx=5, sy=5, sz=5, name="cube3") cmds.namespace(set=":") usdFilePath = os.path.abspath('UsdExportStripNamespaces_EXPORTED.usda') cmds.usdExport(mergeTransformAndShape=True, selection=False, stripNamespaces=True, file=usdFilePath, shadingMode='none') stage = Usd.Stage.Open(usdFilePath) self.assertTrue(stage) expectedPrims = ("/cube1", "/cube2", "/cube3") for primPath in expectedPrims: prim = stage.GetPrimAtPath(primPath) self.assertTrue(prim.IsValid(), "Expect " + primPath)
def testReexportScope(self): cmds.usdImport(file=self.USD_FILE, primPath='/') cmds.usdExport(file=self.USD_FILE_OUT) stage = Usd.Stage.Open(self.USD_FILE_OUT) self.assertTrue(stage) self.assertTrue(stage.GetPrimAtPath('/A')) self.assertEqual(stage.GetPrimAtPath('/A').GetTypeName(), 'Xform') self.assertTrue(stage.GetPrimAtPath('/A/A_1')) self.assertEqual(stage.GetPrimAtPath('/A/A_1').GetTypeName(), 'Scope') self.assertTrue(stage.GetPrimAtPath('/A/A_1/A_1_I')) self.assertEqual( stage.GetPrimAtPath('/A/A_1/A_1_I').GetTypeName(), 'Mesh') self.assertTrue(stage.GetPrimAtPath('/A/A_1/A_1_II')) self.assertEqual( stage.GetPrimAtPath('/A/A_1/A_1_II').GetTypeName(), 'Camera') self.assertTrue(stage.GetPrimAtPath('/A/A_1/A_1_III')) self.assertEqual( stage.GetPrimAtPath('/A/A_1/A_1_III').GetTypeName(), 'Scope') self.assertTrue(stage.GetPrimAtPath('/A/A_2')) self.assertEqual(stage.GetPrimAtPath('/A/A_2').GetTypeName(), 'Scope') self.assertTrue(stage.GetPrimAtPath('/B')) self.assertEqual(stage.GetPrimAtPath('/B').GetTypeName(), 'Scope') self.assertTrue(stage.GetPrimAtPath('/B/B_1')) self.assertEqual(stage.GetPrimAtPath('/B/B_1').GetTypeName(), 'Xform')
def testReexport(self): cmds.usdImport(file=self.USD_FILE, primPath='/') cmds.usdExport(file=self.USD_FILE_OUT) stage = Usd.Stage.Open(self.USD_FILE_OUT) self.assertTrue(stage) self.assertTrue(stage.GetPrimAtPath('/A')) self.assertEqual(stage.GetPrimAtPath('/A').GetTypeName(), 'Xform') self.assertTrue(stage.GetPrimAtPath('/A/A_1')) self.assertEqual(stage.GetPrimAtPath('/A/A_1').GetTypeName(), '') self.assertTrue(stage.GetPrimAtPath('/A/A_1/A_1_I')) self.assertEqual(stage.GetPrimAtPath('/A/A_1/A_1_I').GetTypeName(), '') self.assertTrue(stage.GetPrimAtPath('/A/A_1/A_1_II')) self.assertEqual( stage.GetPrimAtPath('/A/A_1/A_1_II').GetTypeName(), '') # Originally Cube, but not on re-export! self.assertTrue(stage.GetPrimAtPath('/A/A_1/A_1_III')) self.assertEqual( stage.GetPrimAtPath('/A/A_1/A_1_III').GetTypeName(), 'Scope') self.assertTrue(stage.GetPrimAtPath('/A/A_2')) self.assertEqual(stage.GetPrimAtPath('/A/A_2').GetTypeName(), 'Scope') self.assertTrue(stage.GetPrimAtPath('/B')) self.assertEqual(stage.GetPrimAtPath('/B').GetTypeName(), '') self.assertTrue(stage.GetPrimAtPath('/B/B_1')) self.assertEqual(stage.GetPrimAtPath('/B/B_1').GetTypeName(), 'Xform')
def testArKitCompatibility(self): '''Tests usdz package export with ARKit compatibility profile.''' usdFile = os.path.abspath('MyAwesomeArKitCompatibleFile.usdz') usdFileNoExt = os.path.abspath('MyAwesomeArKitCompatibleFile') # The usdExport command should automatically add "usdz" extension since # we're requestion appleArKit compatibility. cmds.usdExport(file=usdFileNoExt, mergeTransformAndShape=True, shadingMode='none', compatibility='appleArKit') # Lets make sure that the root layer is the first file and that all # the references were localized ok. # Note that the path of "card.png" in the usdz archive may have changed # because of the flattening step. zipFile = Usd.ZipFile.Open(usdFile) fileNames = zipFile.GetFileNames() self.assertEqual(len(fileNames), 2) self.assertEqual(fileNames[0], "MyAwesomeArKitCompatibleFile.usdc") self.assertTrue(fileNames[1].endswith("card.png")) # Open the usdz file up to verify that everything exported properly. stage = Usd.Stage.Open(usdFile) self._AssertExpectedStage(stage, fileNames[-1]) # Make sure there's no weird temp files sitting around. self._AssertNoTempFiles(usdFile)
def testExport(self): """ Tests that the adaptor mechanism can export USD_hidden, USD_instanceable, and USD_kind attributes by setting the correct metadata in the output USD file. """ cmds.file(new=True, force=True) usdFile = os.path.abspath('UsdAttrs.usda') cmds.usdImport(file=usdFile, shadingMode='none') newUsdFilePath = os.path.abspath('UsdAttrsNew.usda') cmds.usdExport(file=newUsdFilePath, shadingMode='none') newUsdStage = Usd.Stage.Open(newUsdFilePath) # pCube1 and pCube2 have USD_kind. prim1 = newUsdStage.GetPrimAtPath('/World/pCube1') self.assertEqual(Usd.ModelAPI(prim1).GetKind(), 'potato') prim2 = newUsdStage.GetPrimAtPath('/World/pCube2') self.assertEqual(Usd.ModelAPI(prim2).GetKind(), 'bakedpotato') # pCube2, pCube4, and pCube5 have USD_hidden. pCube1 and pCube3 do not. self.assertTrue(newUsdStage.GetPrimAtPath('/World/pCube2').HasAuthoredHidden()) self.assertTrue(newUsdStage.GetPrimAtPath('/World/pCube4').HasAuthoredHidden()) self.assertTrue(newUsdStage.GetPrimAtPath('/World/pCube5').HasAuthoredHidden()) self.assertFalse(newUsdStage.GetPrimAtPath('/World/pCube1').HasAuthoredHidden()) self.assertFalse(newUsdStage.GetPrimAtPath('/World/pCube3').HasAuthoredHidden()) self.assertTrue(newUsdStage.GetPrimAtPath('/World/pCube2').IsHidden()) self.assertTrue(newUsdStage.GetPrimAtPath('/World/pCube4').IsHidden()) self.assertFalse(newUsdStage.GetPrimAtPath('/World/pCube5').IsHidden()) # pCube3 and pCube4 have USD_instanceable. self.assertTrue(newUsdStage.GetPrimAtPath('/World/pCube3').IsInstanceable()) self.assertTrue(newUsdStage.GetPrimAtPath('/World/pCube4').IsInstanceable())
def testSkelWithoutBindPose(self): """ Tests export of a Skeleton when a bindPose is not fully setup. """ mayaFile = os.path.join(self.inputPath, "UsdExportSkeletonTest", "UsdExportSkeletonWithoutBindPose.ma") cmds.file(mayaFile, force=True, open=True) frameRange = [1, 5] usdFile = os.path.abspath('UsdExportSkeletonWithoutBindPose.usda') cmds.usdExport(mergeTransformAndShape=True, file=usdFile, shadingMode='none', frameRange=frameRange, exportSkels='auto') stage = Usd.Stage.Open(usdFile) skeleton = UsdSkel.Skeleton.Get(stage, '/cubeRig/skel/joint1') self.assertEqual(skeleton.GetBindTransformsAttr().Get(), Vt.Matrix4dArray([Gf.Matrix4d(1.0)])) self.assertEqual(skeleton.GetJointsAttr().Get(), Vt.TokenArray(['joint1'])) self.assertEqual(skeleton.GetRestTransformsAttr().Get(), Vt.Matrix4dArray([Gf.Matrix4d(1.0)])) self.assertTrue(skeleton.GetPrim().HasAPI(UsdSkel.BindingAPI)) skelBindingAPI = UsdSkel.BindingAPI(skeleton) self.assertTrue(skelBindingAPI) animSourcePrim = skelBindingAPI.GetAnimationSource() self.assertEqual(animSourcePrim.GetPath(), '/cubeRig/skel/joint1/Animation') animSource = UsdSkel.Animation(animSourcePrim) self.assertTrue(animSource) self.assertEqual(skeleton.GetJointsAttr().Get(), Vt.TokenArray(['joint1'])) self.assertEqual(animSource.GetRotationsAttr().Get(), Vt.QuatfArray([Gf.Quatf(1.0, Gf.Vec3f(0.0))])) self.assertEqual(animSource.GetScalesAttr().Get(), Vt.Vec3hArray([Gf.Vec3h(1.0)])) self.assertEqual( animSource.GetTranslationsAttr().Get(Usd.TimeCode.Default()), Vt.Vec3fArray([Gf.Vec3f(5.0, 5.0, 0.0)])) self.assertEqual( animSource.GetTranslationsAttr().Get(1.0), Vt.Vec3fArray([Gf.Vec3f(0.0, 0.0, 0.0)])) self.assertEqual( animSource.GetTranslationsAttr().Get(2.0), Vt.Vec3fArray([Gf.Vec3f(1.25, 1.25, 0.0)])) self.assertEqual( animSource.GetTranslationsAttr().Get(3.0), Vt.Vec3fArray([Gf.Vec3f(2.5, 2.5, 0.0)])) self.assertEqual( animSource.GetTranslationsAttr().Get(4.0), Vt.Vec3fArray([Gf.Vec3f(3.75, 3.75, 0.0)])) self.assertEqual( animSource.GetTranslationsAttr().Get(5.0), Vt.Vec3fArray([Gf.Vec3f(5.0, 5.0, 0.0)]))
def testExportWithClashStripping(self): mayaFilePath = os.path.abspath('UsdExportStripNamespaces.ma') cmds.file(mayaFilePath, new=True, force=True) node1 = cmds.polyCube(sx=5, sy=5, sz=5, name="cube1") cmds.namespace(add="foo") cmds.namespace(set="foo") node2 = cmds.polyCube(sx=5, sy=5, sz=5, name="cube1") cmds.namespace(set=":") usdFilePath = os.path.abspath('UsdExportStripNamespaces_EXPORTED.usda') errorRegexp = "Multiple dag nodes map to the same prim path" \ ".+|cube1 - |foo:cube1.*" with self.assertRaisesRegexp(RuntimeError, errorRegexp) as cm: cmds.usdExport(mergeTransformAndShape=True, selection=False, stripNamespaces=True, file=usdFilePath, shadingMode='none') with self.assertRaisesRegexp(RuntimeError, errorRegexp) as cm: cmds.usdExport(mergeTransformAndShape=False, selection=False, stripNamespaces=True, file=usdFilePath, shadingMode='none')
def setUpClass(cls): standalone.initialize('usd') # Stage with simple (non-nested) instancing. mayaFile = os.path.abspath('InstancedShading.ma') cmds.file(mayaFile, open=True, force=True) usdFilePath = os.path.abspath('InstancedShading.usda') cmds.loadPlugin('pxrUsd') cmds.usdExport(mergeTransformAndShape=True, file=usdFilePath, shadingMode='displayColor', exportInstances=True, exportCollectionBasedBindings=True, exportMaterialCollections=True, materialCollectionsPath="/World") cls._simpleStage = Usd.Stage.Open(usdFilePath) # Stage with nested instancing. mayaFile = os.path.abspath('NestedInstancedShading.ma') cmds.file(mayaFile, open=True, force=True) usdFilePath = os.path.abspath('NestedInstancedShading.usda') cmds.loadPlugin('pxrUsd') cmds.usdExport(mergeTransformAndShape=True, file=usdFilePath, shadingMode='displayColor', exportInstances=True, exportCollectionBasedBindings=True, exportMaterialCollections=True, materialCollectionsPath="/World") cls._nestedStage = Usd.Stage.Open(usdFilePath)
def _GetExportedStage(self, activeRenderLayerName, renderLayerMode='defaultLayer', **kwargs): filePath = os.path.join(self.inputPath, "UsdExportRenderLayerModeTest", "UsdExportRenderLayerModeTest.ma") cmds.file(filePath, force=True, open=True) usdFilePathFormat = 'UsdExportRenderLayerModeTest_activeRenderLayer-%s_renderLayerMode-%s.usda' usdFilePath = usdFilePathFormat % (activeRenderLayerName, renderLayerMode) usdFilePath = os.path.abspath(usdFilePath) cmds.editRenderLayerGlobals(currentRenderLayer=activeRenderLayerName) self.assertEqual(self._GetCurrentRenderLayerName(), activeRenderLayerName) # Export to USD. cmds.usdExport(mergeTransformAndShape=True, file=usdFilePath, shadingMode='none', renderLayerMode=renderLayerMode, **kwargs) stage = Usd.Stage.Open(usdFilePath) self.assertTrue(stage) # Make sure the current render layer is the same as what it was pre-export. self.assertEqual(self._GetCurrentRenderLayerName(), activeRenderLayerName) return stage
def setUpClass(cls): standalone.initialize('usd') cmds.loadPlugin('pxrUsd') if not UsdMaya.WriteUtil.WriteUVAsFloat2(): cmds.file(os.path.abspath('UsdExportUVSetsTest.ma'), open=True, force=True) else: cmds.file(os.path.abspath('UsdExportFloatUVSetsTest.ma'), open=True, force=True) # Make some live edits to the box with weird UVs for the # testExportUvVersusUvIndexFromIterator test. cmds.select("box.map[0:299]", r=True) cmds.polyEditUV(u=1.0, v=1.0) usdFilePath = os.path.abspath('UsdExportUVSetsTest.usda') cmds.usdExport(mergeTransformAndShape=True, file=usdFilePath, shadingMode='none', exportColorSets=False, exportDisplayColor=False, exportUVs=True) cls._stage = Usd.Stage.Open(usdFilePath)
def testExportInstances(self): usdFile = os.path.abspath('UsdExportParticles_particles.usda') cmds.usdExport(mergeTransformAndShape=False, exportInstances=False, shadingMode='none', file=usdFile, frameRange=(1, 1)) stage = Usd.Stage.Open(usdFile) p = UsdGeom.Points.Get(stage, '/particle1/particleShape1') self.assertTrue(p.GetPrim().IsValid()) self.assertEqual( p.GetPointsAttr().Get(1), Vt.Vec3fArray(5, (Gf.Vec3f(5.0, 0.0, -6.0), Gf.Vec3f(-4.0, 0.0, -4.5), Gf.Vec3f(-4.5, 0.0, 3.0), Gf.Vec3f( -2.0, 0.0, 8.5), Gf.Vec3f(3.0, 0.0, 3.5)))) self.assertEqual( p.GetVelocitiesAttr().Get(1), Vt.Vec3fArray(5, (Gf.Vec3f(0.0, 0.0, 0.0), Gf.Vec3f( 1.0, 1.0, 1.0), Gf.Vec3f(2.0, 3.0, 4.0), Gf.Vec3f( 5.0, 6.0, 7.0), Gf.Vec3f(8.0, 9.0, 10.0)))) self.assertEqual(p.GetWidthsAttr().Get(1), Vt.FloatArray(5, (2.0, 2.0, 2.0, 2.0, 2.0))) self.assertEqual(p.GetIdsAttr().Get(1), Vt.Int64Array(5, (0, 1, 2, 3, 4)))
def testExportWithStripAndMerge(self): mayaFilePath = os.path.abspath('UsdExportStripNamespaces.ma') cmds.file(mayaFilePath, new=True, force=True) cmds.namespace(add=":foo") cmds.namespace(add=":bar") node1 = cmds.polyCube( sx=5, sy=5, sz=5, name="cube1" ) cmds.namespace(set=":foo"); node2 = cmds.polyCube( sx=5, sy=5, sz=5, name="cube2" ) cmds.namespace(set=":bar"); node3 = cmds.polyCube( sx=5, sy=5, sz=5, name="cube3" ) cmds.namespace(set=":"); usdFilePath = os.path.abspath('UsdExportStripNamespaces_EXPORTED.usda') cmds.usdExport(mergeTransformAndShape=True, selection=False, stripNamespaces=True, file=usdFilePath, shadingMode='none') stage = Usd.Stage.Open(usdFilePath) self.assertTrue(stage) expectedPrims = ("/cube1", "/cube2", "/cube3") for primPath in expectedPrims: prim = stage.GetPrimAtPath(primPath) self.assertTrue(prim.IsValid(), "Expect " + primPath)
def testExportToDiskLayer(self): """ Tests that exporting to an on-disk layer that is open elsewhere in the process still works. """ cmds.file(new=True, force=True) cmds.polyCube(name='TestCube') filePath = os.path.join(self.inputPath, "UsdExportNurbsCurveTest", "testStage.usda") stage = Usd.Stage.CreateNew(filePath) stage.Save() self.assertFalse(stage.GetPrimAtPath('/TestCube').IsValid()) cmds.usdExport(file=filePath, mergeTransformAndShape=True, shadingMode='none') self.assertTrue(stage.GetPrimAtPath('/TestCube').IsValid()) cmds.rename('TestCube', 'TestThing') cmds.usdExport(file=filePath, mergeTransformAndShape=True, shadingMode='none') self.assertFalse(stage.GetPrimAtPath('/TestCube').IsValid()) self.assertTrue(stage.GetPrimAtPath('/TestThing').IsValid())
def testExportWithKindAttrAndKindFlag(self): """ Tests exporting a Maya file with both USD_kind custom attributes and using the usdExport -kind flag; there should be an error if the USD_kind is not derived from the kind specified in the -kind flag. """ cmds.file(os.path.abspath('KindTestUsdKindAttr.ma'), open=True, force=True) cmds.loadPlugin('pxrUsd') usdFilePath = os.path.abspath('KindTestUsdKindAttr.usda') with self.assertRaises(RuntimeError): cmds.usdExport(mergeTransformAndShape=True, file=usdFilePath, kind='assembly') cmds.usdExport(mergeTransformAndShape=True, file=usdFilePath, kind='model') stage = Usd.Stage.Open(usdFilePath) self.assertTrue(stage) rootPrim = stage.GetPrimAtPath('/KindTest') self.assertTrue(Kind.Registry().IsA(Usd.ModelAPI(rootPrim).GetKind(), 'component')) rootPrim2 = stage.GetPrimAtPath('/KindTest2') self.assertTrue(Kind.Registry().IsA(Usd.ModelAPI(rootPrim2).GetKind(), 'assembly'))
def testExportWithKindFlag(self): """ Tests exporting a Maya file with no USD_kind custom attributes and using the usdExport -kind flag. """ cmds.file(os.path.abspath('KindTest.ma'), open=True, force=True) cmds.loadPlugin('pxrUsd') usdFilePath = os.path.abspath('KindTest.usda') # Check the error mark; this ensures that we actually got a Tf error # (that was eventually converted into a Maya error, which Maya raises # in Python as a RuntimeError). mark = Tf.Error.Mark() mark.SetMark() with self.assertRaises(RuntimeError): cmds.usdExport(mergeTransformAndShape=True, file=usdFilePath, kind='assembly') errors = mark.GetErrors() self.assertEqual(len(errors), 1) self.assertIn( "</KindTest> has kind 'assembly', which is derived from 'assembly'", str(errors[0])) cmds.usdExport(mergeTransformAndShape=True, file=usdFilePath, kind='fakeKind') stage = Usd.Stage.Open(usdFilePath) self.assertTrue(stage) rootPrim = stage.GetPrimAtPath('/KindTest') self.assertTrue(Kind.Registry().IsA(Usd.ModelAPI(rootPrim).GetKind(), 'fakeKind'))
def setUpClass(cls): standalone.initialize('usd') cmds.loadPlugin('pxrUsd') if not UsdMaya.WriteUtil.WriteUVAsFloat2(): cmds.file(os.path.abspath('UsdExportUVSetsTest.ma'), open=True, force=True) else: cmds.file(os.path.abspath('UsdExportUVSetsTest_Float.ma'), open=True, force=True) # Make some live edits to the box with weird UVs for the # testExportUvVersusUvIndexFromIterator test. cmds.select("box.map[0:299]", r=True) cmds.polyEditUV(u=1.0, v=1.0) usdFilePath = os.path.abspath('UsdExportUVSetsTest.usda') cmds.usdExport(mergeTransformAndShape=True, file=usdFilePath, shadingMode='none', exportColorSets=False, exportDisplayColor=False, exportUVs=True) cls._stage = Usd.Stage.Open(usdFilePath)
def testExportWithAssemblyAndMesh(self): """ Tests exporting a Maya file with a root prim containing an assembly and a mesh. """ cmds.file(os.path.abspath('KindTestAssemblyAndMesh.ma'), open=True, force=True) cmds.loadPlugin('pxrUsd') # Should fail due to the mesh. usdFilePath = os.path.abspath('KindTestAssemblyAndMesh.usda') with self.assertRaises(RuntimeError): cmds.usdExport(mergeTransformAndShape=True, file=usdFilePath, kind='assembly') # Should be 'component' because of the mesh usdFilePath = os.path.abspath('KindTestAssemblyAndMesh.usda') cmds.usdExport(mergeTransformAndShape=True, file=usdFilePath) stage = Usd.Stage.Open(usdFilePath) self.assertTrue(stage) rootPrim = stage.GetPrimAtPath('/KindTest') self.assertTrue(Kind.Registry().IsA(Usd.ModelAPI(rootPrim).GetKind(), 'component'))
def testExport(self): """ The test scene has multiple face set connections to materials. Make sure the export code has merged the indices correctly. """ usdFile = os.path.abspath('UsdExportGeomSubset.usda') cmds.usdExport(mergeTransformAndShape=True, file=usdFile, shadingMode='useRegistry') stage = Usd.Stage.Open(usdFile) expected = [ ('/pPlane1/initialShadingGroup', [ 1, ]), ('/pPlane1/blinn1SG', [ 2, ]), ('/pPlane1/phong1SG', [0, 3]), ('/pPlane2/blinn1SG', [0, 3]), ('/pPlane2/phong1SG', [1, 2]), ] for subset_path, indices in expected: subset = UsdGeom.Subset(stage.GetPrimAtPath(subset_path)) self.assertEqual(subset.GetElementTypeAttr().Get(), UsdGeom.Tokens.face) self.assertEqual(subset.GetIndicesAttr().Get(), Vt.IntArray(indices))
def setUpClass(cls): standalone.initialize('usd') cmds.loadPlugin("MASH") scene = "InstancerTestMash.ma" cmds.file(os.path.abspath(scene), open=True, force=True) # Create nCache. This is to be on the safe side and ensure that the # particles have the same positions for all test cases. # It doesn't look like doCreateNclothCache is Python-wrapped. cmds.select("nParticle1") # Note: this MEL command expects paths to be in the Maya-normalized # format with the '/' dir separator; using the Windows-style separator # will cause MEL script errors because it's treated as an escape. cacheLocation = os.path.abspath("nCache").replace(os.path.sep, "/") mel.eval( 'doCreateNclothCache 5 { "2", "1", "10", "OneFile", "1", "%s","0","","0", "add", "0", "1", "1","0","1","mcx" }' % cacheLocation) # Export to USD. (Don't load the reference assembly yet; this should # work without the reference assembly.) usdFilePath = os.path.abspath('InstancerTest.usda') cmds.loadPlugin('pxrUsd') cmds.usdExport(mergeTransformAndShape=True, file=usdFilePath, shadingMode='none', frameRange=(cls.START_TIMECODE, cls.END_TIMECODE), kind='component') cls.stage = Usd.Stage.Open(usdFilePath) # Load the USD reference assembly so that it draws instanced. assembly = OM.MFnAssembly(cls._GetDagPath("referencePrototype")) assembly.activate("Full")
def testExportInstances(self): usdFile = os.path.abspath('UsdExportPref_nopref.usda') cmds.usdExport(mergeTransformAndShape=True, exportReferenceObjects=False, shadingMode='none', file=usdFile) stage = Usd.Stage.Open(usdFile) plane1Path = '/pPlane1' plane2Path = '/pPlane2' plane1 = UsdGeom.Mesh.Get(stage, plane1Path) self.assertTrue(plane1.GetPrim().IsValid()) plane2 = UsdGeom.Mesh.Get(stage, plane2Path) self.assertTrue(plane2.GetPrim().IsValid()) self.assertFalse(plane1.GetPrimvar(UsdUtils.GetPrefName()).IsDefined()) usdFile = os.path.abspath('UsdExportPref_pref.usda') cmds.usdExport(mergeTransformAndShape=True, exportReferenceObjects=True, shadingMode='none', file=usdFile) stage = Usd.Stage.Open(usdFile) plane1 = UsdGeom.Mesh.Get(stage, plane1Path) self.assertTrue(plane1.GetPrim().IsValid()) plane2 = UsdGeom.Mesh.Get(stage, plane2Path) self.assertTrue(plane2.GetPrim().IsValid()) self.assertTrue(plane1.GetPrimvar(UsdUtils.GetPrefName()).IsDefined()) self.assertEqual(plane1.GetPrimvar(UsdUtils.GetPrefName()).Get(), plane2.GetPointsAttr().Get())
def testExportAsClip(self): """ Test that a maya scene exports to usd the same way if it is exported all at once, or in 5 frame clips and then stitched back together. """ # generate clip files and validate num samples on points attribute clipFiles = [] # first 5 frames have no animation usdFile = os.path.abspath('UsdExportAsClip_cube.001.usda') clipFiles.append(usdFile) cmds.usdExport(mergeTransformAndShape=True, file=usdFile, frameRange=(1, 5)) stage = Usd.Stage.Open(usdFile) self._ValidateNumSamples(stage,'/world/pCube1', 'points', 1) # next 5 frames have no animation usdFile = os.path.abspath('UsdExportAsClip_cube.005.usda') clipFiles.append(usdFile) cmds.usdExport(mergeTransformAndShape=True, file=usdFile, frameRange=(5, 10)) stage = Usd.Stage.Open(usdFile) self._ValidateNumSamples(stage, '/world/pCube1', 'points', 1) # next 5 frames have deformation animation usdFile = os.path.abspath('UsdExportAsClip_cube.010.usda') clipFiles.append(usdFile) frames = (10, 15) cmds.usdExport(mergeTransformAndShape=True, file=usdFile, frameRange=frames) stage = Usd.Stage.Open(usdFile) self._ValidateNumSamples(stage, '/world/pCube1', 'points', frames[1] + 1 - frames[0]) # next 5 frames have no animation usdFile = os.path.abspath('UsdExportAsClip_cube.015.usda') clipFiles.append(usdFile) cmds.usdExport(mergeTransformAndShape=True, file=usdFile, frameRange=(15, 20)) stage = Usd.Stage.Open(usdFile) self._ValidateNumSamples(stage, '/world/pCube1', 'points', 1) stitchedPath = os.path.abspath('result.usda') stitchedLayer = Sdf.Layer.CreateNew(stitchedPath) UsdUtils.StitchClips(stitchedLayer, clipFiles, '/world', 1, 20, 'default') # export a non clip version for comparison canonicalUsdFile = os.path.abspath('canonical.usda') cmds.usdExport(mergeTransformAndShape=True, file=canonicalUsdFile, frameRange=(1, 20)) print 'comparing: \nnormal: {}\nstitched: {}'.format(canonicalUsdFile, stitchedPath) canonicalStage = Usd.Stage.Open(canonicalUsdFile) clipsStage = Usd.Stage.Open(stitchedPath) # visible self._ValidateSamples(canonicalStage, clipsStage, '/world/pCube1', 'visibility', (0, 21)) # animated visibility self._ValidateSamples(canonicalStage, clipsStage, '/world/pCube2', 'visibility', (0, 21)) # hidden, non animated: self._ValidateSamples(canonicalStage, clipsStage, '/world/pCube4', 'visibility', (0, 21)) # constant points: self._ValidateSamples(canonicalStage, clipsStage, '/world/pCube2', 'points', (0, 21)) # blend shape driven animated points: self._ValidateSamples(canonicalStage, clipsStage, '/world/pCube3', 'points', (0, 21)) # animated points: self._ValidateSamples(canonicalStage, clipsStage, '/world/pCube1', 'points', (0, 21))
def testSkelTransforms(self): """ Tests that the computed joint transforms in USD, when tarnsformed into world space, match the world space transforms of the Maya joints. """ cmds.file(os.path.abspath('UsdExportSkeleton.ma'), open=True, force=True) # frameRange = [1, 30] frameRange = [1, 3] # TODO: The joint hierarchy intentionally includes non-joint nodes, # which are expected to be ignored. However, when we try to extract # restTransforms from the dagPose, the intermediate transforms cause # problems, since they are not members of the dagPose. As a result, # no dag pose is exported. Need to come up with a way to handle this # correctly in export. print "Expect warnings about invalid restTransforms" usdFile = os.path.abspath('UsdExportSkeleton.usda') cmds.usdExport(mergeTransformAndShape=True, file=usdFile, shadingMode='none', frameRange=frameRange, exportSkels='auto') stage = Usd.Stage.Open(usdFile) root = UsdSkel.Root.Get(stage, '/SkelChar') self.assertTrue(root) skelCache = UsdSkel.Cache() skelCache.Populate(root) skel = UsdSkel.Skeleton.Get(stage, '/SkelChar/Hips') self.assertTrue(skel) skelQuery = skelCache.GetSkelQuery(skel) self.assertTrue(skelQuery) xfCache = UsdGeom.XformCache() for frame in xrange(*frameRange): cmds.currentTime(frame, edit=True) xfCache.SetTime(frame) skelLocalToWorld = xfCache.GetLocalToWorldTransform(skelQuery.GetPrim()) usdJointXforms = skelQuery.ComputeJointSkelTransforms(frame) for joint,usdJointXf in zip(skelQuery.GetJointOrder(), usdJointXforms): usdJointWorldXf = usdJointXf * skelLocalToWorld selList = OM.MSelectionList() selList.add(Sdf.Path(joint).name) dagPath = selList.getDagPath(0) mayaJointWorldXf = Gf.Matrix4d(*dagPath.inclusiveMatrix()) self.assertTrue(Gf.IsClose(mayaJointWorldXf, usdJointWorldXf, 1e-5))
def testExportNoParentScope(self): usdFile = os.path.abspath('UsdExportParentScope_testNoParentScope.usda') cmds.usdExport(mergeTransformAndShape=False, exportInstances=False, shadingMode='none', file=usdFile, frameRange=(1, 1)) stage = Usd.Stage.Open(usdFile) p = UsdGeom.Mesh.Get(stage, '/pSphere1/pSphereShape1') self.assertTrue(p.GetPrim().IsValid())
def _GetUsdStage(self, testName): usdFilePath = os.path.abspath('%s.usda' % testName) cmds.usdExport(mergeTransformAndShape=True, file=usdFilePath, shadingMode='none', exportDisplayColor=True, exportUVs=False) self._stage = Usd.Stage.Open(usdFilePath) self.assertTrue(self._stage)
def setUpClass(cls): standalone.initialize('usd') filepath = os.path.abspath('AssemblyTest.ma') cmds.file(filepath, open=True, force=True) usdFilePath = os.path.abspath('AssemblyTest.usda') cmds.loadPlugin('pxrUsd') cmds.usdExport(mergeTransformAndShape=True, file=usdFilePath, shadingMode='none') cls._stage = Usd.Stage.Open(usdFilePath)
def testSkelWithJointsAtSceneRoot(self): """ Tests that exporting joints at the scene root errors, since joints need to be encapsulated inside a transform or other node that can be converted into a SkelRoot. """ cmds.file(os.path.abspath('UsdExportSkeletonAtSceneRoot.ma'), open=True, force=True) usdFile = os.path.abspath('UsdExportSkeletonAtSceneRoot.usda') with self.assertRaises(RuntimeError): cmds.usdExport(mergeTransformAndShape=True, file=usdFile, shadingMode='none', exportSkels='auto')
def testSkelWithoutBindPose(self): """ Tests export of a Skeleton when a bindPose is not fully setup. """ cmds.file(os.path.abspath('UsdExportSkeletonWithoutBindPose.ma'), open=True, force=True) frameRange = [1, 5] usdFile = os.path.abspath('UsdExportSkeletonWithoutBindPose.usda') cmds.usdExport(mergeTransformAndShape=True, file=usdFile, shadingMode='none', frameRange=frameRange, exportSkels='auto')
def testExportedPrimvars(self): mayaFilePath = os.path.abspath('AlembicChaserPrimvars.ma') cmds.file(mayaFilePath, open=True, force=True) usdFilePath = os.path.abspath('out_primvars.usda') # Export to USD. cmds.usdExport( file=usdFilePath, chaser=['alembic'], chaserArgs=[ ('alembic', 'attrprefix', 'my'), ('alembic', 'primvarprefix', 'my=awesome_'), ]) stage = Usd.Stage.Open(usdFilePath) self.assertTrue(stage) prim = stage.GetPrimAtPath('/AlembicChaserPrimvars/Geom/CubeTypedAttrs') self.assertTrue(prim) attr = prim.GetAttribute('userProperties:IntArrayAttr') self.assertTrue(attr) self.assertEqual(attr.Get(), Vt.IntArray([99, 98, 97, 96, 95, 94, 93, 92, 91, 90])) imageable = UsdGeom.Imageable(prim) self.assertTrue(imageable) primvar = imageable.GetPrimvar('awesome_ConstantIntPrimvar') self.assertTrue(primvar) self.assertEqual(primvar.Get(), 123) self.assertEqual(primvar.GetTypeName(), Sdf.ValueTypeNames.Int) self.assertEqual(primvar.GetInterpolation(), UsdGeom.Tokens.constant) primvar2 = imageable.GetPrimvar('awesome_UniformDoublePrimvar') self.assertTrue(primvar2) self.assertEqual(primvar2.Get(), 3.140) self.assertEqual(primvar2.GetTypeName(), Sdf.ValueTypeNames.Double) self.assertEqual(primvar2.GetInterpolation(), UsdGeom.Tokens.uniform) primvar3 = imageable.GetPrimvar('awesome_FaceVaryingIntPrimvar') self.assertTrue(primvar3) self.assertEqual(primvar3.Get(), 999) self.assertEqual(primvar3.GetTypeName(), Sdf.ValueTypeNames.Int) self.assertEqual(primvar3.GetInterpolation(), UsdGeom.Tokens.faceVarying) primvar4 = imageable.GetPrimvar('awesome_FloatArrayPrimvar') self.assertTrue(primvar4) self.assertEqual(primvar4.Get(), Vt.FloatArray([1.1, 2.2, 3.3, 4.4, 5.5, 6.6, 7.7, 8.8])) self.assertEqual(primvar4.GetTypeName(), Sdf.ValueTypeNames.FloatArray) self.assertEqual(primvar4.GetInterpolation(), UsdGeom.Tokens.vertex)
def testExportInstances(self): usdFile = os.path.abspath('UsdExportParticles_particles.usda') cmds.usdExport(mergeTransformAndShape=False, exportInstances=False, shadingMode='none', file=usdFile, frameRange=(1, 1)) stage = Usd.Stage.Open(usdFile) p = UsdGeom.Points.Get(stage, '/particle1/particleShape1') self.assertTrue(p.GetPrim().IsValid()) self.assertEqual(p.GetPointsAttr().Get(1), Vt.Vec3fArray(5, (Gf.Vec3f(5.0, 0.0, -6.0), Gf.Vec3f(-4.0, 0.0, -4.5), Gf.Vec3f(-4.5, 0.0, 3.0), Gf.Vec3f(-2.0, 0.0, 8.5), Gf.Vec3f(3.0, 0.0, 3.5)))) self.assertEqual(p.GetVelocitiesAttr().Get(1), Vt.Vec3fArray(5, (Gf.Vec3f(0.0, 0.0, 0.0), Gf.Vec3f(1.0, 1.0, 1.0), Gf.Vec3f(2.0, 3.0, 4.0), Gf.Vec3f(5.0, 6.0, 7.0), Gf.Vec3f(8.0, 9.0, 10.0)))) self.assertEqual(p.GetWidthsAttr().Get(1), Vt.FloatArray(5, (2.0, 2.0, 2.0, 2.0, 2.0))) self.assertEqual(p.GetIdsAttr().Get(1), Vt.Int64Array(5, (0, 1, 2, 3, 4)))
def setUpClass(cls): standalone.initialize('usd') cmds.file(os.path.abspath('UserExportedAttributesTest.ma'), open=True, force=True) usdFilePathFormat = 'UserExportedAttributesTest_EXPORTED_%s.usda' mergedUsdFilePath = os.path.abspath(usdFilePathFormat % 'MERGED') unmergedUsdFilePath = os.path.abspath(usdFilePathFormat % 'UNMERGED') cmds.loadPlugin('pxrUsd', quiet=True) cmds.usdExport(file=mergedUsdFilePath, mergeTransformAndShape=True) cmds.usdExport(file=unmergedUsdFilePath, mergeTransformAndShape=False)
def setUpClass(cls): standalone.initialize('usd') mayaFile = os.path.abspath('MarbleCube.ma') cmds.file(mayaFile, open=True, force=True) # Export to USD. usdFilePath = os.path.abspath('MarbleCube.usda') cmds.loadPlugin('pxrUsd') cmds.usdExport(mergeTransformAndShape=True, file=usdFilePath, shadingMode='pxrRis', materialsScopeName='Materials') cls._stage = Usd.Stage.Open(usdFilePath)
def setUpClass(cls): standalone.initialize('usd') cmds.file(os.path.abspath('PxrUsdPreviewSurfaceExportTest.ma'), open=True, force=True) # Export to USD. usdFilePath = os.path.abspath('PxrUsdPreviewSurfaceExportTest.usda') cmds.loadPlugin('pxrUsd') cmds.usdExport(mergeTransformAndShape=True, file=usdFilePath, shadingMode='useRegistry') cls.stage = Usd.Stage.Open(usdFilePath)
def _ExportWithFrameSamplesAndStride( self, frameSamples=[], frameStride=1.0): # Export to USD. usdFilePath = os.path.abspath('UsdExportFrameOffsetTest.usda') cmds.loadPlugin('pxrUsd') cmds.usdExport(mergeTransformAndShape=True, file=usdFilePath, frameRange=(1, 10), frameSample=frameSamples, frameStride=frameStride) stage = Usd.Stage.Open(usdFilePath) self.assertTrue(stage) return stage
def testCurrentFrameVisibilityAsDefault(self): # Makes sure that the current frame's visibility is exported as default. for frame in (1, 2): cmds.currentTime(frame) cmds.usdExport(file=os.path.abspath("out_%d.usda" % frame), exportVisibility=True) out_1 = Usd.Stage.Open('out_1.usda') self.assertEqual(UsdGeom.Imageable.Get(out_1, '/group').ComputeVisibility(), UsdGeom.Tokens.invisible) self.assertEqual(UsdGeom.Imageable.Get(out_1, '/group_inverse').ComputeVisibility(), UsdGeom.Tokens.inherited) out_2 = Usd.Stage.Open('out_2.usda') self.assertEqual(UsdGeom.Imageable.Get(out_2, '/group').ComputeVisibility(), UsdGeom.Tokens.inherited) self.assertEqual(UsdGeom.Imageable.Get(out_2, '/group_inverse').ComputeVisibility(), UsdGeom.Tokens.invisible)