mirror of
https://github.com/Relintai/voxelman.git
synced 2024-11-12 10:15:12 +01:00
Now voxelman can actually make meshes.
This commit is contained in:
parent
b50c9be4e7
commit
71de54d9a0
@ -1,7 +1,7 @@
|
||||
#ifndef VOXEL_TOOLS_H
|
||||
#define VOXEL_TOOLS_H
|
||||
|
||||
#include "core/resource.h"
|
||||
#include "core/reference.h"
|
||||
#include "core/color.h"
|
||||
#include "core/math/vector2.h"
|
||||
#include "core/math/vector3.h"
|
||||
@ -25,8 +25,8 @@ const double PI = 3.141592653589793238463;
|
||||
class VoxelmanLibrary;
|
||||
class Voxel;
|
||||
|
||||
class VoxelMesher : public Resource {
|
||||
GDCLASS(VoxelMesher, Resource);
|
||||
class VoxelMesher : public Reference {
|
||||
GDCLASS(VoxelMesher, Reference);
|
||||
|
||||
public:
|
||||
Ref<VoxelmanLibrary> get_library() { return _library; }
|
||||
|
@ -58,6 +58,11 @@ void TransvoxelTransitionCellData::_bind_methods() {
|
||||
}
|
||||
|
||||
|
||||
Vector3 VoxelMesherTransvoxel::corner_id_to_vertex(int corner_id) const {
|
||||
ERR_FAIL_COND_V(corner_id < 0 || corner_id > 8, Vector3());
|
||||
|
||||
return transvoxel_vertices[corner_id];
|
||||
}
|
||||
|
||||
|
||||
int VoxelMesherTransvoxel::get_regular_cell_class(int index) const {
|
||||
@ -85,10 +90,16 @@ int VoxelMesherTransvoxel::get_regular_vertex_data_second_vertex(int index1, int
|
||||
return vert2;
|
||||
}
|
||||
|
||||
Vector3 VoxelMesherTransvoxel::get_regular_vertex_start_position(int index1, int index2) const {
|
||||
int vert1 = regularVertexData[index1][index2] & 0x000F;
|
||||
Vector3 VoxelMesherTransvoxel::get_regular_vertex_first_position(int index1, int index2) const {
|
||||
int vert = regularVertexData[index1][index2] & 0x000F;
|
||||
|
||||
return transvoxel_vertices[vert1];
|
||||
return transvoxel_vertices[vert];
|
||||
}
|
||||
|
||||
Vector3 VoxelMesherTransvoxel::get_regular_vertex_second_position(int index1, int index2) const {
|
||||
int vert = (regularVertexData[index1][index2] & 0x00F0) >> 4;
|
||||
|
||||
return transvoxel_vertices[vert];
|
||||
}
|
||||
|
||||
Vector3 VoxelMesherTransvoxel::get_regular_vertex_direction(int index1, int index2) const {
|
||||
@ -130,15 +141,21 @@ int VoxelMesherTransvoxel::get_transition_vertex_data_second_vertex(int index1,
|
||||
return static_cast<int>(vert);
|
||||
}
|
||||
|
||||
Vector3 VoxelMesherTransvoxel::get_transition_vertex_start_position(int index1, int index2) const {
|
||||
int vert1 = regularVertexData[index1][index2] & 0x000F;
|
||||
Vector3 VoxelMesherTransvoxel::get_transition_vertex_first_position(int index1, int index2) const {
|
||||
int vert = transitionVertexData[index1][index2] & 0x000F;
|
||||
|
||||
return transvoxel_vertices[vert1];
|
||||
return transvoxel_vertices[vert];
|
||||
}
|
||||
|
||||
Vector3 VoxelMesherTransvoxel::get_transition_vertex_second_position(int index1, int index2) const {
|
||||
int vert = (transitionVertexData[index1][index2] & 0x00F0) >> 4;
|
||||
|
||||
return transvoxel_vertices[vert];
|
||||
}
|
||||
|
||||
Vector3 VoxelMesherTransvoxel::get_transition_vertex_direction(int index1, int index2) const {
|
||||
int vert1 = regularVertexData[index1][index2] & 0x000F;
|
||||
int vert2 = (regularVertexData[index1][index2] & 0x00F0) >> 4;
|
||||
int vert1 = transitionVertexData[index1][index2] & 0x000F;
|
||||
int vert2 = (transitionVertexData[index1][index2] & 0x00F0) >> 4;
|
||||
|
||||
return transvoxel_vertices[vert2] - transvoxel_vertices[vert1];
|
||||
}
|
||||
@ -160,12 +177,15 @@ VoxelMesherTransvoxel::~VoxelMesherTransvoxel() {
|
||||
}
|
||||
|
||||
void VoxelMesherTransvoxel::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("corner_id_to_vertex", "index1"), &VoxelMesherTransvoxel::corner_id_to_vertex);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_regular_cell_class", "index"), &VoxelMesherTransvoxel::get_regular_cell_class);
|
||||
ClassDB::bind_method(D_METHOD("get_regular_cell_data", "index"), &VoxelMesherTransvoxel::get_regular_cell_data);
|
||||
ClassDB::bind_method(D_METHOD("get_regular_vertex_data", "index1", "index2"), &VoxelMesherTransvoxel::get_regular_vertex_data);
|
||||
ClassDB::bind_method(D_METHOD("get_regular_vertex_data_first_vertex", "index1", "index2"), &VoxelMesherTransvoxel::get_regular_vertex_data_first_vertex);
|
||||
ClassDB::bind_method(D_METHOD("get_regular_vertex_data_second_vertex", "index1", "index2"), &VoxelMesherTransvoxel::get_regular_vertex_data_second_vertex);
|
||||
ClassDB::bind_method(D_METHOD("get_regular_vertex_start_position", "index1", "index2"), &VoxelMesherTransvoxel::get_regular_vertex_start_position);
|
||||
ClassDB::bind_method(D_METHOD("get_regular_vertex_first_position", "index1", "index2"), &VoxelMesherTransvoxel::get_regular_vertex_first_position);
|
||||
ClassDB::bind_method(D_METHOD("get_regular_vertex_second_position", "index1", "index2"), &VoxelMesherTransvoxel::get_regular_vertex_second_position);
|
||||
ClassDB::bind_method(D_METHOD("get_regular_vertex_direction", "index1", "index2"), &VoxelMesherTransvoxel::get_regular_vertex_direction);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_transition_cell_class", "index"), &VoxelMesherTransvoxel::get_transition_cell_class);
|
||||
@ -174,7 +194,8 @@ void VoxelMesherTransvoxel::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("get_transition_vertex_data", "index1", "index2"), &VoxelMesherTransvoxel::get_transition_vertex_data);
|
||||
ClassDB::bind_method(D_METHOD("get_transition_vertex_data_first_vertex", "index1", "index2"), &VoxelMesherTransvoxel::get_transition_vertex_data_first_vertex);
|
||||
ClassDB::bind_method(D_METHOD("get_transition_vertex_data_second_vertex", "index1", "index2"), &VoxelMesherTransvoxel::get_transition_vertex_data_second_vertex);
|
||||
ClassDB::bind_method(D_METHOD("get_transition_vertex_start_position", "index1", "index2"), &VoxelMesherTransvoxel::get_transition_vertex_start_position);
|
||||
ClassDB::bind_method(D_METHOD("get_transition_vertex_first_position", "index1", "index2"), &VoxelMesherTransvoxel::get_transition_vertex_first_position);
|
||||
ClassDB::bind_method(D_METHOD("get_transition_vertex_second_position", "index1", "index2"), &VoxelMesherTransvoxel::get_transition_vertex_second_position);
|
||||
ClassDB::bind_method(D_METHOD("get_transition_vertex_direction", "index1", "index2"), &VoxelMesherTransvoxel::get_transition_vertex_direction);
|
||||
|
||||
BIND_ENUM_CONSTANT(VOXEL_ENTRY_INDEX_000);
|
||||
|
@ -81,6 +81,7 @@ public:
|
||||
VOXEL_ENTRY_MASK_111 = 1 << 7,
|
||||
};
|
||||
|
||||
Vector3 corner_id_to_vertex(int corner_id) const;
|
||||
|
||||
int get_regular_cell_class(int index) const;
|
||||
|
||||
@ -88,10 +89,10 @@ public:
|
||||
int get_regular_vertex_data(int index10, int index2) const;
|
||||
int get_regular_vertex_data_first_vertex(int index1, int index2) const;
|
||||
int get_regular_vertex_data_second_vertex(int index1, int index2) const;
|
||||
Vector3 get_regular_vertex_start_position(int index1, int index2) const;
|
||||
Vector3 get_regular_vertex_first_position(int index1, int index2) const;
|
||||
Vector3 get_regular_vertex_second_position(int index1, int index2) const;
|
||||
Vector3 get_regular_vertex_direction(int index1, int index2) const;
|
||||
|
||||
|
||||
int get_transition_cell_class(int index) const;
|
||||
|
||||
Ref<TransvoxelTransitionCellData> get_transition_cell_data(int index) const;
|
||||
@ -99,7 +100,8 @@ public:
|
||||
int get_transition_vertex_data(int index1, int index2) const;
|
||||
int get_transition_vertex_data_first_vertex(int index1, int index2) const;
|
||||
int get_transition_vertex_data_second_vertex(int index1, int index2) const;
|
||||
Vector3 get_transition_vertex_start_position(int index1, int index2) const;
|
||||
Vector3 get_transition_vertex_first_position(int index1, int index2) const;
|
||||
Vector3 get_transition_vertex_second_position(int index1, int index2) const;
|
||||
Vector3 get_transition_vertex_direction(int index1, int index2) const;
|
||||
|
||||
VoxelMesherTransvoxel();
|
||||
|
@ -73,7 +73,12 @@ void VoxelChunk::clear() {
|
||||
|
||||
void VoxelChunk::build() {
|
||||
ERR_FAIL_COND(!_library.is_valid());
|
||||
ERR_FAIL_COND(!_mesher.is_valid());
|
||||
|
||||
if (!_mesher.is_valid()) {
|
||||
call("_create_mesher");
|
||||
|
||||
ERR_FAIL_COND(!_mesher.is_valid());
|
||||
}
|
||||
|
||||
_mesher->set_library(_library);
|
||||
|
||||
@ -100,6 +105,10 @@ void VoxelChunk::build() {
|
||||
}
|
||||
}
|
||||
|
||||
void VoxelChunk::_create_mesher() {
|
||||
_mesher = Ref<VoxelMesher>(memnew(VoxelMesher()));
|
||||
}
|
||||
|
||||
void VoxelChunk::finalize_mesh() {
|
||||
_mesher->set_library(_library);
|
||||
|
||||
@ -229,7 +238,7 @@ void VoxelChunk::draw_debug_voxels(int max, Color color) {
|
||||
continue;
|
||||
}
|
||||
|
||||
draw_cross_voxels(Vector3(x + 0.5, y + 0.5, z + 0.5), _buffer->get_voxel(x, y, z, VoxelBuffer::CHANNEL_ISOLEVEL) / 255.0);
|
||||
draw_cross_voxels(Vector3(x, y, z), _buffer->get_voxel(x, y, z, VoxelBuffer::CHANNEL_ISOLEVEL) / 255.0);
|
||||
|
||||
++a;
|
||||
|
||||
@ -289,6 +298,9 @@ void VoxelChunk::draw_debug_voxel_lights(int max, bool localPosition) {
|
||||
|
||||
void VoxelChunk::_bind_methods() {
|
||||
BIND_VMETHOD(MethodInfo("_create_mesh"));
|
||||
BIND_VMETHOD(MethodInfo("_create_mesher"));
|
||||
|
||||
ClassDB::bind_method(D_METHOD("_create_mesher"), &VoxelChunk::_create_mesher);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_library_path"), &VoxelChunk::get_library_path);
|
||||
ClassDB::bind_method(D_METHOD("set_library_path", "value"), &VoxelChunk::set_library_path);
|
||||
|
@ -53,6 +53,8 @@ public:
|
||||
|
||||
Ref<VoxelBuffer> get_buffer() const;
|
||||
|
||||
void _create_mesher();
|
||||
|
||||
void finalize_mesh();
|
||||
|
||||
void clear();
|
||||
|
Loading…
Reference in New Issue
Block a user