@loaders.gl/gltf 4.3.0-alpha.7 → 4.3.0-alpha.8
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.dev.js +383 -66
- package/dist/dist.min.js +1 -1
- package/dist/glb-writer.js +1 -1
- package/dist/gltf-writer.d.ts.map +1 -1
- package/dist/gltf-writer.js +4 -2
- package/dist/index.cjs +266 -16
- package/dist/index.cjs.map +3 -3
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/lib/api/gltf-extensions.d.ts +4 -1
- package/dist/lib/api/gltf-extensions.d.ts.map +1 -1
- package/dist/lib/api/gltf-extensions.js +11 -0
- package/dist/lib/api/gltf-scenegraph.d.ts.map +1 -1
- package/dist/lib/api/gltf-scenegraph.js +1 -2
- package/dist/lib/encoders/encode-gltf.d.ts +3 -1
- package/dist/lib/encoders/encode-gltf.d.ts.map +1 -1
- package/dist/lib/encoders/encode-gltf.js +3 -3
- package/dist/lib/extensions/EXT_mesh_features.d.ts +17 -1
- package/dist/lib/extensions/EXT_mesh_features.d.ts.map +1 -1
- package/dist/lib/extensions/EXT_mesh_features.js +109 -0
- package/dist/lib/extensions/EXT_structural_metadata.d.ts +19 -0
- package/dist/lib/extensions/EXT_structural_metadata.d.ts.map +1 -1
- package/dist/lib/extensions/EXT_structural_metadata.js +168 -0
- package/dist/lib/utils/version.js +1 -1
- package/package.json +8 -8
- package/src/glb-writer.ts +1 -1
- package/src/gltf-writer.ts +8 -4
- package/src/index.ts +6 -0
- package/src/lib/api/gltf-extensions.ts +15 -1
- package/src/lib/api/gltf-scenegraph.ts +1 -3
- package/src/lib/encoders/encode-gltf.ts +11 -4
- package/src/lib/extensions/EXT_mesh_features.ts +130 -0
- package/src/lib/extensions/EXT_structural_metadata.ts +232 -1
package/dist/index.cjs
CHANGED
|
@@ -29,6 +29,8 @@ __export(dist_exports, {
|
|
|
29
29
|
GLTFScenegraph: () => GLTFScenegraph,
|
|
30
30
|
GLTFWriter: () => GLTFWriter,
|
|
31
31
|
_getMemoryUsageGLTF: () => getMemoryUsageGLTF,
|
|
32
|
+
createExtMeshFeatures: () => createExtMeshFeatures,
|
|
33
|
+
createExtStructuralMetadata: () => createExtStructuralMetadata,
|
|
32
34
|
postProcessGLTF: () => postProcessGLTF
|
|
33
35
|
});
|
|
34
36
|
module.exports = __toCommonJS(dist_exports);
|
|
@@ -36,7 +38,9 @@ module.exports = __toCommonJS(dist_exports);
|
|
|
36
38
|
// dist/lib/extensions/EXT_mesh_features.js
|
|
37
39
|
var EXT_mesh_features_exports = {};
|
|
38
40
|
__export(EXT_mesh_features_exports, {
|
|
41
|
+
createExtMeshFeatures: () => createExtMeshFeatures,
|
|
39
42
|
decode: () => decode,
|
|
43
|
+
encode: () => encode,
|
|
40
44
|
name: () => name
|
|
41
45
|
});
|
|
42
46
|
|
|
@@ -611,7 +615,6 @@ var GLTFScenegraph = class {
|
|
|
611
615
|
/** Pack the binary chunk */
|
|
612
616
|
createBinaryChunk() {
|
|
613
617
|
var _a, _b;
|
|
614
|
-
this.gltf.buffers = [];
|
|
615
618
|
const totalByteLength = this.byteLength;
|
|
616
619
|
const arrayBuffer = new ArrayBuffer(totalByteLength);
|
|
617
620
|
const targetArray = new Uint8Array(arrayBuffer);
|
|
@@ -626,6 +629,7 @@ var GLTFScenegraph = class {
|
|
|
626
629
|
}
|
|
627
630
|
this.gltf.binary = arrayBuffer;
|
|
628
631
|
this.sourceBuffers = [arrayBuffer];
|
|
632
|
+
this.gltf.buffers = [{ arrayBuffer, byteOffset: 0, byteLength: arrayBuffer.byteLength }];
|
|
629
633
|
}
|
|
630
634
|
// PRIVATE
|
|
631
635
|
_removeStringFromArray(array, string) {
|
|
@@ -927,6 +931,12 @@ async function decode(gltfData, options) {
|
|
|
927
931
|
const scenegraph = new GLTFScenegraph(gltfData);
|
|
928
932
|
decodeExtMeshFeatures(scenegraph, options);
|
|
929
933
|
}
|
|
934
|
+
function encode(gltfData, options) {
|
|
935
|
+
const scenegraph = new GLTFScenegraph(gltfData);
|
|
936
|
+
encodeExtMeshFeatures(scenegraph, options);
|
|
937
|
+
scenegraph.createBinaryChunk();
|
|
938
|
+
return scenegraph.gltf;
|
|
939
|
+
}
|
|
930
940
|
function decodeExtMeshFeatures(scenegraph, options) {
|
|
931
941
|
const json = scenegraph.gltf.json;
|
|
932
942
|
if (!json.meshes) {
|
|
@@ -962,11 +972,87 @@ function processMeshPrimitiveFeatures(scenegraph, primitive, options) {
|
|
|
962
972
|
featureId.data = featureIdData;
|
|
963
973
|
}
|
|
964
974
|
}
|
|
975
|
+
function encodeExtMeshFeatures(scenegraph, options) {
|
|
976
|
+
const meshes = scenegraph.gltf.json.meshes;
|
|
977
|
+
if (!meshes) {
|
|
978
|
+
return;
|
|
979
|
+
}
|
|
980
|
+
for (const mesh of meshes) {
|
|
981
|
+
for (const primitive of mesh.primitives) {
|
|
982
|
+
encodeExtMeshFeaturesForPrimitive(scenegraph, primitive);
|
|
983
|
+
}
|
|
984
|
+
}
|
|
985
|
+
}
|
|
986
|
+
function createExtMeshFeatures(scenegraph, primitive, featureIdArray, propertyTableIndex) {
|
|
987
|
+
if (!primitive.extensions) {
|
|
988
|
+
primitive.extensions = {};
|
|
989
|
+
}
|
|
990
|
+
let extension = primitive.extensions[EXT_MESH_FEATURES_NAME];
|
|
991
|
+
if (!extension) {
|
|
992
|
+
extension = { featureIds: [] };
|
|
993
|
+
primitive.extensions[EXT_MESH_FEATURES_NAME] = extension;
|
|
994
|
+
}
|
|
995
|
+
const { featureIds } = extension;
|
|
996
|
+
const featureId = {
|
|
997
|
+
featureCount: featureIdArray.length,
|
|
998
|
+
propertyTable: propertyTableIndex,
|
|
999
|
+
data: featureIdArray
|
|
1000
|
+
};
|
|
1001
|
+
featureIds.push(featureId);
|
|
1002
|
+
scenegraph.addObjectExtension(primitive, EXT_MESH_FEATURES_NAME, extension);
|
|
1003
|
+
}
|
|
1004
|
+
function encodeExtMeshFeaturesForPrimitive(scenegraph, primitive) {
|
|
1005
|
+
var _a;
|
|
1006
|
+
const extension = (_a = primitive.extensions) == null ? void 0 : _a[EXT_MESH_FEATURES_NAME];
|
|
1007
|
+
if (!extension) {
|
|
1008
|
+
return;
|
|
1009
|
+
}
|
|
1010
|
+
const featureIds = extension.featureIds;
|
|
1011
|
+
featureIds.forEach((featureId, elementIndex) => {
|
|
1012
|
+
if (featureId.data) {
|
|
1013
|
+
const { accessorKey, index } = createAccessorKey(primitive.attributes);
|
|
1014
|
+
const typedArray = new Uint32Array(featureId.data);
|
|
1015
|
+
featureIds[elementIndex] = {
|
|
1016
|
+
featureCount: typedArray.length,
|
|
1017
|
+
propertyTable: featureId.propertyTable,
|
|
1018
|
+
attribute: index
|
|
1019
|
+
};
|
|
1020
|
+
scenegraph.gltf.buffers.push({
|
|
1021
|
+
arrayBuffer: typedArray.buffer,
|
|
1022
|
+
byteOffset: typedArray.byteOffset,
|
|
1023
|
+
byteLength: typedArray.byteLength
|
|
1024
|
+
});
|
|
1025
|
+
const bufferViewIndex = scenegraph.addBufferView(typedArray);
|
|
1026
|
+
const accessorIndex = scenegraph.addAccessor(bufferViewIndex, {
|
|
1027
|
+
size: 1,
|
|
1028
|
+
componentType: getComponentTypeFromArray(typedArray),
|
|
1029
|
+
count: typedArray.length
|
|
1030
|
+
});
|
|
1031
|
+
primitive.attributes[accessorKey] = accessorIndex;
|
|
1032
|
+
}
|
|
1033
|
+
});
|
|
1034
|
+
}
|
|
1035
|
+
function createAccessorKey(attributes) {
|
|
1036
|
+
const prefix = "_FEATURE_ID_";
|
|
1037
|
+
const attrs = Object.keys(attributes).filter((item) => item.indexOf(prefix) === 0);
|
|
1038
|
+
let max = -1;
|
|
1039
|
+
for (const a of attrs) {
|
|
1040
|
+
const n = Number(a.substring(prefix.length));
|
|
1041
|
+
if (n > max) {
|
|
1042
|
+
max = n;
|
|
1043
|
+
}
|
|
1044
|
+
}
|
|
1045
|
+
max++;
|
|
1046
|
+
const accessorKey = `${prefix}${max}`;
|
|
1047
|
+
return { accessorKey, index: max };
|
|
1048
|
+
}
|
|
965
1049
|
|
|
966
1050
|
// dist/lib/extensions/EXT_structural_metadata.js
|
|
967
1051
|
var EXT_structural_metadata_exports = {};
|
|
968
1052
|
__export(EXT_structural_metadata_exports, {
|
|
1053
|
+
createExtStructuralMetadata: () => createExtStructuralMetadata,
|
|
969
1054
|
decode: () => decode2,
|
|
1055
|
+
encode: () => encode2,
|
|
970
1056
|
name: () => name2
|
|
971
1057
|
});
|
|
972
1058
|
var EXT_STRUCTURAL_METADATA_NAME = "EXT_structural_metadata";
|
|
@@ -975,6 +1061,12 @@ async function decode2(gltfData, options) {
|
|
|
975
1061
|
const scenegraph = new GLTFScenegraph(gltfData);
|
|
976
1062
|
decodeExtStructuralMetadata(scenegraph, options);
|
|
977
1063
|
}
|
|
1064
|
+
function encode2(gltfData, options) {
|
|
1065
|
+
const scenegraph = new GLTFScenegraph(gltfData);
|
|
1066
|
+
encodeExtStructuralMetadata(scenegraph, options);
|
|
1067
|
+
scenegraph.createBinaryChunk();
|
|
1068
|
+
return scenegraph.gltf;
|
|
1069
|
+
}
|
|
978
1070
|
function decodeExtStructuralMetadata(scenegraph, options) {
|
|
979
1071
|
var _a, _b;
|
|
980
1072
|
if (!((_a = options.gltf) == null ? void 0 : _a.loadBuffers)) {
|
|
@@ -1245,6 +1337,155 @@ function getEnumByValue(enumEntry, value) {
|
|
|
1245
1337
|
}
|
|
1246
1338
|
return null;
|
|
1247
1339
|
}
|
|
1340
|
+
var SCHEMA_CLASS_ID_DEFAULT = "schemaClassId";
|
|
1341
|
+
function encodeExtStructuralMetadata(scenegraph, options) {
|
|
1342
|
+
var _a, _b;
|
|
1343
|
+
const extension = scenegraph.getExtension(EXT_STRUCTURAL_METADATA_NAME);
|
|
1344
|
+
if (!extension) {
|
|
1345
|
+
return;
|
|
1346
|
+
}
|
|
1347
|
+
if (extension.propertyTables) {
|
|
1348
|
+
for (const table of extension.propertyTables) {
|
|
1349
|
+
const classId = table.class;
|
|
1350
|
+
const schemaClass = (_b = (_a = extension.schema) == null ? void 0 : _a.classes) == null ? void 0 : _b[classId];
|
|
1351
|
+
if (table.properties && schemaClass) {
|
|
1352
|
+
encodeProperties(table, schemaClass, scenegraph);
|
|
1353
|
+
}
|
|
1354
|
+
}
|
|
1355
|
+
}
|
|
1356
|
+
}
|
|
1357
|
+
function encodeProperties(table, schemaClass, scenegraph) {
|
|
1358
|
+
for (const propertyName in table.properties) {
|
|
1359
|
+
const data = table.properties[propertyName].data;
|
|
1360
|
+
if (data) {
|
|
1361
|
+
const classProperty = schemaClass.properties[propertyName];
|
|
1362
|
+
if (classProperty) {
|
|
1363
|
+
const tableProperty = createPropertyTableProperty(data, classProperty, scenegraph);
|
|
1364
|
+
table.properties[propertyName] = tableProperty;
|
|
1365
|
+
}
|
|
1366
|
+
}
|
|
1367
|
+
}
|
|
1368
|
+
}
|
|
1369
|
+
function createExtStructuralMetadata(scenegraph, propertyAttributes, classId = SCHEMA_CLASS_ID_DEFAULT) {
|
|
1370
|
+
let extension = scenegraph.getExtension(EXT_STRUCTURAL_METADATA_NAME);
|
|
1371
|
+
if (!extension) {
|
|
1372
|
+
extension = scenegraph.addExtension(EXT_STRUCTURAL_METADATA_NAME);
|
|
1373
|
+
}
|
|
1374
|
+
extension.schema = createSchema(propertyAttributes, classId, extension.schema);
|
|
1375
|
+
const table = createPropertyTable(propertyAttributes, classId, extension.schema);
|
|
1376
|
+
if (!extension.propertyTables) {
|
|
1377
|
+
extension.propertyTables = [];
|
|
1378
|
+
}
|
|
1379
|
+
return extension.propertyTables.push(table) - 1;
|
|
1380
|
+
}
|
|
1381
|
+
function createSchema(propertyAttributes, classId, schemaToUpdate) {
|
|
1382
|
+
const schema = schemaToUpdate ?? {
|
|
1383
|
+
id: "schema_id"
|
|
1384
|
+
};
|
|
1385
|
+
const schemaClass = {
|
|
1386
|
+
properties: {}
|
|
1387
|
+
};
|
|
1388
|
+
for (const attribute of propertyAttributes) {
|
|
1389
|
+
const classProperty = {
|
|
1390
|
+
type: attribute.elementType,
|
|
1391
|
+
componentType: attribute.componentType
|
|
1392
|
+
};
|
|
1393
|
+
schemaClass.properties[attribute.name] = classProperty;
|
|
1394
|
+
}
|
|
1395
|
+
schema.classes = {};
|
|
1396
|
+
schema.classes[classId] = schemaClass;
|
|
1397
|
+
return schema;
|
|
1398
|
+
}
|
|
1399
|
+
function createPropertyTable(propertyAttributes, classId, schema) {
|
|
1400
|
+
var _a;
|
|
1401
|
+
const table = {
|
|
1402
|
+
class: classId,
|
|
1403
|
+
count: 0
|
|
1404
|
+
};
|
|
1405
|
+
let count = 0;
|
|
1406
|
+
const schemaClass = (_a = schema.classes) == null ? void 0 : _a[classId];
|
|
1407
|
+
for (const attribute of propertyAttributes) {
|
|
1408
|
+
if (count === 0) {
|
|
1409
|
+
count = attribute.values.length;
|
|
1410
|
+
}
|
|
1411
|
+
if (count !== attribute.values.length && attribute.values.length) {
|
|
1412
|
+
throw new Error("Illegal values in attributes");
|
|
1413
|
+
}
|
|
1414
|
+
const classProperty = schemaClass == null ? void 0 : schemaClass.properties[attribute.name];
|
|
1415
|
+
if (classProperty) {
|
|
1416
|
+
if (!table.properties) {
|
|
1417
|
+
table.properties = {};
|
|
1418
|
+
}
|
|
1419
|
+
table.properties[attribute.name] = { values: 0, data: attribute.values };
|
|
1420
|
+
}
|
|
1421
|
+
}
|
|
1422
|
+
table.count = count;
|
|
1423
|
+
return table;
|
|
1424
|
+
}
|
|
1425
|
+
function createPropertyTableProperty(values, classProperty, scenegraph) {
|
|
1426
|
+
const prop = { values: 0 };
|
|
1427
|
+
if (classProperty.type === "STRING") {
|
|
1428
|
+
const { stringData, stringOffsets } = createPropertyDataString(values);
|
|
1429
|
+
prop.stringOffsets = createBufferView(stringOffsets, scenegraph);
|
|
1430
|
+
prop.values = createBufferView(stringData, scenegraph);
|
|
1431
|
+
} else if (classProperty.type === "SCALAR" && classProperty.componentType) {
|
|
1432
|
+
const data = createPropertyDataScalar(values, classProperty.componentType);
|
|
1433
|
+
prop.values = createBufferView(data, scenegraph);
|
|
1434
|
+
}
|
|
1435
|
+
return prop;
|
|
1436
|
+
}
|
|
1437
|
+
var COMPONENT_TYPE_TO_ARRAY_CONSTRUCTOR = {
|
|
1438
|
+
INT8: Int8Array,
|
|
1439
|
+
UINT8: Uint8Array,
|
|
1440
|
+
INT16: Int16Array,
|
|
1441
|
+
UINT16: Uint16Array,
|
|
1442
|
+
INT32: Int32Array,
|
|
1443
|
+
UINT32: Uint32Array,
|
|
1444
|
+
INT64: Int32Array,
|
|
1445
|
+
UINT64: Uint32Array,
|
|
1446
|
+
FLOAT32: Float32Array,
|
|
1447
|
+
FLOAT64: Float64Array
|
|
1448
|
+
};
|
|
1449
|
+
function createPropertyDataScalar(array, componentType) {
|
|
1450
|
+
const numberArray = [];
|
|
1451
|
+
for (const value of array) {
|
|
1452
|
+
numberArray.push(Number(value));
|
|
1453
|
+
}
|
|
1454
|
+
const Construct = COMPONENT_TYPE_TO_ARRAY_CONSTRUCTOR[componentType];
|
|
1455
|
+
if (!Construct) {
|
|
1456
|
+
throw new Error("Illegal component type");
|
|
1457
|
+
}
|
|
1458
|
+
return new Construct(numberArray);
|
|
1459
|
+
}
|
|
1460
|
+
function createPropertyDataString(strings) {
|
|
1461
|
+
const utf8Encode = new TextEncoder();
|
|
1462
|
+
const arr = [];
|
|
1463
|
+
let len = 0;
|
|
1464
|
+
for (const str of strings) {
|
|
1465
|
+
const uint8Array = utf8Encode.encode(str);
|
|
1466
|
+
len += uint8Array.length;
|
|
1467
|
+
arr.push(uint8Array);
|
|
1468
|
+
}
|
|
1469
|
+
const strArray = new Uint8Array(len);
|
|
1470
|
+
const strOffsets = [];
|
|
1471
|
+
let offset = 0;
|
|
1472
|
+
for (const str of arr) {
|
|
1473
|
+
strArray.set(str, offset);
|
|
1474
|
+
strOffsets.push(offset);
|
|
1475
|
+
offset += str.length;
|
|
1476
|
+
}
|
|
1477
|
+
strOffsets.push(offset);
|
|
1478
|
+
const stringOffsetsTypedArray = new Uint32Array(strOffsets);
|
|
1479
|
+
return { stringData: strArray, stringOffsets: stringOffsetsTypedArray };
|
|
1480
|
+
}
|
|
1481
|
+
function createBufferView(typedArray, scenegraph) {
|
|
1482
|
+
scenegraph.gltf.buffers.push({
|
|
1483
|
+
arrayBuffer: typedArray.buffer,
|
|
1484
|
+
byteOffset: typedArray.byteOffset,
|
|
1485
|
+
byteLength: typedArray.byteLength
|
|
1486
|
+
});
|
|
1487
|
+
return scenegraph.addBufferView(typedArray);
|
|
1488
|
+
}
|
|
1248
1489
|
|
|
1249
1490
|
// dist/lib/extensions/deprecated/EXT_feature_metadata.js
|
|
1250
1491
|
var EXT_feature_metadata_exports = {};
|
|
@@ -1452,7 +1693,7 @@ function processPrimitiveTextures(scenegraph, attributeName, featureTexturePrope
|
|
|
1452
1693
|
}
|
|
1453
1694
|
|
|
1454
1695
|
// dist/lib/utils/version.js
|
|
1455
|
-
var VERSION = true ? "4.3.0-alpha.
|
|
1696
|
+
var VERSION = true ? "4.3.0-alpha.7" : "latest";
|
|
1456
1697
|
|
|
1457
1698
|
// dist/lib/parsers/parse-gltf.js
|
|
1458
1699
|
var import_loader_utils4 = require("@loaders.gl/loader-utils");
|
|
@@ -1862,7 +2103,7 @@ function preprocess2(gltfData, options) {
|
|
|
1862
2103
|
var KHR_draco_mesh_compression_exports = {};
|
|
1863
2104
|
__export(KHR_draco_mesh_compression_exports, {
|
|
1864
2105
|
decode: () => decode6,
|
|
1865
|
-
encode: () =>
|
|
2106
|
+
encode: () => encode3,
|
|
1866
2107
|
name: () => name7,
|
|
1867
2108
|
preprocess: () => preprocess3
|
|
1868
2109
|
});
|
|
@@ -1953,7 +2194,7 @@ async function decode6(gltfData, options, context) {
|
|
|
1953
2194
|
await Promise.all(promises);
|
|
1954
2195
|
scenegraph.removeExtension(KHR_DRACO_MESH_COMPRESSION);
|
|
1955
2196
|
}
|
|
1956
|
-
function
|
|
2197
|
+
function encode3(gltfData, options = {}) {
|
|
1957
2198
|
const scenegraph = new GLTFScenegraph(gltfData);
|
|
1958
2199
|
for (const mesh of scenegraph.json.meshes || []) {
|
|
1959
2200
|
compressMesh(mesh, options);
|
|
@@ -2184,7 +2425,7 @@ function makeTransformationMatrix(extensionData) {
|
|
|
2184
2425
|
var KHR_lights_punctual_exports = {};
|
|
2185
2426
|
__export(KHR_lights_punctual_exports, {
|
|
2186
2427
|
decode: () => decode8,
|
|
2187
|
-
encode: () =>
|
|
2428
|
+
encode: () => encode4,
|
|
2188
2429
|
name: () => name9
|
|
2189
2430
|
});
|
|
2190
2431
|
var KHR_LIGHTS_PUNCTUAL = "KHR_lights_punctual";
|
|
@@ -2205,7 +2446,7 @@ async function decode8(gltfData) {
|
|
|
2205
2446
|
gltfScenegraph.removeObjectExtension(node, KHR_LIGHTS_PUNCTUAL);
|
|
2206
2447
|
}
|
|
2207
2448
|
}
|
|
2208
|
-
async function
|
|
2449
|
+
async function encode4(gltfData) {
|
|
2209
2450
|
const gltfScenegraph = new GLTFScenegraph(gltfData);
|
|
2210
2451
|
const { json } = gltfScenegraph;
|
|
2211
2452
|
if (json.lights) {
|
|
@@ -2227,7 +2468,7 @@ async function encode2(gltfData) {
|
|
|
2227
2468
|
var KHR_materials_unlit_exports = {};
|
|
2228
2469
|
__export(KHR_materials_unlit_exports, {
|
|
2229
2470
|
decode: () => decode9,
|
|
2230
|
-
encode: () =>
|
|
2471
|
+
encode: () => encode5,
|
|
2231
2472
|
name: () => name10
|
|
2232
2473
|
});
|
|
2233
2474
|
var KHR_MATERIALS_UNLIT = "KHR_materials_unlit";
|
|
@@ -2244,7 +2485,7 @@ async function decode9(gltfData) {
|
|
|
2244
2485
|
}
|
|
2245
2486
|
gltfScenegraph.removeExtension(KHR_MATERIALS_UNLIT);
|
|
2246
2487
|
}
|
|
2247
|
-
function
|
|
2488
|
+
function encode5(gltfData) {
|
|
2248
2489
|
const gltfScenegraph = new GLTFScenegraph(gltfData);
|
|
2249
2490
|
const { json } = gltfScenegraph;
|
|
2250
2491
|
if (gltfScenegraph.materials) {
|
|
@@ -2262,7 +2503,7 @@ function encode3(gltfData) {
|
|
|
2262
2503
|
var KHR_techniques_webgl_exports = {};
|
|
2263
2504
|
__export(KHR_techniques_webgl_exports, {
|
|
2264
2505
|
decode: () => decode10,
|
|
2265
|
-
encode: () =>
|
|
2506
|
+
encode: () => encode6,
|
|
2266
2507
|
name: () => name11
|
|
2267
2508
|
});
|
|
2268
2509
|
var KHR_TECHNIQUES_WEBGL = "KHR_techniques_webgl";
|
|
@@ -2289,7 +2530,7 @@ async function decode10(gltfData) {
|
|
|
2289
2530
|
gltfScenegraph.removeExtension(KHR_TECHNIQUES_WEBGL);
|
|
2290
2531
|
}
|
|
2291
2532
|
}
|
|
2292
|
-
async function
|
|
2533
|
+
async function encode6(gltfData, options) {
|
|
2293
2534
|
}
|
|
2294
2535
|
function resolveTechniques(techniquesExtension, gltfScenegraph) {
|
|
2295
2536
|
const { programs = [], shaders = [], techniques = [] } = techniquesExtension;
|
|
@@ -2344,6 +2585,7 @@ var EXTENSIONS = [
|
|
|
2344
2585
|
KHR_texture_transform_exports,
|
|
2345
2586
|
EXT_feature_metadata_exports
|
|
2346
2587
|
];
|
|
2588
|
+
var EXTENSIONS_ENCODING = [EXT_structural_metadata_exports, EXT_mesh_features_exports];
|
|
2347
2589
|
function preprocessExtensions(gltf, options = {}, context) {
|
|
2348
2590
|
var _a;
|
|
2349
2591
|
const extensions = EXTENSIONS.filter((extension) => useExtension(extension.name, options));
|
|
@@ -2358,6 +2600,13 @@ async function decodeExtensions(gltf, options = {}, context) {
|
|
|
2358
2600
|
await ((_a = extension.decode) == null ? void 0 : _a.call(extension, gltf, options, context));
|
|
2359
2601
|
}
|
|
2360
2602
|
}
|
|
2603
|
+
function encodeExtensions(gltf, options = {}) {
|
|
2604
|
+
var _a;
|
|
2605
|
+
for (const extension of EXTENSIONS_ENCODING) {
|
|
2606
|
+
gltf = ((_a = extension.encode) == null ? void 0 : _a.call(extension, gltf, options)) ?? gltf;
|
|
2607
|
+
}
|
|
2608
|
+
return gltf;
|
|
2609
|
+
}
|
|
2361
2610
|
function useExtension(extensionName, options) {
|
|
2362
2611
|
var _a;
|
|
2363
2612
|
const excludes = ((_a = options == null ? void 0 : options.gltf) == null ? void 0 : _a.excludeExtensions) || {};
|
|
@@ -2811,11 +3060,11 @@ function encodeGLBSync(glb, dataView, byteOffset = 0, options = {}) {
|
|
|
2811
3060
|
|
|
2812
3061
|
// dist/lib/encoders/encode-gltf.js
|
|
2813
3062
|
function encodeGLTFSync(gltf, arrayBuffer, byteOffset, options) {
|
|
2814
|
-
|
|
3063
|
+
validateGltf(gltf);
|
|
2815
3064
|
return encodeGLBSync(gltf, arrayBuffer, byteOffset, options);
|
|
2816
3065
|
}
|
|
2817
|
-
function
|
|
2818
|
-
if (gltf.buffers && gltf.buffers.length >
|
|
3066
|
+
function validateGltf(gltf) {
|
|
3067
|
+
if (gltf.buffers && gltf.buffers.length > 1) {
|
|
2819
3068
|
throw new Error("encodeGLTF: multiple buffers not yet implemented");
|
|
2820
3069
|
}
|
|
2821
3070
|
}
|
|
@@ -2841,10 +3090,11 @@ var GLTFWriter = {
|
|
|
2841
3090
|
};
|
|
2842
3091
|
function encodeSync(gltf, options = {}) {
|
|
2843
3092
|
const { byteOffset = 0 } = options;
|
|
2844
|
-
const
|
|
3093
|
+
const gltfToEncode = encodeExtensions(gltf);
|
|
3094
|
+
const byteLength = encodeGLTFSync(gltfToEncode, null, byteOffset, options);
|
|
2845
3095
|
const arrayBuffer = new ArrayBuffer(byteLength);
|
|
2846
3096
|
const dataView = new DataView(arrayBuffer);
|
|
2847
|
-
encodeGLTFSync(
|
|
3097
|
+
encodeGLTFSync(gltfToEncode, dataView, byteOffset, options);
|
|
2848
3098
|
return arrayBuffer;
|
|
2849
3099
|
}
|
|
2850
3100
|
|
|
@@ -2894,7 +3144,7 @@ var GLBWriter = {
|
|
|
2894
3144
|
encodeSync: encodeSync2
|
|
2895
3145
|
};
|
|
2896
3146
|
function encodeSync2(glb, options) {
|
|
2897
|
-
const { byteOffset = 0 } = options;
|
|
3147
|
+
const { byteOffset = 0 } = options ?? {};
|
|
2898
3148
|
const byteLength = encodeGLBSync(glb, null, byteOffset, options);
|
|
2899
3149
|
const arrayBuffer = new ArrayBuffer(byteLength);
|
|
2900
3150
|
const dataView = new DataView(arrayBuffer);
|