-
-
Notifications
You must be signed in to change notification settings - Fork 26.4k
Add normalization button to Quaternion inspector #98308
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1941,6 +1941,30 @@ void EditorPropertyQuaternion::_set_read_only(bool p_read_only) { | |
| } | ||
| } | ||
|
|
||
| void EditorPropertyQuaternion::_edit_normalize_quaternion_value() { | ||
| if (normalize_quaternion_bttn->is_pressed()) { | ||
| EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton(); | ||
| undo_redo->create_action("Quaternion Normalized"); | ||
|
|
||
| Quaternion temp; | ||
| for (int i = 0; i < 4; i++) { | ||
| temp[i] = (real_t)spin[i]->get_value(); | ||
|
|
||
| //undo_redo->add_undo_property(spin[i], "Un-Normalize Quaternion", spin[i]); | ||
| undo_redo->add_undo_property(get_edited_object(), get_edited_property(), spin[i]); | ||
| } | ||
| temp = temp.normalized(); | ||
| for (int i = 0; i < 4; i++) { | ||
| spin[i]->set_value_no_signal((double)temp[i]); | ||
|
|
||
| undo_redo->add_undo_property(get_edited_object(), get_edited_property(), temp[i]); | ||
| //undo_redo->add_do_property(spin[i], "Re-Normalize Quaternion", temp[i]); | ||
| } | ||
| _value_changed(-1, ""); | ||
| undo_redo->commit_action(); | ||
|
Comment on lines
+1946
to
+1964
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If property's |
||
| } | ||
| } | ||
|
|
||
| void EditorPropertyQuaternion::_edit_custom_value() { | ||
| if (edit_button->is_pressed()) { | ||
| edit_custom_bc->show(); | ||
|
|
@@ -2065,6 +2089,7 @@ EditorPropertyQuaternion::EditorPropertyQuaternion() { | |
|
|
||
| VBoxContainer *bc = memnew(VBoxContainer); | ||
| edit_custom_bc = memnew(VBoxContainer); | ||
| normalize_quaternion = memnew(VBoxContainer); | ||
| BoxContainer *edit_custom_layout; | ||
| if (horizontal) { | ||
| default_layout = memnew(HBoxContainer); | ||
|
|
@@ -2076,10 +2101,12 @@ EditorPropertyQuaternion::EditorPropertyQuaternion() { | |
| } | ||
| edit_custom_bc->hide(); | ||
| add_child(bc); | ||
| normalize_quaternion->set_h_size_flags(SIZE_EXPAND_FILL); | ||
| edit_custom_bc->set_h_size_flags(SIZE_EXPAND_FILL); | ||
| default_layout->set_h_size_flags(SIZE_EXPAND_FILL); | ||
| edit_custom_layout->set_h_size_flags(SIZE_EXPAND_FILL); | ||
| bc->add_child(default_layout); | ||
| bc->add_child(normalize_quaternion); | ||
| bc->add_child(edit_custom_bc); | ||
|
|
||
| static const char *desc[4] = { "x", "y", "z", "w" }; | ||
|
|
@@ -2095,6 +2122,12 @@ EditorPropertyQuaternion::EditorPropertyQuaternion() { | |
| } | ||
| } | ||
|
|
||
| normalize_quaternion_bttn = memnew(Button); | ||
| normalize_quaternion_bttn->set_text("Normalize"); | ||
| normalize_quaternion_bttn->connect(SceneStringName(pressed), callable_mp(this, &EditorPropertyQuaternion::_edit_normalize_quaternion_value)); | ||
| add_focusable(normalize_quaternion_bttn); | ||
| normalize_quaternion->add_child(normalize_quaternion_bttn); | ||
|
|
||
| warning = memnew(Button); | ||
| warning->set_text(TTR("Temporary Euler may be changed implicitly!")); | ||
| warning->set_clip_text(true); | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -487,14 +487,17 @@ class EditorPropertyQuaternion : public EditorProperty { | |||||
| AcceptDialog *warning_dialog = nullptr; | ||||||
|
|
||||||
| Label *euler_label = nullptr; | ||||||
| VBoxContainer *normalize_quaternion = nullptr; | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
The name should be clearer.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. However, I felt that the normalization button is overemphasized. So how about making the letters “Nrm” or “1.0” into icons and placing them to the right of the SpinBox? Then, it will conflicts with EulerEdit, so I think it would be smartest way is making it function as Nrm button when In other words, it places only one button to the right of the SpinBox, whose icon changes depending on the state of |
||||||
| VBoxContainer *edit_custom_bc = nullptr; | ||||||
| EditorSpinSlider *euler[3]; | ||||||
| Button *edit_button = nullptr; | ||||||
| Button *normalize_quaternion_bttn = nullptr; | ||||||
|
TokageItLab marked this conversation as resolved.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Nitpick for consistency with other classes. |
||||||
|
|
||||||
| Vector3 edit_euler; | ||||||
|
|
||||||
| void _value_changed(double p_val, const String &p_name); | ||||||
| void _edit_custom_value(); | ||||||
| void _edit_normalize_quaternion_value(); | ||||||
| void _custom_value_changed(double p_val); | ||||||
| void _warning_pressed(); | ||||||
|
|
||||||
|
|
||||||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this issue depends on the accuracy of the inspector, the correct fix is to do it in the inspector, as in #106352.
If the accuracy of Quaternion's input in the inspector is increased by #106352, this line change is not necessary.