Merge pull request #172 from awtterpip/update_camera_texture_view
Update camera texture view
This commit is contained in:
@@ -64,7 +64,7 @@ pub fn add_xr_plugins<G: PluginGroup>(plugins: G) -> PluginGroupBuilder {
|
||||
.add_before::<RenderPlugin>(OxrInitPlugin::default())
|
||||
.add(OxrEventsPlugin)
|
||||
.add(OxrReferenceSpacePlugin::default())
|
||||
.add(OxrRenderPlugin)
|
||||
.add(OxrRenderPlugin::default())
|
||||
.add(OxrPassthroughPlugin)
|
||||
.add(HandTrackingPlugin::default())
|
||||
.add(XrCameraPlugin)
|
||||
|
||||
@@ -25,7 +25,17 @@ pub struct OxrRenderBegin;
|
||||
#[derive(Debug, Hash, PartialEq, Eq, Clone, Copy, SystemSet)]
|
||||
pub struct OxrRenderEnd;
|
||||
|
||||
pub struct OxrRenderPlugin;
|
||||
pub struct OxrRenderPlugin {
|
||||
pub spawn_cameras: bool,
|
||||
}
|
||||
|
||||
impl Default for OxrRenderPlugin {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
spawn_cameras: true,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Plugin for OxrRenderPlugin {
|
||||
fn build(&self, app: &mut App) {
|
||||
@@ -45,7 +55,12 @@ impl Plugin for OxrRenderPlugin {
|
||||
(
|
||||
wait_frame.run_if(should_run_frame_loop),
|
||||
update_cameras.run_if(should_run_frame_loop),
|
||||
init_views.run_if(resource_added::<OxrSession>),
|
||||
if self.spawn_cameras {
|
||||
init_views::<true>
|
||||
} else {
|
||||
init_views::<false>
|
||||
}
|
||||
.run_if(resource_added::<OxrSession>),
|
||||
)
|
||||
.chain()
|
||||
.in_set(XrHandleEvents::FrameLoop),
|
||||
@@ -129,7 +144,7 @@ pub fn clean_views(
|
||||
}
|
||||
}
|
||||
|
||||
pub fn init_views(
|
||||
pub fn init_views<const SPAWN_CAMERAS: bool>(
|
||||
graphics_info: Res<OxrGraphicsInfo>,
|
||||
mut manual_texture_views: ResMut<ManualTextureViews>,
|
||||
swapchain_images: Res<OxrSwapchainImages>,
|
||||
@@ -142,6 +157,7 @@ pub fn init_views(
|
||||
info!("XrCamera resolution: {}", graphics_info.resolution);
|
||||
let view_handle =
|
||||
add_texture_view(&mut manual_texture_views, temp_tex, &graphics_info, index);
|
||||
if SPAWN_CAMERAS {
|
||||
commands.spawn((
|
||||
Camera {
|
||||
target: RenderTarget::TextureView(view_handle),
|
||||
@@ -151,6 +167,7 @@ pub fn init_views(
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn wait_frame(mut frame_waiter: ResMut<OxrFrameWaiter>, mut commands: Commands) {
|
||||
let state = frame_waiter.wait().expect("Failed to wait frame");
|
||||
@@ -159,10 +176,14 @@ pub fn wait_frame(mut frame_waiter: ResMut<OxrFrameWaiter>, mut commands: Comman
|
||||
|
||||
pub fn update_cameras(
|
||||
frame_state: Res<OxrFrameState>,
|
||||
mut cameras: Query<&mut Camera, With<XrCamera>>,
|
||||
mut cameras: Query<(&mut Camera, &XrCamera)>,
|
||||
) {
|
||||
for (mut camera, xr_camera) in &mut cameras {
|
||||
camera.target =
|
||||
RenderTarget::TextureView(ManualTextureViewHandle(XR_TEXTURE_INDEX + xr_camera.0));
|
||||
}
|
||||
if frame_state.is_changed() {
|
||||
for mut camera in &mut cameras {
|
||||
for (mut camera, _) in &mut cameras {
|
||||
camera.is_active = frame_state.should_render
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user