Variantの挙動を調べる_1
ipynbFile variantset01__Variantの挙動を調べる_1.ipynb
In [123]:
In [124]:
| stage = Usd.Stage.CreateInMemory()
prim = stage.DefinePrim("/VariantSet")
|
In [125]:
| vset = prim.GetVariantSets().AddVariantSet('hogehoge')
vset.AddVariant('A')
vset.AddVariant('B')
vset.AddVariant('C')
print(vset)
|
Success
| <pxr.Usd.VariantSet object at 0x000002C0014160B8>
|
In [126]:
| # VariantSetを取得
prim.GetVariantSets().GetNames()
|
In [127]:
| vset = prim.GetVariantSets().GetVariantSet("hogehoge")
vset.SetVariantSelection('A')
# 今選択されているものを表示
print(vset.GetVariantSelection())
# VariatnSetがあるPrimを取得
print(vset.GetPrim())
|
Success
| A
Usd.Prim(</VariantSet>)
|
In [128]:
| vset.SetVariantSelection('A')
with vset.GetVariantEditContext():
# VariantSet「A」を選んでいる時には VariantSet/hoge というPrimができあがる
childPrim = stage.DefinePrim(prim.GetPath().AppendChild("hoge"))
|
In [129]:
| vset.SetVariantSelection('B')
with vset.GetVariantEditContext():
childPrim = stage.DefinePrim(prim.GetPath().AppendChild("hogeB"))
childPrim.GetReferences().AddReference(r"D:\work\usd_py36\usd\layerB.usda")
|
In [130]:
| vset.SetVariantSelection('C')
with vset.GetVariantEditContext():
prim.CreateAttribute("TEST",Sdf.ValueTypeNames.String).Set("HOGE")
|
In [131]:
| print(stage.GetRootLayer().ExportToString())
|
Success
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30 | #usda 1.0
def "VariantSet" (
variants = {
string hogehoge = "C"
}
prepend variantSets = "hogehoge"
)
{
variantSet "hogehoge" = {
"A" {
def "hoge"
{
}
}
"B" {
def "hogeB" (
prepend references = @D:\work\usd_py36\usd\layerB.usda@
)
{
}
}
"C" {
custom string TEST = "HOGE"
}
}
}
|
In [132]:
| vset.SetVariantSelection('A')
print(stage.Flatten().ExportToString())
|
Success
1
2
3
4
5
6
7
8
9
10
11
12 | #usda 1.0
(
doc = """Generated from Composed Stage of root layer
"""
)
def "VariantSet"
{
def "hoge"
{
}
}
|
In [133]:
| vset.SetVariantSelection('B')
print(stage.Flatten().ExportToString())
|
Success
1
2
3
4
5
6
7
8
9
10
11
12 | #usda 1.0
(
doc = """Generated from Composed Stage of root layer
"""
)
def "VariantSet"
{
def "hogeB"
{
}
}
|
In [134]:
| vset.SetVariantSelection('C')
print(stage.Flatten().ExportToString())
|
Success
| #usda 1.0
(
doc = """Generated from Composed Stage of root layer
"""
)
def "VariantSet"
{
custom string TEST = "HOGE"
}
|
In [135]:
| stage.GetRootLayer().Export("D:/test.usda")
|
In [136]:
Success
| [Sdf.Find('anon:000002C06682DA70:tmp.usda', '/VariantSet'),
Sdf.Find('anon:000002C06682DA70:tmp.usda', '/VariantSet{hogehoge=C}')]
|
In [138]:
| vset.SetVariantSelection('B')
a = stage.GetPrimAtPath("/VariantSet/hogeB")
print(a.GetPrimStack())
|
Success
| [Sdf.Find('anon:000002C06682DA70:tmp.usda', '/VariantSet{hogehoge=B}hogeB')]
|
In [139]:
| spec = a.GetPrimStack()[0] #PrimSpecを取得できる
|
In [140]:
| # PrimSpecからReferenceのUSDAは取得できるっぽい
for ref in spec.referenceList.prependedItems:
print(ref.assetPath)
|
Success
| D:\work\usd_py36\usd\layerB.usda
|