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

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,215 @@
1
+ import { getComponentTypeFromArray, getFloat32ArrayForAccessor } from '../../gltf-utils/gltf-utils';
2
+ import { getImageData } from '@loaders.gl/images';
3
+ import { emod } from '@loaders.gl/math';
4
+ const ATTRIBUTE_TYPE_TO_COMPONENTS = {
5
+ SCALAR: 1,
6
+ VEC2: 2,
7
+ VEC3: 3,
8
+ VEC4: 4,
9
+ MAT2: 4,
10
+ MAT3: 9,
11
+ MAT4: 16,
12
+ BOOLEAN: 1,
13
+ STRING: 1,
14
+ ENUM: 1
15
+ };
16
+ const ATTRIBUTE_COMPONENT_TYPE_TO_ARRAY = {
17
+ INT8: Int8Array,
18
+ UINT8: Uint8Array,
19
+ INT16: Int16Array,
20
+ UINT16: Uint16Array,
21
+ INT32: Int32Array,
22
+ UINT32: Uint32Array,
23
+ INT64: BigInt64Array,
24
+ UINT64: BigUint64Array,
25
+ FLOAT32: Float32Array,
26
+ FLOAT64: Float64Array
27
+ };
28
+ const ATTRIBUTE_COMPONENT_TYPE_TO_BYTE_SIZE = {
29
+ INT8: 1,
30
+ UINT8: 1,
31
+ INT16: 2,
32
+ UINT16: 2,
33
+ INT32: 4,
34
+ UINT32: 4,
35
+ INT64: 8,
36
+ UINT64: 8,
37
+ FLOAT32: 4,
38
+ FLOAT64: 8
39
+ };
40
+ export function getArrayElementByteSize(attributeType, componentType) {
41
+ return ATTRIBUTE_COMPONENT_TYPE_TO_BYTE_SIZE[componentType] * ATTRIBUTE_TYPE_TO_COMPONENTS[attributeType];
42
+ }
43
+ export function getOffsetsForProperty(scenegraph, bufferViewIndex, offsetType, numberOfElements) {
44
+ if (offsetType !== 'UINT8' && offsetType !== 'UINT16' && offsetType !== 'UINT32' && offsetType !== 'UINT64') {
45
+ return null;
46
+ }
47
+ const arrayOffsetsBytes = scenegraph.getTypedArrayForBufferView(bufferViewIndex);
48
+ const arrayOffsets = convertRawBufferToMetadataArray(arrayOffsetsBytes, 'SCALAR', offsetType, numberOfElements + 1);
49
+ if (arrayOffsets instanceof BigInt64Array || arrayOffsets instanceof BigUint64Array) {
50
+ return null;
51
+ }
52
+ return arrayOffsets;
53
+ }
54
+ export function convertRawBufferToMetadataArray(data, attributeType, componentType) {
55
+ let elementCount = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 1;
56
+ const numberOfComponents = ATTRIBUTE_TYPE_TO_COMPONENTS[attributeType];
57
+ const ArrayType = ATTRIBUTE_COMPONENT_TYPE_TO_ARRAY[componentType];
58
+ const size = ATTRIBUTE_COMPONENT_TYPE_TO_BYTE_SIZE[componentType];
59
+ const length = elementCount * numberOfComponents;
60
+ const byteLength = length * size;
61
+ let buffer = data.buffer;
62
+ let offset = data.byteOffset;
63
+ if (offset % size !== 0) {
64
+ const bufferArray = new Uint8Array(buffer);
65
+ buffer = bufferArray.slice(offset, offset + byteLength).buffer;
66
+ offset = 0;
67
+ }
68
+ return new ArrayType(buffer, offset, length);
69
+ }
70
+ export function getPrimitiveTextureData(scenegraph, textureInfo, primitive) {
71
+ var _json$textures, _json$textures$textur;
72
+ const json = scenegraph.gltf.json;
73
+ const texCoordAccessorKey = "TEXCOORD_".concat(textureInfo.texCoord || 0);
74
+ const texCoordAccessorIndex = primitive.attributes[texCoordAccessorKey];
75
+ const textureCoordinates = getFloat32ArrayForAccessor(scenegraph.gltf, texCoordAccessorIndex);
76
+ if (!textureCoordinates) {
77
+ return null;
78
+ }
79
+ const textureIndex = textureInfo.index;
80
+ const imageIndex = (_json$textures = json.textures) === null || _json$textures === void 0 ? void 0 : (_json$textures$textur = _json$textures[textureIndex]) === null || _json$textures$textur === void 0 ? void 0 : _json$textures$textur.source;
81
+ if (typeof imageIndex !== 'undefined') {
82
+ var _json$images, _json$images$imageInd, _scenegraph$gltf$imag;
83
+ const mimeType = (_json$images = json.images) === null || _json$images === void 0 ? void 0 : (_json$images$imageInd = _json$images[imageIndex]) === null || _json$images$imageInd === void 0 ? void 0 : _json$images$imageInd.mimeType;
84
+ const parsedImage = (_scenegraph$gltf$imag = scenegraph.gltf.images) === null || _scenegraph$gltf$imag === void 0 ? void 0 : _scenegraph$gltf$imag[imageIndex];
85
+ if (parsedImage && typeof parsedImage.width !== 'undefined') {
86
+ const textureData = [];
87
+ for (let index = 0; index < textureCoordinates.length; index += 2) {
88
+ const value = getImageValueByCoordinates(parsedImage, mimeType, textureCoordinates, index, textureInfo.channels);
89
+ textureData.push(value);
90
+ }
91
+ return textureData;
92
+ }
93
+ }
94
+ return null;
95
+ }
96
+ export function primitivePropertyDataToAttributes(scenegraph, attributeName, propertyData, featureTable, primitive) {
97
+ if (!(propertyData !== null && propertyData !== void 0 && propertyData.length)) {
98
+ return;
99
+ }
100
+ const featureIndices = [];
101
+ for (const texelData of propertyData) {
102
+ let index = featureTable.findIndex(item => item === texelData);
103
+ if (index === -1) {
104
+ index = featureTable.push(texelData) - 1;
105
+ }
106
+ featureIndices.push(index);
107
+ }
108
+ const typedArray = new Uint32Array(featureIndices);
109
+ const bufferIndex = scenegraph.gltf.buffers.push({
110
+ arrayBuffer: typedArray.buffer,
111
+ byteOffset: typedArray.byteOffset,
112
+ byteLength: typedArray.byteLength
113
+ }) - 1;
114
+ const bufferViewIndex = scenegraph.addBufferView(typedArray, bufferIndex, 0);
115
+ const accessorIndex = scenegraph.addAccessor(bufferViewIndex, {
116
+ size: 1,
117
+ componentType: getComponentTypeFromArray(typedArray),
118
+ count: typedArray.length
119
+ });
120
+ primitive.attributes[attributeName] = accessorIndex;
121
+ }
122
+ function getImageValueByCoordinates(parsedImage, mimeType, textureCoordinates, index) {
123
+ let channels = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : [0];
124
+ const CHANNELS_MAP = {
125
+ r: {
126
+ offset: 0,
127
+ shift: 0
128
+ },
129
+ g: {
130
+ offset: 1,
131
+ shift: 8
132
+ },
133
+ b: {
134
+ offset: 2,
135
+ shift: 16
136
+ },
137
+ a: {
138
+ offset: 3,
139
+ shift: 24
140
+ }
141
+ };
142
+ const u = textureCoordinates[index];
143
+ const v = textureCoordinates[index + 1];
144
+ let components = 1;
145
+ if (mimeType && (mimeType.indexOf('image/jpeg') !== -1 || mimeType.indexOf('image/png') !== -1)) components = 4;
146
+ const offset = coordinatesToOffset(u, v, parsedImage, components);
147
+ let value = 0;
148
+ for (const c of channels) {
149
+ const map = typeof c === 'number' ? Object.values(CHANNELS_MAP)[c] : CHANNELS_MAP[c];
150
+ const imageOffset = offset + map.offset;
151
+ const imageData = getImageData(parsedImage);
152
+ if (imageData.data.length <= imageOffset) {
153
+ throw new Error("".concat(imageData.data.length, " <= ").concat(imageOffset));
154
+ }
155
+ const imageValue = imageData.data[imageOffset];
156
+ value |= imageValue << map.shift;
157
+ }
158
+ return value;
159
+ }
160
+ function coordinatesToOffset(u, v, parsedImage) {
161
+ let componentsCount = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 1;
162
+ const w = parsedImage.width;
163
+ const iX = emod(u) * (w - 1);
164
+ const indX = Math.round(iX);
165
+ const h = parsedImage.height;
166
+ const iY = emod(v) * (h - 1);
167
+ const indY = Math.round(iY);
168
+ const components = parsedImage.components ? parsedImage.components : componentsCount;
169
+ const offset = (indY * w + indX) * components;
170
+ return offset;
171
+ }
172
+ export function parseVariableLengthArrayNumeric(valuesData, numberOfElements, arrayOffsets, valuesDataBytesLength, valueSize) {
173
+ const attributeValueArray = [];
174
+ for (let index = 0; index < numberOfElements; index++) {
175
+ const arrayOffset = arrayOffsets[index];
176
+ const arrayByteSize = arrayOffsets[index + 1] - arrayOffsets[index];
177
+ if (arrayByteSize + arrayOffset > valuesDataBytesLength) {
178
+ break;
179
+ }
180
+ const typedArrayOffset = arrayOffset / valueSize;
181
+ const elementCount = arrayByteSize / valueSize;
182
+ attributeValueArray.push(valuesData.slice(typedArrayOffset, typedArrayOffset + elementCount));
183
+ }
184
+ return attributeValueArray;
185
+ }
186
+ export function parseFixedLengthArrayNumeric(valuesData, numberOfElements, arrayCount) {
187
+ const attributeValueArray = [];
188
+ for (let index = 0; index < numberOfElements; index++) {
189
+ const elementOffset = index * arrayCount;
190
+ attributeValueArray.push(valuesData.slice(elementOffset, elementOffset + arrayCount));
191
+ }
192
+ return attributeValueArray;
193
+ }
194
+ export function getPropertyDataString(numberOfElements, valuesDataBytes, arrayOffsets, stringOffsets) {
195
+ if (arrayOffsets) {
196
+ throw new Error('Not implemented - arrayOffsets for strings is specified');
197
+ }
198
+ if (stringOffsets) {
199
+ const stringsArray = [];
200
+ const textDecoder = new TextDecoder('utf8');
201
+ let stringOffset = 0;
202
+ for (let index = 0; index < numberOfElements; index++) {
203
+ const stringByteSize = stringOffsets[index + 1] - stringOffsets[index];
204
+ if (stringByteSize + stringOffset <= valuesDataBytes.length) {
205
+ const stringData = valuesDataBytes.subarray(stringOffset, stringByteSize + stringOffset);
206
+ const stringAttribute = textDecoder.decode(stringData);
207
+ stringsArray.push(stringAttribute);
208
+ stringOffset += stringByteSize;
209
+ }
210
+ }
211
+ return stringsArray;
212
+ }
213
+ return [];
214
+ }
215
+ //# sourceMappingURL=3d-tiles-utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"3d-tiles-utils.js","names":["getComponentTypeFromArray","getFloat32ArrayForAccessor","getImageData","emod","ATTRIBUTE_TYPE_TO_COMPONENTS","SCALAR","VEC2","VEC3","VEC4","MAT2","MAT3","MAT4","BOOLEAN","STRING","ENUM","ATTRIBUTE_COMPONENT_TYPE_TO_ARRAY","INT8","Int8Array","UINT8","Uint8Array","INT16","Int16Array","UINT16","Uint16Array","INT32","Int32Array","UINT32","Uint32Array","INT64","BigInt64Array","UINT64","BigUint64Array","FLOAT32","Float32Array","FLOAT64","Float64Array","ATTRIBUTE_COMPONENT_TYPE_TO_BYTE_SIZE","getArrayElementByteSize","attributeType","componentType","getOffsetsForProperty","scenegraph","bufferViewIndex","offsetType","numberOfElements","arrayOffsetsBytes","getTypedArrayForBufferView","arrayOffsets","convertRawBufferToMetadataArray","data","elementCount","arguments","length","undefined","numberOfComponents","ArrayType","size","byteLength","buffer","offset","byteOffset","bufferArray","slice","getPrimitiveTextureData","textureInfo","primitive","_json$textures","_json$textures$textur","json","gltf","texCoordAccessorKey","concat","texCoord","texCoordAccessorIndex","attributes","textureCoordinates","textureIndex","index","imageIndex","textures","source","_json$images","_json$images$imageInd","_scenegraph$gltf$imag","mimeType","images","parsedImage","width","textureData","value","getImageValueByCoordinates","channels","push","primitivePropertyDataToAttributes","attributeName","propertyData","featureTable","featureIndices","texelData","findIndex","item","typedArray","bufferIndex","buffers","arrayBuffer","addBufferView","accessorIndex","addAccessor","count","CHANNELS_MAP","r","shift","g","b","a","u","v","components","indexOf","coordinatesToOffset","c","map","Object","values","imageOffset","imageData","Error","imageValue","componentsCount","w","iX","indX","Math","round","h","height","iY","indY","parseVariableLengthArrayNumeric","valuesData","valuesDataBytesLength","valueSize","attributeValueArray","arrayOffset","arrayByteSize","typedArrayOffset","parseFixedLengthArrayNumeric","arrayCount","elementOffset","getPropertyDataString","valuesDataBytes","stringOffsets","stringsArray","textDecoder","TextDecoder","stringOffset","stringByteSize","stringData","subarray","stringAttribute","decode"],"sources":["../../../../../src/lib/extensions/utils/3d-tiles-utils.ts"],"sourcesContent":["/**\n * loaders.gl, MIT license\n *\n * Shared code for 3DTiles extensions:\n * * EXT_feature_metadata\n * * EXT_mesh_features\n * * EXT_structural_metadata\n */\n\nimport type {GLTFTextureInfoMetadata, GLTFMeshPrimitive} from '../../types/gltf-json-schema';\nimport type {BigTypedArray, TypedArray} from '@loaders.gl/schema';\nimport type {ImageType} from '@loaders.gl/images';\n\nimport {GLTFScenegraph} from '../../api/gltf-scenegraph';\nimport {getComponentTypeFromArray, getFloat32ArrayForAccessor} from '../../gltf-utils/gltf-utils';\nimport {getImageData} from '@loaders.gl/images';\nimport {emod} from '@loaders.gl/math';\n\nexport type NumericComponentType =\n | 'INT8'\n | 'UINT8'\n | 'INT16'\n | 'UINT16'\n | 'INT32'\n | 'UINT32'\n | 'INT64'\n | 'UINT64'\n | 'FLOAT32'\n | 'FLOAT64';\n\nconst ATTRIBUTE_TYPE_TO_COMPONENTS = {\n SCALAR: 1,\n VEC2: 2,\n VEC3: 3,\n VEC4: 4,\n MAT2: 4,\n MAT3: 9,\n MAT4: 16,\n BOOLEAN: 1,\n STRING: 1,\n ENUM: 1\n};\n\nconst ATTRIBUTE_COMPONENT_TYPE_TO_ARRAY = {\n INT8: Int8Array,\n UINT8: Uint8Array,\n INT16: Int16Array,\n UINT16: Uint16Array,\n INT32: Int32Array,\n UINT32: Uint32Array,\n INT64: BigInt64Array,\n UINT64: BigUint64Array,\n FLOAT32: Float32Array,\n FLOAT64: Float64Array\n};\n\nconst ATTRIBUTE_COMPONENT_TYPE_TO_BYTE_SIZE = {\n INT8: 1,\n UINT8: 1,\n INT16: 2,\n UINT16: 2,\n INT32: 4,\n UINT32: 4,\n INT64: 8,\n UINT64: 8,\n FLOAT32: 4,\n FLOAT64: 8\n};\n\nexport function getArrayElementByteSize(attributeType, componentType): number {\n return (\n ATTRIBUTE_COMPONENT_TYPE_TO_BYTE_SIZE[componentType] *\n ATTRIBUTE_TYPE_TO_COMPONENTS[attributeType]\n );\n}\n\n/**\n * Gets offset array from `arrayOffsets` or `stringOffsets`.\n * @param scenegraph - Instance of the class for structured access to GLTF data.\n * @param bufferViewIndex - Buffer view index\n * @param offsetType - The type of values in `arrayOffsets` or `stringOffsets`.\n * @param numberOfElements - The number of elements in each property array.\n * @returns Array of values offsets. The number of offsets in the array is equal to `numberOfElements` plus one.\n */\nexport function getOffsetsForProperty(\n scenegraph: GLTFScenegraph,\n bufferViewIndex: number,\n offsetType: 'UINT8' | 'UINT16' | 'UINT32' | 'UINT64' | string,\n numberOfElements: number\n): TypedArray | null {\n if (\n offsetType !== 'UINT8' &&\n offsetType !== 'UINT16' &&\n offsetType !== 'UINT32' &&\n offsetType !== 'UINT64'\n ) {\n return null;\n }\n const arrayOffsetsBytes = scenegraph.getTypedArrayForBufferView(bufferViewIndex);\n const arrayOffsets = convertRawBufferToMetadataArray(\n arrayOffsetsBytes,\n 'SCALAR', // offsets consist of ONE component\n offsetType,\n numberOfElements + 1 // The number of offsets is equal to the property table `count` plus one.\n );\n\n // We don't support BigInt offsets at the moment. It requires additional logic and potential issues in Safari\n if (arrayOffsets instanceof BigInt64Array || arrayOffsets instanceof BigUint64Array) {\n return null;\n }\n return arrayOffsets;\n}\n\n/**\n * Converts raw bytes that are in the buffer to an array of the type defined by the schema.\n * @param data - Raw bytes in the buffer.\n * @param attributeType - SCALAR, VECN, MATN.\n * @param componentType - Type of the component in elements, e.g. 'UINT8' or 'FLOAT32'.\n * @param elementCount - Number of elements in the array. Default value is 1.\n * @returns Data array\n */\nexport function convertRawBufferToMetadataArray(\n data: Uint8Array,\n attributeType: string,\n componentType: NumericComponentType,\n elementCount: number = 1\n): BigTypedArray {\n const numberOfComponents = ATTRIBUTE_TYPE_TO_COMPONENTS[attributeType];\n const ArrayType = ATTRIBUTE_COMPONENT_TYPE_TO_ARRAY[componentType];\n const size = ATTRIBUTE_COMPONENT_TYPE_TO_BYTE_SIZE[componentType];\n const length = elementCount * numberOfComponents;\n const byteLength = length * size;\n let buffer = data.buffer;\n let offset = data.byteOffset;\n if (offset % size !== 0) {\n const bufferArray = new Uint8Array(buffer);\n buffer = bufferArray.slice(offset, offset + byteLength).buffer;\n offset = 0;\n }\n return new ArrayType(buffer, offset, length);\n}\n\n/**\n * Processes data encoded in the texture associated with the primitive.\n * @param scenegraph - Instance of the class for structured access to GLTF data.\n * @param textureInfo - Reference to the texture where extension data are stored.\n * @param primitive - Primitive object in the mesh.\n * @returns Array of data taken. Null if data can't be taken from the texture.\n */\nexport function getPrimitiveTextureData(\n scenegraph: GLTFScenegraph,\n textureInfo: GLTFTextureInfoMetadata,\n primitive: GLTFMeshPrimitive\n): number[] | null {\n /*\n texture.index is an index for the \"textures\" array.\n The texture object referenced by this index looks like this:\n {\n \"sampler\": 0,\n \"source\": 0\n }\n \"sampler\" is an index for the \"samplers\" array\n \"source\" is an index for the \"images\" array that contains data. These data are stored in rgba channels of the image.\n\n texture.texCoord is a number-suffix (like 1) for an attribute like \"TEXCOORD_1\" in meshes.primitives\n The value of \"TEXCOORD_1\" is an accessor that is used to get coordinates. These coordinates are being used to get data from the image.\n */\n const json = scenegraph.gltf.json;\n\n const texCoordAccessorKey = `TEXCOORD_${textureInfo.texCoord || 0}`;\n const texCoordAccessorIndex = primitive.attributes[texCoordAccessorKey];\n\n const textureCoordinates: Float32Array | null = getFloat32ArrayForAccessor(\n scenegraph.gltf,\n texCoordAccessorIndex\n );\n if (!textureCoordinates) {\n return null;\n }\n\n const textureIndex: number = textureInfo.index;\n const imageIndex = json.textures?.[textureIndex]?.source;\n if (typeof imageIndex !== 'undefined') {\n const mimeType = json.images?.[imageIndex]?.mimeType;\n const parsedImage = scenegraph.gltf.images?.[imageIndex];\n // Checking for width is to prevent handling Un-processed images (e.g. [analyze] stage, where loadImages option is set to false)\n if (parsedImage && typeof parsedImage.width !== 'undefined') {\n const textureData: number[] = [];\n for (let index = 0; index < textureCoordinates.length; index += 2) {\n const value = getImageValueByCoordinates(\n parsedImage,\n mimeType,\n textureCoordinates,\n index,\n textureInfo.channels\n );\n textureData.push(value);\n }\n return textureData;\n }\n }\n return null;\n}\n\n/**\n * Puts property data to attributes.\n * It creates corresponding buffer, bufferView and accessor\n * so the data can be accessed like regular data stored in buffers.\n * @param scenegraph - Scenegraph object.\n * @param attributeName - Name of the attribute.\n * @param propertyData - Property data to store.\n * @param featureTable - Array where unique data from the property data are being stored.\n * @param primitive - Primitive object.\n */\nexport function primitivePropertyDataToAttributes(\n scenegraph: GLTFScenegraph,\n attributeName: string,\n propertyData: number[],\n featureTable: number[],\n primitive: GLTFMeshPrimitive\n): void {\n // No reason to create an empty buffer if there is no property data to store.\n if (!propertyData?.length) {\n return;\n }\n /*\n featureTable will contain unique values, e.g.\n propertyData = [24, 35, 28, 24]\n featureTable = [24, 35, 28]\n featureIndices will contain indices that refer featureTextureTable, e.g.\n featureIndices = [0, 1, 2, 0]\n */\n const featureIndices: number[] = [];\n for (const texelData of propertyData) {\n let index = featureTable.findIndex((item) => item === texelData);\n if (index === -1) {\n index = featureTable.push(texelData) - 1;\n }\n featureIndices.push(index);\n }\n const typedArray = new Uint32Array(featureIndices);\n const bufferIndex =\n scenegraph.gltf.buffers.push({\n arrayBuffer: typedArray.buffer,\n byteOffset: typedArray.byteOffset,\n byteLength: typedArray.byteLength\n }) - 1;\n const bufferViewIndex = scenegraph.addBufferView(typedArray, bufferIndex, 0);\n const accessorIndex = scenegraph.addAccessor(bufferViewIndex, {\n size: 1,\n componentType: getComponentTypeFromArray(typedArray),\n count: typedArray.length\n });\n primitive.attributes[attributeName] = accessorIndex;\n}\n\n/**\n * Gets the value from the texture by coordinates provided.\n * @param parsedImage - Image where the data are stored.\n * @param mimeType - MIME type.\n * @param textureCoordinates - uv coordinates to access data in the image.\n * @param index - Index of uv coordinates in the array textureCoordinates.\n * @param channels - Image channels where data are stored. Channels of an RGBA texture are numbered 0..3 respectively.\n * @returns Value taken from the image.\n */\nfunction getImageValueByCoordinates(\n parsedImage: ImageType,\n mimeType: string | undefined,\n textureCoordinates: Float32Array,\n index: number,\n channels: number[] | string = [0]\n) {\n const CHANNELS_MAP = {\n r: {offset: 0, shift: 0},\n g: {offset: 1, shift: 8},\n b: {offset: 2, shift: 16},\n a: {offset: 3, shift: 24}\n };\n\n const u = textureCoordinates[index];\n const v = textureCoordinates[index + 1];\n\n let components = 1;\n if (mimeType && (mimeType.indexOf('image/jpeg') !== -1 || mimeType.indexOf('image/png') !== -1))\n components = 4;\n const offset = coordinatesToOffset(u, v, parsedImage, components);\n let value: number = 0;\n for (const c of channels) {\n /*\n According to the EXT_feature_metadata extension specification:\n Channels are labeled by rgba and are swizzled with a string of 1-4 characters.\n According to the EXT_mesh_features extension specification:\n The channels array contains non-negative integer values corresponding to channels of the source texture that the feature ID consists of.\n Channels of an RGBA texture are numbered 0–3 respectively.\n Function getImageValueByCoordinates is used to process both extensions. \n So, there should be possible to get the element of CHANNELS_MAP by either index (0, 1, 2, 3) or key (r, g, b, a).\n */\n const map = typeof c === 'number' ? Object.values(CHANNELS_MAP)[c] : CHANNELS_MAP[c];\n const imageOffset = offset + map.offset;\n const imageData = getImageData(parsedImage);\n if (imageData.data.length <= imageOffset) {\n throw new Error(`${imageData.data.length} <= ${imageOffset}`);\n }\n const imageValue = imageData.data[imageOffset];\n value |= imageValue << map.shift;\n }\n return value;\n}\n\n/**\n * Retrieves the offset in the image where the data are stored.\n * @param u - u-coordinate.\n * @param v - v-coordinate.\n * @param parsedImage - Image where the data are stored.\n * @param componentsCount - Number of components the data consists of.\n * @returns Offset in the image where the data are stored.\n */\nfunction coordinatesToOffset(\n u: number,\n v: number,\n parsedImage: any,\n componentsCount: number = 1\n): number {\n const w = parsedImage.width;\n const iX = emod(u) * (w - 1);\n const indX = Math.round(iX);\n\n const h = parsedImage.height;\n const iY = emod(v) * (h - 1);\n const indY = Math.round(iY);\n const components = parsedImage.components ? parsedImage.components : componentsCount;\n // components is a number of channels in the image\n const offset = (indY * w + indX) * components;\n return offset;\n}\n\n/**\n * Parses variable-length array data.\n * In this case every value of the property in the table will be an array\n * of arbitrary length.\n * @param valuesData - Values in a flat typed array.\n * @param numberOfElements - Number of rows in the property table.\n * @param arrayOffsets - Offsets of nested arrays in the flat values array.\n * @param valuesDataBytesLength - Data byte length.\n * @param valueSize - Value size in bytes.\n * @returns Array of typed arrays.\n */\nexport function parseVariableLengthArrayNumeric(\n valuesData: BigTypedArray,\n numberOfElements: number,\n arrayOffsets: TypedArray,\n valuesDataBytesLength: number,\n valueSize: number\n): BigTypedArray[] {\n const attributeValueArray: BigTypedArray[] = [];\n for (let index = 0; index < numberOfElements; index++) {\n const arrayOffset = arrayOffsets[index];\n const arrayByteSize = arrayOffsets[index + 1] - arrayOffsets[index];\n if (arrayByteSize + arrayOffset > valuesDataBytesLength) {\n break;\n }\n const typedArrayOffset = arrayOffset / valueSize;\n const elementCount = arrayByteSize / valueSize;\n attributeValueArray.push(valuesData.slice(typedArrayOffset, typedArrayOffset + elementCount));\n }\n return attributeValueArray;\n}\n\n/**\n * Parses fixed-length array data.\n * In this case every value of the property in the table will be an array\n * of constant length equal to `arrayCount`.\n * @param valuesData - Values in a flat typed array.\n * @param numberOfElements - Number of rows in the property table.\n * @param arrayCount - Nested arrays length.\n * @returns Array of typed arrays.\n */\nexport function parseFixedLengthArrayNumeric(\n valuesData: BigTypedArray,\n numberOfElements: number,\n arrayCount: number\n): BigTypedArray[] {\n const attributeValueArray: BigTypedArray[] = [];\n for (let index = 0; index < numberOfElements; index++) {\n const elementOffset = index * arrayCount;\n attributeValueArray.push(valuesData.slice(elementOffset, elementOffset + arrayCount));\n }\n return attributeValueArray;\n}\n\n/**\n * Decodes properties of string type from binary source.\n * @param numberOfElements - The number of elements in each property array that propertyTableProperty contains. It's a number of rows in the table.\n * @param valuesDataBytes - Data taken from values property of the property table property.\n * @param arrayOffsets - Offsets for variable-length arrays. It's null for fixed-length arrays or scalar types.\n * @param stringOffsets - Index of the buffer view containing offsets for strings. It should be available for string type.\n * @returns String property values\n */\nexport function getPropertyDataString(\n numberOfElements: number,\n valuesDataBytes: Uint8Array,\n arrayOffsets: TypedArray | null,\n stringOffsets: TypedArray | null\n): string[] | string[][] {\n if (arrayOffsets) {\n // TODO: implement it as soon as we have the corresponding tileset\n throw new Error('Not implemented - arrayOffsets for strings is specified');\n }\n\n if (stringOffsets) {\n const stringsArray: string[] = [];\n const textDecoder = new TextDecoder('utf8');\n\n let stringOffset = 0;\n for (let index = 0; index < numberOfElements; index++) {\n const stringByteSize = stringOffsets[index + 1] - stringOffsets[index];\n\n if (stringByteSize + stringOffset <= valuesDataBytes.length) {\n const stringData = valuesDataBytes.subarray(stringOffset, stringByteSize + stringOffset);\n const stringAttribute = textDecoder.decode(stringData);\n\n stringsArray.push(stringAttribute);\n stringOffset += stringByteSize;\n }\n }\n\n return stringsArray;\n }\n return [];\n}\n"],"mappings":"AAcA,SAAQA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AEA,aAAa,GAAGD,UAAU,CAAC,CAAC;EACvF;EACA,OAAOL,mBAAmB;AAC5B;AAUA,OAAO,SAASO,qBAAqBA,CACnCzG,gBAAwB,EACxB0G,eAA2B,EAC3BvG,YAA+B,EAC/BwG,aAAgC,EACT;EACvB,IAAIxG,YAAY,EAAE;IAEhB,MAAM,IAAI+E,KAAK,CAAC,yDAAyD,CAAC;EAC5E;EAEA,IAAIyB,aAAa,EAAE;IACjB,MAAMC,YAAsB,GAAG,EAAE;IACjC,MAAMC,WAAW,GAAG,IAAIC,WAAW,CAAC,MAAM,CAAC;IAE3C,IAAIC,YAAY,GAAG,CAAC;IACpB,KAAK,IAAI9E,KAAK,GAAG,CAAC,EAAEA,KAAK,GAAGjC,gBAAgB,EAAEiC,KAAK,EAAE,EAAE;MACrD,MAAM+E,cAAc,GAAGL,aAAa,CAAC1E,KAAK,GAAG,CAAC,CAAC,GAAG0E,aAAa,CAAC1E,KAAK,CAAC;MAEtE,IAAI+E,cAAc,GAAGD,YAAY,IAAIL,eAAe,CAAClG,MAAM,EAAE;QAC3D,MAAMyG,UAAU,GAAGP,eAAe,CAACQ,QAAQ,CAACH,YAAY,EAAEC,cAAc,GAAGD,YAAY,CAAC;QACxF,MAAMI,eAAe,GAAGN,WAAW,CAACO,MAAM,CAACH,UAAU,CAAC;QAEtDL,YAAY,CAAC5D,IAAI,CAACmE,eAAe,CAAC;QAClCJ,YAAY,IAAIC,cAAc;MAChC;IACF;IAEA,OAAOJ,YAAY;EACrB;EACA,OAAO,EAAE;AACX"}
@@ -1,4 +1,5 @@
1
1
  import { assert } from '../utils/assert';
2
+ import { BYTES, COMPONENTS } from '../gltf-utils/gltf-constants';
2
3
  const MIPMAP_FACTOR = 1.33;
3
4
  const TYPES = ['SCALAR', 'VEC2', 'VEC3', 'VEC4'];
4
5
  const ARRAY_CONSTRUCTOR_TO_WEBGL_CONSTANT = [[Int8Array, 5120], [Uint8Array, 5121], [Int16Array, 5122], [Uint16Array, 5123], [Uint32Array, 5125], [Float32Array, 5126], [Float64Array, 5130]];
@@ -52,6 +53,35 @@ export function getAccessorArrayTypeAndLength(accessor, bufferView) {
52
53
  byteLength
53
54
  };
54
55
  }
56
+ export function getFloat32ArrayForAccessor(gltfData, texCoordAccessor) {
57
+ var _gltfData$json$access;
58
+ const accessor = (_gltfData$json$access = gltfData.json.accessors) === null || _gltfData$json$access === void 0 ? void 0 : _gltfData$json$access[texCoordAccessor];
59
+ if (accessor && typeof accessor.bufferView !== 'undefined') {
60
+ var _gltfData$json$buffer;
61
+ const bufferView = (_gltfData$json$buffer = gltfData.json.bufferViews) === null || _gltfData$json$buffer === void 0 ? void 0 : _gltfData$json$buffer[accessor.bufferView];
62
+ if (bufferView) {
63
+ const {
64
+ arrayBuffer,
65
+ byteOffset: bufferByteOffset
66
+ } = gltfData.buffers[bufferView.buffer];
67
+ const byteOffset = (bufferByteOffset || 0) + (accessor.byteOffset || 0) + (bufferView.byteOffset || 0);
68
+ const {
69
+ ArrayType,
70
+ length
71
+ } = getAccessorArrayTypeAndLength(accessor, bufferView);
72
+ const bytes = BYTES[accessor.componentType];
73
+ const components = COMPONENTS[accessor.type];
74
+ const elementAddressScale = bufferView.byteStride || bytes * components;
75
+ const result = new Float32Array(length);
76
+ for (let i = 0; i < accessor.count; i++) {
77
+ const uv = new ArrayType(arrayBuffer, byteOffset + i * elementAddressScale, 2);
78
+ result.set(uv, i * components);
79
+ }
80
+ return result;
81
+ }
82
+ }
83
+ return null;
84
+ }
55
85
  export function getMemoryUsageGLTF(gltf) {
56
86
  let {
57
87
  images,
@@ -1 +1 @@
1
- {"version":3,"file":"gltf-utils.js","names":["assert","MIPMAP_FACTOR","TYPES","ARRAY_CONSTRUCTOR_TO_WEBGL_CONSTANT","Int8Array","Uint8Array","Int16Array","Uint16Array","Uint32Array","Float32Array","Float64Array","ARRAY_TO_COMPONENT_TYPE","Map","ATTRIBUTE_TYPE_TO_COMPONENTS","SCALAR","VEC2","VEC3","VEC4","MAT2","MAT3","MAT4","ATTRIBUTE_COMPONENT_TYPE_TO_BYTE_SIZE","ATTRIBUTE_COMPONENT_TYPE_TO_ARRAY","getAccessorTypeFromSize","size","type","getComponentTypeFromArray","typedArray","componentType","get","constructor","Error","getAccessorArrayTypeAndLength","accessor","bufferView","ArrayType","components","bytesPerComponent","length","count","byteLength","getMemoryUsageGLTF","gltf","images","bufferViews","imageBufferViews","map","i","filter","view","includes","bufferMemory","reduce","acc","pixelCount","image","width","height","Math","ceil"],"sources":["../../../../src/lib/gltf-utils/gltf-utils.ts"],"sourcesContent":["import {assert} from '../utils/assert';\nimport type {GLTFPostprocessed} from '../types/gltf-postprocessed-schema';\n\n/**\n * Memory needed to store texture and all mipmap levels 1 + 1/4 + 1/16 + 1/64 + ...\n * Minimum 1.33, but due to GPU layout may be 1.5\n */\nconst MIPMAP_FACTOR = 1.33;\n\nconst TYPES = ['SCALAR', 'VEC2', 'VEC3', 'VEC4'];\n\ntype TypedArrayConstructor =\n | Int8ArrayConstructor\n | Uint8ArrayConstructor\n | Int16ArrayConstructor\n | Uint16ArrayConstructor\n | Int32ArrayConstructor\n | Uint32ArrayConstructor\n | Int32ArrayConstructor\n | Uint32ArrayConstructor\n | Float32ArrayConstructor\n | Float64ArrayConstructor;\n\nconst ARRAY_CONSTRUCTOR_TO_WEBGL_CONSTANT: [TypedArrayConstructor, number][] = [\n [Int8Array, 5120],\n [Uint8Array, 5121],\n [Int16Array, 5122],\n [Uint16Array, 5123],\n [Uint32Array, 5125],\n [Float32Array, 5126],\n [Float64Array, 5130]\n];\nconst ARRAY_TO_COMPONENT_TYPE = new Map<TypedArrayConstructor, number>(\n ARRAY_CONSTRUCTOR_TO_WEBGL_CONSTANT\n);\n\nconst ATTRIBUTE_TYPE_TO_COMPONENTS = {\n SCALAR: 1,\n VEC2: 2,\n VEC3: 3,\n VEC4: 4,\n MAT2: 4,\n MAT3: 9,\n MAT4: 16\n};\n\nconst ATTRIBUTE_COMPONENT_TYPE_TO_BYTE_SIZE = {\n 5120: 1,\n 5121: 1,\n 5122: 2,\n 5123: 2,\n 5125: 4,\n 5126: 4\n};\n\nconst ATTRIBUTE_COMPONENT_TYPE_TO_ARRAY = {\n 5120: Int8Array,\n 5121: Uint8Array,\n 5122: Int16Array,\n 5123: Uint16Array,\n 5125: Uint32Array,\n 5126: Float32Array\n};\n\nexport function getAccessorTypeFromSize(size) {\n const type = TYPES[size - 1];\n return type || TYPES[0];\n}\n\nexport function getComponentTypeFromArray(typedArray) {\n const componentType = ARRAY_TO_COMPONENT_TYPE.get(typedArray.constructor);\n if (!componentType) {\n throw new Error('Illegal typed array');\n }\n return componentType;\n}\n\nexport function getAccessorArrayTypeAndLength(accessor, bufferView) {\n const ArrayType = ATTRIBUTE_COMPONENT_TYPE_TO_ARRAY[accessor.componentType];\n const components = ATTRIBUTE_TYPE_TO_COMPONENTS[accessor.type];\n const bytesPerComponent = ATTRIBUTE_COMPONENT_TYPE_TO_BYTE_SIZE[accessor.componentType];\n const length = accessor.count * components;\n const byteLength = accessor.count * components * bytesPerComponent;\n assert(byteLength >= 0 && byteLength <= bufferView.byteLength);\n return {ArrayType, length, byteLength};\n}\n\n/**\n * Calculate the GPU memory used by a GLTF tile, for both buffer and texture memory\n * @param gltf - the gltf content of a GLTF tile\n * @returns - total memory usage in bytes\n */\nexport function getMemoryUsageGLTF(gltf: GLTFPostprocessed): number {\n let {images, bufferViews} = gltf;\n images = images || [];\n bufferViews = bufferViews || [];\n const imageBufferViews = images.map((i) => i.bufferView);\n bufferViews = bufferViews.filter((view) => !imageBufferViews.includes(view as any));\n\n const bufferMemory = bufferViews.reduce((acc, view) => acc + view.byteLength, 0);\n\n // Assume each pixel of the texture is 4 channel with mimmaps (which add 33%)\n // TODO correctly handle compressed textures\n const pixelCount = images.reduce((acc, image) => {\n // @ts-ignore\n const {width, height} = (image as any).image;\n return acc + width * height;\n }, 0);\n return bufferMemory + Math.ceil(4 * pixelCount * MIPMAP_FACTOR);\n}\n"],"mappings":"AAAA,SAA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,GAAGJ,IAAI,CAACT,UAAU,EAAE,CAAC,CAAC;EAIhF,MAAMc,UAAU,GAAGX,MAAM,CAACS,MAAM,CAAC,CAACC,GAAG,EAAEE,KAAK,KAAK;IAE/C,MAAM;MAACC,KAAK;MAAEC;IAAM,CAAC,GAAIF,KAAK,CAASA,KAAK;IAC5C,OAAOF,GAAG,GAAGG,KAAK,GAAGC,MAAM;EAC7B,CAAC,EAAE,CAAC,CAAC;EACL,OAAON,YAAY,GAAGO,IAAI,CAACC,IAAI,CAAC,CAAC,GAAGL,UAAU,GAAGrD,aAAa,CAAC;AACjE"}
1
+ {"version":3,"file":"gltf-utils.js","names":["assert","BYTES","COMPONENTS","MIPMAP_FACTOR","TYPES","ARRAY_CONSTRUCTOR_TO_WEBGL_CONSTANT","Int8Array","Uint8Array","Int16Array","Uint16Array","Uint32Array","Float32Array","Float64Array","ARRAY_TO_COMPONENT_TYPE","Map","ATTRIBUTE_TYPE_TO_COMPONENTS","SCALAR","VEC2","VEC3","VEC4","MAT2","MAT3","MAT4","ATTRIBUTE_COMPONENT_TYPE_TO_BYTE_SIZE","ATTRIBUTE_COMPONENT_TYPE_TO_ARRAY","getAccessorTypeFromSize","size","type","getComponentTypeFromArray","typedArray","componentType","get","constructor","Error","getAccessorArrayTypeAndLength","accessor","bufferView","ArrayType","components","bytesPerComponent","length","count","byteLength","getFloat32ArrayForAccessor","gltfData","texCoordAccessor","_gltfData$json$access","json","accessors","_gltfData$json$buffer","bufferViews","arrayBuffer","byteOffset","bufferByteOffset","buffers","buffer","bytes","elementAddressScale","byteStride","result","i","uv","set","getMemoryUsageGLTF","gltf","images","imageBufferViews","map","filter","view","includes","bufferMemory","reduce","acc","pixelCount","image","width","height","Math","ceil"],"sources":["../../../../src/lib/gltf-utils/gltf-utils.ts"],"sourcesContent":["import {assert} from '../utils/assert';\n\nimport type {GLTFWithBuffers} from '../types/gltf-types';\nimport type {GLTFPostprocessed} from '../types/gltf-postprocessed-schema';\nimport {BYTES, COMPONENTS} from '../gltf-utils/gltf-constants';\n\n/**\n * Memory needed to store texture and all mipmap levels 1 + 1/4 + 1/16 + 1/64 + ...\n * Minimum 1.33, but due to GPU layout may be 1.5\n */\nconst MIPMAP_FACTOR = 1.33;\n\nconst TYPES = ['SCALAR', 'VEC2', 'VEC3', 'VEC4'];\n\ntype TypedArrayConstructor =\n | Int8ArrayConstructor\n | Uint8ArrayConstructor\n | Int16ArrayConstructor\n | Uint16ArrayConstructor\n | Int32ArrayConstructor\n | Uint32ArrayConstructor\n | Int32ArrayConstructor\n | Uint32ArrayConstructor\n | Float32ArrayConstructor\n | Float64ArrayConstructor;\n\nconst ARRAY_CONSTRUCTOR_TO_WEBGL_CONSTANT: [TypedArrayConstructor, number][] = [\n [Int8Array, 5120],\n [Uint8Array, 5121],\n [Int16Array, 5122],\n [Uint16Array, 5123],\n [Uint32Array, 5125],\n [Float32Array, 5126],\n [Float64Array, 5130]\n];\nconst ARRAY_TO_COMPONENT_TYPE = new Map<TypedArrayConstructor, number>(\n ARRAY_CONSTRUCTOR_TO_WEBGL_CONSTANT\n);\n\nconst ATTRIBUTE_TYPE_TO_COMPONENTS = {\n SCALAR: 1,\n VEC2: 2,\n VEC3: 3,\n VEC4: 4,\n MAT2: 4,\n MAT3: 9,\n MAT4: 16\n};\n\nconst ATTRIBUTE_COMPONENT_TYPE_TO_BYTE_SIZE = {\n 5120: 1,\n 5121: 1,\n 5122: 2,\n 5123: 2,\n 5125: 4,\n 5126: 4\n};\n\nconst ATTRIBUTE_COMPONENT_TYPE_TO_ARRAY = {\n 5120: Int8Array,\n 5121: Uint8Array,\n 5122: Int16Array,\n 5123: Uint16Array,\n 5125: Uint32Array,\n 5126: Float32Array\n};\n\nexport function getAccessorTypeFromSize(size) {\n const type = TYPES[size - 1];\n return type || TYPES[0];\n}\n\nexport function getComponentTypeFromArray(typedArray) {\n const componentType = ARRAY_TO_COMPONENT_TYPE.get(typedArray.constructor);\n if (!componentType) {\n throw new Error('Illegal typed array');\n }\n return componentType;\n}\n\nexport function getAccessorArrayTypeAndLength(accessor, bufferView) {\n const ArrayType = ATTRIBUTE_COMPONENT_TYPE_TO_ARRAY[accessor.componentType];\n const components = ATTRIBUTE_TYPE_TO_COMPONENTS[accessor.type];\n const bytesPerComponent = ATTRIBUTE_COMPONENT_TYPE_TO_BYTE_SIZE[accessor.componentType];\n const length = accessor.count * components;\n const byteLength = accessor.count * components * bytesPerComponent;\n assert(byteLength >= 0 && byteLength <= bufferView.byteLength);\n return {ArrayType, length, byteLength};\n}\n\nexport function getFloat32ArrayForAccessor(\n gltfData: GLTFWithBuffers,\n texCoordAccessor: number\n): Float32Array | null {\n const accessor = gltfData.json.accessors?.[texCoordAccessor];\n if (accessor && typeof accessor.bufferView !== 'undefined') {\n // Get `bufferView` of the `accessor`\n const bufferView = gltfData.json.bufferViews?.[accessor.bufferView];\n if (bufferView) {\n // Get `arrayBuffer` the `bufferView` look at\n const {arrayBuffer, byteOffset: bufferByteOffset} = gltfData.buffers[bufferView.buffer];\n // Resulting byteOffset is sum of the buffer, accessor and bufferView byte offsets\n const byteOffset =\n (bufferByteOffset || 0) + (accessor.byteOffset || 0) + (bufferView.byteOffset || 0);\n // Deduce TypedArray type and its length from `accessor` and `bufferView` data\n const {ArrayType, length} = getAccessorArrayTypeAndLength(accessor, bufferView);\n // Number of bytes each component occupies\n const bytes = BYTES[accessor.componentType];\n // Number of components. For the `TEXCOORD_0` with `VEC2` type, it must return 2\n const components = COMPONENTS[accessor.type];\n // Multiplier to calculate the address of the `TEXCOORD_0` element in the arrayBuffer\n const elementAddressScale = bufferView.byteStride || bytes * components;\n // Data transform to Float32Array\n const result = new Float32Array(length);\n for (let i = 0; i < accessor.count; i++) {\n // Take [u, v] couple from the arrayBuffer\n const uv = new ArrayType(arrayBuffer, byteOffset + i * elementAddressScale, 2);\n result.set(uv, i * components);\n }\n return result;\n }\n }\n return null;\n}\n\n/**\n * Calculate the GPU memory used by a GLTF tile, for both buffer and texture memory\n * @param gltf - the gltf content of a GLTF tile\n * @returns - total memory usage in bytes\n */\nexport function getMemoryUsageGLTF(gltf: GLTFPostprocessed): number {\n let {images, bufferViews} = gltf;\n images = images || [];\n bufferViews = bufferViews || [];\n const imageBufferViews = images.map((i) => i.bufferView);\n bufferViews = bufferViews.filter((view) => !imageBufferViews.includes(view as any));\n\n const bufferMemory = bufferViews.reduce((acc, view) => acc + view.byteLength, 0);\n\n // Assume each pixel of the texture is 4 channel with mimmaps (which add 33%)\n // TODO correctly handle compressed textures\n const pixelCount = images.reduce((acc, image) => {\n // @ts-ignore\n const {width, height} = (image as any).image;\n return acc + width * height;\n }, 0);\n return bufferMemory + Math.ceil(4 * pixelCount * MIPMAP_FACTOR);\n}\n"],"mappings":"AAAA,SAAQA,MAAM,QAAO,iBAAiB;AAItC,SAAQC,KAAK,EAAEC,UAAU,QAAO,8BAA8B;AAM9D,MAAMC,aAAa,GAAG,IAAI;AAE1B,MAAMC,KAAK,GAAG,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC;AAchD,MAAMC,mCAAsE,GAAG,CAC7E,CAACC,SAAS,EAAE,IAAI,CAAC,EACjB,CAACC,UAAU,EAAE,IAAI,CAAC,EAClB,CAACC,UAAU,EAAE,IAAI,CAAC,EAClB,CAACC,WAAW,EAAE,IAAI,CAAC,EACnB,CAACC,WAAW,EAAE,IAAI,CAAC,EACnB,CAACC,YAAY,EAAE,IAAI,CAAC,EACpB,CAACC,YAAY,EAAE,IAAI,CAAC,CACrB;AACD,MAAMC,uBAAuB,GAAG,IAAIC,GAAG,CACrCT,mCACF,CAAC;AAED,MAAMU,4BAA4B,GAAG;EACnCC,MAAM,EAAE,CAAC;EACTC,IAAI,EAAE,CAAC;EACPC,IAAI,EAAE,CAAC;EACPC,IAAI,EAAE,CAAC;EACPC,IAAI,EAAE,CAAC;EACPC,IAAI,EAAE,CAAC;EACPC,IAAI,EAAE;AACR,CAAC;AAED,MAAMC,qCAAqC,GAAG;EAC5C,IAAI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AE,EAAE;QAEvC,MAAMC,EAAE,GAAG,IAAIxB,SAAS,CAACc,WAAW,EAAEC,UAAU,GAAGQ,CAAC,GAAGH,mBAAmB,EAAE,CAAC,CAAC;QAC9EE,MAAM,CAACG,GAAG,CAACD,EAAE,EAAED,CAAC,GAAGtB,UAAU,CAAC;MAChC;MACA,OAAOqB,MAAM;IACf;EACF;EACA,OAAO,IAAI;AACb;AAOA,OAAO,SAASI,kBAAkBA,CAACC,IAAuB,EAAU;EAClE,IAAI;IAACC,MAAM;IAAEf;EAAW,CAAC,GAAGc,IAAI;EAChCC,MAAM,GAAGA,MAAM,IAAI,EAAE;EACrBf,WAAW,GAAGA,WAAW,IAAI,EAAE;EAC/B,MAAMgB,gBAAgB,GAAGD,MAAM,CAACE,GAAG,CAAEP,CAAC,IAAKA,CAAC,CAACxB,UAAU,CAAC;EACxDc,WAAW,GAAGA,WAAW,CAACkB,MAAM,CAAEC,IAAI,IAAK,CAACH,gBAAgB,CAACI,QAAQ,CAACD,IAAW,CAAC,CAAC;EAEnF,MAAME,YAAY,GAAGrB,WAAW,CAACsB,MAAM,CAAC,CAACC,GAAG,EAAEJ,IAAI,KAAKI,GAAG,GAAGJ,IAAI,CAAC3B,UAAU,EAAE,CAAC,CAAC;EAIhF,MAAMgC,UAAU,GAAGT,MAAM,CAACO,MAAM,CAAC,CAACC,GAAG,EAAEE,KAAK,KAAK;IAE/C,MAAM;MAACC,KAAK;MAAEC;IAAM,CAAC,GAAIF,KAAK,CAASA,KAAK;IAC5C,OAAOF,GAAG,GAAGG,KAAK,GAAGC,MAAM;EAC7B,CAAC,EAAE,CAAC,CAAC;EACL,OAAON,YAAY,GAAGO,IAAI,CAACC,IAAI,CAAC,CAAC,GAAGL,UAAU,GAAGvE,aAAa,CAAC;AACjE"}
@@ -1,4 +1,4 @@
1
- import { parseJSON, sliceArrayBuffer } from '@loaders.gl/loader-utils';
1
+ import { parseJSON, sliceArrayBuffer, parseFromContext } from '@loaders.gl/loader-utils';
2
2
  import { ImageLoader } from '@loaders.gl/images';
3
3
  import { BasisLoader, selectSupportedBasisFormat } from '@loaders.gl/textures';
4
4
  import { assert } from '../utils/assert';
@@ -112,13 +112,12 @@ function getReferencesImageIndices(gltf) {
112
112
  return Array.from(imageIndices).sort();
113
113
  }
114
114
  async function loadImage(gltf, image, index, options, context) {
115
- const {
116
- fetch,
117
- parse
118
- } = context;
119
115
  let arrayBuffer;
120
116
  if (image.uri && !image.hasOwnProperty('bufferView')) {
121
117
  const uri = resolveUrl(image.uri, options);
118
+ const {
119
+ fetch
120
+ } = context;
122
121
  const response = await fetch(uri);
123
122
  arrayBuffer = await response.arrayBuffer();
124
123
  image.bufferView = {
@@ -130,7 +129,8 @@ async function loadImage(gltf, image, index, options, context) {
130
129
  arrayBuffer = sliceArrayBuffer(array.buffer, array.byteOffset, array.byteLength);
131
130
  }
132
131
  assert(arrayBuffer, 'glTF image has no data');
133
- let parsedImage = await parse(arrayBuffer, [ImageLoader, BasisLoader], {
132
+ let parsedImage = await parseFromContext(arrayBuffer, [ImageLoader, BasisLoader], {
133
+ ...options,
134
134
  mimeType: image.mimeType,
135
135
  basis: options.basis || {
136
136
  format: selectSupportedBasisFormat()
@@ -1 +1 @@
1
- {"version":3,"file":"parse-gltf.js","names":["parseJSON","sliceArrayBuffer","ImageLoader","BasisLoader","selectSupportedBasisFormat","assert","isGLB","parseGLBSync","resolveUrl","getTypedArrayForBufferView","preprocessExtensions","decodeExtensions","normalizeGLTFV1","isGLTF","arrayBuffer","options","byteOffset","parseGLTF","gltf","arrayBufferOrString","_options$gltf","_options$gltf2","_options$gltf3","arguments","length","undefined","context","parseGLTFContainerSync","normalize","loadBuffers","json","buffers","loadImages","data","uri","baseUri","ArrayBuffer","textDecoder","TextDecoder","decode","glb","type","concat","_glb","Array","fill","header","hasBinChunk","binChunks","byteLength","images","i","buffer","_context$fetch","_response$arrayBuffer","fetch","response","call","imageIndices","getReferencesImageIndices","promises","imageIndex","push","loadImage","Promise","all","Set","textures","texture","source","add","from","sort","image","index","parse","hasOwnProperty","bufferView","Number","isFinite","array","parsedImage","mimeType","basis","format","compressed","mipmaps","width","height"],"sources":["../../../../src/lib/parsers/parse-gltf.ts"],"sourcesContent":["/* eslint-disable camelcase, max-statements, no-restricted-globals */\nimport type {LoaderContext} from '@loaders.gl/loader-utils';\nimport type {GLTFLoaderOptions} from '../../gltf-loader';\nimport type {GLTFWithBuffers} from '../types/gltf-types';\nimport type {GLB} from '../types/glb-types';\nimport type {ParseGLBOptions} from './parse-glb';\n\nimport {parseJSON, sliceArrayBuffer} from '@loaders.gl/loader-utils';\nimport {ImageLoader} from '@loaders.gl/images';\nimport {BasisLoader, selectSupportedBasisFormat} from '@loaders.gl/textures';\n\nimport {assert} from '../utils/assert';\nimport {isGLB, parseGLBSync} from './parse-glb';\nimport {resolveUrl} from '../gltf-utils/resolve-url';\nimport {getTypedArrayForBufferView} from '../gltf-utils/get-typed-array';\nimport {preprocessExtensions, decodeExtensions} from '../api/gltf-extensions';\nimport {normalizeGLTFV1} from '../api/normalize-gltf-v1';\n\n/** */\nexport type ParseGLTFOptions = ParseGLBOptions & {\n normalize?: boolean;\n loadImages?: boolean;\n loadBuffers?: boolean;\n decompressMeshes?: boolean;\n excludeExtensions?: string[];\n\n /** @deprecated not supported in v4. `postProcessGLTF()` must be called by the application */\n postProcess?: false;\n};\n\n/** Check if an array buffer appears to contain GLTF data */\nexport function isGLTF(arrayBuffer: ArrayBuffer, options?: ParseGLTFOptions): boolean {\n const byteOffset = 0;\n return isGLB(arrayBuffer, byteOffset, options);\n}\n\nexport async function parseGLTF(\n gltf: GLTFWithBuffers,\n arrayBufferOrString,\n byteOffset = 0,\n options: GLTFLoaderOptions,\n context: LoaderContext\n): Promise<GLTFWithBuffers> {\n parseGLTFContainerSync(gltf, arrayBufferOrString, byteOffset, options);\n\n normalizeGLTFV1(gltf, {normalize: options?.gltf?.normalize});\n\n preprocessExtensions(gltf, options, context);\n\n // Load linked buffers asynchronously and decodes base64 buffers in parallel\n if (options?.gltf?.loadBuffers && gltf.json.buffers) {\n await loadBuffers(gltf, options, context);\n }\n\n // loadImages and decodeExtensions should not be running in parallel, because\n // decodeExtensions uses data from images taken during the loadImages call.\n if (options?.gltf?.loadImages) {\n await loadImages(gltf, options, context);\n }\n\n await decodeExtensions(gltf, options, context);\n\n return gltf;\n}\n\n/**\n *\n * @param gltf\n * @param data - can be ArrayBuffer (GLB), ArrayBuffer (Binary JSON), String (JSON), or Object (parsed JSON)\n * @param byteOffset\n * @param options\n */\nfunction parseGLTFContainerSync(gltf, data, byteOffset, options) {\n // Initialize gltf container\n if (options.uri) {\n gltf.baseUri = options.uri;\n }\n\n // If data is binary and starting with magic bytes, assume binary JSON text, convert to string\n if (data instanceof ArrayBuffer && !isGLB(data, byteOffset, options)) {\n const textDecoder = new TextDecoder();\n data = textDecoder.decode(data);\n }\n\n if (typeof data === 'string') {\n // If string, try to parse as JSON\n gltf.json = parseJSON(data);\n } else if (data instanceof ArrayBuffer) {\n // If still ArrayBuffer, parse as GLB container\n const glb: GLB = {} as GLB;\n byteOffset = parseGLBSync(glb, data, byteOffset, options.glb);\n\n assert(glb.type === 'glTF', `Invalid GLB magic string ${glb.type}`);\n\n gltf._glb = glb;\n gltf.json = glb.json;\n } else {\n assert(false, 'GLTF: must be ArrayBuffer or string');\n }\n\n // Populate buffers\n // Create an external buffers array to hold binary data\n const buffers = gltf.json.buffers || [];\n gltf.buffers = new Array(buffers.length).fill(null);\n\n // Populates JSON and some bin chunk info\n if (gltf._glb && gltf._glb.header.hasBinChunk) {\n const {binChunks} = gltf._glb;\n gltf.buffers[0] = {\n arrayBuffer: binChunks[0].arrayBuffer,\n byteOffset: binChunks[0].byteOffset,\n byteLength: binChunks[0].byteLength\n };\n\n // TODO - this modifies JSON and is a post processing thing\n // gltf.json.buffers[0].data = gltf.buffers[0].arrayBuffer;\n // gltf.json.buffers[0].byteOffset = gltf.buffers[0].byteOffset;\n }\n\n // Populate images\n const images = gltf.json.images || [];\n gltf.images = new Array(images.length).fill({});\n}\n\n/** Asynchronously fetch and parse buffers, store in buffers array outside of json\n * TODO - traverse gltf and determine which buffers are actually needed\n */\nasync function loadBuffers(gltf: GLTFWithBuffers, options, context: LoaderContext) {\n // TODO\n const buffers = gltf.json.buffers || [];\n for (let i = 0; i < buffers.length; ++i) {\n const buffer = buffers[i];\n if (buffer.uri) {\n const {fetch} = context;\n assert(fetch);\n\n const uri = resolveUrl(buffer.uri, options);\n const response = await context?.fetch?.(uri);\n const arrayBuffer = await response?.arrayBuffer?.();\n\n gltf.buffers[i] = {\n arrayBuffer,\n byteOffset: 0,\n byteLength: arrayBuffer.byteLength\n };\n\n delete buffer.uri;\n } else if (gltf.buffers[i] === null) {\n gltf.buffers[i] = {\n arrayBuffer: new ArrayBuffer(buffer.byteLength),\n byteOffset: 0,\n byteLength: buffer.byteLength\n };\n }\n }\n}\n\n/**\n * Loads all images\n * TODO - traverse gltf and determine which images are actually needed\n * @param gltf\n * @param options\n * @param context\n * @returns\n */\nasync function loadImages(gltf: GLTFWithBuffers, options, context: LoaderContext) {\n const imageIndices = getReferencesImageIndices(gltf);\n\n const images = gltf.json.images || [];\n\n const promises: Promise<any>[] = [];\n for (const imageIndex of imageIndices) {\n promises.push(loadImage(gltf, images[imageIndex], imageIndex, options, context));\n }\n\n return await Promise.all(promises);\n}\n\n/** Make sure we only load images that are actually referenced by textures */\nfunction getReferencesImageIndices(gltf: GLTFWithBuffers): number[] {\n const imageIndices = new Set<number>();\n\n const textures = gltf.json.textures || [];\n for (const texture of textures) {\n if (texture.source !== undefined) {\n imageIndices.add(texture.source);\n }\n }\n\n return Array.from(imageIndices).sort();\n}\n\n/** Asynchronously fetches and parses one image, store in images array outside of json */\nasync function loadImage(\n gltf: GLTFWithBuffers,\n image,\n index: number,\n options,\n context: LoaderContext\n) {\n const {fetch, parse} = context;\n\n let arrayBuffer;\n\n if (image.uri && !image.hasOwnProperty('bufferView')) {\n const uri = resolveUrl(image.uri, options);\n const response = await fetch(uri);\n arrayBuffer = await response.arrayBuffer();\n image.bufferView = {\n data: arrayBuffer\n };\n }\n\n if (Number.isFinite(image.bufferView)) {\n const array = getTypedArrayForBufferView(gltf.json, gltf.buffers, image.bufferView);\n arrayBuffer = sliceArrayBuffer(array.buffer, array.byteOffset, array.byteLength);\n }\n\n assert(arrayBuffer, 'glTF image has no data');\n\n // Call `parse`\n let parsedImage = await parse(\n arrayBuffer,\n [ImageLoader, BasisLoader],\n {mimeType: image.mimeType, basis: options.basis || {format: selectSupportedBasisFormat()}},\n context\n );\n\n if (parsedImage && parsedImage[0]) {\n parsedImage = {\n compressed: true,\n mipmaps: false,\n width: parsedImage[0].width,\n height: parsedImage[0].height,\n data: parsedImage[0]\n };\n }\n // TODO making sure ImageLoader is overridable by using array of loaders\n // const parsedImage = await parse(arrayBuffer, [ImageLoader]);\n\n // Store the loaded image\n gltf.images = gltf.images || [];\n gltf.images[index] = parsedImage;\n}\n"],"mappings":"AAOA,SAAQA,SAAS,EAAEC,gBAAgB,QAAO,0BAA0B;AACpE,SAAQC,WAAW,QAAO,oBAAoB;AAC9C,SAAQC,WAAW,EAAEC,0BAA0B,QAAO,sBAAsB;AAE5E,SAAQC,MAAM,QAAO,iBAAiB;AACtC,SAAQC,KAAK,EAAEC,YAAY,QAAO,aAAa;AAC/C,SAAQC,UAAU,QAAO,2BAA2B;AACpD,SAAQC,0BAA0B,QAAO,+BAA+B;AACxE,SAAQC,oBAAoB,EAAEC,gBAAgB,QAAO,wBAAwB;AAC7E,SAAQC,eAAe,QAAO,0BAA0B;AAexD,OAAO,SAASC,MAAMA,CAACC,WAAwB,EAAEC,OAA0B,EAAW;EACpF,MAAMC,UAAU,GAAG,CAAC;EACpB,OAAOV,KAAK,CAACQ,WAAW,EAAEE,UAAU,EAAED,OAAO,CAAC;AAChD;AAEA,OAAO,eAAeE,SAASA,CAC7BC,IAAqB,EACrBC,mBAAmB,EAIO;EAAA,IAAAC,aAAA,EAAAC,cAAA,EAAAC,cAAA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AC,EAC1FsB,OACF,CAAC;EAED,IAAIuD,WAAW,IAAIA,WAAW,CAAC,CAAC,CAAC,EAAE;IACjCA,WAAW,GAAG;MACZI,UAAU,EAAE,IAAI;MAChBC,OAAO,EAAE,KAAK;MACdC,KAAK,EAAEN,WAAW,CAAC,CAAC,CAAC,CAACM,KAAK;MAC3BC,MAAM,EAAEP,WAAW,CAAC,CAAC,CAAC,CAACO,MAAM;MAC7BvD,IAAI,EAAEgD,WAAW,CAAC,CAAC;IACrB,CAAC;EACH;EAKA/D,IAAI,CAACgC,MAAM,GAAGhC,IAAI,CAACgC,MAAM,IAAI,EAAE;EAC/BhC,IAAI,CAACgC,MAAM,CAACwB,KAAK,CAAC,GAAGO,WAAW;AAClC"}
1
+ {"version":3,"file":"parse-gltf.js","names":["parseJSON","sliceArrayBuffer","parseFromContext","ImageLoader","BasisLoader","selectSupportedBasisFormat","assert","isGLB","parseGLBSync","resolveUrl","getTypedArrayForBufferView","preprocessExtensions","decodeExtensions","normalizeGLTFV1","isGLTF","arrayBuffer","options","byteOffset","parseGLTF","gltf","arrayBufferOrString","_options$gltf","_options$gltf2","_options$gltf3","arguments","length","undefined","context","parseGLTFContainerSync","normalize","loadBuffers","json","buffers","loadImages","data","uri","baseUri","ArrayBuffer","textDecoder","TextDecoder","decode","glb","type","concat","_glb","Array","fill","header","hasBinChunk","binChunks","byteLength","images","i","buffer","_context$fetch","_response$arrayBuffer","fetch","response","call","imageIndices","getReferencesImageIndices","promises","imageIndex","push","loadImage","Promise","all","Set","textures","texture","source","add","from","sort","image","index","hasOwnProperty","bufferView","Number","isFinite","array","parsedImage","mimeType","basis","format","compressed","mipmaps","width","height"],"sources":["../../../../src/lib/parsers/parse-gltf.ts"],"sourcesContent":["/* eslint-disable camelcase, max-statements, no-restricted-globals */\nimport type {LoaderContext} from '@loaders.gl/loader-utils';\nimport type {GLTFLoaderOptions} from '../../gltf-loader';\nimport type {GLTFWithBuffers} from '../types/gltf-types';\nimport type {GLB} from '../types/glb-types';\nimport type {ParseGLBOptions} from './parse-glb';\n\nimport type {ImageType, TextureLevel} from '@loaders.gl/schema';\nimport {parseJSON, sliceArrayBuffer, parseFromContext} from '@loaders.gl/loader-utils';\nimport {ImageLoader} from '@loaders.gl/images';\nimport {BasisLoader, selectSupportedBasisFormat} from '@loaders.gl/textures';\n\nimport {assert} from '../utils/assert';\nimport {isGLB, parseGLBSync} from './parse-glb';\nimport {resolveUrl} from '../gltf-utils/resolve-url';\nimport {getTypedArrayForBufferView} from '../gltf-utils/get-typed-array';\nimport {preprocessExtensions, decodeExtensions} from '../api/gltf-extensions';\nimport {normalizeGLTFV1} from '../api/normalize-gltf-v1';\n\n/** */\nexport type ParseGLTFOptions = ParseGLBOptions & {\n normalize?: boolean;\n loadImages?: boolean;\n loadBuffers?: boolean;\n decompressMeshes?: boolean;\n excludeExtensions?: string[];\n\n /** @deprecated not supported in v4. `postProcessGLTF()` must be called by the application */\n postProcess?: false;\n};\n\n/** Check if an array buffer appears to contain GLTF data */\nexport function isGLTF(arrayBuffer: ArrayBuffer, options?: ParseGLTFOptions): boolean {\n const byteOffset = 0;\n return isGLB(arrayBuffer, byteOffset, options);\n}\n\nexport async function parseGLTF(\n gltf: GLTFWithBuffers,\n arrayBufferOrString,\n byteOffset = 0,\n options: GLTFLoaderOptions,\n context: LoaderContext\n): Promise<GLTFWithBuffers> {\n parseGLTFContainerSync(gltf, arrayBufferOrString, byteOffset, options);\n\n normalizeGLTFV1(gltf, {normalize: options?.gltf?.normalize});\n\n preprocessExtensions(gltf, options, context);\n\n // Load linked buffers asynchronously and decodes base64 buffers in parallel\n if (options?.gltf?.loadBuffers && gltf.json.buffers) {\n await loadBuffers(gltf, options, context);\n }\n\n // loadImages and decodeExtensions should not be running in parallel, because\n // decodeExtensions uses data from images taken during the loadImages call.\n if (options?.gltf?.loadImages) {\n await loadImages(gltf, options, context);\n }\n\n await decodeExtensions(gltf, options, context);\n\n return gltf;\n}\n\n/**\n *\n * @param gltf\n * @param data - can be ArrayBuffer (GLB), ArrayBuffer (Binary JSON), String (JSON), or Object (parsed JSON)\n * @param byteOffset\n * @param options\n */\nfunction parseGLTFContainerSync(gltf, data, byteOffset, options) {\n // Initialize gltf container\n if (options.uri) {\n gltf.baseUri = options.uri;\n }\n\n // If data is binary and starting with magic bytes, assume binary JSON text, convert to string\n if (data instanceof ArrayBuffer && !isGLB(data, byteOffset, options)) {\n const textDecoder = new TextDecoder();\n data = textDecoder.decode(data);\n }\n\n if (typeof data === 'string') {\n // If string, try to parse as JSON\n gltf.json = parseJSON(data);\n } else if (data instanceof ArrayBuffer) {\n // If still ArrayBuffer, parse as GLB container\n const glb: GLB = {} as GLB;\n byteOffset = parseGLBSync(glb, data, byteOffset, options.glb);\n\n assert(glb.type === 'glTF', `Invalid GLB magic string ${glb.type}`);\n\n gltf._glb = glb;\n gltf.json = glb.json;\n } else {\n assert(false, 'GLTF: must be ArrayBuffer or string');\n }\n\n // Populate buffers\n // Create an external buffers array to hold binary data\n const buffers = gltf.json.buffers || [];\n gltf.buffers = new Array(buffers.length).fill(null);\n\n // Populates JSON and some bin chunk info\n if (gltf._glb && gltf._glb.header.hasBinChunk) {\n const {binChunks} = gltf._glb;\n gltf.buffers[0] = {\n arrayBuffer: binChunks[0].arrayBuffer,\n byteOffset: binChunks[0].byteOffset,\n byteLength: binChunks[0].byteLength\n };\n\n // TODO - this modifies JSON and is a post processing thing\n // gltf.json.buffers[0].data = gltf.buffers[0].arrayBuffer;\n // gltf.json.buffers[0].byteOffset = gltf.buffers[0].byteOffset;\n }\n\n // Populate images\n const images = gltf.json.images || [];\n gltf.images = new Array(images.length).fill({});\n}\n\n/** Asynchronously fetch and parse buffers, store in buffers array outside of json\n * TODO - traverse gltf and determine which buffers are actually needed\n */\nasync function loadBuffers(gltf: GLTFWithBuffers, options, context: LoaderContext) {\n // TODO\n const buffers = gltf.json.buffers || [];\n for (let i = 0; i < buffers.length; ++i) {\n const buffer = buffers[i];\n if (buffer.uri) {\n const {fetch} = context;\n assert(fetch);\n\n const uri = resolveUrl(buffer.uri, options);\n const response = await context?.fetch?.(uri);\n const arrayBuffer = await response?.arrayBuffer?.();\n\n gltf.buffers[i] = {\n arrayBuffer,\n byteOffset: 0,\n byteLength: arrayBuffer.byteLength\n };\n\n delete buffer.uri;\n } else if (gltf.buffers[i] === null) {\n gltf.buffers[i] = {\n arrayBuffer: new ArrayBuffer(buffer.byteLength),\n byteOffset: 0,\n byteLength: buffer.byteLength\n };\n }\n }\n}\n\n/**\n * Loads all images\n * TODO - traverse gltf and determine which images are actually needed\n * @param gltf\n * @param options\n * @param context\n * @returns\n */\nasync function loadImages(gltf: GLTFWithBuffers, options, context: LoaderContext) {\n const imageIndices = getReferencesImageIndices(gltf);\n\n const images = gltf.json.images || [];\n\n const promises: Promise<any>[] = [];\n for (const imageIndex of imageIndices) {\n promises.push(loadImage(gltf, images[imageIndex], imageIndex, options, context));\n }\n\n return await Promise.all(promises);\n}\n\n/** Make sure we only load images that are actually referenced by textures */\nfunction getReferencesImageIndices(gltf: GLTFWithBuffers): number[] {\n const imageIndices = new Set<number>();\n\n const textures = gltf.json.textures || [];\n for (const texture of textures) {\n if (texture.source !== undefined) {\n imageIndices.add(texture.source);\n }\n }\n\n return Array.from(imageIndices).sort();\n}\n\n/** Asynchronously fetches and parses one image, store in images array outside of json */\nasync function loadImage(\n gltf: GLTFWithBuffers,\n image,\n index: number,\n options,\n context: LoaderContext\n) {\n let arrayBuffer;\n\n if (image.uri && !image.hasOwnProperty('bufferView')) {\n const uri = resolveUrl(image.uri, options);\n\n const {fetch} = context;\n const response = await fetch(uri);\n\n arrayBuffer = await response.arrayBuffer();\n image.bufferView = {\n data: arrayBuffer\n };\n }\n\n if (Number.isFinite(image.bufferView)) {\n const array = getTypedArrayForBufferView(gltf.json, gltf.buffers, image.bufferView);\n arrayBuffer = sliceArrayBuffer(array.buffer, array.byteOffset, array.byteLength);\n }\n\n assert(arrayBuffer, 'glTF image has no data');\n\n // Call `parse`\n let parsedImage = (await parseFromContext(\n arrayBuffer,\n [ImageLoader, BasisLoader],\n {\n ...options,\n mimeType: image.mimeType,\n basis: options.basis || {format: selectSupportedBasisFormat()}\n },\n context\n )) as ImageType | TextureLevel[][];\n\n if (parsedImage && parsedImage[0]) {\n parsedImage = {\n compressed: true,\n // @ts-expect-error\n mipmaps: false,\n width: parsedImage[0].width,\n height: parsedImage[0].height,\n data: parsedImage[0]\n };\n }\n // TODO making sure ImageLoader is overridable by using array of loaders\n // const parsedImage = await parse(arrayBuffer, [ImageLoader]);\n\n // Store the loaded image\n gltf.images = gltf.images || [];\n // @ts-expect-error TODO - sort out image typing asap\n gltf.images[index] = parsedImage;\n}\n"],"mappings":"AAQA,SAAQA,SAAS,EAAEC,gBAAgB,EAAEC,gBAAgB,QAAO,0BAA0B;AACtF,SAAQC,WAAW,QAAO,oBAAoB;AAC9C,SAAQC,WAAW,EAAEC,0BAA0B,QAAO,sBAAsB;AAE5E,SAAQC,MAAM,QAAO,iBAAiB;AACtC,SAAQC,KAAK,EAAEC,YAAY,QAAO,aAAa;AAC/C,SAAQC,UAAU,QAAO,2BAA2B;AACpD,SAAQC,0BAA0B,QAAO,+BAA+B;AACxE,SAAQC,oBAAoB,EAAEC,gBAAgB,QAAO,wBAAwB;AAC7E,SAAQC,eAAe,QAAO,0BAA0B;AAexD,OAAO,SAASC,MAAMA,CAACC,WAAwB,EAAEC,OAA0B,EAAW;EACpF,MAAMC,UAAU,GAAG,CAAC;EACpB,OAAOV,KAAK,CAACQ,WAAW,EAAEE,UAAU,EAAED,OAAO,CAAC;AAChD;AAEA,OAAO,eAAeE,SAASA,CAC7BC,IAAqB,EACrBC,mBAAmB,EAIO;EAAA,IAAAC,aAAA,EAAAC,cAAA,EAAAC,cAAA;EAAA,IAH1BN,UAAU,GAAAO,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAG,CAAC;EAAA,IACdR,OAA0B,GAAAQ,SAAA,CAAAC,MAAA,OA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E,KAAK;MACdC,KAAK,EAAEN,WAAW,CAAC,CAAC,CAAC,CAACM,KAAK;MAC3BC,MAAM,EAAEP,WAAW,CAAC,CAAC,CAAC,CAACO,MAAM;MAC7BtD,IAAI,EAAE+C,WAAW,CAAC,CAAC;IACrB,CAAC;EACH;EAKA9D,IAAI,CAACgC,MAAM,GAAGhC,IAAI,CAACgC,MAAM,IAAI,EAAE;EAE/BhC,IAAI,CAACgC,MAAM,CAACwB,KAAK,CAAC,GAAGM,WAAW;AAClC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=gltf-ext-feature-metadata-schema.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"gltf-ext-feature-metadata-schema.js","names":[],"sources":["../../../../src/lib/types/gltf-ext-feature-metadata-schema.ts"],"sourcesContent":["import {GLTFTextureInfo} from './gltf-json-schema';\n\n/* eslint-disable camelcase */\n\n/**\n * EXT_feature_metadata extension types\n * This extension has glTF-level metadata and primitive-level feature indexing and segmentation metadata\n * Spec - https://github.com/CesiumGS/glTF/tree/3d-tiles-next/extensions/2.0/Vendor/EXT_feature_metadata\n *\n * glTF-level metadata\n * Spec - https://github.com/CesiumGS/glTF/tree/3d-tiles-next/extensions/2.0/Vendor/EXT_feature_metadata#gltf-extension-1\n * JSON Schema - https://github.com/CesiumGS/glTF/blob/3d-tiles-next/extensions/2.0/Vendor/EXT_feature_metadata/schema/glTF.EXT_feature_metadata.schema.json\n */\nexport type GLTF_EXT_feature_metadata_GLTF = {\n /** An object defining classes and enums. */\n schema?: GLTF_EXT_feature_metadata_Schema;\n /** A uri to an external schema file. */\n schemaUri?: string;\n /** An object containing statistics about features. */\n statistics?: GLTF_EXT_feature_metadata_Statistics;\n /** A dictionary, where each key is a feature table ID and each value is an object defining the feature table. */\n featureTables?: {\n [key: string]: GLTF_EXT_feature_metadata_FeatureTable;\n };\n /** A dictionary, where each key is a feature texture ID and each value is an object defining the feature texture. */\n featureTextures?: {\n [key: string]: GLTF_EXT_feature_metadata_FeatureTexture;\n };\n extensions?: Record<string, unknown>;\n extras?: unknown;\n};\n\n/**\n * An object defining classes and enums.\n * Spec - https://github.com/CesiumGS/glTF/tree/3d-tiles-next/extensions/2.0/Vendor/EXT_feature_metadata#schema\n * JSON Schema - https://github.com/CesiumGS/glTF/blob/c38f7f37e894004353c15cd0481bc5b7381ce841/extensions/2.0/Vendor/EXT_feature_metadata/schema/schema.schema.json\n */\nexport type GLTF_EXT_feature_metadata_Schema = {\n /** The name of the schema. */\n name?: string;\n /** The description of the schema. */\n description?: string;\n /** Application-specific version of the schema. */\n version?: string;\n /** A dictionary, where each key is a class ID and each value is an object defining the class. */\n classes?: {\n [key: string]: GLTF_EXT_feature_metadata_Class;\n };\n /** A dictionary, where each key is an enum ID and each value is an object defining the values for the enum. */\n enums?: {\n [key: string]: GLTF_EXT_feature_metadata_Enum;\n };\n extensions?: Record<string, unknown>;\n extras?: unknown;\n};\n\n/**\n * A class containing a set of properties.\n * Spec - https://github.com/CesiumGS/glTF/tree/3d-tiles-next/extensions/2.0/Vendor/EXT_feature_metadata#class\n * JSON Schema - https://github.com/CesiumGS/glTF/blob/c38f7f37e894004353c15cd0481bc5b7381ce841/extensions/2.0/Vendor/EXT_feature_metadata/schema/class.schema.json\n */\nexport type GLTF_EXT_feature_metadata_Class = {\n /** The name of the class, e.g. for display purposes. */\n name?: string;\n /** The description of the class. */\n description?: string;\n /** A dictionary, where each key is a property ID and each value is an object defining the property. */\n properties: {\n [key: string]: GLTF_EXT_feature_metadata_ClassProperty;\n };\n extensions?: Record<string, unknown>;\n extras?: unknown;\n};\n\n/**\n * A class property.\n * Spec - https://github.com/CesiumGS/glTF/tree/3d-tiles-next/extensions/2.0/Vendor/EXT_feature_metadata#class-property\n * JSON Schema - https://github.com/CesiumGS/glTF/blob/c38f7f37e894004353c15cd0481bc5b7381ce841/extensions/2.0/Vendor/EXT_feature_metadata/schema/class.property.schema.json\n */\nexport type GLTF_EXT_feature_metadata_ClassProperty = {\n /** The name of the property, e.g. for display purposes. */\n name?: string;\n /** The description of the property. */\n description?: string;\n /**\n * The property type. If ENUM is used, then enumType must also be specified.\n * If ARRAY is used, then componentType must also be specified.\n * ARRAY is a fixed-length array when componentCount is defined, and variable-length otherwise.\n */\n type:\n | 'INT8'\n | 'UINT8'\n | 'INT16'\n | 'UINT16'\n | 'INT32'\n | 'UINT32'\n | 'INT64'\n | 'UINT64'\n | 'FLOAT32'\n | 'FLOAT64'\n | 'BOOLEAN'\n | 'STRING'\n | 'ENUM'\n | 'ARRAY'\n | string;\n /**\n * An enum ID as declared in the enums dictionary.\n * This value must be specified when type or componentType is ENUM.\n */\n enumType?: string;\n /**\n * When type is ARRAY this indicates the type of each component of the array.\n * If ENUM is used, then enumType must also be specified.\n */\n componentType?:\n | 'INT8'\n | 'UINT8'\n | 'INT16'\n | 'UINT16'\n | 'INT32'\n | 'UINT32'\n | 'INT64'\n | 'UINT64'\n | 'FLOAT32'\n | 'FLOAT64'\n | 'BOOLEAN'\n | 'STRING'\n | 'ENUM'\n | string;\n /** The number of components per element for ARRAY elements. */\n componentCount?: number;\n /**\n * Specifies whether integer values are normalized.\n * This applies both when type is an integer type, or when type is ARRAY with a componentType that is an integer type.\n * For unsigned integer types, values are normalized between [0.0, 1.0].\n * For signed integer types, values are normalized between [-1.0, 1.0].\n * For all other types, this property is ignored.\n */\n normalized: boolean;\n /**\n * Maximum allowed values for property values.\n * Only applicable for numeric types and fixed-length arrays of numeric types.\n * For numeric types this is a single number.\n * For fixed-length arrays this is an array with componentCount number of elements.\n * The normalized property has no effect on these values: they always correspond to the integer values.\n */\n max?: number | number[];\n /**\n * Minimum allowed values for property values.\n * Only applicable for numeric types and fixed-length arrays of numeric types.\n * For numeric types this is a single number.\n * For fixed-length arrays this is an array with componentCount number of elements.\n * The normalized property has no effect on these values: they always correspond to the integer values.\n */\n min?: number | number[];\n /**\n * A default value to use when the property value is not defined.\n * If used, optional must be set to true.\n * The type of the default value must match the property definition: For BOOLEAN use true or false.\n * For STRING use a JSON string. For a numeric type use a JSON number.\n * For ENUM use the enum name, not the integer value.\n * For ARRAY use a JSON array containing values matching the componentType.\n */\n default?: boolean | number | string | number[];\n /** If true, this property is optional. */\n optional?: boolean; // default false;\n /**\n * An identifier that describes how this property should be interpreted.\n * The semantic cannot be used by other properties in the class.\n */\n semantic?: string;\n extensions?: Record<string, unknown>;\n extras?: unknown;\n};\n\n/**\n * An object defining the values of an enum.\n * Spec - https://github.com/CesiumGS/glTF/tree/3d-tiles-next/extensions/2.0/Vendor/EXT_feature_metadata#enum\n * JSON Schema - https://github.com/CesiumGS/glTF/blob/3d-tiles-next/extensions/2.0/Vendor/EXT_feature_metadata/schema/enum.schema.json\n */\nexport type GLTF_EXT_feature_metadata_Enum = {\n /** The name of the enum, e.g. for display purposes. */\n name?: string;\n /** The description of the enum. */\n description?: string;\n /** The type of the integer enum value. */\n valueType?: 'INT8' | 'UINT8' | 'INT16' | 'UINT16' | 'INT32' | 'UINT32' | 'INT64' | 'UINT64'; // default: \"UINT16\"\n /** An array of enum values. Duplicate names or duplicate integer values are not allowed. */\n values: GLTF_EXT_feature_metadata_EnumValue[];\n extensions?: Record<string, unknown>;\n extras?: unknown;\n [key: string]: unknown;\n};\n\n/**\n * An enum value.\n * Spec - https://github.com/CesiumGS/glTF/tree/3d-tiles-next/extensions/2.0/Vendor/EXT_feature_metadata#enum-value\n * JSON Schema - https://github.com/CesiumGS/glTF/blob/3d-tiles-next/extensions/2.0/Vendor/EXT_feature_metadata/schema/enum.value.schema.json\n */\nexport type GLTF_EXT_feature_metadata_EnumValue = {\n /** The name of the enum value. */\n name: string;\n /** The description of the enum value. */\n description?: string;\n /** The integer enum value. */\n value: number; // default: \"UINT16\"\n extensions?: Record<string, unknown>;\n extras?: unknown;\n [key: string]: unknown;\n};\n\n/**\n * A feature table defined by a class and property values stored in arrays.\n * Spec - https://github.com/CesiumGS/glTF/tree/3d-tiles-next/extensions/2.0/Vendor/EXT_feature_metadata#feature-table\n * JSON Schenma - https://github.com/CesiumGS/glTF/blob/c38f7f37e894004353c15cd0481bc5b7381ce841/extensions/2.0/Vendor/EXT_feature_metadata/schema/featureTable.schema.json\n */\nexport type GLTF_EXT_feature_metadata_FeatureTable = {\n /** The class that property values conform to. The value must be a class ID declared in the classes dictionary. */\n class?: string;\n /** The number of features, as well as the number of elements in each property array. */\n count: number;\n /**\n * A dictionary, where each key corresponds to a property ID in the class properties dictionary\n * and each value is an object describing where property values are stored.\n * Optional properties may be excluded from this dictionary.\n */\n properties?: {\n [key: string]: GLTF_EXT_feature_metadata_FeatureTableProperty;\n };\n extensions?: Record<string, unknown>;\n extras?: unknown;\n};\n\n/**\n * An array of binary property values.\n * Spec - https://github.com/CesiumGS/glTF/tree/3d-tiles-next/extensions/2.0/Vendor/EXT_feature_metadata#feature-table-property\n * JSON Schema - https://github.com/CesiumGS/glTF/blob/c38f7f37e894004353c15cd0481bc5b7381ce841/extensions/2.0/Vendor/EXT_feature_metadata/schema/featureTable.property.schema.json\n */\nexport type GLTF_EXT_feature_metadata_FeatureTableProperty = {\n /**\n * The index of the buffer view containing property values.\n * The data type of property values is determined by the property definition:\n * When type is BOOLEAN values are packed into a bitfield.\n * When type is STRING values are stored as byte sequences and decoded as UTF-8 strings.\n * When type is a numeric type values are stored as the provided type.\n * When type is ENUM values are stored as the enum's valueType.\n * Each enum value in the buffer must match one of the allowed values in the enum definition.\n * When type is ARRAY elements are packed tightly together and the data type is based on the componentType following the same rules as above.\n * arrayOffsetBufferView is required for variable-size arrays\n * and stringOffsetBufferView is required for strings (for variable-length arrays of strings, both are required)\n * The buffer view byteOffset must be aligned to a multiple of 8 bytes.\n * If the buffer view's buffer is the GLB-stored BIN chunk the byte offset is measured relative to the beginning of the GLB.\n * Otherwise it is measured relative to the beginning of the buffer.\n */\n bufferView: number;\n\n /** The type of values in arrayOffsetBufferView and stringOffsetBufferView. */\n offsetType?: 'UINT8' | 'UINT16' | 'UINT32' | 'UINT64' | string; // default: \"UINT32\"\n /**\n * The index of the buffer view containing offsets for variable-length arrays.\n * The number of offsets is equal to the feature table count plus one.\n * The offsets represent the start positions of each array, with the last offset representing the position after the last array.\n * The array length is computed using the difference between the current offset and the subsequent offset.\n * If componentType is STRING the offsets index into the string offsets array (stored in stringOffsetBufferView),\n * otherwise they index into the property array (stored in bufferView).\n * The data type of these offsets is determined by offsetType.\n * The buffer view byteOffset must be aligned to a multiple of 8 bytes in the same manner as the main bufferView\n */\n arrayOffsetBufferView?: number;\n /**\n * The index of the buffer view containing offsets for strings.\n * The number of offsets is equal to the number of string components plus one.\n * The offsets represent the byte offsets of each string in the main bufferView,\n * with the last offset representing the byte offset after the last string.\n * The string byte length is computed using the difference between the current offset and the subsequent offset.\n * The data type of these offsets is determined by offsetType.\n * The buffer view byteOffset must be aligned to a multiple of 8 bytes in the same manner as the main bufferView.\n */\n stringOffsetBufferView?: number;\n extensions?: Record<string, unknown>;\n extras?: unknown;\n /** This is not part of the spec. GLTFLoader loads feature tables data into this property */\n data: unknown;\n};\n\n/**\n * Features whose property values are stored directly in texture channels. This is not to be confused with feature ID textures which store feature IDs for use with a feature table.\n * Spec - https://github.com/CesiumGS/glTF/tree/3d-tiles-next/extensions/2.0/Vendor/EXT_feature_metadata#feature-texture\n * JSON Schema - https://github.com/CesiumGS/glTF/blob/c38f7f37e894004353c15cd0481bc5b7381ce841/extensions/2.0/Vendor/EXT_feature_metadata/schema/featureTexture.schema.json\n */\nexport type GLTF_EXT_feature_metadata_FeatureTexture = {\n /** The class this feature texture conforms to. The value must be a class ID declared in the classes dictionary. */\n class: string;\n /**\n * A dictionary, where each key corresponds to a property ID in the class properties dictionary\n * and each value describes the texture channels containing property values.\n */\n properties: {\n [key: string]: GLTF_EXT_feature_metadata_TextureAccessor;\n };\n extensions?: Record<string, unknown>;\n extras?: unknown;\n};\n\n/**\n * A description of how to access property values from the color channels of a texture.\n * Spec - https://github.com/CesiumGS/glTF/tree/3d-tiles-next/extensions/2.0/Vendor/EXT_feature_metadata#texture-accessor\n * JSON Schema - https://github.com/CesiumGS/glTF/blob/c38f7f37e894004353c15cd0481bc5b7381ce841/extensions/2.0/Vendor/EXT_feature_metadata/schema/textureAccessor.schema.json\n */\nexport type GLTF_EXT_feature_metadata_TextureAccessor = {\n /** Texture channels containing property values. Channels are labeled by rgba and are swizzled with a string of 1-4 characters. */\n channels: string;\n /** The glTF texture and texture coordinates to use. */\n texture: GLTFTextureInfo;\n extensions?: Record<string, unknown>;\n extras?: unknown;\n /** This is not part of the spec. GLTFLoader loads feature tables data into this property */\n data: unknown;\n};\n\n/**\n * Statistics about features.\n * Spec - https://github.com/CesiumGS/glTF/tree/3d-tiles-next/extensions/2.0/Vendor/EXT_feature_metadata#statistics-1\n * JSON Schema - https://github.com/CesiumGS/glTF/blob/c38f7f37e894004353c15cd0481bc5b7381ce841/extensions/2.0/Vendor/EXT_feature_metadata/schema/statistics.schema.json\n */\nexport type GLTF_EXT_feature_metadata_Statistics = {\n /**\n * A dictionary, where each key is a class ID declared in the classes dictionary\n * and each value is an object containing statistics about features that conform to the class.\n */\n classes?: {\n [key: string]: GLTF_EXT_feature_metadata_StatisticsClass;\n };\n extensions?: Record<string, unknown>;\n extras?: unknown;\n};\n\n/**\n * Statistics about features that conform to the class.\n * Spec - https://github.com/CesiumGS/glTF/tree/3d-tiles-next/extensions/2.0/Vendor/EXT_feature_metadata#class-statistics\n * JSON Schema - https://github.com/CesiumGS/glTF/blob/c38f7f37e894004353c15cd0481bc5b7381ce841/extensions/2.0/Vendor/EXT_feature_metadata/schema/statistics.class.property.schema.json\n */\nexport type GLTF_EXT_feature_metadata_StatisticsClass = {\n /** The number of features that conform to the class. */\n count?: number;\n /**\n * A dictionary, where each key is a class ID declared in the classes dictionary\n * and each value is an object containing statistics about property values.\n */\n properties?: {\n [key: string]: GLTF_EXT_feature_metadata_StatisticsClassProperty;\n };\n extensions?: Record<string, unknown>;\n extras?: unknown;\n};\n\n/**\n * min, max, mean, median, standardDeviation, variance, sum are\n * only applicable for numeric types and fixed-length arrays of numeric types.\n * For numeric types this is a single number.\n * For fixed-length arrays this is an array with componentCount number of elements.\n * The normalized property has no effect on these values.\n * Spec - https://github.com/CesiumGS/glTF/tree/3d-tiles-next/extensions/2.0/Vendor/EXT_feature_metadata#property-statistics\n * JSON Schema - https://github.com/CesiumGS/glTF/blob/c38f7f37e894004353c15cd0481bc5b7381ce841/extensions/2.0/Vendor/EXT_feature_metadata/schema/statistics.class.property.schema.json\n */\nexport type GLTF_EXT_feature_metadata_StatisticsClassProperty = {\n /** The minimum property value. */\n min?: number | number[];\n /** The maximum property value. */\n max?: number | number[];\n /** The arithmetic mean of the property values. */\n mean?: number | number[];\n /** The median of the property values. */\n median?: number | number[];\n /** The standard deviation of the property values. */\n standardDeviation?: number | number[];\n /** The variance of the property values. */\n variance?: number | number[];\n /** The sum of the property values. */\n sum?: number | number[];\n /**\n * A dictionary, where each key corresponds to an enum name and each value is the number of occurrences of that enum.\n * Only applicable when type or componentType is ENUM.\n * For fixed-length arrays, this is an array with componentCount number of elements.\n */\n occurrences: {\n [key: string]: number | number[];\n };\n extensions?: Record<string, unknown>;\n extras?: unknown;\n};\n\n/**\n * EXT_feature_metadata extension types\n * This extension has glTF-level metadata and primitive-level (feature indexing and segmentation) metadata\n * Spec - https://github.com/CesiumGS/glTF/tree/3d-tiles-next/extensions/2.0/Vendor/EXT_feature_metadata\n *\n * primitive-level metadata\n * Spec - https://github.com/CesiumGS/glTF/tree/3d-tiles-next/extensions/2.0/Vendor/EXT_feature_metadata#primitive-extension\n * JSON Schema - https://github.com/CesiumGS/glTF/blob/c38f7f37e894004353c15cd0481bc5b7381ce841/extensions/2.0/Vendor/EXT_feature_metadata/schema/mesh.primitive.EXT_feature_metadata.schema.json\n */\nexport type GLTF_EXT_feature_metadata_Primitive = {\n /** Feature ids definition in attributes */\n featureIdAttributes?: GLTF_EXT_feature_metadata_FeatureIdAttribute[];\n /** Feature ids definition in textures */\n featureIdTextures?: GLTF_EXT_feature_metadata_FeatureIdTexture[];\n /** An array of IDs of feature textures from the root EXT_feature_metadata object. */\n featureTextures?: string[];\n extensions?: Record<string, unknown>;\n extras?: unknown;\n};\n\n/**\n * Attribute which described featureIds definition.\n * Spec - https://github.com/CesiumGS/glTF/tree/3d-tiles-next/extensions/2.0/Vendor/EXT_feature_metadata#feature-id-attribute\n * JSON Schema - https://github.com/CesiumGS/glTF/blob/c38f7f37e894004353c15cd0481bc5b7381ce841/extensions/2.0/Vendor/EXT_feature_metadata/schema/featureIdAttribute.schema.json\n */\nexport type GLTF_EXT_feature_metadata_FeatureIdAttribute = {\n /** Name of feature table */\n featureTable: string;\n /** Described how feature ids are defined */\n featureIds: GLTF_EXT_feature_metadata_FeatureIdAttributeFeatureIds;\n extensions?: Record<string, unknown>;\n extras?: unknown;\n};\n\n/**\n * Defining featureIds by attributes or implicitly.\n * Spec - https://github.com/CesiumGS/glTF/tree/3d-tiles-next/extensions/2.0/Vendor/EXT_feature_metadata#primitive-extensionfeatureidattributes\n * JSON Schema - https://github.com/CesiumGS/glTF/blob/c38f7f37e894004353c15cd0481bc5b7381ce841/extensions/2.0/Vendor/EXT_feature_metadata/schema/featureIdAttribute.featureIds.schema.json\n */\nexport type GLTF_EXT_feature_metadata_FeatureIdAttributeFeatureIds = {\n /** Name of attribute where featureIds are defined */\n attribute?: string;\n /** Sets a constant feature ID for each vertex. The default is 0. */\n constant?: number;\n /** Sets the rate at which feature IDs increment.\n * If divisor is zero then constant is used.\n * If divisor is greater than zero the feature ID increments once per divisor sets of vertices, starting at constant.\n * The default is 0\n */\n divisor?: number;\n};\n\n/**\n * An object describing a texture used for storing per-texel feature IDs.\n * Spec - https://github.com/CesiumGS/glTF/tree/3d-tiles-next/extensions/2.0/Vendor/EXT_feature_metadata#feature-id-texture\n * JSON Schema - https://github.com/CesiumGS/glTF/blob/c38f7f37e894004353c15cd0481bc5b7381ce841/extensions/2.0/Vendor/EXT_feature_metadata/schema/featureIdTexture.schema.json\n */\nexport type GLTF_EXT_feature_metadata_FeatureIdTexture = {\n /** The ID of the feature table in the model's root `EXT_feature_metadata.featureTables` dictionary. */\n featureTable: string;\n /** A description of the texture and channel to use for feature IDs. The `channels` property must have a single channel. Furthermore,\n * feature IDs must be whole numbers in the range `[0, count - 1]` (inclusive), where `count` is the total number of features\n * in the feature table. Texel values must be read as integers. Texture filtering should be disabled when fetching feature IDs.\n */\n featureIds: GLTF_EXT_feature_metadata_FeatureIdTextureAccessor;\n};\n\n/**\n * A description of how to access property values from the color channels of a texture.\n * Spec - https://github.com/CesiumGS/glTF/tree/3d-tiles-next/extensions/2.0/Vendor/EXT_feature_metadata#featureidtexturefeatureids\n * JSON Schema - https://github.com/CesiumGS/glTF/blob/c38f7f37e894004353c15cd0481bc5b7381ce841/extensions/2.0/Vendor/EXT_feature_metadata/schema/textureAccessor.schema.json\n */\nexport type GLTF_EXT_feature_metadata_FeatureIdTextureAccessor = {\n /** gLTF textureInfo object - https://github.com/CesiumGS/glTF/blob/3d-tiles-next/specification/2.0/schema/textureInfo.schema.json */\n texture: GLTFTextureInfo;\n /** Must be a single channel (\"r\", \"g\", \"b\", or \"a\") */\n channels: 'r' | 'g' | 'b' | 'a';\n};\n"],"mappings":""}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=gltf-ext-mesh-features-schema.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"gltf-ext-mesh-features-schema.js","names":[],"sources":["../../../../src/lib/types/gltf-ext-mesh-features-schema.ts"],"sourcesContent":["import {GLTFTextureInfoMetadata} from './gltf-json-schema';\n/* eslint-disable camelcase */\n\n/**\n * EXT_mesh_features extension types\n * This is a primitive-level extension.\n * An object describing feature IDs for a mesh primitive.\n * @see https://github.com/CesiumGS/glTF/tree/3d-tiles-next/extensions/2.0/Vendor/EXT_mesh_features\n * or https://github.com/CesiumGS/glTF/blob/c38f7f37e894004353c15cd0481bc5b7381ce841/extensions/2.0/Vendor/EXT_mesh_features/schema/mesh.primitive.EXT_mesh_features.schema.json\n */\nexport type GLTF_EXT_mesh_features = {\n /** An array of feature ID sets. */\n featureIds: GLTF_EXT_mesh_features_featureId[];\n extensions?: Record<string, unknown>;\n extras?: unknown;\n};\n\n/**\n * Feature IDs stored in an attribute or texture.\n * @see https://github.com/CesiumGS/glTF/blob/c38f7f37e894004353c15cd0481bc5b7381ce841/extensions/2.0/Vendor/EXT_mesh_features/schema/featureId.schema.json\n */\nexport type GLTF_EXT_mesh_features_featureId = {\n /** The number of unique features in the attribute or texture. */\n featureCount: number;\n /** A value that indicates that no feature is associated with this vertex or texel. */\n nullFeatureId?: number;\n /** A label assigned to this feature ID set. Labels must be alphanumeric identifiers matching the regular expression `^[a-zA-Z_][a-zA-Z0-9_]*$`. */\n label?: string;\n /**\n * An attribute containing feature IDs.\n * When `attribute` and `texture` are omitted the feature IDs are assigned to vertices by their index.\n * @see https://github.com/CesiumGS/glTF/blob/3d-tiles-next/extensions/2.0/Vendor/EXT_mesh_features/schema/featureIdAttribute.schema.json\n * An integer value used to construct a string in the format `_FEATURE_ID_<set index>` which is a reference to a key in `mesh.primitives.attributes`\n * (e.g. a value of `0` corresponds to `_FEATURE_ID_0`).\n */\n attribute?: number;\n /** A texture containing feature IDs. */\n texture?: GLTFTextureInfoMetadata;\n /** The index of the property table containing per-feature property values. Only applicable when using the `EXT_structural_metadata` extension. */\n propertyTable?: number;\n extensions?: Record<string, unknown>;\n extras?: unknown;\n\n /** This is not part of the spec. GLTFLoader loads feature tables data into this property */\n data?: unknown;\n};\n"],"mappings":""}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=gltf-ext-structural-metadata-schema.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"gltf-ext-structural-metadata-schema.js","names":[],"sources":["../../../../src/lib/types/gltf-ext-structural-metadata-schema.ts"],"sourcesContent":["import {GLTFTextureInfoMetadata} from './gltf-json-schema';\n\n/* eslint-disable camelcase */\n\n/**\n * glTF extension that provides structural metadata about vertices, texels, and features in a glTF asset.\n * @see https://github.com/CesiumGS/glTF/blob/3d-tiles-next/extensions/2.0/Vendor/EXT_structural_metadata/schema/glTF.EXT_structural_metadata.schema.json\n */\nexport type GLTF_EXT_structural_metadata_GLTF = {\n /** An object defining classes and enums. */\n schema?: GLTF_EXT_structural_metadata_Schema;\n /** A uri to an external schema file. */\n schemaUri?: string;\n /** An array of property table definitions, which may be referenced by index. */\n propertyTables?: GLTF_EXT_structural_metadata_PropertyTable[];\n /** An array of property texture definitions, which may be referenced by index. */\n propertyTextures?: GLTF_EXT_structural_metadata_PropertyTexture[];\n /** \"An array of property attribute definitions, which may be referenced by index. */\n propertyAttributes?: GLTF_EXT_structural_metadata_PropertyAttribute[];\n /** This is not part of the spec. GLTFLoader loads names of attributes crated into this property */\n dataAttributeNames?: string[];\n};\n\n/**\n * An object defining classes and enums.\n * @see https://github.com/CesiumGS/glTF/blob/3d-tiles-next/extensions/2.0/Vendor/EXT_structural_metadata/schema/schema.schema.json\n */\nexport type GLTF_EXT_structural_metadata_Schema = {\n /** Unique identifier for the schema. Schema IDs must be alphanumeric identifiers matching the regular expression `^[a-zA-Z_][a-zA-Z0-9_]*$`. */\n id: string;\n /** The name of the schema. */\n name?: string;\n /** The description of the schema. */\n description?: string;\n /** Application-specific version of the schema. */\n version?: string;\n /** A dictionary, where each key is a class ID and each value is an object defining the class. */\n classes?: {\n [key: string]: GLTF_EXT_structural_metadata_Class;\n };\n /** A dictionary, where each key is an enum ID and each value is an object defining the values for the enum. */\n enums?: {\n [key: string]: GLTF_EXT_structural_metadata_Enum;\n };\n extensions?: Record<string, unknown>;\n extras?: unknown;\n};\n\n/**\n * An object defining the values of an enum.\n * @see https://github.com/CesiumGS/glTF/blob/3d-tiles-next/extensions/2.0/Vendor/EXT_structural_metadata/schema/enum.schema.json\n */\nexport type GLTF_EXT_structural_metadata_Enum = {\n /** The name of the enum, e.g. for display purposes. */\n name?: string;\n /** The description of the enum. */\n description?: string;\n /**\n * The type of the integer enum value.\n * Default value is 'UINT16'\n */\n valueType?: 'INT8' | 'UINT8' | 'INT16' | 'UINT16' | 'INT32' | 'UINT32' | 'INT64' | 'UINT64';\n /** An array of enum values. Duplicate names or duplicate integer values are not allowed. */\n values: GLTF_EXT_structural_metadata_EnumValue[];\n extensions?: Record<string, unknown>;\n extras?: unknown;\n};\n\n/**\n * An enum value.\n * @see https://github.com/CesiumGS/glTF/blob/3d-tiles-next/extensions/2.0/Vendor/EXT_structural_metadata/schema/enum.value.schema.json\n */\nexport type GLTF_EXT_structural_metadata_EnumValue = {\n /** The name of the enum value. */\n name: string;\n /** The description of the enum value. */\n description?: string;\n /** The integer enum value. */\n value: number;\n extensions?: Record<string, unknown>;\n extras?: unknown;\n};\n\n/**\n * A class containing a set of properties.\n * @see https://github.com/CesiumGS/glTF/blob/3d-tiles-next/extensions/2.0/Vendor/EXT_structural_metadata/schema/class.schema.json\n */\nexport type GLTF_EXT_structural_metadata_Class = {\n /** The name of the class, e.g. for display purposes. */\n name?: string;\n /** The description of the class. */\n description?: string;\n /**\n * A dictionary, where each key is a property ID and each value is an object defining the property.\n * Property IDs must be alphanumeric identifiers matching the regular expression `^[a-zA-Z_][a-zA-Z0-9_]*$`.\n */\n properties: {\n [key: string]: GLTF_EXT_structural_metadata_ClassProperty;\n };\n extensions?: Record<string, unknown>;\n extras?: unknown;\n};\n\n/**\n * A class property.\n * @see https://github.com/CesiumGS/glTF/blob/3d-tiles-next/extensions/2.0/Vendor/EXT_structural_metadata/schema/class.property.schema.json\n */\nexport type GLTF_EXT_structural_metadata_ClassProperty = {\n /** The name of the property, e.g. for display purposes. */\n name?: string;\n\n /** The description of the property. */\n description?: string;\n\n /** The element type. */\n type:\n | 'SCALAR'\n | 'VEC2'\n | 'VEC3'\n | 'VEC4'\n | 'MAT2'\n | 'MAT3'\n | 'MAT4'\n | 'BOOLEAN'\n | 'STRING'\n | 'ENUM'\n | string;\n\n /** The datatype of the element's components. Only applicable to `SCALAR`, `VECN`, and `MATN` types. */\n componentType?:\n | 'INT8'\n | 'UINT8'\n | 'INT16'\n | 'UINT16'\n | 'INT32'\n | 'UINT32'\n | 'INT64'\n | 'UINT64'\n | 'FLOAT32'\n | 'FLOAT64'\n | string;\n\n /** Enum ID as declared in the `enums` dictionary. Required when `type` is `ENUM`. */\n enumType?: string;\n\n /**\n * Whether the property is an array.\n * When `count` is defined the property is a fixed-length array. Otherwise the property is a variable-length array.\n */\n array?: boolean;\n\n /** The number of array elements. May only be defined when `array` is true. */\n count?: number;\n\n /**\n * Specifies whether integer values are normalized.\n * Only applicable to `SCALAR`, `VECN`, and `MATN` types with integer component types.\n * For unsigned integer component types, values are normalized between `[0.0, 1.0]`.\n * For signed integer component types, values are normalized between `[-1.0, 1.0]`.\n * For all other component types, this property must be false.\n */\n normalized?: boolean;\n\n /**\n * An offset to apply to property values.\n * Only applicable to `SCALAR`, `VECN`, and `MATN` types when the component type is `FLOAT32` or `FLOAT64`, or when the property is `normalized`.\n */\n offset?: number | number[];\n\n /**\n * A scale to apply to property values.\n * Only applicable to `SCALAR`, `VECN`, and `MATN` types when the component type is `FLOAT32` or `FLOAT64`, or when the property is `normalized`.\n */\n scale?: number | number[];\n\n /**\n * Maximum allowed value for the property.\n * Only applicable to `SCALAR`, `VECN`, and `MATN` types.\n * This is the maximum of all property values, after the transforms based on the `normalized`, `offset`, and `scale` properties have been applied.\n */\n max?: number | number[];\n\n /**\n * Minimum allowed value for the property.\n * Only applicable to `SCALAR`, `VECN`, and `MATN` types.\n * This is the minimum of all property values, after the transforms based on the `normalized`, `offset`, and `scale` properties have been applied.\n */\n min?: number | number[];\n\n default?: boolean | number | string | number[];\n /**\n * If required, the property must be present in every entity conforming to the class.\n * If not required, individual entities may include `noData` values, or the entire property may be omitted.\n * As a result, `noData` has no effect on a required property.\n * Client implementations may use required properties to make performance optimizations.\n * Default value is false.\n */\n required?: boolean;\n\n /**\n * A `noData` value represents missing data — also known as a sentinel value — wherever it appears.\n * `BOOLEAN` properties may not specify `noData` values.\n * This is given as the plain property value, without the transforms from the `normalized`, `offset`, and `scale` properties.\n * Must not be defined if `required` is true.\n */\n noData?: number | string | number[] | string[];\n\n /**\n * An identifier that describes how this property should be interpreted.\n * The semantic cannot be used by other properties in the class.\n */\n semantic?: string;\n extensions?: Record<string, unknown>;\n extras?: unknown;\n};\n\n/**\n * Properties conforming to a class, organized as property values stored in binary columnar arrays.\n * @see https://github.com/CesiumGS/glTF/blob/3d-tiles-next/extensions/2.0/Vendor/EXT_structural_metadata/schema/propertyTable.schema.json\n */\nexport type GLTF_EXT_structural_metadata_PropertyTable = {\n /** The name of the property table, e.g. for display purposes. */\n name?: string;\n /** The class that property values conform to. The value must be a class ID declared in the `classes` dictionary. */\n class: string;\n /** The number of elements in each property array. */\n count: number;\n /**\n * A dictionary, where each key corresponds to a property ID in the class' `properties` dictionary\n * and each value is an object describing where property values are stored.\n * Required properties must be included in this dictionary.\n */\n properties?: {\n [key: string]: GLTF_EXT_structural_metadata_PropertyTable_Property;\n };\n extensions?: Record<string, unknown>;\n extras?: unknown;\n};\n\n/**\n * An array of binary property values.\n * @see https://github.com/CesiumGS/glTF/blob/3d-tiles-next/extensions/2.0/Vendor/EXT_structural_metadata/schema/propertyTable.property.schema.json\n */\nexport type GLTF_EXT_structural_metadata_PropertyTable_Property = {\n /**\n * The index of the buffer view containing property values.\n * The data type of property values is determined by the property definition:\n * When `type` is `BOOLEAN` values are packed into a bitstream.\n * When `type` is `STRING` values are stored as byte sequences and decoded as UTF-8 strings.\n * When `type` is `SCALAR`, `VECN`, or `MATN` the values are stored as the provided `componentType`\n * and the buffer view `byteOffset` must be aligned to a multiple of the `componentType` size.\n * When `type` is `ENUM` values are stored as the enum's `valueType`\n * and the buffer view `byteOffset` must be aligned to a multiple of the `valueType` size.\n * Each enum value in the array must match one of the allowed values in the enum definition.\n * `arrayOffsets` is required for variable-length arrays and `stringOffsets` is required for strings (for variable-length arrays of strings, both are required).\n */\n values: number;\n /**\n * The index of the buffer view containing offsets for variable-length arrays.\n * The number of offsets is equal to the property table `count` plus one.\n * The offsets represent the start positions of each array, with the last offset representing the position after the last array.\n * The array length is computed using the difference between the subsequent offset and the current offset.\n * If `type` is `STRING` the offsets index into the string offsets array (stored in `stringOffsets`), otherwise they index into the property array (stored in `values`).\n * The data type of these offsets is determined by `arrayOffsetType`.\n * The buffer view `byteOffset` must be aligned to a multiple of the `arrayOffsetType` size.\n */\n arrayOffsets?: number;\n /**\n * The index of the buffer view containing offsets for strings.\n * The number of offsets is equal to the number of string elements plus one.\n * The offsets represent the byte offsets of each string in the property array (stored in `values`), with the last offset representing the byte offset after the last string.\n * The string byte length is computed using the difference between the subsequent offset and the current offset.\n * The data type of these offsets is determined by `stringOffsetType`.\n * The buffer view `byteOffset` must be aligned to a multiple of the `stringOffsetType` size.\n */\n stringOffsets?: number;\n /**\n * The type of values in `arrayOffsets`.\n * Default value is 'UINT32'\n */\n arrayOffsetType?: 'UINT8' | 'UINT16' | 'UINT32' | 'UINT64' | string;\n\n /**\n * The type of values in `stringOffsets`.\n * Default value is 'UINT32'\n */\n stringOffsetType?: 'UINT8' | 'UINT16' | 'UINT32' | 'UINT64' | string;\n /**\n * An offset to apply to property values.\n * Only applicable when the component type is `FLOAT32` or `FLOAT64`, or when the property is `normalized`.\n * Overrides the class property's `offset` if both are defined.\n */\n offset?: number | number[];\n /**\n * A scale to apply to property values.\n * Only applicable when the component type is `FLOAT32` or `FLOAT64`, or when the property is `normalized`.\n * Overrides the class property's `scale` if both are defined.\n */\n scale?: number | number[];\n /**\n * Maximum value present in the property values.\n * Only applicable to `SCALAR`, `VECN`, and `MATN` types.\n * This is the maximum of all property values, after the transforms based on the `normalized`, `offset`, and `scale` properties have been applied.\n */\n max?: number | number[];\n /**\n * Minimum value present in the property values.\n * Only applicable to `SCALAR`, `VECN`, and `MATN` types.\n * This is the minimum of all property values, after the transforms based on the `normalized`, `offset`, and `scale` properties have been applied.\n */\n min?: number | number[];\n extensions?: Record<string, unknown>;\n extras?: unknown;\n /** This is not part of the spec. GLTFLoader loads feature tables data into this property */\n data?: unknown;\n};\n\n/**\n * Properties conforming to a class, organized as property values stored in textures.\n * @see https://github.com/CesiumGS/glTF/blob/3d-tiles-next/extensions/2.0/Vendor/EXT_structural_metadata/schema/propertyTexture.schema.json\n */\nexport type GLTF_EXT_structural_metadata_PropertyTexture = {\n /** The name of the property texture, e.g. for display purposes. */\n name?: string;\n /** The class that property values conform to. The value must be a class ID declared in the `classes` dictionary. */\n class: string;\n /**\n * A dictionary, where each key corresponds to a property ID in the class' `properties` dictionary\n * and each value is an object describing where property values are stored.\n * Required properties must be included in this dictionary.\n *\n * https://github.com/CesiumGS/glTF/tree/3d-tiles-next/extensions/2.0/Vendor/EXT_structural_metadata\n * Each property that is defined in the propertyTexture object extends the glTF textureInfo object.\n * The texCoord specifies a texture coordinate set in the referring primitive.\n * The index is the index of the glTF texture object that stores the actual data. Additionally,\n * each property specifies an array of channels, which are the indices of the texture channels providing data for the respective property.\n * Channels of an RGBA texture are numbered 0..3 respectively.\n */\n properties?: {\n [key: string]: GLTFTextureInfoMetadata;\n };\n extensions?: Record<string, unknown>;\n extras?: unknown;\n};\n\n/**\n * Properties conforming to a class, organized as property values stored in attributes.\n * @see https://github.com/CesiumGS/glTF/blob/3d-tiles-next/extensions/2.0/Vendor/EXT_structural_metadata/schema/propertyAttribute.schema.json\n */\nexport type GLTF_EXT_structural_metadata_PropertyAttribute = {\n /** The name of the property attribute, e.g. for display purposes. */\n name?: string;\n /** The class that property values conform to. The value must be a class ID declared in the `classes` dictionary. */\n class: string;\n /**\n * \"A dictionary, where each key corresponds to a property ID in the class' `properties` dictionary\n * and each value is an object describing where property values are stored.\n * Required properties must be included in this dictionary.\n */\n properties?: {\n [key: string]: unknown;\n };\n extensions?: Record<string, unknown>;\n extras?: unknown;\n};\n\n/**\n * Structural metadata about a glTF primitive.\n * @see https://github.com/CesiumGS/glTF/blob/3d-tiles-next/extensions/2.0/Vendor/EXT_structural_metadata/schema/mesh.primitive.EXT_structural_metadata.schema.json\n */\nexport type GLTF_EXT_structural_metadata_Primitive = {\n /** An array of indexes of property textures in the root `EXT_structural_metadata` object. */\n propertyTextures?: number[];\n /** An array of indexes of property attributes in the root `EXT_structural_metadata` object. */\n propertyAttributes?: number[];\n extensions?: Record<string, unknown>;\n extras?: unknown;\n};\n"],"mappings":""}