minidraco 0.8.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 +6 -6
- package/dist/index.d.ts +3 -2
- package/dist/index.js +1112 -1121
- package/dist/pool.js +19 -19
- package/dist/three.d.ts +3 -2
- package/dist/three.js +1120 -1129
- package/dist/worker.js +1112 -1121
- package/package.json +1 -1
package/dist/pool.js
CHANGED
|
@@ -8,9 +8,9 @@ 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
12
|
Ec = 0;
|
|
13
|
-
|
|
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
16
|
Ha = [];
|
|
@@ -30,18 +30,18 @@ var WorkerPool = class {
|
|
|
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.
|
|
33
|
+
while (this.D.length < this.limit && this.ac() !== null) {
|
|
34
34
|
}
|
|
35
35
|
}
|
|
36
36
|
dispose() {
|
|
37
|
-
for (const entry of this.
|
|
38
|
-
this.
|
|
37
|
+
for (const entry of this.D) entry.worker.terminate();
|
|
38
|
+
this.D = [];
|
|
39
39
|
const error = decodeError("MinidracoLoader: disposed while decoding");
|
|
40
40
|
for (const task of this.Ha) task.reject(error);
|
|
41
41
|
this.Ha = [];
|
|
42
42
|
this.Ya = false;
|
|
43
|
-
for (const [, task] of this.
|
|
44
|
-
this.
|
|
43
|
+
for (const [, task] of this.da) task.reject(error);
|
|
44
|
+
this.da.clear();
|
|
45
45
|
if (this.oa !== null) {
|
|
46
46
|
URL.revokeObjectURL(this.oa);
|
|
47
47
|
this.oa = null;
|
|
@@ -59,7 +59,7 @@ var WorkerPool = class {
|
|
|
59
59
|
}
|
|
60
60
|
ac() {
|
|
61
61
|
if (this.broken) return null;
|
|
62
|
-
if (this.
|
|
62
|
+
if (this.D.length < this.limit) {
|
|
63
63
|
const workerUrl = this.Ga ?? new URL("./worker.js", import.meta.url);
|
|
64
64
|
let worker;
|
|
65
65
|
try {
|
|
@@ -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,18 +92,18 @@ 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
|
}
|
|
101
101
|
};
|
|
102
|
-
this.
|
|
102
|
+
this.D.push(entry);
|
|
103
103
|
return entry;
|
|
104
104
|
}
|
|
105
|
-
let best = this.
|
|
106
|
-
for (const entry of this.
|
|
105
|
+
let best = this.D[0];
|
|
106
|
+
for (const entry of this.D) if (entry.pending < best.pending) best = entry;
|
|
107
107
|
return best;
|
|
108
108
|
}
|
|
109
109
|
Fc() {
|
|
@@ -111,9 +111,9 @@ var WorkerPool = class {
|
|
|
111
111
|
const batch = this.Ha;
|
|
112
112
|
if (batch.length === 0) return;
|
|
113
113
|
this.Ha = [];
|
|
114
|
-
while (this.
|
|
114
|
+
while (this.D.length < Math.min(this.limit, batch.length) && this.ac() !== null) {
|
|
115
115
|
}
|
|
116
|
-
if (this.broken || this.
|
|
116
|
+
if (this.broken || this.D.length === 0) {
|
|
117
117
|
const error = new Error("MinidracoLoader: worker unavailable");
|
|
118
118
|
for (const task of batch) task.reject(error);
|
|
119
119
|
return;
|
|
@@ -122,7 +122,7 @@ var WorkerPool = class {
|
|
|
122
122
|
let totalBytes = 0;
|
|
123
123
|
for (const task of batch) totalBytes += task.buffer.byteLength;
|
|
124
124
|
const averageBytes = totalBytes / batch.length;
|
|
125
|
-
const buckets = this.
|
|
125
|
+
const buckets = this.D.map((entry) => ({
|
|
126
126
|
entry,
|
|
127
127
|
tasks: [],
|
|
128
128
|
bytes: entry.pending * averageBytes
|
|
@@ -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
|
@@ -49,6 +49,7 @@ declare class PointAttribute extends GeometryAttribute {
|
|
|
49
49
|
constructor(geometryAttribute?: GeometryAttribute);
|
|
50
50
|
init(attributeType: number, numComponents: number, dataType: number, normalized: boolean, numAttributeValues: number): void;
|
|
51
51
|
reset(numAttributeValues: number): boolean;
|
|
52
|
+
resetWithData(data: Uint8Array, numAttributeValues: number): void;
|
|
52
53
|
resetLazy(numAttributeValues: number): void;
|
|
53
54
|
setLazyInteger(values: Int32Array | null): void;
|
|
54
55
|
setLazyQuantized(values: Int32Array | null, minValues: number[], delta: number, bounded: boolean): void;
|
|
@@ -67,8 +68,8 @@ declare class PointAttribute extends GeometryAttribute {
|
|
|
67
68
|
extractTo<C extends new (length: number) => ExtractTypedArray>(OutputTypedArray: C, numPoints: number): InstanceType<C>;
|
|
68
69
|
_lazyMap(numPoints: number): Uint32Array;
|
|
69
70
|
_lazyFloatValues(): Int32Array;
|
|
70
|
-
_extractQuantized(out:
|
|
71
|
-
_extractOctahedron(out:
|
|
71
|
+
_extractQuantized(out: Float32Array, numPoints: number): void;
|
|
72
|
+
_extractOctahedron(out: Float32Array, numPoints: number): void;
|
|
72
73
|
_extractInteger(out: ExtractTypedArray, numPoints: number): void;
|
|
73
74
|
}
|
|
74
75
|
|