Skip to content

USDCollectionの基本操作

ipynbFile USDCollectoinSample__USDCollectionの基本操作.ipynb

In [45]:

1
2
3
4
5
6
7
8
9
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]:

1
2
api = Usd.CollectionAPI.ApplyCollection(prim, 'test')
api.IncludePath(spherePrim.GetPath())

Success

1
True

In [47]:

1
2
3
# 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]:

1
2
3
4
5
6
7
collection = Usd.CollectionAPI.GetCollection(prim, 'test')
# Collection名取得
print(collection.GetName())
# CollectionまでのPathを取得
print(collection.GetCollectionPath())
# CollectionはRelation構造になってるので、ソレを利用してPrimを取得
print(collection.GetIncludesRel().GetTargets())

Success

1
2
3
test
/World.collection:test
[Sdf.Path('/World/Sphere')]

In [49]:

1
2
# Getでも取得できるぽい
print(Usd.CollectionAPI.Get(prim, 'test'))

Success

1
<pxr.Usd.CollectionAPI object at 0x0000000006CD5C48>