Skip to content
forked from Weasy666/bevy_svg

A simple and incomplete SVG drawer for the Bevy engine.

License

Notifications You must be signed in to change notification settings

neosam/bevy_svg

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

39 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

bevy_svg

Crates.io license

For one of my personal projects i needed a way to load and display some simple SVG files/shapes in Bevy, so i took inspiration from bevy_prototype_lyon and modified and extended it to...well...load and display simple SVG files. SVGs can be used/displayed in 2D as well as in 3D.

I use usvg to load, parse and simplify a SVG or SVGZ file and Lyon to tessellate it into a vertex buffer, which i then convert into a Bevy mesh and draw with shaders.

Something else that i want to change, is how i load the SVG file. This would ideally use the Bevy asset manager, but i didn't have the time to take a deeper look at how it works or how i can integrate with it.

Compatibility

Bevy version bevy_svg version Branch
Crates.io Crates.io bevy-0.5
Crates.io Crates.io main

Examples

Complex shapes Multiple colors Fonts
complex_one_color two_colors twinkle

Usage

This crate is not yet on crates.io because it uses Bevy master. But i am planning to publish it as soon as Bevy 0.5 is released. Until then, you need to copy this to your Cargo.toml

# Stable
bevy_svg = "0.3"

# Living on the edge (at your own risk 😅)
bevy_svg = { git = "https://github.com/Weasy666/bevy_svg", branch = "main" }

Then use it like this.

2D

fn main() {
    App::new()
        .insert_resource(Msaa { samples: 4 })
        .insert_resource(WindowDescriptor {
            title: "SVG Plugin".to_string(),
            ..Default::default()
        })
        .add_plugins(DefaultPlugins)
        .add_plugin(bevy_svg::prelude::SvgPlugin)
        .add_startup_system(setup.system());
        .run();
}

fn setup(mut commands: Commands) {
    commands.spawn_bundle(OrthographicCameraBundle::new_2d());
    commands.spawn_bundle(
        SvgBuilder::from_file("path/to/file.svg")
            .origin(Origin::Center)
            .position(Vec3::new(0.0, 0.0, 0.0))
            .build()
            .expect("File not found")
    );
}

3D

fn main() {
    App::new()
        .insert_resource(Msaa { samples: 4 })
        .insert_resource(WindowDescriptor {
            title: "SVG Plugin".to_string(),
            ..Default::default()
        })
        .add_plugins(DefaultPlugins)
        .add_plugin(bevy_svg::prelude::SvgPlugin)
        .add_startup_system(setup.system());
        .run();
}

fn setup(mut commands: Commands) {
    commands.spawn_bundle(PerspectiveCameraBundle::new_3d());
    commands.spawn_bundle(
        SvgBuilder::from_file("path/to/file.svg")
            .origin(Origin::Center)
            .position(Vec3::new(0.0, 0.0, -1.0))
            .scale(Vec2::new(0.01, 0.01))
            .build()
            .expect("File not found")
    );
}

About

A simple and incomplete SVG drawer for the Bevy engine.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Rust 100.0%