Skip to content

Commit cdb6f12

Browse files
committed
Increase float precision in the inspector for Quaternions
1 parent 9b22b41 commit cdb6f12

File tree

3 files changed

+21
-5
lines changed

3 files changed

+21
-5
lines changed

editor/editor_properties.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3917,7 +3917,14 @@ EditorProperty *EditorInspectorDefaultPlugin::get_editor_for_property(Object *p_
39173917
} break;
39183918
case Variant::QUATERNION: {
39193919
EditorPropertyQuaternion *editor = memnew(EditorPropertyQuaternion);
3920-
EditorPropertyRangeHint hint = _parse_range_hint(p_hint, p_hint_text, default_float_step);
3920+
// Quaternions are almost never used for human-readable values that need stepifying,
3921+
// so we should be more precise with their step, as much as the float precision allows.
3922+
#ifdef REAL_T_IS_DOUBLE
3923+
constexpr double QUATERNION_STEP = 1e-14;
3924+
#else
3925+
constexpr double QUATERNION_STEP = 1e-6;
3926+
#endif
3927+
EditorPropertyRangeHint hint = _parse_range_hint(p_hint, p_hint_text, QUATERNION_STEP);
39213928
editor->setup(hint.min, hint.max, hint.step, hint.hide_slider, hint.suffix, p_hint == PROPERTY_HINT_HIDE_QUATERNION_EDIT);
39223929
return editor;
39233930
} break;

editor/gui/editor_spin_slider.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,16 +109,18 @@ void EditorSpinSlider::gui_input(const Ref<InputEvent> &p_event) {
109109
pre_grab_value = get_max();
110110
}
111111

112+
// Prevent dragging properties with very precise steps from being agonizingly slow.
113+
const double drag_step = MAX(get_step(), 0.001);
112114
if (mm->is_command_or_control_pressed()) {
113115
// If control was just pressed, don't make the value do a huge jump in magnitude.
114116
if (grabbing_spinner_dist_cache != 0) {
115-
pre_grab_value += grabbing_spinner_dist_cache * get_step();
117+
pre_grab_value += grabbing_spinner_dist_cache * drag_step;
116118
grabbing_spinner_dist_cache = 0;
117119
}
118120

119-
set_value(Math::round(pre_grab_value + get_step() * grabbing_spinner_dist_cache * 10));
121+
set_value(Math::round(pre_grab_value + drag_step * grabbing_spinner_dist_cache * 10));
120122
} else {
121-
set_value(pre_grab_value + get_step() * grabbing_spinner_dist_cache);
123+
set_value(pre_grab_value + drag_step * grabbing_spinner_dist_cache);
122124
}
123125
}
124126
} else if (updown_offset != -1) {

editor/plugins/skeleton_3d_editor_plugin.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,14 @@ void BonePropertiesEditor::create_editors() {
7373

7474
// Rotation property.
7575
rotation_property = memnew(EditorPropertyQuaternion());
76-
rotation_property->setup(-10000, 10000, 0.001, true);
76+
// Quaternions are almost never used for human-readable values that need stepifying,
77+
// so we should be more precise with their step, as much as the float precision allows.
78+
#ifdef REAL_T_IS_DOUBLE
79+
constexpr double QUATERNION_STEP = 1e-14;
80+
#else
81+
constexpr double QUATERNION_STEP = 1e-6;
82+
#endif
83+
rotation_property->setup(-10000, 10000, QUATERNION_STEP, true);
7784
rotation_property->set_label("Rotation");
7885
rotation_property->set_selectable(false);
7986
rotation_property->connect("property_changed", callable_mp(this, &BonePropertiesEditor::_value_changed));

0 commit comments

Comments
 (0)