@loaders.gl/tile-converter 4.0.0-alpha.16 → 4.0.0-alpha.18

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 (48) hide show
  1. package/bin/converter.js +1 -1
  2. package/dist/3d-tiles-converter/3d-tiles-converter.d.ts +5 -4
  3. package/dist/3d-tiles-converter/3d-tiles-converter.d.ts.map +1 -1
  4. package/dist/3d-tiles-converter/3d-tiles-converter.js +39 -37
  5. package/dist/3d-tiles-converter/helpers/b3dm-converter.d.ts +3 -1
  6. package/dist/3d-tiles-converter/helpers/b3dm-converter.d.ts.map +1 -1
  7. package/dist/3d-tiles-converter/helpers/b3dm-converter.js +4 -2
  8. package/dist/3d-tiles-converter/helpers/load-i3s.d.ts +10 -0
  9. package/dist/3d-tiles-converter/helpers/load-i3s.d.ts.map +1 -0
  10. package/dist/3d-tiles-converter/helpers/load-i3s.js +42 -0
  11. package/dist/3d-tiles-converter/helpers/texture-atlas.d.ts +2 -1
  12. package/dist/3d-tiles-converter/helpers/texture-atlas.d.ts.map +1 -1
  13. package/dist/3d-tiles-converter/helpers/texture-atlas.js +2 -0
  14. package/dist/converter.min.js +79 -79
  15. package/dist/dist.min.js +753 -3022
  16. package/dist/es5/3d-tiles-converter/3d-tiles-converter.js +94 -81
  17. package/dist/es5/3d-tiles-converter/3d-tiles-converter.js.map +1 -1
  18. package/dist/es5/3d-tiles-converter/helpers/b3dm-converter.js +6 -4
  19. package/dist/es5/3d-tiles-converter/helpers/b3dm-converter.js.map +1 -1
  20. package/dist/es5/3d-tiles-converter/helpers/load-i3s.js +63 -0
  21. package/dist/es5/3d-tiles-converter/helpers/load-i3s.js.map +1 -0
  22. package/dist/es5/3d-tiles-converter/helpers/texture-atlas.js.map +1 -1
  23. package/dist/es5/deps-installer/deps-installer.js +1 -1
  24. package/dist/es5/lib/utils/lod-conversion-utils.js +10 -4
  25. package/dist/es5/lib/utils/lod-conversion-utils.js.map +1 -1
  26. package/dist/es5/pgm-loader.js +1 -1
  27. package/dist/esm/3d-tiles-converter/3d-tiles-converter.js +46 -43
  28. package/dist/esm/3d-tiles-converter/3d-tiles-converter.js.map +1 -1
  29. package/dist/esm/3d-tiles-converter/helpers/b3dm-converter.js +4 -3
  30. package/dist/esm/3d-tiles-converter/helpers/b3dm-converter.js.map +1 -1
  31. package/dist/esm/3d-tiles-converter/helpers/load-i3s.js +32 -0
  32. package/dist/esm/3d-tiles-converter/helpers/load-i3s.js.map +1 -0
  33. package/dist/esm/3d-tiles-converter/helpers/texture-atlas.js.map +1 -1
  34. package/dist/esm/deps-installer/deps-installer.js +1 -1
  35. package/dist/esm/i3s-server/bin/i3s-server.min.js +72 -72
  36. package/dist/esm/lib/utils/lod-conversion-utils.js +6 -4
  37. package/dist/esm/lib/utils/lod-conversion-utils.js.map +1 -1
  38. package/dist/esm/pgm-loader.js +1 -1
  39. package/dist/lib/utils/lod-conversion-utils.d.ts +2 -2
  40. package/dist/lib/utils/lod-conversion-utils.d.ts.map +1 -1
  41. package/dist/lib/utils/lod-conversion-utils.js +4 -4
  42. package/dist/slpk-extractor.min.js +38 -38
  43. package/package.json +14 -14
  44. package/src/3d-tiles-converter/3d-tiles-converter.ts +60 -46
  45. package/src/3d-tiles-converter/helpers/b3dm-converter.ts +11 -10
  46. package/src/3d-tiles-converter/helpers/load-i3s.ts +51 -0
  47. package/src/3d-tiles-converter/helpers/texture-atlas.ts +6 -2
  48. package/src/lib/utils/lod-conversion-utils.ts +10 -6
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@loaders.gl/tile-converter",
3
- "version": "4.0.0-alpha.16",
3
+ "version": "4.0.0-alpha.18",
4
4
  "description": "Converter",
5
5
  "license": "MIT",
6
6
  "publishConfig": {
@@ -45,18 +45,18 @@
45
45
  "build-i3s-server-bundle": "esbuild src/i3s-server/bin/www.ts --outfile=dist/esm/i3s-server/bin/i3s-server.min.js --platform=node --target=esnext,node14 --external:join-images --minify --bundle --define:__VERSION__=\\\"$npm_package_version\\\""
46
46
  },
47
47
  "dependencies": {
48
- "@loaders.gl/3d-tiles": "4.0.0-alpha.16",
49
- "@loaders.gl/crypto": "4.0.0-alpha.16",
50
- "@loaders.gl/draco": "4.0.0-alpha.16",
51
- "@loaders.gl/gltf": "4.0.0-alpha.16",
52
- "@loaders.gl/i3s": "4.0.0-alpha.16",
53
- "@loaders.gl/images": "4.0.0-alpha.16",
54
- "@loaders.gl/loader-utils": "4.0.0-alpha.16",
55
- "@loaders.gl/polyfills": "4.0.0-alpha.16",
56
- "@loaders.gl/textures": "4.0.0-alpha.16",
57
- "@loaders.gl/tiles": "4.0.0-alpha.16",
58
- "@loaders.gl/worker-utils": "4.0.0-alpha.16",
59
- "@loaders.gl/zip": "4.0.0-alpha.16",
48
+ "@loaders.gl/3d-tiles": "4.0.0-alpha.18",
49
+ "@loaders.gl/crypto": "4.0.0-alpha.18",
50
+ "@loaders.gl/draco": "4.0.0-alpha.18",
51
+ "@loaders.gl/gltf": "4.0.0-alpha.18",
52
+ "@loaders.gl/i3s": "4.0.0-alpha.18",
53
+ "@loaders.gl/images": "4.0.0-alpha.18",
54
+ "@loaders.gl/loader-utils": "4.0.0-alpha.18",
55
+ "@loaders.gl/polyfills": "4.0.0-alpha.18",
56
+ "@loaders.gl/textures": "4.0.0-alpha.18",
57
+ "@loaders.gl/tiles": "4.0.0-alpha.18",
58
+ "@loaders.gl/worker-utils": "4.0.0-alpha.18",
59
+ "@loaders.gl/zip": "4.0.0-alpha.18",
60
60
  "@math.gl/core": "^3.5.1",
61
61
  "@math.gl/culling": "^3.5.1",
62
62
  "@math.gl/geoid": "^3.5.1",
@@ -79,7 +79,7 @@
79
79
  "join-images": "^1.1.3",
80
80
  "sharp": "^0.31.3"
81
81
  },
82
- "gitHead": "87e9714165c3ce143a04ac45bbd9d922006f1b63",
82
+ "gitHead": "7bc633f46560f661bdd46cf1015ea27b3694ebce",
83
83
  "devDependencies": {
84
84
  "@types/express": "^4.17.17",
85
85
  "@types/node": "^20.4.2"
@@ -1,4 +1,9 @@
1
- import type {AttributeStorageInfo, FeatureAttribute, NodeReference} from '@loaders.gl/i3s';
1
+ import type {
2
+ AttributeStorageInfo,
3
+ FeatureAttribute,
4
+ NodeReference,
5
+ I3STilesetHeader
6
+ } from '@loaders.gl/i3s';
2
7
  import type {Tiles3DTileJSON} from '@loaders.gl/3d-tiles';
3
8
 
4
9
  import {join} from 'path';
@@ -6,7 +11,6 @@ import process from 'process';
6
11
  import transform from 'json-map-transform';
7
12
  import {load, isBrowser} from '@loaders.gl/core';
8
13
  import {I3SLoader, I3SAttributeLoader, COORDINATE_SYSTEM} from '@loaders.gl/i3s';
9
- import {Tileset3D, Tile3D} from '@loaders.gl/tiles';
10
14
  import {Geoid} from '@math.gl/geoid';
11
15
 
12
16
  import {PGMLoader} from '../pgm-loader';
@@ -19,6 +23,9 @@ import {createObbFromMbs} from '../i3s-converter/helpers/coordinate-converter';
19
23
  import {WorkerFarm} from '@loaders.gl/worker-utils';
20
24
  import {BROWSER_ERROR_MESSAGE} from '../constants';
21
25
  import B3dmConverter, {I3SAttributesData} from './helpers/b3dm-converter';
26
+ import {I3STileHeader} from '@loaders.gl/i3s/src/types';
27
+ import {loadI3SContent} from './helpers/load-i3s';
28
+ import {I3SLoaderOptions} from '@loaders.gl/i3s/src/i3s-loader';
22
29
 
23
30
  const I3S = 'I3S';
24
31
 
@@ -31,9 +38,18 @@ export default class Tiles3DConverter {
31
38
  vertexCounter: number;
32
39
  conversionStartTime: [number, number];
33
40
  geoidHeightModel: Geoid | null;
34
- sourceTileset: Tileset3D | null;
35
- attributeStorageInfo: AttributeStorageInfo | null;
41
+ sourceTileset: I3STilesetHeader | null;
42
+ attributeStorageInfo?: AttributeStorageInfo[] | null;
36
43
  workerSource: {[key: string]: string} = {};
44
+ loaderOptions: I3SLoaderOptions = {
45
+ _nodeWorkers: true,
46
+ reuseWorkers: true,
47
+ i3s: {coordinateSystem: COORDINATE_SYSTEM.LNGLAT_OFFSETS, decodeTextures: false},
48
+ // We need to load local fs workers because nodejs can't load workers from the Internet
49
+ 'i3s-content': {
50
+ workerUrl: './modules/i3s/dist/i3s-content-worker-node.js'
51
+ }
52
+ };
37
53
 
38
54
  constructor() {
39
55
  this.options = {};
@@ -74,28 +90,19 @@ export default class Tiles3DConverter {
74
90
  this.geoidHeightModel = await load(egmFilePath, PGMLoader);
75
91
  console.log('Loading egm file completed!'); // eslint-disable-line
76
92
 
77
- const sourceTilesetJson = await load(inputUrl, I3SLoader, {});
93
+ this.sourceTileset = await load(inputUrl, I3SLoader, this.loaderOptions);
78
94
 
79
- this.sourceTileset = new Tileset3D(sourceTilesetJson, {
80
- loadOptions: {
81
- _nodeWorkers: true,
82
- reuseWorkers: true,
83
- i3s: {coordinateSystem: COORDINATE_SYSTEM.LNGLAT_OFFSETS, decodeTextures: false},
84
- // We need to load local fs workers because nodejs can't load workers from the Internet
85
- 'i3s-content': {
86
- workerUrl: './modules/i3s/dist/i3s-content-worker-node.js'
87
- }
88
- }
89
- });
95
+ if (!this.sourceTileset) {
96
+ return;
97
+ }
90
98
 
91
- await this.sourceTileset.tilesetInitializationPromise;
92
- const rootNode = this.sourceTileset.root!;
93
- if (!rootNode.header.obb) {
94
- rootNode.header.obb = createObbFromMbs(rootNode.header.mbs);
99
+ const rootNode = this.sourceTileset?.root;
100
+ if (!rootNode.obb) {
101
+ rootNode.obb = createObbFromMbs(rootNode.mbs);
95
102
  }
96
103
 
97
104
  this.tilesetPath = join(`${outputPath}`, `${tilesetName}`);
98
- this.attributeStorageInfo = sourceTilesetJson.attributeStorageInfo;
105
+ this.attributeStorageInfo = this.sourceTileset.attributeStorageInfo;
99
106
  // Removing the tilesetPath needed to exclude erroneous files after conversion
100
107
  try {
101
108
  await removeDir(this.tilesetPath);
@@ -105,7 +112,7 @@ export default class Tiles3DConverter {
105
112
 
106
113
  const rootTile: Tiles3DTileJSON = {
107
114
  boundingVolume: {
108
- box: i3sObbTo3dTilesObb(rootNode.header.obb, this.geoidHeightModel)
115
+ box: i3sObbTo3dTilesObb(rootNode.obb, this.geoidHeightModel)
109
116
  },
110
117
  geometricError: convertScreenThresholdToGeometricError(rootNode),
111
118
  children: []
@@ -131,28 +138,33 @@ export default class Tiles3DConverter {
131
138
  * @param childNodeInfo child node to convert
132
139
  */
133
140
  private async convertChildNode(
134
- parentSourceNode: Tile3D,
141
+ parentSourceNode: I3STileHeader,
135
142
  parentNode: Tiles3DTileJSON,
136
143
  level: number,
137
144
  childNodeInfo: NodeReference
138
145
  ): Promise<void> {
139
146
  const sourceChild = await this._loadChildNode(parentSourceNode, childNodeInfo);
140
- parentSourceNode.children.push(sourceChild);
141
147
  if (sourceChild.contentUrl) {
142
- await this.sourceTileset!._loadTile(sourceChild);
143
- this.vertexCounter += sourceChild.content.vertexCount;
148
+ const content = await loadI3SContent(this.sourceTileset, sourceChild, this.loaderOptions);
149
+
150
+ if (!content) {
151
+ await this._addChildren(sourceChild, parentNode, level + 1);
152
+ return;
153
+ }
154
+
155
+ this.vertexCounter += content?.vertexCount || 0;
144
156
 
145
157
  let featureAttributes: FeatureAttribute | null = null;
146
158
  if (this.attributeStorageInfo) {
147
159
  featureAttributes = await this._loadChildAttributes(sourceChild, this.attributeStorageInfo);
148
160
  }
149
161
 
150
- if (!sourceChild.header.obb) {
151
- sourceChild.header.obb = createObbFromMbs(sourceChild.header.mbs);
162
+ if (!sourceChild.obb) {
163
+ sourceChild.obb = createObbFromMbs(sourceChild.mbs);
152
164
  }
153
165
 
154
166
  const boundingVolume = {
155
- box: i3sObbTo3dTilesObb(sourceChild.header.obb, this.geoidHeightModel)
167
+ box: i3sObbTo3dTilesObb(sourceChild.obb, this.geoidHeightModel)
156
168
  };
157
169
  const child: Tiles3DTileJSON = {
158
170
  boundingVolume,
@@ -161,8 +173,9 @@ export default class Tiles3DConverter {
161
173
  };
162
174
 
163
175
  const i3sAttributesData: I3SAttributesData = {
164
- tileContent: sourceChild.content,
165
- textureFormat: sourceChild?.header?.textureFormat
176
+ tileContent: content,
177
+ box: boundingVolume.box,
178
+ textureFormat: sourceChild.textureFormat
166
179
  };
167
180
 
168
181
  const b3dmConverter = new B3dmConverter();
@@ -175,7 +188,6 @@ export default class Tiles3DConverter {
175
188
  await writeFile(this.tilesetPath, new Uint8Array(b3dm), `${sourceChild.id}.b3dm`);
176
189
  parentNode.children.push(child);
177
190
 
178
- sourceChild.unloadContent();
179
191
  await this._addChildren(sourceChild, child, level + 1);
180
192
  } else {
181
193
  await this._addChildren(sourceChild, parentNode, level + 1);
@@ -189,7 +201,7 @@ export default class Tiles3DConverter {
189
201
  * @param level a current level of a tree depth
190
202
  */
191
203
  private async _addChildren(
192
- parentSourceNode: Tile3D,
204
+ parentSourceNode: I3STileHeader,
193
205
  parentNode: Tiles3DTileJSON,
194
206
  level: number
195
207
  ): Promise<void> {
@@ -197,7 +209,7 @@ export default class Tiles3DConverter {
197
209
  return;
198
210
  }
199
211
  const promises: Promise<void>[] = [];
200
- for (const childNodeInfo of parentSourceNode.header.children || []) {
212
+ for (const childNodeInfo of parentSourceNode.children || []) {
201
213
  promises.push(this.convertChildNode(parentSourceNode, parentNode, level, childNodeInfo));
202
214
  }
203
215
  await Promise.all(promises);
@@ -209,29 +221,31 @@ export default class Tiles3DConverter {
209
221
  * @param childNodeInfo child information from 3DNodeIndexDocument
210
222
  * (https://github.com/Esri/i3s-spec/blob/master/docs/1.7/nodeReference.cmn.md)
211
223
  */
212
- private async _loadChildNode(parentNode: Tile3D, childNodeInfo: NodeReference): Promise<Tile3D> {
224
+ private async _loadChildNode(
225
+ parentNode: I3STileHeader,
226
+ childNodeInfo: NodeReference
227
+ ): Promise<I3STileHeader> {
213
228
  let header;
214
- if (this.sourceTileset!.tileset.nodePages) {
229
+ if (this.sourceTileset?.nodePagesTile) {
215
230
  console.log(`Node conversion: ${childNodeInfo.id}`); // eslint-disable-line no-console,no-undef
216
- header = await this.sourceTileset!.tileset.nodePagesTile.formTileFromNodePages(
217
- childNodeInfo.id
231
+ header = await this.sourceTileset.nodePagesTile.formTileFromNodePages(
232
+ parseInt(childNodeInfo.id)
218
233
  );
219
234
  } else {
220
- const {loader} = this.sourceTileset!;
221
235
  const nodeUrl = this._relativeUrlToFullUrl(parentNode.url, childNodeInfo.href!);
222
236
  // load metadata
223
237
  const options = {
224
238
  i3s: {
225
- ...this.sourceTileset!.loadOptions,
239
+ ...this.loaderOptions,
226
240
  isTileHeader: true,
227
241
  loadContent: false
228
242
  }
229
243
  };
230
244
 
231
245
  console.log(`Node conversion: ${nodeUrl}`); // eslint-disable-line no-console,no-undef
232
- header = await load(nodeUrl, loader, options);
246
+ header = await load(nodeUrl, I3SLoader, options);
233
247
  }
234
- return new Tile3D(this.sourceTileset!, header, parentNode);
248
+ return header;
235
249
  }
236
250
 
237
251
  /**
@@ -239,7 +253,7 @@ export default class Tiles3DConverter {
239
253
  * @param baseUrl the base url. A resulting url will be related from this url
240
254
  * @param relativeUrl a realtive url of a resource
241
255
  */
242
- private _relativeUrlToFullUrl(baseUrl: string, relativeUrl: string): string {
256
+ private _relativeUrlToFullUrl(baseUrl: string = '', relativeUrl: string): string {
243
257
  let resultArray = baseUrl.split('/');
244
258
  const relativeUrlArray = relativeUrl.split('/');
245
259
  for (const folder of relativeUrlArray) {
@@ -263,11 +277,11 @@ export default class Tiles3DConverter {
263
277
  * @returns Promise of attributes object.
264
278
  */
265
279
  private async _loadChildAttributes(
266
- sourceChild: Tile3D,
267
- attributeStorageInfo: AttributeStorageInfo
280
+ sourceChild: I3STileHeader,
281
+ attributeStorageInfo: AttributeStorageInfo[]
268
282
  ): Promise<FeatureAttribute> {
269
283
  const promises: any[] = [];
270
- const {attributeUrls} = sourceChild.header;
284
+ const {attributeUrls = []} = sourceChild;
271
285
 
272
286
  for (let index = 0; index < attributeUrls.length; index++) {
273
287
  const inputUrl = attributeUrls[index];
@@ -1,3 +1,4 @@
1
+ import type {I3STileContent} from '@loaders.gl/i3s';
1
2
  import {encodeSync} from '@loaders.gl/core';
2
3
  import {GLTFScenegraph, GLTFWriter} from '@loaders.gl/gltf';
3
4
  import {Tile3DWriter} from '@loaders.gl/3d-tiles';
@@ -10,7 +11,8 @@ const Z_UP_TO_Y_UP_MATRIX = new Matrix4([1, 0, 0, 0, 0, 0, -1, 0, 0, 1, 0, 0, 0,
10
11
  const scratchVector = new Vector3();
11
12
 
12
13
  export type I3SAttributesData = {
13
- tileContent: any;
14
+ tileContent: I3STileContent;
15
+ box: number[];
14
16
  textureFormat: string;
15
17
  };
16
18
 
@@ -53,15 +55,8 @@ export default class B3dmConverter {
53
55
  i3sAttributesData: I3SAttributesData,
54
56
  featureAttributes: any
55
57
  ): Promise<ArrayBuffer> {
56
- const {tileContent, textureFormat} = i3sAttributesData;
57
- const {
58
- material,
59
- attributes,
60
- indices: originalIndices,
61
- cartesianOrigin,
62
- cartographicOrigin,
63
- modelMatrix
64
- } = tileContent;
58
+ const {tileContent, textureFormat, box} = i3sAttributesData;
59
+ const {material, attributes, indices: originalIndices, modelMatrix} = tileContent;
65
60
  const gltfBuilder = new GLTFScenegraph();
66
61
 
67
62
  const textureIndex = await this._addI3sTextureToGltf(tileContent, textureFormat, gltfBuilder);
@@ -78,6 +73,12 @@ export default class B3dmConverter {
78
73
  );
79
74
  }
80
75
 
76
+ const cartesianOrigin = new Vector3(box);
77
+ const cartographicOrigin = Ellipsoid.WGS84.cartesianToCartographic(
78
+ cartesianOrigin,
79
+ new Vector3()
80
+ );
81
+
81
82
  attributes.positions.value = this._normalizePositions(
82
83
  positionsValue,
83
84
  cartesianOrigin,
@@ -0,0 +1,51 @@
1
+ import {load} from '@loaders.gl/core';
2
+ import {
3
+ I3STileContent,
4
+ I3STileHeader,
5
+ I3STilesetHeader,
6
+ I3SLoader,
7
+ I3SLoaderOptions
8
+ } from '@loaders.gl/i3s';
9
+
10
+ /**
11
+ * Load I3S node content
12
+ * @param sourceTileset - source layer JSON
13
+ * @param sourceTile - source I3S node metadata
14
+ * @param tilesetLoadOptions - load options for Tiles3DLoader
15
+ * @returns - 3DTiles tile content or null
16
+ */
17
+ export const loadI3SContent = async (
18
+ sourceTileset: I3STilesetHeader | null,
19
+ sourceTile: I3STileHeader,
20
+ tilesetLoadOptions: I3SLoaderOptions
21
+ ): Promise<I3STileContent | null> => {
22
+ if (!sourceTileset || !sourceTile.contentUrl) {
23
+ return null;
24
+ }
25
+
26
+ const loadOptions = {
27
+ ...tilesetLoadOptions,
28
+ i3s: {
29
+ ...tilesetLoadOptions.i3s,
30
+ isTileset: false,
31
+ isTileHeader: false,
32
+ _tileOptions: {
33
+ attributeUrls: sourceTile.attributeUrls,
34
+ textureUrl: sourceTile.textureUrl,
35
+ textureFormat: sourceTile.textureFormat,
36
+ textureLoaderOptions: sourceTile.textureLoaderOptions,
37
+ materialDefinition: sourceTile.materialDefinition,
38
+ isDracoGeometry: sourceTile.isDracoGeometry,
39
+ mbs: sourceTile.mbs
40
+ },
41
+ _tilesetOptions: {
42
+ store: sourceTileset.store,
43
+ attributeStorageInfo: sourceTileset.attributeStorageInfo,
44
+ fields: sourceTileset.fields
45
+ }
46
+ }
47
+ };
48
+ const tileContent = await load(sourceTile.contentUrl, I3SLoader, loadOptions);
49
+
50
+ return tileContent;
51
+ };
@@ -1,3 +1,5 @@
1
+ import type {TypedArray} from '@loaders.gl/loader-utils';
2
+
1
3
  /**
2
4
  * Apply uvRegions to texture coordinates.
3
5
  * Spec - https://github.com/Esri/i3s-spec/blob/master/docs/1.7/geometryUVRegion.cmn.md
@@ -5,7 +7,7 @@
5
7
  * @param texCoords
6
8
  * @param uvRegions
7
9
  */
8
- export function convertTextureAtlas(texCoords: Float32Array, uvRegions: Uint16Array): Float32Array {
10
+ export function convertTextureAtlas(texCoords: TypedArray, uvRegions: TypedArray): Float32Array {
9
11
  const convertedTexCoords = new Float32Array(texCoords.length);
10
12
  const normalisedRegions = normalizeRegions(uvRegions);
11
13
 
@@ -43,7 +45,9 @@ function fract(uv: [number, number]): [number, number] {
43
45
  * Normalize uvRegions by dividing by the maximum Uint16 value
44
46
  * @param regions
45
47
  */
46
- function normalizeRegions(regions: Uint16Array): number[] {
48
+ function normalizeRegions(regions: TypedArray): number[] {
49
+ // The code is for Uint16Array because it is the spec requirement
50
+ // https://github.com/Esri/i3s-spec/blob/master/docs/1.8/geometryUVRegion.cmn.md
47
51
  const MAX_UINT_16_VALUE = 65535;
48
52
  const normalizedRegions: number[] = [];
49
53
 
@@ -1,6 +1,6 @@
1
1
  import {Tiles3DTileJSONPostprocessed} from '@loaders.gl/3d-tiles';
2
2
  import {BoundingVolumes} from '@loaders.gl/i3s';
3
- import {Tile3D} from '@loaders.gl/tiles';
3
+ import {I3STileHeader} from '@loaders.gl/i3s/src/types';
4
4
 
5
5
  // https://cesium.com/docs/cesiumjs-ref-doc/Cesium3DTileset.html
6
6
  const DEFAULT_MAXIMUM_SCREEN_SPACE_ERROR = 16;
@@ -64,11 +64,15 @@ export function convertGeometricErrorToScreenThreshold(
64
64
  * @param node - i3s node data
65
65
  * @returns lod metric in 3d-tiles format
66
66
  */
67
- export function convertScreenThresholdToGeometricError(node: Tile3D): number {
68
- const metricData = node.header.lodSelection.maxScreenThreshold || {};
69
- let maxError = metricData.maxError;
67
+ export function convertScreenThresholdToGeometricError(node: I3STileHeader): number {
68
+ const metricData = node.lodSelection?.find(
69
+ (metric) => metric.metricType === 'maxScreenThreshold'
70
+ );
71
+ let maxError = metricData?.maxError;
70
72
  if (!maxError) {
71
- const sqMetricData = node.header.lodSelection.maxScreenThresholdSQ;
73
+ const sqMetricData = node.lodSelection?.find(
74
+ (metric) => metric.metricType === 'maxScreenThresholdSQ'
75
+ );
72
76
  if (sqMetricData) {
73
77
  maxError = Math.sqrt(sqMetricData.maxError / (Math.PI * 0.25));
74
78
  }
@@ -78,5 +82,5 @@ export function convertScreenThresholdToGeometricError(node: Tile3D): number {
78
82
  maxError = DEFAULT_MAXIMUM_SCREEN_SPACE_ERROR;
79
83
  }
80
84
 
81
- return (node.header.mbs[3] * 2 * DEFAULT_MAXIMUM_SCREEN_SPACE_ERROR) / maxError;
85
+ return (node.mbs[3] * 2 * DEFAULT_MAXIMUM_SCREEN_SPACE_ERROR) / maxError;
82
86
  }