@esengine/spatial 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/dist/index.d.ts +843 -0
- package/dist/index.js +1607 -0
- package/dist/index.js.map +1 -0
- package/module.json +23 -0
- package/package.json +41 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,843 @@
|
|
|
1
|
+
import { IVector2 } from '@esengine/ecs-framework-math';
|
|
2
|
+
import * as _esengine_ecs_framework from '@esengine/ecs-framework';
|
|
3
|
+
import { BlueprintNodeTemplate, INodeExecutor, BlueprintNode, ExecutionResult } from '@esengine/blueprint';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @zh 空间查询接口
|
|
7
|
+
* @en Spatial Query Interface
|
|
8
|
+
*
|
|
9
|
+
* @zh 提供空间查询的核心抽象
|
|
10
|
+
* @en Provides core abstractions for spatial queries
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* @zh 空间边界框
|
|
15
|
+
* @en Spatial bounding box
|
|
16
|
+
*/
|
|
17
|
+
interface IBounds {
|
|
18
|
+
/**
|
|
19
|
+
* @zh 最小 X 坐标
|
|
20
|
+
* @en Minimum X coordinate
|
|
21
|
+
*/
|
|
22
|
+
readonly minX: number;
|
|
23
|
+
/**
|
|
24
|
+
* @zh 最小 Y 坐标
|
|
25
|
+
* @en Minimum Y coordinate
|
|
26
|
+
*/
|
|
27
|
+
readonly minY: number;
|
|
28
|
+
/**
|
|
29
|
+
* @zh 最大 X 坐标
|
|
30
|
+
* @en Maximum X coordinate
|
|
31
|
+
*/
|
|
32
|
+
readonly maxX: number;
|
|
33
|
+
/**
|
|
34
|
+
* @zh 最大 Y 坐标
|
|
35
|
+
* @en Maximum Y coordinate
|
|
36
|
+
*/
|
|
37
|
+
readonly maxY: number;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* @zh 可定位对象接口
|
|
41
|
+
* @en Positionable object interface
|
|
42
|
+
*/
|
|
43
|
+
interface IPositionable {
|
|
44
|
+
/**
|
|
45
|
+
* @zh 获取对象位置
|
|
46
|
+
* @en Get object position
|
|
47
|
+
*/
|
|
48
|
+
readonly position: IVector2;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* @zh 可定位且有边界的对象接口
|
|
52
|
+
* @en Positionable object with bounds interface
|
|
53
|
+
*/
|
|
54
|
+
interface IBoundable extends IPositionable {
|
|
55
|
+
/**
|
|
56
|
+
* @zh 获取对象边界
|
|
57
|
+
* @en Get object bounds
|
|
58
|
+
*/
|
|
59
|
+
readonly bounds: IBounds;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* @zh 射线检测结果
|
|
63
|
+
* @en Raycast hit result
|
|
64
|
+
*/
|
|
65
|
+
interface IRaycastHit<T> {
|
|
66
|
+
/**
|
|
67
|
+
* @zh 命中的对象
|
|
68
|
+
* @en Hit object
|
|
69
|
+
*/
|
|
70
|
+
readonly target: T;
|
|
71
|
+
/**
|
|
72
|
+
* @zh 命中点
|
|
73
|
+
* @en Hit point
|
|
74
|
+
*/
|
|
75
|
+
readonly point: IVector2;
|
|
76
|
+
/**
|
|
77
|
+
* @zh 命中点的法线
|
|
78
|
+
* @en Normal at hit point
|
|
79
|
+
*/
|
|
80
|
+
readonly normal: IVector2;
|
|
81
|
+
/**
|
|
82
|
+
* @zh 距离射线起点的距离
|
|
83
|
+
* @en Distance from ray origin
|
|
84
|
+
*/
|
|
85
|
+
readonly distance: number;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* @zh 过滤器函数类型
|
|
89
|
+
* @en Filter function type
|
|
90
|
+
*/
|
|
91
|
+
type SpatialFilter<T> = (item: T) => boolean;
|
|
92
|
+
/**
|
|
93
|
+
* @zh 空间查询接口
|
|
94
|
+
* @en Spatial query interface
|
|
95
|
+
*
|
|
96
|
+
* @zh 提供空间查询能力,支持范围查询、最近邻查询和射线检测
|
|
97
|
+
* @en Provides spatial query capabilities including range queries, nearest neighbor queries, and raycasting
|
|
98
|
+
*/
|
|
99
|
+
interface ISpatialQuery<T> {
|
|
100
|
+
/**
|
|
101
|
+
* @zh 查找半径内的所有对象
|
|
102
|
+
* @en Find all objects within radius
|
|
103
|
+
*
|
|
104
|
+
* @param center - @zh 中心点 @en Center point
|
|
105
|
+
* @param radius - @zh 半径 @en Radius
|
|
106
|
+
* @param filter - @zh 过滤函数 @en Filter function
|
|
107
|
+
* @returns @zh 半径内的对象数组 @en Array of objects within radius
|
|
108
|
+
*/
|
|
109
|
+
findInRadius(center: IVector2, radius: number, filter?: SpatialFilter<T>): T[];
|
|
110
|
+
/**
|
|
111
|
+
* @zh 查找矩形区域内的所有对象
|
|
112
|
+
* @en Find all objects within rectangle
|
|
113
|
+
*
|
|
114
|
+
* @param bounds - @zh 边界框 @en Bounding box
|
|
115
|
+
* @param filter - @zh 过滤函数 @en Filter function
|
|
116
|
+
* @returns @zh 区域内的对象数组 @en Array of objects within bounds
|
|
117
|
+
*/
|
|
118
|
+
findInRect(bounds: IBounds, filter?: SpatialFilter<T>): T[];
|
|
119
|
+
/**
|
|
120
|
+
* @zh 查找最近的对象
|
|
121
|
+
* @en Find nearest object
|
|
122
|
+
*
|
|
123
|
+
* @param center - @zh 查询中心点 @en Query center point
|
|
124
|
+
* @param maxDistance - @zh 最大搜索距离 @en Maximum search distance
|
|
125
|
+
* @param filter - @zh 过滤函数 @en Filter function
|
|
126
|
+
* @returns @zh 最近的对象,没有则返回 null @en Nearest object or null
|
|
127
|
+
*/
|
|
128
|
+
findNearest(center: IVector2, maxDistance?: number, filter?: SpatialFilter<T>): T | null;
|
|
129
|
+
/**
|
|
130
|
+
* @zh 查找最近的 K 个对象
|
|
131
|
+
* @en Find K nearest objects
|
|
132
|
+
*
|
|
133
|
+
* @param center - @zh 查询中心点 @en Query center point
|
|
134
|
+
* @param k - @zh 返回的对象数量 @en Number of objects to return
|
|
135
|
+
* @param maxDistance - @zh 最大搜索距离 @en Maximum search distance
|
|
136
|
+
* @param filter - @zh 过滤函数 @en Filter function
|
|
137
|
+
* @returns @zh 最近的 K 个对象数组 @en Array of K nearest objects
|
|
138
|
+
*/
|
|
139
|
+
findKNearest(center: IVector2, k: number, maxDistance?: number, filter?: SpatialFilter<T>): T[];
|
|
140
|
+
/**
|
|
141
|
+
* @zh 射线检测
|
|
142
|
+
* @en Raycast
|
|
143
|
+
*
|
|
144
|
+
* @param origin - @zh 射线起点 @en Ray origin
|
|
145
|
+
* @param direction - @zh 射线方向(应归一化)@en Ray direction (should be normalized)
|
|
146
|
+
* @param maxDistance - @zh 最大检测距离 @en Maximum detection distance
|
|
147
|
+
* @param filter - @zh 过滤函数 @en Filter function
|
|
148
|
+
* @returns @zh 命中结果数组,按距离排序 @en Array of hit results sorted by distance
|
|
149
|
+
*/
|
|
150
|
+
raycast(origin: IVector2, direction: IVector2, maxDistance: number, filter?: SpatialFilter<T>): IRaycastHit<T>[];
|
|
151
|
+
/**
|
|
152
|
+
* @zh 射线检测(仅返回第一个命中)
|
|
153
|
+
* @en Raycast (return first hit only)
|
|
154
|
+
*
|
|
155
|
+
* @param origin - @zh 射线起点 @en Ray origin
|
|
156
|
+
* @param direction - @zh 射线方向(应归一化)@en Ray direction (should be normalized)
|
|
157
|
+
* @param maxDistance - @zh 最大检测距离 @en Maximum detection distance
|
|
158
|
+
* @param filter - @zh 过滤函数 @en Filter function
|
|
159
|
+
* @returns @zh 第一个命中结果,没有则返回 null @en First hit result or null
|
|
160
|
+
*/
|
|
161
|
+
raycastFirst(origin: IVector2, direction: IVector2, maxDistance: number, filter?: SpatialFilter<T>): IRaycastHit<T> | null;
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* @zh 空间索引接口
|
|
165
|
+
* @en Spatial index interface
|
|
166
|
+
*
|
|
167
|
+
* @zh 提供空间索引的管理能力
|
|
168
|
+
* @en Provides spatial index management capabilities
|
|
169
|
+
*/
|
|
170
|
+
interface ISpatialIndex<T> extends ISpatialQuery<T> {
|
|
171
|
+
/**
|
|
172
|
+
* @zh 插入对象
|
|
173
|
+
* @en Insert object
|
|
174
|
+
*
|
|
175
|
+
* @param item - @zh 要插入的对象 @en Object to insert
|
|
176
|
+
* @param position - @zh 对象位置 @en Object position
|
|
177
|
+
*/
|
|
178
|
+
insert(item: T, position: IVector2): void;
|
|
179
|
+
/**
|
|
180
|
+
* @zh 移除对象
|
|
181
|
+
* @en Remove object
|
|
182
|
+
*
|
|
183
|
+
* @param item - @zh 要移除的对象 @en Object to remove
|
|
184
|
+
* @returns @zh 是否成功移除 @en Whether removal was successful
|
|
185
|
+
*/
|
|
186
|
+
remove(item: T): boolean;
|
|
187
|
+
/**
|
|
188
|
+
* @zh 更新对象位置
|
|
189
|
+
* @en Update object position
|
|
190
|
+
*
|
|
191
|
+
* @param item - @zh 要更新的对象 @en Object to update
|
|
192
|
+
* @param newPosition - @zh 新位置 @en New position
|
|
193
|
+
* @returns @zh 是否成功更新 @en Whether update was successful
|
|
194
|
+
*/
|
|
195
|
+
update(item: T, newPosition: IVector2): boolean;
|
|
196
|
+
/**
|
|
197
|
+
* @zh 清空索引
|
|
198
|
+
* @en Clear index
|
|
199
|
+
*/
|
|
200
|
+
clear(): void;
|
|
201
|
+
/**
|
|
202
|
+
* @zh 获取索引中的对象数量
|
|
203
|
+
* @en Get number of objects in index
|
|
204
|
+
*/
|
|
205
|
+
readonly count: number;
|
|
206
|
+
/**
|
|
207
|
+
* @zh 获取所有对象
|
|
208
|
+
* @en Get all objects
|
|
209
|
+
*/
|
|
210
|
+
getAll(): T[];
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* @zh 创建边界框
|
|
214
|
+
* @en Create bounding box
|
|
215
|
+
*/
|
|
216
|
+
declare function createBounds(minX: number, minY: number, maxX: number, maxY: number): IBounds;
|
|
217
|
+
/**
|
|
218
|
+
* @zh 从中心点和尺寸创建边界框
|
|
219
|
+
* @en Create bounding box from center and size
|
|
220
|
+
*/
|
|
221
|
+
declare function createBoundsFromCenter(center: IVector2, width: number, height: number): IBounds;
|
|
222
|
+
/**
|
|
223
|
+
* @zh 从圆形创建边界框
|
|
224
|
+
* @en Create bounding box from circle
|
|
225
|
+
*/
|
|
226
|
+
declare function createBoundsFromCircle(center: IVector2, radius: number): IBounds;
|
|
227
|
+
/**
|
|
228
|
+
* @zh 检查点是否在边界框内
|
|
229
|
+
* @en Check if point is inside bounds
|
|
230
|
+
*/
|
|
231
|
+
declare function isPointInBounds(point: IVector2, bounds: IBounds): boolean;
|
|
232
|
+
/**
|
|
233
|
+
* @zh 检查两个边界框是否相交
|
|
234
|
+
* @en Check if two bounding boxes intersect
|
|
235
|
+
*/
|
|
236
|
+
declare function boundsIntersect(a: IBounds, b: IBounds): boolean;
|
|
237
|
+
/**
|
|
238
|
+
* @zh 检查边界框是否与圆形相交
|
|
239
|
+
* @en Check if bounds intersects with circle
|
|
240
|
+
*/
|
|
241
|
+
declare function boundsIntersectsCircle(bounds: IBounds, center: IVector2, radius: number): boolean;
|
|
242
|
+
/**
|
|
243
|
+
* @zh 计算两点之间的距离平方
|
|
244
|
+
* @en Calculate squared distance between two points
|
|
245
|
+
*/
|
|
246
|
+
declare function distanceSquared(a: IVector2, b: IVector2): number;
|
|
247
|
+
/**
|
|
248
|
+
* @zh 计算两点之间的距离
|
|
249
|
+
* @en Calculate distance between two points
|
|
250
|
+
*/
|
|
251
|
+
declare function distance(a: IVector2, b: IVector2): number;
|
|
252
|
+
|
|
253
|
+
/**
|
|
254
|
+
* @zh 网格空间索引
|
|
255
|
+
* @en Grid Spatial Index
|
|
256
|
+
*
|
|
257
|
+
* @zh 基于均匀网格的空间索引实现
|
|
258
|
+
* @en Uniform grid based spatial index implementation
|
|
259
|
+
*/
|
|
260
|
+
|
|
261
|
+
/**
|
|
262
|
+
* @zh 网格空间索引配置
|
|
263
|
+
* @en Grid spatial index configuration
|
|
264
|
+
*/
|
|
265
|
+
interface GridSpatialIndexConfig {
|
|
266
|
+
/**
|
|
267
|
+
* @zh 网格单元格大小
|
|
268
|
+
* @en Grid cell size
|
|
269
|
+
*/
|
|
270
|
+
cellSize: number;
|
|
271
|
+
}
|
|
272
|
+
/**
|
|
273
|
+
* @zh 网格空间索引实现
|
|
274
|
+
* @en Grid spatial index implementation
|
|
275
|
+
*
|
|
276
|
+
* @zh 使用均匀网格进行空间划分,适合对象分布均匀的场景
|
|
277
|
+
* @en Uses uniform grid for spatial partitioning, suitable for evenly distributed objects
|
|
278
|
+
*/
|
|
279
|
+
declare class GridSpatialIndex<T> implements ISpatialIndex<T> {
|
|
280
|
+
private readonly _cellSize;
|
|
281
|
+
private readonly _cells;
|
|
282
|
+
private readonly _itemMap;
|
|
283
|
+
constructor(config: GridSpatialIndexConfig);
|
|
284
|
+
get count(): number;
|
|
285
|
+
/**
|
|
286
|
+
* @zh 插入对象
|
|
287
|
+
* @en Insert object
|
|
288
|
+
*/
|
|
289
|
+
insert(item: T, position: IVector2): void;
|
|
290
|
+
/**
|
|
291
|
+
* @zh 移除对象
|
|
292
|
+
* @en Remove object
|
|
293
|
+
*/
|
|
294
|
+
remove(item: T): boolean;
|
|
295
|
+
/**
|
|
296
|
+
* @zh 更新对象位置
|
|
297
|
+
* @en Update object position
|
|
298
|
+
*/
|
|
299
|
+
update(item: T, newPosition: IVector2): boolean;
|
|
300
|
+
/**
|
|
301
|
+
* @zh 清空索引
|
|
302
|
+
* @en Clear index
|
|
303
|
+
*/
|
|
304
|
+
clear(): void;
|
|
305
|
+
/**
|
|
306
|
+
* @zh 获取所有对象
|
|
307
|
+
* @en Get all objects
|
|
308
|
+
*/
|
|
309
|
+
getAll(): T[];
|
|
310
|
+
/**
|
|
311
|
+
* @zh 查找半径内的所有对象
|
|
312
|
+
* @en Find all objects within radius
|
|
313
|
+
*/
|
|
314
|
+
findInRadius(center: IVector2, radius: number, filter?: SpatialFilter<T>): T[];
|
|
315
|
+
/**
|
|
316
|
+
* @zh 查找矩形区域内的所有对象
|
|
317
|
+
* @en Find all objects within rectangle
|
|
318
|
+
*/
|
|
319
|
+
findInRect(bounds: IBounds, filter?: SpatialFilter<T>): T[];
|
|
320
|
+
/**
|
|
321
|
+
* @zh 查找最近的对象
|
|
322
|
+
* @en Find nearest object
|
|
323
|
+
*/
|
|
324
|
+
findNearest(center: IVector2, maxDistance?: number, filter?: SpatialFilter<T>): T | null;
|
|
325
|
+
/**
|
|
326
|
+
* @zh 查找最近的 K 个对象
|
|
327
|
+
* @en Find K nearest objects
|
|
328
|
+
*/
|
|
329
|
+
findKNearest(center: IVector2, k: number, maxDistance?: number, filter?: SpatialFilter<T>): T[];
|
|
330
|
+
/**
|
|
331
|
+
* @zh 射线检测
|
|
332
|
+
* @en Raycast
|
|
333
|
+
*/
|
|
334
|
+
raycast(origin: IVector2, direction: IVector2, maxDistance: number, filter?: SpatialFilter<T>): IRaycastHit<T>[];
|
|
335
|
+
/**
|
|
336
|
+
* @zh 射线检测(仅返回第一个命中)
|
|
337
|
+
* @en Raycast (return first hit only)
|
|
338
|
+
*/
|
|
339
|
+
raycastFirst(origin: IVector2, direction: IVector2, maxDistance: number, filter?: SpatialFilter<T>): IRaycastHit<T> | null;
|
|
340
|
+
private _getCellKey;
|
|
341
|
+
private _getCellCoords;
|
|
342
|
+
private _addToCell;
|
|
343
|
+
private _removeFromCell;
|
|
344
|
+
private _forEachInBounds;
|
|
345
|
+
private _getRayBounds;
|
|
346
|
+
private _rayIntersectsPoint;
|
|
347
|
+
}
|
|
348
|
+
/**
|
|
349
|
+
* @zh 创建网格空间索引
|
|
350
|
+
* @en Create grid spatial index
|
|
351
|
+
*/
|
|
352
|
+
declare function createGridSpatialIndex<T>(cellSize?: number): GridSpatialIndex<T>;
|
|
353
|
+
|
|
354
|
+
/**
|
|
355
|
+
* @zh AOI (Area of Interest) 兴趣区域接口
|
|
356
|
+
* @en AOI (Area of Interest) Interface
|
|
357
|
+
*
|
|
358
|
+
* @zh 提供 MMO 游戏中的兴趣区域管理能力
|
|
359
|
+
* @en Provides area of interest management for MMO games
|
|
360
|
+
*/
|
|
361
|
+
|
|
362
|
+
/**
|
|
363
|
+
* @zh AOI 事件类型
|
|
364
|
+
* @en AOI event type
|
|
365
|
+
*/
|
|
366
|
+
type AOIEventType = 'enter' | 'exit' | 'update';
|
|
367
|
+
/**
|
|
368
|
+
* @zh AOI 事件
|
|
369
|
+
* @en AOI event
|
|
370
|
+
*/
|
|
371
|
+
interface IAOIEvent<T> {
|
|
372
|
+
/**
|
|
373
|
+
* @zh 事件类型
|
|
374
|
+
* @en Event type
|
|
375
|
+
*/
|
|
376
|
+
readonly type: AOIEventType;
|
|
377
|
+
/**
|
|
378
|
+
* @zh 观察者(谁看到了变化)
|
|
379
|
+
* @en Observer (who saw the change)
|
|
380
|
+
*/
|
|
381
|
+
readonly observer: T;
|
|
382
|
+
/**
|
|
383
|
+
* @zh 目标(发生变化的对象)
|
|
384
|
+
* @en Target (the object that changed)
|
|
385
|
+
*/
|
|
386
|
+
readonly target: T;
|
|
387
|
+
/**
|
|
388
|
+
* @zh 目标位置
|
|
389
|
+
* @en Target position
|
|
390
|
+
*/
|
|
391
|
+
readonly position: IVector2;
|
|
392
|
+
}
|
|
393
|
+
/**
|
|
394
|
+
* @zh AOI 事件监听器
|
|
395
|
+
* @en AOI event listener
|
|
396
|
+
*/
|
|
397
|
+
type AOIEventListener<T> = (event: IAOIEvent<T>) => void;
|
|
398
|
+
/**
|
|
399
|
+
* @zh AOI 观察者配置
|
|
400
|
+
* @en AOI observer configuration
|
|
401
|
+
*/
|
|
402
|
+
interface IAOIObserverConfig {
|
|
403
|
+
/**
|
|
404
|
+
* @zh 视野范围
|
|
405
|
+
* @en View range
|
|
406
|
+
*/
|
|
407
|
+
viewRange: number;
|
|
408
|
+
/**
|
|
409
|
+
* @zh 是否是可被观察的对象(默认 true)
|
|
410
|
+
* @en Whether this observer can be observed by others (default true)
|
|
411
|
+
*/
|
|
412
|
+
observable?: boolean;
|
|
413
|
+
}
|
|
414
|
+
/**
|
|
415
|
+
* @zh AOI 管理器接口
|
|
416
|
+
* @en AOI manager interface
|
|
417
|
+
*
|
|
418
|
+
* @zh 管理兴趣区域,追踪对象的进入/离开事件
|
|
419
|
+
* @en Manages areas of interest, tracking enter/exit events for objects
|
|
420
|
+
*
|
|
421
|
+
* @typeParam T - @zh 被管理对象的类型 @en Type of managed objects
|
|
422
|
+
*/
|
|
423
|
+
interface IAOIManager<T> {
|
|
424
|
+
/**
|
|
425
|
+
* @zh 添加观察者
|
|
426
|
+
* @en Add observer
|
|
427
|
+
*
|
|
428
|
+
* @param entity - @zh 实体对象 @en Entity object
|
|
429
|
+
* @param position - @zh 初始位置 @en Initial position
|
|
430
|
+
* @param config - @zh 观察者配置 @en Observer configuration
|
|
431
|
+
*/
|
|
432
|
+
addObserver(entity: T, position: IVector2, config: IAOIObserverConfig): void;
|
|
433
|
+
/**
|
|
434
|
+
* @zh 移除观察者
|
|
435
|
+
* @en Remove observer
|
|
436
|
+
*
|
|
437
|
+
* @param entity - @zh 实体对象 @en Entity object
|
|
438
|
+
* @returns @zh 是否成功移除 @en Whether removal was successful
|
|
439
|
+
*/
|
|
440
|
+
removeObserver(entity: T): boolean;
|
|
441
|
+
/**
|
|
442
|
+
* @zh 更新观察者位置
|
|
443
|
+
* @en Update observer position
|
|
444
|
+
*
|
|
445
|
+
* @param entity - @zh 实体对象 @en Entity object
|
|
446
|
+
* @param newPosition - @zh 新位置 @en New position
|
|
447
|
+
* @returns @zh 是否成功更新 @en Whether update was successful
|
|
448
|
+
*/
|
|
449
|
+
updatePosition(entity: T, newPosition: IVector2): boolean;
|
|
450
|
+
/**
|
|
451
|
+
* @zh 更新观察者视野范围
|
|
452
|
+
* @en Update observer view range
|
|
453
|
+
*
|
|
454
|
+
* @param entity - @zh 实体对象 @en Entity object
|
|
455
|
+
* @param newRange - @zh 新视野范围 @en New view range
|
|
456
|
+
* @returns @zh 是否成功更新 @en Whether update was successful
|
|
457
|
+
*/
|
|
458
|
+
updateViewRange(entity: T, newRange: number): boolean;
|
|
459
|
+
/**
|
|
460
|
+
* @zh 获取实体视野内的所有对象
|
|
461
|
+
* @en Get all objects within entity's view
|
|
462
|
+
*
|
|
463
|
+
* @param entity - @zh 观察者实体 @en Observer entity
|
|
464
|
+
* @returns @zh 视野内的对象数组 @en Array of objects within view
|
|
465
|
+
*/
|
|
466
|
+
getEntitiesInView(entity: T): T[];
|
|
467
|
+
/**
|
|
468
|
+
* @zh 获取能看到指定实体的所有观察者
|
|
469
|
+
* @en Get all observers who can see the specified entity
|
|
470
|
+
*
|
|
471
|
+
* @param entity - @zh 目标实体 @en Target entity
|
|
472
|
+
* @returns @zh 能看到目标的观察者数组 @en Array of observers who can see target
|
|
473
|
+
*/
|
|
474
|
+
getObserversOf(entity: T): T[];
|
|
475
|
+
/**
|
|
476
|
+
* @zh 检查观察者是否能看到目标
|
|
477
|
+
* @en Check if observer can see target
|
|
478
|
+
*
|
|
479
|
+
* @param observer - @zh 观察者 @en Observer
|
|
480
|
+
* @param target - @zh 目标 @en Target
|
|
481
|
+
* @returns @zh 是否在视野内 @en Whether target is in view
|
|
482
|
+
*/
|
|
483
|
+
canSee(observer: T, target: T): boolean;
|
|
484
|
+
/**
|
|
485
|
+
* @zh 添加事件监听器
|
|
486
|
+
* @en Add event listener
|
|
487
|
+
*
|
|
488
|
+
* @param listener - @zh 监听器函数 @en Listener function
|
|
489
|
+
*/
|
|
490
|
+
addListener(listener: AOIEventListener<T>): void;
|
|
491
|
+
/**
|
|
492
|
+
* @zh 移除事件监听器
|
|
493
|
+
* @en Remove event listener
|
|
494
|
+
*
|
|
495
|
+
* @param listener - @zh 监听器函数 @en Listener function
|
|
496
|
+
*/
|
|
497
|
+
removeListener(listener: AOIEventListener<T>): void;
|
|
498
|
+
/**
|
|
499
|
+
* @zh 为特定观察者添加事件监听器
|
|
500
|
+
* @en Add event listener for specific observer
|
|
501
|
+
*
|
|
502
|
+
* @param entity - @zh 观察者实体 @en Observer entity
|
|
503
|
+
* @param listener - @zh 监听器函数 @en Listener function
|
|
504
|
+
*/
|
|
505
|
+
addEntityListener(entity: T, listener: AOIEventListener<T>): void;
|
|
506
|
+
/**
|
|
507
|
+
* @zh 移除特定观察者的事件监听器
|
|
508
|
+
* @en Remove event listener for specific observer
|
|
509
|
+
*
|
|
510
|
+
* @param entity - @zh 观察者实体 @en Observer entity
|
|
511
|
+
* @param listener - @zh 监听器函数 @en Listener function
|
|
512
|
+
*/
|
|
513
|
+
removeEntityListener(entity: T, listener: AOIEventListener<T>): void;
|
|
514
|
+
/**
|
|
515
|
+
* @zh 清空所有观察者
|
|
516
|
+
* @en Clear all observers
|
|
517
|
+
*/
|
|
518
|
+
clear(): void;
|
|
519
|
+
/**
|
|
520
|
+
* @zh 获取观察者数量
|
|
521
|
+
* @en Get observer count
|
|
522
|
+
*/
|
|
523
|
+
readonly count: number;
|
|
524
|
+
}
|
|
525
|
+
|
|
526
|
+
/**
|
|
527
|
+
* @zh 网格 AOI 实现
|
|
528
|
+
* @en Grid AOI Implementation
|
|
529
|
+
*
|
|
530
|
+
* @zh 基于均匀网格的兴趣区域管理实现
|
|
531
|
+
* @en Uniform grid based area of interest management implementation
|
|
532
|
+
*/
|
|
533
|
+
|
|
534
|
+
/**
|
|
535
|
+
* @zh 网格 AOI 配置
|
|
536
|
+
* @en Grid AOI configuration
|
|
537
|
+
*/
|
|
538
|
+
interface GridAOIConfig {
|
|
539
|
+
/**
|
|
540
|
+
* @zh 网格单元格大小(建议设置为平均视野范围的 1-2 倍)
|
|
541
|
+
* @en Grid cell size (recommended 1-2x average view range)
|
|
542
|
+
*/
|
|
543
|
+
cellSize: number;
|
|
544
|
+
}
|
|
545
|
+
/**
|
|
546
|
+
* @zh 网格 AOI 实现
|
|
547
|
+
* @en Grid AOI implementation
|
|
548
|
+
*
|
|
549
|
+
* @zh 使用均匀网格进行空间划分,高效管理大量实体的兴趣区域
|
|
550
|
+
* @en Uses uniform grid for spatial partitioning, efficiently managing AOI for many entities
|
|
551
|
+
*/
|
|
552
|
+
declare class GridAOI<T> implements IAOIManager<T> {
|
|
553
|
+
private readonly _cellSize;
|
|
554
|
+
private readonly _cells;
|
|
555
|
+
private readonly _observers;
|
|
556
|
+
private readonly _globalListeners;
|
|
557
|
+
constructor(config: GridAOIConfig);
|
|
558
|
+
get count(): number;
|
|
559
|
+
/**
|
|
560
|
+
* @zh 添加观察者
|
|
561
|
+
* @en Add observer
|
|
562
|
+
*/
|
|
563
|
+
addObserver(entity: T, position: IVector2, config: IAOIObserverConfig): void;
|
|
564
|
+
/**
|
|
565
|
+
* @zh 移除观察者
|
|
566
|
+
* @en Remove observer
|
|
567
|
+
*/
|
|
568
|
+
removeObserver(entity: T): boolean;
|
|
569
|
+
/**
|
|
570
|
+
* @zh 更新观察者位置
|
|
571
|
+
* @en Update observer position
|
|
572
|
+
*/
|
|
573
|
+
updatePosition(entity: T, newPosition: IVector2): boolean;
|
|
574
|
+
/**
|
|
575
|
+
* @zh 更新观察者视野范围
|
|
576
|
+
* @en Update observer view range
|
|
577
|
+
*/
|
|
578
|
+
updateViewRange(entity: T, newRange: number): boolean;
|
|
579
|
+
/**
|
|
580
|
+
* @zh 获取实体视野内的所有对象
|
|
581
|
+
* @en Get all objects within entity's view
|
|
582
|
+
*/
|
|
583
|
+
getEntitiesInView(entity: T): T[];
|
|
584
|
+
/**
|
|
585
|
+
* @zh 获取能看到指定实体的所有观察者
|
|
586
|
+
* @en Get all observers who can see the specified entity
|
|
587
|
+
*/
|
|
588
|
+
getObserversOf(entity: T): T[];
|
|
589
|
+
/**
|
|
590
|
+
* @zh 检查观察者是否能看到目标
|
|
591
|
+
* @en Check if observer can see target
|
|
592
|
+
*/
|
|
593
|
+
canSee(observer: T, target: T): boolean;
|
|
594
|
+
/**
|
|
595
|
+
* @zh 添加全局事件监听器
|
|
596
|
+
* @en Add global event listener
|
|
597
|
+
*/
|
|
598
|
+
addListener(listener: AOIEventListener<T>): void;
|
|
599
|
+
/**
|
|
600
|
+
* @zh 移除全局事件监听器
|
|
601
|
+
* @en Remove global event listener
|
|
602
|
+
*/
|
|
603
|
+
removeListener(listener: AOIEventListener<T>): void;
|
|
604
|
+
/**
|
|
605
|
+
* @zh 为特定观察者添加事件监听器
|
|
606
|
+
* @en Add event listener for specific observer
|
|
607
|
+
*/
|
|
608
|
+
addEntityListener(entity: T, listener: AOIEventListener<T>): void;
|
|
609
|
+
/**
|
|
610
|
+
* @zh 移除特定观察者的事件监听器
|
|
611
|
+
* @en Remove event listener for specific observer
|
|
612
|
+
*/
|
|
613
|
+
removeEntityListener(entity: T, listener: AOIEventListener<T>): void;
|
|
614
|
+
/**
|
|
615
|
+
* @zh 清空所有观察者
|
|
616
|
+
* @en Clear all observers
|
|
617
|
+
*/
|
|
618
|
+
clear(): void;
|
|
619
|
+
private _getCellKey;
|
|
620
|
+
private _getCellCoords;
|
|
621
|
+
private _addToCell;
|
|
622
|
+
private _removeFromCell;
|
|
623
|
+
/**
|
|
624
|
+
* @zh 更新观察者的可见实体列表
|
|
625
|
+
* @en Update observer's visible entities list
|
|
626
|
+
*/
|
|
627
|
+
private _updateVisibility;
|
|
628
|
+
/**
|
|
629
|
+
* @zh 更新其他观察者对于某个实体的可见性
|
|
630
|
+
* @en Update other observers' visibility of an entity
|
|
631
|
+
*/
|
|
632
|
+
private _updateObserversOfEntity;
|
|
633
|
+
/**
|
|
634
|
+
* @zh 获取最大视野范围(用于优化搜索)
|
|
635
|
+
* @en Get maximum view range (for search optimization)
|
|
636
|
+
*/
|
|
637
|
+
private _getMaxViewRange;
|
|
638
|
+
/**
|
|
639
|
+
* @zh 发送事件
|
|
640
|
+
* @en Emit event
|
|
641
|
+
*/
|
|
642
|
+
private _emitEvent;
|
|
643
|
+
}
|
|
644
|
+
/**
|
|
645
|
+
* @zh 创建网格 AOI 管理器
|
|
646
|
+
* @en Create grid AOI manager
|
|
647
|
+
*
|
|
648
|
+
* @param cellSize - @zh 网格单元格大小 @en Grid cell size
|
|
649
|
+
*/
|
|
650
|
+
declare function createGridAOI<T>(cellSize?: number): GridAOI<T>;
|
|
651
|
+
|
|
652
|
+
/**
|
|
653
|
+
* @zh 空间索引服务令牌
|
|
654
|
+
* @en Spatial index service token
|
|
655
|
+
*
|
|
656
|
+
* @zh 用于注入空间索引服务
|
|
657
|
+
* @en Used for injecting spatial index service
|
|
658
|
+
*/
|
|
659
|
+
declare const SpatialIndexToken: _esengine_ecs_framework.ServiceToken<ISpatialIndex<unknown>>;
|
|
660
|
+
/**
|
|
661
|
+
* @zh 空间查询服务令牌
|
|
662
|
+
* @en Spatial query service token
|
|
663
|
+
*
|
|
664
|
+
* @zh 用于注入空间查询服务(只读)
|
|
665
|
+
* @en Used for injecting spatial query service (read-only)
|
|
666
|
+
*/
|
|
667
|
+
declare const SpatialQueryToken: _esengine_ecs_framework.ServiceToken<ISpatialQuery<unknown>>;
|
|
668
|
+
/**
|
|
669
|
+
* @zh AOI 管理器服务令牌
|
|
670
|
+
* @en AOI manager service token
|
|
671
|
+
*
|
|
672
|
+
* @zh 用于注入 AOI 兴趣区域管理服务
|
|
673
|
+
* @en Used for injecting AOI (Area of Interest) manager service
|
|
674
|
+
*/
|
|
675
|
+
declare const AOIManagerToken: _esengine_ecs_framework.ServiceToken<IAOIManager<unknown>>;
|
|
676
|
+
|
|
677
|
+
/**
|
|
678
|
+
* @zh 空间查询蓝图节点
|
|
679
|
+
* @en Spatial Query Blueprint Nodes
|
|
680
|
+
*
|
|
681
|
+
* @zh 提供空间查询功能的蓝图节点
|
|
682
|
+
* @en Provides blueprint nodes for spatial query functionality
|
|
683
|
+
*/
|
|
684
|
+
|
|
685
|
+
/**
|
|
686
|
+
* @zh FindInRadius 节点模板
|
|
687
|
+
* @en FindInRadius node template
|
|
688
|
+
*/
|
|
689
|
+
declare const FindInRadiusTemplate: BlueprintNodeTemplate;
|
|
690
|
+
/**
|
|
691
|
+
* @zh FindInRadius 节点执行器
|
|
692
|
+
* @en FindInRadius node executor
|
|
693
|
+
*/
|
|
694
|
+
declare class FindInRadiusExecutor implements INodeExecutor {
|
|
695
|
+
execute(node: BlueprintNode, context: unknown): ExecutionResult;
|
|
696
|
+
}
|
|
697
|
+
/**
|
|
698
|
+
* @zh FindInRect 节点模板
|
|
699
|
+
* @en FindInRect node template
|
|
700
|
+
*/
|
|
701
|
+
declare const FindInRectTemplate: BlueprintNodeTemplate;
|
|
702
|
+
/**
|
|
703
|
+
* @zh FindInRect 节点执行器
|
|
704
|
+
* @en FindInRect node executor
|
|
705
|
+
*/
|
|
706
|
+
declare class FindInRectExecutor implements INodeExecutor {
|
|
707
|
+
execute(node: BlueprintNode, context: unknown): ExecutionResult;
|
|
708
|
+
}
|
|
709
|
+
/**
|
|
710
|
+
* @zh FindNearest 节点模板
|
|
711
|
+
* @en FindNearest node template
|
|
712
|
+
*/
|
|
713
|
+
declare const FindNearestTemplate: BlueprintNodeTemplate;
|
|
714
|
+
/**
|
|
715
|
+
* @zh FindNearest 节点执行器
|
|
716
|
+
* @en FindNearest node executor
|
|
717
|
+
*/
|
|
718
|
+
declare class FindNearestExecutor implements INodeExecutor {
|
|
719
|
+
execute(node: BlueprintNode, context: unknown): ExecutionResult;
|
|
720
|
+
}
|
|
721
|
+
/**
|
|
722
|
+
* @zh FindKNearest 节点模板
|
|
723
|
+
* @en FindKNearest node template
|
|
724
|
+
*/
|
|
725
|
+
declare const FindKNearestTemplate: BlueprintNodeTemplate;
|
|
726
|
+
/**
|
|
727
|
+
* @zh FindKNearest 节点执行器
|
|
728
|
+
* @en FindKNearest node executor
|
|
729
|
+
*/
|
|
730
|
+
declare class FindKNearestExecutor implements INodeExecutor {
|
|
731
|
+
execute(node: BlueprintNode, context: unknown): ExecutionResult;
|
|
732
|
+
}
|
|
733
|
+
/**
|
|
734
|
+
* @zh Raycast 节点模板
|
|
735
|
+
* @en Raycast node template
|
|
736
|
+
*/
|
|
737
|
+
declare const RaycastTemplate: BlueprintNodeTemplate;
|
|
738
|
+
/**
|
|
739
|
+
* @zh Raycast 节点执行器
|
|
740
|
+
* @en Raycast node executor
|
|
741
|
+
*/
|
|
742
|
+
declare class RaycastExecutor implements INodeExecutor {
|
|
743
|
+
execute(node: BlueprintNode, context: unknown): ExecutionResult;
|
|
744
|
+
}
|
|
745
|
+
/**
|
|
746
|
+
* @zh RaycastFirst 节点模板
|
|
747
|
+
* @en RaycastFirst node template
|
|
748
|
+
*/
|
|
749
|
+
declare const RaycastFirstTemplate: BlueprintNodeTemplate;
|
|
750
|
+
/**
|
|
751
|
+
* @zh RaycastFirst 节点执行器
|
|
752
|
+
* @en RaycastFirst node executor
|
|
753
|
+
*/
|
|
754
|
+
declare class RaycastFirstExecutor implements INodeExecutor {
|
|
755
|
+
execute(node: BlueprintNode, context: unknown): ExecutionResult;
|
|
756
|
+
}
|
|
757
|
+
/**
|
|
758
|
+
* @zh 空间查询节点定义
|
|
759
|
+
* @en Spatial query node definitions
|
|
760
|
+
*/
|
|
761
|
+
declare const SpatialQueryNodeDefinitions: {
|
|
762
|
+
template: BlueprintNodeTemplate;
|
|
763
|
+
executor: FindInRadiusExecutor;
|
|
764
|
+
}[];
|
|
765
|
+
|
|
766
|
+
/**
|
|
767
|
+
* @zh AOI 蓝图节点
|
|
768
|
+
* @en AOI Blueprint Nodes
|
|
769
|
+
*
|
|
770
|
+
* @zh 提供 AOI 功能的蓝图节点
|
|
771
|
+
* @en Provides blueprint nodes for AOI functionality
|
|
772
|
+
*/
|
|
773
|
+
|
|
774
|
+
/**
|
|
775
|
+
* @zh GetEntitiesInView 节点模板
|
|
776
|
+
* @en GetEntitiesInView node template
|
|
777
|
+
*/
|
|
778
|
+
declare const GetEntitiesInViewTemplate: BlueprintNodeTemplate;
|
|
779
|
+
/**
|
|
780
|
+
* @zh GetEntitiesInView 节点执行器
|
|
781
|
+
* @en GetEntitiesInView node executor
|
|
782
|
+
*/
|
|
783
|
+
declare class GetEntitiesInViewExecutor implements INodeExecutor {
|
|
784
|
+
execute(node: BlueprintNode, context: unknown): ExecutionResult;
|
|
785
|
+
}
|
|
786
|
+
/**
|
|
787
|
+
* @zh GetObserversOf 节点模板
|
|
788
|
+
* @en GetObserversOf node template
|
|
789
|
+
*/
|
|
790
|
+
declare const GetObserversOfTemplate: BlueprintNodeTemplate;
|
|
791
|
+
/**
|
|
792
|
+
* @zh GetObserversOf 节点执行器
|
|
793
|
+
* @en GetObserversOf node executor
|
|
794
|
+
*/
|
|
795
|
+
declare class GetObserversOfExecutor implements INodeExecutor {
|
|
796
|
+
execute(node: BlueprintNode, context: unknown): ExecutionResult;
|
|
797
|
+
}
|
|
798
|
+
/**
|
|
799
|
+
* @zh CanSee 节点模板
|
|
800
|
+
* @en CanSee node template
|
|
801
|
+
*/
|
|
802
|
+
declare const CanSeeTemplate: BlueprintNodeTemplate;
|
|
803
|
+
/**
|
|
804
|
+
* @zh CanSee 节点执行器
|
|
805
|
+
* @en CanSee node executor
|
|
806
|
+
*/
|
|
807
|
+
declare class CanSeeExecutor implements INodeExecutor {
|
|
808
|
+
execute(node: BlueprintNode, context: unknown): ExecutionResult;
|
|
809
|
+
}
|
|
810
|
+
/**
|
|
811
|
+
* @zh OnEntityEnterView 事件节点模板
|
|
812
|
+
* @en OnEntityEnterView event node template
|
|
813
|
+
*/
|
|
814
|
+
declare const OnEntityEnterViewTemplate: BlueprintNodeTemplate;
|
|
815
|
+
/**
|
|
816
|
+
* @zh OnEntityEnterView 事件执行器
|
|
817
|
+
* @en OnEntityEnterView event executor
|
|
818
|
+
*/
|
|
819
|
+
declare class OnEntityEnterViewExecutor implements INodeExecutor {
|
|
820
|
+
execute(_node: BlueprintNode, _context: unknown): ExecutionResult;
|
|
821
|
+
}
|
|
822
|
+
/**
|
|
823
|
+
* @zh OnEntityExitView 事件节点模板
|
|
824
|
+
* @en OnEntityExitView event node template
|
|
825
|
+
*/
|
|
826
|
+
declare const OnEntityExitViewTemplate: BlueprintNodeTemplate;
|
|
827
|
+
/**
|
|
828
|
+
* @zh OnEntityExitView 事件执行器
|
|
829
|
+
* @en OnEntityExitView event executor
|
|
830
|
+
*/
|
|
831
|
+
declare class OnEntityExitViewExecutor implements INodeExecutor {
|
|
832
|
+
execute(_node: BlueprintNode, _context: unknown): ExecutionResult;
|
|
833
|
+
}
|
|
834
|
+
/**
|
|
835
|
+
* @zh AOI 节点定义集合
|
|
836
|
+
* @en AOI node definition collection
|
|
837
|
+
*/
|
|
838
|
+
declare const AOINodeDefinitions: {
|
|
839
|
+
templates: BlueprintNodeTemplate[];
|
|
840
|
+
executors: Map<string, INodeExecutor>;
|
|
841
|
+
};
|
|
842
|
+
|
|
843
|
+
export { type AOIEventListener, type AOIEventType, AOIManagerToken, AOINodeDefinitions, CanSeeExecutor, CanSeeTemplate, FindInRadiusExecutor, FindInRadiusTemplate, FindInRectExecutor, FindInRectTemplate, FindKNearestExecutor, FindKNearestTemplate, FindNearestExecutor, FindNearestTemplate, GetEntitiesInViewExecutor, GetEntitiesInViewTemplate, GetObserversOfExecutor, GetObserversOfTemplate, GridAOI, type GridAOIConfig, GridSpatialIndex, type GridSpatialIndexConfig, type IAOIEvent, type IAOIManager, type IAOIObserverConfig, type IBoundable, type IBounds, type IPositionable, type IRaycastHit, type ISpatialIndex, type ISpatialQuery, OnEntityEnterViewExecutor, OnEntityEnterViewTemplate, OnEntityExitViewExecutor, OnEntityExitViewTemplate, RaycastExecutor, RaycastFirstExecutor, RaycastFirstTemplate, RaycastTemplate, type SpatialFilter, SpatialIndexToken, SpatialQueryNodeDefinitions, SpatialQueryToken, boundsIntersect, boundsIntersectsCircle, createBounds, createBoundsFromCenter, createBoundsFromCircle, createGridAOI, createGridSpatialIndex, distance, distanceSquared, isPointInBounds };
|