three-to-cannon
Advanced tools
Weekly downloads
Readme
Convert a THREE.Mesh or THREE.Object3D to a CANNON.Shape, with optimizations to simplified bounding shapes (AABB, sphere, etc.).
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.
FAQs
Convert a THREE.Mesh to a CANNON.Shape.
The npm package three-to-cannon receives a total of 450 weekly downloads. As such, three-to-cannon popularity was classified as not popular.
We found that three-to-cannon demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket installs a Github app to automatically flag issues on every pull request and report the health of your dependencies. Find out what is inside your node modules and prevent malicious activity before you update the dependencies.