rename BlockModel to BlockModelType
This commit is contained in:
parent
ad07ec61cd
commit
718f5d1089
@ -28,7 +28,7 @@ std::unique_ptr<Content> ContentBuilder::build() {
|
||||
// Generating runtime info
|
||||
def.rt.id = blockDefsIndices.size();
|
||||
def.rt.emissive = *reinterpret_cast<uint32_t*>(def.emission);
|
||||
def.rt.solid = def.model == BlockModel::block;
|
||||
def.rt.solid = def.model == BlockModelType::BLOCK;
|
||||
def.rt.extended = def.size.x > 1 || def.size.y > 1 || def.size.z > 1;
|
||||
|
||||
const float EPSILON = 0.01f;
|
||||
|
||||
@ -86,11 +86,11 @@ template<> void ContentUnitLoader<Block>::loadUnit(
|
||||
}
|
||||
|
||||
// block model
|
||||
std::string modelTypeName = BlockModelMeta.getNameString(def.model);
|
||||
std::string modelTypeName = BlockModelTypeMeta.getNameString(def.model);
|
||||
root.at("model").get(modelTypeName);
|
||||
root.at("model-name").get(def.modelName);
|
||||
if (BlockModelMeta.getItem(modelTypeName, def.model)) {
|
||||
if (def.model == BlockModel::custom && def.customModelRaw == nullptr) {
|
||||
if (BlockModelTypeMeta.getItem(modelTypeName, def.model)) {
|
||||
if (def.model == BlockModelType::CUSTOM && def.customModelRaw == nullptr) {
|
||||
if (root.has("model-primitives")) {
|
||||
def.customModelRaw = root["model-primitives"];
|
||||
} else if (def.modelName.empty()) {
|
||||
@ -99,7 +99,7 @@ template<> void ContentUnitLoader<Block>::loadUnit(
|
||||
}
|
||||
} else if (!modelTypeName.empty()) {
|
||||
logger.error() << "unknown model: " << modelTypeName;
|
||||
def.model = BlockModel::none;
|
||||
def.model = BlockModelType::NONE;
|
||||
}
|
||||
|
||||
std::string cullingModeName = CullingModeMeta.getNameString(def.culling);
|
||||
@ -171,9 +171,9 @@ template<> void ContentUnitLoader<Block>::loadUnit(
|
||||
"block " + util::quote(def.name) + ": invalid block size"
|
||||
);
|
||||
}
|
||||
if (def.model == BlockModel::block &&
|
||||
if (def.model == BlockModelType::BLOCK &&
|
||||
(def.size.x != 1 || def.size.y != 1 || def.size.z != 1)) {
|
||||
def.model = BlockModel::aabb;
|
||||
def.model = BlockModelType::AABB;
|
||||
def.hitboxes = {AABB(def.size)};
|
||||
}
|
||||
}
|
||||
|
||||
@ -19,7 +19,7 @@ void corecontent::setup(Input& input, ContentBuilder& builder) {
|
||||
block.skyLightPassing = true;
|
||||
block.obstacle = false;
|
||||
block.selectable = false;
|
||||
block.model = BlockModel::none;
|
||||
block.model = BlockModelType::NONE;
|
||||
block.pickingItem = CORE_EMPTY;
|
||||
}
|
||||
{
|
||||
|
||||
@ -35,7 +35,7 @@ void ContentGfxCache::refresh(const Block& def, const Atlas& atlas) {
|
||||
sideregions[def.rt.id * 6 + side] = atlas.get(TEXTURE_NOTFOUND);
|
||||
}
|
||||
}
|
||||
if (def.model == BlockModel::custom) {
|
||||
if (def.model == BlockModelType::CUSTOM) {
|
||||
auto model = assets.require<model::Model>(def.modelName);
|
||||
// temporary dirty fix tbh
|
||||
if (def.modelName.find(':') == std::string::npos) {
|
||||
|
||||
@ -45,7 +45,7 @@ void BlockWrapsRenderer::draw(const BlockWrapper& wrapper) {
|
||||
if (vox->id != BLOCK_VOID) {
|
||||
const auto& def = level.content.getIndices()->blocks.require(vox->id);
|
||||
switch (def.model) {
|
||||
case BlockModel::block:
|
||||
case BlockModelType::BLOCK:
|
||||
batch->cube(
|
||||
glm::vec3(wrapper.position) + glm::vec3(0.5f),
|
||||
glm::vec3(1.01f),
|
||||
@ -54,7 +54,7 @@ void BlockWrapsRenderer::draw(const BlockWrapper& wrapper) {
|
||||
false
|
||||
);
|
||||
break;
|
||||
case BlockModel::aabb: {
|
||||
case BlockModelType::AABB: {
|
||||
const auto& aabb =
|
||||
(def.rotatable ? def.rt.hitboxes[vox->state.rotation]
|
||||
: def.hitboxes)
|
||||
|
||||
@ -33,16 +33,16 @@ std::unique_ptr<ImageData> BlocksPreview::draw(
|
||||
|
||||
glm::vec3 offset(0.1f, 0.5f, 0.1f);
|
||||
switch (def.model) {
|
||||
case BlockModel::none:
|
||||
case BlockModelType::NONE:
|
||||
// something went wrong...
|
||||
break;
|
||||
case BlockModel::block:
|
||||
case BlockModelType::BLOCK:
|
||||
shader.uniformMatrix("u_apply", glm::translate(glm::mat4(1.0f), offset));
|
||||
batch.blockCube(glm::vec3(size * 0.63f), texfaces,
|
||||
glm::vec4(1.0f), !def.rt.emissive);
|
||||
batch.flush();
|
||||
break;
|
||||
case BlockModel::aabb:
|
||||
case BlockModelType::AABB:
|
||||
{
|
||||
glm::vec3 hitbox {};
|
||||
for (const auto& box : def.hitboxes) {
|
||||
@ -60,7 +60,7 @@ std::unique_ptr<ImageData> BlocksPreview::draw(
|
||||
}
|
||||
batch.flush();
|
||||
break;
|
||||
case BlockModel::custom:{
|
||||
case BlockModelType::CUSTOM:{
|
||||
glm::vec3 pmul = glm::vec3(size * 0.63f);
|
||||
glm::vec3 hitbox = glm::vec3(1.0f);
|
||||
glm::vec3 poff = glm::vec3(0.0f, 0.0f, 1.0f);
|
||||
@ -78,7 +78,7 @@ std::unique_ptr<ImageData> BlocksPreview::draw(
|
||||
}
|
||||
break;
|
||||
}
|
||||
case BlockModel::xsprite: {
|
||||
case BlockModelType::XSPRITE: {
|
||||
shader.uniformMatrix("u_apply", glm::translate(glm::mat4(1.0f), offset));
|
||||
glm::vec3 right = glm::normalize(glm::vec3(1.f, 0.f, -1.f));
|
||||
batch.sprite(
|
||||
|
||||
@ -454,21 +454,21 @@ void BlocksRenderer::render(
|
||||
int y = i / (CHUNK_D * CHUNK_W);
|
||||
int z = (i / CHUNK_D) % CHUNK_W;
|
||||
switch (def.model) {
|
||||
case BlockModel::block:
|
||||
case BlockModelType::BLOCK:
|
||||
blockCube({x, y, z}, texfaces, def, vox.state, !def.shadeless,
|
||||
def.ambientOcclusion);
|
||||
break;
|
||||
case BlockModel::xsprite: {
|
||||
case BlockModelType::XSPRITE: {
|
||||
blockXSprite(x, y, z, glm::vec3(1.0f),
|
||||
texfaces[FACE_MX], texfaces[FACE_MZ], 1.0f);
|
||||
break;
|
||||
}
|
||||
case BlockModel::aabb: {
|
||||
case BlockModelType::AABB: {
|
||||
blockAABB({x, y, z}, texfaces, &def, vox.state.rotation,
|
||||
!def.shadeless, def.ambientOcclusion);
|
||||
break;
|
||||
}
|
||||
case BlockModel::custom: {
|
||||
case BlockModelType::CUSTOM: {
|
||||
blockCustomModel({x, y, z}, &def, vox.state.rotation,
|
||||
!def.shadeless, def.ambientOcclusion);
|
||||
break;
|
||||
@ -517,21 +517,21 @@ SortingMeshData BlocksRenderer::renderTranslucent(
|
||||
int y = i / (CHUNK_D * CHUNK_W);
|
||||
int z = (i / CHUNK_D) % CHUNK_W;
|
||||
switch (def.model) {
|
||||
case BlockModel::block:
|
||||
case BlockModelType::BLOCK:
|
||||
blockCube({x, y, z}, texfaces, def, vox.state, !def.shadeless,
|
||||
def.ambientOcclusion);
|
||||
break;
|
||||
case BlockModel::xsprite: {
|
||||
case BlockModelType::XSPRITE: {
|
||||
blockXSprite(x, y, z, glm::vec3(1.0f),
|
||||
texfaces[FACE_MX], texfaces[FACE_MZ], 1.0f);
|
||||
break;
|
||||
}
|
||||
case BlockModel::aabb: {
|
||||
case BlockModelType::AABB: {
|
||||
blockAABB({x, y, z}, texfaces, &def, vox.state.rotation,
|
||||
!def.shadeless, def.ambientOcclusion);
|
||||
break;
|
||||
}
|
||||
case BlockModel::custom: {
|
||||
case BlockModelType::CUSTOM: {
|
||||
blockCustomModel({x, y, z}, &def, vox.state.rotation,
|
||||
!def.shadeless, def.ambientOcclusion);
|
||||
break;
|
||||
|
||||
@ -50,7 +50,7 @@ static inline UVRegion get_region_for(
|
||||
|
||||
void ModelsGenerator::prepare(Content& content, Assets& assets) {
|
||||
for (auto& [name, def] : content.blocks.getDefs()) {
|
||||
if (def->model == BlockModel::custom && def->modelName.empty()) {
|
||||
if (def->model == BlockModelType::CUSTOM && def->modelName.empty()) {
|
||||
assets.store(
|
||||
std::make_unique<model::Model>(
|
||||
loadCustomBlockModel(
|
||||
@ -74,7 +74,7 @@ void ModelsGenerator::prepare(Content& content, Assets& assets) {
|
||||
|
||||
model::Model ModelsGenerator::fromCustom(
|
||||
const Assets& assets,
|
||||
const std::vector<BoxModel>& modelBoxes,
|
||||
const std::vector<AABB>& modelBoxes,
|
||||
const std::vector<std::string>& modelTextures,
|
||||
const std::vector<glm::vec3>& points,
|
||||
bool lighting
|
||||
@ -131,11 +131,11 @@ model::Model ModelsGenerator::generate(
|
||||
if (def.iconType == ItemIconType::BLOCK) {
|
||||
auto model = assets.require<model::Model>("block");
|
||||
const auto& blockDef = content.blocks.require(def.icon);
|
||||
if (blockDef.model == BlockModel::xsprite) {
|
||||
if (blockDef.model == BlockModelType::XSPRITE) {
|
||||
return create_flat_model(
|
||||
"blocks:" + blockDef.textureFaces.at(0), assets
|
||||
);
|
||||
} else if (blockDef.model == BlockModel::custom) {
|
||||
} else if (blockDef.model == BlockModelType::CUSTOM) {
|
||||
model = assets.require<model::Model>(blockDef.modelName);
|
||||
for (auto& mesh : model.meshes) {
|
||||
mesh.scale(glm::vec3(0.2f));
|
||||
@ -145,7 +145,7 @@ model::Model ModelsGenerator::generate(
|
||||
for (auto& mesh : model.meshes) {
|
||||
mesh.lighting = !blockDef.shadeless;
|
||||
switch (blockDef.model) {
|
||||
case BlockModel::aabb: {
|
||||
case BlockModelType::AABB: {
|
||||
glm::vec3 size = blockDef.hitboxes.at(0).size();
|
||||
float m = glm::max(size.x, glm::max(size.y, size.z));
|
||||
m = glm::min(1.0f, m);
|
||||
|
||||
@ -312,7 +312,7 @@ static int l_get_textures(lua::State* L) {
|
||||
|
||||
static int l_get_model(lua::State* L) {
|
||||
if (auto def = require_block(L)) {
|
||||
return lua::pushlstring(L, BlockModelMeta.getName(def->model));
|
||||
return lua::pushlstring(L, BlockModelTypeMeta.getName(def->model));
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -81,25 +81,25 @@ struct BlockRotProfile {
|
||||
static inline std::string PANE_NAME = "pane";
|
||||
};
|
||||
|
||||
enum class BlockModel {
|
||||
enum class BlockModelType {
|
||||
/// @brief invisible
|
||||
none,
|
||||
NONE,
|
||||
/// @brief default cube shape
|
||||
block,
|
||||
BLOCK,
|
||||
/// @brief X-shape (grass)
|
||||
xsprite,
|
||||
XSPRITE,
|
||||
/// @brief box shape sized as block hitbox
|
||||
aabb,
|
||||
AABB,
|
||||
/// @brief custom model defined in json
|
||||
custom
|
||||
CUSTOM
|
||||
};
|
||||
|
||||
VC_ENUM_METADATA(BlockModel)
|
||||
{"none", BlockModel::none},
|
||||
{"block", BlockModel::block},
|
||||
{"X", BlockModel::xsprite},
|
||||
{"aabb", BlockModel::aabb},
|
||||
{"custom", BlockModel::custom},
|
||||
VC_ENUM_METADATA(BlockModelType)
|
||||
{"none", BlockModelType::NONE},
|
||||
{"block", BlockModelType::BLOCK},
|
||||
{"X", BlockModelType::XSPRITE},
|
||||
{"aabb", BlockModelType::AABB},
|
||||
{"custom", BlockModelType::CUSTOM},
|
||||
VC_ENUM_END
|
||||
|
||||
enum class CullingMode {
|
||||
@ -114,8 +114,6 @@ VC_ENUM_METADATA(CullingMode)
|
||||
{"disabled", CullingMode::DISABLED},
|
||||
VC_ENUM_END
|
||||
|
||||
using BoxModel = AABB;
|
||||
|
||||
/// @brief Common kit of block properties applied to groups of blocks
|
||||
struct BlockMaterial : Serializable {
|
||||
std::string name;
|
||||
@ -155,7 +153,7 @@ public:
|
||||
uint8_t drawGroup = 0;
|
||||
|
||||
/// @brief Block model type
|
||||
BlockModel model = BlockModel::block;
|
||||
BlockModelType model = BlockModelType::BLOCK;
|
||||
|
||||
/// @brief Custom model raw data
|
||||
dv::value customModelRaw = nullptr;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user