Socket
Socket
Sign inDemoInstall

three-to-cannon

Package Overview
Dependencies
8
Maintainers
1
Versions
25
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    three-to-cannon

Convert a THREE.Mesh to a CANNON.Shape.


Version published
Weekly downloads
521
increased by30.25%
Maintainers
1
Install size
2.16 MB
Created
Weekly downloads
 

Readme

Source

three-to-cannon

Latest NPM release Minzipped 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.

Keywords

FAQs

Last updated on 25 Oct 2022

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc