feat: models loading
This commit is contained in:
parent
d54b6b2e58
commit
ea0add3017
@ -13,14 +13,6 @@
|
|||||||
|
|
||||||
class Assets;
|
class Assets;
|
||||||
|
|
||||||
namespace audio {
|
|
||||||
class Sound;
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace model {
|
|
||||||
struct Model;
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace assetload {
|
namespace assetload {
|
||||||
/// @brief final work to do in the main thread
|
/// @brief final work to do in the main thread
|
||||||
using postfunc = std::function<void(Assets*)>;
|
using postfunc = std::function<void(Assets*)>;
|
||||||
|
|||||||
@ -30,6 +30,7 @@ AssetsLoader::AssetsLoader(Assets* assets, const ResPaths* paths)
|
|||||||
addLoader(AssetType::atlas, assetload::atlas);
|
addLoader(AssetType::atlas, assetload::atlas);
|
||||||
addLoader(AssetType::layout, assetload::layout);
|
addLoader(AssetType::layout, assetload::layout);
|
||||||
addLoader(AssetType::sound, assetload::sound);
|
addLoader(AssetType::sound, assetload::sound);
|
||||||
|
addLoader(AssetType::model, assetload::model);
|
||||||
}
|
}
|
||||||
|
|
||||||
void AssetsLoader::addLoader(AssetType tag, aloader_func func) {
|
void AssetsLoader::addLoader(AssetType tag, aloader_func func) {
|
||||||
@ -99,6 +100,7 @@ static std::string assets_def_folder(AssetType tag) {
|
|||||||
case AssetType::atlas: return TEXTURES_FOLDER;
|
case AssetType::atlas: return TEXTURES_FOLDER;
|
||||||
case AssetType::layout: return LAYOUTS_FOLDER;
|
case AssetType::layout: return LAYOUTS_FOLDER;
|
||||||
case AssetType::sound: return SOUNDS_FOLDER;
|
case AssetType::sound: return SOUNDS_FOLDER;
|
||||||
|
case AssetType::model: return MODELS_FOLDER;
|
||||||
}
|
}
|
||||||
return "<error>";
|
return "<error>";
|
||||||
}
|
}
|
||||||
@ -155,6 +157,7 @@ void AssetsLoader::processPreloadConfig(const fs::path& file) {
|
|||||||
processPreloadList(AssetType::shader, root->list("shaders"));
|
processPreloadList(AssetType::shader, root->list("shaders"));
|
||||||
processPreloadList(AssetType::texture, root->list("textures"));
|
processPreloadList(AssetType::texture, root->list("textures"));
|
||||||
processPreloadList(AssetType::sound, root->list("sounds"));
|
processPreloadList(AssetType::sound, root->list("sounds"));
|
||||||
|
processPreloadList(AssetType::model, root->list("models"));
|
||||||
// layouts are loaded automatically
|
// layouts are loaded automatically
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -25,7 +25,8 @@ enum class AssetType {
|
|||||||
font,
|
font,
|
||||||
atlas,
|
atlas,
|
||||||
layout,
|
layout,
|
||||||
sound
|
sound,
|
||||||
|
model,
|
||||||
};
|
};
|
||||||
|
|
||||||
class ResPaths;
|
class ResPaths;
|
||||||
|
|||||||
@ -9,14 +9,17 @@
|
|||||||
#include "../coders/commons.hpp"
|
#include "../coders/commons.hpp"
|
||||||
#include "../coders/imageio.hpp"
|
#include "../coders/imageio.hpp"
|
||||||
#include "../coders/json.hpp"
|
#include "../coders/json.hpp"
|
||||||
|
#include "../coders/obj.hpp"
|
||||||
#include "../coders/GLSLExtension.hpp"
|
#include "../coders/GLSLExtension.hpp"
|
||||||
#include "../graphics/core/Shader.hpp"
|
#include "../graphics/core/Shader.hpp"
|
||||||
#include "../graphics/core/Texture.hpp"
|
#include "../graphics/core/Texture.hpp"
|
||||||
#include "../graphics/core/ImageData.hpp"
|
#include "../graphics/core/ImageData.hpp"
|
||||||
#include "../graphics/core/Atlas.hpp"
|
#include "../graphics/core/Atlas.hpp"
|
||||||
#include "../graphics/core/Font.hpp"
|
#include "../graphics/core/Font.hpp"
|
||||||
|
#include "../graphics/core/Model.hpp"
|
||||||
#include "../graphics/core/TextureAnimation.hpp"
|
#include "../graphics/core/TextureAnimation.hpp"
|
||||||
#include "../frontend/UiDocument.hpp"
|
#include "../frontend/UiDocument.hpp"
|
||||||
|
#include "../constants.hpp"
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
@ -198,6 +201,30 @@ assetload::postfunc assetload::sound(
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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+".obj");
|
||||||
|
auto text = files::read_string(path);
|
||||||
|
try {
|
||||||
|
auto model = obj::parse(path.u8string(), text).release();
|
||||||
|
return [=](Assets* assets) {
|
||||||
|
for (auto& mesh : model->meshes) {
|
||||||
|
auto filename = TEXTURES_FOLDER+"/"+mesh.texture;
|
||||||
|
loader->add(AssetType::texture, filename, mesh.texture, nullptr);
|
||||||
|
}
|
||||||
|
assets->store(std::unique_ptr<model::Model>(model), name);
|
||||||
|
};
|
||||||
|
} catch (const parsing_error& err) {
|
||||||
|
std::cerr << err.errorLog() << std::endl;
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static void read_anim_file(
|
static void read_anim_file(
|
||||||
const std::string& animFile,
|
const std::string& animFile,
|
||||||
std::vector<std::pair<std::string, int>>& frameList
|
std::vector<std::pair<std::string, int>>& frameList
|
||||||
|
|||||||
@ -49,7 +49,6 @@ namespace assetload {
|
|||||||
const std::string &name,
|
const std::string &name,
|
||||||
const std::shared_ptr<AssetCfg>& settings
|
const std::shared_ptr<AssetCfg>& settings
|
||||||
);
|
);
|
||||||
|
|
||||||
postfunc sound(
|
postfunc sound(
|
||||||
AssetsLoader*,
|
AssetsLoader*,
|
||||||
const ResPaths* paths,
|
const ResPaths* paths,
|
||||||
@ -57,6 +56,13 @@ namespace assetload {
|
|||||||
const std::string &name,
|
const std::string &name,
|
||||||
const std::shared_ptr<AssetCfg>& settings
|
const std::shared_ptr<AssetCfg>& settings
|
||||||
);
|
);
|
||||||
|
postfunc model(
|
||||||
|
AssetsLoader*,
|
||||||
|
const ResPaths* paths,
|
||||||
|
const std::string& file,
|
||||||
|
const std::string &name,
|
||||||
|
const std::shared_ptr<AssetCfg>& settings
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // ASSETS_ASSET_LOADERS_HPP_
|
#endif // ASSETS_ASSET_LOADERS_HPP_
|
||||||
|
|||||||
@ -49,5 +49,6 @@ inline const std::string TEXTURES_FOLDER = "textures";
|
|||||||
inline const std::string FONTS_FOLDER = "fonts";
|
inline const std::string FONTS_FOLDER = "fonts";
|
||||||
inline const std::string LAYOUTS_FOLDER = "layouts";
|
inline const std::string LAYOUTS_FOLDER = "layouts";
|
||||||
inline const std::string SOUNDS_FOLDER = "sounds";
|
inline const std::string SOUNDS_FOLDER = "sounds";
|
||||||
|
inline const std::string MODELS_FOLDER = "models";
|
||||||
|
|
||||||
#endif // CONSTANTS_HPP_
|
#endif // CONSTANTS_HPP_
|
||||||
|
|||||||
@ -50,7 +50,7 @@ ModelBatch::ModelBatch(size_t capacity, Assets* assets, Chunks* chunks)
|
|||||||
ModelBatch::~ModelBatch() {
|
ModelBatch::~ModelBatch() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void ModelBatch::draw(const model::Model& model) {
|
void ModelBatch::draw(const model::Model* model) {
|
||||||
glm::vec3 gpos = combined * glm::vec4(glm::vec3(), 1.0f);
|
glm::vec3 gpos = combined * glm::vec4(glm::vec3(), 1.0f);
|
||||||
light_t light = chunks->getLight(gpos.x, gpos.y, gpos.z);
|
light_t light = chunks->getLight(gpos.x, gpos.y, gpos.z);
|
||||||
glm::vec4 lights (
|
glm::vec4 lights (
|
||||||
@ -59,7 +59,7 @@ void ModelBatch::draw(const model::Model& model) {
|
|||||||
Lightmap::extract(light, 2) / 15.0f,
|
Lightmap::extract(light, 2) / 15.0f,
|
||||||
Lightmap::extract(light, 3) / 15.0f
|
Lightmap::extract(light, 3) / 15.0f
|
||||||
);
|
);
|
||||||
for (const auto& mesh : model.meshes) {
|
for (const auto& mesh : model->meshes) {
|
||||||
auto texture = assets->get<Texture>(mesh.texture);
|
auto texture = assets->get<Texture>(mesh.texture);
|
||||||
if (texture) {
|
if (texture) {
|
||||||
texture->bind();
|
texture->bind();
|
||||||
|
|||||||
@ -83,7 +83,7 @@ public:
|
|||||||
|
|
||||||
void box(glm::vec3 pos, glm::vec3 size, glm::vec4 lights);
|
void box(glm::vec3 pos, glm::vec3 size, glm::vec4 lights);
|
||||||
|
|
||||||
void draw(const model::Model& model);
|
void draw(const model::Model* model);
|
||||||
|
|
||||||
void flush();
|
void flush();
|
||||||
};
|
};
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user