mirror of
https://github.com/Relintai/terraman.git
synced 2025-04-23 21:43:23 +02:00
Removed the cubic mesher.
This commit is contained in:
parent
126bb7c712
commit
77e5f9e1e4
6
SCsub
6
SCsub
@ -60,15 +60,9 @@ sources = [
|
|||||||
"world/marching_cubes/voxel_chunk_marching_cubes.cpp",
|
"world/marching_cubes/voxel_chunk_marching_cubes.cpp",
|
||||||
"world/marching_cubes/voxel_world_marching_cubes.cpp",
|
"world/marching_cubes/voxel_world_marching_cubes.cpp",
|
||||||
|
|
||||||
"meshers/cubic/voxel_mesher_cubic.cpp",
|
|
||||||
"meshers/cubic/voxel_cube_points.cpp",
|
|
||||||
|
|
||||||
"level_generator/voxelman_level_generator.cpp",
|
"level_generator/voxelman_level_generator.cpp",
|
||||||
"level_generator/voxelman_level_generator_flat.cpp",
|
"level_generator/voxelman_level_generator_flat.cpp",
|
||||||
|
|
||||||
"world/cubic/voxel_chunk_cubic.cpp",
|
|
||||||
"world/cubic/voxel_world_cubic.cpp",
|
|
||||||
|
|
||||||
"areas/world_area.cpp",
|
"areas/world_area.cpp",
|
||||||
|
|
||||||
"world/voxel_world_editor.cpp",
|
"world/voxel_world_editor.cpp",
|
||||||
|
@ -1,940 +0,0 @@
|
|||||||
/*
|
|
||||||
Copyright (c) 2019-2021 Péter Magyar
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
|
||||||
copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "voxel_cube_points.h"
|
|
||||||
#include "../../world/default/voxel_chunk_default.h"
|
|
||||||
#include "../../world/voxel_chunk.h"
|
|
||||||
|
|
||||||
const unsigned int TerraCubePoints::index_table[6][4] = {
|
|
||||||
{ P000, P010, P110, P100 }, //TERRA_FACE_FRONT 0
|
|
||||||
{ P100, P110, P111, P101 }, //TERRA_FACE_RIGHT 1
|
|
||||||
{ P101, P111, P011, P001 }, //TERRA_FACE_BACK 2
|
|
||||||
{ P001, P011, P010, P000 }, //TERRA_FACE_LEFT 3
|
|
||||||
{ P111, P110, P010, P011 }, //TERRA_FACE_TOP 4
|
|
||||||
{ P001, P000, P100, P101 }, //TERRA_FACE_BOTTOM 5
|
|
||||||
};
|
|
||||||
|
|
||||||
const unsigned int TerraCubePoints::visibility_check_table[6] = {
|
|
||||||
TERRA_NEIGHBOUR_FRONT, //TERRA_FACE_FRONT 0
|
|
||||||
TERRA_NEIGHBOUR_RIGHT, //TERRA_FACE_RIGHT 1
|
|
||||||
TERRA_NEIGHBOUR_BACK, //TERRA_FACE_BACK 2
|
|
||||||
TERRA_NEIGHBOUR_LEFT, //TERRA_FACE_LEFT 3
|
|
||||||
TERRA_NEIGHBOUR_TOP, //TERRA_FACE_TOP 4
|
|
||||||
TERRA_NEIGHBOUR_BOTTOM //TERRA_FACE_BOTTOM 5
|
|
||||||
};
|
|
||||||
|
|
||||||
const int TerraCubePoints::face_light_direction_table[6][3] = {
|
|
||||||
{ 0, 0, -1 }, //TERRA_FACE_FRONT 0
|
|
||||||
{ -1, 0, 0 }, //TERRA_FACE_RIGHT 1
|
|
||||||
{ 0, 0, 1 }, //TERRA_FACE_BACK 2
|
|
||||||
{ 1, 0, 0 }, //TERRA_FACE_LEFT 3
|
|
||||||
{ 0, -1, 0 }, //TERRA_FACE_TOP 4
|
|
||||||
{ 0, 1, 0 } //TERRA_FACE_BOTTOM 5
|
|
||||||
};
|
|
||||||
|
|
||||||
const float TerraCubePoints::point_direction_table[8][3] = {
|
|
||||||
{ -0.5, -0.5, -0.5 }, //P000
|
|
||||||
{ 0.5, -0.5, -0.5 }, //P100
|
|
||||||
{ -0.5, 0.5, -0.5 }, //P010
|
|
||||||
{ -0.5, -0.5, 0.5 }, //P001
|
|
||||||
|
|
||||||
{ 0.5, 0.5, -0.5 }, //P110
|
|
||||||
{ -0.5, 0.5, 0.5 }, //P011
|
|
||||||
{ 0.5, -0.5, 0.5 }, //P101
|
|
||||||
{ 0.5, 0.5, 0.5 }, //P111
|
|
||||||
};
|
|
||||||
|
|
||||||
const unsigned int TerraCubePoints::point_direction_neighbour_table[8][3] = {
|
|
||||||
{ TERRA_NEIGHBOUR_LEFT, TERRA_NEIGHBOUR_BOTTOM, TERRA_NEIGHBOUR_FRONT }, //P000
|
|
||||||
{ TERRA_NEIGHBOUR_RIGHT, TERRA_NEIGHBOUR_BOTTOM, TERRA_NEIGHBOUR_FRONT }, //P100
|
|
||||||
{ TERRA_NEIGHBOUR_LEFT, TERRA_NEIGHBOUR_TOP, TERRA_NEIGHBOUR_FRONT }, //P010
|
|
||||||
{ TERRA_NEIGHBOUR_LEFT, TERRA_NEIGHBOUR_BOTTOM, TERRA_NEIGHBOUR_BACK }, //P001
|
|
||||||
|
|
||||||
{ TERRA_NEIGHBOUR_RIGHT, TERRA_NEIGHBOUR_TOP, TERRA_NEIGHBOUR_FRONT }, //P110
|
|
||||||
{ TERRA_NEIGHBOUR_LEFT, TERRA_NEIGHBOUR_TOP, TERRA_NEIGHBOUR_BACK }, //P011
|
|
||||||
{ TERRA_NEIGHBOUR_RIGHT, TERRA_NEIGHBOUR_BOTTOM, TERRA_NEIGHBOUR_BACK }, //P101
|
|
||||||
{ TERRA_NEIGHBOUR_RIGHT, TERRA_NEIGHBOUR_TOP, TERRA_NEIGHBOUR_BACK }, //P111
|
|
||||||
};
|
|
||||||
|
|
||||||
const float TerraCubePoints::uv_direction_table[8][4][2] = {
|
|
||||||
{ { -0.5, -0.5 }, { 0.5, -0.5 }, { 0.5, 0.5 }, { 0.5, -0.5 } }, //TERRA_FACE_FRONT 0, P000, P010, P110, P100
|
|
||||||
{ { -0.5, -0.5 }, { 0.5, -0.5 }, { 0.5, 0.5 }, { 0.5, -0.5 } }, //TERRA_FACE_RIGHT 1, P100, P110, P111, P101
|
|
||||||
{ { -0.5, -0.5 }, { 0.5, -0.5 }, { 0.5, 0.5 }, { 0.5, -0.5 } }, //TERRA_FACE_BACK 2, P101, P111, P011, P001
|
|
||||||
{ { -0.5, -0.5 }, { 0.5, -0.5 }, { 0.5, 0.5 }, { 0.5, -0.5 } }, //TERRA_FACE_LEFT 3, P001, P011, P010, P000
|
|
||||||
{ { -0.5, -0.5 }, { 0.5, -0.5 }, { 0.5, 0.5 }, { 0.5, -0.5 } }, //TERRA_FACE_TOP 4, P111, P110, P010, P011
|
|
||||||
{ { -0.5, -0.5 }, { 0.5, -0.5 }, { 0.5, 0.5 }, { 0.5, -0.5 } }, //TERRA_FACE_BOTTOM 5, P001, P000, P100, P101
|
|
||||||
};
|
|
||||||
|
|
||||||
int TerraCubePoints::get_x() {
|
|
||||||
return _x;
|
|
||||||
}
|
|
||||||
void TerraCubePoints::set_x(int value) {
|
|
||||||
_x = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
int TerraCubePoints::get_y() {
|
|
||||||
return _y;
|
|
||||||
}
|
|
||||||
void TerraCubePoints::set_y(int value) {
|
|
||||||
_y = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
int TerraCubePoints::get_z() {
|
|
||||||
return _z;
|
|
||||||
}
|
|
||||||
void TerraCubePoints::set_z(int value) {
|
|
||||||
_z = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
int TerraCubePoints::get_size() {
|
|
||||||
return _size;
|
|
||||||
}
|
|
||||||
void TerraCubePoints::set_size(int value) {
|
|
||||||
_size = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
int TerraCubePoints::get_channel_index_type() const {
|
|
||||||
return _channel_index_type;
|
|
||||||
}
|
|
||||||
void TerraCubePoints::set_channel_index_type(const int value) {
|
|
||||||
_channel_index_type = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
int TerraCubePoints::get_channel_index_isolevel() const {
|
|
||||||
return _channel_index_isolevel;
|
|
||||||
}
|
|
||||||
void TerraCubePoints::set_channel_index_isolevel(const int value) {
|
|
||||||
_channel_index_isolevel = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
void TerraCubePoints::refresh_points() {
|
|
||||||
for (int i = 0; i < POINT_COUNT; ++i) {
|
|
||||||
recalculate_point(i);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
//Front
|
|
||||||
//Bottom Left
|
|
||||||
refresh_point(P000, 0, 0, 0,
|
|
||||||
TERRA_NEIGHBOUR_LEFT, TERRA_NEIGHBOUR_BOTTOM_LEFT, TERRA_NEIGHBOUR_LEFT, TERRA_NEIGHBOUR_FRONT,
|
|
||||||
TERRA_NEIGHBOUR_BOTTOM, TERRA_NEIGHBOUR_BOTTOM_LEFT, TERRA_NEIGHBOUR_BOTTOM_FRONT, TERRA_NEIGHBOUR_BOTTOM_LEFT_FRONT,
|
|
||||||
TERRA_NEIGHBOUR_FRONT, TERRA_NEIGHBOUR_BOTTOM_FRONT, TERRA_NEIGHBOUR_LEFT, TERRA_NEIGHBOUR_FRONT);
|
|
||||||
|
|
||||||
//Bottom Right
|
|
||||||
refresh_point(P100, 255, 0, 0,
|
|
||||||
TERRA_NEIGHBOUR_RIGHT, TERRA_NEIGHBOUR_BOTTOM_RIGHT, TERRA_NEIGHBOUR_RIGHT, TERRA_NEIGHBOUR_FRONT,
|
|
||||||
TERRA_NEIGHBOUR_BOTTOM, TERRA_NEIGHBOUR_BOTTOM_RIGHT, TERRA_NEIGHBOUR_BOTTOM_FRONT, TERRA_NEIGHBOUR_BOTTOM_RIGHT_FRONT,
|
|
||||||
TERRA_NEIGHBOUR_FRONT, TERRA_NEIGHBOUR_BOTTOM_FRONT, TERRA_NEIGHBOUR_RIGHT, TERRA_NEIGHBOUR_FRONT);
|
|
||||||
|
|
||||||
//Top Left
|
|
||||||
refresh_point(P010, 0, 255, 0,
|
|
||||||
TERRA_NEIGHBOUR_LEFT, TERRA_NEIGHBOUR_TOP_LEFT, TERRA_NEIGHBOUR_LEFT, TERRA_NEIGHBOUR_FRONT,
|
|
||||||
TERRA_NEIGHBOUR_TOP, TERRA_NEIGHBOUR_TOP_LEFT, TERRA_NEIGHBOUR_TOP_FRONT, TERRA_NEIGHBOUR_TOP_LEFT_FRONT,
|
|
||||||
TERRA_NEIGHBOUR_FRONT, TERRA_NEIGHBOUR_TOP_FRONT, TERRA_NEIGHBOUR_LEFT, TERRA_NEIGHBOUR_FRONT);
|
|
||||||
|
|
||||||
//Top Right
|
|
||||||
refresh_point(P110, 255, 255, 0,
|
|
||||||
TERRA_NEIGHBOUR_RIGHT, TERRA_NEIGHBOUR_TOP_RIGHT, TERRA_NEIGHBOUR_RIGHT, TERRA_NEIGHBOUR_FRONT,
|
|
||||||
TERRA_NEIGHBOUR_TOP, TERRA_NEIGHBOUR_TOP_RIGHT, TERRA_NEIGHBOUR_TOP_FRONT, TERRA_NEIGHBOUR_TOP_RIGHT_FRONT,
|
|
||||||
TERRA_NEIGHBOUR_FRONT, TERRA_NEIGHBOUR_TOP_FRONT, TERRA_NEIGHBOUR_RIGHT, TERRA_NEIGHBOUR_FRONT);
|
|
||||||
|
|
||||||
//Back
|
|
||||||
//Bottom Left
|
|
||||||
refresh_point(P001, 0, 0, 255,
|
|
||||||
TERRA_NEIGHBOUR_LEFT, TERRA_NEIGHBOUR_BOTTOM_LEFT, TERRA_NEIGHBOUR_LEFT, TERRA_NEIGHBOUR_BACK,
|
|
||||||
TERRA_NEIGHBOUR_BOTTOM, TERRA_NEIGHBOUR_BOTTOM_LEFT, TERRA_NEIGHBOUR_BOTTOM_BACK, TERRA_NEIGHBOUR_BOTTOM_LEFT_BACK,
|
|
||||||
TERRA_NEIGHBOUR_BACK, TERRA_NEIGHBOUR_BOTTOM_BACK, TERRA_NEIGHBOUR_LEFT, TERRA_NEIGHBOUR_BACK);
|
|
||||||
|
|
||||||
//Bottom Right
|
|
||||||
refresh_point(P101, 255, 0, 255,
|
|
||||||
TERRA_NEIGHBOUR_RIGHT, TERRA_NEIGHBOUR_BOTTOM_RIGHT, TERRA_NEIGHBOUR_RIGHT, TERRA_NEIGHBOUR_BACK,
|
|
||||||
TERRA_NEIGHBOUR_BOTTOM, TERRA_NEIGHBOUR_BOTTOM_RIGHT, TERRA_NEIGHBOUR_BOTTOM_BACK, TERRA_NEIGHBOUR_BOTTOM_RIGHT_BACK,
|
|
||||||
TERRA_NEIGHBOUR_BACK, TERRA_NEIGHBOUR_BOTTOM_BACK, TERRA_NEIGHBOUR_RIGHT, TERRA_NEIGHBOUR_BACK);
|
|
||||||
|
|
||||||
//Top Left
|
|
||||||
refresh_point(P011, 0, 255, 255,
|
|
||||||
TERRA_NEIGHBOUR_LEFT, TERRA_NEIGHBOUR_TOP_LEFT, TERRA_NEIGHBOUR_LEFT, TERRA_NEIGHBOUR_BACK,
|
|
||||||
TERRA_NEIGHBOUR_TOP, TERRA_NEIGHBOUR_TOP_LEFT, TERRA_NEIGHBOUR_TOP_BACK, TERRA_NEIGHBOUR_TOP_LEFT_BACK,
|
|
||||||
TERRA_NEIGHBOUR_BACK, TERRA_NEIGHBOUR_TOP_BACK, TERRA_NEIGHBOUR_LEFT, TERRA_NEIGHBOUR_BACK);
|
|
||||||
|
|
||||||
//Top Right
|
|
||||||
refresh_point(P111, 255, 255, 255,
|
|
||||||
TERRA_NEIGHBOUR_RIGHT, TERRA_NEIGHBOUR_TOP_RIGHT, TERRA_NEIGHBOUR_RIGHT, TERRA_NEIGHBOUR_BACK,
|
|
||||||
TERRA_NEIGHBOUR_TOP, TERRA_NEIGHBOUR_TOP_RIGHT, TERRA_NEIGHBOUR_TOP_BACK, TERRA_NEIGHBOUR_TOP_RIGHT_BACK,
|
|
||||||
TERRA_NEIGHBOUR_BACK, TERRA_NEIGHBOUR_TOP_BACK, TERRA_NEIGHBOUR_RIGHT, TERRA_NEIGHBOUR_BACK);*/
|
|
||||||
}
|
|
||||||
|
|
||||||
void TerraCubePoints::recalculate_point(int point) {
|
|
||||||
ERR_FAIL_INDEX(point, POINT_COUNT);
|
|
||||||
|
|
||||||
Vector3 static_offset;
|
|
||||||
Vector3 dynamic_offset;
|
|
||||||
|
|
||||||
for (int i = 0; i < 3; ++i) {
|
|
||||||
int neighbour_check = point_direction_neighbour_table[point][i];
|
|
||||||
|
|
||||||
if ((_point_neighbours[point] & neighbour_check) == 0) {
|
|
||||||
dynamic_offset[i] = point_direction_table[point][i];
|
|
||||||
} else {
|
|
||||||
static_offset[i] = point_direction_table[point][i];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
dynamic_offset *= (_point_fills[point] / 255.0);
|
|
||||||
dynamic_offset += static_offset;
|
|
||||||
dynamic_offset += Vector3(0.5 * _size, 0.5 * _size, 0.5 * _size);
|
|
||||||
|
|
||||||
_points[point] = dynamic_offset;
|
|
||||||
}
|
|
||||||
|
|
||||||
void TerraCubePoints::refresh_neighbours(Ref<TerraChunk> chunk) {
|
|
||||||
ERR_FAIL_COND(!chunk.is_valid());
|
|
||||||
|
|
||||||
int neighbours = 0;
|
|
||||||
|
|
||||||
int x = _x;
|
|
||||||
int y = _y;
|
|
||||||
int z = _z;
|
|
||||||
|
|
||||||
//000
|
|
||||||
if (chunk->get_voxel(x - 1, y, z, _channel_index_type) != 0)
|
|
||||||
neighbours = neighbours | TERRA_NEIGHBOUR_LEFT;
|
|
||||||
|
|
||||||
if (chunk->get_voxel(x, y - 1, z, _channel_index_type) != 0)
|
|
||||||
neighbours = neighbours | TERRA_NEIGHBOUR_BOTTOM;
|
|
||||||
|
|
||||||
if (chunk->get_voxel(x, y, z - 1, _channel_index_type) != 0)
|
|
||||||
neighbours = neighbours | TERRA_NEIGHBOUR_FRONT;
|
|
||||||
/*
|
|
||||||
if (chunk->get_voxel(x - 1, y, z - 1, _channel_index_type) != 0)
|
|
||||||
neighbours = neighbours | TERRA_NEIGHBOUR_LEFT_FRONT;
|
|
||||||
|
|
||||||
if (chunk->get_voxel(x - 1, y - 1, z, _channel_index_type) != 0)
|
|
||||||
neighbours = neighbours | TERRA_NEIGHBOUR_BOTTOM_LEFT;
|
|
||||||
|
|
||||||
if (chunk->get_voxel(x, y - 1, z - 1, _channel_index_type) != 0)
|
|
||||||
neighbours = neighbours | TERRA_NEIGHBOUR_BOTTOM_FRONT;
|
|
||||||
|
|
||||||
if (chunk->get_voxel(x - 1, y - 1, z - 1, _channel_index_type) != 0)
|
|
||||||
neighbours = neighbours | TERRA_NEIGHBOUR_BOTTOM_LEFT_FRONT;*/
|
|
||||||
|
|
||||||
_point_neighbours[P000] = neighbours;
|
|
||||||
|
|
||||||
neighbours = 0;
|
|
||||||
x = _x + 1;
|
|
||||||
y = _y;
|
|
||||||
z = _z;
|
|
||||||
|
|
||||||
//100
|
|
||||||
if (chunk->get_voxel(x + 1, y, z, _channel_index_type) != 0)
|
|
||||||
neighbours = neighbours | TERRA_NEIGHBOUR_RIGHT;
|
|
||||||
|
|
||||||
if (chunk->get_voxel(x, y - 1, z, _channel_index_type) != 0)
|
|
||||||
neighbours = neighbours | TERRA_NEIGHBOUR_BOTTOM;
|
|
||||||
|
|
||||||
if (chunk->get_voxel(x, y, z - 1, _channel_index_type) != 0)
|
|
||||||
neighbours = neighbours | TERRA_NEIGHBOUR_FRONT;
|
|
||||||
/*
|
|
||||||
if (chunk->get_voxel(x + 1, y, z - 1, _channel_index_type) != 0)
|
|
||||||
neighbours = neighbours | TERRA_NEIGHBOUR_RIGHT_FRONT;
|
|
||||||
|
|
||||||
if (chunk->get_voxel(x + 1, y - 1, z, _channel_index_type) != 0)
|
|
||||||
neighbours = neighbours | TERRA_NEIGHBOUR_BOTTOM_RIGHT;
|
|
||||||
|
|
||||||
if (chunk->get_voxel(x, y - 1, z - 1, _channel_index_type) != 0)
|
|
||||||
neighbours = neighbours | TERRA_NEIGHBOUR_BOTTOM_FRONT;
|
|
||||||
|
|
||||||
if (chunk->get_voxel(x + 1, y - 1, z - 1, _channel_index_type) != 0)
|
|
||||||
neighbours = neighbours | TERRA_NEIGHBOUR_BOTTOM_RIGHT_FRONT;*/
|
|
||||||
|
|
||||||
_point_neighbours[P100] = neighbours;
|
|
||||||
|
|
||||||
neighbours = 0;
|
|
||||||
x = _x;
|
|
||||||
y = _y + 1;
|
|
||||||
z = _z;
|
|
||||||
|
|
||||||
//010
|
|
||||||
if (chunk->get_voxel(x - 1, y, z, _channel_index_type) != 0)
|
|
||||||
neighbours = neighbours | TERRA_NEIGHBOUR_LEFT;
|
|
||||||
|
|
||||||
if (chunk->get_voxel(x, y + 1, z, _channel_index_type) != 0)
|
|
||||||
neighbours = neighbours | TERRA_NEIGHBOUR_TOP;
|
|
||||||
|
|
||||||
if (chunk->get_voxel(x, y, z - 1, _channel_index_type) != 0)
|
|
||||||
neighbours = neighbours | TERRA_NEIGHBOUR_FRONT;
|
|
||||||
/*
|
|
||||||
if (chunk->get_voxel(x - 1, y, z - 1, _channel_index_type) != 0)
|
|
||||||
neighbours = neighbours | TERRA_NEIGHBOUR_LEFT_FRONT;
|
|
||||||
|
|
||||||
if (chunk->get_voxel(x - 1, y + 1, z, _channel_index_type) != 0)
|
|
||||||
neighbours = neighbours | TERRA_NEIGHBOUR_TOP_LEFT;
|
|
||||||
|
|
||||||
if (chunk->get_voxel(x, y + 1, z - 1, _channel_index_type) != 0)
|
|
||||||
neighbours = neighbours | TERRA_NEIGHBOUR_TOP_FRONT;
|
|
||||||
|
|
||||||
if (chunk->get_voxel(x - 1, y + 1, z - 1, _channel_index_type) != 0)
|
|
||||||
neighbours = neighbours | TERRA_NEIGHBOUR_TOP_LEFT_FRONT;*/
|
|
||||||
|
|
||||||
_point_neighbours[P010] = neighbours;
|
|
||||||
|
|
||||||
neighbours = 0;
|
|
||||||
x = _x + 1;
|
|
||||||
y = _y + 1;
|
|
||||||
z = _z;
|
|
||||||
|
|
||||||
//110
|
|
||||||
if (chunk->get_voxel(x + 1, y, z, _channel_index_type) != 0)
|
|
||||||
neighbours = neighbours | TERRA_NEIGHBOUR_RIGHT;
|
|
||||||
|
|
||||||
if (chunk->get_voxel(x, y + 1, z, _channel_index_type) != 0)
|
|
||||||
neighbours = neighbours | TERRA_NEIGHBOUR_TOP;
|
|
||||||
|
|
||||||
if (chunk->get_voxel(x, y, z - 1, _channel_index_type) != 0)
|
|
||||||
neighbours = neighbours | TERRA_NEIGHBOUR_FRONT;
|
|
||||||
/*
|
|
||||||
if (chunk->get_voxel(x + 1, y, z - 1, _channel_index_type) != 0)
|
|
||||||
neighbours = neighbours | TERRA_NEIGHBOUR_RIGHT_FRONT;
|
|
||||||
|
|
||||||
if (chunk->get_voxel(x + 1, y + 1, z, _channel_index_type) != 0)
|
|
||||||
neighbours = neighbours | TERRA_NEIGHBOUR_TOP_RIGHT;
|
|
||||||
|
|
||||||
if (chunk->get_voxel(x, y + 1, z - 1, _channel_index_type) != 0)
|
|
||||||
neighbours = neighbours | TERRA_NEIGHBOUR_TOP_FRONT;
|
|
||||||
|
|
||||||
if (chunk->get_voxel(x + 1, y + 1, z - 1, _channel_index_type) != 0)
|
|
||||||
neighbours = neighbours | TERRA_NEIGHBOUR_TOP_RIGHT_FRONT;*/
|
|
||||||
|
|
||||||
_point_neighbours[P110] = neighbours;
|
|
||||||
|
|
||||||
neighbours = 0;
|
|
||||||
x = _x;
|
|
||||||
y = _y;
|
|
||||||
z = _z + 1;
|
|
||||||
|
|
||||||
//001
|
|
||||||
if (chunk->get_voxel(x - 1, y, z, _channel_index_type) != 0)
|
|
||||||
neighbours = neighbours | TERRA_NEIGHBOUR_LEFT;
|
|
||||||
|
|
||||||
if (chunk->get_voxel(x, y - 1, z, _channel_index_type) != 0)
|
|
||||||
neighbours = neighbours | TERRA_NEIGHBOUR_BOTTOM;
|
|
||||||
|
|
||||||
if (chunk->get_voxel(x, y, z + 1, _channel_index_type) != 0)
|
|
||||||
neighbours = neighbours | TERRA_NEIGHBOUR_BACK;
|
|
||||||
/*
|
|
||||||
if (chunk->get_voxel(x - 1, y, z + 1, _channel_index_type) != 0)
|
|
||||||
neighbours = neighbours | TERRA_NEIGHBOUR_LEFT_BACK;
|
|
||||||
|
|
||||||
if (chunk->get_voxel(x - 1, y - 1, z, _channel_index_type) != 0)
|
|
||||||
neighbours = neighbours | TERRA_NEIGHBOUR_BOTTOM_LEFT;
|
|
||||||
|
|
||||||
if (chunk->get_voxel(x, y - 1, z + 1, _channel_index_type) != 0)
|
|
||||||
neighbours = neighbours | TERRA_NEIGHBOUR_BOTTOM_BACK;
|
|
||||||
|
|
||||||
if (chunk->get_voxel(x - 1, y - 1, z + 1, _channel_index_type) != 0)
|
|
||||||
neighbours = neighbours | TERRA_NEIGHBOUR_BOTTOM_LEFT_BACK;*/
|
|
||||||
|
|
||||||
_point_neighbours[P001] = neighbours;
|
|
||||||
|
|
||||||
neighbours = 0;
|
|
||||||
x = _x + 1;
|
|
||||||
y = _y;
|
|
||||||
z = _z + 1;
|
|
||||||
|
|
||||||
//101
|
|
||||||
if (chunk->get_voxel(x + 1, y, z, _channel_index_type) != 0)
|
|
||||||
neighbours = neighbours | TERRA_NEIGHBOUR_RIGHT;
|
|
||||||
|
|
||||||
if (chunk->get_voxel(x, y - 1, z, _channel_index_type) != 0)
|
|
||||||
neighbours = neighbours | TERRA_NEIGHBOUR_BOTTOM;
|
|
||||||
|
|
||||||
if (chunk->get_voxel(x, y, z + 1, _channel_index_type) != 0)
|
|
||||||
neighbours = neighbours | TERRA_NEIGHBOUR_BACK;
|
|
||||||
/*
|
|
||||||
if (chunk->get_voxel(x + 1, y, z + 1, _channel_index_type) != 0)
|
|
||||||
neighbours = neighbours | TERRA_NEIGHBOUR_RIGHT_BACK;
|
|
||||||
|
|
||||||
if (chunk->get_voxel(x + 1, y - 1, z, _channel_index_type) != 0)
|
|
||||||
neighbours = neighbours | TERRA_NEIGHBOUR_BOTTOM_RIGHT;
|
|
||||||
|
|
||||||
if (chunk->get_voxel(x, y - 1, z + 1, _channel_index_type) != 0)
|
|
||||||
neighbours = neighbours | TERRA_NEIGHBOUR_BOTTOM_BACK;
|
|
||||||
|
|
||||||
if (chunk->get_voxel(x + 1, y - 1, z + 1, _channel_index_type) != 0)
|
|
||||||
neighbours = neighbours | TERRA_NEIGHBOUR_BOTTOM_RIGHT_BACK;*/
|
|
||||||
|
|
||||||
_point_neighbours[P101] = neighbours;
|
|
||||||
|
|
||||||
neighbours = 0;
|
|
||||||
x = _x;
|
|
||||||
y = _y + 1;
|
|
||||||
z = _z + 1;
|
|
||||||
|
|
||||||
//011
|
|
||||||
if (chunk->get_voxel(x - 1, y, z, _channel_index_type) != 0)
|
|
||||||
neighbours = neighbours | TERRA_NEIGHBOUR_LEFT;
|
|
||||||
|
|
||||||
if (chunk->get_voxel(x, y + 1, z, _channel_index_type) != 0)
|
|
||||||
neighbours = neighbours | TERRA_NEIGHBOUR_TOP;
|
|
||||||
|
|
||||||
if (chunk->get_voxel(x, y, z + 1, _channel_index_type) != 0)
|
|
||||||
neighbours = neighbours | TERRA_NEIGHBOUR_BACK;
|
|
||||||
/*
|
|
||||||
if (chunk->get_voxel(x - 1, y, z + 1, _channel_index_type) != 0)
|
|
||||||
neighbours = neighbours | TERRA_NEIGHBOUR_LEFT_BACK;
|
|
||||||
|
|
||||||
if (chunk->get_voxel(x - 1, y + 1, z, _channel_index_type) != 0)
|
|
||||||
neighbours = neighbours | TERRA_NEIGHBOUR_TOP_LEFT;
|
|
||||||
|
|
||||||
if (chunk->get_voxel(x, y + 1, z + 1, _channel_index_type) != 0)
|
|
||||||
neighbours = neighbours | TERRA_NEIGHBOUR_TOP_BACK;
|
|
||||||
|
|
||||||
if (chunk->get_voxel(x - 1, y + 1, z + 1, _channel_index_type) != 0)
|
|
||||||
neighbours = neighbours | TERRA_NEIGHBOUR_TOP_LEFT_BACK;*/
|
|
||||||
|
|
||||||
_point_neighbours[P011] = neighbours;
|
|
||||||
|
|
||||||
neighbours = 0;
|
|
||||||
x = _x + 1;
|
|
||||||
y = _y + 1;
|
|
||||||
z = _z + 1;
|
|
||||||
|
|
||||||
//111
|
|
||||||
if (chunk->get_voxel(x + 1, y, z, _channel_index_type) != 0)
|
|
||||||
neighbours = neighbours | TERRA_NEIGHBOUR_RIGHT;
|
|
||||||
|
|
||||||
if (chunk->get_voxel(x, y + 1, z, _channel_index_type) != 0)
|
|
||||||
neighbours = neighbours | TERRA_NEIGHBOUR_TOP;
|
|
||||||
|
|
||||||
if (chunk->get_voxel(x, y, z + 1, _channel_index_type) != 0)
|
|
||||||
neighbours = neighbours | TERRA_NEIGHBOUR_BACK;
|
|
||||||
/*
|
|
||||||
if (chunk->get_voxel(x + 1, y, z + 1, _channel_index_type) != 0)
|
|
||||||
neighbours = neighbours | TERRA_NEIGHBOUR_RIGHT_BACK;
|
|
||||||
|
|
||||||
if (chunk->get_voxel(x + 1, y + 1, z, _channel_index_type) != 0)
|
|
||||||
neighbours = neighbours | TERRA_NEIGHBOUR_TOP_RIGHT;
|
|
||||||
|
|
||||||
if (chunk->get_voxel(x, y + 1, z + 1, _channel_index_type) != 0)
|
|
||||||
neighbours = neighbours | TERRA_NEIGHBOUR_TOP_BACK;
|
|
||||||
|
|
||||||
if (chunk->get_voxel(x + 1, y + 1, z + 1, _channel_index_type) != 0)
|
|
||||||
neighbours = neighbours | TERRA_NEIGHBOUR_TOP_RIGHT_BACK;*/
|
|
||||||
|
|
||||||
_point_neighbours[P111] = neighbours;
|
|
||||||
}
|
|
||||||
|
|
||||||
void TerraCubePoints::setup(Ref<TerraChunk> chunk, int x, int y, int z, int size) {
|
|
||||||
ERR_FAIL_COND(!chunk.is_valid());
|
|
||||||
ERR_FAIL_COND(size <= 0);
|
|
||||||
ERR_FAIL_COND(!chunk->validate_data_position(x + size, y + size, z + size) || !chunk->validate_data_position(x, y, z));
|
|
||||||
|
|
||||||
reset();
|
|
||||||
|
|
||||||
_x = x;
|
|
||||||
_y = y;
|
|
||||||
_z = z;
|
|
||||||
_size = size;
|
|
||||||
|
|
||||||
_point_types[P000] = chunk->get_voxel(x, y, z, _channel_index_type);
|
|
||||||
_point_types[P100] = chunk->get_voxel(x + size, y, z, _channel_index_type);
|
|
||||||
_point_types[P010] = chunk->get_voxel(x, y + size, z, _channel_index_type);
|
|
||||||
_point_types[P001] = chunk->get_voxel(x, y, z + size, _channel_index_type);
|
|
||||||
_point_types[P110] = chunk->get_voxel(x + size, y + size, z, _channel_index_type);
|
|
||||||
_point_types[P011] = chunk->get_voxel(x, y + size, z + size, _channel_index_type);
|
|
||||||
_point_types[P101] = chunk->get_voxel(x + size, y, z + size, _channel_index_type);
|
|
||||||
_point_types[P111] = chunk->get_voxel(x + size, y + size, z + size, _channel_index_type);
|
|
||||||
|
|
||||||
if (!has_points())
|
|
||||||
return;
|
|
||||||
|
|
||||||
//for (int i = 0; i < 8; ++i) {
|
|
||||||
// if (_point_types[i] == 0) {
|
|
||||||
// _point_types[i] = 1;
|
|
||||||
// }
|
|
||||||
//}
|
|
||||||
|
|
||||||
_point_fills[P000] = chunk->get_voxel(x, y, z, _channel_index_isolevel);
|
|
||||||
_point_fills[P100] = chunk->get_voxel(x + size, y, z, _channel_index_isolevel);
|
|
||||||
_point_fills[P010] = chunk->get_voxel(x, y + size, z, _channel_index_isolevel);
|
|
||||||
_point_fills[P001] = chunk->get_voxel(x, y, z + size, _channel_index_isolevel);
|
|
||||||
_point_fills[P110] = chunk->get_voxel(x + size, y + size, z, _channel_index_isolevel);
|
|
||||||
_point_fills[P011] = chunk->get_voxel(x, y + size, z + size, _channel_index_isolevel);
|
|
||||||
_point_fills[P101] = chunk->get_voxel(x + size, y, z + size, _channel_index_isolevel);
|
|
||||||
_point_fills[P111] = chunk->get_voxel(x + size, y + size, z + size, _channel_index_isolevel);
|
|
||||||
|
|
||||||
//for (int i = 0; i < 8; ++i) {
|
|
||||||
// if (_point_fills[i] == 0) {
|
|
||||||
// _point_fills[i] = 1;
|
|
||||||
// }
|
|
||||||
//}
|
|
||||||
|
|
||||||
_point_aos[P000] = chunk->get_voxel(x, y, z, TerraChunkDefault::DEFAULT_CHANNEL_AO);
|
|
||||||
_point_aos[P100] = chunk->get_voxel(x + size, y, z, TerraChunkDefault::DEFAULT_CHANNEL_AO);
|
|
||||||
_point_aos[P010] = chunk->get_voxel(x, y + size, z, TerraChunkDefault::DEFAULT_CHANNEL_AO);
|
|
||||||
_point_aos[P001] = chunk->get_voxel(x, y, z + size, TerraChunkDefault::DEFAULT_CHANNEL_AO);
|
|
||||||
_point_aos[P110] = chunk->get_voxel(x + size, y + size, z, TerraChunkDefault::DEFAULT_CHANNEL_AO);
|
|
||||||
_point_aos[P011] = chunk->get_voxel(x, y + size, z + size, TerraChunkDefault::DEFAULT_CHANNEL_AO);
|
|
||||||
_point_aos[P101] = chunk->get_voxel(x + size, y, z + size, TerraChunkDefault::DEFAULT_CHANNEL_AO);
|
|
||||||
_point_aos[P111] = chunk->get_voxel(x + size, y + size, z + size, TerraChunkDefault::DEFAULT_CHANNEL_AO);
|
|
||||||
|
|
||||||
_point_colors[P000] = Color(chunk->get_voxel(x, y, z, TerraChunkDefault::DEFAULT_CHANNEL_LIGHT_COLOR_R) / 255.0, chunk->get_voxel(x, y, z, TerraChunkDefault::DEFAULT_CHANNEL_LIGHT_COLOR_G) / 255.0, chunk->get_voxel(x, y, z, TerraChunkDefault::DEFAULT_CHANNEL_LIGHT_COLOR_B) / 255.0);
|
|
||||||
_point_colors[P100] = Color(chunk->get_voxel(x + size, y, z, TerraChunkDefault::DEFAULT_CHANNEL_LIGHT_COLOR_R) / 255.0, chunk->get_voxel(x + size, y, z, TerraChunkDefault::DEFAULT_CHANNEL_LIGHT_COLOR_G) / 255.0, chunk->get_voxel(x + size, y, z, TerraChunkDefault::DEFAULT_CHANNEL_LIGHT_COLOR_B) / 255.0);
|
|
||||||
_point_colors[P010] = Color(chunk->get_voxel(x, y + size, z, TerraChunkDefault::DEFAULT_CHANNEL_LIGHT_COLOR_R) / 255.0, chunk->get_voxel(x, y + size, z, TerraChunkDefault::DEFAULT_CHANNEL_LIGHT_COLOR_G) / 255.0, chunk->get_voxel(x, y + size, z, TerraChunkDefault::DEFAULT_CHANNEL_LIGHT_COLOR_B) / 255.0);
|
|
||||||
_point_colors[P001] = Color(chunk->get_voxel(x, y, z + size, TerraChunkDefault::DEFAULT_CHANNEL_LIGHT_COLOR_R) / 255.0, chunk->get_voxel(x, y, z + size, TerraChunkDefault::DEFAULT_CHANNEL_LIGHT_COLOR_G) / 255.0, chunk->get_voxel(x, y, z + size, TerraChunkDefault::DEFAULT_CHANNEL_LIGHT_COLOR_B) / 255.0);
|
|
||||||
_point_colors[P110] = Color(chunk->get_voxel(x + size, y + size, z, TerraChunkDefault::DEFAULT_CHANNEL_LIGHT_COLOR_R) / 255.0, chunk->get_voxel(x + size, y + size, z, TerraChunkDefault::DEFAULT_CHANNEL_LIGHT_COLOR_G) / 255.0, chunk->get_voxel(x + size, y + size, z, TerraChunkDefault::DEFAULT_CHANNEL_LIGHT_COLOR_B) / 255.0);
|
|
||||||
_point_colors[P011] = Color(chunk->get_voxel(x, y + size, z + size, TerraChunkDefault::DEFAULT_CHANNEL_LIGHT_COLOR_R) / 255.0, chunk->get_voxel(x, y + size, z + size, TerraChunkDefault::DEFAULT_CHANNEL_LIGHT_COLOR_G) / 255.0, chunk->get_voxel(x, y + size, z + size, TerraChunkDefault::DEFAULT_CHANNEL_LIGHT_COLOR_B) / 255.0);
|
|
||||||
_point_colors[P101] = Color(chunk->get_voxel(x + size, y, z + size, TerraChunkDefault::DEFAULT_CHANNEL_LIGHT_COLOR_R) / 255.0, chunk->get_voxel(x + size, y, z + size, TerraChunkDefault::DEFAULT_CHANNEL_LIGHT_COLOR_G) / 255.0, chunk->get_voxel(x + size, y, z + size, TerraChunkDefault::DEFAULT_CHANNEL_LIGHT_COLOR_B) / 255.0);
|
|
||||||
_point_colors[P111] = Color(chunk->get_voxel(x + size, y + size, z + size, TerraChunkDefault::DEFAULT_CHANNEL_LIGHT_COLOR_R) / 255.0, chunk->get_voxel(x + size, y + size, z + size, TerraChunkDefault::DEFAULT_CHANNEL_LIGHT_COLOR_G) / 255.0, chunk->get_voxel(x + size, y + size, z + size, TerraChunkDefault::DEFAULT_CHANNEL_LIGHT_COLOR_B) / 255.0);
|
|
||||||
|
|
||||||
refresh_neighbours(chunk);
|
|
||||||
|
|
||||||
refresh_points();
|
|
||||||
}
|
|
||||||
|
|
||||||
void TerraCubePoints::reset() {
|
|
||||||
for (int i = 0; i < POINT_COUNT; ++i) {
|
|
||||||
_point_types[i] = 0;
|
|
||||||
_point_fills[i] = 0;
|
|
||||||
_point_neighbours[i] = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
_x = 0;
|
|
||||||
_y = 0;
|
|
||||||
_z = 0;
|
|
||||||
_size = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
int TerraCubePoints::get_point_index(int face, int index) {
|
|
||||||
ERR_FAIL_INDEX_V(face, TERRA_FACE_COUNT, 0);
|
|
||||||
ERR_FAIL_INDEX_V(index, 4, 0);
|
|
||||||
|
|
||||||
return index_table[face][index];
|
|
||||||
}
|
|
||||||
|
|
||||||
Vector2 TerraCubePoints::get_point_uv_direction(int face, int index) {
|
|
||||||
ERR_FAIL_INDEX_V(face, TERRA_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 TerraCubePoints::get_points_for_face(int face, int index) {
|
|
||||||
return _points[get_point_index(face, index)];
|
|
||||||
}
|
|
||||||
|
|
||||||
bool TerraCubePoints::is_face_visible(int face) {
|
|
||||||
ERR_FAIL_INDEX_V(face, TERRA_FACE_COUNT, false);
|
|
||||||
|
|
||||||
int target_neighbour = visibility_check_table[face];
|
|
||||||
|
|
||||||
for (int i = 0; i < 4; ++i) {
|
|
||||||
int indx = get_point_index(face, i);
|
|
||||||
int neighbour_mask = _point_neighbours[indx];
|
|
||||||
|
|
||||||
if ((neighbour_mask & target_neighbour) == 0)
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool TerraCubePoints::is_sub_voxel_point(int x, int y, int z) {
|
|
||||||
for (int i = 0; i < POINT_COUNT; i += 1) {
|
|
||||||
if (get_point(i) == Vector3(x, y, z)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
void TerraCubePoints::set_point(int point, int x, int y, int z) {
|
|
||||||
_points[point] = Vector3(x, y, z);
|
|
||||||
}
|
|
||||||
|
|
||||||
int TerraCubePoints::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;
|
|
||||||
}
|
|
||||||
|
|
||||||
Vector3 TerraCubePoints::get_point_for_face(int face, int index) {
|
|
||||||
int indx = get_point_index(face, index);
|
|
||||||
|
|
||||||
return _points[indx];
|
|
||||||
}
|
|
||||||
|
|
||||||
Vector3 TerraCubePoints::get_vertex_vector3_for_point(int face, int index) {
|
|
||||||
int point_index = get_point_index(face, index);
|
|
||||||
|
|
||||||
Vector3 a = get_point(point_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;
|
|
||||||
}
|
|
||||||
|
|
||||||
int TerraCubePoints::get_point_type(int index) {
|
|
||||||
ERR_FAIL_INDEX_V(index, POINT_COUNT, 0);
|
|
||||||
|
|
||||||
return _point_types[index];
|
|
||||||
}
|
|
||||||
|
|
||||||
int TerraCubePoints::get_point_fill(int index) {
|
|
||||||
ERR_FAIL_INDEX_V(index, POINT_COUNT, 0);
|
|
||||||
|
|
||||||
return _point_fills[index];
|
|
||||||
}
|
|
||||||
|
|
||||||
int TerraCubePoints::get_point_neighbours(int index) {
|
|
||||||
ERR_FAIL_INDEX_V(index, POINT_COUNT, 0);
|
|
||||||
|
|
||||||
return _point_neighbours[index];
|
|
||||||
}
|
|
||||||
|
|
||||||
int TerraCubePoints::get_point_ao(int index) {
|
|
||||||
ERR_FAIL_INDEX_V(index, POINT_COUNT, 0);
|
|
||||||
|
|
||||||
return _point_aos[index];
|
|
||||||
}
|
|
||||||
|
|
||||||
int TerraCubePoints::get_face_point_ao(int face, int index) {
|
|
||||||
int indx = get_point_index(face, index);
|
|
||||||
|
|
||||||
return _point_aos[indx];
|
|
||||||
}
|
|
||||||
|
|
||||||
Color TerraCubePoints::get_face_point_ao_color(int face, int index) {
|
|
||||||
int indx = get_point_index(face, index);
|
|
||||||
|
|
||||||
float ao_value = (_point_aos[indx] / 255.0) * 0.75;
|
|
||||||
|
|
||||||
return Color(ao_value, ao_value, ao_value);
|
|
||||||
}
|
|
||||||
|
|
||||||
Color TerraCubePoints::get_face_point_light_color(int face, int index) {
|
|
||||||
int indx = get_point_index(face, index);
|
|
||||||
|
|
||||||
return _point_colors[indx];
|
|
||||||
}
|
|
||||||
Color TerraCubePoints::get_face_point_color_mixed(int face, int index) {
|
|
||||||
int indx = get_point_index(face, index);
|
|
||||||
|
|
||||||
float ao_value = (_point_aos[indx] / 255.0) * 0.75;
|
|
||||||
|
|
||||||
return _point_colors[indx] - Color(ao_value, ao_value, ao_value);
|
|
||||||
}
|
|
||||||
|
|
||||||
Vector3 TerraCubePoints::get_face_light_direction(int face) {
|
|
||||||
ERR_FAIL_INDEX_V(face, TERRA_FACE_COUNT, Vector3());
|
|
||||||
|
|
||||||
return Vector3(face_light_direction_table[face][0], face_light_direction_table[face][1], face_light_direction_table[face][2]);
|
|
||||||
}
|
|
||||||
|
|
||||||
Vector3 TerraCubePoints::get_point(int index) {
|
|
||||||
ERR_FAIL_INDEX_V(index, POINT_COUNT, Vector3());
|
|
||||||
|
|
||||||
return _points[index];
|
|
||||||
}
|
|
||||||
|
|
||||||
Vector3 TerraCubePoints::get_top_left_point(int face) {
|
|
||||||
if (face == TERRA_FACE_BACK) {
|
|
||||||
return _points[P011];
|
|
||||||
}
|
|
||||||
if (face == TERRA_FACE_FRONT) {
|
|
||||||
return _points[P010];
|
|
||||||
}
|
|
||||||
if (face == TERRA_FACE_RIGHT) {
|
|
||||||
return _points[P111];
|
|
||||||
}
|
|
||||||
if (face == TERRA_FACE_LEFT) {
|
|
||||||
return _points[P010];
|
|
||||||
}
|
|
||||||
if (face == TERRA_FACE_TOP) {
|
|
||||||
return _points[P010];
|
|
||||||
}
|
|
||||||
if (face == TERRA_FACE_BOTTOM) {
|
|
||||||
return _points[P000];
|
|
||||||
}
|
|
||||||
return _points[0];
|
|
||||||
}
|
|
||||||
|
|
||||||
Vector3 TerraCubePoints::get_top_right_point(int face) {
|
|
||||||
if (face == TERRA_FACE_BACK) {
|
|
||||||
return _points[P111];
|
|
||||||
}
|
|
||||||
if (face == TERRA_FACE_FRONT) {
|
|
||||||
return _points[P110];
|
|
||||||
}
|
|
||||||
if (face == TERRA_FACE_RIGHT) {
|
|
||||||
return _points[P110];
|
|
||||||
}
|
|
||||||
if (face == TERRA_FACE_LEFT) {
|
|
||||||
return _points[P011];
|
|
||||||
}
|
|
||||||
if (face == TERRA_FACE_TOP) {
|
|
||||||
return _points[P110];
|
|
||||||
}
|
|
||||||
if (face == TERRA_FACE_BOTTOM) {
|
|
||||||
return _points[P100];
|
|
||||||
}
|
|
||||||
return _points[0];
|
|
||||||
}
|
|
||||||
|
|
||||||
Vector3 TerraCubePoints::get_bottom_left_point(int face) {
|
|
||||||
if (face == TERRA_FACE_BACK) {
|
|
||||||
return _points[P001];
|
|
||||||
}
|
|
||||||
if (face == TERRA_FACE_FRONT) {
|
|
||||||
return _points[P000];
|
|
||||||
}
|
|
||||||
if (face == TERRA_FACE_RIGHT) {
|
|
||||||
return _points[P101];
|
|
||||||
}
|
|
||||||
if (face == TERRA_FACE_LEFT) {
|
|
||||||
return _points[P001];
|
|
||||||
}
|
|
||||||
if (face == TERRA_FACE_TOP) {
|
|
||||||
return _points[P011];
|
|
||||||
}
|
|
||||||
if (face == TERRA_FACE_BOTTOM) {
|
|
||||||
return _points[P001];
|
|
||||||
}
|
|
||||||
return _points[0];
|
|
||||||
}
|
|
||||||
|
|
||||||
Vector3 TerraCubePoints::get_bottom_right_point(int face) {
|
|
||||||
if (face == TERRA_FACE_BACK) {
|
|
||||||
return _points[P101];
|
|
||||||
}
|
|
||||||
if (face == TERRA_FACE_FRONT) {
|
|
||||||
return _points[P100];
|
|
||||||
}
|
|
||||||
if (face == TERRA_FACE_RIGHT) {
|
|
||||||
return _points[P100];
|
|
||||||
}
|
|
||||||
if (face == TERRA_FACE_LEFT) {
|
|
||||||
return _points[P001];
|
|
||||||
}
|
|
||||||
if (face == TERRA_FACE_TOP) {
|
|
||||||
return _points[P111];
|
|
||||||
}
|
|
||||||
if (face == TERRA_FACE_BOTTOM) {
|
|
||||||
return _points[P101];
|
|
||||||
}
|
|
||||||
return _points[P000];
|
|
||||||
}
|
|
||||||
|
|
||||||
uint8_t TerraCubePoints::get_face_type(int face) {
|
|
||||||
if (face == TERRA_FACE_BACK) {
|
|
||||||
return _point_types[P111];
|
|
||||||
}
|
|
||||||
if (face == TERRA_FACE_FRONT) {
|
|
||||||
return _point_types[P110];
|
|
||||||
}
|
|
||||||
if (face == TERRA_FACE_RIGHT) {
|
|
||||||
return _point_types[P110];
|
|
||||||
}
|
|
||||||
if (face == TERRA_FACE_LEFT) {
|
|
||||||
return _point_types[P011];
|
|
||||||
}
|
|
||||||
if (face == TERRA_FACE_TOP) {
|
|
||||||
return _point_types[P110];
|
|
||||||
}
|
|
||||||
if (face == TERRA_FACE_BOTTOM) {
|
|
||||||
return _point_types[P100];
|
|
||||||
}
|
|
||||||
return _point_types[0];
|
|
||||||
}
|
|
||||||
|
|
||||||
bool TerraCubePoints::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);
|
|
||||||
|
|
||||||
//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);
|
|
||||||
}
|
|
||||||
|
|
||||||
int TerraCubePoints::get_opposite_face(int face) {
|
|
||||||
if (face == TERRA_FACE_FRONT) {
|
|
||||||
return TERRA_FACE_BACK;
|
|
||||||
}
|
|
||||||
if (face == TERRA_FACE_BACK) {
|
|
||||||
return TERRA_FACE_FRONT;
|
|
||||||
}
|
|
||||||
if (face == TERRA_FACE_LEFT) {
|
|
||||||
return TERRA_FACE_RIGHT;
|
|
||||||
}
|
|
||||||
if (face == TERRA_FACE_RIGHT) {
|
|
||||||
return TERRA_FACE_LEFT;
|
|
||||||
}
|
|
||||||
if (face == TERRA_FACE_TOP) {
|
|
||||||
return TERRA_FACE_BOTTOM;
|
|
||||||
}
|
|
||||||
|
|
||||||
return TERRA_FACE_BOTTOM;
|
|
||||||
}
|
|
||||||
|
|
||||||
TerraCubePoints::TerraCubePoints() {
|
|
||||||
_channel_index_type = 0;
|
|
||||||
_channel_index_isolevel = 0;
|
|
||||||
|
|
||||||
reset();
|
|
||||||
}
|
|
||||||
|
|
||||||
TerraCubePoints::~TerraCubePoints() {
|
|
||||||
}
|
|
||||||
|
|
||||||
void TerraCubePoints::_bind_methods() {
|
|
||||||
|
|
||||||
ClassDB::bind_method(D_METHOD("get_x"), &TerraCubePoints::get_x);
|
|
||||||
ClassDB::bind_method(D_METHOD("set_x", "value"), &TerraCubePoints::set_x);
|
|
||||||
ADD_PROPERTY(PropertyInfo(Variant::INT, "x"), "set_x", "get_x");
|
|
||||||
|
|
||||||
ClassDB::bind_method(D_METHOD("get_y"), &TerraCubePoints::get_y);
|
|
||||||
ClassDB::bind_method(D_METHOD("set_y", "value"), &TerraCubePoints::set_y);
|
|
||||||
ADD_PROPERTY(PropertyInfo(Variant::INT, "y"), "set_y", "get_y");
|
|
||||||
|
|
||||||
ClassDB::bind_method(D_METHOD("get_z"), &TerraCubePoints::get_z);
|
|
||||||
ClassDB::bind_method(D_METHOD("set_z", "value"), &TerraCubePoints::set_z);
|
|
||||||
ADD_PROPERTY(PropertyInfo(Variant::INT, "z"), "set_z", "get_z");
|
|
||||||
|
|
||||||
ClassDB::bind_method(D_METHOD("get_size"), &TerraCubePoints::get_size);
|
|
||||||
ClassDB::bind_method(D_METHOD("set_size", "value"), &TerraCubePoints::set_size);
|
|
||||||
ADD_PROPERTY(PropertyInfo(Variant::INT, "size"), "set_size", "get_size");
|
|
||||||
|
|
||||||
ClassDB::bind_method(D_METHOD("get_channel_index_type"), &TerraCubePoints::get_channel_index_type);
|
|
||||||
ClassDB::bind_method(D_METHOD("set_channel_index_type", "value"), &TerraCubePoints::set_channel_index_type);
|
|
||||||
ADD_PROPERTY(PropertyInfo(Variant::INT, "channel_index_type"), "set_channel_index_type", "get_channel_index_type");
|
|
||||||
|
|
||||||
ClassDB::bind_method(D_METHOD("get_channel_index_isolevel"), &TerraCubePoints::get_channel_index_isolevel);
|
|
||||||
ClassDB::bind_method(D_METHOD("set_channel_index_isolevel", "value"), &TerraCubePoints::set_channel_index_isolevel);
|
|
||||||
ADD_PROPERTY(PropertyInfo(Variant::INT, "channel_index_isolevel"), "set_channel_index_isolevel", "get_channel_index_isolevel");
|
|
||||||
|
|
||||||
ClassDB::bind_method(D_METHOD("refresh_points"), &TerraCubePoints::refresh_points);
|
|
||||||
ClassDB::bind_method(D_METHOD("setup", "chunk", "x", "y", "z", "size"), &TerraCubePoints::setup, DEFVAL(1));
|
|
||||||
|
|
||||||
ClassDB::bind_method(D_METHOD("get_point_index", "face", "index"), &TerraCubePoints::get_point_index);
|
|
||||||
ClassDB::bind_method(D_METHOD("get_point_uv_direction", "face", "index"), &TerraCubePoints::get_point_uv_direction);
|
|
||||||
|
|
||||||
ClassDB::bind_method(D_METHOD("get_points_for_face", "face", "index"), &TerraCubePoints::get_points_for_face);
|
|
||||||
|
|
||||||
ClassDB::bind_method(D_METHOD("is_face_visible", "face"), &TerraCubePoints::is_face_visible);
|
|
||||||
|
|
||||||
ClassDB::bind_method(D_METHOD("is_sub_voxel_point", "x", "y", "z"), &TerraCubePoints::is_sub_voxel_point);
|
|
||||||
ClassDB::bind_method(D_METHOD("set_point", "point", "x", "y", "z"), &TerraCubePoints::set_point);
|
|
||||||
ClassDB::bind_method(D_METHOD("get_point_id", "x", "y", "z"), &TerraCubePoints::get_point_id);
|
|
||||||
|
|
||||||
ClassDB::bind_method(D_METHOD("get_point_for_face", "face", "index"), &TerraCubePoints::get_point_for_face);
|
|
||||||
ClassDB::bind_method(D_METHOD("get_vertex_vector3_for_point", "face", "index"), &TerraCubePoints::get_vertex_vector3_for_point);
|
|
||||||
|
|
||||||
ClassDB::bind_method(D_METHOD("get_point_type", "index"), &TerraCubePoints::get_point_type);
|
|
||||||
ClassDB::bind_method(D_METHOD("get_point_fill", "index"), &TerraCubePoints::get_point_fill);
|
|
||||||
ClassDB::bind_method(D_METHOD("get_point_neighbours", "index"), &TerraCubePoints::get_point_neighbours);
|
|
||||||
|
|
||||||
ClassDB::bind_method(D_METHOD("get_point_ao", "index"), &TerraCubePoints::get_point_ao);
|
|
||||||
ClassDB::bind_method(D_METHOD("get_face_point_ao", "face", "index"), &TerraCubePoints::get_face_point_ao);
|
|
||||||
ClassDB::bind_method(D_METHOD("get_face_point_ao_color", "face", "index"), &TerraCubePoints::get_face_point_ao_color);
|
|
||||||
ClassDB::bind_method(D_METHOD("get_face_point_light_color", "face", "index"), &TerraCubePoints::get_face_point_light_color);
|
|
||||||
ClassDB::bind_method(D_METHOD("get_face_point_color_mixed", "face", "index"), &TerraCubePoints::get_face_point_color_mixed);
|
|
||||||
|
|
||||||
ClassDB::bind_method(D_METHOD("get_face_light_direction", "face"), &TerraCubePoints::get_face_light_direction);
|
|
||||||
|
|
||||||
ClassDB::bind_method(D_METHOD("get_point", "index"), &TerraCubePoints::get_point);
|
|
||||||
|
|
||||||
ClassDB::bind_method(D_METHOD("get_top_left_point", "face"), &TerraCubePoints::get_top_left_point);
|
|
||||||
ClassDB::bind_method(D_METHOD("get_top_right_point", "face"), &TerraCubePoints::get_top_right_point);
|
|
||||||
ClassDB::bind_method(D_METHOD("get_bottom_left_point", "face"), &TerraCubePoints::get_bottom_left_point);
|
|
||||||
ClassDB::bind_method(D_METHOD("get_bottom_right_point", "face"), &TerraCubePoints::get_bottom_right_point);
|
|
||||||
|
|
||||||
ClassDB::bind_method(D_METHOD("get_face_type", "face"), &TerraCubePoints::get_face_type);
|
|
||||||
|
|
||||||
ClassDB::bind_method(D_METHOD("has_points"), &TerraCubePoints::has_points);
|
|
||||||
ClassDB::bind_method(D_METHOD("get_opposite_face", "face"), &TerraCubePoints::get_opposite_face);
|
|
||||||
|
|
||||||
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(TERRA_FACE_FRONT);
|
|
||||||
BIND_ENUM_CONSTANT(TERRA_FACE_RIGHT);
|
|
||||||
BIND_ENUM_CONSTANT(TERRA_FACE_BACK);
|
|
||||||
BIND_ENUM_CONSTANT(TERRA_FACE_LEFT);
|
|
||||||
BIND_ENUM_CONSTANT(TERRA_FACE_TOP);
|
|
||||||
BIND_ENUM_CONSTANT(TERRA_FACE_BOTTOM);
|
|
||||||
BIND_ENUM_CONSTANT(TERRA_FACE_COUNT);
|
|
||||||
|
|
||||||
BIND_ENUM_CONSTANT(TERRA_NEIGHBOUR_NONE);
|
|
||||||
|
|
||||||
BIND_ENUM_CONSTANT(TERRA_NEIGHBOUR_LEFT);
|
|
||||||
BIND_ENUM_CONSTANT(TERRA_NEIGHBOUR_RIGHT);
|
|
||||||
BIND_ENUM_CONSTANT(TERRA_NEIGHBOUR_FRONT);
|
|
||||||
BIND_ENUM_CONSTANT(TERRA_NEIGHBOUR_BACK);
|
|
||||||
BIND_ENUM_CONSTANT(TERRA_NEIGHBOUR_TOP);
|
|
||||||
BIND_ENUM_CONSTANT(TERRA_NEIGHBOUR_BOTTOM);
|
|
||||||
|
|
||||||
BIND_ENUM_CONSTANT(TERRA_NEIGHBOUR_LEFT_FRONT);
|
|
||||||
BIND_ENUM_CONSTANT(TERRA_NEIGHBOUR_LEFT_BACK);
|
|
||||||
BIND_ENUM_CONSTANT(TERRA_NEIGHBOUR_RIGHT_FRONT);
|
|
||||||
BIND_ENUM_CONSTANT(TERRA_NEIGHBOUR_RIGHT_BACK);
|
|
||||||
|
|
||||||
BIND_ENUM_CONSTANT(TERRA_NEIGHBOUR_TOP_LEFT);
|
|
||||||
BIND_ENUM_CONSTANT(TERRA_NEIGHBOUR_TOP_RIGHT);
|
|
||||||
BIND_ENUM_CONSTANT(TERRA_NEIGHBOUR_TOP_FRONT);
|
|
||||||
BIND_ENUM_CONSTANT(TERRA_NEIGHBOUR_TOP_BACK);
|
|
||||||
|
|
||||||
BIND_ENUM_CONSTANT(TERRA_NEIGHBOUR_BOTTOM_LEFT);
|
|
||||||
BIND_ENUM_CONSTANT(TERRA_NEIGHBOUR_BOTTOM_RIGHT);
|
|
||||||
BIND_ENUM_CONSTANT(TERRA_NEIGHBOUR_BOTTOM_FRONT);
|
|
||||||
BIND_ENUM_CONSTANT(TERRA_NEIGHBOUR_BOTTOM_BACK);
|
|
||||||
|
|
||||||
BIND_ENUM_CONSTANT(TERRA_NEIGHBOUR_BOTTOM_LEFT_FRONT);
|
|
||||||
BIND_ENUM_CONSTANT(TERRA_NEIGHBOUR_BOTTOM_LEFT_BACK);
|
|
||||||
BIND_ENUM_CONSTANT(TERRA_NEIGHBOUR_BOTTOM_RIGHT_FRONT);
|
|
||||||
BIND_ENUM_CONSTANT(TERRA_NEIGHBOUR_BOTTOM_RIGHT_BACK);
|
|
||||||
|
|
||||||
BIND_ENUM_CONSTANT(TERRA_NEIGHBOUR_TOP_LEFT_FRONT);
|
|
||||||
BIND_ENUM_CONSTANT(TERRA_NEIGHBOUR_TOP_LEFT_BACK);
|
|
||||||
BIND_ENUM_CONSTANT(TERRA_NEIGHBOUR_TOP_RIGHT_FRONT);
|
|
||||||
BIND_ENUM_CONSTANT(TERRA_NEIGHBOUR_TOP_RIGHT_BACK);
|
|
||||||
|
|
||||||
BIND_ENUM_CONSTANT(TERRA_FULL_NEIGHBOURS_CROSS);
|
|
||||||
BIND_ENUM_CONSTANT(TERRA_FULL_SIDE_NEIGHBOURS);
|
|
||||||
BIND_ENUM_CONSTANT(TERRA_FULL_SIDE_NEIGHBOURS_TOP);
|
|
||||||
BIND_ENUM_CONSTANT(TERRA_FULL_SIDE_NEIGHBOURS_DOWN);
|
|
||||||
}
|
|
@ -1,203 +0,0 @@
|
|||||||
/*
|
|
||||||
Copyright (c) 2019-2021 Péter Magyar
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
|
||||||
copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef SUB_TERRA_POINTS_H
|
|
||||||
#define SUB_TERRA_POINTS_H
|
|
||||||
|
|
||||||
#include "core/version.h"
|
|
||||||
|
|
||||||
#if VERSION_MAJOR > 3
|
|
||||||
#include "core/object/reference.h"
|
|
||||||
#include "core/templates/vector.h"
|
|
||||||
#else
|
|
||||||
#include "core/reference.h"
|
|
||||||
#include "core/vector.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
class TerraChunk;
|
|
||||||
class SubTerraFacePointsHelper;
|
|
||||||
|
|
||||||
class TerraCubePoints : public Reference {
|
|
||||||
GDCLASS(TerraCubePoints, Reference);
|
|
||||||
|
|
||||||
public:
|
|
||||||
enum Points {
|
|
||||||
P000 = 0,
|
|
||||||
P100 = 1,
|
|
||||||
P010 = 2,
|
|
||||||
P001 = 3,
|
|
||||||
|
|
||||||
P110 = 4,
|
|
||||||
P011 = 5,
|
|
||||||
P101 = 6,
|
|
||||||
P111 = 7,
|
|
||||||
|
|
||||||
POINT_COUNT = 8,
|
|
||||||
};
|
|
||||||
|
|
||||||
enum TerraFaces {
|
|
||||||
TERRA_FACE_FRONT = 0,
|
|
||||||
TERRA_FACE_RIGHT = 1,
|
|
||||||
TERRA_FACE_BACK = 2,
|
|
||||||
TERRA_FACE_LEFT = 3,
|
|
||||||
TERRA_FACE_TOP = 4,
|
|
||||||
TERRA_FACE_BOTTOM = 5,
|
|
||||||
TERRA_FACE_COUNT = 6,
|
|
||||||
};
|
|
||||||
|
|
||||||
enum TerraNeighbours {
|
|
||||||
TERRA_NEIGHBOUR_NONE = 0,
|
|
||||||
|
|
||||||
TERRA_NEIGHBOUR_LEFT = 1 << 0,
|
|
||||||
TERRA_NEIGHBOUR_RIGHT = 1 << 1,
|
|
||||||
TERRA_NEIGHBOUR_FRONT = 1 << 2,
|
|
||||||
TERRA_NEIGHBOUR_BACK = 1 << 3,
|
|
||||||
TERRA_NEIGHBOUR_TOP = 1 << 4,
|
|
||||||
TERRA_NEIGHBOUR_BOTTOM = 1 << 5,
|
|
||||||
|
|
||||||
TERRA_NEIGHBOUR_LEFT_FRONT = 1 << 6,
|
|
||||||
TERRA_NEIGHBOUR_LEFT_BACK = 1 << 7,
|
|
||||||
TERRA_NEIGHBOUR_RIGHT_FRONT = 1 << 8,
|
|
||||||
TERRA_NEIGHBOUR_RIGHT_BACK = 1 << 9,
|
|
||||||
|
|
||||||
TERRA_NEIGHBOUR_TOP_LEFT = 1 << 10,
|
|
||||||
TERRA_NEIGHBOUR_TOP_RIGHT = 1 << 11,
|
|
||||||
TERRA_NEIGHBOUR_TOP_FRONT = 1 << 12,
|
|
||||||
TERRA_NEIGHBOUR_TOP_BACK = 1 << 13,
|
|
||||||
|
|
||||||
TERRA_NEIGHBOUR_BOTTOM_LEFT = 1 << 14,
|
|
||||||
TERRA_NEIGHBOUR_BOTTOM_RIGHT = 1 << 15,
|
|
||||||
TERRA_NEIGHBOUR_BOTTOM_FRONT = 1 << 16,
|
|
||||||
TERRA_NEIGHBOUR_BOTTOM_BACK = 1 << 17,
|
|
||||||
|
|
||||||
TERRA_NEIGHBOUR_BOTTOM_LEFT_FRONT = 1 << 18,
|
|
||||||
TERRA_NEIGHBOUR_BOTTOM_LEFT_BACK = 1 << 19,
|
|
||||||
TERRA_NEIGHBOUR_BOTTOM_RIGHT_FRONT = 1 << 20,
|
|
||||||
TERRA_NEIGHBOUR_BOTTOM_RIGHT_BACK = 1 << 21,
|
|
||||||
|
|
||||||
TERRA_NEIGHBOUR_TOP_LEFT_FRONT = 1 << 22,
|
|
||||||
TERRA_NEIGHBOUR_TOP_LEFT_BACK = 1 << 23,
|
|
||||||
TERRA_NEIGHBOUR_TOP_RIGHT_FRONT = 1 << 24,
|
|
||||||
TERRA_NEIGHBOUR_TOP_RIGHT_BACK = 1 << 25,
|
|
||||||
|
|
||||||
TERRA_FULL_NEIGHBOURS_CROSS = TERRA_NEIGHBOUR_LEFT | TERRA_NEIGHBOUR_RIGHT | TERRA_NEIGHBOUR_BACK | TERRA_NEIGHBOUR_FRONT | TERRA_NEIGHBOUR_TOP | TERRA_NEIGHBOUR_BOTTOM, // | TERRA_NEIGHBOUR_LEFT_BACK | TERRA_NEIGHBOUR_LEFT_FRONT | TERRA_NEIGHBOUR_RIGHT_BACK | TERRA_NEIGHBOUR_RIGHT_FRONT;
|
|
||||||
TERRA_FULL_SIDE_NEIGHBOURS = TERRA_NEIGHBOUR_LEFT | TERRA_NEIGHBOUR_RIGHT | TERRA_NEIGHBOUR_BACK | TERRA_NEIGHBOUR_FRONT,
|
|
||||||
TERRA_FULL_SIDE_NEIGHBOURS_TOP = TERRA_NEIGHBOUR_LEFT | TERRA_NEIGHBOUR_RIGHT | TERRA_NEIGHBOUR_BACK | TERRA_NEIGHBOUR_FRONT | TERRA_NEIGHBOUR_TOP,
|
|
||||||
TERRA_FULL_SIDE_NEIGHBOURS_DOWN = TERRA_NEIGHBOUR_LEFT | TERRA_NEIGHBOUR_RIGHT | TERRA_NEIGHBOUR_BACK | TERRA_NEIGHBOUR_FRONT | TERRA_NEIGHBOUR_BOTTOM,
|
|
||||||
};
|
|
||||||
|
|
||||||
int get_x();
|
|
||||||
void set_x(int value);
|
|
||||||
|
|
||||||
int get_y();
|
|
||||||
void set_y(int value);
|
|
||||||
|
|
||||||
int get_z();
|
|
||||||
void set_z(int value);
|
|
||||||
|
|
||||||
int get_size();
|
|
||||||
void set_size(int value);
|
|
||||||
|
|
||||||
int get_channel_index_type() const;
|
|
||||||
void set_channel_index_type(const int value);
|
|
||||||
|
|
||||||
int get_channel_index_isolevel() const;
|
|
||||||
void set_channel_index_isolevel(const int value);
|
|
||||||
|
|
||||||
void refresh_points();
|
|
||||||
void recalculate_point(int point);
|
|
||||||
void refresh_neighbours(Ref<TerraChunk> chunk);
|
|
||||||
void setup(Ref<TerraChunk> chunk, int x, int y, int z, int size = 1);
|
|
||||||
|
|
||||||
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(int x, int y, int z);
|
|
||||||
void set_point(int point, int x, int y, int z);
|
|
||||||
int get_point_id(int x, int y, int z);
|
|
||||||
|
|
||||||
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);
|
|
||||||
|
|
||||||
int get_point_ao(int index);
|
|
||||||
int get_face_point_ao(int face, int index);
|
|
||||||
Color get_face_point_ao_color(int face, int index);
|
|
||||||
Color get_face_point_light_color(int face, int index);
|
|
||||||
Color get_face_point_color_mixed(int face, int index);
|
|
||||||
|
|
||||||
Vector3 get_face_light_direction(int face);
|
|
||||||
|
|
||||||
Vector3 get_point(int index);
|
|
||||||
Vector3 get_top_left_point(int face);
|
|
||||||
Vector3 get_top_right_point(int face);
|
|
||||||
Vector3 get_bottom_left_point(int face);
|
|
||||||
Vector3 get_bottom_right_point(int face);
|
|
||||||
|
|
||||||
uint8_t get_face_type(int face);
|
|
||||||
|
|
||||||
bool has_points();
|
|
||||||
int get_opposite_face(int face);
|
|
||||||
|
|
||||||
TerraCubePoints();
|
|
||||||
~TerraCubePoints();
|
|
||||||
|
|
||||||
protected:
|
|
||||||
static void _bind_methods();
|
|
||||||
|
|
||||||
static const unsigned int index_table[6][4];
|
|
||||||
static const unsigned int visibility_check_table[6];
|
|
||||||
static const int face_light_direction_table[6][3];
|
|
||||||
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:
|
|
||||||
int _channel_index_type;
|
|
||||||
int _channel_index_isolevel;
|
|
||||||
|
|
||||||
Vector3 _points[POINT_COUNT];
|
|
||||||
|
|
||||||
uint8_t _point_types[POINT_COUNT];
|
|
||||||
uint8_t _point_fills[POINT_COUNT];
|
|
||||||
uint8_t _point_aos[POINT_COUNT];
|
|
||||||
Color _point_colors[POINT_COUNT];
|
|
||||||
unsigned int _point_neighbours[POINT_COUNT];
|
|
||||||
|
|
||||||
int _size;
|
|
||||||
int _x;
|
|
||||||
int _y;
|
|
||||||
int _z;
|
|
||||||
};
|
|
||||||
|
|
||||||
VARIANT_ENUM_CAST(TerraCubePoints::Points);
|
|
||||||
VARIANT_ENUM_CAST(TerraCubePoints::TerraFaces);
|
|
||||||
VARIANT_ENUM_CAST(TerraCubePoints::TerraNeighbours);
|
|
||||||
|
|
||||||
#endif
|
|
@ -1,157 +0,0 @@
|
|||||||
/*
|
|
||||||
Copyright (c) 2019-2021 Péter Magyar
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
|
||||||
copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "voxel_mesher_cubic.h"
|
|
||||||
|
|
||||||
#include "../../world/default/voxel_chunk_default.h"
|
|
||||||
|
|
||||||
#include "../../defines.h"
|
|
||||||
|
|
||||||
#include visual_server_h
|
|
||||||
|
|
||||||
void TerraMesherCubic::_add_chunk(Ref<TerraChunk> p_chunk) {
|
|
||||||
Ref<TerraChunkDefault> chunk = p_chunk;
|
|
||||||
|
|
||||||
ERR_FAIL_COND(!chunk.is_valid());
|
|
||||||
|
|
||||||
if (!chunk->channel_get(_channel_index_type) || !chunk->channel_get(_channel_index_isolevel)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
//if (chunk->get_channel(TerraChunkDefault::DEFAULT_CHANNEL_RANDOM_AO)) {
|
|
||||||
// chunk->generate_ao();
|
|
||||||
//}
|
|
||||||
|
|
||||||
int x_size = chunk->get_size_x() - 1;
|
|
||||||
int y_size = chunk->get_size_y() - 1;
|
|
||||||
int z_size = chunk->get_size_z() - 1;
|
|
||||||
|
|
||||||
float voxel_size = 1;
|
|
||||||
float voxel_scale = get_voxel_scale();
|
|
||||||
|
|
||||||
Ref<TerraCubePoints> cube_points;
|
|
||||||
cube_points.instance();
|
|
||||||
cube_points->set_channel_index_type(_channel_index_type);
|
|
||||||
cube_points->set_channel_index_isolevel(_channel_index_isolevel);
|
|
||||||
|
|
||||||
Color base_light(_base_light_value, _base_light_value, _base_light_value);
|
|
||||||
|
|
||||||
for (int y = 0; y < y_size; ++y) {
|
|
||||||
for (int z = 0; z < z_size; ++z) {
|
|
||||||
for (int x = 0; x < x_size; ++x) {
|
|
||||||
|
|
||||||
cube_points->setup(chunk, x, y, z, 1);
|
|
||||||
|
|
||||||
if (!cube_points->has_points())
|
|
||||||
continue;
|
|
||||||
|
|
||||||
for (int face = 0; face < TerraCubePoints::TERRA_FACE_COUNT; ++face) {
|
|
||||||
if (!cube_points->is_face_visible(face))
|
|
||||||
continue;
|
|
||||||
|
|
||||||
uint8_t type = cube_points->get_face_type(face) - 1;
|
|
||||||
|
|
||||||
Ref<TerraSurface> surface = _library->voxel_surface_get(type);
|
|
||||||
|
|
||||||
if (!surface.is_valid())
|
|
||||||
continue;
|
|
||||||
|
|
||||||
add_indices(get_vertex_count() + 2);
|
|
||||||
add_indices(get_vertex_count() + 1);
|
|
||||||
add_indices(get_vertex_count() + 0);
|
|
||||||
add_indices(get_vertex_count() + 3);
|
|
||||||
add_indices(get_vertex_count() + 2);
|
|
||||||
add_indices(get_vertex_count() + 0);
|
|
||||||
|
|
||||||
Vector3 vertices[4] = {
|
|
||||||
cube_points->get_point_for_face(face, 0),
|
|
||||||
cube_points->get_point_for_face(face, 1),
|
|
||||||
cube_points->get_point_for_face(face, 2),
|
|
||||||
cube_points->get_point_for_face(face, 3)
|
|
||||||
};
|
|
||||||
|
|
||||||
Vector3 normals[4] = {
|
|
||||||
(vertices[3] - vertices[0]).cross(vertices[1] - vertices[0]),
|
|
||||||
(vertices[0] - vertices[1]).cross(vertices[2] - vertices[1]),
|
|
||||||
(vertices[1] - vertices[2]).cross(vertices[3] - vertices[2]),
|
|
||||||
(vertices[2] - vertices[3]).cross(vertices[0] - vertices[3])
|
|
||||||
};
|
|
||||||
|
|
||||||
Vector3 face_light_direction = cube_points->get_face_light_direction(face);
|
|
||||||
|
|
||||||
for (int i = 0; i < 4; ++i) {
|
|
||||||
add_normal(normals[i]);
|
|
||||||
|
|
||||||
Color light = cube_points->get_face_point_light_color(face, i);
|
|
||||||
light += base_light;
|
|
||||||
|
|
||||||
float NdotL = CLAMP(normals[i].dot(face_light_direction), 0, 1.0);
|
|
||||||
|
|
||||||
light *= NdotL;
|
|
||||||
|
|
||||||
light -= cube_points->get_face_point_ao_color(face, i) * _ao_strength;
|
|
||||||
|
|
||||||
light.r = CLAMP(light.r, 0, 1.0);
|
|
||||||
light.g = CLAMP(light.g, 0, 1.0);
|
|
||||||
light.b = CLAMP(light.b, 0, 1.0);
|
|
||||||
light.a = 1.0;
|
|
||||||
|
|
||||||
add_color(light);
|
|
||||||
|
|
||||||
Vector2 uv = cube_points->get_point_uv_direction(face, i) + Vector2(0.5, 0.5);
|
|
||||||
|
|
||||||
TerraSurface::TerraSurfaceSides side = TerraSurface::TERRA_SIDE_SIDE;
|
|
||||||
|
|
||||||
switch (face) {
|
|
||||||
case TerraCubePoints::TERRA_FACE_TOP:
|
|
||||||
side = TerraSurface::TERRA_SIDE_TOP;
|
|
||||||
break;
|
|
||||||
case TerraCubePoints::TERRA_FACE_BOTTOM:
|
|
||||||
side = TerraSurface::TERRA_SIDE_BOTTOM;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
uv = surface->transform_uv_scaled(side, uv, x % get_texture_scale(), z % get_texture_scale(), get_texture_scale());
|
|
||||||
|
|
||||||
add_uv(uv);
|
|
||||||
add_uv2(uv);
|
|
||||||
|
|
||||||
add_vertex((vertices[i] * voxel_size + Vector3(x, y, z)) * voxel_scale);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
TerraMesherCubic::TerraMesherCubic() {
|
|
||||||
_format = VisualServer::ARRAY_FORMAT_NORMAL | VisualServer::ARRAY_FORMAT_COLOR | VisualServer::ARRAY_FORMAT_TEX_UV;
|
|
||||||
|
|
||||||
_texture_scale = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
TerraMesherCubic::~TerraMesherCubic() {
|
|
||||||
}
|
|
||||||
|
|
||||||
void TerraMesherCubic::_bind_methods() {
|
|
||||||
ClassDB::bind_method(D_METHOD("_add_chunk", "buffer"), &TerraMesherCubic::_add_chunk);
|
|
||||||
}
|
|
@ -1,57 +0,0 @@
|
|||||||
/*
|
|
||||||
Copyright (c) 2019-2021 Péter Magyar
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
|
||||||
copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef TERRA_MESHER_CUBIC_H
|
|
||||||
#define TERRA_MESHER_CUBIC_H
|
|
||||||
|
|
||||||
#include "core/version.h"
|
|
||||||
|
|
||||||
#if VERSION_MAJOR > 3
|
|
||||||
#include "core/math/color.h"
|
|
||||||
#else
|
|
||||||
#include "core/color.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include "core/math/vector2.h"
|
|
||||||
#include "core/math/vector3.h"
|
|
||||||
|
|
||||||
#include "../default/voxel_mesher_default.h"
|
|
||||||
|
|
||||||
#include "voxel_cube_points.h"
|
|
||||||
|
|
||||||
class TerraMesherCubic : public TerraMesherDefault {
|
|
||||||
GDCLASS(TerraMesherCubic, TerraMesherDefault);
|
|
||||||
|
|
||||||
public:
|
|
||||||
void _add_chunk(Ref<TerraChunk> p_chunk);
|
|
||||||
|
|
||||||
TerraMesherCubic();
|
|
||||||
~TerraMesherCubic();
|
|
||||||
|
|
||||||
protected:
|
|
||||||
static void _bind_methods();
|
|
||||||
|
|
||||||
private:
|
|
||||||
int _texture_scale;
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
|
@ -49,9 +49,6 @@ SOFTWARE.
|
|||||||
#include "world/default/voxel_chunk_default.h"
|
#include "world/default/voxel_chunk_default.h"
|
||||||
#include "world/default/voxel_world_default.h"
|
#include "world/default/voxel_world_default.h"
|
||||||
|
|
||||||
#include "meshers/cubic/voxel_cube_points.h"
|
|
||||||
#include "meshers/cubic/voxel_mesher_cubic.h"
|
|
||||||
|
|
||||||
#include "level_generator/voxelman_level_generator.h"
|
#include "level_generator/voxelman_level_generator.h"
|
||||||
#include "level_generator/voxelman_level_generator_flat.h"
|
#include "level_generator/voxelman_level_generator_flat.h"
|
||||||
|
|
||||||
@ -65,9 +62,6 @@ SOFTWARE.
|
|||||||
#include "world/blocky/voxel_chunk_blocky.h"
|
#include "world/blocky/voxel_chunk_blocky.h"
|
||||||
#include "world/blocky/voxel_world_blocky.h"
|
#include "world/blocky/voxel_world_blocky.h"
|
||||||
|
|
||||||
#include "world/cubic/voxel_chunk_cubic.h"
|
|
||||||
#include "world/cubic/voxel_world_cubic.h"
|
|
||||||
|
|
||||||
#include "world/marching_cubes/voxel_chunk_marching_cubes.h"
|
#include "world/marching_cubes/voxel_chunk_marching_cubes.h"
|
||||||
#include "world/marching_cubes/voxel_world_marching_cubes.h"
|
#include "world/marching_cubes/voxel_world_marching_cubes.h"
|
||||||
|
|
||||||
@ -109,9 +103,6 @@ void register_terraman_types() {
|
|||||||
ClassDB::register_class<TerraChunkDefault>();
|
ClassDB::register_class<TerraChunkDefault>();
|
||||||
ClassDB::register_class<TerraWorldDefault>();
|
ClassDB::register_class<TerraWorldDefault>();
|
||||||
|
|
||||||
ClassDB::register_class<TerraMesherCubic>();
|
|
||||||
ClassDB::register_class<TerraCubePoints>();
|
|
||||||
|
|
||||||
ClassDB::register_class<TerraMesherBlocky>();
|
ClassDB::register_class<TerraMesherBlocky>();
|
||||||
ClassDB::register_class<TerraWorldBlocky>();
|
ClassDB::register_class<TerraWorldBlocky>();
|
||||||
ClassDB::register_class<TerraChunkBlocky>();
|
ClassDB::register_class<TerraChunkBlocky>();
|
||||||
@ -120,9 +111,6 @@ void register_terraman_types() {
|
|||||||
ClassDB::register_class<TerraWorldMarchingCubes>();
|
ClassDB::register_class<TerraWorldMarchingCubes>();
|
||||||
ClassDB::register_class<TerraChunkMarchingCubes>();
|
ClassDB::register_class<TerraChunkMarchingCubes>();
|
||||||
|
|
||||||
ClassDB::register_class<TerraWorldCubic>();
|
|
||||||
ClassDB::register_class<TerraChunkCubic>();
|
|
||||||
|
|
||||||
ClassDB::register_class<TerramanLevelGenerator>();
|
ClassDB::register_class<TerramanLevelGenerator>();
|
||||||
ClassDB::register_class<TerramanLevelGeneratorFlat>();
|
ClassDB::register_class<TerramanLevelGeneratorFlat>();
|
||||||
|
|
||||||
|
@ -1,43 +0,0 @@
|
|||||||
/*
|
|
||||||
Copyright (c) 2019-2021 Péter Magyar
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
|
||||||
copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "voxel_chunk_cubic.h"
|
|
||||||
|
|
||||||
#include "../../defines.h"
|
|
||||||
|
|
||||||
TerraChunkCubic::TerraChunkCubic() {
|
|
||||||
}
|
|
||||||
|
|
||||||
TerraChunkCubic::~TerraChunkCubic() {
|
|
||||||
}
|
|
||||||
|
|
||||||
void TerraChunkCubic::_setup_channels() {
|
|
||||||
channel_set_count(MAX_DEFAULT_CHANNELS);
|
|
||||||
}
|
|
||||||
|
|
||||||
void TerraChunkCubic::_bind_methods() {
|
|
||||||
ADD_PROPERTYI(PropertyInfo(Variant::POOL_BYTE_ARRAY, "data_channel"), "channel_set_compressed", "channel_get_compressed", 0);
|
|
||||||
ADD_PROPERTYI(PropertyInfo(Variant::POOL_BYTE_ARRAY, "isolevel_channel"), "channel_set_compressed", "channel_get_compressed", 1);
|
|
||||||
|
|
||||||
//ClassDB::bind_method(D_METHOD("get_channel_compressed", "channel_index"), &TerraChunk::get_channel_compressed);
|
|
||||||
//ClassDB::bind_method(D_METHOD("set_channel_compressed", "channel_index", "array"), &TerraChunk::set_channel_compressed);
|
|
||||||
}
|
|
@ -1,41 +0,0 @@
|
|||||||
/*
|
|
||||||
Copyright (c) 2019-2021 Péter Magyar
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
|
||||||
copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef TERRA_CHUNK_CUBIC_H
|
|
||||||
#define TERRA_CHUNK_CUBIC_H
|
|
||||||
|
|
||||||
#include "../default/voxel_chunk_default.h"
|
|
||||||
|
|
||||||
class TerraChunkCubic : public TerraChunkDefault {
|
|
||||||
GDCLASS(TerraChunkCubic, TerraChunkDefault);
|
|
||||||
|
|
||||||
public:
|
|
||||||
TerraChunkCubic();
|
|
||||||
~TerraChunkCubic();
|
|
||||||
|
|
||||||
protected:
|
|
||||||
virtual void _setup_channels();
|
|
||||||
|
|
||||||
static void _bind_methods();
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
|
@ -1,73 +0,0 @@
|
|||||||
/*
|
|
||||||
Copyright (c) 2019-2021 Péter Magyar
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
|
||||||
copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "voxel_world_cubic.h"
|
|
||||||
|
|
||||||
#include "voxel_chunk_cubic.h"
|
|
||||||
|
|
||||||
#include "../../meshers/cubic/voxel_mesher_cubic.h"
|
|
||||||
#include "../jobs/voxel_light_job.h"
|
|
||||||
#include "../jobs/voxel_prop_job.h"
|
|
||||||
#include "../jobs/voxel_terrarin_job.h"
|
|
||||||
|
|
||||||
Ref<TerraChunk> TerraWorldCubic::_create_chunk(int x, int y, int z, Ref<TerraChunk> chunk) {
|
|
||||||
|
|
||||||
if (!chunk.is_valid()) {
|
|
||||||
chunk = Ref<TerraChunk>(memnew(TerraChunkCubic));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (chunk->job_get_count() == 0) {
|
|
||||||
Ref<TerraTerrarinJob> tj;
|
|
||||||
tj.instance();
|
|
||||||
|
|
||||||
Ref<TerraLightJob> lj;
|
|
||||||
lj.instance();
|
|
||||||
|
|
||||||
Ref<TerraPropJob> pj;
|
|
||||||
pj.instance();
|
|
||||||
pj->set_prop_mesher(Ref<TerraMesher>(memnew(TerraMesherCubic)));
|
|
||||||
|
|
||||||
Ref<TerraMesher> m = Ref<TerraMesher>(memnew(TerraMesherCubic()));
|
|
||||||
m->set_channel_index_type(TerraChunkDefault::DEFAULT_CHANNEL_TYPE);
|
|
||||||
m->set_channel_index_isolevel(TerraChunkDefault::DEFAULT_CHANNEL_ISOLEVEL);
|
|
||||||
|
|
||||||
tj->add_mesher(m);
|
|
||||||
//add_liquid_mesher(Ref<TerraMesher>(memnew(TerraMesherLiquidMarchingCubes())));
|
|
||||||
|
|
||||||
chunk->job_add(lj);
|
|
||||||
chunk->job_add(tj);
|
|
||||||
chunk->job_add(pj);
|
|
||||||
}
|
|
||||||
|
|
||||||
return TerraWorld::_create_chunk(x, y, z, chunk);
|
|
||||||
}
|
|
||||||
|
|
||||||
TerraWorldCubic::TerraWorldCubic() {
|
|
||||||
set_data_margin_start(1);
|
|
||||||
set_data_margin_end(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
TerraWorldCubic ::~TerraWorldCubic() {
|
|
||||||
}
|
|
||||||
|
|
||||||
void TerraWorldCubic::_bind_methods() {
|
|
||||||
}
|
|
@ -1,41 +0,0 @@
|
|||||||
/*
|
|
||||||
Copyright (c) 2019-2021 Péter Magyar
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
|
||||||
copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef TERRA_WORLD_CUBIC_H
|
|
||||||
#define TERRA_WORLD_CUBIC_H
|
|
||||||
|
|
||||||
#include "../default/voxel_world_default.h"
|
|
||||||
|
|
||||||
class TerraWorldCubic : public TerraWorldDefault {
|
|
||||||
GDCLASS(TerraWorldCubic, TerraWorldDefault);
|
|
||||||
|
|
||||||
public:
|
|
||||||
TerraWorldCubic();
|
|
||||||
~TerraWorldCubic();
|
|
||||||
|
|
||||||
protected:
|
|
||||||
Ref<TerraChunk> _create_chunk(int x, int y, int z, Ref<TerraChunk> p_chunk);
|
|
||||||
|
|
||||||
static void _bind_methods();
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
|
Loading…
Reference in New Issue
Block a user