Skip to content

Commit

Permalink
fix vscreen scale
Browse files Browse the repository at this point in the history
  • Loading branch information
kayhhh committed Sep 10, 2024
1 parent b2e6c36 commit 67a0739
Show file tree
Hide file tree
Showing 9 changed files with 341 additions and 124 deletions.
16 changes: 10 additions & 6 deletions wasm/example-unavi-ui/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::{cell::Cell, f32::consts::PI};
use std::{cell::Cell, f32::consts::FRAC_PI_2};

use bindings::{
exports::wired::script::types::{Guest, GuestScript},
Expand Down Expand Up @@ -41,7 +41,7 @@ impl GuestScript for Script {
container.set_align_z(Alignment::End);
container.root().set_transform(Transform {
translation: Vec3::new(0.0, 0.2, -8.0),
rotation: Quat::from_rotation_y(PI),
rotation: Quat::from_rotation_x(FRAC_PI_2),
..Default::default()
});

Expand All @@ -65,13 +65,17 @@ impl GuestScript for Script {

// Button
let button = Button::new(Container::new(Vec3::new(1.0, 0.5, 0.2)));
button
.root()
.inner()
.set_transform(Transform::from_rotation(Quat::from_rotation_x(-FRAC_PI_2)));
container.add_child(&button.root());

// TextBox
let clock_container = Container::new(Vec3::new(2.0, 0.5, 0.01));
clock_container.inner().set_transform(Transform {
translation: Vec3::new(-1.0, 1.0, 0.0),
rotation: Quat::from_rotation_y(PI),
translation: Vec3::new(1.5, 0.01, -1.0),
rotation: Quat::from_rotation_x(-FRAC_PI_2),
..Default::default()
});
container.add_child(&clock_container);
Expand All @@ -84,8 +88,8 @@ impl GuestScript for Script {
clock.root().root().add_child(&label);
label.set_mesh(Some(&label_text.mesh()));
label.set_transform(Transform {
translation: Vec3::new(0.0, 1.1, 0.0),
rotation: Quat::from_rotation_y(PI),
translation: Vec3::new(0.5, 0.01, -1.0),
rotation: Quat::from_rotation_x(-FRAC_PI_2),
..Default::default()
});

Expand Down
70 changes: 56 additions & 14 deletions wasm/example-unavi-vscreen/src/bindings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2216,6 +2216,46 @@ pub mod unavi {
}
}
}
impl Screen {
#[allow(unused_unsafe, clippy::all)]
/// How long it takes to open the screen, in seconds.
pub fn open_duration(&self) -> f32 {
unsafe {
#[cfg(target_arch = "wasm32")]
#[link(wasm_import_module = "unavi:vscreen/screen")]
extern "C" {
#[link_name = "[method]screen.open-duration"]
fn wit_import(_: i32) -> f32;
}

#[cfg(not(target_arch = "wasm32"))]
fn wit_import(_: i32) -> f32 {
unreachable!()
}
let ret = wit_import((self).handle() as i32);
ret
}
}
}
impl Screen {
#[allow(unused_unsafe, clippy::all)]
pub fn set_open_duration(&self, value: f32) {
unsafe {
#[cfg(target_arch = "wasm32")]
#[link(wasm_import_module = "unavi:vscreen/screen")]
extern "C" {
#[link_name = "[method]screen.set-open-duration"]
fn wit_import(_: i32, _: f32);
}

#[cfg(not(target_arch = "wasm32"))]
fn wit_import(_: i32, _: f32) {
unreachable!()
}
wit_import((self).handle() as i32, _rt::as_f32(&value));
}
}
}
impl Screen {
#[allow(unused_unsafe, clippy::all)]
pub fn child_layout(&self) -> ChildLayout {
Expand Down Expand Up @@ -5898,8 +5938,8 @@ pub(crate) use __export_script_impl as export;
#[cfg(target_arch = "wasm32")]
#[link_section = "component-type:wit-bindgen:0.25.0:script:encoded world"]
#[doc(hidden)]
pub static __WIT_BINDGEN_COMPONENT_TYPE: [u8; 7639] = *b"\
\0asm\x0d\0\x01\0\0\x19\x16wit-component-encoding\x04\0\x07\xda:\x01A\x02\x01A\"\
pub static __WIT_BINDGEN_COMPONENT_TYPE: [u8; 7738] = *b"\
\0asm\x0d\0\x01\0\0\x19\x16wit-component-encoding\x04\0\x07\xbd;\x01A\x02\x01A\"\
\x01B\x10\x01r\x02\x01xv\x01yv\x04\0\x04vec2\x03\0\0\x01r\x03\x01xv\x01yv\x01zv\x04\
\0\x04vec3\x03\0\x02\x01r\x04\x01xv\x01yv\x01zv\x01wv\x04\0\x04quat\x03\0\x04\x01\
r\x03\x08rotation\x05\x05scale\x03\x0btranslation\x03\x04\0\x09transform\x03\0\x06\
Expand Down Expand Up @@ -6046,7 +6086,7 @@ ontainer.align-y\x01\x12\x04\0\x19[method]container.align-z\x01\x12\x01@\x02\x04
self\x09\x05value\x05\x01\0\x04\0\x1d[method]container.set-align-x\x01\x13\x04\0\
\x1d[method]container.set-align-y\x01\x13\x04\0\x1d[method]container.set-align-z\
\x01\x13\x03\x01\x16unavi:layout/container\x05\x13\x02\x03\0\x08\x09container\x01\
B&\x02\x03\x02\x01\x14\x04\0\x09container\x03\0\0\x02\x03\x02\x01\x0c\x04\0\x09t\
B*\x02\x03\x02\x01\x14\x04\0\x09container\x03\0\0\x02\x03\x02\x01\x0c\x04\0\x09t\
ransform\x03\0\x02\x02\x03\x02\x01\x10\x04\0\x04vec2\x03\0\x04\x02\x03\x02\x01\x04\
\x04\0\x04vec3\x03\0\x06\x02\x03\x02\x01\x11\x04\0\x04node\x03\0\x08\x01q\x02\x06\
circle\x01v\0\x09rectangle\x01\x05\0\x04\0\x0cscreen-shape\x03\0\x0a\x01q\x03\x09\
Expand All @@ -6055,17 +6095,19 @@ butterfly\0\0\x06circle\0\0\x09transform\x01\x03\0\x04\0\x0cchild-layout\x03\0\x
tor]screen\x01\x10\x01h\x0e\x01i\x01\x01@\x01\x04self\x11\0\x12\x04\0\x13[method\
]screen.root\x01\x13\x01@\x01\x04self\x11\0\x7f\x04\0\x16[method]screen.visible\x01\
\x14\x01@\x02\x04self\x11\x05value\x7f\x01\0\x04\0\x1a[method]screen.set-visible\
\x01\x15\x01@\x01\x04self\x11\0\x0d\x04\0\x1b[method]screen.child-layout\x01\x16\
\x01@\x02\x04self\x11\x05value\x0d\x01\0\x04\0\x1f[method]screen.set-child-layou\
t\x01\x17\x01p\x0f\x01@\x01\x04self\x11\0\x18\x04\0\x17[method]screen.children\x01\
\x19\x01@\x02\x04self\x11\x05value\x11\x01\0\x04\0\x18[method]screen.add-child\x01\
\x1a\x04\0\x1b[method]screen.remove-child\x01\x1a\x01@\x02\x04self\x11\x05deltav\
\x01\0\x04\0\x15[method]screen.update\x01\x1b\x03\x01\x14unavi:vscreen/screen\x05\
\x15\x01B\x07\x04\0\x06script\x03\x01\x01i\0\x01@\0\0\x01\x04\0\x13[constructor]\
script\x01\x02\x01h\0\x01@\x02\x04self\x03\x05deltav\x01\0\x04\0\x15[method]scri\
pt.update\x01\x04\x04\x01\x12wired:script/types\x05\x16\x04\x01\x1cexample:unavi\
-vscreen/script\x04\0\x0b\x0c\x01\0\x06script\x03\0\0\0G\x09producers\x01\x0cpro\
cessed-by\x02\x0dwit-component\x070.208.1\x10wit-bindgen-rust\x060.25.0";
\x01\x15\x01@\x01\x04self\x11\0v\x04\0\x1c[method]screen.open-duration\x01\x16\x01\
@\x02\x04self\x11\x05valuev\x01\0\x04\0\x20[method]screen.set-open-duration\x01\x17\
\x01@\x01\x04self\x11\0\x0d\x04\0\x1b[method]screen.child-layout\x01\x18\x01@\x02\
\x04self\x11\x05value\x0d\x01\0\x04\0\x1f[method]screen.set-child-layout\x01\x19\
\x01p\x0f\x01@\x01\x04self\x11\0\x1a\x04\0\x17[method]screen.children\x01\x1b\x01\
@\x02\x04self\x11\x05value\x11\x01\0\x04\0\x18[method]screen.add-child\x01\x1c\x04\
\0\x1b[method]screen.remove-child\x01\x1c\x01@\x02\x04self\x11\x05deltav\x01\0\x04\
\0\x15[method]screen.update\x01\x1d\x03\x01\x14unavi:vscreen/screen\x05\x15\x01B\
\x07\x04\0\x06script\x03\x01\x01i\0\x01@\0\0\x01\x04\0\x13[constructor]script\x01\
\x02\x01h\0\x01@\x02\x04self\x03\x05deltav\x01\0\x04\0\x15[method]script.update\x01\
\x04\x04\x01\x12wired:script/types\x05\x16\x04\x01\x1cexample:unavi-vscreen/scri\
pt\x04\0\x0b\x0c\x01\0\x06script\x03\0\0\0G\x09producers\x01\x0cprocessed-by\x02\
\x0dwit-component\x070.208.1\x10wit-bindgen-rust\x060.25.0";

#[inline(never)]
#[doc(hidden)]
Expand Down
33 changes: 22 additions & 11 deletions wasm/example-unavi-vscreen/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::f32::consts::{FRAC_PI_2, PI};
use std::f32::consts::FRAC_PI_2;

use bindings::{
exports::wired::script::types::{Guest, GuestScript},
Expand All @@ -16,49 +16,60 @@ use bindings::{
mod bindings;
mod wired_math_impls;

struct Script;
struct Script {
screens: Vec<Screen>,
}

impl GuestScript for Script {
fn new() -> Self {
let mut screens = Vec::default();

// Background
let bg = Rectangle::new(Vec2::new(8.0, 3.0)).to_physics_node();
bg.set_transform(Transform {
translation: Vec3::new(0.0, 0.0, -8.0),
rotation: Quat::from_rotation_y(PI),
rotation: Quat::from_rotation_x(FRAC_PI_2),
..Default::default()
});
let material = Material::new();
material.set_color(Color {
r: 0.7,
g: 0.2,
b: 0.3,
r: 0.5,
g: 0.1,
b: 0.2,
a: 1.0,
});
for primitive in bg.mesh().unwrap().list_primitives() {
primitive.set_material(Some(&material))
}

// Circle Screen
// Circle screen
let screen = Screen::new(ScreenShape::Circle(0.1));
screen.set_visible(true);
screen.root().root().set_transform(Transform {
translation: Vec3::new(-2.0, 0.0, -7.99),
rotation: Quat::from_rotation_x(FRAC_PI_2),
..Default::default()
});
screens.push(screen);

// Rectangle Screen
// Rectangle screen
let screen = Screen::new(ScreenShape::Rectangle(Vec2::new(0.4, 0.2)));
screen.set_visible(true);
screen.root().root().set_transform(Transform {
translation: Vec3::new(-1.0, 0.0, -7.99),
translation: Vec3::new(0.0, 0.0, -7.99),
rotation: Quat::from_rotation_x(FRAC_PI_2),
..Default::default()
});
screens.push(screen);

Self
Self { screens }
}

fn update(&self, _delta: f32) {}
fn update(&self, delta: f32) {
for screen in self.screens.iter() {
screen.update(delta);
}
}
}

struct GuestImpl;
Expand Down
2 changes: 1 addition & 1 deletion wasm/unavi-shapes/src/shapes/circle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ impl GuestCircle for Circle {
let radius = self.radius.get();
node.set_collider(Some(&Collider::new(Shape::Cylinder(ShapeCylinder {
radius,
height: 0.0001,
height: 0.0,
}))));
node
}
Expand Down
88 changes: 65 additions & 23 deletions wasm/unavi-system/src/bindings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1675,6 +1675,46 @@ pub mod unavi {
}
}
}
impl Screen {
#[allow(unused_unsafe, clippy::all)]
/// How long it takes to open the screen, in seconds.
pub fn open_duration(&self) -> f32 {
unsafe {
#[cfg(target_arch = "wasm32")]
#[link(wasm_import_module = "unavi:vscreen/screen")]
extern "C" {
#[link_name = "[method]screen.open-duration"]
fn wit_import(_: i32) -> f32;
}

#[cfg(not(target_arch = "wasm32"))]
fn wit_import(_: i32) -> f32 {
unreachable!()
}
let ret = wit_import((self).handle() as i32);
ret
}
}
}
impl Screen {
#[allow(unused_unsafe, clippy::all)]
pub fn set_open_duration(&self, value: f32) {
unsafe {
#[cfg(target_arch = "wasm32")]
#[link(wasm_import_module = "unavi:vscreen/screen")]
extern "C" {
#[link_name = "[method]screen.set-open-duration"]
fn wit_import(_: i32, _: f32);
}

#[cfg(not(target_arch = "wasm32"))]
fn wit_import(_: i32, _: f32) {
unreachable!()
}
wit_import((self).handle() as i32, _rt::as_f32(&value));
}
}
}
impl Screen {
#[allow(unused_unsafe, clippy::all)]
pub fn child_layout(&self) -> ChildLayout {
Expand Down Expand Up @@ -7936,8 +7976,8 @@ pub(crate) use __export_guest_impl as export;
#[cfg(target_arch = "wasm32")]
#[link_section = "component-type:wit-bindgen:0.25.0:guest:encoded world"]
#[doc(hidden)]
pub static __WIT_BINDGEN_COMPONENT_TYPE: [u8; 10208] = *b"\
\0asm\x0d\0\x01\0\0\x19\x16wit-component-encoding\x04\0\x07\xe4N\x01A\x02\x01A4\x01\
pub static __WIT_BINDGEN_COMPONENT_TYPE: [u8; 10307] = *b"\
\0asm\x0d\0\x01\0\0\x19\x16wit-component-encoding\x04\0\x07\xc7O\x01A\x02\x01A4\x01\
B\x10\x01r\x02\x01xv\x01yv\x04\0\x04vec2\x03\0\0\x01r\x03\x01xv\x01yv\x01zv\x04\0\
\x04vec3\x03\0\x02\x01r\x04\x01xv\x01yv\x01zv\x01wv\x04\0\x04quat\x03\0\x04\x01r\
\x03\x08rotation\x05\x05scale\x03\x0btranslation\x03\x04\0\x09transform\x03\0\x06\
Expand Down Expand Up @@ -8045,7 +8085,7 @@ iner.align-y\x01\x12\x04\0\x19[method]container.align-z\x01\x12\x01@\x02\x04self
\x09\x05value\x05\x01\0\x04\0\x1d[method]container.set-align-x\x01\x13\x04\0\x1d\
[method]container.set-align-y\x01\x13\x04\0\x1d[method]container.set-align-z\x01\
\x13\x03\x01\x16unavi:layout/container\x05\x12\x02\x03\0\x08\x09container\x02\x03\
\0\0\x04vec2\x01B&\x02\x03\x02\x01\x13\x04\0\x09container\x03\0\0\x02\x03\x02\x01\
\0\0\x04vec2\x01B*\x02\x03\x02\x01\x13\x04\0\x09container\x03\0\0\x02\x03\x02\x01\
\x0c\x04\0\x09transform\x03\0\x02\x02\x03\x02\x01\x14\x04\0\x04vec2\x03\0\x04\x02\
\x03\x02\x01\x04\x04\0\x04vec3\x03\0\x06\x02\x03\x02\x01\x10\x04\0\x04node\x03\0\
\x08\x01q\x02\x06circle\x01v\0\x09rectangle\x01\x05\0\x04\0\x0cscreen-shape\x03\0\
Expand All @@ -8054,26 +8094,28 @@ ld-layout\x03\0\x0c\x04\0\x06screen\x03\x01\x01i\x0e\x01@\x01\x05shape\x0b\0\x0f
\x04\0\x13[constructor]screen\x01\x10\x01h\x0e\x01i\x01\x01@\x01\x04self\x11\0\x12\
\x04\0\x13[method]screen.root\x01\x13\x01@\x01\x04self\x11\0\x7f\x04\0\x16[metho\
d]screen.visible\x01\x14\x01@\x02\x04self\x11\x05value\x7f\x01\0\x04\0\x1a[metho\
d]screen.set-visible\x01\x15\x01@\x01\x04self\x11\0\x0d\x04\0\x1b[method]screen.\
child-layout\x01\x16\x01@\x02\x04self\x11\x05value\x0d\x01\0\x04\0\x1f[method]sc\
reen.set-child-layout\x01\x17\x01p\x0f\x01@\x01\x04self\x11\0\x18\x04\0\x17[meth\
od]screen.children\x01\x19\x01@\x02\x04self\x11\x05value\x11\x01\0\x04\0\x18[met\
hod]screen.add-child\x01\x1a\x04\0\x1b[method]screen.remove-child\x01\x1a\x01@\x02\
\x04self\x11\x05deltav\x01\0\x04\0\x15[method]screen.update\x01\x1b\x03\x01\x14u\
navi:vscreen/screen\x05\x15\x01B\x02\x01@\x01\x05deltav\x01\0\x04\0\x09update-ui\
\x01\0\x03\x01\x0cunavi:ui/api\x05\x16\x01B\x0f\x02\x03\x02\x01\x13\x04\0\x09con\
tainer\x03\0\0\x02\x03\x02\x01\x0b\x04\0\x0dinput-handler\x03\0\x02\x04\0\x06but\
ton\x03\x01\x01i\x01\x01i\x04\x01@\x01\x04root\x05\0\x06\x04\0\x13[constructor]b\
utton\x01\x07\x01h\x04\x01@\x01\x04self\x08\0\x05\x04\0\x13[method]button.root\x01\
\x09\x01@\x01\x04self\x08\0\x7f\x04\0\x16[method]button.hovered\x01\x0a\x04\0\x16\
[method]button.pressed\x01\x0a\x03\x01\x0funavi:ui/button\x05\x17\x01B(\x02\x03\x02\
\x01\x13\x04\0\x09container\x03\0\0\x02\x03\x02\x01\x0a\x04\0\x04mesh\x03\0\x02\x02\
\x03\x02\x01\x10\x04\0\x04node\x03\0\x04\x04\0\x04text\x03\x01\x04\0\x08text-box\
\x03\x01\x01i\x06\x01@\x01\x04texts\0\x08\x04\0\x11[constructor]text\x01\x09\x01\
h\x06\x01@\x01\x04self\x0a\0\x08\x04\0\x10[method]text.ref\x01\x0b\x01p}\x01k\x0c\
\x01@\x02\x04self\x0a\x05value\x0d\x01\0\x04\0\x15[method]text.set-font\x01\x0e\x01\
@\x01\x04self\x0a\0s\x04\0\x11[method]text.text\x01\x0f\x01@\x02\x04self\x0a\x05\
values\x01\0\x04\0\x15[method]text.set-text\x01\x10\x01@\x01\x04self\x0a\0v\x04\0\
d]screen.set-visible\x01\x15\x01@\x01\x04self\x11\0v\x04\0\x1c[method]screen.ope\
n-duration\x01\x16\x01@\x02\x04self\x11\x05valuev\x01\0\x04\0\x20[method]screen.\
set-open-duration\x01\x17\x01@\x01\x04self\x11\0\x0d\x04\0\x1b[method]screen.chi\
ld-layout\x01\x18\x01@\x02\x04self\x11\x05value\x0d\x01\0\x04\0\x1f[method]scree\
n.set-child-layout\x01\x19\x01p\x0f\x01@\x01\x04self\x11\0\x1a\x04\0\x17[method]\
screen.children\x01\x1b\x01@\x02\x04self\x11\x05value\x11\x01\0\x04\0\x18[method\
]screen.add-child\x01\x1c\x04\0\x1b[method]screen.remove-child\x01\x1c\x01@\x02\x04\
self\x11\x05deltav\x01\0\x04\0\x15[method]screen.update\x01\x1d\x03\x01\x14unavi\
:vscreen/screen\x05\x15\x01B\x02\x01@\x01\x05deltav\x01\0\x04\0\x09update-ui\x01\
\0\x03\x01\x0cunavi:ui/api\x05\x16\x01B\x0f\x02\x03\x02\x01\x13\x04\0\x09contain\
er\x03\0\0\x02\x03\x02\x01\x0b\x04\0\x0dinput-handler\x03\0\x02\x04\0\x06button\x03\
\x01\x01i\x01\x01i\x04\x01@\x01\x04root\x05\0\x06\x04\0\x13[constructor]button\x01\
\x07\x01h\x04\x01@\x01\x04self\x08\0\x05\x04\0\x13[method]button.root\x01\x09\x01\
@\x01\x04self\x08\0\x7f\x04\0\x16[method]button.hovered\x01\x0a\x04\0\x16[method\
]button.pressed\x01\x0a\x03\x01\x0funavi:ui/button\x05\x17\x01B(\x02\x03\x02\x01\
\x13\x04\0\x09container\x03\0\0\x02\x03\x02\x01\x0a\x04\0\x04mesh\x03\0\x02\x02\x03\
\x02\x01\x10\x04\0\x04node\x03\0\x04\x04\0\x04text\x03\x01\x04\0\x08text-box\x03\
\x01\x01i\x06\x01@\x01\x04texts\0\x08\x04\0\x11[constructor]text\x01\x09\x01h\x06\
\x01@\x01\x04self\x0a\0\x08\x04\0\x10[method]text.ref\x01\x0b\x01p}\x01k\x0c\x01\
@\x02\x04self\x0a\x05value\x0d\x01\0\x04\0\x15[method]text.set-font\x01\x0e\x01@\
\x01\x04self\x0a\0s\x04\0\x11[method]text.text\x01\x0f\x01@\x02\x04self\x0a\x05v\
alues\x01\0\x04\0\x15[method]text.set-text\x01\x10\x01@\x01\x04self\x0a\0v\x04\0\
\x16[method]text.font-size\x01\x11\x01@\x02\x04self\x0a\x05valuev\x01\0\x04\0\x1a\
[method]text.set-font-size\x01\x12\x04\0\x16[method]text.thickness\x01\x11\x04\0\
\x1a[method]text.set-thickness\x01\x12\x01i\x03\x01@\x01\x04self\x0a\0\x13\x04\0\
Expand Down
12 changes: 12 additions & 0 deletions wasm/unavi-system/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use bindings::{
exports::wired::script::types::{Guest, GuestScript},
unavi::vscreen::screen::{Screen, ScreenShape},
wired::{
math::types::{Transform, Vec3},
player::api::{local_player, Skeleton},
scene::gltf::Node,
},
Expand All @@ -15,6 +16,8 @@ mod wired_math_impls;
mod wired_scene_impls;

const ACTIVE_Y: f32 = 1.2;
const ARM_RADIUS: f32 = 0.03;
const SCREEN_RADIUS: f32 = 0.03;

struct Script {
root: Node,
Expand All @@ -25,6 +28,15 @@ struct Script {
impl GuestScript for Script {
fn new() -> Self {
let screen = Screen::new(ScreenShape::Circle(0.03));
screen.set_open_duration(0.4);
screen
.root()
.root()
.set_transform(Transform::from_translation(Vec3::new(
SCREEN_RADIUS * 2.0,
ARM_RADIUS,
0.0,
)));

let player = local_player();
let skeleton = player.skeleton();
Expand Down
Loading

0 comments on commit 67a0739

Please sign in to comment.