@loaders.gl/tile-converter 5.0.0-alpha.11 → 5.0.0-alpha.14

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 (152) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +180 -4
  3. package/bin/converter-v5.js +2 -0
  4. package/dist/converter.min.cjs +172 -182
  5. package/dist/i3s-server/bin/i3s-server.min.cjs +113 -158
  6. package/dist/index.cjs +18832 -19228
  7. package/dist/index.js +19566 -19968
  8. package/dist/v5/adapters.cjs +2002 -230
  9. package/dist/v5/adapters.d.ts +20 -0
  10. package/dist/v5/adapters.js +2005 -214
  11. package/dist/v5/archive-source.d.ts +36 -0
  12. package/dist/v5/browser-tileset-source.d.ts +55 -11
  13. package/dist/v5/browser.cjs +18 -0
  14. package/dist/v5/browser.d.ts +15 -1
  15. package/dist/v5/browser.js +26 -0
  16. package/dist/v5/conversion-api.d.ts +34 -0
  17. package/dist/v5/converter-cli.d.ts +1 -0
  18. package/dist/v5/converter-cli.js +1230 -0
  19. package/dist/v5/core.cjs +547 -77
  20. package/dist/v5/core.d.ts +3 -1
  21. package/dist/v5/core.js +540 -70
  22. package/dist/v5/feature-arrow.d.ts +1 -1
  23. package/dist/v5/i3s-mesh-conversion.d.ts +5 -1
  24. package/dist/v5/i3s-mesh-source-features.d.ts +2 -2
  25. package/dist/v5/i3s-mesh-source-material.d.ts +1 -1
  26. package/dist/v5/i3s-mesh-source.d.ts +2 -2
  27. package/dist/v5/i3s-selection-source.d.ts +70 -0
  28. package/dist/v5/index.cjs +15 -0
  29. package/dist/v5/index.d.ts +13 -1
  30. package/dist/v5/index.js +22 -0
  31. package/dist/v5/mesh-conversion.d.ts +21 -3
  32. package/dist/v5/mesh-draco.d.ts +2 -2
  33. package/dist/v5/mesh-features.d.ts +2 -2
  34. package/dist/v5/mesh-hierarchy.d.ts +47 -0
  35. package/dist/v5/mesh-source-features.d.ts +6 -5
  36. package/dist/v5/mesh-source-schema.d.ts +12 -0
  37. package/dist/v5/mesh-source-texture.d.ts +3 -3
  38. package/dist/v5/mesh-source.d.ts +10 -7
  39. package/dist/v5/mesh-tileset-sink.d.ts +5 -0
  40. package/dist/v5/mesh.d.ts +1 -1
  41. package/dist/v5/node-cli.d.ts +9 -0
  42. package/dist/v5/node-conversion.d.ts +34 -0
  43. package/dist/v5/node-feature-schema.d.ts +3 -0
  44. package/dist/v5/node-i3s-source.d.ts +41 -0
  45. package/dist/v5/node-source.d.ts +47 -0
  46. package/dist/v5/node.cjs +913 -0
  47. package/dist/v5/node.d.ts +6 -0
  48. package/dist/v5/node.js +890 -0
  49. package/dist/v5/point-cloud-attributes.d.ts +19 -0
  50. package/dist/v5/point-cloud-conversion.d.ts +1 -1
  51. package/dist/v5/point-cloud-copc.d.ts +44 -0
  52. package/dist/v5/point-cloud-file.d.ts +83 -0
  53. package/dist/v5/point-cloud-potree.d.ts +47 -0
  54. package/dist/v5/point-cloud-source-encoder.d.ts +1 -1
  55. package/dist/v5/point-cloud-source.d.ts +1 -1
  56. package/dist/v5/point-cloud-tileset.d.ts +44 -0
  57. package/dist/v5/point-cloud.d.ts +1 -1
  58. package/dist/v5/resource-manifest.d.ts +10 -1
  59. package/dist/v5/selected-mesh-source.d.ts +53 -0
  60. package/dist/v5/spatial-conversion.d.ts +1 -1
  61. package/dist/v5/tileset-source.d.ts +1 -1
  62. package/package.json +25 -32
  63. package/src/index.ts +4 -1
  64. package/src/v4/3d-tiles-converter/3d-tiles-converter.ts +11 -12
  65. package/src/v4/3d-tiles-converter/helpers/3d-tiles-content-converter.ts +7 -3
  66. package/src/v4/3d-tiles-converter/helpers/i3s-obb-to-3d-tiles-obb.ts +2 -2
  67. package/src/v4/3d-tiles-converter/helpers/load-i3s.ts +4 -6
  68. package/src/v4/3d-tiles-converter/helpers/texture-atlas.ts +1 -1
  69. package/src/v4/3d-tiles-converter/helpers/validate-i3s-spatial-reference.ts +2 -2
  70. package/src/v4/3d-tiles-converter/json-templates/tileset.ts +58 -39
  71. package/src/v4/converter-cli.ts +10 -4
  72. package/src/v4/deps-installer/deps-installer.ts +3 -3
  73. package/src/v4/i3s-converter/helpers/attribute-metadata-info.ts +1 -1
  74. package/src/v4/i3s-converter/helpers/batch-ids-extensions.ts +9 -10
  75. package/src/v4/i3s-converter/helpers/conversion-gltf.ts +108 -0
  76. package/src/v4/i3s-converter/helpers/coordinate-converter.ts +6 -5
  77. package/src/v4/i3s-converter/helpers/create-scene-server-path.ts +5 -6
  78. package/src/v4/i3s-converter/helpers/feature-attributes.ts +4 -4
  79. package/src/v4/i3s-converter/helpers/geometry-attributes.ts +1 -1
  80. package/src/v4/i3s-converter/helpers/geometry-converter.ts +69 -77
  81. package/src/v4/i3s-converter/helpers/gltf-attributes.ts +58 -74
  82. package/src/v4/i3s-converter/helpers/load-3d-tiles.ts +6 -54
  83. package/src/v4/i3s-converter/helpers/node-debug.ts +7 -3
  84. package/src/v4/i3s-converter/helpers/node-index-document.ts +11 -9
  85. package/src/v4/i3s-converter/helpers/node-pages.ts +3 -4
  86. package/src/v4/i3s-converter/helpers/preprocess-3d-tiles.ts +2 -2
  87. package/src/v4/i3s-converter/helpers/tileset-traversal.ts +1 -1
  88. package/src/v4/i3s-converter/i3s-converter.ts +29 -31
  89. package/src/v4/i3s-converter/json-templates/geometry-definitions.ts +71 -66
  90. package/src/v4/i3s-converter/json-templates/layers.ts +97 -132
  91. package/src/v4/i3s-converter/json-templates/metadata.ts +31 -21
  92. package/src/v4/i3s-converter/json-templates/node.ts +60 -74
  93. package/src/v4/i3s-converter/json-templates/scene-server.ts +36 -27
  94. package/src/v4/i3s-converter/json-templates/shared-resources.ts +62 -123
  95. package/src/v4/i3s-converter/json-templates/store.ts +39 -57
  96. package/src/v4/i3s-converter/types.ts +4 -4
  97. package/src/v4/i3s-server/controllers/slpk-controller.ts +3 -3
  98. package/src/v4/i3s-server/utils/create-scene-server.ts +3 -3
  99. package/src/v4/lib/utils/builder-input.ts +8 -0
  100. package/src/v4/lib/utils/conversion-dump.ts +5 -1
  101. package/src/v4/lib/utils/file-utils.ts +1 -1
  102. package/src/v4/lib/utils/hash-string.ts +21 -0
  103. package/src/v4/lib/utils/lod-conversion-utils.ts +3 -3
  104. package/src/v4/pgm-loader.ts +2 -2
  105. package/src/v5/adapters.ts +53 -0
  106. package/src/v5/archive-source.ts +235 -0
  107. package/src/v5/browser-tileset-source.ts +418 -48
  108. package/src/v5/browser.ts +46 -0
  109. package/src/v5/conversion-api.ts +184 -17
  110. package/src/v5/conversion-archive.ts +2 -2
  111. package/src/v5/converter-cli.ts +28 -0
  112. package/src/v5/core.ts +7 -0
  113. package/src/v5/feature-arrow.ts +2 -2
  114. package/src/v5/i3s-mesh-conversion.ts +41 -3
  115. package/src/v5/i3s-mesh-sink.ts +1 -1
  116. package/src/v5/i3s-mesh-source-features.ts +3 -3
  117. package/src/v5/i3s-mesh-source-material.ts +18 -11
  118. package/src/v5/i3s-mesh-source.ts +3 -2
  119. package/src/v5/i3s-selection-source.ts +298 -0
  120. package/src/v5/index.ts +41 -0
  121. package/src/v5/mesh-conversion.ts +24 -4
  122. package/src/v5/mesh-draco.ts +2 -2
  123. package/src/v5/mesh-features.ts +3 -3
  124. package/src/v5/mesh-hierarchy.ts +648 -0
  125. package/src/v5/mesh-source-features.ts +165 -51
  126. package/src/v5/mesh-source-schema.ts +140 -0
  127. package/src/v5/mesh-source-texture.ts +49 -19
  128. package/src/v5/mesh-source.ts +80 -49
  129. package/src/v5/mesh-tileset-archive.ts +1 -1
  130. package/src/v5/mesh-tileset-sink.ts +2 -2
  131. package/src/v5/mesh.ts +1 -1
  132. package/src/v5/node-cli.ts +201 -0
  133. package/src/v5/node-conversion.ts +362 -0
  134. package/src/v5/node-feature-schema.ts +155 -0
  135. package/src/v5/node-i3s-source.ts +181 -0
  136. package/src/v5/node-source.ts +328 -0
  137. package/src/v5/node.ts +16 -0
  138. package/src/v5/point-cloud-attributes.ts +113 -0
  139. package/src/v5/point-cloud-conversion.ts +1 -1
  140. package/src/v5/point-cloud-copc.ts +289 -0
  141. package/src/v5/point-cloud-file.ts +306 -0
  142. package/src/v5/point-cloud-potree.ts +134 -0
  143. package/src/v5/point-cloud-source-encoder.ts +1 -1
  144. package/src/v5/point-cloud-source.ts +1 -1
  145. package/src/v5/point-cloud-spatial.ts +2 -2
  146. package/src/v5/point-cloud-tileset.ts +137 -0
  147. package/src/v5/point-cloud.ts +3 -3
  148. package/src/v5/resource-fetcher.ts +4 -1
  149. package/src/v5/resource-manifest.ts +40 -5
  150. package/src/v5/selected-mesh-source.ts +384 -0
  151. package/src/v5/spatial-conversion.ts +90 -19
  152. package/src/v5/tileset-source.ts +2 -2
@@ -1,5 +1,5 @@
1
1
  /* eslint-disable camelcase */
2
- import {Tiles3DTileContent} from '@loaders.gl/3d-tiles';
2
+ import {Tiles3DTileContent} from '@loaders.gl/tiles-3d/3d-tiles';
3
3
  import {GLTFPrimitiveModeString, PreprocessData} from '../types';
4
4
  import {
5
5
  EXT_STRUCTURAL_METADATA,
@@ -43,7 +43,7 @@ export const analyzeTileContent = async (
43
43
  }
44
44
 
45
45
  const gltfData = await parse(tileContent.gltfArrayBuffer, GLTFLoader, {
46
- gltf: {normalize: false, loadBuffers: false, loadImages: false, decompressMeshes: false}
46
+ gltf: {normalize: true, loadBuffers: false, loadImages: false, decompressMeshes: false}
47
47
  });
48
48
  const gltf = gltfData.json;
49
49
 
@@ -1,4 +1,4 @@
1
- import {Tiles3DTileJSONPostprocessed} from '@loaders.gl/3d-tiles';
1
+ import {Tiles3DTileJSONPostprocessed} from '@loaders.gl/tiles-3d/3d-tiles';
2
2
  import {NodeIndexDocument} from './node-index-document';
3
3
  import {Matrix4} from '@math.gl/core';
4
4
 
@@ -1,3 +1,4 @@
1
+ import type {ConversionImage} from './helpers/conversion-gltf';
1
2
  // loaders.gl
2
3
  // SPDX-License-Identifier: MIT
3
4
  // Copyright (c) vis.gl contributors
@@ -10,7 +11,7 @@ import type {
10
11
  Tiles3DTileContent,
11
12
  Tiles3DTileJSONPostprocessed,
12
13
  Tiles3DTilesetJSONPostprocessed
13
- } from '@loaders.gl/3d-tiles';
14
+ } from '@loaders.gl/tiles-3d/3d-tiles';
14
15
  import type {WriteQueueItem} from '../lib/utils/write-queue';
15
16
  import type {
16
17
  SceneLayer3D,
@@ -19,15 +20,14 @@ import type {
19
20
  NodeInPage,
20
21
  Attribute,
21
22
  Node3DIndexDocument
22
- } from '@loaders.gl/i3s';
23
+ } from '@loaders.gl/tiles-3d/i3s';
23
24
  import {load, encode, isBrowser} from '@loaders.gl/core';
24
- import {CesiumIonLoader, Tiles3DLoader} from '@loaders.gl/3d-tiles';
25
- import {Geoid} from '@math.gl/geoid';
25
+ import {CesiumIonLoader, Tiles3DLoader} from '@loaders.gl/tiles-3d/3d-tiles';
26
+ import {Geoid} from '@math.gl/earth/geoid';
26
27
  import {join} from 'path';
27
- import {v4 as uuidv4} from 'uuid';
28
+ import {randomUUID} from 'node:crypto';
28
29
  import process from 'process';
29
- import transform from 'json-map-transform';
30
- import md5 from 'md5';
30
+ import {hashString} from '../lib/utils/hash-string';
31
31
 
32
32
  import NodePages from './helpers/node-pages';
33
33
  import {writeFile, removeDir, writeFileForSlpk, removeFile} from '../lib/utils/file-utils';
@@ -42,15 +42,14 @@ import {createSceneServerPath} from './helpers/create-scene-server-path';
42
42
  import {convertGeometricErrorToScreenThreshold} from '../lib/utils/lod-conversion-utils';
43
43
  import {PGMLoader} from '../pgm-loader';
44
44
 
45
- import {LAYERS as layersTemplate} from './json-templates/layers';
46
- import {GEOMETRY_DEFINITION as geometryDefinitionTemlate} from './json-templates/geometry-definitions';
47
- import {SHARED_RESOURCES as sharedResourcesTemplate} from './json-templates/shared-resources';
45
+ import {createLayers} from './json-templates/layers';
46
+ import {createGeometryDefinition} from './json-templates/geometry-definitions';
47
+ import {createSharedResources} from './json-templates/shared-resources';
48
48
  import {validateNodeBoundingVolumes} from './helpers/node-debug';
49
49
  import {KTX2BasisWriterWorker} from '@loaders.gl/textures';
50
- import {LoaderWithParser} from '@loaders.gl/loader-utils';
51
- import {I3SMaterialDefinition, TextureSetDefinitionFormats} from '@loaders.gl/i3s';
50
+ import {LoaderWithParser} from '@loaders.gl/core/loader-utils';
51
+ import {I3SMaterialDefinition, TextureSetDefinitionFormats} from '@loaders.gl/tiles-3d/i3s';
52
52
  import {getImageData, ImageWriter} from '@loaders.gl/images';
53
- import {GLTFImagePostprocessed} from '@loaders.gl/gltf';
54
53
  import {
55
54
  GLTFPrimitiveModeString,
56
55
  I3SConvertedResources,
@@ -58,7 +57,7 @@ import {
58
57
  ResourceType,
59
58
  SharedResourcesArrays
60
59
  } from './types';
61
- import {WorkerFarm} from '@loaders.gl/worker-utils';
60
+ import {WorkerFarm} from '@loaders.gl/core/worker-utils';
62
61
  import WriteQueue from '../lib/utils/write-queue';
63
62
  import {BROWSER_ERROR_MESSAGE} from '../constants';
64
63
  import {
@@ -73,12 +72,12 @@ import {
73
72
  loadFromArchive
74
73
  } from './helpers/load-3d-tiles';
75
74
  import {Matrix4} from '@math.gl/core';
76
- import {BoundingSphere, OrientedBoundingBox} from '@math.gl/culling';
77
- import {TILE_REFINEMENT, createBoundingVolume} from '@loaders.gl/tiles';
75
+ import {BoundingSphere, OrientedBoundingBox} from '@math.gl/geometry/culling';
76
+ import {TILE_REFINEMENT, createBoundingVolume} from '@loaders.gl/tiles-3d';
78
77
  import {TraversalConversionProps, traverseDatasetWith} from './helpers/tileset-traversal';
79
78
  import {analyzeTileContent, mergePreprocessData} from './helpers/preprocess-3d-tiles';
80
79
  import {Progress} from './helpers/progress';
81
- import {composeHashFile, createZip} from '@loaders.gl/zip';
80
+ import {composeHashFile, createZip} from '@loaders.gl/archives/zip';
82
81
  import {ConversionDump, ConversionDumpOptions, DumpMetadata} from '../lib/utils/conversion-dump';
83
82
  import {PromptModule} from 'inquirer';
84
83
 
@@ -475,7 +474,7 @@ export default class I3SConverter {
475
474
 
476
475
  if (this.conversionDump.restored && this.conversionDump.materialDefinitions) {
477
476
  for (let i = 0; i < this.conversionDump.materialDefinitions.length; i++) {
478
- const hash = md5(JSON.stringify(this.conversionDump.materialDefinitions[i]));
477
+ const hash = hashString(JSON.stringify(this.conversionDump.materialDefinitions[i]));
479
478
  this.materialMap.set(hash, i);
480
479
  }
481
480
  this.materialDefinitions = this.conversionDump.materialDefinitions;
@@ -531,12 +530,11 @@ export default class I3SConverter {
531
530
 
532
531
  this.layers0!.materialDefinitions = this.materialDefinitions;
533
532
  // @ts-ignore
534
- this.layers0.geometryDefinitions = transform(
535
- this.geometryConfigs.map(config => ({
533
+ this.layers0.geometryDefinitions = this.geometryConfigs
534
+ .map(config => ({
536
535
  geometryConfig: {...config, draco: this.options.draco}
537
- })),
538
- geometryDefinitionTemlate()
539
- );
536
+ }))
537
+ .map(createGeometryDefinition);
540
538
 
541
539
  if (this.layersHasTexture === false) {
542
540
  this.layers0!.store.defaultGeometrySchema.ordering =
@@ -575,12 +573,12 @@ export default class I3SConverter {
575
573
  }
576
574
  const extent = [fullExtent.xmin, fullExtent.ymin, fullExtent.xmax, fullExtent.ymax];
577
575
  const layers0data = {
578
- version: `{${uuidv4().toUpperCase()}}`,
576
+ version: `{${randomUUID().toUpperCase()}}`,
579
577
  id: 0,
580
578
  name: tilesetName,
581
579
  href: './layers/0',
582
580
  store: {
583
- id: `{${uuidv4().toUpperCase()}}`,
581
+ id: `{${randomUUID().toUpperCase()}}`,
584
582
  extent
585
583
  },
586
584
  nodePages: {
@@ -589,7 +587,7 @@ export default class I3SConverter {
589
587
  compressGeometry: this.options.draco,
590
588
  fullExtent
591
589
  };
592
- this.layers0 = transform(layers0data, layersTemplate());
590
+ this.layers0 = createLayers(layers0data);
593
591
  }
594
592
 
595
593
  /**
@@ -1210,7 +1208,7 @@ export default class I3SConverter {
1210
1208
  return;
1211
1209
  }
1212
1210
  sharedResources.nodePath = nodePath;
1213
- const sharedData = transform(sharedResources, sharedResourcesTemplate());
1211
+ const sharedData = createSharedResources(sharedResources);
1214
1212
  const sharedDataStr = JSON.stringify(sharedData);
1215
1213
  this.conversionDump.updateDoneStatus(sourceId, nodeId, ResourceType.SHARED, false);
1216
1214
  const slpkSharedPath = join(childPath, 'shared');
@@ -1233,7 +1231,7 @@ export default class I3SConverter {
1233
1231
  */
1234
1232
  // eslint-disable-next-line max-statements
1235
1233
  private async _writeTexture(
1236
- texture: GLTFImagePostprocessed,
1234
+ texture: ConversionImage,
1237
1235
  childPath: string,
1238
1236
  slpkChildPath: string,
1239
1237
  sourceId: string,
@@ -1462,7 +1460,7 @@ export default class I3SConverter {
1462
1460
  * @return material id
1463
1461
  */
1464
1462
  private _findOrCreateMaterial(material: I3SMaterialDefinition): number {
1465
- const hash = md5(JSON.stringify(material));
1463
+ const hash = hashString(JSON.stringify(material));
1466
1464
  if (this.materialMap.has(hash)) {
1467
1465
  return this.materialMap.get(hash) || 0;
1468
1466
  }
@@ -1480,7 +1478,7 @@ export default class I3SConverter {
1480
1478
  */
1481
1479
  private findOrCreateGeometryDefinition(hasTexture: boolean, hasUvRegions: boolean): number {
1482
1480
  const geometryConfig = {hasTexture, hasUvRegions};
1483
- const hash = md5(JSON.stringify(geometryConfig));
1481
+ const hash = hashString(JSON.stringify(geometryConfig));
1484
1482
  if (this.geometryMap.has(hash)) {
1485
1483
  return this.geometryMap.get(hash) || 0;
1486
1484
  }
@@ -1508,7 +1506,7 @@ export default class I3SConverter {
1508
1506
  if (this.options.metadataClass) {
1509
1507
  if (!this.attributeMetadataInfo.attributeStorageInfo.length && tileContent?.gltf) {
1510
1508
  attributeTypesMap = getAttributeTypesMapFromSchema(
1511
- tileContent.gltf,
1509
+ tileContent.gltf.json,
1512
1510
  this.options.metadataClass
1513
1511
  );
1514
1512
  }
@@ -1,83 +1,88 @@
1
- import transform from 'json-map-transform';
1
+ // loaders.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
2
4
 
3
- const PLAIN_GEOMETRY_DEFINITION = () => ({
4
- offset: {
5
- default: 8
6
- },
7
- position: {
8
- default: {
5
+ import type {BuilderInput} from '../../lib/utils/builder-input';
6
+
7
+ import type {SceneLayer3D} from '@loaders.gl/tiles-3d/i3s';
8
+ /** Legacy geometry layout choices. */
9
+ export type GeometryConfiguration = {
10
+ /** Whether texture coordinates are present. */
11
+ hasTexture?: boolean;
12
+ /** Whether UV regions are present. */
13
+ hasUvRegions?: boolean;
14
+ /** Whether Draco is emitted. */
15
+ draco?: boolean;
16
+ };
17
+ /** Input to one geometry layout builder. */
18
+ export type GeometryDefinitionInput = {
19
+ /** Geometry layout choices. */
20
+ geometryConfig: GeometryConfiguration;
21
+ };
22
+
23
+ /** Builds plain geometry definition with the legacy field selection and defaults. */
24
+ function createPlainGeometryDefinition(
25
+ input: BuilderInput<GeometryConfiguration> | null | undefined
26
+ ) {
27
+ const source = input ?? {};
28
+ return {
29
+ offset: 8,
30
+ position: {
9
31
  type: 'Float32',
10
32
  component: 3
11
- }
12
- },
13
- normal: {
14
- default: {
33
+ },
34
+ normal: {
15
35
  type: 'Float32',
16
36
  component: 3
17
- }
18
- },
19
- uv0: {
20
- path: 'hasTexture',
21
- transform: val => (val && {type: 'Float32', component: 2}) || false,
22
- omitValues: [false]
23
- },
24
- color: {
25
- default: {
37
+ },
38
+ ...(source.hasTexture ? {uv0: {type: 'Float32', component: 2}} : {}),
39
+ color: {
26
40
  type: 'UInt8',
27
41
  component: 4
28
- }
29
- },
30
- uvRegion: {
31
- path: 'hasUvRegions',
32
- transform: val => (val && {type: 'UInt16', component: 4}) || false,
33
- omitValues: [false]
34
- },
35
- featureId: {
36
- default: {
42
+ },
43
+ ...(source.hasUvRegions ? {uvRegion: {type: 'UInt16', component: 4}} : {}),
44
+ featureId: {
37
45
  binding: 'per-feature',
38
46
  type: 'UInt64',
39
47
  component: 1
40
- }
41
- },
42
- faceRange: {
43
- default: {
48
+ },
49
+ faceRange: {
44
50
  binding: 'per-feature',
45
51
  type: 'UInt32',
46
52
  component: 2
47
53
  }
48
- }
49
- });
54
+ };
55
+ }
50
56
 
51
- const COMPRESSED_GEOMETRY_DEFINITION = () => ({
52
- 'compressedAttributes.encoding': {
53
- default: 'draco'
54
- },
55
- 'compressedAttributes.attributes': {
56
- path: 'geometryConfig',
57
- transform: val => {
58
- const result = ['position', 'normal'];
59
- if (val.hasTexture) {
60
- result.push('uv0');
61
- }
62
- result.push('color');
63
- if (val.hasUvRegions) {
64
- result.push('uv-region');
65
- }
66
- result.push('feature-index');
67
- return result;
57
+ /** Builds compressed geometry definition with the legacy field selection and defaults. */
58
+ function createCompressedGeometryDefinition(
59
+ input: BuilderInput<GeometryDefinitionInput> | null | undefined
60
+ ) {
61
+ const configuration = input!.geometryConfig!;
62
+ return {
63
+ compressedAttributes: {
64
+ encoding: 'draco',
65
+ attributes: [
66
+ 'position',
67
+ 'normal',
68
+ ...(configuration.hasTexture ? ['uv0'] : []),
69
+ 'color',
70
+ ...(configuration.hasUvRegions ? ['uv-region'] : []),
71
+ 'feature-index'
72
+ ]
68
73
  }
69
- }
70
- });
74
+ };
75
+ }
71
76
 
72
- export const GEOMETRY_DEFINITION = () => ({
73
- geometryBuffers: {
74
- path: 'geometryConfig',
75
- transform: val => {
76
- const result = [transform(val, PLAIN_GEOMETRY_DEFINITION())];
77
- if (val.draco) {
78
- result.push(transform({geometryConfig: val}, COMPRESSED_GEOMETRY_DEFINITION()));
79
- }
80
- return result;
81
- }
82
- }
83
- });
77
+ /** Builds geometry definition with the legacy field selection and defaults. */
78
+ export function createGeometryDefinition(
79
+ input: BuilderInput<GeometryDefinitionInput> | null | undefined
80
+ ): NonNullable<SceneLayer3D['geometryDefinitions']>[number] {
81
+ const source = input ?? {};
82
+ return {
83
+ geometryBuffers: [
84
+ createPlainGeometryDefinition(source.geometryConfig),
85
+ ...(source.geometryConfig!.draco ? [createCompressedGeometryDefinition(source)] : [])
86
+ ]
87
+ } as NonNullable<SceneLayer3D['geometryDefinitions']>[number];
88
+ }
@@ -1,137 +1,102 @@
1
- import transform from 'json-map-transform';
2
- import {STORE} from './store';
1
+ // loaders.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
3
4
 
4
- const SPATIAL_REFERENCE = () => ({
5
- wkid: {
6
- path: 'wkid',
7
- default: 4326
8
- },
9
- latestWkid: {
10
- path: 'latestWkid',
11
- default: 4326
12
- },
13
- vcsWkid: {
14
- path: 'vcsWkid',
15
- default: 5773
16
- },
17
- latestVcsWkid: {
18
- path: 'latestVcsWkid',
19
- default: 5773
20
- }
21
- });
5
+ import type {BuilderInput} from '../../lib/utils/builder-input';
22
6
 
23
- const HEIGHT_MODEL_INFO = () => ({
24
- heightModel: {
25
- path: 'heightModel',
26
- default: 'gravity_related_height'
27
- },
28
- vertCRS: {
29
- path: 'vertCRS',
30
- default: 'EGM96_Geoid'
31
- },
32
- heightUnit: {
33
- path: 'heightUnit',
34
- default: 'meter'
35
- }
36
- });
7
+ import type {SceneLayer3D} from '@loaders.gl/tiles-3d/i3s';
8
+ import {createStore, type StoreBuilderRecord} from './store';
37
9
 
38
- const NODE_PAGES = () => ({
39
- nodesPerPage: {
40
- path: 'nodesPerPage'
41
- },
42
- lodSelectionMetricType: {
43
- path: 'lodSelectionMetricType',
44
- default: 'maxScreenThresholdSQ'
45
- }
46
- });
10
+ /** Partially specified nested records completed by the legacy layer builder. */
11
+ type LayerBuilderRecord = Omit<
12
+ SceneLayer3D,
13
+ 'store' | 'nodePages' | 'spatialReference' | 'heightModelInfo' | 'fullExtent'
14
+ > & {
15
+ /** Store values completed with defaults. */
16
+ store: BuilderInput<StoreBuilderRecord>;
17
+ /** Node page settings. */
18
+ nodePages?: BuilderInput<NonNullable<SceneLayer3D['nodePages']>>;
19
+ /** Spatial reference identifiers. */
20
+ spatialReference?: BuilderInput<NonNullable<SceneLayer3D['spatialReference']>>;
21
+ /** Height model settings. */
22
+ heightModelInfo?: BuilderInput<NonNullable<SceneLayer3D['heightModelInfo']>>;
23
+ /** Extent fields retained without defaults. */
24
+ fullExtent?: BuilderInput<NonNullable<SceneLayer3D['fullExtent']>>;
25
+ };
47
26
 
48
- const FULL_EXTENT = () => ({
49
- xmin: {
50
- path: 'xmin'
51
- },
52
- ymin: {
53
- path: 'ymin'
54
- },
55
- xmax: {
56
- path: 'xmax'
57
- },
58
- ymax: {
59
- path: 'ymax'
60
- },
61
- zmin: {
62
- path: 'zmin'
63
- },
64
- zmax: {
65
- path: 'zmax'
66
- }
67
- });
27
+ /** Builds spatial reference with the legacy field selection and defaults. */
28
+ function createSpatialReference(
29
+ input: BuilderInput<NonNullable<SceneLayer3D['spatialReference']>> | null | undefined
30
+ ) {
31
+ const source = input ?? {};
32
+ return {
33
+ wkid: source.wkid ?? 4326,
34
+ latestWkid: source.latestWkid ?? 4326,
35
+ vcsWkid: source.vcsWkid ?? 5773,
36
+ latestVcsWkid: source.latestVcsWkid ?? 5773
37
+ };
38
+ }
68
39
 
69
- export const LAYERS = () => ({
70
- version: {
71
- path: 'version',
72
- transform: val => val.toUpperCase()
73
- },
74
- id: {
75
- path: 'id',
76
- default: 0
77
- },
78
- name: {
79
- path: 'name'
80
- },
81
- href: {
82
- path: 'href',
83
- default: './layers/0'
84
- },
85
- layerType: {
86
- path: 'layerType',
87
- default: 'IntegratedMesh'
88
- },
89
- spatialReference: {
90
- path: 'spatialReference',
91
- transform: val => transform(val, SPATIAL_REFERENCE())
92
- },
93
- capabilities: {
94
- path: 'capabilities',
95
- default: ['View', 'Query']
96
- },
97
- store: {
98
- path: 'store',
99
- transform: val => transform(val, STORE)
100
- },
101
- fullExtent: {
102
- path: 'fullExtent',
103
- transform: val => transform(val, FULL_EXTENT())
104
- },
105
- heightModelInfo: {
106
- path: 'heightModelInfo',
107
- transform: val => transform(val, HEIGHT_MODEL_INFO())
108
- },
109
- nodePages: {
110
- path: 'nodePages',
111
- transform: val => transform(val, NODE_PAGES())
112
- },
113
- materialDefinitions: {
114
- path: 'materialDefinitions',
115
- default: []
116
- },
117
- textureSetDefinitions: {
118
- path: 'textureSetDefinitions',
119
- default: []
120
- },
121
- geometryDefinitions: {
122
- path: 'geometryDefinitions',
123
- default: []
124
- },
125
- attributeStorageInfo: {
126
- path: 'attributeStorageInfo',
127
- default: []
128
- },
129
- fields: {
130
- path: 'fields',
131
- default: []
132
- },
133
- popupInfo: {
134
- path: 'popupInfo',
135
- default: null
136
- }
137
- });
40
+ /** Builds height model info with the legacy field selection and defaults. */
41
+ function createHeightModelInfo(
42
+ input: BuilderInput<NonNullable<SceneLayer3D['heightModelInfo']>> | null | undefined
43
+ ) {
44
+ const source = input ?? {};
45
+ return {
46
+ heightModel: source.heightModel ?? 'gravity_related_height',
47
+ vertCRS: source.vertCRS ?? 'EGM96_Geoid',
48
+ heightUnit: source.heightUnit ?? 'meter'
49
+ };
50
+ }
51
+
52
+ /** Builds node pages with the legacy field selection and defaults. */
53
+ function createNodePages(
54
+ input: BuilderInput<NonNullable<SceneLayer3D['nodePages']>> | null | undefined
55
+ ) {
56
+ const source = input ?? {};
57
+ return {
58
+ nodesPerPage: source.nodesPerPage ?? undefined,
59
+ lodSelectionMetricType: source.lodSelectionMetricType ?? 'maxScreenThresholdSQ'
60
+ };
61
+ }
62
+
63
+ /** Builds full extent with the legacy field selection and defaults. */
64
+ function createFullExtent(
65
+ input: BuilderInput<NonNullable<SceneLayer3D['fullExtent']>> | null | undefined
66
+ ) {
67
+ const source = input ?? {};
68
+ return {
69
+ xmin: source.xmin ?? undefined,
70
+ ymin: source.ymin ?? undefined,
71
+ xmax: source.xmax ?? undefined,
72
+ ymax: source.ymax ?? undefined,
73
+ zmin: source.zmin ?? undefined,
74
+ zmax: source.zmax ?? undefined
75
+ };
76
+ }
77
+
78
+ /** Builds layers with the legacy field selection and defaults. */
79
+ export function createLayers(
80
+ input: BuilderInput<LayerBuilderRecord> | null | undefined
81
+ ): SceneLayer3D {
82
+ const source = input ?? {};
83
+ return {
84
+ version: source.version!.toUpperCase(),
85
+ id: source.id ?? 0,
86
+ name: source.name ?? undefined,
87
+ href: source.href ?? './layers/0',
88
+ layerType: source.layerType ?? 'IntegratedMesh',
89
+ spatialReference: createSpatialReference(source.spatialReference),
90
+ capabilities: source.capabilities ?? ['View', 'Query'],
91
+ store: createStore(source.store),
92
+ fullExtent: createFullExtent(source.fullExtent),
93
+ heightModelInfo: createHeightModelInfo(source.heightModelInfo),
94
+ nodePages: createNodePages(source.nodePages),
95
+ materialDefinitions: source.materialDefinitions ?? [],
96
+ textureSetDefinitions: source.textureSetDefinitions ?? [],
97
+ geometryDefinitions: source.geometryDefinitions ?? [],
98
+ attributeStorageInfo: source.attributeStorageInfo ?? [],
99
+ fields: source.fields ?? [],
100
+ popupInfo: source.popupInfo ?? undefined
101
+ } as SceneLayer3D;
102
+ }
@@ -1,21 +1,31 @@
1
- export const METADATA = () => ({
2
- folderPattern: {
3
- path: 'folderPattern',
4
- default: 'BASIC'
5
- },
6
- archiveCompressionType: {
7
- path: 'archiveCompressionType',
8
- default: 'STORE'
9
- },
10
- resourceCompressionType: {
11
- path: 'resourceCompressionType',
12
- default: 'GZIP'
13
- },
14
- I3SVersion: {
15
- path: 'I3SVersion',
16
- default: '1.8'
17
- },
18
- nodeCount: {
19
- path: 'nodeCount'
20
- }
21
- });
1
+ // loaders.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
4
+
5
+ import type {BuilderInput} from '../../lib/utils/builder-input';
6
+
7
+ /** Serialized legacy archive metadata. */
8
+ export type ConversionMetadata = {
9
+ /** Folder layout. */
10
+ folderPattern: string;
11
+ /** Archive compression. */
12
+ archiveCompressionType: string;
13
+ /** Resource compression. */
14
+ resourceCompressionType: string;
15
+ /** I3S version. */
16
+ I3SVersion: string;
17
+ /** Number of nodes. */
18
+ nodeCount?: number;
19
+ };
20
+
21
+ /** Builds metadata with the legacy field selection and defaults. */
22
+ export function createMetadata(input: BuilderInput<ConversionMetadata> | null | undefined) {
23
+ const source = input ?? {};
24
+ return {
25
+ folderPattern: source.folderPattern ?? 'BASIC',
26
+ archiveCompressionType: source.archiveCompressionType ?? 'STORE',
27
+ resourceCompressionType: source.resourceCompressionType ?? 'GZIP',
28
+ I3SVersion: source.I3SVersion ?? '1.8',
29
+ nodeCount: source.nodeCount ?? undefined
30
+ };
31
+ }