Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UsdView: Display resolved labels in attribute editor #3300

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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):
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))