Work on fixing the uv issues.

This commit is contained in:
Relintai 2019-09-04 18:33:19 +02:00
parent 5eb5249147
commit 05781891b3
8 changed files with 210 additions and 178 deletions

1
SCsub
View File

@ -10,6 +10,7 @@ env.add_source_files(env.modules_sources,"library/voxel_surface.cpp")
env.add_source_files(env.modules_sources,"data/voxel_light.cpp")
env.add_source_files(env.modules_sources,"meshers/voxel_mesher.cpp")
env.add_source_files(env.modules_sources,"meshers/transvoxel_cell_data.cpp")
env.add_source_files(env.modules_sources,"meshers/voxel_mesher_transvoxel.cpp")
env.add_source_files(env.modules_sources,"meshers/voxel_mesher_transvoxel_terrarin.cpp")
env.add_source_files(env.modules_sources,"meshers/transvoxel_tables.cpp")

View File

@ -0,0 +1,68 @@
#include "transvoxel_cell_data.h"
int TransvoxelCellData::get_vertex_index(int index) const {
return static_cast<int>(vertexIndex[index]);
}
void TransvoxelCellData::set_vertex_index(int index, int value) {
ERR_FAIL_INDEX(index, 36);
vertexIndex[index] = static_cast<unsigned char>(value);
}
int TransvoxelCellData::get_vertex_count() const {
return (geometryCounts >> 4);
}
void TransvoxelCellData::set_vertex_count(int value) {
geometryCounts &= 0xFF0F;
geometryCounts |= value << 4;
}
int TransvoxelCellData::get_triangle_count() const {
return (geometryCounts & 0x0F);
}
void TransvoxelCellData::set_triangle_count(int value) {
geometryCounts &= 0xFFF0;
geometryCounts |= value;
}
TransvoxelCellData::TransvoxelCellData() {
geometryCounts = 0;
for (int i = 0; i < 36; ++i) {
vertexIndex[i] = 0;
}
}
TransvoxelCellData::TransvoxelCellData(const RegularCellData &cell_data) {
geometryCounts = cell_data.geometryCounts;
for (int i = 0; i < 15; ++i) {
vertexIndex[i] = cell_data.vertexIndex[i];
}
}
TransvoxelCellData::TransvoxelCellData(const TransitionCellData &cell_data) {
geometryCounts = cell_data.geometryCounts;
for (int i = 0; i < 36; ++i) {
vertexIndex[i] = cell_data.vertexIndex[i];
}
}
TransvoxelCellData::~TransvoxelCellData() {
}
void TransvoxelCellData::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_vertex_index", "index"), &TransvoxelCellData::get_vertex_index);
ClassDB::bind_method(D_METHOD("set_vertex_index", "index", "value"), &TransvoxelCellData::set_vertex_index);
ClassDB::bind_method(D_METHOD("get_vertex_count"), &TransvoxelCellData::get_vertex_count);
ClassDB::bind_method(D_METHOD("set_vertex_count", "value"), &TransvoxelCellData::set_vertex_count);
ClassDB::bind_method(D_METHOD("get_triangle_count"), &TransvoxelCellData::get_triangle_count);
ClassDB::bind_method(D_METHOD("set_triangle_count", "value"), &TransvoxelCellData::set_triangle_count);
}

View File

@ -0,0 +1,34 @@
#ifndef TRANSVOXEL_CELL_DATA_H
#define TRANSVOXEL_CELL_DATA_H
#include "core/reference.h"
#include "transvoxel_tables.h"
using namespace Transvoxel;
class TransvoxelCellData : public Reference {
GDCLASS(TransvoxelCellData, Reference)
public:
int get_vertex_index(int index) const;
void set_vertex_index(int index, int value);
int get_vertex_count() const;
void set_vertex_count(int value);
int get_triangle_count() const;
void set_triangle_count(int value);
TransvoxelCellData();
TransvoxelCellData(const RegularCellData &cell_data);
TransvoxelCellData(const TransitionCellData &cell_data);
~TransvoxelCellData();
protected:
static void _bind_methods();
private:
long geometryCounts; // High nibble is vertex count, low nibble is triangle count.
unsigned char vertexIndex[36]; // Groups of 3 indexes giving the triangulation.
};
#endif

View File

@ -41,22 +41,23 @@ namespace Transvoxel {
// that the class index ranges from 0 to 15.
const unsigned char regularCellClass[256] = {
0x00, 0x01, 0x01, 0x03, 0x01, 0x03, 0x02, 0x04, 0x01, 0x02, 0x03, 0x04, 0x03, 0x04, 0x04, 0x03,
0x01, 0x03, 0x02, 0x04, 0x02, 0x04, 0x06, 0x0C, 0x02, 0x05, 0x05, 0x0B, 0x05, 0x0A, 0x07, 0x04,
0x01, 0x02, 0x03, 0x04, 0x02, 0x05, 0x05, 0x0A, 0x02, 0x06, 0x04, 0x0C, 0x05, 0x07, 0x0B, 0x04,
0x03, 0x04, 0x04, 0x03, 0x05, 0x0B, 0x07, 0x04, 0x05, 0x07, 0x0A, 0x04, 0x08, 0x0E, 0x0E, 0x03,
0x01, 0x02, 0x02, 0x05, 0x03, 0x04, 0x05, 0x0B, 0x02, 0x06, 0x05, 0x07, 0x04, 0x0C, 0x0A, 0x04,
0x03, 0x04, 0x05, 0x0A, 0x04, 0x03, 0x07, 0x04, 0x05, 0x07, 0x08, 0x0E, 0x0B, 0x04, 0x0E, 0x03,
0x02, 0x06, 0x05, 0x07, 0x05, 0x07, 0x08, 0x0E, 0x06, 0x09, 0x07, 0x0F, 0x07, 0x0F, 0x0E, 0x0D,
0x04, 0x0C, 0x0B, 0x04, 0x0A, 0x04, 0x0E, 0x03, 0x07, 0x0F, 0x0E, 0x0D, 0x0E, 0x0D, 0x02, 0x01,
0x01, 0x02, 0x02, 0x05, 0x02, 0x05, 0x06, 0x07, 0x03, 0x05, 0x04, 0x0A, 0x04, 0x0B, 0x0C, 0x04,
0x02, 0x05, 0x06, 0x07, 0x06, 0x07, 0x09, 0x0F, 0x05, 0x08, 0x07, 0x0E, 0x07, 0x0E, 0x0F, 0x0D,
0x03, 0x05, 0x04, 0x0B, 0x05, 0x08, 0x07, 0x0E, 0x04, 0x07, 0x03, 0x04, 0x0A, 0x0E, 0x04, 0x03,
0x04, 0x0A, 0x0C, 0x04, 0x07, 0x0E, 0x0F, 0x0D, 0x0B, 0x0E, 0x04, 0x03, 0x0E, 0x02, 0x0D, 0x01,
0x03, 0x05, 0x05, 0x08, 0x04, 0x0A, 0x07, 0x0E, 0x04, 0x07, 0x0B, 0x0E, 0x03, 0x04, 0x04, 0x03,
0x04, 0x0B, 0x07, 0x0E, 0x0C, 0x04, 0x0F, 0x0D, 0x0A, 0x0E, 0x0E, 0x02, 0x04, 0x03, 0x0D, 0x01,
0x04, 0x07, 0x0A, 0x0E, 0x0B, 0x0E, 0x0E, 0x02, 0x0C, 0x0F, 0x04, 0x0D, 0x04, 0x0D, 0x03, 0x01,
0x03, 0x04, 0x04, 0x03, 0x04, 0x03, 0x0D, 0x01, 0x04, 0x0D, 0x03, 0x01, 0x03, 0x01, 0x01, 0x00
// 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
0x00, 0x01, 0x01, 0x03, 0x01, 0x03, 0x02, 0x04, 0x01, 0x02, 0x03, 0x04, 0x03, 0x04, 0x04, 0x03, // 0
0x01, 0x03, 0x02, 0x04, 0x02, 0x04, 0x06, 0x0C, 0x02, 0x05, 0x05, 0x0B, 0x05, 0x0A, 0x07, 0x04, // 16
0x01, 0x02, 0x03, 0x04, 0x02, 0x05, 0x05, 0x0A, 0x02, 0x06, 0x04, 0x0C, 0x05, 0x07, 0x0B, 0x04, // 32
0x03, 0x04, 0x04, 0x03, 0x05, 0x0B, 0x07, 0x04, 0x05, 0x07, 0x0A, 0x04, 0x08, 0x0E, 0x0E, 0x03, // 48
0x01, 0x02, 0x02, 0x05, 0x03, 0x04, 0x05, 0x0B, 0x02, 0x06, 0x05, 0x07, 0x04, 0x0C, 0x0A, 0x04, // 64
0x03, 0x04, 0x05, 0x0A, 0x04, 0x03, 0x07, 0x04, 0x05, 0x07, 0x08, 0x0E, 0x0B, 0x04, 0x0E, 0x03, // 80
0x02, 0x06, 0x05, 0x07, 0x05, 0x07, 0x08, 0x0E, 0x06, 0x09, 0x07, 0x0F, 0x07, 0x0F, 0x0E, 0x0D, // 96
0x04, 0x0C, 0x0B, 0x04, 0x0A, 0x04, 0x0E, 0x03, 0x07, 0x0F, 0x0E, 0x0D, 0x0E, 0x0D, 0x02, 0x01, // 112
0x01, 0x02, 0x02, 0x05, 0x02, 0x05, 0x06, 0x07, 0x03, 0x05, 0x04, 0x0A, 0x04, 0x0B, 0x0C, 0x04, // 128
0x02, 0x05, 0x06, 0x07, 0x06, 0x07, 0x09, 0x0F, 0x05, 0x08, 0x07, 0x0E, 0x07, 0x0E, 0x0F, 0x0D, // 144
0x03, 0x05, 0x04, 0x0B, 0x05, 0x08, 0x07, 0x0E, 0x04, 0x07, 0x03, 0x04, 0x0A, 0x0E, 0x04, 0x03, // 160
0x04, 0x0A, 0x0C, 0x04, 0x07, 0x0E, 0x0F, 0x0D, 0x0B, 0x0E, 0x04, 0x03, 0x0E, 0x02, 0x0D, 0x01, // 176
0x03, 0x05, 0x05, 0x08, 0x04, 0x0A, 0x07, 0x0E, 0x04, 0x07, 0x0B, 0x0E, 0x03, 0x04, 0x04, 0x03, // 192
0x04, 0x0B, 0x07, 0x0E, 0x0C, 0x04, 0x0F, 0x0D, 0x0A, 0x0E, 0x0E, 0x02, 0x04, 0x03, 0x0D, 0x01, // 208
0x04, 0x07, 0x0A, 0x0E, 0x0B, 0x0E, 0x0E, 0x02, 0x0C, 0x0F, 0x04, 0x0D, 0x04, 0x0D, 0x03, 0x01, // 224
0x03, 0x04, 0x04, 0x03, 0x04, 0x03, 0x0D, 0x01, 0x04, 0x0D, 0x03, 0x01, 0x03, 0x01, 0x01, 0x00 // 240
};
// The regularCellData table holds the triangulation data for all 16 distinct classes to
@ -67,7 +68,7 @@ const RegularCellData regularCellData[16] = {
{ 0x31, { 0, 1, 2 } },
{ 0x62, { 0, 1, 2, 3, 4, 5 } },
{ 0x42, { 0, 1, 2, 0, 2, 3 } },
{ 0x53, { 0, 1, 4, 1, 3, 4, 1, 2, 3 } },
{ 0x73, { 0, 1, 4, 1, 3, 4, 2, 5, 6 } }, //{ 0x53, { 0, 1, 4, 1, 3, 4, 1, 2, 3 } },
{ 0x73, { 0, 1, 2, 0, 2, 3, 4, 5, 6 } },
{ 0x93, { 0, 1, 2, 3, 4, 5, 6, 7, 8 } },
{ 0x84, { 0, 1, 4, 1, 3, 4, 1, 2, 3, 5, 6, 7 } },
@ -86,8 +87,8 @@ const RegularCellData regularCellData[16] = {
// about whether a vertex can be reused from a neighboring cell. See Section 3.3 for details.
// The low byte contains the indexes for the two endpoints of the edge on which the vertex lies,
// as numbered in Figure 3.7. The high byte contains the vertex reuse data shown in Figure 3.8.
const unsigned short regularVertexData[256][12] = {
//TODO add back const
unsigned short regularVertexData[256][12] = {
{},
{ 0x6201, 0x5102, 0x3304 },
{ 0x6201, 0x2315, 0x4113 },
@ -95,21 +96,22 @@ const unsigned short regularVertexData[256][12] = {
{ 0x5102, 0x4223, 0x1326 },
{ 0x3304, 0x6201, 0x4223, 0x1326 },
{ 0x6201, 0x2315, 0x4113, 0x5102, 0x4223, 0x1326 },
{ 0x4223, 0x1326, 0x3304, 0x2315, 0x4113 },
{ 0x4223, 0x1326, 0x3304, 0x2315, 0x4113, 0x3304, 0x2315 }, //7
{ 0x4113, 0x8337, 0x4223 },
{ 0x6201, 0x5102, 0x3304, 0x4223, 0x4113, 0x8337 },
{ 0x6201, 0x2315, 0x8337, 0x4223 },
{ 0x5102, 0x3304, 0x2315, 0x8337, 0x4223 },
{ 0x5102, 0x3304, 0x2315, 0x8337, 0x4223, 0x3304, 0x8337 },
{ 0x5102, 0x4113, 0x8337, 0x1326 },
{ 0x4113, 0x8337, 0x1326, 0x3304, 0x6201 },
{ 0x6201, 0x2315, 0x8337, 0x1326, 0x5102 },
{ 0x4113, 0x8337, 0x1326, 0x3304, 0x6201, 0x8337, 0x3304 },
{ 0x6201, 0x2315, 0x8337, 0x1326, 0x5102, 0x2315, 0x1326 },
{ 0x3304, 0x2315, 0x8337, 0x1326 },
//16 3 5 15
{ 0x3304, 0x1146, 0x2245 },
{ 0x6201, 0x5102, 0x1146, 0x2245 },
{ 0x6201, 0x2315, 0x4113, 0x3304, 0x1146, 0x2245 },
{ 0x2315, 0x4113, 0x5102, 0x1146, 0x2245 },
{ 0x2315, 0x4113, 0x5102, 0x1146, 0x2245, 0x4113, 0x1146 },
{ 0x5102, 0x4223, 0x1326, 0x3304, 0x1146, 0x2245 },
{ 0x1146, 0x2245, 0x6201, 0x4223, 0x1326 },
{ 0x1146, 0x2245, 0x6201, 0x4223, 0x1326, 0x2245, 0x4223 },
{ 0x3304, 0x1146, 0x2245, 0x6201, 0x2315, 0x4113, 0x5102, 0x4223, 0x1326 },
{ 0x4223, 0x1326, 0x1146, 0x2245, 0x2315, 0x4113 },
{ 0x4223, 0x4113, 0x8337, 0x3304, 0x1146, 0x2245 },
@ -119,71 +121,76 @@ const unsigned short regularVertexData[256][12] = {
{ 0x5102, 0x4113, 0x8337, 0x1326, 0x3304, 0x1146, 0x2245 },
{ 0x4113, 0x8337, 0x1326, 0x1146, 0x2245, 0x6201 },
{ 0x6201, 0x2315, 0x8337, 0x1326, 0x5102, 0x3304, 0x1146, 0x2245 },
{ 0x2245, 0x2315, 0x8337, 0x1326, 0x1146 },
{ 0x2245, 0x2315, 0x8337, 0x1326, 0x1146, 0x2315, 0x1326 },
//32 3 10 15
{ 0x2315, 0x2245, 0x8157 },
{ 0x6201, 0x5102, 0x3304, 0x2315, 0x2245, 0x8157 },
{ 0x4113, 0x6201, 0x2245, 0x8157 },
{ 0x2245, 0x8157, 0x4113, 0x5102, 0x3304 },
{ 0x2245, 0x8157, 0x4113, 0x5102, 0x3304, 0x8157, 0x5102 },
{ 0x5102, 0x4223, 0x1326, 0x2315, 0x2245, 0x8157 },
{ 0x6201, 0x4223, 0x1326, 0x3304, 0x2315, 0x2245, 0x8157 },
{ 0x6201, 0x2245, 0x8157, 0x4113, 0x5102, 0x4223, 0x1326 },
{ 0x4223, 0x1326, 0x3304, 0x2245, 0x8157, 0x4113 },
{ 0x4223, 0x4113, 0x8337, 0x2315, 0x2245, 0x8157 },
{ 0x6201, 0x5102, 0x3304, 0x4223, 0x4113, 0x8337, 0x2315, 0x2245, 0x8157 },
{ 0x8337, 0x4223, 0x6201, 0x2245, 0x8157 },
{ 0x8337, 0x4223, 0x6201, 0x2245, 0x8157, 0x4223, 0x2245 },
{ 0x5102, 0x3304, 0x2245, 0x8157, 0x8337, 0x4223 },
{ 0x5102, 0x4113, 0x8337, 0x1326, 0x2315, 0x2245, 0x8157 },
{ 0x4113, 0x8337, 0x1326, 0x3304, 0x6201, 0x2315, 0x2245, 0x8157 },
{ 0x5102, 0x1326, 0x8337, 0x8157, 0x2245, 0x6201 },
{ 0x8157, 0x8337, 0x1326, 0x3304, 0x2245 },
{ 0x8157, 0x8337, 0x1326, 0x3304, 0x2245, 0x8337, 0x3304 },
//48 1 2 7 11
{ 0x2315, 0x3304, 0x1146, 0x8157 },
{ 0x6201, 0x5102, 0x1146, 0x8157, 0x2315 },
{ 0x3304, 0x1146, 0x8157, 0x4113, 0x6201 },
{ 0x6201, 0x5102, 0x1146, 0x8157, 0x2315, 0x5102, 0x8157 },
{ 0x3304, 0x1146, 0x8157, 0x4113, 0x6201, 0x1146, 0x4113 },
{ 0x4113, 0x5102, 0x1146, 0x8157 },
{ 0x2315, 0x3304, 0x1146, 0x8157, 0x5102, 0x4223, 0x1326 },
{ 0x1326, 0x4223, 0x6201, 0x2315, 0x8157, 0x1146 },
{ 0x3304, 0x1146, 0x8157, 0x4113, 0x6201, 0x5102, 0x4223, 0x1326 },
{ 0x1326, 0x1146, 0x8157, 0x4113, 0x4223 },
{ 0x1326, 0x1146, 0x8157, 0x4113, 0x4223, 0x1146, 0x4113 },
{ 0x2315, 0x3304, 0x1146, 0x8157, 0x4223, 0x4113, 0x8337 },
{ 0x6201, 0x5102, 0x1146, 0x8157, 0x2315, 0x4223, 0x4113, 0x8337 },
{ 0x3304, 0x1146, 0x8157, 0x8337, 0x4223, 0x6201 },
{ 0x4223, 0x5102, 0x1146, 0x8157, 0x8337 },
{ 0x4223, 0x5102, 0x1146, 0x8157, 0x8337, 0x5102, 0x8157 },
{ 0x2315, 0x3304, 0x1146, 0x8157, 0x5102, 0x4113, 0x8337, 0x1326 },
{ 0x6201, 0x4113, 0x8337, 0x1326, 0x1146, 0x8157, 0x2315 },
{ 0x6201, 0x3304, 0x1146, 0x8157, 0x8337, 0x1326, 0x5102 },
{ 0x1326, 0x1146, 0x8157, 0x8337 },
//64 5 12 15
{ 0x1326, 0x8267, 0x1146 },
{ 0x6201, 0x5102, 0x3304, 0x1326, 0x8267, 0x1146 },
{ 0x6201, 0x2315, 0x4113, 0x1326, 0x8267, 0x1146 },
{ 0x5102, 0x3304, 0x2315, 0x4113, 0x1326, 0x8267, 0x1146 },
{ 0x5102, 0x4223, 0x8267, 0x1146 },
{ 0x3304, 0x6201, 0x4223, 0x8267, 0x1146 },
{ 0x3304, 0x6201, 0x4223, 0x8267, 0x1146, 0x6201, 0x8267 },
{ 0x5102, 0x4223, 0x8267, 0x1146, 0x6201, 0x2315, 0x4113 },
{ 0x1146, 0x8267, 0x4223, 0x4113, 0x2315, 0x3304 },
{ 0x4113, 0x8337, 0x4223, 0x1326, 0x8267, 0x1146 },
{ 0x6201, 0x5102, 0x3304, 0x4223, 0x4113, 0x8337, 0x1326, 0x8267, 0x1146 },
{ 0x6201, 0x2315, 0x8337, 0x4223, 0x1326, 0x8267, 0x1146 },
{ 0x5102, 0x3304, 0x2315, 0x8337, 0x4223, 0x1326, 0x8267, 0x1146 },
{ 0x8267, 0x1146, 0x5102, 0x4113, 0x8337 },
{ 0x8267, 0x1146, 0x5102, 0x4113, 0x8337, 0x1146, 0x4113 },
{ 0x6201, 0x4113, 0x8337, 0x8267, 0x1146, 0x3304 },
{ 0x6201, 0x2315, 0x8337, 0x8267, 0x1146, 0x5102 },
{ 0x1146, 0x3304, 0x2315, 0x8337, 0x8267 },
{ 0x1146, 0x3304, 0x2315, 0x8337, 0x8267, 0x3304, 0x8337 },
//80 1 4 7 13
{ 0x3304, 0x1326, 0x8267, 0x2245 },
{ 0x1326, 0x8267, 0x2245, 0x6201, 0x5102 },
{ 0x1326, 0x8267, 0x2245, 0x6201, 0x5102, 0x8267, 0x6201 },
{ 0x3304, 0x1326, 0x8267, 0x2245, 0x6201, 0x2315, 0x4113 },
{ 0x1326, 0x8267, 0x2245, 0x2315, 0x4113, 0x5102 },
{ 0x5102, 0x4223, 0x8267, 0x2245, 0x3304 },
{ 0x5102, 0x4223, 0x8267, 0x2245, 0x3304, 0x4223, 0x2245 },
{ 0x6201, 0x4223, 0x8267, 0x2245 },
{ 0x5102, 0x4223, 0x8267, 0x2245, 0x3304, 0x6201, 0x2315, 0x4113 },
{ 0x4113, 0x4223, 0x8267, 0x2245, 0x2315 },
{ 0x4113, 0x4223, 0x8267, 0x2245, 0x2315, 0x4223, 0x2245 },
{ 0x3304, 0x1326, 0x8267, 0x2245, 0x4223, 0x4113, 0x8337 },
{ 0x1326, 0x8267, 0x2245, 0x6201, 0x5102, 0x4223, 0x4113, 0x8337 },
{ 0x3304, 0x1326, 0x8267, 0x2245, 0x4223, 0x6201, 0x2315, 0x8337 },
{ 0x5102, 0x1326, 0x8267, 0x2245, 0x2315, 0x8337, 0x4223 },
{ 0x3304, 0x2245, 0x8267, 0x8337, 0x4113, 0x5102 },
{ 0x8337, 0x8267, 0x2245, 0x6201, 0x4113 },
{ 0x8337, 0x8267, 0x2245, 0x6201, 0x4113, 0x8267, 0x6201 },
{ 0x5102, 0x6201, 0x2315, 0x8337, 0x8267, 0x2245, 0x3304 },
{ 0x2315, 0x8337, 0x8267, 0x2245 },
//96 -
{ 0x2315, 0x2245, 0x8157, 0x1326, 0x8267, 0x1146 },
{ 0x6201, 0x5102, 0x3304, 0x2315, 0x2245, 0x8157, 0x1326, 0x8267, 0x1146 },
{ 0x6201, 0x2245, 0x8157, 0x4113, 0x1326, 0x8267, 0x1146 },
@ -200,12 +207,13 @@ const unsigned short regularVertexData[256][12] = {
{ 0x6201, 0x4113, 0x8337, 0x8267, 0x1146, 0x3304, 0x2315, 0x2245, 0x8157 },
{ 0x8337, 0x8267, 0x1146, 0x5102, 0x6201, 0x2245, 0x8157 },
{ 0x3304, 0x2245, 0x8157, 0x8337, 0x8267, 0x1146 },
{ 0x8157, 0x2315, 0x3304, 0x1326, 0x8267 },
//112 0 3 5
{ 0x8157, 0x2315, 0x3304, 0x1326, 0x8267, 0x2315, 0x1326 },
{ 0x8267, 0x8157, 0x2315, 0x6201, 0x5102, 0x1326 },
{ 0x8267, 0x1326, 0x3304, 0x6201, 0x4113, 0x8157 },
{ 0x8267, 0x8157, 0x4113, 0x5102, 0x1326 },
{ 0x8267, 0x8157, 0x4113, 0x5102, 0x1326, 0x8157, 0x5102 },
{ 0x5102, 0x4223, 0x8267, 0x8157, 0x2315, 0x3304 },
{ 0x2315, 0x6201, 0x4223, 0x8267, 0x8157 },
{ 0x2315, 0x6201, 0x4223, 0x8267, 0x8157, 0x6201, 0x8267 },
{ 0x3304, 0x5102, 0x4223, 0x8267, 0x8157, 0x4113, 0x6201 },
{ 0x4113, 0x4223, 0x8267, 0x8157 },
{ 0x8157, 0x2315, 0x3304, 0x1326, 0x8267, 0x4223, 0x4113, 0x8337 },
@ -216,6 +224,7 @@ const unsigned short regularVertexData[256][12] = {
{ 0x6201, 0x4113, 0x8337, 0x8267, 0x8157, 0x2315 },
{ 0x6201, 0x3304, 0x5102, 0x8337, 0x8267, 0x8157 },
{ 0x8337, 0x8267, 0x8157 },
//128 10 12 15
{ 0x8337, 0x8157, 0x8267 },
{ 0x6201, 0x5102, 0x3304, 0x8337, 0x8157, 0x8267 },
{ 0x6201, 0x2315, 0x4113, 0x8337, 0x8157, 0x8267 },
@ -226,12 +235,13 @@ const unsigned short regularVertexData[256][12] = {
{ 0x4223, 0x1326, 0x3304, 0x2315, 0x4113, 0x8337, 0x8157, 0x8267 },
{ 0x4113, 0x8157, 0x8267, 0x4223 },
{ 0x4223, 0x4113, 0x8157, 0x8267, 0x6201, 0x5102, 0x3304 },
{ 0x8157, 0x8267, 0x4223, 0x6201, 0x2315 },
{ 0x8157, 0x8267, 0x4223, 0x6201, 0x2315, 0x8267, 0x6201 },
{ 0x3304, 0x2315, 0x8157, 0x8267, 0x4223, 0x5102 },
{ 0x1326, 0x5102, 0x4113, 0x8157, 0x8267 },
{ 0x1326, 0x5102, 0x4113, 0x8157, 0x8267, 0x5102, 0x8157 },
{ 0x8157, 0x4113, 0x6201, 0x3304, 0x1326, 0x8267 },
{ 0x1326, 0x5102, 0x6201, 0x2315, 0x8157, 0x8267 },
{ 0x8267, 0x1326, 0x3304, 0x2315, 0x8157 },
{ 0x8267, 0x1326, 0x3304, 0x2315, 0x8157, 0x1326, 0x2315 },
//144 -
{ 0x3304, 0x1146, 0x2245, 0x8337, 0x8157, 0x8267 },
{ 0x6201, 0x5102, 0x1146, 0x2245, 0x8337, 0x8157, 0x8267 },
{ 0x6201, 0x2315, 0x4113, 0x3304, 0x1146, 0x2245, 0x8337, 0x8157, 0x8267 },
@ -248,71 +258,76 @@ const unsigned short regularVertexData[256][12] = {
{ 0x1326, 0x1146, 0x2245, 0x6201, 0x4113, 0x8157, 0x8267 },
{ 0x5102, 0x6201, 0x2315, 0x8157, 0x8267, 0x1326, 0x3304, 0x1146, 0x2245 },
{ 0x1326, 0x1146, 0x2245, 0x2315, 0x8157, 0x8267 },
//160 2 8 11 14
{ 0x2315, 0x2245, 0x8267, 0x8337 },
{ 0x2315, 0x2245, 0x8267, 0x8337, 0x6201, 0x5102, 0x3304 },
{ 0x4113, 0x6201, 0x2245, 0x8267, 0x8337 },
{ 0x4113, 0x6201, 0x2245, 0x8267, 0x8337, 0x6201, 0x8267 },
{ 0x5102, 0x4113, 0x8337, 0x8267, 0x2245, 0x3304 },
{ 0x2315, 0x2245, 0x8267, 0x8337, 0x5102, 0x4223, 0x1326 },
{ 0x6201, 0x4223, 0x1326, 0x3304, 0x8337, 0x2315, 0x2245, 0x8267 },
{ 0x4113, 0x6201, 0x2245, 0x8267, 0x8337, 0x5102, 0x4223, 0x1326 },
{ 0x4113, 0x4223, 0x1326, 0x3304, 0x2245, 0x8267, 0x8337 },
{ 0x2315, 0x2245, 0x8267, 0x4223, 0x4113 },
{ 0x2315, 0x2245, 0x8267, 0x4223, 0x4113, 0x2245, 0x4223 },
{ 0x2315, 0x2245, 0x8267, 0x4223, 0x4113, 0x6201, 0x5102, 0x3304 },
{ 0x6201, 0x2245, 0x8267, 0x4223 },
{ 0x3304, 0x2245, 0x8267, 0x4223, 0x5102 },
{ 0x3304, 0x2245, 0x8267, 0x4223, 0x5102, 0x2245, 0x4223 },
{ 0x5102, 0x4113, 0x2315, 0x2245, 0x8267, 0x1326 },
{ 0x4113, 0x2315, 0x2245, 0x8267, 0x1326, 0x3304, 0x6201 },
{ 0x5102, 0x6201, 0x2245, 0x8267, 0x1326 },
{ 0x5102, 0x6201, 0x2245, 0x8267, 0x1326, 0x6201, 0x8267 },
{ 0x3304, 0x2245, 0x8267, 0x1326 },
{ 0x8267, 0x8337, 0x2315, 0x3304, 0x1146 },
//176 0 3 10
{ 0x8267, 0x8337, 0x2315, 0x3304, 0x1146, 0x8337, 0x3304 },
{ 0x5102, 0x1146, 0x8267, 0x8337, 0x2315, 0x6201 },
{ 0x3304, 0x1146, 0x8267, 0x8337, 0x4113, 0x6201 },
{ 0x8337, 0x4113, 0x5102, 0x1146, 0x8267 },
{ 0x8337, 0x4113, 0x5102, 0x1146, 0x8267, 0x4113, 0x1146 },
{ 0x8267, 0x8337, 0x2315, 0x3304, 0x1146, 0x5102, 0x4223, 0x1326 },
{ 0x1146, 0x8267, 0x8337, 0x2315, 0x6201, 0x4223, 0x1326 },
{ 0x8267, 0x8337, 0x4113, 0x6201, 0x3304, 0x1146, 0x5102, 0x4223, 0x1326 },
{ 0x4113, 0x4223, 0x1326, 0x1146, 0x8267, 0x8337 },
{ 0x3304, 0x2315, 0x4113, 0x4223, 0x8267, 0x1146 },
{ 0x2315, 0x6201, 0x5102, 0x1146, 0x8267, 0x4223, 0x4113 },
{ 0x1146, 0x8267, 0x4223, 0x6201, 0x3304 },
{ 0x1146, 0x8267, 0x4223, 0x6201, 0x3304, 0x8267, 0x6201 },
{ 0x5102, 0x1146, 0x8267, 0x4223 },
{ 0x8267, 0x1326, 0x5102, 0x4113, 0x2315, 0x3304, 0x1146 },
{ 0x6201, 0x4113, 0x2315, 0x1326, 0x1146, 0x8267 },
{ 0x6201, 0x3304, 0x1146, 0x8267, 0x1326, 0x5102 },
{ 0x1326, 0x1146, 0x8267 },
//192 4 8 13 14
{ 0x1326, 0x8337, 0x8157, 0x1146 },
{ 0x8337, 0x8157, 0x1146, 0x1326, 0x6201, 0x5102, 0x3304 },
{ 0x8337, 0x8157, 0x1146, 0x1326, 0x6201, 0x2315, 0x4113 },
{ 0x4113, 0x5102, 0x3304, 0x2315, 0x1326, 0x8337, 0x8157, 0x1146 },
{ 0x8337, 0x8157, 0x1146, 0x5102, 0x4223 },
{ 0x8337, 0x8157, 0x1146, 0x5102, 0x4223, 0x8157, 0x5102 },
{ 0x6201, 0x4223, 0x8337, 0x8157, 0x1146, 0x3304 },
{ 0x8337, 0x8157, 0x1146, 0x5102, 0x4223, 0x6201, 0x2315, 0x4113 },
{ 0x4223, 0x8337, 0x8157, 0x1146, 0x3304, 0x2315, 0x4113 },
{ 0x4223, 0x4113, 0x8157, 0x1146, 0x1326 },
{ 0x4223, 0x4113, 0x8157, 0x1146, 0x1326, 0x4113, 0x1146 },
{ 0x4223, 0x4113, 0x8157, 0x1146, 0x1326, 0x6201, 0x5102, 0x3304 },
{ 0x1146, 0x8157, 0x2315, 0x6201, 0x4223, 0x1326 },
{ 0x4223, 0x5102, 0x3304, 0x2315, 0x8157, 0x1146, 0x1326 },
{ 0x4113, 0x8157, 0x1146, 0x5102 },
{ 0x6201, 0x4113, 0x8157, 0x1146, 0x3304 },
{ 0x2315, 0x8157, 0x1146, 0x5102, 0x6201 },
{ 0x6201, 0x4113, 0x8157, 0x1146, 0x3304, 0x4113, 0x1146 },
{ 0x2315, 0x8157, 0x1146, 0x5102, 0x6201, 0x8157, 0x5102 },
{ 0x2315, 0x8157, 0x1146, 0x3304 },
{ 0x2245, 0x3304, 0x1326, 0x8337, 0x8157 },
//208 0 5 12
{ 0x2245, 0x3304, 0x1326, 0x8337, 0x8157, 0x3304, 0x8337 },
{ 0x6201, 0x2245, 0x8157, 0x8337, 0x1326, 0x5102 },
{ 0x2245, 0x3304, 0x1326, 0x8337, 0x8157, 0x6201, 0x2315, 0x4113 },
{ 0x2245, 0x2315, 0x4113, 0x5102, 0x1326, 0x8337, 0x8157 },
{ 0x4223, 0x8337, 0x8157, 0x2245, 0x3304, 0x5102 },
{ 0x8157, 0x2245, 0x6201, 0x4223, 0x8337 },
{ 0x8157, 0x2245, 0x6201, 0x4223, 0x8337, 0x2245, 0x4223 },
{ 0x2245, 0x3304, 0x5102, 0x4223, 0x8337, 0x8157, 0x4113, 0x6201, 0x2315 },
{ 0x4223, 0x8337, 0x8157, 0x2245, 0x2315, 0x4113 },
{ 0x4113, 0x8157, 0x2245, 0x3304, 0x1326, 0x4223 },
{ 0x1326, 0x4223, 0x4113, 0x8157, 0x2245, 0x6201, 0x5102 },
{ 0x8157, 0x2245, 0x3304, 0x1326, 0x4223, 0x6201, 0x2315 },
{ 0x5102, 0x1326, 0x4223, 0x2315, 0x8157, 0x2245 },
{ 0x3304, 0x5102, 0x4113, 0x8157, 0x2245 },
{ 0x3304, 0x5102, 0x4113, 0x8157, 0x2245, 0x5102, 0x8157 },
{ 0x4113, 0x8157, 0x2245, 0x6201 },
{ 0x5102, 0x6201, 0x2315, 0x8157, 0x2245, 0x3304 },
{ 0x2315, 0x8157, 0x2245 },
{ 0x1146, 0x1326, 0x8337, 0x2315, 0x2245 },
//224 0 10 12
{ 0x1146, 0x1326, 0x8337, 0x2315, 0x2245, 0x1326, 0x2315 },
{ 0x1146, 0x1326, 0x8337, 0x2315, 0x2245, 0x6201, 0x5102, 0x3304 },
{ 0x6201, 0x2245, 0x1146, 0x1326, 0x8337, 0x4113 },
{ 0x2245, 0x1146, 0x1326, 0x8337, 0x4113, 0x5102, 0x3304 },
@ -322,21 +337,22 @@ const unsigned short regularVertexData[256][12] = {
{ 0x4223, 0x8337, 0x4113, 0x3304, 0x2245, 0x1146 },
{ 0x4113, 0x2315, 0x2245, 0x1146, 0x1326, 0x4223 },
{ 0x1146, 0x1326, 0x4223, 0x4113, 0x2315, 0x2245, 0x6201, 0x5102, 0x3304 },
{ 0x1326, 0x4223, 0x6201, 0x2245, 0x1146 },
{ 0x1326, 0x4223, 0x6201, 0x2245, 0x1146, 0x4223, 0x2245 },
{ 0x4223, 0x5102, 0x3304, 0x2245, 0x1146, 0x1326 },
{ 0x2245, 0x1146, 0x5102, 0x4113, 0x2315 },
{ 0x2245, 0x1146, 0x5102, 0x4113, 0x2315, 0x1146, 0x4113 },
{ 0x4113, 0x2315, 0x2245, 0x1146, 0x3304, 0x6201 },
{ 0x6201, 0x2245, 0x1146, 0x5102 },
{ 0x3304, 0x2245, 0x1146 },
//240 1 2 4 8
{ 0x3304, 0x1326, 0x8337, 0x2315 },
{ 0x5102, 0x1326, 0x8337, 0x2315, 0x6201 },
{ 0x6201, 0x3304, 0x1326, 0x8337, 0x4113 },
{ 0x5102, 0x1326, 0x8337, 0x2315, 0x6201, 0x1326, 0x2315 },
{ 0x6201, 0x3304, 0x1326, 0x8337, 0x4113, 0x3304, 0x8337 },
{ 0x5102, 0x1326, 0x8337, 0x4113 },
{ 0x4223, 0x8337, 0x2315, 0x3304, 0x5102 },
{ 0x4223, 0x8337, 0x2315, 0x3304, 0x5102, 0x8337, 0x3304 },
{ 0x6201, 0x4223, 0x8337, 0x2315 },
{ 0x3304, 0x5102, 0x4223, 0x8337, 0x4113, 0x6201 },
{ 0x4113, 0x4223, 0x8337 },
{ 0x4113, 0x2315, 0x3304, 0x1326, 0x4223 },
{ 0x4113, 0x2315, 0x3304, 0x1326, 0x4223, 0x2315, 0x1326 },
{ 0x1326, 0x4223, 0x4113, 0x2315, 0x6201, 0x5102 },
{ 0x3304, 0x1326, 0x4223, 0x6201 },
{ 0x5102, 0x1326, 0x4223 },
@ -344,6 +360,7 @@ const unsigned short regularVertexData[256][12] = {
{ 0x6201, 0x4113, 0x2315 },
{ 0x6201, 0x3304, 0x5102 },
{}
//256
};
// The transitionCellClass table maps a 9-bit transition cell case index to an equivalence

View File

@ -73,7 +73,7 @@ struct TransitionCellData {
extern const unsigned char regularCellClass[256];
extern const RegularCellData regularCellData[16];
extern const unsigned short regularVertexData[256][12];
extern unsigned short regularVertexData[256][12];
extern const unsigned char transitionCellClass[512];
extern const TransitionCellData transitionCellData[56];
extern const unsigned char transitionCornerData[13];

View File

@ -1,75 +1,16 @@
#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);
}
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];
}
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 {
Ref<TransvoxelCellData> VoxelMesherTransvoxel::get_regular_cell_data(int index) const {
return _regular_cell_datas[index];
}
@ -78,6 +19,13 @@ int VoxelMesherTransvoxel::get_regular_vertex_data(int index1, int index2) const
return regularVertexData[index1][index2];
}
void VoxelMesherTransvoxel::set_regular_vertex_data(int index1, int index2, int value) {
ERR_FAIL_INDEX(index1, 256);
ERR_FAIL_INDEX(index2, 12);
regularVertexData[index1][index2] = value;
}
int VoxelMesherTransvoxel::get_regular_vertex_data_first_vertex(int index1, int index2) const {
int vert1 = regularVertexData[index1][index2] & 0x000F;
@ -113,7 +61,7 @@ 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 {
Ref<TransvoxelCellData> VoxelMesherTransvoxel::get_transition_cell_data(int index) const {
return _transition_cell_data[index];
}
@ -163,11 +111,11 @@ Vector3 VoxelMesherTransvoxel::get_transition_vertex_direction(int index1, int i
VoxelMesherTransvoxel::VoxelMesherTransvoxel() {
for (int i = 0; i < 16; ++i) {
_regular_cell_datas[i] = Ref<TransvoxelRegularCellData>(memnew(TransvoxelRegularCellData(regularCellData[i])));
_regular_cell_datas[i] = Ref<TransvoxelCellData>(memnew(TransvoxelCellData(regularCellData[i])));
}
for (int i = 0; i < 56; ++i) {
_transition_cell_data[i] = Ref<TransvoxelTransitionCellData>(memnew(TransvoxelTransitionCellData(transitionCellData[i])));
_transition_cell_data[i] = Ref<TransvoxelCellData>(memnew(TransvoxelCellData(transitionCellData[i])));
}
}
@ -182,6 +130,7 @@ 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("set_regular_vertex_data", "index1", "index2", "value"), &VoxelMesherTransvoxel::set_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_first_position", "index1", "index2"), &VoxelMesherTransvoxel::get_regular_vertex_first_position);

View File

@ -4,50 +4,12 @@
#include "core/reference.h"
#include "voxel_mesher.h"
#include "transvoxel_cell_data.h"
#include "transvoxel_tables.h"
using namespace Transvoxel;
class TransvoxelRegularCellData : public Reference {
GDCLASS(TransvoxelRegularCellData, Reference)
public:
int get_vertex_index(int index) const;
int get_vertex_count() const;
int get_triangle_count() const;
TransvoxelRegularCellData();
TransvoxelRegularCellData(RegularCellData cell_data);
~TransvoxelRegularCellData();
protected:
static void _bind_methods();
private:
RegularCellData _cell_data;
};
class TransvoxelTransitionCellData : public Reference {
GDCLASS(TransvoxelTransitionCellData, Reference)
public:
int get_vertex_index(int index) const;
int get_vertex_count() const;
int get_triangle_count() const;
TransvoxelTransitionCellData();
TransvoxelTransitionCellData(TransitionCellData cell_data);
~TransvoxelTransitionCellData();
protected:
static void _bind_methods();
private:
TransitionCellData _cell_data;
};
class VoxelMesherTransvoxel : public VoxelMesher {
GDCLASS(VoxelMesherTransvoxel, VoxelMesher)
@ -85,8 +47,9 @@ public:
int get_regular_cell_class(int index) const;
Ref<TransvoxelRegularCellData> get_regular_cell_data(int index) const;
Ref<TransvoxelCellData> get_regular_cell_data(int index) const;
int get_regular_vertex_data(int index10, int index2) const;
void set_regular_vertex_data(int index1, int index2, int value);
int get_regular_vertex_data_first_vertex(int index1, int index2) const;
int get_regular_vertex_data_second_vertex(int index1, int index2) const;
Vector3 get_regular_vertex_first_position(int index1, int index2) const;
@ -95,7 +58,7 @@ public:
int get_transition_cell_class(int index) const;
Ref<TransvoxelTransitionCellData> get_transition_cell_data(int index) const;
Ref<TransvoxelCellData> get_transition_cell_data(int index) const;
int get_transition_corner_data(int index) const;
int get_transition_vertex_data(int index1, int index2) const;
int get_transition_vertex_data_first_vertex(int index1, int index2) const;
@ -109,8 +72,8 @@ public:
protected:
static void _bind_methods();
Ref<TransvoxelRegularCellData> _regular_cell_datas[16];
Ref<TransvoxelTransitionCellData> _transition_cell_data[56];
Ref<TransvoxelCellData> _regular_cell_datas[16];
Ref<TransvoxelCellData> _transition_cell_data[56];
};
VARIANT_ENUM_CAST(VoxelMesherTransvoxel::VoxelEntryIndices);

View File

@ -5,6 +5,7 @@
#include "data/voxel_light.h"
#include "meshers/voxel_mesher.h"
#include "meshers/transvoxel_cell_data.h"
#include "meshers/voxel_mesher_transvoxel.h"
#include "meshers/voxel_mesher_transvoxel_terrarin.h"
@ -24,8 +25,7 @@ void register_voxelman_types() {
ClassDB::register_class<VoxelMesher>();
ClassDB::register_class<VoxelMesherTransvoxel>();
ClassDB::register_class<VoxelMesherTransvoxelTerrarin>();
ClassDB::register_class<TransvoxelRegularCellData>();
ClassDB::register_class<TransvoxelTransitionCellData>();
ClassDB::register_class<TransvoxelCellData>();
ClassDB::register_class<VoxelSurface>();
ClassDB::register_class<VoxelmanLibrary>();