@loaders.gl/i3s 3.4.11 → 3.4.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. package/dist/es5/arcgis-webscene-loader.js +1 -1
  2. package/dist/es5/i3s-attribute-loader.js +1 -1
  3. package/dist/es5/i3s-building-scene-layer-loader.js +1 -1
  4. package/dist/es5/i3s-content-loader.js +1 -1
  5. package/dist/es5/i3s-loader.js +1 -1
  6. package/dist/es5/i3s-node-page-loader.js +1 -1
  7. package/dist/es5/i3s-slpk-loader.js +1 -1
  8. package/dist/esm/arcgis-webscene-loader.js +1 -1
  9. package/dist/esm/i3s-attribute-loader.js +1 -1
  10. package/dist/esm/i3s-building-scene-layer-loader.js +1 -1
  11. package/dist/esm/i3s-content-loader.js +1 -1
  12. package/dist/esm/i3s-loader.js +1 -1
  13. package/dist/esm/i3s-node-page-loader.js +1 -1
  14. package/dist/esm/i3s-slpk-loader.js +1 -1
  15. package/dist/i3s-content-nodejs-worker.js +2 -2
  16. package/dist/i3s-content-worker.js +8 -8
  17. package/package.json +9 -9
  18. package/dist/arcgis-webscene-loader.js +0 -28
  19. package/dist/bundle.js +0 -5
  20. package/dist/i3s-attribute-loader.js +0 -178
  21. package/dist/i3s-building-scene-layer-loader.js +0 -26
  22. package/dist/i3s-content-loader.js +0 -33
  23. package/dist/i3s-loader.js +0 -102
  24. package/dist/i3s-node-page-loader.js +0 -26
  25. package/dist/i3s-slpk-loader.js +0 -20
  26. package/dist/index.js +0 -18
  27. package/dist/lib/helpers/i3s-nodepages-tiles.js +0 -242
  28. package/dist/lib/parsers/constants.js +0 -89
  29. package/dist/lib/parsers/parse-arcgis-webscene.js +0 -87
  30. package/dist/lib/parsers/parse-i3s-attribute.js +0 -98
  31. package/dist/lib/parsers/parse-i3s-building-scene-layer.js +0 -46
  32. package/dist/lib/parsers/parse-i3s-tile-content.js +0 -494
  33. package/dist/lib/parsers/parse-i3s.js +0 -95
  34. package/dist/lib/parsers/parse-slpk/parse-slpk.js +0 -50
  35. package/dist/lib/parsers/parse-slpk/slpk-archieve.js +0 -79
  36. package/dist/lib/parsers/parse-zip/cd-file-header.js +0 -48
  37. package/dist/lib/parsers/parse-zip/local-file-header.js +0 -28
  38. package/dist/lib/utils/convert-i3s-obb-to-mbs.js +0 -20
  39. package/dist/lib/utils/customizeColors.js +0 -89
  40. package/dist/lib/utils/url-utils.js +0 -44
  41. package/dist/types.js +0 -20
  42. package/dist/workers/i3s-content-nodejs-worker.js +0 -6
  43. package/dist/workers/i3s-content-worker.js +0 -5
@@ -1,494 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.parseI3STileContent = void 0;
4
- const core_1 = require("@loaders.gl/core");
5
- const core_2 = require("@math.gl/core");
6
- const geospatial_1 = require("@math.gl/geospatial");
7
- const images_1 = require("@loaders.gl/images");
8
- const draco_1 = require("@loaders.gl/draco");
9
- const textures_1 = require("@loaders.gl/textures");
10
- const types_1 = require("../../types");
11
- const url_utils_1 = require("../utils/url-utils");
12
- const constants_1 = require("./constants");
13
- const customizeColors_1 = require("../utils/customizeColors");
14
- const scratchVector = new core_2.Vector3([0, 0, 0]);
15
- function getLoaderForTextureFormat(textureFormat) {
16
- switch (textureFormat) {
17
- case 'ktx-etc2':
18
- case 'dds':
19
- return textures_1.CompressedTextureLoader;
20
- case 'ktx2':
21
- return textures_1.BasisLoader;
22
- case 'jpg':
23
- case 'png':
24
- default:
25
- return images_1.ImageLoader;
26
- }
27
- }
28
- const I3S_ATTRIBUTE_TYPE = 'i3s-attribute-type';
29
- async function parseI3STileContent(arrayBuffer, tileOptions, tilesetOptions, options, context) {
30
- const content = {
31
- attributes: {},
32
- indices: null,
33
- featureIds: [],
34
- vertexCount: 0,
35
- modelMatrix: new core_2.Matrix4(),
36
- coordinateSystem: 0,
37
- byteLength: 0,
38
- texture: null
39
- };
40
- if (tileOptions.textureUrl) {
41
- // @ts-expect-error options is not properly typed
42
- const url = (0, url_utils_1.getUrlWithToken)(tileOptions.textureUrl, options?.i3s?.token);
43
- const loader = getLoaderForTextureFormat(tileOptions.textureFormat);
44
- const response = await fetch(url, options?.fetch);
45
- const arrayBuffer = await response.arrayBuffer();
46
- // @ts-expect-error options is not properly typed
47
- if (options?.i3s.decodeTextures) {
48
- if (loader === images_1.ImageLoader) {
49
- const options = { ...tileOptions.textureLoaderOptions, image: { type: 'data' } };
50
- try {
51
- // @ts-ignore context must be defined
52
- // Image constructor is not supported in worker thread.
53
- // Do parsing image data on the main thread by using context to avoid worker issues.
54
- content.texture = await context.parse(arrayBuffer, options);
55
- }
56
- catch (e) {
57
- // context object is different between worker and node.js conversion script.
58
- // To prevent error we parse data in ordinary way if it is not parsed by using context.
59
- content.texture = await (0, core_1.parse)(arrayBuffer, loader, options);
60
- }
61
- }
62
- else if (loader === textures_1.CompressedTextureLoader || loader === textures_1.BasisLoader) {
63
- let texture = await (0, core_1.load)(arrayBuffer, loader, tileOptions.textureLoaderOptions);
64
- if (loader === textures_1.BasisLoader) {
65
- texture = texture[0];
66
- }
67
- content.texture = {
68
- compressed: true,
69
- mipmaps: false,
70
- width: texture[0].width,
71
- height: texture[0].height,
72
- data: texture
73
- };
74
- }
75
- }
76
- else {
77
- content.texture = arrayBuffer;
78
- }
79
- }
80
- content.material = makePbrMaterial(tileOptions.materialDefinition, content.texture);
81
- if (content.material) {
82
- content.texture = null;
83
- }
84
- return await parseI3SNodeGeometry(arrayBuffer, content, tileOptions, tilesetOptions, options);
85
- }
86
- exports.parseI3STileContent = parseI3STileContent;
87
- /* eslint-disable max-statements */
88
- async function parseI3SNodeGeometry(arrayBuffer, content, tileOptions, tilesetOptions, options) {
89
- const contentByteLength = arrayBuffer.byteLength;
90
- let attributes;
91
- let vertexCount;
92
- let byteOffset = 0;
93
- let featureCount = 0;
94
- let indices;
95
- if (tileOptions.isDracoGeometry) {
96
- const decompressedGeometry = await (0, core_1.parse)(arrayBuffer, draco_1.DracoLoader, {
97
- draco: {
98
- attributeNameEntry: I3S_ATTRIBUTE_TYPE
99
- }
100
- });
101
- // @ts-expect-error
102
- vertexCount = decompressedGeometry.header.vertexCount;
103
- indices = decompressedGeometry.indices?.value;
104
- const { POSITION, NORMAL, COLOR_0, TEXCOORD_0, ['feature-index']: featureIndex, ['uv-region']: uvRegion } = decompressedGeometry.attributes;
105
- attributes = {
106
- position: POSITION,
107
- normal: NORMAL,
108
- color: COLOR_0,
109
- uv0: TEXCOORD_0,
110
- uvRegion,
111
- id: featureIndex
112
- };
113
- updateAttributesMetadata(attributes, decompressedGeometry);
114
- const featureIds = getFeatureIdsFromFeatureIndexMetadata(featureIndex);
115
- if (featureIds) {
116
- flattenFeatureIdsByFeatureIndices(attributes, featureIds);
117
- }
118
- }
119
- else {
120
- const { vertexAttributes, ordering: attributesOrder, featureAttributes, featureAttributeOrder } = tilesetOptions.store.defaultGeometrySchema;
121
- // First 8 bytes reserved for header (vertexCount and featureCount)
122
- const headers = parseHeaders(arrayBuffer, tilesetOptions);
123
- byteOffset = headers.byteOffset;
124
- vertexCount = headers.vertexCount;
125
- featureCount = headers.featureCount;
126
- // Getting vertex attributes such as positions, normals, colors, etc...
127
- const { attributes: normalizedVertexAttributes, byteOffset: offset } = normalizeAttributes(arrayBuffer, byteOffset, vertexAttributes, vertexCount, attributesOrder);
128
- // Getting feature attributes such as featureIds and faceRange
129
- const { attributes: normalizedFeatureAttributes } = normalizeAttributes(arrayBuffer, offset, featureAttributes, featureCount, featureAttributeOrder);
130
- flattenFeatureIdsByFaceRanges(normalizedFeatureAttributes);
131
- attributes = concatAttributes(normalizedVertexAttributes, normalizedFeatureAttributes);
132
- }
133
- if (!options?.i3s?.coordinateSystem ||
134
- options.i3s.coordinateSystem === constants_1.COORDINATE_SYSTEM.METER_OFFSETS) {
135
- const enuMatrix = parsePositions(attributes.position, tileOptions);
136
- content.modelMatrix = enuMatrix.invert();
137
- content.coordinateSystem = constants_1.COORDINATE_SYSTEM.METER_OFFSETS;
138
- }
139
- else {
140
- content.modelMatrix = getModelMatrix(attributes.position);
141
- content.coordinateSystem = constants_1.COORDINATE_SYSTEM.LNGLAT_OFFSETS;
142
- }
143
- attributes.color = await (0, customizeColors_1.customizeColors)(attributes.color, attributes.id, tileOptions, tilesetOptions, options);
144
- content.attributes = {
145
- positions: attributes.position,
146
- normals: attributes.normal,
147
- colors: normalizeAttribute(attributes.color),
148
- texCoords: attributes.uv0,
149
- uvRegions: normalizeAttribute(attributes.uvRegion || attributes.region) // Normalize from UInt16
150
- };
151
- content.indices = indices || null;
152
- if (attributes.id && attributes.id.value) {
153
- content.featureIds = attributes.id.value;
154
- }
155
- // Remove undefined attributes
156
- for (const attributeIndex in content.attributes) {
157
- if (!content.attributes[attributeIndex]) {
158
- delete content.attributes[attributeIndex];
159
- }
160
- }
161
- content.vertexCount = vertexCount;
162
- content.byteLength = contentByteLength;
163
- return content;
164
- }
165
- /**
166
- * Update attributes with metadata from decompressed geometry.
167
- * @param decompressedGeometry
168
- * @param attributes
169
- */
170
- function updateAttributesMetadata(attributes, decompressedGeometry) {
171
- for (const key in decompressedGeometry.loaderData.attributes) {
172
- const dracoAttribute = decompressedGeometry.loaderData.attributes[key];
173
- switch (dracoAttribute.name) {
174
- case 'POSITION':
175
- attributes.position.metadata = dracoAttribute.metadata;
176
- break;
177
- case 'feature-index':
178
- attributes.id.metadata = dracoAttribute.metadata;
179
- break;
180
- default:
181
- break;
182
- }
183
- }
184
- }
185
- /**
186
- * Do concatenation of attribute objects.
187
- * Done as separate fucntion to avoid ts errors.
188
- * @param normalizedVertexAttributes
189
- * @param normalizedFeatureAttributes
190
- * @returns - result of attributes concatenation.
191
- */
192
- function concatAttributes(normalizedVertexAttributes, normalizedFeatureAttributes) {
193
- return { ...normalizedVertexAttributes, ...normalizedFeatureAttributes };
194
- }
195
- /**
196
- * Normalize attribute to range [0..1] . Eg. convert colors buffer from [255,255,255,255] to [1,1,1,1]
197
- * @param attribute - geometry attribute
198
- * @returns - geometry attribute in right format
199
- */
200
- function normalizeAttribute(attribute) {
201
- if (!attribute) {
202
- return attribute;
203
- }
204
- attribute.normalized = true;
205
- return attribute;
206
- }
207
- function parseHeaders(arrayBuffer, options) {
208
- let byteOffset = 0;
209
- // First 8 bytes reserved for header (vertexCount and featurecount)
210
- let vertexCount = 0;
211
- let featureCount = 0;
212
- for (const { property, type } of options.store.defaultGeometrySchema.header) {
213
- const TypedArrayTypeHeader = (0, constants_1.getConstructorForDataFormat)(type);
214
- switch (property) {
215
- case types_1.HeaderAttributeProperty.vertexCount:
216
- vertexCount = new TypedArrayTypeHeader(arrayBuffer, 0, 4)[0];
217
- byteOffset += (0, constants_1.sizeOf)(type);
218
- break;
219
- case types_1.HeaderAttributeProperty.featureCount:
220
- featureCount = new TypedArrayTypeHeader(arrayBuffer, 4, 4)[0];
221
- byteOffset += (0, constants_1.sizeOf)(type);
222
- break;
223
- default:
224
- break;
225
- }
226
- }
227
- return {
228
- vertexCount,
229
- featureCount,
230
- byteOffset
231
- };
232
- }
233
- /* eslint-enable max-statements */
234
- function normalizeAttributes(arrayBuffer, byteOffset, vertexAttributes, attributeCount, attributesOrder) {
235
- const attributes = {};
236
- // the order of attributes depend on the order being added to the vertexAttributes object
237
- for (const attribute of attributesOrder) {
238
- if (vertexAttributes[attribute]) {
239
- const { valueType, valuesPerElement } = vertexAttributes[attribute];
240
- // protect from arrayBuffer read overunns by NOT assuming node has regions always even though its declared in defaultGeometrySchema.
241
- // In i3s 1.6: client is required to decide that based on ./shared resource of the node (materialDefinitions.[Mat_id].params.vertexRegions == true)
242
- // In i3s 1.7 the property has been rolled into the 3d scene layer json/node pages.
243
- // Code below does not account when the bytelength is actually bigger than
244
- // the calculated value (b\c the tile potentially could have mesh segmentation information).
245
- // In those cases tiles without regions could fail or have garbage values.
246
- if (byteOffset + attributeCount * valuesPerElement * (0, constants_1.sizeOf)(valueType) <=
247
- arrayBuffer.byteLength) {
248
- const buffer = arrayBuffer.slice(byteOffset);
249
- let value;
250
- if (valueType === 'UInt64') {
251
- value = parseUint64Values(buffer, attributeCount * valuesPerElement, (0, constants_1.sizeOf)(valueType));
252
- }
253
- else {
254
- const TypedArrayType = (0, constants_1.getConstructorForDataFormat)(valueType);
255
- value = new TypedArrayType(buffer, 0, attributeCount * valuesPerElement);
256
- }
257
- attributes[attribute] = {
258
- value,
259
- type: constants_1.GL_TYPE_MAP[valueType],
260
- size: valuesPerElement
261
- };
262
- switch (attribute) {
263
- case 'color':
264
- attributes.color.normalized = true;
265
- break;
266
- case 'position':
267
- case 'region':
268
- case 'normal':
269
- default:
270
- }
271
- byteOffset = byteOffset + attributeCount * valuesPerElement * (0, constants_1.sizeOf)(valueType);
272
- }
273
- else if (attribute !== 'uv0') {
274
- break;
275
- }
276
- }
277
- }
278
- return { attributes, byteOffset };
279
- }
280
- /**
281
- * Parse buffer to return array of uint64 values
282
- *
283
- * @param buffer
284
- * @param elementsCount
285
- * @returns 64-bit array of values until precision is lost after Number.MAX_SAFE_INTEGER
286
- */
287
- function parseUint64Values(buffer, elementsCount, attributeSize) {
288
- const values = [];
289
- const dataView = new DataView(buffer);
290
- let offset = 0;
291
- for (let index = 0; index < elementsCount; index++) {
292
- // split 64-bit number into two 32-bit parts
293
- const left = dataView.getUint32(offset, true);
294
- const right = dataView.getUint32(offset + 4, true);
295
- // combine the two 32-bit values
296
- const value = left + 2 ** 32 * right;
297
- values.push(value);
298
- offset += attributeSize;
299
- }
300
- return new Uint32Array(values);
301
- }
302
- function parsePositions(attribute, options) {
303
- const mbs = options.mbs;
304
- const value = attribute.value;
305
- const metadata = attribute.metadata;
306
- const enuMatrix = new core_2.Matrix4();
307
- const cartographicOrigin = new core_2.Vector3(mbs[0], mbs[1], mbs[2]);
308
- const cartesianOrigin = new core_2.Vector3();
309
- geospatial_1.Ellipsoid.WGS84.cartographicToCartesian(cartographicOrigin, cartesianOrigin);
310
- geospatial_1.Ellipsoid.WGS84.eastNorthUpToFixedFrame(cartesianOrigin, enuMatrix);
311
- attribute.value = offsetsToCartesians(value, metadata, cartographicOrigin);
312
- return enuMatrix;
313
- }
314
- /**
315
- * Converts position coordinates to absolute cartesian coordinates
316
- * @param vertices - "position" attribute data
317
- * @param metadata - When the geometry is DRACO compressed, contain position attribute's metadata
318
- * https://github.com/Esri/i3s-spec/blob/master/docs/1.7/compressedAttributes.cmn.md
319
- * @param cartographicOrigin - Cartographic origin coordinates
320
- * @returns - converted "position" data
321
- */
322
- function offsetsToCartesians(vertices, metadata = {}, cartographicOrigin) {
323
- const positions = new Float64Array(vertices.length);
324
- const scaleX = (metadata['i3s-scale_x'] && metadata['i3s-scale_x'].double) || 1;
325
- const scaleY = (metadata['i3s-scale_y'] && metadata['i3s-scale_y'].double) || 1;
326
- for (let i = 0; i < positions.length; i += 3) {
327
- positions[i] = vertices[i] * scaleX + cartographicOrigin.x;
328
- positions[i + 1] = vertices[i + 1] * scaleY + cartographicOrigin.y;
329
- positions[i + 2] = vertices[i + 2] + cartographicOrigin.z;
330
- }
331
- for (let i = 0; i < positions.length; i += 3) {
332
- // @ts-ignore
333
- geospatial_1.Ellipsoid.WGS84.cartographicToCartesian(positions.subarray(i, i + 3), scratchVector);
334
- positions[i] = scratchVector.x;
335
- positions[i + 1] = scratchVector.y;
336
- positions[i + 2] = scratchVector.z;
337
- }
338
- return positions;
339
- }
340
- /**
341
- * Get model matrix for loaded vertices
342
- * @param positions positions attribute
343
- * @returns Matrix4 - model matrix for geometry transformation
344
- */
345
- function getModelMatrix(positions) {
346
- const metadata = positions.metadata;
347
- const scaleX = metadata?.['i3s-scale_x']?.double || 1;
348
- const scaleY = metadata?.['i3s-scale_y']?.double || 1;
349
- const modelMatrix = new core_2.Matrix4();
350
- modelMatrix[0] = scaleX;
351
- modelMatrix[5] = scaleY;
352
- return modelMatrix;
353
- }
354
- /**
355
- * Makes a glTF-compatible PBR material from an I3S material definition
356
- * @param materialDefinition - i3s material definition
357
- * https://github.com/Esri/i3s-spec/blob/master/docs/1.7/materialDefinitions.cmn.md
358
- * @param texture - texture image
359
- * @returns {object}
360
- */
361
- function makePbrMaterial(materialDefinition, texture) {
362
- let pbrMaterial;
363
- if (materialDefinition) {
364
- pbrMaterial = {
365
- ...materialDefinition,
366
- pbrMetallicRoughness: materialDefinition.pbrMetallicRoughness
367
- ? { ...materialDefinition.pbrMetallicRoughness }
368
- : { baseColorFactor: [255, 255, 255, 255] }
369
- };
370
- }
371
- else {
372
- pbrMaterial = {
373
- pbrMetallicRoughness: {}
374
- };
375
- if (texture) {
376
- pbrMaterial.pbrMetallicRoughness.baseColorTexture = { texCoord: 0 };
377
- }
378
- else {
379
- pbrMaterial.pbrMetallicRoughness.baseColorFactor = [255, 255, 255, 255];
380
- }
381
- }
382
- // Set default 0.25 per spec https://github.com/Esri/i3s-spec/blob/master/docs/1.7/materialDefinitions.cmn.md
383
- pbrMaterial.alphaCutoff = pbrMaterial.alphaCutoff || 0.25;
384
- if (pbrMaterial.alphaMode) {
385
- // I3S contain alphaMode in lowerCase
386
- pbrMaterial.alphaMode = pbrMaterial.alphaMode.toUpperCase();
387
- }
388
- // Convert colors from [255,255,255,255] to [1,1,1,1]
389
- if (pbrMaterial.emissiveFactor) {
390
- pbrMaterial.emissiveFactor = convertColorFormat(pbrMaterial.emissiveFactor);
391
- }
392
- if (pbrMaterial.pbrMetallicRoughness && pbrMaterial.pbrMetallicRoughness.baseColorFactor) {
393
- pbrMaterial.pbrMetallicRoughness.baseColorFactor = convertColorFormat(pbrMaterial.pbrMetallicRoughness.baseColorFactor);
394
- }
395
- if (texture) {
396
- setMaterialTexture(pbrMaterial, texture);
397
- }
398
- return pbrMaterial;
399
- }
400
- /**
401
- * Convert color from [255,255,255,255] to [1,1,1,1]
402
- * @param colorFactor - color array
403
- * @returns - new color array
404
- */
405
- function convertColorFormat(colorFactor) {
406
- const normalizedColor = [...colorFactor];
407
- for (let index = 0; index < colorFactor.length; index++) {
408
- normalizedColor[index] = colorFactor[index] / 255;
409
- }
410
- return normalizedColor;
411
- }
412
- /**
413
- * Set texture in PBR material
414
- * @param {object} material - i3s material definition
415
- * @param image - texture image
416
- * @returns
417
- */
418
- function setMaterialTexture(material, image) {
419
- const texture = { source: { image } };
420
- // I3SLoader now support loading only one texture. This elseif sequence will assign this texture to one of
421
- // properties defined in materialDefinition
422
- if (material.pbrMetallicRoughness && material.pbrMetallicRoughness.baseColorTexture) {
423
- material.pbrMetallicRoughness.baseColorTexture = {
424
- ...material.pbrMetallicRoughness.baseColorTexture,
425
- texture
426
- };
427
- }
428
- else if (material.emissiveTexture) {
429
- material.emissiveTexture = { ...material.emissiveTexture, texture };
430
- }
431
- else if (material.pbrMetallicRoughness &&
432
- material.pbrMetallicRoughness.metallicRoughnessTexture) {
433
- material.pbrMetallicRoughness.metallicRoughnessTexture = {
434
- ...material.pbrMetallicRoughness.metallicRoughnessTexture,
435
- texture
436
- };
437
- }
438
- else if (material.normalTexture) {
439
- material.normalTexture = { ...material.normalTexture, texture };
440
- }
441
- else if (material.occlusionTexture) {
442
- material.occlusionTexture = { ...material.occlusionTexture, texture };
443
- }
444
- }
445
- /**
446
- * Flatten feature ids using face ranges
447
- * @param normalizedFeatureAttributes
448
- * @returns
449
- */
450
- function flattenFeatureIdsByFaceRanges(normalizedFeatureAttributes) {
451
- const { id, faceRange } = normalizedFeatureAttributes;
452
- if (!id || !faceRange) {
453
- return;
454
- }
455
- const featureIds = id.value;
456
- const range = faceRange.value;
457
- const featureIdsLength = range[range.length - 1] + 1;
458
- const orderedFeatureIndices = new Uint32Array(featureIdsLength * 3);
459
- let featureIndex = 0;
460
- let startIndex = 0;
461
- for (let index = 1; index < range.length; index += 2) {
462
- const fillId = Number(featureIds[featureIndex]);
463
- const endValue = range[index];
464
- const prevValue = range[index - 1];
465
- const trianglesCount = endValue - prevValue + 1;
466
- const endIndex = startIndex + trianglesCount * 3;
467
- orderedFeatureIndices.fill(fillId, startIndex, endIndex);
468
- featureIndex++;
469
- startIndex = endIndex;
470
- }
471
- normalizedFeatureAttributes.id.value = orderedFeatureIndices;
472
- }
473
- /**
474
- * Flatten feature ids using featureIndices
475
- * @param attributes
476
- * @param featureIds
477
- * @returns
478
- */
479
- function flattenFeatureIdsByFeatureIndices(attributes, featureIds) {
480
- const featureIndices = attributes.id.value;
481
- const result = new Float32Array(featureIndices.length);
482
- for (let index = 0; index < featureIndices.length; index++) {
483
- result[index] = featureIds[featureIndices[index]];
484
- }
485
- attributes.id.value = result;
486
- }
487
- /**
488
- * Flatten feature ids using featureIndices
489
- * @param featureIndex
490
- * @returns
491
- */
492
- function getFeatureIdsFromFeatureIndexMetadata(featureIndex) {
493
- return featureIndex?.metadata?.['i3s-feature-ids']?.intArray;
494
- }
@@ -1,95 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.normalizeTilesetData = exports.normalizeTileNonUrlData = exports.normalizeTileData = void 0;
7
- const culling_1 = require("@math.gl/culling");
8
- const geospatial_1 = require("@math.gl/geospatial");
9
- const core_1 = require("@loaders.gl/core");
10
- const tiles_1 = require("@loaders.gl/tiles");
11
- const i3s_nodepages_tiles_1 = __importDefault(require("../helpers/i3s-nodepages-tiles"));
12
- const url_utils_1 = require("../utils/url-utils");
13
- function normalizeTileData(tile, context) {
14
- const url = context.url || '';
15
- let contentUrl;
16
- if (tile.geometryData) {
17
- contentUrl = `${url}/${tile.geometryData[0].href}`;
18
- }
19
- let textureUrl;
20
- if (tile.textureData) {
21
- textureUrl = `${url}/${tile.textureData[0].href}`;
22
- }
23
- let attributeUrls;
24
- if (tile.attributeData) {
25
- attributeUrls = (0, url_utils_1.generateTileAttributeUrls)(url, tile);
26
- }
27
- return normalizeTileNonUrlData({
28
- ...tile,
29
- url,
30
- contentUrl,
31
- textureUrl,
32
- attributeUrls,
33
- isDracoGeometry: false
34
- });
35
- }
36
- exports.normalizeTileData = normalizeTileData;
37
- function normalizeTileNonUrlData(tile) {
38
- const boundingVolume = {};
39
- let mbs = [0, 0, 0, 1];
40
- if (tile.mbs) {
41
- mbs = tile.mbs;
42
- boundingVolume.sphere = [
43
- ...geospatial_1.Ellipsoid.WGS84.cartographicToCartesian(tile.mbs.slice(0, 3)),
44
- tile.mbs[3] // radius of sphere
45
- ];
46
- }
47
- else if (tile.obb) {
48
- boundingVolume.box = [
49
- ...geospatial_1.Ellipsoid.WGS84.cartographicToCartesian(tile.obb.center),
50
- ...tile.obb.halfSize,
51
- ...tile.obb.quaternion // quaternion
52
- ];
53
- const obb = new culling_1.OrientedBoundingBox().fromCenterHalfSizeQuaternion(boundingVolume.box.slice(0, 3), tile.obb.halfSize, tile.obb.quaternion);
54
- const boundingSphere = obb.getBoundingSphere();
55
- boundingVolume.sphere = [...boundingSphere.center, boundingSphere.radius];
56
- mbs = [...tile.obb.center, boundingSphere.radius];
57
- }
58
- const lodMetricType = tile.lodSelection?.[0].metricType;
59
- const lodMetricValue = tile.lodSelection?.[0].maxError;
60
- const transformMatrix = tile.transform;
61
- const type = tiles_1.TILE_TYPE.MESH;
62
- /**
63
- * I3S specification supports only REPLACE
64
- */
65
- const refine = tiles_1.TILE_REFINEMENT.REPLACE;
66
- return { ...tile, mbs, boundingVolume, lodMetricType, lodMetricValue, transformMatrix, type, refine };
67
- }
68
- exports.normalizeTileNonUrlData = normalizeTileNonUrlData;
69
- async function normalizeTilesetData(tileset, options, context) {
70
- tileset.url = context.url;
71
- if (tileset.nodePages) {
72
- tileset.nodePagesTile = new i3s_nodepages_tiles_1.default(tileset, options);
73
- tileset.root = tileset.nodePagesTile.formTileFromNodePages(0);
74
- }
75
- else {
76
- // @ts-expect-error options is not properly typed
77
- const rootNodeUrl = (0, url_utils_1.getUrlWithToken)(`${tileset.url}/nodes/root`, options.i3s?.token);
78
- // eslint-disable-next-line no-use-before-define
79
- tileset.root = await (0, core_1.load)(rootNodeUrl, tileset.loader, {
80
- ...options,
81
- i3s: {
82
- // @ts-expect-error options is not properly typed
83
- ...options.i3s,
84
- loadContent: false, isTileHeader: true, isTileset: false
85
- }
86
- });
87
- }
88
- // base path that non-absolute paths in tileset are relative to.
89
- tileset.basePath = tileset.url;
90
- tileset.type = tiles_1.TILESET_TYPE.I3S;
91
- // populate from root node
92
- tileset.lodMetricType = tileset.root.lodMetricType;
93
- tileset.lodMetricValue = tileset.root.lodMetricValue;
94
- }
95
- exports.normalizeTilesetData = normalizeTilesetData;
@@ -1,50 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.parseSLPK = void 0;
4
- const cd_file_header_1 = require("../parse-zip/cd-file-header");
5
- const local_file_header_1 = require("../parse-zip/local-file-header");
6
- const slpk_archieve_1 = require("./slpk-archieve");
7
- /**
8
- * Returns one byte from the provided buffer at the provided position
9
- * @param offset - position where to read
10
- * @param buffer - buffer to read
11
- * @returns one byte from the provided buffer at the provided position
12
- */
13
- const getByteAt = (offset, buffer) => {
14
- return buffer.getUint8(buffer.byteOffset + offset);
15
- };
16
- async function parseSLPK(data, options = {}) {
17
- const archive = new DataView(data);
18
- const cdFileHeaderSignature = [80, 75, 1, 2];
19
- const searchWindow = [
20
- getByteAt(archive.byteLength - 1, archive),
21
- getByteAt(archive.byteLength - 2, archive),
22
- getByteAt(archive.byteLength - 3, archive),
23
- undefined
24
- ];
25
- let hashCDOffset = 0;
26
- // looking for the last record in the central directory
27
- for (let i = archive.byteLength - 4; i > -1; i--) {
28
- searchWindow[3] = searchWindow[2];
29
- searchWindow[2] = searchWindow[1];
30
- searchWindow[1] = searchWindow[0];
31
- searchWindow[0] = getByteAt(i, archive);
32
- if (searchWindow.every((val, index) => val === cdFileHeaderSignature[index])) {
33
- hashCDOffset = i;
34
- break;
35
- }
36
- }
37
- const cdFileHeader = (0, cd_file_header_1.parseZipCDFileHeader)(hashCDOffset, archive);
38
- const textDecoder = new TextDecoder();
39
- if (textDecoder.decode(cdFileHeader.fileName) !== '@specialIndexFileHASH128@') {
40
- throw new Error('No hash file in slpk');
41
- }
42
- const localFileHeader = (0, local_file_header_1.parseZipLocalFileHeader)(cdFileHeader.localHeaderOffset, archive);
43
- const fileDataOffset = localFileHeader.fileDataOffset;
44
- const hashFile = archive.buffer.slice(fileDataOffset, fileDataOffset + localFileHeader.compressedSize);
45
- if (!hashFile) {
46
- throw new Error('No hash file in slpk');
47
- }
48
- return await new slpk_archieve_1.SLPKArchive(data, hashFile).getFile(options.path ?? '');
49
- }
50
- exports.parseSLPK = parseSLPK;