How awtterpip/bevy_oxr works
Project Type and Purpose
• This is a Rust Cargo workspace providing a modular, plugin-driven extension (“Bevy Mod XR”) to the Bevy game engine.
• It delivers a core XR abstraction crate plus two backend crates (OpenXR and WebXR) and a utilities crate.
• Its goal is to let Bevy apps easily add VR/AR support via OpenXR on desktop and WebXR in the browser.
File Structure Overview
• Root: workspace Cargo.toml, CI (.github/workflows), Nix files (flake.nix, default.nix), xbuild for cross-compiling.
• crates/
• bevy_xr — core, engine-agnostic XR types & traits (actions, sessions, spaces, camera, hands).
• bevy_openxr — OpenXR backend plugin, with sub-modules for init, sessions, action binding, rendering (Vulkan & D3D12), features (handtracking, overlay, passthrough), examples.
• bevy_webxr — WebXR backend plugin for browser/WebAssembly.
• bevy_xr_utils — optional utilities (hand gizmos, tracking & transform helpers, predefined action sets).
Key Insights from README
• Primary support for OpenXR (desktop) with future WebXR support.
• Examples demonstrate plugin usage (3d_scene, actions, overlay, etc.).
• External runtime dependency: system’s OpenXR loader (Linux package) and browser WebXR APIs.
a. Main Components to Show
• User’s Bevy Application
• Bevy Engine Core (ECS, rendering, asset pipelines)
• bevy_xr (core abstraction layer)
• Backend plugins
• bevy_openxr → OpenXR runtime → GPU driver (Vulkan/D3D12) → hardware
• bevy_webxr → Browser WebXR API → WebGL/WebGPU → hardware
• bevy_xr_utils (optional toolkit layer)
• Examples/project binaries
• Build & CI layer (Cargo workspace, .cargo config, Nix, CI workflows)
b. Relationships & Data Flows
• Your Bevy app depends on bevy_xr_utils (opt-in) and on exactly one backend plugin (bevy_openxr or bevy_webxr).
• bevy_xr provides the Plugin trait and shared resources (XRSession, XRActions, XRSpaces).
• Backend plugins implement those abstractions, register systems into the Bevy App.
• At runtime, plugin systems call into the OpenXR loader or browser WebXR to:
• Initialize sessions
• Synchronize input actions
• Acquire swapchains, render via Vulkan/D3D12 or WebGL/WebGPU
• Poll events and update ECS resources
• bevy_xr_utils hooks into those shared resources to provide gizmos and utility transforms.
c. Architectural Patterns & Principles
• Modular crate separation: core abstraction vs. backends vs. utilities.
• Plugin architecture leveraging Bevy’s ECS and schedule system.
• Feature-gated modules for optional XR features (hand tracking, overlays, passthrough).
• Graphics adapter pattern: separate renderer implementations behind a common graphics trait.
d. Key Technologies & Libraries
• Rust & Cargo workspaces
• Bevy game engine (ECS, rendering pipeline)
• OpenXR loader/runtime
• Vulkan & Direct3D12 graphics APIs
• WebXR API in browsers, WebAssembly target
• Nix/flakes and xbuild for reproducible builds & cross-compilation
• GitHub Actions for CI