@loaders.gl/gltf 4.3.0-alpha.6 → 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/dist.dev.js
CHANGED
|
@@ -57,6 +57,8 @@ var __exports__ = (() => {
|
|
|
57
57
|
GLTFScenegraph: () => GLTFScenegraph,
|
|
58
58
|
GLTFWriter: () => GLTFWriter,
|
|
59
59
|
_getMemoryUsageGLTF: () => getMemoryUsageGLTF,
|
|
60
|
+
createExtMeshFeatures: () => createExtMeshFeatures,
|
|
61
|
+
createExtStructuralMetadata: () => createExtStructuralMetadata,
|
|
60
62
|
postProcessGLTF: () => postProcessGLTF
|
|
61
63
|
});
|
|
62
64
|
__reExport(bundle_exports, __toESM(require_core(), 1));
|
|
@@ -64,7 +66,9 @@ var __exports__ = (() => {
|
|
|
64
66
|
// src/lib/extensions/EXT_mesh_features.ts
|
|
65
67
|
var EXT_mesh_features_exports = {};
|
|
66
68
|
__export(EXT_mesh_features_exports, {
|
|
69
|
+
createExtMeshFeatures: () => createExtMeshFeatures,
|
|
67
70
|
decode: () => decode,
|
|
71
|
+
encode: () => encode,
|
|
68
72
|
name: () => name
|
|
69
73
|
});
|
|
70
74
|
|
|
@@ -1337,7 +1341,6 @@ var __exports__ = (() => {
|
|
|
1337
1341
|
}
|
|
1338
1342
|
/** Pack the binary chunk */
|
|
1339
1343
|
createBinaryChunk() {
|
|
1340
|
-
this.gltf.buffers = [];
|
|
1341
1344
|
const totalByteLength = this.byteLength;
|
|
1342
1345
|
const arrayBuffer = new ArrayBuffer(totalByteLength);
|
|
1343
1346
|
const targetArray = new Uint8Array(arrayBuffer);
|
|
@@ -1352,6 +1355,7 @@ var __exports__ = (() => {
|
|
|
1352
1355
|
}
|
|
1353
1356
|
this.gltf.binary = arrayBuffer;
|
|
1354
1357
|
this.sourceBuffers = [arrayBuffer];
|
|
1358
|
+
this.gltf.buffers = [{ arrayBuffer, byteOffset: 0, byteLength: arrayBuffer.byteLength }];
|
|
1355
1359
|
}
|
|
1356
1360
|
// PRIVATE
|
|
1357
1361
|
_removeStringFromArray(array, string) {
|
|
@@ -1657,6 +1661,12 @@ var __exports__ = (() => {
|
|
|
1657
1661
|
const scenegraph = new GLTFScenegraph(gltfData);
|
|
1658
1662
|
decodeExtMeshFeatures(scenegraph, options);
|
|
1659
1663
|
}
|
|
1664
|
+
function encode(gltfData, options) {
|
|
1665
|
+
const scenegraph = new GLTFScenegraph(gltfData);
|
|
1666
|
+
encodeExtMeshFeatures(scenegraph, options);
|
|
1667
|
+
scenegraph.createBinaryChunk();
|
|
1668
|
+
return scenegraph.gltf;
|
|
1669
|
+
}
|
|
1660
1670
|
function decodeExtMeshFeatures(scenegraph, options) {
|
|
1661
1671
|
const json = scenegraph.gltf.json;
|
|
1662
1672
|
if (!json.meshes) {
|
|
@@ -1691,11 +1701,86 @@ var __exports__ = (() => {
|
|
|
1691
1701
|
featureId.data = featureIdData;
|
|
1692
1702
|
}
|
|
1693
1703
|
}
|
|
1704
|
+
function encodeExtMeshFeatures(scenegraph, options) {
|
|
1705
|
+
const meshes = scenegraph.gltf.json.meshes;
|
|
1706
|
+
if (!meshes) {
|
|
1707
|
+
return;
|
|
1708
|
+
}
|
|
1709
|
+
for (const mesh of meshes) {
|
|
1710
|
+
for (const primitive of mesh.primitives) {
|
|
1711
|
+
encodeExtMeshFeaturesForPrimitive(scenegraph, primitive);
|
|
1712
|
+
}
|
|
1713
|
+
}
|
|
1714
|
+
}
|
|
1715
|
+
function createExtMeshFeatures(scenegraph, primitive, featureIdArray, propertyTableIndex) {
|
|
1716
|
+
if (!primitive.extensions) {
|
|
1717
|
+
primitive.extensions = {};
|
|
1718
|
+
}
|
|
1719
|
+
let extension = primitive.extensions[EXT_MESH_FEATURES_NAME];
|
|
1720
|
+
if (!extension) {
|
|
1721
|
+
extension = { featureIds: [] };
|
|
1722
|
+
primitive.extensions[EXT_MESH_FEATURES_NAME] = extension;
|
|
1723
|
+
}
|
|
1724
|
+
const { featureIds } = extension;
|
|
1725
|
+
const featureId = {
|
|
1726
|
+
featureCount: featureIdArray.length,
|
|
1727
|
+
propertyTable: propertyTableIndex,
|
|
1728
|
+
data: featureIdArray
|
|
1729
|
+
};
|
|
1730
|
+
featureIds.push(featureId);
|
|
1731
|
+
scenegraph.addObjectExtension(primitive, EXT_MESH_FEATURES_NAME, extension);
|
|
1732
|
+
}
|
|
1733
|
+
function encodeExtMeshFeaturesForPrimitive(scenegraph, primitive) {
|
|
1734
|
+
const extension = primitive.extensions?.[EXT_MESH_FEATURES_NAME];
|
|
1735
|
+
if (!extension) {
|
|
1736
|
+
return;
|
|
1737
|
+
}
|
|
1738
|
+
const featureIds = extension.featureIds;
|
|
1739
|
+
featureIds.forEach((featureId, elementIndex) => {
|
|
1740
|
+
if (featureId.data) {
|
|
1741
|
+
const { accessorKey, index } = createAccessorKey(primitive.attributes);
|
|
1742
|
+
const typedArray = new Uint32Array(featureId.data);
|
|
1743
|
+
featureIds[elementIndex] = {
|
|
1744
|
+
featureCount: typedArray.length,
|
|
1745
|
+
propertyTable: featureId.propertyTable,
|
|
1746
|
+
attribute: index
|
|
1747
|
+
};
|
|
1748
|
+
scenegraph.gltf.buffers.push({
|
|
1749
|
+
arrayBuffer: typedArray.buffer,
|
|
1750
|
+
byteOffset: typedArray.byteOffset,
|
|
1751
|
+
byteLength: typedArray.byteLength
|
|
1752
|
+
});
|
|
1753
|
+
const bufferViewIndex = scenegraph.addBufferView(typedArray);
|
|
1754
|
+
const accessorIndex = scenegraph.addAccessor(bufferViewIndex, {
|
|
1755
|
+
size: 1,
|
|
1756
|
+
componentType: getComponentTypeFromArray(typedArray),
|
|
1757
|
+
count: typedArray.length
|
|
1758
|
+
});
|
|
1759
|
+
primitive.attributes[accessorKey] = accessorIndex;
|
|
1760
|
+
}
|
|
1761
|
+
});
|
|
1762
|
+
}
|
|
1763
|
+
function createAccessorKey(attributes) {
|
|
1764
|
+
const prefix = "_FEATURE_ID_";
|
|
1765
|
+
const attrs = Object.keys(attributes).filter((item) => item.indexOf(prefix) === 0);
|
|
1766
|
+
let max = -1;
|
|
1767
|
+
for (const a of attrs) {
|
|
1768
|
+
const n = Number(a.substring(prefix.length));
|
|
1769
|
+
if (n > max) {
|
|
1770
|
+
max = n;
|
|
1771
|
+
}
|
|
1772
|
+
}
|
|
1773
|
+
max++;
|
|
1774
|
+
const accessorKey = `${prefix}${max}`;
|
|
1775
|
+
return { accessorKey, index: max };
|
|
1776
|
+
}
|
|
1694
1777
|
|
|
1695
1778
|
// src/lib/extensions/EXT_structural_metadata.ts
|
|
1696
1779
|
var EXT_structural_metadata_exports = {};
|
|
1697
1780
|
__export(EXT_structural_metadata_exports, {
|
|
1781
|
+
createExtStructuralMetadata: () => createExtStructuralMetadata,
|
|
1698
1782
|
decode: () => decode2,
|
|
1783
|
+
encode: () => encode2,
|
|
1699
1784
|
name: () => name2
|
|
1700
1785
|
});
|
|
1701
1786
|
var EXT_STRUCTURAL_METADATA_NAME = "EXT_structural_metadata";
|
|
@@ -1704,6 +1789,12 @@ var __exports__ = (() => {
|
|
|
1704
1789
|
const scenegraph = new GLTFScenegraph(gltfData);
|
|
1705
1790
|
decodeExtStructuralMetadata(scenegraph, options);
|
|
1706
1791
|
}
|
|
1792
|
+
function encode2(gltfData, options) {
|
|
1793
|
+
const scenegraph = new GLTFScenegraph(gltfData);
|
|
1794
|
+
encodeExtStructuralMetadata(scenegraph, options);
|
|
1795
|
+
scenegraph.createBinaryChunk();
|
|
1796
|
+
return scenegraph.gltf;
|
|
1797
|
+
}
|
|
1707
1798
|
function decodeExtStructuralMetadata(scenegraph, options) {
|
|
1708
1799
|
if (!options.gltf?.loadBuffers) {
|
|
1709
1800
|
return;
|
|
@@ -2036,6 +2127,161 @@ var __exports__ = (() => {
|
|
|
2036
2127
|
}
|
|
2037
2128
|
return null;
|
|
2038
2129
|
}
|
|
2130
|
+
var SCHEMA_CLASS_ID_DEFAULT = "schemaClassId";
|
|
2131
|
+
function encodeExtStructuralMetadata(scenegraph, options) {
|
|
2132
|
+
const extension = scenegraph.getExtension(
|
|
2133
|
+
EXT_STRUCTURAL_METADATA_NAME
|
|
2134
|
+
);
|
|
2135
|
+
if (!extension) {
|
|
2136
|
+
return;
|
|
2137
|
+
}
|
|
2138
|
+
if (extension.propertyTables) {
|
|
2139
|
+
for (const table of extension.propertyTables) {
|
|
2140
|
+
const classId = table.class;
|
|
2141
|
+
const schemaClass = extension.schema?.classes?.[classId];
|
|
2142
|
+
if (table.properties && schemaClass) {
|
|
2143
|
+
encodeProperties(table, schemaClass, scenegraph);
|
|
2144
|
+
}
|
|
2145
|
+
}
|
|
2146
|
+
}
|
|
2147
|
+
}
|
|
2148
|
+
function encodeProperties(table, schemaClass, scenegraph) {
|
|
2149
|
+
for (const propertyName in table.properties) {
|
|
2150
|
+
const data = table.properties[propertyName].data;
|
|
2151
|
+
if (data) {
|
|
2152
|
+
const classProperty = schemaClass.properties[propertyName];
|
|
2153
|
+
if (classProperty) {
|
|
2154
|
+
const tableProperty = createPropertyTableProperty(
|
|
2155
|
+
data,
|
|
2156
|
+
classProperty,
|
|
2157
|
+
scenegraph
|
|
2158
|
+
);
|
|
2159
|
+
table.properties[propertyName] = tableProperty;
|
|
2160
|
+
}
|
|
2161
|
+
}
|
|
2162
|
+
}
|
|
2163
|
+
}
|
|
2164
|
+
function createExtStructuralMetadata(scenegraph, propertyAttributes, classId = SCHEMA_CLASS_ID_DEFAULT) {
|
|
2165
|
+
let extension = scenegraph.getExtension(
|
|
2166
|
+
EXT_STRUCTURAL_METADATA_NAME
|
|
2167
|
+
);
|
|
2168
|
+
if (!extension) {
|
|
2169
|
+
extension = scenegraph.addExtension(EXT_STRUCTURAL_METADATA_NAME);
|
|
2170
|
+
}
|
|
2171
|
+
extension.schema = createSchema(propertyAttributes, classId, extension.schema);
|
|
2172
|
+
const table = createPropertyTable(propertyAttributes, classId, extension.schema);
|
|
2173
|
+
if (!extension.propertyTables) {
|
|
2174
|
+
extension.propertyTables = [];
|
|
2175
|
+
}
|
|
2176
|
+
return extension.propertyTables.push(table) - 1;
|
|
2177
|
+
}
|
|
2178
|
+
function createSchema(propertyAttributes, classId, schemaToUpdate) {
|
|
2179
|
+
const schema = schemaToUpdate ?? {
|
|
2180
|
+
id: "schema_id"
|
|
2181
|
+
};
|
|
2182
|
+
const schemaClass = {
|
|
2183
|
+
properties: {}
|
|
2184
|
+
};
|
|
2185
|
+
for (const attribute of propertyAttributes) {
|
|
2186
|
+
const classProperty = {
|
|
2187
|
+
type: attribute.elementType,
|
|
2188
|
+
componentType: attribute.componentType
|
|
2189
|
+
};
|
|
2190
|
+
schemaClass.properties[attribute.name] = classProperty;
|
|
2191
|
+
}
|
|
2192
|
+
schema.classes = {};
|
|
2193
|
+
schema.classes[classId] = schemaClass;
|
|
2194
|
+
return schema;
|
|
2195
|
+
}
|
|
2196
|
+
function createPropertyTable(propertyAttributes, classId, schema) {
|
|
2197
|
+
const table = {
|
|
2198
|
+
class: classId,
|
|
2199
|
+
count: 0
|
|
2200
|
+
};
|
|
2201
|
+
let count = 0;
|
|
2202
|
+
const schemaClass = schema.classes?.[classId];
|
|
2203
|
+
for (const attribute of propertyAttributes) {
|
|
2204
|
+
if (count === 0) {
|
|
2205
|
+
count = attribute.values.length;
|
|
2206
|
+
}
|
|
2207
|
+
if (count !== attribute.values.length && attribute.values.length) {
|
|
2208
|
+
throw new Error("Illegal values in attributes");
|
|
2209
|
+
}
|
|
2210
|
+
const classProperty = schemaClass?.properties[attribute.name];
|
|
2211
|
+
if (classProperty) {
|
|
2212
|
+
if (!table.properties) {
|
|
2213
|
+
table.properties = {};
|
|
2214
|
+
}
|
|
2215
|
+
table.properties[attribute.name] = { values: 0, data: attribute.values };
|
|
2216
|
+
}
|
|
2217
|
+
}
|
|
2218
|
+
table.count = count;
|
|
2219
|
+
return table;
|
|
2220
|
+
}
|
|
2221
|
+
function createPropertyTableProperty(values, classProperty, scenegraph) {
|
|
2222
|
+
const prop = { values: 0 };
|
|
2223
|
+
if (classProperty.type === "STRING") {
|
|
2224
|
+
const { stringData, stringOffsets } = createPropertyDataString(values);
|
|
2225
|
+
prop.stringOffsets = createBufferView(stringOffsets, scenegraph);
|
|
2226
|
+
prop.values = createBufferView(stringData, scenegraph);
|
|
2227
|
+
} else if (classProperty.type === "SCALAR" && classProperty.componentType) {
|
|
2228
|
+
const data = createPropertyDataScalar(values, classProperty.componentType);
|
|
2229
|
+
prop.values = createBufferView(data, scenegraph);
|
|
2230
|
+
}
|
|
2231
|
+
return prop;
|
|
2232
|
+
}
|
|
2233
|
+
var COMPONENT_TYPE_TO_ARRAY_CONSTRUCTOR = {
|
|
2234
|
+
INT8: Int8Array,
|
|
2235
|
+
UINT8: Uint8Array,
|
|
2236
|
+
INT16: Int16Array,
|
|
2237
|
+
UINT16: Uint16Array,
|
|
2238
|
+
INT32: Int32Array,
|
|
2239
|
+
UINT32: Uint32Array,
|
|
2240
|
+
INT64: Int32Array,
|
|
2241
|
+
UINT64: Uint32Array,
|
|
2242
|
+
FLOAT32: Float32Array,
|
|
2243
|
+
FLOAT64: Float64Array
|
|
2244
|
+
};
|
|
2245
|
+
function createPropertyDataScalar(array, componentType) {
|
|
2246
|
+
const numberArray = [];
|
|
2247
|
+
for (const value of array) {
|
|
2248
|
+
numberArray.push(Number(value));
|
|
2249
|
+
}
|
|
2250
|
+
const Construct = COMPONENT_TYPE_TO_ARRAY_CONSTRUCTOR[componentType];
|
|
2251
|
+
if (!Construct) {
|
|
2252
|
+
throw new Error("Illegal component type");
|
|
2253
|
+
}
|
|
2254
|
+
return new Construct(numberArray);
|
|
2255
|
+
}
|
|
2256
|
+
function createPropertyDataString(strings) {
|
|
2257
|
+
const utf8Encode = new TextEncoder();
|
|
2258
|
+
const arr = [];
|
|
2259
|
+
let len = 0;
|
|
2260
|
+
for (const str of strings) {
|
|
2261
|
+
const uint8Array = utf8Encode.encode(str);
|
|
2262
|
+
len += uint8Array.length;
|
|
2263
|
+
arr.push(uint8Array);
|
|
2264
|
+
}
|
|
2265
|
+
const strArray = new Uint8Array(len);
|
|
2266
|
+
const strOffsets = [];
|
|
2267
|
+
let offset = 0;
|
|
2268
|
+
for (const str of arr) {
|
|
2269
|
+
strArray.set(str, offset);
|
|
2270
|
+
strOffsets.push(offset);
|
|
2271
|
+
offset += str.length;
|
|
2272
|
+
}
|
|
2273
|
+
strOffsets.push(offset);
|
|
2274
|
+
const stringOffsetsTypedArray = new Uint32Array(strOffsets);
|
|
2275
|
+
return { stringData: strArray, stringOffsets: stringOffsetsTypedArray };
|
|
2276
|
+
}
|
|
2277
|
+
function createBufferView(typedArray, scenegraph) {
|
|
2278
|
+
scenegraph.gltf.buffers.push({
|
|
2279
|
+
arrayBuffer: typedArray.buffer,
|
|
2280
|
+
byteOffset: typedArray.byteOffset,
|
|
2281
|
+
byteLength: typedArray.byteLength
|
|
2282
|
+
});
|
|
2283
|
+
return scenegraph.addBufferView(typedArray);
|
|
2284
|
+
}
|
|
2039
2285
|
|
|
2040
2286
|
// src/lib/extensions/deprecated/EXT_feature_metadata.ts
|
|
2041
2287
|
var EXT_feature_metadata_exports = {};
|
|
@@ -3165,7 +3411,7 @@ var __exports__ = (() => {
|
|
|
3165
3411
|
var KHR_draco_mesh_compression_exports = {};
|
|
3166
3412
|
__export(KHR_draco_mesh_compression_exports, {
|
|
3167
3413
|
decode: () => decode6,
|
|
3168
|
-
encode: () =>
|
|
3414
|
+
encode: () => encode3,
|
|
3169
3415
|
name: () => name7,
|
|
3170
3416
|
preprocess: () => preprocess3
|
|
3171
3417
|
});
|
|
@@ -3946,7 +4192,7 @@ var __exports__ = (() => {
|
|
|
3946
4192
|
await Promise.all(promises);
|
|
3947
4193
|
scenegraph.removeExtension(KHR_DRACO_MESH_COMPRESSION);
|
|
3948
4194
|
}
|
|
3949
|
-
function
|
|
4195
|
+
function encode3(gltfData, options = {}) {
|
|
3950
4196
|
const scenegraph = new GLTFScenegraph(gltfData);
|
|
3951
4197
|
for (const mesh of scenegraph.json.meshes || []) {
|
|
3952
4198
|
compressMesh(mesh, options);
|
|
@@ -4043,17 +4289,11 @@ var __exports__ = (() => {
|
|
|
4043
4289
|
printRowMajor: true,
|
|
4044
4290
|
_cartographicRadians: false
|
|
4045
4291
|
};
|
|
4046
|
-
globalThis.mathgl = globalThis.mathgl || {
|
|
4047
|
-
config: {
|
|
4048
|
-
...DEFAULT_CONFIG
|
|
4049
|
-
}
|
|
4050
|
-
};
|
|
4292
|
+
globalThis.mathgl = globalThis.mathgl || { config: { ...DEFAULT_CONFIG } };
|
|
4051
4293
|
var config = globalThis.mathgl.config;
|
|
4052
|
-
function formatValue(value, {
|
|
4053
|
-
precision = config.precision
|
|
4054
|
-
} = {}) {
|
|
4294
|
+
function formatValue(value, { precision = config.precision } = {}) {
|
|
4055
4295
|
value = round(value);
|
|
4056
|
-
return
|
|
4296
|
+
return `${parseFloat(value.toPrecision(precision))}`;
|
|
4057
4297
|
}
|
|
4058
4298
|
function isArray(value) {
|
|
4059
4299
|
return Array.isArray(value) || ArrayBuffer.isView(value) && !(value instanceof DataView);
|
|
@@ -4097,28 +4337,12 @@ var __exports__ = (() => {
|
|
|
4097
4337
|
}
|
|
4098
4338
|
|
|
4099
4339
|
// ../../node_modules/@math.gl/core/dist/classes/base/math-array.js
|
|
4100
|
-
|
|
4101
|
-
|
|
4102
|
-
|
|
4103
|
-
|
|
4104
|
-
|
|
4105
|
-
|
|
4106
|
-
ExtendableBuiltin.prototype = Object.create(cls.prototype, {
|
|
4107
|
-
constructor: {
|
|
4108
|
-
value: cls,
|
|
4109
|
-
enumerable: false,
|
|
4110
|
-
writable: true,
|
|
4111
|
-
configurable: true
|
|
4112
|
-
}
|
|
4113
|
-
});
|
|
4114
|
-
if (Object.setPrototypeOf) {
|
|
4115
|
-
Object.setPrototypeOf(ExtendableBuiltin, cls);
|
|
4116
|
-
} else {
|
|
4117
|
-
ExtendableBuiltin.__proto__ = cls;
|
|
4118
|
-
}
|
|
4119
|
-
return ExtendableBuiltin;
|
|
4120
|
-
}
|
|
4121
|
-
var MathArray = class extends _extendableBuiltin(Array) {
|
|
4340
|
+
var MathArray = class extends Array {
|
|
4341
|
+
// Common methods
|
|
4342
|
+
/**
|
|
4343
|
+
* Clone the current object
|
|
4344
|
+
* @returns a new copy of this object
|
|
4345
|
+
*/
|
|
4122
4346
|
clone() {
|
|
4123
4347
|
return new this.constructor().copy(this);
|
|
4124
4348
|
}
|
|
@@ -4138,7 +4362,10 @@ var __exports__ = (() => {
|
|
|
4138
4362
|
return targetObject;
|
|
4139
4363
|
}
|
|
4140
4364
|
from(arrayOrObject) {
|
|
4141
|
-
return Array.isArray(arrayOrObject) ? this.copy(arrayOrObject) :
|
|
4365
|
+
return Array.isArray(arrayOrObject) ? this.copy(arrayOrObject) : (
|
|
4366
|
+
// @ts-ignore
|
|
4367
|
+
this.fromObject(arrayOrObject)
|
|
4368
|
+
);
|
|
4142
4369
|
}
|
|
4143
4370
|
to(arrayOrObject) {
|
|
4144
4371
|
if (arrayOrObject === this) {
|
|
@@ -4149,18 +4376,20 @@ var __exports__ = (() => {
|
|
|
4149
4376
|
toTarget(target) {
|
|
4150
4377
|
return target ? this.to(target) : this;
|
|
4151
4378
|
}
|
|
4379
|
+
/** @deprecated */
|
|
4152
4380
|
toFloat32Array() {
|
|
4153
4381
|
return new Float32Array(this);
|
|
4154
4382
|
}
|
|
4155
4383
|
toString() {
|
|
4156
4384
|
return this.formatString(config);
|
|
4157
4385
|
}
|
|
4386
|
+
/** Formats string according to options */
|
|
4158
4387
|
formatString(opts) {
|
|
4159
4388
|
let string = "";
|
|
4160
4389
|
for (let i = 0; i < this.ELEMENTS; ++i) {
|
|
4161
4390
|
string += (i > 0 ? ", " : "") + formatValue(this[i], opts);
|
|
4162
4391
|
}
|
|
4163
|
-
return
|
|
4392
|
+
return `${opts.printTypes ? this.constructor.name : ""}[${string}]`;
|
|
4164
4393
|
}
|
|
4165
4394
|
equals(array) {
|
|
4166
4395
|
if (!array || this.length !== array.length) {
|
|
@@ -4184,6 +4413,8 @@ var __exports__ = (() => {
|
|
|
4184
4413
|
}
|
|
4185
4414
|
return true;
|
|
4186
4415
|
}
|
|
4416
|
+
// Modifiers
|
|
4417
|
+
/** Negates all values in this object */
|
|
4187
4418
|
negate() {
|
|
4188
4419
|
for (let i = 0; i < this.ELEMENTS; ++i) {
|
|
4189
4420
|
this[i] = -this[i];
|
|
@@ -4201,12 +4432,14 @@ var __exports__ = (() => {
|
|
|
4201
4432
|
}
|
|
4202
4433
|
return this.check();
|
|
4203
4434
|
}
|
|
4435
|
+
/** Minimal */
|
|
4204
4436
|
min(vector) {
|
|
4205
4437
|
for (let i = 0; i < this.ELEMENTS; ++i) {
|
|
4206
4438
|
this[i] = Math.min(vector[i], this[i]);
|
|
4207
4439
|
}
|
|
4208
4440
|
return this.check();
|
|
4209
4441
|
}
|
|
4442
|
+
/** Maximal */
|
|
4210
4443
|
max(vector) {
|
|
4211
4444
|
for (let i = 0; i < this.ELEMENTS; ++i) {
|
|
4212
4445
|
this[i] = Math.max(vector[i], this[i]);
|
|
@@ -4247,18 +4480,25 @@ var __exports__ = (() => {
|
|
|
4247
4480
|
}
|
|
4248
4481
|
return this.check();
|
|
4249
4482
|
}
|
|
4483
|
+
/**
|
|
4484
|
+
* Multiplies all elements by `scale`
|
|
4485
|
+
* Note: `Matrix4.multiplyByScalar` only scales its 3x3 "minor"
|
|
4486
|
+
*/
|
|
4250
4487
|
multiplyByScalar(scalar) {
|
|
4251
4488
|
for (let i = 0; i < this.ELEMENTS; ++i) {
|
|
4252
4489
|
this[i] *= scalar;
|
|
4253
4490
|
}
|
|
4254
4491
|
return this.check();
|
|
4255
4492
|
}
|
|
4493
|
+
// Debug checks
|
|
4494
|
+
/** Throws an error if array length is incorrect or contains illegal values */
|
|
4256
4495
|
check() {
|
|
4257
4496
|
if (config.debug && !this.validate()) {
|
|
4258
|
-
throw new Error(
|
|
4497
|
+
throw new Error(`math.gl: ${this.constructor.name} some fields set to invalid numbers'`);
|
|
4259
4498
|
}
|
|
4260
4499
|
return this;
|
|
4261
4500
|
}
|
|
4501
|
+
/** Returns false if the array length is incorrect or contains illegal values */
|
|
4262
4502
|
validate() {
|
|
4263
4503
|
let valid = this.length === this.ELEMENTS;
|
|
4264
4504
|
for (let i = 0; i < this.ELEMENTS; ++i) {
|
|
@@ -4266,39 +4506,48 @@ var __exports__ = (() => {
|
|
|
4266
4506
|
}
|
|
4267
4507
|
return valid;
|
|
4268
4508
|
}
|
|
4509
|
+
// three.js compatibility
|
|
4510
|
+
/** @deprecated */
|
|
4269
4511
|
sub(a) {
|
|
4270
4512
|
return this.subtract(a);
|
|
4271
4513
|
}
|
|
4514
|
+
/** @deprecated */
|
|
4272
4515
|
setScalar(a) {
|
|
4273
4516
|
for (let i = 0; i < this.ELEMENTS; ++i) {
|
|
4274
4517
|
this[i] = a;
|
|
4275
4518
|
}
|
|
4276
4519
|
return this.check();
|
|
4277
4520
|
}
|
|
4521
|
+
/** @deprecated */
|
|
4278
4522
|
addScalar(a) {
|
|
4279
4523
|
for (let i = 0; i < this.ELEMENTS; ++i) {
|
|
4280
4524
|
this[i] += a;
|
|
4281
4525
|
}
|
|
4282
4526
|
return this.check();
|
|
4283
4527
|
}
|
|
4528
|
+
/** @deprecated */
|
|
4284
4529
|
subScalar(a) {
|
|
4285
4530
|
return this.addScalar(-a);
|
|
4286
4531
|
}
|
|
4532
|
+
/** @deprecated */
|
|
4287
4533
|
multiplyScalar(scalar) {
|
|
4288
4534
|
for (let i = 0; i < this.ELEMENTS; ++i) {
|
|
4289
4535
|
this[i] *= scalar;
|
|
4290
4536
|
}
|
|
4291
4537
|
return this.check();
|
|
4292
4538
|
}
|
|
4539
|
+
/** @deprecated */
|
|
4293
4540
|
divideScalar(a) {
|
|
4294
4541
|
return this.multiplyByScalar(1 / a);
|
|
4295
4542
|
}
|
|
4543
|
+
/** @deprecated */
|
|
4296
4544
|
clampScalar(min, max) {
|
|
4297
4545
|
for (let i = 0; i < this.ELEMENTS; ++i) {
|
|
4298
4546
|
this[i] = Math.min(Math.max(this[i], min), max);
|
|
4299
4547
|
}
|
|
4300
4548
|
return this.check();
|
|
4301
4549
|
}
|
|
4550
|
+
/** @deprecated */
|
|
4302
4551
|
get elements() {
|
|
4303
4552
|
return this;
|
|
4304
4553
|
}
|
|
@@ -4318,13 +4567,13 @@ var __exports__ = (() => {
|
|
|
4318
4567
|
}
|
|
4319
4568
|
function checkNumber(value) {
|
|
4320
4569
|
if (!Number.isFinite(value)) {
|
|
4321
|
-
throw new Error(
|
|
4570
|
+
throw new Error(`Invalid number ${JSON.stringify(value)}`);
|
|
4322
4571
|
}
|
|
4323
4572
|
return value;
|
|
4324
4573
|
}
|
|
4325
4574
|
function checkVector(v, length, callerName = "") {
|
|
4326
4575
|
if (config.debug && !validateVector(v, length)) {
|
|
4327
|
-
throw new Error(
|
|
4576
|
+
throw new Error(`math.gl: ${callerName} some fields set to invalid numbers'`);
|
|
4328
4577
|
}
|
|
4329
4578
|
return v;
|
|
4330
4579
|
}
|
|
@@ -4332,12 +4581,13 @@ var __exports__ = (() => {
|
|
|
4332
4581
|
// ../../node_modules/@math.gl/core/dist/lib/assert.js
|
|
4333
4582
|
function assert4(condition, message) {
|
|
4334
4583
|
if (!condition) {
|
|
4335
|
-
throw new Error(
|
|
4584
|
+
throw new Error(`math.gl assertion ${message}`);
|
|
4336
4585
|
}
|
|
4337
4586
|
}
|
|
4338
4587
|
|
|
4339
4588
|
// ../../node_modules/@math.gl/core/dist/classes/base/vector.js
|
|
4340
4589
|
var Vector = class extends MathArray {
|
|
4590
|
+
// ACCESSORS
|
|
4341
4591
|
get x() {
|
|
4342
4592
|
return this[0];
|
|
4343
4593
|
}
|
|
@@ -4350,12 +4600,24 @@ var __exports__ = (() => {
|
|
|
4350
4600
|
set y(value) {
|
|
4351
4601
|
this[1] = checkNumber(value);
|
|
4352
4602
|
}
|
|
4603
|
+
/**
|
|
4604
|
+
* Returns the length of the vector from the origin to the point described by this vector
|
|
4605
|
+
*
|
|
4606
|
+
* @note `length` is a reserved word for Arrays, so `v.length()` will return number of elements
|
|
4607
|
+
* Instead we provide `len` and `magnitude`
|
|
4608
|
+
*/
|
|
4353
4609
|
len() {
|
|
4354
4610
|
return Math.sqrt(this.lengthSquared());
|
|
4355
4611
|
}
|
|
4612
|
+
/**
|
|
4613
|
+
* Returns the length of the vector from the origin to the point described by this vector
|
|
4614
|
+
*/
|
|
4356
4615
|
magnitude() {
|
|
4357
4616
|
return this.len();
|
|
4358
4617
|
}
|
|
4618
|
+
/**
|
|
4619
|
+
* Returns the squared length of the vector from the origin to the point described by this vector
|
|
4620
|
+
*/
|
|
4359
4621
|
lengthSquared() {
|
|
4360
4622
|
let length = 0;
|
|
4361
4623
|
for (let i = 0; i < this.ELEMENTS; ++i) {
|
|
@@ -4363,6 +4625,9 @@ var __exports__ = (() => {
|
|
|
4363
4625
|
}
|
|
4364
4626
|
return length;
|
|
4365
4627
|
}
|
|
4628
|
+
/**
|
|
4629
|
+
* Returns the squared length of the vector from the origin to the point described by this vector
|
|
4630
|
+
*/
|
|
4366
4631
|
magnitudeSquared() {
|
|
4367
4632
|
return this.lengthSquared();
|
|
4368
4633
|
}
|
|
@@ -4384,6 +4649,7 @@ var __exports__ = (() => {
|
|
|
4384
4649
|
}
|
|
4385
4650
|
return checkNumber(product);
|
|
4386
4651
|
}
|
|
4652
|
+
// MODIFIERS
|
|
4387
4653
|
normalize() {
|
|
4388
4654
|
const length = this.magnitude();
|
|
4389
4655
|
if (length !== 0) {
|
|
@@ -4409,6 +4675,7 @@ var __exports__ = (() => {
|
|
|
4409
4675
|
}
|
|
4410
4676
|
return this.check();
|
|
4411
4677
|
}
|
|
4678
|
+
// THREE.js compatibility
|
|
4412
4679
|
lengthSq() {
|
|
4413
4680
|
return this.lengthSquared();
|
|
4414
4681
|
}
|
|
@@ -4682,6 +4949,12 @@ var __exports__ = (() => {
|
|
|
4682
4949
|
}
|
|
4683
4950
|
return ZERO;
|
|
4684
4951
|
}
|
|
4952
|
+
/**
|
|
4953
|
+
* @class
|
|
4954
|
+
* @param x
|
|
4955
|
+
* @param y
|
|
4956
|
+
* @param z
|
|
4957
|
+
*/
|
|
4685
4958
|
constructor(x = 0, y = 0, z = 0) {
|
|
4686
4959
|
super(-0, -0, -0);
|
|
4687
4960
|
if (arguments.length === 1 && isArray(x)) {
|
|
@@ -4726,6 +4999,7 @@ var __exports__ = (() => {
|
|
|
4726
4999
|
object.z = this[2];
|
|
4727
5000
|
return object;
|
|
4728
5001
|
}
|
|
5002
|
+
// Getters/setters
|
|
4729
5003
|
get ELEMENTS() {
|
|
4730
5004
|
return 3;
|
|
4731
5005
|
}
|
|
@@ -4735,41 +5009,38 @@ var __exports__ = (() => {
|
|
|
4735
5009
|
set z(value) {
|
|
4736
5010
|
this[2] = checkNumber(value);
|
|
4737
5011
|
}
|
|
5012
|
+
// ACCESSORS
|
|
4738
5013
|
angle(vector) {
|
|
4739
5014
|
return angle(this, vector);
|
|
4740
5015
|
}
|
|
5016
|
+
// MODIFIERS
|
|
4741
5017
|
cross(vector) {
|
|
4742
5018
|
cross(this, this, vector);
|
|
4743
5019
|
return this.check();
|
|
4744
5020
|
}
|
|
4745
|
-
rotateX({
|
|
4746
|
-
radians,
|
|
4747
|
-
origin = ORIGIN
|
|
4748
|
-
}) {
|
|
5021
|
+
rotateX({ radians, origin = ORIGIN }) {
|
|
4749
5022
|
rotateX(this, this, origin, radians);
|
|
4750
5023
|
return this.check();
|
|
4751
5024
|
}
|
|
4752
|
-
rotateY({
|
|
4753
|
-
radians,
|
|
4754
|
-
origin = ORIGIN
|
|
4755
|
-
}) {
|
|
5025
|
+
rotateY({ radians, origin = ORIGIN }) {
|
|
4756
5026
|
rotateY(this, this, origin, radians);
|
|
4757
5027
|
return this.check();
|
|
4758
5028
|
}
|
|
4759
|
-
rotateZ({
|
|
4760
|
-
radians,
|
|
4761
|
-
origin = ORIGIN
|
|
4762
|
-
}) {
|
|
5029
|
+
rotateZ({ radians, origin = ORIGIN }) {
|
|
4763
5030
|
rotateZ(this, this, origin, radians);
|
|
4764
5031
|
return this.check();
|
|
4765
5032
|
}
|
|
5033
|
+
// Transforms
|
|
5034
|
+
// transforms as point (4th component is implicitly 1)
|
|
4766
5035
|
transform(matrix4) {
|
|
4767
5036
|
return this.transformAsPoint(matrix4);
|
|
4768
5037
|
}
|
|
5038
|
+
// transforms as point (4th component is implicitly 1)
|
|
4769
5039
|
transformAsPoint(matrix4) {
|
|
4770
5040
|
transformMat4(this, this, matrix4);
|
|
4771
5041
|
return this.check();
|
|
4772
5042
|
}
|
|
5043
|
+
// transforms as vector (4th component is implicitly 0, ignores translation. slightly faster)
|
|
4773
5044
|
transformAsVector(matrix4) {
|
|
4774
5045
|
vec3_transformMat4AsVector(this, this, matrix4);
|
|
4775
5046
|
return this.check();
|
|
@@ -4790,19 +5061,29 @@ var __exports__ = (() => {
|
|
|
4790
5061
|
|
|
4791
5062
|
// ../../node_modules/@math.gl/core/dist/classes/base/matrix.js
|
|
4792
5063
|
var Matrix = class extends MathArray {
|
|
5064
|
+
// fromObject(object) {
|
|
5065
|
+
// const array = object.elements;
|
|
5066
|
+
// return this.fromRowMajor(array);
|
|
5067
|
+
// }
|
|
5068
|
+
// toObject(object) {
|
|
5069
|
+
// const array = object.elements;
|
|
5070
|
+
// this.toRowMajor(array);
|
|
5071
|
+
// return object;
|
|
5072
|
+
// }
|
|
5073
|
+
// TODO better override formatString?
|
|
4793
5074
|
toString() {
|
|
4794
5075
|
let string = "[";
|
|
4795
5076
|
if (config.printRowMajor) {
|
|
4796
5077
|
string += "row-major:";
|
|
4797
5078
|
for (let row = 0; row < this.RANK; ++row) {
|
|
4798
5079
|
for (let col = 0; col < this.RANK; ++col) {
|
|
4799
|
-
string +=
|
|
5080
|
+
string += ` ${this[col * this.RANK + row]}`;
|
|
4800
5081
|
}
|
|
4801
5082
|
}
|
|
4802
5083
|
} else {
|
|
4803
5084
|
string += "column-major:";
|
|
4804
5085
|
for (let i = 0; i < this.ELEMENTS; ++i) {
|
|
4805
|
-
string +=
|
|
5086
|
+
string += ` ${this[i]}`;
|
|
4806
5087
|
}
|
|
4807
5088
|
}
|
|
4808
5089
|
string += "]";
|
|
@@ -4811,9 +5092,11 @@ var __exports__ = (() => {
|
|
|
4811
5092
|
getElementIndex(row, col) {
|
|
4812
5093
|
return col * this.RANK + row;
|
|
4813
5094
|
}
|
|
5095
|
+
// By default assumes row major indices
|
|
4814
5096
|
getElement(row, col) {
|
|
4815
5097
|
return this[col * this.RANK + row];
|
|
4816
5098
|
}
|
|
5099
|
+
// By default assumes row major indices
|
|
4817
5100
|
setElement(row, col, value) {
|
|
4818
5101
|
this[col * this.RANK + row] = checkNumber(value);
|
|
4819
5102
|
return this;
|
|
@@ -5071,16 +5354,30 @@ var __exports__ = (() => {
|
|
|
5071
5354
|
this[8] = array[8];
|
|
5072
5355
|
return this.check();
|
|
5073
5356
|
}
|
|
5357
|
+
// Constructors
|
|
5074
5358
|
identity() {
|
|
5075
5359
|
return this.copy(IDENTITY_MATRIX);
|
|
5076
5360
|
}
|
|
5361
|
+
/**
|
|
5362
|
+
*
|
|
5363
|
+
* @param object
|
|
5364
|
+
* @returns self
|
|
5365
|
+
*/
|
|
5366
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
5077
5367
|
fromObject(object) {
|
|
5078
5368
|
return this.check();
|
|
5079
5369
|
}
|
|
5370
|
+
/** Calculates a 3x3 matrix from the given quaternion
|
|
5371
|
+
* q quat Quaternion to create matrix from
|
|
5372
|
+
*/
|
|
5080
5373
|
fromQuaternion(q) {
|
|
5081
5374
|
fromQuat(this, q);
|
|
5082
5375
|
return this.check();
|
|
5083
5376
|
}
|
|
5377
|
+
/**
|
|
5378
|
+
* accepts column major order, stores in column major order
|
|
5379
|
+
*/
|
|
5380
|
+
// eslint-disable-next-line max-params
|
|
5084
5381
|
set(m00, m10, m20, m01, m11, m21, m02, m12, m22) {
|
|
5085
5382
|
this[0] = m00;
|
|
5086
5383
|
this[1] = m10;
|
|
@@ -5093,6 +5390,10 @@ var __exports__ = (() => {
|
|
|
5093
5390
|
this[8] = m22;
|
|
5094
5391
|
return this.check();
|
|
5095
5392
|
}
|
|
5393
|
+
/**
|
|
5394
|
+
* accepts row major order, stores as column major
|
|
5395
|
+
*/
|
|
5396
|
+
// eslint-disable-next-line max-params
|
|
5096
5397
|
setRowMajor(m00, m01, m02, m10, m11, m12, m20, m21, m22) {
|
|
5097
5398
|
this[0] = m00;
|
|
5098
5399
|
this[1] = m10;
|
|
@@ -5105,17 +5406,21 @@ var __exports__ = (() => {
|
|
|
5105
5406
|
this[8] = m22;
|
|
5106
5407
|
return this.check();
|
|
5107
5408
|
}
|
|
5409
|
+
// Accessors
|
|
5108
5410
|
determinant() {
|
|
5109
5411
|
return determinant(this);
|
|
5110
5412
|
}
|
|
5413
|
+
// Modifiers
|
|
5111
5414
|
transpose() {
|
|
5112
5415
|
transpose(this, this);
|
|
5113
5416
|
return this.check();
|
|
5114
5417
|
}
|
|
5418
|
+
/** Invert a matrix. Note that this can fail if the matrix is not invertible */
|
|
5115
5419
|
invert() {
|
|
5116
5420
|
invert(this, this);
|
|
5117
5421
|
return this.check();
|
|
5118
5422
|
}
|
|
5423
|
+
// Operations
|
|
5119
5424
|
multiplyLeft(a) {
|
|
5120
5425
|
multiply(this, a, this);
|
|
5121
5426
|
return this.check();
|
|
@@ -5140,6 +5445,7 @@ var __exports__ = (() => {
|
|
|
5140
5445
|
translate(this, this, vec);
|
|
5141
5446
|
return this.check();
|
|
5142
5447
|
}
|
|
5448
|
+
// Transforms
|
|
5143
5449
|
transform(vector, result) {
|
|
5144
5450
|
let out;
|
|
5145
5451
|
switch (vector.length) {
|
|
@@ -5158,12 +5464,15 @@ var __exports__ = (() => {
|
|
|
5158
5464
|
checkVector(out, vector.length);
|
|
5159
5465
|
return out;
|
|
5160
5466
|
}
|
|
5467
|
+
/** @deprecated */
|
|
5161
5468
|
transformVector(vector, result) {
|
|
5162
5469
|
return this.transform(vector, result);
|
|
5163
5470
|
}
|
|
5471
|
+
/** @deprecated */
|
|
5164
5472
|
transformVector2(vector, result) {
|
|
5165
5473
|
return this.transform(vector, result);
|
|
5166
5474
|
}
|
|
5475
|
+
/** @deprecated */
|
|
5167
5476
|
transformVector3(vector, result) {
|
|
5168
5477
|
return this.transform(vector, result);
|
|
5169
5478
|
}
|
|
@@ -5342,7 +5651,7 @@ var __exports__ = (() => {
|
|
|
5342
5651
|
var KHR_lights_punctual_exports = {};
|
|
5343
5652
|
__export(KHR_lights_punctual_exports, {
|
|
5344
5653
|
decode: () => decode8,
|
|
5345
|
-
encode: () =>
|
|
5654
|
+
encode: () => encode4,
|
|
5346
5655
|
name: () => name9
|
|
5347
5656
|
});
|
|
5348
5657
|
var KHR_LIGHTS_PUNCTUAL = "KHR_lights_punctual";
|
|
@@ -5363,7 +5672,7 @@ var __exports__ = (() => {
|
|
|
5363
5672
|
gltfScenegraph.removeObjectExtension(node, KHR_LIGHTS_PUNCTUAL);
|
|
5364
5673
|
}
|
|
5365
5674
|
}
|
|
5366
|
-
async function
|
|
5675
|
+
async function encode4(gltfData) {
|
|
5367
5676
|
const gltfScenegraph = new GLTFScenegraph(gltfData);
|
|
5368
5677
|
const { json } = gltfScenegraph;
|
|
5369
5678
|
if (json.lights) {
|
|
@@ -5385,7 +5694,7 @@ var __exports__ = (() => {
|
|
|
5385
5694
|
var KHR_materials_unlit_exports = {};
|
|
5386
5695
|
__export(KHR_materials_unlit_exports, {
|
|
5387
5696
|
decode: () => decode9,
|
|
5388
|
-
encode: () =>
|
|
5697
|
+
encode: () => encode5,
|
|
5389
5698
|
name: () => name10
|
|
5390
5699
|
});
|
|
5391
5700
|
var KHR_MATERIALS_UNLIT = "KHR_materials_unlit";
|
|
@@ -5402,7 +5711,7 @@ var __exports__ = (() => {
|
|
|
5402
5711
|
}
|
|
5403
5712
|
gltfScenegraph.removeExtension(KHR_MATERIALS_UNLIT);
|
|
5404
5713
|
}
|
|
5405
|
-
function
|
|
5714
|
+
function encode5(gltfData) {
|
|
5406
5715
|
const gltfScenegraph = new GLTFScenegraph(gltfData);
|
|
5407
5716
|
const { json } = gltfScenegraph;
|
|
5408
5717
|
if (gltfScenegraph.materials) {
|
|
@@ -5420,7 +5729,7 @@ var __exports__ = (() => {
|
|
|
5420
5729
|
var KHR_techniques_webgl_exports = {};
|
|
5421
5730
|
__export(KHR_techniques_webgl_exports, {
|
|
5422
5731
|
decode: () => decode10,
|
|
5423
|
-
encode: () =>
|
|
5732
|
+
encode: () => encode6,
|
|
5424
5733
|
name: () => name11
|
|
5425
5734
|
});
|
|
5426
5735
|
var KHR_TECHNIQUES_WEBGL = "KHR_techniques_webgl";
|
|
@@ -5447,7 +5756,7 @@ var __exports__ = (() => {
|
|
|
5447
5756
|
gltfScenegraph.removeExtension(KHR_TECHNIQUES_WEBGL);
|
|
5448
5757
|
}
|
|
5449
5758
|
}
|
|
5450
|
-
async function
|
|
5759
|
+
async function encode6(gltfData, options) {
|
|
5451
5760
|
}
|
|
5452
5761
|
function resolveTechniques(techniquesExtension, gltfScenegraph) {
|
|
5453
5762
|
const { programs = [], shaders = [], techniques = [] } = techniquesExtension;
|
|
@@ -5504,6 +5813,7 @@ var __exports__ = (() => {
|
|
|
5504
5813
|
KHR_texture_transform_exports,
|
|
5505
5814
|
EXT_feature_metadata_exports
|
|
5506
5815
|
];
|
|
5816
|
+
var EXTENSIONS_ENCODING = [EXT_structural_metadata_exports, EXT_mesh_features_exports];
|
|
5507
5817
|
function preprocessExtensions(gltf, options = {}, context) {
|
|
5508
5818
|
const extensions = EXTENSIONS2.filter((extension) => useExtension(extension.name, options));
|
|
5509
5819
|
for (const extension of extensions) {
|
|
@@ -5516,6 +5826,12 @@ var __exports__ = (() => {
|
|
|
5516
5826
|
await extension.decode?.(gltf, options, context);
|
|
5517
5827
|
}
|
|
5518
5828
|
}
|
|
5829
|
+
function encodeExtensions(gltf, options = {}) {
|
|
5830
|
+
for (const extension of EXTENSIONS_ENCODING) {
|
|
5831
|
+
gltf = extension.encode?.(gltf, options) ?? gltf;
|
|
5832
|
+
}
|
|
5833
|
+
return gltf;
|
|
5834
|
+
}
|
|
5519
5835
|
function useExtension(extensionName, options) {
|
|
5520
5836
|
const excludes = options?.gltf?.excludeExtensions || {};
|
|
5521
5837
|
const exclude = extensionName in excludes && !excludes[extensionName];
|
|
@@ -5972,11 +6288,11 @@ var __exports__ = (() => {
|
|
|
5972
6288
|
|
|
5973
6289
|
// src/lib/encoders/encode-gltf.ts
|
|
5974
6290
|
function encodeGLTFSync(gltf, arrayBuffer, byteOffset, options) {
|
|
5975
|
-
|
|
6291
|
+
validateGltf(gltf);
|
|
5976
6292
|
return encodeGLBSync(gltf, arrayBuffer, byteOffset, options);
|
|
5977
6293
|
}
|
|
5978
|
-
function
|
|
5979
|
-
if (gltf.buffers && gltf.buffers.length >
|
|
6294
|
+
function validateGltf(gltf) {
|
|
6295
|
+
if (gltf.buffers && gltf.buffers.length > 1) {
|
|
5980
6296
|
throw new Error("encodeGLTF: multiple buffers not yet implemented");
|
|
5981
6297
|
}
|
|
5982
6298
|
}
|
|
@@ -6002,10 +6318,11 @@ var __exports__ = (() => {
|
|
|
6002
6318
|
};
|
|
6003
6319
|
function encodeSync(gltf, options = {}) {
|
|
6004
6320
|
const { byteOffset = 0 } = options;
|
|
6005
|
-
const
|
|
6321
|
+
const gltfToEncode = encodeExtensions(gltf);
|
|
6322
|
+
const byteLength = encodeGLTFSync(gltfToEncode, null, byteOffset, options);
|
|
6006
6323
|
const arrayBuffer = new ArrayBuffer(byteLength);
|
|
6007
6324
|
const dataView = new DataView(arrayBuffer);
|
|
6008
|
-
encodeGLTFSync(
|
|
6325
|
+
encodeGLTFSync(gltfToEncode, dataView, byteOffset, options);
|
|
6009
6326
|
return arrayBuffer;
|
|
6010
6327
|
}
|
|
6011
6328
|
|
|
@@ -6055,7 +6372,7 @@ var __exports__ = (() => {
|
|
|
6055
6372
|
encodeSync: encodeSync2
|
|
6056
6373
|
};
|
|
6057
6374
|
function encodeSync2(glb, options) {
|
|
6058
|
-
const { byteOffset = 0 } = options;
|
|
6375
|
+
const { byteOffset = 0 } = options ?? {};
|
|
6059
6376
|
const byteLength = encodeGLBSync(glb, null, byteOffset, options);
|
|
6060
6377
|
const arrayBuffer = new ArrayBuffer(byteLength);
|
|
6061
6378
|
const dataView = new DataView(arrayBuffer);
|