minidraco 0.1.0 → 0.1.1
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/README.md +7 -0
- package/dist/three.d.ts +4 -1
- package/dist/three.js +38 -1
- package/package.json +6 -1
package/README.md
CHANGED
|
@@ -26,6 +26,13 @@ no-ops). Decoding runs in a pool of module workers (default 4, `setWorkerLimit(n
|
|
|
26
26
|
`0` to force synchronous main-thread decoding). If workers can't be spawned (SSR, exotic
|
|
27
27
|
bundlers), it falls back to synchronous decoding automatically.
|
|
28
28
|
|
|
29
|
+
**Serving JS from a CDN origin** (Next.js `assetPrefix`, etc.) works out of the box: browsers
|
|
30
|
+
refuse to construct a Worker from a cross-origin script, so minidraco bootstraps the worker
|
|
31
|
+
through a same-origin blob module that imports the hashed CDN asset (a CORS request — your CDN
|
|
32
|
+
must send `Access-Control-Allow-Origin`, which it already does if you load models or fonts from
|
|
33
|
+
it). If even that fails, decoding falls back to the main thread rather than erroring.
|
|
34
|
+
`setWorkerUrl(url)` exists as a manual override for exotic setups.
|
|
35
|
+
|
|
29
36
|
Or decode a raw Draco bitstream without Three.js:
|
|
30
37
|
|
|
31
38
|
```ts
|
package/dist/three.d.ts
CHANGED
|
@@ -154,7 +154,10 @@ declare class MiniDRACOLoader extends Loader<BufferGeometry> {
|
|
|
154
154
|
entry: WorkerEntry;
|
|
155
155
|
}>;
|
|
156
156
|
_workersBroken: boolean;
|
|
157
|
+
_workerUrl: string | URL | null;
|
|
158
|
+
_workerBlobUrl: string | null;
|
|
157
159
|
constructor(manager?: LoadingManager);
|
|
160
|
+
setWorkerUrl(url: string | URL | null): this;
|
|
158
161
|
setDecoderPath(_path?: string): this;
|
|
159
162
|
setDecoderConfig(_config?: object): this;
|
|
160
163
|
setWorkerLimit(limit: number): this;
|
|
@@ -166,7 +169,7 @@ declare class MiniDRACOLoader extends Loader<BufferGeometry> {
|
|
|
166
169
|
decodeGeometry(buffer: ArrayBuffer, taskConfig: TaskConfig): Promise<BufferGeometry>;
|
|
167
170
|
_runTask(buffer: ArrayBuffer, taskConfig: TaskConfig): Promise<BufferGeometry>;
|
|
168
171
|
_workersAvailable(): boolean;
|
|
169
|
-
_getWorker(): WorkerEntry;
|
|
172
|
+
_getWorker(): WorkerEntry | null;
|
|
170
173
|
_decodeInWorker(buffer: ArrayBuffer, taskConfig: TaskConfig): Promise<RawGeometry>;
|
|
171
174
|
_buildGeometryFromRaw(raw: RawGeometry, taskConfig: TaskConfig): BufferGeometry;
|
|
172
175
|
_decodeBuffer(buffer: ArrayBuffer, taskConfig: TaskConfig): BufferGeometry;
|
package/dist/three.js
CHANGED
|
@@ -6714,6 +6714,10 @@ var MiniDRACOLoader = class extends Loader {
|
|
|
6714
6714
|
// Set when spawning a worker fails (bundler without module-worker support,
|
|
6715
6715
|
// file:// pages, …): decoding transparently falls back to the main thread.
|
|
6716
6716
|
_workersBroken;
|
|
6717
|
+
_workerUrl;
|
|
6718
|
+
// Same-origin blob bootstrap used when the worker asset lives on a CDN
|
|
6719
|
+
// origin (created lazily, revoked on dispose).
|
|
6720
|
+
_workerBlobUrl;
|
|
6717
6721
|
constructor(manager) {
|
|
6718
6722
|
super(manager);
|
|
6719
6723
|
this.defaultAttributeIDs = {
|
|
@@ -6733,6 +6737,16 @@ var MiniDRACOLoader = class extends Loader {
|
|
|
6733
6737
|
this._taskId = 0;
|
|
6734
6738
|
this._tasks = /* @__PURE__ */ new Map();
|
|
6735
6739
|
this._workersBroken = false;
|
|
6740
|
+
this._workerUrl = null;
|
|
6741
|
+
this._workerBlobUrl = null;
|
|
6742
|
+
}
|
|
6743
|
+
// Overrides where the decode worker is loaded from. Normally unnecessary:
|
|
6744
|
+
// the worker resolves through `new URL('./worker.js', import.meta.url)`
|
|
6745
|
+
// (bundlers emit it as a hashed asset), and CDN origins are handled by the
|
|
6746
|
+
// blob bootstrap in _getWorker.
|
|
6747
|
+
setWorkerUrl(url) {
|
|
6748
|
+
this._workerUrl = url;
|
|
6749
|
+
return this;
|
|
6736
6750
|
}
|
|
6737
6751
|
// Kept for API compatibility with THREE.DRACOLoader — minidraco has no
|
|
6738
6752
|
// external decoder files to configure.
|
|
@@ -6754,6 +6768,10 @@ var MiniDRACOLoader = class extends Loader {
|
|
|
6754
6768
|
for (const entry of this._workers) entry.worker.terminate();
|
|
6755
6769
|
this._workers = [];
|
|
6756
6770
|
this._tasks.clear();
|
|
6771
|
+
if (this._workerBlobUrl !== null) {
|
|
6772
|
+
URL.revokeObjectURL(this._workerBlobUrl);
|
|
6773
|
+
this._workerBlobUrl = null;
|
|
6774
|
+
}
|
|
6757
6775
|
return this;
|
|
6758
6776
|
}
|
|
6759
6777
|
load(url, onLoad, onProgress, onError) {
|
|
@@ -6817,8 +6835,24 @@ var MiniDRACOLoader = class extends Loader {
|
|
|
6817
6835
|
return this.workerLimit > 0 && typeof Worker !== "undefined" && !this._workersBroken;
|
|
6818
6836
|
}
|
|
6819
6837
|
_getWorker() {
|
|
6838
|
+
if (this._workersBroken) return null;
|
|
6820
6839
|
if (this._workers.length < this.workerLimit) {
|
|
6821
|
-
const
|
|
6840
|
+
const workerUrl = this._workerUrl ?? new URL("./worker.js", import.meta.url);
|
|
6841
|
+
let worker;
|
|
6842
|
+
try {
|
|
6843
|
+
worker = new Worker(workerUrl, { type: "module" });
|
|
6844
|
+
} catch {
|
|
6845
|
+
try {
|
|
6846
|
+
if (this._workerBlobUrl === null) {
|
|
6847
|
+
const bootstrap = `import ${JSON.stringify(String(workerUrl))};`;
|
|
6848
|
+
this._workerBlobUrl = URL.createObjectURL(new Blob([bootstrap], { type: "text/javascript" }));
|
|
6849
|
+
}
|
|
6850
|
+
worker = new Worker(this._workerBlobUrl, { type: "module" });
|
|
6851
|
+
} catch {
|
|
6852
|
+
this._workersBroken = true;
|
|
6853
|
+
return null;
|
|
6854
|
+
}
|
|
6855
|
+
}
|
|
6822
6856
|
const entry = { worker, pending: 0 };
|
|
6823
6857
|
worker.onmessage = (event) => {
|
|
6824
6858
|
const { id, ok, indices, attributes, error } = event.data;
|
|
@@ -6852,6 +6886,9 @@ var MiniDRACOLoader = class extends Loader {
|
|
|
6852
6886
|
}
|
|
6853
6887
|
_decodeInWorker(buffer, taskConfig) {
|
|
6854
6888
|
const entry = this._getWorker();
|
|
6889
|
+
if (entry === null) {
|
|
6890
|
+
return Promise.reject(new Error("MiniDRACOLoader: worker unavailable"));
|
|
6891
|
+
}
|
|
6855
6892
|
const id = this._taskId++;
|
|
6856
6893
|
return new Promise((resolve, reject) => {
|
|
6857
6894
|
this._tasks.set(id, { resolve, reject, entry });
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "minidraco",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"description": "A fast pure-TypeScript Draco mesh decoder, drop-in DRACOLoader replacement for Three.js.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"files": [
|
|
@@ -33,5 +33,10 @@
|
|
|
33
33
|
},
|
|
34
34
|
"peerDependencies": {
|
|
35
35
|
"three": ">=0.170"
|
|
36
|
+
},
|
|
37
|
+
"peerDependenciesMeta": {
|
|
38
|
+
"three": {
|
|
39
|
+
"optional": true
|
|
40
|
+
}
|
|
36
41
|
}
|
|
37
42
|
}
|