Skip to content

Commit

Permalink
Merge pull request #3300 from nvaszabo/nvaszabo/usdview-add-resolved-…
Browse files Browse the repository at this point in the history
…labels-to-attribute-editor

UsdView: Display resolved labels in attribute editor

(Internal change: 2350530)
  • Loading branch information
pixar-oss committed Dec 6, 2024
2 parents 272b9ac + b8ca3fa commit 2e83650
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 6 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
29 changes: 25 additions & 4 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,9 +36,10 @@ def _GetCustomAttributes(currentPrim, rootDataModel):
LocalToWorldXformAttribute(currentPrim,
rootDataModel),
ResolvedPreviewMaterial(currentPrim, rootDataModel),
ResolvedFullMaterial(currentPrim, rootDataModel)]

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

#
# The base class for per-prim custom attributes.
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):
try:
labels = self._rootDataModel.getResolvedLabels(
self._currentPrim, frame)
except RuntimeError as err:
labels = "Invalid: " + str(err)

return labels


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))
13 changes: 12 additions & 1 deletion pxr/usdImaging/usdviewq/rootDataModel.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 Usd, UsdGeom, UsdShade, UsdSemantics
from .qt import QtCore
from .common import IncludedPurposes, Timer
from pxr.UsdUtils.constantsGroup import ConstantsGroup
Expand Down Expand Up @@ -209,3 +209,14 @@ def computeBoundMaterial(self, prim, purpose):
# We don't use the binding cache yet since it isn't exposed to python.
return UsdShade.MaterialBindingAPI(
prim).ComputeBoundMaterial(purpose)

def getResolvedLabels(self, prim, frame):
"""Compute the resolved labels for a prim."""
inheritedTaxonomies = \
UsdSemantics.LabelsAPI.ComputeInheritedTaxonomies(prim)
resolvedLabels: dict[str, list[str]] = {}
for taxonomy in inheritedTaxonomies:
query = UsdSemantics.LabelsQuery(taxonomy, frame)
labels = query.ComputeUniqueInheritedLabels(prim)
resolvedLabels[taxonomy] = list(labels)
return resolvedLabels

0 comments on commit 2e83650

Please sign in to comment.