Skip to content

Commit

Permalink
Merge pull request #2885 from sirpalee/pr/compliance-checker-producin…
Browse files Browse the repository at this point in the history
…g-attr

Using get value producing attrs when checking texture assets in NormalMapTextureChecker

(Internal change: 2311331)
  • Loading branch information
pixar-oss committed Jan 12, 2024
2 parents d6c0dab + 82b4765 commit 1e2baf4
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 4 deletions.
10 changes: 10 additions & 0 deletions pxr/usd/bin/usdchecker/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,34 @@ def "World"
normal3f inputs:normal.connect = </World/material/NormalMap.outputs:rgb>
}
}
}

# 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 = </World/assetOnMaterial.inputs:file>
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 = </World/assetOnMaterial.inputs:file>
float3 outputs:rgb
}

def Shader "Surface"
{
uniform token info:id = "UsdPreviewSurface"
color3f inputs:diffuseColor.connect = </World/assetOnMaterial/ColorMap.outputs:rgb>
normal3f inputs:normal.connect = </World/assetOnMaterial/NormalMap.outputs:rgb>
}
}
}
14 changes: 11 additions & 3 deletions pxr/usd/usdUtils/complianceChecker.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.Input.IsInput(valueProducingAttrs[0]):
return None
return valueProducingAttrs[0].Get(Usd.TimeCode.EarliestTime())

def CheckPrim(self, prim):
from pxr import UsdShade, Gf
Expand Down

0 comments on commit 1e2baf4

Please sign in to comment.