@loaders.gl/gltf 4.0.0-alpha.21 → 4.0.0-alpha.23

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 (86) hide show
  1. package/dist/dist.min.js +3587 -3026
  2. package/dist/es5/index.js +21 -0
  3. package/dist/es5/index.js.map +1 -1
  4. package/dist/es5/lib/api/gltf-extensions.js +3 -1
  5. package/dist/es5/lib/api/gltf-extensions.js.map +1 -1
  6. package/dist/es5/lib/extensions/EXT_mesh_features.js +111 -0
  7. package/dist/es5/lib/extensions/EXT_mesh_features.js.map +1 -0
  8. package/dist/es5/lib/extensions/EXT_structural_metadata.js +386 -0
  9. package/dist/es5/lib/extensions/EXT_structural_metadata.js.map +1 -0
  10. package/dist/es5/lib/extensions/KHR_draco_mesh_compression.js +6 -7
  11. package/dist/es5/lib/extensions/KHR_draco_mesh_compression.js.map +1 -1
  12. package/dist/es5/lib/extensions/data-processing.js +181 -0
  13. package/dist/es5/lib/extensions/data-processing.js.map +1 -0
  14. package/dist/es5/lib/extensions/deprecated/EXT_feature_metadata.js +6 -9
  15. package/dist/es5/lib/extensions/deprecated/EXT_feature_metadata.js.map +1 -1
  16. package/dist/es5/lib/parsers/parse-gltf.js +3 -3
  17. package/dist/es5/lib/parsers/parse-gltf.js.map +1 -1
  18. package/dist/es5/lib/types/gltf-ext-mesh-features-schema.js +2 -0
  19. package/dist/es5/lib/types/gltf-ext-mesh-features-schema.js.map +1 -0
  20. package/dist/es5/lib/types/gltf-ext-structural-metadata-schema.js +2 -0
  21. package/dist/es5/lib/types/gltf-ext-structural-metadata-schema.js.map +1 -0
  22. package/dist/es5/lib/types/gltf-json-schema.js.map +1 -1
  23. package/dist/es5/lib/utils/version.js +1 -1
  24. package/dist/esm/index.js +3 -0
  25. package/dist/esm/index.js.map +1 -1
  26. package/dist/esm/lib/api/gltf-extensions.js +3 -1
  27. package/dist/esm/lib/api/gltf-extensions.js.map +1 -1
  28. package/dist/esm/lib/extensions/EXT_mesh_features.js +55 -0
  29. package/dist/esm/lib/extensions/EXT_mesh_features.js.map +1 -0
  30. package/dist/esm/lib/extensions/EXT_structural_metadata.js +320 -0
  31. package/dist/esm/lib/extensions/EXT_structural_metadata.js.map +1 -0
  32. package/dist/esm/lib/extensions/KHR_draco_mesh_compression.js +2 -5
  33. package/dist/esm/lib/extensions/KHR_draco_mesh_compression.js.map +1 -1
  34. package/dist/esm/lib/extensions/data-processing.js +146 -0
  35. package/dist/esm/lib/extensions/data-processing.js.map +1 -0
  36. package/dist/esm/lib/extensions/deprecated/EXT_feature_metadata.js +4 -7
  37. package/dist/esm/lib/extensions/deprecated/EXT_feature_metadata.js.map +1 -1
  38. package/dist/esm/lib/parsers/parse-gltf.js +5 -6
  39. package/dist/esm/lib/parsers/parse-gltf.js.map +1 -1
  40. package/dist/esm/lib/types/gltf-ext-mesh-features-schema.js +2 -0
  41. package/dist/esm/lib/types/gltf-ext-mesh-features-schema.js.map +1 -0
  42. package/dist/esm/lib/types/gltf-ext-structural-metadata-schema.js +2 -0
  43. package/dist/esm/lib/types/gltf-ext-structural-metadata-schema.js.map +1 -0
  44. package/dist/esm/lib/types/gltf-json-schema.js.map +1 -1
  45. package/dist/esm/lib/utils/version.js +1 -1
  46. package/dist/index.d.ts +6 -1
  47. package/dist/index.d.ts.map +1 -1
  48. package/dist/index.js +7 -1
  49. package/dist/lib/api/gltf-extensions.d.ts.map +1 -1
  50. package/dist/lib/api/gltf-extensions.js +5 -0
  51. package/dist/lib/extensions/EXT_mesh_features.d.ts +7 -0
  52. package/dist/lib/extensions/EXT_mesh_features.d.ts.map +1 -0
  53. package/dist/lib/extensions/EXT_mesh_features.js +89 -0
  54. package/dist/lib/extensions/EXT_structural_metadata.d.ts +17 -0
  55. package/dist/lib/extensions/EXT_structural_metadata.d.ts.map +1 -0
  56. package/dist/lib/extensions/EXT_structural_metadata.js +504 -0
  57. package/dist/lib/extensions/KHR_draco_mesh_compression.d.ts +1 -1
  58. package/dist/lib/extensions/KHR_draco_mesh_compression.d.ts.map +1 -1
  59. package/dist/lib/extensions/KHR_draco_mesh_compression.js +2 -3
  60. package/dist/lib/extensions/data-processing.d.ts +34 -0
  61. package/dist/lib/extensions/data-processing.d.ts.map +1 -0
  62. package/dist/lib/extensions/data-processing.js +212 -0
  63. package/dist/lib/extensions/deprecated/EXT_feature_metadata.d.ts.map +1 -1
  64. package/dist/lib/extensions/deprecated/EXT_feature_metadata.js +8 -17
  65. package/dist/lib/parsers/parse-gltf.d.ts.map +1 -1
  66. package/dist/lib/parsers/parse-gltf.js +5 -3
  67. package/dist/lib/types/gltf-ext-mesh-features-schema.d.ts +45 -0
  68. package/dist/lib/types/gltf-ext-mesh-features-schema.d.ts.map +1 -0
  69. package/dist/lib/types/gltf-ext-mesh-features-schema.js +2 -0
  70. package/dist/lib/types/gltf-ext-structural-metadata-schema.d.ts +310 -0
  71. package/dist/lib/types/gltf-ext-structural-metadata-schema.d.ts.map +1 -0
  72. package/dist/lib/types/gltf-ext-structural-metadata-schema.js +2 -0
  73. package/dist/lib/types/gltf-json-schema.d.ts +11 -57
  74. package/dist/lib/types/gltf-json-schema.d.ts.map +1 -1
  75. package/package.json +6 -6
  76. package/src/index.ts +11 -3
  77. package/src/lib/api/gltf-extensions.ts +6 -2
  78. package/src/lib/extensions/EXT_mesh_features.ts +117 -0
  79. package/src/lib/extensions/EXT_structural_metadata.ts +730 -0
  80. package/src/lib/extensions/KHR_draco_mesh_compression.ts +7 -7
  81. package/src/lib/extensions/data-processing.ts +264 -0
  82. package/src/lib/extensions/deprecated/EXT_feature_metadata.ts +6 -17
  83. package/src/lib/parsers/parse-gltf.ts +9 -5
  84. package/src/lib/types/gltf-ext-mesh-features-schema.ts +48 -0
  85. package/src/lib/types/gltf-ext-structural-metadata-schema.ts +357 -0
  86. package/src/lib/types/gltf-json-schema.ts +12 -60
@@ -2,7 +2,12 @@
2
2
  // Only TRIANGLES: 0x0004 and TRIANGLE_STRIP: 0x0005 are supported
3
3
  /* eslint-disable camelcase */
4
4
 
5
- /* eslint-disable camelcase */
5
+ import type {LoaderContext} from '@loaders.gl/loader-utils';
6
+ import {sliceArrayBuffer, parseFromContext} from '@loaders.gl/loader-utils';
7
+
8
+ import {DracoLoader} from '@loaders.gl/draco';
9
+ import {DracoLoaderOptions} from '@loaders.gl/draco';
10
+
6
11
  import type {
7
12
  GLTF,
8
13
  GLTFAccessor,
@@ -11,10 +16,6 @@ import type {
11
16
  } from '../types/gltf-json-schema';
12
17
  import type {GLTFLoaderOptions} from '../../gltf-loader';
13
18
 
14
- import type {LoaderContext} from '@loaders.gl/loader-utils';
15
- import {DracoLoader} from '@loaders.gl/draco';
16
- import {DracoLoaderOptions, DracoMesh} from '@loaders.gl/draco';
17
- import {sliceArrayBuffer} from '@loaders.gl/loader-utils';
18
19
  import {GLTFScenegraph} from '../api/gltf-scenegraph';
19
20
  import {getGLTFAccessors, getGLTFAccessor} from '../gltf-utils/gltf-attribute-utils';
20
21
 
@@ -99,12 +100,11 @@ async function decompressPrimitive(
99
100
  // TODO - remove when `parse` is fixed to handle `byteOffset`s
100
101
  const bufferCopy = sliceArrayBuffer(buffer.buffer, buffer.byteOffset); // , buffer.byteLength);
101
102
 
102
- const {parse} = context;
103
103
  const dracoOptions: DracoLoaderOptions = {...options};
104
104
 
105
105
  // TODO - remove hack: The entire tileset might be included, too expensive to serialize
106
106
  delete dracoOptions['3d-tiles'];
107
- const decodedData = (await parse(bufferCopy, DracoLoader, dracoOptions, context)) as DracoMesh;
107
+ const decodedData = await parseFromContext(bufferCopy, DracoLoader, dracoOptions, context);
108
108
 
109
109
  const decodedAttributes: {[key: string]: GLTFAccessor} = getGLTFAccessors(decodedData.attributes);
110
110
 
@@ -0,0 +1,264 @@
1
+ import type {GLTFTextureInfoMetadata, GLTFMeshPrimitive} from '../types/gltf-json-schema';
2
+ import type {TypedArray} from '@loaders.gl/schema';
3
+ import type {ImageType} from '@loaders.gl/images';
4
+
5
+ import {GLTFScenegraph} from '../api/gltf-scenegraph';
6
+ import {getComponentTypeFromArray} from '../gltf-utils/gltf-utils';
7
+ import {getImageData} from '@loaders.gl/images';
8
+ import {emod} from '@loaders.gl/math';
9
+
10
+ const ATTRIBUTE_TYPE_TO_COMPONENTS = {
11
+ SCALAR: 1,
12
+ VEC2: 2,
13
+ VEC3: 3,
14
+ VEC4: 4,
15
+ MAT2: 4,
16
+ MAT3: 9,
17
+ MAT4: 16,
18
+ BOOLEAN: 1,
19
+ STRING: 1,
20
+ ENUM: 1
21
+ };
22
+
23
+ const ATTRIBUTE_COMPONENT_TYPE_TO_ARRAY = {
24
+ INT8: Int8Array,
25
+ UINT8: Uint8Array,
26
+ INT16: Int16Array,
27
+ UINT16: Uint16Array,
28
+ INT32: Int32Array,
29
+ UINT32: Uint32Array,
30
+ INT64: BigInt64Array,
31
+ UINT64: BigUint64Array,
32
+ FLOAT32: Float32Array,
33
+ FLOAT64: Float64Array
34
+ };
35
+
36
+ const ATTRIBUTE_COMPONENT_TYPE_TO_BYTE_SIZE = {
37
+ INT8: 1,
38
+ UINT8: 1,
39
+ INT16: 2,
40
+ UINT16: 2,
41
+ INT32: 4,
42
+ UINT32: 4,
43
+ INT64: 8,
44
+ UINT64: 8,
45
+ FLOAT32: 4,
46
+ FLOAT64: 8
47
+ };
48
+
49
+ export function getArrayElementByteSize(attributeType, componentType): number {
50
+ return (
51
+ ATTRIBUTE_COMPONENT_TYPE_TO_BYTE_SIZE[componentType] *
52
+ ATTRIBUTE_TYPE_TO_COMPONENTS[attributeType]
53
+ );
54
+ }
55
+
56
+ /**
57
+ * Converts raw bytes that are in the buffer to an array of the type defined by the schema.
58
+ * @param {Uint8Array} typedArray - raw bytes in the buffer
59
+ * @param {string} attributeType - SCALAR, VECN, MATN
60
+ * @param {string} componentType - type of the component in elements, e.g. 'UINT8' or 'FLOAT32'
61
+ * @param {number} elementCount - number of elements in the array. Default value is 1.
62
+ * @returns {TypedArray} Data array
63
+ */
64
+ export function convertRawBufferToMetadataArray(
65
+ typedArray: Uint8Array,
66
+ attributeType: string,
67
+ componentType: string,
68
+ elementCount: number = 1
69
+ ): TypedArray {
70
+ const numberOfComponents = ATTRIBUTE_TYPE_TO_COMPONENTS[attributeType];
71
+ const ArrayType = ATTRIBUTE_COMPONENT_TYPE_TO_ARRAY[componentType];
72
+ const length = elementCount * numberOfComponents;
73
+ const size = ATTRIBUTE_COMPONENT_TYPE_TO_BYTE_SIZE[componentType];
74
+ // the buffer view `byteOffset` must be aligned to a multiple of the `componentType` size.
75
+ const offset =
76
+ typedArray.byteOffset % size
77
+ ? Math.ceil(typedArray.byteOffset / size) * size
78
+ : typedArray.byteOffset;
79
+ return new ArrayType(typedArray.buffer, offset, length);
80
+ }
81
+
82
+ /**
83
+ * Processes data encoded in the texture associated with the primitive.
84
+ * If Ext_mesh_featues is combined with the Ext_structural_metadata, propertyTable will also be processed.
85
+ * @param {GLTFScenegraph} scenegraph - Instance of the class for structured access to GLTF data.
86
+ * @param {GLTFTextureInfoMetadata} textureInfo - reference to the texture where extension data are stored.
87
+ * @param {GLTFMeshPrimitive} primitive - primitive object in the mesh
88
+ * @returns {number[] | null} Array of data taken. Null if data can't be taken from the texture.
89
+ */
90
+ export function getPrimitiveTextureData(
91
+ scenegraph: GLTFScenegraph,
92
+ textureInfo: GLTFTextureInfoMetadata,
93
+ primitive: GLTFMeshPrimitive
94
+ ): number[] | null {
95
+ /*
96
+ texture.index is an index for the "textures" array.
97
+ The texture object referenced by this index looks like this:
98
+ {
99
+ "sampler": 0,
100
+ "source": 0
101
+ }
102
+ "sampler" is an index for the "samplers" array
103
+ "source" is an index for the "images" array that contains data. These data are stored in rgba channels of the image.
104
+
105
+ texture.texCoord is a number-suffix (like 1) for an attribute like "TEXCOORD_1" in meshes.primitives
106
+ The value of "TEXCOORD_1" is an accessor that is used to get coordinates. These coordinates are being used to get data from the image.
107
+ */
108
+ const json = scenegraph.gltf.json;
109
+
110
+ const texCoordAccessorKey = `TEXCOORD_${textureInfo.texCoord || 0}`;
111
+ const texCoordAccessorIndex = primitive.attributes[texCoordAccessorKey];
112
+ const texCoordBufferView = scenegraph.getBufferView(texCoordAccessorIndex);
113
+ const texCoordArray: Uint8Array = scenegraph.getTypedArrayForBufferView(texCoordBufferView);
114
+
115
+ // textureCoordinates array contains UV coordinates of the actual data stored in the texture
116
+ const textureCoordinates: Float32Array = new Float32Array(
117
+ texCoordArray.buffer,
118
+ texCoordArray.byteOffset,
119
+ texCoordArray.length / 4
120
+ );
121
+
122
+ const textureIndex: number = textureInfo.index;
123
+ const imageIndex = json.textures?.[textureIndex]?.source;
124
+ if (typeof imageIndex !== 'undefined') {
125
+ const mimeType = json.images?.[imageIndex]?.mimeType;
126
+ const parsedImage = scenegraph.gltf.images?.[imageIndex];
127
+ // Checking for width is to prevent handling Un-processed images (e.g. [analyze] stage, where loadImages option is set to false)
128
+ if (parsedImage && typeof parsedImage.width !== 'undefined') {
129
+ const textureData: number[] = [];
130
+ for (let index = 0; index < textureCoordinates.length; index += 2) {
131
+ const value = getImageValueByCoordinates(
132
+ parsedImage,
133
+ mimeType,
134
+ textureCoordinates,
135
+ index,
136
+ textureInfo.channels
137
+ );
138
+ textureData.push(value);
139
+ }
140
+ return textureData;
141
+ }
142
+ }
143
+ return null;
144
+ }
145
+
146
+ /**
147
+ * Puts property data to attributes.
148
+ * It creates corresponding buffer, bufferView and accessor
149
+ * so the data can be accessed like regular data stored in buffers.
150
+ * @param {GLTFScenegraph} scenegraph - scenegraph object
151
+ * @param {string} attributeName - name of the attribute
152
+ * @param {number[]} propertyData - property data to store
153
+ * @param {number[]} featureTable - an array where unique data from the property data are being stored
154
+ * @param {GLTFMeshPrimitive} primitive - primitive object
155
+ */
156
+ export function primitivePropertyDataToAttributes(
157
+ scenegraph: GLTFScenegraph,
158
+ attributeName: string,
159
+ propertyData: number[],
160
+ featureTable: number[],
161
+ primitive: GLTFMeshPrimitive
162
+ ): void {
163
+ if (propertyData === null) return;
164
+ /*
165
+ featureTable will contain unique values, e.g.
166
+ propertyData = [24, 35, 28, 24]
167
+ featureTable = [24, 35, 28]
168
+ featureIndices will contain indices that refer featureTextureTable, e.g.
169
+ featureIndices = [0, 1, 2, 0]
170
+ */
171
+ const featureIndices: number[] = [];
172
+ for (const texelData of propertyData) {
173
+ let index = featureTable.findIndex((item) => item === texelData);
174
+ if (index === -1) {
175
+ index = featureTable.push(texelData) - 1;
176
+ }
177
+ featureIndices.push(index);
178
+ }
179
+ const typedArray = new Uint32Array(featureIndices);
180
+ const bufferIndex =
181
+ scenegraph.gltf.buffers.push({
182
+ arrayBuffer: typedArray.buffer,
183
+ byteOffset: typedArray.byteOffset,
184
+ byteLength: typedArray.byteLength
185
+ }) - 1;
186
+ const bufferViewIndex = scenegraph.addBufferView(typedArray, bufferIndex, 0);
187
+ const accessorIndex = scenegraph.addAccessor(bufferViewIndex, {
188
+ size: 1,
189
+ componentType: getComponentTypeFromArray(typedArray),
190
+ count: typedArray.length
191
+ });
192
+ primitive.attributes[attributeName] = accessorIndex;
193
+ }
194
+
195
+ /**
196
+ * Gets the value from the texture by coordinates provided.
197
+ * @param {ImageType} parsedImage - image where the data are stored.
198
+ * @param {string | undefined} mimeType - MIME type
199
+ * @param {Float32Array} textureCoordinates - uv coordinates to access data in the image.
200
+ * @param {number} index - index of uv coordinates in the array textureCoordinates
201
+ * @param {channels} channels - image channels where data are stored. Channels of an RGBA texture are numbered 0..3 respectively.
202
+ * @returns {number} Value taken from the image.
203
+ */
204
+ function getImageValueByCoordinates(
205
+ parsedImage: ImageType,
206
+ mimeType: string | undefined,
207
+ textureCoordinates: Float32Array,
208
+ index: number,
209
+ channels: number[] = [0]
210
+ ) {
211
+ const CHANNELS_MAP = [
212
+ {offset: 0, shift: 0},
213
+ {offset: 1, shift: 8},
214
+ {offset: 2, shift: 16},
215
+ {offset: 3, shift: 24}
216
+ ];
217
+
218
+ const u = textureCoordinates[index];
219
+ const v = textureCoordinates[index + 1];
220
+
221
+ let components = 1;
222
+ if (mimeType && (mimeType.indexOf('image/jpeg') !== -1 || mimeType.indexOf('image/png') !== -1))
223
+ components = 4;
224
+ const offset = coordinatesToOffset(u, v, parsedImage, components);
225
+ let value: number = 0;
226
+ for (const c of channels) {
227
+ const map = CHANNELS_MAP[c];
228
+ const imageOffset = offset + map.offset;
229
+ const imageData = getImageData(parsedImage);
230
+ if (imageData.data.length <= imageOffset) {
231
+ throw new Error(`${imageData.data.length} <= ${imageOffset}`);
232
+ }
233
+ const imageValue = imageData.data[imageOffset];
234
+ value |= imageValue << map.shift;
235
+ }
236
+ return value;
237
+ }
238
+
239
+ /**
240
+ * Retrieves the offset in the image where the data are stored
241
+ * @param u - u-coordinate
242
+ * @param v - v-coordinate
243
+ * @param parsedImage - image where the data are stored
244
+ * @param componentsCount - number of components the data consists of.
245
+ * @returns offset in the image where the data are stored
246
+ */
247
+ function coordinatesToOffset(
248
+ u: number,
249
+ v: number,
250
+ parsedImage: any,
251
+ componentsCount: number = 1
252
+ ): number {
253
+ const w = parsedImage.width;
254
+ const iX = emod(u) * (w - 1);
255
+ const indX = Math.round(iX);
256
+
257
+ const h = parsedImage.height;
258
+ const iY = emod(v) * (h - 1);
259
+ const indY = Math.round(iY);
260
+ const components = parsedImage.components ? parsedImage.components : componentsCount;
261
+ // components is a number of channels in the image
262
+ const offset = (indY * w + indX) * components;
263
+ return offset;
264
+ }
@@ -14,11 +14,11 @@ import {getImageData} from '@loaders.gl/images';
14
14
  import {GLTFMeshPrimitive} from '../../types/gltf-json-schema';
15
15
  import {getComponentTypeFromArray} from '../../gltf-utils/gltf-utils';
16
16
  import {GLTFLoaderOptions} from '../../../gltf-loader';
17
+ import {emod} from '@loaders.gl/math';
17
18
 
18
19
  /** Extension name */
19
- const EXT_FEATURE_METADATA = 'EXT_feature_metadata';
20
-
21
- export const name = EXT_FEATURE_METADATA;
20
+ const EXT_FEATURE_METADATA_NAME = 'EXT_feature_metadata';
21
+ export const name = EXT_FEATURE_METADATA_NAME;
22
22
 
23
23
  export async function decode(gltfData: {json: GLTF}, options: GLTFLoaderOptions): Promise<void> {
24
24
  const scenegraph = new GLTFScenegraph(gltfData);
@@ -31,7 +31,7 @@ export async function decode(gltfData: {json: GLTF}, options: GLTFLoaderOptions)
31
31
  */
32
32
  function decodeExtFeatureMetadata(scenegraph: GLTFScenegraph, options: GLTFLoaderOptions): void {
33
33
  const extension: GLTF_EXT_feature_metadata_GLTF | null =
34
- scenegraph.getExtension(EXT_FEATURE_METADATA);
34
+ scenegraph.getExtension(EXT_FEATURE_METADATA_NAME);
35
35
  if (!extension) return;
36
36
 
37
37
  const schemaClasses = extension.schema?.classes;
@@ -62,7 +62,7 @@ function decodeExtFeatureMetadata(scenegraph: GLTFScenegraph, options: GLTFLoade
62
62
  }
63
63
 
64
64
  /**
65
- * Navigate throw all properies in feature table and gets properties data.
65
+ * Navigates through all properies in feature table and gets properties data.
66
66
  * @param scenegraph
67
67
  * @param featureTable
68
68
  * @param schemaClass
@@ -90,7 +90,7 @@ function handleFeatureTableProperties(
90
90
  }
91
91
 
92
92
  /**
93
- * Navigate throw all properies in feature texture and gets properties data.
93
+ * Navigates through all properies in feature texture and gets properties data.
94
94
  * Data will be stored in featureTexture.properties[propertyName].data
95
95
  * @param scenegraph
96
96
  * @param featureTexture
@@ -327,17 +327,6 @@ function coordinatesToOffset(
327
327
  return offset;
328
328
  }
329
329
 
330
- // The following is taken from tile-converter\src\i3s-converter\helpers\batch-ids-extensions.ts
331
- /**
332
- * Handle UVs if they are out of range [0,1].
333
- * @param n
334
- * @param m
335
- */
336
- function emod(n: number): number {
337
- const a = ((n % 1) + 1) % 1;
338
- return a;
339
- }
340
-
341
330
  /**
342
331
  * Find the feature table by class name.
343
332
  * @param featureTables
@@ -5,7 +5,8 @@ import type {GLTFWithBuffers} from '../types/gltf-types';
5
5
  import type {GLB} from '../types/glb-types';
6
6
  import type {ParseGLBOptions} from './parse-glb';
7
7
 
8
- import {parseJSON, sliceArrayBuffer} from '@loaders.gl/loader-utils';
8
+ import type {ImageType, TextureLevel} from '@loaders.gl/schema';
9
+ import {parseJSON, sliceArrayBuffer, parseFromContext} from '@loaders.gl/loader-utils';
9
10
  import {ImageLoader} from '@loaders.gl/images';
10
11
  import {BasisLoader, selectSupportedBasisFormat} from '@loaders.gl/textures';
11
12
 
@@ -198,13 +199,14 @@ async function loadImage(
198
199
  options,
199
200
  context: LoaderContext
200
201
  ) {
201
- const {fetch, parse} = context;
202
-
203
202
  let arrayBuffer;
204
203
 
205
204
  if (image.uri && !image.hasOwnProperty('bufferView')) {
206
205
  const uri = resolveUrl(image.uri, options);
206
+
207
+ const {fetch} = context;
207
208
  const response = await fetch(uri);
209
+
208
210
  arrayBuffer = await response.arrayBuffer();
209
211
  image.bufferView = {
210
212
  data: arrayBuffer
@@ -219,7 +221,7 @@ async function loadImage(
219
221
  assert(arrayBuffer, 'glTF image has no data');
220
222
 
221
223
  // Call `parse`
222
- let parsedImage = await parse(
224
+ let parsedImage = (await parseFromContext(
223
225
  arrayBuffer,
224
226
  [ImageLoader, BasisLoader],
225
227
  {
@@ -228,11 +230,12 @@ async function loadImage(
228
230
  basis: options.basis || {format: selectSupportedBasisFormat()}
229
231
  },
230
232
  context
231
- );
233
+ )) as ImageType | TextureLevel[][];
232
234
 
233
235
  if (parsedImage && parsedImage[0]) {
234
236
  parsedImage = {
235
237
  compressed: true,
238
+ // @ts-expect-error
236
239
  mipmaps: false,
237
240
  width: parsedImage[0].width,
238
241
  height: parsedImage[0].height,
@@ -244,5 +247,6 @@ async function loadImage(
244
247
 
245
248
  // Store the loaded image
246
249
  gltf.images = gltf.images || [];
250
+ // @ts-expect-error TODO - sort out image typing asap
247
251
  gltf.images[index] = parsedImage;
248
252
  }
@@ -0,0 +1,48 @@
1
+ import {GLTFTextureInfoMetadata} from './gltf-json-schema';
2
+ /* eslint-disable camelcase */
3
+
4
+ /**
5
+ * EXT_mesh_features extension types
6
+ * This is a primitive-level extension
7
+ * @see https://github.com/CesiumGS/glTF/tree/3d-tiles-next/extensions/2.0/Vendor/EXT_mesh_features
8
+ * or https://github.com/CesiumGS/glTF/blob/c38f7f37e894004353c15cd0481bc5b7381ce841/extensions/2.0/Vendor/EXT_mesh_features/schema/mesh.primitive.EXT_mesh_features.schema.json
9
+ * An object describing feature IDs for a mesh primitive.
10
+ */
11
+ export type GLTF_EXT_mesh_features = {
12
+ /** An array of feature ID sets. */
13
+ featureIds: GLTF_EXT_mesh_features_featureId[];
14
+ extensions?: Record<string, unknown>;
15
+ extras?: unknown;
16
+ /** For internal usage */
17
+ dataAttributeNames?: string[];
18
+ };
19
+
20
+ /**
21
+ * @see https://github.com/CesiumGS/glTF/blob/c38f7f37e894004353c15cd0481bc5b7381ce841/extensions/2.0/Vendor/EXT_mesh_features/schema/featureId.schema.json
22
+ * Feature IDs stored in an attribute or texture.
23
+ */
24
+ export type GLTF_EXT_mesh_features_featureId = {
25
+ /** The number of unique features in the attribute or texture. */
26
+ featureCount: number;
27
+ /** A value that indicates that no feature is associated with this vertex or texel. */
28
+ nullFeatureId?: number;
29
+ /** A label assigned to this feature ID set. Labels must be alphanumeric identifiers matching the regular expression `^[a-zA-Z_][a-zA-Z0-9_]*$`. */
30
+ label?: string;
31
+ /**
32
+ * An attribute containing feature IDs.
33
+ * When `attribute` and `texture` are omitted the feature IDs are assigned to vertices by their index.
34
+ * @see https://github.com/CesiumGS/glTF/blob/3d-tiles-next/extensions/2.0/Vendor/EXT_mesh_features/schema/featureIdAttribute.schema.json
35
+ * An integer value used to construct a string in the format `_FEATURE_ID_<set index>` which is a reference to a key in `mesh.primitives.attributes`
36
+ * (e.g. a value of `0` corresponds to `_FEATURE_ID_0`).
37
+ */
38
+ attribute?: number;
39
+ /** A texture containing feature IDs. */
40
+ texture?: GLTFTextureInfoMetadata;
41
+ /** The index of the property table containing per-feature property values. Only applicable when using the `EXT_structural_metadata` extension. */
42
+ propertyTable?: number;
43
+ extensions?: Record<string, unknown>;
44
+ extras?: unknown;
45
+
46
+ /** For internal usage */
47
+ data?: unknown;
48
+ };