def _GetEditTargets(self, prim): primIndex = prim.GetPrimIndex() rootNode = primIndex.rootNode refNode = rootNode.children[0] rootLayer = Sdf.Find('timeCodes/root.usda') rootSubLayer = Sdf.Find('timeCodes/root_sub.usda') refLayer = Sdf.Find('timeCodes/ref.usda') refSubLayer = Sdf.Find('timeCodes/ref_sub.usda') self.assertTrue(rootLayer) self.assertTrue(rootSubLayer) self.assertTrue(refLayer) self.assertTrue(refSubLayer) # No mapping rootEditTarget = Usd.EditTarget(rootLayer) # Composed layer offset: scale = 0.5 rootSubEditTarget = Usd.EditTarget(rootSubLayer, rootNode) # Composed layer offset: scale = 2, offset = -3.0 refEditTarget = Usd.EditTarget(refLayer, refNode) # Composed layer offset: scale = 2, offset = +3.0 refSubEditTarget = Usd.EditTarget(refSubLayer, refNode) self.assertEqual(rootEditTarget.GetLayer(), rootLayer) self.assertEqual(rootSubEditTarget.GetLayer(), rootSubLayer) self.assertEqual(refEditTarget.GetLayer(), refLayer) self.assertEqual(refSubEditTarget.GetLayer(), refSubLayer) # Edit targets returned as a tuple with the layers from strongest to # weakest. return (rootEditTarget, rootSubEditTarget, refEditTarget, refSubEditTarget)
def _GetEditTargets(self, prim): primIndex = prim.GetPrimIndex() rootNode = primIndex.rootNode refNode = rootNode.children[0] rootLayer = Sdf.Find('timeCodes/root.usda') rootSubLayer = Sdf.Find('timeCodes/root_sub.usda') refLayer = Sdf.Find('timeCodes/ref.usda') refSubLayer = Sdf.Find('timeCodes/ref_sub.usda') self.assertTrue(rootLayer) self.assertTrue(rootSubLayer) self.assertTrue(refLayer) self.assertTrue(refSubLayer) # No mapping rootEditTarget = Usd.EditTarget(rootLayer) # Composed layer offset: scale = 0.5 (note that this from a tcps change # from 24 to 48 from the root layer to its sub layer) rootSubEditTarget = Usd.EditTarget(rootSubLayer, rootNode) # Composed layer offset: scale = 2, offset = -3.0 (note that this # includes another tcps change back to 24 across the reference) refEditTarget = Usd.EditTarget(refLayer, refNode) # Composed layer offset: scale = 2, offset = +3.0 refSubEditTarget = Usd.EditTarget(refSubLayer, refNode) self.assertEqual(rootEditTarget.GetLayer(), rootLayer) self.assertEqual(rootSubEditTarget.GetLayer(), rootSubLayer) self.assertEqual(refEditTarget.GetLayer(), refLayer) self.assertEqual(refSubEditTarget.GetLayer(), refSubLayer) # Edit targets returned as a tuple with the layers from strongest to # weakest. return (rootEditTarget, rootSubEditTarget, refEditTarget, refSubEditTarget)
def test_anonymousLayerSerialisation(self): """Tests multiple anonymous sublayers can be saved and restored. """ def _setupStage(): # Create a prim at root layer rootLayer = self._stage.GetRootLayer() Sdf.CreatePrimInLayer(rootLayer, "/root") # Create session layer with prim sessionLayer = self._stage.GetSessionLayer() Sdf.CreatePrimInLayer(sessionLayer, "/root/prim01") # Create anonymous sublayers sublayer01 = Sdf.Layer.CreateAnonymous() Sdf.CreatePrimInLayer(sublayer01, "/root/subprim01") sublayer02 = Sdf.Layer.CreateAnonymous() Sdf.CreatePrimInLayer(sublayer02, "/root/subprim02") # TODO easy way to add testing for recursive restoration # sublayer03 = Sdf.Layer.CreateAnonymous() # Sdf.CreatePrimInLayer(sublayer02, "/root/subprim02/subsubprim03") # sublayer02.subLayerPaths = [sublayer03.identifier] # Add sublayers to session layer sessionLayer.subLayerPaths = [ sublayer01.identifier, sublayer02.identifier ] def _saveScene(): # Save Maya scene to temp file and close cmds.file(rename=self._mayaFilePath) cmds.file(save=True, force=True, type="mayaAscii") return self._mayaFilePath def _reloadScene(filename): # Reopen the Maya scene file cmds.file(new=True, force=True) cmds.file(filename, open=True) self._stage = ProxyShape.getByName( 'AL_usdmaya_Proxy').getUsdStage() _setupStage() file = _saveScene() _reloadScene(file) # Assert reloaded state of anonymous sublayers sessionLayer = self._stage.GetSessionLayer() self.assertEqual(len(sessionLayer.subLayerPaths), 2) sublayer01 = Sdf.Find(sessionLayer.subLayerPaths[0]) sublayer02 = Sdf.Find(sessionLayer.subLayerPaths[1]) self.assertIsNotNone(sublayer01) self.assertIsNotNone(sublayer02) self.assertIsNotNone(sublayer01.GetPrimAtPath('/root/subprim01')) self.assertIsNotNone(sublayer02.GetPrimAtPath('/root/subprim02'))
def testTranslateLockedLayer(self): # create new stage cmds.file(new=True, force=True) # Open usdCylinder.ma scene in testSamples mayaUtils.openCylinderScene() # get the stage proxyShapes = cmds.ls(type="mayaUsdProxyShapeBase", long=True) proxyShapePath = proxyShapes[0] stage = mayaUsd.lib.GetPrim(proxyShapePath).GetStage() # cylinder prim cylinderPrim = stage.GetPrimAtPath('/pCylinder1') self.assertIsNotNone(cylinderPrim) # create a sub-layer. rootLayer = stage.GetRootLayer() subLayerA = cmds.mayaUsdLayerEditor(rootLayer.identifier, edit=True, addAnonymous="LayerA")[0] # check to see the if the sublayers was added addedLayers = [subLayerA] self.assertEqual(rootLayer.subLayerPaths, addedLayers) # set the edit target to LayerA. cmds.mayaUsdEditTarget(proxyShapePath, edit=True, editTarget=subLayerA) # set permission to edit to false layerA = Sdf.Find(subLayerA) layerA.SetPermissionToEdit(False) # Check that our helper function is returning the right thing self.assertFalse(mayaUsdUfe.isEditTargetLayerModifiable(stage)) # Get translate attribute and make sure its empty translateAttr = cylinderPrim.GetAttribute('xformOp:translate') self.assertIsNotNone(translateAttr) tranlateBeforeEdit = translateAttr.Get() # create a transform3d and translate cylinderPath = ufe.Path([ mayaUtils.createUfePathSegment("|mayaUsdTransform|shape"), usdUtils.createUfePathSegment("/pCylinder1") ]) cylinderItem = ufe.Hierarchy.createItem(cylinderPath) cylinderT3d = ufe.Transform3d.transform3d(cylinderItem) if cylinderT3d is not None: cylinderT3d.translate(5.0, 6.0, 7.0) # check that the translate operation didn't change anything tranlateAfterEdit = translateAttr.Get() self.assertEqual(tranlateBeforeEdit, tranlateAfterEdit)
def testEditRouter(self): '''Test edit router functionality.''' cmds.file(new=True, force=True) import mayaUsd_createStageWithNewLayer # Create the following hierarchy: # # ps # |_ A # |_ B # # We A and duplicate it. psPathStr = mayaUsd_createStageWithNewLayer.createStageWithNewLayer() stage = mayaUsd.lib.GetPrim(psPathStr).GetStage() stage.DefinePrim('/A', 'Xform') stage.DefinePrim('/A/B', 'Xform') psPath = ufe.PathString.path(psPathStr) psPathSegment = psPath.segments[0] aPath = ufe.Path([psPathSegment, usdUtils.createUfePathSegment('/A')]) a = ufe.Hierarchy.createItem(aPath) bPath = aPath + ufe.PathComponent('B') b = ufe.Hierarchy.createItem(bPath) # Add a sub-layer, where the parent edit should write to. subLayerId = cmds.mayaUsdLayerEditor(stage.GetRootLayer().identifier, edit=True, addAnonymous="aSubLayer")[0] mayaUsd.lib.registerEditRouter('duplicate', firstSubLayer) sn = ufe.GlobalSelection.get() sn.clear() sn.append(a) cmds.duplicate() sublayer01 = Sdf.Find(subLayerId) self.assertIsNotNone(sublayer01) self.assertIsNotNone(sublayer01.GetPrimAtPath('/A1/B'))
def test_PrimCompositionQuery(self): self.maxDiff = None layerFile = 'test.usda' layer = Sdf.Layer.FindOrOpen(layerFile) assert layer, 'failed to find "test.usda' stage = Usd.Stage.Open(layerFile) assert stage, 'failed to create stage for %s' % layerFile prim = stage.GetPrimAtPath('/Sarah') assert prim, 'failed to find prim /Sarah' # Explicit set of expected values that should match the unfiltered query expectedValues = [{ 'nodeLayerStack': Sdf.Find('test.usda'), 'nodePath': Sdf.Path('/Sarah'), 'arcType': Pcp.ArcTypeRoot, 'hasSpecs': True, 'introLayerStack': Sdf.Find('test.usda'), 'introLayer': None, 'introPath': Sdf.Path(), 'introInListEdit': None, 'isImplicit': False, 'isAncestral': False, 'isIntroRootLayer': True, 'isIntroRootLayerPrim': True }, { 'nodeLayerStack': Sdf.Find('test.usda'), 'nodePath': Sdf.Path('/_class_Sarah'), 'arcType': Pcp.ArcTypeInherit, 'hasSpecs': True, 'introLayerStack': Sdf.Find('test.usda'), 'introLayer': Sdf.Find('test.usda'), 'introPath': Sdf.Path('/Sarah'), 'introInListEdit': Sdf.Path('/_class_Sarah'), 'isImplicit': False, 'isAncestral': False, 'isIntroRootLayer': True, 'isIntroRootLayerPrim': True }, { 'nodeLayerStack': Sdf.Find('test.usda'), 'nodePath': Sdf.Path('/_class_Sarah_Ref_Sub1'), 'arcType': Pcp.ArcTypeInherit, 'hasSpecs': False, 'introLayerStack': Sdf.Find('testAPI_root.usda'), 'introLayer': Sdf.Find('testAPI_sub1.usda'), 'introPath': Sdf.Path('/Sarah_Ref'), 'introInListEdit': Sdf.Path('/_class_Sarah_Ref_Sub1'), 'isImplicit': True, 'isAncestral': False, 'isIntroRootLayer': False, 'isIntroRootLayerPrim': False }, { 'nodeLayerStack': Sdf.Find('test.usda'), 'nodePath': Sdf.Path('/_class_Sarah_Ref'), 'arcType': Pcp.ArcTypeInherit, 'hasSpecs': False, 'introLayerStack': Sdf.Find('testAPI_root.usda'), 'introLayer': Sdf.Find('testAPI_root.usda'), 'introPath': Sdf.Path('/Sarah_Ref'), 'introInListEdit': Sdf.Path('/_class_Sarah_Ref'), 'isImplicit': True, 'isAncestral': False, 'isIntroRootLayer': False, 'isIntroRootLayerPrim': False }, { 'nodeLayerStack': Sdf.Find('test.usda'), 'nodePath': Sdf.Path('/Sarah{displayColor=red}'), 'arcType': Pcp.ArcTypeVariant, 'hasSpecs': True, 'introLayerStack': Sdf.Find('test.usda'), 'introLayer': Sdf.Find('test.usda'), 'introPath': Sdf.Path('/Sarah'), 'introInListEdit': 'displayColor', 'isImplicit': False, 'isAncestral': False, 'isIntroRootLayer': True, 'isIntroRootLayerPrim': True }, { 'nodeLayerStack': Sdf.Find('test.usda'), 'nodePath': Sdf.Path('/Sarah{standin=render}'), 'arcType': Pcp.ArcTypeVariant, 'hasSpecs': True, 'introLayerStack': Sdf.Find('test.usda'), 'introLayer': Sdf.Find('test.usda'), 'introPath': Sdf.Path('/Sarah'), 'introInListEdit': 'standin', 'isImplicit': False, 'isAncestral': False, 'isIntroRootLayer': True, 'isIntroRootLayerPrim': True }, { 'nodeLayerStack': Sdf.Find('test.usda'), 'nodePath': Sdf.Path('/Sarah{standin=render}{lod=full}'), 'arcType': Pcp.ArcTypeVariant, 'hasSpecs': True, 'introLayerStack': Sdf.Find('test.usda'), 'introLayer': Sdf.Find('test.usda'), 'introPath': Sdf.Path('/Sarah{standin=render}'), 'introInListEdit': 'lod', 'isImplicit': False, 'isAncestral': False, 'isIntroRootLayer': True, 'isIntroRootLayerPrim': False }, { 'nodeLayerStack': Sdf.Find('test.usda'), 'nodePath': Sdf.Path('/Sarah_Defaults'), 'arcType': Pcp.ArcTypeReference, 'hasSpecs': True, 'introLayerStack': Sdf.Find('test.usda'), 'introLayer': Sdf.Find('test.usda'), 'introPath': Sdf.Path('/Sarah'), 'introInListEdit': Sdf.Reference('test.usda', '/Sarah_Defaults'), 'isImplicit': False, 'isAncestral': False, 'isIntroRootLayer': True, 'isIntroRootLayerPrim': True }, { 'nodeLayerStack': Sdf.Find('test.usda'), 'nodePath': Sdf.Path('/Sarah_Base'), 'arcType': Pcp.ArcTypeReference, 'hasSpecs': True, 'introLayerStack': Sdf.Find('test.usda'), 'introLayer': Sdf.Find('test.usda'), 'introPath': Sdf.Path('/Sarah_Defaults'), 'introInListEdit': Sdf.Reference('test.usda', '/Sarah_Base'), 'isImplicit': False, 'isAncestral': False, 'isIntroRootLayer': True, 'isIntroRootLayerPrim': False }, { 'nodeLayerStack': Sdf.Find('test.usda'), 'nodePath': Sdf.Path('/Sarah_Base{displayColor=red}'), 'arcType': Pcp.ArcTypeVariant, 'hasSpecs': True, 'introLayerStack': Sdf.Find('test.usda'), 'introLayer': Sdf.Find('test.usda'), 'introPath': Sdf.Path('/Sarah_Base'), 'introInListEdit': 'displayColor', 'isImplicit': False, 'isAncestral': False, 'isIntroRootLayer': True, 'isIntroRootLayerPrim': False }, { 'nodeLayerStack': Sdf.Find('test.usda'), 'nodePath': Sdf.Path('/Sarah_Base'), 'arcType': Pcp.ArcTypeReference, 'hasSpecs': True, 'introLayerStack': Sdf.Find('test.usda'), 'introLayer': Sdf.Find('test.usda'), 'introPath': Sdf.Path('/Sarah_Defaults'), 'introInListEdit': Sdf.Reference('test.usda', '/Sarah_Base', Sdf.LayerOffset(10)), 'isImplicit': False, 'isAncestral': False, 'isIntroRootLayer': True, 'isIntroRootLayerPrim': False }, { 'nodeLayerStack': Sdf.Find('test.usda'), 'nodePath': Sdf.Path('/Sarah_Base{displayColor=red}'), 'arcType': Pcp.ArcTypeVariant, 'hasSpecs': True, 'introLayerStack': Sdf.Find('test.usda'), 'introLayer': Sdf.Find('test.usda'), 'introPath': Sdf.Path('/Sarah_Base'), 'introInListEdit': 'displayColor', 'isImplicit': False, 'isAncestral': False, 'isIntroRootLayer': True, 'isIntroRootLayerPrim': False }, { 'nodeLayerStack': Sdf.Find('testAPI_root.usda'), 'nodePath': Sdf.Path('/Sarah_Ref'), 'arcType': Pcp.ArcTypeReference, 'hasSpecs': True, 'introLayerStack': Sdf.Find('test.usda'), 'introLayer': Sdf.Find('test.usda'), 'introPath': Sdf.Path('/Sarah'), 'introInListEdit': Sdf.Reference('testAPI_root.usda', '/Sarah_Ref'), 'isImplicit': False, 'isAncestral': False, 'isIntroRootLayer': True, 'isIntroRootLayerPrim': True }, { 'nodeLayerStack': Sdf.Find('testAPI_root.usda'), 'nodePath': Sdf.Path('/_class_Sarah_Ref_Sub1'), 'arcType': Pcp.ArcTypeInherit, 'hasSpecs': True, 'introLayerStack': Sdf.Find('testAPI_root.usda'), 'introLayer': Sdf.Find('testAPI_sub1.usda'), 'introPath': Sdf.Path('/Sarah_Ref'), 'introInListEdit': Sdf.Path('/_class_Sarah_Ref_Sub1'), 'isImplicit': False, 'isAncestral': False, 'isIntroRootLayer': False, 'isIntroRootLayerPrim': False }, { 'nodeLayerStack': Sdf.Find('testAPI_root.usda'), 'nodePath': Sdf.Path('/_class_Sarah_Ref'), 'arcType': Pcp.ArcTypeInherit, 'hasSpecs': True, 'introLayerStack': Sdf.Find('testAPI_root.usda'), 'introLayer': Sdf.Find('testAPI_root.usda'), 'introPath': Sdf.Path('/Sarah_Ref'), 'introInListEdit': Sdf.Path('/_class_Sarah_Ref'), 'isImplicit': False, 'isAncestral': False, 'isIntroRootLayer': False, 'isIntroRootLayerPrim': False }, { 'nodeLayerStack': Sdf.Find('test.usda'), 'nodePath': Sdf.Path('/Sarah_Internal_Payload'), 'arcType': Pcp.ArcTypePayload, 'hasSpecs': True, 'introLayerStack': Sdf.Find('test.usda'), 'introLayer': Sdf.Find('test.usda'), 'introPath': Sdf.Path('/Sarah'), 'introInListEdit': Sdf.Payload(primPath='/Sarah_Internal_Payload'), 'isImplicit': False, 'isAncestral': False, 'isIntroRootLayer': True, 'isIntroRootLayerPrim': True }, { 'nodeLayerStack': Sdf.Find('testAPI_root.usda'), 'nodePath': Sdf.Path('/Sarah_Payload'), 'arcType': Pcp.ArcTypePayload, 'hasSpecs': True, 'introLayerStack': Sdf.Find('test.usda'), 'introLayer': Sdf.Find('test.usda'), 'introPath': Sdf.Path('/Sarah'), 'introInListEdit': Sdf.Payload('testAPI_root.usda', '/Sarah_Payload'), 'isImplicit': False, 'isAncestral': False, 'isIntroRootLayer': True, 'isIntroRootLayerPrim': True }, { 'nodeLayerStack': Sdf.Find('test.usda'), 'nodePath': Sdf.Path('/Sarah_Container/_class_Sarah_Specialized'), 'arcType': Pcp.ArcTypeSpecialize, 'hasSpecs': True, 'introLayerStack': Sdf.Find('testAPI_root.usda'), 'introLayer': Sdf.Find('testAPI_sub2.usda'), 'introPath': Sdf.Path('/Sarah_Payload'), 'introInListEdit': Sdf.Path('/Sarah_Container/_class_Sarah_Specialized'), 'isImplicit': True, 'isAncestral': False, 'isIntroRootLayer': False, 'isIntroRootLayerPrim': False }, { 'nodeLayerStack': Sdf.Find('test.usda'), 'nodePath': Sdf.Path('/Sarah_Container/_class_Sarah_Inherited'), 'arcType': Pcp.ArcTypeInherit, 'hasSpecs': False, 'introLayerStack': Sdf.Find('test.usda'), 'introLayer': Sdf.Find('test.usda'), 'introPath': Sdf.Path('/Sarah_Container/_class_Sarah_Specialized'), 'introInListEdit': Sdf.Path('/Sarah_Container/_class_Sarah_Inherited'), 'isImplicit': False, 'isAncestral': False, 'isIntroRootLayer': True, 'isIntroRootLayerPrim': False }, { 'nodeLayerStack': Sdf.Find('testAPI_root.usda'), 'nodePath': Sdf.Path('/Sarah_Container_Ref/_class_Sarah_Inherited'), 'arcType': Pcp.ArcTypeReference, 'hasSpecs': True, 'introLayerStack': Sdf.Find('test.usda'), 'introLayer': Sdf.Find('test.usda'), 'introPath': Sdf.Path('/Sarah_Container'), 'introInListEdit': Sdf.Reference('testAPI_root.usda', '/Sarah_Container_Ref'), 'isImplicit': False, 'isAncestral': True, 'isIntroRootLayer': True, 'isIntroRootLayerPrim': False }, { 'nodeLayerStack': Sdf.Find('testAPI_root.usda'), 'nodePath': Sdf.Path('/Sarah_Container_Ref/_class_Sarah_Specialized'), 'arcType': Pcp.ArcTypeReference, 'hasSpecs': True, 'introLayerStack': Sdf.Find('test.usda'), 'introLayer': Sdf.Find('test.usda'), 'introPath': Sdf.Path('/Sarah_Container'), 'introInListEdit': Sdf.Reference('testAPI_root.usda', '/Sarah_Container_Ref'), 'isImplicit': False, 'isAncestral': True, 'isIntroRootLayer': True, 'isIntroRootLayerPrim': False }, { 'nodeLayerStack': Sdf.Find('testAPI_root.usda'), 'nodePath': Sdf.Path('/Sarah_Container/_class_Sarah_Specialized'), 'arcType': Pcp.ArcTypeSpecialize, 'hasSpecs': False, 'introLayerStack': Sdf.Find('testAPI_root.usda'), 'introLayer': Sdf.Find('testAPI_sub2.usda'), 'introPath': Sdf.Path('/Sarah_Payload'), 'introInListEdit': Sdf.Path('/Sarah_Container/_class_Sarah_Specialized'), 'isImplicit': False, 'isAncestral': False, 'isIntroRootLayer': False, 'isIntroRootLayerPrim': False }] # Create the query on the prim. query = Usd.PrimCompositionQuery(prim) # Can use this to print out the unfiltered arcs if desired. Can be # useful in updating expectedValues if need be. #self.PrintExpectedValues(query.GetCompositionArcs()) # Verify the arcs match the expected arcs def _VerifyExpectedArcs(arcs, expectedArcValues): self.assertEqual(len(arcs), len(expectedArcValues)) for arc, expected in zip(arcs, expectedArcValues): self.assertEqual(self._GetArcValuesDict(arc), expected) # Helper function for verifying that the introducing layer and path # for an arc actually introduce the arc. def _VerifyArcIntroducingInfo(arc): listEditor, entry = arc.GetIntroducingListEditor() if arc.GetArcType() == Pcp.ArcTypeRoot: assert listEditor is None assert entry is None self.assertEqual(arc.GetTargetNode(), arc.GetIntroducingNode()) self.assertFalse(arc.GetIntroducingLayer()) self.assertFalse(arc.GetIntroducingPrimPath()) else: # The introducing prim spec is obtained from the introducing layer # and prim path. primSpec = arc.GetIntroducingLayer().GetPrimAtPath( arc.GetIntroducingPrimPath()) assert primSpec assert listEditor assert entry listEntries = listEditor.ApplyEditsToList([]) assert listEntries self.assertIn(entry, listEntries) if arc.GetArcType() == Pcp.ArcTypeReference: self.assertEqual( listEntries, primSpec.referenceList.ApplyEditsToList([])) elif arc.GetArcType() == Pcp.ArcTypePayload: self.assertEqual(listEntries, primSpec.payloadList.ApplyEditsToList([])) elif arc.GetArcType() == Pcp.ArcTypeInherit: self.assertEqual( listEntries, primSpec.inheritPathList.ApplyEditsToList([])) elif arc.GetArcType() == Pcp.ArcTypeSpecialize: self.assertEqual( listEntries, primSpec.specializesList.ApplyEditsToList([])) elif arc.GetArcType() == Pcp.ArcTypeVariant: self.assertEqual( listEntries, primSpec.variantSetNameList.ApplyEditsToList([])) # Updates the query with a new filter and compares expected values # while also checking that our introducing layers have specs that # actually introduce the arc. def CheckWithFilter( expectedFilteredValues, arcTypeFilter=Usd.PrimCompositionQuery.ArcTypeFilter.All, arcIntroducedFilter=Usd.PrimCompositionQuery. ArcIntroducedFilter.All, dependencyTypeFilter=Usd.PrimCompositionQuery. DependencyTypeFilter.All, hasSpecsFilter=Usd.PrimCompositionQuery.HasSpecsFilter.All): # Create an updated filter for the query. qFilter = Usd.PrimCompositionQuery.Filter() qFilter.arcTypeFilter = arcTypeFilter qFilter.arcIntroducedFilter = arcIntroducedFilter qFilter.dependencyTypeFilter = dependencyTypeFilter qFilter.hasSpecsFilter = hasSpecsFilter query.filter = qFilter # Query the composition arcs arcs = query.GetCompositionArcs() # Verify the arcs match the expected arcs _VerifyExpectedArcs(arcs, expectedFilteredValues) # Verify that the "introducing" APIs return what we expect for # each arc. for arc in arcs: _VerifyArcIntroducingInfo(arc) # First verify the unfiltered query. CheckWithFilter(expectedValues) # Now we verify each single type filter. We filter the expected values # and the results of each query should match. We explicity verify the # the length of the each filtered expected value list as an extra # verification that the test is working as expected. # Arc type filters filteredExpectedValues = [ d for d in expectedValues if d['arcType'] == Pcp.ArcTypeReference ] self.assertEqual(len(filteredExpectedValues), 6) CheckWithFilter( filteredExpectedValues, arcTypeFilter=Usd.PrimCompositionQuery.ArcTypeFilter.Reference) filteredExpectedValues = [ d for d in expectedValues if d['arcType'] == Pcp.ArcTypePayload ] self.assertEqual(len(filteredExpectedValues), 2) CheckWithFilter( filteredExpectedValues, arcTypeFilter=Usd.PrimCompositionQuery.ArcTypeFilter.Payload) filteredExpectedValues = [ d for d in expectedValues if d['arcType'] == Pcp.ArcTypeInherit ] self.assertEqual(len(filteredExpectedValues), 6) CheckWithFilter( filteredExpectedValues, arcTypeFilter=Usd.PrimCompositionQuery.ArcTypeFilter.Inherit) filteredExpectedValues = [ d for d in expectedValues if d['arcType'] == Pcp.ArcTypeSpecialize ] self.assertEqual(len(filteredExpectedValues), 2) CheckWithFilter( filteredExpectedValues, arcTypeFilter=Usd.PrimCompositionQuery.ArcTypeFilter.Specialize) filteredExpectedValues = [ d for d in expectedValues if d['arcType'] == Pcp.ArcTypeVariant ] print(filteredExpectedValues) self.assertEqual(len(filteredExpectedValues), 5) CheckWithFilter( filteredExpectedValues, arcTypeFilter=Usd.PrimCompositionQuery.ArcTypeFilter.Variant) filteredExpectedValues = [ d for d in expectedValues if d['arcType'] in [Pcp.ArcTypeReference, Pcp.ArcTypePayload] ] self.assertEqual(len(filteredExpectedValues), 8) CheckWithFilter(filteredExpectedValues, arcTypeFilter=Usd.PrimCompositionQuery.ArcTypeFilter. ReferenceOrPayload) filteredExpectedValues = [ d for d in expectedValues if d['arcType'] in [Pcp.ArcTypeInherit, Pcp.ArcTypeSpecialize] ] self.assertEqual(len(filteredExpectedValues), 8) CheckWithFilter(filteredExpectedValues, arcTypeFilter=Usd.PrimCompositionQuery.ArcTypeFilter. InheritOrSpecialize) filteredExpectedValues = [ d for d in expectedValues if d['arcType'] not in [Pcp.ArcTypeReference, Pcp.ArcTypePayload] ] self.assertEqual(len(filteredExpectedValues), 14) CheckWithFilter(filteredExpectedValues, arcTypeFilter=Usd.PrimCompositionQuery.ArcTypeFilter. NotReferenceOrPayload) filteredExpectedValues = [ d for d in expectedValues if d['arcType'] not in [Pcp.ArcTypeInherit, Pcp.ArcTypeSpecialize] ] self.assertEqual(len(filteredExpectedValues), 14) CheckWithFilter(filteredExpectedValues, arcTypeFilter=Usd.PrimCompositionQuery.ArcTypeFilter. NotInheritOrSpecialize) filteredExpectedValues = [ d for d in expectedValues if d['arcType'] != Pcp.ArcTypeVariant ] self.assertEqual(len(filteredExpectedValues), 17) CheckWithFilter( filteredExpectedValues, arcTypeFilter=Usd.PrimCompositionQuery.ArcTypeFilter.NotVariant) # Arc introduced filters filteredExpectedValues = [ d for d in expectedValues if d['isIntroRootLayer'] ] self.assertEqual(len(filteredExpectedValues), 16) CheckWithFilter(filteredExpectedValues, arcIntroducedFilter=Usd.PrimCompositionQuery. ArcIntroducedFilter.IntroducedInRootLayerStack) filteredExpectedValues = [ d for d in expectedValues if d['isIntroRootLayerPrim'] ] self.assertEqual(len(filteredExpectedValues), 8) CheckWithFilter(filteredExpectedValues, arcIntroducedFilter=Usd.PrimCompositionQuery. ArcIntroducedFilter.IntroducedInRootLayerPrimSpec) # Dependency type filters filteredExpectedValues = [ d for d in expectedValues if not d['isAncestral'] ] self.assertEqual(len(filteredExpectedValues), 20) CheckWithFilter(filteredExpectedValues, dependencyTypeFilter=Usd.PrimCompositionQuery. DependencyTypeFilter.Direct) filteredExpectedValues = [ d for d in expectedValues if d['isAncestral'] ] self.assertEqual(len(filteredExpectedValues), 2) CheckWithFilter(filteredExpectedValues, dependencyTypeFilter=Usd.PrimCompositionQuery. DependencyTypeFilter.Ancestral) # Has specs filters filteredExpectedValues = [d for d in expectedValues if d['hasSpecs']] self.assertEqual(len(filteredExpectedValues), 18) CheckWithFilter( filteredExpectedValues, hasSpecsFilter=Usd.PrimCompositionQuery.HasSpecsFilter.HasSpecs) filteredExpectedValues = [ d for d in expectedValues if not d['hasSpecs'] ] self.assertEqual(len(filteredExpectedValues), 4) CheckWithFilter( filteredExpectedValues, hasSpecsFilter=Usd.PrimCompositionQuery.HasSpecsFilter.HasNoSpecs) # Test combining filter types # Start with a dependency type filter filteredExpectedValues = [ d for d in expectedValues if not d['isAncestral'] ] self.assertEqual(len(filteredExpectedValues), 20) CheckWithFilter(filteredExpectedValues, dependencyTypeFilter=Usd.PrimCompositionQuery. DependencyTypeFilter.Direct) # Add an arc type filter. Note that we refilter the already filtered # expected values unlike the cases above. filteredExpectedValues = [ d for d in filteredExpectedValues if d['arcType'] != Pcp.ArcTypeVariant ] self.assertEqual(len(filteredExpectedValues), 15) CheckWithFilter( filteredExpectedValues, dependencyTypeFilter=Usd.PrimCompositionQuery.DependencyTypeFilter. Direct, arcTypeFilter=Usd.PrimCompositionQuery.ArcTypeFilter.NotVariant) # Add a has specs filter filteredExpectedValues = [ d for d in filteredExpectedValues if d['hasSpecs'] ] self.assertEqual(len(filteredExpectedValues), 11) CheckWithFilter( filteredExpectedValues, dependencyTypeFilter=Usd.PrimCompositionQuery.DependencyTypeFilter. Direct, arcTypeFilter=Usd.PrimCompositionQuery.ArcTypeFilter.NotVariant, hasSpecsFilter=Usd.PrimCompositionQuery.HasSpecsFilter.HasSpecs) # Add an arc introduced filter. filteredExpectedValues = [ d for d in filteredExpectedValues if d['isIntroRootLayer'] ] self.assertEqual(len(filteredExpectedValues), 8) CheckWithFilter( filteredExpectedValues, dependencyTypeFilter=Usd.PrimCompositionQuery.DependencyTypeFilter. Direct, arcTypeFilter=Usd.PrimCompositionQuery.ArcTypeFilter.NotVariant, hasSpecsFilter=Usd.PrimCompositionQuery.HasSpecsFilter.HasSpecs, arcIntroducedFilter=Usd.PrimCompositionQuery.ArcIntroducedFilter. IntroducedInRootLayerStack) # Test the pre-defined queries # Direct references query = Usd.PrimCompositionQuery.GetDirectReferences(prim) self.assertEqual(query.filter.arcTypeFilter, Usd.PrimCompositionQuery.ArcTypeFilter.Reference) self.assertEqual(query.filter.dependencyTypeFilter, Usd.PrimCompositionQuery.DependencyTypeFilter.Direct) self.assertEqual(query.filter.arcIntroducedFilter, Usd.PrimCompositionQuery.ArcIntroducedFilter.All) self.assertEqual(query.filter.hasSpecsFilter, Usd.PrimCompositionQuery.HasSpecsFilter.All) # Query the composition arcs arcs = query.GetCompositionArcs() # Verify the arcs match the expected arcs filteredExpectedValues = [ d for d in expectedValues if not d['isAncestral'] and d['arcType'] == Pcp.ArcTypeReference ] _VerifyExpectedArcs(arcs, filteredExpectedValues) # Direct inherits query = Usd.PrimCompositionQuery.GetDirectInherits(prim) self.assertEqual(query.filter.arcTypeFilter, Usd.PrimCompositionQuery.ArcTypeFilter.Inherit) self.assertEqual(query.filter.dependencyTypeFilter, Usd.PrimCompositionQuery.DependencyTypeFilter.Direct) self.assertEqual(query.filter.arcIntroducedFilter, Usd.PrimCompositionQuery.ArcIntroducedFilter.All) self.assertEqual(query.filter.hasSpecsFilter, Usd.PrimCompositionQuery.HasSpecsFilter.All) # Query the composition arcs arcs = query.GetCompositionArcs() # Verify the arcs match the expected arcs filteredExpectedValues = [ d for d in expectedValues if not d['isAncestral'] and d['arcType'] == Pcp.ArcTypeInherit ] _VerifyExpectedArcs(arcs, filteredExpectedValues) # Direct root layer arcs query = Usd.PrimCompositionQuery.GetDirectRootLayerArcs(prim) self.assertEqual(query.filter.arcTypeFilter, Usd.PrimCompositionQuery.ArcTypeFilter.All) self.assertEqual(query.filter.dependencyTypeFilter, Usd.PrimCompositionQuery.DependencyTypeFilter.Direct) self.assertEqual( query.filter.arcIntroducedFilter, Usd.PrimCompositionQuery. ArcIntroducedFilter.IntroducedInRootLayerStack) self.assertEqual(query.filter.hasSpecsFilter, Usd.PrimCompositionQuery.HasSpecsFilter.All) # Query the composition arcs arcs = query.GetCompositionArcs() # Verify the arcs match the expected arcs filteredExpectedValues = [ d for d in expectedValues if not d['isAncestral'] and d['isIntroRootLayer'] ] _VerifyExpectedArcs(arcs, filteredExpectedValues) # test to make sure c++ objects are propertly destroyed when # PrimCollectionQuery instance is garbage collection stage = Usd.Stage.CreateInMemory("testCreationAndGarbageCollect.usda") Usd.PrimCompositionQuery(stage.GetPseudoRoot()) sessionLayer = stage.GetSessionLayer() del stage self.assertTrue(sessionLayer.expired)