gkjohnson / three-mesh-bvh

A BVH implementation to speed up raycasting and enable spatial queries against three.js meshes.
https://gkjohnson.github.io/three-mesh-bvh/example/bundle/raycast.html
MIT License
2.38k stars 247 forks source link

fix resolveTriangleIndex from wrong condition #665

Closed dongho-shin closed 1 month ago

dongho-shin commented 1 month ago

Hi I found a bug in constructor of MeshBVH.js

  //previous
  // In constructor this._indirectBuffer initialized null
  // then this.resolveTriangleIndex use the latter of conditional operator 
  // result of this.resolveTriangleIndex(i) returns i, even indirect is true
  this.resolveTriangleIndex = this._indirectBuffer ? i => this._indirectBuffer[ i ] : i => i;
  //fixed
  this.resolveTriangleIndex = options.indirect ? i => this._indirectBuffer[ i ] : i => i;

this bug affects three-mesh-pathtracer [scenario] initialize pathtracer => disable pathtracer => move model => enable pathtracer previous version

https://github.com/gkjohnson/three-mesh-bvh/assets/108255990/18428557-8969-4433-841b-22b737fd87e8

For your Information log

image image image

P.S : always thanks fast feedback & amazing library

gkjohnson commented 1 month ago

Excellent - thank you for the fix!