hover input action
This commit is contained in:
parent
5b8529b72f
commit
0a2a8bf1ac
1 changed files with 87 additions and 11 deletions
98
src/main.rs
98
src/main.rs
|
@ -1,23 +1,99 @@
|
|||
use manifest_dir_macros::directory_relative_path;
|
||||
use stardust_xr_fusion::{
|
||||
client::Client, core::values::ResourceID, drawable::Model, spatial::Transform
|
||||
client::{Client, RootHandler}, core::values::ResourceID, drawable::Model, fields::BoxField, input::InputHandler, spatial::{SpatialAspect, Transform}, HandlerWrapper
|
||||
};
|
||||
use stardust_xr_molecules::{input_action::{BaseInputAction, InputActionHandler}, Grabbable, GrabbableSettings};
|
||||
|
||||
struct Root {
|
||||
model: Model,
|
||||
field: BoxField,
|
||||
grabbable: Grabbable,
|
||||
input_handler: HandlerWrapper<InputHandler, InputActionHandler<()>>,
|
||||
color_hover: BaseInputAction<()>,
|
||||
}
|
||||
|
||||
impl Root {
|
||||
async fn create(client: &Client) -> Self {
|
||||
// stardust_xr_fusion::drawable::Model
|
||||
// pub fn create(spatial_parent: &impl SpatialAspect, transform: Transform, model: &ResourceID) -> NodeResult<Self>
|
||||
let model = Model::create(
|
||||
client.get_root(),
|
||||
Transform::identity(),
|
||||
&ResourceID::new_namespaced(
|
||||
"color_cube",
|
||||
"color_cube"
|
||||
),
|
||||
).unwrap();
|
||||
|
||||
let field =
|
||||
BoxField::create(&model, Transform::none(), mint::Vector3 { x: 0.4, y: 0.4, z: 0.4 }).unwrap();
|
||||
|
||||
let grab_settings = GrabbableSettings {
|
||||
zoneable: true,
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
let grabbable =
|
||||
Grabbable::create(client.get_root(), Transform::none(), &field, grab_settings).unwrap();
|
||||
|
||||
model
|
||||
.set_spatial_parent_in_place(grabbable.content_parent())
|
||||
.unwrap();
|
||||
|
||||
let input_handler = InputActionHandler::wrap(
|
||||
InputHandler::create(
|
||||
&model,
|
||||
Transform::none(),
|
||||
&field,
|
||||
).unwrap(),
|
||||
(),
|
||||
).unwrap();
|
||||
|
||||
let color_hover = BaseInputAction::new(
|
||||
false,
|
||||
|d, _| d.distance < 0.0,
|
||||
);
|
||||
|
||||
Root {
|
||||
model,
|
||||
field,
|
||||
grabbable,
|
||||
input_handler,
|
||||
color_hover,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl RootHandler for Root {
|
||||
fn frame(&mut self, info: stardust_xr_fusion::client::FrameInfo) {
|
||||
self.grabbable.update(&info).unwrap();
|
||||
|
||||
self.input_handler.lock_wrapped().update_actions(
|
||||
[&mut self.color_hover],
|
||||
);
|
||||
|
||||
if self.color_hover.currently_acting.is_empty() {
|
||||
self.model.set_local_transform(
|
||||
Transform::from_scale([1.1; 3])
|
||||
).unwrap();
|
||||
} else {
|
||||
self.model.set_local_transform(
|
||||
Transform::from_scale([1.0; 3])
|
||||
).unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
fn save_state(&mut self) -> stardust_xr_fusion::client::ClientState {
|
||||
todo!("implement save state")
|
||||
}
|
||||
}
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() {
|
||||
let (client, event_loop) = Client::connect_with_async_loop().await.unwrap();
|
||||
client.set_base_prefixes(&[directory_relative_path!("res")]);
|
||||
|
||||
// stardust_xr_fusion::drawable::Model
|
||||
// pub fn create(spatial_parent: &impl SpatialAspect, transform: Transform, model: &ResourceID) -> NodeResult<Self>
|
||||
let _model = Model::create(
|
||||
client.get_root(),
|
||||
Transform::identity(),
|
||||
&ResourceID::new_namespaced(
|
||||
"color_cube",
|
||||
"color_cube"
|
||||
),
|
||||
);
|
||||
let _root = client.wrap_root(Root::create(&client).await).unwrap();
|
||||
|
||||
tokio::select! {
|
||||
_ = tokio::signal::ctrl_c() => (),
|
||||
|
|
Loading…
Add table
Reference in a new issue