2
0

grid_map_editor_plugin.cpp 53 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563
  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-2022 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2022 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. if (E->get().instance.is_valid()) {
  445. VisualServer::get_singleton()->free(E->get().instance);
  446. }
  447. }
  448. clipboard_items.clear();
  449. }
  450. void GridMapEditor::_set_clipboard_data() {
  451. _clear_clipboard_data();
  452. Ref<MeshLibrary> meshLibrary = node->get_mesh_library();
  453. for (int i = selection.begin.x; i <= selection.end.x; i++) {
  454. for (int j = selection.begin.y; j <= selection.end.y; j++) {
  455. for (int k = selection.begin.z; k <= selection.end.z; k++) {
  456. int itm = node->get_cell_item(i, j, k);
  457. if (itm == GridMap::INVALID_CELL_ITEM) {
  458. continue;
  459. }
  460. Ref<Mesh> mesh = meshLibrary->get_item_mesh(itm);
  461. ClipboardItem item;
  462. item.cell_item = itm;
  463. item.grid_offset = Vector3(i, j, k) - selection.begin;
  464. item.orientation = node->get_cell_item_orientation(i, j, k);
  465. item.instance = VisualServer::get_singleton()->instance_create2(mesh->get_rid(), get_tree()->get_root()->get_world()->get_scenario());
  466. clipboard_items.push_back(item);
  467. }
  468. }
  469. }
  470. }
  471. void GridMapEditor::_update_paste_indicator() {
  472. if (input_action != INPUT_PASTE) {
  473. Transform xf;
  474. xf.basis.set_zero();
  475. VisualServer::get_singleton()->instance_set_transform(paste_instance, xf);
  476. return;
  477. }
  478. Vector3 center = 0.5 * Vector3(float(node->get_center_x()), float(node->get_center_y()), float(node->get_center_z()));
  479. Vector3 scale = (Vector3(1, 1, 1) + (paste_indicator.end - paste_indicator.begin)) * node->get_cell_size();
  480. Transform xf;
  481. xf.scale(scale);
  482. xf.origin = (paste_indicator.begin + (paste_indicator.current - paste_indicator.click) + center) * node->get_cell_size();
  483. Basis rot;
  484. rot.set_orthogonal_index(paste_indicator.orientation);
  485. xf.basis = rot * xf.basis;
  486. xf.translate((-center * node->get_cell_size()) / scale);
  487. VisualServer::get_singleton()->instance_set_transform(paste_instance, node->get_global_transform() * xf);
  488. for (List<ClipboardItem>::Element *E = clipboard_items.front(); E; E = E->next()) {
  489. ClipboardItem &item = E->get();
  490. xf = Transform();
  491. xf.origin = (paste_indicator.begin + (paste_indicator.current - paste_indicator.click) + center) * node->get_cell_size();
  492. xf.basis = rot * xf.basis;
  493. xf.translate(item.grid_offset * node->get_cell_size());
  494. Basis item_rot;
  495. item_rot.set_orthogonal_index(item.orientation);
  496. xf.basis = item_rot * xf.basis * node->get_cell_scale();
  497. VisualServer::get_singleton()->instance_set_transform(item.instance, node->get_global_transform() * xf);
  498. }
  499. }
  500. void GridMapEditor::_do_paste() {
  501. int idx = options->get_popup()->get_item_index(MENU_OPTION_PASTE_SELECTS);
  502. bool reselect = options->get_popup()->is_item_checked(idx);
  503. Basis rot;
  504. rot.set_orthogonal_index(paste_indicator.orientation);
  505. Vector3 ofs = paste_indicator.current - paste_indicator.click;
  506. undo_redo->create_action(TTR("GridMap Paste Selection"));
  507. for (List<ClipboardItem>::Element *E = clipboard_items.front(); E; E = E->next()) {
  508. ClipboardItem &item = E->get();
  509. Vector3 pos = rot.xform(item.grid_offset) + paste_indicator.begin + ofs;
  510. Basis orm;
  511. orm.set_orthogonal_index(item.orientation);
  512. orm = rot * orm;
  513. undo_redo->add_do_method(node, "set_cell_item", pos.x, pos.y, pos.z, item.cell_item, orm.get_orthogonal_index());
  514. 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));
  515. }
  516. if (reselect) {
  517. undo_redo->add_do_method(this, "_set_selection", true, paste_indicator.begin + ofs, paste_indicator.end + ofs);
  518. undo_redo->add_undo_method(this, "_set_selection", selection.active, selection.begin, selection.end);
  519. }
  520. undo_redo->commit_action();
  521. _clear_clipboard_data();
  522. }
  523. bool GridMapEditor::forward_spatial_input_event(Camera *p_camera, const Ref<InputEvent> &p_event) {
  524. if (!node) {
  525. return false;
  526. }
  527. Ref<InputEventMouseButton> mb = p_event;
  528. if (mb.is_valid()) {
  529. if (mb->get_button_index() == BUTTON_WHEEL_UP && (mb->get_command() || mb->get_shift())) {
  530. if (mb->is_pressed()) {
  531. floor->set_value(floor->get_value() + mb->get_factor());
  532. }
  533. return true; // Eaten.
  534. } else if (mb->get_button_index() == BUTTON_WHEEL_DOWN && (mb->get_command() || mb->get_shift())) {
  535. if (mb->is_pressed()) {
  536. floor->set_value(floor->get_value() - mb->get_factor());
  537. }
  538. return true;
  539. }
  540. if (mb->is_pressed()) {
  541. SpatialEditorViewport::NavigationScheme nav_scheme = (SpatialEditorViewport::NavigationScheme)EditorSettings::get_singleton()->get("editors/3d/navigation/navigation_scheme").operator int();
  542. if ((nav_scheme == SpatialEditorViewport::NAVIGATION_MAYA || nav_scheme == SpatialEditorViewport::NAVIGATION_MODO) && mb->get_alt()) {
  543. input_action = INPUT_NONE;
  544. } else if (mb->get_button_index() == BUTTON_LEFT) {
  545. bool can_edit = (node && node->get_mesh_library().is_valid());
  546. if (input_action == INPUT_PASTE) {
  547. _do_paste();
  548. input_action = INPUT_NONE;
  549. _update_paste_indicator();
  550. } else if (mb->get_shift() && can_edit) {
  551. input_action = INPUT_SELECT;
  552. last_selection = selection;
  553. } else if (mb->get_command() && can_edit) {
  554. input_action = INPUT_PICK;
  555. } else {
  556. input_action = INPUT_PAINT;
  557. set_items.clear();
  558. }
  559. } else if (mb->get_button_index() == BUTTON_RIGHT) {
  560. if (input_action == INPUT_PASTE) {
  561. _clear_clipboard_data();
  562. input_action = INPUT_NONE;
  563. _update_paste_indicator();
  564. return true;
  565. } else if (selection.active) {
  566. _set_selection(false);
  567. return true;
  568. } else {
  569. input_action = INPUT_ERASE;
  570. set_items.clear();
  571. }
  572. } else {
  573. return false;
  574. }
  575. return do_input_action(p_camera, Point2(mb->get_position().x, mb->get_position().y), true);
  576. } else {
  577. if ((mb->get_button_index() == BUTTON_RIGHT && input_action == INPUT_ERASE) || (mb->get_button_index() == BUTTON_LEFT && input_action == INPUT_PAINT)) {
  578. if (set_items.size()) {
  579. undo_redo->create_action(TTR("GridMap Paint"));
  580. for (List<SetItem>::Element *E = set_items.front(); E; E = E->next()) {
  581. const SetItem &si = E->get();
  582. undo_redo->add_do_method(node, "set_cell_item", si.pos.x, si.pos.y, si.pos.z, si.new_value, si.new_orientation);
  583. }
  584. for (List<SetItem>::Element *E = set_items.back(); E; E = E->prev()) {
  585. const SetItem &si = E->get();
  586. undo_redo->add_undo_method(node, "set_cell_item", si.pos.x, si.pos.y, si.pos.z, si.old_value, si.old_orientation);
  587. }
  588. undo_redo->commit_action();
  589. }
  590. set_items.clear();
  591. input_action = INPUT_NONE;
  592. return set_items.size() > 0;
  593. }
  594. if (mb->get_button_index() == BUTTON_LEFT && input_action == INPUT_SELECT) {
  595. undo_redo->create_action(TTR("GridMap Selection"));
  596. undo_redo->add_do_method(this, "_set_selection", selection.active, selection.begin, selection.end);
  597. undo_redo->add_undo_method(this, "_set_selection", last_selection.active, last_selection.begin, last_selection.end);
  598. undo_redo->commit_action();
  599. }
  600. if (mb->get_button_index() == BUTTON_LEFT && input_action != INPUT_NONE) {
  601. set_items.clear();
  602. input_action = INPUT_NONE;
  603. return true;
  604. }
  605. if (mb->get_button_index() == BUTTON_RIGHT && (input_action == INPUT_ERASE || input_action == INPUT_PASTE)) {
  606. input_action = INPUT_NONE;
  607. return true;
  608. }
  609. }
  610. }
  611. Ref<InputEventMouseMotion> mm = p_event;
  612. if (mm.is_valid()) {
  613. return do_input_action(p_camera, mm->get_position(), false);
  614. }
  615. Ref<InputEventKey> k = p_event;
  616. if (k.is_valid()) {
  617. if (k->is_pressed()) {
  618. if (k->get_scancode() == KEY_ESCAPE) {
  619. if (input_action == INPUT_PASTE) {
  620. _clear_clipboard_data();
  621. input_action = INPUT_NONE;
  622. _update_paste_indicator();
  623. return true;
  624. } else if (selection.active) {
  625. _set_selection(false);
  626. return true;
  627. } else {
  628. selected_palette = -1;
  629. mesh_library_palette->unselect_all();
  630. update_palette();
  631. _update_cursor_instance();
  632. return true;
  633. }
  634. }
  635. if (k->get_shift() && selection.active && input_action != INPUT_PASTE) {
  636. if (k->get_scancode() == options->get_popup()->get_item_accelerator(options->get_popup()->get_item_index(MENU_OPTION_PREV_LEVEL))) {
  637. selection.click[edit_axis]--;
  638. _validate_selection();
  639. return true;
  640. }
  641. if (k->get_scancode() == options->get_popup()->get_item_accelerator(options->get_popup()->get_item_index(MENU_OPTION_NEXT_LEVEL))) {
  642. selection.click[edit_axis]++;
  643. _validate_selection();
  644. return true;
  645. }
  646. }
  647. }
  648. }
  649. Ref<InputEventPanGesture> pan_gesture = p_event;
  650. if (pan_gesture.is_valid()) {
  651. if (pan_gesture->get_alt() && (pan_gesture->get_command() || pan_gesture->get_shift())) {
  652. const real_t delta = pan_gesture->get_delta().y * 0.5;
  653. accumulated_floor_delta += delta;
  654. int step = 0;
  655. if (ABS(accumulated_floor_delta) > 1.0) {
  656. step = SGN(accumulated_floor_delta);
  657. accumulated_floor_delta -= step;
  658. }
  659. if (step) {
  660. floor->set_value(floor->get_value() + step);
  661. }
  662. return true;
  663. }
  664. }
  665. accumulated_floor_delta = 0.0;
  666. return false;
  667. }
  668. struct _CGMEItemSort {
  669. String name;
  670. int id;
  671. _FORCE_INLINE_ bool operator<(const _CGMEItemSort &r_it) const { return name < r_it.name; }
  672. };
  673. void GridMapEditor::_set_display_mode(int p_mode) {
  674. if (display_mode == p_mode) {
  675. return;
  676. }
  677. if (p_mode == DISPLAY_LIST) {
  678. mode_list->set_pressed(true);
  679. mode_thumbnail->set_pressed(false);
  680. } else if (p_mode == DISPLAY_THUMBNAIL) {
  681. mode_list->set_pressed(false);
  682. mode_thumbnail->set_pressed(true);
  683. }
  684. display_mode = p_mode;
  685. update_palette();
  686. }
  687. void GridMapEditor::_text_changed(const String &p_text) {
  688. update_palette();
  689. }
  690. void GridMapEditor::_sbox_input(const Ref<InputEvent> &p_ie) {
  691. const Ref<InputEventKey> k = p_ie;
  692. if (k.is_valid() && (k->get_scancode() == KEY_UP || k->get_scancode() == KEY_DOWN || k->get_scancode() == KEY_PAGEUP || k->get_scancode() == KEY_PAGEDOWN)) {
  693. // Forward the key input to the ItemList so it can be scrolled
  694. mesh_library_palette->call("_gui_input", k);
  695. search_box->accept_event();
  696. }
  697. }
  698. void GridMapEditor::_mesh_library_palette_input(const Ref<InputEvent> &p_ie) {
  699. const Ref<InputEventMouseButton> mb = p_ie;
  700. // Zoom in/out using Ctrl + mouse wheel
  701. if (mb.is_valid() && mb->is_pressed() && mb->get_command()) {
  702. if (mb->is_pressed() && mb->get_button_index() == BUTTON_WHEEL_UP) {
  703. size_slider->set_value(size_slider->get_value() + 0.2);
  704. }
  705. if (mb->is_pressed() && mb->get_button_index() == BUTTON_WHEEL_DOWN) {
  706. size_slider->set_value(size_slider->get_value() - 0.2);
  707. }
  708. }
  709. }
  710. void GridMapEditor::_icon_size_changed(float p_value) {
  711. mesh_library_palette->set_icon_scale(p_value);
  712. update_palette();
  713. }
  714. void GridMapEditor::update_palette() {
  715. int selected = mesh_library_palette->get_current();
  716. float min_size = EDITOR_DEF("editors/grid_map/preview_size", 64);
  717. min_size *= EDSCALE;
  718. mesh_library_palette->clear();
  719. if (display_mode == DISPLAY_THUMBNAIL) {
  720. mesh_library_palette->set_max_columns(0);
  721. mesh_library_palette->set_icon_mode(ItemList::ICON_MODE_TOP);
  722. mesh_library_palette->set_fixed_column_width(min_size * MAX(size_slider->get_value(), 1.5));
  723. } else if (display_mode == DISPLAY_LIST) {
  724. mesh_library_palette->set_max_columns(1);
  725. mesh_library_palette->set_icon_mode(ItemList::ICON_MODE_LEFT);
  726. mesh_library_palette->set_fixed_column_width(0);
  727. }
  728. mesh_library_palette->set_fixed_icon_size(Size2(min_size, min_size));
  729. mesh_library_palette->set_max_text_lines(2);
  730. Ref<MeshLibrary> mesh_library = node->get_mesh_library();
  731. if (mesh_library.is_null()) {
  732. last_mesh_library = nullptr;
  733. search_box->set_text("");
  734. search_box->set_editable(false);
  735. info_message->show();
  736. return;
  737. }
  738. search_box->set_editable(true);
  739. info_message->hide();
  740. Vector<int> ids;
  741. ids = mesh_library->get_item_list();
  742. List<_CGMEItemSort> il;
  743. for (int i = 0; i < ids.size(); i++) {
  744. _CGMEItemSort is;
  745. is.id = ids[i];
  746. is.name = mesh_library->get_item_name(ids[i]);
  747. il.push_back(is);
  748. }
  749. il.sort();
  750. String filter = search_box->get_text().strip_edges();
  751. int item = 0;
  752. for (List<_CGMEItemSort>::Element *E = il.front(); E; E = E->next()) {
  753. int id = E->get().id;
  754. String name = mesh_library->get_item_name(id);
  755. Ref<Texture> preview = mesh_library->get_item_preview(id);
  756. if (name == "") {
  757. name = "#" + itos(id);
  758. }
  759. if (filter != "" && !filter.is_subsequence_ofi(name)) {
  760. continue;
  761. }
  762. mesh_library_palette->add_item("");
  763. if (!preview.is_null()) {
  764. mesh_library_palette->set_item_icon(item, preview);
  765. mesh_library_palette->set_item_tooltip(item, name);
  766. }
  767. mesh_library_palette->set_item_text(item, name);
  768. mesh_library_palette->set_item_metadata(item, id);
  769. item++;
  770. }
  771. if (selected != -1 && mesh_library_palette->get_item_count() > 0) {
  772. mesh_library_palette->select(selected);
  773. }
  774. last_mesh_library = mesh_library.operator->();
  775. }
  776. void GridMapEditor::edit(GridMap *p_gridmap) {
  777. if (!p_gridmap && node) {
  778. node->disconnect("cell_size_changed", this, "_draw_grids");
  779. }
  780. node = p_gridmap;
  781. input_action = INPUT_NONE;
  782. selection.active = false;
  783. _update_selection_transform();
  784. _update_paste_indicator();
  785. spatial_editor = Object::cast_to<SpatialEditorPlugin>(editor->get_editor_plugin_screen());
  786. if (!node) {
  787. set_process(false);
  788. for (int i = 0; i < 3; i++) {
  789. VisualServer::get_singleton()->instance_set_visible(grid_instance[i], false);
  790. }
  791. if (cursor_instance.is_valid()) {
  792. VisualServer::get_singleton()->instance_set_visible(cursor_instance, false);
  793. }
  794. return;
  795. }
  796. update_palette();
  797. set_process(true);
  798. clip_mode = p_gridmap->has_meta("_editor_clip_") ? ClipMode(p_gridmap->get_meta("_editor_clip_").operator int()) : CLIP_DISABLED;
  799. _draw_grids(node->get_cell_size());
  800. update_grid();
  801. _update_clip();
  802. node->connect("cell_size_changed", this, "_draw_grids");
  803. }
  804. void GridMapEditor::_update_clip() {
  805. node->set_meta("_editor_clip_", clip_mode);
  806. if (clip_mode == CLIP_DISABLED) {
  807. node->set_clip(false);
  808. } else {
  809. node->set_clip(true, clip_mode == CLIP_ABOVE, edit_floor[edit_axis], edit_axis);
  810. }
  811. }
  812. void GridMapEditor::update_grid() {
  813. grid_xform.origin.x -= 1; // Force update in hackish way.
  814. grid_ofs[edit_axis] = edit_floor[edit_axis] * node->get_cell_size()[edit_axis];
  815. edit_grid_xform.origin = grid_ofs;
  816. edit_grid_xform.basis = Basis();
  817. for (int i = 0; i < 3; i++) {
  818. VisualServer::get_singleton()->instance_set_visible(grid_instance[i], i == edit_axis);
  819. }
  820. updating = true;
  821. floor->set_value(edit_floor[edit_axis]);
  822. updating = false;
  823. }
  824. void GridMapEditor::_draw_grids(const Vector3 &cell_size) {
  825. Vector3 edited_floor = node->has_meta("_editor_floor_") ? node->get_meta("_editor_floor_") : Variant();
  826. for (int i = 0; i < 3; i++) {
  827. if (VS::get_singleton()->mesh_get_surface_count(grid[i]) > 0) {
  828. VS::get_singleton()->mesh_remove_surface(grid[i], 0);
  829. }
  830. edit_floor[i] = edited_floor[i];
  831. }
  832. Vector<Vector3> grid_points[3];
  833. Vector<Color> grid_colors[3];
  834. for (int i = 0; i < 3; i++) {
  835. Vector3 axis;
  836. axis[i] = 1;
  837. Vector3 axis_n1;
  838. axis_n1[(i + 1) % 3] = cell_size[(i + 1) % 3];
  839. Vector3 axis_n2;
  840. axis_n2[(i + 2) % 3] = cell_size[(i + 2) % 3];
  841. for (int j = -GRID_CURSOR_SIZE; j <= GRID_CURSOR_SIZE; j++) {
  842. for (int k = -GRID_CURSOR_SIZE; k <= GRID_CURSOR_SIZE; k++) {
  843. Vector3 p = axis_n1 * j + axis_n2 * k;
  844. float trans = Math::pow(MAX(0, 1.0 - (Vector2(j, k).length() / GRID_CURSOR_SIZE)), 2);
  845. Vector3 pj = axis_n1 * (j + 1) + axis_n2 * k;
  846. float transj = Math::pow(MAX(0, 1.0 - (Vector2(j + 1, k).length() / GRID_CURSOR_SIZE)), 2);
  847. Vector3 pk = axis_n1 * j + axis_n2 * (k + 1);
  848. float transk = Math::pow(MAX(0, 1.0 - (Vector2(j, k + 1).length() / GRID_CURSOR_SIZE)), 2);
  849. grid_points[i].push_back(p);
  850. grid_points[i].push_back(pk);
  851. grid_colors[i].push_back(Color(1, 1, 1, trans));
  852. grid_colors[i].push_back(Color(1, 1, 1, transk));
  853. grid_points[i].push_back(p);
  854. grid_points[i].push_back(pj);
  855. grid_colors[i].push_back(Color(1, 1, 1, trans));
  856. grid_colors[i].push_back(Color(1, 1, 1, transj));
  857. }
  858. }
  859. Array d;
  860. d.resize(VS::ARRAY_MAX);
  861. d[VS::ARRAY_VERTEX] = grid_points[i];
  862. d[VS::ARRAY_COLOR] = grid_colors[i];
  863. VisualServer::get_singleton()->mesh_add_surface_from_arrays(grid[i], VisualServer::PRIMITIVE_LINES, d);
  864. VisualServer::get_singleton()->mesh_surface_set_material(grid[i], 0, indicator_mat->get_rid());
  865. }
  866. }
  867. void GridMapEditor::_notification(int p_what) {
  868. switch (p_what) {
  869. case NOTIFICATION_ENTER_TREE: {
  870. get_tree()->connect("node_removed", this, "_node_removed");
  871. mesh_library_palette->connect("item_selected", this, "_item_selected_cbk");
  872. for (int i = 0; i < 3; i++) {
  873. grid[i] = VS::get_singleton()->mesh_create();
  874. grid_instance[i] = VS::get_singleton()->instance_create2(grid[i], get_tree()->get_root()->get_world()->get_scenario());
  875. VS::get_singleton()->instance_set_layer_mask(grid_instance[i], 1 << SpatialEditorViewport::MISC_TOOL_LAYER);
  876. selection_level_instance[i] = VisualServer::get_singleton()->instance_create2(selection_level_mesh[i], get_tree()->get_root()->get_world()->get_scenario());
  877. VS::get_singleton()->instance_set_layer_mask(selection_level_instance[i], 1 << SpatialEditorViewport::MISC_TOOL_LAYER);
  878. }
  879. selection_instance = VisualServer::get_singleton()->instance_create2(selection_mesh, get_tree()->get_root()->get_world()->get_scenario());
  880. VS::get_singleton()->instance_set_layer_mask(selection_instance, 1 << SpatialEditorViewport::MISC_TOOL_LAYER);
  881. paste_instance = VisualServer::get_singleton()->instance_create2(paste_mesh, get_tree()->get_root()->get_world()->get_scenario());
  882. VS::get_singleton()->instance_set_layer_mask(paste_instance, 1 << SpatialEditorViewport::MISC_TOOL_LAYER);
  883. _update_selection_transform();
  884. _update_paste_indicator();
  885. } break;
  886. case NOTIFICATION_EXIT_TREE: {
  887. get_tree()->disconnect("node_removed", this, "_node_removed");
  888. _clear_clipboard_data();
  889. for (int i = 0; i < 3; i++) {
  890. if (grid_instance[i].is_valid()) {
  891. VS::get_singleton()->free(grid_instance[i]);
  892. grid_instance[i] = RID();
  893. }
  894. if (grid[i].is_valid()) {
  895. VS::get_singleton()->free(grid[i]);
  896. grid[i] = RID();
  897. }
  898. if (selection_level_instance[i].is_valid()) {
  899. VS::get_singleton()->free(selection_level_instance[i]);
  900. selection_level_instance[i] = RID();
  901. }
  902. }
  903. if (selection_instance.is_valid()) {
  904. VS::get_singleton()->free(selection_instance);
  905. selection_instance = RID();
  906. }
  907. if (paste_instance.is_valid()) {
  908. VS::get_singleton()->free(paste_instance);
  909. paste_instance = RID();
  910. }
  911. } break;
  912. case NOTIFICATION_PROCESS: {
  913. if (!node) {
  914. return;
  915. }
  916. Transform xf = node->get_global_transform();
  917. if (xf != grid_xform) {
  918. for (int i = 0; i < 3; i++) {
  919. VS::get_singleton()->instance_set_transform(grid_instance[i], xf * edit_grid_xform);
  920. }
  921. grid_xform = xf;
  922. }
  923. Ref<MeshLibrary> cgmt = node->get_mesh_library();
  924. if (cgmt.operator->() != last_mesh_library) {
  925. update_palette();
  926. }
  927. if (lock_view) {
  928. EditorNode *editor = Object::cast_to<EditorNode>(get_tree()->get_root()->get_child(0));
  929. Plane p;
  930. p.normal[edit_axis] = 1.0;
  931. p.d = edit_floor[edit_axis] * node->get_cell_size()[edit_axis];
  932. p = node->get_transform().xform(p); // plane to snap
  933. SpatialEditorPlugin *sep = Object::cast_to<SpatialEditorPlugin>(editor->get_editor_plugin_screen());
  934. if (sep) {
  935. sep->snap_cursor_to_plane(p);
  936. }
  937. }
  938. } break;
  939. case NOTIFICATION_THEME_CHANGED: {
  940. options->set_icon(get_icon("GridMap", "EditorIcons"));
  941. search_box->set_right_icon(get_icon("Search", "EditorIcons"));
  942. } break;
  943. case NOTIFICATION_WM_FOCUS_OUT: {
  944. if (input_action == INPUT_PAINT) {
  945. // Simulate mouse released event to stop drawing when editor focus exists.
  946. Ref<InputEventMouseButton> release;
  947. release.instance();
  948. release->set_button_index(BUTTON_LEFT);
  949. forward_spatial_input_event(nullptr, release);
  950. }
  951. } break;
  952. }
  953. }
  954. void GridMapEditor::_update_cursor_instance() {
  955. if (!node) {
  956. return;
  957. }
  958. if (cursor_instance.is_valid()) {
  959. VisualServer::get_singleton()->free(cursor_instance);
  960. cursor_instance = RID();
  961. }
  962. if (selected_palette >= 0) {
  963. if (node && !node->get_mesh_library().is_null()) {
  964. Ref<Mesh> mesh = node->get_mesh_library()->get_item_mesh(selected_palette);
  965. if (!mesh.is_null() && mesh->get_rid().is_valid()) {
  966. cursor_instance = VisualServer::get_singleton()->instance_create2(mesh->get_rid(), get_tree()->get_root()->get_world()->get_scenario());
  967. VisualServer::get_singleton()->instance_set_transform(cursor_instance, cursor_transform);
  968. }
  969. }
  970. }
  971. }
  972. void GridMapEditor::_item_selected_cbk(int idx) {
  973. selected_palette = mesh_library_palette->get_item_metadata(idx);
  974. _update_cursor_instance();
  975. }
  976. void GridMapEditor::_floor_changed(float p_value) {
  977. if (updating) {
  978. return;
  979. }
  980. edit_floor[edit_axis] = p_value;
  981. node->set_meta("_editor_floor_", Vector3(edit_floor[0], edit_floor[1], edit_floor[2]));
  982. update_grid();
  983. _update_clip();
  984. _update_selection_transform();
  985. }
  986. void GridMapEditor::_floor_mouse_exited() {
  987. floor->get_line_edit()->release_focus();
  988. }
  989. void GridMapEditor::_bind_methods() {
  990. ClassDB::bind_method("_text_changed", &GridMapEditor::_text_changed);
  991. ClassDB::bind_method("_sbox_input", &GridMapEditor::_sbox_input);
  992. ClassDB::bind_method("_mesh_library_palette_input", &GridMapEditor::_mesh_library_palette_input);
  993. ClassDB::bind_method("_icon_size_changed", &GridMapEditor::_icon_size_changed);
  994. ClassDB::bind_method("_menu_option", &GridMapEditor::_menu_option);
  995. ClassDB::bind_method("_configure", &GridMapEditor::_configure);
  996. ClassDB::bind_method("_item_selected_cbk", &GridMapEditor::_item_selected_cbk);
  997. ClassDB::bind_method("_floor_changed", &GridMapEditor::_floor_changed);
  998. ClassDB::bind_method("_floor_mouse_exited", &GridMapEditor::_floor_mouse_exited);
  999. ClassDB::bind_method("_set_selection", &GridMapEditor::_set_selection);
  1000. ClassDB::bind_method("_node_removed", &GridMapEditor::_node_removed);
  1001. ClassDB::bind_method(D_METHOD("_set_display_mode", "mode"), &GridMapEditor::_set_display_mode);
  1002. ClassDB::bind_method("_draw_grids", &GridMapEditor::_draw_grids);
  1003. }
  1004. GridMapEditor::GridMapEditor(EditorNode *p_editor) {
  1005. input_action = INPUT_NONE;
  1006. node = nullptr;
  1007. editor = p_editor;
  1008. undo_redo = p_editor->get_undo_redo();
  1009. int mw = EDITOR_DEF("editors/grid_map/palette_min_width", 230);
  1010. Control *ec = memnew(Control);
  1011. ec->set_custom_minimum_size(Size2(mw, 0) * EDSCALE);
  1012. add_child(ec);
  1013. spatial_editor_hb = memnew(HBoxContainer);
  1014. spatial_editor_hb->set_h_size_flags(SIZE_EXPAND_FILL);
  1015. spatial_editor_hb->set_alignment(BoxContainer::ALIGN_END);
  1016. SpatialEditor::get_singleton()->add_control_to_menu_panel(spatial_editor_hb);
  1017. spin_box_label = memnew(Label);
  1018. spin_box_label->set_text(TTR("Floor:"));
  1019. spatial_editor_hb->add_child(spin_box_label);
  1020. floor = memnew(SpinBox);
  1021. floor->set_min(-32767);
  1022. floor->set_max(32767);
  1023. floor->set_step(1);
  1024. floor->get_line_edit()->add_constant_override("minimum_spaces", 16);
  1025. spatial_editor_hb->add_child(floor);
  1026. floor->connect("value_changed", this, "_floor_changed");
  1027. floor->connect("mouse_exited", this, "_floor_mouse_exited");
  1028. floor->get_line_edit()->connect("mouse_exited", this, "_floor_mouse_exited");
  1029. spatial_editor_hb->add_child(memnew(VSeparator));
  1030. options = memnew(MenuButton);
  1031. spatial_editor_hb->add_child(options);
  1032. spatial_editor_hb->hide();
  1033. options->set_text(TTR("Grid Map"));
  1034. options->get_popup()->add_check_item(TTR("Snap View"), MENU_OPTION_LOCK_VIEW);
  1035. options->get_popup()->add_separator();
  1036. options->get_popup()->add_item(TTR("Previous Floor"), MENU_OPTION_PREV_LEVEL, KEY_Q);
  1037. options->get_popup()->add_item(TTR("Next Floor"), MENU_OPTION_NEXT_LEVEL, KEY_E);
  1038. options->get_popup()->add_separator();
  1039. options->get_popup()->add_radio_check_item(TTR("Clip Disabled"), MENU_OPTION_CLIP_DISABLED);
  1040. options->get_popup()->set_item_checked(options->get_popup()->get_item_index(MENU_OPTION_CLIP_DISABLED), true);
  1041. options->get_popup()->add_radio_check_item(TTR("Clip Above"), MENU_OPTION_CLIP_ABOVE);
  1042. options->get_popup()->add_radio_check_item(TTR("Clip Below"), MENU_OPTION_CLIP_BELOW);
  1043. options->get_popup()->add_separator();
  1044. options->get_popup()->add_radio_check_item(TTR("Edit X Axis"), MENU_OPTION_X_AXIS, KEY_Z);
  1045. options->get_popup()->add_radio_check_item(TTR("Edit Y Axis"), MENU_OPTION_Y_AXIS, KEY_X);
  1046. options->get_popup()->add_radio_check_item(TTR("Edit Z Axis"), MENU_OPTION_Z_AXIS, KEY_C);
  1047. options->get_popup()->set_item_checked(options->get_popup()->get_item_index(MENU_OPTION_Y_AXIS), true);
  1048. options->get_popup()->add_separator();
  1049. options->get_popup()->add_item(TTR("Cursor Rotate X"), MENU_OPTION_CURSOR_ROTATE_X, KEY_A);
  1050. options->get_popup()->add_item(TTR("Cursor Rotate Y"), MENU_OPTION_CURSOR_ROTATE_Y, KEY_S);
  1051. options->get_popup()->add_item(TTR("Cursor Rotate Z"), MENU_OPTION_CURSOR_ROTATE_Z, KEY_D);
  1052. options->get_popup()->add_item(TTR("Cursor Back Rotate X"), MENU_OPTION_CURSOR_BACK_ROTATE_X, KEY_MASK_SHIFT + KEY_A);
  1053. options->get_popup()->add_item(TTR("Cursor Back Rotate Y"), MENU_OPTION_CURSOR_BACK_ROTATE_Y, KEY_MASK_SHIFT + KEY_S);
  1054. options->get_popup()->add_item(TTR("Cursor Back Rotate Z"), MENU_OPTION_CURSOR_BACK_ROTATE_Z, KEY_MASK_SHIFT + KEY_D);
  1055. options->get_popup()->add_item(TTR("Cursor Clear Rotation"), MENU_OPTION_CURSOR_CLEAR_ROTATION, KEY_W);
  1056. options->get_popup()->add_separator();
  1057. options->get_popup()->add_check_item(TTR("Paste Selects"), MENU_OPTION_PASTE_SELECTS);
  1058. options->get_popup()->add_separator();
  1059. options->get_popup()->add_item(TTR("Duplicate Selection"), MENU_OPTION_SELECTION_DUPLICATE, KEY_MASK_CTRL + KEY_C);
  1060. options->get_popup()->add_item(TTR("Cut Selection"), MENU_OPTION_SELECTION_CUT, KEY_MASK_CTRL + KEY_X);
  1061. options->get_popup()->add_item(TTR("Clear Selection"), MENU_OPTION_SELECTION_CLEAR, KEY_DELETE);
  1062. options->get_popup()->add_item(TTR("Fill Selection"), MENU_OPTION_SELECTION_FILL, KEY_MASK_CTRL + KEY_F);
  1063. options->get_popup()->add_separator();
  1064. options->get_popup()->add_item(TTR("Settings..."), MENU_OPTION_GRIDMAP_SETTINGS);
  1065. settings_dialog = memnew(ConfirmationDialog);
  1066. settings_dialog->set_title(TTR("GridMap Settings"));
  1067. add_child(settings_dialog);
  1068. settings_vbc = memnew(VBoxContainer);
  1069. settings_vbc->set_custom_minimum_size(Size2(200, 0) * EDSCALE);
  1070. settings_dialog->add_child(settings_vbc);
  1071. settings_pick_distance = memnew(SpinBox);
  1072. settings_pick_distance->set_max(10000.0f);
  1073. settings_pick_distance->set_min(500.0f);
  1074. settings_pick_distance->set_step(1.0f);
  1075. settings_pick_distance->set_value(EDITOR_DEF("editors/grid_map/pick_distance", 5000.0));
  1076. settings_vbc->add_margin_child(TTR("Pick Distance:"), settings_pick_distance);
  1077. clip_mode = CLIP_DISABLED;
  1078. options->get_popup()->connect("id_pressed", this, "_menu_option");
  1079. HBoxContainer *hb = memnew(HBoxContainer);
  1080. add_child(hb);
  1081. hb->set_h_size_flags(SIZE_EXPAND_FILL);
  1082. search_box = memnew(LineEdit);
  1083. search_box->set_h_size_flags(SIZE_EXPAND_FILL);
  1084. search_box->set_placeholder(TTR("Filter meshes"));
  1085. hb->add_child(search_box);
  1086. search_box->connect("text_changed", this, "_text_changed");
  1087. search_box->connect("gui_input", this, "_sbox_input");
  1088. mode_thumbnail = memnew(ToolButton);
  1089. mode_thumbnail->set_toggle_mode(true);
  1090. mode_thumbnail->set_pressed(true);
  1091. mode_thumbnail->set_icon(p_editor->get_gui_base()->get_icon("FileThumbnail", "EditorIcons"));
  1092. hb->add_child(mode_thumbnail);
  1093. mode_thumbnail->connect("pressed", this, "_set_display_mode", varray(DISPLAY_THUMBNAIL));
  1094. mode_list = memnew(ToolButton);
  1095. mode_list->set_toggle_mode(true);
  1096. mode_list->set_pressed(false);
  1097. mode_list->set_icon(p_editor->get_gui_base()->get_icon("FileList", "EditorIcons"));
  1098. hb->add_child(mode_list);
  1099. mode_list->connect("pressed", this, "_set_display_mode", varray(DISPLAY_LIST));
  1100. size_slider = memnew(HSlider);
  1101. size_slider->set_h_size_flags(SIZE_EXPAND_FILL);
  1102. size_slider->set_min(0.2f);
  1103. size_slider->set_max(4.0f);
  1104. size_slider->set_step(0.1f);
  1105. size_slider->set_value(1.0f);
  1106. size_slider->connect("value_changed", this, "_icon_size_changed");
  1107. add_child(size_slider);
  1108. EDITOR_DEF("editors/grid_map/preview_size", 64);
  1109. display_mode = DISPLAY_THUMBNAIL;
  1110. mesh_library_palette = memnew(ItemList);
  1111. add_child(mesh_library_palette);
  1112. mesh_library_palette->set_v_size_flags(SIZE_EXPAND_FILL);
  1113. mesh_library_palette->connect("gui_input", this, "_mesh_library_palette_input");
  1114. info_message = memnew(Label);
  1115. info_message->set_text(TTR("Give a MeshLibrary resource to this GridMap to use its meshes."));
  1116. info_message->set_valign(Label::VALIGN_CENTER);
  1117. info_message->set_align(Label::ALIGN_CENTER);
  1118. info_message->set_autowrap(true);
  1119. info_message->set_custom_minimum_size(Size2(100 * EDSCALE, 0));
  1120. info_message->set_anchors_and_margins_preset(PRESET_WIDE, PRESET_MODE_KEEP_SIZE, 8 * EDSCALE);
  1121. mesh_library_palette->add_child(info_message);
  1122. edit_axis = Vector3::AXIS_Y;
  1123. edit_floor[0] = -1;
  1124. edit_floor[1] = -1;
  1125. edit_floor[2] = -1;
  1126. cursor_visible = false;
  1127. selected_palette = -1;
  1128. lock_view = false;
  1129. cursor_rot = 0;
  1130. selection_mesh = VisualServer::get_singleton()->mesh_create();
  1131. paste_mesh = VisualServer::get_singleton()->mesh_create();
  1132. {
  1133. // Selection mesh create.
  1134. PoolVector<Vector3> lines;
  1135. PoolVector<Vector3> triangles;
  1136. PoolVector<Vector3> square[3];
  1137. for (int i = 0; i < 6; i++) {
  1138. Vector3 face_points[4];
  1139. for (int j = 0; j < 4; j++) {
  1140. float v[3];
  1141. v[0] = 1.0;
  1142. v[1] = 1 - 2 * ((j >> 1) & 1);
  1143. v[2] = v[1] * (1 - 2 * (j & 1));
  1144. for (int k = 0; k < 3; k++) {
  1145. if (i < 3) {
  1146. face_points[j][(i + k) % 3] = v[k];
  1147. } else {
  1148. face_points[3 - j][(i + k) % 3] = -v[k];
  1149. }
  1150. }
  1151. }
  1152. triangles.push_back(face_points[0] * 0.5 + Vector3(0.5, 0.5, 0.5));
  1153. triangles.push_back(face_points[1] * 0.5 + Vector3(0.5, 0.5, 0.5));
  1154. triangles.push_back(face_points[2] * 0.5 + Vector3(0.5, 0.5, 0.5));
  1155. triangles.push_back(face_points[2] * 0.5 + Vector3(0.5, 0.5, 0.5));
  1156. triangles.push_back(face_points[3] * 0.5 + Vector3(0.5, 0.5, 0.5));
  1157. triangles.push_back(face_points[0] * 0.5 + Vector3(0.5, 0.5, 0.5));
  1158. }
  1159. for (int i = 0; i < 12; i++) {
  1160. AABB base(Vector3(0, 0, 0), Vector3(1, 1, 1));
  1161. Vector3 a, b;
  1162. base.get_edge(i, a, b);
  1163. lines.push_back(a);
  1164. lines.push_back(b);
  1165. }
  1166. for (int i = 0; i < 3; i++) {
  1167. Vector3 points[4];
  1168. for (int j = 0; j < 4; j++) {
  1169. static const bool orderx[4] = { false, true, true, false };
  1170. static const bool ordery[4] = { false, false, true, true };
  1171. Vector3 sp;
  1172. if (orderx[j]) {
  1173. sp[(i + 1) % 3] = 1.0;
  1174. }
  1175. if (ordery[j]) {
  1176. sp[(i + 2) % 3] = 1.0;
  1177. }
  1178. points[j] = sp;
  1179. }
  1180. for (int j = 0; j < 4; j++) {
  1181. Vector3 ofs;
  1182. ofs[i] += 0.01;
  1183. square[i].push_back(points[j] - ofs);
  1184. square[i].push_back(points[(j + 1) % 4] - ofs);
  1185. square[i].push_back(points[j] + ofs);
  1186. square[i].push_back(points[(j + 1) % 4] + ofs);
  1187. }
  1188. }
  1189. Array d;
  1190. d.resize(VS::ARRAY_MAX);
  1191. inner_mat.instance();
  1192. inner_mat->set_albedo(Color(0.7, 0.7, 1.0, 0.2));
  1193. inner_mat->set_flag(SpatialMaterial::FLAG_UNSHADED, true);
  1194. inner_mat->set_feature(SpatialMaterial::FEATURE_TRANSPARENT, true);
  1195. d[VS::ARRAY_VERTEX] = triangles;
  1196. VisualServer::get_singleton()->mesh_add_surface_from_arrays(selection_mesh, VS::PRIMITIVE_TRIANGLES, d);
  1197. VisualServer::get_singleton()->mesh_surface_set_material(selection_mesh, 0, inner_mat->get_rid());
  1198. outer_mat.instance();
  1199. outer_mat->set_albedo(Color(0.7, 0.7, 1.0, 0.8));
  1200. outer_mat->set_on_top_of_alpha();
  1201. outer_mat->set_flag(SpatialMaterial::FLAG_UNSHADED, true);
  1202. outer_mat->set_line_width(3.0);
  1203. outer_mat->set_feature(SpatialMaterial::FEATURE_TRANSPARENT, true);
  1204. selection_floor_mat.instance();
  1205. selection_floor_mat->set_albedo(Color(0.80, 0.80, 1.0, 1));
  1206. selection_floor_mat->set_on_top_of_alpha();
  1207. selection_floor_mat->set_flag(SpatialMaterial::FLAG_UNSHADED, true);
  1208. selection_floor_mat->set_line_width(3.0);
  1209. d[VS::ARRAY_VERTEX] = lines;
  1210. VisualServer::get_singleton()->mesh_add_surface_from_arrays(selection_mesh, VS::PRIMITIVE_LINES, d);
  1211. VisualServer::get_singleton()->mesh_surface_set_material(selection_mesh, 1, outer_mat->get_rid());
  1212. d[VS::ARRAY_VERTEX] = triangles;
  1213. VisualServer::get_singleton()->mesh_add_surface_from_arrays(paste_mesh, VS::PRIMITIVE_TRIANGLES, d);
  1214. VisualServer::get_singleton()->mesh_surface_set_material(paste_mesh, 0, inner_mat->get_rid());
  1215. d[VS::ARRAY_VERTEX] = lines;
  1216. VisualServer::get_singleton()->mesh_add_surface_from_arrays(paste_mesh, VS::PRIMITIVE_LINES, d);
  1217. VisualServer::get_singleton()->mesh_surface_set_material(paste_mesh, 1, outer_mat->get_rid());
  1218. for (int i = 0; i < 3; i++) {
  1219. d[VS::ARRAY_VERTEX] = square[i];
  1220. selection_level_mesh[i] = VS::get_singleton()->mesh_create();
  1221. VisualServer::get_singleton()->mesh_add_surface_from_arrays(selection_level_mesh[i], VS::PRIMITIVE_LINES, d);
  1222. VisualServer::get_singleton()->mesh_surface_set_material(selection_level_mesh[i], 0, selection_floor_mat->get_rid());
  1223. }
  1224. }
  1225. _set_selection(false);
  1226. updating = false;
  1227. accumulated_floor_delta = 0.0;
  1228. indicator_mat.instance();
  1229. indicator_mat->set_flag(SpatialMaterial::FLAG_UNSHADED, true);
  1230. indicator_mat->set_feature(SpatialMaterial::FEATURE_TRANSPARENT, true);
  1231. indicator_mat->set_flag(SpatialMaterial::FLAG_SRGB_VERTEX_COLOR, true);
  1232. indicator_mat->set_flag(SpatialMaterial::FLAG_ALBEDO_FROM_VERTEX_COLOR, true);
  1233. indicator_mat->set_albedo(Color(0.8, 0.5, 0.1));
  1234. }
  1235. GridMapEditor::~GridMapEditor() {
  1236. _clear_clipboard_data();
  1237. for (int i = 0; i < 3; i++) {
  1238. if (grid[i].is_valid()) {
  1239. VisualServer::get_singleton()->free(grid[i]);
  1240. }
  1241. if (grid_instance[i].is_valid()) {
  1242. VisualServer::get_singleton()->free(grid_instance[i]);
  1243. }
  1244. if (cursor_instance.is_valid()) {
  1245. VisualServer::get_singleton()->free(cursor_instance);
  1246. }
  1247. if (selection_level_instance[i].is_valid()) {
  1248. VisualServer::get_singleton()->free(selection_level_instance[i]);
  1249. }
  1250. if (selection_level_mesh[i].is_valid()) {
  1251. VisualServer::get_singleton()->free(selection_level_mesh[i]);
  1252. }
  1253. }
  1254. if (selection_mesh.is_valid()) {
  1255. VisualServer::get_singleton()->free(selection_mesh);
  1256. }
  1257. if (selection_instance.is_valid()) {
  1258. VisualServer::get_singleton()->free(selection_instance);
  1259. }
  1260. if (paste_mesh.is_valid()) {
  1261. VisualServer::get_singleton()->free(paste_mesh);
  1262. }
  1263. if (paste_instance.is_valid()) {
  1264. VisualServer::get_singleton()->free(paste_instance);
  1265. }
  1266. }
  1267. void GridMapEditorPlugin::_notification(int p_what) {
  1268. if (p_what == EditorSettings::NOTIFICATION_EDITOR_SETTINGS_CHANGED) {
  1269. switch ((int)EditorSettings::get_singleton()->get("editors/grid_map/editor_side")) {
  1270. case 0: { // Left.
  1271. SpatialEditor::get_singleton()->get_palette_split()->move_child(grid_map_editor, 0);
  1272. } break;
  1273. case 1: { // Right.
  1274. SpatialEditor::get_singleton()->get_palette_split()->move_child(grid_map_editor, 1);
  1275. } break;
  1276. }
  1277. }
  1278. }
  1279. void GridMapEditorPlugin::edit(Object *p_object) {
  1280. grid_map_editor->edit(Object::cast_to<GridMap>(p_object));
  1281. }
  1282. bool GridMapEditorPlugin::handles(Object *p_object) const {
  1283. return p_object->is_class("GridMap");
  1284. }
  1285. void GridMapEditorPlugin::make_visible(bool p_visible) {
  1286. if (p_visible) {
  1287. grid_map_editor->show();
  1288. grid_map_editor->spatial_editor_hb->show();
  1289. grid_map_editor->set_process(true);
  1290. } else {
  1291. grid_map_editor->spatial_editor_hb->hide();
  1292. grid_map_editor->hide();
  1293. grid_map_editor->edit(nullptr);
  1294. grid_map_editor->set_process(false);
  1295. }
  1296. }
  1297. GridMapEditorPlugin::GridMapEditorPlugin(EditorNode *p_node) {
  1298. editor = p_node;
  1299. EDITOR_DEF("editors/grid_map/editor_side", 1);
  1300. EditorSettings::get_singleton()->add_property_hint(PropertyInfo(Variant::INT, "editors/grid_map/editor_side", PROPERTY_HINT_ENUM, "Left,Right"));
  1301. grid_map_editor = memnew(GridMapEditor(editor));
  1302. switch ((int)EditorSettings::get_singleton()->get("editors/grid_map/editor_side")) {
  1303. case 0: { // Left.
  1304. add_control_to_container(CONTAINER_SPATIAL_EDITOR_SIDE_LEFT, grid_map_editor);
  1305. } break;
  1306. case 1: { // Right.
  1307. add_control_to_container(CONTAINER_SPATIAL_EDITOR_SIDE_RIGHT, grid_map_editor);
  1308. } break;
  1309. }
  1310. grid_map_editor->hide();
  1311. }
  1312. GridMapEditorPlugin::~GridMapEditorPlugin() {
  1313. }