Crates.io | bevy_sprite3d |
lib.rs | bevy_sprite3d |
version | |
source | src |
created_at | 2022-07-29 19:44:40.059018 |
updated_at | 2024-12-04 05:38:44.252236 |
description | Bevy Plugin to allow using 2d sprites in a 3d scene. |
homepage | |
repository | https://github.com/FraserLee/bevy_sprite3d |
max_upload_size | |
id | 635139 |
Cargo.toml error: | TOML parse error at line 17, column 1 | 17 | autolib = false | ^^^^^^^ unknown field `autolib`, expected one of `name`, `version`, `edition`, `authors`, `description`, `readme`, `license`, `repository`, `homepage`, `documentation`, `build`, `resolver`, `links`, `default-run`, `default_dash_run`, `rust-version`, `rust_dash_version`, `rust_version`, `license-file`, `license_dash_file`, `license_file`, `licenseFile`, `license_capital_file`, `forced-target`, `forced_dash_target`, `autobins`, `autotests`, `autoexamples`, `autobenches`, `publish`, `metadata`, `keywords`, `categories`, `exclude`, `include` |
size | 0 |
Use 2d sprites in a 3d bevy scene.
This is a pretty common setup in other engines (unity, godot, etc). Useful for:
(orthographic camera, 3d sprites)
(perspective camera, 3d sprites)
(perspective camera, both 3d sprites and meshes)
Both meshes and materials are internally cached, so this crate can be used for things like tilemaps without issue.
Example using bevy_sprite3d
:
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:
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
.
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 |