@lijuhong1981/cesium.utils 0.0.0-stage → 0.1.0

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 (99) hide show
  1. package/README.md +62 -2
  2. package/package.json +33 -4
  3. package/src/additions/Geographic.js +603 -0
  4. package/src/additions/GeographicTransform.js +291 -0
  5. package/src/additions/GeometryInstanceAttributes.js +164 -0
  6. package/src/additions/ModelMatrixTransforms.js +822 -0
  7. package/src/additions/PropertyChangedListener.js +72 -0
  8. package/src/additions/PropertyType.js +30 -0
  9. package/src/additions/StTransforms.js +266 -0
  10. package/src/additions/TranslationRotationScaleTransform.js +809 -0
  11. package/src/additions/index.js +8 -0
  12. package/src/index.js +4 -0
  13. package/src/parses/index.js +46 -0
  14. package/src/parses/parseAltitude.js +32 -0
  15. package/src/parses/parseArcType.js +26 -0
  16. package/src/parses/parseAttitudeToHeadingPitchRoll.js +26 -0
  17. package/src/parses/parseAttitudeToMatrix3.js +17 -0
  18. package/src/parses/parseAttitudeToQuaternion.js +21 -0
  19. package/src/parses/parseCartographicToCartesian.js +21 -0
  20. package/src/parses/parseCartographicsToPositions.js +20 -0
  21. package/src/parses/parseClassificationType.js +24 -0
  22. package/src/parses/parseClockRange.js +26 -0
  23. package/src/parses/parseColorBlendMode.js +26 -0
  24. package/src/parses/parseCornerType.js +24 -0
  25. package/src/parses/parseCullFace.js +28 -0
  26. package/src/parses/parseEulerToHeadingPitchRoll.js +21 -0
  27. package/src/parses/parseEulerToQuaternion.js +18 -0
  28. package/src/parses/parseGeographicToCartesian.js +21 -0
  29. package/src/parses/parseGeographicsToPositions.js +20 -0
  30. package/src/parses/parseHeading.js +28 -0
  31. package/src/parses/parseHeightReference.js +24 -0
  32. package/src/parses/parseHorizontalOrigin.js +26 -0
  33. package/src/parses/parseLabelStyle.js +26 -0
  34. package/src/parses/parseLatitude.js +28 -0
  35. package/src/parses/parseLongitude.js +28 -0
  36. package/src/parses/parsePitch.js +26 -0
  37. package/src/parses/parseRoll.js +26 -0
  38. package/src/parses/parseRotationToHeadingPitchRoll.js +40 -0
  39. package/src/parses/parseRotationToMatrix3.js +25 -0
  40. package/src/parses/parseRotationToQuaternion.js +27 -0
  41. package/src/parses/parseShadowMode.js +26 -0
  42. package/src/parses/parseToBoundingRectangle.js +33 -0
  43. package/src/parses/parseToCartesian2.js +35 -0
  44. package/src/parses/parseToCartesian3.js +37 -0
  45. package/src/parses/parseToCartesian3Array.js +21 -0
  46. package/src/parses/parseToCartesian4.js +39 -0
  47. package/src/parses/parseToCartographic.js +31 -0
  48. package/src/parses/parseToColor.js +33 -0
  49. package/src/parses/parseToDistanceDisplayCondition.js +41 -0
  50. package/src/parses/parseToGeographic.js +31 -0
  51. package/src/parses/parseToHeadingPitchRange.js +45 -0
  52. package/src/parses/parseToJulianDate.js +23 -0
  53. package/src/parses/parseToNearFarScalar.js +33 -0
  54. package/src/parses/parseToPlane.js +37 -0
  55. package/src/parses/parseToPolygonHierarchy.js +48 -0
  56. package/src/parses/parseToRange.js +26 -0
  57. package/src/parses/parseToRectangle.js +32 -0
  58. package/src/parses/parseToTimeInterval.js +45 -0
  59. package/src/parses/parseVerticalOrigin.js +28 -0
  60. package/src/revisions/BoundingSphere.revise.js +107 -0
  61. package/src/revisions/Camera.revise.js +366 -0
  62. package/src/revisions/Cartesian.revise.js +313 -0
  63. package/src/revisions/Cartographic.revise.js +443 -0
  64. package/src/revisions/Check.revise.js +164 -0
  65. package/src/revisions/Color.revise.js +271 -0
  66. package/src/revisions/DistanceDisplayCondition.revise.js +37 -0
  67. package/src/revisions/Ellipsoid.revise.js +64 -0
  68. package/src/revisions/Geometry.revise.js +79 -0
  69. package/src/revisions/Globe.revise.js +92 -0
  70. package/src/revisions/HeadingPitchRoll.revise.js +328 -0
  71. package/src/revisions/JulianDate.revise.js +28 -0
  72. package/src/revisions/Material.revise.js +308 -0
  73. package/src/revisions/Math.revise.js +98 -0
  74. package/src/revisions/Matrix.revise.js +578 -0
  75. package/src/revisions/POI.revise.js +178 -0
  76. package/src/revisions/Plane.revise.js +43 -0
  77. package/src/revisions/PolylinePipeline.revise.js +54 -0
  78. package/src/revisions/PostProcessStageLibrary.revise.js +1143 -0
  79. package/src/revisions/Primitive.revise.js +83 -0
  80. package/src/revisions/Property.revise.js +37 -0
  81. package/src/revisions/Quaternion.revise.js +66 -0
  82. package/src/revisions/Rectangle.revise.js +570 -0
  83. package/src/revisions/SceneTransforms.revise.js +82 -0
  84. package/src/revisions/Spherical.revise.js +35 -0
  85. package/src/revisions/index.js +25 -0
  86. package/src/utils/Scratch.js +165 -0
  87. package/src/utils/computeCirclePositions.js +48 -0
  88. package/src/utils/computeCircleRadius.js +19 -0
  89. package/src/utils/computeModelMatrix.js +109 -0
  90. package/src/utils/computeStTransform.js +57 -0
  91. package/src/utils/createGeometry.js +114 -0
  92. package/src/utils/createPointCloudGeometry.js +79 -0
  93. package/src/utils/getGeometryInstanceAttributes.js +43 -0
  94. package/src/utils/getPositionFromTarget.js +29 -0
  95. package/src/utils/getRenderState.js +35 -0
  96. package/src/utils/index.js +13 -0
  97. package/src/utils/isColorMaterial.js +13 -0
  98. package/src/utils/isTranslucent.js +13 -0
  99. package/src/utils/resolveModelMatrixByFixedFrame.js +30 -0
@@ -0,0 +1,178 @@
1
+ import { Billboard, BillboardCollection, BoundingSphere, BoundingSphereState, Check, Label, LabelCollection, PointPrimitive, PointPrimitiveCollection } from "cesium";
2
+
3
+ /**
4
+ * 扩展 Cesium 的 Billboard 类,补充类型标识与从集合移除的便捷方法。
5
+ * @class Billboard
6
+ * @see {@link https://cesium.com/learn/cesiumjs/ref-doc/Billboard.html}
7
+ */
8
+ /**
9
+ * 扩展 Cesium 的 BillboardCollection 类,补充计算包围球的方法。
10
+ * @class BillboardCollection
11
+ * @see {@link https://cesium.com/learn/cesiumjs/ref-doc/BillboardCollection.html}
12
+ */
13
+ /**
14
+ * 扩展 Cesium 的 Label 类,补充类型标识与从集合移除的便捷方法。
15
+ * @class Label
16
+ * @see {@link https://cesium.com/learn/cesiumjs/ref-doc/Label.html}
17
+ */
18
+ /**
19
+ * 扩展 Cesium 的 LabelCollection 类,补充计算包围球的方法。
20
+ * @class LabelCollection
21
+ * @see {@link https://cesium.com/learn/cesiumjs/ref-doc/LabelCollection.html}
22
+ */
23
+ /**
24
+ * 扩展 Cesium 的 PointPrimitive 类,补充类型标识与从集合移除的便捷方法。
25
+ * @class PointPrimitive
26
+ * @see {@link https://cesium.com/learn/cesiumjs/ref-doc/PointPrimitive.html}
27
+ */
28
+ /**
29
+ * 扩展 Cesium 的 PointPrimitiveCollection 类,补充计算包围球的方法。
30
+ * @class PointPrimitiveCollection
31
+ * @see {@link https://cesium.com/learn/cesiumjs/ref-doc/PointPrimitiveCollection.html}
32
+ */
33
+
34
+ /**
35
+ * Billboard 实例的 isBillboard 标识属性,值恒为 true。
36
+ * @name isBillboard
37
+ * @type {boolean}
38
+ * @memberof Billboard
39
+ */
40
+ Object.defineProperties(Billboard.prototype, {
41
+ isBillboard: {
42
+ writable: false,
43
+ configurable: false,
44
+ value: true,
45
+ }
46
+ });
47
+
48
+ /**
49
+ * 将当前 Billboard 从其所属的 BillboardCollection 中移除。
50
+ * @memberof Billboard
51
+ */
52
+ Billboard.prototype._removeFromCollection = function () {
53
+ if (this._billboardCollection)
54
+ this._billboardCollection.remove(this);
55
+ };
56
+
57
+ /**
58
+ * 计算 BillboardCollection 的包围球。
59
+ * @param {boolean} [allowPartial=false] 是否允许仅使用部分已就绪的图元计算包围球。
60
+ * @param {BoundingSphere} result 用于存储包围球的对象。
61
+ * @returns {BoundingSphereState} 包围球的计算状态。
62
+ * @memberof BillboardCollection
63
+ */
64
+ BillboardCollection.prototype.getBoundingSphere = function (allowPartial = false, result) {
65
+ Check.defined('result', result);
66
+
67
+ const length = this.length;
68
+ if (length === 0)
69
+ return BoundingSphereState.FAILED;
70
+
71
+ const boundingSpheres = [];
72
+ for (let i = length - 1; i >= 0; i--) {
73
+ const billboard = this.get(i);
74
+ boundingSpheres[i] = new BoundingSphere(billboard.position);
75
+ }
76
+
77
+ BoundingSphere.fromBoundingSpheres(boundingSpheres, result);
78
+ // console.log('getBoundingSphere:', this.id, result);
79
+ return BoundingSphereState.DONE;
80
+ };
81
+
82
+ /**
83
+ * Label 实例的 isLabel 标识属性,值恒为 true。
84
+ * @name isLabel
85
+ * @type {boolean}
86
+ * @memberof Label
87
+ */
88
+ Object.defineProperties(Label.prototype, {
89
+ isLabel: {
90
+ writable: false,
91
+ configurable: false,
92
+ value: true,
93
+ }
94
+ });
95
+
96
+ /**
97
+ * 将当前 Label 从其所属的 LabelCollection 中移除。
98
+ * @memberof Label
99
+ */
100
+ Label.prototype._removeFromCollection = function () {
101
+ if (this._labelCollection)
102
+ this._labelCollection.remove(this);
103
+ };
104
+
105
+ /**
106
+ * 计算 LabelCollection 的包围球。
107
+ * @param {boolean} [allowPartial=false] 是否允许仅使用部分已就绪的图元计算包围球。
108
+ * @param {BoundingSphere} result 用于存储包围球的对象。
109
+ * @returns {BoundingSphereState} 包围球的计算状态。
110
+ * @memberof LabelCollection
111
+ */
112
+ LabelCollection.prototype.getBoundingSphere = function (allowPartial = false, result) {
113
+ Check.defined('result', result);
114
+
115
+ const length = this.length;
116
+ if (length === 0)
117
+ return BoundingSphereState.FAILED;
118
+
119
+ const boundingSpheres = [];
120
+ for (let i = length - 1; i >= 0; i--) {
121
+ const label = this.get(i);
122
+ boundingSpheres[i] = new BoundingSphere(label.position);
123
+ }
124
+
125
+ BoundingSphere.fromBoundingSpheres(boundingSpheres, result);
126
+ // console.log('getBoundingSphere:', this.id, result);
127
+ return BoundingSphereState.DONE;
128
+ };
129
+
130
+ /**
131
+ * PointPrimitive 实例的 isPointPrimitive 标识属性,值恒为 true。
132
+ * @name isPointPrimitive
133
+ * @type {boolean}
134
+ * @memberof PointPrimitive
135
+ */
136
+ Object.defineProperties(PointPrimitive.prototype, {
137
+ isPointPrimitive: {
138
+ writable: false,
139
+ configurable: true,
140
+ value: true,
141
+ }
142
+ });
143
+
144
+ /**
145
+ * 将当前 PointPrimitive 从其所属的 PointPrimitiveCollection 中移除。
146
+ * @memberof PointPrimitive
147
+ */
148
+ PointPrimitive.prototype._removeFromCollection = function () {
149
+ if (this._pointPrimitiveCollection)
150
+ this._pointPrimitiveCollection.remove(this);
151
+ };
152
+
153
+ /**
154
+ * 计算 PointPrimitiveCollection 的包围球。
155
+ * @param {boolean} [allowPartial=false] 是否允许仅使用部分已就绪的图元计算包围球。
156
+ * @param {BoundingSphere} result 用于存储包围球的对象。
157
+ * @returns {BoundingSphereState} 包围球的计算状态。
158
+ * @memberof PointPrimitiveCollection
159
+ */
160
+ PointPrimitiveCollection.prototype.getBoundingSphere = function (allowPartial = false, result) {
161
+ Check.defined('result', result);
162
+
163
+ const length = this.length;
164
+ if (length === 0)
165
+ return BoundingSphereState.FAILED;
166
+
167
+ const boundingSpheres = [];
168
+ for (let i = length - 1; i >= 0; i--) {
169
+ const point = this.get(i);
170
+ boundingSpheres[i] = new BoundingSphere(point.position);
171
+ }
172
+
173
+ BoundingSphere.fromBoundingSpheres(boundingSpheres, result);
174
+ // console.log('getBoundingSphere:', this.id, result);
175
+ return BoundingSphereState.DONE;
176
+ };
177
+
178
+ export { Billboard, BillboardCollection, Label, LabelCollection, PointPrimitive, PointPrimitiveCollection };
@@ -0,0 +1,43 @@
1
+ import { Cartesian3, Plane } from "cesium";
2
+ import Scratch from "../utils/Scratch.js";
3
+
4
+ /**
5
+ * 扩展 Cesium 的 Plane 类,补充通过共面点创建平面、克隆等方法。
6
+ * @class Plane
7
+ * @see {@link https://cesium.com/learn/cesiumjs/ref-doc/Plane.html}
8
+ */
9
+
10
+ /**
11
+ * 通过三个共面点创建平面。
12
+ * @param {Cartesian3} a 平面上第一个点。
13
+ * @param {Cartesian3} b 平面上第二个点。
14
+ * @param {Cartesian3} c 平面上第三个点。
15
+ * @param {Plane} [result] 用于存储结果的可选对象。
16
+ * @returns {Plane} 生成的平面。
17
+ * @memberof Plane
18
+ * @static
19
+ */
20
+ Plane.fromCoplanarPoints = function (a, b, c, result) {
21
+
22
+ // from threejs
23
+ // const normal = _vector1.subVectors(c, b).cross(_vector2.subVectors(a, b)).normalize();
24
+ const vectorA = Cartesian3.subtract(c, b, Scratch.scratchLeftCartesian3);
25
+ const vectorB = Cartesian3.subtract(a, b, Scratch.scratchRightCartesian3);
26
+ const normal = Cartesian3.cross(vectorA, vectorB, Scratch.scratchNormal);
27
+ normal.normalize();
28
+
29
+ return Plane.fromPointNormal(a, normal, result);
30
+ };
31
+
32
+ /**
33
+ * 克隆当前平面。
34
+ * @param {Plane} [result] 用于存储结果的可选对象。
35
+ * @returns {Plane} 克隆得到的平面。
36
+ * @memberof Plane
37
+ */
38
+ Plane.prototype.clone = function (result) {
39
+ return Plane.clone(this, result);
40
+ };
41
+
42
+ export default Plane;
43
+ export { Plane };
@@ -0,0 +1,54 @@
1
+ import { Cartesian3, Check, PolylinePipeline } from "cesium";
2
+
3
+ /**
4
+ * 扩展 Cesium 的 PolylinePipeline 类,补充计算线段空间长度与地面长度的方法。
5
+ * @class PolylinePipeline
6
+ * @see {@link https://cesium.com/learn/cesiumjs/ref-doc/PolylinePipeline.html}
7
+ */
8
+
9
+ /**
10
+ * 计算线段的空间长度,即各顶点间的直线距离之和。
11
+ * @param {Array} positions 构成线段的笛卡尔坐标点数组(Cartesian3 数组)。
12
+ * @returns {number} 线段的空间长度,单位米。
13
+ * @memberof PolylinePipeline
14
+ * @static
15
+ */
16
+ PolylinePipeline.computeLength = function (positions) {
17
+ Check.typeOf.array('positions', positions);
18
+ if (positions.length < 2)
19
+ return 0;
20
+ let length = 0,
21
+ a, b, distance;
22
+ for (let i = 1; i < positions.length; i++) {
23
+ a = positions[i - 1];
24
+ b = positions[i];
25
+ distance = Cartesian3.distance(a, b);
26
+ length += distance;
27
+ }
28
+ return length;
29
+ };
30
+
31
+ /**
32
+ * 计算线段的地面长度,即各顶点间沿地表(椭球面)距离之和。
33
+ * @param {Array} positions 构成线段的笛卡尔坐标点数组(Cartesian3 数组)。
34
+ * @returns {number} 线段的地面长度,单位米。
35
+ * @memberof PolylinePipeline
36
+ * @static
37
+ */
38
+ PolylinePipeline.computeSurfaceLength = function (positions) {
39
+ Check.typeOf.array('positions', positions);
40
+ if (positions.length < 2)
41
+ return 0;
42
+ let length = 0,
43
+ a, b, distance;
44
+ for (let i = 1; i < positions.length; i++) {
45
+ a = positions[i - 1];
46
+ b = positions[i];
47
+ distance = Cartesian3.surfaceDistance(a, b);
48
+ length += distance;
49
+ }
50
+ return length;
51
+ };
52
+
53
+ export default PolylinePipeline;
54
+ export { PolylinePipeline };