Skip to content

Commit

Permalink
BatchedMesh: Fix getIndexCount, getVertexCount functions (#27099)
Browse files Browse the repository at this point in the history
* BatchedMesh: Fix getVertexCount and getIndexCount functions

* BatchedMesh: Fix index offset
  • Loading branch information
gkjohnson committed Nov 1, 2023
1 parent 834d77d commit 5642032
Showing 1 changed file with 23 additions and 4 deletions.
27 changes: 23 additions & 4 deletions examples/jsm/objects/BatchedMesh.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,6 @@ class BatchedMesh extends Mesh {

this._geometryInitialized = false;
this._geometryCount = 0;
this._vertexCount = 0;
this._indexCount = 0;

// Local matrix per geometry by using data texture
// @TODO: Support uniform parameter per geometry
Expand Down Expand Up @@ -300,13 +298,34 @@ class BatchedMesh extends Mesh {

getVertexCount() {

return this._vertexCount;
const reservedRanges = this._reservedRanges;
if ( reservedRanges.length === 0 ) {

return 0;

} else {

const finalRange = reservedRanges[ reservedRanges.length - 1 ];
return finalRange.vertexStart + finalRange.vertexCount;

}

}

getIndexCount() {

return this._indexCount;
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;

}

}

Expand Down

0 comments on commit 5642032

Please sign in to comment.