Skip to content

⬅️ Back to Table of Contents

📄 UniformsGroup.js

📊 Analysis Summary

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

📚 Table of Contents

🛠️ File Location:

📂 src/core/UniformsGroup.js

📦 Imports

Name Source
EventDispatcher ./EventDispatcher.js
StaticDrawUsage ../constants.js

Variables & Constants

Name Type Kind Value Exported
_id number let/var 0
uniformsSource Uniform[] let/var source.uniforms
uniforms any let/var Array.isArray( uniformsSource[ i ] ) ? uniformsSource[ i ] : [ uniformsSource...

Functions

UniformsGroup.add(uniform: Uniform): UniformsGroup

JSDoc:

/**
     * Adds the given uniform to this uniforms group.
     *
     * @param {Uniform} uniform - The uniform to add.
     * @return {UniformsGroup} A reference to this uniforms group.
     */

Parameters:

  • uniform Uniform

Returns: UniformsGroup

Calls:

  • this.uniforms.push
Code
add( uniform ) {

        this.uniforms.push( uniform );

        return this;

    }

UniformsGroup.remove(uniform: Uniform): UniformsGroup

JSDoc:

/**
     * Removes the given uniform from this uniforms group.
     *
     * @param {Uniform} uniform - The uniform to remove.
     * @return {UniformsGroup} A reference to this uniforms group.
     */

Parameters:

  • uniform Uniform

Returns: UniformsGroup

Calls:

  • this.uniforms.indexOf
  • this.uniforms.splice
Code
remove( uniform ) {

        const index = this.uniforms.indexOf( uniform );

        if ( index !== - 1 ) this.uniforms.splice( index, 1 );

        return this;

    }

UniformsGroup.setName(name: string): UniformsGroup

JSDoc:

/**
     * Sets the name of this uniforms group.
     *
     * @param {string} name - The name to set.
     * @return {UniformsGroup} A reference to this uniforms group.
     */

Parameters:

  • name string

Returns: UniformsGroup

Code
setName( name ) {

        this.name = name;

        return this;

    }

UniformsGroup.setUsage(value: any): UniformsGroup

JSDoc:

/**
     * Sets the usage of this uniforms group.
     *
     * @param {(StaticDrawUsage|DynamicDrawUsage|StreamDrawUsage|StaticReadUsage|DynamicReadUsage|StreamReadUsage|StaticCopyUsage|DynamicCopyUsage|StreamCopyUsage)} value - The usage to set.
     * @return {UniformsGroup} A reference to this uniforms group.
     */

Parameters:

  • value any

Returns: UniformsGroup

Code
setUsage( value ) {

        this.usage = value;

        return this;

    }

UniformsGroup.dispose(): void

JSDoc:

/**
     * Frees the GPU-related resources allocated by this instance. Call this
     * method whenever this instance is no longer used in your app.
     *
     * @fires Texture#dispose
     */

Returns: void

Calls:

  • this.dispatchEvent
Code
dispose() {

        this.dispatchEvent( { type: 'dispose' } );

    }

UniformsGroup.copy(source: UniformsGroup): UniformsGroup

JSDoc:

/**
     * Copies the values of the given uniforms group to this instance.
     *
     * @param {UniformsGroup} source - The uniforms group to copy.
     * @return {UniformsGroup} A reference to this uniforms group.
     */

Parameters:

  • source UniformsGroup

Returns: UniformsGroup

Calls:

  • Array.isArray
  • this.uniforms.push
  • uniforms[ j ].clone
Code
copy( source ) {

        this.name = source.name;
        this.usage = source.usage;

        const uniformsSource = source.uniforms;

        this.uniforms.length = 0;

        for ( let i = 0, l = uniformsSource.length; i < l; i ++ ) {

            const uniforms = Array.isArray( uniformsSource[ i ] ) ? uniformsSource[ i ] : [ uniformsSource[ i ] ];

            for ( let j = 0; j < uniforms.length; j ++ ) {

                this.uniforms.push( uniforms[ j ].clone() );

            }

        }

        return this;

    }

UniformsGroup.clone(): UniformsGroup

JSDoc:

/**
     * Returns a new uniforms group with copied values from this instance.
     *
     * @return {UniformsGroup} A clone of this instance.
     */

Returns: UniformsGroup

Calls:

  • new this.constructor().copy
Code
clone() {

        return new this.constructor().copy( this );

    }

Classes

UniformsGroup

Class Code
class UniformsGroup extends EventDispatcher {

    /**
     * Constructs a new uniforms group.
     */
    constructor() {

        super();

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

        /**
         * The ID of the 3D object.
         *
         * @name UniformsGroup#id
         * @type {number}
         * @readonly
         */
        Object.defineProperty( this, 'id', { value: _id ++ } );

        /**
         * The name of the uniforms group.
         *
         * @type {string}
         */
        this.name = '';

        /**
         * The buffer usage.
         *
         * @type {(StaticDrawUsage|DynamicDrawUsage|StreamDrawUsage|StaticReadUsage|DynamicReadUsage|StreamReadUsage|StaticCopyUsage|DynamicCopyUsage|StreamCopyUsage)}
         * @default StaticDrawUsage
         */
        this.usage = StaticDrawUsage;

        /**
         * An array holding the uniforms.
         *
         * @type {Array<Uniform>}
         */
        this.uniforms = [];

    }

    /**
     * Adds the given uniform to this uniforms group.
     *
     * @param {Uniform} uniform - The uniform to add.
     * @return {UniformsGroup} A reference to this uniforms group.
     */
    add( uniform ) {

        this.uniforms.push( uniform );

        return this;

    }

    /**
     * Removes the given uniform from this uniforms group.
     *
     * @param {Uniform} uniform - The uniform to remove.
     * @return {UniformsGroup} A reference to this uniforms group.
     */
    remove( uniform ) {

        const index = this.uniforms.indexOf( uniform );

        if ( index !== - 1 ) this.uniforms.splice( index, 1 );

        return this;

    }

    /**
     * Sets the name of this uniforms group.
     *
     * @param {string} name - The name to set.
     * @return {UniformsGroup} A reference to this uniforms group.
     */
    setName( name ) {

        this.name = name;

        return this;

    }

    /**
     * Sets the usage of this uniforms group.
     *
     * @param {(StaticDrawUsage|DynamicDrawUsage|StreamDrawUsage|StaticReadUsage|DynamicReadUsage|StreamReadUsage|StaticCopyUsage|DynamicCopyUsage|StreamCopyUsage)} value - The usage to set.
     * @return {UniformsGroup} A reference to this uniforms group.
     */
    setUsage( value ) {

        this.usage = value;

        return this;

    }

    /**
     * Frees the GPU-related resources allocated by this instance. Call this
     * method whenever this instance is no longer used in your app.
     *
     * @fires Texture#dispose
     */
    dispose() {

        this.dispatchEvent( { type: 'dispose' } );

    }

    /**
     * Copies the values of the given uniforms group to this instance.
     *
     * @param {UniformsGroup} source - The uniforms group to copy.
     * @return {UniformsGroup} A reference to this uniforms group.
     */
    copy( source ) {

        this.name = source.name;
        this.usage = source.usage;

        const uniformsSource = source.uniforms;

        this.uniforms.length = 0;

        for ( let i = 0, l = uniformsSource.length; i < l; i ++ ) {

            const uniforms = Array.isArray( uniformsSource[ i ] ) ? uniformsSource[ i ] : [ uniformsSource[ i ] ];

            for ( let j = 0; j < uniforms.length; j ++ ) {

                this.uniforms.push( uniforms[ j ].clone() );

            }

        }

        return this;

    }

    /**
     * Returns a new uniforms group with copied values from this instance.
     *
     * @return {UniformsGroup} A clone of this instance.
     */
    clone() {

        return new this.constructor().copy( this );

    }

}

Methods

add(uniform: Uniform): UniformsGroup
Code
add( uniform ) {

        this.uniforms.push( uniform );

        return this;

    }
remove(uniform: Uniform): UniformsGroup
Code
remove( uniform ) {

        const index = this.uniforms.indexOf( uniform );

        if ( index !== - 1 ) this.uniforms.splice( index, 1 );

        return this;

    }
setName(name: string): UniformsGroup
Code
setName( name ) {

        this.name = name;

        return this;

    }
setUsage(value: any): UniformsGroup
Code
setUsage( value ) {

        this.usage = value;

        return this;

    }
dispose(): void
Code
dispose() {

        this.dispatchEvent( { type: 'dispose' } );

    }
copy(source: UniformsGroup): UniformsGroup
Code
copy( source ) {

        this.name = source.name;
        this.usage = source.usage;

        const uniformsSource = source.uniforms;

        this.uniforms.length = 0;

        for ( let i = 0, l = uniformsSource.length; i < l; i ++ ) {

            const uniforms = Array.isArray( uniformsSource[ i ] ) ? uniformsSource[ i ] : [ uniformsSource[ i ] ];

            for ( let j = 0; j < uniforms.length; j ++ ) {

                this.uniforms.push( uniforms[ j ].clone() );

            }

        }

        return this;

    }
clone(): UniformsGroup
Code
clone() {

        return new this.constructor().copy( this );

    }