@loaders.gl/i3s 3.1.0-alpha.5 → 3.1.0-beta.7
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/bundle.d.ts +1 -0
- package/dist/bundle.d.ts.map +1 -0
- package/dist/bundle.js +10364 -0
- package/dist/es5/i3s-attribute-loader.js +1 -1
- package/dist/es5/i3s-attribute-loader.js.map +1 -1
- package/dist/es5/i3s-building-scene-layer-loader.js +1 -1
- package/dist/es5/i3s-building-scene-layer-loader.js.map +1 -1
- package/dist/es5/i3s-content-loader.js +1 -1
- package/dist/es5/i3s-content-loader.js.map +1 -1
- package/dist/es5/i3s-loader.js +1 -1
- package/dist/es5/i3s-loader.js.map +1 -1
- package/dist/es5/i3s-node-page-loader.js +1 -1
- package/dist/es5/i3s-node-page-loader.js.map +1 -1
- package/dist/es5/lib/parsers/constants.js +61 -25
- package/dist/es5/lib/parsers/constants.js.map +1 -1
- package/dist/es5/lib/parsers/parse-i3s-tile-content.js +42 -36
- package/dist/es5/lib/parsers/parse-i3s-tile-content.js.map +1 -1
- package/dist/es5/lib/utils/url-utils.js.map +1 -1
- package/dist/es5/types.js +19 -0
- package/dist/es5/types.js.map +1 -1
- package/dist/esm/i3s-attribute-loader.js +1 -1
- package/dist/esm/i3s-attribute-loader.js.map +1 -1
- package/dist/esm/i3s-building-scene-layer-loader.js +1 -1
- package/dist/esm/i3s-building-scene-layer-loader.js.map +1 -1
- package/dist/esm/i3s-content-loader.js +1 -1
- package/dist/esm/i3s-content-loader.js.map +1 -1
- package/dist/esm/i3s-loader.js +1 -1
- package/dist/esm/i3s-loader.js.map +1 -1
- package/dist/esm/i3s-node-page-loader.js +1 -1
- package/dist/esm/i3s-node-page-loader.js.map +1 -1
- package/dist/esm/lib/parsers/constants.js +54 -22
- package/dist/esm/lib/parsers/constants.js.map +1 -1
- package/dist/esm/lib/parsers/parse-i3s-tile-content.js +41 -37
- package/dist/esm/lib/parsers/parse-i3s-tile-content.js.map +1 -1
- package/dist/esm/lib/utils/url-utils.js.map +1 -1
- package/dist/esm/types.js +13 -1
- package/dist/esm/types.js.map +1 -1
- package/dist/i3s-attribute-loader.d.ts +1 -0
- package/dist/i3s-attribute-loader.d.ts.map +1 -0
- package/dist/i3s-attribute-loader.js +177 -0
- package/dist/i3s-building-scene-layer-loader.d.ts +1 -0
- package/dist/i3s-building-scene-layer-loader.d.ts.map +1 -0
- package/dist/i3s-building-scene-layer-loader.js +26 -0
- package/dist/i3s-content-loader.d.ts +1 -0
- package/dist/i3s-content-loader.d.ts.map +1 -0
- package/dist/i3s-content-loader.js +28 -0
- package/dist/i3s-content-worker.js +7657 -2
- package/dist/i3s-loader.d.ts +1 -0
- package/dist/i3s-loader.d.ts.map +1 -0
- package/dist/i3s-loader.js +100 -0
- package/dist/i3s-node-page-loader.d.ts +1 -0
- package/dist/i3s-node-page-loader.d.ts.map +1 -0
- package/dist/i3s-node-page-loader.js +26 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +14 -0
- package/dist/lib/helpers/i3s-nodepages-tiles.d.ts +1 -0
- package/dist/lib/helpers/i3s-nodepages-tiles.d.ts.map +1 -0
- package/dist/lib/helpers/i3s-nodepages-tiles.js +231 -0
- package/dist/lib/parsers/constants.d.ts +34 -27
- package/dist/lib/parsers/constants.d.ts.map +1 -0
- package/dist/lib/parsers/constants.js +107 -0
- package/dist/lib/parsers/parse-i3s-attribute.d.ts +2 -1
- package/dist/lib/parsers/parse-i3s-attribute.d.ts.map +1 -0
- package/dist/lib/parsers/parse-i3s-attribute.js +98 -0
- package/dist/lib/parsers/parse-i3s-building-scene-layer.d.ts +1 -0
- package/dist/lib/parsers/parse-i3s-building-scene-layer.d.ts.map +1 -0
- package/dist/lib/parsers/parse-i3s-building-scene-layer.js +46 -0
- package/dist/lib/parsers/parse-i3s-tile-content.d.ts +2 -1
- package/dist/lib/parsers/parse-i3s-tile-content.d.ts.map +1 -0
- package/dist/lib/parsers/parse-i3s-tile-content.js +508 -0
- package/dist/lib/parsers/parse-i3s.d.ts +1 -0
- package/dist/lib/parsers/parse-i3s.d.ts.map +1 -0
- package/dist/lib/parsers/parse-i3s.js +84 -0
- package/dist/lib/utils/convert-i3s-obb-to-mbs.d.ts +1 -0
- package/dist/lib/utils/convert-i3s-obb-to-mbs.d.ts.map +1 -0
- package/dist/lib/utils/convert-i3s-obb-to-mbs.js +20 -0
- package/dist/lib/utils/url-utils.d.ts +2 -1
- package/dist/lib/utils/url-utils.d.ts.map +1 -0
- package/dist/lib/utils/url-utils.js +44 -0
- package/dist/types.d.ts +98 -13
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +15 -0
- package/dist/workers/i3s-content-worker.d.ts +1 -0
- package/dist/workers/i3s-content-worker.d.ts.map +1 -0
- package/dist/workers/i3s-content-worker.js +5 -0
- package/package.json +11 -12
- package/src/lib/parsers/constants.ts +69 -36
- package/src/lib/parsers/parse-i3s-tile-content.ts +110 -85
- package/src/lib/utils/url-utils.ts +1 -1
- package/src/types.ts +153 -22
- package/dist/dist.min.js +0 -2
- package/dist/dist.min.js.map +0 -1
- package/dist/i3s-content-worker.js.map +0 -1
|
@@ -3,18 +3,28 @@ import {load, parse} from '@loaders.gl/core';
|
|
|
3
3
|
import {Vector3, Matrix4} from '@math.gl/core';
|
|
4
4
|
import {Ellipsoid} from '@math.gl/geospatial';
|
|
5
5
|
|
|
6
|
+
import type {GLTFMaterial} from '@loaders.gl/gltf';
|
|
6
7
|
import type {LoaderOptions, LoaderContext} from '@loaders.gl/loader-utils';
|
|
7
8
|
import {ImageLoader} from '@loaders.gl/images';
|
|
8
9
|
import {DracoLoader} from '@loaders.gl/draco';
|
|
9
10
|
import {BasisLoader, CompressedTextureLoader} from '@loaders.gl/textures';
|
|
10
11
|
|
|
11
|
-
import {
|
|
12
|
+
import type {
|
|
13
|
+
Tileset,
|
|
14
|
+
Tile,
|
|
15
|
+
FeatureAttribute,
|
|
16
|
+
TileContent,
|
|
17
|
+
VertexAttribute,
|
|
18
|
+
NormalizedAttribute,
|
|
19
|
+
NormalizedAttributes,
|
|
20
|
+
TileContentTexture
|
|
21
|
+
} from '../../types';
|
|
12
22
|
import {getUrlWithToken} from '../utils/url-utils';
|
|
13
23
|
|
|
14
24
|
import {
|
|
15
25
|
GL_TYPE_MAP,
|
|
16
|
-
|
|
17
|
-
|
|
26
|
+
getConstructorForDataFormat,
|
|
27
|
+
sizeOf,
|
|
18
28
|
I3S_NAMED_HEADER_ATTRIBUTES,
|
|
19
29
|
I3S_NAMED_VERTEX_ATTRIBUTES,
|
|
20
30
|
I3S_NAMED_GEOMETRY_ATTRIBUTES,
|
|
@@ -23,13 +33,20 @@ import {
|
|
|
23
33
|
|
|
24
34
|
const scratchVector = new Vector3([0, 0, 0]);
|
|
25
35
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
36
|
+
function getLoaderForTextureFormat(textureFormat: 'jpeg' | 'png' | 'ktx-etc2' | 'dds' | 'ktx2') {
|
|
37
|
+
switch (textureFormat) {
|
|
38
|
+
case 'jpeg':
|
|
39
|
+
case 'png':
|
|
40
|
+
return ImageLoader;
|
|
41
|
+
case 'ktx-etc2':
|
|
42
|
+
case 'dds':
|
|
43
|
+
return CompressedTextureLoader;
|
|
44
|
+
case 'ktx2':
|
|
45
|
+
return BasisLoader;
|
|
46
|
+
default:
|
|
47
|
+
return null;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
33
50
|
|
|
34
51
|
const I3S_ATTRIBUTE_TYPE = 'i3s-attribute-type';
|
|
35
52
|
|
|
@@ -44,12 +61,12 @@ export async function parseI3STileContent(
|
|
|
44
61
|
tile.content.featureIds = tile.content.featureIds || null;
|
|
45
62
|
|
|
46
63
|
// construct featureData from defaultGeometrySchema;
|
|
47
|
-
tile.content.featureData = constructFeatureDataStruct(
|
|
64
|
+
tile.content.featureData = constructFeatureDataStruct(tileset);
|
|
48
65
|
tile.content.attributes = {};
|
|
49
66
|
|
|
50
67
|
if (tile.textureUrl) {
|
|
51
68
|
const url = getUrlWithToken(tile.textureUrl, options?.i3s?.token);
|
|
52
|
-
const loader =
|
|
69
|
+
const loader = getLoaderForTextureFormat(tile.textureFormat) || ImageLoader;
|
|
53
70
|
// @ts-ignore context must be defined
|
|
54
71
|
const response = await fetch(url);
|
|
55
72
|
const arrayBuffer = await response.arrayBuffer();
|
|
@@ -87,25 +104,20 @@ export async function parseI3STileContent(
|
|
|
87
104
|
tile.content.texture = null;
|
|
88
105
|
}
|
|
89
106
|
|
|
90
|
-
return await parseI3SNodeGeometry(arrayBuffer, tile, options
|
|
107
|
+
return await parseI3SNodeGeometry(arrayBuffer, tile, options);
|
|
91
108
|
}
|
|
92
109
|
|
|
93
110
|
/* eslint-disable max-statements */
|
|
94
|
-
async function parseI3SNodeGeometry(
|
|
95
|
-
arrayBuffer: ArrayBuffer,
|
|
96
|
-
tile: Tile = {},
|
|
97
|
-
options?: LoaderOptions,
|
|
98
|
-
context?: LoaderContext
|
|
99
|
-
) {
|
|
111
|
+
async function parseI3SNodeGeometry(arrayBuffer: ArrayBuffer, tile: Tile, options?: LoaderOptions) {
|
|
100
112
|
if (!tile.content) {
|
|
101
113
|
return tile;
|
|
102
114
|
}
|
|
103
115
|
|
|
104
116
|
const content = tile.content;
|
|
105
|
-
let attributes;
|
|
106
|
-
let vertexCount;
|
|
107
|
-
let byteOffset = 0;
|
|
108
|
-
let featureCount = 0;
|
|
117
|
+
let attributes: NormalizedAttributes;
|
|
118
|
+
let vertexCount: number;
|
|
119
|
+
let byteOffset: number = 0;
|
|
120
|
+
let featureCount: number = 0;
|
|
109
121
|
|
|
110
122
|
if (tile.isDracoGeometry) {
|
|
111
123
|
const decompressedGeometry = await parse(arrayBuffer, DracoLoader, {
|
|
@@ -156,6 +168,7 @@ async function parseI3SNodeGeometry(
|
|
|
156
168
|
byteOffset,
|
|
157
169
|
vertexAttributes,
|
|
158
170
|
vertexCount,
|
|
171
|
+
// @ts-expect-error
|
|
159
172
|
attributesOrder
|
|
160
173
|
);
|
|
161
174
|
|
|
@@ -176,7 +189,7 @@ async function parseI3SNodeGeometry(
|
|
|
176
189
|
!options?.i3s?.coordinateSystem ||
|
|
177
190
|
options.i3s.coordinateSystem === COORDINATE_SYSTEM.METER_OFFSETS
|
|
178
191
|
) {
|
|
179
|
-
const
|
|
192
|
+
const enuMatrix = parsePositions(attributes.position, tile);
|
|
180
193
|
content.modelMatrix = enuMatrix.invert();
|
|
181
194
|
content.coordinateSystem = COORDINATE_SYSTEM.METER_OFFSETS;
|
|
182
195
|
} else {
|
|
@@ -215,7 +228,7 @@ async function parseI3SNodeGeometry(
|
|
|
215
228
|
* @param decompressedGeometry
|
|
216
229
|
* @param attributes
|
|
217
230
|
*/
|
|
218
|
-
function updateAttributesMetadata(attributes, decompressedGeometry) {
|
|
231
|
+
function updateAttributesMetadata(attributes: NormalizedAttributes, decompressedGeometry): void {
|
|
219
232
|
for (const key in decompressedGeometry.loaderData.attributes) {
|
|
220
233
|
const dracoAttribute = decompressedGeometry.loaderData.attributes[key];
|
|
221
234
|
|
|
@@ -235,20 +248,23 @@ function updateAttributesMetadata(attributes, decompressedGeometry) {
|
|
|
235
248
|
/**
|
|
236
249
|
* Do concatenation of attribute objects.
|
|
237
250
|
* Done as separate fucntion to avoid ts errors.
|
|
238
|
-
* @param
|
|
239
|
-
* @param
|
|
240
|
-
* @returns
|
|
251
|
+
* @param normalizedVertexAttributes
|
|
252
|
+
* @param normalizedFeatureAttributes
|
|
253
|
+
* @returns - result of attributes concatenation.
|
|
241
254
|
*/
|
|
242
|
-
function concatAttributes(
|
|
255
|
+
function concatAttributes(
|
|
256
|
+
normalizedVertexAttributes: NormalizedAttributes,
|
|
257
|
+
normalizedFeatureAttributes: NormalizedAttributes
|
|
258
|
+
): NormalizedAttributes {
|
|
243
259
|
return {...normalizedVertexAttributes, ...normalizedFeatureAttributes};
|
|
244
260
|
}
|
|
245
261
|
|
|
246
262
|
/**
|
|
247
263
|
* Normalize attribute to range [0..1] . Eg. convert colors buffer from [255,255,255,255] to [1,1,1,1]
|
|
248
|
-
* @param
|
|
249
|
-
* @returns
|
|
264
|
+
* @param attribute - geometry attribute
|
|
265
|
+
* @returns - geometry attribute in right format
|
|
250
266
|
*/
|
|
251
|
-
function normalizeAttribute(attribute) {
|
|
267
|
+
function normalizeAttribute(attribute: NormalizedAttribute): NormalizedAttribute {
|
|
252
268
|
if (!attribute) {
|
|
253
269
|
return attribute;
|
|
254
270
|
}
|
|
@@ -256,7 +272,7 @@ function normalizeAttribute(attribute) {
|
|
|
256
272
|
return attribute;
|
|
257
273
|
}
|
|
258
274
|
|
|
259
|
-
function constructFeatureDataStruct(
|
|
275
|
+
function constructFeatureDataStruct(tileset: Tileset) {
|
|
260
276
|
// seed featureData from defaultGeometrySchema
|
|
261
277
|
const defaultGeometrySchema = tileset.store.defaultGeometrySchema;
|
|
262
278
|
const featureData = defaultGeometrySchema;
|
|
@@ -281,24 +297,25 @@ function constructFeatureDataStruct(tile, tileset) {
|
|
|
281
297
|
return featureData;
|
|
282
298
|
}
|
|
283
299
|
|
|
284
|
-
function parseHeaders(content,
|
|
300
|
+
function parseHeaders(content: TileContent, arrayBuffer: ArrayBuffer) {
|
|
285
301
|
let byteOffset = 0;
|
|
286
302
|
// First 8 bytes reserved for header (vertexCount and featurecount)
|
|
287
303
|
let vertexCount = 0;
|
|
288
304
|
let featureCount = 0;
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
const {property, type} = headers[header];
|
|
292
|
-
const TypedArrayTypeHeader = TYPE_ARRAY_MAP[type];
|
|
305
|
+
content.featureData.header.forEach(({property, type}) => {
|
|
306
|
+
const TypedArrayTypeHeader = getConstructorForDataFormat(type);
|
|
293
307
|
if (property === I3S_NAMED_HEADER_ATTRIBUTES.vertexCount) {
|
|
294
|
-
|
|
295
|
-
|
|
308
|
+
// @ts-expect-error
|
|
309
|
+
vertexCount = new TypedArrayTypeHeader(arrayBuffer, 0, 4)[0];
|
|
310
|
+
byteOffset += sizeOf(type);
|
|
296
311
|
}
|
|
297
312
|
if (property === I3S_NAMED_HEADER_ATTRIBUTES.featureCount) {
|
|
298
|
-
|
|
299
|
-
|
|
313
|
+
// @ts-expect-error
|
|
314
|
+
featureCount = new TypedArrayTypeHeader(arrayBuffer, 4, 4)[0];
|
|
315
|
+
byteOffset += sizeOf(type);
|
|
300
316
|
}
|
|
301
|
-
}
|
|
317
|
+
});
|
|
318
|
+
|
|
302
319
|
return {
|
|
303
320
|
vertexCount,
|
|
304
321
|
featureCount,
|
|
@@ -309,18 +326,19 @@ function parseHeaders(content, buffer) {
|
|
|
309
326
|
/* eslint-enable max-statements */
|
|
310
327
|
|
|
311
328
|
function normalizeAttributes(
|
|
312
|
-
arrayBuffer,
|
|
313
|
-
byteOffset,
|
|
314
|
-
vertexAttributes,
|
|
315
|
-
vertexCount,
|
|
316
|
-
attributesOrder
|
|
329
|
+
arrayBuffer: ArrayBuffer,
|
|
330
|
+
byteOffset: number,
|
|
331
|
+
vertexAttributes: VertexAttribute | FeatureAttribute,
|
|
332
|
+
vertexCount: number,
|
|
333
|
+
attributesOrder: string[]
|
|
317
334
|
) {
|
|
318
|
-
const attributes = {};
|
|
335
|
+
const attributes: NormalizedAttributes = {};
|
|
319
336
|
|
|
320
337
|
// the order of attributes depend on the order being added to the vertexAttributes object
|
|
321
338
|
for (const attribute of attributesOrder) {
|
|
322
339
|
if (vertexAttributes[attribute]) {
|
|
323
|
-
const {valueType, valuesPerElement}
|
|
340
|
+
const {valueType, valuesPerElement}: {valueType: string; valuesPerElement: number} =
|
|
341
|
+
vertexAttributes[attribute];
|
|
324
342
|
// update count and byteOffset count by calculating from defaultGeometrySchema + binnary content
|
|
325
343
|
const count = vertexCount;
|
|
326
344
|
// protect from arrayBuffer read overunns by NOT assuming node has regions always even though its declared in defaultGeometrySchema.
|
|
@@ -336,9 +354,10 @@ function normalizeAttributes(
|
|
|
336
354
|
let value: number[] | TypedArray = [];
|
|
337
355
|
|
|
338
356
|
if (valueType === 'UInt64') {
|
|
339
|
-
value = parseUint64Values(buffer, count * valuesPerElement,
|
|
357
|
+
value = parseUint64Values(buffer, count * valuesPerElement, sizeOf(valueType));
|
|
340
358
|
} else {
|
|
341
|
-
const TypedArrayType =
|
|
359
|
+
const TypedArrayType = getConstructorForDataFormat(valueType);
|
|
360
|
+
// @ts-expect-error
|
|
342
361
|
value = new TypedArrayType(buffer, 0, count * valuesPerElement);
|
|
343
362
|
}
|
|
344
363
|
|
|
@@ -350,7 +369,6 @@ function normalizeAttributes(
|
|
|
350
369
|
|
|
351
370
|
switch (attribute) {
|
|
352
371
|
case 'color':
|
|
353
|
-
// @ts-ignore
|
|
354
372
|
attributes.color.normalized = true;
|
|
355
373
|
break;
|
|
356
374
|
case 'position':
|
|
@@ -359,7 +377,7 @@ function normalizeAttributes(
|
|
|
359
377
|
default:
|
|
360
378
|
}
|
|
361
379
|
|
|
362
|
-
byteOffset = byteOffset + count * valuesPerElement *
|
|
380
|
+
byteOffset = byteOffset + count * valuesPerElement * sizeOf(valueType);
|
|
363
381
|
}
|
|
364
382
|
}
|
|
365
383
|
|
|
@@ -396,7 +414,7 @@ function parseUint64Values(
|
|
|
396
414
|
return values;
|
|
397
415
|
}
|
|
398
416
|
|
|
399
|
-
function parsePositions(attribute, tile) {
|
|
417
|
+
function parsePositions(attribute: NormalizedAttribute, tile: Tile): Matrix4 {
|
|
400
418
|
const mbs = tile.mbs;
|
|
401
419
|
const value = attribute.value;
|
|
402
420
|
const metadata = attribute.metadata;
|
|
@@ -407,20 +425,22 @@ function parsePositions(attribute, tile) {
|
|
|
407
425
|
Ellipsoid.WGS84.eastNorthUpToFixedFrame(cartesianOrigin, enuMatrix);
|
|
408
426
|
attribute.value = offsetsToCartesians(value, metadata, cartographicOrigin);
|
|
409
427
|
|
|
410
|
-
return
|
|
411
|
-
enuMatrix
|
|
412
|
-
};
|
|
428
|
+
return enuMatrix;
|
|
413
429
|
}
|
|
414
430
|
|
|
415
431
|
/**
|
|
416
432
|
* Converts position coordinates to absolute cartesian coordinates
|
|
417
|
-
* @param
|
|
418
|
-
* @param
|
|
433
|
+
* @param vertices - "position" attribute data
|
|
434
|
+
* @param metadata - When the geometry is DRACO compressed, contain position attribute's metadata
|
|
419
435
|
* https://github.com/Esri/i3s-spec/blob/master/docs/1.7/compressedAttributes.cmn.md
|
|
420
|
-
* @param
|
|
421
|
-
* @returns
|
|
436
|
+
* @param cartographicOrigin - Cartographic origin coordinates
|
|
437
|
+
* @returns - converted "position" data
|
|
422
438
|
*/
|
|
423
|
-
function offsetsToCartesians(
|
|
439
|
+
function offsetsToCartesians(
|
|
440
|
+
vertices: number[] | TypedArray,
|
|
441
|
+
metadata: any = {},
|
|
442
|
+
cartographicOrigin: Vector3
|
|
443
|
+
): Float64Array {
|
|
424
444
|
const positions = new Float64Array(vertices.length);
|
|
425
445
|
const scaleX = (metadata['i3s-scale_x'] && metadata['i3s-scale_x'].double) || 1;
|
|
426
446
|
const scaleY = (metadata['i3s-scale_y'] && metadata['i3s-scale_y'].double) || 1;
|
|
@@ -446,10 +466,10 @@ function offsetsToCartesians(vertices, metadata = {}, cartographicOrigin) {
|
|
|
446
466
|
* @param positions positions attribute
|
|
447
467
|
* @returns Matrix4 - model matrix for geometry transformation
|
|
448
468
|
*/
|
|
449
|
-
function getModelMatrix(positions) {
|
|
469
|
+
function getModelMatrix(positions: NormalizedAttribute): Matrix4 {
|
|
450
470
|
const metadata = positions.metadata;
|
|
451
|
-
const scaleX = metadata?.['i3s-scale_x']?.double || 1;
|
|
452
|
-
const scaleY = metadata?.['i3s-scale_y']?.double || 1;
|
|
471
|
+
const scaleX: number = metadata?.['i3s-scale_x']?.double || 1;
|
|
472
|
+
const scaleY: number = metadata?.['i3s-scale_y']?.double || 1;
|
|
453
473
|
const modelMatrix = new Matrix4();
|
|
454
474
|
modelMatrix[0] = scaleX;
|
|
455
475
|
modelMatrix[5] = scaleY;
|
|
@@ -458,12 +478,12 @@ function getModelMatrix(positions) {
|
|
|
458
478
|
|
|
459
479
|
/**
|
|
460
480
|
* Makes a glTF-compatible PBR material from an I3S material definition
|
|
461
|
-
* @param
|
|
481
|
+
* @param materialDefinition - i3s material definition
|
|
462
482
|
* https://github.com/Esri/i3s-spec/blob/master/docs/1.7/materialDefinitions.cmn.md
|
|
463
|
-
* @param
|
|
483
|
+
* @param texture - texture image
|
|
464
484
|
* @returns {object}
|
|
465
485
|
*/
|
|
466
|
-
function makePbrMaterial(materialDefinition, texture) {
|
|
486
|
+
function makePbrMaterial(materialDefinition: GLTFMaterial, texture: TileContentTexture) {
|
|
467
487
|
let pbrMaterial;
|
|
468
488
|
if (materialDefinition) {
|
|
469
489
|
pbrMaterial = {
|
|
@@ -508,10 +528,10 @@ function makePbrMaterial(materialDefinition, texture) {
|
|
|
508
528
|
|
|
509
529
|
/**
|
|
510
530
|
* Convert color from [255,255,255,255] to [1,1,1,1]
|
|
511
|
-
* @param
|
|
512
|
-
* @returns
|
|
531
|
+
* @param colorFactor - color array
|
|
532
|
+
* @returns - new color array
|
|
513
533
|
*/
|
|
514
|
-
function convertColorFormat(colorFactor) {
|
|
534
|
+
function convertColorFormat(colorFactor: number[]): number[] {
|
|
515
535
|
const normalizedColor = [...colorFactor];
|
|
516
536
|
for (let index = 0; index < colorFactor.length; index++) {
|
|
517
537
|
normalizedColor[index] = colorFactor[index] / 255;
|
|
@@ -522,10 +542,10 @@ function convertColorFormat(colorFactor) {
|
|
|
522
542
|
/**
|
|
523
543
|
* Set texture in PBR material
|
|
524
544
|
* @param {object} material - i3s material definition
|
|
525
|
-
* @param
|
|
526
|
-
* @returns
|
|
545
|
+
* @param image - texture image
|
|
546
|
+
* @returns
|
|
527
547
|
*/
|
|
528
|
-
function setMaterialTexture(material, image) {
|
|
548
|
+
function setMaterialTexture(material, image: TileContentTexture): void {
|
|
529
549
|
const texture = {source: {image}};
|
|
530
550
|
// I3SLoader now support loading only one texture. This elseif sequence will assign this texture to one of
|
|
531
551
|
// properties defined in materialDefinition
|
|
@@ -553,10 +573,10 @@ function setMaterialTexture(material, image) {
|
|
|
553
573
|
|
|
554
574
|
/**
|
|
555
575
|
* Flatten feature ids using face ranges
|
|
556
|
-
* @param
|
|
557
|
-
* @returns
|
|
576
|
+
* @param normalizedFeatureAttributes
|
|
577
|
+
* @returns
|
|
558
578
|
*/
|
|
559
|
-
function flattenFeatureIdsByFaceRanges(normalizedFeatureAttributes) {
|
|
579
|
+
function flattenFeatureIdsByFaceRanges(normalizedFeatureAttributes: NormalizedAttributes): void {
|
|
560
580
|
const {id, faceRange} = normalizedFeatureAttributes;
|
|
561
581
|
|
|
562
582
|
if (!id || !faceRange) {
|
|
@@ -589,11 +609,14 @@ function flattenFeatureIdsByFaceRanges(normalizedFeatureAttributes) {
|
|
|
589
609
|
|
|
590
610
|
/**
|
|
591
611
|
* Flatten feature ids using featureIndices
|
|
592
|
-
* @param
|
|
593
|
-
* @param
|
|
594
|
-
* @returns
|
|
612
|
+
* @param attributes
|
|
613
|
+
* @param featureIds
|
|
614
|
+
* @returns
|
|
595
615
|
*/
|
|
596
|
-
function flattenFeatureIdsByFeatureIndices(
|
|
616
|
+
function flattenFeatureIdsByFeatureIndices(
|
|
617
|
+
attributes: NormalizedAttributes,
|
|
618
|
+
featureIds: Int32Array
|
|
619
|
+
): void {
|
|
597
620
|
const featureIndices = attributes.id.value;
|
|
598
621
|
const result = new Float32Array(featureIndices.length);
|
|
599
622
|
|
|
@@ -606,10 +629,12 @@ function flattenFeatureIdsByFeatureIndices(attributes, featureIds) {
|
|
|
606
629
|
|
|
607
630
|
/**
|
|
608
631
|
* Flatten feature ids using featureIndices
|
|
609
|
-
* @param
|
|
610
|
-
* @returns
|
|
632
|
+
* @param featureIndex
|
|
633
|
+
* @returns
|
|
611
634
|
*/
|
|
612
|
-
function getFeatureIdsFromFeatureIndexMetadata(
|
|
635
|
+
function getFeatureIdsFromFeatureIndexMetadata(
|
|
636
|
+
featureIndex: NormalizedAttribute
|
|
637
|
+
): Int32Array | undefined {
|
|
613
638
|
return (
|
|
614
639
|
featureIndex &&
|
|
615
640
|
featureIndex.metadata &&
|
|
@@ -6,7 +6,7 @@ import {Tile} from '../../types';
|
|
|
6
6
|
* @param {any} token
|
|
7
7
|
* @returns {string}
|
|
8
8
|
*/
|
|
9
|
-
export function getUrlWithToken(url, token = null) {
|
|
9
|
+
export function getUrlWithToken(url: string, token = null): string {
|
|
10
10
|
return token ? `${url}?token=${token}` : url;
|
|
11
11
|
}
|
|
12
12
|
|
package/src/types.ts
CHANGED
|
@@ -1,10 +1,71 @@
|
|
|
1
1
|
import type {GLTFMaterial} from '@loaders.gl/gltf';
|
|
2
|
-
import type {Quaternion, Vector3} from '@math.gl/core';
|
|
2
|
+
import type {Matrix4, Quaternion, Vector3} from '@math.gl/core';
|
|
3
3
|
import type {Mesh} from '@loaders.gl/gltf';
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
import type {TypedArray} from '@loaders.gl/schema';
|
|
5
|
+
|
|
6
|
+
export enum DATA_TYPE {
|
|
7
|
+
UInt8 = 'UInt8',
|
|
8
|
+
UInt16 = 'UInt16',
|
|
9
|
+
UInt32 = 'UInt32',
|
|
10
|
+
UInt64 = 'UInt64',
|
|
11
|
+
Int16 = 'Int16',
|
|
12
|
+
Int32 = 'Int32',
|
|
13
|
+
Int64 = 'Int64',
|
|
14
|
+
Float32 = 'Float32',
|
|
15
|
+
Float64 = 'Float64'
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* spec - https://github.com/Esri/i3s-spec/blob/master/docs/1.8/3DSceneLayer.cmn.md
|
|
19
|
+
*/
|
|
20
|
+
// TODO Replace "[key: string]: any" with actual defenition
|
|
21
|
+
export type Tileset = {
|
|
22
|
+
/**
|
|
23
|
+
* The store object describes the exact physical storage of a layer and enables the client to detect when multiple layers are served from the same store.
|
|
24
|
+
*/
|
|
25
|
+
store: Store;
|
|
26
|
+
[key: string]: any;
|
|
27
|
+
};
|
|
28
|
+
// TODO Replace "[key: string]: any" with actual defenition
|
|
6
29
|
export type NodePage = {[key: string]: any};
|
|
7
|
-
|
|
30
|
+
// TODO Replace "[key: string]: any" with actual defenition
|
|
31
|
+
export type Tile = {
|
|
32
|
+
content: TileContent;
|
|
33
|
+
isDracoGeometry: boolean;
|
|
34
|
+
textureUrl: string;
|
|
35
|
+
url: string;
|
|
36
|
+
/**
|
|
37
|
+
* Resource reference describing a featureData document.
|
|
38
|
+
*/
|
|
39
|
+
attributeData: Resource[];
|
|
40
|
+
textureFormat: 'jpeg' | 'png' | 'ktx-etc2' | 'dds' | 'ktx2';
|
|
41
|
+
textureLoaderOptions: any;
|
|
42
|
+
materialDefinition: GLTFMaterial;
|
|
43
|
+
mbs: Mbs;
|
|
44
|
+
};
|
|
45
|
+
// TODO Replace "[key: string]: any" with actual defenition
|
|
46
|
+
export type TileContent = {
|
|
47
|
+
featureData: DefaultGeometrySchema;
|
|
48
|
+
attributes: NormalizedAttributes;
|
|
49
|
+
indices: NormalizedAttribute | null;
|
|
50
|
+
featureIds: number[] | TypedArray;
|
|
51
|
+
vertexCount: number;
|
|
52
|
+
modelMatrix: Matrix4;
|
|
53
|
+
coordinateSystem: number;
|
|
54
|
+
byteLength: number;
|
|
55
|
+
texture: TileContentTexture;
|
|
56
|
+
[key: string]: any;
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
export type TileContentTexture =
|
|
60
|
+
| ArrayBuffer
|
|
61
|
+
| {
|
|
62
|
+
compressed: boolean;
|
|
63
|
+
mipmaps: boolean;
|
|
64
|
+
width: number;
|
|
65
|
+
height: number;
|
|
66
|
+
data: any;
|
|
67
|
+
}
|
|
68
|
+
| null;
|
|
8
69
|
|
|
9
70
|
export type BoundingVolumes = {
|
|
10
71
|
mbs: Mbs;
|
|
@@ -78,7 +139,9 @@ export type PopupInfo = {
|
|
|
78
139
|
popupElements?: {text?: string; type?: string; fieldInfos?: FieldInfo[]}[];
|
|
79
140
|
};
|
|
80
141
|
|
|
81
|
-
|
|
142
|
+
/**
|
|
143
|
+
* Spec - https://github.com/Esri/i3s-spec/blob/master/docs/1.7/3DNodeIndexDocument.cmn.md
|
|
144
|
+
*/
|
|
82
145
|
export type Node3DIndexDocument = {
|
|
83
146
|
id: string;
|
|
84
147
|
version?: string;
|
|
@@ -173,7 +236,10 @@ export type Attribute = 'OBJECTID' | 'string' | 'double' | 'Int32' | string;
|
|
|
173
236
|
|
|
174
237
|
export type Extent = [number, number, number, number];
|
|
175
238
|
|
|
176
|
-
export type FeatureAttribute = {
|
|
239
|
+
export type FeatureAttribute = {
|
|
240
|
+
id: AttributeValue;
|
|
241
|
+
faceRange: AttributeValue;
|
|
242
|
+
};
|
|
177
243
|
|
|
178
244
|
export type BuildingSceneLayerTileset = {
|
|
179
245
|
header: BuildingSceneLayer;
|
|
@@ -294,7 +360,9 @@ type Domain = {
|
|
|
294
360
|
mergePolicy?: string;
|
|
295
361
|
splitPolicy?: string;
|
|
296
362
|
};
|
|
297
|
-
|
|
363
|
+
/**
|
|
364
|
+
* spec - https://github.com/Esri/i3s-spec/blob/master/docs/1.8/store.cmn.md
|
|
365
|
+
*/
|
|
298
366
|
type Store = {
|
|
299
367
|
id: string | number;
|
|
300
368
|
profile: string;
|
|
@@ -311,24 +379,87 @@ type Store = {
|
|
|
311
379
|
lodModel: string;
|
|
312
380
|
defaultGeometrySchema: DefaultGeometrySchema;
|
|
313
381
|
};
|
|
314
|
-
|
|
382
|
+
/**
|
|
383
|
+
* Spec - https://github.com/Esri/i3s-spec/blob/master/docs/1.8/defaultGeometrySchema.cmn.md
|
|
384
|
+
*/
|
|
315
385
|
type DefaultGeometrySchema = {
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
386
|
+
geometryType?: 'triangles';
|
|
387
|
+
topology: 'PerAttributeArray' | 'Indexed';
|
|
388
|
+
header: {
|
|
389
|
+
property: 'vertexCount' | 'featureCount' | string;
|
|
390
|
+
type:
|
|
391
|
+
| DATA_TYPE.UInt8
|
|
392
|
+
| DATA_TYPE.UInt16
|
|
393
|
+
| DATA_TYPE.UInt32
|
|
394
|
+
| DATA_TYPE.UInt64
|
|
395
|
+
| DATA_TYPE.Int16
|
|
396
|
+
| DATA_TYPE.Int32
|
|
397
|
+
| DATA_TYPE.Int64
|
|
398
|
+
| DATA_TYPE.Float32
|
|
399
|
+
| DATA_TYPE.Float64;
|
|
400
|
+
}[];
|
|
401
|
+
ordering: string[];
|
|
402
|
+
vertexAttributes: VertexAttribute;
|
|
403
|
+
faces?: VertexAttribute;
|
|
404
|
+
featureAttributeOrder: string[];
|
|
405
|
+
featureAttributes: FeatureAttribute;
|
|
406
|
+
// TODO Do we realy need this Property?
|
|
407
|
+
attributesOrder?: string[];
|
|
408
|
+
};
|
|
409
|
+
export type VertexAttribute = {
|
|
410
|
+
position: GeometryAttribute;
|
|
411
|
+
normal: GeometryAttribute;
|
|
412
|
+
uv0: GeometryAttribute;
|
|
413
|
+
color: GeometryAttribute;
|
|
414
|
+
region?: GeometryAttribute;
|
|
415
|
+
};
|
|
416
|
+
export type GeometryAttribute = {
|
|
417
|
+
byteOffset?: number;
|
|
418
|
+
valueType:
|
|
419
|
+
| DATA_TYPE.UInt8
|
|
420
|
+
| DATA_TYPE.UInt16
|
|
421
|
+
| DATA_TYPE.Int16
|
|
422
|
+
| DATA_TYPE.Int32
|
|
423
|
+
| DATA_TYPE.Int64
|
|
424
|
+
| DATA_TYPE.Float32
|
|
425
|
+
| DATA_TYPE.Float64;
|
|
426
|
+
valuesPerElement: number;
|
|
427
|
+
};
|
|
428
|
+
export type NormalizedAttributes = {
|
|
429
|
+
[key: string]: NormalizedAttribute;
|
|
430
|
+
};
|
|
431
|
+
export type NormalizedAttribute = {
|
|
432
|
+
value: number[] | TypedArray;
|
|
433
|
+
type: number;
|
|
434
|
+
size: number;
|
|
435
|
+
normalized?: boolean;
|
|
436
|
+
metadata?: any;
|
|
437
|
+
};
|
|
328
438
|
type HeightModelInfo = {
|
|
329
|
-
heightModel:
|
|
439
|
+
heightModel: 'gravity_related_height' | 'ellipsoidal';
|
|
330
440
|
vertCRS: string;
|
|
331
|
-
heightUnit:
|
|
441
|
+
heightUnit:
|
|
442
|
+
| 'meter'
|
|
443
|
+
| 'us-foot'
|
|
444
|
+
| 'foot'
|
|
445
|
+
| 'clarke-foot'
|
|
446
|
+
| 'clarke-yard'
|
|
447
|
+
| 'clarke-link'
|
|
448
|
+
| 'sears-yard'
|
|
449
|
+
| 'sears-foot'
|
|
450
|
+
| 'sears-chain'
|
|
451
|
+
| 'benoit-1895-b-chain'
|
|
452
|
+
| 'indian-yard'
|
|
453
|
+
| 'indian-1937-yard'
|
|
454
|
+
| 'gold-coast-foot'
|
|
455
|
+
| 'sears-1922-truncated-chain'
|
|
456
|
+
| 'us-inch'
|
|
457
|
+
| 'us-mile'
|
|
458
|
+
| 'us-yard'
|
|
459
|
+
| 'millimeter'
|
|
460
|
+
| 'decimeter'
|
|
461
|
+
| 'centimeter'
|
|
462
|
+
| 'kilometer';
|
|
332
463
|
};
|
|
333
464
|
|
|
334
465
|
type NodePages = {
|