Skip to content

Commit

Permalink
avoid vscreen glitchyness
Browse files Browse the repository at this point in the history
  • Loading branch information
kayhhh committed Sep 5, 2024
1 parent a6b729d commit 995fb2f
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 32 deletions.
8 changes: 4 additions & 4 deletions crates/unavi-scripting/src/api/wired/physics/systems.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use crate::{
};

pub(crate) fn update_physics_transforms(
phys_nodes: Query<(&NodeId, Entity, &Transform), With<Collider>>,
nodes: Query<(&NodeId, Entity, &Transform), With<Collider>>,
script_map: NonSendMut<ScriptMap>,
scripts: Query<(Entity, &ScriptTickrate)>,
) {
Expand All @@ -27,11 +27,11 @@ pub(crate) fn update_physics_transforms(
};

let data = store.data_mut();
let nodes = data.entities.nodes.read().unwrap();
let script_nodes = data.entities.nodes.read().unwrap();

for (id, ent, transform) in phys_nodes.iter() {
for (id, ent, transform) in nodes.iter() {
// Check if phys node is from this script.
if Some(ent) != nodes.get(&id.0).copied() {
if Some(ent) != script_nodes.get(&id.0).copied() {
continue;
}

Expand Down
11 changes: 1 addition & 10 deletions crates/unavi-scripting/src/api/wired/player/systems.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,16 +94,7 @@ pub(crate) fn update_player_skeletons(

// Set node resource transform.
let node = data.table.get_mut(node_res).unwrap();
node.transform.translation.x = bone_transform.translation.x;
node.transform.translation.y = bone_transform.translation.y;
node.transform.translation.z = bone_transform.translation.z;
node.transform.rotation.x = bone_transform.rotation.x;
node.transform.rotation.y = bone_transform.rotation.y;
node.transform.rotation.z = bone_transform.rotation.z;
node.transform.rotation.w = bone_transform.rotation.w;
node.transform.scale.x = bone_transform.scale.x;
node.transform.scale.y = bone_transform.scale.y;
node.transform.scale.z = bone_transform.scale.z;
node.transform = *bone_transform;
}
}
}
Expand Down
26 changes: 8 additions & 18 deletions wasm/unavi-vscreen/src/screen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ use crate::{
unavi::shapes::api::Cylinder,
wired::{
math::types::{Quat, Transform, Vec3},
physics::types::Collider,
scene::node::Node,
},
},
Expand All @@ -17,39 +16,33 @@ use crate::{

const ANIMATION_DURATION_SECONDS: f32 = 0.5;
const ARM_RADIUS: f32 = 0.03;
const MAX_SCALE: f32 = 1.0;
const MIN_SCALE: f32 = 0.0;
const SCREEN_HEIGHT: f32 = 0.001;
const SCREEN_RADIUS: f32 = 0.04;

pub struct Screen {
central_module: RefCell<Option<Module>>,
modules: RefCell<Vec<Module>>,
root: Node,
root_collider: Collider,
visible: Cell<bool>,
visible_animating: Cell<bool>,
}

impl GuestScreen for Screen {
fn new() -> Self {
let cylinder = Cylinder::new(SCREEN_RADIUS, SCREEN_HEIGHT);
cylinder.set_resolution(32);

let root = cylinder.to_physics_node();
let root = Cylinder::new(SCREEN_RADIUS, SCREEN_HEIGHT).to_physics_node();

root.set_transform(Transform {
translation: Vec3::new(SCREEN_RADIUS * 2.0, ARM_RADIUS, -ARM_RADIUS / 3.0),
rotation: Quat::default(),
scale: Vec3::default(),
scale: Vec3::splat(MIN_SCALE),
});

let root_collider = root.collider().unwrap();
root.set_collider(None);

Self {
central_module: RefCell::default(),
modules: RefCell::default(),
root,
root_collider,
visible: Cell::default(),
visible_animating: Cell::default(),
}
Expand Down Expand Up @@ -114,18 +107,15 @@ impl GuestScreen for Screen {
if visible {
transform.scale += delta / ANIMATION_DURATION_SECONDS;

if transform.scale.x > 1.0 {
transform.scale = Vec3::splat(1.0);
if transform.scale.x > MAX_SCALE {
transform.scale = Vec3::splat(MAX_SCALE);
self.visible_animating.set(false);
self.root.set_collider(Some(&self.root_collider));
}
} else {
transform.scale -= delta / ANIMATION_DURATION_SECONDS;

self.root.set_collider(None);

if transform.scale.x < 0.0 {
transform.scale = Vec3::splat(0.0);
if transform.scale.x < MIN_SCALE {
transform.scale = Vec3::splat(MIN_SCALE);
self.visible_animating.set(false);
}
}
Expand Down

0 comments on commit 995fb2f

Please sign in to comment.