feat: new block custom models implementation (WIP)
This commit is contained in:
@@ -1,24 +1,25 @@
|
||||
#include "ContentGfxCache.hpp"
|
||||
|
||||
#include "UiDocument.hpp"
|
||||
#include <string>
|
||||
|
||||
#include "UiDocument.hpp"
|
||||
#include "assets/Assets.hpp"
|
||||
#include "content/Content.hpp"
|
||||
#include "content/ContentPack.hpp"
|
||||
#include "core_defs.hpp"
|
||||
#include "graphics/commons/Model.hpp"
|
||||
#include "graphics/core/Atlas.hpp"
|
||||
#include "maths/UVRegion.hpp"
|
||||
#include "voxels/Block.hpp"
|
||||
|
||||
#include <string>
|
||||
|
||||
ContentGfxCache::ContentGfxCache(const Content* content, Assets* assets) : content(content) {
|
||||
ContentGfxCache::ContentGfxCache(const Content* content, Assets* assets)
|
||||
: content(content) {
|
||||
auto indices = content->getIndices();
|
||||
sideregions = std::make_unique<UVRegion[]>(indices->blocks.count() * 6);
|
||||
auto atlas = assets->get<Atlas>("blocks");
|
||||
|
||||
|
||||
const auto& blocks = indices->blocks.getIterable();
|
||||
for (uint i = 0; i < blocks.size(); i++) {
|
||||
for (blockid_t i = 0; i < blocks.size(); i++) {
|
||||
auto def = blocks[i];
|
||||
for (uint side = 0; side < 6; side++) {
|
||||
const std::string& tex = def->textureFaces[side];
|
||||
@@ -28,13 +29,9 @@ ContentGfxCache::ContentGfxCache(const Content* content, Assets* assets) : conte
|
||||
sideregions[i * 6 + side] = atlas->get(TEXTURE_NOTFOUND);
|
||||
}
|
||||
}
|
||||
for (uint side = 0; side < def->modelTextures.size(); side++) {
|
||||
const std::string& tex = def->modelTextures[side];
|
||||
if (atlas->has(tex)) {
|
||||
def->modelUVs.push_back(atlas->get(tex));
|
||||
} else if (atlas->has(TEXTURE_NOTFOUND)) {
|
||||
def->modelUVs.push_back(atlas->get(TEXTURE_NOTFOUND));
|
||||
}
|
||||
if (def->model == BlockModel::custom) {
|
||||
models[def->rt.id] =
|
||||
assets->require<model::Model>(def->name + ".model");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -44,3 +41,11 @@ ContentGfxCache::~ContentGfxCache() = default;
|
||||
const Content* ContentGfxCache::getContent() const {
|
||||
return content;
|
||||
}
|
||||
|
||||
const model::Model& ContentGfxCache::getModel(blockid_t id) const {
|
||||
const auto& found = models.find(id);
|
||||
if (found == models.end()) {
|
||||
throw std::runtime_error("model not found");
|
||||
}
|
||||
return found->second;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user