fix custom models instancing for different blocks
This commit is contained in:
@@ -37,17 +37,15 @@ void ContentGfxCache::refresh(const Block& def, const Atlas& atlas) {
|
|||||||
}
|
}
|
||||||
if (def.model.type == BlockModelType::CUSTOM) {
|
if (def.model.type == BlockModelType::CUSTOM) {
|
||||||
auto model = assets.require<model::Model>(def.model.name);
|
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) {
|
||||||
for (auto& mesh : model.meshes) {
|
size_t pos = mesh.texture.find(':');
|
||||||
size_t pos = mesh.texture.find(':');
|
if (pos == std::string::npos) {
|
||||||
if (pos == std::string::npos) {
|
continue;
|
||||||
continue;
|
}
|
||||||
}
|
if (auto region = atlas.getIf(mesh.texture.substr(pos+1))) {
|
||||||
if (auto region = atlas.getIf(mesh.texture.substr(pos+1))) {
|
for (auto& vertex : mesh.vertices) {
|
||||||
for (auto& vertex : mesh.vertices) {
|
vertex.uv = region->apply(vertex.uv);
|
||||||
vertex.uv = region->apply(vertex.uv);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -62,14 +62,17 @@ void ModelsGenerator::prepare(Content& content, Assets& assets) {
|
|||||||
);
|
);
|
||||||
def->model.name = def->name + ".model";
|
def->model.name = def->name + ".model";
|
||||||
} else {
|
} else {
|
||||||
auto model = assets.get<model::Model>(def->model.name);
|
auto srcModel = assets.get<model::Model>(def->model.name);
|
||||||
if (model) {
|
if (srcModel) {
|
||||||
|
auto model = std::make_unique<model::Model>(*srcModel);
|
||||||
for (auto& mesh : model->meshes) {
|
for (auto& mesh : model->meshes) {
|
||||||
if (mesh.texture.length() && mesh.texture[0] == '$') {
|
if (mesh.texture.length() && mesh.texture[0] == '$') {
|
||||||
int index = std::stoll(mesh.texture.substr(1));
|
int index = std::stoll(mesh.texture.substr(1));
|
||||||
mesh.texture = "blocks:" + def->textureFaces[index];
|
mesh.texture = "blocks:" + def->textureFaces[index];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
def->model.name = name + ".model";
|
||||||
|
assets.store(std::move(model), def->model.name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user