MaterialXLab API  0.0.1
APIs For MaterialXLab Libraries
Loading...
Searching...
No Matches
JsMaterialXGraph.js File Reference

Go to the source code of this file.

Classes

class  MxGraphBuilder
 Class which will build node graph connectivity information from a MaterialX document. More...
 
class  MxMermaidGraphExporter
 Class which will export a graph to Mermaid format. More...
 
class  MxDefinitionCreator
 Class which will create a MaterialX definition from a node graph. More...
 

Functions

function createMermaidGraphFromDocument (doc, opts)
 Create a Mermaid graph from a MaterialX document.
 
function createMaterialXDefinitionFromNodeGraph (doc, nodeGraphName, options=null)
 Utility to create a MaterialX definition from a node graph.
 

Function Documentation

◆ createMaterialXDefinitionFromNodeGraph()

function createMaterialXDefinitionFromNodeGraph ( doc,
nodeGraphName,
options = null )

Utility to create a MaterialX definition from a node graph.

Parameters
{docMaterialX document
nodeGraphNameName of the node graph
optionsOptions for the definition creation. Default value is null.
Returns
{MaterialX document with the definition

Definition at line 931 of file JsMaterialXGraph.js.

932{
933 let graph = doc.getDescendant(nodeGraphName)
934 console.log('Creating MaterialX definition from NodeGraph...',
935 graph.getName())
936 let creator = new MxDefinitionCreator(graph);
937 if (options)
938 creator.options = options;
939 return creator.execute();
940}
Class which will create a MaterialX definition from a node graph.

◆ createMermaidGraphFromDocument()

function createMermaidGraphFromDocument ( doc,
opts )

Create a Mermaid graph from a MaterialX document.

Parameters
{docMaterialX document
optsWrite options. This includes:
  • saveJSON: Save the graph to JSON file
  • inputFileName: Input file name
  • orientation: Orientation of the graph
  • emitCategory: Emit the category of the node
  • emitType: Emit the type of the node
  • graphs: Write sub graphs
Returns
Mermaid graph and JSON string

Definition at line 674 of file JsMaterialXGraph.js.

675{
676 let graphBuilder = new MxGraphBuilder(doc);
677 //graphBuilder.importFromJSON(filename);
678 graphBuilder.setIncludeGraphs(opts.graphs)
679 console.log('Creating graph from MaterialX document...')
680 graphBuilder.execute()
681 if (opts.saveJSON)
682 {
683 console.log('Exporting graph to JSON (graph.json)...')
684 graphBuilder.exportToJSON('graph.json', opts.inputFileName)
685 }
686 jsonString = graphBuilder.getJSON(opts.inputFileName)
687
688 //console.log('Dictionary\n', graphBuilder.getDictionary())
689 //console.log('COnnetions\n', graphBuilder.getConnections())
690
691 let exporter = new MxMermaidGraphExporter(
692 graphBuilder.getDictionary(),
693 graphBuilder.getConnections()
694 );
695
696 console.log('Creating Mermaid from graph...')
697 exporter.setOrientation(opts.orientation);
698 exporter.setEmitCategory(opts.emitCategory);
699 exporter.setEmitType(opts.emitType);
700 exporter.execute();
701
702 result = exporter.getGraph(false)
703 return [result, jsonString];
704}
Class which will build node graph connectivity information from a MaterialX document.
Class which will export a graph to Mermaid format.