Reorganize all files and rename a few things

This commit is contained in:
Marc Gilleron 2019-04-28 17:58:29 +01:00
parent c8fbf19814
commit 12a97cca5a
44 changed files with 116 additions and 101 deletions

11
SCsub
View File

@ -1,6 +1,11 @@
Import('env')
env.add_source_files(env.modules_sources,"*.cpp")
env.add_source_files(env.modules_sources,"transvoxel/*.cpp")
env.add_source_files(env.modules_sources,"dmc/*.cpp")
env.add_source_files(env.modules_sources, "*.cpp")
env.add_source_files(env.modules_sources, "meshers/blocky/*.cpp")
env.add_source_files(env.modules_sources, "meshers/transvoxel/*.cpp")
env.add_source_files(env.modules_sources, "meshers/dmc/*.cpp")
env.add_source_files(env.modules_sources, "providers/*.cpp")
env.add_source_files(env.modules_sources, "util/*.cpp")
env.add_source_files(env.modules_sources, "terrain/*.cpp")
env.add_source_files(env.modules_sources, "math/*.cpp")

View File

@ -1,8 +1,8 @@
#ifndef CUBE_TABLES_H
#define CUBE_TABLES_H
#include "math/vector3i.h"
#include <core/math/vector3.h>
#include "vector3i.h"
namespace Cube {
@ -71,7 +71,6 @@ extern const unsigned int g_edge_corners[EDGE_COUNT][2];
const unsigned int MOORE_NEIGHBORING_3D_COUNT = 26;
extern const Vector3i g_moore_neighboring_3d[MOORE_NEIGHBORING_3D_COUNT];
} // namespace CubeTables
} // namespace Cube
#endif // CUBE_TABLES_H

View File

@ -1,7 +1,7 @@
#include "voxel_mesher.h"
#include "cube_tables.h"
#include "utility.h"
#include "voxel_library.h"
#include "voxel_mesher_blocky.h"
#include "../../cube_tables.h"
#include "../../util/utility.h"
#include "../../voxel_library.h"
#include <core/os/os.h>
template <typename T>
@ -11,15 +11,15 @@ void raw_copy_to(PoolVector<T> &to, const Vector<T> &from) {
memcpy(w.ptr(), from.ptr(), from.size() * sizeof(T));
}
VoxelMesher::VoxelMesher() :
VoxelMesherBlocky::VoxelMesherBlocky() :
_baked_occlusion_darkness(0.8),
_bake_occlusion(true) {}
void VoxelMesher::set_library(Ref<VoxelLibrary> library) {
void VoxelMesherBlocky::set_library(Ref<VoxelLibrary> library) {
_library = library;
}
void VoxelMesher::set_occlusion_darkness(float darkness) {
void VoxelMesherBlocky::set_occlusion_darkness(float darkness) {
_baked_occlusion_darkness = darkness;
if (_baked_occlusion_darkness < 0.0)
_baked_occlusion_darkness = 0.0;
@ -27,7 +27,7 @@ void VoxelMesher::set_occlusion_darkness(float darkness) {
_baked_occlusion_darkness = 1.0;
}
void VoxelMesher::set_occlusion_enabled(bool enable) {
void VoxelMesherBlocky::set_occlusion_enabled(bool enable) {
_bake_occlusion = enable;
}
@ -51,7 +51,7 @@ inline bool is_transparent(const VoxelLibrary &lib, int voxel_id) {
return true;
}
Ref<ArrayMesh> VoxelMesher::build_mesh(Ref<VoxelBuffer> buffer_ref, unsigned int channel, Array materials, Ref<ArrayMesh> mesh) {
Ref<ArrayMesh> VoxelMesherBlocky::build_mesh(Ref<VoxelBuffer> buffer_ref, unsigned int channel, Array materials, Ref<ArrayMesh> mesh) {
ERR_FAIL_COND_V(buffer_ref.is_null(), Ref<ArrayMesh>());
VoxelBuffer &buffer = **buffer_ref;
@ -75,7 +75,7 @@ Ref<ArrayMesh> VoxelMesher::build_mesh(Ref<VoxelBuffer> buffer_ref, unsigned int
return mesh;
}
Array VoxelMesher::build(const VoxelBuffer &buffer, unsigned int channel, int padding) {
Array VoxelMesherBlocky::build(const VoxelBuffer &buffer, unsigned int channel, int padding) {
//uint64_t time_before = OS::get_singleton()->get_ticks_usec();
ERR_FAIL_COND_V(_library.is_null(), Array());
@ -418,20 +418,20 @@ Array VoxelMesher::build(const VoxelBuffer &buffer, unsigned int channel, int pa
return surfaces;
}
void VoxelMesher::_bind_methods() {
void VoxelMesherBlocky::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_library", "voxel_library"), &VoxelMesher::set_library);
ClassDB::bind_method(D_METHOD("get_library"), &VoxelMesher::get_library);
ClassDB::bind_method(D_METHOD("set_library", "voxel_library"), &VoxelMesherBlocky::set_library);
ClassDB::bind_method(D_METHOD("get_library"), &VoxelMesherBlocky::get_library);
ClassDB::bind_method(D_METHOD("set_occlusion_enabled", "enable"), &VoxelMesher::set_occlusion_enabled);
ClassDB::bind_method(D_METHOD("get_occlusion_enabled"), &VoxelMesher::get_occlusion_enabled);
ClassDB::bind_method(D_METHOD("set_occlusion_enabled", "enable"), &VoxelMesherBlocky::set_occlusion_enabled);
ClassDB::bind_method(D_METHOD("get_occlusion_enabled"), &VoxelMesherBlocky::get_occlusion_enabled);
ClassDB::bind_method(D_METHOD("set_occlusion_darkness", "value"), &VoxelMesher::set_occlusion_darkness);
ClassDB::bind_method(D_METHOD("get_occlusion_darkness"), &VoxelMesher::get_occlusion_darkness);
ClassDB::bind_method(D_METHOD("set_occlusion_darkness", "value"), &VoxelMesherBlocky::set_occlusion_darkness);
ClassDB::bind_method(D_METHOD("get_occlusion_darkness"), &VoxelMesherBlocky::get_occlusion_darkness);
ClassDB::bind_method(D_METHOD("build_mesh", "voxel_buffer", "channel", "materials", "existing_mesh"), &VoxelMesher::build_mesh);
ClassDB::bind_method(D_METHOD("build_mesh", "voxel_buffer", "channel", "materials", "existing_mesh"), &VoxelMesherBlocky::build_mesh);
#ifdef VOXEL_PROFILING
ClassDB::bind_method(D_METHOD("get_profiling_info"), &VoxelMesher::get_profiling_info);
ClassDB::bind_method(D_METHOD("get_profiling_info"), &VoxelMesherBlocky::get_profiling_info);
#endif
}

View File

@ -1,22 +1,22 @@
#ifndef VOXEL_MESHER
#define VOXEL_MESHER
#ifndef VOXEL_MESHER_BLOCKY_H
#define VOXEL_MESHER_BLOCKY_H
#include "voxel.h"
#include "voxel_buffer.h"
#include "voxel_library.h"
#include "zprofiling.h"
#include "../../util/zprofiling.h"
#include "../../voxel.h"
#include "../../voxel_buffer.h"
#include "../../voxel_library.h"
#include <core/reference.h>
#include <scene/resources/mesh.h>
// TODO Should be renamed VoxelMesherBlocky or something like that
class VoxelMesher : public Reference {
GDCLASS(VoxelMesher, Reference)
class VoxelMesherBlocky : public Reference {
GDCLASS(VoxelMesherBlocky, Reference)
public:
static const unsigned int MAX_MATERIALS = 8; // Arbitrary. Tweak if needed.
static const int MINIMUM_PADDING = 1;
VoxelMesher();
VoxelMesherBlocky();
void set_library(Ref<VoxelLibrary> library);
Ref<VoxelLibrary> get_library() const { return _library; }
@ -53,4 +53,4 @@ private:
#endif
};
#endif // VOXEL_MESHER
#endif // VOXEL_MESHER_BLOCKY_H

View File

@ -1,8 +1,8 @@
#ifndef HERMITE_VALUE_H
#define HERMITE_VALUE_H
#include "../utility.h"
#include "../voxel_buffer.h"
#include "../../util/utility.h"
#include "../../voxel_buffer.h"
#include <core/math/vector3.h>
namespace dmc {

View File

@ -1,7 +1,7 @@
#ifndef MESH_BUILDER_H
#define MESH_BUILDER_H
#include "../utility.h"
#include "../../util/utility.h"
#include <core/map.h>
#include <scene/resources/mesh.h>
#include <vector>

View File

@ -1,7 +1,7 @@
#ifndef OCTREE_UTILITY_H
#define OCTREE_UTILITY_H
#ifndef OCTREE_TABLES_H
#define OCTREE_TABLES_H
namespace OctreeUtility {
namespace OctreeTables {
// Corners: Octants:
//
@ -40,6 +40,6 @@ const int g_octant_position[8][3]{
{ 0, 1, 1 }
};
} // namespace OctreeUtility
} // namespace OctreeTables
#endif // OCTREE_UTILITY_H
#endif // OCTREE_TABLES_H

View File

@ -1,8 +1,8 @@
#include "voxel_mesher_dmc.h"
#include "../cube_tables.h"
#include "../../cube_tables.h"
#include "marching_cubes_tables.h"
#include "mesh_builder.h"
#include "octree_utility.h"
#include "octree_tables.h"
#include <core/os/os.h>
// Dual marching cubes
@ -184,7 +184,7 @@ private:
for (int i = 0; i < 8; ++i) {
OctreeNode *child = _pool.create();
const int *v = OctreeUtility::g_octant_position[i];
const int *v = OctreeTables::g_octant_position[i];
child->size = node->size / 2;
child->origin = node->origin + Vector3i(v[0], v[1], v[2]) * child->size;
@ -215,7 +215,7 @@ public:
// Go all the way down, except leaves because we can't reason bottom-up on them
if (node_size > 2) {
for (int i = 0; i < 8; ++i) {
const int *dir = OctreeUtility::g_octant_position[i];
const int *dir = OctreeTables::g_octant_position[i];
int child_size = node_size / 2;
children[i] = build(node_origin + child_size * Vector3i(dir[0], dir[1], dir[2]), child_size);
any_node |= children[i] != nullptr;
@ -263,7 +263,7 @@ public:
private:
inline OctreeNode *create_child(Vector3i parent_origin, int parent_size, int i) const {
const int *dir = OctreeUtility::g_octant_position[i];
const int *dir = OctreeTables::g_octant_position[i];
OctreeNode *child = _pool.create();
child->size = parent_size / 2;
child->origin = parent_origin + child->size * Vector3i(dir[0], dir[1], dir[2]);

View File

@ -1,11 +1,11 @@
#ifndef VOXEL_MESHER_DMC_H
#define VOXEL_MESHER_DMC_H
#include "../voxel_buffer.h"
#include "../../voxel_buffer.h"
#include "hermite_value.h"
#include "mesh_builder.h"
#include "object_pool.h"
#include "scene/resources/mesh.h"
#include <scene/resources/mesh.h>
namespace dmc {

View File

@ -1,7 +1,7 @@
#ifndef VOXEL_MESHER_SMOOTH_H
#define VOXEL_MESHER_SMOOTH_H
#include "../voxel_buffer.h"
#include "../../voxel_buffer.h"
#include <scene/resources/mesh.h>
class VoxelMesherTransvoxel : public Reference {

View File

@ -1,5 +1,5 @@
#include "voxel_provider.h"
#include "voxel_map.h"
#include <core/script_language.h>
void VoxelProvider::emerge_block(Ref<VoxelBuffer> out_buffer, Vector3i origin_in_voxels) {
ERR_FAIL_COND(out_buffer.is_null());

View File

@ -1,7 +1,7 @@
#ifndef VOXEL_PROVIDER_H
#define VOXEL_PROVIDER_H
#include "voxel_buffer.h"
#include "../voxel_buffer.h"
#include <core/resource.h>
class VoxelProvider : public Resource {

View File

@ -1,5 +1,4 @@
#include "voxel_provider_test.h"
#include "voxel_map.h"
VARIANT_ENUM_CAST(VoxelProviderTest::Mode)

View File

@ -1,31 +1,42 @@
#include "register_types.h"
#include "dmc/voxel_mesher_dmc.h"
#include "transvoxel/voxel_mesher_transvoxel.h"
#include "voxel_box_mover.h"
#include "meshers/blocky/voxel_mesher_blocky.h"
#include "meshers/dmc/voxel_mesher_dmc.h"
#include "meshers/transvoxel/voxel_mesher_transvoxel.h"
#include "providers/voxel_provider_image.h"
#include "providers/voxel_provider_test.h"
#include "terrain/voxel_box_mover.h"
#include "terrain/voxel_map.h"
#include "terrain/voxel_terrain.h"
#include "voxel_buffer.h"
#include "voxel_isosurface_tool.h"
#include "voxel_library.h"
#include "voxel_map.h"
#include "voxel_mesher.h"
#include "voxel_provider_image.h"
#include "voxel_provider_test.h"
#include "voxel_terrain.h"
void register_voxel_types() {
ClassDB::register_class<Voxel>();
// Storage
ClassDB::register_class<VoxelBuffer>();
ClassDB::register_class<VoxelMesher>();
ClassDB::register_class<VoxelLibrary>();
ClassDB::register_class<VoxelMap>();
// Voxel types
ClassDB::register_class<Voxel>();
ClassDB::register_class<VoxelLibrary>();
// Nodes
ClassDB::register_class<VoxelTerrain>();
// Providers
ClassDB::register_class<VoxelProvider>();
ClassDB::register_class<VoxelProviderTest>();
ClassDB::register_class<VoxelProviderImage>();
ClassDB::register_class<VoxelMesherTransvoxel>();
// Helpers
ClassDB::register_class<VoxelBoxMover>();
ClassDB::register_class<VoxelMesherDMC>();
ClassDB::register_class<VoxelIsoSurfaceTool>();
// Meshers
ClassDB::register_class<VoxelMesherBlocky>();
ClassDB::register_class<VoxelMesherTransvoxel>();
ClassDB::register_class<VoxelMesherDMC>();
}
void unregister_voxel_types() {

View File

@ -1,7 +1,7 @@
#ifndef VOXEL_BLOCK_H
#define VOXEL_BLOCK_H
#include "voxel_buffer.h"
#include "../voxel_buffer.h"
#include <scene/3d/mesh_instance.h>
#include <scene/3d/physics_body.h>

View File

@ -1,5 +1,5 @@
#include "voxel_map.h"
#include "cube_tables.h"
#include "../cube_tables.h"
#include "voxel_block.h"
#include "core/os/os.h"

View File

@ -1,5 +1,5 @@
#include "voxel_mesh_updater.h"
#include "utility.h"
#include "../util/utility.h"
#include <core/os/os.h>
VoxelMeshUpdater::VoxelMeshUpdater(Ref<VoxelLibrary> library, MeshingParams params) {

View File

@ -5,9 +5,9 @@
#include <core/os/thread.h>
#include <core/vector.h>
#include "dmc/voxel_mesher_dmc.h"
#include "voxel_buffer.h"
#include "voxel_mesher.h"
#include "../meshers/blocky/voxel_mesher_blocky.h"
#include "../meshers/dmc/voxel_mesher_dmc.h"
#include "../voxel_buffer.h"
class VoxelMeshUpdater {
public:
@ -83,7 +83,7 @@ private:
Output _shared_output;
Mutex *_output_mutex;
Ref<VoxelMesher> _blocky_mesher;
Ref<VoxelMesherBlocky> _blocky_mesher;
Ref<VoxelMesherDMC> _dmc_mesher;
Input _input;

View File

@ -1,10 +1,11 @@
#include "voxel_provider_thread.h"
#include "core/os/os.h"
#include "core/os/semaphore.h"
#include "core/os/thread.h"
#include "utility.h"
#include "../providers/voxel_provider.h"
#include "../util/utility.h"
#include "voxel_map.h"
#include "voxel_provider.h"
#include <core/os/os.h>
#include <core/os/semaphore.h>
#include <core/os/thread.h>
VoxelProviderThread::VoxelProviderThread(Ref<VoxelProvider> provider, int block_size_pow2) {

View File

@ -1,8 +1,8 @@
#ifndef VOXEL_PROVIDER_THREAD_H
#define VOXEL_PROVIDER_THREAD_H
#include "core/resource.h"
#include "vector3i.h"
#include "../math/vector3i.h"
#include <core/resource.h>
class VoxelProvider;
class VoxelBuffer;

View File

@ -1,10 +1,10 @@
#include "voxel_terrain.h"
#include "utility.h"
#include "../providers/voxel_provider_test.h"
#include "../util/utility.h"
#include "../util/voxel_raycast.h"
#include "voxel_block.h"
#include "voxel_map.h"
#include "voxel_provider_test.h"
#include "voxel_provider_thread.h"
#include "voxel_raycast.h"
#include <core/engine.h>
#include <core/os/os.h>
@ -41,7 +41,7 @@ bool VoxelTerrain::_set(const StringName &p_name, const Variant &p_value) {
if (p_name.operator String().begins_with("material/")) {
int idx = p_name.operator String().get_slicec('/', 1).to_int();
ERR_FAIL_COND_V(idx >= VoxelMesher::MAX_MATERIALS || idx < 0, false);
ERR_FAIL_COND_V(idx >= VoxelMesherBlocky::MAX_MATERIALS || idx < 0, false);
set_material(idx, p_value);
return true;
}
@ -53,7 +53,7 @@ bool VoxelTerrain::_get(const StringName &p_name, Variant &r_ret) const {
if (p_name.operator String().begins_with("material/")) {
int idx = p_name.operator String().get_slicec('/', 1).to_int();
ERR_FAIL_COND_V(idx >= VoxelMesher::MAX_MATERIALS || idx < 0, false);
ERR_FAIL_COND_V(idx >= VoxelMesherBlocky::MAX_MATERIALS || idx < 0, false);
r_ret = get_material(idx);
return true;
}
@ -63,7 +63,7 @@ bool VoxelTerrain::_get(const StringName &p_name, Variant &r_ret) const {
void VoxelTerrain::_get_property_list(List<PropertyInfo> *p_list) const {
for (int i = 0; i < VoxelMesher::MAX_MATERIALS; ++i) {
for (int i = 0; i < VoxelMesherBlocky::MAX_MATERIALS; ++i) {
p_list->push_back(PropertyInfo(Variant::OBJECT, "material/" + itos(i), PROPERTY_HINT_RESOURCE_TYPE, "ShaderMaterial,SpatialMaterial"));
}
}
@ -151,12 +151,12 @@ Spatial *VoxelTerrain::get_viewer(NodePath path) const {
void VoxelTerrain::set_material(int id, Ref<Material> material) {
// TODO Update existing block surfaces
ERR_FAIL_COND(id < 0 || id >= VoxelMesher::MAX_MATERIALS);
ERR_FAIL_COND(id < 0 || id >= VoxelMesherBlocky::MAX_MATERIALS);
_materials[id] = material;
}
Ref<Material> VoxelTerrain::get_material(int id) const {
ERR_FAIL_COND_V(id < 0 || id >= VoxelMesher::MAX_MATERIALS, Ref<Material>());
ERR_FAIL_COND_V(id < 0 || id >= VoxelMesherBlocky::MAX_MATERIALS, Ref<Material>());
return _materials[id];
}

View File

@ -1,12 +1,12 @@
#ifndef VOXEL_TERRAIN_H
#define VOXEL_TERRAIN_H
#include "rect3i.h"
#include "vector3i.h"
#include "../math/rect3i.h"
#include "../math/vector3i.h"
#include "../providers/voxel_provider.h"
#include "../util/zprofiling.h"
#include "voxel_mesh_updater.h"
#include "voxel_provider.h"
#include "voxel_provider_thread.h"
#include "zprofiling.h"
#include <scene/3d/spatial.h>
@ -150,7 +150,7 @@ private:
bool _run_in_editor;
bool _smooth_meshing_enabled;
Ref<Material> _materials[VoxelMesher::MAX_MATERIALS];
Ref<Material> _materials[VoxelMesherBlocky::MAX_MATERIALS];
Stats _stats;
};

View File

@ -1,7 +1,7 @@
#ifndef HEADER_VOXEL_UTILITY_H
#define HEADER_VOXEL_UTILITY_H
#include "vector3i.h"
#include "../math/vector3i.h"
#include <core/pool_vector.h>
#include <core/ustring.h>
#include <core/vector.h>
@ -54,7 +54,7 @@ void raw_copy_to(PoolVector<T> &to, const std::vector<T> &from) {
}
// Trilinear interpolation between corner values of a cube.
// Cube points respect the same position as in octree_utility.h
// Cube points respect the same position as in octree_tables.h
template <typename T>
inline T interpolate(const T v0, const T v1, const T v2, const T v3, const T v4, const T v5, const T v6, const T v7, Vector3 position) {

View File

@ -1,4 +1,4 @@
#include "vector3i.h"
#include "../math/vector3i.h"
#include <core/math/vector3.h>
// TODO that could be a template function

View File

@ -1,6 +1,6 @@
#include "voxel.h"
#include "meshers/blocky/voxel_mesher_blocky.h" // TODO Only required because of MAX_MATERIALS... could be enough inverting that dependency
#include "voxel_library.h"
#include "voxel_mesher.h"
#define STRLEN(x) (sizeof(x) / sizeof(x[0]))
@ -110,7 +110,7 @@ Ref<Voxel> Voxel::set_color(Color color) {
}
Ref<Voxel> Voxel::set_material_id(unsigned int id) {
ERR_FAIL_COND_V(id >= VoxelMesher::MAX_MATERIALS, Ref<Voxel>(this));
ERR_FAIL_COND_V(id >= VoxelMesherBlocky::MAX_MATERIALS, Ref<Voxel>(this));
_material_id = id;
return Ref<Voxel>(this);
}

View File

@ -1,7 +1,7 @@
#ifndef VOXEL_BUFFER_H
#define VOXEL_BUFFER_H
#include "vector3i.h"
#include "math/vector3i.h"
#include <core/reference.h>
#include <core/vector.h>

View File

@ -1,5 +1,5 @@
#include "voxel_isosurface_tool.h"
#include "utility.h"
#include "util/utility.h"
VoxelIsoSurfaceTool::VoxelIsoSurfaceTool() {
_iso_scale = 1.0;