mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-07 03:51:50 +00:00
Merge branch 'main' into vcm-bones
This commit is contained in:
commit
586fc8fc46
8 changed files with 52 additions and 26 deletions
|
|
@ -34,11 +34,15 @@ std::unique_ptr<Content> ContentBuilder::build() {
|
|||
|
||||
if (def.variants) {
|
||||
for (auto& variant : def.variants->variants) {
|
||||
variant.rt.solid = variant.model.type == BlockModelType::BLOCK;
|
||||
variant.rt.solid =
|
||||
variant.model.type == BlockModelType::BLOCK ||
|
||||
def.explictlySolid;
|
||||
}
|
||||
def.defaults = def.variants->variants.at(0);
|
||||
} else {
|
||||
def.defaults.rt.solid = def.defaults.model.type == BlockModelType::BLOCK;
|
||||
def.defaults.rt.solid =
|
||||
def.defaults.model.type == BlockModelType::BLOCK ||
|
||||
def.explictlySolid;
|
||||
}
|
||||
|
||||
const float EPSILON = 0.01f;
|
||||
|
|
|
|||
|
|
@ -227,6 +227,7 @@ template<> void ContentUnitLoader<Block>::loadUnit(
|
|||
root.at("tick-interval").get(def.tickInterval);
|
||||
root.at("overlay-texture").get(def.overlayTexture);
|
||||
root.at("translucent").get(def.translucent);
|
||||
root.at("solid").get(def.explictlySolid);
|
||||
|
||||
if (root.has("fields")) {
|
||||
def.dataStruct = std::make_unique<StructLayout>();
|
||||
|
|
|
|||
|
|
@ -80,7 +80,7 @@ void BlocksRenderer::face(
|
|||
const glm::vec4(&lights)[4],
|
||||
const glm::vec4& tint
|
||||
) {
|
||||
if (vertexCount + 4 >= capacity) {
|
||||
if (vertexCount + 4 >= capacity || indexCount + 6 >= capacity) {
|
||||
overflow = true;
|
||||
return;
|
||||
}
|
||||
|
|
@ -120,7 +120,7 @@ void BlocksRenderer::faceAO(
|
|||
const UVRegion& region,
|
||||
bool lights
|
||||
) {
|
||||
if (vertexCount + 4 >= capacity) {
|
||||
if (vertexCount + 4 >= capacity || indexCount + 6 >= capacity) {
|
||||
overflow = true;
|
||||
return;
|
||||
}
|
||||
|
|
@ -159,7 +159,7 @@ void BlocksRenderer::face(
|
|||
glm::vec4 tint,
|
||||
bool lights
|
||||
) {
|
||||
if (vertexCount + 4 >= capacity) {
|
||||
if (vertexCount + 4 >= capacity || indexCount + 6 >= capacity) {
|
||||
overflow = true;
|
||||
return;
|
||||
}
|
||||
|
|
@ -274,19 +274,6 @@ void BlocksRenderer::blockAABB(
|
|||
}
|
||||
}
|
||||
|
||||
static bool is_aligned(const glm::vec3& v, float e = 1e-6f) {
|
||||
if (std::abs(v.y) < e && std::abs(v.z) < e && std::abs(v.x) > e) {
|
||||
return true;
|
||||
}
|
||||
if (std::abs(v.x) < e && std::abs(v.z) < e && std::abs(v.y) > e) {
|
||||
return true;
|
||||
}
|
||||
if (std::abs(v.x) < e && std::abs(v.y) < e && std::abs(v.z) > e) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void BlocksRenderer::blockCustomModel(
|
||||
const glm::ivec3& icoord, const Block& block, blockstate states, bool lights, bool ao
|
||||
) {
|
||||
|
|
@ -303,14 +290,34 @@ void BlocksRenderer::blockCustomModel(
|
|||
Z = orient.axes[2];
|
||||
}
|
||||
|
||||
if (!block.rt.extended) {
|
||||
glm::ivec3 offsets[6] {
|
||||
{-1, 0, 0}, {0, -1, 0}, {0, 0, -1},
|
||||
{1, 0, 0}, {0, 1, 0}, {0, 0, 1},
|
||||
};
|
||||
bool culled = true;
|
||||
for (int i = 0; i < 6; i++) {
|
||||
if (isOpen(icoord + offsets[i], block, variant)) {
|
||||
culled = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (culled) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
const auto& model = cache.getModel(block.rt.id, block.getVariantIndex(states.userbits));
|
||||
for (const auto& mesh : model.meshes) {
|
||||
if (vertexCount + mesh.vertices.size() >= capacity) {
|
||||
if (vertexCount + mesh.vertices.size() >= capacity
|
||||
|| indexCount + mesh.vertices.size() >= capacity) {
|
||||
overflow = true;
|
||||
return;
|
||||
}
|
||||
bool shading = mesh.shading && !block.shadeless;
|
||||
for (int triangle = 0; triangle < mesh.vertices.size() / 3; triangle++) {
|
||||
|
||||
int trianglesCount = mesh.vertices.size() / 3;
|
||||
for (int triangle = 0; triangle < trianglesCount; triangle++) {
|
||||
auto r = mesh.vertices[triangle * 3 + (triangle % 2) * 2].coord -
|
||||
mesh.vertices[triangle * 3 + 1].coord;
|
||||
r = r.x * X + r.y * Y + r.z * Z;
|
||||
|
|
@ -327,8 +334,7 @@ void BlocksRenderer::blockCustomModel(
|
|||
vp = vp.x * X + vp.y * Y + vp.z * Z;
|
||||
|
||||
if (!block.rt.extended
|
||||
&& !isOpen(glm::floor(coord + vp + 0.5f + n * 1e-3f), block, variant)
|
||||
&& is_aligned(n)) {
|
||||
&& !isOpen(glm::floor(coord + vp + 0.5f + n * 1e-3f), block, variant)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
|
@ -778,6 +784,10 @@ ChunkMesh BlocksRenderer::render(
|
|||
const Chunk* chunk, const VoxelsVolume& volume
|
||||
) {
|
||||
build(chunk, volume);
|
||||
|
||||
assert(vertexCount <= capacity);
|
||||
assert(indexCount <= capacity);
|
||||
assert(denseIndexCount <= capacity);
|
||||
|
||||
return ChunkMesh{std::make_unique<Mesh<ChunkVertex>>(
|
||||
vertexBuffer.get(), vertexCount,
|
||||
|
|
|
|||
|
|
@ -125,9 +125,6 @@ Block::Block(std::string name, const std::string& texture)
|
|||
|
||||
void Block::cloneTo(Block& dst) {
|
||||
dst.caption = caption;
|
||||
for (int i = 0; i < 6; i++) {
|
||||
dst.defaults = defaults;
|
||||
}
|
||||
dst.defaults = defaults;
|
||||
if (variants) {
|
||||
dst.variants = std::make_unique<Variants>(*variants);
|
||||
|
|
@ -155,6 +152,7 @@ void Block::cloneTo(Block& dst) {
|
|||
dst.tickInterval = tickInterval;
|
||||
dst.overlayTexture = overlayTexture;
|
||||
dst.translucent = translucent;
|
||||
dst.explictlySolid = explictlySolid;
|
||||
dst.tags = tags;
|
||||
if (particles) {
|
||||
dst.particles = std::make_unique<ParticlesPreset>(*particles);
|
||||
|
|
|
|||
|
|
@ -230,6 +230,9 @@ public:
|
|||
/// @brief Block has semi-transparent texture
|
||||
bool translucent = false;
|
||||
|
||||
/// @brief Explicitly overriding 'solid' property if true assigned
|
||||
bool explictlySolid = false;
|
||||
|
||||
/// @brief Set of block physical hitboxes
|
||||
std::vector<AABB> hitboxes {AABB()};
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue