@onerjs/addons 8.27.1 → 8.27.3
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/msdfText/paragraphOptions.d.ts +15 -0
- package/msdfText/paragraphOptions.js.map +1 -1
- package/msdfText/sdf/paragraph.js +1 -1
- package/msdfText/sdf/paragraph.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.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 +1 -0
- package/navigation/factory/index.js +3 -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 +419 -0
- package/navigation/plugin/RecastNavigationJSPlugin.js +482 -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,587 @@
|
|
|
1
|
+
import { StandardMaterial } from "@onerjs/core/Materials/standardMaterial.js";
|
|
2
|
+
import { Color3 } from "@onerjs/core/Maths/math.color.js";
|
|
3
|
+
import { Matrix } from "@onerjs/core/Maths/math.vector.js";
|
|
4
|
+
import { CreateGreasedLine } from "@onerjs/core/Meshes/Builders/greasedLineBuilder.js";
|
|
5
|
+
import { Mesh } from "@onerjs/core/Meshes/mesh.js";
|
|
6
|
+
import { VertexData } from "@onerjs/core/Meshes/mesh.vertexData.js";
|
|
7
|
+
import { TransformNode } from "@onerjs/core/Meshes/transformNode.js";
|
|
8
|
+
import { CreateBox } from "@onerjs/core/Meshes/Builders/boxBuilder.js";
|
|
9
|
+
import { Logger } from "@onerjs/core/Misc/logger.js";
|
|
10
|
+
import { GetRecast } from "../factory/common.js";
|
|
11
|
+
// TODO: Enum?
|
|
12
|
+
export const DebugLayerOption = {
|
|
13
|
+
HEIGHTFIELD_SOLID: "heightfield solid",
|
|
14
|
+
HEIGHTFIELD_WALKABLE: "heightfield walkable",
|
|
15
|
+
COMPACT_HEIGHTFIELD_SOLID: "compact heightfield solid",
|
|
16
|
+
COMPACT_HEIGHTFIELD_REGIONS: "compact heightfield regions",
|
|
17
|
+
COMPACT_HEIGHTFIELD_DISTANCE: "compact heightfield distance",
|
|
18
|
+
RAW_CONTOURS: "raw contours",
|
|
19
|
+
CONTOURS: "contours",
|
|
20
|
+
POLY_MESH: "poly mesh",
|
|
21
|
+
POLY_MESH_DETAIL: "poly mesh detail",
|
|
22
|
+
NAVMESH: "navmesh",
|
|
23
|
+
NAVMESH_BV_TREE: "navmesh bv tree",
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* NavigationDebugger is a utility class for visualizing navigation meshes and related data in a Babylon.js scene.
|
|
27
|
+
* It provides methods to draw various navigation-related primitives such as points, lines, triangles, and quads.
|
|
28
|
+
* It also supports drawing heightfields, compact heightfields, contours, poly meshes, and nav meshes.
|
|
29
|
+
*/
|
|
30
|
+
export class NavigationDebugger {
|
|
31
|
+
/**
|
|
32
|
+
* * Gets or sets the primitive types to be drawn by the debug drawer.
|
|
33
|
+
* * This allows you to control which types of primitives (points, lines, tris, quads) are rendered in the navigation debug visualization.
|
|
34
|
+
* * The default value is `["points", "lines", "tris", "quads"]`.
|
|
35
|
+
* * You can modify this property to include or exclude specific primitive types based on your debugging needs.
|
|
36
|
+
* @returns An array of primitive types that the debug drawer will render.
|
|
37
|
+
*/
|
|
38
|
+
get primitiveTypes() {
|
|
39
|
+
return this._primitiveTypes;
|
|
40
|
+
}
|
|
41
|
+
set primitiveTypes(value) {
|
|
42
|
+
this._primitiveTypes = value;
|
|
43
|
+
}
|
|
44
|
+
constructor(_scene, options) {
|
|
45
|
+
this._scene = _scene;
|
|
46
|
+
/**
|
|
47
|
+
* The list of line materials used in the navigation debug visualization.
|
|
48
|
+
*/
|
|
49
|
+
this.lineMaterials = [];
|
|
50
|
+
/**
|
|
51
|
+
* Get the intermediates from the generator
|
|
52
|
+
* @param intermediates - The generator intermediates
|
|
53
|
+
* @returns An object containing lists of heightfields, compact heightfields, contour sets
|
|
54
|
+
*/
|
|
55
|
+
this.getIntermediates = (intermediates) => {
|
|
56
|
+
const heightfieldList = [];
|
|
57
|
+
const compactHeightfieldList = [];
|
|
58
|
+
const contourSetList = [];
|
|
59
|
+
const polyMeshList = [];
|
|
60
|
+
const polyMeshDetailList = [];
|
|
61
|
+
if (intermediates) {
|
|
62
|
+
if (intermediates.type === "solo") {
|
|
63
|
+
if (intermediates.heightfield) {
|
|
64
|
+
heightfieldList.push(intermediates.heightfield);
|
|
65
|
+
}
|
|
66
|
+
if (intermediates.compactHeightfield) {
|
|
67
|
+
compactHeightfieldList.push(intermediates.compactHeightfield);
|
|
68
|
+
}
|
|
69
|
+
if (intermediates.contourSet) {
|
|
70
|
+
contourSetList.push(intermediates.contourSet);
|
|
71
|
+
}
|
|
72
|
+
if (intermediates.polyMesh) {
|
|
73
|
+
polyMeshList.push(intermediates.polyMesh);
|
|
74
|
+
}
|
|
75
|
+
if (intermediates.polyMeshDetail) {
|
|
76
|
+
polyMeshDetailList.push(intermediates.polyMeshDetail);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
else if (intermediates.type === "tiled") {
|
|
80
|
+
for (const tile of intermediates.tileIntermediates) {
|
|
81
|
+
if (tile.heightfield) {
|
|
82
|
+
heightfieldList.push(tile.heightfield);
|
|
83
|
+
}
|
|
84
|
+
if (tile.compactHeightfield) {
|
|
85
|
+
compactHeightfieldList.push(tile.compactHeightfield);
|
|
86
|
+
}
|
|
87
|
+
if (tile.contourSet) {
|
|
88
|
+
contourSetList.push(tile.contourSet);
|
|
89
|
+
}
|
|
90
|
+
if (tile.polyMesh) {
|
|
91
|
+
polyMeshList.push(tile.polyMesh);
|
|
92
|
+
}
|
|
93
|
+
if (tile.polyMeshDetail) {
|
|
94
|
+
polyMeshDetailList.push(tile.polyMeshDetail);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
else if (intermediates.type === "tilecache") {
|
|
99
|
+
for (const tile of intermediates.tileIntermediates) {
|
|
100
|
+
if (tile.heightfield) {
|
|
101
|
+
heightfieldList.push(tile.heightfield);
|
|
102
|
+
}
|
|
103
|
+
if (tile.compactHeightfield) {
|
|
104
|
+
compactHeightfieldList.push(tile.compactHeightfield);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
return {
|
|
110
|
+
heightfieldList,
|
|
111
|
+
compactHeightfieldList,
|
|
112
|
+
contourSetList,
|
|
113
|
+
polyMeshList,
|
|
114
|
+
polyMeshDetailList,
|
|
115
|
+
};
|
|
116
|
+
};
|
|
117
|
+
this._debugDrawerUtils = new (GetRecast().DebugDrawerUtils)();
|
|
118
|
+
this._primitiveTypes = options?.primitiveTypes ?? ["points", "lines", "tris", "quads"];
|
|
119
|
+
this.debugDrawerParentNode =
|
|
120
|
+
options?.parent?.node instanceof TransformNode ? options.parent.node : new TransformNode(options?.parent?.node ?? "nav-mesh-debug-parent", this._scene);
|
|
121
|
+
const materials = options?.materials;
|
|
122
|
+
if (materials?.triMaterial) {
|
|
123
|
+
this.triMaterial = materials.triMaterial;
|
|
124
|
+
}
|
|
125
|
+
else {
|
|
126
|
+
this.triMaterial = new StandardMaterial("nav-debug-tris-material");
|
|
127
|
+
this.triMaterial.backFaceCulling = false;
|
|
128
|
+
this.triMaterial.specularColor = Color3.Black();
|
|
129
|
+
this.triMaterial.alpha = 0.5;
|
|
130
|
+
}
|
|
131
|
+
if (materials?.pointMaterial) {
|
|
132
|
+
this.pointMaterial = materials.pointMaterial;
|
|
133
|
+
}
|
|
134
|
+
else {
|
|
135
|
+
this.pointMaterial = new StandardMaterial("nav-debug-points-material");
|
|
136
|
+
this.pointMaterial.backFaceCulling = false;
|
|
137
|
+
this.pointMaterial.specularColor = Color3.Black();
|
|
138
|
+
}
|
|
139
|
+
if (materials?.lineMaterialOptions) {
|
|
140
|
+
this._lineMaterialOptions = materials.lineMaterialOptions;
|
|
141
|
+
}
|
|
142
|
+
else {
|
|
143
|
+
this._lineMaterialOptions = {
|
|
144
|
+
greasedLineMaterialOptions: {
|
|
145
|
+
width: 2,
|
|
146
|
+
sizeAttenuation: true,
|
|
147
|
+
},
|
|
148
|
+
greasedLineMeshOptions: {},
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
this._pointMesh = CreateBox(NavigationDebugger.NAV_MESH_DEBUG_NAME_POINTS, { size: 0.02 });
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Resets the debug drawer by disposing of all child meshes in the debug drawer parent node.
|
|
155
|
+
* This is useful for clearing the debug visualization before drawing new primitives.
|
|
156
|
+
*/
|
|
157
|
+
clear() {
|
|
158
|
+
for (const child of this.debugDrawerParentNode.getChildMeshes()) {
|
|
159
|
+
child.dispose();
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Disposes of the debug drawer, including all meshes and materials used for rendering.
|
|
164
|
+
* This method should be called when the debug drawer is no longer needed to free up resources.
|
|
165
|
+
*/
|
|
166
|
+
dispose() {
|
|
167
|
+
this.clear();
|
|
168
|
+
this._debugDrawerUtils.dispose();
|
|
169
|
+
this._pointMesh.dispose();
|
|
170
|
+
this.triMaterial.dispose();
|
|
171
|
+
this.pointMaterial.dispose();
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* This method iterates through the provided primitives and draws them based on their type.
|
|
175
|
+
* It supports drawing points, lines, triangles, and quads, depending on the primitive type.
|
|
176
|
+
* @param primitives An array of debug drawer primitives to be drawn.
|
|
177
|
+
* @param options Optional parameters to control the drawing behavior, such as whether to join meshes.
|
|
178
|
+
*/
|
|
179
|
+
drawPrimitives(primitives, options) {
|
|
180
|
+
let linesInstance = null;
|
|
181
|
+
for (const primitive of primitives) {
|
|
182
|
+
// draw only the primitives that are in the primitiveTypes array
|
|
183
|
+
if (!this._primitiveTypes.includes(primitive.type)) {
|
|
184
|
+
continue;
|
|
185
|
+
}
|
|
186
|
+
switch (primitive.type) {
|
|
187
|
+
case "points":
|
|
188
|
+
this._drawPoints(primitive);
|
|
189
|
+
break;
|
|
190
|
+
case "lines": {
|
|
191
|
+
const line = this._drawLines(primitive, linesInstance);
|
|
192
|
+
if (!linesInstance) {
|
|
193
|
+
linesInstance = line;
|
|
194
|
+
}
|
|
195
|
+
break;
|
|
196
|
+
}
|
|
197
|
+
case "tris":
|
|
198
|
+
this._drawTris(primitive);
|
|
199
|
+
break;
|
|
200
|
+
case "quads":
|
|
201
|
+
this._drawQuads(primitive);
|
|
202
|
+
break;
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
linesInstance?.updateLazy();
|
|
206
|
+
if (options?.joinMeshes ?? true) {
|
|
207
|
+
// Join the debug meshes into a single mesh for better performance
|
|
208
|
+
this._joinDebugMeshes();
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
/**
|
|
212
|
+
* Draws a heightfield as solid using the debug drawer utilities.
|
|
213
|
+
* @param hf The heightfield to draw as solid.
|
|
214
|
+
*/
|
|
215
|
+
drawHeightfieldSolid(hf) {
|
|
216
|
+
const primitives = this._debugDrawerUtils.drawHeightfieldSolid(hf);
|
|
217
|
+
this.drawPrimitives(primitives);
|
|
218
|
+
}
|
|
219
|
+
/**
|
|
220
|
+
* Draws a heightfield as walkable using the debug drawer utilities.
|
|
221
|
+
* @param hf The heightfield to draw as walkable.
|
|
222
|
+
*/
|
|
223
|
+
drawHeightfieldWalkable(hf) {
|
|
224
|
+
const primitives = this._debugDrawerUtils.drawHeightfieldWalkable(hf);
|
|
225
|
+
this.drawPrimitives(primitives);
|
|
226
|
+
}
|
|
227
|
+
/**
|
|
228
|
+
* Draws a compact heightfield as solid using the debug drawer utilities.
|
|
229
|
+
* @param chf The compact heightfield to draw as solid.
|
|
230
|
+
*/
|
|
231
|
+
drawCompactHeightfieldSolid(chf) {
|
|
232
|
+
const primitives = this._debugDrawerUtils.drawCompactHeightfieldSolid(chf);
|
|
233
|
+
this.drawPrimitives(primitives);
|
|
234
|
+
}
|
|
235
|
+
/**
|
|
236
|
+
* Draws the regions of a compact heightfield using the debug drawer utilities.
|
|
237
|
+
* @param chf The compact heightfield to draw regions for.
|
|
238
|
+
*/
|
|
239
|
+
drawCompactHeightfieldRegions(chf) {
|
|
240
|
+
const primitives = this._debugDrawerUtils.drawCompactHeightfieldRegions(chf);
|
|
241
|
+
this.drawPrimitives(primitives);
|
|
242
|
+
}
|
|
243
|
+
/**
|
|
244
|
+
* Draws the distance field of a compact heightfield using the debug drawer utilities.
|
|
245
|
+
* @param chf The compact heightfield to draw the distance for.
|
|
246
|
+
*/
|
|
247
|
+
drawCompactHeightfieldDistance(chf) {
|
|
248
|
+
const primitives = this._debugDrawerUtils.drawCompactHeightfieldDistance(chf);
|
|
249
|
+
this.drawPrimitives(primitives);
|
|
250
|
+
}
|
|
251
|
+
/**
|
|
252
|
+
* Draws a heightfield layer using the debug drawer utilities.
|
|
253
|
+
* @param layer The heightfield layer to draw.
|
|
254
|
+
* @param idx The index of the layer to draw.
|
|
255
|
+
*/
|
|
256
|
+
drawHeightfieldLayer(layer, idx) {
|
|
257
|
+
const primitives = this._debugDrawerUtils.drawHeightfieldLayer(layer, idx);
|
|
258
|
+
this.drawPrimitives(primitives);
|
|
259
|
+
}
|
|
260
|
+
/**
|
|
261
|
+
* Draws the layers of a heightfield using the debug drawer utilities.
|
|
262
|
+
* @param lset The heightfield layer set containing the layers to draw.
|
|
263
|
+
*/
|
|
264
|
+
drawHeightfieldLayers(lset) {
|
|
265
|
+
const primitives = this._debugDrawerUtils.drawHeightfieldLayers(lset);
|
|
266
|
+
this.drawPrimitives(primitives);
|
|
267
|
+
}
|
|
268
|
+
/**
|
|
269
|
+
* Draws the region connections of a RecastContourSet using the debug drawer utilities.
|
|
270
|
+
* @param cset RecastContourSet to draw
|
|
271
|
+
* @param alpha The alpha value for the drawn contours, default is 1.
|
|
272
|
+
*/
|
|
273
|
+
drawRegionConnections(cset, alpha = 1) {
|
|
274
|
+
const primitives = this._debugDrawerUtils.drawRegionConnections(cset, alpha);
|
|
275
|
+
this.drawPrimitives(primitives);
|
|
276
|
+
}
|
|
277
|
+
/**
|
|
278
|
+
* Draws raw contours from a RecastContourSet using the debug drawer utilities.
|
|
279
|
+
* @param cset RecastContourSet to draw
|
|
280
|
+
* @param alpha The alpha value for the drawn contours, default is 1.
|
|
281
|
+
*/
|
|
282
|
+
drawRawContours(cset, alpha = 1) {
|
|
283
|
+
const primitives = this._debugDrawerUtils.drawRawContours(cset, alpha);
|
|
284
|
+
this.drawPrimitives(primitives);
|
|
285
|
+
}
|
|
286
|
+
/**
|
|
287
|
+
* Draws contours from a RecastContourSet using the debug drawer utilities.
|
|
288
|
+
* @param cset RecastContourSet to draw
|
|
289
|
+
* @param alpha The alpha value for the drawn contours, default is 1.
|
|
290
|
+
*/
|
|
291
|
+
drawContours(cset, alpha = 1) {
|
|
292
|
+
const primitives = this._debugDrawerUtils.drawContours(cset, alpha);
|
|
293
|
+
this.drawPrimitives(primitives);
|
|
294
|
+
}
|
|
295
|
+
/**
|
|
296
|
+
* Draws a poly mesh using the debug drawer utilities.
|
|
297
|
+
* @param mesh RecastPolyMesh to draw
|
|
298
|
+
*/
|
|
299
|
+
drawPolyMesh(mesh) {
|
|
300
|
+
const primitives = this._debugDrawerUtils.drawPolyMesh(mesh);
|
|
301
|
+
this.drawPrimitives(primitives);
|
|
302
|
+
}
|
|
303
|
+
/**
|
|
304
|
+
* Draws a poly mesh detail using the debug drawer utilities.
|
|
305
|
+
* @param dmesh RecastPolyMeshDetail to draw
|
|
306
|
+
*/
|
|
307
|
+
drawPolyMeshDetail(dmesh) {
|
|
308
|
+
const primitives = this._debugDrawerUtils.drawPolyMeshDetail(dmesh);
|
|
309
|
+
this.drawPrimitives(primitives);
|
|
310
|
+
}
|
|
311
|
+
/**
|
|
312
|
+
* Draws a NavMesh using the debug drawer utilities.
|
|
313
|
+
* @param mesh NavMesh to draw
|
|
314
|
+
* @param flags Flags to control the drawing behavior, default is 0.
|
|
315
|
+
*/
|
|
316
|
+
drawNavMesh(mesh, flags = 0) {
|
|
317
|
+
const primitives = this._debugDrawerUtils.drawNavMesh(mesh, flags);
|
|
318
|
+
this.drawPrimitives(primitives);
|
|
319
|
+
}
|
|
320
|
+
// todo:
|
|
321
|
+
// - drawTileCacheLayerAreas
|
|
322
|
+
// - drawTileCacheLayerRegions
|
|
323
|
+
// - drawTileCacheContours
|
|
324
|
+
// - drawTileCachePolyMesh
|
|
325
|
+
/**
|
|
326
|
+
* Draws a NavMesh with closed list using the debug drawer utilities.
|
|
327
|
+
* @param mesh NavMesh to draw
|
|
328
|
+
* @param query NavMeshQuery to use for drawing the closed list.
|
|
329
|
+
* @param flags Flags to control the drawing behavior, default is 0.
|
|
330
|
+
*/
|
|
331
|
+
drawNavMeshWithClosedList(mesh, query, flags = 0) {
|
|
332
|
+
const primitives = this._debugDrawerUtils.drawNavMeshWithClosedList(mesh, query, flags);
|
|
333
|
+
this.drawPrimitives(primitives);
|
|
334
|
+
}
|
|
335
|
+
/**
|
|
336
|
+
* Draws the nodes of a NavMesh using the debug drawer utilities.
|
|
337
|
+
* @param query NavMeshQuery to use for drawing the nodes.
|
|
338
|
+
*/
|
|
339
|
+
drawNavMeshNodes(query) {
|
|
340
|
+
const primitives = this._debugDrawerUtils.drawNavMeshNodes(query);
|
|
341
|
+
this.drawPrimitives(primitives);
|
|
342
|
+
}
|
|
343
|
+
/**
|
|
344
|
+
* Draws the bounding volume tree of a NavMesh using the debug drawer utilities.
|
|
345
|
+
* @param mesh NavMesh to draw the bounding volume tree for.
|
|
346
|
+
*/
|
|
347
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
348
|
+
drawNavMeshBVTree(mesh) {
|
|
349
|
+
const primitives = this._debugDrawerUtils.drawNavMeshBVTree(mesh);
|
|
350
|
+
this.drawPrimitives(primitives);
|
|
351
|
+
}
|
|
352
|
+
/**
|
|
353
|
+
* Draws the portals of a NavMesh using the debug drawer utilities.
|
|
354
|
+
* @param mesh NavMesh to draw the portals for.
|
|
355
|
+
*/
|
|
356
|
+
drawNavMeshPortals(mesh) {
|
|
357
|
+
const primitives = this._debugDrawerUtils.drawNavMeshPortals(mesh);
|
|
358
|
+
this.drawPrimitives(primitives);
|
|
359
|
+
}
|
|
360
|
+
/**
|
|
361
|
+
* Draws polygons of a NavMesh with specific flags using the debug drawer utilities.
|
|
362
|
+
* @param mesh NavMesh to draw the polygons with specific flags.
|
|
363
|
+
* @param flags The flags to filter the polygons to be drawn.
|
|
364
|
+
* @param col The color to use for the drawn polygons, represented as a number.
|
|
365
|
+
*/
|
|
366
|
+
drawNavMeshPolysWithFlags(mesh, flags, col) {
|
|
367
|
+
const primitives = this._debugDrawerUtils.drawNavMeshPolysWithFlags(mesh, flags, col);
|
|
368
|
+
this.drawPrimitives(primitives);
|
|
369
|
+
}
|
|
370
|
+
/**
|
|
371
|
+
* Draws polygons of a NavMesh with specific reference and color using the debug drawer utilities.
|
|
372
|
+
* @param mesh NavMesh to draw the polygons with specific reference and color.
|
|
373
|
+
* @param ref The reference number of the polygons to be drawn.
|
|
374
|
+
* @param col The color to use for the drawn polygons, represented as a number.
|
|
375
|
+
*/
|
|
376
|
+
drawNavMeshPoly(mesh, ref, col) {
|
|
377
|
+
const primitives = this._debugDrawerUtils.drawNavMeshPoly(mesh, ref, col);
|
|
378
|
+
this.drawPrimitives(primitives);
|
|
379
|
+
}
|
|
380
|
+
/**
|
|
381
|
+
* Draw debug information based on the selected option
|
|
382
|
+
* @param navMesh - The navigation mesh to draw
|
|
383
|
+
* @param intermediates - The generator intermediates containing the data to draw
|
|
384
|
+
* @param scene - The scene to draw in
|
|
385
|
+
* @param option - The debug drawer option to use
|
|
386
|
+
* @remarks This method will reset the debug drawer before drawing.
|
|
387
|
+
*/
|
|
388
|
+
draw(navMesh, intermediates, scene, option) {
|
|
389
|
+
this.clear();
|
|
390
|
+
const { heightfieldList, compactHeightfieldList, contourSetList, polyMeshList, polyMeshDetailList } = this.getIntermediates(intermediates);
|
|
391
|
+
if (option === DebugLayerOption.HEIGHTFIELD_SOLID) {
|
|
392
|
+
for (const heightfield of heightfieldList) {
|
|
393
|
+
this.drawHeightfieldSolid(heightfield);
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
else if (option === DebugLayerOption.HEIGHTFIELD_WALKABLE) {
|
|
397
|
+
for (const heightfield of heightfieldList) {
|
|
398
|
+
this.drawHeightfieldWalkable(heightfield);
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
else if (option === DebugLayerOption.COMPACT_HEIGHTFIELD_SOLID) {
|
|
402
|
+
for (const compactHeightfield of compactHeightfieldList) {
|
|
403
|
+
this.drawCompactHeightfieldSolid(compactHeightfield);
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
else if (option === DebugLayerOption.COMPACT_HEIGHTFIELD_REGIONS) {
|
|
407
|
+
for (const compactHeightfield of compactHeightfieldList) {
|
|
408
|
+
this.drawCompactHeightfieldRegions(compactHeightfield);
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
else if (option === DebugLayerOption.COMPACT_HEIGHTFIELD_DISTANCE) {
|
|
412
|
+
for (const compactHeightfield of compactHeightfieldList) {
|
|
413
|
+
this.drawCompactHeightfieldDistance(compactHeightfield);
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
else if (option === DebugLayerOption.RAW_CONTOURS) {
|
|
417
|
+
for (const contourSet of contourSetList) {
|
|
418
|
+
this.drawRawContours(contourSet);
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
else if (option === DebugLayerOption.CONTOURS) {
|
|
422
|
+
for (const contourSet of contourSetList) {
|
|
423
|
+
this.drawContours(contourSet);
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
else if (option === DebugLayerOption.POLY_MESH) {
|
|
427
|
+
for (const polyMesh of polyMeshList) {
|
|
428
|
+
this.drawPolyMesh(polyMesh);
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
else if (option === DebugLayerOption.POLY_MESH_DETAIL) {
|
|
432
|
+
for (const polyMeshDetail of polyMeshDetailList) {
|
|
433
|
+
this.drawPolyMeshDetail(polyMeshDetail);
|
|
434
|
+
}
|
|
435
|
+
}
|
|
436
|
+
else if (option === DebugLayerOption.NAVMESH) {
|
|
437
|
+
this.drawNavMesh(navMesh);
|
|
438
|
+
}
|
|
439
|
+
else if (option === DebugLayerOption.NAVMESH_BV_TREE) {
|
|
440
|
+
this.drawNavMeshBVTree(navMesh);
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
_drawPoints(primitive) {
|
|
444
|
+
if (primitive.vertices.length === 0) {
|
|
445
|
+
return;
|
|
446
|
+
}
|
|
447
|
+
const matricesData = new Float32Array(16 * primitive.vertices.length);
|
|
448
|
+
const colorData = new Float32Array(4 * primitive.vertices.length);
|
|
449
|
+
for (let i = 0; i < primitive.vertices.length; i++) {
|
|
450
|
+
const [x, y, z, r, g, b, a] = primitive.vertices[i];
|
|
451
|
+
colorData[i * 4] = r;
|
|
452
|
+
colorData[i * 4 + 1] = g;
|
|
453
|
+
colorData[i * 4 + 2] = b;
|
|
454
|
+
colorData[i * 4 + 3] = a;
|
|
455
|
+
const matrix = Matrix.Translation(x, y, z);
|
|
456
|
+
matrix.copyToArray(matricesData, i * 16);
|
|
457
|
+
}
|
|
458
|
+
this._pointMesh.thinInstanceSetBuffer("matrix", matricesData, 16);
|
|
459
|
+
this._pointMesh.thinInstanceSetBuffer("color", colorData, 4);
|
|
460
|
+
this._pointMesh.parent = this.debugDrawerParentNode;
|
|
461
|
+
}
|
|
462
|
+
_drawLines(primitive, instance) {
|
|
463
|
+
if (primitive.vertices.length === 0) {
|
|
464
|
+
return null;
|
|
465
|
+
}
|
|
466
|
+
const points = [];
|
|
467
|
+
const colors = [];
|
|
468
|
+
for (let i = 0; i < primitive.vertices.length; i += 2) {
|
|
469
|
+
const [x1, y1, z1, r1, g1, b1] = primitive.vertices[i];
|
|
470
|
+
const [x2, y2, z2, r2, g2, b2] = primitive.vertices[i + 1];
|
|
471
|
+
points.push([x1, y1, z1, x2, y2, z2]);
|
|
472
|
+
colors.push(new Color3(r1, g1, b1));
|
|
473
|
+
colors.push(new Color3(r2, g2, b2));
|
|
474
|
+
}
|
|
475
|
+
const options = { ...this._lineMaterialOptions.greasedLineMeshOptions, points, instance: instance ?? undefined };
|
|
476
|
+
const materialOptions = { ...this._lineMaterialOptions.greasedLineMaterialOptions, colors };
|
|
477
|
+
const lines = CreateGreasedLine(NavigationDebugger.NAV_MESH_DEBUG_NAME_LINES, options, materialOptions);
|
|
478
|
+
lines.parent = this.debugDrawerParentNode;
|
|
479
|
+
this.lineMaterials.push(lines.material);
|
|
480
|
+
return lines;
|
|
481
|
+
}
|
|
482
|
+
_drawTris(primitive) {
|
|
483
|
+
if (primitive.vertices.length === 0) {
|
|
484
|
+
return;
|
|
485
|
+
}
|
|
486
|
+
const positions = new Float32Array(primitive.vertices.length * 3);
|
|
487
|
+
const colors = new Float32Array(primitive.vertices.length * 4);
|
|
488
|
+
for (let i = 0; i < primitive.vertices.length; i++) {
|
|
489
|
+
const [x, y, z, r, g, b] = primitive.vertices[i];
|
|
490
|
+
positions[i * 3 + 0] = x;
|
|
491
|
+
positions[i * 3 + 1] = y;
|
|
492
|
+
positions[i * 3 + 2] = z;
|
|
493
|
+
colors[i * 4 + 0] = r;
|
|
494
|
+
colors[i * 4 + 1] = g;
|
|
495
|
+
colors[i * 4 + 2] = b;
|
|
496
|
+
colors[i * 4 + 3] = 1;
|
|
497
|
+
}
|
|
498
|
+
const vertexData = new VertexData();
|
|
499
|
+
vertexData.positions = positions;
|
|
500
|
+
vertexData.colors = colors;
|
|
501
|
+
const customMesh = new Mesh(NavigationDebugger.NAV_MESH_DEBUG_NAME_TRIS);
|
|
502
|
+
customMesh.isUnIndexed = true;
|
|
503
|
+
vertexData.applyToMesh(customMesh);
|
|
504
|
+
customMesh.material = this.triMaterial;
|
|
505
|
+
customMesh.parent = this.debugDrawerParentNode;
|
|
506
|
+
}
|
|
507
|
+
_drawQuads(primitive) {
|
|
508
|
+
if (primitive.vertices.length === 0) {
|
|
509
|
+
return;
|
|
510
|
+
}
|
|
511
|
+
const positions = [];
|
|
512
|
+
const colors = [];
|
|
513
|
+
for (let i = 0; i < primitive.vertices.length; i += 4) {
|
|
514
|
+
const vertices = [
|
|
515
|
+
primitive.vertices[i],
|
|
516
|
+
primitive.vertices[i + 1],
|
|
517
|
+
primitive.vertices[i + 2],
|
|
518
|
+
primitive.vertices[i],
|
|
519
|
+
primitive.vertices[i + 2],
|
|
520
|
+
primitive.vertices[i + 3],
|
|
521
|
+
];
|
|
522
|
+
for (const [x, y, z, r, g, b] of vertices) {
|
|
523
|
+
positions.push(x, y, z);
|
|
524
|
+
colors.push(r, g, b, 1);
|
|
525
|
+
}
|
|
526
|
+
}
|
|
527
|
+
const vertexData = new VertexData();
|
|
528
|
+
vertexData.positions = positions;
|
|
529
|
+
vertexData.colors = colors;
|
|
530
|
+
const customMesh = new Mesh(NavigationDebugger.NAV_MESH_DEBUG_NAME_QUADS);
|
|
531
|
+
customMesh.isUnIndexed = true;
|
|
532
|
+
vertexData.applyToMesh(customMesh);
|
|
533
|
+
customMesh.material = this.triMaterial;
|
|
534
|
+
customMesh.parent = this.debugDrawerParentNode;
|
|
535
|
+
}
|
|
536
|
+
/**
|
|
537
|
+
* Merge the debug meshes for better performance
|
|
538
|
+
*/
|
|
539
|
+
_joinDebugMeshes() {
|
|
540
|
+
const debugMeshes = this._scene.meshes.filter((m) => m.name === NavigationDebugger.NAV_MESH_DEBUG_NAME);
|
|
541
|
+
// only indexed meshes can be merged
|
|
542
|
+
debugMeshes.forEach((m) => {
|
|
543
|
+
this._convertUnindexedToIndexed(m);
|
|
544
|
+
});
|
|
545
|
+
const merged = Mesh.MergeMeshes(debugMeshes, true);
|
|
546
|
+
if (merged) {
|
|
547
|
+
merged.name = NavigationDebugger.NAV_MESH_DEBUG_NAME;
|
|
548
|
+
merged.parent = this.debugDrawerParentNode;
|
|
549
|
+
}
|
|
550
|
+
}
|
|
551
|
+
_convertUnindexedToIndexed(mesh) {
|
|
552
|
+
const vertexData = VertexData.ExtractFromMesh(mesh);
|
|
553
|
+
const positions = vertexData.positions;
|
|
554
|
+
if (!positions || positions.length % 9 !== 0) {
|
|
555
|
+
Logger.Warn("Mesh must be fully unindexed with triangles.");
|
|
556
|
+
return;
|
|
557
|
+
}
|
|
558
|
+
const vertexCount = positions.length / 3;
|
|
559
|
+
const indices = Array.from({ length: vertexCount }, (_, i) => i);
|
|
560
|
+
const newVertexData = new VertexData();
|
|
561
|
+
newVertexData.positions = positions;
|
|
562
|
+
newVertexData.indices = indices;
|
|
563
|
+
newVertexData.applyToMesh(mesh, true);
|
|
564
|
+
}
|
|
565
|
+
}
|
|
566
|
+
/**
|
|
567
|
+
* The name of the debug mesh used for navigation debugging.
|
|
568
|
+
* This is used to group all navigation debug meshes under a single name for easier management
|
|
569
|
+
*/
|
|
570
|
+
NavigationDebugger.NAV_MESH_DEBUG_NAME = "nav-mesh-debug";
|
|
571
|
+
/**
|
|
572
|
+
* The name of the debug mesh used for visualization of the navigation mesh using points.
|
|
573
|
+
*/
|
|
574
|
+
NavigationDebugger.NAV_MESH_DEBUG_NAME_POINTS = "nav-mesh-debug-points";
|
|
575
|
+
/**
|
|
576
|
+
* The name of the debug mesh used for visualization of the navigation mesh using triangles.
|
|
577
|
+
*/
|
|
578
|
+
NavigationDebugger.NAV_MESH_DEBUG_NAME_TRIS = "nav-mesh-debug-tris";
|
|
579
|
+
/**
|
|
580
|
+
* The name of the debug mesh used for visualization of the navigation mesh using quads.
|
|
581
|
+
*/
|
|
582
|
+
NavigationDebugger.NAV_MESH_DEBUG_NAME_QUADS = "nav-mesh-debug-quads";
|
|
583
|
+
/**
|
|
584
|
+
* The name of the debug mesh used for visualization of the navigation mesh using lines.
|
|
585
|
+
*/
|
|
586
|
+
NavigationDebugger.NAV_MESH_DEBUG_NAME_LINES = "nav-mesh-debug-lines";
|
|
587
|
+
//# sourceMappingURL=NavigationDebugger.js.map
|