@loaders.gl/i3s 3.1.0-beta.2 → 3.1.1

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 (90) hide show
  1. package/dist/bundle.js +373 -300
  2. package/dist/es5/bundle.js +1 -1
  3. package/dist/es5/bundle.js.map +1 -1
  4. package/dist/es5/i3s-attribute-loader.js +147 -62
  5. package/dist/es5/i3s-attribute-loader.js.map +1 -1
  6. package/dist/es5/i3s-building-scene-layer-loader.js +36 -8
  7. package/dist/es5/i3s-building-scene-layer-loader.js.map +1 -1
  8. package/dist/es5/i3s-content-loader.js +36 -10
  9. package/dist/es5/i3s-content-loader.js.map +1 -1
  10. package/dist/es5/i3s-loader.js +175 -51
  11. package/dist/es5/i3s-loader.js.map +1 -1
  12. package/dist/es5/i3s-node-page-loader.js +51 -8
  13. package/dist/es5/i3s-node-page-loader.js.map +1 -1
  14. package/dist/es5/index.js +6 -6
  15. package/dist/es5/index.js.map +1 -1
  16. package/dist/es5/lib/helpers/i3s-nodepages-tiles.js +328 -173
  17. package/dist/es5/lib/helpers/i3s-nodepages-tiles.js.map +1 -1
  18. package/dist/es5/lib/parsers/constants.js +9 -28
  19. package/dist/es5/lib/parsers/constants.js.map +1 -1
  20. package/dist/es5/lib/parsers/parse-i3s-attribute.js +69 -27
  21. package/dist/es5/lib/parsers/parse-i3s-attribute.js.map +1 -1
  22. package/dist/es5/lib/parsers/parse-i3s-building-scene-layer.js +62 -28
  23. package/dist/es5/lib/parsers/parse-i3s-building-scene-layer.js.map +1 -1
  24. package/dist/es5/lib/parsers/parse-i3s-tile-content.js +416 -314
  25. package/dist/es5/lib/parsers/parse-i3s-tile-content.js.map +1 -1
  26. package/dist/es5/lib/parsers/parse-i3s.js +109 -49
  27. package/dist/es5/lib/parsers/parse-i3s.js.map +1 -1
  28. package/dist/es5/lib/utils/convert-i3s-obb-to-mbs.js +8 -4
  29. package/dist/es5/lib/utils/convert-i3s-obb-to-mbs.js.map +1 -1
  30. package/dist/es5/lib/utils/url-utils.js +14 -17
  31. package/dist/es5/lib/utils/url-utils.js.map +1 -1
  32. package/dist/es5/types.js +10 -2
  33. package/dist/es5/types.js.map +1 -1
  34. package/dist/esm/i3s-attribute-loader.js +1 -1
  35. package/dist/esm/i3s-attribute-loader.js.map +1 -1
  36. package/dist/esm/i3s-building-scene-layer-loader.js +1 -1
  37. package/dist/esm/i3s-building-scene-layer-loader.js.map +1 -1
  38. package/dist/esm/i3s-content-loader.js +1 -1
  39. package/dist/esm/i3s-content-loader.js.map +1 -1
  40. package/dist/esm/i3s-loader.js +1 -1
  41. package/dist/esm/i3s-loader.js.map +1 -1
  42. package/dist/esm/i3s-node-page-loader.js +1 -1
  43. package/dist/esm/i3s-node-page-loader.js.map +1 -1
  44. package/dist/esm/index.js.map +1 -1
  45. package/dist/esm/lib/helpers/i3s-nodepages-tiles.js +33 -23
  46. package/dist/esm/lib/helpers/i3s-nodepages-tiles.js.map +1 -1
  47. package/dist/esm/lib/parsers/constants.js +2 -18
  48. package/dist/esm/lib/parsers/constants.js.map +1 -1
  49. package/dist/esm/lib/parsers/parse-i3s-tile-content.js +44 -61
  50. package/dist/esm/lib/parsers/parse-i3s-tile-content.js.map +1 -1
  51. package/dist/esm/lib/parsers/parse-i3s.js +40 -25
  52. package/dist/esm/lib/parsers/parse-i3s.js.map +1 -1
  53. package/dist/esm/lib/utils/url-utils.js +2 -3
  54. package/dist/esm/lib/utils/url-utils.js.map +1 -1
  55. package/dist/esm/types.js +7 -0
  56. package/dist/esm/types.js.map +1 -1
  57. package/dist/i3s-building-scene-layer-loader.js +1 -1
  58. package/dist/i3s-content-loader.js +1 -1
  59. package/dist/i3s-content-worker.js +278 -201
  60. package/dist/index.d.ts +1 -1
  61. package/dist/index.d.ts.map +1 -1
  62. package/dist/lib/helpers/i3s-nodepages-tiles.d.ts +20 -20
  63. package/dist/lib/helpers/i3s-nodepages-tiles.d.ts.map +1 -1
  64. package/dist/lib/helpers/i3s-nodepages-tiles.js +33 -32
  65. package/dist/lib/parsers/constants.d.ts +1 -17
  66. package/dist/lib/parsers/constants.d.ts.map +1 -1
  67. package/dist/lib/parsers/constants.js +3 -21
  68. package/dist/lib/parsers/parse-i3s-attribute.d.ts +1 -1
  69. package/dist/lib/parsers/parse-i3s-tile-content.d.ts +2 -2
  70. package/dist/lib/parsers/parse-i3s-tile-content.d.ts.map +1 -1
  71. package/dist/lib/parsers/parse-i3s-tile-content.js +35 -61
  72. package/dist/lib/parsers/parse-i3s.d.ts +5 -3
  73. package/dist/lib/parsers/parse-i3s.d.ts.map +1 -1
  74. package/dist/lib/parsers/parse-i3s.js +37 -32
  75. package/dist/lib/utils/url-utils.d.ts +6 -6
  76. package/dist/lib/utils/url-utils.d.ts.map +1 -1
  77. package/dist/lib/utils/url-utils.js +5 -5
  78. package/dist/types.d.ts +289 -74
  79. package/dist/types.d.ts.map +1 -1
  80. package/dist/types.js +6 -1
  81. package/package.json +9 -9
  82. package/src/i3s-building-scene-layer-loader.ts +1 -1
  83. package/src/i3s-content-loader.ts +1 -1
  84. package/src/index.ts +3 -3
  85. package/src/lib/helpers/i3s-nodepages-tiles.ts +71 -55
  86. package/src/lib/parsers/constants.ts +2 -22
  87. package/src/lib/parsers/parse-i3s-tile-content.ts +74 -103
  88. package/src/lib/parsers/parse-i3s.ts +48 -37
  89. package/src/lib/utils/url-utils.ts +7 -7
  90. package/src/types.ts +302 -93
@@ -2,49 +2,39 @@ import type {TypedArray} from '@loaders.gl/schema';
2
2
  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
-
6
- import type {GLTFMaterial} from '@loaders.gl/gltf';
7
5
  import type {LoaderOptions, LoaderContext} from '@loaders.gl/loader-utils';
8
6
  import {ImageLoader} from '@loaders.gl/images';
9
- import {DracoLoader} from '@loaders.gl/draco';
7
+ import {DracoLoader, DracoMesh} from '@loaders.gl/draco';
10
8
  import {BasisLoader, CompressedTextureLoader} from '@loaders.gl/textures';
11
9
 
12
- import type {
13
- Tileset,
14
- Tile,
10
+ import {
11
+ I3STilesetHeader,
12
+ I3STileHeader,
15
13
  FeatureAttribute,
16
- TileContent,
17
14
  VertexAttribute,
18
- NormalizedAttribute,
19
- NormalizedAttributes,
20
- TileContentTexture
15
+ I3SMeshAttributes,
16
+ I3SMeshAttribute,
17
+ TileContentTexture,
18
+ HeaderAttributeProperty,
19
+ I3SMaterialDefinition
21
20
  } from '../../types';
22
21
  import {getUrlWithToken} from '../utils/url-utils';
23
22
 
24
- import {
25
- GL_TYPE_MAP,
26
- getConstructorForDataFormat,
27
- sizeOf,
28
- I3S_NAMED_HEADER_ATTRIBUTES,
29
- I3S_NAMED_VERTEX_ATTRIBUTES,
30
- I3S_NAMED_GEOMETRY_ATTRIBUTES,
31
- COORDINATE_SYSTEM
32
- } from './constants';
23
+ import {GL_TYPE_MAP, getConstructorForDataFormat, sizeOf, COORDINATE_SYSTEM} from './constants';
33
24
 
34
25
  const scratchVector = new Vector3([0, 0, 0]);
35
26
 
36
- function getLoaderForTextureFormat(textureFormat: 'jpeg' | 'png' | 'ktx-etc2' | 'dds' | 'ktx2') {
27
+ function getLoaderForTextureFormat(textureFormat?: 'jpg' | 'png' | 'ktx-etc2' | 'dds' | 'ktx2') {
37
28
  switch (textureFormat) {
38
- case 'jpeg':
39
- case 'png':
40
- return ImageLoader;
41
29
  case 'ktx-etc2':
42
30
  case 'dds':
43
31
  return CompressedTextureLoader;
44
32
  case 'ktx2':
45
33
  return BasisLoader;
34
+ case 'jpg':
35
+ case 'png':
46
36
  default:
47
- return null;
37
+ return ImageLoader;
48
38
  }
49
39
  }
50
40
 
@@ -52,22 +42,19 @@ const I3S_ATTRIBUTE_TYPE = 'i3s-attribute-type';
52
42
 
53
43
  export async function parseI3STileContent(
54
44
  arrayBuffer: ArrayBuffer,
55
- tile: Tile,
56
- tileset: Tileset,
45
+ tile: I3STileHeader,
46
+ tileset: I3STilesetHeader,
57
47
  options?: LoaderOptions,
58
48
  context?: LoaderContext
59
49
  ) {
60
50
  tile.content = tile.content || {};
61
51
  tile.content.featureIds = tile.content.featureIds || null;
62
52
 
63
- // construct featureData from defaultGeometrySchema;
64
- tile.content.featureData = constructFeatureDataStruct(tileset);
65
53
  tile.content.attributes = {};
66
54
 
67
55
  if (tile.textureUrl) {
68
56
  const url = getUrlWithToken(tile.textureUrl, options?.i3s?.token);
69
- const loader = getLoaderForTextureFormat(tile.textureFormat) || ImageLoader;
70
- // @ts-ignore context must be defined
57
+ const loader = getLoaderForTextureFormat(tile.textureFormat);
71
58
  const response = await fetch(url);
72
59
  const arrayBuffer = await response.arrayBuffer();
73
60
 
@@ -104,30 +91,36 @@ export async function parseI3STileContent(
104
91
  tile.content.texture = null;
105
92
  }
106
93
 
107
- return await parseI3SNodeGeometry(arrayBuffer, tile, options);
94
+ return await parseI3SNodeGeometry(arrayBuffer, tile, tileset, options);
108
95
  }
109
96
 
110
97
  /* eslint-disable max-statements */
111
- async function parseI3SNodeGeometry(arrayBuffer: ArrayBuffer, tile: Tile, options?: LoaderOptions) {
98
+ async function parseI3SNodeGeometry(
99
+ arrayBuffer: ArrayBuffer,
100
+ tile: I3STileHeader,
101
+ tileset: I3STilesetHeader,
102
+ options?: LoaderOptions
103
+ ) {
112
104
  if (!tile.content) {
113
105
  return tile;
114
106
  }
115
107
 
116
108
  const content = tile.content;
117
- let attributes: NormalizedAttributes;
109
+ let attributes: I3SMeshAttributes;
118
110
  let vertexCount: number;
119
111
  let byteOffset: number = 0;
120
112
  let featureCount: number = 0;
113
+ let indices: TypedArray | undefined;
121
114
 
122
115
  if (tile.isDracoGeometry) {
123
- const decompressedGeometry = await parse(arrayBuffer, DracoLoader, {
116
+ const decompressedGeometry: DracoMesh = await parse(arrayBuffer, DracoLoader, {
124
117
  draco: {
125
118
  attributeNameEntry: I3S_ATTRIBUTE_TYPE
126
119
  }
127
120
  });
128
-
121
+ // @ts-expect-error
129
122
  vertexCount = decompressedGeometry.header.vertexCount;
130
- const indices = decompressedGeometry.indices.value;
123
+ indices = decompressedGeometry.indices?.value;
131
124
  const {
132
125
  POSITION,
133
126
  NORMAL,
@@ -143,8 +136,7 @@ async function parseI3SNodeGeometry(arrayBuffer: ArrayBuffer, tile: Tile, option
143
136
  color: COLOR_0,
144
137
  uv0: TEXCOORD_0,
145
138
  uvRegion,
146
- id: featureIndex,
147
- indices
139
+ id: featureIndex
148
140
  };
149
141
 
150
142
  updateAttributesMetadata(attributes, decompressedGeometry);
@@ -155,10 +147,14 @@ async function parseI3SNodeGeometry(arrayBuffer: ArrayBuffer, tile: Tile, option
155
147
  flattenFeatureIdsByFeatureIndices(attributes, featureIds);
156
148
  }
157
149
  } else {
158
- const {vertexAttributes, attributesOrder, featureAttributes, featureAttributeOrder} =
159
- content.featureData;
150
+ const {
151
+ vertexAttributes,
152
+ ordering: attributesOrder,
153
+ featureAttributes,
154
+ featureAttributeOrder
155
+ } = tileset.store.defaultGeometrySchema;
160
156
  // First 8 bytes reserved for header (vertexCount and featureCount)
161
- const headers = parseHeaders(content, arrayBuffer);
157
+ const headers = parseHeaders(tileset, arrayBuffer);
162
158
  byteOffset = headers.byteOffset;
163
159
  vertexCount = headers.vertexCount;
164
160
  featureCount = headers.featureCount;
@@ -168,7 +164,6 @@ async function parseI3SNodeGeometry(arrayBuffer: ArrayBuffer, tile: Tile, option
168
164
  byteOffset,
169
165
  vertexAttributes,
170
166
  vertexCount,
171
- // @ts-expect-error
172
167
  attributesOrder
173
168
  );
174
169
 
@@ -204,7 +199,7 @@ async function parseI3SNodeGeometry(arrayBuffer: ArrayBuffer, tile: Tile, option
204
199
  texCoords: attributes.uv0,
205
200
  uvRegions: normalizeAttribute(attributes.uvRegion) // Normalize from UInt16
206
201
  };
207
- content.indices = attributes.indices || null;
202
+ content.indices = indices || null;
208
203
 
209
204
  if (attributes.id && attributes.id.value) {
210
205
  tile.content.featureIds = attributes.id.value;
@@ -228,7 +223,10 @@ async function parseI3SNodeGeometry(arrayBuffer: ArrayBuffer, tile: Tile, option
228
223
  * @param decompressedGeometry
229
224
  * @param attributes
230
225
  */
231
- function updateAttributesMetadata(attributes: NormalizedAttributes, decompressedGeometry): void {
226
+ function updateAttributesMetadata(
227
+ attributes: I3SMeshAttributes,
228
+ decompressedGeometry: DracoMesh
229
+ ): void {
232
230
  for (const key in decompressedGeometry.loaderData.attributes) {
233
231
  const dracoAttribute = decompressedGeometry.loaderData.attributes[key];
234
232
 
@@ -253,9 +251,9 @@ function updateAttributesMetadata(attributes: NormalizedAttributes, decompressed
253
251
  * @returns - result of attributes concatenation.
254
252
  */
255
253
  function concatAttributes(
256
- normalizedVertexAttributes: NormalizedAttributes,
257
- normalizedFeatureAttributes: NormalizedAttributes
258
- ): NormalizedAttributes {
254
+ normalizedVertexAttributes: I3SMeshAttributes,
255
+ normalizedFeatureAttributes: I3SMeshAttributes
256
+ ): I3SMeshAttributes {
259
257
  return {...normalizedVertexAttributes, ...normalizedFeatureAttributes};
260
258
  }
261
259
 
@@ -264,7 +262,7 @@ function concatAttributes(
264
262
  * @param attribute - geometry attribute
265
263
  * @returns - geometry attribute in right format
266
264
  */
267
- function normalizeAttribute(attribute: NormalizedAttribute): NormalizedAttribute {
265
+ function normalizeAttribute(attribute: I3SMeshAttribute): I3SMeshAttribute {
268
266
  if (!attribute) {
269
267
  return attribute;
270
268
  }
@@ -272,49 +270,26 @@ function normalizeAttribute(attribute: NormalizedAttribute): NormalizedAttribute
272
270
  return attribute;
273
271
  }
274
272
 
275
- function constructFeatureDataStruct(tileset: Tileset) {
276
- // seed featureData from defaultGeometrySchema
277
- const defaultGeometrySchema = tileset.store.defaultGeometrySchema;
278
- const featureData = defaultGeometrySchema;
279
- // populate the vertex attributes value types and values per element
280
- for (const geometryAttribute in I3S_NAMED_GEOMETRY_ATTRIBUTES) {
281
- for (const namedAttribute in I3S_NAMED_VERTEX_ATTRIBUTES) {
282
- const attribute = defaultGeometrySchema[geometryAttribute][namedAttribute];
283
- if (attribute) {
284
- const {byteOffset = 0, count = 0, valueType, valuesPerElement} = attribute;
285
-
286
- featureData[geometryAttribute][namedAttribute] = {
287
- valueType,
288
- valuesPerElement,
289
- byteOffset,
290
- count
291
- };
292
- }
293
- }
294
- }
295
-
296
- featureData.attributesOrder = defaultGeometrySchema.ordering;
297
- return featureData;
298
- }
299
-
300
- function parseHeaders(content: TileContent, arrayBuffer: ArrayBuffer) {
273
+ function parseHeaders(tileset: I3STilesetHeader, arrayBuffer: ArrayBuffer) {
301
274
  let byteOffset = 0;
302
275
  // First 8 bytes reserved for header (vertexCount and featurecount)
303
276
  let vertexCount = 0;
304
277
  let featureCount = 0;
305
- content.featureData.header.forEach(({property, type}) => {
278
+ for (const {property, type} of tileset.store.defaultGeometrySchema.header) {
306
279
  const TypedArrayTypeHeader = getConstructorForDataFormat(type);
307
- if (property === I3S_NAMED_HEADER_ATTRIBUTES.vertexCount) {
308
- // @ts-expect-error
309
- vertexCount = new TypedArrayTypeHeader(arrayBuffer, 0, 4)[0];
310
- byteOffset += sizeOf(type);
311
- }
312
- if (property === I3S_NAMED_HEADER_ATTRIBUTES.featureCount) {
313
- // @ts-expect-error
314
- featureCount = new TypedArrayTypeHeader(arrayBuffer, 4, 4)[0];
315
- byteOffset += sizeOf(type);
280
+ switch (property) {
281
+ case HeaderAttributeProperty.vertexCount:
282
+ vertexCount = new TypedArrayTypeHeader(arrayBuffer, 0, 4)[0];
283
+ byteOffset += sizeOf(type);
284
+ break;
285
+ case HeaderAttributeProperty.featureCount:
286
+ featureCount = new TypedArrayTypeHeader(arrayBuffer, 4, 4)[0];
287
+ byteOffset += sizeOf(type);
288
+ break;
289
+ default:
290
+ break;
316
291
  }
317
- });
292
+ }
318
293
 
319
294
  return {
320
295
  vertexCount,
@@ -332,7 +307,7 @@ function normalizeAttributes(
332
307
  vertexCount: number,
333
308
  attributesOrder: string[]
334
309
  ) {
335
- const attributes: NormalizedAttributes = {};
310
+ const attributes: I3SMeshAttributes = {};
336
311
 
337
312
  // the order of attributes depend on the order being added to the vertexAttributes object
338
313
  for (const attribute of attributesOrder) {
@@ -351,13 +326,12 @@ function normalizeAttributes(
351
326
  break;
352
327
  }
353
328
  const buffer = arrayBuffer.slice(byteOffset);
354
- let value: number[] | TypedArray = [];
329
+ let value: TypedArray;
355
330
 
356
331
  if (valueType === 'UInt64') {
357
332
  value = parseUint64Values(buffer, count * valuesPerElement, sizeOf(valueType));
358
333
  } else {
359
334
  const TypedArrayType = getConstructorForDataFormat(valueType);
360
- // @ts-expect-error
361
335
  value = new TypedArrayType(buffer, 0, count * valuesPerElement);
362
336
  }
363
337
 
@@ -395,7 +369,7 @@ function parseUint64Values(
395
369
  buffer: ArrayBuffer,
396
370
  elementsCount: number,
397
371
  attributeSize: number
398
- ): number[] {
372
+ ): Uint32Array {
399
373
  const values: number[] = [];
400
374
  const dataView = new DataView(buffer);
401
375
  let offset = 0;
@@ -411,10 +385,10 @@ function parseUint64Values(
411
385
  offset += attributeSize;
412
386
  }
413
387
 
414
- return values;
388
+ return new Uint32Array(values);
415
389
  }
416
390
 
417
- function parsePositions(attribute: NormalizedAttribute, tile: Tile): Matrix4 {
391
+ function parsePositions(attribute: I3SMeshAttribute, tile: I3STileHeader): Matrix4 {
418
392
  const mbs = tile.mbs;
419
393
  const value = attribute.value;
420
394
  const metadata = attribute.metadata;
@@ -466,7 +440,7 @@ function offsetsToCartesians(
466
440
  * @param positions positions attribute
467
441
  * @returns Matrix4 - model matrix for geometry transformation
468
442
  */
469
- function getModelMatrix(positions: NormalizedAttribute): Matrix4 {
443
+ function getModelMatrix(positions: I3SMeshAttribute): Matrix4 {
470
444
  const metadata = positions.metadata;
471
445
  const scaleX: number = metadata?.['i3s-scale_x']?.double || 1;
472
446
  const scaleY: number = metadata?.['i3s-scale_y']?.double || 1;
@@ -483,7 +457,7 @@ function getModelMatrix(positions: NormalizedAttribute): Matrix4 {
483
457
  * @param texture - texture image
484
458
  * @returns {object}
485
459
  */
486
- function makePbrMaterial(materialDefinition: GLTFMaterial, texture: TileContentTexture) {
460
+ function makePbrMaterial(materialDefinition?: I3SMaterialDefinition, texture?: TileContentTexture) {
487
461
  let pbrMaterial;
488
462
  if (materialDefinition) {
489
463
  pbrMaterial = {
@@ -521,7 +495,9 @@ function makePbrMaterial(materialDefinition: GLTFMaterial, texture: TileContentT
521
495
  );
522
496
  }
523
497
 
524
- setMaterialTexture(pbrMaterial, texture);
498
+ if (texture) {
499
+ setMaterialTexture(pbrMaterial, texture);
500
+ }
525
501
 
526
502
  return pbrMaterial;
527
503
  }
@@ -576,7 +552,7 @@ function setMaterialTexture(material, image: TileContentTexture): void {
576
552
  * @param normalizedFeatureAttributes
577
553
  * @returns
578
554
  */
579
- function flattenFeatureIdsByFaceRanges(normalizedFeatureAttributes: NormalizedAttributes): void {
555
+ function flattenFeatureIdsByFaceRanges(normalizedFeatureAttributes: I3SMeshAttributes): void {
580
556
  const {id, faceRange} = normalizedFeatureAttributes;
581
557
 
582
558
  if (!id || !faceRange) {
@@ -614,7 +590,7 @@ function flattenFeatureIdsByFaceRanges(normalizedFeatureAttributes: NormalizedAt
614
590
  * @returns
615
591
  */
616
592
  function flattenFeatureIdsByFeatureIndices(
617
- attributes: NormalizedAttributes,
593
+ attributes: I3SMeshAttributes,
618
594
  featureIds: Int32Array
619
595
  ): void {
620
596
  const featureIndices = attributes.id.value;
@@ -633,12 +609,7 @@ function flattenFeatureIdsByFeatureIndices(
633
609
  * @returns
634
610
  */
635
611
  function getFeatureIdsFromFeatureIndexMetadata(
636
- featureIndex: NormalizedAttribute
612
+ featureIndex: I3SMeshAttribute
637
613
  ): Int32Array | undefined {
638
- return (
639
- featureIndex &&
640
- featureIndex.metadata &&
641
- featureIndex.metadata['i3s-feature-ids'] &&
642
- featureIndex.metadata['i3s-feature-ids'].intArray
643
- );
614
+ return featureIndex?.metadata?.['i3s-feature-ids']?.intArray;
644
615
  }
@@ -4,69 +4,80 @@ import {load} from '@loaders.gl/core';
4
4
  import {TILE_TYPE, TILE_REFINEMENT, TILESET_TYPE} from '@loaders.gl/tiles';
5
5
  import I3SNodePagesTiles from '../helpers/i3s-nodepages-tiles';
6
6
  import {generateTileAttributeUrls, getUrlWithToken} from '../utils/url-utils';
7
+ import {
8
+ I3STilesetHeader,
9
+ I3STileHeader,
10
+ Mbs,
11
+ I3SMinimalNodeData,
12
+ Node3DIndexDocument
13
+ } from '../../types';
14
+ import type {LoaderOptions, LoaderContext} from '@loaders.gl/loader-utils';
7
15
 
8
- export function normalizeTileData(tile, options, context) {
9
- tile.url = context.url;
10
-
11
- if (tile.featureData) {
12
- tile.featureUrl = `${tile.url}/${tile.featureData[0].href}`;
13
- }
14
-
16
+ export function normalizeTileData(tile : Node3DIndexDocument, options : LoaderOptions, context: LoaderContext): I3STileHeader {
17
+ const url: string = context.url || '';
18
+ let contentUrl: string | undefined;
15
19
  if (tile.geometryData) {
16
- tile.contentUrl = `${tile.url}/${tile.geometryData[0].href}`;
20
+ contentUrl = `${url}/${tile.geometryData[0].href}`;
17
21
  }
18
22
 
23
+ let textureUrl: string | undefined;
19
24
  if (tile.textureData) {
20
- tile.textureUrl = `${tile.url}/${tile.textureData[0].href}`;
25
+ textureUrl = `${url}/${tile.textureData[0].href}`;
21
26
  }
22
27
 
28
+ let attributeUrls: string[] | undefined;
23
29
  if (tile.attributeData) {
24
- tile.attributeUrls = generateTileAttributeUrls(tile);
30
+ attributeUrls = generateTileAttributeUrls(url, tile);
25
31
  }
26
32
 
27
- return normalizeTileNonUrlData(tile);
33
+ return normalizeTileNonUrlData({
34
+ ...tile,
35
+ url,
36
+ contentUrl,
37
+ textureUrl,
38
+ attributeUrls,
39
+ isDracoGeometry: false
40
+ });
28
41
  }
29
42
 
30
- export function normalizeTileNonUrlData(tile) {
31
- const box = tile.obb
32
- ? [
33
- ...Ellipsoid.WGS84.cartographicToCartesian(tile.obb.center), // cartesian center of box
34
- ...tile.obb.halfSize, // halfSize
35
- ...tile.obb.quaternion // quaternion
36
- ]
37
- : undefined;
38
- let sphere;
43
+ export function normalizeTileNonUrlData(tile : I3SMinimalNodeData): I3STileHeader {
44
+ const boundingVolume: {box?: number[]; sphere?: number[]} = {};
45
+ let mbs: Mbs = [0, 0, 0, 1];
39
46
  if (tile.mbs) {
40
- sphere = [
47
+ mbs = tile.mbs;
48
+ boundingVolume.sphere = [
41
49
  ...Ellipsoid.WGS84.cartographicToCartesian(tile.mbs.slice(0, 3)), // cartesian center of sphere
42
50
  tile.mbs[3] // radius of sphere
51
+ ] as Mbs;
52
+ } else if (tile.obb) {
53
+ boundingVolume.box = [
54
+ ...Ellipsoid.WGS84.cartographicToCartesian(tile.obb.center), // cartesian center of box
55
+ ...tile.obb.halfSize, // halfSize
56
+ ...tile.obb.quaternion // quaternion
43
57
  ];
44
- } else if (box) {
45
58
  const obb = new OrientedBoundingBox().fromCenterHalfSizeQuaternion(
46
- box.slice(0, 3),
59
+ boundingVolume.box.slice(0, 3),
47
60
  tile.obb.halfSize,
48
61
  tile.obb.quaternion
49
62
  );
50
63
  const boundingSphere = obb.getBoundingSphere();
51
- sphere = [...boundingSphere.center, boundingSphere.radius];
52
- tile.mbs = [...tile.obb.center, boundingSphere.radius];
64
+ boundingVolume.sphere = [...boundingSphere.center , boundingSphere.radius] as Mbs;
65
+ mbs = [...tile.obb.center, boundingSphere.radius] as Mbs;
53
66
  }
54
67
 
55
- tile.boundingVolume = {
56
- sphere,
57
- box
58
- };
59
- tile.lodMetricType = tile.lodSelection[0].metricType;
60
- tile.lodMetricValue = tile.lodSelection[0].maxError;
61
- tile.transformMatrix = tile.transform;
62
- tile.type = TILE_TYPE.MESH;
63
- // TODO only support replacement for now
64
- tile.refine = TILE_REFINEMENT.REPLACE;
68
+ const lodMetricType = tile.lodSelection?.[0].metricType;
69
+ const lodMetricValue = tile.lodSelection?.[0].maxError;
70
+ const transformMatrix = tile.transform;
71
+ const type = TILE_TYPE.MESH;
72
+ /**
73
+ * I3S specification supports only REPLACE
74
+ */
75
+ const refine = TILE_REFINEMENT.REPLACE;
65
76
 
66
- return tile;
77
+ return {...tile, mbs, boundingVolume, lodMetricType, lodMetricValue, transformMatrix, type, refine};
67
78
  }
68
79
 
69
- export async function normalizeTilesetData(tileset, options, context) {
80
+ export async function normalizeTilesetData(tileset : I3STilesetHeader, options : LoaderOptions, context: LoaderContext) {
70
81
  tileset.url = context.url;
71
82
 
72
83
  if (tileset.nodePages) {
@@ -1,12 +1,12 @@
1
- import {Tile} from '../../types';
1
+ import {Node3DIndexDocument} from '../../types';
2
2
 
3
3
  /**
4
4
  * Generates url with token if it is exists.
5
- * @param {String} url
6
- * @param {any} token
7
- * @returns {string}
5
+ * @param url
6
+ * @param token
7
+ * @returns
8
8
  */
9
- export function getUrlWithToken(url: string, token = null): string {
9
+ export function getUrlWithToken(url: string, token: string | null = null): string {
10
10
  return token ? `${url}?token=${token}` : url;
11
11
  }
12
12
 
@@ -15,8 +15,8 @@ export function getUrlWithToken(url: string, token = null): string {
15
15
  * @param tile
16
16
  * @returns list of attribute urls
17
17
  */
18
- export function generateTileAttributeUrls(tile: Tile): string[] {
19
- const {url, attributeData} = tile;
18
+ export function generateTileAttributeUrls(url: string, tile: Node3DIndexDocument): string[] {
19
+ const {attributeData = []} = tile;
20
20
  const attributeUrls: string[] = [];
21
21
 
22
22
  for (let index = 0; index < attributeData.length; index++) {