Skip to content

⬅️ Back to Table of Contents

📄 Light.js

📊 Analysis Summary

Metric Count
🔧 Functions 3
🧱 Classes 1
📦 Imports 2

📚 Table of Contents

🛠️ File Location:

📂 src/lights/Light.js

📦 Imports

Name Source
Object3D ../core/Object3D.js
Color ../math/Color.js

Functions

Light.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.
     */

Returns: void

Code
dispose() {

        // Empty here in base class; some subclasses override.

    }

Light.copy(source: any, recursive: any): this

Parameters:

  • source any
  • recursive any

Returns: this

Calls:

  • super.copy
  • this.color.copy
Code
copy( source, recursive ) {

        super.copy( source, recursive );

        this.color.copy( source.color );
        this.intensity = source.intensity;

        return this;

    }

Light.toJSON(meta: any): any

Parameters:

  • meta any

Returns: any

Calls:

  • super.toJSON
  • this.color.getHex
  • this.groundColor.getHex
  • this.shadow.toJSON
Code
toJSON( meta ) {

        const data = super.toJSON( meta );

        data.object.color = this.color.getHex();
        data.object.intensity = this.intensity;

        if ( this.groundColor !== undefined ) data.object.groundColor = this.groundColor.getHex();

        if ( this.distance !== undefined ) data.object.distance = this.distance;
        if ( this.angle !== undefined ) data.object.angle = this.angle;
        if ( this.decay !== undefined ) data.object.decay = this.decay;
        if ( this.penumbra !== undefined ) data.object.penumbra = this.penumbra;

        if ( this.shadow !== undefined ) data.object.shadow = this.shadow.toJSON();
        if ( this.target !== undefined ) data.object.target = this.target.uuid;

        return data;

    }

Classes

Light

Class Code
class Light extends Object3D {

    /**
     * Constructs a new light.
     *
     * @param {(number|Color|string)} [color=0xffffff] - The light's color.
     * @param {number} [intensity=1] - The light's strength/intensity.
     */
    constructor( color, intensity = 1 ) {

        super();

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

        this.type = 'Light';

        /**
         * The light's color.
         *
         * @type {Color}
         */
        this.color = new Color( color );

        /**
         * The light's intensity.
         *
         * @type {number}
         * @default 1
         */
        this.intensity = intensity;

    }

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

        // Empty here in base class; some subclasses override.

    }

    copy( source, recursive ) {

        super.copy( source, recursive );

        this.color.copy( source.color );
        this.intensity = source.intensity;

        return this;

    }

    toJSON( meta ) {

        const data = super.toJSON( meta );

        data.object.color = this.color.getHex();
        data.object.intensity = this.intensity;

        if ( this.groundColor !== undefined ) data.object.groundColor = this.groundColor.getHex();

        if ( this.distance !== undefined ) data.object.distance = this.distance;
        if ( this.angle !== undefined ) data.object.angle = this.angle;
        if ( this.decay !== undefined ) data.object.decay = this.decay;
        if ( this.penumbra !== undefined ) data.object.penumbra = this.penumbra;

        if ( this.shadow !== undefined ) data.object.shadow = this.shadow.toJSON();
        if ( this.target !== undefined ) data.object.target = this.target.uuid;

        return data;

    }

}

Methods

dispose(): void
Code
dispose() {

        // Empty here in base class; some subclasses override.

    }
copy(source: any, recursive: any): this
Code
copy( source, recursive ) {

        super.copy( source, recursive );

        this.color.copy( source.color );
        this.intensity = source.intensity;

        return this;

    }
toJSON(meta: any): any
Code
toJSON( meta ) {

        const data = super.toJSON( meta );

        data.object.color = this.color.getHex();
        data.object.intensity = this.intensity;

        if ( this.groundColor !== undefined ) data.object.groundColor = this.groundColor.getHex();

        if ( this.distance !== undefined ) data.object.distance = this.distance;
        if ( this.angle !== undefined ) data.object.angle = this.angle;
        if ( this.decay !== undefined ) data.object.decay = this.decay;
        if ( this.penumbra !== undefined ) data.object.penumbra = this.penumbra;

        if ( this.shadow !== undefined ) data.object.shadow = this.shadow.toJSON();
        if ( this.target !== undefined ) data.object.target = this.target.uuid;

        return data;

    }