@loaders.gl/tile-converter 3.2.0-alpha.1 → 3.2.0-alpha.2

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 (170) hide show
  1. package/dist/3d-tiles-attributes-worker.d.ts +28 -0
  2. package/dist/3d-tiles-attributes-worker.d.ts.map +1 -0
  3. package/dist/3d-tiles-attributes-worker.js +4 -0
  4. package/dist/3d-tiles-attributes-worker.js.map +7 -0
  5. package/dist/3d-tiles-converter/3d-tiles-converter.d.ts +4 -0
  6. package/dist/3d-tiles-converter/3d-tiles-converter.d.ts.map +1 -1
  7. package/dist/3d-tiles-converter/3d-tiles-converter.js +29 -3
  8. package/dist/3d-tiles-converter/helpers/b3dm-converter.d.ts +5 -4
  9. package/dist/3d-tiles-converter/helpers/b3dm-converter.d.ts.map +1 -1
  10. package/dist/3d-tiles-converter/helpers/b3dm-converter.js +10 -10
  11. package/dist/converter.min.js +20 -20
  12. package/dist/dist.min.js +789 -645
  13. package/dist/es5/3d-tiles-attributes-worker.js +29 -0
  14. package/dist/es5/3d-tiles-attributes-worker.js.map +1 -0
  15. package/dist/es5/3d-tiles-converter/3d-tiles-converter.js +102 -43
  16. package/dist/es5/3d-tiles-converter/3d-tiles-converter.js.map +1 -1
  17. package/dist/es5/3d-tiles-converter/helpers/b3dm-converter.js +21 -23
  18. package/dist/es5/3d-tiles-converter/helpers/b3dm-converter.js.map +1 -1
  19. package/dist/es5/i3s-attributes-worker.js +29 -0
  20. package/dist/es5/i3s-attributes-worker.js.map +1 -0
  21. package/dist/es5/i3s-converter/helpers/coordinate-converter.js +19 -11
  22. package/dist/es5/i3s-converter/helpers/coordinate-converter.js.map +1 -1
  23. package/dist/es5/i3s-converter/helpers/geometry-attributes.js +2 -2
  24. package/dist/es5/i3s-converter/helpers/geometry-attributes.js.map +1 -1
  25. package/dist/es5/i3s-converter/helpers/geometry-converter.js +267 -178
  26. package/dist/es5/i3s-converter/helpers/geometry-converter.js.map +1 -1
  27. package/dist/es5/i3s-converter/helpers/gltf-attributes.js +71 -0
  28. package/dist/es5/i3s-converter/helpers/gltf-attributes.js.map +1 -0
  29. package/dist/es5/i3s-converter/helpers/node-pages.js +47 -99
  30. package/dist/es5/i3s-converter/helpers/node-pages.js.map +1 -1
  31. package/dist/es5/i3s-converter/i3s-converter.js +230 -195
  32. package/dist/es5/i3s-converter/i3s-converter.js.map +1 -1
  33. package/dist/es5/index.js +8 -0
  34. package/dist/es5/index.js.map +1 -1
  35. package/dist/es5/lib/utils/compress-util.js +14 -17
  36. package/dist/es5/lib/utils/compress-util.js.map +1 -1
  37. package/dist/es5/lib/utils/file-utils.js +39 -14
  38. package/dist/es5/lib/utils/file-utils.js.map +1 -1
  39. package/dist/es5/lib/utils/lod-conversion-utils.js.map +1 -1
  40. package/dist/es5/lib/utils/queue.js +61 -0
  41. package/dist/es5/lib/utils/queue.js.map +1 -0
  42. package/dist/es5/lib/utils/statistic-utills.js.map +1 -1
  43. package/dist/es5/lib/utils/write-queue.js +225 -0
  44. package/dist/es5/lib/utils/write-queue.js.map +1 -0
  45. package/dist/es5/pgm-loader.js +1 -1
  46. package/dist/es5/workers/3d-tiles-attributes-worker.js +37 -0
  47. package/dist/es5/workers/3d-tiles-attributes-worker.js.map +1 -0
  48. package/dist/es5/workers/i3s-attributes-worker.js +40 -0
  49. package/dist/es5/workers/i3s-attributes-worker.js.map +1 -0
  50. package/dist/esm/3d-tiles-attributes-worker.js +16 -0
  51. package/dist/esm/3d-tiles-attributes-worker.js.map +1 -0
  52. package/dist/esm/3d-tiles-converter/3d-tiles-converter.js +30 -4
  53. package/dist/esm/3d-tiles-converter/3d-tiles-converter.js.map +1 -1
  54. package/dist/esm/3d-tiles-converter/helpers/b3dm-converter.js +16 -18
  55. package/dist/esm/3d-tiles-converter/helpers/b3dm-converter.js.map +1 -1
  56. package/dist/esm/i3s-attributes-worker.js +16 -0
  57. package/dist/esm/i3s-attributes-worker.js.map +1 -0
  58. package/dist/esm/i3s-converter/helpers/coordinate-converter.js +19 -11
  59. package/dist/esm/i3s-converter/helpers/coordinate-converter.js.map +1 -1
  60. package/dist/esm/i3s-converter/helpers/geometry-attributes.js +2 -2
  61. package/dist/esm/i3s-converter/helpers/geometry-attributes.js.map +1 -1
  62. package/dist/esm/i3s-converter/helpers/geometry-converter.js +117 -58
  63. package/dist/esm/i3s-converter/helpers/geometry-converter.js.map +1 -1
  64. package/dist/esm/i3s-converter/helpers/gltf-attributes.js +54 -0
  65. package/dist/esm/i3s-converter/helpers/gltf-attributes.js.map +1 -0
  66. package/dist/esm/i3s-converter/helpers/node-pages.js +12 -4
  67. package/dist/esm/i3s-converter/helpers/node-pages.js.map +1 -1
  68. package/dist/esm/i3s-converter/i3s-converter.js +105 -28
  69. package/dist/esm/i3s-converter/i3s-converter.js.map +1 -1
  70. package/dist/esm/index.js +1 -0
  71. package/dist/esm/index.js.map +1 -1
  72. package/dist/esm/lib/utils/compress-util.js +6 -8
  73. package/dist/esm/lib/utils/compress-util.js.map +1 -1
  74. package/dist/esm/lib/utils/file-utils.js +11 -1
  75. package/dist/esm/lib/utils/file-utils.js.map +1 -1
  76. package/dist/esm/lib/utils/lod-conversion-utils.js.map +1 -1
  77. package/dist/esm/lib/utils/queue.js +19 -0
  78. package/dist/esm/lib/utils/queue.js.map +1 -0
  79. package/dist/esm/lib/utils/statistic-utills.js.map +1 -1
  80. package/dist/esm/lib/utils/write-queue.js +88 -0
  81. package/dist/esm/lib/utils/write-queue.js.map +1 -0
  82. package/dist/esm/pgm-loader.js +1 -1
  83. package/dist/esm/workers/3d-tiles-attributes-worker.js +5 -0
  84. package/dist/esm/workers/3d-tiles-attributes-worker.js.map +1 -0
  85. package/dist/esm/workers/i3s-attributes-worker.js +4 -0
  86. package/dist/esm/workers/i3s-attributes-worker.js.map +1 -0
  87. package/dist/i3s-attributes-worker.d.ts +33 -0
  88. package/dist/i3s-attributes-worker.d.ts.map +1 -0
  89. package/dist/i3s-attributes-worker.js +10 -0
  90. package/dist/i3s-attributes-worker.js.map +7 -0
  91. package/dist/i3s-converter/helpers/coordinate-converter.d.ts +7 -7
  92. package/dist/i3s-converter/helpers/coordinate-converter.d.ts.map +1 -1
  93. package/dist/i3s-converter/helpers/coordinate-converter.js +25 -21
  94. package/dist/i3s-converter/helpers/geometry-attributes.d.ts +2 -2
  95. package/dist/i3s-converter/helpers/geometry-attributes.d.ts.map +1 -1
  96. package/dist/i3s-converter/helpers/geometry-attributes.js +2 -1
  97. package/dist/i3s-converter/helpers/geometry-converter.d.ts +28 -11
  98. package/dist/i3s-converter/helpers/geometry-converter.d.ts.map +1 -1
  99. package/dist/i3s-converter/helpers/geometry-converter.js +220 -110
  100. package/dist/i3s-converter/helpers/gltf-attributes.d.ts +9 -0
  101. package/dist/i3s-converter/helpers/gltf-attributes.d.ts.map +1 -0
  102. package/dist/i3s-converter/helpers/gltf-attributes.js +56 -0
  103. package/dist/i3s-converter/helpers/node-pages.d.ts +6 -5
  104. package/dist/i3s-converter/helpers/node-pages.d.ts.map +1 -1
  105. package/dist/i3s-converter/helpers/node-pages.js +13 -8
  106. package/dist/i3s-converter/i3s-converter.d.ts +7 -3
  107. package/dist/i3s-converter/i3s-converter.d.ts.map +1 -1
  108. package/dist/i3s-converter/i3s-converter.js +88 -26
  109. package/dist/i3s-converter/types.d.ts +83 -8
  110. package/dist/i3s-converter/types.d.ts.map +1 -1
  111. package/dist/index.d.ts +1 -0
  112. package/dist/index.d.ts.map +1 -1
  113. package/dist/index.js +3 -1
  114. package/dist/lib/utils/compress-util.d.ts +44 -5
  115. package/dist/lib/utils/compress-util.d.ts.map +1 -1
  116. package/dist/lib/utils/compress-util.js +73 -6
  117. package/dist/lib/utils/file-utils.d.ts +34 -5
  118. package/dist/lib/utils/file-utils.d.ts.map +1 -1
  119. package/dist/lib/utils/file-utils.js +40 -1
  120. package/dist/lib/utils/lod-conversion-utils.d.ts +25 -4
  121. package/dist/lib/utils/lod-conversion-utils.d.ts.map +1 -1
  122. package/dist/lib/utils/lod-conversion-utils.js +21 -2
  123. package/dist/lib/utils/queue.d.ts +7 -0
  124. package/dist/lib/utils/queue.d.ts.map +1 -0
  125. package/dist/lib/utils/queue.js +18 -0
  126. package/dist/lib/utils/statistic-utills.d.ts +2 -2
  127. package/dist/lib/utils/statistic-utills.d.ts.map +1 -1
  128. package/dist/lib/utils/write-queue.d.ts +22 -0
  129. package/dist/lib/utils/write-queue.d.ts.map +1 -0
  130. package/dist/lib/utils/write-queue.js +62 -0
  131. package/dist/workers/3d-tiles-attributes-worker.d.ts +2 -0
  132. package/dist/workers/3d-tiles-attributes-worker.d.ts.map +1 -0
  133. package/dist/workers/3d-tiles-attributes-worker.js +9 -0
  134. package/dist/workers/i3s-attributes-worker.d.ts +2 -0
  135. package/dist/workers/i3s-attributes-worker.d.ts.map +1 -0
  136. package/dist/workers/i3s-attributes-worker.js +5 -0
  137. package/package.json +20 -17
  138. package/src/3d-tiles-attributes-worker.ts +43 -0
  139. package/src/3d-tiles-converter/3d-tiles-converter.ts +44 -4
  140. package/src/3d-tiles-converter/helpers/b3dm-converter.ts +15 -13
  141. package/src/i3s-attributes-worker.ts +46 -0
  142. package/src/i3s-converter/helpers/coordinate-converter.ts +29 -24
  143. package/src/i3s-converter/helpers/geometry-attributes.ts +4 -3
  144. package/src/i3s-converter/helpers/{geometry-converter.js → geometry-converter.ts} +421 -175
  145. package/src/i3s-converter/helpers/gltf-attributes.ts +68 -0
  146. package/src/i3s-converter/helpers/node-pages.ts +25 -17
  147. package/src/i3s-converter/i3s-converter.ts +112 -69
  148. package/src/i3s-converter/types.ts +90 -8
  149. package/src/index.ts +1 -0
  150. package/src/lib/utils/{compress-util.js → compress-util.ts} +105 -18
  151. package/src/lib/utils/file-utils.ts +84 -0
  152. package/src/lib/utils/{lod-conversion-utils.js → lod-conversion-utils.ts} +27 -5
  153. package/src/lib/utils/queue.ts +17 -0
  154. package/src/lib/utils/{statistic-utills.js → statistic-utills.ts} +0 -0
  155. package/src/lib/utils/write-queue.ts +75 -0
  156. package/src/workers/3d-tiles-attributes-worker.ts +6 -0
  157. package/src/workers/i3s-attributes-worker.ts +6 -0
  158. package/dist/es5/i3s-converter/helpers/geometry-converter.d.ts +0 -44
  159. package/dist/es5/lib/utils/compress-util.d.ts +0 -53
  160. package/dist/es5/lib/utils/file-utils.d.ts +0 -43
  161. package/dist/es5/lib/utils/lod-conversion-utils.d.ts +0 -32
  162. package/dist/esm/i3s-converter/helpers/geometry-converter.d.ts +0 -44
  163. package/dist/esm/lib/utils/compress-util.d.ts +0 -53
  164. package/dist/esm/lib/utils/file-utils.d.ts +0 -43
  165. package/dist/esm/lib/utils/lod-conversion-utils.d.ts +0 -32
  166. package/src/i3s-converter/helpers/geometry-converter.d.ts +0 -44
  167. package/src/lib/utils/compress-util.d.ts +0 -53
  168. package/src/lib/utils/file-utils.d.ts +0 -43
  169. package/src/lib/utils/file-utils.js +0 -38
  170. package/src/lib/utils/lod-conversion-utils.d.ts +0 -32
@@ -0,0 +1,43 @@
1
+ import type {WorkerObject} from '@loaders.gl/worker-utils';
2
+ import type {FeatureAttribute} from '@loaders.gl/i3s';
3
+
4
+ import {processOnWorker} from '@loaders.gl/worker-utils';
5
+
6
+ // __VERSION__ is injected by babel-plugin-version-inline
7
+ // @ts-ignore TS2304: Cannot find name '__VERSION__'.
8
+ const VERSION = typeof __VERSION__ !== 'undefined' ? __VERSION__ : 'latest';
9
+
10
+ export type Tile3DAttributesWorkerOptions = {
11
+ featureAttributes: FeatureAttribute | null;
12
+ source: string;
13
+ };
14
+
15
+ export type I3SAttributesData = {
16
+ tileContent: any;
17
+ textureFormat: string;
18
+ };
19
+
20
+ /**
21
+ * I3S Attributes Worker to handle B3DM object
22
+ */
23
+ export const Tile3dAttributesWorker = {
24
+ id: '3d-tiles-attributes',
25
+ name: '3DTiles Attributes Worker',
26
+ module: 'tile-converter',
27
+ version: VERSION,
28
+ options: {
29
+ attributes: null
30
+ }
31
+ };
32
+
33
+ /**
34
+ * Performs I3S attributes transformation
35
+ */
36
+ export function transform3DTilesAttributesOnWorker(
37
+ i3sAttributesData: I3SAttributesData,
38
+ options: Tile3DAttributesWorkerOptions
39
+ ): Promise<ArrayBuffer> {
40
+ return processOnWorker(Tile3dAttributesWorker, i3sAttributesData, options);
41
+ }
42
+
43
+ export const _typecheckI3SAttributesWorker: WorkerObject = Tile3dAttributesWorker;
@@ -4,7 +4,7 @@ import type {Node3D} from '@loaders.gl/3d-tiles';
4
4
  import {join} from 'path';
5
5
  import process from 'process';
6
6
  import transform from 'json-map-transform';
7
- import {load} from '@loaders.gl/core';
7
+ import {fetchFile, getLoaderOptions, load} from '@loaders.gl/core';
8
8
  import {I3SLoader, I3SAttributeLoader, COORDINATE_SYSTEM} from '@loaders.gl/i3s';
9
9
  import {Tileset3D, Tile3D} from '@loaders.gl/tiles';
10
10
  import {Geoid} from '@math.gl/geoid';
@@ -17,6 +17,12 @@ import {calculateFilesSize, timeConverter} from '../lib/utils/statistic-utills';
17
17
  import {TILESET as tilesetTemplate} from './json-templates/tileset';
18
18
  import B3dmConverter from './helpers/b3dm-converter';
19
19
  import {createObbFromMbs} from '../i3s-converter/helpers/coordinate-converter';
20
+ import {
21
+ I3SAttributesData,
22
+ Tile3dAttributesWorker
23
+ /*transform3DTilesAttributesOnWorker*/
24
+ } from '../3d-tiles-attributes-worker';
25
+ import {getWorkerURL, WorkerFarm} from '@loaders.gl/worker-utils';
20
26
 
21
27
  const I3S = 'I3S';
22
28
 
@@ -31,6 +37,7 @@ export default class Tiles3DConverter {
31
37
  geoidHeightModel: Geoid | null;
32
38
  sourceTileset: Tileset3D | null;
33
39
  attributeStorageInfo: AttributeStorageInfo | null;
40
+ workerSource: {[key: string]: string} = {};
34
41
 
35
42
  constructor() {
36
43
  this.options = {};
@@ -40,6 +47,7 @@ export default class Tiles3DConverter {
40
47
  this.geoidHeightModel = null;
41
48
  this.sourceTileset = null;
42
49
  this.attributeStorageInfo = null;
50
+ this.workerSource = {};
43
51
  }
44
52
 
45
53
  /**
@@ -66,6 +74,8 @@ export default class Tiles3DConverter {
66
74
  this.geoidHeightModel = await load(egmFilePath, PGMLoader);
67
75
  console.log('Loading egm file completed!'); // eslint-disable-line
68
76
 
77
+ await this.loadWorkers();
78
+
69
79
  const sourceTilesetJson = await load(inputUrl, I3SLoader, {});
70
80
 
71
81
  this.sourceTileset = new Tileset3D(sourceTilesetJson, {
@@ -74,6 +84,7 @@ export default class Tiles3DConverter {
74
84
  }
75
85
  });
76
86
 
87
+ await this.sourceTileset.tilesetInitializationPromise;
77
88
  const rootNode = this.sourceTileset.root!;
78
89
  if (!rootNode.header.obb) {
79
90
  rootNode.header.obb = createObbFromMbs(rootNode.header.mbs);
@@ -102,6 +113,10 @@ export default class Tiles3DConverter {
102
113
  await writeFile(this.tilesetPath, JSON.stringify(tileset), 'tileset.json');
103
114
 
104
115
  this._finishConversion({slpk: false, outputPath, tilesetName});
116
+
117
+ // Clean up worker pools
118
+ const workerFarm = WorkerFarm.getWorkerFarm({});
119
+ workerFarm.destroy();
105
120
  }
106
121
 
107
122
  /**
@@ -125,9 +140,12 @@ export default class Tiles3DConverter {
125
140
  await this.sourceTileset!._loadTile(sourceChild);
126
141
  this.vertexCounter += sourceChild.content.vertexCount;
127
142
 
128
- let attributes: FeatureAttribute | null = null;
143
+ let featureAttributes: FeatureAttribute | null = null;
129
144
  if (this.attributeStorageInfo) {
130
- attributes = await this._loadChildAttributes(sourceChild, this.attributeStorageInfo);
145
+ featureAttributes = await this._loadChildAttributes(
146
+ sourceChild,
147
+ this.attributeStorageInfo
148
+ );
131
149
  }
132
150
 
133
151
  if (!sourceChild.header.obb) {
@@ -143,7 +161,19 @@ export default class Tiles3DConverter {
143
161
  children: []
144
162
  };
145
163
 
146
- const b3dm = await new B3dmConverter().convert(sourceChild, attributes);
164
+ const i3sAttributesData: I3SAttributesData = {
165
+ tileContent: sourceChild.content,
166
+ textureFormat: sourceChild?.header?.textureFormat
167
+ };
168
+
169
+ // TODO Uncomment when 3d-tiles-attributes-worker will be published on CDN.
170
+ // const b3dm = await transform3DTilesAttributesOnWorker(i3sAttributesData, {
171
+ // source: this.workerSource.tile3dWorkerSource,
172
+ // featureAttributes
173
+ // });
174
+
175
+ const b3dm = await new B3dmConverter().convert(i3sAttributesData, featureAttributes);
176
+
147
177
  child.content = {
148
178
  uri: `${sourceChild.id}.b3dm`,
149
179
  boundingVolume
@@ -290,4 +320,14 @@ export default class Tiles3DConverter {
290
320
  console.log(`File(s) size: `, filesSize, ' bytes'); // eslint-disable-line
291
321
  console.log(`------------------------------------------------`); // eslint-disable-line
292
322
  }
323
+
324
+ private async loadWorkers(): Promise<void> {
325
+ console.log(`Loading workers source...`); // eslint-disable-line no-undef, no-console
326
+ const tile3dAttributesWorkerUrl = getWorkerURL(Tile3dAttributesWorker, {...getLoaderOptions()});
327
+ const sourceResponse = await fetchFile(tile3dAttributesWorkerUrl);
328
+ const source = await sourceResponse.text();
329
+
330
+ this.workerSource.tile3dWorkerSource = source;
331
+ console.log(`Loading workers source completed!`); // eslint-disable-line no-undef, no-console
332
+ }
293
333
  }
@@ -1,3 +1,5 @@
1
+ import type {I3SAttributesData} from '../../3d-tiles-attributes-worker';
2
+
1
3
  import {encodeSync} from '@loaders.gl/core';
2
4
  import {GLTFScenegraph, GLTFWriter} from '@loaders.gl/gltf';
3
5
  import {Tile3DWriter} from '@loaders.gl/3d-tiles';
@@ -21,15 +23,17 @@ export default class B3dmConverter {
21
23
  * @param i3sTile - Tile3D instance for I3S node
22
24
  * @returns - encoded content
23
25
  */
24
- async convert(i3sTile: Object, attributes: any = null): Promise<ArrayBuffer> {
25
- this.i3sTile = i3sTile;
26
- const gltf = await this.buildGltf(i3sTile);
26
+ async convert(
27
+ i3sAttributesData: I3SAttributesData,
28
+ featureAttributes: any = null
29
+ ): Promise<ArrayBuffer> {
30
+ const gltf = await this.buildGltf(i3sAttributesData);
27
31
  const b3dm = encodeSync(
28
32
  {
29
33
  gltfEncoded: new Uint8Array(gltf),
30
34
  type: 'b3dm',
31
- featuresLength: this._getFeaturesLength(attributes),
32
- batchTable: attributes
35
+ featuresLength: this._getFeaturesLength(featureAttributes),
36
+ batchTable: featureAttributes
33
37
  },
34
38
  Tile3DWriter
35
39
  );
@@ -41,7 +45,8 @@ export default class B3dmConverter {
41
45
  * @param i3sTile - Tile3D instance for I3S node
42
46
  * @returns - encoded glb content
43
47
  */
44
- async buildGltf(i3sTile): Promise<ArrayBuffer> {
48
+ async buildGltf(i3sAttributesData: I3SAttributesData): Promise<ArrayBuffer> {
49
+ const {tileContent, textureFormat} = i3sAttributesData;
45
50
  const {
46
51
  material,
47
52
  attributes,
@@ -49,10 +54,10 @@ export default class B3dmConverter {
49
54
  cartesianOrigin,
50
55
  cartographicOrigin,
51
56
  modelMatrix
52
- } = i3sTile.content;
57
+ } = tileContent;
53
58
  const gltfBuilder = new GLTFScenegraph();
54
59
 
55
- const textureIndex = await this._addI3sTextureToGltf(i3sTile, gltfBuilder);
60
+ const textureIndex = await this._addI3sTextureToGltf(tileContent, textureFormat, gltfBuilder);
56
61
  const pbrMaterialInfo = this._convertI3sMaterialToGltfMaterial(material, textureIndex);
57
62
  const materialIndex = gltfBuilder.addMaterial(pbrMaterialInfo);
58
63
 
@@ -101,11 +106,8 @@ export default class B3dmConverter {
101
106
  * @param {GLTFScenegraph} gltfBuilder - gltfScenegraph instance to construct GLTF
102
107
  * @returns {Promise<number | null>} - GLTF texture index
103
108
  */
104
- async _addI3sTextureToGltf(i3sTile, gltfBuilder) {
105
- const {
106
- content: {texture, material, attributes},
107
- header: {textureFormat}
108
- } = i3sTile;
109
+ async _addI3sTextureToGltf(tileContent, textureFormat, gltfBuilder) {
110
+ const {texture, material, attributes} = tileContent;
109
111
  let textureIndex = null;
110
112
  let selectedTexture = texture;
111
113
  if (!texture && material) {
@@ -0,0 +1,46 @@
1
+ import type {WorkerObject} from '@loaders.gl/worker-utils';
2
+ import type {ConvertedAttributes} from './i3s-converter/types';
3
+ import type {Matrix4, Vector3} from '@math.gl/core';
4
+
5
+ import {processOnWorker} from '@loaders.gl/worker-utils';
6
+
7
+ // __VERSION__ is injected by babel-plugin-version-inline
8
+ // @ts-ignore TS2304: Cannot find name '__VERSION__'.
9
+ const VERSION = typeof __VERSION__ !== 'undefined' ? __VERSION__ : 'latest';
10
+
11
+ export type I3SAttributesWorkerOptions = {
12
+ useCartesianPositions: boolean;
13
+ source: string;
14
+ };
15
+
16
+ export type B3DMAttributesData = {
17
+ gltfMaterials?: {id: string}[];
18
+ nodes: any;
19
+ cartographicOrigin: Vector3;
20
+ cartesianModelMatrix: Matrix4;
21
+ };
22
+
23
+ /**
24
+ * I3S Attributes Worker to handle B3DM object
25
+ */
26
+ export const I3SAttributesWorker = {
27
+ id: 'i3s-attributes',
28
+ name: 'I3S Attributes Worker',
29
+ module: 'tile-converter',
30
+ version: VERSION,
31
+ options: {
32
+ useCartesianPositions: false
33
+ }
34
+ };
35
+
36
+ /**
37
+ * Performs I3S attributes transformation
38
+ */
39
+ export function transformI3SAttributesOnWorker(
40
+ attributesData: B3DMAttributesData,
41
+ options: I3SAttributesWorkerOptions
42
+ ): Promise<Map<string, ConvertedAttributes>> {
43
+ return processOnWorker(I3SAttributesWorker, attributesData, options);
44
+ }
45
+
46
+ export const _typecheckI3SAttributesWorker: WorkerObject = I3SAttributesWorker;
@@ -1,15 +1,15 @@
1
- import type {BoundingVolumes, Extent, Mbs, Obb} from '@loaders.gl/i3s';
1
+ import type {BoundingVolumes, FullExtent, Mbs, Obb} from '@loaders.gl/i3s';
2
2
 
3
3
  import {Matrix3, Quaternion, Vector3} from '@math.gl/core';
4
4
  import {Ellipsoid} from '@math.gl/geospatial';
5
5
  import {
6
6
  OrientedBoundingBox,
7
7
  makeOrientedBoundingBoxFromPoints,
8
- makeBoundingSphereFromPoints
8
+ makeBoundingSphereFromPoints,
9
+ BoundingSphere
9
10
  } from '@math.gl/culling';
10
11
  import TileHeader from '@loaders.gl/tiles/src/tileset/tile-3d';
11
12
  import {Geoid} from '@math.gl/geoid';
12
- import {Tileset3D} from '@loaders.gl/tiles';
13
13
 
14
14
  /**
15
15
  * Create bounding volumes object from tile and geoid height model.
@@ -101,34 +101,39 @@ export function convertPositionsToVectors(positions: Float32Array): Vector3[] {
101
101
  }
102
102
 
103
103
  /**
104
- * Convert common coordinate to extent coordinate
105
- * @param tileset
106
- * @returns - Extent
107
- * @todo why lodMetricValue is radius? need to check this function
104
+ * Convert common coordinate to fullExtent https://github.com/Esri/i3s-spec/blob/master/docs/1.8/fullExtent.cmn.md
105
+ * @param
106
+ * @param boundingVolume
107
+ * @returns - fullExtent object
108
108
  */
109
- export function convertCommonToI3SExtentCoordinate(tileset: Tileset3D | null): Extent | null {
110
- const cartesianCenter = tileset?.cartesianCenter;
111
- if (!cartesianCenter) {
112
- return null;
109
+ export function convertBoundingVolumeToI3SFullExtent(
110
+ boundingVolume: OrientedBoundingBox | BoundingSphere
111
+ ): FullExtent {
112
+ let sphere: BoundingSphere;
113
+ if (boundingVolume instanceof BoundingSphere) {
114
+ sphere = boundingVolume;
115
+ } else {
116
+ sphere = boundingVolume.getBoundingSphere();
113
117
  }
114
- const radius = tileset?.lodMetricValue;
115
- const rightTop = Ellipsoid.WGS84.cartesianToCartographic(
116
- new Vector3(cartesianCenter[0] + radius, cartesianCenter[1] + radius, cartesianCenter[2]),
118
+ const center: Vector3 = sphere.center;
119
+ const radius: number = sphere.radius;
120
+ const vertexMax = Ellipsoid.WGS84.cartesianToCartographic(
121
+ new Vector3(center[0] + radius, center[1] + radius, center[2] + radius),
117
122
  new Vector3()
118
123
  );
119
- const leftBottom = Ellipsoid.WGS84.cartesianToCartographic(
120
- new Vector3(cartesianCenter[0] - radius, cartesianCenter[1] - radius, cartesianCenter[2]),
124
+ const vertexMin = Ellipsoid.WGS84.cartesianToCartographic(
125
+ new Vector3(center[0] - radius, center[1] - radius, center[2] - radius),
121
126
  new Vector3()
122
127
  );
123
- const isFirstRight = rightTop[0] < leftBottom[0];
124
- const isFirstTop = rightTop[1] < leftBottom[1];
125
128
 
126
- return [
127
- isFirstRight ? rightTop[0] : leftBottom[0],
128
- isFirstTop ? rightTop[1] : leftBottom[1],
129
- isFirstRight ? leftBottom[0] : rightTop[0],
130
- isFirstTop ? leftBottom[1] : rightTop[1]
131
- ];
129
+ return {
130
+ xmin: vertexMin[0],
131
+ xmax: vertexMax[0],
132
+ ymin: vertexMin[1],
133
+ ymax: vertexMax[1],
134
+ zmin: vertexMin[2],
135
+ zmax: vertexMax[2]
136
+ };
132
137
  }
133
138
 
134
139
  /**
@@ -1,4 +1,4 @@
1
- import type {GeometryAttributes, AttributesData, GroupedByFeatureIdAttributes} from '../types';
1
+ import type {GeometryAttributes, ConvertedAttributes, GroupedByFeatureIdAttributes} from '../types';
2
2
  import {concatenateTypedArrays} from '@loaders.gl/loader-utils';
3
3
 
4
4
  const VALUES_PER_VERTEX = 3;
@@ -9,8 +9,9 @@ const POSITIONS_AND_NORMALS_PER_TRIANGLE = 9;
9
9
  * @param attributes
10
10
  * @returns attirbutes with featureCount, featureIds and changed faceRange.
11
11
  */
12
- export function generateAttributes(attributes: AttributesData): GeometryAttributes {
13
- const {positions, normals, texCoords, colors, featureIndices, triangleCount} = attributes;
12
+ export function generateAttributes(attributes: ConvertedAttributes): GeometryAttributes {
13
+ const {positions, normals, texCoords, colors, featureIndices} = attributes;
14
+ const triangleCount = positions.length / POSITIONS_AND_NORMALS_PER_TRIANGLE;
14
15
 
15
16
  if (!featureIndices.length) {
16
17
  return {