Compare commits
5 Commits
dev
...
AnnoyingRa
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3dc32ed3ae | ||
|
|
01ec90c699 | ||
|
|
e60463081e | ||
|
|
cbd99c2cc7 | ||
|
|
62b0fe8240 |
2600
Cargo.lock
generated
2600
Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
25
Cargo.toml
25
Cargo.toml
@@ -1,10 +1,10 @@
|
|||||||
[workspace]
|
[workspace]
|
||||||
resolver = "2"
|
resolver = "2"
|
||||||
members = ["hexagon_launcher", "protostar", "single", "sirius"]
|
members = ["app_grid", "hexagon_launcher", "protostar", "single", "sirius"]
|
||||||
|
|
||||||
[workspace.dependencies]
|
[workspace.dependencies]
|
||||||
tokio = { version = "1.47.1", features = ["rt", "tokio-macros", "sync"] }
|
tokio = { version = "1.32.0", features = ["rt", "tokio-macros", "sync"] }
|
||||||
serde = "1.0.219"
|
serde = "1.0.197"
|
||||||
|
|
||||||
[workspace.dependencies.stardust-xr-fusion]
|
[workspace.dependencies.stardust-xr-fusion]
|
||||||
git = "https://github.com/StardustXR/core.git"
|
git = "https://github.com/StardustXR/core.git"
|
||||||
@@ -13,22 +13,3 @@ branch = "dev"
|
|||||||
[workspace.dependencies.stardust-xr-molecules]
|
[workspace.dependencies.stardust-xr-molecules]
|
||||||
git = "https://github.com/StardustXR/molecules.git"
|
git = "https://github.com/StardustXR/molecules.git"
|
||||||
branch = "dev"
|
branch = "dev"
|
||||||
|
|
||||||
[workspace.dependencies.stardust-xr-asteroids]
|
|
||||||
git = "https://github.com/StardustXR/asteroids.git"
|
|
||||||
branch = "dev"
|
|
||||||
|
|
||||||
[profile]
|
|
||||||
|
|
||||||
[profile.dev]
|
|
||||||
opt-level = 3
|
|
||||||
|
|
||||||
[profile.wasm-dev]
|
|
||||||
inherits = "dev"
|
|
||||||
opt-level = 1
|
|
||||||
|
|
||||||
[profile.server-dev]
|
|
||||||
inherits = "dev"
|
|
||||||
|
|
||||||
[profile.android-dev]
|
|
||||||
inherits = "dev"
|
|
||||||
|
|||||||
@@ -4,13 +4,13 @@ version = "0.1.0"
|
|||||||
edition = "2024"
|
edition = "2024"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
tokio = { version = "1.47.1", features = ["rt", "tokio-macros", "sync"] }
|
tokio = { version = "1.32.0", features = ["rt", "tokio-macros", "sync"] }
|
||||||
protostar = { path = "../protostar" }
|
protostar = { path = "../protostar" }
|
||||||
color-eyre = "0.6.5"
|
color-eyre = "0.6.2"
|
||||||
clap = "4.5.46"
|
clap = "4.4.6"
|
||||||
manifest-dir-macros = "0.1.18"
|
manifest-dir-macros = "0.1.18"
|
||||||
glam = "0.24.2"
|
glam = "0.24.2"
|
||||||
tween = "2.1.0"
|
tween = "2.0.1"
|
||||||
tracing-subscriber = "0.3.20"
|
tracing-subscriber = "0.3.17"
|
||||||
stardust-xr-fusion = { workspace = true }
|
stardust-xr-fusion = { workspace = true }
|
||||||
stardust-xr-molecules = { workspace = true }
|
stardust-xr-molecules = { workspace = true }
|
||||||
|
|||||||
@@ -3,19 +3,19 @@ use glam::{Quat, Vec3};
|
|||||||
use manifest_dir_macros::directory_relative_path;
|
use manifest_dir_macros::directory_relative_path;
|
||||||
use protostar::{
|
use protostar::{
|
||||||
application::Application,
|
application::Application,
|
||||||
xdg::{DesktopFile, Icon, IconType, get_desktop_files, parse_desktop_file},
|
xdg::{get_desktop_files, parse_desktop_file, DesktopFile, Icon, IconType},
|
||||||
};
|
};
|
||||||
use stardust_xr_fusion::{
|
use stardust_xr_fusion::{
|
||||||
ClientHandle,
|
|
||||||
client::Client,
|
client::Client,
|
||||||
core::values::{ResourceID, Vector3, color::rgba_linear},
|
core::values::{color::rgba_linear, ResourceID, Vector3},
|
||||||
drawable::{
|
drawable::{
|
||||||
MaterialParameter, Model, ModelPartAspect, Text, TextBounds, TextFit, TextStyle, XAlign,
|
MaterialParameter, Model, ModelPartAspect, Text, TextBounds, TextFit, TextStyle, XAlign,
|
||||||
YAlign,
|
YAlign,
|
||||||
},
|
},
|
||||||
fields::{Field, Shape},
|
fields::{Field, Shape},
|
||||||
root::{ClientState, FrameInfo, RootAspect},
|
root::{ClientState, FrameInfo, RootAspect},
|
||||||
spatial::{Spatial, SpatialAspect, SpatialRef, SpatialRefAspect, Transform},
|
spatial::{Spatial, SpatialAspect, SpatialRefAspect, Transform},
|
||||||
|
ClientHandle,
|
||||||
};
|
};
|
||||||
use stardust_xr_molecules::{FrameSensitive, Grabbable, GrabbableSettings, UIElement};
|
use stardust_xr_molecules::{FrameSensitive, Grabbable, GrabbableSettings, UIElement};
|
||||||
use std::f32::consts::PI;
|
use std::f32::consts::PI;
|
||||||
@@ -103,7 +103,7 @@ impl AppGrid {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn model_from_icon(parent: &SpatialRef, icon: &Icon) -> Result<Model> {
|
fn model_from_icon(parent: &Spatial, icon: &Icon) -> Result<Model> {
|
||||||
match &icon.icon_type {
|
match &icon.icon_type {
|
||||||
IconType::Png => {
|
IconType::Png => {
|
||||||
// let t = Transform::from_rotation_scale(
|
// let t = Transform::from_rotation_scale(
|
||||||
@@ -145,7 +145,7 @@ pub struct App {
|
|||||||
}
|
}
|
||||||
impl App {
|
impl App {
|
||||||
pub fn create_from_desktop_file(
|
pub fn create_from_desktop_file(
|
||||||
parent: &SpatialRef,
|
parent: &impl SpatialRefAspect,
|
||||||
position: impl Into<Vector3<f32>>,
|
position: impl Into<Vector3<f32>>,
|
||||||
desktop_file: DesktopFile,
|
desktop_file: DesktopFile,
|
||||||
) -> Result<Self> {
|
) -> Result<Self> {
|
||||||
@@ -163,12 +163,12 @@ impl App {
|
|||||||
},
|
},
|
||||||
)?;
|
)?;
|
||||||
grabbable.content_parent().set_spatial_parent(parent)?;
|
grabbable.content_parent().set_spatial_parent(parent)?;
|
||||||
field.set_spatial_parent(&grabbable.content_parent())?;
|
field.set_spatial_parent(grabbable.content_parent())?;
|
||||||
let icon = icon
|
let icon = icon
|
||||||
.map(|i| model_from_icon(&grabbable.content_parent(), &i))
|
.map(|i| model_from_icon(grabbable.content_parent(), &i))
|
||||||
.unwrap_or_else(|| {
|
.unwrap_or_else(|| {
|
||||||
Ok(Model::create(
|
Ok(Model::create(
|
||||||
&grabbable.content_parent(),
|
grabbable.content_parent(),
|
||||||
Transform::from_rotation(Quat::from_rotation_y(PI)),
|
Transform::from_rotation(Quat::from_rotation_y(PI)),
|
||||||
&ResourceID::new_namespaced("protostar", "cartridge"),
|
&ResourceID::new_namespaced("protostar", "cartridge"),
|
||||||
)?)
|
)?)
|
||||||
|
|||||||
17
flake.lock
generated
17
flake.lock
generated
@@ -1,17 +1,12 @@
|
|||||||
{
|
{
|
||||||
"nodes": {
|
"nodes": {
|
||||||
"crane": {
|
"crane": {
|
||||||
"inputs": {
|
|
||||||
"nixpkgs": [
|
|
||||||
"nixpkgs"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1712681629,
|
"lastModified": 1755993354,
|
||||||
"narHash": "sha256-bMDXn4AkTXLCpoZbII6pDGoSeSe9gI87jxPsHRXgu/E=",
|
"narHash": "sha256-FCRRAzSaL/+umLIm3RU3O/+fJ2ssaPHseI2SSFL8yZU=",
|
||||||
"owner": "ipetkov",
|
"owner": "ipetkov",
|
||||||
"repo": "crane",
|
"repo": "crane",
|
||||||
"rev": "220387ac8e99cbee0ca4c95b621c4bc782b6a235",
|
"rev": "25bd41b24426c7734278c2ff02e53258851db914",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
@@ -22,11 +17,11 @@
|
|||||||
},
|
},
|
||||||
"nixpkgs": {
|
"nixpkgs": {
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1712791164,
|
"lastModified": 1756386758,
|
||||||
"narHash": "sha256-3sbWO1mbpWsLepZGbWaMovSO7ndZeFqDSdX0hZ9nVyw=",
|
"narHash": "sha256-1wxxznpW2CKvI9VdniaUnTT2Os6rdRJcRUf65ZK9OtE=",
|
||||||
"owner": "NixOS",
|
"owner": "NixOS",
|
||||||
"repo": "nixpkgs",
|
"repo": "nixpkgs",
|
||||||
"rev": "1042fd8b148a9105f3c0aca3a6177fd1d9360ba5",
|
"rev": "dfb2f12e899db4876308eba6d93455ab7da304cd",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
|
|||||||
@@ -2,7 +2,6 @@
|
|||||||
inputs = {
|
inputs = {
|
||||||
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
|
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
|
||||||
crane = {
|
crane = {
|
||||||
inputs.nixpkgs.follows = "nixpkgs";
|
|
||||||
url = "github:ipetkov/crane";
|
url = "github:ipetkov/crane";
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
@@ -13,9 +12,9 @@
|
|||||||
forAllSystems = nixpkgs.lib.genAttrs supportedSystems;
|
forAllSystems = nixpkgs.lib.genAttrs supportedSystems;
|
||||||
nixpkgsFor = forAllSystems (system: import nixpkgs { inherit system; });
|
nixpkgsFor = forAllSystems (system: import nixpkgs { inherit system; });
|
||||||
in {
|
in {
|
||||||
packages = forAllSystems (system: let pkgs = nixpkgsFor.${system}; in {
|
packages = forAllSystems (system: let pkgs = nixpkgsFor.${system}; craneLib = crane.mkLib pkgs; in {
|
||||||
default = crane.lib.${system}.buildPackage {
|
default = craneLib.buildPackage {
|
||||||
pname = "protostar";
|
pname = "hexagon-launcher";
|
||||||
version = "0.1.0";
|
version = "0.1.0";
|
||||||
src = ./.;
|
src = ./.;
|
||||||
|
|
||||||
|
|||||||
@@ -3,28 +3,15 @@ name = "hexagon_launcher"
|
|||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
edition = "2024"
|
edition = "2024"
|
||||||
|
|
||||||
[features]
|
|
||||||
tracy = ["dep:tracing-tracy", "stardust-xr-asteroids/tracy"]
|
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
protostar = { path = "../protostar" }
|
protostar = { path = "../protostar" }
|
||||||
color-eyre = "0.6.2"
|
color-eyre = "0.6.2"
|
||||||
clap = "4.4.6"
|
clap = "4.4.6"
|
||||||
manifest-dir-macros = "0.1.18"
|
manifest-dir-macros = "0.1.18"
|
||||||
glam = { version = "0.25.0", features = ["mint"] }
|
glam = { version = "0.25.0", features = ["mint"] }
|
||||||
mint = "0.5.9"
|
tween = "2.0.1"
|
||||||
tracing-subscriber = { version = "0.3.18", features = ["env-filter"] }
|
tracing-subscriber = "0.3.17"
|
||||||
tracing-tracy = { version = "0.11.4", default-features = false, features = [
|
|
||||||
"enable",
|
|
||||||
"flush-on-exit",
|
|
||||||
"only-localhost",
|
|
||||||
"sampling",
|
|
||||||
"ondemand",
|
|
||||||
], optional = true }
|
|
||||||
tokio = { workspace = true }
|
tokio = { workspace = true }
|
||||||
serde = { workspace = true }
|
serde = { workspace = true }
|
||||||
stardust-xr-fusion = { workspace = true }
|
stardust-xr-fusion = { workspace = true }
|
||||||
stardust-xr-asteroids = { workspace = true }
|
stardust-xr-molecules = { workspace = true }
|
||||||
tracing = "0.1.41"
|
|
||||||
single = { path = "../single" }
|
|
||||||
rayon = "1.11.0"
|
|
||||||
|
|||||||
301
hexagon_launcher/src/app.rs
Normal file
301
hexagon_launcher/src/app.rs
Normal file
@@ -0,0 +1,301 @@
|
|||||||
|
use color_eyre::eyre::Result;
|
||||||
|
use glam::{EulerRot, Quat, Vec3};
|
||||||
|
use protostar::{
|
||||||
|
application::Application,
|
||||||
|
xdg::{DesktopFile, Icon, IconType},
|
||||||
|
};
|
||||||
|
use stardust_xr_fusion::{
|
||||||
|
core::values::{ResourceID, Vector3},
|
||||||
|
drawable::{
|
||||||
|
MaterialParameter, Model, ModelPartAspect, Text, TextBounds, TextFit, TextStyle, XAlign,
|
||||||
|
YAlign,
|
||||||
|
},
|
||||||
|
fields::{CylinderShape, Field, Shape},
|
||||||
|
node::NodeType,
|
||||||
|
root::FrameInfo,
|
||||||
|
spatial::{Spatial, SpatialAspect, SpatialRefAspect, Transform},
|
||||||
|
};
|
||||||
|
use stardust_xr_molecules::{FrameSensitive as _, Grabbable, GrabbableSettings, UIElement};
|
||||||
|
use std::f32::consts::PI;
|
||||||
|
use tween::{QuartInOut, Tweener};
|
||||||
|
|
||||||
|
use crate::{State, ACTIVATION_DISTANCE, APP_SIZE, DEFAULT_HEX_COLOR};
|
||||||
|
|
||||||
|
// Model handling
|
||||||
|
fn model_from_icon(parent: &Spatial, icon: &Icon) -> Result<Model> {
|
||||||
|
match &icon.icon_type {
|
||||||
|
IconType::Png => {
|
||||||
|
let t = Transform::from_rotation_scale(
|
||||||
|
Quat::from_rotation_x(PI / 2.0) * Quat::from_rotation_y(PI),
|
||||||
|
[APP_SIZE / 2.0; 3],
|
||||||
|
);
|
||||||
|
|
||||||
|
let model = Model::create(
|
||||||
|
parent,
|
||||||
|
t,
|
||||||
|
&ResourceID::new_namespaced("protostar", "hexagon/hexagon"),
|
||||||
|
)?;
|
||||||
|
model
|
||||||
|
.part("Hex")?
|
||||||
|
.set_material_parameter("color", MaterialParameter::Color(DEFAULT_HEX_COLOR))?;
|
||||||
|
model.part("Icon")?.set_material_parameter(
|
||||||
|
"diffuse",
|
||||||
|
MaterialParameter::Texture(ResourceID::Direct(icon.path.clone())),
|
||||||
|
)?;
|
||||||
|
Ok(model)
|
||||||
|
}
|
||||||
|
IconType::Gltf => Ok(Model::create(
|
||||||
|
parent,
|
||||||
|
Transform::from_scale([0.05; 3]),
|
||||||
|
&ResourceID::new_direct(icon.path.clone())?,
|
||||||
|
)?),
|
||||||
|
_ => panic!("Invalid Icon Type"),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct App {
|
||||||
|
application: Application,
|
||||||
|
parent: Spatial,
|
||||||
|
position: Vector3<f32>,
|
||||||
|
grabbable: Grabbable,
|
||||||
|
_field: Field,
|
||||||
|
// field_lines: Lines,
|
||||||
|
icon: Model,
|
||||||
|
label: Option<Text>,
|
||||||
|
grabbable_shrink: Option<Tweener<f32, f64, QuartInOut>>,
|
||||||
|
grabbable_grow: Option<Tweener<f32, f64, QuartInOut>>,
|
||||||
|
grabbable_move: Option<Tweener<f32, f64, QuartInOut>>,
|
||||||
|
}
|
||||||
|
impl App {
|
||||||
|
pub fn create_from_desktop_file(
|
||||||
|
parent: &Spatial,
|
||||||
|
position: impl Into<Vector3<f32>>,
|
||||||
|
desktop_file: DesktopFile,
|
||||||
|
state: &State,
|
||||||
|
) -> Result<Self> {
|
||||||
|
let position = position.into();
|
||||||
|
let field = Field::create(
|
||||||
|
parent,
|
||||||
|
Transform::identity(),
|
||||||
|
Shape::Cylinder(CylinderShape {
|
||||||
|
length: 0.01,
|
||||||
|
radius: APP_SIZE / 2.0,
|
||||||
|
}),
|
||||||
|
)?;
|
||||||
|
// let circle = circle(32, 0.0, APP_SIZE / 2.0).thickness(0.001);
|
||||||
|
// let field_lines = Lines::create(
|
||||||
|
// &field,
|
||||||
|
// Transform::identity(),
|
||||||
|
// &[
|
||||||
|
// circle
|
||||||
|
// .clone()
|
||||||
|
// .transform(Mat4::from_translation([0.0, 0.0, 0.005].into())),
|
||||||
|
// circle
|
||||||
|
// .clone()
|
||||||
|
// .transform(Mat4::from_translation([0.0, 0.0, -0.005].into())),
|
||||||
|
// ],
|
||||||
|
// )?;
|
||||||
|
let application = Application::create(desktop_file)?;
|
||||||
|
let icon = application.icon(128, false);
|
||||||
|
let grabbable = Grabbable::create(
|
||||||
|
parent,
|
||||||
|
Transform::from_translation(position),
|
||||||
|
&field,
|
||||||
|
GrabbableSettings {
|
||||||
|
max_distance: 0.05,
|
||||||
|
zoneable: false,
|
||||||
|
..Default::default()
|
||||||
|
},
|
||||||
|
)?;
|
||||||
|
if !state.unfurled {
|
||||||
|
grabbable.set_enabled(false)?;
|
||||||
|
}
|
||||||
|
grabbable.content_parent().set_spatial_parent(parent)?;
|
||||||
|
field.set_spatial_parent(grabbable.content_parent())?;
|
||||||
|
let icon = icon
|
||||||
|
.map(|i| model_from_icon(grabbable.content_parent(), &i))
|
||||||
|
.unwrap_or_else(|| {
|
||||||
|
Ok(Model::create(
|
||||||
|
grabbable.content_parent(),
|
||||||
|
Transform::from_rotation_scale(
|
||||||
|
Quat::from_rotation_x(PI / 2.0) * Quat::from_rotation_y(PI),
|
||||||
|
[APP_SIZE * 0.5; 3],
|
||||||
|
),
|
||||||
|
&ResourceID::new_namespaced("protostar", "hexagon/hexagon"),
|
||||||
|
)?)
|
||||||
|
})?;
|
||||||
|
if !state.unfurled {
|
||||||
|
icon.set_enabled(false)?;
|
||||||
|
}
|
||||||
|
|
||||||
|
let label_style = TextStyle {
|
||||||
|
character_height: APP_SIZE * 2.0,
|
||||||
|
bounds: Some(TextBounds {
|
||||||
|
bounds: [1.0; 2].into(),
|
||||||
|
fit: TextFit::Wrap,
|
||||||
|
anchor_align_x: XAlign::Center,
|
||||||
|
anchor_align_y: YAlign::Center,
|
||||||
|
}),
|
||||||
|
|
||||||
|
text_align_x: XAlign::Center,
|
||||||
|
text_align_y: YAlign::Center,
|
||||||
|
..Default::default()
|
||||||
|
};
|
||||||
|
let label = application.name().and_then(|name| {
|
||||||
|
Text::create(
|
||||||
|
&icon,
|
||||||
|
Transform::from_translation_rotation(
|
||||||
|
[0.0, 0.1, -(APP_SIZE * 4.0)],
|
||||||
|
Quat::from_rotation_x(PI * 0.5),
|
||||||
|
),
|
||||||
|
name,
|
||||||
|
label_style,
|
||||||
|
)
|
||||||
|
.ok()
|
||||||
|
});
|
||||||
|
if !state.unfurled {
|
||||||
|
if let Some(label) = label.as_ref() {
|
||||||
|
label.set_enabled(false)?;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(App {
|
||||||
|
parent: parent.clone(),
|
||||||
|
position,
|
||||||
|
grabbable,
|
||||||
|
_field: field,
|
||||||
|
// field_lines,
|
||||||
|
label,
|
||||||
|
application,
|
||||||
|
icon,
|
||||||
|
grabbable_shrink: None,
|
||||||
|
grabbable_grow: None,
|
||||||
|
grabbable_move: None,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
pub fn content_parent(&self) -> &Spatial {
|
||||||
|
self.grabbable.content_parent()
|
||||||
|
}
|
||||||
|
pub fn apply_state(&mut self, state: &State) {
|
||||||
|
self.grabbable.set_enabled(state.unfurled).unwrap();
|
||||||
|
if state.unfurled {
|
||||||
|
self.icon.set_enabled(true).unwrap();
|
||||||
|
if let Some(label) = self.label.as_ref() {
|
||||||
|
label.set_enabled(true).unwrap()
|
||||||
|
}
|
||||||
|
self.grabbable_move = Some(Tweener::quart_in_out(0.0001, 1.0, 0.25));
|
||||||
|
} else {
|
||||||
|
self.grabbable_move = Some(Tweener::quart_in_out(1.0, 0.0001, 0.25)); //TODO make the scale a parameter
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn frame(&mut self, info: &FrameInfo, state: &State) {
|
||||||
|
if self.grabbable.handle_events() {
|
||||||
|
self.grabbable.frame(info);
|
||||||
|
}
|
||||||
|
|
||||||
|
if let Some(grabbable_move) = &mut self.grabbable_move {
|
||||||
|
if !grabbable_move.is_finished() {
|
||||||
|
let scale = grabbable_move.move_by(info.delta.into());
|
||||||
|
self.grabbable
|
||||||
|
.content_parent()
|
||||||
|
.set_relative_transform(
|
||||||
|
&self.parent,
|
||||||
|
Transform::from_translation(Vec3::from(self.position) * scale),
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
} else {
|
||||||
|
if grabbable_move.final_value() == 0.0001 {
|
||||||
|
self.icon.set_enabled(false).unwrap();
|
||||||
|
if let Some(label) = self.label.as_ref() {
|
||||||
|
label.set_enabled(false).unwrap()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
self.grabbable_move = None;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if let Some(grabbable_shrink) = &mut self.grabbable_shrink {
|
||||||
|
if !grabbable_shrink.is_finished() {
|
||||||
|
let scale = grabbable_shrink.move_by(info.delta.into());
|
||||||
|
self.grabbable
|
||||||
|
.content_parent()
|
||||||
|
.set_relative_transform(&self.parent, Transform::from_scale([scale; 3]))
|
||||||
|
.unwrap();
|
||||||
|
} else {
|
||||||
|
self.grabbable
|
||||||
|
.content_parent()
|
||||||
|
.set_spatial_parent(&self.parent)
|
||||||
|
.unwrap();
|
||||||
|
if state.unfurled {
|
||||||
|
self.grabbable_grow = Some(Tweener::quart_in_out(0.0001, 1.0, 0.25));
|
||||||
|
self.grabbable.cancel_angular_velocity();
|
||||||
|
self.grabbable.cancel_linear_velocity();
|
||||||
|
}
|
||||||
|
self.grabbable_shrink = None;
|
||||||
|
self.grabbable
|
||||||
|
.content_parent()
|
||||||
|
.set_relative_transform(
|
||||||
|
&self.parent,
|
||||||
|
Transform::from_translation(self.position),
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
self.grabbable
|
||||||
|
.content_parent()
|
||||||
|
.set_relative_transform(&self.parent, Transform::from_rotation(Quat::default()))
|
||||||
|
.unwrap();
|
||||||
|
self.icon
|
||||||
|
.set_local_transform(Transform::from_rotation(
|
||||||
|
Quat::from_rotation_x(PI / 2.0) * Quat::from_rotation_y(PI),
|
||||||
|
))
|
||||||
|
.unwrap();
|
||||||
|
}
|
||||||
|
} else if let Some(grabbable_grow) = &mut self.grabbable_grow {
|
||||||
|
if !grabbable_grow.is_finished() {
|
||||||
|
let scale = grabbable_grow.move_by(info.delta.into());
|
||||||
|
self.grabbable
|
||||||
|
.content_parent()
|
||||||
|
.set_relative_transform(&self.parent, Transform::from_scale([scale; 3]))
|
||||||
|
.unwrap();
|
||||||
|
} else {
|
||||||
|
self.grabbable
|
||||||
|
.content_parent()
|
||||||
|
.set_spatial_parent(&self.parent)
|
||||||
|
.unwrap();
|
||||||
|
self.grabbable_grow = None;
|
||||||
|
}
|
||||||
|
} else if self.grabbable.grab_action().actor_stopped() {
|
||||||
|
self.grabbable_shrink = Some(Tweener::quart_in_out(APP_SIZE * 0.5, 0.0001, 0.25));
|
||||||
|
|
||||||
|
let application = self.application.clone();
|
||||||
|
let space = self.content_parent().clone();
|
||||||
|
let parent = self.parent.clone();
|
||||||
|
|
||||||
|
//TODO: split the executable string for the args
|
||||||
|
tokio::task::spawn(async move {
|
||||||
|
let distance_vector = space
|
||||||
|
.get_transform(&parent)
|
||||||
|
.await
|
||||||
|
.unwrap()
|
||||||
|
.translation
|
||||||
|
.unwrap();
|
||||||
|
let distance = Vec3::from(distance_vector).length_squared();
|
||||||
|
|
||||||
|
if distance > ACTIVATION_DISTANCE {
|
||||||
|
let client = space.node().client().unwrap();
|
||||||
|
let space_rot = space
|
||||||
|
.get_transform(client.get_root())
|
||||||
|
.await
|
||||||
|
.unwrap()
|
||||||
|
.rotation
|
||||||
|
.unwrap();
|
||||||
|
let (_, y_rot, _) = Quat::from(space_rot).to_euler(EulerRot::XYZ);
|
||||||
|
let _ = space.set_relative_transform(
|
||||||
|
client.get_root(),
|
||||||
|
Transform::from_rotation_scale(Quat::from_rotation_y(y_rot), [1.0; 3]),
|
||||||
|
);
|
||||||
|
let _ = application.launch(&space);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,8 +1,7 @@
|
|||||||
#![allow(dead_code)]
|
|
||||||
|
|
||||||
use std::ops::Add;
|
use std::ops::Add;
|
||||||
|
|
||||||
use single::{APP_SIZE, PADDING};
|
use crate::{APP_SIZE, PADDING};
|
||||||
|
use tween::TweenTime;
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug, Default)]
|
#[derive(Clone, Copy, Debug, Default)]
|
||||||
pub struct Hex {
|
pub struct Hex {
|
||||||
@@ -27,9 +26,9 @@ impl Hex {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_coords(&self) -> [f32; 3] {
|
pub fn get_coords(&self) -> [f32; 3] {
|
||||||
let x = 3.0 / 2.0 * (APP_SIZE + PADDING) / 2.0 * (-self.q - self.s) as f32;
|
let x = 3.0 / 2.0 * (APP_SIZE + PADDING) / 2.0 * (-self.q - self.s).to_f32();
|
||||||
let y = 3.0_f32.sqrt() * (APP_SIZE + PADDING) / 2.0
|
let y = 3.0_f32.sqrt() * (APP_SIZE + PADDING) / 2.0
|
||||||
* ((-self.q - self.s) as f32 / 2.0 + self.s as f32);
|
* ((-self.q - self.s).to_f32() / 2.0 + self.s.to_f32());
|
||||||
[x, y, 0.0]
|
[x, y, 0.0]
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -40,42 +39,6 @@ impl Hex {
|
|||||||
pub fn scale(self, factor: isize) -> Self {
|
pub fn scale(self, factor: isize) -> Self {
|
||||||
Hex::new(self.q * factor, self.r * factor, self.s * factor)
|
Hex::new(self.q * factor, self.r * factor, self.s * factor)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// outputs a hexagon at an outward spiral at position i, where i=0 is the center.
|
|
||||||
pub fn spiral(i: usize) -> Self {
|
|
||||||
if i == 0 {
|
|
||||||
return HEX_CENTER;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Find which ring we're in and position within ring
|
|
||||||
let mut cells_before = 1; // Count center
|
|
||||||
let mut radius = 1;
|
|
||||||
|
|
||||||
while cells_before + (radius * 6) <= i {
|
|
||||||
cells_before += radius * 6;
|
|
||||||
radius += 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Calculate steps needed within current ring
|
|
||||||
let pos_in_ring = i - cells_before;
|
|
||||||
|
|
||||||
// Start at top of ring (same as original code)
|
|
||||||
let mut hex = HEX_CENTER + HEX_DIRECTION_VECTORS[4].scale(radius as isize);
|
|
||||||
|
|
||||||
// Walk around sides just like original code
|
|
||||||
let mut steps_taken = 0;
|
|
||||||
for side in 0..6 {
|
|
||||||
for _ in 0..radius {
|
|
||||||
if steps_taken == pos_in_ring {
|
|
||||||
return hex;
|
|
||||||
}
|
|
||||||
hex = hex.neighbor(side);
|
|
||||||
steps_taken += 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
hex
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
impl Add for Hex {
|
impl Add for Hex {
|
||||||
type Output = Hex;
|
type Output = Hex;
|
||||||
|
|||||||
@@ -1,149 +1,245 @@
|
|||||||
mod hex;
|
pub mod app;
|
||||||
|
pub mod hex;
|
||||||
|
|
||||||
|
use app::App;
|
||||||
|
use color_eyre::eyre::Result;
|
||||||
use glam::Quat;
|
use glam::Quat;
|
||||||
use hex::Hex;
|
use hex::{HEX_CENTER, HEX_DIRECTION_VECTORS};
|
||||||
use mint::{Quaternion, Vector3};
|
use protostar::xdg::{DesktopFile, get_desktop_files, parse_desktop_file};
|
||||||
use protostar::xdg::{DesktopFile, get_desktop_files};
|
|
||||||
use rayon::iter::{IntoParallelRefIterator, ParallelIterator};
|
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use single::{APP_SIZE, App, BTN_COLOR, BTN_SELECTED_COLOR, MODEL_SCALE};
|
|
||||||
use stardust_xr_asteroids::{
|
|
||||||
ClientState, CustomElement, Element, Migrate, Reify, Transformable, client,
|
|
||||||
elements::{Button, Grabbable, Model, ModelPart, PointerMode, Spatial},
|
|
||||||
};
|
|
||||||
use stardust_xr_fusion::{
|
use stardust_xr_fusion::{
|
||||||
drawable::MaterialParameter,
|
ClientHandle,
|
||||||
fields::{CylinderShape, Shape},
|
client::Client,
|
||||||
|
core::values::{
|
||||||
|
ResourceID,
|
||||||
|
color::{Rgba, color_space::LinearRgb, rgba_linear},
|
||||||
|
},
|
||||||
|
drawable::{MaterialParameter, Model, ModelPartAspect},
|
||||||
|
node::NodeError,
|
||||||
project_local_resources,
|
project_local_resources,
|
||||||
spatial::Transform,
|
root::{ClientState, FrameInfo, RootAspect, RootEvent},
|
||||||
|
spatial::{Spatial, SpatialAspect, Transform},
|
||||||
};
|
};
|
||||||
use std::f32::consts::{FRAC_PI_2, PI};
|
use stardust_xr_molecules::{
|
||||||
use tracing_subscriber::{EnvFilter, Layer, layer::SubscriberExt, util::SubscriberInitExt};
|
FrameSensitive, Grabbable, GrabbableSettings, PointerMode, UIElement,
|
||||||
|
button::{Button, ButtonSettings},
|
||||||
|
};
|
||||||
|
use std::{f32::consts::PI, sync::Arc, time::Duration};
|
||||||
|
|
||||||
|
const APP_SIZE: f32 = 0.06;
|
||||||
|
const PADDING: f32 = 0.005;
|
||||||
|
const MODEL_SCALE: f32 = 0.03;
|
||||||
|
const ACTIVATION_DISTANCE: f32 = 0.05;
|
||||||
|
|
||||||
|
const DEFAULT_HEX_COLOR: Rgba<f32, LinearRgb> = rgba_linear!(0.211, 0.937, 0.588, 1.0);
|
||||||
|
const BTN_SELECTED_COLOR: Rgba<f32, LinearRgb> = rgba_linear!(0.0, 1.0, 0.0, 1.0);
|
||||||
|
const BTN_COLOR: Rgba<f32, LinearRgb> = rgba_linear!(1.0, 1.0, 0.0, 1.0);
|
||||||
|
|
||||||
#[tokio::main(flavor = "current_thread")]
|
#[tokio::main(flavor = "current_thread")]
|
||||||
async fn main() {
|
async fn main() -> Result<()> {
|
||||||
color_eyre::install().unwrap();
|
color_eyre::install().unwrap();
|
||||||
|
tracing_subscriber::fmt()
|
||||||
let registry = tracing_subscriber::registry();
|
.with_env_filter(tracing_subscriber::EnvFilter::from_default_env())
|
||||||
#[cfg(feature = "tracy")]
|
.pretty()
|
||||||
let registry = registry.with({
|
.init();
|
||||||
use tracing_subscriber::Layer;
|
let owned_client = Client::connect().await?;
|
||||||
tracing_tracy::TracyLayer::new(tracing_tracy::DefaultConfig::default())
|
owned_client.setup_resources(&[&project_local_resources!("../res")])?;
|
||||||
.with_filter(tracing::level_filters::LevelFilter::DEBUG)
|
let client = owned_client.handle();
|
||||||
|
let async_loop = owned_client.async_event_loop();
|
||||||
|
let mut grid = AppHexGrid::new(&client).await;
|
||||||
|
let mut owned_client = async_loop.stop().await.unwrap();
|
||||||
|
let event_loop = owned_client.sync_event_loop(|handle, _| {
|
||||||
|
let Some(event) = handle.get_root().recv_root_event() else {
|
||||||
|
return;
|
||||||
|
};
|
||||||
|
match event {
|
||||||
|
RootEvent::Ping { response } => response.send(Ok(())),
|
||||||
|
RootEvent::Frame { info } => {
|
||||||
|
grid.frame(info);
|
||||||
|
}
|
||||||
|
RootEvent::SaveState { response } => {
|
||||||
|
response.send(grid.save_state());
|
||||||
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
let log_layer = tracing_subscriber::fmt::Layer::new()
|
|
||||||
.with_thread_names(true)
|
|
||||||
.with_ansi(true)
|
|
||||||
.with_line_number(true)
|
|
||||||
.with_filter(EnvFilter::from_default_env());
|
|
||||||
registry.with(log_layer).init();
|
|
||||||
|
|
||||||
client::run::<HexagonLauncher>(&[&project_local_resources!("../res")]).await
|
tokio::select! {
|
||||||
|
_ = tokio::signal::ctrl_c() => (),
|
||||||
|
e = event_loop => e?,
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize)]
|
#[derive(Debug, Default, Clone, Serialize, Deserialize)]
|
||||||
pub struct HexagonLauncher {
|
pub struct State {
|
||||||
/// if the hexagon launcher is expanded
|
unfurled: bool,
|
||||||
open: bool,
|
}
|
||||||
pos: Vector3<f32>,
|
|
||||||
rot: Quaternion<f32>,
|
struct AppHexGrid {
|
||||||
#[serde(skip)]
|
movable_root: Spatial,
|
||||||
/// position in the vector is mapped to hex coordinates
|
|
||||||
apps: Vec<App>,
|
apps: Vec<App>,
|
||||||
|
button: CenterButton,
|
||||||
|
state: State,
|
||||||
}
|
}
|
||||||
|
impl AppHexGrid {
|
||||||
|
async fn new(client: &Arc<ClientHandle>) -> Self {
|
||||||
|
let client_state = client.get_root().get_state().await.unwrap();
|
||||||
|
let state = client_state.data().unwrap_or_default();
|
||||||
|
|
||||||
impl Default for HexagonLauncher {
|
let movable_root =
|
||||||
fn default() -> Self {
|
Spatial::create(client.get_root(), Transform::identity(), false).unwrap();
|
||||||
Self {
|
|
||||||
open: false,
|
let button = CenterButton::new(client, &client_state).unwrap();
|
||||||
pos: [0.0; 3].into(),
|
tokio::time::sleep(Duration::from_millis(10)).await; // give it a bit of time to send the messages properly
|
||||||
rot: Quat::IDENTITY.into(),
|
|
||||||
apps: Vec::new(),
|
let mut desktop_files: Vec<DesktopFile> = get_desktop_files()
|
||||||
|
.filter_map(|d| parse_desktop_file(d).ok())
|
||||||
|
.filter(|d| !d.no_display)
|
||||||
|
.collect();
|
||||||
|
|
||||||
|
desktop_files.sort_by_key(|d| d.clone().name.unwrap_or_default());
|
||||||
|
|
||||||
|
let mut apps = Vec::new();
|
||||||
|
let mut radius = 1;
|
||||||
|
while !desktop_files.is_empty() {
|
||||||
|
let mut hex = HEX_CENTER + HEX_DIRECTION_VECTORS[4].scale(radius);
|
||||||
|
for i in 0..6 {
|
||||||
|
if desktop_files.is_empty() {
|
||||||
|
break;
|
||||||
|
};
|
||||||
|
for _ in 0..radius {
|
||||||
|
if desktop_files.is_empty() {
|
||||||
|
break;
|
||||||
|
};
|
||||||
|
apps.push(
|
||||||
|
App::create_from_desktop_file(
|
||||||
|
button.grabbable.content_parent(),
|
||||||
|
hex.get_coords(),
|
||||||
|
desktop_files.pop().unwrap(),
|
||||||
|
&state,
|
||||||
|
)
|
||||||
|
.unwrap(),
|
||||||
|
);
|
||||||
|
hex = hex.neighbor(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
radius += 1;
|
||||||
|
}
|
||||||
|
AppHexGrid {
|
||||||
|
movable_root,
|
||||||
|
apps,
|
||||||
|
button,
|
||||||
|
state,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
impl Migrate for HexagonLauncher {
|
impl AppHexGrid {
|
||||||
type Old = Self;
|
fn frame(&mut self, info: FrameInfo) {
|
||||||
}
|
self.button.frame(&info);
|
||||||
|
if self.button.button.pressed() {
|
||||||
|
self.button
|
||||||
|
.model
|
||||||
|
.part("Hex")
|
||||||
|
.unwrap()
|
||||||
|
.set_material_parameter("color", MaterialParameter::Color(BTN_SELECTED_COLOR))
|
||||||
|
.unwrap();
|
||||||
|
self.state.unfurled = !self.state.unfurled;
|
||||||
|
for app in &mut self.apps {
|
||||||
|
app.apply_state(&self.state);
|
||||||
|
}
|
||||||
|
} else if self.button.button.released() {
|
||||||
|
self.button
|
||||||
|
.model
|
||||||
|
.part("Hex")
|
||||||
|
.unwrap()
|
||||||
|
.set_material_parameter("color", MaterialParameter::Color(BTN_COLOR))
|
||||||
|
.unwrap();
|
||||||
|
}
|
||||||
|
for app in &mut self.apps {
|
||||||
|
app.frame(&info, &self.state);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl ClientState for HexagonLauncher {
|
fn save_state(&mut self) -> Result<ClientState> {
|
||||||
const APP_ID: &'static str = "org.protostar.hexagon_launcher";
|
self.movable_root
|
||||||
|
.set_relative_transform(
|
||||||
fn initial_state_update(&mut self) {
|
self.button.grabbable.content_parent(),
|
||||||
// Load desktop files
|
Transform::from_translation([0.0; 3]),
|
||||||
self.apps = get_desktop_files()
|
)
|
||||||
.filter_map(|d| DesktopFile::parse(d).ok())
|
.unwrap();
|
||||||
.filter(|d| !d.no_display)
|
ClientState::new(
|
||||||
.filter_map(|d| App::new(d).ok())
|
Some(self.state.clone()),
|
||||||
.collect();
|
&self.movable_root,
|
||||||
|
[(
|
||||||
self.apps.par_iter().for_each(|app| {
|
"content_parent".to_string(),
|
||||||
app.load_icon();
|
self.button.grabbable.content_parent(),
|
||||||
});
|
)]
|
||||||
|
.into_iter()
|
||||||
// Sort by name
|
.collect(),
|
||||||
self.apps
|
)
|
||||||
.sort_by_key(|app| app.app.name().unwrap_or_default().to_string());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
impl Reify for HexagonLauncher {
|
|
||||||
#[tracing::instrument(skip_all)]
|
struct CenterButton {
|
||||||
fn reify(&self) -> impl Element<Self> {
|
button: Button,
|
||||||
// Build UI based on current state
|
grabbable: Grabbable,
|
||||||
Grabbable::new(
|
model: Model,
|
||||||
Shape::Cylinder(CylinderShape {
|
}
|
||||||
radius: APP_SIZE / 2.0,
|
impl CenterButton {
|
||||||
length: 0.01,
|
fn new(client: &Arc<ClientHandle>, state: &ClientState) -> Result<Self, NodeError> {
|
||||||
}),
|
// (APP_SIZE + PADDING) / 2.0,
|
||||||
self.pos,
|
let button = Button::create(
|
||||||
self.rot,
|
client.get_root(),
|
||||||
|state: &mut Self, pos, rot| {
|
Transform::identity(),
|
||||||
state.pos = pos;
|
[(APP_SIZE + PADDING) / 2.0; 2],
|
||||||
state.rot = rot;
|
ButtonSettings {
|
||||||
|
visuals: None,
|
||||||
|
..Default::default()
|
||||||
},
|
},
|
||||||
)
|
)?;
|
||||||
.field_transform(Transform::from_rotation(Quat::from_rotation_x(FRAC_PI_2)))
|
let grabbable = Grabbable::create(
|
||||||
.pointer_mode(PointerMode::Align)
|
client.get_root(),
|
||||||
.reparentable(true)
|
Transform::none(),
|
||||||
.build()
|
button.touch_plane().field(),
|
||||||
.child(
|
GrabbableSettings {
|
||||||
Button::new(|state: &mut HexagonLauncher| {
|
max_distance: 0.025,
|
||||||
state.open = !state.open;
|
pointer_mode: PointerMode::Align,
|
||||||
})
|
magnet: false,
|
||||||
.pos([0.0, 0.0, 0.005])
|
..Default::default()
|
||||||
.size([APP_SIZE / 2.0; 2])
|
},
|
||||||
.build(),
|
)?;
|
||||||
)
|
button
|
||||||
.child(
|
.touch_plane()
|
||||||
Model::namespaced("protostar", "hexagon/hexagon")
|
.root()
|
||||||
.transform(Transform::from_rotation_scale(
|
.set_spatial_parent(grabbable.content_parent())?;
|
||||||
Quat::from_rotation_x(PI / 2.0) * Quat::from_rotation_y(PI),
|
|
||||||
[MODEL_SCALE; 3],
|
let model = Model::create(
|
||||||
))
|
grabbable.content_parent(),
|
||||||
.part(ModelPart::new("Hex").mat_param(
|
Transform::from_rotation_scale(
|
||||||
"color",
|
Quat::from_rotation_x(PI / 2.0) * Quat::from_rotation_y(PI),
|
||||||
MaterialParameter::Color(if self.open {
|
[MODEL_SCALE; 3],
|
||||||
BTN_SELECTED_COLOR
|
),
|
||||||
} else {
|
&ResourceID::new_namespaced("protostar", "hexagon/hexagon"),
|
||||||
BTN_COLOR
|
)?;
|
||||||
}),
|
model
|
||||||
))
|
.part("Hex")?
|
||||||
.build(),
|
.set_material_parameter("color", MaterialParameter::Color(BTN_COLOR))?;
|
||||||
)
|
if let Some(content_parent) = state.spatial_anchors(client).get("content_parent") {
|
||||||
.children(
|
grabbable
|
||||||
self.open
|
.content_parent()
|
||||||
.then(|| {
|
.set_relative_transform(content_parent, Transform::identity())?;
|
||||||
self.apps.iter().enumerate().map(|(i, app)| {
|
}
|
||||||
Spatial::default()
|
Ok(CenterButton {
|
||||||
.pos(Hex::spiral(i + 1).get_coords())
|
button,
|
||||||
.build()
|
grabbable,
|
||||||
.child(app.reify_substate(move |state: &mut HexagonLauncher| {
|
model,
|
||||||
state.apps.get_mut(i)
|
})
|
||||||
}))
|
}
|
||||||
})
|
|
||||||
})
|
fn frame(&mut self, info: &FrameInfo) {
|
||||||
.into_iter()
|
if self.grabbable.handle_events() {
|
||||||
.flatten(),
|
self.grabbable.frame(info);
|
||||||
)
|
}
|
||||||
|
self.button.handle_events();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ lazy_static = "1.4.0"
|
|||||||
linicon-theme = "1.2.0"
|
linicon-theme = "1.2.0"
|
||||||
manifest-dir-macros = "0.1.16"
|
manifest-dir-macros = "0.1.16"
|
||||||
mint = "0.5.9"
|
mint = "0.5.9"
|
||||||
nix = { version = "0.27.1", features = ["process"] }
|
nix = "0.27.1"
|
||||||
regex = "1.7.1"
|
regex = "1.7.1"
|
||||||
resvg = "0.29.0"
|
resvg = "0.29.0"
|
||||||
rustc-hash = "1.1.0"
|
rustc-hash = "1.1.0"
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
use crate::xdg::{DesktopFile, Icon, IconType};
|
use crate::xdg::{DesktopFile, Icon, IconType};
|
||||||
use nix::{libc::setsid, unistd::ForkResult};
|
use nix::libc::setsid;
|
||||||
use regex::Regex;
|
use regex::Regex;
|
||||||
use serde::{Deserialize, Serialize};
|
|
||||||
use stardust_xr_fusion::{
|
use stardust_xr_fusion::{
|
||||||
node::{NodeError, NodeResult},
|
node::{NodeError, NodeResult},
|
||||||
root::{ClientState, RootAspect},
|
root::{ClientState, RootAspect},
|
||||||
@@ -9,10 +8,10 @@ use stardust_xr_fusion::{
|
|||||||
};
|
};
|
||||||
use std::{
|
use std::{
|
||||||
os::unix::process::CommandExt,
|
os::unix::process::CommandExt,
|
||||||
process::{Command, Stdio, exit},
|
process::{Command, Stdio},
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct Application {
|
pub struct Application {
|
||||||
desktop_file: DesktopFile,
|
desktop_file: DesktopFile,
|
||||||
}
|
}
|
||||||
@@ -46,7 +45,7 @@ impl Application {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn launch<T: SpatialRefAspect + Clone>(&self, launch_space: &T) -> NodeResult<()> {
|
pub fn launch<T: SpatialRefAspect + Clone>(&self, launch_space: &T) -> NodeResult<()> {
|
||||||
let client = launch_space.client().clone();
|
let client = launch_space.node().client()?;
|
||||||
let launch_space = launch_space.clone();
|
let launch_space = launch_space.clone();
|
||||||
|
|
||||||
let executable = self
|
let executable = self
|
||||||
@@ -83,21 +82,18 @@ impl Application {
|
|||||||
let exec: std::borrow::Cow<'_, str> = re.replace_all(&executable, "");
|
let exec: std::borrow::Cow<'_, str> = re.replace_all(&executable, "");
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
if let ForkResult::Child = nix::unistd::fork().expect("fork died???? how?????") {
|
Command::new("sh")
|
||||||
let _ = Command::new("sh")
|
.arg("-c")
|
||||||
.arg("-c")
|
.arg(exec.to_string())
|
||||||
.arg(exec.to_string())
|
.stdin(Stdio::null())
|
||||||
.stdin(Stdio::null())
|
.stdout(Stdio::null())
|
||||||
.stdout(Stdio::null())
|
.stderr(Stdio::null())
|
||||||
.stderr(Stdio::null())
|
.pre_exec(|| {
|
||||||
.pre_exec(|| {
|
_ = setsid();
|
||||||
_ = setsid();
|
Ok(())
|
||||||
Ok(())
|
})
|
||||||
})
|
.spawn()
|
||||||
.spawn()
|
.expect("Failed to start child process");
|
||||||
.expect("Failed to start child process");
|
|
||||||
exit(0);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -95,11 +95,87 @@ pub fn get_desktop_files() -> impl Iterator<Item = PathBuf> {
|
|||||||
#[test]
|
#[test]
|
||||||
fn test_get_desktop_files() {
|
fn test_get_desktop_files() {
|
||||||
let desktop_files = get_desktop_files().collect::<Vec<_>>();
|
let desktop_files = get_desktop_files().collect::<Vec<_>>();
|
||||||
assert!(
|
assert!(desktop_files
|
||||||
desktop_files
|
.iter()
|
||||||
.iter()
|
.any(|file| file.ends_with("com.belmoussaoui.ashpd.demo.desktop")));
|
||||||
.any(|file| file.ends_with("com.belmoussaoui.ashpd.demo.desktop"))
|
}
|
||||||
);
|
|
||||||
|
pub fn parse_desktop_file(path: PathBuf) -> Result<DesktopFile, String> {
|
||||||
|
// Open the file in read-only mode
|
||||||
|
let file = match fs::File::open(
|
||||||
|
env::current_dir()
|
||||||
|
.map_err(|e| e.to_string())?
|
||||||
|
.join(path.clone()),
|
||||||
|
) {
|
||||||
|
Ok(file) => file,
|
||||||
|
Err(err) => return Err(format!("Failed to open file: {}", err)),
|
||||||
|
};
|
||||||
|
|
||||||
|
let reader = BufReader::new(file);
|
||||||
|
|
||||||
|
// Create temporary variables to hold the parsed values
|
||||||
|
let mut name = None;
|
||||||
|
let mut command = None;
|
||||||
|
let mut categories = Vec::new();
|
||||||
|
let mut icon = None;
|
||||||
|
let mut no_display = false;
|
||||||
|
let mut desktop_entry_found = false;
|
||||||
|
|
||||||
|
let re = Regex::new(r"^\[([^\]]*)\]$").unwrap();
|
||||||
|
|
||||||
|
// Loop through each line of the file
|
||||||
|
for line in reader.lines() {
|
||||||
|
let line = match line {
|
||||||
|
Ok(line) => line,
|
||||||
|
Err(err) => return Err(format!("Failed to read line: {}", err)),
|
||||||
|
};
|
||||||
|
|
||||||
|
// Skip empty lines and lines that start with "#" (comments)
|
||||||
|
if line.is_empty() || line.starts_with('#') {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if let Some(captures) = re.captures(&line) {
|
||||||
|
let entry = captures.get(1).unwrap();
|
||||||
|
desktop_entry_found = entry.as_str().contains("Desktop Entry");
|
||||||
|
}
|
||||||
|
|
||||||
|
if !desktop_entry_found {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
// Split the line into a key-value pair by looking for the first "=" character
|
||||||
|
let parts = line.split_once('=');
|
||||||
|
let (key, value) = match parts {
|
||||||
|
Some((key, value)) => (key, value),
|
||||||
|
None => continue,
|
||||||
|
};
|
||||||
|
|
||||||
|
// Parse the key-value pair based on the key
|
||||||
|
match key {
|
||||||
|
"Name" => name = Some(value.to_string()),
|
||||||
|
"Exec" => command = Some(value.to_string()),
|
||||||
|
"Categories" => {
|
||||||
|
categories = value
|
||||||
|
.split(';')
|
||||||
|
.map(|s| s.to_string())
|
||||||
|
.filter(|s| !s.is_empty())
|
||||||
|
.collect()
|
||||||
|
}
|
||||||
|
"Icon" => icon = Some(value.to_string()),
|
||||||
|
"NoDisplay" => no_display = value == "true",
|
||||||
|
_ => (), // Ignore unknown keys
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create and return a new DesktopFile instance with the parsed values
|
||||||
|
Ok(DesktopFile {
|
||||||
|
path,
|
||||||
|
name,
|
||||||
|
command,
|
||||||
|
categories,
|
||||||
|
icon,
|
||||||
|
no_display,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@@ -111,7 +187,7 @@ fn test_parse_desktop_file() {
|
|||||||
fs::write(&file, data).unwrap();
|
fs::write(&file, data).unwrap();
|
||||||
|
|
||||||
// Parse the test desktop file
|
// Parse the test desktop file
|
||||||
let desktop_file = DesktopFile::parse(file).unwrap();
|
let desktop_file = parse_desktop_file(file).unwrap();
|
||||||
|
|
||||||
// Check the parsed values
|
// Check the parsed values
|
||||||
assert_eq!(desktop_file.name, Some("Test".to_string()));
|
assert_eq!(desktop_file.name, Some("Test".to_string()));
|
||||||
@@ -122,8 +198,8 @@ fn test_parse_desktop_file() {
|
|||||||
);
|
);
|
||||||
assert_eq!(desktop_file.icon, Some("test.png".to_string()));
|
assert_eq!(desktop_file.icon, Some("test.png".to_string()));
|
||||||
}
|
}
|
||||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
|
||||||
#[serde(into = "PathBuf", from = "PathBuf")]
|
#[derive(Debug, Clone)]
|
||||||
pub struct DesktopFile {
|
pub struct DesktopFile {
|
||||||
path: PathBuf,
|
path: PathBuf,
|
||||||
pub name: Option<String>,
|
pub name: Option<String>,
|
||||||
@@ -133,97 +209,6 @@ pub struct DesktopFile {
|
|||||||
pub no_display: bool,
|
pub no_display: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<DesktopFile> for PathBuf {
|
|
||||||
fn from(df: DesktopFile) -> Self {
|
|
||||||
df.path
|
|
||||||
}
|
|
||||||
}
|
|
||||||
impl From<PathBuf> for DesktopFile {
|
|
||||||
fn from(path: PathBuf) -> Self {
|
|
||||||
Self::parse(path).unwrap()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl DesktopFile {
|
|
||||||
pub fn parse(path: PathBuf) -> Result<Self, String> {
|
|
||||||
// Open the file in read-only mode
|
|
||||||
let file = match fs::File::open(
|
|
||||||
env::current_dir()
|
|
||||||
.map_err(|e| e.to_string())?
|
|
||||||
.join(path.clone()),
|
|
||||||
) {
|
|
||||||
Ok(file) => file,
|
|
||||||
Err(err) => return Err(format!("Failed to open file: {err}")),
|
|
||||||
};
|
|
||||||
|
|
||||||
let reader = BufReader::new(file);
|
|
||||||
|
|
||||||
// Create temporary variables to hold the parsed values
|
|
||||||
let mut name = None;
|
|
||||||
let mut command = None;
|
|
||||||
let mut categories = Vec::new();
|
|
||||||
let mut icon = None;
|
|
||||||
let mut no_display = false;
|
|
||||||
let mut desktop_entry_found = false;
|
|
||||||
|
|
||||||
let re = Regex::new(r"^\[([^\]]*)\]$").unwrap();
|
|
||||||
|
|
||||||
// Loop through each line of the file
|
|
||||||
for line in reader.lines() {
|
|
||||||
let line = match line {
|
|
||||||
Ok(line) => line,
|
|
||||||
Err(err) => return Err(format!("Failed to read line: {err}")),
|
|
||||||
};
|
|
||||||
|
|
||||||
// Skip empty lines and lines that start with "#" (comments)
|
|
||||||
if line.is_empty() || line.starts_with('#') {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if let Some(captures) = re.captures(&line) {
|
|
||||||
let entry = captures.get(1).unwrap();
|
|
||||||
desktop_entry_found = entry.as_str().contains("Desktop Entry");
|
|
||||||
}
|
|
||||||
|
|
||||||
if !desktop_entry_found {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
// Split the line into a key-value pair by looking for the first "=" character
|
|
||||||
let parts = line.split_once('=');
|
|
||||||
let (key, value) = match parts {
|
|
||||||
Some((key, value)) => (key, value),
|
|
||||||
None => continue,
|
|
||||||
};
|
|
||||||
|
|
||||||
// Parse the key-value pair based on the key
|
|
||||||
match key {
|
|
||||||
"Name" => name = Some(value.to_string()),
|
|
||||||
"Exec" => command = Some(value.to_string()),
|
|
||||||
"Categories" => {
|
|
||||||
categories = value
|
|
||||||
.split(';')
|
|
||||||
.map(|s| s.to_string())
|
|
||||||
.filter(|s| !s.is_empty())
|
|
||||||
.collect()
|
|
||||||
}
|
|
||||||
"Icon" => icon = Some(value.to_string()),
|
|
||||||
"NoDisplay" => no_display = value == "true",
|
|
||||||
_ => (), // Ignore unknown keys
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create and return a new DesktopFile instance with the parsed values
|
|
||||||
Ok(DesktopFile {
|
|
||||||
path,
|
|
||||||
name,
|
|
||||||
command,
|
|
||||||
categories,
|
|
||||||
icon,
|
|
||||||
no_display,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const ICON_SIZES: [u16; 7] = [512, 256, 128, 64, 48, 32, 24];
|
const ICON_SIZES: [u16; 7] = [512, 256, 128, 64, 48, 32, 24];
|
||||||
|
|
||||||
impl DesktopFile {
|
impl DesktopFile {
|
||||||
|
|||||||
@@ -2,7 +2,6 @@
|
|||||||
name = "single"
|
name = "single"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
edition = "2024"
|
edition = "2024"
|
||||||
rust-version = "1.88"
|
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
protostar = { path = "../protostar" }
|
protostar = { path = "../protostar" }
|
||||||
@@ -11,11 +10,7 @@ clap = "4.4.6"
|
|||||||
manifest-dir-macros = "0.1.18"
|
manifest-dir-macros = "0.1.18"
|
||||||
glam = "0.24.2"
|
glam = "0.24.2"
|
||||||
tween = "2.0.1"
|
tween = "2.0.1"
|
||||||
mint = "0.5.9"
|
|
||||||
tracing = "0.1.41"
|
|
||||||
tracing-subscriber = "0.3.17"
|
tracing-subscriber = "0.3.17"
|
||||||
tokio = { workspace = true }
|
tokio = { workspace = true }
|
||||||
serde = { workspace = true }
|
|
||||||
stardust-xr-fusion = { workspace = true }
|
stardust-xr-fusion = { workspace = true }
|
||||||
stardust-xr-molecules = { workspace = true }
|
stardust-xr-molecules = { workspace = true }
|
||||||
stardust-xr-asteroids = { workspace = true }
|
|
||||||
|
|||||||
@@ -1,163 +0,0 @@
|
|||||||
use glam::{Quat, Vec3};
|
|
||||||
use mint::{Quaternion, Vector3};
|
|
||||||
use protostar::application::Application;
|
|
||||||
use protostar::xdg::{DesktopFile, Icon, IconType};
|
|
||||||
use serde::{Deserialize, Serialize};
|
|
||||||
use stardust_xr_asteroids::elements::{
|
|
||||||
Grabbable, Lines, Model, ModelPart, PointerMode, Text, line_from_points,
|
|
||||||
};
|
|
||||||
use stardust_xr_asteroids::{CustomElement, Element, Reify, Transformable};
|
|
||||||
use stardust_xr_fusion::drawable::{TextBounds, TextFit};
|
|
||||||
use stardust_xr_fusion::node::NodeError;
|
|
||||||
use stardust_xr_fusion::values::ResourceID;
|
|
||||||
use stardust_xr_fusion::{
|
|
||||||
drawable::{MaterialParameter, XAlign, YAlign},
|
|
||||||
fields::{CylinderShape, Shape},
|
|
||||||
spatial::Transform,
|
|
||||||
};
|
|
||||||
use std::f32::consts::{FRAC_PI_2, PI};
|
|
||||||
use std::sync::OnceLock;
|
|
||||||
use std::sync::atomic::{AtomicBool, Ordering};
|
|
||||||
|
|
||||||
use crate::app_launcher::AppLauncher;
|
|
||||||
use crate::{ACTIVATION_DISTANCE, APP_SIZE, DEFAULT_HEX_COLOR, MODEL_SCALE};
|
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize)]
|
|
||||||
pub struct App {
|
|
||||||
pub app: Application,
|
|
||||||
#[serde(skip)]
|
|
||||||
icon: OnceLock<Icon>,
|
|
||||||
pos: Vector3<f32>,
|
|
||||||
rot: Quaternion<f32>,
|
|
||||||
#[serde(skip)]
|
|
||||||
launched: AtomicBool,
|
|
||||||
}
|
|
||||||
impl App {
|
|
||||||
pub fn new(desktop_entry: DesktopFile) -> Result<Self, NodeError> {
|
|
||||||
let app = Application::create(desktop_entry)?;
|
|
||||||
Ok(App {
|
|
||||||
app,
|
|
||||||
icon: OnceLock::default(),
|
|
||||||
pos: [0.0; 3].into(),
|
|
||||||
rot: Quat::IDENTITY.into(),
|
|
||||||
launched: AtomicBool::new(false),
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn load_icon(&self) {
|
|
||||||
if self.icon.get().is_none()
|
|
||||||
&& let Some(icon) = self
|
|
||||||
.app
|
|
||||||
.icon(64, true)
|
|
||||||
.and_then(|i| i.cached_process(64).ok())
|
|
||||||
{
|
|
||||||
let _ = self.icon.set(icon);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Helper functions for creating app components
|
|
||||||
fn create_model(&self) -> impl Element<Self> {
|
|
||||||
match self.icon.get().as_ref().map(|i| (i.icon_type.clone(), i)) {
|
|
||||||
Some((IconType::Gltf, icon)) => Model::direct(icon.path.clone())
|
|
||||||
.unwrap()
|
|
||||||
.transform(Transform::from_rotation_scale(
|
|
||||||
Quat::from_rotation_x(PI / 2.0) * Quat::from_rotation_y(PI),
|
|
||||||
[MODEL_SCALE; 3],
|
|
||||||
))
|
|
||||||
.build(),
|
|
||||||
other => {
|
|
||||||
let model = Model::namespaced("protostar", "hexagon/hexagon")
|
|
||||||
.transform(Transform::from_rotation_scale(
|
|
||||||
Quat::from_rotation_x(PI / 2.0) * Quat::from_rotation_y(PI),
|
|
||||||
[APP_SIZE / 2.0; 3],
|
|
||||||
))
|
|
||||||
.part(
|
|
||||||
ModelPart::new("Hex")
|
|
||||||
.mat_param("color", MaterialParameter::Color(DEFAULT_HEX_COLOR)),
|
|
||||||
);
|
|
||||||
|
|
||||||
match other {
|
|
||||||
Some((IconType::Png, icon)) => model.part(ModelPart::new("Icon").mat_param(
|
|
||||||
"diffuse",
|
|
||||||
MaterialParameter::Texture(ResourceID::Direct(icon.path.clone())),
|
|
||||||
)),
|
|
||||||
_ => model,
|
|
||||||
}
|
|
||||||
.build()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
impl Reify for App {
|
|
||||||
#[tracing::instrument(skip_all)]
|
|
||||||
fn reify(&self) -> impl Element<Self> {
|
|
||||||
// The field shape for the grabbable
|
|
||||||
let field_shape = Shape::Cylinder(CylinderShape {
|
|
||||||
radius: APP_SIZE / 2.0,
|
|
||||||
length: 0.01,
|
|
||||||
});
|
|
||||||
|
|
||||||
let converted = Vec3::from(self.pos);
|
|
||||||
let length = converted.length();
|
|
||||||
let direction = converted.normalize_or_zero();
|
|
||||||
|
|
||||||
Lines::new([line_from_points(vec![
|
|
||||||
Vec3::from([0.0; 3]),
|
|
||||||
(length < ACTIVATION_DISTANCE) as u32 as f32
|
|
||||||
* direction * length.clamp(0.0, ACTIVATION_DISTANCE),
|
|
||||||
])])
|
|
||||||
.build()
|
|
||||||
.child(
|
|
||||||
Grabbable::new(
|
|
||||||
field_shape,
|
|
||||||
self.pos,
|
|
||||||
self.rot,
|
|
||||||
move |state: &mut Self, pos, rot| {
|
|
||||||
state.pos = pos;
|
|
||||||
state.rot = rot;
|
|
||||||
},
|
|
||||||
)
|
|
||||||
.grab_stop({
|
|
||||||
move |state: &mut Self| {
|
|
||||||
let pos_vec = Vec3::from(state.pos);
|
|
||||||
if pos_vec.length() > ACTIVATION_DISTANCE {
|
|
||||||
// state.app.launch(launch_space)
|
|
||||||
state.launched.store(true, Ordering::Relaxed);
|
|
||||||
} else {
|
|
||||||
state.pos = [0.0; 3].into();
|
|
||||||
state.rot = Quat::IDENTITY.into();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.field_transform(Transform::from_rotation(Quat::from_rotation_x(FRAC_PI_2)))
|
|
||||||
.pointer_mode(PointerMode::Align)
|
|
||||||
.max_distance(0.05)
|
|
||||||
.reparentable(false)
|
|
||||||
.build()
|
|
||||||
.child(self.create_model())
|
|
||||||
.children(self.launched.load(Ordering::Relaxed).then(|| {
|
|
||||||
AppLauncher::new(&self.app)
|
|
||||||
.done(|state: &mut Self| {
|
|
||||||
state.launched.store(false, Ordering::Relaxed);
|
|
||||||
state.pos = [0.0; 3].into();
|
|
||||||
state.rot = Quat::IDENTITY.into();
|
|
||||||
})
|
|
||||||
.build()
|
|
||||||
}))
|
|
||||||
.child(
|
|
||||||
Text::new(self.app.name().unwrap_or_default())
|
|
||||||
.character_height(0.005)
|
|
||||||
.bounds(TextBounds {
|
|
||||||
bounds: [0.04, 0.04].into(),
|
|
||||||
fit: TextFit::Wrap,
|
|
||||||
anchor_align_x: XAlign::Center,
|
|
||||||
anchor_align_y: YAlign::Bottom,
|
|
||||||
})
|
|
||||||
.align_x(XAlign::Center)
|
|
||||||
.align_y(YAlign::Bottom)
|
|
||||||
.pos([0.0, -APP_SIZE * 0.35, 0.002])
|
|
||||||
.build(),
|
|
||||||
),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,64 +0,0 @@
|
|||||||
use protostar::application::Application;
|
|
||||||
use stardust_xr_asteroids::{Context, CustomElement, ValidState};
|
|
||||||
use stardust_xr_fusion::{
|
|
||||||
node::{NodeError, NodeType},
|
|
||||||
root::FrameInfo,
|
|
||||||
spatial::{Spatial, SpatialAspect, SpatialRef, Transform},
|
|
||||||
};
|
|
||||||
use std::fmt::Debug;
|
|
||||||
|
|
||||||
pub struct AppLauncher<State: ValidState>(Application, Box<dyn Fn(&mut State) + Send + Sync>);
|
|
||||||
impl<State: ValidState> AppLauncher<State> {
|
|
||||||
pub fn new(app: &Application) -> Self {
|
|
||||||
AppLauncher(app.clone(), Box::new(|_| {}))
|
|
||||||
}
|
|
||||||
pub fn done<F: Fn(&mut State) + Send + Sync + 'static>(mut self, f: F) -> Self {
|
|
||||||
self.1 = Box::new(f);
|
|
||||||
self
|
|
||||||
}
|
|
||||||
}
|
|
||||||
impl<State: ValidState> CustomElement<State> for AppLauncher<State> {
|
|
||||||
type Inner = (Spatial, bool);
|
|
||||||
type Resource = ();
|
|
||||||
type Error = NodeError;
|
|
||||||
|
|
||||||
fn create_inner(
|
|
||||||
&self,
|
|
||||||
_asteroids_context: &stardust_xr_asteroids::Context,
|
|
||||||
info: stardust_xr_asteroids::CreateInnerInfo,
|
|
||||||
_resource: &mut Self::Resource,
|
|
||||||
) -> Result<Self::Inner, Self::Error> {
|
|
||||||
let spatial = Spatial::create(
|
|
||||||
info.parent_space.client().get_root(),
|
|
||||||
Transform::identity(),
|
|
||||||
false,
|
|
||||||
)?;
|
|
||||||
spatial.set_relative_transform(info.parent_space, Transform::from_translation([0.0; 3]))?;
|
|
||||||
Ok((spatial, false))
|
|
||||||
}
|
|
||||||
|
|
||||||
fn diff(&self, _old_self: &Self, _inner: &mut Self::Inner, _resource: &mut Self::Resource) {}
|
|
||||||
|
|
||||||
fn frame(
|
|
||||||
&self,
|
|
||||||
_context: &Context,
|
|
||||||
_info: &FrameInfo,
|
|
||||||
state: &mut State,
|
|
||||||
inner: &mut Self::Inner,
|
|
||||||
) {
|
|
||||||
if !inner.1 {
|
|
||||||
let _ = self.0.launch(&inner.0);
|
|
||||||
(self.1)(state);
|
|
||||||
inner.1 = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn spatial_aspect(&self, inner: &Self::Inner) -> SpatialRef {
|
|
||||||
inner.0.clone().as_spatial_ref()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
impl<State: ValidState> Debug for AppLauncher<State> {
|
|
||||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
|
||||||
f.debug_tuple("ImperativeSpatial").finish()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,15 +0,0 @@
|
|||||||
mod app;
|
|
||||||
mod app_launcher;
|
|
||||||
|
|
||||||
pub use app::App;
|
|
||||||
use stardust_xr_fusion::values::color::{Rgba, color_space::LinearRgb, rgba_linear};
|
|
||||||
|
|
||||||
// Constants from original implementation
|
|
||||||
pub const APP_SIZE: f32 = 0.06;
|
|
||||||
pub const PADDING: f32 = 0.005;
|
|
||||||
pub const MODEL_SCALE: f32 = 0.03;
|
|
||||||
pub const ACTIVATION_DISTANCE: f32 = 0.05;
|
|
||||||
|
|
||||||
pub const DEFAULT_HEX_COLOR: Rgba<f32, LinearRgb> = rgba_linear!(0.211, 0.937, 0.588, 1.0);
|
|
||||||
pub const BTN_SELECTED_COLOR: Rgba<f32, LinearRgb> = rgba_linear!(0.0, 1.0, 0.0, 1.0);
|
|
||||||
pub const BTN_COLOR: Rgba<f32, LinearRgb> = rgba_linear!(1.0, 1.0, 0.0, 1.0);
|
|
||||||
@@ -1,12 +1,15 @@
|
|||||||
use stardust_xr_asteroids::{ClientState, CustomElement, Element, Migrate, Reify, client, elements::Spatial};
|
mod single;
|
||||||
|
|
||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
use protostar::xdg::DesktopFile;
|
use color_eyre::{eyre::Result, Report};
|
||||||
use serde::{Deserialize, Serialize};
|
use manifest_dir_macros::directory_relative_path;
|
||||||
use single::App;
|
use protostar::xdg::parse_desktop_file;
|
||||||
use stardust_xr_fusion::project_local_resources;
|
use stardust_xr_fusion::{client::Client, root::RootAspect};
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use tracing_subscriber::EnvFilter;
|
use tracing_subscriber::EnvFilter;
|
||||||
|
|
||||||
|
use crate::single::Single;
|
||||||
|
|
||||||
#[derive(Debug, Parser)]
|
#[derive(Debug, Parser)]
|
||||||
#[clap(author, version, about, long_about = None)]
|
#[clap(author, version, about, long_about = None)]
|
||||||
struct Args {
|
struct Args {
|
||||||
@@ -15,39 +18,45 @@ struct Args {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[tokio::main(flavor = "current_thread")]
|
#[tokio::main(flavor = "current_thread")]
|
||||||
async fn main() {
|
async fn main() -> Result<()> {
|
||||||
tracing_subscriber::fmt()
|
tracing_subscriber::fmt()
|
||||||
.compact()
|
.compact()
|
||||||
.with_env_filter(EnvFilter::from_env("LOG_LEVEL"))
|
.with_env_filter(EnvFilter::from_env("LOG_LEVEL"))
|
||||||
.init();
|
.init();
|
||||||
client::run::<Single>(&[&project_local_resources!("../res")]).await
|
color_eyre::install()?;
|
||||||
}
|
let args = Args::parse();
|
||||||
|
let owned_client = Client::connect().await?;
|
||||||
|
let client = owned_client.handle();
|
||||||
|
let async_loop = owned_client.async_event_loop();
|
||||||
|
client
|
||||||
|
.get_root()
|
||||||
|
.set_base_prefixes(&[directory_relative_path!("../res").to_string()])?;
|
||||||
|
|
||||||
#[derive(Default, Debug, Serialize, Deserialize)]
|
let mut protostar = Single::create_from_desktop_file(
|
||||||
pub struct Single {
|
client.get_root(),
|
||||||
app: Option<App>,
|
[0.0, 0.0, 0.0],
|
||||||
}
|
parse_desktop_file(args.desktop_file).map_err(Report::msg)?,
|
||||||
impl Migrate for Single {
|
)?;
|
||||||
type Old = Self;
|
|
||||||
}
|
|
||||||
impl ClientState for Single {
|
|
||||||
const APP_ID: &'static str = "org.stardustxr.protostar.single";
|
|
||||||
|
|
||||||
fn initial_state_update(&mut self) {
|
let mut owned_client = async_loop.stop().await.unwrap();
|
||||||
let desktop_file_path = Args::parse().desktop_file;
|
let event_loop = owned_client.sync_event_loop(|handle, _| {
|
||||||
|
let Some(event) = handle.get_root().recv_root_event() else {
|
||||||
|
return;
|
||||||
|
};
|
||||||
|
match event {
|
||||||
|
stardust_xr_fusion::root::RootEvent::Ping { response } => response.send(Ok(())),
|
||||||
|
stardust_xr_fusion::root::RootEvent::Frame { info } => {
|
||||||
|
protostar.frame(info);
|
||||||
|
}
|
||||||
|
stardust_xr_fusion::root::RootEvent::SaveState { response } => {
|
||||||
|
response.send(protostar.save_state());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
let app = App::new(DesktopFile::parse(desktop_file_path).unwrap()).unwrap();
|
tokio::select! {
|
||||||
app.load_icon();
|
_ = tokio::signal::ctrl_c() => (),
|
||||||
self.app.replace(app);
|
e = event_loop => e?,
|
||||||
}
|
};
|
||||||
}
|
Ok(())
|
||||||
impl Reify for Single {
|
|
||||||
#[tracing::instrument(skip_all)]
|
|
||||||
fn reify(&self) -> impl Element<Self> {
|
|
||||||
Spatial::default().build().maybe_child(
|
|
||||||
self.app
|
|
||||||
.as_ref()
|
|
||||||
.map(|app| app.reify_substate(|state: &mut Self| state.app.as_mut())),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
252
single/src/single.rs
Normal file
252
single/src/single.rs
Normal file
@@ -0,0 +1,252 @@
|
|||||||
|
use color_eyre::eyre::Result;
|
||||||
|
use glam::{Quat, Vec3};
|
||||||
|
use protostar::{
|
||||||
|
application::Application,
|
||||||
|
xdg::{DesktopFile, Icon, IconType},
|
||||||
|
};
|
||||||
|
use stardust_xr_fusion::{
|
||||||
|
core::values::{color::rgba_linear, ResourceID, Vector3},
|
||||||
|
drawable::{
|
||||||
|
MaterialParameter, Model, ModelPartAspect, Text, TextBounds, TextFit, TextStyle, XAlign,
|
||||||
|
YAlign,
|
||||||
|
},
|
||||||
|
fields::{Field, Shape},
|
||||||
|
node::NodeType,
|
||||||
|
root::{ClientState, FrameInfo},
|
||||||
|
spatial::{Spatial, SpatialAspect, SpatialRefAspect, Transform},
|
||||||
|
};
|
||||||
|
use stardust_xr_molecules::{FrameSensitive, Grabbable, GrabbableSettings, UIElement};
|
||||||
|
use std::f32::consts::PI;
|
||||||
|
use tween::{QuartInOut, Tweener};
|
||||||
|
|
||||||
|
const MODEL_SCALE: f32 = 0.05;
|
||||||
|
const ACTIVATION_DISTANCE: f32 = 0.5;
|
||||||
|
|
||||||
|
fn model_from_icon(parent: &Spatial, icon: &Icon) -> Result<Model> {
|
||||||
|
match &icon.icon_type {
|
||||||
|
IconType::Png => {
|
||||||
|
let t = Transform::from_rotation_scale(
|
||||||
|
Quat::from_rotation_x(PI / 2.0) * Quat::from_rotation_y(PI),
|
||||||
|
[MODEL_SCALE; 3],
|
||||||
|
);
|
||||||
|
|
||||||
|
let model = Model::create(
|
||||||
|
parent,
|
||||||
|
t,
|
||||||
|
&ResourceID::new_namespaced("protostar", "hexagon/hexagon"),
|
||||||
|
)?;
|
||||||
|
model.part("Hex")?.set_material_parameter(
|
||||||
|
"color",
|
||||||
|
MaterialParameter::Color(rgba_linear!(0.0, 1.0, 1.0, 1.0)),
|
||||||
|
)?;
|
||||||
|
model.part("Icon")?.set_material_parameter(
|
||||||
|
"diffuse",
|
||||||
|
MaterialParameter::Texture(ResourceID::Direct(icon.path.clone())),
|
||||||
|
)?;
|
||||||
|
Ok(model)
|
||||||
|
}
|
||||||
|
IconType::Gltf => Ok(Model::create(
|
||||||
|
parent,
|
||||||
|
Transform::from_scale([0.05; 3]),
|
||||||
|
&ResourceID::new_direct(icon.path.clone())?,
|
||||||
|
)?),
|
||||||
|
_ => panic!("Invalid Icon Type"),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct Single {
|
||||||
|
application: Application,
|
||||||
|
root: Spatial,
|
||||||
|
position: Vector3<f32>,
|
||||||
|
grabbable: Grabbable,
|
||||||
|
_field: Field,
|
||||||
|
icon: Model,
|
||||||
|
label: Option<Text>,
|
||||||
|
grabbable_shrink: Option<Tweener<f32, f64, QuartInOut>>,
|
||||||
|
grabbable_grow: Option<Tweener<f32, f64, QuartInOut>>,
|
||||||
|
grabbable_move: Option<Tweener<f32, f64, QuartInOut>>,
|
||||||
|
currently_shown: bool,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Single {
|
||||||
|
pub fn create_from_desktop_file(
|
||||||
|
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 = 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(
|
||||||
|
&root,
|
||||||
|
Transform::from_translation(position),
|
||||||
|
&field,
|
||||||
|
GrabbableSettings {
|
||||||
|
max_distance: 0.01,
|
||||||
|
..Default::default()
|
||||||
|
},
|
||||||
|
)?;
|
||||||
|
grabbable.content_parent().set_spatial_parent(&root)?;
|
||||||
|
field.set_spatial_parent(grabbable.content_parent())?;
|
||||||
|
let icon = icon
|
||||||
|
.map(|i| model_from_icon(grabbable.content_parent(), &i))
|
||||||
|
.unwrap_or_else(|| {
|
||||||
|
Ok(Model::create(
|
||||||
|
grabbable.content_parent(),
|
||||||
|
Transform::from_scale([MODEL_SCALE; 3]),
|
||||||
|
&ResourceID::new_namespaced("protostar", "default_icon"),
|
||||||
|
)?)
|
||||||
|
})?;
|
||||||
|
|
||||||
|
let label_style = TextStyle {
|
||||||
|
character_height: MODEL_SCALE * 4.0,
|
||||||
|
bounds: Some(TextBounds {
|
||||||
|
bounds: [1.0; 2].into(),
|
||||||
|
fit: TextFit::Wrap,
|
||||||
|
anchor_align_x: XAlign::Center,
|
||||||
|
anchor_align_y: YAlign::Center,
|
||||||
|
}),
|
||||||
|
text_align_x: XAlign::Center,
|
||||||
|
text_align_y: YAlign::Center,
|
||||||
|
..Default::default()
|
||||||
|
};
|
||||||
|
let label = application.name().and_then(|name| {
|
||||||
|
Text::create(
|
||||||
|
&icon,
|
||||||
|
Transform::from_translation_rotation(
|
||||||
|
[0.0, 0.1, -(MODEL_SCALE * 8.0)],
|
||||||
|
Quat::from_rotation_x(PI * 0.5),
|
||||||
|
),
|
||||||
|
name,
|
||||||
|
label_style,
|
||||||
|
)
|
||||||
|
.ok()
|
||||||
|
});
|
||||||
|
Ok(Single {
|
||||||
|
root,
|
||||||
|
position,
|
||||||
|
grabbable,
|
||||||
|
_field: field,
|
||||||
|
label,
|
||||||
|
application,
|
||||||
|
icon,
|
||||||
|
grabbable_shrink: None,
|
||||||
|
grabbable_grow: None,
|
||||||
|
grabbable_move: None,
|
||||||
|
currently_shown: true,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
pub fn content_parent(&self) -> &Spatial {
|
||||||
|
self.grabbable.content_parent()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
impl Single {
|
||||||
|
pub fn frame(&mut self, info: FrameInfo) {
|
||||||
|
if self.grabbable.handle_events() {
|
||||||
|
self.grabbable.frame(&info);
|
||||||
|
}
|
||||||
|
|
||||||
|
if let Some(grabbable_move) = &mut self.grabbable_move {
|
||||||
|
if !grabbable_move.is_finished() {
|
||||||
|
let scale = grabbable_move.move_by(info.delta.into());
|
||||||
|
self.grabbable
|
||||||
|
.content_parent()
|
||||||
|
.set_relative_transform(
|
||||||
|
&self.root,
|
||||||
|
Transform::from_translation([
|
||||||
|
self.position.x * scale,
|
||||||
|
self.position.y * scale,
|
||||||
|
self.position.z * scale,
|
||||||
|
]),
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
} else {
|
||||||
|
if grabbable_move.final_value() == 0.0001 {
|
||||||
|
self.icon.set_enabled(false).unwrap();
|
||||||
|
if let Some(label) = self.label.as_ref() {
|
||||||
|
label.set_enabled(false).unwrap()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
self.grabbable_move = None;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if let Some(grabbable_shrink) = &mut self.grabbable_shrink {
|
||||||
|
if !grabbable_shrink.is_finished() {
|
||||||
|
let scale = grabbable_shrink.move_by(info.delta.into());
|
||||||
|
self.grabbable
|
||||||
|
.content_parent()
|
||||||
|
.set_relative_transform(&self.root, Transform::from_scale([scale; 3]))
|
||||||
|
.unwrap();
|
||||||
|
} else {
|
||||||
|
self.grabbable
|
||||||
|
.content_parent()
|
||||||
|
.set_spatial_parent(&self.root)
|
||||||
|
.unwrap();
|
||||||
|
if self.currently_shown {
|
||||||
|
self.grabbable_grow = Some(Tweener::quart_in_out(0.0001, 1.0, 0.25));
|
||||||
|
self.grabbable.cancel_angular_velocity();
|
||||||
|
self.grabbable.cancel_linear_velocity();
|
||||||
|
}
|
||||||
|
self.grabbable_shrink = None;
|
||||||
|
self.grabbable
|
||||||
|
.content_parent()
|
||||||
|
.set_relative_transform(&self.root, Transform::from_translation(self.position))
|
||||||
|
.unwrap();
|
||||||
|
self.grabbable
|
||||||
|
.content_parent()
|
||||||
|
.set_relative_transform(&self.root, Transform::from_rotation(Quat::default()))
|
||||||
|
.unwrap();
|
||||||
|
self.icon
|
||||||
|
.set_local_transform(Transform::from_rotation(
|
||||||
|
Quat::from_rotation_x(PI / 2.0) * Quat::from_rotation_y(PI),
|
||||||
|
))
|
||||||
|
.unwrap();
|
||||||
|
}
|
||||||
|
} else if let Some(grabbable_grow) = &mut self.grabbable_grow {
|
||||||
|
if !grabbable_grow.is_finished() {
|
||||||
|
let scale = grabbable_grow.move_by(info.delta.into());
|
||||||
|
self.grabbable
|
||||||
|
.content_parent()
|
||||||
|
.set_relative_transform(&self.root, Transform::from_scale([scale; 3]))
|
||||||
|
.unwrap();
|
||||||
|
} else {
|
||||||
|
self.grabbable
|
||||||
|
.content_parent()
|
||||||
|
.set_spatial_parent(&self.root)
|
||||||
|
.unwrap();
|
||||||
|
self.grabbable_grow = None;
|
||||||
|
}
|
||||||
|
} else if self.grabbable.grab_action().actor_stopped() {
|
||||||
|
self.grabbable_shrink = Some(Tweener::quart_in_out(MODEL_SCALE, 0.0001, 0.25));
|
||||||
|
|
||||||
|
let application = self.application.clone();
|
||||||
|
let space = self.content_parent().clone();
|
||||||
|
let root = self.root.clone();
|
||||||
|
|
||||||
|
//TODO: split the executable string for the args
|
||||||
|
tokio::task::spawn(async move {
|
||||||
|
let distance_vector = space
|
||||||
|
.get_transform(&root)
|
||||||
|
.await
|
||||||
|
.unwrap()
|
||||||
|
.translation
|
||||||
|
.unwrap();
|
||||||
|
let distance = Vec3::from(distance_vector).length_squared();
|
||||||
|
|
||||||
|
if distance > ACTIVATION_DISTANCE {
|
||||||
|
let _ = application.launch(&space);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn save_state(&mut self) -> color_eyre::eyre::Result<ClientState> {
|
||||||
|
ClientState::from_root(self.content_parent())
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -3,22 +3,16 @@ name = "sirius"
|
|||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
edition = "2024"
|
edition = "2024"
|
||||||
|
|
||||||
[features]
|
|
||||||
tracy = ["dep:tracing-tracy", "stardust-xr-asteroids/tracy"]
|
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
protostar = { path = "../protostar" }
|
protostar = { path = "../protostar" }
|
||||||
color-eyre = "0.6.2"
|
color-eyre = "0.6.2"
|
||||||
clap = "4.4.6"
|
clap = "4.4.6"
|
||||||
manifest-dir-macros = "0.1.18"
|
manifest-dir-macros = "0.1.18"
|
||||||
glam = { version = "0.25.0", features = ["mint"] }
|
glam = "0.24.2"
|
||||||
mint = "0.5.9"
|
tween = "2.0.1"
|
||||||
tracing-subscriber = { version = "0.3.18", features = ["env-filter"] }
|
tracing-subscriber = "0.3.17"
|
||||||
tracing-tracy = { version = "0.11.4", optional = true }
|
walkdir = "2.4.0"
|
||||||
tokio = { workspace = true }
|
tokio = { workspace = true }
|
||||||
serde = { workspace = true }
|
serde = { workspace = true }
|
||||||
stardust-xr-fusion = { workspace = true }
|
stardust-xr-fusion = { workspace = true }
|
||||||
stardust-xr-asteroids = { workspace = true }
|
stardust-xr-molecules = { workspace = true }
|
||||||
tracing = "0.1.41"
|
|
||||||
walkdir = "2.4.0"
|
|
||||||
single = { path = "../single" }
|
|
||||||
|
|||||||
@@ -1,40 +1,35 @@
|
|||||||
use clap::Parser;
|
use clap::{self, Parser};
|
||||||
use glam::Quat;
|
use color_eyre::eyre::Result;
|
||||||
use mint::{Quaternion, Vector3};
|
use glam::{Quat, Vec3};
|
||||||
use protostar::xdg::DesktopFile;
|
use manifest_dir_macros::directory_relative_path;
|
||||||
|
use protostar::{
|
||||||
|
application::Application,
|
||||||
|
xdg::{parse_desktop_file, DesktopFile, Icon, IconType},
|
||||||
|
};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use single::{App, BTN_COLOR, BTN_SELECTED_COLOR};
|
|
||||||
use stardust_xr_asteroids::{
|
|
||||||
ClientState, CustomElement, Element, Migrate, Reify, Transformable, client,
|
|
||||||
elements::{Button, Grabbable, Model, ModelPart, PointerMode, Spatial},
|
|
||||||
};
|
|
||||||
use stardust_xr_fusion::{
|
use stardust_xr_fusion::{
|
||||||
drawable::MaterialParameter, fields::Shape, project_local_resources, spatial::Transform,
|
client::Client,
|
||||||
|
core::values::{color::rgba_linear, ResourceID, Vector3},
|
||||||
|
drawable::{
|
||||||
|
MaterialParameter, Model, ModelPartAspect, Text, TextBounds, TextFit, TextStyle, XAlign,
|
||||||
|
YAlign,
|
||||||
|
},
|
||||||
|
fields::{Field, Shape},
|
||||||
|
node::{NodeError, NodeType},
|
||||||
|
root::{ClientState, FrameInfo, RootAspect},
|
||||||
|
spatial::{Spatial, SpatialAspect, SpatialRefAspect, Transform}, ClientHandle,
|
||||||
};
|
};
|
||||||
use std::path::PathBuf;
|
use stardust_xr_molecules::{
|
||||||
use tracing_subscriber::{EnvFilter, Layer, layer::SubscriberExt, util::SubscriberInitExt};
|
button::{Button, ButtonSettings},
|
||||||
|
FrameSensitive, Grabbable, GrabbableSettings, UIElement,
|
||||||
|
};
|
||||||
|
use std::{f32::consts::PI, path::PathBuf};
|
||||||
|
|
||||||
|
use tween::{QuartInOut, Tweener};
|
||||||
use walkdir::WalkDir;
|
use walkdir::WalkDir;
|
||||||
|
|
||||||
#[tokio::main(flavor = "current_thread")]
|
const APP_SIZE: f32 = 0.06;
|
||||||
async fn main() {
|
const ACTIVATION_DISTANCE: f32 = 0.5;
|
||||||
color_eyre::install().unwrap();
|
|
||||||
|
|
||||||
let registry = tracing_subscriber::registry();
|
|
||||||
#[cfg(feature = "tracy")]
|
|
||||||
let registry = registry.with({
|
|
||||||
use tracing_subscriber::Layer;
|
|
||||||
tracing_tracy::TracyLayer::new(tracing_tracy::DefaultConfig::default())
|
|
||||||
.with_filter(tracing::level_filters::LevelFilter::DEBUG)
|
|
||||||
});
|
|
||||||
let log_layer = tracing_subscriber::fmt::Layer::new()
|
|
||||||
.with_thread_names(true)
|
|
||||||
.with_ansi(true)
|
|
||||||
.with_line_number(true)
|
|
||||||
.with_filter(EnvFilter::from_default_env());
|
|
||||||
registry.with(log_layer).init();
|
|
||||||
|
|
||||||
client::run::<Sirius>(&[&project_local_resources!("../res")]).await
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Parser)]
|
#[derive(Debug, Parser)]
|
||||||
#[clap(author, version, about, long_about = None)]
|
#[clap(author, version, about, long_about = None)]
|
||||||
@@ -43,45 +38,83 @@ struct Args {
|
|||||||
apps_directory: PathBuf,
|
apps_directory: PathBuf,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize)]
|
#[tokio::main(flavor = "current_thread")]
|
||||||
pub struct Sirius {
|
async fn main() -> Result<()> {
|
||||||
visible: bool,
|
color_eyre::install()?;
|
||||||
pos: Vector3<f32>,
|
|
||||||
rot: Quaternion<f32>,
|
|
||||||
#[serde(skip)]
|
|
||||||
apps: Vec<App>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Default for Sirius {
|
let args = Args::parse();
|
||||||
fn default() -> Self {
|
if !args.apps_directory.is_dir() {
|
||||||
Self {
|
panic!(
|
||||||
visible: false,
|
"{} is not a direcotry",
|
||||||
pos: [0.0; 3].into(),
|
args.apps_directory.to_string_lossy()
|
||||||
rot: Quat::IDENTITY.into(),
|
)
|
||||||
apps: Vec::new(),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
impl Migrate for Sirius {
|
let owned_client = Client::connect().await?;
|
||||||
type Old = Self;
|
let client = owned_client.handle();
|
||||||
}
|
let async_loop = owned_client.async_event_loop();
|
||||||
|
client
|
||||||
|
.get_root()
|
||||||
|
.set_base_prefixes(&[directory_relative_path!("../res").to_string()])?;
|
||||||
|
let mut sirius = Sirius::new(&client, args)?;
|
||||||
|
|
||||||
impl ClientState for Sirius {
|
let mut owned_client = async_loop.stop().await.unwrap();
|
||||||
const APP_ID: &'static str = "org.protostar.sirius";
|
let event_loop = owned_client.sync_event_loop(|handle, _| {
|
||||||
|
let Some(event) = handle.get_root().recv_root_event() else {
|
||||||
fn initial_state_update(&mut self) {
|
return;
|
||||||
let args = Args::parse();
|
};
|
||||||
if !args.apps_directory.is_dir() {
|
match event {
|
||||||
panic!(
|
stardust_xr_fusion::root::RootEvent::Ping { response } => response.send(Ok(())),
|
||||||
"{} is not a directory",
|
stardust_xr_fusion::root::RootEvent::Frame { info } => {
|
||||||
args.apps_directory.to_string_lossy()
|
sirius.frame(info);
|
||||||
)
|
}
|
||||||
|
stardust_xr_fusion::root::RootEvent::SaveState { response } => {
|
||||||
|
response.send(sirius.save_state());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
tokio::select! {
|
||||||
|
_ = tokio::signal::ctrl_c() => (),
|
||||||
|
e = event_loop => e?,
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||||
|
struct State {
|
||||||
|
visible: bool,
|
||||||
|
}
|
||||||
|
|
||||||
|
struct Sirius {
|
||||||
|
button: Button,
|
||||||
|
model: Model,
|
||||||
|
clients: Vec<App>,
|
||||||
|
state: State,
|
||||||
|
grabbable: Grabbable,
|
||||||
|
}
|
||||||
|
impl Sirius {
|
||||||
|
fn new(client: &ClientHandle, args: Args) -> Result<Self, NodeError> {
|
||||||
|
let root = Spatial::create(client.get_root(), Transform::identity(), false).unwrap();
|
||||||
|
|
||||||
|
let field =
|
||||||
|
Field::create(&root, Transform::identity(), Shape::Box([0.1; 3].into())).unwrap();
|
||||||
|
let grabbable = Grabbable::create(
|
||||||
|
&root,
|
||||||
|
Transform::identity(),
|
||||||
|
&field,
|
||||||
|
GrabbableSettings::default(),
|
||||||
|
)?;
|
||||||
|
let button = Button::create(
|
||||||
|
grabbable.content_parent(),
|
||||||
|
Transform::identity(),
|
||||||
|
[0.1; 2],
|
||||||
|
ButtonSettings::default(),
|
||||||
|
)?;
|
||||||
|
|
||||||
let walkdir = WalkDir::new(args.apps_directory.canonicalize().unwrap());
|
let walkdir = WalkDir::new(args.apps_directory.canonicalize().unwrap());
|
||||||
|
|
||||||
self.apps = walkdir
|
let clients: Vec<App> = walkdir
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.filter_map(|path| path.ok())
|
.filter_map(|path| path.ok())
|
||||||
.map(|entry| entry.into_path())
|
.map(|entry| entry.into_path())
|
||||||
@@ -90,62 +123,369 @@ impl ClientState for Sirius {
|
|||||||
&& path.extension().is_some()
|
&& path.extension().is_some()
|
||||||
&& path.extension().unwrap() == "desktop"
|
&& path.extension().unwrap() == "desktop"
|
||||||
})
|
})
|
||||||
.filter_map(|path| App::new(DesktopFile::parse(path).ok()?).ok())
|
.filter_map(|path| {
|
||||||
.collect();
|
App::create_from_desktop_file(
|
||||||
}
|
grabbable.content_parent(),
|
||||||
}
|
[0.0; 3],
|
||||||
impl Reify for Sirius {
|
parse_desktop_file(path).ok()?,
|
||||||
fn reify(&self) -> impl Element<Self> {
|
)
|
||||||
Grabbable::new(
|
.ok()
|
||||||
Shape::Box([0.1; 3].into()),
|
|
||||||
self.pos,
|
|
||||||
self.rot,
|
|
||||||
|state: &mut Self, pos, rot| {
|
|
||||||
state.pos = pos;
|
|
||||||
state.rot = rot;
|
|
||||||
},
|
|
||||||
)
|
|
||||||
.pointer_mode(PointerMode::Align)
|
|
||||||
.reparentable(true)
|
|
||||||
.build()
|
|
||||||
.child(
|
|
||||||
Button::new(|state: &mut Sirius| {
|
|
||||||
state.visible = !state.visible;
|
|
||||||
})
|
})
|
||||||
.pos([0.0, 0.0, 0.005])
|
.collect();
|
||||||
.size([0.1; 2])
|
|
||||||
.build(),
|
let model = Model::create(
|
||||||
)
|
grabbable.content_parent(),
|
||||||
.child(
|
Transform::identity(),
|
||||||
Model::namespaced("protostar", "button")
|
&ResourceID::new_namespaced("protostar", "button"),
|
||||||
.transform(Transform::identity())
|
)?;
|
||||||
.part(ModelPart::new("?????").mat_param(
|
field.set_spatial_parent(grabbable.content_parent())?;
|
||||||
"color",
|
let state = State { visible: false };
|
||||||
MaterialParameter::Color(if self.visible {
|
|
||||||
BTN_SELECTED_COLOR
|
Ok(Sirius {
|
||||||
} else {
|
button,
|
||||||
BTN_COLOR
|
model,
|
||||||
}),
|
clients,
|
||||||
))
|
state,
|
||||||
.build(),
|
grabbable,
|
||||||
)
|
})
|
||||||
.children(
|
}
|
||||||
self.visible
|
|
||||||
.then(|| {
|
// fn left_hand(input_data: &InputData, _: &()) -> bool {
|
||||||
self.apps.iter().enumerate().map(|(pos, app)| {
|
// match &input_data.input {
|
||||||
|
// InputDataType::Hand(h) => !h.right,
|
||||||
|
// _ => false,
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
impl Sirius {
|
||||||
|
fn frame(&mut self, info: FrameInfo) {
|
||||||
|
for app in &mut self.clients {
|
||||||
|
app.frame(&info);
|
||||||
|
}
|
||||||
|
|
||||||
|
if self.grabbable.handle_events() {
|
||||||
|
self.grabbable.frame(&info);
|
||||||
|
};
|
||||||
|
if self.button.handle_events() && self.button.pressed() {
|
||||||
|
println!("Touch started");
|
||||||
|
self.state.visible = !self.state.visible;
|
||||||
|
match self.state.visible {
|
||||||
|
true => {
|
||||||
|
for (pos, star) in self.clients.iter().enumerate() {
|
||||||
let mut starpos = (pos as f32 + 1.0) / 10.0;
|
let mut starpos = (pos as f32 + 1.0) / 10.0;
|
||||||
match starpos % 0.2 == 0.0 {
|
match starpos % 0.2 == 0.0 {
|
||||||
true => starpos = -starpos / 2.0,
|
true => starpos = -starpos / 2.0,
|
||||||
false => starpos = (starpos - 0.1) / 2.0,
|
false => starpos = (starpos - 0.1) / 2.0,
|
||||||
}
|
}
|
||||||
|
println!("{}", starpos);
|
||||||
|
star.content_parent()
|
||||||
|
.set_relative_transform(
|
||||||
|
self.grabbable.content_parent(),
|
||||||
|
Transform::from_translation([starpos, 0.1, 0.0]),
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
false => {
|
||||||
|
for star in &self.clients {
|
||||||
|
star.content_parent()
|
||||||
|
.set_relative_transform(
|
||||||
|
self.grabbable.content_parent(),
|
||||||
|
Transform::from_translation([0.0; 3]),
|
||||||
|
)
|
||||||
|
.ok();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
self.model
|
||||||
|
.part("?????")
|
||||||
|
.unwrap()
|
||||||
|
.set_material_parameter(
|
||||||
|
"color",
|
||||||
|
MaterialParameter::Color(rgba_linear!(0.0, 1.0, 0.0, 1.0)),
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
self.model
|
||||||
|
.part("?????")
|
||||||
|
.unwrap()
|
||||||
|
.set_material_parameter(
|
||||||
|
"emission_factor",
|
||||||
|
MaterialParameter::Color(rgba_linear!(0.0, 0.75, 0.0, 0.75)),
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
Spatial::default().pos([starpos, 0.1, 0.0]).build().child(
|
if self.button.released() {
|
||||||
app.reify_substate(move |state: &mut Sirius| state.apps.get_mut(pos)),
|
println!("Touch ended");
|
||||||
)
|
self.model
|
||||||
})
|
.part("?????")
|
||||||
})
|
.unwrap()
|
||||||
.into_iter()
|
.set_material_parameter(
|
||||||
.flatten(),
|
"color",
|
||||||
|
MaterialParameter::Color(rgba_linear!(1.0, 0.0, 0.0, 1.0)),
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
self.model
|
||||||
|
.part("?????")
|
||||||
|
.unwrap()
|
||||||
|
.set_material_parameter(
|
||||||
|
"emission_factor",
|
||||||
|
MaterialParameter::Color(rgba_linear!(0.5, 0.0, 0.0, 0.5)),
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn save_state(&mut self) -> Result<ClientState> {
|
||||||
|
ClientState::new(
|
||||||
|
Some(self.state.clone()),
|
||||||
|
self.grabbable.content_parent(),
|
||||||
|
[(
|
||||||
|
"content_parent".to_string(),
|
||||||
|
self.grabbable.content_parent(),
|
||||||
|
)]
|
||||||
|
.into_iter()
|
||||||
|
.collect(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn model_from_icon(parent: &Spatial, icon: &Icon) -> Result<Model> {
|
||||||
|
match &icon.icon_type {
|
||||||
|
IconType::Png => {
|
||||||
|
let t = Transform::from_rotation_scale(
|
||||||
|
Quat::from_rotation_x(PI / 2.0) * Quat::from_rotation_y(PI),
|
||||||
|
[APP_SIZE * 0.5; 3],
|
||||||
|
);
|
||||||
|
|
||||||
|
let model = Model::create(
|
||||||
|
parent,
|
||||||
|
t,
|
||||||
|
&ResourceID::new_namespaced("protostar", "hexagon/hexagon"),
|
||||||
|
)?;
|
||||||
|
model.part("Hex")?.set_material_parameter(
|
||||||
|
"color",
|
||||||
|
MaterialParameter::Color(rgba_linear!(0.0, 1.0, 1.0, 1.0)),
|
||||||
|
)?;
|
||||||
|
model.part("Icon")?.set_material_parameter(
|
||||||
|
"diffuse",
|
||||||
|
MaterialParameter::Texture(ResourceID::Direct(icon.path.clone())),
|
||||||
|
)?;
|
||||||
|
Ok(model)
|
||||||
|
}
|
||||||
|
IconType::Gltf => Ok(Model::create(
|
||||||
|
parent,
|
||||||
|
Transform::from_scale([0.05; 3]),
|
||||||
|
&ResourceID::new_direct(icon.path.clone())?,
|
||||||
|
)?),
|
||||||
|
_ => panic!("Invalid Icon Type"),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct App {
|
||||||
|
application: Application,
|
||||||
|
parent: Spatial,
|
||||||
|
position: Vector3<f32>,
|
||||||
|
grabbable: Grabbable,
|
||||||
|
_field: Field,
|
||||||
|
icon: Model,
|
||||||
|
label: Option<Text>,
|
||||||
|
grabbable_shrink: Option<Tweener<f32, f64, QuartInOut>>,
|
||||||
|
grabbable_grow: Option<Tweener<f32, f64, QuartInOut>>,
|
||||||
|
grabbable_move: Option<Tweener<f32, f64, QuartInOut>>,
|
||||||
|
currently_shown: bool,
|
||||||
|
}
|
||||||
|
impl App {
|
||||||
|
pub fn create_from_desktop_file(
|
||||||
|
parent: &Spatial,
|
||||||
|
position: impl Into<Vector3<f32>>,
|
||||||
|
desktop_file: DesktopFile,
|
||||||
|
) -> Result<Self> {
|
||||||
|
let position = position.into();
|
||||||
|
let field = Field::create(
|
||||||
|
parent,
|
||||||
|
Transform::identity(),
|
||||||
|
Shape::Box([APP_SIZE; 3].into()),
|
||||||
|
)?;
|
||||||
|
let application = Application::create(desktop_file)?;
|
||||||
|
let icon = application.icon(128, false);
|
||||||
|
let grabbable = Grabbable::create(
|
||||||
|
parent,
|
||||||
|
Transform::from_translation(position),
|
||||||
|
&field,
|
||||||
|
GrabbableSettings {
|
||||||
|
max_distance: 0.01,
|
||||||
|
zoneable: false,
|
||||||
|
..Default::default()
|
||||||
|
},
|
||||||
|
)?;
|
||||||
|
grabbable.content_parent().set_spatial_parent(parent)?;
|
||||||
|
field.set_spatial_parent(grabbable.content_parent())?;
|
||||||
|
let icon = icon
|
||||||
|
.map(|i| model_from_icon(grabbable.content_parent(), &i))
|
||||||
|
.unwrap_or_else(|| {
|
||||||
|
Ok(Model::create(
|
||||||
|
grabbable.content_parent(),
|
||||||
|
Transform::from_rotation_scale(
|
||||||
|
Quat::from_rotation_x(PI / 2.0) * Quat::from_rotation_y(PI),
|
||||||
|
[APP_SIZE * 0.5; 3],
|
||||||
|
),
|
||||||
|
&ResourceID::new_namespaced("protostar", "hexagon/hexagon"),
|
||||||
|
)?)
|
||||||
|
})?;
|
||||||
|
|
||||||
|
let label_style = TextStyle {
|
||||||
|
character_height: APP_SIZE * 2.0,
|
||||||
|
bounds: Some(TextBounds {
|
||||||
|
bounds: [1.0; 2].into(),
|
||||||
|
fit: TextFit::Wrap,
|
||||||
|
anchor_align_x: XAlign::Center,
|
||||||
|
anchor_align_y: YAlign::Center,
|
||||||
|
}),
|
||||||
|
|
||||||
|
text_align_x: XAlign::Center,
|
||||||
|
text_align_y: YAlign::Center,
|
||||||
|
..Default::default()
|
||||||
|
};
|
||||||
|
let label = application.name().and_then(|name| {
|
||||||
|
Text::create(
|
||||||
|
&icon,
|
||||||
|
Transform::from_translation_rotation(
|
||||||
|
[0.0, 0.1, -(APP_SIZE * 4.0)],
|
||||||
|
Quat::from_rotation_x(PI * 0.5),
|
||||||
|
),
|
||||||
|
name,
|
||||||
|
label_style,
|
||||||
|
)
|
||||||
|
.ok()
|
||||||
|
});
|
||||||
|
Ok(App {
|
||||||
|
parent: parent.clone(),
|
||||||
|
position,
|
||||||
|
grabbable,
|
||||||
|
_field: field,
|
||||||
|
label,
|
||||||
|
application,
|
||||||
|
icon,
|
||||||
|
grabbable_shrink: None,
|
||||||
|
grabbable_grow: None,
|
||||||
|
grabbable_move: None,
|
||||||
|
currently_shown: true,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
pub fn content_parent(&self) -> &Spatial {
|
||||||
|
self.grabbable.content_parent()
|
||||||
|
}
|
||||||
|
pub fn toggle(&mut self) {
|
||||||
|
self.grabbable.set_enabled(!self.currently_shown).unwrap();
|
||||||
|
if self.currently_shown {
|
||||||
|
self.grabbable_move = Some(Tweener::quart_in_out(1.0, 0.0001, 0.25)); //TODO make the scale a parameter
|
||||||
|
} else {
|
||||||
|
self.icon.set_enabled(true).unwrap();
|
||||||
|
if let Some(label) = self.label.as_ref() {
|
||||||
|
label.set_enabled(true).unwrap()
|
||||||
|
}
|
||||||
|
self.grabbable_move = Some(Tweener::quart_in_out(0.0001, 1.0, 0.25));
|
||||||
|
}
|
||||||
|
self.currently_shown = !self.currently_shown;
|
||||||
|
}
|
||||||
|
|
||||||
|
fn frame(&mut self, info: &FrameInfo) {
|
||||||
|
if !self.grabbable.handle_events() {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
self.grabbable.frame(info);
|
||||||
|
|
||||||
|
if let Some(grabbable_move) = &mut self.grabbable_move {
|
||||||
|
if !grabbable_move.is_finished() {
|
||||||
|
let scale = grabbable_move.move_by(info.delta.into());
|
||||||
|
self.grabbable
|
||||||
|
.content_parent()
|
||||||
|
.set_relative_transform(
|
||||||
|
&self.parent,
|
||||||
|
Transform::from_translation(Vec3::from(self.position) * scale),
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
} else {
|
||||||
|
if grabbable_move.final_value() == 0.0001 {
|
||||||
|
self.icon.set_enabled(false).unwrap();
|
||||||
|
if let Some(label) = self.label.as_ref() {
|
||||||
|
label.set_enabled(false).unwrap()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
self.grabbable_move = None;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if let Some(grabbable_shrink) = &mut self.grabbable_shrink {
|
||||||
|
if !grabbable_shrink.is_finished() {
|
||||||
|
let scale = grabbable_shrink.move_by(info.delta.into());
|
||||||
|
self.grabbable
|
||||||
|
.content_parent()
|
||||||
|
.set_relative_transform(&self.parent, Transform::from_scale([scale; 3]))
|
||||||
|
.unwrap();
|
||||||
|
} else {
|
||||||
|
self.grabbable
|
||||||
|
.content_parent()
|
||||||
|
.set_spatial_parent(&self.parent)
|
||||||
|
.unwrap();
|
||||||
|
if self.currently_shown {
|
||||||
|
self.grabbable_grow = Some(Tweener::quart_in_out(0.0001, 1.0, 0.25));
|
||||||
|
self.grabbable.cancel_angular_velocity();
|
||||||
|
self.grabbable.cancel_linear_velocity();
|
||||||
|
}
|
||||||
|
self.grabbable_shrink = None;
|
||||||
|
self.grabbable
|
||||||
|
.content_parent()
|
||||||
|
.set_relative_transform(
|
||||||
|
&self.parent,
|
||||||
|
Transform::from_translation(self.position),
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
self.grabbable
|
||||||
|
.content_parent()
|
||||||
|
.set_relative_transform(&self.parent, Transform::from_rotation(Quat::default()))
|
||||||
|
.unwrap();
|
||||||
|
self.icon
|
||||||
|
.set_local_transform(Transform::from_rotation(
|
||||||
|
Quat::from_rotation_x(PI / 2.0) * Quat::from_rotation_y(PI),
|
||||||
|
))
|
||||||
|
.unwrap();
|
||||||
|
}
|
||||||
|
} else if let Some(grabbable_grow) = &mut self.grabbable_grow {
|
||||||
|
if !grabbable_grow.is_finished() {
|
||||||
|
let scale = grabbable_grow.move_by(info.delta.into());
|
||||||
|
self.grabbable
|
||||||
|
.content_parent()
|
||||||
|
.set_relative_transform(&self.parent, Transform::from_scale([scale; 3]))
|
||||||
|
.unwrap();
|
||||||
|
} else {
|
||||||
|
self.grabbable
|
||||||
|
.content_parent()
|
||||||
|
.set_spatial_parent(&self.parent)
|
||||||
|
.unwrap();
|
||||||
|
self.grabbable_grow = None;
|
||||||
|
}
|
||||||
|
} else if self.grabbable.grab_action().actor_stopped() {
|
||||||
|
self.grabbable_shrink = Some(Tweener::quart_in_out(APP_SIZE * 0.5, 0.0001, 0.25));
|
||||||
|
|
||||||
|
let application = self.application.clone();
|
||||||
|
let space = self.content_parent().clone();
|
||||||
|
let parent = self.parent.clone();
|
||||||
|
|
||||||
|
//TODO: split the executable string for the args
|
||||||
|
tokio::task::spawn(async move {
|
||||||
|
let distance_vector = space
|
||||||
|
.get_transform(&parent)
|
||||||
|
.await
|
||||||
|
.unwrap()
|
||||||
|
.translation
|
||||||
|
.unwrap();
|
||||||
|
let distance = Vec3::from(distance_vector).length_squared();
|
||||||
|
|
||||||
|
if distance > ACTIVATION_DISTANCE {
|
||||||
|
let _ = application.launch(&space);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user