From b558331b329d97bc6122eda73f369ebe0a5fc883 Mon Sep 17 00:00:00 2001 From: Sam Date: Wed, 26 Jan 2022 22:03:52 -0500 Subject: [PATCH] Finishing touches --- assets/voxygen/audio/sfx.ron | 4 +- assets/voxygen/shaders/trail-vert.glsl | 2 +- common/src/comp/ability.rs | 27 ++++++++-- voxygen/anim/src/arthropod/mod.rs | 2 +- voxygen/anim/src/biped_large/mod.rs | 2 +- voxygen/anim/src/biped_small/mod.rs | 2 +- voxygen/anim/src/bird_large/mod.rs | 2 +- voxygen/anim/src/bird_medium/mod.rs | 2 +- voxygen/anim/src/character/mod.rs | 5 +- voxygen/anim/src/dragon/mod.rs | 2 +- voxygen/anim/src/fish_medium/mod.rs | 2 +- voxygen/anim/src/fish_small/mod.rs | 2 +- voxygen/anim/src/fixture/mod.rs | 2 +- voxygen/anim/src/golem/mod.rs | 2 +- voxygen/anim/src/item_drop/mod.rs | 1 + voxygen/anim/src/lib.rs | 2 +- voxygen/anim/src/object/mod.rs | 2 +- voxygen/anim/src/quadruped_low/mod.rs | 2 +- voxygen/anim/src/quadruped_medium/mod.rs | 2 +- voxygen/anim/src/quadruped_small/mod.rs | 2 +- voxygen/anim/src/ship/mod.rs | 2 +- voxygen/anim/src/theropod/mod.rs | 2 +- voxygen/src/scene/figure/mod.rs | 63 ++++++++++++++++++------ voxygen/src/scene/figure/volume.rs | 2 +- voxygen/src/scene/simple.rs | 4 ++ voxygen/src/scene/trail.rs | 2 +- 26 files changed, 100 insertions(+), 44 deletions(-) diff --git a/assets/voxygen/audio/sfx.ron b/assets/voxygen/audio/sfx.ron index b098b45dbf..ca53f57f08 100644 --- a/assets/voxygen/audio/sfx.ron +++ b/assets/voxygen/audio/sfx.ron @@ -517,7 +517,7 @@ ], threshold: 0.5, ), - Attack(BasicMelee, Dagger): ( + Attack(BasicMelee(Action), Dagger): ( files: [ "voxygen.audio.sfx.abilities.swing_sword", ], @@ -551,7 +551,7 @@ ], threshold: 0.5, ), - Attack(BasicMelee, Shield): ( + Attack(BasicMelee(Action), Shield): ( files: [ "voxygen.audio.sfx.abilities.swing", ], diff --git a/assets/voxygen/shaders/trail-vert.glsl b/assets/voxygen/shaders/trail-vert.glsl index c4559a14fa..445f44a3c3 100644 --- a/assets/voxygen/shaders/trail-vert.glsl +++ b/assets/voxygen/shaders/trail-vert.glsl @@ -9,5 +9,5 @@ layout(location = 0) out vec3 f_pos; void main() { f_pos = v_pos; - gl_Position = all_mat * vec4(f_pos, 1); + gl_Position = all_mat * vec4(f_pos - focus_off.xyz, 1); } diff --git a/common/src/comp/ability.rs b/common/src/comp/ability.rs index fde2e1d6b9..95f15f597a 100644 --- a/common/src/comp/ability.rs +++ b/common/src/comp/ability.rs @@ -345,8 +345,12 @@ impl From for Ability { } #[derive(Copy, Clone, Hash, Eq, PartialEq, Debug, Serialize, Deserialize)] +/// A lighter form of character state to pass around as needed for frontend +/// purposes +// Only add to this enum as needed for frontends, not necessary to immediately +// add a variant here when adding a new character state pub enum CharacterAbilityType { - BasicMelee, + BasicMelee(StageSection), BasicRanged, Boost, ChargedMelee(StageSection), @@ -361,12 +365,13 @@ pub enum CharacterAbilityType { RepeaterRanged, BasicAura, SelfBuff, + Other, } impl From<&CharacterState> for CharacterAbilityType { fn from(state: &CharacterState) -> Self { match state { - CharacterState::BasicMelee(_) => Self::BasicMelee, + CharacterState::BasicMelee(data) => Self::BasicMelee(data.stage_section), CharacterState::BasicRanged(_) => Self::BasicRanged, CharacterState::Boost(_) => Self::Boost, CharacterState::DashMelee(data) => Self::DashMelee(data.stage_section), @@ -381,7 +386,23 @@ impl From<&CharacterState> for CharacterAbilityType { CharacterState::RepeaterRanged(_) => Self::RepeaterRanged, CharacterState::BasicAura(_) => Self::BasicAura, CharacterState::SelfBuff(_) => Self::SelfBuff, - _ => Self::BasicMelee, + CharacterState::Idle(_) + | CharacterState::Climb(_) + | CharacterState::Sit + | CharacterState::Dance + | CharacterState::Talk + | CharacterState::Glide(_) + | CharacterState::GlideWield(_) + | CharacterState::Stunned(_) + | CharacterState::Equipping(_) + | CharacterState::Wielding(_) + | CharacterState::Roll(_) + | CharacterState::Blink(_) + | CharacterState::BasicSummon(_) + | CharacterState::SpriteSummon(_) + | CharacterState::UseItem(_) + | CharacterState::SpriteInteract(_) + | CharacterState::Wallrun(_) => Self::Other, } } } diff --git a/voxygen/anim/src/arthropod/mod.rs b/voxygen/anim/src/arthropod/mod.rs index b0dc44d02f..9bbba91d39 100644 --- a/voxygen/anim/src/arthropod/mod.rs +++ b/voxygen/anim/src/arthropod/mod.rs @@ -113,7 +113,7 @@ impl Skeleton for ArthropodSkeleton { orientation: mount_orientation, scale: Vec3::one(), }, - relative_trail_points: None, + weapon_trail_mat: None, } } } diff --git a/voxygen/anim/src/biped_large/mod.rs b/voxygen/anim/src/biped_large/mod.rs index 343692022e..eb805eeafe 100644 --- a/voxygen/anim/src/biped_large/mod.rs +++ b/voxygen/anim/src/biped_large/mod.rs @@ -137,7 +137,7 @@ impl Skeleton for BipedLargeSkeleton { .into(), ..Default::default() }, - relative_trail_points: None, + weapon_trail_mat: None, } } } diff --git a/voxygen/anim/src/biped_small/mod.rs b/voxygen/anim/src/biped_small/mod.rs index 69205faf08..13ece9d2e4 100644 --- a/voxygen/anim/src/biped_small/mod.rs +++ b/voxygen/anim/src/biped_small/mod.rs @@ -83,7 +83,7 @@ impl Skeleton for BipedSmallSkeleton { .into(), ..Default::default() }, - relative_trail_points: None, + weapon_trail_mat: None, } } } diff --git a/voxygen/anim/src/bird_large/mod.rs b/voxygen/anim/src/bird_large/mod.rs index 361e6b8755..30fc73bf2a 100644 --- a/voxygen/anim/src/bird_large/mod.rs +++ b/voxygen/anim/src/bird_large/mod.rs @@ -106,7 +106,7 @@ impl Skeleton for BirdLargeSkeleton { .into(), ..Default::default() }, - relative_trail_points: None, + weapon_trail_mat: None, } } } diff --git a/voxygen/anim/src/bird_medium/mod.rs b/voxygen/anim/src/bird_medium/mod.rs index 55e9984590..ed37962f06 100644 --- a/voxygen/anim/src/bird_medium/mod.rs +++ b/voxygen/anim/src/bird_medium/mod.rs @@ -60,7 +60,7 @@ impl Skeleton for BirdMediumSkeleton { .into(), ..Default::default() }, - relative_trail_points: None, + weapon_trail_mat: None, } } } diff --git a/voxygen/anim/src/character/mod.rs b/voxygen/anim/src/character/mod.rs index ea334491bd..8c24caa42b 100644 --- a/voxygen/anim/src/character/mod.rs +++ b/voxygen/anim/src/character/mod.rs @@ -156,10 +156,7 @@ impl Skeleton for CharacterSkeleton { .into(), ..Default::default() }, - relative_trail_points: Some(( - (main_mat * Vec4::new(0.0, 0.5, -6.0, 1.0)).xyz(), - (main_mat * Vec4::new(0.0, 0.5, -6.0, 1.0)).xyz() + Vec3::unit_z(), - )), + weapon_trail_mat: Some(main_mat), } } } diff --git a/voxygen/anim/src/dragon/mod.rs b/voxygen/anim/src/dragon/mod.rs index 7a825dfbe3..ffd993ccde 100644 --- a/voxygen/anim/src/dragon/mod.rs +++ b/voxygen/anim/src/dragon/mod.rs @@ -81,7 +81,7 @@ impl Skeleton for DragonSkeleton { .into(), ..Default::default() }, - relative_trail_points: None, + weapon_trail_mat: None, } } } diff --git a/voxygen/anim/src/fish_medium/mod.rs b/voxygen/anim/src/fish_medium/mod.rs index d187a3680a..ef062488bf 100644 --- a/voxygen/anim/src/fish_medium/mod.rs +++ b/voxygen/anim/src/fish_medium/mod.rs @@ -60,7 +60,7 @@ impl Skeleton for FishMediumSkeleton { .into(), ..Default::default() }, - relative_trail_points: None, + weapon_trail_mat: None, } } } diff --git a/voxygen/anim/src/fish_small/mod.rs b/voxygen/anim/src/fish_small/mod.rs index eaa6041910..338980b1ba 100644 --- a/voxygen/anim/src/fish_small/mod.rs +++ b/voxygen/anim/src/fish_small/mod.rs @@ -51,7 +51,7 @@ impl Skeleton for FishSmallSkeleton { .into(), ..Default::default() }, - relative_trail_points: None, + weapon_trail_mat: None, } } } diff --git a/voxygen/anim/src/fixture/mod.rs b/voxygen/anim/src/fixture/mod.rs index 1097d91537..f72daab767 100644 --- a/voxygen/anim/src/fixture/mod.rs +++ b/voxygen/anim/src/fixture/mod.rs @@ -37,7 +37,7 @@ impl Skeleton for FixtureSkeleton { Offsets { lantern: None, mount_bone: Transform::default(), - relative_trail_points: None, + weapon_trail_mat: None, } } } diff --git a/voxygen/anim/src/golem/mod.rs b/voxygen/anim/src/golem/mod.rs index 2d9d3e199d..6a81fa6fbe 100644 --- a/voxygen/anim/src/golem/mod.rs +++ b/voxygen/anim/src/golem/mod.rs @@ -83,7 +83,7 @@ impl Skeleton for GolemSkeleton { .into(), ..Default::default() }, - relative_trail_points: None, + weapon_trail_mat: None, } } } diff --git a/voxygen/anim/src/item_drop/mod.rs b/voxygen/anim/src/item_drop/mod.rs index 018be5b393..dd7c8e63b4 100644 --- a/voxygen/anim/src/item_drop/mod.rs +++ b/voxygen/anim/src/item_drop/mod.rs @@ -43,6 +43,7 @@ impl Skeleton for ItemDropSkeleton { .into(), ..Default::default() }, + weapon_trail_mat: None, } } } diff --git a/voxygen/anim/src/lib.rs b/voxygen/anim/src/lib.rs index 21d1636a03..b5244f7ce3 100644 --- a/voxygen/anim/src/lib.rs +++ b/voxygen/anim/src/lib.rs @@ -103,7 +103,7 @@ pub fn init() { lazy_static::initialize(&LIB); } pub struct Offsets { pub lantern: Option>, pub mount_bone: Transform, - pub relative_trail_points: Option<(Vec3, Vec3)>, + pub weapon_trail_mat: Option>, } pub trait Skeleton: Send + Sync + 'static { diff --git a/voxygen/anim/src/object/mod.rs b/voxygen/anim/src/object/mod.rs index 17bca56015..45ee48831c 100644 --- a/voxygen/anim/src/object/mod.rs +++ b/voxygen/anim/src/object/mod.rs @@ -49,7 +49,7 @@ impl Skeleton for ObjectSkeleton { .into(), ..Default::default() }, - relative_trail_points: None, + weapon_trail_mat: None, } } } diff --git a/voxygen/anim/src/quadruped_low/mod.rs b/voxygen/anim/src/quadruped_low/mod.rs index 264717b6c7..74876acf6b 100644 --- a/voxygen/anim/src/quadruped_low/mod.rs +++ b/voxygen/anim/src/quadruped_low/mod.rs @@ -97,7 +97,7 @@ impl Skeleton for QuadrupedLowSkeleton { orientation: mount_orientation, scale: Vec3::one(), }, - relative_trail_points: None, + weapon_trail_mat: None, } } } diff --git a/voxygen/anim/src/quadruped_medium/mod.rs b/voxygen/anim/src/quadruped_medium/mod.rs index 6b3348d5c5..08c1f20d47 100644 --- a/voxygen/anim/src/quadruped_medium/mod.rs +++ b/voxygen/anim/src/quadruped_medium/mod.rs @@ -109,7 +109,7 @@ impl Skeleton for QuadrupedMediumSkeleton { orientation: mount_orientation, scale: Vec3::one(), }, - relative_trail_points: None, + weapon_trail_mat: None, } } } diff --git a/voxygen/anim/src/quadruped_small/mod.rs b/voxygen/anim/src/quadruped_small/mod.rs index 7cc565c4aa..b67c7ddbdc 100644 --- a/voxygen/anim/src/quadruped_small/mod.rs +++ b/voxygen/anim/src/quadruped_small/mod.rs @@ -74,7 +74,7 @@ impl Skeleton for QuadrupedSmallSkeleton { orientation: mount_orientation, scale: Vec3::one(), }, - relative_trail_points: None, + weapon_trail_mat: None, } } } diff --git a/voxygen/anim/src/ship/mod.rs b/voxygen/anim/src/ship/mod.rs index 61462a42be..fd7c8463ee 100644 --- a/voxygen/anim/src/ship/mod.rs +++ b/voxygen/anim/src/ship/mod.rs @@ -53,7 +53,7 @@ impl Skeleton for ShipSkeleton { ), ..Default::default() }, - relative_trail_points: None, + weapon_trail_mat: None, } } } diff --git a/voxygen/anim/src/theropod/mod.rs b/voxygen/anim/src/theropod/mod.rs index 04c9f7e009..51755985bc 100644 --- a/voxygen/anim/src/theropod/mod.rs +++ b/voxygen/anim/src/theropod/mod.rs @@ -84,7 +84,7 @@ impl Skeleton for TheropodSkeleton { .into(), ..Default::default() }, - relative_trail_points: None, + weapon_trail_mat: None, } } } diff --git a/voxygen/src/scene/figure/mod.rs b/voxygen/src/scene/figure/mod.rs index 2d4b8a5c32..e397c1aa3d 100644 --- a/voxygen/src/scene/figure/mod.rs +++ b/voxygen/src/scene/figure/mod.rs @@ -33,8 +33,9 @@ use common::{ comp::{ inventory::slot::EquipSlot, item::{Hands, ItemKind, ToolKind}, - Body, CharacterState, Collider, Controller, Health, Inventory, Item, ItemKey, Last, - LightAnimation, LightEmitter, Ori, PhysicsState, PoiseState, Pos, Scale, Vel, + Body, CharacterAbilityType, CharacterState, Collider, Controller, Health, Inventory, Item, + ItemKey, Last, LightAnimation, LightEmitter, Ori, PhysicsState, PoiseState, Pos, Scale, + Vel, }, link::Is, mounting::Rider, @@ -862,6 +863,8 @@ impl FigureMgr { scale, mount_transform_pos, body: Some(body), + tools: (active_tool_kind, second_tool_kind), + char_ability: character.map(|c| c.into()), col, dt, _lpindex: lpindex, @@ -5368,6 +5371,7 @@ impl FigureMgr { state.skeleton = anim::vek::Lerp::lerp(&state.skeleton, &target_bones, dt_lerp); state.update( renderer, + Some(trail_mgr), &mut update_buf, &common_params, state_animation_rate, @@ -6244,6 +6248,8 @@ pub struct FigureUpdateCommonParameters<'a> { pub scale: f32, pub mount_transform_pos: Option<(anim::vek::Transform, anim::vek::Vec3)>, pub body: Option, + pub tools: (Option, Option), + pub char_ability: Option, pub col: vek::Rgba, pub dt: f32, // TODO: evaluate unused variable @@ -6266,9 +6272,7 @@ impl FigureState { Self { meta: FigureStateMeta { lantern_offset: offsets.lantern, - abs_trail_points: offsets.relative_trail_points, /* No position to add and make - * absolute, also doesn't matter - * here */ + abs_trail_points: None, mount_transform: offsets.mount_bone, mount_world_pos: anim::vek::Vec3::zero(), state_time: 0.0, @@ -6299,6 +6303,8 @@ impl FigureState { scale, mount_transform_pos, body, + tools, + char_ability, col, dt, _lpindex, @@ -6437,26 +6443,53 @@ impl FigureState { renderer.update_consts(&mut self.meta.bound.1, &new_bone_consts[0..S::BONE_COUNT]); self.lantern_offset = offsets.lantern; // Handle weapon trails - let offsets_abs_trail_points = offsets - .relative_trail_points - .map(|(a, b)| (a + pos, b + pos)); + let weapon_offsets = offsets.weapon_trail_mat.map(|mat| { + let (trail_start, trail_end) = match tools.0 { + Some(ToolKind::Sword) => (29.0, 30.0), + Some(ToolKind::Axe) => (19.0, 20.0), + Some(ToolKind::Hammer) => (19.0, 20.0), + _ => (0.0, 0.0), + }; + ( + (mat * anim::vek::Vec4::new(0.0, 0.0, trail_start, 1.0)).xyz(), + (mat * anim::vek::Vec4::new(0.0, 0.0, trail_end, 1.0)).xyz(), + ) + }); + let offsets_abs_trail_points = weapon_offsets.map(|(a, b)| (a + pos, b + pos)); if let Some(trail_mgr) = trail_mgr { if let Some(dynamic_model) = entity .as_ref() .and_then(|e| trail_mgr.dynamic_models.get(e)) { let mut quad_mesh = Mesh::new(); - if let (Some((p1, p2)), Some((p4, p3))) = + let quad = if let (Some((p1, p2)), Some((p4, p3))) = (self.abs_trail_points, offsets_abs_trail_points) { - let vertex = |p: anim::vek::Vec3| trail::Vertex { - pos: p.into_array(), - }; - quad_mesh.push_quad(Quad::new(vertex(p1), vertex(p2), vertex(p3), vertex(p4))); + use StageSection::{Action, Charge, Movement, Recover}; + if matches!( + char_ability, + Some( + CharacterAbilityType::BasicMelee(Action) + | CharacterAbilityType::ChargedMelee(Action) + | CharacterAbilityType::DashMelee(Charge | Action) + | CharacterAbilityType::ComboMelee(Action | Recover, _) + | CharacterAbilityType::LeapMelee(Movement | Action) + | CharacterAbilityType::SpinMelee(Action) + ) + ) { + let vertex = |p: anim::vek::Vec3| trail::Vertex { + pos: p.into_array(), + }; + Quad::new(vertex(p1), vertex(p2), vertex(p3), vertex(p4)) + } else { + let zero = trail::Vertex { pos: [0.0; 3] }; + Quad::new(zero, zero, zero, zero) + } } else { let zero = trail::Vertex { pos: [0.0; 3] }; - quad_mesh.push_quad(Quad::new(zero, zero, zero, zero)); - } + Quad::new(zero, zero, zero, zero) + }; + quad_mesh.push_quad(quad); renderer.update_model(dynamic_model, &quad_mesh, trail_mgr.offset * 4); } } diff --git a/voxygen/src/scene/figure/volume.rs b/voxygen/src/scene/figure/volume.rs index 746f42ab01..6f07d76579 100644 --- a/voxygen/src/scene/figure/volume.rs +++ b/voxygen/src/scene/figure/volume.rs @@ -49,7 +49,7 @@ impl anim::Skeleton for VolumeKey { anim::Offsets { lantern: None, mount_bone: anim::vek::Transform::default(), - relative_trail_points: None, + weapon_trail_mat: None, } } diff --git a/voxygen/src/scene/simple.rs b/voxygen/src/scene/simple.rs index c01c0b3609..15ba41b144 100644 --- a/voxygen/src/scene/simple.rs +++ b/voxygen/src/scene/simple.rs @@ -157,6 +157,8 @@ impl Scene { scale: 1.0, mount_transform_pos: None, body: None, + tools: (None, None), + char_ability: None, col: Rgba::broadcast(1.0), dt: 15.0, // Want to get there immediately. _lpindex: 0, @@ -348,6 +350,8 @@ impl Scene { scale: 1.0, mount_transform_pos: None, body: None, + tools: (None, None), + char_ability: None, col: Rgba::broadcast(1.0), dt: scene_data.delta_time, _lpindex: 0, diff --git a/voxygen/src/scene/trail.rs b/voxygen/src/scene/trail.rs index e0988cfc0c..87bbcb01e5 100644 --- a/voxygen/src/scene/trail.rs +++ b/voxygen/src/scene/trail.rs @@ -19,7 +19,7 @@ pub struct TrailMgr { pub offset: usize, } -const TRAIL_DYNAMIC_MODEL_SIZE: usize = 60; +const TRAIL_DYNAMIC_MODEL_SIZE: usize = 30; impl TrailMgr { pub fn new(_renderer: &mut Renderer) -> Self {