LOD - Verge3D User Manual - Soft8Soft
Description: Learn how to use LOD in your interactive 3D apps made with Verge3D

Object3D →

# LOD

Level of Detail — show meshes with more or less geometry based on distance from the camera.

Every level is associated with an object, and rendering can be switched between them at the distances specified. Typically you would create, say, three meshes, one for far away (low detail), one for mid range (medium detail) and one for close up (high detail).

## Code Example

`const lod = new v3d.LOD(); // create spheres with 3 levels of detail and create new LOD levels for them for (let i = 0; i < 3; i++) { const geometry = new v3d.IcosahedronGeometry(10, 3 - i) const mesh = new v3d.Mesh(geometry, material); lod.addLevel(mesh, i * 75); } app.scene.add(lod);`

## Constructor

### LOD()

Creates a new LOD.

## Properties

See the base Object3D class for inherited properties.

### # .autoUpdate : Boolean

Whether the LOD object is updated automatically by the renderer per frame or not. If set to `false`, you have to call LOD.update() in the render loop by yourself. Default is `true`.

### # .isLOD : Boolean

Read-only flag to check if a given object is of type LOD.

### # .levels : Array

An array of level objects.

Each level is an object with the following properties:

- object — the Object3D to display at this level.
- distance — the distance at which to display this level of detail.
- hysteresis — threshold used to avoid flickering at LOD boundaries, as a fraction of distance.

## Methods

See the base Object3D class for inherited methods.

### # .addLevel(object : Object3D, distance : Float, hysteresis : Float) → this

- object — the Object3D to display at this level.
- distance — the distance at which to display this level of detail. Default `0.0`.
- hysteresis — threshold used to avoid flickering at LOD boundaries, as a fraction of distance. Default `0.0`.

Adds a mesh that will display at a certain distance and greater. Typically the further away the distance, the lower the detail on the mesh.

### # .clone() → LOD

Returns a clone of this LOD object with its associated levels.

### # .getCurrentLevel() → Integer

Get the currently active LOD level. As index of the levels array.

### # .getObjectForDistance(distance : Float) → Object3D

Get a reference to the first Object3D (mesh) with LOD greater than distance.

### # .raycast(raycaster : Raycaster, intersects : Array)

Get intersections between a casted Ray and this LOD. Raycaster.intersectObject will call this method.

### # .update(camera : Camera)

Set the visibility of each level's object based on distance from the camera.

## Source

For more info on how to obtain the source code of this module see this page.