@@ -162,10 +162,11 @@ void GridMapEditor::_menu_option(int p_option) {
162162 }
163163
164164 input_action = INPUT_PASTE;
165- paste_indicator.click = selection.begin ;
166- paste_indicator.current = selection. begin ;
165+ paste_indicator.click = selection.click ;
166+ paste_indicator.current = cursor_gridpos ;
167167 paste_indicator.begin = selection.begin ;
168168 paste_indicator.end = selection.end ;
169+ paste_indicator.distance_from_cursor = cursor_gridpos - paste_indicator.begin ;
169170 paste_indicator.orientation = 0 ;
170171 _update_paste_indicator ();
171172 } break ;
@@ -371,25 +372,24 @@ bool GridMapEditor::do_input_action(Camera3D *p_camera, const Point2 &p_point, b
371372 }
372373 }
373374
374- int cell[3 ];
375375 Vector3 cell_size = node->get_cell_size ();
376376
377377 for (int i = 0 ; i < 3 ; i++) {
378378 if (i == edit_axis) {
379- cell [i] = edit_floor[i];
379+ cursor_gridpos [i] = edit_floor[i];
380380 } else {
381- cell [i] = inters[i] / cell_size[i];
381+ cursor_gridpos [i] = inters[i] / cell_size[i];
382382 if (inters[i] < 0 ) {
383- cell [i] -= 1 ; // Compensate negative.
383+ cursor_gridpos [i] -= 1 ; // Compensate negative.
384384 }
385- grid_ofs[i] = cell [i] * cell_size[i];
385+ grid_ofs[i] = cursor_gridpos [i] * cell_size[i];
386386 }
387387 }
388388
389389 RS::get_singleton ()->instance_set_transform (grid_instance[edit_axis], node->get_global_transform () * edit_grid_xform);
390390
391391 if (cursor_instance.is_valid ()) {
392- 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 ();
392+ cursor_origin = (Vector3 (cursor_gridpos ) + Vector3 (0.5 * node->get_center_x (), 0.5 * node->get_center_y (), 0.5 * node->get_center_z ())) * node->get_cell_size ();
393393 cursor_visible = true ;
394394
395395 if (input_action == INPUT_PASTE) {
@@ -404,11 +404,11 @@ bool GridMapEditor::do_input_action(Camera3D *p_camera, const Point2 &p_point, b
404404 }
405405
406406 if (input_action == INPUT_PASTE) {
407- paste_indicator.current = Vector3i (cell[ 0 ], cell[ 1 ], cell[ 2 ]) ;
407+ paste_indicator.current = cursor_gridpos ;
408408 _update_paste_indicator ();
409409
410410 } else if (input_action == INPUT_SELECT) {
411- selection.current = Vector3i (cell[ 0 ], cell[ 1 ], cell[ 2 ]) ;
411+ selection.current = cursor_gridpos ;
412412 if (p_click) {
413413 selection.click = selection.current ;
414414 }
@@ -417,7 +417,7 @@ bool GridMapEditor::do_input_action(Camera3D *p_camera, const Point2 &p_point, b
417417
418418 return true ;
419419 } else if (input_action == INPUT_PICK) {
420- int item = node->get_cell_item (Vector3i (cell[ 0 ], cell[ 1 ], cell[ 2 ]) );
420+ int item = node->get_cell_item (cursor_gridpos );
421421 if (item >= 0 ) {
422422 selected_palette = item;
423423
@@ -437,23 +437,23 @@ bool GridMapEditor::do_input_action(Camera3D *p_camera, const Point2 &p_point, b
437437
438438 if (input_action == INPUT_PAINT) {
439439 SetItem si;
440- si.position = Vector3i (cell[ 0 ], cell[ 1 ], cell[ 2 ]) ;
440+ si.position = cursor_gridpos ;
441441 si.new_value = selected_palette;
442442 si.new_orientation = cursor_rot;
443- si.old_value = node->get_cell_item (Vector3i (cell[ 0 ], cell[ 1 ], cell[ 2 ]) );
444- si.old_orientation = node->get_cell_item_orientation (Vector3i (cell[ 0 ], cell[ 1 ], cell[ 2 ]) );
443+ si.old_value = node->get_cell_item (cursor_gridpos );
444+ si.old_orientation = node->get_cell_item_orientation (cursor_gridpos );
445445 set_items.push_back (si);
446- node->set_cell_item (Vector3i (cell[ 0 ], cell[ 1 ], cell[ 2 ]) , selected_palette, cursor_rot);
446+ node->set_cell_item (cursor_gridpos , selected_palette, cursor_rot);
447447 return true ;
448448 } else if (input_action == INPUT_ERASE) {
449449 SetItem si;
450- si.position = Vector3i (cell[ 0 ], cell[ 1 ], cell[ 2 ]) ;
450+ si.position = cursor_gridpos ;
451451 si.new_value = -1 ;
452452 si.new_orientation = 0 ;
453- si.old_value = node->get_cell_item (Vector3i (cell[ 0 ], cell[ 1 ], cell[ 2 ]) );
454- si.old_orientation = node->get_cell_item_orientation (Vector3i (cell[ 0 ], cell[ 1 ], cell[ 2 ]) );
453+ si.old_value = node->get_cell_item (cursor_gridpos );
454+ si.old_orientation = node->get_cell_item_orientation (cursor_gridpos );
455455 set_items.push_back (si);
456- node->set_cell_item (Vector3i (cell[ 0 ], cell[ 1 ], cell[ 2 ]) , -1 );
456+ node->set_cell_item (cursor_gridpos , -1 );
457457 return true ;
458458 }
459459
@@ -558,7 +558,7 @@ void GridMapEditor::_update_paste_indicator() {
558558 Vector3 scale = (Vector3 (1 , 1 , 1 ) + (paste_indicator.end - paste_indicator.begin )) * node->get_cell_size ();
559559 Transform3D xf;
560560 xf.scale (scale);
561- xf.origin = (paste_indicator.begin + (paste_indicator. current - paste_indicator.click ) + center) * node->get_cell_size ();
561+ xf.origin = (paste_indicator.current - paste_indicator.distance_from_cursor + center) * node->get_cell_size ();
562562 Basis rot;
563563 rot = node->get_basis_with_orthogonal_index (paste_indicator.orientation );
564564 xf.basis = rot * xf.basis ;
@@ -571,7 +571,7 @@ void GridMapEditor::_update_paste_indicator() {
571571 continue ;
572572 }
573573 xf = Transform3D ();
574- xf.origin = (paste_indicator.begin + (paste_indicator. current - paste_indicator.click ) + center) * node->get_cell_size ();
574+ xf.origin = (paste_indicator.current - paste_indicator.distance_from_cursor + center) * node->get_cell_size ();
575575 xf.basis = rot * xf.basis ;
576576 xf.translate_local (item.grid_offset * node->get_cell_size ());
577577
@@ -590,12 +590,11 @@ void GridMapEditor::_do_paste() {
590590 Basis rot;
591591 rot = node->get_basis_with_orthogonal_index (paste_indicator.orientation );
592592
593- Vector3 ofs = paste_indicator.current - paste_indicator.click ;
594593 EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton ();
595594 undo_redo->create_action (TTR (" GridMap Paste Selection" ));
596595
597596 for (const ClipboardItem &item : clipboard_items) {
598- Vector3 position = rot.xform (item.grid_offset ) + paste_indicator.begin + ofs ;
597+ Vector3 position = rot.xform (item.grid_offset ) + paste_indicator.current - paste_indicator. distance_from_cursor ;
599598
600599 Basis orm;
601600 orm = node->get_basis_with_orthogonal_index (item.orientation );
@@ -607,8 +606,8 @@ void GridMapEditor::_do_paste() {
607606
608607 if (reselect) {
609608 // We need to rotate the paste_indicator to find the selection begin and end:
610- Vector3 temp_end = rot.xform (paste_indicator.end - paste_indicator.begin ) + paste_indicator.begin + ofs ;
611- Vector3 temp_begin = paste_indicator.begin + ofs ;
609+ Vector3 temp_end = rot.xform (paste_indicator.end - paste_indicator.begin ) + paste_indicator.current - paste_indicator. distance_from_cursor ;
610+ Vector3 temp_begin = paste_indicator.current - paste_indicator. distance_from_cursor ;
612611 // _set_selection expects that selection_begin is the corner closer to the origin:
613612 for (int i = 0 ; i < 3 ; ++i) {
614613 if (temp_begin[i] > temp_end[i]) {
0 commit comments