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 910 of file JsMaterialXGraph.js.

911{
912 let graph = doc.getDescendant(nodeGraphName)
913 console.log('Creating MaterialX definition from NodeGraph...',
914 graph.getName())
915 let creator = new MxDefinitionCreator(graph);
916 if (options)
917 creator.options = options;
918 return creator.execute();
919}
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.