// ============================================= // Aster: model_loader.cpp // Copyright (c) 2020-2024 Anish Bhobe // ============================================= #define TINYGLTF_NOEXCEPTION #define JSON_NOEXCEPTION #define TINYGLTF_IMPLEMENTATION #define STB_IMAGE_IMPLEMENTATION #define STB_IMAGE_WRITE_IMPLEMENTATION #include "model_loader.h" Model LoadModel(RenderResourceManager *resourceManager, cstr path) { namespace fs = std::filesystem; tinygltf::Model model; tinygltf::TinyGLTF loader; const auto fsPath = fs::absolute(path); const auto ext = fsPath.extension(); if (ext.c_str() == GLTF_ASCII_FILE_EXTENSION) { std::string err; std::string warn; if (loader.LoadASCIIFromFile(&model, &err, &warn, fsPath.generic_string())) { ERROR_IF(!err.empty(), "{}", err) ELSE_IF_WARN(!warn.empty(), "{}", warn); } } if (ext.c_str() == GLTF_BINARY_FILE_EXTENSION) { std::string err; std::string warn; if (loader.LoadBinaryFromFile(&model, &err, &warn, fsPath.generic_string())) { ERROR_IF(!err.empty(), "{}", err) ELSE_IF_WARN(!warn.empty(), "{}", warn); } } }