@recast-navigation/three 0.9.3 → 0.10.1
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.
- package/README.md +35 -3
- package/dist/helpers/index.d.ts +1 -0
- package/dist/helpers/off-mesh-connections-helper.d.ts +19 -0
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -80,6 +80,18 @@ scene.add(navMeshHelper);
|
|
|
80
80
|
navMeshHelper.update();
|
|
81
81
|
```
|
|
82
82
|
|
|
83
|
+
#### `OffMeshConnectionsHelper`
|
|
84
|
+
|
|
85
|
+
```ts
|
|
86
|
+
import { OffMeshConnectionsHelper } from 'recast-navigation/three';
|
|
87
|
+
|
|
88
|
+
const offMeshConnectionsHelper = new OffMeshConnectionsHelper({
|
|
89
|
+
offMeshConnections,
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
scene.add(offMeshConnectionsHelper);
|
|
93
|
+
```
|
|
94
|
+
|
|
83
95
|
#### `TileCacheHelper`
|
|
84
96
|
|
|
85
97
|
Visualises obstacles in a `TileCache`.
|
|
@@ -115,21 +127,41 @@ crowdHelper.update();
|
|
|
115
127
|
You can optionally provide custom materials to the helpers.
|
|
116
128
|
|
|
117
129
|
```ts
|
|
130
|
+
// NavMeshHelper
|
|
118
131
|
const navMeshMaterial = new THREE.MeshBasicMaterial({ color: 'red' });
|
|
119
|
-
const obstacleMaterial = new THREE.MeshBasicMaterial({ color: 'blue' });
|
|
120
|
-
const agentMaterial = new THREE.MeshBasicMaterial({ color: 'red' });
|
|
121
|
-
|
|
122
132
|
const navMeshHelper = new NavMeshHelper({
|
|
123
133
|
navMesh,
|
|
124
134
|
navMeshMaterial,
|
|
125
135
|
});
|
|
126
136
|
|
|
137
|
+
// OffMeshConnectionsHelper
|
|
138
|
+
const offMeshConnectionEntryCircleMaterial = new THREE.MeshBasicMaterial({
|
|
139
|
+
color: 'green',
|
|
140
|
+
});
|
|
141
|
+
const offMeshConnectionExitCircleMaterial = new THREE.MeshBasicMaterial({
|
|
142
|
+
color: 'yellow',
|
|
143
|
+
});
|
|
144
|
+
const offMeshConnectionLineMaterial = new THREE.LineBasicMaterial({
|
|
145
|
+
color: 'white',
|
|
146
|
+
});
|
|
147
|
+
const offMeshConnectionsHelper = new OffMeshConnectionsHelper({
|
|
148
|
+
offMeshConnections,
|
|
149
|
+
entryCircleMaterial: offMeshConnectionEntryCircleMaterial,
|
|
150
|
+
exitCircleMaterial: offMeshConnectionExitCircleMaterial,
|
|
151
|
+
lineMaterial: offMeshConnectionLineMaterial,
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
// TileCacheHelper
|
|
155
|
+
const obstacleMaterial = new THREE.MeshBasicMaterial({ color: 'blue' });
|
|
127
156
|
const tileCacheHelper = new TileCacheHelper({
|
|
128
157
|
tileCache,
|
|
129
158
|
obstacleMaterial,
|
|
130
159
|
});
|
|
131
160
|
|
|
161
|
+
// CrowdHelper
|
|
162
|
+
const agentMaterial = new THREE.MeshBasicMaterial({ color: 'red' });
|
|
132
163
|
const crowdHelper = new CrowdHelper({
|
|
133
164
|
crowd,
|
|
134
165
|
agentMaterial,
|
|
166
|
+
});
|
|
135
167
|
```
|
package/dist/helpers/index.d.ts
CHANGED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { OffMeshConnection } from '@recast-navigation/core';
|
|
2
|
+
import { LineBasicMaterial, Material, Object3D } from 'three';
|
|
3
|
+
export type OffMeshConnectionsHelperParams = {
|
|
4
|
+
offMeshConnections?: OffMeshConnection[];
|
|
5
|
+
entryCircleMaterial?: Material;
|
|
6
|
+
exitCircleMaterial?: Material;
|
|
7
|
+
lineMaterial?: LineBasicMaterial;
|
|
8
|
+
};
|
|
9
|
+
export declare class OffMeshConnectionsHelper extends Object3D {
|
|
10
|
+
offMeshConnections: OffMeshConnection[];
|
|
11
|
+
entryCircleMaterial: Material;
|
|
12
|
+
exitCircleMaterial: Material;
|
|
13
|
+
lineMaterial: LineBasicMaterial;
|
|
14
|
+
constructor({ offMeshConnections, entryCircleMaterial, exitCircleMaterial, lineMaterial, }: OffMeshConnectionsHelperParams);
|
|
15
|
+
/**
|
|
16
|
+
* Update the three debug view of the off mesh connections.
|
|
17
|
+
*/
|
|
18
|
+
update(): void;
|
|
19
|
+
}
|
package/dist/index.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var e=require("three"),t=require("@recast-navigation/core");class s extends e.Object3D{agentMeshes=new Map;recastCrowd;agentMaterial;constructor({crowd:t,agentMaterial:s}){super(),this.recastCrowd=t,this.agentMaterial=s??new e.MeshBasicMaterial({color:"red"}),this.update()}update(){const t=this.recastCrowd.getAgents(),s=new Set(this.agentMeshes.keys());for(const o of t){s.delete(o.agentIndex);const t=o.position(),
|
|
1
|
+
"use strict";var e=require("three"),t=require("@recast-navigation/core");class s extends e.Object3D{agentMeshes=new Map;recastCrowd;agentMaterial;constructor({crowd:t,agentMaterial:s}){super(),this.recastCrowd=t,this.agentMaterial=s??new e.MeshBasicMaterial({color:"red"}),this.update()}update(){const t=this.recastCrowd.getAgents(),s=new Set(this.agentMeshes.keys());for(const o of t){s.delete(o.agentIndex);const t=o.position(),i=o.velocity(),r=o.parameters();let a=this.agentMeshes.get(o.agentIndex);void 0===a&&(a=this.createAgentMesh(r),this.add(a),this.agentMeshes.set(o.agentIndex,a)),a.position.set(t.x,t.y+r.height/2,t.z),a.lookAt((new e.Vector3).copy(a.position).add(i))}for(const e of s){const t=this.agentMeshes.get(e);t&&(this.remove(t),this.agentMeshes.delete(e))}}createAgentMesh(t){const s=new e.CylinderGeometry(t.radius,t.radius,t.height);return new e.Mesh(s,this.agentMaterial)}}const o=new e.Matrix4;class i extends e.Object3D{heightfields;highlightWalkable;defaultColor;walkableColor;material;constructor({heightfields:t,highlightWalkable:s=!1,material:o=new e.MeshBasicMaterial,defaultColor:i="blue",walkableColor:r="green"}){super(),this.heightfields=t,this.highlightWalkable=s,this.material=o,this.defaultColor=new e.Color(i),this.walkableColor=new e.Color(r),this.update()}update(){this.clear();for(const t of this.heightfields){const s=t.bmin(),i=t.cs(),r=t.ch(),a=t.width(),n=t.height(),l=[];for(let e=0;e<n;++e)for(let o=0;o<a;++o){const n=s.x+o*i,h=s.z+e*i;let c=t.spans(o+e*a);for(;c;){const e=n,t=s.y+c.smin()*r,o=h,a=n+i,d=s.y+c.smax()*r,M=h+i;l.push({position:[(a+e)/2,(d+t)/2,(M+o)/2],walkable:this.highlightWalkable&&0!==c.area()}),c=c.next()}}const h=new e.BoxGeometry(i,r,i),c=new e.InstancedMesh(h,this.material,l.length);c.instanceMatrix.setUsage(e.DynamicDrawUsage);for(let e=0;e<l.length;e++){const{position:t,walkable:s}=l[e];c.setMatrixAt(e,o.setPosition(...t)),c.setColorAt(e,s?this.walkableColor:this.defaultColor)}c.instanceMatrix.needsUpdate=!0,c.instanceColor&&(c.instanceColor.needsUpdate=!0),this.add(c)}}}class r extends e.Object3D{navMesh;navMeshMaterial;mesh;geometry;constructor({navMesh:t,navMeshMaterial:s}){super(),this.navMesh=t,this.geometry=new e.BufferGeometry,this.navMeshMaterial=s||new e.MeshBasicMaterial({color:"orange",transparent:!0,opacity:.7}),this.update(),this.mesh=new e.Mesh(this.geometry,this.navMeshMaterial),this.add(this.mesh)}update(){const[t,s]=this.navMesh.getDebugNavMesh();this.geometry.setAttribute("position",new e.BufferAttribute(Float32Array.from(t),3)),this.geometry.setIndex(new e.BufferAttribute(Uint32Array.from(s),1)),this.geometry.computeVertexNormals()}}class a extends e.Object3D{offMeshConnections;entryCircleMaterial;exitCircleMaterial;lineMaterial;constructor({offMeshConnections:t,entryCircleMaterial:s,exitCircleMaterial:o,lineMaterial:i}){super(),this.offMeshConnections=t??[],this.entryCircleMaterial=s??new e.MeshBasicMaterial({color:"green"}),this.exitCircleMaterial=o??new e.MeshBasicMaterial({color:"blue"}),this.lineMaterial=i??new e.LineBasicMaterial({color:"red"}),this.update()}update(){this.clear();for(const t of this.offMeshConnections){const s=new e.CircleGeometry(t.radius,16),o=new e.Mesh(s,this.entryCircleMaterial);o.position.copy(t.startPosition),o.position.y+=.001,o.rotation.x=-Math.PI/2,this.add(o);const i=new e.Mesh(s,t.bidirectional?this.entryCircleMaterial:this.exitCircleMaterial);i.position.copy(t.endPosition),i.position.y+=.001,i.rotation.x=-Math.PI/2,this.add(i);const r=(new e.Vector3).copy(t.startPosition),a=(new e.Vector3).copy(t.endPosition),n=(new e.Vector3).addVectors(r,a).multiplyScalar(.5);n.y*=1.2;const l=new e.CatmullRomCurve3([r,n,a]).getPoints(50),h=(new e.BufferGeometry).setFromPoints(l),c=new e.Line(h,this.lineMaterial);this.add(c)}}}class n extends e.Object3D{tileCache;obstacleMeshes=new Map;obstacleMaterial;constructor({tileCache:t,obstacleMaterial:s}){super(),this.tileCache=t,this.obstacleMaterial=s||new e.MeshBasicMaterial({color:"red",wireframe:!0,wireframeLinewidth:2}),this.update()}update(){const t=new Set(this.obstacleMeshes.keys());for(const[,s]of this.tileCache.obstacles){let o=this.obstacleMeshes.get(s);if(t.delete(s),!o){const{position:t}=s,o=new e.Mesh(void 0,this.obstacleMaterial);if(o.position.copy(t),"box"===s.type){const{extent:t,angle:i}=s;o.geometry=new e.BoxGeometry(2*t.x,2*t.y,2*t.z),o.rotation.y=i}else{if("cylinder"!==s.type)throw new Error(`Unknown obstacle type: ${s}`);{const{radius:t,height:i}=s;o.geometry=new e.CylinderGeometry(t,t,i,16),o.position.y+=i/2}}this.add(o),this.obstacleMeshes.set(s,o)}}for(const e of t){const t=this.obstacleMeshes.get(e);t&&(this.remove(t),this.obstacleMeshes.delete(e))}}}const l=new e.Vector3,h=e=>{const t=[];for(const s of e){const e=s.geometry.attributes.position;if(!e||3!==e.itemSize)continue;let o=s,i=s.geometry.getIndex()?.array;if(!i){o=o.clone(),o.geometry=s.geometry.clone();const t=[];for(let s=0;s<e.count;s++)t.push(s);o.geometry.setIndex(t)}t.push(o)}const s=[],o=[],i={};let r=0;for(const e of t){e.updateMatrixWorld();const t=e.geometry.attributes.position.array,a=e.geometry.getIndex().array;for(let n=0;n<a.length;n++){const h=3*a[n],c=l.set(t[h],t[h+1],t[h+2]);e.localToWorld(c);const d=`${c.x}_${c.y}_${c.z}`;let M=i[d];M||(i[d]=M=r,s.push(c.x,c.y,c.z),r++),o.push(M)}}return[Float32Array.from(s),Uint32Array.from(o)]};exports.CrowdHelper=s,exports.HeightfieldHelper=i,exports.NavMeshHelper=r,exports.OffMeshConnectionsHelper=a,exports.TileCacheHelper=n,exports.getPositionsAndIndices=h,exports.threeToSoloNavMesh=(e,s={},o=!1)=>{const[i,r]=h(e);return t.generateSoloNavMesh(i,r,s,o)},exports.threeToTileCache=(e,s={},o=!1)=>{const[i,r]=h(e);return t.generateTileCache(i,r,s,o)},exports.threeToTiledNavMesh=(e,s={},o=!1)=>{const[i,r]=h(e);return t.generateTiledNavMesh(i,r,s,o)};
|
|
2
2
|
//# sourceMappingURL=index.cjs.map
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sources":["../src/helpers/crowd-helper.ts","../src/helpers/heightfield-helper.ts","../src/helpers/nav-mesh-helper.ts","../src/helpers/tile-cache-helper.ts","../src/utils/get-positions-and-indices.ts","../src/utils/generators.ts"],"sourcesContent":["import { CylinderGeometry, Mesh, MeshBasicMaterial, Object3D, Vector3, } from 'three';\nexport class CrowdHelper extends Object3D {\n agentMeshes = new Map();\n recastCrowd;\n agentMaterial;\n constructor({ crowd, agentMaterial }) {\n super();\n this.recastCrowd = crowd;\n this.agentMaterial =\n agentMaterial ?? new MeshBasicMaterial({ color: 'red' });\n this.update();\n }\n /**\n * Update the three debug view of the crowd agents.\n *\n * This should be called after updating the crowd.\n */\n update() {\n const agents = this.recastCrowd.getAgents();\n const unseen = new Set(this.agentMeshes.keys());\n for (const agent of agents) {\n unseen.delete(agent.agentIndex);\n const position = agent.position();\n const velocity = agent.velocity();\n const agentParams = agent.parameters();\n let agentMesh = this.agentMeshes.get(agent.agentIndex);\n if (agentMesh === undefined) {\n agentMesh = this.createAgentMesh(agentParams);\n this.add(agentMesh);\n this.agentMeshes.set(agent.agentIndex, agentMesh);\n }\n agentMesh.position.set(position.x, position.y + agentParams.height / 2, position.z);\n agentMesh.lookAt(new Vector3().copy(agentMesh.position).add(velocity));\n }\n for (const agentId of unseen) {\n const agentMesh = this.agentMeshes.get(agentId);\n if (agentMesh) {\n this.remove(agentMesh);\n this.agentMeshes.delete(agentId);\n }\n }\n }\n createAgentMesh(agentParams) {\n const geometry = new CylinderGeometry(agentParams.radius, agentParams.radius, agentParams.height);\n return new Mesh(geometry, this.agentMaterial);\n }\n}\n//# sourceMappingURL=crowd-helper.js.map","import { BoxGeometry, Color, DynamicDrawUsage, InstancedMesh, Matrix4, MeshBasicMaterial, Object3D, } from 'three';\nconst tmpMatrix4 = new Matrix4();\nexport class HeightfieldHelper extends Object3D {\n heightfields;\n highlightWalkable;\n defaultColor;\n walkableColor;\n material;\n constructor({ heightfields, highlightWalkable = false, material = new MeshBasicMaterial(), defaultColor = 'blue', walkableColor = 'green', }) {\n super();\n this.heightfields = heightfields;\n this.highlightWalkable = highlightWalkable;\n this.material = material;\n this.defaultColor = new Color(defaultColor);\n this.walkableColor = new Color(walkableColor);\n this.update();\n }\n update() {\n this.clear();\n for (const hf of this.heightfields) {\n const orig = hf.bmin();\n const cs = hf.cs();\n const ch = hf.ch();\n const width = hf.width();\n const height = hf.height();\n const boxes = [];\n for (let y = 0; y < height; ++y) {\n for (let x = 0; x < width; ++x) {\n const fx = orig.x + x * cs;\n const fz = orig.z + y * cs;\n let span = hf.spans(x + y * width);\n while (span) {\n const minX = fx;\n const minY = orig.y + span.smin() * ch;\n const minZ = fz;\n const maxX = fx + cs;\n const maxY = orig.y + span.smax() * ch;\n const maxZ = fz + cs;\n boxes.push({\n position: [\n (maxX + minX) / 2,\n (maxY + minY) / 2,\n (maxZ + minZ) / 2,\n ],\n walkable: this.highlightWalkable && span.area() !== 0,\n });\n span = span.next();\n }\n }\n }\n const geometry = new BoxGeometry(cs, ch, cs);\n const instancedMesh = new InstancedMesh(geometry, this.material, boxes.length);\n instancedMesh.instanceMatrix.setUsage(DynamicDrawUsage);\n for (let i = 0; i < boxes.length; i++) {\n const { position, walkable } = boxes[i];\n instancedMesh.setMatrixAt(i, tmpMatrix4.setPosition(...position));\n instancedMesh.setColorAt(i, walkable ? this.walkableColor : this.defaultColor);\n }\n instancedMesh.instanceMatrix.needsUpdate = true;\n if (instancedMesh.instanceColor) {\n instancedMesh.instanceColor.needsUpdate = true;\n }\n this.add(instancedMesh);\n }\n }\n}\n//# sourceMappingURL=heightfield-helper.js.map","import { BufferAttribute, BufferGeometry, Mesh, MeshBasicMaterial, Object3D, } from 'three';\nexport class NavMeshHelper extends Object3D {\n navMesh;\n navMeshMaterial;\n mesh;\n geometry;\n constructor({ navMesh, navMeshMaterial }) {\n super();\n this.navMesh = navMesh;\n this.geometry = new BufferGeometry();\n this.navMeshMaterial = navMeshMaterial\n ? navMeshMaterial\n : new MeshBasicMaterial({\n color: 'orange',\n transparent: true,\n opacity: 0.7,\n });\n this.update();\n this.mesh = new Mesh(this.geometry, this.navMeshMaterial);\n this.add(this.mesh);\n }\n /**\n * Update the three debug nav mesh.\n *\n * This should be called after updating the nav mesh.\n */\n update() {\n const [positions, indices] = this.navMesh.getDebugNavMesh();\n this.geometry.setAttribute('position', new BufferAttribute(Float32Array.from(positions), 3));\n this.geometry.setIndex(new BufferAttribute(Uint32Array.from(indices), 1));\n this.geometry.computeVertexNormals();\n }\n}\n//# sourceMappingURL=nav-mesh-helper.js.map","import { BoxGeometry, CylinderGeometry, Mesh, MeshBasicMaterial, Object3D, } from 'three';\nexport class TileCacheHelper extends Object3D {\n tileCache;\n obstacleMeshes = new Map();\n obstacleMaterial;\n constructor({ tileCache, obstacleMaterial }) {\n super();\n this.tileCache = tileCache;\n this.obstacleMaterial = obstacleMaterial\n ? obstacleMaterial\n : new MeshBasicMaterial({\n color: 'red',\n wireframe: true,\n wireframeLinewidth: 2,\n });\n this.update();\n }\n /**\n * Update the obstacle meshes.\n *\n * This should be called after adding or removing obstacles.\n */\n update() {\n const unseen = new Set(this.obstacleMeshes.keys());\n for (const [, obstacle] of this.tileCache.obstacles) {\n let obstacleMesh = this.obstacleMeshes.get(obstacle);\n unseen.delete(obstacle);\n if (!obstacleMesh) {\n const { position } = obstacle;\n const mesh = new Mesh(undefined, this.obstacleMaterial);\n mesh.position.copy(position);\n if (obstacle.type === 'box') {\n const { extent, angle } = obstacle;\n mesh.geometry = new BoxGeometry(extent.x * 2, extent.y * 2, extent.z * 2);\n mesh.rotation.y = angle;\n }\n else if (obstacle.type === 'cylinder') {\n const { radius, height } = obstacle;\n mesh.geometry = new CylinderGeometry(radius, radius, height, 16);\n mesh.position.y += height / 2;\n }\n else {\n throw new Error(`Unknown obstacle type: ${obstacle}`);\n }\n this.add(mesh);\n this.obstacleMeshes.set(obstacle, mesh);\n }\n }\n for (const obstacle of unseen) {\n const obstacleMesh = this.obstacleMeshes.get(obstacle);\n if (obstacleMesh) {\n this.remove(obstacleMesh);\n this.obstacleMeshes.delete(obstacle);\n }\n }\n }\n}\n//# sourceMappingURL=tile-cache-helper.js.map","import { Vector3 } from 'three';\nconst tmpVec3 = new Vector3();\nexport const getPositionsAndIndices = (meshes) => {\n const meshesToMerge = [];\n for (const mesh of meshes) {\n const positionAttribute = mesh.geometry.attributes\n .position;\n if (!positionAttribute || positionAttribute.itemSize !== 3) {\n continue;\n }\n let meshToMerge = mesh;\n let index = mesh.geometry.getIndex()?.array;\n if (!index) {\n meshToMerge = meshToMerge.clone();\n meshToMerge.geometry = mesh.geometry.clone();\n // this will become indexed when merging with other meshes\n const ascendingIndex = [];\n for (let i = 0; i < positionAttribute.count; i++) {\n ascendingIndex.push(i);\n }\n meshToMerge.geometry.setIndex(ascendingIndex);\n }\n meshesToMerge.push(meshToMerge);\n }\n const mergedPositions = [];\n const mergedIndices = [];\n const positionToIndex = {};\n let indexCounter = 0;\n for (const mesh of meshesToMerge) {\n mesh.updateMatrixWorld();\n const positions = mesh.geometry.attributes.position.array;\n const index = mesh.geometry.getIndex().array;\n for (let i = 0; i < index.length; i++) {\n const pt = index[i] * 3;\n const pos = tmpVec3.set(positions[pt], positions[pt + 1], positions[pt + 2]);\n mesh.localToWorld(pos);\n const key = `${pos.x}_${pos.y}_${pos.z}`;\n let idx = positionToIndex[key];\n if (!idx) {\n positionToIndex[key] = idx = indexCounter;\n mergedPositions.push(pos.x, pos.y, pos.z);\n indexCounter++;\n }\n mergedIndices.push(idx);\n }\n }\n return [Float32Array.from(mergedPositions), Uint32Array.from(mergedIndices)];\n};\n//# sourceMappingURL=get-positions-and-indices.js.map","import { generateSoloNavMesh, generateTileCache, generateTiledNavMesh } from '@recast-navigation/core';\nimport { getPositionsAndIndices } from './get-positions-and-indices';\nexport const threeToSoloNavMesh = (meshes, navMeshGeneratorConfig = {}, keepIntermediates = false) => {\n const [positions, indices] = getPositionsAndIndices(meshes);\n return generateSoloNavMesh(positions, indices, navMeshGeneratorConfig, keepIntermediates);\n};\nexport const threeToTiledNavMesh = (meshes, navMeshGeneratorConfig = {}, keepIntermediates = false) => {\n const [positions, indices] = getPositionsAndIndices(meshes);\n return generateTiledNavMesh(positions, indices, navMeshGeneratorConfig, keepIntermediates);\n};\nexport const threeToTileCache = (meshes, navMeshGeneratorConfig = {}, keepIntermediates = false) => {\n const [positions, indices] = getPositionsAndIndices(meshes);\n return generateTileCache(positions, indices, navMeshGeneratorConfig, keepIntermediates);\n};\n//# sourceMappingURL=generators.js.map"],"names":["CrowdHelper","Object3D","agentMeshes","Map","recastCrowd","agentMaterial","constructor","crowd","super","this","MeshBasicMaterial","color","update","agents","getAgents","unseen","Set","keys","agent","delete","agentIndex","position","velocity","agentParams","parameters","agentMesh","get","undefined","createAgentMesh","add","set","x","y","height","z","lookAt","Vector3","copy","agentId","remove","geometry","CylinderGeometry","radius","Mesh","tmpMatrix4","Matrix4","HeightfieldHelper","heightfields","highlightWalkable","defaultColor","walkableColor","material","Color","clear","hf","orig","bmin","cs","ch","width","boxes","fx","fz","span","spans","minX","minY","smin","minZ","maxX","maxY","smax","maxZ","push","walkable","area","next","BoxGeometry","instancedMesh","InstancedMesh","length","instanceMatrix","setUsage","DynamicDrawUsage","i","setMatrixAt","setPosition","setColorAt","needsUpdate","instanceColor","NavMeshHelper","navMesh","navMeshMaterial","mesh","BufferGeometry","transparent","opacity","positions","indices","getDebugNavMesh","setAttribute","BufferAttribute","Float32Array","from","setIndex","Uint32Array","computeVertexNormals","TileCacheHelper","tileCache","obstacleMeshes","obstacleMaterial","wireframe","wireframeLinewidth","obstacle","obstacles","obstacleMesh","type","extent","angle","rotation","Error","tmpVec3","getPositionsAndIndices","meshes","meshesToMerge","positionAttribute","attributes","itemSize","meshToMerge","index","getIndex","array","clone","ascendingIndex","count","mergedPositions","mergedIndices","positionToIndex","indexCounter","updateMatrixWorld","pt","pos","localToWorld","key","idx","navMeshGeneratorConfig","keepIntermediates","generateSoloNavMesh","generateTileCache","generateTiledNavMesh"],"mappings":"yEACO,MAAMA,UAAoBC,EAAAA,SAC7BC,YAAc,IAAIC,IAClBC,YACAC,cACA,WAAAC,EAAYC,MAAEA,EAAKF,cAAEA,IACjBG,QACAC,KAAKL,YAAcG,EACnBE,KAAKJ,cACDA,GAAiB,IAAIK,EAAiBA,kBAAC,CAAEC,MAAO,QACpDF,KAAKG,QACR,CAMD,MAAAA,GACI,MAAMC,EAASJ,KAAKL,YAAYU,YAC1BC,EAAS,IAAIC,IAAIP,KAAKP,YAAYe,QACxC,IAAK,MAAMC,KAASL,EAAQ,CACxBE,EAAOI,OAAOD,EAAME,YACpB,MAAMC,EAAWH,EAAMG,WACjBC,EAAWJ,EAAMI,WACjBC,EAAcL,EAAMM,aAC1B,IAAIC,EAAYhB,KAAKP,YAAYwB,IAAI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AWzG,SAAS8G,MAC9CF,EAAQpC,EAAKrD,SAAS0F,WAAWC,MACvC,IAAK,IAAI/C,EAAI,EAAGA,EAAI6C,EAAMjD,OAAQI,IAAK,CACnC,MAAMwD,EAAgB,EAAXX,EAAM7C,GACXyD,EAAMpB,EAAQ3F,IAAImE,EAAU2C,GAAK3C,EAAU2C,EAAK,GAAI3C,EAAU2C,EAAK,IACzE/C,EAAKiD,aAAaD,GAClB,MAAME,EAAM,GAAGF,EAAI9G,KAAK8G,EAAI7G,KAAK6G,EAAI3G,IACrC,IAAI8G,EAAMP,EAAgBM,GACrBC,IACDP,EAAgBM,GAAOC,EAAMN,EAC7BH,EAAgB9D,KAAKoE,EAAI9G,EAAG8G,EAAI7G,EAAG6G,EAAI3G,GACvCwG,KAEJF,EAAc/D,KAAKuE,EACtB,CACJ,CACD,MAAO,CAAC1C,aAAaC,KAAKgC,GAAkB9B,YAAYF,KAAKiC,GAAe,kKC5C9C,CAACb,EAAQsB,EAAyB,CAAA,EAAIC,GAAoB,KACxF,MAAOjD,EAAWC,GAAWwB,EAAuBC,GACpD,OAAOwB,EAAmBA,oBAAClD,EAAWC,EAAS+C,EAAwBC,EAAkB,2BAM7D,CAACvB,EAAQsB,EAAyB,CAAA,EAAIC,GAAoB,KACtF,MAAOjD,EAAWC,GAAWwB,EAAuBC,GACpD,OAAOyB,EAAiBA,kBAACnD,EAAWC,EAAS+C,EAAwBC,EAAkB,8BANxD,CAACvB,EAAQsB,EAAyB,CAAA,EAAIC,GAAoB,KACzF,MAAOjD,EAAWC,GAAWwB,EAAuBC,GACpD,OAAO0B,EAAoBA,qBAACpD,EAAWC,EAAS+C,EAAwBC,EAAkB"}
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":["../src/helpers/crowd-helper.ts","../src/helpers/heightfield-helper.ts","../src/helpers/nav-mesh-helper.ts","../src/helpers/off-mesh-connections-helper.ts","../src/helpers/tile-cache-helper.ts","../src/utils/get-positions-and-indices.ts","../src/utils/generators.ts"],"sourcesContent":["import { CylinderGeometry, Mesh, MeshBasicMaterial, Object3D, Vector3, } from 'three';\nexport class CrowdHelper extends Object3D {\n agentMeshes = new Map();\n recastCrowd;\n agentMaterial;\n constructor({ crowd, agentMaterial }) {\n super();\n this.recastCrowd = crowd;\n this.agentMaterial =\n agentMaterial ?? new MeshBasicMaterial({ color: 'red' });\n this.update();\n }\n /**\n * Update the three debug view of the crowd agents.\n *\n * This should be called after updating the crowd.\n */\n update() {\n const agents = this.recastCrowd.getAgents();\n const unseen = new Set(this.agentMeshes.keys());\n for (const agent of agents) {\n unseen.delete(agent.agentIndex);\n const position = agent.position();\n const velocity = agent.velocity();\n const agentParams = agent.parameters();\n let agentMesh = this.agentMeshes.get(agent.agentIndex);\n if (agentMesh === undefined) {\n agentMesh = this.createAgentMesh(agentParams);\n this.add(agentMesh);\n this.agentMeshes.set(agent.agentIndex, agentMesh);\n }\n agentMesh.position.set(position.x, position.y + agentParams.height / 2, position.z);\n agentMesh.lookAt(new Vector3().copy(agentMesh.position).add(velocity));\n }\n for (const agentId of unseen) {\n const agentMesh = this.agentMeshes.get(agentId);\n if (agentMesh) {\n this.remove(agentMesh);\n this.agentMeshes.delete(agentId);\n }\n }\n }\n createAgentMesh(agentParams) {\n const geometry = new CylinderGeometry(agentParams.radius, agentParams.radius, agentParams.height);\n return new Mesh(geometry, this.agentMaterial);\n }\n}\n//# sourceMappingURL=crowd-helper.js.map","import { BoxGeometry, Color, DynamicDrawUsage, InstancedMesh, Matrix4, MeshBasicMaterial, Object3D, } from 'three';\nconst tmpMatrix4 = new Matrix4();\nexport class HeightfieldHelper extends Object3D {\n heightfields;\n highlightWalkable;\n defaultColor;\n walkableColor;\n material;\n constructor({ heightfields, highlightWalkable = false, material = new MeshBasicMaterial(), defaultColor = 'blue', walkableColor = 'green', }) {\n super();\n this.heightfields = heightfields;\n this.highlightWalkable = highlightWalkable;\n this.material = material;\n this.defaultColor = new Color(defaultColor);\n this.walkableColor = new Color(walkableColor);\n this.update();\n }\n update() {\n this.clear();\n for (const hf of this.heightfields) {\n const orig = hf.bmin();\n const cs = hf.cs();\n const ch = hf.ch();\n const width = hf.width();\n const height = hf.height();\n const boxes = [];\n for (let y = 0; y < height; ++y) {\n for (let x = 0; x < width; ++x) {\n const fx = orig.x + x * cs;\n const fz = orig.z + y * cs;\n let span = hf.spans(x + y * width);\n while (span) {\n const minX = fx;\n const minY = orig.y + span.smin() * ch;\n const minZ = fz;\n const maxX = fx + cs;\n const maxY = orig.y + span.smax() * ch;\n const maxZ = fz + cs;\n boxes.push({\n position: [\n (maxX + minX) / 2,\n (maxY + minY) / 2,\n (maxZ + minZ) / 2,\n ],\n walkable: this.highlightWalkable && span.area() !== 0,\n });\n span = span.next();\n }\n }\n }\n const geometry = new BoxGeometry(cs, ch, cs);\n const instancedMesh = new InstancedMesh(geometry, this.material, boxes.length);\n instancedMesh.instanceMatrix.setUsage(DynamicDrawUsage);\n for (let i = 0; i < boxes.length; i++) {\n const { position, walkable } = boxes[i];\n instancedMesh.setMatrixAt(i, tmpMatrix4.setPosition(...position));\n instancedMesh.setColorAt(i, walkable ? this.walkableColor : this.defaultColor);\n }\n instancedMesh.instanceMatrix.needsUpdate = true;\n if (instancedMesh.instanceColor) {\n instancedMesh.instanceColor.needsUpdate = true;\n }\n this.add(instancedMesh);\n }\n }\n}\n//# sourceMappingURL=heightfield-helper.js.map","import { BufferAttribute, BufferGeometry, Mesh, MeshBasicMaterial, Object3D, } from 'three';\nexport class NavMeshHelper extends Object3D {\n navMesh;\n navMeshMaterial;\n mesh;\n geometry;\n constructor({ navMesh, navMeshMaterial }) {\n super();\n this.navMesh = navMesh;\n this.geometry = new BufferGeometry();\n this.navMeshMaterial = navMeshMaterial\n ? navMeshMaterial\n : new MeshBasicMaterial({\n color: 'orange',\n transparent: true,\n opacity: 0.7,\n });\n this.update();\n this.mesh = new Mesh(this.geometry, this.navMeshMaterial);\n this.add(this.mesh);\n }\n /**\n * Update the three debug nav mesh.\n *\n * This should be called after updating the nav mesh.\n */\n update() {\n const [positions, indices] = this.navMesh.getDebugNavMesh();\n this.geometry.setAttribute('position', new BufferAttribute(Float32Array.from(positions), 3));\n this.geometry.setIndex(new BufferAttribute(Uint32Array.from(indices), 1));\n this.geometry.computeVertexNormals();\n }\n}\n//# sourceMappingURL=nav-mesh-helper.js.map","import { BufferGeometry, CatmullRomCurve3, CircleGeometry, Line, LineBasicMaterial, Mesh, MeshBasicMaterial, Object3D, Vector3, } from 'three';\nexport class OffMeshConnectionsHelper extends Object3D {\n offMeshConnections;\n entryCircleMaterial;\n exitCircleMaterial;\n lineMaterial;\n constructor({ offMeshConnections, entryCircleMaterial, exitCircleMaterial, lineMaterial, }) {\n super();\n this.offMeshConnections = offMeshConnections ?? [];\n this.entryCircleMaterial =\n entryCircleMaterial ?? new MeshBasicMaterial({ color: 'green' });\n this.exitCircleMaterial =\n exitCircleMaterial ?? new MeshBasicMaterial({ color: 'blue' });\n this.lineMaterial = lineMaterial ?? new LineBasicMaterial({ color: 'red' });\n this.update();\n }\n /**\n * Update the three debug view of the off mesh connections.\n */\n update() {\n this.clear();\n for (const offMeshConnection of this.offMeshConnections) {\n // start and end circles\n const circleGeometry = new CircleGeometry(offMeshConnection.radius, 16);\n const startMesh = new Mesh(circleGeometry, this.entryCircleMaterial);\n startMesh.position.copy(offMeshConnection.startPosition);\n startMesh.position.y += 0.001;\n startMesh.rotation.x = -Math.PI / 2;\n this.add(startMesh);\n const endMesh = new Mesh(circleGeometry, offMeshConnection.bidirectional\n ? this.entryCircleMaterial\n : this.exitCircleMaterial);\n endMesh.position.copy(offMeshConnection.endPosition);\n endMesh.position.y += 0.001;\n endMesh.rotation.x = -Math.PI / 2;\n this.add(endMesh);\n // line between points\n const start = new Vector3().copy(offMeshConnection.startPosition);\n const end = new Vector3().copy(offMeshConnection.endPosition);\n const middle = new Vector3().addVectors(start, end).multiplyScalar(0.5);\n middle.y *= 1.2;\n const curve = new CatmullRomCurve3([start, middle, end]);\n const curvePoints = curve.getPoints(50);\n const lineGeometry = new BufferGeometry().setFromPoints(curvePoints);\n const line = new Line(lineGeometry, this.lineMaterial);\n this.add(line);\n }\n }\n}\n//# sourceMappingURL=off-mesh-connections-helper.js.map","import { BoxGeometry, CylinderGeometry, Mesh, MeshBasicMaterial, Object3D, } from 'three';\nexport class TileCacheHelper extends Object3D {\n tileCache;\n obstacleMeshes = new Map();\n obstacleMaterial;\n constructor({ tileCache, obstacleMaterial }) {\n super();\n this.tileCache = tileCache;\n this.obstacleMaterial = obstacleMaterial\n ? obstacleMaterial\n : new MeshBasicMaterial({\n color: 'red',\n wireframe: true,\n wireframeLinewidth: 2,\n });\n this.update();\n }\n /**\n * Update the obstacle meshes.\n *\n * This should be called after adding or removing obstacles.\n */\n update() {\n const unseen = new Set(this.obstacleMeshes.keys());\n for (const [, obstacle] of this.tileCache.obstacles) {\n let obstacleMesh = this.obstacleMeshes.get(obstacle);\n unseen.delete(obstacle);\n if (!obstacleMesh) {\n const { position } = obstacle;\n const mesh = new Mesh(undefined, this.obstacleMaterial);\n mesh.position.copy(position);\n if (obstacle.type === 'box') {\n const { extent, angle } = obstacle;\n mesh.geometry = new BoxGeometry(extent.x * 2, extent.y * 2, extent.z * 2);\n mesh.rotation.y = angle;\n }\n else if (obstacle.type === 'cylinder') {\n const { radius, height } = obstacle;\n mesh.geometry = new CylinderGeometry(radius, radius, height, 16);\n mesh.position.y += height / 2;\n }\n else {\n throw new Error(`Unknown obstacle type: ${obstacle}`);\n }\n this.add(mesh);\n this.obstacleMeshes.set(obstacle, mesh);\n }\n }\n for (const obstacle of unseen) {\n const obstacleMesh = this.obstacleMeshes.get(obstacle);\n if (obstacleMesh) {\n this.remove(obstacleMesh);\n this.obstacleMeshes.delete(obstacle);\n }\n }\n }\n}\n//# sourceMappingURL=tile-cache-helper.js.map","import { Vector3 } from 'three';\nconst tmpVec3 = new Vector3();\nexport const getPositionsAndIndices = (meshes) => {\n const meshesToMerge = [];\n for (const mesh of meshes) {\n const positionAttribute = mesh.geometry.attributes\n .position;\n if (!positionAttribute || positionAttribute.itemSize !== 3) {\n continue;\n }\n let meshToMerge = mesh;\n let index = mesh.geometry.getIndex()?.array;\n if (!index) {\n meshToMerge = meshToMerge.clone();\n meshToMerge.geometry = mesh.geometry.clone();\n // this will become indexed when merging with other meshes\n const ascendingIndex = [];\n for (let i = 0; i < positionAttribute.count; i++) {\n ascendingIndex.push(i);\n }\n meshToMerge.geometry.setIndex(ascendingIndex);\n }\n meshesToMerge.push(meshToMerge);\n }\n const mergedPositions = [];\n const mergedIndices = [];\n const positionToIndex = {};\n let indexCounter = 0;\n for (const mesh of meshesToMerge) {\n mesh.updateMatrixWorld();\n const positions = mesh.geometry.attributes.position.array;\n const index = mesh.geometry.getIndex().array;\n for (let i = 0; i < index.length; i++) {\n const pt = index[i] * 3;\n const pos = tmpVec3.set(positions[pt], positions[pt + 1], positions[pt + 2]);\n mesh.localToWorld(pos);\n const key = `${pos.x}_${pos.y}_${pos.z}`;\n let idx = positionToIndex[key];\n if (!idx) {\n positionToIndex[key] = idx = indexCounter;\n mergedPositions.push(pos.x, pos.y, pos.z);\n indexCounter++;\n }\n mergedIndices.push(idx);\n }\n }\n return [Float32Array.from(mergedPositions), Uint32Array.from(mergedIndices)];\n};\n//# sourceMappingURL=get-positions-and-indices.js.map","import { generateSoloNavMesh, generateTileCache, generateTiledNavMesh } from '@recast-navigation/core';\nimport { getPositionsAndIndices } from './get-positions-and-indices';\nexport const threeToSoloNavMesh = (meshes, navMeshGeneratorConfig = {}, keepIntermediates = false) => {\n const [positions, indices] = getPositionsAndIndices(meshes);\n return generateSoloNavMesh(positions, indices, navMeshGeneratorConfig, keepIntermediates);\n};\nexport const threeToTiledNavMesh = (meshes, navMeshGeneratorConfig = {}, keepIntermediates = false) => {\n const [positions, indices] = getPositionsAndIndices(meshes);\n return generateTiledNavMesh(positions, indices, navMeshGeneratorConfig, keepIntermediates);\n};\nexport const threeToTileCache = (meshes, navMeshGeneratorConfig = {}, keepIntermediates = false) => {\n const [positions, indices] = getPositionsAndIndices(meshes);\n return generateTileCache(positions, indices, navMeshGeneratorConfig, keepIntermediates);\n};\n//# sourceMappingURL=generators.js.map"],"names":["CrowdHelper","Object3D","agentMeshes","Map","recastCrowd","agentMaterial","constructor","crowd","super","this","MeshBasicMaterial","color","update","agents","getAgents","unseen","Set","keys","agent","delete","agentIndex","position","velocity","agentParams","parameters","agentMesh","get","undefined","createAgentMesh","add","set","x","y","height","z","lookAt","Vector3","copy","agentId","remove","geometry","CylinderGeometry","radius","Mesh","tmpMatrix4","Matrix4","HeightfieldHelper","heightfields","highlightWalkable","defaultColor","walkableColor","material","Color","clear","hf","orig","bmin","cs","ch","width","boxes","fx","fz","span","spans","minX","minY","smin","minZ","maxX","maxY","smax","maxZ","push","walkable","area","next","BoxGeometry","instancedMesh","InstancedMesh","length","instanceMatrix","setUsage","DynamicDrawUsage","i","setMatrixAt","setPosition","setColorAt","needsUpdate","instanceColor","NavMeshHelper","navMesh","navMeshMaterial","mesh","BufferGeometry","transparent","opacity","positions","indices","getDebugNavMesh","setAttribute","BufferAttribute","Float32Array","from","setIndex","Uint32Array","computeVertexNormals","OffMeshConnectionsHelper","offMeshConnections","entryCircleMaterial","exitCircleMaterial","lineMaterial","LineBasicMaterial","offMeshConnection","circleGeometry","CircleGeometry","startMesh","startPosition","rotation","Math","PI","endMesh","bidirectional","endPosition","start","end","middle","addVectors","multiplyScalar","curvePoints","CatmullRomCurve3","getPoints","lineGeometry","setFromPoints","line","Line","TileCacheHelper","tileCache","obstacleMeshes","obstacleMaterial","wireframe","wireframeLinewidth","obstacle","obstacles","obstacleMesh","type","extent","angle","Error","tmpVec3","getPositionsAndIndices","meshes","meshesToMerge","positionAttribute","attributes","itemSize","meshToMerge","index","getIndex","array","clone","ascendingIndex","count","mergedPositions","mergedIndices","positionToIndex","indexCounter","updateMatrixWorld","pt","pos","localToWorld","key","idx","navMeshGeneratorConfig","keepIntermediates","generateSoloNavMesh","generateTileCache","generateTiledNavMes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AoB,KACxF,MAAO7E,EAAWC,GAAWoD,EAAuBC,GACpD,OAAOwB,EAAmBA,oBAAC9E,EAAWC,EAAS2E,EAAwBC,EAAkB,2BAM7D,CAACvB,EAAQsB,EAAyB,CAAA,EAAIC,GAAoB,KACtF,MAAO7E,EAAWC,GAAWoD,EAAuBC,GACpD,OAAOyB,EAAiBA,kBAAC/E,EAAWC,EAAS2E,EAAwBC,EAAkB,8BANxD,CAACvB,EAAQsB,EAAyB,CAAA,EAAIC,GAAoB,KACzF,MAAO7E,EAAWC,GAAWoD,EAAuBC,GACpD,OAAO0B,EAAoBA,qBAAChF,EAAWC,EAAS2E,EAAwBC,EAAkB"}
|
package/dist/index.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{Object3D as e,MeshBasicMaterial as t,Vector3 as s,CylinderGeometry as o,Mesh as
|
|
1
|
+
import{Object3D as e,MeshBasicMaterial as t,Vector3 as s,CylinderGeometry as o,Mesh as i,Matrix4 as a,Color as n,BoxGeometry as r,InstancedMesh as l,DynamicDrawUsage as h,BufferGeometry as c,BufferAttribute as d,LineBasicMaterial as g,CircleGeometry as M,CatmullRomCurve3 as p,Line as w}from"three";import{generateSoloNavMesh as y,generateTiledNavMesh as f,generateTileCache as u}from"@recast-navigation/core";class m extends e{agentMeshes=new Map;recastCrowd;agentMaterial;constructor({crowd:e,agentMaterial:s}){super(),this.recastCrowd=e,this.agentMaterial=s??new t({color:"red"}),this.update()}update(){const e=this.recastCrowd.getAgents(),t=new Set(this.agentMeshes.keys());for(const o of e){t.delete(o.agentIndex);const e=o.position(),i=o.velocity(),a=o.parameters();let n=this.agentMeshes.get(o.agentIndex);void 0===n&&(n=this.createAgentMesh(a),this.add(n),this.agentMeshes.set(o.agentIndex,n)),n.position.set(e.x,e.y+a.height/2,e.z),n.lookAt((new s).copy(n.position).add(i))}for(const e of t){const t=this.agentMeshes.get(e);t&&(this.remove(t),this.agentMeshes.delete(e))}}createAgentMesh(e){const t=new o(e.radius,e.radius,e.height);return new i(t,this.agentMaterial)}}const x=new a;class b extends e{heightfields;highlightWalkable;defaultColor;walkableColor;material;constructor({heightfields:e,highlightWalkable:s=!1,material:o=new t,defaultColor:i="blue",walkableColor:a="green"}){super(),this.heightfields=e,this.highlightWalkable=s,this.material=o,this.defaultColor=new n(i),this.walkableColor=new n(a),this.update()}update(){this.clear();for(const e of this.heightfields){const t=e.bmin(),s=e.cs(),o=e.ch(),i=e.width(),a=e.height(),n=[];for(let r=0;r<a;++r)for(let a=0;a<i;++a){const l=t.x+a*s,h=t.z+r*s;let c=e.spans(a+r*i);for(;c;){const e=l,i=t.y+c.smin()*o,a=h,r=l+s,d=t.y+c.smax()*o,g=h+s;n.push({position:[(r+e)/2,(d+i)/2,(g+a)/2],walkable:this.highlightWalkable&&0!==c.area()}),c=c.next()}}const c=new r(s,o,s),d=new l(c,this.material,n.length);d.instanceMatrix.setUsage(h);for(let e=0;e<n.length;e++){const{position:t,walkable:s}=n[e];d.setMatrixAt(e,x.setPosition(...t)),d.setColorAt(e,s?this.walkableColor:this.defaultColor)}d.instanceMatrix.needsUpdate=!0,d.instanceColor&&(d.instanceColor.needsUpdate=!0),this.add(d)}}}class C extends e{navMesh;navMeshMaterial;mesh;geometry;constructor({navMesh:e,navMeshMaterial:s}){super(),this.navMesh=e,this.geometry=new c,this.navMeshMaterial=s||new t({color:"orange",transparent:!0,opacity:.7}),this.update(),this.mesh=new i(this.geometry,this.navMeshMaterial),this.add(this.mesh)}update(){const[e,t]=this.navMesh.getDebugNavMesh();this.geometry.setAttribute("position",new d(Float32Array.from(e),3)),this.geometry.setIndex(new d(Uint32Array.from(t),1)),this.geometry.computeVertexNormals()}}class v extends e{offMeshConnections;entryCircleMaterial;exitCircleMaterial;lineMaterial;constructor({offMeshConnections:e,entryCircleMaterial:s,exitCircleMaterial:o,lineMaterial:i}){super(),this.offMeshConnections=e??[],this.entryCircleMaterial=s??new t({color:"green"}),this.exitCircleMaterial=o??new t({color:"blue"}),this.lineMaterial=i??new g({color:"red"}),this.update()}update(){this.clear();for(const e of this.offMeshConnections){const t=new M(e.radius,16),o=new i(t,this.entryCircleMaterial);o.position.copy(e.startPosition),o.position.y+=.001,o.rotation.x=-Math.PI/2,this.add(o);const a=new i(t,e.bidirectional?this.entryCircleMaterial:this.exitCircleMaterial);a.position.copy(e.endPosition),a.position.y+=.001,a.rotation.x=-Math.PI/2,this.add(a);const n=(new s).copy(e.startPosition),r=(new s).copy(e.endPosition),l=(new s).addVectors(n,r).multiplyScalar(.5);l.y*=1.2;const h=new p([n,l,r]).getPoints(50),d=(new c).setFromPoints(h),g=new w(d,this.lineMaterial);this.add(g)}}}class k extends e{tileCache;obstacleMeshes=new Map;obstacleMaterial;constructor({tileCache:e,obstacleMaterial:s}){super(),this.tileCache=e,this.obstacleMaterial=s||new t({color:"red",wireframe:!0,wireframeLinewidth:2}),this.update()}update(){const e=new Set(this.obstacleMeshes.keys());for(const[,t]of this.tileCache.obstacles){let s=this.obstacleMeshes.get(t);if(e.delete(t),!s){const{position:e}=t,s=new i(void 0,this.obstacleMaterial);if(s.position.copy(e),"box"===t.type){const{extent:e,angle:o}=t;s.geometry=new r(2*e.x,2*e.y,2*e.z),s.rotation.y=o}else{if("cylinder"!==t.type)throw new Error(`Unknown obstacle type: ${t}`);{const{radius:e,height:i}=t;s.geometry=new o(e,e,i,16),s.position.y+=i/2}}this.add(s),this.obstacleMeshes.set(t,s)}}for(const t of e){const e=this.obstacleMeshes.get(t);e&&(this.remove(e),this.obstacleMeshes.delete(t))}}}const A=new s,I=e=>{const t=[];for(const s of e){const e=s.geometry.attributes.position;if(!e||3!==e.itemSize)continue;let o=s,i=s.geometry.getIndex()?.array;if(!i){o=o.clone(),o.geometry=s.geometry.clone();const t=[];for(let s=0;s<e.count;s++)t.push(s);o.geometry.setIndex(t)}t.push(o)}const s=[],o=[],i={};let a=0;for(const e of t){e.updateMatrixWorld();const t=e.geometry.attributes.position.array,n=e.geometry.getIndex().array;for(let r=0;r<n.length;r++){const l=3*n[r],h=A.set(t[l],t[l+1],t[l+2]);e.localToWorld(h);const c=`${h.x}_${h.y}_${h.z}`;let d=i[c];d||(i[c]=d=a,s.push(h.x,h.y,h.z),a++),o.push(d)}}return[Float32Array.from(s),Uint32Array.from(o)]},P=(e,t={},s=!1)=>{const[o,i]=I(e);return y(o,i,t,s)},z=(e,t={},s=!1)=>{const[o,i]=I(e);return f(o,i,t,s)},U=(e,t={},s=!1)=>{const[o,i]=I(e);return u(o,i,t,s)};export{m as CrowdHelper,b as HeightfieldHelper,C as NavMeshHelper,v as OffMeshConnectionsHelper,k as TileCacheHelper,I as getPositionsAndIndices,P as threeToSoloNavMesh,U as threeToTileCache,z as threeToTiledNavMesh};
|
|
2
2
|
//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sources":["../src/helpers/crowd-helper.ts","../src/helpers/heightfield-helper.ts","../src/helpers/nav-mesh-helper.ts","../src/helpers/tile-cache-helper.ts","../src/utils/get-positions-and-indices.ts","../src/utils/generators.ts"],"sourcesContent":["import { CylinderGeometry, Mesh, MeshBasicMaterial, Object3D, Vector3, } from 'three';\nexport class CrowdHelper extends Object3D {\n agentMeshes = new Map();\n recastCrowd;\n agentMaterial;\n constructor({ crowd, agentMaterial }) {\n super();\n this.recastCrowd = crowd;\n this.agentMaterial =\n agentMaterial ?? new MeshBasicMaterial({ color: 'red' });\n this.update();\n }\n /**\n * Update the three debug view of the crowd agents.\n *\n * This should be called after updating the crowd.\n */\n update() {\n const agents = this.recastCrowd.getAgents();\n const unseen = new Set(this.agentMeshes.keys());\n for (const agent of agents) {\n unseen.delete(agent.agentIndex);\n const position = agent.position();\n const velocity = agent.velocity();\n const agentParams = agent.parameters();\n let agentMesh = this.agentMeshes.get(agent.agentIndex);\n if (agentMesh === undefined) {\n agentMesh = this.createAgentMesh(agentParams);\n this.add(agentMesh);\n this.agentMeshes.set(agent.agentIndex, agentMesh);\n }\n agentMesh.position.set(position.x, position.y + agentParams.height / 2, position.z);\n agentMesh.lookAt(new Vector3().copy(agentMesh.position).add(velocity));\n }\n for (const agentId of unseen) {\n const agentMesh = this.agentMeshes.get(agentId);\n if (agentMesh) {\n this.remove(agentMesh);\n this.agentMeshes.delete(agentId);\n }\n }\n }\n createAgentMesh(agentParams) {\n const geometry = new CylinderGeometry(agentParams.radius, agentParams.radius, agentParams.height);\n return new Mesh(geometry, this.agentMaterial);\n }\n}\n//# sourceMappingURL=crowd-helper.js.map","import { BoxGeometry, Color, DynamicDrawUsage, InstancedMesh, Matrix4, MeshBasicMaterial, Object3D, } from 'three';\nconst tmpMatrix4 = new Matrix4();\nexport class HeightfieldHelper extends Object3D {\n heightfields;\n highlightWalkable;\n defaultColor;\n walkableColor;\n material;\n constructor({ heightfields, highlightWalkable = false, material = new MeshBasicMaterial(), defaultColor = 'blue', walkableColor = 'green', }) {\n super();\n this.heightfields = heightfields;\n this.highlightWalkable = highlightWalkable;\n this.material = material;\n this.defaultColor = new Color(defaultColor);\n this.walkableColor = new Color(walkableColor);\n this.update();\n }\n update() {\n this.clear();\n for (const hf of this.heightfields) {\n const orig = hf.bmin();\n const cs = hf.cs();\n const ch = hf.ch();\n const width = hf.width();\n const height = hf.height();\n const boxes = [];\n for (let y = 0; y < height; ++y) {\n for (let x = 0; x < width; ++x) {\n const fx = orig.x + x * cs;\n const fz = orig.z + y * cs;\n let span = hf.spans(x + y * width);\n while (span) {\n const minX = fx;\n const minY = orig.y + span.smin() * ch;\n const minZ = fz;\n const maxX = fx + cs;\n const maxY = orig.y + span.smax() * ch;\n const maxZ = fz + cs;\n boxes.push({\n position: [\n (maxX + minX) / 2,\n (maxY + minY) / 2,\n (maxZ + minZ) / 2,\n ],\n walkable: this.highlightWalkable && span.area() !== 0,\n });\n span = span.next();\n }\n }\n }\n const geometry = new BoxGeometry(cs, ch, cs);\n const instancedMesh = new InstancedMesh(geometry, this.material, boxes.length);\n instancedMesh.instanceMatrix.setUsage(DynamicDrawUsage);\n for (let i = 0; i < boxes.length; i++) {\n const { position, walkable } = boxes[i];\n instancedMesh.setMatrixAt(i, tmpMatrix4.setPosition(...position));\n instancedMesh.setColorAt(i, walkable ? this.walkableColor : this.defaultColor);\n }\n instancedMesh.instanceMatrix.needsUpdate = true;\n if (instancedMesh.instanceColor) {\n instancedMesh.instanceColor.needsUpdate = true;\n }\n this.add(instancedMesh);\n }\n }\n}\n//# sourceMappingURL=heightfield-helper.js.map","import { BufferAttribute, BufferGeometry, Mesh, MeshBasicMaterial, Object3D, } from 'three';\nexport class NavMeshHelper extends Object3D {\n navMesh;\n navMeshMaterial;\n mesh;\n geometry;\n constructor({ navMesh, navMeshMaterial }) {\n super();\n this.navMesh = navMesh;\n this.geometry = new BufferGeometry();\n this.navMeshMaterial = navMeshMaterial\n ? navMeshMaterial\n : new MeshBasicMaterial({\n color: 'orange',\n transparent: true,\n opacity: 0.7,\n });\n this.update();\n this.mesh = new Mesh(this.geometry, this.navMeshMaterial);\n this.add(this.mesh);\n }\n /**\n * Update the three debug nav mesh.\n *\n * This should be called after updating the nav mesh.\n */\n update() {\n const [positions, indices] = this.navMesh.getDebugNavMesh();\n this.geometry.setAttribute('position', new BufferAttribute(Float32Array.from(positions), 3));\n this.geometry.setIndex(new BufferAttribute(Uint32Array.from(indices), 1));\n this.geometry.computeVertexNormals();\n }\n}\n//# sourceMappingURL=nav-mesh-helper.js.map","import { BoxGeometry, CylinderGeometry, Mesh, MeshBasicMaterial, Object3D, } from 'three';\nexport class TileCacheHelper extends Object3D {\n tileCache;\n obstacleMeshes = new Map();\n obstacleMaterial;\n constructor({ tileCache, obstacleMaterial }) {\n super();\n this.tileCache = tileCache;\n this.obstacleMaterial = obstacleMaterial\n ? obstacleMaterial\n : new MeshBasicMaterial({\n color: 'red',\n wireframe: true,\n wireframeLinewidth: 2,\n });\n this.update();\n }\n /**\n * Update the obstacle meshes.\n *\n * This should be called after adding or removing obstacles.\n */\n update() {\n const unseen = new Set(this.obstacleMeshes.keys());\n for (const [, obstacle] of this.tileCache.obstacles) {\n let obstacleMesh = this.obstacleMeshes.get(obstacle);\n unseen.delete(obstacle);\n if (!obstacleMesh) {\n const { position } = obstacle;\n const mesh = new Mesh(undefined, this.obstacleMaterial);\n mesh.position.copy(position);\n if (obstacle.type === 'box') {\n const { extent, angle } = obstacle;\n mesh.geometry = new BoxGeometry(extent.x * 2, extent.y * 2, extent.z * 2);\n mesh.rotation.y = angle;\n }\n else if (obstacle.type === 'cylinder') {\n const { radius, height } = obstacle;\n mesh.geometry = new CylinderGeometry(radius, radius, height, 16);\n mesh.position.y += height / 2;\n }\n else {\n throw new Error(`Unknown obstacle type: ${obstacle}`);\n }\n this.add(mesh);\n this.obstacleMeshes.set(obstacle, mesh);\n }\n }\n for (const obstacle of unseen) {\n const obstacleMesh = this.obstacleMeshes.get(obstacle);\n if (obstacleMesh) {\n this.remove(obstacleMesh);\n this.obstacleMeshes.delete(obstacle);\n }\n }\n }\n}\n//# sourceMappingURL=tile-cache-helper.js.map","import { Vector3 } from 'three';\nconst tmpVec3 = new Vector3();\nexport const getPositionsAndIndices = (meshes) => {\n const meshesToMerge = [];\n for (const mesh of meshes) {\n const positionAttribute = mesh.geometry.attributes\n .position;\n if (!positionAttribute || positionAttribute.itemSize !== 3) {\n continue;\n }\n let meshToMerge = mesh;\n let index = mesh.geometry.getIndex()?.array;\n if (!index) {\n meshToMerge = meshToMerge.clone();\n meshToMerge.geometry = mesh.geometry.clone();\n // this will become indexed when merging with other meshes\n const ascendingIndex = [];\n for (let i = 0; i < positionAttribute.count; i++) {\n ascendingIndex.push(i);\n }\n meshToMerge.geometry.setIndex(ascendingIndex);\n }\n meshesToMerge.push(meshToMerge);\n }\n const mergedPositions = [];\n const mergedIndices = [];\n const positionToIndex = {};\n let indexCounter = 0;\n for (const mesh of meshesToMerge) {\n mesh.updateMatrixWorld();\n const positions = mesh.geometry.attributes.position.array;\n const index = mesh.geometry.getIndex().array;\n for (let i = 0; i < index.length; i++) {\n const pt = index[i] * 3;\n const pos = tmpVec3.set(positions[pt], positions[pt + 1], positions[pt + 2]);\n mesh.localToWorld(pos);\n const key = `${pos.x}_${pos.y}_${pos.z}`;\n let idx = positionToIndex[key];\n if (!idx) {\n positionToIndex[key] = idx = indexCounter;\n mergedPositions.push(pos.x, pos.y, pos.z);\n indexCounter++;\n }\n mergedIndices.push(idx);\n }\n }\n return [Float32Array.from(mergedPositions), Uint32Array.from(mergedIndices)];\n};\n//# sourceMappingURL=get-positions-and-indices.js.map","import { generateSoloNavMesh, generateTileCache, generateTiledNavMesh } from '@recast-navigation/core';\nimport { getPositionsAndIndices } from './get-positions-and-indices';\nexport const threeToSoloNavMesh = (meshes, navMeshGeneratorConfig = {}, keepIntermediates = false) => {\n const [positions, indices] = getPositionsAndIndices(meshes);\n return generateSoloNavMesh(positions, indices, navMeshGeneratorConfig, keepIntermediates);\n};\nexport const threeToTiledNavMesh = (meshes, navMeshGeneratorConfig = {}, keepIntermediates = false) => {\n const [positions, indices] = getPositionsAndIndices(meshes);\n return generateTiledNavMesh(positions, indices, navMeshGeneratorConfig, keepIntermediates);\n};\nexport const threeToTileCache = (meshes, navMeshGeneratorConfig = {}, keepIntermediates = false) => {\n const [positions, indices] = getPositionsAndIndices(meshes);\n return generateTileCache(positions, indices, navMeshGeneratorConfig, keepIntermediates);\n};\n//# sourceMappingURL=generators.js.map"],"names":["CrowdHelper","Object3D","agentMeshes","Map","recastCrowd","agentMaterial","constructor","crowd","super","this","MeshBasicMaterial","color","update","agents","getAgents","unseen","Set","keys","agent","delete","agentIndex","position","velocity","agentParams","parameters","agentMesh","get","undefined","createAgentMesh","add","set","x","y","height","z","lookAt","Vector3","copy","agentId","remove","geometry","CylinderGeometry","radius","Mesh","tmpMatrix4","Matrix4","HeightfieldHelper","heightfields","highlightWalkable","defaultColor","walkableColor","material","Color","clear","hf","orig","bmin","cs","ch","width","boxes","fx","fz","span","spans","minX","minY","smin","minZ","maxX","maxY","smax","maxZ","push","walkable","area","next","BoxGeometry","instancedMesh","InstancedMesh","length","instanceMatrix","setUsage","DynamicDrawUsage","i","setMatrixAt","setPosition","setColorAt","needsUpdate","instanceColor","NavMeshHelper","navMesh","navMeshMaterial","mesh","BufferGeometry","transparent","opacity","positions","indices","getDebugNavMesh","setAttribute","BufferAttribute","Float32Array","from","setIndex","Uint32Array","computeVertexNormals","TileCacheHelper","tileCache","obstacleMeshes","obstacleMaterial","wireframe","wireframeLinewidth","obstacle","obstacles","obstacleMesh","type","extent","angle","rotation","Error","tmpVec3","getPositionsAndIndices","meshes","meshesToMerge","positionAttribute","attributes","itemSize","meshToMerge","index","getIndex","array","clone","ascendingIndex","count","mergedPositions","mergedIndices","positionToIndex","indexCounter","updateMatrixWorld","pt","pos","localToWorld","key","idx","threeToSoloNavMesh","navMeshGeneratorConfig","keepIntermediates","generateSoloNavMesh","threeToTiledNavMesh","generateTiledNavMesh","threeToTileCache","generateTileCache"],"mappings":"+UACO,MAAMA,UAAoBC,EAC7BC,YAAc,IAAIC,IAClBC,YACAC,cACA,WAAAC,EAAYC,MAAEA,EAAKF,cAAEA,IACjBG,QACAC,KAAKL,YAAcG,EACnBE,KAAKJ,cACDA,GAAiB,IAAIK,EAAkB,CAAEC,MAAO,QACpDF,KAAKG,QACR,CAMD,MAAAA,GACI,MAAMC,EAASJ,KAAKL,YAAYU,YAC1BC,EAAS,IAAIC,IAAIP,KAAKP,YAAYe,QACxC,IAAK,MAAMC,KAASL,EAAQ,CACxBE,EAAOI,OAAOD,EAAME,YACpB,MAAMC,EAAWH,EAAMG,WACjBC,EAAWJ,EAAMI,WACjBC,EAAcL,EAAMM,aAC1B,IAAIC,EAAYhB,KAAKP,YAAYwB,IAAIR,EAAME,iBACzBO,IAAdF,IACAA,EAAYhB,KAAKmB,gBAAgBL,GACjCd,KAAKoB,IAAIJ,GACThB,KAAKP,YAAY4B,IAAIZ,EAAME,WAAYK,IAE3CA,EAAUJ,SAASS,IAAIT,EAASU,EA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8G,EAAI7G,KAAK6G,EAAI3G,IACrC,IAAI8G,EAAMP,EAAgBM,GACrBC,IACDP,EAAgBM,GAAOC,EAAMN,EAC7BH,EAAgB9D,KAAKoE,EAAI9G,EAAG8G,EAAI7G,EAAG6G,EAAI3G,GACvCwG,KAEJF,EAAc/D,KAAKuE,EACtB,CACJ,CACD,MAAO,CAAC1C,aAAaC,KAAKgC,GAAkB9B,YAAYF,KAAKiC,GAAe,EC5CnES,EAAqB,CAACtB,EAAQuB,EAAyB,CAAA,EAAIC,GAAoB,KACxF,MAAOlD,EAAWC,GAAWwB,EAAuBC,GACpD,OAAOyB,EAAoBnD,EAAWC,EAASgD,EAAwBC,EAAkB,EAEhFE,EAAsB,CAAC1B,EAAQuB,EAAyB,CAAA,EAAIC,GAAoB,KACzF,MAAOlD,EAAWC,GAAWwB,EAAuBC,GACpD,OAAO2B,EAAqBrD,EAAWC,EAASgD,EAAwBC,EAAkB,EAEjFI,EAAmB,CAAC5B,EAAQuB,EAAyB,CAAA,EAAIC,GAAoB,KACtF,MAAOlD,EAAWC,GAAWwB,EAAuBC,GACpD,OAAO6B,EAAkBvD,EAAWC,EAASgD,EAAwBC,EAAkB"}
|
|
1
|
+
{"version":3,"file":"index.mjs","sources":["../src/helpers/crowd-helper.ts","../src/helpers/heightfield-helper.ts","../src/helpers/nav-mesh-helper.ts","../src/helpers/off-mesh-connections-helper.ts","../src/helpers/tile-cache-helper.ts","../src/utils/get-positions-and-indices.ts","../src/utils/generators.ts"],"sourcesContent":["import { CylinderGeometry, Mesh, MeshBasicMaterial, Object3D, Vector3, } from 'three';\nexport class CrowdHelper extends Object3D {\n agentMeshes = new Map();\n recastCrowd;\n agentMaterial;\n constructor({ crowd, agentMaterial }) {\n super();\n this.recastCrowd = crowd;\n this.agentMaterial =\n agentMaterial ?? new MeshBasicMaterial({ color: 'red' });\n this.update();\n }\n /**\n * Update the three debug view of the crowd agents.\n *\n * This should be called after updating the crowd.\n */\n update() {\n const agents = this.recastCrowd.getAgents();\n const unseen = new Set(this.agentMeshes.keys());\n for (const agent of agents) {\n unseen.delete(agent.agentIndex);\n const position = agent.position();\n const velocity = agent.velocity();\n const agentParams = agent.parameters();\n let agentMesh = this.agentMeshes.get(agent.agentIndex);\n if (agentMesh === undefined) {\n agentMesh = this.createAgentMesh(agentParams);\n this.add(agentMesh);\n this.agentMeshes.set(agent.agentIndex, agentMesh);\n }\n agentMesh.position.set(position.x, position.y + agentParams.height / 2, position.z);\n agentMesh.lookAt(new Vector3().copy(agentMesh.position).add(velocity));\n }\n for (const agentId of unseen) {\n const agentMesh = this.agentMeshes.get(agentId);\n if (agentMesh) {\n this.remove(agentMesh);\n this.agentMeshes.delete(agentId);\n }\n }\n }\n createAgentMesh(agentParams) {\n const geometry = new CylinderGeometry(agentParams.radius, agentParams.radius, agentParams.height);\n return new Mesh(geometry, this.agentMaterial);\n }\n}\n//# sourceMappingURL=crowd-helper.js.map","import { BoxGeometry, Color, DynamicDrawUsage, InstancedMesh, Matrix4, MeshBasicMaterial, Object3D, } from 'three';\nconst tmpMatrix4 = new Matrix4();\nexport class HeightfieldHelper extends Object3D {\n heightfields;\n highlightWalkable;\n defaultColor;\n walkableColor;\n material;\n constructor({ heightfields, highlightWalkable = false, material = new MeshBasicMaterial(), defaultColor = 'blue', walkableColor = 'green', }) {\n super();\n this.heightfields = heightfields;\n this.highlightWalkable = highlightWalkable;\n this.material = material;\n this.defaultColor = new Color(defaultColor);\n this.walkableColor = new Color(walkableColor);\n this.update();\n }\n update() {\n this.clear();\n for (const hf of this.heightfields) {\n const orig = hf.bmin();\n const cs = hf.cs();\n const ch = hf.ch();\n const width = hf.width();\n const height = hf.height();\n const boxes = [];\n for (let y = 0; y < height; ++y) {\n for (let x = 0; x < width; ++x) {\n const fx = orig.x + x * cs;\n const fz = orig.z + y * cs;\n let span = hf.spans(x + y * width);\n while (span) {\n const minX = fx;\n const minY = orig.y + span.smin() * ch;\n const minZ = fz;\n const maxX = fx + cs;\n const maxY = orig.y + span.smax() * ch;\n const maxZ = fz + cs;\n boxes.push({\n position: [\n (maxX + minX) / 2,\n (maxY + minY) / 2,\n (maxZ + minZ) / 2,\n ],\n walkable: this.highlightWalkable && span.area() !== 0,\n });\n span = span.next();\n }\n }\n }\n const geometry = new BoxGeometry(cs, ch, cs);\n const instancedMesh = new InstancedMesh(geometry, this.material, boxes.length);\n instancedMesh.instanceMatrix.setUsage(DynamicDrawUsage);\n for (let i = 0; i < boxes.length; i++) {\n const { position, walkable } = boxes[i];\n instancedMesh.setMatrixAt(i, tmpMatrix4.setPosition(...position));\n instancedMesh.setColorAt(i, walkable ? this.walkableColor : this.defaultColor);\n }\n instancedMesh.instanceMatrix.needsUpdate = true;\n if (instancedMesh.instanceColor) {\n instancedMesh.instanceColor.needsUpdate = true;\n }\n this.add(instancedMesh);\n }\n }\n}\n//# sourceMappingURL=heightfield-helper.js.map","import { BufferAttribute, BufferGeometry, Mesh, MeshBasicMaterial, Object3D, } from 'three';\nexport class NavMeshHelper extends Object3D {\n navMesh;\n navMeshMaterial;\n mesh;\n geometry;\n constructor({ navMesh, navMeshMaterial }) {\n super();\n this.navMesh = navMesh;\n this.geometry = new BufferGeometry();\n this.navMeshMaterial = navMeshMaterial\n ? navMeshMaterial\n : new MeshBasicMaterial({\n color: 'orange',\n transparent: true,\n opacity: 0.7,\n });\n this.update();\n this.mesh = new Mesh(this.geometry, this.navMeshMaterial);\n this.add(this.mesh);\n }\n /**\n * Update the three debug nav mesh.\n *\n * This should be called after updating the nav mesh.\n */\n update() {\n const [positions, indices] = this.navMesh.getDebugNavMesh();\n this.geometry.setAttribute('position', new BufferAttribute(Float32Array.from(positions), 3));\n this.geometry.setIndex(new BufferAttribute(Uint32Array.from(indices), 1));\n this.geometry.computeVertexNormals();\n }\n}\n//# sourceMappingURL=nav-mesh-helper.js.map","import { BufferGeometry, CatmullRomCurve3, CircleGeometry, Line, LineBasicMaterial, Mesh, MeshBasicMaterial, Object3D, Vector3, } from 'three';\nexport class OffMeshConnectionsHelper extends Object3D {\n offMeshConnections;\n entryCircleMaterial;\n exitCircleMaterial;\n lineMaterial;\n constructor({ offMeshConnections, entryCircleMaterial, exitCircleMaterial, lineMaterial, }) {\n super();\n this.offMeshConnections = offMeshConnections ?? [];\n this.entryCircleMaterial =\n entryCircleMaterial ?? new MeshBasicMaterial({ color: 'green' });\n this.exitCircleMaterial =\n exitCircleMaterial ?? new MeshBasicMaterial({ color: 'blue' });\n this.lineMaterial = lineMaterial ?? new LineBasicMaterial({ color: 'red' });\n this.update();\n }\n /**\n * Update the three debug view of the off mesh connections.\n */\n update() {\n this.clear();\n for (const offMeshConnection of this.offMeshConnections) {\n // start and end circles\n const circleGeometry = new CircleGeometry(offMeshConnection.radius, 16);\n const startMesh = new Mesh(circleGeometry, this.entryCircleMaterial);\n startMesh.position.copy(offMeshConnection.startPosition);\n startMesh.position.y += 0.001;\n startMesh.rotation.x = -Math.PI / 2;\n this.add(startMesh);\n const endMesh = new Mesh(circleGeometry, offMeshConnection.bidirectional\n ? this.entryCircleMaterial\n : this.exitCircleMaterial);\n endMesh.position.copy(offMeshConnection.endPosition);\n endMesh.position.y += 0.001;\n endMesh.rotation.x = -Math.PI / 2;\n this.add(endMesh);\n // line between points\n const start = new Vector3().copy(offMeshConnection.startPosition);\n const end = new Vector3().copy(offMeshConnection.endPosition);\n const middle = new Vector3().addVectors(start, end).multiplyScalar(0.5);\n middle.y *= 1.2;\n const curve = new CatmullRomCurve3([start, middle, end]);\n const curvePoints = curve.getPoints(50);\n const lineGeometry = new BufferGeometry().setFromPoints(curvePoints);\n const line = new Line(lineGeometry, this.lineMaterial);\n this.add(line);\n }\n }\n}\n//# sourceMappingURL=off-mesh-connections-helper.js.map","import { BoxGeometry, CylinderGeometry, Mesh, MeshBasicMaterial, Object3D, } from 'three';\nexport class TileCacheHelper extends Object3D {\n tileCache;\n obstacleMeshes = new Map();\n obstacleMaterial;\n constructor({ tileCache, obstacleMaterial }) {\n super();\n this.tileCache = tileCache;\n this.obstacleMaterial = obstacleMaterial\n ? obstacleMaterial\n : new MeshBasicMaterial({\n color: 'red',\n wireframe: true,\n wireframeLinewidth: 2,\n });\n this.update();\n }\n /**\n * Update the obstacle meshes.\n *\n * This should be called after adding or removing obstacles.\n */\n update() {\n const unseen = new Set(this.obstacleMeshes.keys());\n for (const [, obstacle] of this.tileCache.obstacles) {\n let obstacleMesh = this.obstacleMeshes.get(obstacle);\n unseen.delete(obstacle);\n if (!obstacleMesh) {\n const { position } = obstacle;\n const mesh = new Mesh(undefined, this.obstacleMaterial);\n mesh.position.copy(position);\n if (obstacle.type === 'box') {\n const { extent, angle } = obstacle;\n mesh.geometry = new BoxGeometry(extent.x * 2, extent.y * 2, extent.z * 2);\n mesh.rotation.y = angle;\n }\n else if (obstacle.type === 'cylinder') {\n const { radius, height } = obstacle;\n mesh.geometry = new CylinderGeometry(radius, radius, height, 16);\n mesh.position.y += height / 2;\n }\n else {\n throw new Error(`Unknown obstacle type: ${obstacle}`);\n }\n this.add(mesh);\n this.obstacleMeshes.set(obstacle, mesh);\n }\n }\n for (const obstacle of unseen) {\n const obstacleMesh = this.obstacleMeshes.get(obstacle);\n if (obstacleMesh) {\n this.remove(obstacleMesh);\n this.obstacleMeshes.delete(obstacle);\n }\n }\n }\n}\n//# sourceMappingURL=tile-cache-helper.js.map","import { Vector3 } from 'three';\nconst tmpVec3 = new Vector3();\nexport const getPositionsAndIndices = (meshes) => {\n const meshesToMerge = [];\n for (const mesh of meshes) {\n const positionAttribute = mesh.geometry.attributes\n .position;\n if (!positionAttribute || positionAttribute.itemSize !== 3) {\n continue;\n }\n let meshToMerge = mesh;\n let index = mesh.geometry.getIndex()?.array;\n if (!index) {\n meshToMerge = meshToMerge.clone();\n meshToMerge.geometry = mesh.geometry.clone();\n // this will become indexed when merging with other meshes\n const ascendingIndex = [];\n for (let i = 0; i < positionAttribute.count; i++) {\n ascendingIndex.push(i);\n }\n meshToMerge.geometry.setIndex(ascendingIndex);\n }\n meshesToMerge.push(meshToMerge);\n }\n const mergedPositions = [];\n const mergedIndices = [];\n const positionToIndex = {};\n let indexCounter = 0;\n for (const mesh of meshesToMerge) {\n mesh.updateMatrixWorld();\n const positions = mesh.geometry.attributes.position.array;\n const index = mesh.geometry.getIndex().array;\n for (let i = 0; i < index.length; i++) {\n const pt = index[i] * 3;\n const pos = tmpVec3.set(positions[pt], positions[pt + 1], positions[pt + 2]);\n mesh.localToWorld(pos);\n const key = `${pos.x}_${pos.y}_${pos.z}`;\n let idx = positionToIndex[key];\n if (!idx) {\n positionToIndex[key] = idx = indexCounter;\n mergedPositions.push(pos.x, pos.y, pos.z);\n indexCounter++;\n }\n mergedIndices.push(idx);\n }\n }\n return [Float32Array.from(mergedPositions), Uint32Array.from(mergedIndices)];\n};\n//# sourceMappingURL=get-positions-and-indices.js.map","import { generateSoloNavMesh, generateTileCache, generateTiledNavMesh } from '@recast-navigation/core';\nimport { getPositionsAndIndices } from './get-positions-and-indices';\nexport const threeToSoloNavMesh = (meshes, navMeshGeneratorConfig = {}, keepIntermediates = false) => {\n const [positions, indices] = getPositionsAndIndices(meshes);\n return generateSoloNavMesh(positions, indices, navMeshGeneratorConfig, keepIntermediates);\n};\nexport const threeToTiledNavMesh = (meshes, navMeshGeneratorConfig = {}, keepIntermediates = false) => {\n const [positions, indices] = getPositionsAndIndices(meshes);\n return generateTiledNavMesh(positions, indices, navMeshGeneratorConfig, keepIntermediates);\n};\nexport const threeToTileCache = (meshes, navMeshGeneratorConfig = {}, keepIntermediates = false) => {\n const [positions, indices] = getPositionsAndIndices(meshes);\n return generateTileCache(positions, indices, navMeshGeneratorConfig, keepIntermediates);\n};\n//# sourceMappingURL=generators.js.map"],"names":["CrowdHelper","Object3D","agentMeshes","Map","recastCrowd","agentMaterial","constructor","crowd","super","this","MeshBasicMaterial","color","update","agents","getAgents","unseen","Set","keys","agent","delete","agentIndex","position","velocity","agentParams","parameters","agentMesh","get","undefined","createAgentMesh","add","set","x","y","height","z","lookAt","Vector3","copy","agentId","remove","geometry","CylinderGeometry","radius","Mesh","tmpMatrix4","Matrix4","HeightfieldHelper","heightfields","highlightWalkable","defaultColor","walkableColor","material","Color","clear","hf","orig","bmin","cs","ch","width","boxes","fx","fz","span","spans","minX","minY","smin","minZ","maxX","maxY","smax","maxZ","push","walkable","area","next","BoxGeometry","instancedMesh","InstancedMesh","length","instanceMatrix","setUsage","DynamicDrawUsage","i","setMatrixAt","setPosition","setColorAt","needsUpdate","instanceColor","NavMeshHelper","navMesh","navMeshMaterial","mesh","BufferGeometry","transparent","opacity","positions","indices","getDebugNavMesh","setAttribute","BufferAttribute","Float32Array","from","setIndex","Uint32Array","computeVertexNormals","OffMeshConnectionsHelper","offMeshConnections","entryCircleMaterial","exitCircleMaterial","lineMaterial","LineBasicMaterial","offMeshConnection","circleGeometry","CircleGeometry","startMesh","startPosition","rotation","Math","PI","endMesh","bidirectional","endPosition","start","end","middle","addVectors","multiplyScalar","curvePoints","CatmullRomCurve3","getPoints","lineGeometry","setFromPoints","line","Line","TileCacheHelper","tileCache","obstacleMeshes","obstacleMaterial","wireframe","wireframeLinewidth","obstacle","obstacles","obstacleMesh","type","extent","angle","Error","tmpVec3","getPositionsAndIndices","meshes","meshesToMerge","positionAttribute","attributes","itemSize","meshToMerge","index","getIndex","array","clone","ascendingIndex","count","mergedPositions","mergedIndices","positionToIndex","indexCounter","updateMatrixWorld","pt","pos","localToWorld","key","idx","threeToSoloNavMesh","navMeshGeneratorConfig","keepIntermediates","generateSoloNavMesh","threeToTiledNavMesh","generateTiledNavMesh","threeToTileCache","generateTileCache"],"mappings":"0ZACO,MAAMA,UAAoBC,EAC7BC,YAAc,IAAIC,IAClBC,YACAC,cACA,WAAAC,EAAYC,MAAEA,EAAKF,cAAEA,IACjBG,QACAC,KAAKL,YAAcG,EACnBE,KAAKJ,cACDA,GAAiB,IAAIK,EAAkB,CAAEC,MAAO,QACpDF,KAAKG,QACR,CAMD,MAAAA,GACI,MAAMC,EAASJ,KAAKL,YAAYU,YAC1BC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ason.com/"
|
|
8
8
|
},
|
|
9
|
-
"version": "0.
|
|
9
|
+
"version": "0.10.1",
|
|
10
10
|
"license": "MIT",
|
|
11
11
|
"homepage": "https://github.com/isaac-mason/recast-navigation-js",
|
|
12
12
|
"bugs": {
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
"build": "rollup --config rollup.config.js --bundleConfigAsCjs"
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@recast-navigation/core": "0.
|
|
27
|
+
"@recast-navigation/core": "0.10.1"
|
|
28
28
|
},
|
|
29
29
|
"peerDependencies": {
|
|
30
30
|
"@types/three": "0.x.x",
|