@loaders.gl/gltf 4.0.0-alpha.22 → 4.0.0-alpha.23
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.
- package/dist/dist.min.js +3577 -3025
- package/dist/es5/index.js +21 -0
- package/dist/es5/index.js.map +1 -1
- package/dist/es5/lib/api/gltf-extensions.js +3 -1
- package/dist/es5/lib/api/gltf-extensions.js.map +1 -1
- package/dist/es5/lib/extensions/EXT_mesh_features.js +111 -0
- package/dist/es5/lib/extensions/EXT_mesh_features.js.map +1 -0
- package/dist/es5/lib/extensions/EXT_structural_metadata.js +386 -0
- package/dist/es5/lib/extensions/EXT_structural_metadata.js.map +1 -0
- package/dist/es5/lib/extensions/data-processing.js +181 -0
- package/dist/es5/lib/extensions/data-processing.js.map +1 -0
- package/dist/es5/lib/extensions/deprecated/EXT_feature_metadata.js +6 -9
- package/dist/es5/lib/extensions/deprecated/EXT_feature_metadata.js.map +1 -1
- package/dist/es5/lib/types/gltf-ext-mesh-features-schema.js +2 -0
- package/dist/es5/lib/types/gltf-ext-mesh-features-schema.js.map +1 -0
- package/dist/es5/lib/types/gltf-ext-structural-metadata-schema.js +2 -0
- package/dist/es5/lib/types/gltf-ext-structural-metadata-schema.js.map +1 -0
- package/dist/es5/lib/types/gltf-json-schema.js.map +1 -1
- package/dist/es5/lib/utils/version.js +1 -1
- package/dist/esm/index.js +3 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/lib/api/gltf-extensions.js +3 -1
- package/dist/esm/lib/api/gltf-extensions.js.map +1 -1
- package/dist/esm/lib/extensions/EXT_mesh_features.js +55 -0
- package/dist/esm/lib/extensions/EXT_mesh_features.js.map +1 -0
- package/dist/esm/lib/extensions/EXT_structural_metadata.js +320 -0
- package/dist/esm/lib/extensions/EXT_structural_metadata.js.map +1 -0
- package/dist/esm/lib/extensions/data-processing.js +146 -0
- package/dist/esm/lib/extensions/data-processing.js.map +1 -0
- package/dist/esm/lib/extensions/deprecated/EXT_feature_metadata.js +4 -7
- package/dist/esm/lib/extensions/deprecated/EXT_feature_metadata.js.map +1 -1
- package/dist/esm/lib/types/gltf-ext-mesh-features-schema.js +2 -0
- package/dist/esm/lib/types/gltf-ext-mesh-features-schema.js.map +1 -0
- package/dist/esm/lib/types/gltf-ext-structural-metadata-schema.js +2 -0
- package/dist/esm/lib/types/gltf-ext-structural-metadata-schema.js.map +1 -0
- package/dist/esm/lib/types/gltf-json-schema.js.map +1 -1
- package/dist/esm/lib/utils/version.js +1 -1
- package/dist/index.d.ts +6 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7 -1
- package/dist/lib/api/gltf-extensions.d.ts.map +1 -1
- package/dist/lib/api/gltf-extensions.js +5 -0
- package/dist/lib/extensions/EXT_mesh_features.d.ts +7 -0
- package/dist/lib/extensions/EXT_mesh_features.d.ts.map +1 -0
- package/dist/lib/extensions/EXT_mesh_features.js +89 -0
- package/dist/lib/extensions/EXT_structural_metadata.d.ts +17 -0
- package/dist/lib/extensions/EXT_structural_metadata.d.ts.map +1 -0
- package/dist/lib/extensions/EXT_structural_metadata.js +504 -0
- package/dist/lib/extensions/data-processing.d.ts +34 -0
- package/dist/lib/extensions/data-processing.d.ts.map +1 -0
- package/dist/lib/extensions/data-processing.js +212 -0
- package/dist/lib/extensions/deprecated/EXT_feature_metadata.d.ts.map +1 -1
- package/dist/lib/extensions/deprecated/EXT_feature_metadata.js +8 -17
- package/dist/lib/types/gltf-ext-mesh-features-schema.d.ts +45 -0
- package/dist/lib/types/gltf-ext-mesh-features-schema.d.ts.map +1 -0
- package/dist/lib/types/gltf-ext-mesh-features-schema.js +2 -0
- package/dist/lib/types/gltf-ext-structural-metadata-schema.d.ts +310 -0
- package/dist/lib/types/gltf-ext-structural-metadata-schema.d.ts.map +1 -0
- package/dist/lib/types/gltf-ext-structural-metadata-schema.js +2 -0
- package/dist/lib/types/gltf-json-schema.d.ts +11 -57
- package/dist/lib/types/gltf-json-schema.d.ts.map +1 -1
- package/package.json +6 -6
- package/src/index.ts +11 -3
- package/src/lib/api/gltf-extensions.ts +6 -2
- package/src/lib/extensions/EXT_mesh_features.ts +117 -0
- package/src/lib/extensions/EXT_structural_metadata.ts +730 -0
- package/src/lib/extensions/data-processing.ts +264 -0
- package/src/lib/extensions/deprecated/EXT_feature_metadata.ts +6 -17
- package/src/lib/types/gltf-ext-mesh-features-schema.ts +48 -0
- package/src/lib/types/gltf-ext-structural-metadata-schema.ts +357 -0
- package/src/lib/types/gltf-json-schema.ts +12 -60
|
@@ -0,0 +1,320 @@
|
|
|
1
|
+
import { GLTFScenegraph } from '../api/gltf-scenegraph';
|
|
2
|
+
import { convertRawBufferToMetadataArray, getPrimitiveTextureData, primitivePropertyDataToAttributes, getArrayElementByteSize } from './data-processing';
|
|
3
|
+
const EXT_STRUCTURAL_METADATA_NAME = 'EXT_structural_metadata';
|
|
4
|
+
export const name = EXT_STRUCTURAL_METADATA_NAME;
|
|
5
|
+
export async function decode(gltfData, options) {
|
|
6
|
+
const scenegraph = new GLTFScenegraph(gltfData);
|
|
7
|
+
decodeExtStructuralMetadata(scenegraph, options);
|
|
8
|
+
}
|
|
9
|
+
export function getPropertyTablePopulated(scenegraph, propertyTableIndex) {
|
|
10
|
+
var _extension$propertyTa;
|
|
11
|
+
const extension = scenegraph.getExtension(EXT_STRUCTURAL_METADATA_NAME);
|
|
12
|
+
const propertyTable = extension === null || extension === void 0 ? void 0 : (_extension$propertyTa = extension.propertyTables) === null || _extension$propertyTa === void 0 ? void 0 : _extension$propertyTa[propertyTableIndex];
|
|
13
|
+
if (extension !== null && extension !== void 0 && extension.schema && propertyTable) {
|
|
14
|
+
processPropertyTable(scenegraph, extension.schema, propertyTable);
|
|
15
|
+
return propertyTable;
|
|
16
|
+
}
|
|
17
|
+
throw new Error("Incorrect data in the EXT_structural_metadata extension: no property table with index ".concat(propertyTableIndex));
|
|
18
|
+
}
|
|
19
|
+
function decodeExtStructuralMetadata(scenegraph, options) {
|
|
20
|
+
var _options$gltf;
|
|
21
|
+
const extension = scenegraph.getExtension(EXT_STRUCTURAL_METADATA_NAME);
|
|
22
|
+
if (!(extension !== null && extension !== void 0 && extension.schema)) {
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
const propertyTextures = extension.propertyTextures;
|
|
26
|
+
const json = scenegraph.gltf.json;
|
|
27
|
+
if (propertyTextures && json.meshes && options !== null && options !== void 0 && (_options$gltf = options.gltf) !== null && _options$gltf !== void 0 && _options$gltf.loadImages) {
|
|
28
|
+
for (const mesh of json.meshes) {
|
|
29
|
+
for (const primitive of mesh.primitives) {
|
|
30
|
+
processPrimitivePropertyTextures(scenegraph, propertyTextures, primitive, extension);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
const schemaClasses = extension.schema.classes;
|
|
35
|
+
const propertyTables = extension.propertyTables;
|
|
36
|
+
if (schemaClasses && propertyTables) {
|
|
37
|
+
for (const schemaName in schemaClasses) {
|
|
38
|
+
const propertyTable = findPropertyTableByClass(propertyTables, schemaName);
|
|
39
|
+
if (propertyTable) {
|
|
40
|
+
processPropertyTable(scenegraph, extension.schema, propertyTable);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
function processPrimitivePropertyTextures(scenegraph, propertyTextures, primitive, extension) {
|
|
46
|
+
var _primitive$extensions;
|
|
47
|
+
if (!propertyTextures) {
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
const primitiveExtension = (_primitive$extensions = primitive.extensions) === null || _primitive$extensions === void 0 ? void 0 : _primitive$extensions[EXT_STRUCTURAL_METADATA_NAME];
|
|
51
|
+
const primitivePropertyTextureIndices = primitiveExtension === null || primitiveExtension === void 0 ? void 0 : primitiveExtension.propertyTextures;
|
|
52
|
+
if (!primitivePropertyTextureIndices) {
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
for (const primitivePropertyTextureIndex of primitivePropertyTextureIndices) {
|
|
56
|
+
const propertyTexture = propertyTextures[primitivePropertyTextureIndex];
|
|
57
|
+
processPrimitivePropertyTexture(scenegraph, propertyTexture, primitive, extension);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
function processPrimitivePropertyTexture(scenegraph, propertyTexture, primitive, extension) {
|
|
61
|
+
if (!propertyTexture.properties) {
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
if (!extension.dataAttributeNames) {
|
|
65
|
+
extension.dataAttributeNames = [];
|
|
66
|
+
}
|
|
67
|
+
const className = propertyTexture.class;
|
|
68
|
+
for (const propName in propertyTexture.properties) {
|
|
69
|
+
var _propertyTexture$prop;
|
|
70
|
+
const attributeName = "".concat(className, "_").concat(propName);
|
|
71
|
+
const textureInfoTopLevel = (_propertyTexture$prop = propertyTexture.properties) === null || _propertyTexture$prop === void 0 ? void 0 : _propertyTexture$prop[propName];
|
|
72
|
+
if (!textureInfoTopLevel) {
|
|
73
|
+
continue;
|
|
74
|
+
}
|
|
75
|
+
if (!textureInfoTopLevel.data) {
|
|
76
|
+
textureInfoTopLevel.data = [];
|
|
77
|
+
}
|
|
78
|
+
const featureTextureTable = textureInfoTopLevel.data;
|
|
79
|
+
const propertyData = getPrimitiveTextureData(scenegraph, textureInfoTopLevel, primitive);
|
|
80
|
+
if (propertyData === null) {
|
|
81
|
+
continue;
|
|
82
|
+
}
|
|
83
|
+
primitivePropertyDataToAttributes(scenegraph, attributeName, propertyData, featureTextureTable, primitive);
|
|
84
|
+
textureInfoTopLevel.data = featureTextureTable;
|
|
85
|
+
extension.dataAttributeNames.push(attributeName);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
function processPropertyTable(scenegraph, schema, propertyTable) {
|
|
89
|
+
var _schema$classes;
|
|
90
|
+
const schemaClass = (_schema$classes = schema.classes) === null || _schema$classes === void 0 ? void 0 : _schema$classes[propertyTable.class];
|
|
91
|
+
if (!schemaClass) {
|
|
92
|
+
throw new Error("Incorrect data in the EXT_structural_metadata extension: no schema class with name ".concat(propertyTable.class));
|
|
93
|
+
}
|
|
94
|
+
const numberOfElements = propertyTable.count;
|
|
95
|
+
for (const propertyName in schemaClass.properties) {
|
|
96
|
+
var _propertyTable$proper;
|
|
97
|
+
const classProperty = schemaClass.properties[propertyName];
|
|
98
|
+
const propertyTableProperty = (_propertyTable$proper = propertyTable.properties) === null || _propertyTable$proper === void 0 ? void 0 : _propertyTable$proper[propertyName];
|
|
99
|
+
if (propertyTableProperty) {
|
|
100
|
+
const data = getPropertyDataFromBinarySource(scenegraph, schema, classProperty, numberOfElements, propertyTableProperty);
|
|
101
|
+
propertyTableProperty.data = data;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
function getPropertyDataFromBinarySource(scenegraph, schema, classProperty, numberOfElements, propertyTableProperty) {
|
|
106
|
+
let data = [];
|
|
107
|
+
const valuesBufferView = propertyTableProperty.values;
|
|
108
|
+
const valuesDataBytes = scenegraph.getTypedArrayForBufferView(valuesBufferView);
|
|
109
|
+
let arrayOffsets = null;
|
|
110
|
+
if (classProperty.array && typeof classProperty.count === 'undefined' && typeof propertyTableProperty.arrayOffsets !== 'undefined' && typeof propertyTableProperty.arrayOffsetType !== 'undefined') {
|
|
111
|
+
arrayOffsets = getOffsetArray(scenegraph, propertyTableProperty.arrayOffsets, propertyTableProperty.arrayOffsetType, numberOfElements);
|
|
112
|
+
}
|
|
113
|
+
let stringOffsets = null;
|
|
114
|
+
if (typeof propertyTableProperty.stringOffsets !== 'undefined' && typeof propertyTableProperty.stringOffsetType !== 'undefined') {
|
|
115
|
+
stringOffsets = getOffsetArray(scenegraph, propertyTableProperty.stringOffsets, propertyTableProperty.stringOffsetType, numberOfElements);
|
|
116
|
+
}
|
|
117
|
+
switch (classProperty.type) {
|
|
118
|
+
case 'SCALAR':
|
|
119
|
+
case 'VEC2':
|
|
120
|
+
case 'VEC3':
|
|
121
|
+
case 'VEC4':
|
|
122
|
+
case 'MAT2':
|
|
123
|
+
case 'MAT3':
|
|
124
|
+
case 'MAT4':
|
|
125
|
+
{
|
|
126
|
+
data = getPropertyDataNumeric(classProperty, numberOfElements, valuesDataBytes, arrayOffsets);
|
|
127
|
+
break;
|
|
128
|
+
}
|
|
129
|
+
case 'BOOLEAN':
|
|
130
|
+
{
|
|
131
|
+
throw new Error("Not implemented - classProperty.type=".concat(classProperty.type));
|
|
132
|
+
}
|
|
133
|
+
case 'STRING':
|
|
134
|
+
{
|
|
135
|
+
data = getPropertyDataString(classProperty, numberOfElements, valuesDataBytes, arrayOffsets, stringOffsets);
|
|
136
|
+
break;
|
|
137
|
+
}
|
|
138
|
+
case 'ENUM':
|
|
139
|
+
{
|
|
140
|
+
data = getPropertyDataENUM(schema, classProperty, numberOfElements, valuesDataBytes, arrayOffsets);
|
|
141
|
+
break;
|
|
142
|
+
}
|
|
143
|
+
default:
|
|
144
|
+
throw new Error("Unknown classProperty type ".concat(classProperty.type));
|
|
145
|
+
}
|
|
146
|
+
return data;
|
|
147
|
+
}
|
|
148
|
+
function getOffsetArray(scenegraph, offsets, offsetType, numberOfElements) {
|
|
149
|
+
const arrayOffsetsBufferView = offsets;
|
|
150
|
+
const arrayOffsetsBytes = scenegraph.getTypedArrayForBufferView(arrayOffsetsBufferView);
|
|
151
|
+
const arrayOffsets = convertRawBufferToMetadataArray(arrayOffsetsBytes, 'SCALAR', offsetType, numberOfElements + 1);
|
|
152
|
+
return arrayOffsets;
|
|
153
|
+
}
|
|
154
|
+
function getPropertyDataNumeric(classProperty, numberOfElements, valuesDataBytes, arrayOffsets) {
|
|
155
|
+
const isArray = classProperty.array;
|
|
156
|
+
const arrayCount = classProperty.count;
|
|
157
|
+
const elementSize = getArrayElementByteSize(classProperty.type, classProperty.componentType);
|
|
158
|
+
const elementCount = valuesDataBytes.byteLength / elementSize;
|
|
159
|
+
let valuesData;
|
|
160
|
+
if (classProperty.componentType) {
|
|
161
|
+
valuesData = convertRawBufferToMetadataArray(valuesDataBytes, classProperty.type, classProperty.componentType, elementCount);
|
|
162
|
+
} else {
|
|
163
|
+
valuesData = valuesDataBytes;
|
|
164
|
+
}
|
|
165
|
+
if (isArray) {
|
|
166
|
+
if (arrayOffsets) {
|
|
167
|
+
return handleVariableLengthArrayNumeric(valuesData, numberOfElements, arrayOffsets, valuesDataBytes.length, elementSize);
|
|
168
|
+
}
|
|
169
|
+
if (arrayCount) {
|
|
170
|
+
return handleFixedLengthArrayNumeric(valuesData, numberOfElements, arrayCount);
|
|
171
|
+
}
|
|
172
|
+
return [];
|
|
173
|
+
}
|
|
174
|
+
const attributeValueArray = [];
|
|
175
|
+
for (let index = 0; index < numberOfElements; index++) {
|
|
176
|
+
const value = valuesData[index];
|
|
177
|
+
attributeValueArray.push(value);
|
|
178
|
+
}
|
|
179
|
+
return attributeValueArray;
|
|
180
|
+
}
|
|
181
|
+
function handleVariableLengthArrayNumeric(valuesData, numberOfElements, arrayOffsets, valuesDataBytesLength, elementSize) {
|
|
182
|
+
const attributeValueArray = [];
|
|
183
|
+
for (let index = 0; index < numberOfElements; index++) {
|
|
184
|
+
const array = [];
|
|
185
|
+
const arrayOffset = arrayOffsets[index];
|
|
186
|
+
const arrayByteSize = arrayOffsets[index + 1] - arrayOffsets[index];
|
|
187
|
+
if (arrayByteSize + arrayOffset <= valuesDataBytesLength) {
|
|
188
|
+
const typedArrayOffset = arrayOffset / elementSize;
|
|
189
|
+
const elementCount = arrayByteSize / elementSize;
|
|
190
|
+
for (let i = 0; i < elementCount; i++) {
|
|
191
|
+
const value = valuesData[typedArrayOffset + i];
|
|
192
|
+
array.push(value);
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
attributeValueArray.push(array);
|
|
196
|
+
}
|
|
197
|
+
return attributeValueArray;
|
|
198
|
+
}
|
|
199
|
+
function handleFixedLengthArrayNumeric(valuesData, numberOfElements, arrayCount) {
|
|
200
|
+
const attributeValueArray = [];
|
|
201
|
+
for (let index = 0; index < numberOfElements; index++) {
|
|
202
|
+
const array = [];
|
|
203
|
+
for (let i = 0; i < arrayCount; i++) {
|
|
204
|
+
const value = valuesData[i];
|
|
205
|
+
array.push(value);
|
|
206
|
+
}
|
|
207
|
+
attributeValueArray.push(array);
|
|
208
|
+
}
|
|
209
|
+
return attributeValueArray;
|
|
210
|
+
}
|
|
211
|
+
function getPropertyDataString(classProperty, numberOfElements, valuesDataBytes, arrayOffsets, stringOffsets) {
|
|
212
|
+
if (arrayOffsets) {
|
|
213
|
+
throw new Error("Not implemented - classProperty.type=".concat(classProperty.type));
|
|
214
|
+
}
|
|
215
|
+
if (stringOffsets) {
|
|
216
|
+
const stringsArray = [];
|
|
217
|
+
const textDecoder = new TextDecoder('utf8');
|
|
218
|
+
let stringOffset = 0;
|
|
219
|
+
for (let index = 0; index < numberOfElements; index++) {
|
|
220
|
+
const stringByteSize = stringOffsets[index + 1] - stringOffsets[index];
|
|
221
|
+
if (stringByteSize + stringOffset <= valuesDataBytes.length) {
|
|
222
|
+
const stringData = valuesDataBytes.subarray(stringOffset, stringByteSize + stringOffset);
|
|
223
|
+
const stringAttribute = textDecoder.decode(stringData);
|
|
224
|
+
stringsArray.push(stringAttribute);
|
|
225
|
+
stringOffset += stringByteSize;
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
return stringsArray;
|
|
229
|
+
}
|
|
230
|
+
return [];
|
|
231
|
+
}
|
|
232
|
+
function getPropertyDataENUM(schema, classProperty, numberOfElements, valuesDataBytes, arrayOffsets) {
|
|
233
|
+
var _schema$enums;
|
|
234
|
+
const data = [];
|
|
235
|
+
const isArray = classProperty.array;
|
|
236
|
+
const arrayCount = classProperty.count;
|
|
237
|
+
const enumType = classProperty.enumType;
|
|
238
|
+
if (!enumType) {
|
|
239
|
+
throw new Error('Incorrect data in the EXT_structural_metadata extension: classProperty.enumType is not set for type ENUM');
|
|
240
|
+
}
|
|
241
|
+
const enumEntry = (_schema$enums = schema.enums) === null || _schema$enums === void 0 ? void 0 : _schema$enums[enumType];
|
|
242
|
+
if (!enumEntry) {
|
|
243
|
+
throw new Error("Incorrect data in the EXT_structural_metadata extension: schema.enums does't contain ".concat(enumType));
|
|
244
|
+
}
|
|
245
|
+
const enumValueType = enumEntry.valueType || 'UINT16';
|
|
246
|
+
const elementSize = getArrayElementByteSize(classProperty.type, enumValueType);
|
|
247
|
+
const elementCount = valuesDataBytes.byteLength / elementSize;
|
|
248
|
+
const valuesData = convertRawBufferToMetadataArray(valuesDataBytes, classProperty.type, enumValueType, elementCount);
|
|
249
|
+
if (isArray) {
|
|
250
|
+
if (arrayOffsets) {
|
|
251
|
+
return handleVariableLengthArrayENUM(valuesData, numberOfElements, arrayOffsets, valuesDataBytes.length, elementSize, enumEntry);
|
|
252
|
+
}
|
|
253
|
+
if (arrayCount) {
|
|
254
|
+
return handleFixedLengthArrayENUM(valuesData, numberOfElements, arrayCount, enumEntry);
|
|
255
|
+
}
|
|
256
|
+
return [];
|
|
257
|
+
}
|
|
258
|
+
for (let index = 0; index < numberOfElements; index++) {
|
|
259
|
+
const enumValue = valuesData[index];
|
|
260
|
+
const enumObject = getEnumByValue(enumEntry, enumValue);
|
|
261
|
+
if (enumObject) {
|
|
262
|
+
data.push(enumObject.name);
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
return data;
|
|
266
|
+
}
|
|
267
|
+
function handleVariableLengthArrayENUM(valuesData, numberOfElements, arrayOffsets, valuesDataBytesLength, elementSize, enumEntry) {
|
|
268
|
+
const attributeValueArray = [];
|
|
269
|
+
for (let index = 0; index < numberOfElements; index++) {
|
|
270
|
+
const array = [];
|
|
271
|
+
const arrayOffset = arrayOffsets[index];
|
|
272
|
+
const arrayByteSize = arrayOffsets[index + 1] - arrayOffsets[index];
|
|
273
|
+
if (arrayByteSize + arrayOffset <= valuesDataBytesLength) {
|
|
274
|
+
const typedArrayOffset = arrayOffset / elementSize;
|
|
275
|
+
const elementCount = arrayByteSize / elementSize;
|
|
276
|
+
for (let i = 0; i < elementCount; i++) {
|
|
277
|
+
const value = valuesData[typedArrayOffset + i];
|
|
278
|
+
const enumObject = getEnumByValue(enumEntry, value);
|
|
279
|
+
if (enumObject) {
|
|
280
|
+
array.push(enumObject.name);
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
attributeValueArray.push(array);
|
|
285
|
+
}
|
|
286
|
+
return attributeValueArray;
|
|
287
|
+
}
|
|
288
|
+
function handleFixedLengthArrayENUM(valuesData, numberOfElements, arrayCount, enumEntry) {
|
|
289
|
+
const attributeValueArray = [];
|
|
290
|
+
for (let index = 0; index < numberOfElements; index++) {
|
|
291
|
+
const array = [];
|
|
292
|
+
for (let i = 0; i < arrayCount; i++) {
|
|
293
|
+
const value = valuesData[i];
|
|
294
|
+
const enumObject = getEnumByValue(enumEntry, value);
|
|
295
|
+
if (enumObject) {
|
|
296
|
+
array.push(enumObject.name);
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
attributeValueArray.push(array);
|
|
300
|
+
}
|
|
301
|
+
return attributeValueArray;
|
|
302
|
+
}
|
|
303
|
+
function findPropertyTableByClass(propertyTables, schemaClassName) {
|
|
304
|
+
for (let i = 0, len = propertyTables.length; i < len; i++) {
|
|
305
|
+
const propertyTable = propertyTables[i];
|
|
306
|
+
if (propertyTable.class === schemaClassName) {
|
|
307
|
+
return propertyTable;
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
return null;
|
|
311
|
+
}
|
|
312
|
+
function getEnumByValue(enumEntry, value) {
|
|
313
|
+
for (const enumValue of enumEntry.values) {
|
|
314
|
+
if (enumValue.value === value) {
|
|
315
|
+
return enumValue;
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
return null;
|
|
319
|
+
}
|
|
320
|
+
//# sourceMappingURL=EXT_structural_metadata.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"EXT_structural_metadata.js","names":["GLTFScenegraph","convertRawBufferToMetadataArray","getPrimitiveTextureData","primitivePropertyDataToAttributes","getArrayElementByteSize","EXT_STRUCTURAL_METADATA_NAME","name","decode","gltfData","options","scenegraph","decodeExtStructuralMetadata","getPropertyTablePopulated","propertyTableIndex","_extension$propertyTa","extension","getExtension","propertyTable","propertyTables","schema","processPropertyTable","Error","concat","_options$gltf","propertyTextures","json","gltf","meshes","loadImages","mesh","primitive","primitives","processPrimitivePropertyTextures","schemaClasses","classes","schemaName","findPropertyTableByClass","_primitive$extensions","primitiveExtension","extensions","primitivePropertyTextureIndices","primitivePropertyTextureIndex","propertyTexture","processPrimitivePropertyTexture","properties","dataAttributeNames","className","class","propName","_propertyTexture$prop","attributeName","textureInfoTopLevel","data","featureTextureTable","propertyData","push","_schema$classes","schemaClass","numberOfElements","count","propertyName","_propertyTable$proper","classProperty","propertyTableProperty","getPropertyDataFromBinarySource","valuesBufferView","values","valuesDataBytes","getTypedArrayForBufferView","arrayOffsets","array","arrayOffsetType","getOffsetArray","stringOffsets","stringOffsetType","type","getPropertyDataNumeric","getPropertyDataString","getPropertyDataENUM","offsets","offsetType","arrayOffsetsBufferView","arrayOffsetsBytes","isArray","arrayCount","elementSize","componentType","elementCount","byteLength","valuesData","handleVariableLengthArrayNumeric","length","handleFixedLengthArrayNumeric","attributeValueArray","index","value","valuesDataBytesLength","arrayOffset","arrayByteSize","typedArrayOffset","i","stringsArray","textDecoder","TextDecoder","stringOffset","stringByteSize","stringData","subarray","stringAttribute","_schema$enums","enumType","enumEntry","enums","enumValueType","valueType","handleVariableLengthArrayENUM","handleFixedLengthArrayENUM","enumValue","enumObject","getEnumByValue","schemaClassName","len"],"sources":["../../../../src/lib/extensions/EXT_structural_metadata.ts"],"sourcesContent":["/* eslint-disable camelcase */\nimport type {GLTF, GLTFTextureInfoMetadata, GLTFMeshPrimitive} from '../types/gltf-json-schema';\nimport type {\n GLTF_EXT_structural_metadata_Schema,\n GLTF_EXT_structural_metadata_ClassProperty,\n GLTF_EXT_structural_metadata_Enum,\n GLTF_EXT_structural_metadata_EnumValue,\n GLTF_EXT_structural_metadata_PropertyTable,\n GLTF_EXT_structural_metadata,\n GLTF_EXT_structural_metadata_PropertyTexture,\n GLTF_EXT_structural_metadata_PropertyTable_Property,\n GLTF_EXT_structural_metadata_Primitive\n} from '../types/gltf-ext-structural-metadata-schema';\n\nimport type {TypedArray} from '@loaders.gl/schema';\nimport type {GLTFLoaderOptions} from '../../gltf-loader';\n\nimport {GLTFScenegraph} from '../api/gltf-scenegraph';\nimport {\n convertRawBufferToMetadataArray,\n getPrimitiveTextureData,\n primitivePropertyDataToAttributes,\n getArrayElementByteSize\n} from './data-processing';\n\nconst EXT_STRUCTURAL_METADATA_NAME = 'EXT_structural_metadata';\nexport const name = EXT_STRUCTURAL_METADATA_NAME;\n\nexport async function decode(gltfData: {json: GLTF}, options: GLTFLoaderOptions): Promise<void> {\n const scenegraph = new GLTFScenegraph(gltfData);\n decodeExtStructuralMetadata(scenegraph, options);\n}\n\n/*\n// Example of the extension.\n// See more info at https://github.com/CesiumGS/glTF/tree/3d-tiles-next/extensions/2.0/Vendor/EXT_structural_metadata\nconst extensions = {\n \"extensions\": {\n \"EXT_structural_metadata\": {\n \"schema\": {\n \"classes\": {\n \"tree\": {\n \"name\": \"Tree\",\n \"description\": \"Woody, perennial plant.\",\n \"properties\": {\n \"species\": {\n \"description\": \"Type of tree.\",\n \"type\": \"ENUM\",\n \"enumType\": \"speciesEnum\",\n \"required\": true\n },\n \"age\": {\n \"description\": \"The age of the tree, in years\",\n \"type\": \"SCALAR\",\n \"componentType\": \"UINT8\",\n \"required\": true\n }\n }\n }\n },\n \"enums\": {\n \"speciesEnum\": {\n \"name\": \"Species\",\n \"description\": \"An example enum for tree species.\",\n // valueType is not defined here. Default is \"UINT16\"\n \"values\": [\n { \"name\": \"Unspecified\", \"value\": 0 },\n { \"name\": \"Oak\", \"value\": 1 }\n ]\n }\n }\n },\n \"propertyTables\": [{\n \"name\": \"tree_survey_2021-09-29\",\n \"class\": \"tree\",\n \"count\": 10, // The number of elements in each property array (in `species`, in `age`).\n \"properties\": {\n \"species\": {\n \"values\": 0, // It's an index of the buffer view containing property values.\n },\n \"age\": {\n \"values\": 1\n }\n }\n }]\n }\n }\n}\n*/\n\n/**\n * Returns the property table populated with the data taken according to the extension schema.\n * @param {GLTFScenegraph} scenegraph - Instance of the class for structured access to GLTF data.\n * @param {number} propertyTableIndex - Index of the property table to locate.\n * @returns {GLTF_EXT_structural_metadata_PropertyTable} Property table populated with the data.\n * Throws an exception if no property table was found for propertyTableIndex provided.\n */\nexport function getPropertyTablePopulated(\n scenegraph: GLTFScenegraph,\n propertyTableIndex: number\n): GLTF_EXT_structural_metadata_PropertyTable {\n const extension: GLTF_EXT_structural_metadata | null = scenegraph.getExtension(\n EXT_STRUCTURAL_METADATA_NAME\n );\n const propertyTable = extension?.propertyTables?.[propertyTableIndex];\n if (extension?.schema && propertyTable) {\n processPropertyTable(scenegraph, extension.schema, propertyTable);\n return propertyTable;\n }\n throw new Error(\n `Incorrect data in the EXT_structural_metadata extension: no property table with index ${propertyTableIndex}`\n );\n}\n\n/**\n * Decodes feature metadata from extension\n * @param {GLTFScenegraph} scenegraph - Instance of the class for structured access to GLTF data.\n * @param {GLTFLoaderOptions} options - loader options.\n */\nfunction decodeExtStructuralMetadata(scenegraph: GLTFScenegraph, options: GLTFLoaderOptions): void {\n const extension: GLTF_EXT_structural_metadata | null = scenegraph.getExtension(\n EXT_STRUCTURAL_METADATA_NAME\n );\n if (!extension?.schema) {\n return;\n }\n\n const propertyTextures = extension.propertyTextures;\n const json = scenegraph.gltf.json;\n if (propertyTextures && json.meshes && options?.gltf?.loadImages) {\n // Iterate through all meshes/primitives.\n for (const mesh of json.meshes) {\n for (const primitive of mesh.primitives) {\n processPrimitivePropertyTextures(scenegraph, propertyTextures, primitive, extension);\n }\n }\n }\n\n const schemaClasses = extension.schema.classes;\n const propertyTables = extension.propertyTables;\n if (schemaClasses && propertyTables) {\n for (const schemaName in schemaClasses) {\n const propertyTable = findPropertyTableByClass(propertyTables, schemaName);\n if (propertyTable) {\n processPropertyTable(scenegraph, extension.schema, propertyTable);\n }\n }\n }\n}\n\n/**\n * Takes data from property textures reffered by the primitive\n * @param {GLTFScenegraph} scenegraph - Instance of the class for structured access to GLTF data.\n * @param {GLTF_EXT_structural_metadata_PropertyTexture[]} propertyTextures - propertyTexture definition taken from the top-level extention\n * @param {GLTFMeshPrimitive} primitive - Primitive object\n * @param {GLTF_EXT_structural_metadata} extension - top-level extension\n */\nfunction processPrimitivePropertyTextures(\n scenegraph: GLTFScenegraph,\n propertyTextures: GLTF_EXT_structural_metadata_PropertyTexture[],\n primitive: GLTFMeshPrimitive,\n extension: GLTF_EXT_structural_metadata\n): void {\n if (!propertyTextures) {\n return;\n }\n const primitiveExtension: GLTF_EXT_structural_metadata_Primitive = primitive.extensions?.[\n EXT_STRUCTURAL_METADATA_NAME\n ] as GLTF_EXT_structural_metadata_Primitive;\n const primitivePropertyTextureIndices = primitiveExtension?.propertyTextures;\n if (!primitivePropertyTextureIndices) {\n return;\n }\n\n for (const primitivePropertyTextureIndex of primitivePropertyTextureIndices) {\n const propertyTexture = propertyTextures[primitivePropertyTextureIndex];\n processPrimitivePropertyTexture(scenegraph, propertyTexture, primitive, extension);\n }\n}\n\n/**\n * Takes property data from the texture pointed by the primitive and appends them to `exension.data`\n * @param {GLTFScenegraph} scenegraph - Instance of the class for structured access to GLTF data.\n * @param {GLTF_EXT_structural_metadata_PropertyTexture} propertyTexture - propertyTexture definition taken from the top-level extension.\n * @param {GLTFMeshPrimitive} primitive - Primitive object\n * @param {GLTF_EXT_structural_metadata} extension - top-level extension\n */\nfunction processPrimitivePropertyTexture(\n scenegraph: GLTFScenegraph,\n propertyTexture: GLTF_EXT_structural_metadata_PropertyTexture,\n primitive: GLTFMeshPrimitive,\n extension: GLTF_EXT_structural_metadata\n): void {\n if (!propertyTexture.properties) {\n return;\n }\n\n if (!extension.dataAttributeNames) {\n extension.dataAttributeNames = [];\n }\n\n /* Iterate through all properties defined in propertyTexture, e.g. \"speed\" and \"direction\":\n {\n \"class\": \"wind\",\n \"properties\": {\n \"speed\": {\n \"index\": 0,\n \"texCoord\": 0,\n \"channels\": [0]\n },\n \"direction\": {\n \"index\": 0,\n \"texCoord\": 0,\n \"channels\": [1, 2]\n }\n }\n }\n */\n const className = propertyTexture.class;\n for (const propName in propertyTexture.properties) {\n // propName has values like \"speed\", \"direction\"\n // Make attributeName as a combination of the class name and the propertyName like \"wind_speed\" or \"wind_direction\"\n const attributeName = `${className}_${propName}`;\n const textureInfoTopLevel: GLTFTextureInfoMetadata | undefined =\n propertyTexture.properties?.[propName];\n if (!textureInfoTopLevel) {\n // eslint-disable-next-line no-continue\n continue;\n }\n\n // The data taken from all meshes/primitives (the same property, e.g. \"speed\" or \"direction\") will be combined into one array and saved in textureInfoTopLevel.data\n // Initially textureInfoTopLevel.data will be initialized with an empty array.\n if (!textureInfoTopLevel.data) {\n textureInfoTopLevel.data = [];\n }\n const featureTextureTable: number[] = textureInfoTopLevel.data as number[];\n\n const propertyData: number[] | null = getPrimitiveTextureData(\n scenegraph,\n textureInfoTopLevel,\n primitive\n );\n if (propertyData === null) {\n // eslint-disable-next-line no-continue\n continue;\n }\n primitivePropertyDataToAttributes(\n scenegraph,\n attributeName,\n propertyData,\n featureTextureTable,\n primitive\n );\n textureInfoTopLevel.data = featureTextureTable;\n extension.dataAttributeNames.push(attributeName);\n }\n}\n\n/**\n * Navigates through all properies in the property table, gets properties data,\n * and put the data to `propertyTable.data` as an array.\n * @param {GLTFScenegraph} scenegraph - Instance of the class for structured access to GLTF data.\n * @param {GLTF_EXT_structural_metadata_Schema} schema - schema object\n * @param {GLTF_EXT_structural_metadata_PropertyTable} propertyTable - propertyTable definition taken from the top-level extension\n */\nfunction processPropertyTable(\n scenegraph: GLTFScenegraph,\n schema: GLTF_EXT_structural_metadata_Schema,\n propertyTable: GLTF_EXT_structural_metadata_PropertyTable\n): void {\n const schemaClass = schema.classes?.[propertyTable.class];\n if (!schemaClass) {\n throw new Error(\n `Incorrect data in the EXT_structural_metadata extension: no schema class with name ${propertyTable.class}`\n );\n }\n\n const numberOfElements = propertyTable.count; // `propertyTable.count` is a number of elements in each property array.\n\n for (const propertyName in schemaClass.properties) {\n const classProperty = schemaClass.properties[propertyName];\n const propertyTableProperty: GLTF_EXT_structural_metadata_PropertyTable_Property | undefined =\n propertyTable.properties?.[propertyName];\n\n if (propertyTableProperty) {\n // Getting all elements (`numberOfElements`) of the array in the `propertyTableProperty`\n const data = getPropertyDataFromBinarySource(\n scenegraph,\n schema,\n classProperty,\n numberOfElements,\n propertyTableProperty\n );\n propertyTableProperty.data = data;\n }\n }\n}\n\n/**\n * Decodes properties from binary sourse based on property type.\n * @param {GLTFScenegraph} scenegraph - Instance of the class for structured access to GLTF data.\n * @param {GLTF_EXT_structural_metadata_Schema} schema - Schema object\n * @param {GLTF_EXT_structural_metadata_ClassProperty} classProperty - class property object\n * @param {GLTF_EXT_structural_metadata_PropertyTable_Property} propertyTableProperty\n * @param {number} numberOfElements - The number of elements in each property array that propertyTableProperty contains. It's a number of rows in the table.\n * @returns {string[] | number[] | string[][] | number[][]}\n */\n/* eslint complexity: [\"error\", 17]*/\nfunction getPropertyDataFromBinarySource(\n scenegraph: GLTFScenegraph,\n schema: GLTF_EXT_structural_metadata_Schema,\n classProperty: GLTF_EXT_structural_metadata_ClassProperty,\n numberOfElements: number,\n propertyTableProperty: GLTF_EXT_structural_metadata_PropertyTable_Property\n): string[] | number[] | string[][] | number[][] {\n let data: string[] | number[] | string[][] | number[][] = [];\n const valuesBufferView = propertyTableProperty.values;\n const valuesDataBytes: Uint8Array = scenegraph.getTypedArrayForBufferView(valuesBufferView);\n\n let arrayOffsets: TypedArray | null = null;\n if (\n classProperty.array &&\n // `count` is a number of array elements. May only be defined when `array` is true.\n typeof classProperty.count === 'undefined' && // If `count` is NOT defined, it's a VARIABLE-length array\n typeof propertyTableProperty.arrayOffsets !== 'undefined' && // `arrayOffsets` is an index of the buffer view containing offsets for variable-length arrays.\n typeof propertyTableProperty.arrayOffsetType !== 'undefined'\n ) {\n // Data are in a VARIABLE-length array\n arrayOffsets = getOffsetArray(\n scenegraph,\n propertyTableProperty.arrayOffsets,\n propertyTableProperty.arrayOffsetType,\n numberOfElements\n );\n }\n\n let stringOffsets: TypedArray | null = null;\n if (\n typeof propertyTableProperty.stringOffsets !== 'undefined' && // `stringOffsets` is an index of the buffer view containing offsets for strings.\n typeof propertyTableProperty.stringOffsetType !== 'undefined'\n ) {\n // Data are in a FIXED-length array\n stringOffsets = getOffsetArray(\n scenegraph,\n propertyTableProperty.stringOffsets,\n propertyTableProperty.stringOffsetType,\n numberOfElements\n );\n }\n\n switch (classProperty.type) {\n case 'SCALAR':\n case 'VEC2':\n case 'VEC3':\n case 'VEC4':\n case 'MAT2':\n case 'MAT3':\n case 'MAT4': {\n data = getPropertyDataNumeric(classProperty, numberOfElements, valuesDataBytes, arrayOffsets);\n break;\n }\n case 'BOOLEAN': {\n // TODO: implement it as soon as we have the corresponding tileset\n throw new Error(`Not implemented - classProperty.type=${classProperty.type}`);\n }\n case 'STRING': {\n data = getPropertyDataString(\n classProperty,\n numberOfElements,\n valuesDataBytes,\n arrayOffsets,\n stringOffsets\n );\n break;\n }\n case 'ENUM': {\n data = getPropertyDataENUM(\n schema,\n classProperty,\n numberOfElements,\n valuesDataBytes,\n arrayOffsets\n );\n break;\n }\n default:\n throw new Error(`Unknown classProperty type ${classProperty.type}`);\n }\n\n return data;\n}\n\n/**\n * Gets offset array from `arrayOffsets` or `stringOffsets`.\n * @param {GLTFScenegraph} scenegraph - Instance of the class for structured access to GLTF data.\n * @param {number} offsets - Buffer view index\n * @param offsetType - The type of values in `arrayOffsets` or `stringOffsets`.\n * @param {number} numberOfElements - The number of elements in each property array.\n * @returns {TypedArray}\n */\nfunction getOffsetArray(\n scenegraph: GLTFScenegraph,\n offsets: number,\n offsetType: 'UINT8' | 'UINT16' | 'UINT32' | 'UINT64',\n numberOfElements: number\n): TypedArray {\n const arrayOffsetsBufferView = offsets;\n const arrayOffsetsBytes = scenegraph.getTypedArrayForBufferView(arrayOffsetsBufferView);\n\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 return arrayOffsets;\n}\n\n/**\n * Decodes properties of SCALAR, VEC-N, MAT-N types from binary sourse.\n * @param {GLTF_EXT_structural_metadata_ClassProperty} classProperty - class property object\n * @param {number} numberOfElements - The number of elements in each property array that propertyTableProperty contains. It's a number of rows in the table.\n * @param {Uint8Array} valuesDataBytes - data taken from values property of the property table property.\n * @param {TypedArray | null} arrayOffsets - offsets for variable-length arrays. It's null for fixed-length arrays or scalar types.\n * @returns {number[] | number[][]}\n */\nfunction getPropertyDataNumeric(\n classProperty: GLTF_EXT_structural_metadata_ClassProperty,\n numberOfElements: number,\n valuesDataBytes: Uint8Array,\n arrayOffsets: TypedArray | null\n): number[] | number[][] {\n const isArray = classProperty.array;\n const arrayCount = classProperty.count;\n\n const elementSize = getArrayElementByteSize(classProperty.type, classProperty.componentType);\n const elementCount = valuesDataBytes.byteLength / elementSize;\n\n let valuesData: TypedArray;\n if (classProperty.componentType) {\n valuesData = convertRawBufferToMetadataArray(\n valuesDataBytes,\n classProperty.type,\n classProperty.componentType, // The datatype of the element's components. Only applicable to `SCALAR`, `VECN`, and `MATN` types.\n elementCount\n );\n } else {\n // The spec doesn't provide any info what to do if componentType is not set.\n valuesData = valuesDataBytes;\n }\n\n if (isArray) {\n if (arrayOffsets) {\n // VARIABLE-length array\n return handleVariableLengthArrayNumeric(\n valuesData,\n numberOfElements,\n arrayOffsets,\n valuesDataBytes.length,\n elementSize\n );\n }\n if (arrayCount) {\n // FIXED-length array\n return handleFixedLengthArrayNumeric(valuesData, numberOfElements, arrayCount);\n }\n return [];\n }\n\n // Single value (not an array)\n const attributeValueArray: number[] = [];\n for (let index = 0; index < numberOfElements; index++) {\n const value = valuesData[index];\n attributeValueArray.push(value);\n }\n return attributeValueArray;\n}\n\nfunction handleVariableLengthArrayNumeric(\n valuesData: TypedArray,\n numberOfElements: number,\n arrayOffsets: TypedArray,\n valuesDataBytesLength: number,\n elementSize: number\n) {\n const attributeValueArray: number[][] = [];\n for (let index = 0; index < numberOfElements; index++) {\n const array: number[] = [];\n const arrayOffset = arrayOffsets[index];\n const arrayByteSize = arrayOffsets[index + 1] - arrayOffsets[index];\n if (arrayByteSize + arrayOffset <= valuesDataBytesLength) {\n const typedArrayOffset = arrayOffset / elementSize;\n const elementCount = arrayByteSize / elementSize;\n for (let i = 0; i < elementCount; i++) {\n const value = valuesData[typedArrayOffset + i];\n array.push(value);\n }\n }\n attributeValueArray.push(array);\n }\n return attributeValueArray;\n}\n\nfunction handleFixedLengthArrayNumeric(\n valuesData: TypedArray,\n numberOfElements: number,\n arrayCount: number\n) {\n const attributeValueArray: number[][] = [];\n for (let index = 0; index < numberOfElements; index++) {\n const array: number[] = [];\n for (let i = 0; i < arrayCount; i++) {\n const value = valuesData[i];\n array.push(value);\n }\n attributeValueArray.push(array);\n }\n return attributeValueArray;\n}\n\n/**\n * Decodes properties of string type from binary sourse.\n * @param {GLTF_EXT_structural_metadata_ClassProperty} classProperty - class property object\n * @param {number} numberOfElements - The number of elements in each property array that propertyTableProperty contains. It's a number of rows in the table.\n * @param {Uint8Array} valuesDataBytes - data taken from values property of the property table property.\n * @param {TypedArray | null} arrayOffsets - offsets for variable-length arrays. It's null for fixed-length arrays or scalar types.\n * @param {TypedArray | null} stringOffsets - index of the buffer view containing offsets for strings. It should be available for string type.\n * @returns {string[] | string[][]}\n */\nfunction getPropertyDataString(\n classProperty: GLTF_EXT_structural_metadata_ClassProperty,\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 - classProperty.type=${classProperty.type}`);\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\n/**\n * Decodes properties of enum type from binary sourse.\n * @param {GLTF_EXT_structural_metadata_Schema} schema - schema object\n * @param {GLTF_EXT_structural_metadata_ClassProperty} classProperty - class property object\n * @param {number} numberOfElements - The number of elements in each property array that propertyTableProperty contains. It's a number of rows in the table.\n * @param {Uint8Array} valuesDataBytes - data taken from values property of the property table property.\n * @param {TypedArray | null} arrayOffsets - offsets for variable-length arrays. It's null for fixed-length arrays or scalar types.\n * @returns {string[] | string[][]}\n */\nfunction getPropertyDataENUM(\n schema: GLTF_EXT_structural_metadata_Schema,\n classProperty: GLTF_EXT_structural_metadata_ClassProperty,\n numberOfElements: number,\n valuesDataBytes: Uint8Array,\n arrayOffsets: TypedArray | null\n): string[] | string[][] {\n const data: string[] = [];\n\n const isArray = classProperty.array;\n const arrayCount = classProperty.count;\n\n const enumType = classProperty.enumType;\n // Enum ID as declared in the `enums` dictionary. Required when `type` is `ENUM`.\n if (!enumType) {\n throw new Error(\n 'Incorrect data in the EXT_structural_metadata extension: classProperty.enumType is not set for type ENUM'\n );\n }\n\n const enumEntry: GLTF_EXT_structural_metadata_Enum | undefined = schema.enums?.[enumType];\n if (!enumEntry) {\n throw new Error(\n `Incorrect data in the EXT_structural_metadata extension: schema.enums does't contain ${enumType}`\n );\n }\n\n const enumValueType = enumEntry.valueType || 'UINT16';\n const elementSize = getArrayElementByteSize(classProperty.type, enumValueType);\n const elementCount = valuesDataBytes.byteLength / elementSize;\n const valuesData: TypedArray = convertRawBufferToMetadataArray(\n valuesDataBytes,\n classProperty.type,\n enumValueType,\n elementCount\n );\n\n if (isArray) {\n if (arrayOffsets) {\n // VARIABLE-length array\n return handleVariableLengthArrayENUM(\n valuesData,\n numberOfElements,\n arrayOffsets,\n valuesDataBytes.length,\n elementSize,\n enumEntry\n );\n }\n if (arrayCount) {\n // FIXED-length array\n return handleFixedLengthArrayENUM(valuesData, numberOfElements, arrayCount, enumEntry);\n }\n return [];\n }\n\n // Single value (not an array)\n for (let index = 0; index < numberOfElements; index++) {\n const enumValue = valuesData[index];\n const enumObject = getEnumByValue(enumEntry, enumValue);\n if (enumObject) {\n data.push(enumObject.name);\n }\n }\n\n return data;\n}\n\n/* eslint max-params: [\"error\", 6]*/\nfunction handleVariableLengthArrayENUM(\n valuesData: TypedArray,\n numberOfElements: number,\n arrayOffsets: TypedArray,\n valuesDataBytesLength: number,\n elementSize: number,\n enumEntry: GLTF_EXT_structural_metadata_Enum\n) {\n const attributeValueArray: string[][] = [];\n for (let index = 0; index < numberOfElements; index++) {\n const array: string[] = [];\n const arrayOffset = arrayOffsets[index];\n const arrayByteSize = arrayOffsets[index + 1] - arrayOffsets[index];\n if (arrayByteSize + arrayOffset <= valuesDataBytesLength) {\n const typedArrayOffset = arrayOffset / elementSize;\n const elementCount = arrayByteSize / elementSize;\n for (let i = 0; i < elementCount; i++) {\n const value = valuesData[typedArrayOffset + i];\n\n const enumObject = getEnumByValue(enumEntry, value);\n if (enumObject) {\n array.push(enumObject.name);\n }\n }\n }\n attributeValueArray.push(array);\n }\n return attributeValueArray;\n}\n\nfunction handleFixedLengthArrayENUM(\n valuesData: TypedArray,\n numberOfElements: number,\n arrayCount: number,\n enumEntry: GLTF_EXT_structural_metadata_Enum\n) {\n const attributeValueArray: string[][] = [];\n for (let index = 0; index < numberOfElements; index++) {\n const array: string[] = [];\n for (let i = 0; i < arrayCount; i++) {\n const value = valuesData[i];\n\n const enumObject = getEnumByValue(enumEntry, value);\n if (enumObject) {\n array.push(enumObject.name);\n }\n }\n attributeValueArray.push(array);\n }\n return attributeValueArray;\n}\n/**\n * Find the property table by class name.\n * @param {GLTF_EXT_structural_metadata_PropertyTable[]} propertyTables\n * @param {string} schemaClassName\n */\nfunction findPropertyTableByClass(\n propertyTables: GLTF_EXT_structural_metadata_PropertyTable[],\n schemaClassName: string\n): GLTF_EXT_structural_metadata_PropertyTable | null {\n for (let i = 0, len = propertyTables.length; i < len; i++) {\n const propertyTable = propertyTables[i];\n\n if (propertyTable.class === schemaClassName) {\n return propertyTable;\n }\n }\n\n return null;\n}\n\n/**\n * Looks up ENUM whose `value` property matches the specified number in the parameter `value`.\n * @param {GLTF_EXT_structural_metadata_Enum} enumEntry - ENUM entry containing the array of possible enums.\n * @param {number} value - the value of the ENUM to locate.\n * @returns {GLTF_EXT_structural_metadata_EnumValue | null} ENUM matcihng the specified value or null of no ENUM object was found.\n */\nfunction getEnumByValue(\n enumEntry: GLTF_EXT_structural_metadata_Enum,\n value: number\n): GLTF_EXT_structural_metadata_EnumValue | null {\n for (const enumValue of enumEntry.values) {\n if (enumValue.value === value) {\n return enumValue;\n }\n }\n\n return null;\n}\n"],"mappings":"AAiBA,SAAQA,cAAc,QAAO,wBAAwB;AACrD,SACEC,+BAA+B,EAC/BC,uBAAuB,EACvBC,iCAAiC,EACjCC,uBAAuB,QAClB,mBAAmB;AAE1B,MAAMC,4BAA4B,GAAG,yBAAyB;AAC9D,OAAO,MAAMC,IAAI,GAAGD,4BAA4B;AAEhD,OAAO,eAAeE,MAAMA,CAACC,QAAsB,EAAEC,OAA0B,EAAiB;EAC9F,MAAMC,UAAU,GAAG,IAAIV,cAAc,CAACQ,QAAQ,CAAC;EAC/CG,2BAA2B,CAACD,UAAU,EAAED,OAAO,CAAC;AAClD;AAkEA,OAAO,SAASG,yBAAyBA,CACvCF,UAA0B,EAC1BG,kBAA0B,EACkB;EAAA,IAAAC,qBAAA;EAC5C,MAAMC,SAA8C,GAAGL,UAAU,CAACM,YAAY,CAC5EX,4BACF,CA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UAAU,CAACW,CAAC,CAAC;MAE3B,MAAMkB,UAAU,GAAGC,cAAc,CAACR,SAAS,EAAEhB,KAAK,CAAC;MACnD,IAAIuB,UAAU,EAAE;QACdhD,KAAK,CAACf,IAAI,CAAC+D,UAAU,CAAChH,IAAI,CAAC;MAC7B;IACF;IACAuF,mBAAmB,CAACtC,IAAI,CAACe,KAAK,CAAC;EACjC;EACA,OAAOuB,mBAAmB;AAC5B;AAMA,SAASzD,wBAAwBA,CAC/BlB,cAA4D,EAC5DsG,eAAuB,EAC4B;EACnD,KAAK,IAAIpB,CAAC,GAAG,CAAC,EAAEqB,GAAG,GAAGvG,cAAc,CAACyE,MAAM,EAAES,CAAC,GAAGqB,GAAG,EAAErB,CAAC,EAAE,EAAE;IACzD,MAAMnF,aAAa,GAAGC,cAAc,CAACkF,CAAC,CAAC;IAEvC,IAAInF,aAAa,CAAC8B,KAAK,KAAKyE,eAAe,EAAE;MAC3C,OAAOvG,aAAa;IACtB;EACF;EAEA,OAAO,IAAI;AACb;AAQA,SAASsG,cAAcA,CACrBR,SAA4C,EAC5ChB,KAAa,EACkC;EAC/C,KAAK,MAAMsB,SAAS,IAAIN,SAAS,CAAC7C,MAAM,EAAE;IACxC,IAAImD,SAAS,CAACtB,KAAK,KAAKA,KAAK,EAAE;MAC7B,OAAOsB,SAAS;IAClB;EACF;EAEA,OAAO,IAAI;AACb"}
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import { getComponentTypeFromArray } 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 convertRawBufferToMetadataArray(typedArray, attributeType, componentType) {
|
|
44
|
+
let elementCount = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 1;
|
|
45
|
+
const numberOfComponents = ATTRIBUTE_TYPE_TO_COMPONENTS[attributeType];
|
|
46
|
+
const ArrayType = ATTRIBUTE_COMPONENT_TYPE_TO_ARRAY[componentType];
|
|
47
|
+
const length = elementCount * numberOfComponents;
|
|
48
|
+
const size = ATTRIBUTE_COMPONENT_TYPE_TO_BYTE_SIZE[componentType];
|
|
49
|
+
const offset = typedArray.byteOffset % size ? Math.ceil(typedArray.byteOffset / size) * size : typedArray.byteOffset;
|
|
50
|
+
return new ArrayType(typedArray.buffer, offset, length);
|
|
51
|
+
}
|
|
52
|
+
export function getPrimitiveTextureData(scenegraph, textureInfo, primitive) {
|
|
53
|
+
var _json$textures, _json$textures$textur;
|
|
54
|
+
const json = scenegraph.gltf.json;
|
|
55
|
+
const texCoordAccessorKey = "TEXCOORD_".concat(textureInfo.texCoord || 0);
|
|
56
|
+
const texCoordAccessorIndex = primitive.attributes[texCoordAccessorKey];
|
|
57
|
+
const texCoordBufferView = scenegraph.getBufferView(texCoordAccessorIndex);
|
|
58
|
+
const texCoordArray = scenegraph.getTypedArrayForBufferView(texCoordBufferView);
|
|
59
|
+
const textureCoordinates = new Float32Array(texCoordArray.buffer, texCoordArray.byteOffset, texCoordArray.length / 4);
|
|
60
|
+
const textureIndex = textureInfo.index;
|
|
61
|
+
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;
|
|
62
|
+
if (typeof imageIndex !== 'undefined') {
|
|
63
|
+
var _json$images, _json$images$imageInd, _scenegraph$gltf$imag;
|
|
64
|
+
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;
|
|
65
|
+
const parsedImage = (_scenegraph$gltf$imag = scenegraph.gltf.images) === null || _scenegraph$gltf$imag === void 0 ? void 0 : _scenegraph$gltf$imag[imageIndex];
|
|
66
|
+
if (parsedImage && typeof parsedImage.width !== 'undefined') {
|
|
67
|
+
const textureData = [];
|
|
68
|
+
for (let index = 0; index < textureCoordinates.length; index += 2) {
|
|
69
|
+
const value = getImageValueByCoordinates(parsedImage, mimeType, textureCoordinates, index, textureInfo.channels);
|
|
70
|
+
textureData.push(value);
|
|
71
|
+
}
|
|
72
|
+
return textureData;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
return null;
|
|
76
|
+
}
|
|
77
|
+
export function primitivePropertyDataToAttributes(scenegraph, attributeName, propertyData, featureTable, primitive) {
|
|
78
|
+
if (propertyData === null) return;
|
|
79
|
+
const featureIndices = [];
|
|
80
|
+
for (const texelData of propertyData) {
|
|
81
|
+
let index = featureTable.findIndex(item => item === texelData);
|
|
82
|
+
if (index === -1) {
|
|
83
|
+
index = featureTable.push(texelData) - 1;
|
|
84
|
+
}
|
|
85
|
+
featureIndices.push(index);
|
|
86
|
+
}
|
|
87
|
+
const typedArray = new Uint32Array(featureIndices);
|
|
88
|
+
const bufferIndex = scenegraph.gltf.buffers.push({
|
|
89
|
+
arrayBuffer: typedArray.buffer,
|
|
90
|
+
byteOffset: typedArray.byteOffset,
|
|
91
|
+
byteLength: typedArray.byteLength
|
|
92
|
+
}) - 1;
|
|
93
|
+
const bufferViewIndex = scenegraph.addBufferView(typedArray, bufferIndex, 0);
|
|
94
|
+
const accessorIndex = scenegraph.addAccessor(bufferViewIndex, {
|
|
95
|
+
size: 1,
|
|
96
|
+
componentType: getComponentTypeFromArray(typedArray),
|
|
97
|
+
count: typedArray.length
|
|
98
|
+
});
|
|
99
|
+
primitive.attributes[attributeName] = accessorIndex;
|
|
100
|
+
}
|
|
101
|
+
function getImageValueByCoordinates(parsedImage, mimeType, textureCoordinates, index) {
|
|
102
|
+
let channels = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : [0];
|
|
103
|
+
const CHANNELS_MAP = [{
|
|
104
|
+
offset: 0,
|
|
105
|
+
shift: 0
|
|
106
|
+
}, {
|
|
107
|
+
offset: 1,
|
|
108
|
+
shift: 8
|
|
109
|
+
}, {
|
|
110
|
+
offset: 2,
|
|
111
|
+
shift: 16
|
|
112
|
+
}, {
|
|
113
|
+
offset: 3,
|
|
114
|
+
shift: 24
|
|
115
|
+
}];
|
|
116
|
+
const u = textureCoordinates[index];
|
|
117
|
+
const v = textureCoordinates[index + 1];
|
|
118
|
+
let components = 1;
|
|
119
|
+
if (mimeType && (mimeType.indexOf('image/jpeg') !== -1 || mimeType.indexOf('image/png') !== -1)) components = 4;
|
|
120
|
+
const offset = coordinatesToOffset(u, v, parsedImage, components);
|
|
121
|
+
let value = 0;
|
|
122
|
+
for (const c of channels) {
|
|
123
|
+
const map = CHANNELS_MAP[c];
|
|
124
|
+
const imageOffset = offset + map.offset;
|
|
125
|
+
const imageData = getImageData(parsedImage);
|
|
126
|
+
if (imageData.data.length <= imageOffset) {
|
|
127
|
+
throw new Error("".concat(imageData.data.length, " <= ").concat(imageOffset));
|
|
128
|
+
}
|
|
129
|
+
const imageValue = imageData.data[imageOffset];
|
|
130
|
+
value |= imageValue << map.shift;
|
|
131
|
+
}
|
|
132
|
+
return value;
|
|
133
|
+
}
|
|
134
|
+
function coordinatesToOffset(u, v, parsedImage) {
|
|
135
|
+
let componentsCount = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 1;
|
|
136
|
+
const w = parsedImage.width;
|
|
137
|
+
const iX = emod(u) * (w - 1);
|
|
138
|
+
const indX = Math.round(iX);
|
|
139
|
+
const h = parsedImage.height;
|
|
140
|
+
const iY = emod(v) * (h - 1);
|
|
141
|
+
const indY = Math.round(iY);
|
|
142
|
+
const components = parsedImage.components ? parsedImage.components : componentsCount;
|
|
143
|
+
const offset = (indY * w + indX) * components;
|
|
144
|
+
return offset;
|
|
145
|
+
}
|
|
146
|
+
//# sourceMappingURL=data-processing.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"data-processing.js","names":["getComponentTypeFromArray","getImageData","emod","ATTRIBUTE_TYPE_TO_COMPONENTS","SCALAR","VEC2","VEC3","VEC4","MAT2","MAT3","MAT4","BOOLEAN","STRING","ENUM","ATTRIBUTE_COMPONENT_TYPE_TO_ARRAY","INT8","Int8Array","UINT8","Uint8Array","INT16","Int16Array","UINT16","Uint16Array","INT32","Int32Array","UINT32","Uint32Array","INT64","BigInt64Array","UINT64","BigUint64Array","FLOAT32","Float32Array","FLOAT64","Float64Array","ATTRIBUTE_COMPONENT_TYPE_TO_BYTE_SIZE","getArrayElementByteSize","attributeType","componentType","convertRawBufferToMetadataArray","typedArray","elementCount","arguments","length","undefined","numberOfComponents","ArrayType","size","offset","byteOffset","Math","ceil","buffer","getPrimitiveTextureData","scenegraph","textureInfo","primitive","_json$textures","_json$textures$textur","json","gltf","texCoordAccessorKey","concat","texCoord","texCoordAccessorIndex","attributes","texCoordBufferView","getBufferView","texCoordArray","getTypedArrayForBufferView","textureCoordinates","textureIndex","index","imageIndex","textures","source","_json$images","_json$images$imageInd","_scenegraph$gltf$imag","mimeType","images","parsedImage","width","textureData","value","getImageValueByCoordinates","channels","push","primitivePropertyDataToAttributes","attributeName","propertyData","featureTable","featureIndices","texelData","findIndex","item","bufferIndex","buffers","arrayBuffer","byteLength","bufferViewIndex","addBufferView","accessorIndex","addAccessor","count","CHANNELS_MAP","shift","u","v","components","indexOf","coordinatesToOffset","c","map","imageOffset","imageData","data","Error","imageValue","componentsCount","w","iX","indX","round","h","height","iY","indY"],"sources":["../../../../src/lib/extensions/data-processing.ts"],"sourcesContent":["import type {GLTFTextureInfoMetadata, GLTFMeshPrimitive} from '../types/gltf-json-schema';\nimport type {TypedArray} from '@loaders.gl/schema';\nimport type {ImageType} from '@loaders.gl/images';\n\nimport {GLTFScenegraph} from '../api/gltf-scenegraph';\nimport {getComponentTypeFromArray} from '../gltf-utils/gltf-utils';\nimport {getImageData} from '@loaders.gl/images';\nimport {emod} from '@loaders.gl/math';\n\nconst ATTRIBUTE_TYPE_TO_COMPONENTS = {\n SCALAR: 1,\n VEC2: 2,\n VEC3: 3,\n VEC4: 4,\n MAT2: 4,\n MAT3: 9,\n MAT4: 16,\n BOOLEAN: 1,\n STRING: 1,\n ENUM: 1\n};\n\nconst ATTRIBUTE_COMPONENT_TYPE_TO_ARRAY = {\n INT8: Int8Array,\n UINT8: Uint8Array,\n INT16: Int16Array,\n UINT16: Uint16Array,\n INT32: Int32Array,\n UINT32: Uint32Array,\n INT64: BigInt64Array,\n UINT64: BigUint64Array,\n FLOAT32: Float32Array,\n FLOAT64: Float64Array\n};\n\nconst ATTRIBUTE_COMPONENT_TYPE_TO_BYTE_SIZE = {\n INT8: 1,\n UINT8: 1,\n INT16: 2,\n UINT16: 2,\n INT32: 4,\n UINT32: 4,\n INT64: 8,\n UINT64: 8,\n FLOAT32: 4,\n FLOAT64: 8\n};\n\nexport function getArrayElementByteSize(attributeType, componentType): number {\n return (\n ATTRIBUTE_COMPONENT_TYPE_TO_BYTE_SIZE[componentType] *\n ATTRIBUTE_TYPE_TO_COMPONENTS[attributeType]\n );\n}\n\n/**\n * Converts raw bytes that are in the buffer to an array of the type defined by the schema.\n * @param {Uint8Array} typedArray - raw bytes in the buffer\n * @param {string} attributeType - SCALAR, VECN, MATN\n * @param {string} componentType - type of the component in elements, e.g. 'UINT8' or 'FLOAT32'\n * @param {number} elementCount - number of elements in the array. Default value is 1.\n * @returns {TypedArray} Data array\n */\nexport function convertRawBufferToMetadataArray(\n typedArray: Uint8Array,\n attributeType: string,\n componentType: string,\n elementCount: number = 1\n): TypedArray {\n const numberOfComponents = ATTRIBUTE_TYPE_TO_COMPONENTS[attributeType];\n const ArrayType = ATTRIBUTE_COMPONENT_TYPE_TO_ARRAY[componentType];\n const length = elementCount * numberOfComponents;\n const size = ATTRIBUTE_COMPONENT_TYPE_TO_BYTE_SIZE[componentType];\n // the buffer view `byteOffset` must be aligned to a multiple of the `componentType` size.\n const offset =\n typedArray.byteOffset % size\n ? Math.ceil(typedArray.byteOffset / size) * size\n : typedArray.byteOffset;\n return new ArrayType(typedArray.buffer, offset, length);\n}\n\n/**\n * Processes data encoded in the texture associated with the primitive.\n * If Ext_mesh_featues is combined with the Ext_structural_metadata, propertyTable will also be processed.\n * @param {GLTFScenegraph} scenegraph - Instance of the class for structured access to GLTF data.\n * @param {GLTFTextureInfoMetadata} textureInfo - reference to the texture where extension data are stored.\n * @param {GLTFMeshPrimitive} primitive - primitive object in the mesh\n * @returns {number[] | null} Array of data taken. Null if data can't be taken from the texture.\n */\nexport function getPrimitiveTextureData(\n scenegraph: GLTFScenegraph,\n textureInfo: GLTFTextureInfoMetadata,\n primitive: GLTFMeshPrimitive\n): number[] | null {\n /*\n texture.index is an index for the \"textures\" array.\n The texture object referenced by this index looks like this:\n {\n \"sampler\": 0,\n \"source\": 0\n }\n \"sampler\" is an index for the \"samplers\" array\n \"source\" is an index for the \"images\" array that contains data. These data are stored in rgba channels of the image.\n\n texture.texCoord is a number-suffix (like 1) for an attribute like \"TEXCOORD_1\" in meshes.primitives\n The value of \"TEXCOORD_1\" is an accessor that is used to get coordinates. These coordinates are being used to get data from the image.\n */\n const json = scenegraph.gltf.json;\n\n const texCoordAccessorKey = `TEXCOORD_${textureInfo.texCoord || 0}`;\n const texCoordAccessorIndex = primitive.attributes[texCoordAccessorKey];\n const texCoordBufferView = scenegraph.getBufferView(texCoordAccessorIndex);\n const texCoordArray: Uint8Array = scenegraph.getTypedArrayForBufferView(texCoordBufferView);\n\n // textureCoordinates array contains UV coordinates of the actual data stored in the texture\n const textureCoordinates: Float32Array = new Float32Array(\n texCoordArray.buffer,\n texCoordArray.byteOffset,\n texCoordArray.length / 4\n );\n\n const textureIndex: number = textureInfo.index;\n const imageIndex = json.textures?.[textureIndex]?.source;\n if (typeof imageIndex !== 'undefined') {\n const mimeType = json.images?.[imageIndex]?.mimeType;\n const parsedImage = scenegraph.gltf.images?.[imageIndex];\n // Checking for width is to prevent handling Un-processed images (e.g. [analyze] stage, where loadImages option is set to false)\n if (parsedImage && typeof parsedImage.width !== 'undefined') {\n const textureData: number[] = [];\n for (let index = 0; index < textureCoordinates.length; index += 2) {\n const value = getImageValueByCoordinates(\n parsedImage,\n mimeType,\n textureCoordinates,\n index,\n textureInfo.channels\n );\n textureData.push(value);\n }\n return textureData;\n }\n }\n return null;\n}\n\n/**\n * Puts property data to attributes.\n * It creates corresponding buffer, bufferView and accessor\n * so the data can be accessed like regular data stored in buffers.\n * @param {GLTFScenegraph} scenegraph - scenegraph object\n * @param {string} attributeName - name of the attribute\n * @param {number[]} propertyData - property data to store\n * @param {number[]} featureTable - an array where unique data from the property data are being stored\n * @param {GLTFMeshPrimitive} primitive - primitive object\n */\nexport function primitivePropertyDataToAttributes(\n scenegraph: GLTFScenegraph,\n attributeName: string,\n propertyData: number[],\n featureTable: number[],\n primitive: GLTFMeshPrimitive\n): void {\n if (propertyData === null) return;\n /*\n featureTable will contain unique values, e.g.\n propertyData = [24, 35, 28, 24]\n featureTable = [24, 35, 28]\n featureIndices will contain indices that refer featureTextureTable, e.g.\n featureIndices = [0, 1, 2, 0]\n */\n const featureIndices: number[] = [];\n for (const texelData of propertyData) {\n let index = featureTable.findIndex((item) => item === texelData);\n if (index === -1) {\n index = featureTable.push(texelData) - 1;\n }\n featureIndices.push(index);\n }\n const typedArray = new Uint32Array(featureIndices);\n const bufferIndex =\n scenegraph.gltf.buffers.push({\n arrayBuffer: typedArray.buffer,\n byteOffset: typedArray.byteOffset,\n byteLength: typedArray.byteLength\n }) - 1;\n const bufferViewIndex = scenegraph.addBufferView(typedArray, bufferIndex, 0);\n const accessorIndex = scenegraph.addAccessor(bufferViewIndex, {\n size: 1,\n componentType: getComponentTypeFromArray(typedArray),\n count: typedArray.length\n });\n primitive.attributes[attributeName] = accessorIndex;\n}\n\n/**\n * Gets the value from the texture by coordinates provided.\n * @param {ImageType} parsedImage - image where the data are stored.\n * @param {string | undefined} mimeType - MIME type\n * @param {Float32Array} textureCoordinates - uv coordinates to access data in the image.\n * @param {number} index - index of uv coordinates in the array textureCoordinates\n * @param {channels} channels - image channels where data are stored. Channels of an RGBA texture are numbered 0..3 respectively.\n * @returns {number} Value taken from the image.\n */\nfunction getImageValueByCoordinates(\n parsedImage: ImageType,\n mimeType: string | undefined,\n textureCoordinates: Float32Array,\n index: number,\n channels: number[] = [0]\n) {\n const CHANNELS_MAP = [\n {offset: 0, shift: 0},\n {offset: 1, shift: 8},\n {offset: 2, shift: 16},\n {offset: 3, shift: 24}\n ];\n\n const u = textureCoordinates[index];\n const v = textureCoordinates[index + 1];\n\n let components = 1;\n if (mimeType && (mimeType.indexOf('image/jpeg') !== -1 || mimeType.indexOf('image/png') !== -1))\n components = 4;\n const offset = coordinatesToOffset(u, v, parsedImage, components);\n let value: number = 0;\n for (const c of channels) {\n const map = CHANNELS_MAP[c];\n const imageOffset = offset + map.offset;\n const imageData = getImageData(parsedImage);\n if (imageData.data.length <= imageOffset) {\n throw new Error(`${imageData.data.length} <= ${imageOffset}`);\n }\n const imageValue = imageData.data[imageOffset];\n value |= imageValue << map.shift;\n }\n return value;\n}\n\n/**\n * Retrieves the offset in the image where the data are stored\n * @param u - u-coordinate\n * @param v - v-coordinate\n * @param parsedImage - image where the data are stored\n * @param componentsCount - number of components the data consists of.\n * @returns offset in the image where the data are stored\n */\nfunction coordinatesToOffset(\n u: number,\n v: number,\n parsedImage: any,\n componentsCount: number = 1\n): number {\n const w = parsedImage.width;\n const iX = emod(u) * (w - 1);\n const indX = Math.round(iX);\n\n const h = parsedImage.height;\n const iY = emod(v) * (h - 1);\n const indY = Math.round(iY);\n const components = parsedImage.components ? parsedImage.components : componentsCount;\n // components is a number of channels in the image\n const offset = (indY * w + indX) * components;\n return offset;\n}\n"],"mappings":"AAKA,SAAQA,yBAAyB,QAAO,0BAA0B;AAClE,SAAQC,YAAY,QAAO,oBAAoB;AAC/C,SAAQC,IAAI,QAAO,kBAAkB;AAErC,MAAMC,4BAA4B,GAAG;EACnCC,MAAM,EAAE,CAAC;EACTC,IAAI,EAAE,CAAC;EACPC,IAAI,EAAE,CAAC;EACPC,IAAI,EAAE,CAAC;EACPC,IAAI,EAAE,CAAC;EACPC,IAAI,EAAE,CAAC;EACPC,IAAI,EAAE,EAAE;EACRC,OAAO,EAAE,CAAC;EACVC,MAAM,EAAE,CAAC;EACTC,IAAI,EAAE;AACR,CAAC;AAED,MAAMC,iCAAiC,GAAG;EACxCC,IAAI,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G,EAAE,CAAC;EAC3B,MAAMjB,UAAU,GAAG5B,WAAW,CAAC4B,UAAU,GAAG5B,WAAW,CAAC4B,UAAU,GAAGU,eAAe;EAEpF,MAAMvE,MAAM,GAAG,CAAC+E,IAAI,GAAGP,CAAC,GAAGE,IAAI,IAAIb,UAAU;EAC7C,OAAO7D,MAAM;AACf"}
|
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
import { GLTFScenegraph } from '../../api/gltf-scenegraph';
|
|
2
2
|
import { getImageData } from '@loaders.gl/images';
|
|
3
3
|
import { getComponentTypeFromArray } from '../../gltf-utils/gltf-utils';
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
import { emod } from '@loaders.gl/math';
|
|
5
|
+
const EXT_FEATURE_METADATA_NAME = 'EXT_feature_metadata';
|
|
6
|
+
export const name = EXT_FEATURE_METADATA_NAME;
|
|
6
7
|
export async function decode(gltfData, options) {
|
|
7
8
|
const scenegraph = new GLTFScenegraph(gltfData);
|
|
8
9
|
decodeExtFeatureMetadata(scenegraph, options);
|
|
9
10
|
}
|
|
10
11
|
function decodeExtFeatureMetadata(scenegraph, options) {
|
|
11
12
|
var _extension$schema, _options$gltf;
|
|
12
|
-
const extension = scenegraph.getExtension(
|
|
13
|
+
const extension = scenegraph.getExtension(EXT_FEATURE_METADATA_NAME);
|
|
13
14
|
if (!extension) return;
|
|
14
15
|
const schemaClasses = (_extension$schema = extension.schema) === null || _extension$schema === void 0 ? void 0 : _extension$schema.classes;
|
|
15
16
|
const {
|
|
@@ -184,10 +185,6 @@ function coordinatesToOffset(u, v, parsedImage) {
|
|
|
184
185
|
const offset = (indY * w + indX) * components;
|
|
185
186
|
return offset;
|
|
186
187
|
}
|
|
187
|
-
function emod(n) {
|
|
188
|
-
const a = (n % 1 + 1) % 1;
|
|
189
|
-
return a;
|
|
190
|
-
}
|
|
191
188
|
function findFeatureTableByName(featureTables, schemaClassName) {
|
|
192
189
|
for (const featureTableName in featureTables) {
|
|
193
190
|
const featureTable = featureTables[featureTableName];
|