这是indexloc提供的服务,不要输入任何密码
Skip to content

mosure/bevy_webcam

Repository files navigation

bevy_webcam 📷

GitHub License crates.io

bevy camera input, using the nokhwa crate

usage

app.add_plugins((
    DefaultPlugins,
    BevyWebcamPlugin::default(),
));
app.add_systems(
    Update,
    setup_ui,
);

// ...

fn setup_ui(
    mut commands: Commands,
    stream: Res<WebcamStream>,
) {
    commands.spawn(Camera2d);

    commands.spawn((
        ImageNode {
            image: stream.frame.clone(),
            ..default()
        },
        Node {
            width: Val::Percent(100.0),
            height: Val::Percent(100.0),
            ..default()
        },
    ));
}

features

  • native camera capture via nokhwa's native backends
  • threaded frame decoding on native targets, so the Bevy Update stage stays responsive
  • wasm32 (browser) capture via the DOM MediaStreamTrackProcessor feeding pixels into the exported frame_input binding

platform notes

  • Native: frames are decoded on a dedicated worker thread and sent to the main Bevy world through a channel before being uploaded to the GPU.
  • Wasm: www/index.html acquires the webcam stream with getUserMedia, processes frames with MediaStreamTrackProcessor, and forwards RGBA pixels into the wasm module via frame_input. The Bevy plugin simply consumes those frames each Update, so there is no blocking nokhwa path on the browser.
  • Camera selection on web: the browser decides which device backs the stream the user grants; the CameraIndex setting currently applies to native builds only.

About

📷 bevy native/web camera input

Topics

Resources

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT

Stars

Watchers

Forks