@loaders.gl/i3s 4.0.0-alpha.1 → 4.0.0-alpha.11

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 (242) hide show
  1. package/dist/arcgis-webscene-loader.d.ts +7 -0
  2. package/dist/arcgis-webscene-loader.d.ts.map +1 -0
  3. package/dist/arcgis-webscene-loader.js +28 -0
  4. package/dist/bundle.d.ts +2 -0
  5. package/dist/bundle.d.ts.map +1 -0
  6. package/dist/bundle.js +2 -2
  7. package/dist/dist.min.js +15501 -0
  8. package/dist/es5/arcgis-webscene-loader.js +40 -0
  9. package/dist/es5/arcgis-webscene-loader.js.map +1 -0
  10. package/dist/es5/bundle.js +6 -0
  11. package/dist/es5/bundle.js.map +1 -0
  12. package/dist/es5/i3s-attribute-loader.js +195 -0
  13. package/dist/es5/i3s-attribute-loader.js.map +1 -0
  14. package/dist/es5/i3s-building-scene-layer-loader.js +46 -0
  15. package/dist/es5/i3s-building-scene-layer-loader.js.map +1 -0
  16. package/dist/es5/i3s-content-loader.js +56 -0
  17. package/dist/es5/i3s-content-loader.js.map +1 -0
  18. package/dist/es5/i3s-loader.js +193 -0
  19. package/dist/es5/i3s-loader.js.map +1 -0
  20. package/dist/es5/i3s-node-page-loader.js +39 -0
  21. package/dist/es5/i3s-node-page-loader.js.map +1 -0
  22. package/dist/es5/i3s-slpk-loader.js +20 -0
  23. package/dist/es5/i3s-slpk-loader.js.map +1 -0
  24. package/dist/es5/index.js +82 -0
  25. package/dist/es5/index.js.map +1 -0
  26. package/dist/es5/lib/helpers/i3s-nodepages-tiles.js +312 -0
  27. package/dist/es5/lib/helpers/i3s-nodepages-tiles.js.map +1 -0
  28. package/dist/es5/lib/parsers/constants.js +72 -0
  29. package/dist/es5/lib/parsers/constants.js.map +1 -0
  30. package/dist/es5/lib/parsers/parse-arcgis-webscene.js +158 -0
  31. package/dist/es5/lib/parsers/parse-arcgis-webscene.js.map +1 -0
  32. package/dist/es5/lib/parsers/parse-i3s-attribute.js +76 -0
  33. package/dist/es5/lib/parsers/parse-i3s-attribute.js.map +1 -0
  34. package/dist/es5/lib/parsers/parse-i3s-building-scene-layer.js +65 -0
  35. package/dist/es5/lib/parsers/parse-i3s-building-scene-layer.js.map +1 -0
  36. package/dist/es5/lib/parsers/parse-i3s-tile-content.js +510 -0
  37. package/dist/es5/lib/parsers/parse-i3s-tile-content.js.map +1 -0
  38. package/dist/es5/lib/parsers/parse-i3s.js +116 -0
  39. package/dist/es5/lib/parsers/parse-i3s.js.map +1 -0
  40. package/dist/es5/lib/parsers/parse-slpk/parse-slpk.js +107 -0
  41. package/dist/es5/lib/parsers/parse-slpk/parse-slpk.js.map +1 -0
  42. package/dist/es5/lib/parsers/parse-slpk/slpk-archieve.js +258 -0
  43. package/dist/es5/lib/parsers/parse-slpk/slpk-archieve.js.map +1 -0
  44. package/dist/es5/lib/parsers/parse-zip/buffer-file-provider.js +46 -0
  45. package/dist/es5/lib/parsers/parse-zip/buffer-file-provider.js.map +1 -0
  46. package/dist/es5/lib/parsers/parse-zip/cd-file-header.js +84 -0
  47. package/dist/es5/lib/parsers/parse-zip/cd-file-header.js.map +1 -0
  48. package/dist/es5/lib/parsers/parse-zip/file-provider.js +2 -0
  49. package/dist/es5/lib/parsers/parse-zip/file-provider.js.map +1 -0
  50. package/dist/es5/lib/parsers/parse-zip/local-file-header.js +72 -0
  51. package/dist/es5/lib/parsers/parse-zip/local-file-header.js.map +1 -0
  52. package/dist/es5/lib/utils/convert-i3s-obb-to-mbs.js +17 -0
  53. package/dist/es5/lib/utils/convert-i3s-obb-to-mbs.js.map +1 -0
  54. package/dist/es5/lib/utils/customize-/321/201olors.js +184 -0
  55. package/dist/es5/lib/utils/customize-/321/201olors.js.map +1 -0
  56. package/dist/es5/lib/utils/url-utils.js +33 -0
  57. package/dist/es5/lib/utils/url-utils.js.map +1 -0
  58. package/dist/es5/types.js +26 -0
  59. package/dist/es5/types.js.map +1 -0
  60. package/dist/es5/workers/i3s-content-worker-node.js +7 -0
  61. package/dist/es5/workers/i3s-content-worker-node.js.map +1 -0
  62. package/dist/es5/workers/i3s-content-worker.js +6 -0
  63. package/dist/es5/workers/i3s-content-worker.js.map +1 -0
  64. package/dist/esm/arcgis-webscene-loader.js +16 -0
  65. package/dist/esm/arcgis-webscene-loader.js.map +1 -0
  66. package/dist/esm/bundle.js +4 -0
  67. package/dist/esm/bundle.js.map +1 -0
  68. package/dist/esm/i3s-attribute-loader.js +119 -0
  69. package/dist/esm/i3s-attribute-loader.js.map +1 -0
  70. package/dist/esm/i3s-building-scene-layer-loader.js +19 -0
  71. package/dist/esm/i3s-building-scene-layer-loader.js.map +1 -0
  72. package/dist/esm/i3s-content-loader.js +30 -0
  73. package/dist/esm/i3s-content-loader.js.map +1 -0
  74. package/dist/esm/i3s-loader.js +87 -0
  75. package/dist/esm/i3s-loader.js.map +1 -0
  76. package/dist/esm/i3s-node-page-loader.js +15 -0
  77. package/dist/esm/i3s-node-page-loader.js.map +1 -0
  78. package/dist/esm/i3s-slpk-loader.js +13 -0
  79. package/dist/esm/i3s-slpk-loader.js.map +1 -0
  80. package/dist/esm/index.js +11 -0
  81. package/dist/esm/index.js.map +1 -0
  82. package/dist/esm/lib/helpers/i3s-nodepages-tiles.js +198 -0
  83. package/dist/esm/lib/helpers/i3s-nodepages-tiles.js.map +1 -0
  84. package/dist/esm/lib/parsers/constants.js +57 -0
  85. package/dist/esm/lib/parsers/constants.js.map +1 -0
  86. package/dist/esm/lib/parsers/parse-arcgis-webscene.js +70 -0
  87. package/dist/esm/lib/parsers/parse-arcgis-webscene.js.map +1 -0
  88. package/dist/esm/lib/parsers/parse-i3s-attribute.js +60 -0
  89. package/dist/esm/lib/parsers/parse-i3s-attribute.js.map +1 -0
  90. package/dist/esm/lib/parsers/parse-i3s-building-scene-layer.js +39 -0
  91. package/dist/esm/lib/parsers/parse-i3s-building-scene-layer.js.map +1 -0
  92. package/dist/esm/lib/parsers/parse-i3s-tile-content.js +435 -0
  93. package/dist/esm/lib/parsers/parse-i3s-tile-content.js.map +1 -0
  94. package/dist/esm/lib/parsers/parse-i3s.js +83 -0
  95. package/dist/esm/lib/parsers/parse-i3s.js.map +1 -0
  96. package/dist/esm/lib/parsers/parse-slpk/parse-slpk.js +41 -0
  97. package/dist/esm/lib/parsers/parse-slpk/parse-slpk.js.map +1 -0
  98. package/dist/esm/lib/parsers/parse-slpk/slpk-archieve.js +107 -0
  99. package/dist/esm/lib/parsers/parse-slpk/slpk-archieve.js.map +1 -0
  100. package/dist/esm/lib/parsers/parse-zip/buffer-file-provider.js +23 -0
  101. package/dist/esm/lib/parsers/parse-zip/buffer-file-provider.js.map +1 -0
  102. package/dist/esm/lib/parsers/parse-zip/cd-file-header.js +37 -0
  103. package/dist/esm/lib/parsers/parse-zip/cd-file-header.js.map +1 -0
  104. package/dist/esm/lib/parsers/parse-zip/file-provider.js +2 -0
  105. package/dist/esm/lib/parsers/parse-zip/file-provider.js.map +1 -0
  106. package/dist/esm/lib/parsers/parse-zip/local-file-header.js +25 -0
  107. package/dist/esm/lib/parsers/parse-zip/local-file-header.js.map +1 -0
  108. package/dist/esm/lib/utils/convert-i3s-obb-to-mbs.js +9 -0
  109. package/dist/esm/lib/utils/convert-i3s-obb-to-mbs.js.map +1 -0
  110. package/dist/esm/lib/utils/customize-/321/201olors.js +98 -0
  111. package/dist/esm/lib/utils/customize-/321/201olors.js.map +1 -0
  112. package/dist/esm/lib/utils/url-utils.js +28 -0
  113. package/dist/esm/lib/utils/url-utils.js.map +1 -0
  114. package/dist/esm/types.js +18 -0
  115. package/dist/esm/types.js.map +1 -0
  116. package/dist/esm/workers/i3s-content-worker-node.js +5 -0
  117. package/dist/esm/workers/i3s-content-worker-node.js.map +1 -0
  118. package/dist/esm/workers/i3s-content-worker.js +4 -0
  119. package/dist/esm/workers/i3s-content-worker.js.map +1 -0
  120. package/dist/i3s-attribute-loader.d.ts +21 -0
  121. package/dist/i3s-attribute-loader.d.ts.map +1 -0
  122. package/dist/i3s-attribute-loader.js +155 -132
  123. package/dist/i3s-building-scene-layer-loader.d.ts +6 -0
  124. package/dist/i3s-building-scene-layer-loader.d.ts.map +1 -0
  125. package/dist/i3s-building-scene-layer-loader.js +23 -18
  126. package/dist/i3s-content-loader.d.ts +6 -0
  127. package/dist/i3s-content-loader.d.ts.map +1 -0
  128. package/dist/i3s-content-loader.js +29 -22
  129. package/dist/i3s-content-worker-node.js +197 -0
  130. package/dist/i3s-content-worker-node.js.map +7 -0
  131. package/dist/i3s-content-worker.js +2308 -1376
  132. package/dist/i3s-loader.d.ts +11 -0
  133. package/dist/i3s-loader.d.ts.map +1 -0
  134. package/dist/i3s-loader.js +88 -81
  135. package/dist/i3s-node-page-loader.d.ts +7 -0
  136. package/dist/i3s-node-page-loader.d.ts.map +1 -0
  137. package/dist/i3s-node-page-loader.js +20 -20
  138. package/dist/i3s-slpk-loader.d.ts +13 -0
  139. package/dist/i3s-slpk-loader.d.ts.map +1 -0
  140. package/dist/i3s-slpk-loader.js +20 -0
  141. package/dist/index.d.ts +12 -0
  142. package/dist/index.d.ts.map +1 -0
  143. package/dist/index.js +23 -5
  144. package/dist/lib/helpers/i3s-nodepages-tiles.d.ts +74 -0
  145. package/dist/lib/helpers/i3s-nodepages-tiles.d.ts.map +1 -0
  146. package/dist/lib/helpers/i3s-nodepages-tiles.js +232 -219
  147. package/dist/lib/parsers/constants.d.ts +40 -0
  148. package/dist/lib/parsers/constants.d.ts.map +1 -0
  149. package/dist/lib/parsers/constants.js +87 -42
  150. package/dist/lib/parsers/parse-arcgis-webscene.d.ts +7 -0
  151. package/dist/lib/parsers/parse-arcgis-webscene.d.ts.map +1 -0
  152. package/dist/lib/parsers/parse-arcgis-webscene.js +88 -0
  153. package/dist/lib/parsers/parse-i3s-attribute.d.ts +12 -0
  154. package/dist/lib/parsers/parse-i3s-attribute.d.ts.map +1 -0
  155. package/dist/lib/parsers/parse-i3s-attribute.js +87 -62
  156. package/dist/lib/parsers/parse-i3s-building-scene-layer.d.ts +9 -0
  157. package/dist/lib/parsers/parse-i3s-building-scene-layer.d.ts.map +1 -0
  158. package/dist/lib/parsers/parse-i3s-building-scene-layer.js +41 -38
  159. package/dist/lib/parsers/parse-i3s-tile-content.d.ts +4 -0
  160. package/dist/lib/parsers/parse-i3s-tile-content.d.ts.map +1 -0
  161. package/dist/lib/parsers/parse-i3s-tile-content.js +460 -415
  162. package/dist/lib/parsers/parse-i3s.d.ts +6 -0
  163. package/dist/lib/parsers/parse-i3s.d.ts.map +1 -0
  164. package/dist/lib/parsers/parse-i3s.js +92 -73
  165. package/dist/lib/parsers/parse-slpk/parse-slpk.d.ts +4 -0
  166. package/dist/lib/parsers/parse-slpk/parse-slpk.d.ts.map +1 -0
  167. package/dist/lib/parsers/parse-slpk/parse-slpk.js +54 -0
  168. package/dist/lib/parsers/parse-slpk/slpk-archieve.d.ts +38 -0
  169. package/dist/lib/parsers/parse-slpk/slpk-archieve.d.ts.map +1 -0
  170. package/dist/lib/parsers/parse-slpk/slpk-archieve.js +142 -0
  171. package/dist/lib/parsers/parse-zip/buffer-file-provider.d.ts +37 -0
  172. package/dist/lib/parsers/parse-zip/buffer-file-provider.d.ts.map +1 -0
  173. package/dist/lib/parsers/parse-zip/buffer-file-provider.js +47 -0
  174. package/dist/lib/parsers/parse-zip/cd-file-header.d.ts +27 -0
  175. package/dist/lib/parsers/parse-zip/cd-file-header.d.ts.map +1 -0
  176. package/dist/lib/parsers/parse-zip/cd-file-header.js +48 -0
  177. package/dist/lib/parsers/parse-zip/file-provider.d.ts +31 -0
  178. package/dist/lib/parsers/parse-zip/file-provider.d.ts.map +1 -0
  179. package/dist/lib/parsers/parse-zip/file-provider.js +2 -0
  180. package/dist/lib/parsers/parse-zip/local-file-header.d.ts +25 -0
  181. package/dist/lib/parsers/parse-zip/local-file-header.d.ts.map +1 -0
  182. package/dist/lib/parsers/parse-zip/local-file-header.js +34 -0
  183. package/dist/lib/utils/convert-i3s-obb-to-mbs.d.ts +2 -0
  184. package/dist/lib/utils/convert-i3s-obb-to-mbs.d.ts.map +1 -0
  185. package/dist/lib/utils/convert-i3s-obb-to-mbs.js +19 -8
  186. package/dist/lib/utils/customize-/321/201olors.d.ts +14 -0
  187. package/dist/lib/utils/customize-/321/201olors.d.ts.map +1 -0
  188. package/dist/lib/utils/customize-/321/201olors.js +104 -0
  189. package/dist/lib/utils/url-utils.d.ts +22 -0
  190. package/dist/lib/utils/url-utils.d.ts.map +1 -0
  191. package/dist/lib/utils/url-utils.js +41 -29
  192. package/dist/types.d.ts +1065 -0
  193. package/dist/types.d.ts.map +1 -0
  194. package/dist/types.js +20 -2
  195. package/dist/workers/i3s-content-worker-node.d.ts +2 -0
  196. package/dist/workers/i3s-content-worker-node.d.ts.map +1 -0
  197. package/dist/workers/i3s-content-worker-node.js +7 -0
  198. package/dist/workers/i3s-content-worker.d.ts +2 -0
  199. package/dist/workers/i3s-content-worker.d.ts.map +1 -0
  200. package/dist/workers/i3s-content-worker.js +5 -4
  201. package/package.json +18 -16
  202. package/src/arcgis-webscene-loader.ts +31 -0
  203. package/src/i3s-attribute-loader.ts +9 -9
  204. package/src/i3s-content-loader.ts +17 -5
  205. package/src/i3s-loader.ts +24 -13
  206. package/src/i3s-node-page-loader.ts +6 -10
  207. package/src/i3s-slpk-loader.ts +27 -0
  208. package/src/index.ts +28 -7
  209. package/src/lib/helpers/i3s-nodepages-tiles.ts +84 -57
  210. package/src/lib/parsers/constants.ts +71 -37
  211. package/src/lib/parsers/parse-arcgis-webscene.ts +102 -0
  212. package/src/lib/parsers/parse-i3s-attribute.ts +21 -14
  213. package/src/lib/parsers/parse-i3s-building-scene-layer.ts +2 -1
  214. package/src/lib/parsers/parse-i3s-tile-content.ts +278 -194
  215. package/src/lib/parsers/parse-i3s.ts +55 -39
  216. package/src/lib/parsers/parse-slpk/parse-slpk.ts +72 -0
  217. package/src/lib/parsers/parse-slpk/slpk-archieve.ts +173 -0
  218. package/src/lib/parsers/parse-zip/buffer-file-provider.ts +55 -0
  219. package/src/lib/parsers/parse-zip/cd-file-header.ts +86 -0
  220. package/src/lib/parsers/parse-zip/file-provider.ts +34 -0
  221. package/src/lib/parsers/parse-zip/local-file-header.ts +65 -0
  222. package/src/lib/utils/customize-/321/201olors.ts +144 -0
  223. package/src/lib/utils/url-utils.ts +7 -7
  224. package/src/types.ts +875 -86
  225. package/src/workers/i3s-content-worker-node.ts +6 -0
  226. package/dist/bundle.js.map +0 -1
  227. package/dist/i3s-attribute-loader.js.map +0 -1
  228. package/dist/i3s-building-scene-layer-loader.js.map +0 -1
  229. package/dist/i3s-content-loader.js.map +0 -1
  230. package/dist/i3s-loader.js.map +0 -1
  231. package/dist/i3s-node-page-loader.js.map +0 -1
  232. package/dist/index.js.map +0 -1
  233. package/dist/lib/helpers/i3s-nodepages-tiles.js.map +0 -1
  234. package/dist/lib/parsers/constants.js.map +0 -1
  235. package/dist/lib/parsers/parse-i3s-attribute.js.map +0 -1
  236. package/dist/lib/parsers/parse-i3s-building-scene-layer.js.map +0 -1
  237. package/dist/lib/parsers/parse-i3s-tile-content.js.map +0 -1
  238. package/dist/lib/parsers/parse-i3s.js.map +0 -1
  239. package/dist/lib/utils/convert-i3s-obb-to-mbs.js.map +0 -1
  240. package/dist/lib/utils/url-utils.js.map +0 -1
  241. package/dist/types.js.map +0 -1
  242. package/dist/workers/i3s-content-worker.js.map +0 -1
@@ -1,454 +1,499 @@
1
- import { load, parse } from '@loaders.gl/core';
2
- import { Matrix4 } from '@math.gl/core';
3
- import { ImageLoader } from '@loaders.gl/images';
4
- import { DracoLoader } from '@loaders.gl/draco';
5
- import { BasisLoader, CompressedTextureLoader } from '@loaders.gl/textures';
6
- import { getUrlWithToken } from '../utils/url-utils';
7
- import { GL_TYPE_MAP, TYPE_ARRAY_MAP, SIZEOF, I3S_NAMED_HEADER_ATTRIBUTES, I3S_NAMED_VERTEX_ATTRIBUTES, I3S_NAMED_GEOMETRY_ATTRIBUTES } from './constants';
8
- const COORDINATE_SYSTEM_LNGLAT_OFFSETS = 3;
9
- const FORMAT_LOADER_MAP = {
10
- jpeg: ImageLoader,
11
- png: ImageLoader,
12
- 'ktx-etc2': CompressedTextureLoader,
13
- dds: CompressedTextureLoader,
14
- ktx2: BasisLoader
15
- };
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.parseI3STileContent = void 0;
4
+ const core_1 = require("@loaders.gl/core");
5
+ const core_2 = require("@math.gl/core");
6
+ const geospatial_1 = require("@math.gl/geospatial");
7
+ const images_1 = require("@loaders.gl/images");
8
+ const draco_1 = require("@loaders.gl/draco");
9
+ const textures_1 = require("@loaders.gl/textures");
10
+ const types_1 = require("../../types");
11
+ const url_utils_1 = require("../utils/url-utils");
12
+ const constants_1 = require("./constants");
13
+ const customize__olors_1 = require("../utils/customize-\u0441olors");
14
+ const scratchVector = new core_2.Vector3([0, 0, 0]);
15
+ function getLoaderForTextureFormat(textureFormat) {
16
+ switch (textureFormat) {
17
+ case 'ktx-etc2':
18
+ case 'dds':
19
+ return textures_1.CompressedTextureLoader;
20
+ case 'ktx2':
21
+ return textures_1.BasisLoader;
22
+ case 'jpg':
23
+ case 'png':
24
+ default:
25
+ return images_1.ImageLoader;
26
+ }
27
+ }
16
28
  const I3S_ATTRIBUTE_TYPE = 'i3s-attribute-type';
17
- export async function parseI3STileContent(arrayBuffer, tile, tileset, options, context) {
18
- tile.content = tile.content || {};
19
- tile.content.featureIds = tile.content.featureIds || null;
20
- tile.content.featureData = constructFeatureDataStruct(tile, tileset);
21
- tile.content.attributes = {};
22
-
23
- if (tile.textureUrl) {
24
- var _options$i3s;
25
-
26
- const url = getUrlWithToken(tile.textureUrl, options === null || options === void 0 ? void 0 : (_options$i3s = options.i3s) === null || _options$i3s === void 0 ? void 0 : _options$i3s.token);
27
- const loader = FORMAT_LOADER_MAP[tile.textureFormat] || ImageLoader;
28
- const response = await fetch(url);
29
- const arrayBuffer = await response.arrayBuffer();
30
-
31
- if (options !== null && options !== void 0 && options.i3s.decodeTextures) {
32
- if (loader === ImageLoader) {
33
- const options = { ...tile.textureLoaderOptions,
34
- image: {
35
- type: 'data'
36
- }
37
- };
38
- tile.content.texture = await context.parse(arrayBuffer, options);
39
- } else if (loader === CompressedTextureLoader || loader === BasisLoader) {
40
- const texture = await load(arrayBuffer, loader, tile.textureLoaderOptions);
41
- tile.content.texture = {
42
- compressed: true,
43
- mipmaps: false,
44
- width: texture[0].width,
45
- height: texture[0].height,
46
- data: texture
47
- };
48
- }
49
- } else {
50
- tile.content.texture = arrayBuffer;
29
+ async function parseI3STileContent(arrayBuffer, tileOptions, tilesetOptions, options, context) {
30
+ const content = {
31
+ attributes: {},
32
+ indices: null,
33
+ featureIds: [],
34
+ vertexCount: 0,
35
+ modelMatrix: new core_2.Matrix4(),
36
+ coordinateSystem: 0,
37
+ byteLength: 0,
38
+ texture: null
39
+ };
40
+ if (tileOptions.textureUrl) {
41
+ // @ts-expect-error options is not properly typed
42
+ const url = (0, url_utils_1.getUrlWithToken)(tileOptions.textureUrl, options?.i3s?.token);
43
+ const loader = getLoaderForTextureFormat(tileOptions.textureFormat);
44
+ const response = await fetch(url, options?.fetch);
45
+ const arrayBuffer = await response.arrayBuffer();
46
+ // @ts-expect-error options is not properly typed
47
+ if (options?.i3s.decodeTextures) {
48
+ if (loader === images_1.ImageLoader) {
49
+ const options = { ...tileOptions.textureLoaderOptions, image: { type: 'data' } };
50
+ try {
51
+ // @ts-ignore context must be defined
52
+ // Image constructor is not supported in worker thread.
53
+ // Do parsing image data on the main thread by using context to avoid worker issues.
54
+ content.texture = await context.parse(arrayBuffer, options);
55
+ }
56
+ catch (e) {
57
+ // context object is different between worker and node.js conversion script.
58
+ // To prevent error we parse data in ordinary way if it is not parsed by using context.
59
+ // @ts-expect-error
60
+ content.texture = await (0, core_1.parse)(arrayBuffer, loader, options);
61
+ }
62
+ }
63
+ else if (loader === textures_1.CompressedTextureLoader || loader === textures_1.BasisLoader) {
64
+ let texture = await (0, core_1.load)(arrayBuffer, loader, tileOptions.textureLoaderOptions);
65
+ if (loader === textures_1.BasisLoader) {
66
+ // @ts-expect-error
67
+ texture = texture[0];
68
+ }
69
+ content.texture = {
70
+ compressed: true,
71
+ mipmaps: false,
72
+ // @ts-expect-error
73
+ width: texture[0].width,
74
+ // @ts-expect-error
75
+ height: texture[0].height,
76
+ // @ts-expect-error
77
+ data: texture
78
+ };
79
+ }
80
+ }
81
+ else {
82
+ content.texture = arrayBuffer;
83
+ }
51
84
  }
52
- }
53
-
54
- tile.content.material = makePbrMaterial(tile.materialDefinition, tile.content.texture);
55
-
56
- if (tile.content.material) {
57
- tile.content.texture = null;
58
- }
59
-
60
- return await parseI3SNodeGeometry(arrayBuffer, tile, context);
85
+ content.material = makePbrMaterial(tileOptions.materialDefinition, content.texture);
86
+ if (content.material) {
87
+ content.texture = null;
88
+ }
89
+ return await parseI3SNodeGeometry(arrayBuffer, content, tileOptions, tilesetOptions, options);
61
90
  }
62
-
63
- async function parseI3SNodeGeometry(arrayBuffer, tile = {}, context) {
64
- if (!tile.content) {
65
- return tile;
66
- }
67
-
68
- const content = tile.content;
69
- let attributes;
70
- let vertexCount;
71
- let byteOffset = 0;
72
- let featureCount = 0;
73
-
74
- if (tile.isDracoGeometry) {
75
- const decompressedGeometry = await parse(arrayBuffer, DracoLoader, {
76
- draco: {
77
- attributeNameEntry: I3S_ATTRIBUTE_TYPE
78
- }
79
- });
80
- vertexCount = decompressedGeometry.header.vertexCount;
81
- const indices = decompressedGeometry.indices.value;
82
- const {
83
- POSITION,
84
- NORMAL,
85
- COLOR_0,
86
- TEXCOORD_0,
87
- ['feature-index']: featureIndex,
88
- ['uv-region']: uvRegion
89
- } = decompressedGeometry.attributes;
90
- attributes = {
91
- position: POSITION,
92
- normal: NORMAL,
93
- color: COLOR_0,
94
- uv0: TEXCOORD_0,
95
- uvRegion,
96
- id: featureIndex,
97
- indices
91
+ exports.parseI3STileContent = parseI3STileContent;
92
+ /* eslint-disable max-statements */
93
+ async function parseI3SNodeGeometry(arrayBuffer, content, tileOptions, tilesetOptions, options) {
94
+ const contentByteLength = arrayBuffer.byteLength;
95
+ let attributes;
96
+ let vertexCount;
97
+ let byteOffset = 0;
98
+ let featureCount = 0;
99
+ let indices;
100
+ if (tileOptions.isDracoGeometry) {
101
+ const decompressedGeometry = await (0, core_1.parse)(arrayBuffer, draco_1.DracoLoader, {
102
+ draco: {
103
+ attributeNameEntry: I3S_ATTRIBUTE_TYPE
104
+ }
105
+ });
106
+ // @ts-expect-error
107
+ vertexCount = decompressedGeometry.header.vertexCount;
108
+ indices = decompressedGeometry.indices?.value;
109
+ const { POSITION, NORMAL, COLOR_0, TEXCOORD_0, ['feature-index']: featureIndex, ['uv-region']: uvRegion } = decompressedGeometry.attributes;
110
+ attributes = {
111
+ position: POSITION,
112
+ normal: NORMAL,
113
+ color: COLOR_0,
114
+ uv0: TEXCOORD_0,
115
+ uvRegion,
116
+ id: featureIndex
117
+ };
118
+ updateAttributesMetadata(attributes, decompressedGeometry);
119
+ const featureIds = getFeatureIdsFromFeatureIndexMetadata(featureIndex);
120
+ if (featureIds) {
121
+ flattenFeatureIdsByFeatureIndices(attributes, featureIds);
122
+ }
123
+ }
124
+ else {
125
+ const { vertexAttributes, ordering: attributesOrder, featureAttributes, featureAttributeOrder } = tilesetOptions.store.defaultGeometrySchema;
126
+ // First 8 bytes reserved for header (vertexCount and featureCount)
127
+ const headers = parseHeaders(arrayBuffer, tilesetOptions);
128
+ byteOffset = headers.byteOffset;
129
+ vertexCount = headers.vertexCount;
130
+ featureCount = headers.featureCount;
131
+ // Getting vertex attributes such as positions, normals, colors, etc...
132
+ const { attributes: normalizedVertexAttributes, byteOffset: offset } = normalizeAttributes(arrayBuffer, byteOffset, vertexAttributes, vertexCount, attributesOrder);
133
+ // Getting feature attributes such as featureIds and faceRange
134
+ const { attributes: normalizedFeatureAttributes } = normalizeAttributes(arrayBuffer, offset, featureAttributes, featureCount, featureAttributeOrder);
135
+ flattenFeatureIdsByFaceRanges(normalizedFeatureAttributes);
136
+ attributes = concatAttributes(normalizedVertexAttributes, normalizedFeatureAttributes);
137
+ }
138
+ if (!options?.i3s?.coordinateSystem ||
139
+ options.i3s.coordinateSystem === constants_1.COORDINATE_SYSTEM.METER_OFFSETS) {
140
+ const enuMatrix = parsePositions(attributes.position, tileOptions);
141
+ content.modelMatrix = enuMatrix.invert();
142
+ content.coordinateSystem = constants_1.COORDINATE_SYSTEM.METER_OFFSETS;
143
+ }
144
+ else {
145
+ content.modelMatrix = getModelMatrix(attributes.position);
146
+ content.coordinateSystem = constants_1.COORDINATE_SYSTEM.LNGLAT_OFFSETS;
147
+ }
148
+ attributes.color = await (0, customize__olors_1.customizeColors)(attributes.color, attributes.id, tileOptions, tilesetOptions, options);
149
+ content.attributes = {
150
+ positions: attributes.position,
151
+ normals: attributes.normal,
152
+ colors: normalizeAttribute(attributes.color),
153
+ texCoords: attributes.uv0,
154
+ uvRegions: normalizeAttribute(attributes.uvRegion || attributes.region) // Normalize from UInt16
98
155
  };
99
- updateAttributesMetadata(attributes, decompressedGeometry);
100
- const featureIds = getFeatureIdsFromFeatureIndexMetadata(featureIndex);
101
-
102
- if (featureIds) {
103
- flattenFeatureIdsByFeatureIndices(attributes, featureIds);
156
+ content.indices = indices || null;
157
+ if (attributes.id && attributes.id.value) {
158
+ content.featureIds = attributes.id.value;
104
159
  }
105
- } else {
106
- const {
107
- vertexAttributes,
108
- attributesOrder,
109
- featureAttributes,
110
- featureAttributeOrder
111
- } = content.featureData;
112
- const headers = parseHeaders(content, arrayBuffer);
113
- byteOffset = headers.byteOffset;
114
- vertexCount = headers.vertexCount;
115
- featureCount = headers.featureCount;
116
- const {
117
- attributes: normalizedVertexAttributes,
118
- byteOffset: offset
119
- } = normalizeAttributes(arrayBuffer, byteOffset, vertexAttributes, vertexCount, attributesOrder);
120
- const {
121
- attributes: normalizedFeatureAttributes
122
- } = normalizeAttributes(arrayBuffer, offset, featureAttributes, featureCount, featureAttributeOrder);
123
- flattenFeatureIdsByFaceRanges(normalizedFeatureAttributes);
124
- attributes = concatAttributes(normalizedVertexAttributes, normalizedFeatureAttributes);
125
- }
126
-
127
- content.attributes = {
128
- positions: attributes.position,
129
- normals: attributes.normal,
130
- colors: normalizeAttribute(attributes.color),
131
- texCoords: attributes.uv0,
132
- uvRegions: normalizeAttribute(attributes.uvRegion)
133
- };
134
- content.indices = attributes.indices || null;
135
-
136
- if (attributes.id && attributes.id.value) {
137
- tile.content.featureIds = attributes.id.value;
138
- }
139
-
140
- for (const attributeIndex in content.attributes) {
141
- if (!content.attributes[attributeIndex]) {
142
- delete content.attributes[attributeIndex];
160
+ // Remove undefined attributes
161
+ for (const attributeIndex in content.attributes) {
162
+ if (!content.attributes[attributeIndex]) {
163
+ delete content.attributes[attributeIndex];
164
+ }
143
165
  }
144
- }
145
-
146
- content.vertexCount = vertexCount;
147
- content.modelMatrix = getModelMatrix(attributes.position);
148
- content.coordinateSystem = COORDINATE_SYSTEM_LNGLAT_OFFSETS;
149
- content.byteLength = arrayBuffer.byteLength;
150
- return tile;
166
+ content.vertexCount = vertexCount;
167
+ content.byteLength = contentByteLength;
168
+ return content;
151
169
  }
152
-
170
+ /**
171
+ * Update attributes with metadata from decompressed geometry.
172
+ * @param decompressedGeometry
173
+ * @param attributes
174
+ */
153
175
  function updateAttributesMetadata(attributes, decompressedGeometry) {
154
- for (const key in decompressedGeometry.loaderData.attributes) {
155
- const dracoAttribute = decompressedGeometry.loaderData.attributes[key];
156
-
157
- switch (dracoAttribute.name) {
158
- case 'POSITION':
159
- attributes.position.metadata = dracoAttribute.metadata;
160
- break;
161
-
162
- case 'feature-index':
163
- attributes.id.metadata = dracoAttribute.metadata;
164
- break;
165
-
166
- default:
167
- break;
176
+ for (const key in decompressedGeometry.loaderData.attributes) {
177
+ const dracoAttribute = decompressedGeometry.loaderData.attributes[key];
178
+ switch (dracoAttribute.name) {
179
+ case 'POSITION':
180
+ attributes.position.metadata = dracoAttribute.metadata;
181
+ break;
182
+ case 'feature-index':
183
+ attributes.id.metadata = dracoAttribute.metadata;
184
+ break;
185
+ default:
186
+ break;
187
+ }
168
188
  }
169
- }
170
189
  }
171
-
190
+ /**
191
+ * Do concatenation of attribute objects.
192
+ * Done as separate fucntion to avoid ts errors.
193
+ * @param normalizedVertexAttributes
194
+ * @param normalizedFeatureAttributes
195
+ * @returns - result of attributes concatenation.
196
+ */
172
197
  function concatAttributes(normalizedVertexAttributes, normalizedFeatureAttributes) {
173
- return { ...normalizedVertexAttributes,
174
- ...normalizedFeatureAttributes
175
- };
198
+ return { ...normalizedVertexAttributes, ...normalizedFeatureAttributes };
176
199
  }
177
-
200
+ /**
201
+ * Normalize attribute to range [0..1] . Eg. convert colors buffer from [255,255,255,255] to [1,1,1,1]
202
+ * @param attribute - geometry attribute
203
+ * @returns - geometry attribute in right format
204
+ */
178
205
  function normalizeAttribute(attribute) {
179
- if (!attribute) {
206
+ if (!attribute) {
207
+ return attribute;
208
+ }
209
+ attribute.normalized = true;
180
210
  return attribute;
181
- }
182
-
183
- attribute.normalized = true;
184
- return attribute;
185
211
  }
186
-
187
- function constructFeatureDataStruct(tile, tileset) {
188
- const defaultGeometrySchema = tileset.store.defaultGeometrySchema;
189
- const featureData = defaultGeometrySchema;
190
-
191
- for (const geometryAttribute in I3S_NAMED_GEOMETRY_ATTRIBUTES) {
192
- for (const namedAttribute in I3S_NAMED_VERTEX_ATTRIBUTES) {
193
- const attribute = defaultGeometrySchema[geometryAttribute][namedAttribute];
194
-
195
- if (attribute) {
196
- const {
197
- byteOffset = 0,
198
- count = 0,
199
- valueType,
200
- valuesPerElement
201
- } = attribute;
202
- featureData[geometryAttribute][namedAttribute] = {
203
- valueType,
204
- valuesPerElement,
205
- byteOffset,
206
- count
207
- };
208
- }
212
+ function parseHeaders(arrayBuffer, options) {
213
+ let byteOffset = 0;
214
+ // First 8 bytes reserved for header (vertexCount and featurecount)
215
+ let vertexCount = 0;
216
+ let featureCount = 0;
217
+ for (const { property, type } of options.store.defaultGeometrySchema.header) {
218
+ const TypedArrayTypeHeader = (0, constants_1.getConstructorForDataFormat)(type);
219
+ switch (property) {
220
+ case types_1.HeaderAttributeProperty.vertexCount:
221
+ vertexCount = new TypedArrayTypeHeader(arrayBuffer, 0, 4)[0];
222
+ byteOffset += (0, constants_1.sizeOf)(type);
223
+ break;
224
+ case types_1.HeaderAttributeProperty.featureCount:
225
+ featureCount = new TypedArrayTypeHeader(arrayBuffer, 4, 4)[0];
226
+ byteOffset += (0, constants_1.sizeOf)(type);
227
+ break;
228
+ default:
229
+ break;
230
+ }
209
231
  }
210
- }
211
-
212
- featureData.attributesOrder = defaultGeometrySchema.ordering;
213
- return featureData;
232
+ return {
233
+ vertexCount,
234
+ featureCount,
235
+ byteOffset
236
+ };
214
237
  }
215
-
216
- function parseHeaders(content, buffer) {
217
- let byteOffset = 0;
218
- let vertexCount = 0;
219
- let featureCount = 0;
220
- const headers = content.featureData[I3S_NAMED_HEADER_ATTRIBUTES.header];
221
-
222
- for (const header in headers) {
223
- const {
224
- property,
225
- type
226
- } = headers[header];
227
- const TypedArrayTypeHeader = TYPE_ARRAY_MAP[type];
228
-
229
- if (property === I3S_NAMED_HEADER_ATTRIBUTES.vertexCount) {
230
- vertexCount = new TypedArrayTypeHeader(buffer, 0, 4)[0];
231
- byteOffset += SIZEOF[type];
238
+ /* eslint-enable max-statements */
239
+ function normalizeAttributes(arrayBuffer, byteOffset, vertexAttributes, attributeCount, attributesOrder) {
240
+ const attributes = {};
241
+ // the order of attributes depend on the order being added to the vertexAttributes object
242
+ for (const attribute of attributesOrder) {
243
+ if (vertexAttributes[attribute]) {
244
+ const { valueType, valuesPerElement } = vertexAttributes[attribute];
245
+ // protect from arrayBuffer read overunns by NOT assuming node has regions always even though its declared in defaultGeometrySchema.
246
+ // In i3s 1.6: client is required to decide that based on ./shared resource of the node (materialDefinitions.[Mat_id].params.vertexRegions == true)
247
+ // In i3s 1.7 the property has been rolled into the 3d scene layer json/node pages.
248
+ // Code below does not account when the bytelength is actually bigger than
249
+ // the calculated value (b\c the tile potentially could have mesh segmentation information).
250
+ // In those cases tiles without regions could fail or have garbage values.
251
+ if (byteOffset + attributeCount * valuesPerElement * (0, constants_1.sizeOf)(valueType) <=
252
+ arrayBuffer.byteLength) {
253
+ const buffer = arrayBuffer.slice(byteOffset);
254
+ let value;
255
+ if (valueType === 'UInt64') {
256
+ value = parseUint64Values(buffer, attributeCount * valuesPerElement, (0, constants_1.sizeOf)(valueType));
257
+ }
258
+ else {
259
+ const TypedArrayType = (0, constants_1.getConstructorForDataFormat)(valueType);
260
+ value = new TypedArrayType(buffer, 0, attributeCount * valuesPerElement);
261
+ }
262
+ attributes[attribute] = {
263
+ value,
264
+ type: constants_1.GL_TYPE_MAP[valueType],
265
+ size: valuesPerElement
266
+ };
267
+ switch (attribute) {
268
+ case 'color':
269
+ attributes.color.normalized = true;
270
+ break;
271
+ case 'position':
272
+ case 'region':
273
+ case 'normal':
274
+ default:
275
+ }
276
+ byteOffset = byteOffset + attributeCount * valuesPerElement * (0, constants_1.sizeOf)(valueType);
277
+ }
278
+ else if (attribute !== 'uv0') {
279
+ break;
280
+ }
281
+ }
232
282
  }
233
-
234
- if (property === I3S_NAMED_HEADER_ATTRIBUTES.featureCount) {
235
- featureCount = new TypedArrayTypeHeader(buffer, 4, 4)[0];
236
- byteOffset += SIZEOF[type];
237
- }
238
- }
239
-
240
- return {
241
- vertexCount,
242
- featureCount,
243
- byteOffset
244
- };
283
+ return { attributes, byteOffset };
245
284
  }
246
-
247
- function normalizeAttributes(arrayBuffer, byteOffset, vertexAttributes, vertexCount, attributesOrder) {
248
- const attributes = {};
249
-
250
- for (const attribute of attributesOrder) {
251
- if (vertexAttributes[attribute]) {
252
- const {
253
- valueType,
254
- valuesPerElement
255
- } = vertexAttributes[attribute];
256
- const count = vertexCount;
257
-
258
- if (byteOffset + count * valuesPerElement > arrayBuffer.byteLength) {
259
- break;
260
- }
261
-
262
- const buffer = arrayBuffer.slice(byteOffset);
263
- let value = [];
264
-
265
- if (valueType === 'UInt64') {
266
- value = parseUint64Values(buffer, count * valuesPerElement, SIZEOF[valueType]);
267
- } else {
268
- const TypedArrayType = TYPE_ARRAY_MAP[valueType];
269
- value = new TypedArrayType(buffer, 0, count * valuesPerElement);
270
- }
271
-
272
- attributes[attribute] = {
273
- value,
274
- type: GL_TYPE_MAP[valueType],
275
- size: valuesPerElement
276
- };
277
-
278
- switch (attribute) {
279
- case 'color':
280
- attributes.color.normalized = true;
281
- break;
282
-
283
- case 'position':
284
- case 'region':
285
- case 'normal':
286
- default:
287
- }
288
-
289
- byteOffset = byteOffset + count * valuesPerElement * SIZEOF[valueType];
285
+ /**
286
+ * Parse buffer to return array of uint64 values
287
+ *
288
+ * @param buffer
289
+ * @param elementsCount
290
+ * @returns 64-bit array of values until precision is lost after Number.MAX_SAFE_INTEGER
291
+ */
292
+ function parseUint64Values(buffer, elementsCount, attributeSize) {
293
+ const values = [];
294
+ const dataView = new DataView(buffer);
295
+ let offset = 0;
296
+ for (let index = 0; index < elementsCount; index++) {
297
+ // split 64-bit number into two 32-bit parts
298
+ const left = dataView.getUint32(offset, true);
299
+ const right = dataView.getUint32(offset + 4, true);
300
+ // combine the two 32-bit values
301
+ const value = left + 2 ** 32 * right;
302
+ values.push(value);
303
+ offset += attributeSize;
290
304
  }
291
- }
292
-
293
- return {
294
- attributes,
295
- byteOffset
296
- };
305
+ return new Uint32Array(values);
297
306
  }
298
-
299
- function parseUint64Values(buffer, elementsCount, attributeSize) {
300
- const values = [];
301
- const dataView = new DataView(buffer);
302
- let offset = 0;
303
-
304
- for (let index = 0; index < elementsCount; index++) {
305
- const left = dataView.getUint32(offset, true);
306
- const right = dataView.getUint32(offset + 4, true);
307
- const value = left + 2 ** 32 * right;
308
- values.push(value);
309
- offset += attributeSize;
310
- }
311
-
312
- return values;
307
+ function parsePositions(attribute, options) {
308
+ const mbs = options.mbs;
309
+ const value = attribute.value;
310
+ const metadata = attribute.metadata;
311
+ const enuMatrix = new core_2.Matrix4();
312
+ const cartographicOrigin = new core_2.Vector3(mbs[0], mbs[1], mbs[2]);
313
+ const cartesianOrigin = new core_2.Vector3();
314
+ geospatial_1.Ellipsoid.WGS84.cartographicToCartesian(cartographicOrigin, cartesianOrigin);
315
+ geospatial_1.Ellipsoid.WGS84.eastNorthUpToFixedFrame(cartesianOrigin, enuMatrix);
316
+ attribute.value = offsetsToCartesians(value, metadata, cartographicOrigin);
317
+ return enuMatrix;
313
318
  }
314
-
319
+ /**
320
+ * Converts position coordinates to absolute cartesian coordinates
321
+ * @param vertices - "position" attribute data
322
+ * @param metadata - When the geometry is DRACO compressed, contain position attribute's metadata
323
+ * https://github.com/Esri/i3s-spec/blob/master/docs/1.7/compressedAttributes.cmn.md
324
+ * @param cartographicOrigin - Cartographic origin coordinates
325
+ * @returns - converted "position" data
326
+ */
327
+ function offsetsToCartesians(vertices, metadata = {}, cartographicOrigin) {
328
+ const positions = new Float64Array(vertices.length);
329
+ const scaleX = (metadata['i3s-scale_x'] && metadata['i3s-scale_x'].double) || 1;
330
+ const scaleY = (metadata['i3s-scale_y'] && metadata['i3s-scale_y'].double) || 1;
331
+ for (let i = 0; i < positions.length; i += 3) {
332
+ positions[i] = vertices[i] * scaleX + cartographicOrigin.x;
333
+ positions[i + 1] = vertices[i + 1] * scaleY + cartographicOrigin.y;
334
+ positions[i + 2] = vertices[i + 2] + cartographicOrigin.z;
335
+ }
336
+ for (let i = 0; i < positions.length; i += 3) {
337
+ // @ts-ignore
338
+ geospatial_1.Ellipsoid.WGS84.cartographicToCartesian(positions.subarray(i, i + 3), scratchVector);
339
+ positions[i] = scratchVector.x;
340
+ positions[i + 1] = scratchVector.y;
341
+ positions[i + 2] = scratchVector.z;
342
+ }
343
+ return positions;
344
+ }
345
+ /**
346
+ * Get model matrix for loaded vertices
347
+ * @param positions positions attribute
348
+ * @returns Matrix4 - model matrix for geometry transformation
349
+ */
315
350
  function getModelMatrix(positions) {
316
- var _metadata$i3sScale_x, _metadata$i3sScale_y;
317
-
318
- const metadata = positions.metadata;
319
- const scaleX = (metadata === null || metadata === void 0 ? void 0 : (_metadata$i3sScale_x = metadata['i3s-scale_x']) === null || _metadata$i3sScale_x === void 0 ? void 0 : _metadata$i3sScale_x.double) || 1;
320
- const scaleY = (metadata === null || metadata === void 0 ? void 0 : (_metadata$i3sScale_y = metadata['i3s-scale_y']) === null || _metadata$i3sScale_y === void 0 ? void 0 : _metadata$i3sScale_y.double) || 1;
321
- const modelMatrix = new Matrix4();
322
- modelMatrix[0] = scaleX;
323
- modelMatrix[5] = scaleY;
324
- return modelMatrix;
351
+ const metadata = positions.metadata;
352
+ const scaleX = metadata?.['i3s-scale_x']?.double || 1;
353
+ const scaleY = metadata?.['i3s-scale_y']?.double || 1;
354
+ const modelMatrix = new core_2.Matrix4();
355
+ modelMatrix[0] = scaleX;
356
+ modelMatrix[5] = scaleY;
357
+ return modelMatrix;
325
358
  }
326
-
359
+ /**
360
+ * Makes a glTF-compatible PBR material from an I3S material definition
361
+ * @param materialDefinition - i3s material definition
362
+ * https://github.com/Esri/i3s-spec/blob/master/docs/1.7/materialDefinitions.cmn.md
363
+ * @param texture - texture image
364
+ * @returns {object}
365
+ */
327
366
  function makePbrMaterial(materialDefinition, texture) {
328
- let pbrMaterial;
329
-
330
- if (materialDefinition) {
331
- pbrMaterial = { ...materialDefinition,
332
- pbrMetallicRoughness: materialDefinition.pbrMetallicRoughness ? { ...materialDefinition.pbrMetallicRoughness
333
- } : {
334
- baseColorFactor: [255, 255, 255, 255]
335
- }
336
- };
337
- } else {
338
- pbrMaterial = {
339
- pbrMetallicRoughness: {}
340
- };
341
-
367
+ let pbrMaterial;
368
+ if (materialDefinition) {
369
+ pbrMaterial = {
370
+ ...materialDefinition,
371
+ pbrMetallicRoughness: materialDefinition.pbrMetallicRoughness
372
+ ? { ...materialDefinition.pbrMetallicRoughness }
373
+ : { baseColorFactor: [255, 255, 255, 255] }
374
+ };
375
+ }
376
+ else {
377
+ pbrMaterial = {
378
+ pbrMetallicRoughness: {}
379
+ };
380
+ if (texture) {
381
+ pbrMaterial.pbrMetallicRoughness.baseColorTexture = { texCoord: 0 };
382
+ }
383
+ else {
384
+ pbrMaterial.pbrMetallicRoughness.baseColorFactor = [255, 255, 255, 255];
385
+ }
386
+ }
387
+ // Set default 0.25 per spec https://github.com/Esri/i3s-spec/blob/master/docs/1.7/materialDefinitions.cmn.md
388
+ pbrMaterial.alphaCutoff = pbrMaterial.alphaCutoff || 0.25;
389
+ if (pbrMaterial.alphaMode) {
390
+ // I3S contain alphaMode in lowerCase
391
+ pbrMaterial.alphaMode = pbrMaterial.alphaMode.toUpperCase();
392
+ }
393
+ // Convert colors from [255,255,255,255] to [1,1,1,1]
394
+ if (pbrMaterial.emissiveFactor) {
395
+ pbrMaterial.emissiveFactor = convertColorFormat(pbrMaterial.emissiveFactor);
396
+ }
397
+ if (pbrMaterial.pbrMetallicRoughness && pbrMaterial.pbrMetallicRoughness.baseColorFactor) {
398
+ pbrMaterial.pbrMetallicRoughness.baseColorFactor = convertColorFormat(pbrMaterial.pbrMetallicRoughness.baseColorFactor);
399
+ }
342
400
  if (texture) {
343
- pbrMaterial.pbrMetallicRoughness.baseColorTexture = {
344
- texCoord: 0
345
- };
346
- } else {
347
- pbrMaterial.pbrMetallicRoughness.baseColorFactor = [255, 255, 255, 255];
401
+ setMaterialTexture(pbrMaterial, texture);
348
402
  }
349
- }
350
-
351
- pbrMaterial.alphaCutoff = pbrMaterial.alphaCutoff || 0.25;
352
-
353
- if (pbrMaterial.alphaMode) {
354
- pbrMaterial.alphaMode = pbrMaterial.alphaMode.toUpperCase();
355
- }
356
-
357
- if (pbrMaterial.emissiveFactor) {
358
- pbrMaterial.emissiveFactor = convertColorFormat(pbrMaterial.emissiveFactor);
359
- }
360
-
361
- if (pbrMaterial.pbrMetallicRoughness && pbrMaterial.pbrMetallicRoughness.baseColorFactor) {
362
- pbrMaterial.pbrMetallicRoughness.baseColorFactor = convertColorFormat(pbrMaterial.pbrMetallicRoughness.baseColorFactor);
363
- }
364
-
365
- setMaterialTexture(pbrMaterial, texture);
366
- return pbrMaterial;
403
+ return pbrMaterial;
367
404
  }
368
-
405
+ /**
406
+ * Convert color from [255,255,255,255] to [1,1,1,1]
407
+ * @param colorFactor - color array
408
+ * @returns - new color array
409
+ */
369
410
  function convertColorFormat(colorFactor) {
370
- const normalizedColor = [...colorFactor];
371
-
372
- for (let index = 0; index < colorFactor.length; index++) {
373
- normalizedColor[index] = colorFactor[index] / 255;
374
- }
375
-
376
- return normalizedColor;
411
+ const normalizedColor = [...colorFactor];
412
+ for (let index = 0; index < colorFactor.length; index++) {
413
+ normalizedColor[index] = colorFactor[index] / 255;
414
+ }
415
+ return normalizedColor;
377
416
  }
378
-
417
+ /**
418
+ * Set texture in PBR material
419
+ * @param {object} material - i3s material definition
420
+ * @param image - texture image
421
+ * @returns
422
+ */
379
423
  function setMaterialTexture(material, image) {
380
- const texture = {
381
- source: {
382
- image
424
+ const texture = { source: { image } };
425
+ // I3SLoader now support loading only one texture. This elseif sequence will assign this texture to one of
426
+ // properties defined in materialDefinition
427
+ if (material.pbrMetallicRoughness && material.pbrMetallicRoughness.baseColorTexture) {
428
+ material.pbrMetallicRoughness.baseColorTexture = {
429
+ ...material.pbrMetallicRoughness.baseColorTexture,
430
+ texture
431
+ };
432
+ }
433
+ else if (material.emissiveTexture) {
434
+ material.emissiveTexture = { ...material.emissiveTexture, texture };
435
+ }
436
+ else if (material.pbrMetallicRoughness &&
437
+ material.pbrMetallicRoughness.metallicRoughnessTexture) {
438
+ material.pbrMetallicRoughness.metallicRoughnessTexture = {
439
+ ...material.pbrMetallicRoughness.metallicRoughnessTexture,
440
+ texture
441
+ };
442
+ }
443
+ else if (material.normalTexture) {
444
+ material.normalTexture = { ...material.normalTexture, texture };
445
+ }
446
+ else if (material.occlusionTexture) {
447
+ material.occlusionTexture = { ...material.occlusionTexture, texture };
383
448
  }
384
- };
385
-
386
- if (material.pbrMetallicRoughness && material.pbrMetallicRoughness.baseColorTexture) {
387
- material.pbrMetallicRoughness.baseColorTexture = { ...material.pbrMetallicRoughness.baseColorTexture,
388
- texture
389
- };
390
- } else if (material.emissiveTexture) {
391
- material.emissiveTexture = { ...material.emissiveTexture,
392
- texture
393
- };
394
- } else if (material.pbrMetallicRoughness && material.pbrMetallicRoughness.metallicRoughnessTexture) {
395
- material.pbrMetallicRoughness.metallicRoughnessTexture = { ...material.pbrMetallicRoughness.metallicRoughnessTexture,
396
- texture
397
- };
398
- } else if (material.normalTexture) {
399
- material.normalTexture = { ...material.normalTexture,
400
- texture
401
- };
402
- } else if (material.occlusionTexture) {
403
- material.occlusionTexture = { ...material.occlusionTexture,
404
- texture
405
- };
406
- }
407
449
  }
408
-
450
+ /**
451
+ * Flatten feature ids using face ranges
452
+ * @param normalizedFeatureAttributes
453
+ * @returns
454
+ */
409
455
  function flattenFeatureIdsByFaceRanges(normalizedFeatureAttributes) {
410
- const {
411
- id,
412
- faceRange
413
- } = normalizedFeatureAttributes;
414
-
415
- if (!id || !faceRange) {
416
- return;
417
- }
418
-
419
- const featureIds = id.value;
420
- const range = faceRange.value;
421
- const featureIdsLength = range[range.length - 1] + 1;
422
- const orderedFeatureIndices = new Uint32Array(featureIdsLength * 3);
423
- let featureIndex = 0;
424
- let startIndex = 0;
425
-
426
- for (let index = 1; index < range.length; index += 2) {
427
- const fillId = Number(featureIds[featureIndex]);
428
- const endValue = range[index];
429
- const prevValue = range[index - 1];
430
- const trianglesCount = endValue - prevValue + 1;
431
- const endIndex = startIndex + trianglesCount * 3;
432
- orderedFeatureIndices.fill(fillId, startIndex, endIndex);
433
- featureIndex++;
434
- startIndex = endIndex;
435
- }
436
-
437
- normalizedFeatureAttributes.id.value = orderedFeatureIndices;
456
+ const { id, faceRange } = normalizedFeatureAttributes;
457
+ if (!id || !faceRange) {
458
+ return;
459
+ }
460
+ const featureIds = id.value;
461
+ const range = faceRange.value;
462
+ const featureIdsLength = range[range.length - 1] + 1;
463
+ const orderedFeatureIndices = new Uint32Array(featureIdsLength * 3);
464
+ let featureIndex = 0;
465
+ let startIndex = 0;
466
+ for (let index = 1; index < range.length; index += 2) {
467
+ const fillId = Number(featureIds[featureIndex]);
468
+ const endValue = range[index];
469
+ const prevValue = range[index - 1];
470
+ const trianglesCount = endValue - prevValue + 1;
471
+ const endIndex = startIndex + trianglesCount * 3;
472
+ orderedFeatureIndices.fill(fillId, startIndex, endIndex);
473
+ featureIndex++;
474
+ startIndex = endIndex;
475
+ }
476
+ normalizedFeatureAttributes.id.value = orderedFeatureIndices;
438
477
  }
439
-
478
+ /**
479
+ * Flatten feature ids using featureIndices
480
+ * @param attributes
481
+ * @param featureIds
482
+ * @returns
483
+ */
440
484
  function flattenFeatureIdsByFeatureIndices(attributes, featureIds) {
441
- const featureIndices = attributes.id.value;
442
- const result = new Float32Array(featureIndices.length);
443
-
444
- for (let index = 0; index < featureIndices.length; index++) {
445
- result[index] = featureIds[featureIndices[index]];
446
- }
447
-
448
- attributes.id.value = result;
485
+ const featureIndices = attributes.id.value;
486
+ const result = new Float32Array(featureIndices.length);
487
+ for (let index = 0; index < featureIndices.length; index++) {
488
+ result[index] = featureIds[featureIndices[index]];
489
+ }
490
+ attributes.id.value = result;
449
491
  }
450
-
492
+ /**
493
+ * Flatten feature ids using featureIndices
494
+ * @param featureIndex
495
+ * @returns
496
+ */
451
497
  function getFeatureIdsFromFeatureIndexMetadata(featureIndex) {
452
- return featureIndex && featureIndex.metadata && featureIndex.metadata['i3s-feature-ids'] && featureIndex.metadata['i3s-feature-ids'].intArray;
498
+ return featureIndex?.metadata?.['i3s-feature-ids']?.intArray;
453
499
  }
454
- //# sourceMappingURL=parse-i3s-tile-content.js.map