@soonspacejs/plugin-navigation 2.13.9 → 2.13.11

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.
@@ -1,4 +1,3 @@
1
- import { Azimuth } from '@three3d/tools';
2
- export { Azimuth, AzimuthOptions, CourseAzimuthMap, AzimuthDefine, AzimuthInfo, CourseInfo, AngleRange, AzimuthList, AzimuthMap, } from '@three3d/tools';
3
- declare const azimuth: Azimuth;
4
- export { azimuth, };
1
+ export { Azimuth, type AzimuthOptions, type CourseAzimuthMap, type AzimuthDefine, type AzimuthInfo, type CourseInfo, type AngleRange, type AzimuthList, type AzimuthMap, } from '@three3d/tools';
2
+ declare const azimuth: any;
3
+ export { azimuth, };
@@ -1,5 +1,5 @@
1
- export * from './map-camera';
2
- export * from './navigate-camera';
3
- export * from './ssp-camera';
4
- export * from './utils';
5
- export * from './types';
1
+ export * from './map-camera';
2
+ export * from './navigate-camera';
3
+ export * from './ssp-camera';
4
+ export * from './utils';
5
+ export * from './types';
@@ -1,14 +1,14 @@
1
- import { OrthographicCamera } from 'three';
2
- import SoonSpace from 'soonspacejs';
3
- import { SoonSpaceCamera } from './ssp-camera';
4
- export declare class MapCamera extends SoonSpaceCamera<OrthographicCamera> {
5
- readonly ssp: SoonSpace;
6
- protected resizeObserver: ResizeObserver;
7
- _zoom: number;
8
- get zoom(): number;
9
- set zoom(value: number);
10
- constructor(ssp: SoonSpace);
11
- resizeCamera(): void;
12
- protected onEnter(): void;
13
- protected onQuit(): void;
14
- }
1
+ import { OrthographicCamera } from 'three';
2
+ import SoonSpace from 'soonspacejs';
3
+ import { SoonSpaceCamera } from './ssp-camera';
4
+ export declare class MapCamera extends SoonSpaceCamera<OrthographicCamera> {
5
+ readonly ssp: SoonSpace;
6
+ protected resizeObserver: ResizeObserver;
7
+ _zoom: number;
8
+ get zoom(): number;
9
+ set zoom(value: number);
10
+ constructor(ssp: SoonSpace);
11
+ resizeCamera(): void;
12
+ protected onEnter(): void;
13
+ protected onQuit(): void;
14
+ }
@@ -1,202 +1,202 @@
1
- import SoonSpace from 'soonspacejs';
2
- import { Camera, Euler, Object3D, Quaternion, Vector3 } from 'three';
3
- import { GyroListener } from '../utils/gyro';
4
- import { SoonSpaceCamera } from './ssp-camera';
5
- import { CameraOppositeType, EulerArray, FixEuler, FixVector, NAVIGATE_ORIENTATION_TYPE, NAVIGATE_VISION_TYPE, NavigateOrientationTarget } from './types';
6
- /**
7
- * 相机控制回调
8
- *
9
- * camera 当前相机
10
- *
11
- * target 跟踪的目标
12
- */
13
- export type ControlCallback = (camera: Camera, target: Object3D, event?: MouseEvent | TouchEvent) => void;
14
- export interface NavigateCameraOptions {
15
- disabledAnimate: boolean;
16
- fixedOrientation: boolean;
17
- autoRestoreOrientation: boolean | number;
18
- oppositeCamera: boolean;
19
- oppositeType: CameraOppositeType;
20
- orientationTarget: NavigateOrientationTarget;
21
- vision: NAVIGATE_VISION_TYPE;
22
- orientationType: NAVIGATE_ORIENTATION_TYPE;
23
- distanceToTarget: number;
24
- rotationToTarget: Vector3;
25
- isFixRotationRelativeTarget: boolean;
26
- targetRotationFix: FixEuler;
27
- isFixPositionRelativeTarget: boolean;
28
- targetPositionFix: FixVector;
29
- enableGyro: boolean;
30
- gyroX: boolean;
31
- gyroY: boolean;
32
- gyroZ: boolean;
33
- gyroAbsolute: boolean;
34
- onControlStart: null | ControlCallback;
35
- onControlRender: null | ControlCallback;
36
- onControlEnd: null | ControlCallback;
37
- }
38
- /** 导航相机 */
39
- export declare class NavigateCamera extends SoonSpaceCamera<Camera> {
40
- readonly ssp: SoonSpace;
41
- initOptions: Readonly<NavigateCameraOptions>;
42
- cameraKey: string;
43
- private _events;
44
- get position(): Vector3;
45
- get rotation(): Euler;
46
- get quaternion(): Quaternion;
47
- private _lookAt;
48
- private _restoreTimer;
49
- private _positionTween;
50
- private autoFollowRender;
51
- /** 相机位置记录用的对象,用于恢复相机位置和朝向使用 */
52
- protected _cameraPlaceholder: Object3D<import("three").Object3DEventMap>;
53
- /** 取消飞向动画 */
54
- disabledAnimate: boolean;
55
- /** 第三人称相机距离跟踪目标距离 */
56
- distanceToTarget: number;
57
- /** 第三人称相机相对模型视角 */
58
- rotationToTarget: Vector3;
59
- /** 相机反转 */
60
- oppositeCamera: boolean;
61
- /** 相机反转类型, 默认为 Y 轴对称 */
62
- oppositeType: CameraOppositeType;
63
- /** 是否相对模型修正角度 */
64
- isFixRotationRelativeTarget: boolean;
65
- /**
66
- * 目标角度修正
67
- *
68
- * 支持传入 getter 函数
69
- */
70
- targetRotationFix: FixEuler;
71
- /** 是否相对模型修正偏移 */
72
- isFixPositionRelativeTarget: boolean;
73
- /**
74
- * 目标位置修正
75
- *
76
- * 支持传入 getter 函数
77
- */
78
- targetPositionFix: FixVector;
79
- /**
80
- * 自动恢复朝向
81
- *
82
- * boolean 是否恢复朝向
83
- *
84
- * number 间隔多少秒后恢复朝向
85
- */
86
- autoRestoreOrientation: boolean | number;
87
- /** 当控制器控制相机时允许外部自定义控制,控制开始时触发 */
88
- onControlStart: null | ControlCallback;
89
- /** 当控制器控制相机时允许外部自定义控制,控制进行时回调 */
90
- onControlRender: null | ControlCallback;
91
- /** 当控制器控制相机时允许外部自定义控制,控制结束时回调 */
92
- onControlEnd: null | ControlCallback;
93
- /** 陀螺仪 */
94
- protected _gyroListener: GyroListener;
95
- protected _enableGyro: boolean;
96
- /** 开启 */
97
- get enableGyro(): boolean;
98
- set enableGyro(value: boolean);
99
- /** 是否应用陀螺仪 X 轴,默认不启动 */
100
- get gyroX(): boolean;
101
- set gyroX(value: boolean);
102
- /** 是否应用陀螺仪 Y 轴,默认启动 */
103
- get gyroY(): boolean;
104
- set gyroY(value: boolean);
105
- /** 是否应用陀螺仪 Z 轴,默认不启动 */
106
- get gyroZ(): boolean;
107
- set gyroZ(value: boolean);
108
- /** 陀螺仪是否使用绝对值,默认使用 */
109
- get gyroAbsolute(): boolean;
110
- set gyroAbsolute(value: boolean);
111
- /** 陀螺仪的旋转欧拉角 */
112
- protected _gyroRotation: Euler;
113
- get targetRotationAfterFix(): EulerArray;
114
- get targetPositionAfterFix(): import("./types").VectorArray;
115
- get realDistanceToTarget(): number;
116
- get realRotationToTarget(): Vector3;
117
- protected _orientationType: NAVIGATE_ORIENTATION_TYPE;
118
- /** 绝对朝向的缓存值 */
119
- private _fixedOrientationRotation;
120
- /**
121
- * 相机朝向类型
122
- *
123
- * NAVIGATE_ORIENTATION_TYPE.RELATIVE_ORIENTATION 相对朝向
124
- *
125
- * NAVIGATE_ORIENTATION_TYPE.FIXED_ORIENTATION 绝对朝向
126
- *
127
- * NAVIGATE_ORIENTATION_TYPE.GYRO_ORIENTATION 陀螺仪朝向
128
- */
129
- get orientationType(): NAVIGATE_ORIENTATION_TYPE;
130
- set orientationType(value: NAVIGATE_ORIENTATION_TYPE);
131
- protected _orientationTarget: NavigateOrientationTarget;
132
- /**
133
- * 相机朝向目标
134
- *
135
- * “main” 朝向跟踪目标
136
- *
137
- * Vector3 朝向点
138
- *
139
- * Object3D 朝向目标对象
140
- *
141
- * Euler 固定朝向
142
- */
143
- get orientationTarget(): NavigateOrientationTarget;
144
- set orientationTarget(value: NavigateOrientationTarget);
145
- protected _vision: NAVIGATE_VISION_TYPE;
146
- /**
147
- * 视角配置
148
- *
149
- * NAVIGATE_VISION_TYPE.FIRST_VISION 第一人称
150
- *
151
- * NAVIGATE_VISION_TYPE.THIRD_VISION 第三人称
152
- *
153
- * NAVIGATE_VISION_TYPE.UP_VISION 俯视图
154
- *
155
- * NAVIGATE_VISION_TYPE.LEFT_VISION 左视图
156
- *
157
- * 默认为第三人称
158
- */
159
- get vision(): NAVIGATE_VISION_TYPE;
160
- set vision(value: NAVIGATE_VISION_TYPE);
161
- protected _followTarget: Object3D;
162
- /** 相机跟随目标 */
163
- get followTarget(): Object3D;
164
- set followTarget(value: Object3D);
165
- /** 相机跟踪点(相对跟随目标以及偏移参数获取的点) */
166
- get followPosition(): Vector3;
167
- /** 跟踪目标的方向(相对跟随目标以及偏移参数获取的朝向) */
168
- get followRotation(): Euler;
169
- protected _fixedOrientation: boolean;
170
- /** 固定朝向,朝向不受控制器影响 */
171
- get fixedOrientation(): boolean;
172
- set fixedOrientation(value: boolean);
173
- constructor(ssp: SoonSpace, camera?: Camera, options?: Partial<NavigateCameraOptions>);
174
- protected initGyroListener(): void;
175
- /** 控制器操作时处理 */
176
- protected setCameraOrientationOnControl(): void;
177
- /** 更新相机占位符的方位 */
178
- protected updateCameraPlaceholder(): void;
179
- /** 设置相机的方位 */
180
- protected setCameraOrientationOnRender(): void;
181
- /** 获取相机点相对跟踪点的欧拉角 */
182
- protected getRenderCameraOrientation(): Euler;
183
- /** 获取相机落点(相对跟踪点的方向归一化 * 距离) */
184
- protected getRenderCameraPosition(): Vector3;
185
- protected onRender(): void;
186
- /** 初始化事件 */
187
- protected initEvents(): void;
188
- /** 清除事件 */
189
- protected clearEvents(): void;
190
- protected onEnter(): void;
191
- protected onQuit(): void;
192
- /** 参数重置 */
193
- resetOptions(): void;
194
- /** 设置参数 */
195
- setOptions(options: Partial<NavigateCameraOptions>): void;
196
- /**
197
- * 设置相机,若导航相机正在使用中,则会立即切换为设置的相机
198
- */
199
- setCamera(camera: Camera): this;
200
- /** 重置相机坐标 */
201
- restoreOrientation(): void;
202
- }
1
+ import SoonSpace from 'soonspacejs';
2
+ import { Camera, Euler, Object3D, Quaternion, Vector3 } from 'three';
3
+ import { GyroListener } from '../utils/gyro';
4
+ import { SoonSpaceCamera } from './ssp-camera';
5
+ import { CameraOppositeType, EulerArray, FixEuler, FixVector, NAVIGATE_ORIENTATION_TYPE, NAVIGATE_VISION_TYPE, NavigateOrientationTarget } from './types';
6
+ /**
7
+ * 相机控制回调
8
+ *
9
+ * camera 当前相机
10
+ *
11
+ * target 跟踪的目标
12
+ */
13
+ export type ControlCallback = (camera: Camera, target: Object3D, event?: MouseEvent | TouchEvent) => void;
14
+ export interface NavigateCameraOptions {
15
+ disabledAnimate: boolean;
16
+ fixedOrientation: boolean;
17
+ autoRestoreOrientation: boolean | number;
18
+ oppositeCamera: boolean;
19
+ oppositeType: CameraOppositeType;
20
+ orientationTarget: NavigateOrientationTarget;
21
+ vision: NAVIGATE_VISION_TYPE;
22
+ orientationType: NAVIGATE_ORIENTATION_TYPE;
23
+ distanceToTarget: number;
24
+ rotationToTarget: Vector3;
25
+ isFixRotationRelativeTarget: boolean;
26
+ targetRotationFix: FixEuler;
27
+ isFixPositionRelativeTarget: boolean;
28
+ targetPositionFix: FixVector;
29
+ enableGyro: boolean;
30
+ gyroX: boolean;
31
+ gyroY: boolean;
32
+ gyroZ: boolean;
33
+ gyroAbsolute: boolean;
34
+ onControlStart: null | ControlCallback;
35
+ onControlRender: null | ControlCallback;
36
+ onControlEnd: null | ControlCallback;
37
+ }
38
+ /** 导航相机 */
39
+ export declare class NavigateCamera extends SoonSpaceCamera<Camera> {
40
+ readonly ssp: SoonSpace;
41
+ initOptions: Readonly<NavigateCameraOptions>;
42
+ cameraKey: string;
43
+ private _events;
44
+ get position(): Vector3;
45
+ get rotation(): Euler;
46
+ get quaternion(): Quaternion;
47
+ private _lookAt;
48
+ private _restoreTimer;
49
+ private _positionTween;
50
+ private autoFollowRender;
51
+ /** 相机位置记录用的对象,用于恢复相机位置和朝向使用 */
52
+ protected _cameraPlaceholder: Object3D<import("three").Object3DEventMap>;
53
+ /** 取消飞向动画 */
54
+ disabledAnimate: boolean;
55
+ /** 第三人称相机距离跟踪目标距离 */
56
+ distanceToTarget: number;
57
+ /** 第三人称相机相对模型视角 */
58
+ rotationToTarget: Vector3;
59
+ /** 相机反转 */
60
+ oppositeCamera: boolean;
61
+ /** 相机反转类型, 默认为 Y 轴对称 */
62
+ oppositeType: CameraOppositeType;
63
+ /** 是否相对模型修正角度 */
64
+ isFixRotationRelativeTarget: boolean;
65
+ /**
66
+ * 目标角度修正
67
+ *
68
+ * 支持传入 getter 函数
69
+ */
70
+ targetRotationFix: FixEuler;
71
+ /** 是否相对模型修正偏移 */
72
+ isFixPositionRelativeTarget: boolean;
73
+ /**
74
+ * 目标位置修正
75
+ *
76
+ * 支持传入 getter 函数
77
+ */
78
+ targetPositionFix: FixVector;
79
+ /**
80
+ * 自动恢复朝向
81
+ *
82
+ * boolean 是否恢复朝向
83
+ *
84
+ * number 间隔多少秒后恢复朝向
85
+ */
86
+ autoRestoreOrientation: boolean | number;
87
+ /** 当控制器控制相机时允许外部自定义控制,控制开始时触发 */
88
+ onControlStart: null | ControlCallback;
89
+ /** 当控制器控制相机时允许外部自定义控制,控制进行时回调 */
90
+ onControlRender: null | ControlCallback;
91
+ /** 当控制器控制相机时允许外部自定义控制,控制结束时回调 */
92
+ onControlEnd: null | ControlCallback;
93
+ /** 陀螺仪 */
94
+ protected _gyroListener: GyroListener;
95
+ protected _enableGyro: boolean;
96
+ /** 开启 */
97
+ get enableGyro(): boolean;
98
+ set enableGyro(value: boolean);
99
+ /** 是否应用陀螺仪 X 轴,默认不启动 */
100
+ get gyroX(): boolean;
101
+ set gyroX(value: boolean);
102
+ /** 是否应用陀螺仪 Y 轴,默认启动 */
103
+ get gyroY(): boolean;
104
+ set gyroY(value: boolean);
105
+ /** 是否应用陀螺仪 Z 轴,默认不启动 */
106
+ get gyroZ(): boolean;
107
+ set gyroZ(value: boolean);
108
+ /** 陀螺仪是否使用绝对值,默认使用 */
109
+ get gyroAbsolute(): boolean;
110
+ set gyroAbsolute(value: boolean);
111
+ /** 陀螺仪的旋转欧拉角 */
112
+ protected _gyroRotation: Euler;
113
+ get targetRotationAfterFix(): EulerArray;
114
+ get targetPositionAfterFix(): import("./types").VectorArray;
115
+ get realDistanceToTarget(): number;
116
+ get realRotationToTarget(): Vector3;
117
+ protected _orientationType: NAVIGATE_ORIENTATION_TYPE;
118
+ /** 绝对朝向的缓存值 */
119
+ private _fixedOrientationRotation;
120
+ /**
121
+ * 相机朝向类型
122
+ *
123
+ * NAVIGATE_ORIENTATION_TYPE.RELATIVE_ORIENTATION 相对朝向
124
+ *
125
+ * NAVIGATE_ORIENTATION_TYPE.FIXED_ORIENTATION 绝对朝向
126
+ *
127
+ * NAVIGATE_ORIENTATION_TYPE.GYRO_ORIENTATION 陀螺仪朝向
128
+ */
129
+ get orientationType(): NAVIGATE_ORIENTATION_TYPE;
130
+ set orientationType(value: NAVIGATE_ORIENTATION_TYPE);
131
+ protected _orientationTarget: NavigateOrientationTarget;
132
+ /**
133
+ * 相机朝向目标
134
+ *
135
+ * “main” 朝向跟踪目标
136
+ *
137
+ * Vector3 朝向点
138
+ *
139
+ * Object3D 朝向目标对象
140
+ *
141
+ * Euler 固定朝向
142
+ */
143
+ get orientationTarget(): NavigateOrientationTarget;
144
+ set orientationTarget(value: NavigateOrientationTarget);
145
+ protected _vision: NAVIGATE_VISION_TYPE;
146
+ /**
147
+ * 视角配置
148
+ *
149
+ * NAVIGATE_VISION_TYPE.FIRST_VISION 第一人称
150
+ *
151
+ * NAVIGATE_VISION_TYPE.THIRD_VISION 第三人称
152
+ *
153
+ * NAVIGATE_VISION_TYPE.UP_VISION 俯视图
154
+ *
155
+ * NAVIGATE_VISION_TYPE.LEFT_VISION 左视图
156
+ *
157
+ * 默认为第三人称
158
+ */
159
+ get vision(): NAVIGATE_VISION_TYPE;
160
+ set vision(value: NAVIGATE_VISION_TYPE);
161
+ protected _followTarget: Object3D;
162
+ /** 相机跟随目标 */
163
+ get followTarget(): Object3D;
164
+ set followTarget(value: Object3D);
165
+ /** 相机跟踪点(相对跟随目标以及偏移参数获取的点) */
166
+ get followPosition(): Vector3;
167
+ /** 跟踪目标的方向(相对跟随目标以及偏移参数获取的朝向) */
168
+ get followRotation(): Euler;
169
+ protected _fixedOrientation: boolean;
170
+ /** 固定朝向,朝向不受控制器影响 */
171
+ get fixedOrientation(): boolean;
172
+ set fixedOrientation(value: boolean);
173
+ constructor(ssp: SoonSpace, camera?: Camera, options?: Partial<NavigateCameraOptions>);
174
+ protected initGyroListener(): void;
175
+ /** 控制器操作时处理 */
176
+ protected setCameraOrientationOnControl(): void;
177
+ /** 更新相机占位符的方位 */
178
+ protected updateCameraPlaceholder(): void;
179
+ /** 设置相机的方位 */
180
+ protected setCameraOrientationOnRender(): void;
181
+ /** 获取相机点相对跟踪点的欧拉角 */
182
+ protected getRenderCameraOrientation(): Euler;
183
+ /** 获取相机落点(相对跟踪点的方向归一化 * 距离) */
184
+ protected getRenderCameraPosition(): Vector3;
185
+ protected onRender(): void;
186
+ /** 初始化事件 */
187
+ protected initEvents(): void;
188
+ /** 清除事件 */
189
+ protected clearEvents(): void;
190
+ protected onEnter(): void;
191
+ protected onQuit(): void;
192
+ /** 参数重置 */
193
+ resetOptions(): void;
194
+ /** 设置参数 */
195
+ setOptions(options: Partial<NavigateCameraOptions>): void;
196
+ /**
197
+ * 设置相机,若导航相机正在使用中,则会立即切换为设置的相机
198
+ */
199
+ setCamera(camera: Camera): this;
200
+ /** 重置相机坐标 */
201
+ restoreOrientation(): void;
202
+ }
@@ -1,13 +1,13 @@
1
- import { Camera } from 'three';
2
- import SoonSpace from 'soonspacejs';
3
- export declare abstract class SoonSpaceCamera<C extends Camera = Camera> {
4
- readonly ssp: SoonSpace;
5
- nativeCamera: C;
6
- protected _isActive: boolean;
7
- constructor(ssp: SoonSpace, nativeCamera: C);
8
- active(): void;
9
- private _onBeforeEnter;
10
- private _onBeforeQuit;
11
- protected onEnter(): void;
12
- protected onQuit(): void;
13
- }
1
+ import { Camera } from 'three';
2
+ import SoonSpace from 'soonspacejs';
3
+ export declare abstract class SoonSpaceCamera<C extends Camera = Camera> {
4
+ readonly ssp: SoonSpace;
5
+ nativeCamera: C;
6
+ protected _isActive: boolean;
7
+ constructor(ssp: SoonSpace, nativeCamera: C);
8
+ active(): void;
9
+ private _onBeforeEnter;
10
+ private _onBeforeQuit;
11
+ protected onEnter(): void;
12
+ protected onQuit(): void;
13
+ }
@@ -1,26 +1,26 @@
1
- import { Euler, EulerOrder, Object3D, Vector3 } from 'three';
2
- export type NavigateOrientationTarget = 'main' | Vector3 | Euler | Object3D;
3
- export declare enum NAVIGATE_VISION_TYPE {
4
- FIRST_VISION = "first",
5
- THIRD_VISION = "third",
6
- UP_VISION = "up",
7
- LEFT_VISION = "left"
8
- }
9
- export declare enum NAVIGATE_ORIENTATION_TYPE {
10
- RELATIVE_ORIENTATION = "relative",
11
- FIXED_ORIENTATION = "fixed",
12
- GYRO_ORIENTATION = "gyro"
13
- }
14
- export type CameraOppositeType = {
15
- x: boolean;
16
- y: boolean;
17
- z: boolean;
18
- };
19
- export type Object3DLike = {
20
- position: Vector3;
21
- rotation: Euler;
22
- } & Record<PropertyKey, any>;
23
- export type VectorArray = [number, number, number];
24
- export type EulerArray = [number, number, number, EulerOrder?];
25
- export type FixVector = VectorArray | ((target?: Object3DLike) => VectorArray);
26
- export type FixEuler = EulerArray | ((target?: Object3DLike) => EulerArray);
1
+ import { Euler, EulerOrder, Object3D, Vector3 } from 'three';
2
+ export type NavigateOrientationTarget = 'main' | Vector3 | Euler | Object3D;
3
+ export declare enum NAVIGATE_VISION_TYPE {
4
+ FIRST_VISION = "first",
5
+ THIRD_VISION = "third",
6
+ UP_VISION = "up",
7
+ LEFT_VISION = "left"
8
+ }
9
+ export declare enum NAVIGATE_ORIENTATION_TYPE {
10
+ RELATIVE_ORIENTATION = "relative",
11
+ FIXED_ORIENTATION = "fixed",
12
+ GYRO_ORIENTATION = "gyro"
13
+ }
14
+ export type CameraOppositeType = {
15
+ x: boolean;
16
+ y: boolean;
17
+ z: boolean;
18
+ };
19
+ export type Object3DLike = {
20
+ position: Vector3;
21
+ rotation: Euler;
22
+ } & Record<PropertyKey, any>;
23
+ export type VectorArray = [number, number, number];
24
+ export type EulerArray = [number, number, number, EulerOrder?];
25
+ export type FixVector = VectorArray | ((target?: Object3DLike) => VectorArray);
26
+ export type FixEuler = EulerArray | ((target?: Object3DLike) => EulerArray);
@@ -1,11 +1,11 @@
1
- import { Euler, Vector3 } from 'three';
2
- import { FixEuler, FixVector, Object3DLike } from './types';
3
- export declare function Vector3ToEuler(v: Vector3): Euler;
4
- export declare function eulerToVector3(e: Euler): Vector3;
5
- /**
6
- * 欧拉角归一化
7
- * @param e 欧拉角
8
- */
9
- export declare function normalizeEuler(e: Euler): Vector3;
10
- export declare function getFixVector(v: FixVector, target?: Object3DLike): import("./types").VectorArray;
11
- export declare function getFixEuler(e: FixEuler, target?: Object3DLike): import("./types").EulerArray;
1
+ import { Euler, Vector3 } from 'three';
2
+ import { FixEuler, FixVector, Object3DLike } from './types';
3
+ export declare function Vector3ToEuler(v: Vector3): Euler;
4
+ export declare function eulerToVector3(e: Euler): Vector3;
5
+ /**
6
+ * 欧拉角归一化
7
+ * @param e 欧拉角
8
+ */
9
+ export declare function normalizeEuler(e: Euler): Vector3;
10
+ export declare function getFixVector(v: FixVector, target?: Object3DLike): import("./types").VectorArray;
11
+ export declare function getFixEuler(e: FixEuler, target?: Object3DLike): import("./types").EulerArray;
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export * from './camera';
2
- export * from './navigator';
3
- export * from './utils';
4
- export * from './azimuth';
1
+ export * from './camera';
2
+ export * from './navigator';
3
+ export * from './utils';
4
+ export * from './azimuth';
package/dist/index.esm.js CHANGED
@@ -1 +1 @@
1
- import{OrthographicCamera as t,Matrix4 as e,Quaternion as i,Euler as o,Vector3 as n,PerspectiveCamera as s,Object3D as r,MathUtils as a,Matrix3 as h}from"three";class l{constructor(t,e){this.ssp=t,this.nativeCamera=e,this._isActive=!1,this.ssp.signals.cameraObjectChange.add((()=>{const t=this.ssp.viewport.cameraManager.currentCamera;this._isActive&&t===this.nativeCamera||(t===this.nativeCamera?(this._onBeforeEnter(),this.onEnter()):this._isActive&&t!==this.nativeCamera&&(this._onBeforeQuit(),this.onQuit()))}))}active(){this.ssp.viewport.cameraManager.setCurrentCamera(this.nativeCamera)}_onBeforeEnter(){this._isActive=!0}_onBeforeQuit(){this._isActive=!1}onEnter(){}onQuit(){}}class u extends l{get zoom(){return this._zoom}set zoom(t){this._zoom=t,this.resizeCamera()}constructor(e){const i=new t;super(e,i),this.ssp=e,this.resizeObserver=new ResizeObserver((()=>{this.resizeCamera()})),this._zoom=.01,i.far=2e5}resizeCamera(){if(this._isActive){const{clientWidth:t,clientHeight:e}=this.ssp.viewport.renderer.domElement,i=t*this.zoom/2,o=e*this.zoom/2;this.nativeCamera.left=-i,this.nativeCamera.right=i,this.nativeCamera.top=o,this.nativeCamera.bottom=-o,this.nativeCamera.updateProjectionMatrix()}}onEnter(){console.log("map camera enter"),this.ssp.domElement&&(this.resizeObserver.observe(this.ssp.domElement),this.resizeCamera())}onQuit(){this.ssp.domElement&&(this.resizeObserver.unobserve(this.ssp.domElement),console.log("map camera quit"))}}class c{constructor(t,e,i,o){this.gyroEvent=null,this.onChange=()=>{},this._isActive=!1,this.defaultBeta=null,this.defaultAlpha=null,this.defaultGamma=null,this.cache=null,this.beta=null,this.alpha=null,this.gamma=null,this.gyroX=null==t||t,this.gyroY=null==e||e,this.gyroZ=null==i||i,this.absolute=null==o||o}requestPermisson(){return new Promise(((t,e)=>{var i;window.DeviceOrientationEvent.requestPermission||t(!0),null===(i=window.DeviceOrientationEvent)||void 0===i||i.requestPermission().then((i=>{"granted"===i?t(!0):e("用户拒绝使用陀螺仪权限")}))}))}async active(){await this.requestPermisson(),this._isActive=!0,this.gyroEvent&&this.inActive(),this.gyroEvent=t=>{const{defaultAlpha:e,defaultBeta:i,defaultGamma:o,gyroX:n,gyroY:s,gyroZ:r}=this,{alpha:a,beta:h,gamma:l}=t,u=s&&null!=a?a:e,c=n&&null!=h?h:i,p=r&&null!=l?l:o;if(this.absolute)this.alpha=u,this.beta=c,this.gamma=p;else if(this.cache){const{alpha:t,beta:e,gamma:i}=this.cache;this.alpha=null===u?null:null===t?u:u-t,this.beta=null===c?null:null===e?c:c-e,this.gamma=null===p?null:null===i?p:p-i}else this.cache={alpha:u,beta:c,gamma:p};this.onChange(this.alpha,this.beta,this.gamma)},window.addEventListener("deviceorientation",this.gyroEvent)}inActive(){this._isActive=!1,this.gyroEvent&&(window.removeEventListener("deviceorientation",this.gyroEvent),this.gyroEvent=null)}}var p,g;function d(t){const s=new e,r=new i,a=new o;return s.lookAt(new n,t,new n(0,1,0)),r.setFromRotationMatrix(s),a.setFromQuaternion(r),a}function m(t){return new n(0,0,-1).applyQuaternion((new i).setFromEuler(t))}function v(t){return m(t).normalize()}function y(t,e){return"function"==typeof t?t(e):t}function T(t,e){return"function"==typeof t?t(e):t}!function(t){t.FIRST_VISION="first",t.THIRD_VISION="third",t.UP_VISION="up",t.LEFT_VISION="left"}(p||(p={})),function(t){t.RELATIVE_ORIENTATION="relative",t.FIXED_ORIENTATION="fixed",t.GYRO_ORIENTATION="gyro"}(g||(g={}));const f=Object.freeze({disabledAnimate:!1,fixedOrientation:!1,autoRestoreOrientation:1500,oppositeCamera:!1,oppositeType:{x:!1,y:!0,z:!1},orientationTarget:"main",vision:p.THIRD_VISION,orientationType:g.RELATIVE_ORIENTATION,rotationToTarget:new n(0,4,-10),distanceToTarget:1,targetRotationFix:[0,0,0,"XYZ"],isFixRotationRelativeTarget:!0,targetPositionFix:[0,2,0],isFixPositionRelativeTarget:!1,enableGyro:!1,gyroX:!1,gyroY:!0,gyroZ:!1,gyroAbsolute:!0,onControlStart:null,onControlRender:null,onControlEnd:null});function _(t){const e=(new i).setFromEuler((new o).fromArray(t));this.quaternion.multiply(e)}class w extends l{get position(){return this.nativeCamera.position}get rotation(){return this.nativeCamera.rotation}get quaternion(){return this.nativeCamera.quaternion}_lookAt(...t){this.nativeCamera.lookAt(...t),this.isFixRotationRelativeTarget||_.call(this.nativeCamera,this.targetRotationAfterFix)}get enableGyro(){return this._enableGyro}set enableGyro(t){this._enableGyro=t,t?this._gyroListener.active():this._gyroListener.inActive()}get gyroX(){return this._gyroListener.gyroX}set gyroX(t){this._gyroListener.gyroX=t}get gyroY(){return this._gyroListener.gyroY}set gyroY(t){this._gyroListener.gyroY=t}get gyroZ(){return this._gyroListener.gyroZ}set gyroZ(t){this._gyroListener.gyroZ=t}get gyroAbsolute(){return this._gyroListener.absolute}set gyroAbsolute(t){this._gyroListener.absolute=t}get targetRotationAfterFix(){return T(this.targetRotationFix)}get targetPositionAfterFix(){return y(this.targetPositionFix)}get realDistanceToTarget(){return"first"===this.vision?1:this.distanceToTarget}get realRotationToTarget(){switch(this.vision){case"first":return new n(0,0,-1);case"up":return new n(0,1,-.01);case"left":return new n(1,0,0);default:return this.rotationToTarget}}get orientationType(){return this._orientationType}set orientationType(t){this._orientationType=t,t===g.GYRO_ORIENTATION?this._gyroListener.active():this._gyroListener.inActive(),t===g.FIXED_ORIENTATION&&this._fixedOrientationRotation.copy(this.followRotation),this.restoreOrientation()}get orientationTarget(){return this._orientationTarget}set orientationTarget(t){this._orientationTarget=t,this.restoreOrientation()}get vision(){return this._vision}set vision(t){this._vision=t,this.followTarget.visible=t!==p.FIRST_VISION,this.restoreOrientation()}get followTarget(){return this._followTarget}set followTarget(t){this._followTarget=t,this.restoreOrientation()}get followPosition(){const t=new n;return t.fromArray(this.targetPositionAfterFix),this.isFixPositionRelativeTarget&&t.applyEuler(this.followRotation),this.followTarget.position.clone().add(t)}get followRotation(){const t=this.followTarget.rotation;if(this.isFixRotationRelativeTarget){const e=(new o).copy(t),n=(new i).setFromEuler(e),s=(new i).setFromEuler((new o).fromArray(this.targetRotationAfterFix));return n.multiply(s),(new o).setFromQuaternion(n)}return this.followTarget.rotation}get fixedOrientation(){return this._fixedOrientation}set fixedOrientation(t){this._fixedOrientation=t,t||this.restoreOrientation()}constructor(t,e,i){const n=null!=e?e:new s(80,1,.1,100);super(t,n),this.ssp=t,this.initOptions=f,this.cameraKey="navigatorCamera"+~~(1e4*Math.random()),this._events={onRender:()=>{},onMouseDown:t=>{}},this._restoreTimer=void 0,this._positionTween=null,this.autoFollowRender=!0,this._cameraPlaceholder=new r,this.disabledAnimate=f.disabledAnimate,this.distanceToTarget=f.distanceToTarget,this.rotationToTarget=f.rotationToTarget,this.oppositeCamera=f.oppositeCamera,this.oppositeType=f.oppositeType,this.isFixRotationRelativeTarget=f.isFixRotationRelativeTarget,this.targetRotationFix=f.targetRotationFix,this.isFixPositionRelativeTarget=f.isFixPositionRelativeTarget,this.targetPositionFix=f.targetPositionFix,this.autoRestoreOrientation=f.autoRestoreOrientation,this.onControlStart=null,this.onControlRender=null,this.onControlEnd=null,this._enableGyro=!1,this._gyroRotation=new o,this._orientationType=f.orientationType,this._fixedOrientationRotation=new o,this._orientationTarget=f.orientationTarget,this._vision=f.vision,this._followTarget=new r,this._fixedOrientation=f.fixedOrientation,this.initGyroListener();const a=Object.freeze(Object.assign(Object.assign({},f),null!=i?i:{}));this.initOptions=a,this.setOptions(a),this.setCamera(n)}initGyroListener(){const t=this.initOptions;this._gyroListener=new c(t.gyroX,t.gyroY,t.gyroZ,t.gyroAbsolute),this._gyroListener.onChange=(t,e,i)=>{const n=null===t?0:a.degToRad(t),s=null===e?0:a.degToRad(e),r=null===i?0:a.degToRad(i);this._gyroRotation=new o(s,n,r)}}setCameraOrientationOnControl(){const{rotation:t}=this.ssp.viewport.cameraManager.mainCamera,{realDistanceToTarget:e,followPosition:i}=this,o=v(t);this.position.copy(i.clone().add(o.multiplyScalar(-e))),this._lookAt(this.followPosition)}updateCameraPlaceholder(){const t=this.getRenderCameraPosition();this._cameraPlaceholder.position.copy(t)}setCameraOrientationOnRender(){this.position.copy(this._cameraPlaceholder.position),this._lookAt(this.followPosition)}getRenderCameraOrientation(){const{_fixedOrientationRotation:t,_orientationType:e,_orientationTarget:i}=this,s=new o;switch(e===g.GYRO_ORIENTATION&&s.copy(this._gyroRotation),!0){case"main"===i:s.copy(e===g.FIXED_ORIENTATION?t:this.followRotation);break;case i instanceof n:{const t=this.orientationTarget.clone().sub(this.followPosition);s.copy(d(t));break}case i instanceof r:{const t=i;switch(e){case g.RELATIVE_ORIENTATION:s.copy(t.rotation);break;case g.FIXED_ORIENTATION:s.copy(d(t.position.clone().sub(this.followPosition)))}break}case i instanceof o:s.copy(i)}return s}getRenderCameraPosition(){const t=new n,e=this.getRenderCameraOrientation(),{realDistanceToTarget:i,realRotationToTarget:o}=this;if(t.copy(this.followPosition.clone().add(o.clone().applyEuler(e).normalize().multiplyScalar(i))),this.oppositeCamera){const e=this.followPosition.clone().sub(t).multiplyScalar(2),{x:i,y:o,z:n}=this.oppositeType;[i,o,n].includes(!1)&&[i,o,n].includes(!0)?(i&&(e.x=0),o&&(e.y=0),n&&(e.z=0),t.add(e)):i&&t.add(e)}return t}onRender(){this.followTarget&&(this.updateCameraPlaceholder(),this._positionTween||(this.autoFollowRender||this.fixedOrientation?this.setCameraOrientationOnRender():this.onControlRender?this.onControlRender(this.nativeCamera,this.followTarget):this.setCameraOrientationOnControl()))}initEvents(){var t;const e=this.ssp.viewport.renderer.domElement,n=this.ssp.viewport.cameraManager.mainCamera,s=this.onRender.bind(this),r=t=>{var e,s;const r=!1===this.autoFollowRender;if(this.autoFollowRender=!1,null===(e=this._positionTween)||void 0===e||e.stop(),window.clearTimeout(this._restoreTimer),document.removeEventListener("mouseup",a),document.removeEventListener("touchend",a),document.addEventListener("mouseup",a,!0),document.addEventListener("touchend",a,!0),!r){if(this.isFixRotationRelativeTarget)n.quaternion.copy(this.quaternion);else{const t=(new i).setFromEuler((new o).fromArray(this.targetRotationAfterFix)).invert();n.quaternion.copy((new i).copy(this.quaternion).multiply(t))}null===(s=this.onControlStart)||void 0===s||s.call(this,this.nativeCamera,this.followTarget,t)}},a=t=>{const e=()=>{var e;this.restoreOrientation(),this.autoFollowRender=!0,null===(e=this.onControlEnd)||void 0===e||e.call(this,this.nativeCamera,this.followTarget,t),document.removeEventListener("mouseup",a,!0),document.removeEventListener("touchend",a,!0)};"number"==typeof this.autoRestoreOrientation?(window.clearTimeout(this._restoreTimer),this._restoreTimer=setTimeout(e,this.autoRestoreOrientation)):this.autoRestoreOrientation&&e()};this._events.onRender=s,this._events.onMouseDown=r;const h=this.ssp.signals;h.beforeRender.add(s),h.mouseDown.add(r),null===(t=e.parentElement)||void 0===t||t.addEventListener("touchstart",r,!0)}clearEvents(){var t;const{onRender:e,onMouseDown:i}=this._events,o=this.ssp.signals,n=this.ssp.viewport.renderer.domElement;o.beforeRender.remove(e),o.mouseDown.remove(i),null===(t=n.parentElement)||void 0===t||t.removeEventListener("touchstart",i,!0)}onEnter(){console.log("onenter"),this.initEvents()}onQuit(){console.log("onquit"),this.clearEvents(),this._gyroListener.inActive()}resetOptions(){this.setOptions(Object.assign({},this.initOptions))}setOptions(t){const e=this.disabledAnimate;this.disabledAnimate=!0,void 0!==t.isFixPositionRelativeTarget&&(this.isFixPositionRelativeTarget=t.isFixPositionRelativeTarget),void 0!==t.targetPositionFix&&(this.targetPositionFix=t.targetPositionFix),void 0!==t.isFixRotationRelativeTarget&&(this.isFixRotationRelativeTarget=t.isFixRotationRelativeTarget),void 0!==t.targetRotationFix&&(this.targetRotationFix=t.targetRotationFix),void 0!==t.rotationToTarget&&(this.rotationToTarget=t.rotationToTarget),void 0!==t.distanceToTarget&&(this.distanceToTarget=t.distanceToTarget),void 0!==t.fixedOrientation&&(this.fixedOrientation=t.fixedOrientation),void 0!==t.oppositeCamera&&(this.oppositeCamera=t.oppositeCamera),void 0!==t.oppositeType&&(this.oppositeType=t.oppositeType),void 0!==t.orientationTarget&&(this.orientationTarget=t.orientationTarget),void 0!==t.orientationType&&(this.orientationType=t.orientationType),void 0!==t.vision&&(this.vision=t.vision),void 0!==t.autoRestoreOrientation&&(this.autoRestoreOrientation=t.autoRestoreOrientation),void 0!==t.gyroX&&(this.gyroX=t.gyroX),void 0!==t.gyroY&&(this.gyroY=t.gyroY),void 0!==t.gyroZ&&(this.gyroZ=t.gyroZ),void 0!==t.gyroAbsolute&&(this.gyroAbsolute=t.gyroAbsolute),void 0!==t.enableGyro&&(this.enableGyro=t.enableGyro),void 0!==t.onControlStart&&(this.onControlStart=t.onControlStart),void 0!==t.onControlRender&&(this.onControlRender=t.onControlRender),void 0!==t.onControlEnd&&(this.onControlEnd=t.onControlEnd),this.disabledAnimate=e,void 0!==t.disabledAnimate&&(this.disabledAnimate=t.disabledAnimate)}setCamera(t){return this._isActive&&this.ssp.viewport.cameraManager.removeCamera(this.cameraKey),this.nativeCamera=t,this.ssp.viewport.cameraManager.cameras[this.cameraKey]=t,this._isActive&&this.ssp.viewport.cameraManager.setCurrentCamera(t),this}restoreOrientation(){if(this.followTarget&&!this.fixedOrientation){if(this._positionTween&&(this._positionTween.stop(),this._positionTween=null),this.disabledAnimate)return this.position.copy(this._cameraPlaceholder.position),void this._lookAt(this.followPosition);this.ssp.animation(this.position,this._cameraPlaceholder.position,{duration:1e3},(t=>{this._lookAt(this.followPosition)}),(t=>this._positionTween=t)).finally((()=>{this._positionTween=null}))}}}var O;!function(t){t.PENDING="pending",t.STOP="stop",t.PLAYING="playing",t.PAUSE="pause",t.FINISHED="finished"}(O||(O={}));var R=Object.defineProperty,A=(t,e,i)=>(((t,e,i)=>{e in t?R(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i})(t,"symbol"!=typeof e?e+"":e,i),i);function E(t,e,i){let o=function(t,e){const i=Math.sqrt(t.lengthSq()*e.lengthSq());if(0===i)return 0;let o=t.dot(e)/i;return o=Math.max(-1,Math.min(1,o)),Math.acos(o)}(t,e);return 0===o?o:t.clone().cross(e).dot(i)<0?-o:o}const C=180/Math.PI,b={yaw:[{name:"前",range:[-15,15]},{name:"左",range:[15,165]},{name:"右",range:[-165,-15]},{name:"后",range:[-180.1,-165]},{name:"后",range:[165,180.1]}],pitch:[{name:"前",range:[-15,15]},{name:"上",range:[15,165]},{name:"下",range:[-165,-15]},{name:"后",range:[-180.1,-165]},{name:"后",range:[165,180.1]}],roll:[{name:"上",range:[-15,15]},{name:"左",range:[15,165]},{name:"右",range:[-165,-15]},{name:"下",range:[-180.1,-165]},{name:"下",range:[165,180.1]}]};const x={degrees:!0,map:b,front:{x:0,y:0,z:1},up:{x:0,y:1,z:0}};class P{constructor(t){A(this,"_options"),A(this,"_listMap"),A(this,"_front"),A(this,"_up"),t&&(this.options=t)}static get options(){return this._options??(this.options=x)}static set options(t){this._options=Object.assign({},structuredClone(b),t)}get defaultOptions(){return this.constructor.options}get options(){return this._options??(this.options=this.defaultOptions)}set options(t){this._options=Object.assign({},structuredClone(this.defaultOptions),t),this._listMap=null,this._front=null,this._up=null}get degrees(){return this.options.degrees??(this.options.degrees=this.defaultOptions.degrees??!0)}set degrees(t){this.options.degrees=t}get map(){return this.options.map||(this.map=this.defaultOptions.map),this.options.map}set map(t){const e=structuredClone(this.defaultOptions.map),i=structuredClone(b);t=t?{yaw:t.yaw??e.yaw??i.yaw,pitch:t.pitch??e.pitch??i.pitch,roll:t.roll??e.roll??i.roll}:e,this.options.map=t,this._listMap=null}get listMap(){return this._listMap??(this._listMap=function(t){const e={};for(const[i,o]of Object.entries(t))e[i]=Array.isArray(o)?o:Object.entries(o).map((([t,e])=>({name:t,range:e})));return e}(this.map??{}))}get front(){return this._front||(this.front=this.options.front??this.defaultOptions.front??x.front),this._front}set front(t){this._front=(new n).copy(t)}get up(){return this._up||(this.up=this.options.up??this.defaultOptions.up??x.up),this._up}set up(t){this._up=(new n).copy(t)}computeAzimuth(t,e,i){const o=(new n).copy(t),s=(new n).copy(e??this.front),r=(new n).copy(i??this.up);let{yaw:a,pitch:h,roll:l}=function(t,e,i){const o=e.clone().negate(),n=i.clone().projectOnPlane(e),s=E(e,t.clone().projectOnPlane(n),n),r=e.clone().cross(n);return{yaw:s,pitch:E(e,t.clone().projectOnPlane(r),r),roll:E(n,t.clone().projectOnPlane(o),o)}}(o,s,r);return this.degrees&&(a*=C,h*=C,l*=C),{yaw:{angle:a,name:this.findAzimuthNames("yaw",a)},pitch:{angle:h,name:this.findAzimuthNames("pitch",h)},roll:{angle:l,name:this.findAzimuthNames("roll",l)}}}findAzimuthNames(t,e){const i=[],o=this.listMap[t];if(!o)return i;for(const{name:t,range:[n,s]}of o)(e>=n&&e<s||e<=n&&e>s)&&i.push(t);return i}}A(P,"_options");const F=new P;function I(t,e){F.map={yaw:{left:[20,170],right:[-170,-20]},pitch:{up:[20,170],down:[-170,-20]}};const{yaw:i,pitch:o}=F.computeAzimuth(t,e),n=i.name,s=o.name;return n&&s?s?n?`${n}-${s}`:s:n:"straight"}function N(t,e){return e.reverse().map((e=>{t.removeObjectById(e.sid);const i=e.nodes.reverse().map((t=>({id:t.sid,position:t.position,graphs:t.graphs})));return t.createTopology(Object.assign(Object.assign({},e.info),{nodes:i}))}))}function S(t,e,i){if(!e||!i)return"straight";return I(e.position.clone().sub(t.position),i.position.clone().sub(e.position))}function L(t){const e=t.nodes,i=t.getLength();let o=0,n=0;return e.reduce(((t,s,r)=>{const a=e[r+1],h=e[r+2],l=a?a.position.clone().distanceTo(s.position):0,u=S(s,a,h),c=o+l,p=c/i,g={progressArea:[n,p],distanceArea:[o,c],node:s,nextNode:a,distanceToStart:o,distanceToEnd:i-o,distanceToNext:l,frontDirection:u};return o=c,n=p,t.push(g),t}),[])}function z(t,e){return 0===t?e[0]:100===t?e[e.length-1]:e.find((e=>{const[i,o]=e.progressArea;return t>=i&&t<o}))}function M(t,e){if(!e)return{distanceToStartNode:0,distanceToEndNode:0,distanceToStart:0,distanceToEnd:0};const[i,o]=e.progressArea,{distanceToNext:n,distanceToEnd:s,distanceToStart:r}=e,a=(t-i)/(o-i),h=n*a,l=n*(1-a);return{distanceToStartNode:h,distanceToEndNode:l,distanceToStart:h+r,distanceToEnd:s-l}}new h;class D{get model(){return this._model}set model(t){this._model=t}get speed(){return this._speed}set speed(t){this._speed=t}get pathProgress(){return this._pathProgress}set pathProgress(t){this._pathProgress=t}get totalProgress(){return this._pathProgress}set totalProgress(t){this._pathProgress=t}get currentPath(){return this.paths[this.currentPathIndex]}get currentPathIndex(){return this._currentPathIndex}get currentRotationVector(){return this._nextNode&&this._currentNode?this._nextNode.clone().sub(this._currentNode):new n}constructor(t,e){this.ssp=t,this.paths=e,this.onPlay=()=>{},this.onStatusChange=()=>{},this.loop=!1,this.autoNext=!0,this.playAfterStart=!1,this.flyToModelAfterStart=!0,this.backStartPointWhenStop=!0,this._model=new r,this._speed=1,this._pathProgress=0,this._totalProgress=0,this._currentPathIndex=0,this._currentNode=null,this._nextNode=null,this._playStatus=O.PENDING}changeStatus(t){this._playStatus=t,this.onStatusChange(t)}start(){}restart(){this.stop(),this.start()}play(t=0,e){this.changeStatus(O.PLAYING),this.paths[t]}pause(){this.changeStatus(O.PAUSE)}stop(){this.changeStatus(O.STOP)}flip(){}over(){this.changeStatus(O.PENDING)}}const G=new P;export{P as Azimuth,c as GyroListener,u as MapCamera,g as NAVIGATE_ORIENTATION_TYPE,p as NAVIGATE_VISION_TYPE,w as NavigateCamera,D as Navigator,O as PLAY_STATUS,l as SoonSpaceCamera,d as Vector3ToEuler,G as azimuth,m as eulerToVector3,I as getDirection,S as getDirectionByNodes,M as getDistanceInfoByProgress,T as getFixEuler,y as getFixVector,z as getNavigatorNodeInfoByProgress,L as getNavigatorNodeInfosByTopology,v as normalizeEuler,N as reverseTopologies};
1
+ import{OrthographicCamera as t,Matrix4 as e,Quaternion as i,Euler as o,Vector3 as n,PerspectiveCamera as s,Object3D as r,MathUtils as a,Matrix3 as h}from"three";class l{constructor(t,e){this.ssp=t,this.nativeCamera=e,this._isActive=!1,this.ssp.signals.cameraObjectChange.add(()=>{const t=this.ssp.viewport.cameraManager.currentCamera;this._isActive&&t===this.nativeCamera||(t===this.nativeCamera?(this._onBeforeEnter(),this.onEnter()):this._isActive&&t!==this.nativeCamera&&(this._onBeforeQuit(),this.onQuit()))})}active(){this.ssp.viewport.cameraManager.setCurrentCamera(this.nativeCamera)}_onBeforeEnter(){this._isActive=!0}_onBeforeQuit(){this._isActive=!1}onEnter(){}onQuit(){}}class u extends l{get zoom(){return this._zoom}set zoom(t){this._zoom=t,this.resizeCamera()}constructor(e){const i=new t;super(e,i),this.ssp=e,this.resizeObserver=new ResizeObserver(()=>{this.resizeCamera()}),this._zoom=.01,i.far=2e5}resizeCamera(){if(this._isActive){const{clientWidth:t,clientHeight:e}=this.ssp.viewport.renderer.domElement,i=t*this.zoom/2,o=e*this.zoom/2;this.nativeCamera.left=-i,this.nativeCamera.right=i,this.nativeCamera.top=o,this.nativeCamera.bottom=-o,this.nativeCamera.updateProjectionMatrix()}}onEnter(){console.log("map camera enter"),this.ssp.domElement&&(this.resizeObserver.observe(this.ssp.domElement),this.resizeCamera())}onQuit(){this.ssp.domElement&&(this.resizeObserver.unobserve(this.ssp.domElement),console.log("map camera quit"))}}class c{constructor(t,e,i,o){this.gyroEvent=null,this.onChange=()=>{},this._isActive=!1,this.defaultBeta=null,this.defaultAlpha=null,this.defaultGamma=null,this.cache=null,this.beta=null,this.alpha=null,this.gamma=null,this.gyroX=null==t||t,this.gyroY=null==e||e,this.gyroZ=null==i||i,this.absolute=null==o||o}requestPermisson(){return new Promise((t,e)=>{var i;window.DeviceOrientationEvent.requestPermission||t(!0),null===(i=window.DeviceOrientationEvent)||void 0===i||i.requestPermission().then(i=>{"granted"===i?t(!0):e("用户拒绝使用陀螺仪权限")})})}async active(){await this.requestPermisson(),this._isActive=!0,this.gyroEvent&&this.inActive(),this.gyroEvent=t=>{const{defaultAlpha:e,defaultBeta:i,defaultGamma:o,gyroX:n,gyroY:s,gyroZ:r}=this,{alpha:a,beta:h,gamma:l}=t,u=s&&null!=a?a:e,c=n&&null!=h?h:i,p=r&&null!=l?l:o;if(this.absolute)this.alpha=u,this.beta=c,this.gamma=p;else if(this.cache){const{alpha:t,beta:e,gamma:i}=this.cache;this.alpha=null===u?null:null===t?u:u-t,this.beta=null===c?null:null===e?c:c-e,this.gamma=null===p?null:null===i?p:p-i}else this.cache={alpha:u,beta:c,gamma:p};this.onChange(this.alpha,this.beta,this.gamma)},window.addEventListener("deviceorientation",this.gyroEvent)}inActive(){this._isActive=!1,this.gyroEvent&&(window.removeEventListener("deviceorientation",this.gyroEvent),this.gyroEvent=null)}}var p,g;function d(t){const s=new e,r=new i,a=new o;return s.lookAt(new n,t,new n(0,1,0)),r.setFromRotationMatrix(s),a.setFromQuaternion(r),a}function m(t){return new n(0,0,-1).applyQuaternion((new i).setFromEuler(t))}function v(t){return m(t).normalize()}function y(t,e){return"function"==typeof t?t(e):t}function T(t,e){return"function"==typeof t?t(e):t}!function(t){t.FIRST_VISION="first",t.THIRD_VISION="third",t.UP_VISION="up",t.LEFT_VISION="left"}(p||(p={})),function(t){t.RELATIVE_ORIENTATION="relative",t.FIXED_ORIENTATION="fixed",t.GYRO_ORIENTATION="gyro"}(g||(g={}));const f=Object.freeze({disabledAnimate:!1,fixedOrientation:!1,autoRestoreOrientation:1500,oppositeCamera:!1,oppositeType:{x:!1,y:!0,z:!1},orientationTarget:"main",vision:p.THIRD_VISION,orientationType:g.RELATIVE_ORIENTATION,rotationToTarget:new n(0,4,-10),distanceToTarget:1,targetRotationFix:[0,0,0,"XYZ"],isFixRotationRelativeTarget:!0,targetPositionFix:[0,2,0],isFixPositionRelativeTarget:!1,enableGyro:!1,gyroX:!1,gyroY:!0,gyroZ:!1,gyroAbsolute:!0,onControlStart:null,onControlRender:null,onControlEnd:null});function _(t){const e=(new i).setFromEuler((new o).fromArray(t));this.quaternion.multiply(e)}class w extends l{get position(){return this.nativeCamera.position}get rotation(){return this.nativeCamera.rotation}get quaternion(){return this.nativeCamera.quaternion}_lookAt(...t){this.nativeCamera.lookAt(...t),this.isFixRotationRelativeTarget||_.call(this.nativeCamera,this.targetRotationAfterFix)}get enableGyro(){return this._enableGyro}set enableGyro(t){this._enableGyro=t,t?this._gyroListener.active():this._gyroListener.inActive()}get gyroX(){return this._gyroListener.gyroX}set gyroX(t){this._gyroListener.gyroX=t}get gyroY(){return this._gyroListener.gyroY}set gyroY(t){this._gyroListener.gyroY=t}get gyroZ(){return this._gyroListener.gyroZ}set gyroZ(t){this._gyroListener.gyroZ=t}get gyroAbsolute(){return this._gyroListener.absolute}set gyroAbsolute(t){this._gyroListener.absolute=t}get targetRotationAfterFix(){return T(this.targetRotationFix)}get targetPositionAfterFix(){return y(this.targetPositionFix)}get realDistanceToTarget(){return"first"===this.vision?1:this.distanceToTarget}get realRotationToTarget(){switch(this.vision){case"first":return new n(0,0,-1);case"up":return new n(0,1,-.01);case"left":return new n(1,0,0);default:return this.rotationToTarget}}get orientationType(){return this._orientationType}set orientationType(t){this._orientationType=t,t===g.GYRO_ORIENTATION?this._gyroListener.active():this._gyroListener.inActive(),t===g.FIXED_ORIENTATION&&this._fixedOrientationRotation.copy(this.followRotation),this.restoreOrientation()}get orientationTarget(){return this._orientationTarget}set orientationTarget(t){this._orientationTarget=t,this.restoreOrientation()}get vision(){return this._vision}set vision(t){this._vision=t,this.followTarget.visible=t!==p.FIRST_VISION,this.restoreOrientation()}get followTarget(){return this._followTarget}set followTarget(t){this._followTarget=t,this.restoreOrientation()}get followPosition(){const t=new n;return t.fromArray(this.targetPositionAfterFix),this.isFixPositionRelativeTarget&&t.applyEuler(this.followRotation),this.followTarget.position.clone().add(t)}get followRotation(){const t=this.followTarget.rotation;if(this.isFixRotationRelativeTarget){const e=(new o).copy(t),n=(new i).setFromEuler(e),s=(new i).setFromEuler((new o).fromArray(this.targetRotationAfterFix));return n.multiply(s),(new o).setFromQuaternion(n)}return this.followTarget.rotation}get fixedOrientation(){return this._fixedOrientation}set fixedOrientation(t){this._fixedOrientation=t,t||this.restoreOrientation()}constructor(t,e,i){const n=null!=e?e:new s(80,1,.1,100);super(t,n),this.ssp=t,this.initOptions=f,this.cameraKey="navigatorCamera"+~~(1e4*Math.random()),this._events={onRender:()=>{},onMouseDown:t=>{}},this._restoreTimer=void 0,this._positionTween=null,this.autoFollowRender=!0,this._cameraPlaceholder=new r,this.disabledAnimate=f.disabledAnimate,this.distanceToTarget=f.distanceToTarget,this.rotationToTarget=f.rotationToTarget,this.oppositeCamera=f.oppositeCamera,this.oppositeType=f.oppositeType,this.isFixRotationRelativeTarget=f.isFixRotationRelativeTarget,this.targetRotationFix=f.targetRotationFix,this.isFixPositionRelativeTarget=f.isFixPositionRelativeTarget,this.targetPositionFix=f.targetPositionFix,this.autoRestoreOrientation=f.autoRestoreOrientation,this.onControlStart=null,this.onControlRender=null,this.onControlEnd=null,this._enableGyro=!1,this._gyroRotation=new o,this._orientationType=f.orientationType,this._fixedOrientationRotation=new o,this._orientationTarget=f.orientationTarget,this._vision=f.vision,this._followTarget=new r,this._fixedOrientation=f.fixedOrientation,this.initGyroListener();const a=Object.freeze(Object.assign(Object.assign({},f),null!=i?i:{}));this.initOptions=a,this.setOptions(a),this.setCamera(n)}initGyroListener(){const t=this.initOptions;this._gyroListener=new c(t.gyroX,t.gyroY,t.gyroZ,t.gyroAbsolute),this._gyroListener.onChange=(t,e,i)=>{const n=null===t?0:a.degToRad(t),s=null===e?0:a.degToRad(e),r=null===i?0:a.degToRad(i);this._gyroRotation=new o(s,n,r)}}setCameraOrientationOnControl(){const{rotation:t}=this.ssp.viewport.cameraManager.mainCamera,{realDistanceToTarget:e,followPosition:i}=this,o=v(t);this.position.copy(i.clone().add(o.multiplyScalar(-e))),this._lookAt(this.followPosition)}updateCameraPlaceholder(){const t=this.getRenderCameraPosition();this._cameraPlaceholder.position.copy(t)}setCameraOrientationOnRender(){this.position.copy(this._cameraPlaceholder.position),this._lookAt(this.followPosition)}getRenderCameraOrientation(){const{_fixedOrientationRotation:t,_orientationType:e,_orientationTarget:i}=this,s=new o;switch(e===g.GYRO_ORIENTATION&&s.copy(this._gyroRotation),!0){case"main"===i:s.copy(e===g.FIXED_ORIENTATION?t:this.followRotation);break;case i instanceof n:{const t=this.orientationTarget.clone().sub(this.followPosition);s.copy(d(t));break}case i instanceof r:{const t=i;switch(e){case g.RELATIVE_ORIENTATION:s.copy(t.rotation);break;case g.FIXED_ORIENTATION:s.copy(d(t.position.clone().sub(this.followPosition)))}break}case i instanceof o:s.copy(i)}return s}getRenderCameraPosition(){const t=new n,e=this.getRenderCameraOrientation(),{realDistanceToTarget:i,realRotationToTarget:o}=this;if(t.copy(this.followPosition.clone().add(o.clone().applyEuler(e).normalize().multiplyScalar(i))),this.oppositeCamera){const e=this.followPosition.clone().sub(t).multiplyScalar(2),{x:i,y:o,z:n}=this.oppositeType;[i,o,n].includes(!1)&&[i,o,n].includes(!0)?(i&&(e.x=0),o&&(e.y=0),n&&(e.z=0),t.add(e)):i&&t.add(e)}return t}onRender(){this.followTarget&&(this.updateCameraPlaceholder(),this._positionTween||(this.autoFollowRender||this.fixedOrientation?this.setCameraOrientationOnRender():this.onControlRender?this.onControlRender(this.nativeCamera,this.followTarget):this.setCameraOrientationOnControl()))}initEvents(){var t;const e=this.ssp.viewport.renderer.domElement,n=this.ssp.viewport.cameraManager.mainCamera,s=this.onRender.bind(this),r=t=>{var e,s;const r=!1===this.autoFollowRender;if(this.autoFollowRender=!1,null===(e=this._positionTween)||void 0===e||e.stop(),window.clearTimeout(this._restoreTimer),document.removeEventListener("mouseup",a),document.removeEventListener("touchend",a),document.addEventListener("mouseup",a,!0),document.addEventListener("touchend",a,!0),!r){if(this.isFixRotationRelativeTarget)n.quaternion.copy(this.quaternion);else{const t=(new i).setFromEuler((new o).fromArray(this.targetRotationAfterFix)).invert();n.quaternion.copy((new i).copy(this.quaternion).multiply(t))}null===(s=this.onControlStart)||void 0===s||s.call(this,this.nativeCamera,this.followTarget,t)}},a=t=>{const e=()=>{var e;this.restoreOrientation(),this.autoFollowRender=!0,null===(e=this.onControlEnd)||void 0===e||e.call(this,this.nativeCamera,this.followTarget,t),document.removeEventListener("mouseup",a,!0),document.removeEventListener("touchend",a,!0)};"number"==typeof this.autoRestoreOrientation?(window.clearTimeout(this._restoreTimer),this._restoreTimer=setTimeout(e,this.autoRestoreOrientation)):this.autoRestoreOrientation&&e()};this._events.onRender=s,this._events.onMouseDown=r;const h=this.ssp.signals;h.beforeRender.add(s),h.mouseDown.add(r),null===(t=e.parentElement)||void 0===t||t.addEventListener("touchstart",r,!0)}clearEvents(){var t;const{onRender:e,onMouseDown:i}=this._events,o=this.ssp.signals,n=this.ssp.viewport.renderer.domElement;o.beforeRender.remove(e),o.mouseDown.remove(i),null===(t=n.parentElement)||void 0===t||t.removeEventListener("touchstart",i,!0)}onEnter(){console.log("onenter"),this.initEvents()}onQuit(){console.log("onquit"),this.clearEvents(),this._gyroListener.inActive()}resetOptions(){this.setOptions(Object.assign({},this.initOptions))}setOptions(t){const e=this.disabledAnimate;this.disabledAnimate=!0,void 0!==t.isFixPositionRelativeTarget&&(this.isFixPositionRelativeTarget=t.isFixPositionRelativeTarget),void 0!==t.targetPositionFix&&(this.targetPositionFix=t.targetPositionFix),void 0!==t.isFixRotationRelativeTarget&&(this.isFixRotationRelativeTarget=t.isFixRotationRelativeTarget),void 0!==t.targetRotationFix&&(this.targetRotationFix=t.targetRotationFix),void 0!==t.rotationToTarget&&(this.rotationToTarget=t.rotationToTarget),void 0!==t.distanceToTarget&&(this.distanceToTarget=t.distanceToTarget),void 0!==t.fixedOrientation&&(this.fixedOrientation=t.fixedOrientation),void 0!==t.oppositeCamera&&(this.oppositeCamera=t.oppositeCamera),void 0!==t.oppositeType&&(this.oppositeType=t.oppositeType),void 0!==t.orientationTarget&&(this.orientationTarget=t.orientationTarget),void 0!==t.orientationType&&(this.orientationType=t.orientationType),void 0!==t.vision&&(this.vision=t.vision),void 0!==t.autoRestoreOrientation&&(this.autoRestoreOrientation=t.autoRestoreOrientation),void 0!==t.gyroX&&(this.gyroX=t.gyroX),void 0!==t.gyroY&&(this.gyroY=t.gyroY),void 0!==t.gyroZ&&(this.gyroZ=t.gyroZ),void 0!==t.gyroAbsolute&&(this.gyroAbsolute=t.gyroAbsolute),void 0!==t.enableGyro&&(this.enableGyro=t.enableGyro),void 0!==t.onControlStart&&(this.onControlStart=t.onControlStart),void 0!==t.onControlRender&&(this.onControlRender=t.onControlRender),void 0!==t.onControlEnd&&(this.onControlEnd=t.onControlEnd),this.disabledAnimate=e,void 0!==t.disabledAnimate&&(this.disabledAnimate=t.disabledAnimate)}setCamera(t){return this._isActive&&this.ssp.viewport.cameraManager.removeCamera(this.cameraKey),this.nativeCamera=t,this.ssp.viewport.cameraManager.cameras[this.cameraKey]=t,this._isActive&&this.ssp.viewport.cameraManager.setCurrentCamera(t),this}restoreOrientation(){if(this.followTarget&&!this.fixedOrientation){if(this._positionTween&&(this._positionTween.stop(),this._positionTween=null),this.disabledAnimate)return this.position.copy(this._cameraPlaceholder.position),void this._lookAt(this.followPosition);this.ssp.animation(this.position,this._cameraPlaceholder.position,{duration:1e3},t=>{this._lookAt(this.followPosition)},t=>this._positionTween=t).finally(()=>{this._positionTween=null})}}}var O;!function(t){t.PENDING="pending",t.STOP="stop",t.PLAYING="playing",t.PAUSE="pause",t.FINISHED="finished"}(O||(O={}));var R=Object.defineProperty,A=(t,e,i)=>(((t,e,i)=>{e in t?R(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i})(t,"symbol"!=typeof e?e+"":e,i),i);function E(t,e,i){let o=function(t,e){const i=Math.sqrt(t.lengthSq()*e.lengthSq());if(0===i)return 0;let o=t.dot(e)/i;return o=Math.max(-1,Math.min(1,o)),Math.acos(o)}(t,e);return 0===o?o:t.clone().cross(e).dot(i)<0?-o:o}const C=180/Math.PI,b={yaw:[{name:"前",range:[-15,15]},{name:"左",range:[15,165]},{name:"右",range:[-165,-15]},{name:"后",range:[-180.1,-165]},{name:"后",range:[165,180.1]}],pitch:[{name:"前",range:[-15,15]},{name:"上",range:[15,165]},{name:"下",range:[-165,-15]},{name:"后",range:[-180.1,-165]},{name:"后",range:[165,180.1]}],roll:[{name:"上",range:[-15,15]},{name:"左",range:[15,165]},{name:"右",range:[-165,-15]},{name:"下",range:[-180.1,-165]},{name:"下",range:[165,180.1]}]};const x={degrees:!0,map:b,front:{x:0,y:0,z:1},up:{x:0,y:1,z:0}};class P{constructor(t){A(this,"_options"),A(this,"_listMap"),A(this,"_front"),A(this,"_up"),t&&(this.options=t)}static get options(){return this._options??(this.options=x)}static set options(t){this._options=Object.assign({},structuredClone(b),t)}get defaultOptions(){return this.constructor.options}get options(){return this._options??(this.options=this.defaultOptions)}set options(t){this._options=Object.assign({},structuredClone(this.defaultOptions),t),this._listMap=null,this._front=null,this._up=null}get degrees(){return this.options.degrees??(this.options.degrees=this.defaultOptions.degrees??!0)}set degrees(t){this.options.degrees=t}get map(){return this.options.map||(this.map=this.defaultOptions.map),this.options.map}set map(t){const e=structuredClone(this.defaultOptions.map),i=structuredClone(b);t=t?{yaw:t.yaw??e.yaw??i.yaw,pitch:t.pitch??e.pitch??i.pitch,roll:t.roll??e.roll??i.roll}:e,this.options.map=t,this._listMap=null}get listMap(){return this._listMap??(this._listMap=function(t){const e={};for(const[i,o]of Object.entries(t))e[i]=Array.isArray(o)?o:Object.entries(o).map(([t,e])=>({name:t,range:e}));return e}(this.map??{}))}get front(){return this._front||(this.front=this.options.front??this.defaultOptions.front??x.front),this._front}set front(t){this._front=(new n).copy(t)}get up(){return this._up||(this.up=this.options.up??this.defaultOptions.up??x.up),this._up}set up(t){this._up=(new n).copy(t)}computeAzimuth(t,e,i){const o=(new n).copy(t),s=(new n).copy(e??this.front),r=(new n).copy(i??this.up);let{yaw:a,pitch:h,roll:l}=function(t,e,i){const o=e.clone().negate(),n=i.clone().projectOnPlane(e),s=E(e,t.clone().projectOnPlane(n),n),r=e.clone().cross(n);return{yaw:s,pitch:E(e,t.clone().projectOnPlane(r),r),roll:E(n,t.clone().projectOnPlane(o),o)}}(o,s,r);return this.degrees&&(a*=C,h*=C,l*=C),{yaw:{angle:a,name:this.findAzimuthNames("yaw",a)},pitch:{angle:h,name:this.findAzimuthNames("pitch",h)},roll:{angle:l,name:this.findAzimuthNames("roll",l)}}}findAzimuthNames(t,e){const i=[],o=this.listMap[t];if(!o)return i;for(const{name:t,range:[n,s]}of o)(e>=n&&e<s||e<=n&&e>s)&&i.push(t);return i}}A(P,"_options");const F=new P;function I(t,e){F.map={yaw:{left:[20,170],right:[-170,-20]},pitch:{up:[20,170],down:[-170,-20]}};const{yaw:i,pitch:o}=F.computeAzimuth(t,e),n=i.name,s=o.name;return n&&s?s?n?`${n}-${s}`:s:n:"straight"}function N(t,e){return e.reverse().map(e=>{t.removeObjectById(e.sid);const i=e.nodes.reverse().map(t=>({id:t.sid,position:t.position,graphs:t.graphs}));return t.createTopology(Object.assign(Object.assign({},e.info),{nodes:i}))})}function S(t,e,i){if(!e||!i)return"straight";return I(e.position.clone().sub(t.position),i.position.clone().sub(e.position))}function L(t){const e=t.nodes,i=t.getLength();let o=0,n=0;return e.reduce((t,s,r)=>{const a=e[r+1],h=e[r+2],l=a?a.position.clone().distanceTo(s.position):0,u=S(s,a,h),c=o+l,p=c/i,g={progressArea:[n,p],distanceArea:[o,c],node:s,nextNode:a,distanceToStart:o,distanceToEnd:i-o,distanceToNext:l,frontDirection:u};return o=c,n=p,t.push(g),t},[])}function z(t,e){return 0===t?e[0]:100===t?e[e.length-1]:e.find(e=>{const[i,o]=e.progressArea;return t>=i&&t<o})}function M(t,e){if(!e)return{distanceToStartNode:0,distanceToEndNode:0,distanceToStart:0,distanceToEnd:0};const[i,o]=e.progressArea,{distanceToNext:n,distanceToEnd:s,distanceToStart:r}=e,a=(t-i)/(o-i),h=n*a,l=n*(1-a);return{distanceToStartNode:h,distanceToEndNode:l,distanceToStart:h+r,distanceToEnd:s-l}}new h;class D{get model(){return this._model}set model(t){this._model=t}get speed(){return this._speed}set speed(t){this._speed=t}get pathProgress(){return this._pathProgress}set pathProgress(t){this._pathProgress=t}get totalProgress(){return this._pathProgress}set totalProgress(t){this._pathProgress=t}get currentPath(){return this.paths[this.currentPathIndex]}get currentPathIndex(){return this._currentPathIndex}get currentRotationVector(){return this._nextNode&&this._currentNode?this._nextNode.clone().sub(this._currentNode):new n}constructor(t,e){this.ssp=t,this.paths=e,this.onPlay=()=>{},this.onStatusChange=()=>{},this.loop=!1,this.autoNext=!0,this.playAfterStart=!1,this.flyToModelAfterStart=!0,this.backStartPointWhenStop=!0,this._model=new r,this._speed=1,this._pathProgress=0,this._totalProgress=0,this._currentPathIndex=0,this._currentNode=null,this._nextNode=null,this._playStatus=O.PENDING}changeStatus(t){this._playStatus=t,this.onStatusChange(t)}start(){}restart(){this.stop(),this.start()}play(t=0,e){this.changeStatus(O.PLAYING),this.paths[t]}pause(){this.changeStatus(O.PAUSE)}stop(){this.changeStatus(O.STOP)}flip(){}over(){this.changeStatus(O.PENDING)}}const G=new P;export{P as Azimuth,c as GyroListener,u as MapCamera,g as NAVIGATE_ORIENTATION_TYPE,p as NAVIGATE_VISION_TYPE,w as NavigateCamera,D as Navigator,O as PLAY_STATUS,l as SoonSpaceCamera,d as Vector3ToEuler,G as azimuth,m as eulerToVector3,I as getDirection,S as getDirectionByNodes,M as getDistanceInfoByProgress,T as getFixEuler,y as getFixVector,z as getNavigatorNodeInfoByProgress,L as getNavigatorNodeInfosByTopology,v as normalizeEuler,N as reverseTopologies};
@@ -1,68 +1,68 @@
1
- import { Object3D, Vector3 } from 'three';
2
- import SoonSpace from 'soonspacejs';
3
- import { Topology } from 'soonspacejs';
4
- import { PLAY_STATUS, playInfo } from './types';
5
- export * from './navigator-nodes';
6
- export * from './types';
7
- export * from './utils';
8
- export declare class Navigator {
9
- readonly ssp: SoonSpace;
10
- paths: Topology[];
11
- onPlay: (info: playInfo) => void;
12
- onStatusChange: (status: PLAY_STATUS) => void;
13
- /** 是否循环播放,默认为否 */
14
- loop: boolean;
15
- /** 是否自动开始下一段路径播放,默认为是 */
16
- autoNext: boolean;
17
- /** 开始或者重新开始后自动播放路径动画,默认为否 */
18
- playAfterStart: boolean;
19
- /** 开始时飞向模型,默认为是 */
20
- flyToModelAfterStart: boolean;
21
- /** 停止时是否返回起点,默认为是 */
22
- backStartPointWhenStop: boolean;
23
- /** 路径动画主体模型 */
24
- _model: Object3D<import("three").Object3DEventMap>;
25
- get model(): Object3D;
26
- set model(obj: Object3D);
27
- protected _speed: number;
28
- /** 播放速度 */
29
- get speed(): number;
30
- set speed(value: number);
31
- protected _pathProgress: number;
32
- /** 当前段进度 */
33
- get pathProgress(): number;
34
- set pathProgress(value: number);
35
- protected _totalProgress: number;
36
- /** 总进度 */
37
- get totalProgress(): number;
38
- set totalProgress(value: number);
39
- /** 当前播放的动画路径索引 */
40
- protected _currentPathIndex: number;
41
- /** 当前节点 */
42
- protected _currentNode: Vector3 | null;
43
- /** 下个路径节点 */
44
- protected _nextNode: Vector3 | null;
45
- /** 当前状态 */
46
- protected _playStatus: PLAY_STATUS;
47
- get currentPath(): Topology;
48
- /** 对外只读 当前路径索引 */
49
- get currentPathIndex(): number;
50
- /** 对外只读 当前朝向方向向量 */
51
- get currentRotationVector(): Vector3;
52
- constructor(ssp: SoonSpace, paths: Topology[]);
53
- protected changeStatus(status: PLAY_STATUS): void;
54
- /** 开始导航 */
55
- start(): void;
56
- /** 重新开始导航 */
57
- restart(): void;
58
- /** 播放动画 */
59
- play(index?: number, node?: Vector3): void;
60
- /** 暂停动画 */
61
- pause(): void;
62
- /** 停止动画 */
63
- stop(): void;
64
- /** 路径反转 */
65
- flip(): void;
66
- /** 结束导航 */
67
- over(): void;
68
- }
1
+ import { Object3D, Vector3 } from 'three';
2
+ import SoonSpace from 'soonspacejs';
3
+ import { Topology } from 'soonspacejs';
4
+ import { PLAY_STATUS, playInfo } from './types';
5
+ export * from './navigator-nodes';
6
+ export * from './types';
7
+ export * from './utils';
8
+ export declare class Navigator {
9
+ readonly ssp: SoonSpace;
10
+ paths: Topology[];
11
+ onPlay: (info: playInfo) => void;
12
+ onStatusChange: (status: PLAY_STATUS) => void;
13
+ /** 是否循环播放,默认为否 */
14
+ loop: boolean;
15
+ /** 是否自动开始下一段路径播放,默认为是 */
16
+ autoNext: boolean;
17
+ /** 开始或者重新开始后自动播放路径动画,默认为否 */
18
+ playAfterStart: boolean;
19
+ /** 开始时飞向模型,默认为是 */
20
+ flyToModelAfterStart: boolean;
21
+ /** 停止时是否返回起点,默认为是 */
22
+ backStartPointWhenStop: boolean;
23
+ /** 路径动画主体模型 */
24
+ _model: Object3D<import("three").Object3DEventMap>;
25
+ get model(): Object3D;
26
+ set model(obj: Object3D);
27
+ protected _speed: number;
28
+ /** 播放速度 */
29
+ get speed(): number;
30
+ set speed(value: number);
31
+ protected _pathProgress: number;
32
+ /** 当前段进度 */
33
+ get pathProgress(): number;
34
+ set pathProgress(value: number);
35
+ protected _totalProgress: number;
36
+ /** 总进度 */
37
+ get totalProgress(): number;
38
+ set totalProgress(value: number);
39
+ /** 当前播放的动画路径索引 */
40
+ protected _currentPathIndex: number;
41
+ /** 当前节点 */
42
+ protected _currentNode: Vector3 | null;
43
+ /** 下个路径节点 */
44
+ protected _nextNode: Vector3 | null;
45
+ /** 当前状态 */
46
+ protected _playStatus: PLAY_STATUS;
47
+ get currentPath(): Topology;
48
+ /** 对外只读 当前路径索引 */
49
+ get currentPathIndex(): number;
50
+ /** 对外只读 当前朝向方向向量 */
51
+ get currentRotationVector(): Vector3;
52
+ constructor(ssp: SoonSpace, paths: Topology[]);
53
+ protected changeStatus(status: PLAY_STATUS): void;
54
+ /** 开始导航 */
55
+ start(): void;
56
+ /** 重新开始导航 */
57
+ restart(): void;
58
+ /** 播放动画 */
59
+ play(index?: number, node?: Vector3): void;
60
+ /** 暂停动画 */
61
+ pause(): void;
62
+ /** 停止动画 */
63
+ stop(): void;
64
+ /** 路径反转 */
65
+ flip(): void;
66
+ /** 结束导航 */
67
+ over(): void;
68
+ }
@@ -1,26 +1,26 @@
1
- import type { Node, Topology } from 'soonspacejs';
2
- import { Direction } from './types';
3
- interface NavigatorNodeInfo {
4
- progressArea: [number, number];
5
- distanceArea: [number, number];
6
- node: Node;
7
- nextNode?: Node;
8
- distanceToNext: number;
9
- distanceToStart: number;
10
- distanceToEnd: number;
11
- frontDirection: Direction;
12
- }
13
- interface DistanceInfo {
14
- distanceToStartNode: number;
15
- distanceToEndNode: number;
16
- distanceToStart: number;
17
- distanceToEnd: number;
18
- }
19
- export declare function getDirectionByNodes(p1: Node, p2?: Node, p3?: Node): Direction;
20
- /** 分析并返回所有节点信息 */
21
- export declare function getNavigatorNodeInfosByTopology(topology: Topology): NavigatorNodeInfo[];
22
- /** 根据进度获取当前节点信息 */
23
- export declare function getNavigatorNodeInfoByProgress(progress: number, infos: NavigatorNodeInfo[]): NavigatorNodeInfo | undefined;
24
- /** 获取当前位置距离信息 */
25
- export declare function getDistanceInfoByProgress(progress: number, info?: NavigatorNodeInfo): DistanceInfo;
26
- export {};
1
+ import type { Node, Topology } from 'soonspacejs';
2
+ import { Direction } from './types';
3
+ interface NavigatorNodeInfo {
4
+ progressArea: [number, number];
5
+ distanceArea: [number, number];
6
+ node: Node;
7
+ nextNode?: Node;
8
+ distanceToNext: number;
9
+ distanceToStart: number;
10
+ distanceToEnd: number;
11
+ frontDirection: Direction;
12
+ }
13
+ interface DistanceInfo {
14
+ distanceToStartNode: number;
15
+ distanceToEndNode: number;
16
+ distanceToStart: number;
17
+ distanceToEnd: number;
18
+ }
19
+ export declare function getDirectionByNodes(p1: Node, p2?: Node, p3?: Node): Direction;
20
+ /** 分析并返回所有节点信息 */
21
+ export declare function getNavigatorNodeInfosByTopology(topology: Topology): NavigatorNodeInfo[];
22
+ /** 根据进度获取当前节点信息 */
23
+ export declare function getNavigatorNodeInfoByProgress(progress: number, infos: NavigatorNodeInfo[]): NavigatorNodeInfo | undefined;
24
+ /** 获取当前位置距离信息 */
25
+ export declare function getDistanceInfoByProgress(progress: number, info?: NavigatorNodeInfo): DistanceInfo;
26
+ export {};
@@ -1,23 +1,23 @@
1
- import { Vector3 } from 'three';
2
- export type Direction = 'left' | 'right' | 'up' | 'down' | 'left-up' | 'left-down' | 'right-up' | 'right-down' | 'straight';
3
- export interface playInfo {
4
- pathId: string;
5
- progress: number;
6
- pathProgress: number;
7
- distanceToNodeStart: number;
8
- distanceToPathStart: number;
9
- distanceToStart: number;
10
- distanceToNodeEnd: number;
11
- distanceToPathEnd: number;
12
- distanceToEnd: number;
13
- position: Vector3;
14
- rotation: Vector3;
15
- direction: Direction;
16
- }
17
- export declare enum PLAY_STATUS {
18
- 'PENDING' = "pending",
19
- 'STOP' = "stop",
20
- 'PLAYING' = "playing",
21
- 'PAUSE' = "pause",
22
- 'FINISHED' = "finished"
23
- }
1
+ import { Vector3 } from 'three';
2
+ export type Direction = 'left' | 'right' | 'up' | 'down' | 'left-up' | 'left-down' | 'right-up' | 'right-down' | 'straight';
3
+ export interface playInfo {
4
+ pathId: string;
5
+ progress: number;
6
+ pathProgress: number;
7
+ distanceToNodeStart: number;
8
+ distanceToPathStart: number;
9
+ distanceToStart: number;
10
+ distanceToNodeEnd: number;
11
+ distanceToPathEnd: number;
12
+ distanceToEnd: number;
13
+ position: Vector3;
14
+ rotation: Vector3;
15
+ direction: Direction;
16
+ }
17
+ export declare enum PLAY_STATUS {
18
+ 'PENDING' = "pending",
19
+ 'STOP' = "stop",
20
+ 'PLAYING' = "playing",
21
+ 'PAUSE' = "pause",
22
+ 'FINISHED' = "finished"
23
+ }
@@ -1,12 +1,12 @@
1
- import SoonSpace from 'soonspacejs';
2
- import { Topology } from 'soonspacejs';
3
- import { Vector3 } from 'three';
4
- import { Direction } from './types';
5
- export declare function getDirection(target: Vector3, front: Vector3): Direction;
6
- /**
7
- * 路径反转
8
- * @param ssp
9
- * @param topologies 路径数组
10
- * @returns
11
- */
12
- export declare function reverseTopologies(ssp: SoonSpace, topologies: Topology[]): Topology[];
1
+ import SoonSpace from 'soonspacejs';
2
+ import { Topology } from 'soonspacejs';
3
+ import { Vector3 } from 'three';
4
+ import { Direction } from './types';
5
+ export declare function getDirection(target: Vector3, front: Vector3): Direction;
6
+ /**
7
+ * 路径反转
8
+ * @param ssp
9
+ * @param topologies 路径数组
10
+ * @returns
11
+ */
12
+ export declare function reverseTopologies(ssp: SoonSpace, topologies: Topology[]): Topology[];
@@ -1,26 +1,26 @@
1
- export declare class GyroListener {
2
- gyroEvent: null | ((event: DeviceOrientationEvent) => void);
3
- onChange: (alpha: number | null, beta: number | null, gamma: number | null) => void;
4
- _isActive: boolean;
5
- defaultBeta: number | null;
6
- defaultAlpha: number | null;
7
- defaultGamma: number | null;
8
- cache: null | {
9
- beta: number | null;
10
- alpha: number | null;
11
- gamma: number | null;
12
- };
13
- beta: number | null;
14
- alpha: number | null;
15
- gamma: number | null;
16
- gyroX: boolean;
17
- gyroY: boolean;
18
- gyroZ: boolean;
19
- absolute: boolean;
20
- constructor(x?: boolean, y?: boolean, z?: boolean, absolute?: boolean);
21
- requestPermisson(): Promise<unknown>;
22
- /** 监听陀螺仪事件 */
23
- active(): Promise<void>;
24
- /** 销毁陀螺仪事件 */
25
- inActive(): void;
26
- }
1
+ export declare class GyroListener {
2
+ gyroEvent: null | ((event: DeviceOrientationEvent) => void);
3
+ onChange: (alpha: number | null, beta: number | null, gamma: number | null) => void;
4
+ _isActive: boolean;
5
+ defaultBeta: number | null;
6
+ defaultAlpha: number | null;
7
+ defaultGamma: number | null;
8
+ cache: null | {
9
+ beta: number | null;
10
+ alpha: number | null;
11
+ gamma: number | null;
12
+ };
13
+ beta: number | null;
14
+ alpha: number | null;
15
+ gamma: number | null;
16
+ gyroX: boolean;
17
+ gyroY: boolean;
18
+ gyroZ: boolean;
19
+ absolute: boolean;
20
+ constructor(x?: boolean, y?: boolean, z?: boolean, absolute?: boolean);
21
+ requestPermisson(): Promise<unknown>;
22
+ /** 监听陀螺仪事件 */
23
+ active(): Promise<void>;
24
+ /** 销毁陀螺仪事件 */
25
+ inActive(): void;
26
+ }
@@ -1 +1 @@
1
- export * from './gyro';
1
+ export * from './gyro';
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@soonspacejs/plugin-navigation",
3
3
  "pluginName": "NavigationPlugin",
4
- "version": "2.13.9",
4
+ "version": "2.13.11",
5
5
  "description": "Navigation plugin for SoonSpace.js",
6
6
  "main": "dist/index.esm.js",
7
7
  "module": "dist/index.esm.js",
@@ -13,9 +13,9 @@
13
13
  ],
14
14
  "author": "zhuojian",
15
15
  "license": "UNLICENSED",
16
- "gitHead": "a5596909f48bd136905b85f239e13690f9f2c66e",
16
+ "gitHead": "08bf9efb38c291f22ca044b936fd49269c716bbb",
17
17
  "peerDependencies": {
18
- "soonspacejs": "2.13.9"
18
+ "soonspacejs": "2.13.11"
19
19
  },
20
20
  "dependencies": {
21
21
  "@three3d/tools": "^1.6.0"