fix custom block models
This commit is contained in:
parent
bbadaf7a19
commit
86b5f5d82b
@ -11,6 +11,8 @@
|
|||||||
#include "maths/UVRegion.hpp"
|
#include "maths/UVRegion.hpp"
|
||||||
#include "voxels/Block.hpp"
|
#include "voxels/Block.hpp"
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
ContentGfxCache::ContentGfxCache(const Content* content, Assets* assets)
|
ContentGfxCache::ContentGfxCache(const Content* content, Assets* assets)
|
||||||
: content(content) {
|
: content(content) {
|
||||||
auto indices = content->getIndices();
|
auto indices = content->getIndices();
|
||||||
@ -29,8 +31,22 @@ ContentGfxCache::ContentGfxCache(const Content* content, Assets* assets)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (def->model == BlockModel::custom) {
|
if (def->model == BlockModel::custom) {
|
||||||
models[def->rt.id] =
|
auto model = assets->require<model::Model>(def->modelName);
|
||||||
assets->require<model::Model>(def->modelName);
|
// temporary dirty fix tbh
|
||||||
|
if (def->modelName.find(':') == std::string::npos) {
|
||||||
|
for (auto& mesh : model.meshes) {
|
||||||
|
size_t pos = mesh.texture.find(':');
|
||||||
|
if (pos == std::string::npos) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (auto region = atlas->getIf(mesh.texture.substr(pos+1))) {
|
||||||
|
for (auto& vertex : mesh.vertices) {
|
||||||
|
vertex.uv = region->apply(vertex.uv);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
models[def->rt.id] = std::move(model);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -38,6 +38,6 @@ struct UVRegion {
|
|||||||
inline glm::vec2 apply(const glm::vec2& uv) {
|
inline glm::vec2 apply(const glm::vec2& uv) {
|
||||||
float w = getWidth();
|
float w = getWidth();
|
||||||
float h = getHeight();
|
float h = getHeight();
|
||||||
return glm::vec2(u1 + uv.x / w, v1 + uv.y / h);
|
return glm::vec2(u1 + uv.x * w, v1 + uv.y * h);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user