Socket
Socket
Sign inDemoInstall

three-to-cannon

Package Overview
Dependencies
2
Maintainers
1
Versions
25
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 3.0.1 to 3.0.2

lib/ConvexHull.js

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,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;
var e=require("cannon-es"),t=require("three"),n=function(){var e,n,r,i,o=new t.Vector3;function a(){this.tolerance=-1,this.faces=[],this.newFaces=[],this.assigned=new l,this.unassigned=new l,this.vertices=[]}function s(){this.normal=new t.Vector3,this.midpoint=new t.Vector3,this.area=0,this.constant=0,this.outside=null,this.mark=0,this.edge=null}function u(e,t){this.vertex=e,this.prev=null,this.next=null,this.twin=null,this.face=t}function h(e){this.point=e,this.prev=null,this.next=null,this.face=null}function l(){this.head=null,this.tail=null}return Object.assign(a.prototype,{setFromPoints:function(e){!0!==Array.isArray(e)&&console.error("THREE.ConvexHull: Points parameter is not an array."),e.length<4&&console.error("THREE.ConvexHull: The algorithm needs at least four points."),this.makeEmpty();for(var t=0,n=e.length;t<n;t++)this.vertices.push(new h(e[t]));return this.compute(),this},setFromObject:function(e){var n=[];return e.updateMatrixWorld(!0),e.traverse(function(e){var r,i,o,a=e.geometry;if(void 0!==a)if(a.isGeometry){var s=a.vertices;for(r=0,i=s.length;r<i;r++)(o=s[r].clone()).applyMatrix4(e.matrixWorld),n.push(o)}else if(a.isBufferGeometry){var u=a.attributes.position;if(void 0!==u)for(r=0,i=u.count;r<i;r++)(o=new t.Vector3).fromBufferAttribute(u,r).applyMatrix4(e.matrixWorld),n.push(o)}}),this.setFromPoints(n)},containsPoint:function(e){for(var t=this.faces,n=0,r=t.length;n<r;n++)if(t[n].distanceToPoint(e)>this.tolerance)return!1;return!0},intersectRay:function(e,t){for(var n=this.faces,r=-Infinity,i=Infinity,o=0,a=n.length;o<a;o++){var s=n[o],u=s.distanceToPoint(e.origin),h=s.normal.dot(e.direction);if(u>0&&h>=0)return null;var l=0!==h?-u/h:0;if(!(l<=0)&&(h>0?i=Math.min(l,i):r=Math.max(l,r),r>i))return null}return e.at(-Infinity!==r?r:i,t),t},intersectsRay:function(e){return null!==this.intersectRay(e,o)},makeEmpty:function(){return this.faces=[],this.vertices=[],this},addVertexToFace:function(e,t){return e.face=t,null===t.outside?this.assigned.append(e):this.assigned.insertBefore(t.outside,e),t.outside=e,this},removeVertexFromFace:function(e,t){return e===t.outside&&(t.outside=null!==e.next&&e.next.face===t?e.next:null),this.assigned.remove(e),this},removeAllVerticesFromFace:function(e){if(null!==e.outside){for(var t=e.outside,n=e.outside;null!==n.next&&n.next.face===e;)n=n.next;return this.assigned.removeSubList(t,n),t.prev=n.next=null,e.outside=null,t}},deleteFaceVertices:function(e,t){var n=this.removeAllVerticesFromFace(e);if(void 0!==n)if(void 0===t)this.unassigned.appendChain(n);else{var r=n;do{var i=r.next;t.distanceToPoint(r.point)>this.tolerance?this.addVertexToFace(r,t):this.unassigned.append(r),r=i}while(null!==r)}return this},resolveUnassignedPoints:function(e){if(!1===this.unassigned.isEmpty()){var t=this.unassigned.first();do{for(var n=t.next,r=this.tolerance,i=null,o=0;o<e.length;o++){var a=e[o];if(0===a.mark){var s=a.distanceToPoint(t.point);if(s>r&&(r=s,i=a),r>1e3*this.tolerance)break}}null!==i&&this.addVertexToFace(t,i),t=n}while(null!==t)}return this},computeExtremes:function(){var e,n,r,i=new t.Vector3,o=new t.Vector3,a=[],s=[];for(e=0;e<3;e++)a[e]=s[e]=this.vertices[0];for(i.copy(this.vertices[0].point),o.copy(this.vertices[0].point),e=0,n=this.vertices.length;e<n;e++){var u=this.vertices[e],h=u.point;for(r=0;r<3;r++)h.getComponent(r)<i.getComponent(r)&&(i.setComponent(r,h.getComponent(r)),a[r]=u);for(r=0;r<3;r++)h.getComponent(r)>o.getComponent(r)&&(o.setComponent(r,h.getComponent(r)),s[r]=u)}return this.tolerance=3*Number.EPSILON*(Math.max(Math.abs(i.x),Math.abs(o.x))+Math.max(Math.abs(i.y),Math.abs(o.y))+Math.max(Math.abs(i.z),Math.abs(o.z))),{min:a,max:s}},computeInitialHull:function(){void 0===e&&(e=new t.Line3,n=new t.Plane,r=new t.Vector3);var i,o,a,u,h,l,c,d,m,p=this.vertices,f=this.computeExtremes(),v=f.min,g=f.max,x=0,y=0;for(l=0;l<3;l++)(m=g[l].point.getComponent(l)-v[l].point.getComponent(l))>x&&(x=m,y=l);for(x=0,e.set((o=v[y]).point,(a=g[y]).point),l=0,c=this.vertices.length;l<c;l++)(i=p[l])!==o&&i!==a&&(e.closestPointToPoint(i.point,!0,r),(m=r.distanceToSquared(i.point))>x&&(x=m,u=i));for(x=-1,n.setFromCoplanarPoints(o.point,a.point,u.point),l=0,c=this.vertices.length;l<c;l++)(i=p[l])!==o&&i!==a&&i!==u&&(m=Math.abs(n.distanceToPoint(i.point)))>x&&(x=m,h=i);var w=[];if(n.distanceToPoint(h.point)<0)for(w.push(s.create(o,a,u),s.create(h,a,o),s.create(h,u,a),s.create(h,o,u)),l=0;l<3;l++)d=(l+1)%3,w[l+1].getEdge(2).setTwin(w[0].getEdge(d)),w[l+1].getEdge(1).setTwin(w[d+1].getEdge(0));else for(w.push(s.create(o,u,a),s.create(h,o,a),s.create(h,a,u),s.create(h,u,o)),l=0;l<3;l++)d=(l+1)%3,w[l+1].getEdge(2).setTwin(w[0].getEdge((3-l)%3)),w[l+1].getEdge(0).setTwin(w[d+1].getEdge(1));for(l=0;l<4;l++)this.faces.push(w[l]);for(l=0,c=p.length;l<c;l++)if((i=p[l])!==o&&i!==a&&i!==u&&i!==h){x=this.tolerance;var T=null;for(d=0;d<4;d++)(m=this.faces[d].distanceToPoint(i.point))>x&&(x=m,T=this.faces[d]);null!==T&&this.addVertexToFace(i,T)}return this},reindexFaces:function(){for(var e=[],t=0;t<this.faces.length;t++){var n=this.faces[t];0===n.mark&&e.push(n)}return this.faces=e,this},nextVertexToAdd:function(){if(!1===this.assigned.isEmpty()){var e,t=0,n=this.assigned.first().face,r=n.outside;do{var i=n.distanceToPoint(r.point);i>t&&(t=i,e=r),r=r.next}while(null!==r&&r.face===n);return e}},computeHorizon:function(e,t,n,r){var i;this.deleteFaceVertices(n),n.mark=1,i=null===t?t=n.getEdge(0):t.next;do{var o=i.twin,a=o.face;0===a.mark&&(a.distanceToPoint(e)>this.tolerance?this.computeHorizon(e,o,a,r):r.push(i)),i=i.next}while(i!==t);return this},addAdjoiningFace:function(e,t){var n=s.create(e,t.tail(),t.head());return this.faces.push(n),n.getEdge(-1).setTwin(t.twin),n.getEdge(0)},addNewFaces:function(e,t){this.newFaces=[];for(var n=null,r=null,i=0;i<t.length;i++){var o=this.addAdjoiningFace(e,t[i]);null===n?n=o:o.next.setTwin(r),this.newFaces.push(o.face),r=o}return n.next.setTwin(r),this},addVertexToHull:function(e){var t=[];return this.unassigned.clear(),this.removeVertexFromFace(e,e.face),this.computeHorizon(e.point,null,e.face,t),this.addNewFaces(e,t),this.resolveUnassignedPoints(this.newFaces),this},cleanup:function(){return this.assigned.clear(),this.unassigned.clear(),this.newFaces=[],this},compute:function(){var e;for(this.computeInitialHull();void 0!==(e=this.nextVertexToAdd());)this.addVertexToHull(e);return this.reindexFaces(),this.cleanup(),this}}),Object.assign(s,{create:function(e,t,n){var r=new s,i=new u(e,r),o=new u(t,r),a=new u(n,r);return i.next=a.prev=o,o.next=i.prev=a,a.next=o.prev=i,r.edge=i,r.compute()}}),Object.assign(s.prototype,{getEdge:function(e){for(var t=this.edge;e>0;)t=t.next,e--;for(;e<0;)t=t.prev,e++;return t},compute:function(){void 0===i&&(i=new t.Triangle);var e=this.edge.tail(),n=this.edge.head(),r=this.edge.next.head();return i.set(e.point,n.point,r.point),i.getNormal(this.normal),i.getMidpoint(this.midpoint),this.area=i.getArea(),this.constant=this.normal.dot(this.midpoint),this},distanceToPoint:function(e){return this.normal.dot(e)-this.constant}}),Object.assign(u.prototype,{head:function(){return this.vertex},tail:function(){return this.prev?this.prev.vertex:null},length:function(){var e=this.head(),t=this.tail();return null!==t?t.point.distanceTo(e.point):-1},lengthSquared:function(){var e=this.head(),t=this.tail();return null!==t?t.point.distanceToSquared(e.point):-1},setTwin:function(e){return this.twin=e,e.twin=this,this}}),Object.assign(l.prototype,{first:function(){return this.head},last:function(){return this.tail},clear:function(){return this.head=this.tail=null,this},insertBefore:function(e,t){return t.prev=e.prev,t.next=e,null===t.prev?this.head=t:t.prev.next=t,e.prev=t,this},insertAfter:function(e,t){return t.prev=e,t.next=e.next,null===t.next?this.tail=t:t.next.prev=t,e.next=t,this},append:function(e){return null===this.head?this.head=e:this.tail.next=e,e.prev=this.tail,e.next=null,this.tail=e,this},appendChain:function(e){for(null===this.head?this.head=e:this.tail.next=e,e.prev=this.tail;null!==e.next;)e=e.next;return this.tail=e,this},remove:function(e){return null===e.prev?this.head=e.next:e.prev.next=e.next,null===e.next?this.tail=e.prev:e.next.prev=e.prev,this},removeSubList:function(e,t){return null===e.prev?this.head=t.next:e.prev.next=t.next,null===t.next?this.tail=e.prev:t.next.prev=e.prev,this},isEmpty:function(){return null===this.head}}),a}(),r=Math.PI/2,i={BOX:"Box",CYLINDER:"Cylinder",SPHERE:"Sphere",HULL:"ConvexPolyhedron",MESH:"Trimesh"},o=function(o,l){var c;if((l=l||{}).type===i.BOX)return s(o);if(l.type===i.CYLINDER)return function(n,i){var o=["x","y","z"],a=i.cylinderAxis||"y",s=o.splice(o.indexOf(a),1)&&o,u=(new t.Box3).setFromObject(n);if(!isFinite(u.min.lengthSq()))return null;var h=u.max[a]-u.min[a],l=.5*Math.max(u.max[s[0]]-u.min[s[0]],u.max[s[1]]-u.min[s[1]]),c=new e.Cylinder(l,l,h,12);return c._type=e.Shape.types.CYLINDER,c.radiusTop=l,c.radiusBottom=l,c.height=h,c.numSegments=12,c.orientation=new e.Quaternion,c.orientation.setFromEuler("y"===a?r:0,"z"===a?r:0,0,"XYZ").normalize(),c}(o,l);if(l.type===i.SPHERE)return function(t,n){if(n.sphereRadius)return new e.Sphere(n.sphereRadius);var r=u(t);return r?(r.computeBoundingSphere(),new e.Sphere(r.boundingSphere.radius)):null}(o,l);if(l.type===i.HULL)return function(r){var i=u(r);if(!i||!i.vertices.length)return null;for(var o=0;o<i.vertices.length;o++)i.vertices[o].x+=1e-4*(Math.random()-.5),i.vertices[o].y+=1e-4*(Math.random()-.5),i.vertices[o].z+=1e-4*(Math.random()-.5);var a=(new n).setFromObject(new t.Mesh(i)).faces,s=[],h=[];for(o=0;o<a.length;o++){var l=a[o],c=l.edge;do{var d=c.head().point;s.push(new e.Vec3(d.x,d.y,d.z)),h.push(new e.Vec3(l.normal.x,l.normal.y,l.normal.z)),c=c.next}while(c!==l.edge)}return new e.ConvexPolyhedron({vertices:s,normals:h})}(o);if(l.type===i.MESH)return(c=u(o))?function(t){var n=h(t);if(!n.length)return null;var r=Object.keys(n).map(Number);return new e.Trimesh(n,r)}(c):null;if(l.type)throw new Error('[CANNON.threeToCannon] Invalid type "%s".',l.type);if(!(c=u(o)))return null;switch(c.metadata?c.metadata.type:c.type){case"BoxGeometry":case"BoxBufferGeometry":return a(c);case"CylinderGeometry":case"CylinderBufferGeometry":return function(n){var r=n.metadata?n.metadata.parameters:n.parameters,i=new e.Cylinder(r.radiusTop,r.radiusBottom,r.height,r.radialSegments);return i._type=e.Shape.types.CYLINDER,i.radiusTop=r.radiusTop,i.radiusBottom=r.radiusBottom,i.height=r.height,i.numSegments=r.radialSegments,i.orientation=new e.Quaternion,i.orientation.setFromEuler(t.Math.degToRad(-90),0,0,"XYZ").normalize(),i}(c);case"PlaneGeometry":case"PlaneBufferGeometry":return function(t){t.computeBoundingBox();var n=t.boundingBox;return new e.Box(new e.Vec3((n.max.x-n.min.x)/2||.1,(n.max.y-n.min.y)/2||.1,(n.max.z-n.min.z)/2||.1))}(c);case"SphereGeometry":case"SphereBufferGeometry":return function(t){return new e.Sphere((t.metadata?t.metadata.parameters:t.parameters).radius)}(c);case"TubeGeometry":case"Geometry":case"BufferGeometry":return s(o);default:return console.warn('Unrecognized geometry: "%s". Using bounding box as shape.',c.type),a(c)}};function a(t){if(!h(t).length)return null;t.computeBoundingBox();var n=t.boundingBox;return new e.Box(new e.Vec3((n.max.x-n.min.x)/2,(n.max.y-n.min.y)/2,(n.max.z-n.min.z)/2))}function s(n){var r=n.clone();r.quaternion.set(0,0,0,1),r.updateMatrixWorld();var i=(new t.Box3).setFromObject(r);if(!isFinite(i.min.lengthSq()))return null;var o=new e.Box(new e.Vec3((i.max.x-i.min.x)/2,(i.max.y-i.min.y)/2,(i.max.z-i.min.z)/2)),a=i.translate(r.position.negate()).getCenter(new t.Vector3);return a.lengthSq()&&(o.offset=a),o}function u(e){var n,r=function(e){var t=[];return e.traverse(function(e){"Mesh"===e.type&&t.push(e)}),t}(e),i=new t.Geometry,o=new t.Geometry;if(0===r.length)return null;if(1===r.length){var a=new t.Vector3,s=new t.Quaternion,u=new t.Vector3;return r[0].geometry.isBufferGeometry?r[0].geometry.attributes.position&&r[0].geometry.attributes.position.itemSize>2&&i.fromBufferGeometry(r[0].geometry):i=r[0].geometry.clone(),i.metadata=r[0].geometry.metadata,r[0].updateMatrixWorld(),r[0].matrixWorld.decompose(a,s,u),i.scale(u.x,u.y,u.z)}for(;n=r.pop();)if(n.updateMatrixWorld(),n.geometry.isBufferGeometry){if(n.geometry.attributes.position&&n.geometry.attributes.position.itemSize>2){var h=new t.Geometry;h.fromBufferGeometry(n.geometry),o.merge(h,n.matrixWorld),h.dispose()}}else o.merge(n.geometry,n.matrixWorld);var l=new t.Matrix4;return l.scale(e.scale),o.applyMatrix(l),o}function h(e){return e.attributes||(e=(new t.BufferGeometry).fromGeometry(e)),(e.attributes.position||{}).array||[]}o.Type=i,exports.threeToCannon=o;
//# sourceMappingURL=three-to-cannon.js.map

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

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};
import{Sphere as e,Box as t,Vec3 as n,ConvexPolyhedron as i,Cylinder as r,Shape as s,Quaternion as o,Trimesh as a}from"cannon-es";import{Vector3 as u,Line3 as h,Plane as l,Triangle as c,Box3 as d,Mesh as m,Math as f,Geometry as p,Quaternion as v,Matrix4 as g,BufferGeometry as x}from"three";var y=function(){var e,t,n,i,r=new u;function s(){this.tolerance=-1,this.faces=[],this.newFaces=[],this.assigned=new m,this.unassigned=new m,this.vertices=[]}function o(){this.normal=new u,this.midpoint=new u,this.area=0,this.constant=0,this.outside=null,this.mark=0,this.edge=null}function a(e,t){this.vertex=e,this.prev=null,this.next=null,this.twin=null,this.face=t}function d(e){this.point=e,this.prev=null,this.next=null,this.face=null}function m(){this.head=null,this.tail=null}return Object.assign(s.prototype,{setFromPoints:function(e){!0!==Array.isArray(e)&&console.error("THREE.ConvexHull: Points parameter is not an array."),e.length<4&&console.error("THREE.ConvexHull: The algorithm needs at least four points."),this.makeEmpty();for(var t=0,n=e.length;t<n;t++)this.vertices.push(new d(e[t]));return this.compute(),this},setFromObject:function(e){var t=[];return e.updateMatrixWorld(!0),e.traverse(function(e){var n,i,r,s=e.geometry;if(void 0!==s)if(s.isGeometry){var o=s.vertices;for(n=0,i=o.length;n<i;n++)(r=o[n].clone()).applyMatrix4(e.matrixWorld),t.push(r)}else if(s.isBufferGeometry){var a=s.attributes.position;if(void 0!==a)for(n=0,i=a.count;n<i;n++)(r=new u).fromBufferAttribute(a,n).applyMatrix4(e.matrixWorld),t.push(r)}}),this.setFromPoints(t)},containsPoint:function(e){for(var t=this.faces,n=0,i=t.length;n<i;n++)if(t[n].distanceToPoint(e)>this.tolerance)return!1;return!0},intersectRay:function(e,t){for(var n=this.faces,i=-Infinity,r=Infinity,s=0,o=n.length;s<o;s++){var a=n[s],u=a.distanceToPoint(e.origin),h=a.normal.dot(e.direction);if(u>0&&h>=0)return null;var l=0!==h?-u/h:0;if(!(l<=0)&&(h>0?r=Math.min(l,r):i=Math.max(l,i),i>r))return null}return e.at(-Infinity!==i?i:r,t),t},intersectsRay:function(e){return null!==this.intersectRay(e,r)},makeEmpty:function(){return this.faces=[],this.vertices=[],this},addVertexToFace:function(e,t){return e.face=t,null===t.outside?this.assigned.append(e):this.assigned.insertBefore(t.outside,e),t.outside=e,this},removeVertexFromFace:function(e,t){return e===t.outside&&(t.outside=null!==e.next&&e.next.face===t?e.next:null),this.assigned.remove(e),this},removeAllVerticesFromFace:function(e){if(null!==e.outside){for(var t=e.outside,n=e.outside;null!==n.next&&n.next.face===e;)n=n.next;return this.assigned.removeSubList(t,n),t.prev=n.next=null,e.outside=null,t}},deleteFaceVertices:function(e,t){var n=this.removeAllVerticesFromFace(e);if(void 0!==n)if(void 0===t)this.unassigned.appendChain(n);else{var i=n;do{var r=i.next;t.distanceToPoint(i.point)>this.tolerance?this.addVertexToFace(i,t):this.unassigned.append(i),i=r}while(null!==i)}return this},resolveUnassignedPoints:function(e){if(!1===this.unassigned.isEmpty()){var t=this.unassigned.first();do{for(var n=t.next,i=this.tolerance,r=null,s=0;s<e.length;s++){var o=e[s];if(0===o.mark){var a=o.distanceToPoint(t.point);if(a>i&&(i=a,r=o),i>1e3*this.tolerance)break}}null!==r&&this.addVertexToFace(t,r),t=n}while(null!==t)}return this},computeExtremes:function(){var e,t,n,i=new u,r=new u,s=[],o=[];for(e=0;e<3;e++)s[e]=o[e]=this.vertices[0];for(i.copy(this.vertices[0].point),r.copy(this.vertices[0].point),e=0,t=this.vertices.length;e<t;e++){var a=this.vertices[e],h=a.point;for(n=0;n<3;n++)h.getComponent(n)<i.getComponent(n)&&(i.setComponent(n,h.getComponent(n)),s[n]=a);for(n=0;n<3;n++)h.getComponent(n)>r.getComponent(n)&&(r.setComponent(n,h.getComponent(n)),o[n]=a)}return this.tolerance=3*Number.EPSILON*(Math.max(Math.abs(i.x),Math.abs(r.x))+Math.max(Math.abs(i.y),Math.abs(r.y))+Math.max(Math.abs(i.z),Math.abs(r.z))),{min:s,max:o}},computeInitialHull:function(){void 0===e&&(e=new h,t=new l,n=new u);var i,r,s,a,c,d,m,f,p,v=this.vertices,g=this.computeExtremes(),x=g.min,y=g.max,w=0,T=0;for(d=0;d<3;d++)(p=y[d].point.getComponent(d)-x[d].point.getComponent(d))>w&&(w=p,T=d);for(w=0,e.set((r=x[T]).point,(s=y[T]).point),d=0,m=this.vertices.length;d<m;d++)(i=v[d])!==r&&i!==s&&(e.closestPointToPoint(i.point,!0,n),(p=n.distanceToSquared(i.point))>w&&(w=p,a=i));for(w=-1,t.setFromCoplanarPoints(r.point,s.point,a.point),d=0,m=this.vertices.length;d<m;d++)(i=v[d])!==r&&i!==s&&i!==a&&(p=Math.abs(t.distanceToPoint(i.point)))>w&&(w=p,c=i);var E=[];if(t.distanceToPoint(c.point)<0)for(E.push(o.create(r,s,a),o.create(c,s,r),o.create(c,a,s),o.create(c,r,a)),d=0;d<3;d++)f=(d+1)%3,E[d+1].getEdge(2).setTwin(E[0].getEdge(f)),E[d+1].getEdge(1).setTwin(E[f+1].getEdge(0));else for(E.push(o.create(r,a,s),o.create(c,r,s),o.create(c,s,a),o.create(c,a,r)),d=0;d<3;d++)f=(d+1)%3,E[d+1].getEdge(2).setTwin(E[0].getEdge((3-d)%3)),E[d+1].getEdge(0).setTwin(E[f+1].getEdge(1));for(d=0;d<4;d++)this.faces.push(E[d]);for(d=0,m=v.length;d<m;d++)if((i=v[d])!==r&&i!==s&&i!==a&&i!==c){w=this.tolerance;var b=null;for(f=0;f<4;f++)(p=this.faces[f].distanceToPoint(i.point))>w&&(w=p,b=this.faces[f]);null!==b&&this.addVertexToFace(i,b)}return this},reindexFaces:function(){for(var e=[],t=0;t<this.faces.length;t++){var n=this.faces[t];0===n.mark&&e.push(n)}return this.faces=e,this},nextVertexToAdd:function(){if(!1===this.assigned.isEmpty()){var e,t=0,n=this.assigned.first().face,i=n.outside;do{var r=n.distanceToPoint(i.point);r>t&&(t=r,e=i),i=i.next}while(null!==i&&i.face===n);return e}},computeHorizon:function(e,t,n,i){var r;this.deleteFaceVertices(n),n.mark=1,r=null===t?t=n.getEdge(0):t.next;do{var s=r.twin,o=s.face;0===o.mark&&(o.distanceToPoint(e)>this.tolerance?this.computeHorizon(e,s,o,i):i.push(r)),r=r.next}while(r!==t);return this},addAdjoiningFace:function(e,t){var n=o.create(e,t.tail(),t.head());return this.faces.push(n),n.getEdge(-1).setTwin(t.twin),n.getEdge(0)},addNewFaces:function(e,t){this.newFaces=[];for(var n=null,i=null,r=0;r<t.length;r++){var s=this.addAdjoiningFace(e,t[r]);null===n?n=s:s.next.setTwin(i),this.newFaces.push(s.face),i=s}return n.next.setTwin(i),this},addVertexToHull:function(e){var t=[];return this.unassigned.clear(),this.removeVertexFromFace(e,e.face),this.computeHorizon(e.point,null,e.face,t),this.addNewFaces(e,t),this.resolveUnassignedPoints(this.newFaces),this},cleanup:function(){return this.assigned.clear(),this.unassigned.clear(),this.newFaces=[],this},compute:function(){var e;for(this.computeInitialHull();void 0!==(e=this.nextVertexToAdd());)this.addVertexToHull(e);return this.reindexFaces(),this.cleanup(),this}}),Object.assign(o,{create:function(e,t,n){var i=new o,r=new a(e,i),s=new a(t,i),u=new a(n,i);return r.next=u.prev=s,s.next=r.prev=u,u.next=s.prev=r,i.edge=r,i.compute()}}),Object.assign(o.prototype,{getEdge:function(e){for(var t=this.edge;e>0;)t=t.next,e--;for(;e<0;)t=t.prev,e++;return t},compute:function(){void 0===i&&(i=new c);var e=this.edge.tail(),t=this.edge.head(),n=this.edge.next.head();return i.set(e.point,t.point,n.point),i.getNormal(this.normal),i.getMidpoint(this.midpoint),this.area=i.getArea(),this.constant=this.normal.dot(this.midpoint),this},distanceToPoint:function(e){return this.normal.dot(e)-this.constant}}),Object.assign(a.prototype,{head:function(){return this.vertex},tail:function(){return this.prev?this.prev.vertex:null},length:function(){var e=this.head(),t=this.tail();return null!==t?t.point.distanceTo(e.point):-1},lengthSquared:function(){var e=this.head(),t=this.tail();return null!==t?t.point.distanceToSquared(e.point):-1},setTwin:function(e){return this.twin=e,e.twin=this,this}}),Object.assign(m.prototype,{first:function(){return this.head},last:function(){return this.tail},clear:function(){return this.head=this.tail=null,this},insertBefore:function(e,t){return t.prev=e.prev,t.next=e,null===t.prev?this.head=t:t.prev.next=t,e.prev=t,this},insertAfter:function(e,t){return t.prev=e,t.next=e.next,null===t.next?this.tail=t:t.next.prev=t,e.next=t,this},append:function(e){return null===this.head?this.head=e:this.tail.next=e,e.prev=this.tail,e.next=null,this.tail=e,this},appendChain:function(e){for(null===this.head?this.head=e:this.tail.next=e,e.prev=this.tail;null!==e.next;)e=e.next;return this.tail=e,this},remove:function(e){return null===e.prev?this.head=e.next:e.prev.next=e.next,null===e.next?this.tail=e.prev:e.next.prev=e.prev,this},removeSubList:function(e,t){return null===e.prev?this.head=t.next:e.prev.next=t.next,null===t.next?this.tail=e.prev:t.next.prev=e.prev,this},isEmpty:function(){return null===this.head}}),s}(),w=Math.PI/2,T={BOX:"Box",CYLINDER:"Cylinder",SPHERE:"Sphere",HULL:"ConvexPolyhedron",MESH:"Trimesh"};const E=function(u,h){var l;if((h=h||{}).type===T.BOX)return F(u);if(h.type===T.CYLINDER)return function(e,t){var n=["x","y","z"],i=t.cylinderAxis||"y",a=n.splice(n.indexOf(i),1)&&n,u=(new d).setFromObject(e);if(!isFinite(u.min.lengthSq()))return null;var h=u.max[i]-u.min[i],l=.5*Math.max(u.max[a[0]]-u.min[a[0]],u.max[a[1]]-u.min[a[1]]),c=new r(l,l,h,12);return c._type=s.types.CYLINDER,c.radiusTop=l,c.radiusBottom=l,c.height=h,c.numSegments=12,c.orientation=new o,c.orientation.setFromEuler("y"===i?w:0,"z"===i?w:0,0,"XYZ").normalize(),c}(u,h);if(h.type===T.SPHERE)return function(t,n){if(n.sphereRadius)return new e(n.sphereRadius);var i=B(t);return i?(i.computeBoundingSphere(),new e(i.boundingSphere.radius)):null}(u,h);if(h.type===T.HULL)return function(e){var t=B(e);if(!t||!t.vertices.length)return null;for(var r=0;r<t.vertices.length;r++)t.vertices[r].x+=1e-4*(Math.random()-.5),t.vertices[r].y+=1e-4*(Math.random()-.5),t.vertices[r].z+=1e-4*(Math.random()-.5);var s=(new y).setFromObject(new m(t)).faces,o=[],a=[];for(r=0;r<s.length;r++){var u=s[r],h=u.edge;do{var l=h.head().point;o.push(new n(l.x,l.y,l.z)),a.push(new n(u.normal.x,u.normal.y,u.normal.z)),h=h.next}while(h!==u.edge)}return new i({vertices:o,normals:a})}(u);if(h.type===T.MESH)return(l=B(u))?function(e){var t=M(e);if(!t.length)return null;var n=Object.keys(t).map(Number);return new a(t,n)}(l):null;if(h.type)throw new Error('[CANNON.threeToCannon] Invalid type "%s".',h.type);if(!(l=B(u)))return null;switch(l.metadata?l.metadata.type:l.type){case"BoxGeometry":case"BoxBufferGeometry":return b(l);case"CylinderGeometry":case"CylinderBufferGeometry":return function(e){var t=e.metadata?e.metadata.parameters:e.parameters,n=new r(t.radiusTop,t.radiusBottom,t.height,t.radialSegments);return n._type=s.types.CYLINDER,n.radiusTop=t.radiusTop,n.radiusBottom=t.radiusBottom,n.height=t.height,n.numSegments=t.radialSegments,n.orientation=new o,n.orientation.setFromEuler(f.degToRad(-90),0,0,"XYZ").normalize(),n}(l);case"PlaneGeometry":case"PlaneBufferGeometry":return function(e){e.computeBoundingBox();var i=e.boundingBox;return new t(new n((i.max.x-i.min.x)/2||.1,(i.max.y-i.min.y)/2||.1,(i.max.z-i.min.z)/2||.1))}(l);case"SphereGeometry":case"SphereBufferGeometry":return function(t){return new e((t.metadata?t.metadata.parameters:t.parameters).radius)}(l);case"TubeGeometry":case"Geometry":case"BufferGeometry":return F(u);default:return console.warn('Unrecognized geometry: "%s". Using bounding box as shape.',l.type),b(l)}};function b(e){if(!M(e).length)return null;e.computeBoundingBox();var i=e.boundingBox;return new t(new n((i.max.x-i.min.x)/2,(i.max.y-i.min.y)/2,(i.max.z-i.min.z)/2))}function F(e){var i=e.clone();i.quaternion.set(0,0,0,1),i.updateMatrixWorld();var r=(new d).setFromObject(i);if(!isFinite(r.min.lengthSq()))return null;var s=new t(new n((r.max.x-r.min.x)/2,(r.max.y-r.min.y)/2,(r.max.z-r.min.z)/2)),o=r.translate(i.position.negate()).getCenter(new u);return o.lengthSq()&&(s.offset=o),s}function B(e){var t,n=function(e){var t=[];return e.traverse(function(e){"Mesh"===e.type&&t.push(e)}),t}(e),i=new p,r=new p;if(0===n.length)return null;if(1===n.length){var s=new u,o=new v,a=new u;return n[0].geometry.isBufferGeometry?n[0].geometry.attributes.position&&n[0].geometry.attributes.position.itemSize>2&&i.fromBufferGeometry(n[0].geometry):i=n[0].geometry.clone(),i.metadata=n[0].geometry.metadata,n[0].updateMatrixWorld(),n[0].matrixWorld.decompose(s,o,a),i.scale(a.x,a.y,a.z)}for(;t=n.pop();)if(t.updateMatrixWorld(),t.geometry.isBufferGeometry){if(t.geometry.attributes.position&&t.geometry.attributes.position.itemSize>2){var h=new p;h.fromBufferGeometry(t.geometry),r.merge(h,t.matrixWorld),h.dispose()}}else r.merge(t.geometry,t.matrixWorld);var l=new g;return l.scale(e.scale),r.applyMatrix(l),r}function M(e){return e.attributes||(e=(new x).fromGeometry(e)),(e.attributes.position||{}).array||[]}E.Type=T;export{E as threeToCannon};
//# sourceMappingURL=three-to-cannon.modern.js.map

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

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};
import{Sphere as e,Box as t,Vec3 as n,ConvexPolyhedron as i,Cylinder as r,Shape as s,Quaternion as a,Trimesh as o}from"cannon-es";import{Vector3 as u,Line3 as h,Plane as l,Triangle as c,Box3 as d,Mesh as m,Math as f,Geometry as p,Quaternion as v,Matrix4 as g,BufferGeometry as x}from"three";var y=function(){var e,t,n,i,r=new u;function s(){this.tolerance=-1,this.faces=[],this.newFaces=[],this.assigned=new m,this.unassigned=new m,this.vertices=[]}function a(){this.normal=new u,this.midpoint=new u,this.area=0,this.constant=0,this.outside=null,this.mark=0,this.edge=null}function o(e,t){this.vertex=e,this.prev=null,this.next=null,this.twin=null,this.face=t}function d(e){this.point=e,this.prev=null,this.next=null,this.face=null}function m(){this.head=null,this.tail=null}return Object.assign(s.prototype,{setFromPoints:function(e){!0!==Array.isArray(e)&&console.error("THREE.ConvexHull: Points parameter is not an array."),e.length<4&&console.error("THREE.ConvexHull: The algorithm needs at least four points."),this.makeEmpty();for(var t=0,n=e.length;t<n;t++)this.vertices.push(new d(e[t]));return this.compute(),this},setFromObject:function(e){var t=[];return e.updateMatrixWorld(!0),e.traverse(function(e){var n,i,r,s=e.geometry;if(void 0!==s)if(s.isGeometry){var a=s.vertices;for(n=0,i=a.length;n<i;n++)(r=a[n].clone()).applyMatrix4(e.matrixWorld),t.push(r)}else if(s.isBufferGeometry){var o=s.attributes.position;if(void 0!==o)for(n=0,i=o.count;n<i;n++)(r=new u).fromBufferAttribute(o,n).applyMatrix4(e.matrixWorld),t.push(r)}}),this.setFromPoints(t)},containsPoint:function(e){for(var t=this.faces,n=0,i=t.length;n<i;n++)if(t[n].distanceToPoint(e)>this.tolerance)return!1;return!0},intersectRay:function(e,t){for(var n=this.faces,i=-Infinity,r=Infinity,s=0,a=n.length;s<a;s++){var o=n[s],u=o.distanceToPoint(e.origin),h=o.normal.dot(e.direction);if(u>0&&h>=0)return null;var l=0!==h?-u/h:0;if(!(l<=0)&&(h>0?r=Math.min(l,r):i=Math.max(l,i),i>r))return null}return e.at(-Infinity!==i?i:r,t),t},intersectsRay:function(e){return null!==this.intersectRay(e,r)},makeEmpty:function(){return this.faces=[],this.vertices=[],this},addVertexToFace:function(e,t){return e.face=t,null===t.outside?this.assigned.append(e):this.assigned.insertBefore(t.outside,e),t.outside=e,this},removeVertexFromFace:function(e,t){return e===t.outside&&(t.outside=null!==e.next&&e.next.face===t?e.next:null),this.assigned.remove(e),this},removeAllVerticesFromFace:function(e){if(null!==e.outside){for(var t=e.outside,n=e.outside;null!==n.next&&n.next.face===e;)n=n.next;return this.assigned.removeSubList(t,n),t.prev=n.next=null,e.outside=null,t}},deleteFaceVertices:function(e,t){var n=this.removeAllVerticesFromFace(e);if(void 0!==n)if(void 0===t)this.unassigned.appendChain(n);else{var i=n;do{var r=i.next;t.distanceToPoint(i.point)>this.tolerance?this.addVertexToFace(i,t):this.unassigned.append(i),i=r}while(null!==i)}return this},resolveUnassignedPoints:function(e){if(!1===this.unassigned.isEmpty()){var t=this.unassigned.first();do{for(var n=t.next,i=this.tolerance,r=null,s=0;s<e.length;s++){var a=e[s];if(0===a.mark){var o=a.distanceToPoint(t.point);if(o>i&&(i=o,r=a),i>1e3*this.tolerance)break}}null!==r&&this.addVertexToFace(t,r),t=n}while(null!==t)}return this},computeExtremes:function(){var e,t,n,i=new u,r=new u,s=[],a=[];for(e=0;e<3;e++)s[e]=a[e]=this.vertices[0];for(i.copy(this.vertices[0].point),r.copy(this.vertices[0].point),e=0,t=this.vertices.length;e<t;e++){var o=this.vertices[e],h=o.point;for(n=0;n<3;n++)h.getComponent(n)<i.getComponent(n)&&(i.setComponent(n,h.getComponent(n)),s[n]=o);for(n=0;n<3;n++)h.getComponent(n)>r.getComponent(n)&&(r.setComponent(n,h.getComponent(n)),a[n]=o)}return this.tolerance=3*Number.EPSILON*(Math.max(Math.abs(i.x),Math.abs(r.x))+Math.max(Math.abs(i.y),Math.abs(r.y))+Math.max(Math.abs(i.z),Math.abs(r.z))),{min:s,max:a}},computeInitialHull:function(){void 0===e&&(e=new h,t=new l,n=new u);var i,r,s,o,c,d,m,f,p,v=this.vertices,g=this.computeExtremes(),x=g.min,y=g.max,w=0,T=0;for(d=0;d<3;d++)(p=y[d].point.getComponent(d)-x[d].point.getComponent(d))>w&&(w=p,T=d);for(w=0,e.set((r=x[T]).point,(s=y[T]).point),d=0,m=this.vertices.length;d<m;d++)(i=v[d])!==r&&i!==s&&(e.closestPointToPoint(i.point,!0,n),(p=n.distanceToSquared(i.point))>w&&(w=p,o=i));for(w=-1,t.setFromCoplanarPoints(r.point,s.point,o.point),d=0,m=this.vertices.length;d<m;d++)(i=v[d])!==r&&i!==s&&i!==o&&(p=Math.abs(t.distanceToPoint(i.point)))>w&&(w=p,c=i);var E=[];if(t.distanceToPoint(c.point)<0)for(E.push(a.create(r,s,o),a.create(c,s,r),a.create(c,o,s),a.create(c,r,o)),d=0;d<3;d++)f=(d+1)%3,E[d+1].getEdge(2).setTwin(E[0].getEdge(f)),E[d+1].getEdge(1).setTwin(E[f+1].getEdge(0));else for(E.push(a.create(r,o,s),a.create(c,r,s),a.create(c,s,o),a.create(c,o,r)),d=0;d<3;d++)f=(d+1)%3,E[d+1].getEdge(2).setTwin(E[0].getEdge((3-d)%3)),E[d+1].getEdge(0).setTwin(E[f+1].getEdge(1));for(d=0;d<4;d++)this.faces.push(E[d]);for(d=0,m=v.length;d<m;d++)if((i=v[d])!==r&&i!==s&&i!==o&&i!==c){w=this.tolerance;var b=null;for(f=0;f<4;f++)(p=this.faces[f].distanceToPoint(i.point))>w&&(w=p,b=this.faces[f]);null!==b&&this.addVertexToFace(i,b)}return this},reindexFaces:function(){for(var e=[],t=0;t<this.faces.length;t++){var n=this.faces[t];0===n.mark&&e.push(n)}return this.faces=e,this},nextVertexToAdd:function(){if(!1===this.assigned.isEmpty()){var e,t=0,n=this.assigned.first().face,i=n.outside;do{var r=n.distanceToPoint(i.point);r>t&&(t=r,e=i),i=i.next}while(null!==i&&i.face===n);return e}},computeHorizon:function(e,t,n,i){var r;this.deleteFaceVertices(n),n.mark=1,r=null===t?t=n.getEdge(0):t.next;do{var s=r.twin,a=s.face;0===a.mark&&(a.distanceToPoint(e)>this.tolerance?this.computeHorizon(e,s,a,i):i.push(r)),r=r.next}while(r!==t);return this},addAdjoiningFace:function(e,t){var n=a.create(e,t.tail(),t.head());return this.faces.push(n),n.getEdge(-1).setTwin(t.twin),n.getEdge(0)},addNewFaces:function(e,t){this.newFaces=[];for(var n=null,i=null,r=0;r<t.length;r++){var s=this.addAdjoiningFace(e,t[r]);null===n?n=s:s.next.setTwin(i),this.newFaces.push(s.face),i=s}return n.next.setTwin(i),this},addVertexToHull:function(e){var t=[];return this.unassigned.clear(),this.removeVertexFromFace(e,e.face),this.computeHorizon(e.point,null,e.face,t),this.addNewFaces(e,t),this.resolveUnassignedPoints(this.newFaces),this},cleanup:function(){return this.assigned.clear(),this.unassigned.clear(),this.newFaces=[],this},compute:function(){var e;for(this.computeInitialHull();void 0!==(e=this.nextVertexToAdd());)this.addVertexToHull(e);return this.reindexFaces(),this.cleanup(),this}}),Object.assign(a,{create:function(e,t,n){var i=new a,r=new o(e,i),s=new o(t,i),u=new o(n,i);return r.next=u.prev=s,s.next=r.prev=u,u.next=s.prev=r,i.edge=r,i.compute()}}),Object.assign(a.prototype,{getEdge:function(e){for(var t=this.edge;e>0;)t=t.next,e--;for(;e<0;)t=t.prev,e++;return t},compute:function(){void 0===i&&(i=new c);var e=this.edge.tail(),t=this.edge.head(),n=this.edge.next.head();return i.set(e.point,t.point,n.point),i.getNormal(this.normal),i.getMidpoint(this.midpoint),this.area=i.getArea(),this.constant=this.normal.dot(this.midpoint),this},distanceToPoint:function(e){return this.normal.dot(e)-this.constant}}),Object.assign(o.prototype,{head:function(){return this.vertex},tail:function(){return this.prev?this.prev.vertex:null},length:function(){var e=this.head(),t=this.tail();return null!==t?t.point.distanceTo(e.point):-1},lengthSquared:function(){var e=this.head(),t=this.tail();return null!==t?t.point.distanceToSquared(e.point):-1},setTwin:function(e){return this.twin=e,e.twin=this,this}}),Object.assign(m.prototype,{first:function(){return this.head},last:function(){return this.tail},clear:function(){return this.head=this.tail=null,this},insertBefore:function(e,t){return t.prev=e.prev,t.next=e,null===t.prev?this.head=t:t.prev.next=t,e.prev=t,this},insertAfter:function(e,t){return t.prev=e,t.next=e.next,null===t.next?this.tail=t:t.next.prev=t,e.next=t,this},append:function(e){return null===this.head?this.head=e:this.tail.next=e,e.prev=this.tail,e.next=null,this.tail=e,this},appendChain:function(e){for(null===this.head?this.head=e:this.tail.next=e,e.prev=this.tail;null!==e.next;)e=e.next;return this.tail=e,this},remove:function(e){return null===e.prev?this.head=e.next:e.prev.next=e.next,null===e.next?this.tail=e.prev:e.next.prev=e.prev,this},removeSubList:function(e,t){return null===e.prev?this.head=t.next:e.prev.next=t.next,null===t.next?this.tail=e.prev:t.next.prev=e.prev,this},isEmpty:function(){return null===this.head}}),s}(),w=Math.PI/2,T={BOX:"Box",CYLINDER:"Cylinder",SPHERE:"Sphere",HULL:"ConvexPolyhedron",MESH:"Trimesh"},E=function(u,h){var l;if((h=h||{}).type===T.BOX)return F(u);if(h.type===T.CYLINDER)return function(e,t){var n=["x","y","z"],i=t.cylinderAxis||"y",o=n.splice(n.indexOf(i),1)&&n,u=(new d).setFromObject(e);if(!isFinite(u.min.lengthSq()))return null;var h=u.max[i]-u.min[i],l=.5*Math.max(u.max[o[0]]-u.min[o[0]],u.max[o[1]]-u.min[o[1]]),c=new r(l,l,h,12);return c._type=s.types.CYLINDER,c.radiusTop=l,c.radiusBottom=l,c.height=h,c.numSegments=12,c.orientation=new a,c.orientation.setFromEuler("y"===i?w:0,"z"===i?w:0,0,"XYZ").normalize(),c}(u,h);if(h.type===T.SPHERE)return function(t,n){if(n.sphereRadius)return new e(n.sphereRadius);var i=B(t);return i?(i.computeBoundingSphere(),new e(i.boundingSphere.radius)):null}(u,h);if(h.type===T.HULL)return function(e){var t=B(e);if(!t||!t.vertices.length)return null;for(var r=0;r<t.vertices.length;r++)t.vertices[r].x+=1e-4*(Math.random()-.5),t.vertices[r].y+=1e-4*(Math.random()-.5),t.vertices[r].z+=1e-4*(Math.random()-.5);var s=(new y).setFromObject(new m(t)).faces,a=[],o=[];for(r=0;r<s.length;r++){var u=s[r],h=u.edge;do{var l=h.head().point;a.push(new n(l.x,l.y,l.z)),o.push(new n(u.normal.x,u.normal.y,u.normal.z)),h=h.next}while(h!==u.edge)}return new i({vertices:a,normals:o})}(u);if(h.type===T.MESH)return(l=B(u))?function(e){var t=M(e);if(!t.length)return null;var n=Object.keys(t).map(Number);return new o(t,n)}(l):null;if(h.type)throw new Error('[CANNON.threeToCannon] Invalid type "%s".',h.type);if(!(l=B(u)))return null;switch(l.metadata?l.metadata.type:l.type){case"BoxGeometry":case"BoxBufferGeometry":return b(l);case"CylinderGeometry":case"CylinderBufferGeometry":return function(e){var t=e.metadata?e.metadata.parameters:e.parameters,n=new r(t.radiusTop,t.radiusBottom,t.height,t.radialSegments);return n._type=s.types.CYLINDER,n.radiusTop=t.radiusTop,n.radiusBottom=t.radiusBottom,n.height=t.height,n.numSegments=t.radialSegments,n.orientation=new a,n.orientation.setFromEuler(f.degToRad(-90),0,0,"XYZ").normalize(),n}(l);case"PlaneGeometry":case"PlaneBufferGeometry":return function(e){e.computeBoundingBox();var i=e.boundingBox;return new t(new n((i.max.x-i.min.x)/2||.1,(i.max.y-i.min.y)/2||.1,(i.max.z-i.min.z)/2||.1))}(l);case"SphereGeometry":case"SphereBufferGeometry":return function(t){return new e((t.metadata?t.metadata.parameters:t.parameters).radius)}(l);case"TubeGeometry":case"Geometry":case"BufferGeometry":return F(u);default:return console.warn('Unrecognized geometry: "%s". Using bounding box as shape.',l.type),b(l)}};function b(e){if(!M(e).length)return null;e.computeBoundingBox();var i=e.boundingBox;return new t(new n((i.max.x-i.min.x)/2,(i.max.y-i.min.y)/2,(i.max.z-i.min.z)/2))}function F(e){var i=e.clone();i.quaternion.set(0,0,0,1),i.updateMatrixWorld();var r=(new d).setFromObject(i);if(!isFinite(r.min.lengthSq()))return null;var s=new t(new n((r.max.x-r.min.x)/2,(r.max.y-r.min.y)/2,(r.max.z-r.min.z)/2)),a=r.translate(i.position.negate()).getCenter(new u);return a.lengthSq()&&(s.offset=a),s}function B(e){var t,n=function(e){var t=[];return e.traverse(function(e){"Mesh"===e.type&&t.push(e)}),t}(e),i=new p,r=new p;if(0===n.length)return null;if(1===n.length){var s=new u,a=new v,o=new u;return n[0].geometry.isBufferGeometry?n[0].geometry.attributes.position&&n[0].geometry.attributes.position.itemSize>2&&i.fromBufferGeometry(n[0].geometry):i=n[0].geometry.clone(),i.metadata=n[0].geometry.metadata,n[0].updateMatrixWorld(),n[0].matrixWorld.decompose(s,a,o),i.scale(o.x,o.y,o.z)}for(;t=n.pop();)if(t.updateMatrixWorld(),t.geometry.isBufferGeometry){if(t.geometry.attributes.position&&t.geometry.attributes.position.itemSize>2){var h=new p;h.fromBufferGeometry(t.geometry),r.merge(h,t.matrixWorld),h.dispose()}}else r.merge(t.geometry,t.matrixWorld);var l=new g;return l.scale(e.scale),r.applyMatrix(l),r}function M(e){return e.attributes||(e=(new x).fromGeometry(e)),(e.attributes.position||{}).array||[]}E.Type=T;export{E as threeToCannon};
//# sourceMappingURL=three-to-cannon.module.js.map

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

!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});
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("cannon-es"),require("three")):"function"==typeof define&&define.amd?define(["exports","cannon-es","three"],t):t((e=e||self).threeToCannon={},e.cannonEs,e.THREE)}(this,function(e,t,n){var r=function(){var e,t,r,i,o=new n.Vector3;function a(){this.tolerance=-1,this.faces=[],this.newFaces=[],this.assigned=new l,this.unassigned=new l,this.vertices=[]}function s(){this.normal=new n.Vector3,this.midpoint=new n.Vector3,this.area=0,this.constant=0,this.outside=null,this.mark=0,this.edge=null}function u(e,t){this.vertex=e,this.prev=null,this.next=null,this.twin=null,this.face=t}function h(e){this.point=e,this.prev=null,this.next=null,this.face=null}function l(){this.head=null,this.tail=null}return Object.assign(a.prototype,{setFromPoints:function(e){!0!==Array.isArray(e)&&console.error("THREE.ConvexHull: Points parameter is not an array."),e.length<4&&console.error("THREE.ConvexHull: The algorithm needs at least four points."),this.makeEmpty();for(var t=0,n=e.length;t<n;t++)this.vertices.push(new h(e[t]));return this.compute(),this},setFromObject:function(e){var t=[];return e.updateMatrixWorld(!0),e.traverse(function(e){var r,i,o,a=e.geometry;if(void 0!==a)if(a.isGeometry){var s=a.vertices;for(r=0,i=s.length;r<i;r++)(o=s[r].clone()).applyMatrix4(e.matrixWorld),t.push(o)}else if(a.isBufferGeometry){var u=a.attributes.position;if(void 0!==u)for(r=0,i=u.count;r<i;r++)(o=new n.Vector3).fromBufferAttribute(u,r).applyMatrix4(e.matrixWorld),t.push(o)}}),this.setFromPoints(t)},containsPoint:function(e){for(var t=this.faces,n=0,r=t.length;n<r;n++)if(t[n].distanceToPoint(e)>this.tolerance)return!1;return!0},intersectRay:function(e,t){for(var n=this.faces,r=-Infinity,i=Infinity,o=0,a=n.length;o<a;o++){var s=n[o],u=s.distanceToPoint(e.origin),h=s.normal.dot(e.direction);if(u>0&&h>=0)return null;var l=0!==h?-u/h:0;if(!(l<=0)&&(h>0?i=Math.min(l,i):r=Math.max(l,r),r>i))return null}return e.at(-Infinity!==r?r:i,t),t},intersectsRay:function(e){return null!==this.intersectRay(e,o)},makeEmpty:function(){return this.faces=[],this.vertices=[],this},addVertexToFace:function(e,t){return e.face=t,null===t.outside?this.assigned.append(e):this.assigned.insertBefore(t.outside,e),t.outside=e,this},removeVertexFromFace:function(e,t){return e===t.outside&&(t.outside=null!==e.next&&e.next.face===t?e.next:null),this.assigned.remove(e),this},removeAllVerticesFromFace:function(e){if(null!==e.outside){for(var t=e.outside,n=e.outside;null!==n.next&&n.next.face===e;)n=n.next;return this.assigned.removeSubList(t,n),t.prev=n.next=null,e.outside=null,t}},deleteFaceVertices:function(e,t){var n=this.removeAllVerticesFromFace(e);if(void 0!==n)if(void 0===t)this.unassigned.appendChain(n);else{var r=n;do{var i=r.next;t.distanceToPoint(r.point)>this.tolerance?this.addVertexToFace(r,t):this.unassigned.append(r),r=i}while(null!==r)}return this},resolveUnassignedPoints:function(e){if(!1===this.unassigned.isEmpty()){var t=this.unassigned.first();do{for(var n=t.next,r=this.tolerance,i=null,o=0;o<e.length;o++){var a=e[o];if(0===a.mark){var s=a.distanceToPoint(t.point);if(s>r&&(r=s,i=a),r>1e3*this.tolerance)break}}null!==i&&this.addVertexToFace(t,i),t=n}while(null!==t)}return this},computeExtremes:function(){var e,t,r,i=new n.Vector3,o=new n.Vector3,a=[],s=[];for(e=0;e<3;e++)a[e]=s[e]=this.vertices[0];for(i.copy(this.vertices[0].point),o.copy(this.vertices[0].point),e=0,t=this.vertices.length;e<t;e++){var u=this.vertices[e],h=u.point;for(r=0;r<3;r++)h.getComponent(r)<i.getComponent(r)&&(i.setComponent(r,h.getComponent(r)),a[r]=u);for(r=0;r<3;r++)h.getComponent(r)>o.getComponent(r)&&(o.setComponent(r,h.getComponent(r)),s[r]=u)}return this.tolerance=3*Number.EPSILON*(Math.max(Math.abs(i.x),Math.abs(o.x))+Math.max(Math.abs(i.y),Math.abs(o.y))+Math.max(Math.abs(i.z),Math.abs(o.z))),{min:a,max:s}},computeInitialHull:function(){void 0===e&&(e=new n.Line3,t=new n.Plane,r=new n.Vector3);var i,o,a,u,h,l,c,d,f,p=this.vertices,m=this.computeExtremes(),v=m.min,x=m.max,g=0,y=0;for(l=0;l<3;l++)(f=x[l].point.getComponent(l)-v[l].point.getComponent(l))>g&&(g=f,y=l);for(g=0,e.set((o=v[y]).point,(a=x[y]).point),l=0,c=this.vertices.length;l<c;l++)(i=p[l])!==o&&i!==a&&(e.closestPointToPoint(i.point,!0,r),(f=r.distanceToSquared(i.point))>g&&(g=f,u=i));for(g=-1,t.setFromCoplanarPoints(o.point,a.point,u.point),l=0,c=this.vertices.length;l<c;l++)(i=p[l])!==o&&i!==a&&i!==u&&(f=Math.abs(t.distanceToPoint(i.point)))>g&&(g=f,h=i);var w=[];if(t.distanceToPoint(h.point)<0)for(w.push(s.create(o,a,u),s.create(h,a,o),s.create(h,u,a),s.create(h,o,u)),l=0;l<3;l++)d=(l+1)%3,w[l+1].getEdge(2).setTwin(w[0].getEdge(d)),w[l+1].getEdge(1).setTwin(w[d+1].getEdge(0));else for(w.push(s.create(o,u,a),s.create(h,o,a),s.create(h,a,u),s.create(h,u,o)),l=0;l<3;l++)d=(l+1)%3,w[l+1].getEdge(2).setTwin(w[0].getEdge((3-l)%3)),w[l+1].getEdge(0).setTwin(w[d+1].getEdge(1));for(l=0;l<4;l++)this.faces.push(w[l]);for(l=0,c=p.length;l<c;l++)if((i=p[l])!==o&&i!==a&&i!==u&&i!==h){g=this.tolerance;var T=null;for(d=0;d<4;d++)(f=this.faces[d].distanceToPoint(i.point))>g&&(g=f,T=this.faces[d]);null!==T&&this.addVertexToFace(i,T)}return this},reindexFaces:function(){for(var e=[],t=0;t<this.faces.length;t++){var n=this.faces[t];0===n.mark&&e.push(n)}return this.faces=e,this},nextVertexToAdd:function(){if(!1===this.assigned.isEmpty()){var e,t=0,n=this.assigned.first().face,r=n.outside;do{var i=n.distanceToPoint(r.point);i>t&&(t=i,e=r),r=r.next}while(null!==r&&r.face===n);return e}},computeHorizon:function(e,t,n,r){var i;this.deleteFaceVertices(n),n.mark=1,i=null===t?t=n.getEdge(0):t.next;do{var o=i.twin,a=o.face;0===a.mark&&(a.distanceToPoint(e)>this.tolerance?this.computeHorizon(e,o,a,r):r.push(i)),i=i.next}while(i!==t);return this},addAdjoiningFace:function(e,t){var n=s.create(e,t.tail(),t.head());return this.faces.push(n),n.getEdge(-1).setTwin(t.twin),n.getEdge(0)},addNewFaces:function(e,t){this.newFaces=[];for(var n=null,r=null,i=0;i<t.length;i++){var o=this.addAdjoiningFace(e,t[i]);null===n?n=o:o.next.setTwin(r),this.newFaces.push(o.face),r=o}return n.next.setTwin(r),this},addVertexToHull:function(e){var t=[];return this.unassigned.clear(),this.removeVertexFromFace(e,e.face),this.computeHorizon(e.point,null,e.face,t),this.addNewFaces(e,t),this.resolveUnassignedPoints(this.newFaces),this},cleanup:function(){return this.assigned.clear(),this.unassigned.clear(),this.newFaces=[],this},compute:function(){var e;for(this.computeInitialHull();void 0!==(e=this.nextVertexToAdd());)this.addVertexToHull(e);return this.reindexFaces(),this.cleanup(),this}}),Object.assign(s,{create:function(e,t,n){var r=new s,i=new u(e,r),o=new u(t,r),a=new u(n,r);return i.next=a.prev=o,o.next=i.prev=a,a.next=o.prev=i,r.edge=i,r.compute()}}),Object.assign(s.prototype,{getEdge:function(e){for(var t=this.edge;e>0;)t=t.next,e--;for(;e<0;)t=t.prev,e++;return t},compute:function(){void 0===i&&(i=new n.Triangle);var e=this.edge.tail(),t=this.edge.head(),r=this.edge.next.head();return i.set(e.point,t.point,r.point),i.getNormal(this.normal),i.getMidpoint(this.midpoint),this.area=i.getArea(),this.constant=this.normal.dot(this.midpoint),this},distanceToPoint:function(e){return this.normal.dot(e)-this.constant}}),Object.assign(u.prototype,{head:function(){return this.vertex},tail:function(){return this.prev?this.prev.vertex:null},length:function(){var e=this.head(),t=this.tail();return null!==t?t.point.distanceTo(e.point):-1},lengthSquared:function(){var e=this.head(),t=this.tail();return null!==t?t.point.distanceToSquared(e.point):-1},setTwin:function(e){return this.twin=e,e.twin=this,this}}),Object.assign(l.prototype,{first:function(){return this.head},last:function(){return this.tail},clear:function(){return this.head=this.tail=null,this},insertBefore:function(e,t){return t.prev=e.prev,t.next=e,null===t.prev?this.head=t:t.prev.next=t,e.prev=t,this},insertAfter:function(e,t){return t.prev=e,t.next=e.next,null===t.next?this.tail=t:t.next.prev=t,e.next=t,this},append:function(e){return null===this.head?this.head=e:this.tail.next=e,e.prev=this.tail,e.next=null,this.tail=e,this},appendChain:function(e){for(null===this.head?this.head=e:this.tail.next=e,e.prev=this.tail;null!==e.next;)e=e.next;return this.tail=e,this},remove:function(e){return null===e.prev?this.head=e.next:e.prev.next=e.next,null===e.next?this.tail=e.prev:e.next.prev=e.prev,this},removeSubList:function(e,t){return null===e.prev?this.head=t.next:e.prev.next=t.next,null===t.next?this.tail=e.prev:t.next.prev=e.prev,this},isEmpty:function(){return null===this.head}}),a}(),i=Math.PI/2,o={BOX:"Box",CYLINDER:"Cylinder",SPHERE:"Sphere",HULL:"ConvexPolyhedron",MESH:"Trimesh"},a=function(e,a){var c;if((a=a||{}).type===o.BOX)return u(e);if(a.type===o.CYLINDER)return function(e,r){var o=["x","y","z"],a=r.cylinderAxis||"y",s=o.splice(o.indexOf(a),1)&&o,u=(new n.Box3).setFromObject(e);if(!isFinite(u.min.lengthSq()))return null;var h=u.max[a]-u.min[a],l=.5*Math.max(u.max[s[0]]-u.min[s[0]],u.max[s[1]]-u.min[s[1]]),c=new t.Cylinder(l,l,h,12);return c._type=t.Shape.types.CYLINDER,c.radiusTop=l,c.radiusBottom=l,c.height=h,c.numSegments=12,c.orientation=new t.Quaternion,c.orientation.setFromEuler("y"===a?i:0,"z"===a?i:0,0,"XYZ").normalize(),c}(e,a);if(a.type===o.SPHERE)return function(e,n){if(n.sphereRadius)return new t.Sphere(n.sphereRadius);var r=h(e);return r?(r.computeBoundingSphere(),new t.Sphere(r.boundingSphere.radius)):null}(e,a);if(a.type===o.HULL)return function(e){var i=h(e);if(!i||!i.vertices.length)return null;for(var o=0;o<i.vertices.length;o++)i.vertices[o].x+=1e-4*(Math.random()-.5),i.vertices[o].y+=1e-4*(Math.random()-.5),i.vertices[o].z+=1e-4*(Math.random()-.5);var a=(new r).setFromObject(new n.Mesh(i)).faces,s=[],u=[];for(o=0;o<a.length;o++){var l=a[o],c=l.edge;do{var d=c.head().point;s.push(new t.Vec3(d.x,d.y,d.z)),u.push(new t.Vec3(l.normal.x,l.normal.y,l.normal.z)),c=c.next}while(c!==l.edge)}return new t.ConvexPolyhedron({vertices:s,normals:u})}(e);if(a.type===o.MESH)return(c=h(e))?function(e){var n=l(e);if(!n.length)return null;var r=Object.keys(n).map(Number);return new t.Trimesh(n,r)}(c):null;if(a.type)throw new Error('[CANNON.threeToCannon] Invalid type "%s".',a.type);if(!(c=h(e)))return null;switch(c.metadata?c.metadata.type:c.type){case"BoxGeometry":case"BoxBufferGeometry":return s(c);case"CylinderGeometry":case"CylinderBufferGeometry":return function(e){var r=e.metadata?e.metadata.parameters:e.parameters,i=new t.Cylinder(r.radiusTop,r.radiusBottom,r.height,r.radialSegments);return i._type=t.Shape.types.CYLINDER,i.radiusTop=r.radiusTop,i.radiusBottom=r.radiusBottom,i.height=r.height,i.numSegments=r.radialSegments,i.orientation=new t.Quaternion,i.orientation.setFromEuler(n.Math.degToRad(-90),0,0,"XYZ").normalize(),i}(c);case"PlaneGeometry":case"PlaneBufferGeometry":return function(e){e.computeBoundingBox();var n=e.boundingBox;return new t.Box(new t.Vec3((n.max.x-n.min.x)/2||.1,(n.max.y-n.min.y)/2||.1,(n.max.z-n.min.z)/2||.1))}(c);case"SphereGeometry":case"SphereBufferGeometry":return function(e){return new t.Sphere((e.metadata?e.metadata.parameters:e.parameters).radius)}(c);case"TubeGeometry":case"Geometry":case"BufferGeometry":return u(e);default:return console.warn('Unrecognized geometry: "%s". Using bounding box as shape.',c.type),s(c)}};function s(e){if(!l(e).length)return null;e.computeBoundingBox();var n=e.boundingBox;return new t.Box(new t.Vec3((n.max.x-n.min.x)/2,(n.max.y-n.min.y)/2,(n.max.z-n.min.z)/2))}function u(e){var r=e.clone();r.quaternion.set(0,0,0,1),r.updateMatrixWorld();var i=(new n.Box3).setFromObject(r);if(!isFinite(i.min.lengthSq()))return null;var o=new t.Box(new t.Vec3((i.max.x-i.min.x)/2,(i.max.y-i.min.y)/2,(i.max.z-i.min.z)/2)),a=i.translate(r.position.negate()).getCenter(new n.Vector3);return a.lengthSq()&&(o.offset=a),o}function h(e){var t,r=function(e){var t=[];return e.traverse(function(e){"Mesh"===e.type&&t.push(e)}),t}(e),i=new n.Geometry,o=new n.Geometry;if(0===r.length)return null;if(1===r.length){var a=new n.Vector3,s=new n.Quaternion,u=new n.Vector3;return r[0].geometry.isBufferGeometry?r[0].geometry.attributes.position&&r[0].geometry.attributes.position.itemSize>2&&i.fromBufferGeometry(r[0].geometry):i=r[0].geometry.clone(),i.metadata=r[0].geometry.metadata,r[0].updateMatrixWorld(),r[0].matrixWorld.decompose(a,s,u),i.scale(u.x,u.y,u.z)}for(;t=r.pop();)if(t.updateMatrixWorld(),t.geometry.isBufferGeometry){if(t.geometry.attributes.position&&t.geometry.attributes.position.itemSize>2){var h=new n.Geometry;h.fromBufferGeometry(t.geometry),o.merge(h,t.matrixWorld),h.dispose()}}else o.merge(t.geometry,t.matrixWorld);var l=new n.Matrix4;return l.scale(e.scale),o.applyMatrix(l),o}function l(e){return e.attributes||(e=(new n.BufferGeometry).fromGeometry(e)),(e.attributes.position||{}).array||[]}a.Type=o,e.threeToCannon=a});
//# sourceMappingURL=three-to-cannon.umd.js.map

@@ -1,4 +0,4 @@

import { Box, ConvexPolyhedron, Cylinder, Shape, Sphere, Quaternion as CQuaternion, Trimesh, Vec3 } from 'cannon-es';
import { ConvexHull } from 'three/examples/jsm/math/ConvexHull.js';
import { Box3, BufferGeometry, Geometry, Math as _Math, Matrix4, Mesh, Quaternion, Vector3 } from 'three';
import { Box, Quaternion as CQuaternion, ConvexPolyhedron, Cylinder, Shape, Sphere, Trimesh, Vec3 } from 'cannon-es';
import { Box3, BufferGeometry, Geometry, Matrix4, Mesh, Quaternion, Vector3, Math as _Math } from 'three';
import { ConvexHull } from './lib/ConvexHull.js';

@@ -184,3 +184,3 @@ var PI_2 = Math.PI / 2;

shape.orientation = new CQuaternion();
shape.orientation.setFromEuler(_Math.degToRad(90), 0, 0, 'XYZ').normalize();
shape.orientation.setFromEuler(_Math.degToRad(-90), 0, 0, 'XYZ').normalize();
return shape;

@@ -187,0 +187,0 @@ }

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

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

@@ -6,3 +6,3 @@ # three-to-cannon

[![License](https://img.shields.io/badge/license-MIT-007ec6.svg)](https://github.com/donmccurdy/three-to-cannon/blob/master/LICENSE)
[![Build Status](https://travis-ci.org/donmccurdy/three-to-cannon.svg?branch=master)](https://travis-ci.org/donmccurdy/three-to-cannon)
[![Build Status](https://travis-ci.com/donmccurdy/three-to-cannon.svg?branch=master)](https://travis-ci.com/donmccurdy/three-to-cannon)

@@ -9,0 +9,0 @@ Convert a THREE.Mesh to a CANNON.Shape, and optional optimizations with simplified shapes.

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

test('shape - cylinder without type', function (t) {
const geometry = new THREE.CylinderGeometry(2, 3, 5, 8);
const bufferGeometry = new THREE.BufferGeometry().fromGeometry(geometry);
bufferGeometry.metadata = {type: geometry.type, parameters: geometry.parameters || {}};
const cylinderObject = new THREE.Mesh(bufferGeometry);
const cylinder = threeToCannon(cylinderObject);
t.equal( cylinder.type, ShapeType.CYLINDER, 'cylinder.type' );
t.equal( cylinder.radiusTop, 2, 'cylinder.radiusTop' );
t.equal( cylinder.radiusBottom, 3, 'cylinder.radiusBottom' );
t.equal( cylinder.height, 5, '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) {

@@ -63,0 +82,0 @@ const hull = threeToCannon(object, {type: threeToCannon.Type.HULL});

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc