@loaders.gl/i3s 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/dist/bundle.d.ts +2 -0
- package/dist/bundle.d.ts.map +1 -0
- package/dist/bundle.js +10364 -0
- package/dist/es5/bundle.js +1 -1
- package/dist/es5/bundle.js.map +1 -1
- package/dist/es5/i3s-attribute-loader.js +89 -138
- package/dist/es5/i3s-attribute-loader.js.map +1 -1
- package/dist/es5/i3s-building-scene-layer-loader.js +8 -36
- package/dist/es5/i3s-building-scene-layer-loader.js.map +1 -1
- package/dist/es5/i3s-content-loader.js +10 -36
- package/dist/es5/i3s-content-loader.js.map +1 -1
- package/dist/es5/i3s-loader.js +56 -176
- package/dist/es5/i3s-loader.js.map +1 -1
- package/dist/es5/i3s-node-page-loader.js +8 -51
- package/dist/es5/i3s-node-page-loader.js.map +1 -1
- package/dist/es5/index.js +13 -5
- package/dist/es5/index.js.map +1 -1
- package/dist/es5/lib/helpers/i3s-nodepages-tiles.js +172 -325
- package/dist/es5/lib/helpers/i3s-nodepages-tiles.js.map +1 -1
- package/dist/es5/lib/parsers/constants.js +71 -25
- package/dist/es5/lib/parsers/constants.js.map +1 -1
- package/dist/es5/lib/parsers/parse-i3s-attribute.js +34 -68
- package/dist/es5/lib/parsers/parse-i3s-attribute.js.map +1 -1
- package/dist/es5/lib/parsers/parse-i3s-building-scene-layer.js +28 -59
- package/dist/es5/lib/parsers/parse-i3s-building-scene-layer.js.map +1 -1
- package/dist/es5/lib/parsers/parse-i3s-tile-content.js +314 -415
- package/dist/es5/lib/parsers/parse-i3s-tile-content.js.map +1 -1
- package/dist/es5/lib/parsers/parse-i3s.js +31 -70
- package/dist/es5/lib/parsers/parse-i3s.js.map +1 -1
- package/dist/es5/lib/utils/convert-i3s-obb-to-mbs.js +4 -8
- package/dist/es5/lib/utils/convert-i3s-obb-to-mbs.js.map +1 -1
- package/dist/es5/lib/utils/url-utils.js +17 -14
- 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 +44 -14
- 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 +5 -2
- 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/index.js +1 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/lib/helpers/i3s-nodepages-tiles.js +3 -3
- package/dist/esm/lib/helpers/i3s-nodepages-tiles.js.map +1 -1
- package/dist/esm/lib/parsers/constants.js +55 -15
- package/dist/esm/lib/parsers/constants.js.map +1 -1
- package/dist/esm/lib/parsers/parse-i3s-attribute.js +9 -1
- package/dist/esm/lib/parsers/parse-i3s-attribute.js.map +1 -1
- package/dist/esm/lib/parsers/parse-i3s-building-scene-layer.js +3 -1
- package/dist/esm/lib/parsers/parse-i3s-building-scene-layer.js.map +1 -1
- package/dist/esm/lib/parsers/parse-i3s-tile-content.js +87 -61
- package/dist/esm/lib/parsers/parse-i3s-tile-content.js.map +1 -1
- package/dist/esm/lib/parsers/parse-i3s.js +4 -4
- package/dist/esm/lib/parsers/parse-i3s.js.map +1 -1
- package/dist/esm/lib/utils/url-utils.js +3 -3
- 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 +14 -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 +6 -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 +6 -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 +6 -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 +6 -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 +7 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +14 -0
- package/dist/lib/helpers/i3s-nodepages-tiles.d.ts +73 -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 +56 -0
- 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 +10 -0
- 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 +9 -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 +4 -0
- 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 +4 -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 +2 -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 +22 -0
- 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 +429 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +15 -0
- package/dist/workers/i3s-content-worker.d.ts +2 -0
- package/dist/workers/i3s-content-worker.d.ts.map +1 -0
- package/dist/workers/i3s-content-worker.js +5 -0
- package/package.json +14 -12
- package/src/i3s-attribute-loader.ts +56 -19
- package/src/i3s-loader.ts +4 -1
- package/src/index.ts +1 -0
- package/src/lib/parsers/constants.ts +73 -18
- package/src/lib/parsers/parse-i3s-attribute.ts +19 -1
- package/src/lib/parsers/parse-i3s-building-scene-layer.ts +2 -1
- package/src/lib/parsers/parse-i3s-tile-content.ts +159 -109
- 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
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parseI3STileAttribute = void 0;
|
|
4
|
+
const constants_1 = require("./constants");
|
|
5
|
+
/**
|
|
6
|
+
* Get particular tile and creates attribute object inside.
|
|
7
|
+
* @param {ArrayBuffer} arrayBuffer
|
|
8
|
+
* @param {Object} options
|
|
9
|
+
* @returns {Promise<object>}
|
|
10
|
+
*/
|
|
11
|
+
async function parseI3STileAttribute(arrayBuffer, options) {
|
|
12
|
+
const { attributeName, attributeType } = options;
|
|
13
|
+
if (!attributeName) {
|
|
14
|
+
return {};
|
|
15
|
+
}
|
|
16
|
+
return {
|
|
17
|
+
[attributeName]: attributeType ? parseAttribute(attributeType, arrayBuffer) : null
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
exports.parseI3STileAttribute = parseI3STileAttribute;
|
|
21
|
+
/**
|
|
22
|
+
* Parse attributes based on attribute type.
|
|
23
|
+
* @param {String} attributeType
|
|
24
|
+
* @param {ArrayBuffer} arrayBuffer
|
|
25
|
+
* @returns {any}
|
|
26
|
+
*/
|
|
27
|
+
function parseAttribute(attributeType, arrayBuffer) {
|
|
28
|
+
switch (attributeType) {
|
|
29
|
+
case constants_1.STRING_ATTRIBUTE_TYPE:
|
|
30
|
+
return parseStringsAttribute(arrayBuffer);
|
|
31
|
+
case constants_1.OBJECT_ID_ATTRIBUTE_TYPE:
|
|
32
|
+
return parseShortNumberAttribute(arrayBuffer);
|
|
33
|
+
case constants_1.FLOAT_64_TYPE:
|
|
34
|
+
return parseFloatAttribute(arrayBuffer);
|
|
35
|
+
case constants_1.INT_16_ATTRIBUTE_TYPE:
|
|
36
|
+
return parseInt16ShortNumberAttribute(arrayBuffer);
|
|
37
|
+
default:
|
|
38
|
+
return parseShortNumberAttribute(arrayBuffer);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Parse short number attribute.
|
|
43
|
+
* Short Integer spec - https://github.com/Esri/i3s-spec/blob/master/docs/1.7/attributeStorageInfo.cmn.md
|
|
44
|
+
* @param {ArrayBuffer} arrayBuffer
|
|
45
|
+
* @returns {Uint32Array}
|
|
46
|
+
*/
|
|
47
|
+
function parseShortNumberAttribute(arrayBuffer) {
|
|
48
|
+
const countOffset = 4;
|
|
49
|
+
return new Uint32Array(arrayBuffer, countOffset);
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Parse Int16 short number attribute.
|
|
53
|
+
* Parsing of such data is not documented. Added to handle Building Scene Layer Tileset attributes data.
|
|
54
|
+
* @param {ArrayBuffer} arrayBuffer
|
|
55
|
+
* @returns {Int16Array}
|
|
56
|
+
*/
|
|
57
|
+
function parseInt16ShortNumberAttribute(arrayBuffer) {
|
|
58
|
+
const countOffset = 4;
|
|
59
|
+
return new Int16Array(arrayBuffer, countOffset);
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Parse float attribute.
|
|
63
|
+
* Double Spec - https://github.com/Esri/i3s-spec/blob/master/docs/1.7/attributeStorageInfo.cmn.md
|
|
64
|
+
* @param {ArrayBuffer} arrayBuffer
|
|
65
|
+
* @returns {Float64Array}
|
|
66
|
+
*/
|
|
67
|
+
function parseFloatAttribute(arrayBuffer) {
|
|
68
|
+
const countOffset = 8;
|
|
69
|
+
return new Float64Array(arrayBuffer, countOffset);
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Parse string attribute.
|
|
73
|
+
* String spec - https://github.com/Esri/i3s-spec/blob/master/docs/1.7/attributeStorageInfo.cmn.md
|
|
74
|
+
* @param arrayBuffer
|
|
75
|
+
* @returns list of strings
|
|
76
|
+
*/
|
|
77
|
+
function parseStringsAttribute(arrayBuffer) {
|
|
78
|
+
const stringsCountOffset = 0;
|
|
79
|
+
const dataOffset = 8;
|
|
80
|
+
const bytesPerStringSize = 4;
|
|
81
|
+
const stringsArray = [];
|
|
82
|
+
try {
|
|
83
|
+
// Use DataView to avoid multiple of 4 error on Uint32Array constructor
|
|
84
|
+
const stringsCount = new DataView(arrayBuffer, stringsCountOffset, bytesPerStringSize).getUint32(stringsCountOffset, true);
|
|
85
|
+
const stringSizes = new Uint32Array(arrayBuffer, dataOffset, stringsCount);
|
|
86
|
+
let stringOffset = dataOffset + stringsCount * bytesPerStringSize;
|
|
87
|
+
for (const stringByteSize of stringSizes) {
|
|
88
|
+
const textDecoder = new TextDecoder('utf-8');
|
|
89
|
+
const stringAttribute = new Uint8Array(arrayBuffer, stringOffset, stringByteSize);
|
|
90
|
+
stringsArray.push(textDecoder.decode(stringAttribute));
|
|
91
|
+
stringOffset += stringByteSize;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
catch (error) {
|
|
95
|
+
console.error('Parse string attribute error: ', error.message); // eslint-disable-line
|
|
96
|
+
}
|
|
97
|
+
return stringsArray;
|
|
98
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { BuildingSceneLayerTileset } from '../../types';
|
|
2
|
+
/**
|
|
3
|
+
* Parses Builiding Scene Layer and creates tileset
|
|
4
|
+
* @param data
|
|
5
|
+
* @param options
|
|
6
|
+
* @param context
|
|
7
|
+
*/
|
|
8
|
+
export declare function parseBuildingSceneLayer(data: ArrayBuffer, url: string): Promise<BuildingSceneLayerTileset>;
|
|
9
|
+
//# sourceMappingURL=parse-i3s-building-scene-layer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parse-i3s-building-scene-layer.d.ts","sourceRoot":"","sources":["../../../src/lib/parsers/parse-i3s-building-scene-layer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,yBAAyB,EAAwB,MAAM,aAAa,CAAC;AAIlF;;;;;GAKG;AACH,wBAAsB,uBAAuB,CAC3C,IAAI,EAAE,WAAW,EACjB,GAAG,EAAE,MAAM,GACV,OAAO,CAAC,yBAAyB,CAAC,CAQpC"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parseBuildingSceneLayer = void 0;
|
|
4
|
+
const OBJECT_3D_LAYER_TYPE = '3DObject';
|
|
5
|
+
/**
|
|
6
|
+
* Parses Builiding Scene Layer and creates tileset
|
|
7
|
+
* @param data
|
|
8
|
+
* @param options
|
|
9
|
+
* @param context
|
|
10
|
+
*/
|
|
11
|
+
async function parseBuildingSceneLayer(data, url) {
|
|
12
|
+
const layer0 = JSON.parse(new TextDecoder().decode(data));
|
|
13
|
+
const { sublayers } = layer0;
|
|
14
|
+
return {
|
|
15
|
+
header: layer0,
|
|
16
|
+
sublayers: parseSublayersTree(sublayers, url)
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
exports.parseBuildingSceneLayer = parseBuildingSceneLayer;
|
|
20
|
+
/**
|
|
21
|
+
* Recursively parses Building Scene Layer sublayers.
|
|
22
|
+
* @param sublayers
|
|
23
|
+
* @param url
|
|
24
|
+
*/
|
|
25
|
+
function parseSublayersTree(sublayers, url) {
|
|
26
|
+
let layers = [];
|
|
27
|
+
for (let index = 0; index < sublayers.length; index++) {
|
|
28
|
+
const subLayer = sublayers[index];
|
|
29
|
+
const { id, layerType, visibility = true, ...rest } = subLayer;
|
|
30
|
+
// Add support only for 3DObject layer type for I3S purposes.
|
|
31
|
+
if (layerType === OBJECT_3D_LAYER_TYPE) {
|
|
32
|
+
const sublayerUrl = `${url}/sublayers/${id}`;
|
|
33
|
+
layers.push({
|
|
34
|
+
url: sublayerUrl,
|
|
35
|
+
id,
|
|
36
|
+
layerType,
|
|
37
|
+
visibility,
|
|
38
|
+
...rest
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
if (subLayer?.sublayers?.length) {
|
|
42
|
+
layers = [...layers, ...parseSublayersTree(subLayer.sublayers, url)];
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
return layers;
|
|
46
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { LoaderOptions, LoaderContext } from '@loaders.gl/loader-utils';
|
|
2
|
+
import type { Tileset, Tile } from '../../types';
|
|
3
|
+
export declare function parseI3STileContent(arrayBuffer: ArrayBuffer, tile: Tile, tileset: Tileset, options?: LoaderOptions, context?: LoaderContext): Promise<Tile>;
|
|
4
|
+
//# sourceMappingURL=parse-i3s-tile-content.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parse-i3s-tile-content.d.ts","sourceRoot":"","sources":["../../../src/lib/parsers/parse-i3s-tile-content.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAC,aAAa,EAAE,aAAa,EAAC,MAAM,0BAA0B,CAAC;AAK3E,OAAO,KAAK,EACV,OAAO,EACP,IAAI,EAOL,MAAM,aAAa,CAAC;AAgCrB,wBAAsB,mBAAmB,CACvC,WAAW,EAAE,WAAW,EACxB,IAAI,EAAE,IAAI,EACV,OAAO,EAAE,OAAO,EAChB,OAAO,CAAC,EAAE,aAAa,EACvB,OAAO,CAAC,EAAE,aAAa,iBAkDxB"}
|
|
@@ -0,0 +1,508 @@
|
|
|
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 url_utils_1 = require("../utils/url-utils");
|
|
11
|
+
const constants_1 = require("./constants");
|
|
12
|
+
const scratchVector = new core_2.Vector3([0, 0, 0]);
|
|
13
|
+
function getLoaderForTextureFormat(textureFormat) {
|
|
14
|
+
switch (textureFormat) {
|
|
15
|
+
case 'jpeg':
|
|
16
|
+
case 'png':
|
|
17
|
+
return images_1.ImageLoader;
|
|
18
|
+
case 'ktx-etc2':
|
|
19
|
+
case 'dds':
|
|
20
|
+
return textures_1.CompressedTextureLoader;
|
|
21
|
+
case 'ktx2':
|
|
22
|
+
return textures_1.BasisLoader;
|
|
23
|
+
default:
|
|
24
|
+
return null;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
const I3S_ATTRIBUTE_TYPE = 'i3s-attribute-type';
|
|
28
|
+
async function parseI3STileContent(arrayBuffer, tile, tileset, options, context) {
|
|
29
|
+
tile.content = tile.content || {};
|
|
30
|
+
tile.content.featureIds = tile.content.featureIds || null;
|
|
31
|
+
// construct featureData from defaultGeometrySchema;
|
|
32
|
+
tile.content.featureData = constructFeatureDataStruct(tileset);
|
|
33
|
+
tile.content.attributes = {};
|
|
34
|
+
if (tile.textureUrl) {
|
|
35
|
+
const url = (0, url_utils_1.getUrlWithToken)(tile.textureUrl, options?.i3s?.token);
|
|
36
|
+
const loader = getLoaderForTextureFormat(tile.textureFormat) || images_1.ImageLoader;
|
|
37
|
+
// @ts-ignore context must be defined
|
|
38
|
+
const response = await fetch(url);
|
|
39
|
+
const arrayBuffer = await response.arrayBuffer();
|
|
40
|
+
if (options?.i3s.decodeTextures) {
|
|
41
|
+
if (loader === images_1.ImageLoader) {
|
|
42
|
+
const options = { ...tile.textureLoaderOptions, image: { type: 'data' } };
|
|
43
|
+
try {
|
|
44
|
+
// @ts-ignore context must be defined
|
|
45
|
+
// Image constructor is not supported in worker thread.
|
|
46
|
+
// Do parsing image data on the main thread by using context to avoid worker issues.
|
|
47
|
+
tile.content.texture = await context.parse(arrayBuffer, options);
|
|
48
|
+
}
|
|
49
|
+
catch (e) {
|
|
50
|
+
// context object is different between worker and node.js conversion script.
|
|
51
|
+
// To prevent error we parse data in ordinary way if it is not parsed by using context.
|
|
52
|
+
tile.content.texture = await (0, core_1.parse)(arrayBuffer, loader, options);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
else if (loader === textures_1.CompressedTextureLoader || loader === textures_1.BasisLoader) {
|
|
56
|
+
const texture = await (0, core_1.load)(arrayBuffer, loader, tile.textureLoaderOptions);
|
|
57
|
+
tile.content.texture = {
|
|
58
|
+
compressed: true,
|
|
59
|
+
mipmaps: false,
|
|
60
|
+
width: texture[0].width,
|
|
61
|
+
height: texture[0].height,
|
|
62
|
+
data: texture
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
tile.content.texture = arrayBuffer;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
tile.content.material = makePbrMaterial(tile.materialDefinition, tile.content.texture);
|
|
71
|
+
if (tile.content.material) {
|
|
72
|
+
tile.content.texture = null;
|
|
73
|
+
}
|
|
74
|
+
return await parseI3SNodeGeometry(arrayBuffer, tile, options);
|
|
75
|
+
}
|
|
76
|
+
exports.parseI3STileContent = parseI3STileContent;
|
|
77
|
+
/* eslint-disable max-statements */
|
|
78
|
+
async function parseI3SNodeGeometry(arrayBuffer, tile, options) {
|
|
79
|
+
if (!tile.content) {
|
|
80
|
+
return tile;
|
|
81
|
+
}
|
|
82
|
+
const content = tile.content;
|
|
83
|
+
let attributes;
|
|
84
|
+
let vertexCount;
|
|
85
|
+
let byteOffset = 0;
|
|
86
|
+
let featureCount = 0;
|
|
87
|
+
if (tile.isDracoGeometry) {
|
|
88
|
+
const decompressedGeometry = await (0, core_1.parse)(arrayBuffer, draco_1.DracoLoader, {
|
|
89
|
+
draco: {
|
|
90
|
+
attributeNameEntry: I3S_ATTRIBUTE_TYPE
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
vertexCount = decompressedGeometry.header.vertexCount;
|
|
94
|
+
const indices = decompressedGeometry.indices.value;
|
|
95
|
+
const { POSITION, NORMAL, COLOR_0, TEXCOORD_0, ['feature-index']: featureIndex, ['uv-region']: uvRegion } = decompressedGeometry.attributes;
|
|
96
|
+
attributes = {
|
|
97
|
+
position: POSITION,
|
|
98
|
+
normal: NORMAL,
|
|
99
|
+
color: COLOR_0,
|
|
100
|
+
uv0: TEXCOORD_0,
|
|
101
|
+
uvRegion,
|
|
102
|
+
id: featureIndex,
|
|
103
|
+
indices
|
|
104
|
+
};
|
|
105
|
+
updateAttributesMetadata(attributes, decompressedGeometry);
|
|
106
|
+
const featureIds = getFeatureIdsFromFeatureIndexMetadata(featureIndex);
|
|
107
|
+
if (featureIds) {
|
|
108
|
+
flattenFeatureIdsByFeatureIndices(attributes, featureIds);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
else {
|
|
112
|
+
const { vertexAttributes, attributesOrder, featureAttributes, featureAttributeOrder } = content.featureData;
|
|
113
|
+
// First 8 bytes reserved for header (vertexCount and featureCount)
|
|
114
|
+
const headers = parseHeaders(content, arrayBuffer);
|
|
115
|
+
byteOffset = headers.byteOffset;
|
|
116
|
+
vertexCount = headers.vertexCount;
|
|
117
|
+
featureCount = headers.featureCount;
|
|
118
|
+
// Getting vertex attributes such as positions, normals, colors, etc...
|
|
119
|
+
const { attributes: normalizedVertexAttributes, byteOffset: offset } = normalizeAttributes(arrayBuffer, byteOffset, vertexAttributes, vertexCount,
|
|
120
|
+
// @ts-expect-error
|
|
121
|
+
attributesOrder);
|
|
122
|
+
// Getting feature attributes such as featureIds and faceRange
|
|
123
|
+
const { attributes: normalizedFeatureAttributes } = normalizeAttributes(arrayBuffer, offset, featureAttributes, featureCount, featureAttributeOrder);
|
|
124
|
+
flattenFeatureIdsByFaceRanges(normalizedFeatureAttributes);
|
|
125
|
+
attributes = concatAttributes(normalizedVertexAttributes, normalizedFeatureAttributes);
|
|
126
|
+
}
|
|
127
|
+
if (!options?.i3s?.coordinateSystem ||
|
|
128
|
+
options.i3s.coordinateSystem === constants_1.COORDINATE_SYSTEM.METER_OFFSETS) {
|
|
129
|
+
const enuMatrix = parsePositions(attributes.position, tile);
|
|
130
|
+
content.modelMatrix = enuMatrix.invert();
|
|
131
|
+
content.coordinateSystem = constants_1.COORDINATE_SYSTEM.METER_OFFSETS;
|
|
132
|
+
}
|
|
133
|
+
else {
|
|
134
|
+
content.modelMatrix = getModelMatrix(attributes.position);
|
|
135
|
+
content.coordinateSystem = constants_1.COORDINATE_SYSTEM.LNGLAT_OFFSETS;
|
|
136
|
+
}
|
|
137
|
+
content.attributes = {
|
|
138
|
+
positions: attributes.position,
|
|
139
|
+
normals: attributes.normal,
|
|
140
|
+
colors: normalizeAttribute(attributes.color),
|
|
141
|
+
texCoords: attributes.uv0,
|
|
142
|
+
uvRegions: normalizeAttribute(attributes.uvRegion) // Normalize from UInt16
|
|
143
|
+
};
|
|
144
|
+
content.indices = attributes.indices || null;
|
|
145
|
+
if (attributes.id && attributes.id.value) {
|
|
146
|
+
tile.content.featureIds = attributes.id.value;
|
|
147
|
+
}
|
|
148
|
+
// Remove undefined attributes
|
|
149
|
+
for (const attributeIndex in content.attributes) {
|
|
150
|
+
if (!content.attributes[attributeIndex]) {
|
|
151
|
+
delete content.attributes[attributeIndex];
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
content.vertexCount = vertexCount;
|
|
155
|
+
content.byteLength = arrayBuffer.byteLength;
|
|
156
|
+
return tile;
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Update attributes with metadata from decompressed geometry.
|
|
160
|
+
* @param decompressedGeometry
|
|
161
|
+
* @param attributes
|
|
162
|
+
*/
|
|
163
|
+
function updateAttributesMetadata(attributes, decompressedGeometry) {
|
|
164
|
+
for (const key in decompressedGeometry.loaderData.attributes) {
|
|
165
|
+
const dracoAttribute = decompressedGeometry.loaderData.attributes[key];
|
|
166
|
+
switch (dracoAttribute.name) {
|
|
167
|
+
case 'POSITION':
|
|
168
|
+
attributes.position.metadata = dracoAttribute.metadata;
|
|
169
|
+
break;
|
|
170
|
+
case 'feature-index':
|
|
171
|
+
attributes.id.metadata = dracoAttribute.metadata;
|
|
172
|
+
break;
|
|
173
|
+
default:
|
|
174
|
+
break;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* Do concatenation of attribute objects.
|
|
180
|
+
* Done as separate fucntion to avoid ts errors.
|
|
181
|
+
* @param normalizedVertexAttributes
|
|
182
|
+
* @param normalizedFeatureAttributes
|
|
183
|
+
* @returns - result of attributes concatenation.
|
|
184
|
+
*/
|
|
185
|
+
function concatAttributes(normalizedVertexAttributes, normalizedFeatureAttributes) {
|
|
186
|
+
return { ...normalizedVertexAttributes, ...normalizedFeatureAttributes };
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Normalize attribute to range [0..1] . Eg. convert colors buffer from [255,255,255,255] to [1,1,1,1]
|
|
190
|
+
* @param attribute - geometry attribute
|
|
191
|
+
* @returns - geometry attribute in right format
|
|
192
|
+
*/
|
|
193
|
+
function normalizeAttribute(attribute) {
|
|
194
|
+
if (!attribute) {
|
|
195
|
+
return attribute;
|
|
196
|
+
}
|
|
197
|
+
attribute.normalized = true;
|
|
198
|
+
return attribute;
|
|
199
|
+
}
|
|
200
|
+
function constructFeatureDataStruct(tileset) {
|
|
201
|
+
// seed featureData from defaultGeometrySchema
|
|
202
|
+
const defaultGeometrySchema = tileset.store.defaultGeometrySchema;
|
|
203
|
+
const featureData = defaultGeometrySchema;
|
|
204
|
+
// populate the vertex attributes value types and values per element
|
|
205
|
+
for (const geometryAttribute in constants_1.I3S_NAMED_GEOMETRY_ATTRIBUTES) {
|
|
206
|
+
for (const namedAttribute in constants_1.I3S_NAMED_VERTEX_ATTRIBUTES) {
|
|
207
|
+
const attribute = defaultGeometrySchema[geometryAttribute][namedAttribute];
|
|
208
|
+
if (attribute) {
|
|
209
|
+
const { byteOffset = 0, count = 0, valueType, valuesPerElement } = attribute;
|
|
210
|
+
featureData[geometryAttribute][namedAttribute] = {
|
|
211
|
+
valueType,
|
|
212
|
+
valuesPerElement,
|
|
213
|
+
byteOffset,
|
|
214
|
+
count
|
|
215
|
+
};
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
featureData.attributesOrder = defaultGeometrySchema.ordering;
|
|
220
|
+
return featureData;
|
|
221
|
+
}
|
|
222
|
+
function parseHeaders(content, arrayBuffer) {
|
|
223
|
+
let byteOffset = 0;
|
|
224
|
+
// First 8 bytes reserved for header (vertexCount and featurecount)
|
|
225
|
+
let vertexCount = 0;
|
|
226
|
+
let featureCount = 0;
|
|
227
|
+
content.featureData.header.forEach(({ property, type }) => {
|
|
228
|
+
const TypedArrayTypeHeader = (0, constants_1.getConstructorForDataFormat)(type);
|
|
229
|
+
if (property === constants_1.I3S_NAMED_HEADER_ATTRIBUTES.vertexCount) {
|
|
230
|
+
// @ts-expect-error
|
|
231
|
+
vertexCount = new TypedArrayTypeHeader(arrayBuffer, 0, 4)[0];
|
|
232
|
+
byteOffset += (0, constants_1.sizeOf)(type);
|
|
233
|
+
}
|
|
234
|
+
if (property === constants_1.I3S_NAMED_HEADER_ATTRIBUTES.featureCount) {
|
|
235
|
+
// @ts-expect-error
|
|
236
|
+
featureCount = new TypedArrayTypeHeader(arrayBuffer, 4, 4)[0];
|
|
237
|
+
byteOffset += (0, constants_1.sizeOf)(type);
|
|
238
|
+
}
|
|
239
|
+
});
|
|
240
|
+
return {
|
|
241
|
+
vertexCount,
|
|
242
|
+
featureCount,
|
|
243
|
+
byteOffset
|
|
244
|
+
};
|
|
245
|
+
}
|
|
246
|
+
/* eslint-enable max-statements */
|
|
247
|
+
function normalizeAttributes(arrayBuffer, byteOffset, vertexAttributes, vertexCount, attributesOrder) {
|
|
248
|
+
const attributes = {};
|
|
249
|
+
// the order of attributes depend on the order being added to the vertexAttributes object
|
|
250
|
+
for (const attribute of attributesOrder) {
|
|
251
|
+
if (vertexAttributes[attribute]) {
|
|
252
|
+
const { valueType, valuesPerElement } = vertexAttributes[attribute];
|
|
253
|
+
// update count and byteOffset count by calculating from defaultGeometrySchema + binnary content
|
|
254
|
+
const count = vertexCount;
|
|
255
|
+
// protect from arrayBuffer read overunns by NOT assuming node has regions always even though its declared in defaultGeometrySchema.
|
|
256
|
+
// In i3s 1.6: client is required to decide that based on ./shared resource of the node (materialDefinitions.[Mat_id].params.vertexRegions == true)
|
|
257
|
+
// In i3s 1.7 the property has been rolled into the 3d scene layer json/node pages.
|
|
258
|
+
// Code below does not account when the bytelength is actually bigger than
|
|
259
|
+
// the calculated value (b\c the tile potentially could have mesh segmentation information).
|
|
260
|
+
// In those cases tiles without regions could fail or have garbage values.
|
|
261
|
+
if (byteOffset + count * valuesPerElement > arrayBuffer.byteLength) {
|
|
262
|
+
break;
|
|
263
|
+
}
|
|
264
|
+
const buffer = arrayBuffer.slice(byteOffset);
|
|
265
|
+
let value = [];
|
|
266
|
+
if (valueType === 'UInt64') {
|
|
267
|
+
value = parseUint64Values(buffer, count * valuesPerElement, (0, constants_1.sizeOf)(valueType));
|
|
268
|
+
}
|
|
269
|
+
else {
|
|
270
|
+
const TypedArrayType = (0, constants_1.getConstructorForDataFormat)(valueType);
|
|
271
|
+
// @ts-expect-error
|
|
272
|
+
value = new TypedArrayType(buffer, 0, count * valuesPerElement);
|
|
273
|
+
}
|
|
274
|
+
attributes[attribute] = {
|
|
275
|
+
value,
|
|
276
|
+
type: constants_1.GL_TYPE_MAP[valueType],
|
|
277
|
+
size: valuesPerElement
|
|
278
|
+
};
|
|
279
|
+
switch (attribute) {
|
|
280
|
+
case 'color':
|
|
281
|
+
attributes.color.normalized = true;
|
|
282
|
+
break;
|
|
283
|
+
case 'position':
|
|
284
|
+
case 'region':
|
|
285
|
+
case 'normal':
|
|
286
|
+
default:
|
|
287
|
+
}
|
|
288
|
+
byteOffset = byteOffset + count * valuesPerElement * (0, constants_1.sizeOf)(valueType);
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
return { attributes, byteOffset };
|
|
292
|
+
}
|
|
293
|
+
/**
|
|
294
|
+
* Parse buffer to return array of uint64 values
|
|
295
|
+
*
|
|
296
|
+
* @param buffer
|
|
297
|
+
* @param elementsCount
|
|
298
|
+
* @returns 64-bit array of values until precision is lost after Number.MAX_SAFE_INTEGER
|
|
299
|
+
*/
|
|
300
|
+
function parseUint64Values(buffer, elementsCount, attributeSize) {
|
|
301
|
+
const values = [];
|
|
302
|
+
const dataView = new DataView(buffer);
|
|
303
|
+
let offset = 0;
|
|
304
|
+
for (let index = 0; index < elementsCount; index++) {
|
|
305
|
+
// split 64-bit number into two 32-bit parts
|
|
306
|
+
const left = dataView.getUint32(offset, true);
|
|
307
|
+
const right = dataView.getUint32(offset + 4, true);
|
|
308
|
+
// combine the two 32-bit values
|
|
309
|
+
const value = left + 2 ** 32 * right;
|
|
310
|
+
values.push(value);
|
|
311
|
+
offset += attributeSize;
|
|
312
|
+
}
|
|
313
|
+
return values;
|
|
314
|
+
}
|
|
315
|
+
function parsePositions(attribute, tile) {
|
|
316
|
+
const mbs = tile.mbs;
|
|
317
|
+
const value = attribute.value;
|
|
318
|
+
const metadata = attribute.metadata;
|
|
319
|
+
const enuMatrix = new core_2.Matrix4();
|
|
320
|
+
const cartographicOrigin = new core_2.Vector3(mbs[0], mbs[1], mbs[2]);
|
|
321
|
+
const cartesianOrigin = new core_2.Vector3();
|
|
322
|
+
geospatial_1.Ellipsoid.WGS84.cartographicToCartesian(cartographicOrigin, cartesianOrigin);
|
|
323
|
+
geospatial_1.Ellipsoid.WGS84.eastNorthUpToFixedFrame(cartesianOrigin, enuMatrix);
|
|
324
|
+
attribute.value = offsetsToCartesians(value, metadata, cartographicOrigin);
|
|
325
|
+
return enuMatrix;
|
|
326
|
+
}
|
|
327
|
+
/**
|
|
328
|
+
* Converts position coordinates to absolute cartesian coordinates
|
|
329
|
+
* @param vertices - "position" attribute data
|
|
330
|
+
* @param metadata - When the geometry is DRACO compressed, contain position attribute's metadata
|
|
331
|
+
* https://github.com/Esri/i3s-spec/blob/master/docs/1.7/compressedAttributes.cmn.md
|
|
332
|
+
* @param cartographicOrigin - Cartographic origin coordinates
|
|
333
|
+
* @returns - converted "position" data
|
|
334
|
+
*/
|
|
335
|
+
function offsetsToCartesians(vertices, metadata = {}, cartographicOrigin) {
|
|
336
|
+
const positions = new Float64Array(vertices.length);
|
|
337
|
+
const scaleX = (metadata['i3s-scale_x'] && metadata['i3s-scale_x'].double) || 1;
|
|
338
|
+
const scaleY = (metadata['i3s-scale_y'] && metadata['i3s-scale_y'].double) || 1;
|
|
339
|
+
for (let i = 0; i < positions.length; i += 3) {
|
|
340
|
+
positions[i] = vertices[i] * scaleX + cartographicOrigin.x;
|
|
341
|
+
positions[i + 1] = vertices[i + 1] * scaleY + cartographicOrigin.y;
|
|
342
|
+
positions[i + 2] = vertices[i + 2] + cartographicOrigin.z;
|
|
343
|
+
}
|
|
344
|
+
for (let i = 0; i < positions.length; i += 3) {
|
|
345
|
+
// @ts-ignore
|
|
346
|
+
geospatial_1.Ellipsoid.WGS84.cartographicToCartesian(positions.subarray(i, i + 3), scratchVector);
|
|
347
|
+
positions[i] = scratchVector.x;
|
|
348
|
+
positions[i + 1] = scratchVector.y;
|
|
349
|
+
positions[i + 2] = scratchVector.z;
|
|
350
|
+
}
|
|
351
|
+
return positions;
|
|
352
|
+
}
|
|
353
|
+
/**
|
|
354
|
+
* Get model matrix for loaded vertices
|
|
355
|
+
* @param positions positions attribute
|
|
356
|
+
* @returns Matrix4 - model matrix for geometry transformation
|
|
357
|
+
*/
|
|
358
|
+
function getModelMatrix(positions) {
|
|
359
|
+
const metadata = positions.metadata;
|
|
360
|
+
const scaleX = metadata?.['i3s-scale_x']?.double || 1;
|
|
361
|
+
const scaleY = metadata?.['i3s-scale_y']?.double || 1;
|
|
362
|
+
const modelMatrix = new core_2.Matrix4();
|
|
363
|
+
modelMatrix[0] = scaleX;
|
|
364
|
+
modelMatrix[5] = scaleY;
|
|
365
|
+
return modelMatrix;
|
|
366
|
+
}
|
|
367
|
+
/**
|
|
368
|
+
* Makes a glTF-compatible PBR material from an I3S material definition
|
|
369
|
+
* @param materialDefinition - i3s material definition
|
|
370
|
+
* https://github.com/Esri/i3s-spec/blob/master/docs/1.7/materialDefinitions.cmn.md
|
|
371
|
+
* @param texture - texture image
|
|
372
|
+
* @returns {object}
|
|
373
|
+
*/
|
|
374
|
+
function makePbrMaterial(materialDefinition, texture) {
|
|
375
|
+
let pbrMaterial;
|
|
376
|
+
if (materialDefinition) {
|
|
377
|
+
pbrMaterial = {
|
|
378
|
+
...materialDefinition,
|
|
379
|
+
pbrMetallicRoughness: materialDefinition.pbrMetallicRoughness
|
|
380
|
+
? { ...materialDefinition.pbrMetallicRoughness }
|
|
381
|
+
: { baseColorFactor: [255, 255, 255, 255] }
|
|
382
|
+
};
|
|
383
|
+
}
|
|
384
|
+
else {
|
|
385
|
+
pbrMaterial = {
|
|
386
|
+
pbrMetallicRoughness: {}
|
|
387
|
+
};
|
|
388
|
+
if (texture) {
|
|
389
|
+
pbrMaterial.pbrMetallicRoughness.baseColorTexture = { texCoord: 0 };
|
|
390
|
+
}
|
|
391
|
+
else {
|
|
392
|
+
pbrMaterial.pbrMetallicRoughness.baseColorFactor = [255, 255, 255, 255];
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
// Set default 0.25 per spec https://github.com/Esri/i3s-spec/blob/master/docs/1.7/materialDefinitions.cmn.md
|
|
396
|
+
pbrMaterial.alphaCutoff = pbrMaterial.alphaCutoff || 0.25;
|
|
397
|
+
if (pbrMaterial.alphaMode) {
|
|
398
|
+
// I3S contain alphaMode in lowerCase
|
|
399
|
+
pbrMaterial.alphaMode = pbrMaterial.alphaMode.toUpperCase();
|
|
400
|
+
}
|
|
401
|
+
// Convert colors from [255,255,255,255] to [1,1,1,1]
|
|
402
|
+
if (pbrMaterial.emissiveFactor) {
|
|
403
|
+
pbrMaterial.emissiveFactor = convertColorFormat(pbrMaterial.emissiveFactor);
|
|
404
|
+
}
|
|
405
|
+
if (pbrMaterial.pbrMetallicRoughness && pbrMaterial.pbrMetallicRoughness.baseColorFactor) {
|
|
406
|
+
pbrMaterial.pbrMetallicRoughness.baseColorFactor = convertColorFormat(pbrMaterial.pbrMetallicRoughness.baseColorFactor);
|
|
407
|
+
}
|
|
408
|
+
setMaterialTexture(pbrMaterial, texture);
|
|
409
|
+
return pbrMaterial;
|
|
410
|
+
}
|
|
411
|
+
/**
|
|
412
|
+
* Convert color from [255,255,255,255] to [1,1,1,1]
|
|
413
|
+
* @param colorFactor - color array
|
|
414
|
+
* @returns - new color array
|
|
415
|
+
*/
|
|
416
|
+
function convertColorFormat(colorFactor) {
|
|
417
|
+
const normalizedColor = [...colorFactor];
|
|
418
|
+
for (let index = 0; index < colorFactor.length; index++) {
|
|
419
|
+
normalizedColor[index] = colorFactor[index] / 255;
|
|
420
|
+
}
|
|
421
|
+
return normalizedColor;
|
|
422
|
+
}
|
|
423
|
+
/**
|
|
424
|
+
* Set texture in PBR material
|
|
425
|
+
* @param {object} material - i3s material definition
|
|
426
|
+
* @param image - texture image
|
|
427
|
+
* @returns
|
|
428
|
+
*/
|
|
429
|
+
function setMaterialTexture(material, image) {
|
|
430
|
+
const texture = { source: { image } };
|
|
431
|
+
// I3SLoader now support loading only one texture. This elseif sequence will assign this texture to one of
|
|
432
|
+
// properties defined in materialDefinition
|
|
433
|
+
if (material.pbrMetallicRoughness && material.pbrMetallicRoughness.baseColorTexture) {
|
|
434
|
+
material.pbrMetallicRoughness.baseColorTexture = {
|
|
435
|
+
...material.pbrMetallicRoughness.baseColorTexture,
|
|
436
|
+
texture
|
|
437
|
+
};
|
|
438
|
+
}
|
|
439
|
+
else if (material.emissiveTexture) {
|
|
440
|
+
material.emissiveTexture = { ...material.emissiveTexture, texture };
|
|
441
|
+
}
|
|
442
|
+
else if (material.pbrMetallicRoughness &&
|
|
443
|
+
material.pbrMetallicRoughness.metallicRoughnessTexture) {
|
|
444
|
+
material.pbrMetallicRoughness.metallicRoughnessTexture = {
|
|
445
|
+
...material.pbrMetallicRoughness.metallicRoughnessTexture,
|
|
446
|
+
texture
|
|
447
|
+
};
|
|
448
|
+
}
|
|
449
|
+
else if (material.normalTexture) {
|
|
450
|
+
material.normalTexture = { ...material.normalTexture, texture };
|
|
451
|
+
}
|
|
452
|
+
else if (material.occlusionTexture) {
|
|
453
|
+
material.occlusionTexture = { ...material.occlusionTexture, texture };
|
|
454
|
+
}
|
|
455
|
+
}
|
|
456
|
+
/**
|
|
457
|
+
* Flatten feature ids using face ranges
|
|
458
|
+
* @param normalizedFeatureAttributes
|
|
459
|
+
* @returns
|
|
460
|
+
*/
|
|
461
|
+
function flattenFeatureIdsByFaceRanges(normalizedFeatureAttributes) {
|
|
462
|
+
const { id, faceRange } = normalizedFeatureAttributes;
|
|
463
|
+
if (!id || !faceRange) {
|
|
464
|
+
return;
|
|
465
|
+
}
|
|
466
|
+
const featureIds = id.value;
|
|
467
|
+
const range = faceRange.value;
|
|
468
|
+
const featureIdsLength = range[range.length - 1] + 1;
|
|
469
|
+
const orderedFeatureIndices = new Uint32Array(featureIdsLength * 3);
|
|
470
|
+
let featureIndex = 0;
|
|
471
|
+
let startIndex = 0;
|
|
472
|
+
for (let index = 1; index < range.length; index += 2) {
|
|
473
|
+
const fillId = Number(featureIds[featureIndex]);
|
|
474
|
+
const endValue = range[index];
|
|
475
|
+
const prevValue = range[index - 1];
|
|
476
|
+
const trianglesCount = endValue - prevValue + 1;
|
|
477
|
+
const endIndex = startIndex + trianglesCount * 3;
|
|
478
|
+
orderedFeatureIndices.fill(fillId, startIndex, endIndex);
|
|
479
|
+
featureIndex++;
|
|
480
|
+
startIndex = endIndex;
|
|
481
|
+
}
|
|
482
|
+
normalizedFeatureAttributes.id.value = orderedFeatureIndices;
|
|
483
|
+
}
|
|
484
|
+
/**
|
|
485
|
+
* Flatten feature ids using featureIndices
|
|
486
|
+
* @param attributes
|
|
487
|
+
* @param featureIds
|
|
488
|
+
* @returns
|
|
489
|
+
*/
|
|
490
|
+
function flattenFeatureIdsByFeatureIndices(attributes, featureIds) {
|
|
491
|
+
const featureIndices = attributes.id.value;
|
|
492
|
+
const result = new Float32Array(featureIndices.length);
|
|
493
|
+
for (let index = 0; index < featureIndices.length; index++) {
|
|
494
|
+
result[index] = featureIds[featureIndices[index]];
|
|
495
|
+
}
|
|
496
|
+
attributes.id.value = result;
|
|
497
|
+
}
|
|
498
|
+
/**
|
|
499
|
+
* Flatten feature ids using featureIndices
|
|
500
|
+
* @param featureIndex
|
|
501
|
+
* @returns
|
|
502
|
+
*/
|
|
503
|
+
function getFeatureIdsFromFeatureIndexMetadata(featureIndex) {
|
|
504
|
+
return (featureIndex &&
|
|
505
|
+
featureIndex.metadata &&
|
|
506
|
+
featureIndex.metadata['i3s-feature-ids'] &&
|
|
507
|
+
featureIndex.metadata['i3s-feature-ids'].intArray);
|
|
508
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export declare function normalizeTileData(tile: any, options: any, context: any): any;
|
|
2
|
+
export declare function normalizeTileNonUrlData(tile: any): any;
|
|
3
|
+
export declare function normalizeTilesetData(tileset: any, options: any, context: any): Promise<void>;
|
|
4
|
+
//# sourceMappingURL=parse-i3s.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parse-i3s.d.ts","sourceRoot":"","sources":["../../../src/lib/parsers/parse-i3s.ts"],"names":[],"mappings":"AAOA,wBAAgB,iBAAiB,CAAC,IAAI,KAAA,EAAE,OAAO,KAAA,EAAE,OAAO,KAAA,OAoBvD;AAED,wBAAgB,uBAAuB,CAAC,IAAI,KAAA,OAqC3C;AAED,wBAAsB,oBAAoB,CAAC,OAAO,KAAA,EAAE,OAAO,KAAA,EAAE,OAAO,KAAA,iBAqBnE"}
|