Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Outlines #267

Open
wants to merge 1 commit into
base: act-2-bevy
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions sbepis/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ blenvy = { git = "https://github.com/jwright159/Blenvy.git" }
bevy-butler = "0.5.4-alpha.3"
bevy_hanabi = "0.14.0"
typetag = "0.2.19"
bevy_edge_detection = "0.15.4"
bevy_mod_outline = {version="0.9.0", git="https://github.com/komadori/bevy_mod_outline.git"}

[build-dependencies]
winres = "0.1"
22 changes: 13 additions & 9 deletions sbepis/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ use bevy::input::common_conditions::input_just_pressed;
use bevy::log::LogPlugin;
use bevy::prelude::*;
use bevy::winit::WinitWindows;
use bevy_edge_detection::EdgeDetectionPlugin;
use bevy_mod_outline::OutlinePlugin;
use bevy_rapier3d::prelude::*;
use winit::window::Icon;

Expand Down Expand Up @@ -58,20 +60,22 @@ fn main() {
},
})
.set(LogPlugin {
filter: "info,sbepis=debug,avian3d=debug,wgpu=error,naga=warn,calloop=error,symphonia_core=warn,symphonia_bundle_mp3=warn,blenvy=error".into(),
filter: "info,sbepis=debug,avian3d=debug,wgpu=error,naga=warn,calloop=error,symphonia_core=warn,symphonia_bundle_mp3=warn,blenvy=error,bevy_mod_outline=error".into(),
..default()
}),
RapierPhysicsPlugin::<NoUserData>::default(),
#[cfg(feature = "rapier_debug")]
RapierDebugRenderPlugin::default(),
#[cfg(feature = "inspector")]
bevy_inspector_egui::quick::WorldInspectorPlugin::new(),
#[cfg(feature = "overview_camera")]
overview_camera::OverviewCameraPlugin,
bevy_hanabi::HanabiPlugin,
OutlinePlugin,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This particular line should not be indented... Do you have cargo fmt and format-on-save?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

stuffs broken on windows. cant fix rn, will do cargo fmt and commit.

));

app.add_plugins((
#[cfg(feature = "rapier_debug")]
RapierDebugRenderPlugin::default(),
#[cfg(feature = "inspector")]
bevy_inspector_egui::quick::WorldInspectorPlugin::new(),
#[cfg(feature = "overview_camera")]
overview_camera::OverviewCameraPlugin,
EdgeDetectionPlugin::default(),
RapierPhysicsPlugin::<NoUserData>::default(),
bevy_hanabi::HanabiPlugin,
Comment on lines +70 to +78
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had these set up in the above add_plugin so we wouldn't run into issues in having too many tuple elements

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah this doesn't even compile

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it does for me, I will fix this, I know what I changed.

player_commands::PlayerCommandsPlugin,
camera::PlayerCameraPlugin,
skybox::SkyboxPlugin,
Expand Down
65 changes: 37 additions & 28 deletions sbepis/src/npcs/consort.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use crate::entity::{Healing, RandomInput, RotateTowardMovement, SpawnHealthBar};
use crate::gridbox_material;
use crate::main_bundles::Mob;
use crate::npcs::NpcPlugin;
use crate::player_controller::camera_controls::InteractOutlineComponentTarget;
use crate::questing::{QuestGiver, SpawnQuestMarker};

use super::name_tags::SpawnNameTag;
Expand Down Expand Up @@ -39,36 +40,44 @@ fn spawn_consort(
continue;
}

commands.entity(ev.entity).insert((
Name::new("Consort"),
Transform::from_translation(ev.position),
Mob,
SpawnHealthBar,
RandomInput::default(),
Healing(0.2),
RotateTowardMovement,
Consort,
QuestGiver::default(),
SpawnQuestMarker,
SpawnNameTag,
));
let mut id = None;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a way better way to get child Entities. Just call let id = commands.spawn(...).set_parent(ev.entity).id();

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice!

commands.entity(ev.entity).with_children(|parent| {
id = Some(
parent
.spawn((
Transform::from_translation(Vec3::Y * 0.5),
Mesh3d(
meshes.add(
Capsule3d::new(0.25, 0.5)
.mesh()
.rings(1)
.latitudes(8)
.longitudes(16)
.uv_profile(CapsuleUvProfile::Fixed),
),
),
MeshMaterial3d(gridbox_material("magenta", &mut materials, &asset_server)),
Collider::capsule_y(0.25, 0.25),
))
.id(),
);
});
commands
.entity(ev.entity)
.insert((
Name::new("Consort"),
Transform::from_translation(ev.position),
Mob,
SpawnHealthBar,
RandomInput::default(),
Healing(0.2),
RotateTowardMovement,
Consort,
QuestGiver::default(),
SpawnQuestMarker,
SpawnNameTag,
))
.with_child((
Transform::from_translation(Vec3::Y * 0.5),
Mesh3d(
meshes.add(
Capsule3d::new(0.25, 0.5)
.mesh()
.rings(1)
.latitudes(8)
.longitudes(16)
.uv_profile(CapsuleUvProfile::Fixed),
),
),
MeshMaterial3d(gridbox_material("magenta", &mut materials, &asset_server)),
Collider::capsule_y(0.25, 0.25),
));
.insert(InteractOutlineComponentTarget(id.unwrap()));
ev_spawned.send(EntitySpawned(ev.entity));
}
}
64 changes: 57 additions & 7 deletions sbepis/src/player_controller/camera_controls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use std::marker::PhantomData;

use bevy::prelude::*;
use bevy_butler::*;
use bevy_mod_outline::OutlineVolume;
use bevy_rapier3d::prelude::*;
use leafwing_input_manager::prelude::*;

Expand Down Expand Up @@ -64,21 +65,24 @@ fn rotate_camera_and_body(
}
}

#[resource(plugin = PlayerControllerPlugin, init = LastHitEntity(None))]
#[derive(Resource)]
pub struct LastHitEntity(pub Option<Entity>);

#[derive(Component)]
pub struct InteractOutlineComponentTarget(pub Entity);

pub fn interact_with<T: Component>(
rapier_context: Query<&RapierContext>,
player_camera: Query<&GlobalTransform, With<PlayerCamera>>,
entities: Query<Entity, With<T>>,
parents: Query<&Parent>,
input: Query<&ActionState<PlayerAction>>,
outline_targets: Query<&InteractOutlineComponentTarget>,
mut commands: Commands,
mut last_hit: ResMut<LastHitEntity>,
mut ev_interact: EventWriter<InteractedWith<T>>,
) {
if !match input.iter().find(|input| !input.disabled()) {
Some(input) => input.just_pressed(&PlayerAction::Interact),
None => false,
} {
return;
}

let player_camera = player_camera.get_single().expect("Player camera missing");
let mut hit_entity: Option<(Option<Entity>, f32)> = None;
rapier_context.single().intersections_with_ray(
Expand All @@ -102,6 +106,52 @@ pub fn interact_with<T: Component>(
},
);

if let Some((Some(entity), _)) = hit_entity {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BTW there is some flickering in the selection here.... any ideas why? I'll have to debug this sooner or later....

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

its only every other time I run the game too which sucks.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did see that, I have NO idea-- oh wait it's probably system run order race condition stuff. run the shader system after = whatever_the_interact_system_is_called

if last_hit.0.is_none() {
for target in outline_targets.get(entity).iter() {
commands.entity(target.0).insert(OutlineVolume {
colour: Color::Srgba(Srgba {
red: 1.0,
green: 1.0,
blue: 1.0,
alpha: 1.0,
}),
visible: true,
width: 1.0,
});
}
}
match last_hit.0 {
None => {}
Some(last_hit_entity) => {
if last_hit_entity != entity {
for target in outline_targets.get(last_hit_entity).iter() {
commands.entity(target.0).remove::<OutlineVolume>();
}
last_hit.0 = None;
}
}
}
last_hit.0 = Some(entity);
} else {
match last_hit.0 {
None => {}
Some(last_hit_entity) => {
for target in outline_targets.get(last_hit_entity).iter() {
commands.entity(target.0).remove::<OutlineVolume>();
}
last_hit.0 = None;
}
}
}

if !match input.iter().find(|input| !input.disabled()) {
Some(input) => input.just_pressed(&PlayerAction::Interact),
None => false,
} {
return;
}

if let Some((Some(entity), _)) = hit_entity {
ev_interact.send(InteractedWith::new(entity));
}
Expand Down
14 changes: 8 additions & 6 deletions sbepis/src/player_controller/mod.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
use std::f32::consts::PI;

use bevy::prelude::*;
use bevy::render::mesh::CapsuleUvProfile;
use bevy_butler::*;
use bevy_rapier3d::prelude::*;
use leafwing_input_manager::prelude::*;

use crate::camera::PlayerCamera;
use crate::gridbox_material;
use crate::input::*;
Expand All @@ -14,6 +8,12 @@ use crate::main_bundles::Mob;
use crate::menus::{
InputManagerMenuPlugin, Menu, MenuStack, MenuWithInputManager, MenuWithoutMouse,
};
use bevy::prelude::*;
use bevy::render::mesh::CapsuleUvProfile;
use bevy_butler::*;
use bevy_edge_detection::EdgeDetection;
use bevy_rapier3d::prelude::*;
use leafwing_input_manager::prelude::*;

use self::camera_controls::*;
use self::weapons::hammer::*;
Expand Down Expand Up @@ -98,6 +98,8 @@ fn setup(
..default()
}),
PlayerCamera,
Msaa::Off,
EdgeDetection::default(),
Pitch(0.0),
SpatialListener::new(-0.25),
))
Expand Down