Skip to content

UsdStageでできること

ipynbFile UsdStage_01__UsdStageでできること.ipynb
Stageの使い方いろいろテスト

In [1]:

1
from pxr import Usd,Sdf

In [37]:

1
2
3
4
5
6
7
# 既存のUSDファイルをロードする
stage = Usd.Stage.Open("usd/sample.usda")
# 一度ロードしたものをそのあと編集すると、編集した内容がキャッシュされているので
# クリアしたい場合はReloadする
stage.Reload()
# RootLayerをPrintできる
print(stage.ExportToString())

Success

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
#usda 1.0
(
    defaultPrim = "Sample"
    doc = """Generated from Composed Stage of root layer c:\\reincarnation_tech\\notebooks\\USD\\Stage\\usd\\sample.usda
"""
)

def "Sample"
{
}

In [38]:

1
2
3
4
5
# DefaultPrimを取得して、Attributeを追加する
print(stage.HasDefaultPrim()) # DefaultPrimを持っているか
prim = stage.GetDefaultPrim()
prim.CreateAttribute("hoge",Sdf.ValueTypeNames.String).Set("Fuga")
layer = stage.GetRootLayer()

Success

1
True

In [39]:

1
2
3
4
# TimeCode指定
stage.SetStartTimeCode(1)
stage.SetEndTimeCode(30)
print(stage.ExportToString())

Success

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
#usda 1.0
(
    defaultPrim = "Sample"
    doc = """Generated from Composed Stage of root layer c:\\reincarnation_tech\\notebooks\\USD\\Stage\\usd\\sample.usda
"""
    endTimeCode = 30
    startTimeCode = 1
)

def "Sample"
{
    custom string hoge = "Fuga"
}

In [40]:

1
2
3
4
5
# セッションレイヤーを取得して、EditTargetにする
session = stage.GetSessionLayer()
target = Usd.EditTarget(session)
stage.SetEditTarget(target)
session.subLayerPaths = [layer.identifier]

In [41]:

1
2
3
4
5
6
# Targetは、ステージのEdit対象レイヤーのこと。
print(target.GetLayer().identifier)
# どこのSdfPathにMapされるか
print(target.GetMapFunction())
# TargetのレイヤーからPrimSpecを取得する
print(target.GetPrimSpecForScenePath("/Sample"))

Success

1
2
3
anon:000001B2F688ADF0:sample-session.usda
/ -> /
None

In [42]:

1
2
3
4
5
# Prim定義
prim = stage.DefinePrim("/SampleB")
# Overを定義
over = stage.OverridePrim("/Sample")
over.CreateAttribute("fuga",Sdf.ValueTypeNames.String).Set("hoge")

Success

1
True

In [43]:

1
print(session.ExportToString())

Success

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
#usda 1.0
(
    subLayers = [
        @usd/sample.usda@
    ]
)

def "SampleB"
{
}

over "Sample"
{
    custom string fuga = "hoge"
}

In [44]:

1
print(layer.ExportToString())

Success

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
#usda 1.0
(
    defaultPrim = "Sample"
    endTimeCode = 30
    startTimeCode = 1
)

def "Sample"
{
    custom string hoge = "Fuga"
}

In [45]:

1
print(stage.ExportToString())

Success

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
#usda 1.0
(
    defaultPrim = "Sample"
    doc = """Generated from Composed Stage of root layer c:\\reincarnation_tech\\notebooks\\USD\\Stage\\usd\\sample.usda
"""
    endTimeCode = 30
    startTimeCode = 1
)

def "Sample"
{
    custom string fuga = "hoge"
    custom string hoge = "Fuga"
}

def "SampleB"
{
}

In [46]:

1
2
3
# SessionLayerをミュートする
stage.MuteLayer(session.identifier)
print(stage.ExportToString())

Success

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
#usda 1.0
(
    defaultPrim = "Sample"
    doc = """Generated from Composed Stage of root layer c:\\reincarnation_tech\\notebooks\\USD\\Stage\\usd\\sample.usda
"""
    endTimeCode = 30
    startTimeCode = 1
)

def "Sample"
{
    custom string hoge = "Fuga"
}

In [47]:

1
2
3
4
# UnmuteしてTraverse
stage.UnmuteLayer(session.identifier)
for prim in stage.Traverse():
    print(prim)

Success

1
2
Usd.Prim(</Sample>)
Usd.Prim(</SampleB>)

In [48]:

1
2
3
# Memory上にレイヤーを作成する
memStage = Usd.Stage.CreateInMemory()
print(memStage.ExportToString())

Success

1
2
3
4
5
#usda 1.0
(
    doc = """Generated from Composed Stage of root layer 
"""
)

In [49]:

1
2
3
# レイヤースタックを取得
for stack in stage.GetLayerStack():
    print(stack)

Success

1
2
3
Sdf.Find('anon:000001B2F688ADF0:sample-session.usda')
Sdf.Find('usd/sample.usda')
Sdf.Find('usd/sample.usda')

In [36]:

1
2
# レイヤーを取得
print(stage.GetUsedLayers())

Success

1
[Sdf.Find('anon:000001B2F688D8F0:sample-session.usda'), Sdf.Find('usd/sample.usda')]