From 2d4960dc7e687862a3ef48e6e436eb32dd90790a Mon Sep 17 00:00:00 2001 From: VirxEC Date: Sun, 19 May 2024 23:15:05 -0400 Subject: [PATCH] New fields colors showing orange/blue field sides --- Cargo.lock | 2 +- Cargo.toml | 3 ++- src/assets.rs | 69 ++++++++++++++++++++++++++++++++---------------- src/camera.rs | 2 +- src/main.rs | 2 +- src/mesh.rs | 27 +++++++++++++++++-- src/rocketsim.rs | 2 +- src/udp.rs | 16 ++++++++--- 8 files changed, 90 insertions(+), 33 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 52b16a1..b5704b9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3052,7 +3052,7 @@ checksum = "3582f63211428f83597b51b2ddb88e2a91a9d52d12831f9d08f5e624e8977422" [[package]] name = "rlviser" -version = "0.7.4" +version = "0.7.5" dependencies = [ "ahash", "bevy", diff --git a/Cargo.toml b/Cargo.toml index d0323f7..f7e3bb4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,5 +1,5 @@ [package] -version = "0.7.4" +version = "0.7.5" name = "rlviser" edition = "2021" publish = false @@ -35,6 +35,7 @@ features = ["bevy_core_pipeline", "bevy_pbr", "bevy_ui", "wayland", "x11", "tga" full_load = [] ssao = [] team_goal_barriers = [] +debug = [] # Enable a small amount of optimization in debug mode [profile.dev] diff --git a/src/assets.rs b/src/assets.rs index 8e3baeb..1e5d579 100644 --- a/src/assets.rs +++ b/src/assets.rs @@ -1,4 +1,7 @@ -use crate::mesh::{MeshBuilder, MeshBuilderError}; +use crate::{ + mesh::{MeshBuilder, MeshBuilderError}, + rocketsim::Team, +}; use bevy::{ asset::{io::Reader, AssetLoader, AsyncReadExt}, prelude::*, @@ -251,14 +254,19 @@ fn is_in_whitelist(_name: &str) -> bool { true } -fn retreive_material(name: &str, asset_server: &AssetServer, base_color: Color) -> Option { +fn retreive_material( + name: &str, + asset_server: &AssetServer, + base_color: Color, + side: Option, +) -> Option { if name.is_empty() { return None; } if !is_in_whitelist(name) { // load custom material instead - return get_default_material(name); + return get_default_material(name, side); } debug!("Retreiving material {name}"); @@ -400,25 +408,31 @@ fn retreive_material(name: &str, asset_server: &AssetServer, base_color: Color) Some(material) } -fn get_default_material(name: &str) -> Option { - let mut material = if [ +fn get_default_material(name: &str, side: Option) -> Option { + let color = if [ "Stadium_Assets.Materials.Grass_Base_Team1_MIC", "Proto_BBall.Materials.WoodFloor_Corrected_Mat_INST", ] .contains(&name) { // primary - StandardMaterial::from(Color::rgb_u8(45, 49, 66)) + Color::rgb_u8(45, 49, 66) } else if [ "FutureTech.Materials.Reflective_Floor_V2_Mat", - "Proto_BBall.Materials.BBall_Rubber_MIC", "Proto_BBall.SM.BackBoard_Teams_MIC", + "Proto_BBall.Materials.BBall_Rubber_MIC", "Proto_BBall.Materials.MIC_DarkGlass", ] .contains(&name) { // secondary - StandardMaterial::from(Color::rgb_u8(79, 93, 117)) + match side { + Some(Team::Blue) => Color::rgb_u8(86, 136, 199), + Some(Team::Orange) => Color::rgb_u8(222, 145, 81), + None => Color::rgb_u8(131, 144, 115), + } + } else if name == "OOBFloor_MAT_CUSTOM" { + Color::rgb_u8(41, 2, 0) } else if [ "FutureTech.Materials.Frame_01_MIC", "FutureTech.Materials.Frame_01_V2_Mat", @@ -434,30 +448,32 @@ fn get_default_material(name: &str) -> Option { || name.contains("PaintedLine_MIC") { // tertiary - StandardMaterial::from(Color::rgb_u8(55, 30, 48)) + Color::rgb_u8(55, 30, 48) } else if [ "FutureTech.Materials.Frame_01_White_MIC", "Graybox_Assets.Materials.ForceFieldCage_Solid_Mat", ] .contains(&name) { - StandardMaterial::from(Color::SILVER) + Color::SILVER } else if name == "FutureTech.Materials.CrossHatched_Grate_MIC" { - StandardMaterial::from(Color::TOMATO) + Color::TOMATO } else if [ "Pickup_Boost.Materials.BoostPad_Small_MIC", "Pickup_Boost.Materials.BoostPad_Large_MIC", ] .contains(&name) { - StandardMaterial::from(Color::rgb_u8(152, 29, 23)) + Color::rgb_u8(152, 29, 23) } else if name.contains("Advert") || name.contains("DarkMetal") { - StandardMaterial::from(Color::rgb_u8(191, 192, 192)) + Color::rgb_u8(191, 192, 192) } else { println!("Unknown material {name}"); return None; }; + let mut material = StandardMaterial::from(color); + if TRANSPARENT_MATS.contains(&name) { material.alpha_mode = AlphaMode::Blend; } else if ADD_MATS.contains(&name) { @@ -475,32 +491,39 @@ fn get_default_material(name: &str) -> Option { Some(material) } -static MATERIALS: Mutex, Handle>>> = Mutex::new(Lazy::new(HashMap::new)); +type MaterialsKey = (&'static str, Option); +static MATERIALS: Mutex>>> = Mutex::new(Lazy::new(HashMap::new)); pub fn get_material( name: &str, materials: &mut Assets, asset_server: &AssetServer, base_color: Option, + side: Option, ) -> Handle { let mut material_names = MATERIALS.lock().unwrap(); - if let Some(material) = material_names.get(name) { + let name: &'static str = Box::leak(Box::from(name)); + let key = (name, side); + + if let Some(material) = material_names.get(&key) { return material.clone(); } let base_color = base_color.unwrap_or(Color::rgb(0.3, 0.3, 0.3)); material_names - .entry(Box::from(name)) + .entry(key) .or_insert_with(|| { - materials.add(retreive_material(name, asset_server, base_color).unwrap_or(StandardMaterial { - base_color, - metallic: 0.1, - cull_mode: None, - double_sided: true, - ..default() - })) + materials.add( + retreive_material(name, asset_server, base_color, side).unwrap_or(StandardMaterial { + base_color, + metallic: 0.1, + cull_mode: None, + double_sided: true, + ..default() + }), + ) }) .clone() } diff --git a/src/camera.rs b/src/camera.rs index 450d44a..a542e6b 100644 --- a/src/camera.rs +++ b/src/camera.rs @@ -179,7 +179,7 @@ fn daylight_cycle( atmosphere.sun_position = sun_position; if let Some((mut light_trans, mut directional)) = query.single_mut().into() { - light_trans.translation = sun_position * 10_000_000.; + light_trans.translation = sun_position * 100_000.; light_trans.look_at(Vec3::ZERO, Vec3::Y); directional.illuminance = t.sin().max(0.0).powi(2) * 10000.; } diff --git a/src/main.rs b/src/main.rs index d238f66..0876c19 100644 --- a/src/main.rs +++ b/src/main.rs @@ -71,7 +71,7 @@ fn main() { }),)) .add_plugins(( LogDiagnosticsPlugin { - debug: cfg!(debug_assertions), + debug: cfg!(feature = "debug"), ..default() }, camera::CameraPlugin, diff --git a/src/mesh.rs b/src/mesh.rs index 0357b8f..33ee17a 100644 --- a/src/mesh.rs +++ b/src/mesh.rs @@ -1,7 +1,7 @@ use crate::{ assets::*, camera::{HighlightedEntity, PrimaryCamera}, - rocketsim::GameMode, + rocketsim::{GameMode, Team}, settings::{ default_field::{get_hoops_floor, get_standard_floor, load_hoops, load_standard}, state_setting::{EnableBallInfo, EnableCarInfo, EnablePadInfo, UserCarStates, UserPadStates}, @@ -25,6 +25,7 @@ use bevy_mod_picking::{backends::raycast::RaycastPickable, prelude::*}; use include_flate::flate; use serde::Deserialize; use std::{ + cmp::Ordering, io::{self, Read}, path::Path, rc::Rc, @@ -707,7 +708,29 @@ fn process_info_node( continue; } - let material = get_material(mat, materials, asset_server, None); + let side_signum = if node.static_mesh.contains("BBall_HoopBackBoard_02") { + if node.rotation.is_some() { + -1 + } else { + 1 + } + } else { + node.translation.map(|t| (t[1] as i16).signum()).unwrap_or_default() + }; + + let side = match side_signum.cmp(&0) { + Ordering::Greater => Some(Team::Orange), + Ordering::Less => Some(Team::Blue), + _ => None, + }; + + let mat_name = if !cfg!(features = "full_load") && node.static_mesh.ends_with("OOBFloor") { + "OOBFloor_MAT_CUSTOM" + } else { + mat.as_ref() + }; + + let material = get_material(mat_name, materials, asset_server, None, side); let mut transform = node.get_transform(); diff --git a/src/rocketsim.rs b/src/rocketsim.rs index c5c5f3d..b870658 100644 --- a/src/rocketsim.rs +++ b/src/rocketsim.rs @@ -69,7 +69,7 @@ impl Default for BallState { } #[repr(u8)] -#[derive(Clone, Copy, Default, Debug)] +#[derive(Clone, Copy, Default, Debug, PartialEq, Eq, Hash)] pub enum Team { #[default] Blue, diff --git a/src/udp.rs b/src/udp.rs index 3e983ab..265455c 100644 --- a/src/udp.rs +++ b/src/udp.rs @@ -259,7 +259,7 @@ fn spawn_car( const CAR_BOOST_LENGTH: f32 = 50.; if cfg!(feature = "full_load") { - let mesh_materials = get_car_mesh_materials(mesh_id, materials, asset_server, base_color); + let mesh_materials = get_car_mesh_materials(mesh_id, materials, asset_server, base_color, car_info.team); mesh_info .into_iter() @@ -338,6 +338,7 @@ fn get_car_mesh_materials( materials: &mut Assets, asset_server: &AssetServer, base_color: Color, + side: Team, ) -> Vec> { let mesh_path = mesh_id.replace('.', "/"); let props = fs::read_to_string(format!("./assets/{mesh_path}.props.txt")).unwrap(); @@ -362,7 +363,13 @@ fn get_car_mesh_materials( let material_name = line.split('\'').nth(1).unwrap(); - mesh_materials.push(get_material(material_name, materials, asset_server, Some(base_color))); + mesh_materials.push(get_material( + material_name, + materials, + asset_server, + Some(base_color), + Some(side), + )); } mesh_materials } @@ -863,7 +870,10 @@ fn update_camera( PrimaryCamera::Spectator => return, }; - let (car_transform, _) = cars.iter_mut().find(|(_, car)| car.id() == car_id).unwrap(); + let Some((car_transform, _)) = cars.iter_mut().find(|(_, car)| car.id() == car_id) else { + return; + }; + let Some(target_car) = states.current.cars.iter().find(|car_info| car_id == car_info.id) else { return; };