voxelman/meshers/voxel_mesher_transvoxel.cpp

218 lines
8.1 KiB
C++

#include "voxel_mesher_transvoxel.h"
int TransvoxelRegularCellData::get_vertex_index(int index) const {
return static_cast<int>(_cell_data.vertexIndex[index]);
}
int TransvoxelRegularCellData::get_vertex_count() const {
return _cell_data.GetVertexCount();
}
int TransvoxelRegularCellData::get_triangle_count() const {
return _cell_data.GetTriangleCount();
}
TransvoxelRegularCellData::TransvoxelRegularCellData() {
}
TransvoxelRegularCellData::TransvoxelRegularCellData(RegularCellData cell_data) {
_cell_data = cell_data;
}
TransvoxelRegularCellData::~TransvoxelRegularCellData() {
}
void TransvoxelRegularCellData::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_vertex_index", "index"), &TransvoxelRegularCellData::get_vertex_index);
ClassDB::bind_method(D_METHOD("get_vertex_count"), &TransvoxelRegularCellData::get_vertex_count);
ClassDB::bind_method(D_METHOD("get_triangle_count"), &TransvoxelRegularCellData::get_triangle_count);
}
int TransvoxelTransitionCellData::get_vertex_index(int index) const {
return static_cast<int>(_cell_data.vertexIndex[index]);
}
int TransvoxelTransitionCellData::get_vertex_count() const {
return _cell_data.GetVertexCount();
}
int TransvoxelTransitionCellData::get_triangle_count() const {
return _cell_data.GetTriangleCount();
}
TransvoxelTransitionCellData::TransvoxelTransitionCellData() {
}
TransvoxelTransitionCellData::TransvoxelTransitionCellData(TransitionCellData cell_data) {
_cell_data = cell_data;
}
TransvoxelTransitionCellData::~TransvoxelTransitionCellData() {
}
void TransvoxelTransitionCellData::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_vertex_index", "index"), &TransvoxelTransitionCellData::get_vertex_index);
ClassDB::bind_method(D_METHOD("get_vertex_count"), &TransvoxelTransitionCellData::get_vertex_count);
ClassDB::bind_method(D_METHOD("get_triangle_count"), &TransvoxelTransitionCellData::get_triangle_count);
}
int VoxelMesherTransvoxel::get_regular_cell_class(int index) const {
return static_cast<int>(regularCellClass[index]);
}
Ref<TransvoxelRegularCellData> VoxelMesherTransvoxel::get_regular_cell_data(int index) const {
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];
}
int VoxelMesherTransvoxel::get_regular_vertex_data_first_vertex(int index1, int index2) const {
int vert1 = regularVertexData[index1][index2] & 0x000F;
int vert2 = (regularVertexData[index1][index2] & 0x00F0) >> 4;
//The paper says, that the smaller vertex index should be considered first
if (vert2 < vert1) {
return vert2;
}
return vert1;
}
int VoxelMesherTransvoxel::get_regular_vertex_data_second_vertex(int index1, int index2) const {
int vert1 = regularVertexData[index1][index2] & 0x000F;
int vert2 = (regularVertexData[index1][index2] & 0x00F0) >> 4;
//The paper says, that the smaller vertex index should be considered first
if (vert2 > vert1) {
return vert2;
}
return vert1;
}
Vector3 VoxelMesherTransvoxel::get_regular_vertex_start_position(int index1, int index2) const {
int vert1 = regularVertexData[index1][index2] & 0x000F;
int vert2 = (regularVertexData[index1][index2] & 0x00F0) >> 4;
//The paper says, that the smaller vertex index should be considered first
if (vert2 < vert1) {
return transvoxel_vertices[vert2];
}
return transvoxel_vertices[vert1];
}
Vector3 VoxelMesherTransvoxel::get_regular_vertex_direction(int index1, int index2) const {
int vert1 = regularVertexData[index1][index2] & 0x000F;
int vert2 = (regularVertexData[index1][index2] & 0x00F0) >> 4;
//The paper says, that the smaller vertex index should be considered first
if (vert2 < vert1) {
int t = vert2;
vert2 = vert1;
vert1 = t;
}
return transvoxel_vertices[vert2] - transvoxel_vertices[vert1];
}
int VoxelMesherTransvoxel::get_transition_cell_class(int index) const {
return static_cast<int>(transitionCellClass[index]);
}
Ref<TransvoxelTransitionCellData> VoxelMesherTransvoxel::get_transition_cell_data(int index) const {
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);
}
Vector3 VoxelMesherTransvoxel::get_transition_vertex_start_position(int index1, int index2) const {
int vert1 = regularVertexData[index1][index2] & 0x000F;
int vert2 = (regularVertexData[index1][index2] & 0x00F0) >> 4;
//The paper says, that the smaller vertex index should be considered first
if (vert2 < vert1) {
return transvoxel_vertices[vert2];
}
return transvoxel_vertices[vert1];
}
Vector3 VoxelMesherTransvoxel::get_transition_vertex_direction(int index1, int index2) const {
int vert1 = regularVertexData[index1][index2] & 0x000F;
int vert2 = (regularVertexData[index1][index2] & 0x00F0) >> 4;
//The paper says, that the smaller vertex index should be considered first
if (vert2 < vert1) {
int t = vert2;
vert2 = vert1;
vert1 = t;
}
return transvoxel_vertices[vert2] - transvoxel_vertices[vert1];
}
VoxelMesherTransvoxel::VoxelMesherTransvoxel() {
for (int i = 0; i < 16; ++i) {
_regular_cell_datas[i] = Ref<TransvoxelRegularCellData>(memnew(TransvoxelRegularCellData(regularCellData[i])));
}
for (int i = 0; i < 56; ++i) {
_transition_cell_data[i] = Ref<TransvoxelTransitionCellData>(memnew(TransvoxelTransitionCellData(transitionCellData[i])));
}
}
VoxelMesherTransvoxel::~VoxelMesherTransvoxel() {
}
void VoxelMesherTransvoxel::_bind_methods() {
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);
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);
ClassDB::bind_method(D_METHOD("get_regular_vertex_start_position", "index1", "index2"), &VoxelMesherTransvoxel::get_regular_vertex_start_position);
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);
ClassDB::bind_method(D_METHOD("get_transition_vertex_start_position", "index1", "index2"), &VoxelMesherTransvoxel::get_transition_vertex_start_position);
ClassDB::bind_method(D_METHOD("get_transition_vertex_direction", "index1", "index2"), &VoxelMesherTransvoxel::get_transition_vertex_direction);
}