Skip to content

UsdPrimCompositionQueryを使ってみる

ipynbFile compQuery__UsdPrimCompositionQueryを使ってみる.ipynb

In [8]:

1
from pxr import Usd

In [9]:

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

In [10]:

1
prim = stage.GetPrimAtPath("/Kitchen_set/Props_grp/North_grp/SinkArea_grp/Sink_grp/BowlF_3")

In [11]:

1
2
# PCPを使うより、かんたんにコンポジションを取得できる
query = Usd.PrimCompositionQuery(prim)

In [12]:

1
2
3
4
# フィルタをかけてコンポジションを取得@リファレンスの場合
filter = Usd.PrimCompositionQuery.Filter()
filter.arcTypeFilter = Usd.PrimCompositionQuery.ArcTypeFilter.Variant # Variant / Payload でも可 デフォルトはAllになっている
query = Usd.PrimCompositionQuery(prim,filter)

In [13]:

1
2
# Filterを取得したい場合
print(query.filter)

Success

1
<pxr.Usd.Filter object at 0x000002297BC323F0>

In [14]:

1
2
# これでもOK
query = Usd.PrimCompositionQuery.GetDirectReferences(prim)

In [15]:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
# コンポジションを取得
# PrimConpositionQueryに指定したfilterに一致したコンポジションを取得できる
compArc = query.GetCompositionArcs()
print(compArc)
for comp in compArc:
    print(comp.HasSpecs())
    print(comp.GetArcType())
    print(comp.GetIntroducingPrimPath())
    print(comp.GetIntroducingListEditor())
    print(comp.GetIntroducingLayer())
    print(comp.IsIntroducedInRootLayerStack())
    print(comp.GetIntroducingListEditor()[0])
    print("---")

Success

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
[<pxr.Usd.CompositionArc object at 0x000002297B9E37B0>, <pxr.Usd.CompositionArc object at 0x000002297BC092B0>]
True
Pcp.ArcTypeReference
/Kitchen_set/Props_grp/North_grp/SinkArea_grp/Sink_grp/BowlF_3
(<pxr.Sdf.ListEditorProxy_SdfReferenceTypePolicy object at 0x000002297BC32510>, Sdf.Reference('./assets/Bowl/Bowl.usd'))
Sdf.Find('d:/Kitchen_set/Kitchen_set.usd')
True
{ 'added': [SdfReference(./assets/Bowl/Bowl.usd, , SdfLayerOffset(0, 1), {})]'prepended': []'appended': [], 'deleted': [], 'ordered': [] }
---
True
Pcp.ArcTypeReference
/Bowl
(<pxr.Sdf.ListEditorProxy_SdfReferenceTypePolicy object at 0x000002297BC32810>, Sdf.Reference('./Bowl.geom.usd', Sdf.Path('/Bowl')))
Sdf.Find('d:/Kitchen_set/assets/Bowl/Bowl_payload.usd')
False
{ 'added': [SdfReference(./Bowl.geom.usd, /Bowl, SdfLayerOffset(0, 1), {})]'prepended': []'appended': [], 'deleted': [], 'ordered': [] }
---

In [16]:

1
filter.hasSpecsFilter = Usd.PrimCompositionQuery.HasSpecsFilter.HasSpecs

In [19]:

1
arc = compArc[0]

In [21]:

1
2
# 
print(arc.GetIntroducingNode())

Success

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

In [22]:

1
print(arc.HasSpecs())

Success

1
True