def main(): """Run the main execution of this module.""" stage = Usd.Stage.CreateInMemory() stage.SetStartTimeCode(0) stage.SetEndTimeCode(2) prim = stage.DefinePrim("/Set") non_template_set_name = "non_template_clips" model = Usd.ClipsAPI(prim) model.SetClipActive([(0.0, 0)], non_template_set_name) model.SetClipAssetPaths( [Sdf.AssetPath("./non_template_clip.usda")], non_template_set_name ) model.SetClipPrimPath("/NonTemplate", non_template_set_name) template_set_name = "template_clips" model.SetClipTemplateAssetPath("./template_clip.##.usda", template_set_name) model.SetClipTemplateEndTime(2, template_set_name) model.SetClipTemplateStartTime(0, template_set_name) model.SetClipTemplateStride(1, template_set_name) model.SetClipPrimPath("/Template", template_set_name) prim.GetReferences().AddReference(assetPath="./set.usda", primPath="/Set") print(stage.GetRootLayer().ExportToString())
def test_ComputeAllDependenciesInvalidClipTemplate(self): """Test that an invalid clip template asset path does not cause an exception in UsdUtils.ComputeAllDependencies.""" stage = Usd.Stage.CreateNew('testInvalidClipTemplate.usda') prim = stage.DefinePrim('/clip') Usd.ClipsAPI(prim).SetClipTemplateAssetPath('bogus') stage.Save() UsdUtils.ComputeAllDependencies(stage.GetRootLayer().identifier)
def main(): """Run the main execution of this module.""" stage = Usd.Stage.CreateInMemory() stage.SetStartTimeCode(0) stage.SetEndTimeCode(12) prim = stage.DefinePrim("/Prim") model = Usd.ClipsAPI(prim) model.SetClipActive([(0, 0), (2, 1)]) model.SetClipAssetPaths( [Sdf.AssetPath("./clip_1.usda"), Sdf.AssetPath("./clip_2.usda")]) model.SetClipPrimPath("/Clip") model.SetClipTimes([(0, 0), (1, 1), (2, 0), (3, 1)]) model.SetClipManifestAssetPath("./clip_manifest.usda") prim.GetReferences().AddReference(assetPath="./ref.usda", primPath="/Ref") print(stage.GetRootLayer().ExportToString())
def test_GetPropertyStackWithClips(self): clipPath = '/root/fx/test' attrName = 'extent' fullPath = clipPath + '.' + attrName for fmt in allFormats: clipA = Sdf.Layer.CreateNew('clipA.' + fmt) clipB = Sdf.Layer.CreateNew('clipB.' + fmt) clipC = Sdf.Layer.CreateNew('clipC.' + fmt) clips = [clipA, clipB, clipC] clipTime = 102.0 for c in clips: stage = Usd.Stage.Open(c.identifier) prim = stage.DefinePrim(clipPath) attr = prim.CreateAttribute('extent', Sdf.ValueTypeNames.Double) attr.Set(clipTime, clipTime) stage.SetStartTimeCode(clipTime) clipTime += 1.0 stage.SetEndTimeCode(clipTime) # Generate our necessary topology layer topologyLayer = Sdf.Layer.CreateNew('root.topology.' + fmt) stage = Usd.Stage.Open(topologyLayer) prim = stage.DefinePrim(clipPath) prim.CreateAttribute(attrName, Sdf.ValueTypeNames.Double) # Generate our necessary clip metadata root = Sdf.Layer.CreateNew('root.' + fmt) stage = Usd.Stage.Open(root) prim = stage.DefinePrim(clipPath) clipPrim = Usd.ClipsAPI(prim) clipPrim.SetClipAssetPaths( [Sdf.AssetPath(c.identifier) for c in clips]) clipPrim.SetClipPrimPath(clipPath) clipPrim.SetClipManifestAssetPath('root.topology.' + fmt) # Add a reference to our topology layer rootPath = Sdf.Path('/root') rootPrim = stage.GetPrimAtPath(rootPath) rootPrim.GetReferences().AppendReference( Sdf.Reference(topologyLayer.identifier, rootPath)) clipTime = 102.0 stageTime = 0.0 for c in clips: currentClipActive = list(clipPrim.GetClipActive()) currentClipActive.append([clipTime, stageTime]) clipPrim.SetClipActive(currentClipActive) currentClipTimes = list(clipPrim.GetClipTimes()) currentClipTimes.append([clipTime, clipTime]) clipPrim.SetClipTimes(currentClipTimes) clipTime += 1.0 stageTime += 1.0 stage = Usd.Stage.Open(root.identifier) prim = stage.GetPrimAtPath(clipPath) attr = prim.GetAttribute(attrName) # Ensure we only pick up relevant clips # In the case of a default time code we don't want any of the # value clips to show up in our stack of properties stack = attr.GetPropertyStack(Usd.TimeCode.Default()) self.assertEqual(stack, [topologyLayer.GetPropertyAtPath(fullPath)]) # ensure that clip 'c' is in the result when the time code # being used is exactly on 'c's endpoints clipTime = 102 for i in xrange(0, len(clips)): stack = attr.GetPropertyStack(clipTime) self.assertEqual(stack, [ clips[i].GetPropertyAtPath(fullPath), topologyLayer.GetPropertyAtPath(fullPath) ]) clipTime += 1
def test_ClipAuthoring(self): """Tests clip authoring API on Usd.ClipsAPI""" allFormats = ['usd' + x for x in 'ac'] for fmt in allFormats: stage = Usd.Stage.CreateInMemory('TestClipAuthoring.' + fmt) prim = stage.DefinePrim('/Model') model = Usd.ClipsAPI(prim) prim2 = stage.DefinePrim('/Model2') model2 = Usd.ClipsAPI(prim2) # Clip authoring API supports the use of lists as well as Vt arrays. clipAssetPaths = [ Sdf.AssetPath('clip1.usda'), Sdf.AssetPath('clip2.usda') ] model.SetClipAssetPaths(clipAssetPaths) self.assertEqual(model.GetClipAssetPaths(), clipAssetPaths) model2.SetClipAssetPaths( Sdf.AssetPathArray( [Sdf.AssetPath('clip1.usda'), Sdf.AssetPath('clip2.usda')])) self.assertEqual(model2.GetClipAssetPaths(), clipAssetPaths) clipPrimPath = "/Clip" model.SetClipPrimPath(clipPrimPath) self.assertEqual(model.GetClipPrimPath(), clipPrimPath) clipTimes = Vt.Vec2dArray([(0.0, 0.0), (10.0, 10.0), (20.0, 20.0)]) model.SetClipTimes(clipTimes) self.assertEqual(model.GetClipTimes(), clipTimes) model2.SetClipTimes( Vt.Vec2dArray([ Gf.Vec2d(0.0, 0.0), Gf.Vec2d(10.0, 10.0), Gf.Vec2d(20.0, 20.0) ])) self.assertEqual(model2.GetClipTimes(), clipTimes) clipActive = [(0.0, 0.0), (10.0, 1.0), (20.0, 0.0)] model.SetClipActive(clipActive) self.assertEqual(model.GetClipActive(), Vt.Vec2dArray(clipActive)) model2.SetClipActive( Vt.Vec2dArray([ Gf.Vec2d(0.0, 0.0), Gf.Vec2d(10.0, 1.0), Gf.Vec2d(20.0, 0.0) ])) self.assertEqual(model2.GetClipActive(), Vt.Vec2dArray(clipActive)) clipManifestAssetPath = Sdf.AssetPath('clip_manifest.usda') model.SetClipManifestAssetPath(clipManifestAssetPath) self.assertEqual(model.GetClipManifestAssetPath(), clipManifestAssetPath) # Test authoring of template clip metadata model.SetClipTemplateAssetPath('clip.###.usda') self.assertEqual(model.GetClipTemplateAssetPath(), 'clip.###.usda') model.SetClipTemplateStride(4.5) self.assertEqual(model.GetClipTemplateStride(), 4.5) model.SetClipTemplateStartTime(1) self.assertEqual(model.GetClipTemplateStartTime(), 1) model.SetClipTemplateEndTime(5) self.assertEqual(model.GetClipTemplateEndTime(), 5) # Ensure we can't set the clipTemplateStride to 0 with self.assertRaises(Tf.ErrorException) as e: model.SetClipTemplateStride(0)
def test(usdfile): print 'test'.center(40, '-') stage_ref = Usd.Stage.Open(usdfile) for prim_ref in stage_ref.Traverse(): print(prim_ref.GetPath()) if prim_ref.HasPayload(): print 'payloads'.center(40, '-') # this is apparently hacky, but it works, yah? payloads = prim_ref.GetMetadata("payload") # so there's lots of lists for x in dir(payloads): if x.endswith('Items'): print x, getattr(payloads, x) for payload in payloads.appendedItems: pathToResolve = payload.assetPath print 'assetPath:', pathToResolve primSpec = prim_ref.GetPrimStack()[0] # get the layer from the prim anchorPath = primSpec.layer.identifier with Ar.ResolverContextBinder( stage_ref.GetPathResolverContext()): resolver = Ar.GetResolver() # relative to layer path? pathToResolve = resolver.AnchorRelativePath( anchorPath, pathToResolve) print 'pathToResolve', pathToResolve # this should probably work, but no resolvedPath = resolver.Resolve(pathToResolve) print 'resolvedPath', resolvedPath if prim_ref.HasAuthoredPayloads(): payloads = prim_ref.GetPayloads() # print payloads """ There is currently no facility for listing the currently authored payloads on a prim... the problem is somewhat ill-defined, and requires some thought. """ # does this prim have variant sets? if prim_ref.HasVariantSets(): print 'variantsets'.center(30, '-') # list all the variant sets avalable on this prim sets = prim_ref.GetVariantSets() # you can't iterate over the sets. # you have to get the name and do a GetVariantSet(<<set name>>) # TypeError: 'VariantSets' object is not iterable # maybe USD 20? for varset in sets.GetNames(): print 'variant set name:', varset # get the variant set by name thisvarset = prim_ref.GetVariantSet(varset) # the available variants print thisvarset.GetVariantNames() # the current variant print thisvarset.GetVariantSelection() print varset # gotta get a clip on each prim and then test it for paths? clips = Usd.ClipsAPI(prim_ref) if clips.GetClipAssetPaths(): print 'CLIPS'.center(30, '-') # dict of clip info. full of everything # key is the clip *name* print clips.GetClips() # this is a good one - resolved asset paths too for path in clips.GetClipAssetPaths(): print path, type(path) print path.resolvedPath print 'end test'.center(40, '-')
def walkStagePrims(self, usdfile): # print 'test'.center(40, '-') stage = Usd.Stage.Open(usdfile) for prim in stage.TraverseAll(): # print(prim.GetPath()) # from the docs: """Return a list of PrimSpecs that provide opinions for this prim (i.e. the prim's metadata fields, including composition metadata). specs are ordered from strongest to weakest opinion.""" primStack = prim.GetPrimStack() for spec in primStack: if spec.hasPayloads: payloadList = spec.payloadList for itemlist in [ payloadList.appendedItems, payloadList.explicitItems, payloadList.addedItems, payloadList.prependedItems, payloadList.orderedItems ]: if itemlist: for payload in itemlist: payload_path = payload.assetPath # print payload, payload_path with Ar.ResolverContextBinder( stage.GetPathResolverContext()): resolver = Ar.GetResolver() # we resolve the payload path relative to the primSpec layer path (layer.identifier) # far more likely to be correct. i hope resolvedpath = resolver.AnchorRelativePath( spec.layer.identifier, payload_path) # print 'payload resolvedpath', resolvedpath info = {} info['online'] = os.path.isfile( resolvedpath) info['path'] = resolvedpath info['type'] = 'payload' self.nodes[resolvedpath] = info if spec.layer.identifier != resolvedpath: if not [ spec.layer.identifier, resolvedpath, 'payload' ] in self.edges: self.edges.append([ spec.layer.identifier, resolvedpath, 'payload' ]) # the docs say there's a HasSpecializes method # no, there is not. at least in this build of houdini 18.0.453 # if spec.HasSpecializes: # let's just ignore specialize for the time being """ specializesList = spec.specializesList spec_paths = [] for itemlist in [specializesList.appendedItems, specializesList.explicitItems, specializesList.addedItems, specializesList.prependedItems, specializesList.orderedItems]: if itemlist: for specialize in itemlist: specialize_path = specialize.assetPath with Ar.ResolverContextBinder(stage.GetPathResolverContext()): resolver = Ar.GetResolver() resolvedpath = resolver.AnchorRelativePath(spec.layer.identifier, specialize_path) spec_paths.append(resolvedpath) ret.append(resolvedpath) if spec_paths: print 'specializesList', spec.specializesList """ # references operate the same to payloads if spec.hasReferences: reflist = spec.referenceList for itemlist in [ reflist.appendedItems, reflist.explicitItems, reflist.addedItems, reflist.prependedItems, reflist.orderedItems ]: if itemlist: for reference in itemlist: reference_path = reference.assetPath if reference_path: # print reference_path with Ar.ResolverContextBinder( stage.GetPathResolverContext()): resolver = Ar.GetResolver() # we resolve the payload path relative to the primSpec layer path (layer.identifier) # far more likely to be correct. i hope resolvedpath = resolver.AnchorRelativePath( spec.layer.identifier, reference_path) info = {} info['online'] = os.path.isfile( resolvedpath) info['path'] = resolvedpath info['type'] = 'reference' self.nodes[resolvedpath] = info if spec.layer.identifier != resolvedpath: if not [ spec.layer.identifier, resolvedpath, 'reference' ] in self.edges: self.edges.append([ spec.layer.identifier, resolvedpath, 'reference' ]) if spec.variantSets: for varset in spec.variantSets: thisvarset = prim.GetVariantSet(varset.name) current_variant_name = thisvarset.GetVariantSelection() current_variant = varset.variants[current_variant_name] for variant_name in varset.variants.keys(): variant = varset.variants[variant_name] # todo: put variant info onto layer # for key in variant.GetMetaDataInfoKeys(): # print key, variant.GetInfo(key) # variants that are linked to payloads # variants can have other mechanisms, but sometimes they're a payload payloads = variant.GetInfo('payload') for itemlist in [ payloads.appendedItems, payloads.explicitItems, payloads.addedItems, payloads.prependedItems, payloads.orderedItems ]: for payload in itemlist: pathToResolve = payload.assetPath anchorPath = variant.layer.identifier with Ar.ResolverContextBinder( stage.GetPathResolverContext()): resolver = Ar.GetResolver() resolvedpath = resolver.AnchorRelativePath( anchorPath, pathToResolve) if not [ anchorPath, resolvedpath, 'payload' ] in self.edges: self.edges.append([ anchorPath, resolvedpath, 'payload' ]) # def, over or class # print 'GetSpecifier', spec.specifier # component, # print 'GetKind', spec.kind # print '--' # clips - this seems to be the way to do things # clips are not going to be picked up by the stage layers inspection stuff # apparently they're expensive. whatever. # no prim stack shennanigans for us # gotta get a clip on each prim and then test it for paths? clips = Usd.ClipsAPI(prim) if clips.GetClipAssetPaths(): # print 'CLIPS'.center(30, '-') # dict of clip info. full of everything # key is the clip *name* clip_dict = clips.GetClips() # print clip_dict """ @todo: subframe handling integer frames: path/basename.###.usd subinteger frames: path/basename.##.##.usd. @todo: non-1 increments """ # don't use resolved path in case either the first or last file is missing from disk firstFile = str(clips.GetClipAssetPaths()[0].path) lastFile = str(clips.GetClipAssetPaths()[-1].path) firstFileNum = digitSearch.findall(firstFile)[-1] lastFileNum = digitSearch.findall(lastFile)[-1] digitRange = str(firstFileNum + '-' + lastFileNum) nodeName = '' firstFileParts = firstFile.split(firstFileNum) for i in range(len(firstFileParts) - 1): nodeName += str(firstFileParts[i]) nodeName += digitRange nodeName += firstFileParts[-1] allFilesFound = True for path in clips.GetClipAssetPaths(): if (path.resolvedPath == ''): allFilesFound = False break # TODO : make more efficient - looping over everything currently # TODO: validate presence of all files in the clip seq. bg thread? # GetClipSets seems to be crashing this houdini build - clips.GetClipSets() clip_sets = clips.GetClips().keys() # print 'GetClipManifestAssetPath', clips.GetClipManifestAssetPath().resolvedPath # this is a good one - resolved asset paths too for clipSet in clip_sets: for path in clips.GetClipAssetPaths(clipSet): # print path, type(path) # print path.resolvedPath pass # layer that hosts list clip # but this is the MANIFEST path # not really correct. it'll have to do for now. layer = clips.GetClipManifestAssetPath().resolvedPath if not nodeName in self.nodes: info = {} info['online'] = allFilesFound info['path'] = nodeName info['type'] = 'clip' self.nodes[nodeName] = info if not [layer, nodeName, 'clip'] in self.edges: self.edges.append([layer, nodeName, 'clip'])
def test_AppliedSchemas(self): self.assertTrue(Usd.ModelAPI().IsAPISchema()) self.assertTrue(Usd.ClipsAPI().IsAPISchema()) self.assertTrue(Usd.CollectionAPI().IsAPISchema()) self.assertFalse(Usd.ModelAPI().IsAppliedAPISchema()) self.assertFalse(Usd.ClipsAPI().IsAppliedAPISchema()) self.assertTrue(Usd.CollectionAPI().IsAppliedAPISchema()) self.assertTrue(Usd.CollectionAPI().IsMultipleApplyAPISchema()) self.assertTrue(Usd.CollectionAPI().GetSchemaType() == Usd.SchemaType.MultipleApplyAPI) self.assertTrue(Usd.CollectionAPI().GetSchemaType() != Usd.SchemaType.SingleApplyAPI) self.assertTrue( Usd.ModelAPI().GetSchemaType() == Usd.SchemaType.NonAppliedAPI) self.assertTrue( Usd.ClipsAPI().GetSchemaType() == Usd.SchemaType.NonAppliedAPI) # Verify that we an exception but don't crash when applying to the # null prim. with self.assertRaises(Tf.ErrorException): self.assertFalse(Usd.CollectionAPI.Apply(Usd.Prim(), "root")) for fmt in allFormats: sessionLayer = Sdf.Layer.CreateNew("SessionLayer.%s" % fmt) s = Usd.Stage.CreateInMemory('AppliedSchemas.%s' % fmt, sessionLayer) s.SetEditTarget(Usd.EditTarget(s.GetRootLayer())) world = s.OverridePrim('/world') self.assertEqual([], world.GetAppliedSchemas()) rootCollAPI = Usd.CollectionAPI.Apply(world, "root") self.assertTrue(rootCollAPI) world = rootCollAPI.GetPrim() self.assertTrue(world) self.assertTrue(world.HasAPI(Usd.CollectionAPI)) # The schemaType that's passed into HasAPI must derive from # UsdAPISchemaBase and must not be UsdAPISchemaBase. with self.assertRaises(RuntimeError): world.HasAPI(Usd.Typed) with self.assertRaises(RuntimeError): world.HasAPI(Usd.APISchemaBase) with self.assertRaises(RuntimeError): world.HasAPI(Usd.ModelAPI) # Try calling HasAPI a random TfType that isn't a derivative of # SchemaBase. with self.assertRaises(RuntimeError): world.HasAPI(Sdf.ListOpType) self.assertEqual(['CollectionAPI:root'], world.GetAppliedSchemas()) # Switch the edit target to the session layer and test bug 156929 s.SetEditTarget(Usd.EditTarget(s.GetSessionLayer())) sessionCollAPI = Usd.CollectionAPI.Apply(world, "session") self.assertTrue(sessionCollAPI) self.assertEqual(['CollectionAPI:session', 'CollectionAPI:root'], world.GetAppliedSchemas()) self.assertTrue(world.HasAPI(Usd.CollectionAPI)) # Ensure duplicates aren't picked up anotherSessionCollAPI = Usd.CollectionAPI.Apply(world, "session") self.assertTrue(anotherSessionCollAPI) self.assertEqual(['CollectionAPI:session', 'CollectionAPI:root'], world.GetAppliedSchemas()) # Add a duplicate in the root layer and ensure that there are no # duplicates in the composed result. s.SetEditTarget(Usd.EditTarget(s.GetRootLayer())) rootLayerSessionCollAPI = Usd.CollectionAPI.Apply(world, "session") self.assertTrue(rootLayerSessionCollAPI) self.assertEqual(['CollectionAPI:session', 'CollectionAPI:root'], world.GetAppliedSchemas())
def test(usdfile): print('test'.center(40, '-')) stage = Usd.Stage.Open(usdfile) print('GetUsedLayers'.center(40, '-')) # things that are in use, apparntly for x in stage.GetUsedLayers(includeClipLayers=True): print(x) # print(type(x)) # print(dir(x)) # print(x, x.GetFileFormat().GetFileExtensions()) # print('subLayerPaths', x.subLayerPaths) # # return print('stage.Traverse'.center(40, '-')) for prim in stage.Traverse(): print(prim.GetPath()) """Return a list of PrimSpecs that provide opinions for this prim (i.e. the prim's metadata fields, including composition metadata). specs are ordered from strongest to weakest opinion.""" # print(prim.GetPrimStack()) if prim.HasAuthoredReferences(): primSpec = stage.GetEditTarget().GetPrimSpecForScenePath( prim.GetPath()) if primSpec: print('primspec GetAssetInfo') print(primSpec.assetInfo) refList = primSpec.referenceList if refList: print('referenceList'.center(40, '-')) for ref in refList.GetAddedOrExplicitItems(): if ref.assetPath: print(' -', ref.assetPath) print(' -', ref.customData) print(' -', ref.layerOffset) refList = primSpec.payloadList if refList: print('payloadList'.center(40, '-')) for ref in refList.GetAddedOrExplicitItems(): if ref.assetPath: print(' -', ref.assetPath) refList = primSpec.specializesList if refList: print('specializesList'.center(40, '-')) for ref in refList.GetAddedOrExplicitItems(): if ref.assetPath: print(' -', ref.assetPath) refList = primSpec.inheritPathList if refList: print('inheritPathList'.center(40, '-')) for ref in refList.GetAddedOrExplicitItems(): if ref.assetPath: print(' -', ref.assetPath) print('done with primspec'.center(40, '-')) """ this doesn't quite work https://groups.google.com/d/msg/usd-interest/s4AM0v60uBI/sYltgp7OAgAJ """ if prim.HasPayload(): print('payloads'.center(40, '-')) # this is apparently hacky, but it works, yah? # https://groups.google.com/d/msg/usd-interest/s4AM0v60uBI/q-okjU2RCAAJ payloads = prim.GetMetadata("payload") # so there's lots of lists for x in dir(payloads): if x.endswith('Items'): print(x, getattr(payloads, x)) # query GetAddedOrExplicitItems for *all* entries, rather than rooting through each list? print('GetAddedOrExplicitItems') print(payloads.GetAddedOrExplicitItems()) for itemlist in [ payloads.appendedItems, payloads.explicitItems, payloads.addedItems, payloads.prependedItems, payloads.orderedItems ]: for payload in itemlist: pathToResolve = payload.assetPath print('assetPath:', pathToResolve) primSpec = prim.GetPrimStack()[0] # get the layer from the prim anchorPath = primSpec.layer.identifier with Ar.ResolverContextBinder( stage.GetPathResolverContext()): resolver = Ar.GetResolver() # relative to layer path? pathToResolve = resolver.AnchorRelativePath( anchorPath, pathToResolve) print('pathToResolve', pathToResolve) # this should probably work, but no resolvedPath = resolver.Resolve(pathToResolve) print('resolvedPath', resolvedPath) if prim.HasAuthoredPayloads(): payloads = prim.GetPayloads() # print(payloads) """ There is currently no facility for listing the currently authored payloads on a prim... the problem is somewhat ill-defined, and requires some thought. """ # does this prim have variant sets? if prim.HasVariantSets(): print('variantsets'.center(30, '-')) # list all the variant sets avalable on this prim sets = prim.GetVariantSets() # you can't iterate over the sets. # you have to get the name and do a GetVariantSet(<<set name>>) # TypeError: 'VariantSets' object is not iterable # maybe USD 20? for varset in sets.GetNames(): print('variant set name:', varset) # get the variant set by name thisvarset = prim.GetVariantSet(varset) # the available variants print(thisvarset.GetVariantNames()) # the current variant print(thisvarset.GetVariantSelection()) print(varset) # gotta get a clip on each prim and then test it for paths? clips = Usd.ClipsAPI(prim) if clips.GetClipAssetPaths(): print('CLIPS'.center(30, '-')) # dict of clip info. full of everything # key is the clip *name* print(clips.GetClips()) # this is a good one - resolved asset paths too for path in clips.GetClipAssetPaths(): print(path, type(path)) print(path.resolvedPath) print('GetClipPrimPath', clips.GetClipPrimPath()) mdlinfo = Usd.ModelAPI(prim) print('UsdModelAPI'.center(30, '-')) print(mdlinfo) print('GetAssetInfo', mdlinfo.GetAssetInfo()) print('GetAssetIdentifier', mdlinfo.GetAssetIdentifier()) print('GetKind', mdlinfo.GetKind()) print('GetPayloadAssetDependencies', mdlinfo.GetPayloadAssetDependencies()) primStack = prim.GetPrimStack() print('GetPrimStack'.center(30, '-')) for spec in primStack: print(spec) print('layer.realPath', spec.layer.realPath) print('path.pathString', spec.path.pathString) print('layer.identifier', spec.layer.identifier) print('GetPayloadList', spec.payloadList) print('--') print(prim.HasPayload()) print(prim.HasAuthoredPayloads()) print('end test'.center(40, '-'))
def prim_traverse(usdfile): ret = [] stage = Usd.Stage.Open(usdfile) count = 1 for prim in stage.Traverse(): """ this doesn't quite work https://groups.google.com/d/msg/usd-interest/s4AM0v60uBI/sYltgp7OAgAJ """ if prim.HasPayload(): print('payloads'.center(40, '-')) # this is apparently hacky, but it works, yah? # https://groups.google.com/d/msg/usd-interest/s4AM0v60uBI/q-okjU2RCAAJ payloads = prim.GetMetadata("payload") # so there's lots of lists for x in dir(payloads): if x.endswith('Items'): print(x, getattr(payloads, x)) for itemlist in [ payloads.appendedItems, payloads.explicitItems, payloads.addedItems, payloads.prependedItems, payloads.orderedItems ]: for payload in itemlist: pathToResolve = payload.assetPath print('assetPath:', pathToResolve) primSpec = prim.GetPrimStack()[0] # get the layer from the prim anchorPath = primSpec.layer.identifier print('anchorPath', anchorPath) with Ar.ResolverContextBinder( stage.GetPathResolverContext()): resolver = Ar.GetResolver() # relative to layer path? NOPE # problem here is that the layer path is NOT # really what the payload path is relative to # and why it's better to go through the primstack - you can get a # proper anchor path pathToResolve = resolver.AnchorRelativePath( anchorPath, pathToResolve) print('pathToResolve', pathToResolve) # this should probably work, but no resolvedPath = resolver.Resolve(pathToResolve) print('resolvedPath', resolvedPath) # does this prim have variant sets? if prim.HasVariantSets(): print('variantsets'.center(30, '-')) # list all the variant sets avalable on this prim sets = prim.GetVariantSets() # you can't iterate over the sets. # you have to get the name and do a GetVariantSet(<<set name>>) # TypeError: 'VariantSets' object is not iterable # maybe USD 20? for varset in sets.GetNames(): print('variant set name:', varset) # get the variant set by name thisvarset = prim.GetVariantSet(varset) # the available variants print('variant names:', thisvarset.GetVariantNames()) # the current variant print('current variant:', thisvarset.GetVariantSelection()) print(varset) print(thisvarset.GetPrim()) # clips - this seems to be the way to do things # clips are not going to be picked up by the stage layers inspection stuff # apparently they're expensive. whatever. # no prim stack shennanigans for us # gotta get a clip on each prim and then test it for paths? clips = Usd.ClipsAPI(prim) if clips.GetClipAssetPaths(): print('CLIPS'.center(30, '-')) # dict of clip info. full of everything # key is the clip set *name* print(clips.GetClips()) # GetClipSets seems to be crashing this houdini build - clips.GetClipSets() clip_sets = clips.GetClips().keys() print('clip_sets', clip_sets) # this is a good one - resolved asset paths too for clipSet in clip_sets: print('CLIP_SET:', clipSet) for path in clips.GetClipAssetPaths(clipSet): print(path, type(path)) print('resolved path:', path.resolvedPath) ret.append(path.resolvedPath) print('GetClipTemplateAssetPath:', clips.GetClipTemplateAssetPath(clipSet)) print('GetClipAssetPaths:', clips.GetClipAssetPaths()) print('GetClipPrimPath', clips.GetClipPrimPath()) # from the docs: """Return a list of PrimSpecs that provide opinions for this prim (i.e. the prim's metadata fields, including composition metadata). specs are ordered from strongest to weakest opinion.""" primStack = prim.GetPrimStack() print('GetPrimStack'.center(30, '-')) for spec in primStack: # print(spec) # print('layer.realPath', spec.layer.realPath) print('path.pathString', spec.path.pathString) print('layer.identifier', spec.layer.identifier) print('layer.owner', spec.layer.owner) print('layer.subLayerPaths', spec.layer.subLayerPaths) print('specifier', spec.specifier) # if not spec.variantSets: if spec.hasPayloads: print('GetPayloadList'.center(80, '#')) payloadList = spec.payloadList print('GetPayloadList', payloadList) for itemlist in [ payloadList.appendedItems, payloadList.explicitItems, payloadList.addedItems, payloadList.prependedItems, payloadList.orderedItems ]: if itemlist: for payload in itemlist: payload_path = payload.assetPath print(payload, payload_path) with Ar.ResolverContextBinder( stage.GetPathResolverContext()): resolver = Ar.GetResolver() # we resolve the payload path relative to the primSpec layer path (layer.identifier) # far more likely to be correct. i hope resolvedpath = resolver.AnchorRelativePath( spec.layer.identifier, payload_path) print('payload resolvedpath', resolvedpath) ret.append(resolvedpath) # the docs say there's a HasSpecializes method # no, there is not. at least in this build of houdini 18.0.453 # if spec.HasSpecializes: # let's just ignore specialize for the time being """ specializesList = spec.specializesList spec_paths = [] for itemlist in [specializesList.appendedItems, specializesList.explicitItems, specializesList.addedItems, specializesList.prependedItems, specializesList.orderedItems]: if itemlist: for specialize in itemlist: specialize_path = specialize.assetPath with Ar.ResolverContextBinder(stage.GetPathResolverContext()): resolver = Ar.GetResolver() resolvedpath = resolver.AnchorRelativePath(spec.layer.identifier, specialize_path) spec_paths.append(resolvedpath) ret.append(resolvedpath) if spec_paths: print('specializesList', spec.specializesList) """ # references operate the same to payloads if spec.hasReferences: reflist = spec.referenceList print('referenceList', reflist) print('orderedItems', reflist.orderedItems) for itemlist in [ reflist.appendedItems, reflist.explicitItems, reflist.addedItems, reflist.prependedItems, reflist.orderedItems ]: if itemlist: for reference in itemlist: print('reference:', reference) reference_path = reference.assetPath with Ar.ResolverContextBinder( stage.GetPathResolverContext()): resolver = Ar.GetResolver() # we resolve the payload path relative to the primSpec layer path (layer.identifier) # far more likely to be correct. i hope resolvedpath = resolver.AnchorRelativePath( spec.layer.identifier, reference_path) print('reference resolvedpath', resolvedpath) ret.append(resolvedpath) # if spec.hasVariantSetNames: # print(dir(spec)) if spec.variantSets: print('variantSets', spec.variantSets) for varset in spec.variantSets: # SdfVariantSetSpec objects print(varset) # you can get a SdfPath from the variant path # https://groups.google.com/d/msg/usd-interest/Q1tjV88T1EI/_KGo3wzyBAAJ variantDefinitionPath = Sdf.Path(varset.path) print('---variantDefinitionPath') print('variantDefinitionPath', variantDefinitionPath) print(type(variantDefinitionPath)) print(dir(variantDefinitionPath)) print('pathString', variantDefinitionPath.pathString) print('GetParentPath', variantDefinitionPath.GetParentPath()) print( 'GetPrimOrPrimVariantSelectionPath', variantDefinitionPath. GetPrimOrPrimVariantSelectionPath()) print('GetPrimPath', variantDefinitionPath.GetPrimPath()) print('GetVariantSelection', variantDefinitionPath.GetVariantSelection()) print('isAbsolutePath', variantDefinitionPath.IsAbsolutePath()) print('IsPrimVariantSelectionPath', variantDefinitionPath.IsPrimVariantSelectionPath()) print('GetTargetPath', variantDefinitionPath.targetPath) pld = Sdf.Payload(variantDefinitionPath.pathString) print(pld) print(pld.assetPath) print(dir(pld)) print('---variantDefinitionPath') print('variant set name', varset.name) print('owner', varset.owner) print('isInert', varset.isInert) print('layer', varset.layer) # the available variants # dict with the variant name as a key nad a Sdf.Find object as the value print('variant', varset.variants) print('variant_names:', varset.variants.keys()) # SdfVariantSetSpec doesn't seem to know which is the current variant # but it's a short hop to get the variant set object # and perhaps this is the best of both worlds thisvarset = prim.GetVariantSet(varset.name) current_variant_name = thisvarset.GetVariantSelection() print('current variant name:', current_variant_name) current_variant = varset.variants[current_variant_name] for variant_name in varset.variants.keys(): variant = varset.variants[variant_name] print(variant.GetPrimStack()) print('variant:', variant) print('path:', variant.path) print('layer:', variant.layer) print('variant payload info:', variant.GetInfo('payload')) payloads = variant.GetInfo('payload') for itemlist in [ payloads.appendedItems, payloads.explicitItems, payloads.addedItems, payloads.prependedItems, payloads.orderedItems ]: for payload in itemlist: pathToResolve = payload.assetPath anchorPath = variant.layer.identifier print('anchorPath', anchorPath) with Ar.ResolverContextBinder( stage.GetPathResolverContext()): resolver = Ar.GetResolver() pathToResolve = resolver.AnchorRelativePath( anchorPath, pathToResolve) print('pathToResolve', pathToResolve) # print(type(current_variant)) # print(dir(current_variant)) # print('path', current_variant.path) # print('variantSets', current_variant.variantSets) # print('layer', current_variant.layer) # print('GetMetaDataInfoKeys', current_variant.GetMetaDataInfoKeys()) # print('variant payload info:', current_variant.GetInfo('payload')) # for key in current_variant.GetMetaDataInfoKeys(): print(key, current_variant.GetInfo(key)) # THIS IS WAAAY WRONG # it's just giving the layer path current_variant_path = current_variant.layer.realPath # the paths we are looking for are coming in as payloads # (because they can be dynamically loaded i guess) print(current_variant_path) x = thisvarset.GetVariantEditTarget() count += 1 if count > 1: print('count', count) raise RuntimeError("poo") # print('GetVariantNames', spec.GetVariantNames(varset)) # def, over or class print('GetSpecifier', spec.specifier) # component, print('GetInherits') inherits = prim.GetInherits().GetAllDirectInherits() if inherits: print(inherits) raise RuntimeError('poo') print('GetKind', spec.kind) print('--') print(prim.HasPayload()) print(prim.HasAuthoredPayloads()) return ret