deeptwins-engine-3d 0.1.47 → 0.1.48
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/esm/analyze/ViewshedAnalysis.js +3 -2
- package/dist/esm/constant.d.ts +11 -0
- package/dist/esm/constant.js +24 -0
- package/dist/esm/graphicLayer/BaseLayer.js +3 -0
- package/dist/esm/graphicLayer/BaseSource.d.ts +1 -1
- package/dist/esm/graphicLayer/PolygonPrimitive.js +6 -4
- package/dist/esm/graphicLayer/PolygonPrimitiveImageMaterialInstance.d.ts +5 -0
- package/dist/esm/graphicLayer/PolygonPrimitiveImageMaterialInstance.js +75 -0
- package/dist/esm/graphicLayer/PolygonPrimitiveInstance.d.ts +1 -1
- package/dist/esm/graphicLayer/PolygonPrimitiveInstance.js +8 -23
- package/dist/esm/index.d.ts +1 -1
- package/dist/esm/index.js +4 -4
- package/dist/esm/material/primitive/BaseMaterialAppearance.d.ts +1 -0
- package/dist/esm/material/primitive/BaseMaterialAppearance.js +1 -0
- package/dist/esm/material/primitive/ImageMaterialAppearance.d.ts +10 -0
- package/dist/esm/material/primitive/ImageMaterialAppearance.js +77 -0
- package/dist/esm/material/shader/ImageShader.glsl +22 -0
- package/dist/esm/tool/utils.d.ts +10 -1
- package/dist/esm/tool/utils.js +90 -44
- package/dist/esm/videoFusion/VideoProject.js +1 -1
- package/dist/esm/visualization/Frustum.d.ts +27 -2
- package/dist/esm/visualization/Frustum.js +158 -42
- package/dist/umd/deeptwins-engine-3d.min.js +1 -1
- package/package.json +7 -4
- package/dist/esm/visualization/BaseFrustum.d.ts +0 -14
- package/dist/esm/visualization/BaseFrustum.js +0 -96
- package/dist/esm/visualization/FrustumWithCamera.d.ts +0 -5
- package/dist/esm/visualization/FrustumWithCamera.js +0 -133
package/dist/esm/tool/utils.js
CHANGED
|
@@ -320,6 +320,41 @@ export function error(message) {
|
|
|
320
320
|
console.error("[DeepTwinsEngine3d error]: ".concat(message));
|
|
321
321
|
}
|
|
322
322
|
|
|
323
|
+
/**
|
|
324
|
+
* 去除 Polygon ring 的闭合点(首尾重复)
|
|
325
|
+
*/
|
|
326
|
+
export function normalizeRing(ring) {
|
|
327
|
+
var _ring$slice;
|
|
328
|
+
if (!ring || ring.length < 3) return (_ring$slice = ring === null || ring === void 0 ? void 0 : ring.slice()) !== null && _ring$slice !== void 0 ? _ring$slice : [];
|
|
329
|
+
var first = ring[0];
|
|
330
|
+
var last = ring[ring.length - 1];
|
|
331
|
+
if (Cesium.Cartesian3.equals(first, last)) {
|
|
332
|
+
return ring.slice(0, -1);
|
|
333
|
+
}
|
|
334
|
+
return ring.slice();
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
/**
|
|
338
|
+
* 构建 Cesium 安全的 PolygonHierarchy
|
|
339
|
+
* 支持闭合 / 非闭合 / holes
|
|
340
|
+
*/
|
|
341
|
+
export function buildPolygonHierarchy(positions) {
|
|
342
|
+
var holes = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
|
|
343
|
+
var outer = normalizeRing(positions);
|
|
344
|
+
if (outer.length < 3) {
|
|
345
|
+
throw new Error('Polygon 外环至少需要 3 个不同的点');
|
|
346
|
+
}
|
|
347
|
+
var holeHierarchies = holes.map(function (h, i) {
|
|
348
|
+
var ring = normalizeRing(h);
|
|
349
|
+
if (ring.length < 3) {
|
|
350
|
+
console.warn("Polygon hole ".concat(i, " \u9876\u70B9\u4E0D\u8DB3\uFF0C\u5DF2\u5FFD\u7565"));
|
|
351
|
+
return null;
|
|
352
|
+
}
|
|
353
|
+
return new Cesium.PolygonHierarchy(ring);
|
|
354
|
+
}).filter(Boolean);
|
|
355
|
+
return new Cesium.PolygonHierarchy(outer, holeHierarchies);
|
|
356
|
+
}
|
|
357
|
+
|
|
323
358
|
/**
|
|
324
359
|
* 沿多边形平面局部坐标系计算 ST
|
|
325
360
|
* @param positions Cartesian3[] 多边形顶点
|
|
@@ -328,36 +363,56 @@ export function error(message) {
|
|
|
328
363
|
*/
|
|
329
364
|
export function computeSTAlongPlane(positions) {
|
|
330
365
|
var rotation = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
|
|
331
|
-
|
|
332
|
-
var
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
var
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
var
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
366
|
+
// 1️⃣ 去闭合
|
|
367
|
+
var ring = buildPolygonHierarchy(positions).positions;
|
|
368
|
+
var count = ring.length;
|
|
369
|
+
var center = Cesium.BoundingSphere.fromPoints(ring).center;
|
|
370
|
+
|
|
371
|
+
// 2️⃣ 官方切平面(稳定)
|
|
372
|
+
var tangentPlane = new Cesium.EllipsoidTangentPlane(center, Cesium.Ellipsoid.WGS84);
|
|
373
|
+
|
|
374
|
+
// 3️⃣ 投影到 2D
|
|
375
|
+
var pts2D = ring.map(function (p) {
|
|
376
|
+
return tangentPlane.projectPointOntoPlane(p);
|
|
377
|
+
});
|
|
378
|
+
|
|
379
|
+
// 4️⃣ 计算 2D 中心
|
|
380
|
+
var cx = 0,
|
|
381
|
+
cy = 0;
|
|
382
|
+
pts2D.forEach(function (p) {
|
|
383
|
+
cx += p.x;
|
|
384
|
+
cy += p.y;
|
|
385
|
+
});
|
|
386
|
+
cx /= count;
|
|
387
|
+
cy /= count;
|
|
388
|
+
|
|
389
|
+
// 5️⃣ PCA 求主方向(S 轴)
|
|
390
|
+
var xx = 0,
|
|
391
|
+
xy = 0,
|
|
392
|
+
yy = 0;
|
|
393
|
+
pts2D.forEach(function (p) {
|
|
394
|
+
var dx = p.x - cx;
|
|
395
|
+
var dy = p.y - cy;
|
|
396
|
+
xx += dx * dx;
|
|
397
|
+
xy += dx * dy;
|
|
398
|
+
yy += dy * dy;
|
|
399
|
+
});
|
|
400
|
+
var theta = 0.5 * Math.atan2(2 * xy, xx - yy);
|
|
401
|
+
var cosT = Math.cos(theta + rotation);
|
|
402
|
+
var sinT = Math.sin(theta + rotation);
|
|
403
|
+
|
|
404
|
+
// 6️⃣ 投影到主轴坐标系
|
|
351
405
|
var minS = Infinity,
|
|
352
406
|
maxS = -Infinity,
|
|
353
407
|
minT = Infinity,
|
|
354
408
|
maxT = -Infinity;
|
|
355
|
-
var
|
|
356
|
-
|
|
357
|
-
var
|
|
358
|
-
var
|
|
359
|
-
var
|
|
360
|
-
|
|
409
|
+
var local = [];
|
|
410
|
+
pts2D.forEach(function (p) {
|
|
411
|
+
var dx = p.x - cx;
|
|
412
|
+
var dy = p.y - cy;
|
|
413
|
+
var s = dx * cosT + dy * sinT;
|
|
414
|
+
var t = -dx * sinT + dy * cosT;
|
|
415
|
+
local.push({
|
|
361
416
|
s: s,
|
|
362
417
|
t: t
|
|
363
418
|
});
|
|
@@ -366,25 +421,16 @@ export function computeSTAlongPlane(positions) {
|
|
|
366
421
|
minT = Math.min(minT, t);
|
|
367
422
|
maxT = Math.max(maxT, t);
|
|
368
423
|
});
|
|
369
|
-
var rangeS = maxS - minS || 1
|
|
370
|
-
var rangeT = maxT - minT || 1
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
var t = (pt.t - minT) / rangeT;
|
|
378
|
-
|
|
379
|
-
// 旋转 around center (0.5,0.5)
|
|
380
|
-
var s0 = s - 0.5;
|
|
381
|
-
var t0 = t - 0.5;
|
|
382
|
-
s = s0 * cosA - t0 * sinA + 0.5;
|
|
383
|
-
t = s0 * sinA + t0 * cosA + 0.5;
|
|
384
|
-
stValues[i * 2] = s;
|
|
385
|
-
stValues[i * 2 + 1] = t;
|
|
424
|
+
var rangeS = maxS - minS || 1;
|
|
425
|
+
var rangeT = maxT - minT || 1;
|
|
426
|
+
|
|
427
|
+
// 7️⃣ 归一化
|
|
428
|
+
var st = new Float32Array(count * 2);
|
|
429
|
+
local.forEach(function (p, i) {
|
|
430
|
+
st[i * 2] = (p.s - minS) / rangeS;
|
|
431
|
+
st[i * 2 + 1] = (p.t - minT) / rangeT;
|
|
386
432
|
});
|
|
387
|
-
return
|
|
433
|
+
return st;
|
|
388
434
|
}
|
|
389
435
|
|
|
390
436
|
// 计算两点的中心点
|
|
@@ -71,7 +71,7 @@ var VideoProject = /*#__PURE__*/function (_BaseVideo) {
|
|
|
71
71
|
_this2.type = type;
|
|
72
72
|
_this2.frustum = frustum;
|
|
73
73
|
// 取后4个点
|
|
74
|
-
var points = _this2.frustum.
|
|
74
|
+
var points = _this2.frustum.getFarPlane();
|
|
75
75
|
if (_this2.type === 'projection') {
|
|
76
76
|
// 交点数组
|
|
77
77
|
var interPoints = [];
|
|
@@ -1,5 +1,30 @@
|
|
|
1
|
-
import
|
|
2
|
-
export default class Frustum
|
|
1
|
+
import { MapContext } from "../map/Map";
|
|
2
|
+
export default class Frustum {
|
|
3
|
+
_mapContext: MapContext | undefined;
|
|
4
|
+
options: any;
|
|
5
|
+
frustumPrimitive: any;
|
|
6
|
+
frustumLinePrimitive: any;
|
|
7
|
+
isDestroyed: boolean;
|
|
3
8
|
constructor(map: any, options: any);
|
|
9
|
+
getMap(): any;
|
|
10
|
+
private _canOperate;
|
|
4
11
|
private _addFrustum;
|
|
12
|
+
/**
|
|
13
|
+
* 获取视锥体投影面的顶点坐标
|
|
14
|
+
* @param type 投影面类型: 'near'(近裁剪面) 或 'far'(远裁剪面)
|
|
15
|
+
* @returns 投影面的4个顶点坐标数组 [[lng, lat, alt], ...]
|
|
16
|
+
*/
|
|
17
|
+
getProjectionPlane(type?: 'near' | 'far'): any;
|
|
18
|
+
/**
|
|
19
|
+
* 获取近裁剪面的顶点坐标
|
|
20
|
+
* @returns 近裁剪面的4个顶点坐标数组
|
|
21
|
+
*/
|
|
22
|
+
getNearPlane(): any;
|
|
23
|
+
/**
|
|
24
|
+
* 获取远裁剪面的顶点坐标
|
|
25
|
+
* @returns 远裁剪面的4个顶点坐标数组
|
|
26
|
+
*/
|
|
27
|
+
getFarPlane(): any;
|
|
28
|
+
show(isShow: boolean): void;
|
|
29
|
+
destroy(): void;
|
|
5
30
|
}
|
|
@@ -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 (
|
|
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
|
-
|
|
33
|
-
|
|
34
|
-
|
|
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
|
-
|
|
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
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
_this$options$
|
|
61
|
-
|
|
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
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
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) :
|
|
98
|
+
fov: fov ? utils.toRadians(fov) : camera.frustum.fov,
|
|
77
99
|
// 视锥体的宽度/高度
|
|
78
|
-
aspectRatio: aspectRatio ? aspectRatio :
|
|
100
|
+
aspectRatio: aspectRatio ? aspectRatio : camera.frustum.aspectRatio,
|
|
79
101
|
// 近面距视点的距离
|
|
80
|
-
near: near ? near :
|
|
102
|
+
near: near ? near : camera.frustum.near,
|
|
81
103
|
// 远面距视点的距离
|
|
82
|
-
far: far ? 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:
|
|
90
|
-
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:
|
|
113
|
-
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
|
-
}(
|
|
247
|
+
}();
|
|
132
248
|
export { Frustum as default };
|