Skip to content

⬅️ Back to Table of Contents

📄 VertexColorNode.js

📊 Analysis Summary

Metric Count
🔧 Functions 5
🧱 Classes 1
📦 Imports 3
📊 Variables & Constants 2

📚 Table of Contents

🛠️ File Location:

📂 src/nodes/accessors/VertexColorNode.js

📦 Imports

Name Source
AttributeNode ../core/AttributeNode.js
nodeObject ../tsl/TSLBase.js
Vector4 ../../math/Vector4.js

Variables & Constants

Name Type Kind Value Exported
index number let/var this.index
result any let/var *not shown*

Functions

VertexColorNode.getAttributeName(): string

JSDoc:

/**
     * Overwrites the default implementation by honoring the attribute index.
     *
     * @param {NodeBuilder} builder - The current node builder.
     * @return {string} The attribute name.
     */

Returns: string

Code
getAttributeName( /*builder*/ ) {

        const index = this.index;

        return 'color' + ( index > 0 ? index : '' );

    }

VertexColorNode.generate(builder: any): any

Parameters:

  • builder any

Returns: any

Calls:

  • this.getAttributeName
  • builder.hasGeometryAttribute
  • super.generate
  • builder.generateConst

Internal Comments:

// Vertex color fallback should be white (x3)

Code
generate( builder ) {

        const attributeName = this.getAttributeName( builder );
        const geometryAttribute = builder.hasGeometryAttribute( attributeName );

        let result;

        if ( geometryAttribute === true ) {

            result = super.generate( builder );

        } else {

            // Vertex color fallback should be white
            result = builder.generateConst( this.nodeType, new Vector4( 1, 1, 1, 1 ) );

        }

        return result;

    }

VertexColorNode.serialize(data: any): void

Parameters:

  • data any

Returns: void

Calls:

  • super.serialize
Code
serialize( data ) {

        super.serialize( data );

        data.index = this.index;

    }

VertexColorNode.deserialize(data: any): void

Parameters:

  • data any

Returns: void

Calls:

  • super.deserialize
Code
deserialize( data ) {

        super.deserialize( data );

        this.index = data.index;

    }

vertexColor(index: number): VertexColorNode

Parameters:

  • index number

Returns: VertexColorNode

Calls:

  • nodeObject (from ../tsl/TSLBase.js)
Code
( index = 0 ) => nodeObject( new VertexColorNode( index ) )

Classes

VertexColorNode

Class Code
class VertexColorNode extends AttributeNode {

    static get type() {

        return 'VertexColorNode';

    }

    /**
     * Constructs a new vertex color node.
     *
     * @param {number} index - The attribute index.
     */
    constructor( index ) {

        super( null, 'vec4' );

        /**
         * This flag can be used for type testing.
         *
         * @type {boolean}
         * @readonly
         * @default true
         */
        this.isVertexColorNode = true;

        /**
         * The attribute index to enable more than one sets of vertex colors.
         *
         * @type {number}
         * @default 0
         */
        this.index = index;

    }

    /**
     * Overwrites the default implementation by honoring the attribute index.
     *
     * @param {NodeBuilder} builder - The current node builder.
     * @return {string} The attribute name.
     */
    getAttributeName( /*builder*/ ) {

        const index = this.index;

        return 'color' + ( index > 0 ? index : '' );

    }

    generate( builder ) {

        const attributeName = this.getAttributeName( builder );
        const geometryAttribute = builder.hasGeometryAttribute( attributeName );

        let result;

        if ( geometryAttribute === true ) {

            result = super.generate( builder );

        } else {

            // Vertex color fallback should be white
            result = builder.generateConst( this.nodeType, new Vector4( 1, 1, 1, 1 ) );

        }

        return result;

    }

    serialize( data ) {

        super.serialize( data );

        data.index = this.index;

    }

    deserialize( data ) {

        super.deserialize( data );

        this.index = data.index;

    }

}

Methods

getAttributeName(): string
Code
getAttributeName( /*builder*/ ) {

        const index = this.index;

        return 'color' + ( index > 0 ? index : '' );

    }
generate(builder: any): any
Code
generate( builder ) {

        const attributeName = this.getAttributeName( builder );
        const geometryAttribute = builder.hasGeometryAttribute( attributeName );

        let result;

        if ( geometryAttribute === true ) {

            result = super.generate( builder );

        } else {

            // Vertex color fallback should be white
            result = builder.generateConst( this.nodeType, new Vector4( 1, 1, 1, 1 ) );

        }

        return result;

    }
serialize(data: any): void
Code
serialize( data ) {

        super.serialize( data );

        data.index = this.index;

    }
deserialize(data: any): void
Code
deserialize( data ) {

        super.deserialize( data );

        this.index = data.index;

    }