@loaders.gl/gltf 4.0.0-alpha.6 → 4.0.0-alpha.7
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 +1415 -1339
- package/dist/es5/glb-loader.js +2 -2
- package/dist/es5/glb-loader.js.map +1 -1
- package/dist/es5/glb-writer.js +3 -4
- package/dist/es5/glb-writer.js.map +1 -1
- package/dist/es5/gltf-loader.js +3 -3
- package/dist/es5/gltf-loader.js.map +1 -1
- package/dist/es5/index.js +9 -3
- package/dist/es5/index.js.map +1 -1
- package/dist/es5/lib/api/gltf-extensions.js.map +1 -1
- package/dist/es5/lib/api/gltf-scenegraph.js +47 -30
- package/dist/es5/lib/api/gltf-scenegraph.js.map +1 -1
- package/dist/es5/lib/api/post-process-gltf.js +164 -116
- package/dist/es5/lib/api/post-process-gltf.js.map +1 -1
- package/dist/es5/lib/encoders/encode-glb.js +1 -1
- package/dist/es5/lib/encoders/encode-glb.js.map +1 -1
- package/dist/es5/lib/encoders/encode-gltf.js +2 -3
- package/dist/es5/lib/encoders/encode-gltf.js.map +1 -1
- package/dist/es5/lib/extensions/EXT_meshopt_compression.js +3 -5
- package/dist/es5/lib/extensions/EXT_meshopt_compression.js.map +1 -1
- package/dist/es5/lib/extensions/EXT_texture_webp.js +2 -3
- package/dist/es5/lib/extensions/EXT_texture_webp.js.map +1 -1
- package/dist/es5/lib/extensions/KHR_binary_gltf.js +2 -3
- package/dist/es5/lib/extensions/KHR_binary_gltf.js.map +1 -1
- package/dist/es5/lib/extensions/KHR_draco_mesh_compression.js +6 -5
- package/dist/es5/lib/extensions/KHR_draco_mesh_compression.js.map +1 -1
- package/dist/es5/lib/extensions/KHR_texture_basisu.js +3 -4
- package/dist/es5/lib/extensions/KHR_texture_basisu.js.map +1 -1
- package/dist/es5/lib/extensions/KHR_texture_transform.js +9 -8
- package/dist/es5/lib/extensions/KHR_texture_transform.js.map +1 -1
- package/dist/es5/lib/extensions/deprecated/EXT_feature_metadata.js +2 -2
- package/dist/es5/lib/extensions/deprecated/EXT_feature_metadata.js.map +1 -1
- package/dist/es5/lib/extensions/deprecated/KHR_lights_punctual.js +3 -3
- package/dist/es5/lib/extensions/deprecated/KHR_lights_punctual.js.map +1 -1
- package/dist/es5/lib/extensions/deprecated/KHR_materials_unlit.js +3 -3
- package/dist/es5/lib/extensions/deprecated/KHR_materials_unlit.js.map +1 -1
- package/dist/es5/lib/extensions/deprecated/KHR_techniques_webgl.js +2 -2
- package/dist/es5/lib/extensions/deprecated/KHR_techniques_webgl.js.map +1 -1
- package/dist/es5/lib/gltf-utils/gltf-attribute-utils.js.map +1 -1
- package/dist/es5/lib/gltf-utils/gltf-utils.js +24 -0
- package/dist/es5/lib/gltf-utils/gltf-utils.js.map +1 -1
- package/dist/es5/lib/parsers/parse-glb.js +10 -10
- package/dist/es5/lib/parsers/parse-glb.js.map +1 -1
- package/dist/es5/lib/parsers/parse-gltf.js +6 -10
- package/dist/es5/lib/parsers/parse-gltf.js.map +1 -1
- package/dist/es5/lib/types/gltf-json-schema.js.map +1 -1
- package/dist/es5/lib/types/gltf-postprocessed-schema.js.map +1 -1
- package/dist/es5/lib/types/gltf-types.js.map +1 -1
- package/dist/es5/lib/utils/version.js +1 -1
- package/dist/esm/glb-loader.js +1 -1
- package/dist/esm/glb-loader.js.map +1 -1
- package/dist/esm/glb-writer.js +1 -1
- package/dist/esm/glb-writer.js.map +1 -1
- package/dist/esm/gltf-loader.js +3 -3
- package/dist/esm/gltf-loader.js.map +1 -1
- package/dist/esm/index.js +2 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/lib/api/gltf-extensions.js.map +1 -1
- package/dist/esm/lib/api/gltf-scenegraph.js +40 -29
- package/dist/esm/lib/api/gltf-scenegraph.js.map +1 -1
- package/dist/esm/lib/api/post-process-gltf.js +167 -112
- package/dist/esm/lib/api/post-process-gltf.js.map +1 -1
- package/dist/esm/lib/encoders/encode-glb.js +1 -1
- package/dist/esm/lib/encoders/encode-glb.js.map +1 -1
- package/dist/esm/lib/encoders/encode-gltf.js +1 -1
- package/dist/esm/lib/encoders/encode-gltf.js.map +1 -1
- package/dist/esm/lib/extensions/EXT_meshopt_compression.js +2 -3
- package/dist/esm/lib/extensions/EXT_meshopt_compression.js.map +1 -1
- package/dist/esm/lib/extensions/EXT_texture_webp.js +1 -1
- package/dist/esm/lib/extensions/EXT_texture_webp.js.map +1 -1
- package/dist/esm/lib/extensions/KHR_binary_gltf.js +1 -1
- package/dist/esm/lib/extensions/KHR_binary_gltf.js.map +1 -1
- package/dist/esm/lib/extensions/KHR_draco_mesh_compression.js +5 -4
- package/dist/esm/lib/extensions/KHR_draco_mesh_compression.js.map +1 -1
- package/dist/esm/lib/extensions/KHR_texture_basisu.js +2 -2
- package/dist/esm/lib/extensions/KHR_texture_basisu.js.map +1 -1
- package/dist/esm/lib/extensions/KHR_texture_transform.js +7 -6
- package/dist/esm/lib/extensions/KHR_texture_transform.js.map +1 -1
- package/dist/esm/lib/extensions/deprecated/EXT_feature_metadata.js +1 -1
- package/dist/esm/lib/extensions/deprecated/EXT_feature_metadata.js.map +1 -1
- package/dist/esm/lib/extensions/deprecated/KHR_lights_punctual.js +1 -1
- package/dist/esm/lib/extensions/deprecated/KHR_lights_punctual.js.map +1 -1
- package/dist/esm/lib/extensions/deprecated/KHR_materials_unlit.js +1 -1
- package/dist/esm/lib/extensions/deprecated/KHR_materials_unlit.js.map +1 -1
- package/dist/esm/lib/extensions/deprecated/KHR_techniques_webgl.js +1 -1
- package/dist/esm/lib/extensions/deprecated/KHR_techniques_webgl.js.map +1 -1
- package/dist/esm/lib/gltf-utils/gltf-attribute-utils.js.map +1 -1
- package/dist/esm/lib/gltf-utils/gltf-utils.js +20 -0
- package/dist/esm/lib/gltf-utils/gltf-utils.js.map +1 -1
- package/dist/esm/lib/parsers/parse-glb.js +10 -10
- package/dist/esm/lib/parsers/parse-glb.js.map +1 -1
- package/dist/esm/lib/parsers/parse-gltf.js +5 -6
- package/dist/esm/lib/parsers/parse-gltf.js.map +1 -1
- package/dist/esm/lib/types/gltf-json-schema.js.map +1 -1
- package/dist/esm/lib/types/gltf-postprocessed-schema.js.map +1 -1
- package/dist/esm/lib/types/gltf-types.js.map +1 -1
- package/dist/esm/lib/utils/version.js +1 -1
- package/dist/glb-loader.d.ts +2 -2
- package/dist/glb-loader.js +2 -5
- package/dist/glb-writer.d.ts.map +1 -1
- package/dist/glb-writer.js +4 -6
- package/dist/gltf-loader.d.ts +5 -5
- package/dist/gltf-loader.d.ts.map +1 -1
- package/dist/gltf-loader.js +3 -3
- package/dist/index.d.ts +8 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +12 -5
- package/dist/lib/api/gltf-extensions.d.ts +1 -1
- package/dist/lib/api/gltf-extensions.d.ts.map +1 -1
- package/dist/lib/api/gltf-scenegraph.d.ts +6 -4
- package/dist/lib/api/gltf-scenegraph.d.ts.map +1 -1
- package/dist/lib/api/gltf-scenegraph.js +43 -30
- package/dist/lib/api/post-process-gltf.d.ts +4 -1
- package/dist/lib/api/post-process-gltf.d.ts.map +1 -1
- package/dist/lib/api/post-process-gltf.js +186 -123
- package/dist/lib/encoders/encode-glb.d.ts +13 -1
- package/dist/lib/encoders/encode-glb.d.ts.map +1 -1
- package/dist/lib/encoders/encode-glb.js +15 -4
- package/dist/lib/encoders/encode-gltf.js +2 -5
- package/dist/lib/extensions/EXT_meshopt_compression.d.ts +1 -1
- package/dist/lib/extensions/EXT_meshopt_compression.d.ts.map +1 -1
- package/dist/lib/extensions/EXT_meshopt_compression.js +3 -7
- package/dist/lib/extensions/EXT_texture_webp.d.ts +1 -1
- package/dist/lib/extensions/EXT_texture_webp.d.ts.map +1 -1
- package/dist/lib/extensions/EXT_texture_webp.js +2 -5
- package/dist/lib/extensions/KHR_binary_gltf.d.ts +1 -1
- package/dist/lib/extensions/KHR_binary_gltf.d.ts.map +1 -1
- package/dist/lib/extensions/KHR_binary_gltf.js +2 -5
- package/dist/lib/extensions/KHR_draco_mesh_compression.d.ts +1 -1
- package/dist/lib/extensions/KHR_draco_mesh_compression.d.ts.map +1 -1
- package/dist/lib/extensions/KHR_draco_mesh_compression.js +5 -8
- package/dist/lib/extensions/KHR_texture_basisu.d.ts +1 -1
- package/dist/lib/extensions/KHR_texture_basisu.d.ts.map +1 -1
- package/dist/lib/extensions/KHR_texture_basisu.js +3 -6
- package/dist/lib/extensions/KHR_texture_transform.d.ts.map +1 -1
- package/dist/lib/extensions/KHR_texture_transform.js +7 -10
- package/dist/lib/extensions/deprecated/EXT_feature_metadata.d.ts +1 -1
- package/dist/lib/extensions/deprecated/EXT_feature_metadata.d.ts.map +1 -1
- package/dist/lib/extensions/deprecated/EXT_feature_metadata.js +2 -5
- package/dist/lib/extensions/deprecated/KHR_lights_punctual.d.ts +1 -1
- package/dist/lib/extensions/deprecated/KHR_lights_punctual.d.ts.map +1 -1
- package/dist/lib/extensions/deprecated/KHR_lights_punctual.js +3 -6
- package/dist/lib/extensions/deprecated/KHR_materials_unlit.d.ts +1 -1
- package/dist/lib/extensions/deprecated/KHR_materials_unlit.d.ts.map +1 -1
- package/dist/lib/extensions/deprecated/KHR_materials_unlit.js +3 -6
- package/dist/lib/extensions/deprecated/KHR_techniques_webgl.d.ts +1 -1
- package/dist/lib/extensions/deprecated/KHR_techniques_webgl.d.ts.map +1 -1
- package/dist/lib/extensions/deprecated/KHR_techniques_webgl.js +2 -5
- package/dist/lib/gltf-utils/gltf-attribute-utils.d.ts +1 -1
- package/dist/lib/gltf-utils/gltf-attribute-utils.d.ts.map +1 -1
- package/dist/lib/gltf-utils/gltf-utils.d.ts +7 -0
- package/dist/lib/gltf-utils/gltf-utils.d.ts.map +1 -1
- package/dist/lib/gltf-utils/gltf-utils.js +28 -1
- package/dist/lib/parsers/parse-glb.d.ts +15 -3
- package/dist/lib/parsers/parse-glb.d.ts.map +1 -1
- package/dist/lib/parsers/parse-glb.js +43 -18
- package/dist/lib/parsers/parse-gltf.d.ts +8 -4
- package/dist/lib/parsers/parse-gltf.d.ts.map +1 -1
- package/dist/lib/parsers/parse-gltf.js +13 -34
- package/dist/lib/types/gltf-json-schema.d.ts +151 -138
- package/dist/lib/types/gltf-json-schema.d.ts.map +1 -1
- package/dist/lib/types/gltf-postprocessed-schema.d.ts +174 -209
- package/dist/lib/types/gltf-postprocessed-schema.d.ts.map +1 -1
- package/dist/lib/types/gltf-postprocessed-schema.js +1 -1
- package/dist/lib/types/gltf-types.d.ts +18 -6
- package/dist/lib/types/gltf-types.d.ts.map +1 -1
- package/package.json +6 -6
- package/src/glb-loader.ts +3 -3
- package/src/glb-writer.ts +3 -1
- package/src/gltf-loader.ts +12 -8
- package/src/index.ts +32 -13
- package/src/lib/api/gltf-extensions.ts +1 -1
- package/src/lib/api/gltf-scenegraph.ts +55 -37
- package/src/lib/api/post-process-gltf.ts +275 -150
- package/src/lib/encoders/encode-glb.ts +15 -5
- package/src/lib/encoders/encode-gltf.ts +1 -1
- package/src/lib/extensions/EXT_meshopt_compression.ts +4 -6
- package/src/lib/extensions/EXT_texture_webp.ts +2 -2
- package/src/lib/extensions/KHR_binary_gltf.ts +2 -2
- package/src/lib/extensions/KHR_draco_mesh_compression.ts +7 -7
- package/src/lib/extensions/KHR_texture_basisu.ts +3 -3
- package/src/lib/extensions/KHR_texture_transform.ts +22 -19
- package/src/lib/extensions/deprecated/EXT_feature_metadata.ts +2 -2
- package/src/lib/extensions/deprecated/KHR_lights_punctual.ts +2 -2
- package/src/lib/extensions/deprecated/KHR_materials_unlit.ts +2 -2
- package/src/lib/extensions/deprecated/KHR_techniques_webgl.ts +2 -2
- package/src/lib/gltf-utils/gltf-attribute-utils.ts +1 -1
- package/src/lib/gltf-utils/gltf-utils.ts +31 -0
- package/src/lib/parsers/parse-glb.ts +50 -24
- package/src/lib/parsers/parse-gltf.ts +22 -16
- package/src/lib/types/gltf-json-schema.ts +165 -138
- package/src/lib/types/gltf-postprocessed-schema.ts +289 -212
- package/src/lib/types/gltf-types.ts +35 -59
package/dist/dist.min.js
CHANGED
|
@@ -200,7 +200,6 @@
|
|
|
200
200
|
// ../worker-utils/src/index.ts
|
|
201
201
|
var init_src = __esm({
|
|
202
202
|
"../worker-utils/src/index.ts"() {
|
|
203
|
-
init_globals2();
|
|
204
203
|
init_library_utils();
|
|
205
204
|
}
|
|
206
205
|
});
|
|
@@ -321,788 +320,325 @@
|
|
|
321
320
|
}
|
|
322
321
|
});
|
|
323
322
|
|
|
324
|
-
// ../
|
|
323
|
+
// ../images/src/lib/utils/version.ts
|
|
325
324
|
var VERSION4;
|
|
326
325
|
var init_version3 = __esm({
|
|
327
|
-
"../
|
|
328
|
-
VERSION4 = typeof __VERSION__ !== "undefined" ? __VERSION__ : "
|
|
326
|
+
"../images/src/lib/utils/version.ts"() {
|
|
327
|
+
VERSION4 = typeof __VERSION__ !== "undefined" ? __VERSION__ : "latest";
|
|
329
328
|
}
|
|
330
329
|
});
|
|
331
330
|
|
|
332
|
-
// ../
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
331
|
+
// ../images/src/lib/category-api/image-type.ts
|
|
332
|
+
function isImageTypeSupported(type) {
|
|
333
|
+
switch (type) {
|
|
334
|
+
case "auto":
|
|
335
|
+
return IMAGE_BITMAP_SUPPORTED || IMAGE_SUPPORTED || DATA_SUPPORTED;
|
|
336
|
+
case "imagebitmap":
|
|
337
|
+
return IMAGE_BITMAP_SUPPORTED;
|
|
338
|
+
case "image":
|
|
339
|
+
return IMAGE_SUPPORTED;
|
|
340
|
+
case "data":
|
|
341
|
+
return DATA_SUPPORTED;
|
|
342
|
+
default:
|
|
343
|
+
throw new Error(`@loaders.gl/images: image ${type} not supported in this environment`);
|
|
337
344
|
}
|
|
338
|
-
loadBasisTranscoderPromise = loadBasisTranscoderPromise || loadBasisTrascoder(options);
|
|
339
|
-
return await loadBasisTranscoderPromise;
|
|
340
|
-
}
|
|
341
|
-
async function loadBasisTrascoder(options) {
|
|
342
|
-
let BASIS = null;
|
|
343
|
-
let wasmBinary = null;
|
|
344
|
-
[BASIS, wasmBinary] = await Promise.all([
|
|
345
|
-
await loadLibrary("basis_transcoder.js", "textures", options),
|
|
346
|
-
await loadLibrary("basis_transcoder.wasm", "textures", options)
|
|
347
|
-
]);
|
|
348
|
-
BASIS = BASIS || globalThis.BASIS;
|
|
349
|
-
return await initializeBasisTrascoderModule(BASIS, wasmBinary);
|
|
350
345
|
}
|
|
351
|
-
function
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
options.wasmBinary = wasmBinary;
|
|
346
|
+
function getDefaultImageType() {
|
|
347
|
+
if (IMAGE_BITMAP_SUPPORTED) {
|
|
348
|
+
return "imagebitmap";
|
|
355
349
|
}
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
const { BasisFile, initializeBasis } = module;
|
|
359
|
-
initializeBasis();
|
|
360
|
-
resolve({ BasisFile });
|
|
361
|
-
});
|
|
362
|
-
});
|
|
363
|
-
}
|
|
364
|
-
async function loadBasisEncoderModule(options) {
|
|
365
|
-
const modules = options.modules || {};
|
|
366
|
-
if (modules.basisEncoder) {
|
|
367
|
-
return modules.basisEncoder;
|
|
350
|
+
if (IMAGE_SUPPORTED) {
|
|
351
|
+
return "image";
|
|
368
352
|
}
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
}
|
|
372
|
-
async function loadBasisEncoder(options) {
|
|
373
|
-
let BASIS_ENCODER = null;
|
|
374
|
-
let wasmBinary = null;
|
|
375
|
-
[BASIS_ENCODER, wasmBinary] = await Promise.all([
|
|
376
|
-
await loadLibrary(BASIS_CDN_ENCODER_JS, "textures", options),
|
|
377
|
-
await loadLibrary(BASIS_CDN_ENCODER_WASM, "textures", options)
|
|
378
|
-
]);
|
|
379
|
-
BASIS_ENCODER = BASIS_ENCODER || globalThis.BASIS;
|
|
380
|
-
return await initializeBasisEncoderModule(BASIS_ENCODER, wasmBinary);
|
|
381
|
-
}
|
|
382
|
-
function initializeBasisEncoderModule(BasisEncoderModule, wasmBinary) {
|
|
383
|
-
const options = {};
|
|
384
|
-
if (wasmBinary) {
|
|
385
|
-
options.wasmBinary = wasmBinary;
|
|
353
|
+
if (DATA_SUPPORTED) {
|
|
354
|
+
return "data";
|
|
386
355
|
}
|
|
387
|
-
|
|
388
|
-
BasisEncoderModule(options).then((module) => {
|
|
389
|
-
const { BasisFile, KTX2File, initializeBasis, BasisEncoder } = module;
|
|
390
|
-
initializeBasis();
|
|
391
|
-
resolve({ BasisFile, KTX2File, BasisEncoder });
|
|
392
|
-
});
|
|
393
|
-
});
|
|
356
|
+
throw new Error("Install '@loaders.gl/polyfills' to parse images under Node.js");
|
|
394
357
|
}
|
|
395
|
-
var
|
|
396
|
-
var
|
|
397
|
-
"../
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
358
|
+
var _parseImageNode, IMAGE_SUPPORTED, IMAGE_BITMAP_SUPPORTED, NODE_IMAGE_SUPPORTED, DATA_SUPPORTED;
|
|
359
|
+
var init_image_type = __esm({
|
|
360
|
+
"../images/src/lib/category-api/image-type.ts"() {
|
|
361
|
+
init_src2();
|
|
362
|
+
({ _parseImageNode } = globalThis);
|
|
363
|
+
IMAGE_SUPPORTED = typeof Image !== "undefined";
|
|
364
|
+
IMAGE_BITMAP_SUPPORTED = typeof ImageBitmap !== "undefined";
|
|
365
|
+
NODE_IMAGE_SUPPORTED = Boolean(_parseImageNode);
|
|
366
|
+
DATA_SUPPORTED = isBrowser ? true : NODE_IMAGE_SUPPORTED;
|
|
402
367
|
}
|
|
403
368
|
});
|
|
404
369
|
|
|
405
|
-
// ../
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
COMPRESSED_RGB_S3TC_DXT1_EXT: 33776,
|
|
411
|
-
COMPRESSED_RGBA_S3TC_DXT1_EXT: 33777,
|
|
412
|
-
COMPRESSED_RGBA_S3TC_DXT3_EXT: 33778,
|
|
413
|
-
COMPRESSED_RGBA_S3TC_DXT5_EXT: 33779,
|
|
414
|
-
COMPRESSED_R11_EAC: 37488,
|
|
415
|
-
COMPRESSED_SIGNED_R11_EAC: 37489,
|
|
416
|
-
COMPRESSED_RG11_EAC: 37490,
|
|
417
|
-
COMPRESSED_SIGNED_RG11_EAC: 37491,
|
|
418
|
-
COMPRESSED_RGB8_ETC2: 37492,
|
|
419
|
-
COMPRESSED_RGBA8_ETC2_EAC: 37493,
|
|
420
|
-
COMPRESSED_SRGB8_ETC2: 37494,
|
|
421
|
-
COMPRESSED_SRGB8_ALPHA8_ETC2_EAC: 37495,
|
|
422
|
-
COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2: 37496,
|
|
423
|
-
COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2: 37497,
|
|
424
|
-
COMPRESSED_RGB_PVRTC_4BPPV1_IMG: 35840,
|
|
425
|
-
COMPRESSED_RGBA_PVRTC_4BPPV1_IMG: 35842,
|
|
426
|
-
COMPRESSED_RGB_PVRTC_2BPPV1_IMG: 35841,
|
|
427
|
-
COMPRESSED_RGBA_PVRTC_2BPPV1_IMG: 35843,
|
|
428
|
-
COMPRESSED_RGB_ETC1_WEBGL: 36196,
|
|
429
|
-
COMPRESSED_RGB_ATC_WEBGL: 35986,
|
|
430
|
-
COMPRESSED_RGBA_ATC_EXPLICIT_ALPHA_WEBGL: 35987,
|
|
431
|
-
COMPRESSED_RGBA_ATC_INTERPOLATED_ALPHA_WEBGL: 34798,
|
|
432
|
-
COMPRESSED_RGBA_ASTC_4X4_KHR: 37808,
|
|
433
|
-
COMPRESSED_RGBA_ASTC_5X4_KHR: 37809,
|
|
434
|
-
COMPRESSED_RGBA_ASTC_5X5_KHR: 37810,
|
|
435
|
-
COMPRESSED_RGBA_ASTC_6X5_KHR: 37811,
|
|
436
|
-
COMPRESSED_RGBA_ASTC_6X6_KHR: 37812,
|
|
437
|
-
COMPRESSED_RGBA_ASTC_8X5_KHR: 37813,
|
|
438
|
-
COMPRESSED_RGBA_ASTC_8X6_KHR: 37814,
|
|
439
|
-
COMPRESSED_RGBA_ASTC_8X8_KHR: 37815,
|
|
440
|
-
COMPRESSED_RGBA_ASTC_10X5_KHR: 37816,
|
|
441
|
-
COMPRESSED_RGBA_ASTC_10X6_KHR: 37817,
|
|
442
|
-
COMPRESSED_RGBA_ASTC_10X8_KHR: 37818,
|
|
443
|
-
COMPRESSED_RGBA_ASTC_10X10_KHR: 37819,
|
|
444
|
-
COMPRESSED_RGBA_ASTC_12X10_KHR: 37820,
|
|
445
|
-
COMPRESSED_RGBA_ASTC_12X12_KHR: 37821,
|
|
446
|
-
COMPRESSED_SRGB8_ALPHA8_ASTC_4X4_KHR: 37840,
|
|
447
|
-
COMPRESSED_SRGB8_ALPHA8_ASTC_5X4_KHR: 37841,
|
|
448
|
-
COMPRESSED_SRGB8_ALPHA8_ASTC_5X5_KHR: 37842,
|
|
449
|
-
COMPRESSED_SRGB8_ALPHA8_ASTC_6X5_KHR: 37843,
|
|
450
|
-
COMPRESSED_SRGB8_ALPHA8_ASTC_6X6_KHR: 37844,
|
|
451
|
-
COMPRESSED_SRGB8_ALPHA8_ASTC_8X5_KHR: 37845,
|
|
452
|
-
COMPRESSED_SRGB8_ALPHA8_ASTC_8X6_KHR: 37846,
|
|
453
|
-
COMPRESSED_SRGB8_ALPHA8_ASTC_8X8_KHR: 37847,
|
|
454
|
-
COMPRESSED_SRGB8_ALPHA8_ASTC_10X5_KHR: 37848,
|
|
455
|
-
COMPRESSED_SRGB8_ALPHA8_ASTC_10X6_KHR: 37849,
|
|
456
|
-
COMPRESSED_SRGB8_ALPHA8_ASTC_10X8_KHR: 37850,
|
|
457
|
-
COMPRESSED_SRGB8_ALPHA8_ASTC_10X10_KHR: 37851,
|
|
458
|
-
COMPRESSED_SRGB8_ALPHA8_ASTC_12X10_KHR: 37852,
|
|
459
|
-
COMPRESSED_SRGB8_ALPHA8_ASTC_12X12_KHR: 37853,
|
|
460
|
-
COMPRESSED_RED_RGTC1_EXT: 36283,
|
|
461
|
-
COMPRESSED_SIGNED_RED_RGTC1_EXT: 36284,
|
|
462
|
-
COMPRESSED_RED_GREEN_RGTC2_EXT: 36285,
|
|
463
|
-
COMPRESSED_SIGNED_RED_GREEN_RGTC2_EXT: 36286,
|
|
464
|
-
COMPRESSED_SRGB_S3TC_DXT1_EXT: 35916,
|
|
465
|
-
COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT: 35917,
|
|
466
|
-
COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT: 35918,
|
|
467
|
-
COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT: 35919
|
|
468
|
-
};
|
|
370
|
+
// ../images/src/lib/category-api/parsed-image-api.ts
|
|
371
|
+
function getImageType(image) {
|
|
372
|
+
const format = getImageTypeOrNull(image);
|
|
373
|
+
if (!format) {
|
|
374
|
+
throw new Error("Not an image");
|
|
469
375
|
}
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
}
|
|
376
|
+
return format;
|
|
377
|
+
}
|
|
378
|
+
function getImageData(image) {
|
|
379
|
+
switch (getImageType(image)) {
|
|
380
|
+
case "data":
|
|
381
|
+
return image;
|
|
382
|
+
case "image":
|
|
383
|
+
case "imagebitmap":
|
|
384
|
+
const canvas = document.createElement("canvas");
|
|
385
|
+
const context = canvas.getContext("2d");
|
|
386
|
+
if (!context) {
|
|
387
|
+
throw new Error("getImageData");
|
|
483
388
|
}
|
|
484
|
-
|
|
389
|
+
canvas.width = image.width;
|
|
390
|
+
canvas.height = image.height;
|
|
391
|
+
context.drawImage(image, 0, 0);
|
|
392
|
+
return context.getImageData(0, 0, image.width, image.height);
|
|
393
|
+
default:
|
|
394
|
+
throw new Error("getImageData");
|
|
485
395
|
}
|
|
486
|
-
return formats;
|
|
487
396
|
}
|
|
488
|
-
function
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
return canvas.getContext("webgl");
|
|
492
|
-
} catch (error) {
|
|
493
|
-
return null;
|
|
397
|
+
function getImageTypeOrNull(image) {
|
|
398
|
+
if (typeof ImageBitmap !== "undefined" && image instanceof ImageBitmap) {
|
|
399
|
+
return "imagebitmap";
|
|
494
400
|
}
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
var init_texture_formats = __esm({
|
|
498
|
-
"../textures/src/lib/utils/texture-formats.ts"() {
|
|
499
|
-
BROWSER_PREFIXES = ["", "WEBKIT_", "MOZ_"];
|
|
500
|
-
WEBGL_EXTENSIONS = {
|
|
501
|
-
WEBGL_compressed_texture_s3tc: "dxt",
|
|
502
|
-
WEBGL_compressed_texture_s3tc_srgb: "dxt-srgb",
|
|
503
|
-
WEBGL_compressed_texture_etc1: "etc1",
|
|
504
|
-
WEBGL_compressed_texture_etc: "etc2",
|
|
505
|
-
WEBGL_compressed_texture_pvrtc: "pvrtc",
|
|
506
|
-
WEBGL_compressed_texture_atc: "atc",
|
|
507
|
-
WEBGL_compressed_texture_astc: "astc",
|
|
508
|
-
EXT_texture_compression_rgtc: "rgtc"
|
|
509
|
-
};
|
|
510
|
-
formats = null;
|
|
401
|
+
if (typeof Image !== "undefined" && image instanceof Image) {
|
|
402
|
+
return "image";
|
|
511
403
|
}
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
!function(t2) {
|
|
520
|
-
t2[t2.NONE = 0] = "NONE", t2[t2.BASISLZ = 1] = "BASISLZ", t2[t2.ZSTD = 2] = "ZSTD", t2[t2.ZLIB = 3] = "ZLIB";
|
|
521
|
-
}(n || (n = {})), function(t2) {
|
|
522
|
-
t2[t2.BASICFORMAT = 0] = "BASICFORMAT";
|
|
523
|
-
}(i || (i = {})), function(t2) {
|
|
524
|
-
t2[t2.UNSPECIFIED = 0] = "UNSPECIFIED", t2[t2.ETC1S = 163] = "ETC1S", t2[t2.UASTC = 166] = "UASTC";
|
|
525
|
-
}(s || (s = {})), function(t2) {
|
|
526
|
-
t2[t2.UNSPECIFIED = 0] = "UNSPECIFIED", t2[t2.SRGB = 1] = "SRGB";
|
|
527
|
-
}(a || (a = {})), function(t2) {
|
|
528
|
-
t2[t2.UNSPECIFIED = 0] = "UNSPECIFIED", t2[t2.LINEAR = 1] = "LINEAR", t2[t2.SRGB = 2] = "SRGB", t2[t2.ITU = 3] = "ITU", t2[t2.NTSC = 4] = "NTSC", t2[t2.SLOG = 5] = "SLOG", t2[t2.SLOG2 = 6] = "SLOG2";
|
|
529
|
-
}(r || (r = {})), function(t2) {
|
|
530
|
-
t2[t2.ALPHA_STRAIGHT = 0] = "ALPHA_STRAIGHT", t2[t2.ALPHA_PREMULTIPLIED = 1] = "ALPHA_PREMULTIPLIED";
|
|
531
|
-
}(o || (o = {})), function(t2) {
|
|
532
|
-
t2[t2.RGB = 0] = "RGB", t2[t2.RRR = 3] = "RRR", t2[t2.GGG = 4] = "GGG", t2[t2.AAA = 15] = "AAA";
|
|
533
|
-
}(l || (l = {})), function(t2) {
|
|
534
|
-
t2[t2.RGB = 0] = "RGB", t2[t2.RGBA = 3] = "RGBA", t2[t2.RRR = 4] = "RRR", t2[t2.RRRG = 5] = "RRRG";
|
|
535
|
-
}(f || (f = {}));
|
|
404
|
+
if (image && typeof image === "object" && image.data && image.width && image.height) {
|
|
405
|
+
return "data";
|
|
406
|
+
}
|
|
407
|
+
return null;
|
|
408
|
+
}
|
|
409
|
+
var init_parsed_image_api = __esm({
|
|
410
|
+
"../images/src/lib/category-api/parsed-image-api.ts"() {
|
|
536
411
|
}
|
|
537
412
|
});
|
|
538
413
|
|
|
539
|
-
// ../
|
|
540
|
-
function
|
|
541
|
-
|
|
542
|
-
const notKTX = id.byteLength < KTX2_ID.length || id[0] !== KTX2_ID[0] || id[1] !== KTX2_ID[1] || id[2] !== KTX2_ID[2] || id[3] !== KTX2_ID[3] || id[4] !== KTX2_ID[4] || id[5] !== KTX2_ID[5] || id[6] !== KTX2_ID[6] || id[7] !== KTX2_ID[7] || id[8] !== KTX2_ID[8] || id[9] !== KTX2_ID[9] || id[10] !== KTX2_ID[10] || id[11] !== KTX2_ID[11];
|
|
543
|
-
return !notKTX;
|
|
414
|
+
// ../images/src/lib/parsers/svg-utils.ts
|
|
415
|
+
function isSVG(url) {
|
|
416
|
+
return url && (SVG_DATA_URL_PATTERN.test(url) || SVG_URL_PATTERN.test(url));
|
|
544
417
|
}
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
50,
|
|
556
|
-
48,
|
|
557
|
-
187,
|
|
558
|
-
13,
|
|
559
|
-
10,
|
|
560
|
-
26,
|
|
561
|
-
10
|
|
562
|
-
];
|
|
563
|
-
}
|
|
564
|
-
});
|
|
565
|
-
|
|
566
|
-
// ../textures/src/lib/parsers/parse-basis.ts
|
|
567
|
-
async function parseBasis(data, options) {
|
|
568
|
-
if (options.basis.containerFormat === "auto") {
|
|
569
|
-
if (isKTX(data)) {
|
|
570
|
-
const fileConstructors = await loadBasisEncoderModule(options);
|
|
571
|
-
return parseKTX2File(fileConstructors.KTX2File, data, options);
|
|
418
|
+
function getBlobOrSVGDataUrl(arrayBuffer, url) {
|
|
419
|
+
if (isSVG(url)) {
|
|
420
|
+
const textDecoder = new TextDecoder();
|
|
421
|
+
let xmlText = textDecoder.decode(arrayBuffer);
|
|
422
|
+
try {
|
|
423
|
+
if (typeof unescape === "function" && typeof encodeURIComponent === "function") {
|
|
424
|
+
xmlText = unescape(encodeURIComponent(xmlText));
|
|
425
|
+
}
|
|
426
|
+
} catch (error) {
|
|
427
|
+
throw new Error(error.message);
|
|
572
428
|
}
|
|
573
|
-
const
|
|
574
|
-
return
|
|
429
|
+
const src = `data:image/svg+xml;base64,${btoa(xmlText)}`;
|
|
430
|
+
return src;
|
|
575
431
|
}
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
return parseKTX2File(fileConstructors.KTX2File, data, options);
|
|
582
|
-
case "basis":
|
|
583
|
-
default:
|
|
584
|
-
return parseBasisFile(fileConstructors.BasisFile, data, options);
|
|
585
|
-
}
|
|
586
|
-
case "transcoder":
|
|
587
|
-
default:
|
|
588
|
-
const { BasisFile } = await loadBasisTrascoderModule(options);
|
|
589
|
-
return parseBasisFile(BasisFile, data, options);
|
|
432
|
+
return getBlob(arrayBuffer, url);
|
|
433
|
+
}
|
|
434
|
+
function getBlob(arrayBuffer, url) {
|
|
435
|
+
if (isSVG(url)) {
|
|
436
|
+
throw new Error("SVG cannot be parsed directly to imagebitmap");
|
|
590
437
|
}
|
|
438
|
+
return new Blob([new Uint8Array(arrayBuffer)]);
|
|
591
439
|
}
|
|
592
|
-
|
|
593
|
-
|
|
440
|
+
var SVG_DATA_URL_PATTERN, SVG_URL_PATTERN;
|
|
441
|
+
var init_svg_utils = __esm({
|
|
442
|
+
"../images/src/lib/parsers/svg-utils.ts"() {
|
|
443
|
+
SVG_DATA_URL_PATTERN = /^data:image\/svg\+xml/;
|
|
444
|
+
SVG_URL_PATTERN = /\.svg((\?|#).*)?$/;
|
|
445
|
+
}
|
|
446
|
+
});
|
|
447
|
+
|
|
448
|
+
// ../images/src/lib/parsers/parse-to-image.ts
|
|
449
|
+
async function parseToImage(arrayBuffer, options, url) {
|
|
450
|
+
const blobOrDataUrl = getBlobOrSVGDataUrl(arrayBuffer, url);
|
|
451
|
+
const URL = self.URL || self.webkitURL;
|
|
452
|
+
const objectUrl = typeof blobOrDataUrl !== "string" && URL.createObjectURL(blobOrDataUrl);
|
|
594
453
|
try {
|
|
595
|
-
|
|
596
|
-
throw new Error("Failed to start basis transcoding");
|
|
597
|
-
}
|
|
598
|
-
const imageCount = basisFile.getNumImages();
|
|
599
|
-
const images = [];
|
|
600
|
-
for (let imageIndex = 0; imageIndex < imageCount; imageIndex++) {
|
|
601
|
-
const levelsCount = basisFile.getNumLevels(imageIndex);
|
|
602
|
-
const levels = [];
|
|
603
|
-
for (let levelIndex = 0; levelIndex < levelsCount; levelIndex++) {
|
|
604
|
-
levels.push(transcodeImage(basisFile, imageIndex, levelIndex, options));
|
|
605
|
-
}
|
|
606
|
-
images.push(levels);
|
|
607
|
-
}
|
|
608
|
-
return images;
|
|
454
|
+
return await loadToImage(objectUrl || blobOrDataUrl, options);
|
|
609
455
|
} finally {
|
|
610
|
-
|
|
611
|
-
|
|
456
|
+
if (objectUrl) {
|
|
457
|
+
URL.revokeObjectURL(objectUrl);
|
|
458
|
+
}
|
|
612
459
|
}
|
|
613
460
|
}
|
|
614
|
-
function
|
|
615
|
-
const
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
const decodedData = new Uint8Array(decodedSize);
|
|
621
|
-
if (!basisFile.transcodeImage(decodedData, imageIndex, levelIndex, basisFormat, 0, 0)) {
|
|
622
|
-
throw new Error("failed to start Basis transcoding");
|
|
461
|
+
async function loadToImage(url, options) {
|
|
462
|
+
const image = new Image();
|
|
463
|
+
image.src = url;
|
|
464
|
+
if (options.image && options.image.decode && image.decode) {
|
|
465
|
+
await image.decode();
|
|
466
|
+
return image;
|
|
623
467
|
}
|
|
624
|
-
return {
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
hasAlpha
|
|
631
|
-
};
|
|
632
|
-
}
|
|
633
|
-
function parseKTX2File(KTX2File, data, options) {
|
|
634
|
-
const ktx2File = new KTX2File(new Uint8Array(data));
|
|
635
|
-
try {
|
|
636
|
-
if (!ktx2File.startTranscoding()) {
|
|
637
|
-
throw new Error("failed to start KTX2 transcoding");
|
|
468
|
+
return await new Promise((resolve, reject) => {
|
|
469
|
+
try {
|
|
470
|
+
image.onload = () => resolve(image);
|
|
471
|
+
image.onerror = (err) => reject(new Error(`Could not load image ${url}: ${err}`));
|
|
472
|
+
} catch (error) {
|
|
473
|
+
reject(error);
|
|
638
474
|
}
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
475
|
+
});
|
|
476
|
+
}
|
|
477
|
+
var init_parse_to_image = __esm({
|
|
478
|
+
"../images/src/lib/parsers/parse-to-image.ts"() {
|
|
479
|
+
init_svg_utils();
|
|
480
|
+
}
|
|
481
|
+
});
|
|
482
|
+
|
|
483
|
+
// ../images/src/lib/parsers/parse-to-image-bitmap.ts
|
|
484
|
+
async function parseToImageBitmap(arrayBuffer, options, url) {
|
|
485
|
+
let blob;
|
|
486
|
+
if (isSVG(url)) {
|
|
487
|
+
const image = await parseToImage(arrayBuffer, options, url);
|
|
488
|
+
blob = image;
|
|
489
|
+
} else {
|
|
490
|
+
blob = getBlob(arrayBuffer, url);
|
|
491
|
+
}
|
|
492
|
+
const imagebitmapOptions = options && options.imagebitmap;
|
|
493
|
+
return await safeCreateImageBitmap(blob, imagebitmapOptions);
|
|
494
|
+
}
|
|
495
|
+
async function safeCreateImageBitmap(blob, imagebitmapOptions = null) {
|
|
496
|
+
if (isEmptyObject(imagebitmapOptions) || !imagebitmapOptionsSupported) {
|
|
497
|
+
imagebitmapOptions = null;
|
|
498
|
+
}
|
|
499
|
+
if (imagebitmapOptions) {
|
|
500
|
+
try {
|
|
501
|
+
return await createImageBitmap(blob, imagebitmapOptions);
|
|
502
|
+
} catch (error) {
|
|
503
|
+
console.warn(error);
|
|
504
|
+
imagebitmapOptionsSupported = false;
|
|
644
505
|
}
|
|
645
|
-
return [levels];
|
|
646
|
-
} finally {
|
|
647
|
-
ktx2File.close();
|
|
648
|
-
ktx2File.delete();
|
|
649
506
|
}
|
|
507
|
+
return await createImageBitmap(blob);
|
|
650
508
|
}
|
|
651
|
-
function
|
|
652
|
-
const
|
|
653
|
-
|
|
654
|
-
const decodedSize = ktx2File.getImageTranscodedSizeInBytes(levelIndex, 0, 0, basisFormat);
|
|
655
|
-
const decodedData = new Uint8Array(decodedSize);
|
|
656
|
-
if (!ktx2File.transcodeImage(decodedData, levelIndex, 0, 0, basisFormat, 0, -1, -1)) {
|
|
657
|
-
throw new Error("Failed to transcode KTX2 image");
|
|
509
|
+
function isEmptyObject(object) {
|
|
510
|
+
for (const key in object || EMPTY_OBJECT) {
|
|
511
|
+
return false;
|
|
658
512
|
}
|
|
659
|
-
return
|
|
660
|
-
width,
|
|
661
|
-
height,
|
|
662
|
-
data: decodedData,
|
|
663
|
-
compressed,
|
|
664
|
-
levelSize: decodedSize,
|
|
665
|
-
hasAlpha: alphaFlag,
|
|
666
|
-
format
|
|
667
|
-
};
|
|
513
|
+
return true;
|
|
668
514
|
}
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
515
|
+
var EMPTY_OBJECT, imagebitmapOptionsSupported;
|
|
516
|
+
var init_parse_to_image_bitmap = __esm({
|
|
517
|
+
"../images/src/lib/parsers/parse-to-image-bitmap.ts"() {
|
|
518
|
+
init_svg_utils();
|
|
519
|
+
init_parse_to_image();
|
|
520
|
+
EMPTY_OBJECT = {};
|
|
521
|
+
imagebitmapOptionsSupported = true;
|
|
673
522
|
}
|
|
674
|
-
|
|
675
|
-
|
|
523
|
+
});
|
|
524
|
+
|
|
525
|
+
// ../images/src/lib/category-api/parse-isobmff-binary.ts
|
|
526
|
+
function getISOBMFFMediaType(buffer) {
|
|
527
|
+
if (!checkString(buffer, "ftyp", 4)) {
|
|
528
|
+
return null;
|
|
676
529
|
}
|
|
677
|
-
|
|
678
|
-
|
|
530
|
+
if ((buffer[8] & 96) === 0) {
|
|
531
|
+
return null;
|
|
532
|
+
}
|
|
533
|
+
return decodeMajorBrand(buffer);
|
|
679
534
|
}
|
|
680
|
-
function
|
|
681
|
-
const
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
};
|
|
689
|
-
} else if (supportedFormats.has("pvrtc")) {
|
|
690
|
-
return {
|
|
691
|
-
alpha: "pvrtc1-4-rgba",
|
|
692
|
-
noAlpha: "pvrtc1-4-rgb"
|
|
693
|
-
};
|
|
694
|
-
} else if (supportedFormats.has("etc1")) {
|
|
695
|
-
return "etc1";
|
|
696
|
-
} else if (supportedFormats.has("etc2")) {
|
|
697
|
-
return "etc2";
|
|
535
|
+
function decodeMajorBrand(buffer) {
|
|
536
|
+
const brandMajor = getUTF8String(buffer, 8, 12).replace("\0", " ").trim();
|
|
537
|
+
switch (brandMajor) {
|
|
538
|
+
case "avif":
|
|
539
|
+
case "avis":
|
|
540
|
+
return { extension: "avif", mimeType: "image/avif" };
|
|
541
|
+
default:
|
|
542
|
+
return null;
|
|
698
543
|
}
|
|
699
|
-
return "rgb565";
|
|
700
544
|
}
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
"../textures/src/lib/parsers/parse-basis.ts"() {
|
|
704
|
-
init_basis_module_loader();
|
|
705
|
-
init_gl_extensions();
|
|
706
|
-
init_texture_formats();
|
|
707
|
-
init_parse_ktx();
|
|
708
|
-
OutputFormat = {
|
|
709
|
-
etc1: {
|
|
710
|
-
basisFormat: 0,
|
|
711
|
-
compressed: true,
|
|
712
|
-
format: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGB_ETC1_WEBGL
|
|
713
|
-
},
|
|
714
|
-
etc2: { basisFormat: 1, compressed: true },
|
|
715
|
-
bc1: {
|
|
716
|
-
basisFormat: 2,
|
|
717
|
-
compressed: true,
|
|
718
|
-
format: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGB_S3TC_DXT1_EXT
|
|
719
|
-
},
|
|
720
|
-
bc3: {
|
|
721
|
-
basisFormat: 3,
|
|
722
|
-
compressed: true,
|
|
723
|
-
format: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_S3TC_DXT5_EXT
|
|
724
|
-
},
|
|
725
|
-
bc4: { basisFormat: 4, compressed: true },
|
|
726
|
-
bc5: { basisFormat: 5, compressed: true },
|
|
727
|
-
"bc7-m6-opaque-only": { basisFormat: 6, compressed: true },
|
|
728
|
-
"bc7-m5": { basisFormat: 7, compressed: true },
|
|
729
|
-
"pvrtc1-4-rgb": {
|
|
730
|
-
basisFormat: 8,
|
|
731
|
-
compressed: true,
|
|
732
|
-
format: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGB_PVRTC_4BPPV1_IMG
|
|
733
|
-
},
|
|
734
|
-
"pvrtc1-4-rgba": {
|
|
735
|
-
basisFormat: 9,
|
|
736
|
-
compressed: true,
|
|
737
|
-
format: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG
|
|
738
|
-
},
|
|
739
|
-
"astc-4x4": {
|
|
740
|
-
basisFormat: 10,
|
|
741
|
-
compressed: true,
|
|
742
|
-
format: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_4X4_KHR
|
|
743
|
-
},
|
|
744
|
-
"atc-rgb": { basisFormat: 11, compressed: true },
|
|
745
|
-
"atc-rgba-interpolated-alpha": { basisFormat: 12, compressed: true },
|
|
746
|
-
rgba32: { basisFormat: 13, compressed: false },
|
|
747
|
-
rgb565: { basisFormat: 14, compressed: false },
|
|
748
|
-
bgr565: { basisFormat: 15, compressed: false },
|
|
749
|
-
rgba4444: { basisFormat: 16, compressed: false }
|
|
750
|
-
};
|
|
751
|
-
}
|
|
752
|
-
});
|
|
753
|
-
|
|
754
|
-
// ../textures/src/basis-loader.ts
|
|
755
|
-
var BasisWorkerLoader, BasisLoader;
|
|
756
|
-
var init_basis_loader = __esm({
|
|
757
|
-
"../textures/src/basis-loader.ts"() {
|
|
758
|
-
init_src();
|
|
759
|
-
init_version3();
|
|
760
|
-
init_parse_basis();
|
|
761
|
-
BasisWorkerLoader = {
|
|
762
|
-
name: "Basis",
|
|
763
|
-
id: isBrowser2 ? "basis" : "basis-nodejs",
|
|
764
|
-
module: "textures",
|
|
765
|
-
version: VERSION4,
|
|
766
|
-
worker: true,
|
|
767
|
-
extensions: ["basis", "ktx2"],
|
|
768
|
-
mimeTypes: ["application/octet-stream", "image/ktx2"],
|
|
769
|
-
tests: ["sB"],
|
|
770
|
-
binary: true,
|
|
771
|
-
options: {
|
|
772
|
-
basis: {
|
|
773
|
-
format: "auto",
|
|
774
|
-
libraryPath: "libs/",
|
|
775
|
-
containerFormat: "auto",
|
|
776
|
-
module: "transcoder"
|
|
777
|
-
}
|
|
778
|
-
}
|
|
779
|
-
};
|
|
780
|
-
BasisLoader = {
|
|
781
|
-
...BasisWorkerLoader,
|
|
782
|
-
parse: parseBasis
|
|
783
|
-
};
|
|
784
|
-
}
|
|
785
|
-
});
|
|
786
|
-
|
|
787
|
-
// ../images/src/lib/utils/version.ts
|
|
788
|
-
var VERSION6;
|
|
789
|
-
var init_version4 = __esm({
|
|
790
|
-
"../images/src/lib/utils/version.ts"() {
|
|
791
|
-
VERSION6 = typeof __VERSION__ !== "undefined" ? __VERSION__ : "latest";
|
|
792
|
-
}
|
|
793
|
-
});
|
|
794
|
-
|
|
795
|
-
// ../images/src/lib/category-api/image-type.ts
|
|
796
|
-
function isImageTypeSupported(type) {
|
|
797
|
-
switch (type) {
|
|
798
|
-
case "auto":
|
|
799
|
-
return IMAGE_BITMAP_SUPPORTED || IMAGE_SUPPORTED || DATA_SUPPORTED;
|
|
800
|
-
case "imagebitmap":
|
|
801
|
-
return IMAGE_BITMAP_SUPPORTED;
|
|
802
|
-
case "image":
|
|
803
|
-
return IMAGE_SUPPORTED;
|
|
804
|
-
case "data":
|
|
805
|
-
return DATA_SUPPORTED;
|
|
806
|
-
default:
|
|
807
|
-
throw new Error(`@loaders.gl/images: image ${type} not supported in this environment`);
|
|
808
|
-
}
|
|
545
|
+
function getUTF8String(array, start, end) {
|
|
546
|
+
return String.fromCharCode(...array.slice(start, end));
|
|
809
547
|
}
|
|
810
|
-
function
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
548
|
+
function stringToBytes(string) {
|
|
549
|
+
return [...string].map((character) => character.charCodeAt(0));
|
|
550
|
+
}
|
|
551
|
+
function checkString(buffer, header, offset = 0) {
|
|
552
|
+
const headerBytes = stringToBytes(header);
|
|
553
|
+
for (let i2 = 0; i2 < headerBytes.length; ++i2) {
|
|
554
|
+
if (headerBytes[i2] !== buffer[i2 + offset]) {
|
|
555
|
+
return false;
|
|
556
|
+
}
|
|
819
557
|
}
|
|
820
|
-
|
|
558
|
+
return true;
|
|
821
559
|
}
|
|
822
|
-
var
|
|
823
|
-
|
|
824
|
-
"../images/src/lib/category-api/image-type.ts"() {
|
|
825
|
-
init_src2();
|
|
826
|
-
({ _parseImageNode } = globalThis);
|
|
827
|
-
IMAGE_SUPPORTED = typeof Image !== "undefined";
|
|
828
|
-
IMAGE_BITMAP_SUPPORTED = typeof ImageBitmap !== "undefined";
|
|
829
|
-
NODE_IMAGE_SUPPORTED = Boolean(_parseImageNode);
|
|
830
|
-
DATA_SUPPORTED = isBrowser ? true : NODE_IMAGE_SUPPORTED;
|
|
560
|
+
var init_parse_isobmff_binary = __esm({
|
|
561
|
+
"../images/src/lib/category-api/parse-isobmff-binary.ts"() {
|
|
831
562
|
}
|
|
832
563
|
});
|
|
833
564
|
|
|
834
|
-
// ../images/src/lib/category-api/
|
|
835
|
-
function
|
|
836
|
-
const
|
|
837
|
-
|
|
838
|
-
throw new Error("Not an image");
|
|
839
|
-
}
|
|
840
|
-
return format;
|
|
565
|
+
// ../images/src/lib/category-api/binary-image-api.ts
|
|
566
|
+
function getBinaryImageMetadata(binaryData) {
|
|
567
|
+
const dataView = toDataView(binaryData);
|
|
568
|
+
return getPngMetadata(dataView) || getJpegMetadata(dataView) || getGifMetadata(dataView) || getBmpMetadata(dataView) || getISOBMFFMetadata(dataView);
|
|
841
569
|
}
|
|
842
|
-
function
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
case "imagebitmap":
|
|
848
|
-
const canvas = document.createElement("canvas");
|
|
849
|
-
const context = canvas.getContext("2d");
|
|
850
|
-
if (!context) {
|
|
851
|
-
throw new Error("getImageData");
|
|
852
|
-
}
|
|
853
|
-
canvas.width = image.width;
|
|
854
|
-
canvas.height = image.height;
|
|
855
|
-
context.drawImage(image, 0, 0);
|
|
856
|
-
return context.getImageData(0, 0, image.width, image.height);
|
|
857
|
-
default:
|
|
858
|
-
throw new Error("getImageData");
|
|
570
|
+
function getISOBMFFMetadata(binaryData) {
|
|
571
|
+
const buffer = new Uint8Array(binaryData instanceof DataView ? binaryData.buffer : binaryData);
|
|
572
|
+
const mediaType = getISOBMFFMediaType(buffer);
|
|
573
|
+
if (!mediaType) {
|
|
574
|
+
return null;
|
|
859
575
|
}
|
|
576
|
+
return {
|
|
577
|
+
mimeType: mediaType.mimeType,
|
|
578
|
+
width: 0,
|
|
579
|
+
height: 0
|
|
580
|
+
};
|
|
860
581
|
}
|
|
861
|
-
function
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
return "image";
|
|
582
|
+
function getPngMetadata(binaryData) {
|
|
583
|
+
const dataView = toDataView(binaryData);
|
|
584
|
+
const isPng = dataView.byteLength >= 24 && dataView.getUint32(0, BIG_ENDIAN) === 2303741511;
|
|
585
|
+
if (!isPng) {
|
|
586
|
+
return null;
|
|
867
587
|
}
|
|
868
|
-
|
|
869
|
-
|
|
588
|
+
return {
|
|
589
|
+
mimeType: "image/png",
|
|
590
|
+
width: dataView.getUint32(16, BIG_ENDIAN),
|
|
591
|
+
height: dataView.getUint32(20, BIG_ENDIAN)
|
|
592
|
+
};
|
|
593
|
+
}
|
|
594
|
+
function getGifMetadata(binaryData) {
|
|
595
|
+
const dataView = toDataView(binaryData);
|
|
596
|
+
const isGif = dataView.byteLength >= 10 && dataView.getUint32(0, BIG_ENDIAN) === 1195984440;
|
|
597
|
+
if (!isGif) {
|
|
598
|
+
return null;
|
|
870
599
|
}
|
|
871
|
-
return
|
|
600
|
+
return {
|
|
601
|
+
mimeType: "image/gif",
|
|
602
|
+
width: dataView.getUint16(6, LITTLE_ENDIAN),
|
|
603
|
+
height: dataView.getUint16(8, LITTLE_ENDIAN)
|
|
604
|
+
};
|
|
872
605
|
}
|
|
873
|
-
|
|
874
|
-
|
|
606
|
+
function getBmpMetadata(binaryData) {
|
|
607
|
+
const dataView = toDataView(binaryData);
|
|
608
|
+
const isBmp = dataView.byteLength >= 14 && dataView.getUint16(0, BIG_ENDIAN) === 16973 && dataView.getUint32(2, LITTLE_ENDIAN) === dataView.byteLength;
|
|
609
|
+
if (!isBmp) {
|
|
610
|
+
return null;
|
|
875
611
|
}
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
612
|
+
return {
|
|
613
|
+
mimeType: "image/bmp",
|
|
614
|
+
width: dataView.getUint32(18, LITTLE_ENDIAN),
|
|
615
|
+
height: dataView.getUint32(22, LITTLE_ENDIAN)
|
|
616
|
+
};
|
|
881
617
|
}
|
|
882
|
-
function
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
618
|
+
function getJpegMetadata(binaryData) {
|
|
619
|
+
const dataView = toDataView(binaryData);
|
|
620
|
+
const isJpeg = dataView.byteLength >= 3 && dataView.getUint16(0, BIG_ENDIAN) === 65496 && dataView.getUint8(2) === 255;
|
|
621
|
+
if (!isJpeg) {
|
|
622
|
+
return null;
|
|
623
|
+
}
|
|
624
|
+
const { tableMarkers, sofMarkers } = getJpegMarkers();
|
|
625
|
+
let i2 = 2;
|
|
626
|
+
while (i2 + 9 < dataView.byteLength) {
|
|
627
|
+
const marker = dataView.getUint16(i2, BIG_ENDIAN);
|
|
628
|
+
if (sofMarkers.has(marker)) {
|
|
629
|
+
return {
|
|
630
|
+
mimeType: "image/jpeg",
|
|
631
|
+
height: dataView.getUint16(i2 + 5, BIG_ENDIAN),
|
|
632
|
+
width: dataView.getUint16(i2 + 7, BIG_ENDIAN)
|
|
633
|
+
};
|
|
892
634
|
}
|
|
893
|
-
|
|
894
|
-
|
|
635
|
+
if (!tableMarkers.has(marker)) {
|
|
636
|
+
return null;
|
|
637
|
+
}
|
|
638
|
+
i2 += 2;
|
|
639
|
+
i2 += dataView.getUint16(i2, BIG_ENDIAN);
|
|
895
640
|
}
|
|
896
|
-
return
|
|
897
|
-
}
|
|
898
|
-
function getBlob(arrayBuffer, url) {
|
|
899
|
-
if (isSVG(url)) {
|
|
900
|
-
throw new Error("SVG cannot be parsed directly to imagebitmap");
|
|
901
|
-
}
|
|
902
|
-
return new Blob([new Uint8Array(arrayBuffer)]);
|
|
903
|
-
}
|
|
904
|
-
var SVG_DATA_URL_PATTERN, SVG_URL_PATTERN;
|
|
905
|
-
var init_svg_utils = __esm({
|
|
906
|
-
"../images/src/lib/parsers/svg-utils.ts"() {
|
|
907
|
-
SVG_DATA_URL_PATTERN = /^data:image\/svg\+xml/;
|
|
908
|
-
SVG_URL_PATTERN = /\.svg((\?|#).*)?$/;
|
|
909
|
-
}
|
|
910
|
-
});
|
|
911
|
-
|
|
912
|
-
// ../images/src/lib/parsers/parse-to-image.ts
|
|
913
|
-
async function parseToImage(arrayBuffer, options, url) {
|
|
914
|
-
const blobOrDataUrl = getBlobOrSVGDataUrl(arrayBuffer, url);
|
|
915
|
-
const URL = self.URL || self.webkitURL;
|
|
916
|
-
const objectUrl = typeof blobOrDataUrl !== "string" && URL.createObjectURL(blobOrDataUrl);
|
|
917
|
-
try {
|
|
918
|
-
return await loadToImage(objectUrl || blobOrDataUrl, options);
|
|
919
|
-
} finally {
|
|
920
|
-
if (objectUrl) {
|
|
921
|
-
URL.revokeObjectURL(objectUrl);
|
|
922
|
-
}
|
|
923
|
-
}
|
|
924
|
-
}
|
|
925
|
-
async function loadToImage(url, options) {
|
|
926
|
-
const image = new Image();
|
|
927
|
-
image.src = url;
|
|
928
|
-
if (options.image && options.image.decode && image.decode) {
|
|
929
|
-
await image.decode();
|
|
930
|
-
return image;
|
|
931
|
-
}
|
|
932
|
-
return await new Promise((resolve, reject) => {
|
|
933
|
-
try {
|
|
934
|
-
image.onload = () => resolve(image);
|
|
935
|
-
image.onerror = (err) => reject(new Error(`Could not load image ${url}: ${err}`));
|
|
936
|
-
} catch (error) {
|
|
937
|
-
reject(error);
|
|
938
|
-
}
|
|
939
|
-
});
|
|
940
|
-
}
|
|
941
|
-
var init_parse_to_image = __esm({
|
|
942
|
-
"../images/src/lib/parsers/parse-to-image.ts"() {
|
|
943
|
-
init_svg_utils();
|
|
944
|
-
}
|
|
945
|
-
});
|
|
946
|
-
|
|
947
|
-
// ../images/src/lib/parsers/parse-to-image-bitmap.ts
|
|
948
|
-
async function parseToImageBitmap(arrayBuffer, options, url) {
|
|
949
|
-
let blob;
|
|
950
|
-
if (isSVG(url)) {
|
|
951
|
-
const image = await parseToImage(arrayBuffer, options, url);
|
|
952
|
-
blob = image;
|
|
953
|
-
} else {
|
|
954
|
-
blob = getBlob(arrayBuffer, url);
|
|
955
|
-
}
|
|
956
|
-
const imagebitmapOptions = options && options.imagebitmap;
|
|
957
|
-
return await safeCreateImageBitmap(blob, imagebitmapOptions);
|
|
958
|
-
}
|
|
959
|
-
async function safeCreateImageBitmap(blob, imagebitmapOptions = null) {
|
|
960
|
-
if (isEmptyObject(imagebitmapOptions) || !imagebitmapOptionsSupported) {
|
|
961
|
-
imagebitmapOptions = null;
|
|
962
|
-
}
|
|
963
|
-
if (imagebitmapOptions) {
|
|
964
|
-
try {
|
|
965
|
-
return await createImageBitmap(blob, imagebitmapOptions);
|
|
966
|
-
} catch (error) {
|
|
967
|
-
console.warn(error);
|
|
968
|
-
imagebitmapOptionsSupported = false;
|
|
969
|
-
}
|
|
970
|
-
}
|
|
971
|
-
return await createImageBitmap(blob);
|
|
972
|
-
}
|
|
973
|
-
function isEmptyObject(object) {
|
|
974
|
-
for (const key in object || EMPTY_OBJECT) {
|
|
975
|
-
return false;
|
|
976
|
-
}
|
|
977
|
-
return true;
|
|
978
|
-
}
|
|
979
|
-
var EMPTY_OBJECT, imagebitmapOptionsSupported;
|
|
980
|
-
var init_parse_to_image_bitmap = __esm({
|
|
981
|
-
"../images/src/lib/parsers/parse-to-image-bitmap.ts"() {
|
|
982
|
-
init_svg_utils();
|
|
983
|
-
init_parse_to_image();
|
|
984
|
-
EMPTY_OBJECT = {};
|
|
985
|
-
imagebitmapOptionsSupported = true;
|
|
986
|
-
}
|
|
987
|
-
});
|
|
988
|
-
|
|
989
|
-
// ../images/src/lib/category-api/parse-isobmff-binary.ts
|
|
990
|
-
function getISOBMFFMediaType(buffer) {
|
|
991
|
-
if (!checkString(buffer, "ftyp", 4)) {
|
|
992
|
-
return null;
|
|
993
|
-
}
|
|
994
|
-
if ((buffer[8] & 96) === 0) {
|
|
995
|
-
return null;
|
|
996
|
-
}
|
|
997
|
-
return decodeMajorBrand(buffer);
|
|
998
|
-
}
|
|
999
|
-
function decodeMajorBrand(buffer) {
|
|
1000
|
-
const brandMajor = getUTF8String(buffer, 8, 12).replace("\0", " ").trim();
|
|
1001
|
-
switch (brandMajor) {
|
|
1002
|
-
case "avif":
|
|
1003
|
-
case "avis":
|
|
1004
|
-
return { extension: "avif", mimeType: "image/avif" };
|
|
1005
|
-
default:
|
|
1006
|
-
return null;
|
|
1007
|
-
}
|
|
1008
|
-
}
|
|
1009
|
-
function getUTF8String(array, start, end) {
|
|
1010
|
-
return String.fromCharCode(...array.slice(start, end));
|
|
1011
|
-
}
|
|
1012
|
-
function stringToBytes(string) {
|
|
1013
|
-
return [...string].map((character) => character.charCodeAt(0));
|
|
1014
|
-
}
|
|
1015
|
-
function checkString(buffer, header, offset = 0) {
|
|
1016
|
-
const headerBytes = stringToBytes(header);
|
|
1017
|
-
for (let i2 = 0; i2 < headerBytes.length; ++i2) {
|
|
1018
|
-
if (headerBytes[i2] !== buffer[i2 + offset]) {
|
|
1019
|
-
return false;
|
|
1020
|
-
}
|
|
1021
|
-
}
|
|
1022
|
-
return true;
|
|
1023
|
-
}
|
|
1024
|
-
var init_parse_isobmff_binary = __esm({
|
|
1025
|
-
"../images/src/lib/category-api/parse-isobmff-binary.ts"() {
|
|
1026
|
-
}
|
|
1027
|
-
});
|
|
1028
|
-
|
|
1029
|
-
// ../images/src/lib/category-api/binary-image-api.ts
|
|
1030
|
-
function getBinaryImageMetadata(binaryData) {
|
|
1031
|
-
const dataView = toDataView(binaryData);
|
|
1032
|
-
return getPngMetadata(dataView) || getJpegMetadata(dataView) || getGifMetadata(dataView) || getBmpMetadata(dataView) || getISOBMFFMetadata(dataView);
|
|
1033
|
-
}
|
|
1034
|
-
function getISOBMFFMetadata(binaryData) {
|
|
1035
|
-
const buffer = new Uint8Array(binaryData instanceof DataView ? binaryData.buffer : binaryData);
|
|
1036
|
-
const mediaType = getISOBMFFMediaType(buffer);
|
|
1037
|
-
if (!mediaType) {
|
|
1038
|
-
return null;
|
|
1039
|
-
}
|
|
1040
|
-
return {
|
|
1041
|
-
mimeType: mediaType.mimeType,
|
|
1042
|
-
width: 0,
|
|
1043
|
-
height: 0
|
|
1044
|
-
};
|
|
1045
|
-
}
|
|
1046
|
-
function getPngMetadata(binaryData) {
|
|
1047
|
-
const dataView = toDataView(binaryData);
|
|
1048
|
-
const isPng = dataView.byteLength >= 24 && dataView.getUint32(0, BIG_ENDIAN) === 2303741511;
|
|
1049
|
-
if (!isPng) {
|
|
1050
|
-
return null;
|
|
1051
|
-
}
|
|
1052
|
-
return {
|
|
1053
|
-
mimeType: "image/png",
|
|
1054
|
-
width: dataView.getUint32(16, BIG_ENDIAN),
|
|
1055
|
-
height: dataView.getUint32(20, BIG_ENDIAN)
|
|
1056
|
-
};
|
|
1057
|
-
}
|
|
1058
|
-
function getGifMetadata(binaryData) {
|
|
1059
|
-
const dataView = toDataView(binaryData);
|
|
1060
|
-
const isGif = dataView.byteLength >= 10 && dataView.getUint32(0, BIG_ENDIAN) === 1195984440;
|
|
1061
|
-
if (!isGif) {
|
|
1062
|
-
return null;
|
|
1063
|
-
}
|
|
1064
|
-
return {
|
|
1065
|
-
mimeType: "image/gif",
|
|
1066
|
-
width: dataView.getUint16(6, LITTLE_ENDIAN),
|
|
1067
|
-
height: dataView.getUint16(8, LITTLE_ENDIAN)
|
|
1068
|
-
};
|
|
1069
|
-
}
|
|
1070
|
-
function getBmpMetadata(binaryData) {
|
|
1071
|
-
const dataView = toDataView(binaryData);
|
|
1072
|
-
const isBmp = dataView.byteLength >= 14 && dataView.getUint16(0, BIG_ENDIAN) === 16973 && dataView.getUint32(2, LITTLE_ENDIAN) === dataView.byteLength;
|
|
1073
|
-
if (!isBmp) {
|
|
1074
|
-
return null;
|
|
1075
|
-
}
|
|
1076
|
-
return {
|
|
1077
|
-
mimeType: "image/bmp",
|
|
1078
|
-
width: dataView.getUint32(18, LITTLE_ENDIAN),
|
|
1079
|
-
height: dataView.getUint32(22, LITTLE_ENDIAN)
|
|
1080
|
-
};
|
|
1081
|
-
}
|
|
1082
|
-
function getJpegMetadata(binaryData) {
|
|
1083
|
-
const dataView = toDataView(binaryData);
|
|
1084
|
-
const isJpeg = dataView.byteLength >= 3 && dataView.getUint16(0, BIG_ENDIAN) === 65496 && dataView.getUint8(2) === 255;
|
|
1085
|
-
if (!isJpeg) {
|
|
1086
|
-
return null;
|
|
1087
|
-
}
|
|
1088
|
-
const { tableMarkers, sofMarkers } = getJpegMarkers();
|
|
1089
|
-
let i2 = 2;
|
|
1090
|
-
while (i2 + 9 < dataView.byteLength) {
|
|
1091
|
-
const marker = dataView.getUint16(i2, BIG_ENDIAN);
|
|
1092
|
-
if (sofMarkers.has(marker)) {
|
|
1093
|
-
return {
|
|
1094
|
-
mimeType: "image/jpeg",
|
|
1095
|
-
height: dataView.getUint16(i2 + 5, BIG_ENDIAN),
|
|
1096
|
-
width: dataView.getUint16(i2 + 7, BIG_ENDIAN)
|
|
1097
|
-
};
|
|
1098
|
-
}
|
|
1099
|
-
if (!tableMarkers.has(marker)) {
|
|
1100
|
-
return null;
|
|
1101
|
-
}
|
|
1102
|
-
i2 += 2;
|
|
1103
|
-
i2 += dataView.getUint16(i2, BIG_ENDIAN);
|
|
1104
|
-
}
|
|
1105
|
-
return null;
|
|
641
|
+
return null;
|
|
1106
642
|
}
|
|
1107
643
|
function getJpegMarkers() {
|
|
1108
644
|
const tableMarkers = new Set([65499, 65476, 65484, 65501, 65534]);
|
|
@@ -1213,7 +749,7 @@
|
|
|
1213
749
|
var EXTENSIONS, MIME_TYPES, DEFAULT_IMAGE_LOADER_OPTIONS, ImageLoader;
|
|
1214
750
|
var init_image_loader = __esm({
|
|
1215
751
|
"../images/src/image-loader.ts"() {
|
|
1216
|
-
|
|
752
|
+
init_version3();
|
|
1217
753
|
init_parse_image();
|
|
1218
754
|
init_binary_image_api();
|
|
1219
755
|
EXTENSIONS = ["png", "jpg", "jpeg", "gif", "webp", "bmp", "ico", "svg", "avif"];
|
|
@@ -1237,7 +773,7 @@
|
|
|
1237
773
|
id: "image",
|
|
1238
774
|
module: "images",
|
|
1239
775
|
name: "Images",
|
|
1240
|
-
version:
|
|
776
|
+
version: VERSION4,
|
|
1241
777
|
mimeTypes: MIME_TYPES,
|
|
1242
778
|
extensions: EXTENSIONS,
|
|
1243
779
|
parse: parseImage,
|
|
@@ -1260,38 +796,500 @@
|
|
|
1260
796
|
const { _parseImageNode: _parseImageNode2, _imageFormatsNode = NODE_FORMAT_SUPPORT } = globalThis;
|
|
1261
797
|
return Boolean(_parseImageNode2) && _imageFormatsNode.includes(mimeType);
|
|
1262
798
|
}
|
|
1263
|
-
function checkBrowserImageFormatSupport(mimeType) {
|
|
1264
|
-
switch (mimeType) {
|
|
1265
|
-
case "image/avif":
|
|
1266
|
-
case "image/webp":
|
|
1267
|
-
return testBrowserImageFormatSupport(mimeType);
|
|
1268
|
-
default:
|
|
1269
|
-
return true;
|
|
799
|
+
function checkBrowserImageFormatSupport(mimeType) {
|
|
800
|
+
switch (mimeType) {
|
|
801
|
+
case "image/avif":
|
|
802
|
+
case "image/webp":
|
|
803
|
+
return testBrowserImageFormatSupport(mimeType);
|
|
804
|
+
default:
|
|
805
|
+
return true;
|
|
806
|
+
}
|
|
807
|
+
}
|
|
808
|
+
function testBrowserImageFormatSupport(mimeType) {
|
|
809
|
+
try {
|
|
810
|
+
const element = document.createElement("canvas");
|
|
811
|
+
const dataURL = element.toDataURL(mimeType);
|
|
812
|
+
return dataURL.indexOf(`data:${mimeType}`) === 0;
|
|
813
|
+
} catch {
|
|
814
|
+
return false;
|
|
815
|
+
}
|
|
816
|
+
}
|
|
817
|
+
var mimeTypeSupportedSync;
|
|
818
|
+
var init_image_format = __esm({
|
|
819
|
+
"../images/src/lib/category-api/image-format.ts"() {
|
|
820
|
+
init_src2();
|
|
821
|
+
mimeTypeSupportedSync = {};
|
|
822
|
+
}
|
|
823
|
+
});
|
|
824
|
+
|
|
825
|
+
// ../images/src/index.ts
|
|
826
|
+
var init_src3 = __esm({
|
|
827
|
+
"../images/src/index.ts"() {
|
|
828
|
+
init_image_loader();
|
|
829
|
+
init_binary_image_api();
|
|
830
|
+
init_image_format();
|
|
831
|
+
}
|
|
832
|
+
});
|
|
833
|
+
|
|
834
|
+
// ../textures/src/lib/utils/version.ts
|
|
835
|
+
var VERSION5;
|
|
836
|
+
var init_version4 = __esm({
|
|
837
|
+
"../textures/src/lib/utils/version.ts"() {
|
|
838
|
+
VERSION5 = typeof __VERSION__ !== "undefined" ? __VERSION__ : "beta";
|
|
839
|
+
}
|
|
840
|
+
});
|
|
841
|
+
|
|
842
|
+
// ../textures/src/lib/parsers/basis-module-loader.ts
|
|
843
|
+
async function loadBasisTrascoderModule(options) {
|
|
844
|
+
const modules = options.modules || {};
|
|
845
|
+
if (modules.basis) {
|
|
846
|
+
return modules.basis;
|
|
847
|
+
}
|
|
848
|
+
loadBasisTranscoderPromise = loadBasisTranscoderPromise || loadBasisTrascoder(options);
|
|
849
|
+
return await loadBasisTranscoderPromise;
|
|
850
|
+
}
|
|
851
|
+
async function loadBasisTrascoder(options) {
|
|
852
|
+
let BASIS = null;
|
|
853
|
+
let wasmBinary = null;
|
|
854
|
+
[BASIS, wasmBinary] = await Promise.all([
|
|
855
|
+
await loadLibrary("basis_transcoder.js", "textures", options),
|
|
856
|
+
await loadLibrary("basis_transcoder.wasm", "textures", options)
|
|
857
|
+
]);
|
|
858
|
+
BASIS = BASIS || globalThis.BASIS;
|
|
859
|
+
return await initializeBasisTrascoderModule(BASIS, wasmBinary);
|
|
860
|
+
}
|
|
861
|
+
function initializeBasisTrascoderModule(BasisModule, wasmBinary) {
|
|
862
|
+
const options = {};
|
|
863
|
+
if (wasmBinary) {
|
|
864
|
+
options.wasmBinary = wasmBinary;
|
|
865
|
+
}
|
|
866
|
+
return new Promise((resolve) => {
|
|
867
|
+
BasisModule(options).then((module) => {
|
|
868
|
+
const { BasisFile, initializeBasis } = module;
|
|
869
|
+
initializeBasis();
|
|
870
|
+
resolve({ BasisFile });
|
|
871
|
+
});
|
|
872
|
+
});
|
|
873
|
+
}
|
|
874
|
+
async function loadBasisEncoderModule(options) {
|
|
875
|
+
const modules = options.modules || {};
|
|
876
|
+
if (modules.basisEncoder) {
|
|
877
|
+
return modules.basisEncoder;
|
|
878
|
+
}
|
|
879
|
+
loadBasisEncoderPromise = loadBasisEncoderPromise || loadBasisEncoder(options);
|
|
880
|
+
return await loadBasisEncoderPromise;
|
|
881
|
+
}
|
|
882
|
+
async function loadBasisEncoder(options) {
|
|
883
|
+
let BASIS_ENCODER = null;
|
|
884
|
+
let wasmBinary = null;
|
|
885
|
+
[BASIS_ENCODER, wasmBinary] = await Promise.all([
|
|
886
|
+
await loadLibrary(BASIS_CDN_ENCODER_JS, "textures", options),
|
|
887
|
+
await loadLibrary(BASIS_CDN_ENCODER_WASM, "textures", options)
|
|
888
|
+
]);
|
|
889
|
+
BASIS_ENCODER = BASIS_ENCODER || globalThis.BASIS;
|
|
890
|
+
return await initializeBasisEncoderModule(BASIS_ENCODER, wasmBinary);
|
|
891
|
+
}
|
|
892
|
+
function initializeBasisEncoderModule(BasisEncoderModule, wasmBinary) {
|
|
893
|
+
const options = {};
|
|
894
|
+
if (wasmBinary) {
|
|
895
|
+
options.wasmBinary = wasmBinary;
|
|
896
|
+
}
|
|
897
|
+
return new Promise((resolve) => {
|
|
898
|
+
BasisEncoderModule(options).then((module) => {
|
|
899
|
+
const { BasisFile, KTX2File, initializeBasis, BasisEncoder } = module;
|
|
900
|
+
initializeBasis();
|
|
901
|
+
resolve({ BasisFile, KTX2File, BasisEncoder });
|
|
902
|
+
});
|
|
903
|
+
});
|
|
904
|
+
}
|
|
905
|
+
var VERSION6, BASIS_CDN_ENCODER_WASM, BASIS_CDN_ENCODER_JS, loadBasisTranscoderPromise, loadBasisEncoderPromise;
|
|
906
|
+
var init_basis_module_loader = __esm({
|
|
907
|
+
"../textures/src/lib/parsers/basis-module-loader.ts"() {
|
|
908
|
+
init_src();
|
|
909
|
+
VERSION6 = typeof __VERSION__ !== "undefined" ? __VERSION__ : "beta";
|
|
910
|
+
BASIS_CDN_ENCODER_WASM = `https://unpkg.com/@loaders.gl/textures@${VERSION6}/dist/libs/basis_encoder.wasm`;
|
|
911
|
+
BASIS_CDN_ENCODER_JS = `https://unpkg.com/@loaders.gl/textures@${VERSION6}/dist/libs/basis_encoder.js`;
|
|
912
|
+
}
|
|
913
|
+
});
|
|
914
|
+
|
|
915
|
+
// ../textures/src/lib/gl-extensions.ts
|
|
916
|
+
var GL_EXTENSIONS_CONSTANTS;
|
|
917
|
+
var init_gl_extensions = __esm({
|
|
918
|
+
"../textures/src/lib/gl-extensions.ts"() {
|
|
919
|
+
GL_EXTENSIONS_CONSTANTS = {
|
|
920
|
+
COMPRESSED_RGB_S3TC_DXT1_EXT: 33776,
|
|
921
|
+
COMPRESSED_RGBA_S3TC_DXT1_EXT: 33777,
|
|
922
|
+
COMPRESSED_RGBA_S3TC_DXT3_EXT: 33778,
|
|
923
|
+
COMPRESSED_RGBA_S3TC_DXT5_EXT: 33779,
|
|
924
|
+
COMPRESSED_R11_EAC: 37488,
|
|
925
|
+
COMPRESSED_SIGNED_R11_EAC: 37489,
|
|
926
|
+
COMPRESSED_RG11_EAC: 37490,
|
|
927
|
+
COMPRESSED_SIGNED_RG11_EAC: 37491,
|
|
928
|
+
COMPRESSED_RGB8_ETC2: 37492,
|
|
929
|
+
COMPRESSED_RGBA8_ETC2_EAC: 37493,
|
|
930
|
+
COMPRESSED_SRGB8_ETC2: 37494,
|
|
931
|
+
COMPRESSED_SRGB8_ALPHA8_ETC2_EAC: 37495,
|
|
932
|
+
COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2: 37496,
|
|
933
|
+
COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2: 37497,
|
|
934
|
+
COMPRESSED_RGB_PVRTC_4BPPV1_IMG: 35840,
|
|
935
|
+
COMPRESSED_RGBA_PVRTC_4BPPV1_IMG: 35842,
|
|
936
|
+
COMPRESSED_RGB_PVRTC_2BPPV1_IMG: 35841,
|
|
937
|
+
COMPRESSED_RGBA_PVRTC_2BPPV1_IMG: 35843,
|
|
938
|
+
COMPRESSED_RGB_ETC1_WEBGL: 36196,
|
|
939
|
+
COMPRESSED_RGB_ATC_WEBGL: 35986,
|
|
940
|
+
COMPRESSED_RGBA_ATC_EXPLICIT_ALPHA_WEBGL: 35987,
|
|
941
|
+
COMPRESSED_RGBA_ATC_INTERPOLATED_ALPHA_WEBGL: 34798,
|
|
942
|
+
COMPRESSED_RGBA_ASTC_4X4_KHR: 37808,
|
|
943
|
+
COMPRESSED_RGBA_ASTC_5X4_KHR: 37809,
|
|
944
|
+
COMPRESSED_RGBA_ASTC_5X5_KHR: 37810,
|
|
945
|
+
COMPRESSED_RGBA_ASTC_6X5_KHR: 37811,
|
|
946
|
+
COMPRESSED_RGBA_ASTC_6X6_KHR: 37812,
|
|
947
|
+
COMPRESSED_RGBA_ASTC_8X5_KHR: 37813,
|
|
948
|
+
COMPRESSED_RGBA_ASTC_8X6_KHR: 37814,
|
|
949
|
+
COMPRESSED_RGBA_ASTC_8X8_KHR: 37815,
|
|
950
|
+
COMPRESSED_RGBA_ASTC_10X5_KHR: 37816,
|
|
951
|
+
COMPRESSED_RGBA_ASTC_10X6_KHR: 37817,
|
|
952
|
+
COMPRESSED_RGBA_ASTC_10X8_KHR: 37818,
|
|
953
|
+
COMPRESSED_RGBA_ASTC_10X10_KHR: 37819,
|
|
954
|
+
COMPRESSED_RGBA_ASTC_12X10_KHR: 37820,
|
|
955
|
+
COMPRESSED_RGBA_ASTC_12X12_KHR: 37821,
|
|
956
|
+
COMPRESSED_SRGB8_ALPHA8_ASTC_4X4_KHR: 37840,
|
|
957
|
+
COMPRESSED_SRGB8_ALPHA8_ASTC_5X4_KHR: 37841,
|
|
958
|
+
COMPRESSED_SRGB8_ALPHA8_ASTC_5X5_KHR: 37842,
|
|
959
|
+
COMPRESSED_SRGB8_ALPHA8_ASTC_6X5_KHR: 37843,
|
|
960
|
+
COMPRESSED_SRGB8_ALPHA8_ASTC_6X6_KHR: 37844,
|
|
961
|
+
COMPRESSED_SRGB8_ALPHA8_ASTC_8X5_KHR: 37845,
|
|
962
|
+
COMPRESSED_SRGB8_ALPHA8_ASTC_8X6_KHR: 37846,
|
|
963
|
+
COMPRESSED_SRGB8_ALPHA8_ASTC_8X8_KHR: 37847,
|
|
964
|
+
COMPRESSED_SRGB8_ALPHA8_ASTC_10X5_KHR: 37848,
|
|
965
|
+
COMPRESSED_SRGB8_ALPHA8_ASTC_10X6_KHR: 37849,
|
|
966
|
+
COMPRESSED_SRGB8_ALPHA8_ASTC_10X8_KHR: 37850,
|
|
967
|
+
COMPRESSED_SRGB8_ALPHA8_ASTC_10X10_KHR: 37851,
|
|
968
|
+
COMPRESSED_SRGB8_ALPHA8_ASTC_12X10_KHR: 37852,
|
|
969
|
+
COMPRESSED_SRGB8_ALPHA8_ASTC_12X12_KHR: 37853,
|
|
970
|
+
COMPRESSED_RED_RGTC1_EXT: 36283,
|
|
971
|
+
COMPRESSED_SIGNED_RED_RGTC1_EXT: 36284,
|
|
972
|
+
COMPRESSED_RED_GREEN_RGTC2_EXT: 36285,
|
|
973
|
+
COMPRESSED_SIGNED_RED_GREEN_RGTC2_EXT: 36286,
|
|
974
|
+
COMPRESSED_SRGB_S3TC_DXT1_EXT: 35916,
|
|
975
|
+
COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT: 35917,
|
|
976
|
+
COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT: 35918,
|
|
977
|
+
COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT: 35919
|
|
978
|
+
};
|
|
979
|
+
}
|
|
980
|
+
});
|
|
981
|
+
|
|
982
|
+
// ../textures/src/lib/utils/texture-formats.ts
|
|
983
|
+
function getSupportedGPUTextureFormats(gl) {
|
|
984
|
+
if (!formats) {
|
|
985
|
+
gl = gl || getWebGLContext() || void 0;
|
|
986
|
+
formats = new Set();
|
|
987
|
+
for (const prefix of BROWSER_PREFIXES) {
|
|
988
|
+
for (const extension in WEBGL_EXTENSIONS) {
|
|
989
|
+
if (gl && gl.getExtension(`${prefix}${extension}`)) {
|
|
990
|
+
const gpuTextureFormat = WEBGL_EXTENSIONS[extension];
|
|
991
|
+
formats.add(gpuTextureFormat);
|
|
992
|
+
}
|
|
993
|
+
}
|
|
994
|
+
}
|
|
995
|
+
}
|
|
996
|
+
return formats;
|
|
997
|
+
}
|
|
998
|
+
function getWebGLContext() {
|
|
999
|
+
try {
|
|
1000
|
+
const canvas = document.createElement("canvas");
|
|
1001
|
+
return canvas.getContext("webgl");
|
|
1002
|
+
} catch (error) {
|
|
1003
|
+
return null;
|
|
1004
|
+
}
|
|
1005
|
+
}
|
|
1006
|
+
var BROWSER_PREFIXES, WEBGL_EXTENSIONS, formats;
|
|
1007
|
+
var init_texture_formats = __esm({
|
|
1008
|
+
"../textures/src/lib/utils/texture-formats.ts"() {
|
|
1009
|
+
BROWSER_PREFIXES = ["", "WEBKIT_", "MOZ_"];
|
|
1010
|
+
WEBGL_EXTENSIONS = {
|
|
1011
|
+
WEBGL_compressed_texture_s3tc: "dxt",
|
|
1012
|
+
WEBGL_compressed_texture_s3tc_srgb: "dxt-srgb",
|
|
1013
|
+
WEBGL_compressed_texture_etc1: "etc1",
|
|
1014
|
+
WEBGL_compressed_texture_etc: "etc2",
|
|
1015
|
+
WEBGL_compressed_texture_pvrtc: "pvrtc",
|
|
1016
|
+
WEBGL_compressed_texture_atc: "atc",
|
|
1017
|
+
WEBGL_compressed_texture_astc: "astc",
|
|
1018
|
+
EXT_texture_compression_rgtc: "rgtc"
|
|
1019
|
+
};
|
|
1020
|
+
formats = null;
|
|
1021
|
+
}
|
|
1022
|
+
});
|
|
1023
|
+
|
|
1024
|
+
// ../../node_modules/ktx-parse/dist/ktx-parse.modern.js
|
|
1025
|
+
var t, n, i, s, a, r, o, l, f;
|
|
1026
|
+
var init_ktx_parse_modern = __esm({
|
|
1027
|
+
"../../node_modules/ktx-parse/dist/ktx-parse.modern.js"() {
|
|
1028
|
+
t = new Uint8Array([0]);
|
|
1029
|
+
!function(t2) {
|
|
1030
|
+
t2[t2.NONE = 0] = "NONE", t2[t2.BASISLZ = 1] = "BASISLZ", t2[t2.ZSTD = 2] = "ZSTD", t2[t2.ZLIB = 3] = "ZLIB";
|
|
1031
|
+
}(n || (n = {})), function(t2) {
|
|
1032
|
+
t2[t2.BASICFORMAT = 0] = "BASICFORMAT";
|
|
1033
|
+
}(i || (i = {})), function(t2) {
|
|
1034
|
+
t2[t2.UNSPECIFIED = 0] = "UNSPECIFIED", t2[t2.ETC1S = 163] = "ETC1S", t2[t2.UASTC = 166] = "UASTC";
|
|
1035
|
+
}(s || (s = {})), function(t2) {
|
|
1036
|
+
t2[t2.UNSPECIFIED = 0] = "UNSPECIFIED", t2[t2.SRGB = 1] = "SRGB";
|
|
1037
|
+
}(a || (a = {})), function(t2) {
|
|
1038
|
+
t2[t2.UNSPECIFIED = 0] = "UNSPECIFIED", t2[t2.LINEAR = 1] = "LINEAR", t2[t2.SRGB = 2] = "SRGB", t2[t2.ITU = 3] = "ITU", t2[t2.NTSC = 4] = "NTSC", t2[t2.SLOG = 5] = "SLOG", t2[t2.SLOG2 = 6] = "SLOG2";
|
|
1039
|
+
}(r || (r = {})), function(t2) {
|
|
1040
|
+
t2[t2.ALPHA_STRAIGHT = 0] = "ALPHA_STRAIGHT", t2[t2.ALPHA_PREMULTIPLIED = 1] = "ALPHA_PREMULTIPLIED";
|
|
1041
|
+
}(o || (o = {})), function(t2) {
|
|
1042
|
+
t2[t2.RGB = 0] = "RGB", t2[t2.RRR = 3] = "RRR", t2[t2.GGG = 4] = "GGG", t2[t2.AAA = 15] = "AAA";
|
|
1043
|
+
}(l || (l = {})), function(t2) {
|
|
1044
|
+
t2[t2.RGB = 0] = "RGB", t2[t2.RGBA = 3] = "RGBA", t2[t2.RRR = 4] = "RRR", t2[t2.RRRG = 5] = "RRRG";
|
|
1045
|
+
}(f || (f = {}));
|
|
1046
|
+
}
|
|
1047
|
+
});
|
|
1048
|
+
|
|
1049
|
+
// ../textures/src/lib/parsers/parse-ktx.ts
|
|
1050
|
+
function isKTX(data) {
|
|
1051
|
+
const id = new Uint8Array(data);
|
|
1052
|
+
const notKTX = id.byteLength < KTX2_ID.length || id[0] !== KTX2_ID[0] || id[1] !== KTX2_ID[1] || id[2] !== KTX2_ID[2] || id[3] !== KTX2_ID[3] || id[4] !== KTX2_ID[4] || id[5] !== KTX2_ID[5] || id[6] !== KTX2_ID[6] || id[7] !== KTX2_ID[7] || id[8] !== KTX2_ID[8] || id[9] !== KTX2_ID[9] || id[10] !== KTX2_ID[10] || id[11] !== KTX2_ID[11];
|
|
1053
|
+
return !notKTX;
|
|
1054
|
+
}
|
|
1055
|
+
var KTX2_ID;
|
|
1056
|
+
var init_parse_ktx = __esm({
|
|
1057
|
+
"../textures/src/lib/parsers/parse-ktx.ts"() {
|
|
1058
|
+
init_ktx_parse_modern();
|
|
1059
|
+
KTX2_ID = [
|
|
1060
|
+
171,
|
|
1061
|
+
75,
|
|
1062
|
+
84,
|
|
1063
|
+
88,
|
|
1064
|
+
32,
|
|
1065
|
+
50,
|
|
1066
|
+
48,
|
|
1067
|
+
187,
|
|
1068
|
+
13,
|
|
1069
|
+
10,
|
|
1070
|
+
26,
|
|
1071
|
+
10
|
|
1072
|
+
];
|
|
1073
|
+
}
|
|
1074
|
+
});
|
|
1075
|
+
|
|
1076
|
+
// ../textures/src/lib/parsers/parse-basis.ts
|
|
1077
|
+
async function parseBasis(data, options) {
|
|
1078
|
+
if (options.basis.containerFormat === "auto") {
|
|
1079
|
+
if (isKTX(data)) {
|
|
1080
|
+
const fileConstructors = await loadBasisEncoderModule(options);
|
|
1081
|
+
return parseKTX2File(fileConstructors.KTX2File, data, options);
|
|
1082
|
+
}
|
|
1083
|
+
const { BasisFile } = await loadBasisTrascoderModule(options);
|
|
1084
|
+
return parseBasisFile(BasisFile, data, options);
|
|
1085
|
+
}
|
|
1086
|
+
switch (options.basis.module) {
|
|
1087
|
+
case "encoder":
|
|
1088
|
+
const fileConstructors = await loadBasisEncoderModule(options);
|
|
1089
|
+
switch (options.basis.containerFormat) {
|
|
1090
|
+
case "ktx2":
|
|
1091
|
+
return parseKTX2File(fileConstructors.KTX2File, data, options);
|
|
1092
|
+
case "basis":
|
|
1093
|
+
default:
|
|
1094
|
+
return parseBasisFile(fileConstructors.BasisFile, data, options);
|
|
1095
|
+
}
|
|
1096
|
+
case "transcoder":
|
|
1097
|
+
default:
|
|
1098
|
+
const { BasisFile } = await loadBasisTrascoderModule(options);
|
|
1099
|
+
return parseBasisFile(BasisFile, data, options);
|
|
1100
|
+
}
|
|
1101
|
+
}
|
|
1102
|
+
function parseBasisFile(BasisFile, data, options) {
|
|
1103
|
+
const basisFile = new BasisFile(new Uint8Array(data));
|
|
1104
|
+
try {
|
|
1105
|
+
if (!basisFile.startTranscoding()) {
|
|
1106
|
+
throw new Error("Failed to start basis transcoding");
|
|
1107
|
+
}
|
|
1108
|
+
const imageCount = basisFile.getNumImages();
|
|
1109
|
+
const images = [];
|
|
1110
|
+
for (let imageIndex = 0; imageIndex < imageCount; imageIndex++) {
|
|
1111
|
+
const levelsCount = basisFile.getNumLevels(imageIndex);
|
|
1112
|
+
const levels = [];
|
|
1113
|
+
for (let levelIndex = 0; levelIndex < levelsCount; levelIndex++) {
|
|
1114
|
+
levels.push(transcodeImage(basisFile, imageIndex, levelIndex, options));
|
|
1115
|
+
}
|
|
1116
|
+
images.push(levels);
|
|
1117
|
+
}
|
|
1118
|
+
return images;
|
|
1119
|
+
} finally {
|
|
1120
|
+
basisFile.close();
|
|
1121
|
+
basisFile.delete();
|
|
1122
|
+
}
|
|
1123
|
+
}
|
|
1124
|
+
function transcodeImage(basisFile, imageIndex, levelIndex, options) {
|
|
1125
|
+
const width = basisFile.getImageWidth(imageIndex, levelIndex);
|
|
1126
|
+
const height = basisFile.getImageHeight(imageIndex, levelIndex);
|
|
1127
|
+
const hasAlpha = basisFile.getHasAlpha();
|
|
1128
|
+
const { compressed, format, basisFormat } = getBasisOptions(options, hasAlpha);
|
|
1129
|
+
const decodedSize = basisFile.getImageTranscodedSizeInBytes(imageIndex, levelIndex, basisFormat);
|
|
1130
|
+
const decodedData = new Uint8Array(decodedSize);
|
|
1131
|
+
if (!basisFile.transcodeImage(decodedData, imageIndex, levelIndex, basisFormat, 0, 0)) {
|
|
1132
|
+
throw new Error("failed to start Basis transcoding");
|
|
1133
|
+
}
|
|
1134
|
+
return {
|
|
1135
|
+
width,
|
|
1136
|
+
height,
|
|
1137
|
+
data: decodedData,
|
|
1138
|
+
compressed,
|
|
1139
|
+
format,
|
|
1140
|
+
hasAlpha
|
|
1141
|
+
};
|
|
1142
|
+
}
|
|
1143
|
+
function parseKTX2File(KTX2File, data, options) {
|
|
1144
|
+
const ktx2File = new KTX2File(new Uint8Array(data));
|
|
1145
|
+
try {
|
|
1146
|
+
if (!ktx2File.startTranscoding()) {
|
|
1147
|
+
throw new Error("failed to start KTX2 transcoding");
|
|
1148
|
+
}
|
|
1149
|
+
const levelsCount = ktx2File.getLevels();
|
|
1150
|
+
const levels = [];
|
|
1151
|
+
for (let levelIndex = 0; levelIndex < levelsCount; levelIndex++) {
|
|
1152
|
+
levels.push(transcodeKTX2Image(ktx2File, levelIndex, options));
|
|
1153
|
+
break;
|
|
1154
|
+
}
|
|
1155
|
+
return [levels];
|
|
1156
|
+
} finally {
|
|
1157
|
+
ktx2File.close();
|
|
1158
|
+
ktx2File.delete();
|
|
1159
|
+
}
|
|
1160
|
+
}
|
|
1161
|
+
function transcodeKTX2Image(ktx2File, levelIndex, options) {
|
|
1162
|
+
const { alphaFlag, height, width } = ktx2File.getImageLevelInfo(levelIndex, 0, 0);
|
|
1163
|
+
const { compressed, format, basisFormat } = getBasisOptions(options, alphaFlag);
|
|
1164
|
+
const decodedSize = ktx2File.getImageTranscodedSizeInBytes(levelIndex, 0, 0, basisFormat);
|
|
1165
|
+
const decodedData = new Uint8Array(decodedSize);
|
|
1166
|
+
if (!ktx2File.transcodeImage(decodedData, levelIndex, 0, 0, basisFormat, 0, -1, -1)) {
|
|
1167
|
+
throw new Error("Failed to transcode KTX2 image");
|
|
1168
|
+
}
|
|
1169
|
+
return {
|
|
1170
|
+
width,
|
|
1171
|
+
height,
|
|
1172
|
+
data: decodedData,
|
|
1173
|
+
compressed,
|
|
1174
|
+
levelSize: decodedSize,
|
|
1175
|
+
hasAlpha: alphaFlag,
|
|
1176
|
+
format
|
|
1177
|
+
};
|
|
1178
|
+
}
|
|
1179
|
+
function getBasisOptions(options, hasAlpha) {
|
|
1180
|
+
let format = options && options.basis && options.basis.format;
|
|
1181
|
+
if (format === "auto") {
|
|
1182
|
+
format = selectSupportedBasisFormat();
|
|
1183
|
+
}
|
|
1184
|
+
if (typeof format === "object") {
|
|
1185
|
+
format = hasAlpha ? format.alpha : format.noAlpha;
|
|
1270
1186
|
}
|
|
1187
|
+
format = format.toLowerCase();
|
|
1188
|
+
return OutputFormat[format];
|
|
1271
1189
|
}
|
|
1272
|
-
function
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1190
|
+
function selectSupportedBasisFormat() {
|
|
1191
|
+
const supportedFormats = getSupportedGPUTextureFormats();
|
|
1192
|
+
if (supportedFormats.has("astc")) {
|
|
1193
|
+
return "astc-4x4";
|
|
1194
|
+
} else if (supportedFormats.has("dxt")) {
|
|
1195
|
+
return {
|
|
1196
|
+
alpha: "bc3",
|
|
1197
|
+
noAlpha: "bc1"
|
|
1198
|
+
};
|
|
1199
|
+
} else if (supportedFormats.has("pvrtc")) {
|
|
1200
|
+
return {
|
|
1201
|
+
alpha: "pvrtc1-4-rgba",
|
|
1202
|
+
noAlpha: "pvrtc1-4-rgb"
|
|
1203
|
+
};
|
|
1204
|
+
} else if (supportedFormats.has("etc1")) {
|
|
1205
|
+
return "etc1";
|
|
1206
|
+
} else if (supportedFormats.has("etc2")) {
|
|
1207
|
+
return "etc2";
|
|
1279
1208
|
}
|
|
1209
|
+
return "rgb565";
|
|
1280
1210
|
}
|
|
1281
|
-
var
|
|
1282
|
-
var
|
|
1283
|
-
"../
|
|
1284
|
-
|
|
1285
|
-
|
|
1211
|
+
var OutputFormat;
|
|
1212
|
+
var init_parse_basis = __esm({
|
|
1213
|
+
"../textures/src/lib/parsers/parse-basis.ts"() {
|
|
1214
|
+
init_basis_module_loader();
|
|
1215
|
+
init_gl_extensions();
|
|
1216
|
+
init_texture_formats();
|
|
1217
|
+
init_parse_ktx();
|
|
1218
|
+
OutputFormat = {
|
|
1219
|
+
etc1: {
|
|
1220
|
+
basisFormat: 0,
|
|
1221
|
+
compressed: true,
|
|
1222
|
+
format: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGB_ETC1_WEBGL
|
|
1223
|
+
},
|
|
1224
|
+
etc2: { basisFormat: 1, compressed: true },
|
|
1225
|
+
bc1: {
|
|
1226
|
+
basisFormat: 2,
|
|
1227
|
+
compressed: true,
|
|
1228
|
+
format: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGB_S3TC_DXT1_EXT
|
|
1229
|
+
},
|
|
1230
|
+
bc3: {
|
|
1231
|
+
basisFormat: 3,
|
|
1232
|
+
compressed: true,
|
|
1233
|
+
format: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_S3TC_DXT5_EXT
|
|
1234
|
+
},
|
|
1235
|
+
bc4: { basisFormat: 4, compressed: true },
|
|
1236
|
+
bc5: { basisFormat: 5, compressed: true },
|
|
1237
|
+
"bc7-m6-opaque-only": { basisFormat: 6, compressed: true },
|
|
1238
|
+
"bc7-m5": { basisFormat: 7, compressed: true },
|
|
1239
|
+
"pvrtc1-4-rgb": {
|
|
1240
|
+
basisFormat: 8,
|
|
1241
|
+
compressed: true,
|
|
1242
|
+
format: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGB_PVRTC_4BPPV1_IMG
|
|
1243
|
+
},
|
|
1244
|
+
"pvrtc1-4-rgba": {
|
|
1245
|
+
basisFormat: 9,
|
|
1246
|
+
compressed: true,
|
|
1247
|
+
format: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG
|
|
1248
|
+
},
|
|
1249
|
+
"astc-4x4": {
|
|
1250
|
+
basisFormat: 10,
|
|
1251
|
+
compressed: true,
|
|
1252
|
+
format: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_4X4_KHR
|
|
1253
|
+
},
|
|
1254
|
+
"atc-rgb": { basisFormat: 11, compressed: true },
|
|
1255
|
+
"atc-rgba-interpolated-alpha": { basisFormat: 12, compressed: true },
|
|
1256
|
+
rgba32: { basisFormat: 13, compressed: false },
|
|
1257
|
+
rgb565: { basisFormat: 14, compressed: false },
|
|
1258
|
+
bgr565: { basisFormat: 15, compressed: false },
|
|
1259
|
+
rgba4444: { basisFormat: 16, compressed: false }
|
|
1260
|
+
};
|
|
1286
1261
|
}
|
|
1287
1262
|
});
|
|
1288
1263
|
|
|
1289
|
-
// ../
|
|
1290
|
-
var
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1264
|
+
// ../textures/src/basis-loader.ts
|
|
1265
|
+
var BasisWorkerLoader, BasisLoader;
|
|
1266
|
+
var init_basis_loader = __esm({
|
|
1267
|
+
"../textures/src/basis-loader.ts"() {
|
|
1268
|
+
init_version4();
|
|
1269
|
+
init_parse_basis();
|
|
1270
|
+
BasisWorkerLoader = {
|
|
1271
|
+
name: "Basis",
|
|
1272
|
+
id: "basis",
|
|
1273
|
+
module: "textures",
|
|
1274
|
+
version: VERSION5,
|
|
1275
|
+
worker: true,
|
|
1276
|
+
extensions: ["basis", "ktx2"],
|
|
1277
|
+
mimeTypes: ["application/octet-stream", "image/ktx2"],
|
|
1278
|
+
tests: ["sB"],
|
|
1279
|
+
binary: true,
|
|
1280
|
+
options: {
|
|
1281
|
+
basis: {
|
|
1282
|
+
format: "auto",
|
|
1283
|
+
libraryPath: "libs/",
|
|
1284
|
+
containerFormat: "auto",
|
|
1285
|
+
module: "transcoder"
|
|
1286
|
+
}
|
|
1287
|
+
}
|
|
1288
|
+
};
|
|
1289
|
+
BasisLoader = {
|
|
1290
|
+
...BasisWorkerLoader,
|
|
1291
|
+
parse: parseBasis
|
|
1292
|
+
};
|
|
1295
1293
|
}
|
|
1296
1294
|
});
|
|
1297
1295
|
|
|
@@ -1314,6 +1312,119 @@
|
|
|
1314
1312
|
}
|
|
1315
1313
|
});
|
|
1316
1314
|
|
|
1315
|
+
// src/lib/parsers/parse-glb.ts
|
|
1316
|
+
function getMagicString2(dataView, byteOffset = 0) {
|
|
1317
|
+
return `${String.fromCharCode(dataView.getUint8(byteOffset + 0))}${String.fromCharCode(dataView.getUint8(byteOffset + 1))}${String.fromCharCode(dataView.getUint8(byteOffset + 2))}${String.fromCharCode(dataView.getUint8(byteOffset + 3))}`;
|
|
1318
|
+
}
|
|
1319
|
+
function isGLB(arrayBuffer, byteOffset = 0, options = {}) {
|
|
1320
|
+
const dataView = new DataView(arrayBuffer);
|
|
1321
|
+
const { magic = MAGIC_glTF } = options;
|
|
1322
|
+
const magic1 = dataView.getUint32(byteOffset, false);
|
|
1323
|
+
return magic1 === magic || magic1 === MAGIC_glTF;
|
|
1324
|
+
}
|
|
1325
|
+
function parseGLBSync(glb, arrayBuffer, byteOffset = 0, options = {}) {
|
|
1326
|
+
const dataView = new DataView(arrayBuffer);
|
|
1327
|
+
const type = getMagicString2(dataView, byteOffset + 0);
|
|
1328
|
+
const version = dataView.getUint32(byteOffset + 4, LITTLE_ENDIAN2);
|
|
1329
|
+
const byteLength = dataView.getUint32(byteOffset + 8, LITTLE_ENDIAN2);
|
|
1330
|
+
Object.assign(glb, {
|
|
1331
|
+
header: {
|
|
1332
|
+
byteOffset,
|
|
1333
|
+
byteLength,
|
|
1334
|
+
hasBinChunk: false
|
|
1335
|
+
},
|
|
1336
|
+
type,
|
|
1337
|
+
version,
|
|
1338
|
+
json: {},
|
|
1339
|
+
binChunks: []
|
|
1340
|
+
});
|
|
1341
|
+
byteOffset += GLB_FILE_HEADER_SIZE;
|
|
1342
|
+
switch (glb.version) {
|
|
1343
|
+
case 1:
|
|
1344
|
+
return parseGLBV1(glb, dataView, byteOffset);
|
|
1345
|
+
case 2:
|
|
1346
|
+
return parseGLBV2(glb, dataView, byteOffset, options = {});
|
|
1347
|
+
default:
|
|
1348
|
+
throw new Error(`Invalid GLB version ${glb.version}. Only supports version 1 and 2.`);
|
|
1349
|
+
}
|
|
1350
|
+
}
|
|
1351
|
+
function parseGLBV1(glb, dataView, byteOffset) {
|
|
1352
|
+
assert(glb.header.byteLength > GLB_FILE_HEADER_SIZE + GLB_CHUNK_HEADER_SIZE);
|
|
1353
|
+
const contentLength = dataView.getUint32(byteOffset + 0, LITTLE_ENDIAN2);
|
|
1354
|
+
const contentFormat = dataView.getUint32(byteOffset + 4, LITTLE_ENDIAN2);
|
|
1355
|
+
byteOffset += GLB_CHUNK_HEADER_SIZE;
|
|
1356
|
+
assert(contentFormat === GLB_V1_CONTENT_FORMAT_JSON);
|
|
1357
|
+
parseJSONChunk(glb, dataView, byteOffset, contentLength);
|
|
1358
|
+
byteOffset += contentLength;
|
|
1359
|
+
byteOffset += parseBINChunk(glb, dataView, byteOffset, glb.header.byteLength);
|
|
1360
|
+
return byteOffset;
|
|
1361
|
+
}
|
|
1362
|
+
function parseGLBV2(glb, dataView, byteOffset, options) {
|
|
1363
|
+
assert(glb.header.byteLength > GLB_FILE_HEADER_SIZE + GLB_CHUNK_HEADER_SIZE);
|
|
1364
|
+
parseGLBChunksSync(glb, dataView, byteOffset, options);
|
|
1365
|
+
return byteOffset + glb.header.byteLength;
|
|
1366
|
+
}
|
|
1367
|
+
function parseGLBChunksSync(glb, dataView, byteOffset, options) {
|
|
1368
|
+
while (byteOffset + 8 <= glb.header.byteLength) {
|
|
1369
|
+
const chunkLength = dataView.getUint32(byteOffset + 0, LITTLE_ENDIAN2);
|
|
1370
|
+
const chunkFormat = dataView.getUint32(byteOffset + 4, LITTLE_ENDIAN2);
|
|
1371
|
+
byteOffset += GLB_CHUNK_HEADER_SIZE;
|
|
1372
|
+
switch (chunkFormat) {
|
|
1373
|
+
case GLB_CHUNK_TYPE_JSON:
|
|
1374
|
+
parseJSONChunk(glb, dataView, byteOffset, chunkLength);
|
|
1375
|
+
break;
|
|
1376
|
+
case GLB_CHUNK_TYPE_BIN:
|
|
1377
|
+
parseBINChunk(glb, dataView, byteOffset, chunkLength);
|
|
1378
|
+
break;
|
|
1379
|
+
case GLB_CHUNK_TYPE_JSON_XVIZ_DEPRECATED:
|
|
1380
|
+
if (!options.strict) {
|
|
1381
|
+
parseJSONChunk(glb, dataView, byteOffset, chunkLength);
|
|
1382
|
+
}
|
|
1383
|
+
break;
|
|
1384
|
+
case GLB_CHUNK_TYPE_BIX_XVIZ_DEPRECATED:
|
|
1385
|
+
if (!options.strict) {
|
|
1386
|
+
parseBINChunk(glb, dataView, byteOffset, chunkLength);
|
|
1387
|
+
}
|
|
1388
|
+
break;
|
|
1389
|
+
default:
|
|
1390
|
+
break;
|
|
1391
|
+
}
|
|
1392
|
+
byteOffset += padToNBytes(chunkLength, 4);
|
|
1393
|
+
}
|
|
1394
|
+
return byteOffset;
|
|
1395
|
+
}
|
|
1396
|
+
function parseJSONChunk(glb, dataView, byteOffset, chunkLength) {
|
|
1397
|
+
const jsonChunk = new Uint8Array(dataView.buffer, byteOffset, chunkLength);
|
|
1398
|
+
const textDecoder = new TextDecoder("utf8");
|
|
1399
|
+
const jsonText = textDecoder.decode(jsonChunk);
|
|
1400
|
+
glb.json = JSON.parse(jsonText);
|
|
1401
|
+
return padToNBytes(chunkLength, 4);
|
|
1402
|
+
}
|
|
1403
|
+
function parseBINChunk(glb, dataView, byteOffset, chunkLength) {
|
|
1404
|
+
glb.header.hasBinChunk = true;
|
|
1405
|
+
glb.binChunks.push({
|
|
1406
|
+
byteOffset,
|
|
1407
|
+
byteLength: chunkLength,
|
|
1408
|
+
arrayBuffer: dataView.buffer
|
|
1409
|
+
});
|
|
1410
|
+
return padToNBytes(chunkLength, 4);
|
|
1411
|
+
}
|
|
1412
|
+
var LITTLE_ENDIAN2, MAGIC_glTF, GLB_FILE_HEADER_SIZE, GLB_CHUNK_HEADER_SIZE, GLB_CHUNK_TYPE_JSON, GLB_CHUNK_TYPE_BIN, GLB_V1_CONTENT_FORMAT_JSON, GLB_CHUNK_TYPE_JSON_XVIZ_DEPRECATED, GLB_CHUNK_TYPE_BIX_XVIZ_DEPRECATED;
|
|
1413
|
+
var init_parse_glb = __esm({
|
|
1414
|
+
"src/lib/parsers/parse-glb.ts"() {
|
|
1415
|
+
init_src2();
|
|
1416
|
+
LITTLE_ENDIAN2 = true;
|
|
1417
|
+
MAGIC_glTF = 1735152710;
|
|
1418
|
+
GLB_FILE_HEADER_SIZE = 12;
|
|
1419
|
+
GLB_CHUNK_HEADER_SIZE = 8;
|
|
1420
|
+
GLB_CHUNK_TYPE_JSON = 1313821514;
|
|
1421
|
+
GLB_CHUNK_TYPE_BIN = 5130562;
|
|
1422
|
+
GLB_V1_CONTENT_FORMAT_JSON = 0;
|
|
1423
|
+
GLB_CHUNK_TYPE_JSON_XVIZ_DEPRECATED = 0;
|
|
1424
|
+
GLB_CHUNK_TYPE_BIX_XVIZ_DEPRECATED = 1;
|
|
1425
|
+
}
|
|
1426
|
+
});
|
|
1427
|
+
|
|
1317
1428
|
// src/lib/gltf-utils/resolve-url.ts
|
|
1318
1429
|
function resolveUrl(url, options) {
|
|
1319
1430
|
const absolute = url.startsWith("data:") || url.startsWith("http:") || url.startsWith("https:");
|
|
@@ -1368,10 +1479,24 @@
|
|
|
1368
1479
|
assert3(byteLength >= 0 && byteLength <= bufferView.byteLength);
|
|
1369
1480
|
return { ArrayType, length, byteLength };
|
|
1370
1481
|
}
|
|
1371
|
-
|
|
1482
|
+
function getMemoryUsageGLTF(gltf) {
|
|
1483
|
+
let { images, bufferViews } = gltf;
|
|
1484
|
+
images = images || [];
|
|
1485
|
+
bufferViews = bufferViews || [];
|
|
1486
|
+
const imageBufferViews = images.map((i2) => i2.bufferView);
|
|
1487
|
+
bufferViews = bufferViews.filter((view) => !imageBufferViews.includes(view));
|
|
1488
|
+
const bufferMemory = bufferViews.reduce((acc, view) => acc + view.byteLength, 0);
|
|
1489
|
+
const pixelCount = images.reduce((acc, image) => {
|
|
1490
|
+
const { width, height } = image.image;
|
|
1491
|
+
return acc + width * height;
|
|
1492
|
+
}, 0);
|
|
1493
|
+
return bufferMemory + Math.ceil(4 * pixelCount * MIPMAP_FACTOR);
|
|
1494
|
+
}
|
|
1495
|
+
var MIPMAP_FACTOR, TYPES, ARRAY_CONSTRUCTOR_TO_WEBGL_CONSTANT, ARRAY_TO_COMPONENT_TYPE, ATTRIBUTE_TYPE_TO_COMPONENTS, ATTRIBUTE_COMPONENT_TYPE_TO_BYTE_SIZE, ATTRIBUTE_COMPONENT_TYPE_TO_ARRAY;
|
|
1372
1496
|
var init_gltf_utils = __esm({
|
|
1373
1497
|
"src/lib/gltf-utils/gltf-utils.ts"() {
|
|
1374
1498
|
init_assert3();
|
|
1499
|
+
MIPMAP_FACTOR = 1.33;
|
|
1375
1500
|
TYPES = ["SCALAR", "VEC2", "VEC3", "VEC4"];
|
|
1376
1501
|
ARRAY_CONSTRUCTOR_TO_WEBGL_CONSTANT = [
|
|
1377
1502
|
[Int8Array, 5120],
|
|
@@ -1412,25 +1537,30 @@
|
|
|
1412
1537
|
});
|
|
1413
1538
|
|
|
1414
1539
|
// src/lib/api/gltf-scenegraph.ts
|
|
1415
|
-
|
|
1540
|
+
function makeDefaultGLTFJson() {
|
|
1541
|
+
return {
|
|
1542
|
+
asset: {
|
|
1543
|
+
version: "2.0",
|
|
1544
|
+
generator: "loaders.gl"
|
|
1545
|
+
},
|
|
1546
|
+
buffers: [],
|
|
1547
|
+
extensions: {},
|
|
1548
|
+
extensionsRequired: [],
|
|
1549
|
+
extensionsUsed: []
|
|
1550
|
+
};
|
|
1551
|
+
}
|
|
1552
|
+
var GLTFScenegraph;
|
|
1416
1553
|
var init_gltf_scenegraph = __esm({
|
|
1417
1554
|
"src/lib/api/gltf-scenegraph.ts"() {
|
|
1418
1555
|
init_src3();
|
|
1419
1556
|
init_src2();
|
|
1420
1557
|
init_assert3();
|
|
1421
1558
|
init_gltf_utils();
|
|
1422
|
-
DEFAULT_GLTF_JSON = {
|
|
1423
|
-
asset: {
|
|
1424
|
-
version: "2.0",
|
|
1425
|
-
generator: "loaders.gl"
|
|
1426
|
-
},
|
|
1427
|
-
buffers: []
|
|
1428
|
-
};
|
|
1429
1559
|
GLTFScenegraph = class {
|
|
1430
1560
|
constructor(gltf) {
|
|
1431
|
-
this.gltf =
|
|
1432
|
-
json:
|
|
1433
|
-
buffers: []
|
|
1561
|
+
this.gltf = {
|
|
1562
|
+
json: gltf?.json || makeDefaultGLTFJson(),
|
|
1563
|
+
buffers: gltf?.buffers || []
|
|
1434
1564
|
};
|
|
1435
1565
|
this.sourceBuffers = [];
|
|
1436
1566
|
this.byteLength = 0;
|
|
@@ -1450,10 +1580,15 @@
|
|
|
1450
1580
|
const extras = this.json.extras || {};
|
|
1451
1581
|
return extras[key];
|
|
1452
1582
|
}
|
|
1583
|
+
hasExtension(extensionName) {
|
|
1584
|
+
const isUsedExtension = this.getUsedExtensions().find((name10) => name10 === extensionName);
|
|
1585
|
+
const isRequiredExtension = this.getRequiredExtensions().find((name10) => name10 === extensionName);
|
|
1586
|
+
return typeof isUsedExtension === "string" || typeof isRequiredExtension === "string";
|
|
1587
|
+
}
|
|
1453
1588
|
getExtension(extensionName) {
|
|
1454
1589
|
const isExtension = this.getUsedExtensions().find((name10) => name10 === extensionName);
|
|
1455
1590
|
const extensions = this.json.extensions || {};
|
|
1456
|
-
return isExtension ? extensions[extensionName]
|
|
1591
|
+
return isExtension ? extensions[extensionName] : null;
|
|
1457
1592
|
}
|
|
1458
1593
|
getRequiredExtension(extensionName) {
|
|
1459
1594
|
const isRequired = this.getRequiredExtensions().find((name10) => name10 === extensionName);
|
|
@@ -1560,10 +1695,15 @@
|
|
|
1560
1695
|
extensions[extensionName] = data;
|
|
1561
1696
|
}
|
|
1562
1697
|
removeObjectExtension(object, extensionName) {
|
|
1563
|
-
const extensions = object
|
|
1564
|
-
|
|
1698
|
+
const extensions = object?.extensions || {};
|
|
1699
|
+
if (extensions[extensionName]) {
|
|
1700
|
+
this.json.extensionsRemoved = this.json.extensionsRemoved || [];
|
|
1701
|
+
const extensionsRemoved = this.json.extensionsRemoved;
|
|
1702
|
+
if (!extensionsRemoved.includes(extensionName)) {
|
|
1703
|
+
extensionsRemoved.push(extensionName);
|
|
1704
|
+
}
|
|
1705
|
+
}
|
|
1565
1706
|
delete extensions[extensionName];
|
|
1566
|
-
return extension;
|
|
1567
1707
|
}
|
|
1568
1708
|
addExtension(extensionName, extensionData = {}) {
|
|
1569
1709
|
assert3(extensionData);
|
|
@@ -1592,24 +1732,21 @@
|
|
|
1592
1732
|
}
|
|
1593
1733
|
}
|
|
1594
1734
|
removeExtension(extensionName) {
|
|
1595
|
-
if (
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
if (this.json.extensionsUsed) {
|
|
1602
|
-
this._removeStringFromArray(this.json.extensionsUsed, extensionName);
|
|
1735
|
+
if (this.json.extensions?.[extensionName]) {
|
|
1736
|
+
this.json.extensionsRemoved = this.json.extensionsRemoved || [];
|
|
1737
|
+
const extensionsRemoved = this.json.extensionsRemoved;
|
|
1738
|
+
if (!extensionsRemoved.includes(extensionName)) {
|
|
1739
|
+
extensionsRemoved.push(extensionName);
|
|
1740
|
+
}
|
|
1603
1741
|
}
|
|
1604
1742
|
if (this.json.extensions) {
|
|
1605
1743
|
delete this.json.extensions[extensionName];
|
|
1606
1744
|
}
|
|
1607
|
-
if (
|
|
1608
|
-
this.json.
|
|
1745
|
+
if (this.json.extensionsRequired) {
|
|
1746
|
+
this._removeStringFromArray(this.json.extensionsRequired, extensionName);
|
|
1609
1747
|
}
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
extensionsRemoved.push(extensionName);
|
|
1748
|
+
if (this.json.extensionsUsed) {
|
|
1749
|
+
this._removeStringFromArray(this.json.extensionsUsed, extensionName);
|
|
1613
1750
|
}
|
|
1614
1751
|
}
|
|
1615
1752
|
setDefaultScene(sceneIndex) {
|
|
@@ -2045,9 +2182,8 @@
|
|
|
2045
2182
|
const source = new Uint8Array(buffer.arrayBuffer, buffer.byteOffset + byteOffset, byteLength);
|
|
2046
2183
|
const result = new Uint8Array(scenegraph.gltf.buffers[bufferView.buffer].arrayBuffer, bufferView.byteOffset, bufferView.byteLength);
|
|
2047
2184
|
await meshoptDecodeGltfBuffer(result, count, byteStride, source, mode, filter);
|
|
2048
|
-
|
|
2185
|
+
scenegraph.removeObjectExtension(bufferView, EXT_MESHOPT_COMPRESSION);
|
|
2049
2186
|
}
|
|
2050
|
-
return null;
|
|
2051
2187
|
}
|
|
2052
2188
|
var EXT_MESHOPT_COMPRESSION, name;
|
|
2053
2189
|
var init_EXT_meshopt_compression = __esm({
|
|
@@ -2106,8 +2242,8 @@
|
|
|
2106
2242
|
const extension = scene.getObjectExtension(texture, KHR_TEXTURE_BASISU);
|
|
2107
2243
|
if (extension) {
|
|
2108
2244
|
texture.source = extension.source;
|
|
2245
|
+
scene.removeObjectExtension(texture, KHR_TEXTURE_BASISU);
|
|
2109
2246
|
}
|
|
2110
|
-
scene.removeObjectExtension(texture, KHR_TEXTURE_BASISU);
|
|
2111
2247
|
}
|
|
2112
2248
|
scene.removeExtension(KHR_TEXTURE_BASISU);
|
|
2113
2249
|
}
|
|
@@ -2132,7 +2268,6 @@
|
|
|
2132
2268
|
var DEFAULT_DRACO_OPTIONS, DracoLoader;
|
|
2133
2269
|
var init_draco_loader = __esm({
|
|
2134
2270
|
"../draco/src/draco-loader.ts"() {
|
|
2135
|
-
init_src();
|
|
2136
2271
|
init_version5();
|
|
2137
2272
|
DEFAULT_DRACO_OPTIONS = {
|
|
2138
2273
|
draco: {
|
|
@@ -2144,7 +2279,7 @@
|
|
|
2144
2279
|
};
|
|
2145
2280
|
DracoLoader = {
|
|
2146
2281
|
name: "Draco",
|
|
2147
|
-
id:
|
|
2282
|
+
id: "draco",
|
|
2148
2283
|
module: "draco",
|
|
2149
2284
|
version: VERSION7,
|
|
2150
2285
|
worker: true,
|
|
@@ -2843,6 +2978,7 @@
|
|
|
2843
2978
|
if (decodedData.indices) {
|
|
2844
2979
|
primitive.indices = getGLTFAccessor(decodedData.indices);
|
|
2845
2980
|
}
|
|
2981
|
+
scenegraph.removeObjectExtension(primitive, KHR_DRACO_MESH_COMPRESSION);
|
|
2846
2982
|
checkPrimitive(primitive);
|
|
2847
2983
|
}
|
|
2848
2984
|
function compressMesh(attributes, indices, mode = 4, options, context) {
|
|
@@ -4082,8 +4218,8 @@
|
|
|
4082
4218
|
});
|
|
4083
4219
|
async function decode4(gltfData, options) {
|
|
4084
4220
|
const gltfScenegraph = new GLTFScenegraph(gltfData);
|
|
4085
|
-
const
|
|
4086
|
-
if (!
|
|
4221
|
+
const hasExtension = gltfScenegraph.hasExtension(EXT_MESHOPT_TRANSFORM);
|
|
4222
|
+
if (!hasExtension) {
|
|
4087
4223
|
return;
|
|
4088
4224
|
}
|
|
4089
4225
|
const materials = gltfData.json.materials || [];
|
|
@@ -4217,10 +4353,10 @@
|
|
|
4217
4353
|
}
|
|
4218
4354
|
function makeTransformationMatrix(extensionData) {
|
|
4219
4355
|
const { offset = [0, 0], rotation = 0, scale: scale2 = [1, 1] } = extensionData;
|
|
4220
|
-
const
|
|
4221
|
-
const
|
|
4356
|
+
const translationMatrix = new Matrix3().set(1, 0, 0, 0, 1, 0, offset[0], offset[1], 1);
|
|
4357
|
+
const rotationMatrix = scratchRotationMatrix.set(Math.cos(rotation), Math.sin(rotation), 0, -Math.sin(rotation), Math.cos(rotation), 0, 0, 0, 1);
|
|
4222
4358
|
const scaleMatrix = scratchScaleMatrix.set(scale2[0], 0, 0, 0, scale2[1], 0, 0, 0, 1);
|
|
4223
|
-
return
|
|
4359
|
+
return translationMatrix.multiplyRight(rotationMatrix).multiplyRight(scaleMatrix);
|
|
4224
4360
|
}
|
|
4225
4361
|
var EXT_MESHOPT_TRANSFORM, name5, scratchVector, scratchRotationMatrix, scratchScaleMatrix;
|
|
4226
4362
|
var init_KHR_texture_transform = __esm({
|
|
@@ -4626,561 +4762,126 @@
|
|
|
4626
4762
|
this._updateObjects(json);
|
|
4627
4763
|
this._updateMaterial(json);
|
|
4628
4764
|
}
|
|
4629
|
-
_addAsset(json) {
|
|
4630
|
-
json.asset = json.asset || {};
|
|
4631
|
-
json.asset.version = "2.0";
|
|
4632
|
-
json.asset.generator = json.asset.generator || "Normalized to glTF 2.0 by loaders.gl";
|
|
4633
|
-
}
|
|
4634
|
-
_convertTopLevelObjectsToArrays(json) {
|
|
4635
|
-
for (const arrayName in GLTF_ARRAYS) {
|
|
4636
|
-
this._convertTopLevelObjectToArray(json, arrayName);
|
|
4637
|
-
}
|
|
4638
|
-
}
|
|
4639
|
-
_convertTopLevelObjectToArray(json, mapName) {
|
|
4640
|
-
const objectMap = json[mapName];
|
|
4641
|
-
if (!objectMap || Array.isArray(objectMap)) {
|
|
4642
|
-
return;
|
|
4643
|
-
}
|
|
4644
|
-
json[mapName] = [];
|
|
4645
|
-
for (const id in objectMap) {
|
|
4646
|
-
const object = objectMap[id];
|
|
4647
|
-
object.id = object.id || id;
|
|
4648
|
-
const index = json[mapName].length;
|
|
4649
|
-
json[mapName].push(object);
|
|
4650
|
-
this.idToIndexMap[mapName][id] = index;
|
|
4651
|
-
}
|
|
4652
|
-
}
|
|
4653
|
-
_convertObjectIdsToArrayIndices(json) {
|
|
4654
|
-
for (const arrayName in GLTF_ARRAYS) {
|
|
4655
|
-
this._convertIdsToIndices(json, arrayName);
|
|
4656
|
-
}
|
|
4657
|
-
if ("scene" in json) {
|
|
4658
|
-
json.scene = this._convertIdToIndex(json.scene, "scene");
|
|
4659
|
-
}
|
|
4660
|
-
for (const texture of json.textures) {
|
|
4661
|
-
this._convertTextureIds(texture);
|
|
4662
|
-
}
|
|
4663
|
-
for (const mesh of json.meshes) {
|
|
4664
|
-
this._convertMeshIds(mesh);
|
|
4665
|
-
}
|
|
4666
|
-
for (const node2 of json.nodes) {
|
|
4667
|
-
this._convertNodeIds(node2);
|
|
4668
|
-
}
|
|
4669
|
-
for (const node2 of json.scenes) {
|
|
4670
|
-
this._convertSceneIds(node2);
|
|
4671
|
-
}
|
|
4672
|
-
}
|
|
4673
|
-
_convertTextureIds(texture) {
|
|
4674
|
-
if (texture.source) {
|
|
4675
|
-
texture.source = this._convertIdToIndex(texture.source, "image");
|
|
4676
|
-
}
|
|
4677
|
-
}
|
|
4678
|
-
_convertMeshIds(mesh) {
|
|
4679
|
-
for (const primitive of mesh.primitives) {
|
|
4680
|
-
const { attributes, indices, material } = primitive;
|
|
4681
|
-
for (const attributeName in attributes) {
|
|
4682
|
-
attributes[attributeName] = this._convertIdToIndex(attributes[attributeName], "accessor");
|
|
4683
|
-
}
|
|
4684
|
-
if (indices) {
|
|
4685
|
-
primitive.indices = this._convertIdToIndex(indices, "accessor");
|
|
4686
|
-
}
|
|
4687
|
-
if (material) {
|
|
4688
|
-
primitive.material = this._convertIdToIndex(material, "material");
|
|
4689
|
-
}
|
|
4690
|
-
}
|
|
4691
|
-
}
|
|
4692
|
-
_convertNodeIds(node2) {
|
|
4693
|
-
if (node2.children) {
|
|
4694
|
-
node2.children = node2.children.map((child) => this._convertIdToIndex(child, "node"));
|
|
4695
|
-
}
|
|
4696
|
-
if (node2.meshes) {
|
|
4697
|
-
node2.meshes = node2.meshes.map((mesh) => this._convertIdToIndex(mesh, "mesh"));
|
|
4698
|
-
}
|
|
4699
|
-
}
|
|
4700
|
-
_convertSceneIds(scene) {
|
|
4701
|
-
if (scene.nodes) {
|
|
4702
|
-
scene.nodes = scene.nodes.map((node2) => this._convertIdToIndex(node2, "node"));
|
|
4703
|
-
}
|
|
4704
|
-
}
|
|
4705
|
-
_convertIdsToIndices(json, topLevelArrayName) {
|
|
4706
|
-
if (!json[topLevelArrayName]) {
|
|
4707
|
-
console.warn(`gltf v1: json doesn't contain attribute ${topLevelArrayName}`);
|
|
4708
|
-
json[topLevelArrayName] = [];
|
|
4709
|
-
}
|
|
4710
|
-
for (const object of json[topLevelArrayName]) {
|
|
4711
|
-
for (const key in object) {
|
|
4712
|
-
const id = object[key];
|
|
4713
|
-
const index = this._convertIdToIndex(id, key);
|
|
4714
|
-
object[key] = index;
|
|
4715
|
-
}
|
|
4716
|
-
}
|
|
4717
|
-
}
|
|
4718
|
-
_convertIdToIndex(id, key) {
|
|
4719
|
-
const arrayName = GLTF_KEYS[key];
|
|
4720
|
-
if (arrayName in this.idToIndexMap) {
|
|
4721
|
-
const index = this.idToIndexMap[arrayName][id];
|
|
4722
|
-
if (!Number.isFinite(index)) {
|
|
4723
|
-
throw new Error(`gltf v1: failed to resolve ${key} with id ${id}`);
|
|
4724
|
-
}
|
|
4725
|
-
return index;
|
|
4726
|
-
}
|
|
4727
|
-
return id;
|
|
4728
|
-
}
|
|
4729
|
-
_updateObjects(json) {
|
|
4730
|
-
for (const buffer of this.json.buffers) {
|
|
4731
|
-
delete buffer.type;
|
|
4732
|
-
}
|
|
4733
|
-
}
|
|
4734
|
-
_updateMaterial(json) {
|
|
4735
|
-
for (const material of json.materials) {
|
|
4736
|
-
material.pbrMetallicRoughness = {
|
|
4737
|
-
baseColorFactor: [1, 1, 1, 1],
|
|
4738
|
-
metallicFactor: 1,
|
|
4739
|
-
roughnessFactor: 1
|
|
4740
|
-
};
|
|
4741
|
-
const textureId = material.values?.tex || material.values?.texture2d_0 || material.values?.diffuseTex;
|
|
4742
|
-
const textureIndex = json.textures.findIndex((texture) => texture.id === textureId);
|
|
4743
|
-
if (textureIndex !== -1) {
|
|
4744
|
-
material.pbrMetallicRoughness.baseColorTexture = { index: textureIndex };
|
|
4745
|
-
}
|
|
4746
|
-
}
|
|
4747
|
-
}
|
|
4748
|
-
};
|
|
4749
|
-
}
|
|
4750
|
-
});
|
|
4751
|
-
|
|
4752
|
-
// src/lib/api/post-process-gltf.ts
|
|
4753
|
-
function getBytesFromComponentType(componentType) {
|
|
4754
|
-
return BYTES2[componentType];
|
|
4755
|
-
}
|
|
4756
|
-
function getSizeFromAccessorType(type) {
|
|
4757
|
-
return COMPONENTS2[type];
|
|
4758
|
-
}
|
|
4759
|
-
function postProcessGLTF(gltf, options) {
|
|
4760
|
-
return new GLTFPostProcessor().postProcess(gltf, options);
|
|
4761
|
-
}
|
|
4762
|
-
var COMPONENTS2, BYTES2, GL_SAMPLER, SAMPLER_PARAMETER_GLTF_TO_GL, DEFAULT_SAMPLER, GLTFPostProcessor;
|
|
4763
|
-
var init_post_process_gltf = __esm({
|
|
4764
|
-
"src/lib/api/post-process-gltf.ts"() {
|
|
4765
|
-
init_assert3();
|
|
4766
|
-
init_gltf_utils();
|
|
4767
|
-
COMPONENTS2 = {
|
|
4768
|
-
SCALAR: 1,
|
|
4769
|
-
VEC2: 2,
|
|
4770
|
-
VEC3: 3,
|
|
4771
|
-
VEC4: 4,
|
|
4772
|
-
MAT2: 4,
|
|
4773
|
-
MAT3: 9,
|
|
4774
|
-
MAT4: 16
|
|
4775
|
-
};
|
|
4776
|
-
BYTES2 = {
|
|
4777
|
-
5120: 1,
|
|
4778
|
-
5121: 1,
|
|
4779
|
-
5122: 2,
|
|
4780
|
-
5123: 2,
|
|
4781
|
-
5125: 4,
|
|
4782
|
-
5126: 4
|
|
4783
|
-
};
|
|
4784
|
-
GL_SAMPLER = {
|
|
4785
|
-
TEXTURE_MAG_FILTER: 10240,
|
|
4786
|
-
TEXTURE_MIN_FILTER: 10241,
|
|
4787
|
-
TEXTURE_WRAP_S: 10242,
|
|
4788
|
-
TEXTURE_WRAP_T: 10243,
|
|
4789
|
-
REPEAT: 10497,
|
|
4790
|
-
LINEAR: 9729,
|
|
4791
|
-
NEAREST_MIPMAP_LINEAR: 9986
|
|
4792
|
-
};
|
|
4793
|
-
SAMPLER_PARAMETER_GLTF_TO_GL = {
|
|
4794
|
-
magFilter: GL_SAMPLER.TEXTURE_MAG_FILTER,
|
|
4795
|
-
minFilter: GL_SAMPLER.TEXTURE_MIN_FILTER,
|
|
4796
|
-
wrapS: GL_SAMPLER.TEXTURE_WRAP_S,
|
|
4797
|
-
wrapT: GL_SAMPLER.TEXTURE_WRAP_T
|
|
4798
|
-
};
|
|
4799
|
-
DEFAULT_SAMPLER = {
|
|
4800
|
-
[GL_SAMPLER.TEXTURE_MAG_FILTER]: GL_SAMPLER.LINEAR,
|
|
4801
|
-
[GL_SAMPLER.TEXTURE_MIN_FILTER]: GL_SAMPLER.NEAREST_MIPMAP_LINEAR,
|
|
4802
|
-
[GL_SAMPLER.TEXTURE_WRAP_S]: GL_SAMPLER.REPEAT,
|
|
4803
|
-
[GL_SAMPLER.TEXTURE_WRAP_T]: GL_SAMPLER.REPEAT
|
|
4804
|
-
};
|
|
4805
|
-
GLTFPostProcessor = class {
|
|
4806
|
-
constructor() {
|
|
4807
|
-
this.baseUri = "";
|
|
4808
|
-
this.json = {};
|
|
4809
|
-
this.buffers = [];
|
|
4810
|
-
this.images = [];
|
|
4811
|
-
}
|
|
4812
|
-
postProcess(gltf, options = {}) {
|
|
4813
|
-
const { json, buffers = [], images = [], baseUri = "" } = gltf;
|
|
4814
|
-
assert3(json);
|
|
4815
|
-
this.baseUri = baseUri;
|
|
4816
|
-
this.json = json;
|
|
4817
|
-
this.buffers = buffers;
|
|
4818
|
-
this.images = images;
|
|
4819
|
-
this._resolveTree(this.json, options);
|
|
4820
|
-
return this.json;
|
|
4821
|
-
}
|
|
4822
|
-
_resolveTree(json, options = {}) {
|
|
4823
|
-
if (json.bufferViews) {
|
|
4824
|
-
json.bufferViews = json.bufferViews.map((bufView, i2) => this._resolveBufferView(bufView, i2));
|
|
4825
|
-
}
|
|
4826
|
-
if (json.images) {
|
|
4827
|
-
json.images = json.images.map((image, i2) => this._resolveImage(image, i2));
|
|
4828
|
-
}
|
|
4829
|
-
if (json.samplers) {
|
|
4830
|
-
json.samplers = json.samplers.map((sampler, i2) => this._resolveSampler(sampler, i2));
|
|
4831
|
-
}
|
|
4832
|
-
if (json.textures) {
|
|
4833
|
-
json.textures = json.textures.map((texture, i2) => this._resolveTexture(texture, i2));
|
|
4834
|
-
}
|
|
4835
|
-
if (json.accessors) {
|
|
4836
|
-
json.accessors = json.accessors.map((accessor, i2) => this._resolveAccessor(accessor, i2));
|
|
4837
|
-
}
|
|
4838
|
-
if (json.materials) {
|
|
4839
|
-
json.materials = json.materials.map((material, i2) => this._resolveMaterial(material, i2));
|
|
4840
|
-
}
|
|
4841
|
-
if (json.meshes) {
|
|
4842
|
-
json.meshes = json.meshes.map((mesh, i2) => this._resolveMesh(mesh, i2));
|
|
4843
|
-
}
|
|
4844
|
-
if (json.nodes) {
|
|
4845
|
-
json.nodes = json.nodes.map((node2, i2) => this._resolveNode(node2, i2));
|
|
4846
|
-
}
|
|
4847
|
-
if (json.skins) {
|
|
4848
|
-
json.skins = json.skins.map((skin, i2) => this._resolveSkin(skin, i2));
|
|
4849
|
-
}
|
|
4850
|
-
if (json.scenes) {
|
|
4851
|
-
json.scenes = json.scenes.map((scene, i2) => this._resolveScene(scene, i2));
|
|
4852
|
-
}
|
|
4853
|
-
if (json.scene !== void 0) {
|
|
4854
|
-
json.scene = json.scenes[this.json.scene];
|
|
4855
|
-
}
|
|
4856
|
-
}
|
|
4857
|
-
getScene(index) {
|
|
4858
|
-
return this._get("scenes", index);
|
|
4859
|
-
}
|
|
4860
|
-
getNode(index) {
|
|
4861
|
-
return this._get("nodes", index);
|
|
4862
|
-
}
|
|
4863
|
-
getSkin(index) {
|
|
4864
|
-
return this._get("skins", index);
|
|
4865
|
-
}
|
|
4866
|
-
getMesh(index) {
|
|
4867
|
-
return this._get("meshes", index);
|
|
4868
|
-
}
|
|
4869
|
-
getMaterial(index) {
|
|
4870
|
-
return this._get("materials", index);
|
|
4871
|
-
}
|
|
4872
|
-
getAccessor(index) {
|
|
4873
|
-
return this._get("accessors", index);
|
|
4874
|
-
}
|
|
4875
|
-
getCamera(index) {
|
|
4876
|
-
return null;
|
|
4877
|
-
}
|
|
4878
|
-
getTexture(index) {
|
|
4879
|
-
return this._get("textures", index);
|
|
4880
|
-
}
|
|
4881
|
-
getSampler(index) {
|
|
4882
|
-
return this._get("samplers", index);
|
|
4883
|
-
}
|
|
4884
|
-
getImage(index) {
|
|
4885
|
-
return this._get("images", index);
|
|
4886
|
-
}
|
|
4887
|
-
getBufferView(index) {
|
|
4888
|
-
return this._get("bufferViews", index);
|
|
4889
|
-
}
|
|
4890
|
-
getBuffer(index) {
|
|
4891
|
-
return this._get("buffers", index);
|
|
4892
|
-
}
|
|
4893
|
-
_get(array, index) {
|
|
4894
|
-
if (typeof index === "object") {
|
|
4895
|
-
return index;
|
|
4896
|
-
}
|
|
4897
|
-
const object = this.json[array] && this.json[array][index];
|
|
4898
|
-
if (!object) {
|
|
4899
|
-
console.warn(`glTF file error: Could not find ${array}[${index}]`);
|
|
4900
|
-
}
|
|
4901
|
-
return object;
|
|
4902
|
-
}
|
|
4903
|
-
_resolveScene(scene, index) {
|
|
4904
|
-
scene.id = scene.id || `scene-${index}`;
|
|
4905
|
-
scene.nodes = (scene.nodes || []).map((node2) => this.getNode(node2));
|
|
4906
|
-
return scene;
|
|
4907
|
-
}
|
|
4908
|
-
_resolveNode(node2, index) {
|
|
4909
|
-
node2.id = node2.id || `node-${index}`;
|
|
4910
|
-
if (node2.children) {
|
|
4911
|
-
node2.children = node2.children.map((child) => this.getNode(child));
|
|
4912
|
-
}
|
|
4913
|
-
if (node2.mesh !== void 0) {
|
|
4914
|
-
node2.mesh = this.getMesh(node2.mesh);
|
|
4915
|
-
} else if (node2.meshes !== void 0 && node2.meshes.length) {
|
|
4916
|
-
node2.mesh = node2.meshes.reduce((accum, meshIndex) => {
|
|
4917
|
-
const mesh = this.getMesh(meshIndex);
|
|
4918
|
-
accum.id = mesh.id;
|
|
4919
|
-
accum.primitives = accum.primitives.concat(mesh.primitives);
|
|
4920
|
-
return accum;
|
|
4921
|
-
}, { primitives: [] });
|
|
4922
|
-
}
|
|
4923
|
-
if (node2.camera !== void 0) {
|
|
4924
|
-
node2.camera = this.getCamera(node2.camera);
|
|
4925
|
-
}
|
|
4926
|
-
if (node2.skin !== void 0) {
|
|
4927
|
-
node2.skin = this.getSkin(node2.skin);
|
|
4928
|
-
}
|
|
4929
|
-
return node2;
|
|
4930
|
-
}
|
|
4931
|
-
_resolveSkin(skin, index) {
|
|
4932
|
-
skin.id = skin.id || `skin-${index}`;
|
|
4933
|
-
skin.inverseBindMatrices = this.getAccessor(skin.inverseBindMatrices);
|
|
4934
|
-
return skin;
|
|
4935
|
-
}
|
|
4936
|
-
_resolveMesh(mesh, index) {
|
|
4937
|
-
mesh.id = mesh.id || `mesh-${index}`;
|
|
4938
|
-
if (mesh.primitives) {
|
|
4939
|
-
mesh.primitives = mesh.primitives.map((primitive) => {
|
|
4940
|
-
primitive = { ...primitive };
|
|
4941
|
-
const attributes = primitive.attributes;
|
|
4942
|
-
primitive.attributes = {};
|
|
4943
|
-
for (const attribute in attributes) {
|
|
4944
|
-
primitive.attributes[attribute] = this.getAccessor(attributes[attribute]);
|
|
4945
|
-
}
|
|
4946
|
-
if (primitive.indices !== void 0) {
|
|
4947
|
-
primitive.indices = this.getAccessor(primitive.indices);
|
|
4948
|
-
}
|
|
4949
|
-
if (primitive.material !== void 0) {
|
|
4950
|
-
primitive.material = this.getMaterial(primitive.material);
|
|
4951
|
-
}
|
|
4952
|
-
return primitive;
|
|
4953
|
-
});
|
|
4765
|
+
_addAsset(json) {
|
|
4766
|
+
json.asset = json.asset || {};
|
|
4767
|
+
json.asset.version = "2.0";
|
|
4768
|
+
json.asset.generator = json.asset.generator || "Normalized to glTF 2.0 by loaders.gl";
|
|
4769
|
+
}
|
|
4770
|
+
_convertTopLevelObjectsToArrays(json) {
|
|
4771
|
+
for (const arrayName in GLTF_ARRAYS) {
|
|
4772
|
+
this._convertTopLevelObjectToArray(json, arrayName);
|
|
4954
4773
|
}
|
|
4955
|
-
return mesh;
|
|
4956
4774
|
}
|
|
4957
|
-
|
|
4958
|
-
|
|
4959
|
-
if (
|
|
4960
|
-
|
|
4961
|
-
material.normalTexture.texture = this.getTexture(material.normalTexture.index);
|
|
4775
|
+
_convertTopLevelObjectToArray(json, mapName) {
|
|
4776
|
+
const objectMap = json[mapName];
|
|
4777
|
+
if (!objectMap || Array.isArray(objectMap)) {
|
|
4778
|
+
return;
|
|
4962
4779
|
}
|
|
4963
|
-
|
|
4964
|
-
|
|
4965
|
-
|
|
4780
|
+
json[mapName] = [];
|
|
4781
|
+
for (const id in objectMap) {
|
|
4782
|
+
const object = objectMap[id];
|
|
4783
|
+
object.id = object.id || id;
|
|
4784
|
+
const index = json[mapName].length;
|
|
4785
|
+
json[mapName].push(object);
|
|
4786
|
+
this.idToIndexMap[mapName][id] = index;
|
|
4966
4787
|
}
|
|
4967
|
-
|
|
4968
|
-
|
|
4969
|
-
|
|
4788
|
+
}
|
|
4789
|
+
_convertObjectIdsToArrayIndices(json) {
|
|
4790
|
+
for (const arrayName in GLTF_ARRAYS) {
|
|
4791
|
+
this._convertIdsToIndices(json, arrayName);
|
|
4970
4792
|
}
|
|
4971
|
-
if (
|
|
4972
|
-
|
|
4793
|
+
if ("scene" in json) {
|
|
4794
|
+
json.scene = this._convertIdToIndex(json.scene, "scene");
|
|
4973
4795
|
}
|
|
4974
|
-
|
|
4975
|
-
|
|
4976
|
-
const mr = material.pbrMetallicRoughness;
|
|
4977
|
-
if (mr.baseColorTexture) {
|
|
4978
|
-
mr.baseColorTexture = { ...mr.baseColorTexture };
|
|
4979
|
-
mr.baseColorTexture.texture = this.getTexture(mr.baseColorTexture.index);
|
|
4980
|
-
}
|
|
4981
|
-
if (mr.metallicRoughnessTexture) {
|
|
4982
|
-
mr.metallicRoughnessTexture = { ...mr.metallicRoughnessTexture };
|
|
4983
|
-
mr.metallicRoughnessTexture.texture = this.getTexture(mr.metallicRoughnessTexture.index);
|
|
4984
|
-
}
|
|
4796
|
+
for (const texture of json.textures) {
|
|
4797
|
+
this._convertTextureIds(texture);
|
|
4985
4798
|
}
|
|
4986
|
-
|
|
4987
|
-
|
|
4988
|
-
_resolveAccessor(accessor, index) {
|
|
4989
|
-
accessor.id = accessor.id || `accessor-${index}`;
|
|
4990
|
-
if (accessor.bufferView !== void 0) {
|
|
4991
|
-
accessor.bufferView = this.getBufferView(accessor.bufferView);
|
|
4799
|
+
for (const mesh of json.meshes) {
|
|
4800
|
+
this._convertMeshIds(mesh);
|
|
4992
4801
|
}
|
|
4993
|
-
|
|
4994
|
-
|
|
4995
|
-
accessor.bytesPerElement = accessor.bytesPerComponent * accessor.components;
|
|
4996
|
-
if (accessor.bufferView) {
|
|
4997
|
-
const buffer = accessor.bufferView.buffer;
|
|
4998
|
-
const { ArrayType, byteLength } = getAccessorArrayTypeAndLength(accessor, accessor.bufferView);
|
|
4999
|
-
const byteOffset = (accessor.bufferView.byteOffset || 0) + (accessor.byteOffset || 0) + buffer.byteOffset;
|
|
5000
|
-
let cutBuffer = buffer.arrayBuffer.slice(byteOffset, byteOffset + byteLength);
|
|
5001
|
-
if (accessor.bufferView.byteStride) {
|
|
5002
|
-
cutBuffer = this._getValueFromInterleavedBuffer(buffer, byteOffset, accessor.bufferView.byteStride, accessor.bytesPerElement, accessor.count);
|
|
5003
|
-
}
|
|
5004
|
-
accessor.value = new ArrayType(cutBuffer);
|
|
4802
|
+
for (const node2 of json.nodes) {
|
|
4803
|
+
this._convertNodeIds(node2);
|
|
5005
4804
|
}
|
|
5006
|
-
|
|
5007
|
-
|
|
5008
|
-
_getValueFromInterleavedBuffer(buffer, byteOffset, byteStride, bytesPerElement, count) {
|
|
5009
|
-
const result = new Uint8Array(count * bytesPerElement);
|
|
5010
|
-
for (let i2 = 0; i2 < count; i2++) {
|
|
5011
|
-
const elementOffset = byteOffset + i2 * byteStride;
|
|
5012
|
-
result.set(new Uint8Array(buffer.arrayBuffer.slice(elementOffset, elementOffset + bytesPerElement)), i2 * bytesPerElement);
|
|
4805
|
+
for (const node2 of json.scenes) {
|
|
4806
|
+
this._convertSceneIds(node2);
|
|
5013
4807
|
}
|
|
5014
|
-
return result.buffer;
|
|
5015
4808
|
}
|
|
5016
|
-
|
|
5017
|
-
|
|
5018
|
-
|
|
5019
|
-
|
|
5020
|
-
return texture;
|
|
4809
|
+
_convertTextureIds(texture) {
|
|
4810
|
+
if (texture.source) {
|
|
4811
|
+
texture.source = this._convertIdToIndex(texture.source, "image");
|
|
4812
|
+
}
|
|
5021
4813
|
}
|
|
5022
|
-
|
|
5023
|
-
|
|
5024
|
-
|
|
5025
|
-
|
|
5026
|
-
|
|
5027
|
-
|
|
5028
|
-
|
|
4814
|
+
_convertMeshIds(mesh) {
|
|
4815
|
+
for (const primitive of mesh.primitives) {
|
|
4816
|
+
const { attributes, indices, material } = primitive;
|
|
4817
|
+
for (const attributeName in attributes) {
|
|
4818
|
+
attributes[attributeName] = this._convertIdToIndex(attributes[attributeName], "accessor");
|
|
4819
|
+
}
|
|
4820
|
+
if (indices) {
|
|
4821
|
+
primitive.indices = this._convertIdToIndex(indices, "accessor");
|
|
4822
|
+
}
|
|
4823
|
+
if (material) {
|
|
4824
|
+
primitive.material = this._convertIdToIndex(material, "material");
|
|
5029
4825
|
}
|
|
5030
4826
|
}
|
|
5031
|
-
return sampler;
|
|
5032
|
-
}
|
|
5033
|
-
_enumSamplerParameter(key) {
|
|
5034
|
-
return SAMPLER_PARAMETER_GLTF_TO_GL[key];
|
|
5035
4827
|
}
|
|
5036
|
-
|
|
5037
|
-
|
|
5038
|
-
|
|
5039
|
-
image.bufferView = this.getBufferView(image.bufferView);
|
|
4828
|
+
_convertNodeIds(node2) {
|
|
4829
|
+
if (node2.children) {
|
|
4830
|
+
node2.children = node2.children.map((child) => this._convertIdToIndex(child, "node"));
|
|
5040
4831
|
}
|
|
5041
|
-
|
|
5042
|
-
|
|
5043
|
-
image.image = preloadedImage;
|
|
4832
|
+
if (node2.meshes) {
|
|
4833
|
+
node2.meshes = node2.meshes.map((mesh) => this._convertIdToIndex(mesh, "mesh"));
|
|
5044
4834
|
}
|
|
5045
|
-
return image;
|
|
5046
4835
|
}
|
|
5047
|
-
|
|
5048
|
-
|
|
5049
|
-
|
|
5050
|
-
id: `bufferView-${index}`,
|
|
5051
|
-
...bufferView,
|
|
5052
|
-
buffer: this.buffers[bufferIndex]
|
|
5053
|
-
};
|
|
5054
|
-
const arrayBuffer = this.buffers[bufferIndex].arrayBuffer;
|
|
5055
|
-
let byteOffset = this.buffers[bufferIndex].byteOffset || 0;
|
|
5056
|
-
if ("byteOffset" in bufferView) {
|
|
5057
|
-
byteOffset += bufferView.byteOffset;
|
|
4836
|
+
_convertSceneIds(scene) {
|
|
4837
|
+
if (scene.nodes) {
|
|
4838
|
+
scene.nodes = scene.nodes.map((node2) => this._convertIdToIndex(node2, "node"));
|
|
5058
4839
|
}
|
|
5059
|
-
result.data = new Uint8Array(arrayBuffer, byteOffset, bufferView.byteLength);
|
|
5060
|
-
return result;
|
|
5061
4840
|
}
|
|
5062
|
-
|
|
5063
|
-
|
|
5064
|
-
|
|
4841
|
+
_convertIdsToIndices(json, topLevelArrayName) {
|
|
4842
|
+
if (!json[topLevelArrayName]) {
|
|
4843
|
+
console.warn(`gltf v1: json doesn't contain attribute ${topLevelArrayName}`);
|
|
4844
|
+
json[topLevelArrayName] = [];
|
|
5065
4845
|
}
|
|
5066
|
-
|
|
4846
|
+
for (const object of json[topLevelArrayName]) {
|
|
4847
|
+
for (const key in object) {
|
|
4848
|
+
const id = object[key];
|
|
4849
|
+
const index = this._convertIdToIndex(id, key);
|
|
4850
|
+
object[key] = index;
|
|
4851
|
+
}
|
|
5067
4852
|
}
|
|
5068
|
-
return camera;
|
|
5069
4853
|
}
|
|
5070
|
-
|
|
5071
|
-
|
|
5072
|
-
|
|
5073
|
-
|
|
5074
|
-
|
|
5075
|
-
|
|
5076
|
-
|
|
5077
|
-
|
|
5078
|
-
function isGLB(arrayBuffer, byteOffset = 0, options = {}) {
|
|
5079
|
-
const dataView = new DataView(arrayBuffer);
|
|
5080
|
-
const { magic = MAGIC_glTF } = options;
|
|
5081
|
-
const magic1 = dataView.getUint32(byteOffset, false);
|
|
5082
|
-
return magic1 === magic || magic1 === MAGIC_glTF;
|
|
5083
|
-
}
|
|
5084
|
-
function parseGLBSync(glb, arrayBuffer, byteOffset = 0, options = {}) {
|
|
5085
|
-
const dataView = new DataView(arrayBuffer);
|
|
5086
|
-
const type = getMagicString2(dataView, byteOffset + 0);
|
|
5087
|
-
const version = dataView.getUint32(byteOffset + 4, LE);
|
|
5088
|
-
const byteLength = dataView.getUint32(byteOffset + 8, LE);
|
|
5089
|
-
Object.assign(glb, {
|
|
5090
|
-
header: {
|
|
5091
|
-
byteOffset,
|
|
5092
|
-
byteLength,
|
|
5093
|
-
hasBinChunk: false
|
|
5094
|
-
},
|
|
5095
|
-
type,
|
|
5096
|
-
version,
|
|
5097
|
-
json: {},
|
|
5098
|
-
binChunks: []
|
|
5099
|
-
});
|
|
5100
|
-
byteOffset += GLB_FILE_HEADER_SIZE;
|
|
5101
|
-
switch (glb.version) {
|
|
5102
|
-
case 1:
|
|
5103
|
-
return parseGLBV1(glb, dataView, byteOffset);
|
|
5104
|
-
case 2:
|
|
5105
|
-
return parseGLBV2(glb, dataView, byteOffset, options = {});
|
|
5106
|
-
default:
|
|
5107
|
-
throw new Error(`Invalid GLB version ${glb.version}. Only supports v1 and v2.`);
|
|
5108
|
-
}
|
|
5109
|
-
}
|
|
5110
|
-
function parseGLBV1(glb, dataView, byteOffset) {
|
|
5111
|
-
assert(glb.header.byteLength > GLB_FILE_HEADER_SIZE + GLB_CHUNK_HEADER_SIZE);
|
|
5112
|
-
const contentLength = dataView.getUint32(byteOffset + 0, LE);
|
|
5113
|
-
const contentFormat = dataView.getUint32(byteOffset + 4, LE);
|
|
5114
|
-
byteOffset += GLB_CHUNK_HEADER_SIZE;
|
|
5115
|
-
assert(contentFormat === GLB_V1_CONTENT_FORMAT_JSON);
|
|
5116
|
-
parseJSONChunk(glb, dataView, byteOffset, contentLength);
|
|
5117
|
-
byteOffset += contentLength;
|
|
5118
|
-
byteOffset += parseBINChunk(glb, dataView, byteOffset, glb.header.byteLength);
|
|
5119
|
-
return byteOffset;
|
|
5120
|
-
}
|
|
5121
|
-
function parseGLBV2(glb, dataView, byteOffset, options) {
|
|
5122
|
-
assert(glb.header.byteLength > GLB_FILE_HEADER_SIZE + GLB_CHUNK_HEADER_SIZE);
|
|
5123
|
-
parseGLBChunksSync(glb, dataView, byteOffset, options);
|
|
5124
|
-
return byteOffset + glb.header.byteLength;
|
|
5125
|
-
}
|
|
5126
|
-
function parseGLBChunksSync(glb, dataView, byteOffset, options) {
|
|
5127
|
-
while (byteOffset + 8 <= glb.header.byteLength) {
|
|
5128
|
-
const chunkLength = dataView.getUint32(byteOffset + 0, LE);
|
|
5129
|
-
const chunkFormat = dataView.getUint32(byteOffset + 4, LE);
|
|
5130
|
-
byteOffset += GLB_CHUNK_HEADER_SIZE;
|
|
5131
|
-
switch (chunkFormat) {
|
|
5132
|
-
case GLB_CHUNK_TYPE_JSON:
|
|
5133
|
-
parseJSONChunk(glb, dataView, byteOffset, chunkLength);
|
|
5134
|
-
break;
|
|
5135
|
-
case GLB_CHUNK_TYPE_BIN:
|
|
5136
|
-
parseBINChunk(glb, dataView, byteOffset, chunkLength);
|
|
5137
|
-
break;
|
|
5138
|
-
case GLB_CHUNK_TYPE_JSON_XVIZ_DEPRECATED:
|
|
5139
|
-
if (!options.strict) {
|
|
5140
|
-
parseJSONChunk(glb, dataView, byteOffset, chunkLength);
|
|
4854
|
+
_convertIdToIndex(id, key) {
|
|
4855
|
+
const arrayName = GLTF_KEYS[key];
|
|
4856
|
+
if (arrayName in this.idToIndexMap) {
|
|
4857
|
+
const index = this.idToIndexMap[arrayName][id];
|
|
4858
|
+
if (!Number.isFinite(index)) {
|
|
4859
|
+
throw new Error(`gltf v1: failed to resolve ${key} with id ${id}`);
|
|
4860
|
+
}
|
|
4861
|
+
return index;
|
|
5141
4862
|
}
|
|
5142
|
-
|
|
5143
|
-
|
|
5144
|
-
|
|
5145
|
-
|
|
4863
|
+
return id;
|
|
4864
|
+
}
|
|
4865
|
+
_updateObjects(json) {
|
|
4866
|
+
for (const buffer of this.json.buffers) {
|
|
4867
|
+
delete buffer.type;
|
|
5146
4868
|
}
|
|
5147
|
-
|
|
5148
|
-
|
|
5149
|
-
|
|
5150
|
-
|
|
5151
|
-
|
|
5152
|
-
|
|
5153
|
-
|
|
5154
|
-
|
|
5155
|
-
|
|
5156
|
-
|
|
5157
|
-
|
|
5158
|
-
|
|
5159
|
-
|
|
5160
|
-
|
|
5161
|
-
|
|
5162
|
-
|
|
5163
|
-
glb.header.hasBinChunk = true;
|
|
5164
|
-
glb.binChunks.push({
|
|
5165
|
-
byteOffset,
|
|
5166
|
-
byteLength: chunkLength,
|
|
5167
|
-
arrayBuffer: dataView.buffer
|
|
5168
|
-
});
|
|
5169
|
-
return padToNBytes(chunkLength, 4);
|
|
5170
|
-
}
|
|
5171
|
-
var MAGIC_glTF, GLB_FILE_HEADER_SIZE, GLB_CHUNK_HEADER_SIZE, GLB_CHUNK_TYPE_JSON, GLB_CHUNK_TYPE_BIN, GLB_CHUNK_TYPE_JSON_XVIZ_DEPRECATED, GLB_CHUNK_TYPE_BIX_XVIZ_DEPRECATED, GLB_V1_CONTENT_FORMAT_JSON, LE;
|
|
5172
|
-
var init_parse_glb = __esm({
|
|
5173
|
-
"src/lib/parsers/parse-glb.ts"() {
|
|
5174
|
-
init_src2();
|
|
5175
|
-
MAGIC_glTF = 1735152710;
|
|
5176
|
-
GLB_FILE_HEADER_SIZE = 12;
|
|
5177
|
-
GLB_CHUNK_HEADER_SIZE = 8;
|
|
5178
|
-
GLB_CHUNK_TYPE_JSON = 1313821514;
|
|
5179
|
-
GLB_CHUNK_TYPE_BIN = 5130562;
|
|
5180
|
-
GLB_CHUNK_TYPE_JSON_XVIZ_DEPRECATED = 0;
|
|
5181
|
-
GLB_CHUNK_TYPE_BIX_XVIZ_DEPRECATED = 1;
|
|
5182
|
-
GLB_V1_CONTENT_FORMAT_JSON = 0;
|
|
5183
|
-
LE = true;
|
|
4869
|
+
}
|
|
4870
|
+
_updateMaterial(json) {
|
|
4871
|
+
for (const material of json.materials) {
|
|
4872
|
+
material.pbrMetallicRoughness = {
|
|
4873
|
+
baseColorFactor: [1, 1, 1, 1],
|
|
4874
|
+
metallicFactor: 1,
|
|
4875
|
+
roughnessFactor: 1
|
|
4876
|
+
};
|
|
4877
|
+
const textureId = material.values?.tex || material.values?.texture2d_0 || material.values?.diffuseTex;
|
|
4878
|
+
const textureIndex = json.textures.findIndex((texture) => texture.id === textureId);
|
|
4879
|
+
if (textureIndex !== -1) {
|
|
4880
|
+
material.pbrMetallicRoughness.baseColorTexture = { index: textureIndex };
|
|
4881
|
+
}
|
|
4882
|
+
}
|
|
4883
|
+
}
|
|
4884
|
+
};
|
|
5184
4885
|
}
|
|
5185
4886
|
});
|
|
5186
4887
|
|
|
@@ -5200,7 +4901,7 @@
|
|
|
5200
4901
|
const promise = decodeExtensions(gltf, options, context);
|
|
5201
4902
|
promises.push(promise);
|
|
5202
4903
|
await Promise.all(promises);
|
|
5203
|
-
return
|
|
4904
|
+
return gltf;
|
|
5204
4905
|
}
|
|
5205
4906
|
function parseGLTFContainerSync(gltf, data, byteOffset, options) {
|
|
5206
4907
|
if (options.uri) {
|
|
@@ -5309,16 +5010,15 @@
|
|
|
5309
5010
|
}
|
|
5310
5011
|
var init_parse_gltf = __esm({
|
|
5311
5012
|
"src/lib/parsers/parse-gltf.ts"() {
|
|
5312
|
-
init_src4();
|
|
5313
|
-
init_src3();
|
|
5314
5013
|
init_src2();
|
|
5014
|
+
init_src3();
|
|
5015
|
+
init_src4();
|
|
5315
5016
|
init_assert3();
|
|
5017
|
+
init_parse_glb();
|
|
5316
5018
|
init_resolve_url();
|
|
5317
5019
|
init_get_typed_array();
|
|
5318
5020
|
init_gltf_extensions();
|
|
5319
5021
|
init_normalize_gltf_v1();
|
|
5320
|
-
init_post_process_gltf();
|
|
5321
|
-
init_parse_glb();
|
|
5322
5022
|
}
|
|
5323
5023
|
});
|
|
5324
5024
|
|
|
@@ -5351,8 +5051,7 @@
|
|
|
5351
5051
|
normalize: true,
|
|
5352
5052
|
loadBuffers: true,
|
|
5353
5053
|
loadImages: true,
|
|
5354
|
-
decompressMeshes: true
|
|
5355
|
-
postProcess: true
|
|
5054
|
+
decompressMeshes: true
|
|
5356
5055
|
},
|
|
5357
5056
|
log: console
|
|
5358
5057
|
},
|
|
@@ -5362,7 +5061,8 @@
|
|
|
5362
5061
|
decompress: "gltf.decompressMeshes",
|
|
5363
5062
|
postProcess: "gltf.postProcess",
|
|
5364
5063
|
gltf: {
|
|
5365
|
-
decompress: "gltf.decompressMeshes"
|
|
5064
|
+
decompress: "gltf.decompressMeshes",
|
|
5065
|
+
postProcess: "removed in v4"
|
|
5366
5066
|
}
|
|
5367
5067
|
}
|
|
5368
5068
|
};
|
|
@@ -5374,51 +5074,51 @@
|
|
|
5374
5074
|
const { magic = MAGIC_glTF2, version = 2, json = {}, binary } = glb;
|
|
5375
5075
|
const byteOffsetStart = byteOffset;
|
|
5376
5076
|
if (dataView) {
|
|
5377
|
-
dataView.setUint32(byteOffset + 0, magic,
|
|
5378
|
-
dataView.setUint32(byteOffset + 4, version,
|
|
5379
|
-
dataView.setUint32(byteOffset + 8, 0,
|
|
5077
|
+
dataView.setUint32(byteOffset + 0, magic, LE);
|
|
5078
|
+
dataView.setUint32(byteOffset + 4, version, LE);
|
|
5079
|
+
dataView.setUint32(byteOffset + 8, 0, LE);
|
|
5380
5080
|
}
|
|
5381
5081
|
const byteOffsetFileLength = byteOffset + 8;
|
|
5382
5082
|
byteOffset += 12;
|
|
5383
5083
|
const byteOffsetJsonHeader = byteOffset;
|
|
5384
5084
|
if (dataView) {
|
|
5385
|
-
dataView.setUint32(byteOffset + 0, 0,
|
|
5386
|
-
dataView.setUint32(byteOffset + 4, MAGIC_JSON,
|
|
5085
|
+
dataView.setUint32(byteOffset + 0, 0, LE);
|
|
5086
|
+
dataView.setUint32(byteOffset + 4, MAGIC_JSON, LE);
|
|
5387
5087
|
}
|
|
5388
5088
|
byteOffset += 8;
|
|
5389
5089
|
const jsonString = JSON.stringify(json);
|
|
5390
5090
|
byteOffset = copyPaddedStringToDataView(dataView, byteOffset, jsonString, 4);
|
|
5391
5091
|
if (dataView) {
|
|
5392
5092
|
const jsonByteLength = byteOffset - byteOffsetJsonHeader - 8;
|
|
5393
|
-
dataView.setUint32(byteOffsetJsonHeader + 0, jsonByteLength,
|
|
5093
|
+
dataView.setUint32(byteOffsetJsonHeader + 0, jsonByteLength, LE);
|
|
5394
5094
|
}
|
|
5395
5095
|
if (binary) {
|
|
5396
5096
|
const byteOffsetBinHeader = byteOffset;
|
|
5397
5097
|
if (dataView) {
|
|
5398
|
-
dataView.setUint32(byteOffset + 0, 0,
|
|
5399
|
-
dataView.setUint32(byteOffset + 4, MAGIC_BIN,
|
|
5098
|
+
dataView.setUint32(byteOffset + 0, 0, LE);
|
|
5099
|
+
dataView.setUint32(byteOffset + 4, MAGIC_BIN, LE);
|
|
5400
5100
|
}
|
|
5401
5101
|
byteOffset += 8;
|
|
5402
5102
|
byteOffset = copyPaddedArrayBufferToDataView(dataView, byteOffset, binary, 4);
|
|
5403
5103
|
if (dataView) {
|
|
5404
5104
|
const binByteLength = byteOffset - byteOffsetBinHeader - 8;
|
|
5405
|
-
dataView.setUint32(byteOffsetBinHeader + 0, binByteLength,
|
|
5105
|
+
dataView.setUint32(byteOffsetBinHeader + 0, binByteLength, LE);
|
|
5406
5106
|
}
|
|
5407
5107
|
}
|
|
5408
5108
|
if (dataView) {
|
|
5409
5109
|
const fileByteLength = byteOffset - byteOffsetStart;
|
|
5410
|
-
dataView.setUint32(byteOffsetFileLength, fileByteLength,
|
|
5110
|
+
dataView.setUint32(byteOffsetFileLength, fileByteLength, LE);
|
|
5411
5111
|
}
|
|
5412
5112
|
return byteOffset;
|
|
5413
5113
|
}
|
|
5414
|
-
var MAGIC_glTF2, MAGIC_JSON, MAGIC_BIN,
|
|
5114
|
+
var MAGIC_glTF2, MAGIC_JSON, MAGIC_BIN, LE;
|
|
5415
5115
|
var init_encode_glb = __esm({
|
|
5416
5116
|
"src/lib/encoders/encode-glb.ts"() {
|
|
5417
5117
|
init_src2();
|
|
5418
5118
|
MAGIC_glTF2 = 1179937895;
|
|
5419
5119
|
MAGIC_JSON = 1313821514;
|
|
5420
5120
|
MAGIC_BIN = 5130562;
|
|
5421
|
-
|
|
5121
|
+
LE = true;
|
|
5422
5122
|
}
|
|
5423
5123
|
});
|
|
5424
5124
|
|
|
@@ -5532,6 +5232,380 @@
|
|
|
5532
5232
|
}
|
|
5533
5233
|
});
|
|
5534
5234
|
|
|
5235
|
+
// src/lib/api/post-process-gltf.ts
|
|
5236
|
+
function makeDefaultSampler() {
|
|
5237
|
+
return {
|
|
5238
|
+
id: "default-sampler",
|
|
5239
|
+
parameters: DEFAULT_SAMPLER_PARAMETERS
|
|
5240
|
+
};
|
|
5241
|
+
}
|
|
5242
|
+
function getBytesFromComponentType(componentType) {
|
|
5243
|
+
return BYTES2[componentType];
|
|
5244
|
+
}
|
|
5245
|
+
function getSizeFromAccessorType(type) {
|
|
5246
|
+
return COMPONENTS2[type];
|
|
5247
|
+
}
|
|
5248
|
+
function postProcessGLTF(gltf, options) {
|
|
5249
|
+
return new GLTFPostProcessor().postProcess(gltf, options);
|
|
5250
|
+
}
|
|
5251
|
+
var COMPONENTS2, BYTES2, GL_SAMPLER, SAMPLER_PARAMETER_GLTF_TO_GL, DEFAULT_SAMPLER_PARAMETERS, GLTFPostProcessor;
|
|
5252
|
+
var init_post_process_gltf = __esm({
|
|
5253
|
+
"src/lib/api/post-process-gltf.ts"() {
|
|
5254
|
+
init_assert3();
|
|
5255
|
+
init_gltf_utils();
|
|
5256
|
+
COMPONENTS2 = {
|
|
5257
|
+
SCALAR: 1,
|
|
5258
|
+
VEC2: 2,
|
|
5259
|
+
VEC3: 3,
|
|
5260
|
+
VEC4: 4,
|
|
5261
|
+
MAT2: 4,
|
|
5262
|
+
MAT3: 9,
|
|
5263
|
+
MAT4: 16
|
|
5264
|
+
};
|
|
5265
|
+
BYTES2 = {
|
|
5266
|
+
5120: 1,
|
|
5267
|
+
5121: 1,
|
|
5268
|
+
5122: 2,
|
|
5269
|
+
5123: 2,
|
|
5270
|
+
5125: 4,
|
|
5271
|
+
5126: 4
|
|
5272
|
+
};
|
|
5273
|
+
GL_SAMPLER = {
|
|
5274
|
+
TEXTURE_MAG_FILTER: 10240,
|
|
5275
|
+
TEXTURE_MIN_FILTER: 10241,
|
|
5276
|
+
TEXTURE_WRAP_S: 10242,
|
|
5277
|
+
TEXTURE_WRAP_T: 10243,
|
|
5278
|
+
REPEAT: 10497,
|
|
5279
|
+
LINEAR: 9729,
|
|
5280
|
+
NEAREST_MIPMAP_LINEAR: 9986
|
|
5281
|
+
};
|
|
5282
|
+
SAMPLER_PARAMETER_GLTF_TO_GL = {
|
|
5283
|
+
magFilter: GL_SAMPLER.TEXTURE_MAG_FILTER,
|
|
5284
|
+
minFilter: GL_SAMPLER.TEXTURE_MIN_FILTER,
|
|
5285
|
+
wrapS: GL_SAMPLER.TEXTURE_WRAP_S,
|
|
5286
|
+
wrapT: GL_SAMPLER.TEXTURE_WRAP_T
|
|
5287
|
+
};
|
|
5288
|
+
DEFAULT_SAMPLER_PARAMETERS = {
|
|
5289
|
+
[GL_SAMPLER.TEXTURE_MAG_FILTER]: GL_SAMPLER.LINEAR,
|
|
5290
|
+
[GL_SAMPLER.TEXTURE_MIN_FILTER]: GL_SAMPLER.NEAREST_MIPMAP_LINEAR,
|
|
5291
|
+
[GL_SAMPLER.TEXTURE_WRAP_S]: GL_SAMPLER.REPEAT,
|
|
5292
|
+
[GL_SAMPLER.TEXTURE_WRAP_T]: GL_SAMPLER.REPEAT
|
|
5293
|
+
};
|
|
5294
|
+
GLTFPostProcessor = class {
|
|
5295
|
+
constructor() {
|
|
5296
|
+
this.baseUri = "";
|
|
5297
|
+
this.buffers = [];
|
|
5298
|
+
this.images = [];
|
|
5299
|
+
}
|
|
5300
|
+
postProcess(gltf, options = {}) {
|
|
5301
|
+
const { json, buffers = [], images = [] } = gltf;
|
|
5302
|
+
const { baseUri = "" } = gltf;
|
|
5303
|
+
assert3(json);
|
|
5304
|
+
this.baseUri = baseUri;
|
|
5305
|
+
this.buffers = buffers;
|
|
5306
|
+
this.images = images;
|
|
5307
|
+
this.jsonUnprocessed = json;
|
|
5308
|
+
this.json = this._resolveTree(gltf.json, options);
|
|
5309
|
+
return this.json;
|
|
5310
|
+
}
|
|
5311
|
+
_resolveTree(gltf, options = {}) {
|
|
5312
|
+
const json = { ...gltf };
|
|
5313
|
+
this.json = json;
|
|
5314
|
+
if (gltf.bufferViews) {
|
|
5315
|
+
json.bufferViews = gltf.bufferViews.map((bufView, i2) => this._resolveBufferView(bufView, i2));
|
|
5316
|
+
}
|
|
5317
|
+
if (gltf.images) {
|
|
5318
|
+
json.images = gltf.images.map((image, i2) => this._resolveImage(image, i2));
|
|
5319
|
+
}
|
|
5320
|
+
if (gltf.samplers) {
|
|
5321
|
+
json.samplers = gltf.samplers.map((sampler, i2) => this._resolveSampler(sampler, i2));
|
|
5322
|
+
}
|
|
5323
|
+
if (gltf.textures) {
|
|
5324
|
+
json.textures = gltf.textures.map((texture, i2) => this._resolveTexture(texture, i2));
|
|
5325
|
+
}
|
|
5326
|
+
if (gltf.accessors) {
|
|
5327
|
+
json.accessors = gltf.accessors.map((accessor, i2) => this._resolveAccessor(accessor, i2));
|
|
5328
|
+
}
|
|
5329
|
+
if (gltf.materials) {
|
|
5330
|
+
json.materials = gltf.materials.map((material, i2) => this._resolveMaterial(material, i2));
|
|
5331
|
+
}
|
|
5332
|
+
if (gltf.meshes) {
|
|
5333
|
+
json.meshes = gltf.meshes.map((mesh, i2) => this._resolveMesh(mesh, i2));
|
|
5334
|
+
}
|
|
5335
|
+
if (gltf.nodes) {
|
|
5336
|
+
json.nodes = gltf.nodes.map((node2, i2) => this._resolveNode(node2, i2));
|
|
5337
|
+
json.nodes = json.nodes.map((node2, i2) => this._resolveNodeChildren(node2));
|
|
5338
|
+
}
|
|
5339
|
+
if (gltf.skins) {
|
|
5340
|
+
json.skins = gltf.skins.map((skin, i2) => this._resolveSkin(skin, i2));
|
|
5341
|
+
}
|
|
5342
|
+
if (gltf.scenes) {
|
|
5343
|
+
json.scenes = gltf.scenes.map((scene, i2) => this._resolveScene(scene, i2));
|
|
5344
|
+
}
|
|
5345
|
+
if (typeof this.json.scene === "number" && json.scenes) {
|
|
5346
|
+
json.scene = json.scenes[this.json.scene];
|
|
5347
|
+
}
|
|
5348
|
+
return json;
|
|
5349
|
+
}
|
|
5350
|
+
getScene(index) {
|
|
5351
|
+
return this._get(this.json.scenes, index);
|
|
5352
|
+
}
|
|
5353
|
+
getNode(index) {
|
|
5354
|
+
return this._get(this.json.nodes, index);
|
|
5355
|
+
}
|
|
5356
|
+
getSkin(index) {
|
|
5357
|
+
return this._get(this.json.skins, index);
|
|
5358
|
+
}
|
|
5359
|
+
getMesh(index) {
|
|
5360
|
+
return this._get(this.json.meshes, index);
|
|
5361
|
+
}
|
|
5362
|
+
getMaterial(index) {
|
|
5363
|
+
return this._get(this.json.materials, index);
|
|
5364
|
+
}
|
|
5365
|
+
getAccessor(index) {
|
|
5366
|
+
return this._get(this.json.accessors, index);
|
|
5367
|
+
}
|
|
5368
|
+
getCamera(index) {
|
|
5369
|
+
return this._get(this.json.cameras, index);
|
|
5370
|
+
}
|
|
5371
|
+
getTexture(index) {
|
|
5372
|
+
return this._get(this.json.textures, index);
|
|
5373
|
+
}
|
|
5374
|
+
getSampler(index) {
|
|
5375
|
+
return this._get(this.json.samplers, index);
|
|
5376
|
+
}
|
|
5377
|
+
getImage(index) {
|
|
5378
|
+
return this._get(this.json.images, index);
|
|
5379
|
+
}
|
|
5380
|
+
getBufferView(index) {
|
|
5381
|
+
return this._get(this.json.bufferViews, index);
|
|
5382
|
+
}
|
|
5383
|
+
getBuffer(index) {
|
|
5384
|
+
return this._get(this.json.buffers, index);
|
|
5385
|
+
}
|
|
5386
|
+
_get(array, index) {
|
|
5387
|
+
if (typeof index === "object") {
|
|
5388
|
+
return index;
|
|
5389
|
+
}
|
|
5390
|
+
const object = array && array[index];
|
|
5391
|
+
if (!object) {
|
|
5392
|
+
console.warn(`glTF file error: Could not find ${array}[${index}]`);
|
|
5393
|
+
}
|
|
5394
|
+
return object;
|
|
5395
|
+
}
|
|
5396
|
+
_resolveScene(scene, index) {
|
|
5397
|
+
return {
|
|
5398
|
+
...scene,
|
|
5399
|
+
id: scene.id || `scene-${index}`,
|
|
5400
|
+
nodes: (scene.nodes || []).map((node2) => this.getNode(node2))
|
|
5401
|
+
};
|
|
5402
|
+
}
|
|
5403
|
+
_resolveNode(gltfNode, index) {
|
|
5404
|
+
const node2 = {
|
|
5405
|
+
...gltfNode,
|
|
5406
|
+
id: gltfNode?.id || `node-${index}`
|
|
5407
|
+
};
|
|
5408
|
+
if (gltfNode.mesh !== void 0) {
|
|
5409
|
+
node2.mesh = this.getMesh(gltfNode.mesh);
|
|
5410
|
+
}
|
|
5411
|
+
if (gltfNode.camera !== void 0) {
|
|
5412
|
+
node2.camera = this.getCamera(gltfNode.camera);
|
|
5413
|
+
}
|
|
5414
|
+
if (gltfNode.skin !== void 0) {
|
|
5415
|
+
node2.skin = this.getSkin(gltfNode.skin);
|
|
5416
|
+
}
|
|
5417
|
+
if (gltfNode.meshes !== void 0 && gltfNode.meshes.length) {
|
|
5418
|
+
node2.mesh = gltfNode.meshes.reduce((accum, meshIndex) => {
|
|
5419
|
+
const mesh = this.getMesh(meshIndex);
|
|
5420
|
+
accum.id = mesh.id;
|
|
5421
|
+
accum.primitives = accum.primitives.concat(mesh.primitives);
|
|
5422
|
+
return accum;
|
|
5423
|
+
}, { primitives: [] });
|
|
5424
|
+
}
|
|
5425
|
+
return node2;
|
|
5426
|
+
}
|
|
5427
|
+
_resolveNodeChildren(node2) {
|
|
5428
|
+
if (node2.children) {
|
|
5429
|
+
node2.children = node2.children.map((child) => this.getNode(child));
|
|
5430
|
+
}
|
|
5431
|
+
return node2;
|
|
5432
|
+
}
|
|
5433
|
+
_resolveSkin(gltfSkin, index) {
|
|
5434
|
+
const inverseBindMatrices = typeof gltfSkin.inverseBindMatrices === "number" ? this.getAccessor(gltfSkin.inverseBindMatrices) : void 0;
|
|
5435
|
+
return {
|
|
5436
|
+
...gltfSkin,
|
|
5437
|
+
id: gltfSkin.id || `skin-${index}`,
|
|
5438
|
+
inverseBindMatrices
|
|
5439
|
+
};
|
|
5440
|
+
}
|
|
5441
|
+
_resolveMesh(gltfMesh, index) {
|
|
5442
|
+
const mesh = {
|
|
5443
|
+
...gltfMesh,
|
|
5444
|
+
id: gltfMesh.id || `mesh-${index}`,
|
|
5445
|
+
primitives: []
|
|
5446
|
+
};
|
|
5447
|
+
if (gltfMesh.primitives) {
|
|
5448
|
+
mesh.primitives = gltfMesh.primitives.map((gltfPrimitive) => {
|
|
5449
|
+
const primitive = {
|
|
5450
|
+
...gltfPrimitive,
|
|
5451
|
+
attributes: {},
|
|
5452
|
+
indices: void 0,
|
|
5453
|
+
material: void 0
|
|
5454
|
+
};
|
|
5455
|
+
const attributes = gltfPrimitive.attributes;
|
|
5456
|
+
for (const attribute in attributes) {
|
|
5457
|
+
primitive.attributes[attribute] = this.getAccessor(attributes[attribute]);
|
|
5458
|
+
}
|
|
5459
|
+
if (gltfPrimitive.indices !== void 0) {
|
|
5460
|
+
primitive.indices = this.getAccessor(gltfPrimitive.indices);
|
|
5461
|
+
}
|
|
5462
|
+
if (gltfPrimitive.material !== void 0) {
|
|
5463
|
+
primitive.material = this.getMaterial(gltfPrimitive.material);
|
|
5464
|
+
}
|
|
5465
|
+
return primitive;
|
|
5466
|
+
});
|
|
5467
|
+
}
|
|
5468
|
+
return mesh;
|
|
5469
|
+
}
|
|
5470
|
+
_resolveMaterial(gltfMaterial, index) {
|
|
5471
|
+
const material = {
|
|
5472
|
+
...gltfMaterial,
|
|
5473
|
+
id: gltfMaterial.id || `material-${index}`
|
|
5474
|
+
};
|
|
5475
|
+
if (material.normalTexture) {
|
|
5476
|
+
material.normalTexture = { ...material.normalTexture };
|
|
5477
|
+
material.normalTexture.texture = this.getTexture(material.normalTexture.index);
|
|
5478
|
+
}
|
|
5479
|
+
if (material.occlusionTexture) {
|
|
5480
|
+
material.occlusionTexture = { ...material.occlusionTexture };
|
|
5481
|
+
material.occlusionTexture.texture = this.getTexture(material.occlusionTexture.index);
|
|
5482
|
+
}
|
|
5483
|
+
if (material.emissiveTexture) {
|
|
5484
|
+
material.emissiveTexture = { ...material.emissiveTexture };
|
|
5485
|
+
material.emissiveTexture.texture = this.getTexture(material.emissiveTexture.index);
|
|
5486
|
+
}
|
|
5487
|
+
if (!material.emissiveFactor) {
|
|
5488
|
+
material.emissiveFactor = material.emissiveTexture ? [1, 1, 1] : [0, 0, 0];
|
|
5489
|
+
}
|
|
5490
|
+
if (material.pbrMetallicRoughness) {
|
|
5491
|
+
material.pbrMetallicRoughness = { ...material.pbrMetallicRoughness };
|
|
5492
|
+
const mr = material.pbrMetallicRoughness;
|
|
5493
|
+
if (mr.baseColorTexture) {
|
|
5494
|
+
mr.baseColorTexture = { ...mr.baseColorTexture };
|
|
5495
|
+
mr.baseColorTexture.texture = this.getTexture(mr.baseColorTexture.index);
|
|
5496
|
+
}
|
|
5497
|
+
if (mr.metallicRoughnessTexture) {
|
|
5498
|
+
mr.metallicRoughnessTexture = { ...mr.metallicRoughnessTexture };
|
|
5499
|
+
mr.metallicRoughnessTexture.texture = this.getTexture(mr.metallicRoughnessTexture.index);
|
|
5500
|
+
}
|
|
5501
|
+
}
|
|
5502
|
+
return material;
|
|
5503
|
+
}
|
|
5504
|
+
_resolveAccessor(gltfAccessor, index) {
|
|
5505
|
+
const bytesPerComponent = getBytesFromComponentType(gltfAccessor.componentType);
|
|
5506
|
+
const components = getSizeFromAccessorType(gltfAccessor.type);
|
|
5507
|
+
const bytesPerElement = bytesPerComponent * components;
|
|
5508
|
+
const accessor = {
|
|
5509
|
+
...gltfAccessor,
|
|
5510
|
+
id: gltfAccessor.id || `accessor-${index}`,
|
|
5511
|
+
bytesPerComponent,
|
|
5512
|
+
components,
|
|
5513
|
+
bytesPerElement,
|
|
5514
|
+
value: void 0,
|
|
5515
|
+
bufferView: void 0,
|
|
5516
|
+
sparse: void 0
|
|
5517
|
+
};
|
|
5518
|
+
if (gltfAccessor.bufferView !== void 0) {
|
|
5519
|
+
accessor.bufferView = this.getBufferView(gltfAccessor.bufferView);
|
|
5520
|
+
}
|
|
5521
|
+
if (accessor.bufferView) {
|
|
5522
|
+
const buffer = accessor.bufferView.buffer;
|
|
5523
|
+
const { ArrayType, byteLength } = getAccessorArrayTypeAndLength(accessor, accessor.bufferView);
|
|
5524
|
+
const byteOffset = (accessor.bufferView.byteOffset || 0) + (accessor.byteOffset || 0) + buffer.byteOffset;
|
|
5525
|
+
let cutBuffer = buffer.arrayBuffer.slice(byteOffset, byteOffset + byteLength);
|
|
5526
|
+
if (accessor.bufferView.byteStride) {
|
|
5527
|
+
cutBuffer = this._getValueFromInterleavedBuffer(buffer, byteOffset, accessor.bufferView.byteStride, accessor.bytesPerElement, accessor.count);
|
|
5528
|
+
}
|
|
5529
|
+
accessor.value = new ArrayType(cutBuffer);
|
|
5530
|
+
}
|
|
5531
|
+
return accessor;
|
|
5532
|
+
}
|
|
5533
|
+
_getValueFromInterleavedBuffer(buffer, byteOffset, byteStride, bytesPerElement, count) {
|
|
5534
|
+
const result = new Uint8Array(count * bytesPerElement);
|
|
5535
|
+
for (let i2 = 0; i2 < count; i2++) {
|
|
5536
|
+
const elementOffset = byteOffset + i2 * byteStride;
|
|
5537
|
+
result.set(new Uint8Array(buffer.arrayBuffer.slice(elementOffset, elementOffset + bytesPerElement)), i2 * bytesPerElement);
|
|
5538
|
+
}
|
|
5539
|
+
return result.buffer;
|
|
5540
|
+
}
|
|
5541
|
+
_resolveTexture(gltfTexture, index) {
|
|
5542
|
+
return {
|
|
5543
|
+
...gltfTexture,
|
|
5544
|
+
id: gltfTexture.id || `texture-${index}`,
|
|
5545
|
+
sampler: typeof gltfTexture.sampler === "number" ? this.getSampler(gltfTexture.sampler) : makeDefaultSampler(),
|
|
5546
|
+
source: typeof gltfTexture.source === "number" ? this.getImage(gltfTexture.source) : void 0
|
|
5547
|
+
};
|
|
5548
|
+
}
|
|
5549
|
+
_resolveSampler(gltfSampler, index) {
|
|
5550
|
+
const sampler = {
|
|
5551
|
+
id: gltfSampler.id || `sampler-${index}`,
|
|
5552
|
+
...gltfSampler,
|
|
5553
|
+
parameters: {}
|
|
5554
|
+
};
|
|
5555
|
+
for (const key in sampler) {
|
|
5556
|
+
const glEnum = this._enumSamplerParameter(key);
|
|
5557
|
+
if (glEnum !== void 0) {
|
|
5558
|
+
sampler.parameters[glEnum] = sampler[key];
|
|
5559
|
+
}
|
|
5560
|
+
}
|
|
5561
|
+
return sampler;
|
|
5562
|
+
}
|
|
5563
|
+
_enumSamplerParameter(key) {
|
|
5564
|
+
return SAMPLER_PARAMETER_GLTF_TO_GL[key];
|
|
5565
|
+
}
|
|
5566
|
+
_resolveImage(gltfImage, index) {
|
|
5567
|
+
const image = {
|
|
5568
|
+
...gltfImage,
|
|
5569
|
+
id: gltfImage.id || `image-${index}`,
|
|
5570
|
+
image: null,
|
|
5571
|
+
bufferView: gltfImage.bufferView !== void 0 ? this.getBufferView(gltfImage.bufferView) : void 0
|
|
5572
|
+
};
|
|
5573
|
+
const preloadedImage = this.images[index];
|
|
5574
|
+
if (preloadedImage) {
|
|
5575
|
+
image.image = preloadedImage;
|
|
5576
|
+
}
|
|
5577
|
+
return image;
|
|
5578
|
+
}
|
|
5579
|
+
_resolveBufferView(gltfBufferView, index) {
|
|
5580
|
+
const bufferIndex = gltfBufferView.buffer;
|
|
5581
|
+
const arrayBuffer = this.buffers[bufferIndex].arrayBuffer;
|
|
5582
|
+
let byteOffset = this.buffers[bufferIndex].byteOffset || 0;
|
|
5583
|
+
if (gltfBufferView.byteOffset) {
|
|
5584
|
+
byteOffset += gltfBufferView.byteOffset;
|
|
5585
|
+
}
|
|
5586
|
+
const bufferView = {
|
|
5587
|
+
id: `bufferView-${index}`,
|
|
5588
|
+
...gltfBufferView,
|
|
5589
|
+
buffer: this.buffers[bufferIndex],
|
|
5590
|
+
data: new Uint8Array(arrayBuffer, byteOffset, gltfBufferView.byteLength)
|
|
5591
|
+
};
|
|
5592
|
+
return bufferView;
|
|
5593
|
+
}
|
|
5594
|
+
_resolveCamera(gltfCamera, index) {
|
|
5595
|
+
const camera = {
|
|
5596
|
+
...gltfCamera,
|
|
5597
|
+
id: gltfCamera.id || `camera-${index}`
|
|
5598
|
+
};
|
|
5599
|
+
if (camera.perspective) {
|
|
5600
|
+
}
|
|
5601
|
+
if (camera.orthographic) {
|
|
5602
|
+
}
|
|
5603
|
+
return camera;
|
|
5604
|
+
}
|
|
5605
|
+
};
|
|
5606
|
+
}
|
|
5607
|
+
});
|
|
5608
|
+
|
|
5535
5609
|
// src/index.ts
|
|
5536
5610
|
var src_exports = {};
|
|
5537
5611
|
__export(src_exports, {
|
|
@@ -5540,6 +5614,7 @@
|
|
|
5540
5614
|
GLTFLoader: () => GLTFLoader,
|
|
5541
5615
|
GLTFScenegraph: () => GLTFScenegraph,
|
|
5542
5616
|
GLTFWriter: () => GLTFWriter,
|
|
5617
|
+
_getMemoryUsageGLTF: () => getMemoryUsageGLTF,
|
|
5543
5618
|
postProcessGLTF: () => postProcessGLTF
|
|
5544
5619
|
});
|
|
5545
5620
|
var init_src7 = __esm({
|
|
@@ -5550,6 +5625,7 @@
|
|
|
5550
5625
|
init_glb_writer();
|
|
5551
5626
|
init_gltf_scenegraph();
|
|
5552
5627
|
init_post_process_gltf();
|
|
5628
|
+
init_gltf_utils();
|
|
5553
5629
|
}
|
|
5554
5630
|
});
|
|
5555
5631
|
|