USDのインスタンス
ipynbFile usd_instance__USDのインスタンス.ipynb
In [1]:
from pxr import Usd , UsdGeom , Sdf
In [2]:
stage = Usd . Stage . Open ( "D:/Kitchen_set/Kitchen_set_instanced.usd" )
In [44]:
for prim in stage . Traverse ():
if prim . IsInstance ():
# instanceable なPrimを列挙する
# Primから、InstanceのPrototype(ベース)のPrimを取得する
protoPrim = prim . GetPrototype ()
In [4]:
# instanceable が指定されたPrimは、
# StageにPrototypePrimとして登録される。
prototypes = stage . GetPrototypes ()
print ( prototypes [ 0 ] . IsPrototype ())
In [7]:
canA = stage . GetPrimAtPath ( '/Kitchen_set/Props_grp/West_grp/TinCanA_1' )
canB = stage . GetPrimAtPath ( '/Kitchen_set/Props_grp/West_grp/TinCanA_2' )
# 同じモデルなので、Prototypeは共通
print ( canA . GetPrototype ())
print ( canB . GetPrototype ())
Success
Usd.Prim(</__Prototype_2>)
Usd.Prim(</__Prototype_2>)
In [2]:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 stage = Usd . Stage . CreateInMemory ()
primA = stage . DefinePrim ( "/sampleA" )
primA . GetReferences () . AddReference ( './cube.usd' )
primA . SetInstanceable ( True )
primB = stage . DefinePrim ( "/sampleB" )
primB . SetInstanceable ( True )
primB . GetReferences () . AddReference ( './cube.usd' )
primC = stage . DefinePrim ( "/sampleC" )
primC . GetReferences () . AddReference ( './cube.usd' )
# Instanceの場合はChildはみつからない
print ( primB . GetChildren ())
# 普通なら見つかる
print ( primC . GetChildren ())
Success
[]
[Usd.Prim(</sampleC/cube>)]
In [6]:
prototype = primA . GetPrototype ()
for instance in prototype . GetInstances ():
print ( instance )
Success
Usd.Prim(</sampleA>)
Usd.Prim(</sampleB>)
In [47]:
stage . GetRootLayer () . Export ( "./instance.usd" )
In [38]:
for i in primB . GetPrototype () . GetChildren ():
print ( i )
Success
Usd.Prim(</__Prototype_1/cube>)
In [49]:
prototypes = stage . GetPrototypes ()
prototype = prototypes [ 0 ]
In [50]:
Success
[Usd.Prim(</sampleA>), Usd.Prim(</sampleB>)]
In [61]:
# InstanceのPrimも GetPrimAtPathで取得が可能
proxy = stage . GetPrimAtPath ( "/sampleA/cube" )
# Proxyの場合、値の追加や変更を使用するとエラーになる
proxy . CreateAttribute ( 'sample' , Sdf . ValueTypeNames . String ) . Set ( 'hoge' )
Error
ErrorException Traceback (most recent call last)
in
2 proxy = stage.GetPrimAtPath("/sampleA/cube")
3 # Proxyの場合、値の追加や変更を使用するとエラーになる
----> 4 proxy.CreateAttribute('sample',Sdf.ValueTypeNames.String).Set('hoge')
ErrorException:
Error in 'pxrInternal_v0_21__pxrReserved__::UsdStage::_ValidateEditPrim' at line 1297 in file D:\work\GithubRepo\USD\pxr\usd\usd\stage.cpp : 'Cannot create property spec at path ; authoring to an instance proxy is not allowed.'
In [66]:
# ProxyからPrototype側でのPathを取得
protoPrim = proxy . GetPrimInPrototype ()
protoPrim . CreateAttribute ( 'sample' , Sdf . ValueTypeNames . String ) . Set ( 'hoge' )
Error
ErrorException Traceback (most recent call last)
in
1 # ProxyからPrototype側でのPathを取得
2 protoPrim = proxy.GetPrimInPrototype()
----> 3 protoPrim.CreateAttribute('sample',Sdf.ValueTypeNames.String).Set('hoge')
ErrorException:
Error in 'pxrInternal_v0_21__pxrReserved__::UsdStage::_ValidateEditPrim' at line 1290 in file D:\work\GithubRepo\USD\pxr\usd\usd\stage.cpp : 'Cannot create property spec at path ; authoring to an instancing prototype is not allowed.'