@loaders.gl/3d-tiles 4.0.0-alpha.23 → 4.0.0-alpha.25

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 (75) hide show
  1. package/dist/cesium-ion-loader.d.ts +2 -2
  2. package/dist/cesium-ion-loader.d.ts.map +1 -1
  3. package/dist/dist.min.js +421 -270
  4. package/dist/es5/3d-tiles-archive-loader.js +1 -1
  5. package/dist/es5/cesium-ion-loader.js.map +1 -1
  6. package/dist/es5/lib/utils/version.js +1 -1
  7. package/dist/es5/tile-3d-subtree-loader.js.map +1 -1
  8. package/dist/es5/tile-3d-writer.js.map +1 -1
  9. package/dist/es5/types.js.map +1 -1
  10. package/dist/esm/3d-tiles-archive-loader.js +1 -1
  11. package/dist/esm/cesium-ion-loader.js.map +1 -1
  12. package/dist/esm/lib/utils/version.js +1 -1
  13. package/dist/esm/tile-3d-subtree-loader.js.map +1 -1
  14. package/dist/esm/tile-3d-writer.js.map +1 -1
  15. package/dist/esm/types.js.map +1 -1
  16. package/dist/tile-3d-subtree-loader.d.ts +3 -3
  17. package/dist/tile-3d-subtree-loader.d.ts.map +1 -1
  18. package/dist/tile-3d-writer.d.ts +2 -2
  19. package/dist/tile-3d-writer.d.ts.map +1 -1
  20. package/dist/types.d.ts +2 -5
  21. package/dist/types.d.ts.map +1 -1
  22. package/package.json +8 -8
  23. package/src/cesium-ion-loader.ts +2 -2
  24. package/src/tile-3d-subtree-loader.ts +3 -3
  25. package/src/tile-3d-writer.ts +2 -2
  26. package/src/types.ts +3 -5
  27. package/dist/3d-tiles-archive/3d-tiles-archive-archive.js +0 -72
  28. package/dist/3d-tiles-archive/3d-tiles-archive-parser.js +0 -33
  29. package/dist/3d-tiles-archive-loader.js +0 -31
  30. package/dist/bundle.js +0 -5
  31. package/dist/cesium-ion-loader.js +0 -40
  32. package/dist/index.js +0 -30
  33. package/dist/lib/classes/helpers/tile-3d-accessor-utils.js +0 -113
  34. package/dist/lib/classes/tile-3d-batch-table-hierarchy.js +0 -197
  35. package/dist/lib/classes/tile-3d-batch-table.js +0 -245
  36. package/dist/lib/classes/tile-3d-feature-table.js +0 -72
  37. package/dist/lib/constants.js +0 -26
  38. package/dist/lib/encoders/encode-3d-tile-batched-model.js +0 -46
  39. package/dist/lib/encoders/encode-3d-tile-composite.js +0 -24
  40. package/dist/lib/encoders/encode-3d-tile-instanced-model.js +0 -38
  41. package/dist/lib/encoders/encode-3d-tile-point-cloud.js +0 -39
  42. package/dist/lib/encoders/encode-3d-tile.js +0 -33
  43. package/dist/lib/encoders/helpers/encode-3d-tile-header.js +0 -30
  44. package/dist/lib/filesystems/tiles-3d-archive-file-system.js +0 -75
  45. package/dist/lib/ion/ion.js +0 -68
  46. package/dist/lib/parsers/helpers/normalize-3d-tile-colors.js +0 -65
  47. package/dist/lib/parsers/helpers/normalize-3d-tile-normals.js +0 -30
  48. package/dist/lib/parsers/helpers/normalize-3d-tile-positions.js +0 -42
  49. package/dist/lib/parsers/helpers/parse-3d-implicit-tiles.js +0 -303
  50. package/dist/lib/parsers/helpers/parse-3d-tile-gltf-view.js +0 -96
  51. package/dist/lib/parsers/helpers/parse-3d-tile-header.js +0 -28
  52. package/dist/lib/parsers/helpers/parse-3d-tile-subtree.js +0 -87
  53. package/dist/lib/parsers/helpers/parse-3d-tile-tables.js +0 -93
  54. package/dist/lib/parsers/helpers/parse-utils.js +0 -32
  55. package/dist/lib/parsers/parse-3d-tile-batched-model.js +0 -33
  56. package/dist/lib/parsers/parse-3d-tile-composite.js +0 -24
  57. package/dist/lib/parsers/parse-3d-tile-gltf.js +0 -29
  58. package/dist/lib/parsers/parse-3d-tile-header.js +0 -194
  59. package/dist/lib/parsers/parse-3d-tile-instanced-model.js +0 -172
  60. package/dist/lib/parsers/parse-3d-tile-point-cloud.js +0 -441
  61. package/dist/lib/parsers/parse-3d-tile.js +0 -33
  62. package/dist/lib/utils/obb/s2-corners-to-obb.js +0 -37
  63. package/dist/lib/utils/s2/converters/s2-to-boundary.js +0 -61
  64. package/dist/lib/utils/s2/converters/s2-to-obb-points.js +0 -36
  65. package/dist/lib/utils/s2/converters/s2-to-region.js +0 -59
  66. package/dist/lib/utils/s2/index.js +0 -23
  67. package/dist/lib/utils/s2/s2-geometry-functions.js +0 -29
  68. package/dist/lib/utils/s2/s2-token-functions.js +0 -68
  69. package/dist/lib/utils/s2/s2geometry/s2-cell-utils.js +0 -32
  70. package/dist/lib/utils/s2/s2geometry/s2-geometry.js +0 -260
  71. package/dist/lib/utils/version.js +0 -7
  72. package/dist/tile-3d-subtree-loader.js +0 -23
  73. package/dist/tile-3d-writer.js +0 -27
  74. package/dist/tiles-3d-loader.js +0 -80
  75. package/dist/types.js +0 -2
@@ -1,303 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.replaceContentUrlTemplate = exports.parseImplicitTiles = void 0;
7
- const tile_3d_subtree_loader_1 = require("../../../tile-3d-subtree-loader");
8
- const core_1 = require("@loaders.gl/core");
9
- const log_1 = __importDefault(require("@probe.gl/log"));
10
- const index_1 = require("../../utils/s2/index");
11
- const s2_corners_to_obb_1 = require("../../utils/obb/s2-corners-to-obb");
12
- const QUADTREE_DEVISION_COUNT = 4;
13
- const OCTREE_DEVISION_COUNT = 8;
14
- const SUBDIVISION_COUNT_MAP = {
15
- QUADTREE: QUADTREE_DEVISION_COUNT,
16
- OCTREE: OCTREE_DEVISION_COUNT
17
- };
18
- function getChildS2VolumeBox(s2VolumeBox, index, subdivisionScheme) {
19
- if (s2VolumeBox?.box) {
20
- // Check if the BoundingVolume is of type "box"
21
- const cellId = (0, index_1.getS2CellIdFromToken)(s2VolumeBox.s2VolumeInfo.token);
22
- const childCellId = (0, index_1.getS2ChildCellId)(cellId, index);
23
- const childToken = (0, index_1.getS2TokenFromCellId)(childCellId);
24
- // Clone object. Note, s2VolumeInfo is a plain object that doesn't contain any nested object.
25
- // So, we can use the Spread Operator to make a shallow copy of the object.
26
- const s2ChildVolumeInfo = { ...s2VolumeBox.s2VolumeInfo };
27
- s2ChildVolumeInfo.token = childToken; // replace the token with the child's one
28
- // In case of QUADTREE the sizeZ should NOT be changed!
29
- // https://portal.ogc.org/files/102132
30
- // A quadtree divides space only on the x and y dimensions.
31
- // It divides each tile into 4 smaller tiles where the x and y dimensions are halved.
32
- // The quadtree z minimum and maximum remain unchanged.
33
- switch (subdivisionScheme) {
34
- case 'OCTREE':
35
- const s2VolumeInfo = s2VolumeBox.s2VolumeInfo;
36
- const delta = s2VolumeInfo.maximumHeight - s2VolumeInfo.minimumHeight;
37
- const sizeZ = delta / 2.0; // It's a next level (a child)
38
- const midZ = s2VolumeInfo.minimumHeight + delta / 2.0;
39
- s2VolumeInfo.minimumHeight = midZ - sizeZ;
40
- s2VolumeInfo.maximumHeight = midZ + sizeZ;
41
- break;
42
- default:
43
- break;
44
- }
45
- const box = (0, s2_corners_to_obb_1.convertS2BoundingVolumetoOBB)(s2ChildVolumeInfo);
46
- const childS2VolumeBox = {
47
- box,
48
- s2VolumeInfo: s2ChildVolumeInfo
49
- };
50
- return childS2VolumeBox;
51
- }
52
- return undefined;
53
- }
54
- /**
55
- * Recursively parse implicit tiles tree
56
- * Spec - https://github.com/CesiumGS/3d-tiles/tree/main/extensions/3DTILES_implicit_tiling
57
- * TODO Check out do we able to use Tile3D class as return type here.
58
- * @param subtree
59
- * @param lodMetricValue
60
- * @param options
61
- * @param parentData
62
- * @param childIndex
63
- * @param level
64
- * @param globalData
65
- */
66
- // eslint-disable-next-line max-statements
67
- async function parseImplicitTiles(params) {
68
- const { implicitOptions, parentData = {
69
- mortonIndex: 0,
70
- x: 0,
71
- y: 0,
72
- z: 0
73
- }, childIndex = 0, globalData = {
74
- level: 0,
75
- mortonIndex: 0,
76
- x: 0,
77
- y: 0,
78
- z: 0
79
- }, s2VolumeBox, loaderOptions } = params;
80
- let { subtree, level = 0 } = params;
81
- const { subdivisionScheme, subtreeLevels, maximumLevel, contentUrlTemplate, subtreesUriTemplate, basePath } = implicitOptions;
82
- const tile = { children: [], lodMetricValue: 0, contentUrl: '' };
83
- if (!maximumLevel) {
84
- // eslint-disable-next-line no-console
85
- log_1.default.once(`Missing 'maximumLevel' or 'availableLevels' property. The subtree ${contentUrlTemplate} won't be loaded...`);
86
- return tile;
87
- }
88
- const lev = level + globalData.level;
89
- if (lev > maximumLevel) {
90
- return tile;
91
- }
92
- const childrenPerTile = SUBDIVISION_COUNT_MAP[subdivisionScheme];
93
- const bitsPerTile = Math.log2(childrenPerTile);
94
- // childIndex is in range [0,4] for quadtrees and [0, 7] for octrees
95
- const childX = childIndex & 0b01; // Get first bit for X
96
- const childY = (childIndex >> 1) & 0b01; // Get second bit for Y
97
- const childZ = (childIndex >> 2) & 0b01; // Get third bit for Z
98
- const levelOffset = (childrenPerTile ** level - 1) / (childrenPerTile - 1);
99
- let childTileMortonIndex = concatBits(parentData.mortonIndex, childIndex, bitsPerTile);
100
- let tileAvailabilityIndex = levelOffset + childTileMortonIndex;
101
- // Local tile coordinates
102
- let childTileX = concatBits(parentData.x, childX, 1);
103
- let childTileY = concatBits(parentData.y, childY, 1);
104
- let childTileZ = concatBits(parentData.z, childZ, 1);
105
- let isChildSubtreeAvailable = false;
106
- if (level >= subtreeLevels) {
107
- isChildSubtreeAvailable = getAvailabilityResult(subtree.childSubtreeAvailability, childTileMortonIndex);
108
- }
109
- const x = concatBits(globalData.x, childTileX, level * bitsPerTile);
110
- const y = concatBits(globalData.y, childTileY, level * bitsPerTile);
111
- const z = concatBits(globalData.z, childTileZ, level * bitsPerTile);
112
- if (isChildSubtreeAvailable) {
113
- const subtreePath = `${basePath}/${subtreesUriTemplate}`;
114
- const childSubtreeUrl = replaceContentUrlTemplate(subtreePath, lev, x, y, z);
115
- const childSubtree = await (0, core_1.load)(childSubtreeUrl, tile_3d_subtree_loader_1.Tile3DSubtreeLoader, loaderOptions);
116
- subtree = childSubtree;
117
- globalData.mortonIndex = childTileMortonIndex;
118
- globalData.x = childTileX;
119
- globalData.y = childTileY;
120
- globalData.z = childTileZ;
121
- globalData.level = level;
122
- childTileMortonIndex = 0;
123
- tileAvailabilityIndex = 0;
124
- childTileX = 0;
125
- childTileY = 0;
126
- childTileZ = 0;
127
- level = 0;
128
- }
129
- const isTileAvailable = getAvailabilityResult(subtree.tileAvailability, tileAvailabilityIndex);
130
- if (!isTileAvailable) {
131
- return tile;
132
- }
133
- const isContentAvailable = getAvailabilityResult(subtree.contentAvailability, tileAvailabilityIndex);
134
- if (isContentAvailable) {
135
- tile.contentUrl = replaceContentUrlTemplate(contentUrlTemplate, lev, x, y, z);
136
- }
137
- const childTileLevel = level + 1;
138
- const pData = { mortonIndex: childTileMortonIndex, x: childTileX, y: childTileY, z: childTileZ };
139
- for (let index = 0; index < childrenPerTile; index++) {
140
- const childS2VolumeBox = getChildS2VolumeBox(s2VolumeBox, index, subdivisionScheme);
141
- // Recursive calling...
142
- const childTileParsed = await parseImplicitTiles({
143
- subtree,
144
- implicitOptions,
145
- loaderOptions,
146
- parentData: pData,
147
- childIndex: index,
148
- level: childTileLevel,
149
- globalData: { ...globalData },
150
- s2VolumeBox: childS2VolumeBox
151
- });
152
- if (childTileParsed.contentUrl || childTileParsed.children.length) {
153
- const globalLevel = lev + 1;
154
- const childCoordinates = { childTileX, childTileY, childTileZ };
155
- const formattedTile = formatTileData(childTileParsed, globalLevel, childCoordinates, implicitOptions, s2VolumeBox);
156
- // @ts-ignore
157
- tile.children.push(formattedTile);
158
- }
159
- }
160
- return tile;
161
- }
162
- exports.parseImplicitTiles = parseImplicitTiles;
163
- /**
164
- * Check tile availability in the bitstream array
165
- * @param availabilityData - tileAvailability / contentAvailability / childSubtreeAvailability object
166
- * @param index - index in the bitstream array
167
- * @returns
168
- */
169
- function getAvailabilityResult(availabilityData, index) {
170
- let availabilityObject;
171
- if (Array.isArray(availabilityData)) {
172
- /** TODO: we don't support `3DTILES_multiple_contents` extension at the moment.
173
- * https://github.com/CesiumGS/3d-tiles/blob/main/extensions/3DTILES_implicit_tiling/README.md#multiple-contents
174
- * Take first item in the array
175
- */
176
- availabilityObject = availabilityData[0];
177
- if (availabilityData.length > 1) {
178
- // eslint-disable-next-line no-console
179
- log_1.default.once('Not supported extension "3DTILES_multiple_contents" has been detected');
180
- }
181
- }
182
- else {
183
- availabilityObject = availabilityData;
184
- }
185
- if ('constant' in availabilityObject) {
186
- return Boolean(availabilityObject.constant);
187
- }
188
- if (availabilityObject.explicitBitstream) {
189
- return getBooleanValueFromBitstream(index, availabilityObject.explicitBitstream);
190
- }
191
- return false;
192
- }
193
- /**
194
- * Do formatting of implicit tile data.
195
- * TODO Check out do we able to use Tile3D class as type here.
196
- * @param tile
197
- * @param lodMetricValue
198
- * @param options
199
- * @returns
200
- */
201
- function formatTileData(tile, level, childCoordinates, options, s2VolumeBox) {
202
- const { basePath, refine, getRefine, lodMetricType, getTileType, rootLodMetricValue, rootBoundingVolume } = options;
203
- const uri = tile.contentUrl && tile.contentUrl.replace(`${basePath}/`, '');
204
- const lodMetricValue = rootLodMetricValue / 2 ** level;
205
- const boundingVolume = s2VolumeBox?.box
206
- ? { box: s2VolumeBox.box }
207
- : rootBoundingVolume;
208
- const boundingVolumeForChildTile = calculateBoundingVolumeForChildTile(level, boundingVolume, childCoordinates);
209
- return {
210
- children: tile.children,
211
- contentUrl: tile.contentUrl,
212
- content: { uri },
213
- id: tile.contentUrl,
214
- refine: getRefine(refine),
215
- type: getTileType(tile),
216
- lodMetricType,
217
- lodMetricValue,
218
- geometricError: lodMetricValue,
219
- transform: tile.transform,
220
- boundingVolume: boundingVolumeForChildTile
221
- };
222
- }
223
- /**
224
- * Calculate child bounding volume.
225
- * Spec - https://github.com/CesiumGS/3d-tiles/tree/main/extensions/3DTILES_implicit_tiling#subdivision-rules
226
- * @param level
227
- * @param rootBoundingVolume
228
- * @param childCoordinates
229
- */
230
- function calculateBoundingVolumeForChildTile(level, rootBoundingVolume, childCoordinates) {
231
- if (rootBoundingVolume.region) {
232
- const { childTileX, childTileY, childTileZ } = childCoordinates;
233
- const [west, south, east, north, minimumHeight, maximumHeight] = rootBoundingVolume.region;
234
- const boundingVolumesCount = 2 ** level;
235
- const sizeX = (east - west) / boundingVolumesCount;
236
- const sizeY = (north - south) / boundingVolumesCount;
237
- // TODO : Why is the subdivisionScheme not being checked here?
238
- // In case of QUADTREE the sizeZ should NOT be changed!
239
- // https://portal.ogc.org/files/102132
240
- // 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.
241
- const sizeZ = (maximumHeight - minimumHeight) / boundingVolumesCount;
242
- const [childWest, childEast] = [west + sizeX * childTileX, west + sizeX * (childTileX + 1)];
243
- const [childSouth, childNorth] = [south + sizeY * childTileY, south + sizeY * (childTileY + 1)];
244
- const [childMinimumHeight, childMaximumHeight] = [
245
- minimumHeight + sizeZ * childTileZ,
246
- minimumHeight + sizeZ * (childTileZ + 1)
247
- ];
248
- return {
249
- region: [childWest, childSouth, childEast, childNorth, childMinimumHeight, childMaximumHeight]
250
- };
251
- }
252
- if (rootBoundingVolume.box) {
253
- return rootBoundingVolume;
254
- }
255
- throw new Error(`Unsupported bounding volume type ${rootBoundingVolume}`);
256
- }
257
- /**
258
- * Do binary concatenation
259
- * @param higher - number to put to higher part of result
260
- * @param lower - number to put to lower part of result
261
- * @param shift - number of bits to shift lower number
262
- */
263
- function concatBits(higher, lower, shift) {
264
- return (higher << shift) + lower;
265
- }
266
- /**
267
- * Replace implicit tile content url with real coordinates.
268
- * @param templateUrl
269
- * @param level
270
- * @param x
271
- * @param y
272
- * @param z
273
- */
274
- function replaceContentUrlTemplate(templateUrl, level, x, y, z) {
275
- const mapUrl = generateMapUrl({ level, x, y, z });
276
- return templateUrl.replace(/{level}|{x}|{y}|{z}/gi, (matched) => mapUrl[matched]);
277
- }
278
- exports.replaceContentUrlTemplate = replaceContentUrlTemplate;
279
- /**
280
- * Get Map object for content url generation
281
- * @param items
282
- */
283
- function generateMapUrl(items) {
284
- const mapUrl = {};
285
- for (const key in items) {
286
- mapUrl[`{${key}}`] = items[key];
287
- }
288
- return mapUrl;
289
- }
290
- /**
291
- * Get boolean value from bistream by index
292
- * A boolean value is encoded as a single bit, either 0 (false) or 1 (true).
293
- * Multiple boolean values are packed tightly in the same buffer.
294
- * These buffers of tightly-packed bits are sometimes referred to as bitstreams.
295
- * Spec - https://github.com/CesiumGS/3d-tiles/tree/implicit-revisions/specification/Metadata#booleans
296
- * @param availabilitiIndex
297
- */
298
- function getBooleanValueFromBitstream(availabilityIndex, availabilityBuffer) {
299
- const byteIndex = Math.floor(availabilityIndex / 8);
300
- const bitIndex = availabilityIndex % 8;
301
- const bitValue = (availabilityBuffer[byteIndex] >> bitIndex) & 1;
302
- return bitValue === 1;
303
- }
@@ -1,96 +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 || 0) + (tile.byteLength || 0) - 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 || 0) + (tile.byteLength || 0);
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
- if (!context) {
56
- return;
57
- }
58
- if (tile.gltfUrl) {
59
- const { fetch } = context;
60
- const response = await fetch(tile.gltfUrl, options);
61
- tile.gltfArrayBuffer = await response.arrayBuffer();
62
- tile.gltfByteOffset = 0;
63
- }
64
- if (tile.gltfArrayBuffer) {
65
- // TODO - Should handle byteOffset... However, not used now...
66
- const gltfWithBuffers = await (0, loader_utils_1.parseFromContext)(tile.gltfArrayBuffer, gltf_1.GLTFLoader, options, context);
67
- tile.gltf = (0, gltf_1.postProcessGLTF)(gltfWithBuffers);
68
- tile.gpuMemoryUsageInBytes = (0, gltf_1._getMemoryUsageGLTF)(tile.gltf);
69
- delete tile.gltfArrayBuffer;
70
- delete tile.gltfByteOffset;
71
- delete tile.gltfByteLength;
72
- }
73
- }
74
- }
75
- exports.extractGLTF = extractGLTF;
76
- function extractGLTFBufferOrURL(tile, gltfFormat, options) {
77
- switch (gltfFormat) {
78
- case exports.GLTF_FORMAT.URI:
79
- // We need to remove padding from the end of the model URL in case this tile was part of a composite tile.
80
- // This removes all white space and null characters from the end of the string.
81
- if (tile.gltfArrayBuffer) {
82
- const gltfUrlBytes = new Uint8Array(tile.gltfArrayBuffer, tile.gltfByteOffset);
83
- const textDecoder = new TextDecoder();
84
- const gltfUrl = textDecoder.decode(gltfUrlBytes);
85
- tile.gltfUrl = gltfUrl.replace(/[\s\0]+$/, '');
86
- }
87
- delete tile.gltfArrayBuffer;
88
- delete tile.gltfByteOffset;
89
- delete tile.gltfByteLength;
90
- break;
91
- case exports.GLTF_FORMAT.EMBEDDED:
92
- break;
93
- default:
94
- throw new Error('b3dm: Illegal glTF format field');
95
- }
96
- }
@@ -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,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
- }