From 5938f7f783cfc668bd1bc91068b1aa4e7eb3a360 Mon Sep 17 00:00:00 2001 From: Relintai Date: Fri, 21 Aug 2020 20:02:22 +0200 Subject: [PATCH] Now the type and isolevel channels are customizable in the meshers. --- meshers/blocky/voxel_mesher_blocky.cpp | 2 +- meshers/cubic/voxel_cube_points.cpp | 169 ++++++++++-------- meshers/cubic/voxel_cube_points.h | 9 + meshers/cubic/voxel_mesher_cubic.cpp | 10 ++ .../voxel_mesher_marching_cubes.cpp | 12 +- meshers/voxel_mesher.cpp | 26 +++ meshers/voxel_mesher.h | 9 + world/cubic/voxel_chunk_cubic.cpp | 7 +- .../voxel_chunk_marching_cubes.cpp | 7 +- 9 files changed, 170 insertions(+), 81 deletions(-) diff --git a/meshers/blocky/voxel_mesher_blocky.cpp b/meshers/blocky/voxel_mesher_blocky.cpp index 5c7b6b2..c78f0a4 100644 --- a/meshers/blocky/voxel_mesher_blocky.cpp +++ b/meshers/blocky/voxel_mesher_blocky.cpp @@ -38,7 +38,7 @@ void VoxelMesherBlocky::_add_chunk(Ref 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; diff --git a/meshers/cubic/voxel_cube_points.cpp b/meshers/cubic/voxel_cube_points.cpp index 12d47f4..d587c24 100644 --- a/meshers/cubic/voxel_cube_points.cpp +++ b/meshers/cubic/voxel_cube_points.cpp @@ -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 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 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 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 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 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 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 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 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 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)); diff --git a/meshers/cubic/voxel_cube_points.h b/meshers/cubic/voxel_cube_points.h index 45ad487..fcc668e 100644 --- a/meshers/cubic/voxel_cube_points.h +++ b/meshers/cubic/voxel_cube_points.h @@ -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 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]; diff --git a/meshers/cubic/voxel_mesher_cubic.cpp b/meshers/cubic/voxel_mesher_cubic.cpp index 7c1af56..6de0e88 100644 --- a/meshers/cubic/voxel_mesher_cubic.cpp +++ b/meshers/cubic/voxel_mesher_cubic.cpp @@ -40,6 +40,14 @@ void VoxelMesherCubic::_add_chunk(Ref 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 p_chunk) { Ref 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); diff --git a/meshers/marching_cubes/voxel_mesher_marching_cubes.cpp b/meshers/marching_cubes/voxel_mesher_marching_cubes.cpp index 807ea5e..148578b 100644 --- a/meshers/marching_cubes/voxel_mesher_marching_cubes.cpp +++ b/meshers/marching_cubes/voxel_mesher_marching_cubes.cpp @@ -47,7 +47,7 @@ void VoxelMesherMarchingCubes::set_texture_scale(const int value) { } void VoxelMesherMarchingCubes::get_voxel_type_array(int *arr, Ref 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 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 chunk, const int x, } int VoxelMesherMarchingCubes::get_voxel_type(Ref 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 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 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); diff --git a/meshers/voxel_mesher.cpp b/meshers/voxel_mesher.cpp index 6df78aa..b8c06c4 100644 --- a/meshers/voxel_mesher.cpp +++ b/meshers/voxel_mesher.cpp @@ -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 &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"); diff --git a/meshers/voxel_mesher.h b/meshers/voxel_mesher.h index 4f24da4..964f7f6 100644 --- a/meshers/voxel_mesher.h +++ b/meshers/voxel_mesher.h @@ -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; diff --git a/world/cubic/voxel_chunk_cubic.cpp b/world/cubic/voxel_chunk_cubic.cpp index 698f737..ae24250 100644 --- a/world/cubic/voxel_chunk_cubic.cpp +++ b/world/cubic/voxel_chunk_cubic.cpp @@ -38,7 +38,12 @@ void VoxelChunkCubic::_setup_channels() { void VoxelChunkCubic::_create_meshers() { set_prop_mesher(Ref(memnew(VoxelMesherCubic))); - add_mesher(Ref(memnew(VoxelMesherCubic()))); + + Ref m = Ref(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(memnew(VoxelMesherLiquiCubic()))); for (int i = 0; i < _meshers.size(); ++i) { diff --git a/world/marching_cubes/voxel_chunk_marching_cubes.cpp b/world/marching_cubes/voxel_chunk_marching_cubes.cpp index c9fb44c..f0413b8 100644 --- a/world/marching_cubes/voxel_chunk_marching_cubes.cpp +++ b/world/marching_cubes/voxel_chunk_marching_cubes.cpp @@ -38,7 +38,12 @@ void VoxelChunkMarchingCubes::_setup_channels() { void VoxelChunkMarchingCubes::_create_meshers() { set_prop_mesher(Ref(memnew(VoxelMesherMarchingCubes))); - add_mesher(Ref(memnew(VoxelMesherMarchingCubes()))); + + Ref m = Ref(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(memnew(VoxelMesherLiquidMarchingCubes()))); for (int i = 0; i < _meshers.size(); ++i) {