From 7219d7b2d4808249c9b17fe245bdc02709eb68af Mon Sep 17 00:00:00 2001 From: Relintai Date: Fri, 12 Jun 2020 19:34:47 +0200 Subject: [PATCH] Added a Cubic chunk and World. --- SCsub | 8 +- config.py | 3 + .../voxel_cube_points.cpp | 0 .../voxel_cube_points.h | 0 .../voxel_mesher_cubic.cpp | 0 .../voxel_mesher_cubic.h | 0 register_types.cpp | 10 ++- world/cubic/voxel_chunk_cubic.cpp | 81 +++++++++++++++++++ world/cubic/voxel_chunk_cubic.h | 42 ++++++++++ world/cubic/voxel_world_cubic.cpp | 45 +++++++++++ world/cubic/voxel_world_cubic.h | 41 ++++++++++ world/default/voxel_chunk_default.h | 3 +- world/voxel_chunk.h | 7 +- 13 files changed, 230 insertions(+), 10 deletions(-) rename meshers/{cubic_mesher => cubic}/voxel_cube_points.cpp (100%) rename meshers/{cubic_mesher => cubic}/voxel_cube_points.h (100%) rename meshers/{cubic_mesher => cubic}/voxel_mesher_cubic.cpp (100%) rename meshers/{cubic_mesher => cubic}/voxel_mesher_cubic.h (100%) create mode 100644 world/cubic/voxel_chunk_cubic.cpp create mode 100644 world/cubic/voxel_chunk_cubic.h create mode 100644 world/cubic/voxel_world_cubic.cpp create mode 100644 world/cubic/voxel_world_cubic.h diff --git a/SCsub b/SCsub index 19266af..640412e 100644 --- a/SCsub +++ b/SCsub @@ -54,12 +54,16 @@ sources = [ "world/marching_cubes/voxel_chunk_marching_cubes.cpp", "world/marching_cubes/voxel_world_marching_cubes.cpp", - "meshers/cubic_mesher/voxel_mesher_cubic.cpp", - "meshers/cubic_mesher/voxel_cube_points.cpp", + "meshers/cubic/voxel_mesher_cubic.cpp", + "meshers/cubic/voxel_cube_points.cpp", "level_generator/voxelman_level_generator.cpp", "level_generator/voxelman_level_generator_flat.cpp", + "world/cubic/voxel_chunk_cubic.cpp", + "world/cubic/voxel_world_cubic.cpp", + + "areas/world_area.cpp", "world/voxel_world_editor.cpp", diff --git a/config.py b/config.py index 174afca..d0b4545 100644 --- a/config.py +++ b/config.py @@ -49,6 +49,9 @@ def get_doc_classes(): "VoxelWorldMarchingCubes", "VoxelChunkMarchingCubes", + "VoxelMesherCubic", + "VoxelWorldCubic", + "VoxelMesherDefault", "VoxelWorldDefault", "VoxelChunkBlocky", diff --git a/meshers/cubic_mesher/voxel_cube_points.cpp b/meshers/cubic/voxel_cube_points.cpp similarity index 100% rename from meshers/cubic_mesher/voxel_cube_points.cpp rename to meshers/cubic/voxel_cube_points.cpp diff --git a/meshers/cubic_mesher/voxel_cube_points.h b/meshers/cubic/voxel_cube_points.h similarity index 100% rename from meshers/cubic_mesher/voxel_cube_points.h rename to meshers/cubic/voxel_cube_points.h diff --git a/meshers/cubic_mesher/voxel_mesher_cubic.cpp b/meshers/cubic/voxel_mesher_cubic.cpp similarity index 100% rename from meshers/cubic_mesher/voxel_mesher_cubic.cpp rename to meshers/cubic/voxel_mesher_cubic.cpp diff --git a/meshers/cubic_mesher/voxel_mesher_cubic.h b/meshers/cubic/voxel_mesher_cubic.h similarity index 100% rename from meshers/cubic_mesher/voxel_mesher_cubic.h rename to meshers/cubic/voxel_mesher_cubic.h diff --git a/register_types.cpp b/register_types.cpp index 3ee80c3..9aa0b4e 100644 --- a/register_types.cpp +++ b/register_types.cpp @@ -49,8 +49,8 @@ SOFTWARE. #include "world/default/voxel_chunk_default.h" #include "world/default/voxel_world_default.h" -#include "meshers/cubic_mesher/voxel_cube_points.h" -#include "meshers/cubic_mesher/voxel_mesher_cubic.h" +#include "meshers/cubic/voxel_cube_points.h" +#include "meshers/cubic/voxel_mesher_cubic.h" #include "level_generator/voxelman_level_generator.h" #include "level_generator/voxelman_level_generator_flat.h" @@ -65,6 +65,9 @@ SOFTWARE. #include "world/blocky/voxel_chunk_blocky.h" #include "world/blocky/voxel_world_blocky.h" +#include "world/cubic/voxel_chunk_cubic.h" +#include "world/cubic/voxel_world_cubic.h" + #include "world/marching_cubes/voxel_chunk_marching_cubes.h" #include "world/marching_cubes/voxel_world_marching_cubes.h" @@ -109,6 +112,9 @@ void register_voxelman_types() { ClassDB::register_class(); ClassDB::register_class(); + ClassDB::register_class(); + ClassDB::register_class(); + ClassDB::register_class(); ClassDB::register_class(); diff --git a/world/cubic/voxel_chunk_cubic.cpp b/world/cubic/voxel_chunk_cubic.cpp new file mode 100644 index 0000000..d5953b5 --- /dev/null +++ b/world/cubic/voxel_chunk_cubic.cpp @@ -0,0 +1,81 @@ +/* +Copyright (c) 2019-2020 Péter Magyar + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +*/ + +#include "voxel_chunk_cubic.h" + +#include "../../meshers/cubic/voxel_mesher_cubic.h" + +#include "../../defines.h" + +VoxelChunkCubic::VoxelChunkCubic() { +} + +VoxelChunkCubic::~VoxelChunkCubic() { +} + +void VoxelChunkCubic::_setup_channels() { + set_channel_count(MAX_DEFAULT_CHANNELS); +} + +void VoxelChunkCubic::_create_meshers() { + add_mesher(Ref(memnew(VoxelMesherCubic()))); + //add_liquid_mesher(Ref(memnew(VoxelMesherLiquiCubic()))); + + for (int i = 0; i < _meshers.size(); ++i) { + Ref mesher = _meshers.get(i); + + ERR_CONTINUE(!mesher.is_valid()); + + mesher->set_lod_size(get_lod_size()); + mesher->set_voxel_scale(get_voxel_scale()); + + Ref md = mesher; + + if (md.is_valid()) { + md->set_build_flags(get_build_flags()); + } + } + + /* + for (int i = 0; i < _liquid_meshers.size(); ++i) { + Ref mesher = _liquid_meshers.get(i); + + ERR_CONTINUE(!mesher.is_valid()); + + mesher->set_lod_size(get_lod_size()); + mesher->set_voxel_scale(get_voxel_scale()); + + Ref md = mesher; + + if (md.is_valid()) { + md->set_build_flags(get_build_flags()); + } + }*/ +} + +void VoxelChunkCubic::_bind_methods() { + ADD_PROPERTYI(PropertyInfo(Variant::POOL_BYTE_ARRAY, "data_channel"), "set_channel_compressed", "get_channel_compressed", 0); + ADD_PROPERTYI(PropertyInfo(Variant::POOL_BYTE_ARRAY, "isolevel_channel"), "set_channel_compressed", "get_channel_compressed", 1); + + //ClassDB::bind_method(D_METHOD("get_channel_compressed", "channel_index"), &VoxelChunk::get_channel_compressed); + //ClassDB::bind_method(D_METHOD("set_channel_compressed", "channel_index", "array"), &VoxelChunk::set_channel_compressed); +} diff --git a/world/cubic/voxel_chunk_cubic.h b/world/cubic/voxel_chunk_cubic.h new file mode 100644 index 0000000..d191496 --- /dev/null +++ b/world/cubic/voxel_chunk_cubic.h @@ -0,0 +1,42 @@ +/* +Copyright (c) 2019-2020 Péter Magyar + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +*/ + +#ifndef VOXEL_CHUNK_CUBIC_H +#define VOXEL_CHUNK_CUBIC_H + +#include "../default/voxel_chunk_default.h" + +class VoxelChunkCubic : public VoxelChunkDefault { + GDCLASS(VoxelChunkCubic, VoxelChunkDefault); + +public: + VoxelChunkCubic(); + ~VoxelChunkCubic(); + +protected: + virtual void _setup_channels(); + virtual void _create_meshers(); + + static void _bind_methods(); +}; + +#endif diff --git a/world/cubic/voxel_world_cubic.cpp b/world/cubic/voxel_world_cubic.cpp new file mode 100644 index 0000000..9f34271 --- /dev/null +++ b/world/cubic/voxel_world_cubic.cpp @@ -0,0 +1,45 @@ +/* +Copyright (c) 2019-2020 Péter Magyar + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +*/ + +#include "voxel_world_cubic.h" + +#include "voxel_chunk_cubic.h" + +Ref VoxelWorldCubic::_create_chunk(int x, int y, int z, Ref chunk) { + + if (!chunk.is_valid()) { + chunk = Ref(memnew(VoxelChunkCubic)); + } + + return VoxelWorld::_create_chunk(x, y, z, chunk); +} + +VoxelWorldCubic::VoxelWorldCubic() { + set_data_margin_start(1); + set_data_margin_end(1); +} + +VoxelWorldCubic ::~VoxelWorldCubic() { +} + +void VoxelWorldCubic::_bind_methods() { +} \ No newline at end of file diff --git a/world/cubic/voxel_world_cubic.h b/world/cubic/voxel_world_cubic.h new file mode 100644 index 0000000..be5b09a --- /dev/null +++ b/world/cubic/voxel_world_cubic.h @@ -0,0 +1,41 @@ +/* +Copyright (c) 2019-2020 Péter Magyar + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +*/ + +#ifndef VOXEL_WORLD_CUBIC_H +#define VOXEL_WORLD_CUBIC_H + +#include "../default/voxel_world_default.h" + +class VoxelWorldCubic : public VoxelWorldDefault { + GDCLASS(VoxelWorldCubic, VoxelWorldDefault); + +public: + VoxelWorldCubic(); + ~VoxelWorldCubic(); + +protected: + Ref _create_chunk(int x, int y, int z, Ref p_chunk); + + static void _bind_methods(); +}; + +#endif diff --git a/world/default/voxel_chunk_default.h b/world/default/voxel_chunk_default.h index e35228f..058dba3 100644 --- a/world/default/voxel_chunk_default.h +++ b/world/default/voxel_chunk_default.h @@ -43,7 +43,6 @@ SOFTWARE. #include "../../data/voxel_light.h" -#include "../../meshers/cubic_mesher/voxel_mesher_cubic.h" #include "../../meshers/voxel_mesher.h" #include "../../library/voxel_surface.h" @@ -288,7 +287,7 @@ protected: ActiveBuildPhaseType _active_build_phase_type; - Vector> _lights; + Vector > _lights; }; VARIANT_ENUM_CAST(VoxelChunkDefault::DefaultChannels); diff --git a/world/voxel_chunk.h b/world/voxel_chunk.h index 7fb4e05..0347cb6 100644 --- a/world/voxel_chunk.h +++ b/world/voxel_chunk.h @@ -44,7 +44,6 @@ include_pool_vector #include "../data/voxel_light.h" -#include "../meshers/cubic_mesher/voxel_mesher_cubic.h" #include "../meshers/voxel_mesher.h" #include "../library/voxel_surface.h" @@ -257,11 +256,11 @@ protected: float _voxel_scale; Ref _library; - Vector> _meshers; - Vector> _liquid_meshers; + Vector > _meshers; + Vector > _liquid_meshers; //mergeable props - Vector> _props; + Vector > _props; Transform _transform; };