Reputation: 2025
I am using the Python package pxr to read a USD file. The problem is that I cannot find enough information to fully understand how to work with the objects defined in pxr
.
I am trying to crack a Python object pxr.Usd.Prim
which is a binding of a C++ object UsdPrim
. The problem is that I cannot get all attributes of the Python object.
usdc_file = "./input/20240506_145520.usdc"
stage = pxr.Usd.Stage.Open(usdc_file)
The stage
has the type <class 'pxr.Usd.Stage'>
. I can traverse stage
as follows:
for prim in stage.Traverse():
print("prim", type(prim), prim)
The result is
prim: <class 'pxr.Usd.Prim'> Usd.Prim(</_20240506_145520>)
prim: <class 'pxr.Usd.Prim'> Usd.Prim(</_20240506_145520/Geom>)
prim: <class 'pxr.Usd.Prim'> Usd.Prim(</_20240506_145520/Geom/MDL_OBJ_material0000>)
prim: <class 'pxr.Usd.Prim'> Usd.Prim(</_20240506_145520/Materials>)
prim: <class 'pxr.Usd.Prim'> Usd.Prim(</_20240506_145520/Materials/material0000>)
prim: <class 'pxr.Usd.Prim'> Usd.Prim(</_20240506_145520/Materials/material0000/surfaceShader>)
prim: <class 'pxr.Usd.Prim'> Usd.Prim(</_20240506_145520/Materials/material0000/st_texCoordReader>)
prim: <class 'pxr.Usd.Prim'> Usd.Prim(</_20240506_145520/Materials/material0000/diffuseColor_texture>)
As observed, all primitives in stage
have type <class 'pxr.Usd.Prim'>
.
I tried using dir()
and vars()
to get all attributes by following this question. But only methods are returned. E.g.,
for prim in stage.Traverse():
def dump(obj):
for attr in dir(obj):
print("obj.%s = %r" % (attr, getattr(obj, attr)))
print("prim:", type(prim), prim)
dump(prim)
break
The result is
prim: <class 'pxr.Usd.Prim'> Usd.Prim(</_20240506_145520>)
obj.AddAppliedSchema = <bound method AddAppliedSchema of Usd.Prim(</_20240506_145520>)>
obj.ApplyAPI = <bound method ApplyAPI of Usd.Prim(</_20240506_145520>)>
obj.CanApplyAPI = <bound method CanApplyAPI of Usd.Prim(</_20240506_145520>)>
obj.ClearActive = <bound method ClearActive of Usd.Prim(</_20240506_145520>)>
obj.ClearAssetInfo = <bound method ClearAssetInfo of Usd.Prim(</_20240506_145520>)>
obj.ClearAssetInfoByKey = <bound method ClearAssetInfoByKey of Usd.Prim(</_20240506_145520>)>
obj.ClearChildrenReorder = <bound method ClearChildrenReorder of Usd.Prim(</_20240506_145520>)>
obj.ClearCustomData = <bound method ClearCustomData of Usd.Prim(</_20240506_145520>)>
obj.ClearCustomDataByKey = <bound method ClearCustomDataByKey of Usd.Prim(</_20240506_145520>)>
obj.ClearDisplayName = <bound method ClearDisplayName of Usd.Prim(</_20240506_145520>)>
obj.ClearDocumentation = <bound method ClearDocumentation of Usd.Prim(</_20240506_145520>)>
obj.ClearHidden = <bound method ClearHidden of Usd.Prim(</_20240506_145520>)>
obj.ClearInstanceable = <bound method ClearInstanceable of Usd.Prim(</_20240506_145520>)>
obj.ClearMetadata = <bound method ClearMetadata of Usd.Prim(</_20240506_145520>)>
obj.ClearMetadataByDictKey = <bound method ClearMetadataByDictKey of Usd.Prim(</_20240506_145520>)>
obj.ClearPayload = <bound method ClearPayload of Usd.Prim(</_20240506_145520>)>
obj.ClearPropertyOrder = <bound method ClearPropertyOrder of Usd.Prim(</_20240506_145520>)>
obj.ClearTypeName = <bound method ClearTypeName of Usd.Prim(</_20240506_145520>)>
obj.ComputeExpandedPrimIndex = <bound method ComputeExpandedPrimIndex of Usd.Prim(</_20240506_145520>)>
obj.CreateAttribute = <bound method CreateAttribute of Usd.Prim(</_20240506_145520>)>
obj.CreateRelationship = <bound method CreateRelationship of Usd.Prim(</_20240506_145520>)>
obj.FindAllAttributeConnectionPaths = <bound method FindAllAttributeConnectionPaths of Usd.Prim(</_20240506_145520>)>
obj.FindAllRelationshipTargetPaths = <bound method FindAllRelationshipTargetPaths of Usd.Prim(</_20240506_145520>)>
obj.GetAllAuthoredMetadata = <bound method GetAllAuthoredMetadata of Usd.Prim(</_20240506_145520>)>
obj.GetAllChildren = <bound method GetAllChildren of Usd.Prim(</_20240506_145520>)>
obj.GetAllChildrenNames = <bound method GetAllChildrenNames of Usd.Prim(</_20240506_145520>)>
obj.GetAllMetadata = <bound method GetAllMetadata of Usd.Prim(</_20240506_145520>)>
obj.GetAppliedSchemas = <bound method GetAppliedSchemas of Usd.Prim(</_20240506_145520>)>
obj.GetAssetInfo = <bound method GetAssetInfo of Usd.Prim(</_20240506_145520>)>
obj.GetAssetInfoByKey = <bound method GetAssetInfoByKey of Usd.Prim(</_20240506_145520>)>
obj.GetAttribute = <bound method GetAttribute of Usd.Prim(</_20240506_145520>)>
obj.GetAttributeAtPath = <bound method GetAttributeAtPath of Usd.Prim(</_20240506_145520>)>
obj.GetAttributes = <bound method GetAttributes of Usd.Prim(</_20240506_145520>)>
obj.GetAuthoredAttributes = <bound method GetAuthoredAttributes of Usd.Prim(</_20240506_145520>)>
obj.GetAuthoredProperties = <bound method GetAuthoredProperties of Usd.Prim(</_20240506_145520>)>
obj.GetAuthoredPropertiesInNamespace = <bound method GetAuthoredPropertiesInNamespace of Usd.Prim(</_20240506_145520>)>
obj.GetAuthoredPropertyNames = <bound method GetAuthoredPropertyNames of Usd.Prim(</_20240506_145520>)>
obj.GetAuthoredRelationships = <bound method GetAuthoredRelationships of Usd.Prim(</_20240506_145520>)>
obj.GetChild = <bound method GetChild of Usd.Prim(</_20240506_145520>)>
obj.GetChildren = <bound method GetChildren of Usd.Prim(</_20240506_145520>)>
obj.GetChildrenNames = <bound method GetChildrenNames of Usd.Prim(</_20240506_145520>)>
obj.GetChildrenReorder = <bound method GetChildrenReorder of Usd.Prim(</_20240506_145520>)>
obj.GetCustomData = <bound method GetCustomData of Usd.Prim(</_20240506_145520>)>
obj.GetCustomDataByKey = <bound method GetCustomDataByKey of Usd.Prim(</_20240506_145520>)>
obj.GetDescription = <bound method GetDescription of Usd.Prim(</_20240506_145520>)>
obj.GetDisplayName = <bound method GetDisplayName of Usd.Prim(</_20240506_145520>)>
obj.GetDocumentation = <bound method GetDocumentation of Usd.Prim(</_20240506_145520>)>
obj.GetFilteredChildren = <bound method GetFilteredChildren of Usd.Prim(</_20240506_145520>)>
obj.GetFilteredChildrenNames = <bound method GetFilteredChildrenNames of Usd.Prim(</_20240506_145520>)>
obj.GetFilteredNextSibling = <bound method GetFilteredNextSibling of Usd.Prim(</_20240506_145520>)>
obj.GetInherits = <bound method GetInherits of Usd.Prim(</_20240506_145520>)>
obj.GetInstances = <bound method GetInstances of Usd.Prim(</_20240506_145520>)>
obj.GetKind = <bound method GetKind of Usd.Prim(</_20240506_145520>)>
obj.GetMetadata = <bound method GetMetadata of Usd.Prim(</_20240506_145520>)>
obj.GetMetadataByDictKey = <bound method GetMetadataByDictKey of Usd.Prim(</_20240506_145520>)>
obj.GetName = <bound method GetName of Usd.Prim(</_20240506_145520>)>
obj.GetNamespaceDelimiter = <Boost.Python.function object at 0x64c26e21cde0>
obj.GetNextSibling = <bound method GetNextSibling of Usd.Prim(</_20240506_145520>)>
obj.GetObjectAtPath = <bound method GetObjectAtPath of Usd.Prim(</_20240506_145520>)>
obj.GetParent = <bound method GetParent of Usd.Prim(</_20240506_145520>)>
obj.GetPath = <bound method GetPath of Usd.Prim(</_20240506_145520>)>
obj.GetPayloads = <bound method GetPayloads of Usd.Prim(</_20240506_145520>)>
obj.GetPrim = <bound method GetPrim of Usd.Prim(</_20240506_145520>)>
obj.GetPrimAtPath = <bound method GetPrimAtPath of Usd.Prim(</_20240506_145520>)>
obj.GetPrimDefinition = <bound method GetPrimDefinition of Usd.Prim(</_20240506_145520>)>
obj.GetPrimInPrototype = <bound method GetPrimInPrototype of Usd.Prim(</_20240506_145520>)>
obj.GetPrimIndex = <bound method GetPrimIndex of Usd.Prim(</_20240506_145520>)>
obj.GetPrimPath = <bound method GetPrimPath of Usd.Prim(</_20240506_145520>)>
obj.GetPrimStack = <bound method GetPrimStack of Usd.Prim(</_20240506_145520>)>
obj.GetPrimStackWithLayerOffsets = <bound method GetPrimStackWithLayerOffsets of Usd.Prim(</_20240506_145520>)>
obj.GetPrimTypeInfo = <bound method GetPrimTypeInfo of Usd.Prim(</_20240506_145520>)>
obj.GetProperties = <bound method GetProperties of Usd.Prim(</_20240506_145520>)>
obj.GetPropertiesInNamespace = <bound method GetPropertiesInNamespace of Usd.Prim(</_20240506_145520>)>
obj.GetProperty = <bound method GetProperty of Usd.Prim(</_20240506_145520>)>
obj.GetPropertyAtPath = <bound method GetPropertyAtPath of Usd.Prim(</_20240506_145520>)>
obj.GetPropertyNames = <bound method GetPropertyNames of Usd.Prim(</_20240506_145520>)>
obj.GetPropertyOrder = <bound method GetPropertyOrder of Usd.Prim(</_20240506_145520>)>
obj.GetPrototype = <bound method GetPrototype of Usd.Prim(</_20240506_145520>)>
obj.GetReferences = <bound method GetReferences of Usd.Prim(</_20240506_145520>)>
obj.GetRelationship = <bound method GetRelationship of Usd.Prim(</_20240506_145520>)>
obj.GetRelationshipAtPath = <bound method GetRelationshipAtPath of Usd.Prim(</_20240506_145520>)>
obj.GetRelationships = <bound method GetRelationships of Usd.Prim(</_20240506_145520>)>
obj.GetSpecializes = <bound method GetSpecializes of Usd.Prim(</_20240506_145520>)>
obj.GetSpecifier = <bound method GetSpecifier of Usd.Prim(</_20240506_145520>)>
obj.GetStage = <bound method GetStage of Usd.Prim(</_20240506_145520>)>
obj.GetTypeName = <bound method GetTypeName of Usd.Prim(</_20240506_145520>)>
obj.GetVariantSet = <bound method GetVariantSet of Usd.Prim(</_20240506_145520>)>
obj.GetVariantSets = <bound method GetVariantSets of Usd.Prim(</_20240506_145520>)>
obj.GetVersionIfHasAPIInFamily = <bound method GetVersionIfHasAPIInFamily of Usd.Prim(</_20240506_145520>)>
obj.GetVersionIfIsInFamily = <bound method GetVersionIfIsInFamily of Usd.Prim(</_20240506_145520>)>
obj.HasAPI = <bound method HasAPI of Usd.Prim(</_20240506_145520>)>
obj.HasAPIInFamily = <bound method HasAPIInFamily of Usd.Prim(</_20240506_145520>)>
obj.HasAssetInfo = <bound method HasAssetInfo of Usd.Prim(</_20240506_145520>)>
obj.HasAssetInfoKey = <bound method HasAssetInfoKey of Usd.Prim(</_20240506_145520>)>
obj.HasAttribute = <bound method HasAttribute of Usd.Prim(</_20240506_145520>)>
obj.HasAuthoredActive = <bound method HasAuthoredActive of Usd.Prim(</_20240506_145520>)>
obj.HasAuthoredAssetInfo = <bound method HasAuthoredAssetInfo of Usd.Prim(</_20240506_145520>)>
obj.HasAuthoredAssetInfoKey = <bound method HasAuthoredAssetInfoKey of Usd.Prim(</_20240506_145520>)>
obj.HasAuthoredCustomData = <bound method HasAuthoredCustomData of Usd.Prim(</_20240506_145520>)>
obj.HasAuthoredCustomDataKey = <bound method HasAuthoredCustomDataKey of Usd.Prim(</_20240506_145520>)>
obj.HasAuthoredDisplayName = <bound method HasAuthoredDisplayName of Usd.Prim(</_20240506_145520>)>
obj.HasAuthoredDocumentation = <bound method HasAuthoredDocumentation of Usd.Prim(</_20240506_145520>)>
obj.HasAuthoredHidden = <bound method HasAuthoredHidden of Usd.Prim(</_20240506_145520>)>
obj.HasAuthoredInherits = <bound method HasAuthoredInherits of Usd.Prim(</_20240506_145520>)>
obj.HasAuthoredInstanceable = <bound method HasAuthoredInstanceable of Usd.Prim(</_20240506_145520>)>
obj.HasAuthoredMetadata = <bound method HasAuthoredMetadata of Usd.Prim(</_20240506_145520>)>
obj.HasAuthoredMetadataDictKey = <bound method HasAuthoredMetadataDictKey of Usd.Prim(</_20240506_145520>)>
obj.HasAuthoredPayloads = <bound method HasAuthoredPayloads of Usd.Prim(</_20240506_145520>)>
obj.HasAuthoredReferences = <bound method HasAuthoredReferences of Usd.Prim(</_20240506_145520>)>
obj.HasAuthoredSpecializes = <bound method HasAuthoredSpecializes of Usd.Prim(</_20240506_145520>)>
obj.HasAuthoredTypeName = <bound method HasAuthoredTypeName of Usd.Prim(</_20240506_145520>)>
obj.HasCustomData = <bound method HasCustomData of Usd.Prim(</_20240506_145520>)>
obj.HasCustomDataKey = <bound method HasCustomDataKey of Usd.Prim(</_20240506_145520>)>
obj.HasDefiningSpecifier = <bound method HasDefiningSpecifier of Usd.Prim(</_20240506_145520>)>
obj.HasMetadata = <bound method HasMetadata of Usd.Prim(</_20240506_145520>)>
obj.HasMetadataDictKey = <bound method HasMetadataDictKey of Usd.Prim(</_20240506_145520>)>
obj.HasPayload = <bound method HasPayload of Usd.Prim(</_20240506_145520>)>
obj.HasProperty = <bound method HasProperty of Usd.Prim(</_20240506_145520>)>
obj.HasRelationship = <bound method HasRelationship of Usd.Prim(</_20240506_145520>)>
obj.HasVariantSets = <bound method HasVariantSets of Usd.Prim(</_20240506_145520>)>
obj.IsA = <bound method IsA of Usd.Prim(</_20240506_145520>)>
obj.IsAbstract = <bound method IsAbstract of Usd.Prim(</_20240506_145520>)>
obj.IsActive = <bound method IsActive of Usd.Prim(</_20240506_145520>)>
obj.IsComponent = <bound method IsComponent of Usd.Prim(</_20240506_145520>)>
obj.IsDefined = <bound method IsDefined of Usd.Prim(</_20240506_145520>)>
obj.IsGroup = <bound method IsGroup of Usd.Prim(</_20240506_145520>)>
obj.IsHidden = <bound method IsHidden of Usd.Prim(</_20240506_145520>)>
obj.IsInFamily = <bound method IsInFamily of Usd.Prim(</_20240506_145520>)>
obj.IsInPrototype = <bound method IsInPrototype of Usd.Prim(</_20240506_145520>)>
obj.IsInstance = <bound method IsInstance of Usd.Prim(</_20240506_145520>)>
obj.IsInstanceProxy = <bound method IsInstanceProxy of Usd.Prim(</_20240506_145520>)>
obj.IsInstanceable = <bound method IsInstanceable of Usd.Prim(</_20240506_145520>)>
obj.IsLoaded = <bound method IsLoaded of Usd.Prim(</_20240506_145520>)>
obj.IsModel = <bound method IsModel of Usd.Prim(</_20240506_145520>)>
obj.IsPathInPrototype = <Boost.Python.function object at 0x64c26e22b350>
obj.IsPrototype = <bound method IsPrototype of Usd.Prim(</_20240506_145520>)>
obj.IsPrototypePath = <Boost.Python.function object at 0x64c26e22b230>
obj.IsPseudoRoot = <bound method IsPseudoRoot of Usd.Prim(</_20240506_145520>)>
obj.IsSubComponent = <bound method IsSubComponent of Usd.Prim(</_20240506_145520>)>
obj.IsValid = <bound method IsValid of Usd.Prim(</_20240506_145520>)>
obj.Load = <bound method Load of Usd.Prim(</_20240506_145520>)>
obj.MakeResolveTargetStrongerThanEditTarget = <bound method MakeResolveTargetStrongerThanEditTarget of Usd.Prim(</_20240506_145520>)>
obj.MakeResolveTargetUpToEditTarget = <bound method MakeResolveTargetUpToEditTarget of Usd.Prim(</_20240506_145520>)>
obj.RemoveAPI = <bound method RemoveAPI of Usd.Prim(</_20240506_145520>)>
obj.RemoveAppliedSchema = <bound method RemoveAppliedSchema of Usd.Prim(</_20240506_145520>)>
obj.RemoveProperty = <bound method RemoveProperty of Usd.Prim(</_20240506_145520>)>
obj.SetActive = <bound method SetActive of Usd.Prim(</_20240506_145520>)>
obj.SetAssetInfo = <bound method SetAssetInfo of Usd.Prim(</_20240506_145520>)>
obj.SetAssetInfoByKey = <bound method SetAssetInfoByKey of Usd.Prim(</_20240506_145520>)>
obj.SetChildrenReorder = <bound method SetChildrenReorder of Usd.Prim(</_20240506_145520>)>
obj.SetCustomData = <bound method SetCustomData of Usd.Prim(</_20240506_145520>)>
obj.SetCustomDataByKey = <bound method SetCustomDataByKey of Usd.Prim(</_20240506_145520>)>
obj.SetDisplayName = <bound method SetDisplayName of Usd.Prim(</_20240506_145520>)>
obj.SetDocumentation = <bound method SetDocumentation of Usd.Prim(</_20240506_145520>)>
obj.SetHidden = <bound method SetHidden of Usd.Prim(</_20240506_145520>)>
obj.SetInstanceable = <bound method SetInstanceable of Usd.Prim(</_20240506_145520>)>
obj.SetKind = <bound method SetKind of Usd.Prim(</_20240506_145520>)>
obj.SetMetadata = <bound method SetMetadata of Usd.Prim(</_20240506_145520>)>
obj.SetMetadataByDictKey = <bound method SetMetadataByDictKey of Usd.Prim(</_20240506_145520>)>
obj.SetPayload = <bound method SetPayload of Usd.Prim(</_20240506_145520>)>
obj.SetPropertyOrder = <bound method SetPropertyOrder of Usd.Prim(</_20240506_145520>)>
obj.SetSpecifier = <bound method SetSpecifier of Usd.Prim(</_20240506_145520>)>
obj.SetTypeName = <bound method SetTypeName of Usd.Prim(</_20240506_145520>)>
obj.Unload = <bound method Unload of Usd.Prim(</_20240506_145520>)>
obj._GetSourcePrimIndex = <bound method _GetSourcePrimIndex of Usd.Prim(</_20240506_145520>)>
obj.__bool__ = <bound method __bool__ of Usd.Prim(</_20240506_145520>)>
obj.__class__ = <class 'pxr.Usd.Prim'>
obj.__delattr__ = <method-wrapper '__delattr__' of Prim object at 0x787b16fcd7c0>
obj.__dict__ = {}
obj.__dir__ = <built-in method __dir__ of Prim object at 0x787b16fcd7c0>
obj.__doc__ = None
obj.__eq__ = <bound method __eq__ of Usd.Prim(</_20240506_145520>)>
obj.__format__ = <built-in method __format__ of Prim object at 0x787b16fcd7c0>
obj.__ge__ = <method-wrapper '__ge__' of Prim object at 0x787b16fcd7c0>
obj.__getattribute__ = <bound method __getattribute__ of Usd.Prim(</_20240506_145520>)>
obj.__gt__ = <method-wrapper '__gt__' of Prim object at 0x787b16fcd7c0>
obj.__hash__ = <bound method __hash__ of Usd.Prim(</_20240506_145520>)>
obj.__init__ = <bound method __init__ of Usd.Prim(</_20240506_145520>)>
obj.__init_subclass__ = <built-in method __init_subclass__ of Boost.Python.class object at 0x64c26e1e0390>
obj.__instance_size__ = 56
obj.__le__ = <method-wrapper '__le__' of Prim object at 0x787b16fcd7c0>
obj.__lt__ = <method-wrapper '__lt__' of Prim object at 0x787b16fcd7c0>
obj.__module__ = 'pxr.Usd'
obj.__ne__ = <bound method __ne__ of Usd.Prim(</_20240506_145520>)>
obj.__new__ = <built-in method __new__ of Boost.Python.class object at 0x787b44086040>
obj.__reduce__ = <bound method <unnamed Boost.Python function> of Usd.Prim(</_20240506_145520>)>
obj.__reduce_ex__ = <built-in method __reduce_ex__ of Prim object at 0x787b16fcd7c0>
obj.__repr__ = <bound method __repr__ of Usd.Prim(</_20240506_145520>)>
obj.__setattr__ = <method-wrapper '__setattr__' of Prim object at 0x787b16fcd7c0>
obj.__sizeof__ = <built-in method __sizeof__ of Prim object at 0x787b16fcd7c0>
obj.__str__ = <method-wrapper '__str__' of Prim object at 0x787b16fcd7c0>
obj.__subclasshook__ = <built-in method __subclasshook__ of Boost.Python.class object at 0x64c26e1e0390>
obj.__weakref__ = None
As you can see, it only returns methods.
points
attributes by using GetAttribute()
and Get()
I found some old code that can get the points
information from pxr.UsdGeom.Mesh
as follows:
for prim in stage.Traverse():
if prim.IsA(pxr.UsdGeom.Mesh):
points = prim.GetAttribute('points').Get()
print(f"points: {type(points)}")
points = np.array(points)
print(f"points: {points.shape}")
It first checks if prim
is pxr.UsdGeom.Mesh
. If so, it uses prim.GetAttribute('points').Get()
to get the points
from the mesh and turn it into a Numpy array. The output is:
points: <class 'pxr.Vt.Vec3fArray'>
points: (26330, 3)
But how do I know I can use this operation to get the information like this?
Based on the above description, my question is the following:
pxr.Usd.Prim
? I've read through the USD manual and omniverse manual but cannot find any relevant information.Upvotes: 1
Views: 376