runnable without vr
This commit is contained in:
@@ -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(
|
let image = Image::new_fill(
|
||||||
Extent3d {
|
Extent3d {
|
||||||
width: IMAGE_WIDTH as u32,
|
width: IMAGE_WIDTH as u32,
|
||||||
|
|||||||
@@ -22,7 +22,14 @@ impl Plugin for UiPlugin {
|
|||||||
fn build(&self, app: &mut App) {
|
fn build(&self, app: &mut App) {
|
||||||
app.add_systems(Startup, setup).add_systems(
|
app.add_systems(Startup, setup).add_systems(
|
||||||
Update,
|
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;
|
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
|
commands
|
||||||
.entity(ent)
|
.entity(ent)
|
||||||
.insert(UiPosition(Vec2::new(-1000., -1000.)));
|
.insert(UiPosition(Vec2::new(-1000., -1000.)));
|
||||||
}
|
}
|
||||||
|
|
||||||
fn ui(
|
fn color_picker(mut buffer: Query<(&mut DrawableLayer, &UiPosition), With<UiBuffer>>) {
|
||||||
// pen_color: Res<PenColor>,
|
|
||||||
mut buffer: Query<(&mut DrawableLayer, &UiPosition), With<UiBuffer>>,
|
|
||||||
// mut pen_buttons: MessageReader<PenButtons>,
|
|
||||||
// mut pen_position: MessageReader<PenPosition>,
|
|
||||||
) {
|
|
||||||
let Ok((mut buffer, base_pos)) = buffer.single_mut() else {
|
let Ok((mut buffer, base_pos)) = buffer.single_mut() else {
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,21 +1,22 @@
|
|||||||
use std::f32::consts::{FRAC_PI_2, PI};
|
|
||||||
|
|
||||||
use bevy::prelude::*;
|
use bevy::prelude::*;
|
||||||
use bevy_cef::prelude::*;
|
use bevy_cef::prelude::*;
|
||||||
use bevy_mod_openxr::prelude::*;
|
use bevy_mod_openxr::prelude::*;
|
||||||
use bevy_mod_xr::session::XrSessionCreated;
|
|
||||||
use bevy_pkv::{PersistentResourceAppExtensions, PkvStore};
|
use bevy_pkv::{PersistentResourceAppExtensions, PkvStore};
|
||||||
use openxr::Path;
|
use openxr::Path;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
use std::f32::consts::{FRAC_PI_2, PI};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
drawingplugin::MyProcGenImage,
|
MainCamera,
|
||||||
|
drawingplugin::{self, MyProcGenImage},
|
||||||
vrcontrollerplugin::{
|
vrcontrollerplugin::{
|
||||||
LeftController, LeftControllerActions, RightController, RightControllerActions,
|
LeftController, LeftControllerActions, RightController, RightControllerActions,
|
||||||
},
|
},
|
||||||
vrplugin::{Headset, MainCamera, create_view_space},
|
vrplugin::Headset,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// use bevy_mod_xr::session::XrSessionCreated;
|
||||||
|
|
||||||
#[derive(Component)]
|
#[derive(Component)]
|
||||||
pub struct LookedAt;
|
pub struct LookedAt;
|
||||||
|
|
||||||
@@ -50,7 +51,7 @@ impl Plugin for KneeboardPlugin {
|
|||||||
});
|
});
|
||||||
app.insert_resource(PkvStore::new("Avii", "Kneeboard"))
|
app.insert_resource(PkvStore::new("Avii", "Kneeboard"))
|
||||||
.init_persistent_resource::<KneeboardPosition>();
|
.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, gaze.run_if(openxr_session_running));
|
||||||
app.add_systems(Update, move_keyboard.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));
|
app.add_systems(Update, position_kneeboard.after(move_keyboard));
|
||||||
@@ -107,7 +108,9 @@ fn position_kneeboard(
|
|||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
|
|
||||||
let head = head.single().expect("a head to exist");
|
let Ok(head) = head.single() else {
|
||||||
|
return;
|
||||||
|
};
|
||||||
|
|
||||||
transform.translation = kneeboard.position;
|
transform.translation = kneeboard.position;
|
||||||
transform.rotation = kneeboard.rotation;
|
transform.rotation = kneeboard.rotation;
|
||||||
@@ -163,7 +166,7 @@ fn spawn_kneeboard(
|
|||||||
position: Res<KneeboardPosition>,
|
position: Res<KneeboardPosition>,
|
||||||
) {
|
) {
|
||||||
commands.spawn((
|
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)),
|
WebviewSize(Vec2::new(210.0 * 3.5, 279.0 * 3.5)),
|
||||||
Mesh3d(meshes.add(Cuboid::new(0.210, 0.279, 0.01))),
|
Mesh3d(meshes.add(Cuboid::new(0.210, 0.279, 0.01))),
|
||||||
MeshMaterial3d(materials.add(WebviewExtendStandardMaterial {
|
MeshMaterial3d(materials.add(WebviewExtendStandardMaterial {
|
||||||
|
|||||||
46
src/main.rs
46
src/main.rs
@@ -1,23 +1,59 @@
|
|||||||
mod drawingplugin;
|
mod drawingplugin;
|
||||||
mod kneeboardplugin;
|
mod kneeboardplugin;
|
||||||
mod otdipcplugin;
|
mod otdipcplugin;
|
||||||
|
|
||||||
|
#[allow(unused)]
|
||||||
mod vrcontrollerplugin;
|
mod vrcontrollerplugin;
|
||||||
|
#[allow(unused)]
|
||||||
mod vrplugin;
|
mod vrplugin;
|
||||||
|
|
||||||
|
#[allow(unused)]
|
||||||
|
use vrcontrollerplugin::VrControllersPlugin;
|
||||||
|
#[allow(unused)]
|
||||||
use vrplugin::VrPlugin;
|
use vrplugin::VrPlugin;
|
||||||
|
|
||||||
use bevy::prelude::*;
|
use bevy::{
|
||||||
|
prelude::*,
|
||||||
|
window::{PresentMode, WindowResolution},
|
||||||
|
};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
drawingplugin::DrawingPlugin, kneeboardplugin::KneeboardPlugin,
|
drawingplugin::DrawingPlugin, kneeboardplugin::KneeboardPlugin, otdipcplugin::TabletRotation,
|
||||||
vrcontrollerplugin::VrControllersPlugin,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#[derive(Component)]
|
||||||
|
#[require(Camera3d)]
|
||||||
|
pub struct MainCamera;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
App::new()
|
App::new()
|
||||||
.add_plugins(VrPlugin)
|
// .add_plugins(VrPlugin)
|
||||||
.add_plugins(VrControllersPlugin)
|
// .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(DrawingPlugin)
|
||||||
.add_plugins(KneeboardPlugin)
|
.add_plugins(KneeboardPlugin)
|
||||||
|
.insert_resource(TabletRotation::CW)
|
||||||
.run();
|
.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),
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,6 +1,10 @@
|
|||||||
use bevy::{
|
use bevy::{
|
||||||
app::{App, Plugin, PreUpdate},
|
app::{App, Plugin, PreUpdate},
|
||||||
ecs::{message::MessageWriter, resource::Resource, system::ResMut},
|
ecs::{
|
||||||
|
message::MessageWriter,
|
||||||
|
resource::Resource,
|
||||||
|
system::{Res, ResMut},
|
||||||
|
},
|
||||||
math::Vec2,
|
math::Vec2,
|
||||||
prelude::Deref,
|
prelude::Deref,
|
||||||
};
|
};
|
||||||
@@ -41,6 +45,16 @@ pub struct PenPressure {
|
|||||||
pub pressure: f32,
|
pub pressure: f32,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(clippy::upper_case_acronyms)]
|
||||||
|
#[allow(unused)]
|
||||||
|
#[derive(Resource)]
|
||||||
|
pub enum TabletRotation {
|
||||||
|
Default,
|
||||||
|
CW,
|
||||||
|
UpsideDown,
|
||||||
|
CCW,
|
||||||
|
}
|
||||||
|
|
||||||
pub struct OtdIpcPlugin;
|
pub struct OtdIpcPlugin;
|
||||||
|
|
||||||
impl Plugin for OtdIpcPlugin {
|
impl Plugin for OtdIpcPlugin {
|
||||||
@@ -56,6 +70,7 @@ impl Plugin for OtdIpcPlugin {
|
|||||||
app.add_message::<PenPosition>();
|
app.add_message::<PenPosition>();
|
||||||
app.add_message::<PenPressure>();
|
app.add_message::<PenPressure>();
|
||||||
app.add_message::<PenButtons>();
|
app.add_message::<PenButtons>();
|
||||||
|
app.insert_resource(TabletRotation::Default);
|
||||||
app.insert_resource(OtdChannel(rx));
|
app.insert_resource(OtdChannel(rx));
|
||||||
app.insert_resource(MaxPenPressure(None));
|
app.insert_resource(MaxPenPressure(None));
|
||||||
app.insert_resource(TabletSize(None));
|
app.insert_resource(TabletSize(None));
|
||||||
@@ -65,6 +80,7 @@ impl Plugin for OtdIpcPlugin {
|
|||||||
|
|
||||||
#[allow(clippy::too_many_arguments)]
|
#[allow(clippy::too_many_arguments)]
|
||||||
fn reader(
|
fn reader(
|
||||||
|
rotation: Res<TabletRotation>,
|
||||||
mut channel: ResMut<OtdChannel>,
|
mut channel: ResMut<OtdChannel>,
|
||||||
mut size: ResMut<TabletSize>,
|
mut size: ResMut<TabletSize>,
|
||||||
mut pressure: ResMut<MaxPenPressure>,
|
mut pressure: ResMut<MaxPenPressure>,
|
||||||
@@ -96,11 +112,17 @@ fn reader(
|
|||||||
|
|
||||||
pressure_writer.write(PenPressure { pressure: p });
|
pressure_writer.write(PenPressure { pressure: p });
|
||||||
|
|
||||||
// Make rotation configurable with some resource enum or something
|
let x = state.x();
|
||||||
let y = (size.x - state.x()) / size.x;
|
let y = state.y();
|
||||||
let x = state.y() / size.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));
|
position_writer.write(PenPosition(loc));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,10 +6,6 @@ use bevy::{
|
|||||||
use bevy_mod_openxr::prelude::*;
|
use bevy_mod_openxr::prelude::*;
|
||||||
use bevy_mod_xr::session::XrSessionCreated;
|
use bevy_mod_xr::session::XrSessionCreated;
|
||||||
|
|
||||||
#[derive(Component)]
|
|
||||||
#[require(Camera3d)]
|
|
||||||
pub struct MainCamera;
|
|
||||||
|
|
||||||
#[derive(Component)]
|
#[derive(Component)]
|
||||||
pub struct Headset;
|
pub struct Headset;
|
||||||
|
|
||||||
@@ -57,12 +53,4 @@ pub fn create_view_space(session: Res<OxrSession>, mut commands: Commands) {
|
|||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
commands.spawn((Headset, space.0));
|
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),
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user