Skip to content

Commit

Permalink
Fix #238 - Disabling Automatic regions now stops making them
Browse files Browse the repository at this point in the history
  • Loading branch information
TokisanGames committed Nov 4, 2023
1 parent 1c9b249 commit f9fa097
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions src/terrain_3d_editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,18 +60,23 @@ void Terrain3DEditor::_operate_map(Vector3 p_global_position, real_t p_camera_di
Ref<Terrain3DStorage> storage = _terrain->get_storage();
int region_size = storage->get_region_size();
Vector2i region_vsize = Vector2i(region_size, region_size);
int region_index = storage->get_region_index(p_global_position);

int region_index = storage->get_region_index(p_global_position);
if (region_index == -1) {
LOG(DEBUG, "No region to operate on, attempting to add");
storage->add_region(p_global_position);
region_size = storage->get_region_size();
region_index = storage->get_region_index(p_global_position);
if (region_index == -1) {
LOG(ERROR, "Failed to add region, no region to operate on");
if (!_brush.auto_regions_enabled()) {
return;
} else {
LOG(DEBUG, "No region to operate on, attempting to add");
storage->add_region(p_global_position);
region_size = storage->get_region_size();
region_index = storage->get_region_index(p_global_position);
if (region_index == -1) {
LOG(ERROR, "Failed to add region, no region to operate on");
return;
}
}
} else if (_tool < 0 || _tool >= REGION) {
}
if (_tool < 0 || _tool >= REGION) {
LOG(ERROR, "Invalid tool selected");
return;
}
Expand Down Expand Up @@ -122,8 +127,8 @@ void Terrain3DEditor::_operate_map(Vector3 p_global_position, real_t p_camera_di
Vector2i brush_offset = Vector2i(x, y) - (Vector2i(brush_size, brush_size) / 2);
Vector3 brush_global_position = Vector3(p_global_position.x + real_t(brush_offset.x), p_global_position.y, p_global_position.z + real_t(brush_offset.y));

// If we're brushing across a region boundary, possibly add a region, and get the other map
int new_region_index = storage->get_region_index(brush_global_position);

if (new_region_index == -1) {
if (!_brush.auto_regions_enabled()) {
continue;
Expand All @@ -140,6 +145,7 @@ void Terrain3DEditor::_operate_map(Vector3 p_global_position, real_t p_camera_di
map = storage->get_map_region(map_type, region_index);
}

// Identify position on map image
Vector2 uv_position = _get_uv_position(brush_global_position, region_size);
Vector2i map_pixel_position = Vector2i(uv_position * region_size);

Expand All @@ -151,6 +157,7 @@ void Terrain3DEditor::_operate_map(Vector3 p_global_position, real_t p_camera_di
continue;
}

// Start brushing on the map
real_t brush_alpha = real_t(Math::pow(double(_brush.get_alpha(brush_pixel_position)), double(gamma)));
Color src = map->get_pixelv(map_pixel_position);
Color dest = src;
Expand Down

0 comments on commit f9fa097

Please sign in to comment.