コンテンツにスキップ

PcpAPIでコンポジションアークを調べる

ipynbFile USDPCP_01__PcpAPIでコンポジションアークを調べる.ipynb

In [2]:

1
from pxr import Usd,Pcp

In [3]:

1
stage = Usd.Stage.Open(r"D:\Kitchen_set\Kitchen_set.usd")

In [4]:

1
2
3
4
5
# PrimからIndexを取得し、PcpNodeRefを取得する
prim = stage.GetPrimAtPath("/Kitchen_set/Props_grp/North_grp/FridgeArea_grp/Refridgerator_1")
index = prim.GetPrimIndex()
rootRef = index.rootNode
print(rootRef)

Success

1
<pxr.Pcp.NodeRef object at 0x00000252D7561608>

In [30]:

1
2
3
4
5
6
7
8
layerTree = layerStack.layerTree
# subLayerも木構造を取得できる
def traverse(node):
    print(node.layer)
    print(node.offset)
    for child in node.childTrees:
        print(child)
traverse(layerTree)

Success

1
2
Sdf.Find('d:/Kitchen_set/Kitchen_set.usd')
Sdf.LayerOffset()

In [31]:

1
2
3
# identifier経由でLayerを取得する場合
identifier = layerStack.identifier
print(identifier.rootLayer)

Success

1
Sdf.Find('d:/Kitchen_set/Kitchen_set.usd')

In [16]:

1
2
3
4
5
# PrimIndexのPrimの子Prim,Propertyを取得
print(index.ComputePrimChildNames())
print(index.ComputePrimPropertyNames())
print(index.primStack)
print(index.hasAnyPayloads)

Success

1
2
3
4
(['Geom'], [])
['xformOp:translate', 'xformOpOrder']
[]
True

In [12]:

1
help(index)

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
Help on PrimIndex in module pxr.Pcp object:

class PrimIndex(Boost.Python.instance)
 |  Method resolution order:
 |      PrimIndex
 |      Boost.Python.instance
 |      builtins.object
 |  
 |  Methods defined here:
 |  
 |  ComposeAuthoredVariantSelections(...)
 |  
 |  ComputePrimChildNames(...)
 |  
 |  ComputePrimPropertyNames(...)
 |  
 |  DumpToDotGraph(...)
 |  
 |  DumpToString(...)
 |  
 |  GetSelectionAppliedForVariantSet(...)
 |  
 |  IsInstanceable(...)
 |  
 |  IsValid(...)
 |  
 |  PrintStatistics(...)
 |  
 |  __init__(...)
 |      Raises an exception
 |      This class cannot be instantiated from Python
 |  
 |  __reduce__ = <unnamed Boost.Python function>(...)
 |  
 |  ----------------------------------------------------------------------
 |  Data descriptors defined here:
 |  
 |  hasAnyPayloads
 |  
 |  localErrors
 |  
 |  primStack
 |  
 |  rootNode
 |  
 |  ----------------------------------------------------------------------
 |  Methods inherited from Boost.Python.instance:
 |  
 |  __new__(*args, **kwargs) from Boost.Python.class
 |      Create and return a new object.  See help(type) for accurate signature.
 |  
 |  ----------------------------------------------------------------------
 |  Data descriptors inherited from Boost.Python.instance:
 |  
 |  __dict__
 |  
 |  __weakref__

In [6]:

1
2
3
# EditTarget取得してTargetLayerに指定する
et = Usd.EditTarget(rootRef.layerStack.layers[0],rootRef)
stage.SetEditTarget(et)

In [44]:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
# コンポジションを再帰で検索
def traverse(node):
    # コンポジションタイプ
    print(node.arcType) #CompositionArc
    print(node.path) #SdfPath
    print(node.site) #Layer + SdfPath
    print(node.GetRootNode()) # RootNode
    layer = node.layerStack.layers[0] # Layer取得
    print(layer)
    for child in node.children:
        traverse(child)
traverse(rootRef)

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
Pcp.ArcTypeRoot
/Kitchen_set/Props_grp/North_grp/FridgeArea_grp/Refridgerator_1
@d:/Kitchen_set/Kitchen_set.usd@,@anon:0000027614F5B360:Kitchen_set-session.usda@</Kitchen_set/Props_grp/North_grp/FridgeArea_grp/Refridgerator_1>
<pxr.Pcp.NodeRef object at 0x00000276493A73A0>
Sdf.Find('anon:0000027614F5B360:Kitchen_set-session.usda')
Pcp.ArcTypeReference
/Refridgerator
@d:/Kitchen_set/assets/Refridgerator/Refridgerator.usd@</Refridgerator>
<pxr.Pcp.NodeRef object at 0x00000276493A71E8>
Sdf.Find('d:/Kitchen_set/assets/Refridgerator/Refridgerator.usd')
Pcp.ArcTypeVariant
/Refridgerator{modelingVariant=Decorated}
@d:/Kitchen_set/assets/Refridgerator/Refridgerator.usd@</Refridgerator{modelingVariant=Decorated}>
<pxr.Pcp.NodeRef object at 0x00000276493A7920>
Sdf.Find('d:/Kitchen_set/assets/Refridgerator/Refridgerator.usd')
Pcp.ArcTypePayload
/Refridgerator
@d:/Kitchen_set/assets/Refridgerator/Refridgerator_payload.usd@</Refridgerator>
<pxr.Pcp.NodeRef object at 0x00000276493A7920>
Sdf.Find('d:/Kitchen_set/assets/Refridgerator/Refridgerator_payload.usd')
Pcp.ArcTypeReference
/Refridgerator
@d:/Kitchen_set/assets/Refridgerator/Refridgerator.geom.usd@</Refridgerator>
<pxr.Pcp.NodeRef object at 0x00000276493A7710>
Sdf.Find('d:/Kitchen_set/assets/Refridgerator/Refridgerator.geom.usd')
Pcp.ArcTypeVariant
/Refridgerator{modelingVariant=Decorated}
@d:/Kitchen_set/assets/Refridgerator/Refridgerator.geom.usd@</Refridgerator{modelingVariant=Decorated}>
<pxr.Pcp.NodeRef object at 0x0000027648AEAFA8>
Sdf.Find('d:/Kitchen_set/assets/Refridgerator/Refridgerator.geom.usd')

In [21]:

1
2
# PcpNodeRefをGraphvizでビジュアライズ
index.DumpToDotGraph("D:/test.dot")

In [30]:

1
2
# PcpNdoeRefをテキストでDump
print(index.DumpToString())

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
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
Node 0:
    Parent node:              NONE
    Type:                     root
    DependencyType:           root
    Source path:              </Kitchen_set/Props_grp/North_grp/FridgeArea_grp/Refridgerator_1>
    Source layer stack:       @d:/Kitchen_set/Kitchen_set.usd@,@anon:0000027614F5B360:Kitchen_set-session.usda@
    Target path:              <NONE>
    Target layer stack:       NONE
    Map to parent:
        / -> /
    Map to root:
        / -> /
    Namespace depth:          0
    Depth below introduction: 0
    Permission:               Public
    Is restricted:            FALSE
    Is inert:                 FALSE
    Contribute specs:         TRUE
    Has specs:                TRUE
    Has symmetry:             FALSE
Node 1:
    Parent node:              0
    Type:                     reference
    DependencyType:           non-virtual, purely-direct
    Source path:              </Refridgerator>
    Source layer stack:       @d:/Kitchen_set/assets/Refridgerator/Refridgerator.usd@
    Target path:              </Kitchen_set/Props_grp/North_grp/FridgeArea_grp/Refridgerator_1>
    Target layer stack:       @d:/Kitchen_set/Kitchen_set.usd@,@anon:0000027614F5B360:Kitchen_set-session.usda@
    Map to parent:
        /Refridgerator -> /Kitchen_set/Props_grp/North_grp/FridgeArea_grp/Refridgerator_1
    Map to root:
        /Refridgerator -> /Kitchen_set/Props_grp/North_grp/FridgeArea_grp/Refridgerator_1
    Namespace depth:          5
    Depth below introduction: 0
    Permission:               Public
    Is restricted:            FALSE
    Is inert:                 FALSE
    Contribute specs:         TRUE
    Has specs:                TRUE
    Has symmetry:             FALSE
Node 2:
    Parent node:              1
    Type:                     variant
    DependencyType:           non-virtual, purely-direct
    Source path:              </Refridgerator{modelingVariant=Decorated}>
    Source layer stack:       @d:/Kitchen_set/assets/Refridgerator/Refridgerator.usd@
    Target path:              </Refridgerator>
    Target layer stack:       @d:/Kitchen_set/assets/Refridgerator/Refridgerator.usd@
    Map to parent:
        / -> /
    Map to root:
        /Refridgerator -> /Kitchen_set/Props_grp/North_grp/FridgeArea_grp/Refridgerator_1
    Namespace depth:          1
    Depth below introduction: 0
    Permission:               Public
    Is restricted:            FALSE
    Is inert:                 FALSE
    Contribute specs:         TRUE
    Has specs:                TRUE
    Has symmetry:             FALSE

Node 3:
    Parent node:              1
    Type:                     payload
    DependencyType:           non-virtual, purely-direct
    Source path:              </Refridgerator>
    Source layer stack:       @d:/Kitchen_set/assets/Refridgerator/Refridgerator_payload.usd@
    Target path:              </Refridgerator>
    Target layer stack:       @d:/Kitchen_set/assets/Refridgerator/Refridgerator.usd@
    Map to parent:
        /Refridgerator -> /Refridgerator
    Map to root:
        /Refridgerator -> /Kitchen_set/Props_grp/North_grp/FridgeArea_grp/Refridgerator_1
    Namespace depth:          1
    Depth below introduction: 0
    Permission:               Public
    Is restricted:            FALSE
    Is inert:                 FALSE
    Contribute specs:         TRUE
    Has specs:                TRUE
    Has symmetry:             FALSE
Node 4:
    Parent node:              3
    Type:                     reference
    DependencyType:           non-virtual, purely-direct
    Source path:              </Refridgerator>
    Source layer stack:       @d:/Kitchen_set/assets/Refridgerator/Refridgerator.geom.usd@
    Target path:              </Refridgerator>
    Target layer stack:       @d:/Kitchen_set/assets/Refridgerator/Refridgerator_payload.usd@
    Map to parent:
        /Refridgerator -> /Refridgerator
    Map to root:
        /Refridgerator -> /Kitchen_set/Props_grp/North_grp/FridgeArea_grp/Refridgerator_1
    Namespace depth:          1
    Depth below introduction: 0
    Permission:               Public
    Is restricted:            FALSE
    Is inert:                 FALSE
    Contribute specs:         TRUE
    Has specs:                TRUE
    Has symmetry:             FALSE
Node 5:
    Parent node:              4
    Type:                     variant
    DependencyType:           non-virtual, purely-direct
    Source path:              </Refridgerator{modelingVariant=Decorated}>
    Source layer stack:       @d:/Kitchen_set/assets/Refridgerator/Refridgerator.geom.usd@
    Target path:              </Refridgerator>
    Target layer stack:       @d:/Kitchen_set/assets/Refridgerator/Refridgerator.geom.usd@
    Map to parent:
        / -> /
    Map to root:
        /Refridgerator -> /Kitchen_set/Props_grp/North_grp/FridgeArea_grp/Refridgerator_1
    Namespace depth:          1
    Depth below introduction: 0
    Permission:               Public
    Is restricted:            FALSE
    Is inert:                 FALSE
    Contribute specs:         TRUE
    Has specs:                TRUE
    Has symmetry:             FALSE