def testMesh_PretearDownEditTargetWrite(self): """ Simple test to determine if the edit target gets written to preteardown """ # force the import stage = self._importStageWithSphere() mc.AL_usdmaya_TranslatePrim(ip="/pSphere1", fi=True, proxy="AL_usdmaya_Proxy") stage.SetEditTarget(stage.GetSessionLayer()) # Delete some faces mc.select("pSphere1.f[0:399]", r=True) mc.select("pSphere1.f[0]", d=True) mc.delete() preSession = stage.GetEditTarget().GetLayer().ExportToString() mc.AL_usdmaya_TranslatePrim(tp="/pSphere1", proxy="AL_usdmaya_Proxy") postSession = stage.GetEditTarget().GetLayer().ExportToString() # Ensure data has been written sessionStage = Usd.Stage.Open(stage.GetEditTarget().GetLayer()) sessionSphere = sessionStage.GetPrimAtPath("/pSphere1") self.assertTrue(sessionSphere.IsValid()) self.assertTrue(sessionSphere.GetAttribute("faceVertexCounts"))
def testNurbsCurve_PretearDownEditTargetWrite(self): """ Simple test to determine if the edit target gets written to preteardown """ # force the import stage = translatortestutils.importStageWithNurbsCircle() mc.AL_usdmaya_TranslatePrim(ip="/nurbsCircle1", fi=True, proxy="AL_usdmaya_Proxy") stage.SetEditTarget(stage.GetSessionLayer()) # Delete a control vertex mc.select("nurbsCircle1.cv[6]", r=True) mc.delete() preSession = stage.GetEditTarget().GetLayer().ExportToString(); mc.AL_usdmaya_TranslatePrim(tp="/nurbsCircle1", proxy="AL_usdmaya_Proxy") postSession = stage.GetEditTarget().GetLayer().ExportToString() # Ensure data has been written sessionStage = Usd.Stage.Open(stage.GetEditTarget().GetLayer()) sessionNurbCircle = sessionStage.GetPrimAtPath("/nurbsCircle1") self.assertTrue(sessionNurbCircle.IsValid()) cvcAttr = sessionNurbCircle.GetAttribute("curveVertexCounts") self.assertTrue(cvcAttr.IsValid()) self.assertEqual(len(cvcAttr.Get()), 1) self.assertEqual(cvcAttr.Get()[0], 10)
def testMeshTranslator_multipleTranslations(self): path = tempfile.NamedTemporaryFile(suffix=".usda", prefix="test_MeshTranslator_multipleTranslations_", delete=True) d = translatortestutils.importStageWithSphere('AL_usdmaya_Proxy') sessionLayer = d.stage.GetSessionLayer() d.stage.SetEditTarget(sessionLayer) spherePrimPath = "/"+d.sphereXformName offsetAmount = Gf.Vec3f(0,0.25,0) vertPoint = '{}.vtx[0]'.format(d.sphereXformName) spherePrimMesh = UsdGeom.Mesh.Get(d.stage, spherePrimPath) # Test import,modify,teardown a bunch of times for i in xrange(3): # Determine expected result expectedPoint = spherePrimMesh.GetPointsAttr().Get()[0] + offsetAmount # Translate the prim into maya for editing mc.AL_usdmaya_TranslatePrim(forceImport=True, importPaths=spherePrimPath, proxy='AL_usdmaya_Proxy') # Move the point items = ['pSphere1.vtx[0]'] mc.move(offsetAmount[0], offsetAmount[1], offsetAmount[2], items, relative=True) # just affect the Y mc.AL_usdmaya_TranslatePrim(teardownPaths=spherePrimPath, proxy='AL_usdmaya_Proxy') actualPoint = spherePrimMesh.GetPointsAttr().Get()[0] # Confirm that the edit has come back as expected self.assertAlmostEqual(actualPoint[0], expectedPoint[0]) self.assertAlmostEqual(actualPoint[1], expectedPoint[1]) self.assertAlmostEqual(actualPoint[2], expectedPoint[2])
def testNurbsCurve_TranslateRoundTrip(self): """ Test that Translating->TearingDown->Translating roundtrip works """ # setup scene with nurbs circle # Create nurbs circle in Maya and export a .usda file mc.CreateNURBSCircle() mc.group( 'nurbsCircle1', name='parent' ) mc.select("parent") tempFile = tempfile.NamedTemporaryFile(suffix=".usda", prefix="test_NurbsCurveTranslator_", delete=True) mc.file(tempFile.name, exportSelected=True, force=True, type="AL usdmaya export") # clear scene mc.file(f=True, new=True) mc.AL_usdmaya_ProxyShapeImport(file=tempFile.name) # force the import mc.AL_usdmaya_TranslatePrim(ip="/parent/nurbsCircle1", fi=True, proxy="AL_usdmaya_Proxy") self.assertEqual(len(mc.ls('nurbsCircle1')), 1) self.assertEqual(len(mc.ls(type='nurbsCurve')), 1) self.assertEqual(len(mc.ls('parent')), 1) # force the teardown mc.AL_usdmaya_TranslatePrim(tp="/parent/nurbsCircle1", fi=True, proxy="AL_usdmaya_Proxy") self.assertEqual(len(mc.ls('nurbsCircle1')), 0) self.assertEqual(len(mc.ls(type='nurbsCurve')), 0) self.assertEqual(len(mc.ls('parent')), 0) # force the import mc.AL_usdmaya_TranslatePrim(ip="/parent/nurbsCircle1", fi=True, proxy="AL_usdmaya_Proxy") self.assertEqual(len(mc.ls('nurbsCircle1')), 1) self.assertEqual(len(mc.ls(type='nurbsCurve')), 1) self.assertEqual(len(mc.ls('parent')), 1)
def testMeshTranslator_variantswitch(self): mc.AL_usdmaya_ProxyShapeImport(file='./testMeshVariants.usda') self.assertTrue(Tf.Type.Unknown != Tf.Type.FindByName( 'AL::usdmaya::fileio::translators::Mesh')) # test initial state has no meshes self.assertEqual(len(mc.ls(type='mesh')), 0) stage = self._getStage() stage.SetEditTarget(stage.GetSessionLayer()) variantPrim = stage.GetPrimAtPath("/TestVariantSwitch") variantSet = variantPrim.GetVariantSet("MeshVariants") # the MeshA should now be in the scene variantSet.SetVariantSelection("ShowMeshA") mc.AL_usdmaya_TranslatePrim( ip="/TestVariantSwitch/MeshA", fi=True, proxy="AL_usdmaya_Proxy") # force the import self.assertEqual(len(mc.ls('MeshA')), 1) self.assertEqual(len(mc.ls('MeshB')), 0) self.assertEqual(len(mc.ls(type='mesh')), 1) ####### # the MeshB should now be in the scene variantSet.SetVariantSelection("ShowMeshB") #print stage.ExportToString() mc.AL_usdmaya_TranslatePrim( ip="/TestVariantSwitch/MeshB", fi=True, proxy="AL_usdmaya_Proxy") # force the import self.assertEqual(len(mc.ls('MeshA')), 0) self.assertEqual(len(mc.ls('MeshB')), 1) self.assertEqual(len(mc.ls(type='mesh')), 1) # the MeshA and MeshB should be in the scene variantSet.SetVariantSelection("ShowMeshAnB") mc.AL_usdmaya_TranslatePrim(ip="/TestVariantSwitch/MeshB", fi=True, proxy="AL_usdmaya_Proxy") mc.AL_usdmaya_TranslatePrim(ip="/TestVariantSwitch/MeshA", fi=True, proxy="AL_usdmaya_Proxy") self.assertEqual(len(mc.ls('MeshA')), 1) self.assertEqual(len(mc.ls('MeshB')), 1) self.assertEqual(len(mc.ls(type='mesh')), 2) # switch variant to empty variantSet.SetVariantSelection("") self.assertEqual(len(mc.ls(type='mesh')), 0)
def test_import_and_update_consistency(self): ''' test consistency when called via TranslatePrim, or triggered via onObjectsChanged ''' updateableTranslator = UpdateableTranslator() usdmaya.TranslatorBase.registerTranslator(updateableTranslator, 'test') stage = Usd.Stage.Open(self._testDataDir + "translator_update_postimport.usda") stageCache = UsdUtils.StageCache.Get() stageCache.Insert(stage) stageId = stageCache.GetId(stage) shapeName = 'updateProxyShape' cmds.AL_usdmaya_ProxyShapeImport(stageId=stageId.ToLongInt(), name=shapeName) # Verify if the methods have been called self.assertTrue( "import /root/peter01/rig" in updateableTranslator.actions) self.assertTrue( "postImport /root/peter01/rig" in updateableTranslator.actions) # "update()" method should not be called self.assertFalse( "update /root/peter01/rig" in updateableTranslator.actions) updateableTranslator.actions = [] cmds.AL_usdmaya_TranslatePrim(up="/root/peter01/rig", fi=True, proxy=shapeName) # "update()" should have been called self.assertTrue( "update /root/peter01/rig" in updateableTranslator.actions)
def testNurbsCurve_testTranslateOn(self): """ Test that by default that the the mesh is imported """ # setup scene with sphere translatortestutils.importStageWithNurbsCircle() # force the import mc.AL_usdmaya_TranslatePrim(ip="/nurbsCircle1", fi=True, proxy="AL_usdmaya_Proxy") self.assertEqual(len(mc.ls('nurbsCircle1')), 1) self.assertEqual(len(mc.ls(type='nurbsCurve')), 1)
def testMesh_testTranslateOn(self): """ Test that by default that the the mesh is imported """ # setup scene with sphere translatortestutils.importStageWithSphere() # force the import mc.AL_usdmaya_TranslatePrim(ip="/pSphere1", fi=True, proxy="AL_usdmaya_Proxy") self.assertTrue(len(mc.ls('pSphere1'))) self.assertEqual(len(mc.ls(type='mesh')), 1)
def __init__(self, proxyShapeName, parentPrims, onlyTranslateVisible=True, isAnimated=True, doPostTranslation=True): primsToTranslate = [] for prim in parentPrims: primsToTranslate.extend( self.getPrimsToTranslate(prim, onlyTranslateVisible)) if not primsToTranslate: logger.error('Failed to find any prims to translate to maya') return for prim in primsToTranslate: primPath = prim.GetPrimPath().pathString cmds.AL_usdmaya_TranslatePrim(ip=primPath, fi=True, proxy=proxyShapeName) # Selecting the mesh and applying static or animated mesh import is a temporary work around, # this will eventually be moved into the AL_usdmaya_TranslatePrim command as an argument if doPostTranslation: self.createMayaNodes(proxyShapeName, primPath, isAnimated)