Rename VoxelMesherSmooth => VoxelMesherTransvoxel

This commit is contained in:
Marc Gilleron 2019-04-21 14:47:50 +01:00
parent d53e43f115
commit 35ff5fd546
7 changed files with 26 additions and 24 deletions

View File

@ -8,13 +8,14 @@
namespace dmc {
// Faster than SurfaceTool, only does what is needed
// Faster than SurfaceTool, only does what is needed to build a smooth mesh
class MeshBuilder {
public:
inline void add_vertex(Vector3 position, Vector3 normal) {
int i = 0;
// TODO Debug this to see if it's effectively indexing
if (_position_to_index.find(position) != _position_to_index.end()) {
i = _position_to_index[position];

View File

@ -3,6 +3,7 @@
#include "marching_cubes_tables.h"
#include "mesh_builder.h"
// Dual marching cubes
// Algorithm taken from https://www.volume-gfx.com/volume-rendering/dual-marching-cubes/
namespace dmc {

View File

@ -1,6 +1,6 @@
#include "register_types.h"
#include "dmc/voxel_mesher_dmc.h"
#include "transvoxel/voxel_mesher_smooth.h"
#include "transvoxel/voxel_mesher_transvoxel.h"
#include "voxel_box_mover.h"
#include "voxel_buffer.h"
#include "voxel_library.h"
@ -21,7 +21,7 @@ void register_voxel_types() {
ClassDB::register_class<VoxelProvider>();
ClassDB::register_class<VoxelProviderTest>();
ClassDB::register_class<VoxelProviderImage>();
ClassDB::register_class<VoxelMesherSmooth>();
ClassDB::register_class<VoxelMesherTransvoxel>();
ClassDB::register_class<VoxelBoxMover>();
ClassDB::register_class<VoxelMesherDMC>();

View File

@ -1,5 +1,5 @@
#include "voxel_mesher_smooth.h"
#include "voxel_mesher_transvoxel.h"
#include "transvoxel_tables.cpp"
#include <core/os/os.h>
@ -58,17 +58,17 @@ void copy_to(PoolVector<T> &to, Vector<T> &from) {
}
}
VoxelMesherSmooth::ReuseCell::ReuseCell() {
VoxelMesherTransvoxel::ReuseCell::ReuseCell() {
case_index = 0;
for (unsigned int i = 0; i < 4; ++i) {
vertices[i] = -1;
}
}
VoxelMesherSmooth::VoxelMesherSmooth() {
VoxelMesherTransvoxel::VoxelMesherTransvoxel() {
}
Ref<ArrayMesh> VoxelMesherSmooth::build_mesh(Ref<VoxelBuffer> voxels_ref, unsigned int channel, Ref<ArrayMesh> mesh) {
Ref<ArrayMesh> VoxelMesherTransvoxel::build_mesh(Ref<VoxelBuffer> voxels_ref, unsigned int channel, Ref<ArrayMesh> mesh) {
ERR_FAIL_COND_V(voxels_ref.is_null(), Ref<ArrayMesh>());
@ -88,7 +88,7 @@ Ref<ArrayMesh> VoxelMesherSmooth::build_mesh(Ref<VoxelBuffer> voxels_ref, unsign
return mesh;
}
Array VoxelMesherSmooth::build(const VoxelBuffer &voxels, unsigned int channel) {
Array VoxelMesherTransvoxel::build(const VoxelBuffer &voxels, unsigned int channel) {
ERR_FAIL_COND_V(channel >= VoxelBuffer::MAX_CHANNELS, Array());
@ -134,7 +134,7 @@ Array VoxelMesherSmooth::build(const VoxelBuffer &voxels, unsigned int channel)
return surfaces;
}
void VoxelMesherSmooth::build_internal(const VoxelBuffer &voxels, unsigned int channel) {
void VoxelMesherTransvoxel::build_internal(const VoxelBuffer &voxels, unsigned int channel) {
// Each 2x2 voxel group is a "cell"
@ -381,18 +381,18 @@ void VoxelMesherSmooth::build_internal(const VoxelBuffer &voxels, unsigned int c
//OS::get_singleton()->print("\n");
}
VoxelMesherSmooth::ReuseCell &VoxelMesherSmooth::get_reuse_cell(Vector3i pos) {
VoxelMesherTransvoxel::ReuseCell &VoxelMesherTransvoxel::get_reuse_cell(Vector3i pos) {
int j = pos.z & 1;
int i = pos.y * m_block_size.y + pos.x;
return m_cache[j].write[i];
}
void VoxelMesherSmooth::emit_vertex(Vector3 primary, Vector3 normal) {
void VoxelMesherTransvoxel::emit_vertex(Vector3 primary, Vector3 normal) {
m_output_vertices.push_back(primary - PAD.to_vec3());
m_output_normals.push_back(normal);
}
void VoxelMesherSmooth::_bind_methods() {
void VoxelMesherTransvoxel::_bind_methods() {
ClassDB::bind_method(D_METHOD("build", "voxels", "channel", "existing_mesh"), &VoxelMesherSmooth::build_mesh, DEFVAL(Variant()));
ClassDB::bind_method(D_METHOD("build", "voxels", "channel", "existing_mesh"), &VoxelMesherTransvoxel::build_mesh, DEFVAL(Variant()));
}

View File

@ -4,11 +4,11 @@
#include "../voxel_buffer.h"
#include <scene/resources/mesh.h>
class VoxelMesherSmooth : public Reference {
GDCLASS(VoxelMesherSmooth, Reference)
class VoxelMesherTransvoxel : public Reference {
GDCLASS(VoxelMesherTransvoxel, Reference)
public:
VoxelMesherSmooth();
VoxelMesherTransvoxel();
Ref<ArrayMesh> build_mesh(Ref<VoxelBuffer> voxels_ref, unsigned int channel, Ref<ArrayMesh> mesh = Ref<ArrayMesh>());
Array build(const VoxelBuffer &voxels, unsigned int channel);

View File

@ -6,7 +6,7 @@
#include <core/hash_map.h>
#include <scene/main/node.h>
// Infinite voxel storage by means of octants like Gridmap
// Infinite voxel storage by means of octants like Gridmap, within a constant LOD
class VoxelMap : public Reference {
GDCLASS(VoxelMap, Reference)
public:

View File

@ -7,7 +7,7 @@
#include "voxel_buffer.h"
#include "voxel_mesher.h"
#include "transvoxel/voxel_mesher_smooth.h"
#include "transvoxel/voxel_mesher_transvoxel.h"
class VoxelMeshUpdater {
public:
@ -77,7 +77,7 @@ private:
Mutex *_output_mutex;
Ref<VoxelMesher> _model_mesher;
Ref<VoxelMesherSmooth> _smooth_mesher;
Ref<VoxelMesherTransvoxel> _smooth_mesher;
Input _input;
Output _output;