add VEC3 models support

This commit is contained in:
MihailRis
2024-10-25 10:10:30 +03:00
parent 5c019c53f0
commit caf3376ef9
+39 -13
View File
@@ -10,6 +10,7 @@
#include "coders/imageio.hpp" #include "coders/imageio.hpp"
#include "coders/json.hpp" #include "coders/json.hpp"
#include "coders/obj.hpp" #include "coders/obj.hpp"
#include "coders/vec3.hpp"
#include "constants.hpp" #include "constants.hpp"
#include "debug/Logger.hpp" #include "debug/Logger.hpp"
#include "files/engine_paths.hpp" #include "files/engine_paths.hpp"
@@ -23,6 +24,7 @@
#include "graphics/core/Texture.hpp" #include "graphics/core/Texture.hpp"
#include "graphics/core/TextureAnimation.hpp" #include "graphics/core/TextureAnimation.hpp"
#include "objects/rigging.hpp" #include "objects/rigging.hpp"
#include "util/stringutil.hpp"
#include "Assets.hpp" #include "Assets.hpp"
#include "AssetsLoader.hpp" #include "AssetsLoader.hpp"
@@ -190,19 +192,8 @@ assetload::postfunc assetload::sound(
}; };
} }
assetload::postfunc assetload::model( static void request_textures(AssetsLoader* loader, const model::Model& model) {
AssetsLoader* loader, for (auto& mesh : model.meshes) {
const ResPaths* paths,
const std::string& file,
const std::string& name,
const std::shared_ptr<AssetCfg>&
) {
auto path = paths->find(file + ".obj");
auto text = files::read_string(path);
try {
auto model = obj::parse(path.u8string(), text).release();
return [=](Assets* assets) {
for (auto& mesh : model->meshes) {
if (mesh.texture.find('$') == std::string::npos) { if (mesh.texture.find('$') == std::string::npos) {
auto filename = TEXTURES_FOLDER + "/" + mesh.texture; auto filename = TEXTURES_FOLDER + "/" + mesh.texture;
loader->add( loader->add(
@@ -210,6 +201,41 @@ assetload::postfunc assetload::model(
); );
} }
} }
}
assetload::postfunc assetload::model(
AssetsLoader* loader,
const ResPaths* paths,
const std::string& file,
const std::string& name,
const std::shared_ptr<AssetCfg>&
) {
auto path = paths->find(file + ".vec3");
if (fs::exists(path)) {
auto bytes = files::read_bytes_buffer(path);
auto modelVEC3 = std::make_shared<vec3::File>(vec3::load(path.u8string(), bytes));
return [loader, name, modelVEC3=std::move(modelVEC3)](Assets* assets) {
for (auto& [modelName, model] : modelVEC3->models) {
request_textures(loader, model.model);
std::string fullName = name;
if (name != modelName) {
fullName += "." + modelName;
}
assets->store(
std::make_unique<model::Model>(model.model),
fullName
);
logger.info() << "store model " << util::quote(modelName)
<< " as " << util::quote(fullName);
}
};
}
path = paths->find(file + ".obj");
auto text = files::read_string(path);
try {
auto model = obj::parse(path.u8string(), text).release();
return [=](Assets* assets) {
request_textures(loader, *model);
assets->store(std::unique_ptr<model::Model>(model), name); assets->store(std::unique_ptr<model::Model>(model), name);
}; };
} catch (const parsing_error& err) { } catch (const parsing_error& err) {