USDCollectionの基本操作
ipynbFile USDCollectoinSample__USDCollectionの基本操作.ipynb
In [45]:
| from pxr import Usd, UsdGeom, Sdf, Gf, UsdUtils
newScn = Usd.Stage.CreateInMemory()
path = Sdf.Path("/World")
worldGeom = UsdGeom.Xform.Define(newScn, path)
sphereGeom = UsdGeom.Sphere.Define(newScn, path.AppendChild("Sphere"))
prim = worldGeom.GetPrim()
spherePrim = sphereGeom.GetPrim()
|
In [46]:
| api = Usd.CollectionAPI.ApplyCollection(prim, 'test')
api.IncludePath(spherePrim.GetPath())
|
In [47]:
| # expansionRule は explicitOnly(指定Pathを明確に指定?)
# expandPrims は rel-targets以下のすべてのPrim こっちがデフォルト
print(newScn.GetRootLayer().ExportToString())
|
Success
1
2
3
4
5
6
7
8
9
10
11
12
13 | #usda 1.0
def Xform "World" (
prepend apiSchemas = ["CollectionAPI:test"]
)
{
uniform token collection:test:expansionRule = "expandPrims"
prepend rel collection:test:includes = </World/Sphere>
def Sphere "Sphere"
{
}
}
|
In [48]:
| collection = Usd.CollectionAPI.GetCollection(prim, 'test')
# Collection名取得
print(collection.GetName())
# CollectionまでのPathを取得
print(collection.GetCollectionPath())
# CollectionはRelation構造になってるので、ソレを利用してPrimを取得
print(collection.GetIncludesRel().GetTargets())
|
Success
| test
/World.collection:test
[Sdf.Path('/World/Sphere')]
|
In [49]:
| # Getでも取得できるぽい
print(Usd.CollectionAPI.Get(prim, 'test'))
|
Success
| <pxr.Usd.CollectionAPI object at 0x0000000006CD5C48>
|