@loaders.gl/gltf 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 (85) hide show
  1. package/dist/dist.min.js +148 -102
  2. package/dist/es5/lib/extensions/EXT_mesh_features.js +3 -3
  3. package/dist/es5/lib/extensions/EXT_mesh_features.js.map +1 -1
  4. package/dist/es5/lib/extensions/EXT_structural_metadata.js +88 -86
  5. package/dist/es5/lib/extensions/EXT_structural_metadata.js.map +1 -1
  6. package/dist/es5/lib/extensions/deprecated/EXT_feature_metadata.js +26 -13
  7. package/dist/es5/lib/extensions/deprecated/EXT_feature_metadata.js.map +1 -1
  8. package/dist/es5/lib/extensions/{data-processing.js → utils/3d-tiles-utils.js} +25 -6
  9. package/dist/es5/lib/extensions/utils/3d-tiles-utils.js.map +1 -0
  10. package/dist/es5/lib/types/gltf-ext-structural-metadata-schema.js.map +1 -1
  11. package/dist/es5/lib/types/gltf-json-schema.js.map +1 -1
  12. package/dist/es5/lib/utils/version.js +1 -1
  13. package/dist/esm/lib/extensions/EXT_mesh_features.js +1 -1
  14. package/dist/esm/lib/extensions/EXT_mesh_features.js.map +1 -1
  15. package/dist/esm/lib/extensions/EXT_structural_metadata.js +85 -81
  16. package/dist/esm/lib/extensions/EXT_structural_metadata.js.map +1 -1
  17. package/dist/esm/lib/extensions/deprecated/EXT_feature_metadata.js +26 -13
  18. package/dist/esm/lib/extensions/deprecated/EXT_feature_metadata.js.map +1 -1
  19. package/dist/esm/lib/extensions/{data-processing.js → utils/3d-tiles-utils.js} +24 -6
  20. package/dist/esm/lib/extensions/utils/3d-tiles-utils.js.map +1 -0
  21. package/dist/esm/lib/types/gltf-ext-structural-metadata-schema.js.map +1 -1
  22. package/dist/esm/lib/types/gltf-json-schema.js.map +1 -1
  23. package/dist/esm/lib/utils/version.js +1 -1
  24. package/dist/lib/extensions/EXT_structural_metadata.d.ts +3 -3
  25. package/dist/lib/extensions/EXT_structural_metadata.d.ts.map +1 -1
  26. package/dist/lib/extensions/deprecated/EXT_feature_metadata.d.ts.map +1 -1
  27. package/dist/lib/extensions/utils/3d-tiles-utils.d.ts +52 -0
  28. package/dist/lib/extensions/utils/3d-tiles-utils.d.ts.map +1 -0
  29. package/dist/lib/types/gltf-ext-structural-metadata-schema.d.ts +4 -4
  30. package/dist/lib/types/gltf-ext-structural-metadata-schema.d.ts.map +1 -1
  31. package/dist/lib/types/gltf-json-schema.d.ts +1 -1
  32. package/dist/lib/types/gltf-json-schema.d.ts.map +1 -1
  33. package/package.json +6 -6
  34. package/src/lib/extensions/EXT_mesh_features.ts +1 -1
  35. package/src/lib/extensions/EXT_structural_metadata.ts +267 -200
  36. package/src/lib/extensions/deprecated/EXT_feature_metadata.ts +123 -19
  37. package/src/lib/extensions/{data-processing.ts → utils/3d-tiles-utils.ts} +95 -34
  38. package/src/lib/types/gltf-ext-structural-metadata-schema.ts +6 -4
  39. package/src/lib/types/gltf-json-schema.ts +1 -1
  40. package/dist/bundle.js +0 -5
  41. package/dist/es5/lib/extensions/data-processing.js.map +0 -1
  42. package/dist/esm/lib/extensions/data-processing.js.map +0 -1
  43. package/dist/glb-loader.js +0 -34
  44. package/dist/glb-writer.js +0 -35
  45. package/dist/gltf-loader.js +0 -50
  46. package/dist/gltf-writer.js +0 -32
  47. package/dist/index.js +0 -34
  48. package/dist/lib/api/gltf-extensions.js +0 -88
  49. package/dist/lib/api/gltf-scenegraph.js +0 -580
  50. package/dist/lib/api/normalize-gltf-v1.js +0 -299
  51. package/dist/lib/api/post-process-gltf.js +0 -433
  52. package/dist/lib/encoders/encode-glb.js +0 -72
  53. package/dist/lib/encoders/encode-gltf.js +0 -32
  54. package/dist/lib/extensions/EXT_mesh_features.js +0 -89
  55. package/dist/lib/extensions/EXT_meshopt_compression.js +0 -41
  56. package/dist/lib/extensions/EXT_structural_metadata.js +0 -504
  57. package/dist/lib/extensions/EXT_texture_webp.js +0 -36
  58. package/dist/lib/extensions/KHR_binary_gltf.js +0 -39
  59. package/dist/lib/extensions/KHR_draco_mesh_compression.js +0 -137
  60. package/dist/lib/extensions/KHR_texture_basisu.js +0 -29
  61. package/dist/lib/extensions/KHR_texture_transform.js +0 -227
  62. package/dist/lib/extensions/data-processing.d.ts +0 -34
  63. package/dist/lib/extensions/data-processing.d.ts.map +0 -1
  64. package/dist/lib/extensions/data-processing.js +0 -212
  65. package/dist/lib/extensions/deprecated/EXT_feature_metadata.js +0 -282
  66. package/dist/lib/extensions/deprecated/KHR_lights_punctual.js +0 -59
  67. package/dist/lib/extensions/deprecated/KHR_materials_unlit.js +0 -44
  68. package/dist/lib/extensions/deprecated/KHR_techniques_webgl.js +0 -79
  69. package/dist/lib/gltf-utils/get-typed-array.js +0 -41
  70. package/dist/lib/gltf-utils/gltf-attribute-utils.js +0 -73
  71. package/dist/lib/gltf-utils/gltf-constants.js +0 -43
  72. package/dist/lib/gltf-utils/gltf-utils.js +0 -90
  73. package/dist/lib/gltf-utils/resolve-url.js +0 -18
  74. package/dist/lib/parsers/parse-glb.js +0 -166
  75. package/dist/lib/parsers/parse-gltf.js +0 -185
  76. package/dist/lib/types/glb-types.js +0 -2
  77. package/dist/lib/types/gltf-ext-mesh-features-schema.js +0 -2
  78. package/dist/lib/types/gltf-ext-structural-metadata-schema.js +0 -2
  79. package/dist/lib/types/gltf-json-schema.js +0 -4
  80. package/dist/lib/types/gltf-postprocessed-schema.js +0 -4
  81. package/dist/lib/types/gltf-types.js +0 -3
  82. package/dist/lib/utils/assert.js +0 -12
  83. package/dist/lib/utils/version.js +0 -7
  84. package/dist/meshopt/meshopt-decoder.js +0 -118
  85. package/dist/webp/webp.js +0 -38
@@ -1,504 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getPropertyTablePopulated = exports.decode = exports.name = void 0;
4
- const gltf_scenegraph_1 = require("../api/gltf-scenegraph");
5
- const data_processing_1 = require("./data-processing");
6
- const EXT_STRUCTURAL_METADATA_NAME = 'EXT_structural_metadata';
7
- exports.name = EXT_STRUCTURAL_METADATA_NAME;
8
- async function decode(gltfData, options) {
9
- const scenegraph = new gltf_scenegraph_1.GLTFScenegraph(gltfData);
10
- decodeExtStructuralMetadata(scenegraph, options);
11
- }
12
- exports.decode = decode;
13
- /*
14
- // Example of the extension.
15
- // See more info at https://github.com/CesiumGS/glTF/tree/3d-tiles-next/extensions/2.0/Vendor/EXT_structural_metadata
16
- const extensions = {
17
- "extensions": {
18
- "EXT_structural_metadata": {
19
- "schema": {
20
- "classes": {
21
- "tree": {
22
- "name": "Tree",
23
- "description": "Woody, perennial plant.",
24
- "properties": {
25
- "species": {
26
- "description": "Type of tree.",
27
- "type": "ENUM",
28
- "enumType": "speciesEnum",
29
- "required": true
30
- },
31
- "age": {
32
- "description": "The age of the tree, in years",
33
- "type": "SCALAR",
34
- "componentType": "UINT8",
35
- "required": true
36
- }
37
- }
38
- }
39
- },
40
- "enums": {
41
- "speciesEnum": {
42
- "name": "Species",
43
- "description": "An example enum for tree species.",
44
- // valueType is not defined here. Default is "UINT16"
45
- "values": [
46
- { "name": "Unspecified", "value": 0 },
47
- { "name": "Oak", "value": 1 }
48
- ]
49
- }
50
- }
51
- },
52
- "propertyTables": [{
53
- "name": "tree_survey_2021-09-29",
54
- "class": "tree",
55
- "count": 10, // The number of elements in each property array (in `species`, in `age`).
56
- "properties": {
57
- "species": {
58
- "values": 0, // It's an index of the buffer view containing property values.
59
- },
60
- "age": {
61
- "values": 1
62
- }
63
- }
64
- }]
65
- }
66
- }
67
- }
68
- */
69
- /**
70
- * Returns the property table populated with the data taken according to the extension schema.
71
- * @param {GLTFScenegraph} scenegraph - Instance of the class for structured access to GLTF data.
72
- * @param {number} propertyTableIndex - Index of the property table to locate.
73
- * @returns {GLTF_EXT_structural_metadata_PropertyTable} Property table populated with the data.
74
- * Throws an exception if no property table was found for propertyTableIndex provided.
75
- */
76
- function getPropertyTablePopulated(scenegraph, propertyTableIndex) {
77
- const extension = scenegraph.getExtension(EXT_STRUCTURAL_METADATA_NAME);
78
- const propertyTable = extension?.propertyTables?.[propertyTableIndex];
79
- if (extension?.schema && propertyTable) {
80
- processPropertyTable(scenegraph, extension.schema, propertyTable);
81
- return propertyTable;
82
- }
83
- throw new Error(`Incorrect data in the EXT_structural_metadata extension: no property table with index ${propertyTableIndex}`);
84
- }
85
- exports.getPropertyTablePopulated = getPropertyTablePopulated;
86
- /**
87
- * Decodes feature metadata from extension
88
- * @param {GLTFScenegraph} scenegraph - Instance of the class for structured access to GLTF data.
89
- * @param {GLTFLoaderOptions} options - loader options.
90
- */
91
- function decodeExtStructuralMetadata(scenegraph, options) {
92
- const extension = scenegraph.getExtension(EXT_STRUCTURAL_METADATA_NAME);
93
- if (!extension?.schema) {
94
- return;
95
- }
96
- const propertyTextures = extension.propertyTextures;
97
- const json = scenegraph.gltf.json;
98
- if (propertyTextures && json.meshes && options?.gltf?.loadImages) {
99
- // Iterate through all meshes/primitives.
100
- for (const mesh of json.meshes) {
101
- for (const primitive of mesh.primitives) {
102
- processPrimitivePropertyTextures(scenegraph, propertyTextures, primitive, extension);
103
- }
104
- }
105
- }
106
- const schemaClasses = extension.schema.classes;
107
- const propertyTables = extension.propertyTables;
108
- if (schemaClasses && propertyTables) {
109
- for (const schemaName in schemaClasses) {
110
- const propertyTable = findPropertyTableByClass(propertyTables, schemaName);
111
- if (propertyTable) {
112
- processPropertyTable(scenegraph, extension.schema, propertyTable);
113
- }
114
- }
115
- }
116
- }
117
- /**
118
- * Takes data from property textures reffered by the primitive
119
- * @param {GLTFScenegraph} scenegraph - Instance of the class for structured access to GLTF data.
120
- * @param {GLTF_EXT_structural_metadata_PropertyTexture[]} propertyTextures - propertyTexture definition taken from the top-level extention
121
- * @param {GLTFMeshPrimitive} primitive - Primitive object
122
- * @param {GLTF_EXT_structural_metadata} extension - top-level extension
123
- */
124
- function processPrimitivePropertyTextures(scenegraph, propertyTextures, primitive, extension) {
125
- if (!propertyTextures) {
126
- return;
127
- }
128
- const primitiveExtension = primitive.extensions?.[EXT_STRUCTURAL_METADATA_NAME];
129
- const primitivePropertyTextureIndices = primitiveExtension?.propertyTextures;
130
- if (!primitivePropertyTextureIndices) {
131
- return;
132
- }
133
- for (const primitivePropertyTextureIndex of primitivePropertyTextureIndices) {
134
- const propertyTexture = propertyTextures[primitivePropertyTextureIndex];
135
- processPrimitivePropertyTexture(scenegraph, propertyTexture, primitive, extension);
136
- }
137
- }
138
- /**
139
- * Takes property data from the texture pointed by the primitive and appends them to `exension.data`
140
- * @param {GLTFScenegraph} scenegraph - Instance of the class for structured access to GLTF data.
141
- * @param {GLTF_EXT_structural_metadata_PropertyTexture} propertyTexture - propertyTexture definition taken from the top-level extension.
142
- * @param {GLTFMeshPrimitive} primitive - Primitive object
143
- * @param {GLTF_EXT_structural_metadata} extension - top-level extension
144
- */
145
- function processPrimitivePropertyTexture(scenegraph, propertyTexture, primitive, extension) {
146
- if (!propertyTexture.properties) {
147
- return;
148
- }
149
- if (!extension.dataAttributeNames) {
150
- extension.dataAttributeNames = [];
151
- }
152
- /* Iterate through all properties defined in propertyTexture, e.g. "speed" and "direction":
153
- {
154
- "class": "wind",
155
- "properties": {
156
- "speed": {
157
- "index": 0,
158
- "texCoord": 0,
159
- "channels": [0]
160
- },
161
- "direction": {
162
- "index": 0,
163
- "texCoord": 0,
164
- "channels": [1, 2]
165
- }
166
- }
167
- }
168
- */
169
- const className = propertyTexture.class;
170
- for (const propName in propertyTexture.properties) {
171
- // propName has values like "speed", "direction"
172
- // Make attributeName as a combination of the class name and the propertyName like "wind_speed" or "wind_direction"
173
- const attributeName = `${className}_${propName}`;
174
- const textureInfoTopLevel = propertyTexture.properties?.[propName];
175
- if (!textureInfoTopLevel) {
176
- // eslint-disable-next-line no-continue
177
- continue;
178
- }
179
- // The data taken from all meshes/primitives (the same property, e.g. "speed" or "direction") will be combined into one array and saved in textureInfoTopLevel.data
180
- // Initially textureInfoTopLevel.data will be initialized with an empty array.
181
- if (!textureInfoTopLevel.data) {
182
- textureInfoTopLevel.data = [];
183
- }
184
- const featureTextureTable = textureInfoTopLevel.data;
185
- const propertyData = (0, data_processing_1.getPrimitiveTextureData)(scenegraph, textureInfoTopLevel, primitive);
186
- if (propertyData === null) {
187
- // eslint-disable-next-line no-continue
188
- continue;
189
- }
190
- (0, data_processing_1.primitivePropertyDataToAttributes)(scenegraph, attributeName, propertyData, featureTextureTable, primitive);
191
- textureInfoTopLevel.data = featureTextureTable;
192
- extension.dataAttributeNames.push(attributeName);
193
- }
194
- }
195
- /**
196
- * Navigates through all properies in the property table, gets properties data,
197
- * and put the data to `propertyTable.data` as an array.
198
- * @param {GLTFScenegraph} scenegraph - Instance of the class for structured access to GLTF data.
199
- * @param {GLTF_EXT_structural_metadata_Schema} schema - schema object
200
- * @param {GLTF_EXT_structural_metadata_PropertyTable} propertyTable - propertyTable definition taken from the top-level extension
201
- */
202
- function processPropertyTable(scenegraph, schema, propertyTable) {
203
- const schemaClass = schema.classes?.[propertyTable.class];
204
- if (!schemaClass) {
205
- throw new Error(`Incorrect data in the EXT_structural_metadata extension: no schema class with name ${propertyTable.class}`);
206
- }
207
- const numberOfElements = propertyTable.count; // `propertyTable.count` is a number of elements in each property array.
208
- for (const propertyName in schemaClass.properties) {
209
- const classProperty = schemaClass.properties[propertyName];
210
- const propertyTableProperty = propertyTable.properties?.[propertyName];
211
- if (propertyTableProperty) {
212
- // Getting all elements (`numberOfElements`) of the array in the `propertyTableProperty`
213
- const data = getPropertyDataFromBinarySource(scenegraph, schema, classProperty, numberOfElements, propertyTableProperty);
214
- propertyTableProperty.data = data;
215
- }
216
- }
217
- }
218
- /**
219
- * Decodes properties from binary sourse based on property type.
220
- * @param {GLTFScenegraph} scenegraph - Instance of the class for structured access to GLTF data.
221
- * @param {GLTF_EXT_structural_metadata_Schema} schema - Schema object
222
- * @param {GLTF_EXT_structural_metadata_ClassProperty} classProperty - class property object
223
- * @param {GLTF_EXT_structural_metadata_PropertyTable_Property} propertyTableProperty
224
- * @param {number} numberOfElements - The number of elements in each property array that propertyTableProperty contains. It's a number of rows in the table.
225
- * @returns {string[] | number[] | string[][] | number[][]}
226
- */
227
- /* eslint complexity: ["error", 17]*/
228
- function getPropertyDataFromBinarySource(scenegraph, schema, classProperty, numberOfElements, propertyTableProperty) {
229
- let data = [];
230
- const valuesBufferView = propertyTableProperty.values;
231
- const valuesDataBytes = scenegraph.getTypedArrayForBufferView(valuesBufferView);
232
- let arrayOffsets = null;
233
- if (classProperty.array &&
234
- // `count` is a number of array elements. May only be defined when `array` is true.
235
- typeof classProperty.count === 'undefined' && // If `count` is NOT defined, it's a VARIABLE-length array
236
- typeof propertyTableProperty.arrayOffsets !== 'undefined' && // `arrayOffsets` is an index of the buffer view containing offsets for variable-length arrays.
237
- typeof propertyTableProperty.arrayOffsetType !== 'undefined') {
238
- // Data are in a VARIABLE-length array
239
- arrayOffsets = getOffsetArray(scenegraph, propertyTableProperty.arrayOffsets, propertyTableProperty.arrayOffsetType, numberOfElements);
240
- }
241
- let stringOffsets = null;
242
- if (typeof propertyTableProperty.stringOffsets !== 'undefined' && // `stringOffsets` is an index of the buffer view containing offsets for strings.
243
- typeof propertyTableProperty.stringOffsetType !== 'undefined') {
244
- // Data are in a FIXED-length array
245
- stringOffsets = getOffsetArray(scenegraph, propertyTableProperty.stringOffsets, propertyTableProperty.stringOffsetType, numberOfElements);
246
- }
247
- switch (classProperty.type) {
248
- case 'SCALAR':
249
- case 'VEC2':
250
- case 'VEC3':
251
- case 'VEC4':
252
- case 'MAT2':
253
- case 'MAT3':
254
- case 'MAT4': {
255
- data = getPropertyDataNumeric(classProperty, numberOfElements, valuesDataBytes, arrayOffsets);
256
- break;
257
- }
258
- case 'BOOLEAN': {
259
- // TODO: implement it as soon as we have the corresponding tileset
260
- throw new Error(`Not implemented - classProperty.type=${classProperty.type}`);
261
- }
262
- case 'STRING': {
263
- data = getPropertyDataString(classProperty, numberOfElements, valuesDataBytes, arrayOffsets, stringOffsets);
264
- break;
265
- }
266
- case 'ENUM': {
267
- data = getPropertyDataENUM(schema, classProperty, numberOfElements, valuesDataBytes, arrayOffsets);
268
- break;
269
- }
270
- default:
271
- throw new Error(`Unknown classProperty type ${classProperty.type}`);
272
- }
273
- return data;
274
- }
275
- /**
276
- * Gets offset array from `arrayOffsets` or `stringOffsets`.
277
- * @param {GLTFScenegraph} scenegraph - Instance of the class for structured access to GLTF data.
278
- * @param {number} offsets - Buffer view index
279
- * @param offsetType - The type of values in `arrayOffsets` or `stringOffsets`.
280
- * @param {number} numberOfElements - The number of elements in each property array.
281
- * @returns {TypedArray}
282
- */
283
- function getOffsetArray(scenegraph, offsets, offsetType, numberOfElements) {
284
- const arrayOffsetsBufferView = offsets;
285
- const arrayOffsetsBytes = scenegraph.getTypedArrayForBufferView(arrayOffsetsBufferView);
286
- const arrayOffsets = (0, data_processing_1.convertRawBufferToMetadataArray)(arrayOffsetsBytes, 'SCALAR', // offsets consist of ONE component
287
- offsetType, numberOfElements + 1 // The number of offsets is equal to the property table `count` plus one.
288
- );
289
- return arrayOffsets;
290
- }
291
- /**
292
- * Decodes properties of SCALAR, VEC-N, MAT-N types from binary sourse.
293
- * @param {GLTF_EXT_structural_metadata_ClassProperty} classProperty - class property object
294
- * @param {number} numberOfElements - The number of elements in each property array that propertyTableProperty contains. It's a number of rows in the table.
295
- * @param {Uint8Array} valuesDataBytes - data taken from values property of the property table property.
296
- * @param {TypedArray | null} arrayOffsets - offsets for variable-length arrays. It's null for fixed-length arrays or scalar types.
297
- * @returns {number[] | number[][]}
298
- */
299
- function getPropertyDataNumeric(classProperty, numberOfElements, valuesDataBytes, arrayOffsets) {
300
- const isArray = classProperty.array;
301
- const arrayCount = classProperty.count;
302
- const elementSize = (0, data_processing_1.getArrayElementByteSize)(classProperty.type, classProperty.componentType);
303
- const elementCount = valuesDataBytes.byteLength / elementSize;
304
- let valuesData;
305
- if (classProperty.componentType) {
306
- valuesData = (0, data_processing_1.convertRawBufferToMetadataArray)(valuesDataBytes, classProperty.type, classProperty.componentType, // The datatype of the element's components. Only applicable to `SCALAR`, `VECN`, and `MATN` types.
307
- elementCount);
308
- }
309
- else {
310
- // The spec doesn't provide any info what to do if componentType is not set.
311
- valuesData = valuesDataBytes;
312
- }
313
- if (isArray) {
314
- if (arrayOffsets) {
315
- // VARIABLE-length array
316
- return handleVariableLengthArrayNumeric(valuesData, numberOfElements, arrayOffsets, valuesDataBytes.length, elementSize);
317
- }
318
- if (arrayCount) {
319
- // FIXED-length array
320
- return handleFixedLengthArrayNumeric(valuesData, numberOfElements, arrayCount);
321
- }
322
- return [];
323
- }
324
- // Single value (not an array)
325
- const attributeValueArray = [];
326
- for (let index = 0; index < numberOfElements; index++) {
327
- const value = valuesData[index];
328
- attributeValueArray.push(value);
329
- }
330
- return attributeValueArray;
331
- }
332
- function handleVariableLengthArrayNumeric(valuesData, numberOfElements, arrayOffsets, valuesDataBytesLength, elementSize) {
333
- const attributeValueArray = [];
334
- for (let index = 0; index < numberOfElements; index++) {
335
- const array = [];
336
- const arrayOffset = arrayOffsets[index];
337
- const arrayByteSize = arrayOffsets[index + 1] - arrayOffsets[index];
338
- if (arrayByteSize + arrayOffset <= valuesDataBytesLength) {
339
- const typedArrayOffset = arrayOffset / elementSize;
340
- const elementCount = arrayByteSize / elementSize;
341
- for (let i = 0; i < elementCount; i++) {
342
- const value = valuesData[typedArrayOffset + i];
343
- array.push(value);
344
- }
345
- }
346
- attributeValueArray.push(array);
347
- }
348
- return attributeValueArray;
349
- }
350
- function handleFixedLengthArrayNumeric(valuesData, numberOfElements, arrayCount) {
351
- const attributeValueArray = [];
352
- for (let index = 0; index < numberOfElements; index++) {
353
- const array = [];
354
- for (let i = 0; i < arrayCount; i++) {
355
- const value = valuesData[i];
356
- array.push(value);
357
- }
358
- attributeValueArray.push(array);
359
- }
360
- return attributeValueArray;
361
- }
362
- /**
363
- * Decodes properties of string type from binary sourse.
364
- * @param {GLTF_EXT_structural_metadata_ClassProperty} classProperty - class property object
365
- * @param {number} numberOfElements - The number of elements in each property array that propertyTableProperty contains. It's a number of rows in the table.
366
- * @param {Uint8Array} valuesDataBytes - data taken from values property of the property table property.
367
- * @param {TypedArray | null} arrayOffsets - offsets for variable-length arrays. It's null for fixed-length arrays or scalar types.
368
- * @param {TypedArray | null} stringOffsets - index of the buffer view containing offsets for strings. It should be available for string type.
369
- * @returns {string[] | string[][]}
370
- */
371
- function getPropertyDataString(classProperty, numberOfElements, valuesDataBytes, arrayOffsets, stringOffsets) {
372
- if (arrayOffsets) {
373
- // TODO: implement it as soon as we have the corresponding tileset
374
- throw new Error(`Not implemented - classProperty.type=${classProperty.type}`);
375
- }
376
- if (stringOffsets) {
377
- const stringsArray = [];
378
- const textDecoder = new TextDecoder('utf8');
379
- let stringOffset = 0;
380
- for (let index = 0; index < numberOfElements; index++) {
381
- const stringByteSize = stringOffsets[index + 1] - stringOffsets[index];
382
- if (stringByteSize + stringOffset <= valuesDataBytes.length) {
383
- const stringData = valuesDataBytes.subarray(stringOffset, stringByteSize + stringOffset);
384
- const stringAttribute = textDecoder.decode(stringData);
385
- stringsArray.push(stringAttribute);
386
- stringOffset += stringByteSize;
387
- }
388
- }
389
- return stringsArray;
390
- }
391
- return [];
392
- }
393
- /**
394
- * Decodes properties of enum type from binary sourse.
395
- * @param {GLTF_EXT_structural_metadata_Schema} schema - schema object
396
- * @param {GLTF_EXT_structural_metadata_ClassProperty} classProperty - class property object
397
- * @param {number} numberOfElements - The number of elements in each property array that propertyTableProperty contains. It's a number of rows in the table.
398
- * @param {Uint8Array} valuesDataBytes - data taken from values property of the property table property.
399
- * @param {TypedArray | null} arrayOffsets - offsets for variable-length arrays. It's null for fixed-length arrays or scalar types.
400
- * @returns {string[] | string[][]}
401
- */
402
- function getPropertyDataENUM(schema, classProperty, numberOfElements, valuesDataBytes, arrayOffsets) {
403
- const data = [];
404
- const isArray = classProperty.array;
405
- const arrayCount = classProperty.count;
406
- const enumType = classProperty.enumType;
407
- // Enum ID as declared in the `enums` dictionary. Required when `type` is `ENUM`.
408
- if (!enumType) {
409
- throw new Error('Incorrect data in the EXT_structural_metadata extension: classProperty.enumType is not set for type ENUM');
410
- }
411
- const enumEntry = schema.enums?.[enumType];
412
- if (!enumEntry) {
413
- throw new Error(`Incorrect data in the EXT_structural_metadata extension: schema.enums does't contain ${enumType}`);
414
- }
415
- const enumValueType = enumEntry.valueType || 'UINT16';
416
- const elementSize = (0, data_processing_1.getArrayElementByteSize)(classProperty.type, enumValueType);
417
- const elementCount = valuesDataBytes.byteLength / elementSize;
418
- const valuesData = (0, data_processing_1.convertRawBufferToMetadataArray)(valuesDataBytes, classProperty.type, enumValueType, elementCount);
419
- if (isArray) {
420
- if (arrayOffsets) {
421
- // VARIABLE-length array
422
- return handleVariableLengthArrayENUM(valuesData, numberOfElements, arrayOffsets, valuesDataBytes.length, elementSize, enumEntry);
423
- }
424
- if (arrayCount) {
425
- // FIXED-length array
426
- return handleFixedLengthArrayENUM(valuesData, numberOfElements, arrayCount, enumEntry);
427
- }
428
- return [];
429
- }
430
- // Single value (not an array)
431
- for (let index = 0; index < numberOfElements; index++) {
432
- const enumValue = valuesData[index];
433
- const enumObject = getEnumByValue(enumEntry, enumValue);
434
- if (enumObject) {
435
- data.push(enumObject.name);
436
- }
437
- }
438
- return data;
439
- }
440
- /* eslint max-params: ["error", 6]*/
441
- function handleVariableLengthArrayENUM(valuesData, numberOfElements, arrayOffsets, valuesDataBytesLength, elementSize, enumEntry) {
442
- const attributeValueArray = [];
443
- for (let index = 0; index < numberOfElements; index++) {
444
- const array = [];
445
- const arrayOffset = arrayOffsets[index];
446
- const arrayByteSize = arrayOffsets[index + 1] - arrayOffsets[index];
447
- if (arrayByteSize + arrayOffset <= valuesDataBytesLength) {
448
- const typedArrayOffset = arrayOffset / elementSize;
449
- const elementCount = arrayByteSize / elementSize;
450
- for (let i = 0; i < elementCount; i++) {
451
- const value = valuesData[typedArrayOffset + i];
452
- const enumObject = getEnumByValue(enumEntry, value);
453
- if (enumObject) {
454
- array.push(enumObject.name);
455
- }
456
- }
457
- }
458
- attributeValueArray.push(array);
459
- }
460
- return attributeValueArray;
461
- }
462
- function handleFixedLengthArrayENUM(valuesData, numberOfElements, arrayCount, enumEntry) {
463
- const attributeValueArray = [];
464
- for (let index = 0; index < numberOfElements; index++) {
465
- const array = [];
466
- for (let i = 0; i < arrayCount; i++) {
467
- const value = valuesData[i];
468
- const enumObject = getEnumByValue(enumEntry, value);
469
- if (enumObject) {
470
- array.push(enumObject.name);
471
- }
472
- }
473
- attributeValueArray.push(array);
474
- }
475
- return attributeValueArray;
476
- }
477
- /**
478
- * Find the property table by class name.
479
- * @param {GLTF_EXT_structural_metadata_PropertyTable[]} propertyTables
480
- * @param {string} schemaClassName
481
- */
482
- function findPropertyTableByClass(propertyTables, schemaClassName) {
483
- for (let i = 0, len = propertyTables.length; i < len; i++) {
484
- const propertyTable = propertyTables[i];
485
- if (propertyTable.class === schemaClassName) {
486
- return propertyTable;
487
- }
488
- }
489
- return null;
490
- }
491
- /**
492
- * Looks up ENUM whose `value` property matches the specified number in the parameter `value`.
493
- * @param {GLTF_EXT_structural_metadata_Enum} enumEntry - ENUM entry containing the array of possible enums.
494
- * @param {number} value - the value of the ENUM to locate.
495
- * @returns {GLTF_EXT_structural_metadata_EnumValue | null} ENUM matcihng the specified value or null of no ENUM object was found.
496
- */
497
- function getEnumByValue(enumEntry, value) {
498
- for (const enumValue of enumEntry.values) {
499
- if (enumValue.value === value) {
500
- return enumValue;
501
- }
502
- }
503
- return null;
504
- }
@@ -1,36 +0,0 @@
1
- "use strict";
2
- // GLTF EXTENSION: EXT_TEXTURE_WEBP
3
- // https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/EXT_TEXTURE_WEBP
4
- /* eslint-disable camelcase */
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.preprocess = exports.name = void 0;
7
- const images_1 = require("@loaders.gl/images");
8
- const gltf_scenegraph_1 = require("../api/gltf-scenegraph");
9
- const EXT_TEXTURE_WEBP = 'EXT_texture_webp';
10
- /** Extension name */
11
- exports.name = EXT_TEXTURE_WEBP;
12
- /**
13
- * Replaces a texture source reference with the extension texture
14
- * Done in preprocess() to prevent load of default image
15
- */
16
- function preprocess(gltfData, options) {
17
- const scenegraph = new gltf_scenegraph_1.GLTFScenegraph(gltfData);
18
- if (!(0, images_1.isImageFormatSupported)('image/webp')) {
19
- if (scenegraph.getRequiredExtensions().includes(EXT_TEXTURE_WEBP)) {
20
- throw new Error(`gltf: Required extension ${EXT_TEXTURE_WEBP} not supported by browser`);
21
- }
22
- return;
23
- }
24
- const { json } = scenegraph;
25
- for (const texture of json.textures || []) {
26
- const extension = scenegraph.getObjectExtension(texture, EXT_TEXTURE_WEBP);
27
- if (extension) {
28
- // TODO - if multiple texture extensions are present which one wins?
29
- texture.source = extension.source;
30
- }
31
- scenegraph.removeObjectExtension(texture, EXT_TEXTURE_WEBP);
32
- }
33
- // Remove the top-level extension
34
- scenegraph.removeExtension(EXT_TEXTURE_WEBP);
35
- }
36
- exports.preprocess = preprocess;
@@ -1,39 +0,0 @@
1
- "use strict";
2
- // GLTF 1.0 EXTENSION: KHR_binary_glTF
3
- // https://github.com/KhronosGroup/glTF/tree/master/extensions/1.0/Khronos/KHR_binary_glTF
4
- /* eslint-disable camelcase */
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.preprocess = exports.name = void 0;
7
- const gltf_scenegraph_1 = require("../api/gltf-scenegraph");
8
- const KHR_BINARY_GLTF = 'KHR_binary_glTF';
9
- /** Extension name */
10
- exports.name = KHR_BINARY_GLTF;
11
- function preprocess(gltfData) {
12
- const gltfScenegraph = new gltf_scenegraph_1.GLTFScenegraph(gltfData);
13
- const { json } = gltfScenegraph;
14
- // Note: json.buffers.binary_glTF also needs to be replaced
15
- // This is currently done during gltf normalization
16
- // Image and shader nodes can have the extension
17
- // https://github.com/KhronosGroup/glTF/blob/master/extensions/1.0/Khronos/KHR_binary_glTF/schema/image.KHR_binary_glTF.schema.json
18
- for (const image of json.images || []) {
19
- const extension = gltfScenegraph.getObjectExtension(image, KHR_BINARY_GLTF);
20
- // The data in the extension is valid as glTF 2.0 data inside the object, so just copy it in
21
- if (extension) {
22
- Object.assign(image, extension);
23
- }
24
- gltfScenegraph.removeObjectExtension(image, KHR_BINARY_GLTF);
25
- }
26
- // TODO shaders - At least traverse and throw error if used?
27
- // https://github.com/KhronosGroup/glTF/blob/master/extensions/1.0/Khronos/KHR_binary_glTF/schema/shader.KHR_binary_glTF.schema.json
28
- // glTF v1 one files have a partially formed URI field that is not expected in (and causes problems in) 2.0
29
- if (json.buffers && json.buffers[0]) {
30
- delete json.buffers[0].uri;
31
- }
32
- // Remove the top-level extension as it has now been processed
33
- gltfScenegraph.removeExtension(KHR_BINARY_GLTF);
34
- }
35
- exports.preprocess = preprocess;
36
- // KHR_binary_gltf is a 1.0 extension that is supported natively by 2.0
37
- // export function encode() {
38
- // throw new Error(KHR_BINARY_GLTF);
39
- // }