Implemented props.

This commit is contained in:
Relintai 2019-07-18 18:56:42 +02:00
parent 7e7c07cbd8
commit 029f241005
15 changed files with 713 additions and 101 deletions

View File

@ -136,6 +136,10 @@ void VoxelmanLibrary::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_material", "value"), &VoxelmanLibrary::set_material);
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "material", PROPERTY_HINT_RESOURCE_TYPE, "Material"), "set_material", "get_material");
ClassDB::bind_method(D_METHOD("get_prop_material"), &VoxelmanLibrary::get_prop_material);
ClassDB::bind_method(D_METHOD("set_prop_material", "value"), &VoxelmanLibrary::set_prop_material);
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "prop_material", PROPERTY_HINT_RESOURCE_TYPE, "Material"), "set_prop_material", "get_prop_material");
ClassDB::bind_method(D_METHOD("get_voxel_types_count"), &VoxelmanLibrary::get_voxel_types_count);
ClassDB::bind_method(D_METHOD("set_voxel_types_count", "value"), &VoxelmanLibrary::set_voxel_types_count);
ADD_PROPERTY(PropertyInfo(Variant::INT, "voxel_types_count", PROPERTY_HINT_RANGE, "0," + itos(MAX_VOXEL_TYPES), PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_UPDATE_ALL_IF_MODIFIED), "set_voxel_types_count", "get_voxel_types_count");

View File

@ -30,6 +30,9 @@ public:
Ref<Material> get_material() const { return _material; }
void set_material(Ref<Material> mat) { _material = mat; }
Ref<Material> get_prop_material() const { return _prop_material; }
void set_prop_material(Ref<Material> mat) { _prop_material = mat; }
Ref<VoxelSurface> create_voxel(int id, String name);
int get_voxel_count() const;
@ -66,6 +69,7 @@ private:
Ref<VoxelSurface> _voxel_types[MAX_VOXEL_TYPES];
Ref<Material> _material;
Ref<Material> _prop_material;
//atlas
int _atlas_columns;

View File

@ -176,112 +176,112 @@ void VoxelCubePoints::refresh_neighbours(const Ref<VoxelBuffer> buffer) {
int z = _z;
//000
if (buffer->get_voxel(x - _size, y, z, VoxelBuffer::CHANNEL_TYPE) != 0)
if (buffer->get_voxel(x - 1, y, z, VoxelBuffer::CHANNEL_TYPE) != 0)
neighbours = neighbours | VOXEL_NEIGHBOUR_LEFT;
if (buffer->get_voxel(x, y - _size, z, VoxelBuffer::CHANNEL_TYPE) != 0)
if (buffer->get_voxel(x, y - 1, z, VoxelBuffer::CHANNEL_TYPE) != 0)
neighbours = neighbours | VOXEL_NEIGHBOUR_BOTTOM;
if (buffer->get_voxel(x, y, z - _size, VoxelBuffer::CHANNEL_TYPE) != 0)
if (buffer->get_voxel(x, y, z - 1, VoxelBuffer::CHANNEL_TYPE) != 0)
neighbours = neighbours | VOXEL_NEIGHBOUR_FRONT;
/*
if (buffer->get_voxel(x - _size, y, z - _size, VoxelBuffer::CHANNEL_TYPE) != 0)
if (buffer->get_voxel(x - 1, y, z - 1, VoxelBuffer::CHANNEL_TYPE) != 0)
neighbours = neighbours | VOXEL_NEIGHBOUR_LEFT_FRONT;
if (buffer->get_voxel(x - _size, y - _size, z, VoxelBuffer::CHANNEL_TYPE) != 0)
if (buffer->get_voxel(x - 1, y - 1, z, VoxelBuffer::CHANNEL_TYPE) != 0)
neighbours = neighbours | VOXEL_NEIGHBOUR_BOTTOM_LEFT;
if (buffer->get_voxel(x, y - _size, z - _size, VoxelBuffer::CHANNEL_TYPE) != 0)
if (buffer->get_voxel(x, y - 1, z - 1, VoxelBuffer::CHANNEL_TYPE) != 0)
neighbours = neighbours | VOXEL_NEIGHBOUR_BOTTOM_FRONT;
if (buffer->get_voxel(x - _size, y - _size, z - _size, VoxelBuffer::CHANNEL_TYPE) != 0)
if (buffer->get_voxel(x - 1, y - 1, z - 1, VoxelBuffer::CHANNEL_TYPE) != 0)
neighbours = neighbours | VOXEL_NEIGHBOUR_BOTTOM_LEFT_FRONT;*/
_point_neighbours[P000] = neighbours;
neighbours = 0;
x = _x + _size;
x = _x + 1;
y = _y;
z = _z;
//100
if (buffer->get_voxel(x + _size, y, z, VoxelBuffer::CHANNEL_TYPE) != 0)
if (buffer->get_voxel(x + 1, y, z, VoxelBuffer::CHANNEL_TYPE) != 0)
neighbours = neighbours | VOXEL_NEIGHBOUR_RIGHT;
if (buffer->get_voxel(x, y - _size, z, VoxelBuffer::CHANNEL_TYPE) != 0)
if (buffer->get_voxel(x, y - 1, z, VoxelBuffer::CHANNEL_TYPE) != 0)
neighbours = neighbours | VOXEL_NEIGHBOUR_BOTTOM;
if (buffer->get_voxel(x, y, z - _size, VoxelBuffer::CHANNEL_TYPE) != 0)
if (buffer->get_voxel(x, y, z - 1, VoxelBuffer::CHANNEL_TYPE) != 0)
neighbours = neighbours | VOXEL_NEIGHBOUR_FRONT;
/*
if (buffer->get_voxel(x + _size, y, z - _size, VoxelBuffer::CHANNEL_TYPE) != 0)
if (buffer->get_voxel(x + 1, y, z - 1, VoxelBuffer::CHANNEL_TYPE) != 0)
neighbours = neighbours | VOXEL_NEIGHBOUR_RIGHT_FRONT;
if (buffer->get_voxel(x + _size, y - _size, z, VoxelBuffer::CHANNEL_TYPE) != 0)
if (buffer->get_voxel(x + 1, y - 1, z, VoxelBuffer::CHANNEL_TYPE) != 0)
neighbours = neighbours | VOXEL_NEIGHBOUR_BOTTOM_RIGHT;
if (buffer->get_voxel(x, y - _size, z - _size, VoxelBuffer::CHANNEL_TYPE) != 0)
if (buffer->get_voxel(x, y - 1, z - 1, VoxelBuffer::CHANNEL_TYPE) != 0)
neighbours = neighbours | VOXEL_NEIGHBOUR_BOTTOM_FRONT;
if (buffer->get_voxel(x + _size, y - _size, z - _size, VoxelBuffer::CHANNEL_TYPE) != 0)
if (buffer->get_voxel(x + 1, y - 1, z - 1, VoxelBuffer::CHANNEL_TYPE) != 0)
neighbours = neighbours | VOXEL_NEIGHBOUR_BOTTOM_RIGHT_FRONT;*/
_point_neighbours[P100] = neighbours;
neighbours = 0;
x = _x;
y = _y + _size;
y = _y + 1;
z = _z;
//010
if (buffer->get_voxel(x - _size, y, z, VoxelBuffer::CHANNEL_TYPE) != 0)
if (buffer->get_voxel(x - 1, y, z, VoxelBuffer::CHANNEL_TYPE) != 0)
neighbours = neighbours | VOXEL_NEIGHBOUR_LEFT;
if (buffer->get_voxel(x, y + _size, z, VoxelBuffer::CHANNEL_TYPE) != 0)
if (buffer->get_voxel(x, y + 1, z, VoxelBuffer::CHANNEL_TYPE) != 0)
neighbours = neighbours | VOXEL_NEIGHBOUR_TOP;
if (buffer->get_voxel(x, y, z - _size, VoxelBuffer::CHANNEL_TYPE) != 0)
if (buffer->get_voxel(x, y, z - 1, VoxelBuffer::CHANNEL_TYPE) != 0)
neighbours = neighbours | VOXEL_NEIGHBOUR_FRONT;
/*
if (buffer->get_voxel(x - _size, y, z - _size, VoxelBuffer::CHANNEL_TYPE) != 0)
if (buffer->get_voxel(x - 1, y, z - 1, VoxelBuffer::CHANNEL_TYPE) != 0)
neighbours = neighbours | VOXEL_NEIGHBOUR_LEFT_FRONT;
if (buffer->get_voxel(x - _size, y + _size, z, VoxelBuffer::CHANNEL_TYPE) != 0)
if (buffer->get_voxel(x - 1, y + 1, z, VoxelBuffer::CHANNEL_TYPE) != 0)
neighbours = neighbours | VOXEL_NEIGHBOUR_TOP_LEFT;
if (buffer->get_voxel(x, y + _size, z - _size, VoxelBuffer::CHANNEL_TYPE) != 0)
if (buffer->get_voxel(x, y + 1, z - 1, VoxelBuffer::CHANNEL_TYPE) != 0)
neighbours = neighbours | VOXEL_NEIGHBOUR_TOP_FRONT;
if (buffer->get_voxel(x - _size, y + _size, z - _size, VoxelBuffer::CHANNEL_TYPE) != 0)
if (buffer->get_voxel(x - 1, y + 1, z - 1, VoxelBuffer::CHANNEL_TYPE) != 0)
neighbours = neighbours | VOXEL_NEIGHBOUR_TOP_LEFT_FRONT;*/
_point_neighbours[P010] = neighbours;
neighbours = 0;
x = _x + _size;
y = _y + _size;
x = _x + 1;
y = _y + 1;
z = _z;
//110
if (buffer->get_voxel(x + _size, y, z, VoxelBuffer::CHANNEL_TYPE) != 0)
if (buffer->get_voxel(x + 1, y, z, VoxelBuffer::CHANNEL_TYPE) != 0)
neighbours = neighbours | VOXEL_NEIGHBOUR_RIGHT;
if (buffer->get_voxel(x, y + _size, z, VoxelBuffer::CHANNEL_TYPE) != 0)
if (buffer->get_voxel(x, y + 1, z, VoxelBuffer::CHANNEL_TYPE) != 0)
neighbours = neighbours | VOXEL_NEIGHBOUR_TOP;
if (buffer->get_voxel(x, y, z - _size, VoxelBuffer::CHANNEL_TYPE) != 0)
if (buffer->get_voxel(x, y, z - 1, VoxelBuffer::CHANNEL_TYPE) != 0)
neighbours = neighbours | VOXEL_NEIGHBOUR_FRONT;
/*
if (buffer->get_voxel(x + _size, y, z - _size, VoxelBuffer::CHANNEL_TYPE) != 0)
if (buffer->get_voxel(x + 1, y, z - 1, VoxelBuffer::CHANNEL_TYPE) != 0)
neighbours = neighbours | VOXEL_NEIGHBOUR_RIGHT_FRONT;
if (buffer->get_voxel(x + _size, y + _size, z, VoxelBuffer::CHANNEL_TYPE) != 0)
if (buffer->get_voxel(x + 1, y + 1, z, VoxelBuffer::CHANNEL_TYPE) != 0)
neighbours = neighbours | VOXEL_NEIGHBOUR_TOP_RIGHT;
if (buffer->get_voxel(x, y + _size, z - _size, VoxelBuffer::CHANNEL_TYPE) != 0)
if (buffer->get_voxel(x, y + 1, z - 1, VoxelBuffer::CHANNEL_TYPE) != 0)
neighbours = neighbours | VOXEL_NEIGHBOUR_TOP_FRONT;
if (buffer->get_voxel(x + _size, y + _size, z - _size, VoxelBuffer::CHANNEL_TYPE) != 0)
if (buffer->get_voxel(x + 1, y + 1, z - 1, VoxelBuffer::CHANNEL_TYPE) != 0)
neighbours = neighbours | VOXEL_NEIGHBOUR_TOP_RIGHT_FRONT;*/
_point_neighbours[P110] = neighbours;
@ -289,117 +289,117 @@ void VoxelCubePoints::refresh_neighbours(const Ref<VoxelBuffer> buffer) {
neighbours = 0;
x = _x;
y = _y;
z = _z + _size;
z = _z + 1;
//001
if (buffer->get_voxel(x - _size, y, z, VoxelBuffer::CHANNEL_TYPE) != 0)
if (buffer->get_voxel(x - 1, y, z, VoxelBuffer::CHANNEL_TYPE) != 0)
neighbours = neighbours | VOXEL_NEIGHBOUR_LEFT;
if (buffer->get_voxel(x, y - _size, z, VoxelBuffer::CHANNEL_TYPE) != 0)
if (buffer->get_voxel(x, y - 1, z, VoxelBuffer::CHANNEL_TYPE) != 0)
neighbours = neighbours | VOXEL_NEIGHBOUR_BOTTOM;
if (buffer->get_voxel(x, y, z + _size, VoxelBuffer::CHANNEL_TYPE) != 0)
if (buffer->get_voxel(x, y, z + 1, VoxelBuffer::CHANNEL_TYPE) != 0)
neighbours = neighbours | VOXEL_NEIGHBOUR_BACK;
/*
if (buffer->get_voxel(x - _size, y, z + _size, VoxelBuffer::CHANNEL_TYPE) != 0)
if (buffer->get_voxel(x - 1, y, z + 1, VoxelBuffer::CHANNEL_TYPE) != 0)
neighbours = neighbours | VOXEL_NEIGHBOUR_LEFT_BACK;
if (buffer->get_voxel(x - _size, y - _size, z, VoxelBuffer::CHANNEL_TYPE) != 0)
if (buffer->get_voxel(x - 1, y - 1, z, VoxelBuffer::CHANNEL_TYPE) != 0)
neighbours = neighbours | VOXEL_NEIGHBOUR_BOTTOM_LEFT;
if (buffer->get_voxel(x, y - _size, z + _size, VoxelBuffer::CHANNEL_TYPE) != 0)
if (buffer->get_voxel(x, y - 1, z + 1, VoxelBuffer::CHANNEL_TYPE) != 0)
neighbours = neighbours | VOXEL_NEIGHBOUR_BOTTOM_BACK;
if (buffer->get_voxel(x - _size, y - _size, z + _size, VoxelBuffer::CHANNEL_TYPE) != 0)
if (buffer->get_voxel(x - 1, y - 1, z + 1, VoxelBuffer::CHANNEL_TYPE) != 0)
neighbours = neighbours | VOXEL_NEIGHBOUR_BOTTOM_LEFT_BACK;*/
_point_neighbours[P001] = neighbours;
neighbours = 0;
x = _x + _size;
x = _x + 1;
y = _y;
z = _z + _size;
z = _z + 1;
//101
if (buffer->get_voxel(x + _size, y, z, VoxelBuffer::CHANNEL_TYPE) != 0)
if (buffer->get_voxel(x + 1, y, z, VoxelBuffer::CHANNEL_TYPE) != 0)
neighbours = neighbours | VOXEL_NEIGHBOUR_RIGHT;
if (buffer->get_voxel(x, y - _size, z, VoxelBuffer::CHANNEL_TYPE) != 0)
if (buffer->get_voxel(x, y - 1, z, VoxelBuffer::CHANNEL_TYPE) != 0)
neighbours = neighbours | VOXEL_NEIGHBOUR_BOTTOM;
if (buffer->get_voxel(x, y, z + _size, VoxelBuffer::CHANNEL_TYPE) != 0)
if (buffer->get_voxel(x, y, z + 1, VoxelBuffer::CHANNEL_TYPE) != 0)
neighbours = neighbours | VOXEL_NEIGHBOUR_BACK;
/*
if (buffer->get_voxel(x + _size, y, z + _size, VoxelBuffer::CHANNEL_TYPE) != 0)
if (buffer->get_voxel(x + 1, y, z + 1, VoxelBuffer::CHANNEL_TYPE) != 0)
neighbours = neighbours | VOXEL_NEIGHBOUR_RIGHT_BACK;
if (buffer->get_voxel(x + _size, y - _size, z, VoxelBuffer::CHANNEL_TYPE) != 0)
if (buffer->get_voxel(x + 1, y - 1, z, VoxelBuffer::CHANNEL_TYPE) != 0)
neighbours = neighbours | VOXEL_NEIGHBOUR_BOTTOM_RIGHT;
if (buffer->get_voxel(x, y - _size, z + _size, VoxelBuffer::CHANNEL_TYPE) != 0)
if (buffer->get_voxel(x, y - 1, z + 1, VoxelBuffer::CHANNEL_TYPE) != 0)
neighbours = neighbours | VOXEL_NEIGHBOUR_BOTTOM_BACK;
if (buffer->get_voxel(x + _size, y - _size, z + _size, VoxelBuffer::CHANNEL_TYPE) != 0)
if (buffer->get_voxel(x + 1, y - 1, z + 1, VoxelBuffer::CHANNEL_TYPE) != 0)
neighbours = neighbours | VOXEL_NEIGHBOUR_BOTTOM_RIGHT_BACK;*/
_point_neighbours[P101] = neighbours;
neighbours = 0;
x = _x;
y = _y + _size;
z = _z + _size;
y = _y + 1;
z = _z + 1;
//011
if (buffer->get_voxel(x - _size, y, z, VoxelBuffer::CHANNEL_TYPE) != 0)
if (buffer->get_voxel(x - 1, y, z, VoxelBuffer::CHANNEL_TYPE) != 0)
neighbours = neighbours | VOXEL_NEIGHBOUR_LEFT;
if (buffer->get_voxel(x, y + _size, z, VoxelBuffer::CHANNEL_TYPE) != 0)
if (buffer->get_voxel(x, y + 1, z, VoxelBuffer::CHANNEL_TYPE) != 0)
neighbours = neighbours | VOXEL_NEIGHBOUR_TOP;
if (buffer->get_voxel(x, y, z + _size, VoxelBuffer::CHANNEL_TYPE) != 0)
if (buffer->get_voxel(x, y, z + 1, VoxelBuffer::CHANNEL_TYPE) != 0)
neighbours = neighbours | VOXEL_NEIGHBOUR_BACK;
/*
if (buffer->get_voxel(x - _size, y, z + _size, VoxelBuffer::CHANNEL_TYPE) != 0)
if (buffer->get_voxel(x - 1, y, z + 1, VoxelBuffer::CHANNEL_TYPE) != 0)
neighbours = neighbours | VOXEL_NEIGHBOUR_LEFT_BACK;
if (buffer->get_voxel(x - _size, y + _size, z, VoxelBuffer::CHANNEL_TYPE) != 0)
if (buffer->get_voxel(x - 1, y + 1, z, VoxelBuffer::CHANNEL_TYPE) != 0)
neighbours = neighbours | VOXEL_NEIGHBOUR_TOP_LEFT;
if (buffer->get_voxel(x, y + _size, z + _size, VoxelBuffer::CHANNEL_TYPE) != 0)
if (buffer->get_voxel(x, y + 1, z + 1, VoxelBuffer::CHANNEL_TYPE) != 0)
neighbours = neighbours | VOXEL_NEIGHBOUR_TOP_BACK;
if (buffer->get_voxel(x - _size, y + _size, z + _size, VoxelBuffer::CHANNEL_TYPE) != 0)
if (buffer->get_voxel(x - 1, y + 1, z + 1, VoxelBuffer::CHANNEL_TYPE) != 0)
neighbours = neighbours | VOXEL_NEIGHBOUR_TOP_LEFT_BACK;*/
_point_neighbours[P011] = neighbours;
neighbours = 0;
x = _x + _size;
y = _y + _size;
z = _z + _size;
x = _x + 1;
y = _y + 1;
z = _z + 1;
//111
if (buffer->get_voxel(x + _size, y, z, VoxelBuffer::CHANNEL_TYPE) != 0)
if (buffer->get_voxel(x + 1, y, z, VoxelBuffer::CHANNEL_TYPE) != 0)
neighbours = neighbours | VOXEL_NEIGHBOUR_RIGHT;
if (buffer->get_voxel(x, y + _size, z, VoxelBuffer::CHANNEL_TYPE) != 0)
if (buffer->get_voxel(x, y + 1, z, VoxelBuffer::CHANNEL_TYPE) != 0)
neighbours = neighbours | VOXEL_NEIGHBOUR_TOP;
if (buffer->get_voxel(x, y, z + _size, VoxelBuffer::CHANNEL_TYPE) != 0)
if (buffer->get_voxel(x, y, z + 1, VoxelBuffer::CHANNEL_TYPE) != 0)
neighbours = neighbours | VOXEL_NEIGHBOUR_BACK;
/*
if (buffer->get_voxel(x + _size, y, z + _size, VoxelBuffer::CHANNEL_TYPE) != 0)
if (buffer->get_voxel(x + 1, y, z + 1, VoxelBuffer::CHANNEL_TYPE) != 0)
neighbours = neighbours | VOXEL_NEIGHBOUR_RIGHT_BACK;
if (buffer->get_voxel(x + _size, y + _size, z, VoxelBuffer::CHANNEL_TYPE) != 0)
if (buffer->get_voxel(x + 1, y + 1, z, VoxelBuffer::CHANNEL_TYPE) != 0)
neighbours = neighbours | VOXEL_NEIGHBOUR_TOP_RIGHT;
if (buffer->get_voxel(x, y + _size, z + _size, VoxelBuffer::CHANNEL_TYPE) != 0)
if (buffer->get_voxel(x, y + 1, z + 1, VoxelBuffer::CHANNEL_TYPE) != 0)
neighbours = neighbours | VOXEL_NEIGHBOUR_TOP_BACK;
if (buffer->get_voxel(x + _size, y + _size, z + _size, VoxelBuffer::CHANNEL_TYPE) != 0)
if (buffer->get_voxel(x + 1, y + 1, z + 1, VoxelBuffer::CHANNEL_TYPE) != 0)
neighbours = neighbours | VOXEL_NEIGHBOUR_TOP_RIGHT_BACK;*/
_point_neighbours[P111] = neighbours;

View File

@ -33,9 +33,9 @@ void VoxelMesherCubic::_add_buffer(Ref<VoxelBuffer> buffer) {
float tile_uv_size = 1 / 4.0;
Color base_light(_base_light_value, _base_light_value, _base_light_value);
for (int y = lod_size; y < y_size - lod_size; y += lod_size) {
for (int z = lod_size; z < z_size - lod_size; z += lod_size) {
for (int x = lod_size; x < x_size - lod_size; x += lod_size) {
for (int y = 1; y < y_size - 1; y += lod_size) {
for (int z = 1; z < z_size - 1; z += lod_size) {
for (int x = 1; x < x_size - 1; x += lod_size) {
cube_points->setup(buffer, x, y, z, lod_size);
@ -78,12 +78,13 @@ void VoxelMesherCubic::_add_buffer(Ref<VoxelBuffer> buffer) {
light *= NdotL;
light -= cube_points->get_face_point_ao_color(face, i) * _ao_strength;
add_color(light);
light.r = CLAMP(light.r, 0, 1.0);
light.g = CLAMP(light.g, 0, 1.0);
light.b = CLAMP(light.b, 0, 1.0);
add_color(light);
add_uv((cube_points->get_point_uv_direction(face, i) + Vector2(0.5, 0.5)) * Vector2(tile_uv_size, tile_uv_size));
add_vertex((vertices[i] * voxel_size + Vector3(x, y, z)) * voxel_scale);
@ -94,6 +95,61 @@ void VoxelMesherCubic::_add_buffer(Ref<VoxelBuffer> buffer) {
}
}
void VoxelMesherCubic::_bake_colors(Ref<VoxelBuffer> buffer) {
Color base_light(_base_light_value, _base_light_value, _base_light_value);
ERR_FAIL_COND(_vertices.size() != _normals.size());
/*
if (_vertices.size() != _normals.size()) {
print_error("VoxelMesherCubic: Generating normals!");
}*/
for (int i = 0; i < _vertices.size(); ++i) {
Vector3 vert = _vertices[i];
if (vert.x < 0 || vert.y < 0 || vert.z < 0) {
if (_colors.size() < _vertices.size()) {
_colors.push_back(base_light);
}
continue;
}
unsigned int x = (unsigned int)(vert.x / _voxel_scale);
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)) {
int ao = buffer->get_voxel(x, y, z, VoxelBuffer::CHANNEL_AO);
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);
Color ao_color(ao, ao, ao);
light += base_light;
float NdotL = CLAMP(_normals[i].dot(vert - Vector3(x, y, z)), 0, 1.0);
light *= NdotL;
light -= ao_color * _ao_strength;
light.r = CLAMP(light.r, 0, 1.0);
light.g = CLAMP(light.g, 0, 1.0);
light.b = CLAMP(light.b, 0, 1.0);
if (_colors.size() < _vertices.size()) {
_colors.push_back(light);
} else {
_colors.set(i, light);
}
} else {
if (_colors.size() < _vertices.size()) {
_colors.push_back(base_light);
}
}
}
}
VoxelMesherCubic::VoxelMesherCubic() {
_ao_strength = 0.25;
_base_light_value = 0.5;
@ -104,6 +160,7 @@ VoxelMesherCubic::~VoxelMesherCubic() {
void VoxelMesherCubic::_bind_methods() {
ClassDB::bind_method(D_METHOD("_add_buffer", "buffer"), &VoxelMesherCubic::_add_buffer);
ClassDB::bind_method(D_METHOD("_bake_colors", "buffer"), &VoxelMesherCubic::_bake_colors);
ClassDB::bind_method(D_METHOD("get_ao_strength"), &VoxelMesherCubic::get_ao_strength);
ClassDB::bind_method(D_METHOD("set_ao_strength", "value"), &VoxelMesherCubic::set_ao_strength);

View File

@ -20,6 +20,7 @@ public:
void set_base_light_value(float value);
void _add_buffer(Ref<VoxelBuffer> buffer);
void _bake_colors(Ref<VoxelBuffer> buffer);
VoxelMesherCubic();
~VoxelMesherCubic();

View File

@ -40,6 +40,11 @@ void VoxelMesher::build_mesh(RID mesh) {
_surface_tool->begin(Mesh::PRIMITIVE_TRIANGLES);
_surface_tool->set_material(_library->get_material());
if (_colors.size() != _vertices.size()) {
print_error("Colors.size() != vertices.size() -> " + String::num(_colors.size()) + " " + String::num(_vertices.size()));
_colors.clear();
}
int len = _vertices.size();
for (int i = 0; i < len; ++i) {
@ -78,6 +83,8 @@ void VoxelMesher::reset() {
_uvs.clear();
_indices.clear();
_bones.clear();
_surface_tool->clear();
}
void VoxelMesher::add_buffer(Ref<VoxelBuffer> voxels) {
@ -86,6 +93,128 @@ void VoxelMesher::add_buffer(Ref<VoxelBuffer> voxels) {
call("_add_buffer", voxels);
}
void VoxelMesher::add_mesh_data_resource(Transform local_transform, Ref<MeshDataResource> mesh) {
ERR_FAIL_COND(mesh->get_array().size() == 0);
Array verts = mesh->get_array().get(Mesh::ARRAY_VERTEX);
for (int i = 0; i < verts.size(); ++i) {
Vector3 vert = verts[i];
vert = local_transform.xform(vert);
add_vertex(vert);
}
if (mesh->get_array().size() <= Mesh::ARRAY_NORMAL)
return;
Array normals = mesh->get_array().get(Mesh::ARRAY_NORMAL);
for (int i = 0; i < normals.size(); ++i) {
Vector3 normal = normals[i];
normal = local_transform.basis.xform(normal);
add_normal(normal);
}
/*
if (mesh->get_array().size() <= Mesh::ARRAY_TANGENT)
return;
Array tangents = mesh->get_array().get(Mesh::ARRAY_TANGENT);
for (int i = 0; i < verts.size(); ++i) {
Plane p(tangents[i * 4 + 0], tangents[i * 4 + 1], tangents[i * 4 + 2], tangents[i * 4 + 3]);
Vector3 tangent = p.normal;
Vector3 binormal = p.normal.cross(tangent).normalized() * p.d;
tangent = local_transform.basis.xform(tangent);
binormal = local_transform.basis.xform(binormal);
add_t(normal);
add_binorm
}*/
if (mesh->get_array().size() <= Mesh::ARRAY_COLOR)
return;
Array colors = mesh->get_array().get(Mesh::ARRAY_COLOR);
for (int i = 0; i < colors.size(); ++i) {
Color color = colors[i];
add_color(color);
}
if (mesh->get_array().size() <= Mesh::ARRAY_TEX_UV)
return;
Array tex_uv = mesh->get_array().get(Mesh::ARRAY_TEX_UV);
for (int i = 0; i < tex_uv.size(); ++i) {
Vector2 uv = tex_uv[i];
add_uv(uv);
}
/*
if (mesh->get_array().size() <= Mesh::ARRAY_TEX_UV2)
return;
Array tex_uv2 = mesh->get_array().get(Mesh::ARRAY_TEX_UV2);
for (int i = 0; i < tex_uv.size(); ++i) {
Vector2 uv = tex_uv2[i];
add_uv2(uv);
}*/
/*
if (mesh->get_array().size() <= Mesh::ARRAY_BONES)
return;
Array bones = mesh->get_array().get(Mesh::ARRAY_BONES);
for (int i = 0; i < bones.size(); ++i) {
int bone = bones[i];
add_bone(bone);
}*/
/*
if (mesh->get_array().size() <= Mesh::ARRAY_WEIGHTS)
return;
Array weights = mesh->get_array().get(Mesh::ARRAY_WEIGHTS);
for (int i = 0; i < weights.size(); ++i) {
float weight = weights[i];
add_weight(weight);
}*/
if (mesh->get_array().size() <= Mesh::ARRAY_INDEX)
return;
Array indices = mesh->get_array().get(Mesh::ARRAY_INDEX);
int ic = get_vertex_count() - verts.size();
for (int i = 0; i < indices.size(); ++i) {
int index = indices[i];
add_indices(ic + index);
}
}
void VoxelMesher::bake_colors(Ref<VoxelBuffer> voxels) {
if (has_method("_bake_colors"))
call("_bake_colors", voxels);
}
float VoxelMesher::get_voxel_scale() const {
return _voxel_scale;
}
@ -326,8 +455,11 @@ void VoxelMesher::remove_indices(int idx) {
void VoxelMesher::_bind_methods() {
BIND_VMETHOD(MethodInfo("_add_buffer", PropertyInfo(Variant::OBJECT, "buffer", PROPERTY_HINT_RESOURCE_TYPE, "VoxelBuffer")));
BIND_VMETHOD(MethodInfo("_bake_colors", PropertyInfo(Variant::OBJECT, "buffer", PROPERTY_HINT_RESOURCE_TYPE, "VoxelBuffer")));
ClassDB::bind_method(D_METHOD("add_buffer", "buffer"), &VoxelMesher::add_buffer);
ClassDB::bind_method(D_METHOD("add_mesh_data_resource", "local_transform", "mesh"), &VoxelMesher::add_mesh_data_resource);
ClassDB::bind_method(D_METHOD("bake_colors", "buffer"), &VoxelMesher::bake_colors);
ClassDB::bind_method(D_METHOD("get_voxel_scale"), &VoxelMesher::get_voxel_scale);
ClassDB::bind_method(D_METHOD("set_voxel_scale", "value"), &VoxelMesher::set_voxel_scale);

View File

@ -18,6 +18,7 @@
#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;
@ -35,6 +36,8 @@ public:
void reset();
void add_buffer(Ref<VoxelBuffer> voxels);
void add_mesh_data_resource(Transform local_transform, Ref<MeshDataResource> mesh);
void bake_colors(Ref<VoxelBuffer> voxels);
float get_voxel_scale() const;
void set_voxel_scale(const float voxel_scale);

View File

@ -0,0 +1,88 @@
#include "editor_import_collada_mdr.h"
String EditorImportColladaMdr::get_importer_name() const {
return "collada_mdr";
}
String EditorImportColladaMdr::get_visible_name() const {
return "Collada MDR";
}
void EditorImportColladaMdr::get_recognized_extensions(List<String> *p_extensions) const {
p_extensions->push_back("dae");
}
String EditorImportColladaMdr::get_save_extension() const {
return "res";
}
String EditorImportColladaMdr::get_resource_type() const {
return "MeshDataResource";
}
float EditorImportColladaMdr::get_priority() const {
return 1.0;
}
int EditorImportColladaMdr::get_preset_count() const {
return 0;
}
String EditorImportColladaMdr::get_preset_name(int p_idx) const {
return "";
}
void EditorImportColladaMdr::get_import_options(List<ImportOption> *r_options, int p_preset) const {
}
bool EditorImportColladaMdr::get_option_visibility(const String &p_option, const Map<StringName, Variant> &p_options) const {
return true;
}
Error EditorImportColladaMdr::import(const String &p_source_file, const String &p_save_path, const Map<StringName, Variant> &p_options, List<String> *r_platform_variants, List<String> *r_gen_files, Variant *r_metadata) {
Node *n = _importer->import_scene(p_source_file, 0, 15);
if (n == NULL) {
n->queue_delete();
return Error::ERR_PARSE_ERROR;
}
for (int i = 0; i < n->get_child_count(); ++i) {
Node *c = n->get_child(i);
print_error(String::num(i));
if (c == NULL) {
continue;
}
if (Object::cast_to<MeshInstance>(c)) {
MeshInstance *mi = Object::cast_to<MeshInstance>(c);
Ref<ArrayMesh> mesh = mi->get_mesh();
if (mesh.is_valid()) {
Ref<MeshDataResource> mdr;
mdr.instance();
mdr->set_array(mesh->surface_get_arrays(0));
n->queue_delete();
return ResourceSaver::save(p_save_path + "." + get_save_extension(), mdr);
}
}
}
n->queue_delete();
return Error::ERR_PARSE_ERROR;
}
EditorImportColladaMdr::EditorImportColladaMdr() {
_importer.instance();
}
EditorImportColladaMdr::~EditorImportColladaMdr() {
_importer.unref();
}

View File

@ -0,0 +1,42 @@
#ifndef EDITOR_IMPORT_COLLADA_MDR
#define EDITOR_IMPORT_COLLADA_MDR
#include "editor/import/editor_import_plugin.h"
#include "core/ustring.h"
#include "scene/main/node.h"
#include "scene/resources/mesh.h"
#include "scene/3d/mesh_instance.h"
#include "core/io/resource_saver.h"
#include "mesh_data_resource.h"
#include "editor/import/editor_import_collada.h"
class EditorImportColladaMdr : public EditorImportPlugin {
GDCLASS(EditorImportColladaMdr, EditorImportPlugin);
public:
virtual String get_importer_name() const;
virtual String get_visible_name() const;
virtual void get_recognized_extensions(List<String> *p_extensions) const;
virtual String get_save_extension() const;
virtual String get_resource_type() const;
virtual float get_priority() const;
virtual int get_preset_count() const;
virtual String get_preset_name(int p_idx) const;
virtual void get_import_options(List<ImportOption> *r_options, int p_preset = 0) const;
virtual bool get_option_visibility(const String &p_option, const Map<StringName, Variant> &p_options) const;
virtual Error import(const String &p_source_file, const String &p_save_path, const Map<StringName, Variant> &p_options, List<String> *r_platform_variants, List<String> *r_gen_files = NULL, Variant *r_metadata = NULL);
EditorImportColladaMdr();
~EditorImportColladaMdr();
private:
Ref<EditorSceneImporterCollada> _importer;
};
#endif

View File

@ -0,0 +1,22 @@
#include "editor_plugin_collada_mdr.h"
void EditorPluginColladaMdr::_notification(int p_what) {
switch (p_what) {
case NOTIFICATION_ENTER_TREE:
_importer.instance();
add_import_plugin(_importer);
break;
case NOTIFICATION_EXIT_TREE:
remove_import_plugin(_importer);
_importer.unref();
break;
}
}
EditorPluginColladaMdr::EditorPluginColladaMdr(EditorNode *node) {
_node = node;
}

View File

@ -0,0 +1,25 @@
#ifndef EDITOR_PLUGIN_COLLADA_MDR
#define EDITOR_PLUGIN_COLLADA_MDR
#include "editor/editor_plugin.h"
#include "core/ustring.h"
#include "editor_import_collada_mdr.h"
class EditorPluginColladaMdr : public EditorPlugin {
GDCLASS(EditorPluginColladaMdr, EditorPlugin);
public:
EditorPluginColladaMdr(EditorNode *node);
protected:
void _notification(int p_what);
private:
EditorNode *_node;
Ref<EditorImportColladaMdr> _importer;
};
#endif

View File

@ -0,0 +1,20 @@
#include "mesh_data_resource.h"
Array MeshDataResource::get_array() {
return _arrays;
}
void MeshDataResource::set_array(const Array &p_arrays) {
_arrays.clear();
_arrays = p_arrays.duplicate(true);
}
MeshDataResource::MeshDataResource() {
}
void MeshDataResource::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_array"), &MeshDataResource::get_array);
ClassDB::bind_method(D_METHOD("set_array", "array"), &MeshDataResource::set_array);
ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "array"), "set_array", "get_array");
}

View File

@ -0,0 +1,27 @@
#ifndef PROP_MESH_DATA_REOURCE_H
#define PROP_MESH_DATA_REOURCE_H
#include "core/resource.h"
#include "core/array.h"
#include "scene/resources/mesh.h"
class PropMeshDataResource : public Resource {
GDCLASS(PropMeshDataResource, Resource);
RES_BASE_EXTENSION("pmdres");
public:
Array get_array();
void set_array(const Array &p_arrays);
PropMeshDataResource();
protected:
static void _bind_methods();
private:
Array _arrays;
};
#endif

View File

@ -111,13 +111,6 @@ void VoxelChunk::set_voxel_world_bind(Node *world) {
_voxel_world = Object::cast_to<VoxelWorld>(world);
}
bool VoxelChunk::get_build_mesh() const {
return _build_mesh;
}
void VoxelChunk::set_build_mesh(bool value) {
_build_mesh = value;
}
bool VoxelChunk::get_create_collider() const {
return _create_collider;
}
@ -149,23 +142,31 @@ void VoxelChunk::build() {
_mesher->set_library(_library);
if (get_build_mesh()) {
if (has_method("_create_mesh")) {
call("_create_mesh");
} else {
_mesher->add_buffer(_buffer);
}
_mesher->reset();
finalize_mesh();
if (has_method("_create_mesh")) {
call("_create_mesh");
} else {
_mesher->add_buffer(_buffer);
}
finalize_mesh();
if (get_create_collider()) {
if (_body_rid == RID()) {
create_colliders();
}
build_collider();
}
_mesher->reset();
if (_props.size() > 0) {
build_prop_mesh();
if (get_create_collider()) {
build_prop_collider();
}
}
_mesher->reset();
}
void VoxelChunk::create_mesher() {
@ -207,6 +208,10 @@ void VoxelChunk::create_colliders() {
}
void VoxelChunk::build_collider() {
if (_body_rid == RID()) {
create_colliders();
}
_mesher->build_collider(_shape_rid);
}
@ -223,7 +228,6 @@ void VoxelChunk::remove_colliders() {
void VoxelChunk::set_enabled(bool p_enabled) {
_enabled = p_enabled;
}
bool VoxelChunk::is_enabled() const {
@ -291,6 +295,7 @@ void VoxelChunk::create_meshes() {
ERR_FAIL_COND(_voxel_world == NULL);
ERR_FAIL_COND(!get_library().is_valid());
ERR_FAIL_COND(!get_library()->get_material().is_valid());
_mesh_instance_rid = VS::get_singleton()->instance_create();
@ -318,6 +323,133 @@ void VoxelChunk::remove_meshes() {
}
}
void VoxelChunk::add_prop(const Transform local_transform, const Ref<MeshDataResource> mesh) {
VCPropData data;
data.transform = local_transform;
data.mesh_data = mesh;
_props.push_back(data);
}
void VoxelChunk::clear_props() {
_props.clear();
}
void VoxelChunk::create_prop_mesh() {
ERR_FAIL_COND(_voxel_world == NULL);
ERR_FAIL_COND(!get_library().is_valid());
ERR_FAIL_COND(!get_library()->get_prop_material().is_valid());
_prop_mesh_instance_rid = VS::get_singleton()->instance_create();
if (get_library()->get_prop_material().is_valid()) {
VS::get_singleton()->instance_geometry_set_material_override(_prop_mesh_instance_rid, get_library()->get_prop_material()->get_rid());
}
if (get_voxel_world()->get_world().is_valid())
VS::get_singleton()->instance_set_scenario(_prop_mesh_instance_rid, get_voxel_world()->get_world()->get_scenario());
_prop_mesh_rid = VS::get_singleton()->mesh_create();
VS::get_singleton()->instance_set_base(_prop_mesh_instance_rid, _prop_mesh_rid);
VS::get_singleton()->instance_set_transform(_prop_mesh_instance_rid, Transform(Basis(), Vector3(_chunk_position.x * _chunk_size.x * _voxel_scale, _chunk_position.y * _chunk_size.y * _voxel_scale, _chunk_position.z * _chunk_size.z * _voxel_scale)));
}
void VoxelChunk::remove_prop_mesh() {
if (_prop_mesh_instance_rid != RID()) {
VS::get_singleton()->free(_prop_mesh_instance_rid);
VS::get_singleton()->free(_prop_mesh_rid);
_prop_mesh_instance_rid = RID();
_prop_mesh_rid = RID();
}
}
void VoxelChunk::build_prop_mesh() {
if (_prop_mesh_rid == RID()) {
create_prop_mesh();
}
for (int i = 0; i < _props.size(); ++i) {
_mesher->add_mesh_data_resource(_props[i].transform, _props[i].mesh_data);
}
_mesher->bake_colors(_buffer);
_mesher->build_mesh(_prop_mesh_rid);
}
void VoxelChunk::create_prop_colliders() {
ERR_FAIL_COND(_voxel_world == NULL);
_prop_shape_rid = PhysicsServer::get_singleton()->shape_create(PhysicsServer::SHAPE_CONCAVE_POLYGON);
_prop_body_rid = PhysicsServer::get_singleton()->body_create(PhysicsServer::BODY_MODE_STATIC);
PhysicsServer::get_singleton()->body_set_collision_layer(_prop_body_rid, 1);
PhysicsServer::get_singleton()->body_set_collision_mask(_prop_body_rid, 1);
PhysicsServer::get_singleton()->body_add_shape(_prop_body_rid, _prop_shape_rid);
PhysicsServer::get_singleton()->body_set_state(_prop_body_rid, PhysicsServer::BODY_STATE_TRANSFORM, Transform(Basis(), Vector3(_chunk_position.x * _chunk_size.x * _voxel_scale, _chunk_position.y * _chunk_size.y * _voxel_scale, _chunk_position.z * _chunk_size.z * _voxel_scale)));
PhysicsServer::get_singleton()->body_set_space(_prop_body_rid, get_voxel_world()->get_world()->get_space());
}
void VoxelChunk::build_prop_collider() {
if (_prop_shape_rid == RID()) {
create_prop_colliders();
}
_mesher->build_collider(_prop_shape_rid);
}
void VoxelChunk::remove_prop_colliders() {
if (_prop_body_rid != RID()) {
PhysicsServer::get_singleton()->free(_prop_body_rid);
PhysicsServer::get_singleton()->free(_prop_shape_rid);
_prop_body_rid = RID();
_prop_shape_rid = RID();
}
}
void VoxelChunk::add_spawned_prop(const Ref<PackedScene> scene) {
ERR_FAIL_COND(!scene.is_valid());
ERR_FAIL_COND(get_voxel_world() == NULL);
Node *n = scene->instance();
ERR_FAIL_COND(n == NULL);
get_voxel_world()->add_child(n);
n->set_owner(get_voxel_world());
_spawned_props.push_back(n);
}
void VoxelChunk::add_spawned_prop_spatial(const Transform transform, const Ref<PackedScene> scene) {
ERR_FAIL_COND(!scene.is_valid());
ERR_FAIL_COND(get_voxel_world() == NULL);
Node *n = scene->instance();
ERR_FAIL_COND(n == NULL);
get_voxel_world()->add_child(n);
n->set_owner(get_voxel_world());
_spawned_props.push_back(n);
Spatial *spatial = Object::cast_to<Spatial>(n);
ERR_FAIL_COND(spatial == NULL);
spatial->set_transform(transform);
}
void VoxelChunk::clear_spawned_props() {
for (int i = 0; i < _spawned_props.size(); ++i) {
_spawned_props[i]->queue_delete();
}
_spawned_props.clear();
}
void VoxelChunk::create_debug_immediate_geometry() {
ERR_FAIL_COND(_voxel_world == NULL);
ERR_FAIL_COND(_debug_drawer != NULL);
@ -338,6 +470,15 @@ void VoxelChunk::free_debug_immediate_geometry() {
}
}
void VoxelChunk::free() {
free_debug_immediate_geometry();
remove_meshes();
remove_colliders();
remove_prop_mesh();
remove_prop_colliders();
clear_spawned_props();
}
void VoxelChunk::draw_cross_voxels(Vector3 pos) {
pos *= _voxel_scale;
@ -445,6 +586,9 @@ VoxelChunk::VoxelChunk() {
VoxelChunk::~VoxelChunk() {
remove_meshes();
remove_colliders();
remove_prop_mesh();
remove_prop_colliders();
//do not call free here, the app will crash on exit, if you try to free nodes too.
_voxel_lights.clear();
@ -509,10 +653,6 @@ void VoxelChunk::_bind_methods() {
ADD_GROUP("Meshing", "meshing");
ClassDB::bind_method(D_METHOD("meshing_get_build_mesh"), &VoxelChunk::get_build_mesh);
ClassDB::bind_method(D_METHOD("meshing_set_build_mesh", "value"), &VoxelChunk::set_build_mesh);
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "meshing_build_mesh"), "meshing_set_build_mesh", "meshing_get_build_mesh");
ClassDB::bind_method(D_METHOD("meshing_get_create_collider"), &VoxelChunk::get_create_collider);
ClassDB::bind_method(D_METHOD("meshing_set_create_collider", "value"), &VoxelChunk::set_create_collider);
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "meshing_create_collider"), "meshing_set_create_collider", "meshing_get_create_collider");
@ -540,9 +680,21 @@ void VoxelChunk::_bind_methods() {
ClassDB::bind_method(D_METHOD("bake_light", "light"), &VoxelChunk::bake_light);
ClassDB::bind_method(D_METHOD("clear_baked_lights"), &VoxelChunk::clear_baked_lights);
ClassDB::bind_method(D_METHOD("add_prop", "transform", "mesh"), &VoxelChunk::add_prop);
ClassDB::bind_method(D_METHOD("clear_props"), &VoxelChunk::clear_props);
ClassDB::bind_method(D_METHOD("create_prop_mesh"), &VoxelChunk::create_prop_mesh);
ClassDB::bind_method(D_METHOD("remove_prop_mesh"), &VoxelChunk::remove_prop_mesh);
ClassDB::bind_method(D_METHOD("build_prop_mesh"), &VoxelChunk::build_prop_mesh);
ClassDB::bind_method(D_METHOD("add_spawned_prop", "scene"), &VoxelChunk::add_spawned_prop);
ClassDB::bind_method(D_METHOD("add_spawned_prop_spatial", "transform", "scene"), &VoxelChunk::add_spawned_prop_spatial);
ClassDB::bind_method(D_METHOD("clear_spawned_props"), &VoxelChunk::clear_spawned_props);
ClassDB::bind_method(D_METHOD("build"), &VoxelChunk::build);
ClassDB::bind_method(D_METHOD("finalize_mesh"), &VoxelChunk::finalize_mesh);
ClassDB::bind_method(D_METHOD("free"), &VoxelChunk::free);
ClassDB::bind_method(D_METHOD("clear"), &VoxelChunk::clear);
ClassDB::bind_method(D_METHOD("create_mesher"), &VoxelChunk::create_mesher);

View File

@ -6,24 +6,26 @@
#include "core/reference.h"
#include "core/ustring.h"
#include "scene/3d/mesh_instance.h"
//#include "scene/3d/spatial.h"
#include "scene/resources/packed_scene.h"
#include "core/array.h"
#include "scene/3d/collision_shape.h"
#include "scene/3d/physics_body.h"
#include "scene/resources/concave_polygon_shape.h"
#include "core/array.h"
#include "scene/3d/spatial.h"
#include "voxel_world.h"
#include "../data/voxel_light.h"
#include "../meshers/voxel_mesher.h"
#include "../meshers/cubic_mesher/voxel_mesher_cubic.h"
#include "../meshers/voxel_mesher.h"
#include "../library/voxel_surface.h"
#include "../library/voxelman_library.h"
#include "voxel_buffer.h"
#include "../../entity_spell_system/meshes/mesh_data_resource.h"
class VoxelChunk : public Reference {
GDCLASS(VoxelChunk, Reference);
@ -65,9 +67,6 @@ public:
void set_voxel_world(VoxelWorld *world);
void set_voxel_world_bind(Node *world);
bool get_build_mesh() const;
void set_build_mesh(bool value);
bool get_create_collider() const;
void set_create_collider(bool value);
@ -105,9 +104,25 @@ public:
void create_meshes();
void remove_meshes();
void add_prop(const Transform transform, const Ref<MeshDataResource> mesh);
void clear_props();
void create_prop_mesh();
void remove_prop_mesh();
void build_prop_mesh();
void create_prop_colliders();
void build_prop_collider();
void remove_prop_colliders();
void add_spawned_prop(const Ref<PackedScene> scene);
void add_spawned_prop_spatial(const Transform transform, const Ref<PackedScene> scene);
void clear_spawned_props();
void create_debug_immediate_geometry();
void free_debug_immediate_geometry();
void free();
void draw_debug_voxels(int max, Color color = Color(1, 1, 1));
void draw_debug_voxel_lights();
void draw_cross_voxels(Vector3 pos);
@ -116,6 +131,12 @@ public:
VoxelChunk();
~VoxelChunk();
protected:
struct VCPropData {
Transform transform;
Ref<MeshDataResource> mesh_data;
};
protected:
static void _bind_methods();
@ -135,6 +156,7 @@ protected:
NodePath _library_path;
Ref<VoxelmanLibrary> _library;
//voxel mesh
RID _mesh_rid;
RID _mesh_instance_rid;
@ -143,6 +165,19 @@ protected:
Ref<VoxelMesher> _mesher;
//mergeable props
Vector<VCPropData> _props;
RID _prop_mesh_rid;
RID _prop_mesh_instance_rid;
RID _prop_shape_rid;
RID _prop_body_rid;
//spawned props
Vector<Node *> _spawned_props;
//debug
ImmediateGeometry *_debug_drawer;
bool _build_mesh;