mirror of
https://github.com/Relintai/terraman_2d.git
synced 2024-11-12 10:15:18 +01:00
Removed always add colors property from the blocky mesher, as 2d always need colors. Also add white if lighting is off. Also cleanups and smaller fixes to the mesh generation algorithm.
This commit is contained in:
parent
aa85599ec4
commit
ee92bd7491
@ -26,13 +26,6 @@ SOFTWARE.
|
||||
|
||||
#include "../../library/terrain_2d_material_cache.h"
|
||||
|
||||
bool Terrain2DMesherBlocky::get_always_add_colors() const {
|
||||
return _always_add_colors;
|
||||
}
|
||||
void Terrain2DMesherBlocky::set_always_add_colors(const bool value) {
|
||||
_always_add_colors = value;
|
||||
}
|
||||
|
||||
void Terrain2DMesherBlocky::_add_chunk(Ref<Terrain2DChunk> p_chunk) {
|
||||
Ref<Terrain2DChunkDefault> chunk = p_chunk;
|
||||
|
||||
@ -94,8 +87,8 @@ void Terrain2DMesherBlocky::add_chunk_normal(Ref<Terrain2DChunkDefault> chunk) {
|
||||
for (int y = margin_start; y < y_size + margin_start; ++y) {
|
||||
for (int x = margin_start; x < x_size + margin_start; ++x) {
|
||||
int indexes[4] = {
|
||||
chunk->get_data_index(x + 1, y),
|
||||
chunk->get_data_index(x, y),
|
||||
chunk->get_data_index(x + 1, y),
|
||||
chunk->get_data_index(x, y + 1),
|
||||
chunk->get_data_index(x + 1, y + 1)
|
||||
};
|
||||
@ -146,35 +139,38 @@ void Terrain2DMesherBlocky::add_chunk_normal(Ref<Terrain2DChunkDefault> chunk) {
|
||||
}
|
||||
|
||||
int vc = get_vertex_count();
|
||||
add_indices(vc + 0);
|
||||
add_indices(vc + 1);
|
||||
add_indices(vc + 2);
|
||||
add_indices(vc + 1);
|
||||
add_indices(vc + 0);
|
||||
add_indices(vc + 3);
|
||||
add_indices(vc + 2);
|
||||
add_indices(vc + 0);
|
||||
add_indices(vc + 3);
|
||||
|
||||
Vector2 uvs[] = {
|
||||
surface->transform_uv(Vector2(1, 0)),
|
||||
surface->transform_uv(Vector2(0, 0)),
|
||||
surface->transform_uv(Vector2(1, 0)),
|
||||
surface->transform_uv(Vector2(0, 1)),
|
||||
surface->transform_uv(Vector2(1, 1))
|
||||
};
|
||||
|
||||
int xx = (x + 1) * cell_size_x;
|
||||
int xx1 = x * cell_size_x;
|
||||
int xx = x * cell_size_x;
|
||||
int xx1 = (x + 1) * cell_size_x;
|
||||
int yy = y * cell_size_y;
|
||||
int yy1 = (y + 1) * cell_size_y;
|
||||
|
||||
Vector2 verts[] = {
|
||||
Vector2(xx1, yy),
|
||||
Vector2(xx, yy),
|
||||
Vector2(xx1, yy),
|
||||
Vector2(xx, yy1),
|
||||
Vector2(xx1, yy1)
|
||||
};
|
||||
|
||||
for (int i = 0; i < 4; ++i) {
|
||||
if (use_lighting || _always_add_colors)
|
||||
if (use_lighting) {
|
||||
add_color(light[i]);
|
||||
} else {
|
||||
add_color(Color(1, 1, 1, 1));
|
||||
}
|
||||
|
||||
add_uv(uvs[i]);
|
||||
add_vertex(verts[i]);
|
||||
@ -184,7 +180,6 @@ void Terrain2DMesherBlocky::add_chunk_normal(Ref<Terrain2DChunkDefault> chunk) {
|
||||
}
|
||||
|
||||
Terrain2DMesherBlocky::Terrain2DMesherBlocky() {
|
||||
_always_add_colors = false;
|
||||
}
|
||||
|
||||
Terrain2DMesherBlocky::~Terrain2DMesherBlocky() {
|
||||
@ -192,8 +187,4 @@ Terrain2DMesherBlocky::~Terrain2DMesherBlocky() {
|
||||
|
||||
void Terrain2DMesherBlocky::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("_add_chunk", "buffer"), &Terrain2DMesherBlocky::_add_chunk);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_always_add_colors"), &Terrain2DMesherBlocky::get_always_add_colors);
|
||||
ClassDB::bind_method(D_METHOD("set_always_add_colors", "value"), &Terrain2DMesherBlocky::set_always_add_colors);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::INT, "always_add_colors"), "set_always_add_colors", "get_always_add_colors");
|
||||
}
|
||||
|
@ -41,9 +41,6 @@ class Terrain2DMesherBlocky : public Terrain2DMesherDefault {
|
||||
GDCLASS(Terrain2DMesherBlocky, Terrain2DMesherDefault);
|
||||
|
||||
public:
|
||||
bool get_always_add_colors() const;
|
||||
void set_always_add_colors(const bool value);
|
||||
|
||||
void _add_chunk(Ref<Terrain2DChunk> p_chunk);
|
||||
|
||||
void add_chunk_normal(Ref<Terrain2DChunkDefault> chunk);
|
||||
@ -53,9 +50,6 @@ public:
|
||||
|
||||
protected:
|
||||
static void _bind_methods();
|
||||
|
||||
private:
|
||||
bool _always_add_colors;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user