Updated to latest fusion

This commit is contained in:
Nicola Guerrera
2023-05-14 15:24:29 +02:00
parent a4cf97587e
commit 45c6399b63
5 changed files with 155 additions and 103 deletions

28
Cargo.lock generated
View File

@@ -626,6 +626,9 @@ name = "flagset"
version = "0.4.3" version = "0.4.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cda653ca797810c02f7ca4b804b40b8b95ae046eb989d356bce17919a8c25499" checksum = "cda653ca797810c02f7ca4b804b40b8b95ae046eb989d356bce17919a8c25499"
dependencies = [
"serde",
]
[[package]] [[package]]
name = "flatbuffers" name = "flatbuffers"
@@ -833,9 +836,9 @@ dependencies = [
[[package]] [[package]]
name = "glam" name = "glam"
version = "0.23.0" version = "0.24.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8e4afd9ad95555081e109fe1d21f2a30c691b5f0919c67dfa690a2e1eb6bd51c" checksum = "ad83ab008a4fa3b31dfa713dd41b5a9bdea1e94e4cf1e2fc274ffbd49b0271d3"
dependencies = [ dependencies = [
"mint", "mint",
] ]
@@ -1135,6 +1138,15 @@ dependencies = [
"syn", "syn",
] ]
[[package]]
name = "map-range"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dee4036c09f24ea403edcbb911a14dd641d13e181f85eff25fc3cbada6ef90f8"
dependencies = [
"num-traits",
]
[[package]] [[package]]
name = "matchers" name = "matchers"
version = "0.1.0" version = "0.1.0"
@@ -2060,9 +2072,9 @@ dependencies = [
[[package]] [[package]]
name = "stardust-xr-fusion" name = "stardust-xr-fusion"
version = "0.38.1" version = "0.40.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "45a0a1ee96c4be1d4866e1920feb4fb732b810a6cc2e9f7eeff66f07f9c2f496" checksum = "10dc289847fa08d3a67bd2be88abbc04584c6cab0081cc43bf4d56fe3cf43b5a"
dependencies = [ dependencies = [
"color-eyre", "color-eyre",
"color-rs", "color-rs",
@@ -2078,18 +2090,18 @@ dependencies = [
"thiserror", "thiserror",
"tokio", "tokio",
"tracing", "tracing",
"xkbcommon",
] ]
[[package]] [[package]]
name = "stardust-xr-molecules" name = "stardust-xr-molecules"
version = "0.22.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 = "5fe2979f1816d21c3d1a88351f92e1a011992b166072a5fbc73221d6d4557a8e" checksum = "724a92e67765300651d165950b70ec4800d4ad6450f473882f6024d5a559ea9d"
dependencies = [ dependencies = [
"color-rs", "color-rs",
"glam 0.23.0", "glam 0.24.0",
"lazy_static", "lazy_static",
"map-range",
"mint", "mint",
"rustc-hash", "rustc-hash",
"serde", "serde",

View File

@@ -23,8 +23,8 @@ rustc-hash = "1.1.0"
serde = "1.0.155" serde = "1.0.155"
serde_json = "1.0.94" serde_json = "1.0.94"
serde_with = "2.3.1" serde_with = "2.3.1"
stardust-xr-fusion = "0.38.1" stardust-xr-fusion = "0.40.0"
stardust-xr-molecules = "0.22.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"

View File

@@ -132,7 +132,9 @@ 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("?????")
.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.protostar.toggle();
@@ -141,7 +143,9 @@ impl RootHandler for AppHexGrid {
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("?????")
.unwrap()
.set_material_parameter("color", MaterialParameter::Color(color))
.unwrap(); .unwrap();
} }
for app in &mut self.apps { for app in &mut self.apps {
@@ -183,7 +187,7 @@ struct Button {
impl Button { impl Button {
fn new(client: &Client) -> Result<Self, NodeError> { fn new(client: &Client) -> Result<Self, NodeError> {
let field = BoxField::create(client.get_root(), Transform::default(), [APP_SIZE; 3])?; let field = BoxField::create(client.get_root(), Transform::default(), [APP_SIZE; 3])?;
let grabbable = Grabbable::new( let grabbable = Grabbable::create(
client.get_root(), client.get_root(),
Transform::default(), Transform::default(),
&field, &field,
@@ -193,11 +197,13 @@ impl Button {
}, },
)?; )?;
field.set_spatial_parent(grabbable.content_parent())?; field.set_spatial_parent(grabbable.content_parent())?;
let touch_plane = TouchPlane::new( let touch_plane = TouchPlane::create(
grabbable.content_parent(), grabbable.content_parent(),
Transform::default(), Transform::default(),
[(APP_SIZE + PADDING) / 2.0; 2], [(APP_SIZE + PADDING) / 2.0; 2],
(APP_SIZE + PADDING) / 2.0, (APP_SIZE + PADDING) / 2.0,
1.0..0.0,
1.0..0.0,
)?; )?;
let model = Model::create( let model = Model::create(
@@ -208,7 +214,10 @@ 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("?????")
.unwrap()
.set_material_parameter("color", MaterialParameter::Color([0.0, 0.0, 1.0, 1.0]))?;
Ok(Button { Ok(Button {
touch_plane, touch_plane,
grabbable, grabbable,

View File

@@ -8,11 +8,12 @@ use stardust_xr_fusion::{
client::{Client, FrameInfo, RootHandler}, client::{Client, FrameInfo, RootHandler},
core::values::Transform, core::values::Transform,
drawable::{MaterialParameter, Model, ResourceID}, drawable::{MaterialParameter, Model, ResourceID},
node::NodeError, input::{InputData, InputDataType}, spatial::Spatial, fields::BoxField, fields::BoxField,
input::{InputData, InputDataType},
node::NodeError,
spatial::Spatial,
}; };
use stardust_xr_molecules::{touch_plane::TouchPlane, Grabbable, GrabData}; use stardust_xr_molecules::{touch_plane::TouchPlane, GrabData, Grabbable};
#[tokio::main(flavor = "current_thread")] #[tokio::main(flavor = "current_thread")]
async fn main() -> Result<()> { async fn main() -> Result<()> {
@@ -30,107 +31,139 @@ async fn main() -> Result<()> {
} }
struct Star { struct Star {
cli: ProtoStar cli: ProtoStar,
} }
impl Star { impl Star {
fn new(parent: &Spatial, _name: Option<&str>,path: String) -> Option<Self> { fn new(parent: &Spatial, _name: Option<&str>, path: String) -> Option<Self> {
let cli = ProtoStar::new_raw(parent, None, path).unwrap(); let cli = ProtoStar::new_raw(parent, [0.0; 3], None, None, path).unwrap();
Some(Star { Some(Star { cli })
cli, }
})
}
} }
impl RootHandler for Star { impl RootHandler for Star {
fn frame(&mut self, info: FrameInfo) { fn frame(&mut self, info: FrameInfo) {
self.cli.frame(info); self.cli.frame(info);
} }
} }
const LOCATION_OF_TELESCOPE: &str = "/home/bc/repos/stardust/"; const LOCATION_OF_TELESCOPE: &str = "/home/bc/repos/stardust/";
const EXECUTABLES: [&str; 3] = [ const EXECUTABLES: [&str; 3] = ["magnetar", "atmosphere", "manifold"];
"magnetar",
"atmosphere",
"manifold",
];
struct Sirius { struct Sirius {
touch_plane: TouchPlane, touch_plane: TouchPlane,
model: Model, model: Model,
root: Spatial, root: Spatial,
clients: Vec<Star>, clients: Vec<Star>,
visibility: bool, visibility: bool,
grabbable: Grabbable, grabbable: Grabbable,
} }
impl Sirius { impl Sirius {
fn new(client: &Client) -> Result<Self, NodeError> { fn new(client: &Client) -> Result<Self, NodeError> {
let mut client_list: Vec<(Option<&str>, String)> = Vec::new(); let mut client_list: Vec<(Option<&str>, String)> = Vec::new();
for executable in EXECUTABLES { for executable in EXECUTABLES {
client_list.push((Some(executable), format!("{}telescope/repos/{}/target/release/{}", LOCATION_OF_TELESCOPE, executable, executable))); client_list.push((
} Some(executable),
let root = Spatial::create(client.get_root(), Transform::default(), false).unwrap(); format!(
"{}telescope/repos/{}/target/release/{}",
let field = BoxField::create(&root, Transform::default(), Vec3::from([0.1;3])).unwrap(); LOCATION_OF_TELESCOPE, executable, executable
let grabbable = Grabbable::new(&root, Transform::default(), &field, GrabData::default())?; ),
let touch_plane = TouchPlane::new(grabbable.content_parent(), Transform::default(), [0.1; 2], 0.03)?; ));
let mut clients = Vec::new(); }
for clientkv in client_list { let root = Spatial::create(client.get_root(), Transform::default(), false).unwrap();
clients.push(Star::new(grabbable.content_parent(), clientkv.0, clientkv.1).unwrap());
} let field = BoxField::create(&root, Transform::default(), Vec3::from([0.1; 3])).unwrap();
let grabbable =
Grabbable::create(&root, Transform::default(), &field, GrabData::default())?;
let touch_plane = TouchPlane::create(
grabbable.content_parent(),
Transform::default(),
[0.1; 2],
0.03,
1.0..0.0,
1.0..0.0,
)?;
let mut clients = Vec::new();
for clientkv in client_list {
clients.push(Star::new(grabbable.content_parent(), clientkv.0, clientkv.1).unwrap());
}
let model = Model::create( let model = Model::create(
grabbable.content_parent(), grabbable.content_parent(),
Transform::default(), Transform::default(),
&ResourceID::new_namespaced("protostar", "button"), &ResourceID::new_namespaced("protostar", "button"),
)?; )?;
field.set_spatial_parent(grabbable.content_parent())?; field.set_spatial_parent(grabbable.content_parent())?;
let visibility = false; let visibility = false;
Ok(Sirius { touch_plane, model , root, clients, visibility, grabbable}) Ok(Sirius {
touch_plane,
model,
root,
clients,
visibility,
grabbable,
})
} }
// fn left_hand(input_data: &InputData, _: &()) -> bool { // fn left_hand(input_data: &InputData, _: &()) -> bool {
// match &input_data.input { // match &input_data.input {
// InputDataType::Hand(h) => !h.right, // InputDataType::Hand(h) => !h.right,
// _ => false, // _ => false,
// } // }
// } // }
} }
impl RootHandler for Sirius { impl RootHandler for Sirius {
fn frame(&mut self, info: FrameInfo) { fn frame(&mut self, info: FrameInfo) {
for app in &mut self.clients {
app.frame(info);
}
for app in &mut self.clients { self.grabbable.update(&info);
app.frame(info); self.touch_plane.update();
}
self.grabbable.update(&info);
self.touch_plane.update();
if self.touch_plane.touch_started() { if self.touch_plane.touch_started() {
println!("Touch started"); println!("Touch started");
self.visibility = !self.visibility; self.visibility = !self.visibility;
match self.visibility { match self.visibility {
true => for star in self.clients.iter().enumerate() { true => {
let mut starpos = (star.0 as f32 +1.0)/10.0; for star in self.clients.iter().enumerate() {
match starpos % 0.2 == 0.0 { let mut starpos = (star.0 as f32 + 1.0) / 10.0;
true => starpos = -starpos/2.0, match starpos % 0.2 == 0.0 {
false => starpos = (starpos - 0.1)/2.0, true => starpos = -starpos / 2.0,
} false => starpos = (starpos - 0.1) / 2.0,
println!("{}", starpos); }
star.1.cli.content_parent().set_position(Some(&self.grabbable.content_parent()), Vec3::from([starpos,0.1,0.0])).ok(); println!("{}", starpos);
}, star.1
false => for star in &self.clients { .cli
star.cli.content_parent().set_position(Some(&self.grabbable.content_parent()), Vec3::from([0.0,0.0,0.0])).ok(); .content_parent()
}, .set_position(
Some(&self.grabbable.content_parent()),
} Vec3::from([starpos, 0.1, 0.0]),
)
.ok();
}
}
false => {
for star in &self.clients {
star.cli
.content_parent()
.set_position(
Some(&self.grabbable.content_parent()),
Vec3::from([0.0, 0.0, 0.0]),
)
.ok();
}
}
}
let color = [0.0, 1.0, 0.0, 1.0]; let color = [0.0, 1.0, 0.0, 1.0];
self.model self.model
.set_material_parameter(0, "color", MaterialParameter::Color(color)) .model_part("?????")
.unwrap()
.set_material_parameter("color", MaterialParameter::Color(color))
.unwrap(); .unwrap();
self.model self.model
.model_part("?????")
.unwrap()
.set_material_parameter( .set_material_parameter(
0,
"emission_factor", "emission_factor",
MaterialParameter::Color(color.map(|c| c * 0.75)), MaterialParameter::Color(color.map(|c| c * 0.75)),
) )
@@ -141,11 +174,14 @@ impl RootHandler for Sirius {
println!("Touch ended"); println!("Touch ended");
let color = [1.0, 0.0, 0.0, 1.0]; let color = [1.0, 0.0, 0.0, 1.0];
self.model self.model
.set_material_parameter(0, "color", MaterialParameter::Color(color)) .model_part("?????")
.unwrap()
.set_material_parameter("color", MaterialParameter::Color(color))
.unwrap(); .unwrap();
self.model self.model
.model_part("?????")
.unwrap()
.set_material_parameter( .set_material_parameter(
0,
"emission_factor", "emission_factor",
MaterialParameter::Color(color.map(|c| c * 0.5)), MaterialParameter::Color(color.map(|c| c * 0.5)),
) )
@@ -155,11 +191,9 @@ impl RootHandler for Sirius {
} }
fn position(data: &InputData) -> Vec3 { fn position(data: &InputData) -> Vec3 {
match &data.input { match &data.input {
InputDataType::Hand(h) => h.palm.position.into(), InputDataType::Hand(h) => h.palm.position.into(),
InputDataType::Pointer(w) => w.deepest_point.into(), InputDataType::Pointer(w) => w.deepest_point.into(),
InputDataType::Tip(t) => t.origin.into(), InputDataType::Tip(t) => t.origin.into(),
} }
} }

View File

@@ -35,13 +35,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( let model_part = model.model_part("hexagon/hexagon").unwrap();
1, model_part
"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_part.set_material_parameter(
)?;
model.set_material_parameter(
0,
"diffuse", "diffuse",
MaterialParameter::Texture(ResourceID::Direct(icon.path.clone())), MaterialParameter::Texture(ResourceID::Direct(icon.path.clone())),
)?; )?;
@@ -113,7 +110,7 @@ impl ProtoStar {
) -> 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 grabbable = Grabbable::new( let grabbable = Grabbable::create(
parent, parent,
Transform::from_position(position), Transform::from_position(position),
&field, &field,