@recast-navigation/three 0.24.1 → 0.25.0

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.
@@ -0,0 +1,45 @@
1
+ import { NavMesh, NavMeshQuery, RecastCompactHeightfield, RecastContourSet, RecastHeightfield, RecastHeightfieldLayer, RecastHeightfieldLayerSet, RecastPolyMesh, RecastPolyMeshDetail } from '@recast-navigation/core';
2
+ import * as THREE from 'three';
3
+ import { LineMaterial } from 'three-stdlib';
4
+ export type DebugDrawerParams = {
5
+ triMaterial?: THREE.Material;
6
+ pointMaterial?: THREE.Material;
7
+ lineMaterial?: LineMaterial;
8
+ };
9
+ export declare class DebugDrawer extends THREE.Group {
10
+ triMaterial: THREE.Material;
11
+ pointMaterial: THREE.Material;
12
+ pointGeometry: THREE.SphereGeometry;
13
+ lineMaterial: LineMaterial;
14
+ private debugDrawImpl;
15
+ private currentVertices;
16
+ private currentPrimitive;
17
+ constructor({ triMaterial, pointMaterial, lineMaterial, }?: DebugDrawerParams);
18
+ debugDrawHeightfieldSolid(hf: RecastHeightfield): void;
19
+ debugDrawHeightfieldWalkable(hf: RecastHeightfield): void;
20
+ debugDrawCompactHeightfieldSolid(chf: RecastCompactHeightfield): void;
21
+ debugDrawCompactHeightfieldRegions(chf: RecastCompactHeightfield): void;
22
+ debugDrawCompactHeightfieldDistance(chf: RecastCompactHeightfield): void;
23
+ debugDrawHeightfieldLayer(layer: RecastHeightfieldLayer, idx: number): void;
24
+ debugDrawHeightfieldLayers(lset: RecastHeightfieldLayerSet): void;
25
+ debugDrawRegionConnections(cset: RecastContourSet, alpha: number): void;
26
+ debugDrawRawContours(cset: RecastContourSet, alpha: number): void;
27
+ debugDrawContours(cset: RecastContourSet, alpha: number): void;
28
+ debugDrawPolyMesh(mesh: RecastPolyMesh): void;
29
+ debugDrawPolyMeshDetail(dmesh: RecastPolyMeshDetail): void;
30
+ debugDrawNavMesh(mesh: NavMesh, flags: number): void;
31
+ debugDrawNavMeshWithClosedList(mesh: NavMesh, query: NavMeshQuery, flags: number): void;
32
+ debugDrawNavMeshNodes(query: NavMeshQuery): void;
33
+ debugDrawNavMeshBVTree(mesh: NavMesh): void;
34
+ debugDrawNavMeshPortals(mesh: NavMesh): void;
35
+ debugDrawNavMeshPolysWithFlags(mesh: NavMesh, flags: number, col: number): void;
36
+ debugDrawNavMeshPoly(mesh: NavMesh, ref: number, col: number): void;
37
+ resize(width: number, height: number): void;
38
+ reset(): void;
39
+ dispose(): void;
40
+ private vertex;
41
+ private endPoints;
42
+ private endLines;
43
+ private endTris;
44
+ private endQuads;
45
+ }
@@ -0,0 +1 @@
1
+ export * from './debug-drawer';
@@ -1,5 +1,4 @@
1
1
  export * from './crowd-helper';
2
- export * from './heightfield-helper';
3
2
  export * from './nav-mesh-helper';
4
3
  export * from './off-mesh-connections-helper';
5
4
  export * from './tile-cache-helper';
package/dist/index.cjs CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";var e=require("three"),t=require("@recast-navigation/core");class i extends e.Object3D{agentMeshes=new Map;recastCrowd;agentMaterial;constructor({crowd:t,agentMaterial:i}){super(),this.recastCrowd=t,this.agentMaterial=i??new e.MeshBasicMaterial({color:"red"}),this.update()}update(){const t=this.recastCrowd.getAgents(),i=new Set(this.agentMeshes.keys());for(const a of t){i.delete(a.agentIndex);const t=a.position(),r=a.velocity();let s=this.agentMeshes.get(a.agentIndex);void 0===s?(s=this.createAgentMesh(a),this.add(s),this.agentMeshes.set(a.agentIndex,s)):this.updateAgentGeometry(s,a),s.position.set(t.x,t.y+a.height/2,t.z),s.lookAt((new e.Vector3).copy(s.position).add(r))}for(const e of i){const t=this.agentMeshes.get(e);t&&(this.remove(t),this.agentMeshes.delete(e))}}createAgentMesh(t){const i=new e.Mesh;return i.material=this.agentMaterial,this.updateAgentGeometry(i,t),i.userData={radius:t.radius,height:t.height},i}updateAgentGeometry(t,i){if(t.userData.radius!==i.radius||t.userData.height!==i.height){const a=new e.CylinderGeometry(i.radius,i.radius,i.height);t.geometry.dispose(),t.geometry=a,t.userData.radius=i.radius,t.userData.height=i.height}}}const a=new e.Matrix4;class r extends e.Object3D{heightfields;highlightWalkable;defaultColor;walkableColor;material;constructor({heightfields:t,highlightWalkable:i=!1,material:a=new e.MeshBasicMaterial,defaultColor:r="blue",walkableColor:s="green"}){super(),this.heightfields=t,this.highlightWalkable=i,this.material=a,this.defaultColor=new e.Color(r),this.walkableColor=new e.Color(s),this.update()}update(){this.clear();for(const t of this.heightfields){const i=t.bmin(),r=t.cs(),s=t.ch(),l=t.width(),o=t.height(),n=[];for(let e=0;e<o;++e)for(let a=0;a<l;++a){const o=i.x+a*r,h=i.z+e*r;let c=t.spans(a+e*l);for(;c;){const e=o,t=i.y+c.smin()*s,a=h,l=o+r,d=i.y+c.smax()*s,g=h+r;n.push({position:[(l+e)/2,(d+t)/2,(g+a)/2],walkable:this.highlightWalkable&&0!==c.area()}),c=c.next()}}const h=new e.BoxGeometry(r,s,r),c=new e.InstancedMesh(h,this.material,n.length);c.instanceMatrix.setUsage(e.DynamicDrawUsage);for(let e=0;e<n.length;e++){const{position:t,walkable:i}=n[e];c.setMatrixAt(e,a.setPosition(...t)),c.setColorAt(e,i?this.walkableColor:this.defaultColor)}c.instanceMatrix.needsUpdate=!0,c.instanceColor&&(c.instanceColor.needsUpdate=!0),this.add(c)}}}class s extends e.Object3D{navMesh;navMeshMaterial;mesh;geometry;constructor({navMesh:t,navMeshMaterial:i}){super(),this.navMesh=t,this.geometry=new e.BufferGeometry,this.navMeshMaterial=i||new e.MeshBasicMaterial({color:"orange",transparent:!0,opacity:.7,depthWrite:!1}),this.update(),this.mesh=new e.Mesh(this.geometry,this.navMeshMaterial),this.add(this.mesh)}update(){const[t,i]=this.navMesh.getDebugNavMesh();this.geometry.setAttribute("position",new e.BufferAttribute(Float32Array.from(t),3)),this.geometry.setIndex(new e.BufferAttribute(Uint32Array.from(i),1)),this.geometry.computeVertexNormals()}}class l extends e.Object3D{offMeshConnections;entryCircleMaterial;exitCircleMaterial;lineMaterial;constructor({offMeshConnections:t,entryCircleMaterial:i,exitCircleMaterial:a,lineMaterial:r}){super(),this.offMeshConnections=t??[],this.entryCircleMaterial=i??new e.MeshBasicMaterial({color:"green"}),this.exitCircleMaterial=a??new e.MeshBasicMaterial({color:"blue"}),this.lineMaterial=r??new e.LineBasicMaterial({color:"red"}),this.update()}update(){this.clear();for(const t of this.offMeshConnections){const i=new e.CircleGeometry(t.radius,16),a=new e.Mesh(i,this.entryCircleMaterial);a.position.copy(t.startPosition),a.position.y+=.001,a.rotation.x=-Math.PI/2,this.add(a);const r=new e.Mesh(i,t.bidirectional?this.entryCircleMaterial:this.exitCircleMaterial);r.position.copy(t.endPosition),r.position.y+=.001,r.rotation.x=-Math.PI/2,this.add(r);const s=(new e.Vector3).copy(t.startPosition),l=(new e.Vector3).copy(t.endPosition),o=(new e.Vector3).addVectors(s,l).multiplyScalar(.5);o.y*=1.2;const n=new e.CatmullRomCurve3([s,o,l]).getPoints(50),h=(new e.BufferGeometry).setFromPoints(n),c=new e.Line(h,this.lineMaterial);this.add(c)}}}class o extends e.Object3D{tileCache;obstacleMeshes=new Map;obstacleMaterial;constructor({tileCache:t,obstacleMaterial:i}){super(),this.tileCache=t,this.obstacleMaterial=i||new e.MeshBasicMaterial({color:"red",wireframe:!0,wireframeLinewidth:2}),this.update()}update(){const t=new Set(this.obstacleMeshes.keys());for(const[,i]of this.tileCache.obstacles){const a=this.obstacleMeshes.get(i);if(t.delete(i),!a){const{position:t}=i,a=new e.Mesh(void 0,this.obstacleMaterial);if(a.position.copy(t),"box"===i.type){const{extent:t,angle:r}=i;a.geometry=new e.BoxGeometry(2*t.x,2*t.y,2*t.z),a.rotation.y=r}else{if("cylinder"!==i.type)throw new Error(`Unknown obstacle type: ${i}`);{const{radius:t,height:r}=i;a.geometry=new e.CylinderGeometry(t,t,r,16),a.position.y+=r/2}}this.add(a),this.obstacleMeshes.set(i,a)}}for(const e of t){const t=this.obstacleMeshes.get(e);t&&(this.remove(t),this.obstacleMeshes.delete(e))}}}const n=(e,i)=>{const a={x:1/0,y:1/0,z:1/0},r={x:-1/0,y:-1/0,z:-1/0};for(let t=0;t<i.length;t++){const s=i[t],l=e[3*s],o=e[3*s+1],n=e[3*s+2];a.x=Math.min(a.x,l),a.y=Math.min(a.y,o),a.z=Math.min(a.z,n),r.x=Math.max(r.x,l),r.y=Math.max(r.y,o),r.z=Math.max(r.z,n)}return{bbMin:t.vec3.toArray(a),bbMax:t.vec3.toArray(r)}},h=e=>{let t=0,i=0;return t=Number(e>65535)<<4,e>>=t,i=Number(e>255)<<3,e>>=i,t|=i,i=Number(e>15)<<2,e>>=i,t|=i,i=Number(e>3)<<1,t|=i,t|=(e>>=i)>>1,t},c=e=>(e--,e|=e>>1,e|=e>>2,e|=e>>4,e|=e>>8,e|=e>>16,++e),d={...t.recastConfigDefaults},g={...t.recastConfigDefaults,tileSize:32,expectedLayersPerTile:4,maxObstacles:128},u=(e,i,a={},r=!1)=>{const s=new t.RecastBuildContext,l={type:"tilecache",buildContext:s,chunkyTriMesh:void 0,tileIntermediates:[]},o=new t.TileCache,d=new t.NavMesh,u=()=>{if(!r)for(let e=0;e<l.tileIntermediates.length;e++){const i=l.tileIntermediates[e];i.heightfield&&(t.freeHeightfield(i.heightfield),i.heightfield=void 0),i.compactHeightfield&&(t.freeCompactHeightfield(i.compactHeightfield),i.compactHeightfield=void 0),i.heightfieldLayerSet&&(t.freeHeightfieldLayerSet(i.heightfieldLayerSet),i.heightfieldLayerSet=void 0)}},f=e=>(u(),o.destroy(),d.destroy(),{success:!1,navMesh:void 0,tileCache:void 0,intermediates:l,error:e}),m=e,b=i.length,M=new t.Arrays.VertsArray;M.copy(m,m.length);const y=i,w=i.length/3,p=new t.Arrays.TrisArray;p.copy(y,y.length);const{bbMin:C,bbMax:x}=n(e,i),{expectedLayersPerTile:S,maxObstacles:R,...A}={...g,...a},k=t.createRcConfig(A),v=t.calcGridSize(C,x,k.cs);k.width=v.width,k.height=v.height,k.minRegionArea=k.minRegionArea*k.minRegionArea,k.mergeRegionArea=k.mergeRegionArea*k.mergeRegionArea,k.detailSampleDist=k.detailSampleDist<.9?0:k.cs*k.detailSampleDist,k.detailSampleMaxError=k.ch*k.detailSampleMaxError;const H=Math.floor(k.tileSize),T=Math.floor((k.width+H-1)/H),z=Math.floor((k.height+H-1)/H);k.borderSize=k.walkableRadius+3,k.width=k.tileSize+2*k.borderSize,k.height=k.tileSize+2*k.borderSize;const _=t.DetourTileCacheParams.create({orig:C,cs:k.cs,ch:k.ch,width:k.tileSize,height:k.tileSize,walkableHeight:k.walkableHeight,walkableRadius:k.walkableRadius,walkableClimb:k.walkableClimb,maxSimplificationError:k.maxSimplificationError,maxTiles:T*z*S,maxObstacles:R}),D=new t.Raw.RecastLinearAllocator(32e3),L=new t.Raw.RecastFastLZCompressor,P=a.tileCacheMeshProcess??new t.TileCacheMeshProcess(((e,t,i)=>{for(let a=0;a<e.polyCount();++a)t.set(a,0),i.set(a,1)}));if(!o.init(_,D,L,P))return f("Failed to initialize tile cache");const E=t.vec3.fromArray(C);let F=Math.min(Math.floor(h(c(T*z*S))),14);F>14&&(F=14);const O=1<<F,W=1<<22-F,I=t.NavMeshParams.create({orig:E,tileWidth:k.tileSize*k.cs,tileHeight:k.tileSize*k.cs,maxTiles:O,maxPolys:W});if(!d.initTiled(I))return f("Failed to initialize tiled navmesh");const G=new t.RecastChunkyTriMesh;if(l.chunkyTriMesh=G,!G.init(M,p,w,256))return f("Failed to build chunky triangle mesh");const N=(e,i)=>{const a={tileX:e,tileY:i},o=k.tileSize*k.cs,n=t.cloneRcConfig(k),h=[C[0]+e*o,C[1],C[2]+i*o],c=[C[0]+(e+1)*o,x[1],C[2]+(i+1)*o];h[0]-=n.borderSize*n.cs,h[2]-=n.borderSize*n.cs,c[0]+=n.borderSize*n.cs,c[2]+=n.borderSize*n.cs,n.set_bmin(0,h[0]),n.set_bmin(1,h[1]),n.set_bmin(2,h[2]),n.set_bmax(0,c[0]),n.set_bmax(1,c[1]),n.set_bmax(2,c[2]);const d=t.allocHeightfield();if(a.heightfield=d,!t.createHeightfield(s,d,n.width,n.height,h,c,n.cs,n.ch))return{n:0};const g=[h[0],h[2]],u=[c[0],c[2]],f=new t.Arrays.ChunkIdsArray;f.resize(512);const m=G.getChunksOverlappingRect(g,u,f,512);if(0===m)return{n:0};for(let e=0;e<m;++e){const i=f.get_data(e),a=G.nodes(i).n,r=G.getNodeTris(i),l=new t.Arrays.TriAreasArray;l.resize(a),t.markWalkableTriangles(s,n.walkableSlopeAngle,M,b,r,a,l);const o=t.rasterizeTriangles(s,M,b,r,l,a,d,n.walkableClimb);if(l.free(),!o)return{n:0}}t.filterLowHangingWalkableObstacles(s,k.walkableClimb,d),t.filterLedgeSpans(s,k.walkableHeight,k.walkableClimb,d),t.filterWalkableLowHeightSpans(s,k.walkableHeight,d);const y=t.allocCompactHeightfield();if(!t.buildCompactHeightfield(s,k.walkableHeight,k.walkableClimb,d,y))return{n:0};if(r||(t.freeHeightfield(a.heightfield),a.heightfield=void 0),!t.erodeWalkableArea(s,k.walkableRadius,y))return{n:0};const w=t.allocHeightfieldLayerSet();if(!t.buildHeightfieldLayers(s,y,k.borderSize,k.walkableHeight,w))return{n:0};r||(t.freeCompactHeightfield(y),a.compactHeightfield=void 0);const p=[];for(let a=0;a<w.nlayers();a++){const r=new t.Arrays.TileCacheData,s=w.layers(a),l=new t.Raw.dtTileCacheLayerHeader;l.magic=t.Raw.Detour.TILECACHE_MAGIC,l.version=t.Raw.Detour.TILECACHE_VERSION,l.tx=e,l.ty=i,l.tlayer=a;const o=s.bmin(),n=s.bmax();l.set_bmin(0,o.x),l.set_bmin(1,o.y),l.set_bmin(2,o.z),l.set_bmax(0,n.x),l.set_bmax(1,n.y),l.set_bmax(2,n.z),l.width=s.width(),l.height=s.height(),l.minx=s.minx(),l.maxx=s.maxx(),l.miny=s.miny(),l.maxy=s.maxy(),l.hmin=s.hmin(),l.hmax=s.hmax();const h=t.getHeightfieldLayerHeights(s),c=t.getHeightfieldLayerAreas(s),d=t.getHeightfieldLayerCons(s),g=t.buildTileCacheLayer(L,l,h,c,d,r);if(t.Raw.Detour.statusFailed(g))return{n:0};p.push(r)}return r||(t.freeHeightfieldLayerSet(w),a.heightfieldLayerSet=void 0),l.tileIntermediates.push(a),{n:p.length,tiles:p}};for(let e=0;e<z;++e)for(let i=0;i<T;++i){const{n:a,tiles:r}=N(i,e);if(a>0&&r)for(let l=0;l<a;l++){const a=r[l],n=o.addTile(a);t.Raw.Detour.statusFailed(n.status)&&s.log(t.Raw.Module.RC_LOG_WARNING,`Failed to add tile to tile cache - tx: ${i}, ty: ${e}`)}}for(let e=0;e<z;e++)for(let i=0;i<T;i++){const a=o.buildNavMeshTilesAt(i,e,d);if(t.Raw.Detour.statusFailed(a))return f(`Failed to build nav mesh tiles at ${i}, ${e}`)}return u(),{success:!0,tileCache:o,navMesh:d,intermediates:l}},f={...t.recastConfigDefaults},m=new e.Vector3,b=e=>{const t=[];for(const i of e){const e=i.geometry.attributes.position;if(!e||3!==e.itemSize)continue;let a=i;const r=i.geometry.getIndex()?.array;if(void 0===r){a=a.clone(),a.geometry=i.geometry.clone();const t=[];for(let i=0;i<e.count;i++)t.push(i);a.geometry.setIndex(t)}t.push(a)}const i=[],a=[],r={};let s=0;for(const e of t){e.updateMatrixWorld();const t=e.geometry.attributes.position.array,l=e.geometry.getIndex().array;for(let o=0;o<l.length;o++){const n=3*l[o],h=m.set(t[n],t[n+1],t[n+2]);e.localToWorld(h);const c=`${h.x}_${h.y}_${h.z}`;let d=r[c];d||(r[c]=d=s,i.push(h.x,h.y,h.z),s++),a.push(d)}}return[Float32Array.from(i),Uint32Array.from(a)]};exports.CrowdHelper=i,exports.HeightfieldHelper=r,exports.NavMeshHelper=s,exports.OffMeshConnectionsHelper=l,exports.TileCacheHelper=o,exports.getPositionsAndIndices=b,exports.threeToSoloNavMesh=(e,i={},a=!1)=>{const[r,s]=b(e);return((e,i,a={},r=!1)=>{const s=new t.RecastBuildContext,l={type:"solo",buildContext:s},o=new t.NavMesh,h=e=>(r||(l.heightfield&&(t.freeHeightfield(l.heightfield),l.heightfield=void 0),l.compactHeightfield&&(t.freeCompactHeightfield(l.compactHeightfield),l.compactHeightfield=void 0),l.contourSet&&(t.freeContourSet(l.contourSet),l.contourSet=void 0)),o.destroy(),{navMesh:void 0,success:!1,intermediates:l,error:e}),c=e,g=i.length,u=new t.Arrays.VertsArray;u.copy(c,c.length);const f=i,m=i.length/3,b=new t.Arrays.TrisArray;b.copy(f,f.length);const{bbMin:M,bbMax:y}=n(e,i),w=t.createRcConfig({...d,...a});w.minRegionArea=w.minRegionArea*w.minRegionArea,w.mergeRegionArea=w.mergeRegionArea*w.mergeRegionArea,w.detailSampleDist=w.detailSampleDist<.9?0:w.cs*w.detailSampleDist,w.detailSampleMaxError=w.ch*w.detailSampleMaxError;const p=t.calcGridSize(M,y,w.cs);w.width=p.width,w.height=p.height;const C=t.allocHeightfield();if(l.heightfield=C,!t.createHeightfield(s,C,w.width,w.height,M,y,w.cs,w.ch))return h("Could not create heightfield");const x=new t.Arrays.TriAreasArray;if(x.resize(m),t.markWalkableTriangles(s,w.walkableSlopeAngle,u,g,b,m,x),!t.rasterizeTriangles(s,u,g,b,x,m,C,w.walkableClimb))return h("Could not rasterize triangles");x.free(),t.filterLowHangingWalkableObstacles(s,w.walkableClimb,C),t.filterLedgeSpans(s,w.walkableHeight,w.walkableClimb,C),t.filterWalkableLowHeightSpans(s,w.walkableHeight,C);const S=t.allocCompactHeightfield();if(l.compactHeightfield=S,!t.buildCompactHeightfield(s,w.walkableHeight,w.walkableClimb,C,S))return h("Failed to build compact data");if(r||(t.freeHeightfield(C),l.heightfield=void 0),!t.erodeWalkableArea(s,w.walkableRadius,S))return h("Failed to erode walkable area");if(!t.buildDistanceField(s,S))return h("Failed to build distance field");if(!t.buildRegions(s,S,w.borderSize,w.minRegionArea,w.mergeRegionArea))return h("Failed to build regions");const R=t.allocContourSet();if(l.contourSet=R,!t.buildContours(s,S,w.maxSimplificationError,w.maxEdgeLen,R,t.Raw.Module.RC_CONTOUR_TESS_WALL_EDGES))return h("Failed to create contours");const A=t.allocPolyMesh();if(!t.buildPolyMesh(s,R,w.maxVertsPerPoly,A))return h("Failed to triangulate contours");const k=t.allocPolyMeshDetail();if(!t.buildPolyMeshDetail(s,A,S,w.detailSampleDist,w.detailSampleMaxError,k))return h("Failed to build detail mesh");r||(t.freeCompactHeightfield(S),l.compactHeightfield=void 0,t.freeContourSet(R),l.contourSet=void 0);for(let e=0;e<A.npolys();e++)A.areas(e)==t.Raw.Recast.WALKABLE_AREA&&A.setAreas(e,0),0==A.areas(e)&&A.setFlags(e,1);const v=new t.NavMeshCreateParams;v.setPolyMeshCreateParams(A),v.setPolyMeshDetailCreateParams(k),v.setWalkableHeight(w.walkableHeight),v.setWalkableRadius(w.walkableRadius),v.setWalkableClimb(w.walkableClimb),v.setCellSize(w.cs),v.setCellHeight(w.ch),v.setBuildBvTree(!0),a.offMeshConnections&&v.setOffMeshConnections(a.offMeshConnections);const H=t.createNavMeshData(v);if(!H.success)return h("Failed to create Detour navmesh data");const{navMeshData:T}=H;return o.initSolo(T)?{success:!0,navMesh:o,intermediates:l}:h("Failed to create Detour navmesh")})(r,s,i,a)},exports.threeToTileCache=(e,t={},i=!1)=>{const[a,r]=b(e);return u(a,r,t,i)},exports.threeToTiledNavMesh=(e,i={},a=!1)=>{const[r,s]=b(e);return((e,i,a={},r=!1)=>{const s=new t.RecastBuildContext,l={type:"tiled",buildContext:s,chunkyTriMesh:void 0,tileIntermediates:[]},o=new t.NavMesh,d=()=>{if(!r){for(let e=0;e<l.tileIntermediates.length;e++){const i=l.tileIntermediates[e];i.compactHeightfield&&t.freeCompactHeightfield(i.compactHeightfield),i.heightfield&&t.freeHeightfield(i.heightfield),i.contourSet&&t.freeContourSet(i.contourSet)}l.chunkyTriMesh&&(l.chunkyTriMesh=void 0)}},g=e=>(d(),o.destroy(),{success:!1,navMesh:void 0,intermediates:l,error:e}),u=t.createRcConfig({...f,...a}),{bbMin:m,bbMax:b}=n(e,i),M=t.calcGridSize(m,b,u.cs);u.width=M.width,u.height=M.height,u.minRegionArea=u.minRegionArea*u.minRegionArea,u.mergeRegionArea=u.mergeRegionArea*u.mergeRegionArea,u.tileSize=Math.floor(u.tileSize),u.borderSize=u.walkableRadius+3,u.width=u.tileSize+2*u.borderSize,u.height=u.tileSize+2*u.borderSize,u.detailSampleDist=u.detailSampleDist<.9?0:u.cs*u.detailSampleDist,u.detailSampleMaxError=u.ch*u.detailSampleMaxError;const y=Math.floor(u.tileSize),w=Math.floor((M.width+y-1)/y),p=Math.floor((M.height+y-1)/y),C=u.tileSize*u.cs,x=e,S=i.length,R=new t.Arrays.VertsArray;R.copy(x,x.length);const A=i,k=i.length/3,v=new t.Arrays.TrisArray;v.copy(A,A.length);const H=t.vec3.fromArray(m);let T=Math.min(Math.floor(h(c(w*p))),14);T>14&&(T=14);const z=1<<T,_=1<<22-T,D=t.NavMeshParams.create({orig:H,tileWidth:u.tileSize*u.cs,tileHeight:u.tileSize*u.cs,maxTiles:z,maxPolys:_});if(!o.initTiled(D))return g("Could not init nav mesh for tiled use");const L=new t.RecastChunkyTriMesh;if(l.chunkyTriMesh=L,!L.init(R,v,k,256))return g("Failed to build chunky triangle mesh");const P=(e,i,o,n)=>{const h=e=>(s.log(t.Raw.Module.RC_LOG_ERROR,e),{success:!1,error:e}),c={tileX:e,tileY:i};l.tileIntermediates.push(c);const d=t.cloneRcConfig(u),g=[...o],f=[...n];g[0]-=d.borderSize*d.cs,g[2]-=d.borderSize*d.cs,f[0]+=d.borderSize*d.cs,f[2]+=d.borderSize*d.cs,d.set_bmin(0,g[0]),d.set_bmin(1,g[1]),d.set_bmin(2,g[2]),d.set_bmax(0,f[0]),d.set_bmax(1,f[1]),d.set_bmax(2,f[2]),s.resetTimers(),s.startTimer(t.Raw.Module.RC_TIMER_TOTAL),s.log(t.Raw.Module.RC_LOG_PROGRESS,`Building tile ${l.tileIntermediates.length} at x: ${e}, y: ${i}`),s.log(t.Raw.Module.RC_LOG_PROGRESS,` - ${u.width} x ${u.height} cells`),s.log(t.Raw.Module.RC_LOG_PROGRESS,` - ${S/1e3}fK verts, ${k/1e3}K tris`);const m=t.allocHeightfield();if(c.heightfield=m,!t.createHeightfield(s,m,d.width,d.height,g,f,d.cs,d.ch))return h("Could not create heightfield");(new t.Arrays.TriAreasArray).resize(L.maxTrisPerChunk());const b=[g[0],g[2]],M=[f[0],f[2]],y=new t.Arrays.ChunkIdsArray;y.resize(512);const w=L.getChunksOverlappingRect(b,M,y,512);if(0===w)return{success:!0};for(let e=0;e<w;++e){const i=y.get_data(e),a=L.nodes(i).n,r=L.getNodeTris(i),l=new t.Arrays.TriAreasArray;l.resize(a),t.markWalkableTriangles(s,d.walkableSlopeAngle,R,S,r,a,l);const o=t.rasterizeTriangles(s,R,S,r,l,a,m,d.walkableClimb);if(l.free(),!o)return h("Could not rasterize triangles")}t.filterLowHangingWalkableObstacles(s,d.walkableClimb,m),t.filterLedgeSpans(s,d.walkableHeight,d.walkableClimb,m),t.filterWalkableLowHeightSpans(s,d.walkableHeight,m);const p=t.allocCompactHeightfield();if(c.compactHeightfield=p,!t.buildCompactHeightfield(s,d.walkableHeight,d.walkableClimb,m,p))return h("Could not build compact heightfield");if(r||(t.freeHeightfield(c.heightfield),c.heightfield=void 0),!t.erodeWalkableArea(s,d.walkableRadius,p))return h("Could not erode walkable area");if(!t.buildDistanceField(s,p))return h("Failed to build distance field");if(!t.buildRegions(s,p,d.borderSize,d.minRegionArea,d.mergeRegionArea))return h("Failed to build regions");const C=t.allocContourSet();if(c.contourSet=C,!t.buildContours(s,p,d.maxSimplificationError,d.maxEdgeLen,C,t.Raw.Module.RC_CONTOUR_TESS_WALL_EDGES))return h("Failed to create contours");const x=t.allocPolyMesh();if(!t.buildPolyMesh(s,C,d.maxVertsPerPoly,x))return h("Failed to triangulate contours");const A=t.allocPolyMeshDetail();if(!t.buildPolyMeshDetail(s,x,p,d.detailSampleDist,d.detailSampleMaxError,A))return h("Failed to build detail mesh");r||(t.freeCompactHeightfield(p),c.compactHeightfield=void 0,t.freeContourSet(C),c.contourSet=void 0);for(let e=0;e<x.npolys();e++)x.areas(e)==t.Raw.Recast.WALKABLE_AREA&&x.setAreas(e,0),0==x.areas(e)&&x.setFlags(e,1);const v=new t.NavMeshCreateParams;v.setPolyMeshCreateParams(x),v.setPolyMeshDetailCreateParams(A),v.setWalkableHeight(d.walkableHeight),v.setWalkableRadius(d.walkableRadius),v.setWalkableClimb(d.walkableClimb),v.setCellSize(d.cs),v.setCellHeight(d.ch),v.setBuildBvTree(!0),a.offMeshConnections&&v.setOffMeshConnections(a.offMeshConnections),v.setTileX(e),v.setTileY(i);const H=t.createNavMeshData(v);return H.success?(s.log(t.Raw.Module.RC_LOG_PROGRESS,`>> Polymesh: ${x.nverts()} vertices ${x.npolys()} polygons`),{success:!0,data:H.navMeshData}):h("Failed to create Detour navmesh data")};s.startTimer(t.Raw.Module.RC_TIMER_TEMP);const E=[0,0,0],F=[0,0,0];for(let e=0;e<p;e++)for(let i=0;i<w;i++){E[0]=m[0]+i*C,E[1]=m[1],E[2]=m[2]+e*C,F[0]=m[0]+(i+1)*C,F[1]=b[1],F[2]=m[2]+(e+1)*C;const a=P(i,e,E,F);if(a.success&&a.data){o.removeTile(o.getTileRefAt(i,e,0));const r=o.addTile(a.data,t.Raw.Module.DT_TILE_FREE_DATA,0);t.Raw.Detour.statusFailed(r.status)&&(s.log(t.Raw.Module.RC_LOG_WARNING,`Failed to add tile to nav mesh\n\ttx: ${i}, ty: ${e},status: ${t.statusToReadableString(r.status)} (${r.status})`),a.data.free())}}return s.stopTimer(t.Raw.Module.RC_TIMER_TEMP),r||d(),{success:!0,navMesh:o,intermediates:l}})(r,s,i,a)};
1
+ "use strict";var t=require("@recast-navigation/core"),e=require("three");function i(t){var e=Object.create(null);return t&&Object.keys(t).forEach((function(i){if("default"!==i){var n=Object.getOwnPropertyDescriptor(t,i);Object.defineProperty(e,i,n.get?n:{enumerable:!0,get:function(){return t[i]}})}})),e.default=t,Object.freeze(e)}var n=i(e);const r=new e.Box3,a=new e.Vector3;class s extends e.InstancedBufferGeometry{constructor(){super(),this.isLineSegmentsGeometry=!0,this.type="LineSegmentsGeometry";this.setIndex([0,2,1,2,3,1,2,4,3,4,5,3,4,6,5,6,7,5]),this.setAttribute("position",new e.Float32BufferAttribute([-1,2,0,1,2,0,-1,1,0,1,1,0,-1,0,0,1,0,0,-1,-1,0,1,-1,0],3)),this.setAttribute("uv",new e.Float32BufferAttribute([-1,2,1,2,-1,1,1,1,-1,-1,1,-1,-1,-2,1,-2],2))}applyMatrix4(t){const e=this.attributes.instanceStart,i=this.attributes.instanceEnd;return void 0!==e&&(e.applyMatrix4(t),i.applyMatrix4(t),e.needsUpdate=!0),null!==this.boundingBox&&this.computeBoundingBox(),null!==this.boundingSphere&&this.computeBoundingSphere(),this}setPositions(t){let i;t instanceof Float32Array?i=t:Array.isArray(t)&&(i=new Float32Array(t));const n=new e.InstancedInterleavedBuffer(i,6,1);return this.setAttribute("instanceStart",new e.InterleavedBufferAttribute(n,3,0)),this.setAttribute("instanceEnd",new e.InterleavedBufferAttribute(n,3,3)),this.computeBoundingBox(),this.computeBoundingSphere(),this}setColors(t,i=3){let n;t instanceof Float32Array?n=t:Array.isArray(t)&&(n=new Float32Array(t));const r=new e.InstancedInterleavedBuffer(n,2*i,1);return this.setAttribute("instanceColorStart",new e.InterleavedBufferAttribute(r,i,0)),this.setAttribute("instanceColorEnd",new e.InterleavedBufferAttribute(r,i,i)),this}fromWireframeGeometry(t){return this.setPositions(t.attributes.position.array),this}fromEdgesGeometry(t){return this.setPositions(t.attributes.position.array),this}fromMesh(t){return this.fromWireframeGeometry(new e.WireframeGeometry(t.geometry)),this}fromLineSegments(t){const e=t.geometry;return this.setPositions(e.attributes.position.array),this}computeBoundingBox(){null===this.boundingBox&&(this.boundingBox=new e.Box3);const t=this.attributes.instanceStart,i=this.attributes.instanceEnd;void 0!==t&&void 0!==i&&(this.boundingBox.setFromBufferAttribute(t),r.setFromBufferAttribute(i),this.boundingBox.union(r))}computeBoundingSphere(){null===this.boundingSphere&&(this.boundingSphere=new e.Sphere),null===this.boundingBox&&this.computeBoundingBox();const t=this.attributes.instanceStart,i=this.attributes.instanceEnd;if(void 0!==t&&void 0!==i){const e=this.boundingSphere.center;this.boundingBox.getCenter(e);let n=0;for(let r=0,s=t.count;r<s;r++)a.fromBufferAttribute(t,r),n=Math.max(n,e.distanceToSquared(a)),a.fromBufferAttribute(i,r),n=Math.max(n,e.distanceToSquared(a));this.boundingSphere.radius=Math.sqrt(n),isNaN(this.boundingSphere.radius)&&console.error("THREE.LineSegmentsGeometry.computeBoundingSphere(): Computed radius is NaN. The instanced position data is likely to have NaN values.",this)}}toJSON(){}applyMatrix(t){return console.warn("THREE.LineSegmentsGeometry: applyMatrix() has been renamed to applyMatrix4()."),this.applyMatrix4(t)}}class o extends e.ShaderMaterial{constructor(t){super({type:"LineMaterial",uniforms:e.UniformsUtils.clone(e.UniformsUtils.merge([e.UniformsLib.common,e.UniformsLib.fog,{worldUnits:{value:1},linewidth:{value:1},resolution:{value:new e.Vector2(1,1)},dashOffset:{value:0},dashScale:{value:1},dashSize:{value:1},gapSize:{value:1}}])),vertexShader:"\n\t\t\t\t#include <common>\n\t\t\t\t#include <fog_pars_vertex>\n\t\t\t\t#include <logdepthbuf_pars_vertex>\n\t\t\t\t#include <clipping_planes_pars_vertex>\n\n\t\t\t\tuniform float linewidth;\n\t\t\t\tuniform vec2 resolution;\n\n\t\t\t\tattribute vec3 instanceStart;\n\t\t\t\tattribute vec3 instanceEnd;\n\n\t\t\t\t#ifdef USE_COLOR\n\t\t\t\t\t#ifdef USE_LINE_COLOR_ALPHA\n\t\t\t\t\t\tvarying vec4 vLineColor;\n\t\t\t\t\t\tattribute vec4 instanceColorStart;\n\t\t\t\t\t\tattribute vec4 instanceColorEnd;\n\t\t\t\t\t#else\n\t\t\t\t\t\tvarying vec3 vLineColor;\n\t\t\t\t\t\tattribute vec3 instanceColorStart;\n\t\t\t\t\t\tattribute vec3 instanceColorEnd;\n\t\t\t\t\t#endif\n\t\t\t\t#endif\n\n\t\t\t\t#ifdef WORLD_UNITS\n\n\t\t\t\t\tvarying vec4 worldPos;\n\t\t\t\t\tvarying vec3 worldStart;\n\t\t\t\t\tvarying vec3 worldEnd;\n\n\t\t\t\t\t#ifdef USE_DASH\n\n\t\t\t\t\t\tvarying vec2 vUv;\n\n\t\t\t\t\t#endif\n\n\t\t\t\t#else\n\n\t\t\t\t\tvarying vec2 vUv;\n\n\t\t\t\t#endif\n\n\t\t\t\t#ifdef USE_DASH\n\n\t\t\t\t\tuniform float dashScale;\n\t\t\t\t\tattribute float instanceDistanceStart;\n\t\t\t\t\tattribute float instanceDistanceEnd;\n\t\t\t\t\tvarying float vLineDistance;\n\n\t\t\t\t#endif\n\n\t\t\t\tvoid trimSegment( const in vec4 start, inout vec4 end ) {\n\n\t\t\t\t\t// trim end segment so it terminates between the camera plane and the near plane\n\n\t\t\t\t\t// conservative estimate of the near plane\n\t\t\t\t\tfloat a = projectionMatrix[ 2 ][ 2 ]; // 3nd entry in 3th column\n\t\t\t\t\tfloat b = projectionMatrix[ 3 ][ 2 ]; // 3nd entry in 4th column\n\t\t\t\t\tfloat nearEstimate = - 0.5 * b / a;\n\n\t\t\t\t\tfloat alpha = ( nearEstimate - start.z ) / ( end.z - start.z );\n\n\t\t\t\t\tend.xyz = mix( start.xyz, end.xyz, alpha );\n\n\t\t\t\t}\n\n\t\t\t\tvoid main() {\n\n\t\t\t\t\t#ifdef USE_COLOR\n\n\t\t\t\t\t\tvLineColor = ( position.y < 0.5 ) ? instanceColorStart : instanceColorEnd;\n\n\t\t\t\t\t#endif\n\n\t\t\t\t\t#ifdef USE_DASH\n\n\t\t\t\t\t\tvLineDistance = ( position.y < 0.5 ) ? dashScale * instanceDistanceStart : dashScale * instanceDistanceEnd;\n\t\t\t\t\t\tvUv = uv;\n\n\t\t\t\t\t#endif\n\n\t\t\t\t\tfloat aspect = resolution.x / resolution.y;\n\n\t\t\t\t\t// camera space\n\t\t\t\t\tvec4 start = modelViewMatrix * vec4( instanceStart, 1.0 );\n\t\t\t\t\tvec4 end = modelViewMatrix * vec4( instanceEnd, 1.0 );\n\n\t\t\t\t\t#ifdef WORLD_UNITS\n\n\t\t\t\t\t\tworldStart = start.xyz;\n\t\t\t\t\t\tworldEnd = end.xyz;\n\n\t\t\t\t\t#else\n\n\t\t\t\t\t\tvUv = uv;\n\n\t\t\t\t\t#endif\n\n\t\t\t\t\t// special case for perspective projection, and segments that terminate either in, or behind, the camera plane\n\t\t\t\t\t// clearly the gpu firmware has a way of addressing this issue when projecting into ndc space\n\t\t\t\t\t// but we need to perform ndc-space calculations in the shader, so we must address this issue directly\n\t\t\t\t\t// perhaps there is a more elegant solution -- WestLangley\n\n\t\t\t\t\tbool perspective = ( projectionMatrix[ 2 ][ 3 ] == - 1.0 ); // 4th entry in the 3rd column\n\n\t\t\t\t\tif ( perspective ) {\n\n\t\t\t\t\t\tif ( start.z < 0.0 && end.z >= 0.0 ) {\n\n\t\t\t\t\t\t\ttrimSegment( start, end );\n\n\t\t\t\t\t\t} else if ( end.z < 0.0 && start.z >= 0.0 ) {\n\n\t\t\t\t\t\t\ttrimSegment( end, start );\n\n\t\t\t\t\t\t}\n\n\t\t\t\t\t}\n\n\t\t\t\t\t// clip space\n\t\t\t\t\tvec4 clipStart = projectionMatrix * start;\n\t\t\t\t\tvec4 clipEnd = projectionMatrix * end;\n\n\t\t\t\t\t// ndc space\n\t\t\t\t\tvec3 ndcStart = clipStart.xyz / clipStart.w;\n\t\t\t\t\tvec3 ndcEnd = clipEnd.xyz / clipEnd.w;\n\n\t\t\t\t\t// direction\n\t\t\t\t\tvec2 dir = ndcEnd.xy - ndcStart.xy;\n\n\t\t\t\t\t// account for clip-space aspect ratio\n\t\t\t\t\tdir.x *= aspect;\n\t\t\t\t\tdir = normalize( dir );\n\n\t\t\t\t\t#ifdef WORLD_UNITS\n\n\t\t\t\t\t\t// get the offset direction as perpendicular to the view vector\n\t\t\t\t\t\tvec3 worldDir = normalize( end.xyz - start.xyz );\n\t\t\t\t\t\tvec3 offset;\n\t\t\t\t\t\tif ( position.y < 0.5 ) {\n\n\t\t\t\t\t\t\toffset = normalize( cross( start.xyz, worldDir ) );\n\n\t\t\t\t\t\t} else {\n\n\t\t\t\t\t\t\toffset = normalize( cross( end.xyz, worldDir ) );\n\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\t// sign flip\n\t\t\t\t\t\tif ( position.x < 0.0 ) offset *= - 1.0;\n\n\t\t\t\t\t\tfloat forwardOffset = dot( worldDir, vec3( 0.0, 0.0, 1.0 ) );\n\n\t\t\t\t\t\t// don't extend the line if we're rendering dashes because we\n\t\t\t\t\t\t// won't be rendering the endcaps\n\t\t\t\t\t\t#ifndef USE_DASH\n\n\t\t\t\t\t\t\t// extend the line bounds to encompass endcaps\n\t\t\t\t\t\t\tstart.xyz += - worldDir * linewidth * 0.5;\n\t\t\t\t\t\t\tend.xyz += worldDir * linewidth * 0.5;\n\n\t\t\t\t\t\t\t// shift the position of the quad so it hugs the forward edge of the line\n\t\t\t\t\t\t\toffset.xy -= dir * forwardOffset;\n\t\t\t\t\t\t\toffset.z += 0.5;\n\n\t\t\t\t\t\t#endif\n\n\t\t\t\t\t\t// endcaps\n\t\t\t\t\t\tif ( position.y > 1.0 || position.y < 0.0 ) {\n\n\t\t\t\t\t\t\toffset.xy += dir * 2.0 * forwardOffset;\n\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\t// adjust for linewidth\n\t\t\t\t\t\toffset *= linewidth * 0.5;\n\n\t\t\t\t\t\t// set the world position\n\t\t\t\t\t\tworldPos = ( position.y < 0.5 ) ? start : end;\n\t\t\t\t\t\tworldPos.xyz += offset;\n\n\t\t\t\t\t\t// project the worldpos\n\t\t\t\t\t\tvec4 clip = projectionMatrix * worldPos;\n\n\t\t\t\t\t\t// shift the depth of the projected points so the line\n\t\t\t\t\t\t// segments overlap neatly\n\t\t\t\t\t\tvec3 clipPose = ( position.y < 0.5 ) ? ndcStart : ndcEnd;\n\t\t\t\t\t\tclip.z = clipPose.z * clip.w;\n\n\t\t\t\t\t#else\n\n\t\t\t\t\t\tvec2 offset = vec2( dir.y, - dir.x );\n\t\t\t\t\t\t// undo aspect ratio adjustment\n\t\t\t\t\t\tdir.x /= aspect;\n\t\t\t\t\t\toffset.x /= aspect;\n\n\t\t\t\t\t\t// sign flip\n\t\t\t\t\t\tif ( position.x < 0.0 ) offset *= - 1.0;\n\n\t\t\t\t\t\t// endcaps\n\t\t\t\t\t\tif ( position.y < 0.0 ) {\n\n\t\t\t\t\t\t\toffset += - dir;\n\n\t\t\t\t\t\t} else if ( position.y > 1.0 ) {\n\n\t\t\t\t\t\t\toffset += dir;\n\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\t// adjust for linewidth\n\t\t\t\t\t\toffset *= linewidth;\n\n\t\t\t\t\t\t// adjust for clip-space to screen-space conversion // maybe resolution should be based on viewport ...\n\t\t\t\t\t\toffset /= resolution.y;\n\n\t\t\t\t\t\t// select end\n\t\t\t\t\t\tvec4 clip = ( position.y < 0.5 ) ? clipStart : clipEnd;\n\n\t\t\t\t\t\t// back to clip space\n\t\t\t\t\t\toffset *= clip.w;\n\n\t\t\t\t\t\tclip.xy += offset;\n\n\t\t\t\t\t#endif\n\n\t\t\t\t\tgl_Position = clip;\n\n\t\t\t\t\tvec4 mvPosition = ( position.y < 0.5 ) ? start : end; // this is an approximation\n\n\t\t\t\t\t#include <logdepthbuf_vertex>\n\t\t\t\t\t#include <clipping_planes_vertex>\n\t\t\t\t\t#include <fog_vertex>\n\n\t\t\t\t}\n\t\t\t",fragmentShader:`\n\t\t\t\tuniform vec3 diffuse;\n\t\t\t\tuniform float opacity;\n\t\t\t\tuniform float linewidth;\n\n\t\t\t\t#ifdef USE_DASH\n\n\t\t\t\t\tuniform float dashOffset;\n\t\t\t\t\tuniform float dashSize;\n\t\t\t\t\tuniform float gapSize;\n\n\t\t\t\t#endif\n\n\t\t\t\tvarying float vLineDistance;\n\n\t\t\t\t#ifdef WORLD_UNITS\n\n\t\t\t\t\tvarying vec4 worldPos;\n\t\t\t\t\tvarying vec3 worldStart;\n\t\t\t\t\tvarying vec3 worldEnd;\n\n\t\t\t\t\t#ifdef USE_DASH\n\n\t\t\t\t\t\tvarying vec2 vUv;\n\n\t\t\t\t\t#endif\n\n\t\t\t\t#else\n\n\t\t\t\t\tvarying vec2 vUv;\n\n\t\t\t\t#endif\n\n\t\t\t\t#include <common>\n\t\t\t\t#include <fog_pars_fragment>\n\t\t\t\t#include <logdepthbuf_pars_fragment>\n\t\t\t\t#include <clipping_planes_pars_fragment>\n\n\t\t\t\t#ifdef USE_COLOR\n\t\t\t\t\t#ifdef USE_LINE_COLOR_ALPHA\n\t\t\t\t\t\tvarying vec4 vLineColor;\n\t\t\t\t\t#else\n\t\t\t\t\t\tvarying vec3 vLineColor;\n\t\t\t\t\t#endif\n\t\t\t\t#endif\n\n\t\t\t\tvec2 closestLineToLine(vec3 p1, vec3 p2, vec3 p3, vec3 p4) {\n\n\t\t\t\t\tfloat mua;\n\t\t\t\t\tfloat mub;\n\n\t\t\t\t\tvec3 p13 = p1 - p3;\n\t\t\t\t\tvec3 p43 = p4 - p3;\n\n\t\t\t\t\tvec3 p21 = p2 - p1;\n\n\t\t\t\t\tfloat d1343 = dot( p13, p43 );\n\t\t\t\t\tfloat d4321 = dot( p43, p21 );\n\t\t\t\t\tfloat d1321 = dot( p13, p21 );\n\t\t\t\t\tfloat d4343 = dot( p43, p43 );\n\t\t\t\t\tfloat d2121 = dot( p21, p21 );\n\n\t\t\t\t\tfloat denom = d2121 * d4343 - d4321 * d4321;\n\n\t\t\t\t\tfloat numer = d1343 * d4321 - d1321 * d4343;\n\n\t\t\t\t\tmua = numer / denom;\n\t\t\t\t\tmua = clamp( mua, 0.0, 1.0 );\n\t\t\t\t\tmub = ( d1343 + d4321 * ( mua ) ) / d4343;\n\t\t\t\t\tmub = clamp( mub, 0.0, 1.0 );\n\n\t\t\t\t\treturn vec2( mua, mub );\n\n\t\t\t\t}\n\n\t\t\t\tvoid main() {\n\n\t\t\t\t\t#include <clipping_planes_fragment>\n\n\t\t\t\t\t#ifdef USE_DASH\n\n\t\t\t\t\t\tif ( vUv.y < - 1.0 || vUv.y > 1.0 ) discard; // discard endcaps\n\n\t\t\t\t\t\tif ( mod( vLineDistance + dashOffset, dashSize + gapSize ) > dashSize ) discard; // todo - FIX\n\n\t\t\t\t\t#endif\n\n\t\t\t\t\tfloat alpha = opacity;\n\n\t\t\t\t\t#ifdef WORLD_UNITS\n\n\t\t\t\t\t\t// Find the closest points on the view ray and the line segment\n\t\t\t\t\t\tvec3 rayEnd = normalize( worldPos.xyz ) * 1e5;\n\t\t\t\t\t\tvec3 lineDir = worldEnd - worldStart;\n\t\t\t\t\t\tvec2 params = closestLineToLine( worldStart, worldEnd, vec3( 0.0, 0.0, 0.0 ), rayEnd );\n\n\t\t\t\t\t\tvec3 p1 = worldStart + lineDir * params.x;\n\t\t\t\t\t\tvec3 p2 = rayEnd * params.y;\n\t\t\t\t\t\tvec3 delta = p1 - p2;\n\t\t\t\t\t\tfloat len = length( delta );\n\t\t\t\t\t\tfloat norm = len / linewidth;\n\n\t\t\t\t\t\t#ifndef USE_DASH\n\n\t\t\t\t\t\t\t#ifdef USE_ALPHA_TO_COVERAGE\n\n\t\t\t\t\t\t\t\tfloat dnorm = fwidth( norm );\n\t\t\t\t\t\t\t\talpha = 1.0 - smoothstep( 0.5 - dnorm, 0.5 + dnorm, norm );\n\n\t\t\t\t\t\t\t#else\n\n\t\t\t\t\t\t\t\tif ( norm > 0.5 ) {\n\n\t\t\t\t\t\t\t\t\tdiscard;\n\n\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t#endif\n\n\t\t\t\t\t\t#endif\n\n\t\t\t\t\t#else\n\n\t\t\t\t\t\t#ifdef USE_ALPHA_TO_COVERAGE\n\n\t\t\t\t\t\t\t// artifacts appear on some hardware if a derivative is taken within a conditional\n\t\t\t\t\t\t\tfloat a = vUv.x;\n\t\t\t\t\t\t\tfloat b = ( vUv.y > 0.0 ) ? vUv.y - 1.0 : vUv.y + 1.0;\n\t\t\t\t\t\t\tfloat len2 = a * a + b * b;\n\t\t\t\t\t\t\tfloat dlen = fwidth( len2 );\n\n\t\t\t\t\t\t\tif ( abs( vUv.y ) > 1.0 ) {\n\n\t\t\t\t\t\t\t\talpha = 1.0 - smoothstep( 1.0 - dlen, 1.0 + dlen, len2 );\n\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t#else\n\n\t\t\t\t\t\t\tif ( abs( vUv.y ) > 1.0 ) {\n\n\t\t\t\t\t\t\t\tfloat a = vUv.x;\n\t\t\t\t\t\t\t\tfloat b = ( vUv.y > 0.0 ) ? vUv.y - 1.0 : vUv.y + 1.0;\n\t\t\t\t\t\t\t\tfloat len2 = a * a + b * b;\n\n\t\t\t\t\t\t\t\tif ( len2 > 1.0 ) discard;\n\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t#endif\n\n\t\t\t\t\t#endif\n\n\t\t\t\t\tvec4 diffuseColor = vec4( diffuse, alpha );\n\t\t\t\t\t#ifdef USE_COLOR\n\t\t\t\t\t\t#ifdef USE_LINE_COLOR_ALPHA\n\t\t\t\t\t\t\tdiffuseColor *= vLineColor;\n\t\t\t\t\t\t#else\n\t\t\t\t\t\t\tdiffuseColor.rgb *= vLineColor;\n\t\t\t\t\t\t#endif\n\t\t\t\t\t#endif\n\n\t\t\t\t\t#include <logdepthbuf_fragment>\n\n\t\t\t\t\tgl_FragColor = diffuseColor;\n\n\t\t\t\t\t#include <tonemapping_fragment>\n\t\t\t\t\t#include <${parseInt(e.REVISION.replace(/\D+/g,""))>=154?"colorspace_fragment":"encodings_fragment"}>\n\t\t\t\t\t#include <fog_fragment>\n\t\t\t\t\t#include <premultiplied_alpha_fragment>\n\n\t\t\t\t}\n\t\t\t`,clipping:!0}),this.isLineMaterial=!0,this.onBeforeCompile=function(){this.transparent?this.defines.USE_LINE_COLOR_ALPHA="1":delete this.defines.USE_LINE_COLOR_ALPHA},Object.defineProperties(this,{color:{enumerable:!0,get:function(){return this.uniforms.diffuse.value},set:function(t){this.uniforms.diffuse.value=t}},worldUnits:{enumerable:!0,get:function(){return"WORLD_UNITS"in this.defines},set:function(t){!0===t?this.defines.WORLD_UNITS="":delete this.defines.WORLD_UNITS}},linewidth:{enumerable:!0,get:function(){return this.uniforms.linewidth.value},set:function(t){this.uniforms.linewidth.value=t}},dashed:{enumerable:!0,get:function(){return Boolean("USE_DASH"in this.defines)},set(t){Boolean(t)!==Boolean("USE_DASH"in this.defines)&&(this.needsUpdate=!0),!0===t?this.defines.USE_DASH="":delete this.defines.USE_DASH}},dashScale:{enumerable:!0,get:function(){return this.uniforms.dashScale.value},set:function(t){this.uniforms.dashScale.value=t}},dashSize:{enumerable:!0,get:function(){return this.uniforms.dashSize.value},set:function(t){this.uniforms.dashSize.value=t}},dashOffset:{enumerable:!0,get:function(){return this.uniforms.dashOffset.value},set:function(t){this.uniforms.dashOffset.value=t}},gapSize:{enumerable:!0,get:function(){return this.uniforms.gapSize.value},set:function(t){this.uniforms.gapSize.value=t}},opacity:{enumerable:!0,get:function(){return this.uniforms.opacity.value},set:function(t){this.uniforms.opacity.value=t}},resolution:{enumerable:!0,get:function(){return this.uniforms.resolution.value},set:function(t){this.uniforms.resolution.value.copy(t)}},alphaToCoverage:{enumerable:!0,get:function(){return Boolean("USE_ALPHA_TO_COVERAGE"in this.defines)},set:function(t){Boolean(t)!==Boolean("USE_ALPHA_TO_COVERAGE"in this.defines)&&(this.needsUpdate=!0),!0===t?(this.defines.USE_ALPHA_TO_COVERAGE="",this.extensions.derivatives=!0):(delete this.defines.USE_ALPHA_TO_COVERAGE,this.extensions.derivatives=!1)}}}),this.setValues(t)}}const l=new e.Vector3,d=new e.Vector3,c=new e.Vector4,h=new e.Vector4,u=new e.Vector4,f=new e.Vector3,g=new e.Matrix4,p=new e.Line3,m=new e.Vector3,w=new e.Box3,b=new e.Sphere,y=new e.Vector4;let v,M,S,x;function D(t,e,i){return y.set(0,0,-e,1).applyMatrix4(t.projectionMatrix),y.multiplyScalar(1/y.w),y.x=x/i.width,y.y=x/i.height,y.applyMatrix4(t.projectionMatrixInverse),y.multiplyScalar(1/y.w),Math.abs(Math.max(y.x,y.y))}class C extends e.Mesh{constructor(t=new s,e=new o({color:16777215*Math.random()})){super(t,e),this.isLineSegments2=!0,this.type="LineSegments2"}computeLineDistances(){const t=this.geometry,i=t.attributes.instanceStart,n=t.attributes.instanceEnd,r=new Float32Array(2*i.count);for(let t=0,e=0,a=i.count;t<a;t++,e+=2)l.fromBufferAttribute(i,t),d.fromBufferAttribute(n,t),r[e]=0===e?0:r[e-1],r[e+1]=r[e]+l.distanceTo(d);const a=new e.InstancedInterleavedBuffer(r,2,1);return t.setAttribute("instanceDistanceStart",new e.InterleavedBufferAttribute(a,1,0)),t.setAttribute("instanceDistanceEnd",new e.InterleavedBufferAttribute(a,1,1)),this}raycast(t,i){const n=this.material.worldUnits,r=t.camera;null!==r||n||console.error('LineSegments2: "Raycaster.camera" needs to be set in order to raycast against LineSegments2 while worldUnits is set to false.');const a=void 0!==t.params.Line2&&t.params.Line2.threshold||0;v=t.ray;const s=this.matrixWorld,o=this.geometry,l=this.material;let d,y;if(x=l.linewidth+a,M=o.attributes.instanceStart,S=o.attributes.instanceEnd,null===o.boundingSphere&&o.computeBoundingSphere(),b.copy(o.boundingSphere).applyMatrix4(s),n)d=.5*x;else{d=D(r,Math.max(r.near,b.distanceToPoint(v.origin)),l.resolution)}if(b.radius+=d,!1!==v.intersectsSphere(b)){if(null===o.boundingBox&&o.computeBoundingBox(),w.copy(o.boundingBox).applyMatrix4(s),n)y=.5*x;else{y=D(r,Math.max(r.near,w.distanceToPoint(v.origin)),l.resolution)}w.expandByScalar(y),!1!==v.intersectsBox(w)&&(n?function(t,i){for(let n=0,r=M.count;n<r;n++){p.start.fromBufferAttribute(M,n),p.end.fromBufferAttribute(S,n);const r=new e.Vector3,a=new e.Vector3;v.distanceSqToSegment(p.start,p.end,a,r),a.distanceTo(r)<.5*x&&i.push({point:a,pointOnLine:r,distance:v.origin.distanceTo(a),object:t,face:null,faceIndex:n,uv:null,uv2:null})}}(this,i):function(t,i,n){const r=i.projectionMatrix,a=t.material.resolution,s=t.matrixWorld,o=t.geometry,l=o.attributes.instanceStart,d=o.attributes.instanceEnd,w=-i.near;v.at(1,u),u.w=1,u.applyMatrix4(i.matrixWorldInverse),u.applyMatrix4(r),u.multiplyScalar(1/u.w),u.x*=a.x/2,u.y*=a.y/2,u.z=0,f.copy(u),g.multiplyMatrices(i.matrixWorldInverse,s);for(let i=0,o=l.count;i<o;i++){if(c.fromBufferAttribute(l,i),h.fromBufferAttribute(d,i),c.w=1,h.w=1,c.applyMatrix4(g),h.applyMatrix4(g),c.z>w&&h.z>w)continue;if(c.z>w){const t=c.z-h.z,e=(c.z-w)/t;c.lerp(h,e)}else if(h.z>w){const t=h.z-c.z,e=(h.z-w)/t;h.lerp(c,e)}c.applyMatrix4(r),h.applyMatrix4(r),c.multiplyScalar(1/c.w),h.multiplyScalar(1/h.w),c.x*=a.x/2,c.y*=a.y/2,h.x*=a.x/2,h.y*=a.y/2,p.start.copy(c),p.start.z=0,p.end.copy(h),p.end.z=0;const o=p.closestPointToPointParameter(f,!0);p.at(o,m);const u=e.MathUtils.lerp(c.z,h.z,o),b=u>=-1&&u<=1,y=f.distanceTo(m)<.5*x;if(b&&y){p.start.fromBufferAttribute(l,i),p.end.fromBufferAttribute(d,i),p.start.applyMatrix4(s),p.end.applyMatrix4(s);const r=new e.Vector3,a=new e.Vector3;v.distanceSqToSegment(p.start,p.end,a,r),n.push({point:a,pointOnLine:r,distance:v.origin.distanceTo(a),object:t,face:null,faceIndex:i,uv:null,uv2:null})}}}(this,r,i))}}}const A=new n.Color;class R extends n.Group{triMaterial;pointMaterial;pointGeometry=new n.SphereGeometry(.02,32,32);lineMaterial;debugDrawImpl;currentVertices=[];currentPrimitive=0;constructor({triMaterial:e,pointMaterial:i,lineMaterial:r}={}){super(),this.triMaterial=e??new n.MeshBasicMaterial({vertexColors:!0,transparent:!0,opacity:.4,depthWrite:!1}),this.pointMaterial=i??new n.MeshBasicMaterial,this.lineMaterial=r??new o({color:16777215,linewidth:1,vertexColors:!0,transparent:!0,opacity:.4,depthWrite:!1}),this.debugDrawImpl=new t.Raw.Module.DebugDrawImpl,this.debugDrawImpl.handleBegin=(t,e)=>{this.currentPrimitive=t,this.currentVertices=[]},this.debugDrawImpl.handleDepthMask=t=>{},this.debugDrawImpl.handleTexture=t=>{},this.debugDrawImpl.handleVertexWithColor=(t,e,i,n)=>{this.vertex(t,e,i,n)},this.debugDrawImpl.handleVertexWithColorAndUV=(t,e,i,n,r,a)=>{this.vertex(t,e,i,n)},this.debugDrawImpl.handleEnd=()=>{this.currentPrimitive===t.Raw.Module.DU_DRAW_LINES?this.endLines():this.currentPrimitive===t.Raw.Module.DU_DRAW_TRIS?this.endTris():this.currentPrimitive===t.Raw.Module.DU_DRAW_QUADS?this.endQuads():this.currentPrimitive===t.Raw.Module.DU_DRAW_POINTS&&this.endPoints()}}debugDrawHeightfieldSolid(e){t.Raw.RecastDebugDraw.debugDrawHeightfieldSolid(this.debugDrawImpl,e.raw)}debugDrawHeightfieldWalkable(e){t.Raw.RecastDebugDraw.debugDrawHeightfieldWalkable(this.debugDrawImpl,e.raw)}debugDrawCompactHeightfieldSolid(e){t.Raw.RecastDebugDraw.debugDrawCompactHeightfieldSolid(this.debugDrawImpl,e.raw)}debugDrawCompactHeightfieldRegions(e){t.Raw.RecastDebugDraw.debugDrawCompactHeightfieldRegions(this.debugDrawImpl,e.raw)}debugDrawCompactHeightfieldDistance(e){t.Raw.RecastDebugDraw.debugDrawCompactHeightfieldDistance(this.debugDrawImpl,e.raw)}debugDrawHeightfieldLayer(e,i){t.Raw.RecastDebugDraw.debugDrawHeightfieldLayer(this.debugDrawImpl,e.raw,i)}debugDrawHeightfieldLayers(e){t.Raw.RecastDebugDraw.debugDrawHeightfieldLayers(this.debugDrawImpl,e.raw)}debugDrawRegionConnections(e,i){t.Raw.RecastDebugDraw.debugDrawRegionConnections(this.debugDrawImpl,e.raw,i)}debugDrawRawContours(e,i){t.Raw.RecastDebugDraw.debugDrawRawContours(this.debugDrawImpl,e.raw,i)}debugDrawContours(e,i){t.Raw.RecastDebugDraw.debugDrawContours(this.debugDrawImpl,e.raw,i)}debugDrawPolyMesh(e){t.Raw.RecastDebugDraw.debugDrawPolyMesh(this.debugDrawImpl,e.raw)}debugDrawPolyMeshDetail(e){t.Raw.RecastDebugDraw.debugDrawPolyMeshDetail(this.debugDrawImpl,e.raw)}debugDrawNavMesh(e,i){t.Raw.DetourDebugDraw.debugDrawNavMesh(this.debugDrawImpl,e.raw.getNavMesh(),i)}debugDrawNavMeshWithClosedList(e,i,n){t.Raw.DetourDebugDraw.debugDrawNavMeshWithClosedList(this.debugDrawImpl,e.raw.m_navMesh,i.raw.m_navQuery,n)}debugDrawNavMeshNodes(e){t.Raw.DetourDebugDraw.debugDrawNavMeshNodes(this.debugDrawImpl,e.raw.m_navQuery)}debugDrawNavMeshBVTree(e){t.Raw.DetourDebugDraw.debugDrawNavMeshBVTree(this.debugDrawImpl,e.raw.m_navMesh)}debugDrawNavMeshPortals(e){t.Raw.DetourDebugDraw.debugDrawNavMeshPortals(this.debugDrawImpl,e.raw.m_navMesh)}debugDrawNavMeshPolysWithFlags(e,i,n){t.Raw.DetourDebugDraw.debugDrawNavMeshPolysWithFlags(this.debugDrawImpl,e.raw.m_navMesh,i,n)}debugDrawNavMeshPoly(e,i,n){t.Raw.DetourDebugDraw.debugDrawNavMeshPoly(this.debugDrawImpl,e.raw.m_navMesh,i,n)}resize(t,e){this.lineMaterial.resolution.set(t,e)}reset(){for(const t of this.children)(t instanceof n.Mesh||t instanceof C)&&t.geometry.dispose();this.clear()}dispose(){this.reset(),t.Raw.Module.destroy(this.debugDrawImpl)}vertex(t,e,i,n){const r=(n>>16&255)/255,a=(n>>8&255)/255,s=(255&n)/255,o=(n>>24&255)/255;this.currentVertices.push({x:t,y:e,z:i,r:r,g:a,b:s,a:o})}endPoints(){const t=this.pointGeometry,e=new n.InstancedMesh(t,this.pointMaterial,this.currentVertices.length);for(let t=0;t<this.currentVertices.length;t++){const i=this.currentVertices[t];e.setMatrixAt(t,(new n.Matrix4).setPosition(i.x,i.y,i.z)),e.setColorAt(t,A.setRGB(i.r,i.g,i.b))}e.instanceMatrix.needsUpdate=!0,this.add(e)}endLines(){const t=new s,e=[],i=[];for(let t=0;t<this.currentVertices.length;t+=2){const n=this.currentVertices[t],r=this.currentVertices[t+1];e.push(n.x,n.y,n.z),e.push(r.x,r.y,r.z),i.push(n.r,n.g,n.b),i.push(r.r,r.g,r.b)}t.setPositions(e),t.setColors(i);const n=new C(t,this.lineMaterial);this.add(n)}endTris(){const t=new n.BufferGeometry,e=new Float32Array(3*this.currentVertices.length),i=new Float32Array(3*this.currentVertices.length);for(let t=0;t<this.currentVertices.length;t++){const n=this.currentVertices[t];e[3*t+0]=n.x,e[3*t+1]=n.y,e[3*t+2]=n.z,i[3*t+0]=n.r,i[3*t+1]=n.g,i[3*t+2]=n.b}t.setAttribute("position",new n.BufferAttribute(e,3)),t.setAttribute("color",new n.BufferAttribute(i,3));const r=this.triMaterial,a=new n.Mesh(t,r);this.add(a)}endQuads(){const t=[],e=[];for(let i=0;i<this.currentVertices.length;i+=4){const n=[this.currentVertices[i],this.currentVertices[i+1],this.currentVertices[i+2],this.currentVertices[i],this.currentVertices[i+2],this.currentVertices[i+3]];for(const i of n)t.push(i.x,i.y,i.z),e.push(i.r,i.g,i.b)}const i=new n.BufferGeometry;i.setAttribute("position",new n.BufferAttribute(new Float32Array(t),3)),i.setAttribute("color",new n.BufferAttribute(new Float32Array(e),3));const r=this.triMaterial,a=new n.Mesh(i,r);this.add(a)}}class _ extends e.Object3D{agentMeshes=new Map;recastCrowd;agentMaterial;constructor({crowd:t,agentMaterial:i}){super(),this.recastCrowd=t,this.agentMaterial=i??new e.MeshBasicMaterial({color:"red"}),this.update()}update(){const t=this.recastCrowd.getAgents(),i=new Set(this.agentMeshes.keys());for(const n of t){i.delete(n.agentIndex);const t=n.position(),r=n.velocity();let a=this.agentMeshes.get(n.agentIndex);void 0===a?(a=this.createAgentMesh(n),this.add(a),this.agentMeshes.set(n.agentIndex,a)):this.updateAgentGeometry(a,n),a.position.set(t.x,t.y+n.height/2,t.z),a.lookAt((new e.Vector3).copy(a.position).add(r))}for(const t of i){const e=this.agentMeshes.get(t);e&&(this.remove(e),this.agentMeshes.delete(t))}}createAgentMesh(t){const i=new e.Mesh;return i.material=this.agentMaterial,this.updateAgentGeometry(i,t),i.userData={radius:t.radius,height:t.height},i}updateAgentGeometry(t,i){if(t.userData.radius!==i.radius||t.userData.height!==i.height){const n=new e.CylinderGeometry(i.radius,i.radius,i.height);t.geometry.dispose(),t.geometry=n,t.userData.radius=i.radius,t.userData.height=i.height}}}class z extends e.Object3D{navMesh;navMeshMaterial;mesh;geometry;constructor({navMesh:t,navMeshMaterial:i}){super(),this.navMesh=t,this.geometry=new e.BufferGeometry,this.navMeshMaterial=i||new e.MeshBasicMaterial({color:"orange",transparent:!0,opacity:.7,depthWrite:!1}),this.update(),this.mesh=new e.Mesh(this.geometry,this.navMeshMaterial),this.add(this.mesh)}update(){const[t,i]=this.navMesh.getDebugNavMesh();this.geometry.setAttribute("position",new e.BufferAttribute(Float32Array.from(t),3)),this.geometry.setIndex(new e.BufferAttribute(Uint32Array.from(i),1)),this.geometry.computeVertexNormals()}}class E extends e.Object3D{offMeshConnections;entryCircleMaterial;exitCircleMaterial;lineMaterial;constructor({offMeshConnections:t,entryCircleMaterial:i,exitCircleMaterial:n,lineMaterial:r}){super(),this.offMeshConnections=t??[],this.entryCircleMaterial=i??new e.MeshBasicMaterial({color:"green"}),this.exitCircleMaterial=n??new e.MeshBasicMaterial({color:"blue"}),this.lineMaterial=r??new e.LineBasicMaterial({color:"red"}),this.update()}update(){this.clear();for(const t of this.offMeshConnections){const i=new e.CircleGeometry(t.radius,16),n=new e.Mesh(i,this.entryCircleMaterial);n.position.copy(t.startPosition),n.position.y+=.001,n.rotation.x=-Math.PI/2,this.add(n);const r=new e.Mesh(i,t.bidirectional?this.entryCircleMaterial:this.exitCircleMaterial);r.position.copy(t.endPosition),r.position.y+=.001,r.rotation.x=-Math.PI/2,this.add(r);const a=(new e.Vector3).copy(t.startPosition),s=(new e.Vector3).copy(t.endPosition),o=(new e.Vector3).addVectors(a,s).multiplyScalar(.5);o.y*=1.2;const l=new e.CatmullRomCurve3([a,o,s]).getPoints(50),d=(new e.BufferGeometry).setFromPoints(l),c=new e.Line(d,this.lineMaterial);this.add(c)}}}class L extends e.Object3D{tileCache;obstacleMeshes=new Map;obstacleMaterial;constructor({tileCache:t,obstacleMaterial:i}){super(),this.tileCache=t,this.obstacleMaterial=i||new e.MeshBasicMaterial({color:"red",wireframe:!0,wireframeLinewidth:2}),this.update()}update(){const t=new Set(this.obstacleMeshes.keys());for(const[,i]of this.tileCache.obstacles){const n=this.obstacleMeshes.get(i);if(t.delete(i),!n){const{position:t}=i,n=new e.Mesh(void 0,this.obstacleMaterial);if(n.position.copy(t),"box"===i.type){const{extent:t,angle:r}=i;n.geometry=new e.BoxGeometry(2*t.x,2*t.y,2*t.z),n.rotation.y=r}else{if("cylinder"!==i.type)throw new Error(`Unknown obstacle type: ${i}`);{const{radius:t,height:r}=i;n.geometry=new e.CylinderGeometry(t,t,r,16),n.position.y+=r/2}}this.add(n),this.obstacleMeshes.set(i,n)}}for(const e of t){const t=this.obstacleMeshes.get(e);t&&(this.remove(t),this.obstacleMeshes.delete(e))}}}const H=(e,i)=>{const n={x:1/0,y:1/0,z:1/0},r={x:-1/0,y:-1/0,z:-1/0};for(let t=0;t<i.length;t++){const a=i[t],s=e[3*a],o=e[3*a+1],l=e[3*a+2];n.x=Math.min(n.x,s),n.y=Math.min(n.y,o),n.z=Math.min(n.z,l),r.x=Math.max(r.x,s),r.y=Math.max(r.y,o),r.z=Math.max(r.z,l)}return{bbMin:t.vec3.toArray(n),bbMax:t.vec3.toArray(r)}},T=t=>{let e=0,i=0;return e=Number(t>65535)<<4,t>>=e,i=Number(t>255)<<3,t>>=i,e|=i,i=Number(t>15)<<2,t>>=i,e|=i,i=Number(t>3)<<1,e|=i,e|=(t>>=i)>>1,e},P=t=>(t--,t|=t>>1,t|=t>>2,t|=t>>4,t|=t>>8,t|=t>>16,++t),I={...t.recastConfigDefaults},B={...t.recastConfigDefaults,tileSize:32,expectedLayersPerTile:4,maxObstacles:128},O=(e,i,n={},r=!1)=>{const a=new t.RecastBuildContext,s={type:"tilecache",buildContext:a,chunkyTriMesh:void 0,tileIntermediates:[]},o=new t.TileCache,l=new t.NavMesh,d=()=>{if(!r)for(let e=0;e<s.tileIntermediates.length;e++){const i=s.tileIntermediates[e];i.heightfield&&(t.freeHeightfield(i.heightfield),i.heightfield=void 0),i.compactHeightfield&&(t.freeCompactHeightfield(i.compactHeightfield),i.compactHeightfield=void 0),i.heightfieldLayerSet&&(t.freeHeightfieldLayerSet(i.heightfieldLayerSet),i.heightfieldLayerSet=void 0)}},c=t=>(d(),o.destroy(),l.destroy(),{success:!1,navMesh:void 0,tileCache:void 0,intermediates:s,error:t}),h=e,u=i.length,f=new t.Arrays.VertsArray;f.copy(h,h.length);const g=i,p=i.length/3,m=new t.Arrays.TrisArray;m.copy(g,g.length);const{bbMin:w,bbMax:b}=H(e,i),{expectedLayersPerTile:y,maxObstacles:v,...M}={...B,...n},S=t.createRcConfig(M),x=t.calcGridSize(w,b,S.cs);S.width=x.width,S.height=x.height,S.minRegionArea=S.minRegionArea*S.minRegionArea,S.mergeRegionArea=S.mergeRegionArea*S.mergeRegionArea,S.detailSampleDist=S.detailSampleDist<.9?0:S.cs*S.detailSampleDist,S.detailSampleMaxError=S.ch*S.detailSampleMaxError;const D=Math.floor(S.tileSize),C=Math.floor((S.width+D-1)/D),A=Math.floor((S.height+D-1)/D);S.borderSize=S.walkableRadius+3,S.width=S.tileSize+2*S.borderSize,S.height=S.tileSize+2*S.borderSize;const R=t.DetourTileCacheParams.create({orig:w,cs:S.cs,ch:S.ch,width:S.tileSize,height:S.tileSize,walkableHeight:S.walkableHeight,walkableRadius:S.walkableRadius,walkableClimb:S.walkableClimb,maxSimplificationError:S.maxSimplificationError,maxTiles:C*A*y,maxObstacles:v}),_=new t.Raw.RecastLinearAllocator(32e3),z=new t.Raw.RecastFastLZCompressor,E=n.tileCacheMeshProcess??new t.TileCacheMeshProcess(((t,e,i)=>{for(let n=0;n<t.polyCount();++n)e.set(n,0),i.set(n,1)}));if(!o.init(R,_,z,E))return c("Failed to initialize tile cache");const L=t.vec3.fromArray(w);let I=Math.min(Math.floor(T(P(C*A*y))),14);I>14&&(I=14);const O=1<<I,k=1<<22-I,U=t.NavMeshParams.create({orig:L,tileWidth:S.tileSize*S.cs,tileHeight:S.tileSize*S.cs,maxTiles:O,maxPolys:k});if(!l.initTiled(U))return c("Failed to initialize tiled navmesh");const N=new t.RecastChunkyTriMesh;if(s.chunkyTriMesh=N,!N.init(f,m,p,256))return c("Failed to build chunky triangle mesh");const V=(e,i)=>{const n={tileX:e,tileY:i},o=S.tileSize*S.cs,l=t.cloneRcConfig(S),d=[w[0]+e*o,w[1],w[2]+i*o],c=[w[0]+(e+1)*o,b[1],w[2]+(i+1)*o];d[0]-=l.borderSize*l.cs,d[2]-=l.borderSize*l.cs,c[0]+=l.borderSize*l.cs,c[2]+=l.borderSize*l.cs,l.set_bmin(0,d[0]),l.set_bmin(1,d[1]),l.set_bmin(2,d[2]),l.set_bmax(0,c[0]),l.set_bmax(1,c[1]),l.set_bmax(2,c[2]);const h=t.allocHeightfield();if(n.heightfield=h,!t.createHeightfield(a,h,l.width,l.height,d,c,l.cs,l.ch))return{n:0};const g=[d[0],d[2]],p=[c[0],c[2]],m=new t.Arrays.ChunkIdsArray;m.resize(512);const y=N.getChunksOverlappingRect(g,p,m,512);if(0===y)return{n:0};for(let e=0;e<y;++e){const i=m.get_data(e),n=N.nodes(i).n,r=N.getNodeTris(i),s=new t.Arrays.TriAreasArray;s.resize(n),t.markWalkableTriangles(a,l.walkableSlopeAngle,f,u,r,n,s);const o=t.rasterizeTriangles(a,f,u,r,s,n,h,l.walkableClimb);if(s.free(),!o)return{n:0}}t.filterLowHangingWalkableObstacles(a,S.walkableClimb,h),t.filterLedgeSpans(a,S.walkableHeight,S.walkableClimb,h),t.filterWalkableLowHeightSpans(a,S.walkableHeight,h);const v=t.allocCompactHeightfield();if(!t.buildCompactHeightfield(a,S.walkableHeight,S.walkableClimb,h,v))return{n:0};if(r||(t.freeHeightfield(n.heightfield),n.heightfield=void 0),!t.erodeWalkableArea(a,S.walkableRadius,v))return{n:0};const M=t.allocHeightfieldLayerSet();if(!t.buildHeightfieldLayers(a,v,S.borderSize,S.walkableHeight,M))return{n:0};r||(t.freeCompactHeightfield(v),n.compactHeightfield=void 0);const x=[];for(let n=0;n<M.nlayers();n++){const r=new t.Arrays.TileCacheData,a=M.layers(n),s=new t.Raw.dtTileCacheLayerHeader;s.magic=t.Raw.Detour.TILECACHE_MAGIC,s.version=t.Raw.Detour.TILECACHE_VERSION,s.tx=e,s.ty=i,s.tlayer=n;const o=a.bmin(),l=a.bmax();s.set_bmin(0,o.x),s.set_bmin(1,o.y),s.set_bmin(2,o.z),s.set_bmax(0,l.x),s.set_bmax(1,l.y),s.set_bmax(2,l.z),s.width=a.width(),s.height=a.height(),s.minx=a.minx(),s.maxx=a.maxx(),s.miny=a.miny(),s.maxy=a.maxy(),s.hmin=a.hmin(),s.hmax=a.hmax();const d=t.getHeightfieldLayerHeights(a),c=t.getHeightfieldLayerAreas(a),h=t.getHeightfieldLayerCons(a),u=t.buildTileCacheLayer(z,s,d,c,h,r);if(t.Raw.Detour.statusFailed(u))return{n:0};x.push(r)}return r||(t.freeHeightfieldLayerSet(M),n.heightfieldLayerSet=void 0),s.tileIntermediates.push(n),{n:x.length,tiles:x}};for(let e=0;e<A;++e)for(let i=0;i<C;++i){const{n:n,tiles:r}=V(i,e);if(n>0&&r)for(let s=0;s<n;s++){const n=r[s],l=o.addTile(n);t.Raw.Detour.statusFailed(l.status)&&a.log(t.Raw.Module.RC_LOG_WARNING,`Failed to add tile to tile cache - tx: ${i}, ty: ${e}`)}}for(let e=0;e<A;e++)for(let i=0;i<C;i++){const n=o.buildNavMeshTilesAt(i,e,l);if(t.Raw.Detour.statusFailed(n))return c(`Failed to build nav mesh tiles at ${i}, ${e}`)}return d(),{success:!0,tileCache:o,navMesh:l,intermediates:s}},k={...t.recastConfigDefaults},U=new e.Vector3,N=t=>{const e=[];for(const i of t){const t=i.geometry.attributes.position;if(!t||3!==t.itemSize)continue;let n=i;const r=i.geometry.getIndex()?.array;if(void 0===r){n=n.clone(),n.geometry=i.geometry.clone();const e=[];for(let i=0;i<t.count;i++)e.push(i);n.geometry.setIndex(e)}e.push(n)}const i=[],n=[],r={};let a=0;for(const t of e){t.updateMatrixWorld();const e=t.geometry.attributes.position.array,s=t.geometry.getIndex().array;for(let o=0;o<s.length;o++){const l=3*s[o],d=U.set(e[l],e[l+1],e[l+2]);t.localToWorld(d);const c=`${d.x}_${d.y}_${d.z}`;let h=r[c];h||(r[c]=h=a,i.push(d.x,d.y,d.z),a++),n.push(h)}}return[Float32Array.from(i),Uint32Array.from(n)]};exports.CrowdHelper=_,exports.DebugDrawer=R,exports.NavMeshHelper=z,exports.OffMeshConnectionsHelper=E,exports.TileCacheHelper=L,exports.getPositionsAndIndices=N,exports.threeToSoloNavMesh=(e,i={},n=!1)=>{const[r,a]=N(e);return((e,i,n={},r=!1)=>{const a=new t.RecastBuildContext,s={type:"solo",buildContext:a},o=new t.NavMesh,l=e=>(r||(s.heightfield&&(t.freeHeightfield(s.heightfield),s.heightfield=void 0),s.compactHeightfield&&(t.freeCompactHeightfield(s.compactHeightfield),s.compactHeightfield=void 0),s.contourSet&&(t.freeContourSet(s.contourSet),s.contourSet=void 0),s.polyMesh&&(t.freePolyMesh(s.polyMesh),s.polyMesh=void 0),s.polyMeshDetail&&(t.freePolyMeshDetail(s.polyMeshDetail),s.polyMeshDetail=void 0)),o.destroy(),{navMesh:void 0,success:!1,intermediates:s,error:e}),d=e,c=i.length,h=new t.Arrays.VertsArray;h.copy(d,d.length);const u=i,f=i.length/3,g=new t.Arrays.TrisArray;g.copy(u,u.length);const{bbMin:p,bbMax:m}=H(e,i),w=t.createRcConfig({...I,...n});w.minRegionArea=w.minRegionArea*w.minRegionArea,w.mergeRegionArea=w.mergeRegionArea*w.mergeRegionArea,w.detailSampleDist=w.detailSampleDist<.9?0:w.cs*w.detailSampleDist,w.detailSampleMaxError=w.ch*w.detailSampleMaxError;const b=t.calcGridSize(p,m,w.cs);w.width=b.width,w.height=b.height;const y=t.allocHeightfield();if(s.heightfield=y,!t.createHeightfield(a,y,w.width,w.height,p,m,w.cs,w.ch))return l("Could not create heightfield");const v=new t.Arrays.TriAreasArray;if(v.resize(f),t.markWalkableTriangles(a,w.walkableSlopeAngle,h,c,g,f,v),!t.rasterizeTriangles(a,h,c,g,v,f,y,w.walkableClimb))return l("Could not rasterize triangles");v.free(),t.filterLowHangingWalkableObstacles(a,w.walkableClimb,y),t.filterLedgeSpans(a,w.walkableHeight,w.walkableClimb,y),t.filterWalkableLowHeightSpans(a,w.walkableHeight,y);const M=t.allocCompactHeightfield();if(s.compactHeightfield=M,!t.buildCompactHeightfield(a,w.walkableHeight,w.walkableClimb,y,M))return l("Failed to build compact data");if(r||(t.freeHeightfield(y),s.heightfield=void 0),!t.erodeWalkableArea(a,w.walkableRadius,M))return l("Failed to erode walkable area");if(!t.buildDistanceField(a,M))return l("Failed to build distance field");if(!t.buildRegions(a,M,w.borderSize,w.minRegionArea,w.mergeRegionArea))return l("Failed to build regions");const S=t.allocContourSet();if(s.contourSet=S,!t.buildContours(a,M,w.maxSimplificationError,w.maxEdgeLen,S,t.Raw.Module.RC_CONTOUR_TESS_WALL_EDGES))return l("Failed to create contours");const x=t.allocPolyMesh();if(s.polyMesh=x,!t.buildPolyMesh(a,S,w.maxVertsPerPoly,x))return l("Failed to triangulate contours");const D=t.allocPolyMeshDetail();if(s.polyMeshDetail=D,!t.buildPolyMeshDetail(a,x,M,w.detailSampleDist,w.detailSampleMaxError,D))return l("Failed to build detail mesh");r||(t.freeCompactHeightfield(M),s.compactHeightfield=void 0,t.freeContourSet(S),s.contourSet=void 0);for(let e=0;e<x.npolys();e++)x.areas(e)==t.Raw.Recast.WALKABLE_AREA&&x.setAreas(e,0),0==x.areas(e)&&x.setFlags(e,1);const C=new t.NavMeshCreateParams;C.setPolyMeshCreateParams(x),C.setPolyMeshDetailCreateParams(D),C.setWalkableHeight(w.walkableHeight),C.setWalkableRadius(w.walkableRadius),C.setWalkableClimb(w.walkableClimb),C.setCellSize(w.cs),C.setCellHeight(w.ch),C.setBuildBvTree(!0),n.offMeshConnections&&C.setOffMeshConnections(n.offMeshConnections);const A=t.createNavMeshData(C);if(!A.success)return l("Failed to create Detour navmesh data");const{navMeshData:R}=A;return o.initSolo(R)?{success:!0,navMesh:o,intermediates:s}:l("Failed to create Detour navmesh")})(r,a,i,n)},exports.threeToTileCache=(t,e={},i=!1)=>{const[n,r]=N(t);return O(n,r,e,i)},exports.threeToTiledNavMesh=(e,i={},n=!1)=>{const[r,a]=N(e);return((e,i,n={},r=!1)=>{const a=new t.RecastBuildContext,s={type:"tiled",buildContext:a,chunkyTriMesh:void 0,tileIntermediates:[]},o=new t.NavMesh,l=()=>{if(!r){for(let e=0;e<s.tileIntermediates.length;e++){const i=s.tileIntermediates[e];i.compactHeightfield&&t.freeCompactHeightfield(i.compactHeightfield),i.heightfield&&t.freeHeightfield(i.heightfield),i.contourSet&&t.freeContourSet(i.contourSet),i.polyMesh&&t.freePolyMesh(i.polyMesh),i.polyMeshDetail&&t.freePolyMeshDetail(i.polyMeshDetail)}s.chunkyTriMesh&&(s.chunkyTriMesh=void 0)}},d=t=>(l(),o.destroy(),{success:!1,navMesh:void 0,intermediates:s,error:t}),c=t.createRcConfig({...k,...n}),{bbMin:h,bbMax:u}=H(e,i),f=t.calcGridSize(h,u,c.cs);c.width=f.width,c.height=f.height,c.minRegionArea=c.minRegionArea*c.minRegionArea,c.mergeRegionArea=c.mergeRegionArea*c.mergeRegionArea,c.tileSize=Math.floor(c.tileSize),c.borderSize=c.walkableRadius+3,c.width=c.tileSize+2*c.borderSize,c.height=c.tileSize+2*c.borderSize,c.detailSampleDist=c.detailSampleDist<.9?0:c.cs*c.detailSampleDist,c.detailSampleMaxError=c.ch*c.detailSampleMaxError;const g=Math.floor(c.tileSize),p=Math.floor((f.width+g-1)/g),m=Math.floor((f.height+g-1)/g),w=c.tileSize*c.cs,b=e,y=i.length,v=new t.Arrays.VertsArray;v.copy(b,b.length);const M=i,S=i.length/3,x=new t.Arrays.TrisArray;x.copy(M,M.length);const D=t.vec3.fromArray(h);let C=Math.min(Math.floor(T(P(p*m))),14);C>14&&(C=14);const A=1<<C,R=1<<22-C,_=t.NavMeshParams.create({orig:D,tileWidth:c.tileSize*c.cs,tileHeight:c.tileSize*c.cs,maxTiles:A,maxPolys:R});if(!o.initTiled(_))return d("Could not init nav mesh for tiled use");const z=new t.RecastChunkyTriMesh;if(s.chunkyTriMesh=z,!z.init(v,x,S,256))return d("Failed to build chunky triangle mesh");const E=(e,i,o,l)=>{const d=e=>(a.log(t.Raw.Module.RC_LOG_ERROR,e),{success:!1,error:e}),h={tileX:e,tileY:i};s.tileIntermediates.push(h);const u=t.cloneRcConfig(c),f=[...o],g=[...l];f[0]-=u.borderSize*u.cs,f[2]-=u.borderSize*u.cs,g[0]+=u.borderSize*u.cs,g[2]+=u.borderSize*u.cs,u.set_bmin(0,f[0]),u.set_bmin(1,f[1]),u.set_bmin(2,f[2]),u.set_bmax(0,g[0]),u.set_bmax(1,g[1]),u.set_bmax(2,g[2]),a.resetTimers(),a.startTimer(t.Raw.Module.RC_TIMER_TOTAL),a.log(t.Raw.Module.RC_LOG_PROGRESS,`Building tile ${s.tileIntermediates.length} at x: ${e}, y: ${i}`),a.log(t.Raw.Module.RC_LOG_PROGRESS,` - ${c.width} x ${c.height} cells`),a.log(t.Raw.Module.RC_LOG_PROGRESS,` - ${y/1e3}fK verts, ${S/1e3}K tris`);const p=t.allocHeightfield();if(h.heightfield=p,!t.createHeightfield(a,p,u.width,u.height,f,g,u.cs,u.ch))return d("Could not create heightfield");(new t.Arrays.TriAreasArray).resize(z.maxTrisPerChunk());const m=[f[0],f[2]],w=[g[0],g[2]],b=new t.Arrays.ChunkIdsArray;b.resize(512);const M=z.getChunksOverlappingRect(m,w,b,512);if(0===M)return{success:!0};for(let e=0;e<M;++e){const i=b.get_data(e),n=z.nodes(i).n,r=z.getNodeTris(i),s=new t.Arrays.TriAreasArray;s.resize(n),t.markWalkableTriangles(a,u.walkableSlopeAngle,v,y,r,n,s);const o=t.rasterizeTriangles(a,v,y,r,s,n,p,u.walkableClimb);if(s.free(),!o)return d("Could not rasterize triangles")}t.filterLowHangingWalkableObstacles(a,u.walkableClimb,p),t.filterLedgeSpans(a,u.walkableHeight,u.walkableClimb,p),t.filterWalkableLowHeightSpans(a,u.walkableHeight,p);const x=t.allocCompactHeightfield();if(h.compactHeightfield=x,!t.buildCompactHeightfield(a,u.walkableHeight,u.walkableClimb,p,x))return d("Could not build compact heightfield");if(r||(t.freeHeightfield(h.heightfield),h.heightfield=void 0),!t.erodeWalkableArea(a,u.walkableRadius,x))return d("Could not erode walkable area");if(!t.buildDistanceField(a,x))return d("Failed to build distance field");if(!t.buildRegions(a,x,u.borderSize,u.minRegionArea,u.mergeRegionArea))return d("Failed to build regions");const D=t.allocContourSet();if(h.contourSet=D,!t.buildContours(a,x,u.maxSimplificationError,u.maxEdgeLen,D,t.Raw.Module.RC_CONTOUR_TESS_WALL_EDGES))return d("Failed to create contours");const C=t.allocPolyMesh();if(h.polyMesh=C,!t.buildPolyMesh(a,D,u.maxVertsPerPoly,C))return d("Failed to triangulate contours");const A=t.allocPolyMeshDetail();if(h.polyMeshDetail=A,!t.buildPolyMeshDetail(a,C,x,u.detailSampleDist,u.detailSampleMaxError,A))return d("Failed to build detail mesh");r||(t.freeCompactHeightfield(x),h.compactHeightfield=void 0,t.freeContourSet(D),h.contourSet=void 0);for(let e=0;e<C.npolys();e++)C.areas(e)==t.Raw.Recast.WALKABLE_AREA&&C.setAreas(e,0),0==C.areas(e)&&C.setFlags(e,1);const R=new t.NavMeshCreateParams;R.setPolyMeshCreateParams(C),R.setPolyMeshDetailCreateParams(A),R.setWalkableHeight(u.walkableHeight),R.setWalkableRadius(u.walkableRadius),R.setWalkableClimb(u.walkableClimb),R.setCellSize(u.cs),R.setCellHeight(u.ch),R.setBuildBvTree(!0),n.offMeshConnections&&R.setOffMeshConnections(n.offMeshConnections),R.setTileX(e),R.setTileY(i);const _=t.createNavMeshData(R);return _.success?(a.log(t.Raw.Module.RC_LOG_PROGRESS,`>> Polymesh: ${C.nverts()} vertices ${C.npolys()} polygons`),{success:!0,data:_.navMeshData}):d("Failed to create Detour navmesh data")};a.startTimer(t.Raw.Module.RC_TIMER_TEMP);const L=[0,0,0],I=[0,0,0];for(let e=0;e<m;e++)for(let i=0;i<p;i++){L[0]=h[0]+i*w,L[1]=h[1],L[2]=h[2]+e*w,I[0]=h[0]+(i+1)*w,I[1]=u[1],I[2]=h[2]+(e+1)*w;const n=E(i,e,L,I);if(n.success&&n.data){o.removeTile(o.getTileRefAt(i,e,0));const r=o.addTile(n.data,t.Raw.Module.DT_TILE_FREE_DATA,0);t.Raw.Detour.statusFailed(r.status)&&(a.log(t.Raw.Module.RC_LOG_WARNING,`Failed to add tile to nav mesh\n\ttx: ${i}, ty: ${e},status: ${t.statusToReadableString(r.status)} (${r.status})`),n.data.free())}}return a.stopTimer(t.Raw.Module.RC_TIMER_TEMP),r||l(),{success:!0,navMesh:o,intermediates:s}})(r,a,i,n)};
2
2
  //# sourceMappingURL=index.cjs.map