Skip to content

Commit

Permalink
Merge pull request #15026 from RaananW/smalDracoFix
Browse files Browse the repository at this point in the history
Draco - fix for fallback and tests update
  • Loading branch information
sebavan committed Apr 24, 2024
2 parents 4920c2b + f3e4b85 commit 73aff6e
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ export class DracoCompression implements IDisposable {

return new AutoReleaseWorkerPool(numberOfWorkers as number, () => {
const worker = new Worker(workerBlobUrl);
return initializeWebWorker(worker, decoderWasmBinary!, decoderInfo.url);
return initializeWebWorker(worker, decoderWasmBinary, decoderInfo.url);
});
});
} else {
Expand Down
30 changes: 20 additions & 10 deletions packages/dev/core/src/Meshes/Compression/dracoCompressionWorker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,8 @@ export function workerFunction(): void {
if (decoder.url) {
importScripts(decoder.url);
}
decoderPromise = DracoDecoderModule({ wasmBinary: decoder.wasmBinary });
const initDecoderObject = decoder.wasmBinary ? { wasmBinary: decoder.wasmBinary } : {};
decoderPromise = DracoDecoderModule(initDecoderObject);
postMessage({ id: "initDone" });
break;
}
Expand Down Expand Up @@ -225,7 +226,7 @@ export function workerFunction(): void {
* @param moduleUrl The url to the draco decoder module (optional)
* @returns A promise that resolves when the worker is initialized
*/
export function initializeWebWorker(worker: Worker, decoderWasmBinary: ArrayBuffer, moduleUrl?: string): Promise<Worker> {
export function initializeWebWorker(worker: Worker, decoderWasmBinary?: ArrayBuffer, moduleUrl?: string): Promise<Worker> {
return new Promise<Worker>((resolve, reject) => {
const onError = (error: ErrorEvent) => {
worker.removeEventListener("error", onError);
Expand All @@ -244,18 +245,27 @@ export function initializeWebWorker(worker: Worker, decoderWasmBinary: ArrayBuff
worker.addEventListener("error", onError);
worker.addEventListener("message", onMessage);

// clone the array buffer to make it transferable
const clone = decoderWasmBinary.slice(0);
worker.postMessage(
{
if (!decoderWasmBinary) {
worker.postMessage({
id: "init",
decoder: {
url: moduleUrl,
wasmBinary: clone,
},
},
[clone]
);
});
} else {
// clone the array buffer to make it transferable
const clone = decoderWasmBinary.slice(0);
worker.postMessage(
{
id: "init",
decoder: {
url: moduleUrl,
wasmBinary: clone,
},
},
[clone]
);
}
// note: no transfer list as the ArrayBuffer is shared across main thread and pool workers
});
}
12 changes: 9 additions & 3 deletions packages/tools/tests/test/visualization/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -519,17 +519,23 @@
},
{
"title": "Draco Mesh Compression (decodeMeshAsync, numWorkers = 1)",
"playgroundId": "#22MFU2#4",
"playgroundId": "#22MFU2#77",
"referenceImage": "draco.png"
},
{
"title": "Draco Mesh Compression (decodeMeshToGeometryAsync, numWorkers = 0)",
"playgroundId": "#22MFU2#65",
"playgroundId": "#22MFU2#78",
"referenceImage": "draco.png"
},
{
"title": "Draco Mesh Compression (decodeMeshToGeometryAsync, numWorkers = 1)",
"playgroundId": "#22MFU2#65",
"playgroundId": "#22MFU2#78",
"replace": "numWorkers = 0, numWorkers = 1",
"referenceImage": "draco.png"
},
{
"title": "Draco Mesh Compression (fallback)",
"playgroundId": "#22MFU2#75",
"replace": "numWorkers = 0, numWorkers = 1",
"referenceImage": "draco.png"
},
Expand Down

0 comments on commit 73aff6e

Please sign in to comment.