Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion javascript/MaterialXTest/customBindings.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ describe('Custom Bindings', () =>
await mx.readFromXmlFile(doc, filename, examplesPath);
const sourceUris = doc.getReferencedSourceUris();
expect(sourceUris).to.be.instanceof(Array);
expect(sourceUris.length).to.equal(3);
expect(sourceUris.length).to.equal(4);
expect(sourceUris[0]).to.be.a('string');
expect(sourceUris.includes('standard_surface_brass_tiled.mtlx')).to.be.true;
doc.delete();
Expand Down
71 changes: 43 additions & 28 deletions javascript/MaterialXView/source/viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -997,7 +997,6 @@ export class Material
matTitle.classList.remove('peditor_material_assigned');
let img = matTitle.getElementsByTagName('img')[0];
img.src = 'public/shader_ball.svg';
//matTitle.classList.remove('peditor_material_unassigned');
}
}
}
Expand All @@ -1007,34 +1006,45 @@ export class Material
// Prevent the event from being passed to parent folder
event.stopPropagation();

let materialNameList = new Set()
for (let i = 0; i < materials.length; ++i)
{
let matassign = materials[i];
// Need to use path vs name to get a unique key.
let materialName = matassign.getMaterial().getNamePath();
if (materialNameList.has(materialName))
{
continue;
}

var matUI = matassign.getMaterialUI();
let matTitle = matUI.domElement.getElementsByClassName('title')[0];
let img = matTitle.getElementsByTagName('img')[0];
if (materialName == elemPath)
if (matUI)
{
if (this._soloMaterial == elemPath)
materialNameList.add(materialName);

let matTitle = matUI.domElement.getElementsByClassName('title')[0];
let img = matTitle.getElementsByTagName('img')[0];
if (materialName == elemPath)
{
img.src = 'public/shader_ball.svg';
matTitle.classList.remove('peditor_material_assigned');
this._soloMaterial = "";
if (this._soloMaterial == elemPath)
{
img.src = 'public/shader_ball.svg';
matTitle.classList.remove('peditor_material_assigned');
this._soloMaterial = "";
}
else
{
img.src = 'public/shader_ball2.svg';
matTitle.classList.add('peditor_material_assigned');
this._soloMaterial = elemPath;
}
}
else
{
img.src = 'public/shader_ball2.svg';
matTitle.classList.add('peditor_material_assigned');
this._soloMaterial = elemPath;
img.src = 'public/shader_ball.svg';
matTitle.classList.remove('peditor_material_assigned');
}
}
else
{
img.src = 'public/shader_ball.svg';
matTitle.classList.remove('peditor_material_assigned');
}
}
viewer.getMaterial().updateMaterialAssignments(viewer, this._soloMaterial);
}
Expand All @@ -1056,22 +1066,27 @@ export class Material
const elemPath = elem.getNamePath();

// Create and cache associated UI
var matUI = gui.addFolder(elemPath);
let matUI = gui.addFolder(elemPath);
console.log('Set material UI for: ', elemPath, matUI);
matassign.setMaterialUI(matUI);

let matTitle = matUI.domElement.getElementsByClassName('title')[0];
// Add a icon to the title to allow for assigning the material to geometry
// Clicking on the icon will "solo" the material to the geometry.
// Clicking on the title will open/close the material folder.
matTitle.innerHTML = "<img id='" + elemPath + "' src='public/shader_ball.svg' width='16' height='16' style='vertical-align:middle; margin-right: 5px;'>" + elem.getNamePath();
let img = matTitle.getElementsByTagName('img')[0];
if (img)
let matTitle = null
if (matUI && matUI.domElement)
{
// Add event listener to icon to call updateSoloMaterial function
img.addEventListener('click', function (event)
matTitle = matUI.domElement.getElementsByClassName('title')[0];
// Add a icon to the title to allow for assigning the material to geometry
// Clicking on the icon will "solo" the material to the geometry.
// Clicking on the title will open/close the material folder.
matTitle.innerHTML = "<img id='" + elemPath + "' src='public/shader_ball.svg' width='16' height='16' style='vertical-align:middle; margin-right: 5px;'>" + elem.getNamePath();
let img = matTitle.getElementsByTagName('img')[0];
if (img)
{
Material.updateSoloMaterial(viewer, elemPath, materials, event);
});
// Add event listener to icon to call updateSoloMaterial function
img.addEventListener('click', function (event)
{
Material.updateSoloMaterial(viewer, elemPath, materials, event);
});
}
}

if (closeUI)
Expand Down
Binary file added resources/Geometry/usdshaderball.glb
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@
<materialx version="1.39" xmlns:xi="http://www.w3.org/2001/XInclude">
<xi:include href="standard_surface_brass_tiled.mtlx" />
<xi:include href="standard_surface_greysphere_calibration.mtlx" />
<xi:include href="standard_surface_greysphere.mtlx" />
<look name="Brass_Look">
<materialassign name="preview" geom="Preview_Mesh" material="Tiled_Brass" />
<materialassign name="calibration" geom="Calibration_Mesh" material="Greysphere_Calibration" />
<materialassign name="usdpreview" geom="material_surface" material="Tiled_Brass" />
<materialassign name="usddefault" geom="base,core,sss_bars" material="Greysphere" />
</look>
</materialx>
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0"?>
<materialx version="1.39" xmlns:xi="http://www.w3.org/2001/XInclude">
<xi:include href="standard_surface_glass.mtlx" />
<xi:include href="standard_surface_greysphere_calibration.mtlx" />
<xi:include href="standard_surface_greysphere.mtlx" />
<look name="Brass_Look">
<materialassign name="preview" geom="Preview_Mesh" material="Glass" />
<materialassign name="calibration" geom="Calibration_Mesh" material="Greysphere_Calibration" />
<materialassign name="usdpreview" geom="material_surface" material="Glass" />
<materialassign name="usddefault" geom="base,core,sss_bars" material="Greysphere" />
</look>
</materialx>
23 changes: 22 additions & 1 deletion source/MaterialXView/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ const std::string options =
" --remap [TOKEN1:TOKEN2] Specify the remapping from one token to another when MaterialX document is loaded\n"
" --skip [NAME] Specify to skip elements matching the given name attribute\n"
" --terminator [STRING] Specify to enforce the given terminator string for file prefixes\n"
" --transmissionMethod [STRING] Specify the method used to render transmission. Options are: 'opacity', 'refraction'. Default is refraction\n"
" --help Display the complete list of command-line options\n";

template <class T> void parseToken(std::string token, std::string type, T& res)
Expand Down Expand Up @@ -75,7 +76,7 @@ int main(int argc, char* const argv[])
}

std::string materialFilename = "resources/Materials/Examples/StandardSurface/standard_surface_default.mtlx";
std::string meshFilename = "resources/Geometry/shaderball.glb";
std::string meshFilename = "resources/Geometry/usdshaderball.glb";
std::string envRadianceFilename = "resources/Lights/san_giuseppe_bridge_split.hdr";
mx::FileSearchPath searchPath = mx::getDefaultDataSearchPath();
mx::FilePathVec libraryFolders;
Expand All @@ -88,6 +89,7 @@ int main(int argc, char* const argv[])
mx::Vector3 cameraTarget;
float cameraViewAngle(DEFAULT_CAMERA_VIEW_ANGLE);
float cameraZoom(DEFAULT_CAMERA_ZOOM);
mx::HwTransmissionRenderMethod transmissionMethod = mx::TRANSMISSION_REFRACTION;
mx::HwSpecularEnvironmentMethod specularEnvironmentMethod = mx::SPECULAR_ENVIRONMENT_FIS;
int envSampleCount = mx::DEFAULT_ENV_SAMPLE_COUNT;
float envLightIntensity = 1.0f;
Expand Down Expand Up @@ -254,6 +256,24 @@ int main(int argc, char* const argv[])
{
modifiers.filePrefixTerminator = nextToken;
}
else if (token == "--transmissionMethod")
{
const std::string method = nextToken;
if (method == "opacity")
{
transmissionMethod = mx::TRANSMISSION_OPACITY;
}
else if (method == "refraction")
{
transmissionMethod = mx::TRANSMISSION_REFRACTION;
}
else
{
std::cout << "Unrecognized transmission method: " << method << std::endl;
std::cout << "Supported methods are: 'opacity', 'refraction'" << std::endl;
}
}

else if (token == "--help")
{
std::cout << " MaterialXView version " << mx::getVersionString() << std::endl;
Expand Down Expand Up @@ -299,6 +319,7 @@ int main(int argc, char* const argv[])
viewer->setCameraViewAngle(cameraViewAngle);
viewer->setCameraZoom(cameraZoom);
viewer->setSpecularEnvironmentMethod(specularEnvironmentMethod);
viewer->setTransmissionRenderMethod(transmissionMethod);
viewer->setEnvSampleCount(envSampleCount);
viewer->setEnvLightIntensity(envLightIntensity);
viewer->setLightRotation(lightRotation);
Expand Down
6 changes: 6 additions & 0 deletions source/MaterialXView/Viewer.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,12 @@ class Viewer : public ng::Screen
_genContext.getOptions().hwSpecularEnvironmentMethod = method;
}

// Set the method for transmission rendering.
void setTransmissionRenderMethod(mx::HwTransmissionRenderMethod method)
{
_genContext.getOptions().hwTransmissionRenderMethod = method;
}

// Set the number of environment samples.
void setEnvSampleCount(int count)
{
Expand Down