@loaders.gl/tile-converter 4.0.0-alpha.23 → 4.0.0-alpha.25

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 (118) hide show
  1. package/dist/3d-tiles-converter/helpers/b3dm-converter.d.ts +4 -4
  2. package/dist/3d-tiles-converter/helpers/load-i3s.d.ts.map +1 -1
  3. package/dist/converter.min.js +105 -105
  4. package/dist/dist.min.js +725 -652
  5. package/dist/es5/3d-tiles-converter/helpers/b3dm-converter.js +18 -18
  6. package/dist/es5/3d-tiles-converter/helpers/b3dm-converter.js.map +1 -1
  7. package/dist/es5/3d-tiles-converter/helpers/load-i3s.js.map +1 -1
  8. package/dist/es5/deps-installer/deps-installer.js +1 -1
  9. package/dist/es5/i3s-converter/helpers/batch-ids-extensions.js +16 -14
  10. package/dist/es5/i3s-converter/helpers/batch-ids-extensions.js.map +1 -1
  11. package/dist/es5/i3s-converter/helpers/feature-attributes.js +6 -18
  12. package/dist/es5/i3s-converter/helpers/feature-attributes.js.map +1 -1
  13. package/dist/es5/i3s-converter/helpers/geometry-attributes.js +83 -44
  14. package/dist/es5/i3s-converter/helpers/geometry-attributes.js.map +1 -1
  15. package/dist/es5/i3s-converter/helpers/geometry-converter.js +13 -83
  16. package/dist/es5/i3s-converter/helpers/geometry-converter.js.map +1 -1
  17. package/dist/es5/i3s-converter/helpers/preprocess-3d-tiles.js +15 -8
  18. package/dist/es5/i3s-converter/helpers/preprocess-3d-tiles.js.map +1 -1
  19. package/dist/es5/i3s-converter/i3s-converter.js.map +1 -1
  20. package/dist/es5/i3s-converter/types.js.map +1 -1
  21. package/dist/es5/pgm-loader.js +11 -3
  22. package/dist/es5/pgm-loader.js.map +1 -1
  23. package/dist/esm/3d-tiles-converter/helpers/b3dm-converter.js +8 -8
  24. package/dist/esm/3d-tiles-converter/helpers/b3dm-converter.js.map +1 -1
  25. package/dist/esm/3d-tiles-converter/helpers/load-i3s.js.map +1 -1
  26. package/dist/esm/deps-installer/deps-installer.js +1 -1
  27. package/dist/esm/i3s-converter/helpers/batch-ids-extensions.js +5 -15
  28. package/dist/esm/i3s-converter/helpers/batch-ids-extensions.js.map +1 -1
  29. package/dist/esm/i3s-converter/helpers/feature-attributes.js +5 -5
  30. package/dist/esm/i3s-converter/helpers/feature-attributes.js.map +1 -1
  31. package/dist/esm/i3s-converter/helpers/geometry-attributes.js +76 -34
  32. package/dist/esm/i3s-converter/helpers/geometry-attributes.js.map +1 -1
  33. package/dist/esm/i3s-converter/helpers/geometry-converter.js +10 -80
  34. package/dist/esm/i3s-converter/helpers/geometry-converter.js.map +1 -1
  35. package/dist/esm/i3s-converter/helpers/preprocess-3d-tiles.js +15 -9
  36. package/dist/esm/i3s-converter/helpers/preprocess-3d-tiles.js.map +1 -1
  37. package/dist/esm/i3s-converter/i3s-converter.js.map +1 -1
  38. package/dist/esm/i3s-converter/types.js.map +1 -1
  39. package/dist/esm/i3s-server/bin/i3s-server.min.js +75 -75
  40. package/dist/esm/pgm-loader.js +7 -4
  41. package/dist/esm/pgm-loader.js.map +1 -1
  42. package/dist/i3s-converter/helpers/batch-ids-extensions.d.ts +4 -1
  43. package/dist/i3s-converter/helpers/batch-ids-extensions.d.ts.map +1 -1
  44. package/dist/i3s-converter/helpers/feature-attributes.d.ts +6 -6
  45. package/dist/i3s-converter/helpers/feature-attributes.d.ts.map +1 -1
  46. package/dist/i3s-converter/helpers/geometry-attributes.d.ts.map +1 -1
  47. package/dist/i3s-converter/helpers/geometry-converter.d.ts +1 -1
  48. package/dist/i3s-converter/helpers/geometry-converter.d.ts.map +1 -1
  49. package/dist/i3s-converter/helpers/preprocess-3d-tiles.d.ts.map +1 -1
  50. package/dist/i3s-converter/i3s-converter.d.ts.map +1 -1
  51. package/dist/i3s-converter/types.d.ts +13 -5
  52. package/dist/i3s-converter/types.d.ts.map +1 -1
  53. package/dist/pgm-loader.d.ts +9 -2
  54. package/dist/pgm-loader.d.ts.map +1 -1
  55. package/dist/slpk-extractor.min.js +42 -42
  56. package/package.json +14 -14
  57. package/src/3d-tiles-converter/helpers/b3dm-converter.ts +8 -8
  58. package/src/3d-tiles-converter/helpers/load-i3s.ts +1 -0
  59. package/src/i3s-converter/helpers/batch-ids-extensions.ts +14 -35
  60. package/src/i3s-converter/helpers/feature-attributes.ts +14 -11
  61. package/src/i3s-converter/helpers/geometry-attributes.ts +80 -50
  62. package/src/i3s-converter/helpers/geometry-converter.ts +41 -177
  63. package/src/i3s-converter/helpers/preprocess-3d-tiles.ts +30 -9
  64. package/src/i3s-converter/i3s-converter.ts +0 -2
  65. package/src/i3s-converter/types.ts +14 -5
  66. package/src/pgm-loader.ts +15 -7
  67. package/dist/3d-tiles-converter/3d-tiles-converter.js +0 -279
  68. package/dist/3d-tiles-converter/helpers/b3dm-converter.js +0 -271
  69. package/dist/3d-tiles-converter/helpers/i3s-obb-to-3d-tiles-obb.js +0 -23
  70. package/dist/3d-tiles-converter/helpers/load-i3s.js +0 -42
  71. package/dist/3d-tiles-converter/helpers/texture-atlas.js +0 -54
  72. package/dist/3d-tiles-converter/json-templates/tileset.js +0 -43
  73. package/dist/bundle.js +0 -5
  74. package/dist/constants.js +0 -4
  75. package/dist/converter-cli.js +0 -222
  76. package/dist/deps-installer/deps-installer.js +0 -89
  77. package/dist/i3s-converter/helpers/batch-ids-extensions.js +0 -179
  78. package/dist/i3s-converter/helpers/coordinate-converter.js +0 -122
  79. package/dist/i3s-converter/helpers/create-scene-server-path.js +0 -28
  80. package/dist/i3s-converter/helpers/feature-attributes.js +0 -218
  81. package/dist/i3s-converter/helpers/geometry-attributes.js +0 -203
  82. package/dist/i3s-converter/helpers/geometry-converter.js +0 -1321
  83. package/dist/i3s-converter/helpers/gltf-attributes.js +0 -129
  84. package/dist/i3s-converter/helpers/load-3d-tiles.js +0 -99
  85. package/dist/i3s-converter/helpers/node-debug.js +0 -120
  86. package/dist/i3s-converter/helpers/node-index-document.js +0 -271
  87. package/dist/i3s-converter/helpers/node-pages.js +0 -316
  88. package/dist/i3s-converter/helpers/preprocess-3d-tiles.js +0 -100
  89. package/dist/i3s-converter/helpers/tileset-traversal.js +0 -29
  90. package/dist/i3s-converter/i3s-converter.js +0 -964
  91. package/dist/i3s-converter/json-templates/geometry-definitions.js +0 -87
  92. package/dist/i3s-converter/json-templates/layers.js +0 -139
  93. package/dist/i3s-converter/json-templates/metadata.js +0 -25
  94. package/dist/i3s-converter/json-templates/node.js +0 -89
  95. package/dist/i3s-converter/json-templates/scene-server.js +0 -31
  96. package/dist/i3s-converter/json-templates/shared-resources.js +0 -129
  97. package/dist/i3s-converter/json-templates/store.js +0 -103
  98. package/dist/i3s-converter/types.js +0 -17
  99. package/dist/i3s-server/app.js +0 -29
  100. package/dist/i3s-server/bin/www.js +0 -37
  101. package/dist/i3s-server/controllers/index-controller.js +0 -31
  102. package/dist/i3s-server/controllers/slpk-controller.js +0 -33
  103. package/dist/i3s-server/routes/index.js +0 -20
  104. package/dist/i3s-server/routes/slpk-router.js +0 -34
  105. package/dist/i3s-server/utils/create-scene-server.js +0 -22
  106. package/dist/i3s-server/utils/server-utils.js +0 -66
  107. package/dist/index.js +0 -10
  108. package/dist/lib/utils/cli-utils.js +0 -82
  109. package/dist/lib/utils/compress-util.js +0 -257
  110. package/dist/lib/utils/file-utils.js +0 -139
  111. package/dist/lib/utils/geometry-utils.js +0 -18
  112. package/dist/lib/utils/lod-conversion-utils.js +0 -76
  113. package/dist/lib/utils/queue.js +0 -18
  114. package/dist/lib/utils/statistic-utills.js +0 -64
  115. package/dist/lib/utils/write-queue.js +0 -80
  116. package/dist/pgm-loader.js +0 -24
  117. package/dist/slpk-extractor/slpk-extractor.js +0 -75
  118. package/dist/slpk-extractor-cli.js +0 -102
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@loaders.gl/tile-converter",
3
- "version": "4.0.0-alpha.23",
3
+ "version": "4.0.0-alpha.25",
4
4
  "description": "Converter",
5
5
  "license": "MIT",
6
6
  "publishConfig": {
@@ -45,18 +45,18 @@
45
45
  "build-i3s-server-bundle": "esbuild src/i3s-server/bin/www.ts --outfile=dist/esm/i3s-server/bin/i3s-server.min.js --platform=node --target=esnext,node14 --external:join-images --minify --bundle --define:__VERSION__=\\\"$npm_package_version\\\""
46
46
  },
47
47
  "dependencies": {
48
- "@loaders.gl/3d-tiles": "4.0.0-alpha.23",
49
- "@loaders.gl/crypto": "4.0.0-alpha.23",
50
- "@loaders.gl/draco": "4.0.0-alpha.23",
51
- "@loaders.gl/gltf": "4.0.0-alpha.23",
52
- "@loaders.gl/i3s": "4.0.0-alpha.23",
53
- "@loaders.gl/images": "4.0.0-alpha.23",
54
- "@loaders.gl/loader-utils": "4.0.0-alpha.23",
55
- "@loaders.gl/polyfills": "4.0.0-alpha.23",
56
- "@loaders.gl/textures": "4.0.0-alpha.23",
57
- "@loaders.gl/tiles": "4.0.0-alpha.23",
58
- "@loaders.gl/worker-utils": "4.0.0-alpha.23",
59
- "@loaders.gl/zip": "4.0.0-alpha.23",
48
+ "@loaders.gl/3d-tiles": "4.0.0-alpha.25",
49
+ "@loaders.gl/crypto": "4.0.0-alpha.25",
50
+ "@loaders.gl/draco": "4.0.0-alpha.25",
51
+ "@loaders.gl/gltf": "4.0.0-alpha.25",
52
+ "@loaders.gl/i3s": "4.0.0-alpha.25",
53
+ "@loaders.gl/images": "4.0.0-alpha.25",
54
+ "@loaders.gl/loader-utils": "4.0.0-alpha.25",
55
+ "@loaders.gl/polyfills": "4.0.0-alpha.25",
56
+ "@loaders.gl/textures": "4.0.0-alpha.25",
57
+ "@loaders.gl/tiles": "4.0.0-alpha.25",
58
+ "@loaders.gl/worker-utils": "4.0.0-alpha.25",
59
+ "@loaders.gl/zip": "4.0.0-alpha.25",
60
60
  "@math.gl/core": "^3.5.1",
61
61
  "@math.gl/culling": "^3.5.1",
62
62
  "@math.gl/geoid": "^3.5.1",
@@ -80,7 +80,7 @@
80
80
  "join-images": "^1.1.3",
81
81
  "sharp": "^0.31.3"
82
82
  },
83
- "gitHead": "e212f2a0c0e342f7cb65ce84fa2ff39f64b7d94b",
83
+ "gitHead": "40135f391b869388dbbcd615bbe51178d0c370be",
84
84
  "devDependencies": {
85
85
  "@types/express": "^4.17.17",
86
86
  "@types/node": "^20.4.2"
@@ -33,7 +33,7 @@ export default class B3dmConverter {
33
33
  i3sAttributesData: I3SAttributesData,
34
34
  featureAttributes: any = null
35
35
  ): Promise<ArrayBuffer> {
36
- const gltf = await this.buildGltf(i3sAttributesData, featureAttributes);
36
+ const gltf = await this.buildGLTF(i3sAttributesData, featureAttributes);
37
37
  const b3dm = encodeSync(
38
38
  {
39
39
  gltfEncoded: new Uint8Array(gltf),
@@ -51,7 +51,7 @@ export default class B3dmConverter {
51
51
  * @param i3sTile - Tile3D instance for I3S node
52
52
  * @returns - encoded glb content
53
53
  */
54
- async buildGltf(
54
+ async buildGLTF(
55
55
  i3sAttributesData: I3SAttributesData,
56
56
  featureAttributes: any
57
57
  ): Promise<ArrayBuffer> {
@@ -59,8 +59,8 @@ export default class B3dmConverter {
59
59
  const {material, attributes, indices: originalIndices, modelMatrix} = tileContent;
60
60
  const gltfBuilder = new GLTFScenegraph();
61
61
 
62
- const textureIndex = await this._addI3sTextureToGltf(tileContent, textureFormat, gltfBuilder);
63
- const pbrMaterialInfo = this._convertI3sMaterialToGltfMaterial(material, textureIndex);
62
+ const textureIndex = await this._addI3sTextureToGLTF(tileContent, textureFormat, gltfBuilder);
63
+ const pbrMaterialInfo = this._convertI3sMaterialToGLTFMaterial(material, textureIndex);
64
64
  const materialIndex = gltfBuilder.addMaterial(pbrMaterialInfo);
65
65
 
66
66
  const positions = attributes.positions;
@@ -115,7 +115,7 @@ export default class B3dmConverter {
115
115
  * @param {GLTFScenegraph} gltfBuilder - gltfScenegraph instance to construct GLTF
116
116
  * @returns {Promise<number | null>} - GLTF texture index
117
117
  */
118
- async _addI3sTextureToGltf(tileContent, textureFormat, gltfBuilder) {
118
+ async _addI3sTextureToGLTF(tileContent, textureFormat, gltfBuilder) {
119
119
  const {texture, material, attributes} = tileContent;
120
120
  let textureIndex = null;
121
121
  let selectedTexture = texture;
@@ -222,7 +222,7 @@ export default class B3dmConverter {
222
222
  * @param {number | null} textureIndex - texture index in GLTF
223
223
  * @returns {object} GLTF material
224
224
  */
225
- _convertI3sMaterialToGltfMaterial(material, textureIndex) {
225
+ _convertI3sMaterialToGLTFMaterial(material, textureIndex) {
226
226
  const isTextureIndexExists = textureIndex !== null;
227
227
 
228
228
  if (!material) {
@@ -248,7 +248,7 @@ export default class B3dmConverter {
248
248
  }
249
249
 
250
250
  if (textureIndex !== null) {
251
- material = this._setGltfTexture(material, textureIndex);
251
+ material = this._setGLTFTexture(material, textureIndex);
252
252
  }
253
253
 
254
254
  return material;
@@ -260,7 +260,7 @@ export default class B3dmConverter {
260
260
  * @param {number} textureIndex - texture index in GLTF
261
261
  * @returns {void}
262
262
  */
263
- _setGltfTexture(materialDefinition, textureIndex) {
263
+ _setGLTFTexture(materialDefinition, textureIndex) {
264
264
  const material = {
265
265
  ...materialDefinition,
266
266
  pbrMetallicRoughness: {...materialDefinition.pbrMetallicRoughness}
@@ -47,5 +47,6 @@ export const loadI3SContent = async (
47
47
  };
48
48
  const tileContent = await load(sourceTile.contentUrl, I3SLoader, loadOptions);
49
49
 
50
+ // @ts-expect-error
50
51
  return tileContent;
51
52
  };
@@ -3,8 +3,7 @@ import type {NumericArray} from '@loaders.gl/loader-utils';
3
3
  import type {
4
4
  GLTF_EXT_feature_metadata_FeatureIdTexture,
5
5
  GLTF_EXT_feature_metadata_GLTF,
6
- GLTF_EXT_feature_metadata_Primitive,
7
- GLTF_EXT_structural_metadata
6
+ GLTF_EXT_feature_metadata_Primitive
8
7
  } from '@loaders.gl/gltf';
9
8
 
10
9
  import type {GLTF_EXT_mesh_features} from '@loaders.gl/gltf';
@@ -12,11 +11,14 @@ import type {GLTF_EXT_mesh_features} from '@loaders.gl/gltf';
12
11
  import {TypedArray} from '@math.gl/core';
13
12
  import {TextureImageProperties} from '../types';
14
13
  import {emod} from '@loaders.gl/math';
15
- import {EXT_STRUCTURAL_METADATA, EXT_MESH_FEATURES, EXT_FEATURE_METADATA} from '@loaders.gl/gltf';
14
+ import {EXT_MESH_FEATURES, EXT_FEATURE_METADATA} from '@loaders.gl/gltf';
16
15
  import {Tiles3DTileContent} from '@loaders.gl/3d-tiles';
17
16
 
18
17
  /**
19
- * Get featureTexture by metadataClass
18
+ * Get featureTexture by a metadata class.
19
+ * Metadata classes come from a structural metadata extesion (EXT_feature_metadata or EXT_structural_metadata).
20
+ * The glTF might contain multiple texel-level metadata textures related to different classes. Having only one metadata class
21
+ * selected to convert to I3S, we have to pick only one texture to convert to per-vertex property.
20
22
  * @param tileContent - 3d tile content
21
23
  * @param metadataClass - user selected feature metadata class name
22
24
  * @returns featureTexture key
@@ -72,12 +74,6 @@ export function handleBatchIdsExtensions(
72
74
  );
73
75
  case EXT_MESH_FEATURES:
74
76
  return handleExtMeshFeaturesExtension(attributes, extensionData as GLTF_EXT_mesh_features);
75
- case EXT_STRUCTURAL_METADATA:
76
- return handleExtStructuralMetadataExtension(
77
- attributes,
78
- extensionData as GLTF_EXT_structural_metadata
79
- );
80
-
81
77
  default:
82
78
  return [];
83
79
  }
@@ -86,23 +82,6 @@ export function handleBatchIdsExtensions(
86
82
  return [];
87
83
  }
88
84
 
89
- function handleExtStructuralMetadataExtension(
90
- attributes: {
91
- [key: string]: GLTFAccessorPostprocessed;
92
- },
93
- extStructuralMetadata: GLTF_EXT_structural_metadata
94
- ): NumericArray {
95
- // Take only first extension object to get batchIds attribute name.
96
- const dataAttributeNames = extStructuralMetadata?.dataAttributeNames;
97
- if (dataAttributeNames?.length) {
98
- // Let's use the first element of the array
99
- // TODO: What to do with others if any?
100
- const batchIdsAttribute = attributes[dataAttributeNames[0]];
101
- return batchIdsAttribute.value;
102
- }
103
- return [];
104
- }
105
-
106
85
  /**
107
86
  * Getting batchIds from EXT_mesh_features extensions.
108
87
  * @param attributes - gltf accessors
@@ -115,19 +94,19 @@ function handleExtMeshFeaturesExtension(
115
94
  },
116
95
  extMeshFeatures: GLTF_EXT_mesh_features
117
96
  ): NumericArray {
118
- const dataAttributeNames = extMeshFeatures?.dataAttributeNames;
119
- if (dataAttributeNames?.length) {
120
- // Let's use the first element of the array
121
- // TODO: What to do with others if any?
122
- const batchIdsAttribute = attributes[dataAttributeNames[0]];
123
- return batchIdsAttribute.value;
97
+ for (let ids of extMeshFeatures.featureIds) {
98
+ if (typeof ids.propertyTable !== 'undefined') {
99
+ // propertyTable is an index that can be 0
100
+ // return the first featureID set that corresponts to property table.
101
+ return ids.data as NumericArray;
102
+ }
124
103
  }
125
104
  return [];
126
105
  }
127
106
 
128
107
  /**
129
108
  * Get batchIds from EXT_feature_metadata extension.
130
- * Docs - https://github.com/CesiumGS/glTF/tree/3d-tiles-next/extensions/2.0/Vendor/EXT_feature_metadata
109
+ * @see - https://github.com/CesiumGS/glTF/tree/3d-tiles-next/extensions/2.0/Vendor/EXT_feature_metadata
131
110
  * @param attributes - glTF attributes
132
111
  * @param extFeatureMetadata - primitive-level EXT_FEATURE_METADATA extension data
133
112
  * @param textures - texture images
@@ -182,7 +161,7 @@ function handleExtFeatureMetadataExtension(
182
161
 
183
162
  /**
184
163
  * Generates implicit feature ids
185
- * Spec - https://github.com/CesiumGS/glTF/tree/3d-tiles-next/extensions/2.0/Vendor/EXT_feature_metadata#implicit-feature-ids
164
+ * @see - https://github.com/CesiumGS/glTF/tree/3d-tiles-next/extensions/2.0/Vendor/EXT_feature_metadata#implicit-feature-ids
186
165
  * @param featuresCount
187
166
  * @param constant
188
167
  * @param devisor
@@ -9,26 +9,26 @@ import {
9
9
  } from '@loaders.gl/i3s';
10
10
 
11
11
  /**
12
- * Takes attributes from property table based on featureIds.
12
+ * Takes attributes from property table based on featureIdsMap.
13
13
  * If there is no property value for particular featureId (index) the property will be null.
14
14
  * Example:
15
15
  * Initial data:
16
- * OBJECTID: [0, 1, 5]
16
+ * OBJECTID: {0: 0, 3: 33, 4: 333}
17
17
  * component: ['Windows', 'Frames', 'Wall', 'Roof', 'Skylight']
18
18
  * Result:
19
- * OBJECTID: [0, 1, 5]
20
- * component: ['Windows', 'Frames', 'null']
21
- * @param featureIds
19
+ * OBJECTID: [0, 33, 333]
20
+ * component: ['Windows', 'Roof', 'Skylight']
21
+ * @param featureIdsMap
22
22
  * @param propertyTable
23
23
  */
24
24
  export function flattenPropertyTableByFeatureIds(
25
- featureIds: number[],
25
+ featureIdsMap: Record<string, number>,
26
26
  propertyTable: FeatureTableJson
27
27
  ): FeatureTableJson {
28
28
  const resultPropertyTable: FeatureTableJson = {};
29
29
  for (const propertyName in propertyTable) {
30
30
  const properties = propertyTable[propertyName];
31
- resultPropertyTable[propertyName] = getPropertiesByFeatureIds(properties, featureIds);
31
+ resultPropertyTable[propertyName] = getPropertiesByFeatureIds(properties, featureIdsMap);
32
32
  }
33
33
 
34
34
  return resultPropertyTable;
@@ -37,14 +37,17 @@ export function flattenPropertyTableByFeatureIds(
37
37
  /**
38
38
  * Getting properties by featureId index
39
39
  * @param properties
40
- * @param featureIds
40
+ * @param featureIdsMap
41
41
  */
42
- function getPropertiesByFeatureIds(properties: unknown[], featureIds: number[]): unknown[] {
42
+ function getPropertiesByFeatureIds(
43
+ properties: unknown[],
44
+ featureIdsMap: Record<string, number>
45
+ ): unknown[] {
43
46
  const resultProperties: unknown[] = [];
44
47
 
45
48
  if (properties) {
46
- for (const featureId of featureIds) {
47
- const property = properties[featureId] || null;
49
+ for (const featureIdKey in featureIdsMap) {
50
+ const property = properties[featureIdKey] || null;
48
51
  resultProperties.push(property);
49
52
  }
50
53
  }
@@ -1,4 +1,9 @@
1
- import type {GeometryAttributes, ConvertedAttributes, GroupedByFeatureIdAttributes} from '../types';
1
+ import type {
2
+ GeometryAttributes,
3
+ ConvertedAttributes,
4
+ GroupedByFeatureIdAttributes,
5
+ GroupedAttributes
6
+ } from '../types';
2
7
  import {concatenateTypedArrays} from '@loaders.gl/loader-utils';
3
8
 
4
9
  const VALUES_PER_VERTEX = 3;
@@ -125,6 +130,11 @@ function makeAttributeObjects(attributes: GeometryAttributes): GroupedByFeatureI
125
130
  let colorsList = new Uint8Array(colors);
126
131
  let texCoordsList = new Float32Array(texCoords);
127
132
  let uvRegionsList = new Uint16Array(uvRegions);
133
+ let positionsOffset = 0;
134
+ let normalsOffset = 0;
135
+ let colorsOffset = 0;
136
+ let uvRegionsOffset = 0;
137
+ let texCoordsOffset = 0;
128
138
 
129
139
  for (let index = 0; index < featureIds.length; index++) {
130
140
  const startIndex = faceRange[index * 2];
@@ -138,21 +148,21 @@ function makeAttributeObjects(attributes: GeometryAttributes): GroupedByFeatureI
138
148
 
139
149
  groupedData.push({
140
150
  featureId: featureIds[index],
141
- positions: positionsList.slice(0, positionsCount),
142
- normals: normalsList.slice(0, normalsCount),
143
- colors: colorsList.slice(0, colorsCount),
144
- uvRegions: uvRegionsList.slice(0, uvRegionsCount),
145
- texCoords: texCoordsList.slice(0, texCoordsCount)
151
+ positions: positionsList.subarray(positionsOffset, positionsOffset + positionsCount),
152
+ normals: normalsList.subarray(normalsOffset, normalsOffset + normalsCount),
153
+ colors: colorsList.subarray(colorsOffset, colorsOffset + colorsCount),
154
+ uvRegions: uvRegionsList.subarray(uvRegionsOffset, uvRegionsOffset + uvRegionsCount),
155
+ texCoords: texCoordsList.subarray(texCoordsOffset, texCoordsOffset + texCoordsCount)
146
156
  });
147
157
 
148
- positionsList = positionsList.slice(positionsCount);
149
- normalsList = normalsList.slice(normalsCount);
150
- colorsList = colorsList.slice(colorsCount);
151
- uvRegionsList = uvRegionsList.slice(uvRegionsCount);
152
- texCoordsList = texCoordsList.slice(texCoordsCount);
158
+ positionsOffset += positionsCount;
159
+ normalsOffset += normalsCount;
160
+ colorsOffset += colorsCount;
161
+ uvRegionsOffset += uvRegionsCount;
162
+ texCoordsOffset += texCoordsCount;
153
163
  }
154
164
 
155
- return groupedData.sort((first, second) => first.featureId - second.featureId);
165
+ return groupedData;
156
166
  }
157
167
 
158
168
  /**
@@ -195,35 +205,32 @@ function getSliceAttributeCount(
195
205
  function unifyObjectsByFeatureId(
196
206
  sortedData: GroupedByFeatureIdAttributes[]
197
207
  ): GroupedByFeatureIdAttributes[] {
198
- const uniqueObjects: GroupedByFeatureIdAttributes[] = [];
199
-
200
- for (let index = 0; index < sortedData.length; index++) {
201
- const currentObject = sortedData[index];
202
- const existingObject = uniqueObjects.find((obj) => obj.featureId === currentObject.featureId);
203
-
208
+ const groupedMetadata: {
209
+ featureId: number;
210
+ attributes: GroupedByFeatureIdAttributes[];
211
+ }[] = [];
212
+ for (const data of sortedData) {
213
+ const existingObject = groupedMetadata.find((obj) => obj.featureId === data.featureId);
204
214
  if (existingObject) {
205
- existingObject.positions = concatenateTypedArrays(
206
- existingObject.positions,
207
- currentObject.positions
208
- );
209
- existingObject.normals = concatenateTypedArrays(
210
- existingObject.normals,
211
- currentObject.normals
212
- );
213
- existingObject.colors = concatenateTypedArrays(existingObject.colors, currentObject.colors);
214
- existingObject.texCoords = concatenateTypedArrays(
215
- existingObject.texCoords,
216
- currentObject.texCoords
217
- );
218
- existingObject.uvRegions = concatenateTypedArrays(
219
- existingObject.uvRegions,
220
- currentObject.uvRegions
221
- );
215
+ existingObject.attributes.push(data);
222
216
  } else {
223
- uniqueObjects.push(currentObject);
217
+ groupedMetadata.push({
218
+ featureId: data.featureId,
219
+ attributes: [data]
220
+ });
224
221
  }
225
222
  }
226
223
 
224
+ const uniqueObjects: GroupedByFeatureIdAttributes[] = [];
225
+ for (const metatada of groupedMetadata) {
226
+ const attributes = concatenateAttributes(metatada.attributes);
227
+
228
+ uniqueObjects.push({
229
+ featureId: metatada.featureId,
230
+ ...attributes
231
+ });
232
+ }
233
+
227
234
  return uniqueObjects;
228
235
  }
229
236
 
@@ -238,12 +245,6 @@ function groupAttributesAndRangesByFeatureId(
238
245
  ): GeometryAttributes {
239
246
  const firstAttributeObject = unifiedObjects[0];
240
247
  const featureIds = [firstAttributeObject.featureId || 0];
241
-
242
- let positions = new Float32Array(firstAttributeObject.positions);
243
- let normals = new Float32Array(firstAttributeObject.normals);
244
- let colors = new Uint8Array(firstAttributeObject.colors);
245
- let uvRegions = new Uint16Array(firstAttributeObject.uvRegions);
246
- let texCoords = new Float32Array(firstAttributeObject.texCoords);
247
248
  const range = [0];
248
249
 
249
250
  let objIndex = 0;
@@ -253,12 +254,6 @@ function groupAttributesAndRangesByFeatureId(
253
254
  const currentAttributesObject = unifiedObjects[index];
254
255
  featureIds.push(currentAttributesObject.featureId || 0);
255
256
 
256
- positions = concatenateTypedArrays(positions, currentAttributesObject.positions);
257
- normals = concatenateTypedArrays(normals, currentAttributesObject.normals);
258
- colors = concatenateTypedArrays(colors, currentAttributesObject.colors);
259
- uvRegions = concatenateTypedArrays(uvRegions, currentAttributesObject.uvRegions);
260
- texCoords = concatenateTypedArrays(texCoords, currentAttributesObject.texCoords);
261
-
262
257
  const groupedObject = unifiedObjects[objIndex];
263
258
  range.push(groupedObject.positions.length / POSITIONS_AND_NORMALS_PER_TRIANGLE - 1 + sum);
264
259
  range.push(groupedObject.positions.length / POSITIONS_AND_NORMALS_PER_TRIANGLE + sum);
@@ -267,8 +262,43 @@ function groupAttributesAndRangesByFeatureId(
267
262
  objIndex += 1;
268
263
  }
269
264
 
270
- range.push(positions.length / POSITIONS_AND_NORMALS_PER_TRIANGLE - 1);
265
+ const attributes = concatenateAttributes(unifiedObjects);
266
+
267
+ range.push(attributes.positions.length / POSITIONS_AND_NORMALS_PER_TRIANGLE - 1);
271
268
 
272
269
  const faceRange = new Uint32Array(range);
273
- return {faceRange, featureIds, positions, normals, colors, uvRegions, texCoords, featureCount};
270
+ return {faceRange, featureIds, featureCount, ...attributes};
271
+ }
272
+
273
+ /**
274
+ * Concatenate attributes typed arrays
275
+ * @param attributes - grouped by featureId typed arrays
276
+ * @returns - concatenated typed array list
277
+ */
278
+ function concatenateAttributes(attributes: GroupedByFeatureIdAttributes[]): GroupedAttributes {
279
+ const positionGroups = attributes.map(({positions}) => positions);
280
+ const positions =
281
+ positionGroups.length > 1 ? concatenateTypedArrays(...positionGroups) : positionGroups[0];
282
+
283
+ const normalGroups = attributes.map(({normals}) => normals);
284
+ const normals =
285
+ normalGroups.length > 1 ? concatenateTypedArrays(...normalGroups) : normalGroups[0];
286
+
287
+ const colorGroups = attributes.map(({colors}) => colors);
288
+ const colors = colorGroups.length > 1 ? concatenateTypedArrays(...colorGroups) : colorGroups[0];
289
+
290
+ const texCoordGroups = attributes.map(({texCoords}) => texCoords);
291
+ const texCoords =
292
+ texCoordGroups.length > 1 ? concatenateTypedArrays(...texCoordGroups) : texCoordGroups[0];
293
+
294
+ const uvRegionGroups = attributes.map(({uvRegions}) => uvRegions);
295
+ const uvRegions =
296
+ uvRegionGroups.length > 1 ? concatenateTypedArrays(...uvRegionGroups) : uvRegionGroups[0];
297
+ return {
298
+ positions,
299
+ normals,
300
+ colors,
301
+ texCoords,
302
+ uvRegions
303
+ };
274
304
  }