Browse Source

Merge pull request #16206 from takahirox/LODAutoUpdate

Introduce .autoUpdate to LOD
Mr.doob 6 năm trước cách đây
mục cha
commit
43eeb265b8

+ 8 - 9
docs/api/en/objects/LOD.html

@@ -43,13 +43,6 @@ for( var i = 0; i < 3; i++ ) {
 scene.add( lod );
 scene.add( lod );
 		</code>
 		</code>
 
 
-		<p>
-		Note that for the LOD to switch between the different detail levels, you will
-		have to call [page:.update update]( camera ) in your render loop. See the source code
-		for this example for details:
-		[example:webgl_lod WebGL / LOD]
-		</div>
-
 		<h2>Constructor</h2>
 		<h2>Constructor</h2>
 		<h3>[name]( )</h3>
 		<h3>[name]( )</h3>
 		<p>
 		<p>
@@ -60,6 +53,13 @@ scene.add( lod );
 		<h2>Properties</h2>
 		<h2>Properties</h2>
 		<p>See the base [page:Object3D] class for common properties.</p>
 		<p>See the base [page:Object3D] class for common properties.</p>
 
 
+		<h3>[property:boolean autoUpdate]</h3>
+		<p>
+		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.
+		</p>
+
 		<h3>[property:array levels]</h3>
 		<h3>[property:array levels]</h3>
 		<p>
 		<p>
 		An array of [page:object level] objects<br /><br />
 		An array of [page:object level] objects<br /><br />
@@ -108,8 +108,7 @@ scene.add( lod );
 		<h3>[method:null update]( [param:Camera camera] )</h3>
 		<h3>[method:null update]( [param:Camera camera] )</h3>
 		<p>
 		<p>
 			Set the visibility of each [page:levels level]'s [page:Object3D object] based on
 			Set the visibility of each [page:levels level]'s [page:Object3D object] based on
-			distance from the [page:Camera camera]. This needs to be called in the render loop
-			for levels of detail to be updated dynamically.
+			distance from the [page:Camera camera]. 
 		</p>
 		</p>
 
 
 		<h2>Source</h2>
 		<h2>Source</h2>

+ 7 - 7
docs/api/zh/objects/LOD.html

@@ -41,12 +41,6 @@ for( var i = 0; i < 3; i++ ) {
 scene.add( lod );
 scene.add( lod );
 		</code>
 		</code>
 
 
-		<p>
-			请注意,要使得LOD在各不同细节层次之间进行切换,你将需要在你的渲染循环中调用[page:.update update]( camera )。
-			详情请查看这个示例中的源代码:
-		[example:webgl_lod WebGL / LOD]
-		</div>
-
 		<h2>Constructor</h2>
 		<h2>Constructor</h2>
 		<h3>[name]( )</h3>
 		<h3>[name]( )</h3>
 		<p>
 		<p>
@@ -57,6 +51,13 @@ scene.add( lod );
 		<h2>属性</h2>
 		<h2>属性</h2>
 		<p>请参阅其基类[page:Object3D]来查看公共属性。</p>
 		<p>请参阅其基类[page:Object3D]来查看公共属性。</p>
 
 
+		<h3>[property:boolean autoUpdate]</h3>
+		<p>
+		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.
+		</p>
+
 		<h3>[property:array levels]</h3>
 		<h3>[property:array levels]</h3>
 		<p>
 		<p>
 			一个包含有[page:object level] objects(各层次物体)的数组。<br /><br />
 			一个包含有[page:object level] objects(各层次物体)的数组。<br /><br />
@@ -104,7 +105,6 @@ scene.add( lod );
 		<h3>[method:null update]( [param:Camera camera] )</h3>
 		<h3>[method:null update]( [param:Camera camera] )</h3>
 		<p>
 		<p>
 			基于每个[page:levels level]中的[page:Object3D object]和[page:Camera camera](摄像机)之间的距离,来设置其可见性。
 			基于每个[page:levels level]中的[page:Object3D object]和[page:Camera camera](摄像机)之间的距离,来设置其可见性。
-			为了使得多细节层次能够被自动地更新,这个方法需要在渲染循环中被调用。
 		</p>
 		</p>
 
 
 		<h2>源代码</h2>
 		<h2>源代码</h2>

+ 0 - 12
examples/webgl_lod.html

@@ -52,7 +52,6 @@
 
 
 				scene = new Scene();
 				scene = new Scene();
 				scene.fog = new Fog( 0x000000, 1, 15000 );
 				scene.fog = new Fog( 0x000000, 1, 15000 );
-				scene.autoUpdate = false;
 
 
 				var light = new PointLight( 0xff2200 );
 				var light = new PointLight( 0xff2200 );
 				light.position.set( 0, 0, 0 );
 				light.position.set( 0, 0, 0 );
@@ -131,17 +130,6 @@
 
 
 				controls.update( clock.getDelta() );
 				controls.update( clock.getDelta() );
 
 
-				scene.updateMatrixWorld();
-				scene.traverse( function ( object ) {
-
-					if ( object instanceof LOD ) {
-
-						object.update( camera );
-
-					}
-
-				} );
-
 				renderer.render( scene, camera );
 				renderer.render( scene, camera );
 
 
 			}
 			}

+ 2 - 0
src/objects/LOD.js

@@ -20,6 +20,8 @@ function LOD() {
 		}
 		}
 	} );
 	} );
 
 
+	this.autoUpdate = true;
+
 }
 }
 
 
 LOD.prototype = Object.assign( Object.create( Object3D.prototype ), {
 LOD.prototype = Object.assign( Object.create( Object3D.prototype ), {

+ 4 - 0
src/renderers/WebGLRenderer.js

@@ -1259,6 +1259,10 @@ function WebGLRenderer( parameters ) {
 
 
 				groupOrder = object.renderOrder;
 				groupOrder = object.renderOrder;
 
 
+			} else if ( object.isLOD ) {
+
+				if ( object.autoUpdate ) object.update( camera );
+
 			} else if ( object.isLight ) {
 			} else if ( object.isLight ) {
 
 
 				currentRenderState.pushLight( object );
 				currentRenderState.pushLight( object );