@loaders.gl/tile-converter 4.3.0-alpha.6 → 4.3.0-alpha.8
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.
- package/dist/3d-tiles-converter/3d-tiles-converter.d.ts +3 -0
- package/dist/3d-tiles-converter/3d-tiles-converter.d.ts.map +1 -1
- package/dist/3d-tiles-converter/3d-tiles-converter.js +15 -11
- package/dist/3d-tiles-converter/helpers/{b3dm-converter.d.ts → 3d-tiles-content-converter.d.ts} +13 -6
- package/dist/3d-tiles-converter/helpers/3d-tiles-content-converter.d.ts.map +1 -0
- package/dist/3d-tiles-converter/helpers/{b3dm-converter.js → 3d-tiles-content-converter.js} +110 -16
- package/dist/converter-cli.js +15 -0
- package/dist/converter.min.cjs +95 -95
- package/dist/deps-installer/deps-installer.d.ts.map +1 -1
- package/dist/deps-installer/deps-installer.js +4 -3
- package/dist/i3s-converter/i3s-converter.d.ts.map +1 -1
- package/dist/i3s-converter/i3s-converter.js +6 -1
- package/dist/i3s-server/bin/www.js +2 -0
- package/dist/index.cjs +132 -30
- package/dist/index.cjs.map +4 -4
- package/dist/lib/utils/conversion-dump.d.ts +1 -0
- package/dist/lib/utils/conversion-dump.d.ts.map +1 -1
- package/dist/lib/utils/conversion-dump.js +3 -2
- package/dist/pgm-loader.js +1 -1
- package/package.json +20 -20
- package/src/3d-tiles-converter/3d-tiles-converter.ts +40 -14
- package/src/3d-tiles-converter/helpers/{b3dm-converter.ts → 3d-tiles-content-converter.ts} +157 -20
- package/src/converter-cli.ts +22 -0
- package/src/deps-installer/deps-installer.ts +3 -2
- package/src/i3s-converter/i3s-converter.ts +6 -1
- package/src/i3s-server/bin/www.ts +2 -0
- package/src/lib/utils/conversion-dump.ts +5 -2
- 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,
|
|
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,EAEjB,MAAM,iBAAiB,CAAC;AAQzB,OAAO,EAAC,KAAK,EAAC,MAAM,gBAAgB,CAAC;AAiBrC,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;IACnB,OAAO,EAAE,MAAM,CAAC;;IAgBhB;;;;;;;;;OASG;IAEU,OAAO,CAAC,OAAO,EAAE;QAC5B,QAAQ,EAAE,MAAM,CAAC;QACjB,UAAU,EAAE,MAAM,CAAC;QACnB,WAAW,EAAE,MAAM,CAAC;QACpB,aAAa,CAAC,EAAE,MAAM,CAAC;QACvB,QAAQ,CAAC,EAAE,MAAM,CAAC;QAClB,WAAW,EAAE,MAAM,CAAC;QACpB,QAAQ,CAAC,EAAE;YAAC,MAAM,EAAE,YAAY,CAAA;SAAC,CAAC;QAClC,OAAO,CAAC,EAAE,OAAO,CAAC;KACnB,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC;IA8G/B;;;OAGG;YACW,oBAAoB;IA8BlC;;;;;;OAMG;YAEW,gBAAgB;IAiF9B;;;;;OAKG;YACW,YAAY;IAa1B;;;;;OAKG;YACW,cAAc;IA4B5B;;;;OAIG;IACH,OAAO,CAAC,6BAA6B;IAsBrC;;;;OAIG;IACH,OAAO,CAAC,qBAAqB;IAiB7B;;;;;OAKG;YACW,oBAAoB;IAsBlC;;;;;;OAMG;IACH,OAAO,CAAC,iBAAiB;IASzB;;;OAGG;IACH,OAAO,CAAC,oBAAoB;IAU5B;;;OAGG;YACW,iBAAiB;CAgBhC"}
|
|
@@ -12,7 +12,7 @@ import { TILESET as tilesetTemplate } from "./json-templates/tileset.js";
|
|
|
12
12
|
import { createObbFromMbs } from "../i3s-converter/helpers/coordinate-converter.js";
|
|
13
13
|
import { WorkerFarm } from '@loaders.gl/worker-utils';
|
|
14
14
|
import { BROWSER_ERROR_MESSAGE } from "../constants.js";
|
|
15
|
-
import
|
|
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}.
|
|
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
|
|
215
|
-
const
|
|
216
|
-
await this.conversionDump.addNode(`${sourceChild.id}.
|
|
217
|
-
await writeFile(this.tilesetPath, new Uint8Array(
|
|
218
|
-
await this.conversionDump.updateConvertedNodesDumpFile(`${sourceChild.id}.
|
|
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}.
|
|
296
|
+
uri: `${sourceChild.id}.${this.fileExt}`,
|
|
293
297
|
boundingVolume
|
|
294
298
|
}
|
|
295
299
|
};
|
package/dist/3d-tiles-converter/helpers/{b3dm-converter.d.ts → 3d-tiles-content-converter.d.ts}
RENAMED
|
@@ -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
|
|
9
|
+
* Converts content of an I3S node to 3D Tiles file content
|
|
10
10
|
*/
|
|
11
|
-
export
|
|
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?:
|
|
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:
|
|
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=
|
|
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;AAW7F,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,9 @@
|
|
|
1
1
|
import { encodeSync } from '@loaders.gl/core';
|
|
2
|
-
import { GLTFScenegraph, GLTFWriter } from '@loaders.gl/gltf';
|
|
2
|
+
import { GLTFScenegraph, GLTFWriter, createExtStructuralMetadata, createExtMeshFeatures } from '@loaders.gl/gltf';
|
|
3
3
|
import { Tile3DWriter } from '@loaders.gl/3d-tiles';
|
|
4
|
+
import { TILE3D_TYPE } from '@loaders.gl/3d-tiles';
|
|
4
5
|
import { Matrix4, Vector3 } from '@math.gl/core';
|
|
6
|
+
import { isTypedArray } from '@math.gl/types';
|
|
5
7
|
import { Ellipsoid } from '@math.gl/geospatial';
|
|
6
8
|
import { convertTextureAtlas } from "./texture-atlas.js";
|
|
7
9
|
import { generateSyntheticIndices } from "../../lib/utils/geometry-utils.js";
|
|
@@ -11,34 +13,42 @@ const KHR_MATERIALS_UNLIT = 'KHR_materials_unlit';
|
|
|
11
13
|
const METALLIC_FACTOR_DEFAULT = 1.0;
|
|
12
14
|
const ROUGHNESS_FACTOR_DEFAULT = 1.0;
|
|
13
15
|
/**
|
|
14
|
-
* Converts content of an I3S node to
|
|
16
|
+
* Converts content of an I3S node to 3D Tiles file content
|
|
15
17
|
*/
|
|
16
|
-
export
|
|
18
|
+
export class Tiles3DContentConverter {
|
|
17
19
|
// @ts-expect-error
|
|
18
20
|
rtcCenter;
|
|
19
21
|
i3sTile;
|
|
22
|
+
tileType;
|
|
23
|
+
constructor(options = { outputVersion: '1.1' }) {
|
|
24
|
+
this.tileType =
|
|
25
|
+
options.outputVersion === '1.0' ? TILE3D_TYPE.BATCHED_3D_MODEL : TILE3D_TYPE.GLTF;
|
|
26
|
+
}
|
|
20
27
|
/**
|
|
21
28
|
* The starter of content conversion
|
|
22
29
|
* @param i3sTile - Tile3D instance for I3S node
|
|
23
30
|
* @returns - encoded content
|
|
24
31
|
*/
|
|
25
|
-
async convert(i3sAttributesData, featureAttributes = null) {
|
|
26
|
-
const gltf = await this.buildGLTF(i3sAttributesData, featureAttributes);
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
32
|
+
async convert(i3sAttributesData, featureAttributes = null, attributeStorageInfo) {
|
|
33
|
+
const gltf = await this.buildGLTF(i3sAttributesData, featureAttributes, attributeStorageInfo);
|
|
34
|
+
if (this.tileType === TILE3D_TYPE.BATCHED_3D_MODEL) {
|
|
35
|
+
const b3dm = encodeSync({
|
|
36
|
+
gltfEncoded: new Uint8Array(gltf),
|
|
37
|
+
type: 'b3dm',
|
|
38
|
+
featuresLength: this._getFeaturesLength(featureAttributes),
|
|
39
|
+
batchTable: featureAttributes
|
|
40
|
+
}, Tile3DWriter);
|
|
41
|
+
return b3dm;
|
|
42
|
+
}
|
|
43
|
+
return gltf;
|
|
34
44
|
}
|
|
35
45
|
/**
|
|
36
46
|
* Build and encode gltf
|
|
37
47
|
* @param i3sTile - Tile3D instance for I3S node
|
|
38
48
|
* @returns - encoded glb content
|
|
39
49
|
*/
|
|
40
|
-
// eslint-disable-next-line max-statements
|
|
41
|
-
async buildGLTF(i3sAttributesData, featureAttributes) {
|
|
50
|
+
// eslint-disable-next-line complexity, max-statements
|
|
51
|
+
async buildGLTF(i3sAttributesData, featureAttributes, attributeStorageInfo) {
|
|
42
52
|
const { tileContent, textureFormat, box } = i3sAttributesData;
|
|
43
53
|
const { material, attributes, indices: originalIndices, modelMatrix } = tileContent;
|
|
44
54
|
const gltfBuilder = new GLTFScenegraph();
|
|
@@ -76,13 +86,97 @@ export default class B3dmConverter {
|
|
|
76
86
|
material: materialIndex,
|
|
77
87
|
mode: 4
|
|
78
88
|
});
|
|
89
|
+
if (this.tileType === TILE3D_TYPE.GLTF) {
|
|
90
|
+
this._createMetadataExtensions(gltfBuilder, meshIndex, featureAttributes, attributeStorageInfo, tileContent);
|
|
91
|
+
}
|
|
79
92
|
const transformMatrix = this._generateTransformMatrix(cartesianOrigin);
|
|
80
93
|
const nodeIndex = gltfBuilder.addNode({ meshIndex, matrix: transformMatrix });
|
|
81
94
|
const sceneIndex = gltfBuilder.addScene({ nodeIndices: [nodeIndex] });
|
|
82
95
|
gltfBuilder.setDefaultScene(sceneIndex);
|
|
83
96
|
gltfBuilder.createBinaryChunk();
|
|
84
|
-
|
|
85
|
-
|
|
97
|
+
return encodeSync(gltfBuilder.gltf, GLTFWriter, { gltfBuilder });
|
|
98
|
+
}
|
|
99
|
+
_createMetadataExtensions(gltfBuilder, meshIndex, featureAttributes, attributeStorageInfo, tileContent) {
|
|
100
|
+
const propertyAttributes = this._createPropertyAttibutes(featureAttributes, attributeStorageInfo);
|
|
101
|
+
const tableIndex = createExtStructuralMetadata(gltfBuilder, propertyAttributes);
|
|
102
|
+
const mesh = gltfBuilder.getMesh(meshIndex);
|
|
103
|
+
for (const primitive of mesh.primitives) {
|
|
104
|
+
if (tileContent.attributes._BATCHID?.value) {
|
|
105
|
+
createExtMeshFeatures(gltfBuilder, primitive, tileContent.attributes._BATCHID.value, tableIndex);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
_createPropertyAttibutes(featureAttributes, attributeStorageInfo) {
|
|
110
|
+
if (!featureAttributes || !attributeStorageInfo) {
|
|
111
|
+
return [];
|
|
112
|
+
}
|
|
113
|
+
const propertyAttributeArray = [];
|
|
114
|
+
for (const attributeName in featureAttributes) {
|
|
115
|
+
const propertyAttribute = this._convertAttributeStorageInfoToPropertyAttribute(attributeName, attributeStorageInfo, featureAttributes);
|
|
116
|
+
if (propertyAttribute) {
|
|
117
|
+
propertyAttributeArray.push(propertyAttribute);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
return propertyAttributeArray;
|
|
121
|
+
}
|
|
122
|
+
// eslint-disable-next-line complexity
|
|
123
|
+
_convertAttributeStorageInfoToPropertyAttribute(attributeName, attributeStorageInfo, featureAttributes) {
|
|
124
|
+
const attributeValues = featureAttributes[attributeName];
|
|
125
|
+
const info = attributeStorageInfo.find((e) => e.name === attributeName);
|
|
126
|
+
if (!info) {
|
|
127
|
+
return null;
|
|
128
|
+
}
|
|
129
|
+
const attributeMetadata = info.attributeValues;
|
|
130
|
+
if (!attributeMetadata?.valueType) {
|
|
131
|
+
return null;
|
|
132
|
+
}
|
|
133
|
+
let elementType;
|
|
134
|
+
let componentType;
|
|
135
|
+
switch (attributeMetadata.valueType.toLowerCase()) {
|
|
136
|
+
case 'oid32':
|
|
137
|
+
elementType = 'SCALAR';
|
|
138
|
+
componentType = 'UINT32';
|
|
139
|
+
break;
|
|
140
|
+
case 'int32':
|
|
141
|
+
elementType = 'SCALAR';
|
|
142
|
+
componentType = 'INT32';
|
|
143
|
+
break;
|
|
144
|
+
case 'uint32':
|
|
145
|
+
elementType = 'SCALAR';
|
|
146
|
+
componentType = 'UINT32';
|
|
147
|
+
break;
|
|
148
|
+
case 'int16':
|
|
149
|
+
elementType = 'SCALAR';
|
|
150
|
+
componentType = 'INT16';
|
|
151
|
+
break;
|
|
152
|
+
case 'uint16':
|
|
153
|
+
elementType = 'SCALAR';
|
|
154
|
+
componentType = 'UINT16';
|
|
155
|
+
break;
|
|
156
|
+
case 'float64':
|
|
157
|
+
elementType = 'SCALAR';
|
|
158
|
+
componentType = 'FLOAT64';
|
|
159
|
+
break;
|
|
160
|
+
case 'string':
|
|
161
|
+
elementType = 'STRING';
|
|
162
|
+
break;
|
|
163
|
+
default:
|
|
164
|
+
elementType = '';
|
|
165
|
+
break;
|
|
166
|
+
}
|
|
167
|
+
const propertyAttribute = {
|
|
168
|
+
name: attributeName,
|
|
169
|
+
elementType,
|
|
170
|
+
componentType,
|
|
171
|
+
values: []
|
|
172
|
+
};
|
|
173
|
+
if (isTypedArray(attributeValues)) {
|
|
174
|
+
propertyAttribute.values = Array.from(attributeValues);
|
|
175
|
+
}
|
|
176
|
+
else if (attributeValues !== null) {
|
|
177
|
+
propertyAttribute.values = attributeValues;
|
|
178
|
+
}
|
|
179
|
+
return propertyAttribute;
|
|
86
180
|
}
|
|
87
181
|
/**
|
|
88
182
|
* Update gltfBuilder with texture from I3S tile
|
package/dist/converter-cli.js
CHANGED
|
@@ -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;
|