複数のComp組み合わせ
ipynbFile CompArc_01__複数のComp組み合わせ.ipynb
複数のコンポジションを色々組み合わせてみる
In [1]:
In [2]:
| stage = Usd.Stage.CreateInMemory()
stage.Reload()
layer = stage.GetRootLayer()
|
In [3]:
| # Local(そのレイヤーに定義を作る)
prim = stage.DefinePrim("/DefPrim")
stage.SetDefaultPrim(prim)
|
In [4]:
| # Variantのパターンを追加
vset = prim.GetVariantSets().AddVariantSet('hogehoge')
vset.AddVariant('cube')
vset.AddVariant('sphere')
|
In [5]:
| # Inherits用のPrimを作る
cls = stage.CreateClassPrim("/basePrim")
cls.CreateAttribute('addClassParam',Sdf.ValueTypeNames.String).Set("hogehoge")
refBasePrim = stage.CreateClassPrim("/refBasePrim")
refBasePrim.CreateAttribute("addClassParam",Sdf.ValueTypeNames.String).Set("refValue")
|
In [6]:
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 | # Variantを作る
# Variant以下にReferenceがある場合、Vのほうが強いので
# Variantで選んだ選択肢以下のリファレンスがコンポジションされる
vset.SetVariantSelection('cube')
# Variant以下にReference
with vset.GetVariantEditContext():
cprim = stage.DefinePrim(prim.GetPath().AppendChild("cube"))
cprim.GetReferences().AddReference('cube.usda')
cprim.GetInherits().AddInherit('/basePrim')
vset.SetVariantSelection('sphere')
# Variant以下にReference
with vset.GetVariantEditContext():
cprim = stage.DefinePrim(prim.GetPath().AppendChild("sphere"))
cprim.GetReferences().AddReference('sphere.usda')
cprim.GetInherits().AddInherit('/basePrim')
print(prim)
# Inherits付きのPrimを作る
cprim = stage.DefinePrim(prim.GetPath().AppendChild("childA"))
cprim.GetInherits().AddInherit('/basePrim')
cprim = stage.DefinePrim(prim.GetPath().AppendChild("childB"))
cprim.GetInherits().AddInherit('/basePrim')
# ReferenceとInheritsを同時に使う
cprim = stage.DefinePrim(prim.GetPath().AppendChild("childC"))
cprim.GetInherits().AddInherit('/basePrim')
cprim.GetReferences().AddInternalReference("/refBasePrim")
|
In [7]:
| print(layer.ExportToString())
layer.Export("usd/baseLayer.usda")
|
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61 | #usda 1.0
(
defaultPrim = "DefPrim"
)
def "DefPrim" (
variants = {
string hogehoge = "sphere"
}
prepend variantSets = "hogehoge"
)
{
def "childA" (
prepend inherits = </basePrim>
)
{
}
def "childB" (
prepend inherits = </basePrim>
)
{
}
def "childC" (
prepend inherits = </basePrim>
prepend references = </refBasePrim>
)
{
}
variantSet "hogehoge" = {
"cube" {
def "cube" (
prepend inherits = </basePrim>
prepend references = @cube.usda@
)
{
}
}
"sphere" {
def "sphere" (
prepend inherits = </basePrim>
prepend references = @sphere.usda@
)
{
}
}
}
}
class "basePrim"
{
custom string addClassParam = "hogehoge"
}
class "refBasePrim"
{
custom string addClassParam = "refValue"
}
|
In [8]:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 | # サブレイヤー
subStage = Usd.Stage.CreateInMemory()
subLayer = subStage.GetRootLayer()
subLayer.subLayerPaths = ['usd/baseLayer.usda']
subLayer.Export("usd/root.usda")
# サブレイヤーしたレイヤーでClassに対してCreateAttribute
subPrim = subStage.GetPrimAtPath("/basePrim")
subPrim.CreateAttribute('addAttr',Sdf.ValueTypeNames.Int).Set(100)
# SphereのときはOverで値を編集する
over = subStage.OverridePrim("/DefPrim/sphere")
over.GetAttribute('addClassParam').Set('fugafuga')
childB = subStage.GetPrimAtPath("/DefPrim/childB")
childB.GetAttribute('addClassParam').Set('setSubLayer')
|
In [9]:
| print(subStage.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 | #usda 1.0
(
subLayers = [
@usd/baseLayer.usda@
]
)
over "basePrim"
{
custom int addAttr = 100
}
over "DefPrim"
{
over "sphere"
{
custom string addClassParam = "fugafuga"
}
over "childB"
{
custom string addClassParam = "setSubLayer"
}
}
|
In [10]:
| print(subStage.Flatten().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
31
32
33
34
35
36
37
38
39
40
41
42
43 | #usda 1.0
(
doc = """Generated from Composed Stage of root layer
"""
)
def "DefPrim"
{
def Sphere "sphere"
{
custom int addAttr = 100
custom string addClassParam = "fugafuga"
}
def "childA"
{
custom int addAttr = 100
custom string addClassParam = "hogehoge"
}
def "childB"
{
custom int addAttr = 100
custom string addClassParam = "setSubLayer"
}
def "childC"
{
custom int addAttr = 100
custom string addClassParam = "hogehoge"
}
}
class "basePrim"
{
custom int addAttr = 100
custom string addClassParam = "hogehoge"
}
class "refBasePrim"
{
custom string addClassParam = "refValue"
}
|
In [11]:
| # サブレイヤーにVariant切り替えを入れる
v = subStage.GetPrimAtPath('/DefPrim').GetVariantSets().GetVariantSet('hogehoge')
v.SetVariantSelection('cube')
|
In [12]:
| print(subStage.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 | #usda 1.0
(
subLayers = [
@usd/baseLayer.usda@
]
)
over "basePrim"
{
custom int addAttr = 100
}
over "DefPrim" (
variants = {
string hogehoge = "cube"
}
)
{
over "sphere"
{
custom string addClassParam = "fugafuga"
}
over "childB"
{
custom string addClassParam = "setSubLayer"
}
}
|
In [13]:
| print(subStage.Flatten().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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48 | #usda 1.0
(
doc = """Generated from Composed Stage of root layer
"""
)
def "DefPrim"
{
def Cube "cube"
{
custom int addAttr = 100
custom string addClassParam = "hogehoge"
}
def "childA"
{
custom int addAttr = 100
custom string addClassParam = "hogehoge"
}
def "childB"
{
custom int addAttr = 100
custom string addClassParam = "setSubLayer"
}
def "childC"
{
custom int addAttr = 100
custom string addClassParam = "hogehoge"
}
over "sphere"
{
custom string addClassParam = "fugafuga"
}
}
class "basePrim"
{
custom int addAttr = 100
custom string addClassParam = "hogehoge"
}
class "refBasePrim"
{
custom string addClassParam = "refValue"
}
|