最近接触到了USD,想分享一下目前对usd的认识和一些常用的python api。
USD(Universal Scene Description通用场景描述)
usd是Pixar公司开发的一种在DCC中传递场景信息的缓存格式(类似于fbx),但usd的功能远超于其他的文件格式。usd的可读性很强,可以直接编写usd文件来构建场景,同时usd有自己的可视化工具usdview,可直接查看场景。usd中reference功能也很强大,可以场景拆分成更细的usd文件(模型、材质、层级结构等)通过reference重组场景。这样后续更改资产时,仅需要对相应的文件更改即可。下面是pixar官方给的案例。
over,覆盖层,通过over覆盖的信息并不会改变场景原来的信息,只会叠加。例如,场景中存在模型层,通过over再加上材质子层,为模型添加上材质,这样并不会改变原模型层上的信息。
下面是我近期总结的一下常用的python api命令
删除prim属性
stage = Usd.Stage.Open('path')
meshPrim = stage.GetPrimAtPath('/hello/world')
meshPrim.RemoveProperty('attitude')
删除prim
stage = Usd.Stage.Open('path')
meshPrim = stage.GetPrimAtPath('/hello/world')
stage.RemovePrim(meshPrim.GetPath())
设置根prim
stage = Usd.Stage.Open('path')
meshPrim = stage.GetPrimAtPath('/hello/world')
stage.SetDefaultPrim(meshPrim)
获取根prim
stage = Usd.Stage.Open('path')
meshPrim = stage.GetPrimAtPath('/hello/world')
root_prim = stage.GetPseudoRoot()
获取子代prim
stage = Usd.Stage.Open(‘path’)
prim= stage.GetPrimAtPath('/hello/world')
child_prim = prim.GetChildren()
获取父代prim
stage = Usd.Stage.Open(‘path’)
prim= stage.GetPrimAtPath('/hello/world')
child_prim = prim.GetParent()
遍历prim
stage = Usd.Stage.Open(‘path’)
for prim in Usd.PrimRange(stage.GetPseudoRoot()):
print('prim')
获取prim的类型
stage = Usd.Stage.Open(‘path’)
prim= stage.GetPrimAtPath('/hello/world')
print(prim.GetTypeName())
创建prim
stage = Usd.Stage.CreateNew("path")
stage.DefinePrim(name,type)
添加子层
在官方的C++的文档中添加子层是SetSubLayerPaths,但是一直报错显示layer并没有这个属性。通过dir查询也没有这个属性,后来问导师才知道这个命令也可以实现。
stage = Usd.Stage.CreateNew("path")
childpath = 'childpath'
stage.GetRootLayer().subLayerPaths.append(childpath)
展平usd文件
stage = Usd.Stage.Open('path')
flattened_stage = stage.Flatten()
flattened_stage.Export('path')
保存usd文件
stage.GetRootLayer().Save()
reference文件
stage = Usd.Stage.Open('path')
mesh_stage = Usd.Stage.CreateNew(mesh_path)
mesh_prim= mesh_stage .GetPrimAtPath('/hello/world')
prim_name= stage .GetPrimAtPath('/hello/world')
mesh_prim.GetReferences().AddReference(stage.GetRootLayer().identifier, prim_name)
官方文档:USD Home — Universal Scene Description 23.08 documentation
以上是我个人的见解和笔记,仅供参考。如有差错,欢迎大佬斧正。