Reference Source
public class | source

PointLight

Extends:

ComponentLight → PointLight

A positional light source that originates from a single point and spreads outward in all directions, with optional attenuation over distance.

Usage

In the example below we'll replace the Scene's default light sources with three World-space PointLights.

[Run this example]

import {Viewer, Mesh, buildSphereGeometry, buildPlaneGeometry,
     ReadableGeometry, PhongMaterial, Texture, PointLight} from "xeokit-sdk.es.js";

// Create a Viewer and arrange the camera

const viewer = new Viewer({
     canvasId: "myCanvas"
});

viewer.scene.camera.eye = [0, 0, 5];
viewer.scene.camera.look = [0, 0, 0];
viewer.scene.camera.up = [0, 1, 0];

// Replace the Scene's default lights with three custom world-space PointLights

viewer.scene.clearLights();

new PointLight(viewer.scene,{
     id: "keyLight",
     pos: [-80, 60, 80],
     color: [1.0, 0.3, 0.3],
     intensity: 1.0,
     space: "world"
});

new PointLight(viewer.scene,{
     id: "fillLight",
     pos: [80, 40, 40],
     color: [0.3, 1.0, 0.3],
     intensity: 1.0,
     space: "world"
});

new PointLight(viewer.scene,{
     id: "rimLight",
     pos: [-20, 80, -80],
     color: [0.6, 0.6, 0.6],
     intensity: 1.0,
     space: "world"
});

// Create a sphere and ground plane

new Mesh(viewer.scene, {
     geometry: new ReadableGeometry(viewer.scene, buildSphereGeometry({
         radius: 1.3
     }),
     material: new PhongMaterial(viewer.scene, {
         diffuse: [0.7, 0.7, 0.7],
         specular: [1.0, 1.0, 1.0],
         emissive: [0, 0, 0],
         alpha: 1.0,
         ambient: [1, 1, 0],
         diffuseMap: new Texture(viewer.scene, {
             src: "textures/diffuse/uvGrid2.jpg"
         })
     })
});

new Mesh(viewer.scene, {
     geometry: buildPlaneGeometry(ReadableGeometry, viewer.scene, {
         xSize: 30,
         zSize: 30
     }),
     material: new PhongMaterial(viewer.scene, {
         diffuseMap: new Texture(viewer.scene, {
              src: "textures/diffuse/uvGrid2.jpg"
         }),
         backfaces: true
     }),
     position: [0, -2.1, 0]
});

Constructor Summary

Public Constructor
public

constructor(owner: Component, cfg: *)

Member Summary

Public Members
public set

castsShadow(castsShadow: Boolean)

Sets if this PointLight casts a shadow.

public get

Gets if this PointLight casts a shadow.

public set

color(color: Number[])

Sets the RGB color of this PointLight.

public get

color: Number[]: *

Gets the RGB color of this PointLight.

public set

Sets the constant attenuation factor for this PointLight.

public get

Gets the constant attenuation factor for this PointLight.

public set

intensity(intensity: Number)

Sets the intensity of this PointLight.

public get

Gets the intensity of this PointLight.

public set

Sets the linear attenuation factor for this PointLight.

public get

Gets the linear attenuation factor for this PointLight.

public set

pos(pos: Number[])

Sets the position of this PointLight.

public get

pos: Number[]: *

Gets the position of this PointLight.

public set

Sets the quadratic attenuation factor for this PointLight.

public get

Gets the quadratic attenuation factor for this PointLight.

Method Summary

Public Methods
public

Destroys this PointLight.

Inherited Summary

From class Component
public get

The Component that owns the lifecycle of this Component, if any.

public

True as soon as this Component has been destroyed

public

ID of this Component, unique within the Scene.

public

meta: *

Arbitrary, user-defined metadata on this component.

public

The parent Scene that contains this Component.

public

The viewer that contains this Scene.

public

clear()

Destroys all Components that are owned by this.

public

Destroys this component.

public

error(message: String)

Logs an error for this component to the JavaScript console.

public

fire(event: String, value: Object, forget: Boolean)

Fires an event on this component.

public

Returns true if there are any subscribers to the given event on this component.

public

isType(type: *): *: Boolean

Tests if this component is of the given type, or is a subclass of the given type.

public

log(message: String)

Logs a console debugging message for this component.

public

off(subId: String)

Cancels an event subscription that was previously made with Component#on or Component#once.

public

on(event: String, callback: Function, scope: Object): String

Subscribes to an event on this component.

public

once(event: String, callback: Function, scope: Object)

Subscribes to the next occurrence of the given event, then un-subscribes as soon as the event is subIdd.

public

scheduleTask(task: *)

Schedule a task to perform on the next browser interval

public

warn(message: String)

Logs a warning for this component to the JavaScript console.

Public Constructors

public constructor(owner: Component, cfg: *) source

Override:

Light#constructor

Params:

NameTypeAttributeDescription
owner Component

Owner component. When destroyed, the owner will destroy this PointLight as well.

cfg *
  • optional

The PointLight configuration

cfg.id String
  • optional

Optional ID, unique among all components in the parent Scene, generated automatically when omitted.

cfg.pos Number[]
  • optional
  • default: [ 1.0, 1.0, 1.0 ]

Position, in either World or View space, depending on the value of the space parameter.

cfg.color Number[]
  • optional
  • default: [0.7, 0.7, 0.8 ]

Color of this PointLight.

cfg.intensity Number
  • optional
  • default: 1.0

Intensity of this PointLight, as a factor in range [0..1].

cfg.constantAttenuation Number
  • optional
  • default: 0

Constant attenuation factor.

cfg.linearAttenuation Number
  • optional
  • default: 0

Linear attenuation factor.

cfg.quadraticAttenuation Number
  • optional
  • default: 0

Quadratic attenuation factor.

cfg.space String
  • optional
  • default: "view"

The coordinate system this PointLight is defined in - "view" or "world".

cfg.castsShadow Boolean
  • optional
  • default: false

Flag which indicates if this PointLight casts a castsShadow.

Public Members

public set castsShadow(castsShadow: Boolean) source

Sets if this PointLight casts a shadow.

Default value is false.

public get castsShadow: Boolean: * source

Gets if this PointLight casts a shadow.

Default value is false.

Return:

Boolean

true if this PointLight casts shadows.

public set color(color: Number[]) source

Sets the RGB color of this PointLight.

Default value is [0.7, 0.7, 0.8].

public get color: Number[]: * source

Gets the RGB color of this PointLight.

Default value is [0.7, 0.7, 0.8].

Return:

Number[]

The PointLight's RGB color.

public set constantAttenuation(value: Number) source

Sets the constant attenuation factor for this PointLight.

Default value is 0.

public get constantAttenuation: Number: * source

Gets the constant attenuation factor for this PointLight.

Default value is 0.

Return:

Number

The constant attenuation factor.

public set intensity(intensity: Number) source

Sets the intensity of this PointLight.

Default intensity is 1.0 for maximum intensity.

public get intensity: Number: * source

Gets the intensity of this PointLight.

Default value is 1.0 for maximum intensity.

Return:

Number

The PointLight's intensity.

public set linearAttenuation(value: Number) source

Sets the linear attenuation factor for this PointLight.

Default value is 0.

public get linearAttenuation: Number: * source

Gets the linear attenuation factor for this PointLight.

Default value is 0.

Return:

Number

The linear attenuation factor.

public set pos(pos: Number[]) source

Sets the position of this PointLight.

This will be either World- or View-space, depending on the value of PointLight#space.

Default value is [1.0, 1.0, 1.0].

public get pos: Number[]: * source

Gets the position of this PointLight.

This will be either World- or View-space, depending on the value of PointLight#space.

Default value is [1.0, 1.0, 1.0].

Return:

Number[]

The position.

public set quadraticAttenuation(value: Number) source

Sets the quadratic attenuation factor for this PointLight.

Default value is 0.

public get quadraticAttenuation: Number: * source

Gets the quadratic attenuation factor for this PointLight.

Default value is 0.

Return:

Number

The quadratic attenuation factor.

Public Methods

public destroy() source

Destroys this PointLight.

Override:

Component#destroy