Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix update_transforms issues #585

Merged
merged 2 commits into from
Dec 31, 2024
Merged

Fix update_transforms issues #585

merged 2 commits into from
Dec 31, 2024

Conversation

TokisanGames
Copy link
Owner

@TokisanGames TokisanGames commented Dec 28, 2024

Fixes #584
Fixes #544

Issues addressed:

  • Undo not reapplying manual offset when undoing (due to update_transforms being called on the undo)
  • Update_transforms called on non-sculpting brushes
  • Update_transforms affecting whole cell instead of only aabb
  • update_transforms uses wrong/old height offset after swaping IDs
  • Mesh assets not retaining height offset setting and other settings across restarts of the engine

Not done:

  • Retaining manually painted height offset - possible future update

@TokisanGames TokisanGames added the bug Something isn't working label Dec 28, 2024
@TokisanGames TokisanGames marked this pull request as draft December 28, 2024 14:28
@TokisanGames TokisanGames changed the title Fix update_transforms running on non-height tool WIP: Fix update_transforms running on non-height tool Dec 28, 2024
@TokisanGames TokisanGames changed the title WIP: Fix update_transforms running on non-height tool WIP: Update_transforms issues Dec 30, 2024
@TokisanGames TokisanGames changed the title WIP: Update_transforms issues Only calls update_transforms when sculpting or holes Dec 30, 2024
@TokisanGames TokisanGames marked this pull request as ready for review December 30, 2024 10:48
@TokisanGames TokisanGames force-pushed the fix-update-transforms branch 2 times, most recently from 04f211e to a0941d4 Compare December 30, 2024 11:02
@TokisanGames
Copy link
Owner Author

#584 is collecting a lot of issues, so I'm limiting this PR to one at a time.

@Xtarsia Would you review this please?

Copy link
Contributor

@Xtarsia Xtarsia left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As per my comments, I think line 805 in data.cpp is the main culprit.

src/terrain_3d_data.cpp Outdated Show resolved Hide resolved
src/terrain_3d_editor.cpp Show resolved Hide resolved
src/terrain_3d_instancer.cpp Outdated Show resolved Hide resolved
@Xtarsia
Copy link
Contributor

Xtarsia commented Dec 30, 2024

the smaller AABB is actually usuable for much more constrained updates too, at line 833~ modify to:

				for (int i = 0; i < xforms.size(); i++) {
					Transform3D t = xforms[i];
					if (brush_rect.has_point(Point2(t.origin.x + global_local_offset.x, t.origin.z + global_local_offset.z))) {
						Vector3 height_offset = t.basis.get_column(1) * mesh_height_offset;
						t.origin -= height_offset;
						real_t height = _terrain->get_data()->get_height(t.origin + global_local_offset);
						// If the new height is a nan due to creating a hole, remove the instance
						if (std::isnan(height)) {
							continue;
						}
						t.origin.y = height;
						t.origin += height_offset;
						updated_xforms.push_back(t);
						updated_colors.push_back(colors[i]);
					} else {
						updated_xforms.push_back(t);
						updated_colors.push_back(colors[i]);
					}
				}

which prevents modifying the entire cell at once (tho the whole cell will still be itterated over)

@TokisanGames
Copy link
Owner Author

TokisanGames commented Dec 30, 2024

Those changes are in. So far this PR addresses:

  • undo issues (due to update_transforms being called on the undo)
  • update called only on sculpting brushes
  • update only affecting aabb instead of whole cell

Outstanding:

  • update_transforms uses wrong/old height offset after swaping IDs (bug)
  • As for retaining height offsets, Terrain3DObjects stores the current height offset for each object. 🤔 (feature, won't hold up)

@Xtarsia
Copy link
Contributor

Xtarsia commented Dec 30, 2024

As for retaining height offsets, Terrain3DObjects stores the current height offset for each object. 🤔

could increase the triple to a quadruple and store the (tool height) offset as a PackedFloat32Array perhaps.

and/or;

Very out of scope for this PR, I think an extra foliage transform tool might be a better way to go, a brush with expand/shrink (to modify scale of existing xforms) and raise / lower. A foliage color tool could be nice as well.

@TokisanGames TokisanGames changed the title Only calls update_transforms when sculpting or holes Fix update_transforms issues Dec 30, 2024
@TokisanGames
Copy link
Owner Author

@Xtarsia Thanks for your help. Improvement ideas added to #43

@TokisanGames TokisanGames merged commit 7ea2191 into main Dec 31, 2024
15 checks passed
@TokisanGames TokisanGames deleted the fix-update-transforms branch December 31, 2024 03:38
@TokisanGames
Copy link
Owner Author

TokisanGames commented Dec 31, 2024

Some how I dropped the limit update to brush size rather than whole cell. Fortunately I found it in my reflog. Added in 5ab6742

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Tracker] Update_transforms issues Mesh instancer default height can reference incorrect asset values.
2 participants