andstor / voxelizer

:space_invader: Voxelization of 3D models
https://npmjs.org/package/voxelizer
MIT License
50 stars 10 forks source link

using three-mesh-bvh for raycasting #21

Closed arpu closed 3 years ago

arpu commented 3 years ago

Hey,

would it make sense to use https://github.com/gkjohnson/three-mesh-bvh ? for speed up raycasting

andstor commented 3 years ago

Hi 👋

I am actually using it in the RaycastAlgorithm! https://github.com/andstor/voxelizer/blob/51f5c7c6812efff5adc5cfe67ff5d577d398b727/src/algorithms/RaycastAlgorithm.js#L7

I have done some quite extensive research of various raycasting optimization solutions for threejs, and the three-mesh-bvh seems to be by far the best alternative.

However, three-mesh-bvh requires modifications on the prototype of the threejs Mesh class. Depending on how the user loads up the voxelizer engine in relation to threejs, Mesh objects might be instantiated before the methods on the Mesh prototype are modified. One option is to modify the prototype after the object is instantiated. This could be done with the Object.setPrototypeOf(). However, this is considered bad practice and results in bad performance (although I have not actually tested this).

I have been wanting implement a more safe and reliable way of ensuring the raycasting optimizations does take effect. At the very least, it should be document how to ensure the optimizations does take effect.

Is this something you would be interested in taking a look at @arpu ?

arpu commented 3 years ago

Hey wau i missed that you use three-mesh-bvh now! awesome stuff

i only found this, on testing different voxelizer and your, is just the best! only problem i see is on resolution >= 400 my browser tab crashes

nothing i can help on this :/

arpu commented 3 years ago

i think this can be simple be closed!