@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/GLTFDracoExporter.d.ts +1 -1
- package/dist/GLTFDracoExporter.d.ts.map +1 -1
- package/dist/index.js +34 -27
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +34 -27
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -1
- package/src/GLTFDracoExporter.ts +37 -30
|
@@ -17,7 +17,7 @@ export declare class GLTFDracoExporter extends GLTFExporter2 implements IExportP
|
|
|
17
17
|
parseAsync(obj: any, { compress, dracoOptions, ...options }: {
|
|
18
18
|
compress: boolean;
|
|
19
19
|
dracoOptions?: EncoderOptions;
|
|
20
|
-
} & GLTFExporter2Options): Promise<Blob>;
|
|
20
|
+
} & GLTFExporter2Options, throwOnError?: boolean): Promise<Blob>;
|
|
21
21
|
addExtension(extension: typeof Extension): this;
|
|
22
22
|
createAndAddExtension(name: string, textures?: Record<string, string | number>): this;
|
|
23
23
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GLTFDracoExporter.d.ts","sourceRoot":"","sources":["../src/GLTFDracoExporter.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,SAAS,EAMT,aAAa,EAKb,aAAa,EAChB,MAAM,sBAAsB,CAAA;AAC7B,OAAO,EAAC,cAAc,EAAC,MAAM,oEAAoE,CAAA;AAEjG,OAAO,EAAC,YAAY,EAAE,aAAa,EAAE,oBAAoB,EAA6B,aAAa,EAAC,MAAM,WAAW,CAAA;AAErH;;;;GAIG;AACH,qBAAa,iBAAkB,SAAQ,aAAc,YAAW,aAAa;IAClE,MAAM,CAAC,EAAE,YAAY,CAAA;IAC5B,OAAO,CAAC,GAAG,CAAO;IAClB,OAAO,CAAC,WAAW,CAAQ;IAC3B,OAAO,CAAC,eAAe,CAAgB;gBAE3B,cAAc,CAAC,EAAE,cAAc,EAAE,MAAM,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AM,CAAC,MAAM,EAAE,MAAM,GAAC,MAAM,CAAC,GAAG,IAAI;CAGtF;AAED,OAAO,QAAQ,WAAW,CAAA;IACtB,UAAU,oBAAoB;QAC1B,QAAQ,CAAC,EAAE,OAAO,CAAA;QAClB,YAAY,CAAC,EAAE,cAAc,CAAA;KAChC;CACJ;AAoHD,uBAAe,gBAAiB,SAAQ,SAAS;IAC7C,QAAQ,CAAC,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAA;IAEvC,eAAe,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAK;IAE5C,IAAI,CAAC,OAAO,EAAE,aAAa,GAAG,IAAI;IAkElC,KAAK,CAAC,OAAO,EAAE,aAAa,GAAG,IAAI;CAqEtC;AAWD,wBAAgB,2BAA2B,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAC,MAAM,CAAC,GAAG,OAAO,gBAAgB,CAU3H"}
|
package/dist/index.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
})(this, function(exports2, threepipe) {
|
|
4
4
|
"use strict";/**
|
|
5
5
|
* @license
|
|
6
|
-
* @threepipe/plugin-gltf-transform v0.1.
|
|
6
|
+
* @threepipe/plugin-gltf-transform v0.1.3
|
|
7
7
|
* Copyright 2022-2025 repalash <palash@shaders.app>
|
|
8
8
|
* Apache-2.0 License
|
|
9
9
|
* See ./dependencies.txt for any bundled third-party dependencies and licenses.
|
|
@@ -4707,7 +4707,7 @@
|
|
|
4707
4707
|
});
|
|
4708
4708
|
this._loadedLibs = true;
|
|
4709
4709
|
}
|
|
4710
|
-
async parseAsync(obj, { compress = false, dracoOptions, ...options }) {
|
|
4710
|
+
async parseAsync(obj, { compress = false, dracoOptions, ...options }, throwOnError = false) {
|
|
4711
4711
|
if (!this.loader) {
|
|
4712
4712
|
console.error("GLTFDracoExporter: No DRACOLoader2 instance provided");
|
|
4713
4713
|
return super.parseAsync(obj, options);
|
|
@@ -4720,33 +4720,40 @@
|
|
|
4720
4720
|
const uncompressed = await new Promise((resolve, reject) => this.parse(obj, resolve, reject, ops));
|
|
4721
4721
|
const uncompressedBlob = await super.parseAsync(uncompressed, ops);
|
|
4722
4722
|
if (!compress) return uncompressedBlob;
|
|
4723
|
-
|
|
4724
|
-
|
|
4725
|
-
|
|
4726
|
-
|
|
4727
|
-
|
|
4728
|
-
|
|
4729
|
-
|
|
4730
|
-
|
|
4731
|
-
|
|
4732
|
-
|
|
4733
|
-
|
|
4734
|
-
|
|
4735
|
-
|
|
4736
|
-
|
|
4737
|
-
|
|
4738
|
-
|
|
4739
|
-
|
|
4740
|
-
|
|
4741
|
-
|
|
4723
|
+
try {
|
|
4724
|
+
if (!uncompressed) throw new Error("GLTFDracoExporter: gltf is null");
|
|
4725
|
+
let gltf = uncompressed;
|
|
4726
|
+
const bytes = gltf.byteLength || Infinity;
|
|
4727
|
+
const iDocument = await (typeof gltf === "object" && !gltf.byteLength ? this._io.readJSON({
|
|
4728
|
+
json: gltf,
|
|
4729
|
+
resources: {}
|
|
4730
|
+
}) : this._io.readBinary(new Uint8Array(gltf)));
|
|
4731
|
+
iDocument.createExtension(le).setRequired(true).setEncoderOptions({ ...this._encoderOptions, ...dracoOptions ?? {} });
|
|
4732
|
+
if (ops.exportExt === "glb") {
|
|
4733
|
+
gltf = await this._io.writeBinary(iDocument);
|
|
4734
|
+
if (isFinite(bytes)) {
|
|
4735
|
+
console.log("DRACO Compression ratio: " + (gltf.byteLength / bytes).toFixed(5));
|
|
4736
|
+
}
|
|
4737
|
+
} else {
|
|
4738
|
+
const jDoc = await this._io.writeJSON(iDocument);
|
|
4739
|
+
gltf = jDoc.json;
|
|
4740
|
+
if (Object.values(jDoc.resources).filter((v2) => v2).length > 0) {
|
|
4741
|
+
console.warn("DRACOExporter: extra resources in resources not supported properly");
|
|
4742
|
+
gltf.resources = jDoc.resources;
|
|
4743
|
+
}
|
|
4742
4744
|
}
|
|
4745
|
+
gltf.__isGLTFOutput = true;
|
|
4746
|
+
const blob = await super.parseAsync(gltf, ops);
|
|
4747
|
+
if (!blob) throw new Error("GLTFDracoExporter: blob is null");
|
|
4748
|
+
blob.ext = "glb";
|
|
4749
|
+
blob.__uncompressed = uncompressedBlob;
|
|
4750
|
+
return blob;
|
|
4751
|
+
} catch (e) {
|
|
4752
|
+
if (throwOnError) throw e;
|
|
4753
|
+
console.error("Unable to compress glb with DRACO extension, fallback to uncompressed");
|
|
4754
|
+
console.error(e);
|
|
4755
|
+
return uncompressedBlob;
|
|
4743
4756
|
}
|
|
4744
|
-
gltf.__isGLTFOutput = true;
|
|
4745
|
-
const blob = await super.parseAsync(gltf, ops);
|
|
4746
|
-
if (!blob) throw new Error("GLTFDracoExporter: blob is null");
|
|
4747
|
-
blob.ext = "glb";
|
|
4748
|
-
blob.__uncompressed = uncompressedBlob;
|
|
4749
|
-
return blob;
|
|
4750
4757
|
}
|
|
4751
4758
|
addExtension(extension) {
|
|
4752
4759
|
this._io.registerExtensions([extension]);
|