zf-twin-3d 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/dist/index.d.ts +1346 -0
- package/dist/index.mjs +10 -0
- package/package.json +37 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,1346 @@
|
|
|
1
|
+
import * as three from 'three';
|
|
2
|
+
import { PerspectiveCamera, Object3D, Group, Mesh, Sprite, WebGLRenderer, Scene } from 'three';
|
|
3
|
+
export * from 'three';
|
|
4
|
+
import { OrbitControls } from 'three/examples/jsm/controls/OrbitControls.js';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* 场景视角控制
|
|
8
|
+
*/
|
|
9
|
+
declare class Camera {
|
|
10
|
+
/** 透视相机实例 */
|
|
11
|
+
readonly pcInstance: PerspectiveCamera;
|
|
12
|
+
/** 轨道控制器 */
|
|
13
|
+
orbitControls?: OrbitControls;
|
|
14
|
+
/** 相机补间分组 */
|
|
15
|
+
private readonly cameraTweenGroup;
|
|
16
|
+
/** 补间开始前记录的轨道阻尼开关,用于结束后恢复 */
|
|
17
|
+
private cameraTweenDampingRestore;
|
|
18
|
+
constructor(width: number, height: number);
|
|
19
|
+
init(domElement: HTMLElement): void;
|
|
20
|
+
/**
|
|
21
|
+
* 推进相机 Tween,须在渲染循环中调用(早于 OrbitControls.update)
|
|
22
|
+
* @param time 毫秒时间戳,默认 performance.now()
|
|
23
|
+
*/
|
|
24
|
+
updateCameraTweens(time?: number): void;
|
|
25
|
+
/**
|
|
26
|
+
* 设置视角
|
|
27
|
+
* @param options 视角参数
|
|
28
|
+
* @example
|
|
29
|
+
* ```
|
|
30
|
+
* this.setCamera({ target: [0, 0, 0], position: [0, 5, 50] });
|
|
31
|
+
* this.setCamera({ target: [0, 0, 0], yaw: 0, pitch: 90, distance: 50 });
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
setCamera(options: {
|
|
35
|
+
/** 观察目标 */
|
|
36
|
+
target: Position;
|
|
37
|
+
/** 相机位置 */
|
|
38
|
+
position: Position;
|
|
39
|
+
/**
|
|
40
|
+
* 过渡时长(秒)
|
|
41
|
+
* @default 2
|
|
42
|
+
*/
|
|
43
|
+
duration?: number;
|
|
44
|
+
} | {
|
|
45
|
+
/** 观察目标 */
|
|
46
|
+
target: Position;
|
|
47
|
+
/** 方位角 */
|
|
48
|
+
yaw: number;
|
|
49
|
+
/** 俯仰角 */
|
|
50
|
+
pitch: number;
|
|
51
|
+
/** 距离 */
|
|
52
|
+
distance: number;
|
|
53
|
+
/**
|
|
54
|
+
* 过渡时长(秒)
|
|
55
|
+
* @default 2
|
|
56
|
+
*/
|
|
57
|
+
duration?: number;
|
|
58
|
+
}): Promise<void>;
|
|
59
|
+
/**
|
|
60
|
+
* 聚焦自定义对象
|
|
61
|
+
* @param object 目标对象
|
|
62
|
+
* @param options 聚焦参数
|
|
63
|
+
* @returns 过渡结束后完成
|
|
64
|
+
*/
|
|
65
|
+
focusObject(object: BaseObject, options?: {
|
|
66
|
+
/**
|
|
67
|
+
* 方位角
|
|
68
|
+
* @default 0
|
|
69
|
+
*/
|
|
70
|
+
yaw?: number;
|
|
71
|
+
/**
|
|
72
|
+
* 俯仰角
|
|
73
|
+
* @default 35
|
|
74
|
+
*/
|
|
75
|
+
pitch?: number;
|
|
76
|
+
/** 距离 */
|
|
77
|
+
distance?: number;
|
|
78
|
+
/**
|
|
79
|
+
* 过渡时长(秒)
|
|
80
|
+
* @default 2
|
|
81
|
+
*/
|
|
82
|
+
duration?: number;
|
|
83
|
+
}): Promise<void>;
|
|
84
|
+
/**
|
|
85
|
+
* 获取当前视角参数
|
|
86
|
+
* @returns 相机位置、观察目标、方位角、俯仰角、与target的距离
|
|
87
|
+
*/
|
|
88
|
+
getCamera(): {
|
|
89
|
+
position: Position;
|
|
90
|
+
target: Position;
|
|
91
|
+
yaw: number;
|
|
92
|
+
pitch: number;
|
|
93
|
+
distance: number;
|
|
94
|
+
};
|
|
95
|
+
/**
|
|
96
|
+
* 沿路径移动相机
|
|
97
|
+
* @param path 路径
|
|
98
|
+
* @param duration 走完全程所用秒数
|
|
99
|
+
*/
|
|
100
|
+
moveCameraAlongPath(path: Position[], duration: number): Promise<void>;
|
|
101
|
+
/**
|
|
102
|
+
* 中断 {@link moveCameraAlongPath} 进行中的路径移动
|
|
103
|
+
*/
|
|
104
|
+
stopCameraPathMovement(): void;
|
|
105
|
+
/**
|
|
106
|
+
* 在渲染器画布上创建官方 OrbitControls(旋转、平移、缩放)
|
|
107
|
+
* @param domElement WebGLRenderer.domElement
|
|
108
|
+
*/
|
|
109
|
+
private attachOrbitControls;
|
|
110
|
+
/**
|
|
111
|
+
* 动画结束后恢复 OrbitControls.enableDamping
|
|
112
|
+
*/
|
|
113
|
+
private finishCameraTweenDamping;
|
|
114
|
+
/**
|
|
115
|
+
* 停止并清空相机动画分组。
|
|
116
|
+
*/
|
|
117
|
+
private clearCameraPoseTweens;
|
|
118
|
+
/**
|
|
119
|
+
* 使用 Tween.js 在指定秒内插值相机位置与观察目标
|
|
120
|
+
*/
|
|
121
|
+
private runCameraPoseTween;
|
|
122
|
+
/**
|
|
123
|
+
* 根据包围盒估算聚焦距离
|
|
124
|
+
* @param bounds 对象包围盒
|
|
125
|
+
*/
|
|
126
|
+
private resolveFocusDistanceByBounds;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/** 物体类型 */
|
|
130
|
+
declare enum ObjectType {
|
|
131
|
+
/** 园区 */
|
|
132
|
+
CAMPUS = "campus",
|
|
133
|
+
/** 建筑 */
|
|
134
|
+
BUILDING = "building",
|
|
135
|
+
/** 楼层 */
|
|
136
|
+
FLOOR = "floor",
|
|
137
|
+
/** 标记 */
|
|
138
|
+
MARKER = "marker",
|
|
139
|
+
/** UI 锚点 */
|
|
140
|
+
UI_ANCHOR = "ui-anchor",
|
|
141
|
+
/** 普通物体 */
|
|
142
|
+
ELEMENT = "element",
|
|
143
|
+
/** 独立模型对象 */
|
|
144
|
+
THING = "thing",
|
|
145
|
+
/** 折线 */
|
|
146
|
+
POLYLINE = "polyline"
|
|
147
|
+
}
|
|
148
|
+
/** 节点名前缀 */
|
|
149
|
+
declare enum ObjectNamePrefix {
|
|
150
|
+
/** 建筑节点名前缀 */
|
|
151
|
+
BUILDING = "building_",
|
|
152
|
+
/** 楼层节点名前缀 */
|
|
153
|
+
FLOOR = "floor_"
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/** 楼层类 */
|
|
157
|
+
declare class Floor extends BaseObject {
|
|
158
|
+
/** 所属建筑 */
|
|
159
|
+
readonly building: Building;
|
|
160
|
+
get parent(): Building;
|
|
161
|
+
constructor(option: FloorOption, app: App);
|
|
162
|
+
/** 绑定楼层节点与 Floor 实例的映射 */
|
|
163
|
+
private bindFloorCustomObject;
|
|
164
|
+
protected disposeOwnedResources(): void;
|
|
165
|
+
/**
|
|
166
|
+
* 建筑整体销毁时 glTF 根已统一 dispose,仅同步本对象状态,避免后续 destroy 重复释放 GPU
|
|
167
|
+
*/
|
|
168
|
+
releaseAfterBuildingDisposed(): void;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
type Nullable<T> = T | null;
|
|
172
|
+
|
|
173
|
+
declare function isCampus(obj: SceneLevelObject): obj is Campus;
|
|
174
|
+
declare function isBuilding(obj: SceneLevelObject): obj is Building;
|
|
175
|
+
declare function isFloor(obj: SceneLevelObject): obj is Floor;
|
|
176
|
+
/** 是否为 Campus glTF 解析出的子对象 */
|
|
177
|
+
declare function isCampusDerivedObject(type: ObjectType): type is ObjectType.BUILDING | ObjectType.FLOOR | ObjectType.ELEMENT;
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* 场景层级
|
|
181
|
+
*/
|
|
182
|
+
declare class SceneLevel {
|
|
183
|
+
private readonly app;
|
|
184
|
+
/** 当前层级对象 */
|
|
185
|
+
private level;
|
|
186
|
+
/** 层级回退记录栈 */
|
|
187
|
+
private levelHistoryStack;
|
|
188
|
+
constructor(app: App);
|
|
189
|
+
/** 获取当前层级对象 */
|
|
190
|
+
get current(): Nullable<SceneLevelObject>;
|
|
191
|
+
/**
|
|
192
|
+
* 按目标类型切换层级
|
|
193
|
+
* @param target 目标层级对象
|
|
194
|
+
*/
|
|
195
|
+
changeLevel(target: SceneLevelObject): void;
|
|
196
|
+
/**
|
|
197
|
+
* 设置默认层级对象
|
|
198
|
+
* @param target 层级对象
|
|
199
|
+
*/
|
|
200
|
+
applyDefault(target: SceneLevelObject): void;
|
|
201
|
+
/**
|
|
202
|
+
* 返回上一级视图
|
|
203
|
+
*/
|
|
204
|
+
goToParentLevel(): void;
|
|
205
|
+
/**
|
|
206
|
+
* 判断 child 是否为 parent 在园区-建筑-楼层树上的直接子级(仅 Campus→Building、Building→Floor)
|
|
207
|
+
* @param parent 父级场景对象
|
|
208
|
+
* @param child 子级场景对象
|
|
209
|
+
*/
|
|
210
|
+
private isImmediateChildLevel;
|
|
211
|
+
/**
|
|
212
|
+
* 按目标对象重建显示状态,确保任意层级切换后显示一致
|
|
213
|
+
* @param target 目标层级对象
|
|
214
|
+
*/
|
|
215
|
+
private syncVisibilityByTarget;
|
|
216
|
+
/**
|
|
217
|
+
* 园区视图:显示园区全部建筑、楼层及附属物
|
|
218
|
+
* @param campus 园区对象
|
|
219
|
+
*/
|
|
220
|
+
private showCampus;
|
|
221
|
+
/**
|
|
222
|
+
* 建筑视图:仅保留目标建筑内部楼层可见,隐藏其他建筑及附属物
|
|
223
|
+
* @param building 建筑对象
|
|
224
|
+
*/
|
|
225
|
+
private showBuilding;
|
|
226
|
+
/**
|
|
227
|
+
* 楼层视图:先切换为建筑视图,再仅显示目标楼层
|
|
228
|
+
* @param floor 楼层对象
|
|
229
|
+
*/
|
|
230
|
+
private showFloor;
|
|
231
|
+
/**
|
|
232
|
+
* 记录当前层级对象与视角,用于回退时恢复
|
|
233
|
+
*/
|
|
234
|
+
private pushCurrentLevelHistory;
|
|
235
|
+
/**
|
|
236
|
+
* 当回退后层级对象与记录一致时恢复视角
|
|
237
|
+
*/
|
|
238
|
+
private restoreCameraIfHistoryMatch;
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
/** 场景事件类型 */
|
|
242
|
+
declare enum SceneEventType {
|
|
243
|
+
/** 场景点击事件 */
|
|
244
|
+
CLICK = "click",
|
|
245
|
+
/** 双击模型事件 */
|
|
246
|
+
DOUBLE_CLICK = "double-click",
|
|
247
|
+
/** 模型移入事件 */
|
|
248
|
+
MOUSE_ENTER = "mouse-enter",
|
|
249
|
+
/** 模型移出事件 */
|
|
250
|
+
MOUSE_LEAVE = "mouse-leave",
|
|
251
|
+
/** 右键双击 */
|
|
252
|
+
RIGHT_DOUBLE_CLICK = "right-double-click",
|
|
253
|
+
/** 场景层级变化 */
|
|
254
|
+
LEVEL_CHANGE = "level-change",
|
|
255
|
+
/** 每帧更新(渲染前) */
|
|
256
|
+
FRAME_UPDATE = "frame-update"
|
|
257
|
+
}
|
|
258
|
+
/** 内置事件键值 */
|
|
259
|
+
declare enum BuiltInEventKey {
|
|
260
|
+
/** 建筑悬浮高亮 */
|
|
261
|
+
BUILDING_HOVER_HIGHLIGHT = "building-hover-highlight",
|
|
262
|
+
/** 场景层级切换 */
|
|
263
|
+
SCENE_LEVEL_SWITCH = "scene-level-switch"
|
|
264
|
+
}
|
|
265
|
+
/** 事件类型与回调的映射 */
|
|
266
|
+
type SceneEventMap = {
|
|
267
|
+
[SceneEventType.CLICK]: {
|
|
268
|
+
/** 位置 */
|
|
269
|
+
position: Position;
|
|
270
|
+
/** 屏幕坐标(相对 canvas) */
|
|
271
|
+
screen: {
|
|
272
|
+
x: number;
|
|
273
|
+
y: number;
|
|
274
|
+
};
|
|
275
|
+
/** 模型对象 */
|
|
276
|
+
object?: Object3D;
|
|
277
|
+
/** 自定义对象实例 */
|
|
278
|
+
customObject?: BaseObject;
|
|
279
|
+
};
|
|
280
|
+
[SceneEventType.DOUBLE_CLICK]: {
|
|
281
|
+
/** 位置 */
|
|
282
|
+
position: Position;
|
|
283
|
+
/** 屏幕坐标(相对 canvas) */
|
|
284
|
+
screen: {
|
|
285
|
+
x: number;
|
|
286
|
+
y: number;
|
|
287
|
+
};
|
|
288
|
+
/** 模型对象 */
|
|
289
|
+
object?: Object3D;
|
|
290
|
+
/** 自定义对象实例 */
|
|
291
|
+
customObject?: BaseObject;
|
|
292
|
+
};
|
|
293
|
+
[SceneEventType.MOUSE_ENTER]: {
|
|
294
|
+
/** 模型对象 */
|
|
295
|
+
object?: Object3D;
|
|
296
|
+
/** 自定义对象实例 */
|
|
297
|
+
customObject?: BaseObject;
|
|
298
|
+
};
|
|
299
|
+
[SceneEventType.MOUSE_LEAVE]: {
|
|
300
|
+
/** 模型对象 */
|
|
301
|
+
object?: Object3D;
|
|
302
|
+
/** 自定义对象实例 */
|
|
303
|
+
customObject?: BaseObject;
|
|
304
|
+
};
|
|
305
|
+
[SceneEventType.RIGHT_DOUBLE_CLICK]: MouseEvent;
|
|
306
|
+
[SceneEventType.LEVEL_CHANGE]: {
|
|
307
|
+
/** 变化前的层级对象 */
|
|
308
|
+
previous: Nullable<SceneLevelObject>;
|
|
309
|
+
/** 变化后的当前层级对象 */
|
|
310
|
+
current: SceneLevelObject;
|
|
311
|
+
};
|
|
312
|
+
[SceneEventType.FRAME_UPDATE]: void;
|
|
313
|
+
};
|
|
314
|
+
|
|
315
|
+
/** 场景事件 */
|
|
316
|
+
declare class SceneEvent {
|
|
317
|
+
private app;
|
|
318
|
+
/** 事件回调集合 */
|
|
319
|
+
private readonly listeners;
|
|
320
|
+
/** 是否已初始化 */
|
|
321
|
+
private isInit;
|
|
322
|
+
/** 内置事件管理器 */
|
|
323
|
+
private readonly builtInEventManager;
|
|
324
|
+
/** 当前悬浮的模型对象 */
|
|
325
|
+
private hoveredObject?;
|
|
326
|
+
/** 最近一次鼠标移动事件 */
|
|
327
|
+
private latestMouseMoveEvent?;
|
|
328
|
+
/** 是否存在待处理的悬浮检测 */
|
|
329
|
+
private hoverDirty;
|
|
330
|
+
/** 用于识别「同一物体」双击事件 */
|
|
331
|
+
private doubleClickPending;
|
|
332
|
+
/** 延迟派发单击的定时器 */
|
|
333
|
+
private deferredClickTimer?;
|
|
334
|
+
/** 最近一次左键在画布上 mousedown 时的屏幕坐标,用于区分点击与拖拽 */
|
|
335
|
+
private primaryButtonDownPosition;
|
|
336
|
+
/** 右键双击:仅按时间间隔配对,记录上一次右键 mousedown 时刻 */
|
|
337
|
+
private rightDoubleClickPending;
|
|
338
|
+
constructor(app: App);
|
|
339
|
+
/** 初始化场景事件 */
|
|
340
|
+
init(): void;
|
|
341
|
+
/**
|
|
342
|
+
* 订阅事件
|
|
343
|
+
* @param event 事件类型
|
|
344
|
+
* @param handler 回调
|
|
345
|
+
*/
|
|
346
|
+
on<T extends SceneEventType>(event: T, handler: (payload: SceneEventMap[T]) => any): void;
|
|
347
|
+
/**
|
|
348
|
+
* 取消订阅
|
|
349
|
+
* @param event 事件类型
|
|
350
|
+
* @param handler 与订阅时相同的回调引用
|
|
351
|
+
*/
|
|
352
|
+
off(event: SceneEventType, handler: (...args: any[]) => any): void;
|
|
353
|
+
/**
|
|
354
|
+
* 订阅一次事件
|
|
355
|
+
* @param event 事件类型
|
|
356
|
+
* @param handler 回调
|
|
357
|
+
*/
|
|
358
|
+
once<T extends SceneEventType>(event: T, handler: (payload: SceneEventMap[T]) => any): void;
|
|
359
|
+
/** 每帧更新:执行内置逻辑并派发给订阅者 */
|
|
360
|
+
tickFrame(): void;
|
|
361
|
+
/** 每帧处理一次鼠标悬浮检测 */
|
|
362
|
+
private processHover;
|
|
363
|
+
/**
|
|
364
|
+
* 暂停指定内置事件
|
|
365
|
+
* @param eventKey 内置事件键值
|
|
366
|
+
*/
|
|
367
|
+
pauseBuiltInEvent(eventKey: BuiltInEventKey): void;
|
|
368
|
+
/**
|
|
369
|
+
* 恢复指定内置事件
|
|
370
|
+
* @param eventKey 内置事件键值
|
|
371
|
+
*/
|
|
372
|
+
resumeBuiltInEvent(eventKey: BuiltInEventKey): void;
|
|
373
|
+
/** 触发事件 */
|
|
374
|
+
emit<T extends SceneEventType>(event: T, payload: SceneEventMap[T]): void;
|
|
375
|
+
/**
|
|
376
|
+
* 处理画布点击
|
|
377
|
+
*/
|
|
378
|
+
private handleCanvasClick;
|
|
379
|
+
/** 清除延迟派发单击的定时器 */
|
|
380
|
+
private clearDeferredClickTimer;
|
|
381
|
+
/**
|
|
382
|
+
* 在双击判定窗口结束时:要么派发延迟的单击,要么仅清除待配对状态(仅订阅双击时)
|
|
383
|
+
*/
|
|
384
|
+
private scheduleDeferredClickResolution;
|
|
385
|
+
/**
|
|
386
|
+
* 处理画布 mousedown:左键记录起点以过滤拖拽后的误触 click;右键处理双击事件
|
|
387
|
+
*/
|
|
388
|
+
private handleCanvasMouseDown;
|
|
389
|
+
/**
|
|
390
|
+
* 处理画布鼠标移动
|
|
391
|
+
*/
|
|
392
|
+
private handleCanvasMouseMove;
|
|
393
|
+
/**
|
|
394
|
+
* 是否存在对应事件监听器
|
|
395
|
+
* @param event 事件类型
|
|
396
|
+
*/
|
|
397
|
+
private hasListeners;
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
/**
|
|
401
|
+
* 默认场景灯光
|
|
402
|
+
*/
|
|
403
|
+
declare class SceneLights {
|
|
404
|
+
private app;
|
|
405
|
+
constructor(app: App);
|
|
406
|
+
/**
|
|
407
|
+
* 初始化场景灯光
|
|
408
|
+
*/
|
|
409
|
+
private init;
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
/** 独立模型对象 */
|
|
413
|
+
declare class Thing extends BaseObject<Group> {
|
|
414
|
+
/** 是否已订阅帧更新 */
|
|
415
|
+
private isFrameUpdateSubscribed;
|
|
416
|
+
/** 路径移动 Tween 分组 */
|
|
417
|
+
private pathTweenGroup;
|
|
418
|
+
/** 进行中的路径移动 Tween */
|
|
419
|
+
private pathTween;
|
|
420
|
+
/** 是否存在正在运行且未暂停的模型动画 */
|
|
421
|
+
isAnimationPlaying: boolean;
|
|
422
|
+
/** 动画片段 */
|
|
423
|
+
private animationClips;
|
|
424
|
+
/** 模型动画混合器 */
|
|
425
|
+
private animationMixer;
|
|
426
|
+
/** 按名称缓存的动画动作 */
|
|
427
|
+
private animationActions;
|
|
428
|
+
/** 模型动画帧间隔计时 */
|
|
429
|
+
private animationTimer;
|
|
430
|
+
constructor(option: ThingOption, app: App);
|
|
431
|
+
/**
|
|
432
|
+
* 模型内嵌动画名称列表
|
|
433
|
+
*/
|
|
434
|
+
get animationNames(): readonly string[];
|
|
435
|
+
/**
|
|
436
|
+
* 播放指定模型动画
|
|
437
|
+
* @param name 动画名称,见 {@link animationNames}
|
|
438
|
+
* @param loop 是否循环播放,默认 true
|
|
439
|
+
*/
|
|
440
|
+
playAnimation(name: string, loop?: boolean): void;
|
|
441
|
+
/**
|
|
442
|
+
* 暂停指定模型动画
|
|
443
|
+
* @param name 动画名称
|
|
444
|
+
*/
|
|
445
|
+
pauseAnimation(name: string): void;
|
|
446
|
+
/**
|
|
447
|
+
* 继续播放已暂停的模型动画
|
|
448
|
+
* @param name 动画名称
|
|
449
|
+
*/
|
|
450
|
+
resumeAnimation(name: string): void;
|
|
451
|
+
/**
|
|
452
|
+
* 停止指定模型动画并重置到起始帧
|
|
453
|
+
* @param name 动画名称
|
|
454
|
+
*/
|
|
455
|
+
stopAnimation(name: string): void;
|
|
456
|
+
/** 设置世界位置;模型底部对齐 Y 轴 */
|
|
457
|
+
setPosition(position: Position): void;
|
|
458
|
+
/** 设置相对父对象的位置;模型底部对齐父级局部 Y */
|
|
459
|
+
setLocalPosition(localPosition: Position): void;
|
|
460
|
+
/**
|
|
461
|
+
* 沿路径移动模型
|
|
462
|
+
* @param path 路径
|
|
463
|
+
* @param duration 走完全程所用秒数
|
|
464
|
+
* @param loop 是否循环执行,默认 false;为 true 时 Promise 仅在 {@link stopPathMovement} 后 resolve
|
|
465
|
+
*/
|
|
466
|
+
moveAlongPath(path: Position[], duration: number, loop?: boolean): Promise<void>;
|
|
467
|
+
/** 中断 {@link moveAlongPath} 进行中的路径移动 */
|
|
468
|
+
stopPathMovement(): void;
|
|
469
|
+
protected disposeOwnedResources(): void;
|
|
470
|
+
protected afterDisposeResources(): void;
|
|
471
|
+
/**
|
|
472
|
+
* 按路径切线设置朝向(仅 Y 轴,避免 lookAt 与 GLTF 模型轴向冲突)
|
|
473
|
+
* @param position 当前位置
|
|
474
|
+
* @param lookTarget 朝向前瞻点
|
|
475
|
+
*/
|
|
476
|
+
private setPathYaw;
|
|
477
|
+
/**
|
|
478
|
+
* 加载 GLTF 模型并挂载到场景
|
|
479
|
+
* @param url 模型资源地址
|
|
480
|
+
* @param onReady 加载完成回调
|
|
481
|
+
*/
|
|
482
|
+
private loadModel;
|
|
483
|
+
/**
|
|
484
|
+
* 按名称获取或创建动画动作
|
|
485
|
+
* @param name 动画名称
|
|
486
|
+
*/
|
|
487
|
+
private getAnimationAction;
|
|
488
|
+
/** 根据各 AnimationAction 运行状态同步 {@link isAnimationPlaying} */
|
|
489
|
+
private syncAnimationPlaying;
|
|
490
|
+
/** 单次非循环动画结束时的混合器回调 */
|
|
491
|
+
private handleAnimationFinished;
|
|
492
|
+
/** 按需初始化路径动画资源并订阅帧更新 */
|
|
493
|
+
private ensurePathAnimation;
|
|
494
|
+
/** 按需初始化动画资源并订阅帧更新 */
|
|
495
|
+
private ensureAnimation;
|
|
496
|
+
/** 按需订阅帧更新 */
|
|
497
|
+
private ensureFrameUpdate;
|
|
498
|
+
/** 帧更新回调:推进路径 Tween 与 AnimationMixer */
|
|
499
|
+
private handleFrameUpdate;
|
|
500
|
+
}
|
|
501
|
+
|
|
502
|
+
/** 折线 */
|
|
503
|
+
declare class Polyline extends BaseObject<Mesh> {
|
|
504
|
+
/** 路径数据 */
|
|
505
|
+
private points;
|
|
506
|
+
/** 线宽(单位米) */
|
|
507
|
+
private width;
|
|
508
|
+
/** 拐角圆角半径(单位米) */
|
|
509
|
+
private cornerRadius;
|
|
510
|
+
/** 拐角圆角细分段数 */
|
|
511
|
+
private cornerSegments;
|
|
512
|
+
/** 线条颜色 */
|
|
513
|
+
private color;
|
|
514
|
+
/** 线条材质 */
|
|
515
|
+
private meshMaterial;
|
|
516
|
+
/** 贴图路径 */
|
|
517
|
+
private imagePath;
|
|
518
|
+
/** 贴图沿路径滚动速度(米/秒) */
|
|
519
|
+
private textureScrollSpeed;
|
|
520
|
+
/** 贴图沿路径方向一个完整图案占用的世界长度(米) */
|
|
521
|
+
private textureWorldSize;
|
|
522
|
+
/** 贴图沿路径方向相邻图案之间的空隙长度(米) */
|
|
523
|
+
private textureGap;
|
|
524
|
+
/** 是否启用贴图滚动 */
|
|
525
|
+
private enableTextureScroll;
|
|
526
|
+
/** 贴图实例 */
|
|
527
|
+
private texture;
|
|
528
|
+
/** 贴图滚动累积偏移(米) */
|
|
529
|
+
private textureScrollOffset;
|
|
530
|
+
/** 传给材质的图案占周期比例 uniform(图案长度 / 周期长度) */
|
|
531
|
+
private readonly textureImageFractionUniform;
|
|
532
|
+
/** 是否已订阅帧更新 */
|
|
533
|
+
private isFrameUpdateSubscribed;
|
|
534
|
+
/** 帧间隔计时 */
|
|
535
|
+
private frameTimer;
|
|
536
|
+
constructor(option: PolylineOption, app: App);
|
|
537
|
+
/**
|
|
538
|
+
* 设置路径数据
|
|
539
|
+
* @param points 世界坐标路径点
|
|
540
|
+
*/
|
|
541
|
+
setPoints(points: Position[]): void;
|
|
542
|
+
/**
|
|
543
|
+
* 设置线宽
|
|
544
|
+
* @param width 线宽(单位米)
|
|
545
|
+
*/
|
|
546
|
+
setWidth(width: number): void;
|
|
547
|
+
/**
|
|
548
|
+
* 设置拐角圆角半径
|
|
549
|
+
* @param cornerRadius 圆角半径(单位米);0 表示直角
|
|
550
|
+
*/
|
|
551
|
+
setCornerRadius(cornerRadius: number): void;
|
|
552
|
+
/**
|
|
553
|
+
* 设置拐角圆角细分段数
|
|
554
|
+
* @param cornerSegments 数值越大圆角越平滑
|
|
555
|
+
*/
|
|
556
|
+
setCornerSegments(cornerSegments: number): void;
|
|
557
|
+
/**
|
|
558
|
+
* 设置线条颜色
|
|
559
|
+
* @param color 支持 #rgb/#rrggbb、rgb()、rgba() 及 CSS 命名色
|
|
560
|
+
*/
|
|
561
|
+
setColor(color: string): void;
|
|
562
|
+
/**
|
|
563
|
+
* 设置贴图路径
|
|
564
|
+
* @param imagePath 图片地址
|
|
565
|
+
*/
|
|
566
|
+
setImagePath(imagePath: string): void;
|
|
567
|
+
/**
|
|
568
|
+
* 设置贴图沿路径滚动速度
|
|
569
|
+
* @param speed 速度(米/秒);正数沿路径正向
|
|
570
|
+
*/
|
|
571
|
+
setTextureScrollSpeed(speed: number): void;
|
|
572
|
+
/**
|
|
573
|
+
* 设置贴图沿路径方向一个完整图案占用的世界长度
|
|
574
|
+
* @param textureWorldSize 世界长度(米);值越大图案越稀疏
|
|
575
|
+
*/
|
|
576
|
+
setTextureWorldSize(textureWorldSize: number): void;
|
|
577
|
+
/**
|
|
578
|
+
* 设置贴图沿路径方向相邻图案之间的空隙长度
|
|
579
|
+
* @param textureGap 空隙长度(米);值越大图案间距越大,空隙区域透明
|
|
580
|
+
*/
|
|
581
|
+
setTextureGap(textureGap: number): void;
|
|
582
|
+
/**
|
|
583
|
+
* 设置是否启用贴图滚动
|
|
584
|
+
* @param enable 是否滚动
|
|
585
|
+
*/
|
|
586
|
+
setEnableTextureScroll(enable: boolean): void;
|
|
587
|
+
protected disposeOwnedResources(): void;
|
|
588
|
+
protected afterDisposeResources(): void;
|
|
589
|
+
/** 创建折线并挂载到场景 */
|
|
590
|
+
private buildLine;
|
|
591
|
+
/** 按当前路径重建几何体 */
|
|
592
|
+
private rebuildGeometry;
|
|
593
|
+
/** 根据当前状态构建网格几何体 */
|
|
594
|
+
private createMeshGeometry;
|
|
595
|
+
/** 加载贴图并应用到材质 */
|
|
596
|
+
private loadTexture;
|
|
597
|
+
/** 将贴图应用到当前材质 */
|
|
598
|
+
private applyTexturedMaterial;
|
|
599
|
+
/** 根据累积偏移更新贴图 UV 偏移 */
|
|
600
|
+
private applyTextureOffset;
|
|
601
|
+
/** 设置贴图包裹模式 */
|
|
602
|
+
private applyTextureWrap;
|
|
603
|
+
/** 按需订阅或取消帧更新 */
|
|
604
|
+
private syncFrameSubscription;
|
|
605
|
+
/** 订阅全局帧更新 */
|
|
606
|
+
private ensureFrameUpdate;
|
|
607
|
+
/** 取消帧更新订阅 */
|
|
608
|
+
private unsubscribeFrameUpdate;
|
|
609
|
+
/** 帧更新:推进贴图滚动 */
|
|
610
|
+
private handleFrameUpdate;
|
|
611
|
+
/** 是否应生成贴图 UV */
|
|
612
|
+
private shouldUseTextureUv;
|
|
613
|
+
/** 同步「图案占周期比例」到材质 uniform */
|
|
614
|
+
private updateTextureImageFraction;
|
|
615
|
+
/** 贴图布局参数变更后重建几何并同步偏移 */
|
|
616
|
+
private refreshTextureLayout;
|
|
617
|
+
private disposeMaterial;
|
|
618
|
+
}
|
|
619
|
+
|
|
620
|
+
/** 标记 */
|
|
621
|
+
declare class Marker extends BaseObject<Sprite | Mesh> {
|
|
622
|
+
/** 图片宽高比 */
|
|
623
|
+
private textureAspect;
|
|
624
|
+
/** 图片路径 */
|
|
625
|
+
private readonly imagePath;
|
|
626
|
+
/** 是否以 3D 模型展示 */
|
|
627
|
+
private readonly is3D;
|
|
628
|
+
/** 是否保持近大远小 */
|
|
629
|
+
private readonly enablePerspectiveScale;
|
|
630
|
+
/** 标记尺寸:[宽度, 高度] */
|
|
631
|
+
private readonly size;
|
|
632
|
+
constructor(option: MarkerOption, app: App);
|
|
633
|
+
setScale(scale: Scale): void;
|
|
634
|
+
setRotation(rotation: Rotation): void;
|
|
635
|
+
setPosition(position: Position): void;
|
|
636
|
+
/** 加载贴图并创建标记 */
|
|
637
|
+
private loadTexture;
|
|
638
|
+
protected disposeOwnedResources(): void;
|
|
639
|
+
/**
|
|
640
|
+
* 根据像素尺寸计算当前帧世界尺度
|
|
641
|
+
* @param sprite 标记精灵
|
|
642
|
+
* @param camera 当前相机
|
|
643
|
+
*/
|
|
644
|
+
private applyPixelScale;
|
|
645
|
+
/**
|
|
646
|
+
* 创建 2D 标记
|
|
647
|
+
* @param texture 贴图资源
|
|
648
|
+
*/
|
|
649
|
+
private createSpriteMarker;
|
|
650
|
+
/**
|
|
651
|
+
* 创建 3D 标记
|
|
652
|
+
* @param texture 贴图资源
|
|
653
|
+
*/
|
|
654
|
+
private createMeshMarker;
|
|
655
|
+
}
|
|
656
|
+
|
|
657
|
+
/**
|
|
658
|
+
* 轮廓高亮后处理管线(基于 OutlinePass)
|
|
659
|
+
*/
|
|
660
|
+
declare class OutlineHighlighter {
|
|
661
|
+
private readonly renderer;
|
|
662
|
+
private readonly scene;
|
|
663
|
+
private readonly camera;
|
|
664
|
+
/** 后处理合成器 */
|
|
665
|
+
private readonly composer;
|
|
666
|
+
/** 轮廓通道 */
|
|
667
|
+
private readonly outlinePass;
|
|
668
|
+
constructor(renderer: WebGLRenderer, scene: Scene, camera: PerspectiveCamera);
|
|
669
|
+
/**
|
|
670
|
+
* 同步后处理画布尺寸
|
|
671
|
+
* @param width 画布宽度(CSS 像素)
|
|
672
|
+
* @param height 画布高度(CSS 像素)
|
|
673
|
+
*/
|
|
674
|
+
resize(width: number, height: number): void;
|
|
675
|
+
/** 使用后处理通道渲染当前帧 */
|
|
676
|
+
render(): void;
|
|
677
|
+
/**
|
|
678
|
+
* 设置轮廓选中的物体
|
|
679
|
+
* @param object 场景节点
|
|
680
|
+
*/
|
|
681
|
+
setSelection(object: Object3D): void;
|
|
682
|
+
/** 清空轮廓选中 */
|
|
683
|
+
clearSelection(): void;
|
|
684
|
+
/** 释放合成器及相关 GPU 资源 */
|
|
685
|
+
dispose(): void;
|
|
686
|
+
}
|
|
687
|
+
|
|
688
|
+
/** 查询结果过滤函数 */
|
|
689
|
+
type SelectionPredicate<T extends BaseObject> = (item: T, index: number) => boolean;
|
|
690
|
+
/** 查询结果类型守卫过滤函数 */
|
|
691
|
+
type SelectionTypeGuard<T extends BaseObject, S extends T> = (item: T, index: number) => item is S;
|
|
692
|
+
/** 业务对象查询结果集 */
|
|
693
|
+
declare class ObjectSelection<T extends BaseObject = BaseObject> {
|
|
694
|
+
/** 快照结果集合 */
|
|
695
|
+
private readonly selectedItems;
|
|
696
|
+
constructor(items: Iterable<T>);
|
|
697
|
+
/** 获取结果快照 */
|
|
698
|
+
items(): T[];
|
|
699
|
+
/** 获取第一个匹配结果 */
|
|
700
|
+
get first(): T | undefined;
|
|
701
|
+
/**
|
|
702
|
+
* 遍历结果集
|
|
703
|
+
* @param fn 遍历函数
|
|
704
|
+
*/
|
|
705
|
+
forEach(fn: (item: T, index: number) => void): this;
|
|
706
|
+
/**
|
|
707
|
+
* 过滤结果集
|
|
708
|
+
* @param predicate 过滤函数。可为普通断言函数或类型守卫函数。
|
|
709
|
+
* @example
|
|
710
|
+
* ```
|
|
711
|
+
* // 传入普通谓词,返回 ObjectSelection<BaseObject>
|
|
712
|
+
* const visibleSelection = selection.filter((item, index) => {
|
|
713
|
+
* return item.visible && index < 10;
|
|
714
|
+
* });
|
|
715
|
+
*
|
|
716
|
+
* // 传入类型守卫谓词,返回 ObjectSelection<Building>
|
|
717
|
+
* const buildingSelection = selection.filter(
|
|
718
|
+
* (item): item is Building => item.type === ObjectType.BUILDING
|
|
719
|
+
* );
|
|
720
|
+
* ```
|
|
721
|
+
*/
|
|
722
|
+
filter<S extends T>(predicate: SelectionTypeGuard<T, S>): ObjectSelection<S>;
|
|
723
|
+
filter(predicate: SelectionPredicate<T>): ObjectSelection<T>;
|
|
724
|
+
/**
|
|
725
|
+
* 批量控制显隐
|
|
726
|
+
* @param visible 是否可见
|
|
727
|
+
*/
|
|
728
|
+
setVisible(visible: boolean): this;
|
|
729
|
+
}
|
|
730
|
+
|
|
731
|
+
/** 业务对象查询器 */
|
|
732
|
+
declare class ObjectQuery {
|
|
733
|
+
private readonly app;
|
|
734
|
+
constructor(app: App);
|
|
735
|
+
queryAll(): ObjectSelection<BaseObject<three.Object3D<three.Object3DEventMap>>>;
|
|
736
|
+
/**
|
|
737
|
+
* 根据对象名称查询
|
|
738
|
+
* @param name 对象名称
|
|
739
|
+
* @param option 查询参数
|
|
740
|
+
*/
|
|
741
|
+
queryByName(name: string, option?: {
|
|
742
|
+
/**
|
|
743
|
+
* 是否精确匹配
|
|
744
|
+
* @default true
|
|
745
|
+
*/
|
|
746
|
+
exact?: boolean;
|
|
747
|
+
/**
|
|
748
|
+
* 是否大小写敏感
|
|
749
|
+
* @default true
|
|
750
|
+
*/
|
|
751
|
+
caseSensitive?: boolean;
|
|
752
|
+
}): ObjectSelection<BaseObject<three.Object3D<three.Object3DEventMap>>>;
|
|
753
|
+
/**
|
|
754
|
+
* 根据对象唯一标识查询
|
|
755
|
+
* @param id 对象 id
|
|
756
|
+
*/
|
|
757
|
+
queryById(id: string): ObjectSelection<BaseObject<three.Object3D<three.Object3DEventMap>>>;
|
|
758
|
+
/**
|
|
759
|
+
* 根据对象类型查询
|
|
760
|
+
* @param type 对象类型
|
|
761
|
+
*/
|
|
762
|
+
queryByType(type: ObjectType.CAMPUS): ObjectSelection<Campus>;
|
|
763
|
+
queryByType(type: ObjectType.BUILDING): ObjectSelection<Building>;
|
|
764
|
+
queryByType(type: ObjectType.FLOOR): ObjectSelection<Floor>;
|
|
765
|
+
queryByType(type: ObjectType.MARKER): ObjectSelection<Marker>;
|
|
766
|
+
queryByType(type: ObjectType.UI_ANCHOR): ObjectSelection<UIAnchor>;
|
|
767
|
+
queryByType(type: ObjectType.ELEMENT): ObjectSelection<Element>;
|
|
768
|
+
queryByType(type: ObjectType): ObjectSelection<BaseObject>;
|
|
769
|
+
/**
|
|
770
|
+
* 归一化对象名称
|
|
771
|
+
* @param name 对象名称
|
|
772
|
+
* @param caseSensitive 是否大小写敏感
|
|
773
|
+
*/
|
|
774
|
+
private normalizeName;
|
|
775
|
+
}
|
|
776
|
+
|
|
777
|
+
/**
|
|
778
|
+
* 场景入口\
|
|
779
|
+
* 负责初始化场景,管理场景中的所有对象
|
|
780
|
+
*/
|
|
781
|
+
declare class App {
|
|
782
|
+
/** 场景 */
|
|
783
|
+
readonly scene: Scene;
|
|
784
|
+
/** 相机 */
|
|
785
|
+
readonly camera: Camera;
|
|
786
|
+
/** 渲染器 */
|
|
787
|
+
readonly renderer: WebGLRenderer;
|
|
788
|
+
/** 场景灯光 */
|
|
789
|
+
readonly sceneLights: SceneLights;
|
|
790
|
+
/** 场景事件 */
|
|
791
|
+
readonly sceneEvent: SceneEvent;
|
|
792
|
+
/** 轮廓高亮后处理 */
|
|
793
|
+
readonly outlineHighlighter: OutlineHighlighter;
|
|
794
|
+
/** 当前场景层级(园区 / 建筑 / 楼层) */
|
|
795
|
+
readonly sceneLevel: SceneLevel;
|
|
796
|
+
/** 业务对象查询器 */
|
|
797
|
+
readonly objectQuery: ObjectQuery;
|
|
798
|
+
/** 自定义 3D 对象集合 */
|
|
799
|
+
readonly customObjects: Set<BaseObject<three.Object3D<three.Object3DEventMap>>>;
|
|
800
|
+
/** 容器元素 */
|
|
801
|
+
private containerEl?;
|
|
802
|
+
/** 窗口尺寸变化观察器 */
|
|
803
|
+
private resizeObserver?;
|
|
804
|
+
constructor();
|
|
805
|
+
/** 根据容器 id 初始化渲染器、相机与空场景 */
|
|
806
|
+
init(containerId: string): void;
|
|
807
|
+
/**
|
|
808
|
+
* 从自定义对象集合中移除
|
|
809
|
+
* @param customObject 已注册对象
|
|
810
|
+
*/
|
|
811
|
+
unregisterCustomObject(customObject: BaseObject): void;
|
|
812
|
+
/** 创建物体 */
|
|
813
|
+
create(option: CampusOption): Campus;
|
|
814
|
+
create(option: MarkerOption): Marker;
|
|
815
|
+
create(option: UIAnchorOption): UIAnchor;
|
|
816
|
+
create(option: ThingOption): Thing;
|
|
817
|
+
create(option: PolylineOption): Polyline;
|
|
818
|
+
/**
|
|
819
|
+
* 设置天空盒
|
|
820
|
+
* @param imgUrls 图片地址,顺序为:[px, nx, py, ny, pz, nz]
|
|
821
|
+
*/
|
|
822
|
+
setSkyBox(imgUrls: string[]): void;
|
|
823
|
+
/** 根据容器当前大小同步相机与渲染器 */
|
|
824
|
+
private syncSize;
|
|
825
|
+
/** 每帧:更新轨道控制、派发帧事件并渲染 */
|
|
826
|
+
private runFrame;
|
|
827
|
+
/** 处理窗口尺寸变化 */
|
|
828
|
+
private handleWindowResize;
|
|
829
|
+
/**
|
|
830
|
+
* 根据画面大小同步相机纵横比
|
|
831
|
+
*/
|
|
832
|
+
private syncAspect;
|
|
833
|
+
/** 初始化渲染器 */
|
|
834
|
+
private initRenderer;
|
|
835
|
+
}
|
|
836
|
+
|
|
837
|
+
type ElementOption = {
|
|
838
|
+
object3D: Mesh | Group;
|
|
839
|
+
parent: BaseObject;
|
|
840
|
+
/** 对象唯一标识;未传时与节点 name 一致 */
|
|
841
|
+
id?: string;
|
|
842
|
+
};
|
|
843
|
+
/**
|
|
844
|
+
* 场景元素\
|
|
845
|
+
* 某类业务场景下,解析完业务对象后,额外的模型对象则视为场景元素
|
|
846
|
+
*/
|
|
847
|
+
declare class Element extends BaseObject<Mesh | Group> {
|
|
848
|
+
get parent(): BaseObject;
|
|
849
|
+
constructor(option: ElementOption, app: App);
|
|
850
|
+
/**
|
|
851
|
+
* 仅同步本对象状态,避免后续 destroy 重复释放 GPU
|
|
852
|
+
*/
|
|
853
|
+
releaseAfterCampusDisposed(): void;
|
|
854
|
+
protected beforeDisposeResources(): void;
|
|
855
|
+
protected disposeOwnedResources(): void;
|
|
856
|
+
private bindElementCustomObject;
|
|
857
|
+
}
|
|
858
|
+
|
|
859
|
+
/** 园区类 */
|
|
860
|
+
declare class Campus extends BaseObject {
|
|
861
|
+
/** 建筑列表 */
|
|
862
|
+
readonly buildings: Building[];
|
|
863
|
+
/** 普通物体列表 */
|
|
864
|
+
readonly otherElements: Element[];
|
|
865
|
+
constructor(option: CampusOption, app: App);
|
|
866
|
+
/**
|
|
867
|
+
* 从园区建筑列表中摘除建筑
|
|
868
|
+
* @param building 建筑实例
|
|
869
|
+
*/
|
|
870
|
+
detachBuilding(building: Building): void;
|
|
871
|
+
/**
|
|
872
|
+
* 加载模型并添加到场景
|
|
873
|
+
* @param url 模型地址
|
|
874
|
+
*/
|
|
875
|
+
private loadModel;
|
|
876
|
+
protected disposeOwnedResources(): void;
|
|
877
|
+
/** 解析建筑 */
|
|
878
|
+
private parseBuildings;
|
|
879
|
+
/** 获取 Mesh 的父节点,如果父节点是 Group,则返回父节点,否则返回 Mesh 自身 */
|
|
880
|
+
private getParentGroup;
|
|
881
|
+
/**
|
|
882
|
+
* 判断 glTF 节点名是否为独立建筑根(如 building_YFDL;building_YFDL_xxx 则不是)
|
|
883
|
+
* @param name 节点名称
|
|
884
|
+
*/
|
|
885
|
+
private isBuildingName;
|
|
886
|
+
/**
|
|
887
|
+
* 判断节点名是否属于建筑体系(包含建筑根节点及其拆分后的子 Mesh)
|
|
888
|
+
*/
|
|
889
|
+
private isBuildingRelatedName;
|
|
890
|
+
/**
|
|
891
|
+
* 判断节点名是否属于楼层体系(包含楼层根节点及其拆分后的子 Mesh)
|
|
892
|
+
*/
|
|
893
|
+
private isFloorRelatedName;
|
|
894
|
+
}
|
|
895
|
+
|
|
896
|
+
/** 建筑类 */
|
|
897
|
+
declare class Building extends BaseObject {
|
|
898
|
+
/** 所属园区 */
|
|
899
|
+
readonly campus: Campus;
|
|
900
|
+
get parent(): Campus;
|
|
901
|
+
/** 楼层列表 */
|
|
902
|
+
readonly floors: Floor[];
|
|
903
|
+
constructor(option: BuildingOption, app: App);
|
|
904
|
+
/** 绑定建筑节点与 Building 实例的映射 */
|
|
905
|
+
private bindBuildingCustomObject;
|
|
906
|
+
/** 解析当前建筑下的楼层 */
|
|
907
|
+
private parseFloors;
|
|
908
|
+
/**
|
|
909
|
+
* 从建筑楼层列表中摘除楼层
|
|
910
|
+
* @param floor 楼层实例
|
|
911
|
+
*/
|
|
912
|
+
detachFloor(floor: Floor): void;
|
|
913
|
+
/**
|
|
914
|
+
* 设置建筑显隐
|
|
915
|
+
* @param visible 是否可见
|
|
916
|
+
* @param withFloors 是否同步楼层显隐,默认同步
|
|
917
|
+
*/
|
|
918
|
+
setVisible(visible: boolean, withFloors?: boolean): void;
|
|
919
|
+
protected disposeOwnedResources(): void;
|
|
920
|
+
/**
|
|
921
|
+
* 园区整体销毁时 glTF 根已统一 dispose,仅同步本对象状态,避免后续 destroy 重复释放 GPU
|
|
922
|
+
*/
|
|
923
|
+
releaseAfterCampusDisposed(): void;
|
|
924
|
+
}
|
|
925
|
+
|
|
926
|
+
/** 对象就绪回调 */
|
|
927
|
+
type OnObjectReady<T> = (instance: T) => void;
|
|
928
|
+
/** 标记对象初始化参数 */
|
|
929
|
+
interface MarkerOption {
|
|
930
|
+
/** 物体类型 */
|
|
931
|
+
type: ObjectType.MARKER;
|
|
932
|
+
/** 对象名称 */
|
|
933
|
+
name?: string;
|
|
934
|
+
/** 对象唯一标识;未传时与 name 一致 */
|
|
935
|
+
id?: string;
|
|
936
|
+
/** 位置 */
|
|
937
|
+
position: Position;
|
|
938
|
+
/** 图片路径 */
|
|
939
|
+
imagePath: string;
|
|
940
|
+
/**
|
|
941
|
+
* 是否以 3D 模式展示
|
|
942
|
+
* @default false
|
|
943
|
+
*/
|
|
944
|
+
is3D?: boolean;
|
|
945
|
+
/**
|
|
946
|
+
* 标记尺寸:[宽度, 高度]
|
|
947
|
+
* - is3D = false:屏幕像素尺寸
|
|
948
|
+
* - is3D = true:世界尺寸(单位米)
|
|
949
|
+
*/
|
|
950
|
+
size: [number, number];
|
|
951
|
+
/**
|
|
952
|
+
* 是否保持近大远小
|
|
953
|
+
* @default false
|
|
954
|
+
*/
|
|
955
|
+
enablePerspectiveScale?: boolean;
|
|
956
|
+
/**
|
|
957
|
+
* 缩放;is3D = true 时生效
|
|
958
|
+
* @default [1, 1, 1]
|
|
959
|
+
*/
|
|
960
|
+
scale?: Scale;
|
|
961
|
+
/**
|
|
962
|
+
* 欧拉角旋转(单位度),顺序 XYZ;is3D = true 时生效
|
|
963
|
+
* @default [0, 0, 0]
|
|
964
|
+
*/
|
|
965
|
+
rotation?: Rotation;
|
|
966
|
+
/** 层级父对象 */
|
|
967
|
+
parent?: BaseObject;
|
|
968
|
+
/** 对象就绪回调 */
|
|
969
|
+
onReady?: OnObjectReady<Marker>;
|
|
970
|
+
}
|
|
971
|
+
/** UI 锚点初始化参数 */
|
|
972
|
+
interface UIAnchorOption {
|
|
973
|
+
/** 物体类型 */
|
|
974
|
+
type: ObjectType.UI_ANCHOR;
|
|
975
|
+
/** 对象名称 */
|
|
976
|
+
name?: string;
|
|
977
|
+
/** 对象唯一标识;未传时与 name 一致 */
|
|
978
|
+
id?: string;
|
|
979
|
+
/**
|
|
980
|
+
* 是否以 3D 模式展示
|
|
981
|
+
* @default false
|
|
982
|
+
*/
|
|
983
|
+
is3D?: boolean;
|
|
984
|
+
/**
|
|
985
|
+
* 需要挂载的 DOM 元素\
|
|
986
|
+
* is3D ? HTMLCanvasElement : HTMLElement
|
|
987
|
+
*/
|
|
988
|
+
element: HTMLElement | HTMLCanvasElement;
|
|
989
|
+
/** 世界坐标 */
|
|
990
|
+
position: Position;
|
|
991
|
+
/**
|
|
992
|
+
* 屏幕像素偏移 [x, y]
|
|
993
|
+
* @default [0, -12]
|
|
994
|
+
*/
|
|
995
|
+
offsetPx?: [number, number];
|
|
996
|
+
/**
|
|
997
|
+
* 缩放;is3D = true 时生效
|
|
998
|
+
* @default [1, 1, 1]
|
|
999
|
+
*/
|
|
1000
|
+
scale?: Scale;
|
|
1001
|
+
/**
|
|
1002
|
+
* 欧拉角旋转(单位度),顺序 XYZ;is3D = true 时生效
|
|
1003
|
+
* @default [0, 0, 0]
|
|
1004
|
+
*/
|
|
1005
|
+
rotation?: Rotation;
|
|
1006
|
+
/** 层级父对象 */
|
|
1007
|
+
parent?: BaseObject;
|
|
1008
|
+
/** 对象就绪回调 */
|
|
1009
|
+
onReady?: OnObjectReady<UIAnchor>;
|
|
1010
|
+
}
|
|
1011
|
+
/** 园区对象初始化参数 */
|
|
1012
|
+
interface CampusOption {
|
|
1013
|
+
/** 物体类型 */
|
|
1014
|
+
type: ObjectType.CAMPUS;
|
|
1015
|
+
/** 对象名称 */
|
|
1016
|
+
name?: string;
|
|
1017
|
+
/** 对象唯一标识;未传时与 name 一致 */
|
|
1018
|
+
id?: string;
|
|
1019
|
+
/** glb 模型地址 */
|
|
1020
|
+
url: string;
|
|
1021
|
+
/**
|
|
1022
|
+
* 位置
|
|
1023
|
+
* @default [0, 0, 0]
|
|
1024
|
+
*/
|
|
1025
|
+
position?: Position;
|
|
1026
|
+
/**
|
|
1027
|
+
* 缩放
|
|
1028
|
+
* @default [1, 1, 1]
|
|
1029
|
+
*/
|
|
1030
|
+
scale?: Scale;
|
|
1031
|
+
/**
|
|
1032
|
+
* 欧拉角旋转(单位度),顺序 XYZ
|
|
1033
|
+
* @default [0, 0, 0]
|
|
1034
|
+
*/
|
|
1035
|
+
rotation?: Rotation;
|
|
1036
|
+
/** 对象就绪回调 */
|
|
1037
|
+
onReady?: OnObjectReady<Campus>;
|
|
1038
|
+
}
|
|
1039
|
+
/** 折线对象初始化参数 */
|
|
1040
|
+
interface PolylineOption {
|
|
1041
|
+
/** 物体类型 */
|
|
1042
|
+
type: ObjectType.POLYLINE;
|
|
1043
|
+
/** 对象名称 */
|
|
1044
|
+
name?: string;
|
|
1045
|
+
/** 对象唯一标识;未传时与 name 一致 */
|
|
1046
|
+
id?: string;
|
|
1047
|
+
/** 路径数据 */
|
|
1048
|
+
points: Position[];
|
|
1049
|
+
/** 线宽(单位米) */
|
|
1050
|
+
width: number;
|
|
1051
|
+
/** 线条颜色 */
|
|
1052
|
+
color: string;
|
|
1053
|
+
/**
|
|
1054
|
+
* 拐角圆角半径(单位米);0 表示直角
|
|
1055
|
+
* @default 0
|
|
1056
|
+
*/
|
|
1057
|
+
cornerRadius?: number;
|
|
1058
|
+
/**
|
|
1059
|
+
* 拐角圆角细分段数,数值越大越平滑
|
|
1060
|
+
* @default 10
|
|
1061
|
+
*/
|
|
1062
|
+
cornerSegments?: number;
|
|
1063
|
+
/** 贴图路径;不传则仅使用 color 纯色 */
|
|
1064
|
+
imagePath?: string;
|
|
1065
|
+
/**
|
|
1066
|
+
* 贴图沿路径滚动速度(米/秒);正数沿路径正向
|
|
1067
|
+
* @default 0
|
|
1068
|
+
*/
|
|
1069
|
+
textureScrollSpeed?: number;
|
|
1070
|
+
/**
|
|
1071
|
+
* 是否启用贴图滚动
|
|
1072
|
+
* @default false
|
|
1073
|
+
*/
|
|
1074
|
+
enableTextureScroll?: boolean;
|
|
1075
|
+
/**
|
|
1076
|
+
* 贴图沿路径方向一个完整图案占用的世界长度(米)
|
|
1077
|
+
* @default 2
|
|
1078
|
+
*/
|
|
1079
|
+
textureWorldSize?: number;
|
|
1080
|
+
/**
|
|
1081
|
+
* 贴图沿路径方向相邻图案之间的空隙长度(米),空隙区域透明
|
|
1082
|
+
* @default 0
|
|
1083
|
+
*/
|
|
1084
|
+
textureGap?: number;
|
|
1085
|
+
/** 层级父对象 */
|
|
1086
|
+
parent?: BaseObject;
|
|
1087
|
+
/** 对象就绪回调 */
|
|
1088
|
+
onReady?: OnObjectReady<Polyline>;
|
|
1089
|
+
}
|
|
1090
|
+
/** Thing 对象初始化参数 */
|
|
1091
|
+
interface ThingOption {
|
|
1092
|
+
/** 物体类型 */
|
|
1093
|
+
type: ObjectType.THING;
|
|
1094
|
+
/** 对象名称 */
|
|
1095
|
+
name?: string;
|
|
1096
|
+
/** 对象唯一标识;未传时与 name 一致 */
|
|
1097
|
+
id?: string;
|
|
1098
|
+
/** glb 模型地址 */
|
|
1099
|
+
url: string;
|
|
1100
|
+
/**
|
|
1101
|
+
* 位置
|
|
1102
|
+
* @default [0, 0, 0]
|
|
1103
|
+
*/
|
|
1104
|
+
position?: Position;
|
|
1105
|
+
/**
|
|
1106
|
+
* 缩放
|
|
1107
|
+
* @default [1, 1, 1]
|
|
1108
|
+
*/
|
|
1109
|
+
scale?: Scale;
|
|
1110
|
+
/**
|
|
1111
|
+
* 欧拉角旋转(单位度),顺序 XYZ
|
|
1112
|
+
* @default [0, 0, 0]
|
|
1113
|
+
*/
|
|
1114
|
+
rotation?: Rotation;
|
|
1115
|
+
/** 层级父对象 */
|
|
1116
|
+
parent?: BaseObject;
|
|
1117
|
+
/**
|
|
1118
|
+
* 相对父对象的位置
|
|
1119
|
+
* @default [0, 0, 0]
|
|
1120
|
+
*/
|
|
1121
|
+
localPosition?: Position;
|
|
1122
|
+
/** 对象就绪回调 */
|
|
1123
|
+
onReady?: OnObjectReady<Thing>;
|
|
1124
|
+
}
|
|
1125
|
+
/** 建筑对象初始化参数 */
|
|
1126
|
+
interface BuildingOption {
|
|
1127
|
+
/** 对象名称 */
|
|
1128
|
+
name?: string;
|
|
1129
|
+
/** 对象唯一标识;未传时与 name 一致 */
|
|
1130
|
+
id?: string;
|
|
1131
|
+
/** 关联的 glTF 节点(建筑根对象) */
|
|
1132
|
+
object3D: Object3D;
|
|
1133
|
+
/** 父级园区 */
|
|
1134
|
+
parent: Campus;
|
|
1135
|
+
}
|
|
1136
|
+
/** 楼层对象初始化参数 */
|
|
1137
|
+
interface FloorOption {
|
|
1138
|
+
/** 对象名称 */
|
|
1139
|
+
name?: string;
|
|
1140
|
+
/** 对象唯一标识;未传时与 name 一致 */
|
|
1141
|
+
id?: string;
|
|
1142
|
+
/** 关联的 glTF 节点(楼层根对象) */
|
|
1143
|
+
object3D: Object3D;
|
|
1144
|
+
/** 父级建筑 */
|
|
1145
|
+
parent: Building;
|
|
1146
|
+
}
|
|
1147
|
+
/** 创建物体选项 */
|
|
1148
|
+
type CreateOption = CampusOption | MarkerOption | UIAnchorOption | ThingOption | PolylineOption;
|
|
1149
|
+
/** 场景层级对象 */
|
|
1150
|
+
type SceneLevelObject = Campus | Building | Floor;
|
|
1151
|
+
|
|
1152
|
+
/** 三维坐标 */
|
|
1153
|
+
type Position = [number, number, number];
|
|
1154
|
+
/** 缩放 */
|
|
1155
|
+
type Scale = [number, number, number];
|
|
1156
|
+
/** 欧拉角旋转(单位度),顺序 XYZ */
|
|
1157
|
+
type Rotation = [number, number, number];
|
|
1158
|
+
/** 视角参数 */
|
|
1159
|
+
type GetCameraOptions = ReturnType<Camera['getCamera']>;
|
|
1160
|
+
|
|
1161
|
+
/** 基础对象样式 */
|
|
1162
|
+
declare class BaseStyle {
|
|
1163
|
+
private readonly app;
|
|
1164
|
+
private readonly customObject;
|
|
1165
|
+
/** 材质颜色快照 */
|
|
1166
|
+
private materialSnapshots;
|
|
1167
|
+
/** 材质是否已隔离 */
|
|
1168
|
+
private materialsIsolated;
|
|
1169
|
+
constructor(app: App, customObject: BaseObject);
|
|
1170
|
+
/** 高亮模型 */
|
|
1171
|
+
highlight(): void;
|
|
1172
|
+
/** 取消高亮模型 */
|
|
1173
|
+
clearHighlight(): void;
|
|
1174
|
+
/**
|
|
1175
|
+
* 设置模型颜色
|
|
1176
|
+
* @param color 支持 #rgb/#rrggbb/#rrggbbaa、rgb()、rgba() 及 CSS 命名色
|
|
1177
|
+
*/
|
|
1178
|
+
setColor(color: string): void;
|
|
1179
|
+
/**
|
|
1180
|
+
* 设置模型透明度
|
|
1181
|
+
* @param opacity 不透明度,范围 [0, 1];0 全透明,1 不透明
|
|
1182
|
+
*/
|
|
1183
|
+
setOpacity(opacity: number): void;
|
|
1184
|
+
/** 恢复为首次 setColor / setOpacity 前的默认颜色与透明度 */
|
|
1185
|
+
resetColor(): void;
|
|
1186
|
+
/** 重置样式状态 */
|
|
1187
|
+
reset(): void;
|
|
1188
|
+
private forEachModelMaterial;
|
|
1189
|
+
private ensureMaterialSnapshots;
|
|
1190
|
+
private ensureMaterialIsolation;
|
|
1191
|
+
}
|
|
1192
|
+
|
|
1193
|
+
/** 基础对象类 */
|
|
1194
|
+
declare abstract class BaseObject<T extends Object3D = Object3D> {
|
|
1195
|
+
/** 物体类型 */
|
|
1196
|
+
readonly type: ObjectType;
|
|
1197
|
+
/** 对象名称 */
|
|
1198
|
+
readonly name: string;
|
|
1199
|
+
/** 对象唯一标识 */
|
|
1200
|
+
readonly id: string;
|
|
1201
|
+
/**
|
|
1202
|
+
* 相对父对象的位置
|
|
1203
|
+
* @default [0, 0, 0]
|
|
1204
|
+
*/
|
|
1205
|
+
localPosition: Nullable<Position>;
|
|
1206
|
+
/** 位置 */
|
|
1207
|
+
position: Position;
|
|
1208
|
+
/** 缩放 */
|
|
1209
|
+
scale: Scale;
|
|
1210
|
+
/** 欧拉角旋转(单位度),顺序 XYZ */
|
|
1211
|
+
rotation: Rotation;
|
|
1212
|
+
/** 可见状态 */
|
|
1213
|
+
visible: boolean;
|
|
1214
|
+
/** 用户数据 */
|
|
1215
|
+
userData: Record<PropertyKey, unknown>;
|
|
1216
|
+
/** 样式 */
|
|
1217
|
+
readonly style: BaseStyle;
|
|
1218
|
+
/** 父对象 */
|
|
1219
|
+
protected _parent: Nullable<BaseObject>;
|
|
1220
|
+
/** 对象关联的场景节点 */
|
|
1221
|
+
protected _object3D: Nullable<T>;
|
|
1222
|
+
/** 是否已执行销毁(幂等) */
|
|
1223
|
+
protected destroyed: boolean;
|
|
1224
|
+
protected readonly app: App;
|
|
1225
|
+
constructor(init: {
|
|
1226
|
+
app: App;
|
|
1227
|
+
type: ObjectType;
|
|
1228
|
+
name?: string;
|
|
1229
|
+
id?: string;
|
|
1230
|
+
parent?: Nullable<BaseObject>;
|
|
1231
|
+
position?: Position;
|
|
1232
|
+
scale?: Scale;
|
|
1233
|
+
rotation?: Rotation;
|
|
1234
|
+
localPosition?: Position;
|
|
1235
|
+
});
|
|
1236
|
+
get parent(): Nullable<BaseObject>;
|
|
1237
|
+
/** 对象关联的场景节点 */
|
|
1238
|
+
get object3D(): Nullable<T>;
|
|
1239
|
+
protected set object3D(value: Nullable<T>);
|
|
1240
|
+
protected get children(): readonly BaseObject[];
|
|
1241
|
+
/**
|
|
1242
|
+
* 设置模型显隐
|
|
1243
|
+
* @param visible 是否可见
|
|
1244
|
+
*/
|
|
1245
|
+
setVisible(visible: boolean): void;
|
|
1246
|
+
/**
|
|
1247
|
+
* 设置位置
|
|
1248
|
+
* @param position 位置
|
|
1249
|
+
*/
|
|
1250
|
+
setPosition(position: Position): void;
|
|
1251
|
+
/**
|
|
1252
|
+
* 设置相对父对象的位置
|
|
1253
|
+
* @param localPosition 相对父对象的位置
|
|
1254
|
+
*/
|
|
1255
|
+
setLocalPosition(localPosition: Position): void;
|
|
1256
|
+
/**
|
|
1257
|
+
* 设置缩放
|
|
1258
|
+
* @param scale 缩放
|
|
1259
|
+
*/
|
|
1260
|
+
setScale(scale: Scale): void;
|
|
1261
|
+
/**
|
|
1262
|
+
* 设置旋转(欧拉角,单位度,顺序 XYZ)
|
|
1263
|
+
* @param rotation 各轴旋转角度
|
|
1264
|
+
*/
|
|
1265
|
+
setRotation(rotation: Rotation): void;
|
|
1266
|
+
/**
|
|
1267
|
+
* 销毁对象
|
|
1268
|
+
*/
|
|
1269
|
+
destroy(): void;
|
|
1270
|
+
/** 销毁流程模板方法 */
|
|
1271
|
+
protected disposeResources(): void;
|
|
1272
|
+
/** 释放前钩子 */
|
|
1273
|
+
protected beforeDisposeResources(): void;
|
|
1274
|
+
/** 释放对象独占资源 */
|
|
1275
|
+
protected disposeOwnedResources(): void;
|
|
1276
|
+
/** 释放后钩子 */
|
|
1277
|
+
protected afterDisposeResources(): void;
|
|
1278
|
+
/** glTF 节点已有 transform 时,由子类在赋值 object3D 后调用 */
|
|
1279
|
+
protected syncTransformFromObject3D(object3D: Object3D): void;
|
|
1280
|
+
/**
|
|
1281
|
+
* 清理 customObject 映射
|
|
1282
|
+
* @param target 目标节点
|
|
1283
|
+
* @param deep 是否递归清理子树
|
|
1284
|
+
*/
|
|
1285
|
+
protected clearCustomObjectBinding(target: Object3D, deep?: boolean): void;
|
|
1286
|
+
/**
|
|
1287
|
+
* 将节点从场景树摘除(无论挂在 scene 根或任意父级)
|
|
1288
|
+
* @param target 目标节点
|
|
1289
|
+
*/
|
|
1290
|
+
protected detachObject3D(target: Object3D): void;
|
|
1291
|
+
/**
|
|
1292
|
+
* 释放节点子树下的网格资源
|
|
1293
|
+
* @param target 目标节点
|
|
1294
|
+
*/
|
|
1295
|
+
protected disposeObject3DSubtree(target: Object3D): void;
|
|
1296
|
+
/** 仅更新内部 scale,不写入场景节点 */
|
|
1297
|
+
protected setScaleState(scale: Scale): void;
|
|
1298
|
+
/** 仅更新内部 rotation(单位度),不写入场景节点 */
|
|
1299
|
+
protected setRotationState(rotation: Rotation): void;
|
|
1300
|
+
/** 是否使用相对父对象的位置 */
|
|
1301
|
+
protected isUsingLocalPosition(): boolean;
|
|
1302
|
+
}
|
|
1303
|
+
|
|
1304
|
+
/**
|
|
1305
|
+
* UI 界面锚点\
|
|
1306
|
+
* 将 UI 界面元素固定在场景中某个位置,并跟随相机移动
|
|
1307
|
+
*/
|
|
1308
|
+
declare class UIAnchor extends BaseObject<Mesh> {
|
|
1309
|
+
/** 覆盖层根元素 ID */
|
|
1310
|
+
static readonly OVERLAY_ROOT_ID = "twin3d-ui-anchor-overlay-root-id";
|
|
1311
|
+
/** 实例锚点容器 */
|
|
1312
|
+
private readonly anchorContainer;
|
|
1313
|
+
/** 屏幕像素偏移 */
|
|
1314
|
+
private readonly offsetPx?;
|
|
1315
|
+
/** UI 锚点元素 */
|
|
1316
|
+
private readonly uiElement;
|
|
1317
|
+
/** 是否以 3D 模式展示 */
|
|
1318
|
+
private readonly is3D;
|
|
1319
|
+
/** 3D 模式尺寸(世界单位) */
|
|
1320
|
+
private readonly meshSize;
|
|
1321
|
+
constructor(option: UIAnchorOption, app: App);
|
|
1322
|
+
/** 设置显隐 */
|
|
1323
|
+
setVisible(visible: boolean): void;
|
|
1324
|
+
setPosition(position: Position): void;
|
|
1325
|
+
setScale(scale: Scale): void;
|
|
1326
|
+
setRotation(rotation: Rotation): void;
|
|
1327
|
+
/** 每帧更新位置 */
|
|
1328
|
+
update(): void;
|
|
1329
|
+
protected beforeDisposeResources(): void;
|
|
1330
|
+
protected disposeOwnedResources(): void;
|
|
1331
|
+
protected afterDisposeResources(): void;
|
|
1332
|
+
/** 创建实例锚点容器 */
|
|
1333
|
+
private createAnchorContainer;
|
|
1334
|
+
/** 订阅全局帧更新 */
|
|
1335
|
+
private subscribeFrameUpdate;
|
|
1336
|
+
/** 帧更新回调 */
|
|
1337
|
+
private handleFrameUpdate;
|
|
1338
|
+
/** 获取覆盖层根元素 */
|
|
1339
|
+
private getOverlayRoot;
|
|
1340
|
+
/** 创建 3D 锚点 */
|
|
1341
|
+
private create3DAnchor;
|
|
1342
|
+
/** 计算 3D 锚点尺寸 */
|
|
1343
|
+
private getMeshSize;
|
|
1344
|
+
}
|
|
1345
|
+
|
|
1346
|
+
export { App, BaseObject, BaseStyle, Building, type BuildingOption, BuiltInEventKey, Campus, type CampusOption, type CreateOption, Element, Floor, type FloorOption, type GetCameraOptions, Marker, type MarkerOption, type Nullable, ObjectNamePrefix, ObjectType, type OnObjectReady, Polyline, type PolylineOption, type Position, type Rotation, type Scale, type SceneEventMap, SceneEventType, type SceneLevelObject, Thing, type ThingOption, UIAnchor, type UIAnchorOption, isBuilding, isCampus, isCampusDerivedObject, isFloor };
|