{"id":15137945,"url":"https://github.com/jinleili/bevy-in-web-worker","last_synced_at":"2025-10-23T13:31:06.975Z","repository":{"id":239462451,"uuid":"799445423","full_name":"jinleili/bevy-in-web-worker","owner":"jinleili","description":"Running a Bevy app in a Web Worker and interacting with HTML elements and the Bevy engine.","archived":false,"fork":false,"pushed_at":"2025-01-02T05:23:38.000Z","size":8095,"stargazers_count":35,"open_issues_count":0,"forks_count":3,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-30T18:48:25.329Z","etag":null,"topics":["bevy","bevy-engine","bevy-plugin","rust","webgpu","wgpu"],"latest_commit_sha":null,"homepage":"https://jinleili.github.io/bevy_in_web_worker/","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jinleili.png","metadata":{"files":{"readme":"README.MD","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.MIT","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-05-12T06:55:05.000Z","updated_at":"2025-01-24T21:14:43.000Z","dependencies_parsed_at":"2024-05-17T23:30:38.953Z","dependency_job_id":"24a0c58d-3bbf-4a33-b166-30a056723cef","html_url":"https://github.com/jinleili/bevy-in-web-worker","commit_stats":{"total_commits":17,"total_committers":1,"mean_commits":17.0,"dds":0.0,"last_synced_commit":"28d0fb4a2c4b5d6726cadeb0155bcb0bc2814d96"},"previous_names":["jinleili/bevy-in-web-worker"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jinleili%2Fbevy-in-web-worker","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jinleili%2Fbevy-in-web-worker/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jinleili%2Fbevy-in-web-worker/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jinleili%2Fbevy-in-web-worker/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jinleili","download_url":"https://codeload.github.com/jinleili/bevy-in-web-worker/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":237834702,"owners_count":19373773,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bevy","bevy-engine","bevy-plugin","rust","webgpu","wgpu"],"created_at":"2024-09-26T07:03:42.970Z","updated_at":"2025-10-23T13:31:06.964Z","avatar_url":"https://github.com/jinleili.png","language":"JavaScript","funding_links":[],"categories":["Misc"],"sub_categories":[],"readme":"# Bevy in Web Worker\n\n[README 中文](./zh.md)\n\nShowcasing how to run the `Bevy` App within a `Web Worker` and the interaction between HTML elements and Bevy.\n\nImplemented `CanvasViewPlugin` to replace `bevy_winit`, allowing the Bevy engine to run efficiently in a `Web Worker`, thereby significantly improving the application's performance and responsiveness. Additionally, it demonstrates the bidirectional communication between HTML elements and the Bevy engine, facilitating complex interaction patterns to validate the communication latency and performance when the Engine is moved into a Web Worker and interacts with the `UI thread`.\n\n**Validation Points:**\n\n1. Whether the event communication cost between the main thread and the Worker is high.\n2. Whether the asynchronous pick interface leads to poor user interaction experience.\n3. The impact of main thread blocking on events/workers.\n4. The impact on experience caused by mouse events, onmessage, and render blocking.\n\n**Design for the above validation points:**\n\n1. No **Throttle** on the mouse event trigger frequency; every mousemove event is sent to the worker, executed by the worker for ray picking, and the result is sent back to the main thread.\n2. Designed a high-complexity interaction logic for **selection/highlighting**:\n   1. Main thread postMsg to the worker -\u003e\n   2. Worker delegates the task to the engine to execute ray pick -\u003e\n   3. Send the result from the engine to the worker -\u003e\n   4. Worker postMsg to the main thread -\u003e\n   5. Main thread postMsg to the worker to perform the necessary **selection/highlighting**\n3. Simulated scenarios of main thread blocking with controllable frame block duration, with a **main thread stutter indicator** at the upper left corner for easy observation of blocking results.\n4. The interface also provides two running instances of the main thread and the Worker thread for intuitive comparison.\n5. Simulated scenarios of mousemove, onmessage, and render blocking.\n6. Provided the functionality to drag scene objects by holding the left mouse button.\n7. Simulated frame rendering logic of a utility App: with scene animation turned off, frame rendering is entirely driven by mouse events.\n\n## Screenshot\n\n![Bevy in Web Worker](./screenshot.png)\n\n## Running\n\n```sh\n# Compile WASM:\n# Add Rust WebAssembly target\nrustup target add wasm32-unknown-unknown\n# Install wasm-bindgen command line tool\ncargo install -f wasm-bindgen-cli --version 0.2.101\n\n# Run:\n# First install the http server\ncargo install basic-http-server\n# Then run using the following script\nsh ./run-wasm.sh\n\n# Build the release package\nsh ./build-wasm.sh\n```\n\n## Compatible Bevy versions\n\n| Bevy version | `bevy-in-web-worker` version |\n| :----------- | :--------------------------- |\n| `0.17`       | `0.3`                        |\n| `0.16`       | `0.2`                        |\n| `0.14`       | `0.1`                        |\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjinleili%2Fbevy-in-web-worker","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjinleili%2Fbevy-in-web-worker","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjinleili%2Fbevy-in-web-worker/lists"}