Object3D

多细节层次(LOD,Levels of Detail)

多细节层次 —— 在显示网格时,根据摄影机距离物体的距离,来使用更多或者更少的几何体来对其进行显示。

每一个级别都和一个几何体相关联,且在渲染时,可以根据给定的距离,来在这些级别对应的几何体之间进行切换。 通常情况下,你会创建多个几何体,比如说三个,一个距离很远(低细节),一个距离适中(中等细节),还有一个距离非常近(高质量)。

代码示例

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.IcosahedronBufferGeometry(10, 3 - i) const mesh = new v3d.Mesh(geometry, material); lod.addLevel(mesh, i * 75); } scene.add(lod);

例子

webgl / lod

Constructor

LOD()

创建一个新的 LOD.

属性

共有属性请参见其基类Object3D

.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.

.levels : Array

一个包含有level objects(各层次物体)的数组。

每一个层级都是一个对象,具有以下两个属性: object —— 在这个层次中将要显示的Object3D
distance —— 将显示这一细节层次的距离。

方法

共有方法请参见其基类Object3D

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

object —— 在这个层次中将要显示的Object3D
distance —— 将显示这一细节层次的距离。

添加在一定距离和更大范围内显示的网格。通常来说,距离越远,网格中的细节就越少。

.clone() → LOD

返回一个LOD对象及其所关联的在特定距离中的物体。

.getCurrentLevel() → Integer

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

.getObjectForDistance(distance : Float) → Object3D

获得第一个比distance大的Object3D(网格)的引用。

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

在一条投射出去的Ray(射线)和这个LOD之间获得交互。 Raycaster.intersectObject将会调用这个方法。

.toJSON(meta) → Object

使用这个方法,为LOD对象中的每个细节层次创建一个JSON结构。

.update(camera : Camera) → null

基于每个level中的objectcamera(摄影机)之间的距离,来设置其可见性。

源代码

src/objects/LOD.js