add 'model-name' block property
This commit is contained in:
@@ -219,14 +219,15 @@ void ContentLoader::loadBlock(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// block model
|
// block model
|
||||||
std::string modelName;
|
std::string modelTypeName;
|
||||||
root.at("model").get(modelName);
|
root.at("model").get(modelTypeName);
|
||||||
if (auto model = BlockModel_from(modelName)) {
|
root.at("model-name").get(def.modelName);
|
||||||
|
if (auto model = BlockModel_from(modelTypeName)) {
|
||||||
if (*model == BlockModel::custom) {
|
if (*model == BlockModel::custom) {
|
||||||
if (root.has("model-primitives")) {
|
if (root.has("model-primitives")) {
|
||||||
def.customModelRaw = root["model-primitives"];
|
def.customModelRaw = root["model-primitives"];
|
||||||
} else {
|
} else if (def.modelName.empty()) {
|
||||||
throw std::runtime_error(name + ": no 'model-primitives' found");
|
throw std::runtime_error(name + ": no 'model-primitives' or 'model-name' found");
|
||||||
}
|
}
|
||||||
for (uint i = 0; i < 6; i++) {
|
for (uint i = 0; i < 6; i++) {
|
||||||
std::string& texture = def.textureFaces[i];
|
std::string& texture = def.textureFaces[i];
|
||||||
@@ -236,8 +237,8 @@ void ContentLoader::loadBlock(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
def.model = *model;
|
def.model = *model;
|
||||||
} else if (!modelName.empty()) {
|
} else if (!modelTypeName.empty()) {
|
||||||
logger.error() << "unknown model " << modelName;
|
logger.error() << "unknown model " << modelTypeName;
|
||||||
def.model = BlockModel::none;
|
def.model = BlockModel::none;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+11
-8
@@ -288,14 +288,17 @@ void Engine::loadAssets() {
|
|||||||
if (content) {
|
if (content) {
|
||||||
for (auto& [name, def] : content->blocks.getDefs()) {
|
for (auto& [name, def] : content->blocks.getDefs()) {
|
||||||
if (def->model == BlockModel::custom) {
|
if (def->model == BlockModel::custom) {
|
||||||
assets->store(
|
if (def->modelName.empty()) {
|
||||||
std::make_unique<model::Model>(
|
assets->store(
|
||||||
ModelsGenerator::loadCustomBlockModel(
|
std::make_unique<model::Model>(
|
||||||
def->customModelRaw, *assets, !def->shadeless
|
ModelsGenerator::loadCustomBlockModel(
|
||||||
)
|
def->customModelRaw, *assets, !def->shadeless
|
||||||
),
|
)
|
||||||
name + ".model"
|
),
|
||||||
);
|
name + ".model"
|
||||||
|
);
|
||||||
|
def->modelName = def->name + ".model";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (auto& [name, def] : content->items.getDefs()) {
|
for (auto& [name, def] : content->items.getDefs()) {
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ ContentGfxCache::ContentGfxCache(const Content* content, Assets* assets)
|
|||||||
}
|
}
|
||||||
if (def->model == BlockModel::custom) {
|
if (def->model == BlockModel::custom) {
|
||||||
models[def->rt.id] =
|
models[def->rt.id] =
|
||||||
assets->require<model::Model>(def->name + ".model");
|
assets->require<model::Model>(def->modelName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -113,7 +113,7 @@ model::Model ModelsGenerator::generate(
|
|||||||
"blocks:" + blockDef.textureFaces.at(0), assets
|
"blocks:" + blockDef.textureFaces.at(0), assets
|
||||||
);
|
);
|
||||||
} else if (blockDef.model == BlockModel::custom) {
|
} else if (blockDef.model == BlockModel::custom) {
|
||||||
model = assets.require<model::Model>(blockDef.name+".model");
|
model = assets.require<model::Model>(blockDef.modelName);
|
||||||
for (auto& mesh : model.meshes) {
|
for (auto& mesh : model.meshes) {
|
||||||
mesh.scale(glm::vec3(0.3f));
|
mesh.scale(glm::vec3(0.3f));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -135,6 +135,8 @@ public:
|
|||||||
/// @brief Custom model raw data
|
/// @brief Custom model raw data
|
||||||
dv::value customModelRaw = nullptr;
|
dv::value customModelRaw = nullptr;
|
||||||
|
|
||||||
|
std::string modelName = "";
|
||||||
|
|
||||||
/// @brief Does the block passing lights into itself
|
/// @brief Does the block passing lights into itself
|
||||||
bool lightPassing = false;
|
bool lightPassing = false;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user