Skip to content

Commit

Permalink
Merge pull request #728 from gkjohnson/batch-fix-2
Browse files Browse the repository at this point in the history
Fixes for batched mesh
  • Loading branch information
gkjohnson authored Nov 11, 2024
2 parents 4094caa + 0afe732 commit 5dcf74e
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions src/utils/ExtensionUtilities.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ const origBatchedRaycastFunc = BatchedMesh.prototype.raycast;
const _worldScale = /* @__PURE__ */ new Vector3();
const _mesh = /* @__PURE__ */ new Mesh();
const _batchIntersects = [];
const _drawRangeInfo = {};

export function acceleratedRaycast( raycaster, intersects ) {

Expand All @@ -31,9 +30,10 @@ function acceleratedBatchedMeshRaycast( raycaster, intersects ) {

if ( this.boundsTrees ) {

// TODO: remove use of geometry info, instance info when r170 is minimum version
const boundsTrees = this.boundsTrees;
const drawInfo = this._drawInfo;
const drawRanges = this._drawRanges;
const drawInfo = this._drawInfo || this._instanceInfo;
const drawRanges = this._drawRanges || this._geometryInfo;
const matrixWorld = this.matrixWorld;

_mesh.material = this.material;
Expand Down Expand Up @@ -69,8 +69,7 @@ function acceleratedBatchedMeshRaycast( raycaster, intersects ) {
this.getBoundingBoxAt( geometryId, _mesh.geometry.boundingBox );
this.getBoundingSphereAt( geometryId, _mesh.geometry.boundingSphere );

// TODO: remove use of drawRanges when r170 is minimum version
const drawRange = drawRanges ? drawRanges[ geometryId ] : this.getGeometryRangeAt( geometryId, _drawRangeInfo );
const drawRange = drawRanges[ geometryId ];
_mesh.geometry.setDrawRange( drawRange.start, drawRange.count );

}
Expand Down Expand Up @@ -186,7 +185,7 @@ export function computeBatchedBoundsTree( index = - 1, options = {} ) {
range: null
};

const drawRanges = this._drawRanges;
const drawRanges = this._drawRanges || this._geometryInfo;
const geometryCount = this._geometryCount;
if ( ! this.boundsTrees ) {

Expand All @@ -205,7 +204,7 @@ export function computeBatchedBoundsTree( index = - 1, options = {} ) {

for ( let i = 0; i < geometryCount; i ++ ) {

options.range = drawRanges ? drawRanges[ i ] : this.getGeometryRangeAt( i, _drawRangeInfo );
options.range = drawRanges[ i ];
boundsTrees[ i ] = new MeshBVH( this.geometry, options );

}
Expand All @@ -216,7 +215,7 @@ export function computeBatchedBoundsTree( index = - 1, options = {} ) {

if ( index < drawRanges.length ) {

options.range = drawRanges ? drawRanges[ index ] : this.getGeometryRangeAt( index, _drawRangeInfo );
options.range = drawRanges[ index ];
boundsTrees[ index ] = new MeshBVH( this.geometry, options );

}
Expand Down

0 comments on commit 5dcf74e

Please sign in to comment.