From 837ea1ab403e63672a69dbf76b58654eae709c28 Mon Sep 17 00:00:00 2001 From: Franklin Date: Wed, 29 Nov 2023 07:56:01 -0400 Subject: [PATCH] custom Sight glass for each optic. Done --- Design.md | 8 +++---- assets/attachments/aimpoint_t1.glb | Bin 1489884 -> 1489896 bytes src/comps/core/markers/proxy/plugin.rs | 6 +++++- .../proxy/weapons/optic_sight_glass.rs | 18 ++++++++++------ src/comps/core/weapons/attachments/optic.rs | 20 +++++++++++++++++- 5 files changed, 40 insertions(+), 12 deletions(-) diff --git a/Design.md b/Design.md index 28cd7ae..678cdba 100644 --- a/Design.md +++ b/Design.md @@ -37,9 +37,9 @@ Multiplayer - [x] Gun colliding with bullet, making it lower on every shot fired. - [x] Optics - [x] All optics implementing a fn/trait that gives a specific gun offset to use the optic correctly - - [ ] TODO: Find some way to implement a shader for the optics (AFTER IMPLEMENTING NEW BULLET SYSTEM) - - [ ] Optic glass material - - [ ] Reticle render + - [x] Find some way to implement a shader for the optics (AFTER IMPLEMENTING NEW BULLET SYSTEM) + - [x] Optic glass material + - [ ] TODO: Reticle render - [ ] Parallax effect on reticle - [ ] Weapon Clipping - [x] Make the player's collider bigger towards the front @@ -56,7 +56,7 @@ Multiplayer - [x] Gun dropping does not apply impulse for some reason... - [x] Gun colliding with ground and going into low ready - [x] With introduction of floor collision groups now bullets go through floors -- [x] TODO: Huge bug all attachments get despawned and spawned when gun shoots +- [x] Huge bug all attachments get despawned and spawned when gun shoots # Design diff --git a/assets/attachments/aimpoint_t1.glb b/assets/attachments/aimpoint_t1.glb index 4e3173e9179335546bb7d94beefa6b2e0f495c81..4e8d0b471d3e99fad14ff8b1d860b04599c168ed 100644 GIT binary patch delta 136 zcmccfJ?h2xDBkp(5H}_U28I{A#Tf2va?H#v$j{6x2{GIp$T*pkNkO6c30M0Q zE=C|`0%B$$W&vVWAZ7z%b|B^eVoo3ispAG>9w6ogVm=_|2Vwyr76f7;AQlE<5g-=b K{)9{H#|8kJF*AYy delta 122 zcmaFyJ?hT)DBkp(5H}_U28KJk#TYJZ(); app.register_type::(); + // Debug for creating materials + app.register_type::(); + app.insert_resource(DebugMaterialResource::default()); + app.add_systems(Update, (physics_replace_proxies, update_game_load_state)); app.add_systems(Update, insert_components_into_spawned_player); app.add_systems(Update, insert_components_into_player_hand); diff --git a/src/comps/core/markers/proxy/weapons/optic_sight_glass.rs b/src/comps/core/markers/proxy/weapons/optic_sight_glass.rs index f942f49..a504188 100644 --- a/src/comps/core/markers/proxy/weapons/optic_sight_glass.rs +++ b/src/comps/core/markers/proxy/weapons/optic_sight_glass.rs @@ -1,21 +1,27 @@ use bevy::prelude::*; +use crate::comps::core::weapons::attachments::optic::Optic; + #[derive(Default, Component, Reflect, Debug)] #[reflect(Component)] -pub struct OpticSightGlass; +pub struct OpticSightGlass (pub Optic); + +#[derive(Default, Resource, Reflect, Debug)] +#[reflect(Resource)] +pub struct DebugMaterialResource(StandardMaterial); pub fn replace_optic_sight_material( //mut commands: Commands, - marker_query: Query>, + marker_query: Query<(Entity, &OpticSightGlass), Added>, materials_query: Query<(&Parent, &Handle), With>>, mut materials: ResMut>, + debug_mat: Res ) { - for marker in marker_query.iter() { - println!("One marker once"); + for (marker, optic_sight_glass) in marker_query.iter() { for (material_parent, material_handle) in materials_query.iter() { if marker == material_parent.get() { - if let Some(mut material) = materials.get_mut(material_handle) { - println!("Changed material"); + if let Some(material) = materials.get_mut(material_handle) { + *material = optic_sight_glass.0.sight_glass_material(); } } } diff --git a/src/comps/core/weapons/attachments/optic.rs b/src/comps/core/weapons/attachments/optic.rs index c9f2bf5..718c59b 100644 --- a/src/comps/core/weapons/attachments/optic.rs +++ b/src/comps/core/weapons/attachments/optic.rs @@ -1,4 +1,5 @@ -use bevy::{reflect::{Reflect, std_traits::ReflectDefault}, ecs::{component::Component, reflect::ReflectComponent}, math::Vec3}; +use bevy::{reflect::{Reflect, std_traits::ReflectDefault}, ecs::{component::Component, reflect::ReflectComponent}, math::Vec3, pbr::StandardMaterial, render::color::Color}; +use bevy_inspector_egui::egui::Rgba; use super::attachment::Attachment; @@ -16,6 +17,23 @@ impl Optic { Optic::AimpointT1 => Vec3 { x: 0.0, y: -0.05, z: 0.0 }, } } + pub fn sight_glass_material(&self) -> StandardMaterial { + match self { + Optic::AimpointT1 => { + StandardMaterial { + base_color: Color::Rgba { red: 0.0, green: 0.47, blue: 0.42, alpha: 0.48 }, + reflectance: 0.0, + diffuse_transmission: -2.0, + specular_transmission: -1.8, + thickness: 0.0, + ior: 0.0, + attenuation_distance: 1.0, + alpha_mode: bevy::pbr::AlphaMode::Blend, + ..Default::default() + } + }, + } + } } impl Attachment for Optic {