Work on cleaning up up VoxelCubePoints, and Voxel Side Points, and started work on the sub voxel point helper.

This commit is contained in:
Relintai 2019-07-14 17:33:46 +02:00
parent 3d550a0772
commit 9a84ab8500
10 changed files with 355 additions and 462 deletions

2
SCsub
View File

@ -20,3 +20,5 @@ env.add_source_files(env.modules_sources,"world/voxel_chunk.cpp")
env.add_source_files(env.modules_sources,"meshers/cubic_mesher/voxel_mesher_cubic.cpp")
env.add_source_files(env.modules_sources,"meshers/cubic_mesher/voxel_cube_points.cpp")
env.add_source_files(env.modules_sources,"meshers/cubic_mesher/sub_voxel_side_points.cpp")

View File

@ -1,8 +1,4 @@
#include "sub_voxel_points_helper.h"
#if MEM_TOOLS
int SubVoxelFacePointsHelper::allocs = 0;
#endif
#include "sub_voxel_face_points_helper.h"
Vector2i SubVoxelFacePointsHelper::gettlv2() {
return SubVoxelFacePointsHelper::transform_to_vector2i(_face, _tl);
@ -36,29 +32,20 @@ int SubVoxelFacePointsHelper::getbr_depth() {
return SubVoxelFacePointsHelper::get_depth(_face, _br);
}
SubVoxelFacePointsHelper::SubVoxelFacePointsHelper(int face, SubVoxelPoints *points) {
SubVoxelFacePointsHelper::SubVoxelFacePointsHelper(int face, VoxelCubePoints *points) {
_size = 255;
set_sub_voxel_points(face, points);
#if MEM_TOOLS
SubVoxelFacePointsHelper::allocs++;
print_error("SubVoxelFacePointsHelper alloc " + String::num(SubVoxelFacePointsHelper::allocs));
#endif
}
SubVoxelFacePointsHelper::~SubVoxelFacePointsHelper() {
#if MEM_TOOLS
SubVoxelFacePointsHelper::allocs--;
print_error("SubVoxelFacePointsHelper dealloc " + String::num(SubVoxelFacePointsHelper::allocs));
#endif
}
void SubVoxelFacePointsHelper::set_sub_voxel_points(int face, SubVoxelPoints *points) {
void SubVoxelFacePointsHelper::set_sub_voxel_points(int face, VoxelCubePoints *points) {
_face = face;
_tl = Vector3i(SubVoxelPoints::get_top_left_point(face, points));
_tr = Vector3i(SubVoxelPoints::get_top_right_point(face, points));
_bl = Vector3i(SubVoxelPoints::get_bottom_left_point(face, points));
_br = Vector3i(SubVoxelPoints::get_bottom_right_point(face, points));
_tl = Vector3i(VoxelCubePoints::get_top_left_point(face, points));
_tr = Vector3i(VoxelCubePoints::get_top_right_point(face, points));
_bl = Vector3i(VoxelCubePoints::get_bottom_left_point(face, points));
_br = Vector3i(VoxelCubePoints::get_bottom_right_point(face, points));
}
bool SubVoxelFacePointsHelper::is_face_fully_covered() {

View File

@ -1,17 +1,13 @@
#ifndef SUB_VOXEL_FACE_POINTS_HELPER_H
#define SUB_VOXEL_FACE_POINTS_HELPER_H
#include "../collections/vector3i.h"
#include "../../math/vector3i.h"
#include "core/math/vector2.h"
#include "core/vector.h"
#include "sub_voxel_points.h"
#include "voxel_face.h"
#include "voxel_cube_points.h"
using namespace voxelman;
namespace voxelman {
class SubVoxelPoints;
class VoxelCubePoints;
class SubVoxelFacePointsHelper {
@ -26,10 +22,10 @@ public:
int getbl_depth();
int getbr_depth();
SubVoxelFacePointsHelper(int face, SubVoxelPoints *points);
SubVoxelFacePointsHelper(int face, VoxelCubePoints *points);
~SubVoxelFacePointsHelper();
void set_sub_voxel_points(int face, SubVoxelPoints *points);
void set_sub_voxel_points(int face, VoxelCubePoints *points);
bool is_face_fully_covered();
bool is_face_near_the_edges();
bool is_face_visible_against(SubVoxelFacePointsHelper *other);
@ -49,12 +45,6 @@ private:
Vector3i _tr;
Vector3i _bl;
Vector3i _br;
#if MEM_TOOLS
static int allocs;
#endif
};
} // namespace voxelman
#endif

View File

@ -1,30 +1,10 @@
#include "sub_voxel_side_points.h"
using namespace voxelman;
#if MEM_TOOLS
int SubVoxelSidePoints::allocs = 0;
#endif
SubVoxelSidePoints::SubVoxelSidePoints() {
//_points = new Vector<Vector3i>(4);
for (int i = 0; i < 4; ++i) {
Vector3i a;
_points.push_back(a);
}
#if MEM_TOOLS
SubVoxelSidePoints::allocs++;
print_error("SubVoxelSidePoints alloc " + String::num(SubVoxelSidePoints::allocs));
#endif
}
SubVoxelSidePoints::~SubVoxelSidePoints() {
#if MEM_TOOLS
SubVoxelSidePoints::allocs--;
print_error("SubVoxelSidePoints dealloc " + String::num(SubVoxelSidePoints::allocs));
#endif
}
bool SubVoxelSidePoints::is_sub_voxel_point(Vector3i point) {
@ -49,7 +29,6 @@ bool SubVoxelSidePoints::is_sub_voxel_point(int x, int y, int z) {
}
Vector3 SubVoxelSidePoints::get_vector3_for_point(int index) {
//return Vector3((float)(getPoints()->GetData(pointIndex)->x), (float)(getPoints()->GetData(pointIndex)->y), (float)(getPoints()->GetData(pointIndex)->z));
Vector3i a = _points[index];
Vector3 b(a.x, a.y, a.z);
@ -58,7 +37,6 @@ Vector3 SubVoxelSidePoints::get_vector3_for_point(int index) {
}
Vector3 SubVoxelSidePoints::get_vertex_vector3_for_point(int index) {
//Vector3 vector3((float)(getPoints()->GetData(index)->x), (float)(getPoints()->GetData(index)->y), (float)(getPoints()->GetData(index)->z));
Vector3i a = _points[index];
Vector3 vector(a.x, a.y, a.z);

View File

@ -1,13 +1,12 @@
#ifndef SUB_VOXEL_SIDE_POINTS_H
#define SUB_VOXEL_SIDE_POINTS_H
#include "core/object.h"
#include "../collections/vector3i.h"
#include "core/reference.h"
#include "../../math/vector3i.h"
#include "core/vector.h"
namespace voxelman {
class SubVoxelSidePoints {
class SubVoxelSidePoints : public Reference {
GDCLASS(SubVoxelSidePoints, Reference);
public:
Vector3i get_point(int index) { return _points[index]; }
@ -22,13 +21,7 @@ public:
~SubVoxelSidePoints();
private:
Vector<Vector3i> _points;
#if MEM_TOOLS
static int allocs;
#endif
Vector3i _points[4];
};
} // namespace voxelman
#endif

View File

@ -1,114 +1,76 @@
#include "sub_voxel_points.h"
#include "voxel_cube_points.h"
namespace voxelman {
#if MEM_TOOLS
int SubVoxelPoints::allocs = 0;
#endif
Vector3i SubVoxelPoints::get_point(int index) {
Vector3i VoxelCubePoints::get_point(int index) {
return _points[index];
}
SubVoxelPoints::SubVoxelPoints(Voxel *voxel) {
_voxel = voxel;
_voxel_datas = memnew_arr(Ref<VoxelData>, POINT_COUNT);
//for (int i = 0; i < POINT_COUNT; i++) {
// _voxel_datas[i] = Ref<VoxelData>(NULL);
//}
//_voxel_datas = new Vector<VoxelData>(8);
//points = new Vector<Vector3i>(8);
//for (int i = 0; i < POINT_COUNT; ++i) {
// points.SetData(i, );
//}
//faceHelper = new SubVoxelSidePoints();
#if MEM_TOOLS
SubVoxelPoints::allocs++;
print_error("SubVoxelPoints alloc " + String::num(SubVoxelPoints::allocs));
#endif
VoxelCubePoints::VoxelCubePoints() {
_face_helper.instance();
}
SubVoxelPoints::~SubVoxelPoints() {
for (int i = 0; i < POINT_COUNT; i++) {
_voxel_datas[i] = Ref<VoxelData>(NULL);
}
memdelete_arr(_voxel_datas);
#if MEM_TOOLS
SubVoxelPoints::allocs--;
print_error("SubVoxelPoints dealloc " + String::num(SubVoxelPoints::allocs));
#endif
VoxelCubePoints::~VoxelCubePoints() {
_face_helper.unref();
}
void SubVoxelPoints::refresh_points() {
void VoxelCubePoints::refresh_points() {
//Front
//Bottom Left
refresh_point(P000, 0, 0, 0,
Voxel::NEIGHBOUR_LEFT, Voxel::NEIGHBOUR_BOTTOM_LEFT, Voxel::NEIGHBOUR_LEFT, Voxel::NEIGHBOUR_FRONT,
Voxel::NEIGHBOUR_DOWN, Voxel::NEIGHBOUR_BOTTOM_LEFT, Voxel::NEIGHBOUR_BOTTOM_FRONT, Voxel::NEIGHBOUR_BOTTOM_LEFT_FRONT,
Voxel::NEIGHBOUR_FRONT, Voxel::NEIGHBOUR_BOTTOM_FRONT, Voxel::NEIGHBOUR_LEFT, Voxel::NEIGHBOUR_FRONT);
VOXEL_NEIGHBOUR_LEFT, VOXEL_NEIGHBOUR_BOTTOM_LEFT, VOXEL_NEIGHBOUR_LEFT, VOXEL_NEIGHBOUR_FRONT,
VOXEL_NEIGHBOUR_BOTTOM, VOXEL_NEIGHBOUR_BOTTOM_LEFT, VOXEL_NEIGHBOUR_BOTTOM_FRONT, VOXEL_NEIGHBOUR_BOTTOM_LEFT_FRONT,
VOXEL_NEIGHBOUR_FRONT, VOXEL_NEIGHBOUR_BOTTOM_FRONT, VOXEL_NEIGHBOUR_LEFT, VOXEL_NEIGHBOUR_FRONT);
//Bottom Right
refresh_point(P100, 255, 0, 0,
Voxel::NEIGHBOUR_RIGHT, Voxel::NEIGHBOUR_BOTTOM_RIGHT, Voxel::NEIGHBOUR_RIGHT, Voxel::NEIGHBOUR_FRONT,
Voxel::NEIGHBOUR_DOWN, Voxel::NEIGHBOUR_BOTTOM_RIGHT, Voxel::NEIGHBOUR_BOTTOM_FRONT, Voxel::NEIGHBOUR_BOTTOM_RIGHT_FRONT,
Voxel::NEIGHBOUR_FRONT, Voxel::NEIGHBOUR_BOTTOM_FRONT, Voxel::NEIGHBOUR_RIGHT, Voxel::NEIGHBOUR_FRONT);
VOXEL_NEIGHBOUR_RIGHT, VOXEL_NEIGHBOUR_BOTTOM_RIGHT, VOXEL_NEIGHBOUR_RIGHT, VOXEL_NEIGHBOUR_FRONT,
VOXEL_NEIGHBOUR_BOTTOM, VOXEL_NEIGHBOUR_BOTTOM_RIGHT, VOXEL_NEIGHBOUR_BOTTOM_FRONT, VOXEL_NEIGHBOUR_BOTTOM_RIGHT_FRONT,
VOXEL_NEIGHBOUR_FRONT, VOXEL_NEIGHBOUR_BOTTOM_FRONT, VOXEL_NEIGHBOUR_RIGHT, VOXEL_NEIGHBOUR_FRONT);
//Top Left
refresh_point(P010, 0, 255, 0,
Voxel::NEIGHBOUR_LEFT, Voxel::NEIGHBOUR_TOP_LEFT, Voxel::NEIGHBOUR_LEFT, Voxel::NEIGHBOUR_FRONT,
Voxel::NEIGHBOUR_TOP, Voxel::NEIGHBOUR_TOP_LEFT, Voxel::NEIGHBOUR_TOP_FRONT, Voxel::NEIGHBOUR_TOP_LEFT_FRONT,
Voxel::NEIGHBOUR_FRONT, Voxel::NEIGHBOUR_TOP_FRONT, Voxel::NEIGHBOUR_LEFT, Voxel::NEIGHBOUR_FRONT);
VOXEL_NEIGHBOUR_LEFT, VOXEL_NEIGHBOUR_TOP_LEFT, VOXEL_NEIGHBOUR_LEFT, VOXEL_NEIGHBOUR_FRONT,
VOXEL_NEIGHBOUR_TOP, VOXEL_NEIGHBOUR_TOP_LEFT, VOXEL_NEIGHBOUR_TOP_FRONT, VOXEL_NEIGHBOUR_TOP_LEFT_FRONT,
VOXEL_NEIGHBOUR_FRONT, VOXEL_NEIGHBOUR_TOP_FRONT, VOXEL_NEIGHBOUR_LEFT, VOXEL_NEIGHBOUR_FRONT);
//Top Right
refresh_point(P110, 255, 255, 0,
Voxel::NEIGHBOUR_RIGHT, Voxel::NEIGHBOUR_TOP_RIGHT, Voxel::NEIGHBOUR_RIGHT, Voxel::NEIGHBOUR_FRONT,
Voxel::NEIGHBOUR_TOP, Voxel::NEIGHBOUR_TOP_RIGHT, Voxel::NEIGHBOUR_TOP_FRONT, Voxel::NEIGHBOUR_TOP_RIGHT_FRONT,
Voxel::NEIGHBOUR_FRONT, Voxel::NEIGHBOUR_TOP_FRONT, Voxel::NEIGHBOUR_RIGHT, Voxel::NEIGHBOUR_FRONT);
VOXEL_NEIGHBOUR_RIGHT, VOXEL_NEIGHBOUR_TOP_RIGHT, VOXEL_NEIGHBOUR_RIGHT, VOXEL_NEIGHBOUR_FRONT,
VOXEL_NEIGHBOUR_TOP, VOXEL_NEIGHBOUR_TOP_RIGHT, VOXEL_NEIGHBOUR_TOP_FRONT, VOXEL_NEIGHBOUR_TOP_RIGHT_FRONT,
VOXEL_NEIGHBOUR_FRONT, VOXEL_NEIGHBOUR_TOP_FRONT, VOXEL_NEIGHBOUR_RIGHT, VOXEL_NEIGHBOUR_FRONT);
//Back
//Bottom Left
refresh_point(P001, 0, 0, 255,
Voxel::NEIGHBOUR_LEFT, Voxel::NEIGHBOUR_BOTTOM_LEFT, Voxel::NEIGHBOUR_LEFT, Voxel::NEIGHBOUR_BACK,
Voxel::NEIGHBOUR_DOWN, Voxel::NEIGHBOUR_BOTTOM_LEFT, Voxel::NEIGHBOUR_BOTTOM_BACK, Voxel::NEIGHBOUR_BOTTOM_LEFT_BACK,
Voxel::NEIGHBOUR_BACK, Voxel::NEIGHBOUR_BOTTOM_BACK, Voxel::NEIGHBOUR_LEFT, Voxel::NEIGHBOUR_BACK);
VOXEL_NEIGHBOUR_LEFT, VOXEL_NEIGHBOUR_BOTTOM_LEFT, VOXEL_NEIGHBOUR_LEFT, VOXEL_NEIGHBOUR_BACK,
VOXEL_NEIGHBOUR_BOTTOM, VOXEL_NEIGHBOUR_BOTTOM_LEFT, VOXEL_NEIGHBOUR_BOTTOM_BACK, VOXEL_NEIGHBOUR_BOTTOM_LEFT_BACK,
VOXEL_NEIGHBOUR_BACK, VOXEL_NEIGHBOUR_BOTTOM_BACK, VOXEL_NEIGHBOUR_LEFT, VOXEL_NEIGHBOUR_BACK);
//Bottom Right
refresh_point(P101, 255, 0, 255,
Voxel::NEIGHBOUR_RIGHT, Voxel::NEIGHBOUR_BOTTOM_RIGHT, Voxel::NEIGHBOUR_RIGHT, Voxel::NEIGHBOUR_BACK,
Voxel::NEIGHBOUR_DOWN, Voxel::NEIGHBOUR_BOTTOM_RIGHT, Voxel::NEIGHBOUR_BOTTOM_BACK, Voxel::NEIGHBOUR_BOTTOM_RIGHT_BACK,
Voxel::NEIGHBOUR_BACK, Voxel::NEIGHBOUR_BOTTOM_BACK, Voxel::NEIGHBOUR_RIGHT, Voxel::NEIGHBOUR_BACK);
VOXEL_NEIGHBOUR_RIGHT, VOXEL_NEIGHBOUR_BOTTOM_RIGHT, VOXEL_NEIGHBOUR_RIGHT, VOXEL_NEIGHBOUR_BACK,
VOXEL_NEIGHBOUR_BOTTOM, VOXEL_NEIGHBOUR_BOTTOM_RIGHT, VOXEL_NEIGHBOUR_BOTTOM_BACK, VOXEL_NEIGHBOUR_BOTTOM_RIGHT_BACK,
VOXEL_NEIGHBOUR_BACK, VOXEL_NEIGHBOUR_BOTTOM_BACK, VOXEL_NEIGHBOUR_RIGHT, VOXEL_NEIGHBOUR_BACK);
//Top Left
refresh_point(P011, 0, 255, 255,
Voxel::NEIGHBOUR_LEFT, Voxel::NEIGHBOUR_TOP_LEFT, Voxel::NEIGHBOUR_LEFT, Voxel::NEIGHBOUR_BACK,
Voxel::NEIGHBOUR_TOP, Voxel::NEIGHBOUR_TOP_LEFT, Voxel::NEIGHBOUR_TOP_BACK, Voxel::NEIGHBOUR_TOP_LEFT_BACK,
Voxel::NEIGHBOUR_BACK, Voxel::NEIGHBOUR_TOP_BACK, Voxel::NEIGHBOUR_LEFT, Voxel::NEIGHBOUR_BACK);
VOXEL_NEIGHBOUR_LEFT, VOXEL_NEIGHBOUR_TOP_LEFT, VOXEL_NEIGHBOUR_LEFT, VOXEL_NEIGHBOUR_BACK,
VOXEL_NEIGHBOUR_TOP, VOXEL_NEIGHBOUR_TOP_LEFT, VOXEL_NEIGHBOUR_TOP_BACK, VOXEL_NEIGHBOUR_TOP_LEFT_BACK,
VOXEL_NEIGHBOUR_BACK, VOXEL_NEIGHBOUR_TOP_BACK, VOXEL_NEIGHBOUR_LEFT, VOXEL_NEIGHBOUR_BACK);
//Top Right
refresh_point(P111, 255, 255, 255,
Voxel::NEIGHBOUR_RIGHT, Voxel::NEIGHBOUR_TOP_RIGHT, Voxel::NEIGHBOUR_RIGHT, Voxel::NEIGHBOUR_BACK,
Voxel::NEIGHBOUR_TOP, Voxel::NEIGHBOUR_TOP_RIGHT, Voxel::NEIGHBOUR_TOP_BACK, Voxel::NEIGHBOUR_TOP_RIGHT_BACK,
Voxel::NEIGHBOUR_BACK, Voxel::NEIGHBOUR_TOP_BACK, Voxel::NEIGHBOUR_RIGHT, Voxel::NEIGHBOUR_BACK);
VOXEL_NEIGHBOUR_RIGHT, VOXEL_NEIGHBOUR_TOP_RIGHT, VOXEL_NEIGHBOUR_RIGHT, VOXEL_NEIGHBOUR_BACK,
VOXEL_NEIGHBOUR_TOP, VOXEL_NEIGHBOUR_TOP_RIGHT, VOXEL_NEIGHBOUR_TOP_BACK, VOXEL_NEIGHBOUR_TOP_RIGHT_BACK,
VOXEL_NEIGHBOUR_BACK, VOXEL_NEIGHBOUR_TOP_BACK, VOXEL_NEIGHBOUR_RIGHT, VOXEL_NEIGHBOUR_BACK);
}
void SubVoxelPoints::refresh_point(int index, int vectx, int vecty, int vectz, int axisx, int axis2x, int axis3x, int axis4notx, int axisy, int axis2y, int axis3y, int axis4y, int axisz, int axis2z, int axis3z, int axis4notz) {
Ref<VoxelData> tVoxelData = _voxel_datas[index];
char fill = (char)128;
void VoxelCubePoints::refresh_point(int index, int vectx, int vecty, int vectz, int axisx, int axis2x, int axis3x, int axis4notx, int axisy, int axis2y, int axis3y, int axis4y, int axisz, int axis2z, int axis3z, int axis4notz) {
if (tVoxelData != NULL) {
fill = tVoxelData->get_fill();
}
char fill = _point_fills[index];
unsigned int neighbours = _point_neighbours[index];
Vector3i vector3i = Vector3i(vectx, vecty, vectz);
if ((tVoxelData->get_neighbours() & axisx) != axisx) {
if ((neighbours & axisx) != axisx) {
if (vectx == 0) {
vector3i.x = (int)(128 - fill);
} else {
@ -116,7 +78,7 @@ void SubVoxelPoints::refresh_point(int index, int vectx, int vecty, int vectz, i
}
}
if ((tVoxelData->get_neighbours() & axisy) != axisy) {
if ((neighbours & axisy) != axisy) {
if (vecty == 0) {
vector3i.y = (int)(128 - fill);
} else {
@ -124,7 +86,7 @@ void SubVoxelPoints::refresh_point(int index, int vectx, int vecty, int vectz, i
}
}
if ((tVoxelData->get_neighbours() & axisz) != axisz) {
if ((neighbours & axisz) != axisz) {
if (vectz == 0) {
vector3i.z = (int)(128 - fill);
} else {
@ -135,121 +97,91 @@ void SubVoxelPoints::refresh_point(int index, int vectx, int vecty, int vectz, i
_points[index] = vector3i;
}
void SubVoxelPoints::refresh_pointo(int index, int vectx, int vecty, int vectz, int axisx, int axis2x, int axis3x, int axis4notx, int axisy, int axis2y, int axis3y, int axis4y, int axisz, int axis2z, int axis3z, int axis4notz) {
Ref<VoxelData> tVoxelData = _voxel_datas[index];
char b = (char)128;
if (tVoxelData != NULL) {
b = tVoxelData->get_fill();
}
Vector3i vector3i = Vector3i(vectx, vecty, vectz);
if (((((tVoxelData->get_neighbours() & axisx) != axisx) && ((tVoxelData->get_neighbours() & axis2x) != axis2x)) && ((tVoxelData->get_neighbours() & axis3x) != axis3x)) && ((tVoxelData->get_neighbours() & axis4notx) != axis4notx)) {
if (vectx == 0) {
vector3i.x = (int)(128 - b);
} else {
vector3i.x = (int)(b + 128);
}
}
if (((((tVoxelData->get_neighbours() & axisy) != axisy) && ((tVoxelData->get_neighbours() & axis2y) != axis2y)) && ((tVoxelData->get_neighbours() & axis3y) != axis3y)) && ((tVoxelData->get_neighbours() & axis4y) != axis4y)) {
if (vecty == 0) {
vector3i.y = (int)(128 - b);
} else {
vector3i.y = (int)(b + 128);
}
}
if (((((tVoxelData->get_neighbours() & axisz) != axisz) && ((tVoxelData->get_neighbours() & axis2z) != axis2z)) && ((tVoxelData->get_neighbours() & axis3z) != axis3z)) && ((tVoxelData->get_neighbours() & axis4notz) != axis4notz)) {
if (vectz == 0) {
vector3i.z = (int)(128 - b);
} else {
vector3i.z = (int)(b + 128);
}
}
_points[index] = vector3i;
}
void SubVoxelPoints::refresh_point_full(int index, int vectx, int vecty, int vectz, int axisx, int axis2x, int axis3x, int axisy, int axis2y, int axis3y, int axis4y, int axisz, int axis2z, int axis3z) {
void VoxelCubePoints::refresh_point_full(int index, int vectx, int vecty, int vectz, int axisx, int axis2x, int axis3x, int axisy, int axis2y, int axis3y, int axis4y, int axisz, int axis2z, int axis3z) {
Vector3i vector3i = Vector3i(vectx, vecty, vectz);
_points[index] = vector3i;
}
void SubVoxelPoints::set_voxel_datas(Ref<VoxelData> VP000, Ref<VoxelData> VP100, Ref<VoxelData> VP010, Ref<VoxelData> VP001, Ref<VoxelData> VP110, Ref<VoxelData> VP011, Ref<VoxelData> VP101, Ref<VoxelData> VP111) {
if (VP000 != NULL && VP000->get_surface()->get_prefab_id() == 0 && VP000->get_surface()->get_mesh_id() == 0) {
_voxel_datas[P000] = VP000;
}
if (VP100 != NULL && VP100->get_surface()->get_prefab_id() == 0 && VP100->get_surface()->get_mesh_id() == 0) {
_voxel_datas[P100] = VP100;
}
if (VP010 != NULL && VP010->get_surface()->get_prefab_id() == 0 && VP010->get_surface()->get_mesh_id() == 0) {
_voxel_datas[P010] = VP010;
}
if (VP001 != NULL && VP001->get_surface()->get_prefab_id() == 0 && VP001->get_surface()->get_mesh_id() == 0) {
_voxel_datas[P001] = VP001;
}
if (VP110 != NULL && VP110->get_surface()->get_prefab_id() == 0 && VP110->get_surface()->get_mesh_id() == 0) {
_voxel_datas[P110] = VP110;
}
if (VP011 != NULL && VP011->get_surface()->get_prefab_id() == 0 && VP011->get_surface()->get_mesh_id() == 0) {
_voxel_datas[P011] = VP011;
}
if (VP101 != NULL && VP101->get_surface()->get_prefab_id() == 0 && VP101->get_surface()->get_mesh_id() == 0) {
_voxel_datas[P101] = VP101;
}
if (VP111 != NULL && VP111->get_surface()->get_prefab_id() == 0 && VP111->get_surface()->get_mesh_id() == 0) {
_voxel_datas[P111] = VP111;
}
void VoxelCubePoints::setup(const Ref<VoxelBuffer> buffer, int x, int y, int z, int size) {
ERR_FAIL_COND(size <= 0);
_point_types[P000] = buffer->get_voxel(x, y, z, VoxelBuffer::CHANNEL_TYPE);
_point_types[P100] = buffer->get_voxel(x + size, y, z, VoxelBuffer::CHANNEL_TYPE);
_point_types[P010] = buffer->get_voxel(x, y + size, z, VoxelBuffer::CHANNEL_TYPE);
_point_types[P001] = buffer->get_voxel(x, y, z + size, VoxelBuffer::CHANNEL_TYPE);
_point_types[P110] = buffer->get_voxel(x + size, y + size, z, VoxelBuffer::CHANNEL_TYPE);
_point_types[P011] = buffer->get_voxel(x, y + size, z + size, VoxelBuffer::CHANNEL_TYPE);
_point_types[P101] = buffer->get_voxel(x + size, y, z + size, VoxelBuffer::CHANNEL_TYPE);
_point_types[P111] = buffer->get_voxel(x + size, y + size, z + size, VoxelBuffer::CHANNEL_TYPE);
if (!has_points())
return;
_point_fills[P000] = buffer->get_voxel(x, y, z, VoxelBuffer::CHANNEL_ISOLEVEL);
_point_fills[P100] = buffer->get_voxel(x + size, y, z, VoxelBuffer::CHANNEL_ISOLEVEL);
_point_fills[P010] = buffer->get_voxel(x, y + size, z, VoxelBuffer::CHANNEL_ISOLEVEL);
_point_fills[P001] = buffer->get_voxel(x, y, z + size, VoxelBuffer::CHANNEL_ISOLEVEL);
_point_fills[P110] = buffer->get_voxel(x + size, y + size, z, VoxelBuffer::CHANNEL_ISOLEVEL);
_point_fills[P011] = buffer->get_voxel(x, y + size, z + size, VoxelBuffer::CHANNEL_ISOLEVEL);
_point_fills[P101] = buffer->get_voxel(x + size, y, z + size, VoxelBuffer::CHANNEL_ISOLEVEL);
_point_fills[P111] = buffer->get_voxel(x + size, y + size, z + size, VoxelBuffer::CHANNEL_ISOLEVEL);
}
SubVoxelSidePoints SubVoxelPoints::get_points_for_face(int face) {
if (face == VoxelFace::VOXEL_FACE_FRONT) {
_face_helper.set_point(0, get_point(P000));
_face_helper.set_point(1, get_point(P010));
_face_helper.set_point(2, get_point(P110));
_face_helper.set_point(3, get_point(P100));
} else if (face == VoxelFace::VOXEL_FACE_BACK) {
_face_helper.set_point(0, get_point(P101));
_face_helper.set_point(1, get_point(P111));
_face_helper.set_point(2, get_point(P011));
_face_helper.set_point(3, get_point(P001));
} else if (face == VoxelFace::VOXEL_FACE_RIGHT) {
_face_helper.set_point(0, get_point(P100));
_face_helper.set_point(1, get_point(P110));
_face_helper.set_point(2, get_point(P111));
_face_helper.set_point(3, get_point(P101));
} else if (face == VoxelFace::VOXEL_FACE_LEFT) {
_face_helper.set_point(0, get_point(P001));
_face_helper.set_point(1, get_point(P011));
_face_helper.set_point(2, get_point(P010));
_face_helper.set_point(3, get_point(P000));
} else if (face == VoxelFace::VOXEL_FACE_TOP) {
_face_helper.set_point(0, get_point(P111));
_face_helper.set_point(1, get_point(P110));
_face_helper.set_point(2, get_point(P010));
_face_helper.set_point(3, get_point(P011));
} else if (face == VoxelFace::VOXEL_FACE_DOWN) {
_face_helper.set_point(0, get_point(P001));
_face_helper.set_point(1, get_point(P000));
_face_helper.set_point(2, get_point(P100));
_face_helper.set_point(3, get_point(P101));
Ref<SubVoxelSidePoints> VoxelCubePoints::get_points_for_face(int face) {
if (face == VOXEL_FACE_FRONT) {
_face_helper->set_point(0, get_point(P000));
_face_helper->set_point(1, get_point(P010));
_face_helper->set_point(2, get_point(P110));
_face_helper->set_point(3, get_point(P100));
} else if (face == VOXEL_FACE_BACK) {
_face_helper->set_point(0, get_point(P101));
_face_helper->set_point(1, get_point(P111));
_face_helper->set_point(2, get_point(P011));
_face_helper->set_point(3, get_point(P001));
} else if (face == VOXEL_FACE_RIGHT) {
_face_helper->set_point(0, get_point(P100));
_face_helper->set_point(1, get_point(P110));
_face_helper->set_point(2, get_point(P111));
_face_helper->set_point(3, get_point(P101));
} else if (face == VOXEL_FACE_LEFT) {
_face_helper->set_point(0, get_point(P001));
_face_helper->set_point(1, get_point(P011));
_face_helper->set_point(2, get_point(P010));
_face_helper->set_point(3, get_point(P000));
} else if (face == VOXEL_FACE_TOP) {
_face_helper->set_point(0, get_point(P111));
_face_helper->set_point(1, get_point(P110));
_face_helper->set_point(2, get_point(P010));
_face_helper->set_point(3, get_point(P011));
} else if (face == VOXEL_FACE_BOTTOM) {
_face_helper->set_point(0, get_point(P001));
_face_helper->set_point(1, get_point(P000));
_face_helper->set_point(2, get_point(P100));
_face_helper->set_point(3, get_point(P101));
}
return _face_helper;
}
bool SubVoxelPoints::face_fully_covered(int face) {
bool VoxelCubePoints::face_fully_covered(int face) {
SubVoxelFacePointsHelper avp(face, this);
return avp.is_face_fully_covered();
}
bool SubVoxelPoints::face_should_be_visible_against_full(int face) {
bool VoxelCubePoints::face_should_be_visible_against_full(int face) {
SubVoxelFacePointsHelper avp(face, this);
return !avp.is_face_near_the_edges();
}
bool SubVoxelPoints::face_should_be_visible_against(int face, SubVoxelPoints *other) {
bool VoxelCubePoints::face_should_be_visible_against(int face, Ref<VoxelCubePoints> other) {
SubVoxelFacePointsHelper avp(face, this);
SubVoxelFacePointsHelper other2(get_opposite_face(face), other);
@ -257,7 +189,7 @@ bool SubVoxelPoints::face_should_be_visible_against(int face, SubVoxelPoints *ot
return avp.is_face_visible_against(other2);
}
bool SubVoxelPoints::is_sub_voxel_point(Vector3i point) {
bool VoxelCubePoints::is_sub_voxel_point(Vector3i point) {
for (int i = 0; i < POINT_COUNT; i += 1) {
if (get_point(i) == (point)) {
return true;
@ -266,7 +198,7 @@ bool SubVoxelPoints::is_sub_voxel_point(Vector3i point) {
return false;
}
bool SubVoxelPoints::is_sub_voxel_point(int x, int y, int z) {
bool VoxelCubePoints::is_sub_voxel_point(int x, int y, int z) {
for (int i = 0; i < POINT_COUNT; i += 1) {
if (get_point(i) == Vector3i(x, y, z)) {
return true;
@ -275,11 +207,11 @@ bool SubVoxelPoints::is_sub_voxel_point(int x, int y, int z) {
return false;
}
void SubVoxelPoints::set_point(int point, int x, int y, int z) {
void VoxelCubePoints::set_point(int point, int x, int y, int z) {
_points[point] = Vector3i(x, y, z);
}
int SubVoxelPoints::get_point_id(Vector3i point) {
int VoxelCubePoints::get_point_id(Vector3i point) {
for (int i = 0; i < POINT_COUNT; ++i) {
if (get_point(i) == point) {
return i;
@ -288,7 +220,7 @@ int SubVoxelPoints::get_point_id(Vector3i point) {
return 0;
}
int SubVoxelPoints::get_point_id(int x, int y, int z) {
int VoxelCubePoints::get_point_id(int x, int y, int z) {
for (int i = 0; i < POINT_COUNT; ++i) {
if (get_point(i) == Vector3i(x, y, z)) {
return i;
@ -297,139 +229,175 @@ int SubVoxelPoints::get_point_id(int x, int y, int z) {
return 0;
}
void SubVoxelPoints::copy_values_from(SubVoxelPoints *other) {
for (int i = 0; i < POINT_COUNT; ++i) {
_points[i] = other->get_point(i);
Vector3i VoxelCubePoints::get_top_left_point(int face) {
if (face == VOXEL_FACE_BACK) {
return _points[P011];
}
if (face == VOXEL_FACE_FRONT) {
return _points[P010];
}
if (face == VOXEL_FACE_RIGHT) {
return _points[P111];
}
if (face == VOXEL_FACE_LEFT) {
return _points[P010];
}
if (face == VOXEL_FACE_TOP) {
return _points[P010];
}
if (face == VOXEL_FACE_BOTTOM) {
return _points[P000];
}
return _points[0];
}
Vector3i SubVoxelPoints::get_top_left_point(int face, SubVoxelPoints *points) {
if (face == VoxelFace::VOXEL_FACE_BACK) {
return points->get_point(P011);
Vector3i VoxelCubePoints::get_top_right_point(int face) {
if (face == VOXEL_FACE_BACK) {
return _points[P111];
}
if (face == VoxelFace::VOXEL_FACE_FRONT) {
return points->get_point(P010);
if (face == VOXEL_FACE_FRONT) {
return _points[P110];
}
if (face == VoxelFace::VOXEL_FACE_RIGHT) {
return points->get_point(P111);
if (face == VOXEL_FACE_RIGHT) {
return _points[P110];
}
if (face == VoxelFace::VOXEL_FACE_LEFT) {
return points->get_point(P010);
if (face == VOXEL_FACE_LEFT) {
return _points[P011];
}
if (face == VoxelFace::VOXEL_FACE_TOP) {
return points->get_point(P010);
if (face == VOXEL_FACE_TOP) {
return _points[P110];
}
if (face == VoxelFace::VOXEL_FACE_DOWN) {
return points->get_point(P000);
if (face == VOXEL_FACE_BOTTOM) {
return _points[P100];
}
return points->get_point(0);
return _points[0];
}
Vector3i SubVoxelPoints::get_top_right_point(int face, SubVoxelPoints *points) {
if (face == VoxelFace::VOXEL_FACE_BACK) {
return points->get_point(P111);
Vector3i VoxelCubePoints::get_bottom_left_point(int face) {
if (face == VOXEL_FACE_BACK) {
return _points[P001];
}
if (face == VoxelFace::VOXEL_FACE_FRONT) {
return points->get_point(P110);
if (face == VOXEL_FACE_FRONT) {
return _points[P000];
}
if (face == VoxelFace::VOXEL_FACE_RIGHT) {
return points->get_point(P110);
if (face == VOXEL_FACE_RIGHT) {
return _points[P101];
}
if (face == VoxelFace::VOXEL_FACE_LEFT) {
return points->get_point(P011);
if (face == VOXEL_FACE_LEFT) {
return _points[P001];
}
if (face == VoxelFace::VOXEL_FACE_TOP) {
return points->get_point(P110);
if (face == VOXEL_FACE_TOP) {
return _points[P011];
}
if (face == VoxelFace::VOXEL_FACE_DOWN) {
return points->get_point(P100);
if (face == VOXEL_FACE_BOTTOM) {
return _points[P001];
}
return points->get_point(0);
return _points[0];
}
Vector3i SubVoxelPoints::get_bottom_left_point(int face, SubVoxelPoints *points) {
if (face == VoxelFace::VOXEL_FACE_BACK) {
return points->get_point(P001);
Vector3i VoxelCubePoints::get_bottom_right_point(int face) {
if (face == VOXEL_FACE_BACK) {
return _points[P101];
}
if (face == VoxelFace::VOXEL_FACE_FRONT) {
return points->get_point(P000);
if (face == VOXEL_FACE_FRONT) {
return _points[P100];
}
if (face == VoxelFace::VOXEL_FACE_RIGHT) {
return points->get_point(P101);
if (face == VOXEL_FACE_RIGHT) {
return _points[P100];
}
if (face == VoxelFace::VOXEL_FACE_LEFT) {
return points->get_point(P001);
if (face == VOXEL_FACE_LEFT) {
return _points[P001];
}
if (face == VoxelFace::VOXEL_FACE_TOP) {
return points->get_point(P011);
if (face == VOXEL_FACE_TOP) {
return _points[P111];
}
if (face == VoxelFace::VOXEL_FACE_DOWN) {
return points->get_point(P001);
if (face == VOXEL_FACE_BOTTOM) {
return _points[P101];
}
return points->get_point(0);
return _points[P000];
}
Vector3i SubVoxelPoints::get_bottom_right_point(int face, SubVoxelPoints *points) {
if (face == VoxelFace::VOXEL_FACE_BACK) {
return points->get_point(P101);
}
if (face == VoxelFace::VOXEL_FACE_FRONT) {
return points->get_point(P100);
}
if (face == VoxelFace::VOXEL_FACE_RIGHT) {
return points->get_point(P100);
}
if (face == VoxelFace::VOXEL_FACE_LEFT) {
return points->get_point(P001);
}
if (face == VoxelFace::VOXEL_FACE_TOP) {
return points->get_point(P111);
}
if (face == VoxelFace::VOXEL_FACE_DOWN) {
return points->get_point(P101);
}
return points->get_point(0);
bool VoxelCubePoints::has_points() {
return (_point_types[P000] != 0 && _point_types[P100] != 0 && _point_types[P010] != 0 && _point_types[P001] != 0 &&
_point_types[P110] != 0 && _point_types[P011] != 0 && _point_types[P101] != 0 && _point_types[P111] != 0);
}
bool SubVoxelPoints::validate_voxel_datas(Ref<VoxelData> VP000, Ref<VoxelData> VP100, Ref<VoxelData> VP010, Ref<VoxelData> VP001, Ref<VoxelData> VP110, Ref<VoxelData> VP011, Ref<VoxelData> VP101, Ref<VoxelData> VP111) {
return (VP000 != NULL && VP100 != NULL && VP010 != NULL && VP001 != NULL &&
VP110 != NULL && VP011 != NULL && VP101 != NULL && VP111 != NULL &&
VP000->get_surface()->get_prefab_id() == 0 &&
VP000->get_surface()->get_mesh_id() == 0 &&
VP100->get_surface()->get_prefab_id() == 0 &&
VP100->get_surface()->get_mesh_id() == 0 &&
VP010->get_surface()->get_prefab_id() == 0 &&
VP010->get_surface()->get_mesh_id() == 0 &&
VP001->get_surface()->get_prefab_id() == 0 &&
VP001->get_surface()->get_mesh_id() == 0 &&
VP110->get_surface()->get_prefab_id() == 0 &&
VP110->get_surface()->get_mesh_id() == 0 &&
VP011->get_surface()->get_prefab_id() == 0 &&
VP011->get_surface()->get_mesh_id() == 0 &&
VP101->get_surface()->get_prefab_id() == 0 &&
VP101->get_surface()->get_mesh_id() == 0 &&
VP111->get_surface()->get_prefab_id() == 0 &&
VP111->get_surface()->get_mesh_id() == 0);
int VoxelCubePoints::get_opposite_face(int face) {
if (face == VOXEL_FACE_FRONT) {
return VOXEL_FACE_BACK;
}
if (face == VOXEL_FACE_BACK) {
return VOXEL_FACE_FRONT;
}
if (face == VOXEL_FACE_LEFT) {
return VOXEL_FACE_RIGHT;
}
if (face == VOXEL_FACE_RIGHT) {
return VOXEL_FACE_LEFT;
}
if (face == VOXEL_FACE_TOP) {
return VOXEL_FACE_BOTTOM;
}
return VOXEL_FACE_BOTTOM;
}
int SubVoxelPoints::get_opposite_face(int face) {
if (face == VoxelFace::VOXEL_FACE_FRONT) {
return VoxelFace::VOXEL_FACE_BACK;
}
if (face == VoxelFace::VOXEL_FACE_BACK) {
return VoxelFace::VOXEL_FACE_FRONT;
}
if (face == VoxelFace::VOXEL_FACE_LEFT) {
return VoxelFace::VOXEL_FACE_RIGHT;
}
if (face == VoxelFace::VOXEL_FACE_RIGHT) {
return VoxelFace::VOXEL_FACE_LEFT;
}
if (face == VoxelFace::VOXEL_FACE_TOP) {
return VoxelFace::VOXEL_FACE_DOWN;
}
//int arg_4C_0 = VoxelFace::VOXEL_FACE_DOWN;
return VoxelFace::VOXEL_FACE_DOWN;
}
void VoxelCubePoints::_bind_methods() {
} // namespace voxelman
BIND_ENUM_CONSTANT(P000);
BIND_ENUM_CONSTANT(P100);
BIND_ENUM_CONSTANT(P010);
BIND_ENUM_CONSTANT(P001);
BIND_ENUM_CONSTANT(P110);
BIND_ENUM_CONSTANT(P011);
BIND_ENUM_CONSTANT(P101);
BIND_ENUM_CONSTANT(P111);
BIND_ENUM_CONSTANT(POINT_COUNT);
BIND_ENUM_CONSTANT(VOXEL_FACE_FRONT);
BIND_ENUM_CONSTANT(VOXEL_FACE_RIGHT);
BIND_ENUM_CONSTANT(VOXEL_FACE_BACK);
BIND_ENUM_CONSTANT(VOXEL_FACE_LEFT);
BIND_ENUM_CONSTANT(VOXEL_FACE_TOP);
BIND_ENUM_CONSTANT(VOXEL_FACE_BOTTOM);
BIND_ENUM_CONSTANT(VOXEL_FACE_COUNT);
BIND_ENUM_CONSTANT(VOXEL_NEIGHBOUR_NONE);
BIND_ENUM_CONSTANT(VOXEL_NEIGHBOUR_LEFT);
BIND_ENUM_CONSTANT(VOXEL_NEIGHBOUR_RIGHT);
BIND_ENUM_CONSTANT(VOXEL_NEIGHBOUR_FRONT);
BIND_ENUM_CONSTANT(VOXEL_NEIGHBOUR_BACK);
BIND_ENUM_CONSTANT(VOXEL_NEIGHBOUR_TOP);
BIND_ENUM_CONSTANT(VOXEL_NEIGHBOUR_BOTTOM);
BIND_ENUM_CONSTANT(VOXEL_NEIGHBOUR_LEFT_FRONT);
BIND_ENUM_CONSTANT(VOXEL_NEIGHBOUR_LEFT_BACK);
BIND_ENUM_CONSTANT(VOXEL_NEIGHBOUR_RIGHT_FRONT);
BIND_ENUM_CONSTANT(VOXEL_NEIGHBOUR_RIGHT_BACK);
BIND_ENUM_CONSTANT(VOXEL_NEIGHBOUR_TOP_LEFT);
BIND_ENUM_CONSTANT(VOXEL_NEIGHBOUR_TOP_RIGHT);
BIND_ENUM_CONSTANT(VOXEL_NEIGHBOUR_TOP_FRONT);
BIND_ENUM_CONSTANT(VOXEL_NEIGHBOUR_TOP_BACK);
BIND_ENUM_CONSTANT(VOXEL_NEIGHBOUR_BOTTOM_LEFT);
BIND_ENUM_CONSTANT(VOXEL_NEIGHBOUR_BOTTOM_RIGHT);
BIND_ENUM_CONSTANT(VOXEL_NEIGHBOUR_BOTTOM_FRONT);
BIND_ENUM_CONSTANT(VOXEL_NEIGHBOUR_BOTTOM_BACK);
BIND_ENUM_CONSTANT(VOXEL_NEIGHBOUR_BOTTOM_LEFT_FRONT);
BIND_ENUM_CONSTANT(VOXEL_NEIGHBOUR_BOTTOM_LEFT_BACK);
BIND_ENUM_CONSTANT(VOXEL_NEIGHBOUR_BOTTOM_RIGHT_FRONT);
BIND_ENUM_CONSTANT(VOXEL_NEIGHBOUR_BOTTOM_RIGHT_BACK);
BIND_ENUM_CONSTANT(VOXEL_NEIGHBOUR_TOP_LEFT_FRONT);
BIND_ENUM_CONSTANT(VOXEL_NEIGHBOUR_TOP_LEFT_BACK);
BIND_ENUM_CONSTANT(VOXEL_NEIGHBOUR_TOP_RIGHT_FRONT);
BIND_ENUM_CONSTANT(VOXEL_NEIGHBOUR_TOP_RIGHT_BACK);
BIND_ENUM_CONSTANT(VOXEL_FULL_NEIGHBOURS_CROSS);
BIND_ENUM_CONSTANT(VOXEL_FULL_SIDE_NEIGHBOURS);
BIND_ENUM_CONSTANT(VOXEL_FULL_SIDE_NEIGHBOURS_TOP);
BIND_ENUM_CONSTANT(VOXEL_FULL_SIDE_NEIGHBOURS_DOWN);
}

View File

@ -1,74 +1,127 @@
#ifndef SUB_VOXEL_POINTS_H
#define SUB_VOXEL_POINTS_H
#include "../collections/vector3i.h"
#include "core/reference.h"
#include "../../math/vector3i.h"
#include "core/vector.h"
#include "sub_voxel_points_helper.h"
#include "../../world/voxel_buffer.h"
#include "sub_voxel_side_points.h"
#include "voxel.h"
#include "voxel_data.h"
using namespace voxelman;
class VoxelCubePoints : Reference {
GDCLASS(VoxelCubePoints, Reference);
namespace voxelman {
class Voxel;
class VoxelData;
class SubVoxelPoints {
public:
enum SidePoints {
enum Points {
P000 = 0,
P100 = 1,
P010 = 2,
P001 = 3,
P110 = 4,
P011 = 5,
P101 = 6,
P111 = 7,
};
enum Points {
POINT_COUNT = 8,
};
enum VoxelFaces {
VOXEL_FACE_FRONT = 0,
VOXEL_FACE_RIGHT = 1,
VOXEL_FACE_BACK = 2,
VOXEL_FACE_LEFT = 3,
VOXEL_FACE_TOP = 4,
VOXEL_FACE_BOTTOM = 5,
VOXEL_FACE_COUNT = 6,
};
enum VoxelNeighbours {
VOXEL_NEIGHBOUR_NONE = 0,
VOXEL_NEIGHBOUR_LEFT = 1 << 0,
VOXEL_NEIGHBOUR_RIGHT = 1 << 1,
VOXEL_NEIGHBOUR_FRONT = 1 << 2,
VOXEL_NEIGHBOUR_BACK = 1 << 3,
VOXEL_NEIGHBOUR_TOP = 1 << 4,
VOXEL_NEIGHBOUR_BOTTOM = 1 << 5,
VOXEL_NEIGHBOUR_LEFT_FRONT = 1 << 6,
VOXEL_NEIGHBOUR_LEFT_BACK = 1 << 7,
VOXEL_NEIGHBOUR_RIGHT_FRONT = 1 << 8,
VOXEL_NEIGHBOUR_RIGHT_BACK = 1 << 9,
VOXEL_NEIGHBOUR_TOP_LEFT = 1 << 10,
VOXEL_NEIGHBOUR_TOP_RIGHT = 1 << 11,
VOXEL_NEIGHBOUR_TOP_FRONT = 1 << 12,
VOXEL_NEIGHBOUR_TOP_BACK = 1 << 13,
VOXEL_NEIGHBOUR_BOTTOM_LEFT = 1 << 14,
VOXEL_NEIGHBOUR_BOTTOM_RIGHT = 1 << 15,
VOXEL_NEIGHBOUR_BOTTOM_FRONT = 1 << 16,
VOXEL_NEIGHBOUR_BOTTOM_BACK = 1 << 17,
VOXEL_NEIGHBOUR_BOTTOM_LEFT_FRONT = 1 << 18,
VOXEL_NEIGHBOUR_BOTTOM_LEFT_BACK = 1 << 19,
VOXEL_NEIGHBOUR_BOTTOM_RIGHT_FRONT = 1 << 20,
VOXEL_NEIGHBOUR_BOTTOM_RIGHT_BACK = 1 << 21,
VOXEL_NEIGHBOUR_TOP_LEFT_FRONT = 1 << 22,
VOXEL_NEIGHBOUR_TOP_LEFT_BACK = 1 << 23,
VOXEL_NEIGHBOUR_TOP_RIGHT_FRONT = 1 << 24,
VOXEL_NEIGHBOUR_TOP_RIGHT_BACK = 1 << 25,
VOXEL_FULL_NEIGHBOURS_CROSS = VOXEL_NEIGHBOUR_LEFT | VOXEL_NEIGHBOUR_RIGHT | VOXEL_NEIGHBOUR_BACK | VOXEL_NEIGHBOUR_FRONT | VOXEL_NEIGHBOUR_TOP | VOXEL_NEIGHBOUR_BOTTOM, // | VOXEL_NEIGHBOUR_LEFT_BACK | VOXEL_NEIGHBOUR_LEFT_FRONT | VOXEL_NEIGHBOUR_RIGHT_BACK | VOXEL_NEIGHBOUR_RIGHT_FRONT;
VOXEL_FULL_SIDE_NEIGHBOURS = VOXEL_NEIGHBOUR_LEFT | VOXEL_NEIGHBOUR_RIGHT | VOXEL_NEIGHBOUR_BACK | VOXEL_NEIGHBOUR_FRONT,
VOXEL_FULL_SIDE_NEIGHBOURS_TOP = VOXEL_NEIGHBOUR_LEFT | VOXEL_NEIGHBOUR_RIGHT | VOXEL_NEIGHBOUR_BACK | VOXEL_NEIGHBOUR_FRONT | VOXEL_NEIGHBOUR_TOP,
VOXEL_FULL_SIDE_NEIGHBOURS_DOWN = VOXEL_NEIGHBOUR_LEFT | VOXEL_NEIGHBOUR_RIGHT | VOXEL_NEIGHBOUR_BACK | VOXEL_NEIGHBOUR_FRONT | VOXEL_NEIGHBOUR_BOTTOM,
};
Vector3i get_point(int index);
SubVoxelPoints(Voxel *voxel);
~SubVoxelPoints();
VoxelCubePoints();
~VoxelCubePoints();
void refresh_points();
void set_voxel_datas(Ref<VoxelData> VP000, Ref<VoxelData> VP100, Ref<VoxelData> VP010, Ref<VoxelData> VP001, Ref<VoxelData> VP110, Ref<VoxelData> VP011, Ref<VoxelData> VP101, Ref<VoxelData> VP111);
SubVoxelSidePoints get_points_for_face(int face);
void setup(const Ref<VoxelBuffer> buffer, int x, int y, int z, int size = 1);
Ref<SubVoxelSidePoints> get_points_for_face(int face);
bool face_fully_covered(int face);
bool face_should_be_visible_against_full(int face);
bool face_should_be_visible_against(int face, SubVoxelPoints *other);
bool face_should_be_visible_against(int face, Ref<VoxelCubePoints> other);
bool is_sub_voxel_point(Vector3i point);
bool is_sub_voxel_point(int x, int y, int z);
void set_point(int point, int x, int y, int z);
int get_point_id(Vector3i point);
int get_point_id(int x, int y, int z);
void copy_values_from(SubVoxelPoints *other);
static Vector3i get_top_left_point(int face, SubVoxelPoints *points);
static Vector3i get_top_right_point(int face, SubVoxelPoints *points);
static Vector3i get_bottom_left_point(int face, SubVoxelPoints *points);
static Vector3i get_bottom_right_point(int face, SubVoxelPoints *points);
static bool validate_voxel_datas(Ref<VoxelData> VP000, Ref<VoxelData> VP100, Ref<VoxelData> VP010, Ref<VoxelData> VP001, Ref<VoxelData> VP110, Ref<VoxelData> VP011, Ref<VoxelData> VP101, Ref<VoxelData> VP111);
Vector3i get_top_left_point(int face);
Vector3i get_top_right_point(int face);
Vector3i get_bottom_left_point(int face);
Vector3i get_bottom_right_point(int face);
bool has_points();
int get_opposite_face(int face);
protected:
static void _bind_methods();
private:
Vector3i _points[POINT_COUNT];
Ref<VoxelData> *_voxel_datas;
Voxel *_voxel;
SubVoxelSidePoints _face_helper;
void refresh_point(int index, int vectx, int vecty, int vectz, int axisx, int axis2x, int axis3x, int axis4notx, int axisy, int axis2y, int axis3y, int axis4y, int axisz, int axis2z, int axis3z, int axis4notz);
void refresh_pointo(int index, int vectx, int vecty, int vectz, int axisx, int axis2x, int axis3x, int axis4notx, int axisy, int axis2y, int axis3y, int axis4y, int axisz, int axis2z, int axis3z, int axis4notz);
void refresh_point_full(int index, int vectx, int vecty, int vectz, int axisx, int axis2x, int axis3x, int axisy, int axis2y, int axis3y, int axis4y, int axisz, int axis2z, int axis3z);
#if MEM_TOOLS
static int allocs;
#endif
uint8_t _point_types[POINT_COUNT];
uint8_t _point_fills[POINT_COUNT];
unsigned int _point_neighbours[POINT_COUNT];
Ref<SubVoxelSidePoints> _face_helper;
void refresh_point(int index, int vectx, int vecty, int vectz, int axisx, int axis2x, int axis3x, int axis4notx, int axisy, int axis2y, int axis3y, int axis4y, int axisz, int axis2z, int axis3z, int axis4notz);
void refresh_point_full(int index, int vectx, int vecty, int vectz, int axisx, int axis2x, int axis3x, int axisy, int axis2y, int axis3y, int axis4y, int axisz, int axis2z, int axis3z);
};
} // namespace voxelman
VARIANT_ENUM_CAST(VoxelCubePoints::Points);
VARIANT_ENUM_CAST(VoxelCubePoints::VoxelFaces);
VARIANT_ENUM_CAST(VoxelCubePoints::VoxelNeighbours);
#endif

View File

@ -7,43 +7,4 @@ VoxelMesherCubic::VoxelMesherCubic() {
void VoxelMesherCubic::_bind_methods() {
BIND_ENUM_CONSTANT(VOXEL_NEIGHBOUR_NONE);
BIND_ENUM_CONSTANT(VOXEL_NEIGHBOUR_LEFT);
BIND_ENUM_CONSTANT(VOXEL_NEIGHBOUR_RIGHT);
BIND_ENUM_CONSTANT(VOXEL_NEIGHBOUR_FRONT);
BIND_ENUM_CONSTANT(VOXEL_NEIGHBOUR_BACK);
BIND_ENUM_CONSTANT(VOXEL_NEIGHBOUR_TOP);
BIND_ENUM_CONSTANT(VOXEL_NEIGHBOUR_BOTTOM);
BIND_ENUM_CONSTANT(VOXEL_NEIGHBOUR_LEFT_FRONT);
BIND_ENUM_CONSTANT(VOXEL_NEIGHBOUR_LEFT_BACK);
BIND_ENUM_CONSTANT(VOXEL_NEIGHBOUR_RIGHT_FRONT);
BIND_ENUM_CONSTANT(VOXEL_NEIGHBOUR_RIGHT_BACK);
BIND_ENUM_CONSTANT(VOXEL_NEIGHBOUR_TOP_LEFT);
BIND_ENUM_CONSTANT(VOXEL_NEIGHBOUR_TOP_RIGHT);
BIND_ENUM_CONSTANT(VOXEL_NEIGHBOUR_TOP_FRONT);
BIND_ENUM_CONSTANT(VOXEL_NEIGHBOUR_TOP_BACK);
BIND_ENUM_CONSTANT(VOXEL_NEIGHBOUR_BOTTOM_LEFT);
BIND_ENUM_CONSTANT(VOXEL_NEIGHBOUR_BOTTOM_RIGHT);
BIND_ENUM_CONSTANT(VOXEL_NEIGHBOUR_BOTTOM_FRONT);
BIND_ENUM_CONSTANT(VOXEL_NEIGHBOUR_BOTTOM_BACK);
BIND_ENUM_CONSTANT(VOXEL_NEIGHBOUR_BOTTOM_LEFT_FRONT);
BIND_ENUM_CONSTANT(VOXEL_NEIGHBOUR_BOTTOM_LEFT_BACK);
BIND_ENUM_CONSTANT(VOXEL_NEIGHBOUR_BOTTOM_RIGHT_FRONT);
BIND_ENUM_CONSTANT(VOXEL_NEIGHBOUR_BOTTOM_RIGHT_BACK);
BIND_ENUM_CONSTANT(VOXEL_NEIGHBOUR_TOP_LEFT_FRONT);
BIND_ENUM_CONSTANT(VOXEL_NEIGHBOUR_TOP_LEFT_BACK);
BIND_ENUM_CONSTANT(VOXEL_NEIGHBOUR_TOP_RIGHT_FRONT);
BIND_ENUM_CONSTANT(VOXEL_NEIGHBOUR_TOP_RIGHT_BACK);
BIND_ENUM_CONSTANT(VOXEL_FULL_NEIGHBOURS_CROSS);
BIND_ENUM_CONSTANT(VOXEL_FULL_SIDE_NEIGHBOURS);
BIND_ENUM_CONSTANT(VOXEL_FULL_SIDE_NEIGHBOURS_TOP);
BIND_ENUM_CONSTANT(VOXEL_FULL_SIDE_NEIGHBOURS_DOWN);
}

View File

@ -7,47 +7,6 @@ class VoxelMesherCubic : public VoxelMesher {
GDCLASS(VoxelMesherCubic, VoxelMesher);
public:
enum VoxelNeighbours {
VOXEL_NEIGHBOUR_NONE = 0,
VOXEL_NEIGHBOUR_LEFT = 1 << 0,
VOXEL_NEIGHBOUR_RIGHT = 1 << 1,
VOXEL_NEIGHBOUR_FRONT = 1 << 2,
VOXEL_NEIGHBOUR_BACK = 1 << 3,
VOXEL_NEIGHBOUR_TOP = 1 << 4,
VOXEL_NEIGHBOUR_BOTTOM = 1 << 5,
VOXEL_NEIGHBOUR_LEFT_FRONT = 1 << 6,
VOXEL_NEIGHBOUR_LEFT_BACK = 1 << 7,
VOXEL_NEIGHBOUR_RIGHT_FRONT = 1 << 8,
VOXEL_NEIGHBOUR_RIGHT_BACK = 1 << 9,
VOXEL_NEIGHBOUR_TOP_LEFT = 1 << 10,
VOXEL_NEIGHBOUR_TOP_RIGHT = 1 << 11,
VOXEL_NEIGHBOUR_TOP_FRONT = 1 << 12,
VOXEL_NEIGHBOUR_TOP_BACK = 1 << 13,
VOXEL_NEIGHBOUR_BOTTOM_LEFT = 1 << 14,
VOXEL_NEIGHBOUR_BOTTOM_RIGHT = 1 << 15,
VOXEL_NEIGHBOUR_BOTTOM_FRONT = 1 << 16,
VOXEL_NEIGHBOUR_BOTTOM_BACK = 1 << 17,
VOXEL_NEIGHBOUR_BOTTOM_LEFT_FRONT = 1 << 18,
VOXEL_NEIGHBOUR_BOTTOM_LEFT_BACK = 1 << 19,
VOXEL_NEIGHBOUR_BOTTOM_RIGHT_FRONT = 1 << 20,
VOXEL_NEIGHBOUR_BOTTOM_RIGHT_BACK = 1 << 21,
VOXEL_NEIGHBOUR_TOP_LEFT_FRONT = 1 << 22,
VOXEL_NEIGHBOUR_TOP_LEFT_BACK = 1 << 23,
VOXEL_NEIGHBOUR_TOP_RIGHT_FRONT = 1 << 24,
VOXEL_NEIGHBOUR_TOP_RIGHT_BACK = 1 << 25,
VOXEL_FULL_NEIGHBOURS_CROSS = VOXEL_NEIGHBOUR_LEFT | VOXEL_NEIGHBOUR_RIGHT | VOXEL_NEIGHBOUR_BACK | VOXEL_NEIGHBOUR_FRONT | VOXEL_NEIGHBOUR_TOP | VOXEL_NEIGHBOUR_BOTTOM, // | VOXEL_NEIGHBOUR_LEFT_BACK | VOXEL_NEIGHBOUR_LEFT_FRONT | VOXEL_NEIGHBOUR_RIGHT_BACK | VOXEL_NEIGHBOUR_RIGHT_FRONT;
VOXEL_FULL_SIDE_NEIGHBOURS = VOXEL_NEIGHBOUR_LEFT | VOXEL_NEIGHBOUR_RIGHT | VOXEL_NEIGHBOUR_BACK | VOXEL_NEIGHBOUR_FRONT,
VOXEL_FULL_SIDE_NEIGHBOURS_TOP = VOXEL_NEIGHBOUR_LEFT | VOXEL_NEIGHBOUR_RIGHT | VOXEL_NEIGHBOUR_BACK | VOXEL_NEIGHBOUR_FRONT | VOXEL_NEIGHBOUR_TOP,
VOXEL_FULL_SIDE_NEIGHBOURS_DOWN = VOXEL_NEIGHBOUR_LEFT | VOXEL_NEIGHBOUR_RIGHT | VOXEL_NEIGHBOUR_BACK | VOXEL_NEIGHBOUR_FRONT | VOXEL_NEIGHBOUR_BOTTOM,
};
VoxelMesherCubic();
@ -56,6 +15,4 @@ protected:
};
VARIANT_ENUM_CAST(VoxelMesherCubic::VoxelNeighbours);
#endif

View File

@ -13,6 +13,8 @@
#include "world/voxel_chunk.h"
#include "meshers/cubic_mesher/voxel_mesher_cubic.h"
#include "meshers/cubic_mesher/voxel_cube_points.h"
#include "meshers/cubic_mesher/sub_voxel_side_points.h"
void register_voxelman_types() {
ClassDB::register_class<VoxelMesher>();
@ -31,6 +33,8 @@ void register_voxelman_types() {
ClassDB::register_class<VoxelChunk>();
ClassDB::register_class<VoxelMesherCubic>();
ClassDB::register_class<VoxelCubePoints>();
ClassDB::register_class<SubVoxelSidePoints>();
}
void unregister_voxelman_types() {