Fix some Node3DEditor
snapping issues
#84049
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #79862.
There was a discrepancy between what's saved in the plugin's state and where it gets loaded to:
godot/editor/plugins/node_3d_editor_plugin.cpp
Lines 5860 to 5862 in dd74ffd
godot/editor/plugins/node_3d_editor_plugin.cpp
Lines 5940 to 5950 in dd74ffd
All
get_translate_snap
/get_rotate_snap
/get_scale_snap
were reading the values from the snap dialog's LineEdits instead of using plugin'ssnap_translate_value
/snap_rotate_value
/snap_scale_value
(which are being updated according to these LineEdits on pressing OK / confirming in the snap dialog). Also what's worse (given these were the values being saved), these methods return smaller snap values when Shift is being pressed.godot/editor/plugins/node_3d_editor_plugin.cpp
Lines 8889 to 8920 in dd74ffd
Meaning if Shift was pressed when plugin's state was being saved then values smaller than the actual snap values were being saved into a file. Then when loading they'd be loaded as the actual snap values. Everytime this happened the snap values were becoming smaller and smaller.
For reproducing #79862 it was enough for me to create two 3D scenes and keep switching between them (by pressing their tabs) while keeping Shift pressed.
This PR makes
get_translate_snap
/get_rotate_snap
/get_scale_snap
properly usesnap_translate_value
/snap_rotate_value
/snap_scale_value
, and makessnap_translate_value
/snap_rotate_value
/snap_scale_value
be what's saved in the plugin's state.Since
get_translate_snap
/get_rotate_snap
/get_scale_snap
no longer read values from LineEdits they were changed to returnreal_t
instead ofdouble
, as that's the type ofsnap_translate_value
/snap_rotate_value
/snap_scale_value
. See #49783 (comment) for why they were returning doubles before.If we'd want snapping to always operate on doubles then what would need to be changed are
snap_translate_value
/snap_rotate_value
/snap_scale_value
. I could make such changes if that's desired.Fixes #39507.
godot/editor/plugins/node_3d_editor_plugin.cpp
Lines 4885 to 4886 in dd74ffd
Math::fmod
would return NaN forsnap == 0.0
. Besides, this calculation doesn't correctly snap for negative angles anyway.Fixed it to use
Math::snapped
which handles these cases properly.