diff --git a/Cargo.toml b/Cargo.toml index ae7a8bd..d17c38e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "bevy_mod_outline" -version = "0.2.4" +version = "0.3.0" edition = "2021" license = "MIT OR Apache-2.0" description = "A mesh outlining plugin for Bevy." @@ -26,14 +26,17 @@ bevy = { version = "0.8", default-features = false, features = [ ] } [features] -default = ["align16", "bevy_ui"] -align16 = [] +default = ["bevy_ui"] bevy_ui = ["bevy/bevy_ui", "bevy/bevy_sprite", "bevy/bevy_text"] [[example]] name = "shapes" path = "examples/shapes.rs" +[[example]] +name = "pieces" +path = "examples/pieces.rs" + [[example]] name = "animated_fox" path = "examples/animated_fox.rs" diff --git a/examples/pieces.rs b/examples/pieces.rs new file mode 100644 index 0000000..0f63213 --- /dev/null +++ b/examples/pieces.rs @@ -0,0 +1,139 @@ +use std::f32::consts::TAU; + +use bevy::{ + prelude::{ + shape::{Capsule, Torus, UVSphere}, + *, + }, + window::close_on_esc, +}; + +use bevy_mod_outline::*; + +#[bevy_main] +fn main() { + App::new() + .insert_resource(Msaa { samples: 4 }) + .insert_resource(ClearColor(Color::BLACK)) + .add_plugins(DefaultPlugins) + .add_plugin(OutlinePlugin) + .add_startup_system(setup) + .add_system(close_on_esc) + .add_system(rotates) + .run(); +} + +#[derive(Component)] +struct Rotates; + +fn setup( + mut commands: Commands, + mut meshes: ResMut>, + mut materials: ResMut>, +) { + // Add sphere with child meshes sticking out of it + commands + .spawn_bundle(PbrBundle { + mesh: meshes.add( + UVSphere { + radius: 0.75, + sectors: 30, + stacks: 30, + } + .into(), + ), + material: materials.add(Color::rgb(0.9, 0.1, 0.1).into()), + transform: Transform::from_translation(Vec3::new(0.0, 1.0, 0.0)), + + ..default() + }) + .insert_bundle(OutlineBundle { + outline: Outline { + visible: true, + colour: Color::WHITE, + width: 10.0, + }, + ..default() + }) + .insert(Rotates) + .with_children(|parent| { + parent + .spawn_bundle(PbrBundle { + mesh: meshes.add( + Capsule { + radius: 0.2, + rings: 15, + depth: 1.0, + latitudes: 15, + longitudes: 15, + ..Default::default() + } + .into(), + ), + material: materials.add(Color::rgb(0.1, 0.1, 0.9).into()), + transform: Transform::from_rotation(Quat::from_axis_angle(Vec3::X, TAU / 4.0)) + .with_translation(Vec3::new(0.0, 0.0, 0.75)), + ..default() + }) + .insert_bundle(OutlineBundle { + outline: Outline { + visible: true, + colour: Color::WHITE, + width: 10.0, + }, + ..default() + }) + .insert(InheritOutlinePlane); + parent + .spawn_bundle(PbrBundle { + mesh: meshes.add( + Torus { + radius: 0.5, + ring_radius: 0.1, + subdivisions_segments: 30, + subdivisions_sides: 15, + } + .into(), + ), + material: materials.add(Color::rgb(0.1, 0.1, 0.9).into()), + transform: Transform::from_rotation(Quat::from_axis_angle(Vec3::Z, TAU / 4.0)) + .with_translation(Vec3::new(0.0, 0.0, -0.75)), + ..default() + }) + .insert_bundle(OutlineBundle { + outline: Outline { + visible: true, + colour: Color::WHITE, + width: 10.0, + }, + ..default() + }) + .insert(InheritOutlinePlane); + }); + + // Add plane, light source, and camera + commands.spawn_bundle(PbrBundle { + mesh: meshes.add(Mesh::from(bevy::prelude::shape::Plane { size: 5.0 })), + material: materials.add(Color::rgb(0.3, 0.5, 0.3).into()), + ..default() + }); + commands.spawn_bundle(PointLightBundle { + point_light: PointLight { + intensity: 1500.0, + shadows_enabled: true, + ..default() + }, + transform: Transform::from_xyz(4.0, 8.0, 4.0), + ..default() + }); + commands.spawn_bundle(Camera3dBundle { + transform: Transform::from_xyz(-2.0, 2.5, 5.0).looking_at(Vec3::ZERO, Vec3::Y), + ..default() + }); +} + +fn rotates(mut query: Query<&mut Transform, With>, timer: Res