Browse Source

BatchedMesh: cleanup, add maxGeometryCount member (#27231)

* Linting, add maxGeometryCount to BatchedMesh, remove undocumented functions

* BatchedMesh: Update documentation
Garrett Johnson 1 year ago
parent
commit
13105483ab
3 changed files with 35 additions and 43 deletions
  1. 26 1
      docs/api/en/objects/BatchedMesh.html
  2. 3 3
      examples/webgl_mesh_batch.html
  3. 6 39
      src/objects/BatchedMesh.js

+ 26 - 1
docs/api/en/objects/BatchedMesh.html

@@ -21,9 +21,29 @@
 			<br/>
 			<br/>
 
-			Requires platform support for the [link:https://developer.mozilla.org/en-US/docs/Web/API/WEBGL_multi_draw WEBGL_multi_draw extension].
+			If the [link:https://developer.mozilla.org/en-US/docs/Web/API/WEBGL_multi_draw WEBGL_multi_draw extension] is
+			not supported then a less performant callback is used.
 		</p>
 
+		<h2>Code Example</h2>
+
+		<code>
+		const box = new THREE.BoxGeometry( 1, 1, 1 );
+		const sphere = new THREE.BoxGeometry( 1, 1, 1 );
+		const material = new THREE.MeshBasicMaterial( { color: 0x00ff00 } );
+
+		// initialize and add geometries into the batched mesh
+		const batchedMesh = new BatchedMesh( 10, 5000, 10000, material );
+		const boxId = batchedMesh.addGeometry( box );
+		const sphereId = batchedMesh.addGeometry( sphere );
+
+		// position the geometries
+		batchedMesh.setMatrixAt( boxId, boxMatrix );
+		batchedMesh.setMatrixAt( sphereId, sphereMatrix );
+
+		scene.add( batchedMesh );
+		</code>
+
 		<h2>Examples</h2>
 		<p>
 			[example:webgl_mesh_batch WebGL / mesh / batch]<br />
@@ -71,6 +91,11 @@
 			rendered front to back. Default is `true`.
 		</p>
 
+		<h3>[property:Integer maxGeometryCount]</h3>
+		<p>
+			The maximum number of individual geometries that can be stored in the [name]. Read only.
+		</p>
+
 		<h3>[property:Boolean isBatchedMesh]</h3>
 		<p>Read-only flag to check if a given object is of type [name].</p>
 

+ 3 - 3
examples/webgl_mesh_batch.html

@@ -287,17 +287,17 @@
 			// initialize options
 			this._options = this._options || {
 				get: el => el.z,
-				aux: new Array( this._maxGeometryCount )
+				aux: new Array( this.maxGeometryCount )
 			};
 
 			const options = this._options;
 			options.reversed = this.material.transparent;
 
 			// convert depth to unsigned 32 bit range
-			const factor = ( 2**32 - 1 ) / camera.far; // UINT32_MAX / max_depth
+			const factor = ( 2 ** 32 - 1 ) / camera.far; // UINT32_MAX / max_depth
 			for ( let i = 0, l = list.length; i < l; i ++ ) {
 
-				list[i].z *= factor;
+				list[ i ].z *= factor;
 
 			}
 

+ 6 - 39
src/objects/BatchedMesh.js

@@ -120,6 +120,12 @@ function copyAttributeData( src, target, targetOffset = 0 ) {
 
 class BatchedMesh extends Mesh {
 
+	get maxGeometryCount() {
+
+		return this._maxGeometryCount;
+
+	}
+
 	constructor( maxGeometryCount, maxVertexCount, maxIndexCount = maxVertexCount * 2, material ) {
 
 		super( new BufferGeometry(), material );
@@ -262,45 +268,6 @@ class BatchedMesh extends Mesh {
 
 	}
 
-	getGeometryCount() {
-
-		return this._geometryCount;
-
-	}
-
-	getVertexCount() {
-
-		const reservedRanges = this._reservedRanges;
-		if ( reservedRanges.length === 0 ) {
-
-			return 0;
-
-		} else {
-
-			const finalRange = reservedRanges[ reservedRanges.length - 1 ];
-			return finalRange.vertexStart + finalRange.vertexCount;
-
-		}
-
-	}
-
-	getIndexCount() {
-
-		const reservedRanges = this._reservedRanges;
-		const geometry = this.geometry;
-		if ( geometry.getIndex() === null || reservedRanges.length === 0 ) {
-
-			return 0;
-
-		} else {
-
-			const finalRange = reservedRanges[ reservedRanges.length - 1 ];
-			return finalRange.indexStart + finalRange.indexCount;
-
-		}
-
-	}
-
 	setCustomSort( func ) {
 
 		this.customSort = func;