@lijuhong1981/cesium.utils 0.0.0-stage → 0.1.1

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 +45 -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,25 @@
1
+ export * from "./BoundingSphere.revise.js";
2
+ export * from "./Camera.revise.js";
3
+ export * from "./Cartesian.revise.js";
4
+ export * from "./Cartographic.revise.js";
5
+ export * from "./Check.revise.js";
6
+ export * from "./Color.revise.js";
7
+ export * from "./DistanceDisplayCondition.revise.js";
8
+ export * from "./Ellipsoid.revise.js";
9
+ export * from "./Geometry.revise.js";
10
+ export * from "./Globe.revise.js";
11
+ export * from "./HeadingPitchRoll.revise.js";
12
+ export * from "./JulianDate.revise.js";
13
+ export * from "./Material.revise.js";
14
+ export * from "./Math.revise.js";
15
+ export * from "./Matrix.revise.js";
16
+ export * from "./Plane.revise.js";
17
+ export * from "./POI.revise.js";
18
+ export * from "./PolylinePipeline.revise.js";
19
+ export * from "./PostProcessStageLibrary.revise.js";
20
+ export * from "./Primitive.revise.js";
21
+ export * from "./Property.revise.js";
22
+ export * from "./Quaternion.revise.js";
23
+ export * from "./Rectangle.revise.js";
24
+ export * from "./SceneTransforms.revise.js";
25
+ export * from "./Spherical.revise.js";
@@ -0,0 +1,165 @@
1
+ import { BoundingRectangle, BoundingSphere, Cartesian2, Cartesian3, Cartesian4, Cartographic, Color, DistanceDisplayCondition, HeadingPitchRange, HeadingPitchRoll, Interval, Matrix3, Matrix4, NearFarScalar, PerspectiveFrustum, Plane, Quaternion, Ray, Rectangle } from "cesium";
2
+ import Geographic from "../additions/Geographic.js";
3
+
4
+ // --Cartesian2--
5
+ const scratchCanvasCoordinates = new Cartesian2(), // Cartesian2 画布坐标缓存
6
+ scratchCartesian2 = new Cartesian2(), // Cartesian2 二维笛卡尔坐标缓存
7
+ scratchPixelSize = new Cartesian2(), // Cartesian2 像素尺寸缓存
8
+ scratchRepeat = new Cartesian2(1, 1), // Cartesian2 纹理重复次数缓存(默认 1,1)
9
+ scratchScale2 = new Cartesian2(1, 1), // Cartesian2 二维缩放缓存(默认 1,1)
10
+ scratchWindowPosition = new Cartesian2(); // Cartesian2 窗口坐标缓存
11
+
12
+ // --Cartesian3--
13
+ const scratchCartesian3 = new Cartesian3(), // Cartesian3 三维笛卡尔坐标缓存
14
+ scratchDepthPosition = new Cartesian3(), // Cartesian3 深度位置缓存
15
+ scratchEllipsoidPosition = new Cartesian3(), // Cartesian3 椭球位置缓存
16
+ scratchEuler = new Cartesian3(), // Cartesian3 欧拉角缓存
17
+ scratchGlobePosition = new Cartesian3(), // Cartesian3 地球表面位置缓存
18
+ scratchPositionWC = new Cartesian3(), // Cartesian3 世界坐标位置缓存
19
+ scratchScale3 = new Cartesian3(1, 1, 1), // Cartesian3 三维缩放缓存(默认 1,1,1)
20
+ scratchTranslate = new Cartesian3(), // Cartesian3 平移量缓存
21
+ scratchTranslation = new Cartesian3(), // Cartesian3 平移量缓存
22
+ scratchCenter = new Cartesian3(), // Cartesian3 中心点缓存
23
+ scratchDirection = new Cartesian3(), // Cartesian3 方向向量缓存
24
+ scratchForward = new Cartesian3(), // Cartesian3 前方向向量缓存
25
+ scratchNormal = new Cartesian3(), // Cartesian3 法线向量缓存
26
+ scratchUp = new Cartesian3(), // Cartesian3 上方向向量缓存
27
+ scratchUpCartesian3 = new Cartesian3(), // Cartesian3 上方向向量缓存
28
+ scratchDownCartesian3 = new Cartesian3(), // Cartesian3 下方向向量缓存
29
+ scratchLeftCartesian3 = new Cartesian3(), // Cartesian3 左方向向量缓存
30
+ scratchLeftDirection = new Cartesian3(), // Cartesian3 左方向向量缓存
31
+ scratchLeftNormal = new Cartesian3(), // Cartesian3 左法线向量缓存
32
+ scratchRightCartesian3 = new Cartesian3(), // Cartesian3 右方向向量缓存
33
+ scratchRightDirection = new Cartesian3(), // Cartesian3 右方向向量缓存
34
+ scratchRightNormal = new Cartesian3(); // Cartesian3 右法线向量缓存
35
+
36
+ // --Cartesian4--
37
+ const scratchCartesian4 = new Cartesian4(), // Cartesian4 四维笛卡尔坐标缓存
38
+ scratchNDC = new Cartesian4(); // Cartesian4 归一化设备坐标缓存
39
+
40
+ // --Cartographic--
41
+ const scratchCartographic = new Cartographic(), // Cartographic 制图坐标(经度、纬度、高度)缓存
42
+ scratchLeftCartographic = new Cartographic(), // Cartographic 左侧制图坐标缓存
43
+ scratchRightCartographic = new Cartographic(), // Cartographic 右侧制图坐标缓存
44
+ scratchStartCartographic = new Cartographic(), // Cartographic 起点制图坐标缓存
45
+ scratchEndCartographic = new Cartographic(); // Cartographic 终点制图坐标缓存
46
+
47
+ // --Matrix3--
48
+ const scratchMatrix3 = new Matrix3(), // Matrix3 三维矩阵缓存
49
+ scratchRotationMatrix = new Matrix3(); // Matrix3 旋转矩阵缓存
50
+
51
+ // --Matrix4--
52
+ const scratchMatrix4 = new Matrix4(), // Matrix4 四维矩阵缓存
53
+ scratchTransform = new Matrix4(), // Matrix4 变换矩阵缓存
54
+ scratchViewMatrix = new Matrix4(); // Matrix4 视图矩阵缓存
55
+
56
+ // --Others--
57
+ const scratchBoundingRectangle = new BoundingRectangle(), // BoundingRectangle 包围矩形缓存
58
+ scratchBoundingSphere = new BoundingSphere(), // BoundingSphere 包围球缓存
59
+ scratchColor = new Color(), // Color 颜色缓存
60
+ scratchDistanceDisplayCondition = new DistanceDisplayCondition(), // DistanceDisplayCondition 距离显示条件缓存
61
+ scratchGeographic = new Geographic(), // Geographic 地理坐标缓存
62
+ scratchHeadingPitchRange = new HeadingPitchRange(), // HeadingPitchRange 航向俯仰距离缓存
63
+ scratchHeadingPitchRoll = new HeadingPitchRoll(), // HeadingPitchRoll 航向俯仰翻滚缓存
64
+ scratchInterval = new Interval(), // Interval 区间缓存
65
+ scratchTiltRestriction = new Interval(), // Interval 倾斜限制区间缓存
66
+ scratchNearFarScalar = new NearFarScalar(), // NearFarScalar 近远标量缓存
67
+ scratchPerspective = new PerspectiveFrustum(), // PerspectiveFrustum 透视视锥体缓存
68
+ scratchPlane = new Plane(Cartesian3.UNIT_Z, 0), // Plane 平面缓存(法线为 UNIT_Z)
69
+ scratchOrientation = new Quaternion(), // Quaternion 姿态四元数缓存
70
+ scratchQuaternion = new Quaternion(), // Quaternion 四元数缓存
71
+ scratchRay = new Ray(), // Ray 射线缓存
72
+ scratchRectangle = new Rectangle(); // Rectangle 矩形缓存
73
+
74
+ let _scratchCamera;
75
+
76
+ /**
77
+ * Cesium 常用临时对象的统一 scratch 缓存集合。
78
+ * 集中存放各类可复用的临时对象(Cartesian2/3/4、Cartographic、Matrix3/4、Color 等),
79
+ * 供内部计算复用以减少运行时对象创建与垃圾回收开销。
80
+ * 使用约定:仅在同步计算过程中临时占用,不要长期持有其引用。
81
+ */
82
+ const Scratch = {
83
+ // --Cartesian2--
84
+ scratchCartesian2,
85
+ scratchPixelSize,
86
+ scratchScale2,
87
+ scratchCanvasCoordinates,
88
+ scratchWindowPosition,
89
+ scratchRepeat,
90
+ // --Cartesian3--
91
+ scratchCartesian3,
92
+ scratchCenter,
93
+ scratchLeftCartesian3,
94
+ scratchRightCartesian3,
95
+ scratchUpCartesian3,
96
+ scratchDownCartesian3,
97
+ scratchPositionWC,
98
+ scratchTranslation,
99
+ scratchTranslate,
100
+ scratchEuler,
101
+ scratchDirection,
102
+ scratchLeftDirection,
103
+ scratchRightDirection,
104
+ scratchUp,
105
+ scratchNormal,
106
+ scratchLeftNormal,
107
+ scratchRightNormal,
108
+ scratchForward,
109
+ scratchScale3,
110
+ scratchEllipsoidPosition,
111
+ scratchGlobePosition,
112
+ scratchDepthPosition,
113
+ // --Cartesian4--
114
+ scratchCartesian4,
115
+ scratchNDC,
116
+ // --Cartographic--
117
+ scratchCartographic,
118
+ scratchLeftCartographic,
119
+ scratchRightCartographic,
120
+ scratchStartCartographic,
121
+ scratchEndCartographic,
122
+ // --Matrix3--
123
+ scratchMatrix3,
124
+ scratchRotationMatrix,
125
+ // --Matrix4--
126
+ scratchMatrix4,
127
+ scratchTransform,
128
+ scratchViewMatrix,
129
+ // --Others--
130
+ scratchBoundingRectangle,
131
+ scratchBoundingSphere,
132
+ scratchColor,
133
+ scratchDistanceDisplayCondition,
134
+ scratchGeographic,
135
+ scratchHeadingPitchRange,
136
+ scratchHeadingPitchRoll,
137
+ scratchNearFarScalar,
138
+ scratchQuaternion,
139
+ scratchRay,
140
+ scratchInterval,
141
+ scratchTiltRestriction,
142
+ scratchPlane,
143
+ scratchRectangle,
144
+ scratchOrientation,
145
+ scratchPerspective,
146
+ };
147
+
148
+ Object.defineProperties(Scratch, {
149
+ // Camera 相机实例的临时缓存(通过 get/set 访问)
150
+ scratchCamera: {
151
+ set: function (value) {
152
+ _scratchCamera = value;
153
+ },
154
+ get: function () {
155
+ return _scratchCamera;
156
+ }
157
+ }
158
+ });
159
+
160
+ export default Scratch;
161
+ export {
162
+ Scratch,
163
+ // ----
164
+ scratchBoundingRectangle, scratchBoundingSphere, scratchCanvasCoordinates, scratchCartesian2, scratchCartesian3, scratchCartesian4, scratchCartographic, scratchCenter, scratchColor, scratchDepthPosition, scratchDirection, scratchDistanceDisplayCondition, scratchDownCartesian3, scratchEllipsoidPosition, scratchEndCartographic, scratchEuler, scratchForward, scratchGeographic, scratchGlobePosition, scratchHeadingPitchRange, scratchHeadingPitchRoll, scratchInterval, scratchTiltRestriction, scratchLeftCartesian3, scratchLeftCartographic, scratchLeftDirection, scratchLeftNormal, scratchMatrix3, scratchMatrix4, scratchNDC, scratchNearFarScalar, scratchNormal, scratchOrientation, scratchPerspective, scratchPixelSize, scratchPlane, scratchPositionWC, scratchQuaternion, scratchRay, scratchRectangle, scratchRepeat, scratchRightCartesian3, scratchRightCartographic, scratchRightDirection, scratchRightNormal, scratchRotationMatrix, scratchScale2, scratchScale3, scratchStartCartographic, scratchTransform, scratchTranslate, scratchTranslation, scratchUp, scratchUpCartesian3, scratchViewMatrix, scratchWindowPosition
165
+ };
@@ -0,0 +1,48 @@
1
+ import { Cartesian3, Math as CesiumMath, Check, defined, EllipseGeometryLibrary } from "cesium";
2
+
3
+ /**
4
+ * 在椭球面上按给定中心、半径与分段数计算圆(环)上的点集。
5
+ * @param {object} options 参数对象
6
+ * @param {Cartesian3} options.center 圆心(世界坐标,决定圆所在的椭球面位置)
7
+ * @param {number} options.radius 圆半径,单位米,需大于 0
8
+ * @param {number} [options.rotation=0] 圆的旋转角,单位弧度
9
+ * @param {number} [options.rotationDegrees] 圆的旋转角,单位度;提供时覆盖 rotation
10
+ * @param {number} [options.numberOfSegments=64] 圆周分段数,需为不小于 3 的整数
11
+ * @returns {Cartesian3[]} 圆周上的点集
12
+ */
13
+ function computeCirclePositions(options) {
14
+ const center = options.center;
15
+ Check.typeOf.object('center', center);
16
+ const radius = options.radius;
17
+ Check.typeOf.number.greaterThan('radius', radius, 0);
18
+ let rotation = options.rotation ?? 0;
19
+ if (defined(options.rotationDegrees))
20
+ rotation = CesiumMath.toRadians(options.rotationDegrees);
21
+ const numberOfSegments = options.numberOfSegments ?? 64;
22
+ Check.typeOf.integer.greaterThanOrEquals('numberOfSegments', numberOfSegments, 3);
23
+
24
+ const rSqr = radius * radius;
25
+
26
+ const mag = Cartesian3.magnitude(center);
27
+
28
+ const unitPos = Cartesian3.normalize(center, new Cartesian3());
29
+ const eastVec = Cartesian3.cross(Cartesian3.UNIT_Z, center, new Cartesian3());
30
+ Cartesian3.normalize(eastVec, eastVec);
31
+ const northVec = Cartesian3.cross(unitPos, eastVec, new Cartesian3());
32
+
33
+ const deltaTheta = CesiumMath.TWO_PI / numberOfSegments;
34
+
35
+ let theta = 0;
36
+ const result = [];
37
+ for (let i = 0; i < numberOfSegments; i++) {
38
+ const position = EllipseGeometryLibrary.pointOnEllipsoid(theta, rotation, northVec, eastVec, rSqr, rSqr, rSqr, mag, unitPos, new Cartesian3());
39
+ result.push(position);
40
+
41
+ theta += deltaTheta;
42
+ }
43
+
44
+ return result;
45
+ };
46
+
47
+ export default computeCirclePositions;
48
+ export { computeCirclePositions };
@@ -0,0 +1,19 @@
1
+ import { Cartesian3 } from "cesium";
2
+
3
+ /**
4
+ * 计算一组圆周点到首点(圆心)的最大距离,即圆的半径。
5
+ * @param {Cartesian3[]} positions 圆周上的点集,首个元素视为圆心
6
+ * @returns {number} 圆的半径,单位米
7
+ */
8
+ function computeCircleRadius(positions) {
9
+ let result = 0;
10
+ for (let i = 1; i < positions.length; i++) {
11
+ let radius = Cartesian3.distance(positions[0], positions[i]);
12
+ if (radius > result)
13
+ result = radius;
14
+ }
15
+ return result;
16
+ };
17
+
18
+ export default computeCircleRadius;
19
+ export { computeCircleRadius };
@@ -0,0 +1,109 @@
1
+ import { Cartesian3, Check, Matrix4, Quaternion, Transforms } from "cesium";
2
+ import parseAttitudeToQuaternion from "../parses/parseAttitudeToQuaternion.js";
3
+ import parseEulerToQuaternion from "../parses/parseEulerToQuaternion.js";
4
+ import parseGeographicToCartesian from "../parses/parseGeographicToCartesian.js";
5
+ import parseRotationToQuaternion from "../parses/parseRotationToQuaternion.js";
6
+ import parseToCartesian3 from "../parses/parseToCartesian3.js";
7
+ import Scratch from "../utils/Scratch.js";
8
+
9
+ /**
10
+ * 根据多种来源选项计算模型矩阵(世界坐标到局部坐标的变换矩阵)。
11
+ * 支持通过原点/经纬度/原点矩阵、变换前后矩阵以及平移、旋转/姿态/欧拉角、缩放等组合生成。
12
+ * @param {object} options 参数对象
13
+ * @param {Matrix4|Cartesian3|object} [options.origin] 原点,可为 Matrix4 或可解析为 Cartesian3 的位置
14
+ * @param {Ellipsoid} [options.ellipsoid] 参考椭球体
15
+ * @param {Matrix4} [options.originMatrix] 原点矩阵,也支持 fixedFrame/fixedFrameMatrix/localFrame/localFrameMatrix 别名
16
+ * @param {object} [options.geographic] 地理坐标原点
17
+ * @param {Cartesian3|object} [options.position] 位置原点,也支持 originPosition/center 别名
18
+ * @param {Matrix4} [options.beforeTransform] 前置变换矩阵,也支持 beforeTransformtion/beforeTransformMatrix 别名
19
+ * @param {Matrix4} [options.transform] 变换矩阵,也支持 transformation/transformMatrix/localTransform/localTransformMatrix 别名
20
+ * @param {Cartesian3} [options.translation] 平移量
21
+ * @param {Quaternion|object} [options.rotation] 旋转四元数
22
+ * @param {object} [options.attitude] 姿态
23
+ * @param {object} [options.euler] 欧拉角,也支持 eulerRotation 别名
24
+ * @param {Cartesian3} [options.scale] 缩放
25
+ * @param {Matrix4} [options.afterTransform] 后置变换矩阵,也支持 afterTransformtion/afterTransformMatrix 别名
26
+ * @param {Matrix4} [result] 用于存储结果的矩阵,未提供则新建
27
+ * @returns {Matrix4} 计算得到的模型矩阵
28
+ */
29
+ function computeModelMatrix(options, result) {
30
+ Check.typeOf.object('options', options);
31
+
32
+ if (result === undefined)
33
+ result = Matrix4.IDENTITY.clone(new Matrix4());
34
+ else
35
+ result = Matrix4.IDENTITY.clone(result);
36
+
37
+ if (options.origin) {
38
+ if (options.origin instanceof Matrix4)
39
+ Matrix4.clone(options.origin, result);
40
+ else {
41
+ const origin = parseToCartesian3(options.origin, Scratch.scratchCartesian3, 0.0);
42
+ if (!Cartesian3.equals(Cartesian3.ZERO, origin))
43
+ Transforms.eastNorthUpToFixedFrame(origin, options.ellipsoid, result);
44
+ }
45
+ } else if (options.originMatrix || options.fixedFrame || options.fixedFrameMatrix || options.localFrame || options.localFrameMatrix) {
46
+ const originMatrix = options.originMatrix || options.fixedFrame || options.fixedFrameMatrix || options.localFrame || options.localFrameMatrix;
47
+ Check.instanceOf('originMatrix', originMatrix, Matrix4);
48
+ Matrix4.clone(originMatrix, result);
49
+ } else {
50
+ let origin;
51
+ if (options.geographic)
52
+ origin = parseGeographicToCartesian(options.geographic, Scratch.scratchCartesian3, options.ellipsoid);
53
+ else if (options.position || options.originPosition || options.center) {
54
+ origin = options.position || options.originPosition || options.center;
55
+ origin = parseToCartesian3(origin, Scratch.scratchCartesian3, 0.0);
56
+ }
57
+ if (origin && !Cartesian3.equals(Cartesian3.ZERO, origin))
58
+ Transforms.eastNorthUpToFixedFrame(origin, options.ellipsoid, result);
59
+ }
60
+
61
+ if (options.beforeTransform || options.beforeTransformtion || options.beforeTransformMatrix) {
62
+ const beforeTransform = options.beforeTransform || options.beforeTransformtion || options.beforeTransformMatrix;
63
+ Check.instanceOf('beforeTransform', beforeTransform, Matrix4);
64
+ if (!Matrix4.equals(beforeTransform, Matrix4.IDENTITY))
65
+ Matrix4.multiplyTransformation(result, beforeTransform, result);
66
+ }
67
+
68
+ if (options.transform || options.transformation || options.transformMatrix || options.localTransform || options.localTransformMatrix) {
69
+ const transform = options.transform || options.transformation || options.transformMatrix || options.localTransform || options.localTransformMatrix;
70
+ Check.instanceOf('transform', transform, Matrix4);
71
+ if (!Matrix4.equals(transform, Matrix4.IDENTITY))
72
+ Matrix4.multiplyTransformation(result, transform, result);
73
+ } else {
74
+ const transform = Matrix4.IDENTITY.clone(Scratch.scratchTransform);
75
+
76
+ const translation = Cartesian3.ZERO.clone(Scratch.scratchTranslation);
77
+ if (options.translation)
78
+ parseToCartesian3(options.translation, translation, 0.0);
79
+
80
+ const quaternion = Quaternion.IDENTITY.clone(Scratch.scratchQuaternion);
81
+ if (options.rotation)
82
+ parseRotationToQuaternion(options.rotation, quaternion);
83
+ else if (options.attitude)
84
+ parseAttitudeToQuaternion(options.attitude, quaternion);
85
+ else if (options.euler || options.eulerRotation)
86
+ parseEulerToQuaternion(options.euler || options.eulerRotation, quaternion);
87
+
88
+ const scale = Cartesian3.ONE.clone(Scratch.scratchScale3);
89
+ if (options.scale)
90
+ parseToCartesian3(options.scale, scale, 1.0);
91
+
92
+ Matrix4.fromTranslationQuaternionRotationScale(translation, quaternion, scale, transform);
93
+
94
+ if (!Matrix4.equals(transform, Matrix4.IDENTITY))
95
+ Matrix4.multiplyTransformation(result, transform, result);
96
+ }
97
+
98
+ if (options.afterTransform || options.afterTransformtion || options.afterTransformMatrix) {
99
+ const afterTransform = options.afterTransform || options.afterTransformtion || options.afterTransformMatrix;
100
+ Check.instanceOf('afterTransform', afterTransform, Matrix4);
101
+ if (!Matrix4.equals(afterTransform, Matrix4.IDENTITY))
102
+ Matrix4.multiplyTransformation(result, afterTransform, result);
103
+ }
104
+
105
+ return result;
106
+ };
107
+
108
+ export default computeModelMatrix;
109
+ export { computeModelMatrix };
@@ -0,0 +1,57 @@
1
+ import { Matrix3 } from "cesium";
2
+
3
+ /**
4
+ * 由偏移、重复、旋转与中心参数构建纹理坐标(st)变换矩阵。
5
+ * @param {object} [stOffset={x:0,y:0}] 纹理坐标偏移
6
+ * @param {object} [stRepeat={x:1,y:1}] 纹理坐标重复(缩放)
7
+ * @param {number} [stRotation=0] 纹理坐标旋转角,单位弧度
8
+ * @param {object} [stCenter={x:0.5,y:0.5}] 纹理坐标旋转中心
9
+ * @param {Matrix3} [result] 用于存储结果的矩阵,未提供则新建
10
+ * @returns {Matrix3} 纹理坐标变换矩阵
11
+ */
12
+ function computeStTransform(stOffset = {
13
+ x: 0,
14
+ y: 0
15
+ }, stRepeat = {
16
+ x: 1,
17
+ y: 1
18
+ }, stRotation = 0, stCenter = {
19
+ x: 0.5,
20
+ y: 0.5,
21
+ }, result = new Matrix3()) {
22
+ const tx = stOffset.x,
23
+ ty = stOffset.y,
24
+ sx = stRepeat.x,
25
+ sy = stRepeat.y,
26
+ cx = stCenter.x,
27
+ cy = stCenter.y,
28
+ c = Math.cos(stRotation),
29
+ s = Math.sin(stRotation);
30
+ //sx * c, sx * s, - sx * ( c * cx + s * cy ) + cx + tx,
31
+ //- sy * s, sy * c, - sy * ( - s * cx + c * cy ) + cy + ty,
32
+ //0, 0, 1
33
+ const n11 = sx * c,
34
+ n12 = sx * s,
35
+ n13 = -sx * (c * cx + s * cy) + cx - tx,
36
+ n21 = -sy * s,
37
+ n22 = sy * c,
38
+ n23 = -sy * (-s * cx + c * cy) + cy - ty,
39
+ n31 = 0,
40
+ n32 = 0,
41
+ n33 = 1;
42
+
43
+ result[0] = n11;
44
+ result[1] = n21;
45
+ result[2] = n31;
46
+ result[3] = n12;
47
+ result[4] = n22;
48
+ result[5] = n32;
49
+ result[6] = n13;
50
+ result[7] = n23;
51
+ result[8] = n33;
52
+
53
+ return result;
54
+ };
55
+
56
+ export default computeStTransform;
57
+ export { computeStTransform };
@@ -0,0 +1,114 @@
1
+ import { BoundingSphere, Check, ComponentDatatype, DeveloperError, Geometry, GeometryAttribute, PrimitiveType } from 'cesium';
2
+
3
+ /**
4
+ * 根据 TypedArray 的类型推断对应的 Cesium 组件数据类型(ComponentDatatype)。
5
+ * @param {ArrayBufferView} array 顶点属性数组
6
+ * @returns {ComponentDatatype} 对应的组件数据类型,无法识别时返回 SHORT
7
+ */
8
+ function getAttributeComponentType(array) {
9
+ var attributeComponentType = ComponentDatatype.SHORT;
10
+ if (array instanceof Int8Array) {
11
+ attributeComponentType = ComponentDatatype.BYTE;
12
+ } else if (array instanceof Uint8Array || array instanceof Uint8ClampedArray) {
13
+ attributeComponentType = ComponentDatatype.UNSIGNED_BYTE;
14
+ } else if (array instanceof Int16Array) {
15
+ attributeComponentType = ComponentDatatype.SHORT;
16
+ } else if (array instanceof Uint16Array) {
17
+ attributeComponentType = ComponentDatatype.UNSIGNED_SHORT;
18
+ } else if (array instanceof Int32Array) {
19
+ attributeComponentType = ComponentDatatype.INT;
20
+ } else if (array instanceof Uint32Array) {
21
+ attributeComponentType = ComponentDatatype.UNSIGNED_INT;
22
+ } else if (array instanceof Float32Array) {
23
+ attributeComponentType = ComponentDatatype.FLOAT;
24
+ } else if (array instanceof Float64Array) {
25
+ attributeComponentType = ComponentDatatype.DOUBLE;
26
+ }
27
+ return attributeComponentType;
28
+ }
29
+
30
+ /**
31
+ * 将 three.js 的 BufferGeometry 转换为 Cesium 的 Geometry。
32
+ * @param {object} geometry three.js BufferGeometry 对象
33
+ * @returns {Geometry} 转换后的 Cesium 几何对象
34
+ */
35
+ function threeGeometryToCesiumGeometry(geometry) {
36
+ Check.defined('geometry', geometry);
37
+
38
+ let attributes = {};
39
+ if (!geometry.attributes.normal && typeof geometry.computeVertexNormals === 'function') {
40
+ geometry.computeVertexNormals();
41
+ }
42
+
43
+ let positions;
44
+ for (let attrName in geometry.attributes) {
45
+ if (geometry.attributes.hasOwnProperty(attrName)) {
46
+ let attr = geometry.getAttribute(attrName);
47
+ if (attr && attr.array.length > 0) {
48
+ if (attrName === 'position') {
49
+ positions = new Float64Array(attr.array);
50
+ attributes[attrName] = new GeometryAttribute({
51
+ componentDatatype: ComponentDatatype.DOUBLE,
52
+ componentsPerAttribute: attr.itemSize,
53
+ values: positions,
54
+ normalize: attr.normalized
55
+ });
56
+ } else {
57
+ if (attrName === 'uv')
58
+ attrName = 'st';
59
+ attributes[attrName] = new GeometryAttribute({
60
+ componentDatatype: getAttributeComponentType(attr.array),
61
+ componentsPerAttribute: attr.itemSize,
62
+ values: attr.array,
63
+ normalize: attr.normalized
64
+ });
65
+ }
66
+ }
67
+ }
68
+ }
69
+
70
+ let indices = [];
71
+ if (geometry.index)
72
+ indices = geometry.index.array;
73
+ else if (geometry.groups && geometry.groups.length > 0) {
74
+ geometry.groups.forEach(function (group) {
75
+ for (let i = 0; i < group.count; i++) {
76
+ indices.push(i + group.start);
77
+ }
78
+ })
79
+ indices = new Int32Array(indices);
80
+ } else {
81
+ const length = geometry.attributes.position.count;
82
+ for (let i = 0; i < length; i++) {
83
+ indices.push(i);
84
+ }
85
+ indices = new Int32Array(indices);
86
+ }
87
+
88
+ return new Geometry({
89
+ attributes: attributes,
90
+ indices: indices,
91
+ primitiveType: PrimitiveType.TRIANGLES,
92
+ boundingSphere: BoundingSphere.fromVertices(positions)
93
+ });
94
+ };
95
+
96
+ /**
97
+ * 将多种几何类型统一转换为 Cesium 的 Geometry 对象。
98
+ * 支持已为 Geometry 的对象、three.js BufferGeometry,以及构造函数带 createGeometry 静态方法的几何对象。
99
+ * @param {Geometry|object} geometry 待转换的几何对象
100
+ * @returns {Geometry} Cesium 几何对象
101
+ */
102
+ function createGeometry(geometry) {
103
+ Check.defined('geometry', geometry);
104
+ if (geometry instanceof Geometry)
105
+ return geometry;
106
+ if (geometry.isBufferGeometry)
107
+ return threeGeometryToCesiumGeometry(geometry);
108
+ if (typeof geometry.constructor.createGeometry === 'function')
109
+ return geometry.constructor.createGeometry(geometry);
110
+ throw new DeveloperError('Unable to identify geometry.');
111
+ };
112
+
113
+ export default createGeometry;
114
+ export { createGeometry };
@@ -0,0 +1,79 @@
1
+ import isTypedArray from "@lijuhong1981/jscheck/src/isTypedArray.js";
2
+ import { BoundingSphere, Cartesian3, Check, Color, ComponentDatatype, DeveloperError, GeometryAttribute, GeometryAttributes, PrimitiveType } from "cesium";
3
+
4
+ /**
5
+ * 根据位置与可选颜色数据创建 Cesium 点云几何体(PrimitiveType.POINTS)。
6
+ * @param {object} [options={}] 参数对象
7
+ * @param {ArrayBuffer|Array|ArrayBufferView} options.positions 位置数据,可为 Cartesian3 数组、扁平数值数组或 TypedArray
8
+ * @param {ArrayBuffer|Array|ArrayBufferView} [options.colors] 颜色数据,缺省时全部使用深灰色
9
+ * @returns {Geometry} 点云几何体
10
+ */
11
+ function createPointCloudGeometry(options = {}) {
12
+ Check.defined('positions', options.positions);
13
+ const positions = options.positions;
14
+ let positionsArray;
15
+ if (positions instanceof ArrayBuffer) {
16
+ positionsArray = new Float64Array(positions);
17
+ } else if (Array.isArray(positions))
18
+ if (typeof positions[0] === 'number')
19
+ positionsArray = positions;
20
+ else
21
+ positionsArray = Cartesian3.packArray(positions);
22
+ else if (isTypedArray(positions))
23
+ positionsArray = positions;
24
+ else {
25
+ throw new DeveloperError('positions must be Cartesian`s Array or TypedArray object.');
26
+ }
27
+ const positionsLength = positionsArray.length / 3;
28
+
29
+ let colors, colorsArray;
30
+ if (options.colors) {
31
+ colors = options.colors;
32
+ } else {
33
+ colors = new Array();
34
+ for (let i = 0; i < positionsLength; i++) {
35
+ colors[i] = Color.DARKGRAY.clone();
36
+ }
37
+ }
38
+ if (colors instanceof ArrayBuffer) {
39
+ colorsArray = new Uint8Array(colors);
40
+ } else if (Array.isArray(colors)) {
41
+ if (typeof colors[0] === 'number')
42
+ colorsArray = colors;
43
+ else
44
+ colorsArray = Color.packArrayToBytes(colors);
45
+ } else if (isTypedArray(colors))
46
+ colorsArray = colors;
47
+ else {
48
+ throw new DeveloperError('colors must be Color`s Array or TypedArray object.');
49
+ }
50
+ const colorsLength = colorsArray.length / 4;
51
+
52
+ if (positionsLength !== colorsLength) {
53
+ throw new DeveloperError('the positionsLength must be equal to colorsLength.');
54
+ }
55
+
56
+ const attributes = new GeometryAttributes();
57
+
58
+ attributes.position = new GeometryAttribute({
59
+ componentDatatype: ComponentDatatype.DOUBLE,
60
+ componentsPerAttribute: 3,
61
+ values: new Float64Array(positionsArray),
62
+ });
63
+
64
+ attributes.color = new GeometryAttribute({
65
+ componentDatatype: ComponentDatatype.UNSIGNED_BYTE,
66
+ componentsPerAttribute: 4,
67
+ values: new Uint8Array(colorsArray),
68
+ normalize: true,
69
+ });
70
+
71
+ return new Geometry({
72
+ attributes: attributes,
73
+ primitiveType: PrimitiveType.POINTS,
74
+ boundingSphere: BoundingSphere.fromVertices(positionsArray),
75
+ });
76
+ };
77
+
78
+ export default createPointCloudGeometry;
79
+ export { createPointCloudGeometry };
@@ -0,0 +1,43 @@
1
+ import { BooleanGeometryInstanceAttribute, Cartesian3GeometryInstanceAttribute, FloatGeometryInstanceAttribute } from "../additions/GeometryInstanceAttributes.js";
2
+ import { Cartesian3, ColorGeometryInstanceAttribute, defined, DistanceDisplayConditionGeometryInstanceAttribute, ShowGeometryInstanceAttribute } from "cesium";
3
+
4
+ /**
5
+ * 根据各项参数构建几何实例属性集合(GeometryInstanceAttributes)。
6
+ * @param {boolean} show 是否显示
7
+ * @param {Color} color 材质颜色
8
+ * @param {DistanceDisplayCondition} distanceDisplayCondition 距离显示条件
9
+ * @param {Matrix3} stTransform 纹理坐标变换矩阵,按列拆分为三个 Cartesian3 分别存储
10
+ * @param {number} pointSize 点大小
11
+ * @param {boolean} perVertexColors 是否使用逐顶点颜色
12
+ * @param {Color} instanceColor 实例颜色
13
+ * @returns {object} 几何实例属性集合
14
+ */
15
+ function getGeometryInstanceAttributes(show, color, distanceDisplayCondition, stTransform, pointSize, perVertexColors, instanceColor) {
16
+ const attributes = {};
17
+ if (defined(show))
18
+ attributes.show = new ShowGeometryInstanceAttribute(show);
19
+ if (defined(color))
20
+ attributes.color = ColorGeometryInstanceAttribute.fromColor(color);
21
+ if (defined(distanceDisplayCondition))
22
+ attributes.distanceDisplayCondition = DistanceDisplayConditionGeometryInstanceAttribute.fromDistanceDisplayCondition(distanceDisplayCondition);
23
+ if (defined(stTransform)) {
24
+ //stTransform是一个Matrix3对象,但是GeometryInstanceAttribute最多只支持到Cartesian4对象,所以这里将Matrix3按列拆分成3个Cartesian3对象分别传入,然后在shader中再合成为mat3数据
25
+ const scratchCartesian3 = new Cartesian3();
26
+ const column0 = stTransform.getColumn(0, scratchCartesian3);
27
+ attributes.stTransformColumn0 = Cartesian3GeometryInstanceAttribute.fromCartesian3(column0);
28
+ const column1 = stTransform.getColumn(1, scratchCartesian3);
29
+ attributes.stTransformColumn1 = Cartesian3GeometryInstanceAttribute.fromCartesian3(column1);
30
+ const column2 = stTransform.getColumn(2, scratchCartesian3);
31
+ attributes.stTransformColumn2 = Cartesian3GeometryInstanceAttribute.fromCartesian3(column2);
32
+ }
33
+ if (defined(pointSize))
34
+ attributes.pointSize = FloatGeometryInstanceAttribute.fromFloat(pointSize);
35
+ if (defined(perVertexColors))
36
+ attributes.perVertexColors = BooleanGeometryInstanceAttribute.fromBoolean(perVertexColors);
37
+ if (defined(instanceColor))
38
+ attributes.instanceColor = ColorGeometryInstanceAttribute.fromColor(instanceColor);
39
+ return attributes;
40
+ };
41
+
42
+ export default getGeometryInstanceAttributes;
43
+ export { getGeometryInstanceAttributes };