@loaders.gl/tile-converter 4.3.0-alpha.7 → 4.3.0-beta.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 (45) hide show
  1. package/dist/3d-tiles-converter/3d-tiles-converter.d.ts +3 -0
  2. package/dist/3d-tiles-converter/3d-tiles-converter.d.ts.map +1 -1
  3. package/dist/3d-tiles-converter/3d-tiles-converter.js +15 -11
  4. package/dist/3d-tiles-converter/helpers/{b3dm-converter.d.ts → 3d-tiles-content-converter.d.ts} +13 -6
  5. package/dist/3d-tiles-converter/helpers/3d-tiles-content-converter.d.ts.map +1 -0
  6. package/dist/3d-tiles-converter/helpers/{b3dm-converter.js → 3d-tiles-content-converter.js} +110 -17
  7. package/dist/3d-tiles-converter/helpers/load-i3s.d.ts.map +1 -1
  8. package/dist/converter-cli.js +15 -0
  9. package/dist/converter.min.cjs +95 -95
  10. package/dist/deps-installer/deps-installer.js +1 -1
  11. package/dist/i3s-converter/helpers/batch-ids-extensions.d.ts +2 -2
  12. package/dist/i3s-converter/helpers/batch-ids-extensions.d.ts.map +1 -1
  13. package/dist/i3s-converter/helpers/batch-ids-extensions.js +1 -1
  14. package/dist/i3s-converter/helpers/feature-attributes.d.ts.map +1 -1
  15. package/dist/i3s-converter/helpers/geometry-converter.d.ts.map +1 -1
  16. package/dist/i3s-converter/helpers/load-3d-tiles.d.ts.map +1 -1
  17. package/dist/i3s-converter/helpers/preprocess-3d-tiles.d.ts.map +1 -1
  18. package/dist/i3s-converter/helpers/preprocess-3d-tiles.js +1 -2
  19. package/dist/i3s-converter/helpers/tileset-traversal.d.ts +3 -3
  20. package/dist/i3s-converter/helpers/tileset-traversal.d.ts.map +1 -1
  21. package/dist/i3s-converter/i3s-converter.d.ts.map +1 -1
  22. package/dist/i3s-converter/i3s-converter.js +1 -0
  23. package/dist/i3s-server/bin/i3s-server.min.cjs +70 -70
  24. package/dist/i3s-server/bin/www.js +2 -0
  25. package/dist/i3s-server/utils/server-utils.d.ts +0 -3
  26. package/dist/i3s-server/utils/server-utils.d.ts.map +1 -1
  27. package/dist/index.cjs +130 -34
  28. package/dist/index.cjs.map +4 -4
  29. package/dist/lib/utils/conversion-dump.d.ts +1 -0
  30. package/dist/lib/utils/conversion-dump.d.ts.map +1 -1
  31. package/dist/lib/utils/conversion-dump.js +3 -2
  32. package/dist/pgm-loader.d.ts.map +1 -1
  33. package/dist/pgm-loader.js +1 -1
  34. package/package.json +20 -20
  35. package/src/3d-tiles-converter/3d-tiles-converter.ts +40 -14
  36. package/src/3d-tiles-converter/helpers/{b3dm-converter.ts → 3d-tiles-content-converter.ts} +157 -21
  37. package/src/converter-cli.ts +22 -0
  38. package/src/i3s-converter/helpers/batch-ids-extensions.ts +6 -6
  39. package/src/i3s-converter/helpers/geometry-converter.ts +6 -2
  40. package/src/i3s-converter/helpers/preprocess-3d-tiles.ts +2 -2
  41. package/src/i3s-converter/i3s-converter.ts +1 -0
  42. package/src/i3s-server/README.md +2 -0
  43. package/src/i3s-server/bin/www.ts +2 -0
  44. package/src/lib/utils/conversion-dump.ts +5 -2
  45. package/dist/3d-tiles-converter/helpers/b3dm-converter.d.ts.map +0 -1
@@ -23,12 +23,14 @@ export default class Tiles3DConverter {
23
23
  loaderOptions: I3SLoaderOptions;
24
24
  conversionDump: ConversionDump;
25
25
  progress: Progress;
26
+ fileExt: string;
26
27
  constructor();
27
28
  /**
28
29
  * Convert i3s format data to 3dTiles
29
30
  * @param options
30
31
  * @param options.inputUrl the url to read the tileset from
31
32
  * @param options.outputPath the output filename
33
+ * @param options.outputVersion the version of 3DTiles
32
34
  * @param options.tilesetName the output name of the tileset
33
35
  * @param options.egmFilePath location of *.pgm file to convert heights from ellipsoidal to gravity-related format
34
36
  * @param options.maxDepth The max tree depth of conversion
@@ -37,6 +39,7 @@ export default class Tiles3DConverter {
37
39
  inputUrl: string;
38
40
  outputPath: string;
39
41
  tilesetName: string;
42
+ outputVersion?: string;
40
43
  maxDepth?: number;
41
44
  egmFilePath: string;
42
45
  inquirer?: {
@@ -1 +1 @@
1
- {"version":3,"file":"3d-tiles-converter.d.ts","sourceRoot":"","sources":["../../src/3d-tiles-converter/3d-tiles-converter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,oBAAoB,EAGpB,gBAAgB,EACjB,MAAM,iBAAiB,CAAC;AAQzB,OAAO,EAAC,KAAK,EAAC,MAAM,gBAAgB,CAAC;AAcrC,OAAO,EAAC,gBAAgB,EAAC,MAAM,gCAAgC,CAAC;AAChE,OAAO,EAAC,aAAa,EAAC,4BAAyB;AAC/C,OAAO,EAAC,cAAc,EAAwB,wCAAqC;AACnF,OAAO,EAAC,QAAQ,EAAC,6CAA0C;AAC3D,OAAO,EAAC,YAAY,EAAC,MAAM,UAAU,CAAC;AAItC;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,gBAAgB;IACnC,OAAO,EAAE,GAAG,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,aAAa,EAAE,MAAM,CAAC;IACtB,mBAAmB,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACtC,gBAAgB,EAAE,KAAK,GAAG,IAAI,CAAC;IAC/B,aAAa,EAAE,gBAAgB,GAAG,IAAI,CAAC;IACvC,oBAAoB,CAAC,EAAE,oBAAoB,EAAE,GAAG,IAAI,CAAC;IACrD,YAAY,EAAE;QAAC,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAA;KAAC,CAAM;IAC3C,cAAc,EAAE,aAAa,GAAG,IAAI,CAAQ;IAC5C,aAAa,EAAE,gBAAgB,CAU7B;IACF,cAAc,EAAE,cAAc,CAAC;IAC/B,QAAQ,EAAE,QAAQ,CAAC;;IAenB;;;;;;;;OAQG;IAEU,OAAO,CAAC,OAAO,EAAE;QAC5B,QAAQ,EAAE,MAAM,CAAC;QACjB,UAAU,EAAE,MAAM,CAAC;QACnB,WAAW,EAAE,MAAM,CAAC;QACpB,QAAQ,CAAC,EAAE,M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ers/coordinate-converter.js";
13
13
  import { WorkerFarm } from '@loaders.gl/worker-utils';
14
14
  import { BROWSER_ERROR_MESSAGE } from "../constants.js";
15
- import B3dmConverter from "./helpers/b3dm-converter.js";
15
+ import { Tiles3DContentConverter } from "./helpers/3d-tiles-content-converter.js";
16
16
  import { getNodeCount, loadFromArchive, loadI3SContent, openSLPK } from "./helpers/load-i3s.js";
17
17
  import { ConversionDump } from "../lib/utils/conversion-dump.js";
18
18
  import { Progress } from "../i3s-converter/helpers/progress.js";
@@ -43,6 +43,7 @@ export default class Tiles3DConverter {
43
43
  };
44
44
  conversionDump;
45
45
  progress;
46
+ fileExt;
46
47
  constructor() {
47
48
  this.options = {};
48
49
  this.tilesetPath = '';
@@ -54,12 +55,14 @@ export default class Tiles3DConverter {
54
55
  this.workerSource = {};
55
56
  this.conversionDump = new ConversionDump();
56
57
  this.progress = new Progress();
58
+ this.fileExt = '';
57
59
  }
58
60
  /**
59
61
  * Convert i3s format data to 3dTiles
60
62
  * @param options
61
63
  * @param options.inputUrl the url to read the tileset from
62
64
  * @param options.outputPath the output filename
65
+ * @param options.outputVersion the version of 3DTiles
63
66
  * @param options.tilesetName the output name of the tileset
64
67
  * @param options.egmFilePath location of *.pgm file to convert heights from ellipsoidal to gravity-related format
65
68
  * @param options.maxDepth The max tree depth of conversion
@@ -70,9 +73,10 @@ export default class Tiles3DConverter {
70
73
  console.log(BROWSER_ERROR_MESSAGE); // eslint-disable-line no-console
71
74
  return BROWSER_ERROR_MESSAGE;
72
75
  }
73
- const { inputUrl, outputPath, tilesetName, maxDepth, egmFilePath, inquirer, analyze } = options;
76
+ const { inputUrl, outputPath, outputVersion, tilesetName, maxDepth, egmFilePath, inquirer, analyze } = options;
74
77
  this.conversionStartTime = process.hrtime();
75
- this.options = { maxDepth, inquirer };
78
+ this.options = { maxDepth, inquirer, outputVersion };
79
+ this.fileExt = this.options.outputVersion === '1.0' ? 'b3dm' : 'glb';
76
80
  console.log('Loading egm file...'); // eslint-disable-line
77
81
  this.geoidHeightModel = await load(egmFilePath, PGMLoader);
78
82
  console.log('Loading egm file completed!'); // eslint-disable-line
@@ -130,7 +134,7 @@ export default class Tiles3DConverter {
130
134
  refine: 'REPLACE'
131
135
  };
132
136
  await this._addChildren(rootNode, rootTile, 1);
133
- const tileset = transform({ root: rootTile }, tilesetTemplate());
137
+ const tileset = transform({ asset: { version: outputVersion }, root: rootTile }, tilesetTemplate());
134
138
  await writeFile(this.tilesetPath, JSON.stringify(tileset), 'tileset.json');
135
139
  await this.conversionDump.deleteDumpFile();
136
140
  this.progress.stopMonitoring();
@@ -188,7 +192,7 @@ export default class Tiles3DConverter {
188
192
  const sourceChild = await this._loadChildNode(parentSourceNode, childNodeInfo);
189
193
  if (sourceChild.contentUrl) {
190
194
  if (this.conversionDump.restored &&
191
- this.conversionDump.isFileConversionComplete(`${sourceChild.id}.b3dm`) &&
195
+ this.conversionDump.isFileConversionComplete(`${sourceChild.id}.${this.fileExt}`) &&
192
196
  (sourceChild.obb || sourceChild.mbs)) {
193
197
  const { child } = this._createChildAndBoundingVolume(sourceChild);
194
198
  parentNode.children.push(child);
@@ -211,11 +215,11 @@ export default class Tiles3DConverter {
211
215
  box: boundingVolume.box || [],
212
216
  textureFormat: sourceChild.textureFormat
213
217
  };
214
- const b3dmConverter = new B3dmConverter();
215
- const b3dm = await b3dmConverter.convert(i3sAttributesData, featureAttributes);
216
- await this.conversionDump.addNode(`${sourceChild.id}.b3dm`, sourceChild.id);
217
- await writeFile(this.tilesetPath, new Uint8Array(b3dm), `${sourceChild.id}.b3dm`);
218
- await this.conversionDump.updateConvertedNodesDumpFile(`${sourceChild.id}.b3dm`, sourceChild.id, true);
218
+ const converter = new Tiles3DContentConverter({ outputVersion: this.options.outputVersion });
219
+ const contentData = await converter.convert(i3sAttributesData, featureAttributes, this.attributeStorageInfo);
220
+ await this.conversionDump.addNode(`${sourceChild.id}.${this.fileExt}`, sourceChild.id);
221
+ await writeFile(this.tilesetPath, new Uint8Array(contentData), `${sourceChild.id}.${this.fileExt}`);
222
+ await this.conversionDump.updateConvertedNodesDumpFile(`${sourceChild.id}.${this.fileExt}`, sourceChild.id, true);
219
223
  parentNode.children.push(child);
220
224
  nextParentNode = child;
221
225
  }
@@ -289,7 +293,7 @@ export default class Tiles3DConverter {
289
293
  geometricError: convertScreenThresholdToGeometricError(sourceChild),
290
294
  children: [],
291
295
  content: {
292
- uri: `${sourceChild.id}.b3dm`,
296
+ uri: `${sourceChild.id}.${this.fileExt}`,
293
297
  boundingVolume
294
298
  }
295
299
  };
@@ -1,4 +1,4 @@
1
- import type { I3STileContent } from '@loaders.gl/i3s';
1
+ import type { I3STileContent, AttributeStorageInfo, I3STileAttributes } from '@loaders.gl/i3s';
2
2
  import { Matrix4 } from '@math.gl/core';
3
3
  export type I3SAttributesData = {
4
4
  tileContent: I3STileContent;
@@ -6,23 +6,30 @@ export type I3SAttributesData = {
6
6
  textureFormat: string;
7
7
  };
8
8
  /**
9
- * Converts content of an I3S node to *.b3dm's file content
9
+ * Converts content of an I3S node to 3D Tiles file content
10
10
  */
11
- export default class B3dmConverter {
11
+ export declare class Tiles3DContentConverter {
12
12
  rtcCenter: Float32Array;
13
13
  i3sTile: any;
14
+ tileType: string;
15
+ constructor(options?: {
16
+ outputVersion: string;
17
+ });
14
18
  /**
15
19
  * The starter of content conversion
16
20
  * @param i3sTile - Tile3D instance for I3S node
17
21
  * @returns - encoded content
18
22
  */
19
- convert(i3sAttributesData: I3SAttributesData, featureAttributes?: any): Promise<ArrayBuffer>;
23
+ convert(i3sAttributesData: I3SAttributesData, featureAttributes?: I3STileAttributes | null, attributeStorageInfo?: AttributeStorageInfo[] | null | undefined): Promise<ArrayBuffer>;
20
24
  /**
21
25
  * Build and encode gltf
22
26
  * @param i3sTile - Tile3D instance for I3S node
23
27
  * @returns - encoded glb content
24
28
  */
25
- buildGLTF(i3sAttributesData: I3SAttributesData, featureAttributes: any): Promise<ArrayBuffer>;
29
+ buildGLTF(i3sAttributesData: I3SAttributesData, featureAttributes: I3STileAttributes | null, attributeStorageInfo?: AttributeStorageInfo[] | null | undefined): Promise<ArrayBuffer>;
30
+ private _createMetadataExtensions;
31
+ private _createPropertyAttibutes;
32
+ private _convertAttributeStorageInfoToPropertyAttribute;
26
33
  /**
27
34
  * Update gltfBuilder with texture from I3S tile
28
35
  * @param {object} i3sTile - Tile3D object
@@ -78,4 +85,4 @@ export default class B3dmConverter {
78
85
  _getFeaturesLength(attributes: any): any;
79
86
  _checkNormals(normals: any): any;
80
87
  }
81
- //# sourceMappingURL=b3dm-converter.d.ts.map
88
+ //# sourceMappingURL=3d-tiles-content-converter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"3d-tiles-content-converter.d.ts","sourceRoot":"","sources":["../../../src/3d-tiles-converter/helpers/3d-tiles-content-converter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,cAAc,EAAE,oBAAoB,EAAE,iBAAiB,EAAC,MAAM,iBAAiB,CAAC;AAU7F,OAAO,EAAC,OAAO,EAAU,MAAM,eAAe,CAAC;AAY/C,MAAM,MAAM,iBAAiB,GAAG;IAC9B,WAAW,EAAE,cAAc,CAAC;IAC5B,GAAG,EAAE,MAAM,EAAE,CAAC;IACd,aAAa,EAAE,MAAM,CAAC;CACvB,CAAC;AAEF;;GAEG;AACH,qBAAa,uBAAuB;IAElC,SAAS,EAAE,YAAY,CAAC;IACxB,OAAO,EAAE,GAAG,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;gBAEL,OAAO,GAAE;QAAC,aAAa,EAAE,MAAM,CAAA;KAA0B;IAKrE;;;;OAIG;IACG,OAAO,CACX,iBAAiB,EAAE,iBAAiB,EACpC,iBAAiB,GAAE,iBAAiB,GAAG,IAAW,EAClD,oBAAoB,CAAC,EAAE,oBAAoB,EAAE,GAAG,IAAI,GAAG,SAAS,GAC/D,OAAO,CAAC,WAAW,CAAC;IAkBvB;;;;OAIG;IAEG,SAAS,CACb,iBAAiB,EAAE,iBAAiB,EACpC,iBAAiB,EAAE,iBAAiB,GAAG,IAAI,EAC3C,oBAAoB,CAAC,EAAE,oBAAoB,EAAE,GAAG,IAAI,GAAG,SAAS,GAC/D,OAAO,CAAC,WAAW,CAAC;IA8EvB,OAAO,CAAC,yBAAyB;IA0BjC,OAAO,CAAC,wBAAwB;IAsBhC,OAAO,CAAC,+CAA+C;IA8DvD;;;;;OAKG;IACG,oBAAoB,CAAC,WAAW,KAAA,EAAE,aAAa,KAAA,EAAE,WAAW,KAAA;IAmBlE;;;;;;;OAOG;IACH,mBAAmB,CAAC,cAAc,KAAA,EAAE,eAAe,KAAA,EAAE,kBAAkB,KAAA,EAAE,WAAW,KAAA;IAepF;;;;;;;OAOG;IACH,wBAAwB,CAAC,eAAe,KAAA;IAMxC;;;;OAIG;IACH,eAAe,CAAC,UAAU,KAAA,EAAE,iBAAiB,KAAA;IAoB7C;;;;;OAKG;IACH,yBAAyB,CAAC,MAAM,KAAA;IAchC;;;;;OAKG;IACH,iCAAiC,CAAC,QAAQ,KAAA,EAAE,YAAY,KAAA;IAgCxD;;;;;OAKG;IACH,eAAe,CAAC,kBAAkB,KAAA,EAAE,YAAY,KAAA;IA+ChD,kBAAkB,CAAC,UAAU,KAAA;IAY7B,aAAa,CAAC,OAAO,KAAA;CAItB"}
@@ -1,7 +1,8 @@
1
1
  import { encodeSync } from '@loaders.gl/core';
2
- import { GLTFScenegraph, GLTFWriter } from '@loaders.gl/gltf';
3
- import { Tile3DWriter } from '@loaders.gl/3d-tiles';
2
+ import { GLTFScenegraph, GLTFWriter, createExtStructuralMetadata, createExtMeshFeatures } from '@loaders.gl/gltf';
3
+ import { Tile3DWriter, TILE3D_TYPE } from '@loaders.gl/3d-tiles';
4
4
  import { Matrix4, Vector3 } from '@math.gl/core';
5
+ import { isTypedArray } from '@math.gl/types';
5
6
  import { Ellipsoid } from '@math.gl/geospatial';
6
7
  import { convertTextureAtlas } from "./texture-atlas.js";
7
8
  import { generateSyntheticIndices } from "../../lib/utils/geometry-utils.js";
@@ -11,34 +12,42 @@ const KHR_MATERIALS_UNLIT = 'KHR_materials_unlit';
11
12
  const METALLIC_FACTOR_DEFAULT = 1.0;
12
13
  const ROUGHNESS_FACTOR_DEFAULT = 1.0;
13
14
  /**
14
- * Converts content of an I3S node to *.b3dm's file content
15
+ * Converts content of an I3S node to 3D Tiles file content
15
16
  */
16
- export default class B3dmConverter {
17
+ export class Tiles3DContentConverter {
17
18
  // @ts-expect-error
18
19
  rtcCenter;
19
20
  i3sTile;
21
+ tileType;
22
+ constructor(options = { outputVersion: '1.1' }) {
23
+ this.tileType =
24
+ options.outputVersion === '1.0' ? TILE3D_TYPE.BATCHED_3D_MODEL : TILE3D_TYPE.GLTF;
25
+ }
20
26
  /**
21
27
  * The starter of content conversion
22
28
  * @param i3sTile - Tile3D instance for I3S node
23
29
  * @returns - encoded content
24
30
  */
25
- async convert(i3sAttributesData, featureAttributes = null) {
26
- const gltf = await this.buildGLTF(i3sAttributesData, featureAttributes);
27
- const b3dm = encodeSync({
28
- gltfEncoded: new Uint8Array(gltf),
29
- type: 'b3dm',
30
- featuresLength: this._getFeaturesLength(featureAttributes),
31
- batchTable: featureAttributes
32
- }, Tile3DWriter);
33
- return b3dm;
31
+ async convert(i3sAttributesData, featureAttributes = null, attributeStorageInfo) {
32
+ const gltf = await this.buildGLTF(i3sAttributesData, featureAttributes, attributeStorageInfo);
33
+ if (this.tileType === TILE3D_TYPE.BATCHED_3D_MODEL) {
34
+ const b3dm = encodeSync({
35
+ gltfEncoded: new Uint8Array(gltf),
36
+ type: 'b3dm',
37
+ featuresLength: this._getFeaturesLength(featureAttributes),
38
+ batchTable: featureAttributes
39
+ }, Tile3DWriter);
40
+ return b3dm;
41
+ }
42
+ return gltf;
34
43
  }
35
44
  /**
36
45
  * Build and encode gltf
37
46
  * @param i3sTile - Tile3D instance for I3S node
38
47
  * @returns - encoded glb content
39
48
  */
40
- // eslint-disable-next-line max-statements
41
- async buildGLTF(i3sAttributesData, featureAttributes) {
49
+ // eslint-disable-next-line complexity, max-statements
50
+ async buildGLTF(i3sAttributesData, featureAttributes, attributeStorageInfo) {
42
51
  const { tileContent, textureFormat, box } = i3sAttributesData;
43
52
  const { material, attributes, indices: originalIndices, modelMatrix } = tileContent;
44
53
  const gltfBuilder = new GLTFScenegraph();
@@ -76,13 +85,97 @@ export default class B3dmConverter {
76
85
  material: materialIndex,
77
86
  mode: 4
78
87
  });
88
+ if (this.tileType === TILE3D_TYPE.GLTF) {
89
+ this._createMetadataExtensions(gltfBuilder, meshIndex, featureAttributes, attributeStorageInfo, tileContent);
90
+ }
79
91
  const transformMatrix = this._generateTransformMatrix(cartesianOrigin);
80
92
  const nodeIndex = gltfBuilder.addNode({ meshIndex, matrix: transformMatrix });
81
93
  const sceneIndex = gltfBuilder.addScene({ nodeIndices: [nodeIndex] });
82
94
  gltfBuilder.setDefaultScene(sceneIndex);
83
95
  gltfBuilder.createBinaryChunk();
84
- const gltfBuffer = encodeSync(gltfBuilder.gltf, GLTFWriter);
85
- return gltfBuffer;
96
+ return encodeSync(gltfBuilder.gltf, GLTFWriter, { gltfBuilder });
97
+ }
98
+ _createMetadataExtensions(gltfBuilder, meshIndex, featureAttributes, attributeStorageInfo, tileContent) {
99
+ const propertyAttributes = this._createPropertyAttibutes(featureAttributes, attributeStorageInfo);
100
+ const tableIndex = createExtStructuralMetadata(gltfBuilder, propertyAttributes);
101
+ const mesh = gltfBuilder.getMesh(meshIndex);
102
+ for (const primitive of mesh.primitives) {
103
+ if (tileContent.attributes._BATCHID?.value) {
104
+ createExtMeshFeatures(gltfBuilder, primitive, tileContent.attributes._BATCHID.value, tableIndex);
105
+ }
106
+ }
107
+ }
108
+ _createPropertyAttibutes(featureAttributes, attributeStorageInfo) {
109
+ if (!featureAttributes || !attributeStorageInfo) {
110
+ return [];
111
+ }
112
+ const propertyAttributeArray = [];
113
+ for (const attributeName in featureAttributes) {
114
+ const propertyAttribute = this._convertAttributeStorageInfoToPropertyAttribute(attributeName, attributeStorageInfo, featureAttributes);
115
+ if (propertyAttribute) {
116
+ propertyAttributeArray.push(propertyAttribute);
117
+ }
118
+ }
119
+ return propertyAttributeArray;
120
+ }
121
+ // eslint-disable-next-line complexity
122
+ _convertAttributeStorageInfoToPropertyAttribute(attributeName, attributeStorageInfo, featureAttributes) {
123
+ const attributeValues = featureAttributes[attributeName];
124
+ const info = attributeStorageInfo.find((e) => e.name === attributeName);
125
+ if (!info) {
126
+ return null;
127
+ }
128
+ const attributeMetadata = info.attributeValues;
129
+ if (!attributeMetadata?.valueType) {
130
+ return null;
131
+ }
132
+ let elementType;
133
+ let componentType;
134
+ switch (attributeMetadata.valueType.toLowerCase()) {
135
+ case 'oid32':
136
+ elementType = 'SCALAR';
137
+ componentType = 'UINT32';
138
+ break;
139
+ case 'int32':
140
+ elementType = 'SCALAR';
141
+ componentType = 'INT32';
142
+ break;
143
+ case 'uint32':
144
+ elementType = 'SCALAR';
145
+ componentType = 'UINT32';
146
+ break;
147
+ case 'int16':
148
+ elementType = 'SCALAR';
149
+ componentType = 'INT16';
150
+ break;
151
+ case 'uint16':
152
+ elementType = 'SCALAR';
153
+ componentType = 'UINT16';
154
+ break;
155
+ case 'float64':
156
+ elementType = 'SCALAR';
157
+ componentType = 'FLOAT64';
158
+ break;
159
+ case 'string':
160
+ elementType = 'STRING';
161
+ break;
162
+ default:
163
+ elementType = '';
164
+ break;
165
+ }
166
+ const propertyAttribute = {
167
+ name: attributeName,
168
+ elementType,
169
+ componentType,
170
+ values: []
171
+ };
172
+ if (isTypedArray(attributeValues)) {
173
+ propertyAttribute.values = Array.from(attributeValues);
174
+ }
175
+ else if (attributeValues !== null) {
176
+ propertyAttribute.values = attributeValues;
177
+ }
178
+ return propertyAttribute;
86
179
  }
87
180
  /**
88
181
  * Update gltfBuilder with texture from I3S tile
@@ -1 +1 @@
1
- {"version":3,"file":"load-i3s.d.ts","sourceRoot":"","sources":["../../../src/3d-tiles-converter/helpers/load-i3s.ts"],"names":[],"mappings":"AAAA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CAAC;AAE5E;;;;;;;GAOG;AACH,eAAO,MAAM,cAAc,kBACV,gBAAgB,GAAG,IAAI,cAC1B,aAAa,sBACL,gBAAgB,kBACpB,aAAa,GAAG,IAAI,KACnC,OAAO,CAAC,cAAc,GAAG,IAAI,CAuC/B,CAAC;AAEF;;;;GAIG;AACH,wBAAsB,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,GAAG,IAAI,CAAC,CAUzE;AAED;;;;;;GAMG;AACH,wBAAsB,eAAe,CACnC,GAAG,EAAE,MAAM,EACX,MAAM,EAAE,gBAAgB,EACxB,WAAW,EAAE,gBAAgB,EAC7B,UAAU,EAAE,aAAa,GAAG,IAAI,gBAUjC;AAED;;;;GAIG;AACH,wBAAsB,YAAY,CAAC,UAAU,EAAE,aAAa,GAAG,IAAI,GAAG,OAAO,CAAC,MAAM,CAAC,CAcpF"}
@@ -88,6 +88,7 @@ function printHelp() {
88
88
  console.log('--split-nodes [Prevent to merge similar materials that could lead to incorrect visualization (I3S to 3DTiles conversion only)]');
89
89
  console.log('--tileset [tileset.json file (3DTiles) / http://..../SceneServer/layers/0 resource (I3S)]');
90
90
  console.log('--input-type [tileset input type: I3S or 3DTILES]');
91
+ console.log('--output-version [3dtile version: 1.0 or 1.1, default: 1.1]. This option supports only 1.0/1.1 values for 3DTiles output. I3S output version setting is not supported yet.');
91
92
  console.log('--egm [location of Earth Gravity Model *.pgm file to convert heights from ellipsoidal to gravity-related format or "None" to not use it. A model file can be loaded from GeographicLib https://geographiclib.sourceforge.io/html/geoid.html], default: "./deps/egm2008-5.zip"');
92
93
  console.log('--token [Token for Cesium ION tilesets authentication]');
93
94
  console.log('--no-draco [Disable draco compression for geometry]');
@@ -114,6 +115,7 @@ async function convert(options) {
114
115
  await tiles3DConverter.convert({
115
116
  inputUrl: options.tileset,
116
117
  outputPath: options.output,
118
+ outputVersion: options.outputVersion,
117
119
  tilesetName: options.name,
118
120
  maxDepth: options.maxDepth,
119
121
  egmFilePath: options.egm,
@@ -163,6 +165,15 @@ function validateOptions(options, addHash) {
163
165
  inputType: {
164
166
  getMessage: () => console.log('Missed/Incorrect: --input-type [tileset input type: I3S or 3DTILES]'),
165
167
  condition: (value) => addHash || (Boolean(value) && Object.values(TILESET_TYPE).includes(value.toUpperCase()))
168
+ },
169
+ outputVersion: {
170
+ getMessage: () => console.log('Incorrect: --output-version [1.0 or 1.1] is for --input-type "I3S" only'),
171
+ condition: (value) => addHash ||
172
+ (Boolean(value) &&
173
+ Object.values(['1.0', '1.1']).includes(value) &&
174
+ Boolean(options.inputType === 'I3S')) ||
175
+ Boolean(options.inputType !== 'I3S') ||
176
+ Boolean(options.analyze)
166
177
  }
167
178
  };
168
179
  const exceptions = [];
@@ -188,6 +199,7 @@ function validateOptions(options, addHash) {
188
199
  function parseOptions(args) {
189
200
  const opts = {
190
201
  output: 'data',
202
+ outputVersion: '1.1',
191
203
  instantNodeWriting: false,
192
204
  mergeMaterials: true,
193
205
  egm: join(process.cwd(), 'deps', 'egm2008-5.pgm'),
@@ -215,6 +227,9 @@ function parseOptions(args) {
215
227
  case '--output':
216
228
  opts.output = getStringValue(index, args);
217
229
  break;
230
+ case '--output-version':
231
+ opts.outputVersion = getStringValue(index, args);
232
+ break;
218
233
  case '--instant-node-writing':
219
234
  opts.instantNodeWriting = getBooleanValue(index, args);
220
235
  break;