コンテンツにスキップ

SdfLayer_UsdStage

ipynbFile SdfLayer_01__SdfLayer_UsdStage.ipynb

In [52]:

1
2
from pxr import Usd,Sdf
import os

In [53]:

1
2
layer = Sdf.Layer.CreateAnonymous()
layer.Reload()

Success

1
False

In [54]:

1
spec = Sdf.CreatePrimInLayer(layer,'/sample')

In [55]:

1
print(layer.ExportToString())

Success

1
2
3
4
5
#sdf 1.4.32

over "sample"
{
}

In [56]:

1
2
# MetaDataの一覧を表示
print(spec.GetMetaDataInfoKeys())

Success

1
['apiSchemas', 'suffixSubstitutions', 'active', 'symmetryArguments', 'assetInfo', 'instanceable', 'customData', 'displayGroupOrder', 'documentation', 'hidden', 'kind', 'payload', 'permission', 'clips', 'prefix', 'prefixSubstitutions', 'suffix', 'symmetricPeer', 'symmetryFunction', 'typeName', 'sample_metadata', 'payloadAssetDependencies', 'inactiveIds', 'clipSets', 'sdrMetadata']

In [57]:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
# PrimSpec
spec.GetObjectAtPath('/sample')
print(spec.attributes)
print(spec.properties)
spec.customData
print(spec.nameRoot)
print(spec.payloadList)
print(spec.referenceList)
print(spec.relationships)
print(spec.specifier)
print(spec.kind)
# overではなく defにする
spec.specifier = Sdf.SpecifierDef # Defaultは Sdf.SpecifierOver

Success

1
2
3
4
5
6
7
{}
{}
Sdf.Find('anon:0000020E4E1F5600', '/')
{ 'added': []'prepended': []'appended': [], 'deleted': [], 'ordered': [] }
{ 'added': []'prepended': []'appended': [], 'deleted': [], 'ordered': [] }
{}
Sdf.SpecifierOver

In [59]:

1
print(layer.ExportToString())

Success

1
2
3
4
5
#sdf 1.4.32

def "sample"
{
}

In [60]:

1
2
3
# Stageを使用してLayerを操作
stage = Usd.Stage.Open(layer)
prim = stage.DefinePrim('/sampleB')

In [61]:

1
print(layer.ExportToString())

Success

1
2
3
4
5
6
7
8
9
#sdf 1.4.32

def "sample"
{
}

def "sampleB"
{
}

In [73]:

1
2
3
4
5
# Referenceを指定
prim.GetReferences().AddReference(f'{os.getcwd()}/usd/sample.usda')
# Attribute追加
attr = prim.CreateAttribute('hoge',Sdf.ValueTypeNames.String)
attr.Set("fugafuga")

Success

1
True

In [63]:

1
print(layer.ExportToString())

Success

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
#sdf 1.4.32

def "sample"
{
}

def "sampleB" (
    prepend references = @c:\reincarnation_tech\notebooks\USD\Stage/usd/sample.usda@
)
{
}

In [68]:

1
2
3
# LayerからPrimSpecを取得して、referenceを取得する
specB = layer.GetPrimAtPath('/sampleB')
print(specB.referenceList)

Success

1
{ 'added': []'prepended': [SdfReference(c:\reincarnation_tech\notebooks\USD\Stage/usd/sample.usda, , SdfLayerOffset(0, 1), {})]'appended': [], 'deleted': [], 'ordered': [] }

In [90]:

1
2
# SpecからAttribute取得
attrSpec = specB.attributes['hoge']

In [91]:

1
2
3
4
# AttributeNameを取得
print(attrSpec.name)
# Specから値を取得
print(attrSpec.default)

Success

1
2
hoge
fugafuga

最終更新日: 2021-07-10 20:30:30