From 54616a24fa8f0732c93ec68c586b69491697c4f7 Mon Sep 17 00:00:00 2001 From: Daniel Rakos Date: Tue, 29 Jan 2019 17:59:31 +0100 Subject: [PATCH] Fixed inspector precision issues when editing floats For some reason the editor limits the precision of all floating-point values, including vectors, matrices, etc. to 3 decimal places after the decimal point (as they all have a step of 0.001). This change gets rid of this artificial limitation at least for the basic types and uniforms. The implementation of step_decimals() is also changed to use log10 instead of a loop, and it will now correctly handle a step size of zero and return maxn while previously it incorrectly returned 0 in this case. Fixes #18251 (at least). --- core/math/math_funcs.cpp | 24 ++++-------------------- editor/editor_properties.cpp | 20 ++++++++++---------- servers/visual/shader_language.h | 2 +- 3 files changed, 15 insertions(+), 31 deletions(-) diff --git a/core/math/math_funcs.cpp b/core/math/math_funcs.cpp index 5b5fd8e28334..c4e13671105e 100644 --- a/core/math/math_funcs.cpp +++ b/core/math/math_funcs.cpp @@ -55,28 +55,12 @@ uint32_t Math::rand() { int Math::step_decimals(double p_step) { static const int maxn = 10; - static const double sd[maxn] = { - 0.9999, // somehow compensate for floating point error - 0.09999, - 0.009999, - 0.0009999, - 0.00009999, - 0.000009999, - 0.0000009999, - 0.00000009999, - 0.000000009999, - 0.0000000009999 - }; - double abs = Math::abs(p_step); - double decs = abs - (int)abs; // Strip away integer part - for (int i = 0; i < maxn; i++) { - if (decs >= sd[i]) { - return i; - } + if (p_step > 0) { + return MAX(MIN(-Math::floor(::log10(p_step)), maxn), 0); + } else { + return maxn; } - - return 0; } double Math::dectime(double p_value, double p_amount, double p_step) { diff --git a/editor/editor_properties.cpp b/editor/editor_properties.cpp index 56bab440c9f9..24b628884d3e 100644 --- a/editor/editor_properties.cpp +++ b/editor/editor_properties.cpp @@ -2885,7 +2885,7 @@ bool EditorInspectorDefaultPlugin::parse_property(Object *p_object, Variant::Typ } else { EditorPropertyFloat *editor = memnew(EditorPropertyFloat); - double min = -65535, max = 65535, step = 0.001; + double min = -65535, max = 65535, step = 0; bool hide_slider = true; bool exp_range = false; bool greater = true, lesser = true; @@ -2977,7 +2977,7 @@ bool EditorInspectorDefaultPlugin::parse_property(Object *p_object, Variant::Typ case Variant::VECTOR2: { EditorPropertyVector2 *editor = memnew(EditorPropertyVector2); - double min = -65535, max = 65535, step = 0.001; + double min = -65535, max = 65535, step = 0; bool hide_slider = true; if (p_hint == PROPERTY_HINT_RANGE && p_hint_text.get_slice_count(",") >= 2) { @@ -2995,7 +2995,7 @@ bool EditorInspectorDefaultPlugin::parse_property(Object *p_object, Variant::Typ } break; // 5 case Variant::RECT2: { EditorPropertyRect2 *editor = memnew(EditorPropertyRect2); - double min = -65535, max = 65535, step = 0.001; + double min = -65535, max = 65535, step = 0; bool hide_slider = true; if (p_hint == PROPERTY_HINT_RANGE && p_hint_text.get_slice_count(",") >= 2) { @@ -3012,7 +3012,7 @@ bool EditorInspectorDefaultPlugin::parse_property(Object *p_object, Variant::Typ } break; case Variant::VECTOR3: { EditorPropertyVector3 *editor = memnew(EditorPropertyVector3); - double min = -65535, max = 65535, step = 0.001; + double min = -65535, max = 65535, step = 0; bool hide_slider = true; if (p_hint == PROPERTY_HINT_RANGE && p_hint_text.get_slice_count(",") >= 2) { @@ -3030,7 +3030,7 @@ bool EditorInspectorDefaultPlugin::parse_property(Object *p_object, Variant::Typ } break; case Variant::TRANSFORM2D: { EditorPropertyTransform2D *editor = memnew(EditorPropertyTransform2D); - double min = -65535, max = 65535, step = 0.001; + double min = -65535, max = 65535, step = 0; bool hide_slider = true; if (p_hint == PROPERTY_HINT_RANGE && p_hint_text.get_slice_count(",") >= 2) { @@ -3048,7 +3048,7 @@ bool EditorInspectorDefaultPlugin::parse_property(Object *p_object, Variant::Typ } break; case Variant::PLANE: { EditorPropertyPlane *editor = memnew(EditorPropertyPlane); - double min = -65535, max = 65535, step = 0.001; + double min = -65535, max = 65535, step = 0; bool hide_slider = true; if (p_hint == PROPERTY_HINT_RANGE && p_hint_text.get_slice_count(",") >= 2) { @@ -3065,7 +3065,7 @@ bool EditorInspectorDefaultPlugin::parse_property(Object *p_object, Variant::Typ } break; case Variant::QUAT: { EditorPropertyQuat *editor = memnew(EditorPropertyQuat); - double min = -65535, max = 65535, step = 0.001; + double min = -65535, max = 65535, step = 0; bool hide_slider = true; if (p_hint == PROPERTY_HINT_RANGE && p_hint_text.get_slice_count(",") >= 2) { @@ -3082,7 +3082,7 @@ bool EditorInspectorDefaultPlugin::parse_property(Object *p_object, Variant::Typ } break; // 10 case Variant::AABB: { EditorPropertyAABB *editor = memnew(EditorPropertyAABB); - double min = -65535, max = 65535, step = 0.001; + double min = -65535, max = 65535, step = 0; bool hide_slider = true; if (p_hint == PROPERTY_HINT_RANGE && p_hint_text.get_slice_count(",") >= 2) { @@ -3099,7 +3099,7 @@ bool EditorInspectorDefaultPlugin::parse_property(Object *p_object, Variant::Typ } break; case Variant::BASIS: { EditorPropertyBasis *editor = memnew(EditorPropertyBasis); - double min = -65535, max = 65535, step = 0.001; + double min = -65535, max = 65535, step = 0; bool hide_slider = true; if (p_hint == PROPERTY_HINT_RANGE && p_hint_text.get_slice_count(",") >= 2) { @@ -3116,7 +3116,7 @@ bool EditorInspectorDefaultPlugin::parse_property(Object *p_object, Variant::Typ } break; case Variant::TRANSFORM: { EditorPropertyTransform *editor = memnew(EditorPropertyTransform); - double min = -65535, max = 65535, step = 0.001; + double min = -65535, max = 65535, step = 0; bool hide_slider = true; if (p_hint == PROPERTY_HINT_RANGE && p_hint_text.get_slice_count(",") >= 2) { diff --git a/servers/visual/shader_language.h b/servers/visual/shader_language.h index b908f9539bd3..31e1722ece27 100644 --- a/servers/visual/shader_language.h +++ b/servers/visual/shader_language.h @@ -483,7 +483,7 @@ class ShaderLanguage { hint = HINT_NONE; hint_range[0] = 0; hint_range[1] = 1; - hint_range[2] = 0.001; + hint_range[2] = 0; } };