@loaders.gl/i3s 3.1.0-alpha.4 → 3.1.0-beta.5

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 (125) hide show
  1. package/dist/bundle.d.ts +2 -0
  2. package/dist/bundle.d.ts.map +1 -0
  3. package/dist/bundle.js +10364 -0
  4. package/dist/es5/bundle.js +1 -1
  5. package/dist/es5/bundle.js.map +1 -1
  6. package/dist/es5/i3s-attribute-loader.js +89 -138
  7. package/dist/es5/i3s-attribute-loader.js.map +1 -1
  8. package/dist/es5/i3s-building-scene-layer-loader.js +8 -36
  9. package/dist/es5/i3s-building-scene-layer-loader.js.map +1 -1
  10. package/dist/es5/i3s-content-loader.js +10 -36
  11. package/dist/es5/i3s-content-loader.js.map +1 -1
  12. package/dist/es5/i3s-loader.js +56 -176
  13. package/dist/es5/i3s-loader.js.map +1 -1
  14. package/dist/es5/i3s-node-page-loader.js +8 -51
  15. package/dist/es5/i3s-node-page-loader.js.map +1 -1
  16. package/dist/es5/index.js +13 -5
  17. package/dist/es5/index.js.map +1 -1
  18. package/dist/es5/lib/helpers/i3s-nodepages-tiles.js +172 -325
  19. package/dist/es5/lib/helpers/i3s-nodepages-tiles.js.map +1 -1
  20. package/dist/es5/lib/parsers/constants.js +71 -25
  21. package/dist/es5/lib/parsers/constants.js.map +1 -1
  22. package/dist/es5/lib/parsers/parse-i3s-attribute.js +34 -68
  23. package/dist/es5/lib/parsers/parse-i3s-attribute.js.map +1 -1
  24. package/dist/es5/lib/parsers/parse-i3s-building-scene-layer.js +28 -59
  25. package/dist/es5/lib/parsers/parse-i3s-building-scene-layer.js.map +1 -1
  26. package/dist/es5/lib/parsers/parse-i3s-tile-content.js +314 -415
  27. package/dist/es5/lib/parsers/parse-i3s-tile-content.js.map +1 -1
  28. package/dist/es5/lib/parsers/parse-i3s.js +31 -70
  29. package/dist/es5/lib/parsers/parse-i3s.js.map +1 -1
  30. package/dist/es5/lib/utils/convert-i3s-obb-to-mbs.js +4 -8
  31. package/dist/es5/lib/utils/convert-i3s-obb-to-mbs.js.map +1 -1
  32. package/dist/es5/lib/utils/url-utils.js +17 -14
  33. package/dist/es5/lib/utils/url-utils.js.map +1 -1
  34. package/dist/es5/types.js +19 -0
  35. package/dist/es5/types.js.map +1 -1
  36. package/dist/esm/i3s-attribute-loader.js +44 -14
  37. package/dist/esm/i3s-attribute-loader.js.map +1 -1
  38. package/dist/esm/i3s-building-scene-layer-loader.js +1 -1
  39. package/dist/esm/i3s-building-scene-layer-loader.js.map +1 -1
  40. package/dist/esm/i3s-content-loader.js +1 -1
  41. package/dist/esm/i3s-content-loader.js.map +1 -1
  42. package/dist/esm/i3s-loader.js +5 -2
  43. package/dist/esm/i3s-loader.js.map +1 -1
  44. package/dist/esm/i3s-node-page-loader.js +1 -1
  45. package/dist/esm/i3s-node-page-loader.js.map +1 -1
  46. package/dist/esm/index.js +1 -0
  47. package/dist/esm/index.js.map +1 -1
  48. package/dist/esm/lib/helpers/i3s-nodepages-tiles.js +3 -3
  49. package/dist/esm/lib/helpers/i3s-nodepages-tiles.js.map +1 -1
  50. package/dist/esm/lib/parsers/constants.js +55 -15
  51. package/dist/esm/lib/parsers/constants.js.map +1 -1
  52. package/dist/esm/lib/parsers/parse-i3s-attribute.js +9 -1
  53. package/dist/esm/lib/parsers/parse-i3s-attribute.js.map +1 -1
  54. package/dist/esm/lib/parsers/parse-i3s-building-scene-layer.js +3 -1
  55. package/dist/esm/lib/parsers/parse-i3s-building-scene-layer.js.map +1 -1
  56. package/dist/esm/lib/parsers/parse-i3s-tile-content.js +87 -61
  57. package/dist/esm/lib/parsers/parse-i3s-tile-content.js.map +1 -1
  58. package/dist/esm/lib/parsers/parse-i3s.js +4 -4
  59. package/dist/esm/lib/parsers/parse-i3s.js.map +1 -1
  60. package/dist/esm/lib/utils/url-utils.js +3 -3
  61. package/dist/esm/lib/utils/url-utils.js.map +1 -1
  62. package/dist/esm/types.js +13 -1
  63. package/dist/esm/types.js.map +1 -1
  64. package/dist/i3s-attribute-loader.d.ts +14 -0
  65. package/dist/i3s-attribute-loader.d.ts.map +1 -0
  66. package/dist/i3s-attribute-loader.js +177 -0
  67. package/dist/i3s-building-scene-layer-loader.d.ts +6 -0
  68. package/dist/i3s-building-scene-layer-loader.d.ts.map +1 -0
  69. package/dist/i3s-building-scene-layer-loader.js +26 -0
  70. package/dist/i3s-content-loader.d.ts +6 -0
  71. package/dist/i3s-content-loader.d.ts.map +1 -0
  72. package/dist/i3s-content-loader.js +28 -0
  73. package/dist/i3s-content-worker.js +7657 -2
  74. package/dist/i3s-loader.d.ts +6 -0
  75. package/dist/i3s-loader.d.ts.map +1 -0
  76. package/dist/i3s-loader.js +100 -0
  77. package/dist/i3s-node-page-loader.d.ts +6 -0
  78. package/dist/i3s-node-page-loader.d.ts.map +1 -0
  79. package/dist/i3s-node-page-loader.js +26 -0
  80. package/dist/index.d.ts +7 -0
  81. package/dist/index.d.ts.map +1 -0
  82. package/dist/index.js +14 -0
  83. package/dist/lib/helpers/i3s-nodepages-tiles.d.ts +73 -0
  84. package/dist/lib/helpers/i3s-nodepages-tiles.d.ts.map +1 -0
  85. package/dist/lib/helpers/i3s-nodepages-tiles.js +231 -0
  86. package/dist/lib/parsers/constants.d.ts +56 -0
  87. package/dist/lib/parsers/constants.d.ts.map +1 -0
  88. package/dist/lib/parsers/constants.js +107 -0
  89. package/dist/lib/parsers/parse-i3s-attribute.d.ts +10 -0
  90. package/dist/lib/parsers/parse-i3s-attribute.d.ts.map +1 -0
  91. package/dist/lib/parsers/parse-i3s-attribute.js +98 -0
  92. package/dist/lib/parsers/parse-i3s-building-scene-layer.d.ts +9 -0
  93. package/dist/lib/parsers/parse-i3s-building-scene-layer.d.ts.map +1 -0
  94. package/dist/lib/parsers/parse-i3s-building-scene-layer.js +46 -0
  95. package/dist/lib/parsers/parse-i3s-tile-content.d.ts +4 -0
  96. package/dist/lib/parsers/parse-i3s-tile-content.d.ts.map +1 -0
  97. package/dist/lib/parsers/parse-i3s-tile-content.js +508 -0
  98. package/dist/lib/parsers/parse-i3s.d.ts +4 -0
  99. package/dist/lib/parsers/parse-i3s.d.ts.map +1 -0
  100. package/dist/lib/parsers/parse-i3s.js +84 -0
  101. package/dist/lib/utils/convert-i3s-obb-to-mbs.d.ts +2 -0
  102. package/dist/lib/utils/convert-i3s-obb-to-mbs.d.ts.map +1 -0
  103. package/dist/lib/utils/convert-i3s-obb-to-mbs.js +20 -0
  104. package/dist/lib/utils/url-utils.d.ts +22 -0
  105. package/dist/lib/utils/url-utils.d.ts.map +1 -0
  106. package/dist/lib/utils/url-utils.js +44 -0
  107. package/dist/types.d.ts +429 -0
  108. package/dist/types.d.ts.map +1 -0
  109. package/dist/types.js +15 -0
  110. package/dist/workers/i3s-content-worker.d.ts +2 -0
  111. package/dist/workers/i3s-content-worker.d.ts.map +1 -0
  112. package/dist/workers/i3s-content-worker.js +5 -0
  113. package/package.json +14 -12
  114. package/src/i3s-attribute-loader.ts +56 -19
  115. package/src/i3s-loader.ts +4 -1
  116. package/src/index.ts +1 -0
  117. package/src/lib/parsers/constants.ts +73 -18
  118. package/src/lib/parsers/parse-i3s-attribute.ts +19 -1
  119. package/src/lib/parsers/parse-i3s-building-scene-layer.ts +2 -1
  120. package/src/lib/parsers/parse-i3s-tile-content.ts +159 -109
  121. package/src/lib/utils/url-utils.ts +1 -1
  122. package/src/types.ts +153 -22
  123. package/dist/dist.min.js +0 -2
  124. package/dist/dist.min.js.map +0 -1
  125. package/dist/i3s-content-worker.js.map +0 -1
@@ -3,32 +3,50 @@ import {load, parse} from '@loaders.gl/core';
3
3
  import {Vector3, Matrix4} from '@math.gl/core';
4
4
  import {Ellipsoid} from '@math.gl/geospatial';
5
5
 
6
+ import type {GLTFMaterial} from '@loaders.gl/gltf';
6
7
  import type {LoaderOptions, LoaderContext} from '@loaders.gl/loader-utils';
7
8
  import {ImageLoader} from '@loaders.gl/images';
8
9
  import {DracoLoader} from '@loaders.gl/draco';
9
10
  import {BasisLoader, CompressedTextureLoader} from '@loaders.gl/textures';
10
11
 
11
- import {Tileset, Tile} from '../../types';
12
+ import type {
13
+ Tileset,
14
+ Tile,
15
+ FeatureAttribute,
16
+ TileContent,
17
+ VertexAttribute,
18
+ NormalizedAttribute,
19
+ NormalizedAttributes,
20
+ TileContentTexture
21
+ } from '../../types';
12
22
  import {getUrlWithToken} from '../utils/url-utils';
13
23
 
14
24
  import {
15
25
  GL_TYPE_MAP,
16
- TYPE_ARRAY_MAP,
17
- SIZEOF,
26
+ getConstructorForDataFormat,
27
+ sizeOf,
18
28
  I3S_NAMED_HEADER_ATTRIBUTES,
19
29
  I3S_NAMED_VERTEX_ATTRIBUTES,
20
- I3S_NAMED_GEOMETRY_ATTRIBUTES
30
+ I3S_NAMED_GEOMETRY_ATTRIBUTES,
31
+ COORDINATE_SYSTEM
21
32
  } from './constants';
22
33
 
23
34
  const scratchVector = new Vector3([0, 0, 0]);
24
35
 
25
- const FORMAT_LOADER_MAP = {
26
- jpeg: ImageLoader,
27
- png: ImageLoader,
28
- 'ktx-etc2': CompressedTextureLoader,
29
- dds: CompressedTextureLoader,
30
- ktx2: BasisLoader
31
- };
36
+ function getLoaderForTextureFormat(textureFormat: 'jpeg' | 'png' | 'ktx-etc2' | 'dds' | 'ktx2') {
37
+ switch (textureFormat) {
38
+ case 'jpeg':
39
+ case 'png':
40
+ return ImageLoader;
41
+ case 'ktx-etc2':
42
+ case 'dds':
43
+ return CompressedTextureLoader;
44
+ case 'ktx2':
45
+ return BasisLoader;
46
+ default:
47
+ return null;
48
+ }
49
+ }
32
50
 
33
51
  const I3S_ATTRIBUTE_TYPE = 'i3s-attribute-type';
34
52
 
@@ -43,32 +61,41 @@ export async function parseI3STileContent(
43
61
  tile.content.featureIds = tile.content.featureIds || null;
44
62
 
45
63
  // construct featureData from defaultGeometrySchema;
46
- tile.content.featureData = constructFeatureDataStruct(tile, tileset);
64
+ tile.content.featureData = constructFeatureDataStruct(tileset);
47
65
  tile.content.attributes = {};
48
66
 
49
67
  if (tile.textureUrl) {
50
68
  const url = getUrlWithToken(tile.textureUrl, options?.i3s?.token);
51
- const loader = FORMAT_LOADER_MAP[tile.textureFormat] || ImageLoader;
69
+ const loader = getLoaderForTextureFormat(tile.textureFormat) || ImageLoader;
52
70
  // @ts-ignore context must be defined
53
71
  const response = await fetch(url);
54
72
  const arrayBuffer = await response.arrayBuffer();
55
73
 
56
- if (loader === ImageLoader) {
57
- const options = {...tile.textureLoaderOptions, image: {type: 'data'}};
58
- // @ts-ignore context must be defined
59
- // Image constructor is not supported in worker thread.
60
- // Do parsing image data on the main thread by using context to avoid worker issues.
61
- tile.content.texture = await context.parse(arrayBuffer, options);
62
- } else if (loader === CompressedTextureLoader || loader === BasisLoader) {
63
- // @ts-ignore context must be defined
64
- const texture = await load(arrayBuffer, loader, tile.textureLoaderOptions);
65
- tile.content.texture = {
66
- compressed: true,
67
- mipmaps: false,
68
- width: texture[0].width,
69
- height: texture[0].height,
70
- data: texture
71
- };
74
+ if (options?.i3s.decodeTextures) {
75
+ if (loader === ImageLoader) {
76
+ const options = {...tile.textureLoaderOptions, image: {type: 'data'}};
77
+ try {
78
+ // @ts-ignore context must be defined
79
+ // Image constructor is not supported in worker thread.
80
+ // Do parsing image data on the main thread by using context to avoid worker issues.
81
+ tile.content.texture = await context.parse(arrayBuffer, options);
82
+ } catch (e) {
83
+ // context object is different between worker and node.js conversion script.
84
+ // To prevent error we parse data in ordinary way if it is not parsed by using context.
85
+ tile.content.texture = await parse(arrayBuffer, loader, options);
86
+ }
87
+ } else if (loader === CompressedTextureLoader || loader === BasisLoader) {
88
+ const texture = await load(arrayBuffer, loader, tile.textureLoaderOptions);
89
+ tile.content.texture = {
90
+ compressed: true,
91
+ mipmaps: false,
92
+ width: texture[0].width,
93
+ height: texture[0].height,
94
+ data: texture
95
+ };
96
+ }
97
+ } else {
98
+ tile.content.texture = arrayBuffer;
72
99
  }
73
100
  }
74
101
 
@@ -77,24 +104,20 @@ export async function parseI3STileContent(
77
104
  tile.content.texture = null;
78
105
  }
79
106
 
80
- return await parseI3SNodeGeometry(arrayBuffer, tile, context);
107
+ return await parseI3SNodeGeometry(arrayBuffer, tile, options);
81
108
  }
82
109
 
83
110
  /* eslint-disable max-statements */
84
- async function parseI3SNodeGeometry(
85
- arrayBuffer: ArrayBuffer,
86
- tile: Tile = {},
87
- context?: LoaderContext
88
- ) {
111
+ async function parseI3SNodeGeometry(arrayBuffer: ArrayBuffer, tile: Tile, options?: LoaderOptions) {
89
112
  if (!tile.content) {
90
113
  return tile;
91
114
  }
92
115
 
93
116
  const content = tile.content;
94
- let attributes;
95
- let vertexCount;
96
- let byteOffset = 0;
97
- let featureCount = 0;
117
+ let attributes: NormalizedAttributes;
118
+ let vertexCount: number;
119
+ let byteOffset: number = 0;
120
+ let featureCount: number = 0;
98
121
 
99
122
  if (tile.isDracoGeometry) {
100
123
  const decompressedGeometry = await parse(arrayBuffer, DracoLoader, {
@@ -145,6 +168,7 @@ async function parseI3SNodeGeometry(
145
168
  byteOffset,
146
169
  vertexAttributes,
147
170
  vertexCount,
171
+ // @ts-expect-error
148
172
  attributesOrder
149
173
  );
150
174
 
@@ -161,12 +185,17 @@ async function parseI3SNodeGeometry(
161
185
  attributes = concatAttributes(normalizedVertexAttributes, normalizedFeatureAttributes);
162
186
  }
163
187
 
164
- const {enuMatrix, cartographicOrigin, cartesianOrigin} = parsePositions(
165
- attributes.position,
166
- tile
167
- );
168
-
169
- const matrix = new Matrix4().multiplyRight(enuMatrix);
188
+ if (
189
+ !options?.i3s?.coordinateSystem ||
190
+ options.i3s.coordinateSystem === COORDINATE_SYSTEM.METER_OFFSETS
191
+ ) {
192
+ const enuMatrix = parsePositions(attributes.position, tile);
193
+ content.modelMatrix = enuMatrix.invert();
194
+ content.coordinateSystem = COORDINATE_SYSTEM.METER_OFFSETS;
195
+ } else {
196
+ content.modelMatrix = getModelMatrix(attributes.position);
197
+ content.coordinateSystem = COORDINATE_SYSTEM.LNGLAT_OFFSETS;
198
+ }
170
199
 
171
200
  content.attributes = {
172
201
  positions: attributes.position,
@@ -189,9 +218,6 @@ async function parseI3SNodeGeometry(
189
218
  }
190
219
 
191
220
  content.vertexCount = vertexCount;
192
- content.cartographicCenter = cartographicOrigin;
193
- content.cartesianOrigin = cartesianOrigin;
194
- content.modelMatrix = matrix.invert();
195
221
  content.byteLength = arrayBuffer.byteLength;
196
222
 
197
223
  return tile;
@@ -202,7 +228,7 @@ async function parseI3SNodeGeometry(
202
228
  * @param decompressedGeometry
203
229
  * @param attributes
204
230
  */
205
- function updateAttributesMetadata(attributes, decompressedGeometry) {
231
+ function updateAttributesMetadata(attributes: NormalizedAttributes, decompressedGeometry): void {
206
232
  for (const key in decompressedGeometry.loaderData.attributes) {
207
233
  const dracoAttribute = decompressedGeometry.loaderData.attributes[key];
208
234
 
@@ -222,20 +248,23 @@ function updateAttributesMetadata(attributes, decompressedGeometry) {
222
248
  /**
223
249
  * Do concatenation of attribute objects.
224
250
  * Done as separate fucntion to avoid ts errors.
225
- * @param {Object} normalizedVertexAttributes
226
- * @param {Object} normalizedFeatureAttributes
227
- * @returns {object} - result of attributes concatenation.
251
+ * @param normalizedVertexAttributes
252
+ * @param normalizedFeatureAttributes
253
+ * @returns - result of attributes concatenation.
228
254
  */
229
- function concatAttributes(normalizedVertexAttributes, normalizedFeatureAttributes) {
255
+ function concatAttributes(
256
+ normalizedVertexAttributes: NormalizedAttributes,
257
+ normalizedFeatureAttributes: NormalizedAttributes
258
+ ): NormalizedAttributes {
230
259
  return {...normalizedVertexAttributes, ...normalizedFeatureAttributes};
231
260
  }
232
261
 
233
262
  /**
234
263
  * Normalize attribute to range [0..1] . Eg. convert colors buffer from [255,255,255,255] to [1,1,1,1]
235
- * @param {Object} attribute - geometry attribute
236
- * @returns {Object} - geometry attribute in right format
264
+ * @param attribute - geometry attribute
265
+ * @returns - geometry attribute in right format
237
266
  */
238
- function normalizeAttribute(attribute) {
267
+ function normalizeAttribute(attribute: NormalizedAttribute): NormalizedAttribute {
239
268
  if (!attribute) {
240
269
  return attribute;
241
270
  }
@@ -243,7 +272,7 @@ function normalizeAttribute(attribute) {
243
272
  return attribute;
244
273
  }
245
274
 
246
- function constructFeatureDataStruct(tile, tileset) {
275
+ function constructFeatureDataStruct(tileset: Tileset) {
247
276
  // seed featureData from defaultGeometrySchema
248
277
  const defaultGeometrySchema = tileset.store.defaultGeometrySchema;
249
278
  const featureData = defaultGeometrySchema;
@@ -268,24 +297,25 @@ function constructFeatureDataStruct(tile, tileset) {
268
297
  return featureData;
269
298
  }
270
299
 
271
- function parseHeaders(content, buffer) {
300
+ function parseHeaders(content: TileContent, arrayBuffer: ArrayBuffer) {
272
301
  let byteOffset = 0;
273
302
  // First 8 bytes reserved for header (vertexCount and featurecount)
274
303
  let vertexCount = 0;
275
304
  let featureCount = 0;
276
- const headers = content.featureData[I3S_NAMED_HEADER_ATTRIBUTES.header];
277
- for (const header in headers) {
278
- const {property, type} = headers[header];
279
- const TypedArrayTypeHeader = TYPE_ARRAY_MAP[type];
305
+ content.featureData.header.forEach(({property, type}) => {
306
+ const TypedArrayTypeHeader = getConstructorForDataFormat(type);
280
307
  if (property === I3S_NAMED_HEADER_ATTRIBUTES.vertexCount) {
281
- vertexCount = new TypedArrayTypeHeader(buffer, 0, 4)[0];
282
- byteOffset += SIZEOF[type];
308
+ // @ts-expect-error
309
+ vertexCount = new TypedArrayTypeHeader(arrayBuffer, 0, 4)[0];
310
+ byteOffset += sizeOf(type);
283
311
  }
284
312
  if (property === I3S_NAMED_HEADER_ATTRIBUTES.featureCount) {
285
- featureCount = new TypedArrayTypeHeader(buffer, 4, 4)[0];
286
- byteOffset += SIZEOF[type];
313
+ // @ts-expect-error
314
+ featureCount = new TypedArrayTypeHeader(arrayBuffer, 4, 4)[0];
315
+ byteOffset += sizeOf(type);
287
316
  }
288
- }
317
+ });
318
+
289
319
  return {
290
320
  vertexCount,
291
321
  featureCount,
@@ -296,18 +326,19 @@ function parseHeaders(content, buffer) {
296
326
  /* eslint-enable max-statements */
297
327
 
298
328
  function normalizeAttributes(
299
- arrayBuffer,
300
- byteOffset,
301
- vertexAttributes,
302
- vertexCount,
303
- attributesOrder
329
+ arrayBuffer: ArrayBuffer,
330
+ byteOffset: number,
331
+ vertexAttributes: VertexAttribute | FeatureAttribute,
332
+ vertexCount: number,
333
+ attributesOrder: string[]
304
334
  ) {
305
- const attributes = {};
335
+ const attributes: NormalizedAttributes = {};
306
336
 
307
337
  // the order of attributes depend on the order being added to the vertexAttributes object
308
338
  for (const attribute of attributesOrder) {
309
339
  if (vertexAttributes[attribute]) {
310
- const {valueType, valuesPerElement} = vertexAttributes[attribute];
340
+ const {valueType, valuesPerElement}: {valueType: string; valuesPerElement: number} =
341
+ vertexAttributes[attribute];
311
342
  // update count and byteOffset count by calculating from defaultGeometrySchema + binnary content
312
343
  const count = vertexCount;
313
344
  // protect from arrayBuffer read overunns by NOT assuming node has regions always even though its declared in defaultGeometrySchema.
@@ -323,9 +354,10 @@ function normalizeAttributes(
323
354
  let value: number[] | TypedArray = [];
324
355
 
325
356
  if (valueType === 'UInt64') {
326
- value = parseUint64Values(buffer, count * valuesPerElement, SIZEOF[valueType]);
357
+ value = parseUint64Values(buffer, count * valuesPerElement, sizeOf(valueType));
327
358
  } else {
328
- const TypedArrayType = TYPE_ARRAY_MAP[valueType];
359
+ const TypedArrayType = getConstructorForDataFormat(valueType);
360
+ // @ts-expect-error
329
361
  value = new TypedArrayType(buffer, 0, count * valuesPerElement);
330
362
  }
331
363
 
@@ -337,7 +369,6 @@ function normalizeAttributes(
337
369
 
338
370
  switch (attribute) {
339
371
  case 'color':
340
- // @ts-ignore
341
372
  attributes.color.normalized = true;
342
373
  break;
343
374
  case 'position':
@@ -346,7 +377,7 @@ function normalizeAttributes(
346
377
  default:
347
378
  }
348
379
 
349
- byteOffset = byteOffset + count * valuesPerElement * SIZEOF[valueType];
380
+ byteOffset = byteOffset + count * valuesPerElement * sizeOf(valueType);
350
381
  }
351
382
  }
352
383
 
@@ -383,7 +414,7 @@ function parseUint64Values(
383
414
  return values;
384
415
  }
385
416
 
386
- function parsePositions(attribute, tile) {
417
+ function parsePositions(attribute: NormalizedAttribute, tile: Tile): Matrix4 {
387
418
  const mbs = tile.mbs;
388
419
  const value = attribute.value;
389
420
  const metadata = attribute.metadata;
@@ -394,23 +425,22 @@ function parsePositions(attribute, tile) {
394
425
  Ellipsoid.WGS84.eastNorthUpToFixedFrame(cartesianOrigin, enuMatrix);
395
426
  attribute.value = offsetsToCartesians(value, metadata, cartographicOrigin);
396
427
 
397
- return {
398
- enuMatrix,
399
- fixedFrameToENUMatrix: enuMatrix.invert(),
400
- cartographicOrigin,
401
- cartesianOrigin
402
- };
428
+ return enuMatrix;
403
429
  }
404
430
 
405
431
  /**
406
432
  * Converts position coordinates to absolute cartesian coordinates
407
- * @param {Float32Array} vertices - "position" attribute data
408
- * @param {Object} metadata - When the geometry is DRACO compressed, contain position attribute's metadata
433
+ * @param vertices - "position" attribute data
434
+ * @param metadata - When the geometry is DRACO compressed, contain position attribute's metadata
409
435
  * https://github.com/Esri/i3s-spec/blob/master/docs/1.7/compressedAttributes.cmn.md
410
- * @param {Vector3} cartographicOrigin - Cartographic origin coordinates
411
- * @returns {Float64Array} - converted "position" data
436
+ * @param cartographicOrigin - Cartographic origin coordinates
437
+ * @returns - converted "position" data
412
438
  */
413
- function offsetsToCartesians(vertices, metadata = {}, cartographicOrigin) {
439
+ function offsetsToCartesians(
440
+ vertices: number[] | TypedArray,
441
+ metadata: any = {},
442
+ cartographicOrigin: Vector3
443
+ ): Float64Array {
414
444
  const positions = new Float64Array(vertices.length);
415
445
  const scaleX = (metadata['i3s-scale_x'] && metadata['i3s-scale_x'].double) || 1;
416
446
  const scaleY = (metadata['i3s-scale_y'] && metadata['i3s-scale_y'].double) || 1;
@@ -431,14 +461,29 @@ function offsetsToCartesians(vertices, metadata = {}, cartographicOrigin) {
431
461
  return positions;
432
462
  }
433
463
 
464
+ /**
465
+ * Get model matrix for loaded vertices
466
+ * @param positions positions attribute
467
+ * @returns Matrix4 - model matrix for geometry transformation
468
+ */
469
+ function getModelMatrix(positions: NormalizedAttribute): Matrix4 {
470
+ const metadata = positions.metadata;
471
+ const scaleX: number = metadata?.['i3s-scale_x']?.double || 1;
472
+ const scaleY: number = metadata?.['i3s-scale_y']?.double || 1;
473
+ const modelMatrix = new Matrix4();
474
+ modelMatrix[0] = scaleX;
475
+ modelMatrix[5] = scaleY;
476
+ return modelMatrix;
477
+ }
478
+
434
479
  /**
435
480
  * Makes a glTF-compatible PBR material from an I3S material definition
436
- * @param {object} materialDefinition - i3s material definition
481
+ * @param materialDefinition - i3s material definition
437
482
  * https://github.com/Esri/i3s-spec/blob/master/docs/1.7/materialDefinitions.cmn.md
438
- * @param {object} texture - texture image
483
+ * @param texture - texture image
439
484
  * @returns {object}
440
485
  */
441
- function makePbrMaterial(materialDefinition, texture) {
486
+ function makePbrMaterial(materialDefinition: GLTFMaterial, texture: TileContentTexture) {
442
487
  let pbrMaterial;
443
488
  if (materialDefinition) {
444
489
  pbrMaterial = {
@@ -483,10 +528,10 @@ function makePbrMaterial(materialDefinition, texture) {
483
528
 
484
529
  /**
485
530
  * Convert color from [255,255,255,255] to [1,1,1,1]
486
- * @param {Array} colorFactor - color array
487
- * @returns {Array} - new color array
531
+ * @param colorFactor - color array
532
+ * @returns - new color array
488
533
  */
489
- function convertColorFormat(colorFactor) {
534
+ function convertColorFormat(colorFactor: number[]): number[] {
490
535
  const normalizedColor = [...colorFactor];
491
536
  for (let index = 0; index < colorFactor.length; index++) {
492
537
  normalizedColor[index] = colorFactor[index] / 255;
@@ -497,10 +542,10 @@ function convertColorFormat(colorFactor) {
497
542
  /**
498
543
  * Set texture in PBR material
499
544
  * @param {object} material - i3s material definition
500
- * @param {object} image - texture image
501
- * @returns {void}
545
+ * @param image - texture image
546
+ * @returns
502
547
  */
503
- function setMaterialTexture(material, image) {
548
+ function setMaterialTexture(material, image: TileContentTexture): void {
504
549
  const texture = {source: {image}};
505
550
  // I3SLoader now support loading only one texture. This elseif sequence will assign this texture to one of
506
551
  // properties defined in materialDefinition
@@ -528,10 +573,10 @@ function setMaterialTexture(material, image) {
528
573
 
529
574
  /**
530
575
  * Flatten feature ids using face ranges
531
- * @param {object} normalizedFeatureAttributes
532
- * @returns {void}
576
+ * @param normalizedFeatureAttributes
577
+ * @returns
533
578
  */
534
- function flattenFeatureIdsByFaceRanges(normalizedFeatureAttributes) {
579
+ function flattenFeatureIdsByFaceRanges(normalizedFeatureAttributes: NormalizedAttributes): void {
535
580
  const {id, faceRange} = normalizedFeatureAttributes;
536
581
 
537
582
  if (!id || !faceRange) {
@@ -564,11 +609,14 @@ function flattenFeatureIdsByFaceRanges(normalizedFeatureAttributes) {
564
609
 
565
610
  /**
566
611
  * Flatten feature ids using featureIndices
567
- * @param {object} attributes
568
- * @param {any} featureIds
569
- * @returns {void}
612
+ * @param attributes
613
+ * @param featureIds
614
+ * @returns
570
615
  */
571
- function flattenFeatureIdsByFeatureIndices(attributes, featureIds) {
616
+ function flattenFeatureIdsByFeatureIndices(
617
+ attributes: NormalizedAttributes,
618
+ featureIds: Int32Array
619
+ ): void {
572
620
  const featureIndices = attributes.id.value;
573
621
  const result = new Float32Array(featureIndices.length);
574
622
 
@@ -581,10 +629,12 @@ function flattenFeatureIdsByFeatureIndices(attributes, featureIds) {
581
629
 
582
630
  /**
583
631
  * Flatten feature ids using featureIndices
584
- * @param {object} featureIndex
585
- * @returns {Int32Array}
632
+ * @param featureIndex
633
+ * @returns
586
634
  */
587
- function getFeatureIdsFromFeatureIndexMetadata(featureIndex) {
635
+ function getFeatureIdsFromFeatureIndexMetadata(
636
+ featureIndex: NormalizedAttribute
637
+ ): Int32Array | undefined {
588
638
  return (
589
639
  featureIndex &&
590
640
  featureIndex.metadata &&
@@ -6,7 +6,7 @@ import {Tile} from '../../types';
6
6
  * @param {any} token
7
7
  * @returns {string}
8
8
  */
9
- export function getUrlWithToken(url, token = null) {
9
+ export function getUrlWithToken(url: string, token = null): string {
10
10
  return token ? `${url}?token=${token}` : url;
11
11
  }
12
12