Moved side, edge and corner enums to cube tables, and renamed CubeTables to Cube

This commit is contained in:
Marc Gilleron 2018-09-30 19:37:39 +01:00
parent 8ffa7110c8
commit da0a1a058c
6 changed files with 120 additions and 127 deletions

View File

@ -1,6 +1,6 @@
#include "cube_tables.h"
namespace CubeTables {
namespace Cube {
// The following tables respect the following conventions
//
@ -45,7 +45,7 @@ const Vector3 g_corner_position[CORNER_COUNT] = {
Vector3(0, 1, 1)
};
const int g_side_quad_triangles[Voxel::SIDE_COUNT][6] = {
const int g_side_quad_triangles[SIDE_COUNT][6] = {
// LEFT
{ 0, 1, 2, 0, 2, 3 },
// RIGHT
@ -60,10 +60,10 @@ const int g_side_quad_triangles[Voxel::SIDE_COUNT][6] = {
{ 0, 1, 2, 0, 2, 3 },
};
const unsigned int g_side_coord[Voxel::SIDE_COUNT] = { 0, 0, 1, 1, 2, 2 };
const unsigned int g_side_sign[Voxel::SIDE_COUNT] = { 0, 1, 0, 1, 0, 1 };
const unsigned int g_side_coord[SIDE_COUNT] = { 0, 0, 1, 1, 2, 2 };
const unsigned int g_side_sign[SIDE_COUNT] = { 0, 1, 0, 1, 0, 1 };
const Vector3i g_side_normals[Voxel::SIDE_COUNT] = {
const Vector3i g_side_normals[SIDE_COUNT] = {
Vector3i(-1, 0, 0),
Vector3i(1, 0, 0),
Vector3i(0, -1, 0),
@ -73,7 +73,7 @@ const Vector3i g_side_normals[Voxel::SIDE_COUNT] = {
};
// Corners have same winding, relative to the face's normal
const unsigned int g_side_corners[Voxel::SIDE_COUNT][4] = {
const unsigned int g_side_corners[SIDE_COUNT][4] = {
{ 3, 0, 4, 7 },
{ 1, 2, 6, 5 },
{ 1, 0, 3, 2 },
@ -82,7 +82,7 @@ const unsigned int g_side_corners[Voxel::SIDE_COUNT][4] = {
{ 2, 3, 7, 6 }
};
const unsigned int g_side_edges[Voxel::SIDE_COUNT][4] = {
const unsigned int g_side_edges[SIDE_COUNT][4] = {
{ 3, 7, 11, 4 },
{ 1, 6, 9, 5 },
{ 0, 1, 2, 3 },

View File

@ -3,26 +3,64 @@
#include <core/math/vector3.h>
#include "vector3i.h"
#include "voxel.h"
// TODO Rename Cube, as we may move enums in there because they are related
namespace CubeTables {
namespace Cube {
const unsigned int CORNER_COUNT = 8;
const unsigned int EDGE_COUNT = 12;
const unsigned int MOORE_NEIGHBORING_3D_COUNT = 26;
// Index convention used in some lookup tables
enum Side {
SIDE_LEFT = 0,
SIDE_RIGHT,
SIDE_BOTTOM,
SIDE_TOP,
SIDE_BACK,
SIDE_FRONT,
SIDE_COUNT
};
// Index convention used in some lookup tables
enum Edge {
EDGE_BOTTOM_BACK = 0,
EDGE_BOTTOM_RIGHT,
EDGE_BOTTOM_FRONT,
EDGE_BOTTOM_LEFT,
EDGE_BACK_LEFT,
EDGE_BACK_RIGHT,
EDGE_FRONT_RIGHT,
EDGE_FRONT_LEFT,
EDGE_TOP_BACK,
EDGE_TOP_RIGHT,
EDGE_TOP_FRONT,
EDGE_TOP_LEFT,
EDGE_COUNT
};
// Index convention used in some lookup tables
enum Corner {
CORNER_BOTTOM_BACK_LEFT = 0,
CORNER_BOTTOM_BACK_RIGHT,
CORNER_BOTTOM_FRONT_RIGHT,
CORNER_BOTTOM_FRONT_LEFT,
CORNER_TOP_BACK_LEFT,
CORNER_TOP_BACK_RIGHT,
CORNER_TOP_FRONT_RIGHT,
CORNER_TOP_FRONT_LEFT,
CORNER_COUNT
};
extern const Vector3 g_corner_position[CORNER_COUNT];
extern const int g_side_quad_triangles[Voxel::SIDE_COUNT][6];
extern const int g_side_quad_triangles[SIDE_COUNT][6];
extern const unsigned int g_side_coord[Voxel::SIDE_COUNT];
extern const unsigned int g_side_sign[Voxel::SIDE_COUNT];
extern const unsigned int g_side_coord[SIDE_COUNT];
extern const unsigned int g_side_sign[SIDE_COUNT];
extern const Vector3i g_side_normals[Voxel::SIDE_COUNT];
extern const Vector3i g_side_normals[SIDE_COUNT];
extern const unsigned int g_side_corners[Voxel::SIDE_COUNT][4];
extern const unsigned int g_side_edges[Voxel::SIDE_COUNT][4];
extern const unsigned int g_side_corners[SIDE_COUNT][4];
extern const unsigned int g_side_edges[SIDE_COUNT][4];
extern const Vector3i g_corner_inormals[CORNER_COUNT];
@ -30,6 +68,7 @@ extern const Vector3i g_edge_inormals[EDGE_COUNT];
extern const unsigned int g_edge_corners[EDGE_COUNT][2];
const unsigned int MOORE_NEIGHBORING_3D_COUNT = 26;
extern const Vector3i g_moore_neighboring_3d[MOORE_NEIGHBORING_3D_COUNT];
} // namespace CubeTables

View File

@ -1,7 +1,6 @@
#include "voxel.h"
#include "voxel_library.h"
#include "voxel_mesher.h"
#include "cube_tables.h"
#define STRLEN(x) (sizeof(x) / sizeof(x[0]))
@ -15,20 +14,20 @@ Voxel::Voxel():
_cube_geometry_padding_y(0)
{}
static Voxel::Side name_to_side(const String &s) {
static Cube::Side name_to_side(const String &s) {
if (s == "left")
return Voxel::SIDE_LEFT;
return Cube::SIDE_LEFT;
if (s == "right")
return Voxel::SIDE_RIGHT;
return Cube::SIDE_RIGHT;
if (s == "top")
return Voxel::SIDE_TOP;
return Cube::SIDE_TOP;
if (s == "bottom")
return Voxel::SIDE_BOTTOM;
return Cube::SIDE_BOTTOM;
if (s == "front")
return Voxel::SIDE_FRONT;
return Cube::SIDE_FRONT;
if (s == "back")
return Voxel::SIDE_BACK;
return Voxel::SIDE_COUNT; // Invalid
return Cube::SIDE_BACK;
return Cube::SIDE_COUNT; // Invalid
}
bool Voxel::_set(const StringName &p_name, const Variant &p_value) {
@ -39,8 +38,8 @@ bool Voxel::_set(const StringName &p_name, const Variant &p_value) {
if (name.begins_with("cube_tiles/")) {
String s = name.substr(STRLEN("cube_tiles/"), name.length());
Voxel::Side side = name_to_side(s);
if (side != Voxel::SIDE_COUNT) {
Cube::Side side = name_to_side(s);
if (side != Cube::SIDE_COUNT) {
Vector2 v = p_value;
set_cube_uv_side(side, v);
return true;
@ -63,8 +62,8 @@ bool Voxel::_get(const StringName &p_name, Variant &r_ret) const {
if (name.begins_with("cube_tiles/")) {
String s = name.substr(STRLEN("cube_tiles/"), name.length());
Voxel::Side side = name_to_side(s);
if (side != Voxel::SIDE_COUNT) {
Cube::Side side = name_to_side(s);
if (side != Cube::SIDE_COUNT) {
r_ret = _cube_tiles[side];
return true;
}
@ -135,7 +134,7 @@ void Voxel::set_geometry_type(GeometryType type) {
_model_uvs.resize(0);
_model_indices.resize(0);
for (int side = 0; side < SIDE_COUNT; ++side) {
for (int side = 0; side < Cube::SIDE_COUNT; ++side) {
_model_side_positions[side].resize(0);
_model_side_uvs[side].resize(0);
_model_side_indices[side].resize(0);
@ -179,14 +178,14 @@ VoxelLibrary *Voxel::get_library() const {
Ref<Voxel> Voxel::set_cube_geometry(float sy) {
sy = 1.0 + sy;
for (unsigned int side = 0; side < SIDE_COUNT; ++side) {
for (unsigned int side = 0; side < Cube::SIDE_COUNT; ++side) {
{
_model_side_positions[side].resize(4);
PoolVector<Vector3>::Write w = _model_side_positions[side].write();
for (unsigned int i = 0; i < 4; ++i) {
int corner = CubeTables::g_side_corners[side][i];
Vector3 p = CubeTables::g_corner_position[corner];
int corner = Cube::g_side_corners[side][i];
Vector3 p = Cube::g_corner_position[corner];
if(p.y > 0.9)
p.y = sy;
w[i] = p;
@ -197,7 +196,7 @@ Ref<Voxel> Voxel::set_cube_geometry(float sy) {
_model_side_indices[side].resize(6);
PoolVector<int>::Write w = _model_side_indices[side].write();
for (unsigned int i = 0; i < 6; ++i) {
w[i] = CubeTables::g_side_quad_triangles[side][i];
w[i] = Cube::g_side_quad_triangles[side][i];
}
}
}
@ -230,7 +229,7 @@ void Voxel::update_cube_uv_sides() {
float s = 1.0 / (float)library->get_atlas_size();
for (unsigned int side = 0; side < SIDE_COUNT; ++side) {
for (unsigned int side = 0; side < Cube::SIDE_COUNT; ++side) {
_model_side_uvs[side].resize(4);
PoolVector<Vector2>::Write w = _model_side_uvs[side].write();
for (unsigned int i = 0; i < 4; ++i) {

55
voxel.h
View File

@ -2,6 +2,7 @@
#define VOXEL_TYPE_H
#include <core/resource.h>
#include "cube_tables.h"
class VoxelLibrary;
@ -12,52 +13,6 @@ class Voxel : public Resource {
GDCLASS(Voxel, Resource)
public:
// TODO Move enums to CubeTables
// Index convention used in some lookup tables
enum Side {
SIDE_LEFT = 0,
SIDE_RIGHT,
SIDE_BOTTOM,
SIDE_TOP,
SIDE_BACK,
SIDE_FRONT,
SIDE_COUNT
};
// Index convention used in some lookup tables
enum Edge {
EDGE_BOTTOM_BACK,
EDGE_BOTTOM_RIGHT,
EDGE_BOTTOM_FRONT,
EDGE_BOTTOM_LEFT,
EDGE_BACK_LEFT,
EDGE_BACK_RIGHT,
EDGE_FRONT_RIGHT,
EDGE_FRONT_LEFT,
EDGE_TOP_BACK,
EDGE_TOP_RIGHT,
EDGE_TOP_FRONT,
EDGE_TOP_LEFT,
EDGE_COUNT
};
// Index convention used in some lookup tables
enum Corner {
CORNER_BOTTOM_BACK_LEFT,
CORNER_BOTTOM_BACK_RIGHT,
CORNER_BOTTOM_FRONT_RIGHT,
CORNER_BOTTOM_FRONT_LEFT,
CORNER_TOP_BACK_LEFT,
CORNER_TOP_BACK_RIGHT,
CORNER_TOP_FRONT_RIGHT,
CORNER_TOP_FRONT_LEFT,
CORNER_COUNT
};
enum ChannelMode {
// For mapping to a Voxel type
CHANNEL_TYPE = 0,
@ -139,7 +94,7 @@ private:
Color _color;
GeometryType _geometry_type;
float _cube_geometry_padding_y;
Vector2 _cube_tiles[SIDE_COUNT];
Vector2 _cube_tiles[Cube::SIDE_COUNT];
// Model
PoolVector<Vector3> _model_positions;
@ -149,9 +104,9 @@ private:
// Model sides:
// They are separated because this way we can occlude them easily.
// Due to these defining cube side triangles, normals are known already.
PoolVector<Vector3> _model_side_positions[SIDE_COUNT];
PoolVector<Vector2> _model_side_uvs[SIDE_COUNT];
PoolVector<int> _model_side_indices[SIDE_COUNT];
PoolVector<Vector3> _model_side_positions[Cube::SIDE_COUNT];
PoolVector<Vector2> _model_side_uvs[Cube::SIDE_COUNT];
PoolVector<int> _model_side_indices[Cube::SIDE_COUNT];
// TODO Child voxel types?
};

View File

@ -105,8 +105,8 @@ bool VoxelMap::has_block(Vector3i pos) const {
}
bool VoxelMap::is_block_surrounded(Vector3i pos) const {
for (unsigned int i = 0; i < CubeTables::MOORE_NEIGHBORING_3D_COUNT; ++i) {
Vector3i bpos = pos + CubeTables::g_moore_neighboring_3d[i];
for (unsigned int i = 0; i < Cube::MOORE_NEIGHBORING_3D_COUNT; ++i) {
Vector3i bpos = pos + Cube::g_moore_neighboring_3d[i];
if (!has_block(bpos)) {
return false;
}

View File

@ -130,37 +130,37 @@ Array VoxelMesher::build(const VoxelBuffer &buffer, unsigned int channel, Vector
int row_size = buffer.get_size().y;
int deck_size = buffer.get_size().x * row_size;
int side_neighbor_lut[Voxel::SIDE_COUNT];
side_neighbor_lut[Voxel::SIDE_LEFT] = -row_size;
side_neighbor_lut[Voxel::SIDE_RIGHT] = row_size;
side_neighbor_lut[Voxel::SIDE_BACK] = -deck_size;
side_neighbor_lut[Voxel::SIDE_FRONT] = deck_size;
side_neighbor_lut[Voxel::SIDE_BOTTOM] = -1;
side_neighbor_lut[Voxel::SIDE_TOP] = 1;
int side_neighbor_lut[Cube::SIDE_COUNT];
side_neighbor_lut[Cube::SIDE_LEFT] = -row_size;
side_neighbor_lut[Cube::SIDE_RIGHT] = row_size;
side_neighbor_lut[Cube::SIDE_BACK] = -deck_size;
side_neighbor_lut[Cube::SIDE_FRONT] = deck_size;
side_neighbor_lut[Cube::SIDE_BOTTOM] = -1;
side_neighbor_lut[Cube::SIDE_TOP] = 1;
int edge_neighbor_lut[Voxel::EDGE_COUNT];
edge_neighbor_lut[Voxel::EDGE_BOTTOM_BACK] = side_neighbor_lut[Voxel::SIDE_BOTTOM] + side_neighbor_lut[Voxel::SIDE_BACK];
edge_neighbor_lut[Voxel::EDGE_BOTTOM_FRONT] = side_neighbor_lut[Voxel::SIDE_BOTTOM] + side_neighbor_lut[Voxel::SIDE_FRONT];
edge_neighbor_lut[Voxel::EDGE_BOTTOM_LEFT] = side_neighbor_lut[Voxel::SIDE_BOTTOM] + side_neighbor_lut[Voxel::SIDE_LEFT];
edge_neighbor_lut[Voxel::EDGE_BOTTOM_RIGHT] = side_neighbor_lut[Voxel::SIDE_BOTTOM] + side_neighbor_lut[Voxel::SIDE_RIGHT];
edge_neighbor_lut[Voxel::EDGE_BACK_LEFT] = side_neighbor_lut[Voxel::SIDE_BACK] + side_neighbor_lut[Voxel::SIDE_LEFT];
edge_neighbor_lut[Voxel::EDGE_BACK_RIGHT] = side_neighbor_lut[Voxel::SIDE_BACK] + side_neighbor_lut[Voxel::SIDE_RIGHT];
edge_neighbor_lut[Voxel::EDGE_FRONT_LEFT] = side_neighbor_lut[Voxel::SIDE_FRONT] + side_neighbor_lut[Voxel::SIDE_LEFT];
edge_neighbor_lut[Voxel::EDGE_FRONT_RIGHT] = side_neighbor_lut[Voxel::SIDE_FRONT] + side_neighbor_lut[Voxel::SIDE_RIGHT];
edge_neighbor_lut[Voxel::EDGE_TOP_BACK] = side_neighbor_lut[Voxel::SIDE_TOP] + side_neighbor_lut[Voxel::SIDE_BACK];
edge_neighbor_lut[Voxel::EDGE_TOP_FRONT] = side_neighbor_lut[Voxel::SIDE_TOP] + side_neighbor_lut[Voxel::SIDE_FRONT];
edge_neighbor_lut[Voxel::EDGE_TOP_LEFT] = side_neighbor_lut[Voxel::SIDE_TOP] + side_neighbor_lut[Voxel::SIDE_LEFT];
edge_neighbor_lut[Voxel::EDGE_TOP_RIGHT] = side_neighbor_lut[Voxel::SIDE_TOP] + side_neighbor_lut[Voxel::SIDE_RIGHT];
int edge_neighbor_lut[Cube::EDGE_COUNT];
edge_neighbor_lut[Cube::EDGE_BOTTOM_BACK] = side_neighbor_lut[Cube::SIDE_BOTTOM] + side_neighbor_lut[Cube::SIDE_BACK];
edge_neighbor_lut[Cube::EDGE_BOTTOM_FRONT] = side_neighbor_lut[Cube::SIDE_BOTTOM] + side_neighbor_lut[Cube::SIDE_FRONT];
edge_neighbor_lut[Cube::EDGE_BOTTOM_LEFT] = side_neighbor_lut[Cube::SIDE_BOTTOM] + side_neighbor_lut[Cube::SIDE_LEFT];
edge_neighbor_lut[Cube::EDGE_BOTTOM_RIGHT] = side_neighbor_lut[Cube::SIDE_BOTTOM] + side_neighbor_lut[Cube::SIDE_RIGHT];
edge_neighbor_lut[Cube::EDGE_BACK_LEFT] = side_neighbor_lut[Cube::SIDE_BACK] + side_neighbor_lut[Cube::SIDE_LEFT];
edge_neighbor_lut[Cube::EDGE_BACK_RIGHT] = side_neighbor_lut[Cube::SIDE_BACK] + side_neighbor_lut[Cube::SIDE_RIGHT];
edge_neighbor_lut[Cube::EDGE_FRONT_LEFT] = side_neighbor_lut[Cube::SIDE_FRONT] + side_neighbor_lut[Cube::SIDE_LEFT];
edge_neighbor_lut[Cube::EDGE_FRONT_RIGHT] = side_neighbor_lut[Cube::SIDE_FRONT] + side_neighbor_lut[Cube::SIDE_RIGHT];
edge_neighbor_lut[Cube::EDGE_TOP_BACK] = side_neighbor_lut[Cube::SIDE_TOP] + side_neighbor_lut[Cube::SIDE_BACK];
edge_neighbor_lut[Cube::EDGE_TOP_FRONT] = side_neighbor_lut[Cube::SIDE_TOP] + side_neighbor_lut[Cube::SIDE_FRONT];
edge_neighbor_lut[Cube::EDGE_TOP_LEFT] = side_neighbor_lut[Cube::SIDE_TOP] + side_neighbor_lut[Cube::SIDE_LEFT];
edge_neighbor_lut[Cube::EDGE_TOP_RIGHT] = side_neighbor_lut[Cube::SIDE_TOP] + side_neighbor_lut[Cube::SIDE_RIGHT];
int corner_neighbor_lut[Voxel::CORNER_COUNT];
corner_neighbor_lut[Voxel::CORNER_BOTTOM_BACK_LEFT] = side_neighbor_lut[Voxel::SIDE_BOTTOM] + side_neighbor_lut[Voxel::SIDE_BACK] + side_neighbor_lut[Voxel::SIDE_LEFT];
corner_neighbor_lut[Voxel::CORNER_BOTTOM_BACK_RIGHT] = side_neighbor_lut[Voxel::SIDE_BOTTOM] + side_neighbor_lut[Voxel::SIDE_BACK] + side_neighbor_lut[Voxel::SIDE_RIGHT];
corner_neighbor_lut[Voxel::CORNER_BOTTOM_FRONT_RIGHT] = side_neighbor_lut[Voxel::SIDE_BOTTOM] + side_neighbor_lut[Voxel::SIDE_FRONT] + side_neighbor_lut[Voxel::SIDE_RIGHT];
corner_neighbor_lut[Voxel::CORNER_BOTTOM_FRONT_LEFT] = side_neighbor_lut[Voxel::SIDE_BOTTOM] + side_neighbor_lut[Voxel::SIDE_FRONT] + side_neighbor_lut[Voxel::SIDE_LEFT];
corner_neighbor_lut[Voxel::CORNER_TOP_BACK_LEFT] = side_neighbor_lut[Voxel::SIDE_TOP] + side_neighbor_lut[Voxel::SIDE_BACK] + side_neighbor_lut[Voxel::SIDE_LEFT];
corner_neighbor_lut[Voxel::CORNER_TOP_BACK_RIGHT] = side_neighbor_lut[Voxel::SIDE_TOP] + side_neighbor_lut[Voxel::SIDE_BACK] + side_neighbor_lut[Voxel::SIDE_RIGHT];
corner_neighbor_lut[Voxel::CORNER_TOP_FRONT_RIGHT] = side_neighbor_lut[Voxel::SIDE_TOP] + side_neighbor_lut[Voxel::SIDE_FRONT] + side_neighbor_lut[Voxel::SIDE_RIGHT];
corner_neighbor_lut[Voxel::CORNER_TOP_FRONT_LEFT] = side_neighbor_lut[Voxel::SIDE_TOP] + side_neighbor_lut[Voxel::SIDE_FRONT] + side_neighbor_lut[Voxel::SIDE_LEFT];
int corner_neighbor_lut[Cube::CORNER_COUNT];
corner_neighbor_lut[Cube::CORNER_BOTTOM_BACK_LEFT] = side_neighbor_lut[Cube::SIDE_BOTTOM] + side_neighbor_lut[Cube::SIDE_BACK] + side_neighbor_lut[Cube::SIDE_LEFT];
corner_neighbor_lut[Cube::CORNER_BOTTOM_BACK_RIGHT] = side_neighbor_lut[Cube::SIDE_BOTTOM] + side_neighbor_lut[Cube::SIDE_BACK] + side_neighbor_lut[Cube::SIDE_RIGHT];
corner_neighbor_lut[Cube::CORNER_BOTTOM_FRONT_RIGHT] = side_neighbor_lut[Cube::SIDE_BOTTOM] + side_neighbor_lut[Cube::SIDE_FRONT] + side_neighbor_lut[Cube::SIDE_RIGHT];
corner_neighbor_lut[Cube::CORNER_BOTTOM_FRONT_LEFT] = side_neighbor_lut[Cube::SIDE_BOTTOM] + side_neighbor_lut[Cube::SIDE_FRONT] + side_neighbor_lut[Cube::SIDE_LEFT];
corner_neighbor_lut[Cube::CORNER_TOP_BACK_LEFT] = side_neighbor_lut[Cube::SIDE_TOP] + side_neighbor_lut[Cube::SIDE_BACK] + side_neighbor_lut[Cube::SIDE_LEFT];
corner_neighbor_lut[Cube::CORNER_TOP_BACK_RIGHT] = side_neighbor_lut[Cube::SIDE_TOP] + side_neighbor_lut[Cube::SIDE_BACK] + side_neighbor_lut[Cube::SIDE_RIGHT];
corner_neighbor_lut[Cube::CORNER_TOP_FRONT_RIGHT] = side_neighbor_lut[Cube::SIDE_TOP] + side_neighbor_lut[Cube::SIDE_FRONT] + side_neighbor_lut[Cube::SIDE_RIGHT];
corner_neighbor_lut[Cube::CORNER_TOP_FRONT_LEFT] = side_neighbor_lut[Cube::SIDE_TOP] + side_neighbor_lut[Cube::SIDE_FRONT] + side_neighbor_lut[Cube::SIDE_LEFT];
uint64_t time_prep = OS::get_singleton()->get_ticks_usec() - time_before;
time_before = OS::get_singleton()->get_ticks_usec();
@ -185,7 +185,7 @@ Array VoxelMesher::build(const VoxelBuffer &buffer, unsigned int channel, Vector
// and still allow voxels to have geometry that is not a cube
// Sides
for (unsigned int side = 0; side < Voxel::SIDE_COUNT; ++side) {
for (unsigned int side = 0; side < Cube::SIDE_COUNT; ++side) {
const PoolVector<Vector3> &positions = voxel.get_model_side_positions(side);
int vertex_count = positions.size();
@ -206,15 +206,15 @@ Array VoxelMesher::build(const VoxelBuffer &buffer, unsigned int channel, Vector
// Combinatory solution for https://0fps.net/2013/07/03/ambient-occlusion-for-minecraft-like-worlds/
for (unsigned int j = 0; j < 4; ++j) {
unsigned int edge = CubeTables::g_side_edges[side][j];
unsigned int edge = Cube::g_side_edges[side][j];
int edge_neighbor_id = type_buffer[voxel_index + edge_neighbor_lut[edge]];
if (!is_transparent(library, edge_neighbor_id)) {
shaded_corner[CubeTables::g_edge_corners[edge][0]] += 1;
shaded_corner[CubeTables::g_edge_corners[edge][1]] += 1;
shaded_corner[Cube::g_edge_corners[edge][0]] += 1;
shaded_corner[Cube::g_edge_corners[edge][1]] += 1;
}
}
for (unsigned int j = 0; j < 4; ++j) {
unsigned int corner = CubeTables::g_side_corners[side][j];
unsigned int corner = Cube::g_side_corners[side][j];
if (shaded_corner[corner] == 2) {
shaded_corner[corner] = 3;
} else {
@ -254,7 +254,7 @@ Array VoxelMesher::build(const VoxelBuffer &buffer, unsigned int channel, Vector
arrays.normals.resize(arrays.normals.size() + vertex_count);
Vector3 *w = arrays.normals.ptrw() + append_index;
for (unsigned int i = 0; i < vertex_count; ++i) {
w[i] = CubeTables::g_side_normals[side].to_vec3();
w[i] = Cube::g_side_normals[side].to_vec3();
}
}
@ -273,10 +273,10 @@ Array VoxelMesher::build(const VoxelBuffer &buffer, unsigned int channel, Vector
// TODO Fix occlusion inconsistency caused by triangles orientation? Not sure if worth it
float shade = 0;
for (unsigned int j = 0; j < 4; ++j) {
unsigned int corner = CubeTables::g_side_corners[side][j];
unsigned int corner = Cube::g_side_corners[side][j];
if (shaded_corner[corner]) {
float s = baked_occlusion_darkness * static_cast<float>(shaded_corner[corner]);
float k = 1.0 - CubeTables::g_corner_position[corner].distance_to(v);
float k = 1.0 - Cube::g_corner_position[corner].distance_to(v);
if (k < 0.0)
k = 0.0;
s *= k;