diff --git a/include/fastgltf/parser.hpp b/include/fastgltf/parser.hpp index e331858a1..ddbb23bd6 100644 --- a/include/fastgltf/parser.hpp +++ b/include/fastgltf/parser.hpp @@ -597,7 +597,9 @@ namespace fastgltf { * Returns the size, in bytes, * @return */ - [[nodiscard]] inline std::size_t getBufferSize() const noexcept; + [[nodiscard]] inline std::size_t getBufferSize() const noexcept { + return dataSize; + } [[nodiscard]] explicit operator span() { return span(bufferPointer, dataSize); diff --git a/src/fastgltf.cpp b/src/fastgltf.cpp index 6224beefe..31c6d1cc9 100644 --- a/src/fastgltf.cpp +++ b/src/fastgltf.cpp @@ -3212,10 +3212,6 @@ bool fg::GltfDataBuffer::loadFromFile(const fs::path& path, std::uint64_t byteOf std::memset(bufferPointer + dataSize, 0, allocatedSize - dataSize); return true; } - -std::size_t fg::GltfDataBuffer::getBufferSize() const noexcept { - return dataSize; -} #pragma endregion #pragma region AndroidGltfDataBuffer diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 5131a4eb8..a7d541afa 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -48,4 +48,16 @@ if (FASTGLTF_ENABLE_GLTF_RS AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/gltf-rs/src/ target_compile_definitions(fastgltf_tests PRIVATE HAS_GLTFRS=1) endif() +if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/gltf_loaders/assimp") + message(STATUS "fastgltf: Found assimp") + # Only enable glTF importer + set(ASSIMP_NO_EXPORT ON CACHE BOOL "") + set(ASSIMP_BUILD_TESTS OFF CACHE BOOL "") + set(ASSIMP_BUILD_ALL_IMPORTERS_BY_DEFAULT OFF CACHE BOOL "") + set(ASSIMP_BUILD_GLTF_IMPORTER ON CACHE BOOL "") + add_subdirectory(gltf_loaders/assimp) + target_link_libraries(fastgltf_tests PRIVATE assimp::assimp) + target_compile_definitions(fastgltf_tests PRIVATE HAS_ASSIMP=1) +endif() + add_source_directory(TARGET fastgltf_tests FOLDER ".") diff --git a/tests/benchmarks.cpp b/tests/benchmarks.cpp index 90b47d4cb..7fbfd0653 100644 --- a/tests/benchmarks.cpp +++ b/tests/benchmarks.cpp @@ -70,6 +70,12 @@ void setTinyGLTFCallbacks(tinygltf::TinyGLTF& gltf) { #include "gltf-rs-bridge/lib.h" #endif +#ifdef HAS_ASSIMP +#include +#include +#include +#endif + std::vector readFileAsBytes(std::filesystem::path path) { std::ifstream file(path, std::ios::ate | std::ios::binary); if (!file.is_open()) @@ -129,6 +135,12 @@ TEST_CASE("Benchmark loading of NewSponza", "[gltf-benchmark]") { return rust::gltf::run(slice); }; #endif + +#ifdef HAS_ASSIMP + BENCHMARK("Parse NewSponza with assimp") { + return aiImportFileFromMemory(reinterpret_cast(bytes.data()), jsonData->getBufferSize(), 0, nullptr); + }; +#endif } TEST_CASE("Benchmark base64 decoding from glTF file", "[gltf-benchmark]") { @@ -175,6 +187,14 @@ TEST_CASE("Benchmark base64 decoding from glTF file", "[gltf-benchmark]") { return rust::gltf::run(slice); }; #endif + +#ifdef HAS_ASSIMP + BENCHMARK("2CylinderEngine with assimp") { + const auto* scene = aiImportFileFromMemory(reinterpret_cast(bytes.data()), jsonData->getBufferSize(), 0, nullptr); + REQUIRE(scene != nullptr); + return scene; + }; +#endif } TEST_CASE("Benchmark raw JSON parsing", "[gltf-benchmark]") { @@ -220,6 +240,12 @@ TEST_CASE("Benchmark raw JSON parsing", "[gltf-benchmark]") { return rust::gltf::run(slice); }; #endif + +#ifdef HAS_ASSIMP + BENCHMARK("Parse Buggy.gltf with assimp") { + return aiImportFileFromMemory(reinterpret_cast(bytes.data()), jsonData->getBufferSize(), 0, nullptr); + }; +#endif } TEST_CASE("Benchmark massive gltf file", "[gltf-benchmark]") { @@ -269,6 +295,12 @@ TEST_CASE("Benchmark massive gltf file", "[gltf-benchmark]") { return rust::gltf::run(slice); }; #endif + +#ifdef HAS_ASSIMP + BENCHMARK("Parse Bistro with assimp") { + return aiImportFileFromMemory(reinterpret_cast(bytes.data()), jsonData->getBufferSize(), 0, nullptr); + }; +#endif } TEST_CASE("Compare parsing performance with minified documents", "[gltf-benchmark]") { @@ -357,6 +389,12 @@ TEST_CASE("Compare base64 decoding performance", "[gltf-benchmark]") { }; #endif +#ifdef HAS_ASSIMP + BENCHMARK("Run Assimp's base64 decoder") { + return Assimp::Base64::Decode(generatedData); + }; +#endif + BENCHMARK("Run fastgltf's fallback base64 decoder") { return fastgltf::base64::fallback_decode(generatedData); };