@loaders.gl/tile-converter 3.1.0-alpha.4 → 3.1.0-beta.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/converter.js +1 -1
- package/dist/bundle.js +86025 -0
- package/dist/converter.min.js +292 -0
- package/dist/es5/3d-tiles-converter/3d-tiles-converter.js +189 -421
- package/dist/es5/3d-tiles-converter/3d-tiles-converter.js.map +1 -1
- package/dist/es5/3d-tiles-converter/helpers/b3dm-converter.js +214 -296
- 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 -8
- 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 +40 -0
- package/dist/es5/3d-tiles-converter/helpers/texture-atlas.js.map +1 -0
- package/dist/es5/3d-tiles-converter/json-templates/tileset.js +7 -17
- 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/deps-installer/deps-installer.js +17 -65
- package/dist/es5/deps-installer/deps-installer.js.map +1 -1
- package/dist/es5/i3s-converter/helpers/coordinate-converter.js +16 -16
- package/dist/es5/i3s-converter/helpers/coordinate-converter.js.map +1 -1
- package/dist/es5/i3s-converter/helpers/create-scene-server-path.js +9 -33
- package/dist/es5/i3s-converter/helpers/create-scene-server-path.js.map +1 -1
- package/dist/es5/i3s-converter/helpers/geometry-attributes.js +93 -103
- package/dist/es5/i3s-converter/helpers/geometry-attributes.js.map +1 -1
- package/dist/es5/i3s-converter/helpers/geometry-converter.js +348 -511
- package/dist/es5/i3s-converter/helpers/geometry-converter.js.map +1 -1
- package/dist/es5/i3s-converter/helpers/node-debug.js +30 -26
- package/dist/es5/i3s-converter/helpers/node-debug.js.map +1 -1
- package/dist/es5/i3s-converter/helpers/node-pages.js +102 -203
- package/dist/es5/i3s-converter/helpers/node-pages.js.map +1 -1
- package/dist/es5/i3s-converter/i3s-converter.js +701 -1501
- package/dist/es5/i3s-converter/i3s-converter.js.map +1 -1
- package/dist/es5/i3s-converter/json-templates/layers.js +15 -25
- package/dist/es5/i3s-converter/json-templates/layers.js.map +1 -1
- package/dist/es5/i3s-converter/json-templates/metadata.js +2 -2
- package/dist/es5/i3s-converter/json-templates/metadata.js.map +1 -1
- package/dist/es5/i3s-converter/json-templates/node.js +12 -21
- package/dist/es5/i3s-converter/json-templates/node.js.map +1 -1
- package/dist/es5/i3s-converter/json-templates/scene-server.js +3 -5
- package/dist/es5/i3s-converter/json-templates/scene-server.js.map +1 -1
- package/dist/es5/i3s-converter/json-templates/shared-resources.js +15 -55
- package/dist/es5/i3s-converter/json-templates/shared-resources.js.map +1 -1
- package/dist/es5/i3s-converter/json-templates/store.js +4 -6
- 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 -60
- package/dist/es5/i3s-server/controllers/index-controller.js.map +1 -1
- package/dist/es5/i3s-server/routes/index.js +14 -41
- package/dist/es5/i3s-server/routes/index.js.map +1 -1
- package/dist/es5/index.js +4 -4
- package/dist/es5/lib/geoid-height-model.js +100 -114
- package/dist/es5/lib/geoid-height-model.js.map +1 -1
- package/dist/es5/lib/pgm-parser.js +68 -122
- package/dist/es5/lib/pgm-parser.js.map +1 -1
- package/dist/es5/lib/utils/compress-util.js +123 -345
- package/dist/es5/lib/utils/compress-util.js.map +1 -1
- package/dist/es5/lib/utils/file-utils.js +20 -98
- 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/statistic-utills.js +41 -152
- package/dist/es5/lib/utils/statistic-utills.js.map +1 -1
- package/dist/es5/pgm-loader.js +3 -5
- package/dist/es5/pgm-loader.js.map +1 -1
- package/dist/esm/3d-tiles-converter/3d-tiles-converter.js +19 -13
- package/dist/esm/3d-tiles-converter/3d-tiles-converter.js.map +1 -1
- package/dist/esm/3d-tiles-converter/helpers/b3dm-converter.js +19 -8
- package/dist/esm/3d-tiles-converter/helpers/b3dm-converter.js.map +1 -1
- package/dist/esm/3d-tiles-converter/helpers/texture-atlas.js +33 -0
- package/dist/esm/3d-tiles-converter/helpers/texture-atlas.js.map +1 -0
- package/dist/esm/i3s-converter/helpers/geometry-converter.js +29 -31
- package/dist/esm/i3s-converter/helpers/geometry-converter.js.map +1 -1
- package/dist/esm/i3s-converter/helpers/node-debug.js +2 -2
- package/dist/esm/i3s-converter/helpers/node-debug.js.map +1 -1
- package/dist/esm/i3s-converter/helpers/node-pages.js +2 -2
- package/dist/esm/i3s-converter/helpers/node-pages.js.map +1 -1
- package/dist/esm/i3s-converter/i3s-converter.js +50 -31
- package/dist/esm/i3s-converter/i3s-converter.js.map +1 -1
- package/dist/esm/i3s-converter/json-templates/metadata.js +1 -1
- package/dist/esm/i3s-converter/json-templates/metadata.js.map +1 -1
- package/dist/esm/i3s-converter/json-templates/scene-server.js +1 -1
- package/dist/esm/i3s-converter/json-templates/scene-server.js.map +1 -1
- package/dist/esm/i3s-converter/json-templates/shared-resources.js +2 -2
- package/dist/esm/i3s-converter/json-templates/shared-resources.js.map +1 -1
- package/dist/esm/i3s-converter/json-templates/store.js +2 -2
- package/dist/esm/i3s-converter/json-templates/store.js.map +1 -1
- package/dist/esm/i3s-server/controllers/index-controller.js +2 -2
- package/dist/esm/i3s-server/controllers/index-controller.js.map +1 -1
- package/dist/esm/lib/utils/compress-util.js +13 -13
- package/dist/esm/lib/utils/compress-util.js.map +1 -1
- package/dist/esm/lib/utils/file-utils.js +1 -1
- package/dist/esm/lib/utils/file-utils.js.map +1 -1
- package/dist/esm/lib/utils/statistic-utills.js +5 -5
- package/dist/esm/lib/utils/statistic-utills.js.map +1 -1
- package/dist/esm/pgm-loader.js +1 -1
- package/dist/esm/pgm-loader.js.map +1 -1
- package/package.json +22 -19
- package/src/3d-tiles-converter/3d-tiles-converter.ts +4 -2
- package/src/3d-tiles-converter/helpers/b3dm-converter.js +35 -7
- package/src/3d-tiles-converter/helpers/texture-atlas.ts +55 -0
- package/src/i3s-converter/helpers/geometry-converter.js +21 -22
- package/src/i3s-converter/i3s-converter.ts +32 -7
- package/src/i3s-converter/json-templates/metadata.js +1 -1
- package/src/i3s-converter/json-templates/scene-server.js +1 -1
- package/src/i3s-converter/json-templates/store.js +2 -2
- package/src/i3s-server/controllers/index-controller.js +1 -1
- package/dist/dist.min.js +0 -94
- package/dist/dist.min.js.map +0 -1
- package/dist/scripts/converter.js +0 -274
|
@@ -7,12 +7,6 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
7
7
|
});
|
|
8
8
|
exports.default = convertB3dmToI3sGeometry;
|
|
9
9
|
|
|
10
|
-
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
|
11
|
-
|
|
12
|
-
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
13
|
-
|
|
14
|
-
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
15
|
-
|
|
16
10
|
var _core = require("@math.gl/core");
|
|
17
11
|
|
|
18
12
|
var _geospatial = require("@math.gl/geospatial");
|
|
@@ -27,280 +21,169 @@ var _md = _interopRequireDefault(require("md5"));
|
|
|
27
21
|
|
|
28
22
|
var _geometryAttributes = require("./geometry-attributes");
|
|
29
23
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
function convertB3dmToI3sGeometry(_x, _x2, _x3, _x4, _x5) {
|
|
50
|
-
return _convertB3dmToI3sGeometry.apply(this, arguments);
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
function _convertB3dmToI3sGeometry() {
|
|
54
|
-
_convertB3dmToI3sGeometry = (0, _asyncToGenerator2.default)(_regenerator.default.mark(function _callee(tileContent, nodeId, featuresHashArray, attributeStorageInfo, draco) {
|
|
55
|
-
var materialAndTextureList, convertedAttributesMap, result, nodesCounter, i, sourceMaterial, convertedAttributes, _materialAndTextureLi, material, texture;
|
|
56
|
-
|
|
57
|
-
return _regenerator.default.wrap(function _callee$(_context) {
|
|
58
|
-
while (1) {
|
|
59
|
-
switch (_context.prev = _context.next) {
|
|
60
|
-
case 0:
|
|
61
|
-
materialAndTextureList = convertMaterials(tileContent);
|
|
62
|
-
convertedAttributesMap = convertAttributes(tileContent);
|
|
63
|
-
|
|
64
|
-
if (convertedAttributesMap.has('default')) {
|
|
65
|
-
materialAndTextureList.push({
|
|
66
|
-
material: getDefaultMaterial()
|
|
67
|
-
});
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
result = [];
|
|
71
|
-
nodesCounter = nodeId;
|
|
72
|
-
i = 0;
|
|
73
|
-
|
|
74
|
-
case 6:
|
|
75
|
-
if (!(i < (tileContent.gltf.materials.length || 1))) {
|
|
76
|
-
_context.next = 21;
|
|
77
|
-
break;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
sourceMaterial = tileContent.gltf.materials[i] || {
|
|
81
|
-
id: 'default'
|
|
82
|
-
};
|
|
83
|
-
|
|
84
|
-
if (convertedAttributesMap.has(sourceMaterial.id)) {
|
|
85
|
-
_context.next = 10;
|
|
86
|
-
break;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
return _context.abrupt("continue", 18);
|
|
90
|
-
|
|
91
|
-
case 10:
|
|
92
|
-
convertedAttributes = convertedAttributesMap.get(sourceMaterial.id);
|
|
93
|
-
_materialAndTextureLi = materialAndTextureList[i], material = _materialAndTextureLi.material, texture = _materialAndTextureLi.texture;
|
|
94
|
-
_context.t0 = result;
|
|
95
|
-
_context.next = 15;
|
|
96
|
-
return _makeNodeResources({
|
|
97
|
-
convertedAttributes: convertedAttributes,
|
|
98
|
-
material: material,
|
|
99
|
-
texture: texture,
|
|
100
|
-
tileContent: tileContent,
|
|
101
|
-
nodeId: nodesCounter,
|
|
102
|
-
featuresHashArray: featuresHashArray,
|
|
103
|
-
attributeStorageInfo: attributeStorageInfo,
|
|
104
|
-
draco: draco
|
|
105
|
-
});
|
|
106
|
-
|
|
107
|
-
case 15:
|
|
108
|
-
_context.t1 = _context.sent;
|
|
109
|
-
|
|
110
|
-
_context.t0.push.call(_context.t0, _context.t1);
|
|
111
|
-
|
|
112
|
-
nodesCounter++;
|
|
113
|
-
|
|
114
|
-
case 18:
|
|
115
|
-
i++;
|
|
116
|
-
_context.next = 6;
|
|
117
|
-
break;
|
|
118
|
-
|
|
119
|
-
case 21:
|
|
120
|
-
return _context.abrupt("return", result);
|
|
121
|
-
|
|
122
|
-
case 22:
|
|
123
|
-
case "end":
|
|
124
|
-
return _context.stop();
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
}, _callee);
|
|
128
|
-
}));
|
|
129
|
-
return _convertB3dmToI3sGeometry.apply(this, arguments);
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
function _makeNodeResources(_x6) {
|
|
133
|
-
return _makeNodeResources2.apply(this, arguments);
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
function _makeNodeResources2() {
|
|
137
|
-
_makeNodeResources2 = (0, _asyncToGenerator2.default)(_regenerator.default.mark(function _callee2(_ref) {
|
|
138
|
-
var convertedAttributes, material, texture, tileContent, nodeId, featuresHashArray, attributeStorageInfo, draco, vertexCount, triangleCount, _generateAttributes, faceRange, featureIds, positions, normals, colors, texCoords, featureCount, header, typedFeatureIds, fileBuffer, compressedGeometry, attributes;
|
|
139
|
-
|
|
140
|
-
return _regenerator.default.wrap(function _callee2$(_context2) {
|
|
141
|
-
while (1) {
|
|
142
|
-
switch (_context2.prev = _context2.next) {
|
|
143
|
-
case 0:
|
|
144
|
-
convertedAttributes = _ref.convertedAttributes, material = _ref.material, texture = _ref.texture, tileContent = _ref.tileContent, nodeId = _ref.nodeId, featuresHashArray = _ref.featuresHashArray, attributeStorageInfo = _ref.attributeStorageInfo, draco = _ref.draco;
|
|
145
|
-
vertexCount = convertedAttributes.positions.length / VALUES_PER_VERTEX;
|
|
146
|
-
triangleCount = vertexCount / 3;
|
|
147
|
-
_generateAttributes = (0, _geometryAttributes.generateAttributes)(_objectSpread({
|
|
148
|
-
triangleCount: triangleCount
|
|
149
|
-
}, convertedAttributes)), faceRange = _generateAttributes.faceRange, featureIds = _generateAttributes.featureIds, positions = _generateAttributes.positions, normals = _generateAttributes.normals, colors = _generateAttributes.colors, texCoords = _generateAttributes.texCoords, featureCount = _generateAttributes.featureCount;
|
|
150
|
-
|
|
151
|
-
if (tileContent.batchTableJson) {
|
|
152
|
-
makeFeatureIdsUnique(featureIds, convertedAttributes.featureIndices, featuresHashArray, tileContent.batchTableJson);
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
header = new Uint32Array(2);
|
|
156
|
-
typedFeatureIds = generateBigUint64Array(featureIds);
|
|
157
|
-
header.set([vertexCount, featureCount], 0);
|
|
158
|
-
fileBuffer = new Uint8Array((0, _loaderUtils.concatenateArrayBuffers)(header.buffer, positions.buffer, normals.buffer, texture ? texCoords.buffer : new ArrayBuffer(0), colors.buffer, typedFeatureIds.buffer, faceRange.buffer));
|
|
159
|
-
|
|
160
|
-
if (!draco) {
|
|
161
|
-
_context2.next = 15;
|
|
162
|
-
break;
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
_context2.next = 12;
|
|
166
|
-
return generateCompressedGeometry(vertexCount, convertedAttributes, {
|
|
167
|
-
positions: positions,
|
|
168
|
-
normals: normals,
|
|
169
|
-
texCoords: texture ? texCoords : new Float32Array(0),
|
|
170
|
-
colors: colors,
|
|
171
|
-
featureIds: featureIds,
|
|
172
|
-
faceRange: faceRange
|
|
173
|
-
});
|
|
174
|
-
|
|
175
|
-
case 12:
|
|
176
|
-
_context2.t0 = _context2.sent;
|
|
177
|
-
_context2.next = 16;
|
|
178
|
-
break;
|
|
179
|
-
|
|
180
|
-
case 15:
|
|
181
|
-
_context2.t0 = null;
|
|
182
|
-
|
|
183
|
-
case 16:
|
|
184
|
-
compressedGeometry = _context2.t0;
|
|
185
|
-
attributes = convertBatchTableToAttributeBuffers(tileContent.batchTableJson, featureIds, attributeStorageInfo);
|
|
186
|
-
return _context2.abrupt("return", {
|
|
187
|
-
geometry: fileBuffer,
|
|
188
|
-
compressedGeometry: compressedGeometry,
|
|
189
|
-
texture: texture,
|
|
190
|
-
sharedResources: getSharedResources(tileContent, nodeId),
|
|
191
|
-
meshMaterial: material,
|
|
192
|
-
vertexCount: vertexCount,
|
|
193
|
-
attributes: attributes,
|
|
194
|
-
featureCount: featureCount
|
|
195
|
-
});
|
|
196
|
-
|
|
197
|
-
case 19:
|
|
198
|
-
case "end":
|
|
199
|
-
return _context2.stop();
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
}, _callee2);
|
|
203
|
-
}));
|
|
204
|
-
return _makeNodeResources2.apply(this, arguments);
|
|
205
|
-
}
|
|
24
|
+
const VALUES_PER_VERTEX = 3;
|
|
25
|
+
const VALUES_PER_TEX_COORD = 2;
|
|
26
|
+
const VALUES_PER_COLOR_ELEMENT = 4;
|
|
27
|
+
const STRING_TYPE = 'string';
|
|
28
|
+
const SHORT_INT_TYPE = 'Int32';
|
|
29
|
+
const DOUBLE_TYPE = 'Float64';
|
|
30
|
+
const OBJECT_ID_TYPE = 'Oid32';
|
|
31
|
+
const BATCHED_ID_POSSIBLE_ATTRIBUTE_NAMES = ['CUSTOM_ATTRIBUTE_2', '_BATCHID', 'BATCHID'];
|
|
32
|
+
|
|
33
|
+
async function convertB3dmToI3sGeometry(tileContent, nodeId, featuresHashArray, attributeStorageInfo, draco) {
|
|
34
|
+
const materialAndTextureList = convertMaterials(tileContent);
|
|
35
|
+
const convertedAttributesMap = convertAttributes(tileContent);
|
|
36
|
+
|
|
37
|
+
if (convertedAttributesMap.has('default')) {
|
|
38
|
+
materialAndTextureList.push({
|
|
39
|
+
material: getDefaultMaterial()
|
|
40
|
+
});
|
|
41
|
+
}
|
|
206
42
|
|
|
207
|
-
|
|
208
|
-
|
|
43
|
+
const result = [];
|
|
44
|
+
let nodesCounter = nodeId;
|
|
45
|
+
let {
|
|
46
|
+
materials = []
|
|
47
|
+
} = tileContent.gltf;
|
|
209
48
|
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
texCoords: new Float32Array(0),
|
|
222
|
-
colors: new Uint8Array(0),
|
|
223
|
-
featureIndices: []
|
|
224
|
-
});
|
|
49
|
+
if (!materials.length === 0) {
|
|
50
|
+
materials.push({
|
|
51
|
+
id: 'default'
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
for (let i = 0; i < materials.length; i++) {
|
|
56
|
+
const sourceMaterial = materials[i];
|
|
57
|
+
|
|
58
|
+
if (!convertedAttributesMap.has(sourceMaterial.id)) {
|
|
59
|
+
continue;
|
|
225
60
|
}
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
61
|
+
|
|
62
|
+
const convertedAttributes = convertedAttributesMap.get(sourceMaterial.id);
|
|
63
|
+
const {
|
|
64
|
+
material,
|
|
65
|
+
texture
|
|
66
|
+
} = materialAndTextureList[i];
|
|
67
|
+
result.push(await _makeNodeResources({
|
|
68
|
+
convertedAttributes,
|
|
69
|
+
material,
|
|
70
|
+
texture,
|
|
71
|
+
tileContent,
|
|
72
|
+
nodeId: nodesCounter,
|
|
73
|
+
featuresHashArray,
|
|
74
|
+
attributeStorageInfo,
|
|
75
|
+
draco
|
|
76
|
+
}));
|
|
77
|
+
nodesCounter++;
|
|
230
78
|
}
|
|
231
79
|
|
|
232
|
-
|
|
233
|
-
|
|
80
|
+
if (!result.length) {
|
|
81
|
+
return null;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
return result;
|
|
85
|
+
}
|
|
234
86
|
|
|
235
|
-
|
|
236
|
-
|
|
87
|
+
async function _makeNodeResources({
|
|
88
|
+
convertedAttributes,
|
|
89
|
+
material,
|
|
90
|
+
texture,
|
|
91
|
+
tileContent,
|
|
92
|
+
nodeId,
|
|
93
|
+
featuresHashArray,
|
|
94
|
+
attributeStorageInfo,
|
|
95
|
+
draco
|
|
96
|
+
}) {
|
|
97
|
+
const vertexCount = convertedAttributes.positions.length / VALUES_PER_VERTEX;
|
|
98
|
+
const triangleCount = vertexCount / 3;
|
|
99
|
+
const {
|
|
100
|
+
faceRange,
|
|
101
|
+
featureIds,
|
|
102
|
+
positions,
|
|
103
|
+
normals,
|
|
104
|
+
colors,
|
|
105
|
+
texCoords,
|
|
106
|
+
featureCount
|
|
107
|
+
} = (0, _geometryAttributes.generateAttributes)({
|
|
108
|
+
triangleCount,
|
|
109
|
+
...convertedAttributes
|
|
110
|
+
});
|
|
237
111
|
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
var attributes = attributesMap.get(attrKey);
|
|
112
|
+
if (tileContent.batchTableJson) {
|
|
113
|
+
makeFeatureIdsUnique(featureIds, convertedAttributes.featureIndices, featuresHashArray, tileContent.batchTableJson);
|
|
114
|
+
}
|
|
242
115
|
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
116
|
+
const header = new Uint32Array(2);
|
|
117
|
+
const typedFeatureIds = generateBigUint64Array(featureIds);
|
|
118
|
+
header.set([vertexCount, featureCount], 0);
|
|
119
|
+
const fileBuffer = new Uint8Array((0, _loaderUtils.concatenateArrayBuffers)(header.buffer, positions.buffer, normals.buffer, texture ? texCoords.buffer : new ArrayBuffer(0), colors.buffer, typedFeatureIds.buffer, faceRange.buffer));
|
|
120
|
+
const compressedGeometry = draco ? await generateCompressedGeometry(vertexCount, convertedAttributes, {
|
|
121
|
+
positions,
|
|
122
|
+
normals,
|
|
123
|
+
texCoords: texture ? texCoords : new Float32Array(0),
|
|
124
|
+
colors,
|
|
125
|
+
featureIds,
|
|
126
|
+
faceRange
|
|
127
|
+
}) : null;
|
|
128
|
+
const attributes = convertBatchTableToAttributeBuffers(tileContent.batchTableJson, featureIds, attributeStorageInfo);
|
|
129
|
+
return {
|
|
130
|
+
geometry: fileBuffer,
|
|
131
|
+
compressedGeometry,
|
|
132
|
+
texture,
|
|
133
|
+
sharedResources: getSharedResources(tileContent, nodeId),
|
|
134
|
+
meshMaterial: material,
|
|
135
|
+
vertexCount,
|
|
136
|
+
attributes,
|
|
137
|
+
featureCount
|
|
138
|
+
};
|
|
139
|
+
}
|
|
247
140
|
|
|
248
|
-
|
|
141
|
+
function convertAttributes(tileContent) {
|
|
142
|
+
var _tileContent$gltf$sce;
|
|
249
143
|
|
|
250
|
-
|
|
251
|
-
attributes.colors = new Uint8Array(vertexCount * VALUES_PER_COLOR_ELEMENT);
|
|
144
|
+
const attributesMap = new Map();
|
|
252
145
|
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
146
|
+
for (const material of tileContent.gltf.materials || [{
|
|
147
|
+
id: 'default'
|
|
148
|
+
}]) {
|
|
149
|
+
attributesMap.set(material.id, {
|
|
150
|
+
positions: new Float32Array(0),
|
|
151
|
+
normals: new Float32Array(0),
|
|
152
|
+
texCoords: new Float32Array(0),
|
|
153
|
+
colors: new Uint8Array(0),
|
|
154
|
+
featureIndices: []
|
|
155
|
+
});
|
|
156
|
+
}
|
|
257
157
|
|
|
258
|
-
|
|
259
|
-
|
|
158
|
+
const nodes = (tileContent.gltf.scene || ((_tileContent$gltf$sce = tileContent.gltf.scenes) === null || _tileContent$gltf$sce === void 0 ? void 0 : _tileContent$gltf$sce[0]) || tileContent.gltf).nodes;
|
|
159
|
+
convertNodes(nodes, tileContent, attributesMap);
|
|
260
160
|
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
}
|
|
264
|
-
}
|
|
161
|
+
for (const attrKey of attributesMap.keys()) {
|
|
162
|
+
const attributes = attributesMap.get(attrKey);
|
|
265
163
|
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
164
|
+
if (attributes.positions.length === 0) {
|
|
165
|
+
attributesMap.delete(attrKey);
|
|
166
|
+
continue;
|
|
269
167
|
}
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
} finally {
|
|
273
|
-
_iterator2.f();
|
|
168
|
+
|
|
169
|
+
attributes.featureIndices = attributes.featureIndices.reduce((acc, value) => acc.concat(value));
|
|
274
170
|
}
|
|
275
171
|
|
|
276
172
|
return attributesMap;
|
|
277
173
|
}
|
|
278
174
|
|
|
279
|
-
function convertNodes(nodes, tileContent, attributesMap) {
|
|
280
|
-
var matrix = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : new _core.Matrix4([1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1]);
|
|
281
|
-
|
|
175
|
+
function convertNodes(nodes, tileContent, attributesMap, matrix = new _core.Matrix4([1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1])) {
|
|
282
176
|
if (nodes) {
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
try {
|
|
287
|
-
for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
|
|
288
|
-
var node = _step3.value;
|
|
289
|
-
convertNode(node, tileContent, attributesMap, matrix);
|
|
290
|
-
}
|
|
291
|
-
} catch (err) {
|
|
292
|
-
_iterator3.e(err);
|
|
293
|
-
} finally {
|
|
294
|
-
_iterator3.f();
|
|
177
|
+
for (const node of nodes) {
|
|
178
|
+
convertNode(node, tileContent, attributesMap, matrix);
|
|
295
179
|
}
|
|
296
180
|
}
|
|
297
181
|
}
|
|
298
182
|
|
|
299
|
-
function convertNode(node, tileContent, attributesMap) {
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
var mesh = node.mesh;
|
|
183
|
+
function convertNode(node, tileContent, attributesMap, matrix = new _core.Matrix4([1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1])) {
|
|
184
|
+
const nodeMatrix = node.matrix;
|
|
185
|
+
const compositeMatrix = nodeMatrix ? matrix.multiplyRight(nodeMatrix) : matrix;
|
|
186
|
+
const mesh = node.mesh;
|
|
304
187
|
|
|
305
188
|
if (mesh) {
|
|
306
189
|
convertMesh(mesh, tileContent, attributesMap, compositeMatrix);
|
|
@@ -309,66 +192,56 @@ function convertNode(node, tileContent, attributesMap) {
|
|
|
309
192
|
convertNodes(node.children, tileContent, attributesMap, compositeMatrix);
|
|
310
193
|
}
|
|
311
194
|
|
|
312
|
-
function convertMesh(mesh, content, attributesMap) {
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
var _iterator4 = _createForOfIteratorHelper(mesh.primitives),
|
|
316
|
-
_step4;
|
|
317
|
-
|
|
318
|
-
try {
|
|
319
|
-
for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
|
|
320
|
-
var primitive = _step4.value;
|
|
321
|
-
var outputAttributes = null;
|
|
322
|
-
|
|
323
|
-
if (primitive.material) {
|
|
324
|
-
outputAttributes = attributesMap.get(primitive.material.id);
|
|
325
|
-
} else if (attributesMap.has('default')) {
|
|
326
|
-
outputAttributes = attributesMap.get('default');
|
|
327
|
-
}
|
|
195
|
+
function convertMesh(mesh, content, attributesMap, matrix = new _core.Matrix4([1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1])) {
|
|
196
|
+
for (const primitive of mesh.primitives) {
|
|
197
|
+
let outputAttributes = null;
|
|
328
198
|
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
cartographicOrigin: content.cartographicOrigin,
|
|
334
|
-
cartesianModelMatrix: content.cartesianModelMatrix,
|
|
335
|
-
nodeMatrix: matrix,
|
|
336
|
-
indices: primitive.indices.value,
|
|
337
|
-
attributeSpecificTransformation: transformVertexPositions
|
|
338
|
-
}));
|
|
339
|
-
outputAttributes.normals = (0, _loaderUtils.concatenateTypedArrays)(outputAttributes.normals, transformVertexArray({
|
|
340
|
-
vertices: attributes.NORMAL && attributes.NORMAL.value,
|
|
341
|
-
cartographicOrigin: content.cartographicOrigin,
|
|
342
|
-
cartesianModelMatrix: content.cartesianModelMatrix,
|
|
343
|
-
nodeMatrix: matrix,
|
|
344
|
-
indices: primitive.indices.value,
|
|
345
|
-
attributeSpecificTransformation: transformVertexNormals
|
|
346
|
-
}));
|
|
347
|
-
outputAttributes.texCoords = (0, _loaderUtils.concatenateTypedArrays)(outputAttributes.texCoords, flattenTexCoords(attributes.TEXCOORD_0 && attributes.TEXCOORD_0.value, primitive.indices.value));
|
|
348
|
-
outputAttributes.colors = (0, _loaderUtils.concatenateTypedArrays)(outputAttributes.colors, flattenColors(attributes.COLOR_0, primitive.indices.value));
|
|
349
|
-
outputAttributes.featureIndices.push(flattenBatchIds(getBatchIdsByAttributeName(attributes), primitive.indices.value));
|
|
199
|
+
if (primitive.material) {
|
|
200
|
+
outputAttributes = attributesMap.get(primitive.material.id);
|
|
201
|
+
} else if (attributesMap.has('default')) {
|
|
202
|
+
outputAttributes = attributesMap.get('default');
|
|
350
203
|
}
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
204
|
+
|
|
205
|
+
(0, _core2.assert)(outputAttributes !== null, 'Primitive - material mapping failed');
|
|
206
|
+
const attributes = primitive.attributes;
|
|
207
|
+
outputAttributes.positions = (0, _loaderUtils.concatenateTypedArrays)(outputAttributes.positions, transformVertexArray({
|
|
208
|
+
vertices: attributes.POSITION.value,
|
|
209
|
+
cartographicOrigin: content.cartographicOrigin,
|
|
210
|
+
cartesianModelMatrix: content.cartesianModelMatrix,
|
|
211
|
+
nodeMatrix: matrix,
|
|
212
|
+
indices: primitive.indices.value,
|
|
213
|
+
attributeSpecificTransformation: transformVertexPositions
|
|
214
|
+
}));
|
|
215
|
+
outputAttributes.normals = (0, _loaderUtils.concatenateTypedArrays)(outputAttributes.normals, transformVertexArray({
|
|
216
|
+
vertices: attributes.NORMAL && attributes.NORMAL.value,
|
|
217
|
+
cartographicOrigin: content.cartographicOrigin,
|
|
218
|
+
cartesianModelMatrix: content.cartesianModelMatrix,
|
|
219
|
+
nodeMatrix: matrix,
|
|
220
|
+
indices: primitive.indices.value,
|
|
221
|
+
attributeSpecificTransformation: transformVertexNormals
|
|
222
|
+
}));
|
|
223
|
+
outputAttributes.texCoords = (0, _loaderUtils.concatenateTypedArrays)(outputAttributes.texCoords, flattenTexCoords(attributes.TEXCOORD_0 && attributes.TEXCOORD_0.value, primitive.indices.value));
|
|
224
|
+
outputAttributes.colors = (0, _loaderUtils.concatenateTypedArrays)(outputAttributes.colors, flattenColors(attributes.COLOR_0, primitive.indices.value));
|
|
225
|
+
outputAttributes.featureIndices.push(flattenBatchIds(getBatchIdsByAttributeName(attributes), primitive.indices.value));
|
|
355
226
|
}
|
|
356
227
|
}
|
|
357
228
|
|
|
358
229
|
function transformVertexArray(args) {
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
230
|
+
const {
|
|
231
|
+
vertices,
|
|
232
|
+
indices,
|
|
233
|
+
attributeSpecificTransformation
|
|
234
|
+
} = args;
|
|
235
|
+
const newVertices = new Float32Array(indices.length * VALUES_PER_VERTEX);
|
|
363
236
|
|
|
364
237
|
if (!vertices) {
|
|
365
238
|
return newVertices;
|
|
366
239
|
}
|
|
367
240
|
|
|
368
|
-
for (
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
241
|
+
for (let i = 0; i < indices.length; i++) {
|
|
242
|
+
const coordIndex = indices[i] * VALUES_PER_VERTEX;
|
|
243
|
+
const vertex = vertices.subarray(coordIndex, coordIndex + VALUES_PER_VERTEX);
|
|
244
|
+
let vertexVector = new _core.Vector3(Array.from(vertex));
|
|
372
245
|
vertexVector = attributeSpecificTransformation(vertexVector, args);
|
|
373
246
|
newVertices[i * VALUES_PER_VERTEX] = vertexVector.x;
|
|
374
247
|
newVertices[i * VALUES_PER_VERTEX + 1] = vertexVector.y;
|
|
@@ -379,9 +252,11 @@ function transformVertexArray(args) {
|
|
|
379
252
|
}
|
|
380
253
|
|
|
381
254
|
function transformVertexPositions(vertexVector, calleeArgs) {
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
255
|
+
const {
|
|
256
|
+
cartesianModelMatrix,
|
|
257
|
+
cartographicOrigin,
|
|
258
|
+
nodeMatrix
|
|
259
|
+
} = calleeArgs;
|
|
385
260
|
|
|
386
261
|
if (nodeMatrix) {
|
|
387
262
|
vertexVector = vertexVector.transform(nodeMatrix);
|
|
@@ -396,8 +271,10 @@ function transformVertexPositions(vertexVector, calleeArgs) {
|
|
|
396
271
|
}
|
|
397
272
|
|
|
398
273
|
function transformVertexNormals(vertexVector, calleeArgs) {
|
|
399
|
-
|
|
400
|
-
|
|
274
|
+
const {
|
|
275
|
+
cartesianModelMatrix,
|
|
276
|
+
nodeMatrix
|
|
277
|
+
} = calleeArgs;
|
|
401
278
|
|
|
402
279
|
if (nodeMatrix) {
|
|
403
280
|
vertexVector = vertexVector.transformAsVector(nodeMatrix);
|
|
@@ -408,15 +285,16 @@ function transformVertexNormals(vertexVector, calleeArgs) {
|
|
|
408
285
|
}
|
|
409
286
|
|
|
410
287
|
function flattenTexCoords(texCoords, indices) {
|
|
288
|
+
const newTexCoords = new Float32Array(indices.length * VALUES_PER_TEX_COORD);
|
|
289
|
+
|
|
411
290
|
if (!texCoords) {
|
|
412
|
-
|
|
291
|
+
newTexCoords.fill(1);
|
|
292
|
+
return newTexCoords;
|
|
413
293
|
}
|
|
414
294
|
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
var coordIndex = indices[i] * VALUES_PER_TEX_COORD;
|
|
419
|
-
var texCoord = texCoords.subarray(coordIndex, coordIndex + VALUES_PER_TEX_COORD);
|
|
295
|
+
for (let i = 0; i < indices.length; i++) {
|
|
296
|
+
const coordIndex = indices[i] * VALUES_PER_TEX_COORD;
|
|
297
|
+
const texCoord = texCoords.subarray(coordIndex, coordIndex + VALUES_PER_TEX_COORD);
|
|
420
298
|
newTexCoords[i * VALUES_PER_TEX_COORD] = texCoord[0];
|
|
421
299
|
newTexCoords[i * VALUES_PER_TEX_COORD + 1] = texCoord[1];
|
|
422
300
|
}
|
|
@@ -425,20 +303,22 @@ function flattenTexCoords(texCoords, indices) {
|
|
|
425
303
|
}
|
|
426
304
|
|
|
427
305
|
function flattenColors(colorsAttribute, indices) {
|
|
306
|
+
const components = (colorsAttribute === null || colorsAttribute === void 0 ? void 0 : colorsAttribute.components) || VALUES_PER_COLOR_ELEMENT;
|
|
307
|
+
const newColors = new Uint8Array(indices.length * components);
|
|
308
|
+
|
|
428
309
|
if (!colorsAttribute) {
|
|
429
|
-
|
|
310
|
+
newColors.fill(255);
|
|
311
|
+
return newColors;
|
|
430
312
|
}
|
|
431
313
|
|
|
432
|
-
|
|
433
|
-
var colors = colorsAttribute.value;
|
|
434
|
-
var newColors = new Uint8Array(indices.length * components);
|
|
314
|
+
const colors = colorsAttribute.value;
|
|
435
315
|
|
|
436
|
-
for (
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
316
|
+
for (let i = 0; i < indices.length; i++) {
|
|
317
|
+
const colorIndex = indices[i] * components;
|
|
318
|
+
const color = colors.subarray(colorIndex, colorIndex + components);
|
|
319
|
+
const colorUint8 = new Uint8Array(components);
|
|
440
320
|
|
|
441
|
-
for (
|
|
321
|
+
for (let j = 0; j < color.length; j++) {
|
|
442
322
|
colorUint8[j] = color[j] * 255;
|
|
443
323
|
}
|
|
444
324
|
|
|
@@ -453,10 +333,10 @@ function flattenBatchIds(batchedIds, indices) {
|
|
|
453
333
|
return [];
|
|
454
334
|
}
|
|
455
335
|
|
|
456
|
-
|
|
336
|
+
const newBatchIds = [];
|
|
457
337
|
|
|
458
|
-
for (
|
|
459
|
-
|
|
338
|
+
for (let i = 0; i < indices.length; i++) {
|
|
339
|
+
const coordIndex = indices[i];
|
|
460
340
|
newBatchIds.push(batchedIds[coordIndex]);
|
|
461
341
|
}
|
|
462
342
|
|
|
@@ -464,10 +344,10 @@ function flattenBatchIds(batchedIds, indices) {
|
|
|
464
344
|
}
|
|
465
345
|
|
|
466
346
|
function getBatchIdsByAttributeName(attributes) {
|
|
467
|
-
|
|
347
|
+
let batchIds = [];
|
|
468
348
|
|
|
469
|
-
for (
|
|
470
|
-
|
|
349
|
+
for (let index = 0; index < BATCHED_ID_POSSIBLE_ATTRIBUTE_NAMES.length; index++) {
|
|
350
|
+
const possibleBatchIdAttributeName = BATCHED_ID_POSSIBLE_ATTRIBUTE_NAMES[index];
|
|
471
351
|
|
|
472
352
|
if (attributes[possibleBatchIdAttributeName] && attributes[possibleBatchIdAttributeName].value) {
|
|
473
353
|
batchIds = attributes[possibleBatchIdAttributeName].value;
|
|
@@ -479,39 +359,27 @@ function getBatchIdsByAttributeName(attributes) {
|
|
|
479
359
|
}
|
|
480
360
|
|
|
481
361
|
function convertMaterials(tileContent) {
|
|
482
|
-
|
|
483
|
-
|
|
362
|
+
const result = [];
|
|
363
|
+
const sourceMaterials = tileContent.gltf.materials || [];
|
|
484
364
|
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
try {
|
|
489
|
-
for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
|
|
490
|
-
var sourceMaterial = _step5.value;
|
|
491
|
-
result.push(convertMaterial(sourceMaterial));
|
|
492
|
-
}
|
|
493
|
-
} catch (err) {
|
|
494
|
-
_iterator5.e(err);
|
|
495
|
-
} finally {
|
|
496
|
-
_iterator5.f();
|
|
365
|
+
for (const sourceMaterial of sourceMaterials) {
|
|
366
|
+
result.push(convertMaterial(sourceMaterial));
|
|
497
367
|
}
|
|
498
368
|
|
|
499
369
|
return result;
|
|
500
370
|
}
|
|
501
371
|
|
|
502
372
|
function convertMaterial(sourceMaterial) {
|
|
503
|
-
|
|
373
|
+
const material = {
|
|
504
374
|
doubleSided: sourceMaterial.doubleSided,
|
|
505
|
-
emissiveFactor: sourceMaterial.emissiveFactor.map(
|
|
506
|
-
return Math.round(c * 255);
|
|
507
|
-
}),
|
|
375
|
+
emissiveFactor: sourceMaterial.emissiveFactor.map(c => Math.round(c * 255)),
|
|
508
376
|
alphaMode: (sourceMaterial.alphaMode || 'OPAQUE').toLowerCase(),
|
|
509
377
|
pbrMetallicRoughness: {
|
|
510
378
|
roughnessFactor: sourceMaterial.pbrMetallicRoughness.roughnessFactor,
|
|
511
379
|
metallicFactor: sourceMaterial.pbrMetallicRoughness.metallicFactor
|
|
512
380
|
}
|
|
513
381
|
};
|
|
514
|
-
|
|
382
|
+
let texture;
|
|
515
383
|
|
|
516
384
|
if (sourceMaterial.pbrMetallicRoughness.baseColorTexture) {
|
|
517
385
|
texture = sourceMaterial.pbrMetallicRoughness.baseColorTexture.texture.source;
|
|
@@ -526,15 +394,13 @@ function convertMaterial(sourceMaterial) {
|
|
|
526
394
|
}
|
|
527
395
|
|
|
528
396
|
if (!texture) {
|
|
529
|
-
|
|
530
|
-
material.pbrMetallicRoughness.baseColorFactor = baseColorFactor && baseColorFactor.map(
|
|
531
|
-
return Math.round(c * 255);
|
|
532
|
-
}) || undefined;
|
|
397
|
+
const baseColorFactor = sourceMaterial.pbrMetallicRoughness.baseColorFactor;
|
|
398
|
+
material.pbrMetallicRoughness.baseColorFactor = baseColorFactor && baseColorFactor.map(c => Math.round(c * 255)) || undefined;
|
|
533
399
|
}
|
|
534
400
|
|
|
535
401
|
return {
|
|
536
|
-
material
|
|
537
|
-
texture
|
|
402
|
+
material,
|
|
403
|
+
texture
|
|
538
404
|
};
|
|
539
405
|
}
|
|
540
406
|
|
|
@@ -546,8 +412,8 @@ function getDefaultMaterial() {
|
|
|
546
412
|
}
|
|
547
413
|
|
|
548
414
|
function getSharedResources(tileContent, nodeId) {
|
|
549
|
-
|
|
550
|
-
|
|
415
|
+
const gltfMaterials = tileContent.gltf.materials;
|
|
416
|
+
const i3sResources = {};
|
|
551
417
|
|
|
552
418
|
if (!gltfMaterials || !gltfMaterials.length) {
|
|
553
419
|
return i3sResources;
|
|
@@ -555,45 +421,35 @@ function getSharedResources(tileContent, nodeId) {
|
|
|
555
421
|
|
|
556
422
|
i3sResources.materialDefinitionInfos = [];
|
|
557
423
|
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
var _convertGLTFMaterialT = convertGLTFMaterialToI3sSharedResources(gltfMaterial, nodeId),
|
|
566
|
-
materialDefinitionInfo = _convertGLTFMaterialT.materialDefinitionInfo,
|
|
567
|
-
textureDefinitionInfo = _convertGLTFMaterialT.textureDefinitionInfo;
|
|
424
|
+
for (const gltfMaterial of gltfMaterials) {
|
|
425
|
+
const {
|
|
426
|
+
materialDefinitionInfo,
|
|
427
|
+
textureDefinitionInfo
|
|
428
|
+
} = convertGLTFMaterialToI3sSharedResources(gltfMaterial, nodeId);
|
|
429
|
+
i3sResources.materialDefinitionInfos.push(materialDefinitionInfo);
|
|
568
430
|
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
i3sResources.textureDefinitionInfos = i3sResources.textureDefinitionInfos || [];
|
|
573
|
-
i3sResources.textureDefinitionInfos.push(textureDefinitionInfo);
|
|
574
|
-
}
|
|
431
|
+
if (textureDefinitionInfo) {
|
|
432
|
+
i3sResources.textureDefinitionInfos = i3sResources.textureDefinitionInfos || [];
|
|
433
|
+
i3sResources.textureDefinitionInfos.push(textureDefinitionInfo);
|
|
575
434
|
}
|
|
576
|
-
} catch (err) {
|
|
577
|
-
_iterator6.e(err);
|
|
578
|
-
} finally {
|
|
579
|
-
_iterator6.f();
|
|
580
435
|
}
|
|
581
436
|
|
|
582
437
|
return i3sResources;
|
|
583
438
|
}
|
|
584
439
|
|
|
585
440
|
function convertGLTFMaterialToI3sSharedResources(gltfMaterial, nodeId) {
|
|
586
|
-
|
|
587
|
-
|
|
441
|
+
const texture = gltfMaterial.pbrMetallicRoughness.baseColorTexture || gltfMaterial.emissiveTexture;
|
|
442
|
+
let textureDefinitionInfo = null;
|
|
588
443
|
|
|
589
444
|
if (texture) {
|
|
590
445
|
textureDefinitionInfo = extractSharedResourcesTextureInfo(texture.texture, nodeId);
|
|
591
446
|
}
|
|
592
447
|
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
448
|
+
const {
|
|
449
|
+
baseColorFactor,
|
|
450
|
+
metallicFactor
|
|
451
|
+
} = gltfMaterial.pbrMetallicRoughness;
|
|
452
|
+
let colorFactor = baseColorFactor;
|
|
597
453
|
|
|
598
454
|
if ((!baseColorFactor || baseColorFactor[3] === 0) && gltfMaterial.emissiveFactor) {
|
|
599
455
|
colorFactor = gltfMaterial.emissiveFactor;
|
|
@@ -602,21 +458,20 @@ function convertGLTFMaterialToI3sSharedResources(gltfMaterial, nodeId) {
|
|
|
602
458
|
|
|
603
459
|
return {
|
|
604
460
|
materialDefinitionInfo: extractSharedResourcesMaterialInfo(colorFactor, metallicFactor),
|
|
605
|
-
textureDefinitionInfo
|
|
461
|
+
textureDefinitionInfo
|
|
606
462
|
};
|
|
607
463
|
}
|
|
608
464
|
|
|
609
|
-
function extractSharedResourcesMaterialInfo(baseColorFactor) {
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
var diffuse = firstOperand.lerp(firstOperand, black, metallicFactor);
|
|
465
|
+
function extractSharedResourcesMaterialInfo(baseColorFactor, metallicFactor = 0) {
|
|
466
|
+
const matDielectricColorComponent = 0.04 / 255;
|
|
467
|
+
const black = new _core.Vector4(0, 0, 0, 1);
|
|
468
|
+
const unitVector = new _core.Vector4(1, 1, 1, 1);
|
|
469
|
+
const dielectricSpecular = new _core.Vector4(matDielectricColorComponent, matDielectricColorComponent, matDielectricColorComponent, 0);
|
|
470
|
+
const baseColorVector = new _core.Vector4(baseColorFactor);
|
|
471
|
+
const firstOperand = unitVector.subtract(dielectricSpecular).multiply(baseColorVector);
|
|
472
|
+
const diffuse = firstOperand.lerp(firstOperand, black, metallicFactor);
|
|
618
473
|
dielectricSpecular[3] = 1;
|
|
619
|
-
|
|
474
|
+
const specular = dielectricSpecular.lerp(dielectricSpecular, baseColorVector, metallicFactor);
|
|
620
475
|
return {
|
|
621
476
|
diffuse: diffuse.toArray(),
|
|
622
477
|
specular: specular.toArray()
|
|
@@ -635,35 +490,36 @@ function extractSharedResourcesTextureInfo(texture, nodeId) {
|
|
|
635
490
|
}
|
|
636
491
|
|
|
637
492
|
function generateImageId(texture, nodeId) {
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
493
|
+
const {
|
|
494
|
+
width,
|
|
495
|
+
height
|
|
496
|
+
} = texture.source.image;
|
|
497
|
+
const levelCountOfTexture = 1;
|
|
498
|
+
const indexOfLevel = 0;
|
|
499
|
+
const indexOfTextureInStore = nodeId + 1;
|
|
500
|
+
const zerosCount = 32 - indexOfTextureInStore.toString(2).length;
|
|
501
|
+
const rightHalf = '0'.repeat(zerosCount).concat(indexOfTextureInStore.toString(2));
|
|
502
|
+
const shiftedLevelCountOfTexture = levelCountOfTexture << 28;
|
|
503
|
+
const shiftedIndexOfLevel = indexOfLevel << 24;
|
|
504
|
+
const shiftedWidth = width - 1 << 12;
|
|
505
|
+
const shiftedHeight = height - 1 << 0;
|
|
506
|
+
const leftHalf = shiftedLevelCountOfTexture + shiftedIndexOfLevel + shiftedWidth + shiftedHeight;
|
|
507
|
+
const imageId = BigInt("0b".concat(leftHalf.toString(2)).concat(rightHalf));
|
|
652
508
|
return imageId.toString();
|
|
653
509
|
}
|
|
654
510
|
|
|
655
511
|
function makeFeatureIdsUnique(featureIds, featureIndices, featuresHashArray, batchTable) {
|
|
656
|
-
|
|
512
|
+
const replaceMap = getFeaturesReplaceMap(featureIds, batchTable, featuresHashArray);
|
|
657
513
|
replaceIndicesByUnique(featureIndices, replaceMap);
|
|
658
514
|
replaceIndicesByUnique(featureIds, replaceMap);
|
|
659
515
|
}
|
|
660
516
|
|
|
661
517
|
function getFeaturesReplaceMap(featureIds, batchTable, featuresHashArray) {
|
|
662
|
-
|
|
518
|
+
const featureMap = {};
|
|
663
519
|
|
|
664
|
-
for (
|
|
665
|
-
|
|
666
|
-
|
|
520
|
+
for (let index = 0; index < featureIds.length; index++) {
|
|
521
|
+
const oldFeatureId = featureIds[index];
|
|
522
|
+
const uniqueFeatureId = getOrCreateUniqueFeatureId(index, batchTable, featuresHashArray);
|
|
667
523
|
featureMap[oldFeatureId.toString()] = uniqueFeatureId;
|
|
668
524
|
}
|
|
669
525
|
|
|
@@ -671,9 +527,9 @@ function getFeaturesReplaceMap(featureIds, batchTable, featuresHashArray) {
|
|
|
671
527
|
}
|
|
672
528
|
|
|
673
529
|
function generateStringFromBatchTableByIndex(batchTable, index) {
|
|
674
|
-
|
|
530
|
+
let str = '';
|
|
675
531
|
|
|
676
|
-
for (
|
|
532
|
+
for (const key in batchTable) {
|
|
677
533
|
str += batchTable[key][index];
|
|
678
534
|
}
|
|
679
535
|
|
|
@@ -681,8 +537,8 @@ function generateStringFromBatchTableByIndex(batchTable, index) {
|
|
|
681
537
|
}
|
|
682
538
|
|
|
683
539
|
function getOrCreateUniqueFeatureId(index, batchTable, featuresHashArray) {
|
|
684
|
-
|
|
685
|
-
|
|
540
|
+
const batchTableStr = generateStringFromBatchTableByIndex(batchTable, index);
|
|
541
|
+
const hash = (0, _md.default)(batchTableStr);
|
|
686
542
|
|
|
687
543
|
if (featuresHashArray.includes(hash)) {
|
|
688
544
|
return featuresHashArray.indexOf(hash);
|
|
@@ -692,22 +548,23 @@ function getOrCreateUniqueFeatureId(index, batchTable, featuresHashArray) {
|
|
|
692
548
|
}
|
|
693
549
|
|
|
694
550
|
function replaceIndicesByUnique(indicesArray, featureMap) {
|
|
695
|
-
for (
|
|
551
|
+
for (let index = 0; index < indicesArray.length; index++) {
|
|
696
552
|
indicesArray[index] = featureMap[indicesArray[index]];
|
|
697
553
|
}
|
|
698
554
|
}
|
|
699
555
|
|
|
700
556
|
function convertBatchTableToAttributeBuffers(batchTable, featureIds, attributeStorageInfo) {
|
|
701
|
-
|
|
557
|
+
const attributeBuffers = [];
|
|
702
558
|
|
|
703
559
|
if (batchTable) {
|
|
704
|
-
|
|
705
|
-
OBJECTID: featureIds
|
|
706
|
-
|
|
560
|
+
const batchTableWithFeatureIds = {
|
|
561
|
+
OBJECTID: featureIds,
|
|
562
|
+
...batchTable
|
|
563
|
+
};
|
|
707
564
|
|
|
708
|
-
for (
|
|
709
|
-
|
|
710
|
-
|
|
565
|
+
for (const key in batchTableWithFeatureIds) {
|
|
566
|
+
const type = getAttributeType(key, attributeStorageInfo);
|
|
567
|
+
let attributeBuffer = null;
|
|
711
568
|
|
|
712
569
|
switch (type) {
|
|
713
570
|
case OBJECT_ID_TYPE:
|
|
@@ -735,124 +592,104 @@ function convertBatchTableToAttributeBuffers(batchTable, featureIds, attributeSt
|
|
|
735
592
|
}
|
|
736
593
|
|
|
737
594
|
function getAttributeType(key, attributeStorageInfo) {
|
|
738
|
-
|
|
739
|
-
return attr.name === key;
|
|
740
|
-
});
|
|
595
|
+
const attribute = attributeStorageInfo.find(attr => attr.name === key);
|
|
741
596
|
return attribute.attributeValues.valueType;
|
|
742
597
|
}
|
|
743
598
|
|
|
744
599
|
function generateShortIntegerAttributeBuffer(featureIds) {
|
|
745
|
-
|
|
746
|
-
|
|
600
|
+
const count = new Uint32Array([featureIds.length]);
|
|
601
|
+
const valuesArray = new Uint32Array(featureIds);
|
|
747
602
|
return (0, _loaderUtils.concatenateArrayBuffers)(count.buffer, valuesArray.buffer);
|
|
748
603
|
}
|
|
749
604
|
|
|
750
605
|
function generateDoubleAttributeBuffer(featureIds) {
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
606
|
+
const count = new Uint32Array([featureIds.length]);
|
|
607
|
+
const padding = new Uint8Array(4);
|
|
608
|
+
const valuesArray = new Float64Array(featureIds);
|
|
754
609
|
return (0, _loaderUtils.concatenateArrayBuffers)(count.buffer, padding.buffer, valuesArray.buffer);
|
|
755
610
|
}
|
|
756
611
|
|
|
757
612
|
function generateStringAttributeBuffer(batchAttributes) {
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
for (
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
613
|
+
const stringCountArray = new Uint32Array([batchAttributes.length]);
|
|
614
|
+
let totalNumberOfBytes = 0;
|
|
615
|
+
const stringSizesArray = new Uint32Array(batchAttributes.length);
|
|
616
|
+
const stringBufferArray = [];
|
|
617
|
+
|
|
618
|
+
for (let index = 0; index < batchAttributes.length; index++) {
|
|
619
|
+
const currentString = "".concat(String(batchAttributes[index]), "\0");
|
|
620
|
+
const currentStringBuffer = Buffer.from(currentString);
|
|
621
|
+
const currentStringSize = currentStringBuffer.length;
|
|
767
622
|
totalNumberOfBytes += currentStringSize;
|
|
768
623
|
stringSizesArray[index] = currentStringSize;
|
|
769
624
|
stringBufferArray.push(currentStringBuffer);
|
|
770
625
|
}
|
|
771
626
|
|
|
772
|
-
|
|
773
|
-
return _loaderUtils.concatenateArrayBuffers
|
|
627
|
+
const totalBytes = new Uint32Array([totalNumberOfBytes]);
|
|
628
|
+
return (0, _loaderUtils.concatenateArrayBuffers)(stringCountArray.buffer, totalBytes.buffer, stringSizesArray.buffer, ...stringBufferArray);
|
|
774
629
|
}
|
|
775
630
|
|
|
776
631
|
function generateBigUint64Array(featureIds) {
|
|
777
|
-
|
|
632
|
+
const typedFeatureIds = new BigUint64Array(featureIds.length);
|
|
778
633
|
|
|
779
|
-
for (
|
|
634
|
+
for (let index = 0; index < featureIds.length; index++) {
|
|
780
635
|
typedFeatureIds[index] = BigInt(featureIds[index]);
|
|
781
636
|
}
|
|
782
637
|
|
|
783
638
|
return typedFeatureIds;
|
|
784
639
|
}
|
|
785
640
|
|
|
786
|
-
function generateCompressedGeometry(
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
}, _draco.DracoWriter, {
|
|
829
|
-
draco: {
|
|
830
|
-
method: 'MESH_SEQUENTIAL_ENCODING',
|
|
831
|
-
attributesMetadata: attributesMetadata
|
|
832
|
-
}
|
|
833
|
-
});
|
|
834
|
-
|
|
835
|
-
case 11:
|
|
836
|
-
_context3.t1 = _context3.sent;
|
|
837
|
-
return _context3.abrupt("return", new _context3.t0(_context3.t1));
|
|
838
|
-
|
|
839
|
-
case 13:
|
|
840
|
-
case "end":
|
|
841
|
-
return _context3.stop();
|
|
842
|
-
}
|
|
843
|
-
}
|
|
844
|
-
}, _callee3);
|
|
641
|
+
async function generateCompressedGeometry(vertexCount, convertedAttributes, attributes) {
|
|
642
|
+
const {
|
|
643
|
+
positions,
|
|
644
|
+
normals,
|
|
645
|
+
texCoords,
|
|
646
|
+
colors,
|
|
647
|
+
featureIds,
|
|
648
|
+
faceRange
|
|
649
|
+
} = attributes;
|
|
650
|
+
const indices = new Uint32Array(vertexCount);
|
|
651
|
+
|
|
652
|
+
for (let index = 0; index < indices.length; index++) {
|
|
653
|
+
indices.set([index], index);
|
|
654
|
+
}
|
|
655
|
+
|
|
656
|
+
const featureIndices = new Uint32Array(convertedAttributes.featureIndices.length ? convertedAttributes.featureIndices : vertexCount);
|
|
657
|
+
const featureIndex = generateFeatureIndexAttribute(featureIndices, faceRange);
|
|
658
|
+
const compressedAttributes = {
|
|
659
|
+
positions,
|
|
660
|
+
normals,
|
|
661
|
+
colors,
|
|
662
|
+
'feature-index': featureIndex
|
|
663
|
+
};
|
|
664
|
+
|
|
665
|
+
if (texCoords.length) {
|
|
666
|
+
compressedAttributes.texCoords = texCoords;
|
|
667
|
+
}
|
|
668
|
+
|
|
669
|
+
const attributesMetadata = {
|
|
670
|
+
'feature-index': {
|
|
671
|
+
'i3s-attribute-type': 'feature-index',
|
|
672
|
+
'i3s-feature-ids': new Int32Array(featureIds)
|
|
673
|
+
}
|
|
674
|
+
};
|
|
675
|
+
return new Uint8Array(await (0, _core2.encode)({
|
|
676
|
+
attributes: compressedAttributes,
|
|
677
|
+
indices
|
|
678
|
+
}, _draco.DracoWriter, {
|
|
679
|
+
draco: {
|
|
680
|
+
method: 'MESH_SEQUENTIAL_ENCODING',
|
|
681
|
+
attributesMetadata
|
|
682
|
+
}
|
|
845
683
|
}));
|
|
846
|
-
return _generateCompressedGeometry.apply(this, arguments);
|
|
847
684
|
}
|
|
848
685
|
|
|
849
686
|
function generateFeatureIndexAttribute(featureIndex, faceRange) {
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
687
|
+
const orderedFeatureIndices = new Uint32Array(featureIndex.length);
|
|
688
|
+
let fillIndex = 0;
|
|
689
|
+
let startIndex = 0;
|
|
853
690
|
|
|
854
|
-
for (
|
|
855
|
-
|
|
691
|
+
for (let index = 1; index < faceRange.length; index += 2) {
|
|
692
|
+
const endIndex = (faceRange[index] + 1) * VALUES_PER_VERTEX;
|
|
856
693
|
orderedFeatureIndices.fill(fillIndex, startIndex, endIndex);
|
|
857
694
|
fillIndex++;
|
|
858
695
|
startIndex = endIndex + 1;
|