@loaders.gl/tile-converter 4.0.0-alpha.7 → 4.0.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.
Files changed (148) hide show
  1. package/dist/3d-tiles-attributes-worker.js +2 -2
  2. package/dist/3d-tiles-attributes-worker.js.map +2 -2
  3. package/dist/converter.min.js +67 -67
  4. package/dist/deps-installer/deps-installer.js +1 -1
  5. package/dist/dist.min.js +694 -338
  6. package/dist/es5/3d-tiles-attributes-worker.js +1 -1
  7. package/dist/es5/3d-tiles-converter/3d-tiles-converter.js.map +1 -1
  8. package/dist/es5/deps-installer/deps-installer.js +2 -2
  9. package/dist/es5/deps-installer/deps-installer.js.map +1 -1
  10. package/dist/es5/i3s-attributes-worker.js +1 -1
  11. package/dist/es5/i3s-converter/helpers/batch-ids-extensions.js +2 -2
  12. package/dist/es5/i3s-converter/helpers/batch-ids-extensions.js.map +1 -1
  13. package/dist/es5/i3s-converter/helpers/coordinate-converter.js +6 -7
  14. package/dist/es5/i3s-converter/helpers/coordinate-converter.js.map +1 -1
  15. package/dist/es5/i3s-converter/helpers/geometry-converter.js +25 -14
  16. package/dist/es5/i3s-converter/helpers/geometry-converter.js.map +1 -1
  17. package/dist/es5/i3s-converter/helpers/gltf-attributes.js +45 -12
  18. package/dist/es5/i3s-converter/helpers/gltf-attributes.js.map +1 -1
  19. package/dist/es5/i3s-converter/helpers/load-3d-tiles.js +82 -0
  20. package/dist/es5/i3s-converter/helpers/load-3d-tiles.js.map +1 -0
  21. package/dist/es5/i3s-converter/helpers/node-index-document.js +74 -45
  22. package/dist/es5/i3s-converter/helpers/node-index-document.js.map +1 -1
  23. package/dist/es5/i3s-converter/helpers/preprocess-3d-tiles.js +111 -0
  24. package/dist/es5/i3s-converter/helpers/preprocess-3d-tiles.js.map +1 -0
  25. package/dist/es5/i3s-converter/helpers/tileset-traversal.js +82 -0
  26. package/dist/es5/i3s-converter/helpers/tileset-traversal.js.map +1 -0
  27. package/dist/es5/i3s-converter/i3s-converter.js +545 -516
  28. package/dist/es5/i3s-converter/i3s-converter.js.map +1 -1
  29. package/dist/es5/i3s-converter/types.js +16 -0
  30. package/dist/es5/i3s-converter/types.js.map +1 -1
  31. package/dist/es5/i3s-server/README.md +19 -0
  32. package/dist/es5/i3s-server/app.js +10 -1
  33. package/dist/es5/i3s-server/app.js.map +1 -1
  34. package/dist/es5/i3s-server/controllers/slpk-controller.js +84 -0
  35. package/dist/es5/i3s-server/controllers/slpk-controller.js.map +1 -0
  36. package/dist/es5/i3s-server/routes/slpk-router.js +71 -0
  37. package/dist/es5/i3s-server/routes/slpk-router.js.map +1 -0
  38. package/dist/es5/i3s-server/utils/create-scene-server.js +17 -0
  39. package/dist/es5/i3s-server/utils/create-scene-server.js.map +1 -0
  40. package/dist/es5/lib/utils/file-utils.js +1 -1
  41. package/dist/es5/lib/utils/file-utils.js.map +1 -1
  42. package/dist/es5/lib/utils/lod-conversion-utils.js.map +1 -1
  43. package/dist/es5/pgm-loader.js +1 -1
  44. package/dist/esm/3d-tiles-attributes-worker.js +1 -1
  45. package/dist/esm/3d-tiles-converter/3d-tiles-converter.js.map +1 -1
  46. package/dist/esm/deps-installer/deps-installer.js +2 -2
  47. package/dist/esm/deps-installer/deps-installer.js.map +1 -1
  48. package/dist/esm/i3s-attributes-worker.js +1 -1
  49. package/dist/esm/i3s-converter/helpers/batch-ids-extensions.js +2 -2
  50. package/dist/esm/i3s-converter/helpers/batch-ids-extensions.js.map +1 -1
  51. package/dist/esm/i3s-converter/helpers/coordinate-converter.js +6 -7
  52. package/dist/esm/i3s-converter/helpers/coordinate-converter.js.map +1 -1
  53. package/dist/esm/i3s-converter/helpers/geometry-converter.js +19 -8
  54. package/dist/esm/i3s-converter/helpers/geometry-converter.js.map +1 -1
  55. package/dist/esm/i3s-converter/helpers/gltf-attributes.js +49 -12
  56. package/dist/esm/i3s-converter/helpers/gltf-attributes.js.map +1 -1
  57. package/dist/esm/i3s-converter/helpers/load-3d-tiles.js +35 -0
  58. package/dist/esm/i3s-converter/helpers/load-3d-tiles.js.map +1 -0
  59. package/dist/esm/i3s-converter/helpers/node-index-document.js +14 -1
  60. package/dist/esm/i3s-converter/helpers/node-index-document.js.map +1 -1
  61. package/dist/esm/i3s-converter/helpers/preprocess-3d-tiles.js +48 -0
  62. package/dist/esm/i3s-converter/helpers/preprocess-3d-tiles.js.map +1 -0
  63. package/dist/esm/i3s-converter/helpers/tileset-traversal.js +14 -0
  64. package/dist/esm/i3s-converter/helpers/tileset-traversal.js.map +1 -0
  65. package/dist/esm/i3s-converter/i3s-converter.js +134 -120
  66. package/dist/esm/i3s-converter/i3s-converter.js.map +1 -1
  67. package/dist/esm/i3s-converter/types.js +10 -1
  68. package/dist/esm/i3s-converter/types.js.map +1 -1
  69. package/dist/esm/i3s-server/README.md +19 -0
  70. package/dist/esm/i3s-server/app.js +11 -1
  71. package/dist/esm/i3s-server/app.js.map +1 -1
  72. package/dist/esm/i3s-server/controllers/slpk-controller.js +36 -0
  73. package/dist/esm/i3s-server/controllers/slpk-controller.js.map +1 -0
  74. package/dist/esm/i3s-server/routes/slpk-router.js +33 -0
  75. package/dist/esm/i3s-server/routes/slpk-router.js.map +1 -0
  76. package/dist/esm/i3s-server/utils/create-scene-server.js +16 -0
  77. package/dist/esm/i3s-server/utils/create-scene-server.js.map +1 -0
  78. package/dist/esm/lib/utils/file-utils.js +1 -1
  79. package/dist/esm/lib/utils/file-utils.js.map +1 -1
  80. package/dist/esm/lib/utils/lod-conversion-utils.js.map +1 -1
  81. package/dist/esm/pgm-loader.js +1 -1
  82. package/dist/i3s-attributes-worker.js +2 -2
  83. package/dist/i3s-attributes-worker.js.map +2 -2
  84. package/dist/i3s-converter/helpers/batch-ids-extensions.js +2 -5
  85. package/dist/i3s-converter/helpers/coordinate-converter.d.ts +3 -4
  86. package/dist/i3s-converter/helpers/coordinate-converter.d.ts.map +1 -1
  87. package/dist/i3s-converter/helpers/coordinate-converter.js +8 -9
  88. package/dist/i3s-converter/helpers/geometry-converter.d.ts +9 -4
  89. package/dist/i3s-converter/helpers/geometry-converter.d.ts.map +1 -1
  90. package/dist/i3s-converter/helpers/geometry-converter.js +34 -12
  91. package/dist/i3s-converter/helpers/gltf-attributes.d.ts +22 -3
  92. package/dist/i3s-converter/helpers/gltf-attributes.d.ts.map +1 -1
  93. package/dist/i3s-converter/helpers/gltf-attributes.js +61 -18
  94. package/dist/i3s-converter/helpers/load-3d-tiles.d.ts +18 -0
  95. package/dist/i3s-converter/helpers/load-3d-tiles.d.ts.map +1 -0
  96. package/dist/i3s-converter/helpers/load-3d-tiles.js +53 -0
  97. package/dist/i3s-converter/helpers/node-index-document.d.ts +8 -0
  98. package/dist/i3s-converter/helpers/node-index-document.d.ts.map +1 -1
  99. package/dist/i3s-converter/helpers/node-index-document.js +20 -2
  100. package/dist/i3s-converter/helpers/node-pages.js +1 -1
  101. package/dist/i3s-converter/helpers/preprocess-3d-tiles.d.ts +23 -0
  102. package/dist/i3s-converter/helpers/preprocess-3d-tiles.d.ts.map +1 -0
  103. package/dist/i3s-converter/helpers/preprocess-3d-tiles.js +76 -0
  104. package/dist/i3s-converter/helpers/tileset-traversal.d.ts +25 -0
  105. package/dist/i3s-converter/helpers/tileset-traversal.d.ts.map +1 -0
  106. package/dist/i3s-converter/helpers/tileset-traversal.js +29 -0
  107. package/dist/i3s-converter/i3s-converter.d.ts +40 -40
  108. package/dist/i3s-converter/i3s-converter.d.ts.map +1 -1
  109. package/dist/i3s-converter/i3s-converter.js +150 -126
  110. package/dist/i3s-converter/types.d.ts +18 -0
  111. package/dist/i3s-converter/types.d.ts.map +1 -1
  112. package/dist/i3s-converter/types.js +15 -0
  113. package/dist/i3s-server/app.d.ts.map +1 -1
  114. package/dist/i3s-server/app.js +9 -1
  115. package/dist/i3s-server/controllers/slpk-controller.d.ts +3 -0
  116. package/dist/i3s-server/controllers/slpk-controller.d.ts.map +1 -0
  117. package/dist/i3s-server/controllers/slpk-controller.js +32 -0
  118. package/dist/i3s-server/routes/slpk-router.d.ts +3 -0
  119. package/dist/i3s-server/routes/slpk-router.d.ts.map +1 -0
  120. package/dist/i3s-server/routes/slpk-router.js +33 -0
  121. package/dist/i3s-server/utils/create-scene-server.d.ts +11 -0
  122. package/dist/i3s-server/utils/create-scene-server.d.ts.map +1 -0
  123. package/dist/i3s-server/utils/create-scene-server.js +14 -0
  124. package/dist/lib/utils/file-utils.d.ts.map +1 -1
  125. package/dist/lib/utils/file-utils.js +2 -1
  126. package/dist/lib/utils/lod-conversion-utils.d.ts +3 -2
  127. package/dist/lib/utils/lod-conversion-utils.d.ts.map +1 -1
  128. package/dist/lib/utils/lod-conversion-utils.js +1 -1
  129. package/package.json +14 -14
  130. package/src/3d-tiles-converter/3d-tiles-converter.ts +5 -5
  131. package/src/deps-installer/deps-installer.ts +1 -1
  132. package/src/i3s-converter/helpers/batch-ids-extensions.ts +2 -5
  133. package/src/i3s-converter/helpers/coordinate-converter.ts +11 -10
  134. package/src/i3s-converter/helpers/geometry-converter.ts +51 -19
  135. package/src/i3s-converter/helpers/gltf-attributes.ts +84 -21
  136. package/src/i3s-converter/helpers/load-3d-tiles.ts +68 -0
  137. package/src/i3s-converter/helpers/node-index-document.ts +22 -2
  138. package/src/i3s-converter/helpers/preprocess-3d-tiles.ts +81 -0
  139. package/src/i3s-converter/helpers/tileset-traversal.ts +51 -0
  140. package/src/i3s-converter/i3s-converter.ts +228 -178
  141. package/src/i3s-converter/types.ts +20 -0
  142. package/src/i3s-server/README.md +19 -0
  143. package/src/i3s-server/app.js +8 -1
  144. package/src/i3s-server/controllers/slpk-controller.js +38 -0
  145. package/src/i3s-server/routes/slpk-router.js +33 -0
  146. package/src/i3s-server/utils/create-scene-server.js +15 -0
  147. package/src/lib/utils/file-utils.ts +2 -1
  148. package/src/lib/utils/lod-conversion-utils.ts +6 -2
@@ -1,7 +1,6 @@
1
1
  import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
2
2
  var _process$env;
3
3
  import { load, encode, fetchFile, getLoaderOptions, isBrowser } from '@loaders.gl/core';
4
- import { Tileset3D } from '@loaders.gl/tiles';
5
4
  import { CesiumIonLoader, Tiles3DLoader } from '@loaders.gl/3d-tiles';
6
5
  import { join } from 'path';
7
6
  import { v4 as uuidv4 } from 'uuid';
@@ -23,6 +22,7 @@ import { SHARED_RESOURCES as sharedResourcesTemplate } from './json-templates/sh
23
22
  import { validateNodeBoundingVolumes } from './helpers/node-debug';
24
23
  import { KTX2BasisWriterWorker } from '@loaders.gl/textures';
25
24
  import { ImageWriter } from '@loaders.gl/images';
25
+ import { GltfPrimitiveModeString } from './types';
26
26
  import { getWorkerURL, WorkerFarm } from '@loaders.gl/worker-utils';
27
27
  import { DracoWriterWorker } from '@loaders.gl/draco';
28
28
  import WriteQueue from '../lib/utils/write-queue';
@@ -30,6 +30,11 @@ import { I3SAttributesWorker } from '../i3s-attributes-worker';
30
30
  import { BROWSER_ERROR_MESSAGE } from '../constants';
31
31
  import { createdStorageAttribute, createFieldAttribute, createPopupInfo, getAttributeType, getFieldAttributeType } from './helpers/feature-attributes';
32
32
  import { NodeIndexDocument } from './helpers/node-index-document';
33
+ import { loadNestedTileset, loadTile3DContent } from './helpers/load-3d-tiles';
34
+ import { Matrix4 } from '@math.gl/core';
35
+ import { createBoundingVolume } from '@loaders.gl/tiles';
36
+ import { traverseDatasetWith } from './helpers/tileset-traversal';
37
+ import { analyzeTileContent, mergePreprocessData } from './helpers/preprocess-3d-tiles';
33
38
  const ION_DEFAULT_TOKEN = ((_process$env = process.env) === null || _process$env === void 0 ? void 0 : _process$env.IonToken) || 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiJlYWMxMzcyYy0zZjJkLTQwODctODNlNi01MDRkZmMzMjIxOWIiLCJpZCI6OTYyMCwic2NvcGVzIjpbImFzbCIsImFzciIsImdjIl0sImlhdCI6MTU2Mjg2NjI3M30.1FNiClUyk00YH_nWfSGpiQAjR5V2OvREDq1PJ5QMjWQ';
34
39
  const HARDCODED_NODES_PER_PAGE = 64;
35
40
  const _3D_TILES = '3DTILES';
@@ -54,6 +59,18 @@ export default class I3SConverter {
54
59
  _defineProperty(this, "conversionStartTime", [0, 0]);
55
60
  _defineProperty(this, "refreshTokenTime", [0, 0]);
56
61
  _defineProperty(this, "sourceTileset", null);
62
+ _defineProperty(this, "loadOptions", {
63
+ _nodeWorkers: true,
64
+ reuseWorkers: true,
65
+ basis: {
66
+ format: 'rgba32',
67
+ workerUrl: './modules/textures/dist/basis-worker-node.js'
68
+ },
69
+ draco: {
70
+ workerUrl: './modules/draco/dist/draco-worker-node.js'
71
+ },
72
+ fetch: {}
73
+ });
57
74
  _defineProperty(this, "geoidHeightModel", null);
58
75
  _defineProperty(this, "Loader", Tiles3DLoader);
59
76
  _defineProperty(this, "generateTextures", void 0);
@@ -62,6 +79,9 @@ export default class I3SConverter {
62
79
  _defineProperty(this, "workerSource", {});
63
80
  _defineProperty(this, "writeQueue", new WriteQueue());
64
81
  _defineProperty(this, "compressList", null);
82
+ _defineProperty(this, "preprocessData", {
83
+ meshTopologyTypes: new Set()
84
+ });
65
85
  this.nodePages = new NodePages(writeFile, HARDCODED_NODES_PER_PAGE, this);
66
86
  this.options = {};
67
87
  this.layers0Path = '';
@@ -130,50 +150,81 @@ export default class I3SConverter {
130
150
  }
131
151
  await this.loadWorkers();
132
152
  try {
133
- var _sourceTilesetJson$ro, _sourceTilesetJson$ro2;
134
153
  const preloadOptions = await this._fetchPreloadOptions();
135
- const tilesetOptions = {
136
- loadOptions: {
137
- _nodeWorkers: true,
138
- reuseWorkers: true,
139
- basis: {
140
- format: 'rgba32'
141
- }
142
- }
143
- };
144
154
  if (preloadOptions.headers) {
145
- tilesetOptions.loadOptions.fetch = {
155
+ this.loadOptions.fetch = {
146
156
  headers: preloadOptions.headers
147
157
  };
148
158
  }
149
- Object.assign(tilesetOptions, preloadOptions);
150
- const sourceTilesetJson = await load(inputUrl, this.Loader, tilesetOptions.loadOptions);
151
- this.sourceTileset = new Tileset3D(sourceTilesetJson, tilesetOptions);
152
- await this._createAndSaveTileset(outputPath, tilesetName, sourceTilesetJson === null || sourceTilesetJson === void 0 ? void 0 : (_sourceTilesetJson$ro = sourceTilesetJson.root) === null || _sourceTilesetJson$ro === void 0 ? void 0 : (_sourceTilesetJson$ro2 = _sourceTilesetJson$ro.boundingVolume) === null || _sourceTilesetJson$ro2 === void 0 ? void 0 : _sourceTilesetJson$ro2.region);
153
- await this._finishConversion({
154
- slpk: Boolean(slpk),
155
- outputPath,
156
- tilesetName
157
- });
158
- return sourceTilesetJson;
159
+ this.sourceTileset = await load(inputUrl, this.Loader, this.loadOptions);
160
+ const preprocessResult = await this.preprocessConversion();
161
+ if (preprocessResult) {
162
+ await this._createAndSaveTileset(outputPath, tilesetName);
163
+ await this._finishConversion({
164
+ slpk: Boolean(slpk),
165
+ outputPath,
166
+ tilesetName
167
+ });
168
+ }
159
169
  } catch (error) {
160
170
  throw error;
161
171
  } finally {
172
+ await this.writeQueue.finalize();
162
173
  const workerFarm = WorkerFarm.getWorkerFarm({});
163
174
  workerFarm.destroy();
164
175
  }
176
+ return 'success';
177
+ }
178
+ async preprocessConversion() {
179
+ console.log("Analyze source tileset");
180
+ const sourceRootTile = this.sourceTileset.root;
181
+ await traverseDatasetWith(sourceRootTile, null, this.analyzeTile.bind(this), undefined, this.options.maxDepth);
182
+ const {
183
+ meshTopologyTypes
184
+ } = this.preprocessData;
185
+ console.log("------------------------------------------------");
186
+ console.log("Preprocess results:");
187
+ console.log("glTF mesh topology types: ".concat(Array.from(meshTopologyTypes).join(', ')));
188
+ console.log("------------------------------------------------");
189
+ if (!meshTopologyTypes.has(GltfPrimitiveModeString.TRIANGLES) && !meshTopologyTypes.has(GltfPrimitiveModeString.TRIANGLE_STRIP)) {
190
+ console.log('The tileset is of unsupported mesh topology types. The conversion will be interrupted.');
191
+ console.log("------------------------------------------------");
192
+ return false;
193
+ }
194
+ return true;
165
195
  }
166
- async _createAndSaveTileset(outputPath, tilesetName, boundingVolumeRegion) {
196
+ async analyzeTile(sourceTile, traversalProps) {
197
+ if (sourceTile.type === 'json') {
198
+ await loadNestedTileset(this.sourceTileset, sourceTile, this.loadOptions);
199
+ return null;
200
+ }
201
+ if (sourceTile.id) {
202
+ console.log("[analyze]: ".concat(sourceTile.id));
203
+ }
204
+ const tileContent = await loadTile3DContent(this.sourceTileset, sourceTile, {
205
+ ...this.loadOptions,
206
+ '3d-tiles': {
207
+ ...this.loadOptions['3d-tiles'],
208
+ loadGLTF: false
209
+ }
210
+ });
211
+ const tilePreprocessData = await analyzeTileContent(sourceTile, tileContent);
212
+ mergePreprocessData(this.preprocessData, tilePreprocessData);
213
+ return null;
214
+ }
215
+ async _createAndSaveTileset(outputPath, tilesetName) {
216
+ var _this$sourceTileset, _this$sourceTileset$r, _this$sourceTileset$r2;
167
217
  const tilesetPath = join("".concat(outputPath), "".concat(tilesetName));
168
218
  try {
169
219
  await removeDir(tilesetPath);
170
220
  } catch (e) {}
171
221
  this.layers0Path = join(tilesetPath, 'SceneServer', 'layers', '0');
172
- this._formLayers0(tilesetName, boundingVolumeRegion);
173
222
  this.materialDefinitions = [];
174
223
  this.materialMap = new Map();
175
224
  const sourceRootTile = this.sourceTileset.root;
176
- const boundingVolumes = createBoundingVolumes(sourceRootTile, this.geoidHeightModel);
225
+ const sourceBoundingVolume = createBoundingVolume(sourceRootTile.boundingVolume, new Matrix4(sourceRootTile.transform), null);
226
+ this._formLayers0(tilesetName, sourceBoundingVolume, (_this$sourceTileset = this.sourceTileset) === null || _this$sourceTileset === void 0 ? void 0 : (_this$sourceTileset$r = _this$sourceTileset.root) === null || _this$sourceTileset$r === void 0 ? void 0 : (_this$sourceTileset$r2 = _this$sourceTileset$r.boundingVolume) === null || _this$sourceTileset$r2 === void 0 ? void 0 : _this$sourceTileset$r2.region);
227
+ const boundingVolumes = createBoundingVolumes(sourceBoundingVolume, this.geoidHeightModel);
177
228
  await this.nodePages.push({
178
229
  index: 0,
179
230
  lodThreshold: 0,
@@ -181,7 +232,10 @@ export default class I3SConverter {
181
232
  children: []
182
233
  });
183
234
  const rootNode = await NodeIndexDocument.createRootNode(boundingVolumes, this);
184
- await this._convertNodesTree(rootNode, sourceRootTile);
235
+ await traverseDatasetWith(sourceRootTile, {
236
+ transform: new Matrix4(sourceRootTile.transform),
237
+ parentNodes: [rootNode]
238
+ }, this.convertTile.bind(this), this.finalizeTile.bind(this), this.options.maxDepth);
185
239
  this.layers0.materialDefinitions = this.materialDefinitions;
186
240
  this.layers0.geometryDefinitions = transform(this.geometryConfigs.map(config => ({
187
241
  geometryConfig: {
@@ -202,9 +256,12 @@ export default class I3SConverter {
202
256
  await this.writeQueue.finalize();
203
257
  await this._createSlpk(tilesetPath);
204
258
  }
205
- _formLayers0(tilesetName, boundingVolumeRegion) {
206
- var _this$sourceTileset, _this$sourceTileset2, _this$sourceTileset2$;
207
- const fullExtent = convertBoundingVolumeToI3SFullExtent(((_this$sourceTileset = this.sourceTileset) === null || _this$sourceTileset === void 0 ? void 0 : _this$sourceTileset.boundingVolume) || ((_this$sourceTileset2 = this.sourceTileset) === null || _this$sourceTileset2 === void 0 ? void 0 : (_this$sourceTileset2$ = _this$sourceTileset2.root) === null || _this$sourceTileset2$ === void 0 ? void 0 : _this$sourceTileset2$.boundingVolume));
259
+ _formLayers0(tilesetName, sourceBoundingVolume, boundingVolumeRegion) {
260
+ var _this$sourceTileset2;
261
+ if (!((_this$sourceTileset2 = this.sourceTileset) !== null && _this$sourceTileset2 !== void 0 && _this$sourceTileset2.root)) {
262
+ return;
263
+ }
264
+ const fullExtent = convertBoundingVolumeToI3SFullExtent(sourceBoundingVolume);
208
265
  if (boundingVolumeRegion) {
209
266
  fullExtent.zmin = boundingVolumeRegion[4];
210
267
  fullExtent.zmax = boundingVolumeRegion[5];
@@ -227,24 +284,6 @@ export default class I3SConverter {
227
284
  };
228
285
  this.layers0 = transform(layers0data, layersTemplate());
229
286
  }
230
- async _convertNodesTree(rootNode, sourceRootTile) {
231
- await this.sourceTileset._loadTile(sourceRootTile);
232
- if (this.isContentSupported(sourceRootTile)) {
233
- const childNodes = await this._createNode(rootNode, sourceRootTile, 0);
234
- for (const childNode of childNodes) {
235
- await childNode.save();
236
- }
237
- await rootNode.addChildren(childNodes);
238
- } else {
239
- await this._addChildrenWithNeighborsAndWriteFile({
240
- parentNode: rootNode,
241
- sourceTiles: sourceRootTile.children,
242
- level: 1
243
- });
244
- }
245
- await sourceRootTile.unloadContent();
246
- await rootNode.save();
247
- }
248
287
  async _writeLayers0() {
249
288
  if (this.options.slpk) {
250
289
  await this.writeQueue.enqueue({
@@ -267,72 +306,58 @@ export default class I3SConverter {
267
306
  } catch (e) {}
268
307
  }
269
308
  }
270
- async _addChildrenWithNeighborsAndWriteFile(data) {
271
- await this._addChildren(data);
272
- await data.parentNode.addNeighbors();
273
- }
274
- async convertNestedTileset(_ref) {
275
- let {
276
- parentNode,
277
- sourceTile,
278
- level
279
- } = _ref;
280
- await this.sourceTileset._loadTile(sourceTile);
281
- await this._addChildren({
282
- parentNode,
283
- sourceTiles: sourceTile.children,
284
- level: level + 1
285
- });
286
- await sourceTile.unloadContent();
287
- }
288
- async convertNode(_ref2) {
289
- let {
290
- parentNode,
291
- sourceTile,
292
- level
293
- } = _ref2;
294
- const childNodes = await this._createNode(parentNode, sourceTile, level);
295
- await parentNode.addChildren(childNodes);
296
- }
297
- async _addChildren(data) {
298
- const {
299
- sourceTiles,
300
- parentNode,
301
- level
302
- } = data;
303
- if (this.options.maxDepth && level > this.options.maxDepth) {
304
- return;
305
- }
306
- for (const sourceTile of sourceTiles) {
309
+ async convertTile(sourceTile, traversalProps) {
310
+ if (sourceTile.type === 'json' || sourceTile.type === 'empty') {
307
311
  if (sourceTile.type === 'json') {
308
- await this.convertNestedTileset({
309
- parentNode,
310
- sourceTile,
311
- level
312
- });
313
- } else {
314
- await this.convertNode({
315
- parentNode,
316
- sourceTile,
317
- level
318
- });
312
+ if (sourceTile.id) {
313
+ console.log("[load]: ".concat(sourceTile.id));
314
+ }
315
+ await loadNestedTileset(this.sourceTileset, sourceTile, this.loadOptions);
319
316
  }
320
- if (sourceTile.id) {
321
- console.log(sourceTile.id);
317
+ return traversalProps;
318
+ }
319
+ if (sourceTile.id) {
320
+ console.log("[convert]: ".concat(sourceTile.id));
321
+ }
322
+ const {
323
+ parentNodes,
324
+ transform
325
+ } = traversalProps;
326
+ let transformationMatrix = transform.clone();
327
+ if (sourceTile.transform) {
328
+ transformationMatrix = transformationMatrix.multiplyRight(sourceTile.transform);
329
+ }
330
+ const parentNode = parentNodes[0];
331
+ const childNodes = await this._createNode(parentNode, sourceTile, transformationMatrix);
332
+ await parentNode.addChildren(childNodes);
333
+ const newTraversalProps = {
334
+ transform: transformationMatrix,
335
+ parentNodes: childNodes
336
+ };
337
+ return newTraversalProps;
338
+ }
339
+ async finalizeTile(conversionResults, currentTraversalProps) {
340
+ for (const result of conversionResults) {
341
+ for (const node of result.parentNodes) {
342
+ await node.addNeighbors();
322
343
  }
323
344
  }
345
+ for (const node of currentTraversalProps.parentNodes) {
346
+ await node.save();
347
+ }
324
348
  }
325
- async _createNode(parentNode, sourceTile, level) {
349
+ async _createNode(parentNode, sourceTile, transformationMatrix) {
326
350
  var _this$layers, _this$layers$attribut;
327
351
  this._checkAddRefinementTypeForTile(sourceTile);
328
352
  await this._updateTilesetOptions();
329
- await this.sourceTileset._loadTile(sourceTile);
330
- let boundingVolumes = createBoundingVolumes(sourceTile, this.geoidHeightModel);
331
- const propertyTable = getPropertyTable(sourceTile.content);
353
+ const tileContent = await loadTile3DContent(this.sourceTileset, sourceTile, this.loadOptions);
354
+ const sourceBoundingVolume = createBoundingVolume(sourceTile.boundingVolume, transformationMatrix, null);
355
+ let boundingVolumes = createBoundingVolumes(sourceBoundingVolume, this.geoidHeightModel);
356
+ const propertyTable = getPropertyTable(tileContent);
332
357
  if (propertyTable && !((_this$layers = this.layers0) !== null && _this$layers !== void 0 && (_this$layers$attribut = _this$layers.attributeStorageInfo) !== null && _this$layers$attribut !== void 0 && _this$layers$attribut.length)) {
333
358
  this._convertPropertyTableToNodeAttributes(propertyTable);
334
359
  }
335
- const resourcesData = await this._convertResources(sourceTile, parentNode.inPageId, propertyTable);
360
+ const resourcesData = await this._convertResources(sourceTile, transformationMatrix, sourceBoundingVolume, tileContent, parentNode.inPageId, propertyTable);
336
361
  const nodes = [];
337
362
  const nodeIds = [];
338
363
  const nodesInPage = [];
@@ -373,17 +398,11 @@ export default class I3SConverter {
373
398
  nodeIds.push(nodeInPage.index);
374
399
  nodesInPage.push(nodeInPage);
375
400
  }
376
- sourceTile.unloadContent();
377
- await this._addChildrenWithNeighborsAndWriteFile({
378
- parentNode: nodes[0],
379
- sourceTiles: sourceTile.children,
380
- level: level + 1
381
- });
382
401
  return nodes;
383
402
  }
384
- async _convertResources(sourceTile, parentId, propertyTable) {
403
+ async _convertResources(sourceTile, transformationMatrix, boundingVolume, tileContent, parentId, propertyTable) {
385
404
  var _this$layers2;
386
- if (!this.isContentSupported(sourceTile)) {
405
+ if (!this.isContentSupported(sourceTile) || !tileContent) {
387
406
  return null;
388
407
  }
389
408
  const draftObb = {
@@ -391,7 +410,7 @@ export default class I3SConverter {
391
410
  halfSize: [],
392
411
  quaternion: []
393
412
  };
394
- const resourcesData = await convertB3dmToI3sGeometry(sourceTile.content, async () => (await this.nodePages.push({
413
+ const resourcesData = await convertB3dmToI3sGeometry(tileContent, transformationMatrix, boundingVolume, async () => (await this.nodePages.push({
395
414
  index: 0,
396
415
  obb: draftObb
397
416
  }, parentId)).index, propertyTable, this.featuresHashArray, (_this$layers2 = this.layers0) === null || _this$layers2 === void 0 ? void 0 : _this$layers2.attributeStorageInfo, this.options.draco, this.generateBoundingVolumes, this.options.mergeMaterials, this.geoidHeightModel, this.workerSource);
@@ -710,13 +729,9 @@ export default class I3SConverter {
710
729
  }
711
730
  this.refreshTokenTime = process.hrtime();
712
731
  const preloadOptions = await this._fetchPreloadOptions();
713
- this.sourceTileset.options = {
714
- ...this.sourceTileset.options,
715
- ...preloadOptions
716
- };
717
732
  if (preloadOptions.headers) {
718
- this.sourceTileset.loadOptions.fetch = {
719
- ...this.sourceTileset.loadOptions.fetch,
733
+ this.loadOptions.fetch = {
734
+ ...this.loadOptions.fetch,
720
735
  headers: preloadOptions.headers
721
736
  };
722
737
  console.log('Authorization Bearer token has been updated');
@@ -730,9 +745,8 @@ export default class I3SConverter {
730
745
  }
731
746
  this.refinementCounter.tilesCount += 1;
732
747
  }
733
- isContentSupported(sourceRootTile) {
734
- var _sourceRootTile$conte;
735
- return ['b3dm', 'glTF'].includes(sourceRootTile === null || sourceRootTile === void 0 ? void 0 : (_sourceRootTile$conte = sourceRootTile.content) === null || _sourceRootTile$conte === void 0 ? void 0 : _sourceRootTile$conte.type);
748
+ isContentSupported(sourceTile) {
749
+ return ['b3dm', 'glTF', 'scenegraph'].includes(sourceTile.type || '');
736
750
  }
737
751
  async loadWorkers() {
738
752
  console.log("Loading workers source...");