Lighting ( OccViewer.Lights) in LWV plays a crucial role in enhancing the visual representation of 3D models. The framework offers a flexible and powerful system to define and control various types of light sources. Below is an overview of the key features and parameters associated with lights in LWV.

Types of Light Sources:

  • Ambient Light: A general light source that uniformly illuminates the scene.
  • Directional Light: Simulates light from a distant source (like the sun), defined by a direction vector.
  • Positional Light: A point light source that emits light in all directions from a specific position in 3D space.
  • Spot Light: A focused light source that emits a cone of light, defined by its position, direction, and cone angle.

Light Parameters ( OccViewer.WasmLightParams):

  • Type: Specifies the type of light (AMBIENT, DIRECTIONAL, POSITIONAL, SPOT).
  • Direction (dir): The direction vector for directional light.
  • Intensity: Defines the brightness of the light.
  • Shadows (toCastShadows): Determines whether the light casts shadows (directional lights only).
  • Headlight Mode (isHeadlight): Indicates whether the light follows the camera.
  • Enabled State (isEnabled): Toggles the light on or off.
  • Color: Defines the base color of the light as a normalized color string.
  • Name: A unique identifier for the light source.
  • Position: 3D coordinates for the positional light source.
  • Range: Specifies the distance limit for positional light.
  • Angle: The cone angle of a spotlight in radians.

Usage and Management Light sources can be created and managed using the LightsController( OccViewer.LightsController) class in conjunction with the lights property of the viewer. This allows dynamic updates to the lighting setup, enabling developers to create highly realistic scenes with minimal effort.

// getting all automatically added lights
const aLightList = OccViewerModule.lights.getLights();
// add a new light
OccViewerModule.lights.addLight(
{
angle: 0,
color: '#FFFFFF',
dir: {x: 0.0, y: 0.0, z: -1},
intensity: 20.0,
isHeadlight: false,
name: 'light_' + Date.now(),
position: {x: 0, y: 0, z: 0},
range: 0,
toCastShadows: true,
type: OccViewerModule.Graphic3d_TypeOfLightSource.DIRECTIONAL,
},
true,
);