@loaders.gl/tile-converter 4.2.0-alpha.3 → 4.2.0-alpha.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (144) hide show
  1. package/dist/3d-tiles-converter/3d-tiles-converter.d.ts +3 -3
  2. package/dist/3d-tiles-converter/3d-tiles-converter.d.ts.map +1 -1
  3. package/dist/3d-tiles-converter/3d-tiles-converter.js +329 -293
  4. package/dist/3d-tiles-converter/helpers/b3dm-converter.js +257 -200
  5. package/dist/3d-tiles-converter/helpers/i3s-obb-to-3d-tiles-obb.js +14 -5
  6. package/dist/3d-tiles-converter/helpers/load-i3s.js +106 -75
  7. package/dist/3d-tiles-converter/helpers/texture-atlas.js +44 -21
  8. package/dist/3d-tiles-converter/json-templates/tileset.js +32 -33
  9. package/dist/constants.js +0 -1
  10. package/dist/converter-cli.js +255 -234
  11. package/dist/converter.min.cjs +80 -90
  12. package/dist/deps-installer/deps-installer.js +73 -59
  13. package/dist/i3s-converter/helpers/attribute-metadata-info.js +207 -153
  14. package/dist/i3s-converter/helpers/batch-ids-extensions.d.ts +1 -1
  15. package/dist/i3s-converter/helpers/batch-ids-extensions.d.ts.map +1 -1
  16. package/dist/i3s-converter/helpers/batch-ids-extensions.js +145 -103
  17. package/dist/i3s-converter/helpers/coordinate-converter.js +100 -65
  18. package/dist/i3s-converter/helpers/create-scene-server-path.js +14 -9
  19. package/dist/i3s-converter/helpers/feature-attributes.js +168 -105
  20. package/dist/i3s-converter/helpers/geometry-attributes.d.ts +1 -1
  21. package/dist/i3s-converter/helpers/geometry-attributes.d.ts.map +1 -1
  22. package/dist/i3s-converter/helpers/geometry-attributes.js +204 -212
  23. package/dist/i3s-converter/helpers/geometry-converter.d.ts +2 -2
  24. package/dist/i3s-converter/helpers/geometry-converter.d.ts.map +1 -1
  25. package/dist/i3s-converter/helpers/geometry-converter.js +1148 -829
  26. package/dist/i3s-converter/helpers/gltf-attributes.d.ts +1 -1
  27. package/dist/i3s-converter/helpers/gltf-attributes.d.ts.map +1 -1
  28. package/dist/i3s-converter/helpers/gltf-attributes.js +111 -97
  29. package/dist/i3s-converter/helpers/load-3d-tiles.js +103 -66
  30. package/dist/i3s-converter/helpers/node-debug.js +98 -54
  31. package/dist/i3s-converter/helpers/node-index-document.d.ts +3 -3
  32. package/dist/i3s-converter/helpers/node-index-document.d.ts.map +1 -1
  33. package/dist/i3s-converter/helpers/node-index-document.js +248 -177
  34. package/dist/i3s-converter/helpers/node-pages.d.ts +1 -1
  35. package/dist/i3s-converter/helpers/node-pages.d.ts.map +1 -1
  36. package/dist/i3s-converter/helpers/node-pages.js +299 -194
  37. package/dist/i3s-converter/helpers/preprocess-3d-tiles.d.ts +1 -1
  38. package/dist/i3s-converter/helpers/preprocess-3d-tiles.d.ts.map +1 -1
  39. package/dist/i3s-converter/helpers/preprocess-3d-tiles.js +92 -60
  40. package/dist/i3s-converter/helpers/progress.js +134 -83
  41. package/dist/i3s-converter/helpers/tileset-traversal.d.ts +1 -1
  42. package/dist/i3s-converter/helpers/tileset-traversal.d.ts.map +1 -1
  43. package/dist/i3s-converter/helpers/tileset-traversal.js +24 -13
  44. package/dist/i3s-converter/i3s-converter.d.ts +7 -7
  45. package/dist/i3s-converter/i3s-converter.d.ts.map +1 -1
  46. package/dist/i3s-converter/i3s-converter.js +1044 -898
  47. package/dist/i3s-converter/json-templates/geometry-definitions.js +70 -79
  48. package/dist/i3s-converter/json-templates/layers.js +120 -121
  49. package/dist/i3s-converter/json-templates/metadata.js +19 -20
  50. package/dist/i3s-converter/json-templates/node.js +73 -71
  51. package/dist/i3s-converter/json-templates/scene-server.js +25 -26
  52. package/dist/i3s-converter/json-templates/shared-resources.js +107 -108
  53. package/dist/i3s-converter/json-templates/store.js +96 -94
  54. package/dist/i3s-converter/types.js +35 -23
  55. package/dist/i3s-server/app.js +15 -12
  56. package/dist/i3s-server/bin/www.js +14 -7
  57. package/dist/i3s-server/controllers/index-controller.js +18 -15
  58. package/dist/i3s-server/controllers/slpk-controller.js +22 -11
  59. package/dist/i3s-server/routes/index.js +9 -8
  60. package/dist/i3s-server/routes/slpk-router.js +18 -17
  61. package/dist/i3s-server/utils/create-scene-server.js +15 -10
  62. package/dist/i3s-server/utils/server-utils.js +49 -32
  63. package/dist/index.cjs +292 -851
  64. package/dist/index.cjs.map +7 -0
  65. package/dist/index.d.ts +2 -2
  66. package/dist/index.d.ts.map +1 -1
  67. package/dist/index.js +0 -1
  68. package/dist/lib/json-schemas/conversion-dump-json-schema.js +243 -421
  69. package/dist/lib/utils/cli-utils.js +63 -36
  70. package/dist/lib/utils/compress-util.js +20 -15
  71. package/dist/lib/utils/conversion-dump.d.ts +1 -1
  72. package/dist/lib/utils/conversion-dump.d.ts.map +1 -1
  73. package/dist/lib/utils/conversion-dump.js +209 -187
  74. package/dist/lib/utils/file-utils.js +122 -74
  75. package/dist/lib/utils/geometry-utils.js +13 -7
  76. package/dist/lib/utils/lod-conversion-utils.js +65 -33
  77. package/dist/lib/utils/queue.js +12 -13
  78. package/dist/lib/utils/statistic-utills.d.ts +6 -23
  79. package/dist/lib/utils/statistic-utills.js +64 -59
  80. package/dist/lib/utils/write-queue.d.ts +2 -2
  81. package/dist/lib/utils/write-queue.d.ts.map +1 -1
  82. package/dist/lib/utils/write-queue.js +68 -86
  83. package/dist/pgm-loader.js +17 -13
  84. package/dist/slpk-extractor/slpk-extractor.js +59 -50
  85. package/dist/slpk-extractor-cli.js +82 -59
  86. package/package.json +18 -18
  87. package/dist/3d-tiles-converter/3d-tiles-converter.js.map +0 -1
  88. package/dist/3d-tiles-converter/helpers/b3dm-converter.js.map +0 -1
  89. package/dist/3d-tiles-converter/helpers/i3s-obb-to-3d-tiles-obb.js.map +0 -1
  90. package/dist/3d-tiles-converter/helpers/load-i3s.js.map +0 -1
  91. package/dist/3d-tiles-converter/helpers/texture-atlas.js.map +0 -1
  92. package/dist/3d-tiles-converter/json-templates/tileset.js.map +0 -1
  93. package/dist/constants.js.map +0 -1
  94. package/dist/converter-cli.js.map +0 -1
  95. package/dist/deps-installer/deps-installer.js.map +0 -1
  96. package/dist/i3s-converter/helpers/attribute-metadata-info.js.map +0 -1
  97. package/dist/i3s-converter/helpers/batch-ids-extensions.js.map +0 -1
  98. package/dist/i3s-converter/helpers/coordinate-converter.js.map +0 -1
  99. package/dist/i3s-converter/helpers/create-scene-server-path.js.map +0 -1
  100. package/dist/i3s-converter/helpers/feature-attributes.js.map +0 -1
  101. package/dist/i3s-converter/helpers/geometry-attributes.js.map +0 -1
  102. package/dist/i3s-converter/helpers/geometry-converter.js.map +0 -1
  103. package/dist/i3s-converter/helpers/gltf-attributes.js.map +0 -1
  104. package/dist/i3s-converter/helpers/load-3d-tiles.js.map +0 -1
  105. package/dist/i3s-converter/helpers/node-debug.js.map +0 -1
  106. package/dist/i3s-converter/helpers/node-index-document.js.map +0 -1
  107. package/dist/i3s-converter/helpers/node-pages.js.map +0 -1
  108. package/dist/i3s-converter/helpers/preprocess-3d-tiles.js.map +0 -1
  109. package/dist/i3s-converter/helpers/progress.js.map +0 -1
  110. package/dist/i3s-converter/helpers/tileset-traversal.js.map +0 -1
  111. package/dist/i3s-converter/i3s-converter.js.map +0 -1
  112. package/dist/i3s-converter/json-templates/geometry-definitions.js.map +0 -1
  113. package/dist/i3s-converter/json-templates/layers.js.map +0 -1
  114. package/dist/i3s-converter/json-templates/metadata.js.map +0 -1
  115. package/dist/i3s-converter/json-templates/node.js.map +0 -1
  116. package/dist/i3s-converter/json-templates/scene-server.js.map +0 -1
  117. package/dist/i3s-converter/json-templates/shared-resources.js.map +0 -1
  118. package/dist/i3s-converter/json-templates/store.js.map +0 -1
  119. package/dist/i3s-converter/types.js.map +0 -1
  120. package/dist/i3s-server/README.md +0 -63
  121. package/dist/i3s-server/app.js.map +0 -1
  122. package/dist/i3s-server/bin/www.js.map +0 -1
  123. package/dist/i3s-server/certs/cert.pem +0 -19
  124. package/dist/i3s-server/certs/key.pem +0 -27
  125. package/dist/i3s-server/controllers/index-controller.js.map +0 -1
  126. package/dist/i3s-server/controllers/slpk-controller.js.map +0 -1
  127. package/dist/i3s-server/routes/index.js.map +0 -1
  128. package/dist/i3s-server/routes/slpk-router.js.map +0 -1
  129. package/dist/i3s-server/utils/create-scene-server.js.map +0 -1
  130. package/dist/i3s-server/utils/server-utils.js.map +0 -1
  131. package/dist/index.js.map +0 -1
  132. package/dist/lib/json-schemas/conversion-dump-json-schema.js.map +0 -1
  133. package/dist/lib/utils/cli-utils.js.map +0 -1
  134. package/dist/lib/utils/compress-util.js.map +0 -1
  135. package/dist/lib/utils/conversion-dump.js.map +0 -1
  136. package/dist/lib/utils/file-utils.js.map +0 -1
  137. package/dist/lib/utils/geometry-utils.js.map +0 -1
  138. package/dist/lib/utils/lod-conversion-utils.js.map +0 -1
  139. package/dist/lib/utils/queue.js.map +0 -1
  140. package/dist/lib/utils/statistic-utills.js.map +0 -1
  141. package/dist/lib/utils/write-queue.js.map +0 -1
  142. package/dist/pgm-loader.js.map +0 -1
  143. package/dist/slpk-extractor/slpk-extractor.js.map +0 -1
  144. package/dist/slpk-extractor-cli.js.map +0 -1
@@ -1,233 +1,225 @@
1
1
  import { concatenateTypedArrays } from '@loaders.gl/loader-utils';
2
2
  const VALUES_PER_VERTEX = 3;
3
3
  const POSITIONS_AND_NORMALS_PER_TRIANGLE = 9;
4
+ /**
5
+ * Generate geometry attributes with faceRange and featureCount
6
+ * @param attributes
7
+ * @returns attirbutes with featureCount, featureIds and changed faceRange.
8
+ */
4
9
  export function generateAttributes(attributes) {
5
- const {
6
- positions,
7
- normals,
8
- texCoords,
9
- colors,
10
- uvRegions,
11
- featureIndices
12
- } = attributes;
13
- const triangleCount = positions.length / POSITIONS_AND_NORMALS_PER_TRIANGLE;
14
- if (!featureIndices.length) {
15
- return {
16
- faceRange: new Uint32Array([0, triangleCount - 1]),
17
- featureIds: [0],
18
- featureCount: 1,
19
- positions,
20
- normals,
21
- texCoords,
22
- colors,
23
- uvRegions
24
- };
25
- }
26
- const data = calculateFaceRangesAndFeaturesCount(featureIndices);
27
- const attributeObjects = makeAttributeObjects({
28
- ...data,
29
- ...attributes
30
- });
31
- const unifiedAttributeObjectsByFeatureIds = unifyObjectsByFeatureId(attributeObjects);
32
- const groupedAttributes = groupAttributesAndRangesByFeatureId(unifiedAttributeObjectsByFeatureIds, data.featureCount);
33
- return groupedAttributes;
10
+ const { positions, normals, texCoords, colors, uvRegions, featureIndices } = attributes;
11
+ const triangleCount = positions.length / POSITIONS_AND_NORMALS_PER_TRIANGLE;
12
+ if (!featureIndices.length) {
13
+ return {
14
+ faceRange: new Uint32Array([0, triangleCount - 1]),
15
+ featureIds: [0],
16
+ featureCount: 1,
17
+ positions,
18
+ normals,
19
+ texCoords,
20
+ colors,
21
+ uvRegions
22
+ };
23
+ }
24
+ const data = calculateFaceRangesAndFeaturesCount(featureIndices);
25
+ const attributeObjects = makeAttributeObjects({ ...data, ...attributes });
26
+ const unifiedAttributeObjectsByFeatureIds = unifyObjectsByFeatureId(attributeObjects);
27
+ const groupedAttributes = groupAttributesAndRangesByFeatureId(unifiedAttributeObjectsByFeatureIds, data.featureCount);
28
+ return groupedAttributes;
34
29
  }
30
+ /**
31
+ * Calculates face Ranges and feature count based on featureIndices.
32
+ * @param featureIndices
33
+ * @returns Object with featureCount, reordered attributes and changed faceRange.
34
+ */
35
35
  function calculateFaceRangesAndFeaturesCount(featureIndices) {
36
- let rangeIndex = 1;
37
- let featureIndex = 1;
38
- let currentFeatureId = getFrequentValue(featureIndices.slice(0, VALUES_PER_VERTEX));
39
- const faceRangeList = [];
40
- const featureIds = [];
41
- const uniqueFeatureIds = [currentFeatureId];
42
- faceRangeList[0] = 0;
43
- featureIds[0] = currentFeatureId;
44
- for (let index = VALUES_PER_VERTEX; index < featureIndices.length; index += VALUES_PER_VERTEX) {
45
- const newFeatureId = getFrequentValue(featureIndices.slice(index, index + VALUES_PER_VERTEX));
46
- if (currentFeatureId !== newFeatureId) {
47
- faceRangeList[rangeIndex] = index / VALUES_PER_VERTEX - 1;
48
- faceRangeList[rangeIndex + 1] = index / VALUES_PER_VERTEX;
49
- featureIds[featureIndex] = newFeatureId;
50
- if (!uniqueFeatureIds.includes(newFeatureId)) {
51
- uniqueFeatureIds.push(newFeatureId);
52
- }
53
- rangeIndex += 2;
54
- featureIndex += 1;
36
+ let rangeIndex = 1;
37
+ let featureIndex = 1;
38
+ let currentFeatureId = getFrequentValue(featureIndices.slice(0, VALUES_PER_VERTEX));
39
+ const faceRangeList = [];
40
+ const featureIds = [];
41
+ const uniqueFeatureIds = [currentFeatureId];
42
+ faceRangeList[0] = 0;
43
+ featureIds[0] = currentFeatureId;
44
+ for (let index = VALUES_PER_VERTEX; index < featureIndices.length; index += VALUES_PER_VERTEX) {
45
+ const newFeatureId = getFrequentValue(featureIndices.slice(index, index + VALUES_PER_VERTEX));
46
+ if (currentFeatureId !== newFeatureId) {
47
+ faceRangeList[rangeIndex] = index / VALUES_PER_VERTEX - 1;
48
+ faceRangeList[rangeIndex + 1] = index / VALUES_PER_VERTEX;
49
+ featureIds[featureIndex] = newFeatureId;
50
+ if (!uniqueFeatureIds.includes(newFeatureId)) {
51
+ uniqueFeatureIds.push(newFeatureId);
52
+ }
53
+ rangeIndex += 2;
54
+ featureIndex += 1;
55
+ }
56
+ currentFeatureId = newFeatureId;
55
57
  }
56
- currentFeatureId = newFeatureId;
57
- }
58
- faceRangeList[rangeIndex] = featureIndices.length / VALUES_PER_VERTEX - 1;
59
- const faceRange = new Uint32Array(faceRangeList);
60
- const featureCount = uniqueFeatureIds.length;
61
- return {
62
- faceRange,
63
- featureCount,
64
- featureIds
65
- };
58
+ faceRangeList[rangeIndex] = featureIndices.length / VALUES_PER_VERTEX - 1;
59
+ const faceRange = new Uint32Array(faceRangeList);
60
+ const featureCount = uniqueFeatureIds.length;
61
+ return { faceRange, featureCount, featureIds };
66
62
  }
63
+ /**
64
+ * Find most frequent value to avoid situation where one vertex can be part of multiple features (objects).
65
+ * @param values
66
+ */
67
67
  function getFrequentValue(values) {
68
- const map = {};
69
- let mostFrequentValue = values[0];
70
- let maxCount = 1;
71
- for (const value of values) {
72
- map[value] = (map[value] || 0) + 1;
73
- maxCount = maxCount > map[value] ? maxCount : map[value];
74
- mostFrequentValue = maxCount > map[value] ? mostFrequentValue : value;
75
- }
76
- return mostFrequentValue;
68
+ const map = {};
69
+ let mostFrequentValue = values[0];
70
+ let maxCount = 1;
71
+ for (const value of values) {
72
+ // Save item and it's frequency count to the map.
73
+ map[value] = (map[value] || 0) + 1;
74
+ // Find max count of frequency.
75
+ maxCount = maxCount > map[value] ? maxCount : map[value];
76
+ // Find the most frequent value.
77
+ mostFrequentValue = maxCount > map[value] ? mostFrequentValue : value;
78
+ }
79
+ return mostFrequentValue;
77
80
  }
81
+ /**
82
+ * Generate list of attribute object grouped by feature ids.
83
+ * @param attributes
84
+ * @returns sorted list of attribute objects.
85
+ */
78
86
  function makeAttributeObjects(attributes) {
79
- const {
80
- featureIds,
81
- positions,
82
- normals,
83
- colors,
84
- uvRegions,
85
- texCoords,
86
- faceRange = new Uint32Array(0)
87
- } = attributes;
88
- const groupedData = [];
89
- let positionsList = new Float32Array(positions);
90
- let normalsList = new Float32Array(normals);
91
- let colorsList = new Uint8Array(colors);
92
- let texCoordsList = new Float32Array(texCoords);
93
- let uvRegionsList = new Uint16Array(uvRegions);
94
- let positionsOffset = 0;
95
- let normalsOffset = 0;
96
- let colorsOffset = 0;
97
- let uvRegionsOffset = 0;
98
- let texCoordsOffset = 0;
99
- for (let index = 0; index < featureIds.length; index++) {
100
- const startIndex = faceRange[index * 2];
101
- const endIndex = faceRange[index * 2 + 1];
102
- const positionsCount = getSliceAttributeCount('positions', startIndex, endIndex);
103
- const normalsCount = getSliceAttributeCount('normals', startIndex, endIndex);
104
- const colorsCount = getSliceAttributeCount('colors', startIndex, endIndex);
105
- const uvRegionsCount = getSliceAttributeCount('uvRegions', startIndex, endIndex);
106
- const texCoordsCount = getSliceAttributeCount('texCoords', startIndex, endIndex);
107
- groupedData.push({
108
- featureId: featureIds[index],
109
- positions: positionsList.subarray(positionsOffset, positionsOffset + positionsCount),
110
- normals: normalsList.subarray(normalsOffset, normalsOffset + normalsCount),
111
- colors: colorsList.subarray(colorsOffset, colorsOffset + colorsCount),
112
- uvRegions: uvRegionsList.subarray(uvRegionsOffset, uvRegionsOffset + uvRegionsCount),
113
- texCoords: texCoordsList.subarray(texCoordsOffset, texCoordsOffset + texCoordsCount)
114
- });
115
- positionsOffset += positionsCount;
116
- normalsOffset += normalsCount;
117
- colorsOffset += colorsCount;
118
- uvRegionsOffset += uvRegionsCount;
119
- texCoordsOffset += texCoordsCount;
120
- }
121
- return groupedData;
87
+ const { featureIds, positions, normals, colors, uvRegions, texCoords, faceRange = new Uint32Array(0) } = attributes;
88
+ const groupedData = [];
89
+ let positionsList = new Float32Array(positions);
90
+ let normalsList = new Float32Array(normals);
91
+ let colorsList = new Uint8Array(colors);
92
+ let texCoordsList = new Float32Array(texCoords);
93
+ let uvRegionsList = new Uint16Array(uvRegions);
94
+ let positionsOffset = 0;
95
+ let normalsOffset = 0;
96
+ let colorsOffset = 0;
97
+ let uvRegionsOffset = 0;
98
+ let texCoordsOffset = 0;
99
+ for (let index = 0; index < featureIds.length; index++) {
100
+ const startIndex = faceRange[index * 2];
101
+ const endIndex = faceRange[index * 2 + 1];
102
+ const positionsCount = getSliceAttributeCount('positions', startIndex, endIndex);
103
+ const normalsCount = getSliceAttributeCount('normals', startIndex, endIndex);
104
+ const colorsCount = getSliceAttributeCount('colors', startIndex, endIndex);
105
+ const uvRegionsCount = getSliceAttributeCount('uvRegions', startIndex, endIndex);
106
+ const texCoordsCount = getSliceAttributeCount('texCoords', startIndex, endIndex);
107
+ groupedData.push({
108
+ featureId: featureIds[index],
109
+ positions: positionsList.subarray(positionsOffset, positionsOffset + positionsCount),
110
+ normals: normalsList.subarray(normalsOffset, normalsOffset + normalsCount),
111
+ colors: colorsList.subarray(colorsOffset, colorsOffset + colorsCount),
112
+ uvRegions: uvRegionsList.subarray(uvRegionsOffset, uvRegionsOffset + uvRegionsCount),
113
+ texCoords: texCoordsList.subarray(texCoordsOffset, texCoordsOffset + texCoordsCount)
114
+ });
115
+ positionsOffset += positionsCount;
116
+ normalsOffset += normalsCount;
117
+ colorsOffset += colorsCount;
118
+ uvRegionsOffset += uvRegionsCount;
119
+ texCoordsOffset += texCoordsCount;
120
+ }
121
+ return groupedData;
122
122
  }
123
+ /**
124
+ * Generate sliced count for generating attribute objects depends on attribute name and range.
125
+ * @param attributeName
126
+ * @param startIndex
127
+ * @param endIndex
128
+ * @returns sliced count
129
+ */
123
130
  function getSliceAttributeCount(attributeName, startIndex, endIndex) {
124
- const itemsPerVertex4 = 4;
125
- const texCoordsPerVertex = 2;
126
- const trianglesCount = endIndex - startIndex + 1;
127
- const vertexCount = trianglesCount * 3;
128
- switch (attributeName) {
129
- case 'positions':
130
- case 'normals':
131
- return trianglesCount * POSITIONS_AND_NORMALS_PER_TRIANGLE;
132
- case 'colors':
133
- case 'uvRegions':
134
- return vertexCount * itemsPerVertex4;
135
- case 'texCoords':
136
- return vertexCount * texCoordsPerVertex;
137
- default:
138
- return 0;
139
- }
131
+ const itemsPerVertex4 = 4;
132
+ const texCoordsPerVertex = 2;
133
+ const trianglesCount = endIndex - startIndex + 1;
134
+ const vertexCount = trianglesCount * 3;
135
+ switch (attributeName) {
136
+ case 'positions':
137
+ case 'normals':
138
+ return trianglesCount * POSITIONS_AND_NORMALS_PER_TRIANGLE;
139
+ case 'colors':
140
+ case 'uvRegions':
141
+ return vertexCount * itemsPerVertex4;
142
+ case 'texCoords':
143
+ return vertexCount * texCoordsPerVertex;
144
+ default:
145
+ return 0;
146
+ }
140
147
  }
148
+ /**
149
+ * Generates unique object list depends on feature ids and concantenate their attributes.
150
+ * @param sortedData
151
+ * @returns unique list of objects
152
+ */
141
153
  function unifyObjectsByFeatureId(sortedData) {
142
- const groupedMetadata = [];
143
- for (const data of sortedData) {
144
- const existingObject = groupedMetadata.find(obj => obj.featureId === data.featureId);
145
- if (existingObject) {
146
- existingObject.attributes.push(data);
147
- } else {
148
- groupedMetadata.push({
149
- featureId: data.featureId,
150
- attributes: [data]
151
- });
154
+ const groupedMetadata = [];
155
+ for (const data of sortedData) {
156
+ const existingObject = groupedMetadata.find((obj) => obj.featureId === data.featureId);
157
+ if (existingObject) {
158
+ existingObject.attributes.push(data);
159
+ }
160
+ else {
161
+ groupedMetadata.push({
162
+ featureId: data.featureId,
163
+ attributes: [data]
164
+ });
165
+ }
166
+ }
167
+ const uniqueObjects = [];
168
+ for (const metatada of groupedMetadata) {
169
+ const attributes = concatenateAttributes(metatada.attributes);
170
+ uniqueObjects.push({
171
+ featureId: metatada.featureId,
172
+ ...attributes
173
+ });
152
174
  }
153
- }
154
- const uniqueObjects = [];
155
- for (const metatada of groupedMetadata) {
156
- const attributes = concatenateAttributes(metatada.attributes);
157
- uniqueObjects.push({
158
- featureId: metatada.featureId,
159
- ...attributes
160
- });
161
- }
162
- return uniqueObjects;
175
+ return uniqueObjects;
163
176
  }
177
+ /**
178
+ * Generates attribute objects with new faceRange and reordered attributes.
179
+ * @param unifiedObjects
180
+ * @returns generated attributes with new faceRange.
181
+ */
164
182
  function groupAttributesAndRangesByFeatureId(unifiedObjects, featureCount) {
165
- const firstAttributeObject = unifiedObjects[0];
166
- const featureIds = [firstAttributeObject.featureId || 0];
167
- const range = [0];
168
- let objIndex = 0;
169
- let sum = 0;
170
- for (let index = 1; index < unifiedObjects.length; index++) {
171
- const currentAttributesObject = unifiedObjects[index];
172
- featureIds.push(currentAttributesObject.featureId || 0);
173
- const groupedObject = unifiedObjects[objIndex];
174
- range.push(groupedObject.positions.length / POSITIONS_AND_NORMALS_PER_TRIANGLE - 1 + sum);
175
- range.push(groupedObject.positions.length / POSITIONS_AND_NORMALS_PER_TRIANGLE + sum);
176
- sum += groupedObject.positions.length / POSITIONS_AND_NORMALS_PER_TRIANGLE;
177
- objIndex += 1;
178
- }
179
- const attributes = concatenateAttributes(unifiedObjects);
180
- range.push(attributes.positions.length / POSITIONS_AND_NORMALS_PER_TRIANGLE - 1);
181
- const faceRange = new Uint32Array(range);
182
- return {
183
- faceRange,
184
- featureIds,
185
- featureCount,
186
- ...attributes
187
- };
183
+ const firstAttributeObject = unifiedObjects[0];
184
+ const featureIds = [firstAttributeObject.featureId || 0];
185
+ const range = [0];
186
+ let objIndex = 0;
187
+ let sum = 0;
188
+ for (let index = 1; index < unifiedObjects.length; index++) {
189
+ const currentAttributesObject = unifiedObjects[index];
190
+ featureIds.push(currentAttributesObject.featureId || 0);
191
+ const groupedObject = unifiedObjects[objIndex];
192
+ range.push(groupedObject.positions.length / POSITIONS_AND_NORMALS_PER_TRIANGLE - 1 + sum);
193
+ range.push(groupedObject.positions.length / POSITIONS_AND_NORMALS_PER_TRIANGLE + sum);
194
+ sum += groupedObject.positions.length / POSITIONS_AND_NORMALS_PER_TRIANGLE;
195
+ objIndex += 1;
196
+ }
197
+ const attributes = concatenateAttributes(unifiedObjects);
198
+ range.push(attributes.positions.length / POSITIONS_AND_NORMALS_PER_TRIANGLE - 1);
199
+ const faceRange = new Uint32Array(range);
200
+ return { faceRange, featureIds, featureCount, ...attributes };
188
201
  }
202
+ /**
203
+ * Concatenate attributes typed arrays
204
+ * @param attributes - grouped by featureId typed arrays
205
+ * @returns - concatenated typed array list
206
+ */
189
207
  function concatenateAttributes(attributes) {
190
- const positionGroups = attributes.map(_ref => {
191
- let {
192
- positions
193
- } = _ref;
194
- return positions;
195
- });
196
- const positions = positionGroups.length > 1 ? concatenateTypedArrays(...positionGroups) : positionGroups[0];
197
- const normalGroups = attributes.map(_ref2 => {
198
- let {
199
- normals
200
- } = _ref2;
201
- return normals;
202
- });
203
- const normals = normalGroups.length > 1 ? concatenateTypedArrays(...normalGroups) : normalGroups[0];
204
- const colorGroups = attributes.map(_ref3 => {
205
- let {
206
- colors
207
- } = _ref3;
208
- return colors;
209
- });
210
- const colors = colorGroups.length > 1 ? concatenateTypedArrays(...colorGroups) : colorGroups[0];
211
- const texCoordGroups = attributes.map(_ref4 => {
212
- let {
213
- texCoords
214
- } = _ref4;
215
- return texCoords;
216
- });
217
- const texCoords = texCoordGroups.length > 1 ? concatenateTypedArrays(...texCoordGroups) : texCoordGroups[0];
218
- const uvRegionGroups = attributes.map(_ref5 => {
219
- let {
220
- uvRegions
221
- } = _ref5;
222
- return uvRegions;
223
- });
224
- const uvRegions = uvRegionGroups.length > 1 ? concatenateTypedArrays(...uvRegionGroups) : uvRegionGroups[0];
225
- return {
226
- positions,
227
- normals,
228
- colors,
229
- texCoords,
230
- uvRegions
231
- };
208
+ const positionGroups = attributes.map(({ positions }) => positions);
209
+ const positions = positionGroups.length > 1 ? concatenateTypedArrays(...positionGroups) : positionGroups[0];
210
+ const normalGroups = attributes.map(({ normals }) => normals);
211
+ const normals = normalGroups.length > 1 ? concatenateTypedArrays(...normalGroups) : normalGroups[0];
212
+ const colorGroups = attributes.map(({ colors }) => colors);
213
+ const colors = colorGroups.length > 1 ? concatenateTypedArrays(...colorGroups) : colorGroups[0];
214
+ const texCoordGroups = attributes.map(({ texCoords }) => texCoords);
215
+ const texCoords = texCoordGroups.length > 1 ? concatenateTypedArrays(...texCoordGroups) : texCoordGroups[0];
216
+ const uvRegionGroups = attributes.map(({ uvRegions }) => uvRegions);
217
+ const uvRegions = uvRegionGroups.length > 1 ? concatenateTypedArrays(...uvRegionGroups) : uvRegionGroups[0];
218
+ return {
219
+ positions,
220
+ normals,
221
+ colors,
222
+ texCoords,
223
+ uvRegions
224
+ };
232
225
  }
233
- //# sourceMappingURL=geometry-attributes.js.map
@@ -1,9 +1,9 @@
1
1
  import type { FeatureTableJson, Tiles3DTileContent } from '@loaders.gl/3d-tiles';
2
2
  import { Matrix4 } from '@math.gl/core';
3
- import { ConvertedAttributes, I3SConvertedResources, I3SMaterialWithTexture } from '../types';
3
+ import { ConvertedAttributes, I3SConvertedResources, I3SMaterialWithTexture } from "../types.js";
4
4
  import { AttributeStorageInfo } from '@loaders.gl/i3s';
5
5
  import { Geoid } from '@math.gl/geoid';
6
- import type { GLTFAttributesData } from '../types';
6
+ import type { GLTFAttributesData } from "../types.js";
7
7
  import { BoundingSphere, OrientedBoundingBox } from '@math.gl/culling';
8
8
  /**
9
9
  * Convert binary data from b3dm file to i3s resources
@@ -1 +1 @@
1
- {"version":3,"file":"geometry-converter.d.ts","sourceRoot":"","sources":["../../../src/i3s-converter/helpers/geometry-converter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,gBAAgB,EAAE,kBAAkB,EAAC,MAAM,sBAAsB,CAAC;AAgB/E,OAAO,EAAU,OAAO,EAAU,MAAM,eAAe,CAAC;AAUxD,OAAO,EACL,mBAAmB,EACnB,qBAAqB,EACrB,sBAAsB,EAGvB,MAAM,UAAU,CAAC;AAClB,OAAO,EACL,oBAAoB,EAIrB,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EAAC,KAAK,EAAC,MAAM,gBAAgB,CAAC;AAWrC,OAAO,KAAK,EAAC,kBAAkB,EAAgD,MAAM,UAAU,CAAC;AAEhG,OAAO,EAAC,cAAc,EAAE,mBAAmB,EAAC,MAAM,kBAAkB,CAAC;AAyBrE;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAA8B,wBAAwB,CACpD,WAAW,EAAE,kBAAkB,EAC/B,aAAa,EAAE,OAAO,EACtB,kBAAkB,EAAE,mBAAmB,GAAG,cAAc,EACxD,iBAAiB,EAAE,MAAM,OAAO,CAAC,MAAM,CAAC,EACxC,aAAa,EAAE,gBAAgB,GAAG,IAAI,EACtC,iBAAiB,EAAE,MAAM,EAAE,EAC3B,oBAAoB,EAAE,oBAAoB,EAAE,GAAG,SAAS,EACxD,KAAK,EAAE,OAAO,EACd,uBAAuB,EAAE,OAAO,EAChC,oBAAoB,EAAE,OAAO,EAC7B,gBAAgB,EAAE,KAAK,EACvB,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EACjC,aAAa,CAAC,EAAE,MAAM,GACrB,OAAO,CAAC,qBAAqB,EAAE,GAAG,IAAI,CAAC,CAgEzC;AAoJD;;;;;;;;GAQG;AACH,wBAAsB,iBAAiB,CACrC,cAAc,EAAE,kBAAkB,EAClC,sBAAsB,EAAE,sBAAsB,EAAE,EAChD,qBAAqB,EAAE,OAAO,EAC9B,cAAc,EAAE,MAAM,GAAG,IAAI,GAC5B,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,mBAAmB,CAAC,CAAC,CAkD3C;AAwsCD;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAC9B,WAAW,EAAE,kBAAkB,GAAG,IAAI,EACtC,aAAa,CAAC,EAAE,MAAM,GACrB,gBAAgB,GAAG,IAAI,CA+BzB"}
1
+ {"version":3,"file":"geometry-converter.d.ts","sourceRoot":"","sources":["../../../src/i3s-converter/helpers/geometry-converter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,gBAAgB,EAAE,kBAAkB,EAAC,MAAM,sBAAsB,CAAC;AAgB/E,OAAO,EAAU,OAAO,EAAU,MAAM,eAAe,CAAC;AAUxD,OAAO,EACL,mBAAmB,EACnB,qBAAqB,EACrB,sBAAsB,EAGvB,oBAAiB;AAClB,OAAO,EACL,oBAAoB,EAIrB,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EAAC,KAAK,EAAC,MAAM,gBAAgB,CAAC;AAWrC,OAAO,KAAK,EAAC,kBAAkB,EAAgD,oBAAiB;AAEhG,OAAO,EAAC,cAAc,EAAE,mBAAmB,EAAC,MAAM,kBAAkB,CAAC;AAyBrE;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAA8B,wBAAwB,CACpD,WAAW,EAAE,kBAAkB,EAC/B,aAAa,EAAE,OAAO,EACtB,kBAAkB,EAAE,mBAAmB,GAAG,cAAc,EACxD,iBAAiB,EAAE,MAAM,OAAO,CAAC,MAAM,CAAC,EACxC,aAAa,EAAE,gBAAgB,GAAG,IAAI,EACtC,iBAAiB,EAAE,MAAM,EAAE,EAC3B,oBAAoB,EAAE,oBAAoB,EAAE,GAAG,SAAS,EACxD,KAAK,EAAE,OAAO,EACd,uBAAuB,EAAE,OAAO,EAChC,oBAAoB,EAAE,OAAO,EAC7B,gBAAgB,EAAE,KAAK,EACvB,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EACjC,aAAa,CAAC,EAAE,MAAM,GACrB,OAAO,CAAC,qBAAqB,EAAE,GAAG,IAAI,CAAC,CAgEzC;AAoJD;;;;;;;;GAQG;AACH,wBAAsB,iBAAiB,CACrC,cAAc,EAAE,kBAAkB,EAClC,sBAAsB,EAAE,sBAAsB,EAAE,EAChD,qBAAqB,EAAE,OAAO,EAC9B,cAAc,EAAE,MAAM,GAAG,IAAI,GAC5B,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,mBAAmB,CAAC,CAAC,CAkD3C;AAwsCD;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAC9B,WAAW,EAAE,kBAAkB,GAAG,IAAI,EACtC,aAAa,CAAC,EAAE,MAAM,GACrB,gBAAgB,GAAG,IAAI,CA+BzB"}