Now the type and isolevel channels are customizable in the meshers.

This commit is contained in:
Relintai 2020-08-21 20:02:22 +02:00
parent 4921252475
commit 5938f7f783
9 changed files with 170 additions and 81 deletions

View File

@ -38,7 +38,7 @@ void VoxelMesherBlocky::_add_chunk(Ref<VoxelChunk> p_chunk) {
float voxel_scale = get_voxel_scale();
uint8_t *channel_type = chunk->get_channel(VoxelChunkDefault::DEFAULT_CHANNEL_TYPE);
uint8_t *channel_type = chunk->get_channel(_channel_index_type);
if (!channel_type)
return;

View File

@ -112,6 +112,20 @@ void VoxelCubePoints::set_size(int value) {
_size = value;
}
int VoxelCubePoints::get_channel_index_type() const {
return _channel_index_type;
}
void VoxelCubePoints::set_channel_index_type(const int value) {
_channel_index_type = value;
}
int VoxelCubePoints::get_channel_index_isolevel() const {
return _channel_index_isolevel;
}
void VoxelCubePoints::set_channel_index_isolevel(const int value) {
_channel_index_isolevel = value;
}
void VoxelCubePoints::refresh_points() {
for (int i = 0; i < POINT_COUNT; ++i) {
recalculate_point(i);
@ -202,25 +216,25 @@ void VoxelCubePoints::refresh_neighbours(Ref<VoxelChunk> chunk) {
int z = _z;
//000
if (chunk->get_voxel(x - 1, y, z, VoxelChunkDefault::DEFAULT_CHANNEL_TYPE) != 0)
if (chunk->get_voxel(x - 1, y, z, _channel_index_type) != 0)
neighbours = neighbours | VOXEL_NEIGHBOUR_LEFT;
if (chunk->get_voxel(x, y - 1, z, VoxelChunkDefault::DEFAULT_CHANNEL_TYPE) != 0)
if (chunk->get_voxel(x, y - 1, z, _channel_index_type) != 0)
neighbours = neighbours | VOXEL_NEIGHBOUR_BOTTOM;
if (chunk->get_voxel(x, y, z - 1, VoxelChunkDefault::DEFAULT_CHANNEL_TYPE) != 0)
if (chunk->get_voxel(x, y, z - 1, _channel_index_type) != 0)
neighbours = neighbours | VOXEL_NEIGHBOUR_FRONT;
/*
if (chunk->get_voxel(x - 1, y, z - 1, VoxelChunkDefault::DEFAULT_CHANNEL_TYPE) != 0)
if (chunk->get_voxel(x - 1, y, z - 1, _channel_index_type) != 0)
neighbours = neighbours | VOXEL_NEIGHBOUR_LEFT_FRONT;
if (chunk->get_voxel(x - 1, y - 1, z, VoxelChunkDefault::DEFAULT_CHANNEL_TYPE) != 0)
if (chunk->get_voxel(x - 1, y - 1, z, _channel_index_type) != 0)
neighbours = neighbours | VOXEL_NEIGHBOUR_BOTTOM_LEFT;
if (chunk->get_voxel(x, y - 1, z - 1, VoxelChunkDefault::DEFAULT_CHANNEL_TYPE) != 0)
if (chunk->get_voxel(x, y - 1, z - 1, _channel_index_type) != 0)
neighbours = neighbours | VOXEL_NEIGHBOUR_BOTTOM_FRONT;
if (chunk->get_voxel(x - 1, y - 1, z - 1, VoxelChunkDefault::DEFAULT_CHANNEL_TYPE) != 0)
if (chunk->get_voxel(x - 1, y - 1, z - 1, _channel_index_type) != 0)
neighbours = neighbours | VOXEL_NEIGHBOUR_BOTTOM_LEFT_FRONT;*/
_point_neighbours[P000] = neighbours;
@ -231,25 +245,25 @@ void VoxelCubePoints::refresh_neighbours(Ref<VoxelChunk> chunk) {
z = _z;
//100
if (chunk->get_voxel(x + 1, y, z, VoxelChunkDefault::DEFAULT_CHANNEL_TYPE) != 0)
if (chunk->get_voxel(x + 1, y, z, _channel_index_type) != 0)
neighbours = neighbours | VOXEL_NEIGHBOUR_RIGHT;
if (chunk->get_voxel(x, y - 1, z, VoxelChunkDefault::DEFAULT_CHANNEL_TYPE) != 0)
if (chunk->get_voxel(x, y - 1, z, _channel_index_type) != 0)
neighbours = neighbours | VOXEL_NEIGHBOUR_BOTTOM;
if (chunk->get_voxel(x, y, z - 1, VoxelChunkDefault::DEFAULT_CHANNEL_TYPE) != 0)
if (chunk->get_voxel(x, y, z - 1, _channel_index_type) != 0)
neighbours = neighbours | VOXEL_NEIGHBOUR_FRONT;
/*
if (chunk->get_voxel(x + 1, y, z - 1, VoxelChunkDefault::DEFAULT_CHANNEL_TYPE) != 0)
if (chunk->get_voxel(x + 1, y, z - 1, _channel_index_type) != 0)
neighbours = neighbours | VOXEL_NEIGHBOUR_RIGHT_FRONT;
if (chunk->get_voxel(x + 1, y - 1, z, VoxelChunkDefault::DEFAULT_CHANNEL_TYPE) != 0)
if (chunk->get_voxel(x + 1, y - 1, z, _channel_index_type) != 0)
neighbours = neighbours | VOXEL_NEIGHBOUR_BOTTOM_RIGHT;
if (chunk->get_voxel(x, y - 1, z - 1, VoxelChunkDefault::DEFAULT_CHANNEL_TYPE) != 0)
if (chunk->get_voxel(x, y - 1, z - 1, _channel_index_type) != 0)
neighbours = neighbours | VOXEL_NEIGHBOUR_BOTTOM_FRONT;
if (chunk->get_voxel(x + 1, y - 1, z - 1, VoxelChunkDefault::DEFAULT_CHANNEL_TYPE) != 0)
if (chunk->get_voxel(x + 1, y - 1, z - 1, _channel_index_type) != 0)
neighbours = neighbours | VOXEL_NEIGHBOUR_BOTTOM_RIGHT_FRONT;*/
_point_neighbours[P100] = neighbours;
@ -260,25 +274,25 @@ void VoxelCubePoints::refresh_neighbours(Ref<VoxelChunk> chunk) {
z = _z;
//010
if (chunk->get_voxel(x - 1, y, z, VoxelChunkDefault::DEFAULT_CHANNEL_TYPE) != 0)
if (chunk->get_voxel(x - 1, y, z, _channel_index_type) != 0)
neighbours = neighbours | VOXEL_NEIGHBOUR_LEFT;
if (chunk->get_voxel(x, y + 1, z, VoxelChunkDefault::DEFAULT_CHANNEL_TYPE) != 0)
if (chunk->get_voxel(x, y + 1, z, _channel_index_type) != 0)
neighbours = neighbours | VOXEL_NEIGHBOUR_TOP;
if (chunk->get_voxel(x, y, z - 1, VoxelChunkDefault::DEFAULT_CHANNEL_TYPE) != 0)
if (chunk->get_voxel(x, y, z - 1, _channel_index_type) != 0)
neighbours = neighbours | VOXEL_NEIGHBOUR_FRONT;
/*
if (chunk->get_voxel(x - 1, y, z - 1, VoxelChunkDefault::DEFAULT_CHANNEL_TYPE) != 0)
if (chunk->get_voxel(x - 1, y, z - 1, _channel_index_type) != 0)
neighbours = neighbours | VOXEL_NEIGHBOUR_LEFT_FRONT;
if (chunk->get_voxel(x - 1, y + 1, z, VoxelChunkDefault::DEFAULT_CHANNEL_TYPE) != 0)
if (chunk->get_voxel(x - 1, y + 1, z, _channel_index_type) != 0)
neighbours = neighbours | VOXEL_NEIGHBOUR_TOP_LEFT;
if (chunk->get_voxel(x, y + 1, z - 1, VoxelChunkDefault::DEFAULT_CHANNEL_TYPE) != 0)
if (chunk->get_voxel(x, y + 1, z - 1, _channel_index_type) != 0)
neighbours = neighbours | VOXEL_NEIGHBOUR_TOP_FRONT;
if (chunk->get_voxel(x - 1, y + 1, z - 1, VoxelChunkDefault::DEFAULT_CHANNEL_TYPE) != 0)
if (chunk->get_voxel(x - 1, y + 1, z - 1, _channel_index_type) != 0)
neighbours = neighbours | VOXEL_NEIGHBOUR_TOP_LEFT_FRONT;*/
_point_neighbours[P010] = neighbours;
@ -289,25 +303,25 @@ void VoxelCubePoints::refresh_neighbours(Ref<VoxelChunk> chunk) {
z = _z;
//110
if (chunk->get_voxel(x + 1, y, z, VoxelChunkDefault::DEFAULT_CHANNEL_TYPE) != 0)
if (chunk->get_voxel(x + 1, y, z, _channel_index_type) != 0)
neighbours = neighbours | VOXEL_NEIGHBOUR_RIGHT;
if (chunk->get_voxel(x, y + 1, z, VoxelChunkDefault::DEFAULT_CHANNEL_TYPE) != 0)
if (chunk->get_voxel(x, y + 1, z, _channel_index_type) != 0)
neighbours = neighbours | VOXEL_NEIGHBOUR_TOP;
if (chunk->get_voxel(x, y, z - 1, VoxelChunkDefault::DEFAULT_CHANNEL_TYPE) != 0)
if (chunk->get_voxel(x, y, z - 1, _channel_index_type) != 0)
neighbours = neighbours | VOXEL_NEIGHBOUR_FRONT;
/*
if (chunk->get_voxel(x + 1, y, z - 1, VoxelChunkDefault::DEFAULT_CHANNEL_TYPE) != 0)
if (chunk->get_voxel(x + 1, y, z - 1, _channel_index_type) != 0)
neighbours = neighbours | VOXEL_NEIGHBOUR_RIGHT_FRONT;
if (chunk->get_voxel(x + 1, y + 1, z, VoxelChunkDefault::DEFAULT_CHANNEL_TYPE) != 0)
if (chunk->get_voxel(x + 1, y + 1, z, _channel_index_type) != 0)
neighbours = neighbours | VOXEL_NEIGHBOUR_TOP_RIGHT;
if (chunk->get_voxel(x, y + 1, z - 1, VoxelChunkDefault::DEFAULT_CHANNEL_TYPE) != 0)
if (chunk->get_voxel(x, y + 1, z - 1, _channel_index_type) != 0)
neighbours = neighbours | VOXEL_NEIGHBOUR_TOP_FRONT;
if (chunk->get_voxel(x + 1, y + 1, z - 1, VoxelChunkDefault::DEFAULT_CHANNEL_TYPE) != 0)
if (chunk->get_voxel(x + 1, y + 1, z - 1, _channel_index_type) != 0)
neighbours = neighbours | VOXEL_NEIGHBOUR_TOP_RIGHT_FRONT;*/
_point_neighbours[P110] = neighbours;
@ -318,25 +332,25 @@ void VoxelCubePoints::refresh_neighbours(Ref<VoxelChunk> chunk) {
z = _z + 1;
//001
if (chunk->get_voxel(x - 1, y, z, VoxelChunkDefault::DEFAULT_CHANNEL_TYPE) != 0)
if (chunk->get_voxel(x - 1, y, z, _channel_index_type) != 0)
neighbours = neighbours | VOXEL_NEIGHBOUR_LEFT;
if (chunk->get_voxel(x, y - 1, z, VoxelChunkDefault::DEFAULT_CHANNEL_TYPE) != 0)
if (chunk->get_voxel(x, y - 1, z, _channel_index_type) != 0)
neighbours = neighbours | VOXEL_NEIGHBOUR_BOTTOM;
if (chunk->get_voxel(x, y, z + 1, VoxelChunkDefault::DEFAULT_CHANNEL_TYPE) != 0)
if (chunk->get_voxel(x, y, z + 1, _channel_index_type) != 0)
neighbours = neighbours | VOXEL_NEIGHBOUR_BACK;
/*
if (chunk->get_voxel(x - 1, y, z + 1, VoxelChunkDefault::DEFAULT_CHANNEL_TYPE) != 0)
if (chunk->get_voxel(x - 1, y, z + 1, _channel_index_type) != 0)
neighbours = neighbours | VOXEL_NEIGHBOUR_LEFT_BACK;
if (chunk->get_voxel(x - 1, y - 1, z, VoxelChunkDefault::DEFAULT_CHANNEL_TYPE) != 0)
if (chunk->get_voxel(x - 1, y - 1, z, _channel_index_type) != 0)
neighbours = neighbours | VOXEL_NEIGHBOUR_BOTTOM_LEFT;
if (chunk->get_voxel(x, y - 1, z + 1, VoxelChunkDefault::DEFAULT_CHANNEL_TYPE) != 0)
if (chunk->get_voxel(x, y - 1, z + 1, _channel_index_type) != 0)
neighbours = neighbours | VOXEL_NEIGHBOUR_BOTTOM_BACK;
if (chunk->get_voxel(x - 1, y - 1, z + 1, VoxelChunkDefault::DEFAULT_CHANNEL_TYPE) != 0)
if (chunk->get_voxel(x - 1, y - 1, z + 1, _channel_index_type) != 0)
neighbours = neighbours | VOXEL_NEIGHBOUR_BOTTOM_LEFT_BACK;*/
_point_neighbours[P001] = neighbours;
@ -347,25 +361,25 @@ void VoxelCubePoints::refresh_neighbours(Ref<VoxelChunk> chunk) {
z = _z + 1;
//101
if (chunk->get_voxel(x + 1, y, z, VoxelChunkDefault::DEFAULT_CHANNEL_TYPE) != 0)
if (chunk->get_voxel(x + 1, y, z, _channel_index_type) != 0)
neighbours = neighbours | VOXEL_NEIGHBOUR_RIGHT;
if (chunk->get_voxel(x, y - 1, z, VoxelChunkDefault::DEFAULT_CHANNEL_TYPE) != 0)
if (chunk->get_voxel(x, y - 1, z, _channel_index_type) != 0)
neighbours = neighbours | VOXEL_NEIGHBOUR_BOTTOM;
if (chunk->get_voxel(x, y, z + 1, VoxelChunkDefault::DEFAULT_CHANNEL_TYPE) != 0)
if (chunk->get_voxel(x, y, z + 1, _channel_index_type) != 0)
neighbours = neighbours | VOXEL_NEIGHBOUR_BACK;
/*
if (chunk->get_voxel(x + 1, y, z + 1, VoxelChunkDefault::DEFAULT_CHANNEL_TYPE) != 0)
if (chunk->get_voxel(x + 1, y, z + 1, _channel_index_type) != 0)
neighbours = neighbours | VOXEL_NEIGHBOUR_RIGHT_BACK;
if (chunk->get_voxel(x + 1, y - 1, z, VoxelChunkDefault::DEFAULT_CHANNEL_TYPE) != 0)
if (chunk->get_voxel(x + 1, y - 1, z, _channel_index_type) != 0)
neighbours = neighbours | VOXEL_NEIGHBOUR_BOTTOM_RIGHT;
if (chunk->get_voxel(x, y - 1, z + 1, VoxelChunkDefault::DEFAULT_CHANNEL_TYPE) != 0)
if (chunk->get_voxel(x, y - 1, z + 1, _channel_index_type) != 0)
neighbours = neighbours | VOXEL_NEIGHBOUR_BOTTOM_BACK;
if (chunk->get_voxel(x + 1, y - 1, z + 1, VoxelChunkDefault::DEFAULT_CHANNEL_TYPE) != 0)
if (chunk->get_voxel(x + 1, y - 1, z + 1, _channel_index_type) != 0)
neighbours = neighbours | VOXEL_NEIGHBOUR_BOTTOM_RIGHT_BACK;*/
_point_neighbours[P101] = neighbours;
@ -376,25 +390,25 @@ void VoxelCubePoints::refresh_neighbours(Ref<VoxelChunk> chunk) {
z = _z + 1;
//011
if (chunk->get_voxel(x - 1, y, z, VoxelChunkDefault::DEFAULT_CHANNEL_TYPE) != 0)
if (chunk->get_voxel(x - 1, y, z, _channel_index_type) != 0)
neighbours = neighbours | VOXEL_NEIGHBOUR_LEFT;
if (chunk->get_voxel(x, y + 1, z, VoxelChunkDefault::DEFAULT_CHANNEL_TYPE) != 0)
if (chunk->get_voxel(x, y + 1, z, _channel_index_type) != 0)
neighbours = neighbours | VOXEL_NEIGHBOUR_TOP;
if (chunk->get_voxel(x, y, z + 1, VoxelChunkDefault::DEFAULT_CHANNEL_TYPE) != 0)
if (chunk->get_voxel(x, y, z + 1, _channel_index_type) != 0)
neighbours = neighbours | VOXEL_NEIGHBOUR_BACK;
/*
if (chunk->get_voxel(x - 1, y, z + 1, VoxelChunkDefault::DEFAULT_CHANNEL_TYPE) != 0)
if (chunk->get_voxel(x - 1, y, z + 1, _channel_index_type) != 0)
neighbours = neighbours | VOXEL_NEIGHBOUR_LEFT_BACK;
if (chunk->get_voxel(x - 1, y + 1, z, VoxelChunkDefault::DEFAULT_CHANNEL_TYPE) != 0)
if (chunk->get_voxel(x - 1, y + 1, z, _channel_index_type) != 0)
neighbours = neighbours | VOXEL_NEIGHBOUR_TOP_LEFT;
if (chunk->get_voxel(x, y + 1, z + 1, VoxelChunkDefault::DEFAULT_CHANNEL_TYPE) != 0)
if (chunk->get_voxel(x, y + 1, z + 1, _channel_index_type) != 0)
neighbours = neighbours | VOXEL_NEIGHBOUR_TOP_BACK;
if (chunk->get_voxel(x - 1, y + 1, z + 1, VoxelChunkDefault::DEFAULT_CHANNEL_TYPE) != 0)
if (chunk->get_voxel(x - 1, y + 1, z + 1, _channel_index_type) != 0)
neighbours = neighbours | VOXEL_NEIGHBOUR_TOP_LEFT_BACK;*/
_point_neighbours[P011] = neighbours;
@ -405,25 +419,25 @@ void VoxelCubePoints::refresh_neighbours(Ref<VoxelChunk> chunk) {
z = _z + 1;
//111
if (chunk->get_voxel(x + 1, y, z, VoxelChunkDefault::DEFAULT_CHANNEL_TYPE) != 0)
if (chunk->get_voxel(x + 1, y, z, _channel_index_type) != 0)
neighbours = neighbours | VOXEL_NEIGHBOUR_RIGHT;
if (chunk->get_voxel(x, y + 1, z, VoxelChunkDefault::DEFAULT_CHANNEL_TYPE) != 0)
if (chunk->get_voxel(x, y + 1, z, _channel_index_type) != 0)
neighbours = neighbours | VOXEL_NEIGHBOUR_TOP;
if (chunk->get_voxel(x, y, z + 1, VoxelChunkDefault::DEFAULT_CHANNEL_TYPE) != 0)
if (chunk->get_voxel(x, y, z + 1, _channel_index_type) != 0)
neighbours = neighbours | VOXEL_NEIGHBOUR_BACK;
/*
if (chunk->get_voxel(x + 1, y, z + 1, VoxelChunkDefault::DEFAULT_CHANNEL_TYPE) != 0)
if (chunk->get_voxel(x + 1, y, z + 1, _channel_index_type) != 0)
neighbours = neighbours | VOXEL_NEIGHBOUR_RIGHT_BACK;
if (chunk->get_voxel(x + 1, y + 1, z, VoxelChunkDefault::DEFAULT_CHANNEL_TYPE) != 0)
if (chunk->get_voxel(x + 1, y + 1, z, _channel_index_type) != 0)
neighbours = neighbours | VOXEL_NEIGHBOUR_TOP_RIGHT;
if (chunk->get_voxel(x, y + 1, z + 1, VoxelChunkDefault::DEFAULT_CHANNEL_TYPE) != 0)
if (chunk->get_voxel(x, y + 1, z + 1, _channel_index_type) != 0)
neighbours = neighbours | VOXEL_NEIGHBOUR_TOP_BACK;
if (chunk->get_voxel(x + 1, y + 1, z + 1, VoxelChunkDefault::DEFAULT_CHANNEL_TYPE) != 0)
if (chunk->get_voxel(x + 1, y + 1, z + 1, _channel_index_type) != 0)
neighbours = neighbours | VOXEL_NEIGHBOUR_TOP_RIGHT_BACK;*/
_point_neighbours[P111] = neighbours;
@ -441,26 +455,26 @@ void VoxelCubePoints::setup(Ref<VoxelChunk> chunk, int x, int y, int z, int size
_z = z;
_size = size;
_point_types[P000] = chunk->get_voxel(x, y, z, VoxelChunkDefault::DEFAULT_CHANNEL_TYPE);
_point_types[P100] = chunk->get_voxel(x + size, y, z, VoxelChunkDefault::DEFAULT_CHANNEL_TYPE);
_point_types[P010] = chunk->get_voxel(x, y + size, z, VoxelChunkDefault::DEFAULT_CHANNEL_TYPE);
_point_types[P001] = chunk->get_voxel(x, y, z + size, VoxelChunkDefault::DEFAULT_CHANNEL_TYPE);
_point_types[P110] = chunk->get_voxel(x + size, y + size, z, VoxelChunkDefault::DEFAULT_CHANNEL_TYPE);
_point_types[P011] = chunk->get_voxel(x, y + size, z + size, VoxelChunkDefault::DEFAULT_CHANNEL_TYPE);
_point_types[P101] = chunk->get_voxel(x + size, y, z + size, VoxelChunkDefault::DEFAULT_CHANNEL_TYPE);
_point_types[P111] = chunk->get_voxel(x + size, y + size, z + size, VoxelChunkDefault::DEFAULT_CHANNEL_TYPE);
_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;
_point_fills[P000] = chunk->get_voxel(x, y, z, VoxelChunkDefault::DEFAULT_CHANNEL_ISOLEVEL);
_point_fills[P100] = chunk->get_voxel(x + size, y, z, VoxelChunkDefault::DEFAULT_CHANNEL_ISOLEVEL);
_point_fills[P010] = chunk->get_voxel(x, y + size, z, VoxelChunkDefault::DEFAULT_CHANNEL_ISOLEVEL);
_point_fills[P001] = chunk->get_voxel(x, y, z + size, VoxelChunkDefault::DEFAULT_CHANNEL_ISOLEVEL);
_point_fills[P110] = chunk->get_voxel(x + size, y + size, z, VoxelChunkDefault::DEFAULT_CHANNEL_ISOLEVEL);
_point_fills[P011] = chunk->get_voxel(x, y + size, z + size, VoxelChunkDefault::DEFAULT_CHANNEL_ISOLEVEL);
_point_fills[P101] = chunk->get_voxel(x + size, y, z + size, VoxelChunkDefault::DEFAULT_CHANNEL_ISOLEVEL);
_point_fills[P111] = chunk->get_voxel(x + size, y + size, z + size, VoxelChunkDefault::DEFAULT_CHANNEL_ISOLEVEL);
_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);
_point_aos[P000] = chunk->get_voxel(x, y, z, VoxelChunkDefault::DEFAULT_CHANNEL_AO);
_point_aos[P100] = chunk->get_voxel(x + size, y, z, VoxelChunkDefault::DEFAULT_CHANNEL_AO);
@ -776,6 +790,9 @@ int VoxelCubePoints::get_opposite_face(int face) {
}
VoxelCubePoints::VoxelCubePoints() {
_channel_index_type = 0;
_channel_index_isolevel = 0;
reset();
}
@ -800,6 +817,14 @@ void VoxelCubePoints::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_size", "value"), &VoxelCubePoints::set_size);
ADD_PROPERTY(PropertyInfo(Variant::INT, "size"), "set_size", "get_size");
ClassDB::bind_method(D_METHOD("get_channel_index_type"), &VoxelCubePoints::get_channel_index_type);
ClassDB::bind_method(D_METHOD("set_channel_index_type", "value"), &VoxelCubePoints::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"), &VoxelCubePoints::get_channel_index_isolevel);
ClassDB::bind_method(D_METHOD("set_channel_index_isolevel", "value"), &VoxelCubePoints::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"), &VoxelCubePoints::refresh_points);
ClassDB::bind_method(D_METHOD("setup", "chunk", "x", "y", "z", "size"), &VoxelCubePoints::setup, DEFVAL(1));

View File

@ -110,6 +110,12 @@ public:
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<VoxelChunk> chunk);
@ -166,6 +172,9 @@ protected:
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];

View File

@ -40,6 +40,14 @@ void VoxelMesherCubic::_add_chunk(Ref<VoxelChunk> p_chunk) {
ERR_FAIL_COND(!chunk.is_valid());
if (!chunk->get_channel(_channel_index_type)) {
return;
}
if (chunk->get_channel(VoxelChunkDefault::DEFAULT_CHANNEL_RANDOM_AO)) {
chunk->generate_ao();
}
int x_size = chunk->get_size_x();
int y_size = chunk->get_size_y();
int z_size = chunk->get_size_z();
@ -49,6 +57,8 @@ void VoxelMesherCubic::_add_chunk(Ref<VoxelChunk> p_chunk) {
Ref<VoxelCubePoints> 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);

View File

@ -47,7 +47,7 @@ void VoxelMesherMarchingCubes::set_texture_scale(const int value) {
}
void VoxelMesherMarchingCubes::get_voxel_type_array(int *arr, Ref<VoxelChunk> chunk, const int x, const int y, const int z, const int size) {
uint8_t *channel_type = chunk->get_channel(VoxelChunkDefault::DEFAULT_CHANNEL_TYPE);
uint8_t *channel_type = chunk->get_channel(_channel_index_type);
if (channel_type == NULL) {
arr[0] = 0;
@ -100,7 +100,7 @@ int VoxelMesherMarchingCubes::get_case_code_from_arr(const int *data) {
return case_code;
}
int VoxelMesherMarchingCubes::get_case_code(Ref<VoxelChunk> chunk, const int x, const int y, const int z, const int size) {
uint8_t *channel_type = chunk->get_channel(VoxelChunkDefault::DEFAULT_CHANNEL_TYPE);
uint8_t *channel_type = chunk->get_channel(_channel_index_type);
if (channel_type == NULL) {
return 0;
@ -136,7 +136,7 @@ int VoxelMesherMarchingCubes::get_case_code(Ref<VoxelChunk> chunk, const int x,
}
int VoxelMesherMarchingCubes::get_voxel_type(Ref<VoxelChunk> chunk, const int x, const int y, const int z, const int size) {
uint8_t *channel_type = chunk->get_channel(VoxelChunkDefault::DEFAULT_CHANNEL_TYPE);
uint8_t *channel_type = chunk->get_channel(_channel_index_type);
if (channel_type == NULL) {
return 0;
@ -324,7 +324,7 @@ void VoxelMesherMarchingCubes::_add_chunk(Ref<VoxelChunk> p_chunk) {
Vector3 offs0 = corner_id_to_vertex(fv) * lod_size;
Vector3 offs1 = corner_id_to_vertex(sv) * lod_size;
int type = chunk->get_voxel(int(x + offs0.x), int(y + offs0.y), int(z + offs0.z), VoxelChunkDefault::DEFAULT_CHANNEL_TYPE);
int type = chunk->get_voxel(int(x + offs0.x), int(y + offs0.y), int(z + offs0.z), _channel_index_type);
int fill = 0;
@ -332,12 +332,12 @@ void VoxelMesherMarchingCubes::_add_chunk(Ref<VoxelChunk> p_chunk) {
Vector3 vert_dir;
if (type == 0) {
fill = chunk->get_voxel(int(x + offs1.x), int(y + offs1.y), int(z + offs1.z), VoxelChunkDefault::DEFAULT_CHANNEL_ISOLEVEL);
fill = chunk->get_voxel(int(x + offs1.x), int(y + offs1.y), int(z + offs1.z), _channel_index_isolevel);
vert_pos = get_regular_vertex_second_position(case_code, i);
vert_dir = get_regular_vertex_first_position(case_code, i);
} else {
fill = chunk->get_voxel(int(x + offs0.x), int(y + offs0.y), int(z + offs0.z), VoxelChunkDefault::DEFAULT_CHANNEL_ISOLEVEL);
fill = chunk->get_voxel(int(x + offs0.x), int(y + offs0.y), int(z + offs0.z), _channel_index_isolevel);
vert_pos = get_regular_vertex_first_position(case_code, i);
vert_dir = get_regular_vertex_second_position(case_code, i);

View File

@ -79,6 +79,20 @@ uint32_t VoxelMesher::VertexHasher::hash(const Vertex &p_vtx) {
return h;
}
int VoxelMesher::get_channel_index_type() const {
return _channel_index_type;
}
void VoxelMesher::set_channel_index_type(const int value) {
_channel_index_type = value;
}
int VoxelMesher::get_channel_index_isolevel() const {
return _channel_index_isolevel;
}
void VoxelMesher::set_channel_index_isolevel(const int value) {
_channel_index_isolevel = value;
}
int VoxelMesher::get_mesher_index() const {
return _mesher_index;
}
@ -888,6 +902,8 @@ VoxelMesher::VoxelMesher(const Ref<VoxelmanLibrary> &library) {
_ao_strength = 0.25;
_base_light_value = 0.5;
_uv_margin = Rect2(0, 0, 1, 1);
_channel_index_type = 0;
_channel_index_isolevel = 0;
_format = 0;
}
@ -900,6 +916,8 @@ VoxelMesher::VoxelMesher() {
_base_light_value = 0.5;
_uv_margin = Rect2(0, 0, 1, 1);
_format = 0;
_channel_index_type = 0;
_channel_index_isolevel = 0;
}
VoxelMesher::~VoxelMesher() {
@ -913,6 +931,14 @@ void VoxelMesher::_bind_methods() {
BIND_VMETHOD(MethodInfo("_bake_colors", PropertyInfo(Variant::OBJECT, "chunk", PROPERTY_HINT_RESOURCE_TYPE, "VoxelChunk")));
BIND_VMETHOD(MethodInfo("_bake_liquid_colors", PropertyInfo(Variant::OBJECT, "chunk", PROPERTY_HINT_RESOURCE_TYPE, "VoxelChunk")));
ClassDB::bind_method(D_METHOD("get_channel_index_type"), &VoxelMesher::get_channel_index_type);
ClassDB::bind_method(D_METHOD("set_channel_index_type", "value"), &VoxelMesher::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"), &VoxelMesher::get_channel_index_isolevel);
ClassDB::bind_method(D_METHOD("set_channel_index_isolevel", "value"), &VoxelMesher::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("get_mesher_index"), &VoxelMesher::get_mesher_index);
ClassDB::bind_method(D_METHOD("set_mesher_index", "value"), &VoxelMesher::set_mesher_index);
ADD_PROPERTY(PropertyInfo(Variant::INT, "mesher_index"), "set_mesher_index", "get_mesher_index");

View File

@ -87,6 +87,12 @@ public:
};
public:
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);
int get_mesher_index() const;
void set_mesher_index(const int value);
@ -182,6 +188,9 @@ public:
protected:
static void _bind_methods();
int _channel_index_type;
int _channel_index_isolevel;
int _mesher_index;
int _format;

View File

@ -38,7 +38,12 @@ void VoxelChunkCubic::_setup_channels() {
void VoxelChunkCubic::_create_meshers() {
set_prop_mesher(Ref<VoxelMesher>(memnew(VoxelMesherCubic)));
add_mesher(Ref<VoxelMesher>(memnew(VoxelMesherCubic())));
Ref<VoxelMesher> m = Ref<VoxelMesher>(memnew(VoxelMesherCubic()));
m->set_channel_index_type(VoxelChunkDefault::DEFAULT_CHANNEL_TYPE);
m->set_channel_index_isolevel(VoxelChunkDefault::DEFAULT_CHANNEL_ISOLEVEL);
add_mesher(m);
//add_liquid_mesher(Ref<VoxelMesher>(memnew(VoxelMesherLiquiCubic())));
for (int i = 0; i < _meshers.size(); ++i) {

View File

@ -38,7 +38,12 @@ void VoxelChunkMarchingCubes::_setup_channels() {
void VoxelChunkMarchingCubes::_create_meshers() {
set_prop_mesher(Ref<VoxelMesher>(memnew(VoxelMesherMarchingCubes)));
add_mesher(Ref<VoxelMesher>(memnew(VoxelMesherMarchingCubes())));
Ref<VoxelMesher> m = Ref<VoxelMesher>(memnew(VoxelMesherMarchingCubes()));
m->set_channel_index_type(VoxelChunkDefault::DEFAULT_CHANNEL_TYPE);
m->set_channel_index_isolevel(VoxelChunkDefault::DEFAULT_CHANNEL_ISOLEVEL);
add_mesher(m);
//add_liquid_mesher(Ref<VoxelMesher>(memnew(VoxelMesherLiquidMarchingCubes())));
for (int i = 0; i < _meshers.size(); ++i) {