#2d-3d #3d #sprite #bevy #bevy-plugin #gamedev #game-engine

bevy_sprite3d

Bevy Plugin to allow using 2d sprites in a 3d scene

14 stable releases (4 major)

4.0.0 Dec 4, 2024
3.0.0 Jul 6, 2024
2.8.0 Feb 26, 2024
2.7.0 Nov 5, 2023
0.1.0 Jul 29, 2022

#67 in Game dev

Download history 11/week @ 2024-08-19 27/week @ 2024-08-26 31/week @ 2024-09-02 18/week @ 2024-09-09 28/week @ 2024-09-16 155/week @ 2024-09-23 51/week @ 2024-09-30 37/week @ 2024-10-07 57/week @ 2024-10-14 8/week @ 2024-10-21 82/week @ 2024-10-28 67/week @ 2024-11-04 21/week @ 2024-11-11 44/week @ 2024-11-18 95/week @ 2024-11-25 222/week @ 2024-12-02

386 downloads per month
Used in 3 crates

MIT license

2.5MB
315 lines

bevy_sprite3d

Crates.io MIT

Use 2d sprites in a 3d bevy scene.

This is a pretty common setup in other engines (unity, godot, etc). Useful for:

  • 2d games using bevy's lighting (orthographic camera, 3d sprites)
  • 2d games with easier parallax and scale (perspective camera, 3d sprites)
  • 2d games in a 3d world (perspective camera, both 3d sprites and meshes)
  • 3d games with billboard sprites (a la Delver)

Both meshes and materials are internally cached, so this crate can be used for things like tilemaps without issue.

Examples

Example using bevy_sprite3d:

chaos

A more complicated scene: examples/dungeon.rs. Try this one with cargo run --example dungeon.

https://github.com/FraserLee/bevy_sprite3d/assets/30442265/1821b13c-9770-4f4e-a889-f67e06a3cda6

Some more examples. These don't use bevy, but demonstrate the effect style:

the last night

the last night

hollow knight

Usage

Check out the examples for details. Tl;dr initialize the plugin with

app.add_plugin(Sprite3dPlugin)

and spawn sprites with

fn setup(
    mut commands: Commands,
    images: Res<ImageAssets>, // this is your custom resource populated with asset handles
    mut sprite_params: Sprite3dParams
) {

    // ----------------------- Single Static Sprite ----------------------------

    commands.spawn(Sprite3d {
            image: images.sprite.clone(),

            pixels_per_metre: 400.,

            partial_alpha: true,

            unlit: true,

            ..default()

            // transform: Transform::from_xyz(0., 0., 0.),
            // pivot: Some(Vec2::new(0.5, 0.5)),
            // double_sided: true,

    }.bundle(&mut sprite_params));

    // ------------------- Texture Atlas (Sprite Sheet) ------------------------

    let texture_atlas = TextureAtlas {
        layout: images.layout.clone(),
        index: 3,
    };

    commands.spawn(Sprite3d {
            image: images.sprite_sheet.clone(),

            pixels_per_metre: 32.,
            partial_alpha: true,
            unlit: true,

            ..default()

            // transform: Transform::from_xyz(0., 0., 0.),
            // pivot: Some(Vec2::new(0.5, 0.5)),
            // double_sided: true,

    }.bundle_with_atlas(&mut sprite_params, texture_atlas));
}

One small complication: your image assets should be loaded prior to spawning, as bevy_sprite3d uses some properties of the image (such as size and aspect ratio) in constructing the 3d mesh. Examples show how to do this with Bevy's States.

Versioning

bevy_sprite3d version bevy version
4.0 0.15
3.0 0.14
2.8 0.13
2.7 0.12
2.5 - 2.6 0.11
2.4 0.10
2.1 - 2.3 0.9
1.1 - 2.0 0.8
1.0 0.7

Dependencies

~42–75MB
~1.5M SLoC