Skip to content

Commit

Permalink
Display the selected prim's computed taxonomies and corresponding lab…
Browse files Browse the repository at this point in the history
…les in the attributes editor
  • Loading branch information
nvaszabo committed Sep 18, 2024
1 parent 27f71d5 commit 7c02ddd
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def _search(appController, searchTerm, expectedItems):
def _testSearchBasic(appController):
_search(appController, 'a',
['Local to World Xform', 'Resolved Preview Material',
'Resolved Full Material', 'a'])
'Resolved Full Material', 'Resolved Labels', 'a'])
_search(appController, 'myR', ['myRel'])
_search(appController, 'y',
['myRel', 'proxyPrim', 'visibility', 'y'])
Expand Down
27 changes: 24 additions & 3 deletions pxr/usdImaging/usdviewq/customAttributes.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# https://openusd.org/license.
#

from pxr import Usd, UsdGeom, UsdShade
from pxr import UsdGeom, UsdShade, UsdSemantics
from pxr.UsdUtils.constantsGroup import ConstantsGroup


Expand All @@ -15,6 +15,7 @@ class ComputedPropertyNames(ConstantsGroup):
LOCAL_WORLD_XFORM = "Local to World Xform"
RESOLVED_PREVIEW_MATERIAL = "Resolved Preview Material"
RESOLVED_FULL_MATERIAL = "Resolved Full Material"
RESOLVED_LABELS = "Resolved Labels"

#
# Edit the following to alter the set of custom attributes.
Expand All @@ -35,8 +36,9 @@ def _GetCustomAttributes(currentPrim, rootDataModel):
LocalToWorldXformAttribute(currentPrim,
rootDataModel),
ResolvedPreviewMaterial(currentPrim, rootDataModel),
ResolvedFullMaterial(currentPrim, rootDataModel)]

ResolvedFullMaterial(currentPrim, rootDataModel),
ResolvedLabelsAttribute(currentPrim, rootDataModel),
]
return []

#
Expand Down Expand Up @@ -137,6 +139,23 @@ def __init__(self, currentPrim, rootDataModel):
ResolvedBoundMaterial.__init__(self, currentPrim, rootDataModel,
UsdShade.Tokens.preview)

#
# Displays a prim's inherited labels
#
class ResolvedLabelsAttribute(CustomAttribute):
def GetName(self):
return ComputedPropertyNames.RESOLVED_LABELS

def Get(self, frame):
inheritedTaxonomies = UsdSemantics.LabelsAPI.ComputeInheritedTaxonomies(self._currentPrim)
resolvedLabels: dict[str, list[str]] = {}
for taxonomy in inheritedTaxonomies:
query = UsdSemantics.LabelsQuery(taxonomy, frame)
labels = query.ComputeUniqueInheritedLabels(self._currentPrim)
resolvedLabels[taxonomy] = list(labels)
return resolvedLabels


class ComputedPropertyFactory:
"""Creates computed properties."""

Expand All @@ -155,6 +174,8 @@ def getComputedProperty(self, prim, propName):
return ResolvedFullMaterial(prim, self._rootDataModel)
elif propName == ComputedPropertyNames.RESOLVED_PREVIEW_MATERIAL:
return ResolvedPreviewMaterial(prim, self._rootDataModel)
elif propName == ComputedPropertyNames.RESOLVED_LABELS:
return ResolvedLabelsAttribute(prim, self._rootDataModel)
else:
raise ValueError("Cannot create computed property '{}'.".format(
propName))

0 comments on commit 7c02ddd

Please sign in to comment.