Skip to content

Commit

Permalink
Update codeExamples
Browse files Browse the repository at this point in the history
  • Loading branch information
frericp committed Jul 6, 2021
1 parent 8838087 commit c7891f4
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 14 deletions.
18 changes: 6 additions & 12 deletions documents/DeveloperGuide/CodeExamples.md
Original file line number Diff line number Diff line change
Expand Up @@ -167,28 +167,22 @@ for elem in doc.traverseTree():
~~~{.js}
import MaterialX from './JsMaterialXCore.js';
MaterialX().then(async (_module) => {
// Get the MaterialX namespace.
const mx = _module.getMaterialX();
MaterialX().then(async (mx) => {
// Read a document from disk.
const doc = mx.createDocument();
// Note: The xmlStr should be defined.
await mx.readFromXmlString(doc, xmlStr);
await mx.readFromXmlFile(doc, 'ExampleFile.mtlx');
// Traverse the document tree in depth-first order.
const elements = doc.traverseTree();
let elem = elements.next();
while(elem) {
for (let elem of elements) {
// Display the filename of each image node.
if (elem instanceof mx.Node) {
const param = elem.getParameter('file');
if (elem.isANode('image')) {
const param = elem.getInput('file');
if (param) {
filename = param.getValueString();
console.log('Image node ' + elem.getName() + ' references ' + filename);
}
}
elem = elements.next();
}
}
~~~
Expand Down Expand Up @@ -300,4 +294,4 @@ MaterialX().then(async (_module) => {
});
});
}
~~~
~~~
4 changes: 2 additions & 2 deletions source/JsMaterialX/test/codeExamples.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ describe('Code Examples', () => {
for(let elem of elements) {
elementCount++;
// Display the filename of each image node.
if (elem instanceof mx.Node) {
if (elem.isANode('image')) {
nodeCount++;
const input = elem.getInput('file');
if (input) {
Expand All @@ -107,7 +107,7 @@ describe('Code Examples', () => {
}
}
expect(elementCount).to.equal(21);
expect(nodeCount).to.equal(5);
expect(nodeCount).to.equal(1);
expect(fileCount).to.equal(1);
});

Expand Down

0 comments on commit c7891f4

Please sign in to comment.