[page:Object3D] →

多细节层次([name],Levels of Detail)

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

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

代码示例

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

例子

[example:webgl_lod webgl / lod ]

Constructor

[name]( )

创建一个新的 [name].

属性

共有属性请参见其基类[page:Object3D]。

[property:Boolean autoUpdate]

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

[property:Boolean isLOD]

Read-only flag to check if a given object is of type [name].

[property:Array levels]

一个包含有[page:Object level] objects(各层次物体)的数组。

每一个层级都是一个对象,具有以下两个属性: [page:Object3D object] —— 在这个层次中将要显示的[page:Object3D]。
[page:Float distance] —— 将显示这一细节层次的距离。
[page:Float hysteresis] —— Threshold used to avoid flickering at LOD boundaries, as a fraction of distance.

方法

共有方法请参见其基类[page:Object3D]。

[method:this addLevel]( [param:Object3D object], [param:Float distance], [param:Float hysteresis] )

[page:Object3D object] —— 在这个层次中将要显示的[page:Object3D]。
[page:Float distance] —— 将显示这一细节层次的距离。
[page:Float hysteresis] —— Threshold used to avoid flickering at LOD boundaries, as a fraction of distance. Default 0.0.

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

[method:LOD clone]()

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

[method:Integer getCurrentLevel]()

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

[method:Object3D getObjectForDistance]( [param:Float distance] )

获得第一个比[page:Float distance]大的[page:Object3D](网格)的引用。

[method:undefined raycast]( [param:Raycaster raycaster], [param:Array intersects] )

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

[method:Object toJSON]( meta )

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

[method:undefined update]( [param:Camera camera] )

基于每个[page:levels level]中的[page:Object3D object]和[page:Camera camera](摄像机)之间的距离,来设置其可见性。

源代码

[link:https://github.com/mrdoob/three.js/blob/master/src/[path].js src/[path].js]