gl-draw 0.17.0-beta.39 → 0.17.0-beta.40

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,94 @@
1
+ import type { Camera } from 'three';
2
+ import type Node from './index';
3
+ interface CollisionManagerOptions {
4
+ /** 标签之间的最小间距(像素) */
5
+ padding?: number;
6
+ /** 是否启用碰撞检测 */
7
+ enabled?: boolean;
8
+ /** 更新节流时间(毫秒) */
9
+ throttleTime?: number;
10
+ /** 视口边距,标签超出视口多少像素后隐藏 */
11
+ viewportMargin?: number;
12
+ }
13
+ /**
14
+ * 标签碰撞检测管理器
15
+ * 参考 Mapbox symbol-placement 实现
16
+ *
17
+ * 使用方式:
18
+ * ```ts
19
+ * const manager = new CollisionManager({ padding: 4 });
20
+ * manager.add(node, { priority: 10 });
21
+ * manager.update(camera); // 在渲染循环中调用
22
+ * ```
23
+ */
24
+ export declare class CollisionManager {
25
+ private labels;
26
+ private options;
27
+ private lastUpdateTime;
28
+ private camera?;
29
+ private animationFrameId?;
30
+ private isUpdating;
31
+ constructor(options?: CollisionManagerOptions);
32
+ /**
33
+ * 添加标签到碰撞检测系统
34
+ * @param node Node 实例
35
+ * @param options 配置项,priority 越大越优先显示,不传则使用 node.options.priority
36
+ */
37
+ add(node: Node, options?: {
38
+ priority?: number;
39
+ }): void;
40
+ /**
41
+ * 移除标签
42
+ */
43
+ remove(node: Node): void;
44
+ /**
45
+ * 更新标签优先级
46
+ */
47
+ setPriority(node: Node, priority: number): void;
48
+ /**
49
+ * 批量添加标签
50
+ */
51
+ addBatch(nodes: Node[], priorityFn?: (node: Node, index: number) => number): void;
52
+ /**
53
+ * 启用/禁用碰撞检测
54
+ */
55
+ setEnabled(enabled: boolean): void;
56
+ /**
57
+ * 更新碰撞检测(在渲染循环中调用)
58
+ */
59
+ update(camera: Camera): void;
60
+ /**
61
+ * 强制立即更新
62
+ */
63
+ forceUpdate(): void;
64
+ private performCollisionDetection;
65
+ /**
66
+ * 检测矩形是否与已占用区域碰撞
67
+ */
68
+ private checkCollision;
69
+ /**
70
+ * 检测两个矩形是否相交(包含 padding)
71
+ */
72
+ private rectsIntersect;
73
+ /**
74
+ * 设置节点可见性
75
+ */
76
+ private setNodeVisibility;
77
+ /**
78
+ * 获取当前可见的标签数量
79
+ */
80
+ getVisibleCount(): number;
81
+ /**
82
+ * 获取所有标签数量
83
+ */
84
+ getTotalCount(): number;
85
+ /**
86
+ * 清空所有标签
87
+ */
88
+ clear(): void;
89
+ /**
90
+ * 销毁管理器
91
+ */
92
+ dispose(): void;
93
+ }
94
+ export default CollisionManager;
@@ -2,10 +2,13 @@ import type { Sprite, Vector3 } from 'three';
2
2
  import type { CSS2DObject } from 'three/examples/jsm/renderers/CSS2DRenderer';
3
3
  import BaseObject from "../../core/BaseObject";
4
4
  import type { PickFunctionsItem } from "../../core/Lead/Pick";
5
+ export { CollisionManager } from './CollisionManager';
5
6
  interface Options {
6
7
  children?: HTMLElement;
7
8
  position?: Vector3;
8
9
  type?: '2d' | '3d' | '3dSprite';
10
+ /** 标签优先级,用于碰撞检测时决定显示顺序,数值越大越优先 */
11
+ priority?: number;
9
12
  }
10
13
  export declare class Node extends BaseObject {
11
14
  objectType: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gl-draw",
3
- "version": "0.17.0-beta.39",
3
+ "version": "0.17.0-beta.40",
4
4
  "author": "gitplus <hstits@gmail.com>",
5
5
  "scripts": {
6
6
  "start": "bundler-dev",