@loaders.gl/tile-converter 3.3.0-alpha.3 → 3.3.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 (107) hide show
  1. package/dist/3d-tiles-attributes-worker.d.ts +1 -1
  2. package/dist/3d-tiles-attributes-worker.js +2 -2
  3. package/dist/3d-tiles-attributes-worker.js.map +2 -2
  4. package/dist/3d-tiles-converter/3d-tiles-converter.d.ts +8 -0
  5. package/dist/3d-tiles-converter/3d-tiles-converter.d.ts.map +1 -1
  6. package/dist/3d-tiles-converter/3d-tiles-converter.js +57 -43
  7. package/dist/3d-tiles-converter/helpers/b3dm-converter.d.ts +5 -5
  8. package/dist/3d-tiles-converter/helpers/b3dm-converter.d.ts.map +1 -1
  9. package/dist/3d-tiles-converter/helpers/b3dm-converter.js +21 -17
  10. package/dist/converter.min.js +21 -21
  11. package/dist/deps-installer/deps-installer.d.ts +5 -1
  12. package/dist/deps-installer/deps-installer.d.ts.map +1 -1
  13. package/dist/deps-installer/deps-installer.js +21 -1
  14. package/dist/dist.min.js +662 -1018
  15. package/dist/es5/3d-tiles-attributes-worker.js +2 -2
  16. package/dist/es5/3d-tiles-attributes-worker.js.map +1 -1
  17. package/dist/es5/3d-tiles-converter/3d-tiles-converter.js +115 -101
  18. package/dist/es5/3d-tiles-converter/3d-tiles-converter.js.map +1 -1
  19. package/dist/es5/3d-tiles-converter/helpers/b3dm-converter.js +27 -19
  20. package/dist/es5/3d-tiles-converter/helpers/b3dm-converter.js.map +1 -1
  21. package/dist/es5/deps-installer/deps-installer.js +70 -6
  22. package/dist/es5/deps-installer/deps-installer.js.map +1 -1
  23. package/dist/es5/i3s-attributes-worker.js +1 -1
  24. package/dist/es5/i3s-attributes-worker.js.map +1 -1
  25. package/dist/es5/i3s-converter/helpers/batch-ids-extensions.js +4 -0
  26. package/dist/es5/i3s-converter/helpers/batch-ids-extensions.js.map +1 -1
  27. package/dist/es5/i3s-converter/helpers/coordinate-converter.js.map +1 -1
  28. package/dist/es5/i3s-converter/helpers/feature-attributes.js +153 -0
  29. package/dist/es5/i3s-converter/helpers/feature-attributes.js.map +1 -1
  30. package/dist/es5/i3s-converter/helpers/geometry-converter.js +40 -44
  31. package/dist/es5/i3s-converter/helpers/geometry-converter.js.map +1 -1
  32. package/dist/es5/i3s-converter/helpers/gltf-attributes.js +55 -36
  33. package/dist/es5/i3s-converter/helpers/gltf-attributes.js.map +1 -1
  34. package/dist/es5/i3s-converter/helpers/node-pages.js +10 -2
  35. package/dist/es5/i3s-converter/helpers/node-pages.js.map +1 -1
  36. package/dist/es5/i3s-converter/i3s-converter.js +364 -435
  37. package/dist/es5/i3s-converter/i3s-converter.js.map +1 -1
  38. package/dist/es5/pgm-loader.js +1 -1
  39. package/dist/es5/workers/3d-tiles-attributes-worker.js +1 -1
  40. package/dist/es5/workers/3d-tiles-attributes-worker.js.map +1 -1
  41. package/dist/esm/3d-tiles-attributes-worker.js +2 -2
  42. package/dist/esm/3d-tiles-attributes-worker.js.map +1 -1
  43. package/dist/esm/3d-tiles-converter/3d-tiles-converter.js +59 -44
  44. package/dist/esm/3d-tiles-converter/3d-tiles-converter.js.map +1 -1
  45. package/dist/esm/3d-tiles-converter/helpers/b3dm-converter.js +25 -15
  46. package/dist/esm/3d-tiles-converter/helpers/b3dm-converter.js.map +1 -1
  47. package/dist/esm/deps-installer/deps-installer.js +21 -2
  48. package/dist/esm/deps-installer/deps-installer.js.map +1 -1
  49. package/dist/esm/i3s-attributes-worker.js +1 -1
  50. package/dist/esm/i3s-attributes-worker.js.map +1 -1
  51. package/dist/esm/i3s-converter/helpers/batch-ids-extensions.js +4 -0
  52. package/dist/esm/i3s-converter/helpers/batch-ids-extensions.js.map +1 -1
  53. package/dist/esm/i3s-converter/helpers/coordinate-converter.js.map +1 -1
  54. package/dist/esm/i3s-converter/helpers/feature-attributes.js +138 -0
  55. package/dist/esm/i3s-converter/helpers/feature-attributes.js.map +1 -1
  56. package/dist/esm/i3s-converter/helpers/geometry-converter.js +19 -21
  57. package/dist/esm/i3s-converter/helpers/geometry-converter.js.map +1 -1
  58. package/dist/esm/i3s-converter/helpers/gltf-attributes.js +55 -36
  59. package/dist/esm/i3s-converter/helpers/gltf-attributes.js.map +1 -1
  60. package/dist/esm/i3s-converter/helpers/node-pages.js +9 -2
  61. package/dist/esm/i3s-converter/helpers/node-pages.js.map +1 -1
  62. package/dist/esm/i3s-converter/i3s-converter.js +93 -183
  63. package/dist/esm/i3s-converter/i3s-converter.js.map +1 -1
  64. package/dist/esm/pgm-loader.js +1 -1
  65. package/dist/esm/workers/3d-tiles-attributes-worker.js +1 -1
  66. package/dist/esm/workers/3d-tiles-attributes-worker.js.map +1 -1
  67. package/dist/i3s-attributes-worker.d.ts +5 -1
  68. package/dist/i3s-attributes-worker.d.ts.map +1 -1
  69. package/dist/i3s-attributes-worker.js +3 -3
  70. package/dist/i3s-attributes-worker.js.map +2 -2
  71. package/dist/i3s-converter/helpers/batch-ids-extensions.d.ts +2 -3
  72. package/dist/i3s-converter/helpers/batch-ids-extensions.d.ts.map +1 -1
  73. package/dist/i3s-converter/helpers/batch-ids-extensions.js +3 -0
  74. package/dist/i3s-converter/helpers/coordinate-converter.d.ts +2 -2
  75. package/dist/i3s-converter/helpers/coordinate-converter.d.ts.map +1 -1
  76. package/dist/i3s-converter/helpers/feature-attributes.d.ts +32 -0
  77. package/dist/i3s-converter/helpers/feature-attributes.d.ts.map +1 -1
  78. package/dist/i3s-converter/helpers/feature-attributes.js +162 -1
  79. package/dist/i3s-converter/helpers/geometry-converter.d.ts +5 -4
  80. package/dist/i3s-converter/helpers/geometry-converter.d.ts.map +1 -1
  81. package/dist/i3s-converter/helpers/geometry-converter.js +29 -27
  82. package/dist/i3s-converter/helpers/gltf-attributes.d.ts.map +1 -1
  83. package/dist/i3s-converter/helpers/gltf-attributes.js +50 -30
  84. package/dist/i3s-converter/helpers/node-pages.d.ts +4 -0
  85. package/dist/i3s-converter/helpers/node-pages.d.ts.map +1 -1
  86. package/dist/i3s-converter/helpers/node-pages.js +9 -2
  87. package/dist/i3s-converter/i3s-converter.d.ts +24 -48
  88. package/dist/i3s-converter/i3s-converter.d.ts.map +1 -1
  89. package/dist/i3s-converter/i3s-converter.js +88 -186
  90. package/dist/i3s-converter/types.d.ts +4 -0
  91. package/dist/i3s-converter/types.d.ts.map +1 -1
  92. package/dist/workers/3d-tiles-attributes-worker.js +1 -1
  93. package/package.json +15 -15
  94. package/src/3d-tiles-attributes-worker.ts +1 -1
  95. package/src/3d-tiles-converter/3d-tiles-converter.ts +71 -55
  96. package/src/3d-tiles-converter/helpers/b3dm-converter.ts +25 -18
  97. package/src/deps-installer/deps-installer.ts +29 -2
  98. package/src/i3s-attributes-worker.ts +5 -1
  99. package/src/i3s-converter/helpers/batch-ids-extensions.ts +13 -6
  100. package/src/i3s-converter/helpers/coordinate-converter.ts +2 -2
  101. package/src/i3s-converter/helpers/feature-attributes.ts +182 -0
  102. package/src/i3s-converter/helpers/geometry-converter.ts +45 -36
  103. package/src/i3s-converter/helpers/gltf-attributes.ts +54 -33
  104. package/src/i3s-converter/helpers/node-pages.ts +10 -2
  105. package/src/i3s-converter/i3s-converter.ts +125 -210
  106. package/src/i3s-converter/types.ts +4 -0
  107. package/src/workers/3d-tiles-attributes-worker.ts +1 -1
@@ -1,13 +1,20 @@
1
- import type {Image, MeshPrimitive} from 'modules/gltf/src/lib/types/gltf-postprocessed-schema';
2
1
  import type {B3DMContent, FeatureTableJson} from '@loaders.gl/3d-tiles';
3
- import type {GLTF_EXT_feature_metadata} from '@loaders.gl/gltf';
2
+ import type {
3
+ GLTF_EXT_feature_metadata,
4
+ GLTFAccessorPostprocessed,
5
+ GLTFMaterialPostprocessed,
6
+ GLTFNodePostprocessed,
7
+ GLTFImagePostprocessed,
8
+ GLTFMeshPrimitivePostprocessed,
9
+ GLTFMeshPostprocessed,
10
+ GLTFTexturePostprocessed
11
+ } from '@loaders.gl/gltf';
4
12
 
5
13
  import {Vector3, Matrix4, Vector4} from '@math.gl/core';
6
14
  import {Ellipsoid} from '@math.gl/geospatial';
7
15
 
8
16
  import {DracoWriterWorker} from '@loaders.gl/draco';
9
17
  import {assert, encode} from '@loaders.gl/core';
10
- import {Tile3D} from '@loaders.gl/tiles';
11
18
  import {concatenateArrayBuffers, concatenateTypedArrays} from '@loaders.gl/loader-utils';
12
19
  import md5 from 'md5';
13
20
  import {generateAttributes} from './geometry-attributes';
@@ -18,7 +25,6 @@ import {
18
25
  I3SMaterialWithTexture,
19
26
  SharedResourcesArrays
20
27
  } from '../types';
21
- import {GLTFMaterialPostprocessed, GLTFNodePostprocessed} from '@loaders.gl/gltf';
22
28
  import {
23
29
  AttributeStorageInfo,
24
30
  I3SMaterialDefinition,
@@ -27,12 +33,8 @@ import {
27
33
  } from '@loaders.gl/i3s';
28
34
  import {TypedArray} from '@loaders.gl/schema';
29
35
  import {Geoid} from '@math.gl/geoid';
30
- import {
31
- GLTFAccessorPostprocessed,
32
- GLTFMeshPostprocessed,
33
- GLTFTexturePostprocessed
34
- } from 'modules/gltf/src/lib/types/gltf-types';
35
- import {B3DMAttributesData /*transformI3SAttributesOnWorker */} from '../../i3s-attributes-worker';
36
+ /** Usage of worker here brings more overhead than advantage */
37
+ import {B3DMAttributesData /*, transformI3SAttributesOnWorker*/} from '../../i3s-attributes-worker';
36
38
  import {prepareDataForAttributesConversion} from './gltf-attributes';
37
39
  import {handleBatchIdsExtensions} from './batch-ids-extensions';
38
40
  import {checkPropertiesLength, flattenPropertyTableByFeatureIds} from './feature-attributes';
@@ -65,7 +67,7 @@ let scratchVector = new Vector3();
65
67
  * Convert binary data from b3dm file to i3s resources
66
68
  *
67
69
  * @param tileContent - 3d tile content
68
- * @param nodeId - target nodeId. If a few nodes will be created - ids will be nodeId+n where n - index in the resulting array
70
+ * @param addNodeToNodePage - function to add new node to node pages
69
71
  * @param featuresHashArray - hash array of features that is needed to not to mix up same features in parent and child nodes
70
72
  * @param attributeStorageInfo - attributes metadata from 3DSceneLayer json
71
73
  * @param draco - is converter should create draco compressed geometry
@@ -75,7 +77,7 @@ let scratchVector = new Vector3();
75
77
  */
76
78
  export default async function convertB3dmToI3sGeometry(
77
79
  tileContent: B3DMContent,
78
- nodeId: number,
80
+ addNodeToNodePage: () => number,
79
81
  propertyTable: FeatureTableJson | null,
80
82
  featuresHashArray: string[],
81
83
  attributeStorageInfo: AttributeStorageInfo[] | undefined,
@@ -83,7 +85,7 @@ export default async function convertB3dmToI3sGeometry(
83
85
  generateBoundingVolumes: boolean,
84
86
  geoidHeightModel: Geoid,
85
87
  workerSource: {[key: string]: string}
86
- ) {
88
+ ): Promise<I3SConvertedResources[] | null> {
87
89
  const useCartesianPositions = generateBoundingVolumes;
88
90
  const materialAndTextureList: I3SMaterialWithTexture[] = convertMaterials(
89
91
  tileContent.gltf?.materials
@@ -95,14 +97,14 @@ export default async function convertB3dmToI3sGeometry(
95
97
  dataForAttributesConversion,
96
98
  useCartesianPositions
97
99
  );
98
- // TODO uncomment it when worker will be published on CDN.
99
- /*
100
- const convertedAttributesMap: Map<string, ConvertedAttributes> =
101
- await transformI3SAttributesOnWorker(dataForAttributesConversion, {
102
- useCartesianPositions,
103
- source: workerSource.I3SAttributes
104
- });
105
- */
100
+ /** Usage of worker here brings more overhead than advantage */
101
+ // const convertedAttributesMap: Map<string, ConvertedAttributes> =
102
+ // await transformI3SAttributesOnWorker(dataForAttributesConversion, {
103
+ // reuseWorkers: true,
104
+ // _nodeWorkers: true,
105
+ // useCartesianPositions,
106
+ // source: workerSource.I3SAttributes
107
+ // });
106
108
 
107
109
  if (generateBoundingVolumes) {
108
110
  _generateBoundingVolumesFromGeometry(convertedAttributesMap, geoidHeightModel);
@@ -115,7 +117,6 @@ export default async function convertB3dmToI3sGeometry(
115
117
  }
116
118
 
117
119
  const result: I3SConvertedResources[] = [];
118
- let nodesCounter = nodeId;
119
120
  let {materials = []} = tileContent.gltf || {materials: []};
120
121
  if (!materials?.length) {
121
122
  materials.push({id: 'default'});
@@ -130,13 +131,14 @@ export default async function convertB3dmToI3sGeometry(
130
131
  continue;
131
132
  }
132
133
  const {material, texture} = materialAndTextureList[i];
134
+ const nodeId = addNodeToNodePage();
133
135
  result.push(
134
136
  await _makeNodeResources({
135
137
  convertedAttributes,
136
138
  material,
137
139
  texture,
138
140
  tileContent,
139
- nodeId: nodesCounter,
141
+ nodeId,
140
142
  featuresHashArray,
141
143
  propertyTable,
142
144
  attributeStorageInfo,
@@ -144,7 +146,6 @@ export default async function convertB3dmToI3sGeometry(
144
146
  workerSource
145
147
  })
146
148
  );
147
- nodesCounter++;
148
149
  }
149
150
 
150
151
  if (!result.length) {
@@ -274,6 +275,7 @@ async function _makeNodeResources({
274
275
  }
275
276
 
276
277
  return {
278
+ nodeId,
277
279
  geometry: fileBuffer,
278
280
  compressedGeometry,
279
281
  texture,
@@ -297,7 +299,7 @@ export async function convertAttributes(
297
299
  attributesData: B3DMAttributesData,
298
300
  useCartesianPositions: boolean
299
301
  ): Promise<Map<string, ConvertedAttributes>> {
300
- const {gltfMaterials, nodes, cartographicOrigin, cartesianModelMatrix} = attributesData;
302
+ const {gltfMaterials, nodes, images, cartographicOrigin, cartesianModelMatrix} = attributesData;
301
303
  const attributesMap = new Map<string, ConvertedAttributes>();
302
304
 
303
305
  for (const material of gltfMaterials || [{id: 'default'}]) {
@@ -314,6 +316,7 @@ export async function convertAttributes(
314
316
 
315
317
  convertNodes(
316
318
  nodes,
319
+ images,
317
320
  cartographicOrigin,
318
321
  cartesianModelMatrix,
319
322
  attributesMap,
@@ -344,6 +347,7 @@ export async function convertAttributes(
344
347
  * Gltf has hierarchical structure of nodes. This function converts nodes starting from those which are in gltf scene object.
345
348
  * The goal is applying tranformation matrix for all children. Functions "convertNodes" and "convertNode" work together recursively.
346
349
  * @param nodes - gltf nodes array
350
+ * @param images - gltf images array
347
351
  * @param tileContent - 3d tile content
348
352
  * @param attributesMap - for recursive concatenation of attributes
349
353
  * @param useCartesianPositions - convert positions to absolute cartesian coordinates instead of cartographic offsets.
@@ -353,6 +357,7 @@ export async function convertAttributes(
353
357
  */
354
358
  function convertNodes(
355
359
  nodes: GLTFNodePostprocessed[],
360
+ images: GLTFImagePostprocessed[],
356
361
  cartographicOrigin: Vector3,
357
362
  cartesianModelMatrix: Matrix4,
358
363
  attributesMap: Map<string, ConvertedAttributes>,
@@ -363,6 +368,7 @@ function convertNodes(
363
368
  for (const node of nodes) {
364
369
  convertNode(
365
370
  node,
371
+ images,
366
372
  cartographicOrigin,
367
373
  cartesianModelMatrix,
368
374
  attributesMap,
@@ -406,6 +412,7 @@ function getCompositeTransformationMatrix(node, matrix) {
406
412
  /**
407
413
  * Convert all primitives of node and all children nodes
408
414
  * @param node - gltf node
415
+ * @param images - gltf images array
409
416
  * @param {Object} tileContent - 3d tile content
410
417
  * @param {Map} attributesMap Map<{positions: Float32Array, normals: Float32Array, texCoords: Float32Array, colors: Uint8Array, featureIndices: Array}> - for recursive concatenation of
411
418
  * attributes
@@ -415,6 +422,7 @@ function getCompositeTransformationMatrix(node, matrix) {
415
422
  */
416
423
  function convertNode(
417
424
  node: GLTFNodePostprocessed,
425
+ images: GLTFImagePostprocessed[],
418
426
  cartographicOrigin: Vector3,
419
427
  cartesianModelMatrix: Matrix4,
420
428
  attributesMap: Map<string, ConvertedAttributes>,
@@ -424,7 +432,6 @@ function convertNode(
424
432
  const transformationMatrix = getCompositeTransformationMatrix(node, matrix);
425
433
 
426
434
  const mesh = node.mesh;
427
- const images = node.images;
428
435
 
429
436
  if (mesh) {
430
437
  convertMesh(
@@ -440,6 +447,7 @@ function convertNode(
440
447
 
441
448
  convertNodes(
442
449
  node.children || [],
450
+ images,
443
451
  cartographicOrigin,
444
452
  cartesianModelMatrix,
445
453
  attributesMap,
@@ -461,7 +469,7 @@ function convertNode(
461
469
  */
462
470
  function convertMesh(
463
471
  mesh: GLTFMeshPostprocessed,
464
- images: Image[],
472
+ images: GLTFImagePostprocessed[],
465
473
  cartographicOrigin: Vector3,
466
474
  cartesianModelMatrix: Matrix4,
467
475
  attributesMap: Map<string, ConvertedAttributes>,
@@ -695,8 +703,8 @@ function getBatchIds(
695
703
  attributes: {
696
704
  [key: string]: GLTFAccessorPostprocessed;
697
705
  },
698
- primitive: MeshPrimitive,
699
- images: Image[]
706
+ primitive: GLTFMeshPrimitivePostprocessed,
707
+ images: GLTFImagePostprocessed[]
700
708
  ): number[] {
701
709
  const batchIds: number[] = handleBatchIdsExtensions(attributes, primitive, images);
702
710
 
@@ -1293,15 +1301,16 @@ function generateFeatureIndexAttribute(featureIndex, faceRange) {
1293
1301
  * Find property table in tile
1294
1302
  * For example it can be batchTable for b3dm files or property table in gLTF extension.
1295
1303
  * @param sourceTile
1304
+ * @return batch table from b3dm / feature properties from EXT_FEATURE_METADATA
1296
1305
  */
1297
- export function getPropertyTable(sourceTile: Tile3D): FeatureTableJson | null {
1298
- const batchTableJson = sourceTile?.content?.batchTableJson;
1306
+ export function getPropertyTable(tileContent: B3DMContent): FeatureTableJson | null {
1307
+ const batchTableJson = tileContent?.batchTableJson;
1299
1308
 
1300
1309
  if (batchTableJson) {
1301
1310
  return batchTableJson;
1302
1311
  }
1303
1312
 
1304
- const {extensionName, extension} = getPropertyTableExtension(sourceTile);
1313
+ const {extensionName, extension} = getPropertyTableExtension(tileContent);
1305
1314
 
1306
1315
  switch (extensionName) {
1307
1316
  case EXT_MESH_FEATURES: {
@@ -1320,9 +1329,9 @@ export function getPropertyTable(sourceTile: Tile3D): FeatureTableJson | null {
1320
1329
  * Check extensions which can be with property table inside.
1321
1330
  * @param sourceTile
1322
1331
  */
1323
- function getPropertyTableExtension(sourceTile: Tile3D) {
1332
+ function getPropertyTableExtension(tileContent: B3DMContent) {
1324
1333
  const extensionsWithPropertyTables = [EXT_FEATURE_METADATA, EXT_MESH_FEATURES];
1325
- const extensionsUsed = sourceTile?.content?.gltf?.extensionsUsed;
1334
+ const extensionsUsed = tileContent?.gltf?.extensionsUsed;
1326
1335
 
1327
1336
  if (!extensionsUsed) {
1328
1337
  return {extensionName: null, extension: null};
@@ -1330,14 +1339,14 @@ function getPropertyTableExtension(sourceTile: Tile3D) {
1330
1339
 
1331
1340
  let extensionName: string = '';
1332
1341
 
1333
- for (const extensionItem of sourceTile?.content?.gltf?.extensionsUsed) {
1342
+ for (const extensionItem of tileContent?.gltf?.extensionsUsed || []) {
1334
1343
  if (extensionsWithPropertyTables.includes(extensionItem)) {
1335
1344
  extensionName = extensionItem;
1336
1345
  break;
1337
1346
  }
1338
1347
  }
1339
1348
 
1340
- const extension = sourceTile?.content?.gltf?.extensions?.[extensionName];
1349
+ const extension = tileContent?.gltf?.extensions?.[extensionName];
1341
1350
 
1342
1351
  return {extensionName, extension};
1343
1352
  }
@@ -1,9 +1,9 @@
1
1
  import type {B3DMContent} from '@loaders.gl/3d-tiles';
2
- import type {Accessor} from 'modules/gltf/src/lib/types/gltf-postprocessed-schema';
2
+ import type {GLTFAccessorPostprocessed, GLTFNodePostprocessed} from '@loaders.gl/gltf';
3
3
  import type {B3DMAttributesData} from '../../i3s-attributes-worker';
4
4
 
5
5
  type AttributesObject = {
6
- [k: string]: Accessor;
6
+ [k: string]: GLTFAccessorPostprocessed;
7
7
  };
8
8
 
9
9
  /**
@@ -38,46 +38,67 @@ export function prepareDataForAttributesConversion(tileContent: B3DMContent): B3
38
38
  const images =
39
39
  tileContent.gltf?.images?.map((imageObject) => {
40
40
  // Need data only for uncompressed images because we can't get batchIds from compressed textures.
41
- const data = imageObject?.image?.compressed ? null : imageObject?.image?.data.subarray();
42
- return {
43
- data,
44
- compressed: Boolean(imageObject?.image?.compressed),
45
- height: imageObject.image.height,
46
- width: imageObject.image.width,
47
- components: imageObject.image.components,
48
- mimeType: imageObject.mimeType
49
- };
41
+ if (imageObject?.image?.compressed) {
42
+ return {
43
+ data: null,
44
+ compressed: true
45
+ };
46
+ } else {
47
+ const data = imageObject?.image?.data;
48
+ const dataCopy = new Uint8Array(data.length);
49
+ dataCopy.set(data);
50
+ return {
51
+ data: dataCopy,
52
+ compressed: false,
53
+ height: imageObject.image.height,
54
+ width: imageObject.image.width,
55
+ components: imageObject.image.components,
56
+ mimeType: imageObject.mimeType
57
+ };
58
+ }
50
59
  }) || [];
51
60
 
52
- const prepearedNodes = nodes.map((node) => {
53
- if (!node.mesh) {
54
- return node;
55
- }
56
-
57
- return {
58
- ...node,
59
- images,
60
- mesh: {
61
- ...node.mesh,
62
- primitives: node.mesh?.primitives.map((primitive) => ({
63
- ...primitive,
64
- indices: {value: primitive?.indices?.value},
65
- attributes: getB3DMAttributesWithoutBufferView(primitive.attributes),
66
- material: {
67
- id: primitive?.material?.id
68
- }
69
- }))
70
- }
71
- };
72
- });
61
+ prepareNodes(nodes);
73
62
 
74
63
  const cartographicOrigin = tileContent.cartographicOrigin;
75
64
  const cartesianModelMatrix = tileContent.cartesianModelMatrix;
76
65
 
77
66
  return {
78
67
  gltfMaterials,
79
- nodes: prepearedNodes,
68
+ nodes,
69
+ images,
80
70
  cartographicOrigin,
81
71
  cartesianModelMatrix
82
72
  };
83
73
  }
74
+
75
+ /**
76
+ * Traverse all nodes to replace all sensible data with copy to avoid data corruption in worker.
77
+ * @param nodes
78
+ */
79
+ function prepareNodes(nodes: GLTFNodePostprocessed[]): void {
80
+ for (let index = 0; index < nodes.length; index++) {
81
+ const node = nodes[index] as any;
82
+
83
+ if (node.mesh) {
84
+ nodes[index] = {
85
+ ...node,
86
+ mesh: {
87
+ ...node.mesh,
88
+ primitives: node.mesh?.primitives.map((primitive) => ({
89
+ ...primitive,
90
+ indices: {value: primitive?.indices?.value},
91
+ attributes: getB3DMAttributesWithoutBufferView(primitive.attributes),
92
+ material: {
93
+ id: primitive?.material?.id
94
+ }
95
+ }))
96
+ }
97
+ };
98
+ }
99
+
100
+ if (node.children) {
101
+ prepareNodes(node.children);
102
+ }
103
+ }
104
+ }
@@ -79,6 +79,14 @@ export default class NodePages {
79
79
  return this.nodePages[pageIndex].nodes[nodeIndex];
80
80
  }
81
81
 
82
+ /**
83
+ * Update all fields in the node excluding id
84
+ */
85
+ updateAll(id: number, data: NodeInPage): void {
86
+ const node = this.getNodeById(id);
87
+ Object.assign(node, data, {index: node.index});
88
+ }
89
+
82
90
  /**
83
91
  * Update material in node.mesh object by node id
84
92
  * @param id - end-to-end index of the node
@@ -114,7 +122,7 @@ export default class NodePages {
114
122
  */
115
123
  updateNodeAttributeByNodeId(id: number): void {
116
124
  const node = this.getNodeById(id);
117
- if (!node.mesh) {
125
+ if (!node.mesh || !node.index) {
118
126
  return;
119
127
  }
120
128
  node.mesh.attribute.resource = node.index;
@@ -164,7 +172,7 @@ export default class NodePages {
164
172
  * @param node - node object
165
173
  */
166
174
  updateResourceInMesh(node: NodeInPage): void {
167
- if (node.mesh) {
175
+ if (node.mesh && isFinite(node.index)) {
168
176
  node.mesh.geometry.resource = node.index;
169
177
  }
170
178
  }