Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes for batched mesh #728

Merged
merged 2 commits into from
Nov 11, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading