Skip to content

Commit

Permalink
Fix update_transforms on non-height tool, using wrong asset offset
Browse files Browse the repository at this point in the history
  • Loading branch information
TokisanGames committed Dec 30, 2024
1 parent e81483a commit 0d730e3
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 9 deletions.
5 changes: 0 additions & 5 deletions src/terrain_3d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,6 @@ void Terrain3D::_initialize() {
LOG(DEBUG, "Connecting _data::height_maps_changed signal to update_aabbs()");
_data->connect("height_maps_changed", callable_mp(this, &Terrain3D::update_aabbs));
}
// Connect height changes to update instances
if (!_data->is_connected("maps_edited", callable_mp(_instancer, &Terrain3DInstancer::update_transforms))) {
LOG(DEBUG, "Connecting maps_edited signal to update_transforms()");
_data->connect("maps_edited", callable_mp(_instancer, &Terrain3DInstancer::update_transforms));
}
// Texture assets changed, update material
if (!_assets->is_connected("textures_changed", callable_mp(_material.ptr(), &Terrain3DMaterial::_update_texture_arrays))) {
LOG(DEBUG, "Connecting _assets.textures_changed to _material->_update_texture_arrays()");
Expand Down
6 changes: 5 additions & 1 deletion src/terrain_3d_editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ void Terrain3DEditor::_operate_map(const Vector3 &p_global_position, const real_
if (map_type == TYPE_HEIGHT) {
real_t srcf = src.r;
// In case data in existing map has nan or inf saved, check, and reset to real number if required.
srcf = std::isnan(srcf) || std::isnan(srcf) ? 0.f : srcf;
srcf = std::isnan(srcf) || std::isnan(srcf) ? 0.f : srcf;
real_t destf = srcf;

switch (_operation) {
Expand Down Expand Up @@ -522,6 +522,10 @@ void Terrain3DEditor::_operate_map(const Vector3 &p_global_position, const real_
data->force_update_maps(map_type);
}
data->add_edited_area(edited_area);

if (_tool == HOLES || _tool == HEIGHT || _tool == SCULPT) {
_terrain->get_instancer()->update_transforms(edited_area);
}
}

void Terrain3DEditor::_store_undo() {
Expand Down
5 changes: 2 additions & 3 deletions src/terrain_3d_instancer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -760,8 +760,7 @@ void Terrain3DInstancer::update_transforms(const AABB &p_aabb) {
int region_size = _terrain->get_region_size();
real_t vertex_spacing = _terrain->get_vertex_spacing();

// Build list of potential regions to search, rather than searching the entire terrain, calculate possible regions covered
// and check if they are valid; if so add that location to the dictionary keys.
// Build list of valid regions within AABB; add the locations as dictionary keys.
Dictionary r_locs;
// Calculate step distance to ensure every region is checked inside the bounds of brush size.
Vector2 step = Vector2(size.x / ceil(size.x / real_t(region_size) / vertex_spacing), size.y / ceil(size.y / real_t(region_size) / vertex_spacing));
Expand Down Expand Up @@ -821,7 +820,7 @@ void Terrain3DInstancer::update_transforms(const AABB &p_aabb) {
if (cell_queue.size() == 0) {
continue;
}
Ref<Terrain3DMeshAsset> mesh_asset = _terrain->get_assets()->get_mesh_asset(m);
Ref<Terrain3DMeshAsset> mesh_asset = _terrain->get_assets()->get_mesh_asset(mesh_types[m]);
real_t mesh_height_offset = mesh_asset->get_height_offset();
for (int c = 0; c < cell_queue.size(); c++) {
Vector2i cell = cell_queue[c];
Expand Down

0 comments on commit 0d730e3

Please sign in to comment.