@loaders.gl/i3s 4.0.0-beta.1 → 4.0.0-beta.3

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 (207) hide show
  1. package/dist/arcgis-webscene-loader.d.ts.map +1 -0
  2. package/dist/{esm/arcgis-webscene-loader.js → arcgis-webscene-loader.js} +2 -2
  3. package/dist/arcgis-webscene-loader.js.map +1 -0
  4. package/dist/dist.dev.js +14694 -0
  5. package/dist/i3s-attribute-loader.d.ts.map +1 -0
  6. package/dist/{esm/i3s-attribute-loader.js → i3s-attribute-loader.js} +3 -3
  7. package/dist/i3s-attribute-loader.js.map +1 -0
  8. package/dist/i3s-building-scene-layer-loader.d.ts.map +1 -0
  9. package/dist/{esm/i3s-building-scene-layer-loader.js → i3s-building-scene-layer-loader.js} +2 -2
  10. package/dist/i3s-building-scene-layer-loader.js.map +1 -0
  11. package/dist/i3s-content-loader.d.ts.map +1 -0
  12. package/dist/{esm/i3s-content-loader.js → i3s-content-loader.js} +2 -2
  13. package/dist/i3s-content-loader.js.map +1 -0
  14. package/dist/i3s-content-worker-node.js +300 -155
  15. package/dist/i3s-content-worker-node.js.map +4 -4
  16. package/dist/i3s-content-worker.js +1337 -483
  17. package/dist/i3s-loader.d.ts.map +1 -0
  18. package/dist/{esm/i3s-loader.js → i3s-loader.js} +4 -4
  19. package/dist/i3s-loader.js.map +1 -0
  20. package/dist/i3s-node-page-loader.d.ts.map +1 -0
  21. package/dist/{esm/i3s-node-page-loader.js → i3s-node-page-loader.js} +1 -1
  22. package/dist/i3s-node-page-loader.js.map +1 -0
  23. package/dist/{src/i3s-slpk-loader.d.ts → i3s-slpk-loader.d.ts} +3 -1
  24. package/dist/i3s-slpk-loader.d.ts.map +1 -0
  25. package/dist/i3s-slpk-loader.js +19 -0
  26. package/dist/i3s-slpk-loader.js.map +1 -0
  27. package/dist/index.cjs +1587 -0
  28. package/dist/{src/index.d.ts → index.d.ts} +2 -1
  29. package/dist/index.d.ts.map +1 -0
  30. package/dist/index.js +10 -0
  31. package/dist/index.js.map +1 -0
  32. package/dist/lib/helpers/i3s-nodepages-tiles.d.ts.map +1 -0
  33. package/dist/{esm/lib → lib}/helpers/i3s-nodepages-tiles.js +16 -17
  34. package/dist/lib/helpers/i3s-nodepages-tiles.js.map +1 -0
  35. package/dist/lib/parsers/constants.d.ts.map +1 -0
  36. package/dist/{esm/lib → lib}/parsers/constants.js +2 -2
  37. package/dist/lib/parsers/constants.js.map +1 -0
  38. package/dist/lib/parsers/parse-arcgis-webscene.d.ts.map +1 -0
  39. package/dist/lib/parsers/parse-arcgis-webscene.js.map +1 -0
  40. package/dist/lib/parsers/parse-i3s-attribute.d.ts.map +1 -0
  41. package/dist/{esm/lib → lib}/parsers/parse-i3s-attribute.js +1 -1
  42. package/dist/lib/parsers/parse-i3s-attribute.js.map +1 -0
  43. package/dist/lib/parsers/parse-i3s-building-scene-layer.d.ts.map +1 -0
  44. package/dist/{esm/lib → lib}/parsers/parse-i3s-building-scene-layer.js +1 -1
  45. package/dist/lib/parsers/parse-i3s-building-scene-layer.js.map +1 -0
  46. package/dist/lib/parsers/parse-i3s-tile-content.d.ts.map +1 -0
  47. package/dist/{esm/lib → lib}/parsers/parse-i3s-tile-content.js +6 -5
  48. package/dist/lib/parsers/parse-i3s-tile-content.js.map +1 -0
  49. package/dist/lib/parsers/parse-i3s.d.ts.map +1 -0
  50. package/dist/{esm/lib → lib}/parsers/parse-i3s.js +6 -6
  51. package/dist/lib/parsers/parse-i3s.js.map +1 -0
  52. package/dist/{src/lib → lib}/parsers/parse-slpk/parse-slpk.d.ts +1 -1
  53. package/dist/lib/parsers/parse-slpk/parse-slpk.d.ts.map +1 -0
  54. package/dist/{esm/lib → lib}/parsers/parse-slpk/parse-slpk.js +9 -11
  55. package/dist/lib/parsers/parse-slpk/parse-slpk.js.map +1 -0
  56. package/dist/{src/lib → lib}/parsers/parse-slpk/slpk-archieve.d.ts +10 -7
  57. package/dist/lib/parsers/parse-slpk/slpk-archieve.d.ts.map +1 -0
  58. package/dist/{esm/lib → lib}/parsers/parse-slpk/slpk-archieve.js +21 -21
  59. package/dist/lib/parsers/parse-slpk/slpk-archieve.js.map +1 -0
  60. package/dist/lib/utils/convert-i3s-obb-to-mbs.d.ts.map +1 -0
  61. package/dist/lib/utils/convert-i3s-obb-to-mbs.js.map +1 -0
  62. package/dist/lib/utils/customize-/321/201olors.d.ts.map +1 -0
  63. package/dist/{esm/lib → lib}/utils/customize-/321/201olors.js +2 -2
  64. package/dist/lib/utils/customize-/321/201olors.js.map +1 -0
  65. package/dist/lib/utils/url-utils.d.ts.map +1 -0
  66. package/dist/{esm/lib → lib}/utils/url-utils.js +3 -3
  67. package/dist/lib/utils/url-utils.js.map +1 -0
  68. package/dist/types.d.ts.map +1 -0
  69. package/dist/types.js.map +1 -0
  70. package/dist/workers/i3s-content-worker-node.d.ts.map +1 -0
  71. package/dist/{esm/workers → workers}/i3s-content-worker-node.js +1 -1
  72. package/dist/workers/i3s-content-worker-node.js.map +1 -0
  73. package/dist/workers/i3s-content-worker.d.ts.map +1 -0
  74. package/dist/workers/i3s-content-worker.js +4 -0
  75. package/dist/workers/i3s-content-worker.js.map +1 -0
  76. package/package.json +25 -17
  77. package/src/i3s-slpk-loader.ts +9 -18
  78. package/src/index.ts +3 -1
  79. package/src/lib/parsers/parse-i3s-tile-content.ts +2 -1
  80. package/src/lib/parsers/parse-slpk/parse-slpk.ts +13 -13
  81. package/src/lib/parsers/parse-slpk/slpk-archieve.ts +27 -19
  82. package/dist/dist.min.js +0 -15742
  83. package/dist/es5/arcgis-webscene-loader.js +0 -40
  84. package/dist/es5/arcgis-webscene-loader.js.map +0 -1
  85. package/dist/es5/bundle.js +0 -6
  86. package/dist/es5/bundle.js.map +0 -1
  87. package/dist/es5/i3s-attribute-loader.js +0 -195
  88. package/dist/es5/i3s-attribute-loader.js.map +0 -1
  89. package/dist/es5/i3s-building-scene-layer-loader.js +0 -46
  90. package/dist/es5/i3s-building-scene-layer-loader.js.map +0 -1
  91. package/dist/es5/i3s-content-loader.js +0 -56
  92. package/dist/es5/i3s-content-loader.js.map +0 -1
  93. package/dist/es5/i3s-loader.js +0 -193
  94. package/dist/es5/i3s-loader.js.map +0 -1
  95. package/dist/es5/i3s-node-page-loader.js +0 -41
  96. package/dist/es5/i3s-node-page-loader.js.map +0 -1
  97. package/dist/es5/i3s-slpk-loader.js +0 -48
  98. package/dist/es5/i3s-slpk-loader.js.map +0 -1
  99. package/dist/es5/index.js +0 -75
  100. package/dist/es5/index.js.map +0 -1
  101. package/dist/es5/lib/helpers/i3s-nodepages-tiles.js +0 -316
  102. package/dist/es5/lib/helpers/i3s-nodepages-tiles.js.map +0 -1
  103. package/dist/es5/lib/parsers/constants.js +0 -71
  104. package/dist/es5/lib/parsers/constants.js.map +0 -1
  105. package/dist/es5/lib/parsers/parse-arcgis-webscene.js +0 -158
  106. package/dist/es5/lib/parsers/parse-arcgis-webscene.js.map +0 -1
  107. package/dist/es5/lib/parsers/parse-i3s-attribute.js +0 -76
  108. package/dist/es5/lib/parsers/parse-i3s-attribute.js.map +0 -1
  109. package/dist/es5/lib/parsers/parse-i3s-building-scene-layer.js +0 -65
  110. package/dist/es5/lib/parsers/parse-i3s-building-scene-layer.js.map +0 -1
  111. package/dist/es5/lib/parsers/parse-i3s-tile-content.js +0 -513
  112. package/dist/es5/lib/parsers/parse-i3s-tile-content.js.map +0 -1
  113. package/dist/es5/lib/parsers/parse-i3s.js +0 -128
  114. package/dist/es5/lib/parsers/parse-i3s.js.map +0 -1
  115. package/dist/es5/lib/parsers/parse-slpk/parse-slpk.js +0 -69
  116. package/dist/es5/lib/parsers/parse-slpk/parse-slpk.js.map +0 -1
  117. package/dist/es5/lib/parsers/parse-slpk/slpk-archieve.js +0 -254
  118. package/dist/es5/lib/parsers/parse-slpk/slpk-archieve.js.map +0 -1
  119. package/dist/es5/lib/utils/convert-i3s-obb-to-mbs.js +0 -17
  120. package/dist/es5/lib/utils/convert-i3s-obb-to-mbs.js.map +0 -1
  121. package/dist/es5/lib/utils/customize-/321/201olors.js +0 -184
  122. package/dist/es5/lib/utils/customize-/321/201olors.js.map +0 -1
  123. package/dist/es5/lib/utils/url-utils.js +0 -33
  124. package/dist/es5/lib/utils/url-utils.js.map +0 -1
  125. package/dist/es5/types.js +0 -13
  126. package/dist/es5/types.js.map +0 -1
  127. package/dist/es5/workers/i3s-content-worker-node.js +0 -7
  128. package/dist/es5/workers/i3s-content-worker-node.js.map +0 -1
  129. package/dist/es5/workers/i3s-content-worker.js +0 -6
  130. package/dist/es5/workers/i3s-content-worker.js.map +0 -1
  131. package/dist/esm/arcgis-webscene-loader.js.map +0 -1
  132. package/dist/esm/bundle.js +0 -4
  133. package/dist/esm/bundle.js.map +0 -1
  134. package/dist/esm/i3s-attribute-loader.js.map +0 -1
  135. package/dist/esm/i3s-building-scene-layer-loader.js.map +0 -1
  136. package/dist/esm/i3s-content-loader.js.map +0 -1
  137. package/dist/esm/i3s-loader.js.map +0 -1
  138. package/dist/esm/i3s-node-page-loader.js.map +0 -1
  139. package/dist/esm/i3s-slpk-loader.js +0 -19
  140. package/dist/esm/i3s-slpk-loader.js.map +0 -1
  141. package/dist/esm/index.js +0 -10
  142. package/dist/esm/index.js.map +0 -1
  143. package/dist/esm/lib/helpers/i3s-nodepages-tiles.js.map +0 -1
  144. package/dist/esm/lib/parsers/constants.js.map +0 -1
  145. package/dist/esm/lib/parsers/parse-arcgis-webscene.js.map +0 -1
  146. package/dist/esm/lib/parsers/parse-i3s-attribute.js.map +0 -1
  147. package/dist/esm/lib/parsers/parse-i3s-building-scene-layer.js.map +0 -1
  148. package/dist/esm/lib/parsers/parse-i3s-tile-content.js.map +0 -1
  149. package/dist/esm/lib/parsers/parse-i3s.js.map +0 -1
  150. package/dist/esm/lib/parsers/parse-slpk/parse-slpk.js.map +0 -1
  151. package/dist/esm/lib/parsers/parse-slpk/slpk-archieve.js.map +0 -1
  152. package/dist/esm/lib/utils/convert-i3s-obb-to-mbs.js.map +0 -1
  153. package/dist/esm/lib/utils/customize-/321/201olors.js.map +0 -1
  154. package/dist/esm/lib/utils/url-utils.js.map +0 -1
  155. package/dist/esm/types.js.map +0 -1
  156. package/dist/esm/workers/i3s-content-worker-node.js.map +0 -1
  157. package/dist/esm/workers/i3s-content-worker.js +0 -4
  158. package/dist/esm/workers/i3s-content-worker.js.map +0 -1
  159. package/dist/src/arcgis-webscene-loader.d.ts.map +0 -1
  160. package/dist/src/bundle.d.ts +0 -2
  161. package/dist/src/bundle.d.ts.map +0 -1
  162. package/dist/src/i3s-attribute-loader.d.ts.map +0 -1
  163. package/dist/src/i3s-building-scene-layer-loader.d.ts.map +0 -1
  164. package/dist/src/i3s-content-loader.d.ts.map +0 -1
  165. package/dist/src/i3s-loader.d.ts.map +0 -1
  166. package/dist/src/i3s-node-page-loader.d.ts.map +0 -1
  167. package/dist/src/i3s-slpk-loader.d.ts.map +0 -1
  168. package/dist/src/index.d.ts.map +0 -1
  169. package/dist/src/lib/helpers/i3s-nodepages-tiles.d.ts.map +0 -1
  170. package/dist/src/lib/parsers/constants.d.ts.map +0 -1
  171. package/dist/src/lib/parsers/parse-arcgis-webscene.d.ts.map +0 -1
  172. package/dist/src/lib/parsers/parse-i3s-attribute.d.ts.map +0 -1
  173. package/dist/src/lib/parsers/parse-i3s-building-scene-layer.d.ts.map +0 -1
  174. package/dist/src/lib/parsers/parse-i3s-tile-content.d.ts.map +0 -1
  175. package/dist/src/lib/parsers/parse-i3s.d.ts.map +0 -1
  176. package/dist/src/lib/parsers/parse-slpk/parse-slpk.d.ts.map +0 -1
  177. package/dist/src/lib/parsers/parse-slpk/slpk-archieve.d.ts.map +0 -1
  178. package/dist/src/lib/utils/convert-i3s-obb-to-mbs.d.ts.map +0 -1
  179. package/dist/src/lib/utils/customize-/321/201olors.d.ts.map +0 -1
  180. package/dist/src/lib/utils/url-utils.d.ts.map +0 -1
  181. package/dist/src/types.d.ts.map +0 -1
  182. package/dist/src/workers/i3s-content-worker-node.d.ts.map +0 -1
  183. package/dist/src/workers/i3s-content-worker.d.ts.map +0 -1
  184. package/dist/tsconfig.tsbuildinfo +0 -1
  185. package/src/bundle.ts +0 -4
  186. /package/dist/{src/arcgis-webscene-loader.d.ts → arcgis-webscene-loader.d.ts} +0 -0
  187. /package/dist/{src/i3s-attribute-loader.d.ts → i3s-attribute-loader.d.ts} +0 -0
  188. /package/dist/{src/i3s-building-scene-layer-loader.d.ts → i3s-building-scene-layer-loader.d.ts} +0 -0
  189. /package/dist/{src/i3s-content-loader.d.ts → i3s-content-loader.d.ts} +0 -0
  190. /package/dist/{src/i3s-loader.d.ts → i3s-loader.d.ts} +0 -0
  191. /package/dist/{src/i3s-node-page-loader.d.ts → i3s-node-page-loader.d.ts} +0 -0
  192. /package/dist/{src/lib → lib}/helpers/i3s-nodepages-tiles.d.ts +0 -0
  193. /package/dist/{src/lib → lib}/parsers/constants.d.ts +0 -0
  194. /package/dist/{src/lib → lib}/parsers/parse-arcgis-webscene.d.ts +0 -0
  195. /package/dist/{esm/lib → lib}/parsers/parse-arcgis-webscene.js +0 -0
  196. /package/dist/{src/lib → lib}/parsers/parse-i3s-attribute.d.ts +0 -0
  197. /package/dist/{src/lib → lib}/parsers/parse-i3s-building-scene-layer.d.ts +0 -0
  198. /package/dist/{src/lib → lib}/parsers/parse-i3s-tile-content.d.ts +0 -0
  199. /package/dist/{src/lib → lib}/parsers/parse-i3s.d.ts +0 -0
  200. /package/dist/{src/lib → lib}/utils/convert-i3s-obb-to-mbs.d.ts +0 -0
  201. /package/dist/{esm/lib → lib}/utils/convert-i3s-obb-to-mbs.js +0 -0
  202. /package/dist/{src/lib → lib}/utils/customize-/321/201olors.d.ts" +0 -0
  203. /package/dist/{src/lib → lib}/utils/url-utils.d.ts +0 -0
  204. /package/dist/{src/types.d.ts → types.d.ts} +0 -0
  205. /package/dist/{esm/types.js → types.js} +0 -0
  206. /package/dist/{src/workers → workers}/i3s-content-worker-node.d.ts +0 -0
  207. /package/dist/{src/workers → workers}/i3s-content-worker.d.ts +0 -0
package/dist/index.cjs ADDED
@@ -0,0 +1,1587 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // src/index.ts
31
+ var src_exports = {};
32
+ __export(src_exports, {
33
+ ArcGISWebSceneLoader: () => ArcGISWebSceneLoader,
34
+ COORDINATE_SYSTEM: () => COORDINATE_SYSTEM,
35
+ I3SAttributeLoader: () => I3SAttributeLoader,
36
+ I3SBuildingSceneLayerLoader: () => I3SBuildingSceneLayerLoader,
37
+ I3SContentLoader: () => I3SContentLoader,
38
+ I3SLoader: () => I3SLoader,
39
+ I3SNodePageLoader: () => I3SNodePageLoader,
40
+ SLPKLoader: () => SLPKLoader,
41
+ loadFeatureAttributes: () => loadFeatureAttributes,
42
+ parseSLPKArchive: () => parseSLPKArchive
43
+ });
44
+ module.exports = __toCommonJS(src_exports);
45
+
46
+ // src/lib/parsers/constants.ts
47
+ var import_constants = __toESM(require("@luma.gl/constants"), 1);
48
+ function getConstructorForDataFormat(dataType) {
49
+ switch (dataType) {
50
+ case "UInt8":
51
+ return Uint8Array;
52
+ case "UInt16":
53
+ return Uint16Array;
54
+ case "UInt32":
55
+ return Uint32Array;
56
+ case "Float32":
57
+ return Float32Array;
58
+ case "UInt64":
59
+ return Float64Array;
60
+ default:
61
+ throw new Error(`parse i3s tile content: unknown type of data: ${dataType}`);
62
+ }
63
+ }
64
+ var GL_TYPE_MAP = {
65
+ UInt8: import_constants.default.UNSIGNED_BYTE,
66
+ UInt16: import_constants.default.UNSIGNED_SHORT,
67
+ Float32: import_constants.default.FLOAT,
68
+ UInt32: import_constants.default.UNSIGNED_INT,
69
+ UInt64: import_constants.default.DOUBLE
70
+ };
71
+ function sizeOf(dataType) {
72
+ switch (dataType) {
73
+ case "UInt8":
74
+ return 1;
75
+ case "UInt16":
76
+ case "Int16":
77
+ return 2;
78
+ case "UInt32":
79
+ case "Int32":
80
+ case "Float32":
81
+ return 4;
82
+ case "UInt64":
83
+ case "Int64":
84
+ case "Float64":
85
+ return 8;
86
+ default:
87
+ throw new Error(`parse i3s tile content: unknown size of data: ${dataType}`);
88
+ }
89
+ }
90
+ var STRING_ATTRIBUTE_TYPE = "String";
91
+ var OBJECT_ID_ATTRIBUTE_TYPE = "Oid32";
92
+ var FLOAT_64_TYPE = "Float64";
93
+ var INT_16_ATTRIBUTE_TYPE = "Int16";
94
+ var COORDINATE_SYSTEM = /* @__PURE__ */ ((COORDINATE_SYSTEM2) => {
95
+ COORDINATE_SYSTEM2[COORDINATE_SYSTEM2["DEFAULT"] = -1] = "DEFAULT";
96
+ COORDINATE_SYSTEM2[COORDINATE_SYSTEM2["LNGLAT"] = 1] = "LNGLAT";
97
+ COORDINATE_SYSTEM2[COORDINATE_SYSTEM2["METER_OFFSETS"] = 2] = "METER_OFFSETS";
98
+ COORDINATE_SYSTEM2[COORDINATE_SYSTEM2["LNGLAT_OFFSETS"] = 3] = "LNGLAT_OFFSETS";
99
+ COORDINATE_SYSTEM2[COORDINATE_SYSTEM2["CARTESIAN"] = 0] = "CARTESIAN";
100
+ return COORDINATE_SYSTEM2;
101
+ })(COORDINATE_SYSTEM || {});
102
+
103
+ // src/i3s-loader.ts
104
+ var import_core7 = require("@loaders.gl/core");
105
+
106
+ // src/lib/parsers/parse-i3s-tile-content.ts
107
+ var import_core3 = require("@loaders.gl/core");
108
+ var import_core4 = require("@math.gl/core");
109
+ var import_geospatial = require("@math.gl/geospatial");
110
+ var import_loader_utils = require("@loaders.gl/loader-utils");
111
+ var import_images = require("@loaders.gl/images");
112
+ var import_draco = require("@loaders.gl/draco");
113
+ var import_textures = require("@loaders.gl/textures");
114
+
115
+ // src/lib/utils/url-utils.ts
116
+ function getUrlWithToken(url, token = null) {
117
+ return token ? `${url}?token=${token}` : url;
118
+ }
119
+ function generateTileAttributeUrls(url, tile) {
120
+ const { attributeData = [] } = tile;
121
+ const attributeUrls = [];
122
+ for (let index = 0; index < attributeData.length; index++) {
123
+ const attributeUrl = attributeData[index].href.replace("./", "");
124
+ attributeUrls.push(`${url}/${attributeUrl}`);
125
+ }
126
+ return attributeUrls;
127
+ }
128
+ function generateTilesetAttributeUrls(tileset, url, resource) {
129
+ const attributeUrls = [];
130
+ const { attributeStorageInfo = [] } = tileset;
131
+ for (let index = 0; index < attributeStorageInfo.length; index++) {
132
+ const fileName = attributeStorageInfo[index].key;
133
+ attributeUrls.push(`${url}/nodes/${resource}/attributes/${fileName}/0`);
134
+ }
135
+ return attributeUrls;
136
+ }
137
+
138
+ // src/lib/utils/customize-сolors.ts
139
+ var import_core2 = require("@loaders.gl/core");
140
+
141
+ // src/i3s-attribute-loader.ts
142
+ var import_core = require("@loaders.gl/core");
143
+
144
+ // src/lib/parsers/parse-i3s-attribute.ts
145
+ function parseI3STileAttribute(arrayBuffer, options) {
146
+ const { attributeName, attributeType } = options;
147
+ if (!attributeName) {
148
+ return {};
149
+ }
150
+ return {
151
+ [attributeName]: attributeType ? parseAttribute(attributeType, arrayBuffer) : null
152
+ };
153
+ }
154
+ function parseAttribute(attributeType, arrayBuffer) {
155
+ switch (attributeType) {
156
+ case STRING_ATTRIBUTE_TYPE:
157
+ return parseStringsAttribute(arrayBuffer);
158
+ case OBJECT_ID_ATTRIBUTE_TYPE:
159
+ return parseShortNumberAttribute(arrayBuffer);
160
+ case FLOAT_64_TYPE:
161
+ return parseFloatAttribute(arrayBuffer);
162
+ case INT_16_ATTRIBUTE_TYPE:
163
+ return parseInt16ShortNumberAttribute(arrayBuffer);
164
+ default:
165
+ return parseShortNumberAttribute(arrayBuffer);
166
+ }
167
+ }
168
+ function parseShortNumberAttribute(arrayBuffer) {
169
+ const countOffset = 4;
170
+ return new Uint32Array(arrayBuffer, countOffset);
171
+ }
172
+ function parseInt16ShortNumberAttribute(arrayBuffer) {
173
+ const countOffset = 4;
174
+ return new Int16Array(arrayBuffer, countOffset);
175
+ }
176
+ function parseFloatAttribute(arrayBuffer) {
177
+ const countOffset = 8;
178
+ return new Float64Array(arrayBuffer, countOffset);
179
+ }
180
+ function parseStringsAttribute(arrayBuffer) {
181
+ const stringsCountOffset = 0;
182
+ const dataOffset = 8;
183
+ const bytesPerStringSize = 4;
184
+ const stringsArray = [];
185
+ try {
186
+ const stringsCount = new DataView(
187
+ arrayBuffer,
188
+ stringsCountOffset,
189
+ bytesPerStringSize
190
+ ).getUint32(stringsCountOffset, true);
191
+ const stringSizes = new Uint32Array(arrayBuffer, dataOffset, stringsCount);
192
+ let stringOffset = dataOffset + stringsCount * bytesPerStringSize;
193
+ for (const stringByteSize of stringSizes) {
194
+ const textDecoder = new TextDecoder("utf-8");
195
+ const stringAttribute = new Uint8Array(arrayBuffer, stringOffset, stringByteSize);
196
+ stringsArray.push(textDecoder.decode(stringAttribute));
197
+ stringOffset += stringByteSize;
198
+ }
199
+ } catch (error) {
200
+ console.error("Parse string attribute error: ", error.message);
201
+ }
202
+ return stringsArray;
203
+ }
204
+
205
+ // src/i3s-attribute-loader.ts
206
+ var VERSION = typeof __VERSION__ !== "undefined" ? __VERSION__ : "latest";
207
+ var EMPTY_VALUE = "";
208
+ var REJECTED_STATUS = "rejected";
209
+ var I3SAttributeLoader = {
210
+ name: "I3S Attribute",
211
+ id: "i3s-attribute",
212
+ module: "i3s",
213
+ version: VERSION,
214
+ mimeTypes: ["application/binary"],
215
+ parse: async (arrayBuffer, options) => parseI3STileAttribute(arrayBuffer, options),
216
+ extensions: ["bin"],
217
+ options: {},
218
+ binary: true
219
+ };
220
+ async function loadFeatureAttributes(tile, featureId, options = {}) {
221
+ var _a;
222
+ const { attributeStorageInfo, attributeUrls, tilesetFields } = getAttributesData(tile);
223
+ if (!attributeStorageInfo || !attributeUrls || featureId < 0) {
224
+ return null;
225
+ }
226
+ let attributes = [];
227
+ const attributeLoadPromises = [];
228
+ for (let index = 0; index < attributeStorageInfo.length; index++) {
229
+ const url = getUrlWithToken(attributeUrls[index], (_a = options.i3s) == null ? void 0 : _a.token);
230
+ const attributeName = attributeStorageInfo[index].name;
231
+ const attributeType = getAttributeValueType(attributeStorageInfo[index]);
232
+ const loadOptions = { ...options, attributeName, attributeType };
233
+ const promise = (0, import_core.load)(url, I3SAttributeLoader, loadOptions);
234
+ attributeLoadPromises.push(promise);
235
+ }
236
+ try {
237
+ attributes = await Promise.allSettled(attributeLoadPromises);
238
+ } catch (error) {
239
+ }
240
+ if (!attributes.length) {
241
+ return null;
242
+ }
243
+ return generateAttributesByFeatureId(attributes, attributeStorageInfo, featureId, tilesetFields);
244
+ }
245
+ function getAttributesData(tile) {
246
+ var _a, _b, _c, _d, _e;
247
+ const attributeStorageInfo = (_b = (_a = tile.tileset) == null ? void 0 : _a.tileset) == null ? void 0 : _b.attributeStorageInfo;
248
+ const attributeUrls = (_c = tile.header) == null ? void 0 : _c.attributeUrls;
249
+ const tilesetFields = ((_e = (_d = tile.tileset) == null ? void 0 : _d.tileset) == null ? void 0 : _e.fields) || [];
250
+ return { attributeStorageInfo, attributeUrls, tilesetFields };
251
+ }
252
+ function getAttributeValueType(attribute) {
253
+ if (attribute.hasOwnProperty("objectIds")) {
254
+ return "Oid32";
255
+ } else if (attribute.hasOwnProperty("attributeValues")) {
256
+ return attribute.attributeValues.valueType;
257
+ }
258
+ return "";
259
+ }
260
+ function getFeatureIdsAttributeName(attributeStorageInfo) {
261
+ const objectIdsAttribute = attributeStorageInfo.find((attribute) => attribute.name.includes("OBJECTID"));
262
+ return objectIdsAttribute == null ? void 0 : objectIdsAttribute.name;
263
+ }
264
+ function generateAttributesByFeatureId(attributes, attributeStorageInfo, featureId, tilesetFields) {
265
+ const objectIdsAttributeName = getFeatureIdsAttributeName(attributeStorageInfo);
266
+ const objectIds = attributes.find((attribute) => attribute.value[objectIdsAttributeName]);
267
+ if (!objectIds) {
268
+ return null;
269
+ }
270
+ const attributeIndex = objectIds.value[objectIdsAttributeName].indexOf(featureId);
271
+ if (attributeIndex < 0) {
272
+ return null;
273
+ }
274
+ return getFeatureAttributesByIndex(attributes, attributeIndex, attributeStorageInfo, tilesetFields);
275
+ }
276
+ function getFeatureAttributesByIndex(attributes, featureIdIndex, attributeStorageInfo, tilesetFields) {
277
+ const attributesObject = {};
278
+ for (let index = 0; index < attributeStorageInfo.length; index++) {
279
+ const attributeName = attributeStorageInfo[index].name;
280
+ const codedValues = getAttributeCodedValues(attributeName, tilesetFields);
281
+ const attribute = getAttributeByIndexAndAttributeName(attributes, index, attributeName);
282
+ attributesObject[attributeName] = formatAttributeValue(attribute, featureIdIndex, codedValues);
283
+ }
284
+ return attributesObject;
285
+ }
286
+ function getAttributeCodedValues(attributeName, tilesetFields) {
287
+ var _a;
288
+ const attributeField = tilesetFields.find((field) => field.name === attributeName || field.alias === attributeName);
289
+ return ((_a = attributeField == null ? void 0 : attributeField.domain) == null ? void 0 : _a.codedValues) || [];
290
+ }
291
+ function getAttributeByIndexAndAttributeName(attributes, index, attributesName) {
292
+ const attributeObject = attributes[index];
293
+ if (attributeObject.status === REJECTED_STATUS) {
294
+ return null;
295
+ }
296
+ return attributeObject.value[attributesName];
297
+ }
298
+ function formatAttributeValue(attribute, featureIdIndex, codedValues) {
299
+ let value = EMPTY_VALUE;
300
+ if (attribute && featureIdIndex in attribute) {
301
+ value = String(attribute[featureIdIndex]).replace(/\u0000|NaN/g, "").trim();
302
+ }
303
+ if (codedValues.length) {
304
+ const codeValue = codedValues.find((codedValue) => codedValue.code === Number(value));
305
+ value = (codeValue == null ? void 0 : codeValue.name) || EMPTY_VALUE;
306
+ }
307
+ return value;
308
+ }
309
+
310
+ // src/lib/utils/customize-сolors.ts
311
+ async function customizeColors(colors, featureIds, tileOptions, tilesetOptions, options) {
312
+ var _a;
313
+ if (!((_a = options == null ? void 0 : options.i3s) == null ? void 0 : _a.colorsByAttribute)) {
314
+ return colors;
315
+ }
316
+ const colorizeAttributeField = tilesetOptions.fields.find(
317
+ ({ name }) => {
318
+ var _a2, _b;
319
+ return name === ((_b = (_a2 = options == null ? void 0 : options.i3s) == null ? void 0 : _a2.colorsByAttribute) == null ? void 0 : _b.attributeName);
320
+ }
321
+ );
322
+ if (!colorizeAttributeField || !["esriFieldTypeDouble", "esriFieldTypeInteger", "esriFieldTypeSmallInteger"].includes(
323
+ colorizeAttributeField.type
324
+ )) {
325
+ return colors;
326
+ }
327
+ const colorizeAttributeData = await loadFeatureAttributeData(
328
+ colorizeAttributeField.name,
329
+ tileOptions,
330
+ tilesetOptions,
331
+ options
332
+ );
333
+ if (!colorizeAttributeData) {
334
+ return colors;
335
+ }
336
+ const objectIdField = tilesetOptions.fields.find(({ type }) => type === "esriFieldTypeOID");
337
+ if (!objectIdField) {
338
+ return colors;
339
+ }
340
+ const objectIdAttributeData = await loadFeatureAttributeData(
341
+ objectIdField.name,
342
+ tileOptions,
343
+ tilesetOptions,
344
+ options
345
+ );
346
+ if (!objectIdAttributeData) {
347
+ return colors;
348
+ }
349
+ const attributeValuesMap = {};
350
+ for (let i = 0; i < objectIdAttributeData[objectIdField.name].length; i++) {
351
+ attributeValuesMap[objectIdAttributeData[objectIdField.name][i]] = calculateColorForAttribute(
352
+ // @ts-expect-error
353
+ colorizeAttributeData[colorizeAttributeField.name][i],
354
+ options
355
+ );
356
+ }
357
+ for (let i = 0; i < featureIds.value.length; i++) {
358
+ const color = attributeValuesMap[featureIds.value[i]];
359
+ if (!color) {
360
+ continue;
361
+ }
362
+ if (options.i3s.colorsByAttribute.mode === "multiply") {
363
+ color.forEach((colorItem, index) => {
364
+ colors.value[i * 4 + index] = colors.value[i * 4 + index] * colorItem / 255;
365
+ });
366
+ } else {
367
+ colors.value.set(color, i * 4);
368
+ }
369
+ }
370
+ return colors;
371
+ }
372
+ function calculateColorForAttribute(attributeValue, options) {
373
+ var _a;
374
+ if (!((_a = options == null ? void 0 : options.i3s) == null ? void 0 : _a.colorsByAttribute)) {
375
+ return [255, 255, 255, 255];
376
+ }
377
+ const { minValue, maxValue, minColor, maxColor } = options.i3s.colorsByAttribute;
378
+ const rate = (attributeValue - minValue) / (maxValue - minValue);
379
+ const color = [255, 255, 255, 255];
380
+ for (let i = 0; i < minColor.length; i++) {
381
+ color[i] = Math.round((maxColor[i] - minColor[i]) * rate + minColor[i]);
382
+ }
383
+ return color;
384
+ }
385
+ async function loadFeatureAttributeData(attributeName, { attributeUrls }, { attributeStorageInfo }, options) {
386
+ var _a;
387
+ const attributeIndex = attributeStorageInfo.findIndex(({ name }) => attributeName === name);
388
+ if (attributeIndex === -1) {
389
+ return null;
390
+ }
391
+ const objectIdAttributeUrl = getUrlWithToken(attributeUrls[attributeIndex], (_a = options == null ? void 0 : options.i3s) == null ? void 0 : _a.token);
392
+ const attributeType = getAttributeValueType(attributeStorageInfo[attributeIndex]);
393
+ const objectIdAttributeData = await (0, import_core2.load)(objectIdAttributeUrl, I3SAttributeLoader, {
394
+ attributeName,
395
+ attributeType
396
+ });
397
+ return objectIdAttributeData;
398
+ }
399
+
400
+ // src/lib/parsers/parse-i3s-tile-content.ts
401
+ var scratchVector = new import_core4.Vector3([0, 0, 0]);
402
+ function getLoaderForTextureFormat(textureFormat) {
403
+ switch (textureFormat) {
404
+ case "ktx-etc2":
405
+ case "dds":
406
+ return import_textures.CompressedTextureLoader;
407
+ case "ktx2":
408
+ return import_textures.BasisLoader;
409
+ case "jpg":
410
+ case "png":
411
+ default:
412
+ return import_images.ImageLoader;
413
+ }
414
+ }
415
+ var I3S_ATTRIBUTE_TYPE = "i3s-attribute-type";
416
+ async function parseI3STileContent(arrayBuffer, tileOptions, tilesetOptions, options, context) {
417
+ var _a;
418
+ const content = {
419
+ attributes: {},
420
+ indices: null,
421
+ featureIds: [],
422
+ vertexCount: 0,
423
+ modelMatrix: new import_core4.Matrix4(),
424
+ coordinateSystem: 0,
425
+ byteLength: 0,
426
+ texture: null
427
+ };
428
+ if (tileOptions.textureUrl) {
429
+ const url = getUrlWithToken(tileOptions.textureUrl, (_a = options == null ? void 0 : options.i3s) == null ? void 0 : _a.token);
430
+ const loader = getLoaderForTextureFormat(tileOptions.textureFormat);
431
+ const fetch = context == null ? void 0 : context.fetch;
432
+ const response = await fetch(url);
433
+ const arrayBuffer2 = await response.arrayBuffer();
434
+ if (options == null ? void 0 : options.i3s.decodeTextures) {
435
+ if (loader === import_images.ImageLoader) {
436
+ const options2 = { ...tileOptions.textureLoaderOptions, image: { type: "data" } };
437
+ try {
438
+ const texture = await (0, import_loader_utils.parseFromContext)(arrayBuffer2, [], options2, context);
439
+ content.texture = texture;
440
+ } catch (e) {
441
+ const texture = await (0, import_core3.parse)(arrayBuffer2, loader, options2, context);
442
+ content.texture = texture;
443
+ }
444
+ } else if (loader === import_textures.CompressedTextureLoader || loader === import_textures.BasisLoader) {
445
+ let texture = await (0, import_core3.load)(arrayBuffer2, loader, tileOptions.textureLoaderOptions);
446
+ if (loader === import_textures.BasisLoader) {
447
+ texture = texture[0];
448
+ }
449
+ content.texture = {
450
+ compressed: true,
451
+ mipmaps: false,
452
+ width: texture[0].width,
453
+ height: texture[0].height,
454
+ data: texture
455
+ };
456
+ }
457
+ } else {
458
+ content.texture = arrayBuffer2;
459
+ }
460
+ }
461
+ content.material = makePbrMaterial(tileOptions.materialDefinition, content.texture);
462
+ if (content.material) {
463
+ content.texture = null;
464
+ }
465
+ return await parseI3SNodeGeometry(arrayBuffer, content, tileOptions, tilesetOptions, options);
466
+ }
467
+ async function parseI3SNodeGeometry(arrayBuffer, content, tileOptions, tilesetOptions, options) {
468
+ var _a, _b;
469
+ const contentByteLength = arrayBuffer.byteLength;
470
+ let attributes;
471
+ let vertexCount;
472
+ let byteOffset = 0;
473
+ let featureCount = 0;
474
+ let indices;
475
+ if (tileOptions.isDracoGeometry) {
476
+ const decompressedGeometry = await (0, import_core3.parse)(arrayBuffer, import_draco.DracoLoader, {
477
+ draco: {
478
+ attributeNameEntry: I3S_ATTRIBUTE_TYPE
479
+ }
480
+ });
481
+ vertexCount = decompressedGeometry.header.vertexCount;
482
+ indices = (_a = decompressedGeometry.indices) == null ? void 0 : _a.value;
483
+ const {
484
+ POSITION,
485
+ NORMAL,
486
+ COLOR_0,
487
+ TEXCOORD_0,
488
+ ["feature-index"]: featureIndex,
489
+ ["uv-region"]: uvRegion
490
+ } = decompressedGeometry.attributes;
491
+ attributes = {
492
+ position: POSITION,
493
+ normal: NORMAL,
494
+ color: COLOR_0,
495
+ uv0: TEXCOORD_0,
496
+ uvRegion,
497
+ id: featureIndex
498
+ };
499
+ updateAttributesMetadata(attributes, decompressedGeometry);
500
+ const featureIds = getFeatureIdsFromFeatureIndexMetadata(featureIndex);
501
+ if (featureIds) {
502
+ flattenFeatureIdsByFeatureIndices(attributes, featureIds);
503
+ }
504
+ } else {
505
+ const {
506
+ vertexAttributes,
507
+ ordering: attributesOrder,
508
+ featureAttributes,
509
+ featureAttributeOrder
510
+ } = tilesetOptions.store.defaultGeometrySchema;
511
+ const headers = parseHeaders(arrayBuffer, tilesetOptions);
512
+ byteOffset = headers.byteOffset;
513
+ vertexCount = headers.vertexCount;
514
+ featureCount = headers.featureCount;
515
+ const { attributes: normalizedVertexAttributes, byteOffset: offset } = normalizeAttributes(
516
+ arrayBuffer,
517
+ byteOffset,
518
+ vertexAttributes,
519
+ vertexCount,
520
+ attributesOrder
521
+ );
522
+ const { attributes: normalizedFeatureAttributes } = normalizeAttributes(
523
+ arrayBuffer,
524
+ offset,
525
+ featureAttributes,
526
+ featureCount,
527
+ featureAttributeOrder
528
+ );
529
+ flattenFeatureIdsByFaceRanges(normalizedFeatureAttributes);
530
+ attributes = concatAttributes(normalizedVertexAttributes, normalizedFeatureAttributes);
531
+ }
532
+ if (!((_b = options == null ? void 0 : options.i3s) == null ? void 0 : _b.coordinateSystem) || options.i3s.coordinateSystem === 2 /* METER_OFFSETS */) {
533
+ const enuMatrix = parsePositions(attributes.position, tileOptions);
534
+ content.modelMatrix = enuMatrix.invert();
535
+ content.coordinateSystem = 2 /* METER_OFFSETS */;
536
+ } else {
537
+ content.modelMatrix = getModelMatrix(attributes.position);
538
+ content.coordinateSystem = 3 /* LNGLAT_OFFSETS */;
539
+ }
540
+ attributes.color = await customizeColors(
541
+ attributes.color,
542
+ attributes.id,
543
+ tileOptions,
544
+ tilesetOptions,
545
+ options
546
+ );
547
+ content.attributes = {
548
+ positions: attributes.position,
549
+ normals: attributes.normal,
550
+ colors: normalizeAttribute(attributes.color),
551
+ // Normalize from UInt8
552
+ texCoords: attributes.uv0,
553
+ uvRegions: normalizeAttribute(attributes.uvRegion || attributes.region)
554
+ // Normalize from UInt16
555
+ };
556
+ content.indices = indices || null;
557
+ if (attributes.id && attributes.id.value) {
558
+ content.featureIds = attributes.id.value;
559
+ }
560
+ for (const attributeIndex in content.attributes) {
561
+ if (!content.attributes[attributeIndex]) {
562
+ delete content.attributes[attributeIndex];
563
+ }
564
+ }
565
+ content.vertexCount = vertexCount;
566
+ content.byteLength = contentByteLength;
567
+ return content;
568
+ }
569
+ function updateAttributesMetadata(attributes, decompressedGeometry) {
570
+ for (const key in decompressedGeometry.loaderData.attributes) {
571
+ const dracoAttribute = decompressedGeometry.loaderData.attributes[key];
572
+ switch (dracoAttribute.name) {
573
+ case "POSITION":
574
+ attributes.position.metadata = dracoAttribute.metadata;
575
+ break;
576
+ case "feature-index":
577
+ attributes.id.metadata = dracoAttribute.metadata;
578
+ break;
579
+ default:
580
+ break;
581
+ }
582
+ }
583
+ }
584
+ function concatAttributes(normalizedVertexAttributes, normalizedFeatureAttributes) {
585
+ return { ...normalizedVertexAttributes, ...normalizedFeatureAttributes };
586
+ }
587
+ function normalizeAttribute(attribute) {
588
+ if (!attribute) {
589
+ return attribute;
590
+ }
591
+ attribute.normalized = true;
592
+ return attribute;
593
+ }
594
+ function parseHeaders(arrayBuffer, options) {
595
+ let byteOffset = 0;
596
+ let vertexCount = 0;
597
+ let featureCount = 0;
598
+ for (const { property, type } of options.store.defaultGeometrySchema.header) {
599
+ const TypedArrayTypeHeader = getConstructorForDataFormat(type);
600
+ switch (property) {
601
+ case "vertexCount" /* vertexCount */:
602
+ vertexCount = new TypedArrayTypeHeader(arrayBuffer, 0, 4)[0];
603
+ byteOffset += sizeOf(type);
604
+ break;
605
+ case "featureCount" /* featureCount */:
606
+ featureCount = new TypedArrayTypeHeader(arrayBuffer, 4, 4)[0];
607
+ byteOffset += sizeOf(type);
608
+ break;
609
+ default:
610
+ break;
611
+ }
612
+ }
613
+ return {
614
+ vertexCount,
615
+ featureCount,
616
+ byteOffset
617
+ };
618
+ }
619
+ function normalizeAttributes(arrayBuffer, byteOffset, vertexAttributes, attributeCount, attributesOrder) {
620
+ const attributes = {};
621
+ for (const attribute of attributesOrder) {
622
+ if (vertexAttributes[attribute]) {
623
+ const { valueType, valuesPerElement } = vertexAttributes[attribute];
624
+ if (byteOffset + attributeCount * valuesPerElement * sizeOf(valueType) <= arrayBuffer.byteLength) {
625
+ const buffer = arrayBuffer.slice(byteOffset);
626
+ let value;
627
+ if (valueType === "UInt64") {
628
+ value = parseUint64Values(buffer, attributeCount * valuesPerElement, sizeOf(valueType));
629
+ } else {
630
+ const TypedArrayType = getConstructorForDataFormat(valueType);
631
+ value = new TypedArrayType(buffer, 0, attributeCount * valuesPerElement);
632
+ }
633
+ attributes[attribute] = {
634
+ value,
635
+ type: GL_TYPE_MAP[valueType],
636
+ size: valuesPerElement
637
+ };
638
+ switch (attribute) {
639
+ case "color":
640
+ attributes.color.normalized = true;
641
+ break;
642
+ case "position":
643
+ case "region":
644
+ case "normal":
645
+ default:
646
+ }
647
+ byteOffset = byteOffset + attributeCount * valuesPerElement * sizeOf(valueType);
648
+ } else if (attribute !== "uv0") {
649
+ break;
650
+ }
651
+ }
652
+ }
653
+ return { attributes, byteOffset };
654
+ }
655
+ function parseUint64Values(buffer, elementsCount, attributeSize) {
656
+ const values = [];
657
+ const dataView = new DataView(buffer);
658
+ let offset = 0;
659
+ for (let index = 0; index < elementsCount; index++) {
660
+ const left = dataView.getUint32(offset, true);
661
+ const right = dataView.getUint32(offset + 4, true);
662
+ const value = left + 2 ** 32 * right;
663
+ values.push(value);
664
+ offset += attributeSize;
665
+ }
666
+ return new Uint32Array(values);
667
+ }
668
+ function parsePositions(attribute, options) {
669
+ const mbs = options.mbs;
670
+ const value = attribute.value;
671
+ const metadata = attribute.metadata;
672
+ const enuMatrix = new import_core4.Matrix4();
673
+ const cartographicOrigin = new import_core4.Vector3(mbs[0], mbs[1], mbs[2]);
674
+ const cartesianOrigin = new import_core4.Vector3();
675
+ import_geospatial.Ellipsoid.WGS84.cartographicToCartesian(cartographicOrigin, cartesianOrigin);
676
+ import_geospatial.Ellipsoid.WGS84.eastNorthUpToFixedFrame(cartesianOrigin, enuMatrix);
677
+ attribute.value = offsetsToCartesians(value, metadata, cartographicOrigin);
678
+ return enuMatrix;
679
+ }
680
+ function offsetsToCartesians(vertices, metadata = {}, cartographicOrigin) {
681
+ const positions = new Float64Array(vertices.length);
682
+ const scaleX = metadata["i3s-scale_x"] && metadata["i3s-scale_x"].double || 1;
683
+ const scaleY = metadata["i3s-scale_y"] && metadata["i3s-scale_y"].double || 1;
684
+ for (let i = 0; i < positions.length; i += 3) {
685
+ positions[i] = vertices[i] * scaleX + cartographicOrigin.x;
686
+ positions[i + 1] = vertices[i + 1] * scaleY + cartographicOrigin.y;
687
+ positions[i + 2] = vertices[i + 2] + cartographicOrigin.z;
688
+ }
689
+ for (let i = 0; i < positions.length; i += 3) {
690
+ import_geospatial.Ellipsoid.WGS84.cartographicToCartesian(positions.subarray(i, i + 3), scratchVector);
691
+ positions[i] = scratchVector.x;
692
+ positions[i + 1] = scratchVector.y;
693
+ positions[i + 2] = scratchVector.z;
694
+ }
695
+ return positions;
696
+ }
697
+ function getModelMatrix(positions) {
698
+ var _a, _b;
699
+ const metadata = positions.metadata;
700
+ const scaleX = ((_a = metadata == null ? void 0 : metadata["i3s-scale_x"]) == null ? void 0 : _a.double) || 1;
701
+ const scaleY = ((_b = metadata == null ? void 0 : metadata["i3s-scale_y"]) == null ? void 0 : _b.double) || 1;
702
+ const modelMatrix = new import_core4.Matrix4();
703
+ modelMatrix[0] = scaleX;
704
+ modelMatrix[5] = scaleY;
705
+ return modelMatrix;
706
+ }
707
+ function makePbrMaterial(materialDefinition, texture) {
708
+ let pbrMaterial;
709
+ if (materialDefinition) {
710
+ pbrMaterial = {
711
+ ...materialDefinition,
712
+ pbrMetallicRoughness: materialDefinition.pbrMetallicRoughness ? { ...materialDefinition.pbrMetallicRoughness } : { baseColorFactor: [255, 255, 255, 255] }
713
+ };
714
+ } else {
715
+ pbrMaterial = {
716
+ pbrMetallicRoughness: {}
717
+ };
718
+ if (texture) {
719
+ pbrMaterial.pbrMetallicRoughness.baseColorTexture = { texCoord: 0 };
720
+ } else {
721
+ pbrMaterial.pbrMetallicRoughness.baseColorFactor = [255, 255, 255, 255];
722
+ }
723
+ }
724
+ pbrMaterial.alphaCutoff = pbrMaterial.alphaCutoff || 0.25;
725
+ if (pbrMaterial.alphaMode) {
726
+ pbrMaterial.alphaMode = pbrMaterial.alphaMode.toUpperCase();
727
+ }
728
+ if (pbrMaterial.emissiveFactor) {
729
+ pbrMaterial.emissiveFactor = convertColorFormat(pbrMaterial.emissiveFactor);
730
+ }
731
+ if (pbrMaterial.pbrMetallicRoughness && pbrMaterial.pbrMetallicRoughness.baseColorFactor) {
732
+ pbrMaterial.pbrMetallicRoughness.baseColorFactor = convertColorFormat(
733
+ pbrMaterial.pbrMetallicRoughness.baseColorFactor
734
+ );
735
+ }
736
+ if (texture) {
737
+ setMaterialTexture(pbrMaterial, texture);
738
+ }
739
+ return pbrMaterial;
740
+ }
741
+ function convertColorFormat(colorFactor) {
742
+ const normalizedColor = [...colorFactor];
743
+ for (let index = 0; index < colorFactor.length; index++) {
744
+ normalizedColor[index] = colorFactor[index] / 255;
745
+ }
746
+ return normalizedColor;
747
+ }
748
+ function setMaterialTexture(material, image) {
749
+ const texture = { source: { image } };
750
+ if (material.pbrMetallicRoughness && material.pbrMetallicRoughness.baseColorTexture) {
751
+ material.pbrMetallicRoughness.baseColorTexture = {
752
+ ...material.pbrMetallicRoughness.baseColorTexture,
753
+ texture
754
+ };
755
+ } else if (material.emissiveTexture) {
756
+ material.emissiveTexture = { ...material.emissiveTexture, texture };
757
+ } else if (material.pbrMetallicRoughness && material.pbrMetallicRoughness.metallicRoughnessTexture) {
758
+ material.pbrMetallicRoughness.metallicRoughnessTexture = {
759
+ ...material.pbrMetallicRoughness.metallicRoughnessTexture,
760
+ texture
761
+ };
762
+ } else if (material.normalTexture) {
763
+ material.normalTexture = { ...material.normalTexture, texture };
764
+ } else if (material.occlusionTexture) {
765
+ material.occlusionTexture = { ...material.occlusionTexture, texture };
766
+ }
767
+ }
768
+ function flattenFeatureIdsByFaceRanges(normalizedFeatureAttributes) {
769
+ const { id, faceRange } = normalizedFeatureAttributes;
770
+ if (!id || !faceRange) {
771
+ return;
772
+ }
773
+ const featureIds = id.value;
774
+ const range = faceRange.value;
775
+ const featureIdsLength = range[range.length - 1] + 1;
776
+ const orderedFeatureIndices = new Uint32Array(featureIdsLength * 3);
777
+ let featureIndex = 0;
778
+ let startIndex = 0;
779
+ for (let index = 1; index < range.length; index += 2) {
780
+ const fillId = Number(featureIds[featureIndex]);
781
+ const endValue = range[index];
782
+ const prevValue = range[index - 1];
783
+ const trianglesCount = endValue - prevValue + 1;
784
+ const endIndex = startIndex + trianglesCount * 3;
785
+ orderedFeatureIndices.fill(fillId, startIndex, endIndex);
786
+ featureIndex++;
787
+ startIndex = endIndex;
788
+ }
789
+ normalizedFeatureAttributes.id.value = orderedFeatureIndices;
790
+ }
791
+ function flattenFeatureIdsByFeatureIndices(attributes, featureIds) {
792
+ const featureIndices = attributes.id.value;
793
+ const result = new Float32Array(featureIndices.length);
794
+ for (let index = 0; index < featureIndices.length; index++) {
795
+ result[index] = featureIds[featureIndices[index]];
796
+ }
797
+ attributes.id.value = result;
798
+ }
799
+ function getFeatureIdsFromFeatureIndexMetadata(featureIndex) {
800
+ var _a, _b;
801
+ return (_b = (_a = featureIndex == null ? void 0 : featureIndex.metadata) == null ? void 0 : _a["i3s-feature-ids"]) == null ? void 0 : _b.intArray;
802
+ }
803
+
804
+ // src/i3s-content-loader.ts
805
+ var VERSION2 = typeof __VERSION__ !== "undefined" ? __VERSION__ : "beta";
806
+ var I3SContentLoader = {
807
+ name: "I3S Content (Indexed Scene Layers)",
808
+ id: "i3s-content",
809
+ module: "i3s",
810
+ worker: true,
811
+ version: VERSION2,
812
+ mimeTypes: ["application/octet-stream"],
813
+ parse: parse2,
814
+ extensions: ["bin"],
815
+ options: {
816
+ "i3s-content": {}
817
+ }
818
+ };
819
+ async function parse2(data, options, context) {
820
+ const { tile, _tileOptions, tileset, _tilesetOptions } = (options == null ? void 0 : options.i3s) || {};
821
+ const tileOptions = _tileOptions || tile;
822
+ const tilesetOptions = _tilesetOptions || tileset;
823
+ if (!tileOptions || !tilesetOptions) {
824
+ return null;
825
+ }
826
+ return await parseI3STileContent(
827
+ data,
828
+ tileOptions,
829
+ tilesetOptions,
830
+ options,
831
+ context
832
+ );
833
+ }
834
+
835
+ // src/lib/parsers/parse-i3s.ts
836
+ var import_culling = require("@math.gl/culling");
837
+ var import_geospatial2 = require("@math.gl/geospatial");
838
+ var import_core6 = require("@loaders.gl/core");
839
+ var import_tiles = require("@loaders.gl/tiles");
840
+
841
+ // src/lib/helpers/i3s-nodepages-tiles.ts
842
+ var import_core5 = require("@loaders.gl/core");
843
+ var import_textures2 = require("@loaders.gl/textures");
844
+
845
+ // src/i3s-node-page-loader.ts
846
+ var VERSION3 = typeof __VERSION__ !== "undefined" ? __VERSION__ : "latest";
847
+ var I3SNodePageLoader = {
848
+ name: "I3S Node Page",
849
+ id: "i3s-node-page",
850
+ module: "i3s",
851
+ version: VERSION3,
852
+ mimeTypes: ["application/json"],
853
+ parse: parseNodePage,
854
+ extensions: ["json"],
855
+ options: {
856
+ i3s: {}
857
+ }
858
+ };
859
+ async function parseNodePage(data, options) {
860
+ return JSON.parse(new TextDecoder().decode(data));
861
+ }
862
+
863
+ // src/lib/helpers/i3s-nodepages-tiles.ts
864
+ var I3SNodePagesTiles = class {
865
+ /**
866
+ * @constructs
867
+ * Create a I3SNodePagesTiles instance.
868
+ * @param tileset - i3s tileset header ('layers/0')
869
+ * @param url - tileset url
870
+ * @param options - i3s loader options
871
+ */
872
+ constructor(tileset, url = "", options) {
873
+ this.nodePages = [];
874
+ this.pendingNodePages = [];
875
+ this.textureDefinitionsSelectedFormats = [];
876
+ this.textureLoaderOptions = {};
877
+ var _a, _b;
878
+ this.tileset = { ...tileset };
879
+ this.url = url;
880
+ this.nodesPerPage = ((_a = tileset.nodePages) == null ? void 0 : _a.nodesPerPage) || 64;
881
+ this.lodSelectionMetricType = (_b = tileset.nodePages) == null ? void 0 : _b.lodSelectionMetricType;
882
+ this.options = options;
883
+ this.nodesInNodePages = 0;
884
+ this.initSelectedFormatsForTextureDefinitions(tileset);
885
+ }
886
+ /**
887
+ * Loads some nodePage and return a particular node from it
888
+ * @param id - id of node through all node pages
889
+ */
890
+ async getNodeById(id) {
891
+ var _a;
892
+ const pageIndex = Math.floor(id / this.nodesPerPage);
893
+ if (!this.nodePages[pageIndex] && !this.pendingNodePages[pageIndex]) {
894
+ const nodePageUrl = getUrlWithToken(
895
+ `${this.url}/nodepages/${pageIndex}`,
896
+ // @ts-expect-error this.options is not properly typed
897
+ (_a = this.options.i3s) == null ? void 0 : _a.token
898
+ );
899
+ this.pendingNodePages[pageIndex] = {
900
+ status: "Pending",
901
+ promise: (0, import_core5.load)(nodePageUrl, I3SNodePageLoader, this.options)
902
+ };
903
+ this.nodePages[pageIndex] = await this.pendingNodePages[pageIndex].promise;
904
+ this.nodesInNodePages += this.nodePages[pageIndex].nodes.length;
905
+ this.pendingNodePages[pageIndex].status = "Done";
906
+ }
907
+ if (this.pendingNodePages[pageIndex].status === "Pending") {
908
+ this.nodePages[pageIndex] = await this.pendingNodePages[pageIndex].promise;
909
+ }
910
+ const nodeIndex = id % this.nodesPerPage;
911
+ return this.nodePages[pageIndex].nodes[nodeIndex];
912
+ }
913
+ /**
914
+ * Forms tile header using node and tileset data
915
+ * @param id - id of node through all node pages
916
+ */
917
+ // eslint-disable-next-line complexity, max-statements
918
+ async formTileFromNodePages(id) {
919
+ const node = await this.getNodeById(id);
920
+ const children = [];
921
+ const childNodesPromises = [];
922
+ for (const child of node.children || []) {
923
+ childNodesPromises.push(this.getNodeById(child));
924
+ }
925
+ const childNodes = await Promise.all(childNodesPromises);
926
+ for (const childNode of childNodes) {
927
+ children.push({
928
+ id: childNode.index.toString(),
929
+ obb: childNode.obb
930
+ });
931
+ }
932
+ let contentUrl;
933
+ let textureUrl;
934
+ let materialDefinition;
935
+ let textureFormat = "jpg";
936
+ let attributeUrls = [];
937
+ let isDracoGeometry = false;
938
+ if (node && node.mesh) {
939
+ const { url, isDracoGeometry: isDracoGeometryResult } = node.mesh.geometry && this.getContentUrl(node.mesh.geometry) || { isDracoGeometry: false };
940
+ contentUrl = url;
941
+ isDracoGeometry = isDracoGeometryResult;
942
+ const { textureData, materialDefinition: nodeMaterialDefinition } = this.getInformationFromMaterial(node.mesh.material);
943
+ materialDefinition = nodeMaterialDefinition;
944
+ textureFormat = textureData.format || textureFormat;
945
+ if (textureData.name) {
946
+ textureUrl = `${this.url}/nodes/${node.mesh.material.resource}/textures/${textureData.name}`;
947
+ }
948
+ if (this.tileset.attributeStorageInfo) {
949
+ attributeUrls = generateTilesetAttributeUrls(
950
+ this.tileset,
951
+ this.url,
952
+ node.mesh.attribute.resource
953
+ );
954
+ }
955
+ }
956
+ const lodSelection = this.getLodSelection(node);
957
+ return normalizeTileNonUrlData({
958
+ id: id.toString(),
959
+ lodSelection,
960
+ obb: node.obb,
961
+ contentUrl,
962
+ textureUrl,
963
+ attributeUrls,
964
+ materialDefinition,
965
+ textureFormat,
966
+ textureLoaderOptions: this.textureLoaderOptions,
967
+ children,
968
+ isDracoGeometry
969
+ });
970
+ }
971
+ /**
972
+ * Forms url and type of geometry resource by nodepage's data and `geometryDefinitions` in the tileset
973
+ * @param - data about the node's mesh from the nodepage
974
+ * @returns -
975
+ * {string} url - url to the geometry resource
976
+ * {boolean} isDracoGeometry - whether the geometry resource contain DRACO compressed geometry
977
+ */
978
+ getContentUrl(meshGeometryData) {
979
+ let result = null;
980
+ const geometryDefinition = this.tileset.geometryDefinitions[meshGeometryData.definition];
981
+ let geometryIndex = -1;
982
+ if (this.options.i3s && this.options.i3s.useDracoGeometry) {
983
+ geometryIndex = geometryDefinition.geometryBuffers.findIndex(
984
+ (buffer) => buffer.compressedAttributes && buffer.compressedAttributes.encoding === "draco"
985
+ );
986
+ }
987
+ if (geometryIndex === -1) {
988
+ geometryIndex = geometryDefinition.geometryBuffers.findIndex(
989
+ (buffer) => !buffer.compressedAttributes
990
+ );
991
+ }
992
+ if (geometryIndex !== -1) {
993
+ const isDracoGeometry = Boolean(
994
+ geometryDefinition.geometryBuffers[geometryIndex].compressedAttributes
995
+ );
996
+ result = {
997
+ url: `${this.url}/nodes/${meshGeometryData.resource}/geometries/${geometryIndex}`,
998
+ isDracoGeometry
999
+ };
1000
+ }
1001
+ return result;
1002
+ }
1003
+ /**
1004
+ * Forms 1.6 compatible LOD selection object from a nodepage's node data
1005
+ * @param node - a node from nodepage
1006
+ * @returns- Array of LodSelection
1007
+ */
1008
+ getLodSelection(node) {
1009
+ const lodSelection = [];
1010
+ if (this.lodSelectionMetricType === "maxScreenThresholdSQ") {
1011
+ lodSelection.push({
1012
+ metricType: "maxScreenThreshold",
1013
+ // @ts-ignore
1014
+ maxError: Math.sqrt(node.lodThreshold / (Math.PI * 0.25))
1015
+ });
1016
+ }
1017
+ lodSelection.push({
1018
+ metricType: this.lodSelectionMetricType,
1019
+ // @ts-ignore
1020
+ maxError: node.lodThreshold
1021
+ });
1022
+ return lodSelection;
1023
+ }
1024
+ /**
1025
+ * Returns information about texture and material from `materialDefinitions`
1026
+ * @param material - material data from nodepage
1027
+ * @returns - Couple {textureData, materialDefinition}
1028
+ * {string} textureData.name - path name of the texture
1029
+ * {string} textureData.format - format of the texture
1030
+ * materialDefinition - PBR-like material definition from `materialDefinitions`
1031
+ */
1032
+ getInformationFromMaterial(material) {
1033
+ var _a, _b, _c;
1034
+ const informationFromMaterial = { textureData: { name: null } };
1035
+ if (material) {
1036
+ const materialDefinition = (_a = this.tileset.materialDefinitions) == null ? void 0 : _a[material.definition];
1037
+ if (materialDefinition) {
1038
+ informationFromMaterial.materialDefinition = materialDefinition;
1039
+ const textureSetDefinitionIndex = (_c = (_b = materialDefinition == null ? void 0 : materialDefinition.pbrMetallicRoughness) == null ? void 0 : _b.baseColorTexture) == null ? void 0 : _c.textureSetDefinitionId;
1040
+ if (typeof textureSetDefinitionIndex === "number") {
1041
+ informationFromMaterial.textureData = this.textureDefinitionsSelectedFormats[textureSetDefinitionIndex] || informationFromMaterial.textureData;
1042
+ }
1043
+ }
1044
+ }
1045
+ return informationFromMaterial;
1046
+ }
1047
+ /**
1048
+ * Sets preferable and supported format for each textureDefinition of the tileset
1049
+ * @param tileset - I3S layer data
1050
+ * @returns
1051
+ */
1052
+ initSelectedFormatsForTextureDefinitions(tileset) {
1053
+ this.textureDefinitionsSelectedFormats = [];
1054
+ const possibleI3sFormats = this.getSupportedTextureFormats();
1055
+ const textureSetDefinitions = tileset.textureSetDefinitions || [];
1056
+ for (const textureSetDefinition of textureSetDefinitions) {
1057
+ const formats = textureSetDefinition && textureSetDefinition.formats || [];
1058
+ let selectedFormat = null;
1059
+ for (const i3sFormat of possibleI3sFormats) {
1060
+ const format = formats.find((value) => value.format === i3sFormat);
1061
+ if (format) {
1062
+ selectedFormat = format;
1063
+ break;
1064
+ }
1065
+ }
1066
+ if (selectedFormat && selectedFormat.format === "ktx2") {
1067
+ this.textureLoaderOptions.basis = {
1068
+ format: (0, import_textures2.selectSupportedBasisFormat)(),
1069
+ containerFormat: "ktx2",
1070
+ module: "encoder"
1071
+ };
1072
+ }
1073
+ this.textureDefinitionsSelectedFormats.push(selectedFormat);
1074
+ }
1075
+ }
1076
+ /**
1077
+ * Returns the array of supported texture format
1078
+ * @returns list of format strings
1079
+ */
1080
+ getSupportedTextureFormats() {
1081
+ const formats = [];
1082
+ if (!this.options.i3s || this.options.i3s.useCompressedTextures) {
1083
+ const supportedCompressedFormats = (0, import_textures2.getSupportedGPUTextureFormats)();
1084
+ if (supportedCompressedFormats.has("etc2")) {
1085
+ formats.push("ktx-etc2");
1086
+ }
1087
+ if (supportedCompressedFormats.has("dxt")) {
1088
+ formats.push("dds");
1089
+ }
1090
+ formats.push("ktx2");
1091
+ }
1092
+ formats.push("jpg");
1093
+ formats.push("png");
1094
+ return formats;
1095
+ }
1096
+ };
1097
+
1098
+ // src/lib/parsers/parse-i3s.ts
1099
+ function normalizeTileData(tile, context) {
1100
+ const url = context.url || "";
1101
+ let contentUrl;
1102
+ if (tile.geometryData) {
1103
+ contentUrl = `${url}/${tile.geometryData[0].href}`;
1104
+ }
1105
+ let textureUrl;
1106
+ if (tile.textureData) {
1107
+ textureUrl = `${url}/${tile.textureData[0].href}`;
1108
+ }
1109
+ let attributeUrls;
1110
+ if (tile.attributeData) {
1111
+ attributeUrls = generateTileAttributeUrls(url, tile);
1112
+ }
1113
+ const children = tile.children || [];
1114
+ return normalizeTileNonUrlData({
1115
+ ...tile,
1116
+ children,
1117
+ url,
1118
+ contentUrl,
1119
+ textureUrl,
1120
+ textureFormat: "jpg",
1121
+ // `jpg` format will cause `ImageLoader` usage that will be able to handle `png` as well
1122
+ attributeUrls,
1123
+ isDracoGeometry: false
1124
+ });
1125
+ }
1126
+ function normalizeTileNonUrlData(tile) {
1127
+ var _a, _b;
1128
+ const boundingVolume = {};
1129
+ let mbs = [0, 0, 0, 1];
1130
+ if (tile.mbs) {
1131
+ mbs = tile.mbs;
1132
+ boundingVolume.sphere = [
1133
+ ...import_geospatial2.Ellipsoid.WGS84.cartographicToCartesian(tile.mbs.slice(0, 3)),
1134
+ // cartesian center of sphere
1135
+ tile.mbs[3]
1136
+ // radius of sphere
1137
+ ];
1138
+ } else if (tile.obb) {
1139
+ boundingVolume.box = [
1140
+ ...import_geospatial2.Ellipsoid.WGS84.cartographicToCartesian(tile.obb.center),
1141
+ // cartesian center of box
1142
+ ...tile.obb.halfSize,
1143
+ // halfSize
1144
+ ...tile.obb.quaternion
1145
+ // quaternion
1146
+ ];
1147
+ const obb = new import_culling.OrientedBoundingBox().fromCenterHalfSizeQuaternion(
1148
+ boundingVolume.box.slice(0, 3),
1149
+ tile.obb.halfSize,
1150
+ tile.obb.quaternion
1151
+ );
1152
+ const boundingSphere = obb.getBoundingSphere();
1153
+ boundingVolume.sphere = [...boundingSphere.center, boundingSphere.radius];
1154
+ mbs = [...tile.obb.center, boundingSphere.radius];
1155
+ }
1156
+ const lodMetricType = (_a = tile.lodSelection) == null ? void 0 : _a[0].metricType;
1157
+ const lodMetricValue = (_b = tile.lodSelection) == null ? void 0 : _b[0].maxError;
1158
+ const type = import_tiles.TILE_TYPE.MESH;
1159
+ const refine = import_tiles.TILE_REFINEMENT.REPLACE;
1160
+ return { ...tile, mbs, boundingVolume, lodMetricType, lodMetricValue, type, refine };
1161
+ }
1162
+ async function normalizeTilesetData(tileset, options, context) {
1163
+ const url = context.url;
1164
+ let nodePagesTile;
1165
+ let root;
1166
+ if (tileset.nodePages) {
1167
+ nodePagesTile = new I3SNodePagesTiles(tileset, url, options);
1168
+ root = await nodePagesTile.formTileFromNodePages(0);
1169
+ } else {
1170
+ const parseOptions = options.i3s;
1171
+ const rootNodeUrl = getUrlWithToken(`${url}/nodes/root`, parseOptions.token);
1172
+ root = await (0, import_core6.load)(rootNodeUrl, I3SLoader, {
1173
+ ...options,
1174
+ i3s: {
1175
+ // @ts-expect-error options is not properly typed
1176
+ ...options.i3s,
1177
+ loadContent: false,
1178
+ isTileHeader: true,
1179
+ isTileset: false
1180
+ }
1181
+ });
1182
+ }
1183
+ return {
1184
+ ...tileset,
1185
+ loader: I3SLoader,
1186
+ url,
1187
+ basePath: url,
1188
+ type: import_tiles.TILESET_TYPE.I3S,
1189
+ nodePagesTile,
1190
+ // @ts-expect-error
1191
+ root,
1192
+ lodMetricType: root.lodMetricType,
1193
+ lodMetricValue: root.lodMetricValue
1194
+ };
1195
+ }
1196
+
1197
+ // src/i3s-loader.ts
1198
+ var VERSION4 = typeof __VERSION__ !== "undefined" ? __VERSION__ : "latest";
1199
+ var TILESET_REGEX = /layers\/[0-9]+$/;
1200
+ var TILE_HEADER_REGEX = /nodes\/([0-9-]+|root)$/;
1201
+ var SLPK_HEX = "504b0304";
1202
+ var POINT_CLOUD = "PointCloud";
1203
+ var I3SLoader = {
1204
+ name: "I3S (Indexed Scene Layers)",
1205
+ id: "i3s",
1206
+ module: "i3s",
1207
+ version: VERSION4,
1208
+ mimeTypes: ["application/octet-stream"],
1209
+ parse: parseI3S,
1210
+ extensions: ["bin"],
1211
+ options: {
1212
+ i3s: {
1213
+ token: null,
1214
+ isTileset: "auto",
1215
+ isTileHeader: "auto",
1216
+ tile: null,
1217
+ tileset: null,
1218
+ _tileOptions: null,
1219
+ _tilesetOptions: null,
1220
+ useDracoGeometry: true,
1221
+ useCompressedTextures: true,
1222
+ decodeTextures: true,
1223
+ coordinateSystem: 2 /* METER_OFFSETS */,
1224
+ colorsByAttribute: null
1225
+ }
1226
+ }
1227
+ };
1228
+ async function parseI3S(data, options = {}, context) {
1229
+ const url = context.url;
1230
+ options.i3s = options.i3s || {};
1231
+ const magicNumber = getMagicNumber(data);
1232
+ if (magicNumber === SLPK_HEX) {
1233
+ throw new Error("Files with .slpk extention currently are not supported by I3SLoader");
1234
+ }
1235
+ let isTileset;
1236
+ if (options.i3s.isTileset === "auto") {
1237
+ isTileset = TILESET_REGEX.test(url);
1238
+ } else {
1239
+ isTileset = options.i3s.isTileset;
1240
+ }
1241
+ let isTileHeader;
1242
+ if (options.isTileHeader === "auto") {
1243
+ isTileHeader = TILE_HEADER_REGEX.test(url);
1244
+ } else {
1245
+ isTileHeader = options.i3s.isTileHeader;
1246
+ }
1247
+ if (isTileset) {
1248
+ data = await parseTileset(data, options, context);
1249
+ } else if (isTileHeader) {
1250
+ data = await parseTile(data, context);
1251
+ } else {
1252
+ data = await parseTileContent(data, options);
1253
+ }
1254
+ return data;
1255
+ }
1256
+ async function parseTileContent(arrayBuffer, options) {
1257
+ return await (0, import_core7.parse)(arrayBuffer, I3SContentLoader, options);
1258
+ }
1259
+ async function parseTileset(data, options, context) {
1260
+ const tilesetJson = JSON.parse(new TextDecoder().decode(data));
1261
+ if ((tilesetJson == null ? void 0 : tilesetJson.layerType) === POINT_CLOUD) {
1262
+ throw new Error("Point Cloud layers currently are not supported by I3SLoader");
1263
+ }
1264
+ const tilesetPostprocessed = await normalizeTilesetData(tilesetJson, options, context);
1265
+ return tilesetPostprocessed;
1266
+ }
1267
+ async function parseTile(data, context) {
1268
+ data = JSON.parse(new TextDecoder().decode(data));
1269
+ return normalizeTileData(data, context);
1270
+ }
1271
+ function getMagicNumber(data) {
1272
+ if (data instanceof ArrayBuffer) {
1273
+ return [...new Uint8Array(data, 0, 4)].map((value) => value.toString(16).padStart(2, "0")).join("");
1274
+ }
1275
+ return null;
1276
+ }
1277
+
1278
+ // src/i3s-slpk-loader.ts
1279
+ var import_loader_utils2 = require("@loaders.gl/loader-utils");
1280
+
1281
+ // src/lib/parsers/parse-slpk/parse-slpk.ts
1282
+ var import_zip2 = require("@loaders.gl/zip");
1283
+
1284
+ // src/lib/parsers/parse-slpk/slpk-archieve.ts
1285
+ var import_crypto = require("@loaders.gl/crypto");
1286
+ var import_zip = require("@loaders.gl/zip");
1287
+ var import_compression = require("@loaders.gl/compression");
1288
+ var PATH_DESCRIPTIONS = [
1289
+ {
1290
+ test: /^$/,
1291
+ extensions: ["3dSceneLayer.json.gz"]
1292
+ },
1293
+ {
1294
+ test: /^nodepages\/\d+$/,
1295
+ extensions: [".json.gz"]
1296
+ },
1297
+ {
1298
+ test: /^nodes\/(\d+|root)$/,
1299
+ extensions: ["/3dNodeIndexDocument.json.gz"]
1300
+ },
1301
+ {
1302
+ test: /^nodes\/\d+\/textures\/.+$/,
1303
+ extensions: [".jpg", ".png", ".bin.dds.gz", ".ktx"]
1304
+ },
1305
+ {
1306
+ test: /^nodes\/\d+\/geometries\/\d+$/,
1307
+ extensions: [".bin.gz", ".draco.gz"]
1308
+ },
1309
+ {
1310
+ test: /^nodes\/\d+\/attributes\/f_\d+\/\d+$/,
1311
+ extensions: [".bin.gz"]
1312
+ },
1313
+ {
1314
+ test: /^statistics\/f_\d+\/\d+$/,
1315
+ extensions: [".json.gz"]
1316
+ },
1317
+ {
1318
+ test: /^nodes\/\d+\/shared$/,
1319
+ extensions: ["/sharedResource.json.gz"]
1320
+ }
1321
+ ];
1322
+ var SLPKArchive = class {
1323
+ constructor(slpkArchive, hashTable) {
1324
+ /** Array of hashes and offsets into archive */
1325
+ // hashToOffsetMap: Record<string, number>;
1326
+ this._textEncoder = new TextEncoder();
1327
+ this._textDecoder = new TextDecoder();
1328
+ this._md5Hash = new import_crypto.MD5Hash();
1329
+ this.slpkArchive = slpkArchive;
1330
+ this.hashTable = hashTable;
1331
+ }
1332
+ /**
1333
+ * Returns file with the given path from slpk archive
1334
+ * @param path - path inside the slpk
1335
+ * @param mode - currently only raw mode supported
1336
+ * @returns buffer with ready to use file
1337
+ */
1338
+ async getFile(path, mode = "raw") {
1339
+ var _a;
1340
+ if (mode === "http") {
1341
+ const extensions = (_a = PATH_DESCRIPTIONS.find((val) => val.test.test(path))) == null ? void 0 : _a.extensions;
1342
+ if (extensions) {
1343
+ let data;
1344
+ for (const ext of extensions) {
1345
+ data = await this.getDataByPath(`${path}${ext}`);
1346
+ if (data) {
1347
+ break;
1348
+ }
1349
+ }
1350
+ if (data) {
1351
+ return data;
1352
+ }
1353
+ }
1354
+ }
1355
+ if (mode === "raw") {
1356
+ const decompressedFile = await this.getDataByPath(`${path}.gz`);
1357
+ if (decompressedFile) {
1358
+ return decompressedFile;
1359
+ }
1360
+ const fileWithoutCompression = await this.getFileBytes(path);
1361
+ if (fileWithoutCompression) {
1362
+ return fileWithoutCompression;
1363
+ }
1364
+ }
1365
+ throw new Error(`No such file in the archive: ${path}`);
1366
+ }
1367
+ /**
1368
+ * returning uncompressed data for paths that ends with .gz and raw data for all other paths
1369
+ * @param path - path inside the archive
1370
+ * @returns buffer with the file data
1371
+ */
1372
+ async getDataByPath(path) {
1373
+ let data = await this.getFileBytes(path.toLocaleLowerCase());
1374
+ if (!data) {
1375
+ data = await this.getFileBytes(path);
1376
+ }
1377
+ if (!data) {
1378
+ return void 0;
1379
+ }
1380
+ if (/\.gz$/.test(path)) {
1381
+ const compression = new import_compression.GZipCompression();
1382
+ const decompressedData = await compression.decompress(data);
1383
+ return decompressedData;
1384
+ }
1385
+ return data;
1386
+ }
1387
+ /**
1388
+ * Trying to get raw file data by address
1389
+ * @param path - path inside the archive
1390
+ * @returns buffer with the raw file data
1391
+ */
1392
+ async getFileBytes(path) {
1393
+ const binaryPath = this._textEncoder.encode(path);
1394
+ const nameHash = await this._md5Hash.hash(binaryPath.buffer, "hex");
1395
+ const offset = this.hashTable[nameHash];
1396
+ if (offset === void 0) {
1397
+ return void 0;
1398
+ }
1399
+ const localFileHeader = await (0, import_zip.parseZipLocalFileHeader)(offset, this.slpkArchive);
1400
+ if (!localFileHeader) {
1401
+ return void 0;
1402
+ }
1403
+ const compressedFile = this.slpkArchive.slice(
1404
+ localFileHeader.fileDataOffset,
1405
+ localFileHeader.fileDataOffset + localFileHeader.compressedSize
1406
+ );
1407
+ return compressedFile;
1408
+ }
1409
+ };
1410
+
1411
+ // src/lib/parsers/parse-slpk/parse-slpk.ts
1412
+ async function parseSLPKArchive(fileProvider, cb) {
1413
+ const hashCDOffset = await (0, import_zip2.searchFromTheEnd)(fileProvider, import_zip2.cdSignature);
1414
+ const cdFileHeader = await (0, import_zip2.parseZipCDFileHeader)(hashCDOffset, fileProvider);
1415
+ let hashTable;
1416
+ if ((cdFileHeader == null ? void 0 : cdFileHeader.fileName) !== "@specialIndexFileHASH128@") {
1417
+ hashTable = await (0, import_zip2.makeHashTableFromZipHeaders)(fileProvider);
1418
+ cb == null ? void 0 : cb(
1419
+ "SLPK doesnt contain hash file, hash info has been composed according to zip archive headers"
1420
+ );
1421
+ } else {
1422
+ const localFileHeader = await (0, import_zip2.parseZipLocalFileHeader)(
1423
+ cdFileHeader.localHeaderOffset,
1424
+ fileProvider
1425
+ );
1426
+ if (!localFileHeader) {
1427
+ throw new Error("corrupted SLPK");
1428
+ }
1429
+ const fileDataOffset = localFileHeader.fileDataOffset;
1430
+ const hashFile = await fileProvider.slice(
1431
+ fileDataOffset,
1432
+ fileDataOffset + localFileHeader.compressedSize
1433
+ );
1434
+ hashTable = (0, import_zip2.parseHashTable)(hashFile);
1435
+ }
1436
+ return new SLPKArchive(fileProvider, hashTable);
1437
+ }
1438
+
1439
+ // src/i3s-slpk-loader.ts
1440
+ var VERSION5 = typeof __VERSION__ !== "undefined" ? __VERSION__ : "latest";
1441
+ var SLPKLoader = {
1442
+ name: "I3S SLPK (Scene Layer Package)",
1443
+ id: "slpk",
1444
+ module: "i3s",
1445
+ version: VERSION5,
1446
+ mimeTypes: ["application/octet-stream"],
1447
+ extensions: ["slpk"],
1448
+ options: {},
1449
+ parse: async (data, options = {}) => {
1450
+ var _a, _b;
1451
+ const archive = await parseSLPKArchive(new import_loader_utils2.DataViewFile(new DataView(data)));
1452
+ return archive.getFile(((_a = options.slpk) == null ? void 0 : _a.path) ?? "", (_b = options.slpk) == null ? void 0 : _b.pathMode);
1453
+ }
1454
+ };
1455
+
1456
+ // src/lib/parsers/parse-i3s-building-scene-layer.ts
1457
+ var OBJECT_3D_LAYER_TYPE = "3DObject";
1458
+ async function parseBuildingSceneLayer(data, url) {
1459
+ const layer0 = JSON.parse(new TextDecoder().decode(data));
1460
+ const { sublayers } = layer0;
1461
+ return {
1462
+ header: layer0,
1463
+ sublayers: parseSublayersTree(sublayers, url)
1464
+ };
1465
+ }
1466
+ function parseSublayersTree(sublayers, url) {
1467
+ var _a;
1468
+ let layers = [];
1469
+ for (let index = 0; index < sublayers.length; index++) {
1470
+ const subLayer = sublayers[index];
1471
+ const { id, layerType, visibility = true, ...rest } = subLayer;
1472
+ if (layerType === OBJECT_3D_LAYER_TYPE) {
1473
+ const sublayerUrl = `${url}/sublayers/${id}`;
1474
+ layers.push({
1475
+ url: sublayerUrl,
1476
+ id,
1477
+ layerType,
1478
+ visibility,
1479
+ ...rest
1480
+ });
1481
+ }
1482
+ if ((_a = subLayer == null ? void 0 : subLayer.sublayers) == null ? void 0 : _a.length) {
1483
+ layers = [...layers, ...parseSublayersTree(subLayer.sublayers, url)];
1484
+ }
1485
+ }
1486
+ return layers;
1487
+ }
1488
+
1489
+ // src/i3s-building-scene-layer-loader.ts
1490
+ var VERSION6 = typeof __VERSION__ !== "undefined" ? __VERSION__ : "beta";
1491
+ var I3SBuildingSceneLayerLoader = {
1492
+ name: "I3S Building Scene Layer",
1493
+ id: "i3s-building-scene-layer",
1494
+ module: "i3s",
1495
+ version: VERSION6,
1496
+ mimeTypes: ["application/json"],
1497
+ parse: parse4,
1498
+ extensions: ["json"],
1499
+ options: {}
1500
+ };
1501
+ async function parse4(data, options, context) {
1502
+ if (!(context == null ? void 0 : context.url)) {
1503
+ throw new Error("Url is not provided");
1504
+ }
1505
+ return parseBuildingSceneLayer(data, context.url);
1506
+ }
1507
+
1508
+ // src/lib/parsers/parse-arcgis-webscene.ts
1509
+ var import_core8 = require("@loaders.gl/core");
1510
+ var SUPPORTED_WKID = 4326;
1511
+ var ARCGIS_SCENE_SERVER_LAYER_TYPE = "ArcGISSceneServiceLayer";
1512
+ var BUILDING_SCENE_LAYER = "BuildingSceneLayer";
1513
+ var INTEGRATED_MESH_LAYER = "IntegratedMeshLayer";
1514
+ var GROUP_LAYER = "GroupLayer";
1515
+ var SUPPORTED_LAYERS_TYPES = [
1516
+ ARCGIS_SCENE_SERVER_LAYER_TYPE,
1517
+ INTEGRATED_MESH_LAYER,
1518
+ BUILDING_SCENE_LAYER,
1519
+ GROUP_LAYER
1520
+ ];
1521
+ var NO_AVAILABLE_SUPPORTED_LAYERS_ERROR = "NO_AVAILABLE_SUPPORTED_LAYERS_ERROR";
1522
+ var NOT_SUPPORTED_CRS_ERROR = "NOT_SUPPORTED_CRS_ERROR";
1523
+ async function parseWebscene(data) {
1524
+ const layer0 = JSON.parse(new TextDecoder().decode(data));
1525
+ const { operationalLayers } = layer0;
1526
+ const { layers, unsupportedLayers } = await parseOperationalLayers(operationalLayers, true);
1527
+ if (!layers.length) {
1528
+ throw new Error(NO_AVAILABLE_SUPPORTED_LAYERS_ERROR);
1529
+ }
1530
+ return {
1531
+ header: layer0,
1532
+ layers,
1533
+ unsupportedLayers
1534
+ };
1535
+ }
1536
+ async function parseOperationalLayers(layersList, needToCheckCRS) {
1537
+ var _a;
1538
+ const layers = [];
1539
+ let unsupportedLayers = [];
1540
+ for (let index = 0; index < layersList.length; index++) {
1541
+ const layer = layersList[index];
1542
+ const isLayerSupported = SUPPORTED_LAYERS_TYPES.includes(layer.layerType);
1543
+ if (isLayerSupported) {
1544
+ if (needToCheckCRS && layer.layerType !== GROUP_LAYER) {
1545
+ await checkSupportedIndexCRS(layer);
1546
+ needToCheckCRS = false;
1547
+ }
1548
+ layers.push(layer);
1549
+ } else {
1550
+ unsupportedLayers.push(layer);
1551
+ }
1552
+ if ((_a = layer.layers) == null ? void 0 : _a.length) {
1553
+ const { layers: childLayers, unsupportedLayers: childUnsupportedLayers } = await parseOperationalLayers(layer.layers, needToCheckCRS);
1554
+ layer.layers = childLayers;
1555
+ unsupportedLayers = [...unsupportedLayers, ...childUnsupportedLayers];
1556
+ }
1557
+ }
1558
+ return { layers, unsupportedLayers };
1559
+ }
1560
+ async function checkSupportedIndexCRS(layer) {
1561
+ var _a;
1562
+ try {
1563
+ const layerJson = await (0, import_core8.load)(layer.url, import_core8.JSONLoader);
1564
+ const wkid = (_a = layerJson == null ? void 0 : layerJson.spatialReference) == null ? void 0 : _a.wkid;
1565
+ if (wkid !== SUPPORTED_WKID) {
1566
+ throw new Error(NOT_SUPPORTED_CRS_ERROR);
1567
+ }
1568
+ } catch (error) {
1569
+ throw error;
1570
+ }
1571
+ }
1572
+
1573
+ // src/arcgis-webscene-loader.ts
1574
+ var VERSION7 = typeof __VERSION__ !== "undefined" ? __VERSION__ : "beta";
1575
+ var ArcGISWebSceneLoader = {
1576
+ name: "ArcGIS Web Scene Loader",
1577
+ id: "arcgis-web-scene",
1578
+ module: "i3s",
1579
+ version: VERSION7,
1580
+ mimeTypes: ["application/json"],
1581
+ parse: parse5,
1582
+ extensions: ["json"],
1583
+ options: {}
1584
+ };
1585
+ async function parse5(data) {
1586
+ return parseWebscene(data);
1587
+ }