@threepipe/plugin-gltf-transform 0.1.2 → 0.1.3

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/index.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * @license
3
- * @threepipe/plugin-gltf-transform v0.1.2
3
+ * @threepipe/plugin-gltf-transform v0.1.3
4
4
  * Copyright 2022-2025 repalash <palash@shaders.app>
5
5
  * Apache-2.0 License
6
6
  * See ./dependencies.txt for any bundled third-party dependencies and licenses.
@@ -4704,7 +4704,7 @@ class GLTFDracoExporter extends GLTFExporter2 {
4704
4704
  });
4705
4705
  this._loadedLibs = true;
4706
4706
  }
4707
- async parseAsync(obj, { compress = false, dracoOptions, ...options }) {
4707
+ async parseAsync(obj, { compress = false, dracoOptions, ...options }, throwOnError = false) {
4708
4708
  if (!this.loader) {
4709
4709
  console.error("GLTFDracoExporter: No DRACOLoader2 instance provided");
4710
4710
  return super.parseAsync(obj, options);
@@ -4717,33 +4717,40 @@ class GLTFDracoExporter extends GLTFExporter2 {
4717
4717
  const uncompressed = await new Promise((resolve, reject) => this.parse(obj, resolve, reject, ops));
4718
4718
  const uncompressedBlob = await super.parseAsync(uncompressed, ops);
4719
4719
  if (!compress) return uncompressedBlob;
4720
- if (!uncompressed) throw new Error("GLTFDracoExporter: gltf is null");
4721
- let gltf = uncompressed;
4722
- const bytes = gltf.byteLength || Infinity;
4723
- const iDocument = await (typeof gltf === "object" && !gltf.byteLength ? this._io.readJSON({
4724
- json: gltf,
4725
- resources: {}
4726
- }) : this._io.readBinary(new Uint8Array(gltf)));
4727
- iDocument.createExtension(le).setRequired(true).setEncoderOptions({ ...this._encoderOptions, ...dracoOptions ?? {} });
4728
- if (ops.exportExt === "glb") {
4729
- gltf = await this._io.writeBinary(iDocument);
4730
- if (isFinite(bytes)) {
4731
- console.log("DRACO Compression ratio: " + (gltf.byteLength / bytes).toFixed(5));
4732
- }
4733
- } else {
4734
- const jDoc = await this._io.writeJSON(iDocument);
4735
- gltf = jDoc.json;
4736
- if (Object.values(jDoc.resources).filter((v2) => v2).length > 0) {
4737
- console.warn("DRACOExporter: extra resources in resources not supported properly");
4738
- gltf.resources = jDoc.resources;
4720
+ try {
4721
+ if (!uncompressed) throw new Error("GLTFDracoExporter: gltf is null");
4722
+ let gltf = uncompressed;
4723
+ const bytes = gltf.byteLength || Infinity;
4724
+ const iDocument = await (typeof gltf === "object" && !gltf.byteLength ? this._io.readJSON({
4725
+ json: gltf,
4726
+ resources: {}
4727
+ }) : this._io.readBinary(new Uint8Array(gltf)));
4728
+ iDocument.createExtension(le).setRequired(true).setEncoderOptions({ ...this._encoderOptions, ...dracoOptions ?? {} });
4729
+ if (ops.exportExt === "glb") {
4730
+ gltf = await this._io.writeBinary(iDocument);
4731
+ if (isFinite(bytes)) {
4732
+ console.log("DRACO Compression ratio: " + (gltf.byteLength / bytes).toFixed(5));
4733
+ }
4734
+ } else {
4735
+ const jDoc = await this._io.writeJSON(iDocument);
4736
+ gltf = jDoc.json;
4737
+ if (Object.values(jDoc.resources).filter((v2) => v2).length > 0) {
4738
+ console.warn("DRACOExporter: extra resources in resources not supported properly");
4739
+ gltf.resources = jDoc.resources;
4740
+ }
4739
4741
  }
4742
+ gltf.__isGLTFOutput = true;
4743
+ const blob = await super.parseAsync(gltf, ops);
4744
+ if (!blob) throw new Error("GLTFDracoExporter: blob is null");
4745
+ blob.ext = "glb";
4746
+ blob.__uncompressed = uncompressedBlob;
4747
+ return blob;
4748
+ } catch (e) {
4749
+ if (throwOnError) throw e;
4750
+ console.error("Unable to compress glb with DRACO extension, fallback to uncompressed");
4751
+ console.error(e);
4752
+ return uncompressedBlob;
4740
4753
  }
4741
- gltf.__isGLTFOutput = true;
4742
- const blob = await super.parseAsync(gltf, ops);
4743
- if (!blob) throw new Error("GLTFDracoExporter: blob is null");
4744
- blob.ext = "glb";
4745
- blob.__uncompressed = uncompressedBlob;
4746
- return blob;
4747
4754
  }
4748
4755
  addExtension(extension) {
4749
4756
  this._io.registerExtensions([extension]);