runnable without vr

This commit is contained in:
2026-02-24 03:04:00 +01:00
parent 17a0de5903
commit b05f29da23
6 changed files with 89 additions and 41 deletions

View File

@@ -59,7 +59,7 @@ impl Plugin for DrawingPlugin {
}
}
fn setup(mut commands: Commands, mut images: ResMut<Assets<Image>>) {
pub fn setup(mut commands: Commands, mut images: ResMut<Assets<Image>>) {
let image = Image::new_fill(
Extent3d {
width: IMAGE_WIDTH as u32,

View File

@@ -22,7 +22,14 @@ 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, ui),
(
show_hide,
ui_on_show,
ui_on_hide,
color_changer,
clear,
color_picker,
),
);
}
}
@@ -75,20 +82,12 @@ fn ui_on_hide(mut commands: Commands, mut removed: RemovedComponents<Visible>) {
return;
};
// We should probably ensure that `ent` has a `UiBuffer` on it,
// atm, we're the only one using Visible, so fine for now.
commands
.entity(ent)
.insert(UiPosition(Vec2::new(-1000., -1000.)));
}
fn ui(
// pen_color: Res<PenColor>,
mut buffer: Query<(&mut DrawableLayer, &UiPosition), With<UiBuffer>>,
// mut pen_buttons: MessageReader<PenButtons>,
// mut pen_position: MessageReader<PenPosition>,
) {
fn color_picker(mut buffer: Query<(&mut DrawableLayer, &UiPosition), With<UiBuffer>>) {
let Ok((mut buffer, base_pos)) = buffer.single_mut() else {
return;
};

View File

@@ -1,21 +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::{
drawingplugin::MyProcGenImage,
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;
@@ -50,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));
@@ -107,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;
@@ -163,7 +166,7 @@ fn spawn_kneeboard(
position: Res<KneeboardPosition>,
) {
commands.spawn((
WebviewSource::new("http://localhost:7878/MOSRPRPETASPCLORWTSURDEP"),
// 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 {

View File

@@ -1,23 +1,59 @@
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::{
drawingplugin::DrawingPlugin, kneeboardplugin::KneeboardPlugin,
vrcontrollerplugin::VrControllersPlugin,
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(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),
));
}

View File

@@ -1,6 +1,10 @@
use bevy::{
app::{App, Plugin, PreUpdate},
ecs::{message::MessageWriter, resource::Resource, system::ResMut},
ecs::{
message::MessageWriter,
resource::Resource,
system::{Res, ResMut},
},
math::Vec2,
prelude::Deref,
};
@@ -41,6 +45,16 @@ 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 {
@@ -56,6 +70,7 @@ impl Plugin for OtdIpcPlugin {
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));
@@ -65,6 +80,7 @@ impl Plugin for OtdIpcPlugin {
#[allow(clippy::too_many_arguments)]
fn reader(
rotation: Res<TabletRotation>,
mut channel: ResMut<OtdChannel>,
mut size: ResMut<TabletSize>,
mut pressure: ResMut<MaxPenPressure>,
@@ -96,11 +112,17 @@ fn reader(
pressure_writer.write(PenPressure { pressure: p });
// Make rotation configurable with some resource enum or something
let y = (size.x - state.x()) / size.x;
let x = state.y() / size.y;
let x = state.x();
let y = state.y();
let loc = Vec2::new(x, 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

@@ -6,10 +6,6 @@ use bevy::{
use bevy_mod_openxr::prelude::*;
use bevy_mod_xr::session::XrSessionCreated;
#[derive(Component)]
#[require(Camera3d)]
pub struct MainCamera;
#[derive(Component)]
pub struct Headset;
@@ -57,12 +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),
));
}