Skip to content

Commit

Permalink
1.38 : Upgrade parameters to be inputs (#977)
Browse files Browse the repository at this point in the history
* Change all parameters to inputs w/ "uniform" flag -- to refine.

* First pass param->input cleanup.

* More changes.

* Replace isA<Parameter>() check with getIsUniform() check.

* Preserve input ordering when performing upgrade.

* Fix Javascript buildings (remove Parameter exposure + fix tests).

* Revert uniform check for default geom nodes
Retore "applyFutureUpdates" logic.

* Fix to only apply atan2 update if 1.37 by testing default value.

* Review fixes and cleanup.

* Add sample post 1.38 upgrade file. Has interface tags but no explicit inputs as this appears to fail validation. To handle when explicit inputs are supported.

* Fix texture pathing.

* - Get rid of getPrimaryShaderParameters() method
- Misc cleanup.

* Cleanup Javascript and Python tests.

* Update interface to addInput() to remove default name, type args + add in "isUniform" arg which defaults to false, except for filenames and strings for which it will always be true.

* Review fixes. Add testing for C++, Python, JS.
  • Loading branch information
bernardkwok authored Oct 1, 2020
1 parent 2fde5d0 commit d34358b
Show file tree
Hide file tree
Showing 45 changed files with 344 additions and 445 deletions.
2 changes: 1 addition & 1 deletion libraries/adsk/adsklib/colorcorrect.mtlx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0"?>
<materialx version="1.38" xmlns:xi="http://www.w3.org/2001/XInclude">
<materialx version="1.37" xmlns:xi="http://www.w3.org/2001/XInclude">

<!-- Sample color correct interface. Versioned and namespaced -->
<nodedef name="ND_colorcorrect" node="colorcorrect" nodegroup="adjustment" version="1.0" isdefaultversion="true" namespace="adsk">
Expand Down
41 changes: 19 additions & 22 deletions python/MaterialXTest/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,25 +201,25 @@ def test_BuildDocument(self):

# Set constant node color.
color = mx.Color3(0.1, 0.2, 0.3)
constant.setParameterValue('value', color)
self.assertTrue(constant.getParameterValue('value') == color)
constant.setInputValue('value', color)
self.assertTrue(constant.getInputValue('value') == color)

# Set image node file.
file = 'image1.tif'
image.setParameterValue('file', file, 'filename')
self.assertTrue(image.getParameterValue('file') == file)
image.setInputValue('file', file, 'filename')
self.assertTrue(image.getInputValue('file') == file)

# Create a custom nodedef.
nodeDef = doc.addNodeDef('nodeDef1', 'float', 'turbulence3d')
nodeDef.setParameterValue('octaves', 3)
nodeDef.setParameterValue('lacunarity', 2.0)
nodeDef.setParameterValue('gain', 0.5)
nodeDef.setInputValue('octaves', 3)
nodeDef.setInputValue('lacunarity', 2.0)
nodeDef.setInputValue('gain', 0.5)

# Reference the custom nodedef.
custom = nodeGraph.addNode('turbulence3d', 'turbulence1', 'float')
self.assertTrue(custom.getParameterValue('octaves') == 3)
custom.setParameterValue('octaves', 5)
self.assertTrue(custom.getParameterValue('octaves') == 5)
self.assertTrue(custom.getInputValue('octaves') == 3)
custom.setInputValue('octaves', 5)
self.assertTrue(custom.getInputValue('octaves') == 5)

# Validate the document.
valid, message = doc.validate()
Expand All @@ -228,29 +228,31 @@ def test_BuildDocument(self):
# Test scoped attributes.
nodeGraph.setFilePrefix('folder/')
nodeGraph.setColorSpace('lin_rec709')
self.assertTrue(image.getParameter('file').getResolvedValueString() == 'folder/image1.tif')
self.assertTrue(image.getInput('file').getResolvedValueString() == 'folder/image1.tif')
self.assertTrue(constant.getActiveColorSpace() == 'lin_rec709')

# Create a simple shader interface.
shaderDef = doc.addNodeDef('shader1', 'surfaceshader', 'simpleSrf')
diffColor = shaderDef.setInputValue('diffColor', mx.Color3(1.0))
specColor = shaderDef.setInputValue('specColor', mx.Color3(0.0))
roughness = shaderDef.setParameterValue('roughness', 0.25)
roughness = shaderDef.setInputValue('roughness', 0.25)
texId = shaderDef.setTokenValue('texId', '01')
self.assertTrue(roughness.getValue() == 0.25)
self.assertTrue(roughness.getIsUniform() == False)
roughness.setIsUniform(True);
self.assertTrue(roughness.getIsUniform() == True)

# Create a material that instantiates the shader.
material = doc.addMaterial()
shaderRef = material.addShaderRef('shaderRef1', 'simpleSrf')
self.assertTrue(material.getPrimaryShaderName() == 'simpleSrf')
self.assertTrue(len(material.getPrimaryShaderParameters()) == 1)
self.assertTrue(len(material.getPrimaryShaderInputs()) == 2)
self.assertTrue(len(material.getPrimaryShaderInputs()) == 3)
self.assertTrue(len(material.getPrimaryShaderTokens()) == 1)
self.assertTrue(roughness.getBoundValue(material) == 0.25)

# Bind a shader parameter to a value.
bindParam = shaderRef.addBindParam('roughness')
bindParam.setValue(0.5)
# Bind a shader input to a float value.
bindInput = shaderRef.addBindInput('roughness')
bindInput.setValue(0.5)
self.assertTrue(roughness.getBoundValue(material) == 0.5)
self.assertTrue(roughness.getDefaultValue() == 0.25)

Expand Down Expand Up @@ -484,11 +486,6 @@ def test_ReadXml(self):
for material in doc.getMaterials():
self.assertTrue(material.getPrimaryShaderNodeDef())
edgeCount = 0
for param in material.getPrimaryShaderParameters():
boundValue = param.getBoundValue(material)
self.assertTrue(boundValue is not None)
for _ in param.traverseGraph(material):
edgeCount += 1
for shaderInput in material.getPrimaryShaderInputs():
boundValue = shaderInput.getBoundValue(material)
upstreamElement = shaderInput.getUpstreamElement(material)
Expand Down
2 changes: 1 addition & 1 deletion resources/Materials/TestSuite/adsklib/adsk_shaders.mtlx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0"?>
<materialx version="1.38">
<materialx version="1.37">
<!-- Test graph for adsk nodedefs -->

<nodegraph name="util_nodedefs" type="color3">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0"?>
<materialx version="1.38">
<materialx version="1.37">
<nodegraph name="brick_02_surfaceshader_graph">
<normalmap name="bricks_02_normalmap" type="vector3">
<input name="in" type="vector3" nodename="bricks_02_normal" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0"?>
<materialx version="1.38">
<materialx version="1.37">
<nodegraph name="brick_10_surfaceshader_graph">
<normalmap name="bricks_10_normalmap" type="vector3">
<input name="in" type="vector3" nodename="bricks_10_normal" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0"?>
<materialx version="1.38">
<materialx version="1.37">
<nodegraph name="parquet_03_surfaceshader_graph">
<normalmap name="parquet_03_normalmap" type="vector3">
<input name="in" type="vector3" nodename="parquet_03_normal" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0"?>
<materialx version="1.38">
<materialx version="1.37">
<nodegraph name="test_colorcorrect">
<range name="AlphaClampAndGamma" type="float">
<input name="in" type="float" nodename="AlphaOffset" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
<?xml version="1.0"?>
<materialx version="1.37">
<nodegraph name="parameter_as_input" fileprefix="resources/Images/">
<constant name="constant" type="color3">
<input name="value" type="color3" interfacename="value1" value="1, 0, 0" />
</constant>
<constant name="constant1" type="color3">
<input name="value" type="color3" interfacename="value" value="0, 1, 0" />
</constant>
<ramp4 name="ramp4" type="color3">
<input name="valuetl" type="color3" nodename="ramp5" />
<input name="valuetr" type="color3" nodename="image" />
<input name="valuebl" type="color3" nodename="image" />
<input name="valuebr" type="color3" nodename="constant1" />
</ramp4>
<ramp4 name="ramp5" type="color3">
<input name="valuetl" type="color3" nodename="image" />
<input name="valuetr" type="color3" interfacename="valuetr" value="0, 1, 1" />
<input name="valuebl" type="color3" interfacename="valuebl" value="0, 0, 0" />
<input name="valuebr" type="color3" nodename="image" />
</ramp4>
<image name="image" type="color3">
<input name="file" type="filename" nodename="constant3" />
<input name="layer" type="string" value="" uiname="Layer" uniform="true" />
<input name="default" type="color3" value="0.0, 0.0, 0.0" uiname="Default Color" uniform="true" />
<input name="uaddressmode" type="string" value="periodic" enum="constant,clamp,periodic,mirror" uiname="Address Mode U" uniform="true" />
<input name="vaddressmode" type="string" value="periodic" enum="constant,clamp,periodic,mirror" uiname="Address Mode V" uniform="true" />
<input name="filtertype" type="string" value="linear" enum="closest,linear,cubic" uiname="Filter Type" uniform="true" />
<input name="framerange" type="string" value="" uiname="Frame Range" uniform="true" />
<input name="frameoffset" type="integer" value="0" uiname="Frame Offset" uniform="true" />
<input name="frameendaction" type="string" value="constant" enum="constant,clamp,periodic,mirror" uiname="Frame End Action" uniform="true" />
</image>
<splitlr name="splitlr" type="color3">
<input name="valuel" type="color3" nodename="image" />
<input name="valuer" type="color3" nodename="constant" />
<input name="center" type="float" interfacename="center" value="0.4" />
</splitlr>
<splittb name="splittb" type="color3">
<input name="valuet" type="color3" nodename="splitlr" />
<input name="valueb" type="color3" nodename="noise2d" />
<input name="center" type="float" interfacename="center" value="0.4" />
</splittb>
<noise2d name="noise2d" type="color3">
<input name="pivot" type="float" nodename="noise2d1" />
<input name="texcoord" type="vector2" nodename="multiply" />
<input name="amplitude" type="vector3" value="1.0, 1.0, 1.0" uniform="true" />
</noise2d>
<noise2d name="noise2d1" type="float">
<input name="amplitude" type="float" value="2" />
<input name="pivot" type="float" value="0.1" />
<input name="texcoord" type="vector2" nodename="multiply" />
</noise2d>
<texcoord name="texcoord" type="vector2" />
<multiply name="multiply" type="vector2">
<input name="in1" type="vector2" nodename="texcoord" />
<input name="in2" type="vector2" value="10, 10" />
</multiply>
<tangent name="tangent" type="vector3">
<input name="index" type="integer" nodename="geompropvalue" />
</tangent>
<geompropvalue name="geompropvalue" type="integer">
<input name="geomprop" type="string" value="myvalue" />
<input name="default" type="integer" value="0" uniform="true" />
</geompropvalue>
<constant name="constant2" type="string">
<input name="value" type="string" interfacename="my_tangent_name" value="mytangents" />
</constant>
<invert name="invert" type="color3">
<input name="in" type="color3" nodename="splittb" />
<input name="amount" type="color3" nodename="noise2d" />
</invert>
<constant name="constant3" type="filename">
<input name="value" type="filename" interfacename="file" value="grid.png" />
</constant>
<output name="out" type="color3" nodename="ramp4" />
<output name="out1" type="color3" nodename="splittb" />
<output name="out2" type="vector3" nodename="tangent" />
</nodegraph>
</materialx>
2 changes: 2 additions & 0 deletions source/JsMaterialX/JsMaterialXCore/JsElement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,8 @@ extern "C"
.function("setUnitType", &mx::ValueElement::setUnitType)
.function("hasUnitType", &mx::ValueElement::hasUnitType)
.function("getUnitType", &mx::ValueElement::getUnitType)
.function("setIsUniform", &mx::ValueElement::setIsUniform)
.function("getIsUniform", &mx::ValueElement::getIsUniform)
.class_property("VALUE_ATTRIBUTE", &mx::ValueElement::VALUE_ATTRIBUTE)
.class_property("INTERFACE_NAME_ATTRIBUTE", &mx::ValueElement::INTERFACE_NAME_ATTRIBUTE)
.class_property("IMPLEMENTATION_NAME_ATTRIBUTE", &mx::ValueElement::IMPLEMENTATION_NAME_ATTRIBUTE)
Expand Down
14 changes: 0 additions & 14 deletions source/JsMaterialX/JsMaterialXCore/JsInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,13 @@ namespace ems = emscripten;
namespace mx = MaterialX;

#define BIND_INTERFACE_TYPE_INSTANCE(NAME, T) \
.function("setParameterValue" #NAME, &mx::InterfaceElement::setParameterValue<T>) \
.function("setInputValue" #NAME, &mx::InterfaceElement::setInputValue<T>)

extern "C"
{
EMSCRIPTEN_BINDINGS(interface)
{

ems::class_<mx::Parameter, ems::base<mx::ValueElement>>("Parameter")
.smart_ptr_constructor("Parameter", &std::make_shared<mx::Parameter, mx::ElementPtr, const std::string &>)
.smart_ptr<std::shared_ptr<const mx::Parameter>>("Parameter")
.class_property("CATEGORY", &mx::Parameter::CATEGORY);

ems::class_<mx::PortElement, ems::base<mx::ValueElement>>("PortElement")
.smart_ptr<std::shared_ptr<mx::PortElement>>("PortElement")
.smart_ptr<std::shared_ptr<const mx::PortElement>>("PortElement")
Expand Down Expand Up @@ -54,14 +48,7 @@ extern "C"
.function("setNodeDefString", &mx::InterfaceElement::setNodeDefString)
.function("hasNodeDefString", &mx::InterfaceElement::hasNodeDefString)
.function("getNodeDefString", &mx::InterfaceElement::getNodeDefString)
.function("addParameter", &mx::InterfaceElement::addParameter)

.function("getParameter", &mx::InterfaceElement::getParameter)
.function("getParameters", &mx::InterfaceElement::getParameters)
.function("getParameterCount", &mx::InterfaceElement::getParameterCount)
.function("removeParameter", &mx::InterfaceElement::removeParameter)
.function("getActiveParameter", &mx::InterfaceElement::getActiveParameter)
.function("getActiveParameters", &mx::InterfaceElement::getActiveParameters)
.function("addInput", &mx::InterfaceElement::addInput)
.function("getInput", &mx::InterfaceElement::getInput)
.function("getInputs", &mx::InterfaceElement::getInputs)
Expand All @@ -86,7 +73,6 @@ extern "C"

.function("getActiveValueElement", &mx::InterfaceElement::getActiveValueElement)
.function("getActiveValueElements", &mx::InterfaceElement::getActiveValueElements)
.function("getParameterValue", &mx::InterfaceElement::getParameterValue)
.function("getInputValue", &mx::InterfaceElement::getInputValue)

.function("setTokenValue", &mx::InterfaceElement::setTokenValue)
Expand Down
20 changes: 0 additions & 20 deletions source/JsMaterialX/JsMaterialXCore/JsInterface.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
// jsInterface
addWrapper(function(Module, api) {
/** Setup the Parameter class */
api.Parameter = wrapperFactory(Module.Parameter);

/** Setup the PortElement class */
api.PortElement = wrapperFactory(Module.PortElement);
Expand All @@ -13,22 +11,6 @@ addWrapper(function(Module, api) {
api.Output = wrapperFactory(Module.Output);

var funcs = [
'setParameterValueinteger',
'setParameterValueboolean',
'setParameterValuefloat',
'setParameterValuecolor2',
'setParameterValuecolor3',
'setParameterValuecolor4',
'setParameterValuevector2',
'setParameterValuevector3',
'setParameterValuevector4',
'setParameterValuematrix33',
'setParameterValuematrix44',
'setParameterValuestring',
'setParameterValueintegerarray',
'setParameterValuebooleanarray',
'setParameterValuefloatarray',
'setParameterValuestringarray',
'setInputValueinteger',
'setInputValueboolean',
'setInputValuefloat',
Expand All @@ -48,11 +30,9 @@ addWrapper(function(Module, api) {
];

var defaultArgs = {
addParameter: [api.DEFAULT_TYPE_STRING, api.DEFAULT_TYPE_STRING],
addInput: [api.DEFAULT_TYPE_STRING, api.DEFAULT_TYPE_STRING],
addOutput: ['', api.DEFAULT_TYPE_STRING],
addToken: [''],
getParameterValue: [REQUIRED, ''],
getInputValue: [REQUIRED, ''],
getDeclaration: ['']
};
Expand Down
1 change: 0 additions & 1 deletion source/JsMaterialX/JsMaterialXCore/JsMaterial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ extern "C"
.function("getShaderNodeDefs", &mx::Material::getShaderNodeDefs)
.function("getPrimaryShaderNodeDef", &mx::Material::getPrimaryShaderNodeDef)
.function("getPrimaryShaderName", &mx::Material::getPrimaryShaderName)
.function("getPrimaryShaderParameters", &mx::Material::getPrimaryShaderParameters)
.function("getPrimaryShaderInputs", &mx::Material::getPrimaryShaderInputs)
.function("getPrimaryShaderTokens", &mx::Material::getPrimaryShaderTokens)
.function("getGeometryBindings", &mx::Material::getGeometryBindings)
Expand Down
1 change: 0 additions & 1 deletion source/JsMaterialX/JsMaterialXCore/JsMaterial.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ addWrapper(function(Module, api) {
getShaderNodeDefs: ['', ''],
getPrimaryShaderNodeDef: ['', ''],
getPrimaryShaderName: ['', ''],
getPrimaryShaderParameters: ['', ''],
getPrimaryShaderInputs: ['', ''],
getPrimaryShaderTokens: ['', ''],
getGeometryBindings: [api.UNIVERSAL_GEOM_NAME]
Expand Down
Loading

0 comments on commit d34358b

Please sign in to comment.