Skip to content

Commit 59b5d73

Browse files
committed
Increase float precision in the inspector for Quaternions
1 parent 7cb13a3 commit 59b5d73

3 files changed

Lines changed: 24 additions & 3 deletions

File tree

editor/gui/editor_spin_slider.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,10 @@ void EditorSpinSlider::gui_input(const Ref<InputEvent> &p_event) {
128128
pre_grab_value = get_max();
129129
}
130130

131-
double new_value = pre_grab_value + get_step() * grabbing_spinner_dist_cache;
131+
// Prevent dragging properties with very precise steps from being agonizingly slow.
132+
const double default_float_step = EDITOR_GET("interface/inspector/default_float_step");
133+
const double drag_step = MAX(get_step(), default_float_step);
134+
const double new_value = pre_grab_value + drag_step * grabbing_spinner_dist_cache;
132135
set_value((mm->is_command_or_control_pressed() && !editing_integer) ? Math::round(new_value) : new_value);
133136
}
134137
} else if (updown_offset != -1) {

editor/inspector/editor_properties.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4029,7 +4029,14 @@ EditorProperty *EditorInspectorDefaultPlugin::get_editor_for_property(Object *p_
40294029
} break;
40304030
case Variant::QUATERNION: {
40314031
EditorPropertyQuaternion *editor = memnew(EditorPropertyQuaternion);
4032-
editor->setup(_parse_range_hint(p_hint, p_hint_text, default_float_step), p_hint == PROPERTY_HINT_HIDE_QUATERNION_EDIT);
4032+
// Quaternions are almost never used for human-readable values that need stepifying,
4033+
// so we should be more precise with their step, as much as the float precision allows.
4034+
#ifdef REAL_T_IS_DOUBLE
4035+
constexpr double QUATERNION_STEP = 1e-14;
4036+
#else
4037+
constexpr double QUATERNION_STEP = 1e-6;
4038+
#endif
4039+
editor->setup(_parse_range_hint(p_hint, p_hint_text, QUATERNION_STEP), p_hint == PROPERTY_HINT_HIDE_QUATERNION_EDIT);
40334040
return editor;
40344041
} break;
40354042
case Variant::AABB: {

editor/scene/3d/skeleton_3d_editor_plugin.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,18 @@ void BonePropertiesEditor::create_editors() {
7878

7979
// Rotation property.
8080
rotation_property = memnew(EditorPropertyQuaternion());
81-
rotation_property->setup(large_range_hint);
81+
// Quaternions are almost never used for human-readable values that need stepifying,
82+
// so we should be more precise with their step, as much as the float precision allows.
83+
#ifdef REAL_T_IS_DOUBLE
84+
constexpr double QUATERNION_STEP = 1e-14;
85+
#else
86+
constexpr double QUATERNION_STEP = 1e-6;
87+
#endif
88+
EditorPropertyRangeHint quaternion_range_hint;
89+
quaternion_range_hint.min = -1.0;
90+
quaternion_range_hint.max = 1.0;
91+
quaternion_range_hint.step = QUATERNION_STEP;
92+
rotation_property->setup(quaternion_range_hint);
8293
rotation_property->set_label("Rotation");
8394
rotation_property->set_selectable(false);
8495
rotation_property->connect("property_changed", callable_mp(this, &BonePropertiesEditor::_value_changed));

0 commit comments

Comments
 (0)