Now chunks are only laid out on a 2d grid. Removed the y coordinate from everywhere. The meshers doesn't work properly yet.

This commit is contained in:
Relintai 2021-04-16 17:13:54 +02:00
parent 603581f6e0
commit 025c902b44
14 changed files with 801 additions and 956 deletions

View File

@ -39,6 +39,7 @@ void TerramanLevelGeneratorFlat::set_channel_map(const Dictionary &map) {
} }
void TerramanLevelGeneratorFlat::_generate_chunk(Ref<TerraChunk> chunk) { void TerramanLevelGeneratorFlat::_generate_chunk(Ref<TerraChunk> chunk) {
/*
int dymin = chunk->get_position_y() * chunk->get_size_y(); int dymin = chunk->get_position_y() * chunk->get_size_y();
int dymax = dymin + chunk->get_size_y() + chunk->get_margin_end(); int dymax = dymin + chunk->get_size_y() + chunk->get_margin_end();
@ -80,6 +81,7 @@ void TerramanLevelGeneratorFlat::_generate_chunk(Ref<TerraChunk> chunk) {
keyptr = _channel_map.next(keyptr); keyptr = _channel_map.next(keyptr);
} }
*/
} }
TerramanLevelGeneratorFlat::TerramanLevelGeneratorFlat() { TerramanLevelGeneratorFlat::TerramanLevelGeneratorFlat() {

View File

@ -41,7 +41,6 @@ void TerraMesherBlocky::_add_chunk(Ref<TerraChunk> p_chunk) {
// chunk->generate_ao(); // chunk->generate_ao();
int x_size = chunk->get_size_x(); int x_size = chunk->get_size_x();
int y_size = chunk->get_size_y();
int z_size = chunk->get_size_z(); int z_size = chunk->get_size_z();
float voxel_scale = get_voxel_scale(); float voxel_scale = get_voxel_scale();
@ -86,407 +85,340 @@ void TerraMesherBlocky::_add_chunk(Ref<TerraChunk> p_chunk) {
liquids.push_back(static_cast<uint8_t>(i + 1)); liquids.push_back(static_cast<uint8_t>(i + 1));
} }
for (int y = chunk->get_margin_start(); y < y_size + chunk->get_margin_start(); ++y) { for (int z = chunk->get_margin_start(); z < z_size + chunk->get_margin_start(); ++z) {
for (int z = chunk->get_margin_start(); z < z_size + chunk->get_margin_start(); ++z) { for (int x = chunk->get_margin_start(); x < x_size + chunk->get_margin_start(); ++x) {
for (int x = chunk->get_margin_start(); x < x_size + chunk->get_margin_start(); ++x) {
int index = chunk->get_data_index(x, y, z); int index = chunk->get_data_index(x, z);
int indexxp = chunk->get_data_index(x + 1, y, z); int indexxp = chunk->get_data_index(x + 1, z);
int indexxn = chunk->get_data_index(x - 1, y, z); int indexxn = chunk->get_data_index(x - 1, z);
int indexyp = chunk->get_data_index(x, y + 1, z); int indexzp = chunk->get_data_index(x, z + 1);
int indexyn = chunk->get_data_index(x, y - 1, z); int indexzn = chunk->get_data_index(x, z - 1);
int indexzp = chunk->get_data_index(x, y, z + 1);
int indexzn = chunk->get_data_index(x, y, z - 1);
uint8_t type = channel_type[index]; uint8_t type = channel_type[index];
if (type == 0) if (type == 0)
continue; continue;
if (liquids.find(type) != -1) if (liquids.find(type) != -1)
continue; continue;
Ref<TerraSurface> surface = _library->voxel_surface_get(type - 1); Ref<TerraSurface> surface = _library->voxel_surface_get(type - 1);
if (!surface.is_valid()) if (!surface.is_valid())
continue; continue;
uint8_t neighbours[] = { uint8_t neighbours[] = {
channel_type[indexxp], channel_type[indexxp],
channel_type[indexxn], channel_type[indexxn],
channel_type[indexyp], channel_type[indexzp],
channel_type[indexyn], channel_type[indexzn],
channel_type[indexzp], };
channel_type[indexzn],
for (int i = 0; i < 6; ++i) {
if (liquids.find(neighbours[i]) != -1) {
neighbours[i] = 0;
}
}
//x + 1
if (neighbours[0] == 0) {
if (use_lighting) {
light = Color(channel_color_r[indexxp] / 255.0,
channel_color_g[indexxp] / 255.0,
channel_color_b[indexxp] / 255.0);
float ao = 0;
if (use_ao)
ao = channel_ao[indexxp] / 255.0;
if (use_rao) {
float rao = channel_rao[indexxp] / 255.0;
ao += rao;
}
light += base_light;
if (ao > 0)
light -= Color(ao, ao, ao) * _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);
}
int vc = get_vertex_count();
add_indices(vc + 2);
add_indices(vc + 1);
add_indices(vc + 0);
add_indices(vc + 3);
add_indices(vc + 2);
add_indices(vc + 0);
Vector2 uvs[] = {
surface->transform_uv_scaled(TerraSurface::TERRA_SIDE_SIDE, Vector2(0, 1), x % get_texture_scale(), z % get_texture_scale(), get_texture_scale()),
surface->transform_uv_scaled(TerraSurface::TERRA_SIDE_SIDE, Vector2(0, 0), x % get_texture_scale(), z % get_texture_scale(), get_texture_scale()),
surface->transform_uv_scaled(TerraSurface::TERRA_SIDE_SIDE, Vector2(1, 0), x % get_texture_scale(), z % get_texture_scale(), get_texture_scale()),
surface->transform_uv_scaled(TerraSurface::TERRA_SIDE_SIDE, Vector2(1, 1), x % get_texture_scale(), z % get_texture_scale(), get_texture_scale())
}; };
for (int i = 0; i < 6; ++i) { Vector3 verts[] = {
if (liquids.find(neighbours[i]) != -1) { Vector3(1, 0, 0) * voxel_scale + Vector3(x - 1, -1, z - 1) * voxel_scale,
neighbours[i] = 0; Vector3(1, 1, 0) * voxel_scale + Vector3(x - 1, -1, z - 1) * voxel_scale,
} Vector3(1, 1, 1) * voxel_scale + Vector3(x - 1, -1, z - 1) * voxel_scale,
Vector3(1, 0, 1) * voxel_scale + Vector3(x - 1, -1, z - 1) * voxel_scale
};
for (int i = 0; i < 4; ++i) {
add_normal(Vector3(1, 0, 0));
if (use_lighting || _always_add_colors)
add_color(light);
add_uv(uvs[i]);
add_vertex(verts[i]);
} }
}
//x + 1 //x - 1
if (neighbours[0] == 0) { if (neighbours[1] == 0) {
if (use_lighting) { if (use_lighting) {
light = Color(channel_color_r[indexxp] / 255.0, light = Color(channel_color_r[indexxn] / 255.0,
channel_color_g[indexxp] / 255.0, channel_color_g[indexxn] / 255.0,
channel_color_b[indexxp] / 255.0); channel_color_b[indexxn] / 255.0);
float ao = 0; float ao = 0;
if (use_ao) if (use_ao)
ao = channel_ao[indexxp] / 255.0; ao = channel_ao[indexxn] / 255.0;
if (use_rao) { if (use_rao) {
float rao = channel_rao[indexxp] / 255.0; float rao = channel_rao[indexxn] / 255.0;
ao += rao; ao += rao;
}
light += base_light;
if (ao > 0)
light -= Color(ao, ao, ao) * _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);
} }
int vc = get_vertex_count(); light += base_light;
add_indices(vc + 2);
add_indices(vc + 1);
add_indices(vc + 0);
add_indices(vc + 3);
add_indices(vc + 2);
add_indices(vc + 0);
Vector2 uvs[] = { if (ao > 0)
surface->transform_uv_scaled(TerraSurface::TERRA_SIDE_SIDE, Vector2(0, 1), x % get_texture_scale(), z % get_texture_scale(), get_texture_scale()), light -= Color(ao, ao, ao) * _ao_strength;
surface->transform_uv_scaled(TerraSurface::TERRA_SIDE_SIDE, Vector2(0, 0), x % get_texture_scale(), z % get_texture_scale(), get_texture_scale()),
surface->transform_uv_scaled(TerraSurface::TERRA_SIDE_SIDE, Vector2(1, 0), x % get_texture_scale(), z % get_texture_scale(), get_texture_scale()),
surface->transform_uv_scaled(TerraSurface::TERRA_SIDE_SIDE, Vector2(1, 1), x % get_texture_scale(), z % get_texture_scale(), get_texture_scale())
};
Vector3 verts[] = {
Vector3(1, 0, 0) * voxel_scale + Vector3(x - 1, y - 1, z - 1) * voxel_scale,
Vector3(1, 1, 0) * voxel_scale + Vector3(x - 1, y - 1, z - 1) * voxel_scale,
Vector3(1, 1, 1) * voxel_scale + Vector3(x - 1, y - 1, z - 1) * voxel_scale,
Vector3(1, 0, 1) * voxel_scale + Vector3(x - 1, y - 1, z - 1) * voxel_scale
};
for (int i = 0; i < 4; ++i) {
add_normal(Vector3(1, 0, 0));
if (use_lighting || _always_add_colors)
add_color(light);
add_uv(uvs[i]);
add_vertex(verts[i]);
}
}
//x - 1
if (neighbours[1] == 0) {
if (use_lighting) {
light = Color(channel_color_r[indexxn] / 255.0,
channel_color_g[indexxn] / 255.0,
channel_color_b[indexxn] / 255.0);
float ao = 0;
if (use_ao)
ao = channel_ao[indexxn] / 255.0;
if (use_rao) {
float rao = channel_rao[indexxn] / 255.0;
ao += rao;
}
light += base_light;
if (ao > 0)
light -= Color(ao, ao, ao) * _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);
}
int vc = get_vertex_count();
add_indices(vc + 0);
add_indices(vc + 1);
add_indices(vc + 2);
add_indices(vc + 0);
add_indices(vc + 2);
add_indices(vc + 3);
Vector2 uvs[] = {
surface->transform_uv_scaled(TerraSurface::TERRA_SIDE_SIDE, Vector2(0, 1), x % get_texture_scale(), z % get_texture_scale(), get_texture_scale()),
surface->transform_uv_scaled(TerraSurface::TERRA_SIDE_SIDE, Vector2(0, 0), x % get_texture_scale(), z % get_texture_scale(), get_texture_scale()),
surface->transform_uv_scaled(TerraSurface::TERRA_SIDE_SIDE, Vector2(1, 0), x % get_texture_scale(), z % get_texture_scale(), get_texture_scale()),
surface->transform_uv_scaled(TerraSurface::TERRA_SIDE_SIDE, Vector2(1, 1), x % get_texture_scale(), z % get_texture_scale(), get_texture_scale())
};
Vector3 verts[] = {
Vector3(0, 0, 0) * voxel_scale + Vector3(x - 1, y - 1, z - 1) * voxel_scale,
Vector3(0, 1, 0) * voxel_scale + Vector3(x - 1, y - 1, z - 1) * voxel_scale,
Vector3(0, 1, 1) * voxel_scale + Vector3(x - 1, y - 1, z - 1) * voxel_scale,
Vector3(0, 0, 1) * voxel_scale + Vector3(x - 1, y - 1, z - 1) * voxel_scale
};
for (int i = 0; i < 4; ++i) {
add_normal(Vector3(-1, 0, 0));
if (use_lighting || _always_add_colors)
add_color(light);
add_uv(uvs[i]);
add_vertex(verts[i]);
}
}
//y + 1
if (neighbours[2] == 0) {
if (use_lighting) {
light = Color(channel_color_r[indexyp] / 255.0,
channel_color_g[indexyp] / 255.0,
channel_color_b[indexyp] / 255.0);
float ao = 0;
if (use_ao)
ao = channel_ao[indexyp] / 255.0;
if (use_rao) {
float rao = channel_rao[indexyp] / 255.0;
ao += rao;
}
light += base_light;
if (ao > 0)
light -= Color(ao, ao, ao) * _ao_strength;
}
light.r = CLAMP(light.r, 0, 1.0); light.r = CLAMP(light.r, 0, 1.0);
light.g = CLAMP(light.g, 0, 1.0); light.g = CLAMP(light.g, 0, 1.0);
light.b = CLAMP(light.b, 0, 1.0); light.b = CLAMP(light.b, 0, 1.0);
int vc = get_vertex_count();
add_indices(vc + 2);
add_indices(vc + 1);
add_indices(vc + 0);
add_indices(vc + 3);
add_indices(vc + 2);
add_indices(vc + 0);
Vector2 uvs[] = {
surface->transform_uv_scaled(TerraSurface::TERRA_SIDE_SIDE, Vector2(0, 1), x % get_texture_scale(), z % get_texture_scale(), get_texture_scale()),
surface->transform_uv_scaled(TerraSurface::TERRA_SIDE_SIDE, Vector2(0, 0), x % get_texture_scale(), z % get_texture_scale(), get_texture_scale()),
surface->transform_uv_scaled(TerraSurface::TERRA_SIDE_SIDE, Vector2(1, 0), x % get_texture_scale(), z % get_texture_scale(), get_texture_scale()),
surface->transform_uv_scaled(TerraSurface::TERRA_SIDE_SIDE, Vector2(1, 1), x % get_texture_scale(), z % get_texture_scale(), get_texture_scale())
};
Vector3 verts[] = {
Vector3(1, 1, 0) * voxel_scale + Vector3(x - 1, y - 1, z - 1) * voxel_scale,
Vector3(0, 1, 0) * voxel_scale + Vector3(x - 1, y - 1, z - 1) * voxel_scale,
Vector3(0, 1, 1) * voxel_scale + Vector3(x - 1, y - 1, z - 1) * voxel_scale,
Vector3(1, 1, 1) * voxel_scale + Vector3(x - 1, y - 1, z - 1) * voxel_scale
};
for (int i = 0; i < 4; ++i) {
add_normal(Vector3(0, 1, 0));
if (use_lighting || _always_add_colors)
add_color(light);
add_uv(uvs[i]);
add_vertex(verts[i]);
}
} }
//y - 1 int vc = get_vertex_count();
if (neighbours[3] == 0) { add_indices(vc + 0);
if (use_lighting) { add_indices(vc + 1);
light = Color(channel_color_r[indexyn] / 255.0, add_indices(vc + 2);
channel_color_g[indexyn] / 255.0,
channel_color_b[indexyn] / 255.0);
float ao = 0; add_indices(vc + 0);
add_indices(vc + 2);
add_indices(vc + 3);
if (use_ao) Vector2 uvs[] = {
ao = channel_ao[indexyn] / 255.0; surface->transform_uv_scaled(TerraSurface::TERRA_SIDE_SIDE, Vector2(0, 1), x % get_texture_scale(), z % get_texture_scale(), get_texture_scale()),
surface->transform_uv_scaled(TerraSurface::TERRA_SIDE_SIDE, Vector2(0, 0), x % get_texture_scale(), z % get_texture_scale(), get_texture_scale()),
surface->transform_uv_scaled(TerraSurface::TERRA_SIDE_SIDE, Vector2(1, 0), x % get_texture_scale(), z % get_texture_scale(), get_texture_scale()),
surface->transform_uv_scaled(TerraSurface::TERRA_SIDE_SIDE, Vector2(1, 1), x % get_texture_scale(), z % get_texture_scale(), get_texture_scale())
};
if (use_rao) { Vector3 verts[] = {
float rao = channel_rao[indexyn] / 255.0; Vector3(0, 0, 0) * voxel_scale + Vector3(x - 1, -1, z - 1) * voxel_scale,
ao += rao; Vector3(0, 1, 0) * voxel_scale + Vector3(x - 1, -1, z - 1) * voxel_scale,
} Vector3(0, 1, 1) * voxel_scale + Vector3(x - 1, -1, z - 1) * voxel_scale,
Vector3(0, 0, 1) * voxel_scale + Vector3(x - 1, -1, z - 1) * voxel_scale
};
light += base_light; for (int i = 0; i < 4; ++i) {
add_normal(Vector3(-1, 0, 0));
if (ao > 0) if (use_lighting || _always_add_colors)
light -= Color(ao, ao, ao) * _ao_strength; add_color(light);
add_uv(uvs[i]);
add_vertex(verts[i]);
}
}
/*
//y + 1
if (neighbours[2] == 0) {
if (use_lighting) {
light = Color(channel_color_r[indexyp] / 255.0,
channel_color_g[indexyp] / 255.0,
channel_color_b[indexyp] / 255.0);
float ao = 0;
if (use_ao)
ao = channel_ao[indexyp] / 255.0;
if (use_rao) {
float rao = channel_rao[indexyp] / 255.0;
ao += rao;
} }
light += base_light;
if (ao > 0)
light -= Color(ao, ao, ao) * _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);
int vc = get_vertex_count();
add_indices(vc + 2);
add_indices(vc + 1);
add_indices(vc + 0);
add_indices(vc + 3);
add_indices(vc + 2);
add_indices(vc + 0);
Vector2 uvs[] = {
surface->transform_uv_scaled(TerraSurface::TERRA_SIDE_SIDE, Vector2(0, 1), x % get_texture_scale(), z % get_texture_scale(), get_texture_scale()),
surface->transform_uv_scaled(TerraSurface::TERRA_SIDE_SIDE, Vector2(0, 0), x % get_texture_scale(), z % get_texture_scale(), get_texture_scale()),
surface->transform_uv_scaled(TerraSurface::TERRA_SIDE_SIDE, Vector2(1, 0), x % get_texture_scale(), z % get_texture_scale(), get_texture_scale()),
surface->transform_uv_scaled(TerraSurface::TERRA_SIDE_SIDE, Vector2(1, 1), x % get_texture_scale(), z % get_texture_scale(), get_texture_scale())
};
Vector3 verts[] = {
Vector3(1, 1, 0) * voxel_scale + Vector3(x - 1, y - 1, z - 1) * voxel_scale,
Vector3(0, 1, 0) * voxel_scale + Vector3(x - 1, y - 1, z - 1) * voxel_scale,
Vector3(0, 1, 1) * voxel_scale + Vector3(x - 1, y - 1, z - 1) * voxel_scale,
Vector3(1, 1, 1) * voxel_scale + Vector3(x - 1, y - 1, z - 1) * voxel_scale
};
for (int i = 0; i < 4; ++i) {
add_normal(Vector3(0, 1, 0));
if (use_lighting || _always_add_colors)
add_color(light);
add_uv(uvs[i]);
add_vertex(verts[i]);
}
}
*/
//z + 1
if (neighbours[4] == 0) {
if (use_lighting) {
light = Color(channel_color_r[indexzp] / 255.0,
channel_color_g[indexzp] / 255.0,
channel_color_b[indexzp] / 255.0);
float ao = 0;
if (use_ao)
ao = channel_ao[indexzp] / 255.0;
if (use_rao) {
float rao = channel_rao[indexzp] / 255.0;
ao += rao;
}
light += base_light;
if (ao > 0)
light -= Color(ao, ao, ao) * _ao_strength;
light.r = CLAMP(light.r, 0, 1.0); light.r = CLAMP(light.r, 0, 1.0);
light.g = CLAMP(light.g, 0, 1.0); light.g = CLAMP(light.g, 0, 1.0);
light.b = CLAMP(light.b, 0, 1.0); light.b = CLAMP(light.b, 0, 1.0);
int vc = get_vertex_count();
add_indices(vc + 0);
add_indices(vc + 1);
add_indices(vc + 2);
add_indices(vc + 0);
add_indices(vc + 2);
add_indices(vc + 3);
Vector2 uvs[] = {
surface->transform_uv_scaled(TerraSurface::TERRA_SIDE_SIDE, Vector2(0, 1), x % get_texture_scale(), z % get_texture_scale(), get_texture_scale()),
surface->transform_uv_scaled(TerraSurface::TERRA_SIDE_SIDE, Vector2(0, 0), x % get_texture_scale(), z % get_texture_scale(), get_texture_scale()),
surface->transform_uv_scaled(TerraSurface::TERRA_SIDE_SIDE, Vector2(1, 0), x % get_texture_scale(), z % get_texture_scale(), get_texture_scale()),
surface->transform_uv_scaled(TerraSurface::TERRA_SIDE_SIDE, Vector2(1, 1), x % get_texture_scale(), z % get_texture_scale(), get_texture_scale())
};
Vector3 verts[] = {
Vector3(1, 0, 0) * voxel_scale + Vector3(x - 1, y - 1, z - 1) * voxel_scale,
Vector3(0, 0, 0) * voxel_scale + Vector3(x - 1, y - 1, z - 1) * voxel_scale,
Vector3(0, 0, 1) * voxel_scale + Vector3(x - 1, y - 1, z - 1) * voxel_scale,
Vector3(1, 0, 1) * voxel_scale + Vector3(x - 1, y - 1, z - 1) * voxel_scale
};
for (int i = 0; i < 4; ++i) {
add_normal(Vector3(0, -1, 0));
if (use_lighting || _always_add_colors)
add_color(light);
add_uv(uvs[i]);
add_vertex(verts[i]);
}
} }
//z + 1 int vc = get_vertex_count();
if (neighbours[4] == 0) { add_indices(vc + 2);
if (use_lighting) { add_indices(vc + 1);
light = Color(channel_color_r[indexzp] / 255.0, add_indices(vc + 0);
channel_color_g[indexzp] / 255.0, add_indices(vc + 3);
channel_color_b[indexzp] / 255.0); add_indices(vc + 2);
add_indices(vc + 0);
float ao = 0; Vector2 uvs[] = {
surface->transform_uv_scaled(TerraSurface::TERRA_SIDE_SIDE, Vector2(0, 1), x % get_texture_scale(), z % get_texture_scale(), get_texture_scale()),
surface->transform_uv_scaled(TerraSurface::TERRA_SIDE_SIDE, Vector2(0, 0), x % get_texture_scale(), z % get_texture_scale(), get_texture_scale()),
surface->transform_uv_scaled(TerraSurface::TERRA_SIDE_SIDE, Vector2(1, 0), x % get_texture_scale(), z % get_texture_scale(), get_texture_scale()),
surface->transform_uv_scaled(TerraSurface::TERRA_SIDE_SIDE, Vector2(1, 1), x % get_texture_scale(), z % get_texture_scale(), get_texture_scale())
};
if (use_ao) Vector3 verts[] = {
ao = channel_ao[indexzp] / 255.0; Vector3(1, 0, 1) * voxel_scale + Vector3(x - 1, -1, z - 1) * voxel_scale,
Vector3(1, 1, 1) * voxel_scale + Vector3(x - 1, -1, z - 1) * voxel_scale,
Vector3(0, 1, 1) * voxel_scale + Vector3(x - 1, -1, z - 1) * voxel_scale,
Vector3(0, 0, 1) * voxel_scale + Vector3(x - 1, -1, z - 1) * voxel_scale
};
if (use_rao) { for (int i = 0; i < 4; ++i) {
float rao = channel_rao[indexzp] / 255.0; add_normal(Vector3(0, 0, 1));
ao += rao;
}
light += base_light; if (use_lighting || _always_add_colors)
add_color(light);
if (ao > 0) add_uv(uvs[i]);
light -= Color(ao, ao, ao) * _ao_strength; add_vertex(verts[i]);
}
}
light.r = CLAMP(light.r, 0, 1.0); //z - 1
light.g = CLAMP(light.g, 0, 1.0); if (neighbours[5] == 0) {
light.b = CLAMP(light.b, 0, 1.0); if (use_lighting) {
light = Color(channel_color_r[indexzn] / 255.0,
channel_color_g[indexzn] / 255.0,
channel_color_b[indexzn] / 255.0);
float ao = 0;
if (use_ao)
ao = channel_ao[indexzn] / 255.0;
if (use_rao) {
float rao = channel_rao[indexzn] / 255.0;
ao += rao;
} }
int vc = get_vertex_count(); light += base_light;
add_indices(vc + 2);
add_indices(vc + 1);
add_indices(vc + 0);
add_indices(vc + 3);
add_indices(vc + 2);
add_indices(vc + 0);
Vector2 uvs[] = { if (ao > 0)
surface->transform_uv_scaled(TerraSurface::TERRA_SIDE_SIDE, Vector2(0, 1), x % get_texture_scale(), z % get_texture_scale(), get_texture_scale()), light -= Color(ao, ao, ao) * _ao_strength;
surface->transform_uv_scaled(TerraSurface::TERRA_SIDE_SIDE, Vector2(0, 0), x % get_texture_scale(), z % get_texture_scale(), get_texture_scale()),
surface->transform_uv_scaled(TerraSurface::TERRA_SIDE_SIDE, Vector2(1, 0), x % get_texture_scale(), z % get_texture_scale(), get_texture_scale()),
surface->transform_uv_scaled(TerraSurface::TERRA_SIDE_SIDE, Vector2(1, 1), x % get_texture_scale(), z % get_texture_scale(), get_texture_scale())
};
Vector3 verts[] = { light.r = CLAMP(light.r, 0, 1.0);
Vector3(1, 0, 1) * voxel_scale + Vector3(x - 1, y - 1, z - 1) * voxel_scale, light.g = CLAMP(light.g, 0, 1.0);
Vector3(1, 1, 1) * voxel_scale + Vector3(x - 1, y - 1, z - 1) * voxel_scale, light.b = CLAMP(light.b, 0, 1.0);
Vector3(0, 1, 1) * voxel_scale + Vector3(x - 1, y - 1, z - 1) * voxel_scale,
Vector3(0, 0, 1) * voxel_scale + Vector3(x - 1, y - 1, z - 1) * voxel_scale
};
for (int i = 0; i < 4; ++i) {
add_normal(Vector3(0, 0, 1));
if (use_lighting || _always_add_colors)
add_color(light);
add_uv(uvs[i]);
add_vertex(verts[i]);
}
} }
//z - 1 int vc = get_vertex_count();
if (neighbours[5] == 0) { add_indices(vc + 0);
if (use_lighting) { add_indices(vc + 1);
light = Color(channel_color_r[indexzn] / 255.0, add_indices(vc + 2);
channel_color_g[indexzn] / 255.0,
channel_color_b[indexzn] / 255.0);
float ao = 0; add_indices(vc + 0);
add_indices(vc + 2);
add_indices(vc + 3);
if (use_ao) Vector2 uvs[] = {
ao = channel_ao[indexzn] / 255.0; surface->transform_uv_scaled(TerraSurface::TERRA_SIDE_SIDE, Vector2(0, 1), x % get_texture_scale(), z % get_texture_scale(), get_texture_scale()),
surface->transform_uv_scaled(TerraSurface::TERRA_SIDE_SIDE, Vector2(0, 0), x % get_texture_scale(), z % get_texture_scale(), get_texture_scale()),
surface->transform_uv_scaled(TerraSurface::TERRA_SIDE_SIDE, Vector2(1, 0), x % get_texture_scale(), z % get_texture_scale(), get_texture_scale()),
surface->transform_uv_scaled(TerraSurface::TERRA_SIDE_SIDE, Vector2(1, 1), x % get_texture_scale(), z % get_texture_scale(), get_texture_scale())
};
if (use_rao) { Vector3 verts[] = {
float rao = channel_rao[indexzn] / 255.0; Vector3(1, 0, 0) * voxel_scale + Vector3(x - 1, -1, z - 1) * voxel_scale,
ao += rao; Vector3(1, 1, 0) * voxel_scale + Vector3(x - 1, -1, z - 1) * voxel_scale,
} Vector3(0, 1, 0) * voxel_scale + Vector3(x - 1, -1, z - 1) * voxel_scale,
Vector3(0, 0, 0) * voxel_scale + Vector3(x - 1, -1, z - 1) * voxel_scale
};
light += base_light; for (int i = 0; i < 4; ++i) {
add_normal(Vector3(0, 0, -1));
if (ao > 0) if (use_lighting || _always_add_colors)
light -= Color(ao, ao, ao) * _ao_strength; add_color(light);
light.r = CLAMP(light.r, 0, 1.0); add_uv(uvs[i]);
light.g = CLAMP(light.g, 0, 1.0); add_vertex(verts[i]);
light.b = CLAMP(light.b, 0, 1.0);
}
int vc = get_vertex_count();
add_indices(vc + 0);
add_indices(vc + 1);
add_indices(vc + 2);
add_indices(vc + 0);
add_indices(vc + 2);
add_indices(vc + 3);
Vector2 uvs[] = {
surface->transform_uv_scaled(TerraSurface::TERRA_SIDE_SIDE, Vector2(0, 1), x % get_texture_scale(), z % get_texture_scale(), get_texture_scale()),
surface->transform_uv_scaled(TerraSurface::TERRA_SIDE_SIDE, Vector2(0, 0), x % get_texture_scale(), z % get_texture_scale(), get_texture_scale()),
surface->transform_uv_scaled(TerraSurface::TERRA_SIDE_SIDE, Vector2(1, 0), x % get_texture_scale(), z % get_texture_scale(), get_texture_scale()),
surface->transform_uv_scaled(TerraSurface::TERRA_SIDE_SIDE, Vector2(1, 1), x % get_texture_scale(), z % get_texture_scale(), get_texture_scale())
};
Vector3 verts[] = {
Vector3(1, 0, 0) * voxel_scale + Vector3(x - 1, y - 1, z - 1) * voxel_scale,
Vector3(1, 1, 0) * voxel_scale + Vector3(x - 1, y - 1, z - 1) * voxel_scale,
Vector3(0, 1, 0) * voxel_scale + Vector3(x - 1, y - 1, z - 1) * voxel_scale,
Vector3(0, 0, 0) * voxel_scale + Vector3(x - 1, y - 1, z - 1) * voxel_scale
};
for (int i = 0; i < 4; ++i) {
add_normal(Vector3(0, 0, -1));
if (use_lighting || _always_add_colors)
add_color(light);
add_uv(uvs[i]);
add_vertex(verts[i]);
}
} }
} }
} }

View File

@ -33,7 +33,6 @@ void TerraMesherLiquidBlocky::_add_chunk(Ref<TerraChunk> p_chunk) {
// chunk->generate_ao(); // chunk->generate_ao();
int x_size = chunk->get_size_x(); int x_size = chunk->get_size_x();
int y_size = chunk->get_size_y();
int z_size = chunk->get_size_z(); int z_size = chunk->get_size_z();
float voxel_scale = get_voxel_scale(); float voxel_scale = get_voxel_scale();
@ -78,401 +77,396 @@ void TerraMesherLiquidBlocky::_add_chunk(Ref<TerraChunk> p_chunk) {
liquids.push_back(static_cast<uint8_t>(i + 1)); liquids.push_back(static_cast<uint8_t>(i + 1));
} }
for (int y = chunk->get_margin_start(); y < y_size + chunk->get_margin_start(); ++y) { for (int z = chunk->get_margin_start(); z < z_size + chunk->get_margin_start(); ++z) {
for (int z = chunk->get_margin_start(); z < z_size + chunk->get_margin_start(); ++z) { for (int x = chunk->get_margin_start(); x < x_size + chunk->get_margin_start(); ++x) {
for (int x = chunk->get_margin_start(); x < x_size + chunk->get_margin_start(); ++x) {
int index = chunk->get_data_index(x, y, z); int index = chunk->get_data_index(x, z);
int indexxp = chunk->get_data_index(x + 1, y, z); int indexxp = chunk->get_data_index(x + 1, z);
int indexxn = chunk->get_data_index(x - 1, y, z); int indexxn = chunk->get_data_index(x - 1, z);
int indexyp = chunk->get_data_index(x, y + 1, z); int indexzp = chunk->get_data_index(x, z + 1);
int indexyn = chunk->get_data_index(x, y - 1, z); int indexzn = chunk->get_data_index(x, z - 1);
int indexzp = chunk->get_data_index(x, y, z + 1);
int indexzn = chunk->get_data_index(x, y, z - 1);
uint8_t type = channel_type[index]; uint8_t type = channel_type[index];
if (type == 0) if (type == 0)
continue; continue;
if (liquids.find(type) == -1) if (liquids.find(type) == -1)
continue; continue;
Ref<TerraSurface> surface = _library->voxel_surface_get(type - 1); Ref<TerraSurface> surface = _library->voxel_surface_get(type - 1);
if (!surface.is_valid()) if (!surface.is_valid())
continue; continue;
uint8_t neighbours[] = { uint8_t neighbours[] = {
channel_type[indexxp], channel_type[indexxp],
channel_type[indexxn], channel_type[indexxn],
channel_type[indexyp], channel_type[indexzp],
channel_type[indexyn], channel_type[indexzn],
channel_type[indexzp], };
channel_type[indexzn],
//x + 1
if (neighbours[0] == 0) {
if (use_lighting) {
light = Color(channel_color_r[indexxp] / 255.0,
channel_color_g[indexxp] / 255.0,
channel_color_b[indexxp] / 255.0);
float ao = 0;
if (use_ao)
ao = channel_ao[indexxp] / 255.0;
if (use_rao) {
float rao = channel_rao[indexxp] / 255.0;
ao += rao;
}
light += base_light;
if (ao > 0)
light -= Color(ao, ao, ao) * _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);
}
int vc = get_vertex_count();
add_indices(vc + 2);
add_indices(vc + 1);
add_indices(vc + 0);
add_indices(vc + 3);
add_indices(vc + 2);
add_indices(vc + 0);
Vector2 uvs[] = {
surface->transform_uv(TerraSurface::TERRA_SIDE_SIDE, Vector2(0, 1)),
surface->transform_uv(TerraSurface::TERRA_SIDE_SIDE, Vector2(0, 0)),
surface->transform_uv(TerraSurface::TERRA_SIDE_SIDE, Vector2(1, 0)),
surface->transform_uv(TerraSurface::TERRA_SIDE_SIDE, Vector2(1, 1))
}; };
//x + 1 Vector3 verts[] = {
if (neighbours[0] == 0) { Vector3(1, 0, 0) * voxel_scale + Vector3(x - 1, - 1, z - 1) * voxel_scale,
if (use_lighting) { Vector3(1, 1, 0) * voxel_scale + Vector3(x - 1, - 1, z - 1) * voxel_scale,
light = Color(channel_color_r[indexxp] / 255.0, Vector3(1, 1, 1) * voxel_scale + Vector3(x - 1, - 1, z - 1) * voxel_scale,
channel_color_g[indexxp] / 255.0, Vector3(1, 0, 1) * voxel_scale + Vector3(x - 1, - 1, z - 1) * voxel_scale
channel_color_b[indexxp] / 255.0); };
float ao = 0; for (int i = 0; i < 4; ++i) {
add_normal(Vector3(1, 0, 0));
if (use_ao) if (use_lighting)
ao = channel_ao[indexxp] / 255.0; add_color(light);
if (use_rao) { add_uv(uvs[i]);
float rao = channel_rao[indexxp] / 255.0; add_vertex(verts[i]);
ao += rao;
}
light += base_light;
if (ao > 0)
light -= Color(ao, ao, ao) * _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);
}
int vc = get_vertex_count();
add_indices(vc + 2);
add_indices(vc + 1);
add_indices(vc + 0);
add_indices(vc + 3);
add_indices(vc + 2);
add_indices(vc + 0);
Vector2 uvs[] = {
surface->transform_uv(TerraSurface::TERRA_SIDE_SIDE, Vector2(0, 1)),
surface->transform_uv(TerraSurface::TERRA_SIDE_SIDE, Vector2(0, 0)),
surface->transform_uv(TerraSurface::TERRA_SIDE_SIDE, Vector2(1, 0)),
surface->transform_uv(TerraSurface::TERRA_SIDE_SIDE, Vector2(1, 1))
};
Vector3 verts[] = {
Vector3(1, 0, 0) * voxel_scale + Vector3(x - 1, y - 1, z - 1) * voxel_scale,
Vector3(1, 1, 0) * voxel_scale + Vector3(x - 1, y - 1, z - 1) * voxel_scale,
Vector3(1, 1, 1) * voxel_scale + Vector3(x - 1, y - 1, z - 1) * voxel_scale,
Vector3(1, 0, 1) * voxel_scale + Vector3(x - 1, y - 1, z - 1) * voxel_scale
};
for (int i = 0; i < 4; ++i) {
add_normal(Vector3(1, 0, 0));
if (use_lighting)
add_color(light);
add_uv(uvs[i]);
add_vertex(verts[i]);
}
} }
}
//x - 1 //x - 1
if (neighbours[1] == 0) { if (neighbours[1] == 0) {
if (use_lighting) { if (use_lighting) {
light = Color(channel_color_r[indexxn] / 255.0, light = Color(channel_color_r[indexxn] / 255.0,
channel_color_g[indexxn] / 255.0, channel_color_g[indexxn] / 255.0,
channel_color_b[indexxn] / 255.0); channel_color_b[indexxn] / 255.0);
float ao = 0; float ao = 0;
if (use_ao) if (use_ao)
ao = channel_ao[indexxn] / 255.0; ao = channel_ao[indexxn] / 255.0;
if (use_rao) { if (use_rao) {
float rao = channel_rao[indexxn] / 255.0; float rao = channel_rao[indexxn] / 255.0;
ao += rao; ao += rao;
}
light += base_light;
if (ao > 0)
light -= Color(ao, ao, ao) * _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);
} }
int vc = get_vertex_count(); light += base_light;
add_indices(vc + 0);
add_indices(vc + 1);
add_indices(vc + 2);
add_indices(vc + 0); if (ao > 0)
add_indices(vc + 2); light -= Color(ao, ao, ao) * _ao_strength;
add_indices(vc + 3);
Vector2 uvs[] = {
surface->transform_uv(TerraSurface::TERRA_SIDE_SIDE, Vector2(0, 1)),
surface->transform_uv(TerraSurface::TERRA_SIDE_SIDE, Vector2(0, 0)),
surface->transform_uv(TerraSurface::TERRA_SIDE_SIDE, Vector2(1, 0)),
surface->transform_uv(TerraSurface::TERRA_SIDE_SIDE, Vector2(1, 1))
};
Vector3 verts[] = {
Vector3(0, 0, 0) * voxel_scale + Vector3(x - 1, y - 1, z - 1) * voxel_scale,
Vector3(0, 1, 0) * voxel_scale + Vector3(x - 1, y - 1, z - 1) * voxel_scale,
Vector3(0, 1, 1) * voxel_scale + Vector3(x - 1, y - 1, z - 1) * voxel_scale,
Vector3(0, 0, 1) * voxel_scale + Vector3(x - 1, y - 1, z - 1) * voxel_scale
};
for (int i = 0; i < 4; ++i) {
add_normal(Vector3(-1, 0, 0));
if (use_lighting)
add_color(light);
add_uv(uvs[i]);
add_vertex(verts[i]);
}
}
//y + 1
if (neighbours[2] == 0) {
if (use_lighting) {
light = Color(channel_color_r[indexyp] / 255.0,
channel_color_g[indexyp] / 255.0,
channel_color_b[indexyp] / 255.0);
float ao = 0;
if (use_ao)
ao = channel_ao[indexyp] / 255.0;
if (use_rao) {
float rao = channel_rao[indexyp] / 255.0;
ao += rao;
}
light += base_light;
if (ao > 0)
light -= Color(ao, ao, ao) * _ao_strength;
}
light.r = CLAMP(light.r, 0, 1.0); light.r = CLAMP(light.r, 0, 1.0);
light.g = CLAMP(light.g, 0, 1.0); light.g = CLAMP(light.g, 0, 1.0);
light.b = CLAMP(light.b, 0, 1.0); light.b = CLAMP(light.b, 0, 1.0);
int vc = get_vertex_count();
add_indices(vc + 2);
add_indices(vc + 1);
add_indices(vc + 0);
add_indices(vc + 3);
add_indices(vc + 2);
add_indices(vc + 0);
Vector2 uvs[] = {
surface->transform_uv(TerraSurface::TERRA_SIDE_TOP, Vector2(0, 1)),
surface->transform_uv(TerraSurface::TERRA_SIDE_TOP, Vector2(0, 0)),
surface->transform_uv(TerraSurface::TERRA_SIDE_TOP, Vector2(1, 0)),
surface->transform_uv(TerraSurface::TERRA_SIDE_TOP, Vector2(1, 1))
};
Vector3 verts[] = {
Vector3(1, 1, 0) * voxel_scale + Vector3(x - 1, y - 1, z - 1) * voxel_scale,
Vector3(0, 1, 0) * voxel_scale + Vector3(x - 1, y - 1, z - 1) * voxel_scale,
Vector3(0, 1, 1) * voxel_scale + Vector3(x - 1, y - 1, z - 1) * voxel_scale,
Vector3(1, 1, 1) * voxel_scale + Vector3(x - 1, y - 1, z - 1) * voxel_scale
};
for (int i = 0; i < 4; ++i) {
add_normal(Vector3(0, 1, 0));
if (use_lighting)
add_color(light);
add_uv(uvs[i]);
add_vertex(verts[i]);
}
} }
//y - 1 int vc = get_vertex_count();
if (neighbours[3] == 0) { add_indices(vc + 0);
if (use_lighting) { add_indices(vc + 1);
light = Color(channel_color_r[indexyn] / 255.0, add_indices(vc + 2);
channel_color_g[indexyn] / 255.0,
channel_color_b[indexyn] / 255.0);
float ao = 0; add_indices(vc + 0);
add_indices(vc + 2);
add_indices(vc + 3);
if (use_ao) Vector2 uvs[] = {
ao = channel_ao[indexyn] / 255.0; surface->transform_uv(TerraSurface::TERRA_SIDE_SIDE, Vector2(0, 1)),
surface->transform_uv(TerraSurface::TERRA_SIDE_SIDE, Vector2(0, 0)),
surface->transform_uv(TerraSurface::TERRA_SIDE_SIDE, Vector2(1, 0)),
surface->transform_uv(TerraSurface::TERRA_SIDE_SIDE, Vector2(1, 1))
};
if (use_rao) { Vector3 verts[] = {
float rao = channel_rao[indexyn] / 255.0; Vector3(0, 0, 0) * voxel_scale + Vector3(x - 1, - 1, z - 1) * voxel_scale,
ao += rao; Vector3(0, 1, 0) * voxel_scale + Vector3(x - 1, - 1, z - 1) * voxel_scale,
} Vector3(0, 1, 1) * voxel_scale + Vector3(x - 1, - 1, z - 1) * voxel_scale,
Vector3(0, 0, 1) * voxel_scale + Vector3(x - 1, - 1, z - 1) * voxel_scale
};
light += base_light; for (int i = 0; i < 4; ++i) {
add_normal(Vector3(-1, 0, 0));
if (ao > 0) if (use_lighting)
light -= Color(ao, ao, ao) * _ao_strength; add_color(light);
add_uv(uvs[i]);
add_vertex(verts[i]);
}
}
/*
//y + 1
if (neighbours[2] == 0) {
if (use_lighting) {
light = Color(channel_color_r[indexyp] / 255.0,
channel_color_g[indexyp] / 255.0,
channel_color_b[indexyp] / 255.0);
float ao = 0;
if (use_ao)
ao = channel_ao[indexyp] / 255.0;
if (use_rao) {
float rao = channel_rao[indexyp] / 255.0;
ao += rao;
} }
light += base_light;
if (ao > 0)
light -= Color(ao, ao, ao) * _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);
int vc = get_vertex_count();
add_indices(vc + 2);
add_indices(vc + 1);
add_indices(vc + 0);
add_indices(vc + 3);
add_indices(vc + 2);
add_indices(vc + 0);
Vector2 uvs[] = {
surface->transform_uv(TerraSurface::TERRA_SIDE_TOP, Vector2(0, 1)),
surface->transform_uv(TerraSurface::TERRA_SIDE_TOP, Vector2(0, 0)),
surface->transform_uv(TerraSurface::TERRA_SIDE_TOP, Vector2(1, 0)),
surface->transform_uv(TerraSurface::TERRA_SIDE_TOP, Vector2(1, 1))
};
Vector3 verts[] = {
Vector3(1, 1, 0) * voxel_scale + Vector3(x - 1, y - 1, z - 1) * voxel_scale,
Vector3(0, 1, 0) * voxel_scale + Vector3(x - 1, y - 1, z - 1) * voxel_scale,
Vector3(0, 1, 1) * voxel_scale + Vector3(x - 1, y - 1, z - 1) * voxel_scale,
Vector3(1, 1, 1) * voxel_scale + Vector3(x - 1, y - 1, z - 1) * voxel_scale
};
for (int i = 0; i < 4; ++i) {
add_normal(Vector3(0, 1, 0));
if (use_lighting)
add_color(light);
add_uv(uvs[i]);
add_vertex(verts[i]);
}
}
*/
/*
//y - 1
if (neighbours[3] == 0) {
if (use_lighting) {
light = Color(channel_color_r[indexyn] / 255.0,
channel_color_g[indexyn] / 255.0,
channel_color_b[indexyn] / 255.0);
float ao = 0;
if (use_ao)
ao = channel_ao[indexyn] / 255.0;
if (use_rao) {
float rao = channel_rao[indexyn] / 255.0;
ao += rao;
}
light += base_light;
if (ao > 0)
light -= Color(ao, ao, ao) * _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);
int vc = get_vertex_count();
add_indices(vc + 0);
add_indices(vc + 1);
add_indices(vc + 2);
add_indices(vc + 0);
add_indices(vc + 2);
add_indices(vc + 3);
Vector2 uvs[] = {
surface->transform_uv(TerraSurface::TERRA_SIDE_BOTTOM, Vector2(0, 1)),
surface->transform_uv(TerraSurface::TERRA_SIDE_BOTTOM, Vector2(0, 0)),
surface->transform_uv(TerraSurface::TERRA_SIDE_BOTTOM, Vector2(1, 0)),
surface->transform_uv(TerraSurface::TERRA_SIDE_BOTTOM, Vector2(1, 1))
};
Vector3 verts[] = {
Vector3(1, 0, 0) * voxel_scale + Vector3(x - 1, y - 1, z - 1) * voxel_scale,
Vector3(0, 0, 0) * voxel_scale + Vector3(x - 1, y - 1, z - 1) * voxel_scale,
Vector3(0, 0, 1) * voxel_scale + Vector3(x - 1, y - 1, z - 1) * voxel_scale,
Vector3(1, 0, 1) * voxel_scale + Vector3(x - 1, y - 1, z - 1) * voxel_scale
};
for (int i = 0; i < 4; ++i) {
add_normal(Vector3(0, -1, 0));
if (use_lighting)
add_color(light);
add_uv(uvs[i]);
add_vertex(verts[i]);
}
}
*/
//z + 1
if (neighbours[4] == 0) {
if (use_lighting) {
light = Color(channel_color_r[indexzp] / 255.0,
channel_color_g[indexzp] / 255.0,
channel_color_b[indexzp] / 255.0);
float ao = 0;
if (use_ao)
ao = channel_ao[indexzp] / 255.0;
if (use_rao) {
float rao = channel_rao[indexzp] / 255.0;
ao += rao;
}
light += base_light;
if (ao > 0)
light -= Color(ao, ao, ao) * _ao_strength;
light.r = CLAMP(light.r, 0, 1.0); light.r = CLAMP(light.r, 0, 1.0);
light.g = CLAMP(light.g, 0, 1.0); light.g = CLAMP(light.g, 0, 1.0);
light.b = CLAMP(light.b, 0, 1.0); light.b = CLAMP(light.b, 0, 1.0);
int vc = get_vertex_count();
add_indices(vc + 0);
add_indices(vc + 1);
add_indices(vc + 2);
add_indices(vc + 0);
add_indices(vc + 2);
add_indices(vc + 3);
Vector2 uvs[] = {
surface->transform_uv(TerraSurface::TERRA_SIDE_BOTTOM, Vector2(0, 1)),
surface->transform_uv(TerraSurface::TERRA_SIDE_BOTTOM, Vector2(0, 0)),
surface->transform_uv(TerraSurface::TERRA_SIDE_BOTTOM, Vector2(1, 0)),
surface->transform_uv(TerraSurface::TERRA_SIDE_BOTTOM, Vector2(1, 1))
};
Vector3 verts[] = {
Vector3(1, 0, 0) * voxel_scale + Vector3(x - 1, y - 1, z - 1) * voxel_scale,
Vector3(0, 0, 0) * voxel_scale + Vector3(x - 1, y - 1, z - 1) * voxel_scale,
Vector3(0, 0, 1) * voxel_scale + Vector3(x - 1, y - 1, z - 1) * voxel_scale,
Vector3(1, 0, 1) * voxel_scale + Vector3(x - 1, y - 1, z - 1) * voxel_scale
};
for (int i = 0; i < 4; ++i) {
add_normal(Vector3(0, -1, 0));
if (use_lighting)
add_color(light);
add_uv(uvs[i]);
add_vertex(verts[i]);
}
} }
//z + 1 int vc = get_vertex_count();
if (neighbours[4] == 0) { add_indices(vc + 2);
if (use_lighting) { add_indices(vc + 1);
light = Color(channel_color_r[indexzp] / 255.0, add_indices(vc + 0);
channel_color_g[indexzp] / 255.0, add_indices(vc + 3);
channel_color_b[indexzp] / 255.0); add_indices(vc + 2);
add_indices(vc + 0);
float ao = 0; Vector2 uvs[] = {
surface->transform_uv(TerraSurface::TERRA_SIDE_SIDE, Vector2(0, 1)),
surface->transform_uv(TerraSurface::TERRA_SIDE_SIDE, Vector2(0, 0)),
surface->transform_uv(TerraSurface::TERRA_SIDE_SIDE, Vector2(1, 0)),
surface->transform_uv(TerraSurface::TERRA_SIDE_SIDE, Vector2(1, 1))
};
if (use_ao) Vector3 verts[] = {
ao = channel_ao[indexzp] / 255.0; Vector3(1, 0, 1) * voxel_scale + Vector3(x - 1, - 1, z - 1) * voxel_scale,
Vector3(1, 1, 1) * voxel_scale + Vector3(x - 1, - 1, z - 1) * voxel_scale,
Vector3(0, 1, 1) * voxel_scale + Vector3(x - 1, - 1, z - 1) * voxel_scale,
Vector3(0, 0, 1) * voxel_scale + Vector3(x - 1, - 1, z - 1) * voxel_scale
};
if (use_rao) { for (int i = 0; i < 4; ++i) {
float rao = channel_rao[indexzp] / 255.0; add_normal(Vector3(0, 0, 1));
ao += rao;
}
light += base_light; if (use_lighting)
add_color(light);
if (ao > 0) add_uv(uvs[i]);
light -= Color(ao, ao, ao) * _ao_strength; add_vertex(verts[i]);
}
}
light.r = CLAMP(light.r, 0, 1.0); //z - 1
light.g = CLAMP(light.g, 0, 1.0); if (neighbours[5] == 0) {
light.b = CLAMP(light.b, 0, 1.0); if (use_lighting) {
light = Color(channel_color_r[indexzn] / 255.0,
channel_color_g[indexzn] / 255.0,
channel_color_b[indexzn] / 255.0);
float ao = 0;
if (use_ao)
ao = channel_ao[indexzn] / 255.0;
if (use_rao) {
float rao = channel_rao[indexzn] / 255.0;
ao += rao;
} }
int vc = get_vertex_count(); light += base_light;
add_indices(vc + 2);
add_indices(vc + 1);
add_indices(vc + 0);
add_indices(vc + 3);
add_indices(vc + 2);
add_indices(vc + 0);
Vector2 uvs[] = { if (ao > 0)
surface->transform_uv(TerraSurface::TERRA_SIDE_SIDE, Vector2(0, 1)), light -= Color(ao, ao, ao) * _ao_strength;
surface->transform_uv(TerraSurface::TERRA_SIDE_SIDE, Vector2(0, 0)),
surface->transform_uv(TerraSurface::TERRA_SIDE_SIDE, Vector2(1, 0)),
surface->transform_uv(TerraSurface::TERRA_SIDE_SIDE, Vector2(1, 1))
};
Vector3 verts[] = { light.r = CLAMP(light.r, 0, 1.0);
Vector3(1, 0, 1) * voxel_scale + Vector3(x - 1, y - 1, z - 1) * voxel_scale, light.g = CLAMP(light.g, 0, 1.0);
Vector3(1, 1, 1) * voxel_scale + Vector3(x - 1, y - 1, z - 1) * voxel_scale, light.b = CLAMP(light.b, 0, 1.0);
Vector3(0, 1, 1) * voxel_scale + Vector3(x - 1, y - 1, z - 1) * voxel_scale,
Vector3(0, 0, 1) * voxel_scale + Vector3(x - 1, y - 1, z - 1) * voxel_scale
};
for (int i = 0; i < 4; ++i) {
add_normal(Vector3(0, 0, 1));
if (use_lighting)
add_color(light);
add_uv(uvs[i]);
add_vertex(verts[i]);
}
} }
//z - 1 int vc = get_vertex_count();
if (neighbours[5] == 0) { add_indices(vc + 0);
if (use_lighting) { add_indices(vc + 1);
light = Color(channel_color_r[indexzn] / 255.0, add_indices(vc + 2);
channel_color_g[indexzn] / 255.0,
channel_color_b[indexzn] / 255.0);
float ao = 0; add_indices(vc + 0);
add_indices(vc + 2);
add_indices(vc + 3);
if (use_ao) Vector2 uvs[] = {
ao = channel_ao[indexzn] / 255.0; surface->transform_uv(TerraSurface::TERRA_SIDE_SIDE, Vector2(0, 1)),
surface->transform_uv(TerraSurface::TERRA_SIDE_SIDE, Vector2(0, 0)),
surface->transform_uv(TerraSurface::TERRA_SIDE_SIDE, Vector2(1, 0)),
surface->transform_uv(TerraSurface::TERRA_SIDE_SIDE, Vector2(1, 1))
};
if (use_rao) { Vector3 verts[] = {
float rao = channel_rao[indexzn] / 255.0; Vector3(1, 0, 0) * voxel_scale + Vector3(x - 1, - 1, z - 1) * voxel_scale,
ao += rao; Vector3(1, 1, 0) * voxel_scale + Vector3(x - 1, - 1, z - 1) * voxel_scale,
} Vector3(0, 1, 0) * voxel_scale + Vector3(x - 1, - 1, z - 1) * voxel_scale,
Vector3(0, 0, 0) * voxel_scale + Vector3(x - 1, - 1, z - 1) * voxel_scale
};
light += base_light; for (int i = 0; i < 4; ++i) {
add_normal(Vector3(0, 0, -1));
if (ao > 0) if (use_lighting)
light -= Color(ao, ao, ao) * _ao_strength; add_color(light);
light.r = CLAMP(light.r, 0, 1.0); add_uv(uvs[i]);
light.g = CLAMP(light.g, 0, 1.0); add_vertex(verts[i]);
light.b = CLAMP(light.b, 0, 1.0);
}
int vc = get_vertex_count();
add_indices(vc + 0);
add_indices(vc + 1);
add_indices(vc + 2);
add_indices(vc + 0);
add_indices(vc + 2);
add_indices(vc + 3);
Vector2 uvs[] = {
surface->transform_uv(TerraSurface::TERRA_SIDE_SIDE, Vector2(0, 1)),
surface->transform_uv(TerraSurface::TERRA_SIDE_SIDE, Vector2(0, 0)),
surface->transform_uv(TerraSurface::TERRA_SIDE_SIDE, Vector2(1, 0)),
surface->transform_uv(TerraSurface::TERRA_SIDE_SIDE, Vector2(1, 1))
};
Vector3 verts[] = {
Vector3(1, 0, 0) * voxel_scale + Vector3(x - 1, y - 1, z - 1) * voxel_scale,
Vector3(1, 1, 0) * voxel_scale + Vector3(x - 1, y - 1, z - 1) * voxel_scale,
Vector3(0, 1, 0) * voxel_scale + Vector3(x - 1, y - 1, z - 1) * voxel_scale,
Vector3(0, 0, 0) * voxel_scale + Vector3(x - 1, y - 1, z - 1) * voxel_scale
};
for (int i = 0; i < 4; ++i) {
add_normal(Vector3(0, 0, -1));
if (use_lighting)
add_color(light);
add_uv(uvs[i]);
add_vertex(verts[i]);
}
} }
} }
} }

View File

@ -63,17 +63,16 @@ void TerraMesherDefault::_bake_colors(Ref<TerraChunk> chunk) {
} }
unsigned int x = (unsigned int)(vert.x / _voxel_scale); 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); unsigned int z = (unsigned int)(vert.z / _voxel_scale);
if (chunk->validate_data_position(x, y, z)) { if (chunk->validate_data_position(x, z)) {
Color light = Color( Color light = Color(
chunk->get_voxel(x, y, z, TerraChunkDefault::DEFAULT_CHANNEL_LIGHT_COLOR_R) / 255.0, chunk->get_voxel(x, z, TerraChunkDefault::DEFAULT_CHANNEL_LIGHT_COLOR_R) / 255.0,
chunk->get_voxel(x, y, z, TerraChunkDefault::DEFAULT_CHANNEL_LIGHT_COLOR_G) / 255.0, chunk->get_voxel(x, z, TerraChunkDefault::DEFAULT_CHANNEL_LIGHT_COLOR_G) / 255.0,
chunk->get_voxel(x, y, z, TerraChunkDefault::DEFAULT_CHANNEL_LIGHT_COLOR_B) / 255.0); chunk->get_voxel(x, z, TerraChunkDefault::DEFAULT_CHANNEL_LIGHT_COLOR_B) / 255.0);
float ao = (chunk->get_voxel(x, y, z, TerraChunkDefault::DEFAULT_CHANNEL_AO) / 255.0) * _ao_strength; float ao = (chunk->get_voxel(x, z, TerraChunkDefault::DEFAULT_CHANNEL_AO) / 255.0) * _ao_strength;
float rao = chunk->get_voxel(x, y, z, TerraChunkDefault::DEFAULT_CHANNEL_RANDOM_AO) / 255.0; float rao = chunk->get_voxel(x, z, TerraChunkDefault::DEFAULT_CHANNEL_RANDOM_AO) / 255.0;
ao += rao; ao += rao;
@ -122,17 +121,17 @@ void TerraMesherDefault::_bake_liquid_colors(Ref<TerraChunk> chunk) {
} }
unsigned int x = (unsigned int)(vert.x / _voxel_scale); unsigned int x = (unsigned int)(vert.x / _voxel_scale);
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_data_position(x, y, z)) { if (chunk->validate_data_position(x, z)) {
Color light = Color( Color light = Color(
chunk->get_voxel(x, y, z, TerraChunkDefault::DEFAULT_CHANNEL_LIGHT_COLOR_R) / 255.0, chunk->get_voxel(x, z, TerraChunkDefault::DEFAULT_CHANNEL_LIGHT_COLOR_R) / 255.0,
chunk->get_voxel(x, y, z, TerraChunkDefault::DEFAULT_CHANNEL_LIGHT_COLOR_G) / 255.0, chunk->get_voxel(x, z, TerraChunkDefault::DEFAULT_CHANNEL_LIGHT_COLOR_G) / 255.0,
chunk->get_voxel(x, y, z, TerraChunkDefault::DEFAULT_CHANNEL_LIGHT_COLOR_B) / 255.0); chunk->get_voxel(x, z, TerraChunkDefault::DEFAULT_CHANNEL_LIGHT_COLOR_B) / 255.0);
float ao = (chunk->get_voxel(x, y, z, TerraChunkDefault::DEFAULT_CHANNEL_AO) / 255.0) * _ao_strength; float ao = (chunk->get_voxel(x, z, TerraChunkDefault::DEFAULT_CHANNEL_AO) / 255.0) * _ao_strength;
float rao = chunk->get_voxel(x, y, z, TerraChunkDefault::DEFAULT_CHANNEL_RANDOM_AO) / 255.0; float rao = chunk->get_voxel(x, z, TerraChunkDefault::DEFAULT_CHANNEL_RANDOM_AO) / 255.0;
ao += rao; ao += rao;

View File

@ -30,7 +30,7 @@ SOFTWARE.
#include "../jobs/terra_prop_job.h" #include "../jobs/terra_prop_job.h"
#include "../jobs/terra_terrarin_job.h" #include "../jobs/terra_terrarin_job.h"
Ref<TerraChunk> TerraWorldBlocky::_create_chunk(int x, int y, int z, Ref<TerraChunk> chunk) { Ref<TerraChunk> TerraWorldBlocky::_create_chunk(int x, int z, Ref<TerraChunk> chunk) {
if (!chunk.is_valid()) { if (!chunk.is_valid()) {
chunk = Ref<TerraChunk>(memnew(TerraChunkBlocky)); chunk = Ref<TerraChunk>(memnew(TerraChunkBlocky));
@ -55,7 +55,7 @@ Ref<TerraChunk> TerraWorldBlocky::_create_chunk(int x, int y, int z, Ref<TerraCh
chunk->job_add(pj); chunk->job_add(pj);
} }
return TerraWorld::_create_chunk(x, y, z, chunk); return TerraWorld::_create_chunk(x, z, chunk);
} }
TerraWorldBlocky::TerraWorldBlocky() { TerraWorldBlocky::TerraWorldBlocky() {

View File

@ -33,7 +33,7 @@ public:
~TerraWorldBlocky(); ~TerraWorldBlocky();
protected: protected:
Ref<TerraChunk> _create_chunk(int x, int y, int z, Ref<TerraChunk> p_chunk); Ref<TerraChunk> _create_chunk(int x, int z, Ref<TerraChunk> p_chunk);
static void _bind_methods(); static void _bind_methods();
}; };

View File

@ -640,19 +640,17 @@ void TerraChunkDefault::draw_debug_voxels(int max, Color color) {
int a = 0; int a = 0;
int64_t sx = static_cast<int64_t>(_size_x); int64_t sx = static_cast<int64_t>(_size_x);
int64_t sy = static_cast<int64_t>(_size_y); int64_t sz = static_cast<int64_t>(_size_z);
int64_t sz = static_cast<int64_t>(_size_y);
for (int y = 0; y < sy; ++y) {
for (int z = 0; z < sz; ++z) { for (int z = 0; z < sz; ++z) {
for (int x = 0; x < sx; ++x) { for (int x = 0; x < sx; ++x) {
int type = get_voxel(x, y, z, TerraChunkDefault::DEFAULT_CHANNEL_TYPE); int type = get_voxel(x, z, TerraChunkDefault::DEFAULT_CHANNEL_TYPE);
if (type == 0) { if (type == 0) {
continue; continue;
} }
draw_cross_voxels_fill(Vector3(x, y, z), get_voxel(x, y, z, TerraChunkDefault::DEFAULT_CHANNEL_ISOLEVEL) / 255.0 * get_voxel_scale() * 2.0); draw_cross_voxels_fill(Vector3(x, get_voxel(x, z, TerraChunkDefault::DEFAULT_CHANNEL_ISOLEVEL), z), get_voxel(x, z, TerraChunkDefault::DEFAULT_CHANNEL_ISOLEVEL) / 255.0 * get_voxel_scale() * 2.0);
++a; ++a;
@ -661,7 +659,6 @@ void TerraChunkDefault::draw_debug_voxels(int max, Color color) {
} }
} }
} }
}
debug_mesh_send(); debug_mesh_send();
} }
@ -679,10 +676,9 @@ void TerraChunkDefault::draw_debug_voxel_lights() {
Ref<TerraLight> v = _lights[i]; Ref<TerraLight> v = _lights[i];
int pos_x = v->get_world_position_x() - (_size_x * _position_x); 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_z = v->get_world_position_z() - (_size_z * _position_z); int pos_z = v->get_world_position_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, 0, pos_z), 1.0);
} }
debug_mesh_send(); debug_mesh_send();
@ -756,13 +752,13 @@ void TerraChunkDefault::_bake_light(Ref<TerraLight> light) {
int size = light->get_size(); int size = light->get_size();
int local_x = light->get_world_position_x() - (_position_x * _size_x); int local_x = light->get_world_position_x() - (_position_x * _size_x);
int local_y = light->get_world_position_y() - (_position_y * _size_y); int local_y = light->get_world_position_y();
int local_z = light->get_world_position_z() - (_position_z * _size_z); int local_z = light->get_world_position_z() - (_position_z * _size_z);
ERR_FAIL_COND(size < 0); ERR_FAIL_COND(size < 0);
int64_t dsx = static_cast<int64_t>(_data_size_x); int64_t dsx = static_cast<int64_t>(_data_size_x);
int64_t dsy = static_cast<int64_t>(_data_size_y); int64_t dsy = static_cast<int64_t>(_world_height);
int64_t dsz = static_cast<int64_t>(_data_size_z); int64_t dsz = static_cast<int64_t>(_data_size_z);
uint8_t *channel_color_r = channel_get(TerraChunkDefault::DEFAULT_CHANNEL_LIGHT_COLOR_R); uint8_t *channel_color_r = channel_get(TerraChunkDefault::DEFAULT_CHANNEL_LIGHT_COLOR_R);
@ -793,7 +789,7 @@ void TerraChunkDefault::_bake_light(Ref<TerraLight> light) {
if (str < 0) if (str < 0)
continue; continue;
int index = get_data_index(x, y, z); int index = get_data_index(x, z);
int r = color.r * str * 255.0; int r = color.r * str * 255.0;
int g = color.g * str * 255.0; int g = color.g * str * 255.0;

View File

@ -83,35 +83,29 @@ PoolColorArray TerraWorldDefault::get_vertex_colors(const Transform &transform,
//Note: floor is needed to handle negative numbers proiberly //Note: floor is needed to handle negative numbers proiberly
int x = static_cast<int>(Math::floor(pos.x / get_chunk_size_x())); int x = static_cast<int>(Math::floor(pos.x / get_chunk_size_x()));
int y = static_cast<int>(Math::floor(pos.y / get_chunk_size_y()));
int z = static_cast<int>(Math::floor(pos.z / get_chunk_size_z())); int z = static_cast<int>(Math::floor(pos.z / get_chunk_size_z()));
int bx = static_cast<int>(Math::floor(pos.x)) % get_chunk_size_x(); int bx = static_cast<int>(Math::floor(pos.x)) % get_chunk_size_x();
int by = static_cast<int>(Math::floor(pos.y)) % get_chunk_size_y();
int bz = static_cast<int>(Math::floor(pos.z)) % get_chunk_size_z(); int bz = static_cast<int>(Math::floor(pos.z)) % get_chunk_size_z();
if (bx < 0) { if (bx < 0) {
bx += get_chunk_size_x(); bx += get_chunk_size_x();
} }
if (by < 0) {
by += get_chunk_size_y();
}
if (bz < 0) { if (bz < 0) {
bz += get_chunk_size_z(); bz += get_chunk_size_z();
} }
Ref<TerraChunk> chunk = chunk_get(x, y, z); Ref<TerraChunk> chunk = chunk_get(x, z);
if (chunk.is_valid()) { if (chunk.is_valid()) {
Color light = Color( Color light = Color(
chunk->get_voxel(bx, by, bz, TerraChunkDefault::DEFAULT_CHANNEL_LIGHT_COLOR_R) / 255.0, chunk->get_voxel(bx, bz, TerraChunkDefault::DEFAULT_CHANNEL_LIGHT_COLOR_R) / 255.0,
chunk->get_voxel(bx, by, bz, TerraChunkDefault::DEFAULT_CHANNEL_LIGHT_COLOR_G) / 255.0, chunk->get_voxel(bx, bz, TerraChunkDefault::DEFAULT_CHANNEL_LIGHT_COLOR_G) / 255.0,
chunk->get_voxel(bx, by, bz, TerraChunkDefault::DEFAULT_CHANNEL_LIGHT_COLOR_B) / 255.0); chunk->get_voxel(bx, bz, TerraChunkDefault::DEFAULT_CHANNEL_LIGHT_COLOR_B) / 255.0);
float ao = (chunk->get_voxel(bx, by, bz, TerraChunkDefault::DEFAULT_CHANNEL_AO) / 255.0) * ao_strength; float ao = (chunk->get_voxel(bx, bz, TerraChunkDefault::DEFAULT_CHANNEL_AO) / 255.0) * ao_strength;
float rao = chunk->get_voxel(bx, by, bz, TerraChunkDefault::DEFAULT_CHANNEL_RANDOM_AO) / 255.0; float rao = chunk->get_voxel(bx, bz, TerraChunkDefault::DEFAULT_CHANNEL_RANDOM_AO) / 255.0;
ao += rao; ao += rao;
@ -147,7 +141,6 @@ void TerraWorldDefault::_update_lods() {
Vector3 ppos = get_player()->get_transform().origin; Vector3 ppos = get_player()->get_transform().origin;
int ppx = int(ppos.x / get_chunk_size_x() / get_voxel_scale()); int ppx = int(ppos.x / get_chunk_size_x() / get_voxel_scale());
int ppy = int(ppos.y / get_chunk_size_y() / get_voxel_scale());
int ppz = int(ppos.z / get_chunk_size_z() / get_voxel_scale()); int ppz = int(ppos.z / get_chunk_size_z() / get_voxel_scale());
for (int i = 0; i < chunk_get_count(); ++i) { for (int i = 0; i < chunk_get_count(); ++i) {
@ -157,10 +150,9 @@ void TerraWorldDefault::_update_lods() {
continue; continue;
int dx = Math::abs(ppx - c->get_position_x()); int dx = Math::abs(ppx - c->get_position_x());
int dy = Math::abs(ppy - c->get_position_y());
int dz = Math::abs(ppz - c->get_position_z()); int dz = Math::abs(ppz - c->get_position_z());
int mr = MAX(MAX(dx, dy), dz); int mr = MAX(dx, dz);
mr -= _chunk_lod_falloff; mr -= _chunk_lod_falloff;
@ -172,7 +164,7 @@ void TerraWorldDefault::_update_lods() {
} }
} }
Ref<TerraChunk> TerraWorldDefault::_create_chunk(int x, int y, int z, Ref<TerraChunk> chunk) { Ref<TerraChunk> TerraWorldDefault::_create_chunk(int x, int z, Ref<TerraChunk> chunk) {
if (!chunk.is_valid()) { if (!chunk.is_valid()) {
chunk = Ref<TerraChunk>(memnew(TerraChunkDefault)); chunk = Ref<TerraChunk>(memnew(TerraChunkDefault));
} }
@ -200,7 +192,7 @@ Ref<TerraChunk> TerraWorldDefault::_create_chunk(int x, int y, int z, Ref<TerraC
vcd->set_lod_num(_num_lods); vcd->set_lod_num(_num_lods);
} }
return TerraWorld::_create_chunk(x, y, z, chunk); return TerraWorld::_create_chunk(x, z, chunk);
} }
void TerraWorldDefault::_chunk_added(Ref<TerraChunk> chunk) { void TerraWorldDefault::_chunk_added(Ref<TerraChunk> chunk) {

View File

@ -50,7 +50,7 @@ public:
protected: protected:
void _update_lods(); void _update_lods();
Ref<TerraChunk> _create_chunk(int x, int y, int z, Ref<TerraChunk> p_chunk); Ref<TerraChunk> _create_chunk(int x, int z, Ref<TerraChunk> p_chunk);
virtual void _chunk_added(Ref<TerraChunk> chunk); virtual void _chunk_added(Ref<TerraChunk> chunk);
int _get_channel_index_info(const ChannelTypeInfo channel_type); int _get_channel_index_info(const ChannelTypeInfo channel_type);

View File

@ -106,43 +106,36 @@ void TerraJob::generate_ao() {
ERR_FAIL_COND(!_chunk.is_valid()); ERR_FAIL_COND(!_chunk.is_valid());
int data_size_x = _chunk->get_data_size_x(); int data_size_x = _chunk->get_data_size_x();
int data_size_y = _chunk->get_data_size_y();
int data_size_z = _chunk->get_data_size_z(); int data_size_z = _chunk->get_data_size_z();
ERR_FAIL_COND(data_size_x == 0 || data_size_y == 0 || data_size_z == 0); ERR_FAIL_COND(data_size_x == 0 || data_size_z == 0);
int margin_start = _chunk->get_margin_start(); int margin_start = _chunk->get_margin_start();
int margin_end = _chunk->get_margin_end(); int margin_end = _chunk->get_margin_end();
int ssize_x = _chunk->get_size_x(); int ssize_x = _chunk->get_size_x();
int ssize_y = _chunk->get_size_y();
int ssize_z = _chunk->get_size_z(); int ssize_z = _chunk->get_size_z();
int size_x = ssize_x + margin_end; int size_x = ssize_x + margin_end;
int size_y = ssize_y + margin_end;
int size_z = ssize_z + margin_end; int size_z = ssize_z + margin_end;
for (int y = margin_start - 1; y < size_y - 1; ++y) { for (int z = margin_start - 1; z < size_z - 1; ++z) {
for (int z = margin_start - 1; z < size_z - 1; ++z) { for (int x = margin_start - 1; x < size_x - 1; ++x) {
for (int x = margin_start - 1; x < size_x - 1; ++x) { int current = _chunk->get_voxel(x, z, TerraChunkDefault::DEFAULT_CHANNEL_ISOLEVEL);
int current = _chunk->get_voxel(x, y, z, TerraChunkDefault::DEFAULT_CHANNEL_ISOLEVEL);
int sum = _chunk->get_voxel(x + 1, y, z, TerraChunkDefault::DEFAULT_CHANNEL_ISOLEVEL); int sum = _chunk->get_voxel(x + 1, z, TerraChunkDefault::DEFAULT_CHANNEL_ISOLEVEL);
sum += _chunk->get_voxel(x - 1, y, z, TerraChunkDefault::DEFAULT_CHANNEL_ISOLEVEL); sum += _chunk->get_voxel(x - 1, z, TerraChunkDefault::DEFAULT_CHANNEL_ISOLEVEL);
sum += _chunk->get_voxel(x, y + 1, z, TerraChunkDefault::DEFAULT_CHANNEL_ISOLEVEL); sum += _chunk->get_voxel(x, z + 1, TerraChunkDefault::DEFAULT_CHANNEL_ISOLEVEL);
sum += _chunk->get_voxel(x, y - 1, z, TerraChunkDefault::DEFAULT_CHANNEL_ISOLEVEL); sum += _chunk->get_voxel(x, z - 1, TerraChunkDefault::DEFAULT_CHANNEL_ISOLEVEL);
sum += _chunk->get_voxel(x, y, z + 1, TerraChunkDefault::DEFAULT_CHANNEL_ISOLEVEL);
sum += _chunk->get_voxel(x, y, z - 1, TerraChunkDefault::DEFAULT_CHANNEL_ISOLEVEL);
sum /= 6; sum /= 6;
sum -= current; sum -= current;
if (sum < 0) if (sum < 0)
sum = 0; sum = 0;
_chunk->set_voxel(sum, x, y, z, TerraChunkDefault::DEFAULT_CHANNEL_AO); _chunk->set_voxel(sum, x, z, TerraChunkDefault::DEFAULT_CHANNEL_AO);
}
} }
} }
} }
@ -154,11 +147,9 @@ void TerraJob::generate_random_ao(int seed, int octaves, int period, float persi
int margin_end = _chunk->get_margin_end(); int margin_end = _chunk->get_margin_end();
int size_x = _chunk->get_size_x(); int size_x = _chunk->get_size_x();
int size_y = _chunk->get_size_y();
int size_z = _chunk->get_size_z(); int size_z = _chunk->get_size_z();
int position_x = _chunk->get_position_x(); int position_x = _chunk->get_position_x();
int position_y = _chunk->get_position_y();
int position_z = _chunk->get_position_z(); int position_z = _chunk->get_position_z();
Ref<OpenSimplexNoise> noise; Ref<OpenSimplexNoise> noise;
@ -171,19 +162,18 @@ void TerraJob::generate_random_ao(int seed, int octaves, int period, float persi
for (int x = -margin_start; x < size_x + margin_end; ++x) { for (int x = -margin_start; x < size_x + margin_end; ++x) {
for (int z = -margin_start; z < size_z + margin_end; ++z) { for (int z = -margin_start; z < size_z + margin_end; ++z) {
for (int y = -margin_start; y < size_y + margin_end; ++y) {
float val = noise->get_noise_3d(x + (position_x * size_x), y + (position_y * size_y), z + (position_z * size_z));
val *= scale_factor; float val = noise->get_noise_3d(x + (position_x * size_x), 0, z + (position_z * size_z));
if (val > 1) val *= scale_factor;
val = 1;
if (val < 0) if (val > 1)
val = -val; val = 1;
_chunk->set_voxel(int(val * 255.0), x, y, z, TerraChunkDefault::DEFAULT_CHANNEL_RANDOM_AO); if (val < 0)
} val = -val;
_chunk->set_voxel(int(val * 255.0), x, z, TerraChunkDefault::DEFAULT_CHANNEL_RANDOM_AO);
} }
} }
} }

View File

@ -96,12 +96,6 @@ _FORCE_INLINE_ int TerraChunk::get_position_x() const {
void TerraChunk::set_position_x(const int value) { void TerraChunk::set_position_x(const int value) {
_position_x = value; _position_x = value;
} }
_FORCE_INLINE_ int TerraChunk::get_position_y() const {
return _position_y;
}
void TerraChunk::set_position_y(const int value) {
_position_y = value;
}
_FORCE_INLINE_ int TerraChunk::get_position_z() const { _FORCE_INLINE_ int TerraChunk::get_position_z() const {
return _position_z; return _position_z;
} }
@ -109,27 +103,26 @@ void TerraChunk::set_position_z(const int value) {
_position_z = value; _position_z = value;
} }
_FORCE_INLINE_ Vector3 TerraChunk::get_position() const { _FORCE_INLINE_ Vector2 TerraChunk::get_position() const {
return Vector3(_position_x, _position_y, _position_z); return Vector2(_position_x, _position_z);
} }
_FORCE_INLINE_ Vector3 TerraChunk::get_world_position() const { _FORCE_INLINE_ Vector2 TerraChunk::get_world_position() const {
return Vector3(_position_x * _size_x * _voxel_scale, _position_y * _size_y * _voxel_scale, _position_z * _size_z * _voxel_scale); return Vector2(_position_x * _size_x * _voxel_scale, _position_z * _size_z * _voxel_scale);
} }
_FORCE_INLINE_ Vector3 TerraChunk::get_world_size() const { _FORCE_INLINE_ Vector3 TerraChunk::get_world_size() const {
return Vector3(_size_x * _voxel_scale, _size_y * _voxel_scale, _size_z * _voxel_scale); return Vector3(_size_x * _voxel_scale, _world_height * _voxel_scale, _size_z * _voxel_scale);
} }
_FORCE_INLINE_ AABB TerraChunk::get_world_aabb() const { _FORCE_INLINE_ AABB TerraChunk::get_world_aabb() const {
return AABB(get_world_position(), get_world_size()); Vector2 v = get_world_position();
return AABB(Vector3(v.x, 0, v.y), get_world_size());
} }
_FORCE_INLINE_ int TerraChunk::get_size_x() const { _FORCE_INLINE_ int TerraChunk::get_size_x() const {
return _size_x; return _size_x;
} }
_FORCE_INLINE_ int TerraChunk::get_size_y() const {
return _size_y;
}
_FORCE_INLINE_ int TerraChunk::get_size_z() const { _FORCE_INLINE_ int TerraChunk::get_size_z() const {
return _size_z; return _size_z;
} }
@ -137,23 +130,17 @@ _FORCE_INLINE_ int TerraChunk::get_size_z() const {
_FORCE_INLINE_ void TerraChunk::set_size_x(const int value) { _FORCE_INLINE_ void TerraChunk::set_size_x(const int value) {
_size_x = value; _size_x = value;
} }
_FORCE_INLINE_ void TerraChunk::set_size_y(const int value) {
_size_y = value;
}
_FORCE_INLINE_ void TerraChunk::set_size_z(const int value) { _FORCE_INLINE_ void TerraChunk::set_size_z(const int value) {
_size_z = value; _size_z = value;
} }
_FORCE_INLINE_ Vector3 TerraChunk::get_size() const { _FORCE_INLINE_ Vector3 TerraChunk::get_size() const {
return Vector3(_size_x, _size_y, _size_z); return Vector3(_size_x, _world_height, _size_z);
} }
_FORCE_INLINE_ int TerraChunk::get_data_size_x() const { _FORCE_INLINE_ int TerraChunk::get_data_size_x() const {
return _data_size_x; return _data_size_x;
} }
_FORCE_INLINE_ int TerraChunk::get_data_size_y() const {
return _data_size_y;
}
_FORCE_INLINE_ int TerraChunk::get_data_size_z() const { _FORCE_INLINE_ int TerraChunk::get_data_size_z() const {
return _data_size_z; return _data_size_z;
} }
@ -161,16 +148,19 @@ _FORCE_INLINE_ int TerraChunk::get_data_size_z() const {
_FORCE_INLINE_ void TerraChunk::set_data_size_x(const int value) { _FORCE_INLINE_ void TerraChunk::set_data_size_x(const int value) {
_data_size_x = value; _data_size_x = value;
} }
_FORCE_INLINE_ void TerraChunk::set_data_size_y(const int value) {
_data_size_y = value;
}
_FORCE_INLINE_ void TerraChunk::set_data_size_z(const int value) { _FORCE_INLINE_ void TerraChunk::set_data_size_z(const int value) {
_data_size_z = value; _data_size_z = value;
} }
void TerraChunk::set_position(const int x, const int y, const int z) { _FORCE_INLINE_ float TerraChunk::get_world_height() const {
return _world_height;
}
void TerraChunk::set_world_height(const float value) {
_world_height = value;
}
void TerraChunk::set_position(const int x, const int z) {
_position_x = x; _position_x = x;
_position_y = y;
_position_z = z; _position_z = z;
} }
@ -289,8 +279,8 @@ void TerraChunk::channel_setup() {
call("_channel_setup"); call("_channel_setup");
} }
void TerraChunk::set_size(const int size_x, const int size_y, const int size_z, const int margin_start, const int margin_end) { void TerraChunk::set_size(const int size_x, const int size_z, const int margin_start, const int margin_end) {
if (_size_x == size_x && _size_y == size_y && _size_z == size_z && _margin_start == margin_start && _margin_end == margin_end) { if (_size_x == size_x && _size_z == size_z && _margin_start == margin_start && _margin_end == margin_end) {
return; return;
} }
@ -305,47 +295,43 @@ void TerraChunk::set_size(const int size_x, const int size_y, const int size_z,
channel_setup(); channel_setup();
_size_x = size_x; _size_x = size_x;
_size_y = size_y;
_size_z = size_z; _size_z = size_z;
_data_size_x = size_x + margin_start + margin_end; _data_size_x = size_x + margin_start + margin_end;
_data_size_y = size_y + margin_start + margin_end;
_data_size_z = size_z + margin_start + margin_end; _data_size_z = size_z + margin_start + margin_end;
_margin_start = margin_start; _margin_start = margin_start;
_margin_end = margin_end; _margin_end = margin_end;
} }
bool TerraChunk::validate_data_position(const int x, const int y, const int z) const { bool TerraChunk::validate_data_position(const int x, const int z) const {
return x < _data_size_x && y < _data_size_y && z < _data_size_z; return x < _data_size_x && z < _data_size_z;
} }
uint8_t TerraChunk::get_voxel(const int p_x, const int p_y, const int p_z, const int p_channel_index) const { uint8_t TerraChunk::get_voxel(const int p_x, const int p_z, const int p_channel_index) const {
int x = p_x + _margin_start; int x = p_x + _margin_start;
int y = p_y + _margin_start;
int z = p_z + _margin_start; int z = p_z + _margin_start;
ERR_FAIL_INDEX_V(p_channel_index, _channels.size(), 0); ERR_FAIL_INDEX_V(p_channel_index, _channels.size(), 0);
ERR_FAIL_COND_V_MSG(!validate_data_position(x, y, z), 0, "Error, index out of range! " + String::num(x) + " " + String::num(y) + " " + String::num(z)); ERR_FAIL_COND_V_MSG(!validate_data_position(x, z), 0, "Error, index out of range! " + String::num(x) + " " + String::num(z));
uint8_t *ch = _channels.get(p_channel_index); uint8_t *ch = _channels.get(p_channel_index);
if (!ch) if (!ch)
return 0; return 0;
return ch[get_data_index(x, y, z)]; return ch[get_data_index(x, z)];
} }
void TerraChunk::set_voxel(const uint8_t p_value, const int p_x, const int p_y, const int p_z, const int p_channel_index) { void TerraChunk::set_voxel(const uint8_t p_value, const int p_x, const int p_z, const int p_channel_index) {
int x = p_x + _margin_start; int x = p_x + _margin_start;
int y = p_y + _margin_start;
int z = p_z + _margin_start; int z = p_z + _margin_start;
ERR_FAIL_INDEX(p_channel_index, _channels.size()); ERR_FAIL_INDEX(p_channel_index, _channels.size());
ERR_FAIL_COND_MSG(!validate_data_position(x, y, z), "Error, index out of range! " + String::num(x) + " " + String::num(y) + " " + String::num(z)); ERR_FAIL_COND_MSG(!validate_data_position(x, z), "Error, index out of range! " + String::num(x) + " " + String::num(z));
uint8_t *ch = channel_get_valid(p_channel_index); uint8_t *ch = channel_get_valid(p_channel_index);
ch[get_data_index(x, y, z)] = p_value; ch[get_data_index(x, z)] = p_value;
} }
int TerraChunk::channel_get_count() const { int TerraChunk::channel_get_count() const {
@ -393,7 +379,7 @@ void TerraChunk::channel_allocate(const int channel_index, const uint8_t default
if (_channels[channel_index] != NULL) if (_channels[channel_index] != NULL)
return; return;
uint32_t size = _data_size_x * _data_size_y * _data_size_z; uint32_t size = _data_size_x * _data_size_z;
uint8_t *ch = memnew_arr(uint8_t, size); uint8_t *ch = memnew_arr(uint8_t, size);
memset(ch, default_value, size); memset(ch, default_value, size);
@ -450,7 +436,7 @@ uint8_t *TerraChunk::channel_get_valid(const int channel_index, const uint8_t de
PoolByteArray TerraChunk::channel_get_array(const int channel_index) const { PoolByteArray TerraChunk::channel_get_array(const int channel_index) const {
PoolByteArray arr; PoolByteArray arr;
uint32_t size = _data_size_x * _data_size_y * _data_size_z; uint32_t size = _data_size_x * _data_size_z;
if (channel_index >= _channels.size()) if (channel_index >= _channels.size())
return arr; return arr;
@ -493,7 +479,7 @@ void TerraChunk::channel_set_array(const int channel_index, const PoolByteArray
PoolByteArray TerraChunk::channel_get_compressed(const int channel_index) const { PoolByteArray TerraChunk::channel_get_compressed(const int channel_index) const {
PoolByteArray arr; PoolByteArray arr;
int size = _data_size_x * _data_size_y * _data_size_z; int size = _data_size_x * _data_size_z;
if (channel_index >= _channels.size()) if (channel_index >= _channels.size())
return arr; return arr;
@ -523,7 +509,7 @@ void TerraChunk::channel_set_compressed(const int channel_index, const PoolByteA
if (data.size() == 0) if (data.size() == 0)
return; return;
int size = _data_size_x * _data_size_y * _data_size_z; int size = _data_size_x * _data_size_z;
if (_channels.size() <= channel_index) if (_channels.size() <= channel_index)
channel_set_count(channel_index + 1); channel_set_count(channel_index + 1);
@ -555,16 +541,16 @@ void TerraChunk::channel_set_compressed(const int channel_index, const PoolByteA
#endif #endif
} }
_FORCE_INLINE_ int TerraChunk::get_index(const int x, const int y, const int z) const { _FORCE_INLINE_ int TerraChunk::get_index(const int x, const int z) const {
return (y + _margin_start) + _data_size_y * ((x + _margin_start) + _data_size_x * (z + _margin_start)); return ((x + _margin_start) + _data_size_x * (z + _margin_start));
} }
_FORCE_INLINE_ int TerraChunk::get_data_index(const int x, const int y, const int z) const { _FORCE_INLINE_ int TerraChunk::get_data_index(const int x, const int z) const {
return y + _data_size_y * (x + _data_size_x * z); return (x + _data_size_x * z);
} }
_FORCE_INLINE_ int TerraChunk::get_data_size() const { _FORCE_INLINE_ int TerraChunk::get_data_size() const {
return _data_size_x * _data_size_y * _data_size_z; return _data_size_x * _data_size_z;
} }
//Terra Structures //Terra Structures
@ -1015,15 +1001,12 @@ TerraChunk::TerraChunk() {
_voxel_world = NULL; _voxel_world = NULL;
_position_x = 0; _position_x = 0;
_position_y = 0;
_position_z = 0; _position_z = 0;
_size_x = 0; _size_x = 0;
_size_y = 0;
_size_z = 0; _size_z = 0;
_data_size_x = 0; _data_size_x = 0;
_data_size_y = 0;
_data_size_z = 0; _data_size_z = 0;
_margin_start = 0; _margin_start = 0;
@ -1031,6 +1014,8 @@ TerraChunk::TerraChunk() {
_current_job = -1; _current_job = -1;
_world_height = 256;
_queued_generation = false; _queued_generation = false;
} }
@ -1144,7 +1129,7 @@ void TerraChunk::_world_transform_changed() {
wt = _voxel_world->get_transform(); wt = _voxel_world->get_transform();
} }
set_transform(wt * Transform(Basis(), Vector3(_position_x * static_cast<int>(_size_x) * _voxel_scale, _position_y * static_cast<int>(_size_y) * _voxel_scale, _position_z * static_cast<int>(_size_z) * _voxel_scale))); set_transform(wt * Transform(Basis(), Vector3(_position_x * static_cast<int>(_size_x) * _voxel_scale, 0, _position_z * static_cast<int>(_size_z) * _voxel_scale)));
} }
/* /*
@ -1271,10 +1256,6 @@ void TerraChunk::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_position_x", "value"), &TerraChunk::set_position_x); ClassDB::bind_method(D_METHOD("set_position_x", "value"), &TerraChunk::set_position_x);
ADD_PROPERTY(PropertyInfo(Variant::INT, "position_x"), "set_position_x", "get_position_x"); ADD_PROPERTY(PropertyInfo(Variant::INT, "position_x"), "set_position_x", "get_position_x");
ClassDB::bind_method(D_METHOD("get_position_y"), &TerraChunk::get_position_y);
ClassDB::bind_method(D_METHOD("set_position_y", "value"), &TerraChunk::set_position_y);
ADD_PROPERTY(PropertyInfo(Variant::INT, "position_y"), "set_position_y", "get_position_y");
ClassDB::bind_method(D_METHOD("get_position_z"), &TerraChunk::get_position_z); ClassDB::bind_method(D_METHOD("get_position_z"), &TerraChunk::get_position_z);
ClassDB::bind_method(D_METHOD("set_position_z", "value"), &TerraChunk::set_position_z); ClassDB::bind_method(D_METHOD("set_position_z", "value"), &TerraChunk::set_position_z);
ADD_PROPERTY(PropertyInfo(Variant::INT, "position_z"), "set_position_z", "get_position_z"); ADD_PROPERTY(PropertyInfo(Variant::INT, "position_z"), "set_position_z", "get_position_z");
@ -1283,10 +1264,6 @@ void TerraChunk::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_size_x"), &TerraChunk::set_size_x); ClassDB::bind_method(D_METHOD("set_size_x"), &TerraChunk::set_size_x);
ADD_PROPERTY(PropertyInfo(Variant::INT, "size_x"), "set_size_x", "get_size_x"); ADD_PROPERTY(PropertyInfo(Variant::INT, "size_x"), "set_size_x", "get_size_x");
ClassDB::bind_method(D_METHOD("get_size_y"), &TerraChunk::get_size_y);
ClassDB::bind_method(D_METHOD("set_size_y"), &TerraChunk::set_size_y);
ADD_PROPERTY(PropertyInfo(Variant::INT, "size_y"), "set_size_y", "get_size_y");
ClassDB::bind_method(D_METHOD("get_size_z"), &TerraChunk::get_size_z); ClassDB::bind_method(D_METHOD("get_size_z"), &TerraChunk::get_size_z);
ClassDB::bind_method(D_METHOD("set_size_z"), &TerraChunk::set_size_z); ClassDB::bind_method(D_METHOD("set_size_z"), &TerraChunk::set_size_z);
ADD_PROPERTY(PropertyInfo(Variant::INT, "size_z"), "set_size_z", "get_size_z"); ADD_PROPERTY(PropertyInfo(Variant::INT, "size_z"), "set_size_z", "get_size_z");
@ -1295,14 +1272,14 @@ void TerraChunk::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_data_size_x"), &TerraChunk::set_data_size_x); ClassDB::bind_method(D_METHOD("set_data_size_x"), &TerraChunk::set_data_size_x);
ADD_PROPERTY(PropertyInfo(Variant::INT, "data_size_x"), "set_data_size_x", "get_data_size_x"); ADD_PROPERTY(PropertyInfo(Variant::INT, "data_size_x"), "set_data_size_x", "get_data_size_x");
ClassDB::bind_method(D_METHOD("get_data_size_y"), &TerraChunk::get_data_size_y);
ClassDB::bind_method(D_METHOD("set_data_size_y"), &TerraChunk::set_data_size_y);
ADD_PROPERTY(PropertyInfo(Variant::INT, "data_size_y"), "set_data_size_y", "get_data_size_y");
ClassDB::bind_method(D_METHOD("get_data_size_z"), &TerraChunk::get_data_size_z); ClassDB::bind_method(D_METHOD("get_data_size_z"), &TerraChunk::get_data_size_z);
ClassDB::bind_method(D_METHOD("set_data_size_z"), &TerraChunk::set_data_size_z); ClassDB::bind_method(D_METHOD("set_data_size_z"), &TerraChunk::set_data_size_z);
ADD_PROPERTY(PropertyInfo(Variant::INT, "data_size_z"), "set_data_size_z", "get_data_size_z"); ADD_PROPERTY(PropertyInfo(Variant::INT, "data_size_z"), "set_data_size_z", "get_data_size_z");
ClassDB::bind_method(D_METHOD("get_world_height"), &TerraChunk::get_world_height);
ClassDB::bind_method(D_METHOD("set_world_height", "height"), &TerraChunk::set_world_height);
ADD_PROPERTY(PropertyInfo(Variant::REAL, "world_height"), "set_world_height", "get_world_height");
ClassDB::bind_method(D_METHOD("get_position"), &TerraChunk::get_position); ClassDB::bind_method(D_METHOD("get_position"), &TerraChunk::get_position);
ClassDB::bind_method(D_METHOD("set_position", "x", "y", "z"), &TerraChunk::set_position); ClassDB::bind_method(D_METHOD("set_position", "x", "y", "z"), &TerraChunk::set_position);

View File

@ -108,33 +108,30 @@ public:
int get_position_x() const; int get_position_x() const;
void set_position_x(const int value); void set_position_x(const int value);
int get_position_y() const;
void set_position_y(const int value);
int get_position_z() const; int get_position_z() const;
void set_position_z(const int value); void set_position_z(const int value);
int get_size_x() const; int get_size_x() const;
int get_size_y() const;
int get_size_z() const; int get_size_z() const;
void set_size_x(const int value); void set_size_x(const int value);
void set_size_y(const int value);
void set_size_z(const int value); void set_size_z(const int value);
int get_data_size_x() const; int get_data_size_x() const;
int get_data_size_y() const;
int get_data_size_z() const; int get_data_size_z() const;
void set_data_size_x(const int value); void set_data_size_x(const int value);
void set_data_size_y(const int value);
void set_data_size_z(const int value); void set_data_size_z(const int value);
Vector3 get_position() const; float get_world_height() const;
void set_world_height(const float value);
Vector2 get_position() const;
Vector3 get_size() const; Vector3 get_size() const;
Vector3 get_world_position() const; Vector2 get_world_position() const;
Vector3 get_world_size() const; Vector3 get_world_size() const;
AABB get_world_aabb() const; AABB get_world_aabb() const;
void set_position(const int x, const int y, const int z); void set_position(const int x, const int z);
int get_margin_start() const; int get_margin_start() const;
int get_margin_end() const; int get_margin_end() const;
@ -165,12 +162,12 @@ public:
//Channels //Channels
void channel_setup(); void channel_setup();
void set_size(const int size_x, const int size_y, const int size_z, const int margin_start = 0, const int margin_end = 0); void set_size(const int size_x, const int size_z, const int margin_start = 0, const int margin_end = 0);
bool validate_data_position(const int x, const int y, const int z) const; bool validate_data_position(const int x, const int z) const;
uint8_t get_voxel(const int p_x, const int p_y, const int p_z, const int p_index) const; uint8_t get_voxel(const int p_x, const int p_z, const int p_index) const;
void set_voxel(const uint8_t p_value, const int p_x, const int p_y, const int p_z, const int p_index); void set_voxel(const uint8_t p_value, const int p_x, const int p_z, const int p_index);
int channel_get_count() const; int channel_get_count() const;
void channel_set_count(const int count); void channel_set_count(const int count);
@ -190,8 +187,8 @@ public:
PoolByteArray channel_get_compressed(const int channel_index) const; PoolByteArray channel_get_compressed(const int channel_index) const;
void channel_set_compressed(const int channel_index, const PoolByteArray &data); void channel_set_compressed(const int channel_index, const PoolByteArray &data);
int get_index(const int x, const int y, const int z) const; int get_index(const int x, const int z) const;
int get_data_index(const int x, const int y, const int z) const; int get_data_index(const int x, const int z) const;
int get_data_size() const; int get_data_size() const;
//Terra Structures //Terra Structures
@ -353,20 +350,19 @@ protected:
TerraWorld *_voxel_world; TerraWorld *_voxel_world;
int _position_x; int _position_x;
int _position_y;
int _position_z; int _position_z;
int _size_x; int _size_x;
int _size_y;
int _size_z; int _size_z;
int _data_size_x; int _data_size_x;
int _data_size_y;
int _data_size_z; int _data_size_z;
int _margin_start; int _margin_start;
int _margin_end; int _margin_end;
float _world_height;
Vector<uint8_t *> _channels; Vector<uint8_t *> _channels;
float _voxel_scale; float _voxel_scale;

View File

@ -57,13 +57,6 @@ void TerraWorld::set_chunk_size_x(const int value) {
_chunk_size_x = value; _chunk_size_x = value;
} }
int TerraWorld::get_chunk_size_y() const {
return _chunk_size_y;
}
void TerraWorld::set_chunk_size_y(const int value) {
_chunk_size_y = value;
}
int TerraWorld::get_chunk_size_z() const { int TerraWorld::get_chunk_size_z() const {
return _chunk_size_z; return _chunk_size_z;
} }
@ -108,6 +101,13 @@ void TerraWorld::set_use_threads(const bool value) {
} }
} }
_FORCE_INLINE_ float TerraWorld::get_world_height() const {
return _world_height;
}
void TerraWorld::set_world_height(const float value) {
_world_height = value;
}
int TerraWorld::get_max_concurrent_generations() const { int TerraWorld::get_max_concurrent_generations() const {
return _max_concurrent_generations; return _max_concurrent_generations;
} }
@ -259,16 +259,16 @@ void TerraWorld::voxel_structures_set(const Vector<Variant> &structures) {
} }
} }
void TerraWorld::chunk_add(Ref<TerraChunk> chunk, const int x, const int y, const int z) { void TerraWorld::chunk_add(Ref<TerraChunk> chunk, const int x, const int z) {
ERR_FAIL_COND(!chunk.is_valid()); ERR_FAIL_COND(!chunk.is_valid());
ERR_FAIL_COND_MSG(chunk->get_voxel_world() != NULL && chunk->get_voxel_world() != this, "Chunk is already owned by an another world!"); ERR_FAIL_COND_MSG(chunk->get_voxel_world() != NULL && chunk->get_voxel_world() != this, "Chunk is already owned by an another world!");
IntPos pos(x, y, z); IntPos pos(x, z);
//ERR_FAIL_COND(_chunks.has(pos)); //ERR_FAIL_COND(_chunks.has(pos));
chunk->set_voxel_world(this); chunk->set_voxel_world(this);
chunk->set_position(x, y, z); chunk->set_position(x, z);
chunk->world_transform_changed(); chunk->world_transform_changed();
if (!_chunks.has(pos)) if (!_chunks.has(pos))
@ -283,19 +283,19 @@ void TerraWorld::chunk_add(Ref<TerraChunk> chunk, const int x, const int y, cons
if (has_method("_chunk_added")) if (has_method("_chunk_added"))
call("_chunk_added", chunk); call("_chunk_added", chunk);
} }
bool TerraWorld::chunk_has(const int x, const int y, const int z) const { bool TerraWorld::chunk_has(const int x, const int z) const {
return _chunks.has(IntPos(x, y, z)); return _chunks.has(IntPos(x, z));
} }
Ref<TerraChunk> TerraWorld::chunk_get(const int x, const int y, const int z) { Ref<TerraChunk> TerraWorld::chunk_get(const int x, const int z) {
IntPos pos(x, y, z); IntPos pos(x, z);
if (_chunks.has(pos)) if (_chunks.has(pos))
return _chunks.get(pos); return _chunks.get(pos);
return Ref<TerraChunk>(); return Ref<TerraChunk>();
} }
Ref<TerraChunk> TerraWorld::chunk_remove(const int x, const int y, const int z) { Ref<TerraChunk> TerraWorld::chunk_remove(const int x, const int z) {
IntPos pos(x, y, z); IntPos pos(x, z);
if (!_chunks.has(pos)) if (!_chunks.has(pos))
return NULL; return NULL;
@ -322,7 +322,7 @@ Ref<TerraChunk> TerraWorld::chunk_remove_index(const int index) {
Ref<TerraChunk> chunk = _chunks_vector.get(index); Ref<TerraChunk> chunk = _chunks_vector.get(index);
_chunks_vector.remove(index); _chunks_vector.remove(index);
_chunks.erase(IntPos(chunk->get_position_x(), chunk->get_position_y(), chunk->get_position_z())); _chunks.erase(IntPos(chunk->get_position_x(), chunk->get_position_z()));
chunk->exit_tree(); chunk->exit_tree();
return chunk; return chunk;
@ -350,18 +350,18 @@ void TerraWorld::chunks_clear() {
_generating.clear(); _generating.clear();
} }
Ref<TerraChunk> TerraWorld::chunk_get_or_create(int x, int y, int z) { Ref<TerraChunk> TerraWorld::chunk_get_or_create(int x, int z) {
Ref<TerraChunk> chunk = chunk_get(x, y, z); Ref<TerraChunk> chunk = chunk_get(x, z);
if (!chunk.is_valid()) { if (!chunk.is_valid()) {
chunk = chunk_create(x, y, z); chunk = chunk_create(x, z);
} }
return chunk; return chunk;
} }
Ref<TerraChunk> TerraWorld::chunk_create(const int x, const int y, const int z) { Ref<TerraChunk> TerraWorld::chunk_create(const int x, const int z) {
Ref<TerraChunk> c = call("_create_chunk", x, y, z, Ref<TerraChunk>()); Ref<TerraChunk> c = call("_create_chunk", x, z, Ref<TerraChunk>());
generation_queue_add_to(c); generation_queue_add_to(c);
@ -371,10 +371,10 @@ Ref<TerraChunk> TerraWorld::chunk_create(const int x, const int y, const int z)
void TerraWorld::chunk_setup(Ref<TerraChunk> chunk) { void TerraWorld::chunk_setup(Ref<TerraChunk> chunk) {
ERR_FAIL_COND(!chunk.is_valid()); ERR_FAIL_COND(!chunk.is_valid());
call("_create_chunk", chunk->get_position_x(), chunk->get_position_y(), chunk->get_position_z(), chunk); call("_create_chunk", chunk->get_position_x(), chunk->get_position_z(), chunk);
} }
Ref<TerraChunk> TerraWorld::_create_chunk(const int x, const int y, const int z, Ref<TerraChunk> chunk) { Ref<TerraChunk> TerraWorld::_create_chunk(const int x, const int z, Ref<TerraChunk> chunk) {
if (!chunk.is_valid()) { if (!chunk.is_valid()) {
chunk.instance(); chunk.instance();
} }
@ -383,7 +383,7 @@ Ref<TerraChunk> TerraWorld::_create_chunk(const int x, const int y, const int z,
ERR_FAIL_COND_V(!chunk.is_valid(), NULL); ERR_FAIL_COND_V(!chunk.is_valid(), NULL);
chunk->set_name("Chunk[" + String::num(x) + "," + String::num(y) + "," + String::num(z) + "]"); chunk->set_name("Chunk[" + String::num(x) + "," + String::num(z) + "]");
chunk->set_voxel_world(this); chunk->set_voxel_world(this);
@ -391,13 +391,14 @@ Ref<TerraChunk> TerraWorld::_create_chunk(const int x, const int y, const int z,
if (chunk->has_method("set_is_build_threaded")) if (chunk->has_method("set_is_build_threaded"))
chunk->call("set_is_build_threaded", _use_threads); chunk->call("set_is_build_threaded", _use_threads);
chunk->set_position(x, y, z); chunk->set_position(x, z);
chunk->set_world_height(_world_height);
chunk->set_library(_library); chunk->set_library(_library);
chunk->set_voxel_scale(_voxel_scale); chunk->set_voxel_scale(_voxel_scale);
chunk->set_size(_chunk_size_x, _chunk_size_y, _chunk_size_z, _data_margin_start, _data_margin_end); chunk->set_size(_chunk_size_x, _chunk_size_z, _data_margin_start, _data_margin_end);
//chunk->set_translation(Vector3(x * _chunk_size_x * _voxel_scale, y * _chunk_size_y * _voxel_scale, z * _chunk_size_z * _voxel_scale)); //chunk->set_translation(Vector3(x * _chunk_size_x * _voxel_scale, y * _chunk_size_y * _voxel_scale, z * _chunk_size_z * _voxel_scale));
chunk_add(chunk, x, y, z); chunk_add(chunk, x, z);
return chunk; return chunk;
} }
@ -440,7 +441,7 @@ void TerraWorld::chunks_set(const Vector<Variant> &chunks) {
if (_chunks_vector.find(chunk) != -1) if (_chunks_vector.find(chunk) != -1)
continue; continue;
chunk_add(chunk, chunk->get_position_x(), chunk->get_position_y(), chunk->get_position_z()); chunk_add(chunk, chunk->get_position_x(), chunk->get_position_z());
} }
} else { } else {
_chunks_vector.clear(); _chunks_vector.clear();
@ -487,10 +488,9 @@ bool TerraWorld::can_chunk_do_build_step() {
bool TerraWorld::is_position_walkable(const Vector3 &p_pos) { bool TerraWorld::is_position_walkable(const Vector3 &p_pos) {
int x = static_cast<int>(Math::floor(p_pos.x / (_chunk_size_x * _voxel_scale))); int x = static_cast<int>(Math::floor(p_pos.x / (_chunk_size_x * _voxel_scale)));
int y = static_cast<int>(Math::floor(p_pos.y / (_chunk_size_y * _voxel_scale)));
int z = static_cast<int>(Math::floor(p_pos.z / (_chunk_size_z * _voxel_scale))); int z = static_cast<int>(Math::floor(p_pos.z / (_chunk_size_z * _voxel_scale)));
Ref<TerraChunk> c = chunk_get(x, y, z); Ref<TerraChunk> c = chunk_get(x, z);
if (!c.is_valid()) if (!c.is_valid())
return false; return false;
@ -705,29 +705,23 @@ uint8_t TerraWorld::get_voxel_at_world_position(const Vector3 &world_position, c
//Note: floor is needed to handle negative numbers properly //Note: floor is needed to handle negative numbers properly
int x = static_cast<int>(Math::floor(pos.x / get_chunk_size_x())); int x = static_cast<int>(Math::floor(pos.x / get_chunk_size_x()));
int y = static_cast<int>(Math::floor(pos.y / get_chunk_size_y()));
int z = static_cast<int>(Math::floor(pos.z / get_chunk_size_z())); int z = static_cast<int>(Math::floor(pos.z / get_chunk_size_z()));
int bx = static_cast<int>(Math::floor(pos.x)) % get_chunk_size_x(); int bx = static_cast<int>(Math::floor(pos.x)) % get_chunk_size_x();
int by = static_cast<int>(Math::floor(pos.y)) % get_chunk_size_y();
int bz = static_cast<int>(Math::floor(pos.z)) % get_chunk_size_z(); int bz = static_cast<int>(Math::floor(pos.z)) % get_chunk_size_z();
if (bx < 0) { if (bx < 0) {
bx += get_chunk_size_x(); bx += get_chunk_size_x();
} }
if (by < 0) {
by += get_chunk_size_y();
}
if (bz < 0) { if (bz < 0) {
bz += get_chunk_size_z(); bz += get_chunk_size_z();
} }
Ref<TerraChunk> chunk = chunk_get(x, y, z); Ref<TerraChunk> chunk = chunk_get(x, z);
if (chunk.is_valid()) if (chunk.is_valid())
return chunk->get_voxel(bx, by, bz, channel_index); return chunk->get_voxel(bx, bz, channel_index);
return 0; return 0;
} }
@ -737,45 +731,31 @@ void TerraWorld::set_voxel_at_world_position(const Vector3 &world_position, cons
//Note: floor is needed to handle negative numbers properly //Note: floor is needed to handle negative numbers properly
int x = static_cast<int>(Math::floor(pos.x / get_chunk_size_x())); int x = static_cast<int>(Math::floor(pos.x / get_chunk_size_x()));
int y = static_cast<int>(Math::floor(pos.y / get_chunk_size_y()));
int z = static_cast<int>(Math::floor(pos.z / get_chunk_size_z())); int z = static_cast<int>(Math::floor(pos.z / get_chunk_size_z()));
int bx = static_cast<int>(Math::floor(pos.x)) % get_chunk_size_x(); int bx = static_cast<int>(Math::floor(pos.x)) % get_chunk_size_x();
int by = static_cast<int>(Math::floor(pos.y)) % get_chunk_size_y();
int bz = static_cast<int>(Math::floor(pos.z)) % get_chunk_size_z(); int bz = static_cast<int>(Math::floor(pos.z)) % get_chunk_size_z();
if (bx < 0) { if (bx < 0) {
bx += get_chunk_size_x(); bx += get_chunk_size_x();
} }
if (by < 0) {
by += get_chunk_size_y();
}
if (bz < 0) { if (bz < 0) {
bz += get_chunk_size_z(); bz += get_chunk_size_z();
} }
if (get_data_margin_end() > 0) { if (get_data_margin_end() > 0) {
if (bx == 0) { if (bx == 0) {
Ref<TerraChunk> chunk = chunk_get_or_create(x - 1, y, z); Ref<TerraChunk> chunk = chunk_get_or_create(x - 1, z);
chunk->set_voxel(data, get_chunk_size_x(), by, bz, channel_index); chunk->set_voxel(data, get_chunk_size_x(), bz, channel_index);
if (rebuild)
chunk->build();
}
if (by == 0) {
Ref<TerraChunk> chunk = chunk_get_or_create(x, y - 1, z);
chunk->set_voxel(data, bx, get_chunk_size_y(), bz, channel_index);
if (rebuild) if (rebuild)
chunk->build(); chunk->build();
} }
if (bz == 0) { if (bz == 0) {
Ref<TerraChunk> chunk = chunk_get_or_create(x, y, z - 1); Ref<TerraChunk> chunk = chunk_get_or_create(x, z - 1);
chunk->set_voxel(data, bx, by, get_chunk_size_z(), channel_index); chunk->set_voxel(data, bx, get_chunk_size_z(), channel_index);
if (rebuild) if (rebuild)
chunk->build(); chunk->build();
@ -784,32 +764,24 @@ void TerraWorld::set_voxel_at_world_position(const Vector3 &world_position, cons
if (get_data_margin_start() > 0) { if (get_data_margin_start() > 0) {
if (bx == get_chunk_size_x() - 1) { if (bx == get_chunk_size_x() - 1) {
Ref<TerraChunk> chunk = chunk_get_or_create(x + 1, y, z); Ref<TerraChunk> chunk = chunk_get_or_create(x + 1, z);
chunk->set_voxel(data, -1, by, bz, channel_index); chunk->set_voxel(data, -1, bz, channel_index);
if (rebuild)
chunk->build();
}
if (by == get_chunk_size_y() - 1) {
Ref<TerraChunk> chunk = chunk_get_or_create(x, y + 1, z);
chunk->set_voxel(data, bx, -1, bz, channel_index);
if (rebuild) if (rebuild)
chunk->build(); chunk->build();
} }
if (bz == get_chunk_size_z() - 1) { if (bz == get_chunk_size_z() - 1) {
Ref<TerraChunk> chunk = chunk_get_or_create(x, y, z + 1); Ref<TerraChunk> chunk = chunk_get_or_create(x, z + 1);
chunk->set_voxel(data, bx, by, -1, channel_index); chunk->set_voxel(data, bx, -1, channel_index);
if (rebuild) if (rebuild)
chunk->build(); chunk->build();
} }
} }
Ref<TerraChunk> chunk = chunk_get_or_create(x, y, z); Ref<TerraChunk> chunk = chunk_get_or_create(x, z);
chunk->set_voxel(data, bx, by, bz, channel_index); chunk->set_voxel(data, bx, bz, channel_index);
if (rebuild) if (rebuild)
chunk->build(); chunk->build();
@ -820,20 +792,18 @@ Ref<TerraChunk> TerraWorld::get_chunk_at_world_position(const Vector3 &world_pos
//Note: floor is needed to handle negative numbers proiberly //Note: floor is needed to handle negative numbers proiberly
int x = static_cast<int>(Math::floor(pos.x / get_chunk_size_x())); int x = static_cast<int>(Math::floor(pos.x / get_chunk_size_x()));
int y = static_cast<int>(Math::floor(pos.y / get_chunk_size_y()));
int z = static_cast<int>(Math::floor(pos.z / get_chunk_size_z())); int z = static_cast<int>(Math::floor(pos.z / get_chunk_size_z()));
return chunk_get(x, y, z); return chunk_get(x, z);
} }
Ref<TerraChunk> TerraWorld::get_or_create_chunk_at_world_position(const Vector3 &world_position) { Ref<TerraChunk> TerraWorld::get_or_create_chunk_at_world_position(const Vector3 &world_position) {
Vector3 pos = world_position / get_voxel_scale(); Vector3 pos = world_position / get_voxel_scale();
//Note: floor is needed to handle negative numbers proiberly //Note: floor is needed to handle negative numbers proiberly
int x = static_cast<int>(Math::floor(pos.x / get_chunk_size_x())); int x = static_cast<int>(Math::floor(pos.x / get_chunk_size_x()));
int y = static_cast<int>(Math::floor(pos.y / get_chunk_size_y()));
int z = static_cast<int>(Math::floor(pos.z / get_chunk_size_z())); int z = static_cast<int>(Math::floor(pos.z / get_chunk_size_z()));
return chunk_get_or_create(x, y, z); return chunk_get_or_create(x, z);
} }
void TerraWorld::set_voxel_with_tool(const bool mode_add, const Vector3 hit_position, const Vector3 hit_normal, const int selected_voxel, const int isolevel) { void TerraWorld::set_voxel_with_tool(const bool mode_add, const Vector3 hit_position, const Vector3 hit_normal, const int selected_voxel, const int isolevel) {
@ -850,11 +820,11 @@ TerraWorld::TerraWorld() {
_is_priority_generation = true; _is_priority_generation = true;
_chunk_size_x = 16; _chunk_size_x = 16;
_chunk_size_y = 16;
_chunk_size_z = 16; _chunk_size_z = 16;
_current_seed = 0; _current_seed = 0;
_data_margin_start = 0; _data_margin_start = 0;
_data_margin_end = 0; _data_margin_end = 0;
_world_height = 256;
set_use_threads(true); set_use_threads(true);
set_max_concurrent_generations(3); set_max_concurrent_generations(3);
@ -897,7 +867,7 @@ void TerraWorld::_generate_chunk(Ref<TerraChunk> chunk) {
continue; continue;
if (structure->get_use_aabb()) { if (structure->get_use_aabb()) {
if (structure->get_chunk_aabb().has_point(Vector3(chunk->get_position_x(), chunk->get_position_y(), chunk->get_position_z()))) if (structure->get_chunk_aabb().has_point(Vector3(chunk->get_position_x(), 1, chunk->get_position_z())))
structure->write_to_chunk(chunk); structure->write_to_chunk(chunk);
} else { } else {
structure->write_to_chunk(chunk); structure->write_to_chunk(chunk);
@ -1038,10 +1008,6 @@ void TerraWorld::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_chunk_size_x", "value"), &TerraWorld::set_chunk_size_x); ClassDB::bind_method(D_METHOD("set_chunk_size_x", "value"), &TerraWorld::set_chunk_size_x);
ADD_PROPERTY(PropertyInfo(Variant::INT, "chunk_size_x"), "set_chunk_size_x", "get_chunk_size_x"); ADD_PROPERTY(PropertyInfo(Variant::INT, "chunk_size_x"), "set_chunk_size_x", "get_chunk_size_x");
ClassDB::bind_method(D_METHOD("get_chunk_size_y"), &TerraWorld::get_chunk_size_y);
ClassDB::bind_method(D_METHOD("set_chunk_size_y", "value"), &TerraWorld::set_chunk_size_y);
ADD_PROPERTY(PropertyInfo(Variant::INT, "chunk_size_y"), "set_chunk_size_y", "get_chunk_size_y");
ClassDB::bind_method(D_METHOD("get_chunk_size_z"), &TerraWorld::get_chunk_size_z); ClassDB::bind_method(D_METHOD("get_chunk_size_z"), &TerraWorld::get_chunk_size_z);
ClassDB::bind_method(D_METHOD("set_chunk_size_z", "value"), &TerraWorld::set_chunk_size_z); ClassDB::bind_method(D_METHOD("set_chunk_size_z", "value"), &TerraWorld::set_chunk_size_z);
ADD_PROPERTY(PropertyInfo(Variant::INT, "chunk_size_z"), "set_chunk_size_z", "get_chunk_size_z"); ADD_PROPERTY(PropertyInfo(Variant::INT, "chunk_size_z"), "set_chunk_size_z", "get_chunk_size_z");
@ -1054,6 +1020,10 @@ void TerraWorld::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_data_margin_end", "value"), &TerraWorld::set_data_margin_end); ClassDB::bind_method(D_METHOD("set_data_margin_end", "value"), &TerraWorld::set_data_margin_end);
ADD_PROPERTY(PropertyInfo(Variant::INT, "data_margin_end"), "set_data_margin_end", "get_data_margin_end"); ADD_PROPERTY(PropertyInfo(Variant::INT, "data_margin_end"), "set_data_margin_end", "get_data_margin_end");
ClassDB::bind_method(D_METHOD("get_world_height"), &TerraChunk::get_world_height);
ClassDB::bind_method(D_METHOD("set_world_height", "height"), &TerraChunk::set_world_height);
ADD_PROPERTY(PropertyInfo(Variant::REAL, "world_height"), "set_world_height", "get_world_height");
ClassDB::bind_method(D_METHOD("get_current_seed"), &TerraWorld::get_current_seed); ClassDB::bind_method(D_METHOD("get_current_seed"), &TerraWorld::get_current_seed);
ClassDB::bind_method(D_METHOD("set_current_seed", "value"), &TerraWorld::set_current_seed); ClassDB::bind_method(D_METHOD("set_current_seed", "value"), &TerraWorld::set_current_seed);
ADD_PROPERTY(PropertyInfo(Variant::INT, "current_seed"), "set_current_seed", "get_current_seed"); ADD_PROPERTY(PropertyInfo(Variant::INT, "current_seed"), "set_current_seed", "get_current_seed");
@ -1114,10 +1084,10 @@ void TerraWorld::_bind_methods() {
BIND_VMETHOD(MethodInfo("_chunk_added", PropertyInfo(Variant::OBJECT, "chunk", PROPERTY_HINT_RESOURCE_TYPE, "TerraChunk"))); BIND_VMETHOD(MethodInfo("_chunk_added", PropertyInfo(Variant::OBJECT, "chunk", PROPERTY_HINT_RESOURCE_TYPE, "TerraChunk")));
ClassDB::bind_method(D_METHOD("chunk_add", "chunk", "x", "y", "z"), &TerraWorld::chunk_add); ClassDB::bind_method(D_METHOD("chunk_add", "chunk", "x", "z"), &TerraWorld::chunk_add);
ClassDB::bind_method(D_METHOD("chunk_has", "x", "y", "z"), &TerraWorld::chunk_has); ClassDB::bind_method(D_METHOD("chunk_has", "x", "z"), &TerraWorld::chunk_has);
ClassDB::bind_method(D_METHOD("chunk_get", "x", "y", "z"), &TerraWorld::chunk_get); ClassDB::bind_method(D_METHOD("chunk_get", "x", "z"), &TerraWorld::chunk_get);
ClassDB::bind_method(D_METHOD("chunk_remove", "x", "y", "z"), &TerraWorld::chunk_remove); ClassDB::bind_method(D_METHOD("chunk_remove", "x", "z"), &TerraWorld::chunk_remove);
ClassDB::bind_method(D_METHOD("chunk_remove_index", "index"), &TerraWorld::chunk_remove_index); ClassDB::bind_method(D_METHOD("chunk_remove_index", "index"), &TerraWorld::chunk_remove_index);
ClassDB::bind_method(D_METHOD("chunk_get_index", "index"), &TerraWorld::chunk_get_index); ClassDB::bind_method(D_METHOD("chunk_get_index", "index"), &TerraWorld::chunk_get_index);
@ -1146,11 +1116,11 @@ void TerraWorld::_bind_methods() {
BIND_VMETHOD(MethodInfo("_prepare_chunk_for_generation", PropertyInfo(Variant::OBJECT, "chunk", PROPERTY_HINT_RESOURCE_TYPE, "TerraChunk"))); BIND_VMETHOD(MethodInfo("_prepare_chunk_for_generation", PropertyInfo(Variant::OBJECT, "chunk", PROPERTY_HINT_RESOURCE_TYPE, "TerraChunk")));
BIND_VMETHOD(MethodInfo("_generate_chunk", PropertyInfo(Variant::OBJECT, "chunk", PROPERTY_HINT_RESOURCE_TYPE, "TerraChunk"))); BIND_VMETHOD(MethodInfo("_generate_chunk", PropertyInfo(Variant::OBJECT, "chunk", PROPERTY_HINT_RESOURCE_TYPE, "TerraChunk")));
ClassDB::bind_method(D_METHOD("chunk_get_or_create", "x", "y", "z"), &TerraWorld::chunk_get_or_create); ClassDB::bind_method(D_METHOD("chunk_get_or_create", "x", "z"), &TerraWorld::chunk_get_or_create);
ClassDB::bind_method(D_METHOD("chunk_create", "x", "y", "z"), &TerraWorld::chunk_create); ClassDB::bind_method(D_METHOD("chunk_create", "x", "z"), &TerraWorld::chunk_create);
ClassDB::bind_method(D_METHOD("chunk_setup", "chunk"), &TerraWorld::chunk_setup); ClassDB::bind_method(D_METHOD("chunk_setup", "chunk"), &TerraWorld::chunk_setup);
ClassDB::bind_method(D_METHOD("_create_chunk", "x", "y", "z", "chunk"), &TerraWorld::_create_chunk); ClassDB::bind_method(D_METHOD("_create_chunk", "x", "z", "chunk"), &TerraWorld::_create_chunk);
ClassDB::bind_method(D_METHOD("_generate_chunk", "chunk"), &TerraWorld::_generate_chunk); ClassDB::bind_method(D_METHOD("_generate_chunk", "chunk"), &TerraWorld::_generate_chunk);
ClassDB::bind_method(D_METHOD("can_chunk_do_build_step"), &TerraWorld::can_chunk_do_build_step); ClassDB::bind_method(D_METHOD("can_chunk_do_build_step"), &TerraWorld::can_chunk_do_build_step);

View File

@ -70,9 +70,6 @@ public:
int get_chunk_size_x() const; int get_chunk_size_x() const;
void set_chunk_size_x(const int value); void set_chunk_size_x(const int value);
int get_chunk_size_y() const;
void set_chunk_size_y(const int value);
int get_chunk_size_z() const; int get_chunk_size_z() const;
void set_chunk_size_z(const int value); void set_chunk_size_z(const int value);
@ -88,6 +85,9 @@ public:
bool get_use_threads() const; bool get_use_threads() const;
void set_use_threads(const bool value); void set_use_threads(const bool value);
float get_world_height() const;
void set_world_height(const float value);
int get_max_concurrent_generations() const; int get_max_concurrent_generations() const;
void set_max_concurrent_generations(const int value); void set_max_concurrent_generations(const int value);
@ -133,10 +133,10 @@ public:
void voxel_structures_set(const Vector<Variant> &structures); void voxel_structures_set(const Vector<Variant> &structures);
//Chunks //Chunks
void chunk_add(Ref<TerraChunk> chunk, const int x, const int y, const int z); void chunk_add(Ref<TerraChunk> chunk, const int x, const int z);
bool chunk_has(const int x, const int y, const int z) const; bool chunk_has(const int x, const int z) const;
Ref<TerraChunk> chunk_get(const int x, const int y, const int z); Ref<TerraChunk> chunk_get(const int x, const int z);
Ref<TerraChunk> chunk_remove(const int x, const int y, const int z); Ref<TerraChunk> chunk_remove(const int x, const int z);
Ref<TerraChunk> chunk_remove_index(const int index); Ref<TerraChunk> chunk_remove_index(const int index);
Ref<TerraChunk> chunk_get_index(const int index); Ref<TerraChunk> chunk_get_index(const int index);
@ -144,8 +144,8 @@ public:
void chunks_clear(); void chunks_clear();
Ref<TerraChunk> chunk_get_or_create(const int x, const int y, const int z); Ref<TerraChunk> chunk_get_or_create(const int x, const int z);
Ref<TerraChunk> chunk_create(const int x, const int y, const int z); Ref<TerraChunk> chunk_create(const int x, const int z);
void chunk_setup(Ref<TerraChunk> chunk); void chunk_setup(Ref<TerraChunk> chunk);
void chunk_generate(Ref<TerraChunk> chunk); void chunk_generate(Ref<TerraChunk> chunk);
@ -196,7 +196,7 @@ public:
protected: protected:
virtual void _generate_chunk(Ref<TerraChunk> chunk); virtual void _generate_chunk(Ref<TerraChunk> chunk);
virtual Ref<TerraChunk> _create_chunk(int x, int y, int z, Ref<TerraChunk> p_chunk); virtual Ref<TerraChunk> _create_chunk(int x, int z, Ref<TerraChunk> p_chunk);
virtual int _get_channel_index_info(const ChannelTypeInfo channel_type); virtual int _get_channel_index_info(const ChannelTypeInfo channel_type);
virtual void _set_voxel_with_tool(const bool mode_add, const Vector3 hit_position, const Vector3 hit_normal, const int selected_voxel, const int isolevel); virtual void _set_voxel_with_tool(const bool mode_add, const Vector3 hit_position, const Vector3 hit_normal, const int selected_voxel, const int isolevel);
@ -211,20 +211,17 @@ public:
IntPos() { IntPos() {
x = 0; x = 0;
y = 0;
z = 0; z = 0;
} }
IntPos(int p_x, int p_y, int p_z) { IntPos(int p_x, int p_z) {
x = p_x; x = p_x;
y = p_y;
z = p_z; z = p_z;
} }
IntPos(const Vector3 &p) { IntPos(const Vector2 &p) {
x = p.x; x = p.x;
y = p.y; z = p.y;
z = p.z;
} }
}; };
@ -242,11 +239,11 @@ private:
bool _is_priority_generation; bool _is_priority_generation;
int _chunk_size_x; int _chunk_size_x;
int _chunk_size_y;
int _chunk_size_z; int _chunk_size_z;
int _current_seed; int _current_seed;
int _data_margin_start; int _data_margin_start;
int _data_margin_end; int _data_margin_end;
float _world_height;
Ref<TerramanLibrary> _library; Ref<TerramanLibrary> _library;
Ref<TerramanLevelGenerator> _level_generator; Ref<TerramanLevelGenerator> _level_generator;
@ -274,7 +271,7 @@ private:
}; };
_FORCE_INLINE_ bool operator==(const TerraWorld::IntPos &a, const TerraWorld::IntPos &b) { _FORCE_INLINE_ bool operator==(const TerraWorld::IntPos &a, const TerraWorld::IntPos &b) {
return a.x == b.x && a.y == b.y && a.z == b.z; return a.x == b.x && a.z == b.z;
} }
VARIANT_ENUM_CAST(TerraWorld::ChannelTypeInfo); VARIANT_ENUM_CAST(TerraWorld::ChannelTypeInfo);