minidraco 0.7.0 → 0.9.0
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 +5 -5
- package/dist/index.d.ts +6 -4
- package/dist/index.js +1608 -1625
- package/dist/pool.js +36 -36
- package/dist/three.d.ts +6 -4
- package/dist/three.js +1636 -1653
- package/dist/worker.js +1608 -1625
- package/package.json +1 -1
package/dist/pool.js
CHANGED
|
@@ -7,70 +7,70 @@ var decodeError = (message) => {
|
|
|
7
7
|
var WorkerPool = class {
|
|
8
8
|
// Pool size; the loader keeps it in sync with setWorkerLimit().
|
|
9
9
|
limit;
|
|
10
|
-
|
|
10
|
+
Ga;
|
|
11
11
|
D = [];
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
Ec = 0;
|
|
13
|
+
da = /* @__PURE__ */ new Map();
|
|
14
14
|
// Tasks queued during the current microtask; flushed as one batched message
|
|
15
15
|
// per worker (a 488-primitive scene costs 4 postMessages, not 488).
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
Ha = [];
|
|
17
|
+
Ya = false;
|
|
18
18
|
// Set when spawning a worker fails (bundler without module-worker support,
|
|
19
19
|
// file:// pages, …) or a worker errors: the loader then decodes on the main
|
|
20
20
|
// thread.
|
|
21
21
|
broken = false;
|
|
22
22
|
// Same-origin blob bootstrap used when the worker asset lives on a CDN
|
|
23
23
|
// origin (created lazily, revoked on dispose).
|
|
24
|
-
|
|
24
|
+
oa = null;
|
|
25
25
|
constructor(limit, workerUrl) {
|
|
26
26
|
this.limit = limit;
|
|
27
|
-
this.
|
|
27
|
+
this.Ga = workerUrl;
|
|
28
28
|
}
|
|
29
29
|
// Spawns the whole pool up front: each fresh worker runs a short JIT warmup
|
|
30
30
|
// at startup (see worker.ts), so spawning early lets that overlap the model
|
|
31
31
|
// download instead of the first decode burst.
|
|
32
32
|
spawnAll() {
|
|
33
|
-
while (this.D.length < this.limit && this.
|
|
33
|
+
while (this.D.length < this.limit && this.ac() !== null) {
|
|
34
34
|
}
|
|
35
35
|
}
|
|
36
36
|
dispose() {
|
|
37
37
|
for (const entry of this.D) entry.worker.terminate();
|
|
38
38
|
this.D = [];
|
|
39
39
|
const error = decodeError("MinidracoLoader: disposed while decoding");
|
|
40
|
-
for (const task of this.
|
|
41
|
-
this.
|
|
42
|
-
this.
|
|
43
|
-
for (const [, task] of this.
|
|
44
|
-
this.
|
|
45
|
-
if (this.
|
|
46
|
-
URL.revokeObjectURL(this.
|
|
47
|
-
this.
|
|
40
|
+
for (const task of this.Ha) task.reject(error);
|
|
41
|
+
this.Ha = [];
|
|
42
|
+
this.Ya = false;
|
|
43
|
+
for (const [, task] of this.da) task.reject(error);
|
|
44
|
+
this.da.clear();
|
|
45
|
+
if (this.oa !== null) {
|
|
46
|
+
URL.revokeObjectURL(this.oa);
|
|
47
|
+
this.oa = null;
|
|
48
48
|
}
|
|
49
49
|
}
|
|
50
50
|
decode(buffer, taskConfig) {
|
|
51
|
-
const id = this.
|
|
51
|
+
const id = this.Ec++;
|
|
52
52
|
return new Promise((resolve, reject) => {
|
|
53
|
-
this.
|
|
54
|
-
if (!this.
|
|
55
|
-
this.
|
|
56
|
-
queueMicrotask(() => this.
|
|
53
|
+
this.Ha.push({ id, buffer, taskConfig, resolve, reject });
|
|
54
|
+
if (!this.Ya) {
|
|
55
|
+
this.Ya = true;
|
|
56
|
+
queueMicrotask(() => this.Fc());
|
|
57
57
|
}
|
|
58
58
|
});
|
|
59
59
|
}
|
|
60
|
-
|
|
60
|
+
ac() {
|
|
61
61
|
if (this.broken) return null;
|
|
62
62
|
if (this.D.length < this.limit) {
|
|
63
|
-
const workerUrl = this.
|
|
63
|
+
const workerUrl = this.Ga ?? new URL("./worker.js", import.meta.url);
|
|
64
64
|
let worker;
|
|
65
65
|
try {
|
|
66
66
|
worker = new Worker(workerUrl, { type: "module" });
|
|
67
67
|
} catch {
|
|
68
68
|
try {
|
|
69
|
-
if (this.
|
|
69
|
+
if (this.oa === null) {
|
|
70
70
|
const bootstrap = `import ${JSON.stringify(String(workerUrl))};`;
|
|
71
|
-
this.
|
|
71
|
+
this.oa = URL.createObjectURL(new Blob([bootstrap], { type: "text/javascript" }));
|
|
72
72
|
}
|
|
73
|
-
worker = new Worker(this.
|
|
73
|
+
worker = new Worker(this.oa, { type: "module" });
|
|
74
74
|
} catch {
|
|
75
75
|
this.broken = true;
|
|
76
76
|
return null;
|
|
@@ -79,9 +79,9 @@ var WorkerPool = class {
|
|
|
79
79
|
const entry = { worker, pending: 0 };
|
|
80
80
|
worker.onmessage = (event) => {
|
|
81
81
|
for (const { id, ok, indices, attributes, error } of event.data.results) {
|
|
82
|
-
const task = this.
|
|
82
|
+
const task = this.da.get(id);
|
|
83
83
|
if (!task) continue;
|
|
84
|
-
this.
|
|
84
|
+
this.da.delete(id);
|
|
85
85
|
task.entry.pending--;
|
|
86
86
|
if (ok) {
|
|
87
87
|
task.resolve({ indices, attributes });
|
|
@@ -92,9 +92,9 @@ var WorkerPool = class {
|
|
|
92
92
|
};
|
|
93
93
|
worker.onerror = (event) => {
|
|
94
94
|
this.broken = true;
|
|
95
|
-
for (const [id, task] of this.
|
|
95
|
+
for (const [id, task] of this.da) {
|
|
96
96
|
if (task.entry.worker === worker) {
|
|
97
|
-
this.
|
|
97
|
+
this.da.delete(id);
|
|
98
98
|
task.reject(new Error(`MinidracoLoader worker failed: ${event.message ?? "unknown error"}`));
|
|
99
99
|
}
|
|
100
100
|
}
|
|
@@ -106,12 +106,12 @@ var WorkerPool = class {
|
|
|
106
106
|
for (const entry of this.D) if (entry.pending < best.pending) best = entry;
|
|
107
107
|
return best;
|
|
108
108
|
}
|
|
109
|
-
|
|
110
|
-
this.
|
|
111
|
-
const batch = this.
|
|
109
|
+
Fc() {
|
|
110
|
+
this.Ya = false;
|
|
111
|
+
const batch = this.Ha;
|
|
112
112
|
if (batch.length === 0) return;
|
|
113
|
-
this.
|
|
114
|
-
while (this.D.length < Math.min(this.limit, batch.length) && this.
|
|
113
|
+
this.Ha = [];
|
|
114
|
+
while (this.D.length < Math.min(this.limit, batch.length) && this.ac() !== null) {
|
|
115
115
|
}
|
|
116
116
|
if (this.broken || this.D.length === 0) {
|
|
117
117
|
const error = new Error("MinidracoLoader: worker unavailable");
|
|
@@ -136,7 +136,7 @@ var WorkerPool = class {
|
|
|
136
136
|
for (const { entry, tasks } of buckets) {
|
|
137
137
|
if (tasks.length === 0) continue;
|
|
138
138
|
entry.pending += tasks.length;
|
|
139
|
-
for (const task of tasks) this.
|
|
139
|
+
for (const task of tasks) this.da.set(task.id, { resolve: task.resolve, reject: task.reject, entry });
|
|
140
140
|
entry.worker.postMessage({
|
|
141
141
|
tasks: tasks.map((task) => ({
|
|
142
142
|
id: task.id,
|
package/dist/three.d.ts
CHANGED
|
@@ -45,13 +45,15 @@ declare class PointAttribute extends GeometryAttribute {
|
|
|
45
45
|
_lazyValues: Int32Array | null;
|
|
46
46
|
_lazyMin: number[];
|
|
47
47
|
_lazyScale: number;
|
|
48
|
+
_lazyBounded: boolean;
|
|
48
49
|
constructor(geometryAttribute?: GeometryAttribute);
|
|
49
50
|
init(attributeType: number, numComponents: number, dataType: number, normalized: boolean, numAttributeValues: number): void;
|
|
50
51
|
reset(numAttributeValues: number): boolean;
|
|
52
|
+
resetWithData(data: Uint8Array, numAttributeValues: number): void;
|
|
51
53
|
resetLazy(numAttributeValues: number): void;
|
|
52
54
|
setLazyInteger(values: Int32Array | null): void;
|
|
53
|
-
setLazyQuantized(values: Int32Array | null, minValues: number[], delta: number): void;
|
|
54
|
-
setLazyOctahedron(values: Int32Array | null, scale: number): void;
|
|
55
|
+
setLazyQuantized(values: Int32Array | null, minValues: number[], delta: number, bounded: boolean): void;
|
|
56
|
+
setLazyOctahedron(values: Int32Array | null, scale: number, bounded: boolean): void;
|
|
55
57
|
get size(): number;
|
|
56
58
|
mappedIndex(pointIndex: number): number;
|
|
57
59
|
get isMappingIdentity(): boolean;
|
|
@@ -66,8 +68,8 @@ declare class PointAttribute extends GeometryAttribute {
|
|
|
66
68
|
extractTo<C extends new (length: number) => ExtractTypedArray>(OutputTypedArray: C, numPoints: number): InstanceType<C>;
|
|
67
69
|
_lazyMap(numPoints: number): Uint32Array;
|
|
68
70
|
_lazyFloatValues(): Int32Array;
|
|
69
|
-
_extractQuantized(out:
|
|
70
|
-
_extractOctahedron(out:
|
|
71
|
+
_extractQuantized(out: Float32Array, numPoints: number): void;
|
|
72
|
+
_extractOctahedron(out: Float32Array, numPoints: number): void;
|
|
71
73
|
_extractInteger(out: ExtractTypedArray, numPoints: number): void;
|
|
72
74
|
}
|
|
73
75
|
|