Lights


Introduction

The addlight() function accepts a Light object and adds a light to the scene.

The removeLight() function accepts a LightKey object removes the associated light from the scene.

The updateLight() function accepts a LightKey and a Light and updates the light associated with the key to have the properties of the light object that was passed.

The clearLights() removes all lights from the scene. When there are no lights, material colors are drawn at full intensity.

The Light object is used to define the properties of the light: type, space, position, and color.

LightType

All lights in communicator currently have a directional light type. Directional lights approximate a distant light source like the sun. The light's position is interpreted as a vector pointing toward the light rather than a point inside the scene. Light will hit every point in the scene from that direction.

LightSpace

Lights can either be placed in world space or camera space. Specifying a light position in camera space will cause it to follow the camera.

Position

The position of the light in the scene. Note: for directional lights, the position defines the light direction and is not interpreted as a point in the scene.

Color

The light's color.

Lights

The following code adds a red world space light to the scene.

hwv.view.clearLights()
let light = new Communicator.Light(Communicator.LightType.Directional, Communicator.LightSpace.World, new Communicator.Point3(.5, .5, 1), Communicator.Color.red())
hwv.view.addLight(light)

The following code adds a green camera space light to the scene.

hwv.view.clearLights()
let light = new Communicator.Light(Communicator.LightType.Directional, Communicator.LightSpace.Camera, new Communicator.Point3(.5, .5, 1), Communicator.Color.green())
hwv.view.addLight(light)

The following code adds a red and green camera space light to the scene. Then removes the red light

hwv.view.clearLights()
const redLight = new Communicator.Light(Communicator.LightType.Directional, Communicator.LightSpace.World, new Communicator.Point3(0, 0, 1), Communicator.Color.red())
const greenLight = new Communicator.Light(Communicator.LightType.Directional, Communicator.LightSpace.World, new Communicator.Point3(0, 0, -1), Communicator.Color.green())
Promise.all([hwv.view.addLight(redLight), hwv.view.addLight(greenLight)]).then((lightKeys) => {
hwv.view.removeLight(lightKeys[0])
})

The following code adds a red and green camera space light to the scene. Then changes the red light to be yellow

hwv.view.clearLights()
const redLight = new Communicator.Light(Communicator.LightType.Directional, Communicator.LightSpace.World, new Communicator.Point3(0, 0, 1), Communicator.Color.red())
const greenLight = new Communicator.Light(Communicator.LightType.Directional, Communicator.LightSpace.World, new Communicator.Point3(0, 0, -1), Communicator.Color.green())
Promise.all([hwv.view.addLight(redLight), hwv.view.addLight(greenLight)]).then((lightKeys) => {
const yellowLight = new Communicator.Light(Communicator.LightType.Directional, Communicator.LightSpace.World, new Communicator.Point3(0, 0, 1), Communicator.Color.yellow())
hwv.view.updateLight(lightKeys[0], yellowLight)
})

top_level:2 prog_guide:0 viewing:1