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 3.0.0 to 3.0.1

2

dist/three-to-cannon.js

@@ -1,2 +0,2 @@

var e=require("cannon-es"),r=require("three/examples/jsm/math/ConvexHull.js"),t=require("three"),n=Math.PI/2,o={BOX:"Box",CYLINDER:"Cylinder",SPHERE:"Sphere",HULL:"ConvexPolyhedron",MESH:"Trimesh"},a=function(a,y){var l;if((y=y||{}).type===o.BOX)return m(a);if(y.type===o.CYLINDER)return function(r,o){var a,i,m,u=new t.Box3,s=["x","y","z"],y=o.cylinderAxis||"y",l=s.splice(s.indexOf(y),1)&&s;return u.setFromObject(r),isFinite(u.min.lengthSq())?(i=u.max[y]-u.min[y],m=.5*Math.max(u.max[l[0]]-u.min[l[0]],u.max[l[1]]-u.min[l[1]]),(a=new e.Cylinder(m,m,i,12))._type=e.Shape.types.CYLINDER,a.radiusTop=m,a.radiusBottom=m,a.height=i,a.numSegments=12,a.orientation=new e.Quaternion,a.orientation.setFromEuler("y"===y?n:0,"z"===y?n:0,0,"XYZ").normalize(),a):null}(a,y);if(y.type===o.SPHERE)return function(r,t){if(t.sphereRadius)return new e.Sphere(t.sphereRadius);var n=u(r);return n?(n.computeBoundingSphere(),new e.Sphere(n.boundingSphere.radius)):null}(a,y);if(y.type===o.HULL)return function(n){var o,a,i,m,s=u(n);if(!s||!s.vertices.length)return null;for(o=0;o<s.vertices.length;o++)s.vertices[o].x+=1e-4*(Math.random()-.5),s.vertices[o].y+=1e-4*(Math.random()-.5),s.vertices[o].z+=1e-4*(Math.random()-.5);for(m=(new r.ConvexHull).setFromObject(new t.Mesh(s)),a=new Array(m.vertices.length),o=0;o<m.vertices.length;o++)a[o]=new e.Vec3(m.vertices[o].x,m.vertices[o].y,m.vertices[o].z);for(i=new Array(m.faces.length),o=0;o<m.faces.length;o++)i[o]=[m.faces[o].a,m.faces[o].b,m.faces[o].c];return new e.ConvexPolyhedron(a,i)}(a);if(y.type===o.MESH)return(l=u(a))?function(r){var t,n=s(r);return n.length?(t=Object.keys(n).map(Number),new e.Trimesh(n,t)):null}(l):null;if(y.type)throw new Error('[CANNON.threeToCannon] Invalid type "%s".',y.type);if(!(l=u(a)))return null;switch(l.metadata?l.metadata.type:l.type){case"BoxGeometry":case"BoxBufferGeometry":return i(l);case"CylinderGeometry":case"CylinderBufferGeometry":return function(r){var n,o=r.metadata?r.metadata.parameters:r.parameters;return(n=new e.Cylinder(o.radiusTop,o.radiusBottom,o.height,o.radialSegments))._type=e.Shape.types.CYLINDER,n.radiusTop=o.radiusTop,n.radiusBottom=o.radiusBottom,n.height=o.height,n.numSegments=o.radialSegments,n.orientation=new e.Quaternion,n.orientation.setFromEuler(t.Math.degToRad(90),0,0,"XYZ").normalize(),n}(l);case"PlaneGeometry":case"PlaneBufferGeometry":return function(r){r.computeBoundingBox();var t=r.boundingBox;return new e.Box(new e.Vec3((t.max.x-t.min.x)/2||.1,(t.max.y-t.min.y)/2||.1,(t.max.z-t.min.z)/2||.1))}(l);case"SphereGeometry":case"SphereBufferGeometry":return function(r){return new e.Sphere((r.metadata?r.metadata.parameters:r.parameters).radius)}(l);case"TubeGeometry":case"Geometry":case"BufferGeometry":return m(a);default:return console.warn('Unrecognized geometry: "%s". Using bounding box as shape.',l.type),i(l)}};function i(r){if(!s(r).length)return null;r.computeBoundingBox();var t=r.boundingBox;return new e.Box(new e.Vec3((t.max.x-t.min.x)/2,(t.max.y-t.min.y)/2,(t.max.z-t.min.z)/2))}function m(r){var n,o,a=new t.Box3,i=r.clone();return i.quaternion.set(0,0,0,1),i.updateMatrixWorld(),a.setFromObject(i),isFinite(a.min.lengthSq())?(n=new e.Box(new e.Vec3((a.max.x-a.min.x)/2,(a.max.y-a.min.y)/2,(a.max.z-a.min.z)/2)),(o=a.translate(i.position.negate()).getCenter(new t.Vector3)).lengthSq()&&(n.offset=o),n):null}function u(e){var r,n,o=function(e){var r=[];return e.traverse(function(e){"Mesh"===e.type&&r.push(e)}),r}(e),a=new t.Geometry,i=new t.Geometry;if(0===o.length)return null;if(1===o.length){var m=new t.Vector3,u=new t.Quaternion,s=new t.Vector3;return o[0].geometry.isBufferGeometry?o[0].geometry.attributes.position&&o[0].geometry.attributes.position.itemSize>2&&a.fromBufferGeometry(o[0].geometry):a=o[0].geometry.clone(),a.metadata=o[0].geometry.metadata,o[0].updateMatrixWorld(),o[0].matrixWorld.decompose(m,u,s),a.scale(s.x,s.y,s.z)}for(;n=o.pop();)if(n.updateMatrixWorld(),n.geometry.isBufferGeometry){if(n.geometry.attributes.position&&n.geometry.attributes.position.itemSize>2){var y=new t.Geometry;y.fromBufferGeometry(n.geometry),i.merge(y,n.matrixWorld),y.dispose()}}else i.merge(n.geometry,n.matrixWorld);return(r=new t.Matrix4).scale(e.scale),i.applyMatrix(r),i}function s(e){return e.attributes||(e=(new t.BufferGeometry).fromGeometry(e)),(e.attributes.position||{}).array||[]}a.Type=o,exports.threeToCannon=a;
var e=require("cannon-es"),r=require("three/examples/jsm/math/ConvexHull.js"),t=require("three"),n=Math.PI/2,a={BOX:"Box",CYLINDER:"Cylinder",SPHERE:"Sphere",HULL:"ConvexPolyhedron",MESH:"Trimesh"},o=function(o,y){var l;if((y=y||{}).type===a.BOX)return m(o);if(y.type===a.CYLINDER)return function(r,a){var o=["x","y","z"],i=a.cylinderAxis||"y",m=o.splice(o.indexOf(i),1)&&o,u=(new t.Box3).setFromObject(r);if(!isFinite(u.min.lengthSq()))return null;var s=u.max[i]-u.min[i],y=.5*Math.max(u.max[m[0]]-u.min[m[0]],u.max[m[1]]-u.min[m[1]]),l=new e.Cylinder(y,y,s,12);return l._type=e.Shape.types.CYLINDER,l.radiusTop=y,l.radiusBottom=y,l.height=s,l.numSegments=12,l.orientation=new e.Quaternion,l.orientation.setFromEuler("y"===i?n:0,"z"===i?n:0,0,"XYZ").normalize(),l}(o,y);if(y.type===a.SPHERE)return function(r,t){if(t.sphereRadius)return new e.Sphere(t.sphereRadius);var n=u(r);return n?(n.computeBoundingSphere(),new e.Sphere(n.boundingSphere.radius)):null}(o,y);if(y.type===a.HULL)return function(n){var a=u(n);if(!a||!a.vertices.length)return null;for(var o=0;o<a.vertices.length;o++)a.vertices[o].x+=1e-4*(Math.random()-.5),a.vertices[o].y+=1e-4*(Math.random()-.5),a.vertices[o].z+=1e-4*(Math.random()-.5);var i=(new r.ConvexHull).setFromObject(new t.Mesh(a)).faces,m=[],s=[];for(o=0;o<i.length;o++){var y=i[o],l=y.edge;do{var p=l.head().point;m.push(new e.Vec3(p.x,p.y,p.z)),s.push(new e.Vec3(y.normal.x,y.normal.y,y.normal.z)),l=l.next}while(l!==y.edge)}return new e.ConvexPolyhedron({vertices:m,normals:s})}(o);if(y.type===a.MESH)return(l=u(o))?function(r){var t=s(r);if(!t.length)return null;var n=Object.keys(t).map(Number);return new e.Trimesh(t,n)}(l):null;if(y.type)throw new Error('[CANNON.threeToCannon] Invalid type "%s".',y.type);if(!(l=u(o)))return null;switch(l.metadata?l.metadata.type:l.type){case"BoxGeometry":case"BoxBufferGeometry":return i(l);case"CylinderGeometry":case"CylinderBufferGeometry":return function(r){var n=r.metadata?r.metadata.parameters:r.parameters,a=new e.Cylinder(n.radiusTop,n.radiusBottom,n.height,n.radialSegments);return a._type=e.Shape.types.CYLINDER,a.radiusTop=n.radiusTop,a.radiusBottom=n.radiusBottom,a.height=n.height,a.numSegments=n.radialSegments,a.orientation=new e.Quaternion,a.orientation.setFromEuler(t.Math.degToRad(90),0,0,"XYZ").normalize(),a}(l);case"PlaneGeometry":case"PlaneBufferGeometry":return function(r){r.computeBoundingBox();var t=r.boundingBox;return new e.Box(new e.Vec3((t.max.x-t.min.x)/2||.1,(t.max.y-t.min.y)/2||.1,(t.max.z-t.min.z)/2||.1))}(l);case"SphereGeometry":case"SphereBufferGeometry":return function(r){return new e.Sphere((r.metadata?r.metadata.parameters:r.parameters).radius)}(l);case"TubeGeometry":case"Geometry":case"BufferGeometry":return m(o);default:return console.warn('Unrecognized geometry: "%s". Using bounding box as shape.',l.type),i(l)}};function i(r){if(!s(r).length)return null;r.computeBoundingBox();var t=r.boundingBox;return new e.Box(new e.Vec3((t.max.x-t.min.x)/2,(t.max.y-t.min.y)/2,(t.max.z-t.min.z)/2))}function m(r){var n=r.clone();n.quaternion.set(0,0,0,1),n.updateMatrixWorld();var a=(new t.Box3).setFromObject(n);if(!isFinite(a.min.lengthSq()))return null;var o=new e.Box(new e.Vec3((a.max.x-a.min.x)/2,(a.max.y-a.min.y)/2,(a.max.z-a.min.z)/2)),i=a.translate(n.position.negate()).getCenter(new t.Vector3);return i.lengthSq()&&(o.offset=i),o}function u(e){var r,n=function(e){var r=[];return e.traverse(function(e){"Mesh"===e.type&&r.push(e)}),r}(e),a=new t.Geometry,o=new t.Geometry;if(0===n.length)return null;if(1===n.length){var i=new t.Vector3,m=new t.Quaternion,u=new t.Vector3;return n[0].geometry.isBufferGeometry?n[0].geometry.attributes.position&&n[0].geometry.attributes.position.itemSize>2&&a.fromBufferGeometry(n[0].geometry):a=n[0].geometry.clone(),a.metadata=n[0].geometry.metadata,n[0].updateMatrixWorld(),n[0].matrixWorld.decompose(i,m,u),a.scale(u.x,u.y,u.z)}for(;r=n.pop();)if(r.updateMatrixWorld(),r.geometry.isBufferGeometry){if(r.geometry.attributes.position&&r.geometry.attributes.position.itemSize>2){var s=new t.Geometry;s.fromBufferGeometry(r.geometry),o.merge(s,r.matrixWorld),s.dispose()}}else o.merge(r.geometry,r.matrixWorld);var y=new t.Matrix4;return y.scale(e.scale),o.applyMatrix(y),o}function s(e){return e.attributes||(e=(new t.BufferGeometry).fromGeometry(e)),(e.attributes.position||{}).array||[]}o.Type=a,exports.threeToCannon=o;
//# sourceMappingURL=three-to-cannon.js.map

@@ -1,2 +0,2 @@

import{Sphere as e,Box as t,Vec3 as r,ConvexPolyhedron as n,Cylinder as a,Shape as o,Quaternion as i,Trimesh as m}from"cannon-es";import{ConvexHull as u}from"three/examples/jsm/math/ConvexHull.js";import{Box3 as s,Vector3 as y,Mesh as f,Math as l,Geometry as c,Quaternion as p,Matrix4 as d,BufferGeometry as g}from"three";var h=Math.PI/2,x={BOX:"Box",CYLINDER:"Cylinder",SPHERE:"Sphere",HULL:"ConvexPolyhedron",MESH:"Trimesh"};const w=function(y,c){var p;if((c=c||{}).type===x.BOX)return B(y);if(c.type===x.CYLINDER)return function(e,t){var r,n,m,u=new s,y=["x","y","z"],f=t.cylinderAxis||"y",l=y.splice(y.indexOf(f),1)&&y;return u.setFromObject(e),isFinite(u.min.lengthSq())?(n=u.max[f]-u.min[f],m=.5*Math.max(u.max[l[0]]-u.min[l[0]],u.max[l[1]]-u.min[l[1]]),(r=new a(m,m,n,12))._type=o.types.CYLINDER,r.radiusTop=m,r.radiusBottom=m,r.height=n,r.numSegments=12,r.orientation=new i,r.orientation.setFromEuler("y"===f?h:0,"z"===f?h:0,0,"XYZ").normalize(),r):null}(y,c);if(c.type===x.SPHERE)return function(t,r){if(r.sphereRadius)return new e(r.sphereRadius);var n=b(t);return n?(n.computeBoundingSphere(),new e(n.boundingSphere.radius)):null}(y,c);if(c.type===x.HULL)return function(e){var t,a,o,i,m=b(e);if(!m||!m.vertices.length)return null;for(t=0;t<m.vertices.length;t++)m.vertices[t].x+=1e-4*(Math.random()-.5),m.vertices[t].y+=1e-4*(Math.random()-.5),m.vertices[t].z+=1e-4*(Math.random()-.5);for(i=(new u).setFromObject(new f(m)),a=new Array(i.vertices.length),t=0;t<i.vertices.length;t++)a[t]=new r(i.vertices[t].x,i.vertices[t].y,i.vertices[t].z);for(o=new Array(i.faces.length),t=0;t<i.faces.length;t++)o[t]=[i.faces[t].a,i.faces[t].b,i.faces[t].c];return new n(a,o)}(y);if(c.type===x.MESH)return(p=b(y))?function(e){var t,r=S(e);return r.length?(t=Object.keys(r).map(Number),new m(r,t)):null}(p):null;if(c.type)throw new Error('[CANNON.threeToCannon] Invalid type "%s".',c.type);if(!(p=b(y)))return null;switch(p.metadata?p.metadata.type:p.type){case"BoxGeometry":case"BoxBufferGeometry":return v(p);case"CylinderGeometry":case"CylinderBufferGeometry":return function(e){var t,r=e.metadata?e.metadata.parameters:e.parameters;return(t=new a(r.radiusTop,r.radiusBottom,r.height,r.radialSegments))._type=o.types.CYLINDER,t.radiusTop=r.radiusTop,t.radiusBottom=r.radiusBottom,t.height=r.height,t.numSegments=r.radialSegments,t.orientation=new i,t.orientation.setFromEuler(l.degToRad(90),0,0,"XYZ").normalize(),t}(p);case"PlaneGeometry":case"PlaneBufferGeometry":return function(e){e.computeBoundingBox();var n=e.boundingBox;return new t(new r((n.max.x-n.min.x)/2||.1,(n.max.y-n.min.y)/2||.1,(n.max.z-n.min.z)/2||.1))}(p);case"SphereGeometry":case"SphereBufferGeometry":return function(t){return new e((t.metadata?t.metadata.parameters:t.parameters).radius)}(p);case"TubeGeometry":case"Geometry":case"BufferGeometry":return B(y);default:return console.warn('Unrecognized geometry: "%s". Using bounding box as shape.',p.type),v(p)}};function v(e){if(!S(e).length)return null;e.computeBoundingBox();var n=e.boundingBox;return new t(new r((n.max.x-n.min.x)/2,(n.max.y-n.min.y)/2,(n.max.z-n.min.z)/2))}function B(e){var n,a,o=new s,i=e.clone();return i.quaternion.set(0,0,0,1),i.updateMatrixWorld(),o.setFromObject(i),isFinite(o.min.lengthSq())?(n=new t(new r((o.max.x-o.min.x)/2,(o.max.y-o.min.y)/2,(o.max.z-o.min.z)/2)),(a=o.translate(i.position.negate()).getCenter(new y)).lengthSq()&&(n.offset=a),n):null}function b(e){var t,r,n=function(e){var t=[];return e.traverse(function(e){"Mesh"===e.type&&t.push(e)}),t}(e),a=new c,o=new c;if(0===n.length)return null;if(1===n.length){var i=new y,m=new p,u=new y;return n[0].geometry.isBufferGeometry?n[0].geometry.attributes.position&&n[0].geometry.attributes.position.itemSize>2&&a.fromBufferGeometry(n[0].geometry):a=n[0].geometry.clone(),a.metadata=n[0].geometry.metadata,n[0].updateMatrixWorld(),n[0].matrixWorld.decompose(i,m,u),a.scale(u.x,u.y,u.z)}for(;r=n.pop();)if(r.updateMatrixWorld(),r.geometry.isBufferGeometry){if(r.geometry.attributes.position&&r.geometry.attributes.position.itemSize>2){var s=new c;s.fromBufferGeometry(r.geometry),o.merge(s,r.matrixWorld),s.dispose()}}else o.merge(r.geometry,r.matrixWorld);return(t=new d).scale(e.scale),o.applyMatrix(t),o}function S(e){return e.attributes||(e=(new g).fromGeometry(e)),(e.attributes.position||{}).array||[]}w.Type=x;export{w as threeToCannon};
import{Sphere as e,Box as r,Vec3 as t,ConvexPolyhedron as n,Cylinder as a,Shape as o,Quaternion as i,Trimesh as m}from"cannon-es";import{ConvexHull as u}from"three/examples/jsm/math/ConvexHull.js";import{Box3 as s,Vector3 as l,Mesh as y,Math as f,Geometry as p,Quaternion as d,Matrix4 as c,BufferGeometry as g}from"three";var h=Math.PI/2,x={BOX:"Box",CYLINDER:"Cylinder",SPHERE:"Sphere",HULL:"ConvexPolyhedron",MESH:"Trimesh"};const w=function(l,p){var d;if((p=p||{}).type===x.BOX)return B(l);if(p.type===x.CYLINDER)return function(e,r){var t=["x","y","z"],n=r.cylinderAxis||"y",m=t.splice(t.indexOf(n),1)&&t,u=(new s).setFromObject(e);if(!isFinite(u.min.lengthSq()))return null;var l=u.max[n]-u.min[n],y=.5*Math.max(u.max[m[0]]-u.min[m[0]],u.max[m[1]]-u.min[m[1]]),f=new a(y,y,l,12);return f._type=o.types.CYLINDER,f.radiusTop=y,f.radiusBottom=y,f.height=l,f.numSegments=12,f.orientation=new i,f.orientation.setFromEuler("y"===n?h:0,"z"===n?h:0,0,"XYZ").normalize(),f}(l,p);if(p.type===x.SPHERE)return function(r,t){if(t.sphereRadius)return new e(t.sphereRadius);var n=S(r);return n?(n.computeBoundingSphere(),new e(n.boundingSphere.radius)):null}(l,p);if(p.type===x.HULL)return function(e){var r=S(e);if(!r||!r.vertices.length)return null;for(var a=0;a<r.vertices.length;a++)r.vertices[a].x+=1e-4*(Math.random()-.5),r.vertices[a].y+=1e-4*(Math.random()-.5),r.vertices[a].z+=1e-4*(Math.random()-.5);var o=(new u).setFromObject(new y(r)).faces,i=[],m=[];for(a=0;a<o.length;a++){var s=o[a],l=s.edge;do{var f=l.head().point;i.push(new t(f.x,f.y,f.z)),m.push(new t(s.normal.x,s.normal.y,s.normal.z)),l=l.next}while(l!==s.edge)}return new n({vertices:i,normals:m})}(l);if(p.type===x.MESH)return(d=S(l))?function(e){var r=b(e);if(!r.length)return null;var t=Object.keys(r).map(Number);return new m(r,t)}(d):null;if(p.type)throw new Error('[CANNON.threeToCannon] Invalid type "%s".',p.type);if(!(d=S(l)))return null;switch(d.metadata?d.metadata.type:d.type){case"BoxGeometry":case"BoxBufferGeometry":return v(d);case"CylinderGeometry":case"CylinderBufferGeometry":return function(e){var r=e.metadata?e.metadata.parameters:e.parameters,t=new a(r.radiusTop,r.radiusBottom,r.height,r.radialSegments);return t._type=o.types.CYLINDER,t.radiusTop=r.radiusTop,t.radiusBottom=r.radiusBottom,t.height=r.height,t.numSegments=r.radialSegments,t.orientation=new i,t.orientation.setFromEuler(f.degToRad(90),0,0,"XYZ").normalize(),t}(d);case"PlaneGeometry":case"PlaneBufferGeometry":return function(e){e.computeBoundingBox();var n=e.boundingBox;return new r(new t((n.max.x-n.min.x)/2||.1,(n.max.y-n.min.y)/2||.1,(n.max.z-n.min.z)/2||.1))}(d);case"SphereGeometry":case"SphereBufferGeometry":return function(r){return new e((r.metadata?r.metadata.parameters:r.parameters).radius)}(d);case"TubeGeometry":case"Geometry":case"BufferGeometry":return B(l);default:return console.warn('Unrecognized geometry: "%s". Using bounding box as shape.',d.type),v(d)}};function v(e){if(!b(e).length)return null;e.computeBoundingBox();var n=e.boundingBox;return new r(new t((n.max.x-n.min.x)/2,(n.max.y-n.min.y)/2,(n.max.z-n.min.z)/2))}function B(e){var n=e.clone();n.quaternion.set(0,0,0,1),n.updateMatrixWorld();var a=(new s).setFromObject(n);if(!isFinite(a.min.lengthSq()))return null;var o=new r(new t((a.max.x-a.min.x)/2,(a.max.y-a.min.y)/2,(a.max.z-a.min.z)/2)),i=a.translate(n.position.negate()).getCenter(new l);return i.lengthSq()&&(o.offset=i),o}function S(e){var r,t=function(e){var r=[];return e.traverse(function(e){"Mesh"===e.type&&r.push(e)}),r}(e),n=new p,a=new p;if(0===t.length)return null;if(1===t.length){var o=new l,i=new d,m=new l;return t[0].geometry.isBufferGeometry?t[0].geometry.attributes.position&&t[0].geometry.attributes.position.itemSize>2&&n.fromBufferGeometry(t[0].geometry):n=t[0].geometry.clone(),n.metadata=t[0].geometry.metadata,t[0].updateMatrixWorld(),t[0].matrixWorld.decompose(o,i,m),n.scale(m.x,m.y,m.z)}for(;r=t.pop();)if(r.updateMatrixWorld(),r.geometry.isBufferGeometry){if(r.geometry.attributes.position&&r.geometry.attributes.position.itemSize>2){var u=new p;u.fromBufferGeometry(r.geometry),a.merge(u,r.matrixWorld),u.dispose()}}else a.merge(r.geometry,r.matrixWorld);var s=new c;return s.scale(e.scale),a.applyMatrix(s),a}function b(e){return e.attributes||(e=(new g).fromGeometry(e)),(e.attributes.position||{}).array||[]}w.Type=x;export{w as threeToCannon};
//# sourceMappingURL=three-to-cannon.modern.js.map

@@ -1,2 +0,2 @@

import{Sphere as e,Box as t,Vec3 as r,ConvexPolyhedron as n,Cylinder as a,Shape as o,Quaternion as i,Trimesh as m}from"cannon-es";import{ConvexHull as u}from"three/examples/jsm/math/ConvexHull.js";import{Box3 as s,Vector3 as y,Mesh as f,Math as l,Geometry as c,Quaternion as p,Matrix4 as d,BufferGeometry as g}from"three";var h=Math.PI/2,x={BOX:"Box",CYLINDER:"Cylinder",SPHERE:"Sphere",HULL:"ConvexPolyhedron",MESH:"Trimesh"},w=function(y,c){var p;if((c=c||{}).type===x.BOX)return B(y);if(c.type===x.CYLINDER)return function(e,t){var r,n,m,u=new s,y=["x","y","z"],f=t.cylinderAxis||"y",l=y.splice(y.indexOf(f),1)&&y;return u.setFromObject(e),isFinite(u.min.lengthSq())?(n=u.max[f]-u.min[f],m=.5*Math.max(u.max[l[0]]-u.min[l[0]],u.max[l[1]]-u.min[l[1]]),(r=new a(m,m,n,12))._type=o.types.CYLINDER,r.radiusTop=m,r.radiusBottom=m,r.height=n,r.numSegments=12,r.orientation=new i,r.orientation.setFromEuler("y"===f?h:0,"z"===f?h:0,0,"XYZ").normalize(),r):null}(y,c);if(c.type===x.SPHERE)return function(t,r){if(r.sphereRadius)return new e(r.sphereRadius);var n=b(t);return n?(n.computeBoundingSphere(),new e(n.boundingSphere.radius)):null}(y,c);if(c.type===x.HULL)return function(e){var t,a,o,i,m=b(e);if(!m||!m.vertices.length)return null;for(t=0;t<m.vertices.length;t++)m.vertices[t].x+=1e-4*(Math.random()-.5),m.vertices[t].y+=1e-4*(Math.random()-.5),m.vertices[t].z+=1e-4*(Math.random()-.5);for(i=(new u).setFromObject(new f(m)),a=new Array(i.vertices.length),t=0;t<i.vertices.length;t++)a[t]=new r(i.vertices[t].x,i.vertices[t].y,i.vertices[t].z);for(o=new Array(i.faces.length),t=0;t<i.faces.length;t++)o[t]=[i.faces[t].a,i.faces[t].b,i.faces[t].c];return new n(a,o)}(y);if(c.type===x.MESH)return(p=b(y))?function(e){var t,r=S(e);return r.length?(t=Object.keys(r).map(Number),new m(r,t)):null}(p):null;if(c.type)throw new Error('[CANNON.threeToCannon] Invalid type "%s".',c.type);if(!(p=b(y)))return null;switch(p.metadata?p.metadata.type:p.type){case"BoxGeometry":case"BoxBufferGeometry":return v(p);case"CylinderGeometry":case"CylinderBufferGeometry":return function(e){var t,r=e.metadata?e.metadata.parameters:e.parameters;return(t=new a(r.radiusTop,r.radiusBottom,r.height,r.radialSegments))._type=o.types.CYLINDER,t.radiusTop=r.radiusTop,t.radiusBottom=r.radiusBottom,t.height=r.height,t.numSegments=r.radialSegments,t.orientation=new i,t.orientation.setFromEuler(l.degToRad(90),0,0,"XYZ").normalize(),t}(p);case"PlaneGeometry":case"PlaneBufferGeometry":return function(e){e.computeBoundingBox();var n=e.boundingBox;return new t(new r((n.max.x-n.min.x)/2||.1,(n.max.y-n.min.y)/2||.1,(n.max.z-n.min.z)/2||.1))}(p);case"SphereGeometry":case"SphereBufferGeometry":return function(t){return new e((t.metadata?t.metadata.parameters:t.parameters).radius)}(p);case"TubeGeometry":case"Geometry":case"BufferGeometry":return B(y);default:return console.warn('Unrecognized geometry: "%s". Using bounding box as shape.',p.type),v(p)}};function v(e){if(!S(e).length)return null;e.computeBoundingBox();var n=e.boundingBox;return new t(new r((n.max.x-n.min.x)/2,(n.max.y-n.min.y)/2,(n.max.z-n.min.z)/2))}function B(e){var n,a,o=new s,i=e.clone();return i.quaternion.set(0,0,0,1),i.updateMatrixWorld(),o.setFromObject(i),isFinite(o.min.lengthSq())?(n=new t(new r((o.max.x-o.min.x)/2,(o.max.y-o.min.y)/2,(o.max.z-o.min.z)/2)),(a=o.translate(i.position.negate()).getCenter(new y)).lengthSq()&&(n.offset=a),n):null}function b(e){var t,r,n=function(e){var t=[];return e.traverse(function(e){"Mesh"===e.type&&t.push(e)}),t}(e),a=new c,o=new c;if(0===n.length)return null;if(1===n.length){var i=new y,m=new p,u=new y;return n[0].geometry.isBufferGeometry?n[0].geometry.attributes.position&&n[0].geometry.attributes.position.itemSize>2&&a.fromBufferGeometry(n[0].geometry):a=n[0].geometry.clone(),a.metadata=n[0].geometry.metadata,n[0].updateMatrixWorld(),n[0].matrixWorld.decompose(i,m,u),a.scale(u.x,u.y,u.z)}for(;r=n.pop();)if(r.updateMatrixWorld(),r.geometry.isBufferGeometry){if(r.geometry.attributes.position&&r.geometry.attributes.position.itemSize>2){var s=new c;s.fromBufferGeometry(r.geometry),o.merge(s,r.matrixWorld),s.dispose()}}else o.merge(r.geometry,r.matrixWorld);return(t=new d).scale(e.scale),o.applyMatrix(t),o}function S(e){return e.attributes||(e=(new g).fromGeometry(e)),(e.attributes.position||{}).array||[]}w.Type=x;export{w as threeToCannon};
import{Sphere as e,Box as r,Vec3 as t,ConvexPolyhedron as n,Cylinder as a,Shape as o,Quaternion as i,Trimesh as m}from"cannon-es";import{ConvexHull as u}from"three/examples/jsm/math/ConvexHull.js";import{Box3 as s,Vector3 as l,Mesh as y,Math as f,Geometry as p,Quaternion as d,Matrix4 as c,BufferGeometry as g}from"three";var h=Math.PI/2,x={BOX:"Box",CYLINDER:"Cylinder",SPHERE:"Sphere",HULL:"ConvexPolyhedron",MESH:"Trimesh"},w=function(l,p){var d;if((p=p||{}).type===x.BOX)return B(l);if(p.type===x.CYLINDER)return function(e,r){var t=["x","y","z"],n=r.cylinderAxis||"y",m=t.splice(t.indexOf(n),1)&&t,u=(new s).setFromObject(e);if(!isFinite(u.min.lengthSq()))return null;var l=u.max[n]-u.min[n],y=.5*Math.max(u.max[m[0]]-u.min[m[0]],u.max[m[1]]-u.min[m[1]]),f=new a(y,y,l,12);return f._type=o.types.CYLINDER,f.radiusTop=y,f.radiusBottom=y,f.height=l,f.numSegments=12,f.orientation=new i,f.orientation.setFromEuler("y"===n?h:0,"z"===n?h:0,0,"XYZ").normalize(),f}(l,p);if(p.type===x.SPHERE)return function(r,t){if(t.sphereRadius)return new e(t.sphereRadius);var n=S(r);return n?(n.computeBoundingSphere(),new e(n.boundingSphere.radius)):null}(l,p);if(p.type===x.HULL)return function(e){var r=S(e);if(!r||!r.vertices.length)return null;for(var a=0;a<r.vertices.length;a++)r.vertices[a].x+=1e-4*(Math.random()-.5),r.vertices[a].y+=1e-4*(Math.random()-.5),r.vertices[a].z+=1e-4*(Math.random()-.5);var o=(new u).setFromObject(new y(r)).faces,i=[],m=[];for(a=0;a<o.length;a++){var s=o[a],l=s.edge;do{var f=l.head().point;i.push(new t(f.x,f.y,f.z)),m.push(new t(s.normal.x,s.normal.y,s.normal.z)),l=l.next}while(l!==s.edge)}return new n({vertices:i,normals:m})}(l);if(p.type===x.MESH)return(d=S(l))?function(e){var r=b(e);if(!r.length)return null;var t=Object.keys(r).map(Number);return new m(r,t)}(d):null;if(p.type)throw new Error('[CANNON.threeToCannon] Invalid type "%s".',p.type);if(!(d=S(l)))return null;switch(d.metadata?d.metadata.type:d.type){case"BoxGeometry":case"BoxBufferGeometry":return v(d);case"CylinderGeometry":case"CylinderBufferGeometry":return function(e){var r=e.metadata?e.metadata.parameters:e.parameters,t=new a(r.radiusTop,r.radiusBottom,r.height,r.radialSegments);return t._type=o.types.CYLINDER,t.radiusTop=r.radiusTop,t.radiusBottom=r.radiusBottom,t.height=r.height,t.numSegments=r.radialSegments,t.orientation=new i,t.orientation.setFromEuler(f.degToRad(90),0,0,"XYZ").normalize(),t}(d);case"PlaneGeometry":case"PlaneBufferGeometry":return function(e){e.computeBoundingBox();var n=e.boundingBox;return new r(new t((n.max.x-n.min.x)/2||.1,(n.max.y-n.min.y)/2||.1,(n.max.z-n.min.z)/2||.1))}(d);case"SphereGeometry":case"SphereBufferGeometry":return function(r){return new e((r.metadata?r.metadata.parameters:r.parameters).radius)}(d);case"TubeGeometry":case"Geometry":case"BufferGeometry":return B(l);default:return console.warn('Unrecognized geometry: "%s". Using bounding box as shape.',d.type),v(d)}};function v(e){if(!b(e).length)return null;e.computeBoundingBox();var n=e.boundingBox;return new r(new t((n.max.x-n.min.x)/2,(n.max.y-n.min.y)/2,(n.max.z-n.min.z)/2))}function B(e){var n=e.clone();n.quaternion.set(0,0,0,1),n.updateMatrixWorld();var a=(new s).setFromObject(n);if(!isFinite(a.min.lengthSq()))return null;var o=new r(new t((a.max.x-a.min.x)/2,(a.max.y-a.min.y)/2,(a.max.z-a.min.z)/2)),i=a.translate(n.position.negate()).getCenter(new l);return i.lengthSq()&&(o.offset=i),o}function S(e){var r,t=function(e){var r=[];return e.traverse(function(e){"Mesh"===e.type&&r.push(e)}),r}(e),n=new p,a=new p;if(0===t.length)return null;if(1===t.length){var o=new l,i=new d,m=new l;return t[0].geometry.isBufferGeometry?t[0].geometry.attributes.position&&t[0].geometry.attributes.position.itemSize>2&&n.fromBufferGeometry(t[0].geometry):n=t[0].geometry.clone(),n.metadata=t[0].geometry.metadata,t[0].updateMatrixWorld(),t[0].matrixWorld.decompose(o,i,m),n.scale(m.x,m.y,m.z)}for(;r=t.pop();)if(r.updateMatrixWorld(),r.geometry.isBufferGeometry){if(r.geometry.attributes.position&&r.geometry.attributes.position.itemSize>2){var u=new p;u.fromBufferGeometry(r.geometry),a.merge(u,r.matrixWorld),u.dispose()}}else a.merge(r.geometry,r.matrixWorld);var s=new c;return s.scale(e.scale),a.applyMatrix(s),a}function b(e){return e.attributes||(e=(new g).fromGeometry(e)),(e.attributes.position||{}).array||[]}w.Type=x;export{w as threeToCannon};
//# sourceMappingURL=three-to-cannon.module.js.map

@@ -1,2 +0,2 @@

!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("cannon-es"),require("three/examples/jsm/math/ConvexHull.js"),require("three")):"function"==typeof define&&define.amd?define(["exports","cannon-es","three/examples/jsm/math/ConvexHull.js","three"],t):t((e=e||self).threeToCannon={},e.cannonEs,e.ConvexHull_js,e.THREE)}(this,function(e,t,r,n){var o=Math.PI/2,a={BOX:"Box",CYLINDER:"Cylinder",SPHERE:"Sphere",HULL:"ConvexPolyhedron",MESH:"Trimesh"},i=function(e,i){var y;if((i=i||{}).type===a.BOX)return u(e);if(i.type===a.CYLINDER)return function(e,r){var a,i,m,u=new n.Box3,s=["x","y","z"],l=r.cylinderAxis||"y",y=s.splice(s.indexOf(l),1)&&s;return u.setFromObject(e),isFinite(u.min.lengthSq())?(i=u.max[l]-u.min[l],m=.5*Math.max(u.max[y[0]]-u.min[y[0]],u.max[y[1]]-u.min[y[1]]),(a=new t.Cylinder(m,m,i,12))._type=t.Shape.types.CYLINDER,a.radiusTop=m,a.radiusBottom=m,a.height=i,a.numSegments=12,a.orientation=new t.Quaternion,a.orientation.setFromEuler("y"===l?o:0,"z"===l?o:0,0,"XYZ").normalize(),a):null}(e,i);if(i.type===a.SPHERE)return function(e,r){if(r.sphereRadius)return new t.Sphere(r.sphereRadius);var n=s(e);return n?(n.computeBoundingSphere(),new t.Sphere(n.boundingSphere.radius)):null}(e,i);if(i.type===a.HULL)return function(e){var o,a,i,m,u=s(e);if(!u||!u.vertices.length)return null;for(o=0;o<u.vertices.length;o++)u.vertices[o].x+=1e-4*(Math.random()-.5),u.vertices[o].y+=1e-4*(Math.random()-.5),u.vertices[o].z+=1e-4*(Math.random()-.5);for(m=(new r.ConvexHull).setFromObject(new n.Mesh(u)),a=new Array(m.vertices.length),o=0;o<m.vertices.length;o++)a[o]=new t.Vec3(m.vertices[o].x,m.vertices[o].y,m.vertices[o].z);for(i=new Array(m.faces.length),o=0;o<m.faces.length;o++)i[o]=[m.faces[o].a,m.faces[o].b,m.faces[o].c];return new t.ConvexPolyhedron(a,i)}(e);if(i.type===a.MESH)return(y=s(e))?function(e){var r,n=l(e);return n.length?(r=Object.keys(n).map(Number),new t.Trimesh(n,r)):null}(y):null;if(i.type)throw new Error('[CANNON.threeToCannon] Invalid type "%s".',i.type);if(!(y=s(e)))return null;switch(y.metadata?y.metadata.type:y.type){case"BoxGeometry":case"BoxBufferGeometry":return m(y);case"CylinderGeometry":case"CylinderBufferGeometry":return function(e){var r,o=e.metadata?e.metadata.parameters:e.parameters;return(r=new t.Cylinder(o.radiusTop,o.radiusBottom,o.height,o.radialSegments))._type=t.Shape.types.CYLINDER,r.radiusTop=o.radiusTop,r.radiusBottom=o.radiusBottom,r.height=o.height,r.numSegments=o.radialSegments,r.orientation=new t.Quaternion,r.orientation.setFromEuler(n.Math.degToRad(90),0,0,"XYZ").normalize(),r}(y);case"PlaneGeometry":case"PlaneBufferGeometry":return function(e){e.computeBoundingBox();var r=e.boundingBox;return new t.Box(new t.Vec3((r.max.x-r.min.x)/2||.1,(r.max.y-r.min.y)/2||.1,(r.max.z-r.min.z)/2||.1))}(y);case"SphereGeometry":case"SphereBufferGeometry":return function(e){return new t.Sphere((e.metadata?e.metadata.parameters:e.parameters).radius)}(y);case"TubeGeometry":case"Geometry":case"BufferGeometry":return u(e);default:return console.warn('Unrecognized geometry: "%s". Using bounding box as shape.',y.type),m(y)}};function m(e){if(!l(e).length)return null;e.computeBoundingBox();var r=e.boundingBox;return new t.Box(new t.Vec3((r.max.x-r.min.x)/2,(r.max.y-r.min.y)/2,(r.max.z-r.min.z)/2))}function u(e){var r,o,a=new n.Box3,i=e.clone();return i.quaternion.set(0,0,0,1),i.updateMatrixWorld(),a.setFromObject(i),isFinite(a.min.lengthSq())?(r=new t.Box(new t.Vec3((a.max.x-a.min.x)/2,(a.max.y-a.min.y)/2,(a.max.z-a.min.z)/2)),(o=a.translate(i.position.negate()).getCenter(new n.Vector3)).lengthSq()&&(r.offset=o),r):null}function s(e){var t,r,o=function(e){var t=[];return e.traverse(function(e){"Mesh"===e.type&&t.push(e)}),t}(e),a=new n.Geometry,i=new n.Geometry;if(0===o.length)return null;if(1===o.length){var m=new n.Vector3,u=new n.Quaternion,s=new n.Vector3;return o[0].geometry.isBufferGeometry?o[0].geometry.attributes.position&&o[0].geometry.attributes.position.itemSize>2&&a.fromBufferGeometry(o[0].geometry):a=o[0].geometry.clone(),a.metadata=o[0].geometry.metadata,o[0].updateMatrixWorld(),o[0].matrixWorld.decompose(m,u,s),a.scale(s.x,s.y,s.z)}for(;r=o.pop();)if(r.updateMatrixWorld(),r.geometry.isBufferGeometry){if(r.geometry.attributes.position&&r.geometry.attributes.position.itemSize>2){var l=new n.Geometry;l.fromBufferGeometry(r.geometry),i.merge(l,r.matrixWorld),l.dispose()}}else i.merge(r.geometry,r.matrixWorld);return(t=new n.Matrix4).scale(e.scale),i.applyMatrix(t),i}function l(e){return e.attributes||(e=(new n.BufferGeometry).fromGeometry(e)),(e.attributes.position||{}).array||[]}i.Type=a,e.threeToCannon=i});
!function(e,r){"object"==typeof exports&&"undefined"!=typeof module?r(exports,require("cannon-es"),require("three/examples/jsm/math/ConvexHull.js"),require("three")):"function"==typeof define&&define.amd?define(["exports","cannon-es","three/examples/jsm/math/ConvexHull.js","three"],r):r((e=e||self).threeToCannon={},e.cannonEs,e.ConvexHull_js,e.THREE)}(this,function(e,r,t,n){var o=Math.PI/2,a={BOX:"Box",CYLINDER:"Cylinder",SPHERE:"Sphere",HULL:"ConvexPolyhedron",MESH:"Trimesh"},i=function(e,i){var y;if((i=i||{}).type===a.BOX)return m(e);if(i.type===a.CYLINDER)return function(e,t){var a=["x","y","z"],i=t.cylinderAxis||"y",u=a.splice(a.indexOf(i),1)&&a,m=(new n.Box3).setFromObject(e);if(!isFinite(m.min.lengthSq()))return null;var s=m.max[i]-m.min[i],l=.5*Math.max(m.max[u[0]]-m.min[u[0]],m.max[u[1]]-m.min[u[1]]),y=new r.Cylinder(l,l,s,12);return y._type=r.Shape.types.CYLINDER,y.radiusTop=l,y.radiusBottom=l,y.height=s,y.numSegments=12,y.orientation=new r.Quaternion,y.orientation.setFromEuler("y"===i?o:0,"z"===i?o:0,0,"XYZ").normalize(),y}(e,i);if(i.type===a.SPHERE)return function(e,t){if(t.sphereRadius)return new r.Sphere(t.sphereRadius);var n=s(e);return n?(n.computeBoundingSphere(),new r.Sphere(n.boundingSphere.radius)):null}(e,i);if(i.type===a.HULL)return function(e){var o=s(e);if(!o||!o.vertices.length)return null;for(var a=0;a<o.vertices.length;a++)o.vertices[a].x+=1e-4*(Math.random()-.5),o.vertices[a].y+=1e-4*(Math.random()-.5),o.vertices[a].z+=1e-4*(Math.random()-.5);var i=(new t.ConvexHull).setFromObject(new n.Mesh(o)).faces,u=[],m=[];for(a=0;a<i.length;a++){var l=i[a],y=l.edge;do{var f=y.head().point;u.push(new r.Vec3(f.x,f.y,f.z)),m.push(new r.Vec3(l.normal.x,l.normal.y,l.normal.z)),y=y.next}while(y!==l.edge)}return new r.ConvexPolyhedron({vertices:u,normals:m})}(e);if(i.type===a.MESH)return(y=s(e))?function(e){var t=l(e);if(!t.length)return null;var n=Object.keys(t).map(Number);return new r.Trimesh(t,n)}(y):null;if(i.type)throw new Error('[CANNON.threeToCannon] Invalid type "%s".',i.type);if(!(y=s(e)))return null;switch(y.metadata?y.metadata.type:y.type){case"BoxGeometry":case"BoxBufferGeometry":return u(y);case"CylinderGeometry":case"CylinderBufferGeometry":return function(e){var t=e.metadata?e.metadata.parameters:e.parameters,o=new r.Cylinder(t.radiusTop,t.radiusBottom,t.height,t.radialSegments);return o._type=r.Shape.types.CYLINDER,o.radiusTop=t.radiusTop,o.radiusBottom=t.radiusBottom,o.height=t.height,o.numSegments=t.radialSegments,o.orientation=new r.Quaternion,o.orientation.setFromEuler(n.Math.degToRad(90),0,0,"XYZ").normalize(),o}(y);case"PlaneGeometry":case"PlaneBufferGeometry":return function(e){e.computeBoundingBox();var t=e.boundingBox;return new r.Box(new r.Vec3((t.max.x-t.min.x)/2||.1,(t.max.y-t.min.y)/2||.1,(t.max.z-t.min.z)/2||.1))}(y);case"SphereGeometry":case"SphereBufferGeometry":return function(e){return new r.Sphere((e.metadata?e.metadata.parameters:e.parameters).radius)}(y);case"TubeGeometry":case"Geometry":case"BufferGeometry":return m(e);default:return console.warn('Unrecognized geometry: "%s". Using bounding box as shape.',y.type),u(y)}};function u(e){if(!l(e).length)return null;e.computeBoundingBox();var t=e.boundingBox;return new r.Box(new r.Vec3((t.max.x-t.min.x)/2,(t.max.y-t.min.y)/2,(t.max.z-t.min.z)/2))}function m(e){var t=e.clone();t.quaternion.set(0,0,0,1),t.updateMatrixWorld();var o=(new n.Box3).setFromObject(t);if(!isFinite(o.min.lengthSq()))return null;var a=new r.Box(new r.Vec3((o.max.x-o.min.x)/2,(o.max.y-o.min.y)/2,(o.max.z-o.min.z)/2)),i=o.translate(t.position.negate()).getCenter(new n.Vector3);return i.lengthSq()&&(a.offset=i),a}function s(e){var r,t=function(e){var r=[];return e.traverse(function(e){"Mesh"===e.type&&r.push(e)}),r}(e),o=new n.Geometry,a=new n.Geometry;if(0===t.length)return null;if(1===t.length){var i=new n.Vector3,u=new n.Quaternion,m=new n.Vector3;return t[0].geometry.isBufferGeometry?t[0].geometry.attributes.position&&t[0].geometry.attributes.position.itemSize>2&&o.fromBufferGeometry(t[0].geometry):o=t[0].geometry.clone(),o.metadata=t[0].geometry.metadata,t[0].updateMatrixWorld(),t[0].matrixWorld.decompose(i,u,m),o.scale(m.x,m.y,m.z)}for(;r=t.pop();)if(r.updateMatrixWorld(),r.geometry.isBufferGeometry){if(r.geometry.attributes.position&&r.geometry.attributes.position.itemSize>2){var s=new n.Geometry;s.fromBufferGeometry(r.geometry),a.merge(s,r.matrixWorld),s.dispose()}}else a.merge(r.geometry,r.matrixWorld);var l=new n.Matrix4;return l.scale(e.scale),a.applyMatrix(l),a}function l(e){return e.attributes||(e=(new n.BufferGeometry).fromGeometry(e)),(e.attributes.position||{}).array||[]}i.Type=a,e.threeToCannon=i});
//# sourceMappingURL=three-to-cannon.umd.js.map

@@ -100,5 +100,2 @@ import { Box, ConvexPolyhedron, Cylinder, Shape, Sphere, Quaternion as CQuaternion, Trimesh, Vec3 } from 'cannon-es';

function createBoundingBoxShape (object) {
var shape, localPosition,
box = new Box3();
var clone = object.clone();

@@ -108,7 +105,7 @@ clone.quaternion.set(0, 0, 0, 1);

box.setFromObject(clone);
var box = new Box3().setFromObject(clone);
if (!isFinite(box.min.lengthSq())) return null;
shape = new Box(new Vec3(
var shape = new Box(new Vec3(
(box.max.x - box.min.x) / 2,

@@ -119,3 +116,3 @@ (box.max.y - box.min.y) / 2,

localPosition = box.translate(clone.position.negate()).getCenter(new Vector3());
var localPosition = box.translate(clone.position.negate()).getCenter(new Vector3());
if (localPosition.lengthSq()) {

@@ -134,5 +131,3 @@ shape.offset = localPosition;

function createConvexPolyhedron (object) {
var i, vertices, faces, hull,
eps = 1e-4,
geometry = getGeometry(object);
var geometry = getGeometry(object);

@@ -142,3 +137,4 @@ if (!geometry || !geometry.vertices.length) return null;

// Perturb.
for (i = 0; i < geometry.vertices.length; i++) {
var eps = 1e-4;
for (var i = 0; i < geometry.vertices.length; i++) {
geometry.vertices[i].x += (Math.random() - 0.5) * eps;

@@ -150,17 +146,19 @@ geometry.vertices[i].y += (Math.random() - 0.5) * eps;

// Compute the 3D convex hull.
hull = new ConvexHull().setFromObject(new Mesh(geometry));
var hull = new ConvexHull().setFromObject(new Mesh(geometry));
var faces = hull.faces;
var vertices = [];
var normals = [];
// Convert from THREE.Vector3 to Vec3.
vertices = new Array(hull.vertices.length);
for (i = 0; i < hull.vertices.length; i++) {
vertices[i] = new Vec3(hull.vertices[i].x, hull.vertices[i].y, hull.vertices[i].z);
for ( var i = 0; i < faces.length; i ++ ) {
var face = faces[ i ];
var edge = face.edge;
do {
var point = edge.head().point;
vertices.push( new Vec3(point.x, point.y, point.z) );
normals.push( new Vec3(face.normal.x, face.normal.y, face.normal.z) );
edge = edge.next;
} while ( edge !== face.edge );
}
// Convert from THREE.Face to Array<number>.
faces = new Array(hull.faces.length);
for (i = 0; i < hull.faces.length; i++) {
faces[i] = [hull.faces[i].a, hull.faces[i].b, hull.faces[i].c];
}
return new ConvexPolyhedron(vertices, faces);
return new ConvexPolyhedron({vertices, normals});
}

@@ -173,7 +171,7 @@

function createCylinderShape (geometry) {
var shape,
params = geometry.metadata
? geometry.metadata.parameters
: geometry.parameters;
shape = new Cylinder(
var params = geometry.metadata
? geometry.metadata.parameters
: geometry.parameters;
var shape = new Cylinder(
params.radiusTop,

@@ -202,15 +200,12 @@ params.radiusBottom,

function createBoundingCylinderShape (object, options) {
var shape, height, radius,
box = new Box3(),
axes = ['x', 'y', 'z'],
majorAxis = options.cylinderAxis || 'y',
minorAxes = axes.splice(axes.indexOf(majorAxis), 1) && axes;
var axes = ['x', 'y', 'z'];
var majorAxis = options.cylinderAxis || 'y';
var minorAxes = axes.splice(axes.indexOf(majorAxis), 1) && axes;
var box = new Box3().setFromObject(object);
box.setFromObject(object);
if (!isFinite(box.min.lengthSq())) return null;
// Compute cylinder dimensions.
height = box.max[majorAxis] - box.min[majorAxis];
radius = 0.5 * Math.max(
var height = box.max[majorAxis] - box.min[majorAxis];
var radius = 0.5 * Math.max(
box.max[minorAxes[0]] - box.min[minorAxes[0]],

@@ -221,3 +216,3 @@ box.max[minorAxes[1]] - box.min[minorAxes[1]]

// Create shape.
shape = new Cylinder(radius, radius, height, 12);
var shape = new Cylinder(radius, radius, height, 12);

@@ -285,8 +280,7 @@ // Include metadata for serialization.

function createTrimeshShape (geometry) {
var indices,
vertices = getVertices(geometry);
var vertices = getVertices(geometry);
if (!vertices.length) return null;
indices = Object.keys(vertices).map(Number);
var indices = Object.keys(vertices).map(Number);
return new Trimesh(vertices, indices);

@@ -306,3 +300,3 @@ }

function getGeometry (object) {
var matrix, mesh,
var mesh,
meshes = getMeshes(object),

@@ -349,3 +343,3 @@ tmp = new Geometry(),

matrix = new Matrix4();
var matrix = new Matrix4();
matrix.scale(object.scale);

@@ -352,0 +346,0 @@ combined.applyMatrix(matrix);

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

@@ -5,0 +5,0 @@ "main": "dist/three-to-cannon.js",

@@ -65,2 +65,3 @@ // See: https://github.com/substack/tape/issues/514

t.equal( hull.type, ShapeType.HULL, 'hull.type' );
t.equals( hull.boundingSphereRadius.toFixed( 3 ), '8.660', 'hull.boundingSphereRadius' );

@@ -74,2 +75,3 @@ t.end();

t.equal( mesh.type, ShapeType.MESH, 'mesh.type' );
t.equals( mesh.boundingSphereRadius.toFixed( 3 ), '8.660', 'mesh.boundingSphereRadius' );

@@ -76,0 +78,0 @@ t.end();

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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