@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.
- package/dist/3d-tiles-converter/helpers/b3dm-converter.d.ts +4 -4
- package/dist/3d-tiles-converter/helpers/load-i3s.d.ts.map +1 -1
- package/dist/converter.min.js +105 -105
- package/dist/dist.min.js +725 -652
- package/dist/es5/3d-tiles-converter/helpers/b3dm-converter.js +18 -18
- package/dist/es5/3d-tiles-converter/helpers/b3dm-converter.js.map +1 -1
- package/dist/es5/3d-tiles-converter/helpers/load-i3s.js.map +1 -1
- package/dist/es5/deps-installer/deps-installer.js +1 -1
- package/dist/es5/i3s-converter/helpers/batch-ids-extensions.js +16 -14
- package/dist/es5/i3s-converter/helpers/batch-ids-extensions.js.map +1 -1
- package/dist/es5/i3s-converter/helpers/feature-attributes.js +6 -18
- package/dist/es5/i3s-converter/helpers/feature-attributes.js.map +1 -1
- package/dist/es5/i3s-converter/helpers/geometry-attributes.js +83 -44
- package/dist/es5/i3s-converter/helpers/geometry-attributes.js.map +1 -1
- package/dist/es5/i3s-converter/helpers/geometry-converter.js +13 -83
- package/dist/es5/i3s-converter/helpers/geometry-converter.js.map +1 -1
- package/dist/es5/i3s-converter/helpers/preprocess-3d-tiles.js +15 -8
- package/dist/es5/i3s-converter/helpers/preprocess-3d-tiles.js.map +1 -1
- package/dist/es5/i3s-converter/i3s-converter.js.map +1 -1
- package/dist/es5/i3s-converter/types.js.map +1 -1
- package/dist/es5/pgm-loader.js +11 -3
- package/dist/es5/pgm-loader.js.map +1 -1
- package/dist/esm/3d-tiles-converter/helpers/b3dm-converter.js +8 -8
- package/dist/esm/3d-tiles-converter/helpers/b3dm-converter.js.map +1 -1
- package/dist/esm/3d-tiles-converter/helpers/load-i3s.js.map +1 -1
- package/dist/esm/deps-installer/deps-installer.js +1 -1
- package/dist/esm/i3s-converter/helpers/batch-ids-extensions.js +5 -15
- package/dist/esm/i3s-converter/helpers/batch-ids-extensions.js.map +1 -1
- package/dist/esm/i3s-converter/helpers/feature-attributes.js +5 -5
- package/dist/esm/i3s-converter/helpers/feature-attributes.js.map +1 -1
- package/dist/esm/i3s-converter/helpers/geometry-attributes.js +76 -34
- package/dist/esm/i3s-converter/helpers/geometry-attributes.js.map +1 -1
- package/dist/esm/i3s-converter/helpers/geometry-converter.js +10 -80
- package/dist/esm/i3s-converter/helpers/geometry-converter.js.map +1 -1
- package/dist/esm/i3s-converter/helpers/preprocess-3d-tiles.js +15 -9
- package/dist/esm/i3s-converter/helpers/preprocess-3d-tiles.js.map +1 -1
- package/dist/esm/i3s-converter/i3s-converter.js.map +1 -1
- package/dist/esm/i3s-converter/types.js.map +1 -1
- package/dist/esm/i3s-server/bin/i3s-server.min.js +75 -75
- package/dist/esm/pgm-loader.js +7 -4
- package/dist/esm/pgm-loader.js.map +1 -1
- package/dist/i3s-converter/helpers/batch-ids-extensions.d.ts +4 -1
- package/dist/i3s-converter/helpers/batch-ids-extensions.d.ts.map +1 -1
- package/dist/i3s-converter/helpers/feature-attributes.d.ts +6 -6
- package/dist/i3s-converter/helpers/feature-attributes.d.ts.map +1 -1
- package/dist/i3s-converter/helpers/geometry-attributes.d.ts.map +1 -1
- package/dist/i3s-converter/helpers/geometry-converter.d.ts +1 -1
- package/dist/i3s-converter/helpers/geometry-converter.d.ts.map +1 -1
- package/dist/i3s-converter/helpers/preprocess-3d-tiles.d.ts.map +1 -1
- package/dist/i3s-converter/i3s-converter.d.ts.map +1 -1
- package/dist/i3s-converter/types.d.ts +13 -5
- package/dist/i3s-converter/types.d.ts.map +1 -1
- package/dist/pgm-loader.d.ts +9 -2
- package/dist/pgm-loader.d.ts.map +1 -1
- package/dist/slpk-extractor.min.js +42 -42
- package/package.json +14 -14
- package/src/3d-tiles-converter/helpers/b3dm-converter.ts +8 -8
- package/src/3d-tiles-converter/helpers/load-i3s.ts +1 -0
- package/src/i3s-converter/helpers/batch-ids-extensions.ts +14 -35
- package/src/i3s-converter/helpers/feature-attributes.ts +14 -11
- package/src/i3s-converter/helpers/geometry-attributes.ts +80 -50
- package/src/i3s-converter/helpers/geometry-converter.ts +41 -177
- package/src/i3s-converter/helpers/preprocess-3d-tiles.ts +30 -9
- package/src/i3s-converter/i3s-converter.ts +0 -2
- package/src/i3s-converter/types.ts +14 -5
- package/src/pgm-loader.ts +15 -7
- package/dist/3d-tiles-converter/3d-tiles-converter.js +0 -279
- package/dist/3d-tiles-converter/helpers/b3dm-converter.js +0 -271
- package/dist/3d-tiles-converter/helpers/i3s-obb-to-3d-tiles-obb.js +0 -23
- package/dist/3d-tiles-converter/helpers/load-i3s.js +0 -42
- package/dist/3d-tiles-converter/helpers/texture-atlas.js +0 -54
- package/dist/3d-tiles-converter/json-templates/tileset.js +0 -43
- package/dist/bundle.js +0 -5
- package/dist/constants.js +0 -4
- package/dist/converter-cli.js +0 -222
- package/dist/deps-installer/deps-installer.js +0 -89
- package/dist/i3s-converter/helpers/batch-ids-extensions.js +0 -179
- package/dist/i3s-converter/helpers/coordinate-converter.js +0 -122
- package/dist/i3s-converter/helpers/create-scene-server-path.js +0 -28
- package/dist/i3s-converter/helpers/feature-attributes.js +0 -218
- package/dist/i3s-converter/helpers/geometry-attributes.js +0 -203
- package/dist/i3s-converter/helpers/geometry-converter.js +0 -1321
- package/dist/i3s-converter/helpers/gltf-attributes.js +0 -129
- package/dist/i3s-converter/helpers/load-3d-tiles.js +0 -99
- package/dist/i3s-converter/helpers/node-debug.js +0 -120
- package/dist/i3s-converter/helpers/node-index-document.js +0 -271
- package/dist/i3s-converter/helpers/node-pages.js +0 -316
- package/dist/i3s-converter/helpers/preprocess-3d-tiles.js +0 -100
- package/dist/i3s-converter/helpers/tileset-traversal.js +0 -29
- package/dist/i3s-converter/i3s-converter.js +0 -964
- package/dist/i3s-converter/json-templates/geometry-definitions.js +0 -87
- package/dist/i3s-converter/json-templates/layers.js +0 -139
- package/dist/i3s-converter/json-templates/metadata.js +0 -25
- package/dist/i3s-converter/json-templates/node.js +0 -89
- package/dist/i3s-converter/json-templates/scene-server.js +0 -31
- package/dist/i3s-converter/json-templates/shared-resources.js +0 -129
- package/dist/i3s-converter/json-templates/store.js +0 -103
- package/dist/i3s-converter/types.js +0 -17
- package/dist/i3s-server/app.js +0 -29
- package/dist/i3s-server/bin/www.js +0 -37
- package/dist/i3s-server/controllers/index-controller.js +0 -31
- package/dist/i3s-server/controllers/slpk-controller.js +0 -33
- package/dist/i3s-server/routes/index.js +0 -20
- package/dist/i3s-server/routes/slpk-router.js +0 -34
- package/dist/i3s-server/utils/create-scene-server.js +0 -22
- package/dist/i3s-server/utils/server-utils.js +0 -66
- package/dist/index.js +0 -10
- package/dist/lib/utils/cli-utils.js +0 -82
- package/dist/lib/utils/compress-util.js +0 -257
- package/dist/lib/utils/file-utils.js +0 -139
- package/dist/lib/utils/geometry-utils.js +0 -18
- package/dist/lib/utils/lod-conversion-utils.js +0 -76
- package/dist/lib/utils/queue.js +0 -18
- package/dist/lib/utils/statistic-utills.js +0 -64
- package/dist/lib/utils/write-queue.js +0 -80
- package/dist/pgm-loader.js +0 -24
- package/dist/slpk-extractor/slpk-extractor.js +0 -75
- package/dist/slpk-extractor-cli.js +0 -102
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.createSceneServerPath = void 0;
|
|
7
|
-
const uuid_1 = require("uuid");
|
|
8
|
-
const json_map_transform_1 = __importDefault(require("json-map-transform"));
|
|
9
|
-
const path_1 = require("path");
|
|
10
|
-
const scene_server_1 = require("../json-templates/scene-server");
|
|
11
|
-
const file_utils_1 = require("../../lib/utils/file-utils");
|
|
12
|
-
/**
|
|
13
|
-
* Form and save sceneServer meta data into a file
|
|
14
|
-
* @param layerName - layer name to display
|
|
15
|
-
* @param layers0 - layer object embedded into sceneServer meta data
|
|
16
|
-
* @param rootPath - root path of new converted tileset
|
|
17
|
-
*/
|
|
18
|
-
async function createSceneServerPath(layerName, layers0, rootPath) {
|
|
19
|
-
const sceneServerData = {
|
|
20
|
-
serviceItemId: (0, uuid_1.v4)().replace(/-/gi, ''),
|
|
21
|
-
layerName,
|
|
22
|
-
layers0
|
|
23
|
-
};
|
|
24
|
-
const sceneServer = (0, json_map_transform_1.default)(sceneServerData, (0, scene_server_1.SCENE_SERVER)());
|
|
25
|
-
const nodePagePath = (0, path_1.join)(rootPath, 'SceneServer');
|
|
26
|
-
await (0, file_utils_1.writeFile)(nodePagePath, JSON.stringify(sceneServer));
|
|
27
|
-
}
|
|
28
|
-
exports.createSceneServerPath = createSceneServerPath;
|
|
@@ -1,218 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createPopupInfo = exports.createFieldAttribute = exports.getFieldAttributeType = exports.createdStorageAttribute = exports.getAttributeType = exports.checkPropertiesLength = exports.flattenPropertyTableByFeatureIds = void 0;
|
|
4
|
-
/**
|
|
5
|
-
* Takes attributes from property table based on featureIds.
|
|
6
|
-
* If there is no property value for particular featureId (index) the property will be null.
|
|
7
|
-
* Example:
|
|
8
|
-
* Initial data:
|
|
9
|
-
* OBJECTID: [0, 1, 5]
|
|
10
|
-
* component: ['Windows', 'Frames', 'Wall', 'Roof', 'Skylight']
|
|
11
|
-
* Result:
|
|
12
|
-
* OBJECTID: [0, 1, 5]
|
|
13
|
-
* component: ['Windows', 'Frames', 'null']
|
|
14
|
-
* @param featureIds
|
|
15
|
-
* @param propertyTable
|
|
16
|
-
*/
|
|
17
|
-
function flattenPropertyTableByFeatureIds(featureIds, propertyTable) {
|
|
18
|
-
const resultPropertyTable = {};
|
|
19
|
-
for (const propertyName in propertyTable) {
|
|
20
|
-
const properties = propertyTable[propertyName];
|
|
21
|
-
resultPropertyTable[propertyName] = getPropertiesByFeatureIds(properties, featureIds);
|
|
22
|
-
}
|
|
23
|
-
return resultPropertyTable;
|
|
24
|
-
}
|
|
25
|
-
exports.flattenPropertyTableByFeatureIds = flattenPropertyTableByFeatureIds;
|
|
26
|
-
/**
|
|
27
|
-
* Getting properties by featureId index
|
|
28
|
-
* @param properties
|
|
29
|
-
* @param featureIds
|
|
30
|
-
*/
|
|
31
|
-
function getPropertiesByFeatureIds(properties, featureIds) {
|
|
32
|
-
const resultProperties = [];
|
|
33
|
-
if (properties) {
|
|
34
|
-
for (const featureId of featureIds) {
|
|
35
|
-
const property = properties[featureId] || null;
|
|
36
|
-
resultProperties.push(property);
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
return resultProperties;
|
|
40
|
-
}
|
|
41
|
-
/**
|
|
42
|
-
* Check that all attributes in propertyTable have the same length as FeatureIds.
|
|
43
|
-
* If there are differencies between lengths we should flatten property table based on exiesting featureIds.
|
|
44
|
-
* @param featureIds
|
|
45
|
-
* @param propertyTable
|
|
46
|
-
* @returns
|
|
47
|
-
*/
|
|
48
|
-
function checkPropertiesLength(featureIds, propertyTable) {
|
|
49
|
-
let needFlatten = false;
|
|
50
|
-
for (const attribute of Object.values(propertyTable)) {
|
|
51
|
-
if (!featureIds || !attribute || featureIds.length !== attribute.length) {
|
|
52
|
-
needFlatten = true;
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
return needFlatten;
|
|
56
|
-
}
|
|
57
|
-
exports.checkPropertiesLength = checkPropertiesLength;
|
|
58
|
-
/** String data type name for feature attributes */
|
|
59
|
-
const STRING_TYPE = 'string';
|
|
60
|
-
/** Integer data type name for feature attributes */
|
|
61
|
-
const SHORT_INT_TYPE = 'Int32';
|
|
62
|
-
/** Double data type name for feature attributes */
|
|
63
|
-
const DOUBLE_TYPE = 'double';
|
|
64
|
-
/** Type of attribute that is linked with feature ids */
|
|
65
|
-
const OBJECT_ID_TYPE = 'OBJECTID';
|
|
66
|
-
/**
|
|
67
|
-
* Get the attribute type for attributeStorageInfo https://github.com/Esri/i3s-spec/blob/master/docs/1.7/attributeStorageInfo.cmn.md
|
|
68
|
-
* @param key - attribute's key
|
|
69
|
-
* @param attribute - attribute's type in propertyTable
|
|
70
|
-
*/
|
|
71
|
-
function getAttributeType(key, attribute) {
|
|
72
|
-
if (key === OBJECT_ID_TYPE) {
|
|
73
|
-
return OBJECT_ID_TYPE;
|
|
74
|
-
}
|
|
75
|
-
if (typeof attribute === STRING_TYPE) {
|
|
76
|
-
return STRING_TYPE;
|
|
77
|
-
}
|
|
78
|
-
else if (typeof attribute === 'number') {
|
|
79
|
-
return Number.isInteger(attribute) ? SHORT_INT_TYPE : DOUBLE_TYPE;
|
|
80
|
-
}
|
|
81
|
-
return STRING_TYPE;
|
|
82
|
-
}
|
|
83
|
-
exports.getAttributeType = getAttributeType;
|
|
84
|
-
/**
|
|
85
|
-
* Generate storage attribute for map segmentation.
|
|
86
|
-
* @param attributeIndex - order index of attribute (f_0, f_1 ...).
|
|
87
|
-
* @param key - attribute key from propertyTable.
|
|
88
|
-
* @param attributeType - attribute type.
|
|
89
|
-
* @return Updated storageAttribute.
|
|
90
|
-
*/
|
|
91
|
-
function createdStorageAttribute(attributeIndex, key, attributeType) {
|
|
92
|
-
const storageAttribute = {
|
|
93
|
-
key: `f_${attributeIndex}`,
|
|
94
|
-
name: key,
|
|
95
|
-
ordering: ['attributeValues'],
|
|
96
|
-
header: [{ property: 'count', valueType: 'UInt32' }],
|
|
97
|
-
attributeValues: { valueType: 'Int32', valuesPerElement: 1 }
|
|
98
|
-
};
|
|
99
|
-
switch (attributeType) {
|
|
100
|
-
case OBJECT_ID_TYPE:
|
|
101
|
-
setupIdAttribute(storageAttribute);
|
|
102
|
-
break;
|
|
103
|
-
case STRING_TYPE:
|
|
104
|
-
setupStringAttribute(storageAttribute);
|
|
105
|
-
break;
|
|
106
|
-
case DOUBLE_TYPE:
|
|
107
|
-
setupDoubleAttribute(storageAttribute);
|
|
108
|
-
break;
|
|
109
|
-
case SHORT_INT_TYPE:
|
|
110
|
-
break;
|
|
111
|
-
default:
|
|
112
|
-
setupStringAttribute(storageAttribute);
|
|
113
|
-
}
|
|
114
|
-
return storageAttribute;
|
|
115
|
-
}
|
|
116
|
-
exports.createdStorageAttribute = createdStorageAttribute;
|
|
117
|
-
/**
|
|
118
|
-
* Find and return attribute type based on key form propertyTable.
|
|
119
|
-
* @param attributeType
|
|
120
|
-
*/
|
|
121
|
-
function getFieldAttributeType(attributeType) {
|
|
122
|
-
switch (attributeType) {
|
|
123
|
-
case OBJECT_ID_TYPE:
|
|
124
|
-
return 'esriFieldTypeOID';
|
|
125
|
-
case STRING_TYPE:
|
|
126
|
-
return 'esriFieldTypeString';
|
|
127
|
-
case SHORT_INT_TYPE:
|
|
128
|
-
return 'esriFieldTypeInteger';
|
|
129
|
-
case DOUBLE_TYPE:
|
|
130
|
-
return 'esriFieldTypeDouble';
|
|
131
|
-
default:
|
|
132
|
-
return 'esriFieldTypeString';
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
exports.getFieldAttributeType = getFieldAttributeType;
|
|
136
|
-
/**
|
|
137
|
-
* Setup field attribute for map segmentation.
|
|
138
|
-
* @param key - attribute for map segmentation.
|
|
139
|
-
* @param fieldAttributeType - esri attribute type ('esriFieldTypeString' or 'esriFieldTypeOID').
|
|
140
|
-
*/
|
|
141
|
-
function createFieldAttribute(key, fieldAttributeType) {
|
|
142
|
-
return {
|
|
143
|
-
name: key,
|
|
144
|
-
type: fieldAttributeType,
|
|
145
|
-
alias: key
|
|
146
|
-
};
|
|
147
|
-
}
|
|
148
|
-
exports.createFieldAttribute = createFieldAttribute;
|
|
149
|
-
/**
|
|
150
|
-
* Generate popup info to show metadata on the map.
|
|
151
|
-
* @param propertyTable - table data with OBJECTID.
|
|
152
|
-
* @return data for correct rendering of popup.
|
|
153
|
-
*/
|
|
154
|
-
function createPopupInfo(propertyTable) {
|
|
155
|
-
const title = '{OBJECTID}';
|
|
156
|
-
const mediaInfos = [];
|
|
157
|
-
const fieldInfos = [];
|
|
158
|
-
const popupElements = [];
|
|
159
|
-
const expressionInfos = [];
|
|
160
|
-
for (const key in propertyTable) {
|
|
161
|
-
fieldInfos.push({
|
|
162
|
-
fieldName: key,
|
|
163
|
-
visible: true,
|
|
164
|
-
isEditable: false,
|
|
165
|
-
label: key
|
|
166
|
-
});
|
|
167
|
-
}
|
|
168
|
-
popupElements.push({
|
|
169
|
-
fieldInfos,
|
|
170
|
-
type: 'fields'
|
|
171
|
-
});
|
|
172
|
-
return {
|
|
173
|
-
title,
|
|
174
|
-
mediaInfos,
|
|
175
|
-
popupElements,
|
|
176
|
-
fieldInfos,
|
|
177
|
-
expressionInfos
|
|
178
|
-
};
|
|
179
|
-
}
|
|
180
|
-
exports.createPopupInfo = createPopupInfo;
|
|
181
|
-
/**
|
|
182
|
-
* Setup storage attribute as string.
|
|
183
|
-
* @param storageAttribute - attribute for map segmentation.
|
|
184
|
-
*/
|
|
185
|
-
function setupStringAttribute(storageAttribute) {
|
|
186
|
-
// @ts-expect-error
|
|
187
|
-
storageAttribute.ordering.unshift('attributeByteCounts');
|
|
188
|
-
storageAttribute.header.push({ property: 'attributeValuesByteCount', valueType: 'UInt32' });
|
|
189
|
-
storageAttribute.attributeValues = {
|
|
190
|
-
valueType: 'String',
|
|
191
|
-
encoding: 'UTF-8',
|
|
192
|
-
valuesPerElement: 1
|
|
193
|
-
};
|
|
194
|
-
storageAttribute.attributeByteCounts = {
|
|
195
|
-
valueType: 'UInt32',
|
|
196
|
-
valuesPerElement: 1
|
|
197
|
-
};
|
|
198
|
-
}
|
|
199
|
-
/**
|
|
200
|
-
* Setup Id attribute for map segmentation.
|
|
201
|
-
* @param storageAttribute - attribute for map segmentation .
|
|
202
|
-
*/
|
|
203
|
-
function setupIdAttribute(storageAttribute) {
|
|
204
|
-
storageAttribute.attributeValues = {
|
|
205
|
-
valueType: 'Oid32',
|
|
206
|
-
valuesPerElement: 1
|
|
207
|
-
};
|
|
208
|
-
}
|
|
209
|
-
/**
|
|
210
|
-
* Setup double attribute for map segmentation.
|
|
211
|
-
* @param storageAttribute - attribute for map segmentation .
|
|
212
|
-
*/
|
|
213
|
-
function setupDoubleAttribute(storageAttribute) {
|
|
214
|
-
storageAttribute.attributeValues = {
|
|
215
|
-
valueType: 'Float64',
|
|
216
|
-
valuesPerElement: 1
|
|
217
|
-
};
|
|
218
|
-
}
|
|
@@ -1,203 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.generateAttributes = void 0;
|
|
4
|
-
const loader_utils_1 = require("@loaders.gl/loader-utils");
|
|
5
|
-
const VALUES_PER_VERTEX = 3;
|
|
6
|
-
const POSITIONS_AND_NORMALS_PER_TRIANGLE = 9;
|
|
7
|
-
/**
|
|
8
|
-
* Generate geometry attributes with faceRange and featureCount
|
|
9
|
-
* @param attributes
|
|
10
|
-
* @returns attirbutes with featureCount, featureIds and changed faceRange.
|
|
11
|
-
*/
|
|
12
|
-
function generateAttributes(attributes) {
|
|
13
|
-
const { positions, normals, texCoords, colors, uvRegions, featureIndices } = attributes;
|
|
14
|
-
const triangleCount = positions.length / POSITIONS_AND_NORMALS_PER_TRIANGLE;
|
|
15
|
-
if (!featureIndices.length) {
|
|
16
|
-
return {
|
|
17
|
-
faceRange: new Uint32Array([0, triangleCount - 1]),
|
|
18
|
-
featureIds: [0],
|
|
19
|
-
featureCount: 1,
|
|
20
|
-
positions,
|
|
21
|
-
normals,
|
|
22
|
-
texCoords,
|
|
23
|
-
colors,
|
|
24
|
-
uvRegions
|
|
25
|
-
};
|
|
26
|
-
}
|
|
27
|
-
const data = calculateFaceRangesAndFeaturesCount(featureIndices);
|
|
28
|
-
const attributeObjects = makeAttributeObjects({ ...data, ...attributes });
|
|
29
|
-
const unifiedAttributeObjectsByFeatureIds = unifyObjectsByFeatureId(attributeObjects);
|
|
30
|
-
const groupedAttributes = groupAttributesAndRangesByFeatureId(unifiedAttributeObjectsByFeatureIds, data.featureCount);
|
|
31
|
-
return groupedAttributes;
|
|
32
|
-
}
|
|
33
|
-
exports.generateAttributes = generateAttributes;
|
|
34
|
-
/**
|
|
35
|
-
* Calculates face Ranges and feature count based on featureIndices.
|
|
36
|
-
* @param featureIndices
|
|
37
|
-
* @returns Object with featureCount, reordered attributes and changed faceRange.
|
|
38
|
-
*/
|
|
39
|
-
function calculateFaceRangesAndFeaturesCount(featureIndices) {
|
|
40
|
-
let rangeIndex = 1;
|
|
41
|
-
let featureIndex = 1;
|
|
42
|
-
let currentFeatureId = getFrequentValue(featureIndices.slice(0, VALUES_PER_VERTEX));
|
|
43
|
-
const faceRangeList = [];
|
|
44
|
-
const featureIds = [];
|
|
45
|
-
const uniqueFeatureIds = [currentFeatureId];
|
|
46
|
-
faceRangeList[0] = 0;
|
|
47
|
-
featureIds[0] = currentFeatureId;
|
|
48
|
-
for (let index = VALUES_PER_VERTEX; index < featureIndices.length; index += VALUES_PER_VERTEX) {
|
|
49
|
-
const newFeatureId = getFrequentValue(featureIndices.slice(index, index + VALUES_PER_VERTEX));
|
|
50
|
-
if (currentFeatureId !== newFeatureId) {
|
|
51
|
-
faceRangeList[rangeIndex] = index / VALUES_PER_VERTEX - 1;
|
|
52
|
-
faceRangeList[rangeIndex + 1] = index / VALUES_PER_VERTEX;
|
|
53
|
-
featureIds[featureIndex] = newFeatureId;
|
|
54
|
-
if (!uniqueFeatureIds.includes(newFeatureId)) {
|
|
55
|
-
uniqueFeatureIds.push(newFeatureId);
|
|
56
|
-
}
|
|
57
|
-
rangeIndex += 2;
|
|
58
|
-
featureIndex += 1;
|
|
59
|
-
}
|
|
60
|
-
currentFeatureId = newFeatureId;
|
|
61
|
-
}
|
|
62
|
-
faceRangeList[rangeIndex] = featureIndices.length / VALUES_PER_VERTEX - 1;
|
|
63
|
-
const faceRange = new Uint32Array(faceRangeList);
|
|
64
|
-
const featureCount = uniqueFeatureIds.length;
|
|
65
|
-
return { faceRange, featureCount, featureIds };
|
|
66
|
-
}
|
|
67
|
-
/**
|
|
68
|
-
* Find most frequent value to avoid situation where one vertex can be part of multiple features (objects).
|
|
69
|
-
* @param values
|
|
70
|
-
*/
|
|
71
|
-
function getFrequentValue(values) {
|
|
72
|
-
const map = {};
|
|
73
|
-
let mostFrequentValue = values[0];
|
|
74
|
-
let maxCount = 1;
|
|
75
|
-
for (const value of values) {
|
|
76
|
-
// Save item and it's frequency count to the map.
|
|
77
|
-
map[value] = (map[value] || 0) + 1;
|
|
78
|
-
// Find max count of frequency.
|
|
79
|
-
maxCount = maxCount > map[value] ? maxCount : map[value];
|
|
80
|
-
// Find the most frequent value.
|
|
81
|
-
mostFrequentValue = maxCount > map[value] ? mostFrequentValue : value;
|
|
82
|
-
}
|
|
83
|
-
return mostFrequentValue;
|
|
84
|
-
}
|
|
85
|
-
/**
|
|
86
|
-
* Generate list of attribute object grouped by feature ids.
|
|
87
|
-
* @param attributes
|
|
88
|
-
* @returns sorted list of attribute objects.
|
|
89
|
-
*/
|
|
90
|
-
function makeAttributeObjects(attributes) {
|
|
91
|
-
const { featureIds, positions, normals, colors, uvRegions, texCoords, faceRange = new Uint32Array(0) } = attributes;
|
|
92
|
-
const groupedData = [];
|
|
93
|
-
let positionsList = new Float32Array(positions);
|
|
94
|
-
let normalsList = new Float32Array(normals);
|
|
95
|
-
let colorsList = new Uint8Array(colors);
|
|
96
|
-
let texCoordsList = new Float32Array(texCoords);
|
|
97
|
-
let uvRegionsList = new Uint16Array(uvRegions);
|
|
98
|
-
for (let index = 0; index < featureIds.length; index++) {
|
|
99
|
-
const startIndex = faceRange[index * 2];
|
|
100
|
-
const endIndex = faceRange[index * 2 + 1];
|
|
101
|
-
const positionsCount = getSliceAttributeCount('positions', startIndex, endIndex);
|
|
102
|
-
const normalsCount = getSliceAttributeCount('normals', startIndex, endIndex);
|
|
103
|
-
const colorsCount = getSliceAttributeCount('colors', startIndex, endIndex);
|
|
104
|
-
const uvRegionsCount = getSliceAttributeCount('uvRegions', startIndex, endIndex);
|
|
105
|
-
const texCoordsCount = getSliceAttributeCount('texCoords', startIndex, endIndex);
|
|
106
|
-
groupedData.push({
|
|
107
|
-
featureId: featureIds[index],
|
|
108
|
-
positions: positionsList.slice(0, positionsCount),
|
|
109
|
-
normals: normalsList.slice(0, normalsCount),
|
|
110
|
-
colors: colorsList.slice(0, colorsCount),
|
|
111
|
-
uvRegions: uvRegionsList.slice(0, uvRegionsCount),
|
|
112
|
-
texCoords: texCoordsList.slice(0, texCoordsCount)
|
|
113
|
-
});
|
|
114
|
-
positionsList = positionsList.slice(positionsCount);
|
|
115
|
-
normalsList = normalsList.slice(normalsCount);
|
|
116
|
-
colorsList = colorsList.slice(colorsCount);
|
|
117
|
-
uvRegionsList = uvRegionsList.slice(uvRegionsCount);
|
|
118
|
-
texCoordsList = texCoordsList.slice(texCoordsCount);
|
|
119
|
-
}
|
|
120
|
-
return groupedData.sort((first, second) => first.featureId - second.featureId);
|
|
121
|
-
}
|
|
122
|
-
/**
|
|
123
|
-
* Generate sliced count for generating attribute objects depends on attribute name and range.
|
|
124
|
-
* @param attributeName
|
|
125
|
-
* @param startIndex
|
|
126
|
-
* @param endIndex
|
|
127
|
-
* @returns sliced count
|
|
128
|
-
*/
|
|
129
|
-
function getSliceAttributeCount(attributeName, startIndex, endIndex) {
|
|
130
|
-
const itemsPerVertex4 = 4;
|
|
131
|
-
const texCoordsPerVertex = 2;
|
|
132
|
-
const trianglesCount = endIndex - startIndex + 1;
|
|
133
|
-
const vertexCount = trianglesCount * 3;
|
|
134
|
-
switch (attributeName) {
|
|
135
|
-
case 'positions':
|
|
136
|
-
case 'normals':
|
|
137
|
-
return trianglesCount * POSITIONS_AND_NORMALS_PER_TRIANGLE;
|
|
138
|
-
case 'colors':
|
|
139
|
-
case 'uvRegions':
|
|
140
|
-
return vertexCount * itemsPerVertex4;
|
|
141
|
-
case 'texCoords':
|
|
142
|
-
return vertexCount * texCoordsPerVertex;
|
|
143
|
-
default:
|
|
144
|
-
return 0;
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
/**
|
|
148
|
-
* Generates unique object list depends on feature ids and concantenate their attributes.
|
|
149
|
-
* @param sortedData
|
|
150
|
-
* @returns unique list of objects
|
|
151
|
-
*/
|
|
152
|
-
function unifyObjectsByFeatureId(sortedData) {
|
|
153
|
-
const uniqueObjects = [];
|
|
154
|
-
for (let index = 0; index < sortedData.length; index++) {
|
|
155
|
-
const currentObject = sortedData[index];
|
|
156
|
-
const existingObject = uniqueObjects.find((obj) => obj.featureId === currentObject.featureId);
|
|
157
|
-
if (existingObject) {
|
|
158
|
-
existingObject.positions = (0, loader_utils_1.concatenateTypedArrays)(existingObject.positions, currentObject.positions);
|
|
159
|
-
existingObject.normals = (0, loader_utils_1.concatenateTypedArrays)(existingObject.normals, currentObject.normals);
|
|
160
|
-
existingObject.colors = (0, loader_utils_1.concatenateTypedArrays)(existingObject.colors, currentObject.colors);
|
|
161
|
-
existingObject.texCoords = (0, loader_utils_1.concatenateTypedArrays)(existingObject.texCoords, currentObject.texCoords);
|
|
162
|
-
existingObject.uvRegions = (0, loader_utils_1.concatenateTypedArrays)(existingObject.uvRegions, currentObject.uvRegions);
|
|
163
|
-
}
|
|
164
|
-
else {
|
|
165
|
-
uniqueObjects.push(currentObject);
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
return uniqueObjects;
|
|
169
|
-
}
|
|
170
|
-
/**
|
|
171
|
-
* Generates attribute objects with new faceRange and reordered attributes.
|
|
172
|
-
* @param unifiedObjects
|
|
173
|
-
* @returns generated attributes with new faceRange.
|
|
174
|
-
*/
|
|
175
|
-
function groupAttributesAndRangesByFeatureId(unifiedObjects, featureCount) {
|
|
176
|
-
const firstAttributeObject = unifiedObjects[0];
|
|
177
|
-
const featureIds = [firstAttributeObject.featureId || 0];
|
|
178
|
-
let positions = new Float32Array(firstAttributeObject.positions);
|
|
179
|
-
let normals = new Float32Array(firstAttributeObject.normals);
|
|
180
|
-
let colors = new Uint8Array(firstAttributeObject.colors);
|
|
181
|
-
let uvRegions = new Uint16Array(firstAttributeObject.uvRegions);
|
|
182
|
-
let texCoords = new Float32Array(firstAttributeObject.texCoords);
|
|
183
|
-
const range = [0];
|
|
184
|
-
let objIndex = 0;
|
|
185
|
-
let sum = 0;
|
|
186
|
-
for (let index = 1; index < unifiedObjects.length; index++) {
|
|
187
|
-
const currentAttributesObject = unifiedObjects[index];
|
|
188
|
-
featureIds.push(currentAttributesObject.featureId || 0);
|
|
189
|
-
positions = (0, loader_utils_1.concatenateTypedArrays)(positions, currentAttributesObject.positions);
|
|
190
|
-
normals = (0, loader_utils_1.concatenateTypedArrays)(normals, currentAttributesObject.normals);
|
|
191
|
-
colors = (0, loader_utils_1.concatenateTypedArrays)(colors, currentAttributesObject.colors);
|
|
192
|
-
uvRegions = (0, loader_utils_1.concatenateTypedArrays)(uvRegions, currentAttributesObject.uvRegions);
|
|
193
|
-
texCoords = (0, loader_utils_1.concatenateTypedArrays)(texCoords, currentAttributesObject.texCoords);
|
|
194
|
-
const groupedObject = unifiedObjects[objIndex];
|
|
195
|
-
range.push(groupedObject.positions.length / POSITIONS_AND_NORMALS_PER_TRIANGLE - 1 + sum);
|
|
196
|
-
range.push(groupedObject.positions.length / POSITIONS_AND_NORMALS_PER_TRIANGLE + sum);
|
|
197
|
-
sum += groupedObject.positions.length / POSITIONS_AND_NORMALS_PER_TRIANGLE;
|
|
198
|
-
objIndex += 1;
|
|
199
|
-
}
|
|
200
|
-
range.push(positions.length / POSITIONS_AND_NORMALS_PER_TRIANGLE - 1);
|
|
201
|
-
const faceRange = new Uint32Array(range);
|
|
202
|
-
return { faceRange, featureIds, positions, normals, colors, uvRegions, texCoords, featureCount };
|
|
203
|
-
}
|