@onerjs/addons 8.27.1 → 8.27.2
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/index.d.ts +1 -0
- package/index.js +1 -0
- package/index.js.map +1 -1
- package/navigation/common/config.d.ts +35 -0
- package/navigation/common/config.js +61 -0
- package/navigation/common/config.js.map +1 -0
- package/navigation/common/convert.d.ts +8 -0
- package/navigation/common/convert.js +22 -0
- package/navigation/common/convert.js.map +1 -0
- package/navigation/common/getters.d.ts +15 -0
- package/navigation/common/getters.js +76 -0
- package/navigation/common/getters.js.map +1 -0
- package/navigation/common/index.d.ts +6 -0
- package/navigation/common/index.js +7 -0
- package/navigation/common/index.js.map +1 -0
- package/navigation/common/smooth-path.d.ts +32 -0
- package/navigation/common/smooth-path.js +340 -0
- package/navigation/common/smooth-path.js.map +1 -0
- package/navigation/common/tile-cache.d.ts +15 -0
- package/navigation/common/tile-cache.js +32 -0
- package/navigation/common/tile-cache.js.map +1 -0
- package/navigation/common/utils.d.ts +17 -0
- package/navigation/common/utils.js +66 -0
- package/navigation/common/utils.js.map +1 -0
- package/navigation/debug/NavigationDebugger.d.ts +248 -0
- package/navigation/debug/NavigationDebugger.js +587 -0
- package/navigation/debug/NavigationDebugger.js.map +1 -0
- package/navigation/debug/index.d.ts +2 -0
- package/navigation/debug/index.js +3 -0
- package/navigation/debug/index.js.map +1 -0
- package/navigation/debug/simple-debug.d.ts +13 -0
- package/navigation/debug/simple-debug.js +23 -0
- package/navigation/debug/simple-debug.js.map +1 -0
- package/navigation/factory/common.d.ts +20 -0
- package/navigation/factory/common.js +80 -0
- package/navigation/factory/common.js.map +1 -0
- package/navigation/factory/factory.single-thread.d.ts +7 -0
- package/navigation/factory/factory.single-thread.js +15 -0
- package/navigation/factory/factory.single-thread.js.map +1 -0
- package/navigation/factory/factory.wasm.d.ts +7 -0
- package/navigation/factory/factory.wasm.js +15 -0
- package/navigation/factory/factory.wasm.js.map +1 -0
- package/navigation/factory/factory.worker.d.ts +9 -0
- package/navigation/factory/factory.worker.js +40 -0
- package/navigation/factory/factory.worker.js.map +1 -0
- package/navigation/factory/index.d.ts +2 -0
- package/navigation/factory/index.js +4 -0
- package/navigation/factory/index.js.map +1 -0
- package/navigation/generator/generator.common.d.ts +25 -0
- package/navigation/generator/generator.common.js +40 -0
- package/navigation/generator/generator.common.js.map +1 -0
- package/navigation/generator/generator.single-thread.d.ts +20 -0
- package/navigation/generator/generator.single-thread.js +57 -0
- package/navigation/generator/generator.single-thread.js.map +1 -0
- package/navigation/generator/generator.worker.d.ts +29 -0
- package/navigation/generator/generator.worker.js +47 -0
- package/navigation/generator/generator.worker.js.map +1 -0
- package/navigation/generator/index.d.ts +3 -0
- package/navigation/generator/index.js +5 -0
- package/navigation/generator/index.js.map +1 -0
- package/navigation/generator/injection.d.ts +6 -0
- package/navigation/generator/injection.js +16 -0
- package/navigation/generator/injection.js.map +1 -0
- package/navigation/index.d.ts +5 -0
- package/navigation/index.js +7 -0
- package/navigation/index.js.map +1 -0
- package/navigation/plugin/RecastJSCrowd.d.ts +198 -0
- package/navigation/plugin/RecastJSCrowd.js +359 -0
- package/navigation/plugin/RecastJSCrowd.js.map +1 -0
- package/navigation/plugin/RecastNavigationJSPlugin.d.ts +396 -0
- package/navigation/plugin/RecastNavigationJSPlugin.js +445 -0
- package/navigation/plugin/RecastNavigationJSPlugin.js.map +1 -0
- package/navigation/plugin/index.d.ts +1 -0
- package/navigation/plugin/index.js +2 -0
- package/navigation/plugin/index.js.map +1 -0
- package/navigation/types.d.ts +199 -0
- package/navigation/types.js +11 -0
- package/navigation/types.js.map +1 -0
- package/navigation/worker/navmesh-worker.d.ts +4 -0
- package/navigation/worker/navmesh-worker.js +63 -0
- package/navigation/worker/navmesh-worker.js.map +1 -0
- package/package.json +2 -2
|
@@ -0,0 +1,340 @@
|
|
|
1
|
+
import { Vector3 } from "@onerjs/core/Maths/math.vector.js";
|
|
2
|
+
import { ConvertNavPathPoints } from "./convert.js";
|
|
3
|
+
import { ComputePathError } from "../types.js";
|
|
4
|
+
import { GetRecast } from "../factory/common.js";
|
|
5
|
+
const _DELTA = new Vector3();
|
|
6
|
+
const _MOVE_TARGET = new Vector3();
|
|
7
|
+
/**
|
|
8
|
+
* Compute a smooth navigation path from start to end. Returns an empty array if no path can be computed
|
|
9
|
+
* @param navMesh the navigation mesh to use
|
|
10
|
+
* @param navmeshQuery the navigation mesh query to use
|
|
11
|
+
* @param start world position
|
|
12
|
+
* @param end world position
|
|
13
|
+
* @param options options object
|
|
14
|
+
* @returns array containing world position composing the path
|
|
15
|
+
*/
|
|
16
|
+
export function ComputeSmoothPath(navMesh, navmeshQuery, start, end, options) {
|
|
17
|
+
return ConvertNavPathPoints(ComputeSmoothPathImpl(navMesh, navmeshQuery, start, end, options));
|
|
18
|
+
}
|
|
19
|
+
function ComputeSmoothPathImpl(navMesh, navMeshQuery, start, end, options) {
|
|
20
|
+
const recast = GetRecast();
|
|
21
|
+
const filter = options?.filter ?? navMeshQuery.defaultFilter;
|
|
22
|
+
const halfExtents = options?.halfExtents ?? navMeshQuery.defaultQueryHalfExtents;
|
|
23
|
+
const maxSmoothPathPoints = options?.maxSmoothPathPoints ?? 2048;
|
|
24
|
+
const maxPathPolys = options?.maxPathPolys ?? 256;
|
|
25
|
+
const stepSize = options?.stepSize ?? 0.5;
|
|
26
|
+
const slop = options?.slop ?? 0.01;
|
|
27
|
+
// find nearest polygons for start and end positions
|
|
28
|
+
const startNearestPolyResult = navMeshQuery.findNearestPoly(start, {
|
|
29
|
+
filter,
|
|
30
|
+
halfExtents,
|
|
31
|
+
});
|
|
32
|
+
if (!startNearestPolyResult.success) {
|
|
33
|
+
return {
|
|
34
|
+
success: false,
|
|
35
|
+
error: {
|
|
36
|
+
type: ComputePathError.START_NEAREST_POLY_FAILED,
|
|
37
|
+
status: startNearestPolyResult.status,
|
|
38
|
+
},
|
|
39
|
+
path: [],
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
const endNearestPolyResult = navMeshQuery.findNearestPoly(end, {
|
|
43
|
+
filter,
|
|
44
|
+
halfExtents,
|
|
45
|
+
});
|
|
46
|
+
if (!endNearestPolyResult.success) {
|
|
47
|
+
return {
|
|
48
|
+
success: false,
|
|
49
|
+
error: {
|
|
50
|
+
type: ComputePathError.END_NEAREST_POLY_FAILED,
|
|
51
|
+
status: endNearestPolyResult.status,
|
|
52
|
+
},
|
|
53
|
+
path: [],
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
const startRef = startNearestPolyResult.nearestRef;
|
|
57
|
+
const endRef = endNearestPolyResult.nearestRef;
|
|
58
|
+
// find polygon path
|
|
59
|
+
const findPathResult = navMeshQuery.findPath(startRef, endRef, start, end, {
|
|
60
|
+
filter,
|
|
61
|
+
maxPathPolys,
|
|
62
|
+
});
|
|
63
|
+
if (!findPathResult.success) {
|
|
64
|
+
return {
|
|
65
|
+
success: false,
|
|
66
|
+
error: {
|
|
67
|
+
type: ComputePathError.FIND_PATH_FAILED,
|
|
68
|
+
status: findPathResult.status,
|
|
69
|
+
},
|
|
70
|
+
path: [],
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
if (findPathResult.polys.size <= 0) {
|
|
74
|
+
return {
|
|
75
|
+
success: false,
|
|
76
|
+
error: {
|
|
77
|
+
type: ComputePathError.NO_POLYGON_PATH_FOUND,
|
|
78
|
+
},
|
|
79
|
+
path: [],
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
const lastPoly = findPathResult.polys.get(findPathResult.polys.size - 1);
|
|
83
|
+
let closestEnd = end;
|
|
84
|
+
if (lastPoly !== endRef) {
|
|
85
|
+
const lastPolyClosestPointResult = navMeshQuery.closestPointOnPoly(lastPoly, end);
|
|
86
|
+
if (!lastPolyClosestPointResult.success) {
|
|
87
|
+
return {
|
|
88
|
+
success: false,
|
|
89
|
+
error: {
|
|
90
|
+
type: ComputePathError.NO_CLOSEST_POINT_ON_LAST_POLYGON_FOUND,
|
|
91
|
+
status: lastPolyClosestPointResult.status,
|
|
92
|
+
},
|
|
93
|
+
path: [],
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
closestEnd = lastPolyClosestPointResult.closestPoint;
|
|
97
|
+
}
|
|
98
|
+
// Iterate over the path to find a smooth path on the detail mesh
|
|
99
|
+
const iterPos = new Vector3(start.x, start.y, start.z);
|
|
100
|
+
const targetPos = new Vector3(closestEnd.x, closestEnd.y, closestEnd.z);
|
|
101
|
+
const polys = Array.from(findPathResult.polys.getHeapView());
|
|
102
|
+
const smoothPath = [];
|
|
103
|
+
smoothPath.push(iterPos.clone());
|
|
104
|
+
while (polys.length > 0 && smoothPath.length < maxSmoothPathPoints) {
|
|
105
|
+
// Find location to steer towards
|
|
106
|
+
const steerTarget = getSteerTarget(navMeshQuery, iterPos, targetPos, slop, polys, recast);
|
|
107
|
+
if (!steerTarget.success) {
|
|
108
|
+
break;
|
|
109
|
+
}
|
|
110
|
+
const isEndOfPath = steerTarget.steerPosFlag & recast.Detour.DT_STRAIGHTPATH_END;
|
|
111
|
+
const isOffMeshConnection = steerTarget.steerPosFlag & recast.Detour.DT_STRAIGHTPATH_OFFMESH_CONNECTION;
|
|
112
|
+
// Find movement delta.
|
|
113
|
+
const steerPos = steerTarget.steerPos;
|
|
114
|
+
const delta = _DELTA.copyFrom(steerPos).subtract(iterPos);
|
|
115
|
+
let len = Math.sqrt(delta.dot(delta));
|
|
116
|
+
// If the steer target is the end of the path or an off-mesh connection, do not move past the location.
|
|
117
|
+
if ((isEndOfPath || isOffMeshConnection) && len < stepSize) {
|
|
118
|
+
len = 1;
|
|
119
|
+
}
|
|
120
|
+
else {
|
|
121
|
+
len = stepSize / len;
|
|
122
|
+
}
|
|
123
|
+
const moveTarget = _MOVE_TARGET.copyFrom(iterPos).addInPlace(delta.scale(len));
|
|
124
|
+
// Move
|
|
125
|
+
const moveAlongSurface = navMeshQuery.moveAlongSurface(polys[0], iterPos, moveTarget, { filter, maxVisitedSize: 16 });
|
|
126
|
+
if (!moveAlongSurface.success) {
|
|
127
|
+
break;
|
|
128
|
+
}
|
|
129
|
+
const result = moveAlongSurface.resultPosition;
|
|
130
|
+
fixupCorridor(polys, maxPathPolys, moveAlongSurface.visited);
|
|
131
|
+
fixupShortcuts(polys, navMesh, recast);
|
|
132
|
+
const polyHeightResult = navMeshQuery.getPolyHeight(polys[0], result);
|
|
133
|
+
if (polyHeightResult.success) {
|
|
134
|
+
result.y = polyHeightResult.height;
|
|
135
|
+
}
|
|
136
|
+
iterPos.copyFromFloats(result.x, result.y, result.z);
|
|
137
|
+
// Handle end of path and off-mesh links when close enough
|
|
138
|
+
if (isEndOfPath && inRange(iterPos, steerTarget.steerPos, slop, 1.0)) {
|
|
139
|
+
// Reached end of path
|
|
140
|
+
iterPos.copyFrom(targetPos);
|
|
141
|
+
if (smoothPath.length < maxSmoothPathPoints) {
|
|
142
|
+
smoothPath.push(new Vector3(iterPos.x, iterPos.y, iterPos.z));
|
|
143
|
+
}
|
|
144
|
+
break;
|
|
145
|
+
}
|
|
146
|
+
else if (isOffMeshConnection && inRange(iterPos, steerTarget.steerPos, slop, 1.0)) {
|
|
147
|
+
// Reached off-mesh connection.
|
|
148
|
+
// Advance the path up to and over the off-mesh connection.
|
|
149
|
+
const offMeshConRef = steerTarget.steerPosRef;
|
|
150
|
+
// Advance the path up to and over the off-mesh connection.
|
|
151
|
+
let prevPolyRef = 0;
|
|
152
|
+
let polyRef = polys[0];
|
|
153
|
+
let npos = 0;
|
|
154
|
+
while (npos < polys.length && polyRef !== offMeshConRef) {
|
|
155
|
+
prevPolyRef = polyRef;
|
|
156
|
+
polyRef = polys[npos];
|
|
157
|
+
npos++;
|
|
158
|
+
}
|
|
159
|
+
for (let i = npos; i < polys.length; i++) {
|
|
160
|
+
polys[i - npos] = polys[i];
|
|
161
|
+
}
|
|
162
|
+
polys.splice(npos, polys.length - npos);
|
|
163
|
+
// Handle the connection
|
|
164
|
+
const offMeshConnectionPolyEndPoints = navMesh.getOffMeshConnectionPolyEndPoints(prevPolyRef, polyRef);
|
|
165
|
+
if (offMeshConnectionPolyEndPoints.success) {
|
|
166
|
+
if (smoothPath.length < maxSmoothPathPoints) {
|
|
167
|
+
smoothPath.push(new Vector3(iterPos.x, iterPos.y, iterPos.z));
|
|
168
|
+
// Hack to make the dotted path not visible during off-mesh connection.
|
|
169
|
+
if (smoothPath.length & 1) {
|
|
170
|
+
smoothPath.push(new Vector3(iterPos.x, iterPos.y, iterPos.z));
|
|
171
|
+
}
|
|
172
|
+
// Move position at the other side of the off-mesh link.
|
|
173
|
+
iterPos.copyFromFloats(offMeshConnectionPolyEndPoints.end.x, offMeshConnectionPolyEndPoints.end.y, offMeshConnectionPolyEndPoints.end.z);
|
|
174
|
+
const endPositionPolyHeight = navMeshQuery.getPolyHeight(polys[0], iterPos);
|
|
175
|
+
if (endPositionPolyHeight.success) {
|
|
176
|
+
iterPos.y = endPositionPolyHeight.height;
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
// Store results.
|
|
182
|
+
if (smoothPath.length < maxSmoothPathPoints) {
|
|
183
|
+
smoothPath.push(new Vector3(iterPos.x, iterPos.y, iterPos.z));
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
return {
|
|
187
|
+
success: true,
|
|
188
|
+
path: smoothPath,
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
192
|
+
function getSteerTarget(navMeshQuery, start, end, minTargetDist, pathPolys, recast) {
|
|
193
|
+
const maxSteerPoints = 3;
|
|
194
|
+
const straightPath = navMeshQuery.findStraightPath(start, end, pathPolys, {
|
|
195
|
+
maxStraightPathPoints: maxSteerPoints,
|
|
196
|
+
});
|
|
197
|
+
if (!straightPath.success) {
|
|
198
|
+
return {
|
|
199
|
+
success: false,
|
|
200
|
+
};
|
|
201
|
+
}
|
|
202
|
+
const outPoints = [];
|
|
203
|
+
for (let i = 0; i < straightPath.straightPathCount; i++) {
|
|
204
|
+
const point = new Vector3(straightPath.straightPath.get(i * 3), straightPath.straightPath.get(i * 3 + 1), straightPath.straightPath.get(i * 3 + 2));
|
|
205
|
+
outPoints.push(point);
|
|
206
|
+
}
|
|
207
|
+
// Find vertex far enough to steer to
|
|
208
|
+
let ns = 0;
|
|
209
|
+
while (ns < outPoints.length) {
|
|
210
|
+
// Stop at Off-Mesh link or when point is further than slop away
|
|
211
|
+
if (straightPath.straightPathFlags.get(ns) & recast.Detour.DT_STRAIGHTPATH_OFFMESH_CONNECTION) {
|
|
212
|
+
break;
|
|
213
|
+
}
|
|
214
|
+
const posA = outPoints[ns];
|
|
215
|
+
const posB = start;
|
|
216
|
+
if (!inRange(posA, posB, minTargetDist, 1000.0)) {
|
|
217
|
+
break;
|
|
218
|
+
}
|
|
219
|
+
ns++;
|
|
220
|
+
}
|
|
221
|
+
// Failed to find good point to steer to
|
|
222
|
+
if (ns >= straightPath.straightPathCount) {
|
|
223
|
+
return {
|
|
224
|
+
success: false,
|
|
225
|
+
};
|
|
226
|
+
}
|
|
227
|
+
const steerPos = outPoints[ns];
|
|
228
|
+
const steerPosFlag = straightPath.straightPathFlags.get(ns);
|
|
229
|
+
const steerPosRef = straightPath.straightPathRefs.get(ns);
|
|
230
|
+
return {
|
|
231
|
+
success: true,
|
|
232
|
+
steerPos,
|
|
233
|
+
steerPosFlag,
|
|
234
|
+
steerPosRef,
|
|
235
|
+
points: outPoints,
|
|
236
|
+
};
|
|
237
|
+
}
|
|
238
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
239
|
+
function inRange(a, b, r, h) {
|
|
240
|
+
const dx = b.x - a.x;
|
|
241
|
+
const dy = b.y - a.y;
|
|
242
|
+
const dz = b.z - a.z;
|
|
243
|
+
return dx * dx + dz * dz < r && Math.abs(dy) < h;
|
|
244
|
+
}
|
|
245
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
246
|
+
function fixupCorridor(pathPolys, maxPath, visitedPolyRefs) {
|
|
247
|
+
let furthestPath = -1;
|
|
248
|
+
let furthestVisited = -1;
|
|
249
|
+
// Find furthest common polygon.
|
|
250
|
+
for (let i = pathPolys.length - 1; i >= 0; i--) {
|
|
251
|
+
let found = false;
|
|
252
|
+
for (let j = visitedPolyRefs.length - 1; j >= 0; j--) {
|
|
253
|
+
if (pathPolys[i] === visitedPolyRefs[j]) {
|
|
254
|
+
furthestPath = i;
|
|
255
|
+
furthestVisited = j;
|
|
256
|
+
found = true;
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
if (found) {
|
|
260
|
+
break;
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
// If no intersection found just return current path.
|
|
264
|
+
if (furthestPath === -1 || furthestVisited === -1) {
|
|
265
|
+
return pathPolys;
|
|
266
|
+
}
|
|
267
|
+
// Concatenate paths.
|
|
268
|
+
// Adjust beginning of the buffer to include the visited.
|
|
269
|
+
const req = visitedPolyRefs.length - furthestVisited;
|
|
270
|
+
const orig = Math.min(furthestPath + 1, pathPolys.length);
|
|
271
|
+
let size = Math.max(0, pathPolys.length - orig);
|
|
272
|
+
if (req + size > maxPath) {
|
|
273
|
+
size = maxPath - req;
|
|
274
|
+
}
|
|
275
|
+
if (size) {
|
|
276
|
+
pathPolys.splice(req, size, ...pathPolys.slice(orig, orig + size));
|
|
277
|
+
}
|
|
278
|
+
// Store visited
|
|
279
|
+
for (let i = 0; i < req; i++) {
|
|
280
|
+
pathPolys[i] = visitedPolyRefs[visitedPolyRefs.length - (1 + i)];
|
|
281
|
+
}
|
|
282
|
+
return pathPolys;
|
|
283
|
+
}
|
|
284
|
+
/**
|
|
285
|
+
* This function checks if the path has a small U-turn, that is,
|
|
286
|
+
* a polygon further in the path is adjacent to the first polygon
|
|
287
|
+
* in the path. If that happens, a shortcut is taken.
|
|
288
|
+
* This can happen if the target (T) location is at tile boundary,
|
|
289
|
+
* and we're (S) approaching it parallel to the tile edge.
|
|
290
|
+
* The choice at the vertex can be arbitrary,
|
|
291
|
+
* +---+---+
|
|
292
|
+
* |:::|:::|
|
|
293
|
+
* +-S-+-T-+
|
|
294
|
+
* |:::| | -- the step can end up in here, resulting U-turn path.
|
|
295
|
+
* +---+---+
|
|
296
|
+
* @param pathPolys The path polygons to check for U-turns.
|
|
297
|
+
* @param navMesh The navigation mesh used to check adjacency.
|
|
298
|
+
* @param recast The recast injection to use.
|
|
299
|
+
*/
|
|
300
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
301
|
+
function fixupShortcuts(pathPolys, navMesh, recast) {
|
|
302
|
+
if (pathPolys.length < 3) {
|
|
303
|
+
return;
|
|
304
|
+
}
|
|
305
|
+
// Get connected polygons
|
|
306
|
+
const maxNeis = 16;
|
|
307
|
+
let nneis = 0;
|
|
308
|
+
const neis = [];
|
|
309
|
+
const tileAndPoly = navMesh.getTileAndPolyByRef(pathPolys[0]);
|
|
310
|
+
if (!tileAndPoly.success) {
|
|
311
|
+
return;
|
|
312
|
+
}
|
|
313
|
+
const poly = tileAndPoly.poly;
|
|
314
|
+
const tile = tileAndPoly.tile;
|
|
315
|
+
for (let k = poly.firstLink(); k !== recast.Detour.DT_NULL_LINK; k = tile.links(k).next()) {
|
|
316
|
+
const link = tile.links(k);
|
|
317
|
+
if (link.ref() !== 0) {
|
|
318
|
+
if (nneis < maxNeis) {
|
|
319
|
+
neis.push(link.ref());
|
|
320
|
+
nneis++;
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
// If any of the neighbour polygons is within the next few polygons
|
|
325
|
+
// in the path, short cut to that polygon directly.
|
|
326
|
+
const maxLookAhead = 6;
|
|
327
|
+
let cut = 0;
|
|
328
|
+
for (let i = Math.min(maxLookAhead, pathPolys.length) - 1; i > 1 && cut === 0; i--) {
|
|
329
|
+
for (let j = 0; j < nneis; j++) {
|
|
330
|
+
if (pathPolys[i] === neis[j]) {
|
|
331
|
+
cut = i;
|
|
332
|
+
break;
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
if (cut > 1) {
|
|
337
|
+
pathPolys.splice(1, cut - 1);
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
//# sourceMappingURL=smooth-path.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"smooth-path.js","sourceRoot":"","sources":["../../../../../dev/addons/src/navigation/common/smooth-path.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,OAAO,EAAE,0CAA+B;AAEjD,OAAO,EAAE,oBAAoB,EAAE,MAAM,WAAW,CAAC;AAEjD,OAAO,EAAE,gBAAgB,EAA0B,MAAM,UAAU,CAAC;AACpE,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAE9C,MAAM,MAAM,GAAG,IAAI,OAAO,EAAE,CAAC;AAC7B,MAAM,YAAY,GAAG,IAAI,OAAO,EAAE,CAAC;AAEnC;;;;;;;;GAQG;AACH,MAAM,UAAU,iBAAiB,CAC7B,OAAgB,EAChB,YAA0B,EAC1B,KAAmB,EACnB,GAAiB,EACjB,OAuBC;IAED,OAAO,oBAAoB,CAAC,qBAAqB,CAAC,OAAO,EAAE,YAAY,EAAE,KAAK,EAAE,GAAG,EAAE,OAAO,CAAC,CAAC,CAAC;AACnG,CAAC;AAED,SAAS,qBAAqB,CAC1B,OAAgB,EAChB,YAA0B,EAC1B,KAAmB,EACnB,GAAiB,EACjB,OAOC;IAED,MAAM,MAAM,GAAG,SAAS,EAAE,CAAC;IAC3B,MAAM,MAAM,GAAG,OAAO,EAAE,MAAM,IAAI,YAAY,CAAC,aAAa,CAAC;IAC7D,MAAM,WAAW,GAAG,OAAO,EAAE,WAAW,IAAI,YAAY,CAAC,uBAAuB,CAAC;IACjF,MAAM,mBAAmB,GAAG,OAAO,EAAE,mBAAmB,IAAI,IAAI,CAAC;IACjE,MAAM,YAAY,GAAG,OAAO,EAAE,YAAY,IAAI,GAAG,CAAC;IAClD,MAAM,QAAQ,G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I,GAAG,GAAG,CAAC,EAAE,CAAC;QACV,SAAS,CAAC,MAAM,CAAC,CAAC,EAAE,GAAG,GAAG,CAAC,CAAC,CAAC;IACjC,CAAC;AACL,CAAC","sourcesContent":["import type { NavMeshQuery, NavMesh, QueryFilter } from \"@recast-navigation/core\";\n\nimport type { IVector3Like } from \"core/Maths/math.like\";\nimport { Vector3 } from \"core/Maths/math.vector\";\n\nimport { ConvertNavPathPoints } from \"./convert\";\nimport type { RecastInjection, SteerTargetResult } from \"../types\";\nimport { ComputePathError, type ComputePathResult } from \"../types\";\nimport { GetRecast } from \"../factory/common\";\n\nconst _DELTA = new Vector3();\nconst _MOVE_TARGET = new Vector3();\n\n/**\n * Compute a smooth navigation path from start to end. Returns an empty array if no path can be computed\n * @param navMesh the navigation mesh to use\n * @param navmeshQuery the navigation mesh query to use\n * @param start world position\n * @param end world position\n * @param options options object\n * @returns array containing world position composing the path\n */\nexport function ComputeSmoothPath(\n navMesh: NavMesh,\n navmeshQuery: NavMeshQuery,\n start: IVector3Like,\n end: IVector3Like,\n options?: {\n filter?: QueryFilter;\n halfExtents?: IVector3Like;\n\n /**\n * @default 256\n */\n maxPathPolys?: number;\n\n /**\n * @default 2048\n */\n maxSmoothPathPoints?: number;\n\n /**\n * @default 0.5\n */\n stepSize?: number;\n\n /**\n * @default 0.01\n */\n slop?: number;\n }\n): Vector3[] {\n return ConvertNavPathPoints(ComputeSmoothPathImpl(navMesh, navmeshQuery, start, end, options));\n}\n\nfunction ComputeSmoothPathImpl(\n navMesh: NavMesh,\n navMeshQuery: NavMeshQuery,\n start: IVector3Like,\n end: IVector3Like,\n options?: {\n filter?: QueryFilter;\n halfExtents?: IVector3Like;\n maxPathPolys?: number;\n maxSmoothPathPoints?: number;\n stepSize?: number;\n slop?: number;\n }\n): ComputePathResult {\n const recast = GetRecast();\n const filter = options?.filter ?? navMeshQuery.defaultFilter;\n const halfExtents = options?.halfExtents ?? navMeshQuery.defaultQueryHalfExtents;\n const maxSmoothPathPoints = options?.maxSmoothPathPoints ?? 2048;\n const maxPathPolys = options?.maxPathPolys ?? 256;\n const stepSize = options?.stepSize ?? 0.5;\n const slop = options?.slop ?? 0.01;\n\n // find nearest polygons for start and end positions\n const startNearestPolyResult = navMeshQuery.findNearestPoly(start, {\n filter,\n halfExtents,\n });\n\n if (!startNearestPolyResult.success) {\n return {\n success: false,\n error: {\n type: ComputePathError.START_NEAREST_POLY_FAILED,\n status: startNearestPolyResult.status,\n },\n path: [],\n };\n }\n\n const endNearestPolyResult = navMeshQuery.findNearestPoly(end, {\n filter,\n halfExtents,\n });\n\n if (!endNearestPolyResult.success) {\n return {\n success: false,\n error: {\n type: ComputePathError.END_NEAREST_POLY_FAILED,\n status: endNearestPolyResult.status,\n },\n path: [],\n };\n }\n\n const startRef = startNearestPolyResult.nearestRef;\n const endRef = endNearestPolyResult.nearestRef;\n\n // find polygon path\n const findPathResult = navMeshQuery.findPath(startRef, endRef, start, end, {\n filter,\n maxPathPolys,\n });\n\n if (!findPathResult.success) {\n return {\n success: false,\n error: {\n type: ComputePathError.FIND_PATH_FAILED,\n status: findPathResult.status,\n },\n path: [],\n };\n }\n\n if (findPathResult.polys.size <= 0) {\n return {\n success: false,\n error: {\n type: ComputePathError.NO_POLYGON_PATH_FOUND,\n },\n path: [],\n };\n }\n\n const lastPoly = findPathResult.polys.get(findPathResult.polys.size - 1);\n\n let closestEnd = end;\n\n if (lastPoly !== endRef) {\n const lastPolyClosestPointResult = navMeshQuery.closestPointOnPoly(lastPoly, end);\n\n if (!lastPolyClosestPointResult.success) {\n return {\n success: false,\n error: {\n type: ComputePathError.NO_CLOSEST_POINT_ON_LAST_POLYGON_FOUND,\n status: lastPolyClosestPointResult.status,\n },\n path: [],\n };\n }\n\n closestEnd = lastPolyClosestPointResult.closestPoint;\n }\n\n // Iterate over the path to find a smooth path on the detail mesh\n const iterPos = new Vector3(start.x, start.y, start.z);\n const targetPos = new Vector3(closestEnd.x, closestEnd.y, closestEnd.z);\n\n const polys = Array.from(findPathResult.polys.getHeapView());\n const smoothPath: Vector3[] = [];\n\n smoothPath.push(iterPos.clone());\n\n while (polys.length > 0 && smoothPath.length < maxSmoothPathPoints) {\n // Find location to steer towards\n const steerTarget = getSteerTarget(navMeshQuery, iterPos, targetPos, slop, polys, recast);\n\n if (!steerTarget.success) {\n break;\n }\n\n const isEndOfPath = steerTarget.steerPosFlag & recast.Detour.DT_STRAIGHTPATH_END;\n const isOffMeshConnection = steerTarget.steerPosFlag & recast.Detour.DT_STRAIGHTPATH_OFFMESH_CONNECTION;\n\n // Find movement delta.\n const steerPos = steerTarget.steerPos;\n const delta = _DELTA.copyFrom(steerPos).subtract(iterPos);\n let len = Math.sqrt(delta.dot(delta));\n\n // If the steer target is the end of the path or an off-mesh connection, do not move past the location.\n if ((isEndOfPath || isOffMeshConnection) && len < stepSize) {\n len = 1;\n } else {\n len = stepSize / len;\n }\n\n const moveTarget = _MOVE_TARGET.copyFrom(iterPos).addInPlace(delta.scale(len));\n\n // Move\n const moveAlongSurface = navMeshQuery.moveAlongSurface(polys[0], iterPos, moveTarget, { filter, maxVisitedSize: 16 });\n\n if (!moveAlongSurface.success) {\n break;\n }\n\n const result = moveAlongSurface.resultPosition;\n\n fixupCorridor(polys, maxPathPolys, moveAlongSurface.visited);\n fixupShortcuts(polys, navMesh, recast);\n\n const polyHeightResult = navMeshQuery.getPolyHeight(polys[0], result);\n\n if (polyHeightResult.success) {\n result.y = polyHeightResult.height;\n }\n\n iterPos.copyFromFloats(result.x, result.y, result.z);\n\n // Handle end of path and off-mesh links when close enough\n if (isEndOfPath && inRange(iterPos, steerTarget.steerPos, slop, 1.0)) {\n // Reached end of path\n iterPos.copyFrom(targetPos);\n\n if (smoothPath.length < maxSmoothPathPoints) {\n smoothPath.push(new Vector3(iterPos.x, iterPos.y, iterPos.z));\n }\n\n break;\n } else if (isOffMeshConnection && inRange(iterPos, steerTarget.steerPos, slop, 1.0)) {\n // Reached off-mesh connection.\n\n // Advance the path up to and over the off-mesh connection.\n const offMeshConRef = steerTarget.steerPosRef;\n\n // Advance the path up to and over the off-mesh connection.\n let prevPolyRef = 0;\n let polyRef = polys[0];\n let npos = 0;\n while (npos < polys.length && polyRef !== offMeshConRef) {\n prevPolyRef = polyRef;\n polyRef = polys[npos];\n npos++;\n }\n\n for (let i = npos; i < polys.length; i++) {\n polys[i - npos] = polys[i];\n }\n polys.splice(npos, polys.length - npos);\n\n // Handle the connection\n const offMeshConnectionPolyEndPoints = navMesh.getOffMeshConnectionPolyEndPoints(prevPolyRef, polyRef);\n\n if (offMeshConnectionPolyEndPoints.success) {\n if (smoothPath.length < maxSmoothPathPoints) {\n smoothPath.push(new Vector3(iterPos.x, iterPos.y, iterPos.z));\n\n // Hack to make the dotted path not visible during off-mesh connection.\n if (smoothPath.length & 1) {\n smoothPath.push(new Vector3(iterPos.x, iterPos.y, iterPos.z));\n }\n\n // Move position at the other side of the off-mesh link.\n iterPos.copyFromFloats(offMeshConnectionPolyEndPoints.end.x, offMeshConnectionPolyEndPoints.end.y, offMeshConnectionPolyEndPoints.end.z);\n\n const endPositionPolyHeight = navMeshQuery.getPolyHeight(polys[0], iterPos);\n\n if (endPositionPolyHeight.success) {\n iterPos.y = endPositionPolyHeight.height;\n }\n }\n }\n }\n\n // Store results.\n if (smoothPath.length < maxSmoothPathPoints) {\n smoothPath.push(new Vector3(iterPos.x, iterPos.y, iterPos.z));\n }\n }\n\n return {\n success: true,\n path: smoothPath,\n };\n}\n\n// eslint-disable-next-line @typescript-eslint/naming-convention\nfunction getSteerTarget(navMeshQuery: NavMeshQuery, start: Vector3, end: Vector3, minTargetDist: number, pathPolys: number[], recast: RecastInjection): SteerTargetResult {\n const maxSteerPoints = 3;\n const straightPath = navMeshQuery.findStraightPath(start, end, pathPolys, {\n maxStraightPathPoints: maxSteerPoints,\n });\n\n if (!straightPath.success) {\n return {\n success: false,\n };\n }\n\n const outPoints: Vector3[] = [];\n for (let i = 0; i < straightPath.straightPathCount; i++) {\n const point = new Vector3(straightPath.straightPath.get(i * 3), straightPath.straightPath.get(i * 3 + 1), straightPath.straightPath.get(i * 3 + 2));\n\n outPoints.push(point);\n }\n\n // Find vertex far enough to steer to\n let ns = 0;\n while (ns < outPoints.length) {\n // Stop at Off-Mesh link or when point is further than slop away\n if (straightPath.straightPathFlags.get(ns) & recast.Detour.DT_STRAIGHTPATH_OFFMESH_CONNECTION) {\n break;\n }\n\n const posA = outPoints[ns];\n const posB = start;\n\n if (!inRange(posA, posB, minTargetDist, 1000.0)) {\n break;\n }\n\n ns++;\n }\n\n // Failed to find good point to steer to\n if (ns >= straightPath.straightPathCount) {\n return {\n success: false,\n };\n }\n\n const steerPos = outPoints[ns];\n const steerPosFlag = straightPath.straightPathFlags.get(ns);\n const steerPosRef = straightPath.straightPathRefs.get(ns);\n\n return {\n success: true,\n steerPos,\n steerPosFlag,\n steerPosRef,\n points: outPoints,\n };\n}\n\n// eslint-disable-next-line @typescript-eslint/naming-convention\nfunction inRange(a: Vector3, b: Vector3, r: number, h: number) {\n const dx = b.x - a.x;\n const dy = b.y - a.y;\n const dz = b.z - a.z;\n return dx * dx + dz * dz < r && Math.abs(dy) < h;\n}\n\n// eslint-disable-next-line @typescript-eslint/naming-convention\nfunction fixupCorridor(pathPolys: number[], maxPath: number, visitedPolyRefs: number[]) {\n let furthestPath = -1;\n let furthestVisited = -1;\n\n // Find furthest common polygon.\n for (let i = pathPolys.length - 1; i >= 0; i--) {\n let found = false;\n for (let j = visitedPolyRefs.length - 1; j >= 0; j--) {\n if (pathPolys[i] === visitedPolyRefs[j]) {\n furthestPath = i;\n furthestVisited = j;\n found = true;\n }\n }\n if (found) {\n break;\n }\n }\n\n // If no intersection found just return current path.\n if (furthestPath === -1 || furthestVisited === -1) {\n return pathPolys;\n }\n\n // Concatenate paths.\n\n // Adjust beginning of the buffer to include the visited.\n const req = visitedPolyRefs.length - furthestVisited;\n const orig = Math.min(furthestPath + 1, pathPolys.length);\n\n let size = Math.max(0, pathPolys.length - orig);\n\n if (req + size > maxPath) {\n size = maxPath - req;\n }\n if (size) {\n pathPolys.splice(req, size, ...pathPolys.slice(orig, orig + size));\n }\n\n // Store visited\n for (let i = 0; i < req; i++) {\n pathPolys[i] = visitedPolyRefs[visitedPolyRefs.length - (1 + i)];\n }\n\n return pathPolys;\n}\n\n/**\n * This function checks if the path has a small U-turn, that is,\n * a polygon further in the path is adjacent to the first polygon\n * in the path. If that happens, a shortcut is taken.\n * This can happen if the target (T) location is at tile boundary,\n * and we're (S) approaching it parallel to the tile edge.\n * The choice at the vertex can be arbitrary,\n * +---+---+\n * |:::|:::|\n * +-S-+-T-+\n * |:::| | -- the step can end up in here, resulting U-turn path.\n * +---+---+\n * @param pathPolys The path polygons to check for U-turns.\n * @param navMesh The navigation mesh used to check adjacency.\n * @param recast The recast injection to use.\n */\n// eslint-disable-next-line @typescript-eslint/naming-convention\nfunction fixupShortcuts(pathPolys: number[], navMesh: NavMesh, recast: RecastInjection) {\n if (pathPolys.length < 3) {\n return;\n }\n\n // Get connected polygons\n const maxNeis = 16;\n let nneis = 0;\n const neis: number[] = [];\n\n const tileAndPoly = navMesh.getTileAndPolyByRef(pathPolys[0]);\n\n if (!tileAndPoly.success) {\n return;\n }\n\n const poly = tileAndPoly.poly;\n const tile = tileAndPoly.tile;\n for (let k = poly.firstLink(); k !== recast.Detour.DT_NULL_LINK; k = tile.links(k).next()) {\n const link = tile.links(k);\n\n if (link.ref() !== 0) {\n if (nneis < maxNeis) {\n neis.push(link.ref());\n nneis++;\n }\n }\n }\n\n // If any of the neighbour polygons is within the next few polygons\n // in the path, short cut to that polygon directly.\n const maxLookAhead = 6;\n let cut = 0;\n for (let i = Math.min(maxLookAhead, pathPolys.length) - 1; i > 1 && cut === 0; i--) {\n for (let j = 0; j < nneis; j++) {\n if (pathPolys[i] === neis[j]) {\n cut = i;\n break;\n }\n }\n }\n\n if (cut > 1) {\n pathPolys.splice(1, cut - 1);\n }\n}\n"]}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { NavMesh, OffMeshConnectionParams, TileCache } from "@recast-navigation/core";
|
|
2
|
+
/**
|
|
3
|
+
* Creates a default tile cache mesh process function
|
|
4
|
+
* @param offMeshConnections offMeshConnections
|
|
5
|
+
* @param area the area to be set for each poly
|
|
6
|
+
* @param flags the flags to be set for each poly
|
|
7
|
+
* @returns the tile cache mesh process function
|
|
8
|
+
*/
|
|
9
|
+
export declare function CreateDefaultTileCacheMeshProcess(offMeshConnections?: OffMeshConnectionParams[], area?: number, flags?: number): any;
|
|
10
|
+
/**
|
|
11
|
+
* Waits until the tile cache is fully updated
|
|
12
|
+
* @param navMesh The NavMesh
|
|
13
|
+
* @param tileCache THe TileCache
|
|
14
|
+
*/
|
|
15
|
+
export declare function WaitForFullTileCacheUpdate(navMesh: NavMesh, tileCache: TileCache): void;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { GetRecast } from "../factory/common.js";
|
|
2
|
+
/**
|
|
3
|
+
* Creates a default tile cache mesh process function
|
|
4
|
+
* @param offMeshConnections offMeshConnections
|
|
5
|
+
* @param area the area to be set for each poly
|
|
6
|
+
* @param flags the flags to be set for each poly
|
|
7
|
+
* @returns the tile cache mesh process function
|
|
8
|
+
*/
|
|
9
|
+
export function CreateDefaultTileCacheMeshProcess(offMeshConnections = [], area = 0, flags = 1) {
|
|
10
|
+
return new (GetRecast().TileCacheMeshProcess)((navMeshCreateParams, polyAreas, polyFlags) => {
|
|
11
|
+
for (let i = 0; i < navMeshCreateParams.polyCount(); ++i) {
|
|
12
|
+
polyAreas.set(i, area);
|
|
13
|
+
polyFlags.set(i, flags);
|
|
14
|
+
}
|
|
15
|
+
if (offMeshConnections.length > 0) {
|
|
16
|
+
navMeshCreateParams.setOffMeshConnections(offMeshConnections);
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Waits until the tile cache is fully updated
|
|
22
|
+
* @param navMesh The NavMesh
|
|
23
|
+
* @param tileCache THe TileCache
|
|
24
|
+
*/
|
|
25
|
+
export function WaitForFullTileCacheUpdate(navMesh, tileCache) {
|
|
26
|
+
let upToDate = false;
|
|
27
|
+
while (!upToDate) {
|
|
28
|
+
const result = tileCache.update(navMesh);
|
|
29
|
+
upToDate = result.upToDate;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=tile-cache.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tile-cache.js","sourceRoot":"","sources":["../../../../../dev/addons/src/navigation/common/tile-cache.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAE9C;;;;;;GAMG;AACH,MAAM,UAAU,iCAAiC,CAAC,qBAAgD,EAAE,EAAE,IAAI,GAAG,CAAC,EAAE,KAAK,GAAG,CAAC;IACrH,OAAO,IAAI,CAAC,SAAS,EAAE,CAAC,oBAAoB,CAAC,CAAC,CAAC,mBAAwC,EAAE,SAA4B,EAAE,SAA6B,EAAE,EAAE;QACpJ,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,mBAAmB,CAAC,SAAS,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC;YACvD,SAAS,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC;YACvB,SAAS,CAAC,GAAG,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC;QAC5B,CAAC;QAED,IAAI,kBAAkB,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YAChC,mBAAmB,CAAC,qBAAqB,CAAC,kBAAkB,CAAC,CAAC;QAClE,CAAC;IACL,CAAC,CAAC,CAAC;AACP,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,0BAA0B,CAAC,OAAgB,EAAE,SAAoB;IAC7E,IAAI,QAAQ,GAAG,KAAK,CAAC;IACrB,OAAO,CAAC,QAAQ,EAAE,CAAC;QACf,MAAM,MAAM,GAAG,SAAS,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;QACzC,QAAQ,GAAG,MAAM,CAAC,QAAQ,CAAC;IAC/B,CAAC;AACL,CAAC","sourcesContent":["import type { NavMesh, NavMeshCreateParams, OffMeshConnectionParams, TileCache, UnsignedCharArray, UnsignedShortArray } from \"@recast-navigation/core\";\n\nimport { GetRecast } from \"../factory/common\";\n\n/**\n * Creates a default tile cache mesh process function\n * @param offMeshConnections offMeshConnections\n * @param area the area to be set for each poly\n * @param flags the flags to be set for each poly\n * @returns the tile cache mesh process function\n */\nexport function CreateDefaultTileCacheMeshProcess(offMeshConnections: OffMeshConnectionParams[] = [], area = 0, flags = 1) {\n return new (GetRecast().TileCacheMeshProcess)((navMeshCreateParams: NavMeshCreateParams, polyAreas: UnsignedCharArray, polyFlags: UnsignedShortArray) => {\n for (let i = 0; i < navMeshCreateParams.polyCount(); ++i) {\n polyAreas.set(i, area);\n polyFlags.set(i, flags);\n }\n\n if (offMeshConnections.length > 0) {\n navMeshCreateParams.setOffMeshConnections(offMeshConnections);\n }\n });\n}\n\n/**\n * Waits until the tile cache is fully updated\n * @param navMesh The NavMesh\n * @param tileCache THe TileCache\n */\nexport function WaitForFullTileCacheUpdate(navMesh: NavMesh, tileCache: TileCache) {\n let upToDate = false;\n while (!upToDate) {\n const result = tileCache.update(navMesh);\n upToDate = result.upToDate;\n }\n}\n"]}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { IVector3Like } from "@onerjs/core/Maths/math.like.js";
|
|
2
|
+
import { Vector3 } from "@onerjs/core/Maths/math.vector.js";
|
|
3
|
+
/**
|
|
4
|
+
* Utility function based on Chaikin's alogrithm for navigation path smoothing and segment generation.
|
|
5
|
+
* @param points Array of points to be smoothed, where each point is an object with x, y, and z properties.
|
|
6
|
+
* @param iterations Number of smoothing iterations to apply. Default 1.
|
|
7
|
+
* @returns A new array of smoothed points after applying the Chaikin's algorithm.
|
|
8
|
+
*/
|
|
9
|
+
export declare function GetChaikinSmoothPath(points: IVector3Like[], iterations?: number): IVector3Like[];
|
|
10
|
+
/**
|
|
11
|
+
* Generates a series of points that create an L-shaped path between each pair of points in the input navigation segment.
|
|
12
|
+
* The path consists of a horizontal segment followed by a vertical segment, or vice versa,
|
|
13
|
+
* depending on the relative distances between the x and z coordinates of the points.
|
|
14
|
+
* @param navSegment An array of Vector3 points representing the navigation segment.
|
|
15
|
+
* @returns An array of Vector3 points representing the L-shaped path.
|
|
16
|
+
*/
|
|
17
|
+
export declare function GetLShapedPath(navSegment: Vector3[]): Vector3[];
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { Vector3 } from "@onerjs/core/Maths/math.vector.js";
|
|
2
|
+
/**
|
|
3
|
+
* Utility function based on Chaikin's alogrithm for navigation path smoothing and segment generation.
|
|
4
|
+
* @param points Array of points to be smoothed, where each point is an object with x, y, and z properties.
|
|
5
|
+
* @param iterations Number of smoothing iterations to apply. Default 1.
|
|
6
|
+
* @returns A new array of smoothed points after applying the Chaikin's algorithm.
|
|
7
|
+
*/
|
|
8
|
+
export function GetChaikinSmoothPath(points, iterations = 1) {
|
|
9
|
+
for (let i = 0; i < iterations; i++) {
|
|
10
|
+
const smoothed = [];
|
|
11
|
+
for (let j = 0; j < points.length - 1; j++) {
|
|
12
|
+
const p0 = points[j];
|
|
13
|
+
const p1 = points[j + 1];
|
|
14
|
+
smoothed.push({
|
|
15
|
+
x: 0.75 * p0.x + 0.25 * p1.x,
|
|
16
|
+
y: 0.75 * p0.y + 0.25 * p1.y,
|
|
17
|
+
z: 0.75 * p0.z + 0.25 * p1.z,
|
|
18
|
+
});
|
|
19
|
+
smoothed.push({
|
|
20
|
+
x: 0.25 * p0.x + 0.75 * p1.x,
|
|
21
|
+
y: 0.25 * p0.y + 0.75 * p1.y,
|
|
22
|
+
z: 0.25 * p0.z + 0.75 * p1.z,
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
if (points[0].x === points[points.length - 1].x && points[0].y === points[points.length - 1].y && points[0].z === points[points.length - 1].z) {
|
|
26
|
+
smoothed.push(smoothed[0]);
|
|
27
|
+
}
|
|
28
|
+
points = smoothed;
|
|
29
|
+
}
|
|
30
|
+
return points;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Generates a series of points that create an L-shaped path between each pair of points in the input navigation segment.
|
|
34
|
+
* The path consists of a horizontal segment followed by a vertical segment, or vice versa,
|
|
35
|
+
* depending on the relative distances between the x and z coordinates of the points.
|
|
36
|
+
* @param navSegment An array of Vector3 points representing the navigation segment.
|
|
37
|
+
* @returns An array of Vector3 points representing the L-shaped path.
|
|
38
|
+
*/
|
|
39
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
40
|
+
export function GetLShapedPath(navSegment) {
|
|
41
|
+
const points = [];
|
|
42
|
+
for (let j = 0; j < navSegment.length - 1; j++) {
|
|
43
|
+
const p0 = navSegment[j];
|
|
44
|
+
const p1 = navSegment[j + 1];
|
|
45
|
+
const p01 = getLShapedPoint(p0, p1);
|
|
46
|
+
points.push(p0, new Vector3(p01.x, p1.y, p01.z), p1);
|
|
47
|
+
}
|
|
48
|
+
return points;
|
|
49
|
+
}
|
|
50
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
51
|
+
function getLShapedPoint(pointA, pointB) {
|
|
52
|
+
const { x: x1, z: y1 } = pointA;
|
|
53
|
+
const { x: x2, z: y2 } = pointB;
|
|
54
|
+
let pointC;
|
|
55
|
+
// Determine turn direction automatically based on the offset
|
|
56
|
+
if (Math.abs(x2 - x1) >= Math.abs(y2 - y1)) {
|
|
57
|
+
// Horizontal-then-vertical turn
|
|
58
|
+
pointC = { x: x2, z: y1 };
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
// Vertical-then-horizontal turn
|
|
62
|
+
pointC = { x: x1, z: y2 };
|
|
63
|
+
}
|
|
64
|
+
return pointC;
|
|
65
|
+
}
|
|
66
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"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AAE,EAAE,CAAC,EAAE,EAAE,EAAE,GAAG,MAAM,CAAC;IAEhC,IAAI,MAAM,CAAC;IAEX,6DAA6D;IAC7D,IAAI,IAAI,CAAC,GAAG,CAAC,EAAE,GAAG,EAAE,CAAC,IAAI,IAAI,CAAC,GAAG,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,CAAC;QACzC,gCAAgC;QAChC,MAAM,GAAG,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC;IAC9B,CAAC;SAAM,CAAC;QACJ,gCAAgC;QAChC,MAAM,GAAG,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC;IAC9B,CAAC;IAED,OAAO,MAAM,CAAC;AAClB,CAAC","sourcesContent":["import type { IVector3Like } from \"core/Maths/math.like\";\nimport { Vector3 } from \"core/Maths/math.vector\";\n\n/**\n * Utility function based on Chaikin's alogrithm for navigation path smoothing and segment generation.\n * @param points Array of points to be smoothed, where each point is an object with x, y, and z properties.\n * @param iterations Number of smoothing iterations to apply. Default 1.\n * @returns A new array of smoothed points after applying the Chaikin's algorithm.\n */\nexport function GetChaikinSmoothPath(points: IVector3Like[], iterations = 1) {\n for (let i = 0; i < iterations; i++) {\n const smoothed = [];\n for (let j = 0; j < points.length - 1; j++) {\n const p0 = points[j];\n const p1 = points[j + 1];\n\n smoothed.push({\n x: 0.75 * p0.x + 0.25 * p1.x,\n y: 0.75 * p0.y + 0.25 * p1.y,\n z: 0.75 * p0.z + 0.25 * p1.z,\n });\n\n smoothed.push({\n x: 0.25 * p0.x + 0.75 * p1.x,\n y: 0.25 * p0.y + 0.75 * p1.y,\n z: 0.25 * p0.z + 0.75 * p1.z,\n });\n }\n\n if (points[0].x === points[points.length - 1].x && points[0].y === points[points.length - 1].y && points[0].z === points[points.length - 1].z) {\n smoothed.push(smoothed[0]);\n }\n\n points = smoothed;\n }\n return points;\n}\n\n/**\n * Generates a series of points that create an L-shaped path between each pair of points in the input navigation segment.\n * The path consists of a horizontal segment followed by a vertical segment, or vice versa,\n * depending on the relative distances between the x and z coordinates of the points.\n * @param navSegment An array of Vector3 points representing the navigation segment.\n * @returns An array of Vector3 points representing the L-shaped path.\n */\n// eslint-disable-next-line @typescript-eslint/naming-convention\nexport function GetLShapedPath(navSegment: Vector3[]) {\n const points = [];\n for (let j = 0; j < navSegment.length - 1; j++) {\n const p0 = navSegment[j];\n const p1 = navSegment[j + 1];\n const p01 = getLShapedPoint(p0, p1);\n points.push(p0, new Vector3(p01.x, p1.y, p01.z), p1);\n }\n return points;\n}\n\n// eslint-disable-next-line @typescript-eslint/naming-convention\nfunction getLShapedPoint(pointA: IVector3Like, pointB: IVector3Like) {\n const { x: x1, z: y1 } = pointA;\n const { x: x2, z: y2 } = pointB;\n\n let pointC;\n\n // Determine turn direction automatically based on the offset\n if (Math.abs(x2 - x1) >= Math.abs(y2 - y1)) {\n // Horizontal-then-vertical turn\n pointC = { x: x2, z: y1 };\n } else {\n // Vertical-then-horizontal turn\n pointC = { x: x1, z: y2 };\n }\n\n return pointC;\n}\n"]}
|