SATES6.js is an ES6 version of the SAT.js
SAT.js is useful when you want to test collision of two convex polyhedra, but don't want the overhead of a physics engine line Cannon.js or Ammo.js. It can take in geometries in the Three.js format.
SAT.js is a Javascript implementation of the Separating Axis Theorem for convex polygons and polyhedra.
Requires three.js.
Based on this article.
Add three.js and SAT.js to your page:
npm install sates6
Or add via CDN using an importMap
<script type="importmap">
{
"imports": {
"SAT": "https://unpkg.com/sates6@1.0.0/src/SAT.js"
}
}
</script>
Convert your Three.js geometries to a SAT.js shape object.
import * as THREE from 'three'
import { ShapeFromGeometry } from 'SAT'
const box1 = new THREE.BoxGeometry(1, 1, 1)
const box2 = new THREE.BoxGeometry(2, 2, 2)
const collider1 = ShapeFromGeometry(box1)
const collider2 = ShapeFromGeometry(box2)
import { CheckCollision } from 'SAT'
CheckCollision(collider1, collider2)
Examine the SAT algorithm step-by-step here.