MaterialXLab API  0.0.1
APIs For MaterialXLab Libraries
Loading...
Searching...
No Matches
MxGraphHandler Class Reference

Base class for graph handlers. More...

Inheritance diagram for MxGraphHandler:
MxMaterialXHandler

Public Member Functions

 constructor (id, extension)
 
 addConverter (converter)
 Add a converter to the handler.
 
 setMonitor (monitor)
 Set the monitor for the handler.
 
 canExport (extension)
 Return if the handler can export to the given extension / format.
 
 getExporter (extension='')
 Find the first exporter that can export to the given extension / format.
 
 canImport (extension)
 Return if the handler can import the given extension / format.
 
 getImporter (extension='')
 Find the first importer that can import the given extension / format.
 
 setColorSpaces (colorSpaces)
 Set the color spaces used by the handler.
 
 getColorSpaces ()
 Get the color spaces used by the handler.
 
 setUnits (units)
 Set the units used by the handler.
 
 getUnits ()
 Get the units used by the handler.
 
 setSourceColorSpace (colorSpace)
 Set the source color space for the handler.
 
 setTargetDistanceUnit (unit)
 Set the target distance unit for the handler.
 
 getSourceColorSpace ()
 Get the source color space for the handler.
 
 getTargetDistanceUnit ()
 Get the target distance unit for the handler.
 
 getExtension ()
 Get the extension /format for the handler.
 
 initialize (editor)
 Initialize the handler for the given editor.
 
 createValidName (name)
 Create a valid name for the given name.
 
 getDefaultValue (value, _type)
 Get default value as a string for the given value and type.
 

Detailed Description

Base class for graph handlers.

Definition at line 625 of file JsMaterialXNodeEditor.js.

Member Function Documentation

◆ addConverter()

MxGraphHandler::addConverter ( converter)

Add a converter to the handler.

Parameters
converter- The converter to add.
Returns
{void}

Definition at line 658 of file JsMaterialXNodeEditor.js.

658 {
659 // Add to front of list
660 this.converters.unshift(converter);
661 //this.converters.push(converter);
662 }

◆ canExport()

MxGraphHandler::canExport ( extension)

Return if the handler can export to the given extension / format.

Will test any additional converters that have been added to the handler.

Parameters
extension- The extension to check.
Returns
True if the handler can export to the extension, false otherwise.

Definition at line 682 of file JsMaterialXNodeEditor.js.

683 {
684 if (extension == 'mtlx')
685 {
686 return true;
687 }
688 if (this.getExporter(extension))
689 {
690 return true;
691 }
692 return false;
693 }
getExporter(extension='')
Find the first exporter that can export to the given extension / format.

◆ canImport()

MxGraphHandler::canImport ( extension)

Return if the handler can import the given extension / format.

Parameters
extension- The extension to check.
Returns
True if the handler can import the extension, false otherwise.

Definition at line 716 of file JsMaterialXNodeEditor.js.

717 {
718 if (extension == 'mtlx' || extension == 'zip')
719 {
720 return true;
721 }
722 if (this.getImporter(extension))
723 {
724 return true;
725 }
726 return false;
727 }
getImporter(extension='')
Find the first importer that can import the given extension / format.

◆ constructor()

MxGraphHandler::constructor ( id,
extension )

Definition at line 627 of file JsMaterialXNodeEditor.js.

627 {
628 // Identifier
629 this.id = id;
630 // Extension of format that this handler is associated with
631 // Generally the same as the file extension (e.g. mtlx for MaterialX)
632 this.extension = extension;
633 // Editor
634 this.editor = null;
635
636 // Keep track of global color space and distance unit
637 this.DEFAULT_COLOR_SPACE = 'lin_rec709';
638 this.DEFAULT_DISTANCE_UNIT = 'meter';
639 this.sourceColorSpace = this.DEFAULT_COLOR_SPACE;
640 this.targetDistanceUnit = this.DEFAULT_DISTANCE_UNIT;
641 this.colorSpaces = [];
642 this.units = [];
643
644 // List of additional converters that can convert to the format
645 // that this handler can handle
646 this.converters = [];
647
648 // Graph monitoring instance
649 this.monitor = null;
650 }

◆ createValidName()

MxGraphHandler::createValidName ( name)

Create a valid name for the given name.

Default implementation returns the name as is.

Parameters
name- The name to create a valid name for.
Returns
The valid name created.

Definition at line 864 of file JsMaterialXNodeEditor.js.

864 {
865 return name;
866 }

◆ getColorSpaces()

MxGraphHandler::getColorSpaces ( )

Get the color spaces used by the handler.

Returns
The color spaces used by the handler.

Definition at line 759 of file JsMaterialXNodeEditor.js.

759 {
760 return this.colorSpaces;
761 }

◆ getDefaultValue()

MxGraphHandler::getDefaultValue ( value,
_type )

Get default value as a string for the given value and type.

If no value is specified a default value will be returned based on the type.

Parameters
value- The value to get the default value for.
_type- The type of the value.
Returns
The default value for the given value and type.

Definition at line 876 of file JsMaterialXNodeEditor.js.

876 {
877 if (_type === 'string' || _type === 'filename') {
878 value = "'" + value + "'";
879 }
880 else if (this.isArray(_type)) {
881 if (value.length == 0) {
882 if (_type === 'color3')
883 value = "[0.0, 0.0, 0.0]";
884 else if (_type === 'color4')
885 value = "[0.0, 0.0, 0.0, 0.0]";
886 else if (_type === 'vector2')
887 value = "[0.0, 0.0]";
888 else if (_type === 'vector3')
889 value = "[0.0, 0.0, 0.0]";
890 else if (_type === 'vector4')
891 value = "[0.0, 0.0, 0.0, 0.0]";
892 else if (_type === 'matrix33')
893 value = "[1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0]";
894 else if (_type === 'matrix44')
895 value = "[1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0]";
896 }
897 else {
898 value = "[" + value + "]";
899 }
900 }
901 else if (_type === 'integer') {
902 if (value.length == 0) {
903 value = 0;
904 }
905 }
906 else if (_type === 'float') {
907 if (value.length == 0) {
908 value = 0.0;
909 }
910 }
911 else if (_type === 'boolean') {
912 if (value)
913 value = 'true';
914 else
915 value = 'false';
916 }
917
918 if (value.length == 0) {
919 //console.log('No value for input:', _name, 'type:', _type, 'value:', value);=
920 value = "''";
921 }
922 return value;
923 }

◆ getExporter()

MxGraphHandler::getExporter ( extension = '')

Find the first exporter that can export to the given extension / format.

Parameters
extension- The extension to check.
Returns
The first converter that can export to the extension, or null if none found.

Definition at line 701 of file JsMaterialXNodeEditor.js.

701 {
702 for (let converter of this.converters) {
703 if (converter.exportType() == extension) {
704 return converter;
705 }
706 }
707 return null;
708 }

◆ getExtension()

MxGraphHandler::getExtension ( )

Get the extension /format for the handler.

Returns
The extension / format for the handler.

Definition at line 844 of file JsMaterialXNodeEditor.js.

844 {
845 return this.extension;
846 }

◆ getImporter()

MxGraphHandler::getImporter ( extension = '')

Find the first importer that can import the given extension / format.

Parameters
extension- The extension to check.
Returns
The first converter that can import the extension, or null if none found.

Definition at line 735 of file JsMaterialXNodeEditor.js.

735 {
736 for (let converter of this.converters) {
737 if (converter.importType() == extension) {
738 return converter;
739 }
740 }
741 return null;
742 }

◆ getSourceColorSpace()

MxGraphHandler::getSourceColorSpace ( )

Get the source color space for the handler.

Returns
The source color space for the handler.

Definition at line 824 of file JsMaterialXNodeEditor.js.

824 {
825 //console.log('Handler GET source colorspace:', this.sourceColorSpace);
826 return this.sourceColorSpace;
827 }

◆ getTargetDistanceUnit()

MxGraphHandler::getTargetDistanceUnit ( )

Get the target distance unit for the handler.

Returns
The target distance unit for the handler.

Definition at line 834 of file JsMaterialXNodeEditor.js.

834 {
835 //console.log('Handler GET source distance unit:', this.targetDistanceUnit);
836 return this.targetDistanceUnit;
837 }

◆ getUnits()

MxGraphHandler::getUnits ( )

Get the units used by the handler.

Returns
The units used by the handler.

Definition at line 778 of file JsMaterialXNodeEditor.js.

778 {
779 return this.units;
780 }

◆ initialize()

MxGraphHandler::initialize ( editor)

Initialize the handler for the given editor.

Default implementation just sets the editor instance.

Parameters
editor- The editor instance.
Returns
{void}

Definition at line 854 of file JsMaterialXNodeEditor.js.

854 {
855 this.editor = editor;
856 }

◆ setColorSpaces()

MxGraphHandler::setColorSpaces ( colorSpaces)

Set the color spaces used by the handler.

Parameters
colorSpaces- The color spaces to set.
Returns
{void}

Definition at line 750 of file JsMaterialXNodeEditor.js.

750 {
751 this.colorSpaces = colorSpaces;
752 }

◆ setMonitor()

MxGraphHandler::setMonitor ( monitor)

Set the monitor for the handler.

Parameters
monitor- The monitor to set.
Returns
{void}

Definition at line 670 of file JsMaterialXNodeEditor.js.

671 {
672 this.monitor = monitor;
673 }

◆ setSourceColorSpace()

MxGraphHandler::setSourceColorSpace ( colorSpace)

Set the source color space for the handler.

Parameters
colorSpace- The source color space to set.
Returns
{void}

Definition at line 788 of file JsMaterialXNodeEditor.js.

788 {
789 let newSpace = this.DEFAULT_COLOR_SPACE;
790 if (colorSpace && colorSpace.length > 0)
791 newSpace = colorSpace;
792
793 if (this.monitor)
794 {
795 this.monitor.onDocumentChange('colorspace', colorSpace, this.sourceColorSpace);
796 }
797 this.sourceColorSpace = newSpace;
798 }

◆ setTargetDistanceUnit()

MxGraphHandler::setTargetDistanceUnit ( unit)

Set the target distance unit for the handler.

Parameters
unit- The target distance unit to set.
Returns
{void}

Definition at line 806 of file JsMaterialXNodeEditor.js.

806 {
807 let newUnit = this.DEFAULT_DISTANCE_UNIT;
808 if (unit && unit.length > 0)
809 newUnit = unit;
810
811 if (this.monitor)
812 {
813 this.monitor.onDocumentChange('distanceunit', newUnit, this.targetDistanceUnit);
814 }
815 this.targetDistanceUnit = newUnit;
816 //console.log('Handler SET target distance unit:', this.targetDistanceUnit);
817 }

◆ setUnits()

MxGraphHandler::setUnits ( units)

Set the units used by the handler.

Parameters
units- The units to set.
Returns
{void}

Definition at line 769 of file JsMaterialXNodeEditor.js.

769 {
770 this.units = units;
771 }

The documentation for this class was generated from the following file: