More work on fixing the build.

This commit is contained in:
Relintai 2019-11-18 20:03:40 +01:00
parent decf9a4af2
commit f00933bb71
9 changed files with 107 additions and 73 deletions

View File

@ -1,22 +1,22 @@
#include "voxel_light.h"
int VoxelLight::get_world_position_x() const {
return _world_position.x;
return _world_position_x;
}
int VoxelLight::get_world_position_y() const {
return _world_position.y;
return _world_position_y;
}
int VoxelLight::get_world_position_z() const {
return _world_position.z;
return _world_position_z;
}
Vector3i VoxelLight::get_world_position() {
return _world_position;
Vector3 VoxelLight::get_world_position() {
return Vector3(_world_position_x, _world_position_y, _world_position_z);
}
void VoxelLight::set_world_position(const int x, const int y, const int z) {
_world_position.x = x;
_world_position.y = y;
_world_position.z = z;
_world_position_x = x;
_world_position_y = y;
_world_position_z = z;
}
Color VoxelLight::get_color() const {

View File

@ -5,8 +5,6 @@
#include "core/reference.h"
#include "core/vector.h"
#include "../math/vector3i.h"
class VoxelLight : public Reference {
GDCLASS(VoxelLight, Reference);
@ -14,7 +12,7 @@ public:
int get_world_position_x() const;
int get_world_position_y() const;
int get_world_position_z() const;
Vector3i get_world_position();
Vector3 get_world_position();
void set_world_position(const int x, const int y, const int z);
Color get_color() const;
@ -30,8 +28,14 @@ private:
static void _bind_methods();
private:
Vector3i _chunk_position;
Vector3i _world_position;
int _chunk_position_x;
int _chunk_position_y;
int _chunk_position_z;
int _world_position_x;
int _world_position_y;
int _world_position_z;
Color _color;
int _size;
};

View File

@ -168,7 +168,7 @@ void VoxelCubePoints::recalculate_point(int point) {
_points[point] = dynamic_offset;
}
void VoxelCubePoints::refresh_neighbours(const Ref<VoxelBuffer> buffer) {
void VoxelCubePoints::refresh_neighbours(const VoxelChunk *buffer) {
int neighbours = 0;
int x = _x;
@ -405,7 +405,7 @@ void VoxelCubePoints::refresh_neighbours(const Ref<VoxelBuffer> buffer) {
_point_neighbours[P111] = neighbours;
}
void VoxelCubePoints::setup(const Ref<VoxelBuffer> buffer, int x, int y, int z, int size) {
void VoxelCubePoints::setup(const VoxelChunk *buffer, int x, int y, int z, int size) {
ERR_FAIL_COND(size <= 0);
ERR_FAIL_COND(!buffer->validate_pos(x + size, y + size, z + size) || !buffer->validate_pos(x, y, z));
@ -509,7 +509,7 @@ bool VoxelCubePoints::is_face_visible(int face) {
}
bool VoxelCubePoints::is_sub_voxel_point_vec(Vector3i point) {
bool VoxelCubePoints::is_sub_voxel_point_vec(Vector3 point) {
for (int i = 0; i < POINT_COUNT; i += 1) {
if (get_point(i) == (point)) {
return true;
@ -520,7 +520,7 @@ bool VoxelCubePoints::is_sub_voxel_point_vec(Vector3i point) {
bool VoxelCubePoints::is_sub_voxel_point(int x, int y, int z) {
for (int i = 0; i < POINT_COUNT; i += 1) {
if (get_point(i) == Vector3i(x, y, z)) {
if (get_point(i) == Vector3(x, y, z)) {
return true;
}
}
@ -531,7 +531,7 @@ void VoxelCubePoints::set_point(int point, int x, int y, int z) {
_points[point] = Vector3(x, y, z);
}
int VoxelCubePoints::get_point_id_vec(Vector3i point) {
int VoxelCubePoints::get_point_id_vec(Vector3 point) {
for (int i = 0; i < POINT_COUNT; ++i) {
if (get_point(i) == point) {
return i;

View File

@ -1,8 +1,6 @@
#ifndef SUB_VOXEL_POINTS_H
#define SUB_VOXEL_POINTS_H
#include "../../math/vector3i.h"
#include "../../world/voxel_buffer.h"
#include "core/reference.h"
#include "core/vector.h"
@ -91,8 +89,8 @@ public:
void refresh_points();
void recalculate_point(int point);
void refresh_neighbours(const Ref<VoxelBuffer> buffer);
void setup(const Ref<VoxelBuffer> buffer, int x, int y, int z, int size = 1);
void refresh_neighbours(const VoxelChunk *buffer);
void setup(const VoxelChunk *buffer, int x, int y, int z, int size = 1);
void reset();
@ -101,10 +99,8 @@ public:
Vector3 get_points_for_face(int face, int index);
bool is_face_visible(int face);
bool is_sub_voxel_point_vec(Vector3i point);
bool is_sub_voxel_point(int x, int y, int z);
void set_point(int point, int x, int y, int z);
int get_point_id_vec(Vector3i point);
int get_point_id(int x, int y, int z);
Vector3 get_point_for_face(int face, int pointIndex);

View File

@ -1,7 +1,7 @@
#include "voxel_mesher_cubic.h"
void VoxelMesherCubic::_add_buffer(Ref<VoxelBuffer> buffer) {
void VoxelMesherCubic::_add_buffer(VoxelChunk *buffer) {
buffer->generate_ao();
Vector3i bfs = buffer->get_size();

View File

@ -13,7 +13,7 @@ class VoxelMesherCubic : public VoxelMesher {
GDCLASS(VoxelMesherCubic, VoxelMesher);
public:
void _add_buffer(Ref<VoxelBuffer> buffer);
void _add_buffer(VoxelChunk *buffer);
VoxelMesherCubic();
~VoxelMesherCubic();

View File

@ -1,5 +1,7 @@
#include "voxel_mesher.h"
#include "../world/voxel_chunk.h"
Ref<VoxelmanLibrary> VoxelMesher::get_library() {
return _library;
}
@ -113,16 +115,30 @@ void VoxelMesher::reset() {
_surface_tool->clear();
}
void VoxelMesher::add_buffer(Ref<VoxelBuffer> voxels) {
ERR_FAIL_COND(!has_method("_add_buffer"));
void VoxelMesher::add_chunk_bind(Node *chunk) {
VoxelChunk *vchunk = Object::cast_to<VoxelChunk>(chunk);
call("_add_buffer", voxels);
ERR_FAIL_COND(!ObjectDB::instance_validate(vchunk));
add_chunk(vchunk);
}
void VoxelMesher::add_chunk(VoxelChunk *chunk) {
ERR_FAIL_COND(!has_method("_add_chunk"));
call("_add_chunk", chunk);
}
void VoxelMesher::add_buffer_liquid(Ref<VoxelBuffer> voxels) {
ERR_FAIL_COND(!has_method("_add_buffer_liquid"));
void VoxelMesher::add_chunk_liquid_bind(Node *chunk) {
VoxelChunk *vchunk = Object::cast_to<VoxelChunk>(chunk);
call("_add_buffer_liquid", voxels);
ERR_FAIL_COND(!ObjectDB::instance_validate(vchunk));
add_chunk_liquid(vchunk);
}
void VoxelMesher::add_chunk_liquid(VoxelChunk *chunk) {
ERR_FAIL_COND(!has_method("_add_chunk_liquid"));
call("_add_chunk_liquid", chunk);
}
void VoxelMesher::add_mesh_data_resource(Ref<MeshDataResource> mesh, const Vector3 position, const Vector3 rotation, const Vector3 scale, const Rect2 uv_rect) {
@ -254,11 +270,18 @@ void VoxelMesher::add_mesh_data_resource_transform(Ref<MeshDataResource> mesh, c
}
}
void VoxelMesher::bake_colors(Ref<VoxelBuffer> voxels) {
if (has_method("_bake_colors"))
call("_bake_colors", voxels);
void VoxelMesher::bake_colors_bind(Node *chunk) {
VoxelChunk *vchunk = Object::cast_to<VoxelChunk>(chunk);
ERR_FAIL_COND(!ObjectDB::instance_validate(vchunk));
bake_colors(vchunk);
}
void VoxelMesher::_bake_colors(Ref<VoxelBuffer> buffer) {
void VoxelMesher::bake_colors(VoxelChunk *chunk) {
if (has_method("_bake_colors"))
call("_bake_colors", chunk);
}
void VoxelMesher::_bake_colors(VoxelChunk *chunk) {
Color base_light(_base_light_value, _base_light_value, _base_light_value);
ERR_FAIL_COND(_vertices.size() != _normals.size());
@ -278,14 +301,14 @@ void VoxelMesher::_bake_colors(Ref<VoxelBuffer> buffer) {
unsigned int y = (unsigned int)(vert.y / _voxel_scale);
unsigned int z = (unsigned int)(vert.z / _voxel_scale);
if (buffer->validate_pos(x, y, z)) {
if (chunk->validate_pos(x, y, z)) {
Color light = Color(
buffer->get_voxel(x, y, z, VoxelBuffer::CHANNEL_LIGHT_COLOR_R) / 255.0,
buffer->get_voxel(x, y, z, VoxelBuffer::CHANNEL_LIGHT_COLOR_G) / 255.0,
buffer->get_voxel(x, y, z, VoxelBuffer::CHANNEL_LIGHT_COLOR_B) / 255.0);
chunk->get_voxel(x, y, z, VoxelChunk::CHANNEL_LIGHT_COLOR_R) / 255.0,
chunk->get_voxel(x, y, z, VoxelChunk::CHANNEL_LIGHT_COLOR_G) / 255.0,
chunk->get_voxel(x, y, z, VoxelChunk::CHANNEL_LIGHT_COLOR_B) / 255.0);
float ao = (buffer->get_voxel(x, y, z, VoxelBuffer::CHANNEL_AO) / 255.0) * _ao_strength;
float rao = buffer->get_voxel(x, y, z, VoxelBuffer::CHANNEL_RANDOM_AO) / 255.0;
float ao = (chunk->get_voxel(x, y, z, VoxelChunk::CHANNEL_AO) / 255.0) * _ao_strength;
float rao = chunk->get_voxel(x, y, z, VoxelChunk::CHANNEL_RANDOM_AO) / 255.0;
ao += rao;
light.r += _base_light_value;
@ -313,11 +336,18 @@ void VoxelMesher::_bake_colors(Ref<VoxelBuffer> buffer) {
}
}
void VoxelMesher::bake_liquid_colors(Ref<VoxelBuffer> voxels) {
if (has_method("_bake_liquid_colors"))
call("_bake_liquid_colors", voxels);
void VoxelMesher::bake_liquid_colors_bind(Node *chunk) {
VoxelChunk *vchunk = Object::cast_to<VoxelChunk>(chunk);
ERR_FAIL_COND(!ObjectDB::instance_validate(vchunk));
bake_liquid_colors(vchunk);
}
void VoxelMesher::_bake_liquid_colors(Ref<VoxelBuffer> buffer) {
void VoxelMesher::bake_liquid_colors(VoxelChunk *chunk) {
if (has_method("_bake_liquid_colors"))
call("_bake_liquid_colors", chunk);
}
void VoxelMesher::_bake_liquid_colors(VoxelChunk *chunk) {
Color base_light(_base_light_value, _base_light_value, _base_light_value);
ERR_FAIL_COND(_vertices.size() != _normals.size());
@ -337,14 +367,14 @@ void VoxelMesher::_bake_liquid_colors(Ref<VoxelBuffer> buffer) {
unsigned int y = (unsigned int)(vert.y / _voxel_scale);
unsigned int z = (unsigned int)(vert.z / _voxel_scale);
if (buffer->validate_pos(x, y, z)) {
if (chunk->validate_pos(x, y, z)) {
Color light = Color(
buffer->get_voxel(x, y, z, VoxelBuffer::CHANNEL_LIGHT_COLOR_R) / 255.0,
buffer->get_voxel(x, y, z, VoxelBuffer::CHANNEL_LIGHT_COLOR_G) / 255.0,
buffer->get_voxel(x, y, z, VoxelBuffer::CHANNEL_LIGHT_COLOR_B) / 255.0);
chunk->get_voxel(x, y, z, VoxelChunk::CHANNEL_LIGHT_COLOR_R) / 255.0,
chunk->get_voxel(x, y, z, VoxelChunk::CHANNEL_LIGHT_COLOR_G) / 255.0,
chunk->get_voxel(x, y, z, VoxelChunk::CHANNEL_LIGHT_COLOR_B) / 255.0);
float ao = (buffer->get_voxel(x, y, z, VoxelBuffer::CHANNEL_AO) / 255.0) * _ao_strength;
float rao = buffer->get_voxel(x, y, z, VoxelBuffer::CHANNEL_RANDOM_AO) / 255.0;
float ao = (chunk->get_voxel(x, y, z, VoxelChunk::CHANNEL_AO) / 255.0) * _ao_strength;
float rao = chunk->get_voxel(x, y, z, VoxelChunk::CHANNEL_RANDOM_AO) / 255.0;
ao += rao;
light.r += _base_light_value;
@ -427,7 +457,7 @@ void VoxelMesher::bake_lights(MeshInstance *node, Vector<Ref<VoxelLight> > &ligh
for (int i = 0; i < lights.size(); ++i) {
Ref<VoxelLight> light = lights.get(i);
Vector3 lightDir = light->get_world_position().to_vec3() - vertex;
Vector3 lightDir = light->get_world_position() - vertex;
float dist2 = lightDir.dot(lightDir);
//inverse sqrt
@ -630,10 +660,10 @@ VoxelMesher::~VoxelMesher() {
}
void VoxelMesher::_bind_methods() {
BIND_VMETHOD(MethodInfo("_add_buffer", PropertyInfo(Variant::OBJECT, "buffer", PROPERTY_HINT_RESOURCE_TYPE, "VoxelBuffer")));
BIND_VMETHOD(MethodInfo("_add_buffer_liquid", PropertyInfo(Variant::OBJECT, "buffer", PROPERTY_HINT_RESOURCE_TYPE, "VoxelBuffer")));
BIND_VMETHOD(MethodInfo("_bake_colors", PropertyInfo(Variant::OBJECT, "buffer", PROPERTY_HINT_RESOURCE_TYPE, "VoxelBuffer")));
BIND_VMETHOD(MethodInfo("_bake_liquid_colors", PropertyInfo(Variant::OBJECT, "buffer", PROPERTY_HINT_RESOURCE_TYPE, "VoxelBuffer")));
BIND_VMETHOD(MethodInfo("_add_chunk", PropertyInfo(Variant::OBJECT, "chunk", PROPERTY_HINT_RESOURCE_TYPE, "VoxelChunk")));
BIND_VMETHOD(MethodInfo("_add_chunk_liquid", PropertyInfo(Variant::OBJECT, "chunk", PROPERTY_HINT_RESOURCE_TYPE, "VoxelChunk")));
BIND_VMETHOD(MethodInfo("_bake_colors", PropertyInfo(Variant::OBJECT, "chunk", PROPERTY_HINT_RESOURCE_TYPE, "VoxelChunk")));
BIND_VMETHOD(MethodInfo("_bake_liquid_colors", PropertyInfo(Variant::OBJECT, "chunk", PROPERTY_HINT_RESOURCE_TYPE, "VoxelChunk")));
ClassDB::bind_method(D_METHOD("get_library"), &VoxelMesher::get_library);
ClassDB::bind_method(D_METHOD("set_library", "value"), &VoxelMesher::set_library);
@ -663,15 +693,17 @@ void VoxelMesher::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_uv_margin", "value"), &VoxelMesher::set_uv_margin);
ADD_PROPERTY(PropertyInfo(Variant::RECT2, "uv_margin"), "set_uv_margin", "get_uv_margin");
ClassDB::bind_method(D_METHOD("add_buffer", "buffer"), &VoxelMesher::add_buffer);
ClassDB::bind_method(D_METHOD("add_chunk", "chunk"), &VoxelMesher::add_chunk_bind);
ClassDB::bind_method(D_METHOD("add_chunk_liquid", "chunk"), &VoxelMesher::add_chunk_liquid_bind);
ClassDB::bind_method(D_METHOD("add_mesh_data_resource", "mesh", "position", "rotation", "scale", "uv_rect"), &VoxelMesher::add_mesh_data_resource, DEFVAL(Rect2(0, 0, 1, 1)), DEFVAL(Vector3(1.0, 1.0, 1.0)), DEFVAL(Vector3()), DEFVAL(Vector3()));
ClassDB::bind_method(D_METHOD("add_mesh_data_resource_transform", "mesh", "transform", "uv_rect"), &VoxelMesher::add_mesh_data_resource_transform, DEFVAL(Rect2(0, 0, 1, 1)));
ClassDB::bind_method(D_METHOD("bake_colors", "buffer"), &VoxelMesher::bake_colors);
ClassDB::bind_method(D_METHOD("_bake_colors", "buffer"), &VoxelMesher::_bake_colors);
ClassDB::bind_method(D_METHOD("bake_colors", "chunk"), &VoxelMesher::bake_colors_bind);
ClassDB::bind_method(D_METHOD("_bake_colors", "chunk"), &VoxelMesher::_bake_colors);
ClassDB::bind_method(D_METHOD("bake_liquid_colors", "buffer"), &VoxelMesher::bake_liquid_colors);
ClassDB::bind_method(D_METHOD("_bake_liquid_colors", "buffer"), &VoxelMesher::_bake_liquid_colors);
ClassDB::bind_method(D_METHOD("bake_liquid_colors", "chunk"), &VoxelMesher::bake_liquid_colors_bind);
ClassDB::bind_method(D_METHOD("_bake_liquid_colors", "chunk"), &VoxelMesher::_bake_liquid_colors);
ClassDB::bind_method(D_METHOD("get_vertex_count"), &VoxelMesher::get_vertex_count);
ClassDB::bind_method(D_METHOD("get_vertex", "idx"), &VoxelMesher::get_vertex);

View File

@ -17,15 +17,13 @@
#include "scene/resources/concave_polygon_shape.h"
#include "../library/voxelman_library.h"
#include "../math/vector3i.h"
#include "../world/voxel_buffer.h"
#include "../../entity_spell_system/meshes/mesh_data_resource.h"
const double PI_2 = 3.141592653589793238463 / 2;
const double PI = 3.141592653589793238463;
class VoxelmanLibrary;
class Voxel;
class VoxelChunk;
class VoxelMesher : public Reference {
GDCLASS(VoxelMesher, Reference);
@ -54,16 +52,22 @@ public:
void reset();
void add_buffer(Ref<VoxelBuffer> voxels);
void add_buffer_liquid(Ref<VoxelBuffer> voxels);
void add_chunk_bind(Node *chunk);
void add_chunk(VoxelChunk *chunk);
void add_chunk_liquid_bind(Node *chunk);
void add_chunk_liquid(VoxelChunk *chunk);
void add_mesh_data_resource(Ref<MeshDataResource> mesh, const Vector3 position = Vector3(0, 0, 0), const Vector3 rotation = Vector3(0, 0, 0), const Vector3 scale = Vector3(1.0, 1.0, 1.0), const Rect2 uv_rect = Rect2(0, 0, 1, 1));
void add_mesh_data_resource_transform(Ref<MeshDataResource> mesh, const Transform transform, const Rect2 uv_rect = Rect2(0, 0, 1, 1));
void bake_colors(Ref<VoxelBuffer> voxels);
void _bake_colors(Ref<VoxelBuffer> buffer);
void bake_colors_bind(Node *chunk);
void bake_colors(VoxelChunk *chunk);
void _bake_colors(VoxelChunk *chunk);
void bake_liquid_colors(Ref<VoxelBuffer> voxels);
void _bake_liquid_colors(Ref<VoxelBuffer> buffer);
void bake_liquid_colors_bind(Node *chunk);
void bake_liquid_colors(VoxelChunk *chunk);
void _bake_liquid_colors(VoxelChunk *chunk);
void build_collider(RID shape) const;

View File

@ -4,10 +4,8 @@
#include "scene/3d/navigation.h"
#include "core/hash_map.h"
#include "../math/vector3i.h"
#include "../library/voxelman_library.h"
#include "../level_generator/voxelman_level_generator.h"
#include "voxel_buffer.h"
#include "../areas/world_area.h"
class VoxelChunk;