summaryrefslogtreecommitdiff
path: root/modules/gridmap/grid_map_editor_plugin.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'modules/gridmap/grid_map_editor_plugin.cpp')
-rw-r--r--modules/gridmap/grid_map_editor_plugin.cpp223
1 files changed, 78 insertions, 145 deletions
diff --git a/modules/gridmap/grid_map_editor_plugin.cpp b/modules/gridmap/grid_map_editor_plugin.cpp
index fc545430f5..2bae43510a 100644
--- a/modules/gridmap/grid_map_editor_plugin.cpp
+++ b/modules/gridmap/grid_map_editor_plugin.cpp
@@ -40,23 +40,21 @@
#include "scene/main/window.h"
void GridMapEditor::_node_removed(Node *p_node) {
-
- if (p_node == node)
+ if (p_node == node) {
node = nullptr;
+ }
}
void GridMapEditor::_configure() {
-
- if (!node)
+ if (!node) {
return;
+ }
update_grid();
}
void GridMapEditor::_menu_option(int p_option) {
-
switch (p_option) {
-
case MENU_OPTION_PREV_LEVEL: {
floor->set_value(floor->get_value() - 1);
} break;
@@ -66,7 +64,6 @@ void GridMapEditor::_menu_option(int p_option) {
} break;
case MENU_OPTION_LOCK_VIEW: {
-
int index = options->get_popup()->get_item_index(MENU_OPTION_LOCK_VIEW);
lock_view = !options->get_popup()->is_item_checked(index);
@@ -75,10 +72,8 @@ void GridMapEditor::_menu_option(int p_option) {
case MENU_OPTION_CLIP_DISABLED:
case MENU_OPTION_CLIP_ABOVE:
case MENU_OPTION_CLIP_BELOW: {
-
clip_mode = ClipMode(p_option - MENU_OPTION_CLIP_DISABLED);
for (int i = 0; i < 3; i++) {
-
int index = options->get_popup()->get_item_index(MENU_OPTION_CLIP_DISABLED + i);
options->get_popup()->set_item_checked(index, i == clip_mode);
}
@@ -88,7 +83,6 @@ void GridMapEditor::_menu_option(int p_option) {
case MENU_OPTION_X_AXIS:
case MENU_OPTION_Y_AXIS:
case MENU_OPTION_Z_AXIS: {
-
int new_axis = p_option - MENU_OPTION_X_AXIS;
for (int i = 0; i < 3; i++) {
int idx = options->get_popup()->get_item_index(MENU_OPTION_X_AXIS + i);
@@ -114,10 +108,8 @@ void GridMapEditor::_menu_option(int p_option) {
} break;
case MENU_OPTION_CURSOR_ROTATE_Y: {
-
Basis r;
if (input_action == INPUT_PASTE) {
-
r.set_orthogonal_index(paste_indicator.orientation);
r.rotate(Vector3(0, 1, 0), -Math_PI / 2.0);
paste_indicator.orientation = r.get_orthogonal_index();
@@ -131,10 +123,8 @@ void GridMapEditor::_menu_option(int p_option) {
_update_cursor_transform();
} break;
case MENU_OPTION_CURSOR_ROTATE_X: {
-
Basis r;
if (input_action == INPUT_PASTE) {
-
r.set_orthogonal_index(paste_indicator.orientation);
r.rotate(Vector3(1, 0, 0), -Math_PI / 2.0);
paste_indicator.orientation = r.get_orthogonal_index();
@@ -148,10 +138,8 @@ void GridMapEditor::_menu_option(int p_option) {
_update_cursor_transform();
} break;
case MENU_OPTION_CURSOR_ROTATE_Z: {
-
Basis r;
if (input_action == INPUT_PASTE) {
-
r.set_orthogonal_index(paste_indicator.orientation);
r.rotate(Vector3(0, 0, 1), -Math_PI / 2.0);
paste_indicator.orientation = r.get_orthogonal_index();
@@ -165,10 +153,8 @@ void GridMapEditor::_menu_option(int p_option) {
_update_cursor_transform();
} break;
case MENU_OPTION_CURSOR_BACK_ROTATE_Y: {
-
Basis r;
if (input_action == INPUT_PASTE) {
-
r.set_orthogonal_index(paste_indicator.orientation);
r.rotate(Vector3(0, 1, 0), Math_PI / 2.0);
paste_indicator.orientation = r.get_orthogonal_index();
@@ -182,10 +168,8 @@ void GridMapEditor::_menu_option(int p_option) {
_update_cursor_transform();
} break;
case MENU_OPTION_CURSOR_BACK_ROTATE_X: {
-
Basis r;
if (input_action == INPUT_PASTE) {
-
r.set_orthogonal_index(paste_indicator.orientation);
r.rotate(Vector3(1, 0, 0), Math_PI / 2.0);
paste_indicator.orientation = r.get_orthogonal_index();
@@ -199,10 +183,8 @@ void GridMapEditor::_menu_option(int p_option) {
_update_cursor_transform();
} break;
case MENU_OPTION_CURSOR_BACK_ROTATE_Z: {
-
Basis r;
if (input_action == INPUT_PASTE) {
-
r.set_orthogonal_index(paste_indicator.orientation);
r.rotate(Vector3(0, 0, 1), Math_PI / 2.0);
paste_indicator.orientation = r.get_orthogonal_index();
@@ -216,9 +198,7 @@ void GridMapEditor::_menu_option(int p_option) {
_update_cursor_transform();
} break;
case MENU_OPTION_CURSOR_CLEAR_ROTATION: {
-
if (input_action == INPUT_PASTE) {
-
paste_indicator.orientation = 0;
_update_paste_indicator();
break;
@@ -235,8 +215,9 @@ void GridMapEditor::_menu_option(int p_option) {
case MENU_OPTION_SELECTION_DUPLICATE:
case MENU_OPTION_SELECTION_CUT: {
- if (!(selection.active && input_action == INPUT_NONE))
+ if (!(selection.active && input_action == INPUT_NONE)) {
break;
+ }
_set_clipboard_data();
@@ -253,15 +234,17 @@ void GridMapEditor::_menu_option(int p_option) {
_update_paste_indicator();
} break;
case MENU_OPTION_SELECTION_CLEAR: {
- if (!selection.active)
+ if (!selection.active) {
break;
+ }
_delete_selection();
} break;
case MENU_OPTION_SELECTION_FILL: {
- if (!selection.active)
+ if (!selection.active) {
return;
+ }
_fill_selection();
@@ -273,7 +256,6 @@ void GridMapEditor::_menu_option(int p_option) {
}
void GridMapEditor::_update_cursor_transform() {
-
cursor_transform = Transform();
cursor_transform.origin = cursor_origin;
cursor_transform.basis.set_orthogonal_index(cursor_rot);
@@ -291,7 +273,6 @@ void GridMapEditor::_update_selection_transform() {
xf_zero.basis.set_zero();
if (!selection.active) {
-
RenderingServer::get_singleton()->instance_set_transform(selection_instance, xf_zero);
for (int i = 0; i < 3; i++) {
RenderingServer::get_singleton()->instance_set_transform(selection_level_instance[i], xf_zero);
@@ -309,7 +290,6 @@ void GridMapEditor::_update_selection_transform() {
if (i != edit_axis || (edit_floor[edit_axis] < selection.begin[edit_axis]) || (edit_floor[edit_axis] > selection.end[edit_axis] + 1)) {
RenderingServer::get_singleton()->instance_set_transform(selection_level_instance[i], xf_zero);
} else {
-
Vector3 scale = (selection.end - selection.begin + Vector3(1, 1, 1));
scale[edit_axis] = 1.0;
Vector3 pos = selection.begin;
@@ -328,24 +308,26 @@ void GridMapEditor::_update_selection_transform() {
}
void GridMapEditor::_validate_selection() {
-
- if (!selection.active)
+ if (!selection.active) {
return;
+ }
selection.begin = selection.click;
selection.end = selection.current;
- if (selection.begin.x > selection.end.x)
+ if (selection.begin.x > selection.end.x) {
SWAP(selection.begin.x, selection.end.x);
- if (selection.begin.y > selection.end.y)
+ }
+ if (selection.begin.y > selection.end.y) {
SWAP(selection.begin.y, selection.end.y);
- if (selection.begin.z > selection.end.z)
+ }
+ if (selection.begin.z > selection.end.z) {
SWAP(selection.begin.z, selection.end.z);
+ }
_update_selection_transform();
}
void GridMapEditor::_set_selection(bool p_active, const Vector3 &p_begin, const Vector3 &p_end) {
-
selection.active = p_active;
selection.begin = p_begin;
selection.end = p_end;
@@ -363,17 +345,20 @@ void GridMapEditor::_set_selection(bool p_active, const Vector3 &p_begin, const
}
bool GridMapEditor::do_input_action(Camera3D *p_camera, const Point2 &p_point, bool p_click) {
-
- if (!spatial_editor)
+ if (!spatial_editor) {
return false;
+ }
- if (selected_palette < 0 && input_action != INPUT_PICK && input_action != INPUT_SELECT && input_action != INPUT_PASTE)
+ if (selected_palette < 0 && input_action != INPUT_PICK && input_action != INPUT_SELECT && input_action != INPUT_PASTE) {
return false;
+ }
Ref<MeshLibrary> mesh_library = node->get_mesh_library();
- if (mesh_library.is_null())
+ if (mesh_library.is_null()) {
return false;
- if (input_action != INPUT_PICK && input_action != INPUT_SELECT && input_action != INPUT_PASTE && !mesh_library->has_item(selected_palette))
+ }
+ if (input_action != INPUT_PICK && input_action != INPUT_SELECT && input_action != INPUT_PASTE && !mesh_library->has_item(selected_palette)) {
return false;
+ }
Camera3D *camera = p_camera;
Vector3 from = camera->project_ray_origin(p_point);
@@ -388,30 +373,30 @@ bool GridMapEditor::do_input_action(Camera3D *p_camera, const Point2 &p_point, b
p.d = edit_floor[edit_axis] * node->get_cell_size()[edit_axis];
Vector3 inters;
- if (!p.intersects_segment(from, from + normal * settings_pick_distance->get_value(), &inters))
+ if (!p.intersects_segment(from, from + normal * settings_pick_distance->get_value(), &inters)) {
return false;
+ }
// Make sure the intersection is inside the frustum planes, to avoid
// Painting on invisible regions.
for (int i = 0; i < planes.size(); i++) {
-
Plane fp = local_xform.xform(planes[i]);
- if (fp.is_point_over(inters))
+ if (fp.is_point_over(inters)) {
return false;
+ }
}
int cell[3];
float cell_size[3] = { node->get_cell_size().x, node->get_cell_size().y, node->get_cell_size().z };
for (int i = 0; i < 3; i++) {
-
- if (i == edit_axis)
+ if (i == edit_axis) {
cell[i] = edit_floor[i];
- else {
-
+ } else {
cell[i] = inters[i] / node->get_cell_size()[i];
- if (inters[i] < 0)
+ if (inters[i] < 0) {
cell[i] -= 1; // Compensate negative.
+ }
grid_ofs[i] = cell[i] * cell_size[i];
}
}
@@ -419,7 +404,6 @@ bool GridMapEditor::do_input_action(Camera3D *p_camera, const Point2 &p_point, b
RS::get_singleton()->instance_set_transform(grid_instance[edit_axis], node->get_global_transform() * edit_grid_xform);
if (cursor_instance.is_valid()) {
-
cursor_origin = (Vector3(cell[0], cell[1], cell[2]) + Vector3(0.5 * node->get_center_x(), 0.5 * node->get_center_y(), 0.5 * node->get_center_z())) * node->get_cell_size();
cursor_visible = true;
@@ -431,21 +415,19 @@ bool GridMapEditor::do_input_action(Camera3D *p_camera, const Point2 &p_point, b
}
if (input_action == INPUT_PASTE) {
-
paste_indicator.current = Vector3(cell[0], cell[1], cell[2]);
_update_paste_indicator();
} else if (input_action == INPUT_SELECT) {
-
selection.current = Vector3(cell[0], cell[1], cell[2]);
- if (p_click)
+ if (p_click) {
selection.click = selection.current;
+ }
selection.active = true;
_validate_selection();
return true;
} else if (input_action == INPUT_PICK) {
-
int item = node->get_cell_item(cell[0], cell[1], cell[2]);
if (item >= 0) {
selected_palette = item;
@@ -481,17 +463,14 @@ bool GridMapEditor::do_input_action(Camera3D *p_camera, const Point2 &p_point, b
}
void GridMapEditor::_delete_selection() {
-
- if (!selection.active)
+ if (!selection.active) {
return;
+ }
undo_redo->create_action(TTR("GridMap Delete Selection"));
for (int i = selection.begin.x; i <= selection.end.x; i++) {
-
for (int j = selection.begin.y; j <= selection.end.y; j++) {
-
for (int k = selection.begin.z; k <= selection.end.z; k++) {
-
undo_redo->add_do_method(node, "set_cell_item", i, j, k, GridMap::INVALID_CELL_ITEM);
undo_redo->add_undo_method(node, "set_cell_item", i, j, k, node->get_cell_item(i, j, k), node->get_cell_item_orientation(i, j, k));
}
@@ -503,17 +482,14 @@ void GridMapEditor::_delete_selection() {
}
void GridMapEditor::_fill_selection() {
-
- if (!selection.active)
+ if (!selection.active) {
return;
+ }
undo_redo->create_action(TTR("GridMap Fill Selection"));
for (int i = selection.begin.x; i <= selection.end.x; i++) {
-
for (int j = selection.begin.y; j <= selection.end.y; j++) {
-
for (int k = selection.begin.z; k <= selection.end.z; k++) {
-
undo_redo->add_do_method(node, "set_cell_item", i, j, k, selected_palette, cursor_rot);
undo_redo->add_undo_method(node, "set_cell_item", i, j, k, node->get_cell_item(i, j, k), node->get_cell_item_orientation(i, j, k));
}
@@ -525,9 +501,7 @@ void GridMapEditor::_fill_selection() {
}
void GridMapEditor::_clear_clipboard_data() {
-
for (List<ClipboardItem>::Element *E = clipboard_items.front(); E; E = E->next()) {
-
RenderingServer::get_singleton()->free(E->get().instance);
}
@@ -535,20 +509,17 @@ void GridMapEditor::_clear_clipboard_data() {
}
void GridMapEditor::_set_clipboard_data() {
-
_clear_clipboard_data();
Ref<MeshLibrary> meshLibrary = node->get_mesh_library();
for (int i = selection.begin.x; i <= selection.end.x; i++) {
-
for (int j = selection.begin.y; j <= selection.end.y; j++) {
-
for (int k = selection.begin.z; k <= selection.end.z; k++) {
-
int itm = node->get_cell_item(i, j, k);
- if (itm == GridMap::INVALID_CELL_ITEM)
+ if (itm == GridMap::INVALID_CELL_ITEM) {
continue;
+ }
Ref<Mesh> mesh = meshLibrary->get_item_mesh(itm);
@@ -565,9 +536,7 @@ void GridMapEditor::_set_clipboard_data() {
}
void GridMapEditor::_update_paste_indicator() {
-
if (input_action != INPUT_PASTE) {
-
Transform xf;
xf.basis.set_zero();
RenderingServer::get_singleton()->instance_set_transform(paste_instance, xf);
@@ -587,7 +556,6 @@ void GridMapEditor::_update_paste_indicator() {
RenderingServer::get_singleton()->instance_set_transform(paste_instance, node->get_global_transform() * xf);
for (List<ClipboardItem>::Element *E = clipboard_items.front(); E; E = E->next()) {
-
ClipboardItem &item = E->get();
xf = Transform();
@@ -604,7 +572,6 @@ void GridMapEditor::_update_paste_indicator() {
}
void GridMapEditor::_do_paste() {
-
int idx = options->get_popup()->get_item_index(MENU_OPTION_PASTE_SELECTS);
bool reselect = options->get_popup()->is_item_checked(idx);
@@ -615,7 +582,6 @@ void GridMapEditor::_do_paste() {
undo_redo->create_action(TTR("GridMap Paste Selection"));
for (List<ClipboardItem>::Element *E = clipboard_items.front(); E; E = E->next()) {
-
ClipboardItem &item = E->get();
Vector3 pos = rot.xform(item.grid_offset) + paste_indicator.begin + ofs;
@@ -629,7 +595,6 @@ void GridMapEditor::_do_paste() {
}
if (reselect) {
-
undo_redo->add_do_method(this, "_set_selection", true, paste_indicator.begin + ofs, paste_indicator.end + ofs);
undo_redo->add_undo_method(this, "_set_selection", selection.active, selection.begin, selection.end);
}
@@ -647,15 +612,16 @@ bool GridMapEditor::forward_spatial_input_event(Camera3D *p_camera, const Ref<In
Ref<InputEventMouseButton> mb = p_event;
if (mb.is_valid()) {
-
if (mb->get_button_index() == BUTTON_WHEEL_UP && (mb->get_command() || mb->get_shift())) {
- if (mb->is_pressed())
+ if (mb->is_pressed()) {
floor->set_value(floor->get_value() + mb->get_factor());
+ }
return true; // Eaten.
} else if (mb->get_button_index() == BUTTON_WHEEL_DOWN && (mb->get_command() || mb->get_shift())) {
- if (mb->is_pressed())
+ if (mb->is_pressed()) {
floor->set_value(floor->get_value() - mb->get_factor());
+ }
return true;
}
@@ -664,7 +630,6 @@ bool GridMapEditor::forward_spatial_input_event(Camera3D *p_camera, const Ref<In
if ((nav_scheme == Node3DEditorViewport::NAVIGATION_MAYA || nav_scheme == Node3DEditorViewport::NAVIGATION_MODO) && mb->get_alt()) {
input_action = INPUT_NONE;
} else if (mb->get_button_index() == BUTTON_LEFT) {
-
bool can_edit = (node && node->get_mesh_library().is_valid());
if (input_action == INPUT_PASTE) {
_do_paste();
@@ -698,18 +663,14 @@ bool GridMapEditor::forward_spatial_input_event(Camera3D *p_camera, const Ref<In
return do_input_action(p_camera, Point2(mb->get_position().x, mb->get_position().y), true);
} else {
-
if ((mb->get_button_index() == BUTTON_RIGHT && input_action == INPUT_ERASE) || (mb->get_button_index() == BUTTON_LEFT && input_action == INPUT_PAINT)) {
-
if (set_items.size()) {
undo_redo->create_action(TTR("GridMap Paint"));
for (List<SetItem>::Element *E = set_items.front(); E; E = E->next()) {
-
const SetItem &si = E->get();
undo_redo->add_do_method(node, "set_cell_item", si.pos.x, si.pos.y, si.pos.z, si.new_value, si.new_orientation);
}
for (List<SetItem>::Element *E = set_items.back(); E; E = E->prev()) {
-
const SetItem &si = E->get();
undo_redo->add_undo_method(node, "set_cell_item", si.pos.x, si.pos.y, si.pos.z, si.old_value, si.old_orientation);
}
@@ -722,7 +683,6 @@ bool GridMapEditor::forward_spatial_input_event(Camera3D *p_camera, const Ref<In
}
if (mb->get_button_index() == BUTTON_LEFT && input_action == INPUT_SELECT) {
-
undo_redo->create_action("GridMap Selection");
undo_redo->add_do_method(this, "_set_selection", selection.active, selection.begin, selection.end);
undo_redo->add_undo_method(this, "_set_selection", last_selection.active, last_selection.begin, last_selection.end);
@@ -730,7 +690,6 @@ bool GridMapEditor::forward_spatial_input_event(Camera3D *p_camera, const Ref<In
}
if (mb->get_button_index() == BUTTON_LEFT && input_action != INPUT_NONE) {
-
set_items.clear();
input_action = INPUT_NONE;
return true;
@@ -745,7 +704,6 @@ bool GridMapEditor::forward_spatial_input_event(Camera3D *p_camera, const Ref<In
Ref<InputEventMouseMotion> mm = p_event;
if (mm.is_valid()) {
-
return do_input_action(p_camera, mm->get_position(), false);
}
@@ -754,7 +712,6 @@ bool GridMapEditor::forward_spatial_input_event(Camera3D *p_camera, const Ref<In
if (k.is_valid()) {
if (k->is_pressed()) {
if (k->get_keycode() == KEY_ESCAPE) {
-
if (input_action == INPUT_PASTE) {
_clear_clipboard_data();
input_action = INPUT_NONE;
@@ -773,7 +730,6 @@ bool GridMapEditor::forward_spatial_input_event(Camera3D *p_camera, const Ref<In
}
if (k->get_shift() && selection.active && input_action != INPUT_PASTE) {
-
if (k->get_keycode() == options->get_popup()->get_item_accelerator(options->get_popup()->get_item_index(MENU_OPTION_PREV_LEVEL))) {
selection.click[edit_axis]--;
_validate_selection();
@@ -790,7 +746,6 @@ bool GridMapEditor::forward_spatial_input_event(Camera3D *p_camera, const Ref<In
Ref<InputEventPanGesture> pan_gesture = p_event;
if (pan_gesture.is_valid()) {
-
if (pan_gesture->get_alt() && (pan_gesture->get_command() || pan_gesture->get_shift())) {
const real_t delta = pan_gesture->get_delta().y * 0.5;
accumulated_floor_delta += delta;
@@ -811,7 +766,6 @@ bool GridMapEditor::forward_spatial_input_event(Camera3D *p_camera, const Ref<In
}
struct _CGMEItemSort {
-
String name;
int id;
_FORCE_INLINE_ bool operator<(const _CGMEItemSort &r_it) const { return name < r_it.name; }
@@ -840,11 +794,9 @@ void GridMapEditor::_text_changed(const String &p_text) {
}
void GridMapEditor::_sbox_input(const Ref<InputEvent> &p_ie) {
-
const Ref<InputEventKey> k = p_ie;
if (k.is_valid() && (k->get_keycode() == KEY_UP || k->get_keycode() == KEY_DOWN || k->get_keycode() == KEY_PAGEUP || k->get_keycode() == KEY_PAGEDOWN)) {
-
// Forward the key input to the ItemList so it can be scrolled
mesh_library_palette->call("_gui_input", k);
search_box->accept_event();
@@ -852,12 +804,10 @@ void GridMapEditor::_sbox_input(const Ref<InputEvent> &p_ie) {
}
void GridMapEditor::_mesh_library_palette_input(const Ref<InputEvent> &p_ie) {
-
const Ref<InputEventMouseButton> mb = p_ie;
// Zoom in/out using Ctrl + mouse wheel
if (mb.is_valid() && mb->is_pressed() && mb->get_command()) {
-
if (mb->is_pressed() && mb->get_button_index() == BUTTON_WHEEL_UP) {
size_slider->set_value(size_slider->get_value() + 0.2);
}
@@ -911,7 +861,6 @@ void GridMapEditor::update_palette() {
List<_CGMEItemSort> il;
for (int i = 0; i < ids.size(); i++) {
-
_CGMEItemSort is;
is.id = ids[i];
is.name = mesh_library->get_item_name(ids[i]);
@@ -932,8 +881,9 @@ void GridMapEditor::update_palette() {
name = "#" + itos(id);
}
- if (filter != "" && !filter.is_subsequence_ofi(name))
+ if (filter != "" && !filter.is_subsequence_ofi(name)) {
continue;
+ }
mesh_library_palette->add_item("");
if (!preview.is_null()) {
@@ -954,8 +904,9 @@ void GridMapEditor::update_palette() {
}
void GridMapEditor::edit(GridMap *p_gridmap) {
- if (!p_gridmap && node)
+ if (!p_gridmap && node) {
node->disconnect("cell_size_changed", callable_mp(this, &GridMapEditor::_draw_grids));
+ }
node = p_gridmap;
@@ -993,16 +944,15 @@ void GridMapEditor::edit(GridMap *p_gridmap) {
}
void GridMapEditor::_update_clip() {
-
node->set_meta("_editor_clip_", clip_mode);
- if (clip_mode == CLIP_DISABLED)
+ if (clip_mode == CLIP_DISABLED) {
node->set_clip(false);
- else
+ } else {
node->set_clip(true, clip_mode == CLIP_ABOVE, edit_floor[edit_axis], edit_axis);
+ }
}
void GridMapEditor::update_grid() {
-
grid_xform.origin.x -= 1; // Force update in hackish way.
grid_ofs[edit_axis] = edit_floor[edit_axis] * node->get_cell_size()[edit_axis];
@@ -1031,7 +981,6 @@ void GridMapEditor::_draw_grids(const Vector3 &cell_size) {
Vector<Color> grid_colors[3];
for (int i = 0; i < 3; i++) {
-
Vector3 axis;
axis[i] = 1;
Vector3 axis_n1;
@@ -1040,9 +989,7 @@ void GridMapEditor::_draw_grids(const Vector3 &cell_size) {
axis_n2[(i + 2) % 3] = cell_size[(i + 2) % 3];
for (int j = -GRID_CURSOR_SIZE; j <= GRID_CURSOR_SIZE; j++) {
-
for (int k = -GRID_CURSOR_SIZE; k <= GRID_CURSOR_SIZE; k++) {
-
Vector3 p = axis_n1 * j + axis_n2 * k;
float trans = Math::pow(MAX(0, 1.0 - (Vector2(j, k).length() / GRID_CURSOR_SIZE)), 2);
@@ -1074,14 +1021,11 @@ void GridMapEditor::_draw_grids(const Vector3 &cell_size) {
}
void GridMapEditor::_notification(int p_what) {
-
switch (p_what) {
-
case NOTIFICATION_ENTER_TREE: {
get_tree()->connect("node_removed", callable_mp(this, &GridMapEditor::_node_removed));
mesh_library_palette->connect("item_selected", callable_mp(this, &GridMapEditor::_item_selected_cbk));
for (int i = 0; i < 3; i++) {
-
grid[i] = RS::get_singleton()->mesh_create();
grid_instance[i] = RS::get_singleton()->instance_create2(grid[i], get_tree()->get_root()->get_world_3d()->get_scenario());
selection_level_instance[i] = RenderingServer::get_singleton()->instance_create2(selection_level_mesh[i], get_tree()->get_root()->get_world_3d()->get_scenario());
@@ -1099,7 +1043,6 @@ void GridMapEditor::_notification(int p_what) {
_clear_clipboard_data();
for (int i = 0; i < 3; i++) {
-
RS::get_singleton()->free(grid_instance[i]);
RS::get_singleton()->free(grid[i]);
grid_instance[i] = RID();
@@ -1122,17 +1065,16 @@ void GridMapEditor::_notification(int p_what) {
if (xf != grid_xform) {
for (int i = 0; i < 3; i++) {
-
RS::get_singleton()->instance_set_transform(grid_instance[i], xf * edit_grid_xform);
}
grid_xform = xf;
}
Ref<MeshLibrary> cgmt = node->get_mesh_library();
- if (cgmt.operator->() != last_mesh_library)
+ if (cgmt.operator->() != last_mesh_library) {
update_palette();
+ }
if (lock_view) {
-
EditorNode *editor = Object::cast_to<EditorNode>(get_tree()->get_root()->get_child(0));
Plane p;
@@ -1141,8 +1083,9 @@ void GridMapEditor::_notification(int p_what) {
p = node->get_transform().xform(p); // plane to snap
Node3DEditorPlugin *sep = Object::cast_to<Node3DEditorPlugin>(editor->get_editor_plugin_screen());
- if (sep)
+ if (sep) {
sep->snap_cursor_to_plane(p);
+ }
}
} break;
@@ -1158,16 +1101,15 @@ void GridMapEditor::_update_cursor_instance() {
return;
}
- if (cursor_instance.is_valid())
+ if (cursor_instance.is_valid()) {
RenderingServer::get_singleton()->free(cursor_instance);
+ }
cursor_instance = RID();
if (selected_palette >= 0) {
-
if (node && !node->get_mesh_library().is_null()) {
Ref<Mesh> mesh = node->get_mesh_library()->get_item_mesh(selected_palette);
if (!mesh.is_null() && mesh->get_rid().is_valid()) {
-
cursor_instance = RenderingServer::get_singleton()->instance_create2(mesh->get_rid(), get_tree()->get_root()->get_world_3d()->get_scenario());
RenderingServer::get_singleton()->instance_set_transform(cursor_instance, cursor_transform);
}
@@ -1182,9 +1124,9 @@ void GridMapEditor::_item_selected_cbk(int idx) {
}
void GridMapEditor::_floor_changed(float p_value) {
-
- if (updating)
+ if (updating) {
return;
+ }
edit_floor[edit_axis] = p_value;
node->set_meta("_editor_floor_", Vector3(edit_floor[0], edit_floor[1], edit_floor[2]));
@@ -1198,13 +1140,11 @@ void GridMapEditor::_floor_mouse_exited() {
}
void GridMapEditor::_bind_methods() {
-
ClassDB::bind_method("_configure", &GridMapEditor::_configure);
ClassDB::bind_method("_set_selection", &GridMapEditor::_set_selection);
}
GridMapEditor::GridMapEditor(EditorNode *p_editor) {
-
input_action = INPUT_NONE;
editor = p_editor;
undo_redo = p_editor->get_undo_redo();
@@ -1364,22 +1304,20 @@ GridMapEditor::GridMapEditor(EditorNode *p_editor) {
Vector<Vector3> square[3];
for (int i = 0; i < 6; i++) {
-
Vector3 face_points[4];
for (int j = 0; j < 4; j++) {
-
float v[3];
v[0] = 1.0;
v[1] = 1 - 2 * ((j >> 1) & 1);
v[2] = v[1] * (1 - 2 * (j & 1));
for (int k = 0; k < 3; k++) {
-
- if (i < 3)
+ if (i < 3) {
face_points[j][(i + k) % 3] = v[k];
- else
+ } else {
face_points[3 - j][(i + k) % 3] = -v[k];
+ }
}
}
@@ -1393,7 +1331,6 @@ GridMapEditor::GridMapEditor(EditorNode *p_editor) {
}
for (int i = 0; i < 12; i++) {
-
AABB base(Vector3(0, 0, 0), Vector3(1, 1, 1));
Vector3 a, b;
base.get_edge(i, a, b);
@@ -1404,7 +1341,6 @@ GridMapEditor::GridMapEditor(EditorNode *p_editor) {
for (int i = 0; i < 3; i++) {
Vector3 points[4];
for (int j = 0; j < 4; j++) {
-
static const bool orderx[4] = { false, true, true, false };
static const bool ordery[4] = { false, false, true, true };
@@ -1420,7 +1356,6 @@ GridMapEditor::GridMapEditor(EditorNode *p_editor) {
}
for (int j = 0; j < 4; j++) {
-
Vector3 ofs;
ofs[i] += 0.01;
square[i].push_back(points[j] - ofs);
@@ -1487,36 +1422,39 @@ GridMapEditor::GridMapEditor(EditorNode *p_editor) {
}
GridMapEditor::~GridMapEditor() {
-
_clear_clipboard_data();
for (int i = 0; i < 3; i++) {
-
- if (grid[i].is_valid())
+ if (grid[i].is_valid()) {
RenderingServer::get_singleton()->free(grid[i]);
- if (grid_instance[i].is_valid())
+ }
+ if (grid_instance[i].is_valid()) {
RenderingServer::get_singleton()->free(grid_instance[i]);
- if (cursor_instance.is_valid())
+ }
+ if (cursor_instance.is_valid()) {
RenderingServer::get_singleton()->free(cursor_instance);
- if (selection_level_instance[i].is_valid())
+ }
+ if (selection_level_instance[i].is_valid()) {
RenderingServer::get_singleton()->free(selection_level_instance[i]);
- if (selection_level_mesh[i].is_valid())
+ }
+ if (selection_level_mesh[i].is_valid()) {
RenderingServer::get_singleton()->free(selection_level_mesh[i]);
+ }
}
RenderingServer::get_singleton()->free(selection_mesh);
- if (selection_instance.is_valid())
+ if (selection_instance.is_valid()) {
RenderingServer::get_singleton()->free(selection_instance);
+ }
RenderingServer::get_singleton()->free(paste_mesh);
- if (paste_instance.is_valid())
+ if (paste_instance.is_valid()) {
RenderingServer::get_singleton()->free(paste_instance);
+ }
}
void GridMapEditorPlugin::_notification(int p_what) {
-
if (p_what == EditorSettings::NOTIFICATION_EDITOR_SETTINGS_CHANGED) {
-
switch ((int)EditorSettings::get_singleton()->get("editors/grid_map/editor_side")) {
case 0: { // Left.
Node3DEditor::get_singleton()->get_palette_split()->move_child(grid_map_editor, 0);
@@ -1529,23 +1467,19 @@ void GridMapEditorPlugin::_notification(int p_what) {
}
void GridMapEditorPlugin::edit(Object *p_object) {
-
grid_map_editor->edit(Object::cast_to<GridMap>(p_object));
}
bool GridMapEditorPlugin::handles(Object *p_object) const {
-
return p_object->is_class("GridMap");
}
void GridMapEditorPlugin::make_visible(bool p_visible) {
-
if (p_visible) {
grid_map_editor->show();
grid_map_editor->spatial_editor_hb->show();
grid_map_editor->set_process(true);
} else {
-
grid_map_editor->spatial_editor_hb->hide();
grid_map_editor->hide();
grid_map_editor->edit(nullptr);
@@ -1554,7 +1488,6 @@ void GridMapEditorPlugin::make_visible(bool p_visible) {
}
GridMapEditorPlugin::GridMapEditorPlugin(EditorNode *p_node) {
-
editor = p_node;
EDITOR_DEF("editors/grid_map/editor_side", 1);