Fixed compile, and created the bindings for the new classes.

This commit is contained in:
Relintai 2019-07-15 02:18:51 +02:00
parent 9a84ab8500
commit 79d54238c3
8 changed files with 384 additions and 83 deletions

1
SCsub
View File

@ -22,3 +22,4 @@ 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")
env.add_source_files(env.modules_sources,"meshers/cubic_mesher/sub_voxel_face_points_helper.cpp")

View File

@ -1,21 +1,35 @@
#include "sub_voxel_face_points_helper.h"
#include "voxel_cube_points.h"
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);
}
Vector2 SubVoxelFacePointsHelper::gettlv2_bind() {
return SubVoxelFacePointsHelper::transform_to_vector2(_face, _tl.to_vec3());
}
Vector2 SubVoxelFacePointsHelper::gettrv2_bind() {
return SubVoxelFacePointsHelper::transform_to_vector2(_face, _tr.to_vec3());
}
Vector2 SubVoxelFacePointsHelper::getblv2_bind() {
return SubVoxelFacePointsHelper::transform_to_vector2(_face, _bl.to_vec3());
}
Vector2 SubVoxelFacePointsHelper::getbrv2_bind() {
return SubVoxelFacePointsHelper::transform_to_vector2(_face, _br.to_vec3());
}
int SubVoxelFacePointsHelper::gettl_depth() {
return SubVoxelFacePointsHelper::get_depth(_face, _tl);
}
@ -32,20 +46,18 @@ int SubVoxelFacePointsHelper::getbr_depth() {
return SubVoxelFacePointsHelper::get_depth(_face, _br);
}
SubVoxelFacePointsHelper::SubVoxelFacePointsHelper(int face, VoxelCubePoints *points) {
_size = 255;
set_sub_voxel_points(face, points);
SubVoxelFacePointsHelper::SubVoxelFacePointsHelper() {
}
SubVoxelFacePointsHelper::~SubVoxelFacePointsHelper() {
}
void SubVoxelFacePointsHelper::set_sub_voxel_points(int face, VoxelCubePoints *points) {
void SubVoxelFacePointsHelper::set_sub_voxel_points(int face, Ref<VoxelCubePoints> points) {
_face = face;
_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));
_tl = Vector3i(points->get_top_left_point(face));
_tr = Vector3i(points->get_top_right_point(face));
_bl = Vector3i(points->get_bottom_left_point(face));
_br = Vector3i(points->get_bottom_right_point(face));
}
bool SubVoxelFacePointsHelper::is_face_fully_covered() {
@ -73,27 +85,27 @@ bool SubVoxelFacePointsHelper::is_face_fully_covered() {
}
bool SubVoxelFacePointsHelper::is_face_near_the_edges() {
if (_face == VoxelFace::VOXEL_FACE_FRONT) {
if (_face == VoxelCubePoints::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) {
} else if (_face == VoxelCubePoints::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) {
} else if (_face == VoxelCubePoints::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) {
} else if (_face == VoxelCubePoints::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) {
} else if (_face == VoxelCubePoints::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) {
} else if (_face == VoxelCubePoints::VOXEL_FACE_BOTTOM) {
if (gettl_depth() == 0 && gettr_depth() == 0 && getbl_depth() == 0 && getbr_depth() == 0) {
return true;
}
@ -102,7 +114,7 @@ bool SubVoxelFacePointsHelper::is_face_near_the_edges() {
return false;
}
bool SubVoxelFacePointsHelper::is_face_visible_against(SubVoxelFacePointsHelper *other) {
bool SubVoxelFacePointsHelper::is_face_visible_against(Ref<SubVoxelFacePointsHelper> other) {
if (!is_face_near_the_edges() || !other->is_face_near_the_edges()) {
return true;
}
@ -133,8 +145,8 @@ bool SubVoxelFacePointsHelper::is_face_visible_against(SubVoxelFacePointsHelper
return (brv.x > brv2.x) || (brv.y < brv2.y);
}
bool SubVoxelFacePointsHelper::is_face_visible_against(SubVoxelFacePointsHelper other) {
/*
bool SubVoxelFacePointsHelper::is_face_visible_against(Ref<SubVoxelFacePointsHelper> other) {
if (!is_face_near_the_edges() || !other.is_face_near_the_edges()) {
return true;
}
@ -165,24 +177,46 @@ bool SubVoxelFacePointsHelper::is_face_visible_against(SubVoxelFacePointsHelper
return (brv.x > brv2.x) || (brv.y < brv2.y);
}
*/
int SubVoxelFacePointsHelper::get_depth(int face, Vector3i v3) {
if (face == VoxelFace::VOXEL_FACE_BACK) {
if (face == VoxelCubePoints::VOXEL_FACE_BACK) {
return v3.z;
}
if (face == VoxelFace::VOXEL_FACE_FRONT) {
if (face == VoxelCubePoints::VOXEL_FACE_FRONT) {
return v3.z;
}
if (face == VoxelFace::VOXEL_FACE_RIGHT) {
if (face == VoxelCubePoints::VOXEL_FACE_RIGHT) {
return v3.x;
}
if (face == VoxelFace::VOXEL_FACE_LEFT) {
if (face == VoxelCubePoints::VOXEL_FACE_LEFT) {
return v3.x;
}
if (face == VoxelFace::VOXEL_FACE_TOP) {
if (face == VoxelCubePoints::VOXEL_FACE_TOP) {
return v3.y;
}
if (face == VoxelFace::VOXEL_FACE_DOWN) {
if (face == VoxelCubePoints::VOXEL_FACE_BOTTOM) {
return v3.y;
}
return 0;
}
int SubVoxelFacePointsHelper::get_depth_bind(int face, Vector3 v3) {
if (face == VoxelCubePoints::VOXEL_FACE_BACK) {
return v3.z;
}
if (face == VoxelCubePoints::VOXEL_FACE_FRONT) {
return v3.z;
}
if (face == VoxelCubePoints::VOXEL_FACE_RIGHT) {
return v3.x;
}
if (face == VoxelCubePoints::VOXEL_FACE_LEFT) {
return v3.x;
}
if (face == VoxelCubePoints::VOXEL_FACE_TOP) {
return v3.y;
}
if (face == VoxelCubePoints::VOXEL_FACE_BOTTOM) {
return v3.y;
}
return 0;
@ -190,24 +224,43 @@ int SubVoxelFacePointsHelper::get_depth(int face, Vector3i v3) {
Vector2i SubVoxelFacePointsHelper::transform_to_vector2i(int face, Vector3i v3) {
Vector2i result;
if (face == VoxelFace::VOXEL_FACE_BACK) {
if (face == VoxelCubePoints::VOXEL_FACE_BACK) {
result = Vector2i(v3.x, v3.y);
} else if (face == VoxelFace::VOXEL_FACE_FRONT) {
} else if (face == VoxelCubePoints::VOXEL_FACE_FRONT) {
result = Vector2i(v3.x, v3.y);
} else if (face == VoxelFace::VOXEL_FACE_RIGHT) {
} else if (face == VoxelCubePoints::VOXEL_FACE_RIGHT) {
result = Vector2i(v3.y, v3.z);
} else if (face == VoxelFace::VOXEL_FACE_LEFT) {
} else if (face == VoxelCubePoints::VOXEL_FACE_LEFT) {
result = Vector2i(v3.y, v3.z);
} else if (face == VoxelFace::VOXEL_FACE_TOP) {
} else if (face == VoxelCubePoints::VOXEL_FACE_TOP) {
result = Vector2i(v3.x, v3.z);
} else if (face == VoxelFace::VOXEL_FACE_DOWN) {
} else if (face == VoxelCubePoints::VOXEL_FACE_BOTTOM) {
result = Vector2i(v3.x, v3.z);
}
return result;
}
bool SubVoxelFacePointsHelper::equals(SubVoxelFacePointsHelper *other) {
Vector2 SubVoxelFacePointsHelper::transform_to_vector2(int face, Vector3 v3) {
Vector2 result;
if (face == VoxelCubePoints::VOXEL_FACE_BACK) {
result = Vector2(v3.x, v3.y);
} else if (face == VoxelCubePoints::VOXEL_FACE_FRONT) {
result = Vector2(v3.x, v3.y);
} else if (face == VoxelCubePoints::VOXEL_FACE_RIGHT) {
result = Vector2(v3.y, v3.z);
} else if (face == VoxelCubePoints::VOXEL_FACE_LEFT) {
result = Vector2(v3.y, v3.z);
} else if (face == VoxelCubePoints::VOXEL_FACE_TOP) {
result = Vector2(v3.x, v3.z);
} else if (face == VoxelCubePoints::VOXEL_FACE_BOTTOM) {
result = Vector2(v3.x, v3.z);
}
return result;
}
bool SubVoxelFacePointsHelper::equals(Ref<SubVoxelFacePointsHelper> other) {
return ((((_tl == other->_tl) && (_tr == other->_tr)) && (_bl == other->_bl)) && (_br == other->_br)) && (_face == other->_face);
}
@ -216,3 +269,25 @@ int SubVoxelFacePointsHelper::get_hash_code() {
return 123;
}
void SubVoxelFacePointsHelper::_bind_methods() {
ClassDB::bind_method(D_METHOD("gettlv2"), &SubVoxelFacePointsHelper::gettlv2_bind);
ClassDB::bind_method(D_METHOD("gettrv2"), &SubVoxelFacePointsHelper::gettrv2_bind);
ClassDB::bind_method(D_METHOD("getblv2"), &SubVoxelFacePointsHelper::getblv2_bind);
ClassDB::bind_method(D_METHOD("getbrv2"), &SubVoxelFacePointsHelper::getbrv2_bind);
ClassDB::bind_method(D_METHOD("gettl_depth"), &SubVoxelFacePointsHelper::gettl_depth);
ClassDB::bind_method(D_METHOD("gettr_depth"), &SubVoxelFacePointsHelper::gettr_depth);
ClassDB::bind_method(D_METHOD("getbl_depth"), &SubVoxelFacePointsHelper::getbl_depth);
ClassDB::bind_method(D_METHOD("getbr_depth"), &SubVoxelFacePointsHelper::getbr_depth);
ClassDB::bind_method(D_METHOD("set_sub_voxel_points", "face", "points"), &SubVoxelFacePointsHelper::set_sub_voxel_points);
ClassDB::bind_method(D_METHOD("is_face_fully_covered"), &SubVoxelFacePointsHelper::is_face_fully_covered);
ClassDB::bind_method(D_METHOD("is_face_near_the_edges"), &SubVoxelFacePointsHelper::is_face_near_the_edges);
ClassDB::bind_method(D_METHOD("is_face_visible_against", "other"), &SubVoxelFacePointsHelper::is_face_visible_against);
ClassDB::bind_method(D_METHOD("get_depth", "face", "v3"), &SubVoxelFacePointsHelper::get_depth_bind);
ClassDB::bind_method(D_METHOD("transform_to_vector2"), &SubVoxelFacePointsHelper::transform_to_vector2);
}

View File

@ -1,15 +1,15 @@
#ifndef SUB_VOXEL_FACE_POINTS_HELPER_H
#define SUB_VOXEL_FACE_POINTS_HELPER_H
#include "core/reference.h"
#include "../../math/vector3i.h"
#include "core/math/vector2.h"
#include "core/vector.h"
#include "voxel_cube_points.h"
class VoxelCubePoints;
class SubVoxelFacePointsHelper {
class SubVoxelFacePointsHelper : public Reference {
GDCLASS(SubVoxelFacePointsHelper, Reference);
public:
Vector2i gettlv2();
@ -17,28 +17,37 @@ public:
Vector2i getblv2();
Vector2i getbrv2();
Vector2 gettlv2_bind();
Vector2 gettrv2_bind();
Vector2 getblv2_bind();
Vector2 getbrv2_bind();
int gettl_depth();
int gettr_depth();
int getbl_depth();
int getbr_depth();
SubVoxelFacePointsHelper(int face, VoxelCubePoints *points);
~SubVoxelFacePointsHelper();
void set_sub_voxel_points(int face, VoxelCubePoints *points);
void set_sub_voxel_points(int face, Ref<VoxelCubePoints> 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 is_face_visible_against(Ref<SubVoxelFacePointsHelper> other);
//bool is_face_visible_against(Ref<SubVoxelFacePointsHelper> other);
int get_depth(int face, Vector3i v3);
int get_depth_bind(int face, Vector3 v3);
Vector2i transform_to_vector2i(int face, Vector3i v3);
Vector2 transform_to_vector2(int face, Vector3 v3);
bool equals(SubVoxelFacePointsHelper *other);
bool equals(Ref<SubVoxelFacePointsHelper> other);
int get_hash_code();
SubVoxelFacePointsHelper();
~SubVoxelFacePointsHelper();
protected:
static void _bind_methods();
private:
int _size;
int _face;
Vector3i _tl;

View File

@ -7,9 +7,9 @@ SubVoxelSidePoints::SubVoxelSidePoints() {
SubVoxelSidePoints::~SubVoxelSidePoints() {
}
bool SubVoxelSidePoints::is_sub_voxel_point(Vector3i point) {
for (int i = 0; i < _points.size(); ++i) {
if (_points.get(i) == point) {
bool SubVoxelSidePoints::is_sub_voxel_point_vec(Vector3i point) {
for (int i = 0; i < 4; ++i) {
if (_points[i] == point) {
return true;
}
}
@ -18,14 +18,12 @@ bool SubVoxelSidePoints::is_sub_voxel_point(Vector3i point) {
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)) {
for (int i = 0; i < 4; i += 1) {
if (_points[i].x == x && _points[i].y == y && _points[i].z == z) {
return true;
}
}*/
//return false;
}
return false;
}
Vector3 SubVoxelSidePoints::get_vector3_for_point(int index) {
@ -49,3 +47,13 @@ Vector3 SubVoxelSidePoints::get_vertex_vector3_for_point(int index) {
vector /= num;
return vector;
}
void SubVoxelSidePoints::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_point", "index"), &SubVoxelSidePoints::get_point_bind);
ClassDB::bind_method(D_METHOD("set_point", "index", "point"), &SubVoxelSidePoints::set_point_bind);
ClassDB::bind_method(D_METHOD("get_point_count"), &SubVoxelSidePoints::get_point_count);
ClassDB::bind_method(D_METHOD("is_sub_voxel_point", "x", "y", "z"), &SubVoxelSidePoints::is_sub_voxel_point);
ClassDB::bind_method(D_METHOD("get_vector3_for_point", "index"), &SubVoxelSidePoints::get_vector3_for_point);
ClassDB::bind_method(D_METHOD("get_vertex_vector3_for_point", "index"), &SubVoxelSidePoints::get_vertex_vector3_for_point);
}

View File

@ -1,8 +1,8 @@
#ifndef SUB_VOXEL_SIDE_POINTS_H
#define SUB_VOXEL_SIDE_POINTS_H
#include "core/reference.h"
#include "../../math/vector3i.h"
#include "core/reference.h"
#include "core/vector.h"
class SubVoxelSidePoints : public Reference {
@ -10,17 +10,24 @@ class SubVoxelSidePoints : public Reference {
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(); }
Vector3 get_point_bind(int index) { return _points[index].to_vec3(); }
void set_point(int index, Vector3i point) { _points[index] = point; }
void set_point_bind(int index, Vector3 point) { _points[index] = point; }
int get_point_count() { return 4; }
bool is_sub_voxel_point(Vector3i point);
bool is_sub_voxel_point_vec(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();
protected:
static void _bind_methods();
private:
Vector3i _points[4];
};

View File

@ -1,15 +1,33 @@
#include "voxel_cube_points.h"
Vector3i VoxelCubePoints::get_point(int index) {
return _points[index];
#include "sub_voxel_face_points_helper.h"
int VoxelCubePoints::get_x() {
return _x;
}
void VoxelCubePoints::set_x(int value) {
_x = value;
}
VoxelCubePoints::VoxelCubePoints() {
_face_helper.instance();
int VoxelCubePoints::get_y() {
return _y;
}
void VoxelCubePoints::set_y(int value) {
_y = value;
}
VoxelCubePoints::~VoxelCubePoints() {
_face_helper.unref();
int VoxelCubePoints::get_z() {
return _z;
}
void VoxelCubePoints::set_z(int value) {
_z = value;
}
int VoxelCubePoints::get_size() {
return _size;
}
void VoxelCubePoints::set_size(int value) {
_size = value;
}
void VoxelCubePoints::refresh_points() {
@ -169,27 +187,38 @@ Ref<SubVoxelSidePoints> VoxelCubePoints::get_points_for_face(int face) {
}
bool VoxelCubePoints::face_fully_covered(int face) {
SubVoxelFacePointsHelper avp(face, this);
Ref<SubVoxelFacePointsHelper> avp;
avp.instance();
return avp.is_face_fully_covered();
avp->set_sub_voxel_points(face, this);
return avp->is_face_fully_covered();
}
bool VoxelCubePoints::face_should_be_visible_against_full(int face) {
Ref<SubVoxelFacePointsHelper> avp;
avp.instance();
SubVoxelFacePointsHelper avp(face, this);
avp->set_sub_voxel_points(face, this);
return !avp.is_face_near_the_edges();
return !avp->is_face_near_the_edges();
}
bool VoxelCubePoints::face_should_be_visible_against(int face, Ref<VoxelCubePoints> other) {
SubVoxelFacePointsHelper avp(face, this);
Ref<SubVoxelFacePointsHelper> avp;
avp.instance();
SubVoxelFacePointsHelper other2(get_opposite_face(face), other);
avp->set_sub_voxel_points(face, this);
return avp.is_face_visible_against(other2);
Ref<SubVoxelFacePointsHelper> other2;
other2.instance();
other2->set_sub_voxel_points(get_opposite_face(face), other);
return avp->is_face_visible_against(other2);
}
bool VoxelCubePoints::is_sub_voxel_point(Vector3i point) {
bool VoxelCubePoints::is_sub_voxel_point_vec(Vector3i point) {
for (int i = 0; i < POINT_COUNT; i += 1) {
if (get_point(i) == (point)) {
return true;
@ -211,7 +240,7 @@ void VoxelCubePoints::set_point(int point, int x, int y, int z) {
_points[point] = Vector3i(x, y, z);
}
int VoxelCubePoints::get_point_id(Vector3i point) {
int VoxelCubePoints::get_point_id_vec(Vector3i point) {
for (int i = 0; i < POINT_COUNT; ++i) {
if (get_point(i) == point) {
return i;
@ -229,6 +258,10 @@ int VoxelCubePoints::get_point_id(int x, int y, int z) {
return 0;
}
Vector3i VoxelCubePoints::get_point(int index) {
return _points[index];
}
Vector3i VoxelCubePoints::get_top_left_point(int face) {
if (face == VOXEL_FACE_BACK) {
return _points[P011];
@ -317,6 +350,98 @@ Vector3i VoxelCubePoints::get_bottom_right_point(int face) {
return _points[P000];
}
Vector3 VoxelCubePoints::get_point_bind(int index) {
return _points[index].to_vec3();
}
Vector3 VoxelCubePoints::get_top_left_point_bind(int face) {
if (face == VOXEL_FACE_BACK) {
return _points[P011].to_vec3();
}
if (face == VOXEL_FACE_FRONT) {
return _points[P010].to_vec3();
}
if (face == VOXEL_FACE_RIGHT) {
return _points[P111].to_vec3();
}
if (face == VOXEL_FACE_LEFT) {
return _points[P010].to_vec3();
}
if (face == VOXEL_FACE_TOP) {
return _points[P010].to_vec3();
}
if (face == VOXEL_FACE_BOTTOM) {
return _points[P000].to_vec3();
}
return _points[0].to_vec3();
}
Vector3 VoxelCubePoints::get_top_right_point_bind(int face) {
if (face == VOXEL_FACE_BACK) {
return _points[P111].to_vec3();
}
if (face == VOXEL_FACE_FRONT) {
return _points[P110].to_vec3();
}
if (face == VOXEL_FACE_RIGHT) {
return _points[P110].to_vec3();
}
if (face == VOXEL_FACE_LEFT) {
return _points[P011].to_vec3();
}
if (face == VOXEL_FACE_TOP) {
return _points[P110].to_vec3();
}
if (face == VOXEL_FACE_BOTTOM) {
return _points[P100].to_vec3();
}
return _points[0].to_vec3();
}
Vector3 VoxelCubePoints::get_bottom_left_point_bind(int face) {
if (face == VOXEL_FACE_BACK) {
return _points[P001].to_vec3();
}
if (face == VOXEL_FACE_FRONT) {
return _points[P000].to_vec3();
}
if (face == VOXEL_FACE_RIGHT) {
return _points[P101].to_vec3();
}
if (face == VOXEL_FACE_LEFT) {
return _points[P001].to_vec3();
}
if (face == VOXEL_FACE_TOP) {
return _points[P011].to_vec3();
}
if (face == VOXEL_FACE_BOTTOM) {
return _points[P001].to_vec3();
}
return _points[0].to_vec3();
}
Vector3 VoxelCubePoints::get_bottom_right_point_bind(int face) {
if (face == VOXEL_FACE_BACK) {
return _points[P101].to_vec3();
}
if (face == VOXEL_FACE_FRONT) {
return _points[P100].to_vec3();
}
if (face == VOXEL_FACE_RIGHT) {
return _points[P100].to_vec3();
}
if (face == VOXEL_FACE_LEFT) {
return _points[P001].to_vec3();
}
if (face == VOXEL_FACE_TOP) {
return _points[P111].to_vec3();
}
if (face == VOXEL_FACE_BOTTOM) {
return _points[P101].to_vec3();
}
return _points[P000].to_vec3();
}
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);
@ -342,8 +467,57 @@ int VoxelCubePoints::get_opposite_face(int face) {
return VOXEL_FACE_BOTTOM;
}
VoxelCubePoints::VoxelCubePoints() {
_face_helper.instance();
}
VoxelCubePoints::~VoxelCubePoints() {
_face_helper.unref();
}
void VoxelCubePoints::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_x"), &VoxelCubePoints::get_x);
ClassDB::bind_method(D_METHOD("set_x", "value"), &VoxelCubePoints::set_x);
ADD_PROPERTY(PropertyInfo(Variant::INT, "x"), "set_x", "get_x");
ClassDB::bind_method(D_METHOD("get_y"), &VoxelCubePoints::get_y);
ClassDB::bind_method(D_METHOD("set_y", "value"), &VoxelCubePoints::set_y);
ADD_PROPERTY(PropertyInfo(Variant::INT, "y"), "set_y", "get_y");
ClassDB::bind_method(D_METHOD("get_z"), &VoxelCubePoints::get_z);
ClassDB::bind_method(D_METHOD("set_z", "value"), &VoxelCubePoints::set_z);
ADD_PROPERTY(PropertyInfo(Variant::INT, "z"), "set_z", "get_z");
ClassDB::bind_method(D_METHOD("get_size"), &VoxelCubePoints::get_size);
ClassDB::bind_method(D_METHOD("set_size", "value"), &VoxelCubePoints::set_size);
ADD_PROPERTY(PropertyInfo(Variant::INT, "size"), "set_size", "get_size");
ClassDB::bind_method(D_METHOD("refresh_points"), &VoxelCubePoints::refresh_points);
ClassDB::bind_method(D_METHOD("setup", "buffer", "x", "y", "z", "size"), &VoxelCubePoints::setup, DEFVAL(1));
ClassDB::bind_method(D_METHOD("get_points_for_face", "face"), &VoxelCubePoints::get_points_for_face);
ClassDB::bind_method(D_METHOD("face_fully_covered", "face"), &VoxelCubePoints::face_fully_covered);
ClassDB::bind_method(D_METHOD("face_should_be_visible_against_full", "face"), &VoxelCubePoints::face_should_be_visible_against_full);
//ClassDB::bind_method(D_METHOD("face_should_be_visible_against", "face", "other"), &VoxelCubePoints::face_should_be_visible_against);
ClassDB::bind_method(D_METHOD("is_sub_voxel_point", "x", "y", "z"), &VoxelCubePoints::is_sub_voxel_point);
ClassDB::bind_method(D_METHOD("set_point", "point", "x", "y", "z"), &VoxelCubePoints::set_point);
ClassDB::bind_method(D_METHOD("get_point_id", "x", "y", "z"), &VoxelCubePoints::get_point_id);
ClassDB::bind_method(D_METHOD("get_point", "index"), &VoxelCubePoints::get_point_bind);
ClassDB::bind_method(D_METHOD("get_top_left_point", "face"), &VoxelCubePoints::get_top_left_point_bind);
ClassDB::bind_method(D_METHOD("get_top_right_point", "face"), &VoxelCubePoints::get_top_right_point_bind);
ClassDB::bind_method(D_METHOD("get_bottom_left_point", "face"), &VoxelCubePoints::get_bottom_left_point_bind);
ClassDB::bind_method(D_METHOD("get_bottom_right_point", "face"), &VoxelCubePoints::get_bottom_right_point_bind);
ClassDB::bind_method(D_METHOD("has_points"), &VoxelCubePoints::has_points);
ClassDB::bind_method(D_METHOD("get_opposite_face", "face"), &VoxelCubePoints::get_opposite_face);
BIND_ENUM_CONSTANT(P000);
BIND_ENUM_CONSTANT(P100);
BIND_ENUM_CONSTANT(P010);

View File

@ -8,7 +8,9 @@
#include "sub_voxel_side_points.h"
class VoxelCubePoints : Reference {
class SubVoxelFacePointsHelper;
class VoxelCubePoints : public Reference {
GDCLASS(VoxelCubePoints, Reference);
public:
@ -77,10 +79,18 @@ public:
VOXEL_FULL_SIDE_NEIGHBOURS_DOWN = VOXEL_NEIGHBOUR_LEFT | VOXEL_NEIGHBOUR_RIGHT | VOXEL_NEIGHBOUR_BACK | VOXEL_NEIGHBOUR_FRONT | VOXEL_NEIGHBOUR_BOTTOM,
};
int get_x();
void set_x(int value);
Vector3i get_point(int index);
VoxelCubePoints();
~VoxelCubePoints();
int get_y();
void set_y(int value);
int get_z();
void set_z(int value);
int get_size();
void set_size(int value);
void refresh_points();
void setup(const Ref<VoxelBuffer> buffer, int x, int y, int z, int size = 1);
@ -89,23 +99,36 @@ public:
bool face_fully_covered(int face);
bool face_should_be_visible_against_full(int face);
bool face_should_be_visible_against(int face, Ref<VoxelCubePoints> other);
bool is_sub_voxel_point(Vector3i point);
bool is_sub_voxel_point_vec(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_vec(Vector3i point);
int get_point_id(int x, int y, int z);
Vector3i get_point(int index);
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);
Vector3 get_point_bind(int index);
Vector3 get_top_left_point_bind(int face);
Vector3 get_top_right_point_bind(int face);
Vector3 get_bottom_left_point_bind(int face);
Vector3 get_bottom_right_point_bind(int face);
bool has_points();
int get_opposite_face(int face);
VoxelCubePoints();
~VoxelCubePoints();
protected:
static void _bind_methods();
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);
private:
Vector3i _points[POINT_COUNT];
@ -115,8 +138,10 @@ private:
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);
int _size;
int _x;
int _y;
int _z;
};
VARIANT_ENUM_CAST(VoxelCubePoints::Points);

View File

@ -15,6 +15,7 @@
#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"
#include "meshers/cubic_mesher/sub_voxel_face_points_helper.h"
void register_voxelman_types() {
ClassDB::register_class<VoxelMesher>();
@ -35,6 +36,7 @@ void register_voxelman_types() {
ClassDB::register_class<VoxelMesherCubic>();
ClassDB::register_class<VoxelCubePoints>();
ClassDB::register_class<SubVoxelSidePoints>();
ClassDB::register_class<SubVoxelFacePointsHelper>();
}
void unregister_voxelman_types() {