Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Preparation for the external dependencies package #14773

Merged
merged 14 commits into from Feb 28, 2024

Conversation

RaananW
Copy link
Member

@RaananW RaananW commented Feb 7, 2024

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!

@RaananW RaananW marked this pull request as draft February 7, 2024 17:38
@bjsplat
Copy link
Collaborator

bjsplat commented Feb 7, 2024

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.

@bjsplat
Copy link
Collaborator

bjsplat commented Feb 7, 2024

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.

@bjsplat
Copy link
Collaborator

bjsplat commented Feb 7, 2024

@bjsplat
Copy link
Collaborator

bjsplat commented Feb 7, 2024

@bjsplat
Copy link
Collaborator

bjsplat commented Feb 7, 2024

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.

@bjsplat
Copy link
Collaborator

bjsplat commented Feb 12, 2024

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

@RaananW RaananW marked this pull request as ready for review February 13, 2024 20:10
@bjsplat
Copy link
Collaborator

bjsplat commented Feb 23, 2024

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

@RaananW RaananW merged commit 7e708fa into BabylonJS:master Feb 28, 2024
11 checks passed
@RaananW RaananW deleted the preparingForExternalDependencies branch February 28, 2024 19:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants