Preparation for the external dependencies package
The changes in the code are up for review.
- This architecture allows a developer to create their own workers or worker pool instead of using our default worker creation
- This allows overriding using the CDN. For example, using vite, this will work:
// index.js
import wasm from "@babylonjs/dependencies/draco/draco_decoder_gltf.wasm?arraybuffer"; // also works from "draco3dgltf" package
import { AutoReleaseWorkerPool } from "@babylonjs/core/Misc/workerPool.js";
import { DracoCompression } from "@babylonjs/core/Meshes/Compression/dracoCompression.js";
import { initializeWebWorker } from "@babylonjs/core/Meshes/Compression/dracoCompressionWorker.js";
import { Tools } from "@babylonjs/core/Misc/tools.js";
import { VertexBuffer } from "@babylonjs/core/Meshes/buffer.js";
const workerPool = new AutoReleaseWorkerPool(4, () => {
const worker = new Worker(new URL("./worker.js", import.meta.url), {
type: "module",
});
return initializeWebWorker(worker, wasm);
});
const dracoCompression = new DracoCompression({
workerPool,
});
// worker.js
import { workerFunction } from "@babylonjs/core/Meshes/Compression/dracoCompressionWorker.js";
import "@babylonjs/dependencies/draco/draco_decoder_gltf.js";
workerFunction();
This allows each build system to decide the architecture they want to use, as long as they provide the correct data.
- Providing URLs is still possible, and is the simplest way to override the default babylon behavior. This method will also be present if it is impossible
- The ***Worker.ts files are not exported to UMD! So they will only be available to be used in @babylonjs/core . They will be available in UMD, but not exported.
- This maintains back-compat and makes the least amount of changes
- Only worker-enabled modules were changed. The rest can use the URL configuration instead of injecting, as every build system will provide a URL of an asset which can be used on the main thread. As workers work a bit differently it is required to provide this way of injecting them directly as well.
Waiting for reviews!
Please make sure to label your PR with "bug", "new feature" or "breaking change" label(s). To prevent this PR from going to the changelog marked it with the "skip changelog" label.
Please make sure to label your PR with "bug", "new feature" or "breaking change" label(s). To prevent this PR from going to the changelog marked it with the "skip changelog" label.
Snapshot stored with reference name: refs/pull/14773/merge
Test environment: https://babylonsnapshots.z22.web.core.windows.net/refs/pull/14773/merge/index.html
To test a playground add it to the URL, for example:
https://babylonsnapshots.z22.web.core.windows.net/refs/pull/14773/merge/index.html#WGZLGJ#4600
Links to test babylon tools with this snapshot:
https://playground.babylonjs.com/?snapshot=refs/pull/14773/merge https://sandbox.babylonjs.com/?snapshot=refs/pull/14773/merge https://gui.babylonjs.com/?snapshot=refs/pull/14773/merge https://nme.babylonjs.com/?snapshot=refs/pull/14773/merge
To test the snapshot in the playground with a playground ID add it after the snapshot query string:
https://playground.babylonjs.com/?snapshot=refs/pull/14773/merge#BCU1XR#0
(Experimental) visualisation test reporter:
https://babylonsnapshots.z22.web.core.windows.net/refs/pull/14773/merge/testResults/webgl2playwright/index.html
Visualization tests for webgl1 have failed. If some tests failed because the snapshots do not match, the report can be found at
https://babylonsnapshots.z22.web.core.windows.net/refs/pull/14773/merge/testResults/webgl1/index.html
If tests were successful afterwards, this report might not be available anymore.
Visualization tests for WebGPU (Experimental) Important - these might fail sporadically. This is an optional test.
https://babylonsnapshots.z22.web.core.windows.net/refs/pull/14773/merge/testResults/webgpuplaywright/index.html
Visualization tests for WebGPU (Experimental) Important - these might fail sporadically. This is an optional test.
https://babylonsnapshots.z22.web.core.windows.net/refs/pull/14773/merge/testResults/webgpuplaywright/index.html