Esempio n. 1
0
    def testCacheIdInStageData(self):
        # Create the 2 Proxy nodes and load a stage from file
        shapeNodeA = cmds.createNode('mayaUsdProxyShape')
        cmds.setAttr('{}.filePath'.format(shapeNodeA),
                     self.usdfilePath,
                     type='string')
        shapeStageA = mayaUsdLib.GetPrim(shapeNodeA).GetStage()
        shapeNodeB = cmds.createNode('mayaUsdProxyShape')

        #Connect them
        cmds.connectAttr('{}.outStageData'.format(shapeNodeA),
                         '{}.inStageData'.format(shapeNodeB))

        shapeStageB = mayaUsdLib.GetPrim(shapeNodeA).GetStage()

        # Check they are the same
        self.assertEqual(shapeStageA, shapeStageB)

        # Get the cache ID and load the stage from the cache
        cacheIdValue = cmds.getAttr('{}.outStageCacheId'.format(shapeNodeB))
        cacheId = pxr.Usd.StageCache.Id.FromLongInt(cacheIdValue)
        self.assertTrue(self.SC.Contains(cacheId))
        cacheStageB = self.SC.Find(cacheId)

        # Check they are the same
        self.assertEqual(shapeStageA, cacheStageB)
Esempio n. 2
0
    def testCacheIdDisconnect(self):
        # Create the 2 Proxy nodes and load a stage from file
        shapeNodeA = cmds.createNode('mayaUsdProxyShape')
        cmds.setAttr('{}.filePath'.format(shapeNodeA),
                     self.usdfilePath,
                     type='string')
        shapeStageA = mayaUsdLib.GetPrim(shapeNodeA).GetStage()
        shapeNodeB = cmds.createNode('mayaUsdProxyShape')

        #Connect them
        cmds.connectAttr('{}.outStageCacheId'.format(shapeNodeA),
                         '{}.stageCacheId'.format(shapeNodeB))

        shapeStageB = mayaUsdLib.GetPrim(shapeNodeA).GetStage()

        # Check they are the same
        self.assertEqual(shapeStageA, shapeStageB)

        # Diconnect them
        cmds.disconnectAttr('{}.outStageCacheId'.format(shapeNodeA),
                            '{}.stageCacheId'.format(shapeNodeB))

        # Check that the stageCacheId reset to -1
        self.assertEqual(cmds.getAttr('{}.stageCacheId'.format(shapeNodeB)),
                         -1)
Esempio n. 3
0
    def set_usd_reference_assembly_variant(usd_reference_assmebly_node,
                                           variant_name, variant_value):
        """
        Sets the value of the given variant for the given Pixar USD Maya
        Reference Assembly Node (pxrUsdReferenceAssembly)
        :param usd_reference_assmebly_node: str
        :param variant_name: str
        :param variant_value: str
        :return:
        """

        usd_prim = mayaUsdLib.GetPrim(usd_reference_assmebly_node)
        variant_sets = usd_prim.GetVariantSets()
        variant_set_names = variant_sets.GetNames()
        if variant_name not in variant_set_names:
            LOGGER.warning(
                'Variant with name "{}" not found in Usd Prim "{}" ({})'.
                format(variant_name, usd_prim, variant_set_names))
            return

        usd_variant = usd_prim.GetVariantSet(variant_name)
        usd_variant_choices = usd_variant.GetVariantNames()
        if variant_value not in usd_variant_choices:
            LOGGER.warning(
                'Variant Value "{}" not found in Variant Set Name "{}" for Usd Prim "{}" ({})'
                .format(variant_value, variant_name, usd_prim,
                        usd_variant_choices))
            return

        variant_attr_name = 'usdVariantSet_{}'.format(variant_name)
        return tp.Dcc.set_string_attribute_value(usd_reference_assmebly_node,
                                                 variant_attr_name,
                                                 str(variant_value))
Esempio n. 4
0
    def testUsdChangeProcessingProxy(self):
        """
        Tests that authoring on a USD stage that is referenced by a proxy shape
        invokes drawing refreshes in Maya correctly.
        """
        mayaSceneFile = '%s.ma' % self._testName
        mayaSceneFullPath = os.path.join(self._inputDir, mayaSceneFile)
        cmds.file(mayaSceneFullPath, open=True, force=True)

        dagPathName = '|%s|Primitive|PrimitiveShape' % self._testName

        rootPrim = mayaUsdLib.GetPrim(dagPathName)
        self.assertTrue(rootPrim)

        prim = rootPrim.GetChild('Geom').GetChild('Primitive')
        self.assertTrue(prim)
        self.assertEqual(prim.GetTypeName(), 'Cube')
        self._WriteViewportImage(self._testName, 'initial')

        prim.SetTypeName('Sphere')
        self.assertEqual(prim.GetTypeName(), 'Sphere')
        self._WriteViewportImage(self._testName, 'Sphere')

        prim.SetTypeName('Cube')
        self.assertEqual(prim.GetTypeName(), 'Cube')
        self._WriteViewportImage(self._testName, 'Cube')
Esempio n. 5
0
    def _ValidateCards(self, nodeName):
        """
        Checks that the root prim on the stage has its drawmode properly set.
        """
        drawModeAttr = cmds.getAttr('%s.drawMode' % nodeName)
        self.assertEqual(drawModeAttr, 'cards')

        prim = mayaUsdLib.GetPrim(nodeName)
        primModelAPI = UsdGeom.ModelAPI(prim)
        self.assertEqual(primModelAPI.ComputeModelDrawMode(), 'cards')
Esempio n. 6
0
def createXformOps(ufeObject):
    selDag, selPrim = getDagAndPrimFromUfe(ufeObject)
    stage = mayaUsdLib.GetPrim(selDag).GetStage()

    primPath = Sdf.Path(selPrim)
    prim = stage.GetPrimAtPath(primPath)

    xformAPI = UsdGeom.XformCommonAPI(prim)
    xformAPI.CreateXformOps(
                UsdGeom.XformCommonAPI.OpTranslate,
                UsdGeom.XformCommonAPI.OpRotate,
                UsdGeom.XformCommonAPI.OpScale)
Esempio n. 7
0
    def testCacheIdLoadFromInMemory(self):
        # Create the Proxy node and get the in-memory stage
        shapeNode = cmds.createNode('mayaUsdProxyShape')
        shapeStage = mayaUsdLib.GetPrim(shapeNode).GetStage()

        # Get the cache ID and load the stage from the cache
        cacheIdValue = cmds.getAttr('{}.outStageCacheId'.format(shapeNode))
        cacheId = pxr.Usd.StageCache.Id.FromLongInt(cacheIdValue)
        self.assertTrue(self.SC.Contains(cacheId))
        cacheStage = self.SC.Find(cacheId)

        # Check they are the same
        self.assertEqual(shapeStage, cacheStage)
Esempio n. 8
0
    def testDisjointAssembliesVariantSetsChange(self):
        """
        Tests that changing a variant set in a nested assembly |A1|B does not
        affect the variant sets on a different nested assembly |A2|B where
        A1 and A2 reference the same model.
        """
        cmds.file(new=True, force=True)

        usdFile = os.path.abspath("OneCube_set.usda")
        primPath = "/set"

        assemblyNodes = []
        for name in ["assembly1", "assembly2"]:
            assemblyNode = cmds.assembly(name=name,
                                         type=self.ASSEMBLY_TYPE_NAME)
            cmds.setAttr("%s.filePath" % assemblyNode, usdFile, type='string')
            cmds.setAttr("%s.primPath" % assemblyNode, primPath, type='string')
            cmds.assembly(assemblyNode, edit=True, active='Expanded')
            assemblyNodes.append(assemblyNode)

        cube1 = 'NS_%s:Cube_1' % assemblyNodes[0]
        self.assertTrue(cmds.objExists(cube1))

        cube2 = 'NS_%s:Cube_1' % assemblyNodes[1]
        self.assertTrue(cmds.objExists(cube2))

        cmds.setAttr('%s.usdVariantSet_shadingVariant' % cube1,
                     'Blue',
                     type='string')

        prim1 = mayaUsdLib.GetPrim(cube1)
        self.assertEqual(
            prim1.GetVariantSet('shadingVariant').GetVariantSelection(),
            'Blue')

        prim2 = mayaUsdLib.GetPrim(cube2)
        self.assertEqual(
            prim2.GetVariantSet('shadingVariant').GetVariantSelection(),
            'Default')
def getSdfValueType(ufeObject, usdAttrName):
    proxyDagPath, usdPrimPath = getDagAndPrimFromUfe(ufeObject)

    stage = mayaUsdLib.GetPrim(proxyDagPath).GetStage()

    primPath = Sdf.Path(usdPrimPath)
    prim = stage.GetPrimAtPath(primPath)

    usdAttribute = prim.GetAttribute(usdAttrName)
    if usdAttribute.IsDefined():
        return usdAttribute.GetTypeName()
    else:
        return None
Esempio n. 10
0
def createProxyAndStage():
    """
    Create in-memory stage
    """
    cmds.createNode('mayaUsdProxyShape', name='stageShape')

    shapeNode = cmds.ls(sl=True, l=True)[0]
    shapeStage = mayaUsdLib.GetPrim(shapeNode).GetStage()

    cmds.select(clear=True)
    cmds.connectAttr('time1.outTime', '{}.time'.format(shapeNode))

    return shapeNode, shapeStage
Esempio n. 11
0
def createProxyFromFile(filePath):
    """
    Load stage from file
    """
    cmds.createNode('mayaUsdProxyShape', name='stageShape')

    shapeNode = cmds.ls(sl=True, l=True)[0]
    cmds.setAttr('{}.filePath'.format(shapeNode), filePath, type='string')

    shapeStage = mayaUsdLib.GetPrim(shapeNode).GetStage()

    cmds.select(clear=True)
    cmds.connectAttr('time1.outTime', '{}.time'.format(shapeNode))

    return shapeNode, shapeStage
Esempio n. 12
0
    def _RunTest(self, dagPathName):
        rootPrim = mayaUsdLib.GetPrim(dagPathName)
        self.assertTrue(rootPrim)

        prim = rootPrim.GetChild('Geom').GetChild('Primitive')
        self.assertTrue(prim)
        self.assertEqual(prim.GetTypeName(), 'Cube')
        self._WriteViewportImage(self._testName, 'initial')

        prim.SetTypeName('Sphere')
        self.assertEqual(prim.GetTypeName(), 'Sphere')
        self._WriteViewportImage(self._testName, 'Sphere')

        prim.SetTypeName('Cube')
        self.assertEqual(prim.GetTypeName(), 'Cube')
        self._WriteViewportImage(self._testName, 'Cube')
Esempio n. 13
0
    def create_usd_reference_assembly(
            file_path,
            active_representation=UsdReferenceAssemblyRepresentations.COLLAPSED
    ):
        """
        Creates a new Pixar USD Maya Reference Assembly node (pxrUsdReferenceAssembly)
        pointing to the given USD file path
        :param file_path: str
        :param active_representation: str, UsdReferenceAssemblyRepresentations
        :return:
        """

        if not file_path or not os.path.isfile(file_path):
            return False

        file_path_name = os.path.splitext(os.path.basename(file_path))[0]

        assembly_node = maya.cmds.assembly(name=file_path_name,
                                           type='pxrUsdReferenceAssembly')
        tp.Dcc.set_attribute_value(assembly_node, 'filePath', file_path)
        maya.cmds.assembly(assembly_node,
                           active=active_representation,
                           edit=True)

        usd_prim = mayaUsdLib.GetPrim(assembly_node)
        variant_sets = usd_prim.GetVariantSets()
        variant_set_names = variant_sets.GetNames()

        for variant_set_name in variant_set_names:
            usd_variant = usd_prim.GetVariantSet(variant_set_name)
            if not usd_variant:
                continue
            usd_variant_choices = usd_variant.GetVariantNames()
            variant_attr = 'usdVariantSet_%s' % variant_set_name
            if not tp.Dcc.attribute_exists(assembly_node, variant_attr):
                maya.cmds.addAttr(assembly_node,
                                  ln=variant_attr,
                                  dt='string',
                                  internalSet=True)
            if not usd_variant_choices:
                continue
            usd_variant_value = usd_variant_choices[-1]
            maya.cmds.setAttr('{}.{}'.format(assembly_node, variant_attr),
                              usd_variant_value,
                              type='string')

        return assembly_node
def createXformOps(ufeObject):
    selDag, selPrim = getDagAndPrimFromUfe(ufeObject)
    stage = mayaUsdLib.GetPrim(selDag).GetStage()

    primPath = Sdf.Path(selPrim)
    prim = stage.GetPrimAtPath(primPath)

    xformAPI = UsdGeom.XformCommonAPI(prim)
    t, p, r, s, pInv = xformAPI.CreateXformOps(
        UsdGeom.XformCommonAPI.OpTranslate, UsdGeom.XformCommonAPI.OpRotate,
        UsdGeom.XformCommonAPI.OpScale)

    if not t.GetAttr().HasAuthoredValue():
        t.GetAttr().Set(Gf.Vec3d(0, 0, 0))
    if not r.GetAttr().HasAuthoredValue():
        r.GetAttr().Set(Gf.Vec3f(0, 0, 0))
    if not s.GetAttr().HasAuthoredValue():
        s.GetAttr().Set(Gf.Vec3f(1, 1, 1))
Esempio n. 15
0
    def testCacheIdLoadFromCacheId(self):
        # Open the stage and get the cache Id
        with pxr.Usd.StageCacheContext(self.SC):
            cachedStage = Usd.Stage.Open(self.usdfilePath)
        stageId = self.SC.GetId(cachedStage).ToLongInt()

        # Create the proxy node and load using the stage id
        shapeNode = cmds.createNode('mayaUsdProxyShape')
        cmds.setAttr('{}.stageCacheId'.format(shapeNode), stageId)
        shapeStage = mayaUsdLib.GetPrim(shapeNode).GetStage()

        # Get the cache ID and load the stage from the cache
        cacheIdValue = cmds.getAttr('{}.outStageCacheId'.format(shapeNode))
        cacheId = pxr.Usd.StageCache.Id.FromLongInt(cacheIdValue)
        self.assertTrue(self.SC.Contains(cacheId))
        cacheStage = self.SC.Find(cacheId)

        # Check they are the same
        self.assertEqual(shapeStage, cacheStage)
Esempio n. 16
0
    def testAllSelections(self):
        self._SetSelection('fooVariant', 'FooVariantC')
        self._SetSelection('modelingVariant', 'ModVariantB')
        self._SetSelection('shadingVariant', 'ShadVariantA')

        variantSetSelections = UsdMaya.GetVariantSetSelections(
            self.assemblyNodeName)
        self.assertEqual(
            variantSetSelections, {
                'fooVariant': 'FooVariantC',
                'modelingVariant': 'ModVariantB',
                'shadingVariant': 'ShadVariantA'
            })

        # Verify that selecting a non-registered variant set affects the
        # stage's composition.
        prim = mayaUsdLib.GetPrim(self.assemblyNodeName)
        geomPrim = prim.GetChild('Geom')
        cubePrim = geomPrim.GetChild('Cube')

        attrValue = cubePrim.GetAttribute('variantAttribute').Get()
        self.assertEqual(attrValue, 'C')
    def testAnonymousRootToUsd(self):
        self.setupEmptyScene()

        import mayaUsd_createStageWithNewLayer
        proxyShape = mayaUsd_createStageWithNewLayer.createStageWithNewLayer()
        proxyShapePath = ufe.PathString.path(proxyShape)

        stage = mayaUsd.ufe.getStage(str(proxyShapePath))

        newPrimPath = "/ChangeInRoot"
        stage.DefinePrim(newPrimPath, "xform")
        self.assertTrue(stage.GetPrimAtPath(newPrimPath).IsValid())

        stage.SetEditTarget(stage.GetSessionLayer())
        newSessionsPrimPath = "/ChangeInSession"
        stage.DefinePrim(newSessionsPrimPath, "xform")
        self.assertTrue(stage.GetPrimAtPath(newSessionsPrimPath).IsValid())

        cmds.optionVar(intValue=('mayaUsd_SerializedUsdEditsLocation', 1))

        msg = ("Session Layer before: " + stage.GetSessionLayer().identifier)
        stage = None

        cmds.file(save=True, force=True, type='mayaAscii')
        cmds.file(new=True, force=True)
        cmds.file(self._tempMayaFile, open=True)

        stage = mayaUsdLib.GetPrim('|stage1|stageShape1').GetStage()
        msg += ("    Session Layer after: " +
                stage.GetSessionLayer().identifier)
        self.assertTrue(stage.GetPrimAtPath(newPrimPath).IsValid())

        # Temporarily disabling this check while investigating why it can fail on certain build combinations
        # self.assertFalse(stage.GetPrimAtPath(
        #     newSessionsPrimPath).IsValid(), msg)

        cmds.file(new=True, force=True)
        shutil.rmtree(self._currentTestDir)
Esempio n. 18
0
 def getStageFromProxyShape(shapeNode):
     return mayaUsdLib.GetPrim(shapeNode).GetStage()