Skip to content

Commit

Permalink
Merge pull request #2554 from erikaharrison-adsk/adsk/bugfix/remember…
Browse files Browse the repository at this point in the history
…-matrix33-default-value

Autodesk: Provide enough information to allow matrix33 default values

(Internal change: 2306182)
  • Loading branch information
pixar-oss committed Nov 28, 2023
2 parents d78e3b5 + bcdd4ea commit 0f8376c
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 3 deletions.
5 changes: 3 additions & 2 deletions pxr/usd/usdMtlx/parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -241,10 +241,11 @@ ShaderBuilder::AddProperty(
if (converted.valueTypeName) {
type = converted.valueTypeName.GetAsToken();
// Do not use GetAsToken for comparison as recommended in the API
if (converted.valueTypeName == SdfValueTypeNames->Bool) {
if (converted.valueTypeName == SdfValueTypeNames->Bool ||
converted.valueTypeName == SdfValueTypeNames->Matrix3d) {
defaultValue = UsdMtlxGetUsdValue(element, isOutput);
metadata.emplace(SdrPropertyMetadata->SdrUsdDefinitionType,
converted.valueTypeName.GetType().GetTypeName());
converted.valueTypeName.GetAliasesAsTokens().front());
}
}
else {
Expand Down
18 changes: 17 additions & 1 deletion pxr/usd/usdMtlx/testenv/testUsdMtlxDiscovery.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import os
os.environ['PXR_MTLX_PLUGIN_SEARCH_PATHS'] = os.getcwd()

from pxr import Tf, Ndr, Sdr
from pxr import Ndr, Sdr, Gf
import unittest

class TestDiscovery(unittest.TestCase):
Expand All @@ -42,6 +42,7 @@ def test_NodeDiscovery(self):
['pxr_nd_boolean',
'pxr_nd_float',
'pxr_nd_integer',
'pxr_nd_matrix33',
'pxr_nd_string',
'pxr_nd_vector',
'pxr_nd_vector_2',
Expand All @@ -54,6 +55,7 @@ def test_NodeDiscovery(self):
['pxr_nd_boolean',
'pxr_nd_float',
'pxr_nd_integer',
'pxr_nd_matrix33',
'pxr_nd_string',
'pxr_nd_vector'])

Expand All @@ -68,6 +70,7 @@ def test_NodeDiscovery(self):
['pxr_nd_boolean',
'pxr_nd_float',
'pxr_nd_integer',
'pxr_nd_matrix33',
'pxr_nd_string',
'pxr_nd_vector_2',
'pxr_nd_vector_noversion'])
Expand All @@ -88,6 +91,7 @@ def test_NodeDiscovery(self):
Ndr.Version(),
Ndr.Version(),
Ndr.Version(),
Ndr.Version(),
Ndr.Version(1),
Ndr.Version(2, 0),
Ndr.Version(2, 1),
Expand All @@ -103,6 +107,7 @@ def test_NodeDiscovery(self):
'pxr_nd_booleanDefaults',
'pxr_nd_float',
'pxr_nd_integer',
'pxr_nd_matrix33',
'pxr_nd_string',
'pxr_nd_vector_2',
'pxr_nd_vector_noversion'])
Expand All @@ -114,6 +119,7 @@ def test_NodeDiscovery(self):
Ndr.Version(),
Ndr.Version(),
Ndr.Version(),
Ndr.Version(),
Ndr.Version(2, 0),
Ndr.Version()])

Expand All @@ -127,6 +133,16 @@ def test_NodeDiscovery(self):
self.assertFalse(falseInput.GetDefaultValue())
self.assertFalse(falseInput.GetDefaultValueAsSdfType())

# Check default values of matrix33 inputs:
node = registry.GetNodeByIdentifier("pxr_nd_matrix33")
self.assertTrue(node)
matrixInput = node.GetInput("in")
self.assertEqual(
matrixInput.GetDefaultValue(), Gf.Matrix3d(1,2,3,4,5,6,7,8,9))
self.assertEqual(
matrixInput.GetDefaultValueAsSdfType(),
Gf.Matrix3d(1,2,3,4,5,6,7,8,9))


if __name__ == '__main__':
unittest.main()
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@
<input name="inFalse" type="boolean" value="false" />
<output name="out" type="boolean" />
</nodedef>
<nodedef name="pxr_nd_matrix33" node="UsdMtlxTestNode">
<input name="in" type="matrix33" value="1.0,2.0,3.0, 4.0,5.0,6.0, 7.0,8.0,9.0" />
<input name="note" type="string" value="" uniform="true" />
<output name="out" type="matrix33" />
</nodedef>
<nodedef name="pxr_nd_integer" node="UsdMtlxTestNode">
<input name="in" type="integer" />
<input name="note" type="string" value="" uniform="true" />
Expand Down Expand Up @@ -41,6 +46,7 @@
</nodedef>
<implementation name="im_boolean" nodedef="pxr_nd_boolean" file="mx_boolean.osl" function="mx_boolean" />
<implementation name="im_booleanDefaults" nodedef="pxr_nd_booleanDefaults" file="mx_boolean.osl" function="mx_booleanDefaults" />
<implementation name="im_matrix33" nodedef="pxr_nd_matrix33" file="mx_matrix33.osl" function="mx_matrix33" />
<implementation name="im_integer" nodedef="pxr_nd_integer" file="mx_integer.osl" function="mx_integer" />
<implementation name="im_float" nodedef="pxr_nd_float" file="mx_float.osl" function="mx_float" />
<implementation name="im_string" nodedef="pxr_nd_string" file="mx_string.osl" function="mx_string" />
Expand Down

0 comments on commit 0f8376c

Please sign in to comment.