Allow low-def models to be biome tinted
parent
aee43750f4
commit
f7ea3e6b59
|
@ -6,14 +6,14 @@
|
|||
|
||||
LocalDefinitionAtlas::LocalDefinitionAtlas(TextureAtlas& atlas) {
|
||||
//Invalid Node
|
||||
BlockModel invalidModel = BlockModel::createCube({atlas["_missing"]});
|
||||
BlockDef* invalid = new BlockDef("invalid", 0, "Invalid (you broke the game!)", 1, invalidModel, true, {{}}, {{}});
|
||||
BlockModel invalidModel = BlockModel::createCube({atlas["_missing"]}, {false});
|
||||
BlockDef* invalid = new BlockDef("invalid", 0, "Invalid (you broke the game!)", 1, invalidModel, invalidModel, true, {{}}, {{}});
|
||||
defs.push_back(invalid);
|
||||
defTable.insert({"invalid", 0});
|
||||
|
||||
//Air Node
|
||||
BlockModel nullModel {};
|
||||
BlockDef* air = new BlockDef("air", 0, "Air", 1, nullModel, false, {}, {});
|
||||
BlockDef* air = new BlockDef("air", 0, "Air", 1, nullModel, nullModel, false, {}, {});
|
||||
defs.push_back(air);
|
||||
defTable.insert({"air", 1});
|
||||
}
|
||||
|
|
|
@ -7,13 +7,13 @@
|
|||
ServerDefinitionAtlas::ServerDefinitionAtlas() {
|
||||
|
||||
//Invalid Node
|
||||
BlockModel invalidModel = BlockModel::createCube({});
|
||||
BlockDef* invalid = new BlockDef("invalid", INVALID, "Invalid (you broke the game!)", 1, invalidModel, true, {{}}, {{}});
|
||||
BlockModel invalidModel = BlockModel::createCube({}, {false});
|
||||
BlockDef* invalid = new BlockDef("invalid", INVALID, "Invalid (you broke the game!)", 1, invalidModel, invalidModel, true, {{}}, {{}});
|
||||
registerDef(invalid);
|
||||
|
||||
//Air Node
|
||||
BlockModel nullModel {};
|
||||
BlockDef* air = new BlockDef("air", AIR, "Air (you broke the game!)", 1, nullModel, false, {}, {});
|
||||
BlockDef* air = new BlockDef("air", AIR, "Air (you broke the game!)", 1, nullModel, nullModel, false, {}, {});
|
||||
registerDef(air);
|
||||
}
|
||||
|
||||
|
|
|
@ -5,15 +5,17 @@
|
|||
#include "BlockDef.h"
|
||||
|
||||
BlockDef::BlockDef(const std::string &identifier, const std::string& name, unsigned short maxStackSize,
|
||||
const BlockModel &model, bool solid, const std::vector<SelectionBox>& sBoxes, const std::vector<SelectionBox>& cBoxes) :
|
||||
BlockDef(identifier, 0, name, maxStackSize, model, solid, sBoxes, cBoxes) {}
|
||||
const BlockModel &model, const BlockModel& farModel, bool solid, const std::vector<SelectionBox>& sBoxes,
|
||||
const std::vector<SelectionBox>& cBoxes) :
|
||||
BlockDef(identifier, 0, name, maxStackSize, model, farModel, solid, sBoxes, cBoxes) {}
|
||||
|
||||
BlockDef::BlockDef(const std::string& identifier, unsigned int index, const std::string& name,
|
||||
unsigned short maxStackSize, const BlockModel& model, bool solid,
|
||||
unsigned short maxStackSize, const BlockModel& model, const BlockModel& farModel, bool solid,
|
||||
const std::vector<SelectionBox>& sBoxes, const std::vector<SelectionBox>& cBoxes) :
|
||||
|
||||
ItemDef {identifier, name, index, maxStackSize, ItemDef::Type::BLOCK},
|
||||
model(model),
|
||||
farModel(farModel),
|
||||
culls(model.culls),
|
||||
solid(solid),
|
||||
sBoxes(sBoxes),
|
||||
|
@ -24,7 +26,6 @@ void BlockDef::createModel() {
|
|||
unsigned int indOffset = 0;
|
||||
|
||||
std::vector<EntityVertex> entityVertices;
|
||||
// std::vector<GuiVertex> guiVertices;
|
||||
std::vector<unsigned int> indices;
|
||||
|
||||
for (std::vector<MeshPart>& pArray : model.parts) {
|
||||
|
@ -38,19 +39,9 @@ void BlockDef::createModel() {
|
|||
vertex.nml,
|
||||
{}, {}
|
||||
});
|
||||
// float brightness = 0.8 + (glm::abs(vertex.nml.z) * 0.2) + (vertex.nml.y * 0.4);
|
||||
// guiVertices.push_back(GuiVertex {
|
||||
// vertex.pos - glm::vec3(0.5f),
|
||||
// {vertex.tex.x, vertex.tex.y, 0, 1},
|
||||
// glm::vec3(brightness),
|
||||
// true
|
||||
// });
|
||||
}
|
||||
|
||||
for (unsigned int index : p.indices) {
|
||||
indices.push_back(indOffset + index);
|
||||
}
|
||||
|
||||
for (unsigned int index : p.indices) indices.push_back(indOffset + index);
|
||||
indOffset += p.vertices.size();
|
||||
}
|
||||
}
|
||||
|
@ -58,6 +49,4 @@ void BlockDef::createModel() {
|
|||
entity->create(entityVertices, indices);
|
||||
entityModel = std::make_shared<Model>();
|
||||
entityModel->fromMesh(std::move(entity));
|
||||
|
||||
// guiModel->create(guiVertices, indices);
|
||||
}
|
||||
|
|
|
@ -16,15 +16,16 @@ class BlockDef : public ItemDef {
|
|||
public:
|
||||
BlockDef() = default;
|
||||
BlockDef(const std::string& identifier, const std::string& name, unsigned short maxStackSize,
|
||||
const BlockModel& model, bool solid, const std::vector<SelectionBox>& sBoxes, const std::vector<SelectionBox>& cBoxes);
|
||||
const BlockModel& model, const BlockModel& farModel, bool solid, const std::vector<SelectionBox>& sBoxes,
|
||||
const std::vector<SelectionBox>& cBoxes);
|
||||
|
||||
BlockDef(const std::string& identifier, unsigned int index, const std::string& name,
|
||||
unsigned short maxStackSize, const BlockModel& model, bool solid,
|
||||
unsigned short maxStackSize, const BlockModel& model, const BlockModel& farModel, bool solid,
|
||||
const std::vector<SelectionBox>& sBoxes, const std::vector<SelectionBox>& cBoxes);
|
||||
|
||||
void createModel();
|
||||
|
||||
BlockModel model;
|
||||
BlockModel model, farModel;
|
||||
bool culls = false;
|
||||
bool solid = false;
|
||||
|
||||
|
|
|
@ -19,16 +19,20 @@ struct BlockModel {
|
|||
bool culls = false;
|
||||
bool visible = false;
|
||||
|
||||
static BlockModel createCube(const std::vector<std::shared_ptr<AtlasRef>>& textureRefs) {
|
||||
static BlockModel createCube(std::vector<std::shared_ptr<AtlasRef>> textureRefs, std::vector<bool> biomeTints) {
|
||||
BlockModel blockModel;
|
||||
blockModel.visible = true;
|
||||
blockModel.culls = true;
|
||||
|
||||
std::vector<BlockModelVertex> vertices {};
|
||||
std::vector<unsigned int> indices {};
|
||||
unsigned int accessInd;
|
||||
|
||||
for (auto& ref : textureRefs) blockModel.textureRefs.insert(ref);
|
||||
|
||||
if (textureRefs.empty()) textureRefs.emplace_back(nullptr);
|
||||
if (biomeTints.empty()) biomeTints.emplace_back(false);
|
||||
|
||||
//Left Face
|
||||
vertices = {
|
||||
{glm::vec3{0, 0, 0}, glm::vec3{}, glm::vec2{0, 1}, glm::vec2{}},
|
||||
|
@ -36,7 +40,8 @@ struct BlockModel {
|
|||
{glm::vec3{0, 1, 1}, glm::vec3{}, glm::vec2{1, 0}, glm::vec2{}},
|
||||
{glm::vec3{0, 1, 0}, glm::vec3{}, glm::vec2{0, 0}, glm::vec2{}}};
|
||||
indices = {0, 1, 2, 2, 3, 0};
|
||||
MeshPart leftMeshPart(vertices, indices, (textureRefs.empty()) ? nullptr : textureRefs[(std::min)(static_cast<int>(textureRefs.size() - 1), 2)], false);
|
||||
accessInd = std::max(0, std::min(static_cast<int>(textureRefs.size() - 1), 2));
|
||||
MeshPart leftMeshPart(vertices, indices, textureRefs[accessInd], biomeTints[accessInd]);
|
||||
blockModel.parts[static_cast<int>(Dir::LEFT)].push_back(leftMeshPart);
|
||||
|
||||
//Right Face
|
||||
|
@ -46,7 +51,8 @@ struct BlockModel {
|
|||
{glm::vec3{1, 0, 0}, glm::vec3{}, glm::vec2{0, 1}, glm::vec2{}},
|
||||
{glm::vec3{1, 1, 0}, glm::vec3{}, glm::vec2{0, 0}, glm::vec2{}}};
|
||||
indices = {0, 1, 2, 2, 3, 0};
|
||||
MeshPart rightMeshPart(vertices, indices, (textureRefs.empty()) ? nullptr : textureRefs[(std::min)(static_cast<int>(textureRefs.size() - 1), 3)], false);
|
||||
accessInd = std::max(0, std::min(static_cast<int>(textureRefs.size() - 1), 3));
|
||||
MeshPart rightMeshPart(vertices, indices, textureRefs[accessInd], biomeTints[accessInd]);
|
||||
blockModel.parts[static_cast<int>(Dir::RIGHT)].push_back(rightMeshPart);
|
||||
|
||||
//Top Face
|
||||
|
@ -56,7 +62,8 @@ struct BlockModel {
|
|||
{glm::vec3{1, 1, 1}, glm::vec3{}, glm::vec2{1, 1}, glm::vec2{}},
|
||||
{glm::vec3{1, 1, 0}, glm::vec3{}, glm::vec2{1, 0}, glm::vec2{}}};
|
||||
indices = {0, 1, 2, 2, 3, 0};
|
||||
MeshPart topMeshPart(vertices, indices, (textureRefs.empty()) ? nullptr : textureRefs[(std::min)(static_cast<int>(textureRefs.size() - 1), 0)], false);
|
||||
accessInd = std::max(0, std::min(static_cast<int>(textureRefs.size() - 1), 0));
|
||||
MeshPart topMeshPart(vertices, indices, textureRefs[accessInd], biomeTints[accessInd]);
|
||||
blockModel.parts[static_cast<int>(Dir::TOP)].push_back(topMeshPart);
|
||||
|
||||
//Bottom Face
|
||||
|
@ -66,7 +73,8 @@ struct BlockModel {
|
|||
{glm::vec3{1, 0, 1}, glm::vec3{}, glm::vec2{1, 1}, glm::vec2{}},
|
||||
{glm::vec3{0, 0, 1}, glm::vec3{}, glm::vec2{0, 1}, glm::vec2{}}};
|
||||
indices = {0, 1, 2, 2, 3, 0};
|
||||
MeshPart bottomMeshPart(vertices, indices, (textureRefs.empty()) ? nullptr : textureRefs[(std::min)(static_cast<int>(textureRefs.size() - 1), 1)], false);
|
||||
accessInd = std::max(0, std::min(static_cast<int>(textureRefs.size() - 1), 1));
|
||||
MeshPart bottomMeshPart(vertices, indices, textureRefs[accessInd], biomeTints[accessInd]);
|
||||
blockModel.parts[static_cast<int>(Dir::BOTTOM)].push_back(bottomMeshPart);
|
||||
|
||||
//Front Face
|
||||
|
@ -76,7 +84,8 @@ struct BlockModel {
|
|||
{glm::vec3{1, 1, 1}, glm::vec3{}, glm::vec2{1, 0}, glm::vec2{}},
|
||||
{glm::vec3{0, 1, 1}, glm::vec3{}, glm::vec2{0, 0}, glm::vec2{}}};
|
||||
indices = {0, 1, 2, 2, 3, 0};
|
||||
MeshPart frontMeshPart(vertices, indices, (textureRefs.empty()) ? nullptr : textureRefs[(std::min)(static_cast<int>(textureRefs.size() - 1), 4)], false);
|
||||
accessInd = std::max(0, std::min(static_cast<int>(textureRefs.size() - 1), 4));
|
||||
MeshPart frontMeshPart(vertices, indices, textureRefs[accessInd], biomeTints[accessInd]);
|
||||
blockModel.parts[static_cast<int>(Dir::FRONT)].push_back(frontMeshPart);
|
||||
|
||||
//Back Face
|
||||
|
@ -86,7 +95,8 @@ struct BlockModel {
|
|||
{glm::vec3{1, 1, 0}, glm::vec3{}, glm::vec2{1, 0}, glm::vec2{}},
|
||||
{glm::vec3{1, 0, 0}, glm::vec3{}, glm::vec2{1, 1}, glm::vec2{}}};
|
||||
indices = {0, 1, 2, 2, 3, 0};
|
||||
MeshPart backMeshPart(vertices, indices, (textureRefs.empty()) ? nullptr : textureRefs[(std::min)(static_cast<int>(textureRefs.size() - 1), 5)], false);
|
||||
accessInd = std::max(0, std::min(static_cast<int>(textureRefs.size() - 1), 5));
|
||||
MeshPart backMeshPart(vertices, indices, textureRefs[accessInd], biomeTints[accessInd]);
|
||||
blockModel.parts[static_cast<int>(Dir::BACK)].push_back(backMeshPart);
|
||||
|
||||
return blockModel;
|
||||
|
|
|
@ -2,17 +2,26 @@
|
|||
// Created by aurailus on 01/12/18.
|
||||
//
|
||||
|
||||
#include <thread>
|
||||
#include <vector>
|
||||
#include <glm/gtx/normal.hpp>
|
||||
#include "../MeshDetails.h"
|
||||
#include "../../../../world/chunk/BlockChunk.h"
|
||||
//#include "../../../../def/item/MeshPart.h"
|
||||
//#include "../../../../def/item/BlockModelVertex.h"
|
||||
//#include "../../../../def/item/BlockDef.h"
|
||||
//#include "../../../../util/Vec.h"
|
||||
#include "../../../../util/Timer.h"
|
||||
#include "MeshGenerator.h"
|
||||
|
||||
MeshGenerator::MeshGenerator(MeshDetails* meshDetails, LocalDefs& defs, std::shared_ptr<BlockChunk> chunk,
|
||||
std::array<std::shared_ptr<BlockChunk>, 6> adjacent,
|
||||
std::array<NoiseSample, 3>& blockOffsets) :
|
||||
meshDetails(meshDetails),
|
||||
|
||||
defs(defs),
|
||||
atlas(defs.defs),
|
||||
chunk(chunk),
|
||||
adjacent(adjacent) {
|
||||
atlas(defs.defs),
|
||||
adjacent(adjacent),
|
||||
meshDetails(meshDetails) {
|
||||
|
||||
meshDetails->vertices.reserve(5000);
|
||||
meshDetails->indices.reserve(7000);
|
||||
|
@ -23,8 +32,8 @@ MeshGenerator::MeshGenerator(MeshDetails* meshDetails, LocalDefs& defs, std::sha
|
|||
glm::vec3 vis;
|
||||
glm::vec3 check;
|
||||
|
||||
for (unsigned int i = 0; i < 4096; i++) {
|
||||
BlockModel& model = atlas.blockFromId(chunk->getBlock(i)).model;
|
||||
for (unsigned short i = 0; i < 4096; i++) {
|
||||
BlockModel& model = atlas.blockFromId(chunk->getBlock(i)).farModel;
|
||||
glm::vec3 biomeTint = defs.biomes.biomeFromId(chunk->getBiome(i)).biomeTint;
|
||||
|
||||
if (model.visible) {
|
||||
|
@ -77,14 +86,14 @@ MeshGenerator::MeshGenerator(MeshDetails* meshDetails, LocalDefs& defs, std::sha
|
|||
BlockDef& MeshGenerator::getBlockAt(const glm::ivec3 &pos) {
|
||||
if (pos.x < 0 || pos.x >= 16 || pos.y < 0 || pos.y >= 16 || pos.z < 0 || pos.z >= 16) {
|
||||
|
||||
if (pos.x == 16) return atlas.blockFromId(adjacent[0]->getBlock(pos - glm::ivec3(16, 0, 0)));
|
||||
if (pos.x == -1) return atlas.blockFromId(adjacent[1]->getBlock(pos + glm::ivec3(16, 0, 0)));
|
||||
if (pos.x == 16) return atlas.blockFromId(adjacent[0]->getBlock(pos - glm::ivec3 {16, 0, 0}));
|
||||
if (pos.x == -1) return atlas.blockFromId(adjacent[1]->getBlock(pos + glm::ivec3 {16, 0, 0}));
|
||||
|
||||
if (pos.y == 16) return atlas.blockFromId(adjacent[2]->getBlock(pos - glm::ivec3(0, 16, 0)));
|
||||
if (pos.y == -1) return atlas.blockFromId(adjacent[3]->getBlock(pos + glm::ivec3(0, 16, 0)));
|
||||
if (pos.y == 16) return atlas.blockFromId(adjacent[2]->getBlock(pos - glm::ivec3 {0, 16, 0}));
|
||||
if (pos.y == -1) return atlas.blockFromId(adjacent[3]->getBlock(pos + glm::ivec3 {0, 16, 0}));
|
||||
|
||||
if (pos.z == 16) return atlas.blockFromId(adjacent[4]->getBlock(pos - glm::ivec3(0, 0, 16)));
|
||||
if (pos.z == -1) return atlas.blockFromId(adjacent[5]->getBlock(pos + glm::ivec3(0, 0, 16)));
|
||||
if (pos.z == 16) return atlas.blockFromId(adjacent[4]->getBlock(pos - glm::ivec3 {0, 0, 16}));
|
||||
if (pos.z == -1) return atlas.blockFromId(adjacent[5]->getBlock(pos + glm::ivec3 {0, 0, 16}));
|
||||
}
|
||||
|
||||
return atlas.blockFromId(chunk->getBlock(pos));
|
||||
|
@ -92,8 +101,6 @@ BlockDef& MeshGenerator::getBlockAt(const glm::ivec3 &pos) {
|
|||
|
||||
void MeshGenerator::addFaces(const glm::vec3 &offset, const std::vector<MeshPart> &meshParts, const glm::vec3& tint) {
|
||||
for (const MeshPart& mp : meshParts) {
|
||||
|
||||
|
||||
glm::vec3 modData = {};
|
||||
|
||||
switch (mp.shaderMod) {
|
||||
|
|
|
@ -9,19 +9,11 @@
|
|||
|
||||
#define GLM_ENABLE_EXPERIMENTAL
|
||||
|
||||
#include <glm/gtx/normal.hpp>
|
||||
#include <vector>
|
||||
#include <cstdio>
|
||||
|
||||
#include "../../../../def/item/MeshPart.h"
|
||||
#include "../../../../def/item/BlockModelVertex.h"
|
||||
#include "../../../../world/chunk/BlockChunk.h"
|
||||
#include "../../../../def/LocalDefs.h"
|
||||
#include "../../../../def/item/BlockDef.h"
|
||||
#include "../../../../def/gen/NoiseSample.h"
|
||||
#include "../../../../util/Vec.h"
|
||||
#include "../../../../util/Timer.h"
|
||||
#include "../MeshDetails.h"
|
||||
|
||||
class MeshDetails;
|
||||
class BlockChunk;
|
||||
|
||||
class MeshGenerator {
|
||||
public:
|
||||
|
|
|
@ -55,7 +55,7 @@ namespace RegisterBlocks {
|
|||
if (!ldTexturesOpt) lowdef_textures = textures;
|
||||
else {
|
||||
for (auto pair : *ldTexturesOpt) {
|
||||
if (!pair.second.is<std::string>()) throw "textures table has non-string value!";
|
||||
if (!pair.second.is<std::string>()) throw "lowdef_textures table has non-string value!";
|
||||
lowdef_textures.push_back(pair.second.as<std::string>());
|
||||
}
|
||||
}
|
||||
|
@ -189,19 +189,24 @@ namespace RegisterBlocks {
|
|||
|
||||
if (atlas) {
|
||||
std::vector<std::shared_ptr<AtlasRef>> refs;
|
||||
std::vector<bool> biomeTints;
|
||||
for (auto i = 0; i < lowdef_textures.size(); i++) {
|
||||
std::string texture = lowdef_textures[i];
|
||||
if (strncmp(texture.data(), "biometint(", 10) == 0) {
|
||||
texture = texture.substr(10, texture.length() - 11);
|
||||
biomeTints.emplace_back(true);
|
||||
}
|
||||
else {
|
||||
biomeTints.emplace_back(false);
|
||||
}
|
||||
refs.push_back((*atlas)[texture]);
|
||||
}
|
||||
/*hiccup*/
|
||||
lowdefModel = BlockModel::createCube(refs);
|
||||
lowdefModel = BlockModel::createCube(refs, biomeTints);
|
||||
}
|
||||
else {
|
||||
/*hiccup*//*hiccup*/
|
||||
lowdefModel = BlockModel::createCube({}); /*hiccup*/
|
||||
lowdefModel = BlockModel::createCube({}, {}); /*hiccup*/
|
||||
}
|
||||
/*hiccup*//*hiccup*/
|
||||
lowdefModel.culls = ldRender;
|
||||
|
@ -250,7 +255,7 @@ namespace RegisterBlocks {
|
|||
defs.size(),
|
||||
*nameOpt,
|
||||
maxStack, /*hiccup*//*hiccup*/
|
||||
models.first,
|
||||
models.first, models.second,
|
||||
/*hiccup*/solid,/*hiccup*/
|
||||
std::move(selectionBoxes),
|
||||
std::move(collisionBoxes)
|
||||
|
|
Loading…
Reference in New Issue