Giter Site home page Giter Site logo

Comments (1)

blaind avatar blaind commented on July 21, 2024

What about adding a Recorder trait, with some sample recorders (e.g. gif) provided by the library, but customizable easily by end users.

Here's an example of how the API could look:

  • adding the recorders in a builder pattern (.add_recorder::<CustomRecorder>())
  • inserting MediaCapture as a component for each camera where its needed - this way no need to link the id's. Internally, maybe a few instances could be used but end-user API more bevy-style this way (.insert(MediaCapture::<CustomTracker>::new().set_duration(Duration::from_secs(5)));)
use std::time::Duration;
use bevy::prelude::*;
use bevy_capture_media::{MediaCapture, BevyCapturePlugin};

pub fn spawn_cameras(
    mut commands: Commands,
) {
    let camera_entity = commands
        .spawn_bundle(Camera2dBundle::default())
        .insert(MainCamera)
        .insert(MediaCapture::<CustomTracker>::new().set_duration(Duration::from_secs(5)));       
}

pub fn take_screenshot(
    input: Res<Input<KeyCode>>,
    mut capture: Query<&mut MediaCapture<CustomTracker>, With<MainCamera>>,
) {
    if input.just_released(KeyCode::RShift) {
        capture.single_mut().start();
    }
}

#[derive(Component)]
pub struct MainCamera;

fn main() {
    App::new()
        .add_plugin(DefaultPlugins)
        .add_plugin(bevy_capture_media::BevyCapturePlugin::new().add_recorder::<CustomRecorder>())
        .add_startup_system(spawn_cameras)
        .add_system(take_screenshot)
        .run();
}

pub struct MediaCapture<T: Recorder> {
  recorder: T
}

pub trait Record {
  // some common methods, like receive_frame
}

pub struct CustomRecorder;

impl Recorder for CustomRecorder {
   // ...
}

note: didn't try if possible in practice... (especially the storage of trait, if multiple implementations used)

from bevy_capture_media.

Related Issues (5)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.