Skip to content

Commit b23757c

Browse files
gkjohnsonAdaRoseCannon
authored andcommitted
BatchedMesh: cleanup, add maxGeometryCount member (mrdoob#27231)
* Linting, add maxGeometryCount to BatchedMesh, remove undocumented functions * BatchedMesh: Update documentation
1 parent b863828 commit b23757c

File tree

3 files changed

+35
-43
lines changed

3 files changed

+35
-43
lines changed

docs/api/en/objects/BatchedMesh.html

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,29 @@ <h1>[name]</h1>
2121
<br/>
2222
<br/>
2323

24-
Requires platform support for the [link:https://developer.mozilla.org/en-US/docs/Web/API/WEBGL_multi_draw WEBGL_multi_draw extension].
24+
If the [link:https://developer.mozilla.org/en-US/docs/Web/API/WEBGL_multi_draw WEBGL_multi_draw extension] is
25+
not supported then a less performant callback is used.
2526
</p>
2627

28+
<h2>Code Example</h2>
29+
30+
<code>
31+
const box = new THREE.BoxGeometry( 1, 1, 1 );
32+
const sphere = new THREE.BoxGeometry( 1, 1, 1 );
33+
const material = new THREE.MeshBasicMaterial( { color: 0x00ff00 } );
34+
35+
// initialize and add geometries into the batched mesh
36+
const batchedMesh = new BatchedMesh( 10, 5000, 10000, material );
37+
const boxId = batchedMesh.addGeometry( box );
38+
const sphereId = batchedMesh.addGeometry( sphere );
39+
40+
// position the geometries
41+
batchedMesh.setMatrixAt( boxId, boxMatrix );
42+
batchedMesh.setMatrixAt( sphereId, sphereMatrix );
43+
44+
scene.add( batchedMesh );
45+
</code>
46+
2747
<h2>Examples</h2>
2848
<p>
2949
[example:webgl_mesh_batch WebGL / mesh / batch]<br />
@@ -71,6 +91,11 @@ <h3>[property:Boolean sortObjects]</h3>
7191
rendered front to back. Default is `true`.
7292
</p>
7393

94+
<h3>[property:Integer maxGeometryCount]</h3>
95+
<p>
96+
The maximum number of individual geometries that can be stored in the [name]. Read only.
97+
</p>
98+
7499
<h3>[property:Boolean isBatchedMesh]</h3>
75100
<p>Read-only flag to check if a given object is of type [name].</p>
76101

examples/webgl_mesh_batch.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -287,17 +287,17 @@
287287
// initialize options
288288
this._options = this._options || {
289289
get: el => el.z,
290-
aux: new Array( this._maxGeometryCount )
290+
aux: new Array( this.maxGeometryCount )
291291
};
292292

293293
const options = this._options;
294294
options.reversed = this.material.transparent;
295295

296296
// convert depth to unsigned 32 bit range
297-
const factor = ( 2**32 - 1 ) / camera.far; // UINT32_MAX / max_depth
297+
const factor = ( 2 ** 32 - 1 ) / camera.far; // UINT32_MAX / max_depth
298298
for ( let i = 0, l = list.length; i < l; i ++ ) {
299299

300-
list[i].z *= factor;
300+
list[ i ].z *= factor;
301301

302302
}
303303

src/objects/BatchedMesh.js

Lines changed: 6 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,12 @@ function copyAttributeData( src, target, targetOffset = 0 ) {
120120

121121
class BatchedMesh extends Mesh {
122122

123+
get maxGeometryCount() {
124+
125+
return this._maxGeometryCount;
126+
127+
}
128+
123129
constructor( maxGeometryCount, maxVertexCount, maxIndexCount = maxVertexCount * 2, material ) {
124130

125131
super( new BufferGeometry(), material );
@@ -262,45 +268,6 @@ class BatchedMesh extends Mesh {
262268

263269
}
264270

265-
getGeometryCount() {
266-
267-
return this._geometryCount;
268-
269-
}
270-
271-
getVertexCount() {
272-
273-
const reservedRanges = this._reservedRanges;
274-
if ( reservedRanges.length === 0 ) {
275-
276-
return 0;
277-
278-
} else {
279-
280-
const finalRange = reservedRanges[ reservedRanges.length - 1 ];
281-
return finalRange.vertexStart + finalRange.vertexCount;
282-
283-
}
284-
285-
}
286-
287-
getIndexCount() {
288-
289-
const reservedRanges = this._reservedRanges;
290-
const geometry = this.geometry;
291-
if ( geometry.getIndex() === null || reservedRanges.length === 0 ) {
292-
293-
return 0;
294-
295-
} else {
296-
297-
const finalRange = reservedRanges[ reservedRanges.length - 1 ];
298-
return finalRange.indexStart + finalRange.indexCount;
299-
300-
}
301-
302-
}
303-
304271
setCustomSort( func ) {
305272

306273
this.customSort = func;

0 commit comments

Comments
 (0)