diff --git a/.github/pull.yml b/.github/pull.yml
new file mode 100644
index 00000000..397643b9
--- /dev/null
+++ b/.github/pull.yml
@@ -0,0 +1,6 @@
+version: "1"
+rules:
+ - base: master
+ upstream: WiVRn:master
+ mergeMethod: hardreset
+
\ No newline at end of file
diff --git a/.github/workflows/APK-Release.yml b/.github/workflows/APK-Release.yml
index 545d9330..4eec207d 100644
--- a/.github/workflows/APK-Release.yml
+++ b/.github/workflows/APK-Release.yml
@@ -22,9 +22,14 @@ jobs:
- uses: actions/checkout@v4
with:
# Checkout from upstream instead of WiVRn-APK to ensure the GIT_DESC variable is set correctly
- repository: 'WiVRn/WiVRn'
+ repository: 'Vindicus999/WiVRn'
ref: ${{ github.sha }}
fetch-depth: 0
+ #
+ # - uses: actions/checkout@v4
+ # with:
+ # repository: 'Vindicus999/WiVRn'
+ # ref: sneed
- name: set up JDK
uses: actions/setup-java@v4
@@ -68,7 +73,9 @@ jobs:
- name: Prepare before archiving artifacts
run: |
mkdir apk
+ ls build/outputs/apk/
mv $(find build/outputs/apk/ -name "*.apk") apk/
+ ls apk/
mkdir debug
mv build/intermediates/merged_native_libs/*/*/out/lib/* debug/
find debug -name libopenxr_loader.so -delete
@@ -102,13 +109,15 @@ jobs:
pattern: 'apk-*'
merge-multiple: true
- - name: Rename APK artifacts
- run: |
- cd apk
- for f in *.apk; do
- BASENAME=`echo ${f}|awk -F '-APK-' '{print $2}'`
- mv "${f}" "org.meumeu.wivrn-${BASENAME}"
- done
+ # - name: Rename APK artifacts
+ # run: |
+ # cd apk
+ # ls
+ # for f in *.apk; do
+ # BASENAME=`echo ${f}|awk -F '-APK-' '{print $2}'`
+ # mv "${f}" "org.meumeu.wivrn-${BASENAME}"
+ # done
+ # ls
- name: Download APK debug artifacts
uses: actions/download-artifact@v4
@@ -122,6 +131,11 @@ jobs:
cd symbols
zip -r ../debug-symbols.zip .
+ - name: How the hell doesnt it work
+ run: |
+ ls apk
+ ls
+
- name: APK Release
uses: softprops/action-gh-release@v2
with:
diff --git a/.github/workflows/Build.yml b/.github/workflows/Build.yml
index e61a4874..d2fb4b61 100644
--- a/.github/workflows/Build.yml
+++ b/.github/workflows/Build.yml
@@ -124,7 +124,7 @@ jobs:
run: |
git config --global --add safe.directory $(pwd)
pip install toml aiohttp
- tools/gen_flatpak_manifest.py --git https://github.com/${{github.repository}}.git --out flatpak
+ tools/gen_flatpak_manifest.py --gitlocal --out flatpak
cat flatpak/io.github.wivrn.wivrn.yml
- uses: flatpak/flatpak-github-actions/flatpak-builder@v6.4
@@ -153,11 +153,13 @@ jobs:
nix-test:
name: Test Nix package and devshell
runs-on: ubuntu-24.04
+ if: ${{ vars.APK_ONLY == '' }}
+
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
-
+
- uses: cachix/install-nix-action@v31
- run: nix flake check
- run: nix build
@@ -242,7 +244,7 @@ jobs:
WIVRN_SERVER_PID=$!
mkdir -p ~/.config/wivrn
- echo '{"servers": [{"autoconnect": false, "manual": true, "pretty_name": "Deep Thought", "hostname": "localhost", "port": 9757, "tcp_only": false, "cookie": ""}]}' > ~/.config/wivrn/client.json.in
+ echo '{"servers": [{"autoconnect": false, "manual": true, "pretty_name": "Deep Thought", "hostname": "localhost", "port": 9757, "tcp_only": false, "cookie": ""}], "first_run": false}' > ~/.config/wivrn/client.json.in
for LANG in en $(basename -a ${{github.workspace}}/locale/*)
do
@@ -574,7 +576,7 @@ jobs:
git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com"
git config --global user.name "github-actions[bot]"
- sudo apt-get install python-toml python-aiohttp
+ sudo apt-get install python3-toml python3-aiohttp
cd flathub
git remote add upstream https://github.com/flathub/io.github.wivrn.wivrn.git
diff --git a/.github/workflows/Sync.yml b/.github/workflows/Sync.yml
new file mode 100644
index 00000000..240c2d11
--- /dev/null
+++ b/.github/workflows/Sync.yml
@@ -0,0 +1,34 @@
+name: Sync Upstream
+
+env:
+ UPSTREAM_URL: "https://github.com/wivrn/wivrn.git"
+ WORKFLOW_TOKEN: ${{ secrets.DOWNSTREAM_GITHUB_TOKEN }}
+ UPSTREAM_BRANCH: "master"
+
+on:
+ schedule:
+ - cron: '0 5/6 * * *'
+ workflow_dispatch:
+
+jobs:
+ build:
+ runs-on: ubuntu-latest
+ steps:
+ - name: GitHub Sync to Upstream Repository
+ uses: dabreadman/sync-upstream-repo@v1.3.0
+ with:
+ upstream_repo: ${{ env.UPSTREAM_URL }}
+ upstream_branch: ${{ env.UPSTREAM_BRANCH }}
+ token: ${{ env.WORKFLOW_TOKEN }}
+
+ - name: Checkout stuff
+ uses: actions/checkout@master
+
+ - name: Merge sneed -> master
+ uses: devmasx/merge-branch@master
+ with:
+ type: now
+ from_branch: sneed
+ target_branch: master
+ github_token: ${{ env.WORKFLOW_TOKEN }}
+
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index dddc5896..7f9b6505 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -88,6 +88,8 @@
+
+
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 97e4d1fd..cad020f5 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,4 +1,4 @@
-cmake_minimum_required(VERSION 3.25)
+cmake_minimum_required(VERSION 3.28)
project(WiVRn VERSION 0.0.0 LANGUAGES C CXX)
# Set default for FetchContent projects
@@ -31,6 +31,7 @@ option(WIVRN_BUILD_SERVER_LIBRARY "Build OpenXR library for WiVRn server" ${WIVR
option(WIVRN_BUILD_DASHBOARD "Build WiVRn dashboard" OFF)
option(WIVRN_BUILD_WIVRNCTL "Build wivrnctl" ON)
option(WIVRN_BUILD_DISSECTOR "Build Wireshark dissector" OFF)
+option(WIVRN_BUILD_TEST "Build test binaries" OFF)
option(WIVRN_WERROR "Treat warnings as errors" OFF)
option(WIVRN_USE_NVENC "Enable nvenc (Nvidia) hardware encoder" ON)
@@ -239,9 +240,9 @@ endif()
if (WIVRN_BUILD_DISSECTOR)
if (WIVRN_USE_SYSTEM_OPENXR STREQUAL "AUTO")
- find_package(OpenXR 1.0.34)
+ find_package(OpenXR 1.1.48)
elseif(WIVRN_USE_SYSTEM_OPENXR STREQUAL "ON")
- find_package(OpenXR 1.0.34 REQUIRED)
+ find_package(OpenXR 1.1.48 REQUIRED)
endif()
find_package(Wireshark REQUIRED)
endif()
@@ -273,15 +274,17 @@ FetchContent_Declare(stb EXCLUDE_FROM_ALL SYSTEM URL https://github.co
FetchContent_Declare(libktx EXCLUDE_FROM_ALL SYSTEM
GIT_REPOSITORY https://github.com/KhronosGroup/KTX-Software
GIT_TAG 91ace88675ac59a97e55d0378a6602a9ae6b98bd)
-FetchContent_Declare(implot EXCLUDE_FROM_ALL SYSTEM URL https://github.com/epezent/implot/archive/refs/tags/v0.16.tar.gz
- URL_HASH SHA256=961df327d8a756304d1b0a67316eebdb1111d13d559f0d3415114ec0eb30abd1)
+FetchContent_Declare(implot EXCLUDE_FROM_ALL SYSTEM URL https://github.com/epezent/implot/archive/3da8bd34299965d3b0ab124df743fe3e076fa222.zip
+ URL_HASH SHA256=e9b439a94aa6f09fcf12ed9c2cd784efe5e99e96242122aa683e690b29f7a59f)
file(GLOB IMGUI_PATCHES CONFIGURE_DEPENDS patches/imgui/*)
-FetchContent_Declare(imgui EXCLUDE_FROM_ALL SYSTEM URL https://github.com/ocornut/imgui/archive/refs/tags/v1.91.3.tar.gz
- URL_HASH SHA256=29949d7b300c30565fbcd66398100235b63aa373acfee0b76853a7aeacd1be28
+FetchContent_Declare(imgui EXCLUDE_FROM_ALL SYSTEM URL https://github.com/ocornut/imgui/archive/refs/tags/v1.92.1.tar.gz
+ URL_HASH SHA256=32c237c2abf67a2ffccaac17192f711d4a787554b4133187a153d49057d6109c
PATCH_COMMAND ${CMAKE_CURRENT_LIST_DIR}/patches/apply.sh ${IMGUI_PATCHES}
)
FetchContent_Declare(uni-algo EXCLUDE_FROM_ALL SYSTEM URL https://github.com/uni-algo/uni-algo/archive/v1.2.0.tar.gz
URL_HASH SHA256=f2a1539cd8635bc6088d05144a73ecfe7b4d74ee0361fabed6f87f9f19e74ca9)
+FetchContent_Declare(entt EXCLUDE_FROM_ALL SYSTEM URL https://github.com/skypjack/entt/archive/refs/tags/v3.15.0.tar.gz
+ URL_HASH SHA256=01466fcbf77618a79b62891510c0bbf25ac2804af5751c84982b413852234d66)
file(GLOB MONADO_PATCHES CONFIGURE_DEPENDS patches/monado/*)
set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS monado-rev)
@@ -296,7 +299,9 @@ FetchContent_Declare(monado
)
add_subdirectory(external)
-add_subdirectory(common)
+if (WIVRN_BUILD_CLIENT OR WIVRN_BUILD_SERVER OR WIVRN_BUILD_DASHBOARD OR WIVRN_BUILD_DISSECTOR)
+ add_subdirectory(common)
+endif()
if (WIVRN_BUILD_CLIENT)
add_subdirectory(client)
diff --git a/build.gradle b/build.gradle
index cfdb5663..16d5e697 100644
--- a/build.gradle
+++ b/build.gradle
@@ -55,7 +55,7 @@ task "generatePngs"() {
android {
namespace "org.meumeu.wivrn"
- ndkVersion "27.1.12297006"
+ ndkVersion "28.1.13356709"
lint {
disable += "ExpiredTargetSdkVersion"
@@ -72,6 +72,7 @@ android {
versionName = project.hasProperty('wivrn_version') ? wivrn_version : "1.0"
versionCode = project.hasProperty('wivrn_versionCode') ? wivrn_versionCode.toInteger() : 1
def showImguiDemo = project.hasProperty('wivrn_show_imgui_demo') ? wivrn_show_imgui_demo : 'OFF'
+ def showDebugMenu = project.hasProperty('wivrn_show_debug_menu') ? wivrn_show_debug_menu : 'OFF'
externalNativeBuild {
def css = project.hasProperty('wivrn_css') ? project.wivrn_css: "images/wivrn-local.css"
@@ -90,6 +91,7 @@ android {
'-DWIVRN_BUILD_DASHBOARD=OFF',
'-DWIVRN_WERROR=ON',
'-DWIVRN_SHOW_IMGUI_DEMO_WINDOW=' + showImguiDemo,
+ '-DWIVRN_CLIENT_DEBUG_MENU=' + showDebugMenu,
'-DWIVRN_CSS=' + css
resValue "string", "app_name", project.hasProperty('wivrn_app_name') ? project.wivrn_app_name : "WiVRn Local"
}
diff --git a/client/CMakeLists.txt b/client/CMakeLists.txt
index 736dd541..01059ded 100644
--- a/client/CMakeLists.txt
+++ b/client/CMakeLists.txt
@@ -7,7 +7,7 @@ set(KTX_FEATURE_LOADTEST_APPS OFF)
set(FASTGLTF_COMPILE_AS_CPP20 ON)
-FetchContent_MakeAvailable(simdjson spdlog glm fastgltf imgui stb implot uni-algo)
+FetchContent_MakeAvailable(simdjson spdlog glm fastgltf imgui stb implot uni-algo entt)
if (WIVRN_USE_LIBKTX)
FetchContent_MakeAvailable(libktx)
@@ -140,6 +140,10 @@ target_link_libraries(wivrn-imgui FreetypeHarfbuzz)
target_link_libraries(wivrn wivrn-imgui)
+##############################################################################
+# EnTT
+#
+target_link_libraries(wivrn EnTT::EnTT)
##############################################################################
# Vulkan Validation Layer
diff --git a/client/application.cpp b/client/application.cpp
index 026aa151..798010ac 100644
--- a/client/application.cpp
+++ b/client/application.cpp
@@ -26,7 +26,6 @@
#include "spdlog/spdlog.h"
#include "utils/contains.h"
#include "utils/files.h"
-#include "utils/named_thread.h"
#include "vk/check.h"
#include "wifi_lock.h"
#include "xr/actionset.h"
@@ -51,6 +50,7 @@
#endif
#ifdef __ANDROID__
+#include "utils/named_thread.h"
#include
#include
@@ -66,15 +66,16 @@ struct interaction_profile
{
std::string profile_name;
std::vector required_extensions;
+ XrVersion min_version = XR_MAKE_VERSION(1, 0, 0);
+ XrVersion max_version = XR_MAKE_VERSION(2, 0, 0); // exclusive
std::vector input_sources;
bool available;
};
static std::vector interaction_profiles{
interaction_profile{
- "/interaction_profiles/khr/simple_controller",
- {},
- {
+ .profile_name = "/interaction_profiles/khr/simple_controller",
+ .input_sources = {
"/user/hand/left/output/haptic",
"/user/hand/right/output/haptic",
@@ -90,11 +91,11 @@ static std::vector interaction_profiles{
"/user/hand/right/input/menu/click",
"/user/hand/right/input/select/click",
- }},
+ },
+ },
interaction_profile{
- "/interaction_profiles/oculus/touch_controller",
- {},
- {
+ .profile_name = "/interaction_profiles/oculus/touch_controller",
+ .input_sources = {
"/user/hand/left/output/haptic",
"/user/hand/right/output/haptic",
@@ -129,11 +130,13 @@ static std::vector interaction_profiles{
"/user/hand/right/input/thumbstick/click",
"/user/hand/right/input/thumbstick/touch",
"/user/hand/right/input/thumbrest/touch",
- }},
+ },
+ },
interaction_profile{
- " /interaction_profiles/facebook/touch_controller_pro",
- {"XR_FB_touch_controller_pro"},
- {
+ .profile_name = "/interaction_profiles/facebook/touch_controller_pro",
+ .required_extensions = {"XR_FB_touch_controller_pro"},
+ .max_version = XR_MAKE_VERSION(1, 1, 0),
+ .input_sources = {
"/user/hand/left/output/haptic",
"/user/hand/left/output/haptic_trigger_fb",
"/user/hand/left/output/haptic_thumb_fb",
@@ -171,6 +174,7 @@ static std::vector interaction_profiles{
"/user/hand/right/input/b/click",
"/user/hand/right/input/b/touch",
"/user/hand/right/input/system/click",
+ "/user/hand/right/input/squeeze/value",
"/user/hand/right/input/trigger/value",
"/user/hand/right/input/trigger/touch",
"/user/hand/right/input/thumbstick",
@@ -183,11 +187,12 @@ static std::vector interaction_profiles{
"/user/hand/right/input/trigger/slide_fb",
"/user/hand/right/input/trigger/proximity_fb",
"/user/hand/right/input/thumb_fb/proximity_fb",
- }},
+ },
+ },
interaction_profile{
- " /interaction_profiles/meta/touch_pro_controller",
- {"XR_VERSION_1_1"},
- {
+ .profile_name = "/interaction_profiles/meta/touch_pro_controller",
+ .min_version = XR_MAKE_VERSION(1, 1, 0),
+ .input_sources = {
"/user/hand/left/output/haptic",
"/user/hand/left/output/haptic_trigger",
"/user/hand/left/output/haptic_thumb",
@@ -238,12 +243,13 @@ static std::vector interaction_profiles{
"/user/hand/right/input/thumbrest/touch",
"/user/hand/right/input/thumbrest/force",
"/user/hand/right/input/stylus/force",
-
- }},
+ },
+ },
interaction_profile{
- " /interaction_profiles/meta/touch_controller_plus",
- {"XR_META_touch_controller_plus"},
- {
+ .profile_name = "/interaction_profiles/meta/touch_controller_plus",
+ .required_extensions = {"XR_META_touch_controller_plus"},
+ .max_version = XR_MAKE_VERSION(1, 1, 0),
+ .input_sources = {
"/user/hand/left/output/haptic",
"/user/hand/right/output/haptic",
@@ -287,11 +293,12 @@ static std::vector interaction_profiles{
"/user/hand/right/input/trigger/slide_meta",
"/user/hand/right/input/trigger/force",
- }},
+ },
+ },
interaction_profile{
- " /interaction_profiles/meta/touch_plus_controller",
- {"XR_VERSION_1_1"},
- {
+ .profile_name = "/interaction_profiles/meta/touch_plus_controller",
+ .min_version = XR_MAKE_VERSION(1, 1, 0),
+ .input_sources = {
"/user/hand/left/output/haptic",
"/user/hand/right/output/haptic",
@@ -337,11 +344,12 @@ static std::vector interaction_profiles{
"/user/hand/right/input/thumbstick/touch",
"/user/hand/right/input/thumbrest/touch",
- }},
+ },
+ },
interaction_profile{
- "/interaction_profiles/bytedance/pico_neo3_controller",
- {"XR_BD_controller_interaction"},
- {
+ .profile_name = "/interaction_profiles/bytedance/pico_neo3_controller",
+ .required_extensions = {"XR_BD_controller_interaction"},
+ .input_sources = {
"/user/hand/left/output/haptic",
"/user/hand/right/output/haptic",
@@ -379,11 +387,12 @@ static std::vector interaction_profiles{
"/user/hand/right/input/thumbstick/click",
"/user/hand/right/input/thumbstick/touch",
- }},
+ },
+ },
interaction_profile{
- "/interaction_profiles/bytedance/pico4_controller",
- {"XR_BD_controller_interaction"},
- {
+ .profile_name = "/interaction_profiles/bytedance/pico4_controller",
+ .required_extensions = {"XR_BD_controller_interaction"},
+ .input_sources = {
"/user/hand/left/output/haptic",
"/user/hand/right/output/haptic",
@@ -421,11 +430,12 @@ static std::vector interaction_profiles{
"/user/hand/right/input/thumbstick/touch",
"/user/hand/right/input/squeeze/click",
"/user/hand/right/input/squeeze/value",
- }},
+ },
+ },
interaction_profile{
- "/interaction_profiles/bytedance/pico4s_controller",
- {"XR_BD_controller_interaction"},
- {
+ .profile_name = "/interaction_profiles/bytedance/pico4s_controller",
+ .required_extensions = {"XR_BD_controller_interaction"},
+ .input_sources = {
"/user/hand/left/output/haptic",
"/user/hand/right/output/haptic",
@@ -463,11 +473,12 @@ static std::vector interaction_profiles{
"/user/hand/right/input/thumbstick/touch",
"/user/hand/right/input/squeeze/click",
"/user/hand/right/input/squeeze/value",
- }},
+ },
+ },
interaction_profile{
- "/interaction_profiles/htc/vive_focus3_controller",
- {"XR_HTC_vive_focus3_controller_interaction"},
- {
+ .profile_name = "/interaction_profiles/htc/vive_focus3_controller",
+ .required_extensions = {"XR_HTC_vive_focus3_controller_interaction"},
+ .input_sources = {
"/user/hand/left/output/haptic",
"/user/hand/right/output/haptic",
@@ -504,18 +515,48 @@ static std::vector interaction_profiles{
"/user/hand/right/input/thumbstick/click",
"/user/hand/right/input/thumbstick/touch",
"/user/hand/right/input/thumbrest/touch",
- }},
- interaction_profile{
- "/interaction_profiles/htc/vive_xr_tracker",
- {"XR_HTC_vive_xr_tracker_interaction", "XR_HTC_path_enumeration"},
- {},
+ },
},
interaction_profile{
- "/interaction_profiles/ext/eye_gaze_interaction",
- {"XR_EXT_eye_gaze_interaction"},
- {
+ .profile_name = "/interaction_profiles/ext/hand_interaction_ext",
+ .required_extensions = {"XR_EXT_hand_interaction"},
+ .input_sources = {
+ "/user/hand/left/input/aim/pose",
+ "/user/hand/left/input/grip/pose",
+
+ "/user/hand/left/input/pinch_ext/pose",
+ "/user/hand/left/input/pinch_ext/value",
+ "/user/hand/left/input/pinch_ext/ready_ext",
+ "/user/hand/left/input/poke_ext/pose",
+ "/user/hand/left/input/aim_activate_ext/value",
+ "/user/hand/left/input/aim_activate_ext/ready_ext",
+ "/user/hand/left/input/grasp_ext/value",
+ "/user/hand/left/input/grasp_ext/ready_ext",
+
+ "/user/hand/right/input/aim/pose",
+ "/user/hand/right/input/grip/pose",
+
+ "/user/hand/right/input/pinch_ext/pose",
+ "/user/hand/right/input/pinch_ext/value",
+ "/user/hand/right/input/pinch_ext/ready_ext",
+ "/user/hand/right/input/poke_ext/pose",
+ "/user/hand/right/input/aim_activate_ext/value",
+ "/user/hand/right/input/aim_activate_ext/ready_ext",
+ "/user/hand/right/input/grasp_ext/value",
+ "/user/hand/right/input/grasp_ext/ready_ext",
+ },
+ },
+ interaction_profile{
+ .profile_name = "/interaction_profiles/htc/vive_xr_tracker",
+ .required_extensions = {"XR_HTC_vive_xr_tracker_interaction", "XR_HTC_path_enumeration"},
+ },
+ interaction_profile{
+ .profile_name = "/interaction_profiles/ext/eye_gaze_interaction",
+ .required_extensions = {"XR_EXT_eye_gaze_interaction"},
+ .input_sources = {
"/user/eyes_ext/input/gaze_ext/pose",
- }},
+ },
+ },
};
static const std::pair action_suffixes[] =
@@ -544,6 +585,9 @@ static const std::pair action_suffixes[] =
{"/joystick", XR_ACTION_TYPE_VECTOR2F_INPUT},
{"/trackball", XR_ACTION_TYPE_VECTOR2F_INPUT},
+ // XR_EXT_hand_interaction
+ {"/ready_ext", XR_ACTION_TYPE_BOOLEAN_INPUT},
+
// Output paths
{"/haptic", XR_ACTION_TYPE_VIBRATION_OUTPUT},
{"/haptic_trigger", XR_ACTION_TYPE_VIBRATION_OUTPUT},
@@ -683,9 +727,10 @@ void application::initialize_vulkan()
bool debug_utils_found = false;
#endif
spdlog::info("Available Vulkan instance extensions:");
+ std::vector> extensions;
for (vk::ExtensionProperties & i: vk_context.enumerateInstanceExtensionProperties(nullptr))
{
- spdlog::info(" {} (version {})", i.extensionName.data(), i.specVersion);
+ extensions.emplace_back(i.extensionName.data(), i.specVersion);
#ifndef NDEBUG
if (!strcmp(i.extensionName, VK_EXT_DEBUG_REPORT_EXTENSION_NAME))
@@ -695,6 +740,9 @@ void application::initialize_vulkan()
debug_utils_found = true;
#endif
}
+ std::ranges::sort(extensions);
+ for (const auto & [extension_name, spec_version]: extensions)
+ spdlog::info(" {} (version {})", extension_name, spec_version);
#ifndef NDEBUG
if (debug_utils_found && debug_report_found)
@@ -773,11 +821,16 @@ void application::initialize_vulkan()
vk_physical_device = xr_system_id.physical_device(vk_instance);
physical_device_properties = vk_physical_device.getProperties();
- spdlog::info("Available Vulkan device extensions:");
+ extensions.clear();
for (vk::ExtensionProperties & i: vk_physical_device.enumerateDeviceExtensionProperties())
+ extensions.emplace_back(i.extensionName.data(), i.specVersion);
+ std::ranges::sort(extensions);
+
+ spdlog::info("Available Vulkan device extensions:");
+ for (const auto & [extension_name, spec_version]: extensions)
{
- spdlog::info(" {}", i.extensionName.data());
- if (auto it = optional_device_extensions.find(i.extensionName); it != optional_device_extensions.end())
+ spdlog::info(" {} (version {})", extension_name, spec_version);
+ if (auto it = optional_device_extensions.find(extension_name); it != optional_device_extensions.end())
vk_device_extensions.push_back(it->data());
}
@@ -909,23 +962,69 @@ void application::initialize_actions()
std::unordered_map> suggested_bindings;
+ XrVersion api_version = xr_instance.get_api_version();
// Build the list of all possible input sources, without duplicates,
// checking which profiles are supported by the runtime
std::vector sources;
for (auto & profile: interaction_profiles)
{
- profile.available = utils::contains_all(xr_extensions, profile.required_extensions);
+ profile.available = utils::contains_all(xr_extensions, profile.required_extensions) and profile.min_version <= api_version and profile.max_version > api_version;
+
+ if (profile.profile_name.ends_with("khr/simple_controller"))
+ {
+ switch (guess_model())
+ {
+ // Quest hand tracking creates a fake khr/simple_controller when hand tracking
+ // is enabled, this messes with native hand tracking
+ case model::meta_quest_3:
+ case model::meta_quest_pro:
+ case model::meta_quest_3s:
+ case model::oculus_quest_2:
+ profile.available = false;
+ default:
+ break;
+ }
+ }
if (!profile.available)
continue;
- // Patch profile to add palm_ext
- if (utils::contains(xr_extensions, XR_EXT_PALM_POSE_EXTENSION_NAME) //
- and utils::contains(profile.input_sources, "/user/hand/left/input/grip/pose") //
- and not utils::contains(profile.input_sources, "/user/hand/left/input/palm_ext/pose"))
+ // Patch profile to add grip_surface or palm_ext
+ bool add_palms = true;
+ if (profile.profile_name.ends_with("ext/hand_interaction_ext"))
{
- profile.input_sources.push_back("/user/hand/left/input/palm_ext/pose");
- profile.input_sources.push_back("/user/hand/right/input/palm_ext/pose");
+ switch (guess_model())
+ {
+ // Quest breaks spec and does not support grip_surface for ext/hand_interaction_ext
+ case model::meta_quest_3:
+ case model::meta_quest_pro:
+ case model::meta_quest_3s:
+ case model::oculus_quest_2:
+ case model::oculus_quest:
+ add_palms = false;
+ break;
+ default:
+ break;
+ }
+ }
+ if (add_palms)
+ {
+ if ((api_version >= XR_MAKE_VERSION(1, 1, 0) or utils::contains(xr_extensions, XR_KHR_MAINTENANCE1_EXTENSION_NAME)) //
+ and utils::contains(profile.input_sources, "/user/hand/left/input/grip/pose") //
+ and not utils::contains(profile.input_sources, "/user/hand/left/input/grip_surface/pose"))
+ {
+ spdlog::info("Adding grip_surface/pose for interaction profile {}", profile.profile_name);
+ profile.input_sources.push_back("/user/hand/left/input/grip_surface/pose");
+ profile.input_sources.push_back("/user/hand/right/input/grip_surface/pose");
+ }
+ else if (utils::contains(xr_extensions, XR_EXT_PALM_POSE_EXTENSION_NAME) //
+ and utils::contains(profile.input_sources, "/user/hand/left/input/grip/pose") //
+ and not utils::contains(profile.input_sources, "/user/hand/left/input/palm_ext/pose"))
+ {
+ spdlog::info("Adding palm_ext/pose for interaction profile {}", profile.profile_name);
+ profile.input_sources.push_back("/user/hand/left/input/palm_ext/pose");
+ profile.input_sources.push_back("/user/hand/right/input/palm_ext/pose");
+ }
}
// Dynamically add VIVE XR Trackers to the profile if available
@@ -966,16 +1065,24 @@ void application::initialize_actions()
spaces[size_t(xr::spaces::grip_left)] = xr_session.create_action_space(a);
else if (name == "/user/hand/left/input/aim/pose")
spaces[size_t(xr::spaces::aim_left)] = xr_session.create_action_space(a);
+ else if (name == "/user/hand/left/input/palm_ext/pose" or name == "/user/hand/left/input/grip_surface/pose")
+ spaces[size_t(xr::spaces::palm_left)] = xr_session.create_action_space(a);
+ else if (name == "/user/hand/left/input/pinch_ext/pose")
+ spaces[size_t(xr::spaces::pinch_left)] = xr_session.create_action_space(a);
+ else if (name == "/user/hand/left/input/poke_ext/pose")
+ spaces[size_t(xr::spaces::poke_left)] = xr_session.create_action_space(a);
else if (name == "/user/hand/right/input/grip/pose")
spaces[size_t(xr::spaces::grip_right)] = xr_session.create_action_space(a);
else if (name == "/user/hand/right/input/aim/pose")
spaces[size_t(xr::spaces::aim_right)] = xr_session.create_action_space(a);
+ else if (name == "/user/hand/right/input/palm_ext/pose" or name == "/user/hand/right/input/grip_surface/pose")
+ spaces[size_t(xr::spaces::palm_right)] = xr_session.create_action_space(a);
+ else if (name == "/user/hand/right/input/pinch_ext/pose")
+ spaces[size_t(xr::spaces::pinch_right)] = xr_session.create_action_space(a);
+ else if (name == "/user/hand/right/input/poke_ext/pose")
+ spaces[size_t(xr::spaces::poke_right)] = xr_session.create_action_space(a);
else if (name == "/user/eyes_ext/input/gaze_ext/pose")
spaces[size_t(xr::spaces::eye_gaze)] = xr_session.create_action_space(a);
- else if (name == "/user/hand/right/input/palm_ext/pose")
- spaces[size_t(xr::spaces::palm_right)] = xr_session.create_action_space(a);
- else if (name == "/user/hand/left/input/palm_ext/pose")
- spaces[size_t(xr::spaces::palm_left)] = xr_session.create_action_space(a);
else if (name.contains("/input/entity_htc/pose") && htc_body)
htc_body->add(xr_session.create_action_space(a));
}
@@ -999,20 +1106,23 @@ void application::initialize_actions()
for (const scene::suggested_binding & j: i->bindings)
{
- // Skip unsupported profiles
- if (!suggested_bindings.contains(j.profile_name))
- continue;
-
- std::vector & xr_bindings = suggested_bindings[j.profile_name];
-
- for (const scene::action_binding & k: j.paths)
+ for (const auto & profile: j.profile_names)
{
- XrAction a = i->actions_by_name[k.action_name].first;
- assert(a != XR_NULL_HANDLE);
+ // Skip unsupported profiles
+ if (!suggested_bindings.contains(profile))
+ continue;
- xr_bindings.push_back(XrActionSuggestedBinding{
- .action = a,
- .binding = string_to_path(k.input_source)});
+ std::vector & xr_bindings = suggested_bindings[profile];
+
+ for (const scene::action_binding & k: j.paths)
+ {
+ XrAction a = i->actions_by_name[k.action_name].first;
+ assert(a != XR_NULL_HANDLE);
+
+ xr_bindings.push_back(XrActionSuggestedBinding{
+ .action = a,
+ .binding = string_to_path(k.input_source)});
+ }
}
}
}
@@ -1055,8 +1165,11 @@ void application::initialize()
// Optional extensions
std::vector opt_extensions;
+ opt_extensions.push_back(XR_KHR_LOCATE_SPACES_EXTENSION_NAME);
+ opt_extensions.push_back(XR_KHR_MAINTENANCE1_EXTENSION_NAME);
opt_extensions.push_back(XR_FB_DISPLAY_REFRESH_RATE_EXTENSION_NAME);
opt_extensions.push_back(XR_EXT_HAND_TRACKING_EXTENSION_NAME);
+ opt_extensions.push_back(XR_EXT_HAND_INTERACTION_EXTENSION_NAME);
opt_extensions.push_back(XR_EXT_EYE_GAZE_INTERACTION_EXTENSION_NAME);
opt_extensions.push_back(XR_FB_PASSTHROUGH_EXTENSION_NAME);
opt_extensions.push_back(XR_HTC_PASSTHROUGH_EXTENSION_NAME);
@@ -1072,17 +1185,12 @@ void application::initialize()
opt_extensions.push_back(XR_KHR_COMPOSITION_LAYER_DEPTH_EXTENSION_NAME);
opt_extensions.push_back(XR_FB_COMPOSITION_LAYER_DEPTH_TEST_EXTENSION_NAME);
opt_extensions.push_back(XR_KHR_COMPOSITION_LAYER_COLOR_SCALE_BIAS_EXTENSION_NAME);
+ opt_extensions.push_back(XR_EXT_USER_PRESENCE_EXTENSION_NAME);
opt_extensions.push_back(XR_KHR_VISIBILITY_MASK_EXTENSION_NAME);
opt_extensions.push_back(XR_FB_COMPOSITION_LAYER_SETTINGS_EXTENSION_NAME);
for (const auto & i: interaction_profiles)
- {
- for (const auto & j: i.required_extensions)
- {
- if (not j.starts_with("XR_VERSION"))
- opt_extensions.push_back(j);
- }
- }
+ opt_extensions.insert(opt_extensions.end(), i.required_extensions.begin(), i.required_extensions.end());
for (const auto & i: xr::instance::extensions())
{
@@ -1103,7 +1211,10 @@ void application::initialize()
xr_instance = xr::instance(app_info.name, extensions);
#endif
- spdlog::info("Created OpenXR instance, runtime {}, version {}", xr_instance.get_runtime_name(), xr_instance.get_runtime_version());
+ spdlog::info("Created OpenXR instance, runtime {}, version {}, API version {}",
+ xr_instance.get_runtime_name(),
+ xr_instance.get_runtime_version(),
+ xr::to_string(xr_instance.get_api_version()));
xr_system_id = xr::system(xr_instance, app_info.formfactor);
spdlog::info("Created OpenXR system for form factor {}", xr::to_string(app_info.formfactor));
@@ -1132,40 +1243,6 @@ void application::initialize()
XrSystemEyeGazeInteractionPropertiesEXT eye_gaze_properties = xr_system_id.eye_gaze_interaction_properties();
spdlog::info(" Eye gaze support: {}", (bool)eye_gaze_properties.supportsEyeGazeInteraction);
eye_gaze_supported = eye_gaze_properties.supportsEyeGazeInteraction;
-
- if (eye_gaze_supported)
- {
- switch (guess_model())
- {
- case model::pico_4_pro:
- case model::pico_4_enterprise:
- pico_face_tracking_supported = true;
- break;
- default:
- pico_face_tracking_supported = false;
- break;
- }
- }
- else
- pico_face_tracking_supported = false;
-
- spdlog::info(" PICO face tracking support: {}", (bool)pico_face_tracking_supported);
- }
-
- if (utils::contains(xr_extensions, XR_FB_FACE_TRACKING2_EXTENSION_NAME))
- {
- XrSystemFaceTrackingProperties2FB fb_face2_properties = xr_system_id.fb_face_tracking2_properties();
- spdlog::info(" FB face tracking support: {}", (bool)fb_face2_properties.supportsVisualFaceTracking);
- fb_face_tracking2_supported = fb_face2_properties.supportsVisualFaceTracking;
- }
-
- if (utils::contains(xr_extensions, XR_HTC_FACIAL_TRACKING_EXTENSION_NAME))
- {
- XrSystemFacialTrackingPropertiesHTC htc_face_properties = xr_system_id.htc_face_tracking_properties();
- spdlog::info(" HTC eye tracking support: {}", (bool)htc_face_properties.supportEyeFacialTracking);
- spdlog::info(" HTC lip tracking support: {}", (bool)htc_face_properties.supportLipFacialTracking);
- htc_face_tracking_eye_supported = htc_face_properties.supportEyeFacialTracking;
- htc_face_tracking_lip_supported = htc_face_properties.supportLipFacialTracking;
}
if (utils::contains(xr_extensions, XR_FB_COMPOSITION_LAYER_SETTINGS_EXTENSION_NAME))
@@ -1212,24 +1289,35 @@ void application::initialize()
right_hand = xr_session.create_hand_tracker(XR_HAND_RIGHT_EXT);
}
- if (fb_face_tracking2_supported)
+ if (utils::contains(xr_extensions, XR_FB_FACE_TRACKING2_EXTENSION_NAME))
{
- fb_face_tracker2 = xr_session.create_fb_face_tracker2();
+ XrSystemFaceTrackingProperties2FB fb_face2_properties = xr_system_id.fb_face_tracking2_properties();
+ spdlog::info(" FB face tracking support: {}", (bool)fb_face2_properties.supportsVisualFaceTracking);
+ if (fb_face2_properties.supportsVisualFaceTracking)
+ face_tracker.emplace(xr_instance, xr_session);
}
- if (htc_face_tracking_eye_supported)
+ if (std::holds_alternative(face_tracker) && utils::contains(xr_extensions, XR_HTC_FACIAL_TRACKING_EXTENSION_NAME))
{
- htc_face_tracker_eye = xr_session.create_htc_face_tracker(XR_FACIAL_TRACKING_TYPE_EYE_DEFAULT_HTC);
+ XrSystemFacialTrackingPropertiesHTC htc_face_properties = xr_system_id.htc_face_tracking_properties();
+ spdlog::info(" HTC eye tracking support: {}", (bool)htc_face_properties.supportEyeFacialTracking);
+ spdlog::info(" HTC lip tracking support: {}", (bool)htc_face_properties.supportLipFacialTracking);
+ if (htc_face_properties.supportEyeFacialTracking || htc_face_properties.supportLipFacialTracking)
+ face_tracker.emplace(xr_instance, xr_session, htc_face_properties.supportEyeFacialTracking, htc_face_properties.supportLipFacialTracking);
}
- if (htc_face_tracking_lip_supported)
+ if (std::holds_alternative(face_tracker) && eye_gaze_supported)
{
- htc_face_tracker_lip = xr_session.create_htc_face_tracker(XR_FACIAL_TRACKING_TYPE_LIP_DEFAULT_HTC);
- }
-
- if (pico_face_tracking_supported)
- {
- pico_face_tracker = xr_session.create_pico_face_tracker();
+ switch (guess_model())
+ {
+ case model::pico_4_pro:
+ case model::pico_4_enterprise:
+ spdlog::info(" PICO face tracking support: true");
+ face_tracker.emplace(xr_instance, xr_session);
+ break;
+ default:
+ break;
+ }
}
if (utils::contains_all(xr_extensions, std::array{XR_FB_BODY_TRACKING_EXTENSION_NAME, XR_META_BODY_TRACKING_FULL_BODY_EXTENSION_NAME, XR_META_BODY_TRACKING_FIDELITY_EXTENSION_NAME}))
@@ -1237,13 +1325,13 @@ void application::initialize()
XrSystemBodyTrackingPropertiesFB fb_body_properties = xr_system_id.fb_body_tracking_properties();
spdlog::info(" FB body tracking support: {}", (bool)fb_body_properties.supportsBodyTracking);
if (fb_body_properties.supportsBodyTracking)
- body_tracker = xr_session.create_fb_body_tracker();
+ body_tracker.emplace(xr_instance, xr_session);
}
if (std::holds_alternative(body_tracker) && utils::contains_all(xr_extensions, std::array{XR_HTC_PATH_ENUMERATION_EXTENSION_NAME, XR_HTC_VIVE_XR_TRACKER_INTERACTION_EXTENSION_NAME}))
{
spdlog::info(" HTC body tracking support: true");
- body_tracker = xr_session.create_htc_body_tracker();
+ body_tracker.emplace(xr_instance, xr_session);
}
if (std::holds_alternative(body_tracker) && utils::contains(xr_extensions, XR_BD_BODY_TRACKING_EXTENSION_NAME))
@@ -1251,7 +1339,7 @@ void application::initialize()
XrSystemBodyTrackingPropertiesBD bd_body_properties = xr_system_id.bd_body_tracking_properties();
spdlog::info(" PICO body tracking support: {}", (bool)bd_body_properties.supportsBodyTracking);
if (bd_body_properties.supportsBodyTracking)
- body_tracker = xr_session.create_pico_body_tracker();
+ body_tracker.emplace(xr_instance, xr_session);
}
vk::CommandPoolCreateInfo cmdpool_create_info;
diff --git a/client/application.h b/client/application.h
index 6a2d8af2..377749c1 100644
--- a/client/application.h
+++ b/client/application.h
@@ -129,17 +129,7 @@ class application : public singleton
xr::hand_tracker left_hand;
xr::hand_tracker right_hand;
- bool fb_face_tracking2_supported = false;
- xr::fb_face_tracker2 fb_face_tracker2;
-
- bool htc_face_tracking_eye_supported = false;
- xr::htc_face_tracker htc_face_tracker_eye;
- bool htc_face_tracking_lip_supported = false;
- xr::htc_face_tracker htc_face_tracker_lip;
-
- bool pico_face_tracking_supported = false;
- xr::pico_face_tracker pico_face_tracker;
-
+ std::variant face_tracker;
std::variant body_tracker;
bool eye_gaze_supported = false;
@@ -430,24 +420,9 @@ public:
return instance().hand_tracking_supported;
}
- static bool get_fb_face_tracking2_supported()
+ static bool get_face_tracking_supported()
{
- return instance().fb_face_tracking2_supported;
- }
-
- static bool get_htc_face_tracking_eye_supported()
- {
- return instance().htc_face_tracking_eye_supported;
- }
-
- static bool get_htc_face_tracking_lip_supported()
- {
- return instance().htc_face_tracking_lip_supported;
- }
-
- static bool get_pico_face_tracking_supported()
- {
- return instance().pico_face_tracking_supported;
+ return !std::holds_alternative(instance().face_tracker);
}
static bool get_body_tracking_supported()
@@ -475,24 +450,9 @@ public:
return instance().right_hand;
}
- static xr::fb_face_tracker2 & get_fb_face_tracker2()
+ static auto & get_face_tracker()
{
- return instance().fb_face_tracker2;
- }
-
- static xr::htc_face_tracker & get_htc_face_tracker_eye()
- {
- return instance().htc_face_tracker_eye;
- }
-
- static xr::htc_face_tracker & get_htc_face_tracker_lip()
- {
- return instance().htc_face_tracker_lip;
- }
-
- static xr::pico_face_tracker & get_pico_face_tracker()
- {
- return instance().pico_face_tracker;
+ return instance().face_tracker;
}
static auto & get_body_tracker()
@@ -516,6 +476,11 @@ public:
return *instance().config;
}
+ static XrSessionState get_session_state()
+ {
+ return instance().session_state;
+ }
+
static boost::locale::gnu_gettext::messages_info & get_messages_info()
{
return instance().messages_info;
diff --git a/client/audio/android/audio.cpp b/client/audio/android/audio.cpp
index 43afd64c..62f94799 100644
--- a/client/audio/android/audio.cpp
+++ b/client/audio/android/audio.cpp
@@ -291,7 +291,7 @@ void wivrn::android::audio::operator()(wivrn::audio_data && data)
buffer_size_bytes.fetch_add(size);
}
-void wivrn::android::audio::set_mic_sate(bool running)
+void wivrn::android::audio::set_mic_state(bool running)
{
if (not microphone)
return;
diff --git a/client/audio/android/audio.h b/client/audio/android/audio.h
index 11edda85..a3eab804 100644
--- a/client/audio/android/audio.h
+++ b/client/audio/android/audio.h
@@ -78,7 +78,7 @@ public:
void operator()(wivrn::audio_data &&);
- void set_mic_sate(bool running);
+ void set_mic_state(bool running);
static void get_audio_description(wivrn::from_headset::headset_info_packet & info);
};
diff --git a/client/audio/audio.h b/client/audio/audio.h
index 11189b2e..1564f065 100644
--- a/client/audio/audio.h
+++ b/client/audio/audio.h
@@ -42,7 +42,7 @@ public:
~audio() = default;
void operator()(wivrn::audio_data &&) {}
- void set_mic_sate(bool running) {}
+ void set_mic_state(bool running) {}
static void get_audio_description(wivrn::from_headset::headset_info_packet & info) {}
};
diff --git a/client/configuration.cpp b/client/configuration.cpp
index 82b1f140..abe7f15e 100644
--- a/client/configuration.cpp
+++ b/client/configuration.cpp
@@ -106,18 +106,17 @@ bool configuration::check_feature(feature f) const
{
case model::htc_vive_focus_3:
case model::htc_vive_focus_vision:
- [[fallthrough]];
case model::htc_vive_xr_elite:
- if (not(application::get_htc_face_tracking_eye_supported() or application::get_htc_face_tracking_lip_supported()))
+ if (not std::holds_alternative(application::get_face_tracker()))
return false;
break;
case model::pico_4_pro:
case model::pico_4_enterprise:
- if (not application::get_pico_face_tracking_supported())
+ if (not std::holds_alternative(application::get_face_tracker()))
return false;
break;
default:
- if (not application::get_fb_face_tracking2_supported())
+ if (not std::holds_alternative(application::get_face_tracker()))
return false;
break;
}
@@ -206,9 +205,6 @@ configuration::configuration(xr::system & system)
servers.emplace(data.service.txt["cookie"], data);
}
- if (auto val = root["show_performance_metrics"]; val.is_bool())
- show_performance_metrics = val.get_bool();
-
if (auto val = root["preferred_refresh_rate"]; val.is_double())
preferred_refresh_rate = val.get_double();
@@ -246,6 +242,18 @@ configuration::configuration(xr::system & system)
if (system.passthrough_supported() == xr::system::passthrough_type::no_passthrough)
passthrough_enabled = false;
+
+ if (auto val = root["override_foveation_enable"]; val.is_bool())
+ override_foveation_enable = val.get_bool();
+
+ if (auto val = root["override_foveation_pitch"]; val.is_double())
+ override_foveation_pitch = val.get_double();
+
+ if (auto val = root["override_foveation_distance"]; val.is_double())
+ override_foveation_distance = val.get_double();
+
+ if (auto val = root["first_run"]; val.is_bool())
+ first_run = val.get_bool();
}
catch (std::exception & e)
{
@@ -258,7 +266,6 @@ configuration::configuration(xr::system & system)
resolution_scale = 1.4;
sgsr = {};
openxr_post_processing = {};
- show_performance_metrics = false;
passthrough_enabled = system.passthrough_supported() == xr::system::passthrough_type::color;
}
}
@@ -344,8 +351,7 @@ void configuration::save()
std::ofstream json(application::get_config_path() / "client.json");
- json << "{\"servers\":[" << servers_str << "],"
- << "\"show_performance_metrics\":" << std::boolalpha << show_performance_metrics;
+ json << "{\"servers\":[" << servers_str << "]";
if (preferred_refresh_rate)
json << ",\"preferred_refresh_rate\":" << *preferred_refresh_rate;
if (minimum_refresh_rate)
@@ -362,5 +368,9 @@ void configuration::save()
for (auto & [key, value]: features)
json << "," << key << ":" << std::boolalpha << value;
json << ",\"virtual_keyboard_layout\":" << json_string(virtual_keyboard_layout);
+ json << ",\"override_foveation_enable\":" << std::boolalpha << override_foveation_enable;
+ json << ",\"override_foveation_pitch\":" << override_foveation_pitch;
+ json << ",\"override_foveation_distance\":" << override_foveation_distance;
+ json << ",\"first_run\":" << std::boolalpha << first_run;
json << "}";
}
diff --git a/client/configuration.h b/client/configuration.h
index cdfdd8f5..8d34faae 100644
--- a/client/configuration.h
+++ b/client/configuration.h
@@ -50,7 +50,6 @@ public:
std::optional preferred_refresh_rate;
std::optional minimum_refresh_rate;
float resolution_scale = 1.4;
- bool show_performance_metrics = false;
bool passthrough_enabled = false;
bool mic_unprocessed_audio = false;
@@ -78,6 +77,12 @@ public:
std::string virtual_keyboard_layout = "QWERTY";
+ bool override_foveation_enable = false;
+ float override_foveation_pitch = 10 * M_PI / 180;
+ float override_foveation_distance = 3;
+
+ bool first_run = true;
+
bool check_feature(feature f) const;
void set_feature(feature f, bool state);
@@ -90,6 +95,7 @@ private:
public:
configuration(xr::system &);
+ configuration() = default;
void save();
};
diff --git a/client/constants.h b/client/constants.h
index ad0b8222..69d817d8 100644
--- a/client/constants.h
+++ b/client/constants.h
@@ -18,7 +18,6 @@
#pragma once
-#include
#include
#include
#include
@@ -91,7 +90,7 @@ constexpr float recenter_action_distance = 0.3;
constexpr float initial_gui_distance = 0.5;
// Skybox color
-constexpr std::array sky_color = {0, 0.25, 0.5, 1};
+constexpr XrColor4f sky_color = {0, 0.25, 0.5, 1};
// Dimming scale/bias when a popup window is shown
constexpr XrColor4f dimming_scale = {0.5, 0.5, 0.5, 1};
@@ -105,6 +104,16 @@ constexpr int zindex_controllers = 1;
constexpr int zindex_recenter_tip = 2;
} // namespace constants::lobby
+namespace constants::stream
+{
+constexpr float fade_delay = 3;
+constexpr float fade_duration = 0.25;
+
+// Dimming for the streamed video when the GUI is interactable
+constexpr float dimming_scale = 0.7;
+constexpr float dimming_bias = 0.15;
+} // namespace constants::stream
+
namespace constants::style
{
constexpr ImVec2 window_padding = {20, 20};
diff --git a/client/hardware.cpp b/client/hardware.cpp
index c12960de..745be7bf 100644
--- a/client/hardware.cpp
+++ b/client/hardware.cpp
@@ -348,6 +348,24 @@ std::pair controller_offset(std::string_view profile, xr::
default:
break;
}
+ else if (profile == "meta-quest-touch-plus")
+ {
+ switch (space)
+ {
+ case xr::spaces::grip_left:
+ case xr::spaces::grip_right:
+ return {{0, -0.010, -0.025}, glm::angleAxis(glm::radians(-12.f), glm::vec3{1, 0, 0})};
+
+ case xr::spaces::aim_left:
+ return {{0, 0, 0.03}, {1, 0, 0, 0}};
+
+ case xr::spaces::aim_right:
+ return {{0, 0, 0.03}, {1, 0, 0, 0}};
+
+ default:
+ break;
+ }
+ }
else if (profile == "htc-vive-focus-3")
switch (space)
{
@@ -367,7 +385,7 @@ std::pair controller_offset(std::string_view profile, xr::
{
case xr::spaces::grip_left:
case xr::spaces::grip_right:
- return {{0, -0.030, -0.040}, glm::angleAxis(glm::radians(-35.f), glm::vec3{1, 0, 0})};
+ return {{0, -0.014, -0.048}, glm::angleAxis(glm::radians(-35.060f), glm::vec3{1, 0, 0})};
default:
break;
diff --git a/client/render/imgui_impl.cpp b/client/render/imgui_impl.cpp
index c38be677..3ff6186f 100644
--- a/client/render/imgui_impl.cpp
+++ b/client/render/imgui_impl.cpp
@@ -382,46 +382,9 @@ imgui_context::imgui_context(vk::raii::PhysicalDevice physical_device, vk::raii:
style.Colors[ImGuiCol_ModalWindowDimBg] = {0, 0, 0, 0};
}
-void imgui_context::add_chars(std::string_view sv)
-{
- for (auto it = sv.begin(); it != sv.end();)
- {
- ImWchar c = (ImWchar)*it;
- if (c < 0x80)
- ++it;
- else
- it += ImTextCharFromUtf8(&c, it, sv.end());
-
- if (!glyph_range_builder.GetBit(c))
- {
- glyph_range_builder.AddChar(c);
- glyph_range_dirty = true;
- }
- }
-}
-
#ifdef __ANDROID__
-static std::vector find_font(const ImFontGlyphRangesBuilder & glyph_range_builder, const std::string & locale)
+static std::vector find_font(std::u16string_view sample_text, const std::string & locale)
{
- std::u16string wtext;
- std::u16string_view wtextview;
- for (int i = 0; i < glyph_range_builder.UsedChars.Size; ++i)
- {
- std::uint32_t used_chars = glyph_range_builder.UsedChars[i];
- if (used_chars == 0)
- continue;
-
- for (int j = 0; j < 32; ++j)
- {
- ImWchar c = i * 32 + j;
- if (used_chars & (1 << j))
- {
- wtext += c;
- }
- }
- }
- wtextview = wtext;
-
AFontMatcher * font_matcher = AFontMatcher_create();
if (!font_matcher)
throw std::runtime_error("AFontMatcher_create");
@@ -432,18 +395,18 @@ static std::vector find_font(const ImFontGlyphRangesBuilder & glyph
std::vector fonts;
- while (!wtextview.empty())
+ while (!sample_text.empty())
{
uint32_t runlength = 0;
- AFont * font = AFontMatcher_match(font_matcher, "sans-serif", (uint16_t *)wtextview.data(), wtextview.size(), &runlength);
+ AFont * font = AFontMatcher_match(font_matcher, "sans-serif", (uint16_t *)sample_text.data(), sample_text.size(), &runlength);
fonts.emplace_back(AFont_getFontFilePath(font));
AFont_close(font);
if (runlength == 0)
break;
- wtextview = wtextview.substr(runlength);
+ sample_text = sample_text.substr(runlength);
}
AFontMatcher_destroy(font_matcher);
@@ -451,7 +414,7 @@ static std::vector find_font(const ImFontGlyphRangesBuilder & glyph
return fonts;
}
#else
-static std::vector find_font(ImFontGlyphRangesBuilder glyph_range_builder, const std::string & locale)
+static std::vector find_font(std::u16string sample_text, const std::string & locale)
{
// See https://www.camconn.cc/post/how-to-fontconfig-lib-c/
@@ -470,21 +433,8 @@ static std::vector find_font(ImFontGlyphRangesBuilder glyph_range_b
// Add the text to the pattern (to determine appropriate characters)
FcCharSet * charset = FcCharSetCreate();
- for (int i = 8; i < glyph_range_builder.UsedChars.Size; ++i)
- {
- std::uint32_t used_chars = glyph_range_builder.UsedChars[i];
- if (used_chars == 0)
- continue;
-
- for (int j = 0; j < 32; ++j)
- {
- ImWchar c = i * 32 + j;
- if (used_chars & (1 << j))
- {
- FcCharSetAddChar(charset, c);
- }
- }
- }
+ for (char16_t c: sample_text)
+ FcCharSetAddChar(charset, c);
FcPatternAddCharSet(pattern, FC_CHARSET, charset);
FcCharSetDestroy(charset);
@@ -513,28 +463,26 @@ static std::vector find_font(ImFontGlyphRangesBuilder glyph_range_b
continue;
bool keep_this_font = false;
- for (int i = 0; i < glyph_range_builder.UsedChars.Size; ++i)
- {
- std::uint32_t & used_chars = glyph_range_builder.UsedChars[i];
- if (used_chars == 0)
- continue;
- for (int j = 0; j < 32; ++j)
+ std::u16string tmp = sample_text;
+ for (int i = 0; i < tmp.size();)
+ {
+ char16_t c = tmp[i];
+
+ if (FcCharSetHasChar(font_charset, c))
{
- ImWchar c = i * 32 + j;
- if (used_chars & (1 << j))
- {
- if (FcCharSetHasChar(font_charset, c))
- {
- keep_this_font = true;
- used_chars &= ~(1 << j);
- }
- }
+ keep_this_font = true;
+
+ tmp[i] = tmp[tmp.size() - 1];
+ tmp.resize(tmp.size() - 1);
}
+ else
+ ++i;
}
if (keep_this_font)
fonts.emplace_back((const char *)font_file);
+ break;
}
FcFontSetDestroy(fs);
@@ -546,29 +494,19 @@ static std::vector find_font(ImFontGlyphRangesBuilder glyph_range_b
void imgui_context::initialize_fonts()
{
- glyph_ranges.clear();
+ std::u16string sample_text = u"Hello world";
- // Always include Basic Latin and Latin-1 Supplement without control characters
- ImWchar default_ranges[] = {0x20, 0x7f, 0xa0, 0xff, 0};
- glyph_range_builder.AddRanges(default_ranges);
+ const auto & locale = application::get_messages_info();
+ auto it = glyph_set_per_language.find(locale.language + "_" + locale.country);
+ if (it == glyph_set_per_language.end())
+ it = glyph_set_per_language.find(locale.language);
- {
- const auto & locale = application::get_messages_info();
- auto it = glyph_set_per_language.find(locale.language + "_" + locale.country);
- if (it == glyph_set_per_language.end())
- it = glyph_set_per_language.find(locale.language);
-
- if (it != glyph_set_per_language.end())
- {
- for (ImWchar c: it->second)
- glyph_range_builder.AddChar(c);
- }
- }
-
- glyph_range_builder.BuildRanges(&glyph_ranges);
+ if (it != glyph_set_per_language.end())
+ for (char16_t c: it->second)
+ sample_text += c;
// Load Fonts
- auto fonts = find_font(glyph_range_builder, application::get_messages_info().language);
+ auto fonts = find_font(sample_text, application::get_messages_info().language);
for (auto & i: fonts)
{
spdlog::info("Font {}", i);
@@ -577,40 +515,20 @@ void imgui_context::initialize_fonts()
asset font_awesome_regular("Font Awesome 6 Free-Regular-400.otf");
asset font_awesome_solid("Font Awesome 6 Free-Solid-900.otf");
- IM_DELETE(io.Fonts);
- io.Fonts = IM_NEW(ImFontAtlas);
+ ImFontConfig config;
+ config.FontDataOwnedByAtlas = false;
+ for (auto & font: fonts)
{
- ImFontConfig config;
- config.FontDataOwnedByAtlas = false;
-
- for (auto & font: fonts)
- {
- spdlog::info("Using font {}", font, application::get_messages_info().language);
- io.Fonts->AddFontFromFileTTF(font.c_str(), constants::gui::font_size_small, &config, glyph_ranges.Data);
- config.MergeMode = true;
- }
-
+ spdlog::info("Using font {}", font, application::get_messages_info().language);
+ io.Fonts->AddFontFromFileTTF(font.c_str(), constants::gui::font_size_small, &config);
config.MergeMode = true;
- config.GlyphMinAdvanceX = 40; // Use if you want to make the icon monospaced
- static const ImWchar icon_ranges[] = {ICON_MIN_FA, ICON_MAX_FA, 0};
- io.Fonts->AddFontFromMemoryTTF(const_cast(font_awesome_regular.data()), font_awesome_regular.size(), constants::gui::font_size_small, &config, icon_ranges);
- io.Fonts->AddFontFromMemoryTTF(const_cast(font_awesome_solid.data()), font_awesome_solid.size(), constants::gui::font_size_small, &config, icon_ranges);
}
- {
- ImFontConfig config;
- config.FontDataOwnedByAtlas = false;
- for (auto & font: fonts)
- {
- large_font = io.Fonts->AddFontFromFileTTF(font.c_str(), constants::gui::font_size_large, &config, glyph_ranges.Data);
- config.MergeMode = true;
- }
- }
-
- glyph_range_dirty = false;
-
- ImGui_ImplVulkan_CreateFontsTexture();
+ config.MergeMode = true;
+ config.GlyphMinAdvanceX = 40; // Use if you want to make the icon monospaced
+ io.Fonts->AddFontFromMemoryTTF(const_cast(font_awesome_regular.data()), font_awesome_regular.size(), constants::gui::font_size_small, &config);
+ io.Fonts->AddFontFromMemoryTTF(const_cast(font_awesome_solid.data()), font_awesome_solid.size(), constants::gui::font_size_small, &config);
}
std::vector imgui_context::read_controllers_state(XrTime display_time)
@@ -627,6 +545,9 @@ std::vector imgui_context::read_controllers_sta
controller_state & new_state = new_states.emplace_back();
+ if (not controllers_enabled)
+ continue;
+
if (ctrl.hand)
{
if (auto joints = ctrl.hand->locate(world, display_time))
@@ -841,24 +762,6 @@ void imgui_context::new_frame(XrTime display_time)
controller.second = next_state;
}
- // Force recreation of the font atlas
- if (glyph_range_dirty)
- {
- // Wait for fences before ImGui_ImplVulkan_DestroyFontsTexture is called
- std::vector fences;
- for (auto & f: command_buffers)
- {
- fences.push_back(*f.fence);
- }
-
- if (auto result = device.waitForFences(fences, true, 1'000'000'000); result != vk::Result::eSuccess)
- spdlog::error("vkWaitForfences: {}", vk::to_string(result));
-
- ImGui_ImplVulkan_DestroyFontsTexture();
- initialize_fonts();
- ImGui_ImplVulkan_CreateFontsTexture();
- }
-
// Start the Dear ImGui frame
ImGui_ImplVulkan_NewFrame();
@@ -876,10 +779,20 @@ void imgui_context::new_frame(XrTime display_time)
image_index = swapchain.acquire();
swapchain.wait();
+
+ hovered_item_prev = hovered_item;
+ hovered_item = 0;
}
std::vector> imgui_context::end_frame()
{
+ if (hovered_item != hovered_item_prev && hovered_item != 0)
+ {
+ size_t controller = get_focused_controller();
+ if (auto haptic_output = controllers[controller].first.haptic_output; haptic_output != XR_NULL_HANDLE)
+ application::haptic_start(haptic_output, XR_NULL_PATH, 10'000'000, 1000, 1);
+ }
+
vk::Image destination = swapchain.images()[image_index].image;
ImGui::SetCurrentContext(context);
@@ -1070,6 +983,17 @@ std::vector> imgui_context::end_frame()
return quads;
}
+void imgui_context::vibrate_on_hover()
+{
+ if (ImGui::IsItemHovered())
+ hovered_item = ImGui::GetItemID();
+}
+
+void imgui_context::set_hovered_item()
+{
+ hovered_item = ImGui::GetItemID();
+}
+
imgui_context::~imgui_context()
{
ImGui::SetCurrentContext(context);
@@ -1119,7 +1043,7 @@ ImTextureID imgui_context::load_texture(const std::string & filename, vk::raii::
device.updateDescriptorSets(ds_write, nullptr);
- ImTextureID id = *ds;
+ ImTextureID id = reinterpret_cast(VkDescriptorSet(*ds));
textures.emplace(
id,
@@ -1159,6 +1083,11 @@ void imgui_context::set_current()
ImPlot::SetCurrentContext(plot_context);
}
+void imgui_context::set_controllers_enabled(bool value)
+{
+ controllers_enabled = value;
+}
+
bool imgui_context::is_modal_popup_shown() const
{
return ImGui::GetTopMostAndVisiblePopupModal() != nullptr;
@@ -1174,3 +1103,50 @@ imgui_context::viewport & imgui_context::layer(ImVec2 position)
return layers_.front();
}
+
+void imgui_context::tooltip(std::string_view text)
+{
+ // FIXME: this is incorrect if we use the docking branch of imgui
+ ImGuiViewport * viewport = ImGui::GetMainViewport();
+ auto & current_layer = layer(ImGui::GetMousePos());
+ auto pos_backup = viewport->Pos;
+ auto size_backup = viewport->Size;
+ viewport->Pos = ImVec2(current_layer.vp_origin.x, current_layer.vp_origin.y);
+ viewport->Size = ImVec2(current_layer.vp_size.x, current_layer.vp_size.y);
+
+ ImVec2 pos{
+ (ImGui::GetItemRectMin().x + ImGui::GetItemRectMax().x) / 2,
+ ImGui::GetItemRectMin().y - constants::style::tooltip_distance,
+ };
+
+ ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, constants::style::tooltip_padding);
+ ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, constants::style::tooltip_rounding);
+
+ // Clamp position to avoid overflowing on the left or the right
+ auto & style = ImGui::GetStyle();
+ const ImVec2 text_size = ImGui::CalcTextSize(text.data(), text.data() + text.size(), true);
+ const ImVec2 size = {text_size.x + style.WindowPadding.x * 2.0f, text_size.y + style.WindowPadding.y * 2.0f};
+ pos.x = std::clamp(pos.x, viewport->Pos.x + size.x / 2, viewport->Pos.x + viewport->Size.x - size.x / 2);
+ ImVec2 pivot = {0.5, 1};
+
+ // Move tooltip below the item if it overflows on the top
+ if (pos.y - size.y <= viewport->Pos.y)
+ {
+ pos.y = ImGui::GetItemRectMax().y + constants::style::tooltip_distance;
+ pivot.y = 0;
+ }
+
+ ImGui::SetNextWindowPos(pos, ImGuiCond_Always, pivot);
+ if (ImGui::BeginTooltip())
+ {
+ ImGui::PushStyleColor(ImGuiCol_Text, 0xffffffff);
+ ImGui::TextUnformatted(text.data(), text.data() + text.size());
+ ImGui::PopStyleColor();
+ ImGui::EndTooltip();
+ }
+
+ ImGui::PopStyleVar(2);
+
+ viewport->Pos = pos_backup;
+ viewport->Size = size_backup;
+}
diff --git a/client/render/imgui_impl.h b/client/render/imgui_impl.h
index 95a507c9..cedb31a1 100644
--- a/client/render/imgui_impl.h
+++ b/client/render/imgui_impl.h
@@ -67,6 +67,8 @@ public:
XrAction scroll; // XR_ACTION_TYPE_VECTOR2F_INPUT
// TODO: thresholds?
+ XrAction haptic_output;
+
xr::hand_tracker * hand = nullptr;
};
@@ -153,13 +155,13 @@ private:
XrSpace world;
size_t focused_controller = (size_t)-1;
XrTime last_display_time = 0;
+ bool controllers_enabled = true;
bool button_pressed = false;
bool fingertip_touching = false;
- ImFontGlyphRangesBuilder glyph_range_builder;
- ImVector glyph_ranges;
- bool glyph_range_dirty = true;
+ ImGuiID hovered_item = 0; // Hovered item in the current frame, reset at the beginning of the frame
+ ImGuiID hovered_item_prev = 0; // Hovered item at the previous frame
#if WIVRN_SHOW_IMGUI_DEMO_WINDOW
bool show_demo_window = true;
@@ -192,7 +194,6 @@ public:
void new_frame(XrTime display_time);
std::vector> end_frame();
- ImFont * large_font;
size_t get_focused_controller() const
{
return focused_controller;
@@ -209,6 +210,10 @@ public:
void free_texture(ImTextureID);
void set_current();
- void add_chars(std::string_view sv);
bool is_modal_popup_shown() const;
+
+ void vibrate_on_hover();
+ void set_hovered_item();
+ void set_controllers_enabled(bool value);
+ void tooltip(std::string_view text);
};
diff --git a/client/render/scene_components.cpp b/client/render/scene_components.cpp
new file mode 100644
index 00000000..b1b35dba
--- /dev/null
+++ b/client/render/scene_components.cpp
@@ -0,0 +1,79 @@
+/*
+ * WiVRn VR streaming
+ * Copyright (C) 2024 Guillaume Meunier
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+#include "scene_components.h"
+#include
+#include
+
+entt::entity find_node_by_name(entt::registry & scene, std::string_view name)
+{
+ for (auto && [entity, node]: scene.view().each())
+ {
+ if (node.name == name)
+ return entity;
+ }
+
+ // TODO custom exception
+ throw std::runtime_error("Node \"" + (std::string)name + "\" not found");
+}
+
+entt::entity find_node_by_name(entt::registry & scene, std::string_view name, entt::entity parent)
+{
+ for (auto && [entity, node]: scene.view().each())
+ {
+ if (node.name != name)
+ continue;
+
+ auto current_parent = node.parent;
+
+ do
+ {
+ if (current_parent == parent)
+ return entity;
+ assert(current_parent != scene.get(current_parent).parent);
+ current_parent = scene.get(current_parent).parent;
+
+ } while (current_parent != entt::null);
+ }
+
+ // TODO custom exception
+ throw std::runtime_error("Node \"" + (std::string)name + "\" not found");
+}
+
+std::string get_node_name(const entt::registry & scene, entt::entity entity)
+{
+ auto name_parent = [&](entt::entity entity) -> std::pair {
+ const auto & node = scene.get(entity);
+ if (node.name == "")
+ return {std::to_string((int)entity), node.parent};
+ else
+ return {node.name, node.parent};
+ };
+
+ std::string name;
+ std::tie(name, entity) = name_parent(entity);
+
+ while (entity != entt::null)
+ {
+ std::string tmp;
+ std::tie(tmp, entity) = name_parent(entity);
+ name = tmp + "/" + name;
+ }
+
+ return name;
+}
diff --git a/client/render/scene_components.h b/client/render/scene_components.h
new file mode 100644
index 00000000..9b594947
--- /dev/null
+++ b/client/render/scene_components.h
@@ -0,0 +1,187 @@
+/*
+ * WiVRn VR streaming
+ * Copyright (C) 2025 Guillaume Meunier
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+#pragma once
+
+#include
+#include
+#include
+
+#include
+#include
+#include
+#include
+
+#include "utils/magic_hash.h"
+#include "vk/allocation.h"
+
+namespace renderer
+{
+struct sampler_info
+{
+ vk::Filter mag_filter = vk::Filter::eLinear;
+ vk::Filter min_filter = vk::Filter::eLinear;
+ vk::SamplerMipmapMode min_filter_mipmap = vk::SamplerMipmapMode::eLinear;
+ vk::SamplerAddressMode wrapS = vk::SamplerAddressMode::eRepeat;
+ vk::SamplerAddressMode wrapT = vk::SamplerAddressMode::eRepeat;
+
+ bool operator==(const sampler_info & other) const noexcept = default;
+};
+
+struct texture
+{
+ std::shared_ptr image_view;
+ sampler_info sampler;
+};
+
+struct material
+{
+ struct gpu_data
+ {
+ glm::vec4 base_color_factor = glm::vec4(1, 1, 1, 1);
+ glm::vec4 base_emissive_factor = glm::vec4(0, 0, 0, 0);
+ float metallic_factor = 1;
+ float roughness_factor = 1;
+ float occlusion_strength = 0;
+ float normal_scale = 0;
+
+ uint32_t base_color_texcoord = 0;
+ uint32_t metallic_roughness_texcoord = 0;
+ uint32_t occlusion_texcoord = 0;
+ uint32_t emissive_texcoord = 0;
+ uint32_t normal_texcoord = 0;
+
+ // TODO: add fastgltf::TextureTransform?
+ };
+
+ std::shared_ptr base_color_texture;
+ std::shared_ptr metallic_roughness_texture;
+ std::shared_ptr occlusion_texture;
+ std::shared_ptr emissive_texture;
+ std::shared_ptr normal_texture;
+
+ // Disable back face culling with this material
+ bool double_sided = true;
+
+ // TODO transparency
+ // fastgltf::AlphaMode alphaMode;
+ // float alpha_cutoff;
+
+ gpu_data staging;
+
+ // Resources used by this material
+ std::shared_ptr buffer;
+ size_t offset;
+
+ // The descriptor set is managed by the scene renderer, it is updated whenever ds_dirty is true
+ // Bindings 0-4: textures
+ // Binding 5: uniform buffer
+ std::shared_ptr ds;
+
+ // Set to true to update the descriptor set at the next frame
+ bool ds_dirty;
+
+ std::string name;
+ std::string shader_name = "lit";
+ bool blend_enable = true;
+};
+
+struct primitive
+{
+ bool indexed;
+ uint32_t index_count;
+ uint32_t vertex_count;
+ vk::IndexType index_type;
+ vk::DeviceSize index_offset;
+ vk::DeviceSize vertex_offset;
+
+ // See also material::double_sided
+ vk::CullModeFlagBits cull_mode = vk::CullModeFlagBits::eNone;
+ vk::FrontFace front_face = vk::FrontFace::eClockwise;
+ vk::PrimitiveTopology topology = vk::PrimitiveTopology::eTriangleList;
+
+ std::shared_ptr material_;
+};
+
+struct mesh
+{
+ std::vector primitives;
+ std::shared_ptr buffer;
+};
+
+// TODO move vertex class in .cpp, put vertex description in the primitive
+struct vertex
+{
+ glm::vec3 position;
+ glm::vec3 normal;
+ glm::vec3 tangent;
+ std::array texcoord;
+ glm::vec4 color;
+ std::array joints;
+ std::array weights;
+
+ struct description
+ {
+ vk::VertexInputBindingDescription binding;
+ std::vector attributes;
+ std::vector attribute_names;
+
+ vk::PipelineVertexInputStateCreateFlags flags{};
+ };
+
+ static description describe();
+};
+} // namespace renderer
+
+namespace std
+{
+template <>
+struct hash : utils::magic_hash
+{};
+} // namespace std
+
+namespace components
+{
+struct node
+{
+ entt::entity parent = entt::null;
+ std::string name;
+ std::shared_ptr mesh;
+
+ glm::vec3 position = {0, 0, 0};
+ glm::quat orientation = {1, 0, 0, 0};
+ glm::vec3 scale = {1, 1, 1};
+ bool visible = true;
+ uint32_t layer_mask = -1;
+
+ std::array clipping_planes;
+
+ // TODO: separate component?
+ std::vector> joints; // Node index, inverse bind matrix of each joint
+
+ // For internal use by the renderer
+ glm::mat4 transform_to_root;
+ bool global_visible;
+ bool reverse_side;
+ uint32_t global_layer_mask;
+};
+} // namespace components
+
+entt::entity find_node_by_name(entt::registry & scene, std::string_view name);
+entt::entity find_node_by_name(entt::registry & scene, std::string_view name, entt::entity parent);
+std::string get_node_name(const entt::registry & scene, entt::entity entity);
diff --git a/client/render/scene_data.cpp b/client/render/scene_data.cpp
index 03fe7212..e69de29b 100644
--- a/client/render/scene_data.cpp
+++ b/client/render/scene_data.cpp
@@ -1,992 +0,0 @@
-/*
- * WiVRn VR streaming
- * Copyright (C) 2022 Guillaume Meunier
- * Copyright (C) 2022 Patrick Nicolas
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
- */
-
-#include "render/scene_data.h"
-
-#include "image_loader.h"
-#include "render/gpu_buffer.h"
-#include "utils/fmt_glm.h"
-#include "utils/ranges.h"
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-
-#include "asset.h"
-
-template
-constexpr vk::Format vk_attribute_format = vk::Format::eUndefined;
-template <>
-constexpr vk::Format vk_attribute_format = vk::Format::eR32Sfloat;
-template <>
-constexpr vk::Format vk_attribute_format = vk::Format::eR32G32Sfloat;
-template <>
-constexpr vk::Format vk_attribute_format = vk::Format::eR32G32B32Sfloat;
-template <>
-constexpr vk::Format vk_attribute_format = vk::Format::eR32G32B32A32Sfloat;
-template
-constexpr vk::Format vk_attribute_format> = vk_attribute_format;
-
-template
-constexpr size_t nb_attributes = 1;
-template
-constexpr size_t nb_attributes> = N;
-
-template
-struct remove_array
-{
- using type = T;
-};
-template
-struct remove_array>
-{
- using type = T;
-};
-template
-using remove_array_t = remove_array::type;
-
-template
-struct is_array : std::false_type
-{
-};
-
-template
-struct is_array> : std::true_type
-{
-};
-
-template
-constexpr bool is_array_v = is_array::value;
-
-scene_data::vertex::description scene_data::vertex::describe()
-{
- scene_data::vertex::description desc;
-
- desc.binding = vk::VertexInputBindingDescription{
- .binding = 0,
- .stride = sizeof(vertex),
- .inputRate = vk::VertexInputRate::eVertex,
- };
-
- vk::VertexInputAttributeDescription attribute{
- .location = 0,
- .binding = 0,
- };
-
-#define VERTEX_ATTR(member) \
- attribute.format = vk_attribute_format; \
- for (size_t i = 0; i < nb_attributes; i++) \
- { \
- attribute.offset = offsetof(vertex, member) + i * sizeof(remove_array_t); \
- desc.attributes.push_back(attribute); \
- attribute.location++; \
- if (is_array_v) \
- { \
- desc.attribute_names.push_back(#member "_" + std::to_string(i)); \
- } \
- else \
- { \
- desc.attribute_names.push_back(#member); \
- } \
- }
-
- VERTEX_ATTR(position);
- VERTEX_ATTR(normal);
- VERTEX_ATTR(tangent);
- VERTEX_ATTR(texcoord);
- VERTEX_ATTR(color);
- VERTEX_ATTR(joints);
- VERTEX_ATTR(weights);
-
- static_assert(vertex{}.joints.size() == vertex{}.weights.size());
-
- return desc;
-}
-
-// Conversion functions gltf -> vulkan
-namespace
-{
-fastgltf::Asset load_gltf_asset(fastgltf::GltfDataBuffer & buffer, const std::filesystem::path & directory)
-{
- fastgltf::Parser parser(fastgltf::Extensions::KHR_texture_basisu);
-
- auto gltf_options =
- fastgltf::Options::DontRequireValidAssetMember |
- fastgltf::Options::AllowDouble |
- fastgltf::Options::LoadGLBBuffers |
- fastgltf::Options::DecomposeNodeMatrices;
-
- auto expected_asset = parser.loadGltf(&buffer, directory, gltf_options);
-
- if (auto error = expected_asset.error(); error != fastgltf::Error::None)
- throw std::runtime_error(std::string(fastgltf::getErrorMessage(error)));
-
- return std::move(expected_asset.get());
-}
-
-std::pair convert(fastgltf::Filter filter)
-{
- switch (filter)
- {
- case fastgltf::Filter::Nearest:
- case fastgltf::Filter::NearestMipMapNearest:
- return {vk::Filter::eNearest, vk::SamplerMipmapMode::eNearest};
-
- case fastgltf::Filter::Linear:
- case fastgltf::Filter::LinearMipMapNearest:
- return {vk::Filter::eLinear, vk::SamplerMipmapMode::eNearest};
-
- case fastgltf::Filter::NearestMipMapLinear:
- return {vk::Filter::eNearest, vk::SamplerMipmapMode::eLinear};
-
- case fastgltf::Filter::LinearMipMapLinear:
- return {vk::Filter::eLinear, vk::SamplerMipmapMode::eLinear};
- }
-
- throw std::invalid_argument("filter");
-}
-
-vk::SamplerAddressMode convert(fastgltf::Wrap wrap)
-{
- switch (wrap)
- {
- case fastgltf::Wrap::ClampToEdge:
- return vk::SamplerAddressMode::eClampToEdge;
-
- case fastgltf::Wrap::MirroredRepeat:
- return vk::SamplerAddressMode::eMirroredRepeat;
-
- case fastgltf::Wrap::Repeat:
- return vk::SamplerAddressMode::eRepeat;
- }
-
- throw std::invalid_argument("wrap");
-}
-
-sampler_info convert(fastgltf::Sampler & sampler)
-{
- sampler_info info;
-
- info.mag_filter = convert(sampler.magFilter.value_or(fastgltf::Filter::Linear)).first;
-
- std::tie(info.min_filter, info.min_filter_mipmap) = convert(sampler.minFilter.value_or(fastgltf::Filter::LinearMipMapLinear));
-
- info.wrapS = convert(sampler.wrapS);
- info.wrapT = convert(sampler.wrapT);
-
- return info;
-}
-
-vk::PrimitiveTopology convert(fastgltf::PrimitiveType type)
-{
- switch (type)
- {
- case fastgltf::PrimitiveType::Points:
- return vk::PrimitiveTopology::ePointList;
-
- case fastgltf::PrimitiveType::Lines:
- return vk::PrimitiveTopology::eLineList;
-
- case fastgltf::PrimitiveType::LineLoop:
- throw std::runtime_error("Unimplemented");
-
- case fastgltf::PrimitiveType::LineStrip:
- return vk::PrimitiveTopology::eLineStrip;
-
- case fastgltf::PrimitiveType::Triangles:
- return vk::PrimitiveTopology::eTriangleList;
-
- case fastgltf::PrimitiveType::TriangleStrip:
- return vk::PrimitiveTopology::eTriangleStrip;
-
- case fastgltf::PrimitiveType::TriangleFan:
- return vk::PrimitiveTopology::eTriangleFan;
- }
-
- throw std::invalid_argument("type");
-}
-
-glm::vec4 convert(const std::array & v)
-{
- return {v[0], v[1], v[2], v[3]};
-}
-
-glm::vec3 convert(const std::array & v)
-{
- return {v[0], v[1], v[2]};
-}
-} // namespace
-
-template
- requires is_array_v
-void copy_vertex_attributes(
- const fastgltf::Asset & asset,
- const fastgltf::Primitive & primitive,
- std::string attribute_name,
- std::vector & vertices,
- T scene_data::vertex::*attribute)
-{
- using U = T::value_type;
- constexpr size_t N = std::tuple_size_v;
-
- for (size_t i = 0; i < N; i++)
- {
- auto it = primitive.findAttribute(attribute_name + std::to_string(i));
-
- if (it == primitive.attributes.end())
- continue;
-
- const fastgltf::Accessor & accessor = asset.accessors.at(it->second);
-
- if (vertices.size() < accessor.count)
- vertices.resize(accessor.count, {});
-
- fastgltf::iterateAccessorWithIndex(asset, accessor, [&](U value, std::size_t idx) {
- (vertices[idx].*attribute)[i] = value;
- });
- }
-}
-
-template
- requires(!is_array_v)
-void copy_vertex_attributes(
- const fastgltf::Asset & asset,
- const fastgltf::Primitive & primitive,
- std::string attribute_name,
- std::vector & vertices,
- T scene_data::vertex::*attribute)
-{
- auto it = primitive.findAttribute(attribute_name);
-
- if (it == primitive.attributes.end())
- return;
-
- const fastgltf::Accessor & accessor = asset.accessors.at(it->second);
-
- if (vertices.size() < accessor.count)
- vertices.resize(accessor.count, {});
-
- fastgltf::iterateAccessorWithIndex(asset, accessor, [&](T value, std::size_t idx) {
- vertices[idx].*attribute = value;
- });
-}
-
-namespace
-{
-constexpr bool starts_with(std::span data, std::span prefix)
-{
- return data.size() >= prefix.size() && !memcmp(data.data(), prefix.data(), prefix.size());
-}
-
-fastgltf::MimeType guess_mime_type(std::span image_data)
-{
- const uint8_t jpeg_magic[] = {0xFF, 0xD8, 0xFF};
- const uint8_t png_magic[] = {0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A};
- const uint8_t ktx1_magic[] = {0xAB, 0x4B, 0x54, 0x58, 0x20, 0x31, 0x31, 0xBB, 0x0D, 0x0A, 0x1A, 0x0A};
- const uint8_t ktx2_magic[] = {0xAB, 0x4B, 0x54, 0x58, 0x20, 0x32, 0x30, 0xBB, 0x0D, 0x0A, 0x1A, 0x0A};
-
- if (starts_with(image_data, png_magic))
- return fastgltf::MimeType::PNG;
- else if (starts_with(image_data, jpeg_magic))
- return fastgltf::MimeType::JPEG;
- else if (starts_with(image_data, ktx1_magic))
- return fastgltf::MimeType::KTX2;
- else if (starts_with(image_data, ktx2_magic))
- return fastgltf::MimeType::KTX2;
- else
- return fastgltf::MimeType::None;
-}
-
-std::shared_ptr do_load_image(
- vk::raii::PhysicalDevice & physical_device,
- vk::raii::Device & device,
- vk::raii::Queue & queue,
- vk::raii::CommandPool & cb_pool,
- std::span image_data,
- bool srgb)
-{
- switch (guess_mime_type(image_data))
- {
- case fastgltf::MimeType::JPEG:
- case fastgltf::MimeType::PNG:
- case fastgltf::MimeType::KTX2: {
- try
- {
- image_loader loader(physical_device, device, queue, cb_pool);
- loader.load(image_data, srgb);
-
- spdlog::debug("Loaded image {}x{}, format {}, {} mipmaps", loader.extent.width, loader.extent.height, vk::to_string(loader.format), loader.num_mipmaps);
- return loader.image_view;
- }
- catch (std::exception & e)
- {
- spdlog::info("Cannot load image: {}", e.what());
- return {};
- }
- }
-
- default:
- spdlog::error("Unsupported image MIME type");
- return {};
- }
-}
-
-class loader_context
-{
- std::filesystem::path base_directory;
- fastgltf::Asset & gltf;
- vk::raii::PhysicalDevice physical_device;
- vk::raii::Device & device;
- vk::raii::Queue & queue;
- vk::raii::CommandPool & cb_pool;
-
- std::vector loaded_assets;
- asset & load_from_asset(const std::filesystem::path & path)
- {
- return loaded_assets.emplace_back(path);
- }
-
-public:
- loader_context(std::filesystem::path base_directory,
- fastgltf::Asset & gltf,
- vk::raii::PhysicalDevice physical_device,
- vk::raii::Device & device,
- vk::raii::Queue & queue,
- vk::raii::CommandPool & cb_pool) :
- base_directory(base_directory),
- gltf(gltf),
- physical_device(physical_device),
- device(device),
- queue(queue),
- cb_pool(cb_pool)
- {
- }
-
- fastgltf::span load(const fastgltf::URI & uri)
- {
- auto path = base_directory.empty() ? std::filesystem::path(uri.path()) : base_directory / std::filesystem::path(uri.path());
- std::span bytes;
-
- bytes = load_from_asset(path);
-
- return fastgltf::span(bytes.data(), bytes.size());
- }
-
- fastgltf::span load(const fastgltf::sources::URI & uri)
- {
- return load(uri.uri);
- }
-
- template
- fastgltf::span subspan(fastgltf::span span, size_t offset, size_t count = fastgltf::dynamic_extent)
- {
- assert(offset < span.size());
- assert(count == fastgltf::dynamic_extent || count <= span.size() - offset);
-
- if (count == fastgltf::dynamic_extent)
- count = span.size() - offset;
-
- return fastgltf::span{span.data() + offset, count};
- }
-
- fastgltf::sources::ByteView visit_source(fastgltf::DataSource & source)
- {
- using return_type = fastgltf::sources::ByteView;
-
- return std::visit(fastgltf::visitor{
- [&](std::monostate) -> return_type {
- throw std::runtime_error("Invalid source");
- },
- [&](fastgltf::sources::Fallback) -> return_type {
- throw std::runtime_error("Invalid source");
- },
- [&](const fastgltf::sources::BufferView & buffer_view) -> return_type {
- fastgltf::BufferView & view = gltf.bufferViews.at(buffer_view.bufferViewIndex);
-
- fastgltf::Buffer & buffer = gltf.buffers.at(view.bufferIndex);
-
- auto buffer2 = visit_source(buffer.data);
-
- return {subspan(buffer2.bytes, view.byteOffset, view.byteLength), buffer_view.mimeType};
- },
- [&](const fastgltf::sources::URI & uri) -> return_type {
- if (!uri.uri.isLocalPath())
- throw std::runtime_error("Non local paths are not supported"); // TODO ?
-
- fastgltf::span data = load(uri);
-
- // Don't use the MIME type from fastgltf, it's not initialized for URIs
- return {subspan(data, uri.fileByteOffset), fastgltf::MimeType::None};
- },
- [&](const fastgltf::sources::Vector & vector) -> return_type {
- fastgltf::span data{reinterpret_cast(vector.bytes.data()), vector.bytes.size()};
- return {data, vector.mimeType};
- },
- [&](const fastgltf::sources::Array & array) -> return_type {
- fastgltf::span data{reinterpret_cast(array.bytes.data()), array.bytes.size()};
- return {data, array.mimeType};
- },
- [&](const fastgltf::sources::CustomBuffer & custom_buffer) -> return_type {
- throw std::runtime_error("Unimplemented source CustomBuffer");
- // TODO ?
- },
- [&](fastgltf::sources::ByteView & byte_view) -> return_type {
- return {byte_view.bytes, byte_view.mimeType};
- }},
- source);
- }
-
- std::unordered_map> images;
- std::shared_ptr load_image(int index, bool srgb)
- {
- auto it = images.find(index);
- if (it != images.end())
- return it->second;
-
- try
- {
- auto [image_data, mime_type] = visit_source(gltf.images[index].data);
- auto image = do_load_image(physical_device, device, queue, cb_pool, image_data, srgb);
-
- images.emplace(index, image);
- return image;
- }
- catch (...)
- {
- return nullptr;
- }
- }
-
- std::vector> load_all_textures()
- {
- // Determine which texture is sRGB
- std::vector srgb_array;
- srgb_array.resize(gltf.textures.size(), false);
- for (const fastgltf::Material & gltf_material: gltf.materials)
- {
- if (gltf_material.pbrData.baseColorTexture)
- srgb_array.at(gltf_material.pbrData.baseColorTexture->textureIndex) = true;
-
- if (gltf_material.emissiveTexture)
- srgb_array.at(gltf_material.emissiveTexture->textureIndex) = true;
- }
-
- std::vector> textures;
- textures.reserve(gltf.textures.size());
- for (auto && [srgb, gltf_texture]: std::views::zip(srgb_array, gltf.textures))
- {
- auto & texture_ref = *textures.emplace_back(std::make_shared());
-
- if (gltf_texture.samplerIndex)
- {
- fastgltf::Sampler & sampler = gltf.samplers.at(*gltf_texture.samplerIndex);
- texture_ref.sampler = convert(sampler);
- }
-
- if (gltf_texture.basisuImageIndex)
- {
- texture_ref.image_view = load_image(*gltf_texture.basisuImageIndex, srgb);
- if (texture_ref.image_view)
- continue;
- }
-
- // if (gltf_texture.ddsImageIndex)
- // {
- // // TODO
- // }
-
- // if (gltf_texture.webpImageIndex)
- // {
- // // TODO
- // }
-
- if (gltf_texture.imageIndex)
- {
- texture_ref.image_view = load_image(*gltf_texture.imageIndex, srgb);
- if (texture_ref.image_view)
- continue;
- }
-
- throw std::runtime_error("Unsupported image type");
- }
-
- return textures;
- }
-
- void load_all_buffers()
- {
- for (fastgltf::Buffer & buffer: gltf.buffers)
- {
- if (std::holds_alternative(buffer.data))
- {
- fastgltf::sources::URI uri = std::get(buffer.data);
-
- // Don't use the MIME type from fastgltf, it's not initialized for URIs
- buffer.data = fastgltf::sources::ByteView(load(uri), fastgltf::MimeType::None);
- }
- }
- }
-
- std::vector> load_all_materials(std::vector> & textures, gpu_buffer & staging_buffer, const scene_data::material & default_material)
- {
- std::vector> materials;
- materials.reserve(gltf.materials.size());
- for (const fastgltf::Material & gltf_material: gltf.materials)
- {
- // Copy the default material, without references to its buffer or descriptor set
- auto & material_ref = *materials.emplace_back(std::make_shared(default_material));
- material_ref.name = gltf_material.name;
- spdlog::info("Loading material \"{}\"", material_ref.name);
- material_ref.buffer.reset();
- material_ref.ds.reset();
-
- material_ref.double_sided = gltf_material.doubleSided;
-
- scene_data::material::gpu_data & material_data = material_ref.staging;
-
- material_data.base_color_factor = convert(gltf_material.pbrData.baseColorFactor);
- material_data.base_emissive_factor = glm::vec4(convert(gltf_material.emissiveFactor), 0);
- material_data.metallic_factor = gltf_material.pbrData.metallicFactor;
- material_data.roughness_factor = gltf_material.pbrData.roughnessFactor;
-
- if (gltf_material.pbrData.baseColorTexture)
- {
- material_ref.base_color_texture = textures.at(gltf_material.pbrData.baseColorTexture->textureIndex);
- material_data.base_color_texcoord = gltf_material.pbrData.baseColorTexture->texCoordIndex;
- }
-
- if (gltf_material.pbrData.metallicRoughnessTexture)
- {
- material_ref.metallic_roughness_texture = textures.at(gltf_material.pbrData.metallicRoughnessTexture->textureIndex);
- material_data.metallic_roughness_texcoord = gltf_material.pbrData.metallicRoughnessTexture->texCoordIndex;
- }
-
- if (gltf_material.occlusionTexture)
- {
- material_ref.occlusion_texture = textures.at(gltf_material.occlusionTexture->textureIndex);
- material_data.occlusion_texcoord = gltf_material.occlusionTexture->texCoordIndex;
- material_data.occlusion_strength = gltf_material.occlusionTexture->strength;
- }
-
- if (gltf_material.emissiveTexture)
- {
- material_ref.emissive_texture = textures.at(gltf_material.emissiveTexture->textureIndex);
- material_data.emissive_texcoord = gltf_material.emissiveTexture->texCoordIndex;
- }
-
- if (gltf_material.normalTexture)
- {
- material_ref.normal_texture = textures.at(gltf_material.normalTexture->textureIndex);
- material_data.normal_texcoord = gltf_material.normalTexture->texCoordIndex;
- material_data.normal_scale = gltf_material.normalTexture->scale;
- }
-
- material_ref.offset = staging_buffer.add_uniform(material_data);
- }
-
- return materials;
- }
-
- std::vector load_all_meshes(std::vector> & materials, gpu_buffer & staging_buffer)
- {
- std::vector meshes;
- meshes.reserve(gltf.meshes.size());
- for (const fastgltf::Mesh & gltf_mesh: gltf.meshes)
- {
- auto & mesh_ref = meshes.emplace_back();
-
- mesh_ref.primitives.reserve(gltf_mesh.primitives.size());
-
- for (const fastgltf::Primitive & gltf_primitive: gltf_mesh.primitives)
- {
- auto & primitive_ref = mesh_ref.primitives.emplace_back();
-
- if (gltf_primitive.indicesAccessor)
- {
- fastgltf::Accessor & indices_accessor = gltf.accessors.at(*gltf_primitive.indicesAccessor);
-
- primitive_ref.indexed = true;
- primitive_ref.index_offset = staging_buffer.add_indices(indices_accessor);
- primitive_ref.index_count = indices_accessor.count;
-
- switch (indices_accessor.componentType)
- {
- case fastgltf::ComponentType::Byte:
- case fastgltf::ComponentType::UnsignedByte:
- primitive_ref.index_type = vk::IndexType::eUint8EXT;
- break;
-
- case fastgltf::ComponentType::Short:
- case fastgltf::ComponentType::UnsignedShort:
- primitive_ref.index_type = vk::IndexType::eUint16;
- break;
-
- case fastgltf::ComponentType::Int:
- case fastgltf::ComponentType::UnsignedInt:
- primitive_ref.index_type = vk::IndexType::eUint32;
- break;
-
- default:
- throw std::runtime_error("Invalid index type");
- break;
- }
- }
- else
- {
- primitive_ref.indexed = false;
- }
-
- std::vector vertices;
-
- copy_vertex_attributes(gltf, gltf_primitive, "POSITION", vertices, &scene_data::vertex::position);
- copy_vertex_attributes(gltf, gltf_primitive, "NORMAL", vertices, &scene_data::vertex::normal);
- copy_vertex_attributes(gltf, gltf_primitive, "TANGENT", vertices, &scene_data::vertex::tangent);
- copy_vertex_attributes(gltf, gltf_primitive, "TEXCOORD_", vertices, &scene_data::vertex::texcoord);
- copy_vertex_attributes(gltf, gltf_primitive, "COLOR", vertices, &scene_data::vertex::color);
- copy_vertex_attributes(gltf, gltf_primitive, "JOINTS_", vertices, &scene_data::vertex::joints);
- copy_vertex_attributes(gltf, gltf_primitive, "WEIGHTS_", vertices, &scene_data::vertex::weights);
-
- primitive_ref.vertex_offset = staging_buffer.add_vertices(vertices);
- primitive_ref.vertex_count = vertices.size();
-
- primitive_ref.cull_mode = vk::CullModeFlagBits::eBack; // TBC
- primitive_ref.front_face = vk::FrontFace::eCounterClockwise; // TBC
- primitive_ref.topology = convert(gltf_primitive.type);
-
- if (gltf_primitive.materialIndex)
- primitive_ref.material_ = materials.at(*gltf_primitive.materialIndex);
- }
- }
-
- return meshes;
- }
-
- std::vector load_all_nodes()
- {
- std::vector unsorted_objects;
- unsorted_objects.resize(gltf.nodes.size(), {.parent_id = scene_data::node::root_id});
-
- for (const auto & [index, gltf_node]: utils::enumerate(gltf.nodes))
- {
- if (gltf_node.meshIndex)
- unsorted_objects[index].mesh_id = *gltf_node.meshIndex;
-
- if (gltf_node.skinIndex)
- {
- auto & skin = gltf.skins.at(*gltf_node.skinIndex);
-
- unsorted_objects[index].joints.resize(skin.joints.size());
-
- for (auto [i, joint_index]: utils::enumerate(skin.joints))
- unsorted_objects[index].joints.at(i).first = joint_index;
-
- if (skin.inverseBindMatrices)
- {
- const fastgltf::Accessor & accessor = gltf.accessors.at(*skin.inverseBindMatrices);
-
- fastgltf::iterateAccessorWithIndex(gltf, accessor, [&](const glm::mat4 & value, std::size_t idx) {
- unsorted_objects[index].joints.at(idx).second = value;
- });
- }
- }
-
- for (size_t child: gltf_node.children)
- {
- unsorted_objects[child].parent_id = index;
- }
-
- auto TRS = std::get(gltf_node.transform);
-
- unsorted_objects[index].position = glm::make_vec3(TRS.translation.data());
- unsorted_objects[index].orientation = glm::make_quat(TRS.rotation.data());
- unsorted_objects[index].scale = glm::make_vec3(TRS.scale.data());
- unsorted_objects[index].visible = true;
- unsorted_objects[index].name = gltf_node.name;
- std::ranges::fill(unsorted_objects[index].clipping_planes, glm::vec4{0, 0, 0, 1});
- }
-
- return unsorted_objects;
- }
-
- std::vector topological_sort(const std::vector & unsorted_nodes)
- {
- std::vector sorted_nodes;
- std::vector new_index;
- std::vector already_sorted;
-
- sorted_nodes.reserve(unsorted_nodes.size());
- already_sorted.resize(unsorted_nodes.size(), false);
- new_index.resize(unsorted_nodes.size(), scene_data::node::root_id);
-
- [[maybe_unused]] bool loop_detected = true;
-
- while (sorted_nodes.size() < unsorted_nodes.size())
- {
- for (size_t i = 0; i < unsorted_nodes.size(); i++)
- {
- if (already_sorted[i])
- continue;
-
- if (unsorted_nodes[i].parent_id == scene_data::node::root_id)
- {
- sorted_nodes.push_back(unsorted_nodes[i]);
- already_sorted[i] = true;
- new_index[i] = sorted_nodes.size() - 1;
- loop_detected = false;
- }
- else if (already_sorted[unsorted_nodes[i].parent_id])
- {
- sorted_nodes.emplace_back(unsorted_nodes[i]).parent_id = new_index[unsorted_nodes[i].parent_id];
- already_sorted[i] = true;
- new_index[i] = sorted_nodes.size() - 1;
- loop_detected = false;
- }
- }
-
- assert(!loop_detected);
- }
-
- // renumber joint indices
- for (auto & node: sorted_nodes)
- {
- for (auto & joint: node.joints)
- {
- joint.first = new_index[joint.first];
- }
- }
-
- assert(sorted_nodes.size() == unsorted_nodes.size());
- for (size_t i = 0; i < sorted_nodes.size(); i++)
- {
- assert(sorted_nodes[i].parent_id == scene_data::node::root_id || sorted_nodes[i].parent_id < i);
- }
-
- return sorted_nodes;
- }
-};
-
-} // namespace
-
-scene_data scene_loader::operator()(const std::filesystem::path & gltf_path)
-{
- vk::PhysicalDeviceProperties physical_device_properties = physical_device.getProperties();
- vk::raii::CommandPool cb_pool{device, vk::CommandPoolCreateInfo{
- .flags = vk::CommandPoolCreateFlagBits::eTransient | vk::CommandPoolCreateFlagBits::eResetCommandBuffer,
- .queueFamilyIndex = queue_family_index,
- }};
-
- scene_data data;
-
- asset asset_file(gltf_path);
- fastgltf::GltfDataBuffer data_buffer;
- data_buffer.copyBytes(reinterpret_cast(asset_file.data()), asset_file.size());
-
- fastgltf::Asset asset = load_gltf_asset(data_buffer, gltf_path.parent_path());
- loader_context ctx(gltf_path.parent_path(), asset, physical_device, device, queue, cb_pool);
-
-#ifndef NDEBUG
- if (auto error = fastgltf::validate(asset); error != fastgltf::Error::None)
- throw std::runtime_error(std::string(fastgltf::getErrorMessage(error)));
-#endif
-
- // Load all buffers from URIs
- ctx.load_all_buffers();
-
- gpu_buffer staging_buffer(physical_device_properties, asset);
-
- // Load all textures
- auto textures = ctx.load_all_textures();
-
- // Load all materials
- auto materials = ctx.load_all_materials(textures, staging_buffer, *default_material);
-
- // Load all meshes
- data.meshes = ctx.load_all_meshes(materials, staging_buffer);
-
- data.scene_nodes = ctx.topological_sort(ctx.load_all_nodes());
-
- // Copy the staging buffer to the GPU
- spdlog::debug("Uploading scene data ({} bytes) to GPU memory", staging_buffer.size());
- auto buffer = std::make_shared(staging_buffer.copy_to_gpu());
-
- for (auto & i: materials)
- i->buffer = buffer;
-
- for (auto & i: data.meshes)
- i.buffer = buffer;
-
- return data;
-}
-
-scene_data & scene_data::import(scene_data && other, node_handle parent)
-{
- assert(parent.scene == this || parent.id == node::root_id);
-
- size_t mesh_offset = meshes.size();
- size_t nodes_offset = scene_nodes.size();
-
- for (auto & mesh: other.meshes)
- meshes.push_back(std::move(mesh));
-
- for (auto node: other.scene_nodes)
- {
- assert(!node.mesh_id || *node.mesh_id < other.meshes.size());
-
- if (node.mesh_id)
- *node.mesh_id += mesh_offset;
-
- for (auto & joint: node.joints)
- {
- joint.first += nodes_offset;
- }
-
- if (node.parent_id == node::root_id)
- {
- node.parent_id = parent.id;
- }
- else
- {
- assert(node.parent_id < other.scene_nodes.size());
- node.parent_id += nodes_offset;
- }
-
- scene_nodes.push_back(node);
- }
-
- other.meshes.clear();
- other.scene_nodes.clear();
-
- return *this;
-}
-
-scene_data & scene_data::import(scene_data && other)
-{
- return import(std::move(other), {});
-}
-
-node_handle scene_data::new_node()
-{
- size_t id = scene_nodes.size();
-
- scene_nodes.push_back(node{
- .parent_id = node::root_id,
- .position = {0, 0, 0},
- .orientation = {1, 0, 0, 0},
- .scale = {1, 1, 1},
- .visible = true});
-
- return {id, this};
-}
-
-node_handle scene_data::find_node(std::string_view name)
-{
- for (auto && [index, node]: utils::enumerate(scene_nodes))
- {
- if (node.name == name)
- {
- return {index, this};
- }
- }
-
- // TODO custom exception
- throw std::runtime_error("Node " + std::string(name) + " not found");
-}
-
-node_handle scene_data::find_node(node_handle root, std::string_view name)
-{
- assert(root.id < scene_nodes.size());
- assert(root.scene == this);
-
- std::vector flag(scene_nodes.size(), false);
-
- flag[root.id] = true;
-
- for (size_t index = root.id; index < scene_nodes.size(); index++)
- {
- size_t parent = scene_nodes[index].parent_id;
-
- if (parent == node::root_id)
- continue;
-
- if (!flag[parent])
- continue;
-
- if (scene_nodes[index].name == name)
- return {index, this};
-
- flag[index] = true;
- }
-
- // TODO custom exception
- throw std::runtime_error("Node " + std::string(name) + " not found");
-}
-
-std::vector scene_data::find_children(node_handle root)
-{
- assert(root.id < scene_nodes.size());
- assert(root.scene == this);
-
- std::vector flag(scene_nodes.size(), false);
-
- flag[root.id] = true;
-
- std::vector nodes;
-
- for (size_t index = root.id; index < scene_nodes.size(); index++)
- {
- size_t parent = scene_nodes[index].parent_id;
-
- if (parent == node::root_id)
- continue;
-
- if (!flag[parent])
- continue;
-
- nodes.emplace_back(index, this);
-
- flag[index] = true;
- }
-
- return nodes;
-}
-
-std::shared_ptr scene_data::find_material(std::string_view name)
-{
- for (auto & mesh: meshes)
- {
- for (auto & primitive: mesh.primitives)
- {
- if (primitive.material_ && primitive.material_->name == name)
- return primitive.material_;
- }
- }
-
- return {};
-}
diff --git a/client/render/scene_data.h b/client/render/scene_data.h
index b51671b1..e69de29b 100644
--- a/client/render/scene_data.h
+++ b/client/render/scene_data.h
@@ -1,295 +0,0 @@
-/*
- * WiVRn VR streaming
- * Copyright (C) 2022 Guillaume Meunier
- * Copyright (C) 2022 Patrick Nicolas
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
- */
-
-#pragma once
-
-#include "utils/magic_hash.h"
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-
-struct sampler_info
-{
- vk::Filter mag_filter = vk::Filter::eLinear;
- vk::Filter min_filter = vk::Filter::eLinear;
- vk::SamplerMipmapMode min_filter_mipmap = vk::SamplerMipmapMode::eLinear;
- vk::SamplerAddressMode wrapS = vk::SamplerAddressMode::eRepeat;
- vk::SamplerAddressMode wrapT = vk::SamplerAddressMode::eRepeat;
-
- bool operator==(const sampler_info & other) const noexcept = default;
-};
-
-namespace std
-{
-template <>
-struct hash : utils::magic_hash
-{};
-} // namespace std
-
-class node_handle;
-
-struct scene_data
-{
- struct texture
- {
- std::shared_ptr image_view;
- sampler_info sampler;
- };
-
- struct material
- {
- struct gpu_data
- {
- glm::vec4 base_color_factor = glm::vec4(1, 1, 1, 1);
- glm::vec4 base_emissive_factor = glm::vec4(0, 0, 0, 0);
- float metallic_factor = 1;
- float roughness_factor = 1;
- float occlusion_strength = 0;
- float normal_scale = 0;
-
- uint32_t base_color_texcoord = 0;
- uint32_t metallic_roughness_texcoord = 0;
- uint32_t occlusion_texcoord = 0;
- uint32_t emissive_texcoord = 0;
- uint32_t normal_texcoord = 0;
-
- // TODO: add fastgltf::TextureTransform?
- };
-
- std::shared_ptr base_color_texture;
- std::shared_ptr metallic_roughness_texture;
- std::shared_ptr occlusion_texture;
- std::shared_ptr emissive_texture;
- std::shared_ptr normal_texture;
-
- // Disable back face culling with this material
- bool double_sided = true;
-
- // TODO transparency
- // fastgltf::AlphaMode alphaMode;
- // float alpha_cutoff;
-
- gpu_data staging;
-
- // Resources used by this material
- std::shared_ptr buffer;
- size_t offset;
-
- // The descriptor set is managed by the scene renderer, it is updated whenever ds_dirty is true
- // Bindings 0-4: textures
- // Binding 5: uniform buffer
- std::shared_ptr ds;
-
- // Set to true to update the descriptor set at the next frame
- bool ds_dirty;
-
- std::string name;
- std::string shader_name = "lit";
- bool blend_enable = true;
- };
-
- struct vertex
- {
- glm::vec3 position;
- glm::vec3 normal;
- glm::vec3 tangent;
- std::array texcoord;
- glm::vec4 color;
- std::array joints;
- std::array weights;
-
- struct description
- {
- vk::VertexInputBindingDescription binding;
- std::vector attributes;
- std::vector attribute_names;
-
- vk::PipelineVertexInputStateCreateFlags flags{};
- };
-
- static description describe();
- };
-
- struct primitive
- {
- bool indexed;
- uint32_t index_count;
- uint32_t vertex_count;
- vk::IndexType index_type;
- vk::DeviceSize index_offset;
- vk::DeviceSize vertex_offset;
-
- // See also material::double_sided
- vk::CullModeFlagBits cull_mode = vk::CullModeFlagBits::eNone;
- vk::FrontFace front_face = vk::FrontFace::eClockwise;
- vk::PrimitiveTopology topology = vk::PrimitiveTopology::eTriangleList;
-
- std::shared_ptr material_;
- };
-
- struct mesh
- {
- std::vector primitives;
- std::shared_ptr buffer;
- };
-
- struct node
- {
- static constexpr size_t root_id = size_t(-1);
-
- size_t parent_id;
- std::optional mesh_id;
-
- glm::vec3 position;
- glm::quat orientation;
- glm::vec3 scale;
-
- std::string name;
- bool visible;
-
- std::array clipping_planes;
-
- uint32_t layer_mask = 1;
-
- std::vector> joints; // Node index, inverse bind matrix of each joint
- };
-
- // TODO: lights
- // TODO: skybox
-
- std::vector meshes;
- std::vector