mirror of
https://github.com/Relintai/godot_voxel.git
synced 2024-12-22 01:26:50 +01:00
Rename VoxelMesherSmooth => VoxelMesherTransvoxel
This commit is contained in:
parent
d53e43f115
commit
35ff5fd546
@ -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];
|
||||
|
@ -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 {
|
||||
|
@ -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>();
|
||||
|
@ -1,5 +1,5 @@
|
||||
|
||||
#include "voxel_mesher_smooth.h"
|
||||
#include "voxel_mesher_transvoxel.h"
|
||||
#include "transvoxel_tables.cpp"
|
||||
#include <core/os/os.h>
|
||||
|
||||
@ -58,28 +58,28 @@ 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>());
|
||||
|
||||
VoxelBuffer &buffer = **voxels_ref;
|
||||
Array surfaces = build(buffer, channel);
|
||||
|
||||
if(mesh.is_null())
|
||||
if (mesh.is_null())
|
||||
mesh.instance();
|
||||
|
||||
//int surface = mesh->get_surface_count();
|
||||
for(int i = 0; i < surfaces.size(); ++i) {
|
||||
for (int i = 0; i < surfaces.size(); ++i) {
|
||||
Array arrays = surfaces[i];
|
||||
mesh->add_surface_from_arrays(Mesh::PRIMITIVE_TRIANGLES, arrays);
|
||||
//mesh->surface_set_material(surface, _materials[i]);
|
||||
@ -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,11 +134,11 @@ 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"
|
||||
|
||||
if(voxels.is_uniform(channel)) {
|
||||
if (voxels.is_uniform(channel)) {
|
||||
// Nothing to extract, because constant isolevels never cross the threshold and describe no surface
|
||||
return;
|
||||
}
|
||||
@ -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()));
|
||||
}
|
@ -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);
|
@ -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:
|
||||
@ -60,10 +60,10 @@ public:
|
||||
|
||||
template <typename Action_T>
|
||||
void remove_block(Vector3i bpos, Action_T pre_delete) {
|
||||
if(_last_accessed_block && _last_accessed_block->pos == bpos)
|
||||
if (_last_accessed_block && _last_accessed_block->pos == bpos)
|
||||
_last_accessed_block = NULL;
|
||||
VoxelBlock **pptr = _blocks.getptr(bpos);
|
||||
if(pptr) {
|
||||
if (pptr) {
|
||||
VoxelBlock *block = *pptr;
|
||||
ERR_FAIL_COND(block == NULL);
|
||||
pre_delete(block);
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user