Weasy666 / bevy_svg

A simple and incomplete SVG drawer for the Bevy engine.
Apache License 2.0
108 stars 26 forks source link

Add functions to allow users to import Svg's from bytes. #30

Closed StarArawn closed 1 year ago

StarArawn commented 1 year ago

Motivation

Allow users to load in SVG's during the build process. Example:

pub struct IconsPlugin;
impl Plugin for IconsPlugin {
    fn build(&self, app: &mut bevy::prelude::App) {
        let expand_less_bytes = include_bytes!("expand_less.svg");
        let expand_more_bytes = include_bytes!("expand_more.svg");
        let mut expand_less = Svg::from_bytes(expand_less_bytes, &Path::new("")).unwrap();
        let mut expand_more = Svg::from_bytes(expand_more_bytes, &Path::new("")).unwrap();

        let mut meshes = app.world.get_resource_mut::<Assets<Mesh>>().unwrap();
        expand_less.mesh = meshes.add(expand_less.tessellate());
        expand_more.mesh = meshes.add(expand_more.tessellate());

        let mut svgs = app.world.get_resource_mut::<Assets<Svg>>().unwrap();
        svgs.set_untracked(EXPAND_LESS_HANDLE, expand_less);
        svgs.set_untracked(EXPAND_MORE_HANDLE, expand_more);
    }
}
Weasy666 commented 1 year ago

LGTM! Thank you for your contribution🙂