-
-
Notifications
You must be signed in to change notification settings - Fork 21.3k
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
Fix SoftBody3D
pinned points interaction
#94684
Conversation
Thanks for your contribution. Please squash the commits as required by our pipeline (see docs.godotengine.org/en/latest/contributing/workflow/pr_workflow.html). |
4801bb5
to
1a460dd
Compare
Yeah, no worries. I wasn't sure if I would need to or not. |
4d1c4fa
to
4c246d2
Compare
Please fix the documentation by running |
4c246d2
to
f0d8da1
Compare
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. |
f0d8da1
to
397ff14
Compare
There was a problem hiding this 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
397ff14
to
0e3b2ab
Compare
0e3b2ab
to
71a063a
Compare
There was a problem hiding this 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
No worries, thanks for the help. |
bb8cbc5
to
de538f2
Compare
de538f2
to
e665b54
Compare
e665b54
to
406db1c
Compare
@@ -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) { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
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.
406db1c
to
e2a6320
Compare
Fix erratic behaviour when modifying pinned_points via inspector
e2a6320
to
a58ae8e
Compare
Thanks! And congrats for your first merged Godot contribution 🎉 |
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