From 925eb52500233bb0cdd7bcc5d19ddd18bda16a41 Mon Sep 17 00:00:00 2001 From: Schmarni Date: Fri, 5 Jul 2024 01:34:55 +0200 Subject: [PATCH] forgot examples Signed-off-by: Schmarni --- examples/android/.gitignore | 3 - examples/android/Cargo.toml | 69 -- examples/android/README.md | 67 -- examples/android/hotham_examples.keystore | Bin 2726 -> 0 bytes examples/android/manifest.yaml | 39 -- examples/android/src/lib.rs | 130 ---- examples/demo/Cargo.toml | 15 - examples/demo/Readme.md | 11 - examples/demo/manifest.yaml | 39 -- examples/demo/src/lib.rs | 771 ---------------------- examples/demo/src/main.rs | 3 - examples/demo/src/setup.rs | 81 --- examples/globe.rs | 187 ------ examples/xr.rs | 252 ------- 14 files changed, 1667 deletions(-) delete mode 100644 examples/android/.gitignore delete mode 100644 examples/android/Cargo.toml delete mode 100644 examples/android/README.md delete mode 100644 examples/android/hotham_examples.keystore delete mode 100644 examples/android/manifest.yaml delete mode 100644 examples/android/src/lib.rs delete mode 100644 examples/demo/Cargo.toml delete mode 100644 examples/demo/Readme.md delete mode 100644 examples/demo/manifest.yaml delete mode 100644 examples/demo/src/lib.rs delete mode 100644 examples/demo/src/main.rs delete mode 100644 examples/demo/src/setup.rs delete mode 100644 examples/globe.rs delete mode 100644 examples/xr.rs diff --git a/examples/android/.gitignore b/examples/android/.gitignore deleted file mode 100644 index d74eb91..0000000 --- a/examples/android/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -/target -/Cargo.lock -/runtime_libs diff --git a/examples/android/Cargo.toml b/examples/android/Cargo.toml deleted file mode 100644 index 1257a5d..0000000 --- a/examples/android/Cargo.toml +++ /dev/null @@ -1,69 +0,0 @@ -[package] -name = "bevy_openxr_android" -version = "0.1.0" -description = "Example for building an Android OpenXR app with Bevy" -edition.workspace = true -license.workspace = true -publish = false - -[lib] -name = "bevy_openxr_android" -crate-type = ["rlib", "cdylib"] - - -[dependencies] -bevy.workspace = true -bevy_oxr.path = "../.." -openxr = { workspace = true, features = ["mint"] } - -# [profile.release] -# lto = "fat" -# codegen-units = 1 -# panic = "abort" - -# This metadata is used by `cargo-apk` - `xbuild` uses the `manifest.yaml` instead. -[package.metadata.android] -package = "org.bevyengine.example_openxr_android" -build_targets = ["aarch64-linux-android"] -runtime_libs = "runtime_libs" -apk_name = "bevyopenxr" -# assets = "assets" -# res = "assets/android-res" -icon = "@mipmap/ic_launcher" -label = "Bevy Openxr Android" -strip = "strip" - -# [package.metadata.android.application] -# icon = "@mipmap/ic_launcher" -# label = "Bevy Example" - -[package.metadata.android.sdk] -target_sdk_version = 32 - -[package.metadata.android.application.activity] -theme = "@android:style/Theme.Black.NoTitleBar.Fullscreen" -config_changes = "density|keyboard|keyboardHidden|navigation|orientation|screenLayout|screenSize|uiMode" -launch_mode = "singleTask" -orientation = "landscape" -resizeable_activity = false - -[[package.metadata.android.application.activity.intent_filter]] -actions = ["android.intent.action.MAIN"] -categories = [ - "com.oculus.intent.category.VR", - "android.intent.category.LAUNCHER", -] - -# !! IMPORTANT !! -# -# When creating your own apps, make sure to generate your own keystore, rather than using our example one! -# You can use `keytool` like so: -# keytool -genkey -v -keystore my-release-key.keystore -keyalg RSA -keysize 2048 -validity 10000 -# -# For more information on key signing and why it's so important, check out this article: -# https://developer.android.com/studio/publish/app-signing -# -# !! IMPORTANT !! -[package.metadata.android.signing.release] -path = "./hotham_examples.keystore" -keystore_password = "chomsky-vigilant-spa" diff --git a/examples/android/README.md b/examples/android/README.md deleted file mode 100644 index d8a7890..0000000 --- a/examples/android/README.md +++ /dev/null @@ -1,67 +0,0 @@ -# Bevy OpenXR Android example - -## Setup -Get libopenxr_loader.so from the Oculus OpenXR Mobile SDK and add it to `examples/android/runtime_libs/arm64-v8a` -https://developer.oculus.com/downloads/package/oculus-openxr-mobile-sdk/ -`examples/android/runtime_libs/arm64-v8a/libopenxr_loader.so` - -Also, install either `cargo-apk` (marked as deprecated): -```sh -cargo install cargo-apk -``` -or, install `xbuild` as it supersedes `cargo-apk`. Note that the `--git` is -very important here. -```sh -cargo install --git https://github.com/rust-mobile/xbuild -``` - -## Run -Running on Meta Quest can be done with https://github.com/rust-mobile/cargo-apk. -```sh -cargo apk run --release -``` -But cargo-apk is deprecated in favour of xbuild https://github.com/rust-mobile/xbuild. -```sh -# List devices and copy device string "adb:***" -x devices - -# Run on this device -x run --release --device adb:*** -``` -There is [manifest.yaml](./manifest.yaml) example required by xbuild. -Interface for this manifest can be found as AndroidConfig struct in https://github.com/rust-mobile/xbuild/blob/master/xbuild/src/config.rs - -## Notes - -### Relase mode -More optimisations enabled in Cargo.toml for the release mode. -This gives more performance but longer build time. -```toml -[profile.release] -lto = "fat" -codegen-units = 1 -panic = "abort" -``` - -### Cargo apk -If you see error like `Error: String `` is not a PID`, try to install cargo apk with a fix in branch. -```sh -cargo install --git https://github.com/rust-mobile/cargo-apk --branch=adb-logcat-uid -``` - -### Temporary JNIEnv log -This message is logged every frame. It's not yet fixed. -```sh -I JniUtils-inl: Creating temporary JNIEnv. This is a heavy operation and should be infrequent. To optimize, use JNI AttachCurrentThread on calling threa -``` - -### Android keystore -Release mode requires keystore. See Cargo.toml `package.metadata.android.signing.release`. - -When creating your own apps, make sure to generate your own keystore, rather than using our example one! -You can use `keytool` like so: -```sh -keytool -genkey -v -keystore my-release-key.keystore -keyalg RSA -keysize 2048 -validity 10000 -``` -For more information on key signing and why it's so important, check out this article: -https://developer.android.com/studio/publish/app-signing diff --git a/examples/android/hotham_examples.keystore b/examples/android/hotham_examples.keystore deleted file mode 100644 index 62623c4d30c143b63d33e39fb5b742e403ab5dbe..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 2726 zcma);X*d*&7RSw)F&QTNPWG{;A&gy8Ov@xo)~sPLC`ooPWZo%DO~^7agb}iDiO3Ae z*q2wb=M~vPmJ#u~&%ICYb3fht;XLO#|NlAvkH6<2aL_y;fEj^)FgNfn5tDuCW)eGgM+82s7YPHqX z-axl;h)26#Q-b?aD?$&p>B5iAbzYn1SUApC6W7--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z&-Am0fb_-lI29TVgj+XZDqH7>XzJ zcf40O0$6tV0tEaxq32DhuR`_IZb(?RK9wF?lZmzPm~Pr@E41>x^hXiPSgNt66RF!I zugi1zl(nnQV!&GdY>M*gM6zOp>)}}$=|)d?j6~m=o-xQ0h4p)n$^@tQ+`bb)6;q|O zRru4}uZNlQv9WMe&t=I|G-(g+x)8y|nUT%Q?J%A#wc)#6bqF*<6#@JGy8!`UCXfUd zzA&{#$jFMr>l>, mut gizmos: Gizmos) { - for transform in &query { - gizmos.sphere( - transform.translation(), - Quat::IDENTITY, - 0.01, - palettes::css::RED, - ); - } -} - -/// set up a simple 3D scene -fn setup( - mut commands: Commands, - mut meshes: ResMut>, - mut materials: ResMut>, -) { - // plane - commands.spawn(PbrBundle { - 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::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::srgb(0.8, 0.0, 0.0))), - transform: Transform::from_xyz(0.0, 0.5, 1.0), - ..default() - }); - // light - commands.spawn(PointLightBundle { - point_light: PointLight { - intensity: 1500.0, - shadows_enabled: true, - ..default() - }, - transform: Transform::from_xyz(4.0, 8.0, 4.0), - ..default() - }); -} - -fn spawn_controllers_example(mut commands: Commands) { - //left hand - commands.spawn(( - OpenXRLeftController, - OpenXRController, - OpenXRTracker, - SpatialBundle::default(), - )); - //right hand - commands.spawn(( - OpenXRRightController, - OpenXRController, - OpenXRTracker, - SpatialBundle::default(), - )); -} - -// TODO: make this a vr button -fn toggle_passthrough( - keys: Res>, - passthrough_state: Res, - mut resume: EventWriter, - mut pause: EventWriter, -) { - if keys.just_pressed(KeyCode::Space) { - match *passthrough_state { - XrPassthroughState::Unsupported => {} - XrPassthroughState::Running => { - pause.send_default(); - } - XrPassthroughState::Paused => { - resume.send_default(); - } - } - } -} diff --git a/examples/demo/Cargo.toml b/examples/demo/Cargo.toml deleted file mode 100644 index 31f7bca..0000000 --- a/examples/demo/Cargo.toml +++ /dev/null @@ -1,15 +0,0 @@ -[package] -name = "demo" -version = "0.1.0" -description = "Demo using bevy_oxr" -edition.workspace = true -publish = false - -[lib] -crate-type = ["rlib", "cdylib"] - -[dependencies] -bevy.workspace = true -bevy_oxr.path = "../../" -bevy_rapier3d = "0.25" -color-eyre.workspace = true diff --git a/examples/demo/Readme.md b/examples/demo/Readme.md deleted file mode 100644 index 6b16a29..0000000 --- a/examples/demo/Readme.md +++ /dev/null @@ -1,11 +0,0 @@ -## setup -install xbuild ```cargo install --git https://github.com/rust-mobile/xbuild``` -run ```x doctor``` and install all required depencencies -download the [openxr loader](https://developer.oculus.com/downloads/package/oculus-openxr-mobile-sdk/) and put it in the runtime_libs/arm64-v8a folder - -## how to run -run ```x devices``` - -and get the device name that looks something like this ```adb:1WD523S``` (probably a bit longer) - -then ```run x run --release``` diff --git a/examples/demo/manifest.yaml b/examples/demo/manifest.yaml deleted file mode 100644 index d4085c4..0000000 --- a/examples/demo/manifest.yaml +++ /dev/null @@ -1,39 +0,0 @@ -android: - runtime_libs: - - "runtime_libs" - manifest: - package: "org.bevyengine.demo_openxr_android" - uses_feature: - - name: "android.hardware.vr.headtracking" - required: true - - name: "oculus.software.handtracking" - required: true - - name: "com.oculus.feature.PASSTHROUGH" - required: true - - name: "com.oculus.experimental.enabled" - required: true - uses_permission: - - name: "com.oculus.permission.HAND_TRACKING" - application: - label: "Bevy Openxr Android" - theme: "@android:style/Theme.DeviceDefault.NoActionBar.Fullscreen" - meta_data: - - name: "com.oculus.intent.category.VR" - value: "vr_only" - - name: "com.samsung.android.vr.application.mode" - value: "vr_only" - - name: "com.oculus.supportedDevices" - value: "quest|quest2|quest3|questpro" - activities: - - config_changes: "density|keyboard|keyboardHidden|navigation|orientation|screenLayout|screenSize|uiMode|screenLayout" - launch_mode: "singleTask" - orientation: "landscape" - intent_filters: - - actions: - - "android.intent.action.MAIN" - categories: - - "com.oculus.intent.category.VR" - - "android.intent.category.LAUNCHER" - - "org.khronos.openxr.intent.category.IMMERSIVE_HMD" - sdk: - target_sdk_version: 32 diff --git a/examples/demo/src/lib.rs b/examples/demo/src/lib.rs deleted file mode 100644 index 05d96d8..0000000 --- a/examples/demo/src/lib.rs +++ /dev/null @@ -1,771 +0,0 @@ -mod setup; - -use std::time::Duration; - -use bevy::{ - diagnostic::{FrameTimeDiagnosticsPlugin, LogDiagnosticsPlugin}, - ecs::schedule::ScheduleLabel, - log::info, - math::primitives::{Capsule3d, Cuboid}, - prelude::{ - bevy_main, default, App, Assets, Color, Commands, Component, Entity, Event, EventReader, - EventWriter, FixedUpdate, GlobalTransform, IntoSystemConfigs, IntoSystemSetConfigs, Mesh, - PbrBundle, PostUpdate, Query, Res, ResMut, Resource, Schedule, SpatialBundle, - StandardMaterial, Startup, Transform, Update, Vec3, With, Without, World, - }, - render::mesh::Meshable, - time::{Fixed, Time, Timer, TimerMode}, - transform::TransformSystem, -}; -use bevy_oxr::{ - graphics::{extensions::XrExtensions, XrAppInfo}, - input::XrInput, - resources::{XrFrameState, XrSession}, - xr_init::xr_only, - xr_input::{ - actions::XrActionSets, - debug_gizmos::OpenXrDebugRenderer, - hands::common::{HandInputDebugRenderer, HandResource, HandsResource}, - hands::HandBone, - interactions::{ - draw_interaction_gizmos, draw_socket_gizmos, interactions, socket_interactions, - update_interactable_states, InteractionEvent, Touched, XRDirectInteractor, - XRInteractable, XRInteractableState, XRInteractorState, XRSelection, - }, - oculus_touch::OculusController, - prototype_locomotion::{proto_locomotion, PrototypeLocomotionConfig}, - trackers::{OpenXRController, OpenXRLeftController, OpenXRRightController, OpenXRTracker}, - Hand, - }, - DefaultXrPlugins, -}; - -use crate::setup::setup_scene; -use bevy_rapier3d::prelude::*; - -#[bevy_main] -pub fn main() { - color_eyre::install().unwrap(); - - info!("Running bevy_openxr demo"); - let mut app = App::new(); - let mut xr_extensions = XrExtensions::default(); - xr_extensions.enable_fb_passthrough(); - - app - //lets get the usual diagnostic stuff added - .add_plugins(LogDiagnosticsPlugin::default()) - .add_plugins(FrameTimeDiagnosticsPlugin) - //lets get the xr defaults added - .add_plugins(DefaultXrPlugins { - reqeusted_extensions: xr_extensions, - app_info: XrAppInfo { - name: "Bevy OXR Demo".into(), - }, - ..Default::default() - }) - //lets add the debug renderer for the controllers - .add_plugins(OpenXrDebugRenderer) - //rapier goes here - .add_plugins(RapierPhysicsPlugin::::default().with_default_system_setup(false)) - // .add_plugins(RapierDebugRenderPlugin::default()) - //lets setup the starting scene - .add_systems(Startup, setup_scene) - .add_systems(Startup, spawn_controllers_example) //you need to spawn controllers or it crashes TODO:: Fix this - //add locomotion - .add_systems(Update, proto_locomotion.run_if(xr_only())) - .insert_resource(PrototypeLocomotionConfig::default()) - //lets add the interaction systems - .add_event::() - .add_systems(Update, prototype_interaction_input.run_if(xr_only())) - .add_systems(Update, interactions.before(update_interactable_states)) - .add_systems(Update, update_interactable_states) - .add_systems( - Update, - socket_interactions.before(update_interactable_states), - ) - //add the grabbable system - .add_systems(Update, update_grabbables.after(update_interactable_states)) - //draw the interaction gizmos - .add_systems( - Update, - draw_interaction_gizmos - .run_if(xr_only()) - .after(update_interactable_states), - ) - .add_systems(Update, draw_socket_gizmos.after(update_interactable_states)) - //add our cube spawning system - .add_event::() - .insert_resource(SpawnCubeTimer(Timer::from_seconds( - 0.25, - bevy::time::TimerMode::Once, - ))) - .add_systems(Update, request_cube_spawn.run_if(xr_only())) - .add_systems(Update, cube_spawner.after(request_cube_spawn)) - //test capsule - .add_systems(Startup, spawn_capsule) - //physics hands - // .add_plugins(OpenXrHandInput) - .add_plugins(HandInputDebugRenderer) - .add_systems(Startup, spawn_physics_hands) - .add_systems( - FixedUpdate, - update_physics_hands.before(PhysicsSet::SyncBackend), - ) - .add_event::() - .add_systems(Update, handle_ghost_hand_events.after(update_grabbables)) - .insert_resource(GhostTimers { - left: Timer::from_seconds(0.25, TimerMode::Once), - right: Timer::from_seconds(0.25, TimerMode::Once), - }) - .add_systems(Update, watch_ghost_timers.before(handle_ghost_hand_events)); - - //configure rapier sets - let mut physics_schedule = Schedule::new(PhysicsSchedule); - - physics_schedule.configure_sets( - ( - PhysicsSet::SyncBackend, - PhysicsSet::StepSimulation, - PhysicsSet::Writeback, - ) - .chain() - .before(TransformSystem::TransformPropagate), - ); - - app.configure_sets( - PostUpdate, - ( - PhysicsSet::SyncBackend, - PhysicsSet::StepSimulation, - PhysicsSet::Writeback, - ) - .chain() - .before(TransformSystem::TransformPropagate), - ); - //add rapier systems - physics_schedule.add_systems(( - RapierPhysicsPlugin::::get_systems(PhysicsSet::SyncBackend) - .in_set(PhysicsSet::SyncBackend), - RapierPhysicsPlugin::::get_systems(PhysicsSet::StepSimulation) - .in_set(PhysicsSet::StepSimulation), - RapierPhysicsPlugin::::get_systems(PhysicsSet::Writeback) - .in_set(PhysicsSet::Writeback), - )); - app.add_schedule(physics_schedule) // configure our fixed timestep schedule to run at the rate we want - .insert_resource(Time::::from_duration(Duration::from_secs_f32( - FIXED_TIMESTEP, - ))) - .add_systems(FixedUpdate, run_physics_schedule) - .add_systems(Startup, configure_physics); - app.run(); -} - -//fixed timesteps? -const FIXED_TIMESTEP: f32 = 1. / 90.; - -// A label for our new Schedule! -#[derive(ScheduleLabel, Debug, Hash, PartialEq, Eq, Clone)] -struct PhysicsSchedule; - -fn run_physics_schedule(world: &mut World) { - world.run_schedule(PhysicsSchedule); -} - -fn configure_physics(mut rapier_config: ResMut) { - rapier_config.timestep_mode = TimestepMode::Fixed { - dt: FIXED_TIMESTEP, - substeps: 1, - } -} - -fn spawn_controllers_example(mut commands: Commands) { - //left hand - commands.spawn(( - OpenXRLeftController, - OpenXRController, - OpenXRTracker, - SpatialBundle::default(), - XRDirectInteractor, - XRInteractorState::default(), - XRSelection::default(), - Hand::Left, - )); - //right hand - commands.spawn(( - OpenXRRightController, - OpenXRController, - OpenXRTracker, - SpatialBundle::default(), - XRDirectInteractor, - XRInteractorState::default(), - XRSelection::default(), - Hand::Right, - )); -} - -fn spawn_capsule( - mut commands: Commands, - mut meshes: ResMut>, - mut materials: ResMut>, -) { - commands.spawn(( - PbrBundle { - mesh: meshes.add(Capsule3d::new(0.033, 0.115).mesh()), - material: materials.add(StandardMaterial::from(Color::rgb(0.8, 0.7, 0.6))), - transform: Transform::from_xyz(0.0, 2.0, 0.0), - ..default() - }, - // Collider::capsule_y(0.0575, 0.034), - Collider::capsule( - Vec3 { - x: 0.0, - y: -0.0575, - z: 0.0, - }, - Vec3 { - x: 0.0, - y: 0.0575, - z: 0.0, - }, - 0.034, - ), - RigidBody::Dynamic, - )); -} - -#[derive(Component, PartialEq, Debug, Clone, Copy)] -pub enum PhysicsHandBone { - Palm, - Wrist, - ThumbMetacarpal, - ThumbProximal, - ThumbDistal, - ThumbTip, - IndexMetacarpal, - IndexProximal, - IndexIntermediate, - IndexDistal, - IndexTip, - MiddleMetacarpal, - MiddleProximal, - MiddleIntermediate, - MiddleDistal, - MiddleTip, - RingMetacarpal, - RingProximal, - RingIntermediate, - RingDistal, - RingTip, - LittleMetacarpal, - LittleProximal, - LittleIntermediate, - LittleDistal, - LittleTip, -} -#[derive(Component, PartialEq)] -pub enum BoneInitState { - True, - False, -} - -fn spawn_physics_hands(mut commands: Commands) { - //here we go - let hands = [Hand::Left, Hand::Right]; - let bones = [ - PhysicsHandBone::Palm, - PhysicsHandBone::Wrist, - PhysicsHandBone::ThumbMetacarpal, - PhysicsHandBone::ThumbProximal, - PhysicsHandBone::ThumbDistal, - PhysicsHandBone::ThumbTip, - PhysicsHandBone::IndexMetacarpal, - PhysicsHandBone::IndexProximal, - PhysicsHandBone::IndexIntermediate, - PhysicsHandBone::IndexDistal, - PhysicsHandBone::IndexTip, - PhysicsHandBone::MiddleMetacarpal, - PhysicsHandBone::MiddleProximal, - PhysicsHandBone::MiddleIntermediate, - PhysicsHandBone::MiddleDistal, - PhysicsHandBone::MiddleTip, - PhysicsHandBone::RingMetacarpal, - PhysicsHandBone::RingProximal, - PhysicsHandBone::RingIntermediate, - PhysicsHandBone::RingDistal, - PhysicsHandBone::RingTip, - PhysicsHandBone::LittleMetacarpal, - PhysicsHandBone::LittleProximal, - PhysicsHandBone::LittleIntermediate, - PhysicsHandBone::LittleDistal, - PhysicsHandBone::LittleTip, - ]; - let radius = 0.010; - let left_hand_membership_group = Group::GROUP_1; - let right_hand_membership_group = Group::GROUP_2; - let floor_membership = Group::GROUP_3; - - for hand in hands.iter() { - let hand_membership = match hand { - Hand::Left => left_hand_membership_group, - Hand::Right => right_hand_membership_group, - }; - let mut hand_filter: Group = Group::ALL; - hand_filter.remove(hand_membership); - hand_filter.remove(floor_membership); - for bone in bones.iter() { - //spawn the thing - commands.spawn(( - SpatialBundle::default(), - Collider::capsule( - Vec3 { - x: 0.0, - y: -0.0575, - z: 0.0, - }, - Vec3 { - x: 0.0, - y: 0.0575, - z: 0.0, - }, - radius, - ), - RigidBody::Dynamic, - Velocity::default(), - CollisionGroups::new(hand_membership, Group::from_bits(0b0001).unwrap()), - // SolverGroups::new(self_group, interaction_group), - bone.clone(), - BoneInitState::False, - hand.clone(), - )); - } - } -} - -pub enum MatchingType { - PositionMatching, - VelocityMatching, -} - -fn update_physics_hands( - hands_res: Option>, - mut bone_query: Query<( - &mut Transform, - &mut Collider, - &PhysicsHandBone, - &mut BoneInitState, - &Hand, - &mut Velocity, - )>, - hand_query: Query<(&Transform, &HandBone, &Hand), Without>, - time: Res