0.16 support
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
use std::{any::TypeId, marker::PhantomData};
|
||||
|
||||
use bevy::app::{App, Plugin};
|
||||
use bevy::ecs::system::Resource;
|
||||
use bevy::math::Vec2;
|
||||
use bevy::prelude::Resource;
|
||||
|
||||
pub struct ActionPlugin<A: Action>(PhantomData<A>);
|
||||
|
||||
|
||||
@@ -2,15 +2,15 @@ use core::panic;
|
||||
|
||||
use bevy::app::{App, Plugin, PostUpdate};
|
||||
use bevy::core_pipeline::core_3d::Camera3d;
|
||||
use bevy::ecs::component::{Component, StorageType};
|
||||
use bevy::ecs::component::{Component, HookContext, Mutable, StorageType};
|
||||
use bevy::ecs::reflect::ReflectComponent;
|
||||
use bevy::ecs::schedule::IntoSystemConfigs;
|
||||
use bevy::ecs::world::DeferredWorld;
|
||||
use bevy::math::{Mat4, Vec3A, Vec4};
|
||||
use bevy::pbr::{PbrPlugin, PbrProjectionPlugin};
|
||||
use bevy::prelude::{Projection, SystemSet};
|
||||
use bevy::reflect::std_traits::ReflectDefault;
|
||||
use bevy::reflect::Reflect;
|
||||
use bevy::render::camera::{CameraProjection, CameraProjectionPlugin};
|
||||
use bevy::render::camera::{CameraProjection, CameraProjectionPlugin, CustomProjection};
|
||||
use bevy::render::extract_component::{ExtractComponent, ExtractComponentPlugin};
|
||||
use bevy::render::view::{update_frusta, VisibilitySystems};
|
||||
use bevy::transform::TransformSystem;
|
||||
@@ -21,7 +21,7 @@ pub struct XrCameraPlugin;
|
||||
|
||||
impl Plugin for XrCameraPlugin {
|
||||
fn build(&self, app: &mut App) {
|
||||
app.add_plugins(CameraProjectionPlugin::<XrProjection>::default());
|
||||
/*app.add_plugins(CameraProjectionPlugin::<XrProjection>::default());
|
||||
app.add_systems(
|
||||
PostUpdate,
|
||||
update_frusta::<XrProjection>
|
||||
@@ -30,31 +30,23 @@ impl Plugin for XrCameraPlugin {
|
||||
);
|
||||
if app.is_plugin_added::<PbrPlugin>() {
|
||||
app.add_plugins(PbrProjectionPlugin::<XrProjection>::default());
|
||||
}
|
||||
app.add_plugins((
|
||||
ExtractComponentPlugin::<XrProjection>::default(),
|
||||
ExtractComponentPlugin::<XrCamera>::default(),
|
||||
));
|
||||
}*/
|
||||
app.add_plugins((ExtractComponentPlugin::<XrCamera>::default(),));
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Default, PartialEq, Eq, Debug, Hash, SystemSet)]
|
||||
pub struct XrViewInit;
|
||||
|
||||
#[derive(Debug, Clone, Reflect, ExtractComponent)]
|
||||
#[reflect(Component, Default)]
|
||||
#[derive(Debug, Clone, Reflect)]
|
||||
#[reflect(Default)]
|
||||
pub struct XrProjection {
|
||||
pub projection_matrix: Mat4,
|
||||
pub near: f32,
|
||||
}
|
||||
impl Component for XrProjection {
|
||||
const STORAGE_TYPE: StorageType = StorageType::Table;
|
||||
|
||||
fn register_component_hooks(hooks: &mut bevy::ecs::component::ComponentHooks) {
|
||||
hooks.on_add(|mut world, entity, _| {
|
||||
world.commands().entity(entity).remove::<Projection>();
|
||||
});
|
||||
}
|
||||
fn on_projection_add(mut world: DeferredWorld, HookContext { entity, .. }: HookContext) {
|
||||
world.commands().entity(entity).remove::<Projection>();
|
||||
}
|
||||
|
||||
impl Default for XrProjection {
|
||||
@@ -68,7 +60,7 @@ impl Default for XrProjection {
|
||||
|
||||
/// Marker component for an XR view. It is the backends responsibility to update this.
|
||||
#[derive(Clone, Copy, Component, ExtractComponent, Debug, Default)]
|
||||
#[require(Camera3d, XrProjection, XrTracker)]
|
||||
#[require(Camera3d, XrTracker)]
|
||||
pub struct XrCamera(pub u32);
|
||||
|
||||
impl CameraProjection for XrProjection {
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
use bevy::{
|
||||
ecs::{component::Component, entity::Entity, world::Command},
|
||||
ecs::{component::Component, entity::Entity},
|
||||
log::warn,
|
||||
math::bool,
|
||||
prelude::{Bundle, Commands, Deref, DerefMut, Resource, Transform, Visibility, World},
|
||||
};
|
||||
|
||||
use crate::{session::XrTracker, spaces::XrSpaceLocationFlags};
|
||||
pub const HAND_JOINT_COUNT: usize = 26;
|
||||
|
||||
@@ -181,7 +180,7 @@ pub struct SpawnHandTracker<B: Bundle> {
|
||||
pub side: HandSide,
|
||||
}
|
||||
|
||||
impl<B: Bundle> Command for SpawnHandTracker<B> {
|
||||
impl<B: Bundle> bevy::prelude::Command for SpawnHandTracker<B> {
|
||||
fn apply(self, world: &mut bevy::prelude::World) {
|
||||
let Some(executor) = world.remove_resource::<SpawnHandTrackerCommandExecutor>() else {
|
||||
warn!("no SpawnHandTracker executor defined, skipping handtracker creation");
|
||||
|
||||
@@ -3,8 +3,9 @@ use std::sync::atomic::AtomicBool;
|
||||
use std::sync::Arc;
|
||||
|
||||
use bevy::app::{AppExit, MainScheduleOrder};
|
||||
use bevy::ecs::component::StorageType;
|
||||
use bevy::ecs::component::{HookContext, Mutable, StorageType};
|
||||
use bevy::ecs::schedule::ScheduleLabel;
|
||||
use bevy::ecs::world::DeferredWorld;
|
||||
use bevy::prelude::*;
|
||||
use bevy::render::extract_resource::{ExtractResource, ExtractResourcePlugin};
|
||||
use bevy::render::{Render, RenderApp, RenderSet};
|
||||
@@ -96,26 +97,21 @@ pub struct XrTrackingRoot;
|
||||
struct TrackingRootRes(Entity);
|
||||
|
||||
/// Makes the entity a child of the XrTrackingRoot if the entity has no parent
|
||||
#[derive(Clone, Copy, Hash, PartialEq, Eq, Reflect, Debug, Default)]
|
||||
#[derive(Clone, Copy, Hash, PartialEq, Eq, Reflect, Debug, Default, Component)]
|
||||
#[component(on_add = on_tracker_add)]
|
||||
pub struct XrTracker;
|
||||
impl Component for XrTracker {
|
||||
const STORAGE_TYPE: StorageType = StorageType::SparseSet;
|
||||
|
||||
fn register_component_hooks(hooks: &mut bevy::ecs::component::ComponentHooks) {
|
||||
hooks.on_add(|mut world, entity, _| {
|
||||
if world
|
||||
.entity(entity)
|
||||
.get_components::<Has<Parent>>()
|
||||
.is_some_and(identity)
|
||||
{
|
||||
return;
|
||||
}
|
||||
let Some(root) = world.get_resource::<TrackingRootRes>().map(|r| r.0) else {
|
||||
return;
|
||||
};
|
||||
world.commands().entity(root).add_child(entity);
|
||||
});
|
||||
fn on_tracker_add(mut world: DeferredWorld, HookContext { entity, .. }: HookContext) {
|
||||
if world
|
||||
.entity(entity)
|
||||
.get_components::<Has<Children>>()
|
||||
.is_some_and(identity)
|
||||
{
|
||||
return;
|
||||
}
|
||||
let Some(root) = world.get_resource::<TrackingRootRes>().map(|r| r.0) else {
|
||||
return;
|
||||
};
|
||||
world.commands().entity(root).add_child(entity);
|
||||
}
|
||||
|
||||
pub struct XrSessionPlugin {
|
||||
|
||||
Reference in New Issue
Block a user