Merge branch 'webxr-refactor' into example_actions
This commit is contained in:
@@ -12,6 +12,10 @@ passthrough = []
|
||||
[dev-dependencies]
|
||||
bevy_xr_utils.path = "../bevy_xr_utils"
|
||||
|
||||
[target.'cfg(target_os = "android")'.dependencies]
|
||||
ndk-context = "0.1"
|
||||
jni = "0.20"
|
||||
|
||||
# bevy can't be placed behind target or proc macros won't work properly
|
||||
[dependencies]
|
||||
bevy.workspace = true
|
||||
@@ -28,6 +32,7 @@ ash = { version = "0.37.3", optional = true }
|
||||
|
||||
[target.'cfg(target_family = "unix")'.dependencies]
|
||||
openxr = { version = "0.18.0", features = ["mint"] }
|
||||
wgpu = { version = "0.19.3", features = ["vulkan-portability"] }
|
||||
|
||||
[target.'cfg(target_family = "windows")'.dependencies]
|
||||
openxr = { version = "0.18.0", features = ["mint", "static"] }
|
||||
|
||||
@@ -39,7 +39,8 @@ fn setup(
|
||||
},
|
||||
transform: Transform::from_xyz(4.0, 8.0, 4.0),
|
||||
..default()
|
||||
}); commands.spawn(Camera3dBundle {
|
||||
});
|
||||
commands.spawn(Camera3dBundle {
|
||||
transform: Transform::from_xyz(-2.5, 4.5, 9.0).looking_at(Vec3::ZERO, Vec3::Y),
|
||||
..default()
|
||||
});
|
||||
|
||||
@@ -21,7 +21,12 @@ fn main() {
|
||||
synchronous_pipeline_compilation: default(),
|
||||
}))
|
||||
.add_plugins(bevy_xr_utils::hand_gizmos::HandGizmosPlugin)
|
||||
.insert_resource(Msaa::Off)
|
||||
.add_systems(Startup, setup)
|
||||
.insert_resource(AmbientLight {
|
||||
color: Default::default(),
|
||||
brightness: 500.0,
|
||||
})
|
||||
.insert_resource(ClearColor(Color::NONE))
|
||||
.run();
|
||||
}
|
||||
@@ -46,13 +51,4 @@ fn setup(
|
||||
transform: Transform::from_xyz(0.0, 0.5, 0.0),
|
||||
..default()
|
||||
});
|
||||
// light
|
||||
commands.spawn(PointLightBundle {
|
||||
point_light: PointLight {
|
||||
shadows_enabled: true,
|
||||
..default()
|
||||
},
|
||||
transform: Transform::from_xyz(4.0, 8.0, 4.0),
|
||||
..default()
|
||||
});
|
||||
}
|
||||
|
||||
@@ -14,10 +14,14 @@ impl Plugin for OxrActionAttachingPlugin {
|
||||
|
||||
fn attach_sets(session: Res<OxrSession>, mut events: EventReader<OxrAttachActionSet>) {
|
||||
let sets = events.read().map(|v| &v.0).collect::<Vec<_>>();
|
||||
if sets.is_empty() {return;}
|
||||
if sets.is_empty() {
|
||||
return;
|
||||
}
|
||||
info!("attaching {} sessions", sets.len());
|
||||
match session.attach_action_sets(&sets) {
|
||||
Ok(_) => {info!("attached sessions!")}
|
||||
Ok(_) => {
|
||||
info!("attached sessions!")
|
||||
}
|
||||
Err(openxr::sys::Result::ERROR_ACTIONSETS_ALREADY_ATTACHED) => {
|
||||
error!("Action Sets Already attached!");
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
use bevy::prelude::*;
|
||||
use bevy_xr::hands::{LeftHand, RightHand};
|
||||
use bevy_xr::{
|
||||
hands::{HandBone, HandBoneRadius},
|
||||
session::{session_running, status_changed_to, XrStatus},
|
||||
@@ -74,11 +75,22 @@ fn spawn_default_hands(
|
||||
let mut right_bones = [Entity::PLACEHOLDER; 26];
|
||||
for bone in HandBone::get_all_bones() {
|
||||
let bone_left = cmds
|
||||
.spawn((SpatialBundle::default(), bone, HandBoneRadius(0.0)))
|
||||
.spawn((
|
||||
SpatialBundle::default(),
|
||||
bone,
|
||||
HandBoneRadius(0.0),
|
||||
LeftHand,
|
||||
))
|
||||
.id();
|
||||
let bone_right = cmds
|
||||
.spawn((SpatialBundle::default(), bone, HandBoneRadius(0.0)))
|
||||
.spawn((
|
||||
SpatialBundle::default(),
|
||||
bone,
|
||||
HandBoneRadius(0.0),
|
||||
RightHand,
|
||||
))
|
||||
.id();
|
||||
cmds.entity(root).push_children(&[bone_left]);
|
||||
cmds.entity(root).push_children(&[bone_right]);
|
||||
left_bones[bone as usize] = bone_left;
|
||||
right_bones[bone as usize] = bone_right;
|
||||
@@ -87,11 +99,13 @@ fn spawn_default_hands(
|
||||
DefaultHandTracker,
|
||||
OxrHandTracker(tracker_left),
|
||||
OxrHandBoneEntities(left_bones),
|
||||
LeftHand,
|
||||
));
|
||||
cmds.spawn((
|
||||
DefaultHandTracker,
|
||||
OxrHandTracker(tracker_right),
|
||||
OxrHandBoneEntities(right_bones),
|
||||
RightHand,
|
||||
));
|
||||
}
|
||||
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
pub mod handtracking;
|
||||
#[cfg(feature = "passthrough")]
|
||||
pub mod passthrough;
|
||||
pub mod handtracking;
|
||||
|
||||
@@ -17,6 +17,7 @@ use self::{
|
||||
|
||||
pub mod action_binding;
|
||||
pub mod action_set_attaching;
|
||||
pub mod action_set_syncing;
|
||||
pub mod error;
|
||||
mod exts;
|
||||
pub mod features;
|
||||
@@ -28,7 +29,6 @@ pub mod reference_space;
|
||||
pub mod render;
|
||||
pub mod resources;
|
||||
pub mod types;
|
||||
pub mod action_set_syncing;
|
||||
|
||||
pub fn add_xr_plugins<G: PluginGroup>(plugins: G) -> PluginGroupBuilder {
|
||||
plugins
|
||||
|
||||
@@ -10,14 +10,17 @@ use bevy::{
|
||||
},
|
||||
transform::TransformSystem,
|
||||
};
|
||||
use bevy_xr::{camera::{XrCamera, XrCameraBundle, XrProjection}, session::session_running};
|
||||
use bevy_xr::{
|
||||
camera::{XrCamera, XrCameraBundle, XrProjection},
|
||||
session::session_running,
|
||||
};
|
||||
use openxr::ViewStateFlags;
|
||||
|
||||
use crate::{reference_space::OxrPrimaryReferenceSpace, resources::*};
|
||||
use crate::{
|
||||
init::{session_started, OxrPreUpdateSet, OxrTrackingRoot},
|
||||
layer_builder::ProjectionLayer,
|
||||
};
|
||||
use crate::{reference_space::OxrPrimaryReferenceSpace, resources::*};
|
||||
|
||||
pub struct OxrRenderPlugin;
|
||||
|
||||
@@ -28,7 +31,6 @@ impl Plugin for OxrRenderPlugin {
|
||||
PreUpdate,
|
||||
(
|
||||
init_views.run_if(resource_added::<OxrGraphicsInfo>),
|
||||
wait_frame.run_if(session_started),
|
||||
locate_views.run_if(session_running),
|
||||
update_views.run_if(session_running),
|
||||
)
|
||||
@@ -41,7 +43,8 @@ impl Plugin for OxrRenderPlugin {
|
||||
.chain()
|
||||
.run_if(session_running)
|
||||
.before(TransformSystem::TransformPropagate),
|
||||
);
|
||||
)
|
||||
.add_systems(Last, wait_frame.run_if(session_started));
|
||||
app.sub_app_mut(RenderApp)
|
||||
.add_systems(
|
||||
Render,
|
||||
@@ -350,11 +353,23 @@ pub fn begin_frame(mut frame_stream: ResMut<OxrFrameStream>) {
|
||||
|
||||
pub fn release_image(mut swapchain: ResMut<OxrSwapchain>) {
|
||||
let _span = info_span!("xr_release_image");
|
||||
#[cfg(target_os = "android")]
|
||||
{
|
||||
let ctx = ndk_context::android_context();
|
||||
let vm = unsafe { jni::JavaVM::from_raw(ctx.vm().cast()) }.unwrap();
|
||||
let env = vm.attach_current_thread_as_daemon();
|
||||
}
|
||||
swapchain.release_image().unwrap();
|
||||
}
|
||||
|
||||
pub fn end_frame(world: &mut World) {
|
||||
let _span = info_span!("xr_end_frame");
|
||||
#[cfg(target_os = "android")]
|
||||
{
|
||||
let ctx = ndk_context::android_context();
|
||||
let vm = unsafe { jni::JavaVM::from_raw(ctx.vm().cast()) }.unwrap();
|
||||
let env = vm.attach_current_thread_as_daemon();
|
||||
}
|
||||
world.resource_scope::<OxrFrameStream, ()>(|world, mut frame_stream| {
|
||||
let mut layers = vec![];
|
||||
for layer in world.resource::<OxrRenderLayers>().iter() {
|
||||
|
||||
Reference in New Issue
Block a user