Skip to content

pickles976/SATES6.js

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SATES6.js

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

SAT.js is a Javascript implementation of the Separating Axis Theorem for convex polygons and polyhedra.

Requires three.js.

Based on this article.


Usage

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>

Polyhedra

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)

Collision Checking

import { CheckCollision } from 'SAT'
CheckCollision(collider1, collider2)

Demo

Examine the SAT algorithm step-by-step here.


Video

Video

About

Javascript implementation of the Separating Axis Theorem for convex polygons and polyhedra, converted into ES6.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 92.9%
  • HTML 7.1%