@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,328 @@
1
+ import { Cartesian3, Math as CesiumMath, Check, HeadingPitchRoll, Quaternion } from "cesium";
2
+ import Scratch from "../utils/Scratch.js";
3
+
4
+ /**
5
+ * 扩展 Cesium 的 HeadingPitchRoll 类,补充偏航角别名、角度转换,
6
+ * 与四元数/欧拉角互转、取反以及打包解包等方法。
7
+ * @class HeadingPitchRoll
8
+ * @see {@link https://cesium.com/learn/cesiumjs/ref-doc/HeadingPitchRoll.html}
9
+ */
10
+
11
+ Object.defineProperties(HeadingPitchRoll.prototype, {
12
+ /**
13
+ * heading 的别名,获取/设置偏航角(弧度制)。
14
+ * @type {number}
15
+ * @memberof HeadingPitchRoll
16
+ */
17
+ yaw: {
18
+ set: function (value) {
19
+ this.heading = value;
20
+ },
21
+ get: function () {
22
+ return this.heading;
23
+ }
24
+ },
25
+ /**
26
+ * 获取航向角(角度制,单位度)。
27
+ * @type {number}
28
+ * @memberof HeadingPitchRoll
29
+ */
30
+ headingDegrees: {
31
+ get: function () {
32
+ return CesiumMath.toDegrees(this.heading);
33
+ }
34
+ },
35
+ /**
36
+ * 获取偏航角(角度制,单位度),等同于 headingDegrees。
37
+ * @type {number}
38
+ * @memberof HeadingPitchRoll
39
+ */
40
+ yawDegrees: {
41
+ get: function () {
42
+ return this.headingDegrees;
43
+ }
44
+ },
45
+ /**
46
+ * 获取俯仰角(角度制,单位度)。
47
+ * @type {number}
48
+ * @memberof HeadingPitchRoll
49
+ */
50
+ pitchDegrees: {
51
+ get: function () {
52
+ return CesiumMath.toDegrees(this.pitch);
53
+ }
54
+ },
55
+ /**
56
+ * 获取横滚角(角度制,单位度)。
57
+ * @type {number}
58
+ * @memberof HeadingPitchRoll
59
+ */
60
+ rollDegrees: {
61
+ get: function () {
62
+ return CesiumMath.toDegrees(this.roll);
63
+ }
64
+ },
65
+ });
66
+
67
+ /**
68
+ * 由航向、俯仰、横滚角(弧度制)创建 HeadingPitchRoll。
69
+ * @param {number} heading 航向角(弧度)。
70
+ * @param {number} pitch 俯仰角(弧度)。
71
+ * @param {number} roll 横滚角(弧度)。
72
+ * @param {HeadingPitchRoll} [result=new HeadingPitchRoll()] 存放结果的对象。
73
+ * @returns {HeadingPitchRoll} 修改后的 result 或新建的实例。
74
+ * @memberof HeadingPitchRoll
75
+ * @static
76
+ */
77
+ HeadingPitchRoll.fromRadians = function (heading, pitch, roll, result = new HeadingPitchRoll()) {
78
+ Check.typeOf.number('heading', heading);
79
+ Check.typeOf.number('pitch', pitch);
80
+ Check.typeOf.number('roll', roll);
81
+
82
+ result.heading = heading;
83
+ result.pitch = pitch;
84
+ result.roll = roll;
85
+ return result;
86
+ };
87
+
88
+ /**
89
+ * 由旋转矩阵创建 HeadingPitchRoll。
90
+ * @param {Matrix3} rotationMatrix 旋转矩阵。
91
+ * @param {HeadingPitchRoll} [result] 存放结果的对象。
92
+ * @returns {HeadingPitchRoll} 修改后的 result 或新建的实例。
93
+ * @memberof HeadingPitchRoll
94
+ * @static
95
+ */
96
+ HeadingPitchRoll.fromRotationMatrix = function (rotationMatrix, result) {
97
+ const quaternion = Quaternion.fromRotationMatrix(rotationMatrix, Scratch.scratchQuaternion);
98
+ return HeadingPitchRoll.fromQuaternion(quaternion, result);
99
+ };
100
+
101
+ /**
102
+ * 将 HeadingPitchRoll 转换为四元数。
103
+ * @param {HeadingPitchRoll} hpr 待转换的 HeadingPitchRoll。
104
+ * @param {Quaternion} [result] 存放结果的对象。
105
+ * @returns {Quaternion} 修改后的 result 或新建的实例。
106
+ * @memberof HeadingPitchRoll
107
+ * @static
108
+ */
109
+ HeadingPitchRoll.toQuaternion = function (hpr, result) {
110
+ return Quaternion.fromHeadingPitchRoll(hpr, result);
111
+ };
112
+
113
+ /**
114
+ * 将当前 HeadingPitchRoll 转换为四元数。
115
+ * @param {Quaternion} [result] 存放结果的对象。
116
+ * @returns {Quaternion} 修改后的 result 或新建的实例。
117
+ * @memberof HeadingPitchRoll
118
+ */
119
+ HeadingPitchRoll.prototype.toQuaternion = function (result) {
120
+ return HeadingPitchRoll.toQuaternion(this, result);
121
+ };
122
+
123
+ /**
124
+ * 将 HeadingPitchRoll 转换为角度制对象(包含 heading/pitch/roll/yaw,单位度)。
125
+ * @param {HeadingPitchRoll} hpr 待转换的 HeadingPitchRoll。
126
+ * @param {object} [result={}] 存放结果的对象。
127
+ * @returns {object} 修改后的 result 或新建的对象。
128
+ * @memberof HeadingPitchRoll
129
+ * @static
130
+ */
131
+ HeadingPitchRoll.toDegrees = function (hpr, result = {}) {
132
+ Check.defined('headingPitchRoll', hpr);
133
+
134
+ result.heading = CesiumMath.toDegrees(hpr.heading);
135
+ result.pitch = CesiumMath.toDegrees(hpr.pitch);
136
+ result.roll = CesiumMath.toDegrees(hpr.roll);
137
+ result.yaw = result.heading;
138
+ return result;
139
+ };
140
+
141
+ /**
142
+ * 将当前 HeadingPitchRoll 转换为角度制对象(包含 heading/pitch/roll/yaw,单位度)。
143
+ * @param {object} [result] 存放结果的对象。
144
+ * @returns {object} 修改后的 result 或新建的对象。
145
+ * @memberof HeadingPitchRoll
146
+ */
147
+ HeadingPitchRoll.prototype.toDegrees = function (result) {
148
+ return HeadingPitchRoll.toDegrees(this, result);
149
+ };
150
+
151
+ /**
152
+ * 将 HeadingPitchRoll 转换为欧拉角(Cartesian3,弧度制)。
153
+ * @param {HeadingPitchRoll} hpr 待转换的 HeadingPitchRoll。
154
+ * @param {Cartesian3} [result] 存放结果的对象。
155
+ * @returns {Cartesian3} 修改后的 result 或新建的实例。
156
+ * @memberof HeadingPitchRoll
157
+ * @static
158
+ */
159
+ HeadingPitchRoll.toEuler = function (hpr, result) {
160
+ return Cartesian3.fromElements(hpr.roll, -hpr.pitch, -hpr.heading, result);
161
+ };
162
+
163
+ /**
164
+ * 将当前 HeadingPitchRoll 转换为欧拉角(Cartesian3,弧度制)。
165
+ * @param {Cartesian3} [result] 存放结果的对象。
166
+ * @returns {Cartesian3} 修改后的 result 或新建的实例。
167
+ * @memberof HeadingPitchRoll
168
+ */
169
+ HeadingPitchRoll.prototype.toEuler = function (result) {
170
+ return HeadingPitchRoll.toEuler(this, result);
171
+ };
172
+
173
+ /**
174
+ * 将 HeadingPitchRoll 转换为欧拉角(Cartesian3,角度制)。
175
+ * @param {HeadingPitchRoll} hpr 待转换的 HeadingPitchRoll。
176
+ * @param {Cartesian3} [result] 存放结果的对象。
177
+ * @returns {Cartesian3} 修改后的 result 或新建的实例。
178
+ * @memberof HeadingPitchRoll
179
+ * @static
180
+ */
181
+ HeadingPitchRoll.toEulerDegrees = function (hpr, result) {
182
+ const euler = HeadingPitchRoll.toEuler(hpr, result);
183
+ euler.x = CesiumMath.toDegrees(euler.x);
184
+ euler.y = CesiumMath.toDegrees(euler.y);
185
+ euler.z = CesiumMath.toDegrees(euler.z);
186
+ return euler;
187
+ };
188
+
189
+ /**
190
+ * 将当前 HeadingPitchRoll 转换为欧拉角(Cartesian3,角度制)。
191
+ * @param {Cartesian3} [result] 存放结果的对象。
192
+ * @returns {Cartesian3} 修改后的 result 或新建的实例。
193
+ * @memberof HeadingPitchRoll
194
+ */
195
+ HeadingPitchRoll.prototype.toEulerDegrees = function (result) {
196
+ return HeadingPitchRoll.toEulerDegrees(this, result);
197
+ };
198
+
199
+ /**
200
+ * 计算 HeadingPitchRoll 的逆(航向、俯仰、横滚各角取反)。
201
+ * @param {HeadingPitchRoll} hpr 待取反的 HeadingPitchRoll。
202
+ * @param {HeadingPitchRoll} [result=new HeadingPitchRoll()] 存放结果的对象。
203
+ * @returns {HeadingPitchRoll} 修改后的 result 或新建的实例。
204
+ * @memberof HeadingPitchRoll
205
+ * @static
206
+ */
207
+ HeadingPitchRoll.inverse = function (hpr, result = new HeadingPitchRoll()) {
208
+ Check.defined('headingPitchRoll', hpr);
209
+
210
+ result.heading = -hpr.heading;
211
+ result.pitch = -hpr.pitch;
212
+ result.roll = -hpr.roll;
213
+ return result;
214
+ };
215
+
216
+ /**
217
+ * 计算当前 HeadingPitchRoll 的逆(各角取反)。
218
+ * @param {HeadingPitchRoll} [result] 存放结果的对象。
219
+ * @returns {HeadingPitchRoll} 修改后的 result 或新建的实例。
220
+ * @memberof HeadingPitchRoll
221
+ */
222
+ HeadingPitchRoll.prototype.inverse = function (result) {
223
+ return HeadingPitchRoll.inverse(this, result);
224
+ };
225
+
226
+ /**
227
+ * 打包该对象到数组时占用的元素个数。
228
+ * @type {number}
229
+ * @constant
230
+ * @memberof HeadingPitchRoll
231
+ */
232
+ HeadingPitchRoll.packedLength = 3;
233
+
234
+ /**
235
+ * 将 HeadingPitchRoll 打包到数组中。
236
+ * @param {HeadingPitchRoll} value 待打包的 HeadingPitchRoll。
237
+ * @param {Array} [array=[]] 输出结果的数组。
238
+ * @param {number} [startingIndex=0] 数组开始索引。
239
+ * @returns {Array} 返回修改后的 array 数组。
240
+ * @memberof HeadingPitchRoll
241
+ * @static
242
+ */
243
+ HeadingPitchRoll.pack = function (value, array = [], startingIndex = 0) {
244
+ //>>includeStart('debug', pragmas.debug);
245
+ Check.defined("value", value);
246
+ //>>includeEnd('debug');
247
+
248
+ array[startingIndex++] = value.heading;
249
+ array[startingIndex++] = value.pitch;
250
+ array[startingIndex] = value.roll;
251
+ return array;
252
+ };
253
+
254
+ /**
255
+ * 将数组解包为 HeadingPitchRoll。
256
+ * @param {Array} array 输入的数组。
257
+ * @param {number} [startingIndex=0] 数组开始索引。
258
+ * @param {HeadingPitchRoll} [result=new HeadingPitchRoll()] 存放结果的对象。
259
+ * @returns {HeadingPitchRoll} 修改后的 result 或新建的实例。
260
+ * @memberof HeadingPitchRoll
261
+ * @static
262
+ */
263
+ HeadingPitchRoll.unpack = function (array, startingIndex = 0, result = new HeadingPitchRoll()) {
264
+ //>>includeStart('debug', pragmas.debug);
265
+ Check.typeOf.array("array", array);
266
+ //>>includeEnd('debug');
267
+
268
+ result.heading = array[startingIndex++];
269
+ result.pitch = array[startingIndex++];
270
+ result.roll = array[startingIndex];
271
+ return result;
272
+ };
273
+
274
+ /**
275
+ * 将 HeadingPitchRoll 数组打包到数组中。
276
+ * @param {Array<HeadingPitchRoll>} hprs HeadingPitchRoll 数组。
277
+ * @param {Array} [result=[]] 输出结果的数组。
278
+ * @returns {Array} 返回修改后的 result 数组。
279
+ * @memberof HeadingPitchRoll
280
+ * @static
281
+ */
282
+ HeadingPitchRoll.packArray = function (hprs, result = []) {
283
+ //>>includeStart('debug', pragmas.debug);
284
+ Check.typeOf.array("hprs", hprs);
285
+ //>>includeEnd('debug');
286
+
287
+ let startingIndex = 0;
288
+ for (let i = 0; i < hprs.length; i++) {
289
+ HeadingPitchRoll.pack(hprs[i], result, startingIndex);
290
+ startingIndex += HeadingPitchRoll.packedLength;
291
+ }
292
+ return result;
293
+ };
294
+
295
+ /**
296
+ * 将数组解包为 HeadingPitchRoll 数组。
297
+ * @param {Array} array 输入的数组。
298
+ * @param {Array} [result=[]] 输出结果的数组。
299
+ * @returns {Array<HeadingPitchRoll>} 返回修改后的 result 数组。
300
+ * @memberof HeadingPitchRoll
301
+ * @static
302
+ */
303
+ HeadingPitchRoll.unpackArray = function (array, result = []) {
304
+ //>>includeStart('debug', pragmas.debug);
305
+ Check.typeOf.array("array", array);
306
+ //>>includeEnd('debug');
307
+
308
+ result.length = array.length / HeadingPitchRoll.packedLength;
309
+
310
+ let startingIndex = 0;
311
+ for (let i = 0; i < result.length; i++) {
312
+ result[i] = HeadingPitchRoll.unpack(array, startingIndex);
313
+ startingIndex += HeadingPitchRoll.packedLength;
314
+ }
315
+ return result;
316
+ };
317
+
318
+ /**
319
+ * 值为 (0.0, 0.0, 0.0) 的不可变 HeadingPitchRoll 实例。
320
+ * @type {HeadingPitchRoll}
321
+ * @constant
322
+ * @memberof HeadingPitchRoll
323
+ */
324
+ HeadingPitchRoll.ZERO = Object.freeze(new HeadingPitchRoll(0.0, 0.0, 0.0));
325
+
326
+ export default HeadingPitchRoll;
327
+ export { HeadingPitchRoll };
328
+
@@ -0,0 +1,28 @@
1
+ import { JulianDate } from "cesium";
2
+
3
+ /**
4
+ * 扩展 Cesium 的 JulianDate 类,补充转换为 JavaScript Date 与公历日期的方法。
5
+ * @class JulianDate
6
+ * @see {@link https://cesium.com/learn/cesiumjs/ref-doc/JulianDate.html}
7
+ */
8
+
9
+ /**
10
+ * 将当前 JulianDate 转换为 JavaScript Date 对象。
11
+ * @returns {Date} 对应的 JavaScript Date 对象。
12
+ * @memberof JulianDate
13
+ */
14
+ JulianDate.prototype.toDate = function () {
15
+ return JulianDate.toDate(this);
16
+ };
17
+
18
+ /**
19
+ * 将当前 JulianDate 转换为公历日期对象。
20
+ * @returns {GregorianDate} 对应的公历日期对象。
21
+ * @memberof JulianDate
22
+ */
23
+ JulianDate.prototype.toGregorianDate = function () {
24
+ return JulianDate.toGregorianDate(this);
25
+ };
26
+
27
+ export default JulianDate;
28
+ export { JulianDate };
@@ -0,0 +1,308 @@
1
+ // import setOptions from '@lijuhong1981/jslib/src/setParameters.js';
2
+ // import WaterMaterial from '../materials/WaterMaterial.js';
3
+ import { Check, Color, Event, Material, MaterialProperty, Matrix3, Matrix4 } from 'cesium';
4
+
5
+ /**
6
+ * 扩展 Cesium 的 Material 类,补充 BasicImage、ConverageArea、PolylineTrail、ImageTransform
7
+ * 等自定义材质类型。
8
+ * @class Material
9
+ * @see {@link https://cesium.com/learn/cesiumjs/ref-doc/Material.html}
10
+ */
11
+ /**
12
+ * 扩展 Cesium 的 MaterialProperty 类,补充按材质类型或材质实例创建属性对象的方法。
13
+ * @class MaterialProperty
14
+ * @see {@link https://cesium.com/learn/cesiumjs/ref-doc/MaterialProperty.html}
15
+ */
16
+
17
+ // Material.prototype.setOptions = function (options) {
18
+ // setOptions(this, options);
19
+ // };
20
+
21
+ // Material.defaultWaterMaterial = WaterMaterial.default;
22
+
23
+ /**
24
+ * MaterialProperty 的常量实现:按指定的材质类型与 uniform 直接返回材质参数。
25
+ * @class MaterialPropertyImpl
26
+ * @private
27
+ */
28
+ class MaterialPropertyImpl {
29
+ constructor(type, uniforms = {}, isConstent = true) {
30
+ Check.defined('type', type);
31
+ this._type = type;
32
+ this._uniforms = uniforms;
33
+ this._isConstant = isConstent;
34
+ this._definitionChanged = new Event();
35
+ }
36
+
37
+ get isConstant() {
38
+ return this._isConstant;
39
+ }
40
+
41
+ get definitionChanged() {
42
+ return this._definitionChanged;
43
+ }
44
+
45
+ getType(time) {
46
+ return this._type;
47
+ }
48
+
49
+ getValue(time, uniforms) {
50
+ for (const key in this._uniforms) {
51
+ if (Object.hasOwnProperty.call(this._uniforms, key)) {
52
+ uniforms[key] = this._uniforms[key];
53
+ }
54
+ }
55
+ return uniforms;
56
+ }
57
+
58
+ equals(other) {
59
+ return (this._type === other._type && this._uniforms === other._uniforms);
60
+ }
61
+ };
62
+
63
+ /**
64
+ * 按材质类型与 uniform 创建 MaterialProperty。
65
+ * @param {string} type 材质类型。
66
+ * @param {object} [uniforms={}] 材质参数(uniform)。
67
+ * @param {boolean} [isConstent=true] 是否为常量材质。
68
+ * @returns {MaterialProperty} 创建的 MaterialProperty 实例。
69
+ * @memberof MaterialProperty
70
+ * @static
71
+ */
72
+ MaterialProperty.fromType = function (type, uniforms, isConstent) {
73
+ return new MaterialPropertyImpl(type, uniforms, isConstent);
74
+ };
75
+
76
+ /**
77
+ * MaterialProperty 的实例实现:基于已有的 Material 对象返回材质参数。
78
+ * @class MaterialInstanceProperty
79
+ * @private
80
+ */
81
+ class MaterialInstanceProperty {
82
+ constructor(material, uniforms = {}, isConstent = true) {
83
+ Check.defined('material', material);
84
+ this._material = material;
85
+ this._uniforms = uniforms;
86
+ this._isConstant = isConstent;
87
+ this._definitionChanged = new Event();
88
+ }
89
+
90
+ get material() {
91
+ return this._material;
92
+ }
93
+
94
+ get isConstant() {
95
+ return this._isConstant;
96
+ }
97
+
98
+ get definitionChanged() {
99
+ return this._definitionChanged;
100
+ }
101
+
102
+ getType(time) {
103
+ return this._material.type;
104
+ }
105
+
106
+ getValue(time, uniforms) {
107
+ for (const key in this._uniforms) {
108
+ if (Object.hasOwnProperty.call(this._uniforms, key)) {
109
+ uniforms[key] = this._uniforms[key];
110
+ }
111
+ }
112
+ return uniforms;
113
+ }
114
+
115
+ equals(other) {
116
+ return this._material === other._material;
117
+ }
118
+ }
119
+
120
+ /**
121
+ * 按已有 Material 实例与 uniform 创建 MaterialProperty。
122
+ * @param {Material} material 材质实例。
123
+ * @param {object} [uniforms={}] 材质参数(uniform)。
124
+ * @param {boolean} [isConstent=true] 是否为常量材质。
125
+ * @returns {MaterialProperty} 创建的 MaterialProperty 实例。
126
+ * @memberof MaterialProperty
127
+ * @static
128
+ */
129
+ MaterialProperty.fromMaterial = function (material, uniforms, isConstent) {
130
+ return new MaterialInstanceProperty(material, uniforms, isConstent);
131
+ };
132
+
133
+ const BasicImageType = 'BasicImage';
134
+
135
+ /**
136
+ * BasicImage 材质类型标识(基于 uv 贴图与颜色渲染)。
137
+ * @type {string}
138
+ * @constant
139
+ * @memberof Material
140
+ */
141
+ Material.BasicImageType = BasicImageType;
142
+ //添加BasicImageType材质
143
+ Material._materialCache.addMaterial(BasicImageType, {
144
+ //基于Cesium fabric语法构建材质
145
+ fabric: {
146
+ type: BasicImageType, //材质类型
147
+ uniforms: { //接受的参数
148
+ image: Material.DefaultImageId, //普通uv贴图
149
+ color: new Color(), //颜色
150
+ // translucent: true, //是否透明
151
+ },
152
+ source: "czm_material czm_getMaterial(czm_materialInput materialInput)\n" + //固定写法,重载czm_getMaterial函数
153
+ "{\n" +
154
+ " czm_material material = czm_getDefaultMaterial(materialInput);\n" + //获取默认材质
155
+ " vec2 st = materialInput.st;\n" + //获取uv
156
+ " vec4 imageColor = texture(image, st);\n" + //从uv贴图中获取imageColor
157
+ " material.diffuse = imageColor.rgb * color.rgb;\n" + //与外部传入color相乘得到最终渲染color,material.diffuse为最终渲染至屏幕上的color
158
+ // " if (translucent)\n" +
159
+ " material.alpha = imageColor.a * color.a;\n" + //translucent开启,则alpha值也相乘
160
+ // " else\n" +
161
+ // " material.alpha = imageColor.a;\n" + //translucent未开启
162
+ " return material;\n" +
163
+ "}",
164
+ },
165
+ translucent: function (material) {
166
+ return material.uniforms.color.alpha < 1.0;
167
+ }
168
+ });
169
+
170
+ //定义ConverageAreaType
171
+ const ConverageAreaType = 'ConverageArea';
172
+
173
+ /**
174
+ * ConverageArea 材质类型标识(用于覆盖区域裁剪的材质)。
175
+ * @type {string}
176
+ * @constant
177
+ * @memberof Material
178
+ */
179
+ Material.ConverageAreaType = ConverageAreaType;
180
+ //添加Material材质
181
+ Material._materialCache.addMaterial(ConverageAreaType, {
182
+ //基于Cesium fabric语法构建材质
183
+ fabric: {
184
+ type: ConverageAreaType, //材质类型
185
+ uniforms: { //接受的参数
186
+ outsideOfConverageArea: false,
187
+ converageAreaPlanes: Material.DefaultImageId,
188
+ converageAreaPlanesMatrix: Matrix4.IDENTITY.clone(),
189
+ },
190
+ source: "uniform bool outsideOfConverageArea;\n" +
191
+ "uniform highp sampler2D converageAreaPlanes;\n" +
192
+ "uniform mat4 converageAreaPlanesMatrix;\n" +
193
+ '\n' +
194
+ "czm_material czm_getMaterial(czm_materialInput materialInput)\n" +
195
+ "{\n" +
196
+ " czm_material material = czm_getDefaultMaterial(materialInput);\n" +
197
+ " bool isConverage = isConverageArea(gl_FragCoord, converageAreaPlanes, converageAreaPlanesMatrix);\n" +
198
+ " isConverage = (outsideOfConverageArea ? !isConverage : isConverage);\n" +
199
+ " if (!isConverage)\n" +
200
+ " {\n" +
201
+ " material.alpha = 0.0;\n" +
202
+ " return material;\n" +
203
+ " }\n" +
204
+ " return material;\n" +
205
+ "}\n",
206
+ },
207
+ translucent: false,
208
+ });
209
+
210
+ const PolylineTrailType = 'PolylineTrail';
211
+
212
+ /**
213
+ * PolylineTrail 材质类型标识(用于线尾迹效果的材质)。
214
+ * @type {string}
215
+ * @constant
216
+ * @memberof Material
217
+ */
218
+ Material.PolylineTrailType = PolylineTrailType;
219
+
220
+ Material._materialCache.addMaterial(PolylineTrailType, {
221
+ //基于Cesium fabric语法构建材质
222
+ fabric: {
223
+ type: PolylineTrailType, //材质类型
224
+ uniforms: { //接受的参数
225
+ color: new Color(1.0, 1.0, 1.0, 1.0), //颜色
226
+ trailLength: 1.0,
227
+ trailColor: new Color(1.0, 1.0, 1.0, 1.0),
228
+ trailImage: Material.DefaultImageId,
229
+ enableGlow: false,
230
+ glowPower: 0.25,
231
+ offset: 0,
232
+ reverse: false,
233
+ // translucent: true, //是否透明
234
+ },
235
+ source: "czm_material czm_getMaterial(czm_materialInput materialInput)\n" + //固定写法,重载czm_getMaterial函数
236
+ "{\n" +
237
+ " czm_material material = czm_getDefaultMaterial(materialInput);\n" + //获取默认材质
238
+ " material.diffuse = color.rgb;\n" +
239
+ " material.alpha = color.a;\n" +
240
+ " vec2 st = materialInput.st;\n" + //获取uv
241
+ " float s = fract(st.s - offset);\n" +
242
+ " if (s <= trailLength) {\n" +
243
+ " st.s = s / trailLength;\n" +
244
+ " if (reverse) st.s = 1.0 - st.s;\n" +
245
+ " vec4 imageColor = texture(trailImage, st);\n" + //从uv贴图中获取imageColor
246
+ " material.diffuse = imageColor.rgb * trailColor.rgb;\n" +
247
+ " material.alpha = imageColor.a * trailColor.a;\n" +
248
+ " }\n" +
249
+ " if (enableGlow) {\n" +
250
+ " float glow = glowPower / abs(st.t - 0.5) - (glowPower / 0.5);\n" + //计算glow
251
+ " vec4 glowColor;\n" +
252
+ " glowColor.rgb = max(vec3(glow - 1.0 + material.diffuse), material.diffuse);\n" +
253
+ " glowColor.a = clamp(0.0, 1.0, glow) * material.alpha;\n" +
254
+ " glowColor = czm_gammaCorrect(glowColor);\n" +
255
+ " material.emission = glowColor.rgb;\n" +
256
+ " material.alpha = glowColor.a;\n" +
257
+ " }\n" +
258
+ " return material;\n" +
259
+ "}",
260
+ },
261
+ translucent: function (material) {
262
+ const uniforms = material.uniforms;
263
+ return uniforms.color.alpha < 1.0 || uniforms.trailColor.alpha < 1.0;
264
+ }
265
+ });
266
+
267
+ //定义ImageTransformType
268
+ const ImageTransformType = 'ImageTransform';
269
+
270
+ /**
271
+ * ImageTransform 材质类型标识(基于贴图变换矩阵的材质)。
272
+ * @type {string}
273
+ * @constant
274
+ * @memberof Material
275
+ */
276
+ Material.ImageTransformType = ImageTransformType;
277
+ //添加ImageTransformType材质
278
+ Material._materialCache.addMaterial(ImageTransformType, {
279
+ //基于Cesium fabric语法构建材质
280
+ fabric: {
281
+ type: ImageTransformType, //材质类型
282
+ uniforms: { //接受的参数
283
+ image: Material.DefaultImageId, //普通uv贴图
284
+ stTransform: Matrix3.IDENTITY.clone(), //贴图变换矩阵
285
+ color: new Color(), //颜色
286
+ // translucent: true, //是否透明
287
+ },
288
+ source: "czm_material czm_getMaterial(czm_materialInput materialInput)\n" + //固定写法,重载czm_getMaterial函数
289
+ "{\n" +
290
+ " czm_material material = czm_getDefaultMaterial(materialInput);\n" + //获取默认材质
291
+ " vec2 st = materialInput.st;\n" + //获取uv
292
+ " st = fract((stTransform * vec3(st, 1.0)).xy);\n" + //计算变换后uv
293
+ " vec4 imageColor = texture(image, st);\n" + //从uv贴图中获取imageColor
294
+ " material.diffuse = imageColor.rgb * color.rgb;\n" + //与外部传入color相乘得到最终渲染color,material.diffuse为最终渲染至屏幕上的color
295
+ // " if (translucent)\n" +
296
+ " material.alpha = imageColor.a * color.a;\n" + //translucent开启,则alpha值也相乘
297
+ // " else\n" +
298
+ // " material.alpha = imageColor.a;\n" + //translucent未开启
299
+ " return material;\n" +
300
+ "}",
301
+ },
302
+ translucent: function (material) {
303
+ return material.uniforms.color.alpha < 1.0;
304
+ }
305
+ });
306
+
307
+ export default Material;
308
+ export { Material, MaterialProperty };