MCPcopy Index your code
hub / github.com/Weasy666/bevy_svg

github.com/Weasy666/bevy_svg @main

Chat with this repo
repository ↗ · DeepWiki ↗ · + Follow
110 symbols 159 edges 28 files 17 documented · 15%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

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.

Files are loaded through [AssetLoader], then parsed and simplified with [usvg] and then tessellated with [Lyon] into a vertex buffer, which lastly is convert into a [Bevy] mesh and drawn with custom shaders.

Note: The SVG support is currently rather basic, i'd like to expand that in the future.

Compatibility

Bevy version bevy_svg version Branch
Crates.io Crates.io bevy-0.19
Crates.io Crates.io bevy-0.18
Crates.io Crates.io bevy-0.17

Old versions

Bevy version bevy_svg version Branch
Crates.io Crates.io main
Crates.io Crates.io bevy-0.16
Crates.io Crates.io bevy-0.15
Crates.io Crates.io bevy-0.14
Crates.io Crates.io bevy-0.12
Crates.io Crates.io bevy-0.11
Crates.io Crates.io bevy-0.10
Crates.io Crates.io bevy-0.9
Crates.io Crates.io bevy-0.8
Crates.io Crates.io bevy-0.7
Crates.io Crates.io bevy-0.6
Crates.io Crates.io bevy-0.5

Examples

Complex shapes Multiple colors Fonts
complex_one_color two_colors twinkle

Usage

Copy this to your Cargo.toml

# Stable
bevy_svg = "0.19.0"

# 2D and 3D are available on default, if you only want/need one, use the following
bevy_svg = { version = "0.19.0", default-features = false, features = ["2d"] }
# or
bevy_svg = { version = "0.19.0", default-features = false, features = ["3d"] }

# 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

use bevy_svg::prelude::*;

fn main() {
    App::new()
        .add_plugins(DefaultPlugins.set(WindowPlugin {
            primary_window: Some(Window {
                title: "SVG Plugin".to_string(),
                ..Default::default()
            }),
            ..Default::default()
        }))
        .add_plugin(bevy_svg::prelude::SvgPlugin)
        .add_systems(Startup, setup)
        .run();
}

fn setup(
    mut commands: Commands,
    asset_server: Res<AssetServer>,
) {
    let svg = asset_server.load("path/to/file.svg");
    commands.spawn((Camera2d, Msaa::Sample4));
    commands.spawn((
        Svg2d(svg),
        Origin::Center, // Origin::TopLeft is the default
    ));
}

3D

use bevy_svg::prelude::*;

fn main() {
    App::new()
        .insert_resource(Msaa::Sample4)
        .add_plugins(DefaultPlugins.set(WindowPlugin {
            primary_window: Some(Window {
                title: "SVG Plugin".to_string(),
                ..Default::default()
            }),
            ..Default::default()
        }))
        .add_plugin(bevy_svg::prelude::SvgPlugin)
        .add_systems(Startup, setup)
        .run();
}

fn setup(
    mut commands: Commands,
    asset_server: Res<AssetServer>,
) {
    let svg = asset_server.load("path/to/file.svg");
    commands.spawn((Camera3d::default(), Msaa::Sample4));
    commands.spawn((
        Svg3d(svg),
        Origin::Center, // Origin::TopLeft is the default
        Transform {
            translation: Vec3::new(0.0, 0.0, -600.0),
            // The scale you need depends a lot on your SVG and camera distance
            scale: Vec3::new(1.0, 1.0, 1.0),
            rotation: Quat::from_rotation_x(-std::f32::consts::PI / 5.0),
        },
    ));
}

License

bevy_svg is licensed under either of the following, at your option:

  • Apache License, Version 2.0, (LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0)
  • MIT License (LICENSE-MIT or https://choosealicense.com/licenses/mit)

Extension points exported contracts — how you extend this code

Convert (Interface)
A locally defined [`std::convert::Into`] surrogate to overcome orphan rules. [6 implementers]
src/lib.rs
ToF32Array (Interface)
(no doc) [1 implementers]
src/util.rs
BufferExt (Interface)
(no doc) [1 implementers]
src/render/vertex_buffer.rs

Core symbols most depended-on inside this repo

load
called by 20
src/loader.rs
convert
called by 12
src/svg.rs
avg_gradient
called by 4
src/util.rs
tessellate
called by 3
src/svg.rs
compute_translation
called by 3
src/origin.rs
to_f32_array
called by 3
src/util.rs
process_vertex
called by 2
src/render/vertex_buffer.rs
next
called by 1
src/svg.rs

Shape

Function 43
Class 30
Method 28
Enum 6
Interface 3

Languages

Rust100%

Modules by API surface

examples/common/lib.rs20 symbols
src/svg.rs14 symbols
src/render/vertex_buffer.rs9 symbols
src/loader.rs6 symbols
src/origin.rs5 symbols
src/render/svg3d/plugin.rs4 symbols
src/plugin.rs4 symbols
examples/3d/multiple_translation.rs4 symbols
examples/2d/preloading.rs4 symbols
examples/2d/multiple_translation.rs4 symbols
src/util.rs3 symbols
src/render/svg2d/plugin.rs3 symbols

For agents

$ claude mcp add bevy_svg \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact