Skip to content

Commit

Permalink
Merge (#50)
Browse files Browse the repository at this point in the history
* Web viewer formatting improvements and fixes (AcademySoftwareFoundation#1635)

- Add colouring to items and folders which can be set vis CSS. This makes it easier to tell what areas are under what folders.
- Fix string disable setting (was using old API).
- Fix parenting of enum widgets to be under current folder instead of top level.

* Add HwImplementation class

This changelist adds an intermediate HwImplementation class, allowing the sharing of common features between node implementations in hardware shading languages.

* Merge geometry node implementations

This changelist merges the implementations of geometry nodes across hardware shading languages, allowing a greater degree of code sharing.

* Merge application node implementations

This changelist merges the implementations of application and NPR nodes across hardware shading languages, allowing a greater degree of code sharing.

* Add vector2 variant of normalmap (AcademySoftwareFoundation#1355)

The materialx specification defines the scale attribute of the normalmap to be either a float or a vector2 but the vector2 variant was missing from the implementation. This PR adds it.

* Renderable logic improvements to web viewer (AcademySoftwareFoundation#1644)

- Adds in proper parsing of renderable elements vs always just picking the first surface shader found.
  - The test suite files which have (multiple) nodegraph outputs and top level outputs will now load properly.
- Adds in UI to mark folders as renderable (using a shaderball icon) 
- Adds in "soloing" capability to allow picking a renderable and have it show up on all geometry. When nothing is solo'ed the default material assignment is used.
- Includes fixes for:
  - Dag path assignment matching .
  - Missing exposure of NodeGraph::getDownStreamPorts() in JS.
  - Addressing the big performance hit when binding materials to geometry in ThreeJS. The code by default is some quite slow code for reflection / debugging purposes which is now turned off. Chess set load is seconds vs minutes. This affects the 'solo'ing workflow significantly as each switch is a geometry re-bind. If the material is not already cached then slow code will be hit which can cause seconds to pass when selecting a new material -- which appears like a "hang" from a user perspective.

* Fix irradiance generation in MaterialXView (AcademySoftwareFoundation#1647)

This changelist fixes a regression to environment irradiance generation in MaterialXView, caused by a change to image caching logic for GLSL rendering in MaterialX 1.38.8.  This fix restores the ability to render environment maps that are missing their pre-generated irradiance data, with irradiance being generated on the fly via spherical harmonics.

* Add UI limits for useSpecularWorkflow and normal in UsdPreviewSurface (AcademySoftwareFoundation#1646)

UsdPreviewSurface allows useSpecularWorkflow to be 0 or 1. Normals should have values between -1 to 1, inclusive. This PR puts these limits into place.

* Unify noise unit tests

This changelist merges two sets of noise unit tests into a single document, and aligns their implementations for clarity.

* Static analysis optimizations

This changelist addresses a handful of static analysis optimizations flagged by PVS-Studio and cppcheck, including the following:

- Pass immutable std::string, FilePath, and FileSearchPath arguments by const reference.
- Mark immutable ShaderGenerator references as const.
- Prefer std::string::empty over comparison against an empty string.
- Remove unused private methods Graph::findLinkId, Graph::findInput, and Graph::selectMaterial.
- Remove variable assignments with no impact on code behavior.

* Improvements to noise implementations (AcademySoftwareFoundation#1653)

- Leverage node graphs to share the conversion aspects of noise implementations across languages.
- Simplify noise unit tests to cover only unique implementations.

* Fix shader generation typos

This changelist fixes a handful of minor typos in shader generation, introduced in AcademySoftwareFoundation#1355 and AcademySoftwareFoundation#1553.

* Add frame capture to web viewer (AcademySoftwareFoundation#1636)

Add frame capture code to trigger on 'f' key. This is the same key as used for the desktop viewer.

* Document format updates

This changelist applies the mxformat.py script to the libraries and resources folders in the repository, updating formatting for a handful of documents.

* Add versioning rules to Developer Guide (AcademySoftwareFoundation#1664)

This changelist adds two new sections to the Developer Guide, describing the categories of changes to the MaterialX API and data libraries that are allowed in version upgrades.

* Improve robustness of TypeDesc pointer comparisons (AcademySoftwareFoundation#1665)

- The globals presets defined for TypeDesc are pointers which may not be shared between shared modules. This occurs for instance in Python where the pointers are declared locally for each module.
- Any pointer comparison between the same TypeDesc preset can thus result in a failure status.

* Improvements to smoothstep implementations

- Leverage node graphs to share the conversion aspects of smoothstep implementations across languages.
- Simplify smoothstep unit tests to cover only unique implementations.

* Update changelog for recent work

* Update comments in stdlib_ng.mtlx

This changelist updates the comments in stdlib_ng, aligning them with the conventions for nodegraph definitions in the data libraries.

* Fix orphaned links when deleting node in graph editor (AcademySoftwareFoundation#1667)

This PR introduces fixes related to the removal of orphaned links when deleting a node in the Graph Editor:
- remove the attribute `INTERFACE_NAME_ATTRIBUTE` of input pins that were connected to the deleted node
(Fixes AcademySoftwareFoundation#1577) 
- iterate over all of the output pins instead of only handling the first one.
(Fixes AcademySoftwareFoundation#1666)

* Add facingratio node to nprlib (AcademySoftwareFoundation#1671)

This changelist adds a `facingratio` node to the NPR data library, providing an additional intermediate node for building NPR graphs.

* Add geometry drag & drop to web viewer (AcademySoftwareFoundation#1663)

- Add support to recognize dropping of individual geometry (glb) files.
- Minor cleanup to stop if no MTLX or GLB files loaded.

* Apply JavaScript formatting

This changelist applies automated formatting to the MaterialX JavaScript codebase, aligning it with the 4-space indentation and Allman braces used in MaterialX C++.

* Add missing classification of VolumeShader nodes (AcademySoftwareFoundation#1675)

ShaderNodes.cpp had missing classification information for Volume Shaders. This PR is a simple addition of that classification.

* Add invert node to specification (AcademySoftwareFoundation#1676)

The node exists in the standard library code, but is missing from the specification.

* Improvements to facingratio

- Fix syntax of input default values.
- Use the invert node in facingratio for compactness.
- Clarify the edge brighten example material.

* Always build GLFW as a static library (AcademySoftwareFoundation#1680)

Currently the embedded glfw build for MaterialXGraphEditor inherits the value of BUILD_SHARED_LIBS from MATERIALX_BUILD_SHARED_LIBS, but we're not installing libglfw, per AcademySoftwareFoundation#1245 the intention was to statically link.

---------

Co-authored-by: Jonathan Stone <[email protected]>
Co-authored-by: mnikelsky <[email protected]>
Co-authored-by: Eric Haines <[email protected]>
Co-authored-by: Leo Belda <[email protected]>
Co-authored-by: Dhruv Govil <[email protected]>
Co-authored-by: ld-kerley <[email protected]>
  • Loading branch information
7 people authored Jan 30, 2024
1 parent 9cfb948 commit 9a0d7f0
Show file tree
Hide file tree
Showing 180 changed files with 2,183 additions and 2,632 deletions.
36 changes: 36 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,42 @@

## [1.38.9] - Development

### Added

- Added a [non-photorealistic rendering](https://github.com/AcademySoftwareFoundation/MaterialX/pull/1631) data library to MaterialX, initially supporting the 'viewdirection' and 'facingratio' nodes.
- Added support for the generation of [pre-filtered environment maps](https://github.com/AcademySoftwareFoundation/MaterialX/pull/1420) in MaterialX GLSL and MSL.
- Added support for the [creatematrix node](https://github.com/AcademySoftwareFoundation/MaterialX/pull/1553) in shader generation.
- Added [floating popups](https://github.com/AcademySoftwareFoundation/MaterialX/pull/1565) for hovered pins in the MaterialX Graph Editor.
- Added support for [UI attributes](https://github.com/AcademySoftwareFoundation/MaterialX/pull/1623) and [enumerated values](https://github.com/AcademySoftwareFoundation/MaterialX/pull/1632) in the MaterialX Web Viewer.
- Added [UI ranges](https://github.com/AcademySoftwareFoundation/MaterialX/pull/1646) to the 'useSpecularWorkflow' and 'normal' inputs of the UsdPreviewSurface shading model.
- Added [versioning rules](https://github.com/AcademySoftwareFoundation/MaterialX/pull/1664) for the MaterialX API and data libraries to the developer guide.
- Added initial C++ [fuzz tests](https://github.com/AcademySoftwareFoundation/MaterialX/pull/1605) and [coverage tests](https://github.com/AcademySoftwareFoundation/MaterialX/pull/1548) to GitHub Actions CI.
- Added [GCC 13, Clang 15](https://github.com/AcademySoftwareFoundation/MaterialX/pull/1602), and [Python 3.12](https://github.com/AcademySoftwareFoundation/MaterialX/pull/1588) builds to GitHub Actions CI.

### Changed

- Improved the logic for [connecting pins](https://github.com/AcademySoftwareFoundation/MaterialX/pull/1569) in the MaterialX Graph Editor.
- Improved the robustness of [type pointer comparisons](https://github.com/AcademySoftwareFoundation/MaterialX/pull/1665) in shader generation.
- Improved the handling of [filename inputs](https://github.com/AcademySoftwareFoundation/MaterialX/pull/1547) in OSL shader generation.
- Reduced the size of the MaterialX data libraries, improving the use of [graph definitions](https://github.com/AcademySoftwareFoundation/MaterialX/pull/1653) and merging [duplicate implementations](https://github.com/AcademySoftwareFoundation/MaterialX/pull/1642).
- Updated the MaterialX Web Viewer to [three.js r152](https://github.com/AcademySoftwareFoundation/MaterialX/pull/1615).
- Switched to a more efficient representation of [HDR images](https://github.com/AcademySoftwareFoundation/MaterialX/pull/1616) in the MaterialX Web Viewer.
- Raised the minimum CMake version to [CMake 3.16](https://github.com/AcademySoftwareFoundation/MaterialX/pull/1607).
- Updated the C++ unit test library to [Catch 2.13.10](https://github.com/AcademySoftwareFoundation/MaterialX/pull/1566).

### Fixed

- Fixed the attenuation of [coated emission](https://github.com/AcademySoftwareFoundation/MaterialX/pull/1534) in the Standard Surface shading model.
- Fixed the implementation of the [overlay node](https://github.com/AcademySoftwareFoundation/MaterialX/pull/1539) in shader generation.
- Fixed an edge case for [transform nodes](https://github.com/AcademySoftwareFoundation/MaterialX/pull/1560) in GLSL and MSL shader generation.
- Fixed the implementation of [mx_hsvtorgb](https://github.com/AcademySoftwareFoundation/MaterialX/pull/1584) in MDL shader generation.
- Fixed [scroll wheel interactions](https://github.com/AcademySoftwareFoundation/MaterialX/pull/1578) across windows of the MaterialX Graph Editor.
- Fixed the generation of unused [imgui.ini files](https://github.com/AcademySoftwareFoundation/MaterialX/pull/1570) in the MaterialX Graph Editor.
- Fixed a dependency on [module import order](https://github.com/AcademySoftwareFoundation/MaterialX/pull/1595) in MaterialX Python.
- Fixed an [off-by-one index check](https://github.com/AcademySoftwareFoundation/MaterialX/pull/1582) in Element::setChildIndex.
- Fixed a [missing null check](https://github.com/AcademySoftwareFoundation/MaterialX/pull/1601) in Graph::propertyEditor.
- Fixed cases where [absolute paths](https://github.com/AcademySoftwareFoundation/MaterialX/pull/1603) were stored in MaterialXConfig.cmake.

## [1.38.8] - 2023-09-08

### Added
Expand Down
19 changes: 17 additions & 2 deletions documents/DeveloperGuide/MainPage.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,24 @@ Building the `install` target of your project will install the MaterialX C++ and

### MaterialX Versioning

The MaterialX codebase uses a modified semantic versioning system where the *major* and *minor* versions match that of the corresponding MaterialX [specification](https://www.materialx.org/Specification.html), and the *build* version represents engineering advances within that specification version. MaterialX documents are similarly marked with the specification version they were authored in, and they are valid to load into any MaterialX codebase with an equal or higher specification version.
The MaterialX codebase uses a modified semantic versioning system where the *major* and *minor* versions match that of the corresponding MaterialX [specification](https://github.com/AcademySoftwareFoundation/MaterialX/blob/main/documents/Specification/MaterialX.Specification.md), and the *build* version represents engineering advances within that specification version. MaterialX documents are similarly marked with the specification version they were authored in, and they are valid to load into any MaterialX codebase with an equal or higher specification version.

Upgrading of MaterialX documents from earlier versions is handled at import time by the Document::upgradeVersion method, which applies the syntax and node interface upgrades that have occurred in previous specification revisions. This allows the syntax conventions of MaterialX and the names and interfaces of nodes to evolve over time, without invalidating documents from earlier versions.
Upgrading of MaterialX documents from earlier versions is handled at import time by the `Document::upgradeVersion` method, which applies the syntax and node interface upgrades that have occurred in previous specification revisions. This allows the syntax conventions of MaterialX and the names and interfaces of nodes to evolve over time, without invalidating documents from earlier versions.

#### MaterialX API Changes

The following rules describe the categories of changes to the [MaterialX API](https://materialx.org/docs/api/classes.html) that are allowed in version upgrades:

- In *build* version upgrades, only non-breaking changes to the MaterialX API are allowed. For any API call that is modified in a build version upgrade, backwards compatibility should be maintained using deprecated C++ and Python wrappers for the original API call.
- In *minor* and *major* version upgrades, breaking changes to the MaterialX API are allowed, though their benefit should be carefully weighed against their cost. Any breaking changes to API calls should be highlighted in the release notes for the new version.

#### MaterialX Data Library Changes

The following rules describe the categories of changes to the [MaterialX Data Libraries](https://github.com/AcademySoftwareFoundation/MaterialX/tree/main/libraries) that are allowed in version upgrades:

- In *build* version upgrades, only additive changes and fixes to the MaterialX data libraries are allowed. Additive changes are allowed to introduce new nodes, node versions, and node inputs with backwards-compatible default values. Data library fixes are allowed to update a node implementation to improve its alignment with the specification, without making any changes to its name or interface.
- In *minor* version upgrades, changes to the names and interfaces of MaterialX nodes are allowed, with the requirement that version upgrade logic be used to maintain the validity and visual interpretation of documents from earlier versions.
- In *major* version upgrades, changes to the syntax rules of MaterialX documents are allowed, with the requirement that version upgrade logic be used to maintain the validity and visual interpretation of documents from earlier versions. These changes usually require synchronized updates to both the MaterialX API and data libraries.

### Additional Links

Expand Down
6 changes: 6 additions & 0 deletions documents/Specification/MaterialX.Specification.md
Original file line number Diff line number Diff line change
Expand Up @@ -1084,6 +1084,12 @@ Math nodes have one or two spatially-varying inputs, and are used to perform a m
* `in1` (float or color<em>N</em> or vector<em>N</em>): the value or nodename for the primary input
* `in2` (same type as `in1` or float): the modulo value or nodename to divide by, cannot be 0 in any channel; default is 1.0 in all channels, which effectively returns the fractional part of a float value

<a id="node-invert"> </a>

* **`invert`**: subtract the incoming float/color/vector from "amount" in all channels, outputting: `amount - in`.
* `in` (float or color<em>N</em> or vector<em>N</em>): the value or nodename for the primary input
* `amount` (same type as `in` or float): the value or nodename to subtract from; default is 1.0 in all channels

<a id="node-absval"> </a>

* **`absval`**: the per-channel absolute value of the incoming float/color/vector.
Expand Down
20 changes: 11 additions & 9 deletions javascript/MaterialXTest/browser/esslShaderGenerator.spec.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// MaterialX is served through a script tag in the test setup.

function createStandardSurfaceMaterial(mx)
function createStandardSurfaceMaterial(mx)
{
const doc = mx.createDocument();
const ssName = 'SR_default';
Expand All @@ -15,19 +15,21 @@ function createStandardSurfaceMaterial(mx)
return doc;
}

describe('Generate ESSL Shaders', function ()
describe('Generate ESSL Shaders', function ()
{
let mx;
const canvas = document.createElement('canvas');
const gl = canvas.getContext('webgl2');

this.timeout(60000);

before(async function () {
before(async function ()
{
mx = await MaterialX();
});

it('Compile Shaders', () => {
it('Compile Shaders', () =>
{
const doc = createStandardSurfaceMaterial(mx);

const gen = new mx.EsslShaderGenerator();
Expand All @@ -37,7 +39,7 @@ describe('Generate ESSL Shaders', function ()
doc.importLibrary(stdlib);

const elem = mx.findRenderableElement(doc);
try
try
{
const mxShader = gen.generate(elem.getNamePath(), elem, genContext);

Expand All @@ -47,7 +49,7 @@ describe('Generate ESSL Shaders', function ()
const glVertexShader = gl.createShader(gl.VERTEX_SHADER);
gl.shaderSource(glVertexShader, vShader);
gl.compileShader(glVertexShader);
if (!gl.getShaderParameter(glVertexShader, gl.COMPILE_STATUS))
if (!gl.getShaderParameter(glVertexShader, gl.COMPILE_STATUS))
{
console.error("-------- VERTEX SHADER FAILED TO COMPILE: ----------------");
console.error("--- VERTEX SHADER LOG ---");
Expand All @@ -61,7 +63,7 @@ describe('Generate ESSL Shaders', function ()
const glPixelShader = gl.createShader(gl.FRAGMENT_SHADER);
gl.shaderSource(glPixelShader, fShader);
gl.compileShader(glPixelShader);
if (!gl.getShaderParameter(glPixelShader, gl.COMPILE_STATUS))
if (!gl.getShaderParameter(glPixelShader, gl.COMPILE_STATUS))
{
console.error("-------- PIXEL SHADER FAILED TO COMPILE: ----------------");
console.error("--- PIXEL SHADER LOG ---");
Expand All @@ -75,7 +77,7 @@ describe('Generate ESSL Shaders', function ()
catch (errPtr)
{
console.error("-------- Failed code generation: ----------------");
console.error(mx.getExceptionMessage(errPtr));
console.error(mx.getExceptionMessage(errPtr));
}
});
});
5 changes: 3 additions & 2 deletions javascript/MaterialXTest/browser/karma.conf.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
module.exports = function(config) {
module.exports = function (config)
{
config.set({
basePath: '../', // base is the javascript folder
files: [
{ pattern: '_build/JsMaterialXGenShader.js', watched: false, included: true, served: true },
{ pattern: '_build/JsMaterialXGenShader.wasm', watched: false, included: false, served: true },
{pattern: '_build/JsMaterialXGenShader.data', watched: false, included: false, served: true, nocache: true },
{ pattern: '_build/JsMaterialXGenShader.data', watched: false, included: false, served: true, nocache: true },
{ pattern: 'browser/*.spec.js', watched: true, included: true, served: true },
],
mime: {
Expand Down
21 changes: 14 additions & 7 deletions javascript/MaterialXTest/codeExamples.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ import { expect } from 'chai';
import Module from './_build/JsMaterialXCore.js';
import { getMtlxStrings } from './testHelpers';

describe('Code Examples', () => {
it('Building a MaterialX Document', async () => {
describe('Code Examples', () =>
{
it('Building a MaterialX Document', async () =>
{
const mx = await Module();
// Create a document.
const doc = mx.createDocument();
Expand Down Expand Up @@ -76,7 +78,8 @@ describe('Code Examples', () => {
// expect(roughness.getBoundValue(material).getValueString()).to.equal('0.5');
});

it('Traversing a Document Tree', async () => {
it('Traversing a Document Tree', async () =>
{
const xmlStr = getMtlxStrings(
['standard_surface_greysphere_calibration.mtlx'],
'../../resources/Materials/Examples/StandardSurface'
Expand All @@ -92,13 +95,16 @@ describe('Code Examples', () => {
let elementCount = 0;
let nodeCount = 0;
let fileCount = 0;
for(let elem of elements) {
for (let elem of elements)
{
elementCount++;
// Display the filename of each image node.
if (elem.isANode('image')) {
if (elem.isANode('image'))
{
nodeCount++;
const input = elem.getInput('file');
if (input) {
if (input)
{
fileCount++;
const filename = input.getValueString();
expect(elem.getName()).to.equal('image1');
Expand All @@ -111,7 +117,8 @@ describe('Code Examples', () => {
expect(fileCount).to.equal(1);
});

it('Building a MaterialX Document', async () => {
it('Building a MaterialX Document', async () =>
{
const xmlStr = getMtlxStrings(['standard_surface_marble_solid.mtlx'], '../../resources/Materials/Examples/StandardSurface')[0];
const mx = await Module();

Expand Down
41 changes: 27 additions & 14 deletions javascript/MaterialXTest/customBindings.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,18 @@ import { expect } from 'chai';
import Module from './_build/JsMaterialXCore.js';
import { getMtlxStrings } from './testHelpers';

describe('Custom Bindings', () => {
describe('Custom Bindings', () =>
{
const examplesPath = '../../resources/Materials/Examples/StandardSurface';

let mx;
before(async () => {
let mx;
before(async () =>
{
mx = await Module();
});

it('Optional parameters work as expected', () => {
it('Optional parameters work as expected', () =>
{
const doc = mx.createDocument();
// Call a method without optional argument
const nodeGraph = doc.addNodeGraph();
Expand All @@ -29,7 +32,8 @@ describe('Custom Bindings', () => {
expect(() => { nodeGraph.addNode(); }).to.throw;
});

it('Vector <-> Array conversion', () => {
it('Vector <-> Array conversion', () =>
{
// Functions that return vectors in C++ should return an array in JS
const doc = mx.createDocument();
const nodeGraph = doc.addNodeGraph();
Expand Down Expand Up @@ -66,7 +70,8 @@ describe('Custom Bindings', () => {
expect(nodes[2].getName()).to.equal('anotherNode'); // Name set explicitly at creation time
});

it('C++ exception handling', () => {
it('C++ exception handling', () =>
{
// Exceptions that are thrown and caught in C++ shouldn't bubble up to JS
const doc = mx.createDocument();
const nodeGraph1 = doc.addNodeGraph();
Expand All @@ -79,15 +84,18 @@ describe('Custom Bindings', () => {
// Exceptions that are not caught in C++ should throw with an exception pointer
nodeGraph1.addNode('node', 'node1');
expect(() => { nodeGraph1.addNode('node', 'node1'); }).to.throw;
try {
try
{
nodeGraph1.addNode('node', 'node1');
} catch (errPtr) {
} catch (errPtr)
{
expect(errPtr).to.be.a('number');
expect(mx.getExceptionMessage(errPtr)).to.be.a('string');
}
});

it('getReferencedSourceUris', async () => {
it('getReferencedSourceUris', async () =>
{
const doc = mx.createDocument();
const filename = 'standard_surface_look_brass_tiled.mtlx';
await mx.readFromXmlFile(doc, filename, examplesPath);
Expand All @@ -98,7 +106,8 @@ describe('Custom Bindings', () => {
expect(sourceUris.includes('standard_surface_brass_tiled.mtlx')).to.be.true;
});

it('Should invoke correct instance of \'validate\'', () => {
it('Should invoke correct instance of \'validate\'', () =>
{
// We check whether the correct function is called by provoking an error message that is specific to the
// function that we expect to be called.
const message = {};
Expand Down Expand Up @@ -126,7 +135,8 @@ describe('Custom Bindings', () => {
expect(message.message).to.include('Unit type definition does not exist in document')
});

it('StringResolver name substitution getters', () => {
it('StringResolver name substitution getters', () =>
{
const fnTestData = {
fnKey: 'fnValue',
fnKey1: 'fnValue1'
Expand Down Expand Up @@ -156,7 +166,8 @@ describe('Custom Bindings', () => {
expect(gnSubs).to.deep.equal(gnTestData);
});

it('getShaderNodes', async () => {
it('getShaderNodes', async () =>
{
const doc = mx.createDocument();
const fileNames = ['standard_surface_marble_solid.mtlx'];
const mtlxStrs = getMtlxStrings(fileNames, examplesPath);
Expand All @@ -175,14 +186,16 @@ describe('Custom Bindings', () => {
expect(shaderNodes.length).to.equal(0);
});

it('createValidName', () => {
it('createValidName', () =>
{
const testString = '_Note_:Please,turn.this+-into*1#valid\nname for_me';
const replaceRegex = /[^a-zA-Z0-9_:]/g
expect(mx.createValidName(testString)).to.equal(testString.replace(replaceRegex, '_'));
expect(mx.createValidName(testString, '-')).to.equal(testString.replace(replaceRegex, '-'));
});

it('getVersionIntegers', () => {
it('getVersionIntegers', () =>
{
const versionStringArr = mx.getVersionString().split('.').map((value) => parseInt(value, 10));

// Global getVersionIntegers
Expand Down
21 changes: 14 additions & 7 deletions javascript/MaterialXTest/document.spec.js
Original file line number Diff line number Diff line change
@@ -1,30 +1,37 @@
import { expect } from 'chai';
import Module from './_build/JsMaterialXCore.js';

describe('Document', () => {
describe('Document', () =>
{
let mx, doc;
before(async () => {
before(async () =>
{
mx = await Module();
// Create a document.
doc = mx.createDocument();
});

function expectError(type, cb) {
try {
function expectError(type, cb)
{
try
{
cb();
throw new Error('Expected function to throw!');
} catch (exceptionPtr) {
} catch (exceptionPtr)
{
const message = mx.getExceptionMessage(exceptionPtr);
expect(message.indexOf(type) !== -1).to.be.true;
}
}

let nodeGraph;
it('Build document', () => {
it('Build document', () =>
{
// Create a node graph with constant and image sources.
nodeGraph = doc.addNodeGraph();
expect(nodeGraph).to.exist;
expectError('Child name is not unique: nodegraph1', () => {
expectError('Child name is not unique: nodegraph1', () =>
{
doc.addNodeGraph(nodeGraph.getName());
});
const constant = nodeGraph.addNode('constant');
Expand Down
Loading

0 comments on commit 9a0d7f0

Please sign in to comment.