@loaders.gl/tile-converter 4.2.0-alpha.3 → 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.
Files changed (144) hide show
  1. package/dist/3d-tiles-converter/3d-tiles-converter.d.ts +3 -3
  2. package/dist/3d-tiles-converter/3d-tiles-converter.d.ts.map +1 -1
  3. package/dist/3d-tiles-converter/3d-tiles-converter.js +329 -293
  4. package/dist/3d-tiles-converter/helpers/b3dm-converter.js +257 -200
  5. package/dist/3d-tiles-converter/helpers/i3s-obb-to-3d-tiles-obb.js +14 -5
  6. package/dist/3d-tiles-converter/helpers/load-i3s.js +106 -75
  7. package/dist/3d-tiles-converter/helpers/texture-atlas.js +44 -21
  8. package/dist/3d-tiles-converter/json-templates/tileset.js +32 -33
  9. package/dist/constants.js +0 -1
  10. package/dist/converter-cli.js +255 -234
  11. package/dist/converter.min.cjs +80 -90
  12. package/dist/deps-installer/deps-installer.js +73 -59
  13. package/dist/i3s-converter/helpers/attribute-metadata-info.js +207 -153
  14. package/dist/i3s-converter/helpers/batch-ids-extensions.d.ts +1 -1
  15. package/dist/i3s-converter/helpers/batch-ids-extensions.d.ts.map +1 -1
  16. package/dist/i3s-converter/helpers/batch-ids-extensions.js +145 -103
  17. package/dist/i3s-converter/helpers/coordinate-converter.js +100 -65
  18. package/dist/i3s-converter/helpers/create-scene-server-path.js +14 -9
  19. package/dist/i3s-converter/helpers/feature-attributes.js +168 -105
  20. package/dist/i3s-converter/helpers/geometry-attributes.d.ts +1 -1
  21. package/dist/i3s-converter/helpers/geometry-attributes.d.ts.map +1 -1
  22. package/dist/i3s-converter/helpers/geometry-attributes.js +204 -212
  23. package/dist/i3s-converter/helpers/geometry-converter.d.ts +2 -2
  24. package/dist/i3s-converter/helpers/geometry-converter.d.ts.map +1 -1
  25. package/dist/i3s-converter/helpers/geometry-converter.js +1148 -829
  26. package/dist/i3s-converter/helpers/gltf-attributes.d.ts +1 -1
  27. package/dist/i3s-converter/helpers/gltf-attributes.d.ts.map +1 -1
  28. package/dist/i3s-converter/helpers/gltf-attributes.js +111 -97
  29. package/dist/i3s-converter/helpers/load-3d-tiles.js +103 -66
  30. package/dist/i3s-converter/helpers/node-debug.js +98 -54
  31. package/dist/i3s-converter/helpers/node-index-document.d.ts +3 -3
  32. package/dist/i3s-converter/helpers/node-index-document.d.ts.map +1 -1
  33. package/dist/i3s-converter/helpers/node-index-document.js +248 -177
  34. package/dist/i3s-converter/helpers/node-pages.d.ts +1 -1
  35. package/dist/i3s-converter/helpers/node-pages.d.ts.map +1 -1
  36. package/dist/i3s-converter/helpers/node-pages.js +299 -194
  37. package/dist/i3s-converter/helpers/preprocess-3d-tiles.d.ts +1 -1
  38. package/dist/i3s-converter/helpers/preprocess-3d-tiles.d.ts.map +1 -1
  39. package/dist/i3s-converter/helpers/preprocess-3d-tiles.js +92 -60
  40. package/dist/i3s-converter/helpers/progress.js +134 -83
  41. package/dist/i3s-converter/helpers/tileset-traversal.d.ts +1 -1
  42. package/dist/i3s-converter/helpers/tileset-traversal.d.ts.map +1 -1
  43. package/dist/i3s-converter/helpers/tileset-traversal.js +24 -13
  44. package/dist/i3s-converter/i3s-converter.d.ts +7 -7
  45. package/dist/i3s-converter/i3s-converter.d.ts.map +1 -1
  46. package/dist/i3s-converter/i3s-converter.js +1044 -898
  47. package/dist/i3s-converter/json-templates/geometry-definitions.js +70 -79
  48. package/dist/i3s-converter/json-templates/layers.js +120 -121
  49. package/dist/i3s-converter/json-templates/metadata.js +19 -20
  50. package/dist/i3s-converter/json-templates/node.js +73 -71
  51. package/dist/i3s-converter/json-templates/scene-server.js +25 -26
  52. package/dist/i3s-converter/json-templates/shared-resources.js +107 -108
  53. package/dist/i3s-converter/json-templates/store.js +96 -94
  54. package/dist/i3s-converter/types.js +35 -23
  55. package/dist/i3s-server/app.js +15 -12
  56. package/dist/i3s-server/bin/www.js +14 -7
  57. package/dist/i3s-server/controllers/index-controller.js +18 -15
  58. package/dist/i3s-server/controllers/slpk-controller.js +22 -11
  59. package/dist/i3s-server/routes/index.js +9 -8
  60. package/dist/i3s-server/routes/slpk-router.js +18 -17
  61. package/dist/i3s-server/utils/create-scene-server.js +15 -10
  62. package/dist/i3s-server/utils/server-utils.js +49 -32
  63. package/dist/index.cjs +292 -851
  64. package/dist/index.cjs.map +7 -0
  65. package/dist/index.d.ts +2 -2
  66. package/dist/index.d.ts.map +1 -1
  67. package/dist/index.js +0 -1
  68. package/dist/lib/json-schemas/conversion-dump-json-schema.js +243 -421
  69. package/dist/lib/utils/cli-utils.js +63 -36
  70. package/dist/lib/utils/compress-util.js +20 -15
  71. package/dist/lib/utils/conversion-dump.d.ts +1 -1
  72. package/dist/lib/utils/conversion-dump.d.ts.map +1 -1
  73. package/dist/lib/utils/conversion-dump.js +209 -187
  74. package/dist/lib/utils/file-utils.js +122 -74
  75. package/dist/lib/utils/geometry-utils.js +13 -7
  76. package/dist/lib/utils/lod-conversion-utils.js +65 -33
  77. package/dist/lib/utils/queue.js +12 -13
  78. package/dist/lib/utils/statistic-utills.d.ts +6 -23
  79. package/dist/lib/utils/statistic-utills.js +64 -59
  80. package/dist/lib/utils/write-queue.d.ts +2 -2
  81. package/dist/lib/utils/write-queue.d.ts.map +1 -1
  82. package/dist/lib/utils/write-queue.js +68 -86
  83. package/dist/pgm-loader.js +17 -13
  84. package/dist/slpk-extractor/slpk-extractor.js +59 -50
  85. package/dist/slpk-extractor-cli.js +82 -59
  86. package/package.json +18 -18
  87. package/dist/3d-tiles-converter/3d-tiles-converter.js.map +0 -1
  88. package/dist/3d-tiles-converter/helpers/b3dm-converter.js.map +0 -1
  89. package/dist/3d-tiles-converter/helpers/i3s-obb-to-3d-tiles-obb.js.map +0 -1
  90. package/dist/3d-tiles-converter/helpers/load-i3s.js.map +0 -1
  91. package/dist/3d-tiles-converter/helpers/texture-atlas.js.map +0 -1
  92. package/dist/3d-tiles-converter/json-templates/tileset.js.map +0 -1
  93. package/dist/constants.js.map +0 -1
  94. package/dist/converter-cli.js.map +0 -1
  95. package/dist/deps-installer/deps-installer.js.map +0 -1
  96. package/dist/i3s-converter/helpers/attribute-metadata-info.js.map +0 -1
  97. package/dist/i3s-converter/helpers/batch-ids-extensions.js.map +0 -1
  98. package/dist/i3s-converter/helpers/coordinate-converter.js.map +0 -1
  99. package/dist/i3s-converter/helpers/create-scene-server-path.js.map +0 -1
  100. package/dist/i3s-converter/helpers/feature-attributes.js.map +0 -1
  101. package/dist/i3s-converter/helpers/geometry-attributes.js.map +0 -1
  102. package/dist/i3s-converter/helpers/geometry-converter.js.map +0 -1
  103. package/dist/i3s-converter/helpers/gltf-attributes.js.map +0 -1
  104. package/dist/i3s-converter/helpers/load-3d-tiles.js.map +0 -1
  105. package/dist/i3s-converter/helpers/node-debug.js.map +0 -1
  106. package/dist/i3s-converter/helpers/node-index-document.js.map +0 -1
  107. package/dist/i3s-converter/helpers/node-pages.js.map +0 -1
  108. package/dist/i3s-converter/helpers/preprocess-3d-tiles.js.map +0 -1
  109. package/dist/i3s-converter/helpers/progress.js.map +0 -1
  110. package/dist/i3s-converter/helpers/tileset-traversal.js.map +0 -1
  111. package/dist/i3s-converter/i3s-converter.js.map +0 -1
  112. package/dist/i3s-converter/json-templates/geometry-definitions.js.map +0 -1
  113. package/dist/i3s-converter/json-templates/layers.js.map +0 -1
  114. package/dist/i3s-converter/json-templates/metadata.js.map +0 -1
  115. package/dist/i3s-converter/json-templates/node.js.map +0 -1
  116. package/dist/i3s-converter/json-templates/scene-server.js.map +0 -1
  117. package/dist/i3s-converter/json-templates/shared-resources.js.map +0 -1
  118. package/dist/i3s-converter/json-templates/store.js.map +0 -1
  119. package/dist/i3s-converter/types.js.map +0 -1
  120. package/dist/i3s-server/README.md +0 -63
  121. package/dist/i3s-server/app.js.map +0 -1
  122. package/dist/i3s-server/bin/www.js.map +0 -1
  123. package/dist/i3s-server/certs/cert.pem +0 -19
  124. package/dist/i3s-server/certs/key.pem +0 -27
  125. package/dist/i3s-server/controllers/index-controller.js.map +0 -1
  126. package/dist/i3s-server/controllers/slpk-controller.js.map +0 -1
  127. package/dist/i3s-server/routes/index.js.map +0 -1
  128. package/dist/i3s-server/routes/slpk-router.js.map +0 -1
  129. package/dist/i3s-server/utils/create-scene-server.js.map +0 -1
  130. package/dist/i3s-server/utils/server-utils.js.map +0 -1
  131. package/dist/index.js.map +0 -1
  132. package/dist/lib/json-schemas/conversion-dump-json-schema.js.map +0 -1
  133. package/dist/lib/utils/cli-utils.js.map +0 -1
  134. package/dist/lib/utils/compress-util.js.map +0 -1
  135. package/dist/lib/utils/conversion-dump.js.map +0 -1
  136. package/dist/lib/utils/file-utils.js.map +0 -1
  137. package/dist/lib/utils/geometry-utils.js.map +0 -1
  138. package/dist/lib/utils/lod-conversion-utils.js.map +0 -1
  139. package/dist/lib/utils/queue.js.map +0 -1
  140. package/dist/lib/utils/statistic-utills.js.map +0 -1
  141. package/dist/lib/utils/write-queue.js.map +0 -1
  142. package/dist/pgm-loader.js.map +0 -1
  143. package/dist/slpk-extractor/slpk-extractor.js.map +0 -1
  144. 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
- constructor() {
22
- this.options = void 0;
23
- this.tilesetPath = void 0;
24
- this.vertexCounter = void 0;
25
- this.conversionStartTime = void 0;
26
- this.geoidHeightModel = void 0;
27
- this.sourceTileset = void 0;
28
- this.attributeStorageInfo = void 0;
29
- this.workerSource = {};
30
- this.slpkFilesystem = null;
31
- this.loaderOptions = {
32
- _nodeWorkers: true,
33
- reuseWorkers: true,
34
- worker: false,
35
- i3s: {
36
- coordinateSystem: COORDINATE_SYSTEM.LNGLAT_OFFSETS,
37
- decodeTextures: false
38
- },
39
- 'i3s-content': {
40
- workerUrl: './modules/i3s/dist/i3s-content-worker-node.js'
41
- }
42
- };
43
- this.conversionDump = void 0;
44
- this.progress = void 0;
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
- const {
63
- inputUrl,
64
- outputPath,
65
- tilesetName,
66
- maxDepth,
67
- egmFilePath,
68
- inquirer,
69
- analyze
70
- } = options;
71
- this.conversionStartTime = process.hrtime();
72
- this.options = {
73
- maxDepth,
74
- inquirer
75
- };
76
- console.log('Loading egm file...');
77
- this.geoidHeightModel = await load(egmFilePath, PGMLoader);
78
- console.log('Loading egm file completed!');
79
- this.slpkFilesystem = await openSLPK(inputUrl);
80
- let preprocessResult = true;
81
- if (analyze || this.slpkFilesystem) {
82
- preprocessResult = await this.preprocessConversion();
83
- if (!preprocessResult || analyze) {
84
- return;
85
- }
86
- }
87
- this.progress.startMonitoring();
88
- this.sourceTileset = await loadFromArchive(inputUrl, I3SLoader, {
89
- ...this.loaderOptions,
90
- i3s: {
91
- ...this.loaderOptions.i3s,
92
- isTileset: true
93
- }
94
- }, this.slpkFilesystem);
95
- if (!this.sourceTileset) {
96
- return;
97
- }
98
- const rootNode = (_this$sourceTileset = this.sourceTileset) === null || _this$sourceTileset === void 0 ? void 0 : _this$sourceTileset.root;
99
- if (!rootNode.obb) {
100
- rootNode.obb = createObbFromMbs(rootNode.mbs);
101
- }
102
- this.tilesetPath = join(`${outputPath}`, `${tilesetName}`);
103
- this.attributeStorageInfo = this.sourceTileset.attributeStorageInfo;
104
- await this.conversionDump.createDump(options);
105
- if (this.conversionDump.restored && this.options.inquirer) {
106
- const result = await this.options.inquirer.prompt([{
107
- name: 'resumeConversion',
108
- type: 'confirm',
109
- message: 'Dump file of the previous conversion exists, do you want to resume that conversion?'
110
- }]);
111
- if (!result.resumeConversion) {
112
- this.conversionDump.reset();
113
- }
114
- }
115
- if (!this.conversionDump.restored) {
116
- try {
117
- await removeDir(this.tilesetPath);
118
- } catch (e) {}
119
- }
120
- const rootTile = {
121
- boundingVolume: {
122
- box: i3sObbTo3dTilesObb(rootNode.obb, this.geoidHeightModel)
123
- },
124
- geometricError: convertScreenThresholdToGeometricError(rootNode),
125
- children: [],
126
- refine: 'REPLACE'
127
- };
128
- await this._addChildren(rootNode, rootTile, 1);
129
- const tileset = transform({
130
- root: rootTile
131
- }, tilesetTemplate());
132
- await writeFile(this.tilesetPath, JSON.stringify(tileset), 'tileset.json');
133
- await this.conversionDump.deleteDumpFile();
134
- this.progress.stopMonitoring();
135
- await this._finishConversion({
136
- slpk: false,
137
- outputPath,
138
- tilesetName
139
- });
140
- if (this.slpkFilesystem) {
141
- this.slpkFilesystem.destroy();
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
- const workerFarm = WorkerFarm.getWorkerFarm({});
144
- workerFarm.destroy();
145
- }
146
- async preprocessConversion() {
147
- console.log(`Analyze source layer`);
148
- const nodesCount = await getNodeCount(this.slpkFilesystem);
149
- this.progress.stepsTotal = nodesCount;
150
- console.log(`------------------------------------------------`);
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
- return false;
158
- }
159
- } else {
160
- console.log(`Node count cannot be calculated for the remote dataset`);
161
- }
162
- console.log(`------------------------------------------------`);
163
- return true;
164
- }
165
- async convertChildNode(parentSourceNode, parentNode, level, childNodeInfo) {
166
- let nextParentNode = parentNode;
167
- const sourceChild = await this._loadChildNode(parentSourceNode, childNodeInfo);
168
- if (sourceChild.contentUrl) {
169
- if (this.conversionDump.restored && this.conversionDump.isFileConversionComplete(`${sourceChild.id}.b3dm`) && (sourceChild.obb || sourceChild.mbs)) {
170
- const {
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
- this.progress.stepsDone += 1;
205
- let timeRemainingString = 'Calculating time left...';
206
- const timeRemaining = this.progress.getTimeRemainingString();
207
- if (timeRemaining) {
208
- timeRemainingString = `${timeRemaining} left`;
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
- const percentString = this.progress.getPercentString();
211
- const progressString = percentString ? ` ${percentString}%, ${timeRemainingString}` : '';
212
- console.log(`[converted${progressString}]: ${childNodeInfo.id}`);
213
- await this._addChildren(sourceChild, nextParentNode, level + 1);
214
- }
215
- async _addChildren(parentSourceNode, parentNode, level) {
216
- if (this.options.maxDepth && level > this.options.maxDepth) {
217
- return;
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
- for (const childNodeInfo of parentSourceNode.children || []) {
220
- await this.convertChildNode(parentSourceNode, parentNode, level, childNodeInfo);
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
- async _loadChildNode(parentNode, childNodeInfo) {
224
- var _this$sourceTileset2;
225
- let header;
226
- if ((_this$sourceTileset2 = this.sourceTileset) !== null && _this$sourceTileset2 !== void 0 && _this$sourceTileset2.nodePagesTile) {
227
- console.log(`Node conversion: ${childNodeInfo.id}`);
228
- header = await this.sourceTileset.nodePagesTile.formTileFromNodePages(parseInt(childNodeInfo.id));
229
- } else {
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
- console.log(`Node conversion: ${nodeUrl}`);
239
- header = await loadFromArchive(nodeUrl, I3SLoader, options, this.slpkFilesystem);
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
- return header;
242
- }
243
- _createChildAndBoundingVolume(sourceChild) {
244
- if (!sourceChild.obb) {
245
- sourceChild.obb = createObbFromMbs(sourceChild.mbs);
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
- const boundingVolume = {
248
- box: i3sObbTo3dTilesObb(sourceChild.obb, this.geoidHeightModel)
249
- };
250
- const child = {
251
- boundingVolume,
252
- geometricError: convertScreenThresholdToGeometricError(sourceChild),
253
- children: [],
254
- content: {
255
- uri: `${sourceChild.id}.b3dm`,
256
- boundingVolume
257
- }
258
- };
259
- return {
260
- boundingVolume,
261
- child
262
- };
263
- }
264
- _relativeUrlToFullUrl() {
265
- let baseUrl = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
266
- let relativeUrl = arguments.length > 1 ? arguments[1] : undefined;
267
- let resultArray = baseUrl.split('/');
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
- return resultArray.join('/');
281
- }
282
- async _loadChildAttributes(sourceChild, attributeStorageInfo) {
283
- const promises = [];
284
- const {
285
- attributeUrls = []
286
- } = sourceChild;
287
- for (let index = 0; index < attributeUrls.length; index++) {
288
- const inputUrl = attributeUrls[index];
289
- const attribute = attributeStorageInfo[index];
290
- const options = {
291
- attributeName: attribute.name,
292
- attributeType: this._getAttributeType(attribute)
293
- };
294
- promises.push(loadFromArchive(inputUrl, I3SAttributeLoader, options, this.slpkFilesystem));
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
- const attributesList = await Promise.all(promises);
297
- this._replaceNestedArrays(attributesList);
298
- return Object.assign({}, ...attributesList);
299
- }
300
- _getAttributeType(attribute) {
301
- if (attribute.attributeValues) {
302
- return attribute.attributeValues.valueType;
303
- } else if (attribute.objectIds) {
304
- return 'Oid32';
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
- return '';
307
- }
308
- _replaceNestedArrays(attributesList) {
309
- for (let index = 0; index < attributesList.length; index++) {
310
- const attributeObject = attributesList[index];
311
- for (const key in attributeObject) {
312
- attributeObject[key] = Array.from(attributeObject[key]);
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