diff options
Diffstat (limited to 'modules/gridmap')
-rw-r--r-- | modules/gridmap/grid_map.cpp | 55 | ||||
-rw-r--r-- | modules/gridmap/grid_map.h | 2 | ||||
-rw-r--r-- | modules/gridmap/grid_map_editor_plugin.cpp | 102 | ||||
-rw-r--r-- | modules/gridmap/grid_map_editor_plugin.h | 9 |
4 files changed, 89 insertions, 79 deletions
diff --git a/modules/gridmap/grid_map.cpp b/modules/gridmap/grid_map.cpp index 3d40220869..84075f76fd 100644 --- a/modules/gridmap/grid_map.cpp +++ b/modules/gridmap/grid_map.cpp @@ -36,6 +36,7 @@ #include "scene/resources/mesh_library.h" #include "scene/resources/surface_tool.h" #include "scene/scene_string_names.h" +#include "servers/navigation_server.h" #include "servers/visual_server.h" bool GridMap::_set(const StringName &p_name, const Variant &p_value) { @@ -48,9 +49,9 @@ bool GridMap::_set(const StringName &p_name, const Variant &p_value) { if (d.has("cells")) { - PoolVector<int> cells = d["cells"]; + Vector<int> cells = d["cells"]; int amount = cells.size(); - PoolVector<int>::Read r = cells.read(); + const int *r = cells.ptr(); ERR_FAIL_COND_V(amount % 3, false); // not even cell_map.clear(); for (int i = 0; i < amount / 3; i++) { @@ -102,10 +103,10 @@ bool GridMap::_get(const StringName &p_name, Variant &r_ret) const { Dictionary d; - PoolVector<int> cells; + Vector<int> cells; cells.resize(cell_map.size() * 3); { - PoolVector<int>::Write w = cells.write(); + int *w = cells.ptrw(); int i = 0; for (Map<IndexKey, Cell>::Element *E = cell_map.front(); E; E = E->next(), i++) { @@ -418,12 +419,10 @@ bool GridMap::_octant_update(const OctantKey &p_key) { } //erase navigation - if (navigation) { - for (Map<IndexKey, Octant::NavMesh>::Element *E = g.navmesh_ids.front(); E; E = E->next()) { - navigation->navmesh_remove(E->get().id); - } - g.navmesh_ids.clear(); + for (Map<IndexKey, Octant::NavMesh>::Element *E = g.navmesh_ids.front(); E; E = E->next()) { + NavigationServer::get_singleton()->free(E->get().region); } + g.navmesh_ids.clear(); //erase multimeshes @@ -440,7 +439,7 @@ bool GridMap::_octant_update(const OctantKey &p_key) { return true; } - PoolVector<Vector3> col_debug; + Vector<Vector3> col_debug; /* * foreach item in this octant, @@ -498,9 +497,11 @@ bool GridMap::_octant_update(const OctantKey &p_key) { nm.xform = xform * mesh_library->get_item_navmesh_transform(c.item); if (navigation) { - nm.id = navigation->navmesh_add(navmesh, xform, this); - } else { - nm.id = -1; + RID region = NavigationServer::get_singleton()->region_create(); + NavigationServer::get_singleton()->region_set_navmesh(region, navmesh); + NavigationServer::get_singleton()->region_set_transform(region, navigation->get_global_transform() * nm.xform); + NavigationServer::get_singleton()->region_set_map(region, navigation->get_rid()); + nm.region = region; } g.navmesh_ids[E->get()] = nm; } @@ -513,7 +514,7 @@ bool GridMap::_octant_update(const OctantKey &p_key) { Octant::MultimeshInstance mmi; RID mm = VS::get_singleton()->multimesh_create(); - VS::get_singleton()->multimesh_allocate(mm, E->get().size(), VS::MULTIMESH_TRANSFORM_3D, VS::MULTIMESH_COLOR_NONE); + VS::get_singleton()->multimesh_allocate(mm, E->get().size(), VS::MULTIMESH_TRANSFORM_3D); VS::get_singleton()->multimesh_set_mesh(mm, mesh_library->get_item_mesh(E->key())->get_rid()); int idx = 0; @@ -591,10 +592,14 @@ void GridMap::_octant_enter_world(const OctantKey &p_key) { if (navigation && mesh_library.is_valid()) { for (Map<IndexKey, Octant::NavMesh>::Element *F = g.navmesh_ids.front(); F; F = F->next()) { - if (cell_map.has(F->key()) && F->get().id < 0) { + if (cell_map.has(F->key()) && F->get().region.is_valid() == false) { Ref<NavigationMesh> nm = mesh_library->get_item_navmesh(cell_map[F->key()].item); if (nm.is_valid()) { - F->get().id = navigation->navmesh_add(nm, F->get().xform, this); + RID region = NavigationServer::get_singleton()->region_create(); + NavigationServer::get_singleton()->region_set_navmesh(region, nm); + NavigationServer::get_singleton()->region_set_transform(region, navigation->get_global_transform() * F->get().xform); + NavigationServer::get_singleton()->region_set_map(region, navigation->get_rid()); + F->get().region = region; } } } @@ -620,9 +625,9 @@ void GridMap::_octant_exit_world(const OctantKey &p_key) { if (navigation) { for (Map<IndexKey, Octant::NavMesh>::Element *F = g.navmesh_ids.front(); F; F = F->next()) { - if (F->get().id >= 0) { - navigation->navmesh_remove(F->get().id); - F->get().id = -1; + if (F->get().region.is_valid()) { + NavigationServer::get_singleton()->free(F->get().region); + F->get().region = RID(); } } } @@ -640,13 +645,11 @@ void GridMap::_octant_clean_up(const OctantKey &p_key) { PhysicsServer::get_singleton()->free(g.static_body); - //erase navigation - if (navigation) { - for (Map<IndexKey, Octant::NavMesh>::Element *E = g.navmesh_ids.front(); E; E = E->next()) { - navigation->navmesh_remove(E->get().id); - } - g.navmesh_ids.clear(); + // Erase navigation + for (Map<IndexKey, Octant::NavMesh>::Element *E = g.navmesh_ids.front(); E; E = E->next()) { + NavigationServer::get_singleton()->free(E->get().region); } + g.navmesh_ids.clear(); //erase multimeshes @@ -871,7 +874,7 @@ void GridMap::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::BOOL, "cell_center_x"), "set_center_x", "get_center_x"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "cell_center_y"), "set_center_y", "get_center_y"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "cell_center_z"), "set_center_z", "get_center_z"); - ADD_PROPERTY(PropertyInfo(Variant::REAL, "cell_scale"), "set_cell_scale", "get_cell_scale"); + ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "cell_scale"), "set_cell_scale", "get_cell_scale"); ADD_GROUP("Collision", "collision_"); ADD_PROPERTY(PropertyInfo(Variant::INT, "collision_layer", PROPERTY_HINT_LAYERS_3D_PHYSICS), "set_collision_layer", "get_collision_layer"); ADD_PROPERTY(PropertyInfo(Variant::INT, "collision_mask", PROPERTY_HINT_LAYERS_3D_PHYSICS), "set_collision_mask", "get_collision_mask"); diff --git a/modules/gridmap/grid_map.h b/modules/gridmap/grid_map.h index 705f4929e1..cc1c8c2923 100644 --- a/modules/gridmap/grid_map.h +++ b/modules/gridmap/grid_map.h @@ -91,7 +91,7 @@ class GridMap : public Spatial { struct Octant { struct NavMesh { - int id; + RID region; Transform xform; }; diff --git a/modules/gridmap/grid_map_editor_plugin.cpp b/modules/gridmap/grid_map_editor_plugin.cpp index 4aa407f966..a656ee8b63 100644 --- a/modules/gridmap/grid_map_editor_plugin.cpp +++ b/modules/gridmap/grid_map_editor_plugin.cpp @@ -752,7 +752,7 @@ bool GridMapEditor::forward_spatial_input_event(Camera *p_camera, const Ref<Inpu if (k.is_valid()) { if (k->is_pressed()) { - if (k->get_scancode() == KEY_ESCAPE) { + if (k->get_keycode() == KEY_ESCAPE) { if (input_action == INPUT_PASTE) { _clear_clipboard_data(); @@ -773,12 +773,12 @@ bool GridMapEditor::forward_spatial_input_event(Camera *p_camera, const Ref<Inpu if (k->get_shift() && selection.active && input_action != INPUT_PASTE) { - if (k->get_scancode() == options->get_popup()->get_item_accelerator(options->get_popup()->get_item_index(MENU_OPTION_PREV_LEVEL))) { + if (k->get_keycode() == options->get_popup()->get_item_accelerator(options->get_popup()->get_item_index(MENU_OPTION_PREV_LEVEL))) { selection.click[edit_axis]--; _validate_selection(); return true; } - if (k->get_scancode() == options->get_popup()->get_item_accelerator(options->get_popup()->get_item_index(MENU_OPTION_NEXT_LEVEL))) { + if (k->get_keycode() == options->get_popup()->get_item_accelerator(options->get_popup()->get_item_index(MENU_OPTION_NEXT_LEVEL))) { selection.click[edit_axis]++; _validate_selection(); return true; @@ -840,15 +840,33 @@ void GridMapEditor::_text_changed(const String &p_text) { void GridMapEditor::_sbox_input(const Ref<InputEvent> &p_ie) { - Ref<InputEventKey> k = p_ie; + const Ref<InputEventKey> k = p_ie; - if (k.is_valid() && (k->get_scancode() == KEY_UP || k->get_scancode() == KEY_DOWN || k->get_scancode() == KEY_PAGEUP || k->get_scancode() == KEY_PAGEDOWN)) { + if (k.is_valid() && (k->get_keycode() == KEY_UP || k->get_keycode() == KEY_DOWN || k->get_keycode() == KEY_PAGEUP || k->get_keycode() == KEY_PAGEDOWN)) { + // Forward the key input to the ItemList so it can be scrolled mesh_library_palette->call("_gui_input", k); search_box->accept_event(); } } +void GridMapEditor::_mesh_library_palette_input(const Ref<InputEvent> &p_ie) { + + const Ref<InputEventMouseButton> mb = p_ie; + + // Zoom in/out using Ctrl + mouse wheel + if (mb.is_valid() && mb->is_pressed() && mb->get_command()) { + + if (mb->is_pressed() && mb->get_button_index() == BUTTON_WHEEL_UP) { + size_slider->set_value(size_slider->get_value() + 0.2); + } + + if (mb->is_pressed() && mb->get_button_index() == BUTTON_WHEEL_DOWN) { + size_slider->set_value(size_slider->get_value() - 0.2); + } + } +} + void GridMapEditor::_icon_size_changed(float p_value) { mesh_library_palette->set_icon_scale(p_value); update_palette(); @@ -907,7 +925,7 @@ void GridMapEditor::update_palette() { for (List<_CGMEItemSort>::Element *E = il.front(); E; E = E->next()) { int id = E->get().id; String name = mesh_library->get_item_name(id); - Ref<Texture> preview = mesh_library->get_item_preview(id); + Ref<Texture2D> preview = mesh_library->get_item_preview(id); if (name == "") { name = "#" + itos(id); @@ -936,7 +954,7 @@ void GridMapEditor::update_palette() { void GridMapEditor::edit(GridMap *p_gridmap) { if (!p_gridmap && node) - node->disconnect("cell_size_changed", this, "_draw_grids"); + node->disconnect("cell_size_changed", callable_mp(this, &GridMapEditor::_draw_grids)); node = p_gridmap; @@ -970,7 +988,7 @@ void GridMapEditor::edit(GridMap *p_gridmap) { update_grid(); _update_clip(); - node->connect("cell_size_changed", this, "_draw_grids"); + node->connect("cell_size_changed", callable_mp(this, &GridMapEditor::_draw_grids)); } void GridMapEditor::_update_clip() { @@ -1004,8 +1022,7 @@ void GridMapEditor::_draw_grids(const Vector3 &cell_size) { Vector3 edited_floor = node->has_meta("_editor_floor_") ? node->get_meta("_editor_floor_") : Variant(); for (int i = 0; i < 3; i++) { - if (VS::get_singleton()->mesh_get_surface_count(grid[i]) > 0) - VS::get_singleton()->mesh_remove_surface(grid[i], 0); + VS::get_singleton()->mesh_clear(grid[i]); edit_floor[i] = edited_floor[i]; } @@ -1060,8 +1077,8 @@ void GridMapEditor::_notification(int p_what) { switch (p_what) { case NOTIFICATION_ENTER_TREE: { - get_tree()->connect("node_removed", this, "_node_removed"); - mesh_library_palette->connect("item_selected", this, "_item_selected_cbk"); + get_tree()->connect("node_removed", callable_mp(this, &GridMapEditor::_node_removed)); + mesh_library_palette->connect("item_selected", callable_mp(this, &GridMapEditor::_item_selected_cbk)); for (int i = 0; i < 3; i++) { grid[i] = VS::get_singleton()->mesh_create(); @@ -1077,7 +1094,7 @@ void GridMapEditor::_notification(int p_what) { } break; case NOTIFICATION_EXIT_TREE: { - get_tree()->disconnect("node_removed", this, "_node_removed"); + get_tree()->disconnect("node_removed", callable_mp(this, &GridMapEditor::_node_removed)); _clear_clipboard_data(); for (int i = 0; i < 3; i++) { @@ -1181,19 +1198,8 @@ void GridMapEditor::_floor_mouse_exited() { void GridMapEditor::_bind_methods() { - ClassDB::bind_method("_text_changed", &GridMapEditor::_text_changed); - ClassDB::bind_method("_sbox_input", &GridMapEditor::_sbox_input); - ClassDB::bind_method("_icon_size_changed", &GridMapEditor::_icon_size_changed); - ClassDB::bind_method("_menu_option", &GridMapEditor::_menu_option); ClassDB::bind_method("_configure", &GridMapEditor::_configure); - ClassDB::bind_method("_item_selected_cbk", &GridMapEditor::_item_selected_cbk); - ClassDB::bind_method("_floor_changed", &GridMapEditor::_floor_changed); - ClassDB::bind_method("_floor_mouse_exited", &GridMapEditor::_floor_mouse_exited); ClassDB::bind_method("_set_selection", &GridMapEditor::_set_selection); - ClassDB::bind_method("_node_removed", &GridMapEditor::_node_removed); - - ClassDB::bind_method(D_METHOD("_set_display_mode", "mode"), &GridMapEditor::_set_display_mode); - ClassDB::bind_method("_draw_grids", &GridMapEditor::_draw_grids); } GridMapEditor::GridMapEditor(EditorNode *p_editor) { @@ -1223,9 +1229,9 @@ GridMapEditor::GridMapEditor(EditorNode *p_editor) { floor->get_line_edit()->add_constant_override("minimum_spaces", 16); spatial_editor_hb->add_child(floor); - floor->connect("value_changed", this, "_floor_changed"); - floor->connect("mouse_exited", this, "_floor_mouse_exited"); - floor->get_line_edit()->connect("mouse_exited", this, "_floor_mouse_exited"); + floor->connect("value_changed", callable_mp(this, &GridMapEditor::_floor_changed)); + floor->connect("mouse_exited", callable_mp(this, &GridMapEditor::_floor_mouse_exited)); + floor->get_line_edit()->connect("mouse_exited", callable_mp(this, &GridMapEditor::_floor_mouse_exited)); spatial_editor_hb->add_child(memnew(VSeparator)); @@ -1282,7 +1288,7 @@ GridMapEditor::GridMapEditor(EditorNode *p_editor) { settings_vbc->add_margin_child(TTR("Pick Distance:"), settings_pick_distance); clip_mode = CLIP_DISABLED; - options->get_popup()->connect("id_pressed", this, "_menu_option"); + options->get_popup()->connect("id_pressed", callable_mp(this, &GridMapEditor::_menu_option)); HBoxContainer *hb = memnew(HBoxContainer); add_child(hb); @@ -1292,30 +1298,30 @@ GridMapEditor::GridMapEditor(EditorNode *p_editor) { search_box->set_h_size_flags(SIZE_EXPAND_FILL); search_box->set_placeholder(TTR("Filter meshes")); hb->add_child(search_box); - search_box->connect("text_changed", this, "_text_changed"); - search_box->connect("gui_input", this, "_sbox_input"); + search_box->connect("text_changed", callable_mp(this, &GridMapEditor::_text_changed)); + search_box->connect("gui_input", callable_mp(this, &GridMapEditor::_sbox_input)); mode_thumbnail = memnew(ToolButton); mode_thumbnail->set_toggle_mode(true); mode_thumbnail->set_pressed(true); mode_thumbnail->set_icon(p_editor->get_gui_base()->get_icon("FileThumbnail", "EditorIcons")); hb->add_child(mode_thumbnail); - mode_thumbnail->connect("pressed", this, "_set_display_mode", varray(DISPLAY_THUMBNAIL)); + mode_thumbnail->connect("pressed", callable_mp(this, &GridMapEditor::_set_display_mode), varray(DISPLAY_THUMBNAIL)); mode_list = memnew(ToolButton); mode_list->set_toggle_mode(true); mode_list->set_pressed(false); mode_list->set_icon(p_editor->get_gui_base()->get_icon("FileList", "EditorIcons")); hb->add_child(mode_list); - mode_list->connect("pressed", this, "_set_display_mode", varray(DISPLAY_LIST)); + mode_list->connect("pressed", callable_mp(this, &GridMapEditor::_set_display_mode), varray(DISPLAY_LIST)); size_slider = memnew(HSlider); size_slider->set_h_size_flags(SIZE_EXPAND_FILL); - size_slider->set_min(0.1f); + size_slider->set_min(0.2f); size_slider->set_max(4.0f); size_slider->set_step(0.1f); size_slider->set_value(1.0f); - size_slider->connect("value_changed", this, "_icon_size_changed"); + size_slider->connect("value_changed", callable_mp(this, &GridMapEditor::_icon_size_changed)); add_child(size_slider); EDITOR_DEF("editors/grid_map/preview_size", 64); @@ -1325,6 +1331,7 @@ GridMapEditor::GridMapEditor(EditorNode *p_editor) { mesh_library_palette = memnew(ItemList); add_child(mesh_library_palette); mesh_library_palette->set_v_size_flags(SIZE_EXPAND_FILL); + mesh_library_palette->connect("gui_input", callable_mp(this, &GridMapEditor::_mesh_library_palette_input)); info_message = memnew(Label); info_message->set_text(TTR("Give a MeshLibrary resource to this GridMap to use its meshes.")); @@ -1351,9 +1358,9 @@ GridMapEditor::GridMapEditor(EditorNode *p_editor) { { // Selection mesh create. - PoolVector<Vector3> lines; - PoolVector<Vector3> triangles; - PoolVector<Vector3> square[3]; + Vector<Vector3> lines; + Vector<Vector3> triangles; + Vector<Vector3> square[3]; for (int i = 0; i < 6; i++) { @@ -1427,8 +1434,8 @@ GridMapEditor::GridMapEditor(EditorNode *p_editor) { inner_mat.instance(); inner_mat->set_albedo(Color(0.7, 0.7, 1.0, 0.2)); - inner_mat->set_flag(SpatialMaterial::FLAG_UNSHADED, true); - inner_mat->set_feature(SpatialMaterial::FEATURE_TRANSPARENT, true); + inner_mat->set_shading_mode(StandardMaterial3D::SHADING_MODE_UNSHADED); + inner_mat->set_transparency(StandardMaterial3D::TRANSPARENCY_ALPHA); d[VS::ARRAY_VERTEX] = triangles; VisualServer::get_singleton()->mesh_add_surface_from_arrays(selection_mesh, VS::PRIMITIVE_TRIANGLES, d); @@ -1437,15 +1444,14 @@ GridMapEditor::GridMapEditor(EditorNode *p_editor) { outer_mat.instance(); outer_mat->set_albedo(Color(0.7, 0.7, 1.0, 0.8)); outer_mat->set_on_top_of_alpha(); - outer_mat->set_flag(SpatialMaterial::FLAG_UNSHADED, true); - outer_mat->set_line_width(3.0); - outer_mat->set_feature(SpatialMaterial::FEATURE_TRANSPARENT, true); + + outer_mat->set_shading_mode(StandardMaterial3D::SHADING_MODE_UNSHADED); + outer_mat->set_transparency(StandardMaterial3D::TRANSPARENCY_ALPHA); selection_floor_mat.instance(); selection_floor_mat->set_albedo(Color(0.80, 0.80, 1.0, 1)); selection_floor_mat->set_on_top_of_alpha(); - selection_floor_mat->set_flag(SpatialMaterial::FLAG_UNSHADED, true); - selection_floor_mat->set_line_width(3.0); + selection_floor_mat->set_shading_mode(StandardMaterial3D::SHADING_MODE_UNSHADED); d[VS::ARRAY_VERTEX] = lines; VisualServer::get_singleton()->mesh_add_surface_from_arrays(selection_mesh, VS::PRIMITIVE_LINES, d); @@ -1472,10 +1478,10 @@ GridMapEditor::GridMapEditor(EditorNode *p_editor) { accumulated_floor_delta = 0.0; indicator_mat.instance(); - indicator_mat->set_flag(SpatialMaterial::FLAG_UNSHADED, true); - indicator_mat->set_feature(SpatialMaterial::FEATURE_TRANSPARENT, true); - indicator_mat->set_flag(SpatialMaterial::FLAG_SRGB_VERTEX_COLOR, true); - indicator_mat->set_flag(SpatialMaterial::FLAG_ALBEDO_FROM_VERTEX_COLOR, true); + indicator_mat->set_shading_mode(StandardMaterial3D::SHADING_MODE_UNSHADED); + indicator_mat->set_transparency(StandardMaterial3D::TRANSPARENCY_ALPHA); + indicator_mat->set_flag(StandardMaterial3D::FLAG_SRGB_VERTEX_COLOR, true); + indicator_mat->set_flag(StandardMaterial3D::FLAG_ALBEDO_FROM_VERTEX_COLOR, true); indicator_mat->set_albedo(Color(0.8, 0.5, 0.1)); } diff --git a/modules/gridmap/grid_map_editor_plugin.h b/modules/gridmap/grid_map_editor_plugin.h index 404e95b74c..d6459cee0a 100644 --- a/modules/gridmap/grid_map_editor_plugin.h +++ b/modules/gridmap/grid_map_editor_plugin.h @@ -125,10 +125,10 @@ class GridMapEditor : public VBoxContainer { List<ClipboardItem> clipboard_items; - Ref<SpatialMaterial> indicator_mat; - Ref<SpatialMaterial> inner_mat; - Ref<SpatialMaterial> outer_mat; - Ref<SpatialMaterial> selection_floor_mat; + Ref<StandardMaterial3D> indicator_mat; + Ref<StandardMaterial3D> inner_mat; + Ref<StandardMaterial3D> outer_mat; + Ref<StandardMaterial3D> selection_floor_mat; bool updating; @@ -214,6 +214,7 @@ class GridMapEditor : public VBoxContainer { void _text_changed(const String &p_text); void _sbox_input(const Ref<InputEvent> &p_ie); + void _mesh_library_palette_input(const Ref<InputEvent> &p_ie); void _icon_size_changed(float p_value); |