Giter Site home page Giter Site logo

chleba / bevy_ratatui_render Goto Github PK

View Code? Open in Web Editor NEW

This project forked from cxreiff/bevy_ratatui_render

0.0 0.0 0.0 75 KB

A bevy plugin for rendering your bevy app to the terminal using ratatui.

Home Page: https://crates.io/crates/bevy_ratatui_render

License: Apache License 2.0

Rust 100.00%

bevy_ratatui_render's Introduction

bevy_ratatui_render

Bevy inside the terminal!

Uses bevy headless rendering, ratatui, and ratatui_image to print the rendered output of your bevy application to the terminal using unicode halfblocks.

cube examplefoxessponza test scene

examples/cube.rs, bevy many_foxes example, sponza test scene

getting started

fn main() {
    App::new()
        .add_plugins((
            DefaultPlugins,
            RatatuiPlugin,
            RatatuiRenderPlugin::new(256, 256),
        ))
        .add_systems(Startup, setup_scene)
        .add_systems(Update, draw_scene.map(error))
        .run();
}

fn setup_scene(
    mut commands: Commands,
    mut meshes: ResMut<Assets<Mesh>>,
    mut materials: ResMut<Assets<StandardMaterial>>,
    ratatui_render: Res<RatatuiRenderContext>,
) {
    // spawn objects into your scene

    ...

    commands.spawn(Camera3dBundle {
        camera: Camera {
            target: ratatui_render.target(),
            ..default()
        },
        ..default()
    });
}

fn draw_scene(
    mut ratatui: ResMut<RatatuiContext>,
    ratatui_render: Res<RatatuiRenderContext>,
) -> io::Result<()> {
    ratatui.draw(|frame| {
        frame.render_widget(ratatui_render.widget(), frame.size());
    })?;

    Ok(())
}

There is a convenience function if you do not need access to the ratatui draw loop and just would like the render to print to the full terminal (use instead of adding the draw_scene system above):

RatatuiRenderPlugin::new(256, 256).print_full_terminal()

I also recommend telling bevy you don't need a window or anti-aliasing:

DefaultPlugins
    .set(ImagePlugin::default_nearest())
    .set(WindowPlugin {
        primary_window: None,
        exit_condition: ExitCondition::DontExit,
        close_when_requested: false,
    })

supported terminals

This relies on the terminal supporting 24-bit color. I've personality tested and confirmed that the following terminals display color correctly:

  • Alacritty
  • Kitty
  • iTerm

what's next?

This package currently contains both the headless rendering functionality and a layer of integration between ratatui and bevy. I plan to scoop out the integration layer and contribute to the bevy_ratatui package instead.

Additionally, this package is currently set up for a single camera. It shouldn't take much more code to allow creating multiple render targets.

credits

bevy_ratatui_render's People

Contributors

cxreiff avatar

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.