Skip to content

⬅️ Back to Table of Contents

📄 PointLight.js

📊 Analysis Summary

Metric Count
🔧 Functions 2
🧱 Classes 1
📦 Imports 2

📚 Table of Contents

🛠️ File Location:

📂 src/lights/PointLight.js

📦 Imports

Name Source
Light ./Light.js
PointLightShadow ./PointLightShadow.js

Functions

PointLight.dispose(): void

Returns: void

Calls:

  • this.shadow.dispose
Code
dispose() {

        this.shadow.dispose();

    }

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

Parameters:

  • source any
  • recursive any

Returns: this

Calls:

  • super.copy
  • source.shadow.clone
Code
copy( source, recursive ) {

        super.copy( source, recursive );

        this.distance = source.distance;
        this.decay = source.decay;

        this.shadow = source.shadow.clone();

        return this;

    }

Classes

PointLight

Class Code
class PointLight extends Light {

    /**
     * Constructs a new point light.
     *
     * @param {(number|Color|string)} [color=0xffffff] - The light's color.
     * @param {number} [intensity=1] - The light's strength/intensity measured in candela (cd).
     * @param {number} [distance=0] - Maximum range of the light. `0` means no limit.
     * @param {number} [decay=2] - The amount the light dims along the distance of the light.
     */
    constructor( color, intensity, distance = 0, decay = 2 ) {

        super( color, intensity );

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

        this.type = 'PointLight';

        /**
         * When distance is zero, light will attenuate according to inverse-square
         * law to infinite distance. When distance is non-zero, light will attenuate
         * according to inverse-square law until near the distance cutoff, where it
         * will then attenuate quickly and smoothly to 0. Inherently, cutoffs are not
         * physically correct.
         *
         * @type {number}
         * @default 0
         */
        this.distance = distance;

        /**
         * The amount the light dims along the distance of the light. In context of
         * physically-correct rendering the default value should not be changed.
         *
         * @type {number}
         * @default 2
         */
        this.decay = decay;

        /**
         * This property holds the light's shadow configuration.
         *
         * @type {PointLightShadow}
         */
        this.shadow = new PointLightShadow();

    }

    /**
     * The light's power. Power is the luminous power of the light measured in lumens (lm).
     * Changing the power will also change the light's intensity.
     *
     * @type {number}
     */
    get power() {

        // compute the light's luminous power (in lumens) from its intensity (in candela)
        // for an isotropic light source, luminous power (lm) = 4 π luminous intensity (cd)
        return this.intensity * 4 * Math.PI;

    }

    set power( power ) {

        // set the light's intensity (in candela) from the desired luminous power (in lumens)
        this.intensity = power / ( 4 * Math.PI );

    }

    dispose() {

        this.shadow.dispose();

    }

    copy( source, recursive ) {

        super.copy( source, recursive );

        this.distance = source.distance;
        this.decay = source.decay;

        this.shadow = source.shadow.clone();

        return this;

    }

}

Methods

dispose(): void
Code
dispose() {

        this.shadow.dispose();

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

        super.copy( source, recursive );

        this.distance = source.distance;
        this.decay = source.decay;

        this.shadow = source.shadow.clone();

        return this;

    }