Skip to content

Add snap option to gizmos (Ctrl+drag)#994

Merged
MrNeRF merged 2 commits into
MrNeRF:masterfrom
ToRainu256:feature/gizmo-snap
Mar 16, 2026
Merged

Add snap option to gizmos (Ctrl+drag)#994
MrNeRF merged 2 commits into
MrNeRF:masterfrom
ToRainu256:feature/gizmo-snap

Conversation

@ToRainu256
Copy link
Copy Markdown
Contributor

Summary

  • Add grid snapping to gizmo operations when holding Ctrl during drag
  • Rotation snaps to 5° increments, translation to 0.1 units, scale to 0.1 ratio
  • Without Ctrl, gizmo behavior is unchanged

Details

Introduces a computeSnapPtr() helper that returns snap values based on the active gizmo operation
when Ctrl is held, or nullptr otherwise. Applied to all three ImGuizmo::Manipulate call sites in
GizmoManager (node gizmo, standard gizmo, and the third gizmo path).

#746

Copy link
Copy Markdown
Owner

@MrNeRF MrNeRF left a comment

Choose a reason for hiding this comment

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

Thanks for this pr. I have added two comments which make it a bit more general.
Could be also 10 degrees? Wdyt?

Comment thread src/visualizer/gui/gizmo_manager.cpp Outdated
inline const float* computeSnapPtr(float* buf, ImGuizmo::OPERATION op) {
if (!ImGui::GetIO().KeyCtrl)
return nullptr;
if (op == ImGuizmo::ROTATE)
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

should be & instead == to match individual axes.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed. Now using bitmask comparison consistent with TRANSLATE/SCALE. 36d3ad2

Comment thread src/visualizer/gui/gizmo_manager.cpp Outdated
else if (op & ImGuizmo::TRANSLATE)
buf[0] = buf[1] = buf[2] = TRANSLATE_SNAP_UNITS;
else if (op & ImGuizmo::SCALE)
buf[0] = SCALE_SNAP_RATIO;
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

buf[0] = buf[1] = buf[2] = SCALE_SNAP_RATIO; // to snap all scale axes, no?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed. All three axes now receive the snap value. 36d3ad2

- ROTATE comparison changed from == to & for consistency with TRANSLATE/SCALE
- SCALE snap now fills all three axes instead of only buf[0]
@ToRainu256
Copy link
Copy Markdown
Contributor Author

Thanks for this pr. I have added two comments which make it a bit more general. Could be also 10 degrees? Wdyt?

Thanks for the review! I hardcoded 5° to match Blender's default. Ideally this would be
user-configurable in the UI, but that's a bigger change so I kept it simple for now. Happy to change
it to 10° if you prefer.

@MrNeRF
Copy link
Copy Markdown
Owner

MrNeRF commented Mar 16, 2026

Thanks for this pr. I have added two comments which make it a bit more general. Could be also 10 degrees? Wdyt?

Thanks for the review! I hardcoded 5° to match Blender's default. Ideally this would be user-configurable in the UI, but that's a bigger change so I kept it simple for now. Happy to change it to 10° if you prefer.

Thank you. Let's start with 5 degrees and let's see how it goes. Configuration can be added later, too!
Lgtm!

@MrNeRF MrNeRF merged commit 098ef77 into MrNeRF:master Mar 16, 2026
5 checks passed
@ToRainu256 ToRainu256 deleted the feature/gizmo-snap branch March 16, 2026 09:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants