@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
@@ -0,0 +1,212 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.primitivePropertyDataToAttributes = exports.getPrimitiveTextureData = exports.convertRawBufferToMetadataArray = exports.getArrayElementByteSize = void 0;
4
+ const gltf_utils_1 = require("../gltf-utils/gltf-utils");
5
+ const images_1 = require("@loaders.gl/images");
6
+ const math_1 = require("@loaders.gl/math");
7
+ const ATTRIBUTE_TYPE_TO_COMPONENTS = {
8
+ SCALAR: 1,
9
+ VEC2: 2,
10
+ VEC3: 3,
11
+ VEC4: 4,
12
+ MAT2: 4,
13
+ MAT3: 9,
14
+ MAT4: 16,
15
+ BOOLEAN: 1,
16
+ STRING: 1,
17
+ ENUM: 1
18
+ };
19
+ const ATTRIBUTE_COMPONENT_TYPE_TO_ARRAY = {
20
+ INT8: Int8Array,
21
+ UINT8: Uint8Array,
22
+ INT16: Int16Array,
23
+ UINT16: Uint16Array,
24
+ INT32: Int32Array,
25
+ UINT32: Uint32Array,
26
+ INT64: BigInt64Array,
27
+ UINT64: BigUint64Array,
28
+ FLOAT32: Float32Array,
29
+ FLOAT64: Float64Array
30
+ };
31
+ const ATTRIBUTE_COMPONENT_TYPE_TO_BYTE_SIZE = {
32
+ INT8: 1,
33
+ UINT8: 1,
34
+ INT16: 2,
35
+ UINT16: 2,
36
+ INT32: 4,
37
+ UINT32: 4,
38
+ INT64: 8,
39
+ UINT64: 8,
40
+ FLOAT32: 4,
41
+ FLOAT64: 8
42
+ };
43
+ function getArrayElementByteSize(attributeType, componentType) {
44
+ return (ATTRIBUTE_COMPONENT_TYPE_TO_BYTE_SIZE[componentType] *
45
+ ATTRIBUTE_TYPE_TO_COMPONENTS[attributeType]);
46
+ }
47
+ exports.getArrayElementByteSize = getArrayElementByteSize;
48
+ /**
49
+ * Converts raw bytes that are in the buffer to an array of the type defined by the schema.
50
+ * @param {Uint8Array} typedArray - raw bytes in the buffer
51
+ * @param {string} attributeType - SCALAR, VECN, MATN
52
+ * @param {string} componentType - type of the component in elements, e.g. 'UINT8' or 'FLOAT32'
53
+ * @param {number} elementCount - number of elements in the array. Default value is 1.
54
+ * @returns {TypedArray} Data array
55
+ */
56
+ function convertRawBufferToMetadataArray(typedArray, attributeType, componentType, elementCount = 1) {
57
+ const numberOfComponents = ATTRIBUTE_TYPE_TO_COMPONENTS[attributeType];
58
+ const ArrayType = ATTRIBUTE_COMPONENT_TYPE_TO_ARRAY[componentType];
59
+ const length = elementCount * numberOfComponents;
60
+ const size = ATTRIBUTE_COMPONENT_TYPE_TO_BYTE_SIZE[componentType];
61
+ // the buffer view `byteOffset` must be aligned to a multiple of the `componentType` size.
62
+ const offset = typedArray.byteOffset % size
63
+ ? Math.ceil(typedArray.byteOffset / size) * size
64
+ : typedArray.byteOffset;
65
+ return new ArrayType(typedArray.buffer, offset, length);
66
+ }
67
+ exports.convertRawBufferToMetadataArray = convertRawBufferToMetadataArray;
68
+ /**
69
+ * Processes data encoded in the texture associated with the primitive.
70
+ * If Ext_mesh_featues is combined with the Ext_structural_metadata, propertyTable will also be processed.
71
+ * @param {GLTFScenegraph} scenegraph - Instance of the class for structured access to GLTF data.
72
+ * @param {GLTFTextureInfoMetadata} textureInfo - reference to the texture where extension data are stored.
73
+ * @param {GLTFMeshPrimitive} primitive - primitive object in the mesh
74
+ * @returns {number[] | null} Array of data taken. Null if data can't be taken from the texture.
75
+ */
76
+ function getPrimitiveTextureData(scenegraph, textureInfo, primitive) {
77
+ /*
78
+ texture.index is an index for the "textures" array.
79
+ The texture object referenced by this index looks like this:
80
+ {
81
+ "sampler": 0,
82
+ "source": 0
83
+ }
84
+ "sampler" is an index for the "samplers" array
85
+ "source" is an index for the "images" array that contains data. These data are stored in rgba channels of the image.
86
+
87
+ texture.texCoord is a number-suffix (like 1) for an attribute like "TEXCOORD_1" in meshes.primitives
88
+ 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.
89
+ */
90
+ const json = scenegraph.gltf.json;
91
+ const texCoordAccessorKey = `TEXCOORD_${textureInfo.texCoord || 0}`;
92
+ const texCoordAccessorIndex = primitive.attributes[texCoordAccessorKey];
93
+ const texCoordBufferView = scenegraph.getBufferView(texCoordAccessorIndex);
94
+ const texCoordArray = scenegraph.getTypedArrayForBufferView(texCoordBufferView);
95
+ // textureCoordinates array contains UV coordinates of the actual data stored in the texture
96
+ const textureCoordinates = new Float32Array(texCoordArray.buffer, texCoordArray.byteOffset, texCoordArray.length / 4);
97
+ const textureIndex = textureInfo.index;
98
+ const imageIndex = json.textures?.[textureIndex]?.source;
99
+ if (typeof imageIndex !== 'undefined') {
100
+ const mimeType = json.images?.[imageIndex]?.mimeType;
101
+ const parsedImage = scenegraph.gltf.images?.[imageIndex];
102
+ // Checking for width is to prevent handling Un-processed images (e.g. [analyze] stage, where loadImages option is set to false)
103
+ if (parsedImage && typeof parsedImage.width !== 'undefined') {
104
+ const textureData = [];
105
+ for (let index = 0; index < textureCoordinates.length; index += 2) {
106
+ const value = getImageValueByCoordinates(parsedImage, mimeType, textureCoordinates, index, textureInfo.channels);
107
+ textureData.push(value);
108
+ }
109
+ return textureData;
110
+ }
111
+ }
112
+ return null;
113
+ }
114
+ exports.getPrimitiveTextureData = getPrimitiveTextureData;
115
+ /**
116
+ * Puts property data to attributes.
117
+ * It creates corresponding buffer, bufferView and accessor
118
+ * so the data can be accessed like regular data stored in buffers.
119
+ * @param {GLTFScenegraph} scenegraph - scenegraph object
120
+ * @param {string} attributeName - name of the attribute
121
+ * @param {number[]} propertyData - property data to store
122
+ * @param {number[]} featureTable - an array where unique data from the property data are being stored
123
+ * @param {GLTFMeshPrimitive} primitive - primitive object
124
+ */
125
+ function primitivePropertyDataToAttributes(scenegraph, attributeName, propertyData, featureTable, primitive) {
126
+ if (propertyData === null)
127
+ return;
128
+ /*
129
+ featureTable will contain unique values, e.g.
130
+ propertyData = [24, 35, 28, 24]
131
+ featureTable = [24, 35, 28]
132
+ featureIndices will contain indices that refer featureTextureTable, e.g.
133
+ featureIndices = [0, 1, 2, 0]
134
+ */
135
+ const featureIndices = [];
136
+ for (const texelData of propertyData) {
137
+ let index = featureTable.findIndex((item) => item === texelData);
138
+ if (index === -1) {
139
+ index = featureTable.push(texelData) - 1;
140
+ }
141
+ featureIndices.push(index);
142
+ }
143
+ const typedArray = new Uint32Array(featureIndices);
144
+ const bufferIndex = scenegraph.gltf.buffers.push({
145
+ arrayBuffer: typedArray.buffer,
146
+ byteOffset: typedArray.byteOffset,
147
+ byteLength: typedArray.byteLength
148
+ }) - 1;
149
+ const bufferViewIndex = scenegraph.addBufferView(typedArray, bufferIndex, 0);
150
+ const accessorIndex = scenegraph.addAccessor(bufferViewIndex, {
151
+ size: 1,
152
+ componentType: (0, gltf_utils_1.getComponentTypeFromArray)(typedArray),
153
+ count: typedArray.length
154
+ });
155
+ primitive.attributes[attributeName] = accessorIndex;
156
+ }
157
+ exports.primitivePropertyDataToAttributes = primitivePropertyDataToAttributes;
158
+ /**
159
+ * Gets the value from the texture by coordinates provided.
160
+ * @param {ImageType} parsedImage - image where the data are stored.
161
+ * @param {string | undefined} mimeType - MIME type
162
+ * @param {Float32Array} textureCoordinates - uv coordinates to access data in the image.
163
+ * @param {number} index - index of uv coordinates in the array textureCoordinates
164
+ * @param {channels} channels - image channels where data are stored. Channels of an RGBA texture are numbered 0..3 respectively.
165
+ * @returns {number} Value taken from the image.
166
+ */
167
+ function getImageValueByCoordinates(parsedImage, mimeType, textureCoordinates, index, channels = [0]) {
168
+ const CHANNELS_MAP = [
169
+ { offset: 0, shift: 0 },
170
+ { offset: 1, shift: 8 },
171
+ { offset: 2, shift: 16 },
172
+ { offset: 3, shift: 24 }
173
+ ];
174
+ const u = textureCoordinates[index];
175
+ const v = textureCoordinates[index + 1];
176
+ let components = 1;
177
+ if (mimeType && (mimeType.indexOf('image/jpeg') !== -1 || mimeType.indexOf('image/png') !== -1))
178
+ components = 4;
179
+ const offset = coordinatesToOffset(u, v, parsedImage, components);
180
+ let value = 0;
181
+ for (const c of channels) {
182
+ const map = CHANNELS_MAP[c];
183
+ const imageOffset = offset + map.offset;
184
+ const imageData = (0, images_1.getImageData)(parsedImage);
185
+ if (imageData.data.length <= imageOffset) {
186
+ throw new Error(`${imageData.data.length} <= ${imageOffset}`);
187
+ }
188
+ const imageValue = imageData.data[imageOffset];
189
+ value |= imageValue << map.shift;
190
+ }
191
+ return value;
192
+ }
193
+ /**
194
+ * Retrieves the offset in the image where the data are stored
195
+ * @param u - u-coordinate
196
+ * @param v - v-coordinate
197
+ * @param parsedImage - image where the data are stored
198
+ * @param componentsCount - number of components the data consists of.
199
+ * @returns offset in the image where the data are stored
200
+ */
201
+ function coordinatesToOffset(u, v, parsedImage, componentsCount = 1) {
202
+ const w = parsedImage.width;
203
+ const iX = (0, math_1.emod)(u) * (w - 1);
204
+ const indX = Math.round(iX);
205
+ const h = parsedImage.height;
206
+ const iY = (0, math_1.emod)(v) * (h - 1);
207
+ const indY = Math.round(iY);
208
+ const components = parsedImage.components ? parsedImage.components : componentsCount;
209
+ // components is a number of channels in the image
210
+ const offset = (indY * w + indX) * components;
211
+ return offset;
212
+ }
@@ -1 +1 @@
1
- {"version":3,"file":"EXT_feature_metadata.d.ts","sourceRoot":"","sources":["../../../../src/lib/extensions/deprecated/EXT_feature_metadata.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,IAAI,EAQL,MAAM,8BAA8B,CAAC;AAKtC,OAAO,EAAC,iBAAiB,EAAC,MAAM,sBAAsB,CAAC;AAKvD,eAAO,MAAM,IAAI,yBAAuB,CAAC;AAEzC,wBAAsB,MAAM,CAAC,QAAQ,EAAE;IAAC,IAAI,EAAE,IAAI,CAAA;CAAC,EAAE,OAAO,EAAE,iBAAiB,GAAG,OAAO,CAAC,IAAI,CAAC,CAG9F"}
1
+ {"version":3,"file":"EXT_feature_metadata.d.ts","sourceRoot":"","sources":["../../../../src/lib/extensions/deprecated/EXT_feature_metadata.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,IAAI,EAQL,MAAM,8BAA8B,CAAC;AAKtC,OAAO,EAAC,iBAAiB,EAAC,MAAM,sBAAsB,CAAC;AAKvD,eAAO,MAAM,IAAI,yBAA4B,CAAC;AAE9C,wBAAsB,MAAM,CAAC,QAAQ,EAAE;IAAC,IAAI,EAAE,IAAI,CAAA;CAAC,EAAE,OAAO,EAAE,iBAAiB,GAAG,OAAO,CAAC,IAAI,CAAC,CAG9F"}
@@ -4,9 +4,10 @@ exports.decode = exports.name = void 0;
4
4
  const gltf_scenegraph_1 = require("../../api/gltf-scenegraph");
5
5
  const images_1 = require("@loaders.gl/images");
6
6
  const gltf_utils_1 = require("../../gltf-utils/gltf-utils");
7
+ const math_1 = require("@loaders.gl/math");
7
8
  /** Extension name */
8
- const EXT_FEATURE_METADATA = 'EXT_feature_metadata';
9
- exports.name = EXT_FEATURE_METADATA;
9
+ const EXT_FEATURE_METADATA_NAME = 'EXT_feature_metadata';
10
+ exports.name = EXT_FEATURE_METADATA_NAME;
10
11
  async function decode(gltfData, options) {
11
12
  const scenegraph = new gltf_scenegraph_1.GLTFScenegraph(gltfData);
12
13
  decodeExtFeatureMetadata(scenegraph, options);
@@ -17,7 +18,7 @@ exports.decode = decode;
17
18
  * @param scenegraph
18
19
  */
19
20
  function decodeExtFeatureMetadata(scenegraph, options) {
20
- const extension = scenegraph.getExtension(EXT_FEATURE_METADATA);
21
+ const extension = scenegraph.getExtension(EXT_FEATURE_METADATA_NAME);
21
22
  if (!extension)
22
23
  return;
23
24
  const schemaClasses = extension.schema?.classes;
@@ -43,7 +44,7 @@ function decodeExtFeatureMetadata(scenegraph, options) {
43
44
  }
44
45
  }
45
46
  /**
46
- * Navigate throw all properies in feature table and gets properties data.
47
+ * Navigates through all properies in feature table and gets properties data.
47
48
  * @param scenegraph
48
49
  * @param featureTable
49
50
  * @param schemaClass
@@ -60,7 +61,7 @@ function handleFeatureTableProperties(scenegraph, featureTable, schemaClass) {
60
61
  }
61
62
  }
62
63
  /**
63
- * Navigate throw all properies in feature texture and gets properties data.
64
+ * Navigates through all properies in feature texture and gets properties data.
64
65
  * Data will be stored in featureTexture.properties[propertyName].data
65
66
  * @param scenegraph
66
67
  * @param featureTexture
@@ -224,26 +225,16 @@ function getVal(parsedImage, offset) {
224
225
  }
225
226
  function coordinatesToOffset(u, v, parsedImage, componentsCount = 1) {
226
227
  const w = parsedImage.width;
227
- const iX = emod(u) * (w - 1);
228
+ const iX = (0, math_1.emod)(u) * (w - 1);
228
229
  const indX = Math.round(iX);
229
230
  const h = parsedImage.height;
230
- const iY = emod(v) * (h - 1);
231
+ const iY = (0, math_1.emod)(v) * (h - 1);
231
232
  const indY = Math.round(iY);
232
233
  const components = parsedImage.components ? parsedImage.components : componentsCount;
233
234
  // components is a number of channels in the image
234
235
  const offset = (indY * w + indX) * components;
235
236
  return offset;
236
237
  }
237
- // The following is taken from tile-converter\src\i3s-converter\helpers\batch-ids-extensions.ts
238
- /**
239
- * Handle UVs if they are out of range [0,1].
240
- * @param n
241
- * @param m
242
- */
243
- function emod(n) {
244
- const a = ((n % 1) + 1) % 1;
245
- return a;
246
- }
247
238
  /**
248
239
  * Find the feature table by class name.
249
240
  * @param featureTables
@@ -1 +1 @@
1
- {"version":3,"file":"parse-gltf.d.ts","sourceRoot":"","sources":["../../../src/lib/parsers/parse-gltf.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAC,aAAa,EAAC,MAAM,0BAA0B,CAAC;AAC5D,OAAO,KAAK,EAAC,iBAAiB,EAAC,MAAM,mBAAmB,CAAC;AACzD,OAAO,KAAK,EAAC,eAAe,EAAC,MAAM,qBAAqB,CAAC;AAEzD,OAAO,KAAK,EAAC,eAAe,EAAC,MAAM,aAAa,CAAC;AAajD,OAAO;AACP,MAAM,MAAM,gBAAgB,GAAG,eAAe,GAAG;IAC/C,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,iBAAiB,CAAC,EAAE,MAAM,EAAE,CAAC;IAE7B,6FAA6F;IAC7F,WAAW,CAAC,EAAE,KAAK,CAAC;CACrB,CAAC;AAEF,4DAA4D;AAC5D,wBAAgB,MAAM,CAAC,WAAW,EAAE,WAAW,EAAE,OAAO,CAAC,EAAE,gBAAgB,GAAG,OAAO,CAGpF;AAED,wBAAsB,SAAS,CAC7B,IAAI,EAAE,eAAe,EACrB,mBAAmB,KAAA,EACnB,UAAU,oBAAI,EACd,OAAO,EAAE,iBAAiB,EAC1B,OAAO,EAAE,aAAa,GACrB,OAAO,CAAC,eAAe,CAAC,CAqB1B"}
1
+ {"version":3,"file":"parse-gltf.d.ts","sourceRoot":"","sources":["../../../src/lib/parsers/parse-gltf.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAC,aAAa,EAAC,MAAM,0BAA0B,CAAC;AAC5D,OAAO,KAAK,EAAC,iBAAiB,EAAC,MAAM,mBAAmB,CAAC;AACzD,OAAO,KAAK,EAAC,eAAe,EAAC,MAAM,qBAAqB,CAAC;AAEzD,OAAO,KAAK,EAAC,eAAe,EAAC,MAAM,aAAa,CAAC;AAcjD,OAAO;AACP,MAAM,MAAM,gBAAgB,GAAG,eAAe,GAAG;IAC/C,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,iBAAiB,CAAC,EAAE,MAAM,EAAE,CAAC;IAE7B,6FAA6F;IAC7F,WAAW,CAAC,EAAE,KAAK,CAAC;CACrB,CAAC;AAEF,4DAA4D;AAC5D,wBAAgB,MAAM,CAAC,WAAW,EAAE,WAAW,EAAE,OAAO,CAAC,EAAE,gBAAgB,GAAG,OAAO,CAGpF;AAED,wBAAsB,SAAS,CAC7B,IAAI,EAAE,eAAe,EACrB,mBAAmB,KAAA,EACnB,UAAU,oBAAI,EACd,OAAO,EAAE,iBAAiB,EAC1B,OAAO,EAAE,aAAa,GACrB,OAAO,CAAC,eAAe,CAAC,CAqB1B"}
@@ -145,10 +145,10 @@ function getReferencesImageIndices(gltf) {
145
145
  }
146
146
  /** Asynchronously fetches and parses one image, store in images array outside of json */
147
147
  async function loadImage(gltf, image, index, options, context) {
148
- const { fetch, parse } = context;
149
148
  let arrayBuffer;
150
149
  if (image.uri && !image.hasOwnProperty('bufferView')) {
151
150
  const uri = (0, resolve_url_1.resolveUrl)(image.uri, options);
151
+ const { fetch } = context;
152
152
  const response = await fetch(uri);
153
153
  arrayBuffer = await response.arrayBuffer();
154
154
  image.bufferView = {
@@ -161,14 +161,15 @@ async function loadImage(gltf, image, index, options, context) {
161
161
  }
162
162
  (0, assert_1.assert)(arrayBuffer, 'glTF image has no data');
163
163
  // Call `parse`
164
- let parsedImage = await parse(arrayBuffer, [images_1.ImageLoader, textures_1.BasisLoader], {
164
+ let parsedImage = (await (0, loader_utils_1.parseFromContext)(arrayBuffer, [images_1.ImageLoader, textures_1.BasisLoader], {
165
165
  ...options,
166
166
  mimeType: image.mimeType,
167
167
  basis: options.basis || { format: (0, textures_1.selectSupportedBasisFormat)() }
168
- }, context);
168
+ }, context));
169
169
  if (parsedImage && parsedImage[0]) {
170
170
  parsedImage = {
171
171
  compressed: true,
172
+ // @ts-expect-error
172
173
  mipmaps: false,
173
174
  width: parsedImage[0].width,
174
175
  height: parsedImage[0].height,
@@ -179,5 +180,6 @@ async function loadImage(gltf, image, index, options, context) {
179
180
  // const parsedImage = await parse(arrayBuffer, [ImageLoader]);
180
181
  // Store the loaded image
181
182
  gltf.images = gltf.images || [];
183
+ // @ts-expect-error TODO - sort out image typing asap
182
184
  gltf.images[index] = parsedImage;
183
185
  }
@@ -0,0 +1,45 @@
1
+ import { GLTFTextureInfoMetadata } from './gltf-json-schema';
2
+ /**
3
+ * EXT_mesh_features extension types
4
+ * This is a primitive-level extension
5
+ * @see https://github.com/CesiumGS/glTF/tree/3d-tiles-next/extensions/2.0/Vendor/EXT_mesh_features
6
+ * or https://github.com/CesiumGS/glTF/blob/c38f7f37e894004353c15cd0481bc5b7381ce841/extensions/2.0/Vendor/EXT_mesh_features/schema/mesh.primitive.EXT_mesh_features.schema.json
7
+ * An object describing feature IDs for a mesh primitive.
8
+ */
9
+ export type GLTF_EXT_mesh_features = {
10
+ /** An array of feature ID sets. */
11
+ featureIds: GLTF_EXT_mesh_features_featureId[];
12
+ extensions?: Record<string, unknown>;
13
+ extras?: unknown;
14
+ /** For internal usage */
15
+ dataAttributeNames?: string[];
16
+ };
17
+ /**
18
+ * @see https://github.com/CesiumGS/glTF/blob/c38f7f37e894004353c15cd0481bc5b7381ce841/extensions/2.0/Vendor/EXT_mesh_features/schema/featureId.schema.json
19
+ * Feature IDs stored in an attribute or texture.
20
+ */
21
+ export type GLTF_EXT_mesh_features_featureId = {
22
+ /** The number of unique features in the attribute or texture. */
23
+ featureCount: number;
24
+ /** A value that indicates that no feature is associated with this vertex or texel. */
25
+ nullFeatureId?: number;
26
+ /** A label assigned to this feature ID set. Labels must be alphanumeric identifiers matching the regular expression `^[a-zA-Z_][a-zA-Z0-9_]*$`. */
27
+ label?: string;
28
+ /**
29
+ * An attribute containing feature IDs.
30
+ * When `attribute` and `texture` are omitted the feature IDs are assigned to vertices by their index.
31
+ * @see https://github.com/CesiumGS/glTF/blob/3d-tiles-next/extensions/2.0/Vendor/EXT_mesh_features/schema/featureIdAttribute.schema.json
32
+ * 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`
33
+ * (e.g. a value of `0` corresponds to `_FEATURE_ID_0`).
34
+ */
35
+ attribute?: number;
36
+ /** A texture containing feature IDs. */
37
+ texture?: GLTFTextureInfoMetadata;
38
+ /** The index of the property table containing per-feature property values. Only applicable when using the `EXT_structural_metadata` extension. */
39
+ propertyTable?: number;
40
+ extensions?: Record<string, unknown>;
41
+ extras?: unknown;
42
+ /** For internal usage */
43
+ data?: unknown;
44
+ };
45
+ //# sourceMappingURL=gltf-ext-mesh-features-schema.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"gltf-ext-mesh-features-schema.d.ts","sourceRoot":"","sources":["../../../src/lib/types/gltf-ext-mesh-features-schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,uBAAuB,EAAC,MAAM,oBAAoB,CAAC;AAG3D;;;;;;GAMG;AACH,MAAM,MAAM,sBAAsB,GAAG;IACnC,mCAAmC;IACnC,UAAU,EAAE,gCAAgC,EAAE,CAAC;IAC/C,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACrC,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,yBAAyB;IACzB,kBAAkB,CAAC,EAAE,MAAM,EAAE,CAAC;CAC/B,CAAC;AAEF;;;GAGG;AACH,MAAM,MAAM,gCAAgC,GAAG;IAC7C,iEAAiE;IACjE,YAAY,EAAE,MAAM,CAAC;IACrB,sFAAsF;IACtF,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,mJAAmJ;IACnJ,KAAK,CAAC,EAAE,MAAM,CAAC;IACf;;;;;;OAMG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,wCAAwC;IACxC,OAAO,CAAC,EAAE,uBAAuB,CAAC;IAClC,kJAAkJ;IAClJ,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACrC,MAAM,CAAC,EAAE,OAAO,CAAC;IAEjB,yBAAyB;IACzB,IAAI,CAAC,EAAE,OAAO,CAAC;CAChB,CAAC"}
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });