@loaders.gl/tile-converter 3.4.13 → 3.4.15
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-attributes-worker.js +1 -1
- package/dist/converter.min.js +78 -77
- package/dist/dist.min.js +2081 -1557
- package/dist/es5/3d-tiles-attributes-worker.js +3 -3
- package/dist/es5/3d-tiles-attributes-worker.js.map +1 -1
- package/dist/es5/3d-tiles-converter/3d-tiles-converter.js +203 -417
- package/dist/es5/3d-tiles-converter/3d-tiles-converter.js.map +1 -1
- package/dist/es5/3d-tiles-converter/helpers/b3dm-converter.js +197 -266
- package/dist/es5/3d-tiles-converter/helpers/b3dm-converter.js.map +1 -1
- package/dist/es5/3d-tiles-converter/helpers/i3s-obb-to-3d-tiles-obb.js +4 -6
- package/dist/es5/3d-tiles-converter/helpers/i3s-obb-to-3d-tiles-obb.js.map +1 -1
- package/dist/es5/3d-tiles-converter/helpers/texture-atlas.js +12 -12
- package/dist/es5/3d-tiles-converter/helpers/texture-atlas.js.map +1 -1
- package/dist/es5/3d-tiles-converter/json-templates/tileset.js +35 -51
- package/dist/es5/3d-tiles-converter/json-templates/tileset.js.map +1 -1
- package/dist/es5/bundle.js +1 -1
- package/dist/es5/bundle.js.map +1 -1
- package/dist/es5/constants.js +1 -1
- package/dist/es5/constants.js.map +1 -1
- package/dist/es5/converter-cli.js +78 -133
- package/dist/es5/converter-cli.js.map +1 -1
- package/dist/es5/deps-installer/deps-installer.js +38 -110
- package/dist/es5/deps-installer/deps-installer.js.map +1 -1
- package/dist/es5/i3s-attributes-worker.js +3 -3
- package/dist/es5/i3s-attributes-worker.js.map +1 -1
- package/dist/es5/i3s-converter/helpers/batch-ids-extensions.js +31 -36
- package/dist/es5/i3s-converter/helpers/batch-ids-extensions.js.map +1 -1
- package/dist/es5/i3s-converter/helpers/coordinate-converter.js +23 -23
- package/dist/es5/i3s-converter/helpers/coordinate-converter.js.map +1 -1
- package/dist/es5/i3s-converter/helpers/create-scene-server-path.js +9 -27
- package/dist/es5/i3s-converter/helpers/create-scene-server-path.js.map +1 -1
- package/dist/es5/i3s-converter/helpers/feature-attributes.js +27 -42
- package/dist/es5/i3s-converter/helpers/feature-attributes.js.map +1 -1
- package/dist/es5/i3s-converter/helpers/geometry-attributes.js +97 -114
- package/dist/es5/i3s-converter/helpers/geometry-attributes.js.map +1 -1
- package/dist/es5/i3s-converter/helpers/geometry-converter.js +524 -799
- package/dist/es5/i3s-converter/helpers/geometry-converter.js.map +1 -1
- package/dist/es5/i3s-converter/helpers/gltf-attributes.js +24 -25
- package/dist/es5/i3s-converter/helpers/gltf-attributes.js.map +1 -1
- package/dist/es5/i3s-converter/helpers/node-debug.js +27 -25
- package/dist/es5/i3s-converter/helpers/node-debug.js.map +1 -1
- package/dist/es5/i3s-converter/helpers/node-index-document.js +165 -461
- package/dist/es5/i3s-converter/helpers/node-index-document.js.map +1 -1
- package/dist/es5/i3s-converter/helpers/node-pages.js +169 -474
- package/dist/es5/i3s-converter/helpers/node-pages.js.map +1 -1
- package/dist/es5/i3s-converter/i3s-converter.js +663 -1401
- package/dist/es5/i3s-converter/i3s-converter.js.map +1 -1
- package/dist/es5/i3s-converter/json-templates/geometry-definitions.js +82 -92
- package/dist/es5/i3s-converter/json-templates/geometry-definitions.js.map +1 -1
- package/dist/es5/i3s-converter/json-templates/layers.js +130 -152
- package/dist/es5/i3s-converter/json-templates/layers.js.map +1 -1
- package/dist/es5/i3s-converter/json-templates/metadata.js +21 -23
- package/dist/es5/i3s-converter/json-templates/metadata.js.map +1 -1
- package/dist/es5/i3s-converter/json-templates/node.js +78 -89
- package/dist/es5/i3s-converter/json-templates/node.js.map +1 -1
- package/dist/es5/i3s-converter/json-templates/scene-server.js +27 -31
- package/dist/es5/i3s-converter/json-templates/scene-server.js.map +1 -1
- package/dist/es5/i3s-converter/json-templates/shared-resources.js +110 -152
- package/dist/es5/i3s-converter/json-templates/shared-resources.js.map +1 -1
- package/dist/es5/i3s-converter/json-templates/store.js +2 -4
- package/dist/es5/i3s-converter/json-templates/store.js.map +1 -1
- package/dist/es5/i3s-server/app.js +6 -6
- package/dist/es5/i3s-server/app.js.map +1 -1
- package/dist/es5/i3s-server/controllers/index-controller.js +20 -49
- package/dist/es5/i3s-server/controllers/index-controller.js.map +1 -1
- package/dist/es5/i3s-server/routes/index.js +14 -33
- package/dist/es5/i3s-server/routes/index.js.map +1 -1
- package/dist/es5/index.js +2 -2
- package/dist/es5/lib/utils/compress-util.js +127 -295
- package/dist/es5/lib/utils/compress-util.js.map +1 -1
- package/dist/es5/lib/utils/file-utils.js +65 -174
- package/dist/es5/lib/utils/file-utils.js.map +1 -1
- package/dist/es5/lib/utils/lod-conversion-utils.js +9 -9
- package/dist/es5/lib/utils/lod-conversion-utils.js.map +1 -1
- package/dist/es5/lib/utils/queue.js +13 -38
- package/dist/es5/lib/utils/queue.js.map +1 -1
- package/dist/es5/lib/utils/statistic-utills.js +39 -117
- package/dist/es5/lib/utils/statistic-utills.js.map +1 -1
- package/dist/es5/lib/utils/write-queue.js +74 -195
- package/dist/es5/lib/utils/write-queue.js.map +1 -1
- package/dist/es5/pgm-loader.js +3 -22
- package/dist/es5/pgm-loader.js.map +1 -1
- package/dist/es5/workers/3d-tiles-attributes-worker.js +5 -22
- package/dist/es5/workers/3d-tiles-attributes-worker.js.map +1 -1
- package/dist/es5/workers/i3s-attributes-worker.js +4 -25
- package/dist/es5/workers/i3s-attributes-worker.js.map +1 -1
- package/dist/esm/3d-tiles-attributes-worker.js +1 -1
- package/dist/esm/deps-installer/deps-installer.js +1 -1
- package/dist/esm/i3s-attributes-worker.js +1 -1
- package/dist/esm/i3s-converter/helpers/batch-ids-extensions.js.map +1 -1
- package/dist/esm/i3s-converter/helpers/geometry-converter.js +1 -1
- package/dist/esm/i3s-converter/helpers/geometry-converter.js.map +1 -1
- package/dist/esm/pgm-loader.js +1 -1
- package/dist/i3s-attributes-worker.js +2 -2
- package/dist/i3s-attributes-worker.js.map +3 -3
- package/dist/i3s-converter/helpers/geometry-converter.d.ts +1 -1
- package/dist/i3s-converter/helpers/geometry-converter.d.ts.map +1 -1
- package/package.json +15 -15
- package/src/i3s-converter/helpers/batch-ids-extensions.ts +1 -1
- package/src/i3s-converter/helpers/geometry-converter.ts +14 -14
|
@@ -1,16 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
var _typeof = require("@babel/runtime/helpers/typeof");
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
8
7
|
exports.convertAttributes = convertAttributes;
|
|
9
8
|
exports.default = convertB3dmToI3sGeometry;
|
|
10
9
|
exports.getPropertyTable = getPropertyTable;
|
|
11
|
-
var
|
|
12
|
-
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
13
|
-
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
10
|
+
var _math = require("@loaders.gl/math");
|
|
14
11
|
var _core = require("@math.gl/core");
|
|
15
12
|
var _geospatial = require("@math.gl/geospatial");
|
|
16
13
|
var _draco = require("@loaders.gl/draco");
|
|
@@ -23,324 +20,194 @@ var _coordinateConverter = require("./coordinate-converter");
|
|
|
23
20
|
var _gltfAttributes = require("./gltf-attributes");
|
|
24
21
|
var _batchIdsExtensions = require("./batch-ids-extensions");
|
|
25
22
|
var _featureAttributes = require("./feature-attributes");
|
|
26
|
-
|
|
27
|
-
function
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
var
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
_context.next = 18;
|
|
83
|
-
break;
|
|
84
|
-
}
|
|
85
|
-
return _context.abrupt("continue", 30);
|
|
86
|
-
case 18:
|
|
87
|
-
convertedAttributes = convertedAttributesMap.get(originarMaterialId);
|
|
88
|
-
if (convertedAttributes) {
|
|
89
|
-
_context.next = 21;
|
|
90
|
-
break;
|
|
91
|
-
}
|
|
92
|
-
return _context.abrupt("continue", 30);
|
|
93
|
-
case 21:
|
|
94
|
-
material = materialAndTexture.material, texture = materialAndTexture.texture;
|
|
95
|
-
_context.next = 24;
|
|
96
|
-
return addNodeToNodePage();
|
|
97
|
-
case 24:
|
|
98
|
-
nodeId = _context.sent;
|
|
99
|
-
_context.t0 = result;
|
|
100
|
-
_context.next = 28;
|
|
101
|
-
return _makeNodeResources({
|
|
102
|
-
convertedAttributes: convertedAttributes,
|
|
103
|
-
material: material,
|
|
104
|
-
texture: texture,
|
|
105
|
-
tileContent: tileContent,
|
|
106
|
-
nodeId: nodeId,
|
|
107
|
-
featuresHashArray: featuresHashArray,
|
|
108
|
-
propertyTable: propertyTable,
|
|
109
|
-
attributeStorageInfo: attributeStorageInfo,
|
|
110
|
-
draco: draco,
|
|
111
|
-
workerSource: workerSource
|
|
112
|
-
});
|
|
113
|
-
case 28:
|
|
114
|
-
_context.t1 = _context.sent;
|
|
115
|
-
_context.t0.push.call(_context.t0, _context.t1);
|
|
116
|
-
case 30:
|
|
117
|
-
_context.next = 13;
|
|
118
|
-
break;
|
|
119
|
-
case 32:
|
|
120
|
-
_context.next = 37;
|
|
121
|
-
break;
|
|
122
|
-
case 34:
|
|
123
|
-
_context.prev = 34;
|
|
124
|
-
_context.t2 = _context["catch"](11);
|
|
125
|
-
_iterator6.e(_context.t2);
|
|
126
|
-
case 37:
|
|
127
|
-
_context.prev = 37;
|
|
128
|
-
_iterator6.f();
|
|
129
|
-
return _context.finish(37);
|
|
130
|
-
case 40:
|
|
131
|
-
if (result.length) {
|
|
132
|
-
_context.next = 42;
|
|
133
|
-
break;
|
|
134
|
-
}
|
|
135
|
-
return _context.abrupt("return", null);
|
|
136
|
-
case 42:
|
|
137
|
-
return _context.abrupt("return", result);
|
|
138
|
-
case 43:
|
|
139
|
-
case "end":
|
|
140
|
-
return _context.stop();
|
|
141
|
-
}
|
|
142
|
-
}, _callee, null, [[11, 34, 37, 40]]);
|
|
143
|
-
}));
|
|
144
|
-
return _convertB3dmToI3sGeometry.apply(this, arguments);
|
|
23
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
24
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
25
|
+
const DEFAULT_ROUGHNESS_FACTOR = 1;
|
|
26
|
+
const DEFAULT_METALLIC_FACTOR = 1;
|
|
27
|
+
const VALUES_PER_VERTEX = 3;
|
|
28
|
+
const VALUES_PER_TEX_COORD = 2;
|
|
29
|
+
const VALUES_PER_COLOR_ELEMENT = 4;
|
|
30
|
+
const STRING_TYPE = 'string';
|
|
31
|
+
const SHORT_INT_TYPE = 'Int32';
|
|
32
|
+
const DOUBLE_TYPE = 'Float64';
|
|
33
|
+
const OBJECT_ID_TYPE = 'Oid32';
|
|
34
|
+
const BATCHED_ID_POSSIBLE_ATTRIBUTE_NAMES = ['CUSTOM_ATTRIBUTE_2', '_BATCHID', 'BATCHID'];
|
|
35
|
+
const EXT_FEATURE_METADATA = 'EXT_feature_metadata';
|
|
36
|
+
const EXT_MESH_FEATURES = 'EXT_mesh_features';
|
|
37
|
+
let scratchVector = new _core.Vector3();
|
|
38
|
+
async function convertB3dmToI3sGeometry(tileContent, addNodeToNodePage, propertyTable, featuresHashArray, attributeStorageInfo, draco, generateBoundingVolumes, shouldMergeMaterials, geoidHeightModel, workerSource) {
|
|
39
|
+
var _tileContent$gltf;
|
|
40
|
+
const useCartesianPositions = generateBoundingVolumes;
|
|
41
|
+
const materialAndTextureList = await convertMaterials((_tileContent$gltf = tileContent.gltf) === null || _tileContent$gltf === void 0 ? void 0 : _tileContent$gltf.materials, shouldMergeMaterials);
|
|
42
|
+
const dataForAttributesConversion = (0, _gltfAttributes.prepareDataForAttributesConversion)(tileContent);
|
|
43
|
+
const convertedAttributesMap = await convertAttributes(dataForAttributesConversion, materialAndTextureList, useCartesianPositions);
|
|
44
|
+
if (generateBoundingVolumes) {
|
|
45
|
+
_generateBoundingVolumesFromGeometry(convertedAttributesMap, geoidHeightModel);
|
|
46
|
+
}
|
|
47
|
+
const result = [];
|
|
48
|
+
for (const materialAndTexture of materialAndTextureList) {
|
|
49
|
+
const originarMaterialId = materialAndTexture.mergedMaterials[0].originalMaterialId;
|
|
50
|
+
if (!convertedAttributesMap.has(originarMaterialId)) {
|
|
51
|
+
continue;
|
|
52
|
+
}
|
|
53
|
+
const convertedAttributes = convertedAttributesMap.get(originarMaterialId);
|
|
54
|
+
if (!convertedAttributes) {
|
|
55
|
+
continue;
|
|
56
|
+
}
|
|
57
|
+
const {
|
|
58
|
+
material,
|
|
59
|
+
texture
|
|
60
|
+
} = materialAndTexture;
|
|
61
|
+
const nodeId = await addNodeToNodePage();
|
|
62
|
+
result.push(await _makeNodeResources({
|
|
63
|
+
convertedAttributes,
|
|
64
|
+
material,
|
|
65
|
+
texture,
|
|
66
|
+
tileContent,
|
|
67
|
+
nodeId,
|
|
68
|
+
featuresHashArray,
|
|
69
|
+
propertyTable,
|
|
70
|
+
attributeStorageInfo,
|
|
71
|
+
draco,
|
|
72
|
+
workerSource
|
|
73
|
+
}));
|
|
74
|
+
}
|
|
75
|
+
if (!result.length) {
|
|
76
|
+
return null;
|
|
77
|
+
}
|
|
78
|
+
return result;
|
|
145
79
|
}
|
|
146
80
|
function _generateBoundingVolumesFromGeometry(convertedAttributesMap, geoidHeightModel) {
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
_geospatial.Ellipsoid.WGS84.cartesianToCartographic(Array.from(vertex), scratchVector);
|
|
158
|
-
scratchVector[2] = scratchVector[2] - geoidHeightModel.getHeight(scratchVector[1], scratchVector[0]);
|
|
159
|
-
scratchVector = scratchVector.subtract(cartographicOrigin);
|
|
160
|
-
attributes.positions.set(scratchVector, index);
|
|
161
|
-
}
|
|
81
|
+
for (const attributes of convertedAttributesMap.values()) {
|
|
82
|
+
const boundingVolumes = (0, _coordinateConverter.createBoundingVolumesFromGeometry)(attributes.positions, geoidHeightModel);
|
|
83
|
+
attributes.boundingVolumes = boundingVolumes;
|
|
84
|
+
const cartographicOrigin = boundingVolumes.obb.center;
|
|
85
|
+
for (let index = 0; index < attributes.positions.length; index += VALUES_PER_VERTEX) {
|
|
86
|
+
const vertex = attributes.positions.subarray(index, index + VALUES_PER_VERTEX);
|
|
87
|
+
_geospatial.Ellipsoid.WGS84.cartesianToCartographic(Array.from(vertex), scratchVector);
|
|
88
|
+
scratchVector[2] = scratchVector[2] - geoidHeightModel.getHeight(scratchVector[1], scratchVector[0]);
|
|
89
|
+
scratchVector = scratchVector.subtract(cartographicOrigin);
|
|
90
|
+
attributes.positions.set(scratchVector, index);
|
|
162
91
|
}
|
|
163
|
-
} catch (err) {
|
|
164
|
-
_iterator.e(err);
|
|
165
|
-
} finally {
|
|
166
|
-
_iterator.f();
|
|
167
92
|
}
|
|
168
93
|
}
|
|
169
|
-
function _makeNodeResources(
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
94
|
+
async function _makeNodeResources(_ref) {
|
|
95
|
+
var _tileContent$gltf2;
|
|
96
|
+
let {
|
|
97
|
+
convertedAttributes,
|
|
98
|
+
material,
|
|
99
|
+
texture,
|
|
100
|
+
tileContent,
|
|
101
|
+
nodeId,
|
|
102
|
+
featuresHashArray,
|
|
103
|
+
propertyTable,
|
|
104
|
+
attributeStorageInfo,
|
|
105
|
+
draco,
|
|
106
|
+
workerSource
|
|
107
|
+
} = _ref;
|
|
108
|
+
const boundingVolumes = convertedAttributes.boundingVolumes;
|
|
109
|
+
const vertexCount = convertedAttributes.positions.length / VALUES_PER_VERTEX;
|
|
110
|
+
const {
|
|
111
|
+
faceRange,
|
|
112
|
+
featureIds,
|
|
113
|
+
positions,
|
|
114
|
+
normals,
|
|
115
|
+
colors,
|
|
116
|
+
uvRegions,
|
|
117
|
+
texCoords,
|
|
118
|
+
featureCount
|
|
119
|
+
} = (0, _geometryAttributes.generateAttributes)(convertedAttributes);
|
|
120
|
+
if (tileContent.batchTableJson) {
|
|
121
|
+
makeFeatureIdsUnique(featureIds, convertedAttributes.featureIndices, featuresHashArray, tileContent.batchTableJson);
|
|
122
|
+
}
|
|
123
|
+
const header = new Uint32Array(2);
|
|
124
|
+
const typedFeatureIds = generateBigUint64Array(featureIds);
|
|
125
|
+
header.set([vertexCount, featureCount], 0);
|
|
126
|
+
const fileBuffer = new Uint8Array((0, _loaderUtils.concatenateArrayBuffers)(header.buffer, positions.buffer, normals.buffer, texture ? texCoords.buffer : new ArrayBuffer(0), colors.buffer, uvRegions, typedFeatureIds.buffer, faceRange.buffer));
|
|
127
|
+
const compressedGeometry = draco ? generateCompressedGeometry(vertexCount, convertedAttributes, {
|
|
128
|
+
positions,
|
|
129
|
+
normals,
|
|
130
|
+
texCoords: texture ? texCoords : new Float32Array(0),
|
|
131
|
+
colors,
|
|
132
|
+
uvRegions,
|
|
133
|
+
featureIds,
|
|
134
|
+
faceRange
|
|
135
|
+
}, workerSource.draco) : null;
|
|
136
|
+
let attributes = [];
|
|
137
|
+
if (attributeStorageInfo && propertyTable) {
|
|
138
|
+
attributes = convertPropertyTableToAttributeBuffers(featureIds, propertyTable, attributeStorageInfo);
|
|
139
|
+
}
|
|
140
|
+
return {
|
|
141
|
+
nodeId,
|
|
142
|
+
geometry: fileBuffer,
|
|
143
|
+
compressedGeometry,
|
|
144
|
+
texture,
|
|
145
|
+
hasUvRegions: Boolean(uvRegions.length),
|
|
146
|
+
sharedResources: getSharedResources(((_tileContent$gltf2 = tileContent.gltf) === null || _tileContent$gltf2 === void 0 ? void 0 : _tileContent$gltf2.materials) || [], nodeId),
|
|
147
|
+
meshMaterial: material,
|
|
148
|
+
vertexCount,
|
|
149
|
+
attributes,
|
|
150
|
+
featureCount,
|
|
151
|
+
boundingVolumes
|
|
152
|
+
};
|
|
226
153
|
}
|
|
227
|
-
function
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
convertNodes(nodes, images, cartographicOrigin, cartesianModelMatrix, attributesMap, useCartesianPositions);
|
|
268
|
-
_iterator8 = _createForOfIteratorHelper(attributesMap.keys());
|
|
269
|
-
_context3.prev = 6;
|
|
270
|
-
_iterator8.s();
|
|
271
|
-
case 8:
|
|
272
|
-
if ((_step8 = _iterator8.n()).done) {
|
|
273
|
-
_context3.next = 19;
|
|
274
|
-
break;
|
|
275
|
-
}
|
|
276
|
-
attrKey = _step8.value;
|
|
277
|
-
_attributes = attributesMap.get(attrKey);
|
|
278
|
-
if (_attributes) {
|
|
279
|
-
_context3.next = 13;
|
|
280
|
-
break;
|
|
281
|
-
}
|
|
282
|
-
return _context3.abrupt("continue", 17);
|
|
283
|
-
case 13:
|
|
284
|
-
if (!(_attributes.positions.length === 0)) {
|
|
285
|
-
_context3.next = 16;
|
|
286
|
-
break;
|
|
287
|
-
}
|
|
288
|
-
attributesMap.delete(attrKey);
|
|
289
|
-
return _context3.abrupt("continue", 17);
|
|
290
|
-
case 16:
|
|
291
|
-
if (_attributes.featureIndicesGroups) {
|
|
292
|
-
_attributes.featureIndices = _attributes.featureIndicesGroups.reduce(function (acc, value) {
|
|
293
|
-
return acc.concat(value);
|
|
294
|
-
});
|
|
295
|
-
delete _attributes.featureIndicesGroups;
|
|
296
|
-
}
|
|
297
|
-
case 17:
|
|
298
|
-
_context3.next = 8;
|
|
299
|
-
break;
|
|
300
|
-
case 19:
|
|
301
|
-
_context3.next = 24;
|
|
302
|
-
break;
|
|
303
|
-
case 21:
|
|
304
|
-
_context3.prev = 21;
|
|
305
|
-
_context3.t0 = _context3["catch"](6);
|
|
306
|
-
_iterator8.e(_context3.t0);
|
|
307
|
-
case 24:
|
|
308
|
-
_context3.prev = 24;
|
|
309
|
-
_iterator8.f();
|
|
310
|
-
return _context3.finish(24);
|
|
311
|
-
case 27:
|
|
312
|
-
return _context3.abrupt("return", attributesMap);
|
|
313
|
-
case 28:
|
|
314
|
-
case "end":
|
|
315
|
-
return _context3.stop();
|
|
316
|
-
}
|
|
317
|
-
}, _callee3, null, [[6, 21, 24, 27]]);
|
|
318
|
-
}));
|
|
319
|
-
return _convertAttributes.apply(this, arguments);
|
|
154
|
+
async function convertAttributes(attributesData, materialAndTextureList, useCartesianPositions) {
|
|
155
|
+
const {
|
|
156
|
+
nodes,
|
|
157
|
+
images,
|
|
158
|
+
cartographicOrigin,
|
|
159
|
+
cartesianModelMatrix
|
|
160
|
+
} = attributesData;
|
|
161
|
+
const attributesMap = new Map();
|
|
162
|
+
for (const materialAndTexture of materialAndTextureList) {
|
|
163
|
+
const attributes = {
|
|
164
|
+
positions: new Float32Array(0),
|
|
165
|
+
normals: new Float32Array(0),
|
|
166
|
+
texCoords: new Float32Array(0),
|
|
167
|
+
colors: new Uint8Array(0),
|
|
168
|
+
uvRegions: new Uint16Array(0),
|
|
169
|
+
featureIndicesGroups: [],
|
|
170
|
+
featureIndices: [],
|
|
171
|
+
boundingVolumes: null,
|
|
172
|
+
mergedMaterials: materialAndTexture.mergedMaterials
|
|
173
|
+
};
|
|
174
|
+
for (const mergedMaterial of materialAndTexture.mergedMaterials) {
|
|
175
|
+
attributesMap.set(mergedMaterial.originalMaterialId, attributes);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
convertNodes(nodes, images, cartographicOrigin, cartesianModelMatrix, attributesMap, useCartesianPositions);
|
|
179
|
+
for (const attrKey of attributesMap.keys()) {
|
|
180
|
+
const attributes = attributesMap.get(attrKey);
|
|
181
|
+
if (!attributes) {
|
|
182
|
+
continue;
|
|
183
|
+
}
|
|
184
|
+
if (attributes.positions.length === 0) {
|
|
185
|
+
attributesMap.delete(attrKey);
|
|
186
|
+
continue;
|
|
187
|
+
}
|
|
188
|
+
if (attributes.featureIndicesGroups) {
|
|
189
|
+
attributes.featureIndices = attributes.featureIndicesGroups.reduce((acc, value) => acc.concat(value));
|
|
190
|
+
delete attributes.featureIndicesGroups;
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
return attributesMap;
|
|
320
194
|
}
|
|
321
195
|
function convertNodes(nodes, images, cartographicOrigin, cartesianModelMatrix, attributesMap, useCartesianPositions) {
|
|
322
|
-
|
|
196
|
+
let matrix = arguments.length > 6 && arguments[6] !== undefined ? arguments[6] : new _core.Matrix4([1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1]);
|
|
323
197
|
if (nodes) {
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
try {
|
|
327
|
-
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
328
|
-
var node = _step2.value;
|
|
329
|
-
convertNode(node, images, cartographicOrigin, cartesianModelMatrix, attributesMap, useCartesianPositions, matrix);
|
|
330
|
-
}
|
|
331
|
-
} catch (err) {
|
|
332
|
-
_iterator2.e(err);
|
|
333
|
-
} finally {
|
|
334
|
-
_iterator2.f();
|
|
198
|
+
for (const node of nodes) {
|
|
199
|
+
convertNode(node, images, cartographicOrigin, cartesianModelMatrix, attributesMap, useCartesianPositions, matrix);
|
|
335
200
|
}
|
|
336
201
|
}
|
|
337
202
|
}
|
|
338
203
|
function getCompositeTransformationMatrix(node, matrix) {
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
204
|
+
let transformationMatrix = matrix;
|
|
205
|
+
const {
|
|
206
|
+
matrix: nodeMatrix,
|
|
207
|
+
rotation,
|
|
208
|
+
scale,
|
|
209
|
+
translation
|
|
210
|
+
} = node;
|
|
344
211
|
if (nodeMatrix) {
|
|
345
212
|
transformationMatrix = matrix.multiplyRight(nodeMatrix);
|
|
346
213
|
}
|
|
@@ -356,87 +223,76 @@ function getCompositeTransformationMatrix(node, matrix) {
|
|
|
356
223
|
return transformationMatrix;
|
|
357
224
|
}
|
|
358
225
|
function convertNode(node, images, cartographicOrigin, cartesianModelMatrix, attributesMap, useCartesianPositions) {
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
226
|
+
let matrix = arguments.length > 6 && arguments[6] !== undefined ? arguments[6] : new _core.Matrix4([1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1]);
|
|
227
|
+
const transformationMatrix = getCompositeTransformationMatrix(node, matrix);
|
|
228
|
+
const mesh = node.mesh;
|
|
362
229
|
if (mesh) {
|
|
363
230
|
convertMesh(mesh, images, cartographicOrigin, cartesianModelMatrix, attributesMap, useCartesianPositions, transformationMatrix);
|
|
364
231
|
}
|
|
365
232
|
convertNodes(node.children || [], images, cartographicOrigin, cartesianModelMatrix, attributesMap, useCartesianPositions, transformationMatrix);
|
|
366
233
|
}
|
|
367
234
|
function convertMesh(mesh, images, cartographicOrigin, cartesianModelMatrix, attributesMap) {
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
var
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
if (!outputAttributes) {
|
|
391
|
-
return "continue";
|
|
392
|
-
}
|
|
393
|
-
var indices = getIndices(primitive);
|
|
394
|
-
outputAttributes.positions = (0, _loaderUtils.concatenateTypedArrays)(outputAttributes.positions, transformVertexArray({
|
|
395
|
-
vertices: attributes.POSITION.value,
|
|
396
|
-
cartographicOrigin: cartographicOrigin,
|
|
397
|
-
cartesianModelMatrix: cartesianModelMatrix,
|
|
398
|
-
nodeMatrix: matrix,
|
|
399
|
-
indices: indices,
|
|
400
|
-
attributeSpecificTransformation: transformVertexPositions,
|
|
401
|
-
useCartesianPositions: useCartesianPositions
|
|
402
|
-
}));
|
|
403
|
-
outputAttributes.normals = (0, _loaderUtils.concatenateTypedArrays)(outputAttributes.normals, transformVertexArray({
|
|
404
|
-
vertices: attributes.NORMAL && attributes.NORMAL.value,
|
|
405
|
-
cartographicOrigin: cartographicOrigin,
|
|
406
|
-
cartesianModelMatrix: cartesianModelMatrix,
|
|
407
|
-
nodeMatrix: matrix,
|
|
408
|
-
indices: indices,
|
|
409
|
-
attributeSpecificTransformation: transformVertexNormals,
|
|
410
|
-
useCartesianPositions: false
|
|
411
|
-
}));
|
|
412
|
-
outputAttributes.texCoords = (0, _loaderUtils.concatenateTypedArrays)(outputAttributes.texCoords, flattenTexCoords(attributes.TEXCOORD_0 && attributes.TEXCOORD_0.value, indices));
|
|
413
|
-
outputAttributes.colors = (0, _loaderUtils.concatenateTypedArrays)(outputAttributes.colors, flattenColors(attributes.COLOR_0, indices));
|
|
414
|
-
if (materialUvRegion) {
|
|
415
|
-
outputAttributes.uvRegions = (0, _loaderUtils.concatenateTypedArrays)(outputAttributes.uvRegions, createUvRegion(materialUvRegion, indices));
|
|
416
|
-
}
|
|
417
|
-
outputAttributes.featureIndicesGroups = outputAttributes.featureIndicesGroups || [];
|
|
418
|
-
outputAttributes.featureIndicesGroups.push(flattenBatchIds(getBatchIds(attributes, primitive, images), indices));
|
|
419
|
-
};
|
|
420
|
-
for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
|
|
421
|
-
var _ret = _loop();
|
|
422
|
-
if (_ret === "continue") continue;
|
|
235
|
+
let useCartesianPositions = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : false;
|
|
236
|
+
let matrix = arguments.length > 6 && arguments[6] !== undefined ? arguments[6] : new _core.Matrix4([1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1]);
|
|
237
|
+
for (const primitive of mesh.primitives) {
|
|
238
|
+
let outputAttributes = null;
|
|
239
|
+
let materialUvRegion;
|
|
240
|
+
if (primitive.material) {
|
|
241
|
+
var _outputAttributes, _outputAttributes$mer;
|
|
242
|
+
outputAttributes = attributesMap.get(primitive.material.uniqueId);
|
|
243
|
+
materialUvRegion = (_outputAttributes = outputAttributes) === null || _outputAttributes === void 0 ? void 0 : (_outputAttributes$mer = _outputAttributes.mergedMaterials.find(_ref2 => {
|
|
244
|
+
var _primitive$material;
|
|
245
|
+
let {
|
|
246
|
+
originalMaterialId
|
|
247
|
+
} = _ref2;
|
|
248
|
+
return originalMaterialId === ((_primitive$material = primitive.material) === null || _primitive$material === void 0 ? void 0 : _primitive$material.uniqueId);
|
|
249
|
+
})) === null || _outputAttributes$mer === void 0 ? void 0 : _outputAttributes$mer.uvRegion;
|
|
250
|
+
} else if (attributesMap.has('default')) {
|
|
251
|
+
outputAttributes = attributesMap.get('default');
|
|
252
|
+
}
|
|
253
|
+
(0, _core2.assert)(outputAttributes !== null, 'Primitive - material mapping failed');
|
|
254
|
+
const attributes = primitive.attributes;
|
|
255
|
+
if (!outputAttributes) {
|
|
256
|
+
continue;
|
|
423
257
|
}
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
258
|
+
const indices = getIndices(primitive);
|
|
259
|
+
outputAttributes.positions = (0, _loaderUtils.concatenateTypedArrays)(outputAttributes.positions, transformVertexArray({
|
|
260
|
+
vertices: attributes.POSITION.value,
|
|
261
|
+
cartographicOrigin,
|
|
262
|
+
cartesianModelMatrix,
|
|
263
|
+
nodeMatrix: matrix,
|
|
264
|
+
indices,
|
|
265
|
+
attributeSpecificTransformation: transformVertexPositions,
|
|
266
|
+
useCartesianPositions
|
|
267
|
+
}));
|
|
268
|
+
outputAttributes.normals = (0, _loaderUtils.concatenateTypedArrays)(outputAttributes.normals, transformVertexArray({
|
|
269
|
+
vertices: attributes.NORMAL && attributes.NORMAL.value,
|
|
270
|
+
cartographicOrigin,
|
|
271
|
+
cartesianModelMatrix,
|
|
272
|
+
nodeMatrix: matrix,
|
|
273
|
+
indices,
|
|
274
|
+
attributeSpecificTransformation: transformVertexNormals,
|
|
275
|
+
useCartesianPositions: false
|
|
276
|
+
}));
|
|
277
|
+
outputAttributes.texCoords = (0, _loaderUtils.concatenateTypedArrays)(outputAttributes.texCoords, flattenTexCoords(attributes.TEXCOORD_0 && attributes.TEXCOORD_0.value, indices));
|
|
278
|
+
outputAttributes.colors = (0, _loaderUtils.concatenateTypedArrays)(outputAttributes.colors, flattenColors(attributes.COLOR_0, indices));
|
|
279
|
+
if (materialUvRegion) {
|
|
280
|
+
outputAttributes.uvRegions = (0, _loaderUtils.concatenateTypedArrays)(outputAttributes.uvRegions, createUvRegion(materialUvRegion, indices));
|
|
281
|
+
}
|
|
282
|
+
outputAttributes.featureIndicesGroups = outputAttributes.featureIndicesGroups || [];
|
|
283
|
+
outputAttributes.featureIndicesGroups.push(flattenBatchIds(getBatchIds(attributes, primitive, images), indices));
|
|
428
284
|
}
|
|
429
285
|
}
|
|
430
286
|
function getIndices(primitive) {
|
|
431
287
|
var _primitive$indices;
|
|
432
|
-
|
|
288
|
+
let indices = (_primitive$indices = primitive.indices) === null || _primitive$indices === void 0 ? void 0 : _primitive$indices.value;
|
|
433
289
|
if (indices && primitive.mode === _math.GL.TRIANGLE_STRIP) {
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
290
|
+
const TypedArrayConstructor = indices.constructor;
|
|
291
|
+
const newIndices = new TypedArrayConstructor((indices.length - 2) * 3);
|
|
292
|
+
let triangleIndex = 0;
|
|
293
|
+
let currentTriangle = indices.slice(0, 3);
|
|
438
294
|
newIndices.set(currentTriangle, 0);
|
|
439
|
-
for (
|
|
295
|
+
for (let i = 1; i + 2 < indices.length; i++) {
|
|
440
296
|
triangleIndex += 3;
|
|
441
297
|
currentTriangle = indices.slice(i, i + 3);
|
|
442
298
|
if (i % 2 === 0) {
|
|
@@ -450,17 +306,19 @@ function getIndices(primitive) {
|
|
|
450
306
|
return indices;
|
|
451
307
|
}
|
|
452
308
|
function transformVertexArray(args) {
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
309
|
+
const {
|
|
310
|
+
vertices,
|
|
311
|
+
indices,
|
|
312
|
+
attributeSpecificTransformation
|
|
313
|
+
} = args;
|
|
314
|
+
const newVertices = new Float32Array(indices.length * VALUES_PER_VERTEX);
|
|
457
315
|
if (!vertices) {
|
|
458
316
|
return newVertices;
|
|
459
317
|
}
|
|
460
|
-
for (
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
318
|
+
for (let i = 0; i < indices.length; i++) {
|
|
319
|
+
const coordIndex = indices[i] * VALUES_PER_VERTEX;
|
|
320
|
+
const vertex = vertices.subarray(coordIndex, coordIndex + VALUES_PER_VERTEX);
|
|
321
|
+
let vertexVector = new _core.Vector3(Array.from(vertex));
|
|
464
322
|
vertexVector = attributeSpecificTransformation(vertexVector, args);
|
|
465
323
|
newVertices[i * VALUES_PER_VERTEX] = vertexVector.x;
|
|
466
324
|
newVertices[i * VALUES_PER_VERTEX + 1] = vertexVector.y;
|
|
@@ -469,10 +327,12 @@ function transformVertexArray(args) {
|
|
|
469
327
|
return newVertices;
|
|
470
328
|
}
|
|
471
329
|
function transformVertexPositions(vertexVector, calleeArgs) {
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
330
|
+
const {
|
|
331
|
+
cartesianModelMatrix,
|
|
332
|
+
cartographicOrigin,
|
|
333
|
+
nodeMatrix,
|
|
334
|
+
useCartesianPositions
|
|
335
|
+
} = calleeArgs;
|
|
476
336
|
if (nodeMatrix) {
|
|
477
337
|
vertexVector = vertexVector.transform(nodeMatrix);
|
|
478
338
|
}
|
|
@@ -485,8 +345,10 @@ function transformVertexPositions(vertexVector, calleeArgs) {
|
|
|
485
345
|
return vertexVector;
|
|
486
346
|
}
|
|
487
347
|
function transformVertexNormals(vertexVector, calleeArgs) {
|
|
488
|
-
|
|
489
|
-
|
|
348
|
+
const {
|
|
349
|
+
cartesianModelMatrix,
|
|
350
|
+
nodeMatrix
|
|
351
|
+
} = calleeArgs;
|
|
490
352
|
if (nodeMatrix) {
|
|
491
353
|
vertexVector = vertexVector.transformAsVector(nodeMatrix);
|
|
492
354
|
}
|
|
@@ -494,32 +356,32 @@ function transformVertexNormals(vertexVector, calleeArgs) {
|
|
|
494
356
|
return vertexVector;
|
|
495
357
|
}
|
|
496
358
|
function flattenTexCoords(texCoords, indices) {
|
|
497
|
-
|
|
359
|
+
const newTexCoords = new Float32Array(indices.length * VALUES_PER_TEX_COORD);
|
|
498
360
|
if (!texCoords) {
|
|
499
361
|
newTexCoords.fill(1);
|
|
500
362
|
return newTexCoords;
|
|
501
363
|
}
|
|
502
|
-
for (
|
|
503
|
-
|
|
504
|
-
|
|
364
|
+
for (let i = 0; i < indices.length; i++) {
|
|
365
|
+
const coordIndex = indices[i] * VALUES_PER_TEX_COORD;
|
|
366
|
+
const texCoord = texCoords.subarray(coordIndex, coordIndex + VALUES_PER_TEX_COORD);
|
|
505
367
|
newTexCoords[i * VALUES_PER_TEX_COORD] = texCoord[0];
|
|
506
368
|
newTexCoords[i * VALUES_PER_TEX_COORD + 1] = texCoord[1];
|
|
507
369
|
}
|
|
508
370
|
return newTexCoords;
|
|
509
371
|
}
|
|
510
372
|
function flattenColors(colorsAttribute, indices) {
|
|
511
|
-
|
|
512
|
-
|
|
373
|
+
const components = (colorsAttribute === null || colorsAttribute === void 0 ? void 0 : colorsAttribute.components) || VALUES_PER_COLOR_ELEMENT;
|
|
374
|
+
const newColors = new Uint8Array(indices.length * components);
|
|
513
375
|
if (!colorsAttribute) {
|
|
514
376
|
newColors.fill(255);
|
|
515
377
|
return newColors;
|
|
516
378
|
}
|
|
517
|
-
|
|
518
|
-
for (
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
for (
|
|
379
|
+
const colors = colorsAttribute.value;
|
|
380
|
+
for (let i = 0; i < indices.length; i++) {
|
|
381
|
+
const colorIndex = indices[i] * components;
|
|
382
|
+
const color = colors.subarray(colorIndex, colorIndex + components);
|
|
383
|
+
const colorUint8 = new Uint8Array(components);
|
|
384
|
+
for (let j = 0; j < color.length; j++) {
|
|
523
385
|
colorUint8[j] = color[j] * 255;
|
|
524
386
|
}
|
|
525
387
|
newColors.set(colorUint8, i * components);
|
|
@@ -527,8 +389,8 @@ function flattenColors(colorsAttribute, indices) {
|
|
|
527
389
|
return newColors;
|
|
528
390
|
}
|
|
529
391
|
function createUvRegion(materialUvRegion, indices) {
|
|
530
|
-
|
|
531
|
-
for (
|
|
392
|
+
const result = new Uint16Array(indices.length * 4);
|
|
393
|
+
for (let i = 0; i < result.length; i += 4) {
|
|
532
394
|
result.set(materialUvRegion, i);
|
|
533
395
|
}
|
|
534
396
|
return result;
|
|
@@ -537,239 +399,124 @@ function flattenBatchIds(batchedIds, indices) {
|
|
|
537
399
|
if (!batchedIds.length || !indices.length) {
|
|
538
400
|
return [];
|
|
539
401
|
}
|
|
540
|
-
|
|
541
|
-
for (
|
|
542
|
-
|
|
402
|
+
const newBatchIds = [];
|
|
403
|
+
for (let i = 0; i < indices.length; i++) {
|
|
404
|
+
const coordIndex = indices[i];
|
|
543
405
|
newBatchIds.push(batchedIds[coordIndex]);
|
|
544
406
|
}
|
|
545
407
|
return newBatchIds;
|
|
546
408
|
}
|
|
547
409
|
function getBatchIds(attributes, primitive, images) {
|
|
548
|
-
|
|
410
|
+
const batchIds = (0, _batchIdsExtensions.handleBatchIdsExtensions)(attributes, primitive, images);
|
|
549
411
|
if (batchIds.length) {
|
|
550
412
|
return batchIds;
|
|
551
413
|
}
|
|
552
|
-
for (
|
|
553
|
-
|
|
414
|
+
for (let index = 0; index < BATCHED_ID_POSSIBLE_ATTRIBUTE_NAMES.length; index++) {
|
|
415
|
+
const possibleBatchIdAttributeName = BATCHED_ID_POSSIBLE_ATTRIBUTE_NAMES[index];
|
|
554
416
|
if (attributes[possibleBatchIdAttributeName] && attributes[possibleBatchIdAttributeName].value) {
|
|
555
417
|
return attributes[possibleBatchIdAttributeName].value;
|
|
556
418
|
}
|
|
557
419
|
}
|
|
558
420
|
return [];
|
|
559
421
|
}
|
|
560
|
-
function convertMaterials() {
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
materials.push(convertMaterial(sourceMaterial));
|
|
583
|
-
}
|
|
584
|
-
} catch (err) {
|
|
585
|
-
_iterator10.e(err);
|
|
586
|
-
} finally {
|
|
587
|
-
_iterator10.f();
|
|
588
|
-
}
|
|
589
|
-
if (!shouldMergeMaterials) {
|
|
590
|
-
_context4.next = 9;
|
|
591
|
-
break;
|
|
592
|
-
}
|
|
593
|
-
_context4.next = 8;
|
|
594
|
-
return mergeAllMaterials(materials);
|
|
595
|
-
case 8:
|
|
596
|
-
materials = _context4.sent;
|
|
597
|
-
case 9:
|
|
598
|
-
return _context4.abrupt("return", materials);
|
|
599
|
-
case 10:
|
|
600
|
-
case "end":
|
|
601
|
-
return _context4.stop();
|
|
422
|
+
async function convertMaterials() {
|
|
423
|
+
let sourceMaterials = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
|
424
|
+
let shouldMergeMaterials = arguments.length > 1 ? arguments[1] : undefined;
|
|
425
|
+
let materials = [];
|
|
426
|
+
for (const sourceMaterial of sourceMaterials) {
|
|
427
|
+
materials.push(convertMaterial(sourceMaterial));
|
|
428
|
+
}
|
|
429
|
+
if (shouldMergeMaterials) {
|
|
430
|
+
materials = await mergeAllMaterials(materials);
|
|
431
|
+
}
|
|
432
|
+
return materials;
|
|
433
|
+
}
|
|
434
|
+
async function mergeAllMaterials(materials) {
|
|
435
|
+
const result = [];
|
|
436
|
+
while (materials.length > 0) {
|
|
437
|
+
let newMaterial = materials.splice(0, 1)[0];
|
|
438
|
+
const mergedIndices = [];
|
|
439
|
+
for (let i = 0; i < materials.length; i++) {
|
|
440
|
+
const material = materials[i];
|
|
441
|
+
if (newMaterial.texture && material.texture || !newMaterial.texture && !material.texture) {
|
|
442
|
+
newMaterial = await mergeMaterials(newMaterial, material);
|
|
443
|
+
mergedIndices.push(i);
|
|
602
444
|
}
|
|
603
|
-
}
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
}
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
case 5:
|
|
626
|
-
if (!(i < materials.length)) {
|
|
627
|
-
_context5.next = 15;
|
|
628
|
-
break;
|
|
629
|
-
}
|
|
630
|
-
material = materials[i];
|
|
631
|
-
if (!(newMaterial.texture && material.texture || !newMaterial.texture && !material.texture)) {
|
|
632
|
-
_context5.next = 12;
|
|
633
|
-
break;
|
|
634
|
-
}
|
|
635
|
-
_context5.next = 10;
|
|
636
|
-
return mergeMaterials(newMaterial, material);
|
|
637
|
-
case 10:
|
|
638
|
-
newMaterial = _context5.sent;
|
|
639
|
-
mergedIndices.push(i);
|
|
640
|
-
case 12:
|
|
641
|
-
i++;
|
|
642
|
-
_context5.next = 5;
|
|
643
|
-
break;
|
|
644
|
-
case 15:
|
|
645
|
-
if (newMaterial.texture && mergedIndices.length) {
|
|
646
|
-
newWidth = (_newMaterial$mergedMa = newMaterial.mergedMaterials) === null || _newMaterial$mergedMa === void 0 ? void 0 : _newMaterial$mergedMa.reduce(function (accum, _ref4) {
|
|
647
|
-
var textureSize = _ref4.textureSize;
|
|
648
|
-
return accum + ((textureSize === null || textureSize === void 0 ? void 0 : textureSize.width) || 0);
|
|
649
|
-
}, 0);
|
|
650
|
-
newHeight = (_newMaterial$mergedMa2 = newMaterial.mergedMaterials) === null || _newMaterial$mergedMa2 === void 0 ? void 0 : _newMaterial$mergedMa2.reduce(function (accum, _ref5) {
|
|
651
|
-
var textureSize = _ref5.textureSize;
|
|
652
|
-
return Math.max(accum, (textureSize === null || textureSize === void 0 ? void 0 : textureSize.height) || 0);
|
|
653
|
-
}, 0);
|
|
654
|
-
currentX = -1;
|
|
655
|
-
_iterator11 = _createForOfIteratorHelper(newMaterial.mergedMaterials);
|
|
656
|
-
try {
|
|
657
|
-
for (_iterator11.s(); !(_step11 = _iterator11.n()).done;) {
|
|
658
|
-
aTextureMetadata = _step11.value;
|
|
659
|
-
if (aTextureMetadata.textureSize) {
|
|
660
|
-
newX = currentX + 1 + aTextureMetadata.textureSize.width / newWidth * Math.pow(2, Uint16Array.BYTES_PER_ELEMENT * 8) - 1;
|
|
661
|
-
aTextureMetadata.uvRegion = new Uint16Array([currentX + 1, 0, newX, aTextureMetadata.textureSize.height / newHeight * Math.pow(2, Uint16Array.BYTES_PER_ELEMENT * 8) - 1]);
|
|
662
|
-
currentX = newX;
|
|
663
|
-
}
|
|
664
|
-
}
|
|
665
|
-
} catch (err) {
|
|
666
|
-
_iterator11.e(err);
|
|
667
|
-
} finally {
|
|
668
|
-
_iterator11.f();
|
|
669
|
-
}
|
|
670
|
-
newMaterial.texture.image.width = newWidth;
|
|
671
|
-
newMaterial.texture.image.height = newHeight;
|
|
672
|
-
}
|
|
673
|
-
_iterator12 = _createForOfIteratorHelper(mergedIndices.reverse());
|
|
674
|
-
try {
|
|
675
|
-
for (_iterator12.s(); !(_step12 = _iterator12.n()).done;) {
|
|
676
|
-
index = _step12.value;
|
|
677
|
-
materials.splice(index, 1);
|
|
678
|
-
}
|
|
679
|
-
} catch (err) {
|
|
680
|
-
_iterator12.e(err);
|
|
681
|
-
} finally {
|
|
682
|
-
_iterator12.f();
|
|
683
|
-
}
|
|
684
|
-
result.push(newMaterial);
|
|
685
|
-
_context5.next = 1;
|
|
686
|
-
break;
|
|
687
|
-
case 21:
|
|
688
|
-
if (!result.length) {
|
|
689
|
-
result.push({
|
|
690
|
-
material: getDefaultMaterial(),
|
|
691
|
-
mergedMaterials: [{
|
|
692
|
-
originalMaterialId: 'default'
|
|
693
|
-
}]
|
|
694
|
-
});
|
|
695
|
-
}
|
|
696
|
-
return _context5.abrupt("return", result);
|
|
697
|
-
case 23:
|
|
698
|
-
case "end":
|
|
699
|
-
return _context5.stop();
|
|
445
|
+
}
|
|
446
|
+
if (newMaterial.texture && mergedIndices.length) {
|
|
447
|
+
var _newMaterial$mergedMa, _newMaterial$mergedMa2;
|
|
448
|
+
const newWidth = (_newMaterial$mergedMa = newMaterial.mergedMaterials) === null || _newMaterial$mergedMa === void 0 ? void 0 : _newMaterial$mergedMa.reduce((accum, _ref3) => {
|
|
449
|
+
let {
|
|
450
|
+
textureSize
|
|
451
|
+
} = _ref3;
|
|
452
|
+
return accum + ((textureSize === null || textureSize === void 0 ? void 0 : textureSize.width) || 0);
|
|
453
|
+
}, 0);
|
|
454
|
+
const newHeight = (_newMaterial$mergedMa2 = newMaterial.mergedMaterials) === null || _newMaterial$mergedMa2 === void 0 ? void 0 : _newMaterial$mergedMa2.reduce((accum, _ref4) => {
|
|
455
|
+
let {
|
|
456
|
+
textureSize
|
|
457
|
+
} = _ref4;
|
|
458
|
+
return Math.max(accum, (textureSize === null || textureSize === void 0 ? void 0 : textureSize.height) || 0);
|
|
459
|
+
}, 0);
|
|
460
|
+
let currentX = -1;
|
|
461
|
+
for (const aTextureMetadata of newMaterial.mergedMaterials) {
|
|
462
|
+
if (aTextureMetadata.textureSize) {
|
|
463
|
+
const newX = currentX + 1 + aTextureMetadata.textureSize.width / newWidth * 2 ** (Uint16Array.BYTES_PER_ELEMENT * 8) - 1;
|
|
464
|
+
aTextureMetadata.uvRegion = new Uint16Array([currentX + 1, 0, newX, aTextureMetadata.textureSize.height / newHeight * 2 ** (Uint16Array.BYTES_PER_ELEMENT * 8) - 1]);
|
|
465
|
+
currentX = newX;
|
|
466
|
+
}
|
|
700
467
|
}
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
468
|
+
newMaterial.texture.image.width = newWidth;
|
|
469
|
+
newMaterial.texture.image.height = newHeight;
|
|
470
|
+
}
|
|
471
|
+
for (const index of mergedIndices.reverse()) {
|
|
472
|
+
materials.splice(index, 1);
|
|
473
|
+
}
|
|
474
|
+
result.push(newMaterial);
|
|
475
|
+
}
|
|
476
|
+
if (!result.length) {
|
|
477
|
+
result.push({
|
|
478
|
+
material: getDefaultMaterial(),
|
|
479
|
+
mergedMaterials: [{
|
|
480
|
+
originalMaterialId: 'default'
|
|
481
|
+
}]
|
|
482
|
+
});
|
|
483
|
+
}
|
|
484
|
+
return result;
|
|
707
485
|
}
|
|
708
|
-
function
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
_context6.next = 10;
|
|
730
|
-
return joinImages([buffer1, buffer2], {
|
|
731
|
-
direction: 'horizontal'
|
|
732
|
-
});
|
|
733
|
-
case 10:
|
|
734
|
-
sharpData = _context6.sent;
|
|
735
|
-
_context6.next = 13;
|
|
736
|
-
return sharpData.toFormat(material1.texture.mimeType === 'image/png' ? 'png' : 'jpeg').toBuffer();
|
|
737
|
-
case 13:
|
|
738
|
-
material1.texture.bufferView.data = _context6.sent;
|
|
739
|
-
_context6.next = 20;
|
|
740
|
-
break;
|
|
741
|
-
case 16:
|
|
742
|
-
_context6.prev = 16;
|
|
743
|
-
_context6.t0 = _context6["catch"](3);
|
|
744
|
-
console.log('Join images into a texture atlas has failed. Consider usage `--split-nodes` option. (See documentation https://loaders.gl/modules/tile-converter/docs/cli-reference/tile-converter)');
|
|
745
|
-
throw _context6.t0;
|
|
746
|
-
case 20:
|
|
747
|
-
material1.material.pbrMetallicRoughness.baseColorTexture.textureSetDefinitionId = 1;
|
|
748
|
-
case 21:
|
|
749
|
-
material1.mergedMaterials = material1.mergedMaterials.concat(material2.mergedMaterials);
|
|
750
|
-
return _context6.abrupt("return", material1);
|
|
751
|
-
case 23:
|
|
752
|
-
case "end":
|
|
753
|
-
return _context6.stop();
|
|
754
|
-
}
|
|
755
|
-
}, _callee6, null, [[3, 16]]);
|
|
756
|
-
}));
|
|
757
|
-
return _mergeMaterials.apply(this, arguments);
|
|
486
|
+
async function mergeMaterials(material1, material2) {
|
|
487
|
+
var _material1$texture, _material2$texture;
|
|
488
|
+
if ((_material1$texture = material1.texture) !== null && _material1$texture !== void 0 && _material1$texture.bufferView && (_material2$texture = material2.texture) !== null && _material2$texture !== void 0 && _material2$texture.bufferView && material1.mergedMaterials && material2.mergedMaterials) {
|
|
489
|
+
const buffer1 = Buffer.from(material1.texture.bufferView.data);
|
|
490
|
+
const buffer2 = Buffer.from(material2.texture.bufferView.data);
|
|
491
|
+
try {
|
|
492
|
+
const {
|
|
493
|
+
joinImages
|
|
494
|
+
} = await Promise.resolve().then(() => _interopRequireWildcard(require('join-images')));
|
|
495
|
+
const sharpData = await joinImages([buffer1, buffer2], {
|
|
496
|
+
direction: 'horizontal'
|
|
497
|
+
});
|
|
498
|
+
material1.texture.bufferView.data = await sharpData.toFormat(material1.texture.mimeType === 'image/png' ? 'png' : 'jpeg').toBuffer();
|
|
499
|
+
} catch (error) {
|
|
500
|
+
console.log('Join images into a texture atlas has failed. Consider usage `--split-nodes` option. (See documentation https://loaders.gl/modules/tile-converter/docs/cli-reference/tile-converter)');
|
|
501
|
+
throw error;
|
|
502
|
+
}
|
|
503
|
+
material1.material.pbrMetallicRoughness.baseColorTexture.textureSetDefinitionId = 1;
|
|
504
|
+
}
|
|
505
|
+
material1.mergedMaterials = material1.mergedMaterials.concat(material2.mergedMaterials);
|
|
506
|
+
return material1;
|
|
758
507
|
}
|
|
759
508
|
function convertMaterial(sourceMaterial) {
|
|
760
509
|
var _sourceMaterial$emiss, _sourceMaterial$pbrMe, _sourceMaterial$pbrMe2, _sourceMaterial$pbrMe3;
|
|
761
|
-
|
|
510
|
+
const material = {
|
|
762
511
|
doubleSided: sourceMaterial.doubleSided,
|
|
763
|
-
emissiveFactor: (_sourceMaterial$emiss = sourceMaterial.emissiveFactor) === null || _sourceMaterial$emiss === void 0 ? void 0 : _sourceMaterial$emiss.map(
|
|
764
|
-
return Math.round(c * 255);
|
|
765
|
-
}),
|
|
512
|
+
emissiveFactor: (_sourceMaterial$emiss = sourceMaterial.emissiveFactor) === null || _sourceMaterial$emiss === void 0 ? void 0 : _sourceMaterial$emiss.map(c => Math.round(c * 255)),
|
|
766
513
|
alphaMode: convertAlphaMode(sourceMaterial.alphaMode),
|
|
767
514
|
pbrMetallicRoughness: {
|
|
768
515
|
roughnessFactor: (sourceMaterial === null || sourceMaterial === void 0 ? void 0 : (_sourceMaterial$pbrMe = sourceMaterial.pbrMetallicRoughness) === null || _sourceMaterial$pbrMe === void 0 ? void 0 : _sourceMaterial$pbrMe.roughnessFactor) || DEFAULT_ROUGHNESS_FACTOR,
|
|
769
516
|
metallicFactor: (sourceMaterial === null || sourceMaterial === void 0 ? void 0 : (_sourceMaterial$pbrMe2 = sourceMaterial.pbrMetallicRoughness) === null || _sourceMaterial$pbrMe2 === void 0 ? void 0 : _sourceMaterial$pbrMe2.metallicFactor) || DEFAULT_METALLIC_FACTOR
|
|
770
517
|
}
|
|
771
518
|
};
|
|
772
|
-
|
|
519
|
+
let texture;
|
|
773
520
|
if (sourceMaterial !== null && sourceMaterial !== void 0 && (_sourceMaterial$pbrMe3 = sourceMaterial.pbrMetallicRoughness) !== null && _sourceMaterial$pbrMe3 !== void 0 && _sourceMaterial$pbrMe3.baseColorTexture) {
|
|
774
521
|
texture = sourceMaterial.pbrMetallicRoughness.baseColorTexture.texture.source;
|
|
775
522
|
material.pbrMetallicRoughness.baseColorTexture = {
|
|
@@ -781,17 +528,15 @@ function convertMaterial(sourceMaterial) {
|
|
|
781
528
|
textureSetDefinitionId: 0
|
|
782
529
|
};
|
|
783
530
|
}
|
|
784
|
-
|
|
531
|
+
const uniqueId = (0, _uuid.v4)();
|
|
785
532
|
sourceMaterial.uniqueId = uniqueId;
|
|
786
|
-
|
|
533
|
+
let mergedMaterials = [{
|
|
787
534
|
originalMaterialId: uniqueId
|
|
788
535
|
}];
|
|
789
536
|
if (!texture) {
|
|
790
537
|
var _sourceMaterial$pbrMe4;
|
|
791
|
-
|
|
792
|
-
material.pbrMetallicRoughness.baseColorFactor = baseColorFactor && baseColorFactor.map(
|
|
793
|
-
return Math.round(c * 255);
|
|
794
|
-
}) || undefined;
|
|
538
|
+
const baseColorFactor = sourceMaterial === null || sourceMaterial === void 0 ? void 0 : (_sourceMaterial$pbrMe4 = sourceMaterial.pbrMetallicRoughness) === null || _sourceMaterial$pbrMe4 === void 0 ? void 0 : _sourceMaterial$pbrMe4.baseColorFactor;
|
|
539
|
+
material.pbrMetallicRoughness.baseColorFactor = baseColorFactor && baseColorFactor.map(c => Math.round(c * 255)) || undefined;
|
|
795
540
|
} else {
|
|
796
541
|
mergedMaterials[0].textureSize = {
|
|
797
542
|
width: texture.image.width,
|
|
@@ -799,9 +544,9 @@ function convertMaterial(sourceMaterial) {
|
|
|
799
544
|
};
|
|
800
545
|
}
|
|
801
546
|
return {
|
|
802
|
-
material
|
|
803
|
-
texture
|
|
804
|
-
mergedMaterials
|
|
547
|
+
material,
|
|
548
|
+
texture,
|
|
549
|
+
mergedMaterials
|
|
805
550
|
};
|
|
806
551
|
}
|
|
807
552
|
function convertAlphaMode(gltfAlphaMode) {
|
|
@@ -826,63 +571,56 @@ function getDefaultMaterial() {
|
|
|
826
571
|
};
|
|
827
572
|
}
|
|
828
573
|
function getSharedResources(gltfMaterials, nodeId) {
|
|
829
|
-
|
|
574
|
+
const i3sResources = {};
|
|
830
575
|
if (!gltfMaterials || !gltfMaterials.length) {
|
|
831
576
|
return i3sResources;
|
|
832
577
|
}
|
|
833
578
|
i3sResources.materialDefinitionInfos = [];
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
i3sResources.
|
|
843
|
-
if (textureDefinitionInfo) {
|
|
844
|
-
i3sResources.textureDefinitionInfos = i3sResources.textureDefinitionInfos || [];
|
|
845
|
-
i3sResources.textureDefinitionInfos.push(textureDefinitionInfo);
|
|
846
|
-
}
|
|
579
|
+
for (const gltfMaterial of gltfMaterials) {
|
|
580
|
+
const {
|
|
581
|
+
materialDefinitionInfo,
|
|
582
|
+
textureDefinitionInfo
|
|
583
|
+
} = convertGLTFMaterialToI3sSharedResources(gltfMaterial, nodeId);
|
|
584
|
+
i3sResources.materialDefinitionInfos.push(materialDefinitionInfo);
|
|
585
|
+
if (textureDefinitionInfo) {
|
|
586
|
+
i3sResources.textureDefinitionInfos = i3sResources.textureDefinitionInfos || [];
|
|
587
|
+
i3sResources.textureDefinitionInfos.push(textureDefinitionInfo);
|
|
847
588
|
}
|
|
848
|
-
} catch (err) {
|
|
849
|
-
_iterator4.e(err);
|
|
850
|
-
} finally {
|
|
851
|
-
_iterator4.f();
|
|
852
589
|
}
|
|
853
590
|
return i3sResources;
|
|
854
591
|
}
|
|
855
592
|
function convertGLTFMaterialToI3sSharedResources(gltfMaterial, nodeId) {
|
|
856
593
|
var _gltfMaterial$pbrMeta;
|
|
857
|
-
|
|
858
|
-
|
|
594
|
+
const texture = (gltfMaterial === null || gltfMaterial === void 0 ? void 0 : (_gltfMaterial$pbrMeta = gltfMaterial.pbrMetallicRoughness) === null || _gltfMaterial$pbrMeta === void 0 ? void 0 : _gltfMaterial$pbrMeta.baseColorTexture) || gltfMaterial.emissiveTexture;
|
|
595
|
+
let textureDefinitionInfo = null;
|
|
859
596
|
if (texture) {
|
|
860
597
|
textureDefinitionInfo = extractSharedResourcesTextureInfo(texture.texture, nodeId);
|
|
861
598
|
}
|
|
862
|
-
|
|
863
|
-
baseColorFactor
|
|
864
|
-
metallicFactor
|
|
865
|
-
|
|
599
|
+
const {
|
|
600
|
+
baseColorFactor,
|
|
601
|
+
metallicFactor
|
|
602
|
+
} = (gltfMaterial === null || gltfMaterial === void 0 ? void 0 : gltfMaterial.pbrMetallicRoughness) || {};
|
|
603
|
+
let colorFactor = baseColorFactor;
|
|
866
604
|
if ((!baseColorFactor || baseColorFactor[3] === 0) && gltfMaterial.emissiveFactor) {
|
|
867
605
|
colorFactor = gltfMaterial.emissiveFactor;
|
|
868
606
|
colorFactor[3] = colorFactor[3] || 1;
|
|
869
607
|
}
|
|
870
608
|
return {
|
|
871
609
|
materialDefinitionInfo: extractSharedResourcesMaterialInfo(colorFactor || [1, 1, 1, 1], metallicFactor),
|
|
872
|
-
textureDefinitionInfo
|
|
610
|
+
textureDefinitionInfo
|
|
873
611
|
};
|
|
874
612
|
}
|
|
875
613
|
function extractSharedResourcesMaterialInfo(baseColorFactor) {
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
614
|
+
let metallicFactor = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
|
|
615
|
+
const matDielectricColorComponent = 0.04 / 255;
|
|
616
|
+
const black = new _core.Vector4(0, 0, 0, 1);
|
|
617
|
+
const unitVector = new _core.Vector4(1, 1, 1, 1);
|
|
618
|
+
const dielectricSpecular = new _core.Vector4(matDielectricColorComponent, matDielectricColorComponent, matDielectricColorComponent, 0);
|
|
619
|
+
const baseColorVector = new _core.Vector4(baseColorFactor);
|
|
620
|
+
const firstOperand = unitVector.subtract(dielectricSpecular).multiply(baseColorVector);
|
|
621
|
+
const diffuse = firstOperand.lerp(firstOperand, black, metallicFactor);
|
|
884
622
|
dielectricSpecular[3] = 1;
|
|
885
|
-
|
|
623
|
+
const specular = dielectricSpecular.lerp(dielectricSpecular, baseColorVector, metallicFactor);
|
|
886
624
|
return {
|
|
887
625
|
params: {
|
|
888
626
|
diffuse: diffuse.toArray(),
|
|
@@ -904,73 +642,75 @@ function extractSharedResourcesTextureInfo(texture, nodeId) {
|
|
|
904
642
|
}
|
|
905
643
|
function generateImageId(texture, nodeId) {
|
|
906
644
|
var _texture$source4;
|
|
907
|
-
|
|
908
|
-
width
|
|
909
|
-
height
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
645
|
+
const {
|
|
646
|
+
width,
|
|
647
|
+
height
|
|
648
|
+
} = (_texture$source4 = texture.source) === null || _texture$source4 === void 0 ? void 0 : _texture$source4.image;
|
|
649
|
+
const levelCountOfTexture = 1;
|
|
650
|
+
const indexOfLevel = 0;
|
|
651
|
+
const indexOfTextureInStore = nodeId + 1;
|
|
652
|
+
const zerosCount = 32 - indexOfTextureInStore.toString(2).length;
|
|
653
|
+
const rightHalf = '0'.repeat(zerosCount).concat(indexOfTextureInStore.toString(2));
|
|
654
|
+
const shiftedLevelCountOfTexture = levelCountOfTexture << 28;
|
|
655
|
+
const shiftedIndexOfLevel = indexOfLevel << 24;
|
|
656
|
+
const shiftedWidth = width - 1 << 12;
|
|
657
|
+
const shiftedHeight = height - 1 << 0;
|
|
658
|
+
const leftHalf = shiftedLevelCountOfTexture + shiftedIndexOfLevel + shiftedWidth + shiftedHeight;
|
|
659
|
+
const imageId = BigInt("0b".concat(leftHalf.toString(2)).concat(rightHalf));
|
|
921
660
|
return imageId.toString();
|
|
922
661
|
}
|
|
923
662
|
function makeFeatureIdsUnique(featureIds, featureIndices, featuresHashArray, batchTable) {
|
|
924
|
-
|
|
663
|
+
const replaceMap = getFeaturesReplaceMap(featureIds, batchTable, featuresHashArray);
|
|
925
664
|
replaceIndicesByUnique(featureIndices, replaceMap);
|
|
926
665
|
replaceIndicesByUnique(featureIds, replaceMap);
|
|
927
666
|
}
|
|
928
667
|
function getFeaturesReplaceMap(featureIds, batchTable, featuresHashArray) {
|
|
929
|
-
|
|
930
|
-
for (
|
|
931
|
-
|
|
932
|
-
|
|
668
|
+
const featureMap = {};
|
|
669
|
+
for (let index = 0; index < featureIds.length; index++) {
|
|
670
|
+
const oldFeatureId = featureIds[index];
|
|
671
|
+
const uniqueFeatureId = getOrCreateUniqueFeatureId(index, batchTable, featuresHashArray);
|
|
933
672
|
featureMap[oldFeatureId.toString()] = uniqueFeatureId;
|
|
934
673
|
}
|
|
935
674
|
return featureMap;
|
|
936
675
|
}
|
|
937
676
|
function generateStringFromBatchTableByIndex(batchTable, index) {
|
|
938
|
-
|
|
939
|
-
for (
|
|
940
|
-
str += batchTable[
|
|
677
|
+
let str = '';
|
|
678
|
+
for (const key in batchTable) {
|
|
679
|
+
str += batchTable[key][index];
|
|
941
680
|
}
|
|
942
681
|
return str;
|
|
943
682
|
}
|
|
944
683
|
function getOrCreateUniqueFeatureId(index, batchTable, featuresHashArray) {
|
|
945
|
-
|
|
946
|
-
|
|
684
|
+
const batchTableStr = generateStringFromBatchTableByIndex(batchTable, index);
|
|
685
|
+
const hash = (0, _md.default)(batchTableStr);
|
|
947
686
|
if (featuresHashArray.includes(hash)) {
|
|
948
687
|
return featuresHashArray.indexOf(hash);
|
|
949
688
|
}
|
|
950
689
|
return featuresHashArray.push(hash) - 1;
|
|
951
690
|
}
|
|
952
691
|
function replaceIndicesByUnique(indicesArray, featureMap) {
|
|
953
|
-
for (
|
|
692
|
+
for (let index = 0; index < indicesArray.length; index++) {
|
|
954
693
|
indicesArray[index] = featureMap[indicesArray[index]];
|
|
955
694
|
}
|
|
956
695
|
}
|
|
957
696
|
function convertPropertyTableToAttributeBuffers(featureIds, propertyTable, attributeStorageInfo) {
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
OBJECTID: featureIds
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
697
|
+
const attributeBuffers = [];
|
|
698
|
+
const needFlattenPropertyTable = (0, _featureAttributes.checkPropertiesLength)(featureIds, propertyTable);
|
|
699
|
+
const properties = needFlattenPropertyTable ? (0, _featureAttributes.flattenPropertyTableByFeatureIds)(featureIds, propertyTable) : propertyTable;
|
|
700
|
+
const propertyTableWithObjectIds = {
|
|
701
|
+
OBJECTID: featureIds,
|
|
702
|
+
...properties
|
|
703
|
+
};
|
|
704
|
+
for (const propertyName in propertyTableWithObjectIds) {
|
|
705
|
+
const type = getAttributeType(propertyName, attributeStorageInfo);
|
|
706
|
+
const value = propertyTableWithObjectIds[propertyName];
|
|
707
|
+
const attributeBuffer = generateAttributeBuffer(type, value);
|
|
968
708
|
attributeBuffers.push(attributeBuffer);
|
|
969
709
|
}
|
|
970
710
|
return attributeBuffers;
|
|
971
711
|
}
|
|
972
712
|
function generateAttributeBuffer(type, value) {
|
|
973
|
-
|
|
713
|
+
let attributeBuffer;
|
|
974
714
|
switch (type) {
|
|
975
715
|
case OBJECT_ID_TYPE:
|
|
976
716
|
case SHORT_INT_TYPE:
|
|
@@ -988,108 +728,100 @@ function generateAttributeBuffer(type, value) {
|
|
|
988
728
|
return attributeBuffer;
|
|
989
729
|
}
|
|
990
730
|
function getAttributeType(key, attributeStorageInfo) {
|
|
991
|
-
|
|
992
|
-
return attr.name === key;
|
|
993
|
-
});
|
|
731
|
+
const attribute = attributeStorageInfo.find(attr => attr.name === key);
|
|
994
732
|
return attribute.attributeValues.valueType;
|
|
995
733
|
}
|
|
996
734
|
function generateShortIntegerAttributeBuffer(featureIds) {
|
|
997
|
-
|
|
998
|
-
|
|
735
|
+
const count = new Uint32Array([featureIds.length]);
|
|
736
|
+
const valuesArray = new Uint32Array(featureIds);
|
|
999
737
|
return (0, _loaderUtils.concatenateArrayBuffers)(count.buffer, valuesArray.buffer);
|
|
1000
738
|
}
|
|
1001
739
|
function generateDoubleAttributeBuffer(featureIds) {
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
740
|
+
const count = new Uint32Array([featureIds.length]);
|
|
741
|
+
const padding = new Uint8Array(4);
|
|
742
|
+
const valuesArray = new Float64Array(featureIds);
|
|
1005
743
|
return (0, _loaderUtils.concatenateArrayBuffers)(count.buffer, padding.buffer, valuesArray.buffer);
|
|
1006
744
|
}
|
|
1007
745
|
function generateStringAttributeBuffer(batchAttributes) {
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
for (
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
746
|
+
const stringCountArray = new Uint32Array([batchAttributes.length]);
|
|
747
|
+
let totalNumberOfBytes = 0;
|
|
748
|
+
const stringSizesArray = new Uint32Array(batchAttributes.length);
|
|
749
|
+
const stringBufferArray = [];
|
|
750
|
+
for (let index = 0; index < batchAttributes.length; index++) {
|
|
751
|
+
const currentString = "".concat(String(batchAttributes[index]), "\0");
|
|
752
|
+
const currentStringBuffer = Buffer.from(currentString);
|
|
753
|
+
const currentStringSize = currentStringBuffer.length;
|
|
1016
754
|
totalNumberOfBytes += currentStringSize;
|
|
1017
755
|
stringSizesArray[index] = currentStringSize;
|
|
1018
756
|
stringBufferArray.push(currentStringBuffer);
|
|
1019
757
|
}
|
|
1020
|
-
|
|
1021
|
-
return _loaderUtils.concatenateArrayBuffers
|
|
758
|
+
const totalBytes = new Uint32Array([totalNumberOfBytes]);
|
|
759
|
+
return (0, _loaderUtils.concatenateArrayBuffers)(stringCountArray.buffer, totalBytes.buffer, stringSizesArray.buffer, ...stringBufferArray);
|
|
1022
760
|
}
|
|
1023
761
|
function generateBigUint64Array(featureIds) {
|
|
1024
|
-
|
|
1025
|
-
for (
|
|
762
|
+
const typedFeatureIds = new BigUint64Array(featureIds.length);
|
|
763
|
+
for (let index = 0; index < featureIds.length; index++) {
|
|
1026
764
|
typedFeatureIds[index] = BigInt(featureIds[index]);
|
|
1027
765
|
}
|
|
1028
766
|
return typedFeatureIds;
|
|
1029
767
|
}
|
|
1030
|
-
function generateCompressedGeometry(
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
case "end":
|
|
1081
|
-
return _context7.stop();
|
|
1082
|
-
}
|
|
1083
|
-
}, _callee7);
|
|
1084
|
-
}));
|
|
1085
|
-
return _generateCompressedGeometry.apply(this, arguments);
|
|
768
|
+
async function generateCompressedGeometry(vertexCount, convertedAttributes, attributes, dracoWorkerSoure) {
|
|
769
|
+
const {
|
|
770
|
+
positions,
|
|
771
|
+
normals,
|
|
772
|
+
texCoords,
|
|
773
|
+
colors,
|
|
774
|
+
uvRegions,
|
|
775
|
+
featureIds,
|
|
776
|
+
faceRange
|
|
777
|
+
} = attributes;
|
|
778
|
+
const indices = new Uint32Array(vertexCount);
|
|
779
|
+
for (let index = 0; index < indices.length; index++) {
|
|
780
|
+
indices.set([index], index);
|
|
781
|
+
}
|
|
782
|
+
const featureIndices = new Uint32Array(convertedAttributes.featureIndices.length ? convertedAttributes.featureIndices : vertexCount);
|
|
783
|
+
const featureIndex = generateFeatureIndexAttribute(featureIndices, faceRange);
|
|
784
|
+
const compressedAttributes = {
|
|
785
|
+
positions,
|
|
786
|
+
normals,
|
|
787
|
+
colors,
|
|
788
|
+
'feature-index': featureIndex
|
|
789
|
+
};
|
|
790
|
+
if (texCoords.length) {
|
|
791
|
+
compressedAttributes.texCoords = texCoords;
|
|
792
|
+
}
|
|
793
|
+
const attributesMetadata = {
|
|
794
|
+
'feature-index': {
|
|
795
|
+
'i3s-attribute-type': 'feature-index',
|
|
796
|
+
'i3s-feature-ids': new Int32Array(featureIds)
|
|
797
|
+
}
|
|
798
|
+
};
|
|
799
|
+
if (uvRegions.length) {
|
|
800
|
+
compressedAttributes['uv-region'] = uvRegions;
|
|
801
|
+
attributesMetadata['uv-region'] = {
|
|
802
|
+
'i3s-attribute-type': 'uv-region'
|
|
803
|
+
};
|
|
804
|
+
}
|
|
805
|
+
return (0, _core2.encode)({
|
|
806
|
+
attributes: compressedAttributes,
|
|
807
|
+
indices
|
|
808
|
+
}, _draco.DracoWriterWorker, {
|
|
809
|
+
..._draco.DracoWriterWorker.options,
|
|
810
|
+
source: dracoWorkerSoure,
|
|
811
|
+
reuseWorkers: true,
|
|
812
|
+
_nodeWorkers: true,
|
|
813
|
+
draco: {
|
|
814
|
+
method: 'MESH_SEQUENTIAL_ENCODING',
|
|
815
|
+
attributesMetadata
|
|
816
|
+
}
|
|
817
|
+
});
|
|
1086
818
|
}
|
|
1087
819
|
function generateFeatureIndexAttribute(featureIndex, faceRange) {
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
for (
|
|
1092
|
-
|
|
820
|
+
const orderedFeatureIndices = new Uint32Array(featureIndex.length);
|
|
821
|
+
let fillIndex = 0;
|
|
822
|
+
let startIndex = 0;
|
|
823
|
+
for (let index = 1; index < faceRange.length; index += 2) {
|
|
824
|
+
const endIndex = (faceRange[index] + 1) * VALUES_PER_VERTEX;
|
|
1093
825
|
orderedFeatureIndices.fill(fillIndex, startIndex, endIndex);
|
|
1094
826
|
fillIndex++;
|
|
1095
827
|
startIndex = endIndex + 1;
|
|
@@ -1097,13 +829,14 @@ function generateFeatureIndexAttribute(featureIndex, faceRange) {
|
|
|
1097
829
|
return orderedFeatureIndices;
|
|
1098
830
|
}
|
|
1099
831
|
function getPropertyTable(tileContent) {
|
|
1100
|
-
|
|
832
|
+
const batchTableJson = tileContent === null || tileContent === void 0 ? void 0 : tileContent.batchTableJson;
|
|
1101
833
|
if (batchTableJson) {
|
|
1102
834
|
return batchTableJson;
|
|
1103
835
|
}
|
|
1104
|
-
|
|
1105
|
-
extensionName
|
|
1106
|
-
extension
|
|
836
|
+
const {
|
|
837
|
+
extensionName,
|
|
838
|
+
extension
|
|
839
|
+
} = getPropertyTableExtension(tileContent);
|
|
1107
840
|
switch (extensionName) {
|
|
1108
841
|
case EXT_MESH_FEATURES:
|
|
1109
842
|
{
|
|
@@ -1119,35 +852,27 @@ function getPropertyTable(tileContent) {
|
|
|
1119
852
|
}
|
|
1120
853
|
}
|
|
1121
854
|
function getPropertyTableExtension(tileContent) {
|
|
1122
|
-
var _tileContent$
|
|
1123
|
-
|
|
1124
|
-
|
|
855
|
+
var _tileContent$gltf3, _tileContent$gltf5, _tileContent$gltf5$ex;
|
|
856
|
+
const extensionsWithPropertyTables = [EXT_FEATURE_METADATA, EXT_MESH_FEATURES];
|
|
857
|
+
const extensionsUsed = tileContent === null || tileContent === void 0 ? void 0 : (_tileContent$gltf3 = tileContent.gltf) === null || _tileContent$gltf3 === void 0 ? void 0 : _tileContent$gltf3.extensionsUsed;
|
|
1125
858
|
if (!extensionsUsed) {
|
|
1126
859
|
return {
|
|
1127
860
|
extensionName: null,
|
|
1128
861
|
extension: null
|
|
1129
862
|
};
|
|
1130
863
|
}
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
if (extensionsWithPropertyTables.includes(extensionItem)) {
|
|
1138
|
-
extensionName = extensionItem;
|
|
1139
|
-
break;
|
|
1140
|
-
}
|
|
864
|
+
let extensionName = '';
|
|
865
|
+
for (const extensionItem of (tileContent === null || tileContent === void 0 ? void 0 : (_tileContent$gltf4 = tileContent.gltf) === null || _tileContent$gltf4 === void 0 ? void 0 : _tileContent$gltf4.extensionsUsed) || []) {
|
|
866
|
+
var _tileContent$gltf4;
|
|
867
|
+
if (extensionsWithPropertyTables.includes(extensionItem)) {
|
|
868
|
+
extensionName = extensionItem;
|
|
869
|
+
break;
|
|
1141
870
|
}
|
|
1142
|
-
} catch (err) {
|
|
1143
|
-
_iterator5.e(err);
|
|
1144
|
-
} finally {
|
|
1145
|
-
_iterator5.f();
|
|
1146
871
|
}
|
|
1147
|
-
|
|
872
|
+
const extension = tileContent === null || tileContent === void 0 ? void 0 : (_tileContent$gltf5 = tileContent.gltf) === null || _tileContent$gltf5 === void 0 ? void 0 : (_tileContent$gltf5$ex = _tileContent$gltf5.extensions) === null || _tileContent$gltf5$ex === void 0 ? void 0 : _tileContent$gltf5$ex[extensionName];
|
|
1148
873
|
return {
|
|
1149
|
-
extensionName
|
|
1150
|
-
extension
|
|
874
|
+
extensionName,
|
|
875
|
+
extension
|
|
1151
876
|
};
|
|
1152
877
|
}
|
|
1153
878
|
function getPropertyTableFromExtFeatureMetadata(extension) {
|
|
@@ -1157,11 +882,11 @@ function getPropertyTableFromExtFeatureMetadata(extension) {
|
|
|
1157
882
|
}
|
|
1158
883
|
if (extension !== null && extension !== void 0 && extension.featureTables) {
|
|
1159
884
|
var _Object$keys;
|
|
1160
|
-
|
|
885
|
+
const firstFeatureTableName = (_Object$keys = Object.keys(extension.featureTables)) === null || _Object$keys === void 0 ? void 0 : _Object$keys[0];
|
|
1161
886
|
if (firstFeatureTableName) {
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
for (
|
|
887
|
+
const featureTable = extension === null || extension === void 0 ? void 0 : extension.featureTables[firstFeatureTableName];
|
|
888
|
+
const propertyTable = {};
|
|
889
|
+
for (const propertyName in featureTable.properties) {
|
|
1165
890
|
propertyTable[propertyName] = featureTable.properties[propertyName].data;
|
|
1166
891
|
}
|
|
1167
892
|
return propertyTable;
|