@cesium/engine 17.0.0 → 18.0.1-splats.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 (188) hide show
  1. package/Build/ThirdParty/Workers/z-worker-pako.js +1 -1
  2. package/Build/Workers/{chunk-UC7KH56Y.js → chunk-2AXKROJA.js} +5 -5
  3. package/Build/Workers/{chunk-IKDQX7DY.js → chunk-2J5ZZ7CY.js} +4 -4
  4. package/Build/Workers/{chunk-4TIR5UPL.js → chunk-2SYY3UBI.js} +1 -1
  5. package/Build/Workers/{chunk-CC2WKHIW.js → chunk-2WKW3BEB.js} +6 -6
  6. package/Build/Workers/{chunk-CBFJVM6I.js → chunk-2ZO6BCHN.js} +11 -11
  7. package/Build/Workers/{chunk-7PHT4JHA.js → chunk-3UKG5X7F.js} +12 -12
  8. package/Build/Workers/{chunk-PM4Q36WX.js → chunk-4GYIDPXP.js} +9 -9
  9. package/Build/Workers/{chunk-QUFN3GEO.js → chunk-6EP7ED36.js} +3 -3
  10. package/Build/Workers/{chunk-QJTIOB2Z.js → chunk-6QOBORNG.js} +6 -6
  11. package/Build/Workers/{chunk-YE6MDFDA.js → chunk-6WWHK2ER.js} +14 -14
  12. package/Build/Workers/{chunk-RX65FA7X.js → chunk-6Y6TVYHS.js} +7 -7
  13. package/Build/Workers/{chunk-P2N5IDWU.js → chunk-744VWE2U.js} +13 -13
  14. package/Build/Workers/{chunk-LVGYWPEX.js → chunk-7PQ52XCW.js} +4 -4
  15. package/Build/Workers/{chunk-PS3OKVOQ.js → chunk-A5UFJW2M.js} +12 -12
  16. package/Build/Workers/{chunk-CAKU6ZPR.js → chunk-AQKVFTWV.js} +8 -8
  17. package/Build/Workers/{chunk-236N6BJN.js → chunk-BKTEHJFD.js} +2 -2
  18. package/Build/Workers/{chunk-5PC577K7.js → chunk-CQXYKPAW.js} +16 -16
  19. package/Build/Workers/{chunk-DRMXU674.js → chunk-DI7PHKC6.js} +5 -5
  20. package/Build/Workers/{chunk-CQMXZF4A.js → chunk-DKKIQS6F.js} +6 -6
  21. package/Build/Workers/{chunk-J2HTPGC7.js → chunk-DTVWE5YL.js} +2 -2
  22. package/Build/Workers/{chunk-SSLK4U3V.js → chunk-ERPS2WZC.js} +4 -4
  23. package/Build/Workers/chunk-EYMZ5FSQ.js +280 -0
  24. package/Build/Workers/{chunk-LPGOAMYH.js → chunk-F43TQW5B.js} +2 -2
  25. package/Build/Workers/{chunk-5RPUEFSA.js → chunk-FOMRN6II.js} +6 -6
  26. package/Build/Workers/{chunk-2BJXFXD7.js → chunk-FOTXJYKS.js} +4 -4
  27. package/Build/Workers/{chunk-VXAKU6EV.js → chunk-G2Y7EA4W.js} +5 -5
  28. package/Build/Workers/{chunk-KE45DUDH.js → chunk-GY4E4ZP6.js} +10 -10
  29. package/Build/Workers/{chunk-NZSBSY5K.js → chunk-HDG3VHYL.js} +2 -2
  30. package/Build/Workers/{chunk-WP3IJYLC.js → chunk-HOEUXPBL.js} +9 -9
  31. package/Build/Workers/{chunk-5YEFZMMM.js → chunk-IWDYVJ56.js} +12 -12
  32. package/Build/Workers/{chunk-SQKTLDSD.js → chunk-JA4KPQJL.js} +12 -12
  33. package/Build/Workers/{chunk-MAIKDIBS.js → chunk-JZZQEZMA.js} +6 -6
  34. package/Build/Workers/{chunk-77MDEA47.js → chunk-KPLU3WDY.js} +5 -5
  35. package/Build/Workers/{chunk-E7SMO47Q.js → chunk-LHM6V4D6.js} +5 -5
  36. package/Build/Workers/{chunk-HBNWBMAM.js → chunk-LMTGCD6P.js} +1 -1
  37. package/Build/Workers/{chunk-XYGBWBD5.js → chunk-LWZOYSSF.js} +1 -1
  38. package/Build/Workers/{chunk-OBHLT34A.js → chunk-M6U7SV4T.js} +7 -7
  39. package/Build/Workers/{chunk-MS5NWDHH.js → chunk-O25M56DO.js} +2 -2
  40. package/Build/Workers/{chunk-UX5JWAC7.js → chunk-OE2WXO2Z.js} +10 -10
  41. package/Build/Workers/{chunk-C5DCX2YQ.js → chunk-PFD462OE.js} +6 -6
  42. package/Build/Workers/{chunk-37PA7GZW.js → chunk-PPI33PXH.js} +7 -7
  43. package/Build/Workers/{chunk-4BGKMM7J.js → chunk-PRQQHLUB.js} +1 -1
  44. package/Build/Workers/{chunk-IFIS4CVK.js → chunk-RTUZ7MJB.js} +2 -2
  45. package/Build/Workers/{chunk-G6JUXZUO.js → chunk-S6QBTP5U.js} +4 -4
  46. package/Build/Workers/{chunk-UFV3YUIN.js → chunk-SMFCIGM3.js} +5 -5
  47. package/Build/Workers/{chunk-P57PR3WM.js → chunk-TC3LEKFJ.js} +5 -5
  48. package/Build/Workers/{chunk-7IIMO7ZZ.js → chunk-UTLYCPFY.js} +16 -16
  49. package/Build/Workers/{chunk-HGEGZ67N.js → chunk-V7LEBY53.js} +6 -6
  50. package/Build/Workers/{chunk-GO3RZX2R.js → chunk-VE3UKRDB.js} +9 -9
  51. package/Build/Workers/{chunk-ZTBZMRQT.js → chunk-W3FBD4FE.js} +8 -8
  52. package/Build/Workers/{chunk-K5JTWJPE.js → chunk-YRR6CJGG.js} +4 -4
  53. package/Build/Workers/{chunk-UZ6KXWCA.js → chunk-ZVTKMLU6.js} +4 -4
  54. package/Build/Workers/combineGeometry.js +21 -21
  55. package/Build/Workers/createBoxGeometry.js +15 -15
  56. package/Build/Workers/createBoxOutlineGeometry.js +13 -13
  57. package/Build/Workers/createCircleGeometry.js +23 -23
  58. package/Build/Workers/createCircleOutlineGeometry.js +16 -16
  59. package/Build/Workers/createCoplanarPolygonGeometry.js +30 -30
  60. package/Build/Workers/createCoplanarPolygonOutlineGeometry.js +28 -28
  61. package/Build/Workers/createCorridorGeometry.js +26 -26
  62. package/Build/Workers/createCorridorOutlineGeometry.js +25 -25
  63. package/Build/Workers/createCylinderGeometry.js +17 -17
  64. package/Build/Workers/createCylinderOutlineGeometry.js +15 -15
  65. package/Build/Workers/createEllipseGeometry.js +23 -23
  66. package/Build/Workers/createEllipseOutlineGeometry.js +16 -16
  67. package/Build/Workers/createEllipsoidGeometry.js +16 -16
  68. package/Build/Workers/createEllipsoidOutlineGeometry.js +15 -15
  69. package/Build/Workers/createFrustumGeometry.js +15 -15
  70. package/Build/Workers/createFrustumOutlineGeometry.js +15 -15
  71. package/Build/Workers/createGeometry.js +23 -21
  72. package/Build/Workers/createGroundPolylineGeometry.js +19 -19
  73. package/Build/Workers/createPlaneGeometry.js +13 -13
  74. package/Build/Workers/createPlaneOutlineGeometry.js +12 -12
  75. package/Build/Workers/createPolygonGeometry.js +29 -29
  76. package/Build/Workers/createPolygonOutlineGeometry.js +27 -27
  77. package/Build/Workers/createPolylineGeometry.js +22 -22
  78. package/Build/Workers/createPolylineVolumeGeometry.js +28 -28
  79. package/Build/Workers/createPolylineVolumeOutlineGeometry.js +24 -24
  80. package/Build/Workers/createRectangleGeometry.js +24 -24
  81. package/Build/Workers/createRectangleOutlineGeometry.js +17 -17
  82. package/Build/Workers/createSimplePolylineGeometry.js +20 -20
  83. package/Build/Workers/createSphereGeometry.js +16 -16
  84. package/Build/Workers/createSphereOutlineGeometry.js +15 -15
  85. package/Build/Workers/createTaskProcessorWorker.js +3 -3
  86. package/Build/Workers/createVectorTileClampedPolylines.js +12 -12
  87. package/Build/Workers/createVectorTileGeometries.js +21 -21
  88. package/Build/Workers/createVectorTilePoints.js +11 -11
  89. package/Build/Workers/createVectorTilePolygons.js +19 -19
  90. package/Build/Workers/createVectorTilePolylines.js +12 -12
  91. package/Build/Workers/createVerticesFromGoogleEarthEnterpriseBuffer.js +19 -19
  92. package/Build/Workers/createVerticesFromHeightmap.js +19 -19
  93. package/Build/Workers/createVerticesFromQuantizedTerrainMesh.js +16 -16
  94. package/Build/Workers/createWallGeometry.js +21 -21
  95. package/Build/Workers/createWallOutlineGeometry.js +20 -20
  96. package/Build/Workers/decodeDraco.js +10 -10
  97. package/Build/Workers/decodeGoogleEarthEnterprisePacket.js +5 -5
  98. package/Build/Workers/decodeI3S.js +9 -9
  99. package/Build/Workers/gaussianSplatSorter.js +62 -0
  100. package/Build/Workers/gaussianSplatTextureGenerator.js +68 -0
  101. package/Build/Workers/transcodeKTX2.js +78 -7
  102. package/Build/Workers/transferTypedArrayTest.js +1 -1
  103. package/Build/Workers/upsampleQuantizedTerrainMesh.js +19 -19
  104. package/Source/Core/Ion.js +1 -1
  105. package/Source/Core/PixelFormat.js +98 -0
  106. package/Source/Renderer/Context.js +2 -0
  107. package/Source/Renderer/Pass.js +3 -2
  108. package/Source/Renderer/Texture.js +1 -0
  109. package/Source/Renderer/Texture3D.js +568 -0
  110. package/Source/Renderer/VertexArray.js +33 -8
  111. package/Source/Renderer/createUniform.js +3 -0
  112. package/Source/Renderer/createUniformArray.js +1 -0
  113. package/Source/Scene/ArcGisMapService.js +1 -1
  114. package/Source/Scene/Cesium3DTileContentFactory.js +23 -0
  115. package/Source/Scene/Cesium3DTileset.js +197 -2
  116. package/Source/Scene/GaussianSplat3DTileContent.js +504 -0
  117. package/Source/Scene/GaussianSplatPrimitive.js +932 -0
  118. package/Source/Scene/GaussianSplatRenderResources.js +81 -0
  119. package/Source/Scene/GaussianSplatSorter.js +73 -0
  120. package/Source/Scene/GaussianSplatTextureGenerator.js +64 -0
  121. package/Source/Scene/GlobeSurfaceShaderSet.js +4 -5
  122. package/Source/Scene/GltfLoader.js +82 -4
  123. package/Source/Scene/GltfSpzLoader.js +222 -0
  124. package/Source/Scene/GltfVertexBufferLoader.js +98 -3
  125. package/Source/Scene/ImageryLayer.js +19 -4
  126. package/Source/Scene/ImageryLayerCollection.js +3 -2
  127. package/Source/Scene/Model/CartesianRectangle.js +108 -0
  128. package/Source/Scene/Model/ImageryConfiguration.js +25 -0
  129. package/Source/Scene/Model/ImageryCoverage.js +488 -0
  130. package/Source/Scene/Model/ImageryFlags.js +31 -0
  131. package/Source/Scene/Model/ImageryInput.js +60 -0
  132. package/Source/Scene/Model/ImageryPipelineStage.js +1040 -0
  133. package/Source/Scene/Model/MappedPositions.js +84 -0
  134. package/Source/Scene/Model/Model.js +38 -0
  135. package/Source/Scene/Model/ModelImagery.js +403 -0
  136. package/Source/Scene/Model/ModelImageryMapping.js +489 -0
  137. package/Source/Scene/Model/ModelPrimitiveImagery.js +972 -0
  138. package/Source/Scene/Model/ModelReader.js +810 -0
  139. package/Source/Scene/Model/ModelRenderResources.js +13 -0
  140. package/Source/Scene/Model/ModelRuntimePrimitive.js +20 -0
  141. package/Source/Scene/Model/ModelSceneGraph.js +133 -27
  142. package/Source/Scene/Model/ModelUtility.js +2 -0
  143. package/Source/Scene/Model/NodeRenderResources.js +10 -0
  144. package/Source/Scene/ModelComponents.js +10 -0
  145. package/Source/Scene/PrimitiveLoadPlan.js +59 -0
  146. package/Source/Scene/ResourceCache.js +60 -3
  147. package/Source/Scene/ResourceCacheKey.js +39 -1
  148. package/Source/Scene/Scene.js +32 -1
  149. package/Source/Scene/VertexAttributeSemantic.js +30 -0
  150. package/Source/Scene/VoxelPrimitive.js +22 -37
  151. package/Source/Scene/VoxelRenderResources.js +1 -1
  152. package/Source/Scene/processVoxelProperties.js +41 -100
  153. package/Source/Shaders/Builtin/Constants/passGaussianSplats.glsl +9 -0
  154. package/Source/Shaders/Builtin/Constants/passGaussianSplats.js +11 -0
  155. package/Source/Shaders/Builtin/Constants/passOverlay.glsl +1 -1
  156. package/Source/Shaders/Builtin/Constants/passOverlay.js +1 -1
  157. package/Source/Shaders/Builtin/CzmBuiltins.js +2 -0
  158. package/Source/Shaders/Builtin/Functions/windowToEyeCoordinates.glsl +0 -1
  159. package/Source/Shaders/Builtin/Functions/windowToEyeCoordinates.js +0 -1
  160. package/Source/Shaders/GlobeFS.glsl +22 -0
  161. package/Source/Shaders/GlobeFS.js +22 -0
  162. package/Source/Shaders/Model/MaterialStageFS.glsl +4 -0
  163. package/Source/Shaders/Model/MaterialStageFS.js +4 -0
  164. package/Source/Shaders/Model/ModelFS.glsl +3 -1
  165. package/Source/Shaders/Model/ModelFS.js +3 -1
  166. package/Source/Shaders/Model/ModelVS.glsl +5 -1
  167. package/Source/Shaders/Model/ModelVS.js +5 -1
  168. package/Source/Shaders/Model/PointCloudStylingStageVS.glsl +1 -1
  169. package/Source/Shaders/Model/PointCloudStylingStageVS.js +2 -1
  170. package/Source/Shaders/PrimitiveGaussianSplatFS.glsl +18 -0
  171. package/Source/Shaders/PrimitiveGaussianSplatFS.js +20 -0
  172. package/Source/Shaders/PrimitiveGaussianSplatVS.glsl +108 -0
  173. package/Source/Shaders/PrimitiveGaussianSplatVS.js +109 -0
  174. package/Source/Shaders/Voxels/IntersectDepth.glsl +10 -3
  175. package/Source/Shaders/Voxels/IntersectDepth.js +10 -3
  176. package/Source/Shaders/Voxels/Intersection.glsl +1 -3
  177. package/Source/Shaders/Voxels/Intersection.js +1 -3
  178. package/Source/Shaders/Voxels/IntersectionUtils.glsl +1 -0
  179. package/Source/Shaders/Voxels/IntersectionUtils.js +1 -0
  180. package/Source/Shaders/Voxels/VoxelFS.glsl +37 -24
  181. package/Source/Shaders/Voxels/VoxelFS.js +37 -24
  182. package/Source/ThirdParty/Workers/z-worker-pako.js +1 -1
  183. package/Source/ThirdParty/wasm_splats_bg.wasm +0 -0
  184. package/Source/Workers/gaussianSplatSorter.js +34 -0
  185. package/Source/Workers/gaussianSplatTextureGenerator.js +39 -0
  186. package/index.d.ts +66 -2
  187. package/index.js +101 -80
  188. package/package.json +6 -4
@@ -0,0 +1,489 @@
1
+ import defined from "../../Core/defined.js";
2
+ import Cartesian2 from "../../Core/Cartesian2.js";
3
+ import Cartesian3 from "../../Core/Cartesian3.js";
4
+ import Matrix4 from "../../Core/Matrix4.js";
5
+ import Rectangle from "../../Core/Rectangle.js";
6
+ import Cartographic from "../../Core/Cartographic.js";
7
+ import BoundingRectangle from "../../Core/BoundingRectangle.js";
8
+ import ComponentDatatype from "../../Core/ComponentDatatype.js";
9
+ import Check from "../../Core/Check.js";
10
+
11
+ import AttributeType from "../AttributeType.js";
12
+ import ModelReader from "./ModelReader.js";
13
+ import VertexAttributeSemantic from "../VertexAttributeSemantic.js";
14
+
15
+ /**
16
+ * A class for computing the texture coordinates of imagery that is
17
+ * supposed to be mapped on a <code>ModelComponents.Primitive</code>.
18
+ *
19
+ * @private
20
+ */
21
+ class ModelImageryMapping {
22
+ /**
23
+ * Creates a typed array that contains texture coordinates for
24
+ * the given <code>MappedPositions</code>, using the given
25
+ * projection.
26
+ *
27
+ * This will be a typed array that contains the texture coordinates
28
+ * that result from projecting the given positions with the given
29
+ * projection, and normalizing them to their bounding rectangle.
30
+ *
31
+ * @param {MappedPositions} mappedPositions The positions
32
+ * @param {MapProjection} projection The projection that should be used
33
+ * @returns {TypedArray} The result
34
+ */
35
+ static createTextureCoordinatesForMappedPositions(
36
+ mappedPositions,
37
+ projection,
38
+ ) {
39
+ //>>includeStart('debug', pragmas.debug);
40
+ Check.defined("mappedPositions", mappedPositions);
41
+ Check.defined("projection", projection);
42
+ //>>includeEnd('debug');
43
+
44
+ const cartographicPositions = mappedPositions.cartographicPositions;
45
+ const cartographicBoundingRectangle =
46
+ mappedPositions.cartographicBoundingRectangle;
47
+ const numPositions = mappedPositions.numPositions;
48
+ return ModelImageryMapping._createTextureCoordinates(
49
+ cartographicPositions,
50
+ numPositions,
51
+ cartographicBoundingRectangle,
52
+ projection,
53
+ );
54
+ }
55
+
56
+ /**
57
+ * Creates a typed array that contains texture coordinates for
58
+ * a primitive with the given positions, using the given
59
+ * projection.
60
+ *
61
+ * This will be a typed array of size <code>numPositions*2</code>
62
+ * that contains the texture coordinates that result from
63
+ * projecting the given positions with the given projection,
64
+ * and normalizing them to the given bounding rectangle.
65
+ *
66
+ * @param {Iterable<Cartographic>} cartographicPositions The
67
+ * cartographic positions
68
+ * @param {number} numPositions The number of positions (vertices)
69
+ * @param {Rectangle} cartographicBoundingRectangle The bounding
70
+ * rectangle of the cartographic positions
71
+ * @param {MapProjection} projection The projection that should be used
72
+ * @returns {TypedArray} The result
73
+ * @private
74
+ */
75
+ static _createTextureCoordinates(
76
+ cartographicPositions,
77
+ numPositions,
78
+ cartographicBoundingRectangle,
79
+ projection,
80
+ ) {
81
+ //>>includeStart('debug', pragmas.debug);
82
+ Check.defined("cartographicPositions", cartographicPositions);
83
+ Check.typeOf.number.greaterThanOrEquals("numPositions", numPositions, 0);
84
+ Check.defined(
85
+ "cartographicBoundingRectangle",
86
+ cartographicBoundingRectangle,
87
+ );
88
+ Check.defined("projection", projection);
89
+ //>>includeEnd('debug');
90
+
91
+ // Convert the bounding `Rectangle`(!) of the cartographic positions
92
+ // into a `BoundingRectangle`(!) using the given projection
93
+ const boundingRectangle = new BoundingRectangle();
94
+ BoundingRectangle.fromRectangle(
95
+ cartographicBoundingRectangle,
96
+ projection,
97
+ boundingRectangle,
98
+ );
99
+
100
+ // Compute the projected positions, using the given projection
101
+ const projectedPositions = ModelImageryMapping.createProjectedPositions(
102
+ cartographicPositions,
103
+ projection,
104
+ );
105
+
106
+ // Relativize the projected positions into the bounding rectangle
107
+ // to obtain texture coordinates
108
+ const texCoords = ModelImageryMapping.computeTexCoords(
109
+ projectedPositions,
110
+ boundingRectangle,
111
+ );
112
+
113
+ // Convert the texture coordinates into a typed array
114
+ const texCoordsTypedArray =
115
+ ModelImageryMapping.createTypedArrayFromCartesians2(
116
+ numPositions,
117
+ texCoords,
118
+ );
119
+
120
+ return texCoordsTypedArray;
121
+ }
122
+
123
+ /**
124
+ * Creates the `ModelComponents.Attribute` for the texture coordinates
125
+ * for a primitive
126
+ *
127
+ * This will create an attribute with
128
+ * - semantic: VertexAttributeSemantic.TEXCOORD
129
+ * - type: AttributeType.VEC2
130
+ * - count: mappedPositions.numPositions
131
+ * that contains the texture coordinates for the given vertex positions,
132
+ * after they are projected using the given projection, normalized to
133
+ * their bounding rectangle.
134
+ *
135
+ * @param {Iterable<Cartographic>} cartographicPositions The
136
+ * cartographic positions
137
+ * @param {number} numPositions The number of positions (vertices)
138
+ * @param {Rectangle} cartographicBoundingRectangle The bounding
139
+ * rectangle of the cartographic positions
140
+ * @param {MapProjection} projection The projection that should be used
141
+ * @returns {ModelComponents.Attribute} The new attribute
142
+ */
143
+ static createTextureCoordinatesAttributeForMappedPositions(
144
+ mappedPositions,
145
+ projection,
146
+ ) {
147
+ //>>includeStart('debug', pragmas.debug);
148
+ Check.defined("mappedPositions", mappedPositions);
149
+ Check.defined("projection", projection);
150
+ //>>includeEnd('debug');
151
+
152
+ // Create the typed array that contains the texture coordinates
153
+ const texCoordsTypedArray =
154
+ ModelImageryMapping.createTextureCoordinatesForMappedPositions(
155
+ mappedPositions,
156
+ projection,
157
+ );
158
+
159
+ // Create an attribute from the texture coordinates typed array
160
+ const texCoordAttribute =
161
+ ModelImageryMapping.createTexCoordAttribute(texCoordsTypedArray);
162
+
163
+ return texCoordAttribute;
164
+ }
165
+
166
+ /**
167
+ * Create an iterable that provides the cartographic positions
168
+ * of the given POSITION attribute, based on the given ellipsoid
169
+ *
170
+ * @param {ModelComponents.Attribute} primitivePositionAttribute
171
+ * The "POSITION" attribute of the primitive.
172
+ * @param {Matrix4} primitivePositionTransform The full transform of the primitive
173
+ * @param {Elliposid} ellipsoid The ellipsoid that should be used
174
+ * @returns {Iterable<Cartographic>} The iterable over `Cartographic` objects
175
+ */
176
+ static createCartographicPositions(
177
+ primitivePositionAttribute,
178
+ primitivePositionTransform,
179
+ ellipsoid,
180
+ ) {
181
+ //>>includeStart('debug', pragmas.debug);
182
+ Check.defined("primitivePositionAttribute", primitivePositionAttribute);
183
+ Check.defined("primitivePositionTransform", primitivePositionTransform);
184
+ Check.defined("ellipsoid", ellipsoid);
185
+ //>>includeEnd('debug');
186
+
187
+ // Extract the positions as a typed array
188
+ const typedArray = ModelReader.readAttributeAsTypedArray(
189
+ primitivePositionAttribute,
190
+ );
191
+
192
+ // Create an iterable over the positions
193
+ const type = primitivePositionAttribute.type;
194
+ const numComponents = AttributeType.getNumberOfComponents(type);
195
+ const positions =
196
+ ModelImageryMapping.createIterableCartesian3FromTypedArray(
197
+ typedArray,
198
+ numComponents,
199
+ );
200
+
201
+ // Compute the positions after they are transformed with the given matrix
202
+ const transformedPositions = ModelImageryMapping.transformCartesians3(
203
+ positions,
204
+ primitivePositionTransform,
205
+ );
206
+
207
+ // Compute the cartographic positions for the given ellipsoid
208
+ const cartographicPositions = ModelImageryMapping.transformToCartographic(
209
+ transformedPositions,
210
+ ellipsoid,
211
+ );
212
+ return cartographicPositions;
213
+ }
214
+
215
+ /**
216
+ * Creates an iterable over `Cartesian3` objects from the given
217
+ * typed array.
218
+ *
219
+ * The resulting iterable will always return the same `Cartesian3`
220
+ * object. Clients should not store and modify this object.
221
+ *
222
+ * @param {TypedArray} typedArray The typed array
223
+ * @param {number} stride The stride between to consecutive
224
+ * `Cartesian3` elements in the given array. Must be at least 3.
225
+ * @returns {Iterable<Cartesian3>} The iterable
226
+ */
227
+ static createIterableCartesian3FromTypedArray(typedArray, stride) {
228
+ //>>includeStart('debug', pragmas.debug);
229
+ Check.defined("typedArray", typedArray);
230
+ Check.typeOf.number.greaterThanOrEquals("stride", stride, 3);
231
+ //>>includeEnd('debug');
232
+
233
+ const cartesian = new Cartesian3();
234
+ const numElements = typedArray.length / stride;
235
+ const result = {
236
+ [Symbol.iterator]: function* () {
237
+ for (let i = 0; i < numElements; i++) {
238
+ cartesian.x = typedArray[i * stride + 0];
239
+ cartesian.y = typedArray[i * stride + 1];
240
+ cartesian.z = typedArray[i * stride + 2];
241
+ yield cartesian;
242
+ }
243
+ },
244
+ };
245
+ return result;
246
+ }
247
+
248
+ /**
249
+ * Creates a new iterable that applies the given mapper to the given iterable.
250
+ *
251
+ * @param {Iterable} iterable The input iterable
252
+ * @param {Function} mapper The mapper
253
+ * @returns {Iterable} The mapped iterable
254
+ */
255
+ static map(iterable, mapper) {
256
+ //>>includeStart('debug', pragmas.debug);
257
+ Check.defined("iterable", iterable);
258
+ Check.defined("mapper", mapper);
259
+ //>>includeEnd('debug');
260
+
261
+ const result = {
262
+ [Symbol.iterator]: function* () {
263
+ for (const element of iterable) {
264
+ yield mapper(element);
265
+ }
266
+ },
267
+ };
268
+ return result;
269
+ }
270
+
271
+ /**
272
+ * Computes the bounding rectangle of the given cartographic positions,
273
+ * stores it in the given result, and returns it.
274
+ *
275
+ * If the given result is `undefined`, a new rectangle will be created
276
+ * and returned.
277
+ *
278
+ * @param {Iterable<Cartographic>} cartographicPositions The cartographics
279
+ * @param {Rectangle} [result] The result
280
+ * @returns {Rectangle} The result
281
+ */
282
+ static computeCartographicBoundingRectangle(cartographicPositions, result) {
283
+ //>>includeStart('debug', pragmas.debug);
284
+ Check.defined("cartographicPositions", cartographicPositions);
285
+ //>>includeEnd('debug');
286
+
287
+ if (!defined(result)) {
288
+ result = new Rectangle();
289
+ }
290
+ // One could store these directly in the result, but that would
291
+ // violate the constraint of the PI-related ranges..
292
+ let north = Number.NEGATIVE_INFINITY;
293
+ let south = Number.POSITIVE_INFINITY;
294
+ let east = Number.NEGATIVE_INFINITY;
295
+ let west = Number.POSITIVE_INFINITY;
296
+ for (const cartographicPosition of cartographicPositions) {
297
+ north = Math.max(north, cartographicPosition.latitude);
298
+ south = Math.min(south, cartographicPosition.latitude);
299
+ east = Math.max(east, cartographicPosition.longitude);
300
+ west = Math.min(west, cartographicPosition.longitude);
301
+ }
302
+ result.north = north;
303
+ result.south = south;
304
+ result.east = east;
305
+ result.west = west;
306
+ return result;
307
+ }
308
+
309
+ /**
310
+ * Creates a new iterable that provides `Cartesian3` objects that
311
+ * are created by transforming the `Cartesian3` objects of the
312
+ * given iterable with the given matrix.
313
+ *
314
+ * The resulting iterable will always return the same `Cartesian3`
315
+ * object. Clients should not store and modify this object.
316
+ *
317
+ * @param {Iterable<Cartesian3>} positions The positions
318
+ * @param {Matrix4} matrix The matrix
319
+ * @returns {Iterable<Cartesian3>} The transformed cartesians
320
+ */
321
+ static transformCartesians3(positions, matrix) {
322
+ //>>includeStart('debug', pragmas.debug);
323
+ Check.defined("positions", positions);
324
+ Check.defined("matrix", matrix);
325
+ //>>includeEnd('debug');
326
+
327
+ const transformedPosition = new Cartesian3();
328
+ const transformedPositions = ModelImageryMapping.map(positions, (p) => {
329
+ Matrix4.multiplyByPoint(matrix, p, transformedPosition);
330
+ return transformedPosition;
331
+ });
332
+ return transformedPositions;
333
+ }
334
+
335
+ /**
336
+ * Creates a new iterable that provides `Cartographic` objects that
337
+ * are created by converting the given `Cartesian3` objects to
338
+ * cartographics, based on the given ellipsoid.
339
+ *
340
+ * The resulting iterable will always return the same `Cartographic`
341
+ * object. Clients should not store and modify this object.
342
+ *
343
+ * @param {Iterable<Cartesian3>} positions The positions
344
+ * @param {Ellipsoid} ellipsoid The ellipsoid
345
+ * @returns {Iterable<Cartographic>} The cartographic positions
346
+ */
347
+ static transformToCartographic(positions, ellipsoid) {
348
+ //>>includeStart('debug', pragmas.debug);
349
+ Check.defined("positions", positions);
350
+ Check.defined("ellipsoid", ellipsoid);
351
+ //>>includeEnd('debug');
352
+
353
+ const cartographicPosition = new Cartographic();
354
+ const cartographicPositions = ModelImageryMapping.map(positions, (p) => {
355
+ // Note: This will not yield valid results for p=(0,0,0).
356
+ // But there is no sensible cartographic position for
357
+ // that, so simply accept the unspecified output here.
358
+ ellipsoid.cartesianToCartographic(p, cartographicPosition);
359
+ return cartographicPosition;
360
+ });
361
+ return cartographicPositions;
362
+ }
363
+
364
+ /**
365
+ * Creates an iterable over the results of applying the given projection
366
+ * to the given cartographic positions.
367
+ *
368
+ * The resulting iterable will always return the same `Cartesian3`
369
+ * object. Clients should not store and modify this object.
370
+ *
371
+ * @param {Iterable<Cartographic>} cartographicPositions The cartographic
372
+ * positions
373
+ * @param {MapProjection} projection The projection to use
374
+ * @returns {Iterable<Cartesian3>} The projected positions
375
+ */
376
+ static createProjectedPositions(cartographicPositions, projection) {
377
+ //>>includeStart('debug', pragmas.debug);
378
+ Check.defined("cartographicPositions", cartographicPositions);
379
+ Check.defined("projection", projection);
380
+ //>>includeEnd('debug');
381
+
382
+ const projectedPosition = new Cartesian3();
383
+ const projectedPositions = ModelImageryMapping.map(
384
+ cartographicPositions,
385
+ (c) => {
386
+ projection.project(c, projectedPosition);
387
+ return projectedPosition;
388
+ },
389
+ );
390
+ return projectedPositions;
391
+ }
392
+
393
+ /**
394
+ * Computes the texture coordinates for the given positions, relative
395
+ * to the given bounding rectangle.
396
+ *
397
+ * This will make the x/y coordinates of the given cartesians relative
398
+ * to the given bounding rectangle and clamp them to [0,0]-[1,1].
399
+ *
400
+ * NOTE: This could be broken down into
401
+ * 1. mapping to 2D
402
+ * 2. relativizing for the bounding recangle
403
+ * 3. clamping to [0,0]-[1,1]
404
+ *
405
+ * @param {Iterable<Cartesian3>} positions The positions
406
+ * @param {BoundingRectangle} boundingRectangle The rectangle
407
+ * @returns {Iterable<Cartesian2>} The texture coordinates
408
+ */
409
+ static computeTexCoords(positions, boundingRectangle) {
410
+ //>>includeStart('debug', pragmas.debug);
411
+ Check.defined("positions", positions);
412
+ Check.defined("boundingRectangle", boundingRectangle);
413
+ //>>includeEnd('debug');
414
+
415
+ const texCoord = new Cartesian2();
416
+ const invSizeX = 1.0 / boundingRectangle.width;
417
+ const invSizeY = 1.0 / boundingRectangle.height;
418
+ const texCoords = ModelImageryMapping.map(positions, (p) => {
419
+ const uRaw = (p.x - boundingRectangle.x) * invSizeX;
420
+ const vRaw = (p.y - boundingRectangle.y) * invSizeY;
421
+ const u = Math.min(Math.max(uRaw, 0.0), 1.0);
422
+ const v = Math.min(Math.max(vRaw, 0.0), 1.0);
423
+ texCoord.x = u;
424
+ texCoord.y = v;
425
+ return texCoord;
426
+ });
427
+ return texCoords;
428
+ }
429
+
430
+ /**
431
+ * Creates a new typed array from the given `Cartesian2` objects.
432
+ *
433
+ * @param {number} numElements The number of elements
434
+ * @param {Iterable<Cartesian2>} elements The elements
435
+ * @returns {TypedArray} The typed array
436
+ */
437
+ static createTypedArrayFromCartesians2(numElements, elements) {
438
+ //>>includeStart('debug', pragmas.debug);
439
+ Check.typeOf.number.greaterThanOrEquals("numElements", numElements, 0);
440
+ Check.defined("elements", elements);
441
+ //>>includeEnd('debug');
442
+
443
+ const typedArray = new Float32Array(numElements * 2);
444
+ let index = 0;
445
+ for (const element of elements) {
446
+ typedArray[index * 2 + 0] = element.x;
447
+ typedArray[index * 2 + 1] = element.y;
448
+ index++;
449
+ }
450
+ return typedArray;
451
+ }
452
+
453
+ /**
454
+ * Create a new texture coordinates attribute from the given data.
455
+ *
456
+ * This will create an attribute with
457
+ * - semantic: VertexAttributeSemantic.TEXCOORD
458
+ * - type: AttributeType.VEC2
459
+ * - count: texCoordsTypedArray.length / 2
460
+ * that contains the data from the given typed array.
461
+ *
462
+ * @param {TypedArray} texCoordsTypedArray The typed array
463
+ * @returns {ModelComponents.Attribute} The attribute
464
+ */
465
+ static createTexCoordAttribute(texCoordsTypedArray) {
466
+ //>>includeStart('debug', pragmas.debug);
467
+ Check.defined("texCoordsTypedArray", texCoordsTypedArray);
468
+ //>>includeEnd('debug');
469
+
470
+ const texCoordAttribute = {
471
+ name: "Imagery Texture Coordinates",
472
+ semantic: VertexAttributeSemantic.TEXCOORD,
473
+ setIndex: 0,
474
+ componentDatatype: ComponentDatatype.FLOAT,
475
+ type: AttributeType.VEC2,
476
+ normalized: false,
477
+ count: texCoordsTypedArray.length / 2,
478
+ min: undefined,
479
+ max: undefined,
480
+ constant: new Cartesian2(0, 0),
481
+ quantization: undefined,
482
+ typedArray: texCoordsTypedArray,
483
+ byteOffset: 0,
484
+ byteStride: undefined,
485
+ };
486
+ return texCoordAttribute;
487
+ }
488
+ }
489
+ export default ModelImageryMapping;