@jgphilpott/polytree 0.0.8 → 0.0.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- import{Vector2,Vector3,Mesh,Triangle,Box3,Matrix3,DoubleSide,Ray,Raycaster,BufferGeometry,BufferAttribute}from"three";var BACK,COPLANAR,CSG_Rules,EPSILON,FRONT,Plane,Polygon,Polytree,RAY_EPSILON,SPANNING,Vertex,_asyncUnionArrayID,_asyncUnionID,_matrix3,_normal1,_polygonID,_wP,_wP_EPS_ARR,_wP_EPS_ARR_COUNT,_wV1,_wV2,_wV3,calcWindingNumber_buffer,disposePolytree,edge1,edge2,h,handleIntersectingPolytrees,handleObjectForOp,handleObjectForOp_async,isUniqueTriangle,isValidTriangle,nbuf2,nbuf3,pointRounding,polyInside_WindingNumber_buffer,prepareTriangleBuffer,q,rayIntersectsTriangle,raycastIntersectAscSort,returnXYZ,s,splitPolygonArr,splitPolygonByPlane,tempBox3,tempRay,tempRayDirection,tempRaycaster,tmpm3,triangleVertex0,triangleVertex1,ttvv0,wNPI,EPS2D,constructIntersection,intersectionTestEdge2D,intersectionTestVertex2D,pointInTriangleInclusive2D,pointOnSegmentInclusive2D,pointsEqual2D,resolveCoplanarTriangleIntersection,resolveTriangleIntersection,tempVector1,tempVector2,tempVector3,triangleIntersectionCCW2D,triangleIntersectsTriangle,triangleOrientation2D,trianglesOverlap2D;tempVector1=new Vector3,tempVector2=new Vector3,tempBox3=new Box3,triangleVertex0=new Vector3,triangleVertex1=new Vector3,tempRaycaster=new Raycaster,tempRay=new Ray,tempRayDirection=new Vector3(0,0,1),EPSILON=1e-5,FRONT=1,BACK=2,SPANNING=3,_polygonID=COPLANAR=0,(Polytree=class Polytree{constructor(e,t){this.polygons=[],this.replacedPolygons=[],this.mesh,this.originalMatrixWorld,this.box=e,this.subTrees=[],this.parent=t,this.level=0,this.polygonArrays=void 0,this.addPolygonsArrayToRoot(this.polygons)}clone(){return(new this.constructor).copy(this)}copy(e){var t,r,n,o;for(this.deletePolygonsArrayFromRoot(this.polygons),this.polygons=e.polygons.map(function(e){return e.clone()}),this.addPolygonsArrayToRoot(this.polygons),this.replacedPolygons=e.replacedPolygons.map(function(e){return e.clone()}),e.mesh&&(this.mesh=e.mesh),e.originalMatrixWorld&&(this.originalMatrixWorld=e.originalMatrixWorld.clone()),this.box=e.box.clone(),this.level=e.level,t=r=0,n=e.subTrees.length;0<=n?r<n:n<r;t=0<=n?++r:--r)o=new this.constructor(void 0,this).copy(e.subTrees[t]),this.subTrees.push(o);return this}addPolygonsArrayToRoot(e){return this.parent?this.parent.addPolygonsArrayToRoot(e):(void 0===this.polygonArrays&&(this.polygonArrays=[]),this.polygonArrays.push(e))}deletePolygonsArrayFromRoot(e){return this.parent?this.parent.deletePolygonsArrayFromRoot(e):-1<(e=this.polygonArrays.indexOf(e))?this.polygonArrays.splice(e,1):void 0}isEmpty(){return 0===this.polygons.length}addPolygon(e,t){var r;return this.bounds||(this.bounds=new Box3),r=e.triangle,t&&!isUniqueTriangle(r,t)||(this.bounds.min.x=Math.min(this.bounds.min.x,r.a.x,r.b.x,r.c.x),this.bounds.min.y=Math.min(this.bounds.min.y,r.a.y,r.b.y,r.c.y),this.bounds.min.z=Math.min(this.bounds.min.z,r.a.z,r.b.z,r.c.z),this.bounds.max.x=Math.max(this.bounds.max.x,r.a.x,r.b.x,r.c.x),this.bounds.max.y=Math.max(this.bounds.max.y,r.a.y,r.b.y,r.c.y),this.bounds.max.z=Math.max(this.bounds.max.z,r.a.z,r.b.z,r.c.z),this.polygons.push(e)),this}calcBox(){return this.bounds||(this.bounds=new Box3),this.box=this.bounds.clone(),this.box.min.x-=.01,this.box.min.y-=.01,this.box.min.z-=.01,this}newPolytree(e,t){return new this.constructor(e,t)}split(e){var t,r,n,o,i,s,a,l,c,u,y,h,p,g,d,m,P;if(this.box){for(p=[],n=tempVector2.copy(this.box.max).sub(this.box.min).multiplyScalar(.5),d=i=0;i<=1;d=++i)for(m=s=0;s<=1;m=++s)for(P=a=0;a<=1;P=++a)t=new Box3,g=tempVector1.set(d,m,P),t.min.copy(this.box.min).add(g.multiply(n)),t.max.copy(t.min).add(n),t.expandByScalar(EPSILON),p.push(this.newPolytree(t,this));for(u=void 0;u=this.polygons.pop();){for(r=!1,o=l=0,y=p.length;0<=y?l<y:y<l;o=0<=y?++l:--l)p[o].box.containsPoint(u.getMidpoint())&&(p[o].polygons.push(u),r=!0);if(!r)throw console.error("ERROR: unable to find subtree for:",u.triangle),new Error("Unable to find subtree for triangle at level "+e)}for(o=c=0,h=p.length;0<=h?c<h:h<c;o=0<=h?++c:--c)p[o].level=e+1,p[o].polygons.length>Polytree.polygonsPerTree&&e<Polytree.maxLevel&&p[o].split(e+1),this.subTrees.push(p[o]);return this}}buildTree(){return this.calcBox(),this.split(0),this.processTree(),this}processTree(){var e,t,r,n,o,i;if(!this.isEmpty()){for(tempBox3.copy(this.box),e=t=0,n=this.polygons.length;0<=n?t<n:n<t;e=0<=n?++t:--t)this.box.expandByPoint(this.polygons[e].triangle.a),this.box.expandByPoint(this.polygons[e].triangle.b),this.box.expandByPoint(this.polygons[e].triangle.c);this.expandParentBox()}for(i=[],e=r=0,o=this.subTrees.length;0<=o?r<o:o<r;e=0<=o?++r:--r)i.push(this.subTrees[e].processTree());return i}expandParentBox(){if(this.parent)return this.parent.box.expandByPoint(this.box.min),this.parent.box.expandByPoint(this.box.max),this.parent.expandParentBox()}getPolygonsIntersectingPolygon(e,t=[]){var r,n,o,i,s,a,l,c,u;if(this.box.intersectsTriangle(e.triangle)&&0<this.polygons.length){if(r=this.polygons.slice(),0<this.replacedPolygons.length)for(n=o=0,l=this.replacedPolygons.length;0<=l?o<l:l<o;n=0<=l?++o:--o)r.push(this.replacedPolygons[n]);for(n=i=0,c=r.length;0<=c?i<c:c<i;n=0<=c?++i:--i)(a=r[n]).originalValid&&a.valid&&a.intersects&&triangleIntersectsTriangle(e.triangle,a.triangle)&&t.push(a)}for(n=s=0,u=this.subTrees.length;0<=u?s<u:u<s;n=0<=u?++s:--s)this.subTrees[n].getPolygonsIntersectingPolygon(e,t);return t}getRayPolygons(e,t=[]){var r,n,o,i,s;if(0<this.polygons.length)for(r=n=0,i=this.polygons.length;0<=i?n<i:i<n;r=0<=i?++n:--n)this.polygons[r].valid&&this.polygons[r].originalValid&&-1===t.indexOf(this.polygons[r])&&t.push(this.polygons[r]);for(0<this.replacedPolygons.length&&t.push(...this.replacedPolygons),r=o=0,s=this.subTrees.length;0<=s?o<s:s<o;r=0<=s?++o:--o)e.intersectsBox(this.subTrees[r].box)&&this.subTrees[r].getRayPolygons(e,t);return t}rayIntersect(e,t,r=[]){var n,o,i,s,a,l,c;if(0===e.direction.length())return[];for(n=1e100,o=i=0,l=(a=this.getRayPolygons(e)).length;0<=l?i<l:l<i;o=0<=l?++i:--i)c=void 0,"regular"===Polytree.rayIntersectTriangleType?(c=e.intersectTriangle(a[o].triangle.a,a[o].triangle.b,a[o].triangle.c,!1,tempVector1))&&(tempVector1.applyMatrix4(t),(n=tempVector1.distanceTo(e.origin))<0||1/0<n?console.warn("[rayIntersect] Failed ray distance check",e):r.push({distance:n,polygon:a[o],position:tempVector1.clone()})):(c=rayIntersectsTriangle(e,a[o].triangle,tempVector1))&&(n=(s=c.clone().sub(e.origin).length())<n?s:n)<1e100&&r.push({distance:n,polygon:a[o],position:c.clone().add(e.origin)});return r.length&&r.sort(raycastIntersectAscSort),r}getIntersectingPolygons(i=[]){return this.polygonArrays.forEach(function(e){var t,r,n,o;if(e.length){for(o=[],t=r=0,n=e.length;0<=n?r<n:n<r;t=0<=n?++r:--r)e[t].valid&&e[t].intersects?o.push(i.push(e[t])):o.push(void 0);return o}}),i}getPolygons(i=[]){return this.polygonArrays.forEach(function(e){var t,r,n,o;if(e.length){for(o=[],t=r=0,n=e.length;0<=n?r<n:n<r;t=0<=n?++r:--r)e[t].valid&&-1===i.indexOf(e[t])?o.push(i.push(e[t])):o.push(void 0);return o}}),i}invert(){return this.polygonArrays.forEach(function(e){if(e.length)return e.forEach(function(e){return e.flip()})})}getMesh(){return this.parent?this.parent.getMesh():this.mesh}replacePolygon(e,t){var r,n,o,i,s;for(Array.isArray(t)||(t=[t]),0<this.polygons.length&&-1<(o=this.polygons.indexOf(e))&&(!0===e.originalValid?this.replacedPolygons.push(e):e.setInvalid(),this.polygons.splice(o,1,...t)),s=[],r=n=0,i=this.subTrees.length;0<=i?n<i:i<n;r=0<=i?++n:--n)s.push(this.subTrees[r].replacePolygon(e,t));return s}deletePolygonsByStateRules(p,g=!0){return this.polygonArrays.forEach(function(h){if(h.length)return h.filter(function(e){return!0===e.valid&&!0===e.intersects}).forEach(function(e){for(var t,r,n,o,i,s,a,l,c=!1,u=r=0,y=p.length;0<=y?r<y:y<r;u=0<=y?++r:--r)if(p[u].array){if((a=p[u].rule).includes(e.state)&&("undecided"!==e.previousState&&a.includes(e.previousState)||"undecided"===e.previousState)){for(c=!0,l={},a.forEach(function(e){return l[e]=!1}),a.forEach(function(e){return e,!1}),l[e.state]=!0,t=n=0,i=e.previousStates.length;0<=i?n<i:i<n;t=0<=i?++n:--n){if(!a.includes(e.previousStates[t])){c=!1;break}l[e.previousStates[t]]=!0}if(c){for(s in l)if(!1===l[s]){c=!1;break}if(c)break}}}else if(e.checkAllStates(p[u].rule)){c=!0;break}if(c&&(-1<(o=h.indexOf(e))&&(e.setInvalid(),h.splice(o,1)),g))return e.delete()})})}deletePolygonsByIntersection(n,o=!0){if(void 0!==n)return this.polygonArrays.forEach(function(r){if(r.length)return r.slice().forEach(function(e){var t;if(e.valid&&e.intersects===n&&(-1<(t=r.indexOf(e))&&(e.setInvalid(),r.splice(t,1)),o))return e.delete()})})}isPolygonIntersecting(e){return!!this.box.intersectsTriangle(e.triangle)}markIntesectingPolygons(t){return this.polygonArrays.forEach(function(e){if(e.length)return e.forEach(function(e){return e.intersects=t.isPolygonIntersecting(e)})})}resetPolygons(t=!0){return this.polygonArrays.forEach(function(e){if(e.length)return e.forEach(function(e){return e.reset(t)})})}handleIntersectingPolygons(e,t){var r,n,o,i,s,a,l,c,u,y,h,p,g,d,m,P,f,b,v,V,x,S;if(0<this.polygons.length){for(r=(g=this.polygons.filter(function(e){return!0===e.valid&&!0===e.intersects&&"undecided"===e.state})).pop();r;)if("undecided"===r.state&&r.valid){if(0<(S=e.getPolygonsIntersectingPolygon(r)).length)for(s=a=0,d=S.length;0<=d?a<d:d<a;s=0<=d?++a:--a){if(x=S[s],1<(V=splitPolygonByPlane(r,x.plane)).length){for(n=l=0,m=V.length;0<=m?l<m:m<l;n=0<=m?++l:--l)(p=V[n].polygon).intersects=r.intersects,p.newPolygon=!0,g.push(p);this.replacePolygon(r,V.map(function(e){return e.polygon}));break}if(r.id!==V[0].polygon.id){V[0].polygon.intersects=r.intersects,V[0].polygon.newPolygon=!0,g.push(V[0].polygon),this.replacePolygon(r,V[0].polygon);break}"coplanar-front"!==V[0].type&&"coplanar-back"!==V[0].type||(r.setState(V[0].type),r.coplanar=!0)}r=g.pop()}for(r=(g=this.polygons.filter(function(e){return!0===e.valid&&!0===e.intersects})).pop(),o=!1;r;)if(r.valid){if(o=!1,e.box.containsPoint(r.getMidpoint()))if(!0===Polytree.useWindingNumber)o=polyInside_WindingNumber_buffer(t,r.getMidpoint(),r.coplanar);else if(h=pointRounding(tempVector2.copy(r.getMidpoint())),!0!==Polytree.usePolytreeRay&&e.mesh){if(tempRayDirection.copy(r.plane.normal),tempRaycaster.set(h,tempRayDirection),!(o=(i=tempRaycaster.intersectObject(e.mesh)).length&&0<tempRayDirection.dot(i[0].face.normal)?!0:o)&&r.coplanar)for(s=c=0,P=_wP_EPS_ARR_COUNT;0<=P?c<P:P<c;s=0<=P?++c:--c)if(tempRaycaster.ray.origin.copy(h).add(_wP_EPS_ARR[s]),(i=tempRaycaster.intersectObject(e.mesh)).length&&0<tempRayDirection.dot(i[0].face.normal)){o=!0;break}}else if(tempRay.origin.copy(h),tempRayDirection.copy(r.plane.normal),tempRay.direction.copy(r.plane.normal),!(o=(i=e.rayIntersect(tempRay,e.originalMatrixWorld)).length&&0<tempRayDirection.dot(i[0].polygon.plane.normal)?!0:o)&&r.coplanar)for(s=u=0,f=_wP_EPS_ARR_COUNT;0<=f?u<f:f<u;s=0<=f?++u:--u)if(tempRay.origin.copy(h).add(_wP_EPS_ARR[s]),tempRayDirection.copy(r.plane.normal),tempRay.direction.copy(r.plane.normal),(i=e.rayIntersect(tempRay,e.originalMatrixWorld)).length&&0<tempRayDirection.dot(i[0].polygon.plane.normal)){o=!0;break}!0===o?r.setState("inside"):r.setState("outside"),r=g.pop()}}for(v=[],n=y=0,b=this.subTrees.length;0<=b?y<b:b<y;n=0<=b?++y:--y)v.push(this.subTrees[n].handleIntersectingPolygons(e,t));return v}delete(e=!0){var t,r,n;if(0<this.polygons.length&&e&&(this.polygons.forEach(function(e){return e.delete()}),this.polygons.length=0),0<this.replacedPolygons.length&&e&&(this.replacedPolygons.forEach(function(e){return e.delete()}),this.replacedPolygons.length=0),this.polygonArrays&&(this.polygonArrays.length=0),this.subTrees.length){for(t=r=0,n=this.subTrees.length;0<=n?r<n:n<r;t=0<=n?++r:--r)this.subTrees[t].delete(e);this.subTrees.length=0}return this.mesh=void 0,this.originalMatrixWorld=void 0,this.box=void 0,this.parent=void 0,this.level=void 0}dispose(e=!0){return this.delete(e)}getPolygonCloneCallback(i,s){return this.polygonArrays.forEach(function(e){var t,r,n,o;if(e.length){for(o=[],t=r=0,n=e.length;0<=n?r<n:n<r;t=0<=n?++r:--r)e[t].valid?o.push(i(e[t].clone(),s)):o.push(void 0);return o}})}deleteReplacedPolygons(){var e,t,r,n;for(0<this.replacedPolygons.length&&(this.replacedPolygons.forEach(function(e){return e.delete()}),this.replacedPolygons.length=0),n=[],e=t=0,r=this.subTrees.length;0<=r?t<r:r<t;e=0<=r?++t:--t)n.push(this.subTrees[e].deleteReplacedPolygons());return n}markPolygonsAsOriginal(){return this.polygonArrays.forEach(function(e){if(e.length)return e.forEach(function(e){return e.originalValid=!0})})}applyMatrix(e,t,r=!0){var n,o,i,s,a;if(e.isMesh&&(e.updateMatrix(),e=e.matrix),this.box.makeEmpty(),t=t||tmpm3.getNormalMatrix(e),0<this.polygons.length)for(n=o=0,s=this.polygons.length;0<=s?o<s:s<o;n=0<=s?++o:--o)this.polygons[n].valid&&this.polygons[n].applyMatrix(e,t);for(n=i=0,a=this.subTrees.length;0<=a?i<a:a<i;n=0<=a?++i:--i)this.subTrees[n].applyMatrix(e,t,!1);if(r)return this.processTree()}setPolygonIndex(t){if(void 0!==t)return this.polygonArrays.forEach(function(e){if(e.length)return e.forEach(function(e){return e.shared=t})})}}).prototype.isPolytree=!0,CSG_Rules={union:{a:[{array:!0,rule:["inside","coplanar-back"]},{array:!(splitPolygonArr=function(e){var t,r,n,o,i=[];if(4<e.length)for(console.warn("[splitPolygonArr] arr.length > 4",e.length),t=r=3,n=e.length;3<=n?r<=n:n<=r;t=3<=n?++r:--r)(o=[]).push(e[0].clone()),o.push(e[t-2].clone()),o.push(e[t-1].clone()),i.push(o);else e[0].pos.distanceTo(e[2].pos)<=e[1].pos.distanceTo(e[3].pos)?i.push([e[0].clone(),e[1].clone(),e[2].clone()],[e[0].clone(),e[2].clone(),e[3].clone()]):i.push([e[0].clone(),e[1].clone(),e[3].clone()],[e[1].clone(),e[2].clone(),e[3].clone()]);return i}),rule:"inside"}],b:[{array:!0,rule:["inside","coplanar-back"]},{array:!0,rule:["inside","coplanar-front"]},{array:!(splitPolygonByPlane=function(e,t,r=[]){for(var n,o,i,s,a,l,c,u,y,h,p,g,d,m,P,f,b={polygon:e,type:"undecided"},v=0,V=[],x=a=0,S=e.vertices.length;0<=S?a<S:S<a;x=0<=S?++a:--a)v|=P=(P=t.normal.dot(e.vertices[x].pos)-t.w)<-EPSILON?BACK:EPSILON<P?FRONT:COPLANAR,V.push(P);switch(v){case COPLANAR:b.type=0<t.normal.dot(e.plane.normal)?"coplanar-front":"coplanar-back",r.push(b);break;case FRONT:b.type="front",r.push(b);break;case BACK:b.type="back",r.push(b);break;case SPANNING:for(i=[],n=[],x=l=0,g=e.vertices.length;0<=g?l<g:g<l;x=0<=g?++l:--l)f=V[h=(x+1)%e.vertices.length],o=e.vertices[x],h=e.vertices[h],(s=V[x])!==BACK&&i.push(o),s!==FRONT&&n.push(s!==BACK?o.clone():o),(s|f)===SPANNING&&(s=(t.w-t.normal.dot(o.pos))/t.normal.dot(triangleVertex0.copy(h.pos).sub(o.pos)),f=o.interpolate(h,s),i.push(f),n.push(f.clone()));if(3<=i.length)if(3<i.length)for(p=c=0,d=(y=splitPolygonArr(i)).length;0<=d?c<d:d<c;p=0<=d?++c:--c)r.push({polygon:new Polygon(y[p],e.shared),type:"front"});else r.push({polygon:new Polygon(i,e.shared),type:"front"});if(3<=n.length)if(3<n.length)for(p=u=0,m=(y=splitPolygonArr(n)).length;0<=m?u<m:m<u;p=0<=m?++u:--u)r.push({polygon:new Polygon(y[p],e.shared),type:"back"});else r.push({polygon:new Polygon(n,e.shared),type:"back"})}return 0===r.length&&r.push(b),r}),rule:"inside"}]},subtract:{a:[{array:!0,rule:["inside","coplanar-back"]},{array:!0,rule:["inside","coplanar-front"]},{array:!(pointRounding=function(e,t=15){return e.x=+e.x.toFixed(t),e.y=+e.y.toFixed(t),e.z=+e.z.toFixed(t),e}),rule:"inside"}],b:[{array:!0,rule:["outside","coplanar-back"]},{array:!0,rule:["outside","coplanar-front"]},{array:!0,rule:["inside","coplanar-front"]},{array:!(raycastIntersectAscSort=function(e,t){return e.distance-t.distance}),rule:"outside"}]},intersect:{a:[{array:!0,rule:["inside","coplanar-back"]},{array:!0,rule:["outside","coplanar-front"]},{array:!0,rule:["outside","coplanar-back"]},{array:!1,rule:"outside"}],b:[{array:!0,rule:["inside","coplanar-front"]},{array:!0,rule:["inside","coplanar-back"]},{array:!0,rule:["outside","coplanar-front"]},{array:!0,rule:["outside","coplanar-back"]},{array:!1,rule:"outside"}]}},Polytree.union=function(e,t,r=!0){var n,o,i=new Polytree,s=new Set;return e.box.intersectsBox(t.box)?(o=n=void 0,e.mesh&&(n=e.mesh.material.side,e.mesh.material.side=DoubleSide),t.mesh&&(o=t.mesh.material.side,t.mesh.material.side=DoubleSide),e.resetPolygons(!1),t.resetPolygons(!1),e.markIntesectingPolygons(t),t.markIntesectingPolygons(e),handleIntersectingPolytrees(e,t),e.deleteReplacedPolygons(),t.deleteReplacedPolygons(),e.deletePolygonsByStateRules(CSG_Rules.union.a),t.deletePolygonsByStateRules(CSG_Rules.union.b),e.getPolygonCloneCallback(i.addPolygon.bind(i),s),t.getPolygonCloneCallback(i.addPolygon.bind(i),s),e.mesh&&e.mesh.material.side!==n&&(e.mesh.material.side=n),t.mesh&&t.mesh.material.side!==o&&(t.mesh.material.side=o)):(e.getPolygonCloneCallback(i.addPolygon.bind(i),s),t.getPolygonCloneCallback(i.addPolygon.bind(i),s)),s.clear(),s=void 0,i.markPolygonsAsOriginal(),r&&i.buildTree(),i},Polytree.subtract=function(e,t,r=!0){var n,o,i=new Polytree,s=new Set;return e.box.intersectsBox(t.box)?(o=n=void 0,e.mesh&&(n=e.mesh.material.side,e.mesh.material.side=DoubleSide),t.mesh&&(o=t.mesh.material.side,t.mesh.material.side=DoubleSide),e.resetPolygons(!1),t.resetPolygons(!1),e.markIntesectingPolygons(t),t.markIntesectingPolygons(e),handleIntersectingPolytrees(e,t),e.deleteReplacedPolygons(),t.deleteReplacedPolygons(),e.deletePolygonsByStateRules(CSG_Rules.subtract.a),t.deletePolygonsByStateRules(CSG_Rules.subtract.b),t.deletePolygonsByIntersection(!1),t.invert(),e.getPolygonCloneCallback(i.addPolygon.bind(i),s),t.getPolygonCloneCallback(i.addPolygon.bind(i),s),e.mesh&&e.mesh.material.side!==n&&(e.mesh.material.side=n),t.mesh&&t.mesh.material.side!==o&&(t.mesh.material.side=o)):e.getPolygonCloneCallback(i.addPolygon.bind(i),s),s.clear(),s=void 0,i.markPolygonsAsOriginal(),r&&i.buildTree(),i},CSG_Rules={union:{a:[{array:!0,rule:["inside","coplanar-back"]},{array:!(Polytree.intersect=function(e,t,r=!0){var n,o,i=new Polytree,s=new Set;return e.box.intersectsBox(t.box)&&(o=n=void 0,e.mesh&&(n=e.mesh.material.side,e.mesh.material.side=DoubleSide),t.mesh&&(o=t.mesh.material.side,t.mesh.material.side=DoubleSide),e.resetPolygons(!1),t.resetPolygons(!1),e.markIntesectingPolygons(t),t.markIntesectingPolygons(e),handleIntersectingPolytrees(e,t),e.deleteReplacedPolygons(),t.deleteReplacedPolygons(),e.deletePolygonsByStateRules(CSG_Rules.intersect.a),t.deletePolygonsByStateRules(CSG_Rules.intersect.b),e.deletePolygonsByIntersection(!1),t.deletePolygonsByIntersection(!1),e.getPolygonCloneCallback(i.addPolygon.bind(i),s),t.getPolygonCloneCallback(i.addPolygon.bind(i),s),e.mesh&&e.mesh.material.side!==n&&(e.mesh.material.side=n),t.mesh)&&t.mesh.material.side!==o&&(t.mesh.material.side=o),s.clear(),s=void 0,i.markPolygonsAsOriginal(),r&&i.buildTree(),i}),rule:"inside"}],b:[{array:!0,rule:["inside","coplanar-back"]},{array:!0,rule:["inside","coplanar-front"]},{array:!1,rule:"inside"}]},subtract:{a:[{array:!0,rule:["inside","coplanar-back"]},{array:!0,rule:["inside","coplanar-front"]},{array:!1,rule:"inside"}],b:[{array:!0,rule:["outside","coplanar-back"]},{array:!0,rule:["outside","coplanar-front"]},{array:!0,rule:["inside","coplanar-front"]},{array:!1,rule:"outside"}]},intersect:{a:[{array:!0,rule:["inside","coplanar-back"]},{array:!0,rule:["outside","coplanar-front"]},{array:!0,rule:["outside","coplanar-back"]},{array:!1,rule:"outside"}],b:[{array:!0,rule:["inside","coplanar-front"]},{array:!0,rule:["inside","coplanar-back"]},{array:!0,rule:["outside","coplanar-front"]},{array:!0,rule:["outside","coplanar-back"]},{array:!1,rule:"outside"}]}},Polytree.union=function(e,t,r=!0){var n,o,i=new Polytree,s=new Set;return e.box.intersectsBox(t.box)?(o=n=void 0,e.mesh&&(n=e.mesh.material.side,e.mesh.material.side=DoubleSide),t.mesh&&(o=t.mesh.material.side,t.mesh.material.side=DoubleSide),e.resetPolygons(!1),t.resetPolygons(!1),e.markIntesectingPolygons(t),t.markIntesectingPolygons(e),handleIntersectingPolytrees(e,t),e.deleteReplacedPolygons(),t.deleteReplacedPolygons(),e.deletePolygonsByStateRules(CSG_Rules.union.a),t.deletePolygonsByStateRules(CSG_Rules.union.b),e.getPolygonCloneCallback(i.addPolygon.bind(i),s),t.getPolygonCloneCallback(i.addPolygon.bind(i),s),e.mesh&&e.mesh.material.side!==n&&(e.mesh.material.side=n),t.mesh&&t.mesh.material.side!==o&&(t.mesh.material.side=o)):(e.getPolygonCloneCallback(i.addPolygon.bind(i),s),t.getPolygonCloneCallback(i.addPolygon.bind(i),s)),s.clear(),s=void 0,i.markPolygonsAsOriginal(),r&&i.buildTree(),i},Polytree.subtract=function(e,t,r=!0){var n,o,i=new Polytree,s=new Set;return e.box.intersectsBox(t.box)?(o=n=void 0,e.mesh&&(n=e.mesh.material.side,e.mesh.material.side=DoubleSide),t.mesh&&(o=t.mesh.material.side,t.mesh.material.side=DoubleSide),e.resetPolygons(!1),t.resetPolygons(!1),e.markIntesectingPolygons(t),t.markIntesectingPolygons(e),handleIntersectingPolytrees(e,t),e.deleteReplacedPolygons(),t.deleteReplacedPolygons(),e.deletePolygonsByStateRules(CSG_Rules.subtract.a),t.deletePolygonsByStateRules(CSG_Rules.subtract.b),t.deletePolygonsByIntersection(!1),t.invert(),e.getPolygonCloneCallback(i.addPolygon.bind(i),s),t.getPolygonCloneCallback(i.addPolygon.bind(i),s),e.mesh&&e.mesh.material.side!==n&&(e.mesh.material.side=n),t.mesh&&t.mesh.material.side!==o&&(t.mesh.material.side=o)):e.getPolygonCloneCallback(i.addPolygon.bind(i),s),s.clear(),s=void 0,i.markPolygonsAsOriginal(),r&&i.buildTree(),i},Polytree.intersect=function(e,t,r=!0){var n,o,i=new Polytree,s=new Set;return e.box.intersectsBox(t.box)&&(o=n=void 0,e.mesh&&(n=e.mesh.material.side,e.mesh.material.side=DoubleSide),t.mesh&&(o=t.mesh.material.side,t.mesh.material.side=DoubleSide),e.resetPolygons(!1),t.resetPolygons(!1),e.markIntesectingPolygons(t),t.markIntesectingPolygons(e),handleIntersectingPolytrees(e,t),e.deleteReplacedPolygons(),t.deleteReplacedPolygons(),e.deletePolygonsByStateRules(CSG_Rules.intersect.a),t.deletePolygonsByStateRules(CSG_Rules.intersect.b),e.deletePolygonsByIntersection(!1),t.deletePolygonsByIntersection(!1),e.getPolygonCloneCallback(i.addPolygon.bind(i),s),t.getPolygonCloneCallback(i.addPolygon.bind(i),s),e.mesh&&e.mesh.material.side!==n&&(e.mesh.material.side=n),t.mesh)&&t.mesh.material.side!==o&&(t.mesh.material.side=o),s.clear(),s=void 0,i.markPolygonsAsOriginal(),r&&i.buildTree(),i},Polytree.meshUnion=function(e,t,r){var n=void 0,o=void 0;return r&&Array.isArray(r)?(n=Polytree.fromMesh(e,0),o=Polytree.fromMesh(t,1)):(n=Polytree.fromMesh(e),o=Polytree.fromMesh(t),r=void 0!==r?r:(Array.isArray(e.material)?e.material[0]:e.material).clone()),t=Polytree.union(n,o,!1),e=Polytree.toMesh(t,r),disposePolytree(n,o,t),e},Polytree.meshSubtract=function(e,t,r){var n=void 0,o=void 0;return r&&Array.isArray(r)?(n=Polytree.fromMesh(e,0),o=Polytree.fromMesh(t,1)):(n=Polytree.fromMesh(e),o=Polytree.fromMesh(t),r=void 0!==r?r:(Array.isArray(e.material)?e.material[0]:e.material).clone()),t=Polytree.subtract(n,o,!1),e=Polytree.toMesh(t,r),disposePolytree(n,o,t),e},Polytree.meshIntersect=function(e,t,r){var n=void 0,o=void 0;return r&&Array.isArray(r)?(n=Polytree.fromMesh(e,0),o=Polytree.fromMesh(t,1)):(n=Polytree.fromMesh(e),o=Polytree.fromMesh(t),r=void 0!==r?r:(Array.isArray(e.material)?e.material[0]:e.material).clone()),t=Polytree.intersect(n,o,!1),e=Polytree.toMesh(t,r),disposePolytree(n,o,t),e},Polytree.disposePolytree=!(_asyncUnionArrayID=_asyncUnionID=0),Polytree.async={batchSize:100,union:function(r,n,o=!0){return new Promise(function(e,t){try{return e(Polytree.union(r,n,o)),disposePolytree(r,n)}catch(e){return t(e)}})},subtract:function(r,n,o=!0){return new Promise(function(e,t){try{return e(Polytree.subtract(r,n,o)),disposePolytree(r,n)}catch(e){return t(e)}})},intersect:function(r,n,o=!0){return new Promise(function(e,t){try{return e(Polytree.intersect(r,n,o)),disposePolytree(r,n)}catch(e){return t(e)}})},unionArray:function(b,v=1/0){return new Promise(function(r,n){var e,t,o,i,s,a,l,c,u,y,h,p,g,d,m,P,f;try{if(f=4<Polytree.async.batchSize&&Polytree.async.batchSize<b.length,c=void 0,u=!1,g=[],f){for(t=[],o=0;o<b.length;)t.push(b.slice(o,o+Polytree.async.batchSize)),o+=Polytree.async.batchSize;for(e=t.shift();e;)p=Polytree.async.unionArray(e,0),g.push(p),e=t.shift();u=f=!0,b.length=0}else{for(h=[],i=s=0,d=b.length;0<=d?s<d:d<s;i=0<=d?++s:--s)y=v<i?v:i,P=void 0,b[i].isMesh?P=Polytree.fromMesh(b[i],-1<v?y:void 0):(P=b[i],-1<v&&P.setPolygonIndex(y)),P.polytreeIndex=i,h.push(P);for(c=h.shift(),l=void 0,i=a=0,m=h.length;a<m;i=a+=2){if(h.length<=i+1){l=h[i];break}p=Polytree.async.union(h[i],h[i+1]),g.push(p)}l&&(p=Polytree.async.union(c,l),g.push(p),u=!0)}return Promise.allSettled(g).then(function(e){var t=[];return e.forEach(function(e){if("fulfilled"===e.status)return t.push(e.value)}),u||t.unshift(c),0<t.length?1===t.length?r(t[0]):3<t.length?Polytree.async.unionArray(t,f?0:-1).then(function(e){return r(e)}).catch(function(e){return n(e)}):Polytree.async.union(t[0],t[1]).then(function(e){return 3===t.length?Polytree.async.union(e,t[2]).then(function(e){return r(e)}).catch(function(e){return n(e)}):r(e)}).catch(function(e){return n(e)}):n("Unable to find any result polytree")})}catch(e){return n(e)}})},subtractArray:function(b,v=1/0){return new Promise(function(r,n){var e,t,o,i,s,a,l,c,u,y,h,p,g,d,m,P,f;try{if(f=4<Polytree.async.batchSize&&Polytree.async.batchSize<b.length,c=void 0,u=!1,g=[],f){for(t=[],o=0;o<b.length;)t.push(b.slice(o,o+Polytree.async.batchSize)),o+=Polytree.async.batchSize;for(e=t.shift();e;)p=Polytree.async.subtractArray(e,0),g.push(p),e=t.shift();u=f=!0,b.length=0}else{for(h=[],i=s=0,d=b.length;0<=d?s<d:d<s;i=0<=d?++s:--s)y=v<i?v:i,P=void 0,b[i].isMesh?P=Polytree.fromMesh(b[i],-1<v?y:void 0):(P=b[i],-1<v&&P.setPolygonIndex(y)),P.polytreeIndex=i,h.push(P);for(c=h.shift(),l=void 0,i=a=0,m=h.length;a<m;i=a+=2){if(h.length<=i+1){l=h[i];break}p=Polytree.async.subtract(h[i],h[i+1]),g.push(p)}l&&(p=Polytree.async.subtract(c,l),g.push(p),u=!0)}return Promise.allSettled(g).then(function(e){var t=[];return e.forEach(function(e){if("fulfilled"===e.status)return t.push(e.value)}),u||t.unshift(c),0<t.length?1===t.length?r(t[0]):3<t.length?Polytree.async.subtractArray(t,f?0:-1).then(function(e){return r(e)}).catch(function(e){return n(e)}):Polytree.async.subtract(t[0],t[1]).then(function(e){return 3===t.length?Polytree.async.subtract(e,t[2]).then(function(e){return r(e)}).catch(function(e){return n(e)}):r(e)}).catch(function(e){return n(e)}):n("Unable to find any result polytree")})}catch(e){return n(e)}})},intersectArray:function(b,v=1/0){return new Promise(function(r,n){var e,t,o,i,s,a,l,c,u,y,h,p,g,d,m,P,f;try{if(f=4<Polytree.async.batchSize&&Polytree.async.batchSize<b.length,c=void 0,u=!1,g=[],f){for(t=[],o=0;o<b.length;)t.push(b.slice(o,o+Polytree.async.batchSize)),o+=Polytree.async.batchSize;for(e=t.shift();e;)p=Polytree.async.intersectArray(e,0),g.push(p),e=t.shift();u=f=!0,b.length=0}else{for(h=[],i=s=0,d=b.length;0<=d?s<d:d<s;i=0<=d?++s:--s)y=v<i?v:i,P=void 0,b[i].isMesh?P=Polytree.fromMesh(b[i],-1<v?y:void 0):(P=b[i],-1<v&&P.setPolygonIndex(y)),P.polytreeIndex=i,h.push(P);for(c=h.shift(),l=void 0,i=a=0,m=h.length;a<m;i=a+=2){if(h.length<=i+1){l=h[i];break}p=Polytree.async.intersect(h[i],h[i+1]),g.push(p)}l&&(p=Polytree.async.intersect(c,l),g.push(p),u=!0)}return Promise.allSettled(g).then(function(e){var t=[];return e.forEach(function(e){if("fulfilled"===e.status)return t.push(e.value)}),u||t.unshift(c),0<t.length?1===t.length?r(t[0]):3<t.length?Polytree.async.intersectArray(t,f?0:-1).then(function(e){return r(e)}).catch(function(e){return n(e)}):Polytree.async.intersect(t[0],t[1]).then(function(e){return 3===t.length?Polytree.async.intersect(e,t[2]).then(function(e){return r(e)}).catch(function(e){return n(e)}):r(e)}).catch(function(e){return n(e)}):n("Unable to find any result polytree")})}catch(e){return n(e)}})},operation:function(a,l=!1,c=!0,u={objCounter:0},y=!0){return new Promise(function(r,n){var o,i,s,e,t;try{return o=s=i=void 0,a.material&&(o=a.material),t=[],a.objA&&(e=handleObjectForOp_async(a.objA,l,c,u,0),t.push(e)),a.objB&&(e=handleObjectForOp_async(a.objB,l,c,u,1),t.push(e)),Promise.allSettled(t).then(function(e){var t;switch(e.forEach(function(e){if("fulfilled"===e.status)return 0===e.value.objIndex?i=e.value:1===e.value.objIndex?s=e.value:void 0}),!0===l&&(a.objA=i.original,i=i.result,a.objB=s.original,s=s.result),t=void 0,a.op){case"union":t=Polytree.async.union(i,s,c);break;case"subtract":t=Polytree.async.subtract(i,s,c);break;case"intersect":t=Polytree.async.intersect(i,s,c)}return t.then(function(e){var t;if(y&&o?(t=Polytree.toMesh(e,o),l||disposePolytree(e),r(l?{result:t,operationTree:a}:t)):r(y&&l?{result:e,operationTree:a}:e),!l)return disposePolytree(i,s)}).catch(function(e){return n(e)})})}catch(e){return n(e)}})}},Polytree.unionArray=function(e,t=1/0){for(var r,n,o,i,s,a,l=[],c=r=0,u=e.length;0<=u?r<u:u<r;c=0<=u?++r:--r)n=t<c?t:c,a=void 0,e[c].isMesh?a=Polytree.fromMesh(e[c],n):(a=e[c]).setPolygonIndex(n),a.polytreeIndex=c,l.push(a);for(o=l.shift(),i=l.shift();o&&i;)s=Polytree.union(o,i),disposePolytree(o,i),o=s,i=l.shift();return o},Polytree.subtractArray=function(e,t=1/0){for(var r,n,o,i,s,a,l=[],c=r=0,u=e.length;0<=u?r<u:u<r;c=0<=u?++r:--r)n=t<c?t:c,a=void 0,e[c].isMesh?a=Polytree.fromMesh(e[c],n):(a=e[c]).setPolygonIndex(n),a.polytreeIndex=c,l.push(a);for(o=l.shift(),i=l.shift();o&&i;)s=Polytree.subtract(o,i),disposePolytree(o,i),o=s,i=l.shift();return o},Polytree.intersectArray=function(e,t=1/0){for(var r,n,o,i,s,a,l=[],c=r=0,u=e.length;0<=u?r<u:u<r;c=0<=u?++r:--r)n=t<c?t:c,a=void 0,e[c].isMesh?a=Polytree.fromMesh(e[c],n):(a=e[c]).setPolygonIndex(n),a.polytreeIndex=c,l.push(a);for(o=l.shift(),i=l.shift();o&&i;)s=Polytree.intersect(o,i),disposePolytree(o,i),o=s,i=l.shift();return o},Polytree.operation=function(e,t=!1,r=!0,n={objCounter:0},o=!0){var i=void 0,s=void 0,a=void 0,l=void 0;switch(e.material&&(l=e.material),e.objA&&(i=handleObjectForOp(e.objA,t,r,n),!0===t)&&(e.objA=i.original,i=i.result),e.objB&&(s=handleObjectForOp(e.objB,t,r,n),!0===t)&&(e.objB=s.original,s=s.result),e.op){case"union":a=Polytree.union(i,s,r);break;case"subtract":a=Polytree.subtract(i,s,r);break;case"intersect":a=Polytree.intersect(i,s,r)}return t||disposePolytree(i,s),o&&l?(n=Polytree.toMesh(a,l),disposePolytree(a),t?{result:n,operationTree:e}:n):o&&t?{result:a,operationTree:e}:a},handleObjectForOp=function(e,t,r,n){var o=void 0;return e.isMesh?(o=Polytree.fromMesh(e,n.objCounter++),t&&(o={result:o,original:o.clone()})):e.isPolytree?(o=e,t&&(o={result:e,original:e.clone()})):e.op&&(o=Polytree.operation(e,t,r,n,!1),t)&&(o={result:o,original:e}),o},handleObjectForOp_async=function(n,o,i,s,a){return new Promise(function(t,r){var e;try{return e=void 0,n.isMesh?(e=Polytree.fromMesh(n,s.objCounter++),(e=o?{result:e,original:e.clone()}:e).objIndex=a,t(e)):n.isPolytree?(e=n,(e=o?{result:n,original:n.clone()}:e).objIndex=a,t(e)):n.op?Polytree.async.operation(n,o,i,s,!1).then(function(e){return(e=o?{result:e,original:n}:e).objIndex=a,t(e)}):void 0}catch(e){return r(e)}})},isUniqueTriangle=function(e,t,r){var n=`{${e.a.x},${e.a.y},${e.a.z}}-{${e.b.x},${e.b.y},${e.b.z}}-{${e.c.x},${e.c.y},${e.c.z}}`;return!0!==t.has(n)&&(t.add(n),r&&r.set(e,e),!0)},nbuf3=function(e){return{top:0,array:new Float32Array(e),write:function(e){return this.array[this.top++]=e.x,this.array[this.top++]=e.y,this.array[this.top++]=e.z}}},nbuf2=function(e){return{top:0,array:new Float32Array(e),write:function(e){return this.array[this.top++]=e.x,this.array[this.top++]=e.y}}},_normal1=new Vector3,tmpm3=new Matrix3,ttvv0=new Vector3,Polytree.toGeometry=function(e){for(var t,r,n,o,i,s,a,l,c,u,y,h=e.getPolygons(),p=h.length,g=nbuf3(3*p*3),d=nbuf3(3*p*3),m=void 0,P=void 0,f=[],b=[],v=0,V=h.length;v<V;v++)for(y=(u=(a=h[v]).vertices).length,void 0===a.shared||f[a.shared]||(f[a.shared]=[]),0<y&&(void 0!==u[0].uv&&(m=m||nbuf2(2*p*3)),void 0!==u[0].color)&&(P=P||nbuf3(3*p*3)),n=i=3,l=y;3<=l?i<=l:l<=i;n=3<=l?++i:--i)(void 0===a.shared?b:f[a.shared]).push(g.top/3,g.top/3+1,g.top/3+2),g.write(u[0].pos),g.write(u[n-2].pos),g.write(u[n-1].pos),d.write(u[0].normal),d.write(u[n-2].normal),d.write(u[n-1].normal),null!=m&&(m.write(u[0].uv),m.write(u[n-2].uv),m.write(u[n-1].uv)),null!=P&&(P.write(u[0].color),P.write(u[n-2].color),P.write(u[n-1].color));if((t=new BufferGeometry).setAttribute("position",new BufferAttribute(g.array,3)),t.setAttribute("normal",new BufferAttribute(d.array,3)),m&&t.setAttribute("uv",new BufferAttribute(m.array,2)),P&&t.setAttribute("color",new BufferAttribute(P.array,3)),0<f.length){for(o=[],n=s=r=0,c=f.length;0<=c?s<c:c<s;n=0<=c?++s:--s)f[n]=f[n]||[],t.addGroup(r,f[n].length,n),r+=f[n].length,o=o.concat(f[n]);b.length&&(t.addGroup(r,b.length,f.length),o=o.concat(b)),t.setIndex(o)}return t},Polytree.toMesh=function(e,t){e=Polytree.toGeometry(e);return new Mesh(e,t)},Polytree.fromMesh=function(e,t,r=new Polytree,n=!0){var o,i,s,a,l,c,u,y,h,p,g,d,m,P,f,b,v,V,x,S,I,w,D,E;if(e.isPolytree)return e;for("regular"===Polytree.rayIntersectTriangleType&&(r.originalMatrixWorld=e.matrixWorld.clone()),e.updateWorldMatrix(!0,!0),i=e.geometry,tmpm3.getNormalMatrix(e.matrix),v=i.attributes.position,m=i.attributes.normal,w=i.attributes.uv,o=i.attributes.color,a=i.groups,f=[],l=y=0,V=(c=i.index?i.index.array:Array(v.array.length/v.itemSize|0).fill().map(function(e,t){return t})).length;y<V;l=y+=3){for(E=[],u=h=0;h<3;u=++h)I=2*(D=c[l+u]),b=new Vector3(v.array[D=3*D],v.array[1+D],v.array[2+D]),D=new Vector3(m.array[D],m.array[1+D],m.array[2+D]),b.applyMatrix4(e.matrix),D.applyMatrix3(tmpm3),S=w?{x:w.array[I],y:w.array[1+I]}:void 0,I=o?{x:o.array[I],y:o.array[1+I],z:o.array[2+I]}:void 0,E.push(new Vertex(b,D,S,I));if(void 0===t&&a&&0<a.length){for(P=void 0,g=0,p=a.length;g<p;g++)s=a[g],c[l]>=s.start&&c[l]<s.start+s.count&&((P=new Polygon(E,s.materialIndex)).originalValid=!0);P&&f.push(P)}else(P=new Polygon(E,t)).originalValid=!0,f.push(P)}for(l=d=0,x=f.length;0<=x?d<x:x<d;l=0<=x?++d:--d)isValidTriangle(f[l].triangle)?r.addPolygon(f[l]):f[l].delete();return n&&r.buildTree(),!0!==Polytree.usePolytreeRay&&(r.mesh=e),r},isValidTriangle=function(e){return!e.a.equals(e.b)&&!e.a.equals(e.c)&&!e.b.equals(e.c)},Vertex=class Vertex{constructor(e,t,r,n){this.pos=(new Vector3).copy(e),this.normal=(new Vector3).copy(t),r&&(this.uv=(new Vector2).copy(r)),n&&(this.color=(new Vector3).copy(n))}clone(){return new Vertex(this.pos.clone(),this.normal.clone(),this.uv&&this.uv.clone(),this.color&&this.color.clone())}flip(){return this.normal.negate()}delete(){return this.pos=void 0,this.normal=void 0,this.uv&&(this.uv=void 0),this.color&&(this.color=void 0)}interpolate(e,t){return new Vertex(this.pos.clone().lerp(e.pos,t),this.normal.clone().lerp(e.normal,t),this.uv&&e.uv&&this.uv.clone().lerp(e.uv,t),this.color&&e.color&&this.color.clone().lerp(e.color,t))}},(Plane=class Plane{constructor(e,t){this.normal=e,this.w=t}clone(){return new Plane(this.normal.clone(),this.w)}flip(){return this.normal.negate(),this.w=-this.w}delete(){return this.normal=void 0,this.w=void 0}equals(e){return this.normal.equals(e.normal)&&this.w===e.w}}).fromPoints=function(e,t,r){t=triangleVertex0.copy(t).sub(e).cross(triangleVertex1.copy(r).sub(e)).normalize().clone();return new Plane(t,t.dot(e))},Polygon=class Polygon{constructor(e,t){this.id=_polygonID++,this.vertices=e.map(function(e){return e.clone()}),this.shared=t,this.plane=Plane.fromPoints(this.vertices[0].pos,this.vertices[1].pos,this.vertices[2].pos),this.triangle=new Triangle(this.vertices[0].pos,this.vertices[1].pos,this.vertices[2].pos),this.intersects=!1,this.state="undecided",this.previousState="undecided",this.previousStates=[],this.valid=!0,this.coplanar=!1,this.originalValid=!1,this.newPolygon=!1}getMidpoint(){return this.triangle.midPoint||(this.triangle.midPoint=this.triangle.getMidpoint(new Vector3))}applyMatrix(t,r){if(r=r||tmpm3.getNormalMatrix(t),this.vertices.forEach(function(e){return e.pos.applyMatrix4(t),e.normal.applyMatrix3(r)}),this.plane.delete(),this.plane=Plane.fromPoints(this.vertices[0].pos,this.vertices[1].pos,this.vertices[2].pos),this.triangle.set(this.vertices[0].pos,this.vertices[1].pos,this.vertices[2].pos),this.triangle.midPoint)return this.triangle.getMidpoint(this.triangle.midPoint)}reset(e=!0){return this.intersects=!1,this.state="undecided",this.previousState="undecided",this.previousStates.length=0,this.valid=!0,this.coplanar=!1,e&&(this.originalValid=!1),this.newPolygon=!1}setState(e,t){if(this.state!==t)return this.previousState=this.state,"undecided"!==this.state&&this.previousStates.push(this.state),this.state=e}checkAllStates(e){var t,r,n;if(this.state!==e||this.previousState!==e&&"undecided"!==this.previousState)return!1;for(t=0,r=(n=this.previousStates).length;t<r;t++)if(n[t]!==e)return!1;return!0}setInvalid(){return this.valid=!1}setValid(){return this.valid=!0}clone(){var e=new Polygon(this.vertices.map(function(e){return e.clone()}),this.shared);return e.intersects=this.intersects,e.valid=this.valid,e.coplanar=this.coplanar,e.state=this.state,e.originalValid=this.originalValid,e.newPolygon=this.newPolygon,e.previousState=this.previousState,e.previousStates=this.previousStates.slice(),this.triangle.midPoint&&(e.triangle.midPoint=this.triangle.midPoint.clone()),e}flip(){var e;return this.vertices.reverse().forEach(function(e){return e.flip()}),e=this.triangle.a,this.triangle.a=this.triangle.c,this.triangle.c=e,this.plane.flip()}delete(){return this.vertices.forEach(function(e){return e.delete()}),this.vertices.length=0,this.plane&&(this.plane.delete(),this.plane=void 0),this.triangle=void 0,this.shared=void 0,this.setInvalid()}},disposePolytree=function(...e){if(Polytree.disposePolytree)return e.forEach(function(e){return e.delete()})},_wV1=new Vector3,_wV2=new Vector3,_wV3=new Vector3,_wP=new Vector3,_wP_EPS_ARR=[new Vector3(EPSILON,0,0),new Vector3(0,EPSILON,0),new Vector3(0,0,EPSILON),new Vector3(-EPSILON,0,0),new Vector3(0,-EPSILON,0),new Vector3(0,0,-EPSILON)],_wP_EPS_ARR_COUNT=_wP_EPS_ARR.length,_matrix3=new Matrix3,wNPI=4*Math.PI,returnXYZ=function(e,t){return{x:e[t],y:e[t+1],z:e[t+2]}},calcWindingNumber_buffer=function(e,t){for(var r,n,o,i,s=0,a=r=0,l=e.length;r<l;a=r+=9)_wV1.subVectors(returnXYZ(e,a),t),_wV2.subVectors(returnXYZ(e,a+3),t),_wV3.subVectors(returnXYZ(e,a+6),t),n=_wV1.length(),o=_wV2.length(),i=_wV3.length(),_matrix3.set(_wV1.x,_wV1.y,_wV1.z,_wV2.x,_wV2.y,_wV2.z,_wV3.x,_wV3.y,_wV3.z),s+=2*Math.atan2(_matrix3.determinant(),n*o*i+_wV1.dot(_wV2)*i+_wV2.dot(_wV3)*n+_wV3.dot(_wV1)*o);return s=Math.round(s/wNPI)},polyInside_WindingNumber_buffer=function(e,t,r){var n,o,i,s=!1;if(_wP.copy(t),0===calcWindingNumber_buffer(e,_wP)){if(r)for(n=o=0,i=_wP_EPS_ARR_COUNT;0<=i?o<i:i<o;n=0<=i?++o:--o)if(_wP.copy(t).add(_wP_EPS_ARR[n]),0!==calcWindingNumber_buffer(e,_wP)){s=!0;break}}else s=!0;return s},handleIntersectingPolytrees=function(e,t,r=!0){var n=void 0,o=void 0;!0===Polytree.useWindingNumber&&(r&&(n=prepareTriangleBuffer(e.getPolygons())),o=prepareTriangleBuffer(t.getPolygons())),e.handleIntersectingPolygons(t,o),r&&t.handleIntersectingPolygons(e,n),void 0!==n&&(n=void 0)},prepareTriangleBuffer=function(e){for(var t,r,n=e.length,o=new Float32Array(3*n*3),i=0,s=t=0,a=n;0<=a?t<a:a<t;s=0<=a?++t:--t)r=e[s].triangle,o[i++]=r.a.x,o[i++]=r.a.y,o[i++]=r.a.z,o[i++]=r.b.x,o[i++]=r.b.y,o[i++]=r.b.z,o[i++]=r.c.x,o[i++]=r.c.y,o[i++]=r.c.z;return o},edge1=new Vector3,edge2=new Vector3,h=new Vector3,s=new Vector3,q=new Vector3,RAY_EPSILON=1e-7,rayIntersectsTriangle=function(e,t,r=new Vector3){var n,o;return edge1.subVectors(t.b,t.a),edge2.subVectors(t.c,t.a),h.crossVectors(e.direction,edge2),n=edge1.dot(h),!(-RAY_EPSILON<n&&n<RAY_EPSILON||(n=1/n,s.subVectors(e.origin,t.a),(t=n*s.dot(h))<0)||1<t||(q.crossVectors(s,edge1),(o=n*e.direction.dot(q))<0)||1<t+o||(t=n*edge2.dot(q),!(RAY_EPSILON<t)))?r.copy(e.direction).multiplyScalar(t).add(e.origin):null},Polytree.rayIntersectsTriangle=rayIntersectsTriangle,Polytree.usePolytreeRay=!0,Polytree.useWindingNumber=!1,Polytree.rayIntersectTriangleType="MollerTrumbore",Polytree.maxLevel=16,Polytree.polygonsPerTree=100,EPS2D=1e-10,tempVector1=new Vector3,tempVector2=new Vector3,tempVector3=new Vector3,pointsEqual2D=function(e,t,r=EPS2D){return Math.abs(e.x-t.x)<=r&&Math.abs(e.y-t.y)<=r},pointOnSegmentInclusive2D=function(e,t,r,n=EPS2D){var o,i,s;return pointsEqual2D(t,r,n)?pointsEqual2D(e,t,n)||pointsEqual2D(e,r,n):!(Math.abs(triangleOrientation2D(e,t,r))>n)&&(i=Math.min(t.x,r.x)-n,o=Math.max(t.x,r.x)+n,s=Math.min(t.y,r.y)-n,t=Math.max(t.y,r.y)+n,e.x>=i)&&e.x<=o&&e.y>=s&&e.y<=t},pointInTriangleInclusive2D=function(e,t,r,n,o=EPS2D){var i,s,a,l=triangleOrientation2D(t,r,n);return o<l?(i=triangleOrientation2D(e,t,r),s=triangleOrientation2D(e,r,n),a=triangleOrientation2D(e,n,t),-o<=i&&-o<=s&&-o<=a):l<-o?(i=triangleOrientation2D(e,t,r),s=triangleOrientation2D(e,r,n),a=triangleOrientation2D(e,n,t),i<=o&&s<=o&&a<=o):pointsEqual2D(t,r,o)&&pointsEqual2D(r,n,o)?pointsEqual2D(e,t,o):pointsEqual2D(t,r,o)?pointOnSegmentInclusive2D(e,r,n,o):pointsEqual2D(r,n,o)||pointsEqual2D(n,t,o)?pointOnSegmentInclusive2D(e,t,r,o):pointOnSegmentInclusive2D(e,t,r,o)||pointOnSegmentInclusive2D(e,r,n,o)||pointOnSegmentInclusive2D(e,n,t,o)},triangleIntersectsTriangle=function(e,t,r={coplanar:!1,source:new Vector3,target:new Vector3}){var n,o,i,s,a,l,c,u,y=e.a,h=e.b,e=e.c,p=t.a,g=t.b,t=t.c;return tempVector1.copy(p).sub(t),tempVector2.copy(g).sub(t),u=(new Vector3).copy(tempVector1).cross(tempVector2),tempVector1.copy(y).sub(t),n=tempVector1.dot(u),tempVector1.copy(h).sub(t),i=tempVector1.dot(u),tempVector1.copy(e).sub(t),a=tempVector1.dot(u),!(0<n*i&&0<n*a||(tempVector1.copy(h).sub(y),tempVector2.copy(e).sub(y),c=(new Vector3).copy(tempVector1).cross(tempVector2),tempVector1.copy(p).sub(e),o=tempVector1.dot(c),tempVector1.copy(g).sub(e),s=tempVector1.dot(c),tempVector1.copy(t).sub(e),l=tempVector1.dot(c),0<o*s&&0<o*l))&&(r.normal1=c,r.normal2=u,0<n?0<i?resolveTriangleIntersection(e,y,h,p,t,g,o,l,s,r):0<a?resolveTriangleIntersection(h,e,y,p,t,g,o,l,s,r):resolveTriangleIntersection(y,h,e,p,g,t,o,s,l,r):n<0?i<0?resolveTriangleIntersection(e,y,h,p,g,t,o,s,l,r):a<0?resolveTriangleIntersection(h,e,y,p,g,t,o,s,l,r):resolveTriangleIntersection(y,h,e,p,t,g,o,l,s,r):i<0?0<=a?resolveTriangleIntersection(h,e,y,p,t,g,o,l,s,r):resolveTriangleIntersection(y,h,e,p,g,t,o,s,l,r):0<i?0<a?resolveTriangleIntersection(y,h,e,p,t,g,o,l,s,r):resolveTriangleIntersection(h,e,y,p,g,t,o,s,l,r):0<a?resolveTriangleIntersection(e,y,h,p,g,t,o,s,l,r):a<0?resolveTriangleIntersection(e,y,h,p,t,g,o,l,s,r):(r.coplanar=!0,resolveCoplanarTriangleIntersection(y,h,e,p,g,t,c,u)))},resolveTriangleIntersection=function(e,t,r,n,o,i,s,a,l,c){return!(0<s&&0<a&&0<l||s<0&&a<0&&l<0)&&(0<s?0<a?constructIntersection(e,r,t,i,n,o,c):0<l?constructIntersection(e,r,t,o,i,n,c):constructIntersection(e,t,r,n,o,i,c):s<0?a<0?constructIntersection(e,t,r,i,n,o,c):l<0?constructIntersection(e,t,r,o,i,n,c):constructIntersection(e,r,t,n,o,i,c):a<0?0<=l?constructIntersection(e,r,t,o,i,n,c):constructIntersection(e,t,r,n,o,i,c):0<a?0<l?constructIntersection(e,r,t,n,o,i,c):constructIntersection(e,t,r,o,i,n,c):0<l?constructIntersection(e,t,r,i,n,o,c):l<0?constructIntersection(e,r,t,i,n,o,c):(c.coplanar=!0,resolveCoplanarTriangleIntersection(e,t,r,n,o,i,c.normal1,c.normal2)))},resolveCoplanarTriangleIntersection=function(e,t,r,n,o,i,s,a){var l=new Vector2,c=new Vector2,u=new Vector2,y=new Vector2,h=new Vector2,p=new Vector2,g=Math.abs(s.x),d=Math.abs(s.y),s=Math.abs(s.z);return s<g&&d<=g?(l.set(e.y,e.z),c.set(t.y,t.z),u.set(r.y,r.z),y.set(n.y,n.z),h.set(o.y,o.z),p.set(i.y,i.z)):s<d&&g<=d?(l.set(e.x,e.z),c.set(t.x,t.z),u.set(r.x,r.z),y.set(n.x,n.z),h.set(o.x,o.z),p.set(i.x,i.z)):(l.set(e.x,e.y),c.set(t.x,t.y),u.set(r.x,r.y),y.set(n.x,n.y),h.set(o.x,o.y),p.set(i.x,i.y)),trianglesOverlap2D(l,c,u,y,h,p)},trianglesOverlap2D=function(e,t,r,n,o,i){var s,a,l,c,u,y,h,p,g,d,m,P,f,b,v;return pointsEqual2D(n,o,EPS2D)&&pointsEqual2D(o,i,EPS2D)?pointInTriangleInclusive2D(n,e,t,r,EPS2D):pointsEqual2D(e,t,EPS2D)&&pointsEqual2D(t,r,EPS2D)?pointInTriangleInclusive2D(e,n,o,i,EPS2D):(y=function(e,t,r){return pointsEqual2D(e,t,EPS2D)?[t,r]:(pointsEqual2D(t,r,EPS2D),[e,t])},(h=function(e,t,r){return pointsEqual2D(e,t,EPS2D)&&!pointsEqual2D(t,r,EPS2D)||pointsEqual2D(t,r,EPS2D)&&!pointsEqual2D(e,t,EPS2D)||pointsEqual2D(r,e,EPS2D)&&!pointsEqual2D(e,t,EPS2D)})(e,t,r)&&h(n,o,i)?([h,s]=y(e,t,r),[y,c]=y(n,o,i),m=Math.min(h.x,s.x),v=Math.max(h.x,s.x),P=Math.min(h.y,s.y),p=Math.max(h.y,s.y),f=Math.min(y.x,c.x),g=Math.max(y.x,c.x),b=Math.min(y.y,c.y),d=Math.max(y.y,c.y),!(v<f-EPS2D||g<m-EPS2D||p<b-EPS2D||d<P-EPS2D||Math.abs(triangleOrientation2D(h,s,y))>EPS2D||(v=Math.abs(s.x-h.x),f=Math.abs(s.y-h.y)<=v?(l=Math.min(h.x,s.x)-EPS2D,a=Math.max(h.x,s.x)+EPS2D,u=Math.min(y.x,c.x)-EPS2D,Math.max(y.x,c.x)+EPS2D):(l=Math.min(h.y,s.y)-EPS2D,a=Math.max(h.y,s.y)+EPS2D,u=Math.min(y.y,c.y)-EPS2D,Math.max(y.y,c.y)+EPS2D),a<u)||f<l)):triangleOrientation2D(e,t,r)<0?triangleOrientation2D(n,o,i)<0?triangleIntersectionCCW2D(e,r,t,n,i,o):triangleIntersectionCCW2D(e,r,t,n,o,i):triangleOrientation2D(n,o,i)<0?triangleIntersectionCCW2D(e,t,r,n,i,o):triangleIntersectionCCW2D(e,t,r,n,o,i))},triangleOrientation2D=function(e,t,r){return(e.x-r.x)*(t.y-r.y)-(e.y-r.y)*(t.x-r.x)},triangleIntersectionCCW2D=function(e,t,r,n,o,i){return 0<=triangleOrientation2D(n,o,e)?0<=triangleOrientation2D(o,i,e)?0<=triangleOrientation2D(i,n,e)||intersectionTestEdge2D(e,t,r,n,o,i):0<=triangleOrientation2D(i,n,e)?intersectionTestEdge2D(e,t,r,i,n,o):intersectionTestVertex2D(e,t,r,n,o,i):0<=triangleOrientation2D(o,i,e)?(0<=triangleOrientation2D(i,n,e)?intersectionTestEdge2D:intersectionTestVertex2D)(e,t,r,o,i,n):intersectionTestVertex2D(e,t,r,i,n,o)},intersectionTestEdge2D=function(e,t,r,n,o,i){for(var s,a,l,c,u,y,h=function(e,t,r,n){var o=Math.min(e.x,t.x),i=Math.max(e.x,t.x),s=Math.min(e.y,t.y),a=Math.max(e.y,t.y),l=Math.min(r.x,n.x),c=Math.max(r.x,n.x),u=Math.min(r.y,n.y),y=Math.max(r.y,n.y);return!(i<l||c<o||a<u||y<s)&&(i=triangleOrientation2D(e,t,r),l=triangleOrientation2D(e,t,n),c=triangleOrientation2D(r,n,e),o=triangleOrientation2D(r,n,t),(0<i&&l<0||i<0&&0<l)&&(0<c&&o<0||c<0&&0<o)||!!(Math.abs(i)<=EPS2D&&pointOnSegmentInclusive2D(r,e,t,EPS2D)||Math.abs(l)<=EPS2D&&pointOnSegmentInclusive2D(n,e,t,EPS2D)||Math.abs(c)<=EPS2D&&pointOnSegmentInclusive2D(e,r,n,EPS2D)||Math.abs(o)<=EPS2D&&pointOnSegmentInclusive2D(t,r,n,EPS2D)))},p=[[e,t],[t,r],[r,e]],g=[[n,o],[o,i],[i,n]],d=0,m=p.length;d<m;d++)for([s,a]=p[d],u=0,y=g.length;u<y;u++)if([l,c]=g[u],h(s,a,l,c))return!0;return!1},intersectionTestVertex2D=function(e,t,r,n,o,i){return!!pointInTriangleInclusive2D(n,e,t,r,EPS2D)||!!pointInTriangleInclusive2D(o,e,t,r,EPS2D)||!!(pointInTriangleInclusive2D(i,e,t,r,EPS2D)||pointInTriangleInclusive2D(e,n,o,i,EPS2D)||pointInTriangleInclusive2D(t,n,o,i,EPS2D)||pointInTriangleInclusive2D(r,n,o,i,EPS2D))},constructIntersection=function(e,t,r,n,o,i,s){var a=void 0,l=new Vector3;return tempVector1.subVectors(t,e),tempVector2.subVectors(i,e),l.copy(tempVector1).cross(tempVector2),tempVector3.subVectors(n,e),0<tempVector3.dot(l)?(tempVector1.subVectors(r,e),l.copy(tempVector1).cross(tempVector2),tempVector3.dot(l)<=0&&(tempVector2.subVectors(o,e),l.copy(tempVector1).cross(tempVector2),0<tempVector3.dot(l)?(tempVector1.subVectors(e,n),tempVector2.subVectors(e,r),a=tempVector1.dot(s.normal2)/tempVector2.dot(s.normal2),!!isFinite(a)&&(tempVector1.copy(tempVector2).multiplyScalar(a),s.source.subVectors(e,tempVector1),tempVector1.subVectors(n,e),tempVector2.subVectors(n,i),a=tempVector1.dot(s.normal1)/tempVector2.dot(s.normal1),!!isFinite(a))&&(tempVector1.copy(tempVector2).multiplyScalar(a),s.target.subVectors(n,tempVector1),!0)):(tempVector1.subVectors(n,e),tempVector2.subVectors(n,o),a=tempVector1.dot(s.normal1)/tempVector2.dot(s.normal1),!!isFinite(a)&&(tempVector1.copy(tempVector2).multiplyScalar(a),s.source.subVectors(n,tempVector1),tempVector1.subVectors(n,e),tempVector2.subVectors(n,i),a=tempVector1.dot(s.normal1)/tempVector2.dot(s.normal1),!!isFinite(a))&&(tempVector1.copy(tempVector2).multiplyScalar(a),s.target.subVectors(n,tempVector1),!0)))):(tempVector2.subVectors(o,e),l.copy(tempVector1).cross(tempVector2),!(tempVector3.dot(l)<0||(tempVector1.subVectors(r,e),l.copy(tempVector1).cross(tempVector2),tempVector3.dot(l)<0?(tempVector1.subVectors(n,e),tempVector2.subVectors(n,o),a=tempVector1.dot(s.normal1)/tempVector2.dot(s.normal1),!isFinite(a)||(tempVector1.copy(tempVector2).multiplyScalar(a),s.source.subVectors(n,tempVector1),tempVector1.subVectors(n,e),tempVector2.subVectors(n,i),a=tempVector1.dot(s.normal1)/tempVector2.dot(s.normal1),!isFinite(a))||(tempVector1.copy(tempVector2).multiplyScalar(a),s.target.subVectors(n,tempVector1),0)):(tempVector1.subVectors(e,n),tempVector2.subVectors(e,r),a=tempVector1.dot(s.normal2)/tempVector2.dot(s.normal2),!isFinite(a)||(tempVector1.copy(tempVector2).multiplyScalar(a),s.source.subVectors(e,tempVector1),tempVector1.subVectors(e,n),tempVector2.subVectors(e,t),a=tempVector1.dot(s.normal2)/tempVector2.dot(s.normal2),!isFinite(a))||(tempVector1.copy(tempVector2).multiplyScalar(a),s.target.subVectors(e,tempVector1),0)))))};export default Polytree;export{Polytree,Plane,Vertex,Polygon,rayIntersectsTriangle,triangleIntersectsTriangle,resolveTriangleIntersection,resolveCoplanarTriangleIntersection,trianglesOverlap2D,triangleOrientation2D,triangleIntersectionCCW2D,intersectionTestEdge2D,intersectionTestVertex2D,constructIntersection};
1
+ import{Vector2,Vector3,Box3,Line3,Sphere,Matrix3,Triangle,Ray,Raycaster,Mesh,DoubleSide,BufferGeometry,BufferAttribute,Plane as ThreePlane}from"three";var ASYNC_OPERATION_TIMEOUT,DEBUG_COLOR_BACK,DEBUG_COLOR_COPLANAR,DEBUG_COLOR_FRONT,DEBUG_COLOR_SPANNING,DEBUG_GEOMETRY_VALIDATION,DEBUG_INTERSECTION_VERIFICATION,DEBUG_PERFORMANCE_TIMING,DEBUG_VERBOSE_LOGGING,DEFAULT_BUFFER_SIZE,DEFAULT_COORDINATE_PRECISION,DEFAULT_MATERIAL_INDEX,GARBAGE_COLLECTION_THRESHOLD,GEOMETRY_CACHE_SIZE,INTERSECTION_CACHE_SIZE,MAX_REFINEMENT_ITERATIONS,MAX_WORKER_THREADS,MEMORY_USAGE_WARNING_LIMIT,POINT_COINCIDENCE_THRESHOLD,POLYTREE_MAX_DEPTH,POLYTREE_MAX_POLYGONS_PER_NODE,POLYTREE_MIN_NODE_SIZE,meshOperationNormalVector,meshOperationVertexVector,polygonID,calculateWindingNumberFromBuffer,checkMemoryUsage,clearGeometryCache,clearIntersectionCache,createIntersectionCacheKey,createVector2Buffer,createVector3Buffer,disposePolytreeResources,extractCoordinatesFromArray,geometryCache,geometryCacheKeys,handleIntersectingPolytrees,intersectionCache,intersectionCacheKeys,operationCounter,prepareTriangleBufferFromPolygons,roundPointCoordinates,sortRaycastIntersectionsByDistance,splitPolygonByPlane,splitPolygonVertexArray,testPolygonInsideUsingWindingNumber,testRayTriangleIntersection,handleObjectForOperation,operationHandler,Polytree,uniteRules,subtractRules,intersectRules,Plane,Polygon,constructIntersection,intersectionTestEdge2D,intersectionTestVertex2D,isUniqueTriangle,isValidTriangle,pointInTriangleInclusive2D,pointOnSegmentInclusive2D,pointsEqual2D,resolveCoplanarTriangleIntersection,resolveTriangleIntersection,triangleIntersectionCCW2D,triangleIntersectsTriangle,triangleOrientation2D,trianglesOverlap2D,Vertex,GEOMETRIC_EPSILON=1e-8,RAY_INTERSECTION_EPSILON=1e-12,TRIANGLE_2D_EPSILON=1e-14,WINDING_NUMBER_FULL_ROTATION=4*Math.PI,POLYGON_COPLANAR=0,POLYGON_FRONT=1,POLYGON_BACK=2,POLYGON_SPANNING=3,temporaryVector3Primary=new Vector3,temporaryVector3Secondary=new Vector3,temporaryVector3Tertiary=new Vector3,temporaryVector3Quaternary=new Vector3,temporaryBoundingBox=new Box3,temporaryRaycaster=new Raycaster,temporaryRay=new Ray,defaultRayDirection=new Vector3(0,0,1),windingNumberVector1=new Vector3,windingNumberVector2=new Vector3,windingNumberVector3=new Vector3,windingNumberTestPoint=new Vector3,windingNumberEpsilonOffsets=[new Vector3(GEOMETRIC_EPSILON,0,0),new Vector3(0,GEOMETRIC_EPSILON,0),new Vector3(0,0,GEOMETRIC_EPSILON),new Vector3(-GEOMETRIC_EPSILON,0,0),new Vector3(0,-GEOMETRIC_EPSILON,0),new Vector3(0,0,-GEOMETRIC_EPSILON)],windingNumberEpsilonOffsetsCount=windingNumberEpsilonOffsets.length,windingNumberMatrix3=new Matrix3,rayTriangleEdge1=new Vector3,rayTriangleEdge2=new Vector3,rayTriangleHVector=new Vector3,rayTriangleSVector=new Vector3,rayTriangleQVector=new Vector3,temporaryTriangleVertex=new Vector3,temporaryTriangleVertexSecondary=new Vector3,temporaryMatrix3=new Matrix3,temporaryMatrixWithNormalCalc=new Matrix3;temporaryMatrixWithNormalCalc.getNormalMatrix=function(e){return this.setFromMatrix4(e).invert().transpose()},meshOperationNormalVector=new Vector3,meshOperationVertexVector=new Vector3,POLYTREE_MAX_DEPTH=1e3,POLYTREE_MIN_NODE_SIZE=1e-6,MAX_REFINEMENT_ITERATIONS=1e4,DEFAULT_COORDINATE_PRECISION=15,POINT_COINCIDENCE_THRESHOLD=1e-15,DEFAULT_BUFFER_SIZE=16384,GARBAGE_COLLECTION_THRESHOLD=POLYTREE_MAX_POLYGONS_PER_NODE=1e5,INTERSECTION_CACHE_SIZE=GEOMETRY_CACHE_SIZE=ASYNC_OPERATION_TIMEOUT=MAX_WORKER_THREADS=1/(DEFAULT_MATERIAL_INDEX=0),polygonID=0,DEBUG_INTERSECTION_VERIFICATION=DEBUG_GEOMETRY_VALIDATION=DEBUG_PERFORMANCE_TIMING=DEBUG_VERBOSE_LOGGING=!(MEMORY_USAGE_WARNING_LIMIT=.95),DEBUG_COLOR_FRONT=65280,DEBUG_COLOR_BACK=16711680,DEBUG_COLOR_COPLANAR=255,DEBUG_COLOR_SPANNING=16776960,intersectionCache=new Map,intersectionCacheKeys=[],geometryCache=new Map,geometryCacheKeys=[],operationCounter=0,clearIntersectionCache=function(){var e,r,t,o,n;if(INTERSECTION_CACHE_SIZE!==1/0&&intersectionCache.size>INTERSECTION_CACHE_SIZE){for(n=[],o=(t=intersectionCacheKeys.splice(e=0,Math.floor(INTERSECTION_CACHE_SIZE/2))).length;e<o;e++)r=t[e],n.push(intersectionCache.delete(r));return n}},clearGeometryCache=function(){var e,r,t,o,n;if(GEOMETRY_CACHE_SIZE!==1/0&&geometryCache.size>GEOMETRY_CACHE_SIZE){for(n=[],o=(t=geometryCacheKeys.splice(e=0,Math.floor(GEOMETRY_CACHE_SIZE/2))).length;e<o;e++)r=t[e],n.push(geometryCache.delete(r));return n}},createIntersectionCacheKey=function(e,r){return e.id+"_"+r.id},checkMemoryUsage=function(){var e,r,t;return"undefined"!=typeof process&&process.memoryUsage?(r=(t=process.memoryUsage()).heapUsed/1024/1024,e=t.heapTotal/1024/1024,t=t.heapUsed/t.heapTotal,DEBUG_VERBOSE_LOGGING&&console.log(`Memory usage: ${r.toFixed(2)}MB / ${e.toFixed(2)}MB (${(100*t).toFixed(1)}%)`),MEMORY_USAGE_WARNING_LIMIT<t&&(console.warn(`Memory usage is high: ${(100*t).toFixed(1)}%`),"function"==typeof("undefined"!=typeof global&&null!==global?global.gc:void 0))&&(console.log("Triggering garbage collection..."),global.gc()),t):0},createVector2Buffer=function(e=DEFAULT_BUFFER_SIZE){return{top:0,array:new Float32Array(2*e),write:function(e){return this.array[this.top++]=e.x,this.array[this.top++]=e.y}}},createVector3Buffer=function(e=DEFAULT_BUFFER_SIZE){return{top:0,array:new Float32Array(3*e),write:function(e){return this.array[this.top++]=e.x,this.array[this.top++]=e.y,this.array[this.top++]=e.z}}},sortRaycastIntersectionsByDistance=function(e,r){return e.distance-r.distance},roundPointCoordinates=function(e,r=DEFAULT_COORDINATE_PRECISION){return e.x=+e.x.toFixed(r),e.y=+e.y.toFixed(r),e.z=+e.z.toFixed(r),e},extractCoordinatesFromArray=function(e,r){return{x:e[r],y:e[r+1],z:e[r+2]}},splitPolygonByPlane=function(e,r,t=[]){for(var o,n,i,a,s,l,c,y,u,g,h,p,d,m,P,E,I,f={polygon:e,type:"undecided"},O=0,T=[],N=c=0,_=e.vertices.length;0<=_?c<_:_<c;N=0<=_?++c:--c)O|=I=(I=r.normal.dot(e.vertices[N].pos)-r.distanceFromOrigin)<-GEOMETRIC_EPSILON?POLYGON_BACK:GEOMETRIC_EPSILON<I?POLYGON_FRONT:POLYGON_COPLANAR,T.push(I);switch(O){case POLYGON_COPLANAR:f.type=0<r.normal.dot(e.plane.normal)?"coplanar-front":"coplanar-back",DEBUG_VERBOSE_LOGGING&&console.log("Polygon classified as COPLANAR, debug color:",DEBUG_COLOR_COPLANAR.toString(16)),t.push(f);break;case POLYGON_FRONT:f.type="front",t.push(f),DEBUG_VERBOSE_LOGGING&&console.log("Polygon classified as FRONT, debug color:",DEBUG_COLOR_FRONT.toString(16));break;case POLYGON_BACK:f.type="back",t.push(f),DEBUG_VERBOSE_LOGGING&&console.log("Polygon classified as BACK, debug color:",DEBUG_COLOR_BACK.toString(16));break;case POLYGON_SPANNING:for(DEBUG_VERBOSE_LOGGING&&console.log("Polygon classified as SPANNING, debug color:",DEBUG_COLOR_SPANNING.toString(16)),l=[],n=[],N=u=0,m=e.vertices.length;0<=m?u<m:m<u;N=0<=m?++u:--u)d=T[p=(N+1)%e.vertices.length],i=e.vertices[N],p=e.vertices[p],(y=T[N])!==POLYGON_BACK&&l.push(i),y!==POLYGON_FRONT&&n.push(y!==POLYGON_BACK?i.clone():i),(y|d)===POLYGON_SPANNING&&(y=(r.distanceFromOrigin-r.normal.dot(i.pos))/r.normal.dot(temporaryTriangleVertex.copy(p.pos).sub(i.pos)),d=i.interpolate(p,y),l.push(d),n.push(d.clone()));if(3<=l.length)if(3<l.length)for(a=g=0,P=(s=splitPolygonVertexArray(l)).length;0<=P?g<P:P<g;a=0<=P?++g:--g)t.push({polygon:new Polygon(s[a],e.shared),type:"front"});else t.push({polygon:new Polygon(l,e.shared),type:"front"});if(3<=n.length)if(3<n.length)for(a=h=0,E=(o=splitPolygonVertexArray(n)).length;0<=E?h<E:E<h;a=0<=E?++h:--h)t.push({polygon:new Polygon(o[a],e.shared),type:"back"});else t.push({polygon:new Polygon(n,e.shared),type:"back"})}return 0===t.length&&t.push(f),t},splitPolygonVertexArray=function(e){var r,t,o,n,i=[];if(4<e.length)for(console.warn("[splitPolygonVertexArray] vertexArray.length > 4",e.length),o=r=3,t=e.length;3<=t?r<=t:t<=r;o=3<=t?++r:--r)(n=[]).push(e[0].clone()),n.push(e[o-2].clone()),n.push(e[o-1].clone()),i.push(n);else e[0].pos.distanceTo(e[2].pos)<=e[1].pos.distanceTo(e[3].pos)?i.push([e[0].clone(),e[1].clone(),e[2].clone()],[e[0].clone(),e[2].clone(),e[3].clone()]):i.push([e[0].clone(),e[1].clone(),e[3].clone()],[e[1].clone(),e[2].clone(),e[3].clone()]);return i},calculateWindingNumberFromBuffer=function(e,r){for(var t,o,n,i,a=0,s=t=0,l=e.length;t<l;s=t+=9)windingNumberVector1.subVectors(extractCoordinatesFromArray(e,s),r),windingNumberVector2.subVectors(extractCoordinatesFromArray(e,s+3),r),windingNumberVector3.subVectors(extractCoordinatesFromArray(e,s+6),r),o=windingNumberVector1.length(),n=windingNumberVector2.length(),i=windingNumberVector3.length(),o<POINT_COINCIDENCE_THRESHOLD||n<POINT_COINCIDENCE_THRESHOLD||i<POINT_COINCIDENCE_THRESHOLD||(windingNumberMatrix3.set(windingNumberVector1.x,windingNumberVector1.y,windingNumberVector1.z,windingNumberVector2.x,windingNumberVector2.y,windingNumberVector2.z,windingNumberVector3.x,windingNumberVector3.y,windingNumberVector3.z),a+=2*Math.atan2(windingNumberMatrix3.determinant(),o*n*i+windingNumberVector1.dot(windingNumberVector2)*i+windingNumberVector2.dot(windingNumberVector3)*o+windingNumberVector3.dot(windingNumberVector1)*n));return a=Math.round(a/WINDING_NUMBER_FULL_ROTATION)},testPolygonInsideUsingWindingNumber=function(e,r,t){var o,n,i,a=!1;if(windingNumberTestPoint.copy(r),0===calculateWindingNumberFromBuffer(e,windingNumberTestPoint)){if(t)for(n=o=0,i=Math.min(windingNumberEpsilonOffsetsCount,MAX_REFINEMENT_ITERATIONS);0<=i?o<i:i<o;n=0<=i?++o:--o)if(windingNumberTestPoint.copy(r).add(windingNumberEpsilonOffsets[n]),0!==calculateWindingNumberFromBuffer(e,windingNumberTestPoint)){a=!0;break}}else a=!0;return a},prepareTriangleBufferFromPolygons=function(e){for(var r,t,o=e.length,n=new Float32Array(3*o*3),i=0,a=r=0,s=o;0<=s?r<s:s<r;a=0<=s?++r:--r)t=e[a].triangle,n[i++]=t.a.x,n[i++]=t.a.y,n[i++]=t.a.z,n[i++]=t.b.x,n[i++]=t.b.y,n[i++]=t.b.z,n[i++]=t.c.x,n[i++]=t.c.y,n[i++]=t.c.z;return n},testRayTriangleIntersection=function(e,r,t=new Vector3){var o,n,i;return DEBUG_VERBOSE_LOGGING&&console.log("Testing ray-triangle intersection with ray origin:",e.origin,"direction:",e.direction),rayTriangleEdge1.subVectors(r.b,r.a),rayTriangleEdge2.subVectors(r.c,r.a),rayTriangleHVector.crossVectors(e.direction,rayTriangleEdge2),n=rayTriangleEdge1.dot(rayTriangleHVector),!(-RAY_INTERSECTION_EPSILON<n&&n<RAY_INTERSECTION_EPSILON||(n=1/n,rayTriangleSVector.subVectors(e.origin,r.a),(o=n*rayTriangleSVector.dot(rayTriangleHVector))<0)||1<o||(rayTriangleQVector.crossVectors(rayTriangleSVector,rayTriangleEdge1),(i=n*e.direction.dot(rayTriangleQVector))<0)||1<o+i||(o=n*rayTriangleEdge2.dot(rayTriangleQVector),!(RAY_INTERSECTION_EPSILON<o)))?(i=t.copy(e.direction).multiplyScalar(o).add(e.origin),DEBUG_INTERSECTION_VERIFICATION&&console.log("Ray-triangle intersection verified:",{distance:o,point:i,triangle:{a:r.a,b:r.b,c:r.c}}),i):null},handleIntersectingPolytrees=function(e,r,t=!0){var o,n,i=DEBUG_PERFORMANCE_TIMING?performance.now():0;if(GARBAGE_COLLECTION_THRESHOLD<=++operationCounter&&(operationCounter=0,clearIntersectionCache(),clearGeometryCache(),checkMemoryUsage()),!(n=o=void 0)===Polytree.useWindingNumber&&(t&&(o=prepareTriangleBufferFromPolygons(e.getPolygons())),n=prepareTriangleBufferFromPolygons(r.getPolygons())),e.handleIntersectingPolygons(r,n),t&&r.handleIntersectingPolygons(e,o),void 0!==o&&(o=void 0),void 0!==n&&(n=void 0),DEBUG_PERFORMANCE_TIMING)return t=performance.now(),n=void 0,console.log(`handleIntersectingPolytrees took ${t-i} milliseconds`)},disposePolytreeResources=function(...e){if(Polytree.disposePolytree)return e.forEach(function(e){return e.delete()})},operationHandler=function(u,g=!1,h=!0,p={objCounter:0},d=!0,m=!0){var e,r,t,o,n,i;if(m)return new Promise(function(o,t){var n,i,e,r,a,s,l,c,y;try{return i=y=n=void 0,a=null!=(l=u.objA)?l.material:void 0,s=null!=(c=u.objB)?c.material:void 0,u.material&&(i=u.material),r=[],u.objA&&(e=handleObjectForOperation(u.objA,g,h,p,0,m),r.push(e)),u.objB&&(e=handleObjectForOperation(u.objB,g,h,p,1,m),r.push(e)),Promise.allSettled(r).then(function(e){var r;switch(e.forEach(function(e){if("fulfilled"===e.status)return 0===e.value.objIndex?n=e.value:1===e.value.objIndex?y=e.value:void 0}),!0===g&&(n&&(u.objA=n.original,n=n.result),y)&&(u.objB=y.original,y=y.result),r=void 0,u.op){case"unite":r=n&&y?Polytree.async.unite(n,y,h):Promise.resolve(n||y||new Polytree);break;case"subtract":r=n&&y?Polytree.async.subtract(n,y,h):Promise.resolve(n||new Polytree);break;case"intersect":r=n&&y?Polytree.async.intersect(n,y,h):Promise.resolve(new Polytree);break;default:r=Promise.resolve(new Polytree)}return r.then(function(e){var r,t;if(e&&!e.box&&e.bounds&&e.buildTree(),d&&!g){if(r=e.getPolygons(),!e||0===r.length)return void o(void 0);if(i)t=Polytree.toMesh(e,i);else{if(r=void 0,a)r=(r=Array.isArray(a)?a[0]:a).clone();else{if(!s)return void o(void 0);r=(r=Array.isArray(s)?s[0]:s).clone()}t=Polytree.toMesh(e,r)}disposePolytreeResources(e),o(t)}else d&&g?i?(t=Polytree.toMesh(e,i),disposePolytreeResources(e),o({result:t,operationTree:u})):o({result:e,operationTree:u}):o(e);if(!g&&(n||y))return disposePolytreeResources(n,y)}).catch(function(e){return t(e)})})}catch(e){return t(e)}});switch(o=n=i=t=void 0,u.material&&(o=u.material),u.objA&&(t=handleObjectForOperation(u.objA,g,h,p,void 0,m),!0===g)&&(u.objA=t.original,t=t.result),u.objB&&(i=handleObjectForOperation(u.objB,g,h,p,void 0,m),!0===g)&&(u.objB=i.original,i=i.result),u.op){case"unite":n=t&&i?Polytree.unite(t,i,!1):t||i||new Polytree;break;case"subtract":n=t&&i?Polytree.subtract(t,i,!1):t||new Polytree;break;case"intersect":n=t&&i?Polytree.intersect(t,i,!1):new Polytree;break;default:n=new Polytree}if(n&&!n.box&&n.bounds&&n.buildTree(),g||(t||i)&&disposePolytreeResources(t,i),!d||g)return d&&g?{result:n,operationTree:u}:n;if(e=n.getPolygons(),n&&0!==e.length){if(o)r=Polytree.toMesh(n,o);else{if(e=void 0,null==(o=u.objA)||!o.material)return;e=(e=Array.isArray(u.objA.material)?u.objA.material[0]:u.objA.material).clone(),r=Polytree.toMesh(n,e)}return disposePolytreeResources(n),r}},handleObjectForOperation=function(o,n,i,a,s,l=!0){var e;return l?new Promise(function(r,t){var e;try{return e=void 0,o.isMesh?(e=Polytree.fromMesh(o,a.objCounter++),(e=n?{result:e,original:e.clone()}:e).objIndex=s,r(e)):o.isPolytree?(e=o,(e=n?{result:o,original:o.clone()}:e).objIndex=s,r(e)):o.op?Polytree.operation(o,n,i,a,!1,l).then(function(e){return(e=n?{result:e,original:o}:e).objIndex=s,r(e)}):void 0}catch(e){return t(e)}}):(e=void 0,o.isMesh?(e=Polytree.fromMesh(o,a.objCounter++),n&&(e={result:e,original:e.clone()})):o.isPolytree?(e=o,n&&(e={result:o,original:o.clone()})):o.op&&(e=Polytree.operation(o,n,i,a,!1,l),n)&&(e={result:e,original:o}),e)},(Polytree=function(){class _{constructor(e=null,r=null){this.box=e,this.polygons=[],this.replacedPolygons=[],this.parent=r,this.subTrees=[],this.level=0,this.originalMatrixWorld,this.mesh,this.polygonArrays=void 0,this.addPolygonsArrayToRoot(this.polygons)}isEmpty(){return 0===this.polygons.length}getMesh(){for(var e,r=new Set,t=this;t&&!r.has(t);){if(r.add(t),!t.parent)return null!=(e=t.mesh)?e:null;t=t.parent}return null}newPolytree(e,r){return new this.constructor(e,r)}setPolygonIndex(r){return void 0!==r&&this.polygonArrays?this.polygonArrays.forEach(function(e){if(null!=e&&e.length)return e.forEach(function(e){return e.shared=r})}):void 0}clone(){return(new this.constructor).copy(this)}copy(e){var r,t,o,n,i;if(e&&(this.deletePolygonsArrayFromRoot(this.polygons),this.polygons=e.polygons?e.polygons.map(function(e){return e.clone()}):[],this.addPolygonsArrayToRoot(this.polygons),this.replacedPolygons=e.replacedPolygons?e.replacedPolygons.map(function(e){return e.clone()}):[],e.mesh&&(this.mesh=e.mesh),e.originalMatrixWorld&&(this.originalMatrixWorld=e.originalMatrixWorld.clone()),this.box=e.box?e.box.clone():null,this.level=null!=(o=e.level)?o:0,e.subTrees))for(r=t=0,n=e.subTrees.length;0<=n?t<n:n<t;r=0<=n?++t:--t)i=new this.constructor(void 0,this).copy(e.subTrees[r]),this.subTrees.push(i);return this}unite(e,r,t=null){return _.unite(e,r,t)}subtract(e,r,t=null){return _.subtract(e,r,t)}intersect(e,r,t=null){return _.intersect(e,r,t)}addPolygonsArrayToRoot(e){return this.parent?this.parent.addPolygonsArrayToRoot(e):(void 0===this.polygonArrays&&(this.polygonArrays=[]),this.polygonArrays.push(e))}deletePolygonsArrayFromRoot(e){return this.parent?this.parent.deletePolygonsArrayFromRoot(e):-1<(e=this.polygonArrays.indexOf(e))?this.polygonArrays.splice(e,1):void 0}addPolygon(e,r){var t;return this.bounds||(this.bounds=new Box3),t=e.triangle,r&&!isUniqueTriangle(t,r)||(this.bounds.expandByPoint(t.a),this.bounds.expandByPoint(t.b),this.bounds.expandByPoint(t.c),this.polygons.push(e)),this}calcBox(){var e;return this.bounds||(this.bounds=new Box3),this.box=this.bounds.clone(),e=POLYTREE_MIN_NODE_SIZE,this.box.min.x-=e,this.box.min.y-=e,this.box.min.z-=e,this.box.max.x+=e,this.box.max.y+=e,this.box.max.z+=e,this}split(e){var r,t,o,n,i,a,s,l,c,y,u,g,h,p,d,m,P,E,I,f=[];if(this.box){for(o=temporaryVector3Secondary.copy(this.box.max).sub(this.box.min).multiplyScalar(.5),P=i=0;i<=1;P=++i)for(E=a=0;a<=1;E=++a)for(I=l=0;l<=1;I=++l)r=new Box3,m=temporaryVector3Primary.set(P,E,I),r.min.copy(this.box.min).add(m.multiply(o)),r.max.copy(r.min).add(o),r.expandByScalar(GEOMETRIC_EPSILON),f.push(this.newPolytree(r,this));for(h=void 0;h=this.polygons.pop();){for(t=!1,n=y=0,p=f.length;0<=p?y<p:p<y;n=0<=p?++y:--y)f[n].box.containsPoint(h.getMidpoint())&&(f[n].polygons.push(h),t=!0);if(!t)throw new Error(`Unable to find subtree for triangle at level ${e}.`)}for(n=g=0,d=f.length;0<=d?g<d:d<g;n=0<=d?++g:--g)f[n].level=e+1,s=f[n].polygons.length,u=f[n].box.getSize(temporaryVector3Tertiary).length(),c=Math.min(_.maxLevel,POLYTREE_MAX_DEPTH),Math.min(_.polygonsPerTree,POLYTREE_MAX_POLYGONS_PER_NODE)<s&&e<c&&POLYTREE_MIN_NODE_SIZE<u&&f[n].split(e+1),this.subTrees.push(f[n])}return this}buildTree(){return this.calcBox(),this.split(0),this.processTree(),this}processTree(){var e,r,t,o,n,i;if(!this.isEmpty()){for(temporaryBoundingBox.copy(this.box),e=r=0,o=this.polygons.length;0<=o?r<o:o<r;e=0<=o?++r:--r)this.box.expandByPoint(this.polygons[e].triangle.a),this.box.expandByPoint(this.polygons[e].triangle.b),this.box.expandByPoint(this.polygons[e].triangle.c);this.expandParentBox()}for(i=[],e=t=0,n=this.subTrees.length;0<=n?t<n:n<t;e=0<=n?++t:--t)i.push(this.subTrees[e].processTree());return i}expandParentBox(e=new Set){if(this.parent&&!e.has(this.parent))return e.add(this.parent),this.parent.box.expandByPoint(this.box.min),this.parent.box.expandByPoint(this.box.max),this.parent.expandParentBox(e)}invert(){return this.polygonArrays.forEach(function(e){if(e.length)return e.forEach(function(e){return e.flip()})})}getPolygons(i=[]){return this.polygonArrays.forEach(function(e){var r,t,o,n;if(e.length){for(n=[],r=t=0,o=e.length;0<=o?t<o:o<t;r=0<=o?++t:--t)e[r].valid&&-1===i.indexOf(e[r])?n.push(i.push(e[r])):n.push(void 0);return n}}),i}getTriangles(r=[]){return this.getPolygons().forEach(function(e){return r.push(e.triangle)}),r}getRayPolygons(e,r=[]){var t,o,n,i,a;if(0<this.polygons.length)for(t=o=0,i=this.polygons.length;0<=i?o<i:i<o;t=0<=i?++o:--o)this.polygons[t].valid&&this.polygons[t].originalValid&&-1===r.indexOf(this.polygons[t])&&r.push(this.polygons[t]);for(0<this.replacedPolygons.length&&r.push(...this.replacedPolygons),t=n=0,a=this.subTrees.length;0<=a?n<a:a<n;t=0<=a?++n:--n)e.intersectsBox(this.subTrees[t].box)&&this.subTrees[t].getRayPolygons(e,r);return r}getRayTriangles(e,r=[]){return this.getRayPolygons(e).forEach(function(e){return r.push(e.triangle)}),r}rayIntersect(e,r,t=[]){var o,n,i,a,s,l,c;if(0===e.direction.length())return[];for(o=1e100,n=i=0,l=(s=this.getRayPolygons(e)).length;0<=l?i<l:l<i;n=0<=l?++i:--i)c=void 0,"regular"===_.rayIntersectTriangleType?(c=e.intersectTriangle(s[n].triangle.a,s[n].triangle.b,s[n].triangle.c,!1,temporaryVector3Primary))&&(temporaryVector3Primary.applyMatrix4(r),(o=temporaryVector3Primary.distanceTo(e.origin))<0||1/0<o?console.warn("[rayIntersect] Failed ray distance check.",e):t.push({distance:o,polygon:s[n],position:temporaryVector3Primary.clone()})):(c=testRayTriangleIntersection(e,s[n].triangle,temporaryVector3Primary))&&(o=(a=c.clone().sub(e.origin).length())<o?a:o)<1e100&&t.push({distance:o,polygon:s[n],position:c.clone().add(e.origin)});return t.length&&t.sort(sortRaycastIntersectionsByDistance),t}getIntersectingPolygons(i=[]){return this.polygonArrays.forEach(function(e){var r,t,o,n;if(e.length){for(n=[],r=t=0,o=e.length;0<=o?t<o:o<t;r=0<=o?++t:--t)e[r].valid&&e[r].intersects?n.push(i.push(e[r])):n.push(void 0);return n}}),i}getPolygonsIntersectingPolygon(e,r=[]){var t,o,n,i,a,s,l,c,y;if(this.box.intersectsTriangle(e.triangle)&&0<this.polygons.length){if(t=this.polygons.slice(),0<this.replacedPolygons.length)for(o=n=0,l=this.replacedPolygons.length;0<=l?n<l:l<n;o=0<=l?++n:--n)t.push(this.replacedPolygons[o]);for(o=i=0,c=t.length;0<=c?i<c:c<i;o=0<=c?++i:--i)(s=t[o]).originalValid&&s.valid&&s.intersects&&triangleIntersectsTriangle(e.triangle,s.triangle)&&r.push(s)}for(o=a=0,y=this.subTrees.length;0<=y?a<y:y<a;o=0<=y?++a:--a)this.subTrees[o].getPolygonsIntersectingPolygon(e,r);return r}replacePolygon(e,r){var t,o,n,i,a;for(Array.isArray(r)||(r=[r]),0<this.polygons.length&&-1<(n=this.polygons.indexOf(e))&&(!0===e.originalValid?this.replacedPolygons.push(e):e.setInvalid(),this.polygons.splice(n,1,...r)),a=[],t=o=0,i=this.subTrees.length;0<=i?o<i:i<o;t=0<=i?++o:--o)a.push(this.subTrees[t].replacePolygon(e,r));return a}deletePolygonsByStateRules(h,p=!0){return this.polygonArrays.forEach(function(g){if(g.length)return g.filter(function(e){return!0===e.valid&&!0===e.intersects}).forEach(function(e){for(var r,t,o,n,i,a,s,l,c=!1,y=t=0,u=h.length;0<=u?t<u:u<t;y=0<=u?++t:--t)if(h[y].array){if((s=h[y].rule).includes(e.state)&&("undecided"!==e.previousState&&s.includes(e.previousState)||"undecided"===e.previousState)){for(c=!0,l={},s.forEach(function(e){return l[e]=!1}),s.forEach(function(e){return e,!1}),l[e.state]=!0,r=o=0,i=e.previousStates.length;0<=i?o<i:i<o;r=0<=i?++o:--o){if(!s.includes(e.previousStates[r])){c=!1;break}l[e.previousStates[r]]=!0}if(c){for(a in l)if(!1===l[a]){c=!1;break}if(c)break}}}else if(e.checkAllStates(h[y].rule)){c=!0;break}if(c&&(-1<(n=g.indexOf(e))&&(e.setInvalid(),g.splice(n,1)),p))return e.delete()})})}deletePolygonsByIntersection(o,n=!0){if(void 0!==o)return this.polygonArrays.forEach(function(t){if(t.length)return t.slice().forEach(function(e){var r;if(e.valid&&e.intersects===o&&(-1<(r=t.indexOf(e))&&(e.setInvalid(),t.splice(r,1)),n))return e.delete()})})}isPolygonIntersecting(e){return!!this.box.intersectsTriangle(e.triangle)}markIntesectingPolygons(r){return this.polygonArrays.forEach(function(e){if(e.length)return e.forEach(function(e){return e.intersects=r.isPolygonIntersecting(e)})})}resetPolygons(r=!0){return this.polygonArrays.forEach(function(e){if(e.length)return e.forEach(function(e){return e.reset(r)})})}handleIntersectingPolygons(e,r){var t,o,n,i,a,s,l,c,y,u,g,h,p,d,m,P,E,I,f,O,T,N;if(0<this.polygons.length){for(t=(p=this.polygons.filter(function(e){return!0===e.valid&&!0===e.intersects&&"undecided"===e.state})).pop();t;)if("undecided"===t.state&&t.valid){if(0<(N=e.getPolygonsIntersectingPolygon(t)).length)for(a=s=0,d=N.length;0<=d?s<d:d<s;a=0<=d?++s:--s){if(T=N[a],1<(O=splitPolygonByPlane(t,T.plane)).length){for(o=l=0,m=O.length;0<=m?l<m:m<l;o=0<=m?++l:--l)(h=O[o].polygon).intersects=t.intersects,h.newPolygon=!0,p.push(h);this.replacePolygon(t,O.map(function(e){return e.polygon}));break}if(t.id!==O[0].polygon.id){O[0].polygon.intersects=t.intersects,O[0].polygon.newPolygon=!0,p.push(O[0].polygon),this.replacePolygon(t,O[0].polygon);break}"coplanar-front"!==O[0].type&&"coplanar-back"!==O[0].type||(t.setState(O[0].type),t.coplanar=!0)}t=p.pop()}for(t=(p=this.polygons.filter(function(e){return!0===e.valid&&!0===e.intersects})).pop(),n=!1;t;)if(t.valid){if(n=!1,e.box.containsPoint(t.getMidpoint()))if(!0===_.useWindingNumber)n=testPolygonInsideUsingWindingNumber(r,t.getMidpoint(),t.coplanar);else if(g=roundPointCoordinates(temporaryVector3Secondary.copy(t.getMidpoint())),!0!==_.usePolytreeRay&&e.mesh){if(defaultRayDirection.copy(t.plane.normal),temporaryRaycaster.set(g,defaultRayDirection),!(n=(i=temporaryRaycaster.intersectObject(e.mesh)).length&&0<defaultRayDirection.dot(i[0].face.normal)?!0:n)&&t.coplanar)for(a=c=0,P=windingNumberEpsilonOffsetsCount;0<=P?c<P:P<c;a=0<=P?++c:--c)if(temporaryRaycaster.ray.origin.copy(g).add(windingNumberEpsilonOffsets[a]),(i=temporaryRaycaster.intersectObject(e.mesh)).length&&0<defaultRayDirection.dot(i[0].face.normal)){n=!0;break}}else if(temporaryRay.origin.copy(g),defaultRayDirection.copy(t.plane.normal),temporaryRay.direction.copy(t.plane.normal),!(n=(i=e.rayIntersect(temporaryRay,e.originalMatrixWorld)).length&&0<defaultRayDirection.dot(i[0].polygon.plane.normal)?!0:n)&&t.coplanar)for(a=y=0,E=windingNumberEpsilonOffsetsCount;0<=E?y<E:E<y;a=0<=E?++y:--y)if(temporaryRay.origin.copy(g).add(windingNumberEpsilonOffsets[a]),defaultRayDirection.copy(t.plane.normal),temporaryRay.direction.copy(t.plane.normal),(i=e.rayIntersect(temporaryRay,e.originalMatrixWorld)).length&&0<defaultRayDirection.dot(i[0].polygon.plane.normal)){n=!0;break}!0===n?t.setState("inside"):t.setState("outside"),t=p.pop()}}for(f=[],o=u=0,I=this.subTrees.length;0<=I?u<I:I<u;o=0<=I?++u:--u)f.push(this.subTrees[o].handleIntersectingPolygons(e,r));return f}applyMatrix(e,r,t=!0){var o,n,i,a,s;if(e.isMesh&&(e.updateMatrix(),e=e.matrix),this.box&&this.box.makeEmpty(),r=r||temporaryMatrixWithNormalCalc.getNormalMatrix(e),0<this.polygons.length)for(o=n=0,a=this.polygons.length;0<=a?n<a:a<n;o=0<=a?++n:--n)this.polygons[o].valid&&this.polygons[o].applyMatrix(e,r);for(o=i=0,s=this.subTrees.length;0<=s?i<s:s<i;o=0<=s?++i:--i)this.subTrees[o].applyMatrix(e,r,!1);if(t)return this.processTree()}triangleSphereIntersect(e,r){var t,o,n,i,a,s,l,c,y=new Vector3,u=new Vector3,g=new Line3,h=new ThreePlane;if(r.getPlane(h),e.intersectsPlane(h)){if(n=Math.abs(h.distanceToSphere(e)),s=e.radius*e.radius-n*n,a=h.projectPoint(e.center,y),r.containsPoint(e.center))return{depth:Math.abs(h.distanceToSphere(e)),normal:h.normal.clone(),point:a.clone()};for(o=i=0,l=(c=[[r.a,r.b],[r.b,r.c],[r.c,r.a]]).length;0<=l?i<l:l<i;o=0<=l?++i:--i)if(g.set(c[o][0],c[o][1]),g.closestPointToPoint(a,!0,u),(t=u.distanceToSquared(e.center))<s)return{depth:e.radius-Math.sqrt(t),normal:e.center.clone().sub(u).normalize(),point:u.clone()}}return!1}getSphereTriangles(e,o){for(var n,i,r,a,t=[],s=r=0,l=this.subTrees.length;0<=l?r<l:l<r;s=0<=l?++r:--r)i=this.subTrees[s],e.intersectsBox(i.box)&&(0<i.polygons.length?t.push((()=>{var e,r,t=[];for(a=e=0,r=i.polygons.length;0<=r?e<r:r<e;a=0<=r?++e:--e)(n=i.polygons[a]).valid&&(-1===o.indexOf(n.triangle)?t.push(o.push(n.triangle)):t.push(void 0));return t})()):t.push(i.getSphereTriangles(e,o)));return t}sphereIntersect(e){var r,t,o,n,i=!1,a=void 0,s=[],l=new Sphere;for(l.copy(e),this.getSphereTriangles(e,s),n=r=0,o=s.length;0<=o?r<o:o<r;n=0<=o?++r:--r)(a=this.triangleSphereIntersect(l,s[n]))&&(i=!0,l.center.add(a.normal.multiplyScalar(a.depth)));return!!i&&(t=(e=l.center.clone().sub(e.center)).length(),{normal:e.normalize(),depth:t})}fromGraphNode(e){var r;return e.updateWorldMatrix(!0,!0),r=this,e.traverse(function(e){if(!0===e.isMesh)return _.fromMesh(e,void 0,r,!1)}),this.buildTree()}deleteReplacedPolygons(){var e,r,t,o;for(0<this.replacedPolygons.length&&(this.replacedPolygons.forEach(function(e){return e.delete()}),this.replacedPolygons.length=0),o=[],e=r=0,t=this.subTrees.length;0<=t?r<t:t<r;e=0<=t?++r:--r)o.push(this.subTrees[e].deleteReplacedPolygons());return o}markPolygonsAsOriginal(){return this.polygonArrays.forEach(function(e){if(e.length)return e.forEach(function(e){return e.originalValid=!0})})}getPolygonCloneCallback(i,a){return this.polygonArrays.forEach(function(e){var r,t,o,n;if(e.length){for(n=[],r=t=0,o=e.length;0<=o?t<o:o<t;r=0<=o?++t:--t)e[r].valid?n.push(i(e[r].clone(),a)):n.push(void 0);return n}})}delete(e=!0){var r,t,o;if(0<this.polygons.length&&e&&(this.polygons.forEach(function(e){return e.delete()}),this.polygons.length=0),0<this.replacedPolygons.length&&e&&(this.replacedPolygons.forEach(function(e){return e.delete()}),this.replacedPolygons.length=0),this.polygonArrays&&(this.polygonArrays.length=0),this.subTrees.length){for(r=t=0,o=this.subTrees.length;0<=o?t<o:o<t;r=0<=o?++t:--t)this.subTrees[r].delete(e);this.subTrees.length=0}return this.mesh=void 0,this.originalMatrixWorld=void 0,this.box=void 0,this.parent=void 0,this.level=void 0}dispose(e=!0){return this.delete(e)}}return _.prototype.isPolytree=!0,_.usePolytreeRay=!0,_.disposePolytree=!0,_.useWindingNumber=!1,_.maxLevel=POLYTREE_MAX_DEPTH,_.polygonsPerTree=POLYTREE_MAX_POLYGONS_PER_NODE,_.rayIntersectTriangleType="MollerTrumbore",_.operation=operationHandler,_.rayIntersectsTriangle=testRayTriangleIntersection,_}.call(this)).toGeometry=function(e){for(var r,t,o,n,i,a,s,l,c,y,u,g,h,p,d,m=[],P=[],E=void 0,I=void 0,f=0,O=e.getPolygons(),T=0,N=O.length;T<N;T++)y=O[T],f+=Math.max(0,y.vertices.length-2);for(u=createVector3Buffer(3*f),c=createVector3Buffer(3*f),i=0,a=O.length;i<a;i++)for(d=(p=(y=O[i]).vertices).length,void 0===y.shared||m[y.shared]||(m[y.shared]=[]),0<d&&(void 0!==p[0].uv&&(E=E||createVector2Buffer(3*f)),void 0!==p[0].color)&&(I=I||createVector3Buffer(3*f)),o=s=3,g=d;3<=g?s<=g:g<=s;o=3<=g?++s:--s)(void 0===y.shared?P:m[y.shared]).push(u.top/3,u.top/3+1,u.top/3+2),u.write(p[0].pos),u.write(p[o-2].pos),u.write(p[o-1].pos),c.write(p[0].normal),c.write(p[o-2].normal),c.write(p[o-1].normal),null!=E&&(E.write(p[0].uv),E.write(p[o-2].uv),E.write(p[o-1].uv)),null!=I&&(I.write(p[0].color),I.write(p[o-2].color),I.write(p[o-1].color));if((r=new BufferGeometry).setAttribute("position",new BufferAttribute(u.array,3)),r.setAttribute("normal",new BufferAttribute(c.array,3)),E&&r.setAttribute("uv",new BufferAttribute(E.array,2)),I&&r.setAttribute("color",new BufferAttribute(I.array,3)),0<m.length){for(n=[],o=l=t=0,h=m.length;0<=h?l<h:h<l;o=0<=h?++l:--l)m[o]=m[o]||[],r.addGroup(t,m[o].length,o),t+=m[o].length,n=n.concat(m[o]);P.length&&(r.addGroup(t,P.length,m.length),n=n.concat(P)),r.setIndex(n)}return r},Polytree.toMesh=function(e,r){e=Polytree.toGeometry(e);return new Mesh(e,r)},uniteRules={a:[{array:!0,rule:["inside","coplanar-back"]},{array:!(Polytree.fromMesh=function(e,r,t=new Polytree,o=!0){var n,i,a,s,l,c,y,u,g,h,p,d,m,P,E,I,f,O,T,N,_,b,R,V;if(e.isPolytree)return e;for("regular"===Polytree.rayIntersectTriangleType&&(t.originalMatrixWorld=e.matrixWorld.clone()),e.updateWorldMatrix(!0,!0),i=e.geometry,temporaryMatrixWithNormalCalc.getNormalMatrix(e.matrix),s=i.groups,b=i.attributes.uv,n=i.attributes.color,f=i.attributes.position,m=i.attributes.normal,E=[],l=u=0,O=(c=i.index?i.index.array:Array(f.array.length/f.itemSize|0).fill().map(function(e,r){return r})).length;u<O;l=u+=3){for(V=[],y=g=0;g<3;y=++g)_=2*(R=c[l+y]),I=new Vector3(f.array[R=3*R],f.array[1+R],f.array[2+R]),R=new Vector3(m.array[R],m.array[1+R],m.array[2+R]),I.applyMatrix4(e.matrix),R.applyMatrix3(temporaryMatrixWithNormalCalc),N=b?{x:b.array[_],y:b.array[1+_]}:void 0,_=n?{x:n.array[_],y:n.array[1+_],z:n.array[2+_]}:void 0,V.push(new Vertex(I,R,N,_));if(void 0===r&&s&&0<s.length){for(P=void 0,p=0,h=s.length;p<h;p++)a=s[p],c[l]>=a.start&&c[l]<a.start+a.count&&((P=new Polygon(V,a.materialIndex)).originalValid=!0);P&&E.push(P)}else(P=new Polygon(V,r)).originalValid=!0,E.push(P)}for(l=d=0,T=E.length;0<=T?d<T:T<d;l=0<=T?++d:--d)isValidTriangle(E[l].triangle)?t.addPolygon(E[l]):E[l].delete();return o&&t.buildTree(),!0!==Polytree.usePolytreeRay&&(t.mesh=e),t}),rule:"inside"}],b:[{array:!0,rule:["inside","coplanar-back"]},{array:!0,rule:["inside","coplanar-front"]},{array:!1,rule:"inside"}]},Polytree.unite=function(e,r,t=!0){var o,n,i;return t?e.isPolytree&&r.isPolytree?Polytree.async.unite(e,r,!0):(o=Polytree.fromMesh(e),n=Polytree.fromMesh(r),i=(i=Array.isArray(e.material)?e.material[0]:e.material).clone(),Polytree.async.unite(o,n,!1).then(function(e){var r=Polytree.toMesh(e,i);return disposePolytreeResources(o,n,e),r})):e.isPolytree&&r.isPolytree?(o=e,n=r,this.uniteCore(o,n,!0)):(o=Polytree.fromMesh(e),n=Polytree.fromMesh(r),i=(i=Array.isArray(e.material)?e.material[0]:e.material).clone(),t=this.uniteCore(o,n,!1),r=Polytree.toMesh(t,i),disposePolytreeResources(o,n,t),r)},subtractRules={a:[{array:!0,rule:["inside","coplanar-back"]},{array:!0,rule:["inside","coplanar-front"]},{array:!(Polytree.uniteCore=function(e,r,t=!0){var o,n,i=new Polytree,a=new Set;return e.box.intersectsBox(r.box)?(n=o=void 0,e.mesh&&(o=e.mesh.material.side,e.mesh.material.side=DoubleSide),r.mesh&&(n=r.mesh.material.side,r.mesh.material.side=DoubleSide),e.resetPolygons(!1),r.resetPolygons(!1),e.markIntesectingPolygons(r),r.markIntesectingPolygons(e),handleIntersectingPolytrees(e,r),e.deleteReplacedPolygons(),r.deleteReplacedPolygons(),e.deletePolygonsByStateRules(uniteRules.a),r.deletePolygonsByStateRules(uniteRules.b),e.getPolygonCloneCallback(i.addPolygon.bind(i),a),r.getPolygonCloneCallback(i.addPolygon.bind(i),a),e.mesh&&e.mesh.material.side!==o&&(e.mesh.material.side=o),r.mesh&&r.mesh.material.side!==n&&(r.mesh.material.side=n)):(e.getPolygonCloneCallback(i.addPolygon.bind(i),a),r.getPolygonCloneCallback(i.addPolygon.bind(i),a)),a.clear(),a=void 0,i.markPolygonsAsOriginal(),t&&i.buildTree(),i}),rule:"inside"}],b:[{array:!0,rule:["outside","coplanar-back"]},{array:!0,rule:["outside","coplanar-front"]},{array:!0,rule:["inside","coplanar-front"]},{array:!1,rule:"outside"}]},Polytree.subtract=function(e,r,t=!0){var o,n,i;return t?e.isPolytree&&r.isPolytree?Polytree.async.subtract(e,r,!0):(o=Polytree.fromMesh(e),n=Polytree.fromMesh(r),i=(i=Array.isArray(e.material)?e.material[0]:e.material).clone(),Polytree.async.subtract(o,n,!1).then(function(e){var r=Polytree.toMesh(e,i);return disposePolytreeResources(o,n,e),r})):e.isPolytree&&r.isPolytree?(o=e,n=r,this.subtractCore(o,n,!0)):(o=Polytree.fromMesh(e),n=Polytree.fromMesh(r),i=(i=Array.isArray(e.material)?e.material[0]:e.material).clone(),t=this.subtractCore(o,n,!1),r=Polytree.toMesh(t,i),disposePolytreeResources(o,n,t),r)},intersectRules={a:[{array:!0,rule:["inside","coplanar-back"]},{array:!0,rule:["outside","coplanar-front"]},{array:!0,rule:["outside","coplanar-back"]},{array:!(Polytree.subtractCore=function(e,r,t=!0){var o,n,i=new Polytree,a=new Set;return e.box.intersectsBox(r.box)?(n=o=void 0,e.mesh&&(o=e.mesh.material.side,e.mesh.material.side=DoubleSide),r.mesh&&(n=r.mesh.material.side,r.mesh.material.side=DoubleSide),e.resetPolygons(!1),r.resetPolygons(!1),e.markIntesectingPolygons(r),r.markIntesectingPolygons(e),handleIntersectingPolytrees(e,r),e.deleteReplacedPolygons(),r.deleteReplacedPolygons(),e.deletePolygonsByStateRules(subtractRules.a),r.deletePolygonsByStateRules(subtractRules.b),r.deletePolygonsByIntersection(!1),r.invert(),e.getPolygonCloneCallback(i.addPolygon.bind(i),a),r.getPolygonCloneCallback(i.addPolygon.bind(i),a),e.mesh&&e.mesh.material.side!==o&&(e.mesh.material.side=o),r.mesh&&r.mesh.material.side!==n&&(r.mesh.material.side=n)):e.getPolygonCloneCallback(i.addPolygon.bind(i),a),a.clear(),a=void 0,i.markPolygonsAsOriginal(),t&&i.buildTree(),i}),rule:"outside"}],b:[{array:!0,rule:["inside","coplanar-front"]},{array:!0,rule:["inside","coplanar-back"]},{array:!0,rule:["outside","coplanar-front"]},{array:!0,rule:["outside","coplanar-back"]},{array:!1,rule:"outside"}]},Polytree.intersect=function(e,r,t=!0){var o,n,i;return t?e.isPolytree&&r.isPolytree?Polytree.async.intersect(e,r,!0):(o=Polytree.fromMesh(e),n=Polytree.fromMesh(r),i=(i=Array.isArray(e.material)?e.material[0]:e.material).clone(),Polytree.async.intersect(o,n,!1).then(function(e){var r=Polytree.toMesh(e,i);return disposePolytreeResources(o,n,e),r})):e.isPolytree&&r.isPolytree?(o=e,n=r,this.intersectCore(o,n,!0)):(o=Polytree.fromMesh(e),n=Polytree.fromMesh(r),i=(i=Array.isArray(e.material)?e.material[0]:e.material).clone(),t=this.intersectCore(o,n,!1),r=Polytree.toMesh(t,i),disposePolytreeResources(o,n,t),r)},Polytree.intersectCore=function(e,r,t=!0){var o,n,i=new Polytree,a=new Set;return e.box.intersectsBox(r.box)&&(n=o=void 0,e.mesh&&(o=e.mesh.material.side,e.mesh.material.side=DoubleSide),r.mesh&&(n=r.mesh.material.side,r.mesh.material.side=DoubleSide),e.resetPolygons(!1),r.resetPolygons(!1),e.markIntesectingPolygons(r),r.markIntesectingPolygons(e),handleIntersectingPolytrees(e,r),e.deleteReplacedPolygons(),r.deleteReplacedPolygons(),e.deletePolygonsByStateRules(intersectRules.a),r.deletePolygonsByStateRules(intersectRules.b),e.deletePolygonsByIntersection(!1),r.deletePolygonsByIntersection(!1),e.getPolygonCloneCallback(i.addPolygon.bind(i),a),r.getPolygonCloneCallback(i.addPolygon.bind(i),a),e.mesh&&e.mesh.material.side!==o&&(e.mesh.material.side=o),r.mesh)&&r.mesh.material.side!==n&&(r.mesh.material.side=n),a.clear(),a=void 0,i.markPolygonsAsOriginal(),t&&i.buildTree(),i},Polytree.async={batchSize:DEFAULT_BUFFER_SIZE,maxWorkerThreads:MAX_WORKER_THREADS,unite:function(n,i,a=!0){return new Promise(function(r,t){var e,o=null;ASYNC_OPERATION_TIMEOUT!==1/0&&(o=setTimeout(function(){return t(new Error(`Union operation timed out after ${ASYNC_OPERATION_TIMEOUT}ms`))},ASYNC_OPERATION_TIMEOUT));try{return e=Polytree.uniteCore(n,i,a),disposePolytreeResources(n,i),o&&clearTimeout(o),r(e)}catch(e){return r=e,o&&clearTimeout(o),disposePolytreeResources(n,i),t(r)}})},subtract:function(n,i,a=!0){return new Promise(function(r,t){var e,o=null;ASYNC_OPERATION_TIMEOUT!==1/0&&(o=setTimeout(function(){return t(new Error(`Subtract operation timed out after ${ASYNC_OPERATION_TIMEOUT}ms`))},ASYNC_OPERATION_TIMEOUT));try{return e=Polytree.subtractCore(n,i,a),disposePolytreeResources(n,i),o&&clearTimeout(o),r(e)}catch(e){return r=e,o&&clearTimeout(o),disposePolytreeResources(n,i),t(r)}})},intersect:function(n,i,a=!0){return new Promise(function(r,t){var e,o=null;ASYNC_OPERATION_TIMEOUT!==1/0&&(o=setTimeout(function(){return t(new Error(`Intersect operation timed out after ${ASYNC_OPERATION_TIMEOUT}ms`))},ASYNC_OPERATION_TIMEOUT));try{return e=Polytree.intersectCore(n,i,a),disposePolytreeResources(n,i),o&&clearTimeout(o),r(e)}catch(e){return r=e,o&&clearTimeout(o),disposePolytreeResources(n,i),t(r)}})},uniteArray:function(e,r=1/0){return Polytree.async.processArrayWithOperation(e,r,Polytree.async.unite,Polytree.async.uniteArray,"union")},subtractArray:function(e,r=1/0){return Polytree.async.processArrayWithOperation(e,r,Polytree.async.subtract,Polytree.async.subtractArray,"subtraction")},intersectArray:function(e,r=1/0){return Polytree.async.processArrayWithOperation(e,r,Polytree.async.intersect,Polytree.async.intersectArray,"intersection")},operation:function(e,r=!1,t=!0,o={objCounter:0},n=!0){return Polytree.operation(e,r,t,o,n,!0)},processArrayWithOperation:function(T,N,_,b,R){return new Promise(function(t,o){var e,r,n,i,a,s,l,c,y,u,g,h,p,d,m,P,E,I,f,O;try{if(O=4<Polytree.async.batchSize&&Polytree.async.batchSize<T.length,g=void 0,l=!1,d=[],O){for(e=[],a=0;a<T.length;)e.push(T.slice(a,a+Polytree.async.batchSize)),a+=Polytree.async.batchSize;for(i=e.shift();i;)r=b(i,0),d.push(r),i=e.shift();l=O=!0,T.length=0}else{for(E=[],p=s=0,I=T.length;0<=I?s<I:I<s;p=0<=I?++s:--s)h=N<p?N:p,n=void 0,T[p].isMesh?n=Polytree.fromMesh(T[p],-1<N?h:void 0):(n=T[p],-1<N&&n.setPolygonIndex(h)),n.polytreeIndex=p,E.push(n);for(g=E.shift(),y=void 0,P=c=0,f=E.length;c<f;P=c+=2){if(E.length<=P+1){y=E[P];break}m=_(E[P],E[P+1]),d.push(m)}y&&(u=_(g,y),d.push(u),l=!0)}return Promise.allSettled(d).then(function(e){var r=[];return e.forEach(function(e){if("fulfilled"===e.status)return r.push(e.value)}),l||r.unshift(g),0<r.length?1===r.length?t(r[0]):3<r.length?b(r,O?0:-1).then(function(e){return t(e)}).catch(function(e){return o(e)}):_(r[0],r[1]).then(function(e){return 3===r.length?_(e,r[2]).then(function(e){return t(e)}).catch(function(e){return o(e)}):t(e)}).catch(function(e){return o(e)}):o(`Unable to find any result polytree after ${R} operation.`)})}catch(e){return o(e)}})}},Plane=class Plane{constructor(e,r){this.normal=e,this.distanceFromOrigin=r}clone(){return new Plane(this.normal.clone(),this.distanceFromOrigin)}flip(){return this.normal.negate(),this.distanceFromOrigin=-this.distanceFromOrigin}equals(e){return this.normal.equals(e.normal)&&this.distanceFromOrigin===e.distanceFromOrigin}delete(){return this.normal=void 0,this.distanceFromOrigin=void 0}static fromPoints(e,r,t){r=temporaryTriangleVertex.copy(r).sub(e).cross(temporaryTriangleVertexSecondary.copy(t).sub(e)).normalize().clone();return new Plane(r,r.dot(e))}},Polygon=class Polygon{constructor(e,r){this.id=polygonID++,this.vertices=e.map(function(e){return e.clone()}),this.shared=r,this.plane=Plane.fromPoints(this.vertices[0].pos,this.vertices[1].pos,this.vertices[2].pos),this.triangle=new Triangle(this.vertices[0].pos,this.vertices[1].pos,this.vertices[2].pos),this.intersects=!1,this.state="undecided",this.previousState="undecided",this.previousStates=[],this.valid=!0,this.coplanar=!1,this.originalValid=!1,this.newPolygon=!1}getMidpoint(){return this.triangle.midPoint||(this.triangle.midPoint=this.triangle.getMidpoint(new Vector3))}applyMatrix(r,t){if(t=t||temporaryMatrixWithNormalCalc.getNormalMatrix(r),this.vertices.forEach(function(e){return e.pos.applyMatrix4(r),e.normal.applyMatrix3(t)}),this.plane.delete(),this.plane=Plane.fromPoints(this.vertices[0].pos,this.vertices[1].pos,this.vertices[2].pos),this.triangle.set(this.vertices[0].pos,this.vertices[1].pos,this.vertices[2].pos),this.triangle.midPoint)return this.triangle.getMidpoint(this.triangle.midPoint)}flip(){var e;return this.vertices.reverse().forEach(function(e){return e.flip()}),e=this.triangle.a,this.triangle.a=this.triangle.c,this.triangle.c=e,this.plane.flip()}reset(e=!0){return this.intersects=!1,this.state="undecided",this.previousState="undecided",this.previousStates.length=0,this.valid=!0,this.coplanar=!1,e&&(this.originalValid=!1),this.newPolygon=!1}setState(e,r){if(this.state!==r)return this.previousState=this.state,"undecided"!==this.state&&this.previousStates.push(this.state),this.state=e}checkAllStates(e){var r,t,o;if(this.state!==e||this.previousState!==e&&"undecided"!==this.previousState)return!1;for(r=0,t=(o=this.previousStates).length;r<t;r++)if(o[r]!==e)return!1;return!0}setInvalid(){return this.valid=!1}setValid(){return this.valid=!0}static createWithDefaultMaterial(e){return new Polygon(e,DEFAULT_MATERIAL_INDEX)}clone(){var e=new Polygon(this.vertices.map(function(e){return e.clone()}),this.shared);return e.intersects=this.intersects,e.valid=this.valid,e.coplanar=this.coplanar,e.state=this.state,e.originalValid=this.originalValid,e.newPolygon=this.newPolygon,e.previousState=this.previousState,e.previousStates=this.previousStates.slice(),this.triangle.midPoint&&(e.triangle.midPoint=this.triangle.midPoint.clone()),e}delete(){return this.vertices.forEach(function(e){return e.delete()}),this.vertices.length=0,this.plane&&(this.plane.delete(),this.plane=void 0),this.triangle=void 0,this.shared=void 0,this.setInvalid()}},isValidTriangle=function(e){return DEBUG_GEOMETRY_VALIDATION&&console.log("Validating triangle:",e.a,e.b,e.c),!(e.a.equals(e.b)||e.a.equals(e.c)||e.b.equals(e.c)||(DEBUG_GEOMETRY_VALIDATION&&console.log("Triangle validation passed."),0))},isUniqueTriangle=function(e,r,t){var o=`{${e.a.x},${e.a.y},${e.a.z}}-{${e.b.x},${e.b.y},${e.b.z}}-{${e.c.x},${e.c.y},${e.c.z}}`;return!0!==r.has(o)&&(r.add(o),t&&t.set(e,e),!0)},pointsEqual2D=function(e,r,t=TRIANGLE_2D_EPSILON){return Math.abs(e.x-r.x)<=t&&Math.abs(e.y-r.y)<=t},pointOnSegmentInclusive2D=function(e,r,t,o=TRIANGLE_2D_EPSILON){var n,i,a;return pointsEqual2D(r,t,o)?pointsEqual2D(e,r,o)||pointsEqual2D(e,t,o):!(Math.abs(triangleOrientation2D(e,r,t))>o)&&(i=Math.min(r.x,t.x)-o,n=Math.max(r.x,t.x)+o,a=Math.min(r.y,t.y)-o,r=Math.max(r.y,t.y)+o,e.x>=i)&&e.x<=n&&e.y>=a&&e.y<=r},pointInTriangleInclusive2D=function(e,r,t,o,n=TRIANGLE_2D_EPSILON){var i,a,s,l=triangleOrientation2D(r,t,o);return n<l?(i=triangleOrientation2D(e,r,t),a=triangleOrientation2D(e,t,o),s=triangleOrientation2D(e,o,r),-n<=i&&-n<=a&&-n<=s):l<-n?(i=triangleOrientation2D(e,r,t),a=triangleOrientation2D(e,t,o),s=triangleOrientation2D(e,o,r),i<=n&&a<=n&&s<=n):pointsEqual2D(r,t,n)&&pointsEqual2D(t,o,n)?pointsEqual2D(e,r,n):pointsEqual2D(r,t,n)?pointOnSegmentInclusive2D(e,t,o,n):pointsEqual2D(t,o,n)||pointsEqual2D(o,r,n)?pointOnSegmentInclusive2D(e,r,t,n):pointOnSegmentInclusive2D(e,r,t,n)||pointOnSegmentInclusive2D(e,t,o,n)||pointOnSegmentInclusive2D(e,o,r,n)},triangleIntersectsTriangle=function(e,r,t={coplanar:!1,source:new Vector3,target:new Vector3}){var o,n,i,a,s,l,c,y,u=e.a,g=e.b,e=e.c,h=r.a,p=r.b,r=r.c;return temporaryVector3Primary.copy(h).sub(r),temporaryVector3Secondary.copy(p).sub(r),y=(new Vector3).copy(temporaryVector3Primary).cross(temporaryVector3Secondary),temporaryVector3Primary.copy(u).sub(r),o=temporaryVector3Primary.dot(y),temporaryVector3Primary.copy(g).sub(r),i=temporaryVector3Primary.dot(y),temporaryVector3Primary.copy(e).sub(r),s=temporaryVector3Primary.dot(y),!(0<o*i&&0<o*s||(temporaryVector3Primary.copy(g).sub(u),temporaryVector3Secondary.copy(e).sub(u),c=(new Vector3).copy(temporaryVector3Primary).cross(temporaryVector3Secondary),temporaryVector3Primary.copy(h).sub(e),n=temporaryVector3Primary.dot(c),temporaryVector3Primary.copy(p).sub(e),a=temporaryVector3Primary.dot(c),temporaryVector3Primary.copy(r).sub(e),l=temporaryVector3Primary.dot(c),0<n*a&&0<n*l))&&(t.normal1=c,t.normal2=y,0<o?0<i?resolveTriangleIntersection(e,u,g,h,r,p,n,l,a,t):0<s?resolveTriangleIntersection(g,e,u,h,r,p,n,l,a,t):resolveTriangleIntersection(u,g,e,h,p,r,n,a,l,t):o<0?i<0?resolveTriangleIntersection(e,u,g,h,p,r,n,a,l,t):s<0?resolveTriangleIntersection(g,e,u,h,p,r,n,a,l,t):resolveTriangleIntersection(u,g,e,h,r,p,n,l,a,t):i<0?0<=s?resolveTriangleIntersection(g,e,u,h,r,p,n,l,a,t):resolveTriangleIntersection(u,g,e,h,p,r,n,a,l,t):0<i?0<s?resolveTriangleIntersection(u,g,e,h,r,p,n,l,a,t):resolveTriangleIntersection(g,e,u,h,p,r,n,a,l,t):0<s?resolveTriangleIntersection(e,u,g,h,p,r,n,a,l,t):s<0?resolveTriangleIntersection(e,u,g,h,r,p,n,l,a,t):(t.coplanar=!0,resolveCoplanarTriangleIntersection(u,g,e,h,p,r,c,y)))},resolveTriangleIntersection=function(e,r,t,o,n,i,a,s,l,c){return!(0<a&&0<s&&0<l||a<0&&s<0&&l<0)&&(0<a?0<s?constructIntersection(e,t,r,i,o,n,c):0<l?constructIntersection(e,t,r,n,i,o,c):constructIntersection(e,r,t,o,n,i,c):a<0?s<0?constructIntersection(e,r,t,i,o,n,c):l<0?constructIntersection(e,r,t,n,i,o,c):constructIntersection(e,t,r,o,n,i,c):s<0?0<=l?constructIntersection(e,t,r,n,i,o,c):constructIntersection(e,r,t,o,n,i,c):0<s?0<l?constructIntersection(e,t,r,o,n,i,c):constructIntersection(e,r,t,n,i,o,c):0<l?constructIntersection(e,r,t,i,o,n,c):l<0?constructIntersection(e,t,r,i,o,n,c):(c.coplanar=!0,resolveCoplanarTriangleIntersection(e,r,t,o,n,i,c.normal1,c.normal2)))},resolveCoplanarTriangleIntersection=function(e,r,t,o,n,i,a,s){var l=new Vector2,c=new Vector2,y=new Vector2,u=new Vector2,g=new Vector2,h=new Vector2,p=Math.abs(a.x),d=Math.abs(a.y),a=Math.abs(a.z);return a<p&&d<=p?(l.set(e.y,e.z),c.set(r.y,r.z),y.set(t.y,t.z),u.set(o.y,o.z),g.set(n.y,n.z),h.set(i.y,i.z)):a<d&&p<=d?(l.set(e.x,e.z),c.set(r.x,r.z),y.set(t.x,t.z),u.set(o.x,o.z),g.set(n.x,n.z),h.set(i.x,i.z)):(l.set(e.x,e.y),c.set(r.x,r.y),y.set(t.x,t.y),u.set(o.x,o.y),g.set(n.x,n.y),h.set(i.x,i.y)),trianglesOverlap2D(l,c,y,u,g,h)},trianglesOverlap2D=function(e,r,t,o,n,i){var a,s,l,c,y,u,g,h,p,d,m,P,E,I,f;return pointsEqual2D(o,n,TRIANGLE_2D_EPSILON)&&pointsEqual2D(n,i,TRIANGLE_2D_EPSILON)?pointInTriangleInclusive2D(o,e,r,t,TRIANGLE_2D_EPSILON):pointsEqual2D(e,r,TRIANGLE_2D_EPSILON)&&pointsEqual2D(r,t,TRIANGLE_2D_EPSILON)?pointInTriangleInclusive2D(e,o,n,i,TRIANGLE_2D_EPSILON):(u=function(e,r,t){return pointsEqual2D(e,r,TRIANGLE_2D_EPSILON)?[r,t]:(pointsEqual2D(r,t,TRIANGLE_2D_EPSILON),[e,r])},(g=function(e,r,t){return pointsEqual2D(e,r,TRIANGLE_2D_EPSILON)&&!pointsEqual2D(r,t,TRIANGLE_2D_EPSILON)||pointsEqual2D(r,t,TRIANGLE_2D_EPSILON)&&!pointsEqual2D(e,r,TRIANGLE_2D_EPSILON)||pointsEqual2D(t,e,TRIANGLE_2D_EPSILON)&&!pointsEqual2D(e,r,TRIANGLE_2D_EPSILON)})(e,r,t)&&g(o,n,i)?([g,a]=u(e,r,t),[u,c]=u(o,n,i),m=Math.min(g.x,a.x),f=Math.max(g.x,a.x),P=Math.min(g.y,a.y),h=Math.max(g.y,a.y),E=Math.min(u.x,c.x),p=Math.max(u.x,c.x),I=Math.min(u.y,c.y),d=Math.max(u.y,c.y),!(f<E-TRIANGLE_2D_EPSILON||p<m-TRIANGLE_2D_EPSILON||h<I-TRIANGLE_2D_EPSILON||d<P-TRIANGLE_2D_EPSILON||Math.abs(triangleOrientation2D(g,a,u))>TRIANGLE_2D_EPSILON||(f=Math.abs(a.x-g.x),E=Math.abs(a.y-g.y)<=f?(l=Math.min(g.x,a.x)-TRIANGLE_2D_EPSILON,s=Math.max(g.x,a.x)+TRIANGLE_2D_EPSILON,y=Math.min(u.x,c.x)-TRIANGLE_2D_EPSILON,Math.max(u.x,c.x)+TRIANGLE_2D_EPSILON):(l=Math.min(g.y,a.y)-TRIANGLE_2D_EPSILON,s=Math.max(g.y,a.y)+TRIANGLE_2D_EPSILON,y=Math.min(u.y,c.y)-TRIANGLE_2D_EPSILON,Math.max(u.y,c.y)+TRIANGLE_2D_EPSILON),s<y)||E<l)):triangleOrientation2D(e,r,t)<0?triangleOrientation2D(o,n,i)<0?triangleIntersectionCCW2D(e,t,r,o,i,n):triangleIntersectionCCW2D(e,t,r,o,n,i):triangleOrientation2D(o,n,i)<0?triangleIntersectionCCW2D(e,r,t,o,i,n):triangleIntersectionCCW2D(e,r,t,o,n,i))},triangleOrientation2D=function(e,r,t){return(e.x-t.x)*(r.y-t.y)-(e.y-t.y)*(r.x-t.x)},triangleIntersectionCCW2D=function(e,r,t,o,n,i){return 0<=triangleOrientation2D(o,n,e)?0<=triangleOrientation2D(n,i,e)?0<=triangleOrientation2D(i,o,e)||intersectionTestEdge2D(e,r,t,o,n,i):0<=triangleOrientation2D(i,o,e)?intersectionTestEdge2D(e,r,t,i,o,n):intersectionTestVertex2D(e,r,t,o,n,i):0<=triangleOrientation2D(n,i,e)?(0<=triangleOrientation2D(i,o,e)?intersectionTestEdge2D:intersectionTestVertex2D)(e,r,t,n,i,o):intersectionTestVertex2D(e,r,t,i,o,n)},intersectionTestEdge2D=function(e,r,t,o,n,i){for(var a,s,l,c,y,u,g=function(e,r,t,o){var n=Math.min(e.x,r.x),i=Math.max(e.x,r.x),a=Math.min(e.y,r.y),s=Math.max(e.y,r.y),l=Math.min(t.x,o.x),c=Math.max(t.x,o.x),y=Math.min(t.y,o.y),u=Math.max(t.y,o.y);return!(i<l||c<n||s<y||u<a)&&(i=triangleOrientation2D(e,r,t),l=triangleOrientation2D(e,r,o),c=triangleOrientation2D(t,o,e),n=triangleOrientation2D(t,o,r),(0<i&&l<0||i<0&&0<l)&&(0<c&&n<0||c<0&&0<n)||!!(Math.abs(i)<=TRIANGLE_2D_EPSILON&&pointOnSegmentInclusive2D(t,e,r,TRIANGLE_2D_EPSILON)||Math.abs(l)<=TRIANGLE_2D_EPSILON&&pointOnSegmentInclusive2D(o,e,r,TRIANGLE_2D_EPSILON)||Math.abs(c)<=TRIANGLE_2D_EPSILON&&pointOnSegmentInclusive2D(e,t,o,TRIANGLE_2D_EPSILON)||Math.abs(n)<=TRIANGLE_2D_EPSILON&&pointOnSegmentInclusive2D(r,t,o,TRIANGLE_2D_EPSILON)))},h=[[e,r],[r,t],[t,e]],p=[[o,n],[n,i],[i,o]],d=0,m=h.length;d<m;d++)for([a,s]=h[d],y=0,u=p.length;y<u;y++)if([l,c]=p[y],g(a,s,l,c))return!0;return!1},intersectionTestVertex2D=function(e,r,t,o,n,i){return!!pointInTriangleInclusive2D(o,e,r,t,TRIANGLE_2D_EPSILON)||!!pointInTriangleInclusive2D(n,e,r,t,TRIANGLE_2D_EPSILON)||!!(pointInTriangleInclusive2D(i,e,r,t,TRIANGLE_2D_EPSILON)||pointInTriangleInclusive2D(e,o,n,i,TRIANGLE_2D_EPSILON)||pointInTriangleInclusive2D(r,o,n,i,TRIANGLE_2D_EPSILON)||pointInTriangleInclusive2D(t,o,n,i,TRIANGLE_2D_EPSILON))},constructIntersection=function(e,r,t,o,n,i,a){var s=void 0,l=new Vector3;return temporaryVector3Primary.subVectors(r,e),temporaryVector3Secondary.subVectors(i,e),l.copy(temporaryVector3Primary).cross(temporaryVector3Secondary),temporaryVector3Quaternary.subVectors(o,e),0<temporaryVector3Quaternary.dot(l)?(temporaryVector3Primary.subVectors(t,e),l.copy(temporaryVector3Primary).cross(temporaryVector3Secondary),temporaryVector3Quaternary.dot(l)<=0&&(temporaryVector3Secondary.subVectors(n,e),l.copy(temporaryVector3Primary).cross(temporaryVector3Secondary),0<temporaryVector3Quaternary.dot(l)?(temporaryVector3Primary.subVectors(e,o),temporaryVector3Secondary.subVectors(e,t),s=temporaryVector3Primary.dot(a.normal2)/temporaryVector3Secondary.dot(a.normal2),!!isFinite(s)&&(temporaryVector3Primary.copy(temporaryVector3Secondary).multiplyScalar(s),a.source.subVectors(e,temporaryVector3Primary),temporaryVector3Primary.subVectors(o,e),temporaryVector3Secondary.subVectors(o,i),s=temporaryVector3Primary.dot(a.normal1)/temporaryVector3Secondary.dot(a.normal1),!!isFinite(s))&&(temporaryVector3Primary.copy(temporaryVector3Secondary).multiplyScalar(s),a.target.subVectors(o,temporaryVector3Primary),!0)):(temporaryVector3Primary.subVectors(o,e),temporaryVector3Secondary.subVectors(o,n),s=temporaryVector3Primary.dot(a.normal1)/temporaryVector3Secondary.dot(a.normal1),!!isFinite(s)&&(temporaryVector3Primary.copy(temporaryVector3Secondary).multiplyScalar(s),a.source.subVectors(o,temporaryVector3Primary),temporaryVector3Primary.subVectors(o,e),temporaryVector3Secondary.subVectors(o,i),s=temporaryVector3Primary.dot(a.normal1)/temporaryVector3Secondary.dot(a.normal1),!!isFinite(s))&&(temporaryVector3Primary.copy(temporaryVector3Secondary).multiplyScalar(s),a.target.subVectors(o,temporaryVector3Primary),!0)))):(temporaryVector3Secondary.subVectors(n,e),l.copy(temporaryVector3Primary).cross(temporaryVector3Secondary),!(temporaryVector3Quaternary.dot(l)<0||(temporaryVector3Primary.subVectors(t,e),l.copy(temporaryVector3Primary).cross(temporaryVector3Secondary),temporaryVector3Quaternary.dot(l)<0?(temporaryVector3Primary.subVectors(o,e),temporaryVector3Secondary.subVectors(o,n),s=temporaryVector3Primary.dot(a.normal1)/temporaryVector3Secondary.dot(a.normal1),!isFinite(s)||(temporaryVector3Primary.copy(temporaryVector3Secondary).multiplyScalar(s),a.source.subVectors(o,temporaryVector3Primary),temporaryVector3Primary.subVectors(o,e),temporaryVector3Secondary.subVectors(o,i),s=temporaryVector3Primary.dot(a.normal1)/temporaryVector3Secondary.dot(a.normal1),!isFinite(s))||(temporaryVector3Primary.copy(temporaryVector3Secondary).multiplyScalar(s),a.target.subVectors(o,temporaryVector3Primary),0)):(temporaryVector3Primary.subVectors(e,o),temporaryVector3Secondary.subVectors(e,t),s=temporaryVector3Primary.dot(a.normal2)/temporaryVector3Secondary.dot(a.normal2),!isFinite(s)||(temporaryVector3Primary.copy(temporaryVector3Secondary).multiplyScalar(s),a.source.subVectors(e,temporaryVector3Primary),temporaryVector3Primary.subVectors(e,o),temporaryVector3Secondary.subVectors(e,r),s=temporaryVector3Primary.dot(a.normal2)/temporaryVector3Secondary.dot(a.normal2),!isFinite(s))||(temporaryVector3Primary.copy(temporaryVector3Secondary).multiplyScalar(s),a.target.subVectors(e,temporaryVector3Primary),0)))))},Vertex=class Vertex{constructor(e,r,t,o){this.pos=(new Vector3).copy(e),this.normal=(new Vector3).copy(r),t&&(this.uv=(new Vector2).copy(t)),o&&(this.color=(new Vector3).copy(o))}clone(){return new Vertex(this.pos.clone(),this.normal.clone(),this.uv&&this.uv.clone(),this.color&&this.color.clone())}flip(){return this.normal.negate()}interpolate(e,r){return new Vertex(this.pos.clone().lerp(e.pos,r),this.normal.clone().lerp(e.normal,r),this.uv&&e.uv&&this.uv.clone().lerp(e.uv,r),this.color&&e.color&&this.color.clone().lerp(e.color,r))}delete(){return this.pos=void 0,this.normal=void 0,this.uv&&(this.uv=void 0),this.color&&(this.color=void 0)}};export default Polytree;export{GEOMETRIC_EPSILON,RAY_INTERSECTION_EPSILON,TRIANGLE_2D_EPSILON,WINDING_NUMBER_FULL_ROTATION,POLYGON_COPLANAR,POLYGON_FRONT,POLYGON_BACK,POLYGON_SPANNING,temporaryVector3Primary,temporaryVector3Secondary,temporaryVector3Tertiary,temporaryVector3Quaternary,temporaryBoundingBox,temporaryRaycaster,temporaryRay,defaultRayDirection,windingNumberVector1,windingNumberVector2,windingNumberVector3,windingNumberTestPoint,windingNumberEpsilonOffsets,windingNumberEpsilonOffsetsCount,windingNumberMatrix3,rayTriangleEdge1,rayTriangleEdge2,rayTriangleHVector,rayTriangleSVector,rayTriangleQVector,temporaryTriangleVertex,temporaryTriangleVertexSecondary,temporaryMatrix3,temporaryMatrixWithNormalCalc,meshOperationNormalVector,meshOperationVertexVector,POLYTREE_MAX_DEPTH,POLYTREE_MAX_POLYGONS_PER_NODE,POLYTREE_MIN_NODE_SIZE,DEFAULT_MATERIAL_INDEX,MAX_REFINEMENT_ITERATIONS,DEFAULT_COORDINATE_PRECISION,POINT_COINCIDENCE_THRESHOLD,DEFAULT_BUFFER_SIZE,MAX_WORKER_THREADS,ASYNC_OPERATION_TIMEOUT,GARBAGE_COLLECTION_THRESHOLD,MEMORY_USAGE_WARNING_LIMIT,GEOMETRY_CACHE_SIZE,INTERSECTION_CACHE_SIZE,polygonID,DEBUG_VERBOSE_LOGGING,DEBUG_PERFORMANCE_TIMING,DEBUG_GEOMETRY_VALIDATION,DEBUG_INTERSECTION_VERIFICATION,DEBUG_COLOR_FRONT,DEBUG_COLOR_BACK,DEBUG_COLOR_COPLANAR,DEBUG_COLOR_SPANNING,Polytree,Plane,Vertex,Polygon,createVector2Buffer,createVector3Buffer,isValidTriangle,isUniqueTriangle,testRayTriangleIntersection as rayIntersectsTriangle,triangleIntersectsTriangle,resolveTriangleIntersection,resolveCoplanarTriangleIntersection,sortRaycastIntersectionsByDistance,roundPointCoordinates,extractCoordinatesFromArray,splitPolygonByPlane,splitPolygonVertexArray,prepareTriangleBufferFromPolygons,calculateWindingNumberFromBuffer,testPolygonInsideUsingWindingNumber,testRayTriangleIntersection,handleIntersectingPolytrees,disposePolytreeResources,trianglesOverlap2D,triangleOrientation2D,triangleIntersectionCCW2D,intersectionTestEdge2D,intersectionTestVertex2D,constructIntersection};