Compare commits

..

7 Commits

Author SHA1 Message Date
b05f29da23 runnable without vr 2026-02-24 03:04:00 +01:00
17a0de5903 hasn't been that in a while 2026-02-23 22:16:55 +01:00
485ea056a7 lets use embedded_graphics lol 2026-02-23 22:14:22 +01:00
4296a6488c crosshair is nice 2026-02-23 01:54:44 +01:00
b82a0eb7d4 feat: drawing and stuff 2026-02-22 20:39:23 +01:00
bb05dc5161 head lookat move mouse test 2026-02-21 19:08:35 +01:00
a152eeadc6 no need for this 2026-02-21 14:34:43 +01:00
11 changed files with 1283 additions and 88 deletions

157
Cargo.lock generated
View File

@@ -219,9 +219,9 @@ dependencies = [
[[package]]
name = "anyhow"
version = "1.0.101"
version = "1.0.102"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5f0e0fee31ef5ed1ba1316088939cea399010ed7731dba877ed44aeb407a75ea"
checksum = "7f202df86484c868dbad7eaa557ef785d5c66295e41b460ef922eca0723b842c"
[[package]]
name = "approx"
@@ -382,6 +382,12 @@ version = "1.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c08606f8c3cbf4ce6ec8e28fb0014a2c086708fe954eaa885384a6165172e7e8"
[[package]]
name = "az"
version = "1.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7b7e4c2464d97fe331d41de9d5db0def0a96f4d823b8b32a2efd503578988973"
[[package]]
name = "base64"
version = "0.22.1"
@@ -1120,7 +1126,6 @@ checksum = "7ef8e4b7e61dfe7719bb03c884dc270cd46a82efb40f93e9933b990c5c190c59"
[[package]]
name = "bevy_mod_openxr"
version = "0.5.0"
source = "git+https://git.avii.nl/Avii/bevy_oxr.git#7936b53a024b993c53fc7427b5b290bf210978a9"
dependencies = [
"android_system_properties",
"ash",
@@ -1145,7 +1150,6 @@ dependencies = [
[[package]]
name = "bevy_mod_xr"
version = "0.5.0"
source = "git+https://git.avii.nl/Avii/bevy_oxr.git#7936b53a024b993c53fc7427b5b290bf210978a9"
dependencies = [
"bevy_app",
"bevy_camera",
@@ -2506,9 +2510,9 @@ checksum = "d7a1e2f27636f116493b8b860f5546edb47c8d8f8ea73e1d2a20be88e28d1fea"
[[package]]
name = "deranged"
version = "0.5.6"
version = "0.5.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cc3dc5ad92c2e2d1c193bbbbdf2ea477cb81331de4f3103f267ca18368b988c4"
checksum = "7cd812cc2bc1d69d4764bd80df88b4317eaef9e773c75226407d9bc0876b211c"
dependencies = [
"powerfmt",
]
@@ -2536,6 +2540,12 @@ dependencies = [
"unicode-xid",
]
[[package]]
name = "deunicode"
version = "1.6.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "abd57806937c9cc163efc8ea3910e00a62e2aeb0b8119f1793a978088f8f6b04"
[[package]]
name = "directories"
version = "6.0.0"
@@ -2545,6 +2555,15 @@ dependencies = [
"dirs-sys",
]
[[package]]
name = "dirs"
version = "6.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c3e8aa94d75141228480295a7d0e7feb620b1a5ad9f12bc40be62411e38cce4e"
dependencies = [
"dirs-sys",
]
[[package]]
name = "dirs-sys"
version = "0.5.0"
@@ -2651,6 +2670,29 @@ version = "1.15.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "48c757948c5ede0e46177b7add2e67155f70e33c07fea8284df6576da70b3719"
[[package]]
name = "embedded-graphics"
version = "0.8.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4e8da660bb0c829b34a56a965490597f82a55e767b91f9543be80ce8ccb416fe"
dependencies = [
"az",
"byteorder",
"embedded-graphics-core",
"float-cmp",
"micromath",
]
[[package]]
name = "embedded-graphics-core"
version = "0.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "95743bef3ff70fcba3930246c4e6872882bbea0dcc6da2ca860112e0cd4bd09f"
dependencies = [
"az",
"byteorder",
]
[[package]]
name = "encase"
version = "0.12.0"
@@ -2826,6 +2868,15 @@ dependencies = [
"miniz_oxide",
]
[[package]]
name = "float-cmp"
version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "98de4bbd547a563b716d8dfa9aad1cb19bfab00f4fa09a6a4ed21dbcf44ce9c4"
dependencies = [
"num-traits",
]
[[package]]
name = "fnv"
version = "1.0.7"
@@ -3656,9 +3707,9 @@ dependencies = [
[[package]]
name = "js-sys"
version = "0.3.85"
version = "0.3.88"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8c942ebf8e95485ca0d52d97da7c5a2c387d0e7f0ba4c35e93bfcaee045955b3"
checksum = "c7e709f3e3d22866f9c25b3aff01af289b18422cc8b4262fb19103ee80fe513d"
dependencies = [
"once_cell",
"wasm-bindgen",
@@ -3690,9 +3741,14 @@ dependencies = [
"bevy_mod_openxr",
"bevy_mod_xr",
"bevy_pkv",
"crossbeam-channel",
"embedded-graphics",
"embedded-graphics-core",
"openxr",
"otd-ipc",
"rdev",
"serde",
"triple_buffer",
]
[[package]]
@@ -3888,6 +3944,12 @@ dependencies = [
"paste",
]
[[package]]
name = "micromath"
version = "2.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c3c8dda44ff03a2f238717214da50f65d5a53b45cd213a7370424ffdb6fae815"
[[package]]
name = "minimal-lexical"
version = "0.2.1"
@@ -4467,6 +4529,17 @@ dependencies = [
"num-traits",
]
[[package]]
name = "otd-ipc"
version = "0.1.0"
dependencies = [
"bytes",
"dirs",
"serde",
"serde_bytes",
"slug",
]
[[package]]
name = "owned_ttf_parser"
version = "0.25.1"
@@ -5025,7 +5098,7 @@ dependencies = [
"errno",
"libc",
"linux-raw-sys 0.4.15",
"windows-sys 0.59.0",
"windows-sys 0.52.0",
]
[[package]]
@@ -5157,6 +5230,16 @@ dependencies = [
"serde_derive",
]
[[package]]
name = "serde_bytes"
version = "0.11.19"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a5d440709e79d88e51ac01c4b72fc6cb7314017bb7da9eeff678aa94c10e3ea8"
dependencies = [
"serde",
"serde_core",
]
[[package]]
name = "serde_core"
version = "1.0.228"
@@ -5252,6 +5335,16 @@ dependencies = [
"version_check",
]
[[package]]
name = "slug"
version = "0.1.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "882a80f72ee45de3cc9a5afeb2da0331d58df69e4e7d8eeb5d3c7784ae67e724"
dependencies = [
"deunicode",
"wasm-bindgen",
]
[[package]]
name = "smallvec"
version = "1.15.1"
@@ -5392,9 +5485,9 @@ dependencies = [
[[package]]
name = "syn"
version = "2.0.116"
version = "2.0.117"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3df424c70518695237746f84cede799c9c58fcb37450d7b23716568cc8bc69cb"
checksum = "e665b8803e7b1d2a727f4023456bbbbe74da67099c585258af0ad9c5013b9b99"
dependencies = [
"proc-macro2",
"quote",
@@ -5720,6 +5813,15 @@ dependencies = [
"wasm-bindgen",
]
[[package]]
name = "triple_buffer"
version = "8.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "420466259f9fa5decc654c490b9ab538400e5420df8237f84ecbe20368bcf72b"
dependencies = [
"crossbeam-utils",
]
[[package]]
name = "ttf-parser"
version = "0.25.1"
@@ -5941,9 +6043,9 @@ dependencies = [
[[package]]
name = "wasm-bindgen"
version = "0.2.108"
version = "0.2.111"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "64024a30ec1e37399cf85a7ffefebdb72205ca1c972291c51512360d90bd8566"
checksum = "ec1adf1535672f5b7824f817792b1afd731d7e843d2d04ec8f27e8cb51edd8ac"
dependencies = [
"cfg-if",
"once_cell",
@@ -5954,9 +6056,9 @@ dependencies = [
[[package]]
name = "wasm-bindgen-futures"
version = "0.4.58"
version = "0.4.61"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "70a6e77fd0ae8029c9ea0063f87c46fde723e7d887703d74ad2616d792e51e6f"
checksum = "fe88540d1c934c4ec8e6db0afa536876c5441289d7f9f9123d4f065ac1250a6b"
dependencies = [
"cfg-if",
"futures-util",
@@ -5968,9 +6070,9 @@ dependencies = [
[[package]]
name = "wasm-bindgen-macro"
version = "0.2.108"
version = "0.2.111"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "008b239d9c740232e71bd39e8ef6429d27097518b6b30bdf9086833bd5b6d608"
checksum = "19e638317c08b21663aed4d2b9a2091450548954695ff4efa75bff5fa546b3b1"
dependencies = [
"quote",
"wasm-bindgen-macro-support",
@@ -5978,9 +6080,9 @@ dependencies = [
[[package]]
name = "wasm-bindgen-macro-support"
version = "0.2.108"
version = "0.2.111"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5256bae2d58f54820e6490f9839c49780dff84c65aeab9e772f15d5f0e913a55"
checksum = "2c64760850114d03d5f65457e96fc988f11f01d38fbaa51b254e4ab5809102af"
dependencies = [
"bumpalo",
"proc-macro2",
@@ -5991,9 +6093,9 @@ dependencies = [
[[package]]
name = "wasm-bindgen-shared"
version = "0.2.108"
version = "0.2.111"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1f01b580c9ac74c8d8f0c0e4afb04eeef2acf145458e52c03845ee9cd23e3d12"
checksum = "60eecd4fe26177cfa3339eb00b4a36445889ba3ad37080c2429879718e20ca41"
dependencies = [
"unicode-ident",
]
@@ -6142,9 +6244,9 @@ dependencies = [
[[package]]
name = "web-sys"
version = "0.3.85"
version = "0.3.88"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "312e32e551d92129218ea9a2452120f4aabc03529ef03e4d0d82fb2780608598"
checksum = "9d6bb20ed2d9572df8584f6dc81d68a41a625cadc6f15999d649a70ce7e3597a"
dependencies = [
"js-sys",
"wasm-bindgen",
@@ -6654,15 +6756,6 @@ dependencies = [
"windows-targets 0.52.6",
]
[[package]]
name = "windows-sys"
version = "0.59.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b"
dependencies = [
"windows-targets 0.52.6",
]
[[package]]
name = "windows-sys"
version = "0.61.2"

View File

@@ -8,10 +8,19 @@ license = "MIT/Apache-2.0"
[dependencies]
bevy = { version = "0.18", features = ["debug"] }
bevy_cef = { path = "../bevy_cef" }
bevy_mod_xr = { git = "https://git.avii.nl/Avii/bevy_oxr.git", version = "0.5.0" }
bevy_mod_openxr = { git = "https://git.avii.nl/Avii/bevy_oxr.git", version = "0.5.0" }
# bevy_mod_xr = { git = "https://git.avii.nl/Avii/bevy_oxr.git", version = "0.5.0" }
# bevy_mod_openxr = { git = "https://git.avii.nl/Avii/bevy_oxr.git", version = "0.5.0" }
bevy_mod_xr = { path = "../bevy_oxr/crates/bevy_xr" }
bevy_mod_openxr = { path = "../bevy_oxr/crates/bevy_openxr" }
bevy_pkv = "0.15.0"
# bevy_xr_utils.workspace = true
openxr = "0.21.1"
rdev = { version = "0.5.3", features = ["unstable_grab"] }
serde = { version = "1.0.228", features = ["derive"] }
otd-ipc = { path = "../../otd-ipc-client-rs" }
crossbeam-channel = "0.5.15"
triple_buffer = "8.1.1"
embedded-graphics = "0.8.2"
embedded-graphics-core = "0.4.1"

233
src/drawingplugin.rs Normal file
View File

@@ -0,0 +1,233 @@
mod drawtarget;
mod rgba;
mod uiplugin;
use bevy_cef::prelude::WebviewExtendStandardMaterial;
use bevy::{
asset::RenderAssetUsages,
color::palettes::css,
prelude::*,
render::render_resource::{Extent3d, TextureDimension, TextureFormat},
};
use embedded_graphics::prelude::DrawTarget;
use crate::{
drawingplugin::drawtarget::{DrawableLayer, Visible},
otdipcplugin::OtdIpcPlugin,
};
use crate::{
drawingplugin::uiplugin::UiPlugin,
otdipcplugin::{PenButtons, PenPosition, PenPressure},
};
const IMAGE_WIDTH: usize = (210.0 * 3.5) as usize;
const IMAGE_HEIGHT: usize = (279.0 * 3.5) as usize;
#[derive(Resource)]
pub struct MyProcGenImage(pub(crate) Handle<Image>);
#[derive(Component)]
struct CursorBuffer;
#[derive(Component)]
struct DrawingBuffer;
#[derive(Resource)]
struct PenSize(f32);
#[derive(Resource)]
struct PenColor(Color);
#[derive(Resource)]
pub struct LastPenPos(pub Option<(i32, i32)>);
pub struct DrawingPlugin;
impl Plugin for DrawingPlugin {
fn build(&self, app: &mut App) {
app.add_plugins(OtdIpcPlugin);
app.add_plugins(UiPlugin);
app.insert_resource(ClearColor(Color::NONE))
.insert_resource(LastPenPos(None))
.insert_resource(PenColor(css::BLACK.into()))
.insert_resource(PenSize(5.0));
app.add_systems(Startup, setup)
.add_systems(Update, (cursor, draw, plot));
}
}
pub fn setup(mut commands: Commands, mut images: ResMut<Assets<Image>>) {
let image = Image::new_fill(
Extent3d {
width: IMAGE_WIDTH as u32,
height: IMAGE_HEIGHT as u32,
depth_or_array_layers: 1,
},
TextureDimension::D2,
&(Srgba::new(1.0, 1.0, 1.0, 0.0).to_u8_array()),
TextureFormat::Rgba8UnormSrgb,
RenderAssetUsages::MAIN_WORLD | RenderAssetUsages::RENDER_WORLD,
);
let handle = images.add(image);
commands.insert_resource(MyProcGenImage(handle));
commands.spawn((
CursorBuffer,
DrawableLayer::new(IMAGE_WIDTH, IMAGE_HEIGHT, drawtarget::Layer::Drawing),
Visible,
));
commands.spawn((
DrawingBuffer,
DrawableLayer::new(IMAGE_WIDTH, IMAGE_HEIGHT, drawtarget::Layer::Cursor),
Visible,
));
}
// fn color_changer(mut pen_color: ResMut<PenColor>, mut pen_buttons: MessageReader<PenButtons>) {
// let Some(buttons) = pen_buttons.read().next() else {
// return;
// };
// pen_color.0 = css::BLACK.into();
// if buttons.a() {
// let mut t = LinearRgba::from(pen_color.0);
// t.alpha = 0.0;
// pen_color.0 = t.into();
// }
// }
fn cursor(
pen_color: Res<PenColor>,
mut buffer: Query<&mut DrawableLayer, With<CursorBuffer>>,
mut pen_size: ResMut<PenSize>,
mut pen_buttons: MessageReader<PenButtons>,
mut pen_position: MessageReader<PenPosition>,
mut pen_pressure: MessageReader<PenPressure>,
) {
let Ok(mut buffer) = buffer.single_mut() else {
return;
};
let mut size: f32 = 1.0;
let mut offset = 20.0;
let c = pen_color.0;
if let Some(buttons) = pen_buttons.read().next()
&& buttons.a()
{
offset *= 4.;
};
for penpres in pen_pressure.read() {
let _in = penpres.pressure;
let _out = penpres.pressure.powi(4);
size *= 1. + (_out * offset);
}
pen_size.0 = size.clamp(1.0, 200.0);
let s = pen_size.0 as i32;
let b = css::BLACK.into();
let cs = 10;
let cd = 3;
for penpos in pen_position.read() {
let x = (penpos.x * (buffer.width as f32)) as i32;
let y = (penpos.y * (buffer.height as f32)) as i32;
buffer.clear(Srgba::new(0.0, 0.0, 0.0, 0.0).into()).ok();
buffer.draw_stroke(x - (cs + cd) - s, y, x - (cd) - s, y, 4.0, b);
buffer.draw_stroke(x - (cs + cd) - s, y, x - (cd) - s, y, 1.0, c);
buffer.draw_stroke(x + (cd) + s, y, x + (cs + cd) + s, y, 4.0, b);
buffer.draw_stroke(x + (cd) + s, y, x + (cs + cd) + s, y, 1.0, c);
buffer.draw_stroke(x, y - (cs + cd) - s, x, y - (cd) - s, 4.0, b);
buffer.draw_stroke(x, y - (cs + cd) - s, x, y - (cd) - s, 1.0, c);
buffer.draw_stroke(x, y + (cs + cd) + s, x, y + (cd) + s, 4.0, b);
buffer.draw_stroke(x, y + (cs + cd) + s, x, y + (cd) + s, 1.0, c);
}
}
fn draw(
pen_size: Res<PenSize>,
pen_color: Res<PenColor>,
ui: Query<&Visible, With<uiplugin::UiBuffer>>,
mut lastloc: ResMut<LastPenPos>,
mut buffer: Query<&mut DrawableLayer, With<DrawingBuffer>>,
mut pen_buttons: MessageReader<PenButtons>,
mut pen_position: MessageReader<PenPosition>,
) {
if ui.single().is_ok() {
lastloc.0 = None;
return; // if the ui layer is visible, dont draw
}
let Ok(mut buffer) = buffer.single_mut() else {
return;
};
let Some(buttons) = pen_buttons.read().next() else {
return;
};
for penpos in pen_position.read() {
let x = (penpos.x * (buffer.width as f32)) as i32;
let y = (penpos.y * (buffer.height as f32)) as i32;
let Some(ll) = lastloc.0 else {
lastloc.0 = Some((x, y));
return;
};
if buttons.tip() {
buffer.draw_stroke(ll.0, ll.1, x, y, pen_size.0, pen_color.0);
}
lastloc.0 = Some((x, y));
}
}
fn plot(
buffers: Query<&DrawableLayer, With<Visible>>,
mut images: ResMut<Assets<Image>>,
mut materials: ResMut<Assets<WebviewExtendStandardMaterial>>,
webviews: Query<&MeshMaterial3d<WebviewExtendStandardMaterial>>,
my_handle: Res<MyProcGenImage>,
) {
let image = images.get_mut(&my_handle.0).expect("Image not found");
image.clear(&[0, 0, 0, 0]);
let sorted = buffers
.iter()
.sort_by::<&DrawableLayer>(|a, b| b.order.cmp(&a.order));
for layer in sorted {
for (i, c) in layer.buffer.chunks(4).enumerate() {
let x = i % layer.width;
let y = i / layer.width;
let red: u8 = c[0];
let green = c[1];
let blue = c[2];
let alpha = c[3];
if alpha > 0 {
let color = Color::srgba_u8(red, green, blue, alpha);
image.set_color_at(x as u32, y as u32, color).unwrap();
}
}
}
// Poke redraw
for handle in webviews {
if let Some(material) = materials.get_mut(handle.id()) {
material.extension.overlay = Some(my_handle.0.clone());
}
}
}

View File

@@ -0,0 +1,342 @@
use bevy::{color::Color, ecs::component::Component};
use embedded_graphics::{pixelcolor::Rgb888, prelude::*, primitives::*};
use crate::drawingplugin::rgba::Rgba;
#[allow(unused)]
#[derive(PartialEq, Eq, PartialOrd, Ord)]
pub enum Layer {
Drawing,
Ui,
Cursor,
}
#[derive(Component)]
pub struct Visible;
#[derive(Component)]
pub struct DrawableLayer {
pub order: Layer,
pub width: usize,
pub height: usize,
pub buffer: Vec<u8>,
}
impl DrawableLayer {
pub fn new(width: usize, height: usize, order: Layer) -> Self {
let buffer = vec![0; width * height * 4];
Self {
order,
width,
height,
buffer,
}
}
}
#[allow(unused)]
impl DrawableLayer {
pub fn draw_stroke(
&mut self,
x1: i32,
y1: i32,
x2: i32,
y2: i32,
thickness: f32,
color: Color,
) {
let (mut x0, mut y0) = (x1, y1);
let (x1, y1) = (x2, y2);
let dx = (x1 - x0).abs();
let dy = -(y1 - y0).abs();
let sx = if x0 < x1 { 1 } else { -1 };
let sy = if y0 < y1 { 1 } else { -1 };
let mut err = dx + dy;
let half_t = (thickness / 2.0).ceil() as i32;
loop {
self.draw_filled_circle(x0, y0, half_t, color);
if x0 == x1 && y0 == y1 {
break;
}
let e2 = 2 * err;
if e2 >= dy {
err += dy;
x0 += sx;
}
if e2 <= dx {
err += dx;
y0 += sy;
}
}
}
pub fn set_color_at(&mut self, x: i32, y: i32, color: Color) {
Pixel(Point::new(x, y), super::rgba::Rgba::from(color.to_srgba()))
.draw(self)
.ok();
}
pub fn draw_line(&mut self, x1: i32, y1: i32, x2: i32, y2: i32, thickness: f32, color: Color) {
Line::new(Point::new(x1, y1), Point::new(x2, y2))
.into_styled(PrimitiveStyle::with_stroke(
Rgba::from(color.to_srgba()),
thickness as u32,
))
.draw(self)
.ok();
}
pub fn draw_circle(&mut self, cx: i32, cy: i32, radius: i32, thickness: f32, color: Color) {
Circle::new(Point::new(cx - radius, cy - radius), (radius * 2) as u32)
.into_styled(PrimitiveStyle::with_stroke(
Rgba::from(color.to_srgba()),
thickness as u32,
))
.draw(self)
.ok();
}
pub fn draw_filled_circle(&mut self, cx: i32, cy: i32, radius: i32, color: Color) {
Circle::new(Point::new(cx - radius, cy - radius), (radius * 2) as u32)
.into_styled(PrimitiveStyle::with_fill(Rgba::from(color.to_srgba())))
.draw(self)
.ok();
}
pub fn draw_rectangle(&mut self, x: i32, y: i32, w: u32, h: u32, thickness: f32, color: Color) {
Rectangle::new(Point::new(x, y), Size::new(w, h))
.into_styled(PrimitiveStyle::with_stroke(
Rgba::from(color.to_srgba()),
thickness as u32,
))
.draw(self)
.ok();
}
pub fn draw_filled_rectangle(&mut self, x: i32, y: i32, w: u32, h: u32, color: Color) {
Rectangle::new(Point::new(x, y), Size::new(w, h))
.into_styled(PrimitiveStyle::with_fill(Rgba::from(color.to_srgba())))
.draw(self)
.ok();
}
}
impl Dimensions for DrawableLayer {
fn bounding_box(&self) -> embedded_graphics::primitives::Rectangle {
Rectangle::new(
Point::new(0, 0),
Size::new(self.width as u32, self.height as u32),
)
}
}
impl DrawTarget for DrawableLayer {
type Color = Rgba<Rgb888>;
type Error = Box<dyn std::error::Error>;
fn draw_iter<I>(&mut self, pixels: I) -> Result<(), Self::Error>
where
I: IntoIterator<Item = embedded_graphics::Pixel<Self::Color>>,
{
for p in pixels {
let x = p.0.x as usize;
let y = p.0.y as usize;
if !(0..=self.width).contains(&x) || !(0..=self.height).contains(&y) {
continue;
}
let index = (x + (self.width * y)) * 4;
if index >= self.buffer.len() {
continue;
}
self.buffer[index] = p.1.r();
self.buffer[index + 1] = p.1.g();
self.buffer[index + 2] = p.1.b();
self.buffer[index + 3] = p.1.a();
}
Ok(())
}
}
// pub fn set_color_at(&mut self, x: i32, y: i32, color: Color) {
// let x: usize = x as usize;
// let y: usize = y as usize;
// if !(0..=self.width).contains(&x) || !(0..=self.height).contains(&y) {
// return;
// }
// let index = (x + (self.width * y)) * 4;
// let srgba = Srgba::from(color);
// if index >= self.buffer.len() {
// return;
// }
// self.buffer[index] = (srgba.red * u8::MAX as f32) as u8;
// self.buffer[index + 1] = (srgba.green * u8::MAX as f32) as u8;
// self.buffer[index + 2] = (srgba.blue * u8::MAX as f32) as u8;
// self.buffer[index + 3] = (srgba.alpha * u8::MAX as f32) as u8;
// }
// pub fn clear(&mut self) {
// self.buffer.fill(0);
// }
// pub fn draw_line(&mut self, x1: i32, y1: i32, x2: i32, y2: i32, thickness: f32, color: Color) {
// let (mut x0, mut y0) = (x1, y1);
// let (x1, y1) = (x2, y2);
// let dx = (x1 - x0).abs();
// let dy = -(y1 - y0).abs();
// let sx = if x0 < x1 { 1 } else { -1 };
// let sy = if y0 < y1 { 1 } else { -1 };
// let mut err = dx + dy;
// let half_t = (thickness / 2.0).ceil() as i32;
// loop {
// self.draw_thick_point(x0, y0, half_t, color);
// if x0 == x1 && y0 == y1 {
// break;
// }
// let e2 = 2 * err;
// if e2 >= dy {
// err += dy;
// x0 += sx;
// }
// if e2 <= dx {
// err += dx;
// y0 += sy;
// }
// }
// }
// // Draw a small square brush (fast, branch-free inner loop)
// pub fn draw_thick_point(&mut self, cx: i32, cy: i32, radius: i32, color: Color) {
// self.draw_filled_circle(cx, cy, radius, color);
// }
// pub fn draw_filled_circle(&mut self, cx: i32, cy: i32, radius: i32, color: Color) {
// let r2 = radius * radius;
// for dy in -radius..=radius {
// let y = cy + dy;
// if y < 0 {
// continue;
// }
// let dx_limit = ((r2 - dy * dy) as f32).sqrt() as i32;
// let start_x = cx - dx_limit;
// let end_x = cx + dx_limit;
// for x in start_x..=end_x {
// if x >= 0 {
// self.set_color_at(x, y, color);
// }
// }
// }
// }
// pub fn draw_circle(&mut self, cx: i32, cy: i32, radius: i32, thickness: f32, color: Color) {
// if radius <= 0 {
// return;
// }
// let half_t = (thickness / 2.0).max(0.5);
// let outer_r = radius as f32 + half_t;
// let inner_r = (radius as f32 - half_t).max(0.0);
// let outer_r2 = (outer_r * outer_r) as i32;
// let inner_r2 = (inner_r * inner_r) as i32;
// let max_r = outer_r.ceil() as i32;
// for dy in -max_r..=max_r {
// let y = cy + dy;
// if y < 0 {
// continue;
// }
// let dy2 = dy * dy;
// if dy2 > outer_r2 {
// continue;
// }
// let outer_dx = ((outer_r2 - dy2) as f32).sqrt() as i32;
// let inner_dx = if dy2 < inner_r2 {
// ((inner_r2 - dy2) as f32).sqrt() as i32
// } else {
// -1
// };
// let left_outer = cx - outer_dx;
// let right_outer = cx + outer_dx;
// if inner_dx >= 0 {
// let left_inner = cx - inner_dx;
// let right_inner = cx + inner_dx;
// // left segment
// for x in left_outer..left_inner {
// if x >= 0 {
// self.set_color_at(x, y, color);
// }
// }
// // right segment
// for x in (right_inner + 1)..=right_outer {
// if x >= 0 {
// self.set_color_at(x, y, color);
// }
// }
// } else {
// // fully filled span (very thin or small radius)
// for x in left_outer..=right_outer {
// if x >= 0 {
// self.set_color_at(x, y, color);
// }
// }
// }
// }
// }
// pub fn draw_rectangle(&mut self, x: i32, y: i32, w: u32, h: u32, thickness: f32, color: Color) {
// let w = w as i32;
// let h = h as i32;
// self.draw_line(x, y, x + w, y, thickness, color);
// self.draw_line(x + w, y, x + w, y + h, thickness, color);
// self.draw_line(x, y + h, x + w, y + h, thickness, color);
// self.draw_line(x, y, x, y + h, thickness, color);
// }
// pub fn draw_filled_rectangle(
// &mut self,
// x: i32,
// y: i32,
// w: u32,
// h: u32,
// thickness: f32,
// color: Color,
// ) {
// let w = w as i32;
// let h = h as i32;
// for i in 0..h {
// self.draw_line(x, y + i, x + w, y + i, thickness, color);
// }
// }
// }

94
src/drawingplugin/rgba.rs Normal file
View File

@@ -0,0 +1,94 @@
use bevy::color::Srgba;
use embedded_graphics_core::pixelcolor::*;
/// Simple RGBA color wrapper.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct Rgba<C: RgbColor>(C, u8);
#[allow(unused)]
#[inline(always)]
fn mul_blend_u8(delta: u32, a: u32) -> u32 {
// Exact (delta * a) / 255 using the div255 trick (no slow integer division).
// Valid for 0..=65535 inputs; see Hacker's Delight 10-16.
let t = delta * a + 128;
(t + (t >> 8)) >> 8
}
#[allow(unused)]
impl<C: RgbColor> Rgba<C> {
/// Create a new RGBA color.
pub const fn new(color: C, alpha: u8) -> Self {
Self(color, alpha)
}
/// Get the color component.
pub const fn rgb(&self) -> C {
self.0
}
pub fn r(&self) -> u8 {
self.0.r()
}
pub fn g(&self) -> u8 {
self.0.g()
}
pub fn b(&self) -> u8 {
self.0.b()
}
/// Get the alpha component (0..=255).
pub const fn a(&self) -> u8 {
self.1
}
}
impl<C: RgbColor> PixelColor for Rgba<C> {
type Raw = C::Raw;
}
#[allow(unused)]
pub trait Blend<T> {
fn blend(&self, bg: T) -> T;
}
impl Blend<Rgb888> for Rgba<Rgb888> {
#[inline(always)]
fn blend(&self, bg: Rgb888) -> Rgb888 {
let a = self.a() as u32;
if a == 0 {
return bg;
}
if a == 255 {
return self.rgb();
}
let fr = self.rgb().r() as u32;
let fg = self.rgb().g() as u32;
let fb = self.rgb().b() as u32;
let br = bg.r() as u32;
let bgc = bg.g() as u32;
let bb = bg.b() as u32;
let r = (br + mul_blend_u8(fr.wrapping_sub(br), a)) as u8;
let g = (bgc + mul_blend_u8(fg.wrapping_sub(bgc), a)) as u8;
let b = (bb + mul_blend_u8(fb.wrapping_sub(bb), a)) as u8;
Rgb888::new(r, g, b)
}
}
impl From<Srgba> for Rgba<Rgb888> {
fn from(value: Srgba) -> Self {
Self(
Rgb888::new(
(value.red * 255.) as u8,
(value.green * 255.) as u8,
(value.blue * 255.) as u8,
),
(value.alpha * 255.) as u8,
)
}
}

View File

@@ -0,0 +1,270 @@
use std::f32;
use bevy::{color::palettes::css, prelude::*};
use embedded_graphics::prelude::DrawTarget;
use crate::{
drawingplugin::{DrawingBuffer, IMAGE_HEIGHT, IMAGE_WIDTH, PenColor, drawtarget::Visible},
otdipcplugin::{PenButtons, PenPosition},
};
use super::drawtarget::{DrawableLayer, Layer};
#[derive(Component)]
pub struct UiBuffer;
#[derive(Component, Deref)]
pub struct UiPosition(Vec2);
pub struct UiPlugin;
impl Plugin for UiPlugin {
fn build(&self, app: &mut App) {
app.add_systems(Startup, setup).add_systems(
Update,
(
show_hide,
ui_on_show,
ui_on_hide,
color_changer,
clear,
color_picker,
),
);
}
}
fn setup(mut commands: Commands) {
commands.spawn((
UiBuffer,
DrawableLayer::new(IMAGE_WIDTH, IMAGE_HEIGHT, Layer::Ui),
));
}
fn show_hide(
mut commands: Commands,
mut pen_buttons: MessageReader<PenButtons>,
ent: Query<Entity, With<UiBuffer>>,
) {
let Ok(ent) = ent.single() else {
return;
};
let Some(buttons) = pen_buttons.read().next() else {
return;
};
if buttons.b() {
commands.entity(ent).insert(Visible);
} else {
commands.entity(ent).remove::<Visible>();
}
}
fn ui_on_show(
mut commands: Commands,
ent: Query<Entity, Added<Visible>>,
mut pen_position: MessageReader<PenPosition>,
) {
let Ok(ent) = ent.single() else {
return;
};
let Some(pos) = pen_position.read().next() else {
return;
};
commands.entity(ent).insert(UiPosition(**pos));
}
fn ui_on_hide(mut commands: Commands, mut removed: RemovedComponents<Visible>) {
let Some(ent) = removed.read().next() else {
return;
};
commands
.entity(ent)
.insert(UiPosition(Vec2::new(-1000., -1000.)));
}
fn color_picker(mut buffer: Query<(&mut DrawableLayer, &UiPosition), With<UiBuffer>>) {
let Ok((mut buffer, base_pos)) = buffer.single_mut() else {
return;
};
let w = buffer.width as f32;
let h = buffer.height as f32;
let x = (base_pos.x * w) as i32;
let y = (base_pos.y * h) as i32;
buffer.clear(Srgba::new(0.0, 0.0, 0.0, 0.0).into()).ok();
color_wheel(&mut buffer, x, y, 100);
buffer.draw_circle(x, y, 100, 5.0, css::BLACK.into());
buffer.draw_circle(x, y, 125, 3.0, css::BLACK.into());
}
#[allow(clippy::type_complexity)]
fn clear(
buffer: Query<
(&DrawableLayer, &UiPosition),
(With<UiBuffer>, With<Visible>, Without<DrawingBuffer>),
>,
mut draw_buffer: Query<&mut DrawableLayer, (With<DrawingBuffer>, Without<UiBuffer>)>,
mut pen_position: MessageReader<PenPosition>,
mut pen_buttons: MessageReader<PenButtons>,
) {
let Ok((buffer, base_pos)) = buffer.single() else {
return;
};
let Ok(mut draw_buffer) = draw_buffer.single_mut() else {
return;
};
let Some(pos) = pen_position.read().next() else {
return;
};
let Some(buttons) = pen_buttons.read().next() else {
return;
};
if !buttons.tip() {
return;
}
let w = buffer.width as f32;
let h = buffer.height as f32;
let ui_x = base_pos.x * w;
let ui_y = base_pos.y * h;
let pen_x = pos.x * w;
let pen_y = pos.y * h;
let delta = Vec2::new(pen_x - ui_x, pen_y - ui_y);
let radius = 100.;
let r_sq = radius * radius;
let dist_sq = delta.length_squared();
if dist_sq <= (r_sq * 1.5) {
return;
}
draw_buffer.clear(Srgba::rgba_u8(0, 0, 0, 0).into()).ok();
}
#[allow(clippy::type_complexity)]
fn color_changer(
buffer: Query<(&DrawableLayer, &UiPosition), (With<UiBuffer>, With<Visible>)>,
mut pen_color: ResMut<PenColor>,
mut pen_position: MessageReader<PenPosition>,
mut pen_buttons: MessageReader<PenButtons>,
) {
let Ok((buffer, base_pos)) = buffer.single() else {
return;
};
let Some(pos) = pen_position.read().next() else {
return;
};
let Some(buttons) = pen_buttons.read().next() else {
return;
};
if !buttons.tip() {
return;
}
let w = buffer.width as f32;
let h = buffer.height as f32;
let ui_x = base_pos.x * w;
let ui_y = base_pos.y * h;
let pen_x = pos.x * w;
let pen_y = pos.y * h;
let delta = Vec2::new(pen_x - ui_x, pen_y - ui_y);
let radius = 100.;
let r_sq = radius * radius;
let dist_sq = delta.length_squared();
if dist_sq > (r_sq * 1.5) {
return;
}
pen_color.0 = color_from_pos(delta.x, delta.y, radius);
}
fn color_wheel(buffer: &mut DrawableLayer, cx: i32, cy: i32, radius: i32) {
for dy in -radius..=radius {
for dx in -radius..=radius {
let x = cx + dx;
let y = cy + dy;
buffer.set_color_at(x, y, color_from_pos(dx as f32, dy as f32, radius as f32));
}
}
}
fn color_from_pos(x: f32, y: f32, radius: f32) -> Color {
let r_sq = radius * radius;
let dist_sq = x * x + y * y;
if dist_sq > r_sq {
return Color::srgba(0.0, 0.0, 0.0, 0.0);
}
// Distance normalized (0.0 → 1.0)
let dist = dist_sq.sqrt() / radius;
// Angle in radians → [0, 1]
let angle = y.atan2(x); // -PI..PI
let hue = (angle + std::f32::consts::PI) / (2.0 * std::f32::consts::PI);
let (r, g, b) = hsl_to_rgb(hue, 1.0, dist);
Color::srgba(r, g, b, 1.0)
}
fn hsl_to_rgb(h: f32, s: f32, l: f32) -> (f32, f32, f32) {
if s == 0.0 {
return (l, l, l);
}
fn hue_to_rgb(p: f32, q: f32, mut t: f32) -> f32 {
if t < 0.0 {
t += 1.0;
}
if t > 1.0 {
t -= 1.0;
}
if t < 1.0 / 6.0 {
return p + (q - p) * 6.0 * t;
}
if t < 1.0 / 2.0 {
return q;
}
if t < 2.0 / 3.0 {
return p + (q - p) * (2.0 / 3.0 - t) * 6.0;
}
p
}
let q = if l < 0.5 {
l * (1.0 + s)
} else {
l + s - l * s
};
let p = 2.0 * l - q;
let r = hue_to_rgb(p, q, h + 1.0 / 3.0);
let g = hue_to_rgb(p, q, h);
let b = hue_to_rgb(p, q, h - 1.0 / 3.0);
(r, g, b)
}

View File

@@ -1,20 +1,22 @@
use std::f32::consts::{FRAC_PI_2, PI};
use bevy::prelude::*;
use bevy_cef::prelude::*;
use bevy_mod_openxr::prelude::*;
use bevy_mod_xr::session::XrSessionCreated;
use bevy_pkv::{PersistentResourceAppExtensions, PkvStore};
use openxr::Path;
use serde::{Deserialize, Serialize};
use std::f32::consts::{FRAC_PI_2, PI};
use crate::{
MainCamera,
drawingplugin::{self, MyProcGenImage},
vrcontrollerplugin::{
LeftController, LeftControllerActions, RightController, RightControllerActions,
},
vrplugin::{Headset, MainCamera, create_view_space},
vrplugin::Headset,
};
// use bevy_mod_xr::session::XrSessionCreated;
#[derive(Component)]
pub struct LookedAt;
@@ -49,7 +51,7 @@ impl Plugin for KneeboardPlugin {
});
app.insert_resource(PkvStore::new("Avii", "Kneeboard"))
.init_persistent_resource::<KneeboardPosition>();
app.add_systems(XrSessionCreated, spawn_kneeboard.after(create_view_space));
app.add_systems(Startup, spawn_kneeboard.after(drawingplugin::setup));
app.add_systems(Update, gaze.run_if(openxr_session_running));
app.add_systems(Update, move_keyboard.run_if(openxr_session_running));
app.add_systems(Update, position_kneeboard.after(move_keyboard));
@@ -106,7 +108,9 @@ fn position_kneeboard(
return;
};
let head = head.single().expect("a head to exist");
let Ok(head) = head.single() else {
return;
};
transform.translation = kneeboard.position;
transform.rotation = kneeboard.rotation;
@@ -158,18 +162,22 @@ fn spawn_kneeboard(
mut commands: Commands,
mut meshes: ResMut<Assets<Mesh>>,
mut materials: ResMut<Assets<WebviewExtendStandardMaterial>>,
image_handle: Res<MyProcGenImage>,
position: Res<KneeboardPosition>,
) {
commands.spawn((
WebviewSource::new("http://localhost:7878/"), // i want this to become dynamic.... from ui or something
WebviewSize(Vec2::new(210.0 * 3.5, 279.0 * 3.5)), // this can also be dynamic... kinda like rotating phone
// WebviewSource::new("http://localhost:7878/MOSRPRPETASPCLORWTSURDEP"),
WebviewSize(Vec2::new(210.0 * 3.5, 279.0 * 3.5)),
Mesh3d(meshes.add(Cuboid::new(0.210, 0.279, 0.01))),
MeshMaterial3d(materials.add(WebviewExtendStandardMaterial {
base: StandardMaterial {
unlit: true,
..default()
},
..Default::default()
extension: WebviewMaterial {
surface: None,
overlay: Some(image_handle.0.clone()),
},
})),
Transform::from_translation(position.position).rotate(position.rotation),
Kneeboard,

View File

@@ -1,24 +1,59 @@
//! A simple 3D scene with light shining over a cube sitting on a plane.
mod drawingplugin;
mod kneeboardplugin;
mod otdipcplugin;
#[allow(unused)]
mod vrcontrollerplugin;
#[allow(unused)]
mod vrplugin;
#[allow(unused)]
use vrcontrollerplugin::VrControllersPlugin;
#[allow(unused)]
use vrplugin::VrPlugin;
use bevy::prelude::*;
use bevy::{
prelude::*,
window::{PresentMode, WindowResolution},
};
use crate::{kneeboardplugin::KneeboardPlugin, vrcontrollerplugin::VrControllersPlugin};
use crate::{
drawingplugin::DrawingPlugin, kneeboardplugin::KneeboardPlugin, otdipcplugin::TabletRotation,
};
#[derive(Component)]
#[require(Camera3d)]
pub struct MainCamera;
fn main() {
App::new()
.add_plugins(VrPlugin)
.add_plugins(VrControllersPlugin)
// .add_plugins(VrPlugin)
// .add_plugins(VrControllersPlugin)
.add_plugins(DefaultPlugins.set(WindowPlugin {
primary_window: Some(Window {
title: "Kneeboard".into(),
resolution: WindowResolution::new(550, 720),
present_mode: PresentMode::AutoNoVsync,
fit_canvas_to_parent: true,
prevent_default_event_handling: false,
..default()
}),
..default()
}))
.add_systems(Startup, setup)
.add_plugins(DrawingPlugin)
.add_plugins(KneeboardPlugin)
.insert_resource(ClearColor(Color::NONE))
// .insert_resource(GlobalAmbientLight {
// brightness: 1000.0,
// ..GlobalAmbientLight::default()
// })
.insert_resource(TabletRotation::CW)
.run();
}
fn setup(mut commands: Commands) {
commands.spawn((
Camera {
clear_color: ClearColorConfig::Custom(Color::linear_rgb(0.3, 0.3, 0.3)),
..default()
},
MainCamera,
Transform::from_xyz(-2.5, 4.5, 9.0).looking_at(Vec3::ZERO, Vec3::Y),
));
}

131
src/otdipcplugin.rs Normal file
View File

@@ -0,0 +1,131 @@
use bevy::{
app::{App, Plugin, PreUpdate},
ecs::{
message::MessageWriter,
resource::Resource,
system::{Res, ResMut},
},
math::Vec2,
prelude::Deref,
};
use otd_ipc::{Message, OtdIpc};
use triple_buffer::{Output, triple_buffer};
#[derive(Resource)]
struct OtdChannel(Output<Option<Message>>);
#[derive(Resource)]
struct TabletSize(Option<Vec2>);
#[derive(Resource)]
struct MaxPenPressure(Option<u32>);
#[derive(bevy::ecs::message::Message, Deref)]
pub struct PenPosition(Vec2);
#[derive(bevy::ecs::message::Message, Deref)]
pub struct PenButtons(u32);
impl PenButtons {
pub fn tip(&self) -> bool {
self.0 & 1 == 1
}
pub fn a(&self) -> bool {
self.0 & 2 == 2
}
pub fn b(&self) -> bool {
self.0 & 4 == 4
}
}
#[derive(bevy::ecs::message::Message)]
pub struct PenPressure {
pub pressure: f32,
}
#[allow(clippy::upper_case_acronyms)]
#[allow(unused)]
#[derive(Resource)]
pub enum TabletRotation {
Default,
CW,
UpsideDown,
CCW,
}
pub struct OtdIpcPlugin;
impl Plugin for OtdIpcPlugin {
fn build(&self, app: &mut App) {
let (mut tx, rx) = triple_buffer(&None);
std::thread::spawn(move || {
let otd_ipc = OtdIpc::new("Kneeboard", "master").unwrap();
for msg in otd_ipc {
tx.write(Some(msg));
}
});
app.add_message::<PenPosition>();
app.add_message::<PenPressure>();
app.add_message::<PenButtons>();
app.insert_resource(TabletRotation::Default);
app.insert_resource(OtdChannel(rx));
app.insert_resource(MaxPenPressure(None));
app.insert_resource(TabletSize(None));
app.add_systems(PreUpdate, reader);
}
}
#[allow(clippy::too_many_arguments)]
fn reader(
rotation: Res<TabletRotation>,
mut channel: ResMut<OtdChannel>,
mut size: ResMut<TabletSize>,
mut pressure: ResMut<MaxPenPressure>,
mut pressure_writer: MessageWriter<PenPressure>,
mut position_writer: MessageWriter<PenPosition>,
mut button_writer: MessageWriter<PenButtons>,
) {
let Some(msg) = channel.0.read() else {
return;
};
match msg {
otd_ipc::Message::DeviceInfo(info) => {
size.0 = Some(Vec2::new(info.max_x, info.max_y));
pressure.0 = Some(info.max_pressure);
}
otd_ipc::Message::State(state) => {
let Some(size) = size.0 else {
return;
};
let Some(pressure) = pressure.0 else {
return;
};
button_writer.write(PenButtons(state.pen_buttons()));
let p = state.pressure() as f32 / pressure as f32;
pressure_writer.write(PenPressure { pressure: p });
let x = state.x();
let y = state.y();
let loc = match *rotation {
TabletRotation::Default => Vec2::new(x / size.x, y / size.y),
TabletRotation::CCW => Vec2::new(y / size.y, (size.x - x) / size.x),
TabletRotation::CW => Vec2::new((size.y - y) / size.y, x / size.x),
TabletRotation::UpsideDown => {
Vec2::new((size.x - x) / size.x, (size.y - y) / size.y)
}
};
position_writer.write(PenPosition(loc));
}
_ => {}
}
}

View File

@@ -46,11 +46,17 @@ impl Plugin for VrControllersPlugin {
.run_if(openxr_session_running),
);
app.add_systems(OxrSendActionBindings, suggest_action_bindings_left);
app.add_systems(OxrSendActionBindings, suggest_action_bindings_right);
app.add_systems(Startup, create_actions_left.run_if(session_available));
app.add_systems(Startup, create_actions_right.run_if(session_available));
app.add_systems(
OxrSendActionBindings,
suggest_action_bindings_left.after(create_actions_left),
);
app.add_systems(
OxrSendActionBindings,
suggest_action_bindings_right.after(create_actions_right),
);
}
}

View File

@@ -1,14 +1,11 @@
use bevy::{
prelude::*,
render::render_resource::TextureFormat,
window::{PresentMode, WindowResolution},
};
use bevy_mod_openxr::prelude::*;
use bevy_mod_xr::session::XrSessionCreated;
#[derive(Component)]
#[require(Camera3d)]
pub struct MainCamera;
#[derive(Component)]
pub struct Headset;
@@ -20,7 +17,7 @@ impl Plugin for VrPlugin {
add_xr_plugins(DefaultPlugins.set(WindowPlugin {
primary_window: Some(Window {
title: "Kneeboard".into(),
resolution: WindowResolution::new(550, 720).with_scale_factor_override(1.0),
resolution: WindowResolution::new(550, 720),
present_mode: PresentMode::AutoNoVsync,
fit_canvas_to_parent: true,
prevent_default_event_handling: false,
@@ -41,18 +38,12 @@ impl Plugin for VrPlugin {
);
app.insert_resource(OxrSessionConfig {
blend_mode_preference: {
vec![
EnvironmentBlendMode::ALPHA_BLEND,
EnvironmentBlendMode::ADDITIVE,
EnvironmentBlendMode::OPAQUE,
]
},
..OxrSessionConfig::default()
blend_mode_preference: { vec![EnvironmentBlendMode::ALPHA_BLEND] },
formats: Some(vec![TextureFormat::Rgba8UnormSrgb]),
..Default::default()
});
app.add_systems(XrSessionCreated, create_view_space);
// .add_systems(Update, sync_head_with_camera.run_if(openxr_session_running));
}
}
@@ -62,21 +53,4 @@ pub fn create_view_space(session: Res<OxrSession>, mut commands: Commands) {
.unwrap();
commands.spawn((Headset, space.0));
commands.spawn((
Camera {
clear_color: ClearColorConfig::Custom(Color::linear_rgb(0.3, 0.3, 0.3)),
..default()
},
MainCamera,
Transform::from_xyz(-2.5, 4.5, 9.0).looking_at(Vec3::ZERO, Vec3::Y),
));
}
// fn sync_head_with_camera(
// heads: Query<&Transform, With<Headset>>,
// cameras: Query<&mut Transform, (With<MainCamera>, Without<Headset>)>,
// ) {
// for mut camera in cameras {
// *camera = *heads.single().unwrap();
// }
// }