Giter VIP home page Giter VIP logo

bevy_sprite3d's Introduction

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.

bevy_sprite3d.cutout.shadows.mp4

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>,
    mut sprite_params: Sprite3dParams
) {

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

    commands.spawn_bundle(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) ------------------------

    commands.spawn_bundle(AtlasSprite3d {
            atlas: images.sprite_sheet.clone(),

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

            index: 3,

            ..default()

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

    }.bundle(&mut sprite_params));
}

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
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

bevy_sprite3d's People

Contributors

fraserlee avatar vertesians avatar bardt avatar deukhoofd avatar rs017991 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.