Socket
Socket
Sign inDemoInstall

three-to-cannon

Package Overview
Dependencies
8
Maintainers
1
Versions
25
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 4.0.2 to 4.1.0

dist/three-to-cannon.modern.mjs

40

dist/src/index.d.ts
import { Quaternion as CQuaternion, Shape, Vec3 } from 'cannon-es';
import { Object3D } from 'three';
export declare type BoxParameters = {
x: number;
y: number;
z: number;
};
export declare type CylinderParameters = {
radiusTop: number;
radiusBottom: number;
height: number;
segments: number;
};
export declare type SphereParameters = {
radius: number;
};
export declare type ConvexPolyhedronParameters = {
vertices: Float32Array;
faces: number[][];
};
export declare type TrimeshParameters = {
vertices: Float32Array;
indices: Uint32Array;
};
declare type ShapeTypeToShapeParameters = {
Box: BoxParameters;
Cylinder: CylinderParameters;
Sphere: SphereParameters;
ConvexPolyhedron: ConvexPolyhedronParameters;
Trimesh: TrimeshParameters;
};
export declare enum ShapeType {

@@ -15,2 +44,8 @@ BOX = "Box",

}
export interface ShapeParameters<T extends ShapeType = ShapeType> {
type: T;
params: ShapeTypeToShapeParameters[T];
offset?: Vec3;
orientation?: CQuaternion;
}
export interface ShapeResult<T extends Shape = Shape> {

@@ -22,4 +57,9 @@ shape: T;

/**
* Given a THREE.Object3D instance, creates parameters for a CANNON shape.
*/
export declare const getShapeParameters: (object: Object3D, options?: ShapeOptions) => ShapeParameters | null;
/**
* Given a THREE.Object3D instance, creates a corresponding CANNON shape.
*/
export declare const threeToCannon: (object: Object3D, options?: ShapeOptions) => ShapeResult | null;
export {};

2

dist/three-to-cannon.js

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

var e=require("cannon-es"),t=require("three"),n=function(){var e,n,r,i,o=new t.Vector3;function s(){this.tolerance=-1,this.faces=[],this.newFaces=[],this.assigned=new c,this.unassigned=new c,this.vertices=[]}function a(){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 c(){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 h(e[t]));return this.compute(),this},setFromObject:function(e){var n=[];return e.updateMatrixWorld(!0),e.traverse(function(e){var r,i,o,s=e.geometry;if(void 0!==s&&(s.isGeometry&&(s=s.toBufferGeometry?s.toBufferGeometry():(new t.BufferGeometry).fromGeometry(s)),s.isBufferGeometry)){var a=s.attributes.position;if(void 0!==a)for(r=0,i=a.count;r<i;r++)(o=new t.Vector3).fromBufferAttribute(a,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,s=n.length;o<s;o++){var a=n[o],u=a.distanceToPoint(e.origin),h=a.normal.dot(e.direction);if(u>0&&h>=0)return null;var c=0!==h?-u/h:0;if(!(c<=0)&&(h>0?i=Math.min(c,i):r=Math.max(c,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 s=e[o];if(0===s.mark){var a=s.distanceToPoint(t.point);if(a>r&&(r=a,i=s),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,s=[],a=[];for(e=0;e<3;e++)s[e]=a[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)),s[r]=u);for(r=0;r<3;r++)h.getComponent(r)>o.getComponent(r)&&(o.setComponent(r,h.getComponent(r)),a[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:s,max:a}},computeInitialHull:function(){void 0===e&&(e=new t.Line3,n=new t.Plane,r=new t.Vector3);var i,o,s,u,h,c,l,p,f,d=this.vertices,m=this.computeExtremes(),v=m.min,g=m.max,x=0,y=0;for(c=0;c<3;c++)(f=g[c].point.getComponent(c)-v[c].point.getComponent(c))>x&&(x=f,y=c);for(x=0,e.set((o=v[y]).point,(s=g[y]).point),c=0,l=this.vertices.length;c<l;c++)(i=d[c])!==o&&i!==s&&(e.closestPointToPoint(i.point,!0,r),(f=r.distanceToSquared(i.point))>x&&(x=f,u=i));for(x=-1,n.setFromCoplanarPoints(o.point,s.point,u.point),c=0,l=this.vertices.length;c<l;c++)(i=d[c])!==o&&i!==s&&i!==u&&(f=Math.abs(n.distanceToPoint(i.point)))>x&&(x=f,h=i);var w=[];if(n.distanceToPoint(h.point)<0)for(w.push(a.create(o,s,u),a.create(h,s,o),a.create(h,u,s),a.create(h,o,u)),c=0;c<3;c++)p=(c+1)%3,w[c+1].getEdge(2).setTwin(w[0].getEdge(p)),w[c+1].getEdge(1).setTwin(w[p+1].getEdge(0));else for(w.push(a.create(o,u,s),a.create(h,o,s),a.create(h,s,u),a.create(h,u,o)),c=0;c<3;c++)p=(c+1)%3,w[c+1].getEdge(2).setTwin(w[0].getEdge((3-c)%3)),w[c+1].getEdge(0).setTwin(w[p+1].getEdge(1));for(c=0;c<4;c++)this.faces.push(w[c]);for(c=0,l=d.length;c<l;c++)if((i=d[c])!==o&&i!==s&&i!==u&&i!==h){x=this.tolerance;var T=null;for(p=0;p<4;p++)(f=this.faces[p].distanceToPoint(i.point))>x&&(x=f,T=this.faces[p]);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,s=o.face;0===s.mark&&(s.distanceToPoint(e)>this.tolerance?this.computeHorizon(e,o,s,r):r.push(i)),i=i.next}while(i!==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,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(a,{create:function(e,t,n){var r=new a,i=new u(e,r),o=new u(t,r),s=new u(n,r);return i.next=s.prev=o,o.next=i.prev=s,s.next=o.prev=i,r.edge=i,r.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 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(c.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}(),r=new t.Vector3,i=new t.Vector3,o=new t.Quaternion;function s(e){var n,r=function(e){var t=[];return e.traverse(function(e){e.isMesh&&t.push(e)}),t}(e);if(0===r.length)return null;if(1===r.length)return a(r[0]);for(var i=[];n=r.pop();)i.push(c(a(n)));return function(e){for(var n=0,r=0;r<e.length;r++){var i=e[r].attributes.position;i&&3===i.itemSize&&(n+=i.count)}for(var o=new Float32Array(3*n),s=0,a=0;a<e.length;a++){var u=e[a].attributes.position;if(u&&3===u.itemSize)for(var h=0;h<u.count;h++)o[s++]=u.getX(h),o[s++]=u.getY(h),o[s++]=u.getZ(h)}return(new t.BufferGeometry).setAttribute("position",new t.BufferAttribute(o,3))}(i)}function a(e){var t=e.geometry;return t=t.toBufferGeometry?t.toBufferGeometry():t.clone(),e.updateMatrixWorld(),e.matrixWorld.decompose(r,o,i),t.scale(i.x,i.y,i.z),t}function u(e){for(var t=e.attributes.position,n=new Float32Array(3*t.count),r=0;r<t.count;r+=3)n[r]=t.getX(r),n[r+1]=t.getY(r),n[r+2]=t.getZ(r);return n}function h(e,t){switch(t){case"x":return e.x;case"y":return e.y;case"z":return e.z}throw new Error("Unexpected component "+t)}function c(e,n){void 0===n&&(n=1e-4),n=Math.max(n,Number.EPSILON);for(var r={},i=e.getIndex(),o=e.getAttribute("position"),s=i?i.count:o.count,a=0,u=[],h=[],c=Math.log10(1/n),l=Math.pow(10,c),p=0;p<s;p++){var f=i?i.getX(p):p,d="";d+=~~(o.getX(f)*l)+",",d+=~~(o.getY(f)*l)+",",(d+=~~(o.getZ(f)*l)+",")in r?u.push(r[d]):(h.push(o.getX(f)),h.push(o.getY(f)),h.push(o.getZ(f)),r[d]=a,u.push(a),a++)}var m=new t.BufferAttribute(new Float32Array(h),o.itemSize,o.normalized),v=new t.BufferGeometry;return v.setAttribute("position",m),v.setIndex(u),v}var l,p=Math.PI/2;function f(t){if(!u(t).length)return null;t.computeBoundingBox();var n=t.boundingBox;return{shape: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 d(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)),s=i.translate(r.position.negate()).getCenter(new t.Vector3);return{shape:o,offset:s.lengthSq()?new e.Vec3(s.x,s.y,s.z):void 0}}exports.ShapeType=void 0,(l=exports.ShapeType||(exports.ShapeType={})).BOX="Box",l.CYLINDER="Cylinder",l.SPHERE="Sphere",l.HULL="ConvexPolyhedron",l.MESH="Trimesh",exports.threeToCannon=function(r,i){var o;if(void 0===i&&(i={}),i.type===exports.ShapeType.BOX)return d(r);if(i.type===exports.ShapeType.CYLINDER)return function(n,r){var i=["x","y","z"],o=r.cylinderAxis||"y",s=i.splice(i.indexOf(o),1)&&i,a=(new t.Box3).setFromObject(n);if(!isFinite(a.min.lengthSq()))return null;var u=a.max[o]-a.min[o],c=.5*Math.max(h(a.max,s[0])-h(a.min,s[0]),h(a.max,s[1])-h(a.min,s[1])),l=new e.Cylinder(c,c,u,12);l.radiusTop=c,l.radiusBottom=c,l.height=u,l.numSegments=12;var f="y"===o?p:0,d="z"===o?p:0;return{shape:l,orientation:(new e.Quaternion).setFromEuler(f,d,0,"XYZ").normalize()}}(r,i);if(i.type===exports.ShapeType.SPHERE)return function(t,n){if(n.sphereRadius)return{shape:new e.Sphere(n.sphereRadius)};var r=s(t);return r?(r.computeBoundingSphere(),{shape:new e.Sphere(r.boundingSphere.radius)}):null}(r,i);if(i.type===exports.ShapeType.HULL)return function(r){var i=s(r);if(!i)return null;for(var o=1e-4,a=0;a<i.attributes.position.count;a++)i.attributes.position.setXYZ(a,i.attributes.position.getX(a)+(Math.random()-.5)*o,i.attributes.position.getY(a)+(Math.random()-.5)*o,i.attributes.position.getZ(a)+(Math.random()-.5)*o);for(var u=(new n).setFromObject(new t.Mesh(i)).faces,h=[],c=[],l=0;l<u.length;l++){var p=u[l],f=[];c.push(f);var d=p.edge;do{var m=d.head().point;h.push(new e.Vec3(m.x,m.y,m.z)),f.push(h.length-1),d=d.next}while(d!==p.edge)}return{shape:new e.ConvexPolyhedron({vertices:h,faces:c})}}(r);if(i.type===exports.ShapeType.MESH)return(o=s(r))?function(t){var n=u(t);if(!n.length)return null;var r=Object.keys(n).map(Number);return{shape:new e.Trimesh(n,r)}}(o):null;if(i.type)throw new Error('[CANNON.threeToCannon] Invalid type "'+i.type+'".');if(!(o=s(r)))return null;switch(o.type){case"BoxGeometry":case"BoxBufferGeometry":return f(o);case"CylinderGeometry":case"CylinderBufferGeometry":return function(n){var r=n.parameters,i=new e.Cylinder(r.radiusTop,r.radiusBottom,r.height,r.radialSegments);return i.radiusTop=r.radiusTop,i.radiusBottom=r.radiusBottom,i.height=r.height,i.numSegments=r.radialSegments,{shape:i,orientation:(new e.Quaternion).setFromEuler(t.MathUtils.degToRad(-90),0,0,"XYZ").normalize()}}(o);case"PlaneGeometry":case"PlaneBufferGeometry":return function(t){t.computeBoundingBox();var n=t.boundingBox;return{shape: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))}}(o);case"SphereGeometry":case"SphereBufferGeometry":return function(t){return{shape:new e.Sphere(t.parameters.radius)}}(o);case"TubeGeometry":case"BufferGeometry":return d(r);default:return console.warn('Unrecognized geometry: "%s". Using bounding box as shape.',o.type),f(o)}};
var e=require("cannon-es"),t=require("three"),n=function(){var e,n,r,i,o=new t.Vector3;function s(){this.tolerance=-1,this.faces=[],this.newFaces=[],this.assigned=new p,this.unassigned=new p,this.vertices=[]}function a(){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 p(){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 h(e[t]));return this.compute(),this},setFromObject:function(e){var n=[];return e.updateMatrixWorld(!0),e.traverse(function(e){var r,i,o,s=e.geometry;if(void 0!==s&&(s.isGeometry&&(s=s.toBufferGeometry?s.toBufferGeometry():(new t.BufferGeometry).fromGeometry(s)),s.isBufferGeometry)){var a=s.attributes.position;if(void 0!==a)for(r=0,i=a.count;r<i;r++)(o=new t.Vector3).fromBufferAttribute(a,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,s=n.length;o<s;o++){var a=n[o],u=a.distanceToPoint(e.origin),h=a.normal.dot(e.direction);if(u>0&&h>=0)return null;var p=0!==h?-u/h:0;if(!(p<=0)&&(h>0?i=Math.min(p,i):r=Math.max(p,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 s=e[o];if(0===s.mark){var a=s.distanceToPoint(t.point);if(a>r&&(r=a,i=s),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,s=[],a=[];for(e=0;e<3;e++)s[e]=a[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)),s[r]=u);for(r=0;r<3;r++)h.getComponent(r)>o.getComponent(r)&&(o.setComponent(r,h.getComponent(r)),a[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:s,max:a}},computeInitialHull:function(){void 0===e&&(e=new t.Line3,n=new t.Plane,r=new t.Vector3);var i,o,s,u,h,p,c,l,f,d=this.vertices,m=this.computeExtremes(),v=m.min,x=m.max,g=0,y=0;for(p=0;p<3;p++)(f=x[p].point.getComponent(p)-v[p].point.getComponent(p))>g&&(g=f,y=p);for(g=0,e.set((o=v[y]).point,(s=x[y]).point),p=0,c=this.vertices.length;p<c;p++)(i=d[p])!==o&&i!==s&&(e.closestPointToPoint(i.point,!0,r),(f=r.distanceToSquared(i.point))>g&&(g=f,u=i));for(g=-1,n.setFromCoplanarPoints(o.point,s.point,u.point),p=0,c=this.vertices.length;p<c;p++)(i=d[p])!==o&&i!==s&&i!==u&&(f=Math.abs(n.distanceToPoint(i.point)))>g&&(g=f,h=i);var w=[];if(n.distanceToPoint(h.point)<0)for(w.push(a.create(o,s,u),a.create(h,s,o),a.create(h,u,s),a.create(h,o,u)),p=0;p<3;p++)l=(p+1)%3,w[p+1].getEdge(2).setTwin(w[0].getEdge(l)),w[p+1].getEdge(1).setTwin(w[l+1].getEdge(0));else for(w.push(a.create(o,u,s),a.create(h,o,s),a.create(h,s,u),a.create(h,u,o)),p=0;p<3;p++)l=(p+1)%3,w[p+1].getEdge(2).setTwin(w[0].getEdge((3-p)%3)),w[p+1].getEdge(0).setTwin(w[l+1].getEdge(1));for(p=0;p<4;p++)this.faces.push(w[p]);for(p=0,c=d.length;p<c;p++)if((i=d[p])!==o&&i!==s&&i!==u&&i!==h){g=this.tolerance;var T=null;for(l=0;l<4;l++)(f=this.faces[l].distanceToPoint(i.point))>g&&(g=f,T=this.faces[l]);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,s=o.face;0===s.mark&&(s.distanceToPoint(e)>this.tolerance?this.computeHorizon(e,o,s,r):r.push(i)),i=i.next}while(i!==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,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(a,{create:function(e,t,n){var r=new a,i=new u(e,r),o=new u(t,r),s=new u(n,r);return i.next=s.prev=o,o.next=i.prev=s,s.next=o.prev=i,r.edge=i,r.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 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(p.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}(),r=new t.Vector3,i=new t.Vector3,o=new t.Quaternion;function s(e){var n,r=function(e){var t=[];return e.traverse(function(e){e.isMesh&&t.push(e)}),t}(e);if(0===r.length)return null;if(1===r.length)return a(r[0]);for(var i=[];n=r.pop();)i.push(p(a(n)));return function(e){for(var n=0,r=0;r<e.length;r++){var i=e[r].attributes.position;i&&3===i.itemSize&&(n+=i.count)}for(var o=new Float32Array(3*n),s=0,a=0;a<e.length;a++){var u=e[a].attributes.position;if(u&&3===u.itemSize)for(var h=0;h<u.count;h++)o[s++]=u.getX(h),o[s++]=u.getY(h),o[s++]=u.getZ(h)}return(new t.BufferGeometry).setAttribute("position",new t.BufferAttribute(o,3))}(i)}function a(e){var t=e.geometry;return t=t.toBufferGeometry?t.toBufferGeometry():t.clone(),e.updateMatrixWorld(),e.matrixWorld.decompose(r,o,i),t.scale(i.x,i.y,i.z),t}function u(e){for(var t=e.attributes.position,n=new Float32Array(3*t.count),r=0;r<t.count;r+=3)n[r]=t.getX(r),n[r+1]=t.getY(r),n[r+2]=t.getZ(r);return n}function h(e,t){switch(t){case"x":return e.x;case"y":return e.y;case"z":return e.z}throw new Error("Unexpected component "+t)}function p(e,n){void 0===n&&(n=1e-4),n=Math.max(n,Number.EPSILON);for(var r={},i=e.getIndex(),o=e.getAttribute("position"),s=i?i.count:o.count,a=0,u=[],h=[],p=Math.log10(1/n),c=Math.pow(10,p),l=0;l<s;l++){var f=i?i.getX(l):l,d="";d+=~~(o.getX(f)*c)+",",d+=~~(o.getY(f)*c)+",",(d+=~~(o.getZ(f)*c)+",")in r?u.push(r[d]):(h.push(o.getX(f)),h.push(o.getY(f)),h.push(o.getZ(f)),r[d]=a,u.push(a),a++)}var m=new t.BufferAttribute(new Float32Array(h),o.itemSize,o.normalized),v=new t.BufferGeometry;return v.setAttribute("position",m),v.setIndex(u),v}var c,l=Math.PI/2;exports.ShapeType=void 0,(c=exports.ShapeType||(exports.ShapeType={})).BOX="Box",c.CYLINDER="Cylinder",c.SPHERE="Sphere",c.HULL="ConvexPolyhedron",c.MESH="Trimesh";var f=function(r,i){var o;if(void 0===i&&(i={}),i.type===exports.ShapeType.BOX)return m(r);if(i.type===exports.ShapeType.CYLINDER)return function(n,r){var i=["x","y","z"],o=r.cylinderAxis||"y",s=i.splice(i.indexOf(o),1)&&i,a=(new t.Box3).setFromObject(n);if(!isFinite(a.min.lengthSq()))return null;var u=a.max[o]-a.min[o],p=.5*Math.max(h(a.max,s[0])-h(a.min,s[0]),h(a.max,s[1])-h(a.min,s[1])),c="y"===o?l:0,f="z"===o?l:0;return{type:exports.ShapeType.CYLINDER,params:{radiusTop:p,radiusBottom:p,height:u,segments:12},orientation:(new e.Quaternion).setFromEuler(c,f,0,"XYZ").normalize()}}(r,i);if(i.type===exports.ShapeType.SPHERE)return function(e,t){if(t.sphereRadius)return{type:exports.ShapeType.SPHERE,params:{radius:t.sphereRadius}};var n=s(e);return n?(n.computeBoundingSphere(),{type:exports.ShapeType.SPHERE,params:{radius:n.boundingSphere.radius}}):null}(r,i);if(i.type===exports.ShapeType.HULL)return function(e){var r=s(e);if(!r)return null;for(var i=1e-4,o=0;o<r.attributes.position.count;o++)r.attributes.position.setXYZ(o,r.attributes.position.getX(o)+(Math.random()-.5)*i,r.attributes.position.getY(o)+(Math.random()-.5)*i,r.attributes.position.getZ(o)+(Math.random()-.5)*i);for(var a=(new n).setFromObject(new t.Mesh(r)).faces,u=[],h=[],p=0,c=0;c<a.length;c++){var l=a[c],f=[];h.push(f);var d=l.edge;do{var m=d.head().point;u.push(m.x,m.y,m.z),f.push(p),p++,d=d.next}while(d!==l.edge)}var v=new Float32Array(u.length);return v.set(u),{type:exports.ShapeType.HULL,params:{vertices:v,faces:h}}}(r);if(i.type===exports.ShapeType.MESH)return(o=s(r))?function(e){var t=u(e);if(!t.length)return null;for(var n=new Uint32Array(t.length),r=0;r<t.length;r++)n[r]=r;return{type:exports.ShapeType.MESH,params:{vertices:t,indices:n}}}(o):null;if(i.type)throw new Error('[CANNON.getShapeParameters] Invalid type "'+i.type+'".');if(!(o=s(r)))return null;switch(o.type){case"BoxGeometry":case"BoxBufferGeometry":return d(o);case"CylinderGeometry":case"CylinderBufferGeometry":return function(n){var r=n.parameters;return{type:exports.ShapeType.CYLINDER,params:{radiusTop:r.radiusTop,radiusBottom:r.radiusBottom,height:r.height,segments:r.radialSegments},orientation:(new e.Quaternion).setFromEuler(t.MathUtils.degToRad(-90),0,0,"XYZ").normalize()}}(o);case"PlaneGeometry":case"PlaneBufferGeometry":return function(e){e.computeBoundingBox();var t=e.boundingBox;return{type:exports.ShapeType.BOX,params:{x:(t.max.x-t.min.x)/2||.1,y:(t.max.y-t.min.y)/2||.1,z:(t.max.z-t.min.z)/2||.1}}}(o);case"SphereGeometry":case"SphereBufferGeometry":return function(e){return{type:exports.ShapeType.SPHERE,params:{radius:e.parameters.radius}}}(o);case"TubeGeometry":case"BufferGeometry":return m(r);default:return console.warn('Unrecognized geometry: "%s". Using bounding box as shape.',o.type),d(o)}};function d(e){if(!u(e).length)return null;e.computeBoundingBox();var t=e.boundingBox;return{type:exports.ShapeType.BOX,params:{x:(t.max.x-t.min.x)/2,y:(t.max.y-t.min.y)/2,z:(t.max.z-t.min.z)/2}}}function m(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=i.translate(r.position.negate()).getCenter(new t.Vector3);return{type:exports.ShapeType.BOX,params:{x:(i.max.x-i.min.x)/2,y:(i.max.y-i.min.y)/2,z:(i.max.z-i.min.z)/2},offset:o.lengthSq()?new e.Vec3(o.x,o.y,o.z):void 0}}exports.getShapeParameters=f,exports.threeToCannon=function(t,n){void 0===n&&(n={});var r=f(t,n);if(!r)return null;var i=r.type,o=r.params,s=r.offset,a=r.orientation;return{shape:i===exports.ShapeType.BOX?function(t){return new e.Box(new e.Vec3(t.x,t.y,t.z))}(o):i===exports.ShapeType.CYLINDER?function(t){var n=t.radiusBottom,r=t.height,i=t.segments,o=new e.Cylinder(t.radiusTop,n,r,i);return o.radiusTop=n,o.radiusBottom=n,o.height=r,o.numSegments=i,o}(o):i===exports.ShapeType.SPHERE?function(t){return new e.Sphere(t.radius)}(o):i===exports.ShapeType.HULL?function(t){for(var n=t.faces,r=t.vertices,i=[],o=0;o<r.length;o+=3)i.push(new e.Vec3(r[o],r[o+1],r[o+2]));return new e.ConvexPolyhedron({faces:n,vertices:i})}(o):function(t){return new e.Trimesh(t.vertices,t.indices)}(o),offset:s,orientation:a}};
//# sourceMappingURL=three-to-cannon.js.map

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

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

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

!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||self).threeToCannon={},e.cannonEs,e.THREE)}(this,function(e,t,n){var i=function(){var e,t,i,r,o=new n.Vector3;function s(){this.tolerance=-1,this.faces=[],this.newFaces=[],this.assigned=new c,this.unassigned=new c,this.vertices=[]}function a(){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 c(){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 h(e[t]));return this.compute(),this},setFromObject:function(e){var t=[];return e.updateMatrixWorld(!0),e.traverse(function(e){var i,r,o,s=e.geometry;if(void 0!==s&&(s.isGeometry&&(s=s.toBufferGeometry?s.toBufferGeometry():(new n.BufferGeometry).fromGeometry(s)),s.isBufferGeometry)){var a=s.attributes.position;if(void 0!==a)for(i=0,r=a.count;i<r;i++)(o=new n.Vector3).fromBufferAttribute(a,i).applyMatrix4(e.matrixWorld),t.push(o)}}),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,o=0,s=n.length;o<s;o++){var a=n[o],u=a.distanceToPoint(e.origin),h=a.normal.dot(e.direction);if(u>0&&h>=0)return null;var c=0!==h?-u/h:0;if(!(c<=0)&&(h>0?r=Math.min(c,r):i=Math.max(c,i),i>r))return null}return e.at(-Infinity!==i?i:r,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 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,o=0;o<e.length;o++){var s=e[o];if(0===s.mark){var a=s.distanceToPoint(t.point);if(a>i&&(i=a,r=s),i>1e3*this.tolerance)break}}null!==r&&this.addVertexToFace(t,r),t=n}while(null!==t)}return this},computeExtremes:function(){var e,t,i,r=new n.Vector3,o=new n.Vector3,s=[],a=[];for(e=0;e<3;e++)s[e]=a[e]=this.vertices[0];for(r.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(i=0;i<3;i++)h.getComponent(i)<r.getComponent(i)&&(r.setComponent(i,h.getComponent(i)),s[i]=u);for(i=0;i<3;i++)h.getComponent(i)>o.getComponent(i)&&(o.setComponent(i,h.getComponent(i)),a[i]=u)}return this.tolerance=3*Number.EPSILON*(Math.max(Math.abs(r.x),Math.abs(o.x))+Math.max(Math.abs(r.y),Math.abs(o.y))+Math.max(Math.abs(r.z),Math.abs(o.z))),{min:s,max:a}},computeInitialHull:function(){void 0===e&&(e=new n.Line3,t=new n.Plane,i=new n.Vector3);var r,o,s,u,h,c,l,p,f,d=this.vertices,m=this.computeExtremes(),v=m.min,g=m.max,x=0,y=0;for(c=0;c<3;c++)(f=g[c].point.getComponent(c)-v[c].point.getComponent(c))>x&&(x=f,y=c);for(x=0,e.set((o=v[y]).point,(s=g[y]).point),c=0,l=this.vertices.length;c<l;c++)(r=d[c])!==o&&r!==s&&(e.closestPointToPoint(r.point,!0,i),(f=i.distanceToSquared(r.point))>x&&(x=f,u=r));for(x=-1,t.setFromCoplanarPoints(o.point,s.point,u.point),c=0,l=this.vertices.length;c<l;c++)(r=d[c])!==o&&r!==s&&r!==u&&(f=Math.abs(t.distanceToPoint(r.point)))>x&&(x=f,h=r);var w=[];if(t.distanceToPoint(h.point)<0)for(w.push(a.create(o,s,u),a.create(h,s,o),a.create(h,u,s),a.create(h,o,u)),c=0;c<3;c++)p=(c+1)%3,w[c+1].getEdge(2).setTwin(w[0].getEdge(p)),w[c+1].getEdge(1).setTwin(w[p+1].getEdge(0));else for(w.push(a.create(o,u,s),a.create(h,o,s),a.create(h,s,u),a.create(h,u,o)),c=0;c<3;c++)p=(c+1)%3,w[c+1].getEdge(2).setTwin(w[0].getEdge((3-c)%3)),w[c+1].getEdge(0).setTwin(w[p+1].getEdge(1));for(c=0;c<4;c++)this.faces.push(w[c]);for(c=0,l=d.length;c<l;c++)if((r=d[c])!==o&&r!==s&&r!==u&&r!==h){x=this.tolerance;var T=null;for(p=0;p<4;p++)(f=this.faces[p].distanceToPoint(r.point))>x&&(x=f,T=this.faces[p]);null!==T&&this.addVertexToFace(r,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,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 o=r.twin,s=o.face;0===s.mark&&(s.distanceToPoint(e)>this.tolerance?this.computeHorizon(e,o,s,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 o=this.addAdjoiningFace(e,t[r]);null===n?n=o:o.next.setTwin(i),this.newFaces.push(o.face),i=o}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 u(e,i),o=new u(t,i),s=new u(n,i);return r.next=s.prev=o,o.next=r.prev=s,s.next=o.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===r&&(r=new n.Triangle);var e=this.edge.tail(),t=this.edge.head(),i=this.edge.next.head();return r.set(e.point,t.point,i.point),r.getNormal(this.normal),r.getMidpoint(this.midpoint),this.area=r.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(c.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}(),r=new n.Vector3,o=new n.Vector3,s=new n.Quaternion;function a(e){var t,i=function(e){var t=[];return e.traverse(function(e){e.isMesh&&t.push(e)}),t}(e);if(0===i.length)return null;if(1===i.length)return u(i[0]);for(var r=[];t=i.pop();)r.push(l(u(t)));return function(e){for(var t=0,i=0;i<e.length;i++){var r=e[i].attributes.position;r&&3===r.itemSize&&(t+=r.count)}for(var o=new Float32Array(3*t),s=0,a=0;a<e.length;a++){var u=e[a].attributes.position;if(u&&3===u.itemSize)for(var h=0;h<u.count;h++)o[s++]=u.getX(h),o[s++]=u.getY(h),o[s++]=u.getZ(h)}return(new n.BufferGeometry).setAttribute("position",new n.BufferAttribute(o,3))}(r)}function u(e){var t=e.geometry;return t=t.toBufferGeometry?t.toBufferGeometry():t.clone(),e.updateMatrixWorld(),e.matrixWorld.decompose(r,s,o),t.scale(o.x,o.y,o.z),t}function h(e){for(var t=e.attributes.position,n=new Float32Array(3*t.count),i=0;i<t.count;i+=3)n[i]=t.getX(i),n[i+1]=t.getY(i),n[i+2]=t.getZ(i);return n}function c(e,t){switch(t){case"x":return e.x;case"y":return e.y;case"z":return e.z}throw new Error("Unexpected component "+t)}function l(e,t){void 0===t&&(t=1e-4),t=Math.max(t,Number.EPSILON);for(var i={},r=e.getIndex(),o=e.getAttribute("position"),s=r?r.count:o.count,a=0,u=[],h=[],c=Math.log10(1/t),l=Math.pow(10,c),p=0;p<s;p++){var f=r?r.getX(p):p,d="";d+=~~(o.getX(f)*l)+",",d+=~~(o.getY(f)*l)+",",(d+=~~(o.getZ(f)*l)+",")in i?u.push(i[d]):(h.push(o.getX(f)),h.push(o.getY(f)),h.push(o.getZ(f)),i[d]=a,u.push(a),a++)}var m=new n.BufferAttribute(new Float32Array(h),o.itemSize,o.normalized),v=new n.BufferGeometry;return v.setAttribute("position",m),v.setIndex(u),v}var p,f=Math.PI/2;function d(e){if(!h(e).length)return null;e.computeBoundingBox();var n=e.boundingBox;return{shape: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 m(e){var i=e.clone();i.quaternion.set(0,0,0,1),i.updateMatrixWorld();var r=(new n.Box3).setFromObject(i);if(!isFinite(r.min.lengthSq()))return null;var o=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)),s=r.translate(i.position.negate()).getCenter(new n.Vector3);return{shape:o,offset:s.lengthSq()?new t.Vec3(s.x,s.y,s.z):void 0}}e.ShapeType=void 0,(p=e.ShapeType||(e.ShapeType={})).BOX="Box",p.CYLINDER="Cylinder",p.SPHERE="Sphere",p.HULL="ConvexPolyhedron",p.MESH="Trimesh",e.threeToCannon=function(r,o){var s;if(void 0===o&&(o={}),o.type===e.ShapeType.BOX)return m(r);if(o.type===e.ShapeType.CYLINDER)return function(e,i){var r=["x","y","z"],o=i.cylinderAxis||"y",s=r.splice(r.indexOf(o),1)&&r,a=(new n.Box3).setFromObject(e);if(!isFinite(a.min.lengthSq()))return null;var u=a.max[o]-a.min[o],h=.5*Math.max(c(a.max,s[0])-c(a.min,s[0]),c(a.max,s[1])-c(a.min,s[1])),l=new t.Cylinder(h,h,u,12);l.radiusTop=h,l.radiusBottom=h,l.height=u,l.numSegments=12;var p="y"===o?f:0,d="z"===o?f:0;return{shape:l,orientation:(new t.Quaternion).setFromEuler(p,d,0,"XYZ").normalize()}}(r,o);if(o.type===e.ShapeType.SPHERE)return function(e,n){if(n.sphereRadius)return{shape:new t.Sphere(n.sphereRadius)};var i=a(e);return i?(i.computeBoundingSphere(),{shape:new t.Sphere(i.boundingSphere.radius)}):null}(r,o);if(o.type===e.ShapeType.HULL)return function(e){var r=a(e);if(!r)return null;for(var o=1e-4,s=0;s<r.attributes.position.count;s++)r.attributes.position.setXYZ(s,r.attributes.position.getX(s)+(Math.random()-.5)*o,r.attributes.position.getY(s)+(Math.random()-.5)*o,r.attributes.position.getZ(s)+(Math.random()-.5)*o);for(var u=(new i).setFromObject(new n.Mesh(r)).faces,h=[],c=[],l=0;l<u.length;l++){var p=u[l],f=[];c.push(f);var d=p.edge;do{var m=d.head().point;h.push(new t.Vec3(m.x,m.y,m.z)),f.push(h.length-1),d=d.next}while(d!==p.edge)}return{shape:new t.ConvexPolyhedron({vertices:h,faces:c})}}(r);if(o.type===e.ShapeType.MESH)return(s=a(r))?function(e){var n=h(e);if(!n.length)return null;var i=Object.keys(n).map(Number);return{shape:new t.Trimesh(n,i)}}(s):null;if(o.type)throw new Error('[CANNON.threeToCannon] Invalid type "'+o.type+'".');if(!(s=a(r)))return null;switch(s.type){case"BoxGeometry":case"BoxBufferGeometry":return d(s);case"CylinderGeometry":case"CylinderBufferGeometry":return function(e){var i=e.parameters,r=new t.Cylinder(i.radiusTop,i.radiusBottom,i.height,i.radialSegments);return r.radiusTop=i.radiusTop,r.radiusBottom=i.radiusBottom,r.height=i.height,r.numSegments=i.radialSegments,{shape:r,orientation:(new t.Quaternion).setFromEuler(n.MathUtils.degToRad(-90),0,0,"XYZ").normalize()}}(s);case"PlaneGeometry":case"PlaneBufferGeometry":return function(e){e.computeBoundingBox();var n=e.boundingBox;return{shape: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))}}(s);case"SphereGeometry":case"SphereBufferGeometry":return function(e){return{shape:new t.Sphere(e.parameters.radius)}}(s);case"TubeGeometry":case"BufferGeometry":return m(r);default:return console.warn('Unrecognized geometry: "%s". Using bounding box as shape.',s.type),d(s)}}});
!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||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 c,this.unassigned=new c,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 c(){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&&(a.isGeometry&&(a=a.toBufferGeometry?a.toBufferGeometry():(new n.BufferGeometry).fromGeometry(a)),a.isBufferGeometry)){var s=a.attributes.position;if(void 0!==s)for(r=0,i=s.count;r<i;r++)(o=new n.Vector3).fromBufferAttribute(s,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 c=0!==h?-u/h:0;if(!(c<=0)&&(h>0?i=Math.min(c,i):r=Math.max(c,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,c,p,l,f,d=this.vertices,m=this.computeExtremes(),v=m.min,g=m.max,x=0,y=0;for(c=0;c<3;c++)(f=g[c].point.getComponent(c)-v[c].point.getComponent(c))>x&&(x=f,y=c);for(x=0,e.set((o=v[y]).point,(a=g[y]).point),c=0,p=this.vertices.length;c<p;c++)(i=d[c])!==o&&i!==a&&(e.closestPointToPoint(i.point,!0,r),(f=r.distanceToSquared(i.point))>x&&(x=f,u=i));for(x=-1,t.setFromCoplanarPoints(o.point,a.point,u.point),c=0,p=this.vertices.length;c<p;c++)(i=d[c])!==o&&i!==a&&i!==u&&(f=Math.abs(t.distanceToPoint(i.point)))>x&&(x=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)),c=0;c<3;c++)l=(c+1)%3,w[c+1].getEdge(2).setTwin(w[0].getEdge(l)),w[c+1].getEdge(1).setTwin(w[l+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)),c=0;c<3;c++)l=(c+1)%3,w[c+1].getEdge(2).setTwin(w[0].getEdge((3-c)%3)),w[c+1].getEdge(0).setTwin(w[l+1].getEdge(1));for(c=0;c<4;c++)this.faces.push(w[c]);for(c=0,p=d.length;c<p;c++)if((i=d[c])!==o&&i!==a&&i!==u&&i!==h){x=this.tolerance;var T=null;for(l=0;l<4;l++)(f=this.faces[l].distanceToPoint(i.point))>x&&(x=f,T=this.faces[l]);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(c.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=new n.Vector3,o=new n.Vector3,a=new n.Quaternion;function s(e){var t,r=function(e){var t=[];return e.traverse(function(e){e.isMesh&&t.push(e)}),t}(e);if(0===r.length)return null;if(1===r.length)return u(r[0]);for(var i=[];t=r.pop();)i.push(p(u(t)));return function(e){for(var t=0,r=0;r<e.length;r++){var i=e[r].attributes.position;i&&3===i.itemSize&&(t+=i.count)}for(var o=new Float32Array(3*t),a=0,s=0;s<e.length;s++){var u=e[s].attributes.position;if(u&&3===u.itemSize)for(var h=0;h<u.count;h++)o[a++]=u.getX(h),o[a++]=u.getY(h),o[a++]=u.getZ(h)}return(new n.BufferGeometry).setAttribute("position",new n.BufferAttribute(o,3))}(i)}function u(e){var t=e.geometry;return t=t.toBufferGeometry?t.toBufferGeometry():t.clone(),e.updateMatrixWorld(),e.matrixWorld.decompose(i,a,o),t.scale(o.x,o.y,o.z),t}function h(e){for(var t=e.attributes.position,n=new Float32Array(3*t.count),r=0;r<t.count;r+=3)n[r]=t.getX(r),n[r+1]=t.getY(r),n[r+2]=t.getZ(r);return n}function c(e,t){switch(t){case"x":return e.x;case"y":return e.y;case"z":return e.z}throw new Error("Unexpected component "+t)}function p(e,t){void 0===t&&(t=1e-4),t=Math.max(t,Number.EPSILON);for(var r={},i=e.getIndex(),o=e.getAttribute("position"),a=i?i.count:o.count,s=0,u=[],h=[],c=Math.log10(1/t),p=Math.pow(10,c),l=0;l<a;l++){var f=i?i.getX(l):l,d="";d+=~~(o.getX(f)*p)+",",d+=~~(o.getY(f)*p)+",",(d+=~~(o.getZ(f)*p)+",")in r?u.push(r[d]):(h.push(o.getX(f)),h.push(o.getY(f)),h.push(o.getZ(f)),r[d]=s,u.push(s),s++)}var m=new n.BufferAttribute(new Float32Array(h),o.itemSize,o.normalized),v=new n.BufferGeometry;return v.setAttribute("position",m),v.setIndex(u),v}var l,f=Math.PI/2;e.ShapeType=void 0,(l=e.ShapeType||(e.ShapeType={})).BOX="Box",l.CYLINDER="Cylinder",l.SPHERE="Sphere",l.HULL="ConvexPolyhedron",l.MESH="Trimesh";var d=function(i,o){var a;if(void 0===o&&(o={}),o.type===e.ShapeType.BOX)return v(i);if(o.type===e.ShapeType.CYLINDER)return function(r,i){var o=["x","y","z"],a=i.cylinderAxis||"y",s=o.splice(o.indexOf(a),1)&&o,u=(new n.Box3).setFromObject(r);if(!isFinite(u.min.lengthSq()))return null;var h=u.max[a]-u.min[a],p=.5*Math.max(c(u.max,s[0])-c(u.min,s[0]),c(u.max,s[1])-c(u.min,s[1])),l="y"===a?f:0,d="z"===a?f:0;return{type:e.ShapeType.CYLINDER,params:{radiusTop:p,radiusBottom:p,height:h,segments:12},orientation:(new t.Quaternion).setFromEuler(l,d,0,"XYZ").normalize()}}(i,o);if(o.type===e.ShapeType.SPHERE)return function(t,n){if(n.sphereRadius)return{type:e.ShapeType.SPHERE,params:{radius:n.sphereRadius}};var r=s(t);return r?(r.computeBoundingSphere(),{type:e.ShapeType.SPHERE,params:{radius:r.boundingSphere.radius}}):null}(i,o);if(o.type===e.ShapeType.HULL)return function(t){var i=s(t);if(!i)return null;for(var o=1e-4,a=0;a<i.attributes.position.count;a++)i.attributes.position.setXYZ(a,i.attributes.position.getX(a)+(Math.random()-.5)*o,i.attributes.position.getY(a)+(Math.random()-.5)*o,i.attributes.position.getZ(a)+(Math.random()-.5)*o);for(var u=(new r).setFromObject(new n.Mesh(i)).faces,h=[],c=[],p=0,l=0;l<u.length;l++){var f=u[l],d=[];c.push(d);var m=f.edge;do{var v=m.head().point;h.push(v.x,v.y,v.z),d.push(p),p++,m=m.next}while(m!==f.edge)}var g=new Float32Array(h.length);return g.set(h),{type:e.ShapeType.HULL,params:{vertices:g,faces:c}}}(i);if(o.type===e.ShapeType.MESH)return(a=s(i))?function(t){var n=h(t);if(!n.length)return null;for(var r=new Uint32Array(n.length),i=0;i<n.length;i++)r[i]=i;return{type:e.ShapeType.MESH,params:{vertices:n,indices:r}}}(a):null;if(o.type)throw new Error('[CANNON.getShapeParameters] Invalid type "'+o.type+'".');if(!(a=s(i)))return null;switch(a.type){case"BoxGeometry":case"BoxBufferGeometry":return m(a);case"CylinderGeometry":case"CylinderBufferGeometry":return function(r){var i=r.parameters;return{type:e.ShapeType.CYLINDER,params:{radiusTop:i.radiusTop,radiusBottom:i.radiusBottom,height:i.height,segments:i.radialSegments},orientation:(new t.Quaternion).setFromEuler(n.MathUtils.degToRad(-90),0,0,"XYZ").normalize()}}(a);case"PlaneGeometry":case"PlaneBufferGeometry":return function(t){t.computeBoundingBox();var n=t.boundingBox;return{type:e.ShapeType.BOX,params:{x:(n.max.x-n.min.x)/2||.1,y:(n.max.y-n.min.y)/2||.1,z:(n.max.z-n.min.z)/2||.1}}}(a);case"SphereGeometry":case"SphereBufferGeometry":return function(t){return{type:e.ShapeType.SPHERE,params:{radius:t.parameters.radius}}}(a);case"TubeGeometry":case"BufferGeometry":return v(i);default:return console.warn('Unrecognized geometry: "%s". Using bounding box as shape.',a.type),m(a)}};function m(t){if(!h(t).length)return null;t.computeBoundingBox();var n=t.boundingBox;return{type:e.ShapeType.BOX,params:{x:(n.max.x-n.min.x)/2,y:(n.max.y-n.min.y)/2,z:(n.max.z-n.min.z)/2}}}function v(r){var i=r.clone();i.quaternion.set(0,0,0,1),i.updateMatrixWorld();var o=(new n.Box3).setFromObject(i);if(!isFinite(o.min.lengthSq()))return null;var a=o.translate(i.position.negate()).getCenter(new n.Vector3);return{type:e.ShapeType.BOX,params:{x:(o.max.x-o.min.x)/2,y:(o.max.y-o.min.y)/2,z:(o.max.z-o.min.z)/2},offset:a.lengthSq()?new t.Vec3(a.x,a.y,a.z):void 0}}e.getShapeParameters=d,e.threeToCannon=function(n,r){void 0===r&&(r={});var i=d(n,r);if(!i)return null;var o=i.type,a=i.params,s=i.offset,u=i.orientation;return{shape:o===e.ShapeType.BOX?function(e){return new t.Box(new t.Vec3(e.x,e.y,e.z))}(a):o===e.ShapeType.CYLINDER?function(e){var n=e.radiusBottom,r=e.height,i=e.segments,o=new t.Cylinder(e.radiusTop,n,r,i);return o.radiusTop=n,o.radiusBottom=n,o.height=r,o.numSegments=i,o}(a):o===e.ShapeType.SPHERE?function(e){return new t.Sphere(e.radius)}(a):o===e.ShapeType.HULL?function(e){for(var n=e.faces,r=e.vertices,i=[],o=0;o<r.length;o+=3)i.push(new t.Vec3(r[o],r[o+1],r[o+2]));return new t.ConvexPolyhedron({faces:n,vertices:i})}(a):function(e){return new t.Trimesh(e.vertices,e.indices)}(a),offset:s,orientation:u}}});
//# sourceMappingURL=three-to-cannon.umd.js.map
{
"name": "three-to-cannon",
"version": "4.0.2",
"version": "4.1.0",
"description": "Convert a THREE.Mesh to a CANNON.Shape.",

@@ -40,17 +40,17 @@ "main": "dist/three-to-cannon.js",

"dependencies": {
"@types/three": "^0.127.1"
"@types/three": ">=0.125.x"
},
"devDependencies": {
"@types/tape": "^4.13.0",
"@typescript-eslint/eslint-plugin": "^4.23.0",
"@typescript-eslint/parser": "^4.23.0",
"cannon-es": "^0.17.0",
"eslint": "^7.26.0",
"esm": "^3.2.25",
"microbundle": "^0.13.0",
"tap-spec": "^5.0.0",
"tape": "^5.2.2",
"three": "^0.128.0",
"ts-node": "^9.1.1",
"typescript": "^4.2.4"
"@types/tape": "4.13.2",
"@typescript-eslint/eslint-plugin": "5.27.0",
"@typescript-eslint/parser": "5.27.0",
"cannon-es": "0.19.0",
"eslint": "8.17.0",
"esm": "3.2.25",
"microbundle": "0.15.0",
"tap-spec": "5.0.0",
"tape": "5.5.3",
"three": "0.128.0",
"ts-node": "10.8.1",
"typescript": "4.7.3"
},

@@ -57,0 +57,0 @@ "files": [

@@ -6,5 +6,5 @@ # 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://github.com/donmccurdy/three-to-cannon/workflows/build/badge.svg?branch=master&event=push)](https://github.com/donmccurdy/three-to-cannon/actions?query=workflow%3Abuild)
[![Build Status](https://github.com/donmccurdy/three-to-cannon/workflows/build/badge.svg?branch=main&event=push)](https://github.com/donmccurdy/three-to-cannon/actions?query=workflow%3Abuild)
Convert a [THREE.Mesh](https://threejs.org/docs/?q=mesh#api/en/objects/Mesh) or [THREE.Object3D](https://threejs.org/docs/?q=object3d#api/en/core/Object3D) to a [CANNON.Shape](https://pmndrs.github.io/cannon-es/docs/classes/shape.html), with optimizations to simplified bounding shapes (AABB, sphere, etc.).
Convert a [THREE.Mesh](https://threejs.org/docs/?q=mesh#api/en/objects/Mesh) or [THREE.Object3D](https://threejs.org/docs/?q=object3d#api/en/core/Object3D) to a [CANNON.Shape](https://pmndrs.github.io/cannon-es/docs/classes/Shape.html), with optimizations to simplified bounding shapes (AABB, sphere, etc.).

@@ -36,3 +36,3 @@ ## API

// Automatic.
// Automatic (Usually an AABB, except obvious cases like THREE.SphereGeometry).
const result = threeToCannon(object3D);

@@ -49,6 +49,6 @@

// Convex hull.
// Convex hull.
const result = threeToCannon(object3D, {type: ShapeType.HULL});
// Mesh (not recommended).
// Mesh (Not recommended — limitations: https://github.com/pmndrs/cannon-es/issues/21).
const result = threeToCannon(object3D, {type: ShapeType.MESH});

@@ -63,4 +63,7 @@

const {shape, offset, quaternion} = result;
// Add the shape to a CANNON.Body.
body.addShape(shape, offset, orientation);
```
See further documentation on the [CANNON.Shape](https://pmndrs.github.io/cannon-es/docs/classes/shape.html) class.
See further documentation on the [CANNON.Shape](https://pmndrs.github.io/cannon-es/docs/classes/Shape.html) class.

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