Ejemplo n.º 1
0
    def setUp(self):
        """A few steps take place here:
        1. New scene in Maya, ensure plugin is loaded
        2. Create a polySphere and polyCube, export these using to separate Usd stages
        3. Import both stages together into a new Maya scene
        """

        cmds.file(force=True, new=True)
        cmds.loadPlugin("AL_USDMayaPlugin", quiet=True)
        self.assertTrue(
            cmds.pluginInfo("AL_USDMayaPlugin", query=True, loaded=True))

        stageA_file = tempfile.NamedTemporaryFile(delete=True, suffix=".usda")
        stageB_file = tempfile.NamedTemporaryFile(delete=True, suffix=".usda")
        stageA_file.close()
        stageB_file.close()

        cube = cmds.polyCube(constructionHistory=False, name="cube")[0]
        sphere = cmds.polySphere(constructionHistory=False, name="cube")[0]

        cmds.select(cube, replace=True)
        cmds.file(stageA_file.name,
                  exportSelected=True,
                  force=True,
                  type="AL usdmaya export")

        cmds.select(sphere, replace=True)
        cmds.file(stageB_file.name,
                  exportSelected=True,
                  force=True,
                  type="AL usdmaya export")

        self._stageA.poly = cube
        self._stageB.poly = sphere

        cmds.file(force=True, new=True)

        self._stageA.proxyName = cmds.AL_usdmaya_ProxyShapeImport(
            file=stageA_file.name)[0]
        self._stageB.proxyName = cmds.AL_usdmaya_ProxyShapeImport(
            file=stageB_file.name)[0]

        self._stageA.proxy = AL.usdmaya.ProxyShape.getByName(
            self._stageA.proxyName)
        self._stageB.proxy = AL.usdmaya.ProxyShape.getByName(
            self._stageB.proxyName)

        self._stageA.stage = self._stageA.proxy.getUsdStage()
        self._stageB.stage = self._stageB.proxy.getUsdStage()

        self._stageA.prim = self._stageA.stage.GetPrimAtPath("/{}".format(
            self._stageA.poly))
        self._stageB.prim = self._stageB.stage.GetPrimAtPath("/{}".format(
            self._stageB.poly))

        os.remove(stageA_file.name)
        os.remove(stageB_file.name)
Ejemplo n.º 2
0
    def testDirectionalLight_TranslateRoundTrip(self):
        # setup scene with directional light

        # Create directional light in Maya and export a .usda file
        mel.eval('defaultDirectionalLight(3, 1,1,0, "0", 0,0,0, 0)')
        mc.setAttr('directionalLightShape1.lightAngle', 0.25)
        mc.setAttr('directionalLightShape1.pw', 6, 7, 8)
        tempFile = tempfile.NamedTemporaryFile(
            suffix=".usda",
            prefix="test_DirectionalLightTranslator_",
            delete=False)
        tempFile.close()

        mc.AL_usdmaya_ExportCommand(file=tempFile.name)

        # clear scene
        mc.file(f=True, new=True)

        # import file back
        mc.AL_usdmaya_ProxyShapeImport(file=tempFile.name)
        self.assertEqual(0.25, mc.getAttr('directionalLightShape1.lightAngle'))
        self.assertEqual((1.0, 1.0, 0),
                         mc.getAttr('directionalLightShape1.color')[0])
        self.assertEqual(3, mc.getAttr('directionalLightShape1.intensity'))
        self.assertEqual((6.0, 7.0, 8.0),
                         mc.getAttr('directionalLightShape1.pointWorld')[0])

        os.remove(tempFile.name)
Ejemplo n.º 3
0
    def setUp(self):
        self.assertTrue(
            cmds.pluginInfo("AL_USDMayaPlugin", query=True, loaded=True))

        # Clear the maya file
        cmds.file(self._mayaFilePath, force=True, new=True)

        # Ensure sphere geometry exists
        self._sphere = cmds.polySphere(constructionHistory=False,
                                       name="sphere")[0]
        cmds.select(self._sphere)

        # Export, new scene, import
        cmds.file(self._usdFilePath,
                  exportSelected=True,
                  force=True,
                  type="AL usdmaya export")
        cmds.file(force=True, new=True)
        self._proxyName = cmds.AL_usdmaya_ProxyShapeImport(
            file=self._usdFilePath)[0]

        # Ensure proxy exists
        self.assertIsNotNone(self._proxyName)

        # Store stage
        proxy = ProxyShape.getByName(self._proxyName)
        self._stage = proxy.getUsdStage()
Ejemplo n.º 4
0
    def setUp(self):
        unittest.TestCase.setUp(self)
        self.workingDir = os.path.abspath(type(self).__name__)
        os.mkdir(self.workingDir)
        cmds.file(new=True, save=False, force=True)
        cmds.loadPlugin("AL_USDMayaPlugin", quiet=True)
        self.assertTrue(
            cmds.pluginInfo("AL_USDMayaPlugin", query=True, loaded=True))

        with pxr.Usd.StageCacheContext(self.SC):
            stage = pxr.Usd.Stage.CreateInMemory()
            with pxr.Usd.EditContext(stage,
                                     pxr.Usd.EditTarget(stage.GetRootLayer())):
                pxr.UsdGeom.Xform.Define(
                    stage, '/root/GEO/sphere_hrc').AddTranslateOp().Set(
                        (0.0, 1.0, 0.0))
                pxr.UsdGeom.Sphere.Define(
                    stage,
                    '/root/GEO/sphere_hrc/sphere').GetRadiusAttr().Set(5.0)

        cmds.AL_usdmaya_ProxyShapeImport(
            stageId=self.SC.GetId(stage).ToLongInt(), name='anonymousShape')
        cmds.file(rename=self.serialisationPath())
        cmds.file(type='mayaAscii')
        cmds.file(save=True)
        cmds.file(new=True, save=False, force=True)
        self.SC.Clear()
Ejemplo n.º 5
0
    def setUp(self):
        """Export some sphere geometry as .usda, and import into a new Maya scene."""

        cmds.file(force=True, new=True)
        cmds.loadPlugin("AL_USDMayaPlugin", quiet=True)
        self.assertTrue(
            cmds.pluginInfo("AL_USDMayaPlugin", query=True, loaded=True))

        with tempfile.NamedTemporaryFile(delete=False,
                                         suffix=".usda") as _tmpfile:
            self._usdaFile = _tmpfile.name
            # Ensure sphere geometry exists
            self._sphere = cmds.polySphere(constructionHistory=False,
                                           name="sphere")[0]
            cmds.select(self._sphere)

            # Export, new scene, import
            cmds.file(self._usdaFile,
                      exportSelected=True,
                      force=True,
                      type="AL usdmaya export")
            cmds.file(force=True, new=True)
            self._proxyName = cmds.AL_usdmaya_ProxyShapeImport(
                file=self._usdaFile)[0]

        # Ensure proxy exists
        self.assertIsNotNone(self._proxyName)

        # Store stage
        proxy = ProxyShape.getByName(self._proxyName)
        self._stage = proxy.getUsdStage()
Ejemplo n.º 6
0
    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)
Ejemplo n.º 7
0
def importStageWithSphere(proxyShapeName='AL_usdmaya_Proxy'):
    """
    Creates a USD scene containing a single sphere.
    """

    # Create sphere in Maya and export a .usda file
    sphereXformName, sphereShapeName = mc.polySphere()
    mc.select(sphereXformName)
    tempFile = tempfile.NamedTemporaryFile(suffix=".usda",
                                           prefix="test_MeshTranslator_",
                                           delete=False)
    tempFile.close()
    mc.file(tempFile.name,
            exportSelected=True,
            force=True,
            type="AL usdmaya export")
    dir(tempFile)
    print("tempFile ", tempFile.name)

    # clear scene
    mc.file(f=True, new=True)
    mc.AL_usdmaya_ProxyShapeImport(file=tempFile.name, name=proxyShapeName)

    data = SceneWithSphere()
    data.stage = getStage()
    data.sphereXformName = sphereXformName
    data.sphereShapeName = sphereShapeName
    return data
Ejemplo n.º 8
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)
Ejemplo n.º 9
0
    def _importStageWithSphere(self):
        """
        Creates Scene

        #usda1.0
        def Mesh "pSphere1"()
        {
        }
        """

        # Create sphere in Maya and export a .usda file
        mc.polySphere()
        mc.select("pSphere1")
        tempFile = tempfile.NamedTemporaryFile(suffix=".usda",
                                               prefix="test_MeshTranslator_",
                                               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)
        return self._getStage()
Ejemplo n.º 10
0
    def testMayaReference_TranslatorImport(self):
        """
        Test that the Maya Reference Translator imports correctly
        """

        mc.AL_usdmaya_ProxyShapeImport(file='./testMayaRef.usda')
        self.assertTrue(len(mc.ls('cube:pCube1')))
Ejemplo n.º 11
0
    def test_set_inactive_prim_removes_parent_transform(self):
        usdmaya.TranslatorBase.registerTranslator(CubeGenerator(), 'beast_rig')

        stage = Usd.Stage.Open("../test_data/inactivetest.usda")
        prim = stage.GetPrimAtPath('/root/peter01')
        vs = prim.GetVariantSet("cubes")
        vs.SetVariantSelection("fiveCubes")

        stageCache = UsdUtils.StageCache.Get()
        stageCache.Insert(stage)
        stageId = stageCache.GetId(stage)

        cmds.AL_usdmaya_ProxyShapeImport(stageId=stageId.ToLongInt(), name='bobo')

        self.assertEqual(CubeGenerator.getState()["importObjectCount"],1)
        self.assertEqual(len(CubeGenerator.importObjectMObjects),5)
        self.assertTrue(cmds.objExists('|bobo|root|peter01|rig'))

        p = stage.GetPrimAtPath('/root/peter01/rig')
        p.SetActive(False)

        self.assertEqual(CubeGenerator.getState()["tearDownCount"],1)
        self.assertEqual(CubeGenerator.getState()["importObjectCount"],1)
        self.assertEqual(CubeGenerator.getState()["updateCount"],0)

        self.assertFalse(cmds.objExists('|bobo|root|peter01|rig'))
Ejemplo n.º 12
0
    def recordRefLoad(refNodeMobj, mFileObject, clientData):
        '''Record when a reference path is loading.'''
        path = mFileObject.resolvedFullName()
        count = loadHistory.setdefault(path, 0)
        loadHistory[path] = count + 1

        id = om.MSceneMessage.addReferenceCallback(
            om.MSceneMessage.kBeforeLoadReference, recordRefLoad)

        mc.file(new=1, f=1)
        proxyName = mc.AL_usdmaya_ProxyShapeImport(
            file='./testMayaRefLoading.usda')[0]
        proxy = AL.usdmaya.ProxyShape.getByName(proxyName)
        refPath = os.path.abspath('./cube.ma')
        stage = AL.usdmaya.StageCache.Get().GetAllStages()[0]
        topPrim = stage.GetPrimAtPath('/world/optionalCube')
        loadVariantSet = topPrim.GetVariantSet('state')

        self.assertEqual(loadHistory[refPath], 2)  # one for each copy of ref

        proxy.resync('/')
        self.assertEqual(
            loadHistory[refPath],
            2)  # refs should not have reloaded since nothing has changed.

        # now change the variant, so a third ALMayaReference should load
        loadVariantSet.SetVariantSelection('loaded')
        self.assertEqual(loadHistory[refPath],
                         3)  # only the new ref should load.

        loadVariantSet.SetVariantSelection('unloaded')
        self.assertEqual(loadHistory[refPath],
                         3)  # ref should unload, but nothing else should load.

        om.MMessage.removeCallback(id)
Ejemplo n.º 13
0
    def test_variantSwitch_that_removes_prim_runs_teardown(self):

        usdmaya.TranslatorBase.registerTranslator(CubeGenerator(), 'beast_rig')

        stage = Usd.Stage.Open("../test_data/inactivetest.usda")
        prim = stage.GetPrimAtPath('/root/peter01')
        vs = prim.GetVariantSet("cubes")
        vs.SetVariantSelection("fiveCubes")

        stageCache = UsdUtils.StageCache.Get()
        stageCache.Insert(stage)
        stageId = stageCache.GetId(stage)

        cmds.AL_usdmaya_ProxyShapeImport(stageId=stageId.ToLongInt(), name='bobo')
        self.assertEqual(CubeGenerator.getState()["importObjectCount"],1)
        self.assertTrue(cmds.objExists('|bobo|root|peter01|rig'))

        '''
        Test that we can swap in another empty variant and our content gets deleted
        '''
        vs.SetVariantSelection("noCubes")

        self.assertEqual(CubeGenerator.getState()["tearDownCount"], 1)
        self.assertEqual(CubeGenerator.getState()["importObjectCount"], 1)
        self.assertFalse(cmds.objExists('|bobo|root|peter01|rig'))
Ejemplo n.º 14
0
    def test_variantSwitch_that_removes_prim_and_create_new_one(self):

        usdmaya.TranslatorBase.registerTranslator(CubeGenerator(), 'beast_rig')

        stage = Usd.Stage.Open("../test_data/inactivetest.usda")
        prim = stage.GetPrimAtPath('/root/peter01')
        vs = prim.GetVariantSet("cubes")
        vs.SetVariantSelection("fiveCubes")

        stageCache = UsdUtils.StageCache.Get()
        stageCache.Insert(stage)
        stageId = stageCache.GetId(stage)

        cmds.AL_usdmaya_ProxyShapeImport(stageId=stageId.ToLongInt(), name='bobo')
        self.assertEqual(CubeGenerator.getState()["importObjectCount"],1)
        self.assertEqual(len(CubeGenerator.importObjectMObjects),5)
        self.assertTrue(cmds.objExists('|bobo|root|peter01|rig'))

        '''
        Variant switch that leads to another prim being created.
        '''
        vs.SetVariantSelection("sixCubesRig2")

        self.assertEqual(CubeGenerator.getState()["tearDownCount"],1)
        self.assertEqual(CubeGenerator.getState()["importObjectCount"],2)
        self.assertEqual(CubeGenerator.getState()["updateCount"],0)
        self.assertEqual(len(CubeGenerator.importObjectMObjects),6)
        self.assertFalse(cmds.objExists('|bobo|root|peter01|rig'))
        self.assertTrue(cmds.objExists('|bobo|root|peter01|rig2'))
Ejemplo n.º 15
0
 def testFrameRange_NoImpactIfNoFrameRange(self):
     currentFrameOld = mc.currentTime(q=True)
     
     startAnimFrameOld = mc.playbackOptions(q=True, animationStartTime=True)        
     endAnimFrameOld = mc.playbackOptions(q=True, animationEndTime=True)
     
     startVisibleFrameOld = mc.playbackOptions(q=True, minTime=True)
     endVisibleFrameOld = mc.playbackOptions(q=True, maxTime=True)
     
     # If frame range data is authored neither in ALFrameRange prim nor usdStage, no range action should be taken:
     mc.AL_usdmaya_ProxyShapeImport(file='./testFrameRangeNoImpact.usda')
     self.assertTrue(Tf.Type.Unknown != Tf.Type.FindByName('AL::usdmaya::fileio::translators::FrameRange'))
     
     currentFrame = mc.currentTime(q=True)
     
     startAnimFrame = mc.playbackOptions(q=True, animationStartTime=True)
     endAnimFrame = mc.playbackOptions(q=True, animationEndTime=True)
     
     startVisibleFrame = mc.playbackOptions(q=True, minTime=True)
     endVisibleFrame = mc.playbackOptions(q=True, maxTime=True)
     
     self.assertEqual(currentFrame, currentFrameOld)
     
     self.assertEqual(startAnimFrame, startAnimFrameOld)
     self.assertEqual(endAnimFrame, endAnimFrameOld)
     
     self.assertEqual(startVisibleFrame, startVisibleFrameOld)
     self.assertEqual(endVisibleFrame, endVisibleFrameOld)
Ejemplo n.º 16
0
    def testMayaReference_RefKeepsRefEdits(self):
        '''Tests that, even if the MayaReference is swapped for a pure-usda representation, refedits are preserved'''
        import AL.usdmaya

        mc.file(new=1, f=1)
        mc.AL_usdmaya_ProxyShapeImport(file='./testMayaRefUnloadable.usda')
        stage = AL.usdmaya.StageCache.Get().GetAllStages()[0]
        topPrim = stage.GetPrimAtPath('/usd_top')
        mayaLoadingStyle = topPrim.GetVariantSet('mayaLoadingStyle')
Ejemplo n.º 17
0
 def _performDisablePrimTest(self, usdFilePath):
     shapes = mc.AL_usdmaya_ProxyShapeImport(file=usdFilePath)
     self.assertTrue(Tf.Type.Unknown != Tf.Type.FindByName('AL::usdmaya::fileio::translators::FrameRange'))
     
     shotPrimMayaNodeName = 'shot_name'
     self.assertTrue(mc.objExists(shotPrimMayaNodeName))
     configPrimPath = '/shot_name/config'
     cmds.AL_usdmaya_ActivatePrim(shapes[0], pp=configPrimPath, a=False)
     
     # Assert not clearing:
     self.assertTrue(mc.objExists(shotPrimMayaNodeName))
Ejemplo n.º 18
0
def importStageWithNurbsCircle():
    # Create nurbs circle in Maya and export a .usda file
    mc.CreateNURBSCircle()
    mc.select("nurbsCircle1")
    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)
    return getStage()
Ejemplo n.º 19
0
 def testDirectionalLight_PluginIsFunctional(self):
     mc.AL_usdmaya_ProxyShapeImport(file='./testDirectionalLight.usda')
     self.assertTrue(Tf.Type.Unknown != Tf.Type.FindByName(
         'AL::usdmaya::fileio::translators::DirectionalLight'))
     self.assertEqual(len(mc.ls('directionalLightShape1')), 1)
     self.assertEqual(len(mc.ls(type='directionalLight')), 1)
     self.assertEqual(
         'alight',
         mc.listRelatives(mc.listRelatives(
             mc.ls('directionalLightShape1')[0], parent=1)[0],
                          parent=1)[0])
Ejemplo n.º 20
0
 def testMayaReference_PluginIsFunctional(self):
     mc.AL_usdmaya_ProxyShapeImport(file='./testMayaRef.usda')
     self.assertTrue(Tf.Type.Unknown != Tf.Type.FindByName('AL::usdmaya::fileio::translators::MayaReference'))
     self.assertEqual(1, len(mc.ls('cube:pCube1')))
     self.assertEqual('mayaRefPrim', mc.listRelatives('cube:pCube1', parent=1)[0])
     self.assertEqual((0.0, 0.0, 0.0), cmds.getAttr('mayaRefPrim.translate')[0])
     self.assertFalse(mc.getAttr('mayaRefPrim.translate', lock=1))
     self.assertEqual(1, len(mc.ls('otherNS:pCube1')))
     self.assertEqual('otherCube', mc.listRelatives('otherNS:pCube1', parent=1)[0])
     self.assertEqual((3.0, 2.0, 1.0), cmds.getAttr('otherCube.translate')[0])
     self.assertFalse(mc.getAttr('otherCube.translate', lock=1))
Ejemplo n.º 21
0
    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)
Ejemplo n.º 22
0
    def testMayaReference_RefKeepsRefEdits(self):
        '''Tests that, even if the MayaReference is swapped for a pure-usda representation, refedits are preserved'''
        import AL.usdmaya

        mc.file(new=1, f=1)
        mc.AL_usdmaya_ProxyShapeImport(file='./testMayaRefUnloadable.usda')
        stage = AL.usdmaya.StageCache.Get().GetAllStages()[0]
        topPrim = stage.GetPrimAtPath('/usd_top')
        mayaLoadingStyle = topPrim.GetVariantSet('mayaLoadingStyle')

        def assertUsingMayaReferenceVariant():
            self.assertEqual(1, len(mc.ls('cubeNS:pCube1')))
            self.assertFalse(
                stage.GetPrimAtPath('/usd_top/pCube1_usd').IsValid())
            self.assertEqual('mayaReference',
                             mayaLoadingStyle.GetVariantSelection())

        def assertUsingUsdVariant():
            self.assertEqual(0, len(mc.ls('cubeNS:pCube1')))
            self.assertTrue(
                stage.GetPrimAtPath('/usd_top/pCube1_usd').IsValid())
            self.assertEqual('usd', mayaLoadingStyle.GetVariantSelection())

        # by default, variant should be set so that it's a maya reference
        assertUsingMayaReferenceVariant()

        # check that, by default, the cube is at 1,2,3
        self.assertEqual(
            mc.getAttr('cubeNS:pCube1.translate')[0], (1.0, 2.0, 3.0))
        # now make a ref edit
        mc.setAttr('cubeNS:pCube1.translate', 4.0, 5.0, 6.0)
        self.assertEqual(
            mc.getAttr('cubeNS:pCube1.translate')[0], (4.0, 5.0, 6.0))

        # now change the variant, so the ALMayaReference isn't part of the stage anymore
        mayaLoadingStyle.SetVariantSelection('usd')
        # confirm that worked
        assertUsingUsdVariant()

        # now switch back...
        mayaLoadingStyle.SetVariantSelection('mayaReference')
        assertUsingMayaReferenceVariant()
        # ...and then make sure that our ref edit was preserved
        self.assertEqual(
            mc.getAttr('cubeNS:pCube1.translate')[0], (4.0, 5.0, 6.0))
Ejemplo n.º 23
0
 def testMesh_TranslateOff(self):
     """
     Test that by default that the the mesh isn't imported
     """
    
     # Create sphere in Maya and export a .usda file
     mc.polySphere()
     mc.select("pSphere1")
     tempFile = tempfile.NamedTemporaryFile(suffix=".usda", prefix="test_MeshTranslator_", 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)
     self.assertTrue(Tf.Type.Unknown != Tf.Type.FindByName('AL::usdmaya::fileio::translators::Mesh'))
     self.assertEqual(len(mc.ls('pSphere1')), 0)
     self.assertEqual(len(mc.ls(type='mesh')), 0)
Ejemplo n.º 24
0
    def test_import(self):

        usdmaya.TranslatorBase.registerTranslator(CubeGenerator(), 'beast_rig')

        stage = Usd.Stage.Open("../test_data/inactivetest.usda")
        prim = stage.GetPrimAtPath('/root/peter01')
        vs = prim.GetVariantSet("cubes")
        vs.SetVariantSelection("fiveCubes")

        stageCache = UsdUtils.StageCache.Get()
        stageCache.Insert(stage)
        stageId = stageCache.GetId(stage)

        cmds.AL_usdmaya_ProxyShapeImport(stageId=stageId.ToLongInt(), name='bobo')
        self.assertTrue(CubeGenerator.getState()["importObjectCount"]==1)
        self.assertTrue(len(CubeGenerator.importObjectMObjects)==5)

        prim = stage.GetPrimAtPath('/root/peter01/rig')
Ejemplo n.º 25
0
    def test_variantSwitch_listener_from_different_stage(self):
        """Test listener only responds to changes made to layers found in proxy shape owned stages."""

        usdmaya.TranslatorBase.registerTranslator(CubeGenerator(), 'beast_rig')

        # Make a dummy stage that mimics prim path found in test data
        otherHandle = tempfile.NamedTemporaryFile(delete=True, suffix=".usda")
        otherHandle.close()

        # Scope
        if True:
            stage = Usd.Stage.CreateInMemory()
            stage.DefinePrim("/root/peter01")
            stage.Export(otherHandle.name)

        # Open both stages
        testStage = Usd.Stage.Open("../test_data/inactivetest.usda")
        otherStage = Usd.Stage.Open(otherHandle.name)

        # Cache
        stageCache = UsdUtils.StageCache.Get()
        stageCache.Insert(testStage)
        stageCache.Insert(otherStage)
        stageId = stageCache.GetId(testStage)

        # Import legit test data
        cmds.AL_usdmaya_ProxyShapeImport(stageId=stageId.ToLongInt(),
                                         name='bobo')

        # Make sure both paths are valid
        self.assertTrue(testStage.GetPrimAtPath("/root/peter01"))
        self.assertTrue(otherStage.GetPrimAtPath("/root/peter01"))

        # Modify stage that isn't loaded by AL_USDMaya
        prim = otherStage.GetPrimAtPath("/root/peter01")
        prim.SetActive(False)

        # Ensure stage on proxy wasn't modified
        self.assertEqual(CubeGenerator.getState()["tearDownCount"], 0)

        # Cleanup
        os.remove(otherHandle.name)
Ejemplo n.º 26
0
    def test_deletion_of_parent_node_by_translator_does_not_crash_Maya(self):
        usdmaya.TranslatorBase.registerTranslator(DeleteParentNodeOnPostImport(), 'beast_rig')

        stage = Usd.Stage.Open("../test_data/inactivetest.usda")
        prim = stage.GetPrimAtPath('/root/peter01')
        vs = prim.GetVariantSet("cubes")
        vs.SetVariantSelection("fiveCubes")

        stageCache = UsdUtils.StageCache.Get()
        stageCache.Insert(stage)
        stageId = stageCache.GetId(stage)

        cmds.AL_usdmaya_ProxyShapeImport(stageId=stageId.ToLongInt(), name='bobo')

        self.assertEqual(DeleteParentNodeOnPostImport.nbImport, 1)
        self.assertEqual(DeleteParentNodeOnPostImport.parentNode, '|bobo|root|peter01|rig')
        self.assertEqual(DeleteParentNodeOnPostImport.nbPostImport, 1)
        self.assertEqual(DeleteParentNodeOnPostImport.nbPreTeardown, 0)

        vs.SetVariantSelection("noCubes")
Ejemplo n.º 27
0
    def _prepSessionLayer(self, customVariantFallbacks):
        defaultGlobalVariantFallbacks = pxr.Usd.Stage.GetGlobalVariantFallbacks(
        )
        pxr.Usd.Stage.SetGlobalVariantFallbacks(customVariantFallbacks)
        usdFile = '../test_data/variant_fallbacks.usda'

        stage = pxr.Usd.Stage.Open(usdFile)
        stageCacheId = pxr.UsdUtils.StageCache.Get().Insert(stage)
        sessionLayer = stage.GetSessionLayer()
        sessionLayer.customLayerData = {
            'variant_fallbacks': json.dumps(customVariantFallbacks)
        }
        # restore default
        pxr.Usd.Stage.SetGlobalVariantFallbacks(defaultGlobalVariantFallbacks)

        # create the proxy node with stage cache id
        proxyName = cmds.AL_usdmaya_ProxyShapeImport(
            stageId=stageCacheId.ToLongInt())[0]
        proxyShape = AL.usdmaya.ProxyShape.getByName(proxyName)
        return proxyShape, proxyName
Ejemplo n.º 28
0
    def testMayaReference_PluginIsFunctional(self):
        mc.AL_usdmaya_ProxyShapeImport(file='./testMayaRef.usda')
        self.assertTrue(Tf.Type.Unknown != Tf.Type.FindByName(
            'AL::usdmaya::fileio::translators::MayaReference'))
        self.assertEqual(1, len(mc.ls('cube:pCube1')))
        self.assertEqual('mayaRefPrim',
                         mc.listRelatives('cube:pCube1', parent=1)[0])
        self.assertEqual((0.0, 0.0, 0.0),
                         mc.getAttr('mayaRefPrim.translate')[0])
        self.assertFalse(mc.getAttr('mayaRefPrim.translate', lock=1))
        self.assertEqual(1, len(mc.ls('otherNS:pCube1')))
        self.assertEqual('otherCube',
                         mc.listRelatives('otherNS:pCube1', parent=1)[0])
        self.assertEqual((3.0, 2.0, 1.0), mc.getAttr('otherCube.translate')[0])
        self.assertFalse(mc.getAttr('otherCube.translate', lock=1))

        # Fallback namespace for prim without an explicit namespace
        expectedNamespace = 'test_cubeWithDefaultNamespace'
        self.assertTrue(mc.namespace(exists=expectedNamespace))
        self.assertEqual(1, len(mc.ls('%s:pCube1' % expectedNamespace)))
Ejemplo n.º 29
0
 def testFrameRange_PluginIsFunctional(self):
     mc.AL_usdmaya_ProxyShapeImport(file='./testFrameRange.usda')
     self.assertTrue(Tf.Type.Unknown != Tf.Type.FindByName('AL::usdmaya::fileio::translators::FrameRange'))
     
     currentFrame = mc.currentTime(q=True)
     
     startAnimFrame = mc.playbackOptions(q=True, animationStartTime=True)
     endAnimFrame = mc.playbackOptions(q=True, animationEndTime=True)
     
     startVisibleFrame = mc.playbackOptions(q=True, minTime=True)
     endVisibleFrame = mc.playbackOptions(q=True, maxTime=True)
     
     
     self.assertEqual(currentFrame, 1100)
     
     self.assertEqual(startAnimFrame, 1072)
     self.assertEqual(endAnimFrame, 1290)
     
     self.assertEqual(startVisibleFrame, 1080)
     self.assertEqual(endVisibleFrame, 1200)
Ejemplo n.º 30
0
 def testFrameRange_FallbackIsFunctional(self):
     # If no frame range data is authored in ALFrameRange prim, we use startTimeCode & endTimeCode from usdStage:
     mc.AL_usdmaya_ProxyShapeImport(file='./testFrameRangeFallback.usda')
     self.assertTrue(Tf.Type.Unknown != Tf.Type.FindByName('AL::usdmaya::fileio::translators::FrameRange'))
     
     currentFrame = mc.currentTime(q=True)
     
     startAnimFrame = mc.playbackOptions(q=True, animationStartTime=True)
     endAnimFrame = mc.playbackOptions(q=True, animationEndTime=True)
     
     startVisibleFrame = mc.playbackOptions(q=True, minTime=True)
     endVisibleFrame = mc.playbackOptions(q=True, maxTime=True)
     
     self.assertEqual(currentFrame, 1072)
     
     self.assertEqual(startAnimFrame, 1072)
     self.assertEqual(endAnimFrame, 1290)
     
     self.assertEqual(startVisibleFrame, 1072)
     self.assertEqual(endVisibleFrame, 1290)