deeptwins-engine-3d 0.0.43 → 0.0.44
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/cameraControl/ModelRoamHistory.d.ts +11 -3
- package/dist/cameraControl/ModelRoamHistory.js +101 -27
- package/dist/cameraControl/ModelRoamRealTime.d.ts +23 -47
- package/dist/cameraControl/ModelRoamRealTime.js +210 -374
- package/dist/constant.d.ts +3 -1
- package/dist/constant.js +4 -20
- package/dist/deepTwins/index.d.ts +0 -3
- package/dist/deepTwins/index.js +2 -18
- package/dist/drawer/base.js +1 -1
- package/dist/drawer/index.js +1 -1
- package/dist/graphicLayer/BaseLayer.d.ts +1 -1
- package/dist/graphicLayer/BaseLayer.js +1 -1
- package/dist/graphicLayer/BaseSource.d.ts +1 -1
- package/dist/graphicLayer/BaseSource.js +4 -6
- package/dist/graphicLayer/GraphicLayerCollection.d.ts +3 -2
- package/dist/graphicLayer/GraphicLayerCollection.js +33 -40
- package/dist/graphicLayer/PolylinePrimitiveInstance.js +2 -6
- package/dist/index.d.ts +0 -1
- package/dist/index.js +1 -3
- package/dist/map/Map.d.ts +1 -1
- package/dist/map/Map.js +12 -6
- package/package.json +1 -1
- package/dist/cameraControl/ModelRoamRunTime.d.ts +0 -32
- package/dist/cameraControl/ModelRoamRunTime.js +0 -244
|
@@ -4,23 +4,31 @@ export default class ModelRoamHistory {
|
|
|
4
4
|
modelLayer: any;
|
|
5
5
|
modelEntity: any;
|
|
6
6
|
positionProperty: any;
|
|
7
|
+
private follow;
|
|
7
8
|
status: string;
|
|
8
9
|
private _map;
|
|
9
10
|
private readonly _eventRunning;
|
|
10
11
|
private readonly _eventComplete;
|
|
11
12
|
private readonly _eventCancel;
|
|
13
|
+
private _eventPreUpdate;
|
|
12
14
|
private _positions;
|
|
13
|
-
private
|
|
15
|
+
private _currentPosition;
|
|
16
|
+
private _heading;
|
|
14
17
|
private _listenRunning;
|
|
18
|
+
private firstCameraSettings;
|
|
19
|
+
private thirdPersonSettings;
|
|
15
20
|
constructor(map: any, positions: any, options?: any);
|
|
16
21
|
private _init;
|
|
22
|
+
private _getHeading;
|
|
17
23
|
start(): void;
|
|
18
24
|
pause(): void;
|
|
19
25
|
proceed(): void;
|
|
20
26
|
stop(): void;
|
|
21
|
-
setFollowFirst(
|
|
22
|
-
setFollowThird(): void;
|
|
27
|
+
setFollowFirst(options: any): void;
|
|
28
|
+
setFollowThird(options: any): void;
|
|
23
29
|
cancelFollow(): void;
|
|
30
|
+
private updateFirstPersonView;
|
|
31
|
+
private updateThirdPersonView;
|
|
24
32
|
on(type: any, event: any): any;
|
|
25
33
|
updatePolyline(style: any): void;
|
|
26
34
|
updateModel(style: any): void;
|
|
@@ -8,7 +8,7 @@ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key i
|
|
|
8
8
|
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
9
9
|
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
10
10
|
import * as Cesium from 'deeptwins-cesium';
|
|
11
|
-
import
|
|
11
|
+
import * as constant from "../constant";
|
|
12
12
|
import ModelEntity from "../graphicLayer/ModelEntity";
|
|
13
13
|
import { lineClampToGroundSplit } from "../tool/common";
|
|
14
14
|
import { cartesian3ToLngLatAlt, lngLatAltToCartesian3 } from "../tool/utils";
|
|
@@ -20,14 +20,29 @@ var ModelRoamHistory = /*#__PURE__*/function () {
|
|
|
20
20
|
_defineProperty(this, "modelLayer", void 0);
|
|
21
21
|
_defineProperty(this, "modelEntity", void 0);
|
|
22
22
|
_defineProperty(this, "positionProperty", void 0);
|
|
23
|
+
// 视角
|
|
24
|
+
_defineProperty(this, "follow", null);
|
|
23
25
|
_defineProperty(this, "status", 'stop');
|
|
24
26
|
_defineProperty(this, "_map", void 0);
|
|
25
27
|
_defineProperty(this, "_eventRunning", void 0);
|
|
26
28
|
_defineProperty(this, "_eventComplete", void 0);
|
|
27
29
|
_defineProperty(this, "_eventCancel", void 0);
|
|
30
|
+
// 帧率更新的事件
|
|
31
|
+
_defineProperty(this, "_eventPreUpdate", void 0);
|
|
28
32
|
_defineProperty(this, "_positions", []);
|
|
29
|
-
_defineProperty(this, "
|
|
33
|
+
_defineProperty(this, "_currentPosition", void 0);
|
|
34
|
+
_defineProperty(this, "_heading", void 0);
|
|
30
35
|
_defineProperty(this, "_listenRunning", void 0);
|
|
36
|
+
// 第一人称视角设置
|
|
37
|
+
_defineProperty(this, "firstCameraSettings", {
|
|
38
|
+
distance: 0,
|
|
39
|
+
pitch: -45
|
|
40
|
+
});
|
|
41
|
+
// 第三人称视角设置
|
|
42
|
+
_defineProperty(this, "thirdPersonSettings", {
|
|
43
|
+
distance: 500,
|
|
44
|
+
pitch: -45
|
|
45
|
+
});
|
|
31
46
|
var _ref = options || {},
|
|
32
47
|
complete = _ref.complete,
|
|
33
48
|
cancel = _ref.cancel,
|
|
@@ -99,9 +114,19 @@ var ModelRoamHistory = /*#__PURE__*/function () {
|
|
|
99
114
|
} else {
|
|
100
115
|
// 监听运行状态
|
|
101
116
|
if (_this._eventRunning && _this._map.clock.shouldAnimate) {
|
|
102
|
-
|
|
103
|
-
var
|
|
117
|
+
// 获取当前时间
|
|
118
|
+
var currentTime = _this._map.clock.currentTime;
|
|
119
|
+
// 获取前一帧时间
|
|
120
|
+
var beforeTime = Cesium.JulianDate.addSeconds(currentTime, -0.1, new Cesium.JulianDate());
|
|
121
|
+
// 获取插值后的当前位置
|
|
122
|
+
var currentPosition = _this.positionProperty.getValue(currentTime);
|
|
123
|
+
// 获取前一帧的位置
|
|
124
|
+
var beforePosition = _this.positionProperty.getValue(beforeTime);
|
|
104
125
|
if (currentPosition) {
|
|
126
|
+
_this._currentPosition = currentPosition;
|
|
127
|
+
if (_this.modelLayer && _this._positions && beforePosition) {
|
|
128
|
+
_this._getHeading(currentPosition, beforePosition);
|
|
129
|
+
}
|
|
105
130
|
_this._eventRunning(_objectSpread(_objectSpread({}, cartesian3ToLngLatAlt(currentPosition)), {}, {
|
|
106
131
|
time: Cesium.JulianDate.toDate(currentTime)
|
|
107
132
|
}));
|
|
@@ -109,9 +134,11 @@ var ModelRoamHistory = /*#__PURE__*/function () {
|
|
|
109
134
|
}
|
|
110
135
|
}
|
|
111
136
|
};
|
|
112
|
-
|
|
137
|
+
// 监听帧率
|
|
138
|
+
this._eventPreUpdate = this._map.on(constant.SCENE_EVENT_TYPE.PRE_UPDATE, this._listenRunning);
|
|
113
139
|
this.positionProperty = new Cesium.SampledPositionProperty();
|
|
114
140
|
if (clampToGround) {
|
|
141
|
+
// 贴地计算
|
|
115
142
|
model.heightReference = Cesium.HeightReference.CLAMP_TO_GROUND;
|
|
116
143
|
var _loop = function _loop() {
|
|
117
144
|
var position1 = _this._positions[i];
|
|
@@ -159,12 +186,42 @@ var ModelRoamHistory = /*#__PURE__*/function () {
|
|
|
159
186
|
position: this.positionProperty,
|
|
160
187
|
model: ModelEntity.handleOptions(model)
|
|
161
188
|
});
|
|
162
|
-
this.modelLayer = this._map.
|
|
189
|
+
this.modelLayer = this._map.addCustomSourceToGraphicLayer(this.modelEntity.position, {
|
|
163
190
|
type: 'model',
|
|
164
191
|
entity: this.modelEntity
|
|
165
192
|
});
|
|
166
193
|
}
|
|
167
194
|
|
|
195
|
+
// 获取方向角
|
|
196
|
+
}, {
|
|
197
|
+
key: "_getHeading",
|
|
198
|
+
value: function _getHeading(currentPosition, beforePosition) {
|
|
199
|
+
// 当前位置与之前位置的 Cartographic 经纬度
|
|
200
|
+
var cartoNow = Cesium.Cartographic.fromCartesian(currentPosition);
|
|
201
|
+
var cartoBefore = Cesium.Cartographic.fromCartesian(beforePosition);
|
|
202
|
+
|
|
203
|
+
// 把它们转为 Cartesian3
|
|
204
|
+
var origin = Cesium.Cartesian3.fromRadians(cartoBefore.longitude, cartoBefore.latitude, cartoBefore.height);
|
|
205
|
+
var target = Cesium.Cartesian3.fromRadians(cartoNow.longitude, cartoNow.latitude, cartoNow.height);
|
|
206
|
+
|
|
207
|
+
// 构造 ENU 变换矩阵(以 before 位置为原点)
|
|
208
|
+
var enuTransform = Cesium.Transforms.eastNorthUpToFixedFrame(origin);
|
|
209
|
+
var inverse = Cesium.Matrix4.inverse(enuTransform, new Cesium.Matrix4());
|
|
210
|
+
|
|
211
|
+
// 计算从 before → now 的方向向量
|
|
212
|
+
var directionWorld = Cesium.Cartesian3.subtract(target, origin, new Cesium.Cartesian3());
|
|
213
|
+
var directionENU = Cesium.Matrix4.multiplyByPointAsVector(inverse, directionWorld, new Cesium.Cartesian3());
|
|
214
|
+
|
|
215
|
+
// 在 ENU 坐标中计算 heading
|
|
216
|
+
var heading = Cesium.Math.zeroToTwoPi(Math.atan2(directionENU.x, directionENU.y)); // 东为 x,北为 y
|
|
217
|
+
this._heading = heading;
|
|
218
|
+
if (this.follow === 'first') {
|
|
219
|
+
this.updateFirstPersonView(currentPosition, heading);
|
|
220
|
+
} else if (this.follow === 'third') {
|
|
221
|
+
this.updateThirdPersonView(currentPosition, heading);
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
|
|
168
225
|
// 开始播放场景
|
|
169
226
|
}, {
|
|
170
227
|
key: "start",
|
|
@@ -207,30 +264,21 @@ var ModelRoamHistory = /*#__PURE__*/function () {
|
|
|
207
264
|
// 第一人称视角跟随
|
|
208
265
|
}, {
|
|
209
266
|
key: "setFollowFirst",
|
|
210
|
-
value: function setFollowFirst() {
|
|
211
|
-
var _this2 = this;
|
|
212
|
-
var distance = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1000;
|
|
267
|
+
value: function setFollowFirst(options) {
|
|
213
268
|
if (this.status === 'destroy') return;
|
|
214
|
-
this.
|
|
215
|
-
this.
|
|
216
|
-
|
|
217
|
-
if (position) {
|
|
218
|
-
// 获取模型的姿态
|
|
219
|
-
var orientation = _this2.modelEntity.orientation.getValue(_this2._map.clock.currentTime);
|
|
220
|
-
var transform = Cesium.Transforms.eastNorthUpToFixedFrame(position);
|
|
221
|
-
transform = Cesium.Matrix4.fromRotationTranslation(Cesium.Matrix3.fromQuaternion(orientation), position);
|
|
222
|
-
_this2._map.camera.lookAtTransform(transform, new Cesium.Cartesian3(-20, 0, distance));
|
|
223
|
-
}
|
|
224
|
-
});
|
|
269
|
+
this.firstCameraSettings = _objectSpread(_objectSpread({}, this.firstCameraSettings), options);
|
|
270
|
+
this.follow = 'first';
|
|
271
|
+
this.updateFirstPersonView(this._currentPosition, this._heading);
|
|
225
272
|
}
|
|
226
273
|
|
|
227
274
|
// 第三人称视角跟随
|
|
228
275
|
}, {
|
|
229
276
|
key: "setFollowThird",
|
|
230
|
-
value: function setFollowThird() {
|
|
277
|
+
value: function setFollowThird(options) {
|
|
231
278
|
if (this.status === 'destroy') return;
|
|
232
|
-
this.
|
|
233
|
-
this.
|
|
279
|
+
this.thirdPersonSettings = _objectSpread(_objectSpread({}, this.thirdPersonSettings), options);
|
|
280
|
+
this.follow = 'third';
|
|
281
|
+
this.updateThirdPersonView(this._currentPosition, this._heading);
|
|
234
282
|
}
|
|
235
283
|
|
|
236
284
|
// 取消跟随
|
|
@@ -238,9 +286,35 @@ var ModelRoamHistory = /*#__PURE__*/function () {
|
|
|
238
286
|
key: "cancelFollow",
|
|
239
287
|
value: function cancelFollow() {
|
|
240
288
|
if (this.status === 'destroy') return;
|
|
241
|
-
this.
|
|
242
|
-
|
|
243
|
-
|
|
289
|
+
this.follow = null;
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
// 更新第一人称视角
|
|
293
|
+
}, {
|
|
294
|
+
key: "updateFirstPersonView",
|
|
295
|
+
value: function updateFirstPersonView(position, heading) {
|
|
296
|
+
if (!position || !heading) {
|
|
297
|
+
return;
|
|
298
|
+
}
|
|
299
|
+
// 设置相机位置和朝向
|
|
300
|
+
this._map.camera.setView({
|
|
301
|
+
destination: position,
|
|
302
|
+
orientation: {
|
|
303
|
+
heading: heading,
|
|
304
|
+
pitch: Cesium.Math.toRadians(this.firstCameraSettings.pitch),
|
|
305
|
+
roll: 0.0
|
|
306
|
+
}
|
|
307
|
+
});
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
// 更新第三人称视角
|
|
311
|
+
}, {
|
|
312
|
+
key: "updateThirdPersonView",
|
|
313
|
+
value: function updateThirdPersonView(position, heading) {
|
|
314
|
+
if (!position || !heading) {
|
|
315
|
+
return;
|
|
316
|
+
}
|
|
317
|
+
this._map.camera.lookAt(position, new Cesium.HeadingPitchRange(heading, Cesium.Math.toRadians(this.thirdPersonSettings.pitch), this.thirdPersonSettings.distance));
|
|
244
318
|
}
|
|
245
319
|
|
|
246
320
|
// 监听
|
|
@@ -271,7 +345,7 @@ var ModelRoamHistory = /*#__PURE__*/function () {
|
|
|
271
345
|
this.status = 'destroy';
|
|
272
346
|
this._map.clock.shouldAnimate = false;
|
|
273
347
|
this._map.clock.currentTime = Cesium.JulianDate.fromDate(new Date());
|
|
274
|
-
this.
|
|
348
|
+
this._eventPreUpdate.off();
|
|
275
349
|
this._listenRunning = null;
|
|
276
350
|
this._map.removeLayer('_modelHistoryRoam');
|
|
277
351
|
this._map.removeSource('_modelHistoryRoam');
|
|
@@ -8,30 +8,28 @@ interface Position {
|
|
|
8
8
|
alt: number;
|
|
9
9
|
}
|
|
10
10
|
export default class ModelRoamRealTime {
|
|
11
|
-
_map: any;
|
|
11
|
+
readonly _map: any;
|
|
12
|
+
modelOptions: any;
|
|
13
|
+
polylineOptions: any;
|
|
14
|
+
private follow;
|
|
15
|
+
flyTo: boolean;
|
|
16
|
+
private readonly _onPositionUpdate;
|
|
12
17
|
modelLayer: any;
|
|
13
18
|
polylineLayer: any;
|
|
14
|
-
private modelOptions;
|
|
15
|
-
private polylineOptions;
|
|
16
|
-
private follow;
|
|
17
|
-
private flyTo;
|
|
18
|
-
private onPositionUpdate;
|
|
19
|
-
private linePath;
|
|
20
|
-
private showPath;
|
|
21
19
|
private positions;
|
|
20
|
+
private positionsLineC3;
|
|
21
|
+
private positionInterC3;
|
|
22
|
+
private _eventPreUpdate;
|
|
22
23
|
private modelMatrix;
|
|
23
24
|
private hpRoll;
|
|
24
|
-
private
|
|
25
|
-
|
|
25
|
+
private _time;
|
|
26
|
+
status: 'stop' | 'running' | 'destroy';
|
|
26
27
|
private currentPathIndex;
|
|
27
28
|
private maxPathIndex;
|
|
28
|
-
private isMovingToTarget;
|
|
29
29
|
private targetHeading;
|
|
30
30
|
private currentHeading;
|
|
31
31
|
private rotationSpeed;
|
|
32
|
-
private
|
|
33
|
-
private keyStep;
|
|
34
|
-
private cameraSettings;
|
|
32
|
+
private firstCameraSettings;
|
|
35
33
|
private thirdPersonSettings;
|
|
36
34
|
constructor(map: Viewer, options: any);
|
|
37
35
|
/**
|
|
@@ -39,38 +37,25 @@ export default class ModelRoamRealTime {
|
|
|
39
37
|
* @param newPosition 新位置点
|
|
40
38
|
* @throws 如果新位置与上一个位置完全相同
|
|
41
39
|
*/
|
|
42
|
-
updatePosition(newPosition: Position):
|
|
40
|
+
updatePosition(newPosition: Position): void;
|
|
43
41
|
/**
|
|
44
42
|
* 计算两点之间的路径点
|
|
45
43
|
* 使用插值算法生成平滑的路径
|
|
46
44
|
* @param startP 起始点
|
|
47
45
|
* @param endP 终点
|
|
46
|
+
* @param flightTime 飞行时间
|
|
48
47
|
* @returns 插值后的路径点数组
|
|
49
48
|
*/
|
|
50
|
-
private
|
|
49
|
+
private _getInterPosition;
|
|
51
50
|
/**
|
|
52
51
|
* 初始化模型
|
|
53
52
|
* 加载模型
|
|
54
53
|
* @param initialPosition 初始位置
|
|
55
54
|
*/
|
|
56
55
|
private initModel;
|
|
57
|
-
/**
|
|
58
|
-
* 初始化线路
|
|
59
|
-
*/
|
|
60
|
-
private initPolyline;
|
|
61
|
-
/**
|
|
62
|
-
* 开始漫游
|
|
63
|
-
*/
|
|
64
|
-
startRun(): void;
|
|
65
|
-
/**
|
|
66
|
-
* 结束漫游
|
|
67
|
-
*/
|
|
68
|
-
stopRun(): void;
|
|
69
56
|
/**
|
|
70
57
|
* 渲染回调函数
|
|
71
58
|
* 更新模型位置、朝向和路径线
|
|
72
|
-
* @param scene Cesium场景
|
|
73
|
-
* @param time 当前时间
|
|
74
59
|
*/
|
|
75
60
|
private updateModel;
|
|
76
61
|
/**
|
|
@@ -99,30 +84,21 @@ export default class ModelRoamRealTime {
|
|
|
99
84
|
*/
|
|
100
85
|
private updateThirdPersonView;
|
|
101
86
|
/**
|
|
102
|
-
*
|
|
103
|
-
* 在第一人称和第三人称之间切换
|
|
104
|
-
*/
|
|
105
|
-
changeFollow(type: any): void;
|
|
106
|
-
/**
|
|
107
|
-
* 飞行定位到模型
|
|
87
|
+
* 设置第一人称视角
|
|
108
88
|
*/
|
|
109
|
-
|
|
89
|
+
setFollowFirst(options: any): void;
|
|
110
90
|
/**
|
|
111
|
-
*
|
|
91
|
+
* 设置第一人称视角
|
|
112
92
|
*/
|
|
113
|
-
|
|
93
|
+
setFollowThird(options: any): void;
|
|
114
94
|
/**
|
|
115
|
-
*
|
|
95
|
+
* 取消视角跟随
|
|
116
96
|
*/
|
|
117
|
-
|
|
97
|
+
cancelFollow(): void;
|
|
118
98
|
/**
|
|
119
|
-
*
|
|
120
|
-
*/
|
|
121
|
-
private handleKeyUp;
|
|
122
|
-
/**
|
|
123
|
-
* 根据键盘状态更新视角
|
|
99
|
+
* 飞行定位到模型
|
|
124
100
|
*/
|
|
125
|
-
private
|
|
101
|
+
private _flyToModel;
|
|
126
102
|
/**
|
|
127
103
|
* 监听
|
|
128
104
|
*/
|