@loaders.gl/3d-tiles 3.4.11 → 3.4.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. package/dist/es5/lib/utils/version.js +1 -1
  2. package/dist/esm/lib/utils/version.js +1 -1
  3. package/package.json +7 -7
  4. package/dist/bundle.js +0 -5
  5. package/dist/cesium-ion-loader.js +0 -41
  6. package/dist/index.js +0 -26
  7. package/dist/lib/classes/helpers/tile-3d-accessor-utils.js +0 -113
  8. package/dist/lib/classes/tile-3d-batch-table-hierarchy.js +0 -197
  9. package/dist/lib/classes/tile-3d-batch-table.js +0 -245
  10. package/dist/lib/classes/tile-3d-feature-table.js +0 -72
  11. package/dist/lib/constants.js +0 -26
  12. package/dist/lib/encoders/encode-3d-tile-batched-model.js +0 -46
  13. package/dist/lib/encoders/encode-3d-tile-composite.js +0 -24
  14. package/dist/lib/encoders/encode-3d-tile-instanced-model.js +0 -38
  15. package/dist/lib/encoders/encode-3d-tile-point-cloud.js +0 -39
  16. package/dist/lib/encoders/encode-3d-tile.js +0 -33
  17. package/dist/lib/encoders/helpers/encode-3d-tile-header.js +0 -30
  18. package/dist/lib/ion/ion.js +0 -68
  19. package/dist/lib/parsers/helpers/normalize-3d-tile-colors.js +0 -65
  20. package/dist/lib/parsers/helpers/normalize-3d-tile-normals.js +0 -30
  21. package/dist/lib/parsers/helpers/normalize-3d-tile-positions.js +0 -42
  22. package/dist/lib/parsers/helpers/parse-3d-implicit-tiles.js +0 -266
  23. package/dist/lib/parsers/helpers/parse-3d-tile-gltf-view.js +0 -89
  24. package/dist/lib/parsers/helpers/parse-3d-tile-header.js +0 -28
  25. package/dist/lib/parsers/helpers/parse-3d-tile-subtree.js +0 -104
  26. package/dist/lib/parsers/helpers/parse-3d-tile-tables.js +0 -93
  27. package/dist/lib/parsers/helpers/parse-utils.js +0 -32
  28. package/dist/lib/parsers/parse-3d-tile-batched-model.js +0 -33
  29. package/dist/lib/parsers/parse-3d-tile-composite.js +0 -26
  30. package/dist/lib/parsers/parse-3d-tile-gltf.js +0 -19
  31. package/dist/lib/parsers/parse-3d-tile-header.js +0 -177
  32. package/dist/lib/parsers/parse-3d-tile-instanced-model.js +0 -186
  33. package/dist/lib/parsers/parse-3d-tile-point-cloud.js +0 -411
  34. package/dist/lib/parsers/parse-3d-tile.js +0 -37
  35. package/dist/lib/utils/obb/s2-corners-to-obb.js +0 -37
  36. package/dist/lib/utils/s2/converters/s2-to-boundary.js +0 -61
  37. package/dist/lib/utils/s2/converters/s2-to-obb-points.js +0 -36
  38. package/dist/lib/utils/s2/converters/s2-to-region.js +0 -59
  39. package/dist/lib/utils/s2/index.js +0 -23
  40. package/dist/lib/utils/s2/s2-geometry-functions.js +0 -29
  41. package/dist/lib/utils/s2/s2-token-functions.js +0 -68
  42. package/dist/lib/utils/s2/s2geometry/s2-cell-utils.js +0 -32
  43. package/dist/lib/utils/s2/s2geometry/s2-geometry.js +0 -260
  44. package/dist/lib/utils/version.js +0 -7
  45. package/dist/tile-3d-subtree-loader.js +0 -23
  46. package/dist/tile-3d-writer.js +0 -27
  47. package/dist/tiles-3d-loader.js +0 -74
  48. package/dist/types.js +0 -2
@@ -1,19 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.parseGltf3DTile = void 0;
4
- const gltf_1 = require("@loaders.gl/gltf");
5
- async function parseGltf3DTile(tile, arrayBuffer, options, context) {
6
- // Set flags
7
- // glTF models need to be rotated from Y to Z up
8
- // https://github.com/AnalyticalGraphicsInc/3d-tiles/tree/master/specification#y-up-to-z-up
9
- tile.rotateYtoZ = true;
10
- // Save gltf up axis
11
- tile.gltfUpAxis =
12
- options['3d-tiles'] && options['3d-tiles'].assetGltfUpAxis
13
- ? options['3d-tiles'].assetGltfUpAxis
14
- : 'Y';
15
- const { parse } = context;
16
- tile.gltf = await parse(arrayBuffer, gltf_1.GLTFLoader, options, context);
17
- tile.gpuMemoryUsageInBytes = (0, gltf_1._getMemoryUsageGLTF)(tile.gltf);
18
- }
19
- exports.parseGltf3DTile = parseGltf3DTile;
@@ -1,177 +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 tile_3d_subtree_loader_1 = require("../../tile-3d-subtree-loader");
5
- const core_1 = require("@loaders.gl/core");
6
- const tiles_1 = require("@loaders.gl/tiles");
7
- const parse_3d_implicit_tiles_1 = require("./helpers/parse-3d-implicit-tiles");
8
- const s2_corners_to_obb_1 = require("../utils/obb/s2-corners-to-obb");
9
- function getTileType(tile) {
10
- if (!tile.contentUrl) {
11
- return tiles_1.TILE_TYPE.EMPTY;
12
- }
13
- const contentUrl = tile.contentUrl.split('?')[0]; // Discard query string
14
- const fileExtension = contentUrl.split('.').pop();
15
- switch (fileExtension) {
16
- case 'pnts':
17
- return tiles_1.TILE_TYPE.POINTCLOUD;
18
- case 'i3dm':
19
- case 'b3dm':
20
- case 'glb':
21
- case 'gltf':
22
- return tiles_1.TILE_TYPE.SCENEGRAPH;
23
- default:
24
- return fileExtension;
25
- }
26
- }
27
- function getRefine(refine) {
28
- switch (refine) {
29
- case 'REPLACE':
30
- case 'replace':
31
- return tiles_1.TILE_REFINEMENT.REPLACE;
32
- case 'ADD':
33
- case 'add':
34
- return tiles_1.TILE_REFINEMENT.ADD;
35
- default:
36
- return refine;
37
- }
38
- }
39
- function resolveUri(uri, basePath) {
40
- // url scheme per RFC3986
41
- const urlSchemeRegex = /^[a-z][0-9a-z+.-]*:/i;
42
- if (urlSchemeRegex.test(basePath)) {
43
- const url = new URL(uri, `${basePath}/`);
44
- return decodeURI(url.toString());
45
- }
46
- else if (uri.startsWith('/')) {
47
- return uri;
48
- }
49
- return `${basePath}/${uri}`;
50
- }
51
- function normalizeTileData(tile, options) {
52
- if (!tile) {
53
- return null;
54
- }
55
- if (tile.content) {
56
- const contentUri = tile.content.uri || tile.content.url;
57
- tile.contentUrl = resolveUri(contentUri, options.basePath);
58
- }
59
- tile.id = tile.contentUrl;
60
- tile.lodMetricType = tiles_1.LOD_METRIC_TYPE.GEOMETRIC_ERROR;
61
- tile.lodMetricValue = tile.geometricError;
62
- tile.transformMatrix = tile.transform;
63
- tile.type = getTileType(tile);
64
- tile.refine = getRefine(tile.refine);
65
- return tile;
66
- }
67
- exports.normalizeTileData = normalizeTileData;
68
- // normalize tile headers
69
- async function normalizeTileHeaders(tileset, options) {
70
- const basePath = tileset.basePath;
71
- let root;
72
- const rootImplicitTilingExtension = getImplicitTilingExtensionData(tileset?.root);
73
- if (rootImplicitTilingExtension && tileset.root) {
74
- root = await normalizeImplicitTileHeaders(tileset.root, tileset, rootImplicitTilingExtension, options);
75
- }
76
- else {
77
- root = normalizeTileData(tileset.root, tileset);
78
- }
79
- const stack = [];
80
- stack.push(root);
81
- while (stack.length > 0) {
82
- const tile = stack.pop() || {};
83
- const children = tile.children || [];
84
- for (let childHeader of children) {
85
- const childImplicitTilingExtension = getImplicitTilingExtensionData(childHeader);
86
- if (childImplicitTilingExtension) {
87
- childHeader = await normalizeImplicitTileHeaders(childHeader, tileset, childImplicitTilingExtension, options);
88
- }
89
- else {
90
- normalizeTileData(childHeader, { basePath });
91
- }
92
- stack.push(childHeader);
93
- }
94
- }
95
- return root;
96
- }
97
- exports.normalizeTileHeaders = normalizeTileHeaders;
98
- /**
99
- * Do normalisation of implicit tile headers
100
- * TODO Check if Tile3D class can be a return type here.
101
- * @param tileset
102
- */
103
- async function normalizeImplicitTileHeaders(tile, tileset, implicitTilingExtension, options) {
104
- const basePath = tileset.basePath;
105
- const { subdivisionScheme, maximumLevel, subtreeLevels, subtrees: { uri: subtreesUriTemplate } } = implicitTilingExtension;
106
- const replacedUrlTemplate = (0, parse_3d_implicit_tiles_1.replaceContentUrlTemplate)(subtreesUriTemplate, 0, 0, 0, 0);
107
- const subtreeUrl = resolveUri(replacedUrlTemplate, basePath);
108
- const subtree = await (0, core_1.load)(subtreeUrl, tile_3d_subtree_loader_1.Tile3DSubtreeLoader, options);
109
- const contentUrlTemplate = resolveUri(tile.content.uri, basePath);
110
- const refine = tileset?.root?.refine;
111
- // @ts-ignore
112
- const rootLodMetricValue = tile.geometricError;
113
- // Replace tile.boundingVolume with the the bounding volume specified by the extensions['3DTILES_bounding_volume_S2']
114
- const s2VolumeInfo = tile.boundingVolume.extensions?.['3DTILES_bounding_volume_S2'];
115
- if (s2VolumeInfo) {
116
- const box = (0, s2_corners_to_obb_1.convertS2BoundingVolumetoOBB)(s2VolumeInfo);
117
- const s2VolumeBox = { box, s2VolumeInfo };
118
- tile.boundingVolume = s2VolumeBox;
119
- }
120
- const rootBoundingVolume = tile.boundingVolume;
121
- const implicitOptions = {
122
- contentUrlTemplate,
123
- subtreesUriTemplate,
124
- subdivisionScheme,
125
- subtreeLevels,
126
- maximumLevel,
127
- refine,
128
- basePath,
129
- lodMetricType: tiles_1.LOD_METRIC_TYPE.GEOMETRIC_ERROR,
130
- rootLodMetricValue,
131
- rootBoundingVolume,
132
- getTileType,
133
- getRefine
134
- };
135
- return await normalizeImplicitTileData(tile, subtree, implicitOptions);
136
- }
137
- exports.normalizeImplicitTileHeaders = normalizeImplicitTileHeaders;
138
- /**
139
- * Do implicit data normalisation to create hierarchical tile structure
140
- * @param tile
141
- * @param rootSubtree
142
- * @param options
143
- * @returns
144
- */
145
- async function normalizeImplicitTileData(tile, rootSubtree, options) {
146
- if (!tile) {
147
- return null;
148
- }
149
- tile.lodMetricType = tiles_1.LOD_METRIC_TYPE.GEOMETRIC_ERROR;
150
- tile.lodMetricValue = tile.geometricError;
151
- tile.transformMatrix = tile.transform;
152
- const { children, contentUrl } = await (0, parse_3d_implicit_tiles_1.parseImplicitTiles)({
153
- subtree: rootSubtree,
154
- options,
155
- s2VolumeBox: tile
156
- });
157
- if (contentUrl) {
158
- tile.contentUrl = contentUrl;
159
- tile.content = { uri: contentUrl.replace(`${options.basePath}/`, '') };
160
- }
161
- tile.refine = getRefine(tile.refine);
162
- tile.type = getTileType(tile);
163
- tile.children = children;
164
- tile.id = tile.contentUrl;
165
- return tile;
166
- }
167
- exports.normalizeImplicitTileData = normalizeImplicitTileData;
168
- /**
169
- * Implicit Tiling data can be in 3DTILES_implicit_tiling for 3DTiles v.Next or directly in implicitTiling object for 3DTiles v1.1.
170
- * Spec 3DTiles v.Next - https://github.com/CesiumGS/3d-tiles/tree/main/extensions/3DTILES_implicit_tiling
171
- * Spec 3DTiles v.1.1 - https://github.com/CesiumGS/3d-tiles/tree/draft-1.1/specification/ImplicitTiling
172
- * @param tile
173
- * @returns
174
- */
175
- function getImplicitTilingExtensionData(tile) {
176
- return tile?.extensions?.['3DTILES_implicit_tiling'] || tile?.implicitTiling;
177
- }
@@ -1,186 +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, 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.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
- // Create model instance collection
54
- const collectionOptions = {
55
- instances: new Array(instancesLength),
56
- batchTable: tile._batchTable,
57
- cull: false,
58
- url: undefined,
59
- // requestType: RequestType.TILES3D,
60
- gltf: undefined,
61
- basePath: undefined,
62
- incrementallyLoadTextures: false,
63
- // TODO - tileset is not available at this stage, tile is parsed independently
64
- // upAxis: (tileset && tileset._gltfUpAxis) || [0, 1, 0],
65
- forwardAxis: [1, 0, 0]
66
- };
67
- const instances = collectionOptions.instances;
68
- const instancePosition = new core_1.Vector3();
69
- const instanceNormalRight = new core_1.Vector3();
70
- const instanceNormalUp = new core_1.Vector3();
71
- const instanceNormalForward = new core_1.Vector3();
72
- const instanceRotation = new core_1.Matrix3();
73
- const instanceQuaternion = new core_1.Quaternion();
74
- const instanceScale = new core_1.Vector3();
75
- const instanceTranslationRotationScale = {};
76
- const instanceTransform = new core_1.Matrix4();
77
- const scratch1 = [];
78
- const scratch2 = [];
79
- const scratchVector1 = new core_1.Vector3();
80
- const scratchVector2 = new core_1.Vector3();
81
- for (let i = 0; i < instancesLength; i++) {
82
- let position;
83
- // Get the instance position
84
- if (featureTable.hasProperty('POSITION')) {
85
- position = featureTable.getProperty('POSITION', math_1.GL.FLOAT, 3, i, instancePosition);
86
- }
87
- else if (featureTable.hasProperty('POSITION_QUANTIZED')) {
88
- position = featureTable.getProperty('POSITION_QUANTIZED', math_1.GL.UNSIGNED_SHORT, 3, i, instancePosition);
89
- const quantizedVolumeOffset = featureTable.getGlobalProperty('QUANTIZED_VOLUME_OFFSET', math_1.GL.FLOAT, 3, scratchVector1);
90
- if (!quantizedVolumeOffset) {
91
- throw new Error('i3dm parser: QUANTIZED_VOLUME_OFFSET must be defined for quantized positions.');
92
- }
93
- const quantizedVolumeScale = featureTable.getGlobalProperty('QUANTIZED_VOLUME_SCALE', math_1.GL.FLOAT, 3, scratchVector2);
94
- if (!quantizedVolumeScale) {
95
- throw new Error('i3dm parser: QUANTIZED_VOLUME_SCALE must be defined for quantized positions.');
96
- }
97
- const MAX_UNSIGNED_SHORT = 65535.0;
98
- for (let j = 0; j < 3; j++) {
99
- position[j] =
100
- (position[j] / MAX_UNSIGNED_SHORT) * quantizedVolumeScale[j] + quantizedVolumeOffset[j];
101
- }
102
- }
103
- if (!position) {
104
- throw new Error('i3dm: POSITION or POSITION_QUANTIZED must be defined for each instance.');
105
- }
106
- instancePosition.copy(position);
107
- // @ts-expect-error
108
- instanceTranslationRotationScale.translation = instancePosition;
109
- // Get the instance rotation
110
- tile.normalUp = featureTable.getProperty('NORMAL_UP', math_1.GL.FLOAT, 3, i, scratch1);
111
- tile.normalRight = featureTable.getProperty('NORMAL_RIGHT', math_1.GL.FLOAT, 3, i, scratch2);
112
- const hasCustomOrientation = false;
113
- if (tile.normalUp) {
114
- if (!tile.normalRight) {
115
- throw new Error('i3dm: Custom orientation requires both NORMAL_UP and NORMAL_RIGHT.');
116
- }
117
- // Vector3.unpack(normalUp, 0, instanceNormalUp);
118
- // Vector3.unpack(normalRight, 0, instanceNormalRight);
119
- tile.hasCustomOrientation = true;
120
- }
121
- else {
122
- tile.octNormalUp = featureTable.getProperty('NORMAL_UP_OCT32P', math_1.GL.UNSIGNED_SHORT, 2, scratch1);
123
- tile.octNormalRight = featureTable.getProperty('NORMAL_RIGHT_OCT32P', math_1.GL.UNSIGNED_SHORT, 2, scratch2);
124
- if (tile.octNormalUp) {
125
- if (!tile.octNormalRight) {
126
- throw new Error('i3dm: oct-encoded orientation requires NORMAL_UP_OCT32P and NORMAL_RIGHT_OCT32P');
127
- }
128
- throw new Error('i3dm: oct-encoded orientation not implemented');
129
- /*
130
- AttributeCompression.octDecodeInRange(octNormalUp[0], octNormalUp[1], 65535, instanceNormalUp);
131
- AttributeCompression.octDecodeInRange(octNormalRight[0], octNormalRight[1], 65535, instanceNormalRight);
132
- hasCustomOrientation = true;
133
- */
134
- }
135
- else if (tile.eastNorthUp) {
136
- geospatial_1.Ellipsoid.WGS84.eastNorthUpToFixedFrame(instancePosition, instanceTransform);
137
- instanceTransform.getRotationMatrix3(instanceRotation);
138
- }
139
- else {
140
- instanceRotation.identity();
141
- }
142
- }
143
- if (hasCustomOrientation) {
144
- instanceNormalForward.copy(instanceNormalRight).cross(instanceNormalUp).normalize();
145
- instanceRotation.setColumn(0, instanceNormalRight);
146
- instanceRotation.setColumn(1, instanceNormalUp);
147
- instanceRotation.setColumn(2, instanceNormalForward);
148
- }
149
- instanceQuaternion.fromMatrix3(instanceRotation);
150
- // @ts-expect-error
151
- instanceTranslationRotationScale.rotation = instanceQuaternion;
152
- // Get the instance scale
153
- instanceScale.set(1.0, 1.0, 1.0);
154
- const scale = featureTable.getProperty('SCALE', math_1.GL.FLOAT, 1, i);
155
- if (Number.isFinite(scale)) {
156
- instanceScale.multiplyByScalar(scale);
157
- }
158
- const nonUniformScale = featureTable.getProperty('SCALE_NON_UNIFORM', math_1.GL.FLOAT, 3, i, scratch1);
159
- if (nonUniformScale) {
160
- instanceScale.scale(nonUniformScale);
161
- }
162
- // @ts-expect-error
163
- instanceTranslationRotationScale.scale = instanceScale;
164
- // Get the batchId
165
- let batchId = featureTable.getProperty('BATCH_ID', math_1.GL.UNSIGNED_SHORT, 1, i);
166
- if (batchId === undefined) {
167
- // If BATCH_ID semantic is undefined, batchId is just the instance number
168
- batchId = i;
169
- }
170
- // @ts-expect-error
171
- const rotationMatrix = new core_1.Matrix4().fromQuaternion(instanceTranslationRotationScale.rotation);
172
- // Create the model matrix and the instance
173
- instanceTransform.identity();
174
- // @ts-expect-error
175
- instanceTransform.translate(instanceTranslationRotationScale.translation);
176
- instanceTransform.multiplyRight(rotationMatrix);
177
- // @ts-expect-error
178
- instanceTransform.scale(instanceTranslationRotationScale.scale);
179
- const modelMatrix = instanceTransform.clone();
180
- instances[i] = {
181
- modelMatrix,
182
- batchId
183
- };
184
- }
185
- tile.instances = instances;
186
- }