Socket
Socket
Sign inDemoInstall

three-to-cannon

Package Overview
Dependencies
Maintainers
1
Versions
26
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

three-to-cannon - npm Package Compare versions

Comparing version 1.3.0 to 1.4.1

.travis.yml

13

index.js

@@ -101,7 +101,11 @@ var CANNON = require('cannon'),

function createBoundingBoxShape (object) {
var shape, localPosition, worldPosition,
var shape, localPosition,
box = new THREE.Box3();
box.setFromObject(object);
var clone = object.clone();
clone.quaternion.set(0, 0, 0, 1);
clone.updateMatrixWorld();
box.setFromObject(clone);
if (!isFinite(box.min.lengthSq())) return null;

@@ -115,6 +119,3 @@

object.updateMatrixWorld();
worldPosition = new THREE.Vector3();
worldPosition.setFromMatrixPosition(object.matrixWorld);
localPosition = box.translate(worldPosition.negate()).getCenter();
localPosition = box.translate(clone.position.negate()).getCenter(new THREE.Vector3());
if (localPosition.lengthSq()) {

@@ -121,0 +122,0 @@ shape.offset = localPosition;

{
"name": "three-to-cannon",
"version": "1.3.0",
"version": "1.4.1",
"description": "Convert a THREE.Mesh to a CANNON.Shape.",

@@ -34,4 +34,5 @@ "main": "index.js",

"cannon": "github:donmccurdy/cannon.js#v0.6.2-dev1",
"tape": "^4.9.0",
"three": "^0.89.0"
}
}
# three-to-cannon
[![Build Status](https://travis-ci.org/donmccurdy/three-to-cannon.svg?branch=master)](https://travis-ci.org/donmccurdy/three-to-cannon)
Convert a THREE.Mesh to a CANNON.Shape, and optional optimizations with simplified shapes.

@@ -4,0 +6,0 @@

@@ -1,10 +0,6 @@

const assert = require('assert');
const test = require('tape');
const THREE = global.THREE = require('three');
const mesh2shape = require('../');
function equalsApprox ( a, b ) {
return Math.abs( a - b ) < 0.0001;
}
var ShapeType = {
const ShapeType = {
BOX: 4,

@@ -17,31 +13,81 @@ SPHERE: 1,

var object = new THREE.Mesh(new THREE.BoxGeometry(10, 10, 10));
const object = new THREE.Mesh(new THREE.BoxGeometry(10, 10, 10));
function equalsApprox ( a, b ) {
return Math.abs( a - b ) < 0.0001;
}
var box = mesh2shape(object, {type: mesh2shape.Type.BOX});
assert( box.type === ShapeType.BOX, 'box.type' );
assert( box.halfExtents.x === 5, 'box.halfExtents.x' );
assert( box.halfExtents.y === 5, 'box.halfExtents.y' );
assert( box.halfExtents.z === 5, 'box.halfExtents.z' );
test('shape - box', function (t) {
var box = mesh2shape(object, {type: mesh2shape.Type.BOX});
var sphere = mesh2shape(object, {type: mesh2shape.Type.SPHERE});
assert( sphere.type === ShapeType.SPHERE, 'sphere.type' );
assert( equalsApprox( sphere.radius, 8.660254 ), 'sphere.radius' );
t.equal( box.type, ShapeType.BOX, 'box.type' );
t.equal( box.halfExtents.x, 5, 'box.halfExtents.x' );
t.equal( box.halfExtents.y, 5, 'box.halfExtents.y' );
t.equal( box.halfExtents.z, 5, 'box.halfExtents.z' );
var cylinder = mesh2shape(object, {type: mesh2shape.Type.CYLINDER});
assert( cylinder.type === ShapeType.CYLINDER, 'cylinder.type' );
assert( cylinder.radiusTop === 5, 'cylinder.radiusTop' );
assert( cylinder.radiusBottom === 5, 'cylinder.radiusBottom' );
assert( cylinder.height === 10, 'cylinder.height' );
assert( equalsApprox( cylinder.orientation.x, 0.707106 ), 'cylinder.orientation.x' );
assert( equalsApprox( cylinder.orientation.y, 0 ), 'cylinder.orientation.y' );
assert( equalsApprox( cylinder.orientation.z, 0 ), 'cylinder.orientation.z' );
assert( equalsApprox( cylinder.orientation.w, 0.707106 ), 'cylinder.orientation.w' );
t.end();
});
var hull = mesh2shape(object, {type: mesh2shape.Type.HULL});
assert( hull.type === ShapeType.HULL, 'hull.type' );
test('shape - sphere', function (t) {
const sphere = mesh2shape(object, {type: mesh2shape.Type.SPHERE});
var mesh = mesh2shape(object, {type: mesh2shape.Type.MESH});
assert( mesh.type === ShapeType.MESH, 'mesh.type' );
t.equal( sphere.type, ShapeType.SPHERE, 'sphere.type' );
t.ok( equalsApprox( sphere.radius, 8.660254 ), 'sphere.radius' );
console.log('Passed.');
t.end();
});
test('shape - cylinder', function (t) {
const cylinder = mesh2shape(object, {type: mesh2shape.Type.CYLINDER});
t.equal( cylinder.type, ShapeType.CYLINDER, 'cylinder.type' );
t.equal( cylinder.radiusTop, 5, 'cylinder.radiusTop' );
t.equal( cylinder.radiusBottom, 5, 'cylinder.radiusBottom' );
t.equal( cylinder.height, 10, 'cylinder.height' );
t.ok( equalsApprox( cylinder.orientation.x, 0.707106 ), 'cylinder.orientation.x' );
t.ok( equalsApprox( cylinder.orientation.y, 0 ), 'cylinder.orientation.y' );
t.ok( equalsApprox( cylinder.orientation.z, 0 ), 'cylinder.orientation.z' );
t.ok( equalsApprox( cylinder.orientation.w, 0.707106 ), 'cylinder.orientation.w' );
t.end();
});
test('shape - hull', function (t) {
const hull = mesh2shape(object, {type: mesh2shape.Type.HULL});
t.equal( hull.type, ShapeType.HULL, 'hull.type' );
t.end();
});
test('shape - mesh', function (t) {
const mesh = mesh2shape(object, {type: mesh2shape.Type.MESH});
t.equal( mesh.type, ShapeType.MESH, 'mesh.type' );
t.end();
});
test('transform - position', function (t) {
const group = new THREE.Group();
const object = new THREE.Mesh(new THREE.BoxGeometry(10, 10, 10));
const matrix = new THREE.Matrix4().makeTranslation(0, 50, 0);
object.geometry.applyMatrix(matrix);
group.position.set(100, 0, 0);
group.add(object);
group.updateMatrixWorld();
const box = mesh2shape(object);
t.equal( box.type, ShapeType.BOX, 'box.type' );
t.equal( box.halfExtents.x, 5, 'box.halfExtents.x' );
t.equal( box.halfExtents.y, 5, 'box.halfExtents.y' );
t.equal( box.halfExtents.z, 5, 'box.halfExtents.z' );
t.equal( box.offset.x, 0, 'box.offset.x' );
t.equal( box.offset.y, 50, 'box.offset.y' );
t.equal( box.offset.z, 0, 'box.offset.z' );
t.notOk( box.orientation, 'box.orientation' );
t.end();
});
SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc