diff --git a/.gitmodules b/.gitmodules index b44e47387fc30a41c3f5c8d09b5ad525b354f233..3c782ca01533fefc9c55c6395db7f9b2ba8d29ef 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,9 @@ [submodule "lib/glfw"] path = lib/glfw url = https://github.com/glfw/glfw.git +[submodule "modules/asset_loader/lib/fx-gltf"] + path = modules/asset_loader/lib/fx-gltf + url = https://github.com/jessey-git/fx-gltf.git +[submodule "modules/asset_loader/lib/json"] + path = modules/asset_loader/lib/json + url = https://github.com/nlohmann/json.git diff --git a/CMakeLists.txt b/CMakeLists.txt index 58669d661a0be4cfabcdab69a0639fa28d429c50..6359e2500fc7c8c77cd8a3642227ea171de5d532 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -36,12 +36,15 @@ if (vkcv_build_debug) endif() endif() -# add source files for compilation -include(${vkcv_config}/Sources.cmake) - # configure everything to use the required dependencies include(${vkcv_config}/Libraries.cmake) +# add modules as targets +add_subdirectory(modules) + +# add source files for compilation +include(${vkcv_config}/Sources.cmake) + # set the compiler flags for the framework set(CMAKE_CXX_FLAGS ${vkcv_flags}) diff --git a/config/Sources.cmake b/config/Sources.cmake index 53d0bea7643d511e302a5873d36c65e6b2b3ac82..80fa3a09d163edf3277eb69f91e7b10e57b72c5d 100644 --- a/config/Sources.cmake +++ b/config/Sources.cmake @@ -12,7 +12,4 @@ set(vkcv_sources ${vkcv_include}/vkcv/Window.hpp ${vkcv_source}/vkcv/Window.cpp - - ${vkcv_include}/asset_loader/asset_loader.hpp - ${vkcv_source}/asset_loader/main.cpp ) diff --git a/modules/CMakeLists.txt b/modules/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..145dcf652b7006a35f8e8dae55b9099e9d01cf17 --- /dev/null +++ b/modules/CMakeLists.txt @@ -0,0 +1,3 @@ + +# Add new modules here: +add_subdirectory(asset_loader) \ No newline at end of file diff --git a/modules/asset_loader/CMakeLists.txt b/modules/asset_loader/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..bc4d332f7dbbcaaa30ddf17487bf7b82f89981d4 --- /dev/null +++ b/modules/asset_loader/CMakeLists.txt @@ -0,0 +1,47 @@ +cmake_minimum_required(VERSION 3.16) +project(vkcv_asset_loader) + +# setting c++ standard for the project +set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD_REQUIRED ON) + +set(vkcv_asset_loader_source ${PROJECT_SOURCE_DIR}/src) +set(vkcv_asset_loader_include ${PROJECT_SOURCE_DIR}/include) + +set(vkcv_asset_loader_sources + ${vkcv_asset_loader_include}/vkcv/asset/asset_loader.hpp + ${vkcv_asset_loader_source}/vkcv/asset/asset_loader.cpp +) + +set(vkcv_asset_loader_lib lib) +set(vkcv_asset_loader_lib_path ${PROJECT_SOURCE_DIR}/${vkcv_asset_loader_lib}) + +if (EXISTS "${vkcv_asset_loader_lib_path}/json") + set(JSON_BuildTests OFF CACHE INTERNAL "") + + add_subdirectory(${vkcv_asset_loader_lib}/json) + + list(APPEND vkcv_asset_loader_libraries nlohmann_json::nlohmann_json) +else() + message(WARNING "NLOHMANN_JSON is required..! Update the submodules!") +endif () + +if (EXISTS "${vkcv_asset_loader_lib_path}/fx-gltf") + set(FX_GLTF_INSTALL OFF) + set(FX_GLTF_USE_INSTALLED_DEPS OFF) + set(BUILD_TESTING OFF) + + add_subdirectory(${vkcv_asset_loader_lib}/fx-gltf) + + list(APPEND vkcv_asset_loader_libraries fx-gltf) +else() + message(WARNING "FX-GLTF is required..! Update the submodules!") +endif () + +# adding source files to the project +add_library(vkcv_asset_loader STATIC ${vkcv_asset_loader_sources}) + +target_link_libraries(vkcv_asset_loader ${vkcv_asset_loader_libraries}) + +# add the own include directory for public headers +target_include_directories(vkcv_asset_loader BEFORE PUBLIC ${vkcv_asset_loader_include}) diff --git a/include/asset_loader/asset_loader.hpp b/modules/asset_loader/include/vkcv/asset/asset_loader.hpp similarity index 98% rename from include/asset_loader/asset_loader.hpp rename to modules/asset_loader/include/vkcv/asset/asset_loader.hpp index d48c5cddfcebf2016f06bc1c4ac8431908b116d1..e43861fbe241731d79566ebee65219ad3f8f5d2a 100644 --- a/include/asset_loader/asset_loader.hpp +++ b/modules/asset_loader/include/vkcv/asset/asset_loader.hpp @@ -1,7 +1,7 @@ #pragma once /** * @authors Trevor Hollmann - * @file include/asset_loader/asset_loader.h + * @file include/vkcv/asset/asset_loader.h * @brief Interface of the asset loader module for the vkcv framework. */ @@ -41,7 +41,7 @@ * These values can directly be given to vulkan when describing the content of * vertex buffers. */ -namespace asset { +namespace vkcv::asset { /* With these enums, 0 is reserved to signal uninitialized or invalid data. */ diff --git a/modules/asset_loader/lib/fx-gltf b/modules/asset_loader/lib/fx-gltf new file mode 160000 index 0000000000000000000000000000000000000000..f4f18f2017a049a23748c9c9aad42ba2de20bfd5 --- /dev/null +++ b/modules/asset_loader/lib/fx-gltf @@ -0,0 +1 @@ +Subproject commit f4f18f2017a049a23748c9c9aad42ba2de20bfd5 diff --git a/modules/asset_loader/lib/json b/modules/asset_loader/lib/json new file mode 160000 index 0000000000000000000000000000000000000000..0972f7ff0e651f09a306dba791cc42024b8642c1 --- /dev/null +++ b/modules/asset_loader/lib/json @@ -0,0 +1 @@ +Subproject commit 0972f7ff0e651f09a306dba791cc42024b8642c1 diff --git a/modules/asset_loader/src/vkcv/asset/asset_loader.cpp b/modules/asset_loader/src/vkcv/asset/asset_loader.cpp new file mode 100644 index 0000000000000000000000000000000000000000..cfc77386192a4177c200cc1ba2ad64682d867dec --- /dev/null +++ b/modules/asset_loader/src/vkcv/asset/asset_loader.cpp @@ -0,0 +1,25 @@ + +#include "vkcv/asset/asset_loader.hpp" +#include <iostream> +#include <fx/gltf.h> + +namespace vkcv::asset { + + int loadMesh(const std::string &path, Mesh &mesh) { + std::vector<uint8_t> v; + + if (fx::base64::TryDecode(path, v)) { + for (auto& ve : v) { + std::cout << ve << " "; + } + + std::cout << std::endl; + } else { + std::cerr << "Schade!" << std::endl; + } + + // TODO + return -1; + } + +} diff --git a/projects/CMakeLists.txt b/projects/CMakeLists.txt index f7687bca4ba7cb05835c8afda1396ad319a035c7..7ca73a0811df7f1568508b56312ce3348237a695 100644 --- a/projects/CMakeLists.txt +++ b/projects/CMakeLists.txt @@ -1,3 +1,4 @@ # Add new projects/examples here: add_subdirectory(first_triangle) +add_subdirectory(first_mesh) diff --git a/projects/first_mesh/.gitignore b/projects/first_mesh/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..85ce58a41ce7dcbe4f4a41bbf4779d82cede0106 --- /dev/null +++ b/projects/first_mesh/.gitignore @@ -0,0 +1 @@ +first_mesh \ No newline at end of file diff --git a/projects/first_mesh/CMakeLists.txt b/projects/first_mesh/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..bcd3e09cc7fa539c4a99ae854ae7950d2bbdd4c9 --- /dev/null +++ b/projects/first_mesh/CMakeLists.txt @@ -0,0 +1,24 @@ +cmake_minimum_required(VERSION 3.16) +project(first_mesh) + +# setting c++ standard for the project +set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD_REQUIRED ON) + +# this should fix the execution path to load local files from the project +set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) + +# adding source files to the project +add_executable(first_mesh src/main.cpp) + +# this should fix the execution path to load local files from the project (for MSVC) +if(MSVC) + set_target_properties(first_triangle PROPERTIES RUNTIME_OUTPUT_DIRECTORY_DEBUG ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}) + set_target_properties(first_triangle PROPERTIES RUNTIME_OUTPUT_DIRECTORY_RELEASE ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}) +endif() + +# including headers of dependencies and the VkCV framework +target_include_directories(first_mesh SYSTEM BEFORE PRIVATE ${vkcv_include} ${vkcv_includes} ${vkcv_asset_loader_include}) + +# linking with libraries from all dependencies and the VkCV framework +target_link_libraries(first_mesh vkcv ${vkcv_libraries} vkcv_asset_loader ${vkcv_asset_loader_libraries}) diff --git a/projects/first_mesh/src/main.cpp b/projects/first_mesh/src/main.cpp new file mode 100644 index 0000000000000000000000000000000000000000..0d045a4fe12b1fa1b9ba6be1a981556a66976032 --- /dev/null +++ b/projects/first_mesh/src/main.cpp @@ -0,0 +1,16 @@ +#include <iostream> +#include <vkcv/asset/asset_loader.hpp> + +int main(int argc, const char** argv) { + vkcv::asset::Mesh mesh; + + int result = vkcv::asset::loadMesh("test.gltf", mesh); + + if (result == 0) { + std::cout << "Mesh loading successful!" << std::endl; + } else { + std::cout << "Mesh loading failed: " << result << std::endl; + } + + return 0; +} diff --git a/projects/first_triangle/.gitignore b/projects/first_triangle/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..7e24fd7b853bfb0a29d8b30879ef1cb95ad141c0 --- /dev/null +++ b/projects/first_triangle/.gitignore @@ -0,0 +1 @@ +first_triangle \ No newline at end of file diff --git a/projects/first_triangle/CMakeLists.txt b/projects/first_triangle/CMakeLists.txt index 40e016a71cd3e20690f3ace9ec0260aa37449a0c..c26da08c2f9f4cafd4040c5603fbf0bf30312146 100644 --- a/projects/first_triangle/CMakeLists.txt +++ b/projects/first_triangle/CMakeLists.txt @@ -5,9 +5,18 @@ project(first_triangle) set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) +# this should fix the execution path to load local files from the project +set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) + # adding source files to the project add_executable(first_triangle src/main.cpp) +# this should fix the execution path to load local files from the project (for MSVC) +if(MSVC) + set_target_properties(first_triangle PROPERTIES RUNTIME_OUTPUT_DIRECTORY_DEBUG ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}) + set_target_properties(first_triangle PROPERTIES RUNTIME_OUTPUT_DIRECTORY_RELEASE ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}) +endif() + # including headers of dependencies and the VkCV framework target_include_directories(first_triangle SYSTEM BEFORE PRIVATE ${vkcv_include} ${vkcv_includes}) diff --git a/src/asset_loader/main.cpp b/src/asset_loader/main.cpp deleted file mode 100644 index 1e871e134e7e47ed9829fd3393ebffd51c51c152..0000000000000000000000000000000000000000 --- a/src/asset_loader/main.cpp +++ /dev/null @@ -1 +0,0 @@ -#include "asset_loader/asset_loader.hpp"