@loaders.gl/gltf 4.2.0-alpha.4 → 4.2.0-alpha.5

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 (148) hide show
  1. package/dist/dist.dev.js +1049 -517
  2. package/dist/dist.min.js +9 -0
  3. package/dist/glb-loader.d.ts +2 -2
  4. package/dist/glb-loader.d.ts.map +1 -1
  5. package/dist/glb-loader.js +22 -21
  6. package/dist/glb-writer.d.ts +2 -2
  7. package/dist/glb-writer.d.ts.map +1 -1
  8. package/dist/glb-writer.js +27 -24
  9. package/dist/gltf-loader.d.ts +3 -3
  10. package/dist/gltf-loader.d.ts.map +1 -1
  11. package/dist/gltf-loader.js +31 -36
  12. package/dist/gltf-writer.js +24 -26
  13. package/dist/index.cjs +95 -284
  14. package/dist/index.cjs.map +7 -0
  15. package/dist/index.d.ts +17 -17
  16. package/dist/index.d.ts.map +1 -1
  17. package/dist/index.js +3 -1
  18. package/dist/lib/api/gltf-extensions.d.ts +2 -2
  19. package/dist/lib/api/gltf-extensions.d.ts.map +1 -1
  20. package/dist/lib/api/gltf-extensions.js +45 -22
  21. package/dist/lib/api/gltf-scenegraph.d.ts +2 -2
  22. package/dist/lib/api/gltf-scenegraph.d.ts.map +1 -1
  23. package/dist/lib/api/gltf-scenegraph.js +561 -438
  24. package/dist/lib/api/normalize-gltf-v1.js +250 -181
  25. package/dist/lib/api/post-process-gltf.d.ts +3 -3
  26. package/dist/lib/api/post-process-gltf.d.ts.map +1 -1
  27. package/dist/lib/api/post-process-gltf.js +375 -339
  28. package/dist/lib/encoders/encode-glb.js +62 -48
  29. package/dist/lib/encoders/encode-gltf.js +24 -10
  30. package/dist/lib/extensions/EXT_mesh_features.d.ts +2 -2
  31. package/dist/lib/extensions/EXT_mesh_features.d.ts.map +1 -1
  32. package/dist/lib/extensions/EXT_mesh_features.js +55 -33
  33. package/dist/lib/extensions/EXT_meshopt_compression.d.ts +2 -2
  34. package/dist/lib/extensions/EXT_meshopt_compression.d.ts.map +1 -1
  35. package/dist/lib/extensions/EXT_meshopt_compression.js +27 -31
  36. package/dist/lib/extensions/EXT_structural_metadata.d.ts +2 -2
  37. package/dist/lib/extensions/EXT_structural_metadata.d.ts.map +1 -1
  38. package/dist/lib/extensions/EXT_structural_metadata.js +434 -230
  39. package/dist/lib/extensions/EXT_texture_webp.d.ts +2 -2
  40. package/dist/lib/extensions/EXT_texture_webp.d.ts.map +1 -1
  41. package/dist/lib/extensions/EXT_texture_webp.js +24 -17
  42. package/dist/lib/extensions/KHR_binary_gltf.d.ts +1 -1
  43. package/dist/lib/extensions/KHR_binary_gltf.d.ts.map +1 -1
  44. package/dist/lib/extensions/KHR_binary_gltf.js +29 -15
  45. package/dist/lib/extensions/KHR_draco_mesh_compression.d.ts +2 -2
  46. package/dist/lib/extensions/KHR_draco_mesh_compression.d.ts.map +1 -1
  47. package/dist/lib/extensions/KHR_draco_mesh_compression.js +110 -87
  48. package/dist/lib/extensions/KHR_texture_basisu.d.ts +2 -2
  49. package/dist/lib/extensions/KHR_texture_basisu.d.ts.map +1 -1
  50. package/dist/lib/extensions/KHR_texture_basisu.js +19 -12
  51. package/dist/lib/extensions/KHR_texture_transform.d.ts +2 -2
  52. package/dist/lib/extensions/KHR_texture_transform.d.ts.map +1 -1
  53. package/dist/lib/extensions/KHR_texture_transform.js +194 -154
  54. package/dist/lib/extensions/deprecated/EXT_feature_metadata.d.ts +2 -2
  55. package/dist/lib/extensions/deprecated/EXT_feature_metadata.d.ts.map +1 -1
  56. package/dist/lib/extensions/deprecated/EXT_feature_metadata.js +263 -143
  57. package/dist/lib/extensions/deprecated/KHR_lights_punctual.d.ts +1 -1
  58. package/dist/lib/extensions/deprecated/KHR_lights_punctual.d.ts.map +1 -1
  59. package/dist/lib/extensions/deprecated/KHR_lights_punctual.js +44 -32
  60. package/dist/lib/extensions/deprecated/KHR_materials_unlit.d.ts +1 -1
  61. package/dist/lib/extensions/deprecated/KHR_materials_unlit.d.ts.map +1 -1
  62. package/dist/lib/extensions/deprecated/KHR_materials_unlit.js +30 -24
  63. package/dist/lib/extensions/deprecated/KHR_techniques_webgl.d.ts +1 -1
  64. package/dist/lib/extensions/deprecated/KHR_techniques_webgl.d.ts.map +1 -1
  65. package/dist/lib/extensions/deprecated/KHR_techniques_webgl.js +65 -52
  66. package/dist/lib/extensions/utils/3d-tiles-utils.d.ts +2 -2
  67. package/dist/lib/extensions/utils/3d-tiles-utils.d.ts.map +1 -1
  68. package/dist/lib/extensions/utils/3d-tiles-utils.js +298 -181
  69. package/dist/lib/gltf-utils/get-typed-array.d.ts +1 -1
  70. package/dist/lib/gltf-utils/get-typed-array.d.ts.map +1 -1
  71. package/dist/lib/gltf-utils/get-typed-array.js +54 -42
  72. package/dist/lib/gltf-utils/gltf-attribute-utils.d.ts +1 -1
  73. package/dist/lib/gltf-utils/gltf-attribute-utils.d.ts.map +1 -1
  74. package/dist/lib/gltf-utils/gltf-attribute-utils.js +58 -52
  75. package/dist/lib/gltf-utils/gltf-constants.js +27 -27
  76. package/dist/lib/gltf-utils/gltf-utils.d.ts +1 -1
  77. package/dist/lib/gltf-utils/gltf-utils.d.ts.map +1 -1
  78. package/dist/lib/gltf-utils/gltf-utils.js +67 -60
  79. package/dist/lib/gltf-utils/resolve-url.js +12 -10
  80. package/dist/lib/parsers/parse-glb.d.ts +1 -1
  81. package/dist/lib/parsers/parse-glb.d.ts.map +1 -1
  82. package/dist/lib/parsers/parse-glb.js +132 -89
  83. package/dist/lib/parsers/parse-gltf.d.ts +3 -3
  84. package/dist/lib/parsers/parse-gltf.d.ts.map +1 -1
  85. package/dist/lib/parsers/parse-gltf.js +155 -126
  86. package/dist/lib/types/glb-types.js +0 -1
  87. package/dist/lib/types/gltf-ext-feature-metadata-schema.d.ts +1 -1
  88. package/dist/lib/types/gltf-ext-feature-metadata-schema.d.ts.map +1 -1
  89. package/dist/lib/types/gltf-ext-feature-metadata-schema.js +0 -1
  90. package/dist/lib/types/gltf-ext-mesh-features-schema.d.ts +1 -1
  91. package/dist/lib/types/gltf-ext-mesh-features-schema.d.ts.map +1 -1
  92. package/dist/lib/types/gltf-ext-mesh-features-schema.js +0 -1
  93. package/dist/lib/types/gltf-ext-structural-metadata-schema.d.ts +1 -1
  94. package/dist/lib/types/gltf-ext-structural-metadata-schema.d.ts.map +1 -1
  95. package/dist/lib/types/gltf-ext-structural-metadata-schema.js +0 -1
  96. package/dist/lib/types/gltf-json-schema.js +2 -1
  97. package/dist/lib/types/gltf-postprocessed-schema.js +2 -1
  98. package/dist/lib/types/gltf-types.d.ts +3 -3
  99. package/dist/lib/types/gltf-types.d.ts.map +1 -1
  100. package/dist/lib/types/gltf-types.js +1 -1
  101. package/dist/lib/utils/assert.js +6 -4
  102. package/dist/lib/utils/version.js +3 -1
  103. package/dist/meshopt/meshopt-decoder.js +86 -67
  104. package/dist/webp/webp.js +28 -19
  105. package/package.json +12 -8
  106. package/dist/glb-loader.js.map +0 -1
  107. package/dist/glb-writer.js.map +0 -1
  108. package/dist/gltf-loader.js.map +0 -1
  109. package/dist/gltf-writer.js.map +0 -1
  110. package/dist/index.js.map +0 -1
  111. package/dist/lib/api/gltf-extensions.js.map +0 -1
  112. package/dist/lib/api/gltf-scenegraph.js.map +0 -1
  113. package/dist/lib/api/normalize-gltf-v1.js.map +0 -1
  114. package/dist/lib/api/post-process-gltf.js.map +0 -1
  115. package/dist/lib/encoders/encode-glb.js.map +0 -1
  116. package/dist/lib/encoders/encode-gltf.js.map +0 -1
  117. package/dist/lib/extensions/EXT_mesh_features.js.map +0 -1
  118. package/dist/lib/extensions/EXT_meshopt_compression.js.map +0 -1
  119. package/dist/lib/extensions/EXT_structural_metadata.js.map +0 -1
  120. package/dist/lib/extensions/EXT_texture_webp.js.map +0 -1
  121. package/dist/lib/extensions/KHR_binary_gltf.js.map +0 -1
  122. package/dist/lib/extensions/KHR_draco_mesh_compression.js.map +0 -1
  123. package/dist/lib/extensions/KHR_texture_basisu.js.map +0 -1
  124. package/dist/lib/extensions/KHR_texture_transform.js.map +0 -1
  125. package/dist/lib/extensions/deprecated/EXT_feature_metadata.js.map +0 -1
  126. package/dist/lib/extensions/deprecated/KHR_lights_punctual.js.map +0 -1
  127. package/dist/lib/extensions/deprecated/KHR_materials_unlit.js.map +0 -1
  128. package/dist/lib/extensions/deprecated/KHR_techniques_webgl.js.map +0 -1
  129. package/dist/lib/extensions/utils/3d-tiles-utils.js.map +0 -1
  130. package/dist/lib/gltf-utils/get-typed-array.js.map +0 -1
  131. package/dist/lib/gltf-utils/gltf-attribute-utils.js.map +0 -1
  132. package/dist/lib/gltf-utils/gltf-constants.js.map +0 -1
  133. package/dist/lib/gltf-utils/gltf-utils.js.map +0 -1
  134. package/dist/lib/gltf-utils/resolve-url.js.map +0 -1
  135. package/dist/lib/parsers/parse-glb.js.map +0 -1
  136. package/dist/lib/parsers/parse-gltf.js.map +0 -1
  137. package/dist/lib/types/glb-types.js.map +0 -1
  138. package/dist/lib/types/gltf-ext-feature-metadata-schema.js.map +0 -1
  139. package/dist/lib/types/gltf-ext-mesh-features-schema.js.map +0 -1
  140. package/dist/lib/types/gltf-ext-structural-metadata-schema.js.map +0 -1
  141. package/dist/lib/types/gltf-json-schema.js.map +0 -1
  142. package/dist/lib/types/gltf-postprocessed-schema.js.map +0 -1
  143. package/dist/lib/types/gltf-types.js.map +0 -1
  144. package/dist/lib/utils/assert.js.map +0 -1
  145. package/dist/lib/utils/version.js.map +0 -1
  146. package/dist/meshopt/meshopt-decoder.js.map +0 -1
  147. package/dist/meshopt/meshopt-encoder.ts.disabled +0 -409
  148. package/dist/webp/webp.js.map +0 -1
@@ -1,179 +1,299 @@
1
1
  import { GLTFScenegraph } from "../../api/gltf-scenegraph.js";
2
2
  import { convertRawBufferToMetadataArray, getPrimitiveTextureData, primitivePropertyDataToAttributes, getArrayElementByteSize, getOffsetsForProperty, parseVariableLengthArrayNumeric, parseFixedLengthArrayNumeric, getPropertyDataString } from "../utils/3d-tiles-utils.js";
3
+ /** Extension name */
3
4
  const EXT_FEATURE_METADATA_NAME = 'EXT_feature_metadata';
4
5
  export const name = EXT_FEATURE_METADATA_NAME;
5
6
  export async function decode(gltfData, options) {
6
- const scenegraph = new GLTFScenegraph(gltfData);
7
- decodeExtFeatureMetadata(scenegraph, options);
7
+ const scenegraph = new GLTFScenegraph(gltfData);
8
+ decodeExtFeatureMetadata(scenegraph, options);
8
9
  }
10
+ /**
11
+ * Decodes feature metadata from extension.
12
+ * @param scenegraph - Instance of the class for structured access to GLTF data.
13
+ * @param options - GLTFLoader options.
14
+ */
9
15
  function decodeExtFeatureMetadata(scenegraph, options) {
10
- var _options$gltf, _options$gltf2;
11
- if (!((_options$gltf = options.gltf) !== null && _options$gltf !== void 0 && _options$gltf.loadBuffers)) {
12
- return;
13
- }
14
- const extension = scenegraph.getExtension(EXT_FEATURE_METADATA_NAME);
15
- if (!extension) {
16
- return;
17
- }
18
- if ((_options$gltf2 = options.gltf) !== null && _options$gltf2 !== void 0 && _options$gltf2.loadImages) {
19
- decodePropertyTextures(scenegraph, extension);
20
- }
21
- decodePropertyTables(scenegraph, extension);
16
+ // Decoding metadata involves buffers processing.
17
+ // So, if buffers have not been loaded, there is no reason to process metadata.
18
+ if (!options.gltf?.loadBuffers) {
19
+ return;
20
+ }
21
+ const extension = scenegraph.getExtension(EXT_FEATURE_METADATA_NAME);
22
+ if (!extension) {
23
+ return;
24
+ }
25
+ if (options.gltf?.loadImages) {
26
+ decodePropertyTextures(scenegraph, extension);
27
+ }
28
+ decodePropertyTables(scenegraph, extension);
22
29
  }
30
+ /**
31
+ * Processes the data stored in the textures
32
+ * @param scenegraph - Instance of the class for structured access to GLTF data.
33
+ * @param extension - Top-level extension.
34
+ */
23
35
  function decodePropertyTextures(scenegraph, extension) {
24
- const schema = extension.schema;
25
- if (!schema) {
26
- return;
27
- }
28
- const schemaClasses = schema.classes;
29
- const {
30
- featureTextures
31
- } = extension;
32
- if (schemaClasses && featureTextures) {
33
- for (const schemaName in schemaClasses) {
34
- const schemaClass = schemaClasses[schemaName];
35
- const featureTexture = findFeatureTextureByClass(featureTextures, schemaName);
36
- if (featureTexture) {
37
- handleFeatureTextureProperties(scenegraph, featureTexture, schemaClass);
38
- }
39
- }
40
- }
36
+ const schema = extension.schema;
37
+ if (!schema) {
38
+ return;
39
+ }
40
+ const schemaClasses = schema.classes;
41
+ const { featureTextures } = extension;
42
+ if (schemaClasses && featureTextures) {
43
+ for (const schemaName in schemaClasses) {
44
+ const schemaClass = schemaClasses[schemaName];
45
+ const featureTexture = findFeatureTextureByClass(featureTextures, schemaName);
46
+ if (featureTexture) {
47
+ handleFeatureTextureProperties(scenegraph, featureTexture, schemaClass);
48
+ }
49
+ }
50
+ }
41
51
  }
52
+ /**
53
+ * Processes the data stored in the property tables.
54
+ * @param scenegraph - Instance of the class for structured access to GLTF data.
55
+ * @param extension - Top-level extension.
56
+ */
42
57
  function decodePropertyTables(scenegraph, extension) {
43
- const schema = extension.schema;
44
- if (!schema) {
45
- return;
46
- }
47
- const schemaClasses = schema.classes;
48
- const propertyTables = extension.featureTables;
49
- if (schemaClasses && propertyTables) {
50
- for (const schemaName in schemaClasses) {
51
- const propertyTable = findPropertyTableByClass(propertyTables, schemaName);
52
- if (propertyTable) {
53
- processPropertyTable(scenegraph, schema, propertyTable);
54
- }
55
- }
56
- }
58
+ const schema = extension.schema;
59
+ if (!schema) {
60
+ return;
61
+ }
62
+ const schemaClasses = schema.classes;
63
+ const propertyTables = extension.featureTables;
64
+ if (schemaClasses && propertyTables) {
65
+ for (const schemaName in schemaClasses) {
66
+ const propertyTable = findPropertyTableByClass(propertyTables, schemaName);
67
+ if (propertyTable) {
68
+ processPropertyTable(scenegraph, schema, propertyTable);
69
+ }
70
+ }
71
+ }
57
72
  }
73
+ /**
74
+ * Finds the property table by class name.
75
+ * @param propertyTables - propertyTable definition taken from the top-level extension.
76
+ * @param schemaClassName - class name in the extension schema.
77
+ */
58
78
  function findPropertyTableByClass(propertyTables, schemaClassName) {
59
- for (const propertyTableName in propertyTables) {
60
- const propertyTable = propertyTables[propertyTableName];
61
- if (propertyTable.class === schemaClassName) {
62
- return propertyTable;
79
+ for (const propertyTableName in propertyTables) {
80
+ const propertyTable = propertyTables[propertyTableName];
81
+ if (propertyTable.class === schemaClassName) {
82
+ return propertyTable;
83
+ }
63
84
  }
64
- }
65
- return null;
85
+ return null;
66
86
  }
67
87
  function findFeatureTextureByClass(featureTextures, schemaClassName) {
68
- for (const featureTexturesName in featureTextures) {
69
- const featureTable = featureTextures[featureTexturesName];
70
- if (featureTable.class === schemaClassName) {
71
- return featureTable;
88
+ for (const featureTexturesName in featureTextures) {
89
+ const featureTable = featureTextures[featureTexturesName];
90
+ if (featureTable.class === schemaClassName) {
91
+ return featureTable;
92
+ }
72
93
  }
73
- }
74
- return null;
94
+ return null;
75
95
  }
96
+ /**
97
+ * Navigates through all properies in the property table, gets properties data,
98
+ * and put the data to `propertyTable.data` as an array.
99
+ * @param scenegraph - Instance of the class for structured access to GLTF data.
100
+ * @param schema - schema object.
101
+ * @param propertyTable - propertyTable definition taken from the top-level extension.
102
+ */
76
103
  function processPropertyTable(scenegraph, schema, propertyTable) {
77
- var _schema$classes;
78
- if (!propertyTable.class) {
79
- return;
80
- }
81
- const schemaClass = (_schema$classes = schema.classes) === null || _schema$classes === void 0 ? void 0 : _schema$classes[propertyTable.class];
82
- if (!schemaClass) {
83
- throw new Error(`Incorrect data in the EXT_structural_metadata extension: no schema class with name ${propertyTable.class}`);
84
- }
85
- const numberOfElements = propertyTable.count;
86
- for (const propertyName in schemaClass.properties) {
87
- var _propertyTable$proper;
88
- const classProperty = schemaClass.properties[propertyName];
89
- const propertyTableProperty = (_propertyTable$proper = propertyTable.properties) === null || _propertyTable$proper === void 0 ? void 0 : _propertyTable$proper[propertyName];
90
- if (propertyTableProperty) {
91
- const data = getPropertyDataFromBinarySource(scenegraph, schema, classProperty, numberOfElements, propertyTableProperty);
92
- propertyTableProperty.data = data;
93
- }
94
- }
104
+ // Though 'class' is not required by spec, it doesn't make any scence when it's not provided.
105
+ // So, bale out here.
106
+ if (!propertyTable.class) {
107
+ return;
108
+ }
109
+ const schemaClass = schema.classes?.[propertyTable.class];
110
+ if (!schemaClass) {
111
+ throw new Error(`Incorrect data in the EXT_structural_metadata extension: no schema class with name ${propertyTable.class}`);
112
+ }
113
+ const numberOfElements = propertyTable.count; // `propertyTable.count` is a number of elements in each property array.
114
+ for (const propertyName in schemaClass.properties) {
115
+ const classProperty = schemaClass.properties[propertyName];
116
+ const propertyTableProperty = propertyTable.properties?.[propertyName];
117
+ if (propertyTableProperty) {
118
+ // Getting all elements (`numberOfElements`) of the array in the `propertyTableProperty`
119
+ const data = getPropertyDataFromBinarySource(scenegraph, schema, classProperty, numberOfElements, propertyTableProperty);
120
+ propertyTableProperty.data = data;
121
+ }
122
+ }
95
123
  }
124
+ /**
125
+ * Navigates through all properies in feature texture and gets properties data.
126
+ * Data will be stored in featureTexture.properties[propertyName].data.
127
+ * @param scenegraph - Instance of the class for structured access to GLTF data.
128
+ * @param featureTexture
129
+ * @param schemaClass
130
+ */
96
131
  function handleFeatureTextureProperties(scenegraph, featureTexture, schemaClass) {
97
- const attributeName = featureTexture.class;
98
- for (const propertyName in schemaClass.properties) {
99
- var _featureTexture$prope;
100
- const featureTextureProperty = featureTexture === null || featureTexture === void 0 ? void 0 : (_featureTexture$prope = featureTexture.properties) === null || _featureTexture$prope === void 0 ? void 0 : _featureTexture$prope[propertyName];
101
- if (featureTextureProperty) {
102
- const data = getPropertyDataFromTexture(scenegraph, featureTextureProperty, attributeName);
103
- featureTextureProperty.data = data;
104
- }
105
- }
132
+ const attributeName = featureTexture.class;
133
+ for (const propertyName in schemaClass.properties) {
134
+ const featureTextureProperty = featureTexture?.properties?.[propertyName];
135
+ if (featureTextureProperty) {
136
+ const data = getPropertyDataFromTexture(scenegraph, featureTextureProperty, attributeName);
137
+ featureTextureProperty.data = data;
138
+ }
139
+ }
106
140
  }
141
+ /**
142
+ * Decodes properties from binary sourse based on property type.
143
+ * @param scenegraph - Instance of the class for structured access to GLTF data.
144
+ * @param schemaProperty
145
+ * @param numberOfFeatures
146
+ * @param featureTableProperty
147
+ */
107
148
  function getPropertyDataFromBinarySource(scenegraph, schema, classProperty, numberOfFeatures, featureTableProperty) {
108
- let data = [];
109
- const bufferView = featureTableProperty.bufferView;
110
- const dataArray = scenegraph.getTypedArrayForBufferView(bufferView);
111
- const arrayOffsets = getArrayOffsetsForProperty(scenegraph, classProperty, featureTableProperty, numberOfFeatures);
112
- const stringOffsets = getStringOffsetsForProperty(scenegraph, classProperty, featureTableProperty, numberOfFeatures);
113
- if (classProperty.type === 'STRING' || classProperty.componentType === 'STRING') {
114
- data = getPropertyDataString(numberOfFeatures, dataArray, arrayOffsets, stringOffsets);
115
- } else if (isNumericProperty(classProperty)) {
116
- data = getPropertyDataNumeric(classProperty, numberOfFeatures, dataArray, arrayOffsets);
117
- }
118
- return data;
149
+ let data = [];
150
+ const bufferView = featureTableProperty.bufferView;
151
+ const dataArray = scenegraph.getTypedArrayForBufferView(bufferView);
152
+ const arrayOffsets = getArrayOffsetsForProperty(scenegraph, classProperty, featureTableProperty, numberOfFeatures);
153
+ const stringOffsets = getStringOffsetsForProperty(scenegraph, classProperty, featureTableProperty, numberOfFeatures);
154
+ if (classProperty.type === 'STRING' || classProperty.componentType === 'STRING') {
155
+ data = getPropertyDataString(numberOfFeatures, dataArray, arrayOffsets, stringOffsets);
156
+ }
157
+ else if (isNumericProperty(classProperty)) {
158
+ data = getPropertyDataNumeric(classProperty, numberOfFeatures, dataArray, arrayOffsets);
159
+ }
160
+ return data;
119
161
  }
162
+ /**
163
+ * Parses propertyTable.property.arrayOffsets that are offsets of sub-arrays in a flatten array of values.
164
+ * @param scenegraph - Instance of the class for structured access to GLTF data.
165
+ * @param classProperty - class property object.
166
+ * @param propertyTableProperty - propertyTable's property metadata.
167
+ * @param numberOfElements - The number of elements in each property array that propertyTableProperty contains. It's a number of rows in the table.
168
+ * @returns Typed array with offset values.
169
+ * @see https://github.com/CesiumGS/glTF/blob/2976f1183343a47a29e4059a70961371cd2fcee8/extensions/2.0/Vendor/EXT_structural_metadata/schema/propertyTable.property.schema.json#L21
170
+ */
120
171
  function getArrayOffsetsForProperty(scenegraph, classProperty, propertyTableProperty, numberOfElements) {
121
- if (classProperty.type === 'ARRAY' && typeof classProperty.componentCount === 'undefined' && typeof propertyTableProperty.arrayOffsetBufferView !== 'undefined') {
122
- return getOffsetsForProperty(scenegraph, propertyTableProperty.arrayOffsetBufferView, propertyTableProperty.offsetType || 'UINT32', numberOfElements);
123
- }
124
- return null;
172
+ /*
173
+ If ARRAY is used, then componentType must also be specified.
174
+ ARRAY is a fixed-length array when componentCount is defined, and variable-length otherwise.
175
+ */
176
+ if (classProperty.type === 'ARRAY' &&
177
+ // `componentCount` is a number of fixed-length array elements.
178
+ // If `componentCount` is NOT defined, it's a VARIABLE-length array
179
+ typeof classProperty.componentCount === 'undefined' &&
180
+ // `arrayOffsetBufferView` is an index of the buffer view containing offsets for variable-length arrays.
181
+ typeof propertyTableProperty.arrayOffsetBufferView !== 'undefined') {
182
+ // Data are in a VARIABLE-length array
183
+ return getOffsetsForProperty(scenegraph, propertyTableProperty.arrayOffsetBufferView, propertyTableProperty.offsetType || 'UINT32', // offsetType is used both for stringOffsetBufferView and arrayOffsetBufferView
184
+ numberOfElements);
185
+ }
186
+ return null;
125
187
  }
188
+ /**
189
+ * Parses featureTable.property.stringOffsetBufferView.
190
+ * String offsets is an array of offsets of strings in the united array of characters.
191
+ * @param scenegraph - Instance of the class for structured access to GLTF data.
192
+ * @param propertyTableProperty - propertyTable's property metadata.
193
+ * @param numberOfElements - The number of elements in each property array that propertyTableProperty contains. It's a number of rows in the table.
194
+ * @returns Typed array of offset values. The number of offsets in the array is equal to `numberOfElements` plus one.
195
+ * @see https://github.com/CesiumGS/glTF/blob/c38f7f37e894004353c15cd0481bc5b7381ce841/extensions/2.0/Vendor/EXT_feature_metadata/schema/featureTable.property.schema.json#L50C10-L50C32
196
+ */
126
197
  function getStringOffsetsForProperty(scenegraph, classProperty, propertyTableProperty, numberOfElements) {
127
- if (typeof propertyTableProperty.stringOffsetBufferView !== 'undefined') {
128
- return getOffsetsForProperty(scenegraph, propertyTableProperty.stringOffsetBufferView, propertyTableProperty.offsetType || 'UINT32', numberOfElements);
129
- }
130
- return null;
198
+ if (typeof propertyTableProperty.stringOffsetBufferView !== 'undefined' // `stringOffsetBufferView` is an index of the buffer view containing offsets for strings.
199
+ ) {
200
+ // Data are in a FIXED-length array
201
+ return getOffsetsForProperty(scenegraph, propertyTableProperty.stringOffsetBufferView, propertyTableProperty.offsetType || 'UINT32', // offsetType is used both for stringOffsetBufferView and arrayOffsetBufferView
202
+ numberOfElements);
203
+ }
204
+ return null;
131
205
  }
206
+ /**
207
+ * Checks if the feature table property is of numeric type.
208
+ * @param schemaPropertyType - feature table property
209
+ * @returns true if property is numeric, else - false
210
+ */
132
211
  function isNumericProperty(schemaProperty) {
133
- const types = ['UINT8', 'INT16', 'UINT16', 'INT32', 'UINT32', 'INT64', 'UINT64', 'FLOAT32', 'FLOAT64'];
134
- return types.includes(schemaProperty.type) || typeof schemaProperty.componentType !== 'undefined' && types.includes(schemaProperty.componentType);
212
+ const types = [
213
+ 'UINT8',
214
+ 'INT16',
215
+ 'UINT16',
216
+ 'INT32',
217
+ 'UINT32',
218
+ 'INT64',
219
+ 'UINT64',
220
+ 'FLOAT32',
221
+ 'FLOAT64'
222
+ ];
223
+ return (types.includes(schemaProperty.type) ||
224
+ (typeof schemaProperty.componentType !== 'undefined' &&
225
+ types.includes(schemaProperty.componentType)));
135
226
  }
227
+ /**
228
+ * Decodes properties of numeric types from binary sourse.
229
+ * @param classProperty - class property object.
230
+ * @param numberOfElements - The number of elements in each property array that propertyTableProperty contains. It's a number of rows in the table.
231
+ * @param valuesDataBytes - Data taken from values property of the property table property.
232
+ * @param arrayOffsets - Offsets for variable-length arrays. It's null for fixed-length arrays or scalar types.
233
+ * @returns Property values in a typed array or in an array of typed arrays.
234
+ */
136
235
  function getPropertyDataNumeric(classProperty, numberOfElements, valuesDataBytes, arrayOffsets) {
137
- const isArray = classProperty.type === 'ARRAY';
138
- const arrayCount = classProperty.componentCount;
139
- const attributeType = 'SCALAR';
140
- const componentType = classProperty.componentType || classProperty.type;
141
- const elementSize = getArrayElementByteSize(attributeType, componentType);
142
- const elementCount = valuesDataBytes.byteLength / elementSize;
143
- const valuesData = convertRawBufferToMetadataArray(valuesDataBytes, attributeType, componentType, elementCount);
144
- if (isArray) {
145
- if (arrayOffsets) {
146
- return parseVariableLengthArrayNumeric(valuesData, numberOfElements, arrayOffsets, valuesDataBytes.length, elementSize);
147
- }
148
- if (arrayCount) {
149
- return parseFixedLengthArrayNumeric(valuesData, numberOfElements, arrayCount);
150
- }
151
- return [];
152
- }
153
- return valuesData;
236
+ const isArray = classProperty.type === 'ARRAY';
237
+ const arrayCount = classProperty.componentCount;
238
+ /*
239
+ We are getting Numeric data. So,
240
+ the component type can be one of NumericComponentType,
241
+ the attribute type should be 'SCALAR'
242
+ */
243
+ const attributeType = 'SCALAR';
244
+ const componentType = classProperty.componentType || classProperty.type;
245
+ const elementSize = getArrayElementByteSize(attributeType, componentType);
246
+ const elementCount = valuesDataBytes.byteLength / elementSize;
247
+ const valuesData = convertRawBufferToMetadataArray(valuesDataBytes, attributeType, componentType, elementCount);
248
+ if (isArray) {
249
+ if (arrayOffsets) {
250
+ // VARIABLE-length array
251
+ return parseVariableLengthArrayNumeric(valuesData, numberOfElements, arrayOffsets, valuesDataBytes.length, elementSize);
252
+ }
253
+ if (arrayCount) {
254
+ // FIXED-length array
255
+ return parseFixedLengthArrayNumeric(valuesData, numberOfElements, arrayCount);
256
+ }
257
+ return [];
258
+ }
259
+ return valuesData;
154
260
  }
261
+ /**
262
+ * Gets properties from texture associated with all mesh primitives.
263
+ * @param scenegraph - Instance of the class for structured access to GLTF data.
264
+ * @param featureTextureProperty
265
+ * @param attributeName
266
+ * @returns Feature texture data
267
+ */
155
268
  function getPropertyDataFromTexture(scenegraph, featureTextureProperty, attributeName) {
156
- const json = scenegraph.gltf.json;
157
- if (!json.meshes) {
158
- return [];
159
- }
160
- const featureTextureTable = [];
161
- for (const mesh of json.meshes) {
162
- for (const primitive of mesh.primitives) {
163
- processPrimitiveTextures(scenegraph, attributeName, featureTextureProperty, featureTextureTable, primitive);
164
- }
165
- }
166
- return featureTextureTable;
269
+ const json = scenegraph.gltf.json;
270
+ if (!json.meshes) {
271
+ return [];
272
+ }
273
+ const featureTextureTable = [];
274
+ for (const mesh of json.meshes) {
275
+ for (const primitive of mesh.primitives) {
276
+ processPrimitiveTextures(scenegraph, attributeName, featureTextureProperty, featureTextureTable, primitive);
277
+ }
278
+ }
279
+ return featureTextureTable;
167
280
  }
281
+ /**
282
+ * Processes data encoded in the texture associated with the primitive. This data will be accessible through the attributes.
283
+ * @param scenegraph - Instance of the class for structured access to GLTF data.
284
+ * @param attributeName
285
+ * @param featureTextureProperty
286
+ * @param featureTextureTable
287
+ * @param primitive
288
+ */
168
289
  function processPrimitiveTextures(scenegraph, attributeName, featureTextureProperty, featureTextureTable, primitive) {
169
- const textureInfoTopLevel = {
170
- channels: featureTextureProperty.channels,
171
- ...featureTextureProperty.texture
172
- };
173
- const propertyData = getPrimitiveTextureData(scenegraph, textureInfoTopLevel, primitive);
174
- if (!propertyData) {
175
- return;
176
- }
177
- primitivePropertyDataToAttributes(scenegraph, attributeName, propertyData, featureTextureTable, primitive);
290
+ const textureInfoTopLevel = {
291
+ channels: featureTextureProperty.channels,
292
+ ...featureTextureProperty.texture
293
+ };
294
+ const propertyData = getPrimitiveTextureData(scenegraph, textureInfoTopLevel, primitive);
295
+ if (!propertyData) {
296
+ return;
297
+ }
298
+ primitivePropertyDataToAttributes(scenegraph, attributeName, propertyData, featureTextureTable, primitive);
178
299
  }
179
- //# sourceMappingURL=EXT_feature_metadata.js.map
@@ -1,4 +1,4 @@
1
- import type { GLTF } from '../../types/gltf-json-schema';
1
+ import type { GLTF } from "../../types/gltf-json-schema.js";
2
2
  export declare const name = "KHR_lights_punctual";
3
3
  export declare function decode(gltfData: {
4
4
  json: GLTF;
@@ -1 +1 @@
1
- {"version":3,"file":"KHR_lights_punctual.d.ts","sourceRoot":"","sources":["../../../../src/lib/extensions/deprecated/KHR_lights_punctual.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAC,IAAI,EAAC,MAAM,8BAA8B,CAAC;AAOvD,eAAO,MAAM,IAAI,wBAAsB,CAAC;AAExC,wBAAsB,MAAM,CAAC,QAAQ,EAAE;IAAC,IAAI,EAAE,IAAI,CAAA;CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CAsBlE;AAGD,wBAAsB,MAAM,CAAC,QAAQ,KAAA,GAAG,OAAO,CAAC,IAAI,CAAC,CA2BpD"}
1
+ {"version":3,"file":"KHR_lights_punctual.d.ts","sourceRoot":"","sources":["../../../../src/lib/extensions/deprecated/KHR_lights_punctual.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAC,IAAI,EAAC,wCAAqC;AAOvD,eAAO,MAAM,IAAI,wBAAsB,CAAC;AAExC,wBAAsB,MAAM,CAAC,QAAQ,EAAE;IAAC,IAAI,EAAE,IAAI,CAAA;CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CAsBlE;AAGD,wBAAsB,MAAM,CAAC,QAAQ,KAAA,GAAG,OAAO,CAAC,IAAI,CAAC,CA2BpD"}
@@ -1,42 +1,54 @@
1
+ // GLTF EXTENSION: KHR_lights_punctual
2
+ // https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_lights_punctual
1
3
  import { assert } from "../../utils/assert.js";
2
4
  import { GLTFScenegraph } from "../../api/gltf-scenegraph.js";
3
5
  const KHR_LIGHTS_PUNCTUAL = 'KHR_lights_punctual';
4
6
  export const name = KHR_LIGHTS_PUNCTUAL;
5
7
  export async function decode(gltfData) {
6
- const gltfScenegraph = new GLTFScenegraph(gltfData);
7
- const {
8
- json
9
- } = gltfScenegraph;
10
- const extension = gltfScenegraph.getExtension(KHR_LIGHTS_PUNCTUAL);
11
- if (extension) {
12
- gltfScenegraph.json.lights = extension.lights;
13
- gltfScenegraph.removeExtension(KHR_LIGHTS_PUNCTUAL);
14
- }
15
- for (const node of json.nodes || []) {
16
- const nodeExtension = gltfScenegraph.getObjectExtension(node, KHR_LIGHTS_PUNCTUAL);
17
- if (nodeExtension) {
18
- node.light = nodeExtension.light;
8
+ const gltfScenegraph = new GLTFScenegraph(gltfData);
9
+ const { json } = gltfScenegraph;
10
+ // Move the light array out of the extension and remove the extension
11
+ const extension = gltfScenegraph.getExtension(KHR_LIGHTS_PUNCTUAL);
12
+ if (extension) {
13
+ // @ts-ignore
14
+ gltfScenegraph.json.lights = extension.lights;
15
+ gltfScenegraph.removeExtension(KHR_LIGHTS_PUNCTUAL);
16
+ }
17
+ // Any nodes that have the extension, add lights field pointing to light object
18
+ // and remove the extension
19
+ for (const node of json.nodes || []) {
20
+ const nodeExtension = gltfScenegraph.getObjectExtension(node, KHR_LIGHTS_PUNCTUAL);
21
+ if (nodeExtension) {
22
+ // @ts-ignore
23
+ node.light = nodeExtension.light;
24
+ }
25
+ gltfScenegraph.removeObjectExtension(node, KHR_LIGHTS_PUNCTUAL);
19
26
  }
20
- gltfScenegraph.removeObjectExtension(node, KHR_LIGHTS_PUNCTUAL);
21
- }
22
27
  }
28
+ // Move the light ar ray out of the extension and remove the extension
23
29
  export async function encode(gltfData) {
24
- const gltfScenegraph = new GLTFScenegraph(gltfData);
25
- const {
26
- json
27
- } = gltfScenegraph;
28
- if (json.lights) {
29
- const extension = gltfScenegraph.addExtension(KHR_LIGHTS_PUNCTUAL);
30
- assert(!extension.lights);
31
- extension.lights = json.lights;
32
- delete json.lights;
33
- }
34
- if (gltfScenegraph.json.lights) {
35
- for (const light of gltfScenegraph.json.lights) {
36
- const node = light.node;
37
- gltfScenegraph.addObjectExtension(node, KHR_LIGHTS_PUNCTUAL, light);
30
+ const gltfScenegraph = new GLTFScenegraph(gltfData);
31
+ const { json } = gltfScenegraph;
32
+ // @ts-ignore
33
+ if (json.lights) {
34
+ const extension = gltfScenegraph.addExtension(KHR_LIGHTS_PUNCTUAL);
35
+ // @ts-ignore
36
+ assert(!extension.lights);
37
+ // @ts-ignore
38
+ extension.lights = json.lights;
39
+ // @ts-ignore
40
+ delete json.lights;
41
+ }
42
+ // Any nodes that have lights field pointing to light object
43
+ // add the extension
44
+ // @ts-ignore
45
+ if (gltfScenegraph.json.lights) {
46
+ // @ts-ignore
47
+ for (const light of gltfScenegraph.json.lights) {
48
+ const node = light.node;
49
+ gltfScenegraph.addObjectExtension(node, KHR_LIGHTS_PUNCTUAL, light);
50
+ }
51
+ // @ts-ignore
52
+ delete gltfScenegraph.json.lights;
38
53
  }
39
- delete gltfScenegraph.json.lights;
40
- }
41
54
  }
42
- //# sourceMappingURL=KHR_lights_punctual.js.map
@@ -1,4 +1,4 @@
1
- import type { GLTF } from '../../types/gltf-json-schema';
1
+ import type { GLTF } from "../../types/gltf-json-schema.js";
2
2
  export declare const name = "KHR_materials_unlit";
3
3
  export declare function decode(gltfData: {
4
4
  json: GLTF;
@@ -1 +1 @@
1
- {"version":3,"file":"KHR_materials_unlit.d.ts","sourceRoot":"","sources":["../../../../src/lib/extensions/deprecated/KHR_materials_unlit.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAC,IAAI,EAAC,MAAM,8BAA8B,CAAC;AAMvD,eAAO,MAAM,IAAI,wBAAsB,CAAC;AAExC,wBAAsB,MAAM,CAAC,QAAQ,EAAE;IAAC,IAAI,EAAE,IAAI,CAAA;CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CAiBlE;AAED,wBAAgB,MAAM,CAAC,QAAQ,KAAA,QAkB9B"}
1
+ {"version":3,"file":"KHR_materials_unlit.d.ts","sourceRoot":"","sources":["../../../../src/lib/extensions/deprecated/KHR_materials_unlit.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAC,IAAI,EAAC,wCAAqC;AAMvD,eAAO,MAAM,IAAI,wBAAsB,CAAC;AAExC,wBAAsB,MAAM,CAAC,QAAQ,EAAE;IAAC,IAAI,EAAE,IAAI,CAAA;CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CAiBlE;AAED,wBAAgB,MAAM,CAAC,QAAQ,KAAA,QAkB9B"}
@@ -1,33 +1,39 @@
1
+ // GLTF EXTENSION: KHR_materials_unlit
2
+ // https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_unlit
1
3
  import { GLTFScenegraph } from "../../api/gltf-scenegraph.js";
2
4
  const KHR_MATERIALS_UNLIT = 'KHR_materials_unlit';
3
5
  export const name = KHR_MATERIALS_UNLIT;
4
6
  export async function decode(gltfData) {
5
- const gltfScenegraph = new GLTFScenegraph(gltfData);
6
- const {
7
- json
8
- } = gltfScenegraph;
9
- for (const material of json.materials || []) {
10
- const extension = material.extensions && material.extensions.KHR_materials_unlit;
11
- if (extension) {
12
- material.unlit = true;
7
+ const gltfScenegraph = new GLTFScenegraph(gltfData);
8
+ const { json } = gltfScenegraph;
9
+ // Any nodes that have the extension, add lights field pointing to light object
10
+ // and remove the extension
11
+ for (const material of json.materials || []) {
12
+ const extension = material.extensions && material.extensions.KHR_materials_unlit;
13
+ if (extension) {
14
+ // @ts-ignore TODO
15
+ material.unlit = true;
16
+ }
17
+ gltfScenegraph.removeObjectExtension(material, KHR_MATERIALS_UNLIT);
13
18
  }
14
- gltfScenegraph.removeObjectExtension(material, KHR_MATERIALS_UNLIT);
15
- }
16
- gltfScenegraph.removeExtension(KHR_MATERIALS_UNLIT);
19
+ // Remove the top-level extension
20
+ gltfScenegraph.removeExtension(KHR_MATERIALS_UNLIT);
17
21
  }
18
22
  export function encode(gltfData) {
19
- const gltfScenegraph = new GLTFScenegraph(gltfData);
20
- const {
21
- json
22
- } = gltfScenegraph;
23
- if (gltfScenegraph.materials) {
24
- for (const material of json.materials || []) {
25
- if (material.unlit) {
26
- delete material.unlit;
27
- gltfScenegraph.addObjectExtension(material, KHR_MATERIALS_UNLIT, {});
28
- gltfScenegraph.addExtension(KHR_MATERIALS_UNLIT);
29
- }
23
+ const gltfScenegraph = new GLTFScenegraph(gltfData);
24
+ const { json } = gltfScenegraph;
25
+ // Any nodes that have lights field pointing to light object
26
+ // add the extension
27
+ // @ts-ignore
28
+ if (gltfScenegraph.materials) {
29
+ for (const material of json.materials || []) {
30
+ // @ts-ignore
31
+ if (material.unlit) {
32
+ // @ts-ignore
33
+ delete material.unlit;
34
+ gltfScenegraph.addObjectExtension(material, KHR_MATERIALS_UNLIT, {});
35
+ gltfScenegraph.addExtension(KHR_MATERIALS_UNLIT);
36
+ }
37
+ }
30
38
  }
31
- }
32
39
  }
33
- //# sourceMappingURL=KHR_materials_unlit.js.map
@@ -1,4 +1,4 @@
1
- import type { GLTF } from '../../types/gltf-json-schema';
1
+ import type { GLTF } from "../../types/gltf-json-schema.js";
2
2
  export declare const name = "KHR_techniques_webgl";
3
3
  export declare function decode(gltfData: {
4
4
  json: GLTF;
@@ -1 +1 @@
1
- {"version":3,"file":"KHR_techniques_webgl.d.ts","sourceRoot":"","sources":["../../../../src/lib/extensions/deprecated/KHR_techniques_webgl.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAC,IAAI,EAAC,MAAM,8BAA8B,CAAC;AAMvD,eAAO,MAAM,IAAI,yBAAuB,CAAC;AAEzC,wBAAsB,MAAM,CAAC,QAAQ,EAAE;IAAC,IAAI,EAAE,IAAI,CAAA;CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CA2BlE;AAED,wBAAsB,MAAM,CAAC,QAAQ,KAAA,EAAE,OAAO,KAAA,GAAG,OAAO,CAAC,IAAI,CAAC,CAE7D"}
1
+ {"version":3,"file":"KHR_techniques_webgl.d.ts","sourceRoot":"","sources":["../../../../src/lib/extensions/deprecated/KHR_techniques_webgl.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAC,IAAI,EAAC,wCAAqC;AAMvD,eAAO,MAAM,IAAI,yBAAuB,CAAC;AAEzC,wBAAsB,MAAM,CAAC,QAAQ,EAAE;IAAC,IAAI,EAAE,IAAI,CAAA;CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CA2BlE;AAED,wBAAsB,MAAM,CAAC,QAAQ,KAAA,EAAE,OAAO,KAAA,GAAG,OAAO,CAAC,IAAI,CAAC,CAE7D"}