add BlockModel struct
This commit is contained in:
parent
718f5d1089
commit
20e3a961f9
@ -257,12 +257,12 @@ void AssetsLoader::addDefaults(AssetsLoader& loader, const Content* content) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (const auto& [_, def] : content->blocks.getDefs()) {
|
for (const auto& [_, def] : content->blocks.getDefs()) {
|
||||||
if (!def->modelName.empty() &&
|
if (!def->model.name.empty() &&
|
||||||
def->modelName.find(':') == std::string::npos) {
|
def->model.name.find(':') == std::string::npos) {
|
||||||
loader.add(
|
loader.add(
|
||||||
AssetType::MODEL,
|
AssetType::MODEL,
|
||||||
MODELS_FOLDER + "/" + def->modelName,
|
MODELS_FOLDER + "/" + def->model.name,
|
||||||
def->modelName
|
def->model.name
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -28,7 +28,7 @@ std::unique_ptr<Content> ContentBuilder::build() {
|
|||||||
// Generating runtime info
|
// Generating runtime info
|
||||||
def.rt.id = blockDefsIndices.size();
|
def.rt.id = blockDefsIndices.size();
|
||||||
def.rt.emissive = *reinterpret_cast<uint32_t*>(def.emission);
|
def.rt.emissive = *reinterpret_cast<uint32_t*>(def.emission);
|
||||||
def.rt.solid = def.model == BlockModelType::BLOCK;
|
def.rt.solid = def.model.type == BlockModelType::BLOCK;
|
||||||
def.rt.extended = def.size.x > 1 || def.size.y > 1 || def.size.z > 1;
|
def.rt.extended = def.size.x > 1 || def.size.y > 1 || def.size.z > 1;
|
||||||
|
|
||||||
const float EPSILON = 0.01f;
|
const float EPSILON = 0.01f;
|
||||||
|
|||||||
@ -86,20 +86,23 @@ template<> void ContentUnitLoader<Block>::loadUnit(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// block model
|
// block model
|
||||||
std::string modelTypeName = BlockModelTypeMeta.getNameString(def.model);
|
auto& model = def.model;
|
||||||
|
std::string modelTypeName = BlockModelTypeMeta.getNameString(model.type);
|
||||||
root.at("model").get(modelTypeName);
|
root.at("model").get(modelTypeName);
|
||||||
root.at("model-name").get(def.modelName);
|
root.at("model-name").get(def.model.name);
|
||||||
if (BlockModelTypeMeta.getItem(modelTypeName, def.model)) {
|
if (BlockModelTypeMeta.getItem(modelTypeName, model.type)) {
|
||||||
if (def.model == BlockModelType::CUSTOM && def.customModelRaw == nullptr) {
|
if (model.type == BlockModelType::CUSTOM && def.model.customRaw == nullptr) {
|
||||||
if (root.has("model-primitives")) {
|
if (root.has("model-primitives")) {
|
||||||
def.customModelRaw = root["model-primitives"];
|
def.model.customRaw = root["model-primitives"];
|
||||||
} else if (def.modelName.empty()) {
|
} else if (def.model.name.empty()) {
|
||||||
throw std::runtime_error(name + ": no 'model-primitives' or 'model-name' found");
|
throw std::runtime_error(
|
||||||
|
name + ": no 'model-primitives' or 'model-name' found"
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (!modelTypeName.empty()) {
|
} else if (!modelTypeName.empty()) {
|
||||||
logger.error() << "unknown model: " << modelTypeName;
|
logger.error() << "unknown model: " << modelTypeName;
|
||||||
def.model = BlockModelType::NONE;
|
model.type = BlockModelType::NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string cullingModeName = CullingModeMeta.getNameString(def.culling);
|
std::string cullingModeName = CullingModeMeta.getNameString(def.culling);
|
||||||
@ -171,9 +174,9 @@ template<> void ContentUnitLoader<Block>::loadUnit(
|
|||||||
"block " + util::quote(def.name) + ": invalid block size"
|
"block " + util::quote(def.name) + ": invalid block size"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
if (def.model == BlockModelType::BLOCK &&
|
if (model.type == BlockModelType::BLOCK &&
|
||||||
(def.size.x != 1 || def.size.y != 1 || def.size.z != 1)) {
|
(def.size.x != 1 || def.size.y != 1 || def.size.z != 1)) {
|
||||||
def.model = BlockModelType::AABB;
|
model.type = BlockModelType::AABB;
|
||||||
def.hitboxes = {AABB(def.size)};
|
def.hitboxes = {AABB(def.size)};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -19,7 +19,7 @@ void corecontent::setup(Input& input, ContentBuilder& builder) {
|
|||||||
block.skyLightPassing = true;
|
block.skyLightPassing = true;
|
||||||
block.obstacle = false;
|
block.obstacle = false;
|
||||||
block.selectable = false;
|
block.selectable = false;
|
||||||
block.model = BlockModelType::NONE;
|
block.model.type = BlockModelType::NONE;
|
||||||
block.pickingItem = CORE_EMPTY;
|
block.pickingItem = CORE_EMPTY;
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
|
|||||||
@ -35,10 +35,10 @@ void ContentGfxCache::refresh(const Block& def, const Atlas& atlas) {
|
|||||||
sideregions[def.rt.id * 6 + side] = atlas.get(TEXTURE_NOTFOUND);
|
sideregions[def.rt.id * 6 + side] = atlas.get(TEXTURE_NOTFOUND);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (def.model == BlockModelType::CUSTOM) {
|
if (def.model.type == BlockModelType::CUSTOM) {
|
||||||
auto model = assets.require<model::Model>(def.modelName);
|
auto model = assets.require<model::Model>(def.model.name);
|
||||||
// temporary dirty fix tbh
|
// temporary dirty fix tbh
|
||||||
if (def.modelName.find(':') == std::string::npos) {
|
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) {
|
||||||
|
|||||||
@ -44,7 +44,7 @@ void BlockWrapsRenderer::draw(const BlockWrapper& wrapper) {
|
|||||||
}
|
}
|
||||||
if (vox->id != BLOCK_VOID) {
|
if (vox->id != BLOCK_VOID) {
|
||||||
const auto& def = level.content.getIndices()->blocks.require(vox->id);
|
const auto& def = level.content.getIndices()->blocks.require(vox->id);
|
||||||
switch (def.model) {
|
switch (def.model.type) {
|
||||||
case BlockModelType::BLOCK:
|
case BlockModelType::BLOCK:
|
||||||
batch->cube(
|
batch->cube(
|
||||||
glm::vec3(wrapper.position) + glm::vec3(0.5f),
|
glm::vec3(wrapper.position) + glm::vec3(0.5f),
|
||||||
|
|||||||
@ -32,7 +32,7 @@ std::unique_ptr<ImageData> BlocksPreview::draw(
|
|||||||
cache.getRegion(id, 4), cache.getRegion(id, 5)};
|
cache.getRegion(id, 4), cache.getRegion(id, 5)};
|
||||||
|
|
||||||
glm::vec3 offset(0.1f, 0.5f, 0.1f);
|
glm::vec3 offset(0.1f, 0.5f, 0.1f);
|
||||||
switch (def.model) {
|
switch (def.model.type) {
|
||||||
case BlockModelType::NONE:
|
case BlockModelType::NONE:
|
||||||
// something went wrong...
|
// something went wrong...
|
||||||
break;
|
break;
|
||||||
|
|||||||
@ -453,7 +453,7 @@ void BlocksRenderer::render(
|
|||||||
int x = i % CHUNK_W;
|
int x = i % CHUNK_W;
|
||||||
int y = i / (CHUNK_D * CHUNK_W);
|
int y = i / (CHUNK_D * CHUNK_W);
|
||||||
int z = (i / CHUNK_D) % CHUNK_W;
|
int z = (i / CHUNK_D) % CHUNK_W;
|
||||||
switch (def.model) {
|
switch (def.model.type) {
|
||||||
case BlockModelType::BLOCK:
|
case BlockModelType::BLOCK:
|
||||||
blockCube({x, y, z}, texfaces, def, vox.state, !def.shadeless,
|
blockCube({x, y, z}, texfaces, def, vox.state, !def.shadeless,
|
||||||
def.ambientOcclusion);
|
def.ambientOcclusion);
|
||||||
@ -516,7 +516,7 @@ SortingMeshData BlocksRenderer::renderTranslucent(
|
|||||||
int x = i % CHUNK_W;
|
int x = i % CHUNK_W;
|
||||||
int y = i / (CHUNK_D * CHUNK_W);
|
int y = i / (CHUNK_D * CHUNK_W);
|
||||||
int z = (i / CHUNK_D) % CHUNK_W;
|
int z = (i / CHUNK_D) % CHUNK_W;
|
||||||
switch (def.model) {
|
switch (def.model.type) {
|
||||||
case BlockModelType::BLOCK:
|
case BlockModelType::BLOCK:
|
||||||
blockCube({x, y, z}, texfaces, def, vox.state, !def.shadeless,
|
blockCube({x, y, z}, texfaces, def, vox.state, !def.shadeless,
|
||||||
def.ambientOcclusion);
|
def.ambientOcclusion);
|
||||||
|
|||||||
@ -50,16 +50,16 @@ static inline UVRegion get_region_for(
|
|||||||
|
|
||||||
void ModelsGenerator::prepare(Content& content, Assets& assets) {
|
void ModelsGenerator::prepare(Content& content, Assets& assets) {
|
||||||
for (auto& [name, def] : content.blocks.getDefs()) {
|
for (auto& [name, def] : content.blocks.getDefs()) {
|
||||||
if (def->model == BlockModelType::CUSTOM && def->modelName.empty()) {
|
if (def->model.type == BlockModelType::CUSTOM && def->model.name.empty()) {
|
||||||
assets.store(
|
assets.store(
|
||||||
std::make_unique<model::Model>(
|
std::make_unique<model::Model>(
|
||||||
loadCustomBlockModel(
|
loadCustomBlockModel(
|
||||||
def->customModelRaw, assets, !def->shadeless
|
def->model.customRaw, assets, !def->shadeless
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
name + ".model"
|
name + ".model"
|
||||||
);
|
);
|
||||||
def->modelName = def->name + ".model";
|
def->model.name = def->name + ".model";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (auto& [name, def] : content.items.getDefs()) {
|
for (auto& [name, def] : content.items.getDefs()) {
|
||||||
@ -131,12 +131,12 @@ model::Model ModelsGenerator::generate(
|
|||||||
if (def.iconType == ItemIconType::BLOCK) {
|
if (def.iconType == ItemIconType::BLOCK) {
|
||||||
auto model = assets.require<model::Model>("block");
|
auto model = assets.require<model::Model>("block");
|
||||||
const auto& blockDef = content.blocks.require(def.icon);
|
const auto& blockDef = content.blocks.require(def.icon);
|
||||||
if (blockDef.model == BlockModelType::XSPRITE) {
|
if (blockDef.model.type == BlockModelType::XSPRITE) {
|
||||||
return create_flat_model(
|
return create_flat_model(
|
||||||
"blocks:" + blockDef.textureFaces.at(0), assets
|
"blocks:" + blockDef.textureFaces.at(0), assets
|
||||||
);
|
);
|
||||||
} else if (blockDef.model == BlockModelType::CUSTOM) {
|
} else if (blockDef.model.type == BlockModelType::CUSTOM) {
|
||||||
model = assets.require<model::Model>(blockDef.modelName);
|
model = assets.require<model::Model>(blockDef.model.name);
|
||||||
for (auto& mesh : model.meshes) {
|
for (auto& mesh : model.meshes) {
|
||||||
mesh.scale(glm::vec3(0.2f));
|
mesh.scale(glm::vec3(0.2f));
|
||||||
}
|
}
|
||||||
@ -144,7 +144,7 @@ model::Model ModelsGenerator::generate(
|
|||||||
}
|
}
|
||||||
for (auto& mesh : model.meshes) {
|
for (auto& mesh : model.meshes) {
|
||||||
mesh.lighting = !blockDef.shadeless;
|
mesh.lighting = !blockDef.shadeless;
|
||||||
switch (blockDef.model) {
|
switch (blockDef.model.type) {
|
||||||
case BlockModelType::AABB: {
|
case BlockModelType::AABB: {
|
||||||
glm::vec3 size = blockDef.hitboxes.at(0).size();
|
glm::vec3 size = blockDef.hitboxes.at(0).size();
|
||||||
float m = glm::max(size.x, glm::max(size.y, size.z));
|
float m = glm::max(size.x, glm::max(size.y, size.z));
|
||||||
|
|||||||
@ -312,7 +312,7 @@ static int l_get_textures(lua::State* L) {
|
|||||||
|
|
||||||
static int l_get_model(lua::State* L) {
|
static int l_get_model(lua::State* L) {
|
||||||
if (auto def = require_block(L)) {
|
if (auto def = require_block(L)) {
|
||||||
return lua::pushlstring(L, BlockModelTypeMeta.getName(def->model));
|
return lua::pushlstring(L, BlockModelTypeMeta.getName(def->model.type));
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -143,7 +143,6 @@ void Block::cloneTo(Block& dst) {
|
|||||||
if (particles) {
|
if (particles) {
|
||||||
dst.particles = std::make_unique<ParticlesPreset>(*particles);
|
dst.particles = std::make_unique<ParticlesPreset>(*particles);
|
||||||
}
|
}
|
||||||
dst.customModelRaw = customModelRaw;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static std::set<std::string, std::less<>> RESERVED_BLOCK_FIELDS {
|
static std::set<std::string, std::less<>> RESERVED_BLOCK_FIELDS {
|
||||||
|
|||||||
@ -94,6 +94,16 @@ enum class BlockModelType {
|
|||||||
CUSTOM
|
CUSTOM
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct BlockModel {
|
||||||
|
BlockModelType type = BlockModelType::BLOCK;
|
||||||
|
|
||||||
|
/// @brief Custom model raw data
|
||||||
|
dv::value customRaw = nullptr;
|
||||||
|
|
||||||
|
/// @brief Custom model name (generated or an asset)
|
||||||
|
std::string name = "";
|
||||||
|
};
|
||||||
|
|
||||||
VC_ENUM_METADATA(BlockModelType)
|
VC_ENUM_METADATA(BlockModelType)
|
||||||
{"none", BlockModelType::NONE},
|
{"none", BlockModelType::NONE},
|
||||||
{"block", BlockModelType::BLOCK},
|
{"block", BlockModelType::BLOCK},
|
||||||
@ -152,13 +162,8 @@ public:
|
|||||||
/// @brief Influences visible block sides for transparent blocks
|
/// @brief Influences visible block sides for transparent blocks
|
||||||
uint8_t drawGroup = 0;
|
uint8_t drawGroup = 0;
|
||||||
|
|
||||||
/// @brief Block model type
|
/// @brief Block model
|
||||||
BlockModelType model = BlockModelType::BLOCK;
|
BlockModel model {};
|
||||||
|
|
||||||
/// @brief Custom model raw data
|
|
||||||
dv::value customModelRaw = nullptr;
|
|
||||||
|
|
||||||
std::string modelName = "";
|
|
||||||
|
|
||||||
/// @brief Culling mode
|
/// @brief Culling mode
|
||||||
CullingMode culling = CullingMode::DEFAULT;
|
CullingMode culling = CullingMode::DEFAULT;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user