fix custom models instancing for different blocks
This commit is contained in:
parent
edb12a32b0
commit
895855434f
@ -37,17 +37,15 @@ void ContentGfxCache::refresh(const Block& def, const Atlas& atlas) {
|
||||
}
|
||||
if (def.model.type == BlockModelType::CUSTOM) {
|
||||
auto model = assets.require<model::Model>(def.model.name);
|
||||
// temporary dirty fix tbh
|
||||
if (def.model.name.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);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -62,14 +62,17 @@ void ModelsGenerator::prepare(Content& content, Assets& assets) {
|
||||
);
|
||||
def->model.name = def->name + ".model";
|
||||
} else {
|
||||
auto model = assets.get<model::Model>(def->model.name);
|
||||
if (model) {
|
||||
auto srcModel = assets.get<model::Model>(def->model.name);
|
||||
if (srcModel) {
|
||||
auto model = std::make_unique<model::Model>(*srcModel);
|
||||
for (auto& mesh : model->meshes) {
|
||||
if (mesh.texture.length() && mesh.texture[0] == '$') {
|
||||
int index = std::stoll(mesh.texture.substr(1));
|
||||
mesh.texture = "blocks:" + def->textureFaces[index];
|
||||
}
|
||||
}
|
||||
def->model.name = name + ".model";
|
||||
assets.store(std::move(model), def->model.name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user