Skip to content

CustomOrthopaedics/threejs-fast-raycast

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

87 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

threejs-fast-raycast

A THREEjs utility for providing more efficient raycasts against sufficiently complex meshes.

Demo Here!

screenshot

Casting 500 rays against an 80,000 polygon model at 60fps!

Use

import * as THREE from '.../three.js'
import '.../threejs-fast-raycasting.js'

// 80,000 polygon mesh
const geom = new THREE.TorusKnotBufferGeometry(10, 3, 400, 100);
const mesh = new THREE.Mesh(geom, material);
geom.computeBoundsTree();

// Fast raycasts!

Gotchas

  • This is intended to be used with complicated, high-poly meshes. With less complex meshes, the benefits are negligible.
  • Computing the bounds hierarchy is faster for THREE.BufferGeometry than it is for THREE.Geometry.
  • The bounds hierarchy is not dynamic, so geometry that uses morph targets cannot be used.
  • If the geometry is changed, then a call to computedBoundsTree() is required to update the bounds tree.

Approach

TODO

TODO

  • Add option to basically devolve to an oct tree to speed up generation of tree
  • Consider progressive generation of the tree, splitting nodes only when necessary
  • Add option to take only the first hit to speed things up
  • Use in conjunction with THREE Octtree for faster queries? Or do something similar

About

Repo for experimenting with new methods to raycast and collide THREEjs meshes

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 99.9%
  • HTML 0.1%