3.6 KiB
3.6 KiB
CLAUDE.md
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
Project Overview
This is bevy_cef, a Bevy plugin that integrates the Chromium Embedded Framework (CEF) into Bevy applications, allowing webviews to be rendered as 3D objects in the game world or as UI overlays.
Architecture
Multi-Process Design
- Browser Process: Main application process running Bevy (
bevy_cef_core::browser_process) - Render Process: Separate CEF render process (
bevy_cef_core::render_process) - Communication through IPC channels and Bevy Remote Protocol (BRP)
Core Components
CefWebviewUri: Component specifying webview URL (remote or local viacef://localhost/)WebviewSize: Controls webview rendering dimensions (default 800x800)WebviewExtendStandardMaterial: Material for rendering webviews on 3D meshesHostWindow: Optional parent window specificationZoomLevel: Webview zoom controlAudioMuted: Audio muting control
Plugin Architecture
The main CefPlugin orchestrates several sub-plugins:
LocalHostPlugin: Serves local assets via custom schemeMessageLoopPlugin: CEF message loop integrationWebviewCoreComponentsPlugin: Core component registrationWebviewPlugin: Main webview managementIpcPlugin: Inter-process communicationKeyboardPlugin,NavigationPlugin,ZoomPlugin,AudioMutePlugin: Feature-specific functionality
IPC System
Three communication patterns:
- JS Emit: Webview → Bevy app via
JsEmitEventPlugin<T> - Host Emit: Bevy app → Webview via event emission
- BRP (Bevy Remote Protocol): Bidirectional RPC calls
Development Commands
Code Quality
# Fix and format code
make fix
# Which runs:
# cargo clippy --fix --allow-dirty --allow-staged --workspace --all --all-features
# cargo fmt --all
Development Setup
The build system automatically handles CEF dependencies on macOS with debug feature:
- Installs
bevy_cef_debug_render_processtool - Installs
export-cef-dirtool - Downloads/extracts CEF framework to
$HOME/.local/share/cef
Manual Installation
# Install debug render process tool
make install
# Or: cargo install --path ./crates/bevy_cef_debug_render_process --force
Key Examples
examples/simple.rs: Basic webview on 3D planeexamples/js_emit.rs: JavaScript to Bevy communicationexamples/host_emit.rs: Bevy to JavaScript communicationexamples/brp.rs: Bidirectional RPC with devtoolsexamples/navigation.rs: Page navigation controlsexamples/zoom_level.rs: Zoom functionalityexamples/sprite.rs: Webview as 2D spriteexamples/devtool.rs: Chrome DevTools integration
Local Asset Loading
Local HTML/assets are served via the custom cef://localhost/ scheme:
- Place assets in
assets/directory - Reference as
CefWebviewUri::local("filename.html") - Or manually:
cef://localhost/filename.html
Testing
No automated tests are present in this codebase. Testing is done through the example applications.
Manually Testing
- Run tests with
cargo test --workspace --all-features
Platform Notes
- Currently focused on macOS development (see Cargo.toml target-specific dependencies)
- CEF framework must be available at
$HOME/.local/share/cef - Uses
objccrate for macOS-specific window handling - DYLD environment variables required for CEF library loading
Workspace Structure
This is a Cargo workspace with:
- Root crate:
bevy_cef(public API) crates/bevy_cef_core: Core CEF integration logiccrates/bevy_cef_debug_render_process: Debug render process executableexamples/demo: Standalone demo application