mirror of
https://github.com/Relintai/voxelman.git
synced 2024-11-12 10:15:12 +01:00
Added in a few of my old classes.
This commit is contained in:
parent
115750a66f
commit
ecfcf79f07
3
SCsub
3
SCsub
@ -17,3 +17,6 @@ env.add_source_files(env.modules_sources,"meshers/transvoxel_tables.cpp")
|
||||
env.add_source_files(env.modules_sources,"world/voxel_buffer.cpp")
|
||||
env.add_source_files(env.modules_sources,"world/voxel_world.cpp")
|
||||
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")
|
||||
|
435
meshers/cubic_mesher/old/sub_voxel_points.cpp
Normal file
435
meshers/cubic_mesher/old/sub_voxel_points.cpp
Normal file
@ -0,0 +1,435 @@
|
||||
#include "sub_voxel_points.h"
|
||||
|
||||
namespace voxelman {
|
||||
|
||||
#if MEM_TOOLS
|
||||
int SubVoxelPoints::allocs = 0;
|
||||
#endif
|
||||
|
||||
Vector3i SubVoxelPoints::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
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
void SubVoxelPoints::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);
|
||||
|
||||
//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);
|
||||
|
||||
//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);
|
||||
|
||||
//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);
|
||||
|
||||
//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);
|
||||
|
||||
//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);
|
||||
|
||||
//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);
|
||||
|
||||
//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);
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
if (tVoxelData != NULL) {
|
||||
fill = tVoxelData->get_fill();
|
||||
}
|
||||
|
||||
Vector3i vector3i = Vector3i(vectx, vecty, vectz);
|
||||
if ((tVoxelData->get_neighbours() & axisx) != axisx) {
|
||||
if (vectx == 0) {
|
||||
vector3i.x = (int)(128 - fill);
|
||||
} else {
|
||||
vector3i.x = (int)(fill + 128);
|
||||
}
|
||||
}
|
||||
|
||||
if ((tVoxelData->get_neighbours() & axisy) != axisy) {
|
||||
if (vecty == 0) {
|
||||
vector3i.y = (int)(128 - fill);
|
||||
} else {
|
||||
vector3i.y = (int)(fill + 128);
|
||||
}
|
||||
}
|
||||
|
||||
if ((tVoxelData->get_neighbours() & axisz) != axisz) {
|
||||
if (vectz == 0) {
|
||||
vector3i.z = (int)(128 - fill);
|
||||
} else {
|
||||
vector3i.z = (int)(fill + 128);
|
||||
}
|
||||
}
|
||||
|
||||
_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) {
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
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));
|
||||
}
|
||||
|
||||
return _face_helper;
|
||||
}
|
||||
|
||||
bool SubVoxelPoints::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) {
|
||||
|
||||
SubVoxelFacePointsHelper avp(face, this);
|
||||
|
||||
return !avp.is_face_near_the_edges();
|
||||
}
|
||||
|
||||
bool SubVoxelPoints::face_should_be_visible_against(int face, SubVoxelPoints *other) {
|
||||
SubVoxelFacePointsHelper avp(face, this);
|
||||
|
||||
SubVoxelFacePointsHelper other2(get_opposite_face(face), other);
|
||||
|
||||
return avp.is_face_visible_against(other2);
|
||||
}
|
||||
|
||||
bool SubVoxelPoints::is_sub_voxel_point(Vector3i point) {
|
||||
for (int i = 0; i < POINT_COUNT; i += 1) {
|
||||
if (get_point(i) == (point)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool SubVoxelPoints::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;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void SubVoxelPoints::set_point(int point, int x, int y, int z) {
|
||||
_points[point] = Vector3i(x, y, z);
|
||||
}
|
||||
|
||||
int SubVoxelPoints::get_point_id(Vector3i point) {
|
||||
for (int i = 0; i < POINT_COUNT; ++i) {
|
||||
if (get_point(i) == point) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int SubVoxelPoints::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;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void SubVoxelPoints::copy_values_from(SubVoxelPoints *other) {
|
||||
for (int i = 0; i < POINT_COUNT; ++i) {
|
||||
_points[i] = other->get_point(i);
|
||||
}
|
||||
}
|
||||
|
||||
Vector3i SubVoxelPoints::get_top_left_point(int face, SubVoxelPoints *points) {
|
||||
if (face == VoxelFace::VOXEL_FACE_BACK) {
|
||||
return points->get_point(P011);
|
||||
}
|
||||
if (face == VoxelFace::VOXEL_FACE_FRONT) {
|
||||
return points->get_point(P010);
|
||||
}
|
||||
if (face == VoxelFace::VOXEL_FACE_RIGHT) {
|
||||
return points->get_point(P111);
|
||||
}
|
||||
if (face == VoxelFace::VOXEL_FACE_LEFT) {
|
||||
return points->get_point(P010);
|
||||
}
|
||||
if (face == VoxelFace::VOXEL_FACE_TOP) {
|
||||
return points->get_point(P010);
|
||||
}
|
||||
if (face == VoxelFace::VOXEL_FACE_DOWN) {
|
||||
return points->get_point(P000);
|
||||
}
|
||||
return points->get_point(0);
|
||||
}
|
||||
|
||||
Vector3i SubVoxelPoints::get_top_right_point(int face, SubVoxelPoints *points) {
|
||||
if (face == VoxelFace::VOXEL_FACE_BACK) {
|
||||
return points->get_point(P111);
|
||||
}
|
||||
if (face == VoxelFace::VOXEL_FACE_FRONT) {
|
||||
return points->get_point(P110);
|
||||
}
|
||||
if (face == VoxelFace::VOXEL_FACE_RIGHT) {
|
||||
return points->get_point(P110);
|
||||
}
|
||||
if (face == VoxelFace::VOXEL_FACE_LEFT) {
|
||||
return points->get_point(P011);
|
||||
}
|
||||
if (face == VoxelFace::VOXEL_FACE_TOP) {
|
||||
return points->get_point(P110);
|
||||
}
|
||||
if (face == VoxelFace::VOXEL_FACE_DOWN) {
|
||||
return points->get_point(P100);
|
||||
}
|
||||
return points->get_point(0);
|
||||
}
|
||||
|
||||
Vector3i SubVoxelPoints::get_bottom_left_point(int face, SubVoxelPoints *points) {
|
||||
if (face == VoxelFace::VOXEL_FACE_BACK) {
|
||||
return points->get_point(P001);
|
||||
}
|
||||
if (face == VoxelFace::VOXEL_FACE_FRONT) {
|
||||
return points->get_point(P000);
|
||||
}
|
||||
if (face == VoxelFace::VOXEL_FACE_RIGHT) {
|
||||
return points->get_point(P101);
|
||||
}
|
||||
if (face == VoxelFace::VOXEL_FACE_LEFT) {
|
||||
return points->get_point(P001);
|
||||
}
|
||||
if (face == VoxelFace::VOXEL_FACE_TOP) {
|
||||
return points->get_point(P011);
|
||||
}
|
||||
if (face == VoxelFace::VOXEL_FACE_DOWN) {
|
||||
return points->get_point(P001);
|
||||
}
|
||||
return points->get_point(0);
|
||||
}
|
||||
|
||||
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 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 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;
|
||||
}
|
||||
|
||||
} // namespace voxelman
|
74
meshers/cubic_mesher/old/sub_voxel_points.h
Normal file
74
meshers/cubic_mesher/old/sub_voxel_points.h
Normal file
@ -0,0 +1,74 @@
|
||||
#ifndef SUB_VOXEL_POINTS_H
|
||||
#define SUB_VOXEL_POINTS_H
|
||||
|
||||
#include "../collections/vector3i.h"
|
||||
#include "core/vector.h"
|
||||
#include "sub_voxel_points_helper.h"
|
||||
#include "sub_voxel_side_points.h"
|
||||
#include "voxel.h"
|
||||
#include "voxel_data.h"
|
||||
|
||||
using namespace voxelman;
|
||||
|
||||
namespace voxelman {
|
||||
|
||||
class Voxel;
|
||||
class VoxelData;
|
||||
|
||||
class SubVoxelPoints {
|
||||
public:
|
||||
enum SidePoints {
|
||||
P000 = 0,
|
||||
P100 = 1,
|
||||
P010 = 2,
|
||||
P001 = 3,
|
||||
P110 = 4,
|
||||
P011 = 5,
|
||||
P101 = 6,
|
||||
P111 = 7,
|
||||
};
|
||||
|
||||
enum Points {
|
||||
POINT_COUNT = 8,
|
||||
};
|
||||
|
||||
Vector3i get_point(int index);
|
||||
SubVoxelPoints(Voxel *voxel);
|
||||
~SubVoxelPoints();
|
||||
|
||||
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);
|
||||
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 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);
|
||||
int get_opposite_face(int face);
|
||||
|
||||
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
|
||||
};
|
||||
|
||||
} // namespace voxelman
|
||||
|
||||
#endif
|
231
meshers/cubic_mesher/old/sub_voxel_points_helper.cpp
Normal file
231
meshers/cubic_mesher/old/sub_voxel_points_helper.cpp
Normal file
@ -0,0 +1,231 @@
|
||||
#include "sub_voxel_points_helper.h"
|
||||
|
||||
#if MEM_TOOLS
|
||||
int SubVoxelFacePointsHelper::allocs = 0;
|
||||
#endif
|
||||
|
||||
Vector2i SubVoxelFacePointsHelper::gettlv2() {
|
||||
return SubVoxelFacePointsHelper::transform_to_vector2i(_face, _tl);
|
||||
}
|
||||
|
||||
Vector2i SubVoxelFacePointsHelper::gettrv2() {
|
||||
return SubVoxelFacePointsHelper::transform_to_vector2i(_face, _tr);
|
||||
}
|
||||
|
||||
Vector2i SubVoxelFacePointsHelper::getblv2() {
|
||||
return SubVoxelFacePointsHelper::transform_to_vector2i(_face, _bl);
|
||||
}
|
||||
|
||||
Vector2i SubVoxelFacePointsHelper::getbrv2() {
|
||||
return SubVoxelFacePointsHelper::transform_to_vector2i(_face, _br);
|
||||
}
|
||||
|
||||
int SubVoxelFacePointsHelper::gettl_depth() {
|
||||
return SubVoxelFacePointsHelper::get_depth(_face, _tl);
|
||||
}
|
||||
|
||||
int SubVoxelFacePointsHelper::gettr_depth() {
|
||||
return SubVoxelFacePointsHelper::get_depth(_face, _tr);
|
||||
}
|
||||
|
||||
int SubVoxelFacePointsHelper::getbl_depth() {
|
||||
return SubVoxelFacePointsHelper::get_depth(_face, _bl);
|
||||
}
|
||||
|
||||
int SubVoxelFacePointsHelper::getbr_depth() {
|
||||
return SubVoxelFacePointsHelper::get_depth(_face, _br);
|
||||
}
|
||||
|
||||
SubVoxelFacePointsHelper::SubVoxelFacePointsHelper(int face, SubVoxelPoints *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) {
|
||||
_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));
|
||||
}
|
||||
|
||||
bool SubVoxelFacePointsHelper::is_face_fully_covered() {
|
||||
if (!is_face_near_the_edges()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Vector2i tlv = gettlv2();
|
||||
if ((tlv.x != 0) || (tlv.y != 255)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Vector2i trv = gettrv2();
|
||||
if ((trv.x != 255) || (trv.y != 255)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Vector2i blv = getblv2();
|
||||
if ((blv.x != 0) || (blv.y != 0)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Vector2i brv = getbrv2();
|
||||
return (brv.x == 255) && (brv.y == 0);
|
||||
}
|
||||
|
||||
bool SubVoxelFacePointsHelper::is_face_near_the_edges() {
|
||||
if (_face == VoxelFace::VOXEL_FACE_FRONT) {
|
||||
if (gettl_depth() == 0 && gettr_depth() == 0 && getbl_depth() == 0 && getbr_depth() == 0) {
|
||||
return true;
|
||||
}
|
||||
} else if (_face == VoxelFace::VOXEL_FACE_BACK) {
|
||||
if (gettl_depth() == 255 && gettr_depth() == 255 && getbl_depth() == 255 && getbr_depth() == 255) {
|
||||
return true;
|
||||
}
|
||||
} else if (_face == VoxelFace::VOXEL_FACE_RIGHT) {
|
||||
if (gettl_depth() == 255 && gettr_depth() == 255 && getbl_depth() == 255 && getbr_depth() == 255) {
|
||||
return true;
|
||||
}
|
||||
} else if (_face == VoxelFace::VOXEL_FACE_LEFT) {
|
||||
if (gettl_depth() == 0 && gettr_depth() == 0 && getbl_depth() == 0 && getbr_depth() == 0) {
|
||||
return true;
|
||||
}
|
||||
} else if (_face == VoxelFace::VOXEL_FACE_TOP) {
|
||||
if (gettl_depth() == 255 && gettr_depth() == 255 && getbl_depth() == 255 && getbr_depth() == 255) {
|
||||
return true;
|
||||
}
|
||||
} else if (_face == VoxelFace::VOXEL_FACE_DOWN) {
|
||||
if (gettl_depth() == 0 && gettr_depth() == 0 && getbl_depth() == 0 && getbr_depth() == 0) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool SubVoxelFacePointsHelper::is_face_visible_against(SubVoxelFacePointsHelper *other) {
|
||||
if (!is_face_near_the_edges() || !other->is_face_near_the_edges()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
Vector2i tlv = gettlv2();
|
||||
Vector2i tlv2 = other->gettlv2();
|
||||
|
||||
if ((tlv.x < tlv2.x) || (tlv.y > tlv2.y)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
Vector2i trv = gettrv2();
|
||||
Vector2i trv2 = other->gettrv2();
|
||||
|
||||
if ((trv.x > trv2.x) || (trv.y > trv2.y)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
Vector2i blv = getblv2();
|
||||
Vector2i blv2 = other->getblv2();
|
||||
|
||||
if ((blv.x < blv2.x) || (blv.y < blv2.y)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
Vector2i brv = getbrv2();
|
||||
Vector2i brv2 = other->getbrv2();
|
||||
|
||||
return (brv.x > brv2.x) || (brv.y < brv2.y);
|
||||
}
|
||||
|
||||
bool SubVoxelFacePointsHelper::is_face_visible_against(SubVoxelFacePointsHelper other) {
|
||||
if (!is_face_near_the_edges() || !other.is_face_near_the_edges()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
Vector2i tlv = gettlv2();
|
||||
Vector2i tlv2 = other.gettlv2();
|
||||
|
||||
if ((tlv.x < tlv2.x) || (tlv.y > tlv2.y)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
Vector2i trv = gettrv2();
|
||||
Vector2i trv2 = other.gettrv2();
|
||||
|
||||
if ((trv.x > trv2.x) || (trv.y > trv2.y)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
Vector2i blv = getblv2();
|
||||
Vector2i blv2 = other.getblv2();
|
||||
|
||||
if ((blv.x < blv2.x) || (blv.y < blv2.y)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
Vector2i brv = getbrv2();
|
||||
Vector2i brv2 = other.getbrv2();
|
||||
|
||||
return (brv.x > brv2.x) || (brv.y < brv2.y);
|
||||
}
|
||||
|
||||
int SubVoxelFacePointsHelper::get_depth(int face, Vector3i v3) {
|
||||
if (face == VoxelFace::VOXEL_FACE_BACK) {
|
||||
return v3.z;
|
||||
}
|
||||
if (face == VoxelFace::VOXEL_FACE_FRONT) {
|
||||
return v3.z;
|
||||
}
|
||||
if (face == VoxelFace::VOXEL_FACE_RIGHT) {
|
||||
return v3.x;
|
||||
}
|
||||
if (face == VoxelFace::VOXEL_FACE_LEFT) {
|
||||
return v3.x;
|
||||
}
|
||||
if (face == VoxelFace::VOXEL_FACE_TOP) {
|
||||
return v3.y;
|
||||
}
|
||||
if (face == VoxelFace::VOXEL_FACE_DOWN) {
|
||||
return v3.y;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
Vector2i SubVoxelFacePointsHelper::transform_to_vector2i(int face, Vector3i v3) {
|
||||
Vector2i result;
|
||||
if (face == VoxelFace::VOXEL_FACE_BACK) {
|
||||
result = Vector2i(v3.x, v3.y);
|
||||
} else if (face == VoxelFace::VOXEL_FACE_FRONT) {
|
||||
result = Vector2i(v3.x, v3.y);
|
||||
} else if (face == VoxelFace::VOXEL_FACE_RIGHT) {
|
||||
result = Vector2i(v3.y, v3.z);
|
||||
} else if (face == VoxelFace::VOXEL_FACE_LEFT) {
|
||||
result = Vector2i(v3.y, v3.z);
|
||||
} else if (face == VoxelFace::VOXEL_FACE_TOP) {
|
||||
result = Vector2i(v3.x, v3.z);
|
||||
} else if (face == VoxelFace::VOXEL_FACE_DOWN) {
|
||||
result = Vector2i(v3.x, v3.z);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
bool SubVoxelFacePointsHelper::equals(SubVoxelFacePointsHelper *other) {
|
||||
return ((((_tl == other->_tl) && (_tr == other->_tr)) && (_bl == other->_bl)) && (_br == other->_br)) && (_face == other->_face);
|
||||
}
|
||||
|
||||
int SubVoxelFacePointsHelper::get_hash_code() {
|
||||
//return ((((_tl->get_hash_code() / 100000) + (_tr->get_hash_code() / 100000)) + (_bl->get_hash_code() / 100000)) + (_br->get_hash_code() / 100000)) + _face;
|
||||
|
||||
return 123;
|
||||
}
|
60
meshers/cubic_mesher/old/sub_voxel_points_helper.h
Normal file
60
meshers/cubic_mesher/old/sub_voxel_points_helper.h
Normal file
@ -0,0 +1,60 @@
|
||||
#ifndef SUB_VOXEL_FACE_POINTS_HELPER_H
|
||||
#define SUB_VOXEL_FACE_POINTS_HELPER_H
|
||||
|
||||
#include "../collections/vector3i.h"
|
||||
#include "core/math/vector2.h"
|
||||
#include "core/vector.h"
|
||||
#include "sub_voxel_points.h"
|
||||
#include "voxel_face.h"
|
||||
|
||||
using namespace voxelman;
|
||||
|
||||
namespace voxelman {
|
||||
|
||||
class SubVoxelPoints;
|
||||
|
||||
class SubVoxelFacePointsHelper {
|
||||
|
||||
public:
|
||||
Vector2i gettlv2();
|
||||
Vector2i gettrv2();
|
||||
Vector2i getblv2();
|
||||
Vector2i getbrv2();
|
||||
|
||||
int gettl_depth();
|
||||
int gettr_depth();
|
||||
int getbl_depth();
|
||||
int getbr_depth();
|
||||
|
||||
SubVoxelFacePointsHelper(int face, SubVoxelPoints *points);
|
||||
~SubVoxelFacePointsHelper();
|
||||
|
||||
void set_sub_voxel_points(int face, SubVoxelPoints *points);
|
||||
bool is_face_fully_covered();
|
||||
bool is_face_near_the_edges();
|
||||
bool is_face_visible_against(SubVoxelFacePointsHelper *other);
|
||||
bool is_face_visible_against(SubVoxelFacePointsHelper other);
|
||||
static int get_depth(int face, Vector3i v3);
|
||||
static Vector2i transform_to_vector2i(int face, Vector3i v3);
|
||||
|
||||
bool equals(SubVoxelFacePointsHelper *other);
|
||||
|
||||
int get_hash_code();
|
||||
|
||||
private:
|
||||
int _size;
|
||||
int _face;
|
||||
|
||||
Vector3i _tl;
|
||||
Vector3i _tr;
|
||||
Vector3i _bl;
|
||||
Vector3i _br;
|
||||
|
||||
#if MEM_TOOLS
|
||||
static int allocs;
|
||||
#endif
|
||||
};
|
||||
|
||||
} // namespace voxelman
|
||||
|
||||
#endif
|
73
meshers/cubic_mesher/old/sub_voxel_side_points.cpp
Normal file
73
meshers/cubic_mesher/old/sub_voxel_side_points.cpp
Normal file
@ -0,0 +1,73 @@
|
||||
#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) {
|
||||
for (int i = 0; i < _points.size(); ++i) {
|
||||
if (_points.get(i) == point) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool SubVoxelSidePoints::is_sub_voxel_point(int x, int y, int z) {
|
||||
return is_sub_voxel_point(Vector3i(x, y, z));
|
||||
/*
|
||||
for (int i = 0; i < points->Length; i += 1) {
|
||||
if (points.get(i).Equals(x, y, z)) {
|
||||
return true;
|
||||
}
|
||||
}*/
|
||||
//return false;
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
return b;
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
float num = (float)255;
|
||||
float num2 = num / (float)2;
|
||||
vector.x -= num2;
|
||||
vector.y -= num2;
|
||||
vector.z -= num2;
|
||||
vector /= num;
|
||||
return vector;
|
||||
}
|
34
meshers/cubic_mesher/old/sub_voxel_side_points.h
Normal file
34
meshers/cubic_mesher/old/sub_voxel_side_points.h
Normal file
@ -0,0 +1,34 @@
|
||||
#ifndef SUB_VOXEL_SIDE_POINTS_H
|
||||
#define SUB_VOXEL_SIDE_POINTS_H
|
||||
|
||||
#include "core/object.h"
|
||||
#include "../collections/vector3i.h"
|
||||
#include "core/vector.h"
|
||||
|
||||
namespace voxelman {
|
||||
|
||||
class SubVoxelSidePoints {
|
||||
|
||||
public:
|
||||
Vector3i get_point(int index) { return _points[index]; }
|
||||
void set_point(int index, Vector3i point) { _points.set(index, point); }
|
||||
int get_point_count() { return _points.size(); }
|
||||
|
||||
bool is_sub_voxel_point(Vector3i point);
|
||||
bool is_sub_voxel_point(int x, int y, int z);
|
||||
Vector3 get_vector3_for_point(int pointIndex);
|
||||
Vector3 get_vertex_vector3_for_point(int pointIndex);
|
||||
SubVoxelSidePoints();
|
||||
~SubVoxelSidePoints();
|
||||
|
||||
private:
|
||||
Vector<Vector3i> _points;
|
||||
|
||||
#if MEM_TOOLS
|
||||
static int allocs;
|
||||
#endif
|
||||
};
|
||||
|
||||
} // namespace voxelman
|
||||
|
||||
#endif
|
35
meshers/cubic_mesher/old/voxel.cpp
Normal file
35
meshers/cubic_mesher/old/voxel.cpp
Normal file
@ -0,0 +1,35 @@
|
||||
#include "voxel.h"
|
||||
|
||||
|
||||
int Voxel::get_neighbours() {
|
||||
return _neighbours;
|
||||
}
|
||||
|
||||
void Voxel::set_neighbours(int value) {
|
||||
_neighbours = value;
|
||||
}
|
||||
|
||||
bool Voxel::get_has_sub_voxel_points() {
|
||||
return _sub_voxel_points != NULL;
|
||||
}
|
||||
|
||||
SubVoxelPoints *Voxel::get_sub_voxel_points() {
|
||||
return _sub_voxel_points;
|
||||
}
|
||||
|
||||
Voxel::Voxel() {
|
||||
_sub_voxel_points = NULL;
|
||||
|
||||
}
|
||||
|
||||
void Voxel::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 (_sub_voxel_points == NULL) {
|
||||
_sub_voxel_points = memnew(SubVoxelPoints(this));
|
||||
}
|
||||
|
||||
_sub_voxel_points->set_voxel_datas(VP000, VP100, VP010, VP001, VP110, VP011, VP101, VP111);
|
||||
}
|
||||
|
||||
void Voxel::refresh_sub_voxel_points() {
|
||||
get_sub_voxel_points()->refresh_points();
|
||||
}
|
89
meshers/cubic_mesher/old/voxel.h
Normal file
89
meshers/cubic_mesher/old/voxel.h
Normal file
@ -0,0 +1,89 @@
|
||||
#ifndef VOXEL_H
|
||||
#define VOXEL_H
|
||||
|
||||
#include "core/reference.h"
|
||||
#include "../collections/vector3i.h"
|
||||
#include "core/math/quat.h"
|
||||
#include "core/resource.h"
|
||||
#include "core/vector.h"
|
||||
#include "sub_voxel_points.h"
|
||||
#include "voxel_data.h"
|
||||
#include "voxel_enums.h"
|
||||
#include "voxel_face.h"
|
||||
|
||||
#include "../library/voxel_surface_definition.h"
|
||||
|
||||
using namespace voxelman;
|
||||
|
||||
namespace voxelman {
|
||||
|
||||
class SubVoxelPoints;
|
||||
|
||||
class Voxel : public Reference {
|
||||
GDCLASS(Voxel, Reference);
|
||||
|
||||
public:
|
||||
enum VoxelNeighbours {
|
||||
NEIGHBOUR_NONE = 0,
|
||||
|
||||
NEIGHBOUR_LEFT = 1 << 0,
|
||||
NEIGHBOUR_RIGHT = 1 << 1,
|
||||
NEIGHBOUR_FRONT = 1 << 2,
|
||||
NEIGHBOUR_BACK = 1 << 3,
|
||||
NEIGHBOUR_TOP = 1 << 4,
|
||||
NEIGHBOUR_DOWN = 1 << 5,
|
||||
|
||||
NEIGHBOUR_LEFT_FRONT = 1 << 6,
|
||||
NEIGHBOUR_LEFT_BACK = 1 << 7,
|
||||
NEIGHBOUR_RIGHT_FRONT = 1 << 8,
|
||||
NEIGHBOUR_RIGHT_BACK = 1 << 9,
|
||||
|
||||
NEIGHBOUR_TOP_LEFT = 1 << 10,
|
||||
NEIGHBOUR_TOP_RIGHT = 1 << 11,
|
||||
NEIGHBOUR_TOP_FRONT = 1 << 12,
|
||||
NEIGHBOUR_TOP_BACK = 1 << 13,
|
||||
|
||||
NEIGHBOUR_BOTTOM_LEFT = 1 << 14,
|
||||
NEIGHBOUR_BOTTOM_RIGHT = 1 << 15,
|
||||
NEIGHBOUR_BOTTOM_FRONT = 1 << 16,
|
||||
NEIGHBOUR_BOTTOM_BACK = 1 << 17,
|
||||
|
||||
NEIGHBOUR_BOTTOM_LEFT_FRONT = 1 << 18,
|
||||
NEIGHBOUR_BOTTOM_LEFT_BACK = 1 << 19,
|
||||
NEIGHBOUR_BOTTOM_RIGHT_FRONT = 1 << 20,
|
||||
NEIGHBOUR_BOTTOM_RIGHT_BACK = 1 << 21,
|
||||
|
||||
NEIGHBOUR_TOP_LEFT_FRONT = 1 << 22,
|
||||
NEIGHBOUR_TOP_LEFT_BACK = 1 << 23,
|
||||
NEIGHBOUR_TOP_RIGHT_FRONT = 1 << 24,
|
||||
NEIGHBOUR_TOP_RIGHT_BACK = 1 << 25,
|
||||
|
||||
|
||||
FULL_NEIGHBOURS_CROSS = NEIGHBOUR_LEFT | NEIGHBOUR_RIGHT | NEIGHBOUR_BACK | NEIGHBOUR_FRONT | NEIGHBOUR_TOP | NEIGHBOUR_DOWN, // | NEIGHBOUR_LEFT_BACK | NEIGHBOUR_LEFT_FRONT | NEIGHBOUR_RIGHT_BACK | NEIGHBOUR_RIGHT_FRONT;
|
||||
FULL_SIDE_NEIGHBOURS = NEIGHBOUR_LEFT | NEIGHBOUR_RIGHT | NEIGHBOUR_BACK | NEIGHBOUR_FRONT,
|
||||
FULL_SIDE_NEIGHBOURS_TOP = NEIGHBOUR_LEFT | NEIGHBOUR_RIGHT | NEIGHBOUR_BACK | NEIGHBOUR_FRONT | NEIGHBOUR_TOP,
|
||||
FULL_SIDE_NEIGHBOURS_DOWN = NEIGHBOUR_LEFT | NEIGHBOUR_RIGHT | NEIGHBOUR_BACK | NEIGHBOUR_FRONT | NEIGHBOUR_DOWN,
|
||||
};
|
||||
|
||||
static const unsigned int FACE_COUNT = 6;
|
||||
|
||||
int get_neighbours();
|
||||
void set_neighbours(int value);
|
||||
|
||||
bool get_has_sub_voxel_points();
|
||||
SubVoxelPoints *get_sub_voxel_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);
|
||||
void refresh_sub_voxel_points();
|
||||
|
||||
protected:
|
||||
static void _bind_methods() {}
|
||||
|
||||
private:
|
||||
int _neighbours;
|
||||
SubVoxelPoints *_sub_voxel_points;
|
||||
};
|
||||
|
||||
} // namespace voxelman
|
||||
|
||||
#endif
|
435
meshers/cubic_mesher/voxel_cube_points.cpp
Normal file
435
meshers/cubic_mesher/voxel_cube_points.cpp
Normal file
@ -0,0 +1,435 @@
|
||||
#include "sub_voxel_points.h"
|
||||
|
||||
namespace voxelman {
|
||||
|
||||
#if MEM_TOOLS
|
||||
int SubVoxelPoints::allocs = 0;
|
||||
#endif
|
||||
|
||||
Vector3i SubVoxelPoints::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
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
void SubVoxelPoints::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);
|
||||
|
||||
//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);
|
||||
|
||||
//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);
|
||||
|
||||
//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);
|
||||
|
||||
//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);
|
||||
|
||||
//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);
|
||||
|
||||
//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);
|
||||
|
||||
//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);
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
if (tVoxelData != NULL) {
|
||||
fill = tVoxelData->get_fill();
|
||||
}
|
||||
|
||||
Vector3i vector3i = Vector3i(vectx, vecty, vectz);
|
||||
if ((tVoxelData->get_neighbours() & axisx) != axisx) {
|
||||
if (vectx == 0) {
|
||||
vector3i.x = (int)(128 - fill);
|
||||
} else {
|
||||
vector3i.x = (int)(fill + 128);
|
||||
}
|
||||
}
|
||||
|
||||
if ((tVoxelData->get_neighbours() & axisy) != axisy) {
|
||||
if (vecty == 0) {
|
||||
vector3i.y = (int)(128 - fill);
|
||||
} else {
|
||||
vector3i.y = (int)(fill + 128);
|
||||
}
|
||||
}
|
||||
|
||||
if ((tVoxelData->get_neighbours() & axisz) != axisz) {
|
||||
if (vectz == 0) {
|
||||
vector3i.z = (int)(128 - fill);
|
||||
} else {
|
||||
vector3i.z = (int)(fill + 128);
|
||||
}
|
||||
}
|
||||
|
||||
_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) {
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
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));
|
||||
}
|
||||
|
||||
return _face_helper;
|
||||
}
|
||||
|
||||
bool SubVoxelPoints::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) {
|
||||
|
||||
SubVoxelFacePointsHelper avp(face, this);
|
||||
|
||||
return !avp.is_face_near_the_edges();
|
||||
}
|
||||
|
||||
bool SubVoxelPoints::face_should_be_visible_against(int face, SubVoxelPoints *other) {
|
||||
SubVoxelFacePointsHelper avp(face, this);
|
||||
|
||||
SubVoxelFacePointsHelper other2(get_opposite_face(face), other);
|
||||
|
||||
return avp.is_face_visible_against(other2);
|
||||
}
|
||||
|
||||
bool SubVoxelPoints::is_sub_voxel_point(Vector3i point) {
|
||||
for (int i = 0; i < POINT_COUNT; i += 1) {
|
||||
if (get_point(i) == (point)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool SubVoxelPoints::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;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void SubVoxelPoints::set_point(int point, int x, int y, int z) {
|
||||
_points[point] = Vector3i(x, y, z);
|
||||
}
|
||||
|
||||
int SubVoxelPoints::get_point_id(Vector3i point) {
|
||||
for (int i = 0; i < POINT_COUNT; ++i) {
|
||||
if (get_point(i) == point) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int SubVoxelPoints::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;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void SubVoxelPoints::copy_values_from(SubVoxelPoints *other) {
|
||||
for (int i = 0; i < POINT_COUNT; ++i) {
|
||||
_points[i] = other->get_point(i);
|
||||
}
|
||||
}
|
||||
|
||||
Vector3i SubVoxelPoints::get_top_left_point(int face, SubVoxelPoints *points) {
|
||||
if (face == VoxelFace::VOXEL_FACE_BACK) {
|
||||
return points->get_point(P011);
|
||||
}
|
||||
if (face == VoxelFace::VOXEL_FACE_FRONT) {
|
||||
return points->get_point(P010);
|
||||
}
|
||||
if (face == VoxelFace::VOXEL_FACE_RIGHT) {
|
||||
return points->get_point(P111);
|
||||
}
|
||||
if (face == VoxelFace::VOXEL_FACE_LEFT) {
|
||||
return points->get_point(P010);
|
||||
}
|
||||
if (face == VoxelFace::VOXEL_FACE_TOP) {
|
||||
return points->get_point(P010);
|
||||
}
|
||||
if (face == VoxelFace::VOXEL_FACE_DOWN) {
|
||||
return points->get_point(P000);
|
||||
}
|
||||
return points->get_point(0);
|
||||
}
|
||||
|
||||
Vector3i SubVoxelPoints::get_top_right_point(int face, SubVoxelPoints *points) {
|
||||
if (face == VoxelFace::VOXEL_FACE_BACK) {
|
||||
return points->get_point(P111);
|
||||
}
|
||||
if (face == VoxelFace::VOXEL_FACE_FRONT) {
|
||||
return points->get_point(P110);
|
||||
}
|
||||
if (face == VoxelFace::VOXEL_FACE_RIGHT) {
|
||||
return points->get_point(P110);
|
||||
}
|
||||
if (face == VoxelFace::VOXEL_FACE_LEFT) {
|
||||
return points->get_point(P011);
|
||||
}
|
||||
if (face == VoxelFace::VOXEL_FACE_TOP) {
|
||||
return points->get_point(P110);
|
||||
}
|
||||
if (face == VoxelFace::VOXEL_FACE_DOWN) {
|
||||
return points->get_point(P100);
|
||||
}
|
||||
return points->get_point(0);
|
||||
}
|
||||
|
||||
Vector3i SubVoxelPoints::get_bottom_left_point(int face, SubVoxelPoints *points) {
|
||||
if (face == VoxelFace::VOXEL_FACE_BACK) {
|
||||
return points->get_point(P001);
|
||||
}
|
||||
if (face == VoxelFace::VOXEL_FACE_FRONT) {
|
||||
return points->get_point(P000);
|
||||
}
|
||||
if (face == VoxelFace::VOXEL_FACE_RIGHT) {
|
||||
return points->get_point(P101);
|
||||
}
|
||||
if (face == VoxelFace::VOXEL_FACE_LEFT) {
|
||||
return points->get_point(P001);
|
||||
}
|
||||
if (face == VoxelFace::VOXEL_FACE_TOP) {
|
||||
return points->get_point(P011);
|
||||
}
|
||||
if (face == VoxelFace::VOXEL_FACE_DOWN) {
|
||||
return points->get_point(P001);
|
||||
}
|
||||
return points->get_point(0);
|
||||
}
|
||||
|
||||
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 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 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;
|
||||
}
|
||||
|
||||
} // namespace voxelman
|
74
meshers/cubic_mesher/voxel_cube_points.h
Normal file
74
meshers/cubic_mesher/voxel_cube_points.h
Normal file
@ -0,0 +1,74 @@
|
||||
#ifndef SUB_VOXEL_POINTS_H
|
||||
#define SUB_VOXEL_POINTS_H
|
||||
|
||||
#include "../collections/vector3i.h"
|
||||
#include "core/vector.h"
|
||||
#include "sub_voxel_points_helper.h"
|
||||
#include "sub_voxel_side_points.h"
|
||||
#include "voxel.h"
|
||||
#include "voxel_data.h"
|
||||
|
||||
using namespace voxelman;
|
||||
|
||||
namespace voxelman {
|
||||
|
||||
class Voxel;
|
||||
class VoxelData;
|
||||
|
||||
class SubVoxelPoints {
|
||||
public:
|
||||
enum SidePoints {
|
||||
P000 = 0,
|
||||
P100 = 1,
|
||||
P010 = 2,
|
||||
P001 = 3,
|
||||
P110 = 4,
|
||||
P011 = 5,
|
||||
P101 = 6,
|
||||
P111 = 7,
|
||||
};
|
||||
|
||||
enum Points {
|
||||
POINT_COUNT = 8,
|
||||
};
|
||||
|
||||
Vector3i get_point(int index);
|
||||
SubVoxelPoints(Voxel *voxel);
|
||||
~SubVoxelPoints();
|
||||
|
||||
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);
|
||||
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 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);
|
||||
int get_opposite_face(int face);
|
||||
|
||||
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
|
||||
};
|
||||
|
||||
} // namespace voxelman
|
||||
|
||||
#endif
|
10
meshers/cubic_mesher/voxel_mesher_cubic.cpp
Normal file
10
meshers/cubic_mesher/voxel_mesher_cubic.cpp
Normal file
@ -0,0 +1,10 @@
|
||||
#include "voxel_mesher_cubic.h"
|
||||
|
||||
|
||||
VoxelMesherCubic::VoxelMesherCubic() {
|
||||
}
|
||||
|
||||
|
||||
void VoxelMesherCubic::_bind_methods() {
|
||||
|
||||
}
|
17
meshers/cubic_mesher/voxel_mesher_cubic.h
Normal file
17
meshers/cubic_mesher/voxel_mesher_cubic.h
Normal file
@ -0,0 +1,17 @@
|
||||
#ifndef VOXEL_MESHER_CUBIC_H
|
||||
#define VOXEL_MESHER_CUBIC_H
|
||||
|
||||
#include "../voxel_mesher.h"
|
||||
|
||||
class VoxelMesherCubic : public VoxelMesher {
|
||||
GDCLASS(VoxelMesherCubic, VoxelMesher);
|
||||
|
||||
public:
|
||||
VoxelMesherCubic();
|
||||
|
||||
protected:
|
||||
static void _bind_methods();
|
||||
|
||||
};
|
||||
|
||||
#endif
|
@ -12,6 +12,8 @@
|
||||
#include "world/voxel_world.h"
|
||||
#include "world/voxel_chunk.h"
|
||||
|
||||
#include "meshers/cubic_mesher/voxel_mesher_cubic.h"
|
||||
|
||||
void register_voxelman_types() {
|
||||
ClassDB::register_class<VoxelMesher>();
|
||||
ClassDB::register_class<VoxelMesherTransvoxel>();
|
||||
@ -27,6 +29,8 @@ void register_voxelman_types() {
|
||||
ClassDB::register_class<VoxelBuffer>();
|
||||
ClassDB::register_class<VoxelWorld>();
|
||||
ClassDB::register_class<VoxelChunk>();
|
||||
|
||||
ClassDB::register_class<VoxelMesherCubic>();
|
||||
}
|
||||
|
||||
void unregister_voxelman_types() {
|
||||
|
Loading…
Reference in New Issue
Block a user