@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.
- package/dist/3d-tiles-converter/3d-tiles-converter.d.ts +3 -3
- package/dist/3d-tiles-converter/3d-tiles-converter.d.ts.map +1 -1
- package/dist/3d-tiles-converter/3d-tiles-converter.js +329 -293
- package/dist/3d-tiles-converter/helpers/b3dm-converter.js +257 -200
- package/dist/3d-tiles-converter/helpers/i3s-obb-to-3d-tiles-obb.js +14 -5
- package/dist/3d-tiles-converter/helpers/load-i3s.js +106 -75
- package/dist/3d-tiles-converter/helpers/texture-atlas.js +44 -21
- package/dist/3d-tiles-converter/json-templates/tileset.js +32 -33
- package/dist/constants.js +0 -1
- package/dist/converter-cli.js +255 -234
- package/dist/converter.min.cjs +80 -90
- package/dist/deps-installer/deps-installer.js +73 -59
- package/dist/i3s-converter/helpers/attribute-metadata-info.js +207 -153
- package/dist/i3s-converter/helpers/batch-ids-extensions.d.ts +1 -1
- package/dist/i3s-converter/helpers/batch-ids-extensions.d.ts.map +1 -1
- package/dist/i3s-converter/helpers/batch-ids-extensions.js +145 -103
- package/dist/i3s-converter/helpers/coordinate-converter.js +100 -65
- package/dist/i3s-converter/helpers/create-scene-server-path.js +14 -9
- package/dist/i3s-converter/helpers/feature-attributes.js +168 -105
- package/dist/i3s-converter/helpers/geometry-attributes.d.ts +1 -1
- package/dist/i3s-converter/helpers/geometry-attributes.d.ts.map +1 -1
- package/dist/i3s-converter/helpers/geometry-attributes.js +204 -212
- package/dist/i3s-converter/helpers/geometry-converter.d.ts +2 -2
- package/dist/i3s-converter/helpers/geometry-converter.d.ts.map +1 -1
- package/dist/i3s-converter/helpers/geometry-converter.js +1148 -829
- package/dist/i3s-converter/helpers/gltf-attributes.d.ts +1 -1
- package/dist/i3s-converter/helpers/gltf-attributes.d.ts.map +1 -1
- package/dist/i3s-converter/helpers/gltf-attributes.js +111 -97
- package/dist/i3s-converter/helpers/load-3d-tiles.js +103 -66
- package/dist/i3s-converter/helpers/node-debug.js +98 -54
- package/dist/i3s-converter/helpers/node-index-document.d.ts +3 -3
- package/dist/i3s-converter/helpers/node-index-document.d.ts.map +1 -1
- package/dist/i3s-converter/helpers/node-index-document.js +248 -177
- package/dist/i3s-converter/helpers/node-pages.d.ts +1 -1
- package/dist/i3s-converter/helpers/node-pages.d.ts.map +1 -1
- package/dist/i3s-converter/helpers/node-pages.js +299 -194
- package/dist/i3s-converter/helpers/preprocess-3d-tiles.d.ts +1 -1
- package/dist/i3s-converter/helpers/preprocess-3d-tiles.d.ts.map +1 -1
- package/dist/i3s-converter/helpers/preprocess-3d-tiles.js +92 -60
- package/dist/i3s-converter/helpers/progress.js +134 -83
- package/dist/i3s-converter/helpers/tileset-traversal.d.ts +1 -1
- package/dist/i3s-converter/helpers/tileset-traversal.d.ts.map +1 -1
- package/dist/i3s-converter/helpers/tileset-traversal.js +24 -13
- package/dist/i3s-converter/i3s-converter.d.ts +7 -7
- package/dist/i3s-converter/i3s-converter.d.ts.map +1 -1
- package/dist/i3s-converter/i3s-converter.js +1044 -898
- package/dist/i3s-converter/json-templates/geometry-definitions.js +70 -79
- package/dist/i3s-converter/json-templates/layers.js +120 -121
- package/dist/i3s-converter/json-templates/metadata.js +19 -20
- package/dist/i3s-converter/json-templates/node.js +73 -71
- package/dist/i3s-converter/json-templates/scene-server.js +25 -26
- package/dist/i3s-converter/json-templates/shared-resources.js +107 -108
- package/dist/i3s-converter/json-templates/store.js +96 -94
- package/dist/i3s-converter/types.js +35 -23
- package/dist/i3s-server/app.js +15 -12
- package/dist/i3s-server/bin/www.js +14 -7
- package/dist/i3s-server/controllers/index-controller.js +18 -15
- package/dist/i3s-server/controllers/slpk-controller.js +22 -11
- package/dist/i3s-server/routes/index.js +9 -8
- package/dist/i3s-server/routes/slpk-router.js +18 -17
- package/dist/i3s-server/utils/create-scene-server.js +15 -10
- package/dist/i3s-server/utils/server-utils.js +49 -32
- package/dist/index.cjs +292 -851
- package/dist/index.cjs.map +7 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +0 -1
- package/dist/lib/json-schemas/conversion-dump-json-schema.js +243 -421
- package/dist/lib/utils/cli-utils.js +63 -36
- package/dist/lib/utils/compress-util.js +20 -15
- package/dist/lib/utils/conversion-dump.d.ts +1 -1
- package/dist/lib/utils/conversion-dump.d.ts.map +1 -1
- package/dist/lib/utils/conversion-dump.js +209 -187
- package/dist/lib/utils/file-utils.js +122 -74
- package/dist/lib/utils/geometry-utils.js +13 -7
- package/dist/lib/utils/lod-conversion-utils.js +65 -33
- package/dist/lib/utils/queue.js +12 -13
- package/dist/lib/utils/statistic-utills.d.ts +6 -23
- package/dist/lib/utils/statistic-utills.js +64 -59
- package/dist/lib/utils/write-queue.d.ts +2 -2
- package/dist/lib/utils/write-queue.d.ts.map +1 -1
- package/dist/lib/utils/write-queue.js +68 -86
- package/dist/pgm-loader.js +17 -13
- package/dist/slpk-extractor/slpk-extractor.js +59 -50
- package/dist/slpk-extractor-cli.js +82 -59
- package/package.json +18 -18
- package/dist/3d-tiles-converter/3d-tiles-converter.js.map +0 -1
- package/dist/3d-tiles-converter/helpers/b3dm-converter.js.map +0 -1
- package/dist/3d-tiles-converter/helpers/i3s-obb-to-3d-tiles-obb.js.map +0 -1
- package/dist/3d-tiles-converter/helpers/load-i3s.js.map +0 -1
- package/dist/3d-tiles-converter/helpers/texture-atlas.js.map +0 -1
- package/dist/3d-tiles-converter/json-templates/tileset.js.map +0 -1
- package/dist/constants.js.map +0 -1
- package/dist/converter-cli.js.map +0 -1
- package/dist/deps-installer/deps-installer.js.map +0 -1
- package/dist/i3s-converter/helpers/attribute-metadata-info.js.map +0 -1
- package/dist/i3s-converter/helpers/batch-ids-extensions.js.map +0 -1
- package/dist/i3s-converter/helpers/coordinate-converter.js.map +0 -1
- package/dist/i3s-converter/helpers/create-scene-server-path.js.map +0 -1
- package/dist/i3s-converter/helpers/feature-attributes.js.map +0 -1
- package/dist/i3s-converter/helpers/geometry-attributes.js.map +0 -1
- package/dist/i3s-converter/helpers/geometry-converter.js.map +0 -1
- package/dist/i3s-converter/helpers/gltf-attributes.js.map +0 -1
- package/dist/i3s-converter/helpers/load-3d-tiles.js.map +0 -1
- package/dist/i3s-converter/helpers/node-debug.js.map +0 -1
- package/dist/i3s-converter/helpers/node-index-document.js.map +0 -1
- package/dist/i3s-converter/helpers/node-pages.js.map +0 -1
- package/dist/i3s-converter/helpers/preprocess-3d-tiles.js.map +0 -1
- package/dist/i3s-converter/helpers/progress.js.map +0 -1
- package/dist/i3s-converter/helpers/tileset-traversal.js.map +0 -1
- package/dist/i3s-converter/i3s-converter.js.map +0 -1
- package/dist/i3s-converter/json-templates/geometry-definitions.js.map +0 -1
- package/dist/i3s-converter/json-templates/layers.js.map +0 -1
- package/dist/i3s-converter/json-templates/metadata.js.map +0 -1
- package/dist/i3s-converter/json-templates/node.js.map +0 -1
- package/dist/i3s-converter/json-templates/scene-server.js.map +0 -1
- package/dist/i3s-converter/json-templates/shared-resources.js.map +0 -1
- package/dist/i3s-converter/json-templates/store.js.map +0 -1
- package/dist/i3s-converter/types.js.map +0 -1
- package/dist/i3s-server/README.md +0 -63
- package/dist/i3s-server/app.js.map +0 -1
- package/dist/i3s-server/bin/www.js.map +0 -1
- package/dist/i3s-server/certs/cert.pem +0 -19
- package/dist/i3s-server/certs/key.pem +0 -27
- package/dist/i3s-server/controllers/index-controller.js.map +0 -1
- package/dist/i3s-server/controllers/slpk-controller.js.map +0 -1
- package/dist/i3s-server/routes/index.js.map +0 -1
- package/dist/i3s-server/routes/slpk-router.js.map +0 -1
- package/dist/i3s-server/utils/create-scene-server.js.map +0 -1
- package/dist/i3s-server/utils/server-utils.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/lib/json-schemas/conversion-dump-json-schema.js.map +0 -1
- package/dist/lib/utils/cli-utils.js.map +0 -1
- package/dist/lib/utils/compress-util.js.map +0 -1
- package/dist/lib/utils/conversion-dump.js.map +0 -1
- package/dist/lib/utils/file-utils.js.map +0 -1
- package/dist/lib/utils/geometry-utils.js.map +0 -1
- package/dist/lib/utils/lod-conversion-utils.js.map +0 -1
- package/dist/lib/utils/queue.js.map +0 -1
- package/dist/lib/utils/statistic-utills.js.map +0 -1
- package/dist/lib/utils/write-queue.js.map +0 -1
- package/dist/pgm-loader.js.map +0 -1
- package/dist/slpk-extractor/slpk-extractor.js.map +0 -1
- 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
|
-
|
|
6
|
-
positions
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
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
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
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
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
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
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
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
|
-
|
|
80
|
-
|
|
81
|
-
positions
|
|
82
|
-
normals
|
|
83
|
-
colors
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
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
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
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
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
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
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
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
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
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
|
|
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
|
|
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,
|
|
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"}
|