From 7c02ddd47f79c25e0920f116a7a4e6bd119d9701 Mon Sep 17 00:00:00 2001 From: aszabo Date: Fri, 9 Aug 2024 16:00:44 -0600 Subject: [PATCH] Display the selected prim's computed taxonomies and corresponding lables in the attributes editor --- .../testUsdviewPropertySearch.py | 2 +- pxr/usdImaging/usdviewq/customAttributes.py | 27 ++++++++++++++++--- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/pxr/usdImaging/bin/testusdview/testenv/testUsdviewPropertySearch/testUsdviewPropertySearch.py b/pxr/usdImaging/bin/testusdview/testenv/testUsdviewPropertySearch/testUsdviewPropertySearch.py index 5d6b51f7ec..dafb6090ea 100644 --- a/pxr/usdImaging/bin/testusdview/testenv/testUsdviewPropertySearch/testUsdviewPropertySearch.py +++ b/pxr/usdImaging/bin/testusdview/testenv/testUsdviewPropertySearch/testUsdviewPropertySearch.py @@ -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']) diff --git a/pxr/usdImaging/usdviewq/customAttributes.py b/pxr/usdImaging/usdviewq/customAttributes.py index b29ab1cd5a..2946488b90 100644 --- a/pxr/usdImaging/usdviewq/customAttributes.py +++ b/pxr/usdImaging/usdviewq/customAttributes.py @@ -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 @@ -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. @@ -35,8 +36,9 @@ def _GetCustomAttributes(currentPrim, rootDataModel): LocalToWorldXformAttribute(currentPrim, rootDataModel), ResolvedPreviewMaterial(currentPrim, rootDataModel), - ResolvedFullMaterial(currentPrim, rootDataModel)] - + ResolvedFullMaterial(currentPrim, rootDataModel), + ResolvedLabelsAttribute(currentPrim, rootDataModel), + ] return [] # @@ -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.""" @@ -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))