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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (70) 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 +156 -110
  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/esm/3d-tiles-archive-loader.js +1 -1
  10. package/dist/esm/cesium-ion-loader.js.map +1 -1
  11. package/dist/esm/lib/utils/version.js +1 -1
  12. package/dist/esm/tile-3d-subtree-loader.js.map +1 -1
  13. package/dist/esm/tile-3d-writer.js.map +1 -1
  14. package/dist/tile-3d-subtree-loader.d.ts +3 -3
  15. package/dist/tile-3d-subtree-loader.d.ts.map +1 -1
  16. package/dist/tile-3d-writer.d.ts +2 -2
  17. package/dist/tile-3d-writer.d.ts.map +1 -1
  18. package/package.json +8 -8
  19. package/src/cesium-ion-loader.ts +2 -2
  20. package/src/tile-3d-subtree-loader.ts +3 -3
  21. package/src/tile-3d-writer.ts +2 -2
  22. package/dist/3d-tiles-archive/3d-tiles-archive-archive.js +0 -72
  23. package/dist/3d-tiles-archive/3d-tiles-archive-parser.js +0 -33
  24. package/dist/3d-tiles-archive-loader.js +0 -31
  25. package/dist/bundle.js +0 -5
  26. package/dist/cesium-ion-loader.js +0 -40
  27. package/dist/index.js +0 -30
  28. package/dist/lib/classes/helpers/tile-3d-accessor-utils.js +0 -113
  29. package/dist/lib/classes/tile-3d-batch-table-hierarchy.js +0 -197
  30. package/dist/lib/classes/tile-3d-batch-table.js +0 -245
  31. package/dist/lib/classes/tile-3d-feature-table.js +0 -72
  32. package/dist/lib/constants.js +0 -26
  33. package/dist/lib/encoders/encode-3d-tile-batched-model.js +0 -46
  34. package/dist/lib/encoders/encode-3d-tile-composite.js +0 -24
  35. package/dist/lib/encoders/encode-3d-tile-instanced-model.js +0 -38
  36. package/dist/lib/encoders/encode-3d-tile-point-cloud.js +0 -39
  37. package/dist/lib/encoders/encode-3d-tile.js +0 -33
  38. package/dist/lib/encoders/helpers/encode-3d-tile-header.js +0 -30
  39. package/dist/lib/filesystems/tiles-3d-archive-file-system.js +0 -75
  40. package/dist/lib/ion/ion.js +0 -68
  41. package/dist/lib/parsers/helpers/normalize-3d-tile-colors.js +0 -65
  42. package/dist/lib/parsers/helpers/normalize-3d-tile-normals.js +0 -30
  43. package/dist/lib/parsers/helpers/normalize-3d-tile-positions.js +0 -42
  44. package/dist/lib/parsers/helpers/parse-3d-implicit-tiles.js +0 -303
  45. package/dist/lib/parsers/helpers/parse-3d-tile-gltf-view.js +0 -96
  46. package/dist/lib/parsers/helpers/parse-3d-tile-header.js +0 -28
  47. package/dist/lib/parsers/helpers/parse-3d-tile-subtree.js +0 -87
  48. package/dist/lib/parsers/helpers/parse-3d-tile-tables.js +0 -93
  49. package/dist/lib/parsers/helpers/parse-utils.js +0 -32
  50. package/dist/lib/parsers/parse-3d-tile-batched-model.js +0 -33
  51. package/dist/lib/parsers/parse-3d-tile-composite.js +0 -24
  52. package/dist/lib/parsers/parse-3d-tile-gltf.js +0 -29
  53. package/dist/lib/parsers/parse-3d-tile-header.js +0 -194
  54. package/dist/lib/parsers/parse-3d-tile-instanced-model.js +0 -172
  55. package/dist/lib/parsers/parse-3d-tile-point-cloud.js +0 -441
  56. package/dist/lib/parsers/parse-3d-tile.js +0 -33
  57. package/dist/lib/utils/obb/s2-corners-to-obb.js +0 -37
  58. package/dist/lib/utils/s2/converters/s2-to-boundary.js +0 -61
  59. package/dist/lib/utils/s2/converters/s2-to-obb-points.js +0 -36
  60. package/dist/lib/utils/s2/converters/s2-to-region.js +0 -59
  61. package/dist/lib/utils/s2/index.js +0 -23
  62. package/dist/lib/utils/s2/s2-geometry-functions.js +0 -29
  63. package/dist/lib/utils/s2/s2-token-functions.js +0 -68
  64. package/dist/lib/utils/s2/s2geometry/s2-cell-utils.js +0 -32
  65. package/dist/lib/utils/s2/s2geometry/s2-geometry.js +0 -260
  66. package/dist/lib/utils/version.js +0 -7
  67. package/dist/tile-3d-subtree-loader.js +0 -23
  68. package/dist/tile-3d-writer.js +0 -27
  69. package/dist/tiles-3d-loader.js +0 -80
  70. package/dist/types.js +0 -2
@@ -1,245 +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
- const loader_utils_1 = require("@loaders.gl/loader-utils");
6
- const tile_3d_accessor_utils_1 = require("./helpers/tile-3d-accessor-utils");
7
- const tile_3d_batch_table_hierarchy_1 = require("./tile-3d-batch-table-hierarchy");
8
- function defined(x) {
9
- return x !== undefined && x !== null;
10
- }
11
- const clone = (x, y) => x;
12
- // These top level fields in the batch table json are not properties
13
- const IGNORED_PROPERTY_FIELDS = {
14
- HIERARCHY: true,
15
- extensions: true,
16
- extras: true
17
- };
18
- // The size of this array equals the maximum instance count among all loaded tiles, which has the potential to be large.
19
- class Tile3DBatchTableParser {
20
- constructor(json, binary, featureCount, options = {}) {
21
- (0, loader_utils_1.assert)(featureCount >= 0);
22
- this.json = json || {};
23
- this.binary = binary;
24
- this.featureCount = featureCount;
25
- this._extensions = this.json?.extensions || {};
26
- // Copy all top-level property fields from the json object, ignoring special fields
27
- this._properties = {};
28
- for (const propertyName in this.json) {
29
- if (!IGNORED_PROPERTY_FIELDS[propertyName]) {
30
- this._properties[propertyName] = this.json[propertyName];
31
- }
32
- }
33
- this._binaryProperties = this._initializeBinaryProperties();
34
- // TODO: hierarchy support is only partially implemented and not tested
35
- if (options['3DTILES_batch_table_hierarchy']) {
36
- this._hierarchy = (0, tile_3d_batch_table_hierarchy_1.initializeHierarchy)(this, this.json, this.binary);
37
- }
38
- }
39
- getExtension(extensionName) {
40
- return this.json && this.json.extensions && this.json.extensions[extensionName];
41
- }
42
- memorySizeInBytes() {
43
- return 0;
44
- }
45
- isClass(batchId, className) {
46
- this._checkBatchId(batchId);
47
- (0, loader_utils_1.assert)(typeof className === 'string', className);
48
- // extension: 3DTILES_batch_table_hierarchy
49
- if (this._hierarchy) {
50
- // PERFORMANCE_IDEA : cache results in the ancestor classes
51
- // to speed up this check if this area becomes a hotspot
52
- // PERFORMANCE_IDEA : treat class names as integers for faster comparisons
53
- const result = (0, tile_3d_batch_table_hierarchy_1.traverseHierarchy)(this._hierarchy, batchId, (hierarchy, instanceIndex) => {
54
- const classId = hierarchy.classIds[instanceIndex];
55
- const instanceClass = hierarchy.classes[classId];
56
- return instanceClass.name === className;
57
- });
58
- return defined(result);
59
- }
60
- return false;
61
- }
62
- isExactClass(batchId, className) {
63
- (0, loader_utils_1.assert)(typeof className === 'string', className);
64
- return this.getExactClassName(batchId) === className;
65
- }
66
- getExactClassName(batchId) {
67
- this._checkBatchId(batchId);
68
- // extension: 3DTILES_batch_table_hierarchy
69
- if (this._hierarchy) {
70
- const classId = this._hierarchy.classIds[batchId];
71
- const instanceClass = this._hierarchy.classes[classId];
72
- return instanceClass.name;
73
- }
74
- return undefined;
75
- }
76
- hasProperty(batchId, name) {
77
- this._checkBatchId(batchId);
78
- (0, loader_utils_1.assert)(typeof name === 'string', name);
79
- return defined(this._properties[name]) || this._hasPropertyInHierarchy(batchId, name);
80
- }
81
- getPropertyNames(batchId, results) {
82
- this._checkBatchId(batchId);
83
- results = defined(results) ? results : [];
84
- results.length = 0;
85
- const propertyNames = Object.keys(this._properties);
86
- results.push(...propertyNames);
87
- if (this._hierarchy) {
88
- this._getPropertyNamesInHierarchy(batchId, results);
89
- }
90
- return results;
91
- }
92
- getProperty(batchId, name) {
93
- this._checkBatchId(batchId);
94
- (0, loader_utils_1.assert)(typeof name === 'string', name);
95
- if (this._binaryProperties) {
96
- const binaryProperty = this._binaryProperties[name];
97
- if (defined(binaryProperty)) {
98
- return this._getBinaryProperty(binaryProperty, batchId);
99
- }
100
- }
101
- const propertyValues = this._properties[name];
102
- if (defined(propertyValues)) {
103
- return clone(propertyValues[batchId], true);
104
- }
105
- // EXTENSION: 3DTILES_batch_table_hierarchy
106
- if (this._hierarchy) {
107
- const hierarchyProperty = this._getHierarchyProperty(batchId, name);
108
- if (defined(hierarchyProperty)) {
109
- return hierarchyProperty;
110
- }
111
- }
112
- return undefined;
113
- }
114
- setProperty(batchId, name, value) {
115
- const featureCount = this.featureCount;
116
- this._checkBatchId(batchId);
117
- (0, loader_utils_1.assert)(typeof name === 'string', name);
118
- if (this._binaryProperties) {
119
- const binaryProperty = this._binaryProperties[name];
120
- if (binaryProperty) {
121
- this._setBinaryProperty(binaryProperty, batchId, value);
122
- return;
123
- }
124
- }
125
- // EXTENSION: 3DTILES_batch_table_hierarchy
126
- if (this._hierarchy) {
127
- if (this._setHierarchyProperty(this, batchId, name, value)) {
128
- return;
129
- }
130
- }
131
- let propertyValues = this._properties[name];
132
- if (!defined(propertyValues)) {
133
- // Property does not exist. Create it.
134
- this._properties[name] = new Array(featureCount);
135
- propertyValues = this._properties[name];
136
- }
137
- propertyValues[batchId] = clone(value, true);
138
- }
139
- // PRIVATE METHODS
140
- _checkBatchId(batchId) {
141
- const valid = batchId >= 0 && batchId < this.featureCount;
142
- if (!valid) {
143
- throw new Error('batchId not in range [0, featureCount - 1].');
144
- }
145
- }
146
- _getBinaryProperty(binaryProperty, index) {
147
- return binaryProperty.unpack(binaryProperty.typedArray, index);
148
- }
149
- _setBinaryProperty(binaryProperty, index, value) {
150
- binaryProperty.pack(value, binaryProperty.typedArray, index);
151
- }
152
- _initializeBinaryProperties() {
153
- let binaryProperties = null;
154
- for (const name in this._properties) {
155
- const property = this._properties[name];
156
- const binaryProperty = this._initializeBinaryProperty(name, property);
157
- // Store any information needed to access the binary data, including the typed array,
158
- // componentCount (e.g. a VEC4 would be 4), and the type used to pack and unpack (e.g. Cartesian4).
159
- if (binaryProperty) {
160
- binaryProperties = binaryProperties || {};
161
- binaryProperties[name] = binaryProperty;
162
- }
163
- }
164
- return binaryProperties;
165
- }
166
- _initializeBinaryProperty(name, property) {
167
- if ('byteOffset' in property) {
168
- // This is a binary property
169
- const tile3DAccessor = property;
170
- (0, loader_utils_1.assert)(this.binary, `Property ${name} requires a batch table binary.`);
171
- (0, loader_utils_1.assert)(tile3DAccessor.type, `Property ${name} requires a type.`);
172
- const accessor = (0, tile_3d_accessor_utils_1.createTypedArrayFromAccessor)(tile3DAccessor, this.binary.buffer, this.binary.byteOffset | 0, this.featureCount);
173
- // Store any information needed to access the binary data, including the typed array,
174
- // componentCount (e.g. a VEC4 would be 4), and the type used to pack and unpack (e.g. Cartesian4).
175
- return {
176
- typedArray: accessor.values,
177
- componentCount: accessor.size,
178
- unpack: accessor.unpacker,
179
- pack: accessor.packer
180
- };
181
- }
182
- return null;
183
- }
184
- // EXTENSION SUPPORT: 3DTILES_batch_table_hierarchy
185
- _hasPropertyInHierarchy(batchId, name) {
186
- if (!this._hierarchy) {
187
- return false;
188
- }
189
- const result = (0, tile_3d_batch_table_hierarchy_1.traverseHierarchy)(this._hierarchy, batchId, (hierarchy, instanceIndex) => {
190
- const classId = hierarchy.classIds[instanceIndex];
191
- const instances = hierarchy.classes[classId].instances;
192
- return defined(instances[name]);
193
- });
194
- return defined(result);
195
- }
196
- _getPropertyNamesInHierarchy(batchId, results) {
197
- (0, tile_3d_batch_table_hierarchy_1.traverseHierarchy)(this._hierarchy, batchId, (hierarchy, instanceIndex) => {
198
- const classId = hierarchy.classIds[instanceIndex];
199
- const instances = hierarchy.classes[classId].instances;
200
- for (const name in instances) {
201
- if (instances.hasOwnProperty(name)) {
202
- if (results.indexOf(name) === -1) {
203
- results.push(name);
204
- }
205
- }
206
- }
207
- });
208
- }
209
- _getHierarchyProperty(batchId, name) {
210
- return (0, tile_3d_batch_table_hierarchy_1.traverseHierarchy)(this._hierarchy, batchId, (hierarchy, instanceIndex) => {
211
- const classId = hierarchy.classIds[instanceIndex];
212
- const instanceClass = hierarchy.classes[classId];
213
- const indexInClass = hierarchy.classIndexes[instanceIndex];
214
- const propertyValues = instanceClass.instances[name];
215
- if (defined(propertyValues)) {
216
- if (defined(propertyValues.typedArray)) {
217
- return this._getBinaryProperty(propertyValues, indexInClass);
218
- }
219
- return clone(propertyValues[indexInClass], true);
220
- }
221
- return null;
222
- });
223
- }
224
- _setHierarchyProperty(batchTable, batchId, name, value) {
225
- const result = (0, tile_3d_batch_table_hierarchy_1.traverseHierarchy)(this._hierarchy, batchId, (hierarchy, instanceIndex) => {
226
- const classId = hierarchy.classIds[instanceIndex];
227
- const instanceClass = hierarchy.classes[classId];
228
- const indexInClass = hierarchy.classIndexes[instanceIndex];
229
- const propertyValues = instanceClass.instances[name];
230
- if (defined(propertyValues)) {
231
- (0, loader_utils_1.assert)(instanceIndex === batchId, `Inherited property "${name}" is read-only.`);
232
- if (defined(propertyValues.typedArray)) {
233
- this._setBinaryProperty(propertyValues, indexInClass, value);
234
- }
235
- else {
236
- propertyValues[indexInClass] = clone(value, true);
237
- }
238
- return true;
239
- }
240
- return false;
241
- });
242
- return defined(result);
243
- }
244
- }
245
- exports.default = Tile3DBatchTableParser;
@@ -1,72 +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
- const math_1 = require("@loaders.gl/math");
6
- // Reference:
7
- // https://github.com/AnalyticalGraphicsInc/cesium/blob/1de96d087f0b17575eb1a3f736407b348c765d59/Source/Scene/Cesium3DTileFeatureTable.js
8
- class Tile3DFeatureTable {
9
- constructor(featureTableJson, featureTableBinary) {
10
- this.featuresLength = 0;
11
- this._cachedTypedArrays = {};
12
- this.json = featureTableJson;
13
- this.buffer = featureTableBinary;
14
- }
15
- getExtension(extensionName) {
16
- return this.json.extensions && this.json.extensions[extensionName];
17
- }
18
- hasProperty(propertyName) {
19
- return Boolean(this.json[propertyName]);
20
- }
21
- getGlobalProperty(propertyName, componentType = math_1.GL.UNSIGNED_INT, componentLength = 1) {
22
- const jsonValue = this.json[propertyName];
23
- if (jsonValue && Number.isFinite(jsonValue.byteOffset)) {
24
- return this._getTypedArrayFromBinary(propertyName, componentType, componentLength, 1, jsonValue.byteOffset);
25
- }
26
- return jsonValue;
27
- }
28
- getPropertyArray(propertyName, componentType, componentLength) {
29
- const jsonValue = this.json[propertyName];
30
- if (jsonValue && Number.isFinite(jsonValue.byteOffset)) {
31
- if ('componentType' in jsonValue) {
32
- componentType = math_1.GLType.fromName(jsonValue.componentType);
33
- }
34
- return this._getTypedArrayFromBinary(propertyName, componentType, componentLength, this.featuresLength, jsonValue.byteOffset);
35
- }
36
- return this._getTypedArrayFromArray(propertyName, componentType, jsonValue);
37
- }
38
- getProperty(propertyName, componentType, componentLength, featureId, result) {
39
- const jsonValue = this.json[propertyName];
40
- if (!jsonValue) {
41
- return jsonValue;
42
- }
43
- const typedArray = this.getPropertyArray(propertyName, componentType, componentLength);
44
- if (componentLength === 1) {
45
- return typedArray[featureId];
46
- }
47
- for (let i = 0; i < componentLength; ++i) {
48
- result[i] = typedArray[componentLength * featureId + i];
49
- }
50
- return result;
51
- }
52
- // HELPERS
53
- _getTypedArrayFromBinary(propertyName, componentType, componentLength, count, byteOffset) {
54
- const cachedTypedArrays = this._cachedTypedArrays;
55
- let typedArray = cachedTypedArrays[propertyName];
56
- if (!typedArray) {
57
- typedArray = math_1.GLType.createTypedArray(componentType, this.buffer.buffer, this.buffer.byteOffset + byteOffset, count * componentLength);
58
- cachedTypedArrays[propertyName] = typedArray;
59
- }
60
- return typedArray;
61
- }
62
- _getTypedArrayFromArray(propertyName, componentType, array) {
63
- const cachedTypedArrays = this._cachedTypedArrays;
64
- let typedArray = cachedTypedArrays[propertyName];
65
- if (!typedArray) {
66
- typedArray = math_1.GLType.createTypedArray(componentType, array);
67
- cachedTypedArrays[propertyName] = typedArray;
68
- }
69
- return typedArray;
70
- }
71
- }
72
- exports.default = Tile3DFeatureTable;
@@ -1,26 +0,0 @@
1
- "use strict";
2
- // TILE TYPES
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.TILE3D_OPTIMIZATION_HINT = exports.MAGIC_ARRAY = exports.TILE3D_TYPES = exports.TILE3D_TYPE = void 0;
5
- exports.TILE3D_TYPE = {
6
- COMPOSITE: 'cmpt',
7
- POINT_CLOUD: 'pnts',
8
- BATCHED_3D_MODEL: 'b3dm',
9
- INSTANCED_3D_MODEL: 'i3dm',
10
- GEOMETRY: 'geom',
11
- VECTOR: 'vect',
12
- GLTF: 'glTF'
13
- };
14
- exports.TILE3D_TYPES = Object.keys(exports.TILE3D_TYPE);
15
- exports.MAGIC_ARRAY = {
16
- BATCHED_MODEL: [98, 51, 100, 109],
17
- INSTANCED_MODEL: [105, 51, 100, 109],
18
- POINT_CLOUD: [112, 110, 116, 115],
19
- COMPOSITE: [99, 109, 112, 116]
20
- };
21
- // TILE CONSTANTS
22
- exports.TILE3D_OPTIMIZATION_HINT = {
23
- NOT_COMPUTED: -1,
24
- USE_OPTIMIZATION: 1,
25
- SKIP_OPTIMIZATION: 0
26
- };
@@ -1,46 +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.encodeBatchedModel3DTile = void 0;
6
- const loader_utils_1 = require("@loaders.gl/loader-utils");
7
- const constants_1 = require("../constants");
8
- const encode_3d_tile_header_1 = require("./helpers/encode-3d-tile-header");
9
- // Procedurally encode the tile array dataView for testing purposes
10
- function encodeBatchedModel3DTile(tile, dataView, byteOffset, options) {
11
- const { featuresLength = 0, batchTable } = tile;
12
- const featureTableJson = {
13
- BATCH_LENGTH: featuresLength
14
- };
15
- const featureTableJsonString = JSON.stringify(featureTableJson);
16
- const batchTableJsonString = batchTable ? JSON.stringify(batchTable) : '';
17
- const featureTableJsonByteLength = (0, loader_utils_1.padToNBytes)(featureTableJsonString.length, 8);
18
- const batchTableJsonByteLength = batchTableJsonString
19
- ? (0, loader_utils_1.padToNBytes)(batchTableJsonString.length, 8)
20
- : 0;
21
- // Add default magic for this tile type
22
- tile = { magic: constants_1.MAGIC_ARRAY.BATCHED_MODEL, ...tile };
23
- const byteOffsetStart = byteOffset;
24
- byteOffset = (0, encode_3d_tile_header_1.encode3DTileHeader)(tile, dataView, byteOffset);
25
- if (dataView) {
26
- dataView.setUint32(12, featureTableJsonByteLength, true); // featureTableJsonByteLength
27
- dataView.setUint32(16, 0, true); // featureTableBinaryByteLength
28
- dataView.setUint32(20, batchTableJsonByteLength, true); // batchTableJsonByteLength
29
- dataView.setUint32(24, 0, true); // batchTableBinaryByteLength
30
- }
31
- byteOffset += 16;
32
- // TODO feature table binary
33
- byteOffset = (0, loader_utils_1.copyPaddedStringToDataView)(dataView, byteOffset, featureTableJsonString, 8);
34
- if (batchTable) {
35
- byteOffset = (0, loader_utils_1.copyPaddedStringToDataView)(dataView, byteOffset, batchTableJsonString, 8);
36
- }
37
- // Add encoded GLTF to the end of data
38
- const gltfEncoded = tile.gltfEncoded;
39
- if (gltfEncoded) {
40
- byteOffset = (0, loader_utils_1.copyBinaryToDataView)(dataView, byteOffset, gltfEncoded, gltfEncoded.byteLength);
41
- }
42
- // Go "back" and rewrite the tile's `byteLength` now that we know the value
43
- (0, encode_3d_tile_header_1.encode3DTileByteLength)(dataView, byteOffsetStart, byteOffset - byteOffsetStart);
44
- return byteOffset;
45
- }
46
- exports.encodeBatchedModel3DTile = encodeBatchedModel3DTile;
@@ -1,24 +0,0 @@
1
- "use strict";
2
- // This file is derived from the Cesium code base under Apache 2 license
3
- // See LICENSE.md and https://github.com/AnalyticalGraphicsInc/cesium/blob/master/LICENSE.md
4
- Object.defineProperty(exports, "__esModule", { value: true });
5
- exports.encodeComposite3DTile = void 0;
6
- const constants_1 = require("../constants");
7
- const encode_3d_tile_header_1 = require("./helpers/encode-3d-tile-header");
8
- function encodeComposite3DTile(tile, dataView, byteOffset, options, encode3DTile) {
9
- // Add default magic for this tile type
10
- tile = { magic: constants_1.MAGIC_ARRAY.COMPOSITE, tiles: [], ...tile };
11
- const byteOffsetStart = byteOffset;
12
- byteOffset += (0, encode_3d_tile_header_1.encode3DTileHeader)(tile, dataView, byteOffset);
13
- if (dataView) {
14
- dataView.setUint32(byteOffset, tile.tiles.length, true); // tilesLength
15
- }
16
- byteOffset += 4;
17
- for (let i = 0; i < tile.tiles.length; ++i) {
18
- byteOffset += encode3DTile(tile.tiles[i], dataView, byteOffset, options);
19
- }
20
- // Go "back" and rewrite the tile's `byteLength` now that we know the value
21
- (0, encode_3d_tile_header_1.encode3DTileByteLength)(dataView, byteOffsetStart, byteOffset - byteOffsetStart);
22
- return byteOffset;
23
- }
24
- exports.encodeComposite3DTile = encodeComposite3DTile;
@@ -1,38 +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.encodeInstancedModel3DTile = void 0;
6
- const loader_utils_1 = require("@loaders.gl/loader-utils");
7
- const constants_1 = require("../constants");
8
- const encode_3d_tile_header_1 = require("./helpers/encode-3d-tile-header");
9
- // Procedurally encode the tile array buffer for testing purposes
10
- // eslint-disable-next-line max-statements
11
- function encodeInstancedModel3DTile(tile, dataView, byteOffset, options) {
12
- const { featuresLength = 1, gltfFormat = 1, gltfUri = '' } = tile;
13
- const gltfUriByteLength = gltfUri.length;
14
- const featureTableJson = {
15
- INSTANCES_LENGTH: featuresLength,
16
- POSITION: new Array(featuresLength * 3).fill(0)
17
- };
18
- const featureTableJsonString = JSON.stringify(featureTableJson);
19
- const featureTableJsonByteLength = featureTableJsonString.length;
20
- // Add default magic for this tile type
21
- tile = { magic: constants_1.MAGIC_ARRAY.INSTANCED_MODEL, ...tile };
22
- const byteOffsetStart = byteOffset;
23
- byteOffset = (0, encode_3d_tile_header_1.encode3DTileHeader)(tile, dataView, 0);
24
- if (dataView) {
25
- dataView.setUint32(12, featureTableJsonByteLength, true); // featureTableJsonByteLength
26
- dataView.setUint32(16, 0, true); // featureTableBinaryByteLength
27
- dataView.setUint32(20, 0, true); // batchTableJsonByteLength
28
- dataView.setUint32(24, 0, true); // batchTableBinaryByteLength
29
- dataView.setUint32(28, gltfFormat, true); // gltfFormat
30
- }
31
- byteOffset += 20;
32
- byteOffset += (0, loader_utils_1.copyStringToDataView)(dataView, byteOffset, featureTableJsonString, featureTableJsonByteLength);
33
- byteOffset += (0, loader_utils_1.copyStringToDataView)(dataView, byteOffset, gltfUri, gltfUriByteLength);
34
- // Go "back" and rewrite the tile's `byteLength` now that we know the value
35
- (0, encode_3d_tile_header_1.encode3DTileByteLength)(dataView, byteOffsetStart, byteOffset - byteOffsetStart);
36
- return byteOffset;
37
- }
38
- exports.encodeInstancedModel3DTile = encodeInstancedModel3DTile;
@@ -1,39 +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.encodePointCloud3DTile = void 0;
6
- const constants_1 = require("../constants");
7
- const encode_3d_tile_header_1 = require("./helpers/encode-3d-tile-header");
8
- const loader_utils_1 = require("@loaders.gl/loader-utils");
9
- const DEFAULT_FEATURE_TABLE_JSON = {
10
- POINTS_LENGTH: 1,
11
- POSITIONS: {
12
- byteOffset: 0
13
- }
14
- };
15
- function encodePointCloud3DTile(tile, dataView, byteOffset, options) {
16
- const { featureTableJson = DEFAULT_FEATURE_TABLE_JSON } = tile;
17
- let featureTableJsonString = JSON.stringify(featureTableJson);
18
- featureTableJsonString = (0, loader_utils_1.padStringToByteAlignment)(featureTableJsonString, 4);
19
- const { featureTableJsonByteLength = featureTableJsonString.length } = tile;
20
- const featureTableBinary = new ArrayBuffer(12); // Enough space to hold 3 floats
21
- const featureTableBinaryByteLength = featureTableBinary.byteLength;
22
- // Add default magic for this tile type
23
- tile = { magic: constants_1.MAGIC_ARRAY.POINT_CLOUD, ...tile };
24
- const byteOffsetStart = byteOffset;
25
- byteOffset += (0, encode_3d_tile_header_1.encode3DTileHeader)(tile, dataView, 0);
26
- if (dataView) {
27
- dataView.setUint32(byteOffset + 0, featureTableJsonByteLength, true); // featureTableJsonByteLength
28
- dataView.setUint32(byteOffset + 4, featureTableBinaryByteLength, true); // featureTableBinaryByteLength
29
- dataView.setUint32(byteOffset + 8, 0, true); // batchTableJsonByteLength
30
- dataView.setUint32(byteOffset + 12, 0, true); // batchTableBinaryByteLength
31
- }
32
- byteOffset += 16;
33
- byteOffset += (0, loader_utils_1.copyStringToDataView)(dataView, byteOffset, featureTableJsonString, featureTableJsonByteLength);
34
- byteOffset += (0, loader_utils_1.copyBinaryToDataView)(dataView, byteOffset, featureTableBinary, featureTableBinaryByteLength);
35
- // Go "back" and rewrite the tile's `byteLength` now that we know the value
36
- (0, encode_3d_tile_header_1.encode3DTileByteLength)(dataView, byteOffsetStart, byteOffset - byteOffsetStart);
37
- return byteOffset;
38
- }
39
- exports.encodePointCloud3DTile = encodePointCloud3DTile;
@@ -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
- Object.defineProperty(exports, "__esModule", { value: true });
5
- const constants_1 = require("../constants");
6
- const loader_utils_1 = require("@loaders.gl/loader-utils");
7
- const encode_3d_tile_composite_1 = require("./encode-3d-tile-composite");
8
- const encode_3d_tile_batched_model_1 = require("./encode-3d-tile-batched-model");
9
- const encode_3d_tile_instanced_model_1 = require("./encode-3d-tile-instanced-model");
10
- const encode_3d_tile_point_cloud_1 = require("./encode-3d-tile-point-cloud");
11
- function encode3DTile(tile, options) {
12
- const byteLength = encode3DTileToDataView(tile, null, 0, options);
13
- const arrayBuffer = new ArrayBuffer(byteLength);
14
- const dataView = new DataView(arrayBuffer);
15
- encode3DTileToDataView(tile, dataView, 0, options);
16
- return arrayBuffer;
17
- }
18
- exports.default = encode3DTile;
19
- function encode3DTileToDataView(tile, dataView, byteOffset, options) {
20
- (0, loader_utils_1.assert)(typeof tile.type === 'string');
21
- switch (tile.type) {
22
- case constants_1.TILE3D_TYPE.COMPOSITE:
23
- return (0, encode_3d_tile_composite_1.encodeComposite3DTile)(tile, dataView, byteOffset, options, encode3DTileToDataView);
24
- case constants_1.TILE3D_TYPE.POINT_CLOUD:
25
- return (0, encode_3d_tile_point_cloud_1.encodePointCloud3DTile)(tile, dataView, byteOffset, options);
26
- case constants_1.TILE3D_TYPE.BATCHED_3D_MODEL:
27
- return (0, encode_3d_tile_batched_model_1.encodeBatchedModel3DTile)(tile, dataView, byteOffset, options);
28
- case constants_1.TILE3D_TYPE.INSTANCED_3D_MODEL:
29
- return (0, encode_3d_tile_instanced_model_1.encodeInstancedModel3DTile)(tile, dataView, byteOffset, options);
30
- default:
31
- throw new Error('3D Tiles: unknown tile type');
32
- }
33
- }
@@ -1,30 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.encode3DTileByteLength = exports.encode3DTileHeader = void 0;
4
- // HELPER ENCODERS
5
- const loader_utils_1 = require("@loaders.gl/loader-utils");
6
- function encode3DTileHeader(tile, dataView, byteOffset) {
7
- const HEADER_SIZE = 12;
8
- if (!dataView) {
9
- return byteOffset + HEADER_SIZE;
10
- }
11
- const { magic, version = 1, byteLength = 12 } = tile;
12
- (0, loader_utils_1.assert)(Array.isArray(magic) && Number.isFinite(version) && Number.isFinite(byteLength));
13
- dataView.setUint8(byteOffset + 0, magic[0]);
14
- dataView.setUint8(byteOffset + 1, magic[1]);
15
- dataView.setUint8(byteOffset + 2, magic[2]);
16
- dataView.setUint8(byteOffset + 3, magic[3]);
17
- dataView.setUint32(byteOffset + 4, version, true); // version
18
- dataView.setUint32(byteOffset + 8, byteLength, true); // byteLength
19
- byteOffset += HEADER_SIZE;
20
- return byteOffset;
21
- }
22
- exports.encode3DTileHeader = encode3DTileHeader;
23
- // Bytelength is sometimes only known at the end of writing a tile
24
- function encode3DTileByteLength(dataView, byteOffsetTileStart, byteLength) {
25
- if (!dataView) {
26
- return;
27
- }
28
- dataView.setUint32(byteOffsetTileStart + 8, byteLength, true); // byteLength
29
- }
30
- exports.encode3DTileByteLength = encode3DTileByteLength;
@@ -1,75 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Tiles3DArchiveFileSystem = void 0;
4
- const zip_1 = require("@loaders.gl/zip");
5
- const _3d_tiles_archive_archive_1 = require("../../3d-tiles-archive/3d-tiles-archive-archive");
6
- /**
7
- * FileSystem adapter for a 3tz (3D tiles archive format) file
8
- * Holds FileProvider object that provides random access to archived files.
9
- * The difference from ZipFileSystem is usage of `@3dtilesIndex1@` index file that increases
10
- * access speed to archived files
11
- * @see https://github.com/erikdahlstrom/3tz-specification/blob/master/Specification.md
12
- */
13
- class Tiles3DArchiveFileSystem extends zip_1.ZipFileSystem {
14
- /**
15
- * Constructor
16
- * @param file - instance of FileProvider or file path string
17
- */
18
- constructor(file) {
19
- super(file);
20
- }
21
- /**
22
- * Implementation of fetch against this file system.
23
- * It tries to take `@3dtilesIndex1@` file from the archive and use it
24
- * for faster access to archived files
25
- * @param filename - name of a file
26
- * @returns - Response with file data
27
- */
28
- async fetch(filename) {
29
- const fileProvider = await this.fileProvider;
30
- if (!fileProvider) {
31
- throw new Error('No data detected in the zip archive');
32
- }
33
- await this.parseHashFile();
34
- if (this.hashData) {
35
- const archive = new _3d_tiles_archive_archive_1.Tiles3DArchive(fileProvider, this.hashData);
36
- const fileData = await archive.getFile(filename);
37
- const response = new Response(fileData);
38
- Object.defineProperty(response, 'url', { value: `${this.fileName || ''}/${filename}` });
39
- return response;
40
- }
41
- return super.fetch(filename);
42
- }
43
- /**
44
- * Try to get and parse '@3dtilesIndex1@' file, that allows to get direct access
45
- * to files inside the archive
46
- * @returns void
47
- */
48
- async parseHashFile() {
49
- if (this.hashData !== undefined) {
50
- return;
51
- }
52
- const fileProvider = await this.fileProvider;
53
- if (!fileProvider) {
54
- throw new Error('No data detected in the zip archive');
55
- }
56
- const hashCDOffset = await (0, zip_1.searchFromTheEnd)(fileProvider, zip_1.cdSignature);
57
- const cdFileHeader = await (0, zip_1.parseZipCDFileHeader)(hashCDOffset, fileProvider);
58
- // '@3dtilesIndex1@' is index file that must be the last in the archive. It allows
59
- // to improve load and read performance when the archive contains a very large number
60
- // of files.
61
- if (cdFileHeader?.fileName === '@3dtilesIndex1@') {
62
- const localFileHeader = await (0, zip_1.parseZipLocalFileHeader)(cdFileHeader.localHeaderOffset, fileProvider);
63
- if (!localFileHeader) {
64
- throw new Error('corrupted 3tz');
65
- }
66
- const fileDataOffset = localFileHeader.fileDataOffset;
67
- const hashFile = await fileProvider.slice(fileDataOffset, fileDataOffset + localFileHeader.compressedSize);
68
- this.hashData = (0, zip_1.parseHashFile)(hashFile);
69
- }
70
- else {
71
- this.hashData = null;
72
- }
73
- }
74
- }
75
- exports.Tiles3DArchiveFileSystem = Tiles3DArchiveFileSystem;