bevy_2d_line

Crates.iobevy_2d_line
lib.rsbevy_2d_line
version0.1.2
sourcesrc
created_at2024-08-31 12:09:52.040365
updated_at2024-08-31 16:18:51.131494
descriptionA line rendering plugin for Bevy
homepage
repositoryhttps://github.com/piefayth/bevy_2d_line
max_upload_size
id1358783
size130,022
Piefayth (Piefayth)

documentation

README

bevy 2d line

image

Bevy port of https://github.com/mattdesl/three-line-2d Polylines in a vertex shader; plays nice with projection scale, z-index; supports vertex colors. Does not support picking!

Moving thousands of line endpoints every frame will be slow, because the mesh needs rebuilt when the lines are moved.

Lazily maintained at best!

Compatibility

Bevy Version bevy_2d_line Version
0.14 0.1.2

Installation

Add the following to your Cargo.toml:

[dependencies]
bevy_2d_line = "0.1.2"

Usage

  1. Add the LineRenderingPlugin to your Bevy app:
use bevy::prelude::*;
use bevy_2d_line::LineRenderingPlugin;

fn main() {
    App::new()
        .add_plugins(DefaultPlugins)
        .add_plugins(LineRenderingPlugin)
        .add_systems(Startup, setup)
        .run();
}
  1. Create and spawn a Line component:
use bevy_2d_line::Line;

fn setup(mut commands: Commands) {
    commands.spawn(Camera2dBundle::default());

    let points = vec![
        Vec2::new(-200.0, 0.0),
        Vec2::new(0.0, 200.0),
        Vec2::new(200.0, 0.0),
    ];
    let colors = vec![
        Color::RED,
        Color::GREEN,
        Color::BLUE,
    ];

    commands.spawn(Line {
        points,
        colors,
        thickness: 5.0,
    });
}

Examples

Check out the examples directory for more detailed usage:

  • simple_line.rs: Basic usage of the line renderer
  • curved_line.rs: Rendering a curved line using Bezier curves

To run an example:

cargo run --example simple_line

License

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Commit count: 0

cargo fmt