Fast, optimal, real-time decal spraying. Based on Unity MeshDecal.
Can be modified to use custom materials, animated sprites or a single texture sprite-sheet.
Apply decals to dynamic physics objects and complex meshes: examples/paint_thrower.rs
.
Try it out with cargo run --example paint_thrower
.
Check out the examples for details. Tl;dr initialize the plugin with
app.add_plugin(DecalPlugin)
and spawn decals with
fn setup(
mut commands: Commands,
assets: Res<AssetServer>,
mut standard_materials: ResMut<Assets<StandardMaterial>>,
) {
// Material of the spray
let spray_material = standard_materials.add(
StandardMaterial {
base_color_texture: Some(assets.load("graffiti1.png").clone()),
alpha_mode: AlphaMode::Mask(0.5),
..default()
}
)
// Spawn an object to spray a Decal on
commands.spawn((
PbrBundle {
mesh: assets.load("cube.obj"),
material: standard_materials.add(
StandardMaterial {
base_color: Color::GREEN,
..default()
}
),
transform: Transform::from_translation(Vec3::NEG_Y * 5.),
..default()
}
));
// Spray transform. In this case spraying straight down, scaled by 2 and reaching 12 meters down
let spray_transform = Transform::from_translation(Vec3::Y)
.with_scale(Vec3::ONE * 2. + Vec3::Z * 10.)
.looking_to(Vec3::NEG_Y, Vec3::Y);
// Finally spray the decal, which will be applied next frame
spray_decal(&mut commands, spray_material.clone(), spray_transform);
}
bevy_mesh_decal version |
bevy version |
---|---|
1.0.0 | 0.14 |
Tip
This code can easily be ported to most earler bevy versions