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 616 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 649 of file JsMaterialXNodeEditor.js.

649 {
650 // Add to front of list
651 this.converters.unshift(converter);
652 //this.converters.push(converter);
653 }

◆ 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 673 of file JsMaterialXNodeEditor.js.

674 {
675 if (extension == 'mtlx')
676 {
677 return true;
678 }
679 if (this.getExporter(extension))
680 {
681 return true;
682 }
683 return false;
684 }
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 707 of file JsMaterialXNodeEditor.js.

708 {
709 if (extension == 'mtlx')
710 {
711 return true;
712 }
713 if (this.getImporter(extension))
714 {
715 return true;
716 }
717 return false;
718 }
getImporter(extension='')
Find the first importer that can import the given extension / format.

◆ constructor()

MxGraphHandler::constructor ( id,
extension )

Definition at line 618 of file JsMaterialXNodeEditor.js.

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

◆ 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 855 of file JsMaterialXNodeEditor.js.

855 {
856 return name;
857 }

◆ getColorSpaces()

MxGraphHandler::getColorSpaces ( )

Get the color spaces used by the handler.

Returns
The color spaces used by the handler.

Definition at line 750 of file JsMaterialXNodeEditor.js.

750 {
751 return this.colorSpaces;
752 }

◆ 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 867 of file JsMaterialXNodeEditor.js.

867 {
868 if (_type === 'string' || _type === 'filename') {
869 value = "'" + value + "'";
870 }
871 else if (this.isArray(_type)) {
872 if (value.length == 0) {
873 if (_type === 'color3')
874 value = "[0.0, 0.0, 0.0]";
875 else if (_type === 'color4')
876 value = "[0.0, 0.0, 0.0, 0.0]";
877 else if (_type === 'vector2')
878 value = "[0.0, 0.0]";
879 else if (_type === 'vector3')
880 value = "[0.0, 0.0, 0.0]";
881 else if (_type === 'vector4')
882 value = "[0.0, 0.0, 0.0, 0.0]";
883 else if (_type === 'matrix33')
884 value = "[1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0]";
885 else if (_type === 'matrix44')
886 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]";
887 }
888 else {
889 value = "[" + value + "]";
890 }
891 }
892 else if (_type === 'integer') {
893 if (value.length == 0) {
894 value = 0;
895 }
896 }
897 else if (_type === 'float') {
898 if (value.length == 0) {
899 value = 0.0;
900 }
901 }
902 else if (_type === 'boolean') {
903 if (value)
904 value = 'true';
905 else
906 value = 'false';
907 }
908
909 if (value.length == 0) {
910 //console.log('No value for input:', _name, 'type:', _type, 'value:', value);=
911 value = "''";
912 }
913 return value;
914 }

◆ 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 692 of file JsMaterialXNodeEditor.js.

692 {
693 for (let converter of this.converters) {
694 if (converter.exportType() == extension) {
695 return converter;
696 }
697 }
698 return null;
699 }

◆ getExtension()

MxGraphHandler::getExtension ( )

Get the extension /format for the handler.

Returns
The extension / format for the handler.

Definition at line 835 of file JsMaterialXNodeEditor.js.

835 {
836 return this.extension;
837 }

◆ 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 726 of file JsMaterialXNodeEditor.js.

726 {
727 for (let converter of this.converters) {
728 if (converter.importType() == extension) {
729 return converter;
730 }
731 }
732 return null;
733 }

◆ getSourceColorSpace()

MxGraphHandler::getSourceColorSpace ( )

Get the source color space for the handler.

Returns
The source color space for the handler.

Definition at line 815 of file JsMaterialXNodeEditor.js.

815 {
816 //console.log('Handler GET source colorspace:', this.sourceColorSpace);
817 return this.sourceColorSpace;
818 }

◆ getTargetDistanceUnit()

MxGraphHandler::getTargetDistanceUnit ( )

Get the target distance unit for the handler.

Returns
The target distance unit for the handler.

Definition at line 825 of file JsMaterialXNodeEditor.js.

825 {
826 //console.log('Handler GET source distance unit:', this.targetDistanceUnit);
827 return this.targetDistanceUnit;
828 }

◆ getUnits()

MxGraphHandler::getUnits ( )

Get the units used by the handler.

Returns
The units used by the handler.

Definition at line 769 of file JsMaterialXNodeEditor.js.

769 {
770 return this.units;
771 }

◆ 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 845 of file JsMaterialXNodeEditor.js.

845 {
846 this.editor = editor;
847 }

◆ setColorSpaces()

MxGraphHandler::setColorSpaces ( colorSpaces)

Set the color spaces used by the handler.

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

Definition at line 741 of file JsMaterialXNodeEditor.js.

741 {
742 this.colorSpaces = colorSpaces;
743 }

◆ setMonitor()

MxGraphHandler::setMonitor ( monitor)

Set the monitor for the handler.

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

Definition at line 661 of file JsMaterialXNodeEditor.js.

662 {
663 this.monitor = monitor;
664 }

◆ 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 779 of file JsMaterialXNodeEditor.js.

779 {
780 let newSpace = this.DEFAULT_COLOR_SPACE;
781 if (colorSpace && colorSpace.length > 0)
782 newSpace = colorSpace;
783
784 if (this.monitor)
785 {
786 this.monitor.onDocumentChange('colorspace', colorSpace, this.sourceColorSpace);
787 }
788 this.sourceColorSpace = newSpace;
789 }

◆ 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 797 of file JsMaterialXNodeEditor.js.

797 {
798 let newUnit = this.DEFAULT_DISTANCE_UNIT;
799 if (unit && unit.length > 0)
800 newUnit = unit;
801
802 if (this.monitor)
803 {
804 this.monitor.onDocumentChange('distanceunit', newUnit, this.targetDistanceUnit);
805 }
806 this.targetDistanceUnit = newUnit;
807 //console.log('Handler SET target distance unit:', this.targetDistanceUnit);
808 }

◆ setUnits()

MxGraphHandler::setUnits ( units)

Set the units used by the handler.

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

Definition at line 760 of file JsMaterialXNodeEditor.js.

760 {
761 this.units = units;
762 }

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