コンテンツにスキップ

ipynbFile USDAttribute_connections.ipynb

AttributeのConnectionを試す

In [3]:

1
from pxr import Usd,Sdf

In [8]:

1
2
stage = Usd.Stage.CreateInMemory()
stage.Reload()

In [24]:

1
2
3
4
5
6
7
prim = stage.DefinePrim("/Sample")
attr = prim.CreateAttribute('hoge',Sdf.ValueTypeNames.Int)
attr.Set(10)

primB = stage.DefinePrim("/srcPrim")
attrB = primB.CreateAttribute("src",Sdf.ValueTypeNames.Int)
attrB.Set(100)

Success

1
True

In [12]:

1
2
3
4
# アトリビュートのコネクションをする

attr.AddConnection(attrB.GetPath())
print(stage.ExportToString())

Success

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
#usda 1.0
(
    doc = """Generated from Composed Stage of root layer 
"""
)

def "Sample"
{
    custom int hoge = 10
    int hoge.connect = </srcPrim.src>
}

def "srcPrim"
{
    custom int src = 100
}

In [17]:

1
2
3
4
5
6
7
# 接続先のアトリビュートを取得すると、そのSdfPathがとれるので
# それを利用して接続先の値を取得
print(attr.GetConnections())
# 接続先の値を取得
for i in attr.GetConnections():
    attr = stage.GetAttributeAtPath(i)
    print(attr.Get())

Success

1
[]

In [35]:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
# コンポジションする場合

stageB = Usd.Stage.CreateInMemory()
layer = stageB.GetRootLayer()
layer.subLayerPaths = [stage.GetRootLayer().identifier]

primB = stageB.DefinePrim("/srcPathB")
attrB = primB.CreateAttribute("srcB",Sdf.ValueTypeNames.Int)
attrB.Set(1000)
print(attrB.GetPath())
toAttr = stageB.GetAttributeAtPath("/Sample.hoge")
toAttr.AddConnection(attrB.GetPath())

Success

1
/srcPathB.srcB

Success

1
True

In [38]:

1
2
3
4
print(toAttr.GetConnections())
print(toAttr.HasAuthoredConnections())

print(stageB.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
[Sdf.Path('/srcPathB.srcB'), Sdf.Path('/srcPrim.src')]
#usda 1.0
(
    doc = """Generated from Composed Stage of root layer 
"""
)

def "Sample"
{
    custom int hoge = 10
    int hoge.connect = [
        </srcPathB.srcB>,
        </srcPrim.src>,
    ]
}

def "srcPrim"
{
    custom int src = 100
}

def "srcPathB"
{
    custom int srcB = 1000
}


True