feat: newer input system

This commit is contained in:
Nova
2024-07-02 18:27:40 -04:00
parent 4fc7a513b6
commit 0025e8d955
11 changed files with 885 additions and 255 deletions

View File

@@ -4,7 +4,7 @@ use clap::Parser;
use color_eyre::{eyre::Result, Report};
use manifest_dir_macros::directory_relative_path;
use protostar::xdg::parse_desktop_file;
use stardust_xr_fusion::client::Client;
use stardust_xr_fusion::{client::Client, node::NodeType, root::RootAspect};
use std::path::PathBuf;
use tracing_subscriber::EnvFilter;
@@ -26,7 +26,7 @@ async fn main() -> Result<()> {
color_eyre::install()?;
let args = Args::parse();
let (client, event_loop) = Client::connect_with_async_loop().await?;
client.set_base_prefixes(&[directory_relative_path!("../res")]);
client.set_base_prefixes(&[directory_relative_path!("../res")])?;
let protostar = Single::create_from_desktop_file(
client.get_root(),
@@ -34,7 +34,7 @@ async fn main() -> Result<()> {
parse_desktop_file(args.desktop_file).map_err(Report::msg)?,
)?;
let _root = client.wrap_root(protostar)?;
let _root = client.get_root().alias().wrap(protostar)?;
tokio::select! {
_ = tokio::signal::ctrl_c() => (),

View File

@@ -5,14 +5,14 @@ use protostar::{
xdg::{DesktopFile, Icon, IconType},
};
use stardust_xr_fusion::{
client::{ClientState, FrameInfo, RootHandler},
core::values::{color::rgba_linear, ResourceID, Vector3},
drawable::{
MaterialParameter, Model, ModelPartAspect, Text, TextBounds, TextFit, TextStyle, XAlign,
YAlign,
},
fields::BoxField,
fields::{Field, Shape},
node::NodeType,
root::{ClientState, FrameInfo, RootHandler},
spatial::{Spatial, SpatialAspect, SpatialRefAspect, Transform},
};
use stardust_xr_molecules::{Grabbable, GrabbableSettings};
@@ -35,11 +35,11 @@ fn model_from_icon(parent: &Spatial, icon: &Icon) -> Result<Model> {
t,
&ResourceID::new_namespaced("protostar", "hexagon/hexagon"),
)?;
model.model_part("Hex")?.set_material_parameter(
model.part("Hex")?.set_material_parameter(
"color",
MaterialParameter::Color(rgba_linear!(0.0, 1.0, 1.0, 1.0)),
)?;
model.model_part("Icon")?.set_material_parameter(
model.part("Icon")?.set_material_parameter(
"diffuse",
MaterialParameter::Texture(ResourceID::Direct(icon.path.clone())),
)?;
@@ -59,7 +59,7 @@ pub struct Single {
root: Spatial,
position: Vector3<f32>,
grabbable: Grabbable,
_field: BoxField,
_field: Field,
icon: Model,
label: Option<Text>,
grabbable_shrink: Option<Tweener<f32, f64, QuartInOut>>,
@@ -70,13 +70,17 @@ pub struct Single {
impl Single {
pub fn create_from_desktop_file(
parent: &impl SpatialAspect,
parent: &impl SpatialRefAspect,
position: impl Into<Vector3<f32>>,
desktop_file: DesktopFile,
) -> Result<Self> {
let root = Spatial::create(parent, Transform::identity(), false)?;
let position = position.into();
let field = BoxField::create(&root, Transform::identity(), [MODEL_SCALE * 2.0; 3])?;
let field = Field::create(
&root,
Transform::identity(),
Shape::Box([MODEL_SCALE * 2.0; 3].into()),
)?;
let application = Application::create(desktop_file)?;
let icon = application.icon(128, false);
let grabbable = Grabbable::create(
@@ -148,7 +152,7 @@ impl RootHandler for Single {
if let Some(grabbable_move) = &mut self.grabbable_move {
if !grabbable_move.is_finished() {
let scale = grabbable_move.move_by(info.delta);
let scale = grabbable_move.move_by(info.delta.into());
self.grabbable
.content_parent()
.set_relative_transform(
@@ -172,7 +176,7 @@ impl RootHandler for Single {
}
if let Some(grabbable_shrink) = &mut self.grabbable_shrink {
if !grabbable_shrink.is_finished() {
let scale = grabbable_shrink.move_by(info.delta);
let scale = grabbable_shrink.move_by(info.delta.into());
self.grabbable
.content_parent()
.set_relative_transform(&self.root, Transform::from_scale([scale; 3]))
@@ -204,7 +208,7 @@ impl RootHandler for Single {
}
} else if let Some(grabbable_grow) = &mut self.grabbable_grow {
if !grabbable_grow.is_finished() {
let scale = grabbable_grow.move_by(info.delta);
let scale = grabbable_grow.move_by(info.delta.into());
self.grabbable
.content_parent()
.set_relative_transform(&self.root, Transform::from_scale([scale; 3]))
@@ -240,7 +244,7 @@ impl RootHandler for Single {
}
}
fn save_state(&mut self) -> ClientState {
fn save_state(&mut self) -> color_eyre::eyre::Result<ClientState> {
ClientState::from_root(self.content_parent())
}
}