@rtzh/engine 0.0.3 → 0.0.4

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 (172) hide show
  1. package/Build/ThirdParty/Workers/zip-web-worker.js +640 -0
  2. package/Build/Workers/chunk-245NZYCR.js +124 -0
  3. package/Build/Workers/chunk-25BA4527.js +837 -0
  4. package/Build/Workers/chunk-2APW7KRS.js +101 -0
  5. package/Build/Workers/chunk-2BLQ3B4Q.js +299 -0
  6. package/Build/Workers/chunk-2CAIFJD5.js +387 -0
  7. package/Build/Workers/chunk-3K2PK2OU.js +1045 -0
  8. package/Build/Workers/chunk-3M5CRHSG.js +288 -0
  9. package/Build/Workers/chunk-4HXPSZRC.js +1483 -0
  10. package/Build/Workers/chunk-4Z26IS65.js +3514 -0
  11. package/Build/Workers/chunk-55IROWAX.js +139 -0
  12. package/Build/Workers/chunk-56XTN5NJ.js +1800 -0
  13. package/Build/Workers/chunk-5BIQOSBV.js +55 -0
  14. package/Build/Workers/chunk-5CSRWY7L.js +280 -0
  15. package/Build/Workers/chunk-5QTPACZQ.js +455 -0
  16. package/Build/Workers/chunk-5VZISKJF.js +629 -0
  17. package/Build/Workers/chunk-5WAG5YKS.js +368 -0
  18. package/Build/Workers/chunk-64W2RXA4.js +219 -0
  19. package/Build/Workers/chunk-66YGZWBI.js +1317 -0
  20. package/Build/Workers/chunk-6H33B6OL.js +37 -0
  21. package/Build/Workers/chunk-6LZBBEA7.js +439 -0
  22. package/Build/Workers/chunk-6QVMKRJ4.js +3514 -0
  23. package/Build/Workers/chunk-6XJO625E.js +497 -0
  24. package/Build/Workers/chunk-75UGCVME.js +102 -0
  25. package/Build/Workers/chunk-7B23DD46.js +1054 -0
  26. package/Build/Workers/chunk-7NCJH26L.js +352 -0
  27. package/Build/Workers/chunk-ACH67MPW.js +1483 -0
  28. package/Build/Workers/chunk-AIW5F22O.js +352 -0
  29. package/Build/Workers/chunk-AL22JVIA.js +256 -0
  30. package/Build/Workers/chunk-AVSQILVI.js +75 -0
  31. package/Build/Workers/chunk-B2VFNYD7.js +280 -0
  32. package/Build/Workers/chunk-BJ6WXQOW.js +305 -0
  33. package/Build/Workers/chunk-BN4WA7LX.js +75 -0
  34. package/Build/Workers/chunk-BOV6T7FO.js +44 -0
  35. package/Build/Workers/chunk-BXBGWQ3Z.js +171 -0
  36. package/Build/Workers/chunk-D7TGILR3.js +1054 -0
  37. package/Build/Workers/chunk-DBKYAGM6.js +1800 -0
  38. package/Build/Workers/chunk-DEIMB3B5.js +629 -0
  39. package/Build/Workers/chunk-DP76S3IQ.js +1067 -0
  40. package/Build/Workers/chunk-DSBEWMOQ.js +1067 -0
  41. package/Build/Workers/chunk-E2CARZA7.js +73 -0
  42. package/Build/Workers/chunk-EDIUN7V3.js +219 -0
  43. package/Build/Workers/chunk-EISI2CR2.js +2058 -0
  44. package/Build/Workers/chunk-EKMWNF4U.js +55 -0
  45. package/Build/Workers/chunk-ELXGXAYS.js +682 -0
  46. package/Build/Workers/chunk-F5LAPCFC.js +1460 -0
  47. package/Build/Workers/chunk-FJREGHFG.js +138 -0
  48. package/Build/Workers/chunk-FVYRV2T6.js +455 -0
  49. package/Build/Workers/chunk-GDIBU55R.js +778 -0
  50. package/Build/Workers/chunk-HAWJ7FMN.js +8366 -0
  51. package/Build/Workers/chunk-HAY6YE7M.js +97 -0
  52. package/Build/Workers/chunk-HGIGANIQ.js +163 -0
  53. package/Build/Workers/chunk-HI6X33GO.js +58 -0
  54. package/Build/Workers/chunk-HU5P7PMU.js +1317 -0
  55. package/Build/Workers/chunk-I76SRIKN.js +138 -0
  56. package/Build/Workers/chunk-IDVURFRN.js +241 -0
  57. package/Build/Workers/chunk-IELTSYPZ.js +241 -0
  58. package/Build/Workers/chunk-J3FBVUY4.js +37 -0
  59. package/Build/Workers/chunk-J4MIJCN5.js +171 -0
  60. package/Build/Workers/chunk-JFO3ELF3.js +642 -0
  61. package/Build/Workers/chunk-JH27ZGLN.js +352 -0
  62. package/Build/Workers/chunk-JURLMTV2.js +398 -0
  63. package/Build/Workers/chunk-K4IMD7KH.js +162 -0
  64. package/Build/Workers/chunk-KBAGFNQ4.js +139 -0
  65. package/Build/Workers/chunk-KFMCOG26.js +692 -0
  66. package/Build/Workers/chunk-KH2OWUUA.js +163 -0
  67. package/Build/Workers/chunk-KHKSE4WQ.js +778 -0
  68. package/Build/Workers/chunk-KKYQRQ57.js +368 -0
  69. package/Build/Workers/chunk-KQIZ7AFF.js +8366 -0
  70. package/Build/Workers/chunk-KUAWPGSB.js +511 -0
  71. package/Build/Workers/chunk-KVDSJXRK.js +114 -0
  72. package/Build/Workers/chunk-KVE5EAPO.js +398 -0
  73. package/Build/Workers/chunk-KXB3AARU.js +162 -0
  74. package/Build/Workers/chunk-LN4NMLYY.js +55 -0
  75. package/Build/Workers/chunk-LPM2FVDN.js +642 -0
  76. package/Build/Workers/chunk-MLFVICFZ.js +102 -0
  77. package/Build/Workers/chunk-MQ62ZE2U.js +124 -0
  78. package/Build/Workers/chunk-NOH3R3YY.js +198 -0
  79. package/Build/Workers/chunk-OAOREOSO.js +940 -0
  80. package/Build/Workers/chunk-OFJRMGNX.js +788 -0
  81. package/Build/Workers/chunk-OOB2KZC6.js +476 -0
  82. package/Build/Workers/chunk-OVPPHDU7.js +97 -0
  83. package/Build/Workers/chunk-P7M4VYFT.js +788 -0
  84. package/Build/Workers/chunk-PHB5MRHM.js +439 -0
  85. package/Build/Workers/chunk-PLLZB3R4.js +198 -0
  86. package/Build/Workers/chunk-POY6ZE32.js +2058 -0
  87. package/Build/Workers/chunk-PV5B2YNB.js +2719 -0
  88. package/Build/Workers/chunk-Q2DXNFYW.js +414 -0
  89. package/Build/Workers/chunk-QWV2DM66.js +1443 -0
  90. package/Build/Workers/chunk-R73BHGGI.js +305 -0
  91. package/Build/Workers/chunk-S3AE3MZZ.js +511 -0
  92. package/Build/Workers/chunk-SBFTVHRW.js +57 -0
  93. package/Build/Workers/chunk-SOR7PD4V.js +114 -0
  94. package/Build/Workers/chunk-TDI7UQBO.js +57 -0
  95. package/Build/Workers/chunk-TO7TWUET.js +476 -0
  96. package/Build/Workers/chunk-TSAJNE4K.js +101 -0
  97. package/Build/Workers/chunk-TWF4XRZ6.js +73 -0
  98. package/Build/Workers/chunk-U364CIW4.js +682 -0
  99. package/Build/Workers/chunk-UOD5YNH3.js +940 -0
  100. package/Build/Workers/chunk-UTWLMOPM.js +387 -0
  101. package/Build/Workers/chunk-UUJXSLQ2.js +2719 -0
  102. package/Build/Workers/chunk-UYT2PBMV.js +58 -0
  103. package/Build/Workers/chunk-VIYQ56Z7.js +837 -0
  104. package/Build/Workers/chunk-VR2L2Y4Z.js +1443 -0
  105. package/Build/Workers/chunk-WAS3IHIQ.js +288 -0
  106. package/Build/Workers/chunk-WLREXLZ7.js +414 -0
  107. package/Build/Workers/chunk-WMGESUDW.js +497 -0
  108. package/Build/Workers/chunk-WO5ZNC7S.js +1045 -0
  109. package/Build/Workers/chunk-X65Y2JSA.js +55 -0
  110. package/Build/Workers/chunk-XJKMLTSH.js +692 -0
  111. package/Build/Workers/chunk-XOVHLPKW.js +299 -0
  112. package/Build/Workers/chunk-YBVMSCW4.js +352 -0
  113. package/Build/Workers/chunk-YPGJSFOO.js +1460 -0
  114. package/Build/Workers/chunk-Z356SW7E.js +256 -0
  115. package/Build/Workers/chunk-ZV42SJKS.js +44 -0
  116. package/Build/Workers/combineGeometry.js +66 -0
  117. package/Build/Workers/createBoxGeometry.js +58 -0
  118. package/Build/Workers/createBoxOutlineGeometry.js +231 -0
  119. package/Build/Workers/createCircleGeometry.js +201 -0
  120. package/Build/Workers/createCircleOutlineGeometry.js +147 -0
  121. package/Build/Workers/createCoplanarPolygonGeometry.js +505 -0
  122. package/Build/Workers/createCoplanarPolygonOutlineGeometry.js +225 -0
  123. package/Build/Workers/createCorridorGeometry.js +1258 -0
  124. package/Build/Workers/createCorridorOutlineGeometry.js +563 -0
  125. package/Build/Workers/createCylinderGeometry.js +60 -0
  126. package/Build/Workers/createCylinderOutlineGeometry.js +231 -0
  127. package/Build/Workers/createEllipseGeometry.js +72 -0
  128. package/Build/Workers/createEllipseOutlineGeometry.js +65 -0
  129. package/Build/Workers/createEllipsoidGeometry.js +59 -0
  130. package/Build/Workers/createEllipsoidOutlineGeometry.js +61 -0
  131. package/Build/Workers/createFrustumGeometry.js +58 -0
  132. package/Build/Workers/createFrustumOutlineGeometry.js +234 -0
  133. package/Build/Workers/createGeometry.js +173 -0
  134. package/Build/Workers/createGroundPolylineGeometry.js +1602 -0
  135. package/Build/Workers/createPlaneGeometry.js +223 -0
  136. package/Build/Workers/createPlaneOutlineGeometry.js +124 -0
  137. package/Build/Workers/createPolygonGeometry.js +1404 -0
  138. package/Build/Workers/createPolygonOutlineGeometry.js +532 -0
  139. package/Build/Workers/createPolylineGeometry.js +491 -0
  140. package/Build/Workers/createPolylineVolumeGeometry.js +374 -0
  141. package/Build/Workers/createPolylineVolumeOutlineGeometry.js +272 -0
  142. package/Build/Workers/createRectangleGeometry.js +1264 -0
  143. package/Build/Workers/createRectangleOutlineGeometry.js +476 -0
  144. package/Build/Workers/createSimplePolylineGeometry.js +397 -0
  145. package/Build/Workers/createSphereGeometry.js +116 -0
  146. package/Build/Workers/createSphereOutlineGeometry.js +116 -0
  147. package/Build/Workers/createTaskProcessorWorker.js +32 -0
  148. package/Build/Workers/createVectorTileClampedPolylines.js +492 -0
  149. package/Build/Workers/createVectorTileGeometries.js +387 -0
  150. package/Build/Workers/createVectorTilePoints.js +114 -0
  151. package/Build/Workers/createVectorTilePolygons.js +386 -0
  152. package/Build/Workers/createVectorTilePolylines.js +262 -0
  153. package/Build/Workers/createVerticesFromCesium3DTilesTerrain.js +91 -0
  154. package/Build/Workers/createVerticesFromGoogleEarthEnterpriseBuffer.js +565 -0
  155. package/Build/Workers/createVerticesFromHeightmap.js +2254 -0
  156. package/Build/Workers/createVerticesFromQuantizedTerrainMesh.js +499 -0
  157. package/Build/Workers/createWallGeometry.js +487 -0
  158. package/Build/Workers/createWallOutlineGeometry.js +335 -0
  159. package/Build/Workers/decodeDraco.js +369 -0
  160. package/Build/Workers/decodeGoogleEarthEnterprisePacket.js +2680 -0
  161. package/Build/Workers/decodeI3S.js +1339 -0
  162. package/Build/Workers/gaussianSplatSorter.js +62 -0
  163. package/Build/Workers/gaussianSplatTextureGenerator.js +68 -0
  164. package/Build/Workers/incrementallyBuildTerrainPicker.js +121 -0
  165. package/Build/Workers/transcodeKTX2.js +3463 -0
  166. package/Build/Workers/transferTypedArrayTest.js +41 -0
  167. package/Build/Workers/upsampleQuantizedTerrainMesh.js +820 -0
  168. package/Build/Workers/upsampleVerticesFromCesium3DTilesTerrain.js +95 -0
  169. package/Source/Scene/GltfLoader.js +2 -2
  170. package/Source/Scene/Model/I3dmLoader.js +2 -2
  171. package/index.js +110 -110
  172. package/package.json +1 -1
@@ -0,0 +1,1339 @@
1
+ /**
2
+ * @license
3
+ * Cesium - https://github.com/CesiumGS/cesium
4
+ * Version 0.0.4
5
+ *
6
+ * Copyright 2011-2022 Cesium Contributors
7
+ *
8
+ * Licensed under the Apache License, Version 2.0 (the "License");
9
+ * you may not use this file except in compliance with the License.
10
+ * You may obtain a copy of the License at
11
+ *
12
+ * http://www.apache.org/licenses/LICENSE-2.0
13
+ *
14
+ * Unless required by applicable law or agreed to in writing, software
15
+ * distributed under the License is distributed on an "AS IS" BASIS,
16
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
+ * See the License for the specific language governing permissions and
18
+ * limitations under the License.
19
+ *
20
+ * Columbus View (Pat. Pend.)
21
+ *
22
+ * Portions licensed separately.
23
+ * See https://github.com/CesiumGS/cesium/blob/main/LICENSE.md for full licensing details.
24
+ */
25
+
26
+ import {
27
+ require_draco_decoder_nodejs
28
+ } from "./chunk-DBKYAGM6.js";
29
+ import {
30
+ Color_default
31
+ } from "./chunk-LPM2FVDN.js";
32
+ import {
33
+ createTaskProcessorWorker_default
34
+ } from "./chunk-2APW7KRS.js";
35
+ import {
36
+ WebMercatorProjection_default
37
+ } from "./chunk-KVDSJXRK.js";
38
+ import {
39
+ Cartographic_default,
40
+ Ellipsoid_default
41
+ } from "./chunk-F5LAPCFC.js";
42
+ import {
43
+ Cartesian3_default,
44
+ Matrix3_default
45
+ } from "./chunk-VR2L2Y4Z.js";
46
+ import {
47
+ Math_default
48
+ } from "./chunk-WMGESUDW.js";
49
+ import {
50
+ Check_default
51
+ } from "./chunk-HGIGANIQ.js";
52
+ import {
53
+ __toESM,
54
+ defined_default
55
+ } from "./chunk-BN4WA7LX.js";
56
+
57
+ // packages/engine/Source/Workers/decodeI3S.js
58
+ var import_draco_decoder_nodejs = __toESM(require_draco_decoder_nodejs(), 1);
59
+
60
+ // packages/engine/Source/Core/srgbToLinear.js
61
+ function srgbToLinear(value) {
62
+ Check_default.defined("value", value);
63
+ if (value <= 0.04045) {
64
+ return value * 0.07739938080495357;
65
+ }
66
+ return Math.pow(
67
+ // eslint-disable-next-line no-loss-of-precision
68
+ (value + 0.055) * 0.9478672985781991,
69
+ 2.4
70
+ );
71
+ }
72
+ var srgbToLinear_default = srgbToLinear;
73
+
74
+ // packages/engine/Source/Workers/decodeI3S.js
75
+ var draco;
76
+ function bilinearInterpolate(tx, ty, h00, h10, h01, h11) {
77
+ const a = h00 * (1 - tx) + h10 * tx;
78
+ const b = h01 * (1 - tx) + h11 * tx;
79
+ return a * (1 - ty) + b * ty;
80
+ }
81
+ function sampleMap(u, v, width, data) {
82
+ const address = u + v * width;
83
+ return data[address];
84
+ }
85
+ function sampleGeoid(sampleX, sampleY, geoidData) {
86
+ const extent = geoidData.nativeExtent;
87
+ let x = (sampleX - extent.west) / (extent.east - extent.west) * (geoidData.width - 1);
88
+ let y = (sampleY - extent.south) / (extent.north - extent.south) * (geoidData.height - 1);
89
+ const xi = Math.floor(x);
90
+ let yi = Math.floor(y);
91
+ x -= xi;
92
+ y -= yi;
93
+ const xNext = xi < geoidData.width ? xi + 1 : xi;
94
+ let yNext = yi < geoidData.height ? yi + 1 : yi;
95
+ yi = geoidData.height - 1 - yi;
96
+ yNext = geoidData.height - 1 - yNext;
97
+ const h00 = sampleMap(xi, yi, geoidData.width, geoidData.buffer);
98
+ const h10 = sampleMap(xNext, yi, geoidData.width, geoidData.buffer);
99
+ const h01 = sampleMap(xi, yNext, geoidData.width, geoidData.buffer);
100
+ const h11 = sampleMap(xNext, yNext, geoidData.width, geoidData.buffer);
101
+ let finalHeight = bilinearInterpolate(x, y, h00, h10, h01, h11);
102
+ finalHeight = finalHeight * geoidData.scale + geoidData.offset;
103
+ return finalHeight;
104
+ }
105
+ function sampleGeoidFromList(lon, lat, geoidDataList) {
106
+ for (let i = 0; i < geoidDataList.length; i++) {
107
+ const localExtent = geoidDataList[i].nativeExtent;
108
+ let localPt = new Cartesian3_default();
109
+ if (geoidDataList[i].projectionType === "WebMercator") {
110
+ const radii = geoidDataList[i].projection._ellipsoid._radii;
111
+ const webMercatorProj = new WebMercatorProjection_default(
112
+ new Ellipsoid_default(radii.x, radii.y, radii.z)
113
+ );
114
+ localPt = webMercatorProj.project(new Cartographic_default(lon, lat, 0));
115
+ } else {
116
+ localPt.x = lon;
117
+ localPt.y = lat;
118
+ }
119
+ if (localPt.x > localExtent.west && localPt.x < localExtent.east && localPt.y > localExtent.south && localPt.y < localExtent.north) {
120
+ return sampleGeoid(localPt.x, localPt.y, geoidDataList[i]);
121
+ }
122
+ }
123
+ return 0;
124
+ }
125
+ function orthometricToEllipsoidal(vertexCount, position, scale_x, scale_y, center, geoidDataList, fast) {
126
+ if (fast) {
127
+ return;
128
+ }
129
+ const centerHeight = sampleGeoidFromList(
130
+ center.longitude,
131
+ center.latitude,
132
+ geoidDataList
133
+ );
134
+ for (let i = 0; i < vertexCount; ++i) {
135
+ const height = sampleGeoidFromList(
136
+ center.longitude + Math_default.toRadians(scale_x * position[i * 3]),
137
+ center.latitude + Math_default.toRadians(scale_y * position[i * 3 + 1]),
138
+ geoidDataList
139
+ );
140
+ position[i * 3 + 2] += height - centerHeight;
141
+ }
142
+ }
143
+ function transformToLocal(vertexCount, positions, normals, cartographicCenter, cartesianCenter, parentRotation, ellipsoidRadiiSquare, scale_x, scale_y) {
144
+ if (vertexCount === 0 || !defined_default(positions) || positions.length === 0) {
145
+ return;
146
+ }
147
+ const ellipsoid = new Ellipsoid_default(
148
+ Math.sqrt(ellipsoidRadiiSquare.x),
149
+ Math.sqrt(ellipsoidRadiiSquare.y),
150
+ Math.sqrt(ellipsoidRadiiSquare.z)
151
+ );
152
+ for (let i = 0; i < vertexCount; ++i) {
153
+ const indexOffset = i * 3;
154
+ const indexOffset1 = indexOffset + 1;
155
+ const indexOffset2 = indexOffset + 2;
156
+ const cartographic = new Cartographic_default();
157
+ cartographic.longitude = cartographicCenter.longitude + Math_default.toRadians(scale_x * positions[indexOffset]);
158
+ cartographic.latitude = cartographicCenter.latitude + Math_default.toRadians(scale_y * positions[indexOffset1]);
159
+ cartographic.height = cartographicCenter.height + positions[indexOffset2];
160
+ const position = {};
161
+ ellipsoid.cartographicToCartesian(cartographic, position);
162
+ position.x -= cartesianCenter.x;
163
+ position.y -= cartesianCenter.y;
164
+ position.z -= cartesianCenter.z;
165
+ const rotatedPosition = {};
166
+ Matrix3_default.multiplyByVector(parentRotation, position, rotatedPosition);
167
+ positions[indexOffset] = rotatedPosition.x;
168
+ positions[indexOffset1] = rotatedPosition.y;
169
+ positions[indexOffset2] = rotatedPosition.z;
170
+ if (defined_default(normals)) {
171
+ const normal = new Cartesian3_default(
172
+ normals[indexOffset],
173
+ normals[indexOffset1],
174
+ normals[indexOffset2]
175
+ );
176
+ const rotatedNormal = {};
177
+ Matrix3_default.multiplyByVector(parentRotation, normal, rotatedNormal);
178
+ normals[indexOffset] = rotatedNormal.x;
179
+ normals[indexOffset1] = rotatedNormal.y;
180
+ normals[indexOffset2] = rotatedNormal.z;
181
+ }
182
+ }
183
+ }
184
+ function cropUVs(vertexCount, uv0s, uvRegions) {
185
+ for (let vertexIndex = 0; vertexIndex < vertexCount; ++vertexIndex) {
186
+ const minU = uvRegions[vertexIndex * 4] / 65535;
187
+ const minV = uvRegions[vertexIndex * 4 + 1] / 65535;
188
+ const scaleU = (uvRegions[vertexIndex * 4 + 2] - uvRegions[vertexIndex * 4]) / 65535;
189
+ const scaleV = (uvRegions[vertexIndex * 4 + 3] - uvRegions[vertexIndex * 4 + 1]) / 65535;
190
+ uv0s[vertexIndex * 2] *= scaleU;
191
+ uv0s[vertexIndex * 2] += minU;
192
+ uv0s[vertexIndex * 2 + 1] *= scaleV;
193
+ uv0s[vertexIndex * 2 + 1] += minV;
194
+ }
195
+ }
196
+ function generateIndexArray(vertexCount, indices, colors, splitGeometryByColorTransparency) {
197
+ const indexArray = new Uint32Array(vertexCount);
198
+ const vertexIndexFn = defined_default(indices) ? (vertexIndex) => indices[vertexIndex] : (vertexIndex) => vertexIndex;
199
+ let transparentVertexOffset = 0;
200
+ if (splitGeometryByColorTransparency && defined_default(colors)) {
201
+ const isVertexTransparentFn = (vertexIndex) => colors[vertexIndexFn(vertexIndex) * 4 + 3] < 255;
202
+ for (let vertexIndex = 0; vertexIndex < vertexCount; vertexIndex += 3) {
203
+ if (!isVertexTransparentFn(vertexIndex) && !isVertexTransparentFn(vertexIndex + 1) && !isVertexTransparentFn(vertexIndex + 2)) {
204
+ indexArray[transparentVertexOffset++] = vertexIndexFn(vertexIndex);
205
+ indexArray[transparentVertexOffset++] = vertexIndexFn(vertexIndex + 1);
206
+ indexArray[transparentVertexOffset++] = vertexIndexFn(vertexIndex + 2);
207
+ }
208
+ }
209
+ if (transparentVertexOffset > 0) {
210
+ let offset = transparentVertexOffset;
211
+ for (let vertexIndex = 0; vertexIndex < vertexCount; vertexIndex += 3) {
212
+ if (isVertexTransparentFn(vertexIndex) || isVertexTransparentFn(vertexIndex + 1) || isVertexTransparentFn(vertexIndex + 2)) {
213
+ indexArray[offset++] = vertexIndexFn(vertexIndex);
214
+ indexArray[offset++] = vertexIndexFn(vertexIndex + 1);
215
+ indexArray[offset++] = vertexIndexFn(vertexIndex + 2);
216
+ }
217
+ }
218
+ } else {
219
+ for (let vertexIndex = 0; vertexIndex < vertexCount; ++vertexIndex) {
220
+ indexArray[vertexIndex] = vertexIndexFn(vertexIndex);
221
+ }
222
+ }
223
+ } else {
224
+ transparentVertexOffset = vertexCount;
225
+ for (let vertexIndex = 0; vertexIndex < vertexCount; ++vertexIndex) {
226
+ indexArray[vertexIndex] = vertexIndexFn(vertexIndex);
227
+ }
228
+ }
229
+ return {
230
+ indexArray,
231
+ transparentVertexOffset
232
+ };
233
+ }
234
+ function getFeatureHash(symbologyData, outlinesHash, featureIndex) {
235
+ const featureHash = outlinesHash[featureIndex];
236
+ if (defined_default(featureHash)) {
237
+ return featureHash;
238
+ }
239
+ const newFeatureHash = outlinesHash[featureIndex] = {
240
+ positions: {},
241
+ indices: {},
242
+ edges: {}
243
+ };
244
+ const featureSymbology = symbologyData[featureIndex] ?? symbologyData.default;
245
+ newFeatureHash.hasOutline = defined_default(featureSymbology?.edges);
246
+ return newFeatureHash;
247
+ }
248
+ function addVertexToHash(indexHash, positionHash, vertexIndex, positions) {
249
+ if (!defined_default(indexHash[vertexIndex])) {
250
+ const startPositionIndex = vertexIndex * 3;
251
+ let coordinateHash = positionHash;
252
+ for (let index = 0; index < 3; index++) {
253
+ const coordinate = positions[startPositionIndex + index];
254
+ if (!defined_default(coordinateHash[coordinate])) {
255
+ coordinateHash[coordinate] = {};
256
+ }
257
+ coordinateHash = coordinateHash[coordinate];
258
+ }
259
+ if (!defined_default(coordinateHash.index)) {
260
+ coordinateHash.index = vertexIndex;
261
+ }
262
+ indexHash[vertexIndex] = coordinateHash.index;
263
+ }
264
+ }
265
+ function addEdgeToHash(edgeHash, vertexAIndex, vertexBIndex, vertexAIndexUnique, vertexBIndexUnique, normalIndex) {
266
+ let startVertexIndex;
267
+ let endVertexIndex;
268
+ if (vertexAIndexUnique < vertexBIndexUnique) {
269
+ startVertexIndex = vertexAIndexUnique;
270
+ endVertexIndex = vertexBIndexUnique;
271
+ } else {
272
+ startVertexIndex = vertexBIndexUnique;
273
+ endVertexIndex = vertexAIndexUnique;
274
+ }
275
+ let edgeStart = edgeHash[startVertexIndex];
276
+ if (!defined_default(edgeStart)) {
277
+ edgeStart = edgeHash[startVertexIndex] = {};
278
+ }
279
+ let edgeEnd = edgeStart[endVertexIndex];
280
+ if (!defined_default(edgeEnd)) {
281
+ edgeEnd = edgeStart[endVertexIndex] = {
282
+ normalsIndex: [],
283
+ outlines: []
284
+ };
285
+ }
286
+ edgeEnd.normalsIndex.push(normalIndex);
287
+ if (edgeEnd.outlines.length === 0 || vertexAIndex !== vertexAIndexUnique || vertexBIndex !== vertexBIndexUnique) {
288
+ edgeEnd.outlines.push(vertexAIndex, vertexBIndex);
289
+ }
290
+ }
291
+ function generateOutlinesHash(symbologyData, featureIndexArray, indexArray, positions) {
292
+ const outlinesHash = [];
293
+ for (let i = 0; i < indexArray.length; i += 3) {
294
+ const featureIndex = defined_default(featureIndexArray) ? featureIndexArray[indexArray[i]] : "default";
295
+ const featureHash = getFeatureHash(
296
+ symbologyData,
297
+ outlinesHash,
298
+ featureIndex
299
+ );
300
+ if (!featureHash.hasOutline) {
301
+ continue;
302
+ }
303
+ const indexHash = featureHash.indices;
304
+ const positionHash = featureHash.positions;
305
+ for (let vertex = 0; vertex < 3; vertex++) {
306
+ const vertexIndex = indexArray[i + vertex];
307
+ addVertexToHash(indexHash, positionHash, vertexIndex, positions);
308
+ }
309
+ const edgeHash = featureHash.edges;
310
+ for (let vertex = 0; vertex < 3; vertex++) {
311
+ const vertexIndex = indexArray[i + vertex];
312
+ const nextVertexIndex = indexArray[i + (vertex + 1) % 3];
313
+ const uniqueVertexIndex = indexHash[vertexIndex];
314
+ const uniqueNextVertexIndex = indexHash[nextVertexIndex];
315
+ addEdgeToHash(
316
+ edgeHash,
317
+ vertexIndex,
318
+ nextVertexIndex,
319
+ uniqueVertexIndex,
320
+ uniqueNextVertexIndex,
321
+ i
322
+ );
323
+ }
324
+ }
325
+ return outlinesHash;
326
+ }
327
+ var calculateFaceNormalA = new Cartesian3_default();
328
+ var calculateFaceNormalB = new Cartesian3_default();
329
+ var calculateFaceNormalC = new Cartesian3_default();
330
+ function calculateFaceNormal(normals, vertexAIndex, indexArray, positions) {
331
+ const positionAIndex = indexArray[vertexAIndex] * 3;
332
+ const positionBIndex = indexArray[vertexAIndex + 1] * 3;
333
+ const positionCIndex = indexArray[vertexAIndex + 2] * 3;
334
+ Cartesian3_default.fromArray(positions, positionAIndex, calculateFaceNormalA);
335
+ Cartesian3_default.fromArray(positions, positionBIndex, calculateFaceNormalB);
336
+ Cartesian3_default.fromArray(positions, positionCIndex, calculateFaceNormalC);
337
+ Cartesian3_default.subtract(
338
+ calculateFaceNormalB,
339
+ calculateFaceNormalA,
340
+ calculateFaceNormalB
341
+ );
342
+ Cartesian3_default.subtract(
343
+ calculateFaceNormalC,
344
+ calculateFaceNormalA,
345
+ calculateFaceNormalC
346
+ );
347
+ Cartesian3_default.cross(
348
+ calculateFaceNormalB,
349
+ calculateFaceNormalC,
350
+ calculateFaceNormalA
351
+ );
352
+ const magnitude = Cartesian3_default.magnitude(calculateFaceNormalA);
353
+ if (magnitude !== 0) {
354
+ Cartesian3_default.divideByScalar(
355
+ calculateFaceNormalA,
356
+ magnitude,
357
+ calculateFaceNormalA
358
+ );
359
+ }
360
+ const normalAIndex = vertexAIndex * 3;
361
+ const normalBIndex = (vertexAIndex + 1) * 3;
362
+ const normalCIndex = (vertexAIndex + 2) * 3;
363
+ Cartesian3_default.pack(calculateFaceNormalA, normals, normalAIndex);
364
+ Cartesian3_default.pack(calculateFaceNormalA, normals, normalBIndex);
365
+ Cartesian3_default.pack(calculateFaceNormalA, normals, normalCIndex);
366
+ }
367
+ var isEdgeSmoothA = new Cartesian3_default();
368
+ var isEdgeSmoothB = new Cartesian3_default();
369
+ function isEdgeSmooth(normals, normalAIndex, normalBIndex) {
370
+ Cartesian3_default.fromArray(normals, normalAIndex, isEdgeSmoothA);
371
+ Cartesian3_default.fromArray(normals, normalBIndex, isEdgeSmoothB);
372
+ const cosine = Cartesian3_default.dot(isEdgeSmoothA, isEdgeSmoothB);
373
+ const sine = Cartesian3_default.magnitude(
374
+ Cartesian3_default.cross(isEdgeSmoothA, isEdgeSmoothB, isEdgeSmoothA)
375
+ );
376
+ return Math.atan2(sine, cosine) < 0.25;
377
+ }
378
+ function addOutlinesForEdge(outlines, edgeData, indexArray, positions, normals) {
379
+ if (edgeData.normalsIndex.length > 1) {
380
+ const normalsByIndex = positions.length === normals.length;
381
+ for (let indexA = 0; indexA < edgeData.normalsIndex.length; indexA++) {
382
+ const vertexAIndex = edgeData.normalsIndex[indexA];
383
+ if (!defined_default(normals[vertexAIndex * 3])) {
384
+ calculateFaceNormal(normals, vertexAIndex, indexArray, positions);
385
+ }
386
+ if (indexA === 0) {
387
+ continue;
388
+ }
389
+ for (let indexB = 0; indexB < indexA; indexB++) {
390
+ const vertexBIndex = edgeData.normalsIndex[indexB];
391
+ const normalAIndex = normalsByIndex ? indexArray[vertexAIndex] * 3 : vertexAIndex * 3;
392
+ const normalBIndex = normalsByIndex ? indexArray[vertexBIndex] * 3 : vertexBIndex * 3;
393
+ if (isEdgeSmooth(normals, normalAIndex, normalBIndex)) {
394
+ return;
395
+ }
396
+ }
397
+ }
398
+ }
399
+ outlines.push(...edgeData.outlines);
400
+ }
401
+ function addOutlinesForFeature(outlines, edgeHash, indexArray, positions, normals) {
402
+ const edgeStartKeys = Object.keys(edgeHash);
403
+ for (let startIndex = 0; startIndex < edgeStartKeys.length; startIndex++) {
404
+ const edgeEnds = edgeHash[edgeStartKeys[startIndex]];
405
+ const edgeEndKeys = Object.keys(edgeEnds);
406
+ for (let endIndex = 0; endIndex < edgeEndKeys.length; endIndex++) {
407
+ const edgeData = edgeEnds[edgeEndKeys[endIndex]];
408
+ addOutlinesForEdge(outlines, edgeData, indexArray, positions, normals);
409
+ }
410
+ }
411
+ }
412
+ function generateOutlinesFromHash(outlinesHash, indexArray, positions, normals) {
413
+ const outlines = [];
414
+ const features = Object.keys(outlinesHash);
415
+ for (let featureIndex = 0; featureIndex < features.length; featureIndex++) {
416
+ const edgeHash = outlinesHash[features[featureIndex]].edges;
417
+ addOutlinesForFeature(outlines, edgeHash, indexArray, positions, normals);
418
+ }
419
+ return outlines;
420
+ }
421
+ function generateOutlinesIndexArray(symbologyData, featureIndexArray, indexArray, positions, normals) {
422
+ if (!defined_default(symbologyData) || Object.keys(symbologyData).length === 0) {
423
+ return void 0;
424
+ }
425
+ const outlinesHash = generateOutlinesHash(
426
+ symbologyData,
427
+ featureIndexArray,
428
+ indexArray,
429
+ positions
430
+ );
431
+ if (!defined_default(normals) || indexArray.length * 3 !== normals.length) {
432
+ normals = [];
433
+ }
434
+ const outlines = generateOutlinesFromHash(
435
+ outlinesHash,
436
+ indexArray,
437
+ positions,
438
+ normals
439
+ );
440
+ const outlinesIndexArray = outlines.length > 0 ? new Uint32Array(outlines) : void 0;
441
+ return outlinesIndexArray;
442
+ }
443
+ function convertColorsArray(colors) {
444
+ const colorsArray = new Float32Array(colors.length);
445
+ for (let index = 0; index < colors.length; index += 4) {
446
+ colorsArray[index] = srgbToLinear_default(Color_default.byteToFloat(colors[index]));
447
+ colorsArray[index + 1] = srgbToLinear_default(Color_default.byteToFloat(colors[index + 1]));
448
+ colorsArray[index + 2] = srgbToLinear_default(Color_default.byteToFloat(colors[index + 2]));
449
+ colorsArray[index + 3] = Color_default.byteToFloat(colors[index + 3]);
450
+ }
451
+ return colorsArray;
452
+ }
453
+ function generateNormals(vertexCount, indices, positions, normals, uv0s, colors, featureIndex) {
454
+ const result = {
455
+ normals: void 0,
456
+ positions: void 0,
457
+ uv0s: void 0,
458
+ colors: void 0,
459
+ featureIndex: void 0,
460
+ vertexCount: void 0
461
+ };
462
+ if (vertexCount === 0 || !defined_default(positions) || positions.length === 0 || defined_default(normals)) {
463
+ return result;
464
+ }
465
+ if (defined_default(indices)) {
466
+ result.vertexCount = indices.length;
467
+ result.positions = new Float32Array(indices.length * 3);
468
+ result.uv0s = defined_default(uv0s) ? new Float32Array(indices.length * 2) : void 0;
469
+ result.colors = defined_default(colors) ? new Uint8Array(indices.length * 4) : void 0;
470
+ result.featureIndex = defined_default(featureIndex) ? new Array(indices.length) : void 0;
471
+ for (let i = 0; i < indices.length; i++) {
472
+ const index = indices[i];
473
+ result.positions[i * 3] = positions[index * 3];
474
+ result.positions[i * 3 + 1] = positions[index * 3 + 1];
475
+ result.positions[i * 3 + 2] = positions[index * 3 + 2];
476
+ if (defined_default(result.uv0s)) {
477
+ result.uv0s[i * 2] = uv0s[index * 2];
478
+ result.uv0s[i * 2 + 1] = uv0s[index * 2 + 1];
479
+ }
480
+ if (defined_default(result.colors)) {
481
+ result.colors[i * 4] = colors[index * 4];
482
+ result.colors[i * 4 + 1] = colors[index * 4 + 1];
483
+ result.colors[i * 4 + 2] = colors[index * 4 + 2];
484
+ result.colors[i * 4 + 3] = colors[index * 4 + 3];
485
+ }
486
+ if (defined_default(result.featureIndex)) {
487
+ result.featureIndex[i] = featureIndex[index];
488
+ }
489
+ }
490
+ vertexCount = indices.length;
491
+ positions = result.positions;
492
+ }
493
+ indices = new Array(vertexCount);
494
+ for (let i = 0; i < vertexCount; i++) {
495
+ indices[i] = i;
496
+ }
497
+ result.normals = new Float32Array(indices.length * 3);
498
+ for (let i = 0; i < indices.length; i += 3) {
499
+ calculateFaceNormal(result.normals, i, indices, positions);
500
+ }
501
+ return result;
502
+ }
503
+ function generateGltfBuffer(vertexCount, indices, positions, normals, uv0s, colors, featureIndex, parameters) {
504
+ if (vertexCount === 0 || !defined_default(positions) || positions.length === 0) {
505
+ return {
506
+ buffers: [],
507
+ bufferViews: [],
508
+ accessors: [],
509
+ meshes: [],
510
+ nodes: [],
511
+ nodesInScene: []
512
+ };
513
+ }
514
+ const buffers = [];
515
+ const bufferViews = [];
516
+ const accessors = [];
517
+ const meshes = [];
518
+ const nodes = [];
519
+ const nodesInScene = [];
520
+ const rootExtensions = {};
521
+ const extensionsUsed = [];
522
+ if (defined_default(indices)) {
523
+ vertexCount = indices.length;
524
+ }
525
+ const { indexArray, transparentVertexOffset } = generateIndexArray(
526
+ vertexCount,
527
+ indices,
528
+ colors,
529
+ parameters.splitGeometryByColorTransparency
530
+ );
531
+ const indicesBlob = new Blob([indexArray], { type: "application/binary" });
532
+ const indicesURL = URL.createObjectURL(indicesBlob);
533
+ const endIndex = vertexCount;
534
+ const featureIndexArray = parameters.enableFeatures && defined_default(featureIndex) ? new Float32Array(featureIndex.length) : void 0;
535
+ let featureCount = 0;
536
+ if (defined_default(featureIndexArray)) {
537
+ for (let index = 0; index < featureIndex.length; ++index) {
538
+ featureIndexArray[index] = featureIndex[index];
539
+ const countByIndex = featureIndex[index] + 1;
540
+ if (featureCount < countByIndex) {
541
+ featureCount = countByIndex;
542
+ }
543
+ }
544
+ }
545
+ let outlinesIndicesURL;
546
+ const outlinesIndexArray = generateOutlinesIndexArray(
547
+ parameters.symbologyData,
548
+ featureIndex,
549
+ indexArray,
550
+ positions,
551
+ normals
552
+ );
553
+ if (defined_default(outlinesIndexArray)) {
554
+ const outlinesIndicesBlob = new Blob([outlinesIndexArray], {
555
+ type: "application/binary"
556
+ });
557
+ outlinesIndicesURL = URL.createObjectURL(outlinesIndicesBlob);
558
+ }
559
+ const meshPositions = positions.subarray(0, endIndex * 3);
560
+ const positionsBlob = new Blob([meshPositions], {
561
+ type: "application/binary"
562
+ });
563
+ const positionsURL = URL.createObjectURL(positionsBlob);
564
+ let minX = Number.POSITIVE_INFINITY;
565
+ let maxX = Number.NEGATIVE_INFINITY;
566
+ let minY = Number.POSITIVE_INFINITY;
567
+ let maxY = Number.NEGATIVE_INFINITY;
568
+ let minZ = Number.POSITIVE_INFINITY;
569
+ let maxZ = Number.NEGATIVE_INFINITY;
570
+ for (let i = 0; i < meshPositions.length / 3; i++) {
571
+ minX = Math.min(minX, meshPositions[i * 3 + 0]);
572
+ maxX = Math.max(maxX, meshPositions[i * 3 + 0]);
573
+ minY = Math.min(minY, meshPositions[i * 3 + 1]);
574
+ maxY = Math.max(maxY, meshPositions[i * 3 + 1]);
575
+ minZ = Math.min(minZ, meshPositions[i * 3 + 2]);
576
+ maxZ = Math.max(maxZ, meshPositions[i * 3 + 2]);
577
+ }
578
+ const meshNormals = normals ? normals.subarray(0, endIndex * 3) : void 0;
579
+ let normalsURL;
580
+ if (defined_default(meshNormals)) {
581
+ const normalsBlob = new Blob([meshNormals], {
582
+ type: "application/binary"
583
+ });
584
+ normalsURL = URL.createObjectURL(normalsBlob);
585
+ }
586
+ const meshUv0s = uv0s ? uv0s.subarray(0, endIndex * 2) : void 0;
587
+ let uv0URL;
588
+ if (defined_default(meshUv0s)) {
589
+ const uv0Blob = new Blob([meshUv0s], { type: "application/binary" });
590
+ uv0URL = URL.createObjectURL(uv0Blob);
591
+ }
592
+ const meshColorsInBytes = defined_default(colors) ? convertColorsArray(colors.subarray(0, endIndex * 4)) : void 0;
593
+ let colorsURL;
594
+ if (defined_default(meshColorsInBytes)) {
595
+ const colorsBlob = new Blob([meshColorsInBytes], {
596
+ type: "application/binary"
597
+ });
598
+ colorsURL = URL.createObjectURL(colorsBlob);
599
+ }
600
+ const meshFeatureId0 = defined_default(featureIndexArray) ? featureIndexArray.subarray(0, endIndex) : void 0;
601
+ let featureId0URL;
602
+ if (defined_default(meshFeatureId0)) {
603
+ const featureId0Blob = new Blob([meshFeatureId0], {
604
+ type: "application/binary"
605
+ });
606
+ featureId0URL = URL.createObjectURL(featureId0Blob);
607
+ }
608
+ const meshPropertyTable0 = defined_default(featureIndexArray) ? new Float32Array(featureCount) : void 0;
609
+ let propertyTable0URL;
610
+ if (defined_default(meshPropertyTable0)) {
611
+ for (let index = 0; index < meshPropertyTable0.length; ++index) {
612
+ meshPropertyTable0[index] = index;
613
+ }
614
+ const propertyTable0Blob = new Blob([meshPropertyTable0], {
615
+ type: "application/binary"
616
+ });
617
+ propertyTable0URL = URL.createObjectURL(propertyTable0Blob);
618
+ }
619
+ const attributes = {};
620
+ const extensions = {};
621
+ attributes.POSITION = accessors.length;
622
+ buffers.push({
623
+ uri: positionsURL,
624
+ byteLength: meshPositions.byteLength
625
+ });
626
+ bufferViews.push({
627
+ buffer: buffers.length - 1,
628
+ byteOffset: 0,
629
+ byteLength: meshPositions.byteLength,
630
+ target: 34962
631
+ });
632
+ accessors.push({
633
+ bufferView: bufferViews.length - 1,
634
+ byteOffset: 0,
635
+ componentType: 5126,
636
+ count: meshPositions.length / 3,
637
+ type: "VEC3",
638
+ max: [minX, minY, minZ],
639
+ min: [maxX, maxY, maxZ]
640
+ });
641
+ if (defined_default(normalsURL)) {
642
+ attributes.NORMAL = accessors.length;
643
+ buffers.push({
644
+ uri: normalsURL,
645
+ byteLength: meshNormals.byteLength
646
+ });
647
+ bufferViews.push({
648
+ buffer: buffers.length - 1,
649
+ byteOffset: 0,
650
+ byteLength: meshNormals.byteLength,
651
+ target: 34962
652
+ });
653
+ accessors.push({
654
+ bufferView: bufferViews.length - 1,
655
+ byteOffset: 0,
656
+ componentType: 5126,
657
+ count: meshNormals.length / 3,
658
+ type: "VEC3"
659
+ });
660
+ }
661
+ if (defined_default(uv0URL)) {
662
+ attributes.TEXCOORD_0 = accessors.length;
663
+ buffers.push({
664
+ uri: uv0URL,
665
+ byteLength: meshUv0s.byteLength
666
+ });
667
+ bufferViews.push({
668
+ buffer: buffers.length - 1,
669
+ byteOffset: 0,
670
+ byteLength: meshUv0s.byteLength,
671
+ target: 34962
672
+ });
673
+ accessors.push({
674
+ bufferView: bufferViews.length - 1,
675
+ byteOffset: 0,
676
+ componentType: 5126,
677
+ count: meshUv0s.length / 2,
678
+ type: "VEC2"
679
+ });
680
+ }
681
+ if (defined_default(colorsURL)) {
682
+ attributes.COLOR_0 = accessors.length;
683
+ buffers.push({
684
+ uri: colorsURL,
685
+ byteLength: meshColorsInBytes.byteLength
686
+ });
687
+ bufferViews.push({
688
+ buffer: buffers.length - 1,
689
+ byteOffset: 0,
690
+ byteLength: meshColorsInBytes.byteLength,
691
+ target: 34962
692
+ });
693
+ accessors.push({
694
+ bufferView: bufferViews.length - 1,
695
+ byteOffset: 0,
696
+ componentType: 5126,
697
+ count: meshColorsInBytes.length / 4,
698
+ type: "VEC4"
699
+ });
700
+ }
701
+ if (defined_default(featureId0URL)) {
702
+ attributes._FEATURE_ID_0 = accessors.length;
703
+ buffers.push({
704
+ uri: featureId0URL,
705
+ byteLength: meshFeatureId0.byteLength
706
+ });
707
+ bufferViews.push({
708
+ buffer: buffers.length - 1,
709
+ byteOffset: 0,
710
+ byteLength: meshFeatureId0.byteLength,
711
+ target: 34963
712
+ });
713
+ accessors.push({
714
+ bufferView: bufferViews.length - 1,
715
+ byteOffset: 0,
716
+ componentType: 5126,
717
+ count: meshFeatureId0.length,
718
+ type: "SCALAR"
719
+ });
720
+ extensions.EXT_mesh_features = {
721
+ featureIds: [
722
+ {
723
+ attribute: 0,
724
+ propertyTable: 0,
725
+ featureCount
726
+ }
727
+ ]
728
+ };
729
+ extensionsUsed.push("EXT_mesh_features");
730
+ }
731
+ if (defined_default(propertyTable0URL)) {
732
+ buffers.push({
733
+ uri: propertyTable0URL,
734
+ byteLength: meshPropertyTable0.byteLength
735
+ });
736
+ bufferViews.push({
737
+ buffer: buffers.length - 1,
738
+ byteOffset: 0,
739
+ byteLength: meshPropertyTable0.byteLength,
740
+ target: 34963
741
+ });
742
+ rootExtensions.EXT_structural_metadata = {
743
+ schema: {
744
+ id: "i3s-metadata-schema-001",
745
+ name: "I3S metadata schema 001",
746
+ description: "The schema for I3S metadata",
747
+ version: "1.0",
748
+ classes: {
749
+ feature: {
750
+ name: "feature",
751
+ description: "Feature metadata",
752
+ properties: {
753
+ index: {
754
+ description: "The feature index",
755
+ type: "SCALAR",
756
+ componentType: "FLOAT32",
757
+ required: true
758
+ }
759
+ }
760
+ }
761
+ }
762
+ },
763
+ propertyTables: [
764
+ {
765
+ name: "feature-indices-mapping",
766
+ class: "feature",
767
+ count: featureCount,
768
+ properties: {
769
+ index: {
770
+ values: bufferViews.length - 1
771
+ }
772
+ }
773
+ }
774
+ ]
775
+ };
776
+ extensionsUsed.push("EXT_structural_metadata");
777
+ }
778
+ if (defined_default(outlinesIndicesURL)) {
779
+ buffers.push({
780
+ uri: outlinesIndicesURL,
781
+ byteLength: outlinesIndexArray.byteLength
782
+ });
783
+ bufferViews.push({
784
+ buffer: buffers.length - 1,
785
+ byteOffset: 0,
786
+ byteLength: outlinesIndexArray.byteLength,
787
+ target: 34963
788
+ });
789
+ accessors.push({
790
+ bufferView: bufferViews.length - 1,
791
+ byteOffset: 0,
792
+ componentType: 5125,
793
+ count: outlinesIndexArray.length,
794
+ type: "SCALAR"
795
+ });
796
+ extensions.CESIUM_primitive_outline = {
797
+ indices: accessors.length - 1
798
+ };
799
+ extensionsUsed.push("CESIUM_primitive_outline");
800
+ }
801
+ buffers.push({
802
+ uri: indicesURL,
803
+ byteLength: indexArray.byteLength
804
+ });
805
+ bufferViews.push({
806
+ buffer: buffers.length - 1,
807
+ byteOffset: 0,
808
+ byteLength: indexArray.byteLength,
809
+ target: 34963
810
+ });
811
+ const meshPrimitives = [];
812
+ if (transparentVertexOffset > 0) {
813
+ accessors.push({
814
+ bufferView: bufferViews.length - 1,
815
+ byteOffset: 0,
816
+ componentType: 5125,
817
+ count: transparentVertexOffset,
818
+ type: "SCALAR"
819
+ });
820
+ meshPrimitives.push({
821
+ attributes,
822
+ indices: accessors.length - 1,
823
+ material: meshPrimitives.length,
824
+ extensions
825
+ });
826
+ }
827
+ if (transparentVertexOffset < vertexCount) {
828
+ accessors.push({
829
+ bufferView: bufferViews.length - 1,
830
+ byteOffset: 4 * transparentVertexOffset,
831
+ // skip 4 bytes for each opaque vertex
832
+ componentType: 5125,
833
+ count: vertexCount - transparentVertexOffset,
834
+ type: "SCALAR"
835
+ });
836
+ meshPrimitives.push({
837
+ attributes,
838
+ indices: accessors.length - 1,
839
+ material: meshPrimitives.length,
840
+ extensions,
841
+ extra: {
842
+ isTransparent: true
843
+ }
844
+ });
845
+ }
846
+ meshes.push({
847
+ primitives: meshPrimitives
848
+ });
849
+ nodesInScene.push(0);
850
+ nodes.push({ mesh: 0 });
851
+ return {
852
+ buffers,
853
+ bufferViews,
854
+ accessors,
855
+ meshes,
856
+ nodes,
857
+ nodesInScene,
858
+ rootExtensions,
859
+ extensionsUsed
860
+ };
861
+ }
862
+ function decode(data, schema, bufferInfo, featureData) {
863
+ const magicNumber = new Uint8Array(data, 0, 5);
864
+ if (magicNumber[0] === "D".charCodeAt() && magicNumber[1] === "R".charCodeAt() && magicNumber[2] === "A".charCodeAt() && magicNumber[3] === "C".charCodeAt() && magicNumber[4] === "O".charCodeAt()) {
865
+ return decodeDracoEncodedGeometry(data, bufferInfo);
866
+ }
867
+ return decodeBinaryGeometry(data, schema, bufferInfo, featureData);
868
+ }
869
+ function decodeDracoEncodedGeometry(data) {
870
+ const dracoDecoderModule = draco;
871
+ const buffer = new dracoDecoderModule.DecoderBuffer();
872
+ const byteArray = new Uint8Array(data);
873
+ buffer.Init(byteArray, byteArray.length);
874
+ const dracoDecoder = new dracoDecoderModule.Decoder();
875
+ const geometryType = dracoDecoder.GetEncodedGeometryType(buffer);
876
+ const metadataQuerier = new dracoDecoderModule.MetadataQuerier();
877
+ let dracoGeometry;
878
+ let status;
879
+ if (geometryType === dracoDecoderModule.TRIANGULAR_MESH) {
880
+ dracoGeometry = new dracoDecoderModule.Mesh();
881
+ status = dracoDecoder.DecodeBufferToMesh(buffer, dracoGeometry);
882
+ }
883
+ const decodedGeometry = {
884
+ vertexCount: [0],
885
+ featureCount: 0
886
+ };
887
+ if (defined_default(status) && status.ok() && dracoGeometry.ptr !== 0) {
888
+ const faceCount = dracoGeometry.num_faces();
889
+ const attributesCount = dracoGeometry.num_attributes();
890
+ const vertexCount = dracoGeometry.num_points();
891
+ decodedGeometry.indices = new Uint32Array(faceCount * 3);
892
+ const faces = decodedGeometry.indices;
893
+ decodedGeometry.vertexCount[0] = vertexCount;
894
+ decodedGeometry.scale_x = 1;
895
+ decodedGeometry.scale_y = 1;
896
+ const face = new dracoDecoderModule.DracoInt32Array(3);
897
+ for (let faceIndex = 0; faceIndex < faceCount; ++faceIndex) {
898
+ dracoDecoder.GetFaceFromMesh(dracoGeometry, faceIndex, face);
899
+ faces[faceIndex * 3] = face.GetValue(0);
900
+ faces[faceIndex * 3 + 1] = face.GetValue(1);
901
+ faces[faceIndex * 3 + 2] = face.GetValue(2);
902
+ }
903
+ dracoDecoderModule.destroy(face);
904
+ for (let attrIndex = 0; attrIndex < attributesCount; ++attrIndex) {
905
+ const dracoAttribute = dracoDecoder.GetAttribute(
906
+ dracoGeometry,
907
+ attrIndex
908
+ );
909
+ const attributeData = decodeDracoAttribute(
910
+ dracoDecoderModule,
911
+ dracoDecoder,
912
+ dracoGeometry,
913
+ dracoAttribute,
914
+ vertexCount
915
+ );
916
+ const dracoAttributeType = dracoAttribute.attribute_type();
917
+ let attributei3sName = "unknown";
918
+ if (dracoAttributeType === dracoDecoderModule.POSITION) {
919
+ attributei3sName = "positions";
920
+ } else if (dracoAttributeType === dracoDecoderModule.NORMAL) {
921
+ attributei3sName = "normals";
922
+ } else if (dracoAttributeType === dracoDecoderModule.COLOR) {
923
+ attributei3sName = "colors";
924
+ } else if (dracoAttributeType === dracoDecoderModule.TEX_COORD) {
925
+ attributei3sName = "uv0s";
926
+ }
927
+ const metadata = dracoDecoder.GetAttributeMetadata(
928
+ dracoGeometry,
929
+ attrIndex
930
+ );
931
+ if (metadata.ptr !== 0) {
932
+ const numEntries = metadataQuerier.NumEntries(metadata);
933
+ for (let entry = 0; entry < numEntries; ++entry) {
934
+ const entryName = metadataQuerier.GetEntryName(metadata, entry);
935
+ if (entryName === "i3s-scale_x") {
936
+ decodedGeometry.scale_x = metadataQuerier.GetDoubleEntry(
937
+ metadata,
938
+ "i3s-scale_x"
939
+ );
940
+ } else if (entryName === "i3s-scale_y") {
941
+ decodedGeometry.scale_y = metadataQuerier.GetDoubleEntry(
942
+ metadata,
943
+ "i3s-scale_y"
944
+ );
945
+ } else if (entryName === "i3s-attribute-type") {
946
+ attributei3sName = metadataQuerier.GetStringEntry(
947
+ metadata,
948
+ "i3s-attribute-type"
949
+ );
950
+ }
951
+ }
952
+ }
953
+ if (defined_default(decodedGeometry[attributei3sName])) {
954
+ console.log("Attribute already exists", attributei3sName);
955
+ }
956
+ decodedGeometry[attributei3sName] = attributeData;
957
+ if (attributei3sName === "feature-index") {
958
+ decodedGeometry.featureCount++;
959
+ }
960
+ }
961
+ dracoDecoderModule.destroy(dracoGeometry);
962
+ }
963
+ dracoDecoderModule.destroy(metadataQuerier);
964
+ dracoDecoderModule.destroy(dracoDecoder);
965
+ return decodedGeometry;
966
+ }
967
+ function decodeDracoAttribute(dracoDecoderModule, dracoDecoder, dracoGeometry, dracoAttribute, vertexCount) {
968
+ const bufferSize = dracoAttribute.num_components() * vertexCount;
969
+ let dracoAttributeData;
970
+ const handlers = [
971
+ function() {
972
+ },
973
+ // DT_INVALID - 0
974
+ function() {
975
+ dracoAttributeData = new dracoDecoderModule.DracoInt8Array(bufferSize);
976
+ const success = dracoDecoder.GetAttributeInt8ForAllPoints(
977
+ dracoGeometry,
978
+ dracoAttribute,
979
+ dracoAttributeData
980
+ );
981
+ if (!success) {
982
+ console.error("Bad stream");
983
+ }
984
+ const attributeData2 = new Int8Array(bufferSize);
985
+ for (let i = 0; i < bufferSize; ++i) {
986
+ attributeData2[i] = dracoAttributeData.GetValue(i);
987
+ }
988
+ return attributeData2;
989
+ },
990
+ function() {
991
+ dracoAttributeData = new dracoDecoderModule.DracoInt8Array(bufferSize);
992
+ const success = dracoDecoder.GetAttributeUInt8ForAllPoints(
993
+ dracoGeometry,
994
+ dracoAttribute,
995
+ dracoAttributeData
996
+ );
997
+ if (!success) {
998
+ console.error("Bad stream");
999
+ }
1000
+ const attributeData2 = new Uint8Array(bufferSize);
1001
+ for (let i = 0; i < bufferSize; ++i) {
1002
+ attributeData2[i] = dracoAttributeData.GetValue(i);
1003
+ }
1004
+ return attributeData2;
1005
+ },
1006
+ function() {
1007
+ dracoAttributeData = new dracoDecoderModule.DracoInt16Array(bufferSize);
1008
+ const success = dracoDecoder.GetAttributeInt16ForAllPoints(
1009
+ dracoGeometry,
1010
+ dracoAttribute,
1011
+ dracoAttributeData
1012
+ );
1013
+ if (!success) {
1014
+ console.error("Bad stream");
1015
+ }
1016
+ const attributeData2 = new Int16Array(bufferSize);
1017
+ for (let i = 0; i < bufferSize; ++i) {
1018
+ attributeData2[i] = dracoAttributeData.GetValue(i);
1019
+ }
1020
+ return attributeData2;
1021
+ },
1022
+ function() {
1023
+ dracoAttributeData = new dracoDecoderModule.DracoInt16Array(bufferSize);
1024
+ const success = dracoDecoder.GetAttributeUInt16ForAllPoints(
1025
+ dracoGeometry,
1026
+ dracoAttribute,
1027
+ dracoAttributeData
1028
+ );
1029
+ if (!success) {
1030
+ console.error("Bad stream");
1031
+ }
1032
+ const attributeData2 = new Uint16Array(bufferSize);
1033
+ for (let i = 0; i < bufferSize; ++i) {
1034
+ attributeData2[i] = dracoAttributeData.GetValue(i);
1035
+ }
1036
+ return attributeData2;
1037
+ },
1038
+ function() {
1039
+ dracoAttributeData = new dracoDecoderModule.DracoInt32Array(bufferSize);
1040
+ const success = dracoDecoder.GetAttributeInt32ForAllPoints(
1041
+ dracoGeometry,
1042
+ dracoAttribute,
1043
+ dracoAttributeData
1044
+ );
1045
+ if (!success) {
1046
+ console.error("Bad stream");
1047
+ }
1048
+ const attributeData2 = new Int32Array(bufferSize);
1049
+ for (let i = 0; i < bufferSize; ++i) {
1050
+ attributeData2[i] = dracoAttributeData.GetValue(i);
1051
+ }
1052
+ return attributeData2;
1053
+ },
1054
+ function() {
1055
+ dracoAttributeData = new dracoDecoderModule.DracoInt32Array(bufferSize);
1056
+ const success = dracoDecoder.GetAttributeUInt32ForAllPoints(
1057
+ dracoGeometry,
1058
+ dracoAttribute,
1059
+ dracoAttributeData
1060
+ );
1061
+ if (!success) {
1062
+ console.error("Bad stream");
1063
+ }
1064
+ const attributeData2 = new Uint32Array(bufferSize);
1065
+ for (let i = 0; i < bufferSize; ++i) {
1066
+ attributeData2[i] = dracoAttributeData.GetValue(i);
1067
+ }
1068
+ return attributeData2;
1069
+ },
1070
+ function() {
1071
+ },
1072
+ function() {
1073
+ },
1074
+ function() {
1075
+ dracoAttributeData = new dracoDecoderModule.DracoFloat32Array(bufferSize);
1076
+ const success = dracoDecoder.GetAttributeFloatForAllPoints(
1077
+ dracoGeometry,
1078
+ dracoAttribute,
1079
+ dracoAttributeData
1080
+ );
1081
+ if (!success) {
1082
+ console.error("Bad stream");
1083
+ }
1084
+ const attributeData2 = new Float32Array(bufferSize);
1085
+ for (let i = 0; i < bufferSize; ++i) {
1086
+ attributeData2[i] = dracoAttributeData.GetValue(i);
1087
+ }
1088
+ return attributeData2;
1089
+ },
1090
+ function() {
1091
+ },
1092
+ function() {
1093
+ dracoAttributeData = new dracoDecoderModule.DracoUInt8Array(bufferSize);
1094
+ const success = dracoDecoder.GetAttributeUInt8ForAllPoints(
1095
+ dracoGeometry,
1096
+ dracoAttribute,
1097
+ dracoAttributeData
1098
+ );
1099
+ if (!success) {
1100
+ console.error("Bad stream");
1101
+ }
1102
+ const attributeData2 = new Uint8Array(bufferSize);
1103
+ for (let i = 0; i < bufferSize; ++i) {
1104
+ attributeData2[i] = dracoAttributeData.GetValue(i);
1105
+ }
1106
+ return attributeData2;
1107
+ }
1108
+ ];
1109
+ const attributeData = handlers[dracoAttribute.data_type()]();
1110
+ if (defined_default(dracoAttributeData)) {
1111
+ dracoDecoderModule.destroy(dracoAttributeData);
1112
+ }
1113
+ return attributeData;
1114
+ }
1115
+ var binaryAttributeDecoders = {
1116
+ position: function(decodedGeometry, data, offset) {
1117
+ const count = decodedGeometry.vertexCount * 3;
1118
+ decodedGeometry.positions = new Float32Array(data, offset, count);
1119
+ offset += count * 4;
1120
+ return offset;
1121
+ },
1122
+ normal: function(decodedGeometry, data, offset) {
1123
+ const count = decodedGeometry.vertexCount * 3;
1124
+ decodedGeometry.normals = new Float32Array(data, offset, count);
1125
+ offset += count * 4;
1126
+ return offset;
1127
+ },
1128
+ uv0: function(decodedGeometry, data, offset) {
1129
+ const count = decodedGeometry.vertexCount * 2;
1130
+ decodedGeometry.uv0s = new Float32Array(data, offset, count);
1131
+ offset += count * 4;
1132
+ return offset;
1133
+ },
1134
+ color: function(decodedGeometry, data, offset) {
1135
+ const count = decodedGeometry.vertexCount * 4;
1136
+ decodedGeometry.colors = new Uint8Array(data, offset, count);
1137
+ offset += count;
1138
+ return offset;
1139
+ },
1140
+ featureId: function(decodedGeometry, data, offset) {
1141
+ const count = decodedGeometry.featureCount;
1142
+ offset += count * 8;
1143
+ return offset;
1144
+ },
1145
+ id: function(decodedGeometry, data, offset) {
1146
+ const count = decodedGeometry.featureCount;
1147
+ offset += count * 8;
1148
+ return offset;
1149
+ },
1150
+ faceRange: function(decodedGeometry, data, offset) {
1151
+ const count = decodedGeometry.featureCount * 2;
1152
+ decodedGeometry.faceRange = new Uint32Array(data, offset, count);
1153
+ offset += count * 4;
1154
+ return offset;
1155
+ },
1156
+ uvRegion: function(decodedGeometry, data, offset) {
1157
+ const count = decodedGeometry.vertexCount * 4;
1158
+ decodedGeometry["uv-region"] = new Uint16Array(data, offset, count);
1159
+ offset += count * 2;
1160
+ return offset;
1161
+ },
1162
+ region: function(decodedGeometry, data, offset) {
1163
+ const count = decodedGeometry.vertexCount * 4;
1164
+ decodedGeometry["uv-region"] = new Uint16Array(data, offset, count);
1165
+ offset += count * 2;
1166
+ return offset;
1167
+ }
1168
+ };
1169
+ function decodeBinaryGeometry(data, schema, bufferInfo, featureData) {
1170
+ const decodedGeometry = {
1171
+ vertexCount: 0
1172
+ };
1173
+ const dataView = new DataView(data);
1174
+ try {
1175
+ let offset = 0;
1176
+ decodedGeometry.vertexCount = dataView.getUint32(offset, 1);
1177
+ offset += 4;
1178
+ decodedGeometry.featureCount = dataView.getUint32(offset, 1);
1179
+ offset += 4;
1180
+ if (defined_default(bufferInfo)) {
1181
+ for (let attrIndex = 0; attrIndex < bufferInfo.attributes.length; attrIndex++) {
1182
+ if (defined_default(binaryAttributeDecoders[bufferInfo.attributes[attrIndex]])) {
1183
+ offset = binaryAttributeDecoders[bufferInfo.attributes[attrIndex]](
1184
+ decodedGeometry,
1185
+ data,
1186
+ offset
1187
+ );
1188
+ } else {
1189
+ console.error(
1190
+ "Unknown decoder for",
1191
+ bufferInfo.attributes[attrIndex]
1192
+ );
1193
+ }
1194
+ }
1195
+ } else {
1196
+ let ordering = schema.ordering;
1197
+ let featureAttributeOrder = schema.featureAttributeOrder;
1198
+ if (defined_default(featureData) && defined_default(featureData.geometryData) && defined_default(featureData.geometryData[0]) && defined_default(featureData.geometryData[0].params)) {
1199
+ ordering = Object.keys(
1200
+ featureData.geometryData[0].params.vertexAttributes
1201
+ );
1202
+ featureAttributeOrder = Object.keys(
1203
+ featureData.geometryData[0].params.featureAttributes
1204
+ );
1205
+ }
1206
+ for (let i = 0; i < ordering.length; i++) {
1207
+ const decoder = binaryAttributeDecoders[ordering[i]];
1208
+ offset = decoder(decodedGeometry, data, offset);
1209
+ }
1210
+ for (let j = 0; j < featureAttributeOrder.length; j++) {
1211
+ const curDecoder = binaryAttributeDecoders[featureAttributeOrder[j]];
1212
+ offset = curDecoder(decodedGeometry, data, offset);
1213
+ }
1214
+ }
1215
+ } catch (e) {
1216
+ console.error(e);
1217
+ }
1218
+ decodedGeometry.scale_x = 1;
1219
+ decodedGeometry.scale_y = 1;
1220
+ return decodedGeometry;
1221
+ }
1222
+ function decodeAndCreateGltf(parameters) {
1223
+ const geometryData = decode(
1224
+ parameters.binaryData,
1225
+ parameters.schema,
1226
+ parameters.bufferInfo,
1227
+ parameters.featureData
1228
+ );
1229
+ if (defined_default(parameters.geoidDataList) && parameters.geoidDataList.length > 0) {
1230
+ orthometricToEllipsoidal(
1231
+ geometryData.vertexCount,
1232
+ geometryData.positions,
1233
+ geometryData.scale_x,
1234
+ geometryData.scale_y,
1235
+ parameters.cartographicCenter,
1236
+ parameters.geoidDataList,
1237
+ false
1238
+ );
1239
+ }
1240
+ transformToLocal(
1241
+ geometryData.vertexCount,
1242
+ geometryData.positions,
1243
+ geometryData.normals,
1244
+ parameters.cartographicCenter,
1245
+ parameters.cartesianCenter,
1246
+ parameters.parentRotation,
1247
+ parameters.ellipsoidRadiiSquare,
1248
+ geometryData.scale_x,
1249
+ geometryData.scale_y
1250
+ );
1251
+ if (defined_default(geometryData.uv0s) && defined_default(geometryData["uv-region"])) {
1252
+ cropUVs(
1253
+ geometryData.vertexCount,
1254
+ geometryData.uv0s,
1255
+ geometryData["uv-region"]
1256
+ );
1257
+ }
1258
+ let featureIndex;
1259
+ if (defined_default(geometryData["feature-index"])) {
1260
+ featureIndex = geometryData["feature-index"];
1261
+ } else if (defined_default(geometryData["faceRange"])) {
1262
+ featureIndex = new Array(geometryData.vertexCount);
1263
+ for (let range = 0; range < geometryData["faceRange"].length - 1; range += 2) {
1264
+ const curIndex = range / 2;
1265
+ const rangeStart = geometryData["faceRange"][range];
1266
+ const rangeEnd = geometryData["faceRange"][range + 1];
1267
+ for (let i = rangeStart; i <= rangeEnd; i++) {
1268
+ featureIndex[i * 3] = curIndex;
1269
+ featureIndex[i * 3 + 1] = curIndex;
1270
+ featureIndex[i * 3 + 2] = curIndex;
1271
+ }
1272
+ }
1273
+ }
1274
+ if (parameters.calculateNormals) {
1275
+ const data = generateNormals(
1276
+ geometryData.vertexCount,
1277
+ geometryData.indices,
1278
+ geometryData.positions,
1279
+ geometryData.normals,
1280
+ geometryData.uv0s,
1281
+ geometryData.colors,
1282
+ featureIndex
1283
+ );
1284
+ if (defined_default(data.normals)) {
1285
+ geometryData.normals = data.normals;
1286
+ if (defined_default(data.vertexCount)) {
1287
+ geometryData.vertexCount = data.vertexCount;
1288
+ geometryData.indices = data.indices;
1289
+ geometryData.positions = data.positions;
1290
+ geometryData.uv0s = data.uv0s;
1291
+ geometryData.colors = data.colors;
1292
+ featureIndex = data.featureIndex;
1293
+ }
1294
+ }
1295
+ }
1296
+ const meshData = generateGltfBuffer(
1297
+ geometryData.vertexCount,
1298
+ geometryData.indices,
1299
+ geometryData.positions,
1300
+ geometryData.normals,
1301
+ geometryData.uv0s,
1302
+ geometryData.colors,
1303
+ featureIndex,
1304
+ parameters
1305
+ );
1306
+ const customAttributes = {
1307
+ positions: geometryData.positions,
1308
+ indices: geometryData.indices,
1309
+ featureIndex,
1310
+ sourceURL: parameters.url,
1311
+ cartesianCenter: parameters.cartesianCenter,
1312
+ parentRotation: parameters.parentRotation
1313
+ };
1314
+ meshData._customAttributes = customAttributes;
1315
+ const results = {
1316
+ meshData
1317
+ };
1318
+ return results;
1319
+ }
1320
+ async function initWorker(parameters, transferableObjects) {
1321
+ const wasmConfig = parameters.webAssemblyConfig;
1322
+ if (defined_default(wasmConfig) && defined_default(wasmConfig.wasmBinaryFile)) {
1323
+ draco = await (0, import_draco_decoder_nodejs.default)(wasmConfig);
1324
+ } else {
1325
+ draco = await (0, import_draco_decoder_nodejs.default)();
1326
+ }
1327
+ return true;
1328
+ }
1329
+ function decodeI3S(parameters, transferableObjects) {
1330
+ const wasmConfig = parameters.webAssemblyConfig;
1331
+ if (defined_default(wasmConfig)) {
1332
+ return initWorker(parameters, transferableObjects);
1333
+ }
1334
+ return decodeAndCreateGltf(parameters, transferableObjects);
1335
+ }
1336
+ var decodeI3S_default = createTaskProcessorWorker_default(decodeI3S);
1337
+ export {
1338
+ decodeI3S_default as default
1339
+ };