three-to-cannon
TypeScript icon, indicating that this package has built-in type declarations

5.0.1 • Public • Published

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.

Package Sidebar

Install

npm i three-to-cannon

Weekly Downloads

411

Version

5.0.1

License

MIT

Unpacked Size

553 kB

Total Files

14

Last publish

Collaborators

  • donmccurdy