Work on uv mapping.

This commit is contained in:
Relintai 2019-07-16 11:11:47 +02:00
parent fc27061055
commit 370702cc1e
2 changed files with 50 additions and 3 deletions

View File

@ -42,6 +42,15 @@ const unsigned int VoxelCubePoints::point_direction_neighbour_table[8][3] = {
{ VOXEL_NEIGHBOUR_RIGHT, VOXEL_NEIGHBOUR_TOP, VOXEL_NEIGHBOUR_BACK }, //P111
};
const float VoxelCubePoints::uv_direction_table[8][4][2] = {
{ { -0.5, -0.5 }, { 0.5, -0.5 }, { 0.5, 0.5 }, { 0.5, -0.5 } }, //VOXEL_FACE_FRONT 0, P000, P010, P110, P100
{ { -0.5, -0.5 }, { 0.5, -0.5 }, { 0.5, 0.5 }, { 0.5, -0.5 } }, //VOXEL_FACE_RIGHT 1, P100, P110, P111, P101
{ { -0.5, -0.5 }, { 0.5, -0.5 }, { 0.5, 0.5 }, { 0.5, -0.5 } }, //VOXEL_FACE_BACK 2, P101, P111, P011, P001
{ { -0.5, -0.5 }, { 0.5, -0.5 }, { 0.5, 0.5 }, { 0.5, -0.5 } }, //VOXEL_FACE_LEFT 3, P001, P011, P010, P000
{ { -0.5, -0.5 }, { 0.5, -0.5 }, { 0.5, 0.5 }, { 0.5, -0.5 } }, //VOXEL_FACE_TOP 4, P111, P110, P010, P011
{ { -0.5, -0.5 }, { 0.5, -0.5 }, { 0.5, 0.5 }, { 0.5, -0.5 } }, //VOXEL_FACE_BOTTOM 5, P001, P000, P100, P101
};
int VoxelCubePoints::get_x() {
return _x;
}
@ -445,6 +454,13 @@ int VoxelCubePoints::get_point_index(int face, int index) {
return index_table[face][index];
}
Vector2 VoxelCubePoints::get_point_uv_direction(int face, int index) {
ERR_FAIL_INDEX_V(face, VOXEL_FACE_COUNT, Vector2());
ERR_FAIL_INDEX_V(index, 4, Vector2());
return Vector2(uv_direction_table[face][index][0], uv_direction_table[face][index][1]);
}
Vector3 VoxelCubePoints::get_points_for_face(int face, int index) {
return _points[get_point_index(face, index)];
}
@ -530,7 +546,27 @@ Vector3 VoxelCubePoints::get_vertex_vector3_for_point(int face, int index) {
return vector;
}
int VoxelCubePoints::get_point_type(int index) {
ERR_FAIL_INDEX_V(index, POINT_COUNT, 0);
return _point_types[index];
}
int VoxelCubePoints::get_point_fill(int index) {
ERR_FAIL_INDEX_V(index, POINT_COUNT, 0);
return _point_fills[index];
}
int VoxelCubePoints::get_point_neighbours(int index) {
ERR_FAIL_INDEX_V(index, POINT_COUNT, 0);
return _point_neighbours[index];
}
Vector3 VoxelCubePoints::get_point(int index) {
ERR_FAIL_INDEX_V(index, POINT_COUNT, Vector3());
return _points[index];
}
@ -677,6 +713,8 @@ void VoxelCubePoints::_bind_methods() {
ClassDB::bind_method(D_METHOD("setup", "buffer", "x", "y", "z", "size"), &VoxelCubePoints::setup, DEFVAL(1));
ClassDB::bind_method(D_METHOD("get_point_index", "face", "index"), &VoxelCubePoints::get_point_index);
ClassDB::bind_method(D_METHOD("get_point_uv_direction", "face", "index"), &VoxelCubePoints::get_point_uv_direction);
ClassDB::bind_method(D_METHOD("get_points_for_face", "face", "index"), &VoxelCubePoints::get_points_for_face);
ClassDB::bind_method(D_METHOD("is_face_visible", "face"), &VoxelCubePoints::is_face_visible);
@ -688,6 +726,10 @@ void VoxelCubePoints::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_point_for_face", "face", "index"), &VoxelCubePoints::get_point_for_face);
ClassDB::bind_method(D_METHOD("get_vertex_vector3_for_point", "face", "index"), &VoxelCubePoints::get_vertex_vector3_for_point);
ClassDB::bind_method(D_METHOD("get_point_type", "index"), &VoxelCubePoints::get_point_type);
ClassDB::bind_method(D_METHOD("get_point_fill", "index"), &VoxelCubePoints::get_point_fill);
ClassDB::bind_method(D_METHOD("get_point_neighbours", "index"), &VoxelCubePoints::get_point_neighbours);
ClassDB::bind_method(D_METHOD("get_point", "index"), &VoxelCubePoints::get_point);
ClassDB::bind_method(D_METHOD("get_top_left_point", "face"), &VoxelCubePoints::get_top_left_point);

View File

@ -97,6 +97,8 @@ public:
void reset();
int get_point_index(int face, int index);
Vector2 get_point_uv_direction(int face, int index);
Vector3 get_points_for_face(int face, int index);
bool is_face_visible(int face);
bool is_sub_voxel_point_vec(Vector3i point);
@ -108,6 +110,10 @@ public:
Vector3 get_point_for_face(int face, int pointIndex);
Vector3 get_vertex_vector3_for_point(int face, int pointIndex);
int get_point_type(int index);
int get_point_fill(int index);
int get_point_neighbours(int index);
Vector3 get_point(int index);
Vector3 get_top_left_point(int face);
Vector3 get_top_right_point(int face);
@ -123,14 +129,13 @@ public:
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);
private:
static const unsigned int index_table[6][4];
static const unsigned int visibility_check_table[6];
static const float point_direction_table[8][3];
static const unsigned int point_direction_neighbour_table[8][3];
static const float uv_direction_table[8][4][2];
private:
Vector3 _points[POINT_COUNT];
uint8_t _point_types[POINT_COUNT];