pull changes from webxr-refactor
Signed-off-by: Schmarni <marnistromer@gmail.com>
This commit is contained in:
@@ -40,7 +40,7 @@ fn spawn_default_hands(
|
||||
session: Res<OxrSession>,
|
||||
root: Query<Entity, With<OxrTrackingRoot>>,
|
||||
) {
|
||||
dbg!("spawning default hands");
|
||||
debug!("spawning default hands");
|
||||
let Ok(root) = root.get_single() else {
|
||||
error!("unable to get tracking root, skipping hand creation");
|
||||
return;
|
||||
@@ -118,7 +118,7 @@ fn clean_up_default_hands(
|
||||
query: Query<Entity, Or<(With<DefaultHandTracker>, With<DefaultHandBone>)>>,
|
||||
) {
|
||||
for e in &query {
|
||||
dbg!("removing default hand entity");
|
||||
debug!("removing default hand entity");
|
||||
cmds.entity(e).despawn_recursive();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -511,7 +511,6 @@ pub fn poll_events(
|
||||
SessionState::IDLE => {
|
||||
if *status == XrStatus::Available {
|
||||
session_status_events.send(OxrSessionStatusEvent::Created);
|
||||
info!("sending create info");
|
||||
}
|
||||
XrStatus::Idle
|
||||
}
|
||||
@@ -522,7 +521,6 @@ pub fn poll_events(
|
||||
SessionState::STOPPING => XrStatus::Stopping,
|
||||
SessionState::EXITING | SessionState::LOSS_PENDING => {
|
||||
session_status_events.send(OxrSessionStatusEvent::AboutToBeDestroyed);
|
||||
info!("sending destroy info");
|
||||
XrStatus::Exiting
|
||||
}
|
||||
_ => unreachable!(),
|
||||
@@ -557,5 +555,4 @@ pub fn destroy_xr_session_render(world: &mut World) {
|
||||
world.run_system_once(apply_deferred);
|
||||
world.remove_resource::<OxrSession>();
|
||||
world.insert_resource(OxrSessionStarted(false));
|
||||
info!("Render App destroy");
|
||||
}
|
||||
|
||||
@@ -1,13 +1,15 @@
|
||||
use bevy::{
|
||||
ecs::query::QuerySingleError,
|
||||
app::{MainScheduleOrder, SubApp},
|
||||
ecs::{query::QuerySingleError, schedule::MainThreadExecutor},
|
||||
prelude::*,
|
||||
render::{
|
||||
camera::{ManualTextureView, ManualTextureViewHandle, ManualTextureViews, RenderTarget},
|
||||
extract_resource::ExtractResourcePlugin,
|
||||
pipelined_rendering::PipelinedRenderingPlugin,
|
||||
pipelined_rendering::{PipelinedRenderingPlugin, RenderAppChannels, RenderExtractApp},
|
||||
view::ExtractedView,
|
||||
Render, RenderApp, RenderSet,
|
||||
},
|
||||
tasks::ComputeTaskPool,
|
||||
transform::TransformSystem,
|
||||
};
|
||||
use bevy_xr::{
|
||||
@@ -35,6 +37,20 @@ impl Plugin for OxrRenderPlugin {
|
||||
fn build(&self, app: &mut App) {
|
||||
if app.is_plugin_added::<PipelinedRenderingPlugin>() {
|
||||
app.init_resource::<Pipelined>();
|
||||
|
||||
let mut schedule_order = app.world.resource_mut::<MainScheduleOrder>();
|
||||
|
||||
if let Some(pos) = schedule_order
|
||||
.labels
|
||||
.iter()
|
||||
.position(|label| (**label).eq(&OxrLast))
|
||||
{
|
||||
schedule_order.labels.remove(pos);
|
||||
}
|
||||
|
||||
if let Some(sub_app) = app.remove_sub_app(RenderExtractApp) {
|
||||
app.insert_sub_app(RenderExtractApp, SubApp::new(sub_app.app, update_rendering));
|
||||
}
|
||||
}
|
||||
|
||||
app.add_plugins((
|
||||
@@ -82,11 +98,6 @@ impl Plugin for OxrRenderPlugin {
|
||||
)
|
||||
.add_systems(Last, wait_frame.run_if(session_started));
|
||||
app.sub_app_mut(RenderApp)
|
||||
.add_systems(
|
||||
Render,
|
||||
(|q: Query<&XrCamera>| info!("cams render: {}", q.iter().len()))
|
||||
.in_set(OxrRenderBegin),
|
||||
)
|
||||
.add_systems(
|
||||
Render,
|
||||
(
|
||||
@@ -108,13 +119,13 @@ impl Plugin for OxrRenderPlugin {
|
||||
.in_set(OxrRenderEnd),
|
||||
)
|
||||
.insert_resource(OxrRenderLayers(vec![Box::new(ProjectionLayer)]));
|
||||
// .add_systems(
|
||||
// XrSessionExiting,
|
||||
// (
|
||||
// |mut cmds: Commands| cmds.remove_resource::<OxrRenderLayers>(),
|
||||
// clean_views,
|
||||
// ),
|
||||
// );
|
||||
// .add_systems(
|
||||
// XrSessionExiting,
|
||||
// (
|
||||
// |mut cmds: Commands| cmds.remove_resource::<OxrRenderLayers>(),
|
||||
// clean_views,
|
||||
// ),
|
||||
// );
|
||||
|
||||
// app.add_systems(
|
||||
// PreUpdate,
|
||||
@@ -158,6 +169,31 @@ impl Plugin for OxrRenderPlugin {
|
||||
}
|
||||
}
|
||||
|
||||
// This function waits for the rendering world to be received,
|
||||
// runs extract, and then sends the rendering world back to the render thread.
|
||||
//
|
||||
// modified pipelined rendering extract function
|
||||
fn update_rendering(app_world: &mut World, _sub_app: &mut App) {
|
||||
app_world.resource_scope(|world, main_thread_executor: Mut<MainThreadExecutor>| {
|
||||
world.resource_scope(|world, mut render_channels: Mut<RenderAppChannels>| {
|
||||
// we use a scope here to run any main thread tasks that the render world still needs to run
|
||||
// while we wait for the render world to be received.
|
||||
let mut render_app = ComputeTaskPool::get()
|
||||
.scope_with_executor(true, Some(&*main_thread_executor.0), |s| {
|
||||
s.spawn(async { render_channels.recv().await });
|
||||
})
|
||||
.pop()
|
||||
.unwrap();
|
||||
|
||||
world.run_schedule(OxrLast);
|
||||
|
||||
render_app.extract(world);
|
||||
|
||||
render_channels.send_blocking(render_app);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
pub const XR_TEXTURE_INDEX: u32 = 3383858418;
|
||||
|
||||
pub fn clean_views(
|
||||
@@ -168,7 +204,6 @@ pub fn clean_views(
|
||||
for (e, cam) in &cam_query {
|
||||
manual_texture_views.remove(&ManualTextureViewHandle(XR_TEXTURE_INDEX + cam.0));
|
||||
commands.entity(e).despawn_recursive();
|
||||
info!("removing cam")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -74,7 +74,6 @@ fn run_session_status_schedules(world: &mut World) {
|
||||
world.run_schedule(XrSessionExiting);
|
||||
world.run_system_once(apply_deferred);
|
||||
world.remove_resource::<OxrSession>();
|
||||
info!("Main App destroy");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user