Skip to content

Commit

Permalink
Merge pull request #130 from Schmarni-Dev/legacy-rc
Browse files Browse the repository at this point in the history
Update Legacy code to bevy 0.14
  • Loading branch information
Schmarni-Dev authored Jul 4, 2024
2 parents d6af90a + 5d916b0 commit 856300b
Show file tree
Hide file tree
Showing 17 changed files with 2,042 additions and 738 deletions.
2,544 changes: 1,922 additions & 622 deletions Cargo.lock

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ repository = "https://github.com/awtterpip/bevy_oxr"

[workspace.dependencies]
eyre = "0.6.2"
bevy = "0.13"
bevy = "0.14.0"
openxr = "0.18"
color-eyre = "0.6.2"

Expand All @@ -36,14 +36,14 @@ bevy.workspace = true
eyre.workspace = true
futures-lite = "2.0.1"
mint = "0.5.9"
wgpu = "0.19"
wgpu-core = { version = "0.19" }
wgpu-hal = "0.19"
wgpu = "0.20"
wgpu-core = "0.21"
wgpu-hal = "0.21"

[target.'cfg(windows)'.dependencies]
openxr = { workspace = true, features = [ "linked", "static", "mint" ] }
winapi = { version = "0.3.9", optional = true }
d3d12 = { version = "0.19", features = ["libloading"], optional = true }
d3d12 = { version = "0.20", features = ["libloading"], optional = true }

[target.'cfg(all(target_family = "unix", not(target_arch = "wasm32")) )'.dependencies]
openxr = { workspace = true, features = [ "mint" ] }
Expand All @@ -68,4 +68,4 @@ debug = true
[package.metadata.docs.rs]
rustdoc-args = ["-Zunstable-options", "--cfg", "docsrs"]
all-features = true
cargo-args = ["-Zunstable-options", "-Zrustdoc-scrape-examples"]
cargo-args = ["-Zunstable-options", "-Zrustdoc-scrape-examples"]
2 changes: 1 addition & 1 deletion examples/android/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ crate-type = ["rlib", "cdylib"]


[dependencies]
bevy = "0.13"
bevy.workspace = true
bevy_oxr.path = "../.."
openxr = { workspace = true, features = ["mint"] }

Expand Down
16 changes: 11 additions & 5 deletions examples/android/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use bevy::color::palettes;
use bevy::diagnostic::{FrameTimeDiagnosticsPlugin, LogDiagnosticsPlugin};
use bevy::prelude::*;
use bevy::transform::components::Transform;
Expand Down Expand Up @@ -44,7 +45,12 @@ fn main() {

fn debug_hand_render(query: Query<&GlobalTransform, With<HandBone>>, mut gizmos: Gizmos) {
for transform in &query {
gizmos.sphere(transform.translation(), Quat::IDENTITY, 0.01, Color::RED);
gizmos.sphere(
transform.translation(),
Quat::IDENTITY,
0.01,
palettes::css::RED,
);
}
}

Expand All @@ -56,21 +62,21 @@ fn setup(
) {
// plane
commands.spawn(PbrBundle {
mesh: meshes.add(Plane3d::new(Vec3::Y)),
material: materials.add(StandardMaterial::from(Color::rgb(0.3, 0.5, 0.3))),
mesh: meshes.add(Plane3d::new(Vec3::Y, Vec2::splat(2.5))),
material: materials.add(StandardMaterial::from(Color::srgb(0.3, 0.5, 0.3))),
..default()
});
// cube
commands.spawn(PbrBundle {
mesh: meshes.add(Cuboid::from_size(Vec3::splat(0.1)).mesh()),
material: materials.add(StandardMaterial::from(Color::rgb(0.8, 0.7, 0.6))),
material: materials.add(StandardMaterial::from(Color::srgb(0.8, 0.7, 0.6))),
transform: Transform::from_xyz(0.0, 0.5, 0.0),
..default()
});
// cube
commands.spawn(PbrBundle {
mesh: meshes.add(Mesh::from(Cuboid::from_size(Vec3::splat(0.1)))),
material: materials.add(StandardMaterial::from(Color::rgb(0.8, 0.0, 0.0))),
material: materials.add(StandardMaterial::from(Color::srgb(0.8, 0.0, 0.0))),
transform: Transform::from_xyz(0.0, 0.5, 1.0),
..default()
});
Expand Down
5 changes: 3 additions & 2 deletions examples/globe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use bevy::prelude::*;
use bevy::render::render_asset::RenderAssetUsages;
use bevy::transform::components::Transform;
use bevy_oxr::graphics::XrAppInfo;
use bevy_oxr::prelude::XrSystems;
use bevy_oxr::resources::XrViews;
use bevy_oxr::xr_input::hands::common::HandInputDebugRenderer;
use bevy_oxr::xr_input::interactions::{
Expand All @@ -29,7 +30,7 @@ fn main() {
})
.add_plugins(LogDiagnosticsPlugin::default())
.add_systems(Startup, setup)
.add_systems(Update, (proto_locomotion, pull_to_ground).chain())
.add_systems(Update, (proto_locomotion, pull_to_ground).chain().xr_only())
.insert_resource(PrototypeLocomotionConfig::default())
.add_systems(Startup, spawn_controllers_example)
.add_plugins(HandInputDebugRenderer)
Expand Down Expand Up @@ -95,7 +96,7 @@ fn setup(
// cube
commands.spawn(PbrBundle {
mesh: meshes.add(Cuboid::from_size(Vec3::splat(0.1)).mesh()),
material: materials.add(StandardMaterial::from(Color::rgb(0.8, 0.7, 0.6))),
material: materials.add(StandardMaterial::from(Color::srgb(0.8, 0.7, 0.6))),
transform: Transform::from_xyz(0.0, 0.5, 0.0),
..default()
});
Expand Down
6 changes: 3 additions & 3 deletions examples/xr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,14 +92,14 @@ fn setup(
) {
// plane
commands.spawn(PbrBundle {
mesh: meshes.add(Plane3d::new(Vec3::Y).mesh()),
material: materials.add(StandardMaterial::from(Color::rgb(0.3, 0.5, 0.3))),
mesh: meshes.add(Plane3d::new(Vec3::Y, Vec2::splat(2.5)).mesh()),
material: materials.add(StandardMaterial::from(Color::srgb(0.3, 0.5, 0.3))),
..default()
});
// cube
commands.spawn(PbrBundle {
mesh: meshes.add(Cuboid::from_size(Vec3::splat(0.1)).mesh()),
material: materials.add(StandardMaterial::from(Color::rgb(0.8, 0.7, 0.6))),
material: materials.add(StandardMaterial::from(Color::srgb(0.8, 0.7, 0.6))),
transform: Transform::from_xyz(0.0, 0.5, 0.0),
..default()
});
Expand Down
10 changes: 0 additions & 10 deletions rust-toolchain.toml

This file was deleted.

10 changes: 6 additions & 4 deletions src/graphics/d3d12.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ use std::sync::{Arc, Mutex};
// use anyhow::Context;
use bevy::math::uvec2;
use bevy::prelude::*;
use bevy::render::renderer::{RenderAdapter, RenderAdapterInfo, RenderDevice, RenderQueue};
use bevy::render::renderer::{
RenderAdapter, RenderAdapterInfo, RenderDevice, RenderQueue, WgpuWrapper,
};
use bevy::window::RawHandleWrapper;
use eyre::{Context, ContextCompat};
use openxr as xr;
Expand Down Expand Up @@ -203,9 +205,9 @@ pub fn initialize_xr_instance(
}),
blend_mode.into(),
wgpu_device.into(),
RenderQueue(wgpu_queue.into()),
RenderAdapterInfo(wgpu_adapter.get_info()),
RenderAdapter(wgpu_adapter.into()),
RenderQueue(Arc::new(WgpuWrapper::new(wgpu_queue))),
RenderAdapterInfo(WgpuWrapper::new(wgpu_adapter.get_info())),
RenderAdapter(Arc::new(WgpuWrapper::new(wgpu_adapter))),
wgpu_instance.into(),
))
}
Expand Down
6 changes: 4 additions & 2 deletions src/graphics/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@ mod d3d12;
#[cfg(feature = "vulkan")]
mod vulkan;

use std::sync::Arc;

use bevy::ecs::query::With;
use bevy::ecs::system::{Query, SystemState};
use bevy::ecs::world::World;
use bevy::render::renderer::{
RenderAdapter, RenderAdapterInfo, RenderDevice, RenderInstance, RenderQueue,
RenderAdapter, RenderAdapterInfo, RenderDevice, RenderInstance, RenderQueue, WgpuWrapper,
};
use bevy::window::{PrimaryWindow, RawHandleWrapper};
use wgpu::Instance;
Expand Down Expand Up @@ -228,7 +230,7 @@ pub fn try_full_init(
render_queue,
render_adapter_info,
render_adapter,
RenderInstance(wgpu_instance.into()),
RenderInstance(Arc::new(WgpuWrapper::new(wgpu_instance))),
))
}

Expand Down
10 changes: 6 additions & 4 deletions src/graphics/vulkan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ use std::sync::{Arc, Mutex};
use ash::vk::{self, Handle};
use bevy::math::uvec2;
use bevy::prelude::*;
use bevy::render::renderer::{RenderAdapter, RenderAdapterInfo, RenderDevice, RenderQueue};
use bevy::render::renderer::{
RenderAdapter, RenderAdapterInfo, RenderDevice, RenderQueue, WgpuWrapper,
};
use bevy::window::RawHandleWrapper;
use eyre::{Context, ContextCompat};
use openxr as xr;
Expand Down Expand Up @@ -304,9 +306,9 @@ pub fn initialize_xr_instance(
}),
blend_mode.into(),
wgpu_device.into(),
RenderQueue(wgpu_queue.into()),
RenderAdapterInfo(wgpu_adapter.get_info()),
RenderAdapter(wgpu_adapter.into()),
RenderQueue(Arc::new(WgpuWrapper::new(wgpu_queue))),
RenderAdapterInfo(WgpuWrapper::new(wgpu_adapter.get_info())),
RenderAdapter(Arc::new(WgpuWrapper::new(wgpu_adapter))),
wgpu_instance.into(),
))
}
Expand Down
9 changes: 5 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ pub mod xr_init;
pub mod xr_input;

use std::sync::atomic::AtomicBool;
use std::sync::Arc;

use crate::xr_init::{StartXrSession, XrInitPlugin};
use crate::xr_input::oculus_touch::ActionSets;
Expand All @@ -18,7 +19,7 @@ use bevy::ecs::system::SystemState;
use bevy::prelude::*;
use bevy::render::camera::{ManualTextureView, ManualTextureViewHandle, ManualTextureViews};
use bevy::render::pipelined_rendering::PipelinedRenderingPlugin;
use bevy::render::renderer::{render_system, RenderInstance};
use bevy::render::renderer::{render_system, RenderInstance, WgpuWrapper};
use bevy::render::settings::RenderCreation;
use bevy::render::{Render, RenderApp, RenderPlugin, RenderSet};
use bevy::window::{PresentMode, PrimaryWindow, RawHandleWrapper};
Expand Down Expand Up @@ -61,8 +62,8 @@ impl Plugin for OpenXrPlugin {
#[cfg(not(target_arch = "wasm32"))]
match graphics::initialize_xr_instance(
&self.backend_preference,
SystemState::<Query<&RawHandleWrapper, With<PrimaryWindow>>>::new(&mut app.world)
.get(&app.world)
SystemState::<Query<&RawHandleWrapper, With<PrimaryWindow>>>::new(app.world_mut())
.get(&app.world())
.get_single()
.ok()
.cloned(),
Expand All @@ -89,7 +90,7 @@ impl Plugin for OpenXrPlugin {
app.insert_resource(xr_instance);
app.insert_resource(blend_mode);
app.insert_non_send_resource(oxr_session_setup_info);
let render_instance = RenderInstance(instance.into());
let render_instance = RenderInstance(Arc::new(WgpuWrapper::new(instance)));
app.insert_resource(render_instance.clone());
app.add_plugins(RenderPlugin {
render_creation: RenderCreation::Manual(
Expand Down
8 changes: 3 additions & 5 deletions src/passthrough.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use bevy::color::palettes;
use bevy::render::extract_resource::ExtractResource;
use bevy::{prelude::*, render::extract_resource::ExtractResourcePlugin};
use std::{marker::PhantomData, mem, ptr};
Expand Down Expand Up @@ -88,10 +89,7 @@ fn resume_passthrough(
warn!("Unable to resume Passthrough: {}", e);
return;
}
clear_color.set_a(0.0);
clear_color.set_r(0.0);
clear_color.set_g(0.0);
clear_color.set_b(0.0);
**clear_color = Srgba::NONE.into();
*state = XrPassthroughState::Running;
}
fn pause_passthrough(
Expand All @@ -103,7 +101,7 @@ fn pause_passthrough(
warn!("Unable to resume Passthrough: {}", e);
return;
}
clear_color.set_a(1.0);
clear_color.set_alpha(1.0);
*state = XrPassthroughState::Paused;
}

Expand Down
Loading

0 comments on commit 856300b

Please sign in to comment.