deeptwins-engine-3d 0.1.47 → 0.1.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.
Files changed (37) hide show
  1. package/dist/esm/analyze/ViewshedAnalysis.js +3 -2
  2. package/dist/esm/constant.d.ts +11 -0
  3. package/dist/esm/constant.js +26 -0
  4. package/dist/esm/graphicLayer/BaseLayer.js +6 -0
  5. package/dist/esm/graphicLayer/BasePrimitiveInstance.d.ts +2 -0
  6. package/dist/esm/graphicLayer/BasePrimitiveInstance.js +13 -5
  7. package/dist/esm/graphicLayer/BaseSource.d.ts +1 -1
  8. package/dist/esm/graphicLayer/BaseSource.js +6 -0
  9. package/dist/esm/graphicLayer/PolygonGroundPrimitiveImageMaterialInstance.d.ts +5 -0
  10. package/dist/esm/graphicLayer/PolygonGroundPrimitiveImageMaterialInstance.js +84 -0
  11. package/dist/esm/graphicLayer/PolygonPrimitive.js +6 -4
  12. package/dist/esm/graphicLayer/PolygonPrimitiveImageMaterialInstance.d.ts +5 -0
  13. package/dist/esm/graphicLayer/PolygonPrimitiveImageMaterialInstance.js +81 -0
  14. package/dist/esm/graphicLayer/PolygonPrimitiveInstance.d.ts +1 -1
  15. package/dist/esm/graphicLayer/PolygonPrimitiveInstance.js +8 -23
  16. package/dist/esm/graphicLayer/PolylineGroundPrimitiveInstance.js +1 -1
  17. package/dist/esm/index.d.ts +2 -1
  18. package/dist/esm/index.js +6 -4
  19. package/dist/esm/map/Map.js +1 -1
  20. package/dist/esm/material/primitive/BaseMaterialAppearance.d.ts +1 -0
  21. package/dist/esm/material/primitive/BaseMaterialAppearance.js +1 -0
  22. package/dist/esm/material/primitive/ImageMaterialAppearance.d.ts +10 -0
  23. package/dist/esm/material/primitive/ImageMaterialAppearance.js +77 -0
  24. package/dist/esm/material/shader/ImageShader.glsl +22 -0
  25. package/dist/esm/tool/BuildClampedPolygonGrid.d.ts +11 -0
  26. package/dist/esm/tool/BuildClampedPolygonGrid.js +151 -0
  27. package/dist/esm/tool/utils.d.ts +18 -1
  28. package/dist/esm/tool/utils.js +119 -44
  29. package/dist/esm/videoFusion/VideoProject.js +1 -1
  30. package/dist/esm/visualization/Frustum.d.ts +27 -2
  31. package/dist/esm/visualization/Frustum.js +158 -42
  32. package/dist/umd/deeptwins-engine-3d.min.js +1 -1
  33. package/package.json +8 -5
  34. package/dist/esm/visualization/BaseFrustum.d.ts +0 -14
  35. package/dist/esm/visualization/BaseFrustum.js +0 -96
  36. package/dist/esm/visualization/FrustumWithCamera.d.ts +0 -5
  37. package/dist/esm/visualization/FrustumWithCamera.js +0 -133
@@ -8,37 +8,52 @@ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
8
8
  function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
9
9
  function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
10
10
  function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
11
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
11
12
  function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
12
13
  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); }
13
- function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
14
- function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
15
- function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
16
- function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
17
- function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
18
- function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
19
- function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
20
14
  import * as Cesium from 'deeptwins-cesium';
15
+ import { merge } from 'lodash';
21
16
  import { v4 as uuidv4 } from 'uuid';
17
+ import { DEFAULT_FRUSTUM_OPTIONS } from "../constant";
22
18
  import * as utils from "../tool/utils";
23
- import BaseFrustum from "./BaseFrustum";
24
19
 
25
20
  // 视锥体
26
- var Frustum = /*#__PURE__*/function (_BaseFrustum) {
27
- _inherits(Frustum, _BaseFrustum);
28
- var _super = _createSuper(Frustum);
21
+ var Frustum = /*#__PURE__*/function () {
29
22
  function Frustum(map, options) {
30
- var _this;
31
23
  _classCallCheck(this, Frustum);
32
- _this = _super.call(this, map, options);
33
- _this._addFrustum();
34
- return _this;
24
+ _defineProperty(this, "_mapContext", void 0);
25
+ // 参数
26
+ _defineProperty(this, "options", void 0);
27
+ // 视锥面
28
+ _defineProperty(this, "frustumPrimitive", void 0);
29
+ // 视锥线
30
+ _defineProperty(this, "frustumLinePrimitive", void 0);
31
+ _defineProperty(this, "isDestroyed", false);
32
+ this._mapContext = map._mapContext;
33
+ this.options = merge(DEFAULT_FRUSTUM_OPTIONS(), options);
34
+ this._addFrustum();
35
35
  }
36
36
  _createClass(Frustum, [{
37
+ key: "getMap",
38
+ value: function getMap() {
39
+ return this._mapContext && this._mapContext.getMap();
40
+ }
41
+
42
+ // 是否能进行操作
43
+ }, {
44
+ key: "_canOperate",
45
+ value: function _canOperate() {
46
+ if (this.isDestroyed) {
47
+ utils.error('Frustum实例已销毁');
48
+ return false;
49
+ }
50
+ return true;
51
+ }
52
+ }, {
37
53
  key: "_addFrustum",
38
54
  value: function _addFrustum() {
39
55
  var _this$options = this.options,
40
- _this$options$show = _this$options.show,
41
- show = _this$options$show === void 0 ? true : _this$options$show,
56
+ show = _this$options.show,
42
57
  _this$options$positio = _this$options.position,
43
58
  position = _this$options$positio === void 0 ? [] : _this$options$positio,
44
59
  fov = _this$options.fov,
@@ -51,45 +66,62 @@ var Frustum = /*#__PURE__*/function (_BaseFrustum) {
51
66
  pitch = _this$options$pitch === void 0 ? 0 : _this$options$pitch,
52
67
  _this$options$roll = _this$options.roll,
53
68
  roll = _this$options$roll === void 0 ? 0 : _this$options$roll,
54
- _this$options$fill = _this$options.fill,
55
- fill = _this$options$fill === void 0 ? true : _this$options$fill,
56
- _this$options$color = _this$options.color,
57
- color = _this$options$color === void 0 ? 'rgba(255,0,0,0.3)' : _this$options$color,
58
- _this$options$outline = _this$options.outline,
59
- outline = _this$options$outline === void 0 ? true : _this$options$outline,
60
- _this$options$outline2 = _this$options.outlineColor,
61
- outlineColor = _this$options$outline2 === void 0 ? '#ffffff' : _this$options$outline2;
69
+ fill = _this$options.fill,
70
+ color = _this$options.color,
71
+ outline = _this$options.outline,
72
+ outlineColor = _this$options.outlineColor,
73
+ isWithCamera = _this$options.isWithCamera,
74
+ _this$options$camera = _this$options.camera,
75
+ paramCamera = _this$options$camera === void 0 ? this.getMap().camera : _this$options$camera;
76
+ var camera = isWithCamera ? paramCamera : new Cesium.Camera(this.getMap().scene);
62
77
  var _position = _slicedToArray(position, 3),
63
78
  lng = _position[0],
64
79
  lat = _position[1],
65
80
  alt = _position[2];
66
81
  var positionCartesian3 = utils.lngLatAltToCartesian3(lng, lat, alt);
67
- var hpr = new Cesium.HeadingPitchRoll(utils.toRadians(heading),
68
- // Heading (航向,绕 Z )
69
- utils.toRadians(pitch),
70
- // Pitch (俯仰,绕 X 轴)
71
- utils.toRadians(roll)) // Roll (横滚,绕 Y 轴)
72
- ;
73
- var orientation = Cesium.Transforms.headingPitchRollQuaternion(positionCartesian3, hpr);
82
+ if (!isWithCamera) {
83
+ camera.position = utils.lngLatAltToCartesian3(lng, lat, alt);
84
+ var hpr = new Cesium.HeadingPitchRoll(utils.toRadians(heading),
85
+ // Heading (航向,绕 Z 轴)
86
+ utils.toRadians(pitch),
87
+ // Pitch (俯仰,绕 X 轴)
88
+ utils.toRadians(roll)) // Roll (横滚,绕 Y 轴)
89
+ ;
90
+ camera.setView({
91
+ destination: camera.position,
92
+ // 或者直接用 position
93
+ orientation: hpr
94
+ });
95
+ }
74
96
  var frustum = new Cesium.PerspectiveFrustum({
75
97
  // 查看的视场角
76
- fov: fov ? utils.toRadians(fov) : this.getMap().camera.frustum.fov,
98
+ fov: fov ? utils.toRadians(fov) : camera.frustum.fov,
77
99
  // 视锥体的宽度/高度
78
- aspectRatio: aspectRatio ? aspectRatio : this.getMap().camera.frustum.aspectRatio,
100
+ aspectRatio: aspectRatio ? aspectRatio : camera.frustum.aspectRatio,
79
101
  // 近面距视点的距离
80
- near: near ? near : this.getMap().camera.frustum.near,
102
+ near: near ? near : camera.frustum.near,
81
103
  // 远面距视点的距离
82
- far: far ? far : this.getMap().camera.frustum.far
104
+ far: far ? far : camera.frustum.far
83
105
  });
106
+
107
+ // 计算摄像机的方向四元数
108
+ var direction = Cesium.Cartesian3.clone(camera.directionWC);
109
+ var up = Cesium.Cartesian3.clone(camera.upWC);
110
+ var right = Cesium.Cartesian3.clone(camera.rightWC);
111
+ var rotationMatrix = new Cesium.Matrix3();
112
+ Cesium.Matrix3.setColumn(rotationMatrix, 0, right, rotationMatrix); // X 轴
113
+ Cesium.Matrix3.setColumn(rotationMatrix, 1, up, rotationMatrix); // Y 轴
114
+ Cesium.Matrix3.setColumn(rotationMatrix, 2, direction, rotationMatrix); // Z 轴
115
+ var modelMatrix = Cesium.Matrix4.fromRotationTranslation(rotationMatrix, positionCartesian3);
84
116
  this.frustumPrimitive = new Cesium.Primitive({
85
117
  geometryInstances: new Cesium.GeometryInstance({
86
118
  id: uuidv4(),
87
119
  geometry: new Cesium.FrustumGeometry({
88
120
  frustum: frustum,
89
- origin: positionCartesian3,
90
- orientation: orientation,
91
- vertexFormat: Cesium.VertexFormat.POSITION_ONLY
121
+ origin: Cesium.Cartesian3.ZERO,
122
+ orientation: Cesium.Quaternion.IDENTITY
92
123
  }),
124
+ modelMatrix: modelMatrix,
93
125
  attributes: {
94
126
  color: fill ? utils.colorInstanceString(color) : utils.colorInstanceString('rgba(0, 0, 0, 0)')
95
127
  }
@@ -109,9 +141,10 @@ var Frustum = /*#__PURE__*/function (_BaseFrustum) {
109
141
  id: uuidv4(),
110
142
  geometry: new Cesium.FrustumOutlineGeometry({
111
143
  frustum: frustum,
112
- origin: positionCartesian3,
113
- orientation: orientation
144
+ origin: Cesium.Cartesian3.ZERO,
145
+ orientation: Cesium.Quaternion.IDENTITY
114
146
  }),
147
+ modelMatrix: modelMatrix,
115
148
  attributes: {
116
149
  color: utils.colorInstanceString(outlineColor)
117
150
  }
@@ -126,7 +159,90 @@ var Frustum = /*#__PURE__*/function (_BaseFrustum) {
126
159
  this.getMap().scene.primitives.add(this.frustumLinePrimitive);
127
160
  }
128
161
  }
162
+
163
+ /**
164
+ * 获取视锥体投影面的顶点坐标
165
+ * @param type 投影面类型: 'near'(近裁剪面) 或 'far'(远裁剪面)
166
+ * @returns 投影面的4个顶点坐标数组 [[lng, lat, alt], ...]
167
+ */
168
+ }, {
169
+ key: "getProjectionPlane",
170
+ value: function getProjectionPlane() {
171
+ var type = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'far';
172
+ if (!this._canOperate()) {
173
+ return;
174
+ }
175
+ var geometry = Cesium.FrustumOutlineGeometry.createGeometry(this.frustumPrimitive.geometryInstances.geometry);
176
+ var positions = geometry.attributes.position.values;
177
+
178
+ // 获取模型变换矩阵
179
+ var modelMatrix = this.frustumPrimitive.geometryInstances.modelMatrix;
180
+
181
+ // FrustumGeometry 的顶点顺序:前4个是近裁剪面,后4个是远裁剪面
182
+ // 每个面有4个顶点,每个顶点3个坐标值
183
+ var startIndex = type === 'near' ? 0 : 12; // 近面从0开始,远面从12(4*3)开始
184
+ var endIndex = startIndex + 12; // 4个顶点 * 3个坐标
185
+
186
+ var result = [];
187
+ for (var i = startIndex; i < endIndex; i += 3) {
188
+ var localPosition = new Cesium.Cartesian3(positions[i], positions[i + 1], positions[i + 2]);
189
+
190
+ // 转换为世界坐标
191
+ var worldPosition = Cesium.Matrix4.multiplyByPoint(modelMatrix, localPosition, new Cesium.Cartesian3());
192
+ var _utils$cartesian3ToLn = utils.cartesian3ToLngLatAlt(worldPosition),
193
+ lng = _utils$cartesian3ToLn.lng,
194
+ lat = _utils$cartesian3ToLn.lat,
195
+ alt = _utils$cartesian3ToLn.alt;
196
+ result.push([lng, lat, alt]);
197
+ }
198
+ return result;
199
+ }
200
+
201
+ /**
202
+ * 获取近裁剪面的顶点坐标
203
+ * @returns 近裁剪面的4个顶点坐标数组
204
+ */
205
+ }, {
206
+ key: "getNearPlane",
207
+ value: function getNearPlane() {
208
+ return this.getProjectionPlane('near');
209
+ }
210
+
211
+ /**
212
+ * 获取远裁剪面的顶点坐标
213
+ * @returns 远裁剪面的4个顶点坐标数组
214
+ */
215
+ }, {
216
+ key: "getFarPlane",
217
+ value: function getFarPlane() {
218
+ return this.getProjectionPlane('far');
219
+ }
220
+
221
+ // 显示隐藏
222
+ }, {
223
+ key: "show",
224
+ value: function show(isShow) {
225
+ if (!this._canOperate()) {
226
+ return;
227
+ }
228
+ this.frustumPrimitive && (this.frustumPrimitive.show = isShow);
229
+ this.frustumLinePrimitive && (this.frustumLinePrimitive.show = isShow);
230
+ }
231
+
232
+ // 销毁
233
+ }, {
234
+ key: "destroy",
235
+ value: function destroy() {
236
+ if (!this._canOperate()) {
237
+ return;
238
+ }
239
+ this.isDestroyed = true;
240
+ this.frustumPrimitive && this.getMap().scene.primitives.remove(this.frustumPrimitive);
241
+ this.frustumPrimitive = null;
242
+ this.frustumLinePrimitive && this.getMap().scene.primitives.remove(this.frustumLinePrimitive);
243
+ this.frustumLinePrimitive = null;
244
+ }
129
245
  }]);
130
246
  return Frustum;
131
- }(BaseFrustum);
247
+ }();
132
248
  export { Frustum as default };