@loaders.gl/3d-tiles 4.2.0-alpha.4 → 4.2.0-alpha.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/3d-tiles-archive/3d-tiles-archive-archive.js +66 -41
- 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/3d-tiles-archive-parser.js +26 -16
- package/dist/3d-tiles-archive-loader.js +25 -14
- package/dist/cesium-ion-loader.js +34 -30
- package/dist/dist.dev.js +1963 -1037
- package/dist/dist.min.js +32 -0
- package/dist/index.cjs +122 -337
- package/dist/index.cjs.map +7 -0
- package/dist/index.d.ts +13 -13
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7 -1
- package/dist/lib/classes/helpers/tile-3d-accessor-utils.js +103 -87
- package/dist/lib/classes/tile-3d-batch-table-hierarchy.js +179 -155
- package/dist/lib/classes/tile-3d-batch-table.js +232 -217
- package/dist/lib/classes/tile-3d-feature-table.js +62 -59
- package/dist/lib/constants.js +19 -15
- package/dist/lib/encoders/encode-3d-tile-batched-model.js +40 -35
- package/dist/lib/encoders/encode-3d-tile-composite.js +19 -17
- package/dist/lib/encoders/encode-3d-tile-instanced-model.js +32 -31
- package/dist/lib/encoders/encode-3d-tile-point-cloud.js +31 -32
- package/dist/lib/encoders/encode-3d-tile.js +23 -19
- package/dist/lib/encoders/helpers/encode-3d-tile-header.js +23 -23
- package/dist/lib/ion/ion.js +55 -54
- package/dist/lib/parsers/helpers/normalize-3d-tile-colors.d.ts +1 -1
- package/dist/lib/parsers/helpers/normalize-3d-tile-colors.d.ts.map +1 -1
- package/dist/lib/parsers/helpers/normalize-3d-tile-colors.js +57 -51
- package/dist/lib/parsers/helpers/normalize-3d-tile-normals.d.ts +1 -1
- package/dist/lib/parsers/helpers/normalize-3d-tile-normals.d.ts.map +1 -1
- package/dist/lib/parsers/helpers/normalize-3d-tile-normals.js +21 -18
- package/dist/lib/parsers/helpers/normalize-3d-tile-positions.js +35 -20
- package/dist/lib/parsers/helpers/parse-3d-implicit-tiles.d.ts +4 -4
- package/dist/lib/parsers/helpers/parse-3d-implicit-tiles.d.ts.map +1 -1
- package/dist/lib/parsers/helpers/parse-3d-implicit-tiles.js +269 -234
- package/dist/lib/parsers/helpers/parse-3d-tile-gltf-view.d.ts +2 -2
- package/dist/lib/parsers/helpers/parse-3d-tile-gltf-view.d.ts.map +1 -1
- package/dist/lib/parsers/helpers/parse-3d-tile-gltf-view.js +83 -55
- package/dist/lib/parsers/helpers/parse-3d-tile-header.d.ts +1 -1
- package/dist/lib/parsers/helpers/parse-3d-tile-header.d.ts.map +1 -1
- package/dist/lib/parsers/helpers/parse-3d-tile-header.js +23 -14
- package/dist/lib/parsers/helpers/parse-3d-tile-subtree.d.ts +1 -1
- package/dist/lib/parsers/helpers/parse-3d-tile-subtree.d.ts.map +1 -1
- package/dist/lib/parsers/helpers/parse-3d-tile-subtree.js +82 -54
- package/dist/lib/parsers/helpers/parse-3d-tile-tables.d.ts +2 -2
- package/dist/lib/parsers/helpers/parse-3d-tile-tables.d.ts.map +1 -1
- package/dist/lib/parsers/helpers/parse-3d-tile-tables.js +79 -68
- package/dist/lib/parsers/helpers/parse-utils.js +19 -14
- package/dist/lib/parsers/parse-3d-tile-batched-model.d.ts +2 -2
- package/dist/lib/parsers/parse-3d-tile-batched-model.d.ts.map +1 -1
- package/dist/lib/parsers/parse-3d-tile-batched-model.js +21 -17
- package/dist/lib/parsers/parse-3d-tile-composite.d.ts +2 -2
- package/dist/lib/parsers/parse-3d-tile-composite.d.ts.map +1 -1
- package/dist/lib/parsers/parse-3d-tile-composite.js +18 -14
- package/dist/lib/parsers/parse-3d-tile-gltf.d.ts +2 -2
- package/dist/lib/parsers/parse-3d-tile-gltf.d.ts.map +1 -1
- package/dist/lib/parsers/parse-3d-tile-gltf.js +22 -14
- package/dist/lib/parsers/parse-3d-tile-header.d.ts +2 -2
- package/dist/lib/parsers/parse-3d-tile-header.d.ts.map +1 -1
- package/dist/lib/parsers/parse-3d-tile-header.js +168 -159
- package/dist/lib/parsers/parse-3d-tile-instanced-model.d.ts +2 -2
- package/dist/lib/parsers/parse-3d-tile-instanced-model.d.ts.map +1 -1
- package/dist/lib/parsers/parse-3d-tile-instanced-model.js +153 -123
- package/dist/lib/parsers/parse-3d-tile-point-cloud.d.ts +2 -2
- package/dist/lib/parsers/parse-3d-tile-point-cloud.d.ts.map +1 -1
- package/dist/lib/parsers/parse-3d-tile-point-cloud.js +380 -174
- package/dist/lib/parsers/parse-3d-tile.d.ts +2 -2
- package/dist/lib/parsers/parse-3d-tile.d.ts.map +1 -1
- package/dist/lib/parsers/parse-3d-tile.js +24 -24
- package/dist/lib/utils/obb/s2-corners-to-obb.js +29 -16
- package/dist/lib/utils/s2/converters/s2-to-boundary.d.ts +1 -1
- package/dist/lib/utils/s2/converters/s2-to-boundary.d.ts.map +1 -1
- package/dist/lib/utils/s2/converters/s2-to-boundary.js +55 -35
- package/dist/lib/utils/s2/converters/s2-to-obb-points.js +31 -20
- package/dist/lib/utils/s2/converters/s2-to-region.d.ts +1 -1
- package/dist/lib/utils/s2/converters/s2-to-region.d.ts.map +1 -1
- package/dist/lib/utils/s2/converters/s2-to-region.js +51 -35
- package/dist/lib/utils/s2/index.d.ts +7 -7
- package/dist/lib/utils/s2/index.d.ts.map +1 -1
- package/dist/lib/utils/s2/index.js +3 -1
- package/dist/lib/utils/s2/s2-geometry-functions.js +19 -5
- package/dist/lib/utils/s2/s2-token-functions.js +51 -22
- package/dist/lib/utils/s2/s2geometry/s2-cell-utils.d.ts +1 -1
- package/dist/lib/utils/s2/s2geometry/s2-cell-utils.d.ts.map +1 -1
- package/dist/lib/utils/s2/s2geometry/s2-cell-utils.js +23 -9
- package/dist/lib/utils/s2/s2geometry/s2-geometry.js +218 -157
- package/dist/lib/utils/version.js +3 -1
- package/dist/tile-3d-subtree-loader.d.ts +1 -1
- package/dist/tile-3d-subtree-loader.d.ts.map +1 -1
- package/dist/tile-3d-subtree-loader.js +15 -10
- package/dist/tile-3d-writer.js +19 -14
- package/dist/tiles-3d-loader.js +65 -55
- package/dist/types.js +3 -1
- package/package.json +11 -10
- package/dist/3d-tiles-archive/3d-tiles-archive-archive.js.map +0 -1
- package/dist/3d-tiles-archive/3d-tiles-archive-parser.js.map +0 -1
- package/dist/3d-tiles-archive-loader.js.map +0 -1
- package/dist/cesium-ion-loader.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/lib/classes/helpers/tile-3d-accessor-utils.js.map +0 -1
- package/dist/lib/classes/tile-3d-batch-table-hierarchy.js.map +0 -1
- package/dist/lib/classes/tile-3d-batch-table.js.map +0 -1
- package/dist/lib/classes/tile-3d-feature-table.js.map +0 -1
- package/dist/lib/constants.js.map +0 -1
- package/dist/lib/encoders/encode-3d-tile-batched-model.js.map +0 -1
- package/dist/lib/encoders/encode-3d-tile-composite.js.map +0 -1
- package/dist/lib/encoders/encode-3d-tile-instanced-model.js.map +0 -1
- package/dist/lib/encoders/encode-3d-tile-point-cloud.js.map +0 -1
- package/dist/lib/encoders/encode-3d-tile.js.map +0 -1
- package/dist/lib/encoders/helpers/encode-3d-tile-header.js.map +0 -1
- package/dist/lib/ion/ion.js.map +0 -1
- package/dist/lib/parsers/helpers/normalize-3d-tile-colors.js.map +0 -1
- package/dist/lib/parsers/helpers/normalize-3d-tile-normals.js.map +0 -1
- package/dist/lib/parsers/helpers/normalize-3d-tile-positions.js.map +0 -1
- package/dist/lib/parsers/helpers/parse-3d-implicit-tiles.js.map +0 -1
- package/dist/lib/parsers/helpers/parse-3d-tile-gltf-view.js.map +0 -1
- package/dist/lib/parsers/helpers/parse-3d-tile-header.js.map +0 -1
- package/dist/lib/parsers/helpers/parse-3d-tile-subtree.js.map +0 -1
- package/dist/lib/parsers/helpers/parse-3d-tile-tables.js.map +0 -1
- package/dist/lib/parsers/helpers/parse-utils.js.map +0 -1
- package/dist/lib/parsers/parse-3d-tile-batched-model.js.map +0 -1
- package/dist/lib/parsers/parse-3d-tile-composite.js.map +0 -1
- package/dist/lib/parsers/parse-3d-tile-gltf.js.map +0 -1
- package/dist/lib/parsers/parse-3d-tile-header.js.map +0 -1
- package/dist/lib/parsers/parse-3d-tile-instanced-model.js.map +0 -1
- package/dist/lib/parsers/parse-3d-tile-point-cloud.js.map +0 -1
- package/dist/lib/parsers/parse-3d-tile.js.map +0 -1
- package/dist/lib/utils/obb/s2-corners-to-obb.js.map +0 -1
- package/dist/lib/utils/s2/converters/s2-to-boundary.js.map +0 -1
- package/dist/lib/utils/s2/converters/s2-to-obb-points.js.map +0 -1
- package/dist/lib/utils/s2/converters/s2-to-region.js.map +0 -1
- package/dist/lib/utils/s2/index.js.map +0 -1
- package/dist/lib/utils/s2/s2-geometry-functions.js.map +0 -1
- package/dist/lib/utils/s2/s2-token-functions.js.map +0 -1
- package/dist/lib/utils/s2/s2geometry/s2-cell-utils.js.map +0 -1
- package/dist/lib/utils/s2/s2geometry/s2-geometry.js.map +0 -1
- package/dist/lib/utils/version.js.map +0 -1
- package/dist/tile-3d-subtree-loader.js.map +0 -1
- package/dist/tile-3d-writer.js.map +0 -1
- package/dist/tiles-3d-loader.js.map +0 -1
- package/dist/types.js.map +0 -1
|
@@ -1,138 +1,168 @@
|
|
|
1
|
+
// loaders.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT AND Apache-2.0
|
|
3
|
+
// Copyright vis.gl contributors
|
|
4
|
+
// This file is derived from the Cesium code base under Apache 2 license
|
|
5
|
+
// See LICENSE.md and https://github.com/AnalyticalGraphicsInc/cesium/blob/master/LICENSE.md
|
|
1
6
|
import { Vector3, Matrix3, Matrix4, Quaternion } from '@math.gl/core';
|
|
2
7
|
import { Ellipsoid } from '@math.gl/geospatial';
|
|
3
|
-
import { GL } from '@loaders.gl/math';
|
|
8
|
+
import { GL } from '@loaders.gl/math'; // 'math.gl/geometry';
|
|
4
9
|
import Tile3DFeatureTable from "../classes/tile-3d-feature-table.js";
|
|
5
10
|
import Tile3DBatchTable from "../classes/tile-3d-batch-table.js";
|
|
6
11
|
import { parse3DTileHeaderSync } from "./helpers/parse-3d-tile-header.js";
|
|
7
12
|
import { parse3DTileTablesHeaderSync, parse3DTileTablesSync } from "./helpers/parse-3d-tile-tables.js";
|
|
8
13
|
import { parse3DTileGLTFViewSync, extractGLTF } from "./helpers/parse-3d-tile-gltf-view.js";
|
|
9
14
|
export async function parseInstancedModel3DTile(tile, arrayBuffer, byteOffset, options, context) {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
15
|
+
byteOffset = parseInstancedModel(tile, arrayBuffer, byteOffset, options, context);
|
|
16
|
+
await extractGLTF(tile, tile.gltfFormat || 0, options, context);
|
|
17
|
+
return byteOffset;
|
|
13
18
|
}
|
|
14
19
|
function parseInstancedModel(tile, arrayBuffer, byteOffset, options, context) {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
throw new Error(`Instanced 3D Model version ${tile.version} is not supported`);
|
|
19
|
-
}
|
|
20
|
-
byteOffset = parse3DTileTablesHeaderSync(tile, arrayBuffer, byteOffset);
|
|
21
|
-
const view = new DataView(arrayBuffer);
|
|
22
|
-
tile.gltfFormat = view.getUint32(byteOffset, true);
|
|
23
|
-
byteOffset += 4;
|
|
24
|
-
byteOffset = parse3DTileTablesSync(tile, arrayBuffer, byteOffset, options);
|
|
25
|
-
byteOffset = parse3DTileGLTFViewSync(tile, arrayBuffer, byteOffset, options);
|
|
26
|
-
if (!(tile !== null && tile !== void 0 && (_tile$header = tile.header) !== null && _tile$header !== void 0 && _tile$header.featureTableJsonByteLength) || tile.header.featureTableJsonByteLength === 0) {
|
|
27
|
-
throw new Error('i3dm parser: featureTableJsonByteLength is zero.');
|
|
28
|
-
}
|
|
29
|
-
const featureTable = new Tile3DFeatureTable(tile.featureTableJson, tile.featureTableBinary);
|
|
30
|
-
const instancesLength = featureTable.getGlobalProperty('INSTANCES_LENGTH');
|
|
31
|
-
featureTable.featuresLength = instancesLength;
|
|
32
|
-
if (!Number.isFinite(instancesLength)) {
|
|
33
|
-
throw new Error('i3dm parser: INSTANCES_LENGTH must be defined');
|
|
34
|
-
}
|
|
35
|
-
tile.eastNorthUp = featureTable.getGlobalProperty('EAST_NORTH_UP');
|
|
36
|
-
tile.rtcCenter = featureTable.getGlobalProperty('RTC_CENTER', GL.FLOAT, 3);
|
|
37
|
-
const batchTable = new Tile3DBatchTable(tile.batchTableJson, tile.batchTableBinary, instancesLength);
|
|
38
|
-
extractInstancedAttributes(tile, featureTable, batchTable, instancesLength);
|
|
39
|
-
return byteOffset;
|
|
40
|
-
}
|
|
41
|
-
function extractInstancedAttributes(tile, featureTable, batchTable, instancesLength) {
|
|
42
|
-
const instances = new Array(instancesLength);
|
|
43
|
-
const instancePosition = new Vector3();
|
|
44
|
-
const instanceNormalRight = new Vector3();
|
|
45
|
-
const instanceNormalUp = new Vector3();
|
|
46
|
-
const instanceNormalForward = new Vector3();
|
|
47
|
-
const instanceRotation = new Matrix3();
|
|
48
|
-
const instanceQuaternion = new Quaternion();
|
|
49
|
-
const instanceScale = new Vector3();
|
|
50
|
-
const instanceTranslationRotationScale = {};
|
|
51
|
-
const instanceTransform = new Matrix4();
|
|
52
|
-
const scratch1 = [];
|
|
53
|
-
const scratch2 = [];
|
|
54
|
-
const scratch3 = [];
|
|
55
|
-
const scratch4 = [];
|
|
56
|
-
for (let i = 0; i < instancesLength; i++) {
|
|
57
|
-
let position;
|
|
58
|
-
if (featureTable.hasProperty('POSITION')) {
|
|
59
|
-
position = featureTable.getProperty('POSITION', GL.FLOAT, 3, i, instancePosition);
|
|
60
|
-
} else if (featureTable.hasProperty('POSITION_QUANTIZED')) {
|
|
61
|
-
position = featureTable.getProperty('POSITION_QUANTIZED', GL.UNSIGNED_SHORT, 3, i, instancePosition);
|
|
62
|
-
const quantizedVolumeOffset = featureTable.getGlobalProperty('QUANTIZED_VOLUME_OFFSET', GL.FLOAT, 3);
|
|
63
|
-
if (!quantizedVolumeOffset) {
|
|
64
|
-
throw new Error('i3dm parser: QUANTIZED_VOLUME_OFFSET must be defined for quantized positions.');
|
|
65
|
-
}
|
|
66
|
-
const quantizedVolumeScale = featureTable.getGlobalProperty('QUANTIZED_VOLUME_SCALE', GL.FLOAT, 3);
|
|
67
|
-
if (!quantizedVolumeScale) {
|
|
68
|
-
throw new Error('i3dm parser: QUANTIZED_VOLUME_SCALE must be defined for quantized positions.');
|
|
69
|
-
}
|
|
70
|
-
const MAX_UNSIGNED_SHORT = 65535.0;
|
|
71
|
-
for (let j = 0; j < 3; j++) {
|
|
72
|
-
position[j] = position[j] / MAX_UNSIGNED_SHORT * quantizedVolumeScale[j] + quantizedVolumeOffset[j];
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
if (!position) {
|
|
76
|
-
throw new Error('i3dm: POSITION or POSITION_QUANTIZED must be defined for each instance.');
|
|
77
|
-
}
|
|
78
|
-
instancePosition.copy(position);
|
|
79
|
-
instanceTranslationRotationScale.translation = instancePosition;
|
|
80
|
-
tile.normalUp = featureTable.getProperty('NORMAL_UP', GL.FLOAT, 3, i, scratch1);
|
|
81
|
-
tile.normalRight = featureTable.getProperty('NORMAL_RIGHT', GL.FLOAT, 3, i, scratch2);
|
|
82
|
-
const hasCustomOrientation = false;
|
|
83
|
-
if (tile.normalUp) {
|
|
84
|
-
if (!tile.normalRight) {
|
|
85
|
-
throw new Error('i3dm: Custom orientation requires both NORMAL_UP and NORMAL_RIGHT.');
|
|
86
|
-
}
|
|
87
|
-
tile.hasCustomOrientation = true;
|
|
88
|
-
} else {
|
|
89
|
-
tile.octNormalUp = featureTable.getProperty('NORMAL_UP_OCT32P', GL.UNSIGNED_SHORT, 2, i, scratch1);
|
|
90
|
-
tile.octNormalRight = featureTable.getProperty('NORMAL_RIGHT_OCT32P', GL.UNSIGNED_SHORT, 2, i, scratch2);
|
|
91
|
-
if (tile.octNormalUp) {
|
|
92
|
-
if (!tile.octNormalRight) {
|
|
93
|
-
throw new Error('i3dm: oct-encoded orientation requires NORMAL_UP_OCT32P and NORMAL_RIGHT_OCT32P');
|
|
94
|
-
}
|
|
95
|
-
throw new Error('i3dm: oct-encoded orientation not implemented');
|
|
96
|
-
} else if (tile.eastNorthUp) {
|
|
97
|
-
Ellipsoid.WGS84.eastNorthUpToFixedFrame(instancePosition, instanceTransform);
|
|
98
|
-
instanceTransform.getRotationMatrix3(instanceRotation);
|
|
99
|
-
} else {
|
|
100
|
-
instanceRotation.identity();
|
|
101
|
-
}
|
|
20
|
+
byteOffset = parse3DTileHeaderSync(tile, arrayBuffer, byteOffset);
|
|
21
|
+
if (tile.version !== 1) {
|
|
22
|
+
throw new Error(`Instanced 3D Model version ${tile.version} is not supported`);
|
|
102
23
|
}
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
24
|
+
byteOffset = parse3DTileTablesHeaderSync(tile, arrayBuffer, byteOffset);
|
|
25
|
+
const view = new DataView(arrayBuffer);
|
|
26
|
+
tile.gltfFormat = view.getUint32(byteOffset, true);
|
|
27
|
+
byteOffset += 4;
|
|
28
|
+
// PARSE FEATURE TABLE
|
|
29
|
+
byteOffset = parse3DTileTablesSync(tile, arrayBuffer, byteOffset, options);
|
|
30
|
+
byteOffset = parse3DTileGLTFViewSync(tile, arrayBuffer, byteOffset, options);
|
|
31
|
+
// TODO - Is the feature table sometimes optional or can check be moved into table header parser?
|
|
32
|
+
if (!tile?.header?.featureTableJsonByteLength || tile.header.featureTableJsonByteLength === 0) {
|
|
33
|
+
throw new Error('i3dm parser: featureTableJsonByteLength is zero.');
|
|
108
34
|
}
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
instanceScale.multiplyByScalar(scale);
|
|
35
|
+
const featureTable = new Tile3DFeatureTable(tile.featureTableJson, tile.featureTableBinary);
|
|
36
|
+
const instancesLength = featureTable.getGlobalProperty('INSTANCES_LENGTH');
|
|
37
|
+
featureTable.featuresLength = instancesLength;
|
|
38
|
+
if (!Number.isFinite(instancesLength)) {
|
|
39
|
+
throw new Error('i3dm parser: INSTANCES_LENGTH must be defined');
|
|
115
40
|
}
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
41
|
+
tile.eastNorthUp = featureTable.getGlobalProperty('EAST_NORTH_UP');
|
|
42
|
+
tile.rtcCenter = featureTable.getGlobalProperty('RTC_CENTER', GL.FLOAT, 3);
|
|
43
|
+
const batchTable = new Tile3DBatchTable(tile.batchTableJson, tile.batchTableBinary, instancesLength);
|
|
44
|
+
extractInstancedAttributes(tile, featureTable, batchTable, instancesLength);
|
|
45
|
+
return byteOffset;
|
|
46
|
+
}
|
|
47
|
+
// eslint-disable-next-line max-statements, complexity
|
|
48
|
+
function extractInstancedAttributes(tile, featureTable, batchTable, instancesLength) {
|
|
49
|
+
const instances = new Array(instancesLength);
|
|
50
|
+
const instancePosition = new Vector3();
|
|
51
|
+
const instanceNormalRight = new Vector3();
|
|
52
|
+
const instanceNormalUp = new Vector3();
|
|
53
|
+
const instanceNormalForward = new Vector3();
|
|
54
|
+
const instanceRotation = new Matrix3();
|
|
55
|
+
const instanceQuaternion = new Quaternion();
|
|
56
|
+
const instanceScale = new Vector3();
|
|
57
|
+
const instanceTranslationRotationScale = {};
|
|
58
|
+
const instanceTransform = new Matrix4();
|
|
59
|
+
const scratch1 = [];
|
|
60
|
+
const scratch2 = [];
|
|
61
|
+
const scratch3 = [];
|
|
62
|
+
const scratch4 = [];
|
|
63
|
+
for (let i = 0; i < instancesLength; i++) {
|
|
64
|
+
let position;
|
|
65
|
+
// Get the instance position
|
|
66
|
+
if (featureTable.hasProperty('POSITION')) {
|
|
67
|
+
position = featureTable.getProperty('POSITION', GL.FLOAT, 3, i, instancePosition);
|
|
68
|
+
}
|
|
69
|
+
else if (featureTable.hasProperty('POSITION_QUANTIZED')) {
|
|
70
|
+
position = featureTable.getProperty('POSITION_QUANTIZED', GL.UNSIGNED_SHORT, 3, i, instancePosition);
|
|
71
|
+
const quantizedVolumeOffset = featureTable.getGlobalProperty('QUANTIZED_VOLUME_OFFSET', GL.FLOAT, 3);
|
|
72
|
+
if (!quantizedVolumeOffset) {
|
|
73
|
+
throw new Error('i3dm parser: QUANTIZED_VOLUME_OFFSET must be defined for quantized positions.');
|
|
74
|
+
}
|
|
75
|
+
const quantizedVolumeScale = featureTable.getGlobalProperty('QUANTIZED_VOLUME_SCALE', GL.FLOAT, 3);
|
|
76
|
+
if (!quantizedVolumeScale) {
|
|
77
|
+
throw new Error('i3dm parser: QUANTIZED_VOLUME_SCALE must be defined for quantized positions.');
|
|
78
|
+
}
|
|
79
|
+
const MAX_UNSIGNED_SHORT = 65535.0;
|
|
80
|
+
for (let j = 0; j < 3; j++) {
|
|
81
|
+
position[j] =
|
|
82
|
+
(position[j] / MAX_UNSIGNED_SHORT) * quantizedVolumeScale[j] + quantizedVolumeOffset[j];
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
if (!position) {
|
|
86
|
+
throw new Error('i3dm: POSITION or POSITION_QUANTIZED must be defined for each instance.');
|
|
87
|
+
}
|
|
88
|
+
instancePosition.copy(position);
|
|
89
|
+
// @ts-expect-error
|
|
90
|
+
instanceTranslationRotationScale.translation = instancePosition;
|
|
91
|
+
// Get the instance rotation
|
|
92
|
+
tile.normalUp = featureTable.getProperty('NORMAL_UP', GL.FLOAT, 3, i, scratch1);
|
|
93
|
+
tile.normalRight = featureTable.getProperty('NORMAL_RIGHT', GL.FLOAT, 3, i, scratch2);
|
|
94
|
+
const hasCustomOrientation = false;
|
|
95
|
+
if (tile.normalUp) {
|
|
96
|
+
if (!tile.normalRight) {
|
|
97
|
+
throw new Error('i3dm: Custom orientation requires both NORMAL_UP and NORMAL_RIGHT.');
|
|
98
|
+
}
|
|
99
|
+
// Vector3.unpack(normalUp, 0, instanceNormalUp);
|
|
100
|
+
// Vector3.unpack(normalRight, 0, instanceNormalRight);
|
|
101
|
+
tile.hasCustomOrientation = true;
|
|
102
|
+
}
|
|
103
|
+
else {
|
|
104
|
+
tile.octNormalUp = featureTable.getProperty('NORMAL_UP_OCT32P', GL.UNSIGNED_SHORT, 2, i, scratch1);
|
|
105
|
+
tile.octNormalRight = featureTable.getProperty('NORMAL_RIGHT_OCT32P', GL.UNSIGNED_SHORT, 2, i, scratch2);
|
|
106
|
+
if (tile.octNormalUp) {
|
|
107
|
+
if (!tile.octNormalRight) {
|
|
108
|
+
throw new Error('i3dm: oct-encoded orientation requires NORMAL_UP_OCT32P and NORMAL_RIGHT_OCT32P');
|
|
109
|
+
}
|
|
110
|
+
throw new Error('i3dm: oct-encoded orientation not implemented');
|
|
111
|
+
/*
|
|
112
|
+
AttributeCompression.octDecodeInRange(octNormalUp[0], octNormalUp[1], 65535, instanceNormalUp);
|
|
113
|
+
AttributeCompression.octDecodeInRange(octNormalRight[0], octNormalRight[1], 65535, instanceNormalRight);
|
|
114
|
+
hasCustomOrientation = true;
|
|
115
|
+
*/
|
|
116
|
+
}
|
|
117
|
+
else if (tile.eastNorthUp) {
|
|
118
|
+
Ellipsoid.WGS84.eastNorthUpToFixedFrame(instancePosition, instanceTransform);
|
|
119
|
+
instanceTransform.getRotationMatrix3(instanceRotation);
|
|
120
|
+
}
|
|
121
|
+
else {
|
|
122
|
+
instanceRotation.identity();
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
if (hasCustomOrientation) {
|
|
126
|
+
instanceNormalForward.copy(instanceNormalRight).cross(instanceNormalUp).normalize();
|
|
127
|
+
instanceRotation.setColumn(0, instanceNormalRight);
|
|
128
|
+
instanceRotation.setColumn(1, instanceNormalUp);
|
|
129
|
+
instanceRotation.setColumn(2, instanceNormalForward);
|
|
130
|
+
}
|
|
131
|
+
instanceQuaternion.fromMatrix3(instanceRotation);
|
|
132
|
+
// @ts-expect-error
|
|
133
|
+
instanceTranslationRotationScale.rotation = instanceQuaternion;
|
|
134
|
+
// Get the instance scale
|
|
135
|
+
instanceScale.set(1.0, 1.0, 1.0);
|
|
136
|
+
const scale = featureTable.getProperty('SCALE', GL.FLOAT, 1, i, scratch3);
|
|
137
|
+
if (Number.isFinite(scale)) {
|
|
138
|
+
instanceScale.multiplyByScalar(scale);
|
|
139
|
+
}
|
|
140
|
+
const nonUniformScale = featureTable.getProperty('SCALE_NON_UNIFORM', GL.FLOAT, 3, i, scratch1);
|
|
141
|
+
if (nonUniformScale) {
|
|
142
|
+
instanceScale.scale(nonUniformScale);
|
|
143
|
+
}
|
|
144
|
+
// @ts-expect-error
|
|
145
|
+
instanceTranslationRotationScale.scale = instanceScale;
|
|
146
|
+
// Get the batchId
|
|
147
|
+
let batchId = featureTable.getProperty('BATCH_ID', GL.UNSIGNED_SHORT, 1, i, scratch4);
|
|
148
|
+
if (batchId === undefined) {
|
|
149
|
+
// If BATCH_ID semantic is undefined, batchId is just the instance number
|
|
150
|
+
batchId = i;
|
|
151
|
+
}
|
|
152
|
+
// @ts-expect-error
|
|
153
|
+
const rotationMatrix = new Matrix4().fromQuaternion(instanceTranslationRotationScale.rotation);
|
|
154
|
+
// Create the model matrix and the instance
|
|
155
|
+
instanceTransform.identity();
|
|
156
|
+
// @ts-expect-error
|
|
157
|
+
instanceTransform.translate(instanceTranslationRotationScale.translation);
|
|
158
|
+
instanceTransform.multiplyRight(rotationMatrix);
|
|
159
|
+
// @ts-expect-error
|
|
160
|
+
instanceTransform.scale(instanceTranslationRotationScale.scale);
|
|
161
|
+
const modelMatrix = instanceTransform.clone();
|
|
162
|
+
instances[i] = {
|
|
163
|
+
modelMatrix,
|
|
164
|
+
batchId
|
|
165
|
+
};
|
|
124
166
|
}
|
|
125
|
-
|
|
126
|
-
instanceTransform.identity();
|
|
127
|
-
instanceTransform.translate(instanceTranslationRotationScale.translation);
|
|
128
|
-
instanceTransform.multiplyRight(rotationMatrix);
|
|
129
|
-
instanceTransform.scale(instanceTranslationRotationScale.scale);
|
|
130
|
-
const modelMatrix = instanceTransform.clone();
|
|
131
|
-
instances[i] = {
|
|
132
|
-
modelMatrix,
|
|
133
|
-
batchId
|
|
134
|
-
};
|
|
135
|
-
}
|
|
136
|
-
tile.instances = instances;
|
|
167
|
+
tile.instances = instances;
|
|
137
168
|
}
|
|
138
|
-
//# sourceMappingURL=parse-3d-tile-instanced-model.js.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { LoaderContext } from '@loaders.gl/loader-utils';
|
|
2
|
-
import { Tiles3DLoaderOptions } from
|
|
3
|
-
import { Tiles3DTileContent } from
|
|
2
|
+
import { Tiles3DLoaderOptions } from "../../tiles-3d-loader.js";
|
|
3
|
+
import { Tiles3DTileContent } from "../../types.js";
|
|
4
4
|
export declare function parsePointCloud3DTile(tile: Tiles3DTileContent, arrayBuffer: ArrayBuffer, byteOffset: number, options?: Tiles3DLoaderOptions, context?: LoaderContext): Promise<number>;
|
|
5
5
|
export declare function loadDraco(tile: Tiles3DTileContent, dracoData: any, options?: Tiles3DLoaderOptions, context?: LoaderContext): Promise<void>;
|
|
6
6
|
//# sourceMappingURL=parse-3d-tile-point-cloud.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parse-3d-tile-point-cloud.d.ts","sourceRoot":"","sources":["../../../src/lib/parsers/parse-3d-tile-point-cloud.ts"],"names":[],"mappings":"AAQA,OAAO,EAAC,aAAa,EAAmB,MAAM,0BAA0B,CAAC;AAWzE,OAAO,EAAC,oBAAoB,EAAC,
|
|
1
|
+
{"version":3,"file":"parse-3d-tile-point-cloud.d.ts","sourceRoot":"","sources":["../../../src/lib/parsers/parse-3d-tile-point-cloud.ts"],"names":[],"mappings":"AAQA,OAAO,EAAC,aAAa,EAAmB,MAAM,0BAA0B,CAAC;AAWzE,OAAO,EAAC,oBAAoB,EAAC,iCAA8B;AAC3D,OAAO,EAAC,kBAAkB,EAAC,uBAAoB;AAE/C,wBAAsB,qBAAqB,CACzC,IAAI,EAAE,kBAAkB,EACxB,WAAW,EAAE,WAAW,EACxB,UAAU,EAAE,MAAM,EAClB,OAAO,CAAC,EAAE,oBAAoB,EAC9B,OAAO,CAAC,EAAE,aAAa,GACtB,OAAO,CAAC,MAAM,CAAC,CAgBjB;AAuND,wBAAsB,SAAS,CAC7B,IAAI,EAAE,kBAAkB,EACxB,SAAS,KAAA,EACT,OAAO,CAAC,EAAE,oBAAoB,EAC9B,OAAO,CAAC,EAAE,aAAa,GACtB,OAAO,CAAC,IAAI,CAAC,CA+Df"}
|