def test_USD_4712(self): # Test that activating a prim auto-includes payloads of new descendants # if the ancestors' payloads were already included. from pxr import Usd, Sdf l1 = Sdf.Layer.CreateAnonymous('.usd') l1.ImportFromString('''#usda 1.0 ( defaultPrim = "shot" ) def "shot" { def "camera" { def "cache"( active = false ){ def "cam" { } } } } def "cam_extra" { def "cache_payload" {} } def "cam" { def "cam_payload" {} }''') l2 = Sdf.Layer.CreateAnonymous() Sdf.CreatePrimInLayer(l2, '/cam_extra').specifier = Sdf.SpecifierDef Sdf.CreatePrimInLayer( l2, '/cam_extra/cache_payload').specifier = Sdf.SpecifierDef Sdf.CreatePrimInLayer(l2, '/cam').specifier = Sdf.SpecifierDef Sdf.CreatePrimInLayer(l2, '/cam/cam_payload').specifier = Sdf.SpecifierDef l1.GetPrimAtPath('/shot/camera/cache').payloadList.Prepend( Sdf.Payload(l2.identifier, '/cam_extra')) l1.GetPrimAtPath('/shot/camera/cache/cam').payloadList.Prepend( Sdf.Payload(l2.identifier, '/cam')) stage = Usd.Stage.Open(l1) stage.SetEditTarget(stage.GetSessionLayer()) cachePrim = stage.GetPrimAtPath('/shot/camera/cache') # Activating the cachePrim should auto-load the cam payload since its # nearest loadable ancestor is loaded. cachePrim.SetActive(True) cachePayloadPrim = stage.GetPrimAtPath( '/shot/camera/cache/cache_payload') self.assertTrue(cachePayloadPrim.IsValid()) cameraPayloadPrim = stage.GetPrimAtPath( '/shot/camera/cache/cam/cam_payload') self.assertTrue(cameraPayloadPrim.IsValid())
def test_156222(self): from pxr import Sdf, Usd # Test that removing all instances for a master prim and adding a new # instance with the same instancing key as the master causes the new # instance to be assigned to the master. l = Sdf.Layer.CreateAnonymous('.usda') Sdf.CreatePrimInLayer(l, '/Ref') # The bug is non-deterministic because of threaded composition, # but it's easier to reproduce with more instance prims. numInstancePrims = 50 instancePrimPaths = [ Sdf.Path('/Instance_{}'.format(i)) for i in xrange(numInstancePrims) ] for path in instancePrimPaths: instancePrim = Sdf.CreatePrimInLayer(l, path) instancePrim.instanceable = True instancePrim.referenceList.Add(Sdf.Reference(primPath='/Ref')) nonInstancePrim = Sdf.CreatePrimInLayer(l, '/NonInstance') nonInstancePrim.referenceList.Add(Sdf.Reference(primPath='/Ref')) s = Usd.Stage.Open(l) self.assertEqual(len(s.GetMasters()), 1) # Check that the master prim is using one of the instanceable prim # index for its source. master = s.GetMasters()[0] masterPath = master.GetPath() self.assertIn(master._GetSourcePrimIndex().rootNode.path, instancePrimPaths) # In a single change block, uninstance all of the instanceable prims, # but mark the non-instance prim as instanceable. with Sdf.ChangeBlock(): for path in instancePrimPaths: l.GetPrimAtPath(path).instanceable = False nonInstancePrim.instanceable = True # This should not cause a new master prim to be generated; instead, # the master prim should now be using the newly-instanced prim index # as its source. master = s.GetMasters()[0] self.assertEqual(master.GetPath(), masterPath) self.assertEqual(master._GetSourcePrimIndex().rootNode.path, nonInstancePrim.path)
def test_153956(self): from pixar import Sdf # Create a crate-backed .usd file and populate it with an # attribute connection. These files do not store specs for # targets/connections, so there will be an entry in the # connectionChildren list but no corresponding spec. layer = Sdf.Layer.CreateAnonymous(".usd") primSpec = Sdf.CreatePrimInLayer(layer, "/Test") attrSpec = Sdf.AttributeSpec(primSpec, "attr", Sdf.ValueTypeNames.Float) # -- Adding item to prependedItems list..." attrSpec.connectionPathList.prependedItems.append( "/Test.prependedItem") # Transfer the contents of the crate-backed .usd file into an # memory-backed .usda file. These file *do* store specs for # targets/connections. newLayer = Sdf.Layer.CreateAnonymous(".usda") newLayer.TransferContent(layer) primSpec = newLayer.GetPrimAtPath("/Test") attrSpec = primSpec.properties["attr"] # Adding an item to the explicitItems list changes to listOp to # explicit mode, but does not clear any existing connectionChildren. attrSpec.connectionPathList.explicitItems.append("/Test.explicitItem") # Prior to the fix, this caused a failed verify b/c an entry exists in # the connectionChildren list for which there is no corresponding spec. primSpec.name = "Test2"
def test_141718(self): from pxr import Sdf crateLayer = Sdf.Layer.CreateAnonymous('.usdc') prim = Sdf.CreatePrimInLayer(crateLayer, '/Prim') rel = Sdf.RelationshipSpec(prim, 'myRel', custom=False) rel.targetPathList.explicitItems.append('/Prim2') asciiLayer = Sdf.Layer.CreateAnonymous('.usda') asciiLayer.TransferContent(crateLayer) p = asciiLayer.GetPrimAtPath('/Prim') p.RemoveProperty(p.relationships['myRel'])
def test_USD_5196(self): from pxr import Usd, Sdf, Vt, Tf import os, random # Test that usdc files corrupted by truncation (such that the table of # contents is past the end of the file) are detected and fail to open # with an error. with Tf.NamedTemporaryFile(suffix=".usdc") as f: layer = Sdf.Layer.CreateNew(f.name) foo = Sdf.CreatePrimInLayer(layer, '/foo') attr = Sdf.AttributeSpec(foo, 'attr', Sdf.ValueTypeNames.IntArray) ints = range(1024**2) random.shuffle(ints) attr.default = Vt.IntArray(ints) layer.Save() del layer # Now truncate layer to corrupt it. fobj = open(f.name, "rw+") size = os.path.getsize(f.name) fobj.truncate(size / 2) fobj.close() # Attempting to open the file should raise an exception. with self.assertRaises(Tf.ErrorException): layer = Sdf.Layer.FindOrOpen(f.name)
def test_155392(self): from pxr import Sdf, Usd # Usd should maintain load state across instancing changes. l1 = Sdf.Layer.CreateAnonymous('.usda') l2 = Sdf.Layer.CreateAnonymous('.usda') xpay = Sdf.CreatePrimInLayer(l2, '/xpay') ypay = Sdf.CreatePrimInLayer(l2, '/ypay') p1 = Sdf.CreatePrimInLayer(l1, '/p1') p1.specifier = Sdf.SpecifierDef p1.referenceList.Add(Sdf.Reference('', '/x')) p2 = Sdf.CreatePrimInLayer(l1, '/p2') p2.specifier = Sdf.SpecifierDef p2.referenceList.Add(Sdf.Reference('', '/x')) x = Sdf.CreatePrimInLayer(l1, '/x') x.instanceable = True x.specifier = Sdf.SpecifierDef x.payloadList.explicitItems.append(Sdf.Payload(l2.identifier, '/xpay')) y = Sdf.CreatePrimInLayer(l1, '/x/y') y.specifier = Sdf.SpecifierDef x.payloadList.explicitItems.append(Sdf.Payload(l2.identifier, '/ypay')) s = Usd.Stage.Open(l1, Usd.Stage.LoadAll) self.assertTrue( all([ x.IsLoaded() for x in [ s.GetPrimAtPath('/p1'), s.GetPrimAtPath('/p1/y'), s.GetPrimAtPath('/p2'), s.GetPrimAtPath('/p2/y') ] ])) # Now uninstance, and assert that load state is preserved. s.GetPrimAtPath('/p2').SetInstanceable(False) self.assertTrue( all([ x.IsLoaded() for x in [ s.GetPrimAtPath('/p1'), s.GetPrimAtPath('/p1/y'), s.GetPrimAtPath('/p2'), s.GetPrimAtPath('/p2/y') ] ])) # Reinstance /p2 for next test. s.GetPrimAtPath('/p2').SetInstanceable(True) self.assertTrue( all([ x.IsLoaded() for x in [ s.GetPrimAtPath('/p1'), s.GetPrimAtPath('/p1/y'), s.GetPrimAtPath('/p2'), s.GetPrimAtPath('/p2/y') ] ])) # Now do the same but nested-instance everything. l3 = Sdf.Layer.CreateAnonymous('.usda') l3.comment = 'l3' outer = Sdf.CreatePrimInLayer(l3, '/outer') outer.specifier = Sdf.SpecifierDef outer.instanceable = True outerc = Sdf.CreatePrimInLayer(l3, '/outer/c') outerc.specifier = Sdf.SpecifierDef outerc.referenceList.Add(Sdf.Reference(l1.identifier, '/p1')) i1 = Sdf.CreatePrimInLayer(l3, '/i1') i1.specifier = Sdf.SpecifierDef i1.referenceList.Add(Sdf.Reference('', '/outer')) i2 = Sdf.CreatePrimInLayer(l3, '/i2') i2.specifier = Sdf.SpecifierDef i2.referenceList.Add(Sdf.Reference('', '/outer')) s2 = Usd.Stage.Open(l3, Usd.Stage.LoadAll) self.assertTrue( all([ x.IsLoaded() for x in [ s2.GetPrimAtPath('/i1'), s2.GetPrimAtPath('/i1/c'), s2.GetPrimAtPath('/i1/c/y'), s2.GetPrimAtPath('/i2'), s2.GetPrimAtPath('/i2/c'), s2.GetPrimAtPath('/i2/c/y') ] ])) # Uninstance outer. s2.GetPrimAtPath('/i1').SetInstanceable(False) self.assertTrue( all([ x.IsLoaded() for x in [ s2.GetPrimAtPath('/i1'), s2.GetPrimAtPath('/i1/c'), s2.GetPrimAtPath('/i1/c/y'), s2.GetPrimAtPath('/i2'), s2.GetPrimAtPath('/i2/c'), s2.GetPrimAtPath('/i2/c/y') ] ])) # Uninstance inner. s2.GetPrimAtPath('/i1/c').SetInstanceable(False) self.assertTrue( all([ x.IsLoaded() for x in [ s2.GetPrimAtPath('/i1'), s2.GetPrimAtPath('/i1/c'), s2.GetPrimAtPath('/i1/c/y'), s2.GetPrimAtPath('/i2'), s2.GetPrimAtPath('/i2/c'), s2.GetPrimAtPath('/i2/c/y') ] ]))