diff --git a/.gitmodules b/.gitmodules index 1597251..75eb18e 100644 --- a/.gitmodules +++ b/.gitmodules @@ -29,3 +29,6 @@ path = siren url = ../siren branch = main +[submodule "3rdparty/simdjson"] + path = 3rdparty/simdjson + url = https://github.com/simdjson/simdjson.git diff --git a/3rdparty/simdjson b/3rdparty/simdjson new file mode 160000 index 0000000..769364a --- /dev/null +++ b/3rdparty/simdjson @@ -0,0 +1 @@ +Subproject commit 769364abb2690f838b79c51b086d517008393117 diff --git a/CMakeLists.txt b/CMakeLists.txt index 1032c49..5e10fb7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -147,6 +147,12 @@ add_subdirectory(3rdparty/compressonator/cmp_core) include_directories("${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/compressonator/cmp_core/source") list (APPEND EXTRA_LIBS CMP_Core) +# ---- simdjson ---- +add_subdirectory(3rdparty/simdjson) +include_directories("${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/simdjson/include") +list (APPEND EXTRA_LIBS simdjson) +target_compile_definitions(simdjson PUBLIC SIMDJSON_EXCEPTIONS=OFF) + # ---- Vulkan ---- add_library(vulkan INTERFACE) set(VULKAN_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/vulkan/include) diff --git a/kraken/resources/KRResource+gltf.cpp b/kraken/resources/KRResource+gltf.cpp index 760c82c..12e24a2 100644 --- a/kraken/resources/KRResource+gltf.cpp +++ b/kraken/resources/KRResource+gltf.cpp @@ -40,8 +40,30 @@ using namespace mimir; using namespace hydra; -KRBundle* LoadGltf(KRContext& context, const Block& jsonData, const Block& binData, const std::string& baseName) +#include "simdjson.h" +using namespace simdjson; + +KRBundle* LoadGltf(KRContext& context, Block& jsonData, Block& binData, const std::string& baseName) { + simdjson::dom::parser parser; + simdjson::dom::element jsonRoot; + + jsonData.lock(); + auto error = parser.parse((const char*)jsonData.getStart(), jsonData.getSize()).get(jsonRoot); + jsonData.unlock(); + + if (error) { + // TODO - Report and handle error + return nullptr; + } + + std::string_view version; + error = jsonRoot["asset"]["version"].get(version); + if (error) { + // TODO - Report and handle error + return nullptr; + } + KRScene* pScene = new KRScene(context, baseName + "_scene"); KRBundle* bundle = new KRBundle(context, baseName); @@ -49,6 +71,8 @@ KRBundle* LoadGltf(KRContext& context, const Block& jsonData, const Block& binDa KrResult result = pScene->moveToBundle(bundle); // TODO - Validate result bundle->append(*pScene); + + return bundle; }