コンテンツにスキップ

USDCollectionの基本操作

ipynbFile USDCollectoinSample__USDCollectionの基本操作.ipynb

[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()

[46]:

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

Success

True

[47]:

# expansionRule は explicitOnly(指定Pathを明確に指定?)
# expandPrims は rel-targets以下のすべてのPrim こっちがデフォルト
print(newScn.GetRootLayer().ExportToString())

Success

#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"
    {
    }
}

[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')]

[49]:

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

Success

<pxr.Usd.CollectionAPI object at 0x0000000006CD5C48>

最終更新日: 2020-01-19 03:13:27