Increase float precision in the inspector for Quaternions

This commit is contained in:
Aaron Franke 2025-05-13 06:12:14 -07:00
parent 0304036bed
commit d9c3c87eaa
No known key found for this signature in database
GPG key ID: 40A1750B977E56BF
3 changed files with 24 additions and 3 deletions

View file

@ -128,7 +128,10 @@ void EditorSpinSlider::gui_input(const Ref<InputEvent> &p_event) {
pre_grab_value = get_max();
}
double new_value = pre_grab_value + get_step() * grabbing_spinner_dist_cache;
// Prevent dragging properties with very precise steps from being agonizingly slow.
const double default_float_step = EDITOR_GET("interface/inspector/default_float_step");
const double drag_step = MAX(get_step(), default_float_step);
const double new_value = pre_grab_value + drag_step * grabbing_spinner_dist_cache;
set_value((mm->is_command_or_control_pressed() && !editing_integer) ? Math::round(new_value) : new_value);
}
} else if (updown_offset != -1) {

View file

@ -4029,7 +4029,14 @@ EditorProperty *EditorInspectorDefaultPlugin::get_editor_for_property(Object *p_
} break;
case Variant::QUATERNION: {
EditorPropertyQuaternion *editor = memnew(EditorPropertyQuaternion);
editor->setup(_parse_range_hint(p_hint, p_hint_text, default_float_step), p_hint == PROPERTY_HINT_HIDE_QUATERNION_EDIT);
// Quaternions are almost never used for human-readable values that need stepifying,
// so we should be more precise with their step, as much as the float precision allows.
#ifdef REAL_T_IS_DOUBLE
constexpr double QUATERNION_STEP = 1e-14;
#else
constexpr double QUATERNION_STEP = 1e-6;
#endif
editor->setup(_parse_range_hint(p_hint, p_hint_text, QUATERNION_STEP), p_hint == PROPERTY_HINT_HIDE_QUATERNION_EDIT);
return editor;
} break;
case Variant::AABB: {

View file

@ -78,7 +78,18 @@ void BonePropertiesEditor::create_editors() {
// Rotation property.
rotation_property = memnew(EditorPropertyQuaternion());
rotation_property->setup(large_range_hint);
// Quaternions are almost never used for human-readable values that need stepifying,
// so we should be more precise with their step, as much as the float precision allows.
#ifdef REAL_T_IS_DOUBLE
constexpr double QUATERNION_STEP = 1e-14;
#else
constexpr double QUATERNION_STEP = 1e-6;
#endif
EditorPropertyRangeHint quaternion_range_hint;
quaternion_range_hint.min = -1.0;
quaternion_range_hint.max = 1.0;
quaternion_range_hint.step = QUATERNION_STEP;
rotation_property->setup(quaternion_range_hint);
rotation_property->set_label("Rotation");
rotation_property->set_selectable(false);
rotation_property->connect("property_changed", callable_mp(this, &BonePropertiesEditor::_value_changed));