mirror of
https://github.com/Relintai/voxelman.git
synced 2024-11-12 10:15:12 +01:00
More work on compile.
This commit is contained in:
parent
5e323ce718
commit
9103db635f
@ -1,12 +1,12 @@
|
|||||||
#include "voxel_light.h"
|
#include "voxel_light.h"
|
||||||
|
|
||||||
int VoxelLight::get_world_position_x() const {
|
_FORCE_INLINE_ int VoxelLight::get_world_position_x() const {
|
||||||
return _world_position_x;
|
return _world_position_x;
|
||||||
}
|
}
|
||||||
int VoxelLight::get_world_position_y() const {
|
_FORCE_INLINE_ int VoxelLight::get_world_position_y() const {
|
||||||
return _world_position_y;
|
return _world_position_y;
|
||||||
}
|
}
|
||||||
int VoxelLight::get_world_position_z() const {
|
_FORCE_INLINE_ int VoxelLight::get_world_position_z() const {
|
||||||
return _world_position_z;
|
return _world_position_z;
|
||||||
}
|
}
|
||||||
Vector3 VoxelLight::get_world_position() {
|
Vector3 VoxelLight::get_world_position() {
|
||||||
@ -19,7 +19,7 @@ void VoxelLight::set_world_position(const int x, const int y, const int z) {
|
|||||||
_world_position_z = z;
|
_world_position_z = z;
|
||||||
}
|
}
|
||||||
|
|
||||||
Color VoxelLight::get_color() const {
|
_FORCE_INLINE_ Color VoxelLight::get_color() const {
|
||||||
return _color;
|
return _color;
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -28,9 +28,8 @@ void VoxelLight::set_color(Color color) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
float VoxelLight::get_size() const {
|
_FORCE_INLINE_ float VoxelLight::get_size() const {
|
||||||
return _size;
|
return _size;
|
||||||
|
|
||||||
}
|
}
|
||||||
void VoxelLight::set_size(const float size) {
|
void VoxelLight::set_size(const float size) {
|
||||||
_size = size;
|
_size = size;
|
||||||
|
@ -168,7 +168,7 @@ void VoxelCubePoints::recalculate_point(int point) {
|
|||||||
_points[point] = dynamic_offset;
|
_points[point] = dynamic_offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
void VoxelCubePoints::refresh_neighbours(const VoxelChunk *buffer) {
|
void VoxelCubePoints::refresh_neighbours(const VoxelChunk *chunk) {
|
||||||
int neighbours = 0;
|
int neighbours = 0;
|
||||||
|
|
||||||
int x = _x;
|
int x = _x;
|
||||||
@ -176,25 +176,25 @@ void VoxelCubePoints::refresh_neighbours(const VoxelChunk *buffer) {
|
|||||||
int z = _z;
|
int z = _z;
|
||||||
|
|
||||||
//000
|
//000
|
||||||
if (buffer->get_voxel(x - 1, y, z, VoxelChunk::DEFAULT_CHANNEL_TYPE) != 0)
|
if (chunk->get_voxel(x - 1, y, z, VoxelChunk::DEFAULT_CHANNEL_TYPE) != 0)
|
||||||
neighbours = neighbours | VOXEL_NEIGHBOUR_LEFT;
|
neighbours = neighbours | VOXEL_NEIGHBOUR_LEFT;
|
||||||
|
|
||||||
if (buffer->get_voxel(x, y - 1, z, VoxelChunk::DEFAULT_CHANNEL_TYPE) != 0)
|
if (chunk->get_voxel(x, y - 1, z, VoxelChunk::DEFAULT_CHANNEL_TYPE) != 0)
|
||||||
neighbours = neighbours | VOXEL_NEIGHBOUR_BOTTOM;
|
neighbours = neighbours | VOXEL_NEIGHBOUR_BOTTOM;
|
||||||
|
|
||||||
if (buffer->get_voxel(x, y, z - 1, VoxelChunk::DEFAULT_CHANNEL_TYPE) != 0)
|
if (chunk->get_voxel(x, y, z - 1, VoxelChunk::DEFAULT_CHANNEL_TYPE) != 0)
|
||||||
neighbours = neighbours | VOXEL_NEIGHBOUR_FRONT;
|
neighbours = neighbours | VOXEL_NEIGHBOUR_FRONT;
|
||||||
/*
|
/*
|
||||||
if (buffer->get_voxel(x - 1, y, z - 1, VoxelChunk::DEFAULT_CHANNEL_TYPE) != 0)
|
if (chunk->get_voxel(x - 1, y, z - 1, VoxelChunk::DEFAULT_CHANNEL_TYPE) != 0)
|
||||||
neighbours = neighbours | VOXEL_NEIGHBOUR_LEFT_FRONT;
|
neighbours = neighbours | VOXEL_NEIGHBOUR_LEFT_FRONT;
|
||||||
|
|
||||||
if (buffer->get_voxel(x - 1, y - 1, z, VoxelChunk::DEFAULT_CHANNEL_TYPE) != 0)
|
if (chunk->get_voxel(x - 1, y - 1, z, VoxelChunk::DEFAULT_CHANNEL_TYPE) != 0)
|
||||||
neighbours = neighbours | VOXEL_NEIGHBOUR_BOTTOM_LEFT;
|
neighbours = neighbours | VOXEL_NEIGHBOUR_BOTTOM_LEFT;
|
||||||
|
|
||||||
if (buffer->get_voxel(x, y - 1, z - 1, VoxelChunk::DEFAULT_CHANNEL_TYPE) != 0)
|
if (chunk->get_voxel(x, y - 1, z - 1, VoxelChunk::DEFAULT_CHANNEL_TYPE) != 0)
|
||||||
neighbours = neighbours | VOXEL_NEIGHBOUR_BOTTOM_FRONT;
|
neighbours = neighbours | VOXEL_NEIGHBOUR_BOTTOM_FRONT;
|
||||||
|
|
||||||
if (buffer->get_voxel(x - 1, y - 1, z - 1, VoxelChunk::DEFAULT_CHANNEL_TYPE) != 0)
|
if (chunk->get_voxel(x - 1, y - 1, z - 1, VoxelChunk::DEFAULT_CHANNEL_TYPE) != 0)
|
||||||
neighbours = neighbours | VOXEL_NEIGHBOUR_BOTTOM_LEFT_FRONT;*/
|
neighbours = neighbours | VOXEL_NEIGHBOUR_BOTTOM_LEFT_FRONT;*/
|
||||||
|
|
||||||
_point_neighbours[P000] = neighbours;
|
_point_neighbours[P000] = neighbours;
|
||||||
@ -205,25 +205,25 @@ void VoxelCubePoints::refresh_neighbours(const VoxelChunk *buffer) {
|
|||||||
z = _z;
|
z = _z;
|
||||||
|
|
||||||
//100
|
//100
|
||||||
if (buffer->get_voxel(x + 1, y, z, VoxelChunk::DEFAULT_CHANNEL_TYPE) != 0)
|
if (chunk->get_voxel(x + 1, y, z, VoxelChunk::DEFAULT_CHANNEL_TYPE) != 0)
|
||||||
neighbours = neighbours | VOXEL_NEIGHBOUR_RIGHT;
|
neighbours = neighbours | VOXEL_NEIGHBOUR_RIGHT;
|
||||||
|
|
||||||
if (buffer->get_voxel(x, y - 1, z, VoxelChunk::DEFAULT_CHANNEL_TYPE) != 0)
|
if (chunk->get_voxel(x, y - 1, z, VoxelChunk::DEFAULT_CHANNEL_TYPE) != 0)
|
||||||
neighbours = neighbours | VOXEL_NEIGHBOUR_BOTTOM;
|
neighbours = neighbours | VOXEL_NEIGHBOUR_BOTTOM;
|
||||||
|
|
||||||
if (buffer->get_voxel(x, y, z - 1, VoxelChunk::DEFAULT_CHANNEL_TYPE) != 0)
|
if (chunk->get_voxel(x, y, z - 1, VoxelChunk::DEFAULT_CHANNEL_TYPE) != 0)
|
||||||
neighbours = neighbours | VOXEL_NEIGHBOUR_FRONT;
|
neighbours = neighbours | VOXEL_NEIGHBOUR_FRONT;
|
||||||
/*
|
/*
|
||||||
if (buffer->get_voxel(x + 1, y, z - 1, VoxelChunk::DEFAULT_CHANNEL_TYPE) != 0)
|
if (chunk->get_voxel(x + 1, y, z - 1, VoxelChunk::DEFAULT_CHANNEL_TYPE) != 0)
|
||||||
neighbours = neighbours | VOXEL_NEIGHBOUR_RIGHT_FRONT;
|
neighbours = neighbours | VOXEL_NEIGHBOUR_RIGHT_FRONT;
|
||||||
|
|
||||||
if (buffer->get_voxel(x + 1, y - 1, z, VoxelChunk::DEFAULT_CHANNEL_TYPE) != 0)
|
if (chunk->get_voxel(x + 1, y - 1, z, VoxelChunk::DEFAULT_CHANNEL_TYPE) != 0)
|
||||||
neighbours = neighbours | VOXEL_NEIGHBOUR_BOTTOM_RIGHT;
|
neighbours = neighbours | VOXEL_NEIGHBOUR_BOTTOM_RIGHT;
|
||||||
|
|
||||||
if (buffer->get_voxel(x, y - 1, z - 1, VoxelChunk::DEFAULT_CHANNEL_TYPE) != 0)
|
if (chunk->get_voxel(x, y - 1, z - 1, VoxelChunk::DEFAULT_CHANNEL_TYPE) != 0)
|
||||||
neighbours = neighbours | VOXEL_NEIGHBOUR_BOTTOM_FRONT;
|
neighbours = neighbours | VOXEL_NEIGHBOUR_BOTTOM_FRONT;
|
||||||
|
|
||||||
if (buffer->get_voxel(x + 1, y - 1, z - 1, VoxelChunk::DEFAULT_CHANNEL_TYPE) != 0)
|
if (chunk->get_voxel(x + 1, y - 1, z - 1, VoxelChunk::DEFAULT_CHANNEL_TYPE) != 0)
|
||||||
neighbours = neighbours | VOXEL_NEIGHBOUR_BOTTOM_RIGHT_FRONT;*/
|
neighbours = neighbours | VOXEL_NEIGHBOUR_BOTTOM_RIGHT_FRONT;*/
|
||||||
|
|
||||||
_point_neighbours[P100] = neighbours;
|
_point_neighbours[P100] = neighbours;
|
||||||
@ -234,25 +234,25 @@ void VoxelCubePoints::refresh_neighbours(const VoxelChunk *buffer) {
|
|||||||
z = _z;
|
z = _z;
|
||||||
|
|
||||||
//010
|
//010
|
||||||
if (buffer->get_voxel(x - 1, y, z, VoxelChunk::DEFAULT_CHANNEL_TYPE) != 0)
|
if (chunk->get_voxel(x - 1, y, z, VoxelChunk::DEFAULT_CHANNEL_TYPE) != 0)
|
||||||
neighbours = neighbours | VOXEL_NEIGHBOUR_LEFT;
|
neighbours = neighbours | VOXEL_NEIGHBOUR_LEFT;
|
||||||
|
|
||||||
if (buffer->get_voxel(x, y + 1, z, VoxelChunk::DEFAULT_CHANNEL_TYPE) != 0)
|
if (chunk->get_voxel(x, y + 1, z, VoxelChunk::DEFAULT_CHANNEL_TYPE) != 0)
|
||||||
neighbours = neighbours | VOXEL_NEIGHBOUR_TOP;
|
neighbours = neighbours | VOXEL_NEIGHBOUR_TOP;
|
||||||
|
|
||||||
if (buffer->get_voxel(x, y, z - 1, VoxelChunk::DEFAULT_CHANNEL_TYPE) != 0)
|
if (chunk->get_voxel(x, y, z - 1, VoxelChunk::DEFAULT_CHANNEL_TYPE) != 0)
|
||||||
neighbours = neighbours | VOXEL_NEIGHBOUR_FRONT;
|
neighbours = neighbours | VOXEL_NEIGHBOUR_FRONT;
|
||||||
/*
|
/*
|
||||||
if (buffer->get_voxel(x - 1, y, z - 1, VoxelChunk::DEFAULT_CHANNEL_TYPE) != 0)
|
if (chunk->get_voxel(x - 1, y, z - 1, VoxelChunk::DEFAULT_CHANNEL_TYPE) != 0)
|
||||||
neighbours = neighbours | VOXEL_NEIGHBOUR_LEFT_FRONT;
|
neighbours = neighbours | VOXEL_NEIGHBOUR_LEFT_FRONT;
|
||||||
|
|
||||||
if (buffer->get_voxel(x - 1, y + 1, z, VoxelChunk::DEFAULT_CHANNEL_TYPE) != 0)
|
if (chunk->get_voxel(x - 1, y + 1, z, VoxelChunk::DEFAULT_CHANNEL_TYPE) != 0)
|
||||||
neighbours = neighbours | VOXEL_NEIGHBOUR_TOP_LEFT;
|
neighbours = neighbours | VOXEL_NEIGHBOUR_TOP_LEFT;
|
||||||
|
|
||||||
if (buffer->get_voxel(x, y + 1, z - 1, VoxelChunk::DEFAULT_CHANNEL_TYPE) != 0)
|
if (chunk->get_voxel(x, y + 1, z - 1, VoxelChunk::DEFAULT_CHANNEL_TYPE) != 0)
|
||||||
neighbours = neighbours | VOXEL_NEIGHBOUR_TOP_FRONT;
|
neighbours = neighbours | VOXEL_NEIGHBOUR_TOP_FRONT;
|
||||||
|
|
||||||
if (buffer->get_voxel(x - 1, y + 1, z - 1, VoxelChunk::DEFAULT_CHANNEL_TYPE) != 0)
|
if (chunk->get_voxel(x - 1, y + 1, z - 1, VoxelChunk::DEFAULT_CHANNEL_TYPE) != 0)
|
||||||
neighbours = neighbours | VOXEL_NEIGHBOUR_TOP_LEFT_FRONT;*/
|
neighbours = neighbours | VOXEL_NEIGHBOUR_TOP_LEFT_FRONT;*/
|
||||||
|
|
||||||
_point_neighbours[P010] = neighbours;
|
_point_neighbours[P010] = neighbours;
|
||||||
@ -263,25 +263,25 @@ void VoxelCubePoints::refresh_neighbours(const VoxelChunk *buffer) {
|
|||||||
z = _z;
|
z = _z;
|
||||||
|
|
||||||
//110
|
//110
|
||||||
if (buffer->get_voxel(x + 1, y, z, VoxelChunk::DEFAULT_CHANNEL_TYPE) != 0)
|
if (chunk->get_voxel(x + 1, y, z, VoxelChunk::DEFAULT_CHANNEL_TYPE) != 0)
|
||||||
neighbours = neighbours | VOXEL_NEIGHBOUR_RIGHT;
|
neighbours = neighbours | VOXEL_NEIGHBOUR_RIGHT;
|
||||||
|
|
||||||
if (buffer->get_voxel(x, y + 1, z, VoxelChunk::DEFAULT_CHANNEL_TYPE) != 0)
|
if (chunk->get_voxel(x, y + 1, z, VoxelChunk::DEFAULT_CHANNEL_TYPE) != 0)
|
||||||
neighbours = neighbours | VOXEL_NEIGHBOUR_TOP;
|
neighbours = neighbours | VOXEL_NEIGHBOUR_TOP;
|
||||||
|
|
||||||
if (buffer->get_voxel(x, y, z - 1, VoxelChunk::DEFAULT_CHANNEL_TYPE) != 0)
|
if (chunk->get_voxel(x, y, z - 1, VoxelChunk::DEFAULT_CHANNEL_TYPE) != 0)
|
||||||
neighbours = neighbours | VOXEL_NEIGHBOUR_FRONT;
|
neighbours = neighbours | VOXEL_NEIGHBOUR_FRONT;
|
||||||
/*
|
/*
|
||||||
if (buffer->get_voxel(x + 1, y, z - 1, VoxelChunk::DEFAULT_CHANNEL_TYPE) != 0)
|
if (chunk->get_voxel(x + 1, y, z - 1, VoxelChunk::DEFAULT_CHANNEL_TYPE) != 0)
|
||||||
neighbours = neighbours | VOXEL_NEIGHBOUR_RIGHT_FRONT;
|
neighbours = neighbours | VOXEL_NEIGHBOUR_RIGHT_FRONT;
|
||||||
|
|
||||||
if (buffer->get_voxel(x + 1, y + 1, z, VoxelChunk::DEFAULT_CHANNEL_TYPE) != 0)
|
if (chunk->get_voxel(x + 1, y + 1, z, VoxelChunk::DEFAULT_CHANNEL_TYPE) != 0)
|
||||||
neighbours = neighbours | VOXEL_NEIGHBOUR_TOP_RIGHT;
|
neighbours = neighbours | VOXEL_NEIGHBOUR_TOP_RIGHT;
|
||||||
|
|
||||||
if (buffer->get_voxel(x, y + 1, z - 1, VoxelChunk::DEFAULT_CHANNEL_TYPE) != 0)
|
if (chunk->get_voxel(x, y + 1, z - 1, VoxelChunk::DEFAULT_CHANNEL_TYPE) != 0)
|
||||||
neighbours = neighbours | VOXEL_NEIGHBOUR_TOP_FRONT;
|
neighbours = neighbours | VOXEL_NEIGHBOUR_TOP_FRONT;
|
||||||
|
|
||||||
if (buffer->get_voxel(x + 1, y + 1, z - 1, VoxelChunk::DEFAULT_CHANNEL_TYPE) != 0)
|
if (chunk->get_voxel(x + 1, y + 1, z - 1, VoxelChunk::DEFAULT_CHANNEL_TYPE) != 0)
|
||||||
neighbours = neighbours | VOXEL_NEIGHBOUR_TOP_RIGHT_FRONT;*/
|
neighbours = neighbours | VOXEL_NEIGHBOUR_TOP_RIGHT_FRONT;*/
|
||||||
|
|
||||||
_point_neighbours[P110] = neighbours;
|
_point_neighbours[P110] = neighbours;
|
||||||
@ -292,25 +292,25 @@ void VoxelCubePoints::refresh_neighbours(const VoxelChunk *buffer) {
|
|||||||
z = _z + 1;
|
z = _z + 1;
|
||||||
|
|
||||||
//001
|
//001
|
||||||
if (buffer->get_voxel(x - 1, y, z, VoxelChunk::DEFAULT_CHANNEL_TYPE) != 0)
|
if (chunk->get_voxel(x - 1, y, z, VoxelChunk::DEFAULT_CHANNEL_TYPE) != 0)
|
||||||
neighbours = neighbours | VOXEL_NEIGHBOUR_LEFT;
|
neighbours = neighbours | VOXEL_NEIGHBOUR_LEFT;
|
||||||
|
|
||||||
if (buffer->get_voxel(x, y - 1, z, VoxelChunk::DEFAULT_CHANNEL_TYPE) != 0)
|
if (chunk->get_voxel(x, y - 1, z, VoxelChunk::DEFAULT_CHANNEL_TYPE) != 0)
|
||||||
neighbours = neighbours | VOXEL_NEIGHBOUR_BOTTOM;
|
neighbours = neighbours | VOXEL_NEIGHBOUR_BOTTOM;
|
||||||
|
|
||||||
if (buffer->get_voxel(x, y, z + 1, VoxelChunk::DEFAULT_CHANNEL_TYPE) != 0)
|
if (chunk->get_voxel(x, y, z + 1, VoxelChunk::DEFAULT_CHANNEL_TYPE) != 0)
|
||||||
neighbours = neighbours | VOXEL_NEIGHBOUR_BACK;
|
neighbours = neighbours | VOXEL_NEIGHBOUR_BACK;
|
||||||
/*
|
/*
|
||||||
if (buffer->get_voxel(x - 1, y, z + 1, VoxelChunk::DEFAULT_CHANNEL_TYPE) != 0)
|
if (chunk->get_voxel(x - 1, y, z + 1, VoxelChunk::DEFAULT_CHANNEL_TYPE) != 0)
|
||||||
neighbours = neighbours | VOXEL_NEIGHBOUR_LEFT_BACK;
|
neighbours = neighbours | VOXEL_NEIGHBOUR_LEFT_BACK;
|
||||||
|
|
||||||
if (buffer->get_voxel(x - 1, y - 1, z, VoxelChunk::DEFAULT_CHANNEL_TYPE) != 0)
|
if (chunk->get_voxel(x - 1, y - 1, z, VoxelChunk::DEFAULT_CHANNEL_TYPE) != 0)
|
||||||
neighbours = neighbours | VOXEL_NEIGHBOUR_BOTTOM_LEFT;
|
neighbours = neighbours | VOXEL_NEIGHBOUR_BOTTOM_LEFT;
|
||||||
|
|
||||||
if (buffer->get_voxel(x, y - 1, z + 1, VoxelChunk::DEFAULT_CHANNEL_TYPE) != 0)
|
if (chunk->get_voxel(x, y - 1, z + 1, VoxelChunk::DEFAULT_CHANNEL_TYPE) != 0)
|
||||||
neighbours = neighbours | VOXEL_NEIGHBOUR_BOTTOM_BACK;
|
neighbours = neighbours | VOXEL_NEIGHBOUR_BOTTOM_BACK;
|
||||||
|
|
||||||
if (buffer->get_voxel(x - 1, y - 1, z + 1, VoxelChunk::DEFAULT_CHANNEL_TYPE) != 0)
|
if (chunk->get_voxel(x - 1, y - 1, z + 1, VoxelChunk::DEFAULT_CHANNEL_TYPE) != 0)
|
||||||
neighbours = neighbours | VOXEL_NEIGHBOUR_BOTTOM_LEFT_BACK;*/
|
neighbours = neighbours | VOXEL_NEIGHBOUR_BOTTOM_LEFT_BACK;*/
|
||||||
|
|
||||||
_point_neighbours[P001] = neighbours;
|
_point_neighbours[P001] = neighbours;
|
||||||
@ -322,25 +322,25 @@ void VoxelCubePoints::refresh_neighbours(const VoxelChunk *buffer) {
|
|||||||
z = _z + 1;
|
z = _z + 1;
|
||||||
|
|
||||||
//101
|
//101
|
||||||
if (buffer->get_voxel(x + 1, y, z, VoxelChunk::DEFAULT_CHANNEL_TYPE) != 0)
|
if (chunk->get_voxel(x + 1, y, z, VoxelChunk::DEFAULT_CHANNEL_TYPE) != 0)
|
||||||
neighbours = neighbours | VOXEL_NEIGHBOUR_RIGHT;
|
neighbours = neighbours | VOXEL_NEIGHBOUR_RIGHT;
|
||||||
|
|
||||||
if (buffer->get_voxel(x, y - 1, z, VoxelChunk::DEFAULT_CHANNEL_TYPE) != 0)
|
if (chunk->get_voxel(x, y - 1, z, VoxelChunk::DEFAULT_CHANNEL_TYPE) != 0)
|
||||||
neighbours = neighbours | VOXEL_NEIGHBOUR_BOTTOM;
|
neighbours = neighbours | VOXEL_NEIGHBOUR_BOTTOM;
|
||||||
|
|
||||||
if (buffer->get_voxel(x, y, z + 1, VoxelChunk::DEFAULT_CHANNEL_TYPE) != 0)
|
if (chunk->get_voxel(x, y, z + 1, VoxelChunk::DEFAULT_CHANNEL_TYPE) != 0)
|
||||||
neighbours = neighbours | VOXEL_NEIGHBOUR_BACK;
|
neighbours = neighbours | VOXEL_NEIGHBOUR_BACK;
|
||||||
/*
|
/*
|
||||||
if (buffer->get_voxel(x + 1, y, z + 1, VoxelChunk::DEFAULT_CHANNEL_TYPE) != 0)
|
if (chunk->get_voxel(x + 1, y, z + 1, VoxelChunk::DEFAULT_CHANNEL_TYPE) != 0)
|
||||||
neighbours = neighbours | VOXEL_NEIGHBOUR_RIGHT_BACK;
|
neighbours = neighbours | VOXEL_NEIGHBOUR_RIGHT_BACK;
|
||||||
|
|
||||||
if (buffer->get_voxel(x + 1, y - 1, z, VoxelChunk::DEFAULT_CHANNEL_TYPE) != 0)
|
if (chunk->get_voxel(x + 1, y - 1, z, VoxelChunk::DEFAULT_CHANNEL_TYPE) != 0)
|
||||||
neighbours = neighbours | VOXEL_NEIGHBOUR_BOTTOM_RIGHT;
|
neighbours = neighbours | VOXEL_NEIGHBOUR_BOTTOM_RIGHT;
|
||||||
|
|
||||||
if (buffer->get_voxel(x, y - 1, z + 1, VoxelChunk::DEFAULT_CHANNEL_TYPE) != 0)
|
if (chunk->get_voxel(x, y - 1, z + 1, VoxelChunk::DEFAULT_CHANNEL_TYPE) != 0)
|
||||||
neighbours = neighbours | VOXEL_NEIGHBOUR_BOTTOM_BACK;
|
neighbours = neighbours | VOXEL_NEIGHBOUR_BOTTOM_BACK;
|
||||||
|
|
||||||
if (buffer->get_voxel(x + 1, y - 1, z + 1, VoxelChunk::DEFAULT_CHANNEL_TYPE) != 0)
|
if (chunk->get_voxel(x + 1, y - 1, z + 1, VoxelChunk::DEFAULT_CHANNEL_TYPE) != 0)
|
||||||
neighbours = neighbours | VOXEL_NEIGHBOUR_BOTTOM_RIGHT_BACK;*/
|
neighbours = neighbours | VOXEL_NEIGHBOUR_BOTTOM_RIGHT_BACK;*/
|
||||||
|
|
||||||
_point_neighbours[P101] = neighbours;
|
_point_neighbours[P101] = neighbours;
|
||||||
@ -351,25 +351,25 @@ void VoxelCubePoints::refresh_neighbours(const VoxelChunk *buffer) {
|
|||||||
z = _z + 1;
|
z = _z + 1;
|
||||||
|
|
||||||
//011
|
//011
|
||||||
if (buffer->get_voxel(x - 1, y, z, VoxelChunk::DEFAULT_CHANNEL_TYPE) != 0)
|
if (chunk->get_voxel(x - 1, y, z, VoxelChunk::DEFAULT_CHANNEL_TYPE) != 0)
|
||||||
neighbours = neighbours | VOXEL_NEIGHBOUR_LEFT;
|
neighbours = neighbours | VOXEL_NEIGHBOUR_LEFT;
|
||||||
|
|
||||||
if (buffer->get_voxel(x, y + 1, z, VoxelChunk::DEFAULT_CHANNEL_TYPE) != 0)
|
if (chunk->get_voxel(x, y + 1, z, VoxelChunk::DEFAULT_CHANNEL_TYPE) != 0)
|
||||||
neighbours = neighbours | VOXEL_NEIGHBOUR_TOP;
|
neighbours = neighbours | VOXEL_NEIGHBOUR_TOP;
|
||||||
|
|
||||||
if (buffer->get_voxel(x, y, z + 1, VoxelChunk::DEFAULT_CHANNEL_TYPE) != 0)
|
if (chunk->get_voxel(x, y, z + 1, VoxelChunk::DEFAULT_CHANNEL_TYPE) != 0)
|
||||||
neighbours = neighbours | VOXEL_NEIGHBOUR_BACK;
|
neighbours = neighbours | VOXEL_NEIGHBOUR_BACK;
|
||||||
/*
|
/*
|
||||||
if (buffer->get_voxel(x - 1, y, z + 1, VoxelChunk::DEFAULT_CHANNEL_TYPE) != 0)
|
if (chunk->get_voxel(x - 1, y, z + 1, VoxelChunk::DEFAULT_CHANNEL_TYPE) != 0)
|
||||||
neighbours = neighbours | VOXEL_NEIGHBOUR_LEFT_BACK;
|
neighbours = neighbours | VOXEL_NEIGHBOUR_LEFT_BACK;
|
||||||
|
|
||||||
if (buffer->get_voxel(x - 1, y + 1, z, VoxelChunk::DEFAULT_CHANNEL_TYPE) != 0)
|
if (chunk->get_voxel(x - 1, y + 1, z, VoxelChunk::DEFAULT_CHANNEL_TYPE) != 0)
|
||||||
neighbours = neighbours | VOXEL_NEIGHBOUR_TOP_LEFT;
|
neighbours = neighbours | VOXEL_NEIGHBOUR_TOP_LEFT;
|
||||||
|
|
||||||
if (buffer->get_voxel(x, y + 1, z + 1, VoxelChunk::DEFAULT_CHANNEL_TYPE) != 0)
|
if (chunk->get_voxel(x, y + 1, z + 1, VoxelChunk::DEFAULT_CHANNEL_TYPE) != 0)
|
||||||
neighbours = neighbours | VOXEL_NEIGHBOUR_TOP_BACK;
|
neighbours = neighbours | VOXEL_NEIGHBOUR_TOP_BACK;
|
||||||
|
|
||||||
if (buffer->get_voxel(x - 1, y + 1, z + 1, VoxelChunk::DEFAULT_CHANNEL_TYPE) != 0)
|
if (chunk->get_voxel(x - 1, y + 1, z + 1, VoxelChunk::DEFAULT_CHANNEL_TYPE) != 0)
|
||||||
neighbours = neighbours | VOXEL_NEIGHBOUR_TOP_LEFT_BACK;*/
|
neighbours = neighbours | VOXEL_NEIGHBOUR_TOP_LEFT_BACK;*/
|
||||||
|
|
||||||
_point_neighbours[P011] = neighbours;
|
_point_neighbours[P011] = neighbours;
|
||||||
@ -381,33 +381,33 @@ void VoxelCubePoints::refresh_neighbours(const VoxelChunk *buffer) {
|
|||||||
z = _z + 1;
|
z = _z + 1;
|
||||||
|
|
||||||
//111
|
//111
|
||||||
if (buffer->get_voxel(x + 1, y, z, VoxelChunk::DEFAULT_CHANNEL_TYPE) != 0)
|
if (chunk->get_voxel(x + 1, y, z, VoxelChunk::DEFAULT_CHANNEL_TYPE) != 0)
|
||||||
neighbours = neighbours | VOXEL_NEIGHBOUR_RIGHT;
|
neighbours = neighbours | VOXEL_NEIGHBOUR_RIGHT;
|
||||||
|
|
||||||
if (buffer->get_voxel(x, y + 1, z, VoxelChunk::DEFAULT_CHANNEL_TYPE) != 0)
|
if (chunk->get_voxel(x, y + 1, z, VoxelChunk::DEFAULT_CHANNEL_TYPE) != 0)
|
||||||
neighbours = neighbours | VOXEL_NEIGHBOUR_TOP;
|
neighbours = neighbours | VOXEL_NEIGHBOUR_TOP;
|
||||||
|
|
||||||
if (buffer->get_voxel(x, y, z + 1, VoxelChunk::DEFAULT_CHANNEL_TYPE) != 0)
|
if (chunk->get_voxel(x, y, z + 1, VoxelChunk::DEFAULT_CHANNEL_TYPE) != 0)
|
||||||
neighbours = neighbours | VOXEL_NEIGHBOUR_BACK;
|
neighbours = neighbours | VOXEL_NEIGHBOUR_BACK;
|
||||||
/*
|
/*
|
||||||
if (buffer->get_voxel(x + 1, y, z + 1, VoxelChunk::DEFAULT_CHANNEL_TYPE) != 0)
|
if (chunk->get_voxel(x + 1, y, z + 1, VoxelChunk::DEFAULT_CHANNEL_TYPE) != 0)
|
||||||
neighbours = neighbours | VOXEL_NEIGHBOUR_RIGHT_BACK;
|
neighbours = neighbours | VOXEL_NEIGHBOUR_RIGHT_BACK;
|
||||||
|
|
||||||
if (buffer->get_voxel(x + 1, y + 1, z, VoxelChunk::DEFAULT_CHANNEL_TYPE) != 0)
|
if (chunk->get_voxel(x + 1, y + 1, z, VoxelChunk::DEFAULT_CHANNEL_TYPE) != 0)
|
||||||
neighbours = neighbours | VOXEL_NEIGHBOUR_TOP_RIGHT;
|
neighbours = neighbours | VOXEL_NEIGHBOUR_TOP_RIGHT;
|
||||||
|
|
||||||
if (buffer->get_voxel(x, y + 1, z + 1, VoxelChunk::DEFAULT_CHANNEL_TYPE) != 0)
|
if (chunk->get_voxel(x, y + 1, z + 1, VoxelChunk::DEFAULT_CHANNEL_TYPE) != 0)
|
||||||
neighbours = neighbours | VOXEL_NEIGHBOUR_TOP_BACK;
|
neighbours = neighbours | VOXEL_NEIGHBOUR_TOP_BACK;
|
||||||
|
|
||||||
if (buffer->get_voxel(x + 1, y + 1, z + 1, VoxelChunk::DEFAULT_CHANNEL_TYPE) != 0)
|
if (chunk->get_voxel(x + 1, y + 1, z + 1, VoxelChunk::DEFAULT_CHANNEL_TYPE) != 0)
|
||||||
neighbours = neighbours | VOXEL_NEIGHBOUR_TOP_RIGHT_BACK;*/
|
neighbours = neighbours | VOXEL_NEIGHBOUR_TOP_RIGHT_BACK;*/
|
||||||
|
|
||||||
_point_neighbours[P111] = neighbours;
|
_point_neighbours[P111] = neighbours;
|
||||||
}
|
}
|
||||||
|
|
||||||
void VoxelCubePoints::setup(const VoxelChunk *buffer, int x, int y, int z, int size) {
|
void VoxelCubePoints::setup(const VoxelChunk *chunk, int x, int y, int z, int size) {
|
||||||
ERR_FAIL_COND(size <= 0);
|
ERR_FAIL_COND(size <= 0);
|
||||||
ERR_FAIL_COND(!buffer->validate_pos(x + size, y + size, z + size) || !buffer->validate_pos(x, y, z));
|
ERR_FAIL_COND(!chunk->validate_channel_position(x + size, y + size, z + size) || !chunk->validate_channel_position(x, y, z));
|
||||||
|
|
||||||
reset();
|
reset();
|
||||||
|
|
||||||
@ -416,46 +416,46 @@ void VoxelCubePoints::setup(const VoxelChunk *buffer, int x, int y, int z, int s
|
|||||||
_z = z;
|
_z = z;
|
||||||
_size = size;
|
_size = size;
|
||||||
|
|
||||||
_point_types[P000] = buffer->get_voxel(x, y, z, VoxelChunk::DEFAULT_CHANNEL_TYPE);
|
_point_types[P000] = chunk->get_voxel(x, y, z, VoxelChunk::DEFAULT_CHANNEL_TYPE);
|
||||||
_point_types[P100] = buffer->get_voxel(x + size, y, z, VoxelChunk::DEFAULT_CHANNEL_TYPE);
|
_point_types[P100] = chunk->get_voxel(x + size, y, z, VoxelChunk::DEFAULT_CHANNEL_TYPE);
|
||||||
_point_types[P010] = buffer->get_voxel(x, y + size, z, VoxelChunk::DEFAULT_CHANNEL_TYPE);
|
_point_types[P010] = chunk->get_voxel(x, y + size, z, VoxelChunk::DEFAULT_CHANNEL_TYPE);
|
||||||
_point_types[P001] = buffer->get_voxel(x, y, z + size, VoxelChunk::DEFAULT_CHANNEL_TYPE);
|
_point_types[P001] = chunk->get_voxel(x, y, z + size, VoxelChunk::DEFAULT_CHANNEL_TYPE);
|
||||||
_point_types[P110] = buffer->get_voxel(x + size, y + size, z, VoxelChunk::DEFAULT_CHANNEL_TYPE);
|
_point_types[P110] = chunk->get_voxel(x + size, y + size, z, VoxelChunk::DEFAULT_CHANNEL_TYPE);
|
||||||
_point_types[P011] = buffer->get_voxel(x, y + size, z + size, VoxelChunk::DEFAULT_CHANNEL_TYPE);
|
_point_types[P011] = chunk->get_voxel(x, y + size, z + size, VoxelChunk::DEFAULT_CHANNEL_TYPE);
|
||||||
_point_types[P101] = buffer->get_voxel(x + size, y, z + size, VoxelChunk::DEFAULT_CHANNEL_TYPE);
|
_point_types[P101] = chunk->get_voxel(x + size, y, z + size, VoxelChunk::DEFAULT_CHANNEL_TYPE);
|
||||||
_point_types[P111] = buffer->get_voxel(x + size, y + size, z + size, VoxelChunk::DEFAULT_CHANNEL_TYPE);
|
_point_types[P111] = chunk->get_voxel(x + size, y + size, z + size, VoxelChunk::DEFAULT_CHANNEL_TYPE);
|
||||||
|
|
||||||
if (!has_points())
|
if (!has_points())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
_point_fills[P000] = buffer->get_voxel(x, y, z, VoxelChunk::DEFAULT_CHANNEL_ISOLEVEL);
|
_point_fills[P000] = chunk->get_voxel(x, y, z, VoxelChunk::DEFAULT_CHANNEL_ISOLEVEL);
|
||||||
_point_fills[P100] = buffer->get_voxel(x + size, y, z, VoxelChunk::DEFAULT_CHANNEL_ISOLEVEL);
|
_point_fills[P100] = chunk->get_voxel(x + size, y, z, VoxelChunk::DEFAULT_CHANNEL_ISOLEVEL);
|
||||||
_point_fills[P010] = buffer->get_voxel(x, y + size, z, VoxelChunk::DEFAULT_CHANNEL_ISOLEVEL);
|
_point_fills[P010] = chunk->get_voxel(x, y + size, z, VoxelChunk::DEFAULT_CHANNEL_ISOLEVEL);
|
||||||
_point_fills[P001] = buffer->get_voxel(x, y, z + size, VoxelChunk::DEFAULT_CHANNEL_ISOLEVEL);
|
_point_fills[P001] = chunk->get_voxel(x, y, z + size, VoxelChunk::DEFAULT_CHANNEL_ISOLEVEL);
|
||||||
_point_fills[P110] = buffer->get_voxel(x + size, y + size, z, VoxelChunk::DEFAULT_CHANNEL_ISOLEVEL);
|
_point_fills[P110] = chunk->get_voxel(x + size, y + size, z, VoxelChunk::DEFAULT_CHANNEL_ISOLEVEL);
|
||||||
_point_fills[P011] = buffer->get_voxel(x, y + size, z + size, VoxelChunk::DEFAULT_CHANNEL_ISOLEVEL);
|
_point_fills[P011] = chunk->get_voxel(x, y + size, z + size, VoxelChunk::DEFAULT_CHANNEL_ISOLEVEL);
|
||||||
_point_fills[P101] = buffer->get_voxel(x + size, y, z + size, VoxelChunk::DEFAULT_CHANNEL_ISOLEVEL);
|
_point_fills[P101] = chunk->get_voxel(x + size, y, z + size, VoxelChunk::DEFAULT_CHANNEL_ISOLEVEL);
|
||||||
_point_fills[P111] = buffer->get_voxel(x + size, y + size, z + size, VoxelChunk::DEFAULT_CHANNEL_ISOLEVEL);
|
_point_fills[P111] = chunk->get_voxel(x + size, y + size, z + size, VoxelChunk::DEFAULT_CHANNEL_ISOLEVEL);
|
||||||
|
|
||||||
_point_aos[P000] = buffer->get_voxel(x, y, z, VoxelChunk::DEFAULT_CHANNEL_AO);
|
_point_aos[P000] = chunk->get_voxel(x, y, z, VoxelChunk::DEFAULT_CHANNEL_AO);
|
||||||
_point_aos[P100] = buffer->get_voxel(x + size, y, z, VoxelChunk::DEFAULT_CHANNEL_AO);
|
_point_aos[P100] = chunk->get_voxel(x + size, y, z, VoxelChunk::DEFAULT_CHANNEL_AO);
|
||||||
_point_aos[P010] = buffer->get_voxel(x, y + size, z, VoxelChunk::DEFAULT_CHANNEL_AO);
|
_point_aos[P010] = chunk->get_voxel(x, y + size, z, VoxelChunk::DEFAULT_CHANNEL_AO);
|
||||||
_point_aos[P001] = buffer->get_voxel(x, y, z + size, VoxelChunk::DEFAULT_CHANNEL_AO);
|
_point_aos[P001] = chunk->get_voxel(x, y, z + size, VoxelChunk::DEFAULT_CHANNEL_AO);
|
||||||
_point_aos[P110] = buffer->get_voxel(x + size, y + size, z, VoxelChunk::DEFAULT_CHANNEL_AO);
|
_point_aos[P110] = chunk->get_voxel(x + size, y + size, z, VoxelChunk::DEFAULT_CHANNEL_AO);
|
||||||
_point_aos[P011] = buffer->get_voxel(x, y + size, z + size, VoxelChunk::DEFAULT_CHANNEL_AO);
|
_point_aos[P011] = chunk->get_voxel(x, y + size, z + size, VoxelChunk::DEFAULT_CHANNEL_AO);
|
||||||
_point_aos[P101] = buffer->get_voxel(x + size, y, z + size, VoxelChunk::DEFAULT_CHANNEL_AO);
|
_point_aos[P101] = chunk->get_voxel(x + size, y, z + size, VoxelChunk::DEFAULT_CHANNEL_AO);
|
||||||
_point_aos[P111] = buffer->get_voxel(x + size, y + size, z + size, VoxelChunk::DEFAULT_CHANNEL_AO);
|
_point_aos[P111] = chunk->get_voxel(x + size, y + size, z + size, VoxelChunk::DEFAULT_CHANNEL_AO);
|
||||||
|
|
||||||
_point_colors[P000] = Color(buffer->get_voxel(x, y, z, VoxelChunk::DEFAULT_CHANNEL_LIGHT_COLOR_R) / 255.0, buffer->get_voxel(x, y, z, VoxelChunk::DEFAULT_CHANNEL_LIGHT_COLOR_G) / 255.0, buffer->get_voxel(x, y, z, VoxelChunk::DEFAULT_CHANNEL_LIGHT_COLOR_B) / 255.0);
|
_point_colors[P000] = Color(chunk->get_voxel(x, y, z, VoxelChunk::DEFAULT_CHANNEL_LIGHT_COLOR_R) / 255.0, chunk->get_voxel(x, y, z, VoxelChunk::DEFAULT_CHANNEL_LIGHT_COLOR_G) / 255.0, chunk->get_voxel(x, y, z, VoxelChunk::DEFAULT_CHANNEL_LIGHT_COLOR_B) / 255.0);
|
||||||
_point_colors[P100] = Color(buffer->get_voxel(x + size, y, z, VoxelChunk::DEFAULT_CHANNEL_LIGHT_COLOR_R) / 255.0, buffer->get_voxel(x + size, y, z, VoxelChunk::DEFAULT_CHANNEL_LIGHT_COLOR_G) / 255.0, buffer->get_voxel(x + size, y, z, VoxelChunk::DEFAULT_CHANNEL_LIGHT_COLOR_B) / 255.0);
|
_point_colors[P100] = Color(chunk->get_voxel(x + size, y, z, VoxelChunk::DEFAULT_CHANNEL_LIGHT_COLOR_R) / 255.0, chunk->get_voxel(x + size, y, z, VoxelChunk::DEFAULT_CHANNEL_LIGHT_COLOR_G) / 255.0, chunk->get_voxel(x + size, y, z, VoxelChunk::DEFAULT_CHANNEL_LIGHT_COLOR_B) / 255.0);
|
||||||
_point_colors[P010] = Color(buffer->get_voxel(x, y + size, z, VoxelChunk::DEFAULT_CHANNEL_LIGHT_COLOR_R) / 255.0, buffer->get_voxel(x, y + size, z, VoxelChunk::DEFAULT_CHANNEL_LIGHT_COLOR_G) / 255.0, buffer->get_voxel(x, y + size, z, VoxelChunk::DEFAULT_CHANNEL_LIGHT_COLOR_B) / 255.0);
|
_point_colors[P010] = Color(chunk->get_voxel(x, y + size, z, VoxelChunk::DEFAULT_CHANNEL_LIGHT_COLOR_R) / 255.0, chunk->get_voxel(x, y + size, z, VoxelChunk::DEFAULT_CHANNEL_LIGHT_COLOR_G) / 255.0, chunk->get_voxel(x, y + size, z, VoxelChunk::DEFAULT_CHANNEL_LIGHT_COLOR_B) / 255.0);
|
||||||
_point_colors[P001] = Color(buffer->get_voxel(x, y, z + size, VoxelChunk::DEFAULT_CHANNEL_LIGHT_COLOR_R) / 255.0, buffer->get_voxel(x, y, z + size, VoxelChunk::DEFAULT_CHANNEL_LIGHT_COLOR_G) / 255.0, buffer->get_voxel(x, y, z + size, VoxelChunk::DEFAULT_CHANNEL_LIGHT_COLOR_B) / 255.0);
|
_point_colors[P001] = Color(chunk->get_voxel(x, y, z + size, VoxelChunk::DEFAULT_CHANNEL_LIGHT_COLOR_R) / 255.0, chunk->get_voxel(x, y, z + size, VoxelChunk::DEFAULT_CHANNEL_LIGHT_COLOR_G) / 255.0, chunk->get_voxel(x, y, z + size, VoxelChunk::DEFAULT_CHANNEL_LIGHT_COLOR_B) / 255.0);
|
||||||
_point_colors[P110] = Color(buffer->get_voxel(x + size, y + size, z, VoxelChunk::DEFAULT_CHANNEL_LIGHT_COLOR_R) / 255.0, buffer->get_voxel(x + size, y + size, z, VoxelChunk::DEFAULT_CHANNEL_LIGHT_COLOR_G) / 255.0, buffer->get_voxel(x + size, y + size, z, VoxelChunk::DEFAULT_CHANNEL_LIGHT_COLOR_B) / 255.0);
|
_point_colors[P110] = Color(chunk->get_voxel(x + size, y + size, z, VoxelChunk::DEFAULT_CHANNEL_LIGHT_COLOR_R) / 255.0, chunk->get_voxel(x + size, y + size, z, VoxelChunk::DEFAULT_CHANNEL_LIGHT_COLOR_G) / 255.0, chunk->get_voxel(x + size, y + size, z, VoxelChunk::DEFAULT_CHANNEL_LIGHT_COLOR_B) / 255.0);
|
||||||
_point_colors[P011] = Color(buffer->get_voxel(x, y + size, z + size, VoxelChunk::DEFAULT_CHANNEL_LIGHT_COLOR_R) / 255.0, buffer->get_voxel(x, y + size, z + size, VoxelChunk::DEFAULT_CHANNEL_LIGHT_COLOR_G) / 255.0, buffer->get_voxel(x, y + size, z + size, VoxelChunk::DEFAULT_CHANNEL_LIGHT_COLOR_B) / 255.0);
|
_point_colors[P011] = Color(chunk->get_voxel(x, y + size, z + size, VoxelChunk::DEFAULT_CHANNEL_LIGHT_COLOR_R) / 255.0, chunk->get_voxel(x, y + size, z + size, VoxelChunk::DEFAULT_CHANNEL_LIGHT_COLOR_G) / 255.0, chunk->get_voxel(x, y + size, z + size, VoxelChunk::DEFAULT_CHANNEL_LIGHT_COLOR_B) / 255.0);
|
||||||
_point_colors[P101] = Color(buffer->get_voxel(x + size, y, z + size, VoxelChunk::DEFAULT_CHANNEL_LIGHT_COLOR_R) / 255.0, buffer->get_voxel(x + size, y, z + size, VoxelChunk::DEFAULT_CHANNEL_LIGHT_COLOR_G) / 255.0, buffer->get_voxel(x + size, y, z + size, VoxelChunk::DEFAULT_CHANNEL_LIGHT_COLOR_B) / 255.0);
|
_point_colors[P101] = Color(chunk->get_voxel(x + size, y, z + size, VoxelChunk::DEFAULT_CHANNEL_LIGHT_COLOR_R) / 255.0, chunk->get_voxel(x + size, y, z + size, VoxelChunk::DEFAULT_CHANNEL_LIGHT_COLOR_G) / 255.0, chunk->get_voxel(x + size, y, z + size, VoxelChunk::DEFAULT_CHANNEL_LIGHT_COLOR_B) / 255.0);
|
||||||
_point_colors[P111] = Color(buffer->get_voxel(x + size, y + size, z + size, VoxelChunk::DEFAULT_CHANNEL_LIGHT_COLOR_R) / 255.0, buffer->get_voxel(x + size, y + size, z + size, VoxelChunk::DEFAULT_CHANNEL_LIGHT_COLOR_G) / 255.0, buffer->get_voxel(x + size, y + size, z + size, VoxelChunk::DEFAULT_CHANNEL_LIGHT_COLOR_B) / 255.0);
|
_point_colors[P111] = Color(chunk->get_voxel(x + size, y + size, z + size, VoxelChunk::DEFAULT_CHANNEL_LIGHT_COLOR_R) / 255.0, chunk->get_voxel(x + size, y + size, z + size, VoxelChunk::DEFAULT_CHANNEL_LIGHT_COLOR_G) / 255.0, chunk->get_voxel(x + size, y + size, z + size, VoxelChunk::DEFAULT_CHANNEL_LIGHT_COLOR_B) / 255.0);
|
||||||
|
|
||||||
refresh_neighbours(buffer);
|
refresh_neighbours(chunk);
|
||||||
|
|
||||||
refresh_points();
|
refresh_points();
|
||||||
}
|
}
|
||||||
@ -508,16 +508,6 @@ bool VoxelCubePoints::is_face_visible(int face) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool VoxelCubePoints::is_sub_voxel_point(int x, int y, int z) {
|
bool VoxelCubePoints::is_sub_voxel_point(int x, int y, int z) {
|
||||||
for (int i = 0; i < POINT_COUNT; i += 1) {
|
for (int i = 0; i < POINT_COUNT; i += 1) {
|
||||||
if (get_point(i) == Vector3(x, y, z)) {
|
if (get_point(i) == Vector3(x, y, z)) {
|
||||||
@ -531,21 +521,12 @@ void VoxelCubePoints::set_point(int point, int x, int y, int z) {
|
|||||||
_points[point] = Vector3(x, y, z);
|
_points[point] = Vector3(x, y, z);
|
||||||
}
|
}
|
||||||
|
|
||||||
int VoxelCubePoints::get_point_id_vec(Vector3 point) {
|
|
||||||
for (int i = 0; i < POINT_COUNT; ++i) {
|
|
||||||
if (get_point(i) == point) {
|
|
||||||
return i;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int VoxelCubePoints::get_point_id(int x, int y, int z) {
|
int VoxelCubePoints::get_point_id(int x, int y, int z) {
|
||||||
for (int i = 0; i < POINT_COUNT; ++i) {
|
//for (int i = 0; i < POINT_COUNT; ++i) {
|
||||||
if (get_point(i) == Vector3i(x, y, z)) {
|
// if (get_point(i) == Vector3i(x, y, z)) {
|
||||||
return i;
|
// return i;
|
||||||
}
|
// }
|
||||||
}
|
//}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -776,7 +757,7 @@ void VoxelCubePoints::_bind_methods() {
|
|||||||
ADD_PROPERTY(PropertyInfo(Variant::INT, "size"), "set_size", "get_size");
|
ADD_PROPERTY(PropertyInfo(Variant::INT, "size"), "set_size", "get_size");
|
||||||
|
|
||||||
ClassDB::bind_method(D_METHOD("refresh_points"), &VoxelCubePoints::refresh_points);
|
ClassDB::bind_method(D_METHOD("refresh_points"), &VoxelCubePoints::refresh_points);
|
||||||
ClassDB::bind_method(D_METHOD("setup", "buffer", "x", "y", "z", "size"), &VoxelCubePoints::setup, DEFVAL(1));
|
ClassDB::bind_method(D_METHOD("setup", "chunk", "x", "y", "z", "size"), &VoxelCubePoints::setup, DEFVAL(1));
|
||||||
|
|
||||||
ClassDB::bind_method(D_METHOD("get_point_index", "face", "index"), &VoxelCubePoints::get_point_index);
|
ClassDB::bind_method(D_METHOD("get_point_index", "face", "index"), &VoxelCubePoints::get_point_index);
|
||||||
ClassDB::bind_method(D_METHOD("get_point_uv_direction", "face", "index"), &VoxelCubePoints::get_point_uv_direction);
|
ClassDB::bind_method(D_METHOD("get_point_uv_direction", "face", "index"), &VoxelCubePoints::get_point_uv_direction);
|
||||||
|
@ -301,14 +301,14 @@ void VoxelMesher::_bake_colors(VoxelChunk *chunk) {
|
|||||||
unsigned int y = (unsigned int)(vert.y / _voxel_scale);
|
unsigned int y = (unsigned int)(vert.y / _voxel_scale);
|
||||||
unsigned int z = (unsigned int)(vert.z / _voxel_scale);
|
unsigned int z = (unsigned int)(vert.z / _voxel_scale);
|
||||||
|
|
||||||
if (chunk->validate_pos(x, y, z)) {
|
if (chunk->validate_channel_position(x, y, z)) {
|
||||||
Color light = Color(
|
Color light = Color(
|
||||||
chunk->get_voxel(x, y, z, VoxelChunk::CHANNEL_LIGHT_COLOR_R) / 255.0,
|
chunk->get_voxel(x, y, z, VoxelChunk::DEFAULT_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::DEFAULT_CHANNEL_LIGHT_COLOR_G) / 255.0,
|
||||||
chunk->get_voxel(x, y, z, VoxelChunk::CHANNEL_LIGHT_COLOR_B) / 255.0);
|
chunk->get_voxel(x, y, z, VoxelChunk::DEFAULT_CHANNEL_LIGHT_COLOR_B) / 255.0);
|
||||||
|
|
||||||
float ao = (chunk->get_voxel(x, y, z, VoxelChunk::CHANNEL_AO) / 255.0) * _ao_strength;
|
float ao = (chunk->get_voxel(x, y, z, VoxelChunk::DEFAULT_CHANNEL_AO) / 255.0) * _ao_strength;
|
||||||
float rao = chunk->get_voxel(x, y, z, VoxelChunk::CHANNEL_RANDOM_AO) / 255.0;
|
float rao = chunk->get_voxel(x, y, z, VoxelChunk::DEFAULT_CHANNEL_RANDOM_AO) / 255.0;
|
||||||
ao += rao;
|
ao += rao;
|
||||||
|
|
||||||
light.r += _base_light_value;
|
light.r += _base_light_value;
|
||||||
@ -367,14 +367,14 @@ void VoxelMesher::_bake_liquid_colors(VoxelChunk *chunk) {
|
|||||||
unsigned int y = (unsigned int)(vert.y / _voxel_scale);
|
unsigned int y = (unsigned int)(vert.y / _voxel_scale);
|
||||||
unsigned int z = (unsigned int)(vert.z / _voxel_scale);
|
unsigned int z = (unsigned int)(vert.z / _voxel_scale);
|
||||||
|
|
||||||
if (chunk->validate_pos(x, y, z)) {
|
if (chunk->validate_channel_position(x, y, z)) {
|
||||||
Color light = Color(
|
Color light = Color(
|
||||||
chunk->get_voxel(x, y, z, VoxelChunk::CHANNEL_LIGHT_COLOR_R) / 255.0,
|
chunk->get_voxel(x, y, z, VoxelChunk::DEFAULT_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::DEFAULT_CHANNEL_LIGHT_COLOR_G) / 255.0,
|
||||||
chunk->get_voxel(x, y, z, VoxelChunk::CHANNEL_LIGHT_COLOR_B) / 255.0);
|
chunk->get_voxel(x, y, z, VoxelChunk::DEFAULT_CHANNEL_LIGHT_COLOR_B) / 255.0);
|
||||||
|
|
||||||
float ao = (chunk->get_voxel(x, y, z, VoxelChunk::CHANNEL_AO) / 255.0) * _ao_strength;
|
float ao = (chunk->get_voxel(x, y, z, VoxelChunk::DEFAULT_CHANNEL_AO) / 255.0) * _ao_strength;
|
||||||
float rao = chunk->get_voxel(x, y, z, VoxelChunk::CHANNEL_RANDOM_AO) / 255.0;
|
float rao = chunk->get_voxel(x, y, z, VoxelChunk::DEFAULT_CHANNEL_RANDOM_AO) / 255.0;
|
||||||
ao += rao;
|
ao += rao;
|
||||||
|
|
||||||
light.r += _base_light_value;
|
light.r += _base_light_value;
|
||||||
|
@ -1,149 +0,0 @@
|
|||||||
#include "marching_cubes_voxel_query.h"
|
|
||||||
|
|
||||||
const String MarchingCubesVoxelQuery::BINDING_STRING_VOXEL_ENTRY_INDICES = "Index_000, Index_100, Index_010, Index_110, Index_001, Index_101, Index_011, Index_111";
|
|
||||||
const String MarchingCubesVoxelQuery::BINDING_STRING_VOXEL_ENTRY_MASK = "Index_000, Index_100, Index_010, Index_110, Index_001, Index_101, Index_011, Index_111";
|
|
||||||
|
|
||||||
Ref<Voxel> MarchingCubesVoxelQuery::get_entry(int index) {
|
|
||||||
return _voxels[index];
|
|
||||||
}
|
|
||||||
void MarchingCubesVoxelQuery::set_entry(int index, Ref<Voxel> voxel) {
|
|
||||||
_voxels[index] = voxel;
|
|
||||||
}
|
|
||||||
|
|
||||||
int MarchingCubesVoxelQuery::get_size() {
|
|
||||||
return _size;
|
|
||||||
}
|
|
||||||
void MarchingCubesVoxelQuery::set_size(int size) {
|
|
||||||
_size = size;
|
|
||||||
}
|
|
||||||
|
|
||||||
Vector3i MarchingCubesVoxelQuery::get_position() {
|
|
||||||
return _position;
|
|
||||||
}
|
|
||||||
void MarchingCubesVoxelQuery::set_position(Vector3i position) {
|
|
||||||
_position = position;
|
|
||||||
}
|
|
||||||
|
|
||||||
Vector3 MarchingCubesVoxelQuery::get_position_bind() {
|
|
||||||
return _position.to_vec3();
|
|
||||||
}
|
|
||||||
void MarchingCubesVoxelQuery::set_position_bind(Vector3 position) {
|
|
||||||
_position = position;
|
|
||||||
}
|
|
||||||
|
|
||||||
int MarchingCubesVoxelQuery::get_case_code() {
|
|
||||||
return _case_code;
|
|
||||||
}
|
|
||||||
|
|
||||||
void MarchingCubesVoxelQuery::update_case_code() {
|
|
||||||
int entry_mask = 0;
|
|
||||||
|
|
||||||
if (_voxels[VOXEL_ENTRY_INDEX_000].is_valid()) {
|
|
||||||
entry_mask = entry_mask | VOXEL_ENTRY_MASK_000;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (_voxels[VOXEL_ENTRY_INDEX_100].is_valid()) {
|
|
||||||
entry_mask = entry_mask | VOXEL_ENTRY_MASK_100;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (_voxels[VOXEL_ENTRY_INDEX_010].is_valid()) {
|
|
||||||
entry_mask = entry_mask | VOXEL_ENTRY_MASK_010;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (_voxels[VOXEL_ENTRY_INDEX_110].is_valid()) {
|
|
||||||
entry_mask = entry_mask | VOXEL_ENTRY_MASK_110;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (_voxels[VOXEL_ENTRY_INDEX_001].is_valid()) {
|
|
||||||
entry_mask = entry_mask | VOXEL_ENTRY_MASK_001;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (_voxels[VOXEL_ENTRY_INDEX_101].is_valid()) {
|
|
||||||
entry_mask = entry_mask | VOXEL_ENTRY_MASK_101;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (_voxels[VOXEL_ENTRY_INDEX_011].is_valid()) {
|
|
||||||
entry_mask = entry_mask | VOXEL_ENTRY_MASK_011;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (_voxels[VOXEL_ENTRY_INDEX_111].is_valid()) {
|
|
||||||
entry_mask = entry_mask | VOXEL_ENTRY_MASK_111;
|
|
||||||
}
|
|
||||||
|
|
||||||
_case_code = entry_mask;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool MarchingCubesVoxelQuery::is_triangulation_trivial() {
|
|
||||||
int corner = 0;
|
|
||||||
|
|
||||||
if (_voxels[VOXEL_ENTRY_INDEX_111].is_valid()) {
|
|
||||||
corner = 0xFF;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((_case_code ^ corner) != 0) {
|
|
||||||
// Cell has a nontrivial triangulation.
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void MarchingCubesVoxelQuery::set_entries(Ref<Voxel> voxel000, Ref<Voxel> voxel100, Ref<Voxel> voxel010, Ref<Voxel> voxel110, Ref<Voxel> voxel001,
|
|
||||||
Ref<Voxel> voxel101, Ref<Voxel> voxel011, Ref<Voxel> voxel111) {
|
|
||||||
_voxels[VOXEL_ENTRY_INDEX_000] = voxel000;
|
|
||||||
_voxels[VOXEL_ENTRY_INDEX_100] = voxel100;
|
|
||||||
_voxels[VOXEL_ENTRY_INDEX_010] = voxel010;
|
|
||||||
_voxels[VOXEL_ENTRY_INDEX_110] = voxel110;
|
|
||||||
_voxels[VOXEL_ENTRY_INDEX_001] = voxel001;
|
|
||||||
_voxels[VOXEL_ENTRY_INDEX_101] = voxel101;
|
|
||||||
_voxels[VOXEL_ENTRY_INDEX_011] = voxel011;
|
|
||||||
_voxels[VOXEL_ENTRY_INDEX_111] = voxel111;
|
|
||||||
|
|
||||||
update_case_code();
|
|
||||||
}
|
|
||||||
|
|
||||||
MarchingCubesVoxelQuery::MarchingCubesVoxelQuery() {
|
|
||||||
_size = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
MarchingCubesVoxelQuery::~MarchingCubesVoxelQuery() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void MarchingCubesVoxelQuery::_bind_methods() {
|
|
||||||
ClassDB::bind_method(D_METHOD("get_entry", "index"), &MarchingCubesVoxelQuery::get_entry);
|
|
||||||
ClassDB::bind_method(D_METHOD("set_entry", "index", "voxel"), &MarchingCubesVoxelQuery::set_entry);
|
|
||||||
|
|
||||||
ClassDB::bind_method(D_METHOD("get_size"), &MarchingCubesVoxelQuery::get_size);
|
|
||||||
ClassDB::bind_method(D_METHOD("set_size", "size"), &MarchingCubesVoxelQuery::set_size);
|
|
||||||
ADD_PROPERTY(PropertyInfo(Variant::INT, "size"), "set_size", "get_size");
|
|
||||||
|
|
||||||
ClassDB::bind_method(D_METHOD("get_position"), &MarchingCubesVoxelQuery::get_position_bind);
|
|
||||||
ClassDB::bind_method(D_METHOD("set_position", "spositionize"), &MarchingCubesVoxelQuery::set_position_bind);
|
|
||||||
ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "position"), "set_position", "get_position");
|
|
||||||
|
|
||||||
ClassDB::bind_method(D_METHOD("get_case_code"), &MarchingCubesVoxelQuery::get_case_code);
|
|
||||||
ClassDB::bind_method(D_METHOD("update_case_code"), &MarchingCubesVoxelQuery::update_case_code);
|
|
||||||
ClassDB::bind_method(D_METHOD("is_triangulation_trivial"), &MarchingCubesVoxelQuery::is_triangulation_trivial);
|
|
||||||
|
|
||||||
BIND_ENUM_CONSTANT(VOXEL_ENTRY_INDEX_000);
|
|
||||||
BIND_ENUM_CONSTANT(VOXEL_ENTRY_INDEX_100);
|
|
||||||
BIND_ENUM_CONSTANT(VOXEL_ENTRY_INDEX_010);
|
|
||||||
BIND_ENUM_CONSTANT(VOXEL_ENTRY_INDEX_110);
|
|
||||||
BIND_ENUM_CONSTANT(VOXEL_ENTRY_INDEX_001);
|
|
||||||
BIND_ENUM_CONSTANT(VOXEL_ENTRY_INDEX_101);
|
|
||||||
BIND_ENUM_CONSTANT(VOXEL_ENTRY_INDEX_011);
|
|
||||||
BIND_ENUM_CONSTANT(VOXEL_ENTRY_INDEX_111);
|
|
||||||
|
|
||||||
BIND_ENUM_CONSTANT(VOXEL_ENTRIES_SIZE);
|
|
||||||
|
|
||||||
BIND_ENUM_CONSTANT(VOXEL_ENTRY_MASK_000);
|
|
||||||
BIND_ENUM_CONSTANT(VOXEL_ENTRY_MASK_100);
|
|
||||||
BIND_ENUM_CONSTANT(VOXEL_ENTRY_MASK_010);
|
|
||||||
BIND_ENUM_CONSTANT(VOXEL_ENTRY_MASK_110);
|
|
||||||
BIND_ENUM_CONSTANT(VOXEL_ENTRY_MASK_001);
|
|
||||||
BIND_ENUM_CONSTANT(VOXEL_ENTRY_MASK_101);
|
|
||||||
BIND_ENUM_CONSTANT(VOXEL_ENTRY_MASK_011);
|
|
||||||
BIND_ENUM_CONSTANT(VOXEL_ENTRY_MASK_111);
|
|
||||||
|
|
||||||
}
|
|
@ -1,75 +0,0 @@
|
|||||||
#ifndef MARCHING_CUBES_VOXEL_QUERY_H
|
|
||||||
#define MARCHING_CUBES_VOXEL_QUERY_H
|
|
||||||
|
|
||||||
#include "core/reference.h"
|
|
||||||
|
|
||||||
#include "../data/voxel.h"
|
|
||||||
|
|
||||||
class MarchingCubesVoxelQuery : public Reference {
|
|
||||||
GDCLASS(MarchingCubesVoxelQuery, Reference);
|
|
||||||
|
|
||||||
public:
|
|
||||||
static const String BINDING_STRING_VOXEL_ENTRY_INDICES;
|
|
||||||
static const String BINDING_STRING_VOXEL_ENTRY_MASK;
|
|
||||||
|
|
||||||
enum VoxelEntryIndices {
|
|
||||||
VOXEL_ENTRY_INDEX_000 = 0,
|
|
||||||
VOXEL_ENTRY_INDEX_100 = 1,
|
|
||||||
VOXEL_ENTRY_INDEX_001 = 2,
|
|
||||||
VOXEL_ENTRY_INDEX_101 = 3,
|
|
||||||
|
|
||||||
VOXEL_ENTRY_INDEX_010 = 4,
|
|
||||||
VOXEL_ENTRY_INDEX_110 = 5,
|
|
||||||
VOXEL_ENTRY_INDEX_011 = 6,
|
|
||||||
VOXEL_ENTRY_INDEX_111 = 7,
|
|
||||||
|
|
||||||
VOXEL_ENTRIES_SIZE = 8,
|
|
||||||
};
|
|
||||||
|
|
||||||
enum VoxelEntryMask {
|
|
||||||
VOXEL_ENTRY_MASK_000 = 1 << 0,
|
|
||||||
VOXEL_ENTRY_MASK_100 = 1 << 1,
|
|
||||||
VOXEL_ENTRY_MASK_001 = 1 << 2,
|
|
||||||
VOXEL_ENTRY_MASK_101 = 1 << 3,
|
|
||||||
|
|
||||||
VOXEL_ENTRY_MASK_010 = 1 << 4,
|
|
||||||
VOXEL_ENTRY_MASK_110 = 1 << 5,
|
|
||||||
VOXEL_ENTRY_MASK_011 = 1 << 6,
|
|
||||||
VOXEL_ENTRY_MASK_111 = 1 << 7,
|
|
||||||
};
|
|
||||||
|
|
||||||
Ref<Voxel> get_entry(int index);
|
|
||||||
void set_entry(int index, Ref<Voxel> voxel);
|
|
||||||
|
|
||||||
int get_size();
|
|
||||||
void set_size(int size);
|
|
||||||
|
|
||||||
Vector3i get_position();
|
|
||||||
void set_position(Vector3i position);
|
|
||||||
|
|
||||||
Vector3 get_position_bind();
|
|
||||||
void set_position_bind(Vector3 position);
|
|
||||||
|
|
||||||
int get_case_code();
|
|
||||||
void update_case_code();
|
|
||||||
bool is_triangulation_trivial();
|
|
||||||
|
|
||||||
void set_entries(Ref<Voxel> voxel000, Ref<Voxel> voxel100, Ref<Voxel> voxel010, Ref<Voxel> voxel110, Ref<Voxel> voxel001, Ref<Voxel> voxel101, Ref<Voxel> voxel011, Ref<Voxel> voxel111);
|
|
||||||
|
|
||||||
MarchingCubesVoxelQuery();
|
|
||||||
~MarchingCubesVoxelQuery();
|
|
||||||
|
|
||||||
protected:
|
|
||||||
static void _bind_methods();
|
|
||||||
|
|
||||||
private:
|
|
||||||
int _case_code;
|
|
||||||
int _size;
|
|
||||||
Vector3i _position;
|
|
||||||
Ref<Voxel> _voxels[VOXEL_ENTRIES_SIZE];
|
|
||||||
};
|
|
||||||
|
|
||||||
VARIANT_ENUM_CAST(MarchingCubesVoxelQuery::VoxelEntryIndices);
|
|
||||||
VARIANT_ENUM_CAST(MarchingCubesVoxelQuery::VoxelEntryMask);
|
|
||||||
|
|
||||||
#endif
|
|
@ -181,17 +181,15 @@ RID VoxelChunk::get_clutter_mesh_instance_rid() {
|
|||||||
void VoxelChunk::set_size(int size_x, int size_y, int siye_z, int margin_start = 0, int margin_end = 0) {
|
void VoxelChunk::set_size(int size_x, int size_y, int siye_z, int margin_start = 0, int margin_end = 0) {
|
||||||
|
|
||||||
}
|
}
|
||||||
void VoxelChunk::set_channel_count(int value) {
|
|
||||||
|
|
||||||
}
|
_FORCE_INLINE_ bool VoxelChunk::validate_channel_position(int x, int y, int z) const {
|
||||||
void VoxelChunk::validate_channel_index(int x, int y, int z, int channel_index) {
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t VoxelChunk::get_voxel(int x, int y, int z, int channel_index) {
|
_FORCE_INLINE_ uint8_t VoxelChunk::get_voxel(int x, int y, int z, int channel_index) const {
|
||||||
|
|
||||||
}
|
}
|
||||||
void VoxelChunk::set_voxel(uint8_t value, int x, int y, int z, int channel_index) {
|
_FORCE_INLINE_ void VoxelChunk::set_voxel(uint8_t value, int x, int y, int z, int channel_index) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -201,7 +199,7 @@ void VoxelChunk::set_channel_count(int count) {
|
|||||||
void VoxelChunk::allocate_channel(int channel_index, uint8_t value = 0) {
|
void VoxelChunk::allocate_channel(int channel_index, uint8_t value = 0) {
|
||||||
|
|
||||||
}
|
}
|
||||||
void VoxelChunk::fill_channel(int channel_index) {
|
void VoxelChunk::fill_channel(uint8_t value, int channel_index) {
|
||||||
|
|
||||||
}
|
}
|
||||||
void VoxelChunk::dealloc_channel(int channel_index) {
|
void VoxelChunk::dealloc_channel(int channel_index) {
|
||||||
@ -217,23 +215,23 @@ uint8_t *VoxelChunk::get_valid_channel(int channel_index) {
|
|||||||
|
|
||||||
//Data Management functions
|
//Data Management functions
|
||||||
void VoxelChunk::generate_ao() {
|
void VoxelChunk::generate_ao() {
|
||||||
unsigned int size_x = _actual_size_x;
|
unsigned int size_x = _data_size_x;
|
||||||
unsigned int size_y = _actual_size_y;
|
unsigned int size_y = _data_size_y;
|
||||||
unsigned int size_z = _actual_size_z;
|
unsigned int size_z = _data_size_z;
|
||||||
|
|
||||||
ERR_FAIL_COND(size_x == 0 || size_y == 0 || size_z == 0);
|
ERR_FAIL_COND(size_x == 0 || size_y == 0 || size_z == 0);
|
||||||
|
|
||||||
for (unsigned int y = 1; y < size_y - 1; ++y) {
|
for (unsigned int y = 1; y < size_y - 1; ++y) {
|
||||||
for (unsigned int z = 1; z < size_z - 1; ++z) {
|
for (unsigned int z = 1; z < size_z - 1; ++z) {
|
||||||
for (unsigned int x = 1; x < size_x - 1; ++x) {
|
for (unsigned int x = 1; x < size_x - 1; ++x) {
|
||||||
int current = get_voxel(x, y, z, CHANNEL_ISOLEVEL);
|
int current = get_voxel(x, y, z, DEFAULT_CHANNEL_ISOLEVEL);
|
||||||
|
|
||||||
int sum = get_voxel(x + 1, y, z, CHANNEL_ISOLEVEL);
|
int sum = get_voxel(x + 1, y, z, DEFAULT_CHANNEL_ISOLEVEL);
|
||||||
sum += get_voxel(x - 1, y, z, CHANNEL_ISOLEVEL);
|
sum += get_voxel(x - 1, y, z, DEFAULT_CHANNEL_ISOLEVEL);
|
||||||
sum += get_voxel(x, y + 1, z, CHANNEL_ISOLEVEL);
|
sum += get_voxel(x, y + 1, z, DEFAULT_CHANNEL_ISOLEVEL);
|
||||||
sum += get_voxel(x, y - 1, z, CHANNEL_ISOLEVEL);
|
sum += get_voxel(x, y - 1, z, DEFAULT_CHANNEL_ISOLEVEL);
|
||||||
sum += get_voxel(x, y, z + 1, CHANNEL_ISOLEVEL);
|
sum += get_voxel(x, y, z + 1, DEFAULT_CHANNEL_ISOLEVEL);
|
||||||
sum += get_voxel(x, y, z - 1, CHANNEL_ISOLEVEL);
|
sum += get_voxel(x, y, z - 1, DEFAULT_CHANNEL_ISOLEVEL);
|
||||||
|
|
||||||
sum /= 6;
|
sum /= 6;
|
||||||
|
|
||||||
@ -242,7 +240,7 @@ void VoxelChunk::generate_ao() {
|
|||||||
if (sum < 0)
|
if (sum < 0)
|
||||||
sum = 0;
|
sum = 0;
|
||||||
|
|
||||||
set_voxel(sum, x, y, z, CHANNEL_AO);
|
set_voxel(sum, x, y, z, DEFAULT_CHANNEL_AO);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -251,25 +249,21 @@ void VoxelChunk::generate_ao() {
|
|||||||
void VoxelChunk::add_light(int local_x, int local_y, int local_z, int size, Color color) {
|
void VoxelChunk::add_light(int local_x, int local_y, int local_z, int size, Color color) {
|
||||||
ERR_FAIL_COND(size < 0);
|
ERR_FAIL_COND(size < 0);
|
||||||
|
|
||||||
int size_x = _actual_size_actual_size_xx;
|
|
||||||
int size_y = _actual_size_actual_size_xy;
|
|
||||||
int size_z = _actual_size_actual_size_xz;
|
|
||||||
|
|
||||||
float sizef = static_cast<float>(size);
|
float sizef = static_cast<float>(size);
|
||||||
//float rf = (color.r / sizef);
|
//float rf = (color.r / sizef);
|
||||||
//float gf = (color.g / sizef);
|
//float gf = (color.g / sizef);
|
||||||
//float bf = (color.b / sizef);
|
//float bf = (color.b / sizef);
|
||||||
|
|
||||||
for (int y = local_y - size; y <= local_y + size; ++y) {
|
for (int y = local_y - size; y <= local_y + size; ++y) {
|
||||||
if (y < 0 || y >= size_y)
|
if (y < 0 || y >= _data_size_y)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
for (int z = local_z - size; z <= local_z + size; ++z) {
|
for (int z = local_z - size; z <= local_z + size; ++z) {
|
||||||
if (z < 0 || z >= size_z)
|
if (z < 0 || z >= _data_size_z)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
for (int x = local_x - size; x <= local_x + size; ++x) {
|
for (int x = local_x - size; x <= local_x + size; ++x) {
|
||||||
if (x < 0 || x >= size_x)
|
if (x < 0 || x >= _data_size_x)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
int lx = x - local_x;
|
int lx = x - local_x;
|
||||||
@ -286,9 +280,9 @@ void VoxelChunk::add_light(int local_x, int local_y, int local_z, int size, Colo
|
|||||||
int g = color.g * str * 255.0;
|
int g = color.g * str * 255.0;
|
||||||
int b = color.b * str * 255.0;
|
int b = color.b * str * 255.0;
|
||||||
|
|
||||||
r += get_voxel(x, y, z, CHANNEL_LIGHT_COLOR_R);
|
r += get_voxel(x, y, z, DEFAULT_CHANNEL_LIGHT_COLOR_R);
|
||||||
g += get_voxel(x, y, z, CHANNEL_LIGHT_COLOR_G);
|
g += get_voxel(x, y, z, DEFAULT_CHANNEL_LIGHT_COLOR_G);
|
||||||
b += get_voxel(x, y, z, CHANNEL_LIGHT_COLOR_B);
|
b += get_voxel(x, y, z, DEFAULT_CHANNEL_LIGHT_COLOR_B);
|
||||||
|
|
||||||
if (r > 255)
|
if (r > 255)
|
||||||
r = 255;
|
r = 255;
|
||||||
@ -299,17 +293,17 @@ void VoxelChunk::add_light(int local_x, int local_y, int local_z, int size, Colo
|
|||||||
if (b > 255)
|
if (b > 255)
|
||||||
b = 255;
|
b = 255;
|
||||||
|
|
||||||
set_voxel(r, x, y, z, CHANNEL_LIGHT_COLOR_R);
|
set_voxel(r, x, y, z, DEFAULT_CHANNEL_LIGHT_COLOR_R);
|
||||||
set_voxel(g, x, y, z, CHANNEL_LIGHT_COLOR_G);
|
set_voxel(g, x, y, z, DEFAULT_CHANNEL_LIGHT_COLOR_G);
|
||||||
set_voxel(b, x, y, z, CHANNEL_LIGHT_COLOR_B);
|
set_voxel(b, x, y, z, DEFAULT_CHANNEL_LIGHT_COLOR_B);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void VoxelChunk::clear_lights() {
|
void VoxelChunk::clear_baked_lights() {
|
||||||
fill_channel(0, CHANNEL_LIGHT_COLOR_R);
|
fill_channel(0, DEFAULT_CHANNEL_LIGHT_COLOR_R);
|
||||||
fill_channel(0, CHANNEL_LIGHT_COLOR_G);
|
fill_channel(0, DEFAULT_CHANNEL_LIGHT_COLOR_G);
|
||||||
fill_channel(0, CHANNEL_LIGHT_COLOR_B);
|
fill_channel(0, DEFAULT_CHANNEL_LIGHT_COLOR_B);
|
||||||
}
|
}
|
||||||
|
|
||||||
void VoxelChunk::create_mesher() {
|
void VoxelChunk::create_mesher() {
|
||||||
@ -368,7 +362,7 @@ void VoxelChunk::_build_phase(int phase) {
|
|||||||
if (has_method("_create_mesh")) {
|
if (has_method("_create_mesh")) {
|
||||||
call("_create_mesh");
|
call("_create_mesh");
|
||||||
} else {
|
} else {
|
||||||
_mesher->add_buffer(_buffer);
|
_mesher->add_chunk(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
//finalize_mesh();
|
//finalize_mesh();
|
||||||
@ -387,7 +381,7 @@ void VoxelChunk::_build_phase(int phase) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
case BUILD_PHASE_TERRARIN_MESH: {
|
case BUILD_PHASE_TERRARIN_MESH: {
|
||||||
_mesher->bake_colors(_buffer);
|
_mesher->bake_colors(this);
|
||||||
|
|
||||||
finalize_mesh();
|
finalize_mesh();
|
||||||
|
|
||||||
@ -495,10 +489,7 @@ void VoxelChunk::create_voxel_light(const Color color, const int size, const int
|
|||||||
Ref<VoxelLight> light;
|
Ref<VoxelLight> light;
|
||||||
light.instance();
|
light.instance();
|
||||||
|
|
||||||
Vector3i pos = get_position();
|
light->set_world_position(_position_x * _size_x + x, _position_y * _size_y + y, _position_z * _size_z + z);
|
||||||
Vector3i csize = get_size();
|
|
||||||
|
|
||||||
light->set_world_position(pos.x * csize.x + x, pos.y * csize.y + y, pos.z * csize.z + z);
|
|
||||||
light->set_color(color);
|
light->set_color(color);
|
||||||
light->set_size(size);
|
light->set_size(size);
|
||||||
|
|
||||||
@ -565,21 +556,15 @@ void VoxelChunk::bake_lights() {
|
|||||||
void VoxelChunk::bake_light(Ref<VoxelLight> light) {
|
void VoxelChunk::bake_light(Ref<VoxelLight> light) {
|
||||||
ERR_FAIL_COND(!light.is_valid());
|
ERR_FAIL_COND(!light.is_valid());
|
||||||
|
|
||||||
Vector3i wp = light->get_world_position();
|
int wpx = light->get_world_position_x() - (_position_x * _size_x);
|
||||||
|
int wpy = light->get_world_position_y() - (_position_y * _size_y);
|
||||||
int wpx = wp.x - (_position_x * _size_x);
|
int wpz = light->get_world_position_z() - (_position_z * _size_z);
|
||||||
int wpy = wp.y - (_position_y * _size_y);
|
|
||||||
int wpz = wp.z - (_position_z * _size_z);
|
|
||||||
|
|
||||||
//int wpx = (int)(wp.x / _size.x) - _position.x;
|
//int wpx = (int)(wp.x / _size.x) - _position.x;
|
||||||
//int wpy = (int)(wp.y / _size.y) - _position.y;
|
//int wpy = (int)(wp.y / _size.y) - _position.y;
|
||||||
//int wpz = (int)(wp.z / _size.z) - _position.z;
|
//int wpz = (int)(wp.z / _size.z) - _position.z;
|
||||||
|
|
||||||
_buffer->add_light(wpx, wpy, wpz, light->get_size(), light->get_color());
|
add_light(wpx, wpy, wpz, light->get_size(), light->get_color());
|
||||||
}
|
|
||||||
|
|
||||||
void VoxelChunk::clear_baked_lights() {
|
|
||||||
_buffer->clear_lights();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void VoxelChunk::add_prop_light(Ref<VoxelLight> light) {
|
void VoxelChunk::add_prop_light(Ref<VoxelLight> light) {
|
||||||
@ -614,7 +599,7 @@ void VoxelChunk::process_props() {
|
|||||||
|
|
||||||
call("_process_props");
|
call("_process_props");
|
||||||
|
|
||||||
_mesher->bake_colors(_buffer);
|
_mesher->bake_colors(this);
|
||||||
|
|
||||||
_mesher->build_mesh(_prop_mesh_rid);
|
_mesher->build_mesh(_prop_mesh_rid);
|
||||||
}
|
}
|
||||||
@ -624,7 +609,7 @@ void VoxelChunk::build_prop_meshes() {
|
|||||||
allocate_prop_mesh();
|
allocate_prop_mesh();
|
||||||
}
|
}
|
||||||
|
|
||||||
_mesher->bake_colors(_buffer);
|
_mesher->bake_colors(this);
|
||||||
|
|
||||||
_mesher->build_mesh(_prop_mesh_rid);
|
_mesher->build_mesh(_prop_mesh_rid);
|
||||||
}
|
}
|
||||||
@ -898,11 +883,9 @@ void VoxelChunk::draw_debug_voxel_lights() {
|
|||||||
for (int i = 0; i < _voxel_lights.size(); ++i) {
|
for (int i = 0; i < _voxel_lights.size(); ++i) {
|
||||||
Ref<VoxelLight> v = _voxel_lights[i];
|
Ref<VoxelLight> v = _voxel_lights[i];
|
||||||
|
|
||||||
Vector3i pos = v->get_world_position();
|
int pos_x = v->get_world_position_x() - (_size_x * _position_x);
|
||||||
|
int pos_y = v->get_world_position_y() - (_size_y * _position_y);
|
||||||
int pos_x = pos.x - (_size_x * _position_x);
|
int pos_z = v->get_world_position_z() - (_size_z * _position_z);
|
||||||
int pos_y = pos.y - (_size_y * _position_y);
|
|
||||||
int pos_z = pos.z - (_size_z * _position_z);
|
|
||||||
|
|
||||||
draw_cross_voxels_fill(Vector3(pos_x, pos_y, pos_z), 1.0);
|
draw_cross_voxels_fill(Vector3(pos_x, pos_y, pos_z), 1.0);
|
||||||
}
|
}
|
||||||
@ -935,8 +918,6 @@ VoxelChunk::VoxelChunk() {
|
|||||||
_voxel_scale = 1;
|
_voxel_scale = 1;
|
||||||
_lod_size = 1;
|
_lod_size = 1;
|
||||||
|
|
||||||
_buffer.instance();
|
|
||||||
|
|
||||||
_debug_drawer = NULL;
|
_debug_drawer = NULL;
|
||||||
_voxel_world = NULL;
|
_voxel_world = NULL;
|
||||||
|
|
||||||
@ -959,8 +940,6 @@ VoxelChunk::~VoxelChunk() {
|
|||||||
_mesher.unref();
|
_mesher.unref();
|
||||||
}
|
}
|
||||||
|
|
||||||
_buffer.unref();
|
|
||||||
|
|
||||||
if (_library.is_valid()) {
|
if (_library.is_valid()) {
|
||||||
_library.unref();
|
_library.unref();
|
||||||
}
|
}
|
||||||
@ -987,30 +966,22 @@ void VoxelChunk::_bind_methods() {
|
|||||||
ADD_PROPERTY(PropertyInfo(Variant::INT, "state"), "set_state", "get_state");
|
ADD_PROPERTY(PropertyInfo(Variant::INT, "state"), "set_state", "get_state");
|
||||||
|
|
||||||
ClassDB::bind_method(D_METHOD("get_position_x"), &VoxelChunk::get_position_x);
|
ClassDB::bind_method(D_METHOD("get_position_x"), &VoxelChunk::get_position_x);
|
||||||
ClassDB::bind_method(D_METHOD("set_position_x", "value"), &VoxelChunk::set_position_x);
|
ADD_PROPERTY(PropertyInfo(Variant::INT, "position_x"), "", "get_position_x");
|
||||||
ADD_PROPERTY(PropertyInfo(Variant::INT, "chunk_position_x"), "set_position_x", "get_position_x");
|
|
||||||
|
|
||||||
ClassDB::bind_method(D_METHOD("get_position_y"), &VoxelChunk::get_position_y);
|
ClassDB::bind_method(D_METHOD("get_position_y"), &VoxelChunk::get_position_y);
|
||||||
ClassDB::bind_method(D_METHOD("set_position_y", "value"), &VoxelChunk::set_position_y);
|
ADD_PROPERTY(PropertyInfo(Variant::INT, "position_y"), "", "get_position_y");
|
||||||
ADD_PROPERTY(PropertyInfo(Variant::INT, "chunk_position_y"), "set_position_y", "get_position_y");
|
|
||||||
|
|
||||||
ClassDB::bind_method(D_METHOD("get_position_z"), &VoxelChunk::get_position_z);
|
ClassDB::bind_method(D_METHOD("get_position_z"), &VoxelChunk::get_position_z);
|
||||||
ClassDB::bind_method(D_METHOD("set_position_z", "value"), &VoxelChunk::set_position_z);
|
ADD_PROPERTY(PropertyInfo(Variant::INT, "position_z"), "", "get_position_z");
|
||||||
ADD_PROPERTY(PropertyInfo(Variant::INT, "chunk_position_z"), "set_position_x", "get_position_z");
|
|
||||||
|
|
||||||
ClassDB::bind_method(D_METHOD("set_position", "x", "y", "z"), &VoxelChunk::set_position);
|
|
||||||
|
|
||||||
ClassDB::bind_method(D_METHOD("get_size_x"), &VoxelChunk::get_size_x);
|
ClassDB::bind_method(D_METHOD("get_size_x"), &VoxelChunk::get_size_x);
|
||||||
ClassDB::bind_method(D_METHOD("set_size_x", "value"), &VoxelChunk::set_size_x);
|
ADD_PROPERTY(PropertyInfo(Variant::INT, "size_x"), "", "get_size_x");
|
||||||
ADD_PROPERTY(PropertyInfo(Variant::INT, "chunk_size_x"), "set_size_x", "get_size_x");
|
|
||||||
|
|
||||||
ClassDB::bind_method(D_METHOD("get_size_y"), &VoxelChunk::get_size_y);
|
ClassDB::bind_method(D_METHOD("get_size_y"), &VoxelChunk::get_size_y);
|
||||||
ClassDB::bind_method(D_METHOD("set_size_y", "value"), &VoxelChunk::set_size_y);
|
ADD_PROPERTY(PropertyInfo(Variant::INT, "size_y"), "", "get_size_y");
|
||||||
ADD_PROPERTY(PropertyInfo(Variant::INT, "chunk_size_y"), "set_size_y", "get_size_y");
|
|
||||||
|
|
||||||
ClassDB::bind_method(D_METHOD("get_size_z"), &VoxelChunk::get_size_z);
|
ClassDB::bind_method(D_METHOD("get_size_z"), &VoxelChunk::get_size_z);
|
||||||
ClassDB::bind_method(D_METHOD("set_size_z", "value"), &VoxelChunk::set_size_z);
|
ADD_PROPERTY(PropertyInfo(Variant::INT, "size_z"), "", "get_size_z");
|
||||||
ADD_PROPERTY(PropertyInfo(Variant::INT, "chunk_size_z"), "set_size_x", "get_size_z");
|
|
||||||
|
|
||||||
ClassDB::bind_method(D_METHOD("set_size", "x", "y", "z"), &VoxelChunk::set_size);
|
ClassDB::bind_method(D_METHOD("set_size", "x", "y", "z"), &VoxelChunk::set_size);
|
||||||
|
|
||||||
|
@ -141,17 +141,17 @@ public:
|
|||||||
RID get_clutter_mesh_rid();
|
RID get_clutter_mesh_rid();
|
||||||
RID get_clutter_mesh_instance_rid();
|
RID get_clutter_mesh_instance_rid();
|
||||||
|
|
||||||
//Voxel Data
|
//Voxel Data`
|
||||||
void set_size(int size_x, int size_y, int siye_z, int margin_start = 0, int margin_end = 0);
|
void set_size(int size_x, int size_y, int siye_z, int margin_start = 0, int margin_end = 0);
|
||||||
void set_channel_count(int value);
|
|
||||||
void validate_channel_index(int x, int y, int z, int channel_index);
|
|
||||||
|
|
||||||
uint8_t get_voxel(int x, int y, int z, int channel_index);
|
bool validate_channel_position(int x, int y, int z) const;
|
||||||
|
|
||||||
|
uint8_t get_voxel(int x, int y, int z, int channel_index) const;
|
||||||
void set_voxel(uint8_t value, int x, int y, int z, int channel_index);
|
void set_voxel(uint8_t value, int x, int y, int z, int channel_index);
|
||||||
|
|
||||||
void set_channel_count(int count);
|
void set_channel_count(int count);
|
||||||
void allocate_channel(int channel_index, uint8_t value = 0);
|
void allocate_channel(int channel_index, uint8_t value = 0);
|
||||||
void fill_channel(int channel_index);
|
void fill_channel(uint8_t value, int channel_index);
|
||||||
void dealloc_channel(int channel_index);
|
void dealloc_channel(int channel_index);
|
||||||
|
|
||||||
uint8_t *get_channel(int channel_index);
|
uint8_t *get_channel(int channel_index);
|
||||||
@ -161,7 +161,7 @@ public:
|
|||||||
void generate_ao();
|
void generate_ao();
|
||||||
|
|
||||||
void add_light(int local_x, int local_y, int local_z, int size, Color color);
|
void add_light(int local_x, int local_y, int local_z, int size, Color color);
|
||||||
void clear_lights();
|
void clear_baked_lights();
|
||||||
|
|
||||||
//Meshing
|
//Meshing
|
||||||
void create_mesher();
|
void create_mesher();
|
||||||
@ -194,7 +194,6 @@ public:
|
|||||||
|
|
||||||
void bake_lights();
|
void bake_lights();
|
||||||
void bake_light(Ref<VoxelLight> light);
|
void bake_light(Ref<VoxelLight> light);
|
||||||
void clear_baked_lights();
|
|
||||||
|
|
||||||
void add_prop_light(Ref<VoxelLight> light);
|
void add_prop_light(Ref<VoxelLight> light);
|
||||||
|
|
||||||
|
@ -1,116 +1,114 @@
|
|||||||
#include "voxel_structure.h"
|
#include "voxel_structure.h"
|
||||||
|
|
||||||
int VoxelStructure::get_chunk_size_x() const {
|
int VoxelStructure::get_chunk_size_x() const {
|
||||||
return _chunk_size.x;
|
return _chunk_size_x;
|
||||||
}
|
}
|
||||||
void VoxelStructure::set_chunk_size_x(const int value) {
|
void VoxelStructure::set_chunk_size_x(const int value) {
|
||||||
_chunk_size.x = value;
|
_chunk_size_x = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
int VoxelStructure::get_chunk_size_y() const {
|
int VoxelStructure::get_chunk_size_y() const {
|
||||||
return _chunk_size.y;
|
return _chunk_size_y;
|
||||||
}
|
}
|
||||||
void VoxelStructure::set_chunk_size_y(const int value) {
|
void VoxelStructure::set_chunk_size_y(const int value) {
|
||||||
_chunk_size.y = value;
|
_chunk_size_y = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
int VoxelStructure::get_chunk_size_z() const {
|
int VoxelStructure::get_chunk_size_z() const {
|
||||||
return _chunk_size.z;
|
return _chunk_size_z;
|
||||||
}
|
}
|
||||||
void VoxelStructure::set_chunk_size_z(const int value) {
|
void VoxelStructure::set_chunk_size_z(const int value) {
|
||||||
_chunk_size.z = value;
|
_chunk_size_z = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
int VoxelStructure::get_world_position_x() const {
|
int VoxelStructure::get_world_position_x() const {
|
||||||
return _world_position.x;
|
return _world_position_x;
|
||||||
}
|
}
|
||||||
void VoxelStructure::set_world_position_x(const int value) {
|
void VoxelStructure::set_world_position_x(const int value) {
|
||||||
_world_position.x = value;
|
_world_position_x = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
int VoxelStructure::get_world_position_y() const {
|
int VoxelStructure::get_world_position_y() const {
|
||||||
return _world_position.y;
|
return _world_position_y;
|
||||||
}
|
}
|
||||||
void VoxelStructure::set_world_position_y(const int value) {
|
void VoxelStructure::set_world_position_y(const int value) {
|
||||||
_world_position.y = value;
|
_world_position_y = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
int VoxelStructure::get_world_position_z() const {
|
int VoxelStructure::get_world_position_z() const {
|
||||||
return _world_position.z;
|
return _world_position_z;
|
||||||
}
|
}
|
||||||
void VoxelStructure::set_world_position_z(const int value) {
|
void VoxelStructure::set_world_position_z(const int value) {
|
||||||
_world_position.z = value;
|
_world_position_z = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
Ref<VoxelBuffer> VoxelStructure::get_chunk_voxel_pos(int x, int y, int z) {
|
VoxelChunk *VoxelStructure::get_chunk_voxel_pos(int x, int y, int z) {
|
||||||
|
|
||||||
Ref<VoxelBuffer> b = get_chunk(x / _chunk_size.x, y / _chunk_size.y, z / _chunk_size.z);
|
|
||||||
|
|
||||||
|
VoxelChunk *b = get_chunk(x / _chunk_size_x, y / _chunk_size_y, z / _chunk_size_z);
|
||||||
|
/*
|
||||||
if (!b.is_valid()) {
|
if (!b.is_valid()) {
|
||||||
b.instance();
|
b.instance();
|
||||||
|
|
||||||
add_chunk(b, x / _chunk_size.x, y / _chunk_size.y, z / _chunk_size.z);
|
add_chunk(b, x / _chunk_size_x, y / _chunk_size_y, z / _chunk_size_z);
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
return b;
|
return b;
|
||||||
}
|
}
|
||||||
|
|
||||||
int VoxelStructure::get_voxel(int x, int y, int z, unsigned int channel_index) {
|
int VoxelStructure::get_voxel(int x, int y, int z, unsigned int channel_index) {
|
||||||
Ref<VoxelBuffer> b = get_chunk_voxel_pos(x, y, z);
|
VoxelChunk *b = get_chunk_voxel_pos(x, y, z);
|
||||||
|
|
||||||
ERR_FAIL_COND_V(!b.is_valid(), 0);
|
//ERR_FAIL_COND_V(!b.is_valid(), 0);
|
||||||
|
|
||||||
return b->get_voxel(x, y, z, channel_index);
|
return b->get_voxel(x, y, z, channel_index);
|
||||||
}
|
}
|
||||||
void VoxelStructure::set_voxel(int value, int x, int y, int z, unsigned int channel_index) {
|
void VoxelStructure::set_voxel(int value, int x, int y, int z, unsigned int channel_index) {
|
||||||
Ref<VoxelBuffer> b = get_chunk_voxel_pos(x, y, z);
|
VoxelChunk *b = get_chunk_voxel_pos(x, y, z);
|
||||||
|
|
||||||
ERR_FAIL_COND(!b.is_valid());
|
//ERR_FAIL_COND(!b.is_valid());
|
||||||
|
|
||||||
return b->set_voxel(value, x, y, z, channel_index);
|
return b->set_voxel(value, x, y, z, channel_index);
|
||||||
}
|
}
|
||||||
void VoxelStructure::set_voxel_v(int value, Vector3 pos, unsigned int channel_index) {
|
|
||||||
Ref<VoxelBuffer> b = get_chunk_voxel_pos(pos.x, pos.y, pos.z);
|
|
||||||
|
|
||||||
ERR_FAIL_COND(!b.is_valid());
|
void VoxelStructure::add_chunk(VoxelChunk *chunk, const int x, const int y, const int z) {
|
||||||
|
//_chunks.set(Vector3i(x, y, z), chunk);
|
||||||
|
|
||||||
return b->set_voxel_v(value, pos, channel_index);
|
//VoxelStructureChunk c;
|
||||||
|
//c.chunk = chunk;
|
||||||
|
//c.position = Vector3i(x, y, z);
|
||||||
|
|
||||||
|
//_chunks_vector.push_back(c);
|
||||||
}
|
}
|
||||||
|
VoxelChunk *VoxelStructure::get_chunk(const int x, const int y, const int z) {
|
||||||
|
//const VoxelChunk **chunk = _chunks.getptr(Vector3i(x, y, z));
|
||||||
|
|
||||||
void VoxelStructure::add_chunk(Ref<VoxelBuffer> chunk, const int x, const int y, const int z) {
|
//return Ref<VoxelBuffer>(chunk);
|
||||||
_chunks.set(Vector3i(x, y, z), chunk);
|
|
||||||
|
|
||||||
VoxelStructureChunk c;
|
return NULL;
|
||||||
c.buffer = chunk;
|
|
||||||
c.position = Vector3i(x, y, z);
|
|
||||||
|
|
||||||
_chunks_vector.push_back(c);
|
|
||||||
}
|
}
|
||||||
Ref<VoxelBuffer> VoxelStructure::get_chunk(const int x, const int y, const int z) {
|
VoxelChunk *VoxelStructure::remove_chunk(const int x, const int y, const int z) {
|
||||||
const Ref<VoxelBuffer> *chunk = _chunks.getptr(Vector3i(x, y, z));
|
/*
|
||||||
|
VoxelChunk **chunk = _chunks.getptr(Vector3i(x, y, z));
|
||||||
|
|
||||||
return Ref<VoxelBuffer>(chunk);
|
VoxelChunk *c(chunk);
|
||||||
}
|
|
||||||
Ref<VoxelBuffer> VoxelStructure::remove_chunk(const int x, const int y, const int z) {
|
|
||||||
Ref<VoxelBuffer> *chunk = _chunks.getptr(Vector3i(x, y, z));
|
|
||||||
|
|
||||||
Ref<VoxelBuffer> c(chunk);
|
|
||||||
|
|
||||||
if (c.is_valid()) {
|
if (c.is_valid()) {
|
||||||
|
|
||||||
for (int i = 0; i < _chunks_vector.size(); ++i) {
|
for (int i = 0; i < _chunks_vector.size(); ++i) {
|
||||||
if (_chunks_vector.get(i).buffer == c) {
|
if (_chunks_vector.get(i).chunk == c) {
|
||||||
_chunks_vector.remove(i);
|
_chunks_vector.remove(i);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return c;
|
return c;*/
|
||||||
|
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
Ref<VoxelBuffer> VoxelStructure::get_chunk_index(const int index) {
|
VoxelChunk *VoxelStructure::get_chunk_index(const int index) {
|
||||||
return _chunks_vector.get(index).buffer;
|
//return _chunks_vector.get(index).chunk;
|
||||||
}
|
}
|
||||||
int VoxelStructure::get_chunk_count() const {
|
int VoxelStructure::get_chunk_count() const {
|
||||||
return _chunks_vector.size();
|
return _chunks_vector.size();
|
||||||
@ -118,22 +116,22 @@ int VoxelStructure::get_chunk_count() const {
|
|||||||
|
|
||||||
void VoxelStructure::clear_chunks() {
|
void VoxelStructure::clear_chunks() {
|
||||||
for (int i = 0; i < _chunks_vector.size(); ++i) {
|
for (int i = 0; i < _chunks_vector.size(); ++i) {
|
||||||
_chunks_vector.get(i).buffer.unref();
|
//_chunks_vector.get(i).chunk.unref();
|
||||||
}
|
}
|
||||||
|
|
||||||
_chunks_vector.clear();
|
//_chunks_vector.clear();
|
||||||
|
|
||||||
_chunks.clear();
|
//_chunks.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
VoxelStructure::VoxelStructure() {
|
VoxelStructure::VoxelStructure() {
|
||||||
_chunk_size = Vector3i(16, 16, 16);
|
//_chunk_size = Vector3i(16, 16, 16);
|
||||||
_world_position = Vector3i(0, 0, 0);
|
//_world_position = Vector3i(0, 0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
VoxelStructure::~VoxelStructure() {
|
VoxelStructure::~VoxelStructure() {
|
||||||
for (int i = 0; i < _chunks_vector.size(); ++i) {
|
for (int i = 0; i < _chunks_vector.size(); ++i) {
|
||||||
_chunks_vector.get(i).buffer.unref();
|
//_chunks_vector.get(i).chunk.unref();
|
||||||
}
|
}
|
||||||
|
|
||||||
_chunks.clear();
|
_chunks.clear();
|
||||||
|
@ -4,8 +4,7 @@
|
|||||||
#include "core/reference.h"
|
#include "core/reference.h"
|
||||||
|
|
||||||
#include "core/hash_map.h"
|
#include "core/hash_map.h"
|
||||||
#include "../math/vector3i.h"
|
#include "voxel_chunk.h"
|
||||||
#include "voxel_buffer.h"
|
|
||||||
|
|
||||||
class VoxelStructure : public Reference {
|
class VoxelStructure : public Reference {
|
||||||
GDCLASS(VoxelStructure, Reference);
|
GDCLASS(VoxelStructure, Reference);
|
||||||
@ -30,17 +29,17 @@ public:
|
|||||||
int get_world_position_z() const;
|
int get_world_position_z() const;
|
||||||
void set_world_position_z(const int value);
|
void set_world_position_z(const int value);
|
||||||
|
|
||||||
Ref<VoxelBuffer> get_chunk_voxel_pos(int x, int y, int z);
|
VoxelChunk *get_chunk_voxel_pos(int x, int y, int z);
|
||||||
|
|
||||||
int get_voxel(int x, int y, int z, unsigned int channel_index = 0);
|
int get_voxel(int x, int y, int z, unsigned int channel_index = 0);
|
||||||
void set_voxel(int value, int x, int y, int z, unsigned int channel_index = 0);
|
void set_voxel(int value, int x, int y, int z, unsigned int channel_index = 0);
|
||||||
void set_voxel_v(int value, Vector3 pos, unsigned int channel_index = 0);
|
void set_voxel_v(int value, Vector3 pos, unsigned int channel_index = 0);
|
||||||
|
|
||||||
void add_chunk(Ref<VoxelBuffer> chunk, const int x, const int y, const int z);
|
void add_chunk(VoxelChunk *chunk, const int x, const int y, const int z);
|
||||||
Ref<VoxelBuffer> get_chunk(const int x, const int y, const int z);
|
VoxelChunk *get_chunk(const int x, const int y, const int z);
|
||||||
Ref<VoxelBuffer> remove_chunk(const int x, const int y, const int z);
|
VoxelChunk *remove_chunk(const int x, const int y, const int z);
|
||||||
|
|
||||||
Ref<VoxelBuffer> get_chunk_index(const int index);
|
VoxelChunk *get_chunk_index(const int index);
|
||||||
int get_chunk_count() const;
|
int get_chunk_count() const;
|
||||||
|
|
||||||
void clear_chunks();
|
void clear_chunks();
|
||||||
@ -51,17 +50,31 @@ public:
|
|||||||
protected:
|
protected:
|
||||||
static void _bind_methods();
|
static void _bind_methods();
|
||||||
|
|
||||||
struct VoxelStructureChunk {
|
struct IntPos {
|
||||||
Vector3i position;
|
int x;
|
||||||
Ref<VoxelBuffer> buffer;
|
int y;
|
||||||
|
int z;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct IntPosHasher {
|
||||||
|
static _FORCE_INLINE_ uint32_t hash(const IntPos &v) {
|
||||||
|
uint32_t hash = hash_djb2_one_32(v.x);
|
||||||
|
hash = hash_djb2_one_32(v.y, hash);
|
||||||
|
return hash_djb2_one_32(v.z, hash);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Vector3i _chunk_size;
|
int _chunk_size_x;
|
||||||
Vector3i _world_position;
|
int _chunk_size_y;
|
||||||
|
int _chunk_size_z;
|
||||||
|
|
||||||
HashMap<Vector3i, Ref<VoxelBuffer>, Vector3iHasher> _chunks;
|
int _world_position_x;
|
||||||
Vector<VoxelStructureChunk> _chunks_vector;
|
int _world_position_y;
|
||||||
|
int _world_position_z;
|
||||||
|
|
||||||
|
HashMap<IntPos, VoxelChunk*, IntPosHasher> _chunks;
|
||||||
|
Vector<VoxelChunk*> _chunks_vector;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -64,14 +64,43 @@ public:
|
|||||||
protected:
|
protected:
|
||||||
static void _bind_methods();
|
static void _bind_methods();
|
||||||
|
|
||||||
|
struct IntPos {
|
||||||
|
int x;
|
||||||
|
int y;
|
||||||
|
int z;
|
||||||
|
|
||||||
|
IntPos() {
|
||||||
|
x = 0;
|
||||||
|
y = 0;
|
||||||
|
z = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
IntPos(int p_x, int p_y, int p_z) {
|
||||||
|
x = p_x;
|
||||||
|
y = p_y;
|
||||||
|
z = p_z;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
struct IntPosHasher {
|
||||||
|
static _FORCE_INLINE_ uint32_t hash(const IntPos &v) {
|
||||||
|
uint32_t hash = hash_djb2_one_32(v.x);
|
||||||
|
hash = hash_djb2_one_32(v.y, hash);
|
||||||
|
return hash_djb2_one_32(v.z, hash);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Vector3i _chunk_size;
|
int _chunk_size_x;
|
||||||
|
int _chunk_size_y;
|
||||||
|
int _chunk_size_z;
|
||||||
|
|
||||||
Ref<VoxelmanLibrary> _library;
|
Ref<VoxelmanLibrary> _library;
|
||||||
Ref<VoxelmanLevelGenerator> _level_generator;
|
Ref<VoxelmanLevelGenerator> _level_generator;
|
||||||
float _voxel_scale;
|
float _voxel_scale;
|
||||||
int _chunk_spawn_range;
|
int _chunk_spawn_range;
|
||||||
|
|
||||||
HashMap<Vector3i, VoxelChunk *, Vector3iHasher> _chunks;
|
HashMap<IntPos, VoxelChunk *, IntPosHasher> _chunks;
|
||||||
Vector<VoxelChunk *> _chunks_vector;
|
Vector<VoxelChunk *> _chunks_vector;
|
||||||
|
|
||||||
Vector<Ref<WorldArea> > _world_areas;
|
Vector<Ref<WorldArea> > _world_areas;
|
||||||
|
Loading…
Reference in New Issue
Block a user