5.0.1 • Published 4 months ago

three-to-cannon v5.0.1

Weekly downloads
261
License
MIT
Repository
github
Last release
4 months ago

three-to-cannon

Latest NPM release npm bundle size License Build Status Coverage

Convert a THREE.Mesh or THREE.Object3D to a CANNON.Shape, with optimizations to simplified bounding shapes (AABB, sphere, etc.).

API

Installation:

npm install --save three-to-cannon

Use:

/****************************************
 * Import:
 */

// ES6
import { threeToCannon, ShapeType } from 'three-to-cannon';

// CommonJS
const { threeToCannon, ShapeType } = require('three-to-cannon');

/****************************************
 * Generate a CANNON.Shape:
 */

// Automatic (Usually an AABB, except obvious cases like THREE.SphereGeometry).
const result = threeToCannon(object3D);

// Bounding box (AABB).
const result = threeToCannon(object3D, {type: ShapeType.BOX});

// Bounding sphere.
const result = threeToCannon(object3D, {type: ShapeType.SPHERE});

// Cylinder.
const result = threeToCannon(object3D, {type: ShapeType.CYLINDER});

// Convex hull. 
const result = threeToCannon(object3D, {type: ShapeType.HULL});

// Mesh (Not recommended — limitations: https://github.com/pmndrs/cannon-es/issues/21).
const result = threeToCannon(object3D, {type: ShapeType.MESH});

/****************************************
 * Using the result:
 */

// Result object includes a CANNON.Shape instance, and (optional)
// an offset or quaternion for that shape.
const {shape, offset, quaternion} = result;

// Add the shape to a CANNON.Body.
body.addShape(shape, offset, orientation);

See further documentation on the CANNON.Shape class.

5.0.1

4 months ago

4.3.0

2 years ago

4.1.0

2 years ago

4.2.0

2 years ago

4.0.1

3 years ago

4.0.0

3 years ago

4.0.2

3 years ago

3.1.0

3 years ago

3.0.2

4 years ago

3.0.1

4 years ago

3.0.0

4 years ago

2.1.0

4 years ago

2.0.0

6 years ago

1.4.1

6 years ago

1.3.0

6 years ago

1.2.0

6 years ago

1.1.2

6 years ago

1.1.1

7 years ago

1.1.0

7 years ago

1.0.5

7 years ago

1.0.4

7 years ago

1.0.3

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

8 years ago