@loaders.gl/gltf 4.2.0-alpha.6 → 4.2.0-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/dist.dev.js +90 -62
- package/dist/dist.min.js +1 -1
- package/dist/glb-loader.d.ts +22 -2
- package/dist/glb-loader.d.ts.map +1 -1
- package/dist/glb-loader.js +2 -0
- package/dist/glb-writer.d.ts +17 -2
- package/dist/glb-writer.d.ts.map +1 -1
- package/dist/gltf-loader.d.ts +24 -2
- package/dist/gltf-loader.d.ts.map +1 -1
- package/dist/gltf-loader.js +2 -0
- package/dist/gltf-writer.d.ts +2 -18
- package/dist/gltf-writer.d.ts.map +1 -1
- package/dist/gltf-writer.js +2 -2
- package/dist/index.cjs +7 -1
- package/dist/index.cjs.map +2 -2
- package/dist/lib/utils/version.js +1 -1
- package/package.json +7 -7
- package/src/glb-loader.ts +4 -2
- package/src/glb-writer.ts +2 -2
- package/src/gltf-loader.ts +4 -2
- package/src/gltf-writer.ts +5 -5
package/dist/dist.dev.js
CHANGED
|
@@ -45,13 +45,6 @@ var __exports__ = (() => {
|
|
|
45
45
|
}
|
|
46
46
|
});
|
|
47
47
|
|
|
48
|
-
// (disabled):../worker-utils/src/lib/node/require-utils.node
|
|
49
|
-
var require_require_utils = __commonJS({
|
|
50
|
-
"(disabled):../worker-utils/src/lib/node/require-utils.node"() {
|
|
51
|
-
"use strict";
|
|
52
|
-
}
|
|
53
|
-
});
|
|
54
|
-
|
|
55
48
|
// bundle.ts
|
|
56
49
|
var bundle_exports = {};
|
|
57
50
|
__export(bundle_exports, {
|
|
@@ -108,6 +101,17 @@ var __exports__ = (() => {
|
|
|
108
101
|
var matches = typeof process !== "undefined" && process.version && /v([0-9]*)/.exec(process.version);
|
|
109
102
|
var nodeVersion = matches && parseFloat(matches[1]) || 0;
|
|
110
103
|
|
|
104
|
+
// ../loader-utils/src/lib/module-utils/js-module-utils.ts
|
|
105
|
+
function registerJSModules(modules) {
|
|
106
|
+
globalThis.loaders ||= {};
|
|
107
|
+
globalThis.loaders.modules ||= {};
|
|
108
|
+
Object.assign(globalThis.loaders.modules, modules);
|
|
109
|
+
}
|
|
110
|
+
function getJSModuleOrNull(name12) {
|
|
111
|
+
const module = globalThis.loaders?.modules?.[name12];
|
|
112
|
+
return module || null;
|
|
113
|
+
}
|
|
114
|
+
|
|
111
115
|
// ../worker-utils/src/lib/env-utils/version.ts
|
|
112
116
|
var NPM_TAG = "latest";
|
|
113
117
|
function getVersion() {
|
|
@@ -154,7 +158,6 @@ var __exports__ = (() => {
|
|
|
154
158
|
var nodeVersion2 = matches2 && parseFloat(matches2[1]) || 0;
|
|
155
159
|
|
|
156
160
|
// ../worker-utils/src/lib/library-utils/library-utils.ts
|
|
157
|
-
var node = __toESM(require_require_utils(), 1);
|
|
158
161
|
var loadLibraryPromises = {};
|
|
159
162
|
async function loadLibrary(libraryUrl, moduleName = null, options = {}, libraryName = null) {
|
|
160
163
|
if (moduleName) {
|
|
@@ -191,7 +194,8 @@ var __exports__ = (() => {
|
|
|
191
194
|
}
|
|
192
195
|
if (!isBrowser2) {
|
|
193
196
|
try {
|
|
194
|
-
|
|
197
|
+
const { requireFromFile } = globalThis.loaders || {};
|
|
198
|
+
return await requireFromFile?.(libraryUrl);
|
|
195
199
|
} catch (error) {
|
|
196
200
|
console.error(error);
|
|
197
201
|
return null;
|
|
@@ -205,7 +209,8 @@ var __exports__ = (() => {
|
|
|
205
209
|
}
|
|
206
210
|
function loadLibraryFromString(scriptSource, id) {
|
|
207
211
|
if (!isBrowser2) {
|
|
208
|
-
|
|
212
|
+
const { requireFromString } = globalThis.loaders || {};
|
|
213
|
+
return requireFromString?.(scriptSource, id);
|
|
209
214
|
}
|
|
210
215
|
if (isWorker) {
|
|
211
216
|
eval.call(globalThis, scriptSource);
|
|
@@ -222,18 +227,20 @@ var __exports__ = (() => {
|
|
|
222
227
|
return null;
|
|
223
228
|
}
|
|
224
229
|
async function loadAsArrayBuffer(url) {
|
|
225
|
-
|
|
230
|
+
const { readFileAsArrayBuffer } = globalThis.loaders || {};
|
|
231
|
+
if (isBrowser2 || !readFileAsArrayBuffer || url.startsWith("http")) {
|
|
226
232
|
const response = await fetch(url);
|
|
227
233
|
return await response.arrayBuffer();
|
|
228
234
|
}
|
|
229
|
-
return await (
|
|
235
|
+
return await readFileAsArrayBuffer(url);
|
|
230
236
|
}
|
|
231
237
|
async function loadAsText(url) {
|
|
232
|
-
|
|
238
|
+
const { readFileAsText } = globalThis.loaders || {};
|
|
239
|
+
if (isBrowser2 || !readFileAsText || url.startsWith("http")) {
|
|
233
240
|
const response = await fetch(url);
|
|
234
241
|
return await response.text();
|
|
235
242
|
}
|
|
236
|
-
return await (
|
|
243
|
+
return await readFileAsText(url);
|
|
237
244
|
}
|
|
238
245
|
|
|
239
246
|
// ../loader-utils/src/lib/binary-utils/get-first-characters.ts
|
|
@@ -712,6 +719,8 @@ var __exports__ = (() => {
|
|
|
712
719
|
// imagebitmap: {} - passes (platform dependent) parameters to ImageBitmap constructor
|
|
713
720
|
};
|
|
714
721
|
var ImageLoader = {
|
|
722
|
+
dataType: null,
|
|
723
|
+
batchType: null,
|
|
715
724
|
id: "image",
|
|
716
725
|
module: "images",
|
|
717
726
|
name: "Images",
|
|
@@ -1171,8 +1180,8 @@ var __exports__ = (() => {
|
|
|
1171
1180
|
* `name`, `extensions`, `extras`, `camera`, `children`, `skin`, `rotation`, `scale`, `translation`, `weights`
|
|
1172
1181
|
* https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#node
|
|
1173
1182
|
*/
|
|
1174
|
-
addNode(
|
|
1175
|
-
const { meshIndex, matrix } =
|
|
1183
|
+
addNode(node) {
|
|
1184
|
+
const { meshIndex, matrix } = node;
|
|
1176
1185
|
this.json.nodes = this.json.nodes || [];
|
|
1177
1186
|
const nodeData = { mesh: meshIndex };
|
|
1178
1187
|
if (matrix) {
|
|
@@ -2294,11 +2303,12 @@ var __exports__ = (() => {
|
|
|
2294
2303
|
};
|
|
2295
2304
|
var loadBasisTranscoderPromise;
|
|
2296
2305
|
async function loadBasisTranscoderModule(options) {
|
|
2297
|
-
|
|
2298
|
-
|
|
2299
|
-
|
|
2306
|
+
registerJSModules(options.modules);
|
|
2307
|
+
const basis = getJSModuleOrNull("basis");
|
|
2308
|
+
if (basis) {
|
|
2309
|
+
return basis;
|
|
2300
2310
|
}
|
|
2301
|
-
loadBasisTranscoderPromise
|
|
2311
|
+
loadBasisTranscoderPromise ||= loadBasisTranscoder(options);
|
|
2302
2312
|
return await loadBasisTranscoderPromise;
|
|
2303
2313
|
}
|
|
2304
2314
|
async function loadBasisTranscoder(options) {
|
|
@@ -2730,6 +2740,8 @@ var __exports__ = (() => {
|
|
|
2730
2740
|
|
|
2731
2741
|
// ../textures/src/basis-loader.ts
|
|
2732
2742
|
var BasisWorkerLoader = {
|
|
2743
|
+
dataType: null,
|
|
2744
|
+
batchType: null,
|
|
2733
2745
|
name: "Basis",
|
|
2734
2746
|
id: "basis",
|
|
2735
2747
|
module: "textures",
|
|
@@ -2742,12 +2754,9 @@ var __exports__ = (() => {
|
|
|
2742
2754
|
options: {
|
|
2743
2755
|
basis: {
|
|
2744
2756
|
format: "auto",
|
|
2745
|
-
// gl context doesn't exist on a worker thread
|
|
2746
2757
|
libraryPath: "libs/",
|
|
2747
2758
|
containerFormat: "auto",
|
|
2748
|
-
// 'basis' || 'ktx2' || 'auto'
|
|
2749
2759
|
module: "transcoder"
|
|
2750
|
-
// 'transcoder' || 'encoder'
|
|
2751
2760
|
}
|
|
2752
2761
|
}
|
|
2753
2762
|
};
|
|
@@ -3195,6 +3204,8 @@ var __exports__ = (() => {
|
|
|
3195
3204
|
|
|
3196
3205
|
// ../draco/src/draco-loader.ts
|
|
3197
3206
|
var DracoLoader = {
|
|
3207
|
+
dataType: null,
|
|
3208
|
+
batchType: null,
|
|
3198
3209
|
name: "Draco",
|
|
3199
3210
|
id: "draco",
|
|
3200
3211
|
module: "draco",
|
|
@@ -3349,7 +3360,11 @@ var __exports__ = (() => {
|
|
|
3349
3360
|
4: Uint16Array,
|
|
3350
3361
|
5: Int32Array,
|
|
3351
3362
|
6: Uint32Array,
|
|
3363
|
+
// 7: BigInt64Array,
|
|
3364
|
+
// 8: BigUint64Array,
|
|
3352
3365
|
9: Float32Array
|
|
3366
|
+
// 10: Float64Array
|
|
3367
|
+
// 11: BOOL - What array type do we use for this?
|
|
3353
3368
|
};
|
|
3354
3369
|
var INDEX_ITEM_SIZE = 4;
|
|
3355
3370
|
var DracoParser = class {
|
|
@@ -3522,14 +3537,17 @@ var __exports__ = (() => {
|
|
|
3522
3537
|
for (const loaderAttribute of Object.values(loaderData.attributes)) {
|
|
3523
3538
|
const attributeName = this._deduceAttributeName(loaderAttribute, options);
|
|
3524
3539
|
loaderAttribute.name = attributeName;
|
|
3525
|
-
const
|
|
3526
|
-
|
|
3527
|
-
value,
|
|
3528
|
-
|
|
3529
|
-
|
|
3530
|
-
|
|
3531
|
-
|
|
3532
|
-
|
|
3540
|
+
const values = this._getAttributeValues(dracoGeometry, loaderAttribute);
|
|
3541
|
+
if (values) {
|
|
3542
|
+
const { value, size } = values;
|
|
3543
|
+
attributes[attributeName] = {
|
|
3544
|
+
value,
|
|
3545
|
+
size,
|
|
3546
|
+
byteOffset: loaderAttribute.byte_offset,
|
|
3547
|
+
byteStride: loaderAttribute.byte_stride,
|
|
3548
|
+
normalized: loaderAttribute.normalized
|
|
3549
|
+
};
|
|
3550
|
+
}
|
|
3533
3551
|
}
|
|
3534
3552
|
return attributes;
|
|
3535
3553
|
}
|
|
@@ -3571,6 +3589,10 @@ var __exports__ = (() => {
|
|
|
3571
3589
|
*/
|
|
3572
3590
|
_getAttributeValues(dracoGeometry, attribute) {
|
|
3573
3591
|
const TypedArrayCtor = DRACO_DATA_TYPE_TO_TYPED_ARRAY_MAP[attribute.data_type];
|
|
3592
|
+
if (!TypedArrayCtor) {
|
|
3593
|
+
console.warn(`DRACO: Unsupported attribute type ${attribute.data_type}`);
|
|
3594
|
+
return null;
|
|
3595
|
+
}
|
|
3574
3596
|
const numComponents = attribute.num_components;
|
|
3575
3597
|
const numPoints = dracoGeometry.num_points();
|
|
3576
3598
|
const numValues = numPoints * numComponents;
|
|
@@ -3801,11 +3823,11 @@ var __exports__ = (() => {
|
|
|
3801
3823
|
async function loadDracoDecoderModule(options) {
|
|
3802
3824
|
const modules = options.modules || {};
|
|
3803
3825
|
if (modules.draco3d) {
|
|
3804
|
-
loadDecoderPromise
|
|
3826
|
+
loadDecoderPromise ||= modules.draco3d.createDecoderModule({}).then((draco) => {
|
|
3805
3827
|
return { draco };
|
|
3806
3828
|
});
|
|
3807
3829
|
} else {
|
|
3808
|
-
loadDecoderPromise
|
|
3830
|
+
loadDecoderPromise ||= loadDracoDecoder(options);
|
|
3809
3831
|
}
|
|
3810
3832
|
return await loadDecoderPromise;
|
|
3811
3833
|
}
|
|
@@ -5362,12 +5384,12 @@ var __exports__ = (() => {
|
|
|
5362
5384
|
gltfScenegraph.json.lights = extension.lights;
|
|
5363
5385
|
gltfScenegraph.removeExtension(KHR_LIGHTS_PUNCTUAL);
|
|
5364
5386
|
}
|
|
5365
|
-
for (const
|
|
5366
|
-
const nodeExtension = gltfScenegraph.getObjectExtension(
|
|
5387
|
+
for (const node of json.nodes || []) {
|
|
5388
|
+
const nodeExtension = gltfScenegraph.getObjectExtension(node, KHR_LIGHTS_PUNCTUAL);
|
|
5367
5389
|
if (nodeExtension) {
|
|
5368
|
-
|
|
5390
|
+
node.light = nodeExtension.light;
|
|
5369
5391
|
}
|
|
5370
|
-
gltfScenegraph.removeObjectExtension(
|
|
5392
|
+
gltfScenegraph.removeObjectExtension(node, KHR_LIGHTS_PUNCTUAL);
|
|
5371
5393
|
}
|
|
5372
5394
|
}
|
|
5373
5395
|
async function encode2(gltfData) {
|
|
@@ -5381,8 +5403,8 @@ var __exports__ = (() => {
|
|
|
5381
5403
|
}
|
|
5382
5404
|
if (gltfScenegraph.json.lights) {
|
|
5383
5405
|
for (const light of gltfScenegraph.json.lights) {
|
|
5384
|
-
const
|
|
5385
|
-
gltfScenegraph.addObjectExtension(
|
|
5406
|
+
const node = light.node;
|
|
5407
|
+
gltfScenegraph.addObjectExtension(node, KHR_LIGHTS_PUNCTUAL, light);
|
|
5386
5408
|
}
|
|
5387
5409
|
delete gltfScenegraph.json.lights;
|
|
5388
5410
|
}
|
|
@@ -5666,11 +5688,11 @@ var __exports__ = (() => {
|
|
|
5666
5688
|
for (const mesh of json.meshes) {
|
|
5667
5689
|
this._convertMeshIds(mesh);
|
|
5668
5690
|
}
|
|
5669
|
-
for (const
|
|
5670
|
-
this._convertNodeIds(
|
|
5691
|
+
for (const node of json.nodes) {
|
|
5692
|
+
this._convertNodeIds(node);
|
|
5671
5693
|
}
|
|
5672
|
-
for (const
|
|
5673
|
-
this._convertSceneIds(
|
|
5694
|
+
for (const node of json.scenes) {
|
|
5695
|
+
this._convertSceneIds(node);
|
|
5674
5696
|
}
|
|
5675
5697
|
}
|
|
5676
5698
|
_convertTextureIds(texture) {
|
|
@@ -5692,17 +5714,17 @@ var __exports__ = (() => {
|
|
|
5692
5714
|
}
|
|
5693
5715
|
}
|
|
5694
5716
|
}
|
|
5695
|
-
_convertNodeIds(
|
|
5696
|
-
if (
|
|
5697
|
-
|
|
5717
|
+
_convertNodeIds(node) {
|
|
5718
|
+
if (node.children) {
|
|
5719
|
+
node.children = node.children.map((child) => this._convertIdToIndex(child, "node"));
|
|
5698
5720
|
}
|
|
5699
|
-
if (
|
|
5700
|
-
|
|
5721
|
+
if (node.meshes) {
|
|
5722
|
+
node.meshes = node.meshes.map((mesh) => this._convertIdToIndex(mesh, "mesh"));
|
|
5701
5723
|
}
|
|
5702
5724
|
}
|
|
5703
5725
|
_convertSceneIds(scene) {
|
|
5704
5726
|
if (scene.nodes) {
|
|
5705
|
-
scene.nodes = scene.nodes.map((
|
|
5727
|
+
scene.nodes = scene.nodes.map((node) => this._convertIdToIndex(node, "node"));
|
|
5706
5728
|
}
|
|
5707
5729
|
}
|
|
5708
5730
|
/** Go through all objects in a top-level array and replace ids with indices */
|
|
@@ -5894,6 +5916,8 @@ var __exports__ = (() => {
|
|
|
5894
5916
|
|
|
5895
5917
|
// src/gltf-loader.ts
|
|
5896
5918
|
var GLTFLoader = {
|
|
5919
|
+
dataType: null,
|
|
5920
|
+
batchType: null,
|
|
5897
5921
|
name: "glTF",
|
|
5898
5922
|
id: "gltf",
|
|
5899
5923
|
module: "gltf",
|
|
@@ -5988,6 +6012,8 @@ var __exports__ = (() => {
|
|
|
5988
6012
|
|
|
5989
6013
|
// src/gltf-writer.ts
|
|
5990
6014
|
var GLTFWriter = {
|
|
6015
|
+
dataType: null,
|
|
6016
|
+
batchType: null,
|
|
5991
6017
|
name: "glTF",
|
|
5992
6018
|
id: "gltf",
|
|
5993
6019
|
module: "gltf",
|
|
@@ -6014,6 +6040,8 @@ var __exports__ = (() => {
|
|
|
6014
6040
|
|
|
6015
6041
|
// src/glb-loader.ts
|
|
6016
6042
|
var GLBLoader = {
|
|
6043
|
+
dataType: null,
|
|
6044
|
+
batchType: null,
|
|
6017
6045
|
name: "GLB",
|
|
6018
6046
|
id: "glb",
|
|
6019
6047
|
module: "gltf",
|
|
@@ -6170,8 +6198,8 @@ var __exports__ = (() => {
|
|
|
6170
6198
|
json.meshes = gltf.meshes.map((mesh, i2) => this._resolveMesh(mesh, i2));
|
|
6171
6199
|
}
|
|
6172
6200
|
if (gltf.nodes) {
|
|
6173
|
-
json.nodes = gltf.nodes.map((
|
|
6174
|
-
json.nodes = json.nodes.map((
|
|
6201
|
+
json.nodes = gltf.nodes.map((node, i2) => this._resolveNode(node, i2));
|
|
6202
|
+
json.nodes = json.nodes.map((node, i2) => this._resolveNodeChildren(node));
|
|
6175
6203
|
}
|
|
6176
6204
|
if (gltf.skins) {
|
|
6177
6205
|
json.skins = gltf.skins.map((skin, i2) => this._resolveSkin(skin, i2));
|
|
@@ -6236,26 +6264,26 @@ var __exports__ = (() => {
|
|
|
6236
6264
|
...scene,
|
|
6237
6265
|
// @ts-ignore
|
|
6238
6266
|
id: scene.id || `scene-${index}`,
|
|
6239
|
-
nodes: (scene.nodes || []).map((
|
|
6267
|
+
nodes: (scene.nodes || []).map((node) => this.getNode(node))
|
|
6240
6268
|
};
|
|
6241
6269
|
}
|
|
6242
6270
|
_resolveNode(gltfNode, index) {
|
|
6243
|
-
const
|
|
6271
|
+
const node = {
|
|
6244
6272
|
...gltfNode,
|
|
6245
6273
|
// @ts-expect-error id could already be present, glTF standard does not prevent it
|
|
6246
6274
|
id: gltfNode?.id || `node-${index}`
|
|
6247
6275
|
};
|
|
6248
6276
|
if (gltfNode.mesh !== void 0) {
|
|
6249
|
-
|
|
6277
|
+
node.mesh = this.getMesh(gltfNode.mesh);
|
|
6250
6278
|
}
|
|
6251
6279
|
if (gltfNode.camera !== void 0) {
|
|
6252
|
-
|
|
6280
|
+
node.camera = this.getCamera(gltfNode.camera);
|
|
6253
6281
|
}
|
|
6254
6282
|
if (gltfNode.skin !== void 0) {
|
|
6255
|
-
|
|
6283
|
+
node.skin = this.getSkin(gltfNode.skin);
|
|
6256
6284
|
}
|
|
6257
6285
|
if (gltfNode.meshes !== void 0 && gltfNode.meshes.length) {
|
|
6258
|
-
|
|
6286
|
+
node.mesh = gltfNode.meshes.reduce(
|
|
6259
6287
|
(accum, meshIndex) => {
|
|
6260
6288
|
const mesh = this.getMesh(meshIndex);
|
|
6261
6289
|
accum.id = mesh.id;
|
|
@@ -6265,13 +6293,13 @@ var __exports__ = (() => {
|
|
|
6265
6293
|
{ primitives: [] }
|
|
6266
6294
|
);
|
|
6267
6295
|
}
|
|
6268
|
-
return
|
|
6296
|
+
return node;
|
|
6269
6297
|
}
|
|
6270
|
-
_resolveNodeChildren(
|
|
6271
|
-
if (
|
|
6272
|
-
|
|
6298
|
+
_resolveNodeChildren(node) {
|
|
6299
|
+
if (node.children) {
|
|
6300
|
+
node.children = node.children.map((child) => this.getNode(child));
|
|
6273
6301
|
}
|
|
6274
|
-
return
|
|
6302
|
+
return node;
|
|
6275
6303
|
}
|
|
6276
6304
|
_resolveSkin(gltfSkin, index) {
|
|
6277
6305
|
const inverseBindMatrices = typeof gltfSkin.inverseBindMatrices === "number" ? this.getAccessor(gltfSkin.inverseBindMatrices) : void 0;
|