@loaders.gl/tile-converter 4.2.0-alpha.4 → 4.2.0-alpha.5
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 -3
- package/dist/3d-tiles-converter/3d-tiles-converter.d.ts.map +1 -1
- package/dist/3d-tiles-converter/3d-tiles-converter.js +329 -293
- package/dist/3d-tiles-converter/helpers/b3dm-converter.js +257 -200
- package/dist/3d-tiles-converter/helpers/i3s-obb-to-3d-tiles-obb.js +14 -5
- package/dist/3d-tiles-converter/helpers/load-i3s.js +106 -75
- package/dist/3d-tiles-converter/helpers/texture-atlas.js +44 -21
- package/dist/3d-tiles-converter/json-templates/tileset.js +32 -33
- package/dist/constants.js +0 -1
- package/dist/converter-cli.js +255 -234
- package/dist/converter.min.cjs +80 -90
- package/dist/deps-installer/deps-installer.js +72 -58
- package/dist/i3s-converter/helpers/attribute-metadata-info.js +207 -153
- package/dist/i3s-converter/helpers/batch-ids-extensions.d.ts +1 -1
- package/dist/i3s-converter/helpers/batch-ids-extensions.d.ts.map +1 -1
- package/dist/i3s-converter/helpers/batch-ids-extensions.js +145 -103
- package/dist/i3s-converter/helpers/coordinate-converter.js +100 -65
- package/dist/i3s-converter/helpers/create-scene-server-path.js +14 -9
- package/dist/i3s-converter/helpers/feature-attributes.js +168 -105
- package/dist/i3s-converter/helpers/geometry-attributes.d.ts +1 -1
- package/dist/i3s-converter/helpers/geometry-attributes.d.ts.map +1 -1
- package/dist/i3s-converter/helpers/geometry-attributes.js +204 -212
- package/dist/i3s-converter/helpers/geometry-converter.d.ts +2 -2
- package/dist/i3s-converter/helpers/geometry-converter.d.ts.map +1 -1
- package/dist/i3s-converter/helpers/geometry-converter.js +1148 -829
- package/dist/i3s-converter/helpers/gltf-attributes.d.ts +1 -1
- package/dist/i3s-converter/helpers/gltf-attributes.d.ts.map +1 -1
- package/dist/i3s-converter/helpers/gltf-attributes.js +111 -97
- package/dist/i3s-converter/helpers/load-3d-tiles.js +103 -66
- package/dist/i3s-converter/helpers/node-debug.js +98 -54
- package/dist/i3s-converter/helpers/node-index-document.d.ts +3 -3
- package/dist/i3s-converter/helpers/node-index-document.d.ts.map +1 -1
- package/dist/i3s-converter/helpers/node-index-document.js +248 -177
- package/dist/i3s-converter/helpers/node-pages.d.ts +1 -1
- package/dist/i3s-converter/helpers/node-pages.d.ts.map +1 -1
- package/dist/i3s-converter/helpers/node-pages.js +299 -194
- package/dist/i3s-converter/helpers/preprocess-3d-tiles.d.ts +1 -1
- package/dist/i3s-converter/helpers/preprocess-3d-tiles.d.ts.map +1 -1
- package/dist/i3s-converter/helpers/preprocess-3d-tiles.js +92 -60
- package/dist/i3s-converter/helpers/progress.js +134 -83
- package/dist/i3s-converter/helpers/tileset-traversal.d.ts +1 -1
- package/dist/i3s-converter/helpers/tileset-traversal.d.ts.map +1 -1
- package/dist/i3s-converter/helpers/tileset-traversal.js +24 -13
- package/dist/i3s-converter/i3s-converter.d.ts +7 -7
- package/dist/i3s-converter/i3s-converter.d.ts.map +1 -1
- package/dist/i3s-converter/i3s-converter.js +1044 -898
- package/dist/i3s-converter/json-templates/geometry-definitions.js +70 -79
- package/dist/i3s-converter/json-templates/layers.js +120 -121
- package/dist/i3s-converter/json-templates/metadata.js +19 -20
- package/dist/i3s-converter/json-templates/node.js +73 -71
- package/dist/i3s-converter/json-templates/scene-server.js +25 -26
- package/dist/i3s-converter/json-templates/shared-resources.js +107 -108
- package/dist/i3s-converter/json-templates/store.js +96 -94
- package/dist/i3s-converter/types.js +35 -23
- package/dist/i3s-server/app.js +15 -12
- package/dist/i3s-server/bin/www.js +14 -7
- package/dist/i3s-server/controllers/index-controller.js +18 -15
- package/dist/i3s-server/controllers/slpk-controller.js +22 -11
- package/dist/i3s-server/routes/index.js +9 -8
- package/dist/i3s-server/routes/slpk-router.js +18 -17
- package/dist/i3s-server/utils/create-scene-server.js +15 -10
- package/dist/i3s-server/utils/server-utils.js +49 -32
- package/dist/index.cjs +292 -851
- package/dist/index.cjs.map +7 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +0 -1
- package/dist/lib/json-schemas/conversion-dump-json-schema.js +243 -421
- package/dist/lib/utils/cli-utils.js +63 -36
- package/dist/lib/utils/compress-util.js +20 -15
- package/dist/lib/utils/conversion-dump.d.ts +1 -1
- package/dist/lib/utils/conversion-dump.d.ts.map +1 -1
- package/dist/lib/utils/conversion-dump.js +209 -187
- package/dist/lib/utils/file-utils.js +122 -74
- package/dist/lib/utils/geometry-utils.js +13 -7
- package/dist/lib/utils/lod-conversion-utils.js +65 -33
- package/dist/lib/utils/queue.js +12 -13
- package/dist/lib/utils/statistic-utills.d.ts +6 -23
- package/dist/lib/utils/statistic-utills.js +64 -59
- package/dist/lib/utils/write-queue.d.ts +2 -2
- package/dist/lib/utils/write-queue.d.ts.map +1 -1
- package/dist/lib/utils/write-queue.js +68 -86
- package/dist/pgm-loader.js +16 -12
- package/dist/slpk-extractor/slpk-extractor.js +59 -50
- package/dist/slpk-extractor-cli.js +82 -59
- package/package.json +18 -18
- package/dist/3d-tiles-converter/3d-tiles-converter.js.map +0 -1
- package/dist/3d-tiles-converter/helpers/b3dm-converter.js.map +0 -1
- package/dist/3d-tiles-converter/helpers/i3s-obb-to-3d-tiles-obb.js.map +0 -1
- package/dist/3d-tiles-converter/helpers/load-i3s.js.map +0 -1
- package/dist/3d-tiles-converter/helpers/texture-atlas.js.map +0 -1
- package/dist/3d-tiles-converter/json-templates/tileset.js.map +0 -1
- package/dist/constants.js.map +0 -1
- package/dist/converter-cli.js.map +0 -1
- package/dist/deps-installer/deps-installer.js.map +0 -1
- package/dist/i3s-converter/helpers/attribute-metadata-info.js.map +0 -1
- package/dist/i3s-converter/helpers/batch-ids-extensions.js.map +0 -1
- package/dist/i3s-converter/helpers/coordinate-converter.js.map +0 -1
- package/dist/i3s-converter/helpers/create-scene-server-path.js.map +0 -1
- package/dist/i3s-converter/helpers/feature-attributes.js.map +0 -1
- package/dist/i3s-converter/helpers/geometry-attributes.js.map +0 -1
- package/dist/i3s-converter/helpers/geometry-converter.js.map +0 -1
- package/dist/i3s-converter/helpers/gltf-attributes.js.map +0 -1
- package/dist/i3s-converter/helpers/load-3d-tiles.js.map +0 -1
- package/dist/i3s-converter/helpers/node-debug.js.map +0 -1
- package/dist/i3s-converter/helpers/node-index-document.js.map +0 -1
- package/dist/i3s-converter/helpers/node-pages.js.map +0 -1
- package/dist/i3s-converter/helpers/preprocess-3d-tiles.js.map +0 -1
- package/dist/i3s-converter/helpers/progress.js.map +0 -1
- package/dist/i3s-converter/helpers/tileset-traversal.js.map +0 -1
- package/dist/i3s-converter/i3s-converter.js.map +0 -1
- package/dist/i3s-converter/json-templates/geometry-definitions.js.map +0 -1
- package/dist/i3s-converter/json-templates/layers.js.map +0 -1
- package/dist/i3s-converter/json-templates/metadata.js.map +0 -1
- package/dist/i3s-converter/json-templates/node.js.map +0 -1
- package/dist/i3s-converter/json-templates/scene-server.js.map +0 -1
- package/dist/i3s-converter/json-templates/shared-resources.js.map +0 -1
- package/dist/i3s-converter/json-templates/store.js.map +0 -1
- package/dist/i3s-converter/types.js.map +0 -1
- package/dist/i3s-server/README.md +0 -63
- package/dist/i3s-server/app.js.map +0 -1
- package/dist/i3s-server/bin/www.js.map +0 -1
- package/dist/i3s-server/certs/cert.pem +0 -19
- package/dist/i3s-server/certs/key.pem +0 -27
- package/dist/i3s-server/controllers/index-controller.js.map +0 -1
- package/dist/i3s-server/controllers/slpk-controller.js.map +0 -1
- package/dist/i3s-server/routes/index.js.map +0 -1
- package/dist/i3s-server/routes/slpk-router.js.map +0 -1
- package/dist/i3s-server/utils/create-scene-server.js.map +0 -1
- package/dist/i3s-server/utils/server-utils.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/lib/json-schemas/conversion-dump-json-schema.js.map +0 -1
- package/dist/lib/utils/cli-utils.js.map +0 -1
- package/dist/lib/utils/compress-util.js.map +0 -1
- package/dist/lib/utils/conversion-dump.js.map +0 -1
- package/dist/lib/utils/file-utils.js.map +0 -1
- package/dist/lib/utils/geometry-utils.js.map +0 -1
- package/dist/lib/utils/lod-conversion-utils.js.map +0 -1
- package/dist/lib/utils/queue.js.map +0 -1
- package/dist/lib/utils/statistic-utills.js.map +0 -1
- package/dist/lib/utils/write-queue.js.map +0 -1
- package/dist/pgm-loader.js.map +0 -1
- package/dist/slpk-extractor/slpk-extractor.js.map +0 -1
- package/dist/slpk-extractor-cli.js.map +0 -1
|
@@ -17,312 +17,348 @@ import { getNodeCount, loadFromArchive, loadI3SContent, openSLPK } from "./helpe
|
|
|
17
17
|
import { ConversionDump } from "../lib/utils/conversion-dump.js";
|
|
18
18
|
import { Progress } from "../i3s-converter/helpers/progress.js";
|
|
19
19
|
const I3S = 'I3S';
|
|
20
|
+
/**
|
|
21
|
+
* Converter from i3s to 3d-tiles
|
|
22
|
+
*/
|
|
20
23
|
export default class Tiles3DConverter {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
this.options = {};
|
|
46
|
-
this.tilesetPath = '';
|
|
47
|
-
this.vertexCounter = 0;
|
|
48
|
-
this.conversionStartTime = [0, 0];
|
|
49
|
-
this.geoidHeightModel = null;
|
|
50
|
-
this.sourceTileset = null;
|
|
51
|
-
this.attributeStorageInfo = null;
|
|
52
|
-
this.workerSource = {};
|
|
53
|
-
this.conversionDump = new ConversionDump();
|
|
54
|
-
this.progress = new Progress();
|
|
55
|
-
}
|
|
56
|
-
async convert(options) {
|
|
57
|
-
var _this$sourceTileset;
|
|
58
|
-
if (isBrowser) {
|
|
59
|
-
console.log(BROWSER_ERROR_MESSAGE);
|
|
60
|
-
return BROWSER_ERROR_MESSAGE;
|
|
24
|
+
constructor() {
|
|
25
|
+
this.workerSource = {};
|
|
26
|
+
this.slpkFilesystem = null;
|
|
27
|
+
this.loaderOptions = {
|
|
28
|
+
_nodeWorkers: true,
|
|
29
|
+
reuseWorkers: true,
|
|
30
|
+
// TODO: converter freezes in the end because of i3s-content-worker
|
|
31
|
+
worker: false,
|
|
32
|
+
i3s: { coordinateSystem: COORDINATE_SYSTEM.LNGLAT_OFFSETS, decodeTextures: false },
|
|
33
|
+
// We need to load local fs workers because nodejs can't load workers from the Internet
|
|
34
|
+
'i3s-content': {
|
|
35
|
+
workerUrl: './modules/i3s/dist/i3s-content-worker-node.js'
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
this.options = {};
|
|
39
|
+
this.tilesetPath = '';
|
|
40
|
+
this.vertexCounter = 0;
|
|
41
|
+
this.conversionStartTime = [0, 0];
|
|
42
|
+
this.geoidHeightModel = null;
|
|
43
|
+
this.sourceTileset = null;
|
|
44
|
+
this.attributeStorageInfo = null;
|
|
45
|
+
this.workerSource = {};
|
|
46
|
+
this.conversionDump = new ConversionDump();
|
|
47
|
+
this.progress = new Progress();
|
|
61
48
|
}
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
49
|
+
/**
|
|
50
|
+
* Convert i3s format data to 3dTiles
|
|
51
|
+
* @param options
|
|
52
|
+
* @param options.inputUrl the url to read the tileset from
|
|
53
|
+
* @param options.outputPath the output filename
|
|
54
|
+
* @param options.tilesetName the output name of the tileset
|
|
55
|
+
* @param options.egmFilePath location of *.pgm file to convert heights from ellipsoidal to gravity-related format
|
|
56
|
+
* @param options.maxDepth The max tree depth of conversion
|
|
57
|
+
*/
|
|
58
|
+
async convert(options) {
|
|
59
|
+
if (isBrowser) {
|
|
60
|
+
console.log(BROWSER_ERROR_MESSAGE);
|
|
61
|
+
return BROWSER_ERROR_MESSAGE;
|
|
62
|
+
}
|
|
63
|
+
const { inputUrl, outputPath, tilesetName, maxDepth, egmFilePath, inquirer, analyze } = options;
|
|
64
|
+
this.conversionStartTime = process.hrtime();
|
|
65
|
+
this.options = { maxDepth, inquirer };
|
|
66
|
+
console.log('Loading egm file...'); // eslint-disable-line
|
|
67
|
+
this.geoidHeightModel = await load(egmFilePath, PGMLoader);
|
|
68
|
+
console.log('Loading egm file completed!'); // eslint-disable-line
|
|
69
|
+
this.slpkFilesystem = await openSLPK(inputUrl);
|
|
70
|
+
let preprocessResult = true;
|
|
71
|
+
if (analyze || this.slpkFilesystem) {
|
|
72
|
+
preprocessResult = await this.preprocessConversion();
|
|
73
|
+
if (!preprocessResult || analyze) {
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
this.progress.startMonitoring();
|
|
78
|
+
this.sourceTileset = await loadFromArchive(inputUrl, I3SLoader, {
|
|
79
|
+
...this.loaderOptions,
|
|
80
|
+
// @ts-expect-error `isTileset` can be boolean of 'auto' but TS expects a string
|
|
81
|
+
i3s: { ...this.loaderOptions.i3s, isTileset: true }
|
|
82
|
+
}, this.slpkFilesystem);
|
|
83
|
+
if (!this.sourceTileset) {
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
const rootNode = this.sourceTileset?.root;
|
|
87
|
+
if (!rootNode.obb) {
|
|
88
|
+
rootNode.obb = createObbFromMbs(rootNode.mbs);
|
|
89
|
+
}
|
|
90
|
+
this.tilesetPath = join(`${outputPath}`, `${tilesetName}`);
|
|
91
|
+
this.attributeStorageInfo = this.sourceTileset.attributeStorageInfo;
|
|
92
|
+
await this.conversionDump.createDump(options);
|
|
93
|
+
if (this.conversionDump.restored && this.options.inquirer) {
|
|
94
|
+
const result = await this.options.inquirer.prompt([
|
|
95
|
+
{
|
|
96
|
+
name: 'resumeConversion',
|
|
97
|
+
type: 'confirm',
|
|
98
|
+
message: 'Dump file of the previous conversion exists, do you want to resume that conversion?'
|
|
99
|
+
}
|
|
100
|
+
]);
|
|
101
|
+
if (!result.resumeConversion) {
|
|
102
|
+
this.conversionDump.reset();
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
// Removing the tilesetPath needed to exclude erroneous files after conversion
|
|
106
|
+
if (!this.conversionDump.restored) {
|
|
107
|
+
try {
|
|
108
|
+
await removeDir(this.tilesetPath);
|
|
109
|
+
}
|
|
110
|
+
catch (e) {
|
|
111
|
+
// do nothing
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
const rootTile = {
|
|
115
|
+
boundingVolume: {
|
|
116
|
+
box: i3sObbTo3dTilesObb(rootNode.obb, this.geoidHeightModel)
|
|
117
|
+
},
|
|
118
|
+
geometricError: convertScreenThresholdToGeometricError(rootNode),
|
|
119
|
+
children: [],
|
|
120
|
+
refine: 'REPLACE'
|
|
121
|
+
};
|
|
122
|
+
await this._addChildren(rootNode, rootTile, 1);
|
|
123
|
+
const tileset = transform({ root: rootTile }, tilesetTemplate());
|
|
124
|
+
await writeFile(this.tilesetPath, JSON.stringify(tileset), 'tileset.json');
|
|
125
|
+
await this.conversionDump.deleteDumpFile();
|
|
126
|
+
this.progress.stopMonitoring();
|
|
127
|
+
await this._finishConversion({ slpk: false, outputPath, tilesetName });
|
|
128
|
+
if (this.slpkFilesystem) {
|
|
129
|
+
this.slpkFilesystem.destroy();
|
|
130
|
+
}
|
|
131
|
+
// Clean up worker pools
|
|
132
|
+
const workerFarm = WorkerFarm.getWorkerFarm({});
|
|
133
|
+
workerFarm.destroy();
|
|
142
134
|
}
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
console.log(`Preprocess results:`);
|
|
152
|
-
if (this.slpkFilesystem) {
|
|
153
|
-
console.log(`Node count: ${nodesCount}`);
|
|
154
|
-
if (nodesCount === 0) {
|
|
155
|
-
console.log('Node count is 0. The conversion will be interrupted.');
|
|
135
|
+
/**
|
|
136
|
+
* Preprocess stage of the tile converter. Calculate number of nodes
|
|
137
|
+
* @returns true - the conversion is possible, false - the tileset's content is not supported
|
|
138
|
+
*/
|
|
139
|
+
async preprocessConversion() {
|
|
140
|
+
console.log(`Analyze source layer`);
|
|
141
|
+
const nodesCount = await getNodeCount(this.slpkFilesystem);
|
|
142
|
+
this.progress.stepsTotal = nodesCount;
|
|
156
143
|
console.log(`------------------------------------------------`);
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
child
|
|
172
|
-
} = this._createChildAndBoundingVolume(sourceChild);
|
|
173
|
-
parentNode.children.push(child);
|
|
174
|
-
await this._addChildren(sourceChild, child, level + 1);
|
|
175
|
-
return;
|
|
176
|
-
}
|
|
177
|
-
const content = await loadI3SContent(this.sourceTileset, sourceChild, this.loaderOptions, this.slpkFilesystem);
|
|
178
|
-
if (!content) {
|
|
179
|
-
await this._addChildren(sourceChild, parentNode, level + 1);
|
|
180
|
-
return;
|
|
181
|
-
}
|
|
182
|
-
this.vertexCounter += (content === null || content === void 0 ? void 0 : content.vertexCount) || 0;
|
|
183
|
-
let featureAttributes = null;
|
|
184
|
-
if (this.attributeStorageInfo) {
|
|
185
|
-
featureAttributes = await this._loadChildAttributes(sourceChild, this.attributeStorageInfo);
|
|
186
|
-
}
|
|
187
|
-
const {
|
|
188
|
-
child,
|
|
189
|
-
boundingVolume
|
|
190
|
-
} = this._createChildAndBoundingVolume(sourceChild);
|
|
191
|
-
const i3sAttributesData = {
|
|
192
|
-
tileContent: content,
|
|
193
|
-
box: boundingVolume.box || [],
|
|
194
|
-
textureFormat: sourceChild.textureFormat
|
|
195
|
-
};
|
|
196
|
-
const b3dmConverter = new B3dmConverter();
|
|
197
|
-
const b3dm = await b3dmConverter.convert(i3sAttributesData, featureAttributes);
|
|
198
|
-
await this.conversionDump.addNode(`${sourceChild.id}.b3dm`, sourceChild.id);
|
|
199
|
-
await writeFile(this.tilesetPath, new Uint8Array(b3dm), `${sourceChild.id}.b3dm`);
|
|
200
|
-
await this.conversionDump.updateConvertedNodesDumpFile(`${sourceChild.id}.b3dm`, sourceChild.id, true);
|
|
201
|
-
parentNode.children.push(child);
|
|
202
|
-
nextParentNode = child;
|
|
144
|
+
console.log(`Preprocess results:`);
|
|
145
|
+
if (this.slpkFilesystem) {
|
|
146
|
+
console.log(`Node count: ${nodesCount}`);
|
|
147
|
+
if (nodesCount === 0) {
|
|
148
|
+
console.log('Node count is 0. The conversion will be interrupted.');
|
|
149
|
+
console.log(`------------------------------------------------`);
|
|
150
|
+
return false;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
else {
|
|
154
|
+
console.log(`Node count cannot be calculated for the remote dataset`);
|
|
155
|
+
}
|
|
156
|
+
console.log(`------------------------------------------------`);
|
|
157
|
+
return true;
|
|
203
158
|
}
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
159
|
+
/**
|
|
160
|
+
* Convert particular I3S Node
|
|
161
|
+
* @param parentSourceNode the parent node tile object (@loaders.gl/tiles/Tile3D)
|
|
162
|
+
* @param parentNode object in resulting tileset
|
|
163
|
+
* @param level a current level of a tree depth
|
|
164
|
+
* @param childNodeInfo child node to convert
|
|
165
|
+
*/
|
|
166
|
+
async convertChildNode(parentSourceNode, parentNode, level, childNodeInfo) {
|
|
167
|
+
let nextParentNode = parentNode;
|
|
168
|
+
const sourceChild = await this._loadChildNode(parentSourceNode, childNodeInfo);
|
|
169
|
+
if (sourceChild.contentUrl) {
|
|
170
|
+
if (this.conversionDump.restored &&
|
|
171
|
+
this.conversionDump.isFileConversionComplete(`${sourceChild.id}.b3dm`) &&
|
|
172
|
+
(sourceChild.obb || sourceChild.mbs)) {
|
|
173
|
+
const { child } = this._createChildAndBoundingVolume(sourceChild);
|
|
174
|
+
parentNode.children.push(child);
|
|
175
|
+
await this._addChildren(sourceChild, child, level + 1);
|
|
176
|
+
return;
|
|
177
|
+
}
|
|
178
|
+
const content = await loadI3SContent(this.sourceTileset, sourceChild, this.loaderOptions, this.slpkFilesystem);
|
|
179
|
+
if (!content) {
|
|
180
|
+
await this._addChildren(sourceChild, parentNode, level + 1);
|
|
181
|
+
return;
|
|
182
|
+
}
|
|
183
|
+
this.vertexCounter += content?.vertexCount || 0;
|
|
184
|
+
let featureAttributes = null;
|
|
185
|
+
if (this.attributeStorageInfo) {
|
|
186
|
+
featureAttributes = await this._loadChildAttributes(sourceChild, this.attributeStorageInfo);
|
|
187
|
+
}
|
|
188
|
+
const { child, boundingVolume } = this._createChildAndBoundingVolume(sourceChild);
|
|
189
|
+
const i3sAttributesData = {
|
|
190
|
+
tileContent: content,
|
|
191
|
+
box: boundingVolume.box || [],
|
|
192
|
+
textureFormat: sourceChild.textureFormat
|
|
193
|
+
};
|
|
194
|
+
const b3dmConverter = new B3dmConverter();
|
|
195
|
+
const b3dm = await b3dmConverter.convert(i3sAttributesData, featureAttributes);
|
|
196
|
+
await this.conversionDump.addNode(`${sourceChild.id}.b3dm`, sourceChild.id);
|
|
197
|
+
await writeFile(this.tilesetPath, new Uint8Array(b3dm), `${sourceChild.id}.b3dm`);
|
|
198
|
+
await this.conversionDump.updateConvertedNodesDumpFile(`${sourceChild.id}.b3dm`, sourceChild.id, true);
|
|
199
|
+
parentNode.children.push(child);
|
|
200
|
+
nextParentNode = child;
|
|
201
|
+
}
|
|
202
|
+
this.progress.stepsDone += 1;
|
|
203
|
+
let timeRemainingString = 'Calculating time left...';
|
|
204
|
+
const timeRemaining = this.progress.getTimeRemainingString();
|
|
205
|
+
if (timeRemaining) {
|
|
206
|
+
timeRemainingString = `${timeRemaining} left`;
|
|
207
|
+
}
|
|
208
|
+
const percentString = this.progress.getPercentString();
|
|
209
|
+
const progressString = percentString ? ` ${percentString}%, ${timeRemainingString}` : '';
|
|
210
|
+
console.log(`[converted${progressString}]: ${childNodeInfo.id}`); // eslint-disable-line
|
|
211
|
+
await this._addChildren(sourceChild, nextParentNode, level + 1);
|
|
209
212
|
}
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
213
|
+
/**
|
|
214
|
+
* The recursive function of traversal of a nodes tree
|
|
215
|
+
* @param parentSourceNode the parent node tile object (@loaders.gl/tiles/Tile3D)
|
|
216
|
+
* @param parentNode object in resulting tileset
|
|
217
|
+
* @param level a current level of a tree depth
|
|
218
|
+
*/
|
|
219
|
+
async _addChildren(parentSourceNode, parentNode, level) {
|
|
220
|
+
if (this.options.maxDepth && level > this.options.maxDepth) {
|
|
221
|
+
return;
|
|
222
|
+
}
|
|
223
|
+
for (const childNodeInfo of parentSourceNode.children || []) {
|
|
224
|
+
await this.convertChildNode(parentSourceNode, parentNode, level, childNodeInfo);
|
|
225
|
+
}
|
|
218
226
|
}
|
|
219
|
-
|
|
220
|
-
|
|
227
|
+
/**
|
|
228
|
+
* Load a child node having information from the node header
|
|
229
|
+
* @param parentNode a parent node tile object (@loaders.gl/tiles/Tile3D)
|
|
230
|
+
* @param childNodeInfo child information from 3DNodeIndexDocument
|
|
231
|
+
* (https://github.com/Esri/i3s-spec/blob/master/docs/1.7/nodeReference.cmn.md)
|
|
232
|
+
*/
|
|
233
|
+
async _loadChildNode(parentNode, childNodeInfo) {
|
|
234
|
+
let header;
|
|
235
|
+
if (this.sourceTileset?.nodePagesTile) {
|
|
236
|
+
console.log(`Node conversion: ${childNodeInfo.id}`); // eslint-disable-line no-console,no-undef
|
|
237
|
+
header = await this.sourceTileset.nodePagesTile.formTileFromNodePages(parseInt(childNodeInfo.id));
|
|
238
|
+
}
|
|
239
|
+
else {
|
|
240
|
+
const nodeUrl = this._relativeUrlToFullUrl(parentNode.url, childNodeInfo.href);
|
|
241
|
+
// load metadata
|
|
242
|
+
const options = {
|
|
243
|
+
i3s: {
|
|
244
|
+
...this.loaderOptions,
|
|
245
|
+
// @ts-expect-error
|
|
246
|
+
isTileHeader: true,
|
|
247
|
+
loadContent: false
|
|
248
|
+
}
|
|
249
|
+
};
|
|
250
|
+
console.log(`Node conversion: ${nodeUrl}`); // eslint-disable-line no-console,no-undef
|
|
251
|
+
header = await loadFromArchive(nodeUrl, I3SLoader, options, this.slpkFilesystem);
|
|
252
|
+
}
|
|
253
|
+
return header;
|
|
221
254
|
}
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
const nodeUrl = this._relativeUrlToFullUrl(parentNode.url, childNodeInfo.href);
|
|
231
|
-
const options = {
|
|
232
|
-
i3s: {
|
|
233
|
-
...this.loaderOptions,
|
|
234
|
-
isTileHeader: true,
|
|
235
|
-
loadContent: false
|
|
255
|
+
/**
|
|
256
|
+
* Create child and child's boundingVolume for the converted node
|
|
257
|
+
* @param sourceChild
|
|
258
|
+
* @returns child and child's boundingVolume
|
|
259
|
+
*/
|
|
260
|
+
_createChildAndBoundingVolume(sourceChild) {
|
|
261
|
+
if (!sourceChild.obb) {
|
|
262
|
+
sourceChild.obb = createObbFromMbs(sourceChild.mbs);
|
|
236
263
|
}
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
264
|
+
const boundingVolume = {
|
|
265
|
+
box: i3sObbTo3dTilesObb(sourceChild.obb, this.geoidHeightModel)
|
|
266
|
+
};
|
|
267
|
+
const child = {
|
|
268
|
+
boundingVolume,
|
|
269
|
+
geometricError: convertScreenThresholdToGeometricError(sourceChild),
|
|
270
|
+
children: [],
|
|
271
|
+
content: {
|
|
272
|
+
uri: `${sourceChild.id}.b3dm`,
|
|
273
|
+
boundingVolume
|
|
274
|
+
}
|
|
275
|
+
};
|
|
276
|
+
return { boundingVolume, child };
|
|
240
277
|
}
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
278
|
+
/**
|
|
279
|
+
* Make an url of a resource from its relative url having the base url
|
|
280
|
+
* @param baseUrl the base url. A resulting url will be related from this url
|
|
281
|
+
* @param relativeUrl a realtive url of a resource
|
|
282
|
+
*/
|
|
283
|
+
_relativeUrlToFullUrl(baseUrl = '', relativeUrl) {
|
|
284
|
+
let resultArray = baseUrl.split('/');
|
|
285
|
+
const relativeUrlArray = relativeUrl.split('/');
|
|
286
|
+
for (const folder of relativeUrlArray) {
|
|
287
|
+
switch (folder) {
|
|
288
|
+
case '.':
|
|
289
|
+
continue; // eslint-disable-line no-continue
|
|
290
|
+
case '..':
|
|
291
|
+
resultArray = resultArray.slice(0, -1);
|
|
292
|
+
break;
|
|
293
|
+
default:
|
|
294
|
+
resultArray.push(folder);
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
return resultArray.join('/');
|
|
246
298
|
}
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
const relativeUrlArray = relativeUrl.split('/');
|
|
269
|
-
for (const folder of relativeUrlArray) {
|
|
270
|
-
switch (folder) {
|
|
271
|
-
case '.':
|
|
272
|
-
continue;
|
|
273
|
-
case '..':
|
|
274
|
-
resultArray = resultArray.slice(0, -1);
|
|
275
|
-
break;
|
|
276
|
-
default:
|
|
277
|
-
resultArray.push(folder);
|
|
278
|
-
}
|
|
299
|
+
/**
|
|
300
|
+
* Do loading all attributes related to particular node.
|
|
301
|
+
* @param sourceChild
|
|
302
|
+
* @param attributeStorageInfo
|
|
303
|
+
* @returns Promise of attributes object.
|
|
304
|
+
*/
|
|
305
|
+
async _loadChildAttributes(sourceChild, attributeStorageInfo) {
|
|
306
|
+
const promises = [];
|
|
307
|
+
const { attributeUrls = [] } = sourceChild;
|
|
308
|
+
for (let index = 0; index < attributeUrls.length; index++) {
|
|
309
|
+
const inputUrl = attributeUrls[index];
|
|
310
|
+
const attribute = attributeStorageInfo[index];
|
|
311
|
+
const options = {
|
|
312
|
+
attributeName: attribute.name,
|
|
313
|
+
attributeType: this._getAttributeType(attribute)
|
|
314
|
+
};
|
|
315
|
+
promises.push(loadFromArchive(inputUrl, I3SAttributeLoader, options, this.slpkFilesystem));
|
|
316
|
+
}
|
|
317
|
+
const attributesList = await Promise.all(promises);
|
|
318
|
+
this._replaceNestedArrays(attributesList);
|
|
319
|
+
return Object.assign({}, ...attributesList);
|
|
279
320
|
}
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
321
|
+
/**
|
|
322
|
+
* Returns attribute type for loading attributes
|
|
323
|
+
* @param attribute
|
|
324
|
+
* Workaround for I3S v1.6. There is no attribute.attributeValues.valueType field in attribute.
|
|
325
|
+
* There is an 'Oid32' type if attribute has objectIds property.
|
|
326
|
+
* Doc: https://github.com/Esri/i3s-spec/blob/master/docs/1.6/attributeStorageInfo.cmn.md
|
|
327
|
+
*/
|
|
328
|
+
_getAttributeType(attribute) {
|
|
329
|
+
if (attribute.attributeValues) {
|
|
330
|
+
return attribute.attributeValues.valueType;
|
|
331
|
+
}
|
|
332
|
+
else if (attribute.objectIds) {
|
|
333
|
+
return 'Oid32';
|
|
334
|
+
}
|
|
335
|
+
return '';
|
|
295
336
|
}
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
337
|
+
/**
|
|
338
|
+
* Make simple arrays from attribute typed arrays.
|
|
339
|
+
* @param attributesList
|
|
340
|
+
*/
|
|
341
|
+
_replaceNestedArrays(attributesList) {
|
|
342
|
+
for (let index = 0; index < attributesList.length; index++) {
|
|
343
|
+
const attributeObject = attributesList[index];
|
|
344
|
+
for (const key in attributeObject) {
|
|
345
|
+
attributeObject[key] = Array.from(attributeObject[key]);
|
|
346
|
+
}
|
|
347
|
+
}
|
|
305
348
|
}
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
349
|
+
/**
|
|
350
|
+
* Print statistics in the end of conversion
|
|
351
|
+
* @param params - output files data
|
|
352
|
+
*/
|
|
353
|
+
async _finishConversion(params) {
|
|
354
|
+
const filesSize = await calculateFilesSize(params);
|
|
355
|
+
const diff = process.hrtime(this.conversionStartTime);
|
|
356
|
+
const conversionTime = timeConverter(diff);
|
|
357
|
+
console.log(`------------------------------------------------`); // eslint-disable-line
|
|
358
|
+
console.log(`Finish conversion of ${I3S}`); // eslint-disable-line
|
|
359
|
+
console.log(`Total conversion time: ${conversionTime}`); // eslint-disable-line
|
|
360
|
+
console.log(`Vertex count: `, this.vertexCounter); // eslint-disable-line
|
|
361
|
+
console.log(`File(s) size: `, filesSize, ' bytes'); // eslint-disable-line
|
|
362
|
+
console.log(`------------------------------------------------`); // eslint-disable-line
|
|
314
363
|
}
|
|
315
|
-
}
|
|
316
|
-
async _finishConversion(params) {
|
|
317
|
-
const filesSize = await calculateFilesSize(params);
|
|
318
|
-
const diff = process.hrtime(this.conversionStartTime);
|
|
319
|
-
const conversionTime = timeConverter(diff);
|
|
320
|
-
console.log(`------------------------------------------------`);
|
|
321
|
-
console.log(`Finish conversion of ${I3S}`);
|
|
322
|
-
console.log(`Total conversion time: ${conversionTime}`);
|
|
323
|
-
console.log(`Vertex count: `, this.vertexCounter);
|
|
324
|
-
console.log(`File(s) size: `, filesSize, ' bytes');
|
|
325
|
-
console.log(`------------------------------------------------`);
|
|
326
|
-
}
|
|
327
364
|
}
|
|
328
|
-
//# sourceMappingURL=3d-tiles-converter.js.map
|