@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
@@ -9,12 +9,14 @@ import type {
9
9
  GLTF_EXT_feature_metadata_GLTF,
10
10
  GLTF_EXT_feature_metadata_TextureAccessor
11
11
  } from '../../types/gltf-json-schema';
12
+ import type {BigTypedArray, TypedArray} from '@loaders.gl/schema';
12
13
  import {GLTFScenegraph} from '../../api/gltf-scenegraph';
13
14
  import {getImageData} from '@loaders.gl/images';
14
15
  import {GLTFMeshPrimitive} from '../../types/gltf-json-schema';
15
16
  import {getComponentTypeFromArray} from '../../gltf-utils/gltf-utils';
16
17
  import {GLTFLoaderOptions} from '../../../gltf-loader';
17
18
  import {emod} from '@loaders.gl/math';
19
+ import {convertRawBufferToMetadataArray, getOffsetsForProperty} from '../utils/3d-tiles-utils';
18
20
 
19
21
  /** Extension name */
20
22
  const EXT_FEATURE_METADATA_NAME = 'EXT_feature_metadata';
@@ -125,24 +127,134 @@ function getPropertyDataFromBinarySource(
125
127
  schemaProperty: GLTF_EXT_feature_metadata_ClassProperty,
126
128
  numberOfFeatures: number,
127
129
  featureTableProperty: GLTF_EXT_feature_metadata_FeatureTableProperty
128
- ): Uint8Array | string[] {
130
+ ): BigTypedArray | string[] {
129
131
  const bufferView = featureTableProperty.bufferView;
130
- // TODO think maybe we shouldn't get data only in Uint8Array format.
131
132
  const dataArray: Uint8Array = scenegraph.getTypedArrayForBufferView(bufferView);
132
133
 
133
- switch (schemaProperty.type) {
134
- case 'STRING': {
135
- // stringOffsetBufferView should be available for string type.
136
- const stringOffsetBufferView = featureTableProperty.stringOffsetBufferView!;
137
- const offsetsData = scenegraph.getTypedArrayForBufferView(stringOffsetBufferView);
138
- return getStringAttributes(dataArray, offsetsData, numberOfFeatures);
134
+ if (schemaProperty.type === 'STRING') {
135
+ const offsetsData = getStringOffsets(scenegraph, featureTableProperty, numberOfFeatures);
136
+ if (!offsetsData) {
137
+ return [];
139
138
  }
140
- default:
139
+ return getStringAttributes(dataArray, offsetsData, numberOfFeatures);
140
+ } else if (isNumericProperty(schemaProperty.type)) {
141
+ return getNumericAttributes(
142
+ dataArray,
143
+ schemaProperty.type as
144
+ | 'INT8'
145
+ | 'UINT8'
146
+ | 'INT16'
147
+ | 'UINT16'
148
+ | 'INT32'
149
+ | 'UINT32'
150
+ | 'INT64'
151
+ | 'UINT64'
152
+ | 'FLOAT32'
153
+ | 'FLOAT64',
154
+ numberOfFeatures
155
+ );
141
156
  }
142
157
 
143
158
  return dataArray;
144
159
  }
145
160
 
161
+ /**
162
+ * Check if the feature table property is of numeric type
163
+ * @param schemaPropertyType - feature table property
164
+ * @returns true if property is numeric, else - false
165
+ */
166
+ function isNumericProperty(
167
+ schemaPropertyType:
168
+ | 'INT8'
169
+ | 'UINT8'
170
+ | 'INT16'
171
+ | 'UINT16'
172
+ | 'INT32'
173
+ | 'UINT32'
174
+ | 'INT64'
175
+ | 'UINT64'
176
+ | 'FLOAT32'
177
+ | 'FLOAT64'
178
+ | 'BOOLEAN'
179
+ | 'STRING'
180
+ | 'ENUM'
181
+ | 'ARRAY'
182
+ | string
183
+ ): boolean {
184
+ return [
185
+ 'UINT8',
186
+ 'INT16',
187
+ 'UINT16',
188
+ 'INT32',
189
+ 'UINT32',
190
+ 'INT64',
191
+ 'UINT64',
192
+ 'FLOAT32',
193
+ 'FLOAT64'
194
+ ].includes(schemaPropertyType);
195
+ }
196
+
197
+ /**
198
+ * Parse featureTable.property.stringOffsetBufferView.
199
+ * String offsets is an array of offsets of strings in the united array of charactersz
200
+ * @param scenegraph - Instance of the class for structured access to GLTF data
201
+ * @param propertyTableProperty - propertyTable's property metadata
202
+ * @param numberOfElements - The number of elements in each property array that propertyTableProperty contains. It's a number of rows in the table
203
+ * @returns typed array with offset values
204
+ * @see https://github.com/CesiumGS/glTF/blob/c38f7f37e894004353c15cd0481bc5b7381ce841/extensions/2.0/Vendor/EXT_feature_metadata/schema/featureTable.property.schema.json#L50C10-L50C32
205
+ */
206
+ function getStringOffsets(
207
+ scenegraph: GLTFScenegraph,
208
+ featureTableProperty: GLTF_EXT_feature_metadata_FeatureTableProperty,
209
+ numberOfElements: number
210
+ ): TypedArray | null {
211
+ if (typeof featureTableProperty.stringOffsetBufferView !== 'undefined') {
212
+ // Data are in a FIXED-length array
213
+ return getOffsetsForProperty(
214
+ scenegraph,
215
+ featureTableProperty.stringOffsetBufferView,
216
+ featureTableProperty.offsetType || 'UINT32', // UINT32 is the default by the spec
217
+ numberOfElements
218
+ );
219
+ }
220
+ return null;
221
+ }
222
+
223
+ /**
224
+ * Parse numeric property values
225
+ * @param valuesDataBytes - values data array
226
+ * @param propertyType - type of the property
227
+ * @param elementCount - number of rows in the featureTable
228
+ * @returns Number data in a typed array
229
+ */
230
+ function getNumericAttributes(
231
+ valuesDataBytes: Uint8Array,
232
+ propertyType:
233
+ | 'INT8'
234
+ | 'UINT8'
235
+ | 'INT16'
236
+ | 'UINT16'
237
+ | 'INT32'
238
+ | 'UINT32'
239
+ | 'INT64'
240
+ | 'UINT64'
241
+ | 'FLOAT32'
242
+ | 'FLOAT64',
243
+ elementCount: number
244
+ ): BigTypedArray {
245
+ let valuesData = convertRawBufferToMetadataArray(
246
+ valuesDataBytes,
247
+ 'SCALAR',
248
+ // The datatype of the element's components. Only applicable to `SCALAR`, `VECN`, and `MATN` types.
249
+ propertyType,
250
+ elementCount
251
+ );
252
+ if (!valuesData) {
253
+ valuesData = valuesDataBytes;
254
+ }
255
+ return valuesData;
256
+ }
257
+
146
258
  /**
147
259
  * Get properties from texture associated with all mesh primitives.
148
260
  * @param scenegraph
@@ -371,24 +483,16 @@ function findFeatureTextureByName(
371
483
  */
372
484
  function getStringAttributes(
373
485
  data: Uint8Array,
374
- offsetsData: Uint8Array,
486
+ offsetsData: TypedArray,
375
487
  stringsCount: number
376
488
  ): string[] {
377
489
  const stringsArray: string[] = [];
378
490
  const textDecoder = new TextDecoder('utf8');
379
491
 
380
- let stringOffset = 0;
381
- const bytesPerStringSize = 4;
382
-
383
492
  for (let index = 0; index < stringsCount; index++) {
384
- // TODO check if it is multiplication on bytesPerStringSize is valid operation?
385
- const stringByteSize =
386
- offsetsData[(index + 1) * bytesPerStringSize] - offsetsData[index * bytesPerStringSize];
387
- const stringData = data.subarray(stringOffset, stringByteSize + stringOffset);
493
+ const stringData = data.slice(offsetsData[index], offsetsData[index + 1]);
388
494
  const stringAttribute = textDecoder.decode(stringData);
389
-
390
495
  stringsArray.push(stringAttribute);
391
- stringOffset += stringByteSize;
392
496
  }
393
497
 
394
498
  return stringsArray;
@@ -1,12 +1,33 @@
1
- import type {GLTFTextureInfoMetadata, GLTFMeshPrimitive} from '../types/gltf-json-schema';
2
- import type {TypedArray} from '@loaders.gl/schema';
1
+ /**
2
+ * loaders.gl, MIT license
3
+ *
4
+ * Shared code for 3DTiles extensions:
5
+ * * EXT_feature_metadata
6
+ * * EXT_mesh_features
7
+ * * EXT_structural_metadata
8
+ */
9
+
10
+ import type {GLTFTextureInfoMetadata, GLTFMeshPrimitive} from '../../types/gltf-json-schema';
11
+ import type {BigTypedArray, TypedArray} from '@loaders.gl/schema';
3
12
  import type {ImageType} from '@loaders.gl/images';
4
13
 
5
- import {GLTFScenegraph} from '../api/gltf-scenegraph';
6
- import {getComponentTypeFromArray} from '../gltf-utils/gltf-utils';
14
+ import {GLTFScenegraph} from '../../api/gltf-scenegraph';
15
+ import {getComponentTypeFromArray} from '../../gltf-utils/gltf-utils';
7
16
  import {getImageData} from '@loaders.gl/images';
8
17
  import {emod} from '@loaders.gl/math';
9
18
 
19
+ export type NumericComponentType =
20
+ | 'INT8'
21
+ | 'UINT8'
22
+ | 'INT16'
23
+ | 'UINT16'
24
+ | 'INT32'
25
+ | 'UINT32'
26
+ | 'INT64'
27
+ | 'UINT64'
28
+ | 'FLOAT32'
29
+ | 'FLOAT64';
30
+
10
31
  const ATTRIBUTE_TYPE_TO_COMPONENTS = {
11
32
  SCALAR: 1,
12
33
  VEC2: 2,
@@ -53,39 +74,79 @@ export function getArrayElementByteSize(attributeType, componentType): number {
53
74
  );
54
75
  }
55
76
 
77
+ /**
78
+ * Gets offset array from `arrayOffsets` or `stringOffsets`.
79
+ * @param scenegraph - Instance of the class for structured access to GLTF data.
80
+ * @param bufferViewIndex - Buffer view index
81
+ * @param offsetType - The type of values in `arrayOffsets` or `stringOffsets`.
82
+ * @param numberOfElements - The number of elements in each property array.
83
+ * @returns array with values offsets
84
+ */
85
+ export function getOffsetsForProperty(
86
+ scenegraph: GLTFScenegraph,
87
+ bufferViewIndex: number,
88
+ offsetType: 'UINT8' | 'UINT16' | 'UINT32' | 'UINT64' | string,
89
+ numberOfElements: number
90
+ ): TypedArray | null {
91
+ if (
92
+ offsetType !== 'UINT8' &&
93
+ offsetType !== 'UINT16' &&
94
+ offsetType !== 'UINT32' &&
95
+ offsetType !== 'UINT64'
96
+ ) {
97
+ return null;
98
+ }
99
+ const arrayOffsetsBytes = scenegraph.getTypedArrayForBufferView(bufferViewIndex);
100
+ const arrayOffsets = convertRawBufferToMetadataArray(
101
+ arrayOffsetsBytes,
102
+ 'SCALAR', // offsets consist of ONE component
103
+ offsetType,
104
+ numberOfElements + 1 // The number of offsets is equal to the property table `count` plus one.
105
+ );
106
+
107
+ // We don't support BigInt offsets at the moment. It requires additional logic and potential issues in Safari
108
+ if (arrayOffsets instanceof BigInt64Array || arrayOffsets instanceof BigUint64Array) {
109
+ return null;
110
+ }
111
+ return arrayOffsets;
112
+ }
113
+
56
114
  /**
57
115
  * 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
116
+ * @param data - raw bytes in the buffer
117
+ * @param attributeType - SCALAR, VECN, MATN
118
+ * @param componentType - type of the component in elements, e.g. 'UINT8' or 'FLOAT32'
119
+ * @param elementCount - number of elements in the array. Default value is 1.
120
+ * @returns Data array
63
121
  */
64
122
  export function convertRawBufferToMetadataArray(
65
- typedArray: Uint8Array,
123
+ data: Uint8Array,
66
124
  attributeType: string,
67
- componentType: string,
125
+ componentType: NumericComponentType,
68
126
  elementCount: number = 1
69
- ): TypedArray {
127
+ ): BigTypedArray | null {
70
128
  const numberOfComponents = ATTRIBUTE_TYPE_TO_COMPONENTS[attributeType];
71
129
  const ArrayType = ATTRIBUTE_COMPONENT_TYPE_TO_ARRAY[componentType];
72
- const length = elementCount * numberOfComponents;
73
130
  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);
131
+ const length = elementCount * numberOfComponents;
132
+ const byteLength = length * size;
133
+ let buffer = data.buffer;
134
+ let offset = data.byteOffset;
135
+ if (offset % size !== 0) {
136
+ const bufferArray = new Uint8Array(buffer);
137
+ buffer = bufferArray.slice(offset, offset + byteLength).buffer;
138
+ offset = 0;
139
+ }
140
+ return new ArrayType(buffer, offset, length);
80
141
  }
81
142
 
82
143
  /**
83
144
  * Processes data encoded in the texture associated with the primitive.
84
145
  * 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.
146
+ * @param scenegraph - Instance of the class for structured access to GLTF data.
147
+ * @param textureInfo - reference to the texture where extension data are stored.
148
+ * @param primitive - primitive object in the mesh
149
+ * @returns Array of data taken. Null if data can't be taken from the texture.
89
150
  */
90
151
  export function getPrimitiveTextureData(
91
152
  scenegraph: GLTFScenegraph,
@@ -147,11 +208,11 @@ export function getPrimitiveTextureData(
147
208
  * Puts property data to attributes.
148
209
  * It creates corresponding buffer, bufferView and accessor
149
210
  * 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
211
+ * @param scenegraph - scenegraph object
212
+ * @param attributeName - name of the attribute
213
+ * @param propertyData - property data to store
214
+ * @param featureTable - an array where unique data from the property data are being stored
215
+ * @param primitive - primitive object
155
216
  */
156
217
  export function primitivePropertyDataToAttributes(
157
218
  scenegraph: GLTFScenegraph,
@@ -194,12 +255,12 @@ export function primitivePropertyDataToAttributes(
194
255
 
195
256
  /**
196
257
  * 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.
258
+ * @param parsedImage - image where the data are stored.
259
+ * @param mimeType - MIME type
260
+ * @param textureCoordinates - uv coordinates to access data in the image.
261
+ * @param index - index of uv coordinates in the array textureCoordinates
262
+ * @param channels - image channels where data are stored. Channels of an RGBA texture are numbered 0..3 respectively.
263
+ * @returns Value taken from the image.
203
264
  */
204
265
  function getImageValueByCoordinates(
205
266
  parsedImage: ImageType,
@@ -115,7 +115,8 @@ export type GLTF_EXT_structural_metadata_ClassProperty = {
115
115
  | 'MAT4'
116
116
  | 'BOOLEAN'
117
117
  | 'STRING'
118
- | 'ENUM';
118
+ | 'ENUM'
119
+ | string;
119
120
 
120
121
  /** The datatype of the element's components. Only applicable to `SCALAR`, `VECN`, and `MATN` types. */
121
122
  componentType?:
@@ -128,7 +129,8 @@ export type GLTF_EXT_structural_metadata_ClassProperty = {
128
129
  | 'INT64'
129
130
  | 'UINT64'
130
131
  | 'FLOAT32'
131
- | 'FLOAT64';
132
+ | 'FLOAT64'
133
+ | string;
132
134
 
133
135
  /** Enum ID as declared in the `enums` dictionary. Required when `type` is `ENUM`. */
134
136
  enumType?: string;
@@ -261,12 +263,12 @@ export type GLTF_EXT_structural_metadata_PropertyTable_Property = {
261
263
  /**
262
264
  * The type of values in `arrayOffsets`.
263
265
  */
264
- arrayOffsetType?: 'UINT8' | 'UINT16' | 'UINT32' | 'UINT64';
266
+ arrayOffsetType?: 'UINT8' | 'UINT16' | 'UINT32' | 'UINT64' | string;
265
267
 
266
268
  /**
267
269
  * The type of values in `stringOffsets`.
268
270
  */
269
- stringOffsetType?: 'UINT8' | 'UINT16' | 'UINT32' | 'UINT64';
271
+ stringOffsetType?: 'UINT8' | 'UINT16' | 'UINT32' | 'UINT64' | string;
270
272
  /**
271
273
  * An offset to apply to property values.
272
274
  * Only applicable when the component type is `FLOAT32` or `FLOAT64`, or when the property is `normalized`.
@@ -1057,7 +1057,7 @@ export type GLTF_EXT_feature_metadata_FeatureTableProperty = {
1057
1057
  bufferView: number;
1058
1058
 
1059
1059
  /** The type of values in arrayOffsetBufferView and stringOffsetBufferView. */
1060
- offsetType?: string; // default: "UINT32"
1060
+ offsetType?: 'UINT8' | 'UINT16' | 'UINT32' | 'UINT64' | string; // default: "UINT32"
1061
1061
  /**
1062
1062
  * The index of the buffer view containing offsets for variable-length arrays.
1063
1063
  * The number of offsets is equal to the feature table count plus one.
package/dist/bundle.js DELETED
@@ -1,5 +0,0 @@
1
- "use strict";
2
- // @ts-nocheck
3
- const moduleExports = require('./index');
4
- globalThis.loaders = globalThis.loaders || {};
5
- module.exports = Object.assign(globalThis.loaders, moduleExports);
@@ -1 +0,0 @@
1
- {"version":3,"file":"data-processing.js","names":["_gltfUtils","require","_images","_math","_createForOfIteratorHelper","o","allowArrayLike","it","Symbol","iterator","Array","isArray","_unsupportedIterableToArray","length","i","F","s","n","done","value","e","_e","f","TypeError","normalCompletion","didErr","err","call","step","next","_e2","return","minLen","_arrayLikeToArray","Object","prototype","toString","slice","constructor","name","from","test","arr","len","arr2","ATTRIBUTE_TYPE_TO_COMPONENTS","SCALAR","VEC2","VEC3","VEC4","MAT2","MAT3","MAT4","BOOLEAN","STRING","ENUM","ATTRIBUTE_COMPONENT_TYPE_TO_ARRAY","INT8","Int8Array","UINT8","Uint8Array","INT16","Int16Array","UINT16","Uint16Array","INT32","Int32Array","UINT32","Uint32Array","INT64","BigInt64Array","UINT64","BigUint64Array","FLOAT32","Float32Array","FLOAT64","Float64Array","ATTRIBUTE_COMPONENT_TYPE_TO_BYTE_SIZE","getArrayElementByteSize","attributeType","componentType","convertRawBufferToMetadataArray","typedArray","elementCount","arguments","undefined","numberOfComponents","ArrayType","size","offset","byteOffset","Math","ceil","buffer","getPrimitiveTextureData","scenegraph","textureInfo","primitive","_json$textures","_json$textures$textur","json","gltf","texCoordAccessorKey","concat","texCoord","texCoordAccessorIndex","attributes","texCoordBufferView","getBufferView","texCoordArray","getTypedArrayForBufferView","textureCoordinates","textureIndex","index","imageIndex","textures","source","_json$images","_json$images$imageInd","_scenegraph$gltf$imag","mimeType","images","parsedImage","width","textureData","getImageValueByCoordinates","channels","push","primitivePropertyDataToAttributes","attributeName","propertyData","featureTable","featureIndices","_iterator","_step","_loop","texelData","findIndex","item","bufferIndex","buffers","arrayBuffer","byteLength","bufferViewIndex","addBufferView","accessorIndex","addAccessor","getComponentTypeFromArray","count","CHANNELS_MAP","shift","u","v","components","indexOf","coordinatesToOffset","_iterator2","_step2","c","map","imageOffset","imageData","getImageData","data","Error","imageValue","componentsCount","w","iX","emod","indX","round","h","height","iY","indY"],"sources":["../../../../src/lib/extensions/data-processing.ts"],"sourcesContent":["import type {GLTFTextureInfoMetadata, GLTFMeshPrimitive} from '../types/gltf-json-schema';\nimport type {TypedArray} from '@loaders.gl/schema';\nimport type {ImageType} from '@loaders.gl/images';\n\nimport {GLTFScenegraph} from '../api/gltf-scenegraph';\nimport {getComponentTypeFromArray} from '../gltf-utils/gltf-utils';\nimport {getImageData} from '@loaders.gl/images';\nimport {emod} from '@loaders.gl/math';\n\nconst ATTRIBUTE_TYPE_TO_COMPONENTS = {\n SCALAR: 1,\n VEC2: 2,\n VEC3: 3,\n VEC4: 4,\n MAT2: 4,\n MAT3: 9,\n MAT4: 16,\n BOOLEAN: 1,\n STRING: 1,\n ENUM: 1\n};\n\nconst ATTRIBUTE_COMPONENT_TYPE_TO_ARRAY = {\n INT8: Int8Array,\n UINT8: Uint8Array,\n INT16: Int16Array,\n UINT16: Uint16Array,\n INT32: Int32Array,\n UINT32: Uint32Array,\n INT64: BigInt64Array,\n UINT64: BigUint64Array,\n FLOAT32: Float32Array,\n FLOAT64: Float64Array\n};\n\nconst ATTRIBUTE_COMPONENT_TYPE_TO_BYTE_SIZE = {\n INT8: 1,\n UINT8: 1,\n INT16: 2,\n UINT16: 2,\n INT32: 4,\n UINT32: 4,\n INT64: 8,\n UINT64: 8,\n FLOAT32: 4,\n FLOAT64: 8\n};\n\nexport function getArrayElementByteSize(attributeType, componentType): number {\n return (\n ATTRIBUTE_COMPONENT_TYPE_TO_BYTE_SIZE[componentType] *\n ATTRIBUTE_TYPE_TO_COMPONENTS[attributeType]\n );\n}\n\n/**\n * Converts raw bytes that are in the buffer to an array of the type defined by the schema.\n * @param {Uint8Array} typedArray - raw bytes in the buffer\n * @param {string} attributeType - SCALAR, VECN, MATN\n * @param {string} componentType - type of the component in elements, e.g. 'UINT8' or 'FLOAT32'\n * @param {number} elementCount - number of elements in the array. Default value is 1.\n * @returns {TypedArray} Data array\n */\nexport function convertRawBufferToMetadataArray(\n typedArray: Uint8Array,\n attributeType: string,\n componentType: string,\n elementCount: number = 1\n): TypedArray {\n const numberOfComponents = ATTRIBUTE_TYPE_TO_COMPONENTS[attributeType];\n const ArrayType = ATTRIBUTE_COMPONENT_TYPE_TO_ARRAY[componentType];\n const length = elementCount * numberOfComponents;\n const size = ATTRIBUTE_COMPONENT_TYPE_TO_BYTE_SIZE[componentType];\n // the buffer view `byteOffset` must be aligned to a multiple of the `componentType` size.\n const offset =\n typedArray.byteOffset % size\n ? Math.ceil(typedArray.byteOffset / size) * size\n : typedArray.byteOffset;\n return new ArrayType(typedArray.buffer, offset, length);\n}\n\n/**\n * Processes data encoded in the texture associated with the primitive.\n * If Ext_mesh_featues is combined with the Ext_structural_metadata, propertyTable will also be processed.\n * @param {GLTFScenegraph} scenegraph - Instance of the class for structured access to GLTF data.\n * @param {GLTFTextureInfoMetadata} textureInfo - reference to the texture where extension data are stored.\n * @param {GLTFMeshPrimitive} primitive - primitive object in the mesh\n * @returns {number[] | null} Array of data taken. Null if data can't be taken from the texture.\n */\nexport function getPrimitiveTextureData(\n scenegraph: GLTFScenegraph,\n textureInfo: GLTFTextureInfoMetadata,\n primitive: GLTFMeshPrimitive\n): number[] | null {\n /*\n texture.index is an index for the \"textures\" array.\n The texture object referenced by this index looks like this:\n {\n \"sampler\": 0,\n \"source\": 0\n }\n \"sampler\" is an index for the \"samplers\" array\n \"source\" is an index for the \"images\" array that contains data. These data are stored in rgba channels of the image.\n\n texture.texCoord is a number-suffix (like 1) for an attribute like \"TEXCOORD_1\" in meshes.primitives\n 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.\n */\n const json = scenegraph.gltf.json;\n\n const texCoordAccessorKey = `TEXCOORD_${textureInfo.texCoord || 0}`;\n const texCoordAccessorIndex = primitive.attributes[texCoordAccessorKey];\n const texCoordBufferView = scenegraph.getBufferView(texCoordAccessorIndex);\n const texCoordArray: Uint8Array = scenegraph.getTypedArrayForBufferView(texCoordBufferView);\n\n // textureCoordinates array contains UV coordinates of the actual data stored in the texture\n const textureCoordinates: Float32Array = new Float32Array(\n texCoordArray.buffer,\n texCoordArray.byteOffset,\n texCoordArray.length / 4\n );\n\n const textureIndex: number = textureInfo.index;\n const imageIndex = json.textures?.[textureIndex]?.source;\n if (typeof imageIndex !== 'undefined') {\n const mimeType = json.images?.[imageIndex]?.mimeType;\n const parsedImage = scenegraph.gltf.images?.[imageIndex];\n // Checking for width is to prevent handling Un-processed images (e.g. [analyze] stage, where loadImages option is set to false)\n if (parsedImage && typeof parsedImage.width !== 'undefined') {\n const textureData: number[] = [];\n for (let index = 0; index < textureCoordinates.length; index += 2) {\n const value = getImageValueByCoordinates(\n parsedImage,\n mimeType,\n textureCoordinates,\n index,\n textureInfo.channels\n );\n textureData.push(value);\n }\n return textureData;\n }\n }\n return null;\n}\n\n/**\n * Puts property data to attributes.\n * It creates corresponding buffer, bufferView and accessor\n * so the data can be accessed like regular data stored in buffers.\n * @param {GLTFScenegraph} scenegraph - scenegraph object\n * @param {string} attributeName - name of the attribute\n * @param {number[]} propertyData - property data to store\n * @param {number[]} featureTable - an array where unique data from the property data are being stored\n * @param {GLTFMeshPrimitive} primitive - primitive object\n */\nexport function primitivePropertyDataToAttributes(\n scenegraph: GLTFScenegraph,\n attributeName: string,\n propertyData: number[],\n featureTable: number[],\n primitive: GLTFMeshPrimitive\n): void {\n if (propertyData === null) return;\n /*\n featureTable will contain unique values, e.g.\n propertyData = [24, 35, 28, 24]\n featureTable = [24, 35, 28]\n featureIndices will contain indices that refer featureTextureTable, e.g.\n featureIndices = [0, 1, 2, 0]\n */\n const featureIndices: number[] = [];\n for (const texelData of propertyData) {\n let index = featureTable.findIndex((item) => item === texelData);\n if (index === -1) {\n index = featureTable.push(texelData) - 1;\n }\n featureIndices.push(index);\n }\n const typedArray = new Uint32Array(featureIndices);\n const bufferIndex =\n scenegraph.gltf.buffers.push({\n arrayBuffer: typedArray.buffer,\n byteOffset: typedArray.byteOffset,\n byteLength: typedArray.byteLength\n }) - 1;\n const bufferViewIndex = scenegraph.addBufferView(typedArray, bufferIndex, 0);\n const accessorIndex = scenegraph.addAccessor(bufferViewIndex, {\n size: 1,\n componentType: getComponentTypeFromArray(typedArray),\n count: typedArray.length\n });\n primitive.attributes[attributeName] = accessorIndex;\n}\n\n/**\n * Gets the value from the texture by coordinates provided.\n * @param {ImageType} parsedImage - image where the data are stored.\n * @param {string | undefined} mimeType - MIME type\n * @param {Float32Array} textureCoordinates - uv coordinates to access data in the image.\n * @param {number} index - index of uv coordinates in the array textureCoordinates\n * @param {channels} channels - image channels where data are stored. Channels of an RGBA texture are numbered 0..3 respectively.\n * @returns {number} Value taken from the image.\n */\nfunction getImageValueByCoordinates(\n parsedImage: ImageType,\n mimeType: string | undefined,\n textureCoordinates: Float32Array,\n index: number,\n channels: number[] = [0]\n) {\n const CHANNELS_MAP = [\n {offset: 0, shift: 0},\n {offset: 1, shift: 8},\n {offset: 2, shift: 16},\n {offset: 3, shift: 24}\n ];\n\n const u = textureCoordinates[index];\n const v = textureCoordinates[index + 1];\n\n let components = 1;\n if (mimeType && (mimeType.indexOf('image/jpeg') !== -1 || mimeType.indexOf('image/png') !== -1))\n components = 4;\n const offset = coordinatesToOffset(u, v, parsedImage, components);\n let value: number = 0;\n for (const c of channels) {\n const map = CHANNELS_MAP[c];\n const imageOffset = offset + map.offset;\n const imageData = getImageData(parsedImage);\n if (imageData.data.length <= imageOffset) {\n throw new Error(`${imageData.data.length} <= ${imageOffset}`);\n }\n const imageValue = imageData.data[imageOffset];\n value |= imageValue << map.shift;\n }\n return value;\n}\n\n/**\n * Retrieves the offset in the image where the data are stored\n * @param u - u-coordinate\n * @param v - v-coordinate\n * @param parsedImage - image where the data are stored\n * @param componentsCount - number of components the data consists of.\n * @returns offset in the image where the data are stored\n */\nfunction coordinatesToOffset(\n u: number,\n v: number,\n parsedImage: any,\n componentsCount: number = 1\n): number {\n const w = parsedImage.width;\n const iX = emod(u) * (w - 1);\n const indX = Math.round(iX);\n\n const h = parsedImage.height;\n const iY = emod(v) * (h - 1);\n const indY = Math.round(iY);\n const components = parsedImage.components ? parsedImage.components : componentsCount;\n // components is a number of channels in the image\n const offset = (indY * w + indX) * components;\n return offset;\n}\n"],"mappings":";;;;;;;;;AAKA,IAAAA,UAAA,GAAAC,OAAA;AACA,IAAAC,OAAA,GAAAD,OAAA;AACA,IAAAE,KAAA,GAAAF,OAAA;AAAsC,SAAAG,2BAAAC,CAAA,EAAAC,cAAA,QAAAC,EAAA,UAAAC,MAAA,oBAAAH,CAAA,CAAAG,MAAA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AACgF,KAAK,CAACH,EAAE,CAAC;EAE3B,IAAMI,CAAC,GAAGlD,WAAW,CAACmD,MAAM;EAC5B,IAAMC,EAAE,GAAG,IAAAL,UAAI,EAACjB,CAAC,CAAC,IAAIoB,CAAC,GAAG,CAAC,CAAC;EAC5B,IAAMG,IAAI,GAAGpF,IAAI,CAACgF,KAAK,CAACG,EAAE,CAAC;EAC3B,IAAMrB,UAAU,GAAG/B,WAAW,CAAC+B,UAAU,GAAG/B,WAAW,CAAC+B,UAAU,GAAGa,eAAe;EAEpF,IAAM7E,MAAM,GAAG,CAACsF,IAAI,GAAGR,CAAC,GAAGG,IAAI,IAAIjB,UAAU;EAC7C,OAAOhE,MAAM;AACf"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"data-processing.js","names":["getComponentTypeFromArray","getImageData","emod","ATTRIBUTE_TYPE_TO_COMPONENTS","SCALAR","VEC2","VEC3","VEC4","MAT2","MAT3","MAT4","BOOLEAN","STRING","ENUM","ATTRIBUTE_COMPONENT_TYPE_TO_ARRAY","INT8","Int8Array","UINT8","Uint8Array","INT16","Int16Array","UINT16","Uint16Array","INT32","Int32Array","UINT32","Uint32Array","INT64","BigInt64Array","UINT64","BigUint64Array","FLOAT32","Float32Array","FLOAT64","Float64Array","ATTRIBUTE_COMPONENT_TYPE_TO_BYTE_SIZE","getArrayElementByteSize","attributeType","componentType","convertRawBufferToMetadataArray","typedArray","elementCount","arguments","length","undefined","numberOfComponents","ArrayType","size","offset","byteOffset","Math","ceil","buffer","getPrimitiveTextureData","scenegraph","textureInfo","primitive","_json$textures","_json$textures$textur","json","gltf","texCoordAccessorKey","concat","texCoord","texCoordAccessorIndex","attributes","texCoordBufferView","getBufferView","texCoordArray","getTypedArrayForBufferView","textureCoordinates","textureIndex","index","imageIndex","textures","source","_json$images","_json$images$imageInd","_scenegraph$gltf$imag","mimeType","images","parsedImage","width","textureData","value","getImageValueByCoordinates","channels","push","primitivePropertyDataToAttributes","attributeName","propertyData","featureTable","featureIndices","texelData","findIndex","item","bufferIndex","buffers","arrayBuffer","byteLength","bufferViewIndex","addBufferView","accessorIndex","addAccessor","count","CHANNELS_MAP","shift","u","v","components","indexOf","coordinatesToOffset","c","map","imageOffset","imageData","data","Error","imageValue","componentsCount","w","iX","indX","round","h","height","iY","indY"],"sources":["../../../../src/lib/extensions/data-processing.ts"],"sourcesContent":["import type {GLTFTextureInfoMetadata, GLTFMeshPrimitive} from '../types/gltf-json-schema';\nimport type {TypedArray} from '@loaders.gl/schema';\nimport type {ImageType} from '@loaders.gl/images';\n\nimport {GLTFScenegraph} from '../api/gltf-scenegraph';\nimport {getComponentTypeFromArray} from '../gltf-utils/gltf-utils';\nimport {getImageData} from '@loaders.gl/images';\nimport {emod} from '@loaders.gl/math';\n\nconst ATTRIBUTE_TYPE_TO_COMPONENTS = {\n SCALAR: 1,\n VEC2: 2,\n VEC3: 3,\n VEC4: 4,\n MAT2: 4,\n MAT3: 9,\n MAT4: 16,\n BOOLEAN: 1,\n STRING: 1,\n ENUM: 1\n};\n\nconst ATTRIBUTE_COMPONENT_TYPE_TO_ARRAY = {\n INT8: Int8Array,\n UINT8: Uint8Array,\n INT16: Int16Array,\n UINT16: Uint16Array,\n INT32: Int32Array,\n UINT32: Uint32Array,\n INT64: BigInt64Array,\n UINT64: BigUint64Array,\n FLOAT32: Float32Array,\n FLOAT64: Float64Array\n};\n\nconst ATTRIBUTE_COMPONENT_TYPE_TO_BYTE_SIZE = {\n INT8: 1,\n UINT8: 1,\n INT16: 2,\n UINT16: 2,\n INT32: 4,\n UINT32: 4,\n INT64: 8,\n UINT64: 8,\n FLOAT32: 4,\n FLOAT64: 8\n};\n\nexport function getArrayElementByteSize(attributeType, componentType): number {\n return (\n ATTRIBUTE_COMPONENT_TYPE_TO_BYTE_SIZE[componentType] *\n ATTRIBUTE_TYPE_TO_COMPONENTS[attributeType]\n );\n}\n\n/**\n * Converts raw bytes that are in the buffer to an array of the type defined by the schema.\n * @param {Uint8Array} typedArray - raw bytes in the buffer\n * @param {string} attributeType - SCALAR, VECN, MATN\n * @param {string} componentType - type of the component in elements, e.g. 'UINT8' or 'FLOAT32'\n * @param {number} elementCount - number of elements in the array. Default value is 1.\n * @returns {TypedArray} Data array\n */\nexport function convertRawBufferToMetadataArray(\n typedArray: Uint8Array,\n attributeType: string,\n componentType: string,\n elementCount: number = 1\n): TypedArray {\n const numberOfComponents = ATTRIBUTE_TYPE_TO_COMPONENTS[attributeType];\n const ArrayType = ATTRIBUTE_COMPONENT_TYPE_TO_ARRAY[componentType];\n const length = elementCount * numberOfComponents;\n const size = ATTRIBUTE_COMPONENT_TYPE_TO_BYTE_SIZE[componentType];\n // the buffer view `byteOffset` must be aligned to a multiple of the `componentType` size.\n const offset =\n typedArray.byteOffset % size\n ? Math.ceil(typedArray.byteOffset / size) * size\n : typedArray.byteOffset;\n return new ArrayType(typedArray.buffer, offset, length);\n}\n\n/**\n * Processes data encoded in the texture associated with the primitive.\n * If Ext_mesh_featues is combined with the Ext_structural_metadata, propertyTable will also be processed.\n * @param {GLTFScenegraph} scenegraph - Instance of the class for structured access to GLTF data.\n * @param {GLTFTextureInfoMetadata} textureInfo - reference to the texture where extension data are stored.\n * @param {GLTFMeshPrimitive} primitive - primitive object in the mesh\n * @returns {number[] | null} Array of data taken. Null if data can't be taken from the texture.\n */\nexport function getPrimitiveTextureData(\n scenegraph: GLTFScenegraph,\n textureInfo: GLTFTextureInfoMetadata,\n primitive: GLTFMeshPrimitive\n): number[] | null {\n /*\n texture.index is an index for the \"textures\" array.\n The texture object referenced by this index looks like this:\n {\n \"sampler\": 0,\n \"source\": 0\n }\n \"sampler\" is an index for the \"samplers\" array\n \"source\" is an index for the \"images\" array that contains data. These data are stored in rgba channels of the image.\n\n texture.texCoord is a number-suffix (like 1) for an attribute like \"TEXCOORD_1\" in meshes.primitives\n 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.\n */\n const json = scenegraph.gltf.json;\n\n const texCoordAccessorKey = `TEXCOORD_${textureInfo.texCoord || 0}`;\n const texCoordAccessorIndex = primitive.attributes[texCoordAccessorKey];\n const texCoordBufferView = scenegraph.getBufferView(texCoordAccessorIndex);\n const texCoordArray: Uint8Array = scenegraph.getTypedArrayForBufferView(texCoordBufferView);\n\n // textureCoordinates array contains UV coordinates of the actual data stored in the texture\n const textureCoordinates: Float32Array = new Float32Array(\n texCoordArray.buffer,\n texCoordArray.byteOffset,\n texCoordArray.length / 4\n );\n\n const textureIndex: number = textureInfo.index;\n const imageIndex = json.textures?.[textureIndex]?.source;\n if (typeof imageIndex !== 'undefined') {\n const mimeType = json.images?.[imageIndex]?.mimeType;\n const parsedImage = scenegraph.gltf.images?.[imageIndex];\n // Checking for width is to prevent handling Un-processed images (e.g. [analyze] stage, where loadImages option is set to false)\n if (parsedImage && typeof parsedImage.width !== 'undefined') {\n const textureData: number[] = [];\n for (let index = 0; index < textureCoordinates.length; index += 2) {\n const value = getImageValueByCoordinates(\n parsedImage,\n mimeType,\n textureCoordinates,\n index,\n textureInfo.channels\n );\n textureData.push(value);\n }\n return textureData;\n }\n }\n return null;\n}\n\n/**\n * Puts property data to attributes.\n * It creates corresponding buffer, bufferView and accessor\n * so the data can be accessed like regular data stored in buffers.\n * @param {GLTFScenegraph} scenegraph - scenegraph object\n * @param {string} attributeName - name of the attribute\n * @param {number[]} propertyData - property data to store\n * @param {number[]} featureTable - an array where unique data from the property data are being stored\n * @param {GLTFMeshPrimitive} primitive - primitive object\n */\nexport function primitivePropertyDataToAttributes(\n scenegraph: GLTFScenegraph,\n attributeName: string,\n propertyData: number[],\n featureTable: number[],\n primitive: GLTFMeshPrimitive\n): void {\n if (propertyData === null) return;\n /*\n featureTable will contain unique values, e.g.\n propertyData = [24, 35, 28, 24]\n featureTable = [24, 35, 28]\n featureIndices will contain indices that refer featureTextureTable, e.g.\n featureIndices = [0, 1, 2, 0]\n */\n const featureIndices: number[] = [];\n for (const texelData of propertyData) {\n let index = featureTable.findIndex((item) => item === texelData);\n if (index === -1) {\n index = featureTable.push(texelData) - 1;\n }\n featureIndices.push(index);\n }\n const typedArray = new Uint32Array(featureIndices);\n const bufferIndex =\n scenegraph.gltf.buffers.push({\n arrayBuffer: typedArray.buffer,\n byteOffset: typedArray.byteOffset,\n byteLength: typedArray.byteLength\n }) - 1;\n const bufferViewIndex = scenegraph.addBufferView(typedArray, bufferIndex, 0);\n const accessorIndex = scenegraph.addAccessor(bufferViewIndex, {\n size: 1,\n componentType: getComponentTypeFromArray(typedArray),\n count: typedArray.length\n });\n primitive.attributes[attributeName] = accessorIndex;\n}\n\n/**\n * Gets the value from the texture by coordinates provided.\n * @param {ImageType} parsedImage - image where the data are stored.\n * @param {string | undefined} mimeType - MIME type\n * @param {Float32Array} textureCoordinates - uv coordinates to access data in the image.\n * @param {number} index - index of uv coordinates in the array textureCoordinates\n * @param {channels} channels - image channels where data are stored. Channels of an RGBA texture are numbered 0..3 respectively.\n * @returns {number} Value taken from the image.\n */\nfunction getImageValueByCoordinates(\n parsedImage: ImageType,\n mimeType: string | undefined,\n textureCoordinates: Float32Array,\n index: number,\n channels: number[] = [0]\n) {\n const CHANNELS_MAP = [\n {offset: 0, shift: 0},\n {offset: 1, shift: 8},\n {offset: 2, shift: 16},\n {offset: 3, shift: 24}\n ];\n\n const u = textureCoordinates[index];\n const v = textureCoordinates[index + 1];\n\n let components = 1;\n if (mimeType && (mimeType.indexOf('image/jpeg') !== -1 || mimeType.indexOf('image/png') !== -1))\n components = 4;\n const offset = coordinatesToOffset(u, v, parsedImage, components);\n let value: number = 0;\n for (const c of channels) {\n const map = CHANNELS_MAP[c];\n const imageOffset = offset + map.offset;\n const imageData = getImageData(parsedImage);\n if (imageData.data.length <= imageOffset) {\n throw new Error(`${imageData.data.length} <= ${imageOffset}`);\n }\n const imageValue = imageData.data[imageOffset];\n value |= imageValue << map.shift;\n }\n return value;\n}\n\n/**\n * Retrieves the offset in the image where the data are stored\n * @param u - u-coordinate\n * @param v - v-coordinate\n * @param parsedImage - image where the data are stored\n * @param componentsCount - number of components the data consists of.\n * @returns offset in the image where the data are stored\n */\nfunction coordinatesToOffset(\n u: number,\n v: number,\n parsedImage: any,\n componentsCount: number = 1\n): number {\n const w = parsedImage.width;\n const iX = emod(u) * (w - 1);\n const indX = Math.round(iX);\n\n const h = parsedImage.height;\n const iY = emod(v) * (h - 1);\n const indY = Math.round(iY);\n const components = parsedImage.components ? parsedImage.components : componentsCount;\n // components is a number of channels in the image\n const offset = (indY * w + indX) * components;\n return offset;\n}\n"],"mappings":"AAKA,SAAQA,yBAAyB,QAAO,0BAA0B;AAClE,SAAQC,YAAY,QAAO,oBAAoB;AAC/C,SAAQC,IAAI,QAAO,kBAAkB;AAErC,MAAMC,4BAA4B,GAAG;EACnCC,MAAM,EAAE,CAAC;EACTC,IAAI,EAAE,CAAC;EACPC,IAAI,EAAE,CAAC;EACPC,IAAI,EAAE,CAAC;EACPC,IAAI,EAAE,CAAC;EACPC,IAAI,EAAE,CAAC;EACPC,IAAI,EAAE,EAAE;EACRC,OAAO,EAAE,CAAC;EACVC,MAAM,EAAE,CAAC;EACTC,IAAI,EAAE;AACR,CAAC;AAED,MAAMC,iCAAiC,GAAG;EACxCC,IAAI,EAAEC,SAAS;EACfC,KAAK,EAAEC,UAAU;EACjBC,KAAK,EAAEC,UAAU;EACjBC,MAAM,EAAEC,WAAW;EACnBC,KAAK,EAAEC,UAAU;EACjBC,MAAM,EAAEC,WAAW;EACnBC,KAAK,EAAEC,aAAa;EACpBC,MAAM,EAAEC,cAAc;EACtBC,OAAO,EAAEC,YAAY;EACrBC,OAAO,EAAEC;AACX,CAAC;AAED,MAAMC,qCAAqC,GAAG;EAC5CpB,IAAI,EAAE,CAAC;EACPE,KAAK,EAAE,CAAC;EACRE,KAAK,EAAE,CAAC;EACRE,MAAM,EAAE,CAAC;EACTE,KAAK,EAAE,CAAC;EACRE,MAAM,EAAE,CAAC;EACTE,KAAK,EAAE,CAAC;EACRE,MAAM,EAAE,CAAC;EACTE,OAAO,E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,CAAOoD,WAAW,CAAE,CAAC;IAC/D;IACA,MAAMI,UAAU,GAAGH,SAAS,CAACC,IAAI,CAACF,WAAW,CAAC;IAC9C9B,KAAK,IAAIkC,UAAU,IAAIL,GAAG,CAACP,KAAK;EAClC;EACA,OAAOtB,KAAK;AACd;AAUA,SAAS2B,mBAAmBA,CAC1BJ,CAAS,EACTC,CAAS,EACT3B,WAAgB,EAER;EAAA,IADRsC,eAAuB,GAAA7E,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAG,CAAC;EAE3B,MAAM8E,CAAC,GAAGvC,WAAW,CAACC,KAAK;EAC3B,MAAMuC,EAAE,GAAGvH,IAAI,CAACyG,CAAC,CAAC,IAAIa,CAAC,GAAG,CAAC,CAAC;EAC5B,MAAME,IAAI,GAAGxE,IAAI,CAACyE,KAAK,CAACF,EAAE,CAAC;EAE3B,MAAMG,CAAC,GAAG3C,WAAW,CAAC4C,MAAM;EAC5B,MAAMC,EAAE,GAAG5H,IAAI,CAAC0G,CAAC,CAAC,IAAIgB,CAAC,GAAG,CAAC,CAAC;EAC5B,MAAMG,IAAI,GAAG7E,IAAI,CAACyE,KAAK,CAACG,EAAE,CAAC;EAC3B,MAAMjB,UAAU,GAAG5B,WAAW,CAAC4B,UAAU,GAAG5B,WAAW,CAAC4B,UAAU,GAAGU,eAAe;EAEpF,MAAMvE,MAAM,GAAG,CAAC+E,IAAI,GAAGP,CAAC,GAAGE,IAAI,IAAIb,UAAU;EAC7C,OAAO7D,MAAM;AACf"}
@@ -1,34 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.GLBLoader = void 0;
4
- const version_1 = require("./lib/utils/version");
5
- const parse_glb_1 = require("./lib/parsers/parse-glb");
6
- /**
7
- * GLB Loader -
8
- * GLB is the binary container format for GLTF
9
- */
10
- exports.GLBLoader = {
11
- name: 'GLB',
12
- id: 'glb',
13
- module: 'gltf',
14
- version: version_1.VERSION,
15
- extensions: ['glb'],
16
- mimeTypes: ['model/gltf-binary'],
17
- binary: true,
18
- parse,
19
- parseSync,
20
- options: {
21
- glb: {
22
- strict: false // Enables deprecated XVIZ support (illegal CHUNK formats)
23
- }
24
- }
25
- };
26
- async function parse(arrayBuffer, options) {
27
- return parseSync(arrayBuffer, options);
28
- }
29
- function parseSync(arrayBuffer, options) {
30
- const { byteOffset = 0 } = options || {};
31
- const glb = {};
32
- (0, parse_glb_1.parseGLBSync)(glb, arrayBuffer, byteOffset, options?.glb);
33
- return glb;
34
- }
@@ -1,35 +0,0 @@
1
- "use strict";
2
- // loaders.gl, MIT license
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- exports._TypecheckGLBLoader = exports.GLBWriter = void 0;
5
- const encode_glb_1 = require("./lib/encoders/encode-glb");
6
- const version_1 = require("./lib/utils/version");
7
- /**
8
- * GLB exporter
9
- * GLB is the binary container format for GLTF
10
- */
11
- exports.GLBWriter = {
12
- name: 'GLB',
13
- id: 'glb',
14
- module: 'gltf',
15
- version: version_1.VERSION,
16
- extensions: ['glb'],
17
- mimeTypes: ['model/gltf-binary'],
18
- binary: true,
19
- encodeSync,
20
- options: {
21
- glb: {}
22
- }
23
- };
24
- function encodeSync(glb, options) {
25
- const { byteOffset = 0 } = options;
26
- // Calculate length and allocate buffer
27
- const byteLength = (0, encode_glb_1.encodeGLBSync)(glb, null, byteOffset, options);
28
- const arrayBuffer = new ArrayBuffer(byteLength);
29
- // Encode into buffer
30
- const dataView = new DataView(arrayBuffer);
31
- (0, encode_glb_1.encodeGLBSync)(glb, dataView, byteOffset, options);
32
- return arrayBuffer;
33
- }
34
- // TYPE TESTS - TODO find a better way than exporting junk
35
- exports._TypecheckGLBLoader = exports.GLBWriter;
@@ -1,50 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.parse = exports.GLTFLoader = void 0;
4
- const version_1 = require("./lib/utils/version");
5
- const parse_gltf_1 = require("./lib/parsers/parse-gltf");
6
- /**
7
- * GLTF loader
8
- */
9
- exports.GLTFLoader = {
10
- name: 'glTF',
11
- id: 'gltf',
12
- module: 'gltf',
13
- version: version_1.VERSION,
14
- extensions: ['gltf', 'glb'],
15
- mimeTypes: ['model/gltf+json', 'model/gltf-binary'],
16
- text: true,
17
- binary: true,
18
- tests: ['glTF'],
19
- parse,
20
- options: {
21
- gltf: {
22
- normalize: true,
23
- loadBuffers: true,
24
- loadImages: true,
25
- decompressMeshes: true // Decompress Draco encoded meshes
26
- },
27
- // common?
28
- log: console // eslint-disable-line
29
- },
30
- deprecatedOptions: {
31
- fetchImages: 'gltf.loadImages',
32
- createImages: 'gltf.loadImages',
33
- decompress: 'gltf.decompressMeshes',
34
- postProcess: 'gltf.postProcess',
35
- gltf: {
36
- decompress: 'gltf.decompressMeshes',
37
- postProcess: 'removed in v4'
38
- }
39
- }
40
- };
41
- async function parse(arrayBuffer, options = {}, context) {
42
- // Apps can call the parse method directly, we so apply default options here
43
- options = { ...exports.GLTFLoader.options, ...options };
44
- // @ts-ignore
45
- options.gltf = { ...exports.GLTFLoader.options.gltf, ...options.gltf };
46
- const { byteOffset = 0 } = options;
47
- const gltf = {};
48
- return await (0, parse_gltf_1.parseGLTF)(gltf, arrayBuffer, byteOffset, options, context);
49
- }
50
- exports.parse = parse;
@@ -1,32 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports._TypecheckGLBLoader = exports.GLTFWriter = void 0;
4
- const version_1 = require("./lib/utils/version");
5
- const encode_gltf_1 = require("./lib/encoders/encode-gltf");
6
- /**
7
- * GLTF exporter
8
- */
9
- exports.GLTFWriter = {
10
- name: 'glTF',
11
- id: 'gltf',
12
- module: 'gltf',
13
- version: version_1.VERSION,
14
- extensions: ['glb'],
15
- mimeTypes: ['model/gltf-binary'],
16
- binary: true,
17
- encodeSync,
18
- options: {
19
- gltf: {}
20
- }
21
- };
22
- function encodeSync(gltf, options = {}) {
23
- const { byteOffset = 0 } = options;
24
- // Calculate length, then create arraybuffer and encode
25
- const byteLength = (0, encode_gltf_1.encodeGLTFSync)(gltf, null, byteOffset, options);
26
- const arrayBuffer = new ArrayBuffer(byteLength);
27
- const dataView = new DataView(arrayBuffer);
28
- (0, encode_gltf_1.encodeGLTFSync)(gltf, dataView, byteOffset, options);
29
- return arrayBuffer;
30
- }
31
- // TYPE TESTS - TODO find a better way than exporting junk
32
- exports._TypecheckGLBLoader = exports.GLTFWriter;