@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,266 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.replaceContentUrlTemplate = exports.parseImplicitTiles = void 0;
4
- const tile_3d_subtree_loader_1 = require("../../../tile-3d-subtree-loader");
5
- const core_1 = require("@loaders.gl/core");
6
- const index_1 = require("../../utils/s2/index");
7
- const s2_corners_to_obb_1 = require("../../utils/obb/s2-corners-to-obb");
8
- const QUADTREE_DEVISION_COUNT = 4;
9
- const OCTREE_DEVISION_COUNT = 8;
10
- const SUBDIVISION_COUNT_MAP = {
11
- QUADTREE: QUADTREE_DEVISION_COUNT,
12
- OCTREE: OCTREE_DEVISION_COUNT
13
- };
14
- function getChildS2VolumeBox(s2VolumeBox, index, subdivisionScheme) {
15
- if (s2VolumeBox?.box) {
16
- // Check if the BoundingVolume is of type "box"
17
- const cellId = (0, index_1.getS2CellIdFromToken)(s2VolumeBox.s2VolumeInfo.token);
18
- const childCellId = (0, index_1.getS2ChildCellId)(cellId, index);
19
- const childToken = (0, index_1.getS2TokenFromCellId)(childCellId);
20
- // Clone object. Note, s2VolumeInfo is a plain object that doesn't contain any nested object.
21
- // So, we can use the Spread Operator to make a shallow copy of the object.
22
- const s2ChildVolumeInfo = { ...s2VolumeBox.s2VolumeInfo };
23
- s2ChildVolumeInfo.token = childToken; // replace the token with the child's one
24
- // In case of QUADTREE the sizeZ should NOT be changed!
25
- // https://portal.ogc.org/files/102132
26
- // A quadtree divides space only on the x and y dimensions.
27
- // It divides each tile into 4 smaller tiles where the x and y dimensions are halved.
28
- // The quadtree z minimum and maximum remain unchanged.
29
- switch (subdivisionScheme) {
30
- case 'OCTREE':
31
- const s2VolumeInfo = s2VolumeBox.s2VolumeInfo;
32
- const delta = s2VolumeInfo.maximumHeight - s2VolumeInfo.minimumHeight;
33
- const sizeZ = delta / 2.0; // It's a next level (a child)
34
- const midZ = s2VolumeInfo.minimumHeight + delta / 2.0;
35
- s2VolumeInfo.minimumHeight = midZ - sizeZ;
36
- s2VolumeInfo.maximumHeight = midZ + sizeZ;
37
- break;
38
- default:
39
- break;
40
- }
41
- const box = (0, s2_corners_to_obb_1.convertS2BoundingVolumetoOBB)(s2ChildVolumeInfo);
42
- const childS2VolumeBox = {
43
- box,
44
- s2VolumeInfo: s2ChildVolumeInfo
45
- };
46
- return childS2VolumeBox;
47
- }
48
- return undefined;
49
- }
50
- /**
51
- * Recursively parse implicit tiles tree
52
- * Spec - https://github.com/CesiumGS/3d-tiles/tree/main/extensions/3DTILES_implicit_tiling
53
- * TODO Check out do we able to use Tile3D class as return type here.
54
- * @param subtree
55
- * @param lodMetricValue
56
- * @param options
57
- * @param parentData
58
- * @param childIndex
59
- * @param level
60
- * @param globalData
61
- */
62
- // eslint-disable-next-line max-statements
63
- async function parseImplicitTiles(params) {
64
- const { options, parentData = {
65
- mortonIndex: 0,
66
- x: 0,
67
- y: 0,
68
- z: 0
69
- }, childIndex = 0, globalData = {
70
- level: 0,
71
- mortonIndex: 0,
72
- x: 0,
73
- y: 0,
74
- z: 0
75
- }, s2VolumeBox } = params;
76
- let { subtree, level = 0 } = params;
77
- const { subdivisionScheme, subtreeLevels, maximumLevel, contentUrlTemplate, subtreesUriTemplate, basePath } = options;
78
- const tile = { children: [], lodMetricValue: 0, contentUrl: '' };
79
- const childrenPerTile = SUBDIVISION_COUNT_MAP[subdivisionScheme];
80
- const childX = childIndex & 0b01;
81
- const childY = (childIndex >> 1) & 0b01;
82
- const childZ = (childIndex >> 2) & 0b01;
83
- const levelOffset = (childrenPerTile ** level - 1) / (childrenPerTile - 1);
84
- let childTileMortonIndex = concatBits(parentData.mortonIndex, childIndex);
85
- let tileAvailabilityIndex = levelOffset + childTileMortonIndex;
86
- // Local tile coordinates
87
- let childTileX = concatBits(parentData.x, childX);
88
- let childTileY = concatBits(parentData.y, childY);
89
- let childTileZ = concatBits(parentData.z, childZ);
90
- let isChildSubtreeAvailable = false;
91
- if (level + 1 > subtreeLevels) {
92
- isChildSubtreeAvailable = getAvailabilityResult(subtree.childSubtreeAvailability, childTileMortonIndex);
93
- }
94
- const x = concatBits(globalData.x, childTileX);
95
- const y = concatBits(globalData.y, childTileY);
96
- const z = concatBits(globalData.z, childTileZ);
97
- const lev = level + globalData.level;
98
- if (isChildSubtreeAvailable) {
99
- const subtreePath = `${basePath}/${subtreesUriTemplate}`;
100
- const childSubtreeUrl = replaceContentUrlTemplate(subtreePath, lev, x, y, z);
101
- const childSubtree = await (0, core_1.load)(childSubtreeUrl, tile_3d_subtree_loader_1.Tile3DSubtreeLoader);
102
- subtree = childSubtree;
103
- globalData.mortonIndex = childTileMortonIndex;
104
- globalData.x = childTileX;
105
- globalData.y = childTileY;
106
- globalData.z = childTileZ;
107
- globalData.level = level;
108
- childTileMortonIndex = 0;
109
- tileAvailabilityIndex = 0;
110
- childTileX = 0;
111
- childTileY = 0;
112
- childTileZ = 0;
113
- level = 0;
114
- }
115
- const isTileAvailable = getAvailabilityResult(subtree.tileAvailability, tileAvailabilityIndex);
116
- if (!isTileAvailable || level > maximumLevel) {
117
- return tile;
118
- }
119
- const isContentAvailable = getAvailabilityResult(subtree.contentAvailability, tileAvailabilityIndex);
120
- if (isContentAvailable) {
121
- tile.contentUrl = replaceContentUrlTemplate(contentUrlTemplate, lev, x, y, z);
122
- }
123
- const childTileLevel = level + 1;
124
- const pData = { mortonIndex: childTileMortonIndex, x: childTileX, y: childTileY, z: childTileZ };
125
- for (let index = 0; index < childrenPerTile; index++) {
126
- const childS2VolumeBox = getChildS2VolumeBox(s2VolumeBox, index, subdivisionScheme);
127
- // Recursive calling...
128
- const childTileParsed = await parseImplicitTiles({
129
- subtree,
130
- options,
131
- parentData: pData,
132
- childIndex: index,
133
- level: childTileLevel,
134
- globalData,
135
- s2VolumeBox: childS2VolumeBox
136
- });
137
- if (childTileParsed.contentUrl || childTileParsed.children.length) {
138
- const globalLevel = lev + 1;
139
- const childCoordinates = { childTileX, childTileY, childTileZ };
140
- const formattedTile = formatTileData(childTileParsed, globalLevel, childCoordinates, options, s2VolumeBox);
141
- // @ts-ignore
142
- tile.children.push(formattedTile);
143
- }
144
- }
145
- return tile;
146
- }
147
- exports.parseImplicitTiles = parseImplicitTiles;
148
- function getAvailabilityResult(availabilityData, index) {
149
- if ('constant' in availabilityData) {
150
- return Boolean(availabilityData.constant);
151
- }
152
- if (availabilityData.explicitBitstream) {
153
- return getBooleanValueFromBitstream(index, availabilityData.explicitBitstream);
154
- }
155
- return false;
156
- }
157
- /**
158
- * Do formatting of implicit tile data.
159
- * TODO Check out do we able to use Tile3D class as type here.
160
- * @param tile
161
- * @param lodMetricValue
162
- * @param options
163
- * @returns
164
- */
165
- function formatTileData(tile, level, childCoordinates, options, s2VolumeBox) {
166
- const { basePath, refine, getRefine, lodMetricType, getTileType, rootLodMetricValue, rootBoundingVolume } = options;
167
- const uri = tile.contentUrl && tile.contentUrl.replace(`${basePath}/`, '');
168
- const lodMetricValue = rootLodMetricValue / 2 ** level;
169
- const boundingVolume = s2VolumeBox?.box
170
- ? { box: s2VolumeBox.box }
171
- : rootBoundingVolume;
172
- const boundingVolumeForChildTile = calculateBoundingVolumeForChildTile(level, boundingVolume, childCoordinates);
173
- return {
174
- children: tile.children,
175
- contentUrl: tile.contentUrl,
176
- content: { uri },
177
- id: tile.contentUrl,
178
- refine: getRefine(refine),
179
- type: getTileType(tile),
180
- lodMetricType,
181
- lodMetricValue,
182
- geometricError: lodMetricValue,
183
- transform: tile.transform,
184
- boundingVolume: boundingVolumeForChildTile
185
- };
186
- }
187
- /**
188
- * Calculate child bounding volume.
189
- * Spec - https://github.com/CesiumGS/3d-tiles/tree/main/extensions/3DTILES_implicit_tiling#subdivision-rules
190
- * @param level
191
- * @param rootBoundingVolume
192
- * @param childCoordinates
193
- */
194
- function calculateBoundingVolumeForChildTile(level, rootBoundingVolume, childCoordinates) {
195
- if (rootBoundingVolume.region) {
196
- const { childTileX, childTileY, childTileZ } = childCoordinates;
197
- const [west, south, east, north, minimumHeight, maximumHeight] = rootBoundingVolume.region;
198
- const boundingVolumesCount = 2 ** level;
199
- const sizeX = (east - west) / boundingVolumesCount;
200
- const sizeY = (north - south) / boundingVolumesCount;
201
- // TODO : Why is the subdivisionScheme not being checked here?
202
- // In case of QUADTREE the sizeZ should NOT be changed!
203
- // https://portal.ogc.org/files/102132
204
- // A quadtree divides space only on the x and y dimensions. It divides each tile into 4 smaller tiles where the x and y dimensions are halved. The quadtree z minimum and maximum remain unchanged.
205
- const sizeZ = (maximumHeight - minimumHeight) / boundingVolumesCount;
206
- const [childWest, childEast] = [west + sizeX * childTileX, west + sizeX * (childTileX + 1)];
207
- const [childSouth, childNorth] = [south + sizeY * childTileY, south + sizeY * (childTileY + 1)];
208
- const [childMinimumHeight, childMaximumHeight] = [
209
- minimumHeight + sizeZ * childTileZ,
210
- minimumHeight + sizeZ * (childTileZ + 1)
211
- ];
212
- return {
213
- region: [childWest, childSouth, childEast, childNorth, childMinimumHeight, childMaximumHeight]
214
- };
215
- }
216
- if (rootBoundingVolume.box) {
217
- return rootBoundingVolume;
218
- }
219
- throw new Error(`Unsupported bounding volume type ${rootBoundingVolume}`);
220
- }
221
- /**
222
- * Do binary concatenation
223
- * @param first
224
- * @param second
225
- */
226
- function concatBits(first, second) {
227
- return parseInt(first.toString(2) + second.toString(2), 2);
228
- }
229
- /**
230
- * Replace implicit tile content url with real coordinates.
231
- * @param templateUrl
232
- * @param level
233
- * @param x
234
- * @param y
235
- * @param z
236
- */
237
- function replaceContentUrlTemplate(templateUrl, level, x, y, z) {
238
- const mapUrl = generateMapUrl({ level, x, y, z });
239
- return templateUrl.replace(/{level}|{x}|{y}|{z}/gi, (matched) => mapUrl[matched]);
240
- }
241
- exports.replaceContentUrlTemplate = replaceContentUrlTemplate;
242
- /**
243
- * Get Map object for content url generation
244
- * @param items
245
- */
246
- function generateMapUrl(items) {
247
- const mapUrl = {};
248
- for (const key in items) {
249
- mapUrl[`{${key}}`] = items[key];
250
- }
251
- return mapUrl;
252
- }
253
- /**
254
- * Get boolean value from bistream by index
255
- * A boolean value is encoded as a single bit, either 0 (false) or 1 (true).
256
- * Multiple boolean values are packed tightly in the same buffer.
257
- * These buffers of tightly-packed bits are sometimes referred to as bitstreams.
258
- * Spec - https://github.com/CesiumGS/3d-tiles/tree/implicit-revisions/specification/Metadata#booleans
259
- * @param availabilitiIndex
260
- */
261
- function getBooleanValueFromBitstream(availabilityIndex, availabilityBuffer) {
262
- const byteIndex = Math.floor(availabilityIndex / 8);
263
- const bitIndex = availabilityIndex % 8;
264
- const bitValue = (availabilityBuffer[byteIndex] >> bitIndex) & 1;
265
- return bitValue === 1;
266
- }
@@ -1,89 +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.extractGLTF = exports.parse3DTileGLTFViewSync = exports.GLTF_FORMAT = void 0;
6
- // TODO - should we automatically parse the embedded glTF or leave it to the app?
7
- // - I.e. some apps might work directly on a GLB, in that case no need for us to decode...
8
- // - And if we decode, do we still keep the GLB in case it is needed?
9
- // - Do we add an option to control this?
10
- // - Also, should we have hard dependency on gltf module or use injection or auto-discovery for gltf parser?
11
- const gltf_1 = require("@loaders.gl/gltf");
12
- const loader_utils_1 = require("@loaders.gl/loader-utils");
13
- exports.GLTF_FORMAT = {
14
- URI: 0,
15
- EMBEDDED: 1
16
- };
17
- function parse3DTileGLTFViewSync(tile, arrayBuffer, byteOffset, options) {
18
- // Set flags
19
- // glTF models need to be rotated from Y to Z up
20
- // https://github.com/AnalyticalGraphicsInc/3d-tiles/tree/master/specification#y-up-to-z-up
21
- tile.rotateYtoZ = true;
22
- // Assume glTF consumes rest of tile
23
- const gltfByteLength = tile.byteOffset + tile.byteLength - byteOffset;
24
- if (gltfByteLength === 0) {
25
- throw new Error('glTF byte length must be greater than 0.');
26
- }
27
- // Save gltf up axis
28
- tile.gltfUpAxis =
29
- options['3d-tiles'] && options['3d-tiles'].assetGltfUpAxis
30
- ? options['3d-tiles'].assetGltfUpAxis
31
- : 'Y';
32
- // TODO - We can avoid copy if already 4-byte aligned...
33
- // However the rest of the code may not be able to accept byteOffsets, so copy anyway
34
- tile.gltfArrayBuffer = (0, loader_utils_1.sliceArrayBuffer)(arrayBuffer, byteOffset, gltfByteLength);
35
- tile.gltfByteOffset = 0;
36
- tile.gltfByteLength = gltfByteLength;
37
- if (byteOffset % 4 === 0) {
38
- // tile.gltfArrayBuffer = arrayBuffer;
39
- // tile.gltfByteOffset = byteOffset;
40
- // tile.gltfByteLength = gltfByteLength;
41
- }
42
- else {
43
- // Create a copy of the glb so that it is 4-byte aligned
44
- // eslint-disable-next-line
45
- console.warn(`${tile.type}: embedded glb is not aligned to a 4-byte boundary.`);
46
- }
47
- // Entire tile is consumed
48
- return tile.byteOffset + tile.byteLength;
49
- }
50
- exports.parse3DTileGLTFViewSync = parse3DTileGLTFViewSync;
51
- async function extractGLTF(tile, gltfFormat, options, context) {
52
- const tile3DOptions = options['3d-tiles'] || {};
53
- extractGLTFBufferOrURL(tile, gltfFormat, options);
54
- if (tile3DOptions.loadGLTF) {
55
- const { parse, fetch } = context;
56
- if (tile.gltfUrl) {
57
- tile.gltfArrayBuffer = await fetch(tile.gltfUrl, options);
58
- tile.gltfByteOffset = 0;
59
- }
60
- if (tile.gltfArrayBuffer) {
61
- // TODO - Should handle byteOffset... However, not used now...
62
- tile.gltf = await parse(tile.gltfArrayBuffer, gltf_1.GLTFLoader, options, context);
63
- tile.gpuMemoryUsageInBytes = (0, gltf_1._getMemoryUsageGLTF)(tile.gltf);
64
- delete tile.gltfArrayBuffer;
65
- delete tile.gltfByteOffset;
66
- delete tile.gltfByteLength;
67
- }
68
- }
69
- }
70
- exports.extractGLTF = extractGLTF;
71
- function extractGLTFBufferOrURL(tile, gltfFormat, options) {
72
- switch (gltfFormat) {
73
- case exports.GLTF_FORMAT.URI:
74
- // We need to remove padding from the end of the model URL in case this tile was part of a composite tile.
75
- // This removes all white space and null characters from the end of the string.
76
- const gltfUrlBytes = new Uint8Array(tile.gltfArrayBuffer, tile.gltfByteOffset);
77
- const textDecoder = new TextDecoder();
78
- const gltfUrl = textDecoder.decode(gltfUrlBytes);
79
- tile.gltfUrl = gltfUrl.replace(/[\s\0]+$/, '');
80
- delete tile.gltfArrayBuffer;
81
- delete tile.gltfByteOffset;
82
- delete tile.gltfByteLength;
83
- break;
84
- case exports.GLTF_FORMAT.EMBEDDED:
85
- break;
86
- default:
87
- throw new Error('b3dm: Illegal glTF format field');
88
- }
89
- }
@@ -1,28 +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.parse3DTileHeaderSync = void 0;
6
- const SIZEOF_UINT32 = 4;
7
- /* PARSE FIXED HEADER:
8
- Populates
9
- magic, // identifies type of tile
10
- type, // String version of magic
11
- version,
12
- byteLength
13
- */
14
- function parse3DTileHeaderSync(tile, arrayBuffer, byteOffset = 0) {
15
- const view = new DataView(arrayBuffer);
16
- tile.magic = view.getUint32(byteOffset, true);
17
- byteOffset += SIZEOF_UINT32;
18
- tile.version = view.getUint32(byteOffset, true);
19
- byteOffset += SIZEOF_UINT32;
20
- tile.byteLength = view.getUint32(byteOffset, true);
21
- byteOffset += SIZEOF_UINT32;
22
- // TODO - move version check into each tile parser?
23
- if (tile.version !== 1) {
24
- throw new Error(`3D Tile Version ${tile.version} not supported`);
25
- }
26
- return byteOffset; // Indicates where the parsing ended
27
- }
28
- exports.parse3DTileHeaderSync = parse3DTileHeaderSync;
@@ -1,104 +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
- if ('bufferView' in subtree.tileAvailability) {
32
- subtree.tileAvailability.explicitBitstream = await getExplicitBitstream(subtree, 'tileAvailability', internalBinaryBuffer, context);
33
- }
34
- if ('bufferView' in subtree.contentAvailability) {
35
- subtree.contentAvailability.explicitBitstream = await getExplicitBitstream(subtree, 'contentAvailability', internalBinaryBuffer, context);
36
- }
37
- if ('bufferView' in subtree.childSubtreeAvailability) {
38
- subtree.childSubtreeAvailability.explicitBitstream = await getExplicitBitstream(subtree, 'childSubtreeAvailability', internalBinaryBuffer, context);
39
- }
40
- return subtree;
41
- }
42
- exports.default = parse3DTilesSubtree;
43
- /**
44
- * Get url for bitstream downloading
45
- * @param bitstreamRelativeUri
46
- * @param basePath
47
- * @returns
48
- */
49
- function resolveBufferUri(bitstreamRelativeUri, basePath) {
50
- const hasProtocol = basePath.startsWith('http');
51
- if (hasProtocol) {
52
- const resolvedUri = new URL(bitstreamRelativeUri, basePath);
53
- return decodeURI(resolvedUri.toString());
54
- }
55
- /**
56
- * Adding http protocol only for new URL constructor usage.
57
- * It allows to resolve relative paths like ../../example with basePath.
58
- */
59
- const basePathWithProtocol = `http://${basePath}`;
60
- const resolvedUri = new URL(bitstreamRelativeUri, basePathWithProtocol);
61
- /**
62
- * Drop protocol and use just relative path.
63
- */
64
- return `/${resolvedUri.host}${resolvedUri.pathname}`;
65
- }
66
- /**
67
- * Get explicit bitstream for subtree availability data.
68
- * @param subtree
69
- * @param name
70
- * @param internalBinaryBuffer
71
- */
72
- async function getExplicitBitstream(subtree, name, internalBinaryBuffer, context) {
73
- const bufferViewIndex = subtree[name].bufferView;
74
- const bufferView = subtree.bufferViews[bufferViewIndex];
75
- const buffer = subtree.buffers[bufferView.buffer];
76
- if (!context?.url || !context.fetch) {
77
- throw new Error('Url is not provided');
78
- }
79
- if (!context.fetch) {
80
- throw new Error('fetch is not provided');
81
- }
82
- // External bitstream loading
83
- if (buffer.uri) {
84
- const bufferUri = resolveBufferUri(buffer.uri, context?.url);
85
- const response = await context.fetch(bufferUri);
86
- const data = await response.arrayBuffer();
87
- // Return view of bitstream.
88
- return new Uint8Array(data, bufferView.byteOffset, bufferView.byteLength);
89
- }
90
- // Return view of bitstream.
91
- return new Uint8Array(internalBinaryBuffer, bufferView.byteOffset, bufferView.byteLength);
92
- }
93
- /**
94
- * Parse buffer to return uint64 value
95
- * @param buffer
96
- * @returns 64-bit value until precision is lost after Number.MAX_SAFE_INTEGER
97
- */
98
- function parseUint64Value(buffer) {
99
- const dataView = new DataView(buffer);
100
- const left = dataView.getUint32(0, true);
101
- const right = dataView.getUint32(4, true);
102
- // combine the two 32-bit values
103
- return left + 2 ** 32 * right;
104
- }
@@ -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 > 0) {
64
- const featureTableString = (0, parse_utils_1.getStringFromArrayBuffer)(arrayBuffer, byteOffset, featureTableJsonByteLength);
65
- tile.featureTableJson = JSON.parse(featureTableString);
66
- }
67
- byteOffset += featureTableJsonByteLength;
68
- tile.featureTableBinary = new Uint8Array(arrayBuffer, byteOffset, featureTableBinaryByteLength);
69
- byteOffset += featureTableBinaryByteLength;
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 > 0) {
81
- const batchTableString = (0, parse_utils_1.getStringFromArrayBuffer)(arrayBuffer, byteOffset, batchTableJsonByteLength);
82
- tile.batchTableJson = JSON.parse(batchTableString);
83
- byteOffset += batchTableJsonByteLength;
84
- if (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,26 +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
- // Reference code:
7
- // https://github.com/AnalyticalGraphicsInc/cesium/blob/master/Source/Scene/Composite3DTileContent.js#L182
8
- const parse_3d_tile_header_1 = require("./helpers/parse-3d-tile-header");
9
- // eslint-disable-next-line max-params
10
- async function parseComposite3DTile(tile, arrayBuffer, byteOffset, options, context, parse3DTile) {
11
- byteOffset = (0, parse_3d_tile_header_1.parse3DTileHeaderSync)(tile, arrayBuffer, byteOffset);
12
- const view = new DataView(arrayBuffer);
13
- // Extract number of tiles
14
- tile.tilesLength = view.getUint32(byteOffset, true);
15
- byteOffset += 4;
16
- // extract each tile from the byte stream
17
- tile.tiles = [];
18
- while (tile.tiles.length < tile.tilesLength && tile.byteLength - byteOffset > 12) {
19
- const subtile = {};
20
- tile.tiles.push(subtile);
21
- byteOffset = await parse3DTile(arrayBuffer, byteOffset, options, context, subtile);
22
- // TODO - do we need to add any padding in between tiles?
23
- }
24
- return byteOffset;
25
- }
26
- exports.parseComposite3DTile = parseComposite3DTile;