コンテンツにスキップ

Metadataを仕込む

ipynbFile USDMetadata__Metadataを仕込む.ipynb

In [67]:

1
from pxr import Usd,Vt

In [68]:

1
2
3
4
5
6
stage = Usd.Stage.CreateInMemory()
layer = stage.GetRootLayer()
prim = stage.DefinePrim('/testPrim')
path = prim.GetPath()

layer.defaultPrim = '/testPrim'

In [69]:

1
2
3
4
5
# レイヤーに対して色々Metadataを入れる
layer.comment = 'hello world'
layer.documentation = 'docs'
layer.startTimeCode = 1
layer.endTimeCode = 30

In [70]:

1
2
3
4
5
6
# Primに対しても入れる
# 配列の場合は Vt.~~Arrayを使う必要あり。
prim.SetCustomDataByKey('value', 10) # Int
prim.SetCustomDataByKey('listdata',Vt.StringArray(['a','b','c']))
prim.SetCustomDataByKey('intlist',Vt.IntArray([1,2,3,4,5]))
prim.SetDocumentation('hello world')

Success

1
True

In [71]:

1
2
3
4
5
# AttributeにもMetadataを入れられる
attr = prim.CreateAttribute('testAttr',Sdf.ValueTypeNames.String)
attr.Set('hoge')
# Attributeに対してもMetadataを仕込める
attr.SetCustomDataByKey('meta','data')

In [72]:

1
prim.GetAllMetadata()

Success

1
2
3
4
5
{'customData': {'intlist': Vt.IntArray(5, (1, 2, 3, 4, 5)),
  'listdata': Vt.StringArray(3, ('a', 'b', 'c')),
  'value': 10},
 'documentation': 'hello world',
 'specifier': Sdf.SpecifierDef}

In [73]:

1
print(layer.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
(
    "hello world"
    defaultPrim = "/testPrim"
    doc = "docs"
    endTimeCode = 30
    startTimeCode = 1
)

def "testPrim" (
    customData = {
        int[] intlist = [1, 2, 3, 4, 5]
        string[] listdata = ["a", "b", "c"]
        int value = 10
    }
    doc = "hello world"
)
{
    custom string testAttr = "hoge" (
        customData = {
            string meta = "data"
        }
    )
}

最終更新日: 2021-06-11 08:39:11