import {DirLight} from '@xeokit/xeokit-sdk/src/viewer/scene/lights/DirLight.js'
DirLight
A directional light source that illuminates all Meshes equally from a given direction.
- Has an emission direction vector in DirLight#dir, but no position.
- Defined in either World or View coordinate space. When in World-space, DirLight#dir is relative to the World coordinate system, and will appear to move as the Camera moves. When in View-space, DirLight#dir is relative to the View coordinate system, and will behave as if fixed to the viewer's head.
- AmbientLights, DirLights and PointLights are registered by their Component#id on Scene#lights.
Usage
In the example below we'll replace the Scene's default light sources with three View-space DirLights.
import {Viewer, Mesh, buildSphereGeometry,
buildPlaneGeometry, ReadableGeometry,
PhongMaterial, Texture, DirLight} 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 view-space DirLights
viewer.scene.clearLights();
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 sphere and ground plane
new Mesh(viewer.scene, {
geometry: new ReadableGeometry(viewer.scene, buildSphereGeometry({
radius: 2.0
}),
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 DirLight casts a shadow. |
|
public get |
castsShadow: Boolean: * Gets if this DirLight casts a shadow. |
|
public set |
Sets the RGB color of this DirLight. |
|
public get |
Gets the RGB color of this DirLight. |
|
public set |
Sets the direction in which the DirLight is shining. |
|
public get |
Gets the direction in which the DirLight is shining. |
|
public set |
Sets the intensity of this DirLight. |
|
public get |
Gets the intensity of this DirLight. |
Method Summary
Public Methods | ||
public |
destroy() Destroys this DirLight. |
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 |
destroy() Destroys this component. |
|
public |
Logs an error for this component to the JavaScript console. |
|
public |
Fires an event on this component. |
|
public |
Returns true if there are any subscribers to the given event on this component. |
|
public |
Tests if this component is of the given type, or is a subclass of the given type. |
|
public |
Logs a console debugging message for this component. |
|
public |
Cancels an event subscription that was previously made with Component#on or Component#once. |
|
public |
Subscribes to an event on this component. |
|
public |
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 |
Logs a warning for this component to the JavaScript console. |
Public Constructors
public constructor(owner: Component, cfg: *) source
Override:
Light#constructorParams:
Name | Type | Attribute | Description |
owner | Component | Owner component. When destroyed, the owner will destroy this DirLight as well. |
|
cfg | * |
|
The DirLight configuration |
cfg.id | String |
|
Optional ID, unique among all components in the parent Scene, generated automatically when omitted. |
cfg.dir | Number[] |
|
A unit vector indicating the direction that the light is shining, given in either World or View space, depending on the value of the |
cfg.color | Number[] |
|
The color of this DirLight. |
cfg.intensity | Number |
|
The intensity of this DirLight, as a factor in range |
cfg.space | String |
|
The coordinate system the DirLight is defined in - |
cfg.castsShadow | Boolean |
|
Flag which indicates if this DirLight casts a castsShadow. |
Public Members
public set castsShadow(castsShadow: Boolean) source
Sets if this DirLight casts a shadow.
Default value is false
.
public get castsShadow: Boolean: * source
Gets if this DirLight casts a shadow.
Default value is false
.
public set color(color: Number[]) source
Sets the RGB color of this DirLight.
Default value is [0.7, 0.7, 0.8]
.
public get color: Number[]: * source
Gets the RGB color of this DirLight.
Default value is [0.7, 0.7, 0.8]
.
public set dir(value: Number[]) source
Sets the direction in which the DirLight is shining.
Default value is [1.0, 1.0, 1.0]
.
public get dir: Number[]: * source
Gets the direction in which the DirLight is shining.
Default value is [1.0, 1.0, 1.0]
.