mirror of
https://github.com/Relintai/godot_voxel.git
synced 2024-12-25 16:27:16 +01:00
Dual marching cubes WIP (only octree and dual grid extraction, untested)
This commit is contained in:
parent
6fc70a66c1
commit
1181cfa59f
1
SCsub
1
SCsub
@ -2,4 +2,5 @@ Import('env')
|
|||||||
|
|
||||||
env.add_source_files(env.modules_sources,"*.cpp")
|
env.add_source_files(env.modules_sources,"*.cpp")
|
||||||
env.add_source_files(env.modules_sources,"transvoxel/*.cpp")
|
env.add_source_files(env.modules_sources,"transvoxel/*.cpp")
|
||||||
|
env.add_source_files(env.modules_sources,"dmc/*.cpp")
|
||||||
|
|
||||||
|
1078
dmc/voxel_mesher_dmc.cpp
Normal file
1078
dmc/voxel_mesher_dmc.cpp
Normal file
File diff suppressed because it is too large
Load Diff
21
dmc/voxel_mesher_dmc.h
Normal file
21
dmc/voxel_mesher_dmc.h
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
#ifndef VOXEL_MESHER_DMC_H
|
||||||
|
#define VOXEL_MESHER_DMC_H
|
||||||
|
|
||||||
|
#include "../voxel_buffer.h"
|
||||||
|
#include "scene/resources/mesh.h"
|
||||||
|
|
||||||
|
namespace dmc {
|
||||||
|
|
||||||
|
Ref<ArrayMesh> polygonize(const VoxelBuffer &voxels, float geometric_error);
|
||||||
|
}
|
||||||
|
|
||||||
|
class VoxelMesherDMC : public Reference {
|
||||||
|
GDCLASS(VoxelMesherDMC, Reference)
|
||||||
|
public:
|
||||||
|
Ref<ArrayMesh> build_mesh(Ref<VoxelBuffer> voxels, real_t geometric_error);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
static void _bind_methods();
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // VOXEL_MESHER_DMC_H
|
@ -1,13 +1,14 @@
|
|||||||
#include "register_types.h"
|
#include "register_types.h"
|
||||||
|
#include "dmc/voxel_mesher_dmc.h"
|
||||||
|
#include "transvoxel/voxel_mesher_smooth.h"
|
||||||
|
#include "voxel_box_mover.h"
|
||||||
#include "voxel_buffer.h"
|
#include "voxel_buffer.h"
|
||||||
#include "voxel_mesher.h"
|
|
||||||
#include "voxel_library.h"
|
#include "voxel_library.h"
|
||||||
#include "voxel_map.h"
|
#include "voxel_map.h"
|
||||||
#include "voxel_terrain.h"
|
#include "voxel_mesher.h"
|
||||||
#include "voxel_provider_test.h"
|
|
||||||
#include "voxel_provider_image.h"
|
#include "voxel_provider_image.h"
|
||||||
#include "voxel_box_mover.h"
|
#include "voxel_provider_test.h"
|
||||||
#include "transvoxel/voxel_mesher_smooth.h"
|
#include "voxel_terrain.h"
|
||||||
|
|
||||||
void register_voxel_types() {
|
void register_voxel_types() {
|
||||||
|
|
||||||
@ -23,9 +24,8 @@ void register_voxel_types() {
|
|||||||
ClassDB::register_class<VoxelMesherSmooth>();
|
ClassDB::register_class<VoxelMesherSmooth>();
|
||||||
ClassDB::register_class<VoxelBoxMover>();
|
ClassDB::register_class<VoxelBoxMover>();
|
||||||
|
|
||||||
|
ClassDB::register_class<VoxelMesherDMC>();
|
||||||
}
|
}
|
||||||
|
|
||||||
void unregister_voxel_types() {
|
void unregister_voxel_types() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -81,7 +81,7 @@ void VoxelBuffer::set_voxel(int value, int x, int y, int z, unsigned int channel
|
|||||||
// This version does not cause errors if out of bounds. Use only if it's okay to be outside.
|
// This version does not cause errors if out of bounds. Use only if it's okay to be outside.
|
||||||
void VoxelBuffer::try_set_voxel(int x, int y, int z, int value, unsigned int channel_index) {
|
void VoxelBuffer::try_set_voxel(int x, int y, int z, int value, unsigned int channel_index) {
|
||||||
ERR_FAIL_INDEX(channel_index, MAX_CHANNELS);
|
ERR_FAIL_INDEX(channel_index, MAX_CHANNELS);
|
||||||
if(!validate_pos(x, y, z))
|
if (!validate_pos(x, y, z))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
Channel &channel = _channels[channel_index];
|
Channel &channel = _channels[channel_index];
|
||||||
@ -106,7 +106,7 @@ void VoxelBuffer::fill(int defval, unsigned int channel_index) {
|
|||||||
Channel &channel = _channels[channel_index];
|
Channel &channel = _channels[channel_index];
|
||||||
if (channel.data == NULL) {
|
if (channel.data == NULL) {
|
||||||
// Channel is already optimized and uniform
|
// Channel is already optimized and uniform
|
||||||
if(channel.defval == defval) {
|
if (channel.defval == defval) {
|
||||||
// No change
|
// No change
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
@ -114,8 +114,7 @@ void VoxelBuffer::fill(int defval, unsigned int channel_index) {
|
|||||||
channel.defval = defval;
|
channel.defval = defval;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
} else
|
||||||
else
|
|
||||||
create_channel_noinit(channel_index, _size);
|
create_channel_noinit(channel_index, _size);
|
||||||
|
|
||||||
unsigned int volume = get_volume();
|
unsigned int volume = get_volume();
|
||||||
@ -131,7 +130,7 @@ void VoxelBuffer::fill_area(int defval, Vector3i min, Vector3i max, unsigned int
|
|||||||
max.clamp_to(Vector3i(0, 0, 0), _size + Vector3i(1, 1, 1));
|
max.clamp_to(Vector3i(0, 0, 0), _size + Vector3i(1, 1, 1));
|
||||||
Vector3i area_size = max - min;
|
Vector3i area_size = max - min;
|
||||||
|
|
||||||
if(area_size.x == 0 || area_size.y == 0 || area_size.z == 0)
|
if (area_size.x == 0 || area_size.y == 0 || area_size.z == 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
Channel &channel = _channels[channel_index];
|
Channel &channel = _channels[channel_index];
|
||||||
|
@ -110,8 +110,9 @@ private:
|
|||||||
// Default value when data is null
|
// Default value when data is null
|
||||||
uint8_t defval;
|
uint8_t defval;
|
||||||
|
|
||||||
Channel()
|
Channel() :
|
||||||
: data(NULL), defval(0) {}
|
data(NULL),
|
||||||
|
defval(0) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Each channel can store arbitary data.
|
// Each channel can store arbitary data.
|
||||||
|
Loading…
Reference in New Issue
Block a user