deeptwins-engine-3d 0.0.48 → 0.0.49
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/ModelRoamRealTime.d.ts +7 -2
- package/dist/cameraControl/ModelRoamRealTime.js +64 -26
- package/dist/index.js +1 -1
- package/dist/map/Event.js +1 -1
- package/dist/material/CircleWaveMaterialProperty.js +1 -1
- package/dist/material/DynamicWallMaterialProperty.js +1 -1
- package/package.json +1 -1
|
@@ -17,13 +17,18 @@ export default class ModelRoamRealTime {
|
|
|
17
17
|
private readonly _onPositionUpdate;
|
|
18
18
|
modelLayer: any;
|
|
19
19
|
polylineLayer: any;
|
|
20
|
+
private _lastFrameTime;
|
|
21
|
+
private _stepAccumulator;
|
|
22
|
+
private _frameCount;
|
|
23
|
+
private _fps;
|
|
24
|
+
private _time;
|
|
20
25
|
private receivedPositions;
|
|
21
26
|
private completedSegments;
|
|
22
27
|
private currentSegment;
|
|
23
28
|
private futureSegments;
|
|
24
29
|
private currentPointIndex;
|
|
25
30
|
private segmentCounter;
|
|
26
|
-
private
|
|
31
|
+
private _eventPostUpdate;
|
|
27
32
|
private modelMatrix;
|
|
28
33
|
private hpRoll;
|
|
29
34
|
status: 'stop' | 'running' | 'destroy';
|
|
@@ -80,7 +85,7 @@ export default class ModelRoamRealTime {
|
|
|
80
85
|
private initTrailLine;
|
|
81
86
|
/**
|
|
82
87
|
* 获取轨迹线位置点
|
|
83
|
-
*
|
|
88
|
+
* 返回:已完成路径段的起始点和结束点 + 当前路径段已飞行的插值点
|
|
84
89
|
*/
|
|
85
90
|
private getTrailLinePositions;
|
|
86
91
|
/**
|
|
@@ -48,7 +48,15 @@ var ModelRoamRealTime = /*#__PURE__*/function () {
|
|
|
48
48
|
_defineProperty(this, "modelLayer", void 0);
|
|
49
49
|
// 轨迹layer
|
|
50
50
|
_defineProperty(this, "polylineLayer", void 0);
|
|
51
|
+
// 上一帧时间
|
|
52
|
+
_defineProperty(this, "_lastFrameTime", performance.now());
|
|
53
|
+
// 累加器
|
|
54
|
+
_defineProperty(this, "_stepAccumulator", 0);
|
|
55
|
+
_defineProperty(this, "_frameCount", 0);
|
|
56
|
+
_defineProperty(this, "_fps", 'N/A');
|
|
51
57
|
// 重新设计的数据结构
|
|
58
|
+
// 上个点位的时间
|
|
59
|
+
_defineProperty(this, "_time", performance.now());
|
|
52
60
|
// 接收到的原始位置数据
|
|
53
61
|
_defineProperty(this, "receivedPositions", []);
|
|
54
62
|
// 已完成飞行的路径段
|
|
@@ -62,7 +70,7 @@ var ModelRoamRealTime = /*#__PURE__*/function () {
|
|
|
62
70
|
// 路径段计数器
|
|
63
71
|
_defineProperty(this, "segmentCounter", 0);
|
|
64
72
|
// 帧率更新的事件
|
|
65
|
-
_defineProperty(this, "
|
|
73
|
+
_defineProperty(this, "_eventPostUpdate", void 0);
|
|
66
74
|
// 模型参数
|
|
67
75
|
// 模型变换矩阵
|
|
68
76
|
_defineProperty(this, "modelMatrix", new Cesium.Matrix4());
|
|
@@ -92,6 +100,13 @@ var ModelRoamRealTime = /*#__PURE__*/function () {
|
|
|
92
100
|
* 更新模型位置、朝向和路径线
|
|
93
101
|
*/
|
|
94
102
|
_defineProperty(this, "updateModel", function () {
|
|
103
|
+
var currentTime = performance.now();
|
|
104
|
+
_this._frameCount++;
|
|
105
|
+
if (currentTime - _this._lastFrameTime > 1000) {
|
|
106
|
+
_this._fps = _this._frameCount;
|
|
107
|
+
_this._frameCount = 0;
|
|
108
|
+
_this._lastFrameTime = currentTime;
|
|
109
|
+
}
|
|
95
110
|
if (!_this.currentSegment || _this.status !== 'running') {
|
|
96
111
|
return;
|
|
97
112
|
}
|
|
@@ -125,7 +140,7 @@ var ModelRoamRealTime = /*#__PURE__*/function () {
|
|
|
125
140
|
if (_this._onPositionUpdate) {
|
|
126
141
|
var cartographic = Cesium.Cartographic.fromCartesian(currentPos);
|
|
127
142
|
_this._onPositionUpdate({
|
|
128
|
-
|
|
143
|
+
lng: Cesium.Math.toDegrees(cartographic.longitude),
|
|
129
144
|
lat: Cesium.Math.toDegrees(cartographic.latitude),
|
|
130
145
|
height: cartographic.height
|
|
131
146
|
});
|
|
@@ -135,6 +150,19 @@ var ModelRoamRealTime = /*#__PURE__*/function () {
|
|
|
135
150
|
}
|
|
136
151
|
}
|
|
137
152
|
_this.currentPointIndex++;
|
|
153
|
+
if (_this._fps === 'N/A') {
|
|
154
|
+
_this.currentPointIndex++;
|
|
155
|
+
} else {
|
|
156
|
+
// 每帧应飞的“点数”(允许小数)
|
|
157
|
+
var exactStep = _this._map.targetFrameRate / _this._fps;
|
|
158
|
+
// 累加步长
|
|
159
|
+
_this._stepAccumulator += exactStep;
|
|
160
|
+
// 取整:当前帧应飞的“完整点数”
|
|
161
|
+
var step = Math.max(1, Math.floor(_this._stepAccumulator));
|
|
162
|
+
// 剩余留给下帧
|
|
163
|
+
_this._stepAccumulator -= step;
|
|
164
|
+
_this.currentPointIndex = _this.currentPointIndex + step;
|
|
165
|
+
}
|
|
138
166
|
});
|
|
139
167
|
if (!map) {
|
|
140
168
|
throw new Error('undefined map');
|
|
@@ -160,7 +188,6 @@ var ModelRoamRealTime = /*#__PURE__*/function () {
|
|
|
160
188
|
_createClass(ModelRoamRealTime, [{
|
|
161
189
|
key: "updatePosition",
|
|
162
190
|
value: function updatePosition(newPosition) {
|
|
163
|
-
console.log(newPosition);
|
|
164
191
|
if (!newPosition) return;
|
|
165
192
|
if (this.status === 'destroy') return;
|
|
166
193
|
|
|
@@ -213,7 +240,9 @@ var ModelRoamRealTime = /*#__PURE__*/function () {
|
|
|
213
240
|
var endC3 = Cesium.Cartesian3.fromDegrees(endPos.lng, endPos.lat, endPos.alt);
|
|
214
241
|
|
|
215
242
|
// 计算飞行时间
|
|
216
|
-
var
|
|
243
|
+
var newTime = performance.now();
|
|
244
|
+
var flightTime = (newTime - this._time) / 1000;
|
|
245
|
+
this._time = newTime;
|
|
217
246
|
|
|
218
247
|
// 计算插值点
|
|
219
248
|
var interpolatedPoints = this._getInterPosition(startC3, endC3, flightTime);
|
|
@@ -244,7 +273,7 @@ var ModelRoamRealTime = /*#__PURE__*/function () {
|
|
|
244
273
|
if (this.status === 'running') return;
|
|
245
274
|
this.status = 'running';
|
|
246
275
|
// 监听帧率更新
|
|
247
|
-
this.
|
|
276
|
+
this._eventPostUpdate = this._map.on(constant.SCENE_EVENT_TYPE.POST_UPDATE, this.updateModel);
|
|
248
277
|
}
|
|
249
278
|
|
|
250
279
|
/**
|
|
@@ -279,11 +308,8 @@ var ModelRoamRealTime = /*#__PURE__*/function () {
|
|
|
279
308
|
return arr;
|
|
280
309
|
}
|
|
281
310
|
|
|
282
|
-
//
|
|
283
|
-
var
|
|
284
|
-
|
|
285
|
-
// 计算总的插值点数
|
|
286
|
-
var numberOfPoints = Math.max(10, Math.floor(flightTime * updateRate));
|
|
311
|
+
// 计算总的插值点数 用最大帧率*时间计算点位
|
|
312
|
+
var numberOfPoints = Math.max(10, Math.floor(flightTime * this._map.targetFrameRate));
|
|
287
313
|
|
|
288
314
|
// 计算时间步长
|
|
289
315
|
var timeStep = 1.0 / (numberOfPoints - 1);
|
|
@@ -398,13 +424,13 @@ var ModelRoamRealTime = /*#__PURE__*/function () {
|
|
|
398
424
|
var _this3 = this;
|
|
399
425
|
// 创建轨迹线Entity,使用callback动态更新位置
|
|
400
426
|
this.polylineLayer = this._map.entities.add({
|
|
401
|
-
id:
|
|
427
|
+
id: uuidv4(),
|
|
402
428
|
polyline: {
|
|
403
429
|
positions: new Cesium.CallbackProperty(function () {
|
|
404
430
|
return _this3.getTrailLinePositions();
|
|
405
431
|
}, false),
|
|
406
|
-
width: this.polylineOptions.width ||
|
|
407
|
-
material: colorString(this.polylineOptions.color ||
|
|
432
|
+
width: this.polylineOptions.width || 2,
|
|
433
|
+
material: colorString(this.polylineOptions.color || Cesium.Color.YELLOW),
|
|
408
434
|
clampToGround: false
|
|
409
435
|
}
|
|
410
436
|
});
|
|
@@ -412,29 +438,41 @@ var ModelRoamRealTime = /*#__PURE__*/function () {
|
|
|
412
438
|
|
|
413
439
|
/**
|
|
414
440
|
* 获取轨迹线位置点
|
|
415
|
-
*
|
|
441
|
+
* 返回:已完成路径段的起始点和结束点 + 当前路径段已飞行的插值点
|
|
416
442
|
*/
|
|
417
443
|
}, {
|
|
418
444
|
key: "getTrailLinePositions",
|
|
419
445
|
value: function getTrailLinePositions() {
|
|
420
446
|
var positions = [];
|
|
421
447
|
|
|
422
|
-
//
|
|
423
|
-
if (!Array.isArray(this.receivedPositions) || this.receivedPositions.length <
|
|
448
|
+
// 确保有基础数据
|
|
449
|
+
if (!Array.isArray(this.receivedPositions) || this.receivedPositions.length < 1) {
|
|
424
450
|
return positions;
|
|
425
451
|
}
|
|
426
452
|
|
|
427
|
-
//
|
|
428
|
-
this.
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
453
|
+
// 添加已完成路径段的起始点和结束点
|
|
454
|
+
if (Array.isArray(this.completedSegments)) {
|
|
455
|
+
this.completedSegments.forEach(function (segment) {
|
|
456
|
+
if (segment.startPos && segment.endPos) {
|
|
457
|
+
// 添加起始点(如果这是第一个路径段或者与上一个路径段不重复)
|
|
458
|
+
if (positions.length === 0) {
|
|
459
|
+
positions.push(Cesium.Cartesian3.fromDegrees(segment.startPos.lng, segment.startPos.lat, segment.startPos.alt));
|
|
460
|
+
}
|
|
461
|
+
// 添加结束点
|
|
462
|
+
positions.push(Cesium.Cartesian3.fromDegrees(segment.endPos.lng, segment.endPos.lat, segment.endPos.alt));
|
|
463
|
+
}
|
|
464
|
+
});
|
|
465
|
+
}
|
|
433
466
|
|
|
434
467
|
// 如果当前有正在飞行的路径段,添加已飞行过的插值点
|
|
435
|
-
if (this.currentSegment && Array.isArray(this.currentSegment.interpolatedPoints) && this.currentPointIndex
|
|
436
|
-
//
|
|
437
|
-
|
|
468
|
+
if (this.currentSegment && Array.isArray(this.currentSegment.interpolatedPoints) && this.currentPointIndex >= 0) {
|
|
469
|
+
// 如果还没有添加过任何点,先添加当前路径段的起始点
|
|
470
|
+
if (positions.length === 0 && this.currentSegment.startPos) {
|
|
471
|
+
positions.push(Cesium.Cartesian3.fromDegrees(this.currentSegment.startPos.lng, this.currentSegment.startPos.lat, this.currentSegment.startPos.alt));
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
// 添加当前路径段中已经飞行过的插值点
|
|
475
|
+
for (var i = 0; i <= this.currentPointIndex && i < this.currentSegment.interpolatedPoints.length; i++) {
|
|
438
476
|
positions.push(this.currentSegment.interpolatedPoints[i]);
|
|
439
477
|
}
|
|
440
478
|
}
|
|
@@ -690,8 +728,8 @@ var ModelRoamRealTime = /*#__PURE__*/function () {
|
|
|
690
728
|
value: function destroy() {
|
|
691
729
|
if (this.status === 'destroy') return;
|
|
692
730
|
this.status = 'destroy';
|
|
731
|
+
this._eventPostUpdate && this._eventPostUpdate.off();
|
|
693
732
|
if (this.modelLayer) {
|
|
694
|
-
this._eventPreUpdate.off();
|
|
695
733
|
this._map.scene.primitives.remove(this.modelLayer);
|
|
696
734
|
this.modelLayer = null;
|
|
697
735
|
}
|
package/dist/index.js
CHANGED
|
@@ -45,7 +45,7 @@ window.Cesium = Cesium;
|
|
|
45
45
|
var DeepTwinsEngine3D = /*#__PURE__*/_createClass(function DeepTwinsEngine3D() {
|
|
46
46
|
_classCallCheck(this, DeepTwinsEngine3D);
|
|
47
47
|
});
|
|
48
|
-
_defineProperty(DeepTwinsEngine3D, "Version", '0.0.
|
|
48
|
+
_defineProperty(DeepTwinsEngine3D, "Version", '0.0.49');
|
|
49
49
|
_defineProperty(DeepTwinsEngine3D, "Map", Map);
|
|
50
50
|
_defineProperty(DeepTwinsEngine3D, "GroundSkyBox", GroundSkyBox);
|
|
51
51
|
_defineProperty(DeepTwinsEngine3D, "RasterLayer", RasterLayer);
|
package/dist/map/Event.js
CHANGED
|
@@ -252,7 +252,7 @@ var Event = /*#__PURE__*/function () {
|
|
|
252
252
|
var pickedObject = _this5._getPickedObject(position);
|
|
253
253
|
if (pickedObject) {
|
|
254
254
|
var _modelRoam$modelLayer;
|
|
255
|
-
var targetPolyline =
|
|
255
|
+
var targetPolyline = modelRoam.polylineLayer.id === pickedObject.id.id;
|
|
256
256
|
var targetModel = (modelRoam === null || modelRoam === void 0 || (_modelRoam$modelLayer = modelRoam.modelLayer) === null || _modelRoam$modelLayer === void 0 ? void 0 : _modelRoam$modelLayer.id) === (pickedObject === null || pickedObject === void 0 ? void 0 : pickedObject.id);
|
|
257
257
|
if (targetPolyline || targetModel) {
|
|
258
258
|
var result = {
|
|
@@ -24,7 +24,7 @@ import { DEFAULT_CIRCLE_WAVE_MATERIAL_STYLE } from "../constant";
|
|
|
24
24
|
import * as utils from "../tool/utils";
|
|
25
25
|
import BaseMaterialProperty from "./BaseMaterialProperty";
|
|
26
26
|
/* babel-plugin-inline-import './shader/CircleWaveShader.glsl' */
|
|
27
|
-
var CircleWaveShader = "czm_material czm_getMaterial(czm_materialInput materialInput) {\n czm_material material = czm_getDefaultMaterial(materialInput);\n material.diffuse = 1.5 * color.rgb;\n
|
|
27
|
+
var CircleWaveShader = "czm_material czm_getMaterial(czm_materialInput materialInput) {\n czm_material material = czm_getDefaultMaterial(materialInput);\n material.diffuse = 1.5 * color.rgb;\n vec2 st = materialInput.st;\n vec3 str = materialInput.str;\n float dis = distance(st, vec2(0.5, 0.5));\n float per = fract(time);\n if (abs(str.z) > 0.001) {\n discard;\n }\n if (dis > 0.5) {\n discard;\n } else {\n float perDis = 0.5 / count;\n float disNum;\n float bl = .0;\n for (int i = 0; i <= 9; i++) {\n if (float(i) <= count) {\n disNum = perDis * float(i) - dis + per / count;\n if (disNum > 0.0) {\n if (disNum < perDis) {\n bl = 1.0 - disNum / perDis;\n } else if (disNum - perDis < perDis) {\n bl = 1.0 - abs(1.0 - disNum / perDis);\n }\n material.alpha = pow(bl, gradient);\n }\n }\n }\n }\n return material;\n}\n"; // 水波纹材质
|
|
28
28
|
var CircleWaveMaterialProperty = /*#__PURE__*/function (_BaseMaterialProperty) {
|
|
29
29
|
_inherits(CircleWaveMaterialProperty, _BaseMaterialProperty);
|
|
30
30
|
var _super = _createSuper(CircleWaveMaterialProperty);
|
|
@@ -24,7 +24,7 @@ import { DEFAULT_DYNAMIC_WALL_MATERIAL_STYLE } from "../constant";
|
|
|
24
24
|
import * as utils from "../tool/utils";
|
|
25
25
|
import BaseMaterialProperty from "./BaseMaterialProperty";
|
|
26
26
|
/* babel-plugin-inline-import './shader/DynamicWallShader.glsl' */
|
|
27
|
-
var DynamicWallShader = "czm_material czm_getMaterial(czm_materialInput materialInput)\n{\n czm_material material = czm_getDefaultMaterial(materialInput);\n vec2 st = materialInput.st;\n float vertical = 1.0;\n float directionAdd = 1.0;\n
|
|
27
|
+
var DynamicWallShader = "czm_material czm_getMaterial(czm_materialInput materialInput)\n{\n czm_material material = czm_getDefaultMaterial(materialInput);\n vec2 st = materialInput.st;\n float vertical = 1.0;\n float directionAdd = 1.0;\n vec2 uv = vec2(0, 0);\n // \u5224\u65AD\u6392\u5217\u65B9\u5411\n if (freely == vertical) {\n // \u5224\u65AD\u8FD0\u52A8\u65B9\u5411\n if (direction == directionAdd) {\n uv = vec2(fract(st.s), fract(count * st.t + time));\n } else {\n uv = vec2(fract(st.s), fract(count * st.t - time));\n }\n } else {\n // \u5224\u65AD\u8FD0\u52A8\u65B9\u5411\n if (direction == directionAdd) {\n uv = vec2(fract(count * st.s + time), fract(st.t));\n } else {\n uv = vec2(fract(count * st.s - time), fract(st.t));\n }\n }\n vec4 colorImage = texture(image, uv);\n vec3 mixedColor = mix(colorImage.rgb, color.rgb, mixRatio);\n vec4 fragColor;\n fragColor.rgb = mixedColor;\n fragColor = czm_gammaCorrect(fragColor);\n\n material.diffuse = mixedColor;\n material.alpha = colorImage.a * color.a; // \u53EF\u6839\u636E\u9700\u8981\u51B3\u5B9A\u662F\u5426\u76F8\u4E58\n material.emission = fragColor.rgb;\n\n return material;\n}\n"; // 动态墙材质
|
|
28
28
|
var DynamicWallMaterialProperty = /*#__PURE__*/function (_BaseMaterialProperty) {
|
|
29
29
|
_inherits(DynamicWallMaterialProperty, _BaseMaterialProperty);
|
|
30
30
|
var _super = _createSuper(DynamicWallMaterialProperty);
|