Skip to content

⬅️ Back to Table of Contents

📄 NodeMaterialLoader.js

📊 Analysis Summary

Metric Count
🔧 Functions 4
🧱 Classes 1
📦 Imports 1
📊 Variables & Constants 4

📚 Table of Contents

🛠️ File Location:

📂 src/loaders/nodes/NodeMaterialLoader.js

📦 Imports

Name Source
MaterialLoader ../../loaders/MaterialLoader.js

Variables & Constants

Name Type Kind Value Exported
nodes { [x: string]: Node.constructor; } let/var this.nodes
inputNodes any let/var json.inputNodes
uuid any let/var inputNodes[ property ]
materialClass NodeMaterial.constructor let/var this.nodeMaterials[ type ]

Functions

NodeMaterialLoader.parse(json: any): NodeMaterial

JSDoc:

/**
     * Parses the node material from the given JSON.
     *
     * @param {Object} json - The JSON definition
     * @return {NodeMaterial}. The parsed material.
     */

Parameters:

  • json any

Returns: NodeMaterial

Calls:

  • super.parse
Code
parse( json ) {

        const material = super.parse( json );

        const nodes = this.nodes;
        const inputNodes = json.inputNodes;

        for ( const property in inputNodes ) {

            const uuid = inputNodes[ property ];

            material[ property ] = nodes[ uuid ];

        }

        return material;

    }

NodeMaterialLoader.setNodes(value: { [x: string]: Node.constructor; }): NodeLoader

JSDoc:

/**
     * Defines the dictionary of node types.
     *
     * @param {Object<string,Node.constructor>} value - The node library defined as `<classname,class>`.
     * @return {NodeLoader} A reference to this loader.
     */

Parameters:

  • value { [x: string]: Node.constructor; }

Returns: NodeLoader

Code
setNodes( value ) {

        this.nodes = value;
        return this;

    }

NodeMaterialLoader.setNodeMaterials(value: { [x: string]: NodeMaterial.constructor; }): NodeLoader

JSDoc:

/**
     * Defines the dictionary of node material types.
     *
     * @param {Object<string,NodeMaterial.constructor>} value - The node material library defined as `<classname,class>`.
     * @return {NodeLoader} A reference to this loader.
     */

Parameters:

  • value { [x: string]: NodeMaterial.constructor; }

Returns: NodeLoader

Code
setNodeMaterials( value ) {

        this.nodeMaterials = value;
        return this;

    }

NodeMaterialLoader.createMaterialFromType(type: string): Node

JSDoc:

/**
     * Creates a node material from the given type.
     *
     * @param {string} type - The node material type.
     * @return {Node} The created node material instance.
     */

Parameters:

  • type string

Returns: Node

Calls:

  • super.createMaterialFromType
Code
createMaterialFromType( type ) {

        const materialClass = this.nodeMaterials[ type ];

        if ( materialClass !== undefined ) {

            return new materialClass();

        }

        return super.createMaterialFromType( type );

    }

Classes

NodeMaterialLoader

Class Code
class NodeMaterialLoader extends MaterialLoader {

    /**
     * Constructs a new node material loader.
     *
     * @param {LoadingManager} [manager] - A reference to a loading manager.
     */
    constructor( manager ) {

        super( manager );

        /**
         * Represents a dictionary of node types.
         *
         * @type {Object<string,Node.constructor>}
         */
        this.nodes = {};

        /**
         * Represents a dictionary of node material types.
         *
         * @type {Object<string,NodeMaterial.constructor>}
         */
        this.nodeMaterials = {};

    }

    /**
     * Parses the node material from the given JSON.
     *
     * @param {Object} json - The JSON definition
     * @return {NodeMaterial}. The parsed material.
     */
    parse( json ) {

        const material = super.parse( json );

        const nodes = this.nodes;
        const inputNodes = json.inputNodes;

        for ( const property in inputNodes ) {

            const uuid = inputNodes[ property ];

            material[ property ] = nodes[ uuid ];

        }

        return material;

    }

    /**
     * Defines the dictionary of node types.
     *
     * @param {Object<string,Node.constructor>} value - The node library defined as `<classname,class>`.
     * @return {NodeLoader} A reference to this loader.
     */
    setNodes( value ) {

        this.nodes = value;
        return this;

    }

    /**
     * Defines the dictionary of node material types.
     *
     * @param {Object<string,NodeMaterial.constructor>} value - The node material library defined as `<classname,class>`.
     * @return {NodeLoader} A reference to this loader.
     */
    setNodeMaterials( value ) {

        this.nodeMaterials = value;
        return this;

    }

    /**
     * Creates a node material from the given type.
     *
     * @param {string} type - The node material type.
     * @return {Node} The created node material instance.
     */
    createMaterialFromType( type ) {

        const materialClass = this.nodeMaterials[ type ];

        if ( materialClass !== undefined ) {

            return new materialClass();

        }

        return super.createMaterialFromType( type );

    }

}

Methods

parse(json: any): NodeMaterial
Code
parse( json ) {

        const material = super.parse( json );

        const nodes = this.nodes;
        const inputNodes = json.inputNodes;

        for ( const property in inputNodes ) {

            const uuid = inputNodes[ property ];

            material[ property ] = nodes[ uuid ];

        }

        return material;

    }
setNodes(value: { [x: string]: Node.constructor; }): NodeLoader
Code
setNodes( value ) {

        this.nodes = value;
        return this;

    }
setNodeMaterials(value: { [x: string]: NodeMaterial.constructor; }): NodeLoader
Code
setNodeMaterials( value ) {

        this.nodeMaterials = value;
        return this;

    }
createMaterialFromType(type: string): Node
Code
createMaterialFromType( type ) {

        const materialClass = this.nodeMaterials[ type ];

        if ( materialClass !== undefined ) {

            return new materialClass();

        }

        return super.createMaterialFromType( type );

    }