浏览代码

Examples: Add update() to MarchingCubes (#23934)

* Add support for disabling auto marching cubes update

* use draw range instead of for loop to limit marching cubes drawing

* remove autoupdate
Garrett Johnson 3 年之前
父节点
当前提交
0e15488d1f
共有 2 个文件被更改,包括 5 次插入7 次删除
  1. 3 7
      examples/jsm/objects/MarchingCubes.js
  2. 2 0
      examples/webgl_marchingcubes.html

+ 3 - 7
examples/jsm/objects/MarchingCubes.js

@@ -812,7 +812,7 @@ class MarchingCubes extends Mesh {
 
 
 		};
 		};
 
 
-		this.onBeforeRender = function () {
+		this.update = function () {
 
 
 			this.count = 0;
 			this.count = 0;
 
 
@@ -843,13 +843,9 @@ class MarchingCubes extends Mesh {
 
 
 			}
 			}
 
 
-			// reset unneeded data
+			// set the draw range to only the processed triangles
 
 
-			for ( let i = this.count * 3; i < this.positionArray.length; i ++ ) {
-
-				this.positionArray[ i ] = 0.0;
-
-			}
+			this.geometry.setDrawRange( 0, this.count );
 
 
 			// update geometry data
 			// update geometry data
 
 

+ 2 - 0
examples/webgl_marchingcubes.html

@@ -316,6 +316,8 @@
 			if ( wallz ) object.addPlaneZ( 2, 12 );
 			if ( wallz ) object.addPlaneZ( 2, 12 );
 			if ( wallx ) object.addPlaneX( 2, 12 );
 			if ( wallx ) object.addPlaneX( 2, 12 );
 
 
+			object.update();
+
 		}
 		}
 
 
 		//
 		//