Updated to latest fusion
This commit is contained in:
@@ -132,7 +132,9 @@ impl RootHandler for AppHexGrid {
|
||||
let color = [0.0, 1.0, 0.0, 1.0];
|
||||
self.button
|
||||
.model
|
||||
.set_material_parameter(1, "color", MaterialParameter::Color(color))
|
||||
.model_part("?????")
|
||||
.unwrap()
|
||||
.set_material_parameter("color", MaterialParameter::Color(color))
|
||||
.unwrap();
|
||||
for app in &mut self.apps {
|
||||
app.protostar.toggle();
|
||||
@@ -141,7 +143,9 @@ impl RootHandler for AppHexGrid {
|
||||
let color = [0.0, 0.0, 1.0, 1.0];
|
||||
self.button
|
||||
.model
|
||||
.set_material_parameter(1, "color", MaterialParameter::Color(color))
|
||||
.model_part("?????")
|
||||
.unwrap()
|
||||
.set_material_parameter("color", MaterialParameter::Color(color))
|
||||
.unwrap();
|
||||
}
|
||||
for app in &mut self.apps {
|
||||
@@ -183,7 +187,7 @@ struct Button {
|
||||
impl Button {
|
||||
fn new(client: &Client) -> Result<Self, NodeError> {
|
||||
let field = BoxField::create(client.get_root(), Transform::default(), [APP_SIZE; 3])?;
|
||||
let grabbable = Grabbable::new(
|
||||
let grabbable = Grabbable::create(
|
||||
client.get_root(),
|
||||
Transform::default(),
|
||||
&field,
|
||||
@@ -193,11 +197,13 @@ impl Button {
|
||||
},
|
||||
)?;
|
||||
field.set_spatial_parent(grabbable.content_parent())?;
|
||||
let touch_plane = TouchPlane::new(
|
||||
let touch_plane = TouchPlane::create(
|
||||
grabbable.content_parent(),
|
||||
Transform::default(),
|
||||
[(APP_SIZE + PADDING) / 2.0; 2],
|
||||
(APP_SIZE + PADDING) / 2.0,
|
||||
1.0..0.0,
|
||||
1.0..0.0,
|
||||
)?;
|
||||
|
||||
let model = Model::create(
|
||||
@@ -208,7 +214,10 @@ impl Button {
|
||||
),
|
||||
&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 {
|
||||
touch_plane,
|
||||
grabbable,
|
||||
|
||||
@@ -8,11 +8,12 @@ use stardust_xr_fusion::{
|
||||
client::{Client, FrameInfo, RootHandler},
|
||||
core::values::Transform,
|
||||
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")]
|
||||
async fn main() -> Result<()> {
|
||||
@@ -30,107 +31,139 @@ async fn main() -> Result<()> {
|
||||
}
|
||||
|
||||
struct Star {
|
||||
cli: ProtoStar
|
||||
cli: ProtoStar,
|
||||
}
|
||||
|
||||
impl Star {
|
||||
fn new(parent: &Spatial, _name: Option<&str>,path: String) -> Option<Self> {
|
||||
let cli = ProtoStar::new_raw(parent, None, path).unwrap();
|
||||
Some(Star {
|
||||
cli,
|
||||
})
|
||||
}
|
||||
fn new(parent: &Spatial, _name: Option<&str>, path: String) -> Option<Self> {
|
||||
let cli = ProtoStar::new_raw(parent, [0.0; 3], None, None, path).unwrap();
|
||||
Some(Star { cli })
|
||||
}
|
||||
}
|
||||
|
||||
impl RootHandler for Star {
|
||||
fn frame(&mut self, info: FrameInfo) {
|
||||
self.cli.frame(info);
|
||||
}
|
||||
fn frame(&mut self, info: FrameInfo) {
|
||||
self.cli.frame(info);
|
||||
}
|
||||
}
|
||||
|
||||
const LOCATION_OF_TELESCOPE: &str = "/home/bc/repos/stardust/";
|
||||
const EXECUTABLES: [&str; 3] = [
|
||||
"magnetar",
|
||||
"atmosphere",
|
||||
"manifold",
|
||||
];
|
||||
const EXECUTABLES: [&str; 3] = ["magnetar", "atmosphere", "manifold"];
|
||||
|
||||
struct Sirius {
|
||||
touch_plane: TouchPlane,
|
||||
model: Model,
|
||||
root: Spatial,
|
||||
clients: Vec<Star>,
|
||||
visibility: bool,
|
||||
grabbable: Grabbable,
|
||||
|
||||
root: Spatial,
|
||||
clients: Vec<Star>,
|
||||
visibility: bool,
|
||||
grabbable: Grabbable,
|
||||
}
|
||||
impl Sirius {
|
||||
fn new(client: &Client) -> Result<Self, NodeError> {
|
||||
let mut client_list: Vec<(Option<&str>, String)> = Vec::new();
|
||||
for executable in EXECUTABLES {
|
||||
client_list.push((Some(executable), format!("{}telescope/repos/{}/target/release/{}", LOCATION_OF_TELESCOPE, executable, executable)));
|
||||
}
|
||||
let root = Spatial::create(client.get_root(), Transform::default(), false).unwrap();
|
||||
|
||||
let field = BoxField::create(&root, Transform::default(), Vec3::from([0.1;3])).unwrap();
|
||||
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 {
|
||||
clients.push(Star::new(grabbable.content_parent(), clientkv.0, clientkv.1).unwrap());
|
||||
}
|
||||
let mut client_list: Vec<(Option<&str>, String)> = Vec::new();
|
||||
for executable in EXECUTABLES {
|
||||
client_list.push((
|
||||
Some(executable),
|
||||
format!(
|
||||
"{}telescope/repos/{}/target/release/{}",
|
||||
LOCATION_OF_TELESCOPE, executable, executable
|
||||
),
|
||||
));
|
||||
}
|
||||
let root = Spatial::create(client.get_root(), Transform::default(), false).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(
|
||||
grabbable.content_parent(),
|
||||
grabbable.content_parent(),
|
||||
Transform::default(),
|
||||
&ResourceID::new_namespaced("protostar", "button"),
|
||||
)?;
|
||||
field.set_spatial_parent(grabbable.content_parent())?;
|
||||
let visibility = false;
|
||||
field.set_spatial_parent(grabbable.content_parent())?;
|
||||
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 {
|
||||
// match &input_data.input {
|
||||
// InputDataType::Hand(h) => !h.right,
|
||||
// _ => false,
|
||||
// }
|
||||
// }
|
||||
// fn left_hand(input_data: &InputData, _: &()) -> bool {
|
||||
// match &input_data.input {
|
||||
// InputDataType::Hand(h) => !h.right,
|
||||
// _ => false,
|
||||
// }
|
||||
// }
|
||||
}
|
||||
impl RootHandler for Sirius {
|
||||
fn frame(&mut self, info: FrameInfo) {
|
||||
for app in &mut self.clients {
|
||||
app.frame(info);
|
||||
}
|
||||
|
||||
for app in &mut self.clients {
|
||||
app.frame(info);
|
||||
}
|
||||
|
||||
self.grabbable.update(&info);
|
||||
self.touch_plane.update();
|
||||
self.grabbable.update(&info);
|
||||
self.touch_plane.update();
|
||||
if self.touch_plane.touch_started() {
|
||||
println!("Touch started");
|
||||
self.visibility = !self.visibility;
|
||||
match self.visibility {
|
||||
true => for star in self.clients.iter().enumerate() {
|
||||
let mut starpos = (star.0 as f32 +1.0)/10.0;
|
||||
match starpos % 0.2 == 0.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();
|
||||
},
|
||||
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();
|
||||
},
|
||||
|
||||
}
|
||||
self.visibility = !self.visibility;
|
||||
match self.visibility {
|
||||
true => {
|
||||
for star in self.clients.iter().enumerate() {
|
||||
let mut starpos = (star.0 as f32 + 1.0) / 10.0;
|
||||
match starpos % 0.2 == 0.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();
|
||||
}
|
||||
}
|
||||
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];
|
||||
self.model
|
||||
.set_material_parameter(0, "color", MaterialParameter::Color(color))
|
||||
.model_part("?????")
|
||||
.unwrap()
|
||||
.set_material_parameter("color", MaterialParameter::Color(color))
|
||||
.unwrap();
|
||||
self.model
|
||||
.model_part("?????")
|
||||
.unwrap()
|
||||
.set_material_parameter(
|
||||
0,
|
||||
"emission_factor",
|
||||
MaterialParameter::Color(color.map(|c| c * 0.75)),
|
||||
)
|
||||
@@ -141,11 +174,14 @@ impl RootHandler for Sirius {
|
||||
println!("Touch ended");
|
||||
let color = [1.0, 0.0, 0.0, 1.0];
|
||||
self.model
|
||||
.set_material_parameter(0, "color", MaterialParameter::Color(color))
|
||||
.model_part("?????")
|
||||
.unwrap()
|
||||
.set_material_parameter("color", MaterialParameter::Color(color))
|
||||
.unwrap();
|
||||
self.model
|
||||
.model_part("?????")
|
||||
.unwrap()
|
||||
.set_material_parameter(
|
||||
0,
|
||||
"emission_factor",
|
||||
MaterialParameter::Color(color.map(|c| c * 0.5)),
|
||||
)
|
||||
@@ -155,11 +191,9 @@ impl RootHandler for Sirius {
|
||||
}
|
||||
|
||||
fn position(data: &InputData) -> Vec3 {
|
||||
match &data.input {
|
||||
InputDataType::Hand(h) => h.palm.position.into(),
|
||||
InputDataType::Pointer(w) => w.deepest_point.into(),
|
||||
InputDataType::Tip(t) => t.origin.into(),
|
||||
}
|
||||
|
||||
|
||||
match &data.input {
|
||||
InputDataType::Hand(h) => h.palm.position.into(),
|
||||
InputDataType::Pointer(w) => w.deepest_point.into(),
|
||||
InputDataType::Tip(t) => t.origin.into(),
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user