@loaders.gl/gltf 4.0.0-alpha.9 → 4.0.0-beta.1

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