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 SoftBody3D pinned points interaction #94684

Merged
merged 1 commit into from
Sep 16, 2024

Conversation

Musicgun47
Copy link
Contributor

There are a few issues related to modifying pinned points of the SoftBody3D node which this PR addresses.

The first was that the handles in the 3D viewport were not clickable, meaning selecting pinned points was not possible. This was caused by changes made in this PR which was aimed at reducing console spam from gizmo updates by checking mouse position had changed before committing changes. This has been reverted specifically for the mouse button up event to re-enable clicking of pinned point handles in the 3D viewport without the need for the mouse position to have changed. I have also added an update_gizmos() call to ensure changes to pinned points are displayed immediately as they were not getting updated until the mouse overlapped another handle. As far as I can tell this change hasn't brought back the console spam fixed in the mentioned PR.

Secondly, modifying pinned points directly via the inspector caused points to be dropped from the list. This was caused by the way values were set in the _set_property_pinned_points_indices() function. If a value was changed further up the list, the original value of the pinned point was removed from the list and the new value was added. However, if the modified value was not at the start of the list, this caused a copy to be created and a cascade of remove/add calls as the pointer *w still points to the original list. The result was that the last value of the list was never re-added as it would always match. This has been fixed by ensuring that entries are only removed from the list if the specified index is no longer present in the updated list, and ensuring that the updated index is added at the same point it was removed from (as _add_pinned_point() always added a new point to the end of the list resulting in unwanted reordering of the list). There is still an issue where if an index is incremented from a single value to a repeated value, the duplicate is removed, however I think that this is acceptable given duplicate vertices shouldn't be present in the pinned point array. With the previous fix, this functionality is not as necessary (given most users would set pinned points in the viewport), however it is important that it functions as intended if any improvements are to be made to the UI which may leverage calls to this function.

Fixes #93847

@Musicgun47 Musicgun47 requested review from a team as code owners July 24, 2024 04:30
@Chaosus Chaosus added this to the 4.3 milestone Jul 24, 2024
@Chaosus
Copy link
Member

Chaosus commented Jul 24, 2024

Thanks for your contribution. Please squash the commits as required by our pipeline (see docs.godotengine.org/en/latest/contributing/workflow/pr_workflow.html).

@Musicgun47 Musicgun47 force-pushed the soft-body-overhaul-ui branch from 4801bb5 to 1a460dd Compare July 24, 2024 04:40
@Musicgun47
Copy link
Contributor Author

Yeah, no worries. I wasn't sure if I would need to or not.

@Musicgun47 Musicgun47 force-pushed the soft-body-overhaul-ui branch 2 times, most recently from 4d1c4fa to 4c246d2 Compare July 24, 2024 06:01
@AThousandShips
Copy link
Member

Please fix the documentation by running --doctool on the compiled code, you will also need to fix compatibility, see here

@Musicgun47 Musicgun47 force-pushed the soft-body-overhaul-ui branch from 4c246d2 to f0d8da1 Compare July 25, 2024 07:13
@Musicgun47 Musicgun47 requested review from a team as code owners July 25, 2024 07:13
@Musicgun47
Copy link
Contributor Author

Okay, I think I've fixed everything, but let me know if I haven't. Reading the documentation and actually implementing it are two very different things, so happy for any pointers.

@Musicgun47 Musicgun47 force-pushed the soft-body-overhaul-ui branch from f0d8da1 to 397ff14 Compare July 25, 2024 07:40
Copy link
Member

@AThousandShips AThousandShips left a comment

Choose a reason for hiding this comment

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

Looks good code wise otherwise, but not my area so can't speak for functionality

scene/3d/soft_body_3d.cpp Outdated Show resolved Hide resolved
scene/3d/soft_body_3d.cpp Outdated Show resolved Hide resolved
misc/extension_api_validation/4.2-stable.expected Outdated Show resolved Hide resolved
misc/extension_api_validation/4.2-stable.expected Outdated Show resolved Hide resolved
scene/3d/soft_body_3d.compat.inc Outdated Show resolved Hide resolved
@Musicgun47 Musicgun47 force-pushed the soft-body-overhaul-ui branch from 397ff14 to 0e3b2ab Compare July 25, 2024 13:47
@Musicgun47 Musicgun47 force-pushed the soft-body-overhaul-ui branch from 0e3b2ab to 71a063a Compare July 25, 2024 13:50
Copy link
Member

@AThousandShips AThousandShips left a comment

Choose a reason for hiding this comment

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

Approving on code fundamentals, still need a team review for the functionality as this isn't my area

@Musicgun47
Copy link
Contributor Author

No worries, thanks for the help.

@akien-mga akien-mga modified the milestones: 4.3, 4.4 Jul 26, 2024
@akien-mga akien-mga added the cherrypick:4.3 Considered for cherry-picking into a future 4.3.x release label Jul 26, 2024
@akien-mga akien-mga removed request for a team August 19, 2024 12:56
@akien-mga akien-mga requested a review from a team August 19, 2024 12:56
@Musicgun47 Musicgun47 force-pushed the soft-body-overhaul-ui branch 4 times, most recently from bb8cbc5 to de538f2 Compare September 2, 2024 05:47
@@ -668,10 +675,10 @@ void SoftBody3D::pin_point_toggle(int p_point_index) {
pin_point(p_point_index, !(-1 != _has_pinned_point(p_point_index)));
}

void SoftBody3D::pin_point(int p_point_index, bool pin, const NodePath &p_spatial_attachment_path) {
void SoftBody3D::pin_point(int p_point_index, bool pin, const NodePath &p_spatial_attachment_path, int p_insert_at) {
Copy link
Member

Choose a reason for hiding this comment

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

This should validate that the p_insert_at range is valid, i.e. >= -1 and < pinned_points.size(). Otherwise this will lead to hard-to-understand errors surfaced in CowData if users pass invalid values.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I did think that would be the case, but I was unsure how CowData handled that so I was waiting for confirmation. It should be fixed now. Validation is done in the _add_pinned_point() method at line 753. Values out of bounds are simply added to the end of the list.

Copy link
Member

Choose a reason for hiding this comment

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

My idea was more to abort and notify the user that they used the API illegally, with:

ERR_FAIL_COND_MSG(p_insert_at < -1 || p_insert_at >= pinned_points.size(), "Invalid index for pin point insertion position.");

at the top of this method (which is the end-user facing one).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah yes, that makes more sense; I'll do that instead. I keep forgetting that's a user facing method.

@Musicgun47 Musicgun47 force-pushed the soft-body-overhaul-ui branch from 406db1c to e2a6320 Compare September 16, 2024 11:19
Fix erratic behaviour when modifying pinned_points via inspector
@Musicgun47 Musicgun47 force-pushed the soft-body-overhaul-ui branch from e2a6320 to a58ae8e Compare September 16, 2024 12:01
@akien-mga akien-mga merged commit 6311dd2 into godotengine:master Sep 16, 2024
20 checks passed
@akien-mga
Copy link
Member

Thanks! And congrats for your first merged Godot contribution 🎉

@akien-mga akien-mga removed the cherrypick:4.3 Considered for cherry-picking into a future 4.3.x release label Sep 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Modifying Pinned Points of SoftBody3D is broken
4 participants