def test_ExpansionConnections(self): stage = Usd.Stage.CreateInMemory() a = stage.DefinePrim('/World/A') b = stage.DefinePrim('/World/B') c = stage.DefinePrim('/World/C') d = stage.DefinePrim('/World/D') e = stage.DefinePrim('/World/E') bAttr = b.CreateAttribute('attr', Sdf.ValueTypeNames.Float) cAttr = c.CreateAttribute('attr', Sdf.ValueTypeNames.Float) dAttr = d.CreateAttribute('attr', Sdf.ValueTypeNames.Float) eAttr = e.CreateAttribute('attr', Sdf.ValueTypeNames.Float) floatType = Sdf.ValueTypeNames.Float a.CreateAttribute('a', floatType).AddConnection(bAttr.GetPath()) b.CreateAttribute('a', floatType).AddConnection(cAttr.GetPath()) c.CreateAttribute('a', floatType).AddConnection(dAttr.GetPath()) a.CreateAttribute('pred', floatType).AddConnection(eAttr.GetPath()) mask = Usd.StagePopulationMask().Add(a.GetPath()) masked = Usd.Stage.OpenMasked(stage.GetRootLayer(), mask) assert masked.GetPrimAtPath(a.GetPath()) assert not masked.GetPrimAtPath(b.GetPath()) assert not masked.GetPrimAtPath(c.GetPath()) assert not masked.GetPrimAtPath(d.GetPath()) assert not masked.GetPrimAtPath(e.GetPath()) # Now expand the mask for all connections. masked.ExpandPopulationMask() assert masked.GetPrimAtPath(a.GetPath()) assert masked.GetPrimAtPath(b.GetPath()) assert masked.GetPrimAtPath(c.GetPath()) assert masked.GetPrimAtPath(d.GetPath()) assert masked.GetPrimAtPath(e.GetPath()) masked.SetPopulationMask(Usd.StagePopulationMask().Add(a.GetPath())) assert masked.GetPrimAtPath(a.GetPath()) assert not masked.GetPrimAtPath(b.GetPath()) assert not masked.GetPrimAtPath(c.GetPath()) assert not masked.GetPrimAtPath(d.GetPath()) assert not masked.GetPrimAtPath(e.GetPath()) # Expand with a predicate that only consults attributes named 'pred' masked.ExpandPopulationMask( attributePredicate=lambda r: r.GetName() == 'pred') assert masked.GetPrimAtPath(a.GetPath()) assert not masked.GetPrimAtPath(b.GetPath()) assert not masked.GetPrimAtPath(c.GetPath()) assert not masked.GetPrimAtPath(d.GetPath()) assert masked.GetPrimAtPath(e.GetPath())
def test_ExpansionRelationships(self): stage = Usd.Stage.CreateInMemory() a = stage.DefinePrim('/World/A') b = stage.DefinePrim('/World/B') c = stage.DefinePrim('/World/C') d = stage.DefinePrim('/World/D') e = stage.DefinePrim('/World/E') cAttr = c.CreateAttribute('attr', Sdf.ValueTypeNames.Float) a.CreateRelationship('r').AddTarget(b.GetPath()) b.CreateRelationship('r').AddTarget(cAttr.GetPath()) c.CreateRelationship('r').AddTarget(d.GetPath()) a.CreateRelationship('pred').AddTarget(e.GetPath()) mask = Usd.StagePopulationMask().Add(a.GetPath()) masked = Usd.Stage.OpenMasked(stage.GetRootLayer(), mask) assert masked.GetPrimAtPath(a.GetPath()) assert not masked.GetPrimAtPath(b.GetPath()) assert not masked.GetPrimAtPath(c.GetPath()) assert not masked.GetPrimAtPath(d.GetPath()) assert not masked.GetPrimAtPath(e.GetPath()) # Now expand the mask for all relationships. masked.ExpandPopulationMask() assert masked.GetPrimAtPath(a.GetPath()) assert masked.GetPrimAtPath(b.GetPath()) assert masked.GetPrimAtPath(c.GetPath()) assert masked.GetPrimAtPath(d.GetPath()) assert masked.GetPrimAtPath(e.GetPath()) masked.SetPopulationMask(Usd.StagePopulationMask().Add(a.GetPath())) assert masked.GetPrimAtPath(a.GetPath()) assert not masked.GetPrimAtPath(b.GetPath()) assert not masked.GetPrimAtPath(c.GetPath()) assert not masked.GetPrimAtPath(d.GetPath()) assert not masked.GetPrimAtPath(e.GetPath()) # Expand with a predicate that only consults relationships named 'pred' masked.ExpandPopulationMask( relationshipPredicate=lambda r: r.GetName() == 'pred') assert masked.GetPrimAtPath(a.GetPath()) assert not masked.GetPrimAtPath(b.GetPath()) assert not masked.GetPrimAtPath(c.GetPath()) assert not masked.GetPrimAtPath(d.GetPath()) assert masked.GetPrimAtPath(e.GetPath())
def test_Stages(self): unmasked = Usd.Stage.CreateInMemory() unmasked.DefinePrim('/World/anim/chars/DoryGroup/Dory') unmasked.DefinePrim('/World/anim/chars/NemoGroup/Nemo') unmasked.DefinePrim('/World/sets/Reef/Coral/CoralGroup1') unmasked.DefinePrim('/World/sets/Reef/Rocks/RockGroup1') doryMask = Usd.StagePopulationMask().Add('/World/anim/chars/DoryGroup') doryStage = Usd.Stage.OpenMasked(unmasked.GetRootLayer(), doryMask) assert doryStage.GetPopulationMask() == doryMask assert doryStage.GetPrimAtPath('/World') assert doryStage.GetPrimAtPath('/World/anim') assert doryStage.GetPrimAtPath('/World/anim/chars') assert doryStage.GetPrimAtPath('/World/anim/chars/DoryGroup') assert doryStage.GetPrimAtPath('/World/anim/chars/DoryGroup/Dory') assert not doryStage.GetPrimAtPath('/World/sets') assert not doryStage.GetPrimAtPath('/World/anim/chars/NemoGroup') doryAndNemoMask = (Usd.StagePopulationMask().Add( '/World/anim/chars/DoryGroup').Add('/World/anim/chars/NemoGroup')) # Test modifying an existing mask. doryStage.SetPopulationMask(doryAndNemoMask) assert doryStage.GetPrimAtPath('/World') assert doryStage.GetPrimAtPath('/World/anim') assert doryStage.GetPrimAtPath('/World/anim/chars') assert doryStage.GetPrimAtPath('/World/anim/chars/DoryGroup') assert doryStage.GetPrimAtPath('/World/anim/chars/DoryGroup/Dory') assert doryStage.GetPrimAtPath('/World/anim/chars/NemoGroup') assert doryStage.GetPrimAtPath('/World/anim/chars/NemoGroup/Nemo') doryAndNemoStage = Usd.Stage.OpenMasked(unmasked.GetRootLayer(), doryAndNemoMask) assert doryAndNemoStage.GetPopulationMask() == doryAndNemoMask assert doryAndNemoStage.GetPrimAtPath('/World') assert doryAndNemoStage.GetPrimAtPath('/World/anim') assert doryAndNemoStage.GetPrimAtPath('/World/anim/chars') assert doryAndNemoStage.GetPrimAtPath('/World/anim/chars/DoryGroup') assert doryAndNemoStage.GetPrimAtPath( '/World/anim/chars/DoryGroup/Dory') assert doryAndNemoStage.GetPrimAtPath('/World/anim/chars/NemoGroup') assert doryAndNemoStage.GetPrimAtPath( '/World/anim/chars/NemoGroup/Nemo') assert not doryAndNemoStage.GetPrimAtPath('/World/sets')
def test_Bug152904(self): # Master prims weren't being generated on stages where the population # mask included paths of prims beneath instances. stage = Usd.Stage.CreateInMemory() stage.DefinePrim('/Ref/geom') stage.DefinePrim('/Ref/shading') for path in ['/Instance_1', '/Instance_2']: prim = stage.DefinePrim(path) prim.GetReferences().AddInternalReference('/Ref') prim.SetInstanceable(True) # Open the stage with a mask that includes the 'geom' prim beneath # the instances. maskedStage = Usd.Stage.OpenMasked( stage.GetRootLayer(), Usd.StagePopulationMask(['/Instance_1/geom', '/Instance_2/geom'])) # Both instances should share the same master prim. instance_1 = maskedStage.GetPrimAtPath('/Instance_1') assert instance_1.IsInstance() assert instance_1.GetMaster() instance_2 = maskedStage.GetPrimAtPath('/Instance_2') assert instance_2.IsInstance() assert instance_2.GetMaster() # For now, all prims in masters will be composed, even if they are # not included in the population mask. assert instance_1.GetMaster() == instance_2.GetMaster() master = instance_1.GetMaster() assert master.GetChild('geom') assert master.GetChild('shading')
def PrintTree(args, path): if args.flatten: popMask = (None if args.populationMask is None else Usd.StagePopulationMask()) if popMask: for mask in args.populationMask: popMask.Add(mask) if popMask: if args.unloaded: stage = Usd.Stage.OpenMasked(path, popMask, Usd.Stage.LoadNone) else: stage = Usd.Stage.OpenMasked(path, popMask) else: if args.unloaded: stage = Usd.Stage.Open(path, Usd.Stage.LoadNone) else: stage = Usd.Stage.Open(path) PrintStage(args, stage) elif args.flattenLayerStack: from pxr import UsdUtils stage = Usd.Stage.Open(path, Usd.Stage.LoadNone) layer = UsdUtils.FlattenLayerStack(stage) PrintLayer(args, layer) else: from pxr import Sdf layer = Sdf.Layer.FindOrOpen(path) PrintLayer(args, layer)
def GetFlattenedUsdData(filePath, populationMaskPaths): from pxr import Ar, Usd Ar.GetResolver().ConfigureResolverForAsset(filePath) popMask = (None if populationMaskPaths is None else Usd.StagePopulationMask()) if popMask: for path in populationMaskPaths: popMask.Add(path) return Usd.Stage.OpenMasked(filePath, popMask) else: return Usd.Stage.Open(filePath)
def test_Bug143308(self): # We didn't correctly mask calls to parallel prim indexing, leading to # errors with instancing. stage = Usd.Stage.CreateInMemory() foo, bar, i1, i2 = [ stage.DefinePrim(p) for p in ('/foo', '/bar', '/i1', '/i2')] foo.SetInstanceable(True) [p.GetReferences().AddInternalReference(foo.GetPath()) for p in (i1, i2)] assert len(stage.GetMasters()) stage2 = Usd.Stage.OpenMasked( stage.GetRootLayer(), Usd.StagePopulationMask(['/i1'])) assert len(stage2.GetMasters())
def test_Bug145873(self): # The payload inclusion predicate wasn't being invoked on ancestors of # requested index paths in pcp. payload = Usd.Stage.CreateInMemory() for n in ('One', 'Two', 'Three'): payload.DefinePrim('/CubesModel/Geom/Cube' + n) root = Usd.Stage.CreateInMemory() cubes = root.DefinePrim('/Cubes') cubes.SetPayload(payload.GetRootLayer().identifier, '/CubesModel') testStage = Usd.Stage.OpenMasked( root.GetRootLayer(), Usd.StagePopulationMask(['/Cubes/Geom/CubeTwo'])) # Only /Cubes/Geom/CubeTwo (and ancestors) should be present. assert testStage.GetPrimAtPath('/Cubes') assert testStage.GetPrimAtPath('/Cubes/Geom') assert not testStage.GetPrimAtPath('/Cubes/Geom/CubeOne') assert testStage.GetPrimAtPath('/Cubes/Geom/CubeTwo') assert not testStage.GetPrimAtPath('/Cubes/Geom/CubeThree')
def test_Basic(self): pm = Usd.StagePopulationMask.All() assert not pm.IsEmpty() assert pm.Includes('/any/path') assert pm.GetIncludedChildNames('/') == (True, []) pm = Usd.StagePopulationMask() assert pm.IsEmpty() assert not pm.Includes('/any/path') assert pm.GetIncludedChildNames('/') == (False, []) pm2 = Usd.StagePopulationMask().Add('/foo').Add('/bar') assert not pm.Includes(pm2) assert pm2.Includes(pm) assert pm.GetUnion(pm2) == pm2 assert Usd.StagePopulationMask.Union(pm, pm2) == pm2 assert pm2.GetIncludedChildNames('/') == (True, ['bar', 'foo']) assert pm2.GetIncludedChildNames('/foo') == (True, []) assert pm2.GetIncludedChildNames('/bar') == (True, []) assert pm2.GetIncludedChildNames('/baz') == (False, []) pm.Add('/World/anim/chars/CharGroup') assert pm.GetPaths() == ['/World/anim/chars/CharGroup'] assert not pm.IsEmpty() pm.Add('/World/anim/chars/CharGroup/child') assert pm.GetPaths() == ['/World/anim/chars/CharGroup'] pm.Add('/World/anim/chars/OtherCharGroup') assert pm.GetPaths() == ['/World/anim/chars/CharGroup', '/World/anim/chars/OtherCharGroup'] pm.Add('/World/sets/arch/Building') assert pm.GetPaths() == ['/World/anim/chars/CharGroup', '/World/anim/chars/OtherCharGroup', '/World/sets/arch/Building'] pm2 = Usd.StagePopulationMask() assert pm2 != pm pm2.Add('/World/anim/chars/CharGroup') assert pm2 != pm pm2.Add('/World/sets/arch/Building') pm2.Add('/World/anim/chars/OtherCharGroup') pm2.Add('/World/anim/chars/CharGroup/child') assert pm2 == pm assert pm2.GetUnion(pm) == pm assert pm2.GetUnion(pm) == pm2 pm2 = Usd.StagePopulationMask() assert Usd.StagePopulationMask.Union(pm, pm2) == pm assert Usd.StagePopulationMask.Union(pm, pm2) != pm2 assert pm.Includes('/World') assert not pm.IncludesSubtree('/World') assert pm.Includes('/World/anim') assert not pm.IncludesSubtree('/World/anim') assert pm.Includes('/World/anim/chars/CharGroup') assert pm.IncludesSubtree('/World/anim/chars/CharGroup') assert pm.Includes('/World/anim/chars/CharGroup/child') assert pm.IncludesSubtree('/World/anim/chars/CharGroup/child') pm = Usd.StagePopulationMask().Add('/world/anim') pm2 = pm.GetUnion('/world') assert pm2.GetPaths() == ['/world'] pm = Usd.StagePopulationMask(['/A', '/AA', '/B/C', '/U']) pm2 = Usd.StagePopulationMask(['/A/X', '/B', '/Q']) assert (Usd.StagePopulationMask.Union(pm, pm2) == Usd.StagePopulationMask(['/A', '/AA', '/B', '/Q', '/U'])) assert (Usd.StagePopulationMask.Intersection(pm, pm2) == Usd.StagePopulationMask(['/A/X', '/B/C'])) pm = Usd.StagePopulationMask(['/A/B', '/A/C', '/A/D/E', '/A/D/F', '/B']) assert pm.GetIncludedChildNames('/') == (True, ['A', 'B']) assert pm.GetIncludedChildNames('/A') == (True, ['B', 'C', 'D']) assert pm.GetIncludedChildNames('/A/B') == (True, []) assert pm.GetIncludedChildNames('/A/C') == (True, []) assert pm.GetIncludedChildNames('/A/D') == (True, ['E', 'F']) assert pm.GetIncludedChildNames('/A/D/E') == (True, []) assert pm.GetIncludedChildNames('/A/D/F') == (True, []) assert pm.GetIncludedChildNames('/B') == (True, []) assert pm.GetIncludedChildNames('/C') == (False, []) # Errors. with self.assertRaises(Tf.ErrorException): Usd.StagePopulationMask(['relativePath/is/no/good']) with self.assertRaises(Tf.ErrorException): Usd.StagePopulationMask().Add('relativePath/is/no/good') with self.assertRaises(Tf.ErrorException): Usd.StagePopulationMask(['/property/path/is/no.good']) with self.assertRaises(Tf.ErrorException): Usd.StagePopulationMask().Add('/property/path/is/no.good') with self.assertRaises(Tf.ErrorException): Usd.StagePopulationMask(['/variant/selection/path/is{no=good}']) with self.assertRaises(Tf.ErrorException): Usd.StagePopulationMask().Add('/variant/selection/path/is{no=good}')
def test_USD_5709(self): # Population masks with paths descendant to instances were not working # correctly, since we incorrectly applied the mask to the _master_ prim # paths when populating master prim hierarchies. This test ensures that # masks with paths descendant to instances work as expected. from pxr import Usd, Sdf l = Sdf.Layer.CreateAnonymous('.usda') l.ImportFromString('''#usda 1.0 def Sphere "test" { def Scope "scope1" {} def Scope "scope2" {} def Scope "scope3" {} } def Scope "Model" ( instanceable = True payload = </test> ) { } def "M1" ( append references = </Model> ) { } def "M2" ( append references = </Model> ) { } def "M3" ( append references = </Model> ) { } def Scope "Nested" (instanceable = True) { def "M1" ( append references = </Model> ) {} def "M2" ( append references = </Model> ) {} def "M3" ( append references = </Model> ) {} } def "N1" (append references = </Nested>) { } def "N2" (append references = </Nested>) { } def "N3" (append references = </Nested>) { } ''') ######################################################################## # Non-nested instancing s = Usd.Stage.OpenMasked(l, mask=Usd.StagePopulationMask(['/M1/scope2'])) self.assertFalse(s.GetPrimAtPath('/M1/scope1')) self.assertTrue(s.GetPrimAtPath('/M1/scope2')) self.assertFalse(s.GetPrimAtPath('/M1/scope3')) s = Usd.Stage.OpenMasked(l, mask=Usd.StagePopulationMask( ['/M1/scope2', '/M3'])) self.assertFalse(s.GetPrimAtPath('/M1/scope1')) self.assertTrue(s.GetPrimAtPath('/M1/scope2')) self.assertFalse(s.GetPrimAtPath('/M1/scope3')) self.assertTrue(s.GetPrimAtPath('/M3/scope1')) self.assertTrue(s.GetPrimAtPath('/M3/scope2')) self.assertTrue(s.GetPrimAtPath('/M3/scope3')) s = Usd.Stage.OpenMasked(l, mask=Usd.StagePopulationMask( ['/M1/scope2', '/M3/scope2'])) self.assertFalse(s.GetPrimAtPath('/M1/scope1')) self.assertTrue(s.GetPrimAtPath('/M1/scope2')) self.assertFalse(s.GetPrimAtPath('/M1/scope3')) self.assertFalse(s.GetPrimAtPath('/M3/scope1')) self.assertTrue(s.GetPrimAtPath('/M3/scope2')) self.assertFalse(s.GetPrimAtPath('/M3/scope3')) s = Usd.Stage.OpenMasked(l, mask=Usd.StagePopulationMask(['/M1/scope2']), load=Usd.Stage.LoadNone) self.assertFalse(s.GetPrimAtPath('/M1/scope2')) s.Load('/M1') self.assertFalse(s.GetPrimAtPath('/M1/scope1')) self.assertTrue(s.GetPrimAtPath('/M1/scope2')) self.assertFalse(s.GetPrimAtPath('/M1/scope3')) s = Usd.Stage.OpenMasked(l, mask=Usd.StagePopulationMask( ['/M1/scope2', '/M3']), load=Usd.Stage.LoadNone) self.assertFalse(s.GetPrimAtPath('/M1/scope2')) self.assertFalse(s.GetPrimAtPath('/M3/scope1')) s.Load('/M1') s.Load('/M3') self.assertFalse(s.GetPrimAtPath('/M1/scope1')) self.assertTrue(s.GetPrimAtPath('/M1/scope2')) self.assertFalse(s.GetPrimAtPath('/M1/scope3')) self.assertTrue(s.GetPrimAtPath('/M3/scope1')) self.assertTrue(s.GetPrimAtPath('/M3/scope2')) self.assertTrue(s.GetPrimAtPath('/M3/scope3')) s = Usd.Stage.OpenMasked(l, mask=Usd.StagePopulationMask( ['/M1/scope2', '/M3/scope2']), load=Usd.Stage.LoadNone) self.assertFalse(s.GetPrimAtPath('/M1/scope2')) self.assertFalse(s.GetPrimAtPath('/M3/scope2')) s.Load('/M1') s.Load('/M3') self.assertFalse(s.GetPrimAtPath('/M1/scope1')) self.assertTrue(s.GetPrimAtPath('/M1/scope2')) self.assertFalse(s.GetPrimAtPath('/M1/scope3')) self.assertFalse(s.GetPrimAtPath('/M3/scope1')) self.assertTrue(s.GetPrimAtPath('/M3/scope2')) self.assertFalse(s.GetPrimAtPath('/M3/scope3')) ######################################################################## # Nested instancing s = Usd.Stage.OpenMasked(l, mask=Usd.StagePopulationMask( ['/N1/M1/scope2'])) self.assertFalse(s.GetPrimAtPath('/N1/M1/scope1')) self.assertTrue(s.GetPrimAtPath('/N1/M1/scope2')) self.assertFalse(s.GetPrimAtPath('/N1/M1/scope3')) s = Usd.Stage.OpenMasked(l, mask=Usd.StagePopulationMask( ['/N1/M1/scope2', '/N3/M3'])) self.assertFalse(s.GetPrimAtPath('/N1/M1/scope1')) self.assertTrue(s.GetPrimAtPath('/N1/M1/scope2')) self.assertFalse(s.GetPrimAtPath('/N1/M1/scope3')) self.assertTrue(s.GetPrimAtPath('/N3/M3/scope1')) self.assertTrue(s.GetPrimAtPath('/N3/M3/scope2')) self.assertTrue(s.GetPrimAtPath('/N3/M3/scope3')) s = Usd.Stage.OpenMasked(l, mask=Usd.StagePopulationMask( ['/N1/M1/scope2', '/N3/M3/scope2'])) self.assertFalse(s.GetPrimAtPath('/N1/M1/scope1')) self.assertTrue(s.GetPrimAtPath('/N1/M1/scope2')) self.assertFalse(s.GetPrimAtPath('/N1/M1/scope3')) self.assertFalse(s.GetPrimAtPath('/N3/M3/scope1')) self.assertTrue(s.GetPrimAtPath('/N3/M3/scope2')) self.assertFalse(s.GetPrimAtPath('/N3/M3/scope3')) s = Usd.Stage.OpenMasked(l, mask=Usd.StagePopulationMask( ['/N1/M1/scope2']), load=Usd.Stage.LoadNone) self.assertFalse(s.GetPrimAtPath('/N1/M1/scope2')) s.Load('/N1/M1') self.assertFalse(s.GetPrimAtPath('/N1/M1/scope1')) self.assertTrue(s.GetPrimAtPath('/N1/M1/scope2')) self.assertFalse(s.GetPrimAtPath('/N1/M1/scope3')) s = Usd.Stage.OpenMasked(l, mask=Usd.StagePopulationMask( ['/N1/M1/scope2', '/N3/M3']), load=Usd.Stage.LoadNone) self.assertFalse(s.GetPrimAtPath('/N1/M1/scope2')) self.assertFalse(s.GetPrimAtPath('/N3/M3/scope1')) s.Load('/N1/M1') s.Load('/N3/M3') self.assertFalse(s.GetPrimAtPath('/N1/M1/scope1')) self.assertTrue(s.GetPrimAtPath('/N1/M1/scope2')) self.assertFalse(s.GetPrimAtPath('/N1/M1/scope3')) self.assertTrue(s.GetPrimAtPath('/N3/M3/scope1')) self.assertTrue(s.GetPrimAtPath('/N3/M3/scope2')) self.assertTrue(s.GetPrimAtPath('/N3/M3/scope3')) s = Usd.Stage.OpenMasked(l, mask=Usd.StagePopulationMask( ['/N1/M1/scope2', '/N3/M3/scope2']), load=Usd.Stage.LoadNone) self.assertFalse(s.GetPrimAtPath('/N1/M1/scope2')) self.assertFalse(s.GetPrimAtPath('/N3/M3/scope2')) s.Load('/N1/M1') s.Load('/N3/M3') self.assertFalse(s.GetPrimAtPath('/N1/M1/scope1')) self.assertTrue(s.GetPrimAtPath('/N1/M1/scope2')) self.assertFalse(s.GetPrimAtPath('/N1/M1/scope3')) self.assertFalse(s.GetPrimAtPath('/N3/M3/scope1')) self.assertTrue(s.GetPrimAtPath('/N3/M3/scope2')) self.assertFalse(s.GetPrimAtPath('/N3/M3/scope3')) ######################################################################## # Nested instancing again s = Usd.Stage.OpenMasked(l, mask=Usd.StagePopulationMask( ['/N1/M1/scope2'])) self.assertFalse(s.GetPrimAtPath('/N1/M1/scope1')) self.assertTrue(s.GetPrimAtPath('/N1/M1/scope2')) self.assertFalse(s.GetPrimAtPath('/N1/M1/scope3')) s = Usd.Stage.OpenMasked(l, mask=Usd.StagePopulationMask( ['/N1/M1/scope2', '/N3/M1'])) self.assertFalse(s.GetPrimAtPath('/N1/M1/scope1')) self.assertTrue(s.GetPrimAtPath('/N1/M1/scope2')) self.assertFalse(s.GetPrimAtPath('/N1/M1/scope3')) self.assertTrue(s.GetPrimAtPath('/N3/M1/scope1')) self.assertTrue(s.GetPrimAtPath('/N3/M1/scope2')) self.assertTrue(s.GetPrimAtPath('/N3/M1/scope3')) s = Usd.Stage.OpenMasked(l, mask=Usd.StagePopulationMask( ['/N1/M1/scope2', '/N3/M1/scope2'])) self.assertFalse(s.GetPrimAtPath('/N1/M1/scope1')) self.assertTrue(s.GetPrimAtPath('/N1/M1/scope2')) self.assertFalse(s.GetPrimAtPath('/N1/M1/scope3')) self.assertFalse(s.GetPrimAtPath('/N3/M1/scope1')) self.assertTrue(s.GetPrimAtPath('/N3/M1/scope2')) self.assertFalse(s.GetPrimAtPath('/N3/M1/scope3')) s = Usd.Stage.OpenMasked(l, mask=Usd.StagePopulationMask( ['/N1/M1/scope2']), load=Usd.Stage.LoadNone) self.assertFalse(s.GetPrimAtPath('/N1/M1/scope2')) s.Load('/N1/M1') self.assertFalse(s.GetPrimAtPath('/N1/M1/scope1')) self.assertTrue(s.GetPrimAtPath('/N1/M1/scope2')) self.assertFalse(s.GetPrimAtPath('/N1/M1/scope3')) s = Usd.Stage.OpenMasked(l, mask=Usd.StagePopulationMask( ['/N1/M1/scope2', '/N3/M1']), load=Usd.Stage.LoadNone) self.assertFalse(s.GetPrimAtPath('/N1/M1/scope2')) self.assertFalse(s.GetPrimAtPath('/N3/M1/scope1')) s.Load('/N1/M1') s.Load('/N3/M1') self.assertFalse(s.GetPrimAtPath('/N1/M1/scope1')) self.assertTrue(s.GetPrimAtPath('/N1/M1/scope2')) self.assertFalse(s.GetPrimAtPath('/N1/M1/scope3')) self.assertTrue(s.GetPrimAtPath('/N3/M1/scope1')) self.assertTrue(s.GetPrimAtPath('/N3/M1/scope2')) self.assertTrue(s.GetPrimAtPath('/N3/M1/scope3')) s = Usd.Stage.OpenMasked(l, mask=Usd.StagePopulationMask( ['/N1/M1/scope2', '/N3/M1/scope2']), load=Usd.Stage.LoadNone) self.assertFalse(s.GetPrimAtPath('/N1/M1/scope2')) self.assertFalse(s.GetPrimAtPath('/N3/M1/scope2')) s.Load('/N1/M1') s.Load('/N3/M1') self.assertFalse(s.GetPrimAtPath('/N1/M1/scope1')) self.assertTrue(s.GetPrimAtPath('/N1/M1/scope2')) self.assertFalse(s.GetPrimAtPath('/N1/M1/scope3')) self.assertFalse(s.GetPrimAtPath('/N3/M1/scope1')) self.assertTrue(s.GetPrimAtPath('/N3/M1/scope2')) self.assertFalse(s.GetPrimAtPath('/N3/M1/scope3'))
def test_160884(self): # Test that opening a stage that has a mask pointing beneath an instance # doesn't crash. from pxr import Usd, Sdf import random allFormats = ['usd' + x for x in 'ac'] for fmt in allFormats: l = Sdf.Layer.CreateAnonymous('_bug160884.' + fmt) l.ImportFromString('''#usda 1.0 ( endTimeCode = 150 startTimeCode = 100 upAxis = "Y" ) def Sphere "test" { def Scope "scope1" {} def Scope "scope2" {} def Scope "scope3" {} def Scope "scope4" {} def Scope "scope5" {} def Scope "scope6" {} def Scope "scope7" {} def Scope "scope8" {} def Scope "scope9" {} def Scope "scope10" {} def Scope "scope11" {} def Scope "scope12" {} def Scope "scope13" {} def Scope "scope14" {} def Scope "scope15" {} def Scope "scope16" {} def Scope "scope17" {} def Scope "scope18" {} def Scope "scope19" {} def Scope "scope20" {} } def Scope "Location" { def "asset1" ( instanceable = True add references = </test> ) { } def "asset2" ( add references = </test> ) { } } def Scope "Loc1" ( instanceable = True add references = </Location> ) { } def Scope "Loc2" ( add references = </Location> ) { } ''') for i in range(1024): stage = Usd.Stage.OpenMasked( l, Usd.StagePopulationMask([ '/Loc%s/asset1/scope%s' % (str(random.randint(1, 20)), str(random.randint(1, 2))) ]))
def main(): programName = os.path.basename(sys.argv[0]) parser = argparse.ArgumentParser( prog=programName, description='Generates images from a USD file') # Positional (required) arguments. parser.add_argument('usdFilePath', action='store', type=str, help='USD file to record') parser.add_argument( 'outputImagePath', action='store', type=str, help=('Output image path. For frame ranges, the path must contain ' 'exactly one frame number placeholder of the form "###" or ' '"###.###". Note that the number of hash marks is variable in ' 'each group.')) # Optional arguments. parser.add_argument( '--mask', action='store', type=str, dest='populationMask', metavar='PRIMPATH[,PRIMPATH...]', help=( 'Limit stage population to these prims, their descendants and ' 'ancestors. To specify multiple paths, either use commas with no ' 'spaces or quote the argument and separate paths by commas and/or ' 'spaces.')) parser.add_argument( '--purposes', action='store', type=str, dest='purposes', metavar='PURPOSE[,PURPOSE...]', default='proxy', help=( 'Specify which UsdGeomImageable purposes should be included ' 'in the renders. The "default" purpose is automatically included, ' 'so you need specify only the *additional* purposes. If you want ' 'more than one extra purpose, either use commas with no spaces or ' 'quote the argument and separate purposes by commas and/or spaces.' )) UsdAppUtils.cameraArgs.AddCmdlineArgs(parser) UsdAppUtils.framesArgs.AddCmdlineArgs(parser) UsdAppUtils.complexityArgs.AddCmdlineArgs(parser) UsdAppUtils.colorArgs.AddCmdlineArgs(parser) UsdAppUtils.rendererArgs.AddCmdlineArgs(parser) parser.add_argument( '--imageWidth', '-w', action='store', type=int, default=960, help=( 'Width of the output image. The height will be computed from this ' 'value and the camera\'s aspect ratio (default=%(default)s)')) args = parser.parse_args() UsdAppUtils.framesArgs.ValidateCmdlineArgs( parser, args, frameFormatArgName='outputImagePath') args.imageWidth = max(args.imageWidth, 1) purposes = args.purposes.replace(',', ' ').split() # Open the USD stage, using a population mask if paths were given. if args.populationMask: populationMaskPaths = args.populationMask.replace(',', ' ').split() populationMask = Usd.StagePopulationMask() for maskPath in populationMaskPaths: populationMask.Add(maskPath) usdStage = Usd.Stage.OpenMasked(args.usdFilePath, populationMask) else: usdStage = Usd.Stage.Open(args.usdFilePath) if not usdStage: _Err('Could not open USD stage: %s' % args.usdFilePath) return 1 # Get the camera at the given path (or with the given name). usdCamera = UsdAppUtils.GetCameraAtPath(usdStage, args.camera) # Frame-independent initialization. # Note that the size of the widget doesn't actually affect the size of the # output image. We just pass it along for cleanliness. glWidget = _SetupOpenGLContext(args.imageWidth, args.imageWidth) frameRecorder = UsdAppUtils.FrameRecorder() if args.rendererPlugin: frameRecorder.SetRendererPlugin(args.rendererPlugin.id) frameRecorder.SetImageWidth(args.imageWidth) frameRecorder.SetComplexity(args.complexity.value) frameRecorder.SetColorCorrectionMode(args.colorCorrectionMode) frameRecorder.SetIncludedPurposes(purposes) _Msg('Camera: %s' % usdCamera.GetPath().pathString) _Msg('Renderer plugin: %s' % frameRecorder.GetCurrentRendererId()) for timeCode in args.frames: _Msg('Recording time code: %s' % timeCode) outputImagePath = args.outputImagePath.format( frame=timeCode.GetValue()) try: frameRecorder.Record(usdStage, usdCamera, timeCode, outputImagePath) except Tf.ErrorException as e: _Err("Recording aborted due to the following failure at time code " "{0}: {1}".format(timeCode, str(e))) break # Release our reference to the frame recorder so it can be deleted before # the Qt stuff. frameRecorder = None
from pxr import Usd stage = Usd.Stage.OpenMasked('scene.usda', Usd.StagePopulationMask(['/Scene/asset1/mesh_0'])) print "OpenMasked successful"
from pxr import Usd stage = Usd.Stage.OpenMasked('scene.usda', Usd.StagePopulationMask(['/Scene/asset2/mesh_0'])) print "OpenMasked successful"
def test_Bug152904(self): # Prototype prims weren't being generated on stages where the population # mask included paths of prims beneath instances. stage = Usd.Stage.CreateInMemory() stage.DefinePrim('/Ref/geom') stage.DefinePrim('/Ref/shading') for path in ['/Instance_1', '/Instance_2']: prim = stage.DefinePrim(path) prim.GetReferences().AddInternalReference('/Ref') prim.SetInstanceable(True) # Open the stage with a mask that includes the 'geom' prim beneath # the instances. maskedStage = Usd.Stage.OpenMasked( stage.GetRootLayer(), Usd.StagePopulationMask(['/Instance_1/geom', '/Instance_2/geom'])) # Both instances should share the same prototype prim. instance_1 = maskedStage.GetPrimAtPath('/Instance_1') assert instance_1.IsInstance() assert instance_1.GetPrototype() instance_2 = maskedStage.GetPrimAtPath('/Instance_2') assert instance_2.IsInstance() assert instance_2.GetPrototype() # Only the 'geom' prim in the prototype will be composed, since # it's the only one in the population mask. assert instance_1.GetPrototype() == instance_2.GetPrototype() prototype = instance_1.GetPrototype() assert prototype.GetChild('geom') assert not prototype.GetChild('shading') # Open the stage with a mask that includes the 'geom' prim beneath # /Instance_1 and all children beneath /Instance_2. maskedStage = Usd.Stage.OpenMasked( stage.GetRootLayer(), Usd.StagePopulationMask(['/Instance_1/geom', '/Instance_2'])) # Both instances should *not* share the same prototype, since they # are affected by different population masks. instance_1 = maskedStage.GetPrimAtPath('/Instance_1') assert instance_1.IsInstance() assert instance_1.GetPrototype() instance_2 = maskedStage.GetPrimAtPath('/Instance_2') assert instance_2.IsInstance() assert instance_2.GetPrototype() # Only the 'geom' prim will be composed in the prototype for the # /Instance_1, but both 'geom' and 'shading' will be composed for # /Instance_2. assert instance_1.GetPrototype() != instance_2.GetPrototype() prototype = instance_1.GetPrototype() assert prototype.GetChild('geom') assert not prototype.GetChild('shading') prototype = instance_2.GetPrototype() assert prototype.GetChild('geom') assert prototype.GetChild('shading')