Table Of Contents

Previous topic

21.25. The JSProfiling Object

Next topic

21.27. The LightInstance Object

This Page

21.26. The Light Object

A light object is a light template referenced by one or more LightInstances. The LightInstances provides the transformation for the Lights from the SceneNode they are attached to. Direction lights are not effected by the the transformation.

Lights are often created by loading a Scene, see the Scene pipeline documentation.

Required scripts

The Light object requires:

/*{{ javascript("jslib/light.js") }}*/

It also requires that a MathDevice has been created before calling the Light constructor.

21.26.1. Constructor

21.26.1.1. create

Summary

Creates and returns a Light object with passed in parameters.

Syntax

var pointLight = Light.create({name : lightName,
                               color : mathDevice.v3Build(1, 1, 1),
                               point : true,
                               shadows : true,
                               halfExtents : mathDevice.v3Build(40, 40, 40),
                               origin : mathDevice.v3Build(0, 10, 0),
                               material : lightMatrial});

var spotLight = Light.create({name : "spot_light_1",
                              spot : true,
                              color : mathDevice.v3Build(0.89, 1, 0.99),
                              material : coneLightMaterial,
                              right : mathDevice.v3Build(0, 6, 26),
                              up : mathDevice.v3Build(21, 0, 0),
                              target : mathDevice.v3Build(0, -36, 9),
                              shadows : true});

var directionalLight = Light.create({name : "directional_light1",
                                     directional : true,
                                     color : mathDevice.v3Build(0.2, 0.2, 0.8),
                                     direction : mathDevice.v3Build(0, -1, 0),
                                     material : directionalLightMaterial});

var ambient  = Light.create({name : "ambient1",
                             ambient : true,
                             color : mathDevice.v3Build(0.1, 0.1, 0.1)} );

If a light does not have halfExtents, radius or target parameters defined then it is assumed to be a global light.

name
A string. The name of the light.
point, spot, directional, ambient
Booleans representing the type of the light. Only one of these values should be true.
color
A Vector3 object giving numbers [red, green, blue].
material
The Material to use for the light. This supplies the TechniqueParameters to use.
origin
A Vector3 object giving the position of the light source. This property does not need to have the same value as center.
target, right, up, end, start
All Vector3 objects. For defining spot light frustums.
radius
A number defining the radius of effect, particularly for point lights.
halfExtents
The half extents defining the area of effect for non-spot lights.
direction
A Vector3 object.
shadows
Set to true to enable shadows. Only supported for point and spot lights.
disabled
Set to true to disable the light.

Returns a light object.

21.26.2. Methods

21.26.2.1. clone

Summary

Creates a light by cloning an existing light.

Syntax

var newLight = light.clone();

21.26.3. Properties

The properties of lights depends on the type of the light created.

21.26.3.1. name

Summary

A string name of the light.

Syntax

var name = light.name;

21.26.3.2. directional, spot, ambient, point

Booleans representing the type of the light. Only one of these values should be true.

Syntax

if (light.point)
{
    // ...
}

21.26.3.3. global

Summary

Boolean. If set to true then all objects in the Scene are effected by the light. Ambient and directional lights are often global.

Syntax

if (light.global)
{
    // ...
}

21.26.3.4. color

Summary

A Vector3 representing color. Defaults to white.

Syntax

var red = light.color[0];

21.26.3.5. shadows

Summary

Boolean, set to true if the light casts shadows.

Syntax

var shadows = light.shadows;

21.26.3.6. direction

Summary

A Vector3 representing the direction of a direction light.

Syntax

var direction = light.direction;

21.26.3.7. origin

Summary

A Vector3 representing the position of the light source. This property does not need to have the same value as center.

Syntax

var origin = light.origin;

21.26.3.8. center

Summary

A Vector3 representing the center of the light’s bounding box. If the property is missing or undefined it is implied to be [0, 0, 0].

Syntax

var center = light.center;

21.26.3.9. halfExtents

Summary

A Vector3 representing the half extents of the light’s bounding box.

Syntax

var minX = light.center[0] - light.halfExtents[0];

21.26.3.10. radius

Summary

For point lights the radius of effect. The half extents of the light should be set to this value.

Syntax

light.halfExtents[0] = light.radius;

21.26.3.11. disabled

Summary

Boolean value. If its set then the light is ignored.

Syntax

if (light.disabled)
{
    // ...
}

21.26.3.12. material

Summary

The Material to use. This supplies the TechniqueParameters to use.

Syntax

if (light.material)
{
    // ...
}

21.26.3.13. techniqueParameters

Summary

The TechniqueParameters to use.

Syntax

var techniqueParameters = light.techniqueParameters;