Reference Source
public class | source

AmbientLight

Extends:

ComponentLight → AmbientLight

An ambient light source of fixed color and intensity that illuminates all Meshes equally.

Usage

In the example below we'll destroy the Scene's default light sources then create an AmbientLight and a couple of {@link @DirLight}s:

[Run this example]

import {Viewer, Mesh, buildTorusGeometry,
ReadableGeometry, PhongMaterial, Texture, AmbientLight} 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 a single custom AmbientLight

viewer.scene.clearLights();

new AmbientLight(viewer.scene, {
     color: [0.0, 0.3, 0.7],
     intensity: 1.0
});

new DirLight(viewer.scene, {
     id: "keyLight",
     dir: [0.8, -0.6, -0.8],
     color: [1.0, 0.3, 0.3],
     intensity: 1.0,
     space: "view"
});

new DirLight(viewer.scene, {
     id: "fillLight",
     dir: [-0.8, -0.4, -0.4],
     color: [0.3, 1.0, 0.3],
     intensity: 1.0,
     space: "view"
});

new DirLight(viewer.scene, {
     id: "rimLight",
     dir: [0.2, -0.8, 0.8],
     color: [0.6, 0.6, 0.6],
     intensity: 1.0,
     space: "view"
});

// Create a mesh with torus shape and PhongMaterial

new Mesh(viewer.scene, {
     geometry: new ReadableGeometry(viewer.scene, buildSphereGeometry({
         center: [0, 0, 0],
         radius: 1.5,
         tube: 0.5,
         radialSegments: 32,
         tubeSegments: 24,
         arc: Math.PI * 2.0
     }),
     material: new PhongMaterial(viewer.scene, {
         ambient: [1.0, 1.0, 1.0],
         shininess: 30,
         diffuseMap: new Texture(viewer.scene, {
             src: "textures/diffuse/uvGrid2.jpg"
         })
     })
});

// Adjust the color of our AmbientLight

var ambientLight = viewer.scene.lights["myAmbientLight"];
ambientLight.color = [1.0, 0.8, 0.8];

Constructor Summary

Public Constructor
public

constructor(owner: Component, cfg: *)

Member Summary

Public Members
public set

color(color: Number[])

Sets the RGB color of this AmbientLight.

public get

color: Number[]: *

Gets the RGB color of this AmbientLight.

public set

intensity(intensity: Number)

Sets the intensity of this AmbientLight.

public get

Gets the intensity of this AmbientLight.

Method Summary

Public Methods
public

Destroys this AmbientLight.

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 AmbientLight as well.

cfg *
  • optional

AmbientLight configuration

cfg.id String
  • optional

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

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

The color of this AmbientLight.

cfg.intensity Number
  • optional
  • default: [1.0]

The intensity of this AmbientLight, as a factor in range [0..1].

Public Members

public set color(color: Number[]) source

Sets the RGB color of this AmbientLight.

Default value is [0.7, 0.7, 0.8].

public get color: Number[]: * source

Gets the RGB color of this AmbientLight.

Default value is [0.7, 0.7, 0.8].

Return:

Number[]

The AmbientLight's RGB color.

public set intensity(intensity: Number) source

Sets the intensity of this AmbientLight.

Default value is 1.0 for maximum intensity.

public get intensity: Number: * source

Gets the intensity of this AmbientLight.

Default value is 1.0 for maximum intensity.

Return:

Number

The AmbientLight's intensity.

Public Methods

public destroy() source

Destroys this AmbientLight.

Override:

Component#destroy