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

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 (123) hide show
  1. package/dist/dist.min.js +378 -241
  2. package/dist/es5/index.js +12 -0
  3. package/dist/es5/index.js.map +1 -1
  4. package/dist/es5/lib/api/gltf-extensions.js +1 -1
  5. package/dist/es5/lib/api/gltf-extensions.js.map +1 -1
  6. package/dist/es5/lib/extensions/EXT_mesh_features.js +13 -25
  7. package/dist/es5/lib/extensions/EXT_mesh_features.js.map +1 -1
  8. package/dist/es5/lib/extensions/EXT_structural_metadata.js +152 -106
  9. package/dist/es5/lib/extensions/EXT_structural_metadata.js.map +1 -1
  10. package/dist/es5/lib/extensions/deprecated/EXT_feature_metadata.js +64 -16
  11. package/dist/es5/lib/extensions/deprecated/EXT_feature_metadata.js.map +1 -1
  12. package/dist/es5/lib/extensions/{data-processing.js → utils/3d-tiles-utils.js} +51 -24
  13. package/dist/es5/lib/extensions/utils/3d-tiles-utils.js.map +1 -0
  14. package/dist/es5/lib/gltf-utils/gltf-utils.js +29 -0
  15. package/dist/es5/lib/gltf-utils/gltf-utils.js.map +1 -1
  16. package/dist/es5/lib/types/gltf-ext-feature-metadata-schema.js +2 -0
  17. package/dist/es5/lib/types/gltf-ext-feature-metadata-schema.js.map +1 -0
  18. package/dist/es5/lib/types/gltf-ext-mesh-features-schema.js.map +1 -1
  19. package/dist/es5/lib/types/gltf-ext-structural-metadata-schema.js.map +1 -1
  20. package/dist/es5/lib/types/gltf-json-schema.js.map +1 -1
  21. package/dist/es5/lib/types/gltf-types.js.map +1 -1
  22. package/dist/es5/lib/utils/version.js +1 -1
  23. package/dist/esm/index.js +2 -0
  24. package/dist/esm/index.js.map +1 -1
  25. package/dist/esm/lib/api/gltf-extensions.js +1 -1
  26. package/dist/esm/lib/api/gltf-extensions.js.map +1 -1
  27. package/dist/esm/lib/extensions/EXT_mesh_features.js +13 -25
  28. package/dist/esm/lib/extensions/EXT_mesh_features.js.map +1 -1
  29. package/dist/esm/lib/extensions/EXT_structural_metadata.js +127 -89
  30. package/dist/esm/lib/extensions/EXT_structural_metadata.js.map +1 -1
  31. package/dist/esm/lib/extensions/deprecated/EXT_feature_metadata.js +64 -17
  32. package/dist/esm/lib/extensions/deprecated/EXT_feature_metadata.js.map +1 -1
  33. package/dist/esm/lib/extensions/{data-processing.js → utils/3d-tiles-utils.js} +50 -24
  34. package/dist/esm/lib/extensions/utils/3d-tiles-utils.js.map +1 -0
  35. package/dist/esm/lib/gltf-utils/gltf-utils.js +30 -0
  36. package/dist/esm/lib/gltf-utils/gltf-utils.js.map +1 -1
  37. package/dist/esm/lib/types/gltf-ext-feature-metadata-schema.js +2 -0
  38. package/dist/esm/lib/types/gltf-ext-feature-metadata-schema.js.map +1 -0
  39. package/dist/esm/lib/types/gltf-ext-mesh-features-schema.js.map +1 -1
  40. package/dist/esm/lib/types/gltf-ext-structural-metadata-schema.js.map +1 -1
  41. package/dist/esm/lib/types/gltf-json-schema.js.map +1 -1
  42. package/dist/esm/lib/types/gltf-types.js.map +1 -1
  43. package/dist/esm/lib/utils/version.js +1 -1
  44. package/dist/index.d.ts +6 -3
  45. package/dist/index.d.ts.map +1 -1
  46. package/dist/lib/extensions/EXT_mesh_features.d.ts.map +1 -1
  47. package/dist/lib/extensions/EXT_structural_metadata.d.ts +12 -4
  48. package/dist/lib/extensions/EXT_structural_metadata.d.ts.map +1 -1
  49. package/dist/lib/extensions/deprecated/EXT_feature_metadata.d.ts +9 -0
  50. package/dist/lib/extensions/deprecated/EXT_feature_metadata.d.ts.map +1 -1
  51. package/dist/lib/extensions/utils/3d-tiles-utils.d.ts +52 -0
  52. package/dist/lib/extensions/utils/3d-tiles-utils.d.ts.map +1 -0
  53. package/dist/lib/gltf-utils/gltf-utils.d.ts +2 -0
  54. package/dist/lib/gltf-utils/gltf-utils.d.ts.map +1 -1
  55. package/dist/lib/types/gltf-ext-feature-metadata-schema.d.ts +421 -0
  56. package/dist/lib/types/gltf-ext-feature-metadata-schema.d.ts.map +1 -0
  57. package/dist/lib/types/gltf-ext-mesh-features-schema.d.ts +4 -6
  58. package/dist/lib/types/gltf-ext-mesh-features-schema.d.ts.map +1 -1
  59. package/dist/lib/types/gltf-ext-structural-metadata-schema.d.ts +48 -29
  60. package/dist/lib/types/gltf-ext-structural-metadata-schema.d.ts.map +1 -1
  61. package/dist/lib/types/gltf-json-schema.d.ts +1 -420
  62. package/dist/lib/types/gltf-json-schema.d.ts.map +1 -1
  63. package/dist/lib/types/gltf-types.d.ts +3 -0
  64. package/dist/lib/types/gltf-types.d.ts.map +1 -1
  65. package/package.json +6 -6
  66. package/src/index.ts +10 -5
  67. package/src/lib/api/gltf-extensions.ts +1 -1
  68. package/src/lib/extensions/EXT_mesh_features.ts +18 -44
  69. package/src/lib/extensions/EXT_structural_metadata.ts +364 -217
  70. package/src/lib/extensions/deprecated/EXT_feature_metadata.ts +193 -30
  71. package/src/lib/extensions/{data-processing.ts → utils/3d-tiles-utils.ts} +128 -56
  72. package/src/lib/gltf-utils/gltf-utils.ts +38 -0
  73. package/src/lib/types/gltf-ext-feature-metadata-schema.ts +470 -0
  74. package/src/lib/types/gltf-ext-mesh-features-schema.ts +4 -6
  75. package/src/lib/types/gltf-ext-structural-metadata-schema.ts +52 -31
  76. package/src/lib/types/gltf-json-schema.ts +1 -468
  77. package/src/lib/types/gltf-types.ts +4 -0
  78. package/dist/bundle.js +0 -5
  79. package/dist/es5/lib/extensions/data-processing.js.map +0 -1
  80. package/dist/esm/lib/extensions/data-processing.js.map +0 -1
  81. package/dist/glb-loader.js +0 -34
  82. package/dist/glb-writer.js +0 -35
  83. package/dist/gltf-loader.js +0 -50
  84. package/dist/gltf-writer.js +0 -32
  85. package/dist/index.js +0 -34
  86. package/dist/lib/api/gltf-extensions.js +0 -88
  87. package/dist/lib/api/gltf-scenegraph.js +0 -580
  88. package/dist/lib/api/normalize-gltf-v1.js +0 -299
  89. package/dist/lib/api/post-process-gltf.js +0 -433
  90. package/dist/lib/encoders/encode-glb.js +0 -72
  91. package/dist/lib/encoders/encode-gltf.js +0 -32
  92. package/dist/lib/extensions/EXT_mesh_features.js +0 -89
  93. package/dist/lib/extensions/EXT_meshopt_compression.js +0 -41
  94. package/dist/lib/extensions/EXT_structural_metadata.js +0 -504
  95. package/dist/lib/extensions/EXT_texture_webp.js +0 -36
  96. package/dist/lib/extensions/KHR_binary_gltf.js +0 -39
  97. package/dist/lib/extensions/KHR_draco_mesh_compression.js +0 -137
  98. package/dist/lib/extensions/KHR_texture_basisu.js +0 -29
  99. package/dist/lib/extensions/KHR_texture_transform.js +0 -227
  100. package/dist/lib/extensions/data-processing.d.ts +0 -34
  101. package/dist/lib/extensions/data-processing.d.ts.map +0 -1
  102. package/dist/lib/extensions/data-processing.js +0 -212
  103. package/dist/lib/extensions/deprecated/EXT_feature_metadata.js +0 -282
  104. package/dist/lib/extensions/deprecated/KHR_lights_punctual.js +0 -59
  105. package/dist/lib/extensions/deprecated/KHR_materials_unlit.js +0 -44
  106. package/dist/lib/extensions/deprecated/KHR_techniques_webgl.js +0 -79
  107. package/dist/lib/gltf-utils/get-typed-array.js +0 -41
  108. package/dist/lib/gltf-utils/gltf-attribute-utils.js +0 -73
  109. package/dist/lib/gltf-utils/gltf-constants.js +0 -43
  110. package/dist/lib/gltf-utils/gltf-utils.js +0 -90
  111. package/dist/lib/gltf-utils/resolve-url.js +0 -18
  112. package/dist/lib/parsers/parse-glb.js +0 -166
  113. package/dist/lib/parsers/parse-gltf.js +0 -185
  114. package/dist/lib/types/glb-types.js +0 -2
  115. package/dist/lib/types/gltf-ext-mesh-features-schema.js +0 -2
  116. package/dist/lib/types/gltf-ext-structural-metadata-schema.js +0 -2
  117. package/dist/lib/types/gltf-json-schema.js +0 -4
  118. package/dist/lib/types/gltf-postprocessed-schema.js +0 -4
  119. package/dist/lib/types/gltf-types.js +0 -3
  120. package/dist/lib/utils/assert.js +0 -12
  121. package/dist/lib/utils/version.js +0 -7
  122. package/dist/meshopt/meshopt-decoder.js +0 -118
  123. package/dist/webp/webp.js +0 -38
@@ -1,4 +1,7 @@
1
+ // GLTF EXTENSION: EXT_structural_metadata
2
+ // https://github.com/CesiumGS/glTF/blob/3d-tiles-next/extensions/2.0/Vendor/EXT_structural_metadata
1
3
  /* eslint-disable camelcase */
4
+ import type {BigTypedArray, TypedArray} from '@loaders.gl/schema';
2
5
  import type {GLTF, GLTFTextureInfoMetadata, GLTFMeshPrimitive} from '../types/gltf-json-schema';
3
6
  import type {
4
7
  GLTF_EXT_structural_metadata_Schema,
@@ -6,22 +9,23 @@ import type {
6
9
  GLTF_EXT_structural_metadata_Enum,
7
10
  GLTF_EXT_structural_metadata_EnumValue,
8
11
  GLTF_EXT_structural_metadata_PropertyTable,
9
- GLTF_EXT_structural_metadata,
12
+ GLTF_EXT_structural_metadata_GLTF,
10
13
  GLTF_EXT_structural_metadata_PropertyTexture,
11
14
  GLTF_EXT_structural_metadata_PropertyTable_Property,
12
15
  GLTF_EXT_structural_metadata_Primitive
13
16
  } from '../types/gltf-ext-structural-metadata-schema';
14
-
15
- import type {TypedArray} from '@loaders.gl/schema';
16
17
  import type {GLTFLoaderOptions} from '../../gltf-loader';
18
+ import type {FeatureTableJson} from '../types/gltf-types';
17
19
 
18
20
  import {GLTFScenegraph} from '../api/gltf-scenegraph';
19
21
  import {
20
22
  convertRawBufferToMetadataArray,
21
23
  getPrimitiveTextureData,
22
24
  primitivePropertyDataToAttributes,
23
- getArrayElementByteSize
24
- } from './data-processing';
25
+ getArrayElementByteSize,
26
+ NumericComponentType,
27
+ getOffsetsForProperty
28
+ } from './utils/3d-tiles-utils';
25
29
 
26
30
  const EXT_STRUCTURAL_METADATA_NAME = 'EXT_structural_metadata';
27
31
  export const name = EXT_STRUCTURAL_METADATA_NAME;
@@ -31,6 +35,52 @@ export async function decode(gltfData: {json: GLTF}, options: GLTFLoaderOptions)
31
35
  decodeExtStructuralMetadata(scenegraph, options);
32
36
  }
33
37
 
38
+ /**
39
+ * Handles EXT_structural_metadata to get property table.
40
+ * @param extension - Global level of EXT_STRUCTURAL_METADATA extension.
41
+ * @param metadataClass - User selected feature metadata class name.
42
+ * @returns {FeatureTableJson | null} Property table or null if the extension can't be handled properly.
43
+ */
44
+ export function getPropertyTableFromExtStructuralMetadata(
45
+ extension: GLTF_EXT_structural_metadata_GLTF,
46
+ metadataClass?: string
47
+ ): FeatureTableJson | null {
48
+ if (extension.propertyTables) {
49
+ /**
50
+ * Take only first feature table to generate attributes storage info object.
51
+ * TODO: Think about getting data from all feature tables?
52
+ * It can be tricky just because 3dTiles is able to have multiple featureId attributes and multiple feature tables.
53
+ * In I3S we should decide which featureIds attribute will be passed to geometry data.
54
+ */
55
+ const firstPropertyTable = extension?.propertyTables[0];
56
+ const propertyTableWithData = {};
57
+
58
+ for (const propertyName in firstPropertyTable.properties) {
59
+ propertyTableWithData[propertyName] = firstPropertyTable.properties[propertyName].data;
60
+ }
61
+
62
+ return propertyTableWithData;
63
+ }
64
+
65
+ if (extension.propertyTextures) {
66
+ // TODO: Think about getting data from all property textures.
67
+ const firstPropertyTexture = extension?.propertyTextures[0];
68
+ const propertyTableWithData = {};
69
+
70
+ for (const propertyName in firstPropertyTexture.properties) {
71
+ propertyTableWithData[propertyName] = firstPropertyTexture.properties[propertyName].data;
72
+ }
73
+
74
+ return propertyTableWithData;
75
+ }
76
+
77
+ // eslint-disable-next-line no-console
78
+ console.warn(
79
+ 'Cannot get property table from EXT_structural_metadata extension. There is neither propertyTables, nor propertyTextures in the extension.'
80
+ );
81
+ return null;
82
+ }
83
+
34
84
  /*
35
85
  // Example of the extension.
36
86
  // See more info at https://github.com/CesiumGS/glTF/tree/3d-tiles-next/extensions/2.0/Vendor/EXT_structural_metadata
@@ -90,16 +140,16 @@ const extensions = {
90
140
 
91
141
  /**
92
142
  * Returns the property table populated with the data taken according to the extension schema.
93
- * @param {GLTFScenegraph} scenegraph - Instance of the class for structured access to GLTF data.
94
- * @param {number} propertyTableIndex - Index of the property table to locate.
95
- * @returns {GLTF_EXT_structural_metadata_PropertyTable} Property table populated with the data.
143
+ * @param scenegraph - Instance of the class for structured access to GLTF data.
144
+ * @param propertyTableIndex - Index of the property table to locate.
145
+ * @returns Property table populated with the data.
96
146
  * Throws an exception if no property table was found for propertyTableIndex provided.
97
147
  */
98
148
  export function getPropertyTablePopulated(
99
149
  scenegraph: GLTFScenegraph,
100
150
  propertyTableIndex: number
101
151
  ): GLTF_EXT_structural_metadata_PropertyTable {
102
- const extension: GLTF_EXT_structural_metadata | null = scenegraph.getExtension(
152
+ const extension: GLTF_EXT_structural_metadata_GLTF | null = scenegraph.getExtension(
103
153
  EXT_STRUCTURAL_METADATA_NAME
104
154
  );
105
155
  const propertyTable = extension?.propertyTables?.[propertyTableIndex];
@@ -113,21 +163,42 @@ export function getPropertyTablePopulated(
113
163
  }
114
164
 
115
165
  /**
116
- * Decodes feature metadata from extension
117
- * @param {GLTFScenegraph} scenegraph - Instance of the class for structured access to GLTF data.
118
- * @param {GLTFLoaderOptions} options - loader options.
166
+ * Decodes feature metadata from extension.
167
+ * @param scenegraph - Instance of the class for structured access to GLTF data.
168
+ * @param options - GLTFLoader options.
119
169
  */
120
170
  function decodeExtStructuralMetadata(scenegraph: GLTFScenegraph, options: GLTFLoaderOptions): void {
121
- const extension: GLTF_EXT_structural_metadata | null = scenegraph.getExtension(
171
+ // Decoding metadata involves buffers processing.
172
+ // So, if buffers have not been loaded, there is no reason to process metadata.
173
+ if (!options.gltf?.loadBuffers) {
174
+ return;
175
+ }
176
+ const extension: GLTF_EXT_structural_metadata_GLTF | null = scenegraph.getExtension(
122
177
  EXT_STRUCTURAL_METADATA_NAME
123
178
  );
124
- if (!extension?.schema) {
179
+ if (!extension) {
125
180
  return;
126
181
  }
127
182
 
183
+ if (options.gltf?.loadImages) {
184
+ decodePropertyTextures(scenegraph, extension);
185
+ }
186
+
187
+ decodePropertyTables(scenegraph, extension);
188
+ }
189
+
190
+ /**
191
+ * Processes the data stored in the textures
192
+ * @param scenegraph - Instance of the class for structured access to GLTF data.
193
+ * @param extension - Top-level extension.
194
+ */
195
+ function decodePropertyTextures(
196
+ scenegraph: GLTFScenegraph,
197
+ extension: GLTF_EXT_structural_metadata_GLTF
198
+ ): void {
128
199
  const propertyTextures = extension.propertyTextures;
129
200
  const json = scenegraph.gltf.json;
130
- if (propertyTextures && json.meshes && options?.gltf?.loadImages) {
201
+ if (propertyTextures && json.meshes) {
131
202
  // Iterate through all meshes/primitives.
132
203
  for (const mesh of json.meshes) {
133
204
  for (const primitive of mesh.primitives) {
@@ -135,31 +206,63 @@ function decodeExtStructuralMetadata(scenegraph: GLTFScenegraph, options: GLTFLo
135
206
  }
136
207
  }
137
208
  }
209
+ }
138
210
 
139
- const schemaClasses = extension.schema.classes;
211
+ /**
212
+ * Processes the data stored in the property tables.
213
+ * @param scenegraph - Instance of the class for structured access to GLTF data.
214
+ * @param extension - Top-level extension.
215
+ */
216
+ function decodePropertyTables(
217
+ scenegraph: GLTFScenegraph,
218
+ extension: GLTF_EXT_structural_metadata_GLTF
219
+ ): void {
220
+ const schema = extension.schema;
221
+ if (!schema) {
222
+ return;
223
+ }
224
+ const schemaClasses = schema.classes;
140
225
  const propertyTables = extension.propertyTables;
141
226
  if (schemaClasses && propertyTables) {
142
227
  for (const schemaName in schemaClasses) {
143
228
  const propertyTable = findPropertyTableByClass(propertyTables, schemaName);
144
229
  if (propertyTable) {
145
- processPropertyTable(scenegraph, extension.schema, propertyTable);
230
+ processPropertyTable(scenegraph, schema, propertyTable);
146
231
  }
147
232
  }
148
233
  }
149
234
  }
150
235
 
151
236
  /**
152
- * Takes data from property textures reffered by the primitive
153
- * @param {GLTFScenegraph} scenegraph - Instance of the class for structured access to GLTF data.
154
- * @param {GLTF_EXT_structural_metadata_PropertyTexture[]} propertyTextures - propertyTexture definition taken from the top-level extention
155
- * @param {GLTFMeshPrimitive} primitive - Primitive object
156
- * @param {GLTF_EXT_structural_metadata} extension - top-level extension
237
+ * Finds the property table by class name.
238
+ * @param propertyTables - propertyTable definition taken from the top-level extension.
239
+ * @param schemaClassName - class name in the extension schema.
240
+ */
241
+ function findPropertyTableByClass(
242
+ propertyTables: GLTF_EXT_structural_metadata_PropertyTable[],
243
+ schemaClassName: string
244
+ ): GLTF_EXT_structural_metadata_PropertyTable | null {
245
+ for (const propertyTable of propertyTables) {
246
+ if (propertyTable.class === schemaClassName) {
247
+ return propertyTable;
248
+ }
249
+ }
250
+
251
+ return null;
252
+ }
253
+
254
+ /**
255
+ * Takes data from property textures reffered by the primitive.
256
+ * @param scenegraph - Instance of the class for structured access to GLTF data.
257
+ * @param propertyTextures - propertyTexture definition taken from the top-level extention.
258
+ * @param primitive - Primitive object.
259
+ * @param extension - Top-level extension.
157
260
  */
158
261
  function processPrimitivePropertyTextures(
159
262
  scenegraph: GLTFScenegraph,
160
263
  propertyTextures: GLTF_EXT_structural_metadata_PropertyTexture[],
161
264
  primitive: GLTFMeshPrimitive,
162
- extension: GLTF_EXT_structural_metadata
265
+ extension: GLTF_EXT_structural_metadata_GLTF
163
266
  ): void {
164
267
  if (!propertyTextures) {
165
268
  return;
@@ -179,17 +282,17 @@ function processPrimitivePropertyTextures(
179
282
  }
180
283
 
181
284
  /**
182
- * Takes property data from the texture pointed by the primitive and appends them to `exension.data`
183
- * @param {GLTFScenegraph} scenegraph - Instance of the class for structured access to GLTF data.
184
- * @param {GLTF_EXT_structural_metadata_PropertyTexture} propertyTexture - propertyTexture definition taken from the top-level extension.
185
- * @param {GLTFMeshPrimitive} primitive - Primitive object
186
- * @param {GLTF_EXT_structural_metadata} extension - top-level extension
285
+ * Takes property data from the texture pointed by the primitive and appends them to `exension.data`.
286
+ * @param scenegraph - Instance of the class for structured access to GLTF data.
287
+ * @param propertyTexture - propertyTexture definition taken from the top-level extension.
288
+ * @param primitive - Primitive object.
289
+ * @param extension - Top-level extension.
187
290
  */
188
291
  function processPrimitivePropertyTexture(
189
292
  scenegraph: GLTFScenegraph,
190
293
  propertyTexture: GLTF_EXT_structural_metadata_PropertyTexture,
191
294
  primitive: GLTFMeshPrimitive,
192
- extension: GLTF_EXT_structural_metadata
295
+ extension: GLTF_EXT_structural_metadata_GLTF
193
296
  ): void {
194
297
  if (!propertyTexture.properties) {
195
298
  return;
@@ -217,12 +320,12 @@ function processPrimitivePropertyTexture(
217
320
  }
218
321
  */
219
322
  const className = propertyTexture.class;
220
- for (const propName in propertyTexture.properties) {
221
- // propName has values like "speed", "direction"
323
+ for (const propertyName in propertyTexture.properties) {
324
+ // propertyName has values like "speed", "direction"
222
325
  // Make attributeName as a combination of the class name and the propertyName like "wind_speed" or "wind_direction"
223
- const attributeName = `${className}_${propName}`;
326
+ const attributeName = `${className}_${propertyName}`;
224
327
  const textureInfoTopLevel: GLTFTextureInfoMetadata | undefined =
225
- propertyTexture.properties?.[propName];
328
+ propertyTexture.properties?.[propertyName];
226
329
  if (!textureInfoTopLevel) {
227
330
  // eslint-disable-next-line no-continue
228
331
  continue;
@@ -259,9 +362,9 @@ function processPrimitivePropertyTexture(
259
362
  /**
260
363
  * Navigates through all properies in the property table, gets properties data,
261
364
  * and put the data to `propertyTable.data` as an array.
262
- * @param {GLTFScenegraph} scenegraph - Instance of the class for structured access to GLTF data.
263
- * @param {GLTF_EXT_structural_metadata_Schema} schema - schema object
264
- * @param {GLTF_EXT_structural_metadata_PropertyTable} propertyTable - propertyTable definition taken from the top-level extension
365
+ * @param scenegraph - Instance of the class for structured access to GLTF data.
366
+ * @param schema - schema object.
367
+ * @param propertyTable - propertyTable definition taken from the top-level extension.
265
368
  */
266
369
  function processPropertyTable(
267
370
  scenegraph: GLTFScenegraph,
@@ -297,56 +400,36 @@ function processPropertyTable(
297
400
  }
298
401
 
299
402
  /**
300
- * Decodes properties from binary sourse based on property type.
301
- * @param {GLTFScenegraph} scenegraph - Instance of the class for structured access to GLTF data.
302
- * @param {GLTF_EXT_structural_metadata_Schema} schema - Schema object
303
- * @param {GLTF_EXT_structural_metadata_ClassProperty} classProperty - class property object
304
- * @param {GLTF_EXT_structural_metadata_PropertyTable_Property} propertyTableProperty
305
- * @param {number} numberOfElements - The number of elements in each property array that propertyTableProperty contains. It's a number of rows in the table.
403
+ * Decodes a propertyTable column from binary source based on property type.
404
+ * @param scenegraph - Instance of the class for structured access to GLTF data.
405
+ * @param schema - Schema object.
406
+ * @param classProperty - class property object.
407
+ * @param numberOfElements - The number of elements in each property array that propertyTableProperty contains. It's a number of rows in the table.
408
+ * @param propertyTableProperty - propertyTable's property metadata.
306
409
  * @returns {string[] | number[] | string[][] | number[][]}
307
410
  */
308
- /* eslint complexity: ["error", 17]*/
309
411
  function getPropertyDataFromBinarySource(
310
412
  scenegraph: GLTFScenegraph,
311
413
  schema: GLTF_EXT_structural_metadata_Schema,
312
414
  classProperty: GLTF_EXT_structural_metadata_ClassProperty,
313
415
  numberOfElements: number,
314
416
  propertyTableProperty: GLTF_EXT_structural_metadata_PropertyTable_Property
315
- ): string[] | number[] | string[][] | number[][] {
316
- let data: string[] | number[] | string[][] | number[][] = [];
417
+ ): string[] | BigTypedArray | string[][] | BigTypedArray[] {
418
+ let data: string[] | BigTypedArray | string[][] | BigTypedArray[] = [];
317
419
  const valuesBufferView = propertyTableProperty.values;
318
420
  const valuesDataBytes: Uint8Array = scenegraph.getTypedArrayForBufferView(valuesBufferView);
319
421
 
320
- let arrayOffsets: TypedArray | null = null;
321
- if (
322
- classProperty.array &&
323
- // `count` is a number of array elements. May only be defined when `array` is true.
324
- typeof classProperty.count === 'undefined' && // If `count` is NOT defined, it's a VARIABLE-length array
325
- typeof propertyTableProperty.arrayOffsets !== 'undefined' && // `arrayOffsets` is an index of the buffer view containing offsets for variable-length arrays.
326
- typeof propertyTableProperty.arrayOffsetType !== 'undefined'
327
- ) {
328
- // Data are in a VARIABLE-length array
329
- arrayOffsets = getOffsetArray(
330
- scenegraph,
331
- propertyTableProperty.arrayOffsets,
332
- propertyTableProperty.arrayOffsetType,
333
- numberOfElements
334
- );
335
- }
336
-
337
- let stringOffsets: TypedArray | null = null;
338
- if (
339
- typeof propertyTableProperty.stringOffsets !== 'undefined' && // `stringOffsets` is an index of the buffer view containing offsets for strings.
340
- typeof propertyTableProperty.stringOffsetType !== 'undefined'
341
- ) {
342
- // Data are in a FIXED-length array
343
- stringOffsets = getOffsetArray(
344
- scenegraph,
345
- propertyTableProperty.stringOffsets,
346
- propertyTableProperty.stringOffsetType,
347
- numberOfElements
348
- );
349
- }
422
+ const arrayOffsets = getArrayOffsetsForProperty(
423
+ scenegraph,
424
+ classProperty,
425
+ propertyTableProperty,
426
+ numberOfElements
427
+ );
428
+ const stringOffsets = getStringOffsetsForProperty(
429
+ scenegraph,
430
+ propertyTableProperty,
431
+ numberOfElements
432
+ );
350
433
 
351
434
  switch (classProperty.type) {
352
435
  case 'SCALAR':
@@ -391,59 +474,98 @@ function getPropertyDataFromBinarySource(
391
474
  }
392
475
 
393
476
  /**
394
- * Gets offset array from `arrayOffsets` or `stringOffsets`.
395
- * @param {GLTFScenegraph} scenegraph - Instance of the class for structured access to GLTF data.
396
- * @param {number} offsets - Buffer view index
397
- * @param offsetType - The type of values in `arrayOffsets` or `stringOffsets`.
398
- * @param {number} numberOfElements - The number of elements in each property array.
399
- * @returns {TypedArray}
477
+ * Parses propertyTable.property.arrayOffsets that are offsets of sub-arrays in a flatten array of values.
478
+ * @param scenegraph - Instance of the class for structured access to GLTF data.
479
+ * @param classProperty - class property object.
480
+ * @param propertyTableProperty - propertyTable's property metadata.
481
+ * @param numberOfElements - The number of elements in each property array that propertyTableProperty contains. It's a number of rows in the table.
482
+ * @returns Typed array with offset values.
483
+ * @see https://github.com/CesiumGS/glTF/blob/2976f1183343a47a29e4059a70961371cd2fcee8/extensions/2.0/Vendor/EXT_structural_metadata/schema/propertyTable.property.schema.json#L21
400
484
  */
401
- function getOffsetArray(
485
+ function getArrayOffsetsForProperty(
402
486
  scenegraph: GLTFScenegraph,
403
- offsets: number,
404
- offsetType: 'UINT8' | 'UINT16' | 'UINT32' | 'UINT64',
487
+ classProperty: GLTF_EXT_structural_metadata_ClassProperty,
488
+ propertyTableProperty: GLTF_EXT_structural_metadata_PropertyTable_Property,
405
489
  numberOfElements: number
406
- ): TypedArray {
407
- const arrayOffsetsBufferView = offsets;
408
- const arrayOffsetsBytes = scenegraph.getTypedArrayForBufferView(arrayOffsetsBufferView);
409
-
410
- const arrayOffsets = convertRawBufferToMetadataArray(
411
- arrayOffsetsBytes,
412
- 'SCALAR', // offsets consist of ONE component
413
- offsetType,
414
- numberOfElements + 1 // The number of offsets is equal to the property table `count` plus one.
415
- );
416
- return arrayOffsets;
490
+ ): TypedArray | null {
491
+ if (
492
+ classProperty.array &&
493
+ // `count` is a number of array elements. May only be defined when `array` is true.
494
+ // If `count` is NOT defined, it's a VARIABLE-length array
495
+ typeof classProperty.count === 'undefined' &&
496
+ // `arrayOffsets` is an index of the buffer view containing offsets for variable-length arrays.
497
+ typeof propertyTableProperty.arrayOffsets !== 'undefined'
498
+ ) {
499
+ // Data are in a VARIABLE-length array
500
+ return getOffsetsForProperty(
501
+ scenegraph,
502
+ propertyTableProperty.arrayOffsets,
503
+ propertyTableProperty.arrayOffsetType || 'UINT32',
504
+ numberOfElements
505
+ );
506
+ }
507
+ return null;
508
+ }
509
+
510
+ /**
511
+ * Parses propertyTable.property.stringOffsets.
512
+ * @param scenegraph - Instance of the class for structured access to GLTF data.
513
+ * @param propertyTableProperty - propertyTable's property metadata.
514
+ * @param numberOfElements - The number of elements in each property array that propertyTableProperty contains. It's a number of rows in the table.
515
+ * @returns Typed array with offset values.
516
+ * @see https://github.com/CesiumGS/glTF/blob/2976f1183343a47a29e4059a70961371cd2fcee8/extensions/2.0/Vendor/EXT_structural_metadata/schema/propertyTable.property.schema.json#L29C10-L29C23
517
+ */
518
+ function getStringOffsetsForProperty(
519
+ scenegraph: GLTFScenegraph,
520
+ propertyTableProperty: GLTF_EXT_structural_metadata_PropertyTable_Property,
521
+ numberOfElements: number
522
+ ): TypedArray | null {
523
+ if (
524
+ typeof propertyTableProperty.stringOffsets !== 'undefined' // `stringOffsets` is an index of the buffer view containing offsets for strings.
525
+ ) {
526
+ // Data are in a FIXED-length array
527
+ return getOffsetsForProperty(
528
+ scenegraph,
529
+ propertyTableProperty.stringOffsets,
530
+ propertyTableProperty.stringOffsetType || 'UINT32',
531
+ numberOfElements
532
+ );
533
+ }
534
+ return null;
417
535
  }
418
536
 
419
537
  /**
420
538
  * Decodes properties of SCALAR, VEC-N, MAT-N types from binary sourse.
421
- * @param {GLTF_EXT_structural_metadata_ClassProperty} classProperty - class property object
422
- * @param {number} numberOfElements - The number of elements in each property array that propertyTableProperty contains. It's a number of rows in the table.
423
- * @param {Uint8Array} valuesDataBytes - data taken from values property of the property table property.
424
- * @param {TypedArray | null} arrayOffsets - offsets for variable-length arrays. It's null for fixed-length arrays or scalar types.
425
- * @returns {number[] | number[][]}
539
+ * @param classProperty - class property object.
540
+ * @param numberOfElements - The number of elements in each property array that propertyTableProperty contains. It's a number of rows in the table.
541
+ * @param valuesDataBytes - Data taken from values property of the property table property.
542
+ * @param arrayOffsets - Offsets for variable-length arrays. It's null for fixed-length arrays or scalar types.
543
+ * @returns Property values in a typed array or in an array of typed arrays.
426
544
  */
427
545
  function getPropertyDataNumeric(
428
546
  classProperty: GLTF_EXT_structural_metadata_ClassProperty,
429
547
  numberOfElements: number,
430
548
  valuesDataBytes: Uint8Array,
431
549
  arrayOffsets: TypedArray | null
432
- ): number[] | number[][] {
550
+ ): BigTypedArray | BigTypedArray[] {
433
551
  const isArray = classProperty.array;
434
552
  const arrayCount = classProperty.count;
435
553
 
436
554
  const elementSize = getArrayElementByteSize(classProperty.type, classProperty.componentType);
437
555
  const elementCount = valuesDataBytes.byteLength / elementSize;
438
556
 
439
- let valuesData: TypedArray;
557
+ let valuesData: BigTypedArray | null;
440
558
  if (classProperty.componentType) {
441
559
  valuesData = convertRawBufferToMetadataArray(
442
560
  valuesDataBytes,
443
561
  classProperty.type,
444
- classProperty.componentType, // The datatype of the element's components. Only applicable to `SCALAR`, `VECN`, and `MATN` types.
562
+ // The datatype of the element's components. Only applicable to `SCALAR`, `VECN`, and `MATN` types.
563
+ classProperty.componentType as NumericComponentType,
445
564
  elementCount
446
565
  );
566
+ if (!valuesData) {
567
+ valuesData = valuesDataBytes;
568
+ }
447
569
  } else {
448
570
  // The spec doesn't provide any info what to do if componentType is not set.
449
571
  valuesData = valuesDataBytes;
@@ -452,7 +574,7 @@ function getPropertyDataNumeric(
452
574
  if (isArray) {
453
575
  if (arrayOffsets) {
454
576
  // VARIABLE-length array
455
- return handleVariableLengthArrayNumeric(
577
+ return parseVariableLengthArrayNumeric(
456
578
  valuesData,
457
579
  numberOfElements,
458
580
  arrayOffsets,
@@ -462,70 +584,76 @@ function getPropertyDataNumeric(
462
584
  }
463
585
  if (arrayCount) {
464
586
  // FIXED-length array
465
- return handleFixedLengthArrayNumeric(valuesData, numberOfElements, arrayCount);
587
+ return parseFixedLengthArrayNumeric(valuesData, numberOfElements, arrayCount);
466
588
  }
467
589
  return [];
468
590
  }
469
591
 
470
- // Single value (not an array)
471
- const attributeValueArray: number[] = [];
472
- for (let index = 0; index < numberOfElements; index++) {
473
- const value = valuesData[index];
474
- attributeValueArray.push(value);
475
- }
476
- return attributeValueArray;
592
+ return valuesData;
477
593
  }
478
594
 
479
- function handleVariableLengthArrayNumeric(
480
- valuesData: TypedArray,
595
+ /**
596
+ * Parses variable-length array data.
597
+ * In this case every value of the property in the table will be an array
598
+ * of arbitrary length.
599
+ * @param valuesData - Values in a flat typed array.
600
+ * @param numberOfElements - Number of rows in the property table.
601
+ * @param arrayOffsets - Offsets of nested arrays in the flat values array.
602
+ * @param valuesDataBytesLength - Data byte length.
603
+ * @param valueSize - Value size in bytes.
604
+ * @returns Array of typed arrays.
605
+ */
606
+ function parseVariableLengthArrayNumeric(
607
+ valuesData: BigTypedArray,
481
608
  numberOfElements: number,
482
609
  arrayOffsets: TypedArray,
483
610
  valuesDataBytesLength: number,
484
- elementSize: number
485
- ) {
486
- const attributeValueArray: number[][] = [];
611
+ valueSize: number
612
+ ): BigTypedArray[] {
613
+ const attributeValueArray: BigTypedArray[] = [];
487
614
  for (let index = 0; index < numberOfElements; index++) {
488
- const array: number[] = [];
489
615
  const arrayOffset = arrayOffsets[index];
490
616
  const arrayByteSize = arrayOffsets[index + 1] - arrayOffsets[index];
491
- if (arrayByteSize + arrayOffset <= valuesDataBytesLength) {
492
- const typedArrayOffset = arrayOffset / elementSize;
493
- const elementCount = arrayByteSize / elementSize;
494
- for (let i = 0; i < elementCount; i++) {
495
- const value = valuesData[typedArrayOffset + i];
496
- array.push(value);
497
- }
617
+ if (arrayByteSize + arrayOffset > valuesDataBytesLength) {
618
+ break;
498
619
  }
499
- attributeValueArray.push(array);
620
+ const typedArrayOffset = arrayOffset / valueSize;
621
+ const elementCount = arrayByteSize / valueSize;
622
+ attributeValueArray.push(valuesData.slice(typedArrayOffset, typedArrayOffset + elementCount));
500
623
  }
501
624
  return attributeValueArray;
502
625
  }
503
626
 
504
- function handleFixedLengthArrayNumeric(
505
- valuesData: TypedArray,
627
+ /**
628
+ * Parses fixed-length array data.
629
+ * In this case every value of the property in the table will be an array
630
+ * of constant length equal to `arrayCount`.
631
+ * @param valuesData - Values in a flat typed array.
632
+ * @param numberOfElements - Number of rows in the property table.
633
+ * @param arrayCount - Nested arrays length.
634
+ * @returns Array of typed arrays.
635
+ */
636
+ function parseFixedLengthArrayNumeric(
637
+ valuesData: BigTypedArray,
506
638
  numberOfElements: number,
507
639
  arrayCount: number
508
- ) {
509
- const attributeValueArray: number[][] = [];
640
+ ): BigTypedArray[] {
641
+ const attributeValueArray: BigTypedArray[] = [];
510
642
  for (let index = 0; index < numberOfElements; index++) {
511
- const array: number[] = [];
512
- for (let i = 0; i < arrayCount; i++) {
513
- const value = valuesData[i];
514
- array.push(value);
515
- }
516
- attributeValueArray.push(array);
643
+ const elementOffset = index * arrayCount;
644
+ attributeValueArray.push(valuesData.slice(elementOffset, elementOffset + arrayCount));
517
645
  }
518
646
  return attributeValueArray;
519
647
  }
520
648
 
521
649
  /**
522
- * Decodes properties of string type from binary sourse.
523
- * @param {GLTF_EXT_structural_metadata_ClassProperty} classProperty - class property object
524
- * @param {number} numberOfElements - The number of elements in each property array that propertyTableProperty contains. It's a number of rows in the table.
525
- * @param {Uint8Array} valuesDataBytes - data taken from values property of the property table property.
526
- * @param {TypedArray | null} arrayOffsets - offsets for variable-length arrays. It's null for fixed-length arrays or scalar types.
527
- * @param {TypedArray | null} stringOffsets - index of the buffer view containing offsets for strings. It should be available for string type.
528
- * @returns {string[] | string[][]}
650
+ * Decodes properties of string type from binary source.
651
+ * @param classProperty - Class property object.
652
+ * @param numberOfElements - The number of elements in each property array that propertyTableProperty contains. It's a number of rows in the table.
653
+ * @param valuesDataBytes - Data taken from values property of the property table property.
654
+ * @param arrayOffsets - Offsets for variable-length arrays. It's null for fixed-length arrays or scalar types.
655
+ * @param stringOffsets - Index of the buffer view containing offsets for strings. It should be available for string type.
656
+ * @returns String property values
529
657
  */
530
658
  function getPropertyDataString(
531
659
  classProperty: GLTF_EXT_structural_metadata_ClassProperty,
@@ -562,13 +690,13 @@ function getPropertyDataString(
562
690
  }
563
691
 
564
692
  /**
565
- * Decodes properties of enum type from binary sourse.
566
- * @param {GLTF_EXT_structural_metadata_Schema} schema - schema object
567
- * @param {GLTF_EXT_structural_metadata_ClassProperty} classProperty - class property object
568
- * @param {number} numberOfElements - The number of elements in each property array that propertyTableProperty contains. It's a number of rows in the table.
569
- * @param {Uint8Array} valuesDataBytes - data taken from values property of the property table property.
570
- * @param {TypedArray | null} arrayOffsets - offsets for variable-length arrays. It's null for fixed-length arrays or scalar types.
571
- * @returns {string[] | string[][]}
693
+ * Decodes properties of enum type from binary source.
694
+ * @param schema - Schema object.
695
+ * @param classProperty - Class property object.
696
+ * @param numberOfElements - The number of elements in each property array that propertyTableProperty contains. It's a number of rows in the table.
697
+ * @param valuesDataBytes - Data taken from values property of the property table property.
698
+ * @param arrayOffsets - Offsets for variable-length arrays. It's null for fixed-length arrays or scalar types.
699
+ * @returns Strings array of nested strings array.
572
700
  */
573
701
  function getPropertyDataENUM(
574
702
  schema: GLTF_EXT_structural_metadata_Schema,
@@ -577,11 +705,6 @@ function getPropertyDataENUM(
577
705
  valuesDataBytes: Uint8Array,
578
706
  arrayOffsets: TypedArray | null
579
707
  ): string[] | string[][] {
580
- const data: string[] = [];
581
-
582
- const isArray = classProperty.array;
583
- const arrayCount = classProperty.count;
584
-
585
708
  const enumType = classProperty.enumType;
586
709
  // Enum ID as declared in the `enums` dictionary. Required when `type` is `ENUM`.
587
710
  if (!enumType) {
@@ -600,120 +723,144 @@ function getPropertyDataENUM(
600
723
  const enumValueType = enumEntry.valueType || 'UINT16';
601
724
  const elementSize = getArrayElementByteSize(classProperty.type, enumValueType);
602
725
  const elementCount = valuesDataBytes.byteLength / elementSize;
603
- const valuesData: TypedArray = convertRawBufferToMetadataArray(
726
+ let valuesData: BigTypedArray | null = convertRawBufferToMetadataArray(
604
727
  valuesDataBytes,
605
728
  classProperty.type,
606
729
  enumValueType,
607
730
  elementCount
608
731
  );
732
+ if (!valuesData) {
733
+ valuesData = valuesDataBytes;
734
+ }
609
735
 
610
- if (isArray) {
736
+ if (classProperty.array) {
611
737
  if (arrayOffsets) {
612
738
  // VARIABLE-length array
613
- return handleVariableLengthArrayENUM(
739
+ return parseVariableLengthArrayENUM({
614
740
  valuesData,
615
741
  numberOfElements,
616
742
  arrayOffsets,
617
- valuesDataBytes.length,
743
+ valuesDataBytesLength: valuesDataBytes.length,
618
744
  elementSize,
619
745
  enumEntry
620
- );
746
+ });
621
747
  }
748
+
749
+ const arrayCount = classProperty.count;
622
750
  if (arrayCount) {
623
751
  // FIXED-length array
624
- return handleFixedLengthArrayENUM(valuesData, numberOfElements, arrayCount, enumEntry);
752
+ return parseFixedLengthArrayENUM(valuesData, numberOfElements, arrayCount, enumEntry);
625
753
  }
626
754
  return [];
627
755
  }
628
756
 
629
757
  // Single value (not an array)
630
- for (let index = 0; index < numberOfElements; index++) {
631
- const enumValue = valuesData[index];
632
- const enumObject = getEnumByValue(enumEntry, enumValue);
633
- if (enumObject) {
634
- data.push(enumObject.name);
635
- }
636
- }
637
-
638
- return data;
758
+ return getEnumsArray(valuesData, 0, numberOfElements, enumEntry);
639
759
  }
640
760
 
641
- /* eslint max-params: ["error", 6]*/
642
- function handleVariableLengthArrayENUM(
643
- valuesData: TypedArray,
644
- numberOfElements: number,
645
- arrayOffsets: TypedArray,
646
- valuesDataBytesLength: number,
647
- elementSize: number,
648
- enumEntry: GLTF_EXT_structural_metadata_Enum
649
- ) {
761
+ /**
762
+ * Parses variable length nested ENUM arrays.
763
+ * @param params.valuesData - Values in a flat typed array.
764
+ * @param params.numberOfElements - The number of elements in each property array that propertyTableProperty contains. It's a number of rows in the table.
765
+ * @param params.arrayOffsets - Offsets for variable-length arrays. It's null for fixed-length arrays or scalar types.
766
+ * @param params.valuesDataBytesLength - Byte length of values array.
767
+ * @param params.elementSize - Single element byte size.
768
+ * @param params.enumEntry - Enums dictionary.
769
+ * @returns Nested strings array.
770
+ */
771
+ function parseVariableLengthArrayENUM(params: {
772
+ valuesData: BigTypedArray;
773
+ numberOfElements: number;
774
+ arrayOffsets: TypedArray;
775
+ valuesDataBytesLength: number;
776
+ elementSize: number;
777
+ enumEntry: GLTF_EXT_structural_metadata_Enum;
778
+ }): string[][] {
779
+ const {
780
+ valuesData,
781
+ numberOfElements,
782
+ arrayOffsets,
783
+ valuesDataBytesLength,
784
+ elementSize,
785
+ enumEntry
786
+ } = params;
650
787
  const attributeValueArray: string[][] = [];
651
788
  for (let index = 0; index < numberOfElements; index++) {
652
- const array: string[] = [];
653
789
  const arrayOffset = arrayOffsets[index];
654
790
  const arrayByteSize = arrayOffsets[index + 1] - arrayOffsets[index];
655
- if (arrayByteSize + arrayOffset <= valuesDataBytesLength) {
656
- const typedArrayOffset = arrayOffset / elementSize;
657
- const elementCount = arrayByteSize / elementSize;
658
- for (let i = 0; i < elementCount; i++) {
659
- const value = valuesData[typedArrayOffset + i];
660
-
661
- const enumObject = getEnumByValue(enumEntry, value);
662
- if (enumObject) {
663
- array.push(enumObject.name);
664
- }
665
- }
791
+ if (arrayByteSize + arrayOffset > valuesDataBytesLength) {
792
+ break;
666
793
  }
794
+
795
+ const typedArrayOffset = arrayOffset / elementSize;
796
+ const elementCount = arrayByteSize / elementSize;
797
+ const array: string[] = getEnumsArray(valuesData, typedArrayOffset, elementCount, enumEntry);
667
798
  attributeValueArray.push(array);
668
799
  }
669
800
  return attributeValueArray;
670
801
  }
671
802
 
672
- function handleFixedLengthArrayENUM(
673
- valuesData: TypedArray,
803
+ /**
804
+ * Parses fixed length ENUM arrays.
805
+ * @param valuesData - Values in a flat typed array.
806
+ * @param numberOfElements - The number of elements in each property array that propertyTableProperty contains. It's a number of rows in the table.
807
+ * @param arrayCount - Nested arrays length.
808
+ * @param enumEntry - Enums dictionary.
809
+ * @returns Nested strings array.
810
+ */
811
+ function parseFixedLengthArrayENUM(
812
+ valuesData: BigTypedArray,
674
813
  numberOfElements: number,
675
814
  arrayCount: number,
676
815
  enumEntry: GLTF_EXT_structural_metadata_Enum
677
- ) {
816
+ ): string[][] {
678
817
  const attributeValueArray: string[][] = [];
679
818
  for (let index = 0; index < numberOfElements; index++) {
680
- const array: string[] = [];
681
- for (let i = 0; i < arrayCount; i++) {
682
- const value = valuesData[i];
683
-
684
- const enumObject = getEnumByValue(enumEntry, value);
685
- if (enumObject) {
686
- array.push(enumObject.name);
687
- }
688
- }
819
+ const elementOffset = arrayCount * index;
820
+ const array: string[] = getEnumsArray(valuesData, elementOffset, arrayCount, enumEntry);
689
821
  attributeValueArray.push(array);
690
822
  }
691
823
  return attributeValueArray;
692
824
  }
825
+
693
826
  /**
694
- * Find the property table by class name.
695
- * @param {GLTF_EXT_structural_metadata_PropertyTable[]} propertyTables
696
- * @param {string} schemaClassName
827
+ * Parses ENUM values into a string array.
828
+ * @param valuesData - Values in a flat typed array.
829
+ * @param offset - Offset to start parse from.
830
+ * @param count - Values length to parse.
831
+ * @param enumEntry - Enums dictionary.
832
+ * @returns Array of strings with parsed ENUM names.
697
833
  */
698
- function findPropertyTableByClass(
699
- propertyTables: GLTF_EXT_structural_metadata_PropertyTable[],
700
- schemaClassName: string
701
- ): GLTF_EXT_structural_metadata_PropertyTable | null {
702
- for (let i = 0, len = propertyTables.length; i < len; i++) {
703
- const propertyTable = propertyTables[i];
834
+ function getEnumsArray(
835
+ valuesData: BigTypedArray,
836
+ offset: number,
837
+ count: number,
838
+ enumEntry: GLTF_EXT_structural_metadata_Enum
839
+ ): string[] {
840
+ const array: string[] = [];
841
+ for (let i = 0; i < count; i++) {
842
+ // At the moment we don't support BigInt. It requires additional calculations logic
843
+ // and might be an issue in Safari
844
+ if (valuesData instanceof BigInt64Array || valuesData instanceof BigUint64Array) {
845
+ array.push('');
846
+ } else {
847
+ const value = valuesData[offset + i];
704
848
 
705
- if (propertyTable.class === schemaClassName) {
706
- return propertyTable;
849
+ const enumObject = getEnumByValue(enumEntry, value);
850
+ if (enumObject) {
851
+ array.push(enumObject.name);
852
+ } else {
853
+ array.push('');
854
+ }
707
855
  }
708
856
  }
709
-
710
- return null;
857
+ return array;
711
858
  }
712
859
 
713
860
  /**
714
861
  * Looks up ENUM whose `value` property matches the specified number in the parameter `value`.
715
862
  * @param {GLTF_EXT_structural_metadata_Enum} enumEntry - ENUM entry containing the array of possible enums.
716
- * @param {number} value - the value of the ENUM to locate.
863
+ * @param {number} value - The value of the ENUM to locate.
717
864
  * @returns {GLTF_EXT_structural_metadata_EnumValue | null} ENUM matcihng the specified value or null of no ENUM object was found.
718
865
  */
719
866
  function getEnumByValue(