grid_map_editor_plugin.cpp 52 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544
  1. /*************************************************************************/
  2. /* grid_map_editor_plugin.cpp */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /*************************************************************************/
  30. #include "grid_map_editor_plugin.h"
  31. #include "core/os/input.h"
  32. #include "editor/editor_scale.h"
  33. #include "editor/editor_settings.h"
  34. #include "editor/plugins/spatial_editor_plugin.h"
  35. #include "scene/3d/camera.h"
  36. #include "core/math/geometry.h"
  37. #include "core/os/keyboard.h"
  38. void GridMapEditor::_node_removed(Node *p_node) {
  39. if (p_node == node) {
  40. node = nullptr;
  41. }
  42. }
  43. void GridMapEditor::_configure() {
  44. if (!node) {
  45. return;
  46. }
  47. update_grid();
  48. }
  49. void GridMapEditor::_menu_option(int p_option) {
  50. switch (p_option) {
  51. case MENU_OPTION_PREV_LEVEL: {
  52. floor->set_value(floor->get_value() - 1);
  53. } break;
  54. case MENU_OPTION_NEXT_LEVEL: {
  55. floor->set_value(floor->get_value() + 1);
  56. } break;
  57. case MENU_OPTION_LOCK_VIEW: {
  58. int index = options->get_popup()->get_item_index(MENU_OPTION_LOCK_VIEW);
  59. lock_view = !options->get_popup()->is_item_checked(index);
  60. options->get_popup()->set_item_checked(index, lock_view);
  61. } break;
  62. case MENU_OPTION_CLIP_DISABLED:
  63. case MENU_OPTION_CLIP_ABOVE:
  64. case MENU_OPTION_CLIP_BELOW: {
  65. clip_mode = ClipMode(p_option - MENU_OPTION_CLIP_DISABLED);
  66. for (int i = 0; i < 3; i++) {
  67. int index = options->get_popup()->get_item_index(MENU_OPTION_CLIP_DISABLED + i);
  68. options->get_popup()->set_item_checked(index, i == clip_mode);
  69. }
  70. _update_clip();
  71. } break;
  72. case MENU_OPTION_X_AXIS:
  73. case MENU_OPTION_Y_AXIS:
  74. case MENU_OPTION_Z_AXIS: {
  75. int new_axis = p_option - MENU_OPTION_X_AXIS;
  76. for (int i = 0; i < 3; i++) {
  77. int idx = options->get_popup()->get_item_index(MENU_OPTION_X_AXIS + i);
  78. options->get_popup()->set_item_checked(idx, i == new_axis);
  79. }
  80. if (edit_axis != new_axis) {
  81. int item1 = options->get_popup()->get_item_index(MENU_OPTION_NEXT_LEVEL);
  82. int item2 = options->get_popup()->get_item_index(MENU_OPTION_PREV_LEVEL);
  83. if (edit_axis == Vector3::AXIS_Y) {
  84. options->get_popup()->set_item_text(item1, TTR("Next Plane"));
  85. options->get_popup()->set_item_text(item2, TTR("Previous Plane"));
  86. spin_box_label->set_text(TTR("Plane:"));
  87. } else if (new_axis == Vector3::AXIS_Y) {
  88. options->get_popup()->set_item_text(item1, TTR("Next Floor"));
  89. options->get_popup()->set_item_text(item2, TTR("Previous Floor"));
  90. spin_box_label->set_text(TTR("Floor:"));
  91. }
  92. }
  93. edit_axis = Vector3::Axis(new_axis);
  94. update_grid();
  95. _update_clip();
  96. } break;
  97. case MENU_OPTION_CURSOR_ROTATE_Y: {
  98. Basis r;
  99. if (input_action == INPUT_PASTE) {
  100. r.set_orthogonal_index(paste_indicator.orientation);
  101. r.rotate(Vector3(0, 1, 0), -Math_PI / 2.0);
  102. paste_indicator.orientation = r.get_orthogonal_index();
  103. _update_paste_indicator();
  104. break;
  105. }
  106. r.set_orthogonal_index(cursor_rot);
  107. r.rotate(Vector3(0, 1, 0), -Math_PI / 2.0);
  108. cursor_rot = r.get_orthogonal_index();
  109. _update_cursor_transform();
  110. } break;
  111. case MENU_OPTION_CURSOR_ROTATE_X: {
  112. Basis r;
  113. if (input_action == INPUT_PASTE) {
  114. r.set_orthogonal_index(paste_indicator.orientation);
  115. r.rotate(Vector3(1, 0, 0), -Math_PI / 2.0);
  116. paste_indicator.orientation = r.get_orthogonal_index();
  117. _update_paste_indicator();
  118. break;
  119. }
  120. r.set_orthogonal_index(cursor_rot);
  121. r.rotate(Vector3(1, 0, 0), -Math_PI / 2.0);
  122. cursor_rot = r.get_orthogonal_index();
  123. _update_cursor_transform();
  124. } break;
  125. case MENU_OPTION_CURSOR_ROTATE_Z: {
  126. Basis r;
  127. if (input_action == INPUT_PASTE) {
  128. r.set_orthogonal_index(paste_indicator.orientation);
  129. r.rotate(Vector3(0, 0, 1), -Math_PI / 2.0);
  130. paste_indicator.orientation = r.get_orthogonal_index();
  131. _update_paste_indicator();
  132. break;
  133. }
  134. r.set_orthogonal_index(cursor_rot);
  135. r.rotate(Vector3(0, 0, 1), -Math_PI / 2.0);
  136. cursor_rot = r.get_orthogonal_index();
  137. _update_cursor_transform();
  138. } break;
  139. case MENU_OPTION_CURSOR_BACK_ROTATE_Y: {
  140. Basis r;
  141. if (input_action == INPUT_PASTE) {
  142. r.set_orthogonal_index(paste_indicator.orientation);
  143. r.rotate(Vector3(0, 1, 0), Math_PI / 2.0);
  144. paste_indicator.orientation = r.get_orthogonal_index();
  145. _update_paste_indicator();
  146. break;
  147. }
  148. r.set_orthogonal_index(cursor_rot);
  149. r.rotate(Vector3(0, 1, 0), Math_PI / 2.0);
  150. cursor_rot = r.get_orthogonal_index();
  151. _update_cursor_transform();
  152. } break;
  153. case MENU_OPTION_CURSOR_BACK_ROTATE_X: {
  154. Basis r;
  155. if (input_action == INPUT_PASTE) {
  156. r.set_orthogonal_index(paste_indicator.orientation);
  157. r.rotate(Vector3(1, 0, 0), Math_PI / 2.0);
  158. paste_indicator.orientation = r.get_orthogonal_index();
  159. _update_paste_indicator();
  160. break;
  161. }
  162. r.set_orthogonal_index(cursor_rot);
  163. r.rotate(Vector3(1, 0, 0), Math_PI / 2.0);
  164. cursor_rot = r.get_orthogonal_index();
  165. _update_cursor_transform();
  166. } break;
  167. case MENU_OPTION_CURSOR_BACK_ROTATE_Z: {
  168. Basis r;
  169. if (input_action == INPUT_PASTE) {
  170. r.set_orthogonal_index(paste_indicator.orientation);
  171. r.rotate(Vector3(0, 0, 1), Math_PI / 2.0);
  172. paste_indicator.orientation = r.get_orthogonal_index();
  173. _update_paste_indicator();
  174. break;
  175. }
  176. r.set_orthogonal_index(cursor_rot);
  177. r.rotate(Vector3(0, 0, 1), Math_PI / 2.0);
  178. cursor_rot = r.get_orthogonal_index();
  179. _update_cursor_transform();
  180. } break;
  181. case MENU_OPTION_CURSOR_CLEAR_ROTATION: {
  182. if (input_action == INPUT_PASTE) {
  183. paste_indicator.orientation = 0;
  184. _update_paste_indicator();
  185. break;
  186. }
  187. cursor_rot = 0;
  188. _update_cursor_transform();
  189. } break;
  190. case MENU_OPTION_PASTE_SELECTS: {
  191. int idx = options->get_popup()->get_item_index(MENU_OPTION_PASTE_SELECTS);
  192. options->get_popup()->set_item_checked(idx, !options->get_popup()->is_item_checked(idx));
  193. } break;
  194. case MENU_OPTION_SELECTION_DUPLICATE:
  195. case MENU_OPTION_SELECTION_CUT: {
  196. if (!(selection.active && input_action == INPUT_NONE)) {
  197. break;
  198. }
  199. _set_clipboard_data();
  200. if (p_option == MENU_OPTION_SELECTION_CUT) {
  201. _delete_selection();
  202. }
  203. input_action = INPUT_PASTE;
  204. paste_indicator.click = selection.begin;
  205. paste_indicator.current = selection.begin;
  206. paste_indicator.begin = selection.begin;
  207. paste_indicator.end = selection.end;
  208. paste_indicator.orientation = 0;
  209. _update_paste_indicator();
  210. } break;
  211. case MENU_OPTION_SELECTION_CLEAR: {
  212. if (!selection.active) {
  213. break;
  214. }
  215. _delete_selection();
  216. } break;
  217. case MENU_OPTION_SELECTION_FILL: {
  218. if (!selection.active) {
  219. return;
  220. }
  221. _fill_selection();
  222. } break;
  223. case MENU_OPTION_GRIDMAP_SETTINGS: {
  224. settings_dialog->popup_centered(settings_vbc->get_combined_minimum_size() + Size2(50, 50) * EDSCALE);
  225. } break;
  226. }
  227. }
  228. void GridMapEditor::_update_cursor_transform() {
  229. cursor_transform = Transform();
  230. cursor_transform.origin = cursor_origin;
  231. cursor_transform.basis.set_orthogonal_index(cursor_rot);
  232. cursor_transform.basis *= node->get_cell_scale();
  233. cursor_transform = node->get_global_transform() * cursor_transform;
  234. if (selected_palette >= 0) {
  235. if (node && !node->get_mesh_library().is_null()) {
  236. cursor_transform *= node->get_mesh_library()->get_item_mesh_transform(selected_palette);
  237. }
  238. }
  239. if (cursor_instance.is_valid()) {
  240. VisualServer::get_singleton()->instance_set_transform(cursor_instance, cursor_transform);
  241. VisualServer::get_singleton()->instance_set_visible(cursor_instance, cursor_visible);
  242. }
  243. }
  244. void GridMapEditor::_update_selection_transform() {
  245. Transform xf_zero;
  246. xf_zero.basis.set_zero();
  247. if (!selection.active) {
  248. VisualServer::get_singleton()->instance_set_transform(selection_instance, xf_zero);
  249. for (int i = 0; i < 3; i++) {
  250. VisualServer::get_singleton()->instance_set_transform(selection_level_instance[i], xf_zero);
  251. }
  252. return;
  253. }
  254. Transform xf;
  255. xf.scale((Vector3(1, 1, 1) + (selection.end - selection.begin)) * node->get_cell_size());
  256. xf.origin = selection.begin * node->get_cell_size();
  257. VisualServer::get_singleton()->instance_set_transform(selection_instance, node->get_global_transform() * xf);
  258. for (int i = 0; i < 3; i++) {
  259. if (i != edit_axis || (edit_floor[edit_axis] < selection.begin[edit_axis]) || (edit_floor[edit_axis] > selection.end[edit_axis] + 1)) {
  260. VisualServer::get_singleton()->instance_set_transform(selection_level_instance[i], xf_zero);
  261. } else {
  262. Vector3 scale = (selection.end - selection.begin + Vector3(1, 1, 1));
  263. scale[edit_axis] = 1.0;
  264. Vector3 pos = selection.begin;
  265. pos[edit_axis] = edit_floor[edit_axis];
  266. scale *= node->get_cell_size();
  267. pos *= node->get_cell_size();
  268. Transform xf2;
  269. xf2.basis.scale(scale);
  270. xf2.origin = pos;
  271. VisualServer::get_singleton()->instance_set_transform(selection_level_instance[i], xf2);
  272. }
  273. }
  274. }
  275. void GridMapEditor::_validate_selection() {
  276. if (!selection.active) {
  277. return;
  278. }
  279. selection.begin = selection.click;
  280. selection.end = selection.current;
  281. if (selection.begin.x > selection.end.x) {
  282. SWAP(selection.begin.x, selection.end.x);
  283. }
  284. if (selection.begin.y > selection.end.y) {
  285. SWAP(selection.begin.y, selection.end.y);
  286. }
  287. if (selection.begin.z > selection.end.z) {
  288. SWAP(selection.begin.z, selection.end.z);
  289. }
  290. _update_selection_transform();
  291. }
  292. void GridMapEditor::_set_selection(bool p_active, const Vector3 &p_begin, const Vector3 &p_end) {
  293. selection.active = p_active;
  294. selection.begin = p_begin;
  295. selection.end = p_end;
  296. selection.click = p_begin;
  297. selection.current = p_end;
  298. if (is_visible_in_tree()) {
  299. _update_selection_transform();
  300. }
  301. options->get_popup()->set_item_disabled(options->get_popup()->get_item_index(MENU_OPTION_SELECTION_CLEAR), !selection.active);
  302. options->get_popup()->set_item_disabled(options->get_popup()->get_item_index(MENU_OPTION_SELECTION_CUT), !selection.active);
  303. options->get_popup()->set_item_disabled(options->get_popup()->get_item_index(MENU_OPTION_SELECTION_DUPLICATE), !selection.active);
  304. options->get_popup()->set_item_disabled(options->get_popup()->get_item_index(MENU_OPTION_SELECTION_FILL), !selection.active);
  305. }
  306. bool GridMapEditor::do_input_action(Camera *p_camera, const Point2 &p_point, bool p_click) {
  307. if (!spatial_editor) {
  308. return false;
  309. }
  310. if (selected_palette < 0 && input_action != INPUT_PICK && input_action != INPUT_SELECT && input_action != INPUT_PASTE) {
  311. return false;
  312. }
  313. Ref<MeshLibrary> mesh_library = node->get_mesh_library();
  314. if (mesh_library.is_null()) {
  315. return false;
  316. }
  317. if (input_action != INPUT_PICK && input_action != INPUT_SELECT && input_action != INPUT_PASTE && !mesh_library->has_item(selected_palette)) {
  318. return false;
  319. }
  320. Camera *camera = p_camera;
  321. Vector3 from = camera->project_ray_origin(p_point);
  322. Vector3 normal = camera->project_ray_normal(p_point);
  323. Transform local_xform = node->get_global_transform().affine_inverse();
  324. Vector<Plane> planes = camera->get_frustum();
  325. from = local_xform.xform(from);
  326. normal = local_xform.basis.xform(normal).normalized();
  327. Plane p;
  328. p.normal[edit_axis] = 1.0;
  329. p.d = edit_floor[edit_axis] * node->get_cell_size()[edit_axis];
  330. Vector3 inters;
  331. if (!p.intersects_segment(from, from + normal * settings_pick_distance->get_value(), &inters)) {
  332. return false;
  333. }
  334. // Make sure the intersection is inside the frustum planes, to avoid
  335. // Painting on invisible regions.
  336. for (int i = 0; i < planes.size(); i++) {
  337. Plane fp = local_xform.xform(planes[i]);
  338. if (fp.is_point_over(inters)) {
  339. return false;
  340. }
  341. }
  342. int cell[3];
  343. float cell_size[3] = { node->get_cell_size().x, node->get_cell_size().y, node->get_cell_size().z };
  344. for (int i = 0; i < 3; i++) {
  345. if (i == edit_axis) {
  346. cell[i] = edit_floor[i];
  347. } else {
  348. cell[i] = inters[i] / node->get_cell_size()[i];
  349. if (inters[i] < 0) {
  350. cell[i] -= 1; // Compensate negative.
  351. }
  352. grid_ofs[i] = cell[i] * cell_size[i];
  353. }
  354. }
  355. VS::get_singleton()->instance_set_transform(grid_instance[edit_axis], node->get_global_transform() * edit_grid_xform);
  356. if (cursor_instance.is_valid()) {
  357. 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();
  358. cursor_visible = true;
  359. if (input_action == INPUT_SELECT || input_action == INPUT_PASTE) {
  360. cursor_visible = false;
  361. }
  362. _update_cursor_transform();
  363. }
  364. if (input_action == INPUT_PASTE) {
  365. paste_indicator.current = Vector3(cell[0], cell[1], cell[2]);
  366. _update_paste_indicator();
  367. } else if (input_action == INPUT_SELECT) {
  368. selection.current = Vector3(cell[0], cell[1], cell[2]);
  369. if (p_click) {
  370. selection.click = selection.current;
  371. }
  372. selection.active = true;
  373. _validate_selection();
  374. return true;
  375. } else if (input_action == INPUT_PICK) {
  376. int item = node->get_cell_item(cell[0], cell[1], cell[2]);
  377. if (item >= 0) {
  378. selected_palette = item;
  379. mesh_library_palette->set_current(item);
  380. update_palette();
  381. _update_cursor_instance();
  382. }
  383. return true;
  384. }
  385. if (input_action == INPUT_PAINT) {
  386. SetItem si;
  387. si.pos = Vector3(cell[0], cell[1], cell[2]);
  388. si.new_value = selected_palette;
  389. si.new_orientation = cursor_rot;
  390. si.old_value = node->get_cell_item(cell[0], cell[1], cell[2]);
  391. si.old_orientation = node->get_cell_item_orientation(cell[0], cell[1], cell[2]);
  392. set_items.push_back(si);
  393. node->set_cell_item(cell[0], cell[1], cell[2], selected_palette, cursor_rot);
  394. return true;
  395. } else if (input_action == INPUT_ERASE) {
  396. SetItem si;
  397. si.pos = Vector3(cell[0], cell[1], cell[2]);
  398. si.new_value = -1;
  399. si.new_orientation = 0;
  400. si.old_value = node->get_cell_item(cell[0], cell[1], cell[2]);
  401. si.old_orientation = node->get_cell_item_orientation(cell[0], cell[1], cell[2]);
  402. set_items.push_back(si);
  403. node->set_cell_item(cell[0], cell[1], cell[2], -1);
  404. return true;
  405. }
  406. return false;
  407. }
  408. void GridMapEditor::_delete_selection() {
  409. if (!selection.active) {
  410. return;
  411. }
  412. undo_redo->create_action(TTR("GridMap Delete Selection"));
  413. for (int i = selection.begin.x; i <= selection.end.x; i++) {
  414. for (int j = selection.begin.y; j <= selection.end.y; j++) {
  415. for (int k = selection.begin.z; k <= selection.end.z; k++) {
  416. undo_redo->add_do_method(node, "set_cell_item", i, j, k, GridMap::INVALID_CELL_ITEM);
  417. 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));
  418. }
  419. }
  420. }
  421. undo_redo->add_do_method(this, "_set_selection", !selection.active, selection.begin, selection.end);
  422. undo_redo->add_undo_method(this, "_set_selection", selection.active, selection.begin, selection.end);
  423. undo_redo->commit_action();
  424. }
  425. void GridMapEditor::_fill_selection() {
  426. if (!selection.active) {
  427. return;
  428. }
  429. undo_redo->create_action(TTR("GridMap Fill Selection"));
  430. for (int i = selection.begin.x; i <= selection.end.x; i++) {
  431. for (int j = selection.begin.y; j <= selection.end.y; j++) {
  432. for (int k = selection.begin.z; k <= selection.end.z; k++) {
  433. undo_redo->add_do_method(node, "set_cell_item", i, j, k, selected_palette, cursor_rot);
  434. 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));
  435. }
  436. }
  437. }
  438. undo_redo->add_do_method(this, "_set_selection", !selection.active, selection.begin, selection.end);
  439. undo_redo->add_undo_method(this, "_set_selection", selection.active, selection.begin, selection.end);
  440. undo_redo->commit_action();
  441. }
  442. void GridMapEditor::_clear_clipboard_data() {
  443. for (List<ClipboardItem>::Element *E = clipboard_items.front(); E; E = E->next()) {
  444. VisualServer::get_singleton()->free(E->get().instance);
  445. }
  446. clipboard_items.clear();
  447. }
  448. void GridMapEditor::_set_clipboard_data() {
  449. _clear_clipboard_data();
  450. Ref<MeshLibrary> meshLibrary = node->get_mesh_library();
  451. for (int i = selection.begin.x; i <= selection.end.x; i++) {
  452. for (int j = selection.begin.y; j <= selection.end.y; j++) {
  453. for (int k = selection.begin.z; k <= selection.end.z; k++) {
  454. int itm = node->get_cell_item(i, j, k);
  455. if (itm == GridMap::INVALID_CELL_ITEM) {
  456. continue;
  457. }
  458. Ref<Mesh> mesh = meshLibrary->get_item_mesh(itm);
  459. ClipboardItem item;
  460. item.cell_item = itm;
  461. item.grid_offset = Vector3(i, j, k) - selection.begin;
  462. item.orientation = node->get_cell_item_orientation(i, j, k);
  463. item.instance = VisualServer::get_singleton()->instance_create2(mesh->get_rid(), get_tree()->get_root()->get_world()->get_scenario());
  464. clipboard_items.push_back(item);
  465. }
  466. }
  467. }
  468. }
  469. void GridMapEditor::_update_paste_indicator() {
  470. if (input_action != INPUT_PASTE) {
  471. Transform xf;
  472. xf.basis.set_zero();
  473. VisualServer::get_singleton()->instance_set_transform(paste_instance, xf);
  474. return;
  475. }
  476. Vector3 center = 0.5 * Vector3(float(node->get_center_x()), float(node->get_center_y()), float(node->get_center_z()));
  477. Vector3 scale = (Vector3(1, 1, 1) + (paste_indicator.end - paste_indicator.begin)) * node->get_cell_size();
  478. Transform xf;
  479. xf.scale(scale);
  480. xf.origin = (paste_indicator.begin + (paste_indicator.current - paste_indicator.click) + center) * node->get_cell_size();
  481. Basis rot;
  482. rot.set_orthogonal_index(paste_indicator.orientation);
  483. xf.basis = rot * xf.basis;
  484. xf.translate((-center * node->get_cell_size()) / scale);
  485. VisualServer::get_singleton()->instance_set_transform(paste_instance, node->get_global_transform() * xf);
  486. for (List<ClipboardItem>::Element *E = clipboard_items.front(); E; E = E->next()) {
  487. ClipboardItem &item = E->get();
  488. xf = Transform();
  489. xf.origin = (paste_indicator.begin + (paste_indicator.current - paste_indicator.click) + center) * node->get_cell_size();
  490. xf.basis = rot * xf.basis;
  491. xf.translate(item.grid_offset * node->get_cell_size());
  492. Basis item_rot;
  493. item_rot.set_orthogonal_index(item.orientation);
  494. xf.basis = item_rot * xf.basis * node->get_cell_scale();
  495. VisualServer::get_singleton()->instance_set_transform(item.instance, node->get_global_transform() * xf);
  496. }
  497. }
  498. void GridMapEditor::_do_paste() {
  499. int idx = options->get_popup()->get_item_index(MENU_OPTION_PASTE_SELECTS);
  500. bool reselect = options->get_popup()->is_item_checked(idx);
  501. Basis rot;
  502. rot.set_orthogonal_index(paste_indicator.orientation);
  503. Vector3 ofs = paste_indicator.current - paste_indicator.click;
  504. undo_redo->create_action(TTR("GridMap Paste Selection"));
  505. for (List<ClipboardItem>::Element *E = clipboard_items.front(); E; E = E->next()) {
  506. ClipboardItem &item = E->get();
  507. Vector3 pos = rot.xform(item.grid_offset) + paste_indicator.begin + ofs;
  508. Basis orm;
  509. orm.set_orthogonal_index(item.orientation);
  510. orm = rot * orm;
  511. undo_redo->add_do_method(node, "set_cell_item", pos.x, pos.y, pos.z, item.cell_item, orm.get_orthogonal_index());
  512. undo_redo->add_undo_method(node, "set_cell_item", pos.x, pos.y, pos.z, node->get_cell_item(pos.x, pos.y, pos.z), node->get_cell_item_orientation(pos.x, pos.y, pos.z));
  513. }
  514. if (reselect) {
  515. undo_redo->add_do_method(this, "_set_selection", true, paste_indicator.begin + ofs, paste_indicator.end + ofs);
  516. undo_redo->add_undo_method(this, "_set_selection", selection.active, selection.begin, selection.end);
  517. }
  518. undo_redo->commit_action();
  519. _clear_clipboard_data();
  520. }
  521. bool GridMapEditor::forward_spatial_input_event(Camera *p_camera, const Ref<InputEvent> &p_event) {
  522. if (!node) {
  523. return false;
  524. }
  525. Ref<InputEventMouseButton> mb = p_event;
  526. if (mb.is_valid()) {
  527. if (mb->get_button_index() == BUTTON_WHEEL_UP && (mb->get_command() || mb->get_shift())) {
  528. if (mb->is_pressed()) {
  529. floor->set_value(floor->get_value() + mb->get_factor());
  530. }
  531. return true; // Eaten.
  532. } else if (mb->get_button_index() == BUTTON_WHEEL_DOWN && (mb->get_command() || mb->get_shift())) {
  533. if (mb->is_pressed()) {
  534. floor->set_value(floor->get_value() - mb->get_factor());
  535. }
  536. return true;
  537. }
  538. if (mb->is_pressed()) {
  539. SpatialEditorViewport::NavigationScheme nav_scheme = (SpatialEditorViewport::NavigationScheme)EditorSettings::get_singleton()->get("editors/3d/navigation/navigation_scheme").operator int();
  540. if ((nav_scheme == SpatialEditorViewport::NAVIGATION_MAYA || nav_scheme == SpatialEditorViewport::NAVIGATION_MODO) && mb->get_alt()) {
  541. input_action = INPUT_NONE;
  542. } else if (mb->get_button_index() == BUTTON_LEFT) {
  543. bool can_edit = (node && node->get_mesh_library().is_valid());
  544. if (input_action == INPUT_PASTE) {
  545. _do_paste();
  546. input_action = INPUT_NONE;
  547. _update_paste_indicator();
  548. } else if (mb->get_shift() && can_edit) {
  549. input_action = INPUT_SELECT;
  550. last_selection = selection;
  551. } else if (mb->get_command() && can_edit) {
  552. input_action = INPUT_PICK;
  553. } else {
  554. input_action = INPUT_PAINT;
  555. set_items.clear();
  556. }
  557. } else if (mb->get_button_index() == BUTTON_RIGHT) {
  558. if (input_action == INPUT_PASTE) {
  559. _clear_clipboard_data();
  560. input_action = INPUT_NONE;
  561. _update_paste_indicator();
  562. return true;
  563. } else if (selection.active) {
  564. _set_selection(false);
  565. return true;
  566. } else {
  567. input_action = INPUT_ERASE;
  568. set_items.clear();
  569. }
  570. } else {
  571. return false;
  572. }
  573. return do_input_action(p_camera, Point2(mb->get_position().x, mb->get_position().y), true);
  574. } else {
  575. if ((mb->get_button_index() == BUTTON_RIGHT && input_action == INPUT_ERASE) || (mb->get_button_index() == BUTTON_LEFT && input_action == INPUT_PAINT)) {
  576. if (set_items.size()) {
  577. undo_redo->create_action(TTR("GridMap Paint"));
  578. for (List<SetItem>::Element *E = set_items.front(); E; E = E->next()) {
  579. const SetItem &si = E->get();
  580. undo_redo->add_do_method(node, "set_cell_item", si.pos.x, si.pos.y, si.pos.z, si.new_value, si.new_orientation);
  581. }
  582. for (List<SetItem>::Element *E = set_items.back(); E; E = E->prev()) {
  583. const SetItem &si = E->get();
  584. undo_redo->add_undo_method(node, "set_cell_item", si.pos.x, si.pos.y, si.pos.z, si.old_value, si.old_orientation);
  585. }
  586. undo_redo->commit_action();
  587. }
  588. set_items.clear();
  589. input_action = INPUT_NONE;
  590. return set_items.size() > 0;
  591. }
  592. if (mb->get_button_index() == BUTTON_LEFT && input_action == INPUT_SELECT) {
  593. undo_redo->create_action(TTR("GridMap Selection"));
  594. undo_redo->add_do_method(this, "_set_selection", selection.active, selection.begin, selection.end);
  595. undo_redo->add_undo_method(this, "_set_selection", last_selection.active, last_selection.begin, last_selection.end);
  596. undo_redo->commit_action();
  597. }
  598. if (mb->get_button_index() == BUTTON_LEFT && input_action != INPUT_NONE) {
  599. set_items.clear();
  600. input_action = INPUT_NONE;
  601. return true;
  602. }
  603. if (mb->get_button_index() == BUTTON_RIGHT && (input_action == INPUT_ERASE || input_action == INPUT_PASTE)) {
  604. input_action = INPUT_NONE;
  605. return true;
  606. }
  607. }
  608. }
  609. Ref<InputEventMouseMotion> mm = p_event;
  610. if (mm.is_valid()) {
  611. return do_input_action(p_camera, mm->get_position(), false);
  612. }
  613. Ref<InputEventKey> k = p_event;
  614. if (k.is_valid()) {
  615. if (k->is_pressed()) {
  616. if (k->get_scancode() == KEY_ESCAPE) {
  617. if (input_action == INPUT_PASTE) {
  618. _clear_clipboard_data();
  619. input_action = INPUT_NONE;
  620. _update_paste_indicator();
  621. return true;
  622. } else if (selection.active) {
  623. _set_selection(false);
  624. return true;
  625. } else {
  626. selected_palette = -1;
  627. mesh_library_palette->unselect_all();
  628. update_palette();
  629. _update_cursor_instance();
  630. return true;
  631. }
  632. }
  633. if (k->get_shift() && selection.active && input_action != INPUT_PASTE) {
  634. if (k->get_scancode() == options->get_popup()->get_item_accelerator(options->get_popup()->get_item_index(MENU_OPTION_PREV_LEVEL))) {
  635. selection.click[edit_axis]--;
  636. _validate_selection();
  637. return true;
  638. }
  639. if (k->get_scancode() == options->get_popup()->get_item_accelerator(options->get_popup()->get_item_index(MENU_OPTION_NEXT_LEVEL))) {
  640. selection.click[edit_axis]++;
  641. _validate_selection();
  642. return true;
  643. }
  644. }
  645. }
  646. }
  647. Ref<InputEventPanGesture> pan_gesture = p_event;
  648. if (pan_gesture.is_valid()) {
  649. if (pan_gesture->get_alt() && (pan_gesture->get_command() || pan_gesture->get_shift())) {
  650. const real_t delta = pan_gesture->get_delta().y * 0.5;
  651. accumulated_floor_delta += delta;
  652. int step = 0;
  653. if (ABS(accumulated_floor_delta) > 1.0) {
  654. step = SGN(accumulated_floor_delta);
  655. accumulated_floor_delta -= step;
  656. }
  657. if (step) {
  658. floor->set_value(floor->get_value() + step);
  659. }
  660. return true;
  661. }
  662. }
  663. accumulated_floor_delta = 0.0;
  664. return false;
  665. }
  666. struct _CGMEItemSort {
  667. String name;
  668. int id;
  669. _FORCE_INLINE_ bool operator<(const _CGMEItemSort &r_it) const { return name < r_it.name; }
  670. };
  671. void GridMapEditor::_set_display_mode(int p_mode) {
  672. if (display_mode == p_mode) {
  673. return;
  674. }
  675. if (p_mode == DISPLAY_LIST) {
  676. mode_list->set_pressed(true);
  677. mode_thumbnail->set_pressed(false);
  678. } else if (p_mode == DISPLAY_THUMBNAIL) {
  679. mode_list->set_pressed(false);
  680. mode_thumbnail->set_pressed(true);
  681. }
  682. display_mode = p_mode;
  683. update_palette();
  684. }
  685. void GridMapEditor::_text_changed(const String &p_text) {
  686. update_palette();
  687. }
  688. void GridMapEditor::_sbox_input(const Ref<InputEvent> &p_ie) {
  689. const Ref<InputEventKey> k = p_ie;
  690. if (k.is_valid() && (k->get_scancode() == KEY_UP || k->get_scancode() == KEY_DOWN || k->get_scancode() == KEY_PAGEUP || k->get_scancode() == KEY_PAGEDOWN)) {
  691. // Forward the key input to the ItemList so it can be scrolled
  692. mesh_library_palette->call("_gui_input", k);
  693. search_box->accept_event();
  694. }
  695. }
  696. void GridMapEditor::_mesh_library_palette_input(const Ref<InputEvent> &p_ie) {
  697. const Ref<InputEventMouseButton> mb = p_ie;
  698. // Zoom in/out using Ctrl + mouse wheel
  699. if (mb.is_valid() && mb->is_pressed() && mb->get_command()) {
  700. if (mb->is_pressed() && mb->get_button_index() == BUTTON_WHEEL_UP) {
  701. size_slider->set_value(size_slider->get_value() + 0.2);
  702. }
  703. if (mb->is_pressed() && mb->get_button_index() == BUTTON_WHEEL_DOWN) {
  704. size_slider->set_value(size_slider->get_value() - 0.2);
  705. }
  706. }
  707. }
  708. void GridMapEditor::_icon_size_changed(float p_value) {
  709. mesh_library_palette->set_icon_scale(p_value);
  710. update_palette();
  711. }
  712. void GridMapEditor::update_palette() {
  713. int selected = mesh_library_palette->get_current();
  714. float min_size = EDITOR_DEF("editors/grid_map/preview_size", 64);
  715. min_size *= EDSCALE;
  716. mesh_library_palette->clear();
  717. if (display_mode == DISPLAY_THUMBNAIL) {
  718. mesh_library_palette->set_max_columns(0);
  719. mesh_library_palette->set_icon_mode(ItemList::ICON_MODE_TOP);
  720. mesh_library_palette->set_fixed_column_width(min_size * MAX(size_slider->get_value(), 1.5));
  721. } else if (display_mode == DISPLAY_LIST) {
  722. mesh_library_palette->set_max_columns(1);
  723. mesh_library_palette->set_icon_mode(ItemList::ICON_MODE_LEFT);
  724. mesh_library_palette->set_fixed_column_width(0);
  725. }
  726. mesh_library_palette->set_fixed_icon_size(Size2(min_size, min_size));
  727. mesh_library_palette->set_max_text_lines(2);
  728. Ref<MeshLibrary> mesh_library = node->get_mesh_library();
  729. if (mesh_library.is_null()) {
  730. last_mesh_library = nullptr;
  731. search_box->set_text("");
  732. search_box->set_editable(false);
  733. info_message->show();
  734. return;
  735. }
  736. search_box->set_editable(true);
  737. info_message->hide();
  738. Vector<int> ids;
  739. ids = mesh_library->get_item_list();
  740. List<_CGMEItemSort> il;
  741. for (int i = 0; i < ids.size(); i++) {
  742. _CGMEItemSort is;
  743. is.id = ids[i];
  744. is.name = mesh_library->get_item_name(ids[i]);
  745. il.push_back(is);
  746. }
  747. il.sort();
  748. String filter = search_box->get_text().strip_edges();
  749. int item = 0;
  750. for (List<_CGMEItemSort>::Element *E = il.front(); E; E = E->next()) {
  751. int id = E->get().id;
  752. String name = mesh_library->get_item_name(id);
  753. Ref<Texture> preview = mesh_library->get_item_preview(id);
  754. if (name == "") {
  755. name = "#" + itos(id);
  756. }
  757. if (filter != "" && !filter.is_subsequence_ofi(name)) {
  758. continue;
  759. }
  760. mesh_library_palette->add_item("");
  761. if (!preview.is_null()) {
  762. mesh_library_palette->set_item_icon(item, preview);
  763. mesh_library_palette->set_item_tooltip(item, name);
  764. }
  765. mesh_library_palette->set_item_text(item, name);
  766. mesh_library_palette->set_item_metadata(item, id);
  767. item++;
  768. }
  769. if (selected != -1 && mesh_library_palette->get_item_count() > 0) {
  770. mesh_library_palette->select(selected);
  771. }
  772. last_mesh_library = mesh_library.operator->();
  773. }
  774. void GridMapEditor::edit(GridMap *p_gridmap) {
  775. if (!p_gridmap && node) {
  776. node->disconnect("cell_size_changed", this, "_draw_grids");
  777. }
  778. node = p_gridmap;
  779. input_action = INPUT_NONE;
  780. selection.active = false;
  781. _update_selection_transform();
  782. _update_paste_indicator();
  783. spatial_editor = Object::cast_to<SpatialEditorPlugin>(editor->get_editor_plugin_screen());
  784. if (!node) {
  785. set_process(false);
  786. for (int i = 0; i < 3; i++) {
  787. VisualServer::get_singleton()->instance_set_visible(grid_instance[i], false);
  788. }
  789. if (cursor_instance.is_valid()) {
  790. VisualServer::get_singleton()->instance_set_visible(cursor_instance, false);
  791. }
  792. return;
  793. }
  794. update_palette();
  795. set_process(true);
  796. clip_mode = p_gridmap->has_meta("_editor_clip_") ? ClipMode(p_gridmap->get_meta("_editor_clip_").operator int()) : CLIP_DISABLED;
  797. _draw_grids(node->get_cell_size());
  798. update_grid();
  799. _update_clip();
  800. node->connect("cell_size_changed", this, "_draw_grids");
  801. }
  802. void GridMapEditor::_update_clip() {
  803. node->set_meta("_editor_clip_", clip_mode);
  804. if (clip_mode == CLIP_DISABLED) {
  805. node->set_clip(false);
  806. } else {
  807. node->set_clip(true, clip_mode == CLIP_ABOVE, edit_floor[edit_axis], edit_axis);
  808. }
  809. }
  810. void GridMapEditor::update_grid() {
  811. grid_xform.origin.x -= 1; // Force update in hackish way.
  812. grid_ofs[edit_axis] = edit_floor[edit_axis] * node->get_cell_size()[edit_axis];
  813. edit_grid_xform.origin = grid_ofs;
  814. edit_grid_xform.basis = Basis();
  815. for (int i = 0; i < 3; i++) {
  816. VisualServer::get_singleton()->instance_set_visible(grid_instance[i], i == edit_axis);
  817. }
  818. updating = true;
  819. floor->set_value(edit_floor[edit_axis]);
  820. updating = false;
  821. }
  822. void GridMapEditor::_draw_grids(const Vector3 &cell_size) {
  823. Vector3 edited_floor = node->has_meta("_editor_floor_") ? node->get_meta("_editor_floor_") : Variant();
  824. for (int i = 0; i < 3; i++) {
  825. if (VS::get_singleton()->mesh_get_surface_count(grid[i]) > 0) {
  826. VS::get_singleton()->mesh_remove_surface(grid[i], 0);
  827. }
  828. edit_floor[i] = edited_floor[i];
  829. }
  830. Vector<Vector3> grid_points[3];
  831. Vector<Color> grid_colors[3];
  832. for (int i = 0; i < 3; i++) {
  833. Vector3 axis;
  834. axis[i] = 1;
  835. Vector3 axis_n1;
  836. axis_n1[(i + 1) % 3] = cell_size[(i + 1) % 3];
  837. Vector3 axis_n2;
  838. axis_n2[(i + 2) % 3] = cell_size[(i + 2) % 3];
  839. for (int j = -GRID_CURSOR_SIZE; j <= GRID_CURSOR_SIZE; j++) {
  840. for (int k = -GRID_CURSOR_SIZE; k <= GRID_CURSOR_SIZE; k++) {
  841. Vector3 p = axis_n1 * j + axis_n2 * k;
  842. float trans = Math::pow(MAX(0, 1.0 - (Vector2(j, k).length() / GRID_CURSOR_SIZE)), 2);
  843. Vector3 pj = axis_n1 * (j + 1) + axis_n2 * k;
  844. float transj = Math::pow(MAX(0, 1.0 - (Vector2(j + 1, k).length() / GRID_CURSOR_SIZE)), 2);
  845. Vector3 pk = axis_n1 * j + axis_n2 * (k + 1);
  846. float transk = Math::pow(MAX(0, 1.0 - (Vector2(j, k + 1).length() / GRID_CURSOR_SIZE)), 2);
  847. grid_points[i].push_back(p);
  848. grid_points[i].push_back(pk);
  849. grid_colors[i].push_back(Color(1, 1, 1, trans));
  850. grid_colors[i].push_back(Color(1, 1, 1, transk));
  851. grid_points[i].push_back(p);
  852. grid_points[i].push_back(pj);
  853. grid_colors[i].push_back(Color(1, 1, 1, trans));
  854. grid_colors[i].push_back(Color(1, 1, 1, transj));
  855. }
  856. }
  857. Array d;
  858. d.resize(VS::ARRAY_MAX);
  859. d[VS::ARRAY_VERTEX] = grid_points[i];
  860. d[VS::ARRAY_COLOR] = grid_colors[i];
  861. VisualServer::get_singleton()->mesh_add_surface_from_arrays(grid[i], VisualServer::PRIMITIVE_LINES, d);
  862. VisualServer::get_singleton()->mesh_surface_set_material(grid[i], 0, indicator_mat->get_rid());
  863. }
  864. }
  865. void GridMapEditor::_notification(int p_what) {
  866. switch (p_what) {
  867. case NOTIFICATION_ENTER_TREE: {
  868. get_tree()->connect("node_removed", this, "_node_removed");
  869. mesh_library_palette->connect("item_selected", this, "_item_selected_cbk");
  870. for (int i = 0; i < 3; i++) {
  871. grid[i] = VS::get_singleton()->mesh_create();
  872. grid_instance[i] = VS::get_singleton()->instance_create2(grid[i], get_tree()->get_root()->get_world()->get_scenario());
  873. VS::get_singleton()->instance_set_layer_mask(grid_instance[i], 1 << SpatialEditorViewport::MISC_TOOL_LAYER);
  874. selection_level_instance[i] = VisualServer::get_singleton()->instance_create2(selection_level_mesh[i], get_tree()->get_root()->get_world()->get_scenario());
  875. VS::get_singleton()->instance_set_layer_mask(selection_level_instance[i], 1 << SpatialEditorViewport::MISC_TOOL_LAYER);
  876. }
  877. selection_instance = VisualServer::get_singleton()->instance_create2(selection_mesh, get_tree()->get_root()->get_world()->get_scenario());
  878. VS::get_singleton()->instance_set_layer_mask(selection_instance, 1 << SpatialEditorViewport::MISC_TOOL_LAYER);
  879. paste_instance = VisualServer::get_singleton()->instance_create2(paste_mesh, get_tree()->get_root()->get_world()->get_scenario());
  880. VS::get_singleton()->instance_set_layer_mask(paste_instance, 1 << SpatialEditorViewport::MISC_TOOL_LAYER);
  881. _update_selection_transform();
  882. _update_paste_indicator();
  883. } break;
  884. case NOTIFICATION_EXIT_TREE: {
  885. get_tree()->disconnect("node_removed", this, "_node_removed");
  886. _clear_clipboard_data();
  887. for (int i = 0; i < 3; i++) {
  888. VS::get_singleton()->free(grid_instance[i]);
  889. VS::get_singleton()->free(grid[i]);
  890. grid_instance[i] = RID();
  891. grid[i] = RID();
  892. VisualServer::get_singleton()->free(selection_level_instance[i]);
  893. }
  894. VisualServer::get_singleton()->free(selection_instance);
  895. VisualServer::get_singleton()->free(paste_instance);
  896. selection_instance = RID();
  897. paste_instance = RID();
  898. } break;
  899. case NOTIFICATION_PROCESS: {
  900. if (!node) {
  901. return;
  902. }
  903. Transform xf = node->get_global_transform();
  904. if (xf != grid_xform) {
  905. for (int i = 0; i < 3; i++) {
  906. VS::get_singleton()->instance_set_transform(grid_instance[i], xf * edit_grid_xform);
  907. }
  908. grid_xform = xf;
  909. }
  910. Ref<MeshLibrary> cgmt = node->get_mesh_library();
  911. if (cgmt.operator->() != last_mesh_library) {
  912. update_palette();
  913. }
  914. if (lock_view) {
  915. EditorNode *editor = Object::cast_to<EditorNode>(get_tree()->get_root()->get_child(0));
  916. Plane p;
  917. p.normal[edit_axis] = 1.0;
  918. p.d = edit_floor[edit_axis] * node->get_cell_size()[edit_axis];
  919. p = node->get_transform().xform(p); // plane to snap
  920. SpatialEditorPlugin *sep = Object::cast_to<SpatialEditorPlugin>(editor->get_editor_plugin_screen());
  921. if (sep) {
  922. sep->snap_cursor_to_plane(p);
  923. }
  924. }
  925. } break;
  926. case NOTIFICATION_THEME_CHANGED: {
  927. options->set_icon(get_icon("GridMap", "EditorIcons"));
  928. search_box->set_right_icon(get_icon("Search", "EditorIcons"));
  929. } break;
  930. case NOTIFICATION_WM_FOCUS_OUT: {
  931. if (input_action == INPUT_PAINT) {
  932. // Simulate mouse released event to stop drawing when editor focus exists.
  933. Ref<InputEventMouseButton> release;
  934. release.instance();
  935. release->set_button_index(BUTTON_LEFT);
  936. forward_spatial_input_event(nullptr, release);
  937. }
  938. } break;
  939. }
  940. }
  941. void GridMapEditor::_update_cursor_instance() {
  942. if (!node) {
  943. return;
  944. }
  945. if (cursor_instance.is_valid()) {
  946. VisualServer::get_singleton()->free(cursor_instance);
  947. }
  948. cursor_instance = RID();
  949. if (selected_palette >= 0) {
  950. if (node && !node->get_mesh_library().is_null()) {
  951. Ref<Mesh> mesh = node->get_mesh_library()->get_item_mesh(selected_palette);
  952. if (!mesh.is_null() && mesh->get_rid().is_valid()) {
  953. cursor_instance = VisualServer::get_singleton()->instance_create2(mesh->get_rid(), get_tree()->get_root()->get_world()->get_scenario());
  954. VisualServer::get_singleton()->instance_set_transform(cursor_instance, cursor_transform);
  955. }
  956. }
  957. }
  958. }
  959. void GridMapEditor::_item_selected_cbk(int idx) {
  960. selected_palette = mesh_library_palette->get_item_metadata(idx);
  961. _update_cursor_instance();
  962. }
  963. void GridMapEditor::_floor_changed(float p_value) {
  964. if (updating) {
  965. return;
  966. }
  967. edit_floor[edit_axis] = p_value;
  968. node->set_meta("_editor_floor_", Vector3(edit_floor[0], edit_floor[1], edit_floor[2]));
  969. update_grid();
  970. _update_clip();
  971. _update_selection_transform();
  972. }
  973. void GridMapEditor::_floor_mouse_exited() {
  974. floor->get_line_edit()->release_focus();
  975. }
  976. void GridMapEditor::_bind_methods() {
  977. ClassDB::bind_method("_text_changed", &GridMapEditor::_text_changed);
  978. ClassDB::bind_method("_sbox_input", &GridMapEditor::_sbox_input);
  979. ClassDB::bind_method("_mesh_library_palette_input", &GridMapEditor::_mesh_library_palette_input);
  980. ClassDB::bind_method("_icon_size_changed", &GridMapEditor::_icon_size_changed);
  981. ClassDB::bind_method("_menu_option", &GridMapEditor::_menu_option);
  982. ClassDB::bind_method("_configure", &GridMapEditor::_configure);
  983. ClassDB::bind_method("_item_selected_cbk", &GridMapEditor::_item_selected_cbk);
  984. ClassDB::bind_method("_floor_changed", &GridMapEditor::_floor_changed);
  985. ClassDB::bind_method("_floor_mouse_exited", &GridMapEditor::_floor_mouse_exited);
  986. ClassDB::bind_method("_set_selection", &GridMapEditor::_set_selection);
  987. ClassDB::bind_method("_node_removed", &GridMapEditor::_node_removed);
  988. ClassDB::bind_method(D_METHOD("_set_display_mode", "mode"), &GridMapEditor::_set_display_mode);
  989. ClassDB::bind_method("_draw_grids", &GridMapEditor::_draw_grids);
  990. }
  991. GridMapEditor::GridMapEditor(EditorNode *p_editor) {
  992. input_action = INPUT_NONE;
  993. node = nullptr;
  994. editor = p_editor;
  995. undo_redo = p_editor->get_undo_redo();
  996. int mw = EDITOR_DEF("editors/grid_map/palette_min_width", 230);
  997. Control *ec = memnew(Control);
  998. ec->set_custom_minimum_size(Size2(mw, 0) * EDSCALE);
  999. add_child(ec);
  1000. spatial_editor_hb = memnew(HBoxContainer);
  1001. spatial_editor_hb->set_h_size_flags(SIZE_EXPAND_FILL);
  1002. spatial_editor_hb->set_alignment(BoxContainer::ALIGN_END);
  1003. SpatialEditor::get_singleton()->add_control_to_menu_panel(spatial_editor_hb);
  1004. spin_box_label = memnew(Label);
  1005. spin_box_label->set_text(TTR("Floor:"));
  1006. spatial_editor_hb->add_child(spin_box_label);
  1007. floor = memnew(SpinBox);
  1008. floor->set_min(-32767);
  1009. floor->set_max(32767);
  1010. floor->set_step(1);
  1011. floor->get_line_edit()->add_constant_override("minimum_spaces", 16);
  1012. spatial_editor_hb->add_child(floor);
  1013. floor->connect("value_changed", this, "_floor_changed");
  1014. floor->connect("mouse_exited", this, "_floor_mouse_exited");
  1015. floor->get_line_edit()->connect("mouse_exited", this, "_floor_mouse_exited");
  1016. spatial_editor_hb->add_child(memnew(VSeparator));
  1017. options = memnew(MenuButton);
  1018. spatial_editor_hb->add_child(options);
  1019. spatial_editor_hb->hide();
  1020. options->set_text(TTR("Grid Map"));
  1021. options->get_popup()->add_check_item(TTR("Snap View"), MENU_OPTION_LOCK_VIEW);
  1022. options->get_popup()->add_separator();
  1023. options->get_popup()->add_item(TTR("Previous Floor"), MENU_OPTION_PREV_LEVEL, KEY_Q);
  1024. options->get_popup()->add_item(TTR("Next Floor"), MENU_OPTION_NEXT_LEVEL, KEY_E);
  1025. options->get_popup()->add_separator();
  1026. options->get_popup()->add_radio_check_item(TTR("Clip Disabled"), MENU_OPTION_CLIP_DISABLED);
  1027. options->get_popup()->set_item_checked(options->get_popup()->get_item_index(MENU_OPTION_CLIP_DISABLED), true);
  1028. options->get_popup()->add_radio_check_item(TTR("Clip Above"), MENU_OPTION_CLIP_ABOVE);
  1029. options->get_popup()->add_radio_check_item(TTR("Clip Below"), MENU_OPTION_CLIP_BELOW);
  1030. options->get_popup()->add_separator();
  1031. options->get_popup()->add_radio_check_item(TTR("Edit X Axis"), MENU_OPTION_X_AXIS, KEY_Z);
  1032. options->get_popup()->add_radio_check_item(TTR("Edit Y Axis"), MENU_OPTION_Y_AXIS, KEY_X);
  1033. options->get_popup()->add_radio_check_item(TTR("Edit Z Axis"), MENU_OPTION_Z_AXIS, KEY_C);
  1034. options->get_popup()->set_item_checked(options->get_popup()->get_item_index(MENU_OPTION_Y_AXIS), true);
  1035. options->get_popup()->add_separator();
  1036. options->get_popup()->add_item(TTR("Cursor Rotate X"), MENU_OPTION_CURSOR_ROTATE_X, KEY_A);
  1037. options->get_popup()->add_item(TTR("Cursor Rotate Y"), MENU_OPTION_CURSOR_ROTATE_Y, KEY_S);
  1038. options->get_popup()->add_item(TTR("Cursor Rotate Z"), MENU_OPTION_CURSOR_ROTATE_Z, KEY_D);
  1039. options->get_popup()->add_item(TTR("Cursor Back Rotate X"), MENU_OPTION_CURSOR_BACK_ROTATE_X, KEY_MASK_SHIFT + KEY_A);
  1040. options->get_popup()->add_item(TTR("Cursor Back Rotate Y"), MENU_OPTION_CURSOR_BACK_ROTATE_Y, KEY_MASK_SHIFT + KEY_S);
  1041. options->get_popup()->add_item(TTR("Cursor Back Rotate Z"), MENU_OPTION_CURSOR_BACK_ROTATE_Z, KEY_MASK_SHIFT + KEY_D);
  1042. options->get_popup()->add_item(TTR("Cursor Clear Rotation"), MENU_OPTION_CURSOR_CLEAR_ROTATION, KEY_W);
  1043. options->get_popup()->add_separator();
  1044. options->get_popup()->add_check_item(TTR("Paste Selects"), MENU_OPTION_PASTE_SELECTS);
  1045. options->get_popup()->add_separator();
  1046. options->get_popup()->add_item(TTR("Duplicate Selection"), MENU_OPTION_SELECTION_DUPLICATE, KEY_MASK_CTRL + KEY_C);
  1047. options->get_popup()->add_item(TTR("Cut Selection"), MENU_OPTION_SELECTION_CUT, KEY_MASK_CTRL + KEY_X);
  1048. options->get_popup()->add_item(TTR("Clear Selection"), MENU_OPTION_SELECTION_CLEAR, KEY_DELETE);
  1049. options->get_popup()->add_item(TTR("Fill Selection"), MENU_OPTION_SELECTION_FILL, KEY_MASK_CTRL + KEY_F);
  1050. options->get_popup()->add_separator();
  1051. options->get_popup()->add_item(TTR("Settings..."), MENU_OPTION_GRIDMAP_SETTINGS);
  1052. settings_dialog = memnew(ConfirmationDialog);
  1053. settings_dialog->set_title(TTR("GridMap Settings"));
  1054. add_child(settings_dialog);
  1055. settings_vbc = memnew(VBoxContainer);
  1056. settings_vbc->set_custom_minimum_size(Size2(200, 0) * EDSCALE);
  1057. settings_dialog->add_child(settings_vbc);
  1058. settings_pick_distance = memnew(SpinBox);
  1059. settings_pick_distance->set_max(10000.0f);
  1060. settings_pick_distance->set_min(500.0f);
  1061. settings_pick_distance->set_step(1.0f);
  1062. settings_pick_distance->set_value(EDITOR_DEF("editors/grid_map/pick_distance", 5000.0));
  1063. settings_vbc->add_margin_child(TTR("Pick Distance:"), settings_pick_distance);
  1064. clip_mode = CLIP_DISABLED;
  1065. options->get_popup()->connect("id_pressed", this, "_menu_option");
  1066. HBoxContainer *hb = memnew(HBoxContainer);
  1067. add_child(hb);
  1068. hb->set_h_size_flags(SIZE_EXPAND_FILL);
  1069. search_box = memnew(LineEdit);
  1070. search_box->set_h_size_flags(SIZE_EXPAND_FILL);
  1071. search_box->set_placeholder(TTR("Filter meshes"));
  1072. hb->add_child(search_box);
  1073. search_box->connect("text_changed", this, "_text_changed");
  1074. search_box->connect("gui_input", this, "_sbox_input");
  1075. mode_thumbnail = memnew(ToolButton);
  1076. mode_thumbnail->set_toggle_mode(true);
  1077. mode_thumbnail->set_pressed(true);
  1078. mode_thumbnail->set_icon(p_editor->get_gui_base()->get_icon("FileThumbnail", "EditorIcons"));
  1079. hb->add_child(mode_thumbnail);
  1080. mode_thumbnail->connect("pressed", this, "_set_display_mode", varray(DISPLAY_THUMBNAIL));
  1081. mode_list = memnew(ToolButton);
  1082. mode_list->set_toggle_mode(true);
  1083. mode_list->set_pressed(false);
  1084. mode_list->set_icon(p_editor->get_gui_base()->get_icon("FileList", "EditorIcons"));
  1085. hb->add_child(mode_list);
  1086. mode_list->connect("pressed", this, "_set_display_mode", varray(DISPLAY_LIST));
  1087. size_slider = memnew(HSlider);
  1088. size_slider->set_h_size_flags(SIZE_EXPAND_FILL);
  1089. size_slider->set_min(0.2f);
  1090. size_slider->set_max(4.0f);
  1091. size_slider->set_step(0.1f);
  1092. size_slider->set_value(1.0f);
  1093. size_slider->connect("value_changed", this, "_icon_size_changed");
  1094. add_child(size_slider);
  1095. EDITOR_DEF("editors/grid_map/preview_size", 64);
  1096. display_mode = DISPLAY_THUMBNAIL;
  1097. mesh_library_palette = memnew(ItemList);
  1098. add_child(mesh_library_palette);
  1099. mesh_library_palette->set_v_size_flags(SIZE_EXPAND_FILL);
  1100. mesh_library_palette->connect("gui_input", this, "_mesh_library_palette_input");
  1101. info_message = memnew(Label);
  1102. info_message->set_text(TTR("Give a MeshLibrary resource to this GridMap to use its meshes."));
  1103. info_message->set_valign(Label::VALIGN_CENTER);
  1104. info_message->set_align(Label::ALIGN_CENTER);
  1105. info_message->set_autowrap(true);
  1106. info_message->set_custom_minimum_size(Size2(100 * EDSCALE, 0));
  1107. info_message->set_anchors_and_margins_preset(PRESET_WIDE, PRESET_MODE_KEEP_SIZE, 8 * EDSCALE);
  1108. mesh_library_palette->add_child(info_message);
  1109. edit_axis = Vector3::AXIS_Y;
  1110. edit_floor[0] = -1;
  1111. edit_floor[1] = -1;
  1112. edit_floor[2] = -1;
  1113. cursor_visible = false;
  1114. selected_palette = -1;
  1115. lock_view = false;
  1116. cursor_rot = 0;
  1117. selection_mesh = VisualServer::get_singleton()->mesh_create();
  1118. paste_mesh = VisualServer::get_singleton()->mesh_create();
  1119. {
  1120. // Selection mesh create.
  1121. PoolVector<Vector3> lines;
  1122. PoolVector<Vector3> triangles;
  1123. PoolVector<Vector3> square[3];
  1124. for (int i = 0; i < 6; i++) {
  1125. Vector3 face_points[4];
  1126. for (int j = 0; j < 4; j++) {
  1127. float v[3];
  1128. v[0] = 1.0;
  1129. v[1] = 1 - 2 * ((j >> 1) & 1);
  1130. v[2] = v[1] * (1 - 2 * (j & 1));
  1131. for (int k = 0; k < 3; k++) {
  1132. if (i < 3) {
  1133. face_points[j][(i + k) % 3] = v[k];
  1134. } else {
  1135. face_points[3 - j][(i + k) % 3] = -v[k];
  1136. }
  1137. }
  1138. }
  1139. triangles.push_back(face_points[0] * 0.5 + Vector3(0.5, 0.5, 0.5));
  1140. triangles.push_back(face_points[1] * 0.5 + Vector3(0.5, 0.5, 0.5));
  1141. triangles.push_back(face_points[2] * 0.5 + Vector3(0.5, 0.5, 0.5));
  1142. triangles.push_back(face_points[2] * 0.5 + Vector3(0.5, 0.5, 0.5));
  1143. triangles.push_back(face_points[3] * 0.5 + Vector3(0.5, 0.5, 0.5));
  1144. triangles.push_back(face_points[0] * 0.5 + Vector3(0.5, 0.5, 0.5));
  1145. }
  1146. for (int i = 0; i < 12; i++) {
  1147. AABB base(Vector3(0, 0, 0), Vector3(1, 1, 1));
  1148. Vector3 a, b;
  1149. base.get_edge(i, a, b);
  1150. lines.push_back(a);
  1151. lines.push_back(b);
  1152. }
  1153. for (int i = 0; i < 3; i++) {
  1154. Vector3 points[4];
  1155. for (int j = 0; j < 4; j++) {
  1156. static const bool orderx[4] = { false, true, true, false };
  1157. static const bool ordery[4] = { false, false, true, true };
  1158. Vector3 sp;
  1159. if (orderx[j]) {
  1160. sp[(i + 1) % 3] = 1.0;
  1161. }
  1162. if (ordery[j]) {
  1163. sp[(i + 2) % 3] = 1.0;
  1164. }
  1165. points[j] = sp;
  1166. }
  1167. for (int j = 0; j < 4; j++) {
  1168. Vector3 ofs;
  1169. ofs[i] += 0.01;
  1170. square[i].push_back(points[j] - ofs);
  1171. square[i].push_back(points[(j + 1) % 4] - ofs);
  1172. square[i].push_back(points[j] + ofs);
  1173. square[i].push_back(points[(j + 1) % 4] + ofs);
  1174. }
  1175. }
  1176. Array d;
  1177. d.resize(VS::ARRAY_MAX);
  1178. inner_mat.instance();
  1179. inner_mat->set_albedo(Color(0.7, 0.7, 1.0, 0.2));
  1180. inner_mat->set_flag(SpatialMaterial::FLAG_UNSHADED, true);
  1181. inner_mat->set_feature(SpatialMaterial::FEATURE_TRANSPARENT, true);
  1182. d[VS::ARRAY_VERTEX] = triangles;
  1183. VisualServer::get_singleton()->mesh_add_surface_from_arrays(selection_mesh, VS::PRIMITIVE_TRIANGLES, d);
  1184. VisualServer::get_singleton()->mesh_surface_set_material(selection_mesh, 0, inner_mat->get_rid());
  1185. outer_mat.instance();
  1186. outer_mat->set_albedo(Color(0.7, 0.7, 1.0, 0.8));
  1187. outer_mat->set_on_top_of_alpha();
  1188. outer_mat->set_flag(SpatialMaterial::FLAG_UNSHADED, true);
  1189. outer_mat->set_line_width(3.0);
  1190. outer_mat->set_feature(SpatialMaterial::FEATURE_TRANSPARENT, true);
  1191. selection_floor_mat.instance();
  1192. selection_floor_mat->set_albedo(Color(0.80, 0.80, 1.0, 1));
  1193. selection_floor_mat->set_on_top_of_alpha();
  1194. selection_floor_mat->set_flag(SpatialMaterial::FLAG_UNSHADED, true);
  1195. selection_floor_mat->set_line_width(3.0);
  1196. d[VS::ARRAY_VERTEX] = lines;
  1197. VisualServer::get_singleton()->mesh_add_surface_from_arrays(selection_mesh, VS::PRIMITIVE_LINES, d);
  1198. VisualServer::get_singleton()->mesh_surface_set_material(selection_mesh, 1, outer_mat->get_rid());
  1199. d[VS::ARRAY_VERTEX] = triangles;
  1200. VisualServer::get_singleton()->mesh_add_surface_from_arrays(paste_mesh, VS::PRIMITIVE_TRIANGLES, d);
  1201. VisualServer::get_singleton()->mesh_surface_set_material(paste_mesh, 0, inner_mat->get_rid());
  1202. d[VS::ARRAY_VERTEX] = lines;
  1203. VisualServer::get_singleton()->mesh_add_surface_from_arrays(paste_mesh, VS::PRIMITIVE_LINES, d);
  1204. VisualServer::get_singleton()->mesh_surface_set_material(paste_mesh, 1, outer_mat->get_rid());
  1205. for (int i = 0; i < 3; i++) {
  1206. d[VS::ARRAY_VERTEX] = square[i];
  1207. selection_level_mesh[i] = VS::get_singleton()->mesh_create();
  1208. VisualServer::get_singleton()->mesh_add_surface_from_arrays(selection_level_mesh[i], VS::PRIMITIVE_LINES, d);
  1209. VisualServer::get_singleton()->mesh_surface_set_material(selection_level_mesh[i], 0, selection_floor_mat->get_rid());
  1210. }
  1211. }
  1212. _set_selection(false);
  1213. updating = false;
  1214. accumulated_floor_delta = 0.0;
  1215. indicator_mat.instance();
  1216. indicator_mat->set_flag(SpatialMaterial::FLAG_UNSHADED, true);
  1217. indicator_mat->set_feature(SpatialMaterial::FEATURE_TRANSPARENT, true);
  1218. indicator_mat->set_flag(SpatialMaterial::FLAG_SRGB_VERTEX_COLOR, true);
  1219. indicator_mat->set_flag(SpatialMaterial::FLAG_ALBEDO_FROM_VERTEX_COLOR, true);
  1220. indicator_mat->set_albedo(Color(0.8, 0.5, 0.1));
  1221. }
  1222. GridMapEditor::~GridMapEditor() {
  1223. _clear_clipboard_data();
  1224. for (int i = 0; i < 3; i++) {
  1225. if (grid[i].is_valid()) {
  1226. VisualServer::get_singleton()->free(grid[i]);
  1227. }
  1228. if (grid_instance[i].is_valid()) {
  1229. VisualServer::get_singleton()->free(grid_instance[i]);
  1230. }
  1231. if (cursor_instance.is_valid()) {
  1232. VisualServer::get_singleton()->free(cursor_instance);
  1233. }
  1234. if (selection_level_instance[i].is_valid()) {
  1235. VisualServer::get_singleton()->free(selection_level_instance[i]);
  1236. }
  1237. if (selection_level_mesh[i].is_valid()) {
  1238. VisualServer::get_singleton()->free(selection_level_mesh[i]);
  1239. }
  1240. }
  1241. VisualServer::get_singleton()->free(selection_mesh);
  1242. if (selection_instance.is_valid()) {
  1243. VisualServer::get_singleton()->free(selection_instance);
  1244. }
  1245. VisualServer::get_singleton()->free(paste_mesh);
  1246. if (paste_instance.is_valid()) {
  1247. VisualServer::get_singleton()->free(paste_instance);
  1248. }
  1249. }
  1250. void GridMapEditorPlugin::_notification(int p_what) {
  1251. if (p_what == EditorSettings::NOTIFICATION_EDITOR_SETTINGS_CHANGED) {
  1252. switch ((int)EditorSettings::get_singleton()->get("editors/grid_map/editor_side")) {
  1253. case 0: { // Left.
  1254. SpatialEditor::get_singleton()->get_palette_split()->move_child(grid_map_editor, 0);
  1255. } break;
  1256. case 1: { // Right.
  1257. SpatialEditor::get_singleton()->get_palette_split()->move_child(grid_map_editor, 1);
  1258. } break;
  1259. }
  1260. }
  1261. }
  1262. void GridMapEditorPlugin::edit(Object *p_object) {
  1263. grid_map_editor->edit(Object::cast_to<GridMap>(p_object));
  1264. }
  1265. bool GridMapEditorPlugin::handles(Object *p_object) const {
  1266. return p_object->is_class("GridMap");
  1267. }
  1268. void GridMapEditorPlugin::make_visible(bool p_visible) {
  1269. if (p_visible) {
  1270. grid_map_editor->show();
  1271. grid_map_editor->spatial_editor_hb->show();
  1272. grid_map_editor->set_process(true);
  1273. } else {
  1274. grid_map_editor->spatial_editor_hb->hide();
  1275. grid_map_editor->hide();
  1276. grid_map_editor->edit(nullptr);
  1277. grid_map_editor->set_process(false);
  1278. }
  1279. }
  1280. GridMapEditorPlugin::GridMapEditorPlugin(EditorNode *p_node) {
  1281. editor = p_node;
  1282. EDITOR_DEF("editors/grid_map/editor_side", 1);
  1283. EditorSettings::get_singleton()->add_property_hint(PropertyInfo(Variant::INT, "editors/grid_map/editor_side", PROPERTY_HINT_ENUM, "Left,Right"));
  1284. grid_map_editor = memnew(GridMapEditor(editor));
  1285. switch ((int)EditorSettings::get_singleton()->get("editors/grid_map/editor_side")) {
  1286. case 0: { // Left.
  1287. add_control_to_container(CONTAINER_SPATIAL_EDITOR_SIDE_LEFT, grid_map_editor);
  1288. } break;
  1289. case 1: { // Right.
  1290. add_control_to_container(CONTAINER_SPATIAL_EDITOR_SIDE_RIGHT, grid_map_editor);
  1291. } break;
  1292. }
  1293. grid_map_editor->hide();
  1294. }
  1295. GridMapEditorPlugin::~GridMapEditorPlugin() {
  1296. }