Broken commit
This commit is contained in:
commit
4522ee48df
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
/target
|
2647
Cargo.lock
generated
Normal file
2647
Cargo.lock
generated
Normal file
File diff suppressed because it is too large
Load diff
78
Cargo.toml
Normal file
78
Cargo.toml
Normal file
|
@ -0,0 +1,78 @@
|
|||
[package]
|
||||
name = "vr_test"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[lib]
|
||||
crate-type = ["lib", "cdylib"]
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
hotham = { git = "https://github.com/leetvr/hotham" }
|
||||
|
||||
|
||||
[target.'cfg(target_os = "android")'.dependencies]
|
||||
ndk-glue = "0.6"
|
||||
|
||||
|
||||
[[package.metadata.android.uses_permission]]
|
||||
name = "android.permission.INTERNET"
|
||||
|
||||
[[package.metadata.android.uses_permission]]
|
||||
name = "android.permission.ACCESS_NETWORK_STATE"
|
||||
|
||||
[package.metadata.android]
|
||||
apk_label = "Hotham Simple Scene Example"
|
||||
fullscreen = true
|
||||
runtime_libs = "assets/common_lib"
|
||||
target_sdk_version = 29
|
||||
|
||||
[package.metadata.android.application]
|
||||
debuggable = true
|
||||
label = "Hotham Simple Scene Example"
|
||||
theme = "@android:style/Theme.DeviceDefault.NoActionBar.Fullscreen"
|
||||
|
||||
[package.metadata.android.application.activity]
|
||||
config_changes = "screenSize|screenLayout|orientation|keyboardHidden|keyboard|navigation|uiMode"
|
||||
launch_mode = "singleTask"
|
||||
orientation = "landscape"
|
||||
|
||||
[[package.metadata.android.uses_permission]]
|
||||
name = "android.permission.INTERNET"
|
||||
|
||||
[[package.metadata.android.uses_permission]]
|
||||
name = "android.permission.ACCESS_NETWORK_STATE"
|
||||
|
||||
[[package.metadata.android.application.meta_data]]
|
||||
name = "com.oculus.supportedDevices"
|
||||
value = "quest|quest2"
|
||||
|
||||
[[package.metadata.android.application.meta_data]]
|
||||
name = "com.oculus.intent.category.VR"
|
||||
value = "vr_only"
|
||||
|
||||
[[package.metadata.android.application.activity.intent_filter]]
|
||||
actions = ["android.intent.action.MAIN"]
|
||||
categories = [
|
||||
"com.oculus.intent.category.VR",
|
||||
"android.intent.category.LAUNCHER",
|
||||
]
|
||||
|
||||
[[package.metadata.android.application.activity.meta_data]]
|
||||
name = "com.oculus.vr.focusaware"
|
||||
value = "true"
|
||||
|
||||
[[package.metadata.android.uses_feature]]
|
||||
name = "android.hardware.vulkan.level"
|
||||
required = true
|
||||
version = 1
|
||||
|
||||
[[package.metadata.android.uses_feature]]
|
||||
name = "android.hardware.vr.headtracking"
|
||||
required = true
|
||||
version = 1
|
||||
|
||||
[package.metadata.android.signing.release]
|
||||
path = "keys.keystore"
|
||||
keystore_password = "seven!"
|
BIN
assets/common_lib/arm64-v8a/libopenxr_loader.so
Normal file
BIN
assets/common_lib/arm64-v8a/libopenxr_loader.so
Normal file
Binary file not shown.
BIN
assets/damaged_helmet_squished.glb
Normal file
BIN
assets/damaged_helmet_squished.glb
Normal file
Binary file not shown.
BIN
assets/floor.glb
Normal file
BIN
assets/floor.glb
Normal file
Binary file not shown.
BIN
assets/left_hand.glb
Normal file
BIN
assets/left_hand.glb
Normal file
Binary file not shown.
1154
assets/left_hand_skinned_matrices.json
Normal file
1154
assets/left_hand_skinned_matrices.json
Normal file
File diff suppressed because it is too large
Load diff
BIN
assets/right_hand.glb
Normal file
BIN
assets/right_hand.glb
Normal file
Binary file not shown.
1154
assets/right_hand_skinned_matrices.json
Normal file
1154
assets/right_hand_skinned_matrices.json
Normal file
File diff suppressed because it is too large
Load diff
BIN
keys.keystore
Normal file
BIN
keys.keystore
Normal file
Binary file not shown.
17
scripts/run-on-device.sh
Executable file
17
scripts/run-on-device.sh
Executable file
|
@ -0,0 +1,17 @@
|
|||
#!/usr/bin/env bash
|
||||
set -eux
|
||||
|
||||
adb shell am force-stop rust.vr_test
|
||||
|
||||
scriptdir=$(dirname -- "$(realpath -- "$0")")
|
||||
cd $scriptdir/..
|
||||
|
||||
rm -f target/release/apk/lib/arm64-v8a/libc++_shared.so
|
||||
cargo apk run --release --package vr_test
|
||||
# Wait for the app to start
|
||||
for i in 1 2 3 4 5; do
|
||||
adb shell pidof rust.vr_test && break
|
||||
sleep 1
|
||||
done
|
||||
|
||||
adb logcat --pid="$(adb shell pidof rust.vr_test)"
|
85
shell.nix
Normal file
85
shell.nix
Normal file
|
@ -0,0 +1,85 @@
|
|||
{ pkgs ? import <nixpkgs> {
|
||||
|
||||
config = {
|
||||
android_sdk.accept_license = true;
|
||||
allowUnfree = true;
|
||||
};
|
||||
}
|
||||
}:
|
||||
# based on https://nixos.org/manual/nixpkgs/stable/#android
|
||||
# note: if you get any weird errors of "required extensions not found" or the like, somehow hotham
|
||||
# doesn't search /run/opengl-driver
|
||||
# you can set VK_ICD_FILENAMES manually instead, see https://nixos.org/manual/nixos/stable/index.html#sec-gpu-accel-vulkan
|
||||
let
|
||||
cmakeVersion = "3.22.1";
|
||||
|
||||
androidComposition = pkgs.androidenv.composeAndroidPackages {
|
||||
includeNDK = true;
|
||||
ndkVersion = "22.1.7171670";
|
||||
platformVersions = [ "28" ];
|
||||
cmakeVersions = [ cmakeVersion ];
|
||||
};
|
||||
|
||||
openXrDropin = {
|
||||
file_format_version = "1.0.0";
|
||||
runtime = {
|
||||
api_version = "1.0";
|
||||
name = "Hotham Simulator";
|
||||
# this won't work with pure flakes but flakes are unstable anyway
|
||||
library_path = "${toString ./.}/target/debug/libhotham_simulator.so";
|
||||
};
|
||||
};
|
||||
in
|
||||
pkgs.mkShell rec {
|
||||
buildInputs = with pkgs; [
|
||||
rustup
|
||||
ninja
|
||||
cmake
|
||||
openssl
|
||||
pkg-config
|
||||
python3
|
||||
cargo-apk
|
||||
adoptopenjdk-bin
|
||||
|
||||
shaderc
|
||||
vulkan-headers
|
||||
vulkan-loader
|
||||
vulkan-tools
|
||||
vulkan-tools-lunarg
|
||||
vulkan-validation-layers
|
||||
vulkan-extension-layer
|
||||
monado
|
||||
openxr-loader
|
||||
openxr-loader.dev
|
||||
|
||||
libxkbcommon
|
||||
wayland
|
||||
xorg.libX11
|
||||
xorg.libXcursor
|
||||
xorg.libXrandr
|
||||
xorg.libXi
|
||||
fontconfig
|
||||
freetype
|
||||
alsa-lib
|
||||
|
||||
renderdoc
|
||||
];
|
||||
|
||||
# the nixpkgs manual lists that ANDROID_HOME is outdated and ANDROID_SDK_ROOT should be used instead
|
||||
# when actually running the android tools, they say the opposite, ANDROID_SDK_ROOT being outdated
|
||||
# so I just set both
|
||||
ANDROID_SDK_ROOT = "${androidComposition.androidsdk}/libexec/android-sdk";
|
||||
ANDROID_HOME = ANDROID_SDK_ROOT;
|
||||
ANDROID_NDK_ROOT = "${ANDROID_SDK_ROOT}/ndk-bundle";
|
||||
|
||||
shellHook = ''
|
||||
export PATH="$(echo "$ANDROID_SDK_ROOT/cmake/${cmakeVersion}".*/bin):$PATH"
|
||||
export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:${builtins.toString (pkgs.lib.makeLibraryPath buildInputs)}";
|
||||
export XR_RUNTIME_JSON="${builtins.toFile "hotham-openxr-runtime.json" (builtins.toJSON openXrDropin)}"
|
||||
|
||||
rustup default 1.67 # required due to libunwind having fun
|
||||
rustup target add aarch64-linux-android
|
||||
'';
|
||||
|
||||
|
||||
}
|
117
src/lib.rs
Normal file
117
src/lib.rs
Normal file
|
@ -0,0 +1,117 @@
|
|||
use hotham::{
|
||||
asset_importer::{self, add_model_to_world},
|
||||
components::{
|
||||
hand::Handedness,
|
||||
physics::{BodyType, SharedShape},
|
||||
Collider, LocalTransform, RigidBody,
|
||||
},
|
||||
hecs::World,
|
||||
na,
|
||||
systems::{
|
||||
animation_system, debug::debug_system, grabbing_system, hands::add_hand, hands_system,
|
||||
physics_system, rendering::rendering_system, skinning::skinning_system,
|
||||
update_global_transform_system,
|
||||
},
|
||||
xr, Engine, HothamResult, TickData,
|
||||
};
|
||||
|
||||
#[derive(Clone, Debug, Default)]
|
||||
/// Most Hotham applications will want to keep track of some sort of state.
|
||||
/// However, this _simple_ scene doesn't have any, so this is just left here to let you know that
|
||||
/// this is something you'd probably want to do!
|
||||
struct State {}
|
||||
|
||||
#[cfg_attr(target_os = "android", ndk_glue::main(backtrace = "on"))]
|
||||
pub fn main() {
|
||||
println!("[HOTHAM_SIMPLE_SCENE] MAIN!");
|
||||
real_main().expect("Error running app!");
|
||||
println!("[HOTHAM_SIMPLE_SCENE] FINISHED! Goodbye!");
|
||||
}
|
||||
|
||||
pub fn real_main() -> HothamResult<()> {
|
||||
let mut engine = Engine::new();
|
||||
let mut state = Default::default();
|
||||
init(&mut engine)?;
|
||||
|
||||
while let Ok(tick_data) = engine.update() {
|
||||
tick(tick_data, &mut engine, &mut state);
|
||||
println!("HI");
|
||||
engine.finish()?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn tick(tick_data: TickData, engine: &mut Engine, _state: &mut State) {
|
||||
// if tick_data.current_state == xr::SessionState::FOCUSED {
|
||||
hands_system(engine);
|
||||
grabbing_system(engine);
|
||||
physics_system(engine);
|
||||
animation_system(engine);
|
||||
update_global_transform_system(engine);
|
||||
skinning_system(engine);
|
||||
// debug_system(engine);
|
||||
// }
|
||||
|
||||
rendering_system(engine, tick_data.swapchain_image_index);
|
||||
}
|
||||
|
||||
fn init(engine: &mut Engine) -> Result<(), hotham::HothamError> {
|
||||
let render_context = &mut engine.render_context;
|
||||
let vulkan_context = &mut engine.vulkan_context;
|
||||
let world = &mut engine.world;
|
||||
|
||||
loop {}
|
||||
let mut glb_buffers: Vec<&[u8]> = vec![
|
||||
include_bytes!("../assets/floor.glb"),
|
||||
include_bytes!("../assets/left_hand.glb"),
|
||||
include_bytes!("../assets/right_hand.glb"),
|
||||
];
|
||||
let models =
|
||||
asset_importer::load_models_from_glb(&glb_buffers, vulkan_context, render_context)?;
|
||||
|
||||
add_floor(&models, world);
|
||||
add_hand(&models, Handedness::Left, world);
|
||||
add_hand(&models, Handedness::Right, world);
|
||||
|
||||
#[cfg(target_os = "android")]
|
||||
glb_buffers.push(include_bytes!("../assets/damaged_helmet_squished.glb"));
|
||||
|
||||
let models =
|
||||
asset_importer::load_models_from_glb(&glb_buffers, vulkan_context, render_context)?;
|
||||
add_helmet(&models, world);
|
||||
add_model_to_world("Cube", &models, world, None);
|
||||
|
||||
// Update global transforms from local transforms before physics_system gets confused
|
||||
update_global_transform_system(engine);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn add_floor(models: &std::collections::HashMap<String, World>, world: &mut World) {
|
||||
let entity = add_model_to_world("Floor", models, world, None).expect("Could not find Floor");
|
||||
let collider = Collider::new(SharedShape::halfspace(na::Vector3::y_axis()));
|
||||
let rigid_body = RigidBody {
|
||||
body_type: BodyType::Fixed,
|
||||
..Default::default()
|
||||
};
|
||||
world.insert(entity, (collider, rigid_body)).unwrap();
|
||||
}
|
||||
|
||||
fn add_helmet(models: &std::collections::HashMap<String, World>, world: &mut World) {
|
||||
let helmet = add_model_to_world("Damaged Helmet", models, world, None)
|
||||
.expect("Could not find Damaged Helmet");
|
||||
|
||||
{
|
||||
let mut local_transform = world.get::<&mut LocalTransform>(helmet).unwrap();
|
||||
local_transform.translation.z = -1.;
|
||||
local_transform.translation.y = 1.4;
|
||||
local_transform.scale = [0.5, 0.5, 0.5].into();
|
||||
}
|
||||
|
||||
let collider = Collider::new(SharedShape::ball(0.35));
|
||||
|
||||
world
|
||||
.insert(helmet, (collider, RigidBody::default()))
|
||||
.unwrap();
|
||||
}
|
Loading…
Reference in a new issue