create resource to help with entity selection
This commit is contained in:
@@ -1,13 +1,13 @@
|
||||
use std::f32::consts::PI;
|
||||
|
||||
|
||||
use bevy::diagnostic::{FrameTimeDiagnosticsPlugin, LogDiagnosticsPlugin};
|
||||
|
||||
use bevy::transform::components::Transform;
|
||||
use bevy::prelude::*;
|
||||
use bevy::transform::components::Transform;
|
||||
use bevy_openxr::input::XrInput;
|
||||
use bevy_openxr::resources::{XrFrameState, XrInstance, XrSession};
|
||||
|
||||
use bevy_openxr::xr_input::hand::HandsResource;
|
||||
use bevy_openxr::xr_input::hand_poses::*;
|
||||
use bevy_openxr::xr_input::oculus_touch::OculusController;
|
||||
use bevy_openxr::xr_input::prototype_locomotion::{proto_locomotion, PrototypeLocomotionConfig};
|
||||
@@ -119,17 +119,79 @@ pub fn spawn_hand_entities(mut commands: Commands) {
|
||||
HandBone::LittleDistal,
|
||||
HandBone::LittleTip,
|
||||
];
|
||||
|
||||
//hand resource
|
||||
let mut hand_resource = HandsResource { ..default() };
|
||||
for hand in hands.iter() {
|
||||
for bone in bones.iter() {
|
||||
commands.spawn((
|
||||
SpatialBundle::default(),
|
||||
bone.clone(),
|
||||
OpenXRTracker,
|
||||
hand.clone(),
|
||||
));
|
||||
let boneid = commands
|
||||
.spawn((
|
||||
SpatialBundle::default(),
|
||||
bone.clone(),
|
||||
OpenXRTracker,
|
||||
hand.clone(),
|
||||
))
|
||||
.id();
|
||||
match hand {
|
||||
Hand::Left => match bone {
|
||||
HandBone::Palm => hand_resource.left.palm = boneid,
|
||||
HandBone::Wrist => hand_resource.left.wrist = boneid,
|
||||
HandBone::ThumbMetacarpal => hand_resource.left.thumb.metacarpal = boneid,
|
||||
HandBone::ThumbProximal => hand_resource.left.thumb.proximal = boneid,
|
||||
HandBone::ThumbDistal => hand_resource.left.thumb.distal = boneid,
|
||||
HandBone::ThumbTip => hand_resource.left.thumb.tip = boneid,
|
||||
HandBone::IndexMetacarpal => hand_resource.left.index.metacarpal = boneid,
|
||||
HandBone::IndexProximal => hand_resource.left.index.proximal = boneid,
|
||||
HandBone::IndexIntermediate => hand_resource.left.index.intermediate = boneid,
|
||||
HandBone::IndexDistal => hand_resource.left.index.distal = boneid,
|
||||
HandBone::IndexTip => hand_resource.left.index.tip = boneid,
|
||||
HandBone::MiddleMetacarpal => hand_resource.left.middle.metacarpal = boneid,
|
||||
HandBone::MiddleProximal => hand_resource.left.middle.proximal = boneid,
|
||||
HandBone::MiddleIntermediate => hand_resource.left.middle.intermediate = boneid,
|
||||
HandBone::MiddleDistal => hand_resource.left.middle.distal = boneid,
|
||||
HandBone::MiddleTip => hand_resource.left.middle.tip = boneid,
|
||||
HandBone::RingMetacarpal => hand_resource.left.ring.metacarpal = boneid,
|
||||
HandBone::RingProximal => hand_resource.left.ring.proximal = boneid,
|
||||
HandBone::RingIntermediate => hand_resource.left.ring.intermediate = boneid,
|
||||
HandBone::RingDistal => hand_resource.left.ring.distal = boneid,
|
||||
HandBone::RingTip => hand_resource.left.ring.tip = boneid,
|
||||
HandBone::LittleMetacarpal => hand_resource.left.little.metacarpal = boneid,
|
||||
HandBone::LittleProximal => hand_resource.left.little.proximal = boneid,
|
||||
HandBone::LittleIntermediate => hand_resource.left.little.intermediate = boneid,
|
||||
HandBone::LittleDistal => hand_resource.left.little.distal = boneid,
|
||||
HandBone::LittleTip => hand_resource.left.little.tip = boneid,
|
||||
},
|
||||
Hand::Right => match bone {
|
||||
HandBone::Palm => hand_resource.right.palm = boneid,
|
||||
HandBone::Wrist => hand_resource.right.wrist = boneid,
|
||||
HandBone::ThumbMetacarpal => hand_resource.right.thumb.metacarpal = boneid,
|
||||
HandBone::ThumbProximal => hand_resource.right.thumb.proximal = boneid,
|
||||
HandBone::ThumbDistal => hand_resource.right.thumb.distal = boneid,
|
||||
HandBone::ThumbTip => hand_resource.right.thumb.tip = boneid,
|
||||
HandBone::IndexMetacarpal => hand_resource.right.index.metacarpal = boneid,
|
||||
HandBone::IndexProximal => hand_resource.right.index.proximal = boneid,
|
||||
HandBone::IndexIntermediate => hand_resource.right.index.intermediate = boneid,
|
||||
HandBone::IndexDistal => hand_resource.right.index.distal = boneid,
|
||||
HandBone::IndexTip => hand_resource.right.index.tip = boneid,
|
||||
HandBone::MiddleMetacarpal => hand_resource.right.middle.metacarpal = boneid,
|
||||
HandBone::MiddleProximal => hand_resource.right.middle.proximal = boneid,
|
||||
HandBone::MiddleIntermediate => hand_resource.right.middle.intermediate = boneid,
|
||||
HandBone::MiddleDistal => hand_resource.right.middle.distal = boneid,
|
||||
HandBone::MiddleTip => hand_resource.right.middle.tip = boneid,
|
||||
HandBone::RingMetacarpal => hand_resource.right.ring.metacarpal = boneid,
|
||||
HandBone::RingProximal => hand_resource.right.ring.proximal = boneid,
|
||||
HandBone::RingIntermediate => hand_resource.right.ring.intermediate = boneid,
|
||||
HandBone::RingDistal => hand_resource.right.ring.distal = boneid,
|
||||
HandBone::RingTip => hand_resource.right.ring.tip = boneid,
|
||||
HandBone::LittleMetacarpal => hand_resource.right.little.metacarpal = boneid,
|
||||
HandBone::LittleProximal => hand_resource.right.little.proximal = boneid,
|
||||
HandBone::LittleIntermediate => hand_resource.right.little.intermediate = boneid,
|
||||
HandBone::LittleDistal => hand_resource.right.little.distal = boneid,
|
||||
HandBone::LittleTip => hand_resource.right.little.tip = boneid,
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
commands.insert_resource(hand_resource);
|
||||
}
|
||||
|
||||
pub fn update_hand_states(
|
||||
|
||||
@@ -1,3 +1,85 @@
|
||||
pub struct Hand {
|
||||
pub HandJointPoses: [Posef; 26]
|
||||
use bevy::prelude::{Entity, Resource};
|
||||
|
||||
#[derive(Resource, Default)]
|
||||
pub struct HandsResource {
|
||||
pub left: HandResource,
|
||||
pub right: HandResource,
|
||||
}
|
||||
|
||||
pub struct HandResource {
|
||||
pub palm: Entity,
|
||||
pub wrist: Entity,
|
||||
pub thumb: ThumbResource,
|
||||
pub index: IndexResource,
|
||||
pub middle: MiddleResource,
|
||||
pub ring: RingResource,
|
||||
pub little: LittleResource,
|
||||
}
|
||||
|
||||
impl Default for HandResource {
|
||||
fn default() -> Self {
|
||||
Self { palm: Entity::PLACEHOLDER, wrist: Entity::PLACEHOLDER, thumb: Default::default(), index: Default::default(), middle: Default::default(), ring: Default::default(), little: Default::default() }
|
||||
}
|
||||
}
|
||||
|
||||
pub struct ThumbResource {
|
||||
pub metacarpal: Entity,
|
||||
pub proximal: Entity,
|
||||
pub distal: Entity,
|
||||
pub tip: Entity,
|
||||
}
|
||||
|
||||
impl Default for ThumbResource {
|
||||
fn default() -> Self {
|
||||
Self { metacarpal: Entity::PLACEHOLDER, proximal: Entity::PLACEHOLDER, distal: Entity::PLACEHOLDER, tip: Entity::PLACEHOLDER }
|
||||
}
|
||||
}
|
||||
pub struct IndexResource {
|
||||
pub metacarpal: Entity,
|
||||
pub proximal: Entity,
|
||||
pub intermediate: Entity,
|
||||
pub distal: Entity,
|
||||
pub tip: Entity,
|
||||
}
|
||||
|
||||
impl Default for IndexResource {
|
||||
fn default() -> Self {
|
||||
Self { metacarpal: Entity::PLACEHOLDER, proximal: Entity::PLACEHOLDER, intermediate: Entity::PLACEHOLDER, distal: Entity::PLACEHOLDER, tip: Entity::PLACEHOLDER }
|
||||
}
|
||||
}
|
||||
pub struct MiddleResource {
|
||||
pub metacarpal: Entity,
|
||||
pub proximal: Entity,
|
||||
pub intermediate: Entity,
|
||||
pub distal: Entity,
|
||||
pub tip: Entity,
|
||||
}
|
||||
impl Default for MiddleResource {
|
||||
fn default() -> Self {
|
||||
Self { metacarpal: Entity::PLACEHOLDER, proximal: Entity::PLACEHOLDER, intermediate: Entity::PLACEHOLDER, distal: Entity::PLACEHOLDER, tip: Entity::PLACEHOLDER }
|
||||
}
|
||||
}
|
||||
pub struct RingResource {
|
||||
pub metacarpal: Entity,
|
||||
pub proximal: Entity,
|
||||
pub intermediate: Entity,
|
||||
pub distal: Entity,
|
||||
pub tip: Entity,
|
||||
}
|
||||
impl Default for RingResource {
|
||||
fn default() -> Self {
|
||||
Self { metacarpal: Entity::PLACEHOLDER, proximal: Entity::PLACEHOLDER, intermediate: Entity::PLACEHOLDER, distal: Entity::PLACEHOLDER, tip: Entity::PLACEHOLDER }
|
||||
}
|
||||
}
|
||||
pub struct LittleResource {
|
||||
pub metacarpal: Entity,
|
||||
pub proximal: Entity,
|
||||
pub intermediate: Entity,
|
||||
pub distal: Entity,
|
||||
pub tip: Entity,
|
||||
}
|
||||
impl Default for LittleResource {
|
||||
fn default() -> Self {
|
||||
Self { metacarpal: Entity::PLACEHOLDER, proximal: Entity::PLACEHOLDER, intermediate: Entity::PLACEHOLDER, distal: Entity::PLACEHOLDER, tip: Entity::PLACEHOLDER }
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,7 @@ pub mod prototype_locomotion;
|
||||
pub mod trackers;
|
||||
pub mod xr_camera;
|
||||
pub mod hand_poses;
|
||||
pub mod hand;
|
||||
|
||||
use crate::resources::XrSession;
|
||||
use crate::xr_begin_frame;
|
||||
|
||||
Reference in New Issue
Block a user