Game Development Reference
In-Depth Information
for (var i = 0; i < geometry.length; i++) {
var mesh = new THREE.Mesh(geometry[i][0], material);
lod.addLevel(mesh, geometry[i][1]);
}
scene.add(lod);
The LOD object stores objects of different complexities along with the distances
at which higher-detail versions should be used. To make the mesh change detail
when the camera moves closer or farther away, we'll update the LOD object in the
animation loop:
scene.traverse(function(object) {
if (object instanceof THREE.LOD) {
object.position.z = 2500 * Math.cos(Date.now() / 1000);
object.update(camera);
}
});
We added a little bit of movement here so that we can see the detail change. Let's
move the camera so that we can see the movement better by setting camera.
position.z = 3000 . Now you should be able to see the detail change dynamically,
as shown in the following screenshot:
A sphere with increasing detail as the camera gets closer
 
Search WWH ::




Custom Search