From 188fb425498bed47861d8f2ed4901cdb72c5cb73 Mon Sep 17 00:00:00 2001 From: Pal Mezei Date: Wed, 27 Dec 2023 13:31:23 +1100 Subject: [PATCH 1/2] Using get value producing attrs when checking texture values in complianceChecker.py. --- pxr/usd/bin/usdchecker/CMakeLists.txt | 10 ++++++ .../clean/cleanNormalMapReader.usda | 31 ++++++++++++++++++- pxr/usd/usdUtils/complianceChecker.py | 14 +++++++-- 3 files changed, 51 insertions(+), 4 deletions(-) diff --git a/pxr/usd/bin/usdchecker/CMakeLists.txt b/pxr/usd/bin/usdchecker/CMakeLists.txt index 173f584a57..18e489c09b 100644 --- a/pxr/usd/bin/usdchecker/CMakeLists.txt +++ b/pxr/usd/bin/usdchecker/CMakeLists.txt @@ -144,3 +144,13 @@ pxr_register_test(testUsdChecker12 EXPECTED_RETURN_CODE 1 ) +pxr_install_test_dir( + SRC testenv/testUsdChecker + DEST testUsdChecker13 +) + +pxr_register_test(testUsdChecker13 + PYTHON + COMMAND "${CMAKE_INSTALL_PREFIX}/bin/usdchecker clean/cleanNormalMapReader.usda" + EXPECTED_RETURN_CODE 0 +) diff --git a/pxr/usd/bin/usdchecker/testenv/testUsdChecker/clean/cleanNormalMapReader.usda b/pxr/usd/bin/usdchecker/testenv/testUsdChecker/clean/cleanNormalMapReader.usda index c11e3caf47..aa8ef11c44 100644 --- a/pxr/usd/bin/usdchecker/testenv/testUsdChecker/clean/cleanNormalMapReader.usda +++ b/pxr/usd/bin/usdchecker/testenv/testUsdChecker/clean/cleanNormalMapReader.usda @@ -35,5 +35,34 @@ def "World" normal3f inputs:normal.connect = } } -} + # Normal map compliance checker should handle connected asset attributes. + def Material "assetOnMaterial" + { + asset inputs:file = @texture.jpg@ + + def Shader "ColorMap" + { + uniform token info:id = "UsdUVTexture" + asset inputs:file.connect = + float3 outputs:rgb + } + + def Shader "NormalMap" + { + uniform token info:id = "UsdUVTexture" + token inputs:sourceColorSpace = "raw" + float4 inputs:scale = (2.0, 2.0, 2.0, 1.0) + float4 inputs:bias = (-1.0, -1.0, -1.0, 0.0) + asset inputs:file.connect = + float3 outputs:rgb + } + + def Shader "Surface" + { + uniform token info:id = "UsdPreviewSurface" + color3f inputs:diffuseColor.connect = + normal3f inputs:normal.connect = + } + } +} diff --git a/pxr/usd/usdUtils/complianceChecker.py b/pxr/usd/usdUtils/complianceChecker.py index 3d19cb3bef..f61cae259b 100644 --- a/pxr/usd/usdUtils/complianceChecker.py +++ b/pxr/usd/usdUtils/complianceChecker.py @@ -458,13 +458,21 @@ def _TextureIs8Bit(self, asset): ext = Ar.GetResolver().GetExtension(asset.resolvedPath) # not an exhaustive list, but ones we typically can read return ext in ["bmp", "tga", "jpg", "jpeg", "png", "tif"] - + def _GetInputValue(self, shader, inputName): - from pxr import Usd + from pxr import Usd, UsdShade input = shader.GetInput(inputName) if not input: return None - return input.Get(Usd.TimeCode.EarliestTime()) + # Query value producing attributes for input values. + # This has to be a length of 1, otherwise no attribute is producing a value. + valueProducingAttrs = UsdShade.Utils.GetValueProducingAttributes(input) + if not valueProducingAttrs or len(valueProducingAttrs) != 1: + return None + # We require an input parameter producing the value. + if not UsdShade.Tokens.inputs.startswith(valueProducingAttrs[0].GetNamespace()): + return None + return valueProducingAttrs[0].Get(Usd.TimeCode.EarliestTime()) def CheckPrim(self, prim): from pxr import UsdShade, Gf From 82b47651591038718e43b437e2240c40c7128bd9 Mon Sep 17 00:00:00 2001 From: Pal Mezei Date: Wed, 10 Jan 2024 11:33:38 +1100 Subject: [PATCH 2/2] Using UsdShade.Input.IsInput to verify that the value producing attr is an input value. --- pxr/usd/usdUtils/complianceChecker.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pxr/usd/usdUtils/complianceChecker.py b/pxr/usd/usdUtils/complianceChecker.py index f61cae259b..b3e6182de0 100644 --- a/pxr/usd/usdUtils/complianceChecker.py +++ b/pxr/usd/usdUtils/complianceChecker.py @@ -470,7 +470,7 @@ def _GetInputValue(self, shader, inputName): if not valueProducingAttrs or len(valueProducingAttrs) != 1: return None # We require an input parameter producing the value. - if not UsdShade.Tokens.inputs.startswith(valueProducingAttrs[0].GetNamespace()): + if not UsdShade.Input.IsInput(valueProducingAttrs[0]): return None return valueProducingAttrs[0].Get(Usd.TimeCode.EarliestTime())