deeptwins-engine-3d 0.1.49 → 0.1.51

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 (34) hide show
  1. package/dist/esm/constant.d.ts +9 -0
  2. package/dist/esm/constant.js +16 -0
  3. package/dist/esm/drawCommand/index.d.ts +2 -0
  4. package/dist/esm/drawCommand/index.js +2 -0
  5. package/dist/esm/drawCommand/viewShed/Event.d.ts +42 -0
  6. package/dist/esm/drawCommand/viewShed/Event.js +142 -0
  7. package/dist/esm/drawCommand/viewShed/RectangularSensorPrimitive.d.ts +266 -0
  8. package/dist/esm/drawCommand/viewShed/RectangularSensorPrimitive.js +1271 -0
  9. package/dist/esm/drawCommand/viewShed/ViewShadowPrimitive.d.ts +29 -0
  10. package/dist/esm/drawCommand/viewShed/ViewShadowPrimitive.js +66 -0
  11. package/dist/esm/drawCommand/viewShed/ViewShedAnalyserLayer.d.ts +182 -0
  12. package/dist/esm/drawCommand/viewShed/ViewShedAnalyserLayer.js +466 -0
  13. package/dist/esm/drawCommand/viewShed/ViewShedMap.d.ts +22 -0
  14. package/dist/esm/drawCommand/viewShed/ViewShedMap.js +1238 -0
  15. package/dist/esm/drawCommand/viewShed/config.d.ts +20 -0
  16. package/dist/esm/drawCommand/viewShed/config.js +21 -0
  17. package/dist/esm/graphicLayer/BaseSource.d.ts +1 -1
  18. package/dist/esm/graphicLayer/PolygonGroundPrimitiveImageMaterialInstance.js +1 -1
  19. package/dist/esm/index.d.ts +2 -1
  20. package/dist/esm/index.js +7 -4
  21. package/dist/esm/map/Map.d.ts +1 -0
  22. package/dist/esm/map/Map.js +6 -1
  23. package/dist/esm/material/primitive/ImageMaterialAppearance.d.ts +1 -1
  24. package/dist/esm/tool/BuildClampedPolygonGrid.d.ts +2 -9
  25. package/dist/esm/tool/BuildClampedPolygonGrid.js +200 -73
  26. package/dist/esm/tool/utils.d.ts +1 -0
  27. package/dist/esm/tool/utils.js +21 -0
  28. package/dist/esm/videoFusion/BaseVideo.js +17 -17
  29. package/dist/esm/videoFusion/VideoProject.d.ts +5 -5
  30. package/dist/esm/videoFusion/VideoProject.js +174 -184
  31. package/dist/esm/videoFusion/VideoTexture.d.ts +5 -1
  32. package/dist/esm/videoFusion/VideoTexture.js +133 -46
  33. package/dist/umd/deeptwins-engine-3d.min.js +1 -1
  34. package/package.json +4 -2
@@ -0,0 +1,1271 @@
1
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
2
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
3
+ 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); } }
4
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
5
+ 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; }
6
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
7
+ 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); }
8
+ import * as Cesium from 'deeptwins-cesium';
9
+ import { scanPlaneFS, sensorComm, sensorFS, sensorVS } from "./config";
10
+ var attributeLocations = {
11
+ position: 0,
12
+ normal: 1
13
+ };
14
+ var RectangularSensorPrimitive = /*#__PURE__*/function () {
15
+ function RectangularSensorPrimitive(options) {
16
+ var _options, _options$show, _options$slice, _options$radius, _options$xHalfAngle, _options$yHalfAngle, _options$_color, _options$lineColor, _options$showSectorLi, _options$showSectorSe, _options$showLateralS, _options$showDomeSurf, _options$showDomeLine, _options$showIntersec, _options$intersection, _options$intersection2, _options$showThroughE, _options$showScanPlan, _options$scanPlaneCol, _options$scanPlaneMod, _options$speed;
17
+ _classCallCheck(this, RectangularSensorPrimitive);
18
+ /**
19
+ * 模拟相控阵雷达。
20
+ * @param {Object} options 具有以下属性
21
+ * @param {Boolean} [options.show] 是否显示
22
+ * @param {Cartesian3|LonLat} [options.position] 图形位置
23
+ * @param {Matrix4} [options.modelMatrix] 模型矩阵,如果定义,则覆盖position属性
24
+ * @param {Number} [options.slice=32] 切分程度
25
+ * @param {Number} [options.radius=1] 半径
26
+ * @param {Color} [options.lineColor=Color.RED] 线的颜色
27
+ * @param {Number} [options.xHalfAngle] 水平半夹角,单位度
28
+ * @param {Number} [options.xyHalfAngle] 垂直半夹角,单位度
29
+ * @param {Boolean} [options.showSectorLines=true] 是否显示扇面线
30
+ * @param {Boolean} [options.showSectorSegmentLines=true] 是否显示扇面和圆顶面连接线
31
+ * @param {Boolean} [options.showLateralSurfaces=true] 是否显示侧面
32
+ * @param {Material} [options.material=Material.ColorType] 材质
33
+ * @param {Material} [options.lateralSurfaceMaterial=Material.ColorType] 侧面材质
34
+ * @param {Boolean} [options.showDomeSurfaces=true] 是否显示圆弧顶表面
35
+ * @param {Material} [options.domeSurfaceMaterial=Material.ColorType] 圆弧顶表面材质
36
+ * @param {Boolean} [options.showDomeLines=true] 是否显示圆弧顶表面线
37
+ * @param {Boolean} [options.showIntersection = false] 是否显示与地球相交的线
38
+ * @param {Color} [options.intersectionColor] 与地球相交的线的颜色
39
+ * @param {Number} [options.intersectionWidth=5] 与地球相交的线的宽度
40
+ * @param {Boolean} [options.showThroughEllipsoid=false] 是否穿过地球
41
+ * @param {Boolean} [options.showScanPlane=true] 是否显示扫描面
42
+ * @param {Color} [options.scanPlaneColor=Color.WHITE] 扫描面颜色
43
+ * @param {String} [options.scanPlaneMode='H'] 扫描方向,H表示水平扫描,V表示垂直扫描
44
+ * @param {Number} [options.speed=10] 扫描速度,值越大,扫描越快
45
+ */
46
+ _defineProperty(this, "options", void 0);
47
+ _defineProperty(this, "_createVS", void 0);
48
+ _defineProperty(this, "_createRS", void 0);
49
+ _defineProperty(this, "_createSP", void 0);
50
+ _defineProperty(this, "show", void 0);
51
+ _defineProperty(this, "slice", void 0);
52
+ _defineProperty(this, "_modelMatrix", void 0);
53
+ _defineProperty(this, "_computedModelMatrix", void 0);
54
+ _defineProperty(this, "_computedScanPlaneModelMatrix", void 0);
55
+ _defineProperty(this, "_radius", void 0);
56
+ _defineProperty(this, "_xHalfAngle", void 0);
57
+ _defineProperty(this, "_yHalfAngle", void 0);
58
+ _defineProperty(this, "_color", void 0);
59
+ _defineProperty(this, "lineColor", void 0);
60
+ _defineProperty(this, "showSectorLines", void 0);
61
+ _defineProperty(this, "showSectorSegmentLines", void 0);
62
+ _defineProperty(this, "showLateralSurfaces", void 0);
63
+ _defineProperty(this, "_material", void 0);
64
+ _defineProperty(this, "_translucent", void 0);
65
+ _defineProperty(this, "lateralSurfaceMaterial", void 0);
66
+ _defineProperty(this, "_lateralSurfaceMaterial", void 0);
67
+ _defineProperty(this, "_lateralSurfaceTranslucent", void 0);
68
+ _defineProperty(this, "showDomeSurfaces", void 0);
69
+ _defineProperty(this, "domeSurfaceMaterial", void 0);
70
+ _defineProperty(this, "showDomeLines", void 0);
71
+ _defineProperty(this, "showIntersection", void 0);
72
+ _defineProperty(this, "intersectionColor", void 0);
73
+ _defineProperty(this, "intersectionWidth", void 0);
74
+ _defineProperty(this, "_showThroughEllipsoid", void 0);
75
+ _defineProperty(this, "showScanPlane", void 0);
76
+ _defineProperty(this, "scanPlaneColor", void 0);
77
+ _defineProperty(this, "scanPlaneMode", void 0);
78
+ _defineProperty(this, "speed", void 0);
79
+ _defineProperty(this, "_scanePlaneXHalfAngle", void 0);
80
+ _defineProperty(this, "_scanePlaneYHalfAngle", void 0);
81
+ _defineProperty(this, "_time", void 0);
82
+ _defineProperty(this, "_boundingSphere", void 0);
83
+ _defineProperty(this, "_boundingSphereWC", void 0);
84
+ _defineProperty(this, "_sectorFrontCommand", void 0);
85
+ _defineProperty(this, "_sectorBackCommand", void 0);
86
+ _defineProperty(this, "_sectorVA", void 0);
87
+ _defineProperty(this, "_sectorLineCommand", void 0);
88
+ _defineProperty(this, "_sectorLineVA", void 0);
89
+ _defineProperty(this, "_sectorSegmentLineCommand", void 0);
90
+ _defineProperty(this, "_sectorSegmentLineVA", void 0);
91
+ _defineProperty(this, "_domeFrontCommand", void 0);
92
+ _defineProperty(this, "_domeBackCommand", void 0);
93
+ _defineProperty(this, "_domeVA", void 0);
94
+ _defineProperty(this, "_domeLineCommand", void 0);
95
+ _defineProperty(this, "_domeLineVA", void 0);
96
+ _defineProperty(this, "_scanPlaneFrontCommand", void 0);
97
+ _defineProperty(this, "_scanPlaneBackCommand", void 0);
98
+ _defineProperty(this, "_scanRadialCommand", void 0);
99
+ _defineProperty(this, "_scanPlaneVA", void 0);
100
+ _defineProperty(this, "_colorCommands", void 0);
101
+ _defineProperty(this, "_frontFaceRS", void 0);
102
+ _defineProperty(this, "_backFaceRS", void 0);
103
+ _defineProperty(this, "_sp", void 0);
104
+ _defineProperty(this, "_pickSP", void 0);
105
+ _defineProperty(this, "_scanePlaneSP", void 0);
106
+ _defineProperty(this, "_uniforms", void 0);
107
+ _defineProperty(this, "_scanUniforms", void 0);
108
+ _defineProperty(this, "_pickRS", void 0);
109
+ options = (_options = options) !== null && _options !== void 0 ? _options : Cesium.defaultValue.EMPTY_OBJECT;
110
+ var self = this;
111
+ this._createVS = true;
112
+ this._createRS = true;
113
+ this._createSP = true;
114
+ /**
115
+ * 是否显示
116
+ * @type {Boolean}
117
+ */
118
+ this.show = (_options$show = options.show) !== null && _options$show !== void 0 ? _options$show : true;
119
+
120
+ //切分程度
121
+ this.slice = (_options$slice = options.slice) !== null && _options$slice !== void 0 ? _options$slice : 32;
122
+
123
+ //传感器的模型矩阵
124
+ if (!options.modelMatrix) {
125
+ if (!options.position) {
126
+ throw new Error('parameter position or modelMatrix must be provided.');
127
+ }
128
+ this._modelMatrix = Cesium.Transforms.eastNorthUpToFixedFrame(Cesium.Cartesian3.fromDegrees(options.position.lon, options.position.lat, options.position.alt));
129
+ } else {
130
+ this._modelMatrix = Cesium.Matrix4.clone(options.modelMatrix, new Cesium.Matrix4());
131
+ }
132
+ this._computedModelMatrix = new Cesium.Matrix4();
133
+ this._computedScanPlaneModelMatrix = new Cesium.Matrix4();
134
+
135
+ //传感器的半径
136
+ this._radius = (_options$radius = options.radius) !== null && _options$radius !== void 0 ? _options$radius : Number.POSITIVE_INFINITY;
137
+
138
+ //传感器水平半角
139
+ this._xHalfAngle = Cesium.Math.toRadians((_options$xHalfAngle = options.xHalfAngle) !== null && _options$xHalfAngle !== void 0 ? _options$xHalfAngle : 0);
140
+
141
+ //传感器垂直半角
142
+ this._yHalfAngle = Cesium.Math.toRadians((_options$yHalfAngle = options.yHalfAngle) !== null && _options$yHalfAngle !== void 0 ? _options$yHalfAngle : 0);
143
+ this._color = (_options$_color = options._color) !== null && _options$_color !== void 0 ? _options$_color : Cesium.Color.AQUA.withAlpha(0.4);
144
+
145
+ /**
146
+ * 线的颜色
147
+ * @type {Cesium.Color}
148
+ */
149
+ this.lineColor = (_options$lineColor = options.lineColor) !== null && _options$lineColor !== void 0 ? _options$lineColor : Cesium.Color.WHITE;
150
+
151
+ /**
152
+ * 是否显示扇面的线
153
+ * @type {Boolean}
154
+ */
155
+ this.showSectorLines = (_options$showSectorLi = options.showSectorLines) !== null && _options$showSectorLi !== void 0 ? _options$showSectorLi : true;
156
+
157
+ /**
158
+ * 是否显示扇面和圆顶面连接的线
159
+ * @type {Boolean}
160
+ */
161
+ this.showSectorSegmentLines = (_options$showSectorSe = options.showSectorSegmentLines) !== null && _options$showSectorSe !== void 0 ? _options$showSectorSe : true;
162
+
163
+ /**
164
+ * 是否显示侧面
165
+ * @type {Boolean}
166
+ */
167
+ this.showLateralSurfaces = (_options$showLateralS = options.showLateralSurfaces) !== null && _options$showLateralS !== void 0 ? _options$showLateralS : true;
168
+
169
+ //目前用的统一材质
170
+ this._material = Cesium.defined(options.material) ? options.material : Cesium.Material.fromType(Cesium.Material.ColorType);
171
+ this._material.uniforms.color = this._color;
172
+ this._translucent = undefined;
173
+ /**
174
+ * 侧面材质
175
+ * @type {Material}
176
+ */
177
+ this.lateralSurfaceMaterial = Cesium.defined(options.lateralSurfaceMaterial) ? options.lateralSurfaceMaterial : Cesium.Material.fromType(Cesium.Material.ColorType);
178
+ this._lateralSurfaceMaterial = undefined;
179
+ this._lateralSurfaceTranslucent = undefined;
180
+
181
+ /**
182
+ * 是否显示圆顶表面
183
+ * @type {Boolean}
184
+ */
185
+ this.showDomeSurfaces = (_options$showDomeSurf = options.showDomeSurfaces) !== null && _options$showDomeSurf !== void 0 ? _options$showDomeSurf : true;
186
+
187
+ /**
188
+ * 圆顶表面材质
189
+ * @type {Material}
190
+ */
191
+ this.domeSurfaceMaterial = Cesium.defined(options.domeSurfaceMaterial) ? options.domeSurfaceMaterial : Cesium.Material.fromType(Cesium.Material.ColorType);
192
+
193
+ /**
194
+ * 是否显示圆顶面线
195
+ * @type {Boolean}
196
+ */
197
+ this.showDomeLines = (_options$showDomeLine = options.showDomeLines) !== null && _options$showDomeLine !== void 0 ? _options$showDomeLine : true;
198
+
199
+ /**
200
+ * 是否显示与地球相交的线
201
+ * @type {Boolean}
202
+ */
203
+ this.showIntersection = (_options$showIntersec = options.showIntersection) !== null && _options$showIntersec !== void 0 ? _options$showIntersec : false;
204
+
205
+ /**
206
+ * 与地球相交的线的颜色
207
+ * @type {Color}
208
+ */
209
+ this.intersectionColor = (_options$intersection = options.intersectionColor) !== null && _options$intersection !== void 0 ? _options$intersection : Cesium.Color.WHITE;
210
+
211
+ /**
212
+ * 与地球相交的线的宽度(像素)
213
+ * @type {Number}
214
+ */
215
+ this.intersectionWidth = (_options$intersection2 = options.intersectionWidth) !== null && _options$intersection2 !== void 0 ? _options$intersection2 : 5.0;
216
+
217
+ //是否穿过地球
218
+ this._showThroughEllipsoid = (_options$showThroughE = options.showThroughEllipsoid) !== null && _options$showThroughE !== void 0 ? _options$showThroughE : false;
219
+
220
+ /**
221
+ * 是否显示扫描面
222
+ * @type {Boolean}
223
+ */
224
+ this.showScanPlane = (_options$showScanPlan = options.showScanPlane) !== null && _options$showScanPlan !== void 0 ? _options$showScanPlan : true;
225
+
226
+ /**
227
+ * 扫描面颜色
228
+ * @type {Color}
229
+ */
230
+ this.scanPlaneColor = (_options$scanPlaneCol = options.scanPlaneColor) !== null && _options$scanPlaneCol !== void 0 ? _options$scanPlaneCol : Cesium.Color.AQUA;
231
+ /**
232
+ * 扫描面模式 垂直V/水平H
233
+ * @type {String}
234
+ */
235
+ this.scanPlaneMode = (_options$scanPlaneMod = options.scanPlaneMode) !== null && _options$scanPlaneMod !== void 0 ? _options$scanPlaneMod : 'H';
236
+
237
+ /**
238
+ * 扫描速率,值越大,扫描越慢
239
+ * @type {Number}
240
+ */
241
+ this.speed = (_options$speed = options.speed) !== null && _options$speed !== void 0 ? _options$speed : 10;
242
+ this._scanePlaneXHalfAngle = 0;
243
+ this._scanePlaneYHalfAngle = 0;
244
+
245
+ //时间计算的起点
246
+ this._time = Cesium.JulianDate.now();
247
+ this._boundingSphere = new Cesium.BoundingSphere();
248
+ this._boundingSphereWC = new Cesium.BoundingSphere();
249
+ this._boundingSphere = new Cesium.BoundingSphere(Cesium.Cartesian3.ZERO, this._radius);
250
+ Cesium.Matrix4.multiplyByUniformScale(this._modelMatrix, this._radius, this._computedModelMatrix);
251
+ Cesium.BoundingSphere.transform(this._boundingSphere, this._modelMatrix, this._boundingSphereWC);
252
+
253
+ //扇面 sector
254
+ this._sectorFrontCommand = new Cesium.DrawCommand({
255
+ owner: this,
256
+ primitiveType: Cesium.PrimitiveType.TRIANGLES,
257
+ boundingVolume: this._boundingSphereWC
258
+ });
259
+ this._sectorBackCommand = new Cesium.DrawCommand({
260
+ owner: this,
261
+ primitiveType: Cesium.PrimitiveType.TRIANGLES,
262
+ boundingVolume: this._boundingSphereWC
263
+ });
264
+ this._sectorVA = undefined;
265
+
266
+ //扇面边线 sectorLine
267
+ this._sectorLineCommand = new Cesium.DrawCommand({
268
+ owner: this,
269
+ primitiveType: Cesium.PrimitiveType.LINES,
270
+ boundingVolume: this._boundingSphereWC
271
+ });
272
+ this._sectorLineVA = undefined;
273
+
274
+ //扇面分割线 sectorSegmentLine
275
+ this._sectorSegmentLineCommand = new Cesium.DrawCommand({
276
+ owner: this,
277
+ primitiveType: Cesium.PrimitiveType.LINES,
278
+ boundingVolume: this._boundingSphereWC
279
+ });
280
+ this._sectorSegmentLineVA = undefined;
281
+
282
+ //弧面 dome
283
+ this._domeFrontCommand = new Cesium.DrawCommand({
284
+ owner: this,
285
+ primitiveType: Cesium.PrimitiveType.TRIANGLES,
286
+ boundingVolume: this._boundingSphereWC
287
+ });
288
+ this._domeBackCommand = new Cesium.DrawCommand({
289
+ owner: this,
290
+ primitiveType: Cesium.PrimitiveType.TRIANGLES,
291
+ boundingVolume: this._boundingSphereWC
292
+ });
293
+ this._domeVA = undefined;
294
+
295
+ //弧面线 domeLine
296
+ this._domeLineCommand = new Cesium.DrawCommand({
297
+ owner: this,
298
+ primitiveType: Cesium.PrimitiveType.LINES,
299
+ boundingVolume: this._boundingSphereWC
300
+ });
301
+ this._domeLineVA = undefined;
302
+
303
+ //扫描面 scanPlane/scanRadial
304
+ this._scanPlaneFrontCommand = new Cesium.DrawCommand({
305
+ owner: this,
306
+ primitiveType: Cesium.PrimitiveType.TRIANGLES,
307
+ boundingVolume: this._boundingSphereWC
308
+ });
309
+ this._scanPlaneBackCommand = new Cesium.DrawCommand({
310
+ owner: this,
311
+ primitiveType: Cesium.PrimitiveType.TRIANGLES,
312
+ boundingVolume: this._boundingSphereWC
313
+ });
314
+ this._scanRadialCommand = undefined;
315
+ this._colorCommands = [];
316
+ this._frontFaceRS = undefined;
317
+ this._backFaceRS = undefined;
318
+ this._sp = undefined;
319
+ this._pickSP = undefined;
320
+ this._scanePlaneSP = undefined;
321
+ this._uniforms = {
322
+ u_type: function u_type() {
323
+ return 0; //面
324
+ },
325
+ u_xHalfAngle: function u_xHalfAngle() {
326
+ return self._xHalfAngle;
327
+ },
328
+ u_yHalfAngle: function u_yHalfAngle() {
329
+ return self._yHalfAngle;
330
+ },
331
+ u_radius: function u_radius() {
332
+ return self.radius;
333
+ },
334
+ u_showThroughEllipsoid: function u_showThroughEllipsoid() {
335
+ return self.showThroughEllipsoid;
336
+ },
337
+ u_showIntersection: function u_showIntersection() {
338
+ return self.showIntersection;
339
+ },
340
+ u_intersectionColor: function u_intersectionColor() {
341
+ return self.intersectionColor;
342
+ },
343
+ u_intersectionWidth: function u_intersectionWidth() {
344
+ return self.intersectionWidth;
345
+ },
346
+ u_normalDirection: function u_normalDirection() {
347
+ return 1.0;
348
+ },
349
+ u_lineColor: function u_lineColor() {
350
+ return self.lineColor;
351
+ }
352
+ };
353
+ this._scanUniforms = {
354
+ u_xHalfAngle: function u_xHalfAngle() {
355
+ return self._scanePlaneXHalfAngle;
356
+ },
357
+ u_yHalfAngle: function u_yHalfAngle() {
358
+ return self._scanePlaneYHalfAngle;
359
+ },
360
+ u_radius: function u_radius() {
361
+ return self.radius;
362
+ },
363
+ u_color: function u_color() {
364
+ return self.scanPlaneColor;
365
+ },
366
+ u_showThroughEllipsoid: function u_showThroughEllipsoid() {
367
+ return self.showThroughEllipsoid;
368
+ },
369
+ u_showIntersection: function u_showIntersection() {
370
+ return self.showIntersection;
371
+ },
372
+ u_intersectionColor: function u_intersectionColor() {
373
+ return self.intersectionColor;
374
+ },
375
+ u_intersectionWidth: function u_intersectionWidth() {
376
+ return self.intersectionWidth;
377
+ },
378
+ u_normalDirection: function u_normalDirection() {
379
+ return 1.0;
380
+ },
381
+ u_lineColor: function u_lineColor() {
382
+ return self.lineColor;
383
+ }
384
+ };
385
+ }
386
+ _createClass(RectangularSensorPrimitive, [{
387
+ key: "color",
388
+ get: function get() {
389
+ return this._color;
390
+ },
391
+ set: function set(val) {
392
+ this._color = val;
393
+ this._material.uniforms.color = val;
394
+ }
395
+ }, {
396
+ key: "boundingSphere",
397
+ get: function get() {
398
+ return this._boundingSphere;
399
+ }
400
+ /**
401
+ * 水平面半夹角,单位:度
402
+ * @type {Number}
403
+ */
404
+ }, {
405
+ key: "xHalfAngle",
406
+ get: function get() {
407
+ return Cesium.Math.toDegrees(this._xHalfAngle);
408
+ },
409
+ set: function set(val) {
410
+ if (this._xHalfAngle !== val) {
411
+ this._xHalfAngle = Cesium.Math.toRadians(val);
412
+ this._createVS = true;
413
+ }
414
+ }
415
+ /**
416
+ * 垂直面半夹角,单位:度
417
+ * @type {Number}
418
+ */
419
+ }, {
420
+ key: "yHalfAngle",
421
+ get: function get() {
422
+ return Cesium.Math.toDegrees(this._yHalfAngle);
423
+ },
424
+ set: function set(val) {
425
+ if (this._yHalfAngle !== val) {
426
+ this._yHalfAngle = Cesium.Math.toRadians(val);
427
+ this._createVS = true;
428
+ }
429
+ }
430
+ /**
431
+ * 传感器半径
432
+ * @type {Number}
433
+ */
434
+ }, {
435
+ key: "radius",
436
+ get: function get() {
437
+ return this._radius;
438
+ },
439
+ set: function set(val) {
440
+ if (this._radius !== val) {
441
+ this._radius = val;
442
+ this._boundingSphere = new Cesium.BoundingSphere(Cesium.Cartesian3.ZERO, val);
443
+ Cesium.Matrix4.multiplyByUniformScale(this._modelMatrix, this._radius, this._computedModelMatrix);
444
+ Cesium.BoundingSphere.transform(this._boundingSphere, this._modelMatrix, this._boundingSphereWC);
445
+ }
446
+ }
447
+ /**
448
+ * 传感器模型矩阵
449
+ * @type {Matrix4}
450
+ */
451
+ }, {
452
+ key: "modelMatrix",
453
+ get: function get() {
454
+ return this._modelMatrix;
455
+ },
456
+ set: function set(val) {
457
+ var modelMatrixChanged = !Cesium.Matrix4.equals(val, this._modelMatrix);
458
+ if (modelMatrixChanged) {
459
+ Cesium.Matrix4.clone(val, this._modelMatrix);
460
+ Cesium.Matrix4.multiplyByUniformScale(this._modelMatrix, this._radius, this._computedModelMatrix);
461
+ Cesium.BoundingSphere.transform(this._boundingSphere, this._modelMatrix, this._boundingSphereWC);
462
+ }
463
+ }
464
+ /**
465
+ * 是否传过地球
466
+ * @type {Boolean}
467
+ */
468
+ }, {
469
+ key: "showThroughEllipsoid",
470
+ get: function get() {
471
+ return this._showThroughEllipsoid;
472
+ },
473
+ set: function set(val) {
474
+ if (this._showThroughEllipsoid !== val) {
475
+ this._showThroughEllipsoid = val;
476
+ this._createRS = true;
477
+ }
478
+ }
479
+ /**
480
+ * 材质
481
+ * @type {Material}
482
+ */
483
+ }, {
484
+ key: "material",
485
+ get: function get() {
486
+ return this._material;
487
+ },
488
+ set: function set(val) {
489
+ this._material = val;
490
+ this._createRS = true;
491
+ this._createSP = true;
492
+ }
493
+
494
+ /**
495
+ * 每一帧在渲染时Cesium会自动调用该方法。不要主动调用该方法
496
+ * @override
497
+ * @param {frameState} frameState
498
+ */
499
+ }, {
500
+ key: "update",
501
+ value: function update(frameState) {
502
+ var mode = frameState.mode;
503
+ if (!this.show || mode !== Cesium.SceneMode.SCENE3D) {
504
+ return;
505
+ }
506
+ var xHalfAngle = this._xHalfAngle;
507
+ var yHalfAngle = this._yHalfAngle;
508
+ if (xHalfAngle < 0.0 || yHalfAngle < 0.0) {
509
+ throw new Error('halfAngle must be greater than or equal to zero.');
510
+ }
511
+ if (xHalfAngle == 0.0 || yHalfAngle == 0.0) {
512
+ return;
513
+ }
514
+ var radius = this.radius;
515
+ if (radius < 0.0) {
516
+ throw new Error('this.radius must be greater than or equal to zero.');
517
+ }
518
+ var showThroughEllipsoid = this.showThroughEllipsoid;
519
+ var material = this.material;
520
+ var translucent = material.isTranslucent();
521
+ if (this._translucent !== translucent) {
522
+ this._translucent = translucent;
523
+ this._createRS = true;
524
+ }
525
+ if (this.showScanPlane) {
526
+ var time = frameState.time;
527
+ var timeDiff = Cesium.JulianDate.secondsDifference(time, this._time);
528
+ if (timeDiff < 0) {
529
+ this._time = Cesium.JulianDate.clone(time, this._time);
530
+ }
531
+ var percentage;
532
+ if (this.speed <= 0) {
533
+ percentage = 0;
534
+ } else {
535
+ var speet = 10 / this.speed;
536
+ percentage = Math.max(timeDiff % speet / speet, 0);
537
+ }
538
+ var angle;
539
+ var matrix3Scratch = new Cesium.Matrix3();
540
+ if (this.scanPlaneMode == 'H') {
541
+ angle = 2 * yHalfAngle * percentage - yHalfAngle;
542
+ var cosYHalfAngle = Math.cos(angle);
543
+ var tanXHalfAngle = Math.tan(xHalfAngle);
544
+ var maxX = Math.atan(cosYHalfAngle * tanXHalfAngle);
545
+ this._scanePlaneXHalfAngle = maxX;
546
+ this._scanePlaneYHalfAngle = angle;
547
+ Cesium.Matrix3.fromRotationX(this._scanePlaneYHalfAngle, matrix3Scratch);
548
+ } else {
549
+ angle = 2 * xHalfAngle * percentage - xHalfAngle;
550
+ var tanYHalfAngle = Math.tan(yHalfAngle);
551
+ var cosXHalfAngle = Math.cos(angle);
552
+ var maxY = Math.atan(cosXHalfAngle * tanYHalfAngle);
553
+ this._scanePlaneXHalfAngle = angle;
554
+ this._scanePlaneYHalfAngle = maxY;
555
+ Cesium.Matrix3.fromRotationY(this._scanePlaneXHalfAngle, matrix3Scratch);
556
+ }
557
+ Cesium.Matrix4.multiplyByMatrix3(this.modelMatrix, matrix3Scratch, this._computedScanPlaneModelMatrix);
558
+ Cesium.Matrix4.multiplyByUniformScale(this._computedScanPlaneModelMatrix, this.radius, this._computedScanPlaneModelMatrix);
559
+ }
560
+ if (this._createVS) {
561
+ this.createVertexArray(this, frameState);
562
+ }
563
+ if (this._createRS) {
564
+ this.createRenderState(this, showThroughEllipsoid, translucent);
565
+ }
566
+ if (this._createSP) {
567
+ this.createShaderProgram(this, frameState, material);
568
+ }
569
+ if (this._createRS || this._createSP) {
570
+ this.createCommands(this, translucent);
571
+ }
572
+ var commandList = frameState.commandList;
573
+ var passes = frameState.passes;
574
+ var colorCommands = this._colorCommands;
575
+ if (passes.render) {
576
+ for (var i = 0, len = colorCommands.length; i < len; i++) {
577
+ var colorCommand = colorCommands[i];
578
+ commandList.push(colorCommand);
579
+ }
580
+ }
581
+ }
582
+
583
+ /**
584
+ * 创建顶点数组
585
+ * @param primitive: any
586
+ * @param frameState: any
587
+ */
588
+ }, {
589
+ key: "createVertexArray",
590
+ value: function createVertexArray(primitive, frameState) {
591
+ var context = frameState.context;
592
+ var unitSectorPositions = this.computeUnitPosition(primitive, primitive._xHalfAngle, primitive._yHalfAngle);
593
+ var positions = this.computeSectorPositions(primitive, unitSectorPositions);
594
+
595
+ //显示扇面
596
+ if (primitive.showLateralSurfaces) {
597
+ primitive._sectorVA = this.createSectorVertexArray(context, positions);
598
+ }
599
+
600
+ //显示扇面线
601
+ if (primitive.showSectorLines) {
602
+ primitive._sectorLineVA = this.createSectorLineVertexArray(context, positions);
603
+ }
604
+
605
+ //显示扇面圆顶面的交线
606
+ if (primitive.showSectorSegmentLines) {
607
+ primitive._sectorSegmentLineVA = this.createSectorSegmentLineVertexArray(context, positions);
608
+ }
609
+
610
+ //显示弧面
611
+ if (primitive.showDomeSurfaces) {
612
+ primitive._domeVA = this.createDomeVertexArray(context);
613
+ }
614
+
615
+ //显示弧面线
616
+ if (primitive.showDomeLines) {
617
+ primitive._domeLineVA = this.createDomeLineVertexArray(context);
618
+ }
619
+
620
+ //显示扫描面
621
+ if (primitive.showScanPlane) {
622
+ if (primitive.scanPlaneMode == 'H') {
623
+ var unitScanPlanePositions = this.computeUnitPosition(primitive, Cesium.Math.PI_OVER_TWO, 0);
624
+ primitive._scanPlaneVA = this.createScanPlaneVertexArray(context, unitScanPlanePositions.zox);
625
+ } else {
626
+ var _unitScanPlanePositions = this.computeUnitPosition(primitive, 0, Cesium.Math.PI_OVER_TWO);
627
+ primitive._scanPlaneVA = this.createScanPlaneVertexArray(context, _unitScanPlanePositions.zoy);
628
+ }
629
+ }
630
+ }
631
+ /**
632
+ * 创建渲染状态
633
+ * @param primitive: any
634
+ * @param showThroughEllipsoid: any
635
+ * @param translucent: any
636
+ */
637
+ }, {
638
+ key: "createRenderState",
639
+ value: function createRenderState(primitive, showThroughEllipsoid, translucent) {
640
+ if (translucent) {
641
+ primitive._frontFaceRS = Cesium.RenderState.fromCache({
642
+ depthTest: {
643
+ enabled: !showThroughEllipsoid
644
+ },
645
+ depthMask: false,
646
+ blending: Cesium.BlendingState.ALPHA_BLEND,
647
+ cull: {
648
+ enabled: true,
649
+ face: Cesium.CullFace.BACK
650
+ }
651
+ });
652
+ primitive._backFaceRS = Cesium.RenderState.fromCache({
653
+ depthTest: {
654
+ enabled: !showThroughEllipsoid
655
+ },
656
+ depthMask: false,
657
+ blending: Cesium.BlendingState.ALPHA_BLEND,
658
+ cull: {
659
+ enabled: true,
660
+ face: Cesium.CullFace.FRONT
661
+ }
662
+ });
663
+ primitive._pickRS = Cesium.RenderState.fromCache({
664
+ depthTest: {
665
+ enabled: !showThroughEllipsoid
666
+ },
667
+ depthMask: false,
668
+ blending: Cesium.BlendingState.ALPHA_BLEND
669
+ });
670
+ } else {
671
+ primitive._frontFaceRS = Cesium.RenderState.fromCache({
672
+ depthTest: {
673
+ enabled: !showThroughEllipsoid
674
+ },
675
+ depthMask: true
676
+ });
677
+ primitive._pickRS = Cesium.RenderState.fromCache({
678
+ depthTest: {
679
+ enabled: true
680
+ },
681
+ depthMask: true
682
+ });
683
+ }
684
+ }
685
+ /**
686
+ * 创建着色器程序
687
+ * @param primitive: any
688
+ * @param frameState: any
689
+ * @param material: any
690
+ */
691
+ }, {
692
+ key: "createShaderProgram",
693
+ value: function createShaderProgram(primitive, frameState, material) {
694
+ this.createCommonShaderProgram(primitive, frameState, material);
695
+ if (primitive.showScanPlane) {
696
+ this.createScanPlaneShaderProgram(primitive, frameState, material);
697
+ }
698
+ }
699
+
700
+ /**
701
+ * 创建命令
702
+ * @param primitive: any
703
+ * @param translucent: any
704
+ */
705
+ }, {
706
+ key: "createCommands",
707
+ value: function createCommands(primitive, translucent) {
708
+ primitive._colorCommands.length = 0;
709
+ var pass = translucent ? Cesium.Pass.TRANSLUCENT : Cesium.Pass.OPAQUE;
710
+
711
+ //显示扇面
712
+ if (primitive.showLateralSurfaces) {
713
+ this.createCommand(primitive, primitive._sectorFrontCommand, primitive._sectorBackCommand, primitive._frontFaceRS, primitive._backFaceRS, primitive._sp, primitive._sectorVA, primitive._uniforms, primitive._computedModelMatrix, translucent, pass);
714
+ }
715
+ //显示扇面线
716
+ if (primitive.showSectorLines) {
717
+ this.createCommand(primitive, primitive._sectorLineCommand, undefined, primitive._frontFaceRS, primitive._backFaceRS, primitive._sp, primitive._sectorLineVA, primitive._uniforms, primitive._computedModelMatrix, translucent, pass, true);
718
+ }
719
+
720
+ //显示扇面交接线
721
+ if (primitive.showSectorSegmentLines) {
722
+ this.createCommand(primitive, primitive._sectorSegmentLineCommand, undefined, primitive._frontFaceRS, primitive._backFaceRS, primitive._sp, primitive._sectorSegmentLineVA, primitive._uniforms, primitive._computedModelMatrix, translucent, pass, true);
723
+ }
724
+
725
+ //显示弧面
726
+ if (primitive.showDomeSurfaces) {
727
+ this.createCommand(primitive, primitive._domeFrontCommand, primitive._domeBackCommand, primitive._frontFaceRS, primitive._backFaceRS, primitive._sp, primitive._domeVA, primitive._uniforms, primitive._computedModelMatrix, translucent, pass);
728
+ }
729
+
730
+ //显示弧面线
731
+ if (primitive.showDomeLines) {
732
+ this.createCommand(primitive, primitive._domeLineCommand, undefined, primitive._frontFaceRS, primitive._backFaceRS, primitive._sp, primitive._domeLineVA, primitive._uniforms, primitive._computedModelMatrix, translucent, pass, true);
733
+ }
734
+ //显示扫描面
735
+ if (primitive.showScanPlane) {
736
+ this.createCommand(primitive, primitive._scanPlaneFrontCommand, primitive._scanPlaneBackCommand, primitive._frontFaceRS, primitive._backFaceRS, primitive._scanePlaneSP, primitive._scanPlaneVA, primitive._scanUniforms, primitive._computedScanPlaneModelMatrix, translucent, pass);
737
+ }
738
+ return;
739
+ }
740
+
741
+ /**
742
+ * 生成单位圆
743
+ * @param primitive: any
744
+ * @param xHalfAngle: any
745
+ * @param yHalfAngle: any
746
+ * @returns {Object} {zoy, zox}
747
+ */
748
+ }, {
749
+ key: "computeUnitPosition",
750
+ value: function computeUnitPosition(primitive, xHalfAngle, yHalfAngle) {
751
+ var slice = primitive.slice;
752
+ //以中心为角度
753
+ var cosYHalfAngle = Math.cos(yHalfAngle);
754
+ var tanYHalfAngle = Math.tan(yHalfAngle);
755
+ var cosXHalfAngle = Math.cos(xHalfAngle);
756
+ var tanXHalfAngle = Math.tan(xHalfAngle);
757
+ var maxY = Math.atan(cosXHalfAngle * tanYHalfAngle);
758
+ var maxX = Math.atan(cosYHalfAngle * tanXHalfAngle);
759
+
760
+ //ZOY面单位圆
761
+ var zoy = [];
762
+ for (var i = 0; i < slice; i++) {
763
+ var phi = 2 * maxY * i / (slice - 1) - maxY;
764
+ zoy.push(new Cesium.Cartesian3(0, Math.sin(phi), Math.cos(phi)));
765
+ }
766
+ //zox面单位圆
767
+ var zox = [];
768
+ for (var _i = 0; _i < slice; _i++) {
769
+ var _phi = 2 * maxX * _i / (slice - 1) - maxX;
770
+ zox.push(new Cesium.Cartesian3(Math.sin(_phi), 0, Math.cos(_phi)));
771
+ }
772
+ return {
773
+ zoy: zoy,
774
+ zox: zox
775
+ };
776
+ }
777
+
778
+ /**
779
+ * 计算扇面位置
780
+ * @param primitive: any
781
+ * @param unitPosition: { zoy: any[]; zox: any[] }
782
+ * @returns {Array} 扇面位置
783
+ */
784
+ }, {
785
+ key: "computeSectorPositions",
786
+ value: function computeSectorPositions(primitive, unitPosition) {
787
+ var xHalfAngle = primitive._xHalfAngle,
788
+ yHalfAngle = primitive._yHalfAngle,
789
+ zoy = unitPosition.zoy,
790
+ zox = unitPosition.zox;
791
+ var positions = [];
792
+
793
+ //zoy面沿y轴逆时针转xHalfAngle
794
+ var matrix3Scratch = new Cesium.Matrix3();
795
+ var matrix3 = Cesium.Matrix3.fromRotationY(xHalfAngle, matrix3Scratch);
796
+ positions.push(zoy.map(function (p) {
797
+ return Cesium.Matrix3.multiplyByVector(matrix3, p, new Cesium.Cartesian3());
798
+ }));
799
+ //zox面沿x轴顺时针转yHalfAngle
800
+ matrix3 = Cesium.Matrix3.fromRotationX(-yHalfAngle, matrix3Scratch);
801
+ positions.push(zox.map(function (p) {
802
+ return Cesium.Matrix3.multiplyByVector(matrix3, p, new Cesium.Cartesian3());
803
+ }).reverse());
804
+ //zoy面沿y轴顺时针转xHalfAngle
805
+ matrix3 = Cesium.Matrix3.fromRotationY(-xHalfAngle, matrix3Scratch);
806
+ positions.push(zoy.map(function (p) {
807
+ return Cesium.Matrix3.multiplyByVector(matrix3, p, new Cesium.Cartesian3());
808
+ }).reverse());
809
+ //zox面沿x轴逆时针转yHalfAngle
810
+ matrix3 = Cesium.Matrix3.fromRotationX(yHalfAngle, matrix3Scratch);
811
+ positions.push(zox.map(function (p) {
812
+ return Cesium.Matrix3.multiplyByVector(matrix3, p, new Cesium.Cartesian3());
813
+ }));
814
+ return positions;
815
+ }
816
+
817
+ /**
818
+ * 创建扇面顶点数组
819
+ * @param context: any
820
+ * @param positions: any[]
821
+ * @returns {VertexArray}
822
+ */
823
+ }, {
824
+ key: "createSectorVertexArray",
825
+ value: function createSectorVertexArray(context, positions) {
826
+ var planeLength = Array.prototype.concat.apply([], positions).length - positions.length;
827
+ var vertices = new Float32Array(2 * 3 * 3 * planeLength);
828
+ var k = 0;
829
+ for (var i = 0, len = positions.length; i < len; i++) {
830
+ var planePositions = positions[i];
831
+ var nScratch = new Cesium.Cartesian3();
832
+ var n = Cesium.Cartesian3.normalize(Cesium.Cartesian3.cross(planePositions[0], planePositions[planePositions.length - 1], nScratch), nScratch);
833
+ for (var j = 0, _planeLength = planePositions.length - 1; j < _planeLength; j++) {
834
+ vertices[k++] = 0.0;
835
+ vertices[k++] = 0.0;
836
+ vertices[k++] = 0.0;
837
+ vertices[k++] = -n.x;
838
+ vertices[k++] = -n.y;
839
+ vertices[k++] = -n.z;
840
+ vertices[k++] = planePositions[j].x;
841
+ vertices[k++] = planePositions[j].y;
842
+ vertices[k++] = planePositions[j].z;
843
+ vertices[k++] = -n.x;
844
+ vertices[k++] = -n.y;
845
+ vertices[k++] = -n.z;
846
+ vertices[k++] = planePositions[j + 1].x;
847
+ vertices[k++] = planePositions[j + 1].y;
848
+ vertices[k++] = planePositions[j + 1].z;
849
+ vertices[k++] = -n.x;
850
+ vertices[k++] = -n.y;
851
+ vertices[k++] = -n.z;
852
+ }
853
+ }
854
+ var vertexBuffer = Cesium.Buffer.createVertexBuffer({
855
+ context: context,
856
+ typedArray: vertices,
857
+ usage: Cesium.BufferUsage.STATIC_DRAW
858
+ });
859
+ var stride = 2 * 3 * Float32Array.BYTES_PER_ELEMENT;
860
+ var attributes = [{
861
+ index: attributeLocations.position,
862
+ vertexBuffer: vertexBuffer,
863
+ componentsPerAttribute: 3,
864
+ componentDatatype: Cesium.ComponentDatatype.FLOAT,
865
+ offsetInBytes: 0,
866
+ strideInBytes: stride
867
+ }, {
868
+ index: attributeLocations.normal,
869
+ vertexBuffer: vertexBuffer,
870
+ componentsPerAttribute: 3,
871
+ componentDatatype: Cesium.ComponentDatatype.FLOAT,
872
+ offsetInBytes: 3 * Float32Array.BYTES_PER_ELEMENT,
873
+ strideInBytes: stride
874
+ }];
875
+ return new Cesium.VertexArray({
876
+ context: context,
877
+ attributes: attributes
878
+ });
879
+ }
880
+
881
+ /**
882
+ * 创建扇面边线顶点数组
883
+ * @param context: any
884
+ * @param positions: any[]
885
+ * @returns {VertexArray}
886
+ */
887
+ }, {
888
+ key: "createSectorLineVertexArray",
889
+ value: function createSectorLineVertexArray(context, positions) {
890
+ var planeLength = positions.length;
891
+ var vertices = new Float32Array(3 * 3 * planeLength);
892
+ var k = 0;
893
+ for (var i = 0, len = positions.length; i < len; i++) {
894
+ var planePositions = positions[i];
895
+ vertices[k++] = 0.0;
896
+ vertices[k++] = 0.0;
897
+ vertices[k++] = 0.0;
898
+ vertices[k++] = planePositions[0].x;
899
+ vertices[k++] = planePositions[0].y;
900
+ vertices[k++] = planePositions[0].z;
901
+ }
902
+ var vertexBuffer = Cesium.Buffer.createVertexBuffer({
903
+ context: context,
904
+ typedArray: vertices,
905
+ usage: Cesium.BufferUsage.STATIC_DRAW
906
+ });
907
+ var stride = 3 * Float32Array.BYTES_PER_ELEMENT;
908
+ var attributes = [{
909
+ index: attributeLocations.position,
910
+ vertexBuffer: vertexBuffer,
911
+ componentsPerAttribute: 3,
912
+ componentDatatype: Cesium.ComponentDatatype.FLOAT,
913
+ offsetInBytes: 0,
914
+ strideInBytes: stride
915
+ }];
916
+ return new Cesium.VertexArray({
917
+ context: context,
918
+ attributes: attributes
919
+ });
920
+ }
921
+
922
+ /**
923
+ * 创建扇面圆顶面连接线顶点数组
924
+ * @param context: any
925
+ * @param positions: any[]
926
+ * @returns {VertexArray}
927
+ */
928
+ }, {
929
+ key: "createSectorSegmentLineVertexArray",
930
+ value: function createSectorSegmentLineVertexArray(context, positions) {
931
+ var planeLength = Array.prototype.concat.apply([], positions).length - positions.length;
932
+ var vertices = new Float32Array(3 * 3 * planeLength);
933
+ var k = 0;
934
+ for (var i = 0, len = positions.length; i < len; i++) {
935
+ var planePositions = positions[i];
936
+ for (var j = 0, _planeLength2 = planePositions.length - 1; j < _planeLength2; j++) {
937
+ vertices[k++] = planePositions[j].x;
938
+ vertices[k++] = planePositions[j].y;
939
+ vertices[k++] = planePositions[j].z;
940
+ vertices[k++] = planePositions[j + 1].x;
941
+ vertices[k++] = planePositions[j + 1].y;
942
+ vertices[k++] = planePositions[j + 1].z;
943
+ }
944
+ }
945
+ var vertexBuffer = Cesium.Buffer.createVertexBuffer({
946
+ context: context,
947
+ typedArray: vertices,
948
+ usage: Cesium.BufferUsage.STATIC_DRAW
949
+ });
950
+ var stride = 3 * Float32Array.BYTES_PER_ELEMENT;
951
+ var attributes = [{
952
+ index: attributeLocations.position,
953
+ vertexBuffer: vertexBuffer,
954
+ componentsPerAttribute: 3,
955
+ componentDatatype: Cesium.ComponentDatatype.FLOAT,
956
+ offsetInBytes: 0,
957
+ strideInBytes: stride
958
+ }];
959
+ return new Cesium.VertexArray({
960
+ context: context,
961
+ attributes: attributes
962
+ });
963
+ }
964
+ /**
965
+ * 创建圆顶面顶点数组
966
+ * @param context: any
967
+ * @returns {VertexArray}
968
+ */
969
+ }, {
970
+ key: "createDomeVertexArray",
971
+ value: function createDomeVertexArray(context) {
972
+ var geometry = Cesium.EllipsoidGeometry.createGeometry(new Cesium.EllipsoidGeometry({
973
+ vertexFormat: Cesium.VertexFormat.POSITION_ONLY,
974
+ stackPartitions: 32,
975
+ slicePartitions: 32
976
+ }));
977
+ var vertexArray = Cesium.VertexArray.fromGeometry({
978
+ context: context,
979
+ geometry: geometry,
980
+ attributeLocations: attributeLocations,
981
+ bufferUsage: Cesium.BufferUsage.STATIC_DRAW,
982
+ interleave: false
983
+ });
984
+ return vertexArray;
985
+ }
986
+
987
+ /**
988
+ * 创建圆顶面边线顶点数组
989
+ * @param context: any
990
+ * @returns {VertexArray}
991
+ */
992
+ }, {
993
+ key: "createDomeLineVertexArray",
994
+ value: function createDomeLineVertexArray(context) {
995
+ var geometry = Cesium.EllipsoidOutlineGeometry.createGeometry(new Cesium.EllipsoidOutlineGeometry({
996
+ vertexFormat: Cesium.VertexFormat.POSITION_ONLY,
997
+ stackPartitions: 32,
998
+ slicePartitions: 32
999
+ }));
1000
+ var vertexArray = Cesium.VertexArray.fromGeometry({
1001
+ context: context,
1002
+ geometry: geometry,
1003
+ attributeLocations: attributeLocations,
1004
+ bufferUsage: Cesium.BufferUsage.STATIC_DRAW,
1005
+ interleave: false
1006
+ });
1007
+ return vertexArray;
1008
+ }
1009
+ /**
1010
+ * 创建扫描面顶点数组
1011
+ * @param context: any
1012
+ * @param positions: any[]
1013
+ * @returns {VertexArray}
1014
+ */
1015
+ }, {
1016
+ key: "createScanPlaneVertexArray",
1017
+ value: function createScanPlaneVertexArray(context, positions) {
1018
+ var planeLength = positions.length - 1;
1019
+ var vertices = new Float32Array(3 * 3 * planeLength);
1020
+ var k = 0;
1021
+ for (var i = 0; i < planeLength; i++) {
1022
+ vertices[k++] = 0.0;
1023
+ vertices[k++] = 0.0;
1024
+ vertices[k++] = 0.0;
1025
+ vertices[k++] = positions[i].x;
1026
+ vertices[k++] = positions[i].y;
1027
+ vertices[k++] = positions[i].z;
1028
+ vertices[k++] = positions[i + 1].x;
1029
+ vertices[k++] = positions[i + 1].y;
1030
+ vertices[k++] = positions[i + 1].z;
1031
+ }
1032
+ var vertexBuffer = Cesium.Buffer.createVertexBuffer({
1033
+ context: context,
1034
+ typedArray: vertices,
1035
+ usage: Cesium.BufferUsage.STATIC_DRAW
1036
+ });
1037
+ var stride = 3 * Float32Array.BYTES_PER_ELEMENT;
1038
+ var attributes = [{
1039
+ index: attributeLocations.position,
1040
+ vertexBuffer: vertexBuffer,
1041
+ componentsPerAttribute: 3,
1042
+ componentDatatype: Cesium.ComponentDatatype.FLOAT,
1043
+ offsetInBytes: 0,
1044
+ strideInBytes: stride
1045
+ }];
1046
+ return new Cesium.VertexArray({
1047
+ context: context,
1048
+ attributes: attributes
1049
+ });
1050
+ }
1051
+ /**
1052
+ * 创建通用着色器程序
1053
+ * @param primitive: any
1054
+ * @param frameState: any
1055
+ * @param material: any
1056
+ * @returns {ShaderProgram}
1057
+ */
1058
+ }, {
1059
+ key: "createCommonShaderProgram",
1060
+ value: function createCommonShaderProgram(primitive, frameState, material) {
1061
+ var context = frameState.context;
1062
+ var vs = sensorVS;
1063
+ var fs = new Cesium.ShaderSource({
1064
+ sources: [sensorComm, material.shaderSource, sensorFS]
1065
+ });
1066
+ primitive._sp = Cesium.ShaderProgram.replaceCache({
1067
+ context: context,
1068
+ shaderProgram: primitive._sp,
1069
+ vertexShaderSource: vs,
1070
+ fragmentShaderSource: fs,
1071
+ attributeLocations: attributeLocations
1072
+ });
1073
+ var pickFS = new Cesium.ShaderSource({
1074
+ sources: [sensorComm, material.shaderSource, sensorFS],
1075
+ pickColorQualifier: 'uniform'
1076
+ });
1077
+ primitive._pickSP = Cesium.ShaderProgram.replaceCache({
1078
+ context: context,
1079
+ shaderProgram: primitive._pickSP,
1080
+ vertexShaderSource: vs,
1081
+ fragmentShaderSource: pickFS,
1082
+ attributeLocations: attributeLocations
1083
+ });
1084
+ }
1085
+
1086
+ /**
1087
+ * 创建扫描面着色器程序
1088
+ * @param primitive: any
1089
+ * @param frameState: any
1090
+ * @param material: any
1091
+ * @returns {ShaderProgram}
1092
+ */
1093
+ }, {
1094
+ key: "createScanPlaneShaderProgram",
1095
+ value: function createScanPlaneShaderProgram(primitive, frameState, material) {
1096
+ var context = frameState.context;
1097
+ var vs = sensorVS;
1098
+ var fs = new Cesium.ShaderSource({
1099
+ sources: [sensorComm, material.shaderSource, scanPlaneFS]
1100
+ });
1101
+ primitive._scanePlaneSP = Cesium.ShaderProgram.replaceCache({
1102
+ context: context,
1103
+ shaderProgram: primitive._scanePlaneSP,
1104
+ vertexShaderSource: vs,
1105
+ fragmentShaderSource: fs,
1106
+ attributeLocations: attributeLocations
1107
+ });
1108
+ }
1109
+ /**
1110
+ * 创建命令
1111
+ * @param primitive: any
1112
+ * @param frontCommand: any
1113
+ * @param backCommand: any
1114
+ * @param frontFaceRS: any
1115
+ * @param backFaceRS: any
1116
+ * @param sp: any
1117
+ * @param va: any
1118
+ * @param uniforms: any
1119
+ * @param modelMatrix: any
1120
+ * @param translucent: any
1121
+ * @param pass: any
1122
+ * @param isLine: any
1123
+ * @returns {any}
1124
+ */
1125
+ }, {
1126
+ key: "createCommand",
1127
+ value: function createCommand(primitive, frontCommand, backCommand, frontFaceRS, backFaceRS, sp, va, uniforms, modelMatrix, translucent, pass, isLine) {
1128
+ if (translucent && backCommand) {
1129
+ backCommand.vertexArray = va;
1130
+ backCommand.renderState = backFaceRS;
1131
+ backCommand.shaderProgram = sp;
1132
+ backCommand.uniformMap = Cesium.combine(uniforms, primitive._material._uniforms);
1133
+ backCommand.uniformMap.u_normalDirection = function () {
1134
+ return -1.0;
1135
+ };
1136
+ backCommand.pass = pass;
1137
+ backCommand.modelMatrix = modelMatrix;
1138
+ primitive._colorCommands.push(backCommand);
1139
+ }
1140
+ frontCommand.vertexArray = va;
1141
+ frontCommand.renderState = frontFaceRS;
1142
+ frontCommand.shaderProgram = sp;
1143
+ frontCommand.uniformMap = Cesium.combine(uniforms, primitive._material._uniforms);
1144
+ if (isLine) {
1145
+ frontCommand.uniformMap.u_type = function () {
1146
+ return 1;
1147
+ };
1148
+ }
1149
+ frontCommand.pass = pass;
1150
+ frontCommand.modelMatrix = modelMatrix;
1151
+ primitive._colorCommands.push(frontCommand);
1152
+ }
1153
+ /**
1154
+ * 销毁对象,清理所有资源
1155
+ */
1156
+ }, {
1157
+ key: "destroy",
1158
+ value: function destroy() {
1159
+ // 清理顶点数组
1160
+ if (this._sectorVA) {
1161
+ this._sectorVA.destroy();
1162
+ this._sectorVA = undefined;
1163
+ }
1164
+ if (this._sectorLineVA) {
1165
+ this._sectorLineVA.destroy();
1166
+ this._sectorLineVA = undefined;
1167
+ }
1168
+ if (this._sectorSegmentLineVA) {
1169
+ this._sectorSegmentLineVA.destroy();
1170
+ this._sectorSegmentLineVA = undefined;
1171
+ }
1172
+ if (this._domeVA) {
1173
+ this._domeVA.destroy();
1174
+ this._domeVA = undefined;
1175
+ }
1176
+ if (this._domeLineVA) {
1177
+ this._domeLineVA.destroy();
1178
+ this._domeLineVA = undefined;
1179
+ }
1180
+ if (this._scanPlaneVA) {
1181
+ this._scanPlaneVA.destroy();
1182
+ this._scanPlaneVA = undefined;
1183
+ }
1184
+
1185
+ // 清理着色器程序
1186
+ if (this._sp) {
1187
+ this._sp.destroy();
1188
+ this._sp = undefined;
1189
+ }
1190
+ if (this._pickSP) {
1191
+ this._pickSP.destroy();
1192
+ this._pickSP = undefined;
1193
+ }
1194
+ if (this._scanePlaneSP) {
1195
+ this._scanePlaneSP.destroy();
1196
+ this._scanePlaneSP = undefined;
1197
+ }
1198
+
1199
+ // 清理渲染状态
1200
+ if (this._frontFaceRS) {
1201
+ this._frontFaceRS = undefined;
1202
+ }
1203
+ if (this._backFaceRS) {
1204
+ this._backFaceRS = undefined;
1205
+ }
1206
+ if (this._pickRS) {
1207
+ this._pickRS = undefined;
1208
+ }
1209
+
1210
+ // 清理命令
1211
+ this._colorCommands.length = 0;
1212
+
1213
+ // 清理材质
1214
+ if (this._material) {
1215
+ this._material = undefined;
1216
+ }
1217
+ if (this.lateralSurfaceMaterial) {
1218
+ this.lateralSurfaceMaterial = undefined;
1219
+ }
1220
+ if (this.domeSurfaceMaterial) {
1221
+ this.domeSurfaceMaterial = undefined;
1222
+ }
1223
+
1224
+ // 清理矩阵
1225
+ if (this._modelMatrix) {
1226
+ this._modelMatrix = undefined;
1227
+ }
1228
+ if (this._computedModelMatrix) {
1229
+ this._computedModelMatrix = undefined;
1230
+ }
1231
+ if (this._computedScanPlaneModelMatrix) {
1232
+ this._computedScanPlaneModelMatrix = undefined;
1233
+ }
1234
+
1235
+ // 清理边界球
1236
+ if (this._boundingSphere) {
1237
+ this._boundingSphere = undefined;
1238
+ }
1239
+ if (this._boundingSphereWC) {
1240
+ this._boundingSphereWC = undefined;
1241
+ }
1242
+
1243
+ // 清理命令对象
1244
+ this._sectorFrontCommand = undefined;
1245
+ this._sectorBackCommand = undefined;
1246
+ this._sectorLineCommand = undefined;
1247
+ this._sectorSegmentLineCommand = undefined;
1248
+ this._domeFrontCommand = undefined;
1249
+ this._domeBackCommand = undefined;
1250
+ this._domeLineCommand = undefined;
1251
+ this._scanPlaneFrontCommand = undefined;
1252
+ this._scanPlaneBackCommand = undefined;
1253
+ this._scanRadialCommand = undefined;
1254
+
1255
+ // 清理uniforms
1256
+ this._uniforms = undefined;
1257
+ this._scanUniforms = undefined;
1258
+
1259
+ // 标记为已销毁
1260
+ this.show = false;
1261
+ return Cesium.destroyObject(this);
1262
+ }
1263
+ }, {
1264
+ key: "isDestroyed",
1265
+ value: function isDestroyed() {
1266
+ return false;
1267
+ }
1268
+ }]);
1269
+ return RectangularSensorPrimitive;
1270
+ }();
1271
+ export default RectangularSensorPrimitive;