modular protostar
This commit is contained in:
34
Cargo.lock
generated
34
Cargo.lock
generated
@@ -878,15 +878,6 @@ version = "0.27.2"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "ad0a93d233ebf96623465aad4046a8d3aa4da22d4f4beba5388838c8a434bbb4"
|
checksum = "ad0a93d233ebf96623465aad4046a8d3aa4da22d4f4beba5388838c8a434bbb4"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "glam"
|
|
||||||
version = "0.22.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "12f597d56c1bd55a811a1be189459e8fad2bbc272616375602443bdfb37fa774"
|
|
||||||
dependencies = [
|
|
||||||
"mint",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "glam"
|
name = "glam"
|
||||||
version = "0.24.0"
|
version = "0.24.0"
|
||||||
@@ -1636,7 +1627,7 @@ dependencies = [
|
|||||||
"directories",
|
"directories",
|
||||||
"dirs",
|
"dirs",
|
||||||
"ez-pixmap",
|
"ez-pixmap",
|
||||||
"glam 0.24.0",
|
"glam",
|
||||||
"image",
|
"image",
|
||||||
"lazy_static",
|
"lazy_static",
|
||||||
"linicon",
|
"linicon",
|
||||||
@@ -2065,9 +2056,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "stardust-xr"
|
name = "stardust-xr"
|
||||||
version = "0.11.3"
|
version = "0.11.4"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "52ce36e7f3285a6b1391a298c01bbbb92c9f3d77967a78d1beaac21c0043d23b"
|
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"chrono",
|
"chrono",
|
||||||
"cluFlock",
|
"cluFlock",
|
||||||
@@ -2085,9 +2074,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "stardust-xr-fusion"
|
name = "stardust-xr-fusion"
|
||||||
version = "0.39.2"
|
version = "0.40.2"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "c75214564f52e031f3873963b855cbd9a8253502ef18912480e8e84ad98a30c8"
|
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"color-eyre",
|
"color-eyre",
|
||||||
"color-rs",
|
"color-rs",
|
||||||
@@ -2103,17 +2090,16 @@ dependencies = [
|
|||||||
"thiserror",
|
"thiserror",
|
||||||
"tokio",
|
"tokio",
|
||||||
"tracing",
|
"tracing",
|
||||||
"xkbcommon",
|
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "stardust-xr-molecules"
|
name = "stardust-xr-molecules"
|
||||||
version = "0.24.0"
|
version = "0.24.3"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "185291b7cf2368a9ef0deed9e5ebf2c49954e862d2747aeee96cc08a57796c1c"
|
checksum = "724a92e67765300651d165950b70ec4800d4ad6450f473882f6024d5a559ea9d"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"color-rs",
|
"color-rs",
|
||||||
"glam 0.24.0",
|
"glam",
|
||||||
"lazy_static",
|
"lazy_static",
|
||||||
"map-range",
|
"map-range",
|
||||||
"mint",
|
"mint",
|
||||||
@@ -2127,16 +2113,16 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "stardust-xr-schemas"
|
name = "stardust-xr-schemas"
|
||||||
version = "1.4.0"
|
version = "1.5.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "2bebfbddbcba7db7ce8180bb373c9ad5a7d58ff60ee213ca07562820d7e8aab0"
|
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"flatbuffers",
|
"flatbuffers",
|
||||||
"flexbuffers",
|
"flexbuffers",
|
||||||
"glam 0.22.0",
|
"glam",
|
||||||
|
"manifest-dir-macros",
|
||||||
"mint",
|
"mint",
|
||||||
"ouroboros",
|
"ouroboros",
|
||||||
"serde",
|
"serde",
|
||||||
|
"serde_repr",
|
||||||
"thiserror",
|
"thiserror",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|||||||
@@ -20,8 +20,8 @@ nix = "0.26.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"
|
||||||
stardust-xr-fusion = "0.39.2"
|
stardust-xr-fusion = "0.40.2"
|
||||||
stardust-xr-molecules = "0.24.0"
|
stardust-xr-molecules = "0.24.3"
|
||||||
tokio = { version = "1.24.1", features = ["full"] }
|
tokio = { version = "1.24.1", features = ["full"] }
|
||||||
tracing-subscriber = { version = "0.3.16", features = ["env-filter"] }
|
tracing-subscriber = { version = "0.3.16", features = ["env-filter"] }
|
||||||
tween = "2.0.0"
|
tween = "2.0.0"
|
||||||
@@ -29,4 +29,7 @@ ustr = "0.9.0"
|
|||||||
walkdir = "2.3.2"
|
walkdir = "2.3.2"
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
tempdir = "0.3.7"
|
tempdir = "0.3.7"
|
||||||
|
|
||||||
|
[patch.crates-io.stardust-xr-fusion]
|
||||||
|
path = "../../core/fusion"
|
||||||
Binary file not shown.
@@ -3,23 +3,26 @@ use glam::Quat;
|
|||||||
use manifest_dir_macros::directory_relative_path;
|
use manifest_dir_macros::directory_relative_path;
|
||||||
use mint::Vector3;
|
use mint::Vector3;
|
||||||
use protostar::{
|
use protostar::{
|
||||||
protostar::ProtoStar,
|
application::Application,
|
||||||
xdg::{get_desktop_files, parse_desktop_file, DesktopFile},
|
xdg::{get_desktop_files, parse_desktop_file, DesktopFile, Icon, IconType},
|
||||||
};
|
};
|
||||||
use stardust_xr_fusion::{
|
use stardust_xr_fusion::{
|
||||||
client::{Client, FrameInfo, RootHandler},
|
client::{Client, FrameInfo, RootHandler},
|
||||||
core::values::Transform,
|
core::values::Transform,
|
||||||
drawable::{MaterialParameter, Model, ResourceID},
|
drawable::{Alignment, Bounds, MaterialParameter, Model, ResourceID, Text, TextFit, TextStyle},
|
||||||
fields::BoxField,
|
fields::BoxField,
|
||||||
node::NodeError,
|
node::NodeError,
|
||||||
|
node::NodeType,
|
||||||
spatial::Spatial,
|
spatial::Spatial,
|
||||||
};
|
};
|
||||||
use stardust_xr_molecules::{touch_plane::TouchPlane, GrabData, Grabbable};
|
use stardust_xr_molecules::{touch_plane::TouchPlane, GrabData, Grabbable};
|
||||||
use std::f32::consts::PI;
|
use std::f32::consts::PI;
|
||||||
use tween::TweenTime;
|
use tween::TweenTime;
|
||||||
|
use tween::{QuartInOut, Tweener};
|
||||||
|
|
||||||
const APP_SIZE: f32 = 0.06;
|
const APP_SIZE: f32 = 0.06;
|
||||||
const PADDING: f32 = 0.005;
|
const PADDING: f32 = 0.005;
|
||||||
|
const ACTIVATION_DISTANCE: f32 = 0.5;
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
struct Hex {
|
struct Hex {
|
||||||
@@ -110,7 +113,7 @@ impl AppHexGrid {
|
|||||||
break;
|
break;
|
||||||
};
|
};
|
||||||
apps.push(
|
apps.push(
|
||||||
App::new(
|
App::create_from_desktop_file(
|
||||||
button.grabbable.content_parent(),
|
button.grabbable.content_parent(),
|
||||||
hex.get_coords(),
|
hex.get_coords(),
|
||||||
desktop_files.pop().unwrap(),
|
desktop_files.pop().unwrap(),
|
||||||
@@ -132,16 +135,20 @@ impl RootHandler for AppHexGrid {
|
|||||||
let color = [0.0, 1.0, 0.0, 1.0];
|
let color = [0.0, 1.0, 0.0, 1.0];
|
||||||
self.button
|
self.button
|
||||||
.model
|
.model
|
||||||
.set_material_parameter(1, "color", MaterialParameter::Color(color))
|
.model_part("Hex")
|
||||||
|
.unwrap()
|
||||||
|
.set_material_parameter("color", MaterialParameter::Color(color))
|
||||||
.unwrap();
|
.unwrap();
|
||||||
for app in &mut self.apps {
|
for app in &mut self.apps {
|
||||||
app.protostar.toggle();
|
app.toggle();
|
||||||
}
|
}
|
||||||
} else if self.button.touch_plane.touch_stopped() {
|
} else if self.button.touch_plane.touch_stopped() {
|
||||||
let color = [0.0, 0.0, 1.0, 1.0];
|
let color = [0.0, 0.0, 1.0, 1.0];
|
||||||
self.button
|
self.button
|
||||||
.model
|
.model
|
||||||
.set_material_parameter(1, "color", MaterialParameter::Color(color))
|
.model_part("Hex")
|
||||||
|
.unwrap()
|
||||||
|
.set_material_parameter("color", MaterialParameter::Color(color))
|
||||||
.unwrap();
|
.unwrap();
|
||||||
}
|
}
|
||||||
for app in &mut self.apps {
|
for app in &mut self.apps {
|
||||||
@@ -149,31 +156,6 @@ impl RootHandler for AppHexGrid {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
struct App {
|
|
||||||
_desktop_file: DesktopFile,
|
|
||||||
protostar: ProtoStar,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl App {
|
|
||||||
fn new(
|
|
||||||
parent: &Spatial,
|
|
||||||
position: impl Into<Vector3<f32>>,
|
|
||||||
desktop_file: DesktopFile,
|
|
||||||
) -> Option<Self> {
|
|
||||||
let position = position.into();
|
|
||||||
let protostar =
|
|
||||||
ProtoStar::create_from_desktop_file(parent, position, desktop_file.clone()).ok()?;
|
|
||||||
Some(App {
|
|
||||||
_desktop_file: desktop_file,
|
|
||||||
protostar,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
impl RootHandler for App {
|
|
||||||
fn frame(&mut self, info: FrameInfo) {
|
|
||||||
self.protostar.frame(info);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
struct Button {
|
struct Button {
|
||||||
touch_plane: TouchPlane,
|
touch_plane: TouchPlane,
|
||||||
@@ -210,7 +192,9 @@ impl Button {
|
|||||||
),
|
),
|
||||||
&ResourceID::new_namespaced("protostar", "hexagon/hexagon"),
|
&ResourceID::new_namespaced("protostar", "hexagon/hexagon"),
|
||||||
)?;
|
)?;
|
||||||
model.set_material_parameter(1, "color", MaterialParameter::Color([0.0, 0.0, 1.0, 1.0]))?;
|
model
|
||||||
|
.model_part("Hex")?
|
||||||
|
.set_material_parameter("color", MaterialParameter::Color([0.0, 0.0, 1.0, 1.0]))?;
|
||||||
Ok(Button {
|
Ok(Button {
|
||||||
touch_plane,
|
touch_plane,
|
||||||
grabbable,
|
grabbable,
|
||||||
@@ -230,3 +214,230 @@ impl RootHandler for Button {
|
|||||||
self.touch_plane.update();
|
self.touch_plane.update();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn model_from_icon(parent: &Spatial, icon: &Icon) -> Result<Model> {
|
||||||
|
return 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
|
||||||
|
.model_part("Hex")?
|
||||||
|
.set_material_parameter("color", MaterialParameter::Color([0.0, 1.0, 1.0, 1.0]))?;
|
||||||
|
model.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: BoxField,
|
||||||
|
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 = BoxField::create(parent, Transform::default(), [APP_SIZE; 3])?;
|
||||||
|
let application = Application::create(&parent.client()?, desktop_file)?;
|
||||||
|
let icon = application.icon(128, false);
|
||||||
|
let grabbable = Grabbable::create(
|
||||||
|
parent,
|
||||||
|
Transform::from_position(position),
|
||||||
|
&field,
|
||||||
|
GrabData {
|
||||||
|
max_distance: 0.01,
|
||||||
|
frame_cancel_threshold: 50,
|
||||||
|
..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(Bounds {
|
||||||
|
bounds: [1.0; 2].into(),
|
||||||
|
fit: TextFit::Wrap,
|
||||||
|
bounds_align: Alignment::XCenter | Alignment::YCenter,
|
||||||
|
}),
|
||||||
|
text_align: Alignment::Center.into(),
|
||||||
|
..Default::default()
|
||||||
|
};
|
||||||
|
let label = application.name().and_then(|name| {
|
||||||
|
Text::create(
|
||||||
|
&icon,
|
||||||
|
Transform::from_position_rotation(
|
||||||
|
[0.0, 0.1, -(APP_SIZE * 4.0)],
|
||||||
|
Quat::from_rotation_x(PI * 0.5),
|
||||||
|
),
|
||||||
|
name,
|
||||||
|
label_style,
|
||||||
|
)
|
||||||
|
.ok()
|
||||||
|
});
|
||||||
|
Ok(App {
|
||||||
|
parent: parent.alias(),
|
||||||
|
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();
|
||||||
|
self.label.as_ref().map(|l| l.set_enabled(true).unwrap());
|
||||||
|
self.grabbable_move = Some(Tweener::quart_in_out(0.0001, 1.0, 0.25));
|
||||||
|
}
|
||||||
|
self.currently_shown = !self.currently_shown;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
impl RootHandler for App {
|
||||||
|
fn frame(&mut self, info: FrameInfo) {
|
||||||
|
let _ = self.grabbable.update(&info);
|
||||||
|
|
||||||
|
if let Some(grabbable_move) = &mut self.grabbable_move {
|
||||||
|
if !grabbable_move.is_finished() {
|
||||||
|
let scale = grabbable_move.move_by(info.delta);
|
||||||
|
self.grabbable
|
||||||
|
.content_parent()
|
||||||
|
.set_position(
|
||||||
|
Some(&self.parent),
|
||||||
|
[
|
||||||
|
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();
|
||||||
|
self.label.as_ref().map(|l| l.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);
|
||||||
|
self.grabbable
|
||||||
|
.content_parent()
|
||||||
|
.set_scale(Some(&self.parent), Vector3::from([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_position(Some(&self.parent), self.position)
|
||||||
|
.unwrap();
|
||||||
|
self.grabbable
|
||||||
|
.content_parent()
|
||||||
|
.set_rotation(Some(&self.parent), Quat::default())
|
||||||
|
.unwrap();
|
||||||
|
self.icon
|
||||||
|
.set_rotation(
|
||||||
|
None,
|
||||||
|
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);
|
||||||
|
self.grabbable
|
||||||
|
.content_parent()
|
||||||
|
.set_scale(Some(&self.parent), Vector3::from([scale; 3]))
|
||||||
|
.unwrap();
|
||||||
|
} else {
|
||||||
|
self.grabbable
|
||||||
|
.content_parent()
|
||||||
|
.set_spatial_parent(&self.parent)
|
||||||
|
.unwrap();
|
||||||
|
self.grabbable_grow = None;
|
||||||
|
}
|
||||||
|
} else if self.grabbable.valid() && self.grabbable.grab_action().actor_stopped() {
|
||||||
|
self.grabbable_shrink = Some(Tweener::quart_in_out(APP_SIZE * 0.5, 0.0001, 0.25));
|
||||||
|
let Ok(distance_future) = self.grabbable
|
||||||
|
.content_parent()
|
||||||
|
.get_position_rotation_scale(&self.parent)
|
||||||
|
else {return};
|
||||||
|
|
||||||
|
let application = self.application.clone();
|
||||||
|
let space = self.content_parent().alias();
|
||||||
|
|
||||||
|
//TODO: split the executable string for the args
|
||||||
|
tokio::task::spawn(async move {
|
||||||
|
let distance_vector = distance_future.await.ok().unwrap().0;
|
||||||
|
let distance = ((distance_vector.x.powi(2) + distance_vector.y.powi(2)).sqrt()
|
||||||
|
+ distance_vector.z.powi(2))
|
||||||
|
.sqrt();
|
||||||
|
if dbg!(distance) > ACTIVATION_DISTANCE {
|
||||||
|
let _ = application.launch(&space);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
1665
mono_crash.0.0.json
Normal file
1665
mono_crash.0.0.json
Normal file
File diff suppressed because it is too large
Load Diff
Binary file not shown.
@@ -1,276 +1,286 @@
|
|||||||
{
|
{
|
||||||
"asset" : {
|
"asset":{
|
||||||
"generator" : "Khronos glTF Blender I/O v3.4.50",
|
"generator":"Khronos glTF Blender I/O v3.5.30",
|
||||||
"version" : "2.0"
|
"version":"2.0"
|
||||||
},
|
},
|
||||||
"extensionsUsed" : [
|
"extensionsUsed":[
|
||||||
"KHR_materials_unlit"
|
"KHR_materials_unlit"
|
||||||
],
|
],
|
||||||
"scene" : 0,
|
"scene":0,
|
||||||
"scenes" : [
|
"scenes":[
|
||||||
{
|
{
|
||||||
"name" : "Scene",
|
"name":"Scene",
|
||||||
"nodes" : [
|
"nodes":[
|
||||||
0
|
0,
|
||||||
]
|
1
|
||||||
}
|
]
|
||||||
],
|
}
|
||||||
"nodes" : [
|
],
|
||||||
{
|
"nodes":[
|
||||||
"mesh" : 0,
|
{
|
||||||
"name" : "Hex"
|
"mesh":0,
|
||||||
}
|
"name":"Icon"
|
||||||
],
|
},
|
||||||
"materials" : [
|
{
|
||||||
{
|
"mesh":1,
|
||||||
"alphaCutoff" : 0.5,
|
"name":"Hex"
|
||||||
"alphaMode" : "MASK",
|
}
|
||||||
"extensions" : {
|
],
|
||||||
"KHR_materials_unlit" : {}
|
"materials":[
|
||||||
},
|
{
|
||||||
"name" : "Icon",
|
"alphaCutoff":0.5,
|
||||||
"pbrMetallicRoughness" : {
|
"alphaMode":"MASK",
|
||||||
"baseColorTexture" : {
|
"extensions":{
|
||||||
"index" : 0,
|
"KHR_materials_unlit":{}
|
||||||
"texCoord" : 0
|
},
|
||||||
},
|
"name":"Icon",
|
||||||
"metallicFactor" : 0,
|
"pbrMetallicRoughness":{
|
||||||
"roughnessFactor" : 0.9
|
"baseColorTexture":{
|
||||||
}
|
"index":0,
|
||||||
},
|
"texCoord":0
|
||||||
{
|
},
|
||||||
"alphaMode" : "BLEND",
|
"metallicFactor":0,
|
||||||
"extensions" : {
|
"roughnessFactor":0.9
|
||||||
"KHR_materials_unlit" : {}
|
}
|
||||||
},
|
},
|
||||||
"name" : "Hex",
|
{
|
||||||
"pbrMetallicRoughness" : {
|
"alphaMode":"BLEND",
|
||||||
"baseColorFactor" : [
|
"extensions":{
|
||||||
1,
|
"KHR_materials_unlit":{}
|
||||||
0,
|
},
|
||||||
0,
|
"name":"Hex",
|
||||||
1
|
"pbrMetallicRoughness":{
|
||||||
],
|
"baseColorFactor":[
|
||||||
"baseColorTexture" : {
|
1,
|
||||||
"index" : 1,
|
0,
|
||||||
"texCoord" : 0
|
0,
|
||||||
},
|
1
|
||||||
"metallicFactor" : 0,
|
],
|
||||||
"roughnessFactor" : 0.9
|
"baseColorTexture":{
|
||||||
}
|
"index":1,
|
||||||
}
|
"texCoord":0
|
||||||
],
|
},
|
||||||
"meshes" : [
|
"metallicFactor":0,
|
||||||
{
|
"roughnessFactor":0.9
|
||||||
"name" : "Circle",
|
}
|
||||||
"primitives" : [
|
}
|
||||||
{
|
],
|
||||||
"attributes" : {
|
"meshes":[
|
||||||
"COLOR_0" : 0,
|
{
|
||||||
"POSITION" : 1,
|
"name":"Circle",
|
||||||
"TEXCOORD_0" : 2,
|
"primitives":[
|
||||||
"NORMAL" : 3
|
{
|
||||||
},
|
"attributes":{
|
||||||
"indices" : 4,
|
"COLOR_0":0,
|
||||||
"material" : 0
|
"POSITION":1,
|
||||||
},
|
"TEXCOORD_0":2,
|
||||||
{
|
"NORMAL":3
|
||||||
"attributes" : {
|
},
|
||||||
"COLOR_0" : 5,
|
"indices":4,
|
||||||
"POSITION" : 6,
|
"material":0
|
||||||
"TEXCOORD_0" : 7,
|
}
|
||||||
"NORMAL" : 8
|
]
|
||||||
},
|
},
|
||||||
"indices" : 9,
|
{
|
||||||
"material" : 1
|
"name":"Circle.001",
|
||||||
}
|
"primitives":[
|
||||||
]
|
{
|
||||||
}
|
"attributes":{
|
||||||
],
|
"COLOR_0":5,
|
||||||
"textures" : [
|
"POSITION":6,
|
||||||
{
|
"TEXCOORD_0":7,
|
||||||
"sampler" : 0,
|
"NORMAL":8
|
||||||
"source" : 0
|
},
|
||||||
},
|
"indices":9,
|
||||||
{
|
"material":1
|
||||||
"sampler" : 1,
|
}
|
||||||
"source" : 1
|
]
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"images" : [
|
"textures":[
|
||||||
{
|
{
|
||||||
"mimeType" : "image/png",
|
"sampler":0,
|
||||||
"name" : "icon_test",
|
"source":0
|
||||||
"uri" : "icon_test.png"
|
},
|
||||||
},
|
{
|
||||||
{
|
"sampler":1,
|
||||||
"mimeType" : "image/png",
|
"source":1
|
||||||
"name" : "hex_atlas",
|
}
|
||||||
"uri" : "hex_atlas.png"
|
],
|
||||||
}
|
"images":[
|
||||||
],
|
{
|
||||||
"accessors" : [
|
"mimeType":"image/png",
|
||||||
{
|
"name":"icon_test",
|
||||||
"bufferView" : 0,
|
"uri":"icon_test.png"
|
||||||
"componentType" : 5123,
|
},
|
||||||
"count" : 4,
|
{
|
||||||
"normalized" : true,
|
"mimeType":"image/png",
|
||||||
"type" : "VEC4"
|
"name":"hex_atlas",
|
||||||
},
|
"uri":"hex_atlas.png"
|
||||||
{
|
}
|
||||||
"bufferView" : 1,
|
],
|
||||||
"componentType" : 5126,
|
"accessors":[
|
||||||
"count" : 4,
|
{
|
||||||
"max" : [
|
"bufferView":0,
|
||||||
0.5853440165519714,
|
"componentType":5123,
|
||||||
0.05000000074505806,
|
"count":4,
|
||||||
0.5853440165519714
|
"normalized":true,
|
||||||
],
|
"type":"VEC4"
|
||||||
"min" : [
|
},
|
||||||
-0.5853440165519714,
|
{
|
||||||
0.05000000074505806,
|
"bufferView":1,
|
||||||
-0.5853440165519714
|
"componentType":5126,
|
||||||
],
|
"count":4,
|
||||||
"type" : "VEC3"
|
"max":[
|
||||||
},
|
0.5853440165519714,
|
||||||
{
|
0.05000000074505806,
|
||||||
"bufferView" : 2,
|
0.5853440165519714
|
||||||
"componentType" : 5126,
|
],
|
||||||
"count" : 4,
|
"min":[
|
||||||
"type" : "VEC2"
|
-0.5853440165519714,
|
||||||
},
|
0.05000000074505806,
|
||||||
{
|
-0.5853440165519714
|
||||||
"bufferView" : 3,
|
],
|
||||||
"componentType" : 5126,
|
"type":"VEC3"
|
||||||
"count" : 4,
|
},
|
||||||
"type" : "VEC3"
|
{
|
||||||
},
|
"bufferView":2,
|
||||||
{
|
"componentType":5126,
|
||||||
"bufferView" : 4,
|
"count":4,
|
||||||
"componentType" : 5123,
|
"type":"VEC2"
|
||||||
"count" : 6,
|
},
|
||||||
"type" : "SCALAR"
|
{
|
||||||
},
|
"bufferView":3,
|
||||||
{
|
"componentType":5126,
|
||||||
"bufferView" : 5,
|
"count":4,
|
||||||
"componentType" : 5123,
|
"type":"VEC3"
|
||||||
"count" : 54,
|
},
|
||||||
"normalized" : true,
|
{
|
||||||
"type" : "VEC4"
|
"bufferView":4,
|
||||||
},
|
"componentType":5123,
|
||||||
{
|
"count":6,
|
||||||
"bufferView" : 6,
|
"type":"SCALAR"
|
||||||
"componentType" : 5126,
|
},
|
||||||
"count" : 54,
|
{
|
||||||
"max" : [
|
"bufferView":5,
|
||||||
1.0441828966140747,
|
"componentType":5123,
|
||||||
0.05000000074505806,
|
"count":54,
|
||||||
0.9042890667915344
|
"normalized":true,
|
||||||
],
|
"type":"VEC4"
|
||||||
"min" : [
|
},
|
||||||
-1.0441828966140747,
|
{
|
||||||
0,
|
"bufferView":6,
|
||||||
-0.9042890667915344
|
"componentType":5126,
|
||||||
],
|
"count":54,
|
||||||
"type" : "VEC3"
|
"max":[
|
||||||
},
|
1.0441828966140747,
|
||||||
{
|
0.05000000074505806,
|
||||||
"bufferView" : 7,
|
0.9042890667915344
|
||||||
"componentType" : 5126,
|
],
|
||||||
"count" : 54,
|
"min":[
|
||||||
"type" : "VEC2"
|
-1.0441828966140747,
|
||||||
},
|
0,
|
||||||
{
|
-0.9042890667915344
|
||||||
"bufferView" : 8,
|
],
|
||||||
"componentType" : 5126,
|
"type":"VEC3"
|
||||||
"count" : 54,
|
},
|
||||||
"type" : "VEC3"
|
{
|
||||||
},
|
"bufferView":7,
|
||||||
{
|
"componentType":5126,
|
||||||
"bufferView" : 9,
|
"count":54,
|
||||||
"componentType" : 5123,
|
"type":"VEC2"
|
||||||
"count" : 84,
|
},
|
||||||
"type" : "SCALAR"
|
{
|
||||||
}
|
"bufferView":8,
|
||||||
],
|
"componentType":5126,
|
||||||
"bufferViews" : [
|
"count":54,
|
||||||
{
|
"type":"VEC3"
|
||||||
"buffer" : 0,
|
},
|
||||||
"byteLength" : 32,
|
{
|
||||||
"byteOffset" : 0,
|
"bufferView":9,
|
||||||
"target" : 34962
|
"componentType":5123,
|
||||||
},
|
"count":84,
|
||||||
{
|
"type":"SCALAR"
|
||||||
"buffer" : 0,
|
}
|
||||||
"byteLength" : 48,
|
],
|
||||||
"byteOffset" : 32,
|
"bufferViews":[
|
||||||
"target" : 34962
|
{
|
||||||
},
|
"buffer":0,
|
||||||
{
|
"byteLength":32,
|
||||||
"buffer" : 0,
|
"byteOffset":0,
|
||||||
"byteLength" : 32,
|
"target":34962
|
||||||
"byteOffset" : 80,
|
},
|
||||||
"target" : 34962
|
{
|
||||||
},
|
"buffer":0,
|
||||||
{
|
"byteLength":48,
|
||||||
"buffer" : 0,
|
"byteOffset":32,
|
||||||
"byteLength" : 48,
|
"target":34962
|
||||||
"byteOffset" : 112,
|
},
|
||||||
"target" : 34962
|
{
|
||||||
},
|
"buffer":0,
|
||||||
{
|
"byteLength":32,
|
||||||
"buffer" : 0,
|
"byteOffset":80,
|
||||||
"byteLength" : 12,
|
"target":34962
|
||||||
"byteOffset" : 160,
|
},
|
||||||
"target" : 34963
|
{
|
||||||
},
|
"buffer":0,
|
||||||
{
|
"byteLength":48,
|
||||||
"buffer" : 0,
|
"byteOffset":112,
|
||||||
"byteLength" : 432,
|
"target":34962
|
||||||
"byteOffset" : 172,
|
},
|
||||||
"target" : 34962
|
{
|
||||||
},
|
"buffer":0,
|
||||||
{
|
"byteLength":12,
|
||||||
"buffer" : 0,
|
"byteOffset":160,
|
||||||
"byteLength" : 648,
|
"target":34963
|
||||||
"byteOffset" : 604,
|
},
|
||||||
"target" : 34962
|
{
|
||||||
},
|
"buffer":0,
|
||||||
{
|
"byteLength":432,
|
||||||
"buffer" : 0,
|
"byteOffset":172,
|
||||||
"byteLength" : 432,
|
"target":34962
|
||||||
"byteOffset" : 1252,
|
},
|
||||||
"target" : 34962
|
{
|
||||||
},
|
"buffer":0,
|
||||||
{
|
"byteLength":648,
|
||||||
"buffer" : 0,
|
"byteOffset":604,
|
||||||
"byteLength" : 648,
|
"target":34962
|
||||||
"byteOffset" : 1684,
|
},
|
||||||
"target" : 34962
|
{
|
||||||
},
|
"buffer":0,
|
||||||
{
|
"byteLength":432,
|
||||||
"buffer" : 0,
|
"byteOffset":1252,
|
||||||
"byteLength" : 168,
|
"target":34962
|
||||||
"byteOffset" : 2332,
|
},
|
||||||
"target" : 34963
|
{
|
||||||
}
|
"buffer":0,
|
||||||
],
|
"byteLength":648,
|
||||||
"samplers" : [
|
"byteOffset":1684,
|
||||||
{
|
"target":34962
|
||||||
"magFilter" : 9729,
|
},
|
||||||
"minFilter" : 9987,
|
{
|
||||||
"wrapS" : 33071,
|
"buffer":0,
|
||||||
"wrapT" : 33071
|
"byteLength":168,
|
||||||
},
|
"byteOffset":2332,
|
||||||
{
|
"target":34963
|
||||||
"magFilter" : 9729,
|
}
|
||||||
"minFilter" : 9987
|
],
|
||||||
}
|
"samplers":[
|
||||||
],
|
{
|
||||||
"buffers" : [
|
"magFilter":9729,
|
||||||
{
|
"minFilter":9987,
|
||||||
"byteLength" : 2500,
|
"wrapS":33071,
|
||||||
"uri" : "hexagon.bin"
|
"wrapT":33071
|
||||||
}
|
},
|
||||||
]
|
{
|
||||||
|
"magFilter":9729,
|
||||||
|
"minFilter":9987
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"buffers":[
|
||||||
|
{
|
||||||
|
"byteLength":2500,
|
||||||
|
"uri":"hexagon.bin"
|
||||||
|
}
|
||||||
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
100
src/application.rs
Normal file
100
src/application.rs
Normal file
@@ -0,0 +1,100 @@
|
|||||||
|
use crate::xdg::{DesktopFile, Icon, IconType};
|
||||||
|
use nix::unistd::setsid;
|
||||||
|
use regex::Regex;
|
||||||
|
use stardust_xr_fusion::{
|
||||||
|
client::Client,
|
||||||
|
node::{NodeError, NodeType},
|
||||||
|
spatial::Spatial,
|
||||||
|
startup_settings::StartupSettings,
|
||||||
|
};
|
||||||
|
use std::{
|
||||||
|
os::unix::process::CommandExt,
|
||||||
|
process::{Command, Stdio},
|
||||||
|
sync::Arc,
|
||||||
|
};
|
||||||
|
|
||||||
|
#[derive(Debug, Clone)]
|
||||||
|
pub struct Application {
|
||||||
|
desktop_file: DesktopFile,
|
||||||
|
startup_settings: Arc<StartupSettings>,
|
||||||
|
}
|
||||||
|
impl Application {
|
||||||
|
pub fn create(client: &Arc<Client>, desktop_file: DesktopFile) -> Result<Self, NodeError> {
|
||||||
|
if desktop_file.no_display {
|
||||||
|
return Err(NodeError::DoesNotExist);
|
||||||
|
}
|
||||||
|
|
||||||
|
let startup_settings = Arc::new(StartupSettings::create(client)?);
|
||||||
|
Ok(Application {
|
||||||
|
desktop_file,
|
||||||
|
startup_settings,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn name(&self) -> Option<&str> {
|
||||||
|
self.desktop_file.name.as_deref()
|
||||||
|
}
|
||||||
|
pub fn categories(&self) -> &[String] {
|
||||||
|
self.desktop_file.categories.as_slice()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn icon(&self, preferred_px_size: u16, prefer_3d: bool) -> Option<Icon> {
|
||||||
|
let raw_icons = self.desktop_file.get_raw_icons(preferred_px_size);
|
||||||
|
let mut icon = raw_icons.iter().max_by_key(|i| i.size).cloned();
|
||||||
|
if prefer_3d {
|
||||||
|
icon = raw_icons
|
||||||
|
.into_iter()
|
||||||
|
.find(|i| match i.icon_type {
|
||||||
|
IconType::Gltf => true,
|
||||||
|
_ => false,
|
||||||
|
})
|
||||||
|
.or(icon);
|
||||||
|
}
|
||||||
|
|
||||||
|
icon.and_then(|i| i.cached_process(preferred_px_size).ok())
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn launch(&self, launch_space: &Spatial) -> Result<(), NodeError> {
|
||||||
|
self.startup_settings.set_root(launch_space)?;
|
||||||
|
let future_startup_token = self.startup_settings.generate_startup_token()?;
|
||||||
|
let future_connection_env = self
|
||||||
|
.startup_settings
|
||||||
|
.node()
|
||||||
|
.client()?
|
||||||
|
.get_connection_environment()?;
|
||||||
|
|
||||||
|
let executable = self
|
||||||
|
.desktop_file
|
||||||
|
.command
|
||||||
|
.clone()
|
||||||
|
.ok_or(NodeError::DoesNotExist)?;
|
||||||
|
tokio::task::spawn(async move {
|
||||||
|
let Ok(startup_token) = future_startup_token.await else {return};
|
||||||
|
let Ok(connection_env) = future_connection_env.await else {return};
|
||||||
|
|
||||||
|
for (k, v) in connection_env.into_iter() {
|
||||||
|
std::env::set_var(k, v);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::env::set_var("STARDUST_STARTUP_TOKEN", startup_token);
|
||||||
|
let re = Regex::new(r"%[fFuUdDnNickvm]").unwrap();
|
||||||
|
let exec = re.replace_all(&executable, "");
|
||||||
|
unsafe {
|
||||||
|
Command::new("sh")
|
||||||
|
.arg("-c")
|
||||||
|
.arg(exec.to_string())
|
||||||
|
.stdin(Stdio::null())
|
||||||
|
.stdout(Stdio::null())
|
||||||
|
.stderr(Stdio::null())
|
||||||
|
.pre_exec(|| {
|
||||||
|
_ = setsid();
|
||||||
|
Ok(())
|
||||||
|
})
|
||||||
|
.spawn()
|
||||||
|
.expect("Failed to start child process");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,2 +1,3 @@
|
|||||||
|
pub mod application;
|
||||||
pub mod protostar;
|
pub mod protostar;
|
||||||
pub mod xdg;
|
pub mod xdg;
|
||||||
|
|||||||
38
src/main.rs
38
src/main.rs
@@ -1,8 +1,5 @@
|
|||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
use color_eyre::{
|
use color_eyre::{eyre::Result, Report};
|
||||||
eyre::{bail, Result},
|
|
||||||
Report,
|
|
||||||
};
|
|
||||||
use manifest_dir_macros::directory_relative_path;
|
use manifest_dir_macros::directory_relative_path;
|
||||||
use protostar::{protostar::ProtoStar, xdg::parse_desktop_file};
|
use protostar::{protostar::ProtoStar, xdg::parse_desktop_file};
|
||||||
use stardust_xr_fusion::client::Client;
|
use stardust_xr_fusion::client::Client;
|
||||||
@@ -11,21 +8,8 @@ use std::path::PathBuf;
|
|||||||
#[derive(Debug, Parser)]
|
#[derive(Debug, Parser)]
|
||||||
#[clap(author, version, about, long_about = None)]
|
#[clap(author, version, about, long_about = None)]
|
||||||
struct Args {
|
struct Args {
|
||||||
#[clap(short, long, default_value_t = 0.1)]
|
// #[clap(short, long)]
|
||||||
size: f32,
|
desktop_file: PathBuf,
|
||||||
#[clap(
|
|
||||||
short,
|
|
||||||
long,
|
|
||||||
conflicts_with = "command",
|
|
||||||
required_unless_present = "command",
|
|
||||||
conflicts_with = "icon",
|
|
||||||
required_unless_present = "icon"
|
|
||||||
)]
|
|
||||||
desktop_file: Option<PathBuf>,
|
|
||||||
#[clap(short, long, conflicts_with = "desktop_file", requires = "command")]
|
|
||||||
icon: Option<PathBuf>,
|
|
||||||
#[clap(short, long, conflicts_with = "desktop_file", requires = "icon")]
|
|
||||||
command: Option<String>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tokio::main(flavor = "current_thread")]
|
#[tokio::main(flavor = "current_thread")]
|
||||||
@@ -35,17 +19,11 @@ async fn main() -> Result<()> {
|
|||||||
let (client, event_loop) = Client::connect_with_async_loop().await?;
|
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 = if let Some(desktop_file) = args.desktop_file {
|
let protostar = ProtoStar::create_from_desktop_file(
|
||||||
ProtoStar::create_from_desktop_file(
|
client.get_root(),
|
||||||
client.get_root(),
|
[0.0, 0.0, 0.0],
|
||||||
[0.0, 0.0, 0.0],
|
parse_desktop_file(args.desktop_file).map_err(|e| Report::msg(e))?,
|
||||||
parse_desktop_file(desktop_file).map_err(|e| Report::msg(e))?,
|
)?;
|
||||||
)?
|
|
||||||
} else if let Some(command) = args.command {
|
|
||||||
ProtoStar::new_raw(client.get_root(), [0.0, 0.0, 0.0], None, None, command)?
|
|
||||||
} else {
|
|
||||||
bail!("No command or desktop file, nothing to launch.");
|
|
||||||
};
|
|
||||||
|
|
||||||
let _root = client.wrap_root(protostar);
|
let _root = client.wrap_root(protostar);
|
||||||
|
|
||||||
|
|||||||
113
src/protostar.rs
113
src/protostar.rs
@@ -1,9 +1,10 @@
|
|||||||
use crate::xdg::{DesktopFile, Icon, IconType};
|
use crate::{
|
||||||
use color_eyre::eyre::{eyre, Result};
|
application::Application,
|
||||||
|
xdg::{DesktopFile, Icon, IconType},
|
||||||
|
};
|
||||||
|
use color_eyre::eyre::Result;
|
||||||
use glam::Quat;
|
use glam::Quat;
|
||||||
use mint::Vector3;
|
use mint::Vector3;
|
||||||
use nix::unistd::setsid;
|
|
||||||
use regex::Regex;
|
|
||||||
use stardust_xr_fusion::{
|
use stardust_xr_fusion::{
|
||||||
client::{FrameInfo, RootHandler},
|
client::{FrameInfo, RootHandler},
|
||||||
core::values::Transform,
|
core::values::Transform,
|
||||||
@@ -11,12 +12,9 @@ use stardust_xr_fusion::{
|
|||||||
fields::BoxField,
|
fields::BoxField,
|
||||||
node::NodeType,
|
node::NodeType,
|
||||||
spatial::Spatial,
|
spatial::Spatial,
|
||||||
startup_settings::StartupSettings,
|
|
||||||
};
|
};
|
||||||
use stardust_xr_molecules::{GrabData, Grabbable};
|
use stardust_xr_molecules::{GrabData, Grabbable};
|
||||||
use std::f32::consts::PI;
|
use std::f32::consts::PI;
|
||||||
use std::os::unix::process::CommandExt;
|
|
||||||
use std::process::{Command, Stdio};
|
|
||||||
use tween::{QuartInOut, Tweener};
|
use tween::{QuartInOut, Tweener};
|
||||||
|
|
||||||
const MODEL_SCALE: f32 = 0.03;
|
const MODEL_SCALE: f32 = 0.03;
|
||||||
@@ -35,13 +33,10 @@ fn model_from_icon(parent: &Spatial, icon: &Icon) -> Result<Model> {
|
|||||||
t,
|
t,
|
||||||
&ResourceID::new_namespaced("protostar", "hexagon/hexagon"),
|
&ResourceID::new_namespaced("protostar", "hexagon/hexagon"),
|
||||||
)?;
|
)?;
|
||||||
model.set_material_parameter(
|
model
|
||||||
1,
|
.model_part("Hex")?
|
||||||
"color",
|
.set_material_parameter("color", MaterialParameter::Color([0.0, 1.0, 1.0, 1.0]))?;
|
||||||
MaterialParameter::Color([0.0, 1.0, 1.0, 1.0]),
|
model.model_part("Icon")?.set_material_parameter(
|
||||||
)?;
|
|
||||||
model.set_material_parameter(
|
|
||||||
0,
|
|
||||||
"diffuse",
|
"diffuse",
|
||||||
MaterialParameter::Texture(ResourceID::Direct(icon.path.clone())),
|
MaterialParameter::Texture(ResourceID::Direct(icon.path.clone())),
|
||||||
)?;
|
)?;
|
||||||
@@ -57,16 +52,16 @@ fn model_from_icon(parent: &Spatial, icon: &Icon) -> Result<Model> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub struct ProtoStar {
|
pub struct ProtoStar {
|
||||||
|
application: Application,
|
||||||
parent: Spatial,
|
parent: Spatial,
|
||||||
position: Vector3<f32>,
|
position: Vector3<f32>,
|
||||||
grabbable: Grabbable,
|
grabbable: Grabbable,
|
||||||
field: BoxField,
|
_field: BoxField,
|
||||||
icon: Model,
|
icon: Model,
|
||||||
label: Option<Text>,
|
label: Option<Text>,
|
||||||
grabbable_shrink: Option<Tweener<f32, f64, QuartInOut>>,
|
grabbable_shrink: Option<Tweener<f32, f64, QuartInOut>>,
|
||||||
grabbable_grow: Option<Tweener<f32, f64, QuartInOut>>,
|
grabbable_grow: Option<Tweener<f32, f64, QuartInOut>>,
|
||||||
grabbable_move: Option<Tweener<f32, f64, QuartInOut>>,
|
grabbable_move: Option<Tweener<f32, f64, QuartInOut>>,
|
||||||
execute_command: String,
|
|
||||||
currently_shown: bool,
|
currently_shown: bool,
|
||||||
}
|
}
|
||||||
impl ProtoStar {
|
impl ProtoStar {
|
||||||
@@ -74,45 +69,11 @@ impl ProtoStar {
|
|||||||
parent: &Spatial,
|
parent: &Spatial,
|
||||||
position: impl Into<Vector3<f32>>,
|
position: impl Into<Vector3<f32>>,
|
||||||
desktop_file: DesktopFile,
|
desktop_file: DesktopFile,
|
||||||
) -> Result<Self> {
|
|
||||||
// dbg!(&desktop_file);
|
|
||||||
let raw_icons = desktop_file.get_raw_icons();
|
|
||||||
let mut icon = raw_icons
|
|
||||||
.clone()
|
|
||||||
.into_iter()
|
|
||||||
.find(|i| match i.icon_type {
|
|
||||||
IconType::Gltf => true,
|
|
||||||
_ => false,
|
|
||||||
})
|
|
||||||
.or(raw_icons.into_iter().max_by_key(|i| i.size));
|
|
||||||
|
|
||||||
match icon {
|
|
||||||
Some(i) => {
|
|
||||||
icon = match i.cached_process(128) {
|
|
||||||
Ok(i) => Some(i),
|
|
||||||
_ => None,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
None => {}
|
|
||||||
}
|
|
||||||
|
|
||||||
Self::new_raw(
|
|
||||||
parent,
|
|
||||||
position,
|
|
||||||
desktop_file.name.as_deref(),
|
|
||||||
icon,
|
|
||||||
desktop_file.command.ok_or_else(|| eyre!("No command"))?,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
pub fn new_raw(
|
|
||||||
parent: &Spatial,
|
|
||||||
position: impl Into<Vector3<f32>>,
|
|
||||||
name: Option<&str>,
|
|
||||||
icon: Option<Icon>,
|
|
||||||
execute_command: String,
|
|
||||||
) -> Result<Self> {
|
) -> Result<Self> {
|
||||||
let position = position.into();
|
let position = position.into();
|
||||||
let field = BoxField::create(parent, Transform::default(), [MODEL_SCALE * 2.0; 3])?;
|
let field = BoxField::create(parent, Transform::default(), [MODEL_SCALE * 2.0; 3])?;
|
||||||
|
let application = Application::create(&parent.client()?, desktop_file)?;
|
||||||
|
let icon = application.icon(128, false);
|
||||||
let grabbable = Grabbable::create(
|
let grabbable = Grabbable::create(
|
||||||
parent,
|
parent,
|
||||||
Transform::from_position(position),
|
Transform::from_position(position),
|
||||||
@@ -147,7 +108,7 @@ impl ProtoStar {
|
|||||||
text_align: Alignment::Center.into(),
|
text_align: Alignment::Center.into(),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
};
|
};
|
||||||
let label = name.and_then(|name| {
|
let label = application.name().and_then(|name| {
|
||||||
Text::create(
|
Text::create(
|
||||||
&icon,
|
&icon,
|
||||||
Transform::from_position_rotation(
|
Transform::from_position_rotation(
|
||||||
@@ -163,14 +124,14 @@ impl ProtoStar {
|
|||||||
parent: parent.alias(),
|
parent: parent.alias(),
|
||||||
position,
|
position,
|
||||||
grabbable,
|
grabbable,
|
||||||
field,
|
_field: field,
|
||||||
label,
|
label,
|
||||||
|
application,
|
||||||
icon,
|
icon,
|
||||||
grabbable_shrink: None,
|
grabbable_shrink: None,
|
||||||
grabbable_grow: None,
|
grabbable_grow: None,
|
||||||
execute_command,
|
|
||||||
currently_shown: true,
|
|
||||||
grabbable_move: None,
|
grabbable_move: None,
|
||||||
|
currently_shown: true,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
pub fn content_parent(&self) -> &Spatial {
|
pub fn content_parent(&self) -> &Spatial {
|
||||||
@@ -261,20 +222,15 @@ impl RootHandler for ProtoStar {
|
|||||||
.unwrap();
|
.unwrap();
|
||||||
self.grabbable_grow = None;
|
self.grabbable_grow = None;
|
||||||
}
|
}
|
||||||
} else if self.grabbable.grab_action().actor_stopped() {
|
} else if self.grabbable.valid() && self.grabbable.grab_action().actor_stopped() {
|
||||||
let startup_settings = StartupSettings::create(&self.field.client().unwrap()).unwrap();
|
|
||||||
startup_settings
|
|
||||||
.set_root(self.grabbable.content_parent())
|
|
||||||
.unwrap();
|
|
||||||
self.grabbable_shrink = Some(Tweener::quart_in_out(MODEL_SCALE, 0.0001, 0.25));
|
self.grabbable_shrink = Some(Tweener::quart_in_out(MODEL_SCALE, 0.0001, 0.25));
|
||||||
let distance_future = self
|
let Ok(distance_future) = self.grabbable
|
||||||
.grabbable
|
|
||||||
.content_parent()
|
.content_parent()
|
||||||
.get_position_rotation_scale(&self.parent)
|
.get_position_rotation_scale(&self.parent)
|
||||||
.unwrap();
|
else {return};
|
||||||
|
|
||||||
let executable = self.execute_command.clone();
|
let application = self.application.clone();
|
||||||
let client = self.content_parent().client().unwrap();
|
let space = self.content_parent().alias();
|
||||||
|
|
||||||
//TODO: split the executable string for the args
|
//TODO: split the executable string for the args
|
||||||
tokio::task::spawn(async move {
|
tokio::task::spawn(async move {
|
||||||
@@ -283,30 +239,7 @@ impl RootHandler for ProtoStar {
|
|||||||
+ distance_vector.z.powi(2))
|
+ distance_vector.z.powi(2))
|
||||||
.sqrt();
|
.sqrt();
|
||||||
if dbg!(distance) > ACTIVATION_DISTANCE {
|
if dbg!(distance) > ACTIVATION_DISTANCE {
|
||||||
let future = startup_settings.generate_startup_token().unwrap();
|
let _ = application.launch(&space);
|
||||||
|
|
||||||
let env = client.get_connection_environment().unwrap().await.unwrap();
|
|
||||||
for (k, v) in env.into_iter() {
|
|
||||||
std::env::set_var(k, v);
|
|
||||||
}
|
|
||||||
|
|
||||||
std::env::set_var("STARDUST_STARTUP_TOKEN", future.await.unwrap());
|
|
||||||
let re = Regex::new(r"%[fFuUdDnNickvm]").unwrap();
|
|
||||||
let exec = re.replace_all(&executable, "");
|
|
||||||
unsafe {
|
|
||||||
Command::new("sh")
|
|
||||||
.arg("-c")
|
|
||||||
.arg(exec.to_string())
|
|
||||||
.stdin(Stdio::null())
|
|
||||||
.stdout(Stdio::null())
|
|
||||||
.stderr(Stdio::null())
|
|
||||||
.pre_exec(|| {
|
|
||||||
_ = setsid();
|
|
||||||
Ok(())
|
|
||||||
})
|
|
||||||
.spawn()
|
|
||||||
.expect("Failed to start child process");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -183,19 +183,19 @@ pub struct DesktopFile {
|
|||||||
pub no_display: bool,
|
pub no_display: bool,
|
||||||
}
|
}
|
||||||
impl DesktopFile {
|
impl DesktopFile {
|
||||||
pub fn get_raw_icons(&self) -> Vec<Icon> {
|
pub fn get_raw_icons(&self, preferred_px_size: u16) -> Vec<Icon> {
|
||||||
// Get the name of the icon from the DesktopFile struct
|
// Get the name of the icon from the DesktopFile struct
|
||||||
let Some(icon_name) = self.icon.as_ref() else { return Vec::new(); };
|
let Some(icon_name) = self.icon.as_ref() else { return Vec::new(); };
|
||||||
let test_icon_path = self.path.join(Path::new(icon_name));
|
let test_icon_path = self.path.join(Path::new(icon_name));
|
||||||
if test_icon_path.exists() {
|
if test_icon_path.exists() {
|
||||||
if let Some(icon) = Icon::from_path(test_icon_path, 128) {
|
if let Some(icon) = Icon::from_path(test_icon_path, preferred_px_size) {
|
||||||
return vec![icon];
|
return vec![icon];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let cache_icon_path = get_image_cache_dir().join(icon_name).canonicalize();
|
let cache_icon_path = get_image_cache_dir().join(icon_name).canonicalize();
|
||||||
if cache_icon_path.is_ok() {
|
if cache_icon_path.is_ok() {
|
||||||
if let Some(icon) = Icon::from_path(cache_icon_path.unwrap(), 128) {
|
if let Some(icon) = Icon::from_path(cache_icon_path.unwrap(), preferred_px_size) {
|
||||||
return vec![icon];
|
return vec![icon];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -272,7 +272,7 @@ fn test_get_icon_path() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Call the get_icon_path() function with a size argument and store the result
|
// Call the get_icon_path() function with a size argument and store the result
|
||||||
let icon_paths = desktop_file.get_raw_icons();
|
let icon_paths = desktop_file.get_raw_icons(128);
|
||||||
dbg!(&icon_paths);
|
dbg!(&icon_paths);
|
||||||
|
|
||||||
// Assert that the get_icon_path() function returns the expected result
|
// Assert that the get_icon_path() function returns the expected result
|
||||||
|
|||||||
Reference in New Issue
Block a user