@loaders.gl/3d-tiles 4.0.0-alpha.22 → 4.0.0-alpha.24
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/3d-tiles-archive/3d-tiles-archive-archive.d.ts +2 -1
- package/dist/3d-tiles-archive/3d-tiles-archive-archive.d.ts.map +1 -1
- package/dist/3d-tiles-archive/3d-tiles-archive-parser.d.ts +1 -1
- package/dist/3d-tiles-archive/3d-tiles-archive-parser.d.ts.map +1 -1
- package/dist/3d-tiles-archive-loader.d.ts +1 -1
- package/dist/3d-tiles-archive-loader.d.ts.map +1 -1
- package/dist/cesium-ion-loader.d.ts +2 -2
- package/dist/cesium-ion-loader.d.ts.map +1 -1
- package/dist/dist.min.js +2074 -1483
- package/dist/es5/3d-tiles-archive/3d-tiles-archive-archive.js.map +1 -1
- package/dist/es5/3d-tiles-archive/3d-tiles-archive-parser.js.map +1 -1
- package/dist/es5/3d-tiles-archive-loader.js +3 -3
- package/dist/es5/3d-tiles-archive-loader.js.map +1 -1
- package/dist/es5/cesium-ion-loader.js.map +1 -1
- package/dist/es5/lib/filesystems/tiles-3d-archive-file-system.js.map +1 -1
- package/dist/es5/lib/parsers/parse-3d-tile-composite.js +3 -1
- package/dist/es5/lib/parsers/parse-3d-tile-composite.js.map +1 -1
- package/dist/es5/lib/parsers/parse-3d-tile-gltf.js +3 -1
- package/dist/es5/lib/parsers/parse-3d-tile-gltf.js.map +1 -1
- package/dist/es5/lib/parsers/parse-3d-tile.js +3 -1
- package/dist/es5/lib/parsers/parse-3d-tile.js.map +1 -1
- package/dist/es5/lib/utils/version.js +1 -1
- package/dist/es5/tile-3d-subtree-loader.js.map +1 -1
- package/dist/es5/tile-3d-writer.js.map +1 -1
- package/dist/es5/tiles-3d-loader.js +2 -0
- package/dist/es5/tiles-3d-loader.js.map +1 -1
- package/dist/es5/types.js.map +1 -1
- package/dist/esm/3d-tiles-archive/3d-tiles-archive-archive.js.map +1 -1
- package/dist/esm/3d-tiles-archive/3d-tiles-archive-parser.js.map +1 -1
- package/dist/esm/3d-tiles-archive-loader.js +2 -2
- package/dist/esm/3d-tiles-archive-loader.js.map +1 -1
- package/dist/esm/cesium-ion-loader.js.map +1 -1
- package/dist/esm/lib/filesystems/tiles-3d-archive-file-system.js.map +1 -1
- package/dist/esm/lib/parsers/parse-3d-tile-composite.js +3 -1
- package/dist/esm/lib/parsers/parse-3d-tile-composite.js.map +1 -1
- package/dist/esm/lib/parsers/parse-3d-tile-gltf.js +2 -1
- package/dist/esm/lib/parsers/parse-3d-tile-gltf.js.map +1 -1
- package/dist/esm/lib/parsers/parse-3d-tile.js +3 -1
- package/dist/esm/lib/parsers/parse-3d-tile.js.map +1 -1
- package/dist/esm/lib/utils/version.js +1 -1
- package/dist/esm/tile-3d-subtree-loader.js.map +1 -1
- package/dist/esm/tile-3d-writer.js.map +1 -1
- package/dist/esm/tiles-3d-loader.js +2 -0
- package/dist/esm/tiles-3d-loader.js.map +1 -1
- package/dist/esm/types.js.map +1 -1
- package/dist/lib/filesystems/tiles-3d-archive-file-system.d.ts +2 -1
- package/dist/lib/filesystems/tiles-3d-archive-file-system.d.ts.map +1 -1
- package/dist/lib/parsers/parse-3d-tile-gltf.d.ts +1 -1
- package/dist/lib/parsers/parse-3d-tile-gltf.d.ts.map +1 -1
- package/dist/lib/parsers/parse-3d-tile.d.ts +1 -1
- package/dist/lib/parsers/parse-3d-tile.d.ts.map +1 -1
- package/dist/tile-3d-subtree-loader.d.ts +3 -3
- package/dist/tile-3d-subtree-loader.d.ts.map +1 -1
- package/dist/tile-3d-writer.d.ts +2 -2
- package/dist/tile-3d-writer.d.ts.map +1 -1
- package/dist/tiles-3d-loader.d.ts +2 -1
- package/dist/tiles-3d-loader.d.ts.map +1 -1
- package/dist/types.d.ts +2 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +8 -8
- package/src/3d-tiles-archive/3d-tiles-archive-archive.ts +2 -1
- package/src/3d-tiles-archive/3d-tiles-archive-parser.ts +1 -1
- package/src/3d-tiles-archive-loader.ts +2 -2
- package/src/cesium-ion-loader.ts +2 -3
- package/src/lib/filesystems/tiles-3d-archive-file-system.ts +1 -1
- package/src/lib/parsers/parse-3d-tile-composite.ts +1 -1
- package/src/lib/parsers/parse-3d-tile-gltf.ts +3 -2
- package/src/lib/parsers/parse-3d-tile.ts +2 -2
- package/src/tile-3d-subtree-loader.ts +3 -3
- package/src/tile-3d-writer.ts +2 -2
- package/src/tiles-3d-loader.ts +16 -4
- package/src/types.ts +3 -0
- package/dist/3d-tiles-archive/3d-tiles-archive-archive.js +0 -72
- package/dist/3d-tiles-archive/3d-tiles-archive-parser.js +0 -33
- package/dist/3d-tiles-archive-loader.js +0 -31
- package/dist/bundle.js +0 -5
- package/dist/cesium-ion-loader.js +0 -41
- package/dist/index.js +0 -30
- package/dist/lib/classes/helpers/tile-3d-accessor-utils.js +0 -113
- package/dist/lib/classes/tile-3d-batch-table-hierarchy.js +0 -197
- package/dist/lib/classes/tile-3d-batch-table.js +0 -245
- package/dist/lib/classes/tile-3d-feature-table.js +0 -72
- package/dist/lib/constants.js +0 -26
- package/dist/lib/encoders/encode-3d-tile-batched-model.js +0 -46
- package/dist/lib/encoders/encode-3d-tile-composite.js +0 -24
- package/dist/lib/encoders/encode-3d-tile-instanced-model.js +0 -38
- package/dist/lib/encoders/encode-3d-tile-point-cloud.js +0 -39
- package/dist/lib/encoders/encode-3d-tile.js +0 -33
- package/dist/lib/encoders/helpers/encode-3d-tile-header.js +0 -30
- package/dist/lib/filesystems/tiles-3d-archive-file-system.js +0 -75
- package/dist/lib/ion/ion.js +0 -68
- package/dist/lib/parsers/helpers/normalize-3d-tile-colors.js +0 -65
- package/dist/lib/parsers/helpers/normalize-3d-tile-normals.js +0 -30
- package/dist/lib/parsers/helpers/normalize-3d-tile-positions.js +0 -42
- package/dist/lib/parsers/helpers/parse-3d-implicit-tiles.js +0 -303
- package/dist/lib/parsers/helpers/parse-3d-tile-gltf-view.js +0 -96
- package/dist/lib/parsers/helpers/parse-3d-tile-header.js +0 -28
- package/dist/lib/parsers/helpers/parse-3d-tile-subtree.js +0 -87
- package/dist/lib/parsers/helpers/parse-3d-tile-tables.js +0 -93
- package/dist/lib/parsers/helpers/parse-utils.js +0 -32
- package/dist/lib/parsers/parse-3d-tile-batched-model.js +0 -33
- package/dist/lib/parsers/parse-3d-tile-composite.js +0 -24
- package/dist/lib/parsers/parse-3d-tile-gltf.js +0 -28
- package/dist/lib/parsers/parse-3d-tile-header.js +0 -194
- package/dist/lib/parsers/parse-3d-tile-instanced-model.js +0 -172
- package/dist/lib/parsers/parse-3d-tile-point-cloud.js +0 -441
- package/dist/lib/parsers/parse-3d-tile.js +0 -33
- package/dist/lib/utils/obb/s2-corners-to-obb.js +0 -37
- package/dist/lib/utils/s2/converters/s2-to-boundary.js +0 -61
- package/dist/lib/utils/s2/converters/s2-to-obb-points.js +0 -36
- package/dist/lib/utils/s2/converters/s2-to-region.js +0 -59
- package/dist/lib/utils/s2/index.js +0 -23
- package/dist/lib/utils/s2/s2-geometry-functions.js +0 -29
- package/dist/lib/utils/s2/s2-token-functions.js +0 -68
- package/dist/lib/utils/s2/s2geometry/s2-cell-utils.js +0 -32
- package/dist/lib/utils/s2/s2geometry/s2-geometry.js +0 -260
- package/dist/lib/utils/version.js +0 -7
- package/dist/tile-3d-subtree-loader.js +0 -23
- package/dist/tile-3d-writer.js +0 -27
- package/dist/tiles-3d-loader.js +0 -76
- package/dist/types.js +0 -2
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const SUBTREE_FILE_MAGIC = 0x74627573;
|
|
4
|
-
const SUBTREE_FILE_VERSION = 1;
|
|
5
|
-
/**
|
|
6
|
-
* Parse subtree file
|
|
7
|
-
* Spec - https://github.com/CesiumGS/3d-tiles/tree/main/extensions/3DTILES_implicit_tiling#subtree-file-format
|
|
8
|
-
* @param data
|
|
9
|
-
* @returns
|
|
10
|
-
*/
|
|
11
|
-
// eslint-disable-next-line max-statements
|
|
12
|
-
async function parse3DTilesSubtree(data, options, context) {
|
|
13
|
-
const magic = new Uint32Array(data.slice(0, 4));
|
|
14
|
-
if (magic[0] !== SUBTREE_FILE_MAGIC) {
|
|
15
|
-
throw new Error('Wrong subtree file magic number');
|
|
16
|
-
}
|
|
17
|
-
const version = new Uint32Array(data.slice(4, 8));
|
|
18
|
-
if (version[0] !== SUBTREE_FILE_VERSION) {
|
|
19
|
-
throw new Error('Wrong subtree file verson, must be 1');
|
|
20
|
-
}
|
|
21
|
-
const jsonByteLength = parseUint64Value(data.slice(8, 16));
|
|
22
|
-
const stringAttribute = new Uint8Array(data, 24, jsonByteLength);
|
|
23
|
-
const textDecoder = new TextDecoder('utf8');
|
|
24
|
-
const string = textDecoder.decode(stringAttribute);
|
|
25
|
-
const subtree = JSON.parse(string);
|
|
26
|
-
const binaryByteLength = parseUint64Value(data.slice(16, 24));
|
|
27
|
-
let internalBinaryBuffer = new ArrayBuffer(0);
|
|
28
|
-
if (binaryByteLength) {
|
|
29
|
-
internalBinaryBuffer = data.slice(24 + jsonByteLength);
|
|
30
|
-
}
|
|
31
|
-
await loadExplicitBitstream(subtree, subtree.tileAvailability, internalBinaryBuffer, context);
|
|
32
|
-
if (Array.isArray(subtree.contentAvailability)) {
|
|
33
|
-
for (const contentAvailability of subtree.contentAvailability) {
|
|
34
|
-
await loadExplicitBitstream(subtree, contentAvailability, internalBinaryBuffer, context);
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
else {
|
|
38
|
-
await loadExplicitBitstream(subtree, subtree.contentAvailability, internalBinaryBuffer, context);
|
|
39
|
-
}
|
|
40
|
-
await loadExplicitBitstream(subtree, subtree.childSubtreeAvailability, internalBinaryBuffer, context);
|
|
41
|
-
return subtree;
|
|
42
|
-
}
|
|
43
|
-
exports.default = parse3DTilesSubtree;
|
|
44
|
-
/**
|
|
45
|
-
* Load explicit bitstream for subtree availability data.
|
|
46
|
-
* @param subtree - subtree data
|
|
47
|
-
* @param availabilityObject - tileAvailability / contentAvailability / childSubtreeAvailability object
|
|
48
|
-
* @param internalBinaryBuffer - subtree binary buffer
|
|
49
|
-
* @param context - loaders.gl context
|
|
50
|
-
*/
|
|
51
|
-
async function loadExplicitBitstream(subtree, availabilityObject, internalBinaryBuffer, context) {
|
|
52
|
-
const bufferViewIndex = Number.isFinite(availabilityObject.bitstream)
|
|
53
|
-
? availabilityObject.bitstream
|
|
54
|
-
: availabilityObject.bufferView;
|
|
55
|
-
if (typeof bufferViewIndex !== 'number') {
|
|
56
|
-
return;
|
|
57
|
-
}
|
|
58
|
-
const bufferView = subtree.bufferViews[bufferViewIndex];
|
|
59
|
-
const buffer = subtree.buffers[bufferView.buffer];
|
|
60
|
-
if (!context?.baseUrl) {
|
|
61
|
-
throw new Error('Url is not provided');
|
|
62
|
-
}
|
|
63
|
-
if (!context.fetch) {
|
|
64
|
-
throw new Error('fetch is not provided');
|
|
65
|
-
}
|
|
66
|
-
// External bitstream loading
|
|
67
|
-
if (buffer.uri) {
|
|
68
|
-
const bufferUri = `${context?.baseUrl || ''}/${buffer.uri}`;
|
|
69
|
-
const response = await context.fetch(bufferUri);
|
|
70
|
-
const data = await response.arrayBuffer();
|
|
71
|
-
availabilityObject.explicitBitstream = new Uint8Array(data, bufferView.byteOffset, bufferView.byteLength);
|
|
72
|
-
return;
|
|
73
|
-
}
|
|
74
|
-
availabilityObject.explicitBitstream = new Uint8Array(internalBinaryBuffer, bufferView.byteOffset, bufferView.byteLength);
|
|
75
|
-
}
|
|
76
|
-
/**
|
|
77
|
-
* Parse buffer to return uint64 value
|
|
78
|
-
* @param buffer
|
|
79
|
-
* @returns 64-bit value until precision is lost after Number.MAX_SAFE_INTEGER
|
|
80
|
-
*/
|
|
81
|
-
function parseUint64Value(buffer) {
|
|
82
|
-
const dataView = new DataView(buffer);
|
|
83
|
-
const left = dataView.getUint32(0, true);
|
|
84
|
-
const right = dataView.getUint32(4, true);
|
|
85
|
-
// combine the two 32-bit values
|
|
86
|
-
return left + 2 ** 32 * right;
|
|
87
|
-
}
|
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// This file is derived from the Cesium code base under Apache 2 license
|
|
3
|
-
// See LICENSE.md and https://github.com/AnalyticalGraphicsInc/cesium/blob/master/LICENSE.md
|
|
4
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
-
exports.parse3DTileTablesSync = exports.parse3DTileTablesHeaderSync = void 0;
|
|
6
|
-
const parse_utils_1 = require("./parse-utils");
|
|
7
|
-
const SIZEOF_UINT32 = 4;
|
|
8
|
-
const DEPRECATION_WARNING = 'b3dm tile in legacy format.';
|
|
9
|
-
// eslint-disable-next-line max-statements
|
|
10
|
-
function parse3DTileTablesHeaderSync(tile, arrayBuffer, byteOffset) {
|
|
11
|
-
const view = new DataView(arrayBuffer);
|
|
12
|
-
let batchLength;
|
|
13
|
-
tile.header = tile.header || {};
|
|
14
|
-
let featureTableJsonByteLength = view.getUint32(byteOffset, true);
|
|
15
|
-
byteOffset += SIZEOF_UINT32;
|
|
16
|
-
let featureTableBinaryByteLength = view.getUint32(byteOffset, true);
|
|
17
|
-
byteOffset += SIZEOF_UINT32;
|
|
18
|
-
let batchTableJsonByteLength = view.getUint32(byteOffset, true);
|
|
19
|
-
byteOffset += SIZEOF_UINT32;
|
|
20
|
-
let batchTableBinaryByteLength = view.getUint32(byteOffset, true);
|
|
21
|
-
byteOffset += SIZEOF_UINT32;
|
|
22
|
-
// First legacy header format - [batchLength] [batchTableByteLength] ('batchTableJsonByteLength': JSON starts with a quotation mark or the glTF magic)
|
|
23
|
-
// Second legacy format - [batchTableJsonByteLength] [batchTableBinaryByteLength] [batchLength] (Second legacy format is similar as first but here we check 'batchTableBinaryByteLength' instead)
|
|
24
|
-
// Current header format - [featureTableJsonByteLength] [featureTableBinaryByteLength] [batchTableJsonByteLength] [batchTableBinaryByteLength]
|
|
25
|
-
// First byte will be 0x22 or 0x67. The minimum uint32 expected is 0x22000000 = 570425344 = 570MB.
|
|
26
|
-
if (batchTableJsonByteLength >= 570425344) {
|
|
27
|
-
byteOffset -= SIZEOF_UINT32 * 2;
|
|
28
|
-
batchLength = featureTableJsonByteLength;
|
|
29
|
-
batchTableJsonByteLength = featureTableBinaryByteLength;
|
|
30
|
-
batchTableBinaryByteLength = 0;
|
|
31
|
-
featureTableJsonByteLength = 0;
|
|
32
|
-
featureTableBinaryByteLength = 0;
|
|
33
|
-
console.warn(DEPRECATION_WARNING); // eslint-disable-line
|
|
34
|
-
}
|
|
35
|
-
else if (batchTableBinaryByteLength >= 570425344) {
|
|
36
|
-
byteOffset -= SIZEOF_UINT32;
|
|
37
|
-
batchLength = batchTableJsonByteLength;
|
|
38
|
-
batchTableJsonByteLength = featureTableJsonByteLength;
|
|
39
|
-
batchTableBinaryByteLength = featureTableBinaryByteLength;
|
|
40
|
-
featureTableJsonByteLength = 0;
|
|
41
|
-
featureTableBinaryByteLength = 0;
|
|
42
|
-
console.warn(DEPRECATION_WARNING); // eslint-disable-line
|
|
43
|
-
}
|
|
44
|
-
tile.header.featureTableJsonByteLength = featureTableJsonByteLength;
|
|
45
|
-
tile.header.featureTableBinaryByteLength = featureTableBinaryByteLength;
|
|
46
|
-
tile.header.batchTableJsonByteLength = batchTableJsonByteLength;
|
|
47
|
-
tile.header.batchTableBinaryByteLength = batchTableBinaryByteLength;
|
|
48
|
-
tile.header.batchLength = batchLength;
|
|
49
|
-
return byteOffset;
|
|
50
|
-
}
|
|
51
|
-
exports.parse3DTileTablesHeaderSync = parse3DTileTablesHeaderSync;
|
|
52
|
-
function parse3DTileTablesSync(tile, arrayBuffer, byteOffset, options) {
|
|
53
|
-
byteOffset = parse3DTileFeatureTable(tile, arrayBuffer, byteOffset, options);
|
|
54
|
-
byteOffset = parse3DTileBatchTable(tile, arrayBuffer, byteOffset, options);
|
|
55
|
-
return byteOffset;
|
|
56
|
-
}
|
|
57
|
-
exports.parse3DTileTablesSync = parse3DTileTablesSync;
|
|
58
|
-
function parse3DTileFeatureTable(tile, arrayBuffer, byteOffset, options) {
|
|
59
|
-
const { featureTableJsonByteLength, featureTableBinaryByteLength, batchLength } = tile.header || {};
|
|
60
|
-
tile.featureTableJson = {
|
|
61
|
-
BATCH_LENGTH: batchLength || 0
|
|
62
|
-
};
|
|
63
|
-
if (featureTableJsonByteLength && featureTableJsonByteLength > 0) {
|
|
64
|
-
const featureTableString = (0, parse_utils_1.getStringFromArrayBuffer)(arrayBuffer, byteOffset, featureTableJsonByteLength);
|
|
65
|
-
tile.featureTableJson = JSON.parse(featureTableString);
|
|
66
|
-
}
|
|
67
|
-
byteOffset += featureTableJsonByteLength || 0;
|
|
68
|
-
tile.featureTableBinary = new Uint8Array(arrayBuffer, byteOffset, featureTableBinaryByteLength);
|
|
69
|
-
byteOffset += featureTableBinaryByteLength || 0;
|
|
70
|
-
/*
|
|
71
|
-
const featureTable = parseFeatureTable(featureTableJson, featureTableBinary);
|
|
72
|
-
|
|
73
|
-
const batchLength = featureTable.getGlobalProperty('BATCH_LENGTH');
|
|
74
|
-
featureTable.featuresLength = batchLength;
|
|
75
|
-
*/
|
|
76
|
-
return byteOffset;
|
|
77
|
-
}
|
|
78
|
-
function parse3DTileBatchTable(tile, arrayBuffer, byteOffset, options) {
|
|
79
|
-
const { batchTableJsonByteLength, batchTableBinaryByteLength } = tile.header || {};
|
|
80
|
-
if (batchTableJsonByteLength && batchTableJsonByteLength > 0) {
|
|
81
|
-
const batchTableString = (0, parse_utils_1.getStringFromArrayBuffer)(arrayBuffer, byteOffset, batchTableJsonByteLength);
|
|
82
|
-
tile.batchTableJson = JSON.parse(batchTableString);
|
|
83
|
-
byteOffset += batchTableJsonByteLength;
|
|
84
|
-
if (batchTableBinaryByteLength && batchTableBinaryByteLength > 0) {
|
|
85
|
-
// Has a batch table binary
|
|
86
|
-
tile.batchTableBinary = new Uint8Array(arrayBuffer, byteOffset, batchTableBinaryByteLength);
|
|
87
|
-
// Copy the batchTableBinary section and let the underlying ArrayBuffer be freed
|
|
88
|
-
tile.batchTableBinary = new Uint8Array(tile.batchTableBinary);
|
|
89
|
-
byteOffset += batchTableBinaryByteLength;
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
return byteOffset;
|
|
93
|
-
}
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// This file is derived from the Cesium code base under Apache 2 license
|
|
3
|
-
// See LICENSE.md and https://github.com/AnalyticalGraphicsInc/cesium/blob/master/LICENSE.md
|
|
4
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
-
exports.getMagicString = exports.getStringFromTypedArray = exports.getStringFromArrayBuffer = void 0;
|
|
6
|
-
const loader_utils_1 = require("@loaders.gl/loader-utils");
|
|
7
|
-
// Decode the JSON binary array into clear text
|
|
8
|
-
function getStringFromArrayBuffer(arrayBuffer, byteOffset, byteLength) {
|
|
9
|
-
(0, loader_utils_1.assert)(arrayBuffer instanceof ArrayBuffer);
|
|
10
|
-
const textDecoder = new TextDecoder('utf8');
|
|
11
|
-
const typedArray = new Uint8Array(arrayBuffer, byteOffset, byteLength);
|
|
12
|
-
const string = textDecoder.decode(typedArray);
|
|
13
|
-
return string;
|
|
14
|
-
}
|
|
15
|
-
exports.getStringFromArrayBuffer = getStringFromArrayBuffer;
|
|
16
|
-
// Decode the JSON binary array into clear text
|
|
17
|
-
function getStringFromTypedArray(typedArray) {
|
|
18
|
-
(0, loader_utils_1.assert)(ArrayBuffer.isView(typedArray));
|
|
19
|
-
const textDecoder = new TextDecoder('utf8');
|
|
20
|
-
const string = textDecoder.decode(typedArray);
|
|
21
|
-
return string;
|
|
22
|
-
}
|
|
23
|
-
exports.getStringFromTypedArray = getStringFromTypedArray;
|
|
24
|
-
function getMagicString(arrayBuffer, byteOffset = 0) {
|
|
25
|
-
const dataView = new DataView(arrayBuffer);
|
|
26
|
-
return `\
|
|
27
|
-
${String.fromCharCode(dataView.getUint8(byteOffset + 0))}\
|
|
28
|
-
${String.fromCharCode(dataView.getUint8(byteOffset + 1))}\
|
|
29
|
-
${String.fromCharCode(dataView.getUint8(byteOffset + 2))}\
|
|
30
|
-
${String.fromCharCode(dataView.getUint8(byteOffset + 3))}`;
|
|
31
|
-
}
|
|
32
|
-
exports.getMagicString = getMagicString;
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// This file is derived from the Cesium code base under Apache 2 license
|
|
3
|
-
// See LICENSE.md and https://github.com/AnalyticalGraphicsInc/cesium/blob/master/LICENSE.md
|
|
4
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
5
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
6
|
-
};
|
|
7
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
-
exports.parseBatchedModel3DTile = void 0;
|
|
9
|
-
const math_1 = require("@loaders.gl/math"); // math.gl/geometry;
|
|
10
|
-
const tile_3d_feature_table_1 = __importDefault(require("../classes/tile-3d-feature-table"));
|
|
11
|
-
// import Tile3DBatchTable from '../classes/tile-3d-batch-table';
|
|
12
|
-
const parse_3d_tile_header_1 = require("./helpers/parse-3d-tile-header");
|
|
13
|
-
const parse_3d_tile_tables_1 = require("./helpers/parse-3d-tile-tables");
|
|
14
|
-
const parse_3d_tile_gltf_view_1 = require("./helpers/parse-3d-tile-gltf-view");
|
|
15
|
-
async function parseBatchedModel3DTile(tile, arrayBuffer, byteOffset, options, context) {
|
|
16
|
-
byteOffset = parseBatchedModel(tile, arrayBuffer, byteOffset, options, context);
|
|
17
|
-
await (0, parse_3d_tile_gltf_view_1.extractGLTF)(tile, parse_3d_tile_gltf_view_1.GLTF_FORMAT.EMBEDDED, options, context);
|
|
18
|
-
const extensions = tile?.gltf?.extensions;
|
|
19
|
-
if (extensions && extensions.CESIUM_RTC) {
|
|
20
|
-
tile.rtcCenter = extensions.CESIUM_RTC.center;
|
|
21
|
-
}
|
|
22
|
-
return byteOffset;
|
|
23
|
-
}
|
|
24
|
-
exports.parseBatchedModel3DTile = parseBatchedModel3DTile;
|
|
25
|
-
function parseBatchedModel(tile, arrayBuffer, byteOffset, options, context) {
|
|
26
|
-
byteOffset = (0, parse_3d_tile_header_1.parse3DTileHeaderSync)(tile, arrayBuffer, byteOffset);
|
|
27
|
-
byteOffset = (0, parse_3d_tile_tables_1.parse3DTileTablesHeaderSync)(tile, arrayBuffer, byteOffset);
|
|
28
|
-
byteOffset = (0, parse_3d_tile_tables_1.parse3DTileTablesSync)(tile, arrayBuffer, byteOffset, options);
|
|
29
|
-
byteOffset = (0, parse_3d_tile_gltf_view_1.parse3DTileGLTFViewSync)(tile, arrayBuffer, byteOffset, options);
|
|
30
|
-
const featureTable = new tile_3d_feature_table_1.default(tile.featureTableJson, tile.featureTableBinary);
|
|
31
|
-
tile.rtcCenter = featureTable.getGlobalProperty('RTC_CENTER', math_1.GL.FLOAT, 3);
|
|
32
|
-
return byteOffset;
|
|
33
|
-
}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// This file is derived from the Cesium code base under Apache 2 license
|
|
3
|
-
// See LICENSE.md and https://github.com/AnalyticalGraphicsInc/cesium/blob/master/LICENSE.md
|
|
4
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
-
exports.parseComposite3DTile = void 0;
|
|
6
|
-
const parse_3d_tile_header_1 = require("./helpers/parse-3d-tile-header");
|
|
7
|
-
// eslint-disable-next-line max-params
|
|
8
|
-
async function parseComposite3DTile(tile, arrayBuffer, byteOffset, options, context, parse3DTile) {
|
|
9
|
-
byteOffset = (0, parse_3d_tile_header_1.parse3DTileHeaderSync)(tile, arrayBuffer, byteOffset);
|
|
10
|
-
const view = new DataView(arrayBuffer);
|
|
11
|
-
// Extract number of tiles
|
|
12
|
-
tile.tilesLength = view.getUint32(byteOffset, true);
|
|
13
|
-
byteOffset += 4;
|
|
14
|
-
// extract each tile from the byte stream
|
|
15
|
-
tile.tiles = [];
|
|
16
|
-
while (tile.tiles.length < tile.tilesLength && (tile.byteLength || 0) - byteOffset > 12) {
|
|
17
|
-
const subtile = {};
|
|
18
|
-
tile.tiles.push(subtile);
|
|
19
|
-
byteOffset = await parse3DTile(arrayBuffer, byteOffset, options, context, subtile);
|
|
20
|
-
// TODO - do we need to add any padding in between tiles?
|
|
21
|
-
}
|
|
22
|
-
return byteOffset;
|
|
23
|
-
}
|
|
24
|
-
exports.parseComposite3DTile = parseComposite3DTile;
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// loaders.gl, MIT license
|
|
3
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.parseGltf3DTile = void 0;
|
|
5
|
-
const loader_utils_1 = require("@loaders.gl/loader-utils");
|
|
6
|
-
const gltf_1 = require("@loaders.gl/gltf");
|
|
7
|
-
async function parseGltf3DTile(tile, arrayBuffer, options, context) {
|
|
8
|
-
// Set flags
|
|
9
|
-
// glTF models need to be rotated from Y to Z up
|
|
10
|
-
// https://github.com/AnalyticalGraphicsInc/3d-tiles/tree/master/specification#y-up-to-z-up
|
|
11
|
-
tile.rotateYtoZ = true;
|
|
12
|
-
// Save gltf up axis
|
|
13
|
-
tile.gltfUpAxis = options?.['3d-tiles']?.assetGltfUpAxis
|
|
14
|
-
? options['3d-tiles'].assetGltfUpAxis
|
|
15
|
-
: 'Y';
|
|
16
|
-
if (options?.['3d-tiles']?.loadGLTF) {
|
|
17
|
-
if (!context) {
|
|
18
|
-
return;
|
|
19
|
-
}
|
|
20
|
-
const gltfWithBuffers = await (0, loader_utils_1.parseFromContext)(arrayBuffer, gltf_1.GLTFLoader, options, context);
|
|
21
|
-
tile.gltf = (0, gltf_1.postProcessGLTF)(gltfWithBuffers);
|
|
22
|
-
tile.gpuMemoryUsageInBytes = (0, gltf_1._getMemoryUsageGLTF)(tile.gltf);
|
|
23
|
-
}
|
|
24
|
-
else {
|
|
25
|
-
tile.gltfArrayBuffer = arrayBuffer;
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
exports.parseGltf3DTile = parseGltf3DTile;
|
|
@@ -1,194 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.normalizeImplicitTileData = exports.normalizeImplicitTileHeaders = exports.normalizeTileHeaders = exports.normalizeTileData = void 0;
|
|
4
|
-
const loader_utils_1 = require("@loaders.gl/loader-utils");
|
|
5
|
-
const tile_3d_subtree_loader_1 = require("../../tile-3d-subtree-loader");
|
|
6
|
-
const core_1 = require("@loaders.gl/core");
|
|
7
|
-
const tiles_1 = require("@loaders.gl/tiles");
|
|
8
|
-
const parse_3d_implicit_tiles_1 = require("./helpers/parse-3d-implicit-tiles");
|
|
9
|
-
const s2_corners_to_obb_1 = require("../utils/obb/s2-corners-to-obb");
|
|
10
|
-
function getTileType(tile, tileContentUrl = '') {
|
|
11
|
-
if (!tileContentUrl) {
|
|
12
|
-
return tiles_1.TILE_TYPE.EMPTY;
|
|
13
|
-
}
|
|
14
|
-
const contentUrl = tileContentUrl.split('?')[0]; // Discard query string
|
|
15
|
-
const fileExtension = contentUrl.split('.').pop();
|
|
16
|
-
switch (fileExtension) {
|
|
17
|
-
case 'pnts':
|
|
18
|
-
return tiles_1.TILE_TYPE.POINTCLOUD;
|
|
19
|
-
case 'i3dm':
|
|
20
|
-
case 'b3dm':
|
|
21
|
-
case 'glb':
|
|
22
|
-
case 'gltf':
|
|
23
|
-
return tiles_1.TILE_TYPE.SCENEGRAPH;
|
|
24
|
-
default:
|
|
25
|
-
return fileExtension || tiles_1.TILE_TYPE.EMPTY;
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
function getRefine(refine) {
|
|
29
|
-
switch (refine) {
|
|
30
|
-
case 'REPLACE':
|
|
31
|
-
case 'replace':
|
|
32
|
-
return tiles_1.TILE_REFINEMENT.REPLACE;
|
|
33
|
-
case 'ADD':
|
|
34
|
-
case 'add':
|
|
35
|
-
return tiles_1.TILE_REFINEMENT.ADD;
|
|
36
|
-
default:
|
|
37
|
-
return refine;
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
function resolveUri(uri = '', basePath) {
|
|
41
|
-
// url scheme per RFC3986
|
|
42
|
-
const urlSchemeRegex = /^[a-z][0-9a-z+.-]*:/i;
|
|
43
|
-
if (urlSchemeRegex.test(basePath)) {
|
|
44
|
-
const url = new URL(uri, `${basePath}/`);
|
|
45
|
-
return decodeURI(url.toString());
|
|
46
|
-
}
|
|
47
|
-
else if (uri.startsWith('/')) {
|
|
48
|
-
return uri;
|
|
49
|
-
}
|
|
50
|
-
return loader_utils_1.path.resolve(basePath, uri);
|
|
51
|
-
}
|
|
52
|
-
function normalizeTileData(tile, basePath) {
|
|
53
|
-
if (!tile) {
|
|
54
|
-
return null;
|
|
55
|
-
}
|
|
56
|
-
let tileContentUrl;
|
|
57
|
-
if (tile.content) {
|
|
58
|
-
const contentUri = tile.content.uri || tile.content?.url;
|
|
59
|
-
tileContentUrl = resolveUri(contentUri, basePath);
|
|
60
|
-
}
|
|
61
|
-
const tilePostprocessed = {
|
|
62
|
-
...tile,
|
|
63
|
-
id: tileContentUrl,
|
|
64
|
-
contentUrl: tileContentUrl,
|
|
65
|
-
lodMetricType: tiles_1.LOD_METRIC_TYPE.GEOMETRIC_ERROR,
|
|
66
|
-
lodMetricValue: tile.geometricError,
|
|
67
|
-
transformMatrix: tile.transform,
|
|
68
|
-
type: getTileType(tile, tileContentUrl),
|
|
69
|
-
refine: getRefine(tile.refine)
|
|
70
|
-
};
|
|
71
|
-
return tilePostprocessed;
|
|
72
|
-
}
|
|
73
|
-
exports.normalizeTileData = normalizeTileData;
|
|
74
|
-
// normalize tile headers
|
|
75
|
-
async function normalizeTileHeaders(tileset, basePath, options) {
|
|
76
|
-
let root = null;
|
|
77
|
-
const rootImplicitTilingExtension = getImplicitTilingExtensionData(tileset.root);
|
|
78
|
-
if (rootImplicitTilingExtension && tileset.root) {
|
|
79
|
-
root = await normalizeImplicitTileHeaders(tileset.root, tileset, basePath, rootImplicitTilingExtension, options);
|
|
80
|
-
}
|
|
81
|
-
else {
|
|
82
|
-
root = normalizeTileData(tileset.root, basePath);
|
|
83
|
-
}
|
|
84
|
-
const stack = [];
|
|
85
|
-
stack.push(root);
|
|
86
|
-
while (stack.length > 0) {
|
|
87
|
-
const tile = stack.pop() || {};
|
|
88
|
-
const children = tile.children || [];
|
|
89
|
-
const childrenPostprocessed = [];
|
|
90
|
-
for (const childHeader of children) {
|
|
91
|
-
const childImplicitTilingExtension = getImplicitTilingExtensionData(childHeader);
|
|
92
|
-
let childHeaderPostprocessed;
|
|
93
|
-
if (childImplicitTilingExtension) {
|
|
94
|
-
childHeaderPostprocessed = await normalizeImplicitTileHeaders(childHeader, tileset, basePath, childImplicitTilingExtension, options);
|
|
95
|
-
}
|
|
96
|
-
else {
|
|
97
|
-
childHeaderPostprocessed = normalizeTileData(childHeader, basePath);
|
|
98
|
-
}
|
|
99
|
-
if (childHeaderPostprocessed) {
|
|
100
|
-
childrenPostprocessed.push(childHeaderPostprocessed);
|
|
101
|
-
stack.push(childHeaderPostprocessed);
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
tile.children = childrenPostprocessed;
|
|
105
|
-
}
|
|
106
|
-
return root;
|
|
107
|
-
}
|
|
108
|
-
exports.normalizeTileHeaders = normalizeTileHeaders;
|
|
109
|
-
/**
|
|
110
|
-
* Do normalisation of implicit tile headers
|
|
111
|
-
* TODO Check if Tile3D class can be a return type here.
|
|
112
|
-
* @param tileset
|
|
113
|
-
*/
|
|
114
|
-
async function normalizeImplicitTileHeaders(tile, tileset, basePath, implicitTilingExtension, options) {
|
|
115
|
-
const { subdivisionScheme, maximumLevel, availableLevels, subtreeLevels, subtrees: { uri: subtreesUriTemplate } } = implicitTilingExtension;
|
|
116
|
-
const replacedUrlTemplate = (0, parse_3d_implicit_tiles_1.replaceContentUrlTemplate)(subtreesUriTemplate, 0, 0, 0, 0);
|
|
117
|
-
const subtreeUrl = resolveUri(replacedUrlTemplate, basePath);
|
|
118
|
-
const subtree = await (0, core_1.load)(subtreeUrl, tile_3d_subtree_loader_1.Tile3DSubtreeLoader, options);
|
|
119
|
-
const contentUrlTemplate = resolveUri(tile.content?.uri, basePath);
|
|
120
|
-
const refine = tileset?.root?.refine;
|
|
121
|
-
// @ts-ignore
|
|
122
|
-
const rootLodMetricValue = tile.geometricError;
|
|
123
|
-
// Replace tile.boundingVolume with the the bounding volume specified by the extensions['3DTILES_bounding_volume_S2']
|
|
124
|
-
const s2VolumeInfo = tile.boundingVolume.extensions?.['3DTILES_bounding_volume_S2'];
|
|
125
|
-
if (s2VolumeInfo) {
|
|
126
|
-
const box = (0, s2_corners_to_obb_1.convertS2BoundingVolumetoOBB)(s2VolumeInfo);
|
|
127
|
-
const s2VolumeBox = { box, s2VolumeInfo };
|
|
128
|
-
tile.boundingVolume = s2VolumeBox;
|
|
129
|
-
}
|
|
130
|
-
const rootBoundingVolume = tile.boundingVolume;
|
|
131
|
-
const implicitOptions = {
|
|
132
|
-
contentUrlTemplate,
|
|
133
|
-
subtreesUriTemplate,
|
|
134
|
-
subdivisionScheme,
|
|
135
|
-
subtreeLevels,
|
|
136
|
-
maximumLevel: Number.isFinite(availableLevels) ? availableLevels - 1 : maximumLevel,
|
|
137
|
-
refine,
|
|
138
|
-
basePath,
|
|
139
|
-
lodMetricType: tiles_1.LOD_METRIC_TYPE.GEOMETRIC_ERROR,
|
|
140
|
-
rootLodMetricValue,
|
|
141
|
-
rootBoundingVolume,
|
|
142
|
-
getTileType,
|
|
143
|
-
getRefine
|
|
144
|
-
};
|
|
145
|
-
return await normalizeImplicitTileData(tile, basePath, subtree, implicitOptions, options);
|
|
146
|
-
}
|
|
147
|
-
exports.normalizeImplicitTileHeaders = normalizeImplicitTileHeaders;
|
|
148
|
-
/**
|
|
149
|
-
* Do implicit data normalisation to create hierarchical tile structure
|
|
150
|
-
* @param tile
|
|
151
|
-
* @param rootSubtree
|
|
152
|
-
* @param options
|
|
153
|
-
* @returns
|
|
154
|
-
*/
|
|
155
|
-
async function normalizeImplicitTileData(tile, basePath, rootSubtree, implicitOptions, loaderOptions) {
|
|
156
|
-
if (!tile) {
|
|
157
|
-
return null;
|
|
158
|
-
}
|
|
159
|
-
const { children, contentUrl } = await (0, parse_3d_implicit_tiles_1.parseImplicitTiles)({
|
|
160
|
-
subtree: rootSubtree,
|
|
161
|
-
implicitOptions,
|
|
162
|
-
loaderOptions
|
|
163
|
-
});
|
|
164
|
-
let tileContentUrl;
|
|
165
|
-
let tileContent = null;
|
|
166
|
-
if (contentUrl) {
|
|
167
|
-
tileContentUrl = contentUrl;
|
|
168
|
-
tileContent = { uri: contentUrl.replace(`${basePath}/`, '') };
|
|
169
|
-
}
|
|
170
|
-
const tilePostprocessed = {
|
|
171
|
-
...tile,
|
|
172
|
-
id: tileContentUrl,
|
|
173
|
-
contentUrl: tileContentUrl,
|
|
174
|
-
lodMetricType: tiles_1.LOD_METRIC_TYPE.GEOMETRIC_ERROR,
|
|
175
|
-
lodMetricValue: tile.geometricError,
|
|
176
|
-
transformMatrix: tile.transform,
|
|
177
|
-
type: getTileType(tile, tileContentUrl),
|
|
178
|
-
refine: getRefine(tile.refine),
|
|
179
|
-
content: tileContent || tile.content,
|
|
180
|
-
children
|
|
181
|
-
};
|
|
182
|
-
return tilePostprocessed;
|
|
183
|
-
}
|
|
184
|
-
exports.normalizeImplicitTileData = normalizeImplicitTileData;
|
|
185
|
-
/**
|
|
186
|
-
* Implicit Tiling data can be in 3DTILES_implicit_tiling for 3DTiles v.Next or directly in implicitTiling object for 3DTiles v1.1.
|
|
187
|
-
* Spec 3DTiles v.Next - https://github.com/CesiumGS/3d-tiles/tree/main/extensions/3DTILES_implicit_tiling
|
|
188
|
-
* Spec 3DTiles v.1.1 - https://github.com/CesiumGS/3d-tiles/tree/draft-1.1/specification/ImplicitTiling
|
|
189
|
-
* @param tile
|
|
190
|
-
* @returns
|
|
191
|
-
*/
|
|
192
|
-
function getImplicitTilingExtensionData(tile) {
|
|
193
|
-
return tile?.extensions?.['3DTILES_implicit_tiling'] || tile?.implicitTiling;
|
|
194
|
-
}
|
|
@@ -1,172 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// This file is derived from the Cesium code base under Apache 2 license
|
|
3
|
-
// See LICENSE.md and https://github.com/AnalyticalGraphicsInc/cesium/blob/master/LICENSE.md
|
|
4
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
5
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
6
|
-
};
|
|
7
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
-
exports.parseInstancedModel3DTile = void 0;
|
|
9
|
-
const core_1 = require("@math.gl/core");
|
|
10
|
-
const geospatial_1 = require("@math.gl/geospatial");
|
|
11
|
-
const math_1 = require("@loaders.gl/math"); // 'math.gl/geometry';
|
|
12
|
-
const tile_3d_feature_table_1 = __importDefault(require("../classes/tile-3d-feature-table"));
|
|
13
|
-
const tile_3d_batch_table_1 = __importDefault(require("../classes/tile-3d-batch-table"));
|
|
14
|
-
const parse_3d_tile_header_1 = require("./helpers/parse-3d-tile-header");
|
|
15
|
-
const parse_3d_tile_tables_1 = require("./helpers/parse-3d-tile-tables");
|
|
16
|
-
const parse_3d_tile_gltf_view_1 = require("./helpers/parse-3d-tile-gltf-view");
|
|
17
|
-
async function parseInstancedModel3DTile(tile, arrayBuffer, byteOffset, options, context) {
|
|
18
|
-
byteOffset = parseInstancedModel(tile, arrayBuffer, byteOffset, options, context);
|
|
19
|
-
await (0, parse_3d_tile_gltf_view_1.extractGLTF)(tile, tile.gltfFormat || 0, options, context);
|
|
20
|
-
return byteOffset;
|
|
21
|
-
}
|
|
22
|
-
exports.parseInstancedModel3DTile = parseInstancedModel3DTile;
|
|
23
|
-
function parseInstancedModel(tile, arrayBuffer, byteOffset, options, context) {
|
|
24
|
-
byteOffset = (0, parse_3d_tile_header_1.parse3DTileHeaderSync)(tile, arrayBuffer, byteOffset);
|
|
25
|
-
if (tile.version !== 1) {
|
|
26
|
-
throw new Error(`Instanced 3D Model version ${tile.version} is not supported`);
|
|
27
|
-
}
|
|
28
|
-
byteOffset = (0, parse_3d_tile_tables_1.parse3DTileTablesHeaderSync)(tile, arrayBuffer, byteOffset);
|
|
29
|
-
const view = new DataView(arrayBuffer);
|
|
30
|
-
tile.gltfFormat = view.getUint32(byteOffset, true);
|
|
31
|
-
byteOffset += 4;
|
|
32
|
-
// PARSE FEATURE TABLE
|
|
33
|
-
byteOffset = (0, parse_3d_tile_tables_1.parse3DTileTablesSync)(tile, arrayBuffer, byteOffset, options);
|
|
34
|
-
byteOffset = (0, parse_3d_tile_gltf_view_1.parse3DTileGLTFViewSync)(tile, arrayBuffer, byteOffset, options);
|
|
35
|
-
// TODO - Is the feature table sometimes optional or can check be moved into table header parser?
|
|
36
|
-
if (!tile?.header?.featureTableJsonByteLength || tile.header.featureTableJsonByteLength === 0) {
|
|
37
|
-
throw new Error('i3dm parser: featureTableJsonByteLength is zero.');
|
|
38
|
-
}
|
|
39
|
-
const featureTable = new tile_3d_feature_table_1.default(tile.featureTableJson, tile.featureTableBinary);
|
|
40
|
-
const instancesLength = featureTable.getGlobalProperty('INSTANCES_LENGTH');
|
|
41
|
-
featureTable.featuresLength = instancesLength;
|
|
42
|
-
if (!Number.isFinite(instancesLength)) {
|
|
43
|
-
throw new Error('i3dm parser: INSTANCES_LENGTH must be defined');
|
|
44
|
-
}
|
|
45
|
-
tile.eastNorthUp = featureTable.getGlobalProperty('EAST_NORTH_UP');
|
|
46
|
-
tile.rtcCenter = featureTable.getGlobalProperty('RTC_CENTER', math_1.GL.FLOAT, 3);
|
|
47
|
-
const batchTable = new tile_3d_batch_table_1.default(tile.batchTableJson, tile.batchTableBinary, instancesLength);
|
|
48
|
-
extractInstancedAttributes(tile, featureTable, batchTable, instancesLength);
|
|
49
|
-
return byteOffset;
|
|
50
|
-
}
|
|
51
|
-
// eslint-disable-next-line max-statements, complexity
|
|
52
|
-
function extractInstancedAttributes(tile, featureTable, batchTable, instancesLength) {
|
|
53
|
-
const instances = new Array(instancesLength);
|
|
54
|
-
const instancePosition = new core_1.Vector3();
|
|
55
|
-
const instanceNormalRight = new core_1.Vector3();
|
|
56
|
-
const instanceNormalUp = new core_1.Vector3();
|
|
57
|
-
const instanceNormalForward = new core_1.Vector3();
|
|
58
|
-
const instanceRotation = new core_1.Matrix3();
|
|
59
|
-
const instanceQuaternion = new core_1.Quaternion();
|
|
60
|
-
const instanceScale = new core_1.Vector3();
|
|
61
|
-
const instanceTranslationRotationScale = {};
|
|
62
|
-
const instanceTransform = new core_1.Matrix4();
|
|
63
|
-
const scratch1 = [];
|
|
64
|
-
const scratch2 = [];
|
|
65
|
-
const scratch3 = [];
|
|
66
|
-
const scratch4 = [];
|
|
67
|
-
for (let i = 0; i < instancesLength; i++) {
|
|
68
|
-
let position;
|
|
69
|
-
// Get the instance position
|
|
70
|
-
if (featureTable.hasProperty('POSITION')) {
|
|
71
|
-
position = featureTable.getProperty('POSITION', math_1.GL.FLOAT, 3, i, instancePosition);
|
|
72
|
-
}
|
|
73
|
-
else if (featureTable.hasProperty('POSITION_QUANTIZED')) {
|
|
74
|
-
position = featureTable.getProperty('POSITION_QUANTIZED', math_1.GL.UNSIGNED_SHORT, 3, i, instancePosition);
|
|
75
|
-
const quantizedVolumeOffset = featureTable.getGlobalProperty('QUANTIZED_VOLUME_OFFSET', math_1.GL.FLOAT, 3);
|
|
76
|
-
if (!quantizedVolumeOffset) {
|
|
77
|
-
throw new Error('i3dm parser: QUANTIZED_VOLUME_OFFSET must be defined for quantized positions.');
|
|
78
|
-
}
|
|
79
|
-
const quantizedVolumeScale = featureTable.getGlobalProperty('QUANTIZED_VOLUME_SCALE', math_1.GL.FLOAT, 3);
|
|
80
|
-
if (!quantizedVolumeScale) {
|
|
81
|
-
throw new Error('i3dm parser: QUANTIZED_VOLUME_SCALE must be defined for quantized positions.');
|
|
82
|
-
}
|
|
83
|
-
const MAX_UNSIGNED_SHORT = 65535.0;
|
|
84
|
-
for (let j = 0; j < 3; j++) {
|
|
85
|
-
position[j] =
|
|
86
|
-
(position[j] / MAX_UNSIGNED_SHORT) * quantizedVolumeScale[j] + quantizedVolumeOffset[j];
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
if (!position) {
|
|
90
|
-
throw new Error('i3dm: POSITION or POSITION_QUANTIZED must be defined for each instance.');
|
|
91
|
-
}
|
|
92
|
-
instancePosition.copy(position);
|
|
93
|
-
// @ts-expect-error
|
|
94
|
-
instanceTranslationRotationScale.translation = instancePosition;
|
|
95
|
-
// Get the instance rotation
|
|
96
|
-
tile.normalUp = featureTable.getProperty('NORMAL_UP', math_1.GL.FLOAT, 3, i, scratch1);
|
|
97
|
-
tile.normalRight = featureTable.getProperty('NORMAL_RIGHT', math_1.GL.FLOAT, 3, i, scratch2);
|
|
98
|
-
const hasCustomOrientation = false;
|
|
99
|
-
if (tile.normalUp) {
|
|
100
|
-
if (!tile.normalRight) {
|
|
101
|
-
throw new Error('i3dm: Custom orientation requires both NORMAL_UP and NORMAL_RIGHT.');
|
|
102
|
-
}
|
|
103
|
-
// Vector3.unpack(normalUp, 0, instanceNormalUp);
|
|
104
|
-
// Vector3.unpack(normalRight, 0, instanceNormalRight);
|
|
105
|
-
tile.hasCustomOrientation = true;
|
|
106
|
-
}
|
|
107
|
-
else {
|
|
108
|
-
tile.octNormalUp = featureTable.getProperty('NORMAL_UP_OCT32P', math_1.GL.UNSIGNED_SHORT, 2, i, scratch1);
|
|
109
|
-
tile.octNormalRight = featureTable.getProperty('NORMAL_RIGHT_OCT32P', math_1.GL.UNSIGNED_SHORT, 2, i, scratch2);
|
|
110
|
-
if (tile.octNormalUp) {
|
|
111
|
-
if (!tile.octNormalRight) {
|
|
112
|
-
throw new Error('i3dm: oct-encoded orientation requires NORMAL_UP_OCT32P and NORMAL_RIGHT_OCT32P');
|
|
113
|
-
}
|
|
114
|
-
throw new Error('i3dm: oct-encoded orientation not implemented');
|
|
115
|
-
/*
|
|
116
|
-
AttributeCompression.octDecodeInRange(octNormalUp[0], octNormalUp[1], 65535, instanceNormalUp);
|
|
117
|
-
AttributeCompression.octDecodeInRange(octNormalRight[0], octNormalRight[1], 65535, instanceNormalRight);
|
|
118
|
-
hasCustomOrientation = true;
|
|
119
|
-
*/
|
|
120
|
-
}
|
|
121
|
-
else if (tile.eastNorthUp) {
|
|
122
|
-
geospatial_1.Ellipsoid.WGS84.eastNorthUpToFixedFrame(instancePosition, instanceTransform);
|
|
123
|
-
instanceTransform.getRotationMatrix3(instanceRotation);
|
|
124
|
-
}
|
|
125
|
-
else {
|
|
126
|
-
instanceRotation.identity();
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
if (hasCustomOrientation) {
|
|
130
|
-
instanceNormalForward.copy(instanceNormalRight).cross(instanceNormalUp).normalize();
|
|
131
|
-
instanceRotation.setColumn(0, instanceNormalRight);
|
|
132
|
-
instanceRotation.setColumn(1, instanceNormalUp);
|
|
133
|
-
instanceRotation.setColumn(2, instanceNormalForward);
|
|
134
|
-
}
|
|
135
|
-
instanceQuaternion.fromMatrix3(instanceRotation);
|
|
136
|
-
// @ts-expect-error
|
|
137
|
-
instanceTranslationRotationScale.rotation = instanceQuaternion;
|
|
138
|
-
// Get the instance scale
|
|
139
|
-
instanceScale.set(1.0, 1.0, 1.0);
|
|
140
|
-
const scale = featureTable.getProperty('SCALE', math_1.GL.FLOAT, 1, i, scratch3);
|
|
141
|
-
if (Number.isFinite(scale)) {
|
|
142
|
-
instanceScale.multiplyByScalar(scale);
|
|
143
|
-
}
|
|
144
|
-
const nonUniformScale = featureTable.getProperty('SCALE_NON_UNIFORM', math_1.GL.FLOAT, 3, i, scratch1);
|
|
145
|
-
if (nonUniformScale) {
|
|
146
|
-
instanceScale.scale(nonUniformScale);
|
|
147
|
-
}
|
|
148
|
-
// @ts-expect-error
|
|
149
|
-
instanceTranslationRotationScale.scale = instanceScale;
|
|
150
|
-
// Get the batchId
|
|
151
|
-
let batchId = featureTable.getProperty('BATCH_ID', math_1.GL.UNSIGNED_SHORT, 1, i, scratch4);
|
|
152
|
-
if (batchId === undefined) {
|
|
153
|
-
// If BATCH_ID semantic is undefined, batchId is just the instance number
|
|
154
|
-
batchId = i;
|
|
155
|
-
}
|
|
156
|
-
// @ts-expect-error
|
|
157
|
-
const rotationMatrix = new core_1.Matrix4().fromQuaternion(instanceTranslationRotationScale.rotation);
|
|
158
|
-
// Create the model matrix and the instance
|
|
159
|
-
instanceTransform.identity();
|
|
160
|
-
// @ts-expect-error
|
|
161
|
-
instanceTransform.translate(instanceTranslationRotationScale.translation);
|
|
162
|
-
instanceTransform.multiplyRight(rotationMatrix);
|
|
163
|
-
// @ts-expect-error
|
|
164
|
-
instanceTransform.scale(instanceTranslationRotationScale.scale);
|
|
165
|
-
const modelMatrix = instanceTransform.clone();
|
|
166
|
-
instances[i] = {
|
|
167
|
-
modelMatrix,
|
|
168
|
-
batchId
|
|
169
|
-
};
|
|
170
|
-
}
|
|
171
|
-
tile.instances = instances;
|
|
172
|
-
}
|