2019-05-31 22:54:31 +02:00
|
|
|
#include "voxel_mesher_transvoxel.h"
|
|
|
|
|
2019-06-08 19:47:17 +02:00
|
|
|
Vector3 VoxelMesherTransvoxel::corner_id_to_vertex(int corner_id) const {
|
|
|
|
ERR_FAIL_COND_V(corner_id < 0 || corner_id > 8, Vector3());
|
|
|
|
|
|
|
|
return transvoxel_vertices[corner_id];
|
|
|
|
}
|
2019-05-31 22:54:31 +02:00
|
|
|
|
|
|
|
int VoxelMesherTransvoxel::get_regular_cell_class(int index) const {
|
|
|
|
return static_cast<int>(regularCellClass[index]);
|
|
|
|
}
|
|
|
|
|
2019-09-04 18:33:19 +02:00
|
|
|
Ref<TransvoxelCellData> VoxelMesherTransvoxel::get_regular_cell_data(int index) const {
|
2019-05-31 22:54:31 +02:00
|
|
|
return _regular_cell_datas[index];
|
|
|
|
}
|
|
|
|
|
|
|
|
int VoxelMesherTransvoxel::get_regular_vertex_data(int index1, int index2) const {
|
|
|
|
//return static_cast<int>(regularVertexData[index1][index2]);
|
|
|
|
return regularVertexData[index1][index2];
|
|
|
|
}
|
|
|
|
|
2019-09-05 01:15:04 +02:00
|
|
|
//void VoxelMesherTransvoxel::set_regular_vertex_data(int index1, int index2, int value) {
|
|
|
|
// ERR_FAIL_INDEX(index1, 256);
|
|
|
|
// ERR_FAIL_INDEX(index2, 13);
|
2019-09-04 18:33:19 +02:00
|
|
|
|
2019-09-05 01:15:04 +02:00
|
|
|
// regularVertexData[index1][index2] = value;
|
|
|
|
//}
|
2019-09-04 18:33:19 +02:00
|
|
|
|
2019-05-31 22:54:31 +02:00
|
|
|
int VoxelMesherTransvoxel::get_regular_vertex_data_first_vertex(int index1, int index2) const {
|
|
|
|
int vert1 = regularVertexData[index1][index2] & 0x000F;
|
|
|
|
|
|
|
|
return vert1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int VoxelMesherTransvoxel::get_regular_vertex_data_second_vertex(int index1, int index2) const {
|
|
|
|
int vert2 = (regularVertexData[index1][index2] & 0x00F0) >> 4;
|
|
|
|
|
2019-06-08 01:28:39 +02:00
|
|
|
return vert2;
|
2019-05-31 22:54:31 +02:00
|
|
|
}
|
|
|
|
|
2019-06-08 19:47:17 +02:00
|
|
|
Vector3 VoxelMesherTransvoxel::get_regular_vertex_first_position(int index1, int index2) const {
|
|
|
|
int vert = regularVertexData[index1][index2] & 0x000F;
|
2019-05-31 22:54:31 +02:00
|
|
|
|
2019-06-08 19:47:17 +02:00
|
|
|
return transvoxel_vertices[vert];
|
|
|
|
}
|
|
|
|
|
|
|
|
Vector3 VoxelMesherTransvoxel::get_regular_vertex_second_position(int index1, int index2) const {
|
|
|
|
int vert = (regularVertexData[index1][index2] & 0x00F0) >> 4;
|
|
|
|
|
|
|
|
return transvoxel_vertices[vert];
|
2019-05-31 22:54:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Vector3 VoxelMesherTransvoxel::get_regular_vertex_direction(int index1, int index2) const {
|
|
|
|
int vert1 = regularVertexData[index1][index2] & 0x000F;
|
|
|
|
int vert2 = (regularVertexData[index1][index2] & 0x00F0) >> 4;
|
|
|
|
|
|
|
|
return transvoxel_vertices[vert2] - transvoxel_vertices[vert1];
|
|
|
|
}
|
|
|
|
|
|
|
|
int VoxelMesherTransvoxel::get_transition_cell_class(int index) const {
|
|
|
|
return static_cast<int>(transitionCellClass[index]);
|
|
|
|
}
|
|
|
|
|
2019-09-04 18:33:19 +02:00
|
|
|
Ref<TransvoxelCellData> VoxelMesherTransvoxel::get_transition_cell_data(int index) const {
|
2019-05-31 22:54:31 +02:00
|
|
|
return _transition_cell_data[index];
|
|
|
|
}
|
|
|
|
|
|
|
|
int VoxelMesherTransvoxel::get_transition_corner_data(int index) const {
|
|
|
|
return static_cast<int>(transitionCornerData[index]);
|
|
|
|
}
|
|
|
|
|
|
|
|
int VoxelMesherTransvoxel::get_transition_vertex_data(int index1, int index2) const {
|
|
|
|
return static_cast<int>(transitionVertexData[index1][index2]);
|
|
|
|
}
|
|
|
|
|
|
|
|
int VoxelMesherTransvoxel::get_transition_vertex_data_first_vertex(int index1, int index2) const {
|
|
|
|
unsigned short val = transitionVertexData[index1][index2];
|
|
|
|
|
|
|
|
unsigned short vert = val & 0x000F;
|
|
|
|
|
|
|
|
return static_cast<int>(vert);
|
|
|
|
}
|
|
|
|
|
|
|
|
int VoxelMesherTransvoxel::get_transition_vertex_data_second_vertex(int index1, int index2) const {
|
|
|
|
unsigned short val = transitionVertexData[index1][index2];
|
|
|
|
|
|
|
|
unsigned short vert = (val & 0x00F0) >> 4;
|
|
|
|
|
|
|
|
return static_cast<int>(vert);
|
|
|
|
}
|
|
|
|
|
2019-06-08 19:47:17 +02:00
|
|
|
Vector3 VoxelMesherTransvoxel::get_transition_vertex_first_position(int index1, int index2) const {
|
|
|
|
int vert = transitionVertexData[index1][index2] & 0x000F;
|
2019-05-31 22:54:31 +02:00
|
|
|
|
2019-06-08 19:47:17 +02:00
|
|
|
return transvoxel_vertices[vert];
|
|
|
|
}
|
|
|
|
|
|
|
|
Vector3 VoxelMesherTransvoxel::get_transition_vertex_second_position(int index1, int index2) const {
|
|
|
|
int vert = (transitionVertexData[index1][index2] & 0x00F0) >> 4;
|
|
|
|
|
|
|
|
return transvoxel_vertices[vert];
|
2019-05-31 22:54:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Vector3 VoxelMesherTransvoxel::get_transition_vertex_direction(int index1, int index2) const {
|
2019-06-08 19:47:17 +02:00
|
|
|
int vert1 = transitionVertexData[index1][index2] & 0x000F;
|
|
|
|
int vert2 = (transitionVertexData[index1][index2] & 0x00F0) >> 4;
|
2019-05-31 22:54:31 +02:00
|
|
|
|
|
|
|
return transvoxel_vertices[vert2] - transvoxel_vertices[vert1];
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
VoxelMesherTransvoxel::VoxelMesherTransvoxel() {
|
|
|
|
for (int i = 0; i < 16; ++i) {
|
2019-09-04 18:33:19 +02:00
|
|
|
_regular_cell_datas[i] = Ref<TransvoxelCellData>(memnew(TransvoxelCellData(regularCellData[i])));
|
2019-05-31 22:54:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
for (int i = 0; i < 56; ++i) {
|
2019-09-04 18:33:19 +02:00
|
|
|
_transition_cell_data[i] = Ref<TransvoxelCellData>(memnew(TransvoxelCellData(transitionCellData[i])));
|
2019-05-31 22:54:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
VoxelMesherTransvoxel::~VoxelMesherTransvoxel() {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void VoxelMesherTransvoxel::_bind_methods() {
|
2019-06-08 19:47:17 +02:00
|
|
|
ClassDB::bind_method(D_METHOD("corner_id_to_vertex", "index1"), &VoxelMesherTransvoxel::corner_id_to_vertex);
|
|
|
|
|
2019-05-31 22:54:31 +02:00
|
|
|
ClassDB::bind_method(D_METHOD("get_regular_cell_class", "index"), &VoxelMesherTransvoxel::get_regular_cell_class);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_regular_cell_data", "index"), &VoxelMesherTransvoxel::get_regular_cell_data);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_regular_vertex_data", "index1", "index2"), &VoxelMesherTransvoxel::get_regular_vertex_data);
|
2019-09-05 01:15:04 +02:00
|
|
|
// ClassDB::bind_method(D_METHOD("set_regular_vertex_data", "index1", "index2", "value"), &VoxelMesherTransvoxel::set_regular_vertex_data);
|
2019-05-31 22:54:31 +02:00
|
|
|
ClassDB::bind_method(D_METHOD("get_regular_vertex_data_first_vertex", "index1", "index2"), &VoxelMesherTransvoxel::get_regular_vertex_data_first_vertex);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_regular_vertex_data_second_vertex", "index1", "index2"), &VoxelMesherTransvoxel::get_regular_vertex_data_second_vertex);
|
2019-06-08 19:47:17 +02:00
|
|
|
ClassDB::bind_method(D_METHOD("get_regular_vertex_first_position", "index1", "index2"), &VoxelMesherTransvoxel::get_regular_vertex_first_position);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_regular_vertex_second_position", "index1", "index2"), &VoxelMesherTransvoxel::get_regular_vertex_second_position);
|
2019-05-31 22:54:31 +02:00
|
|
|
ClassDB::bind_method(D_METHOD("get_regular_vertex_direction", "index1", "index2"), &VoxelMesherTransvoxel::get_regular_vertex_direction);
|
|
|
|
|
|
|
|
ClassDB::bind_method(D_METHOD("get_transition_cell_class", "index"), &VoxelMesherTransvoxel::get_transition_cell_class);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_transition_cell_data", "index"), &VoxelMesherTransvoxel::get_transition_cell_data);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_transition_corner_data", "index"), &VoxelMesherTransvoxel::get_transition_corner_data);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_transition_vertex_data", "index1", "index2"), &VoxelMesherTransvoxel::get_transition_vertex_data);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_transition_vertex_data_first_vertex", "index1", "index2"), &VoxelMesherTransvoxel::get_transition_vertex_data_first_vertex);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_transition_vertex_data_second_vertex", "index1", "index2"), &VoxelMesherTransvoxel::get_transition_vertex_data_second_vertex);
|
2019-06-08 19:47:17 +02:00
|
|
|
ClassDB::bind_method(D_METHOD("get_transition_vertex_first_position", "index1", "index2"), &VoxelMesherTransvoxel::get_transition_vertex_first_position);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_transition_vertex_second_position", "index1", "index2"), &VoxelMesherTransvoxel::get_transition_vertex_second_position);
|
2019-05-31 22:54:31 +02:00
|
|
|
ClassDB::bind_method(D_METHOD("get_transition_vertex_direction", "index1", "index2"), &VoxelMesherTransvoxel::get_transition_vertex_direction);
|
2019-06-07 19:13:07 +02:00
|
|
|
|
|
|
|
BIND_ENUM_CONSTANT(VOXEL_ENTRY_INDEX_000);
|
|
|
|
BIND_ENUM_CONSTANT(VOXEL_ENTRY_INDEX_100);
|
|
|
|
BIND_ENUM_CONSTANT(VOXEL_ENTRY_INDEX_010);
|
|
|
|
BIND_ENUM_CONSTANT(VOXEL_ENTRY_INDEX_110);
|
|
|
|
BIND_ENUM_CONSTANT(VOXEL_ENTRY_INDEX_001);
|
|
|
|
BIND_ENUM_CONSTANT(VOXEL_ENTRY_INDEX_101);
|
|
|
|
BIND_ENUM_CONSTANT(VOXEL_ENTRY_INDEX_011);
|
|
|
|
BIND_ENUM_CONSTANT(VOXEL_ENTRY_INDEX_111);
|
|
|
|
|
|
|
|
BIND_ENUM_CONSTANT(VOXEL_ENTRIES_SIZE);
|
|
|
|
|
|
|
|
BIND_ENUM_CONSTANT(VOXEL_ENTRY_MASK_000);
|
|
|
|
BIND_ENUM_CONSTANT(VOXEL_ENTRY_MASK_100);
|
|
|
|
BIND_ENUM_CONSTANT(VOXEL_ENTRY_MASK_010);
|
|
|
|
BIND_ENUM_CONSTANT(VOXEL_ENTRY_MASK_110);
|
|
|
|
BIND_ENUM_CONSTANT(VOXEL_ENTRY_MASK_001);
|
|
|
|
BIND_ENUM_CONSTANT(VOXEL_ENTRY_MASK_101);
|
|
|
|
BIND_ENUM_CONSTANT(VOXEL_ENTRY_MASK_011);
|
|
|
|
BIND_ENUM_CONSTANT(VOXEL_ENTRY_MASK_111);
|
2019-05-31 22:54:31 +02:00
|
|
|
}
|