diff options
Diffstat (limited to 'modules/gridmap')
-rw-r--r-- | modules/gridmap/grid_map.cpp | 73 | ||||
-rw-r--r-- | modules/gridmap/grid_map.h | 9 | ||||
-rw-r--r-- | modules/gridmap/grid_map_editor_plugin.cpp | 104 | ||||
-rw-r--r-- | modules/gridmap/grid_map_editor_plugin.h | 5 | ||||
-rw-r--r-- | modules/gridmap/register_types.cpp | 1 |
5 files changed, 0 insertions, 192 deletions
diff --git a/modules/gridmap/grid_map.cpp b/modules/gridmap/grid_map.cpp index 0dbefbb39f..cf14447232 100644 --- a/modules/gridmap/grid_map.cpp +++ b/modules/gridmap/grid_map.cpp @@ -40,22 +40,18 @@ #include "servers/rendering_server.h" bool GridMap::_set(const StringName &p_name, const Variant &p_value) { - String name = p_name; if (name == "data") { - Dictionary d = p_value; if (d.has("cells")) { - Vector<int> cells = d["cells"]; int amount = cells.size(); 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++) { - IndexKey ik; ik.key = decode_uint64((const uint8_t *)&r[i * 3]); Cell cell; @@ -67,7 +63,6 @@ bool GridMap::_set(const StringName &p_name, const Variant &p_value) { _recreate_octant_data(); } else if (name == "baked_meshes") { - clear_baked_meshes(); Array meshes = p_value; @@ -96,11 +91,9 @@ bool GridMap::_set(const StringName &p_name, const Variant &p_value) { } bool GridMap::_get(const StringName &p_name, Variant &r_ret) const { - String name = p_name; if (name == "data") { - Dictionary d; Vector<int> cells; @@ -109,7 +102,6 @@ bool GridMap::_get(const StringName &p_name, Variant &r_ret) const { int *w = cells.ptrw(); int i = 0; for (Map<IndexKey, Cell>::Element *E = cell_map.front(); E; E = E->next(), i++) { - encode_uint64(E->key().key, (uint8_t *)&w[i * 3]); encode_uint32(E->get().cell, (uint8_t *)&w[i * 3 + 2]); } @@ -119,7 +111,6 @@ bool GridMap::_get(const StringName &p_name, Variant &r_ret) const { r_ret = d; } else if (name == "baked_meshes") { - Array ret; ret.resize(baked_meshes.size()); for (int i = 0; i < baked_meshes.size(); i++) { @@ -134,7 +125,6 @@ bool GridMap::_get(const StringName &p_name, Variant &r_ret) const { } void GridMap::_get_property_list(List<PropertyInfo> *p_list) const { - if (baked_meshes.size()) { p_list->push_back(PropertyInfo(Variant::ARRAY, "baked_meshes", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_STORAGE)); } @@ -143,29 +133,24 @@ void GridMap::_get_property_list(List<PropertyInfo> *p_list) const { } void GridMap::set_collision_layer(uint32_t p_layer) { - collision_layer = p_layer; _reset_physic_bodies_collision_filters(); } uint32_t GridMap::get_collision_layer() const { - return collision_layer; } void GridMap::set_collision_mask(uint32_t p_mask) { - collision_mask = p_mask; _reset_physic_bodies_collision_filters(); } uint32_t GridMap::get_collision_mask() const { - return collision_mask; } void GridMap::set_collision_mask_bit(int p_bit, bool p_value) { - uint32_t mask = get_collision_mask(); if (p_value) mask |= 1 << p_bit; @@ -175,12 +160,10 @@ void GridMap::set_collision_mask_bit(int p_bit, bool p_value) { } bool GridMap::get_collision_mask_bit(int p_bit) const { - return get_collision_mask() & (1 << p_bit); } void GridMap::set_collision_layer_bit(int p_bit, bool p_value) { - uint32_t mask = get_collision_layer(); if (p_value) mask |= 1 << p_bit; @@ -190,12 +173,10 @@ void GridMap::set_collision_layer_bit(int p_bit, bool p_value) { } bool GridMap::get_collision_layer_bit(int p_bit) const { - return get_collision_layer() & (1 << p_bit); } void GridMap::set_mesh_library(const Ref<MeshLibrary> &p_mesh_library) { - if (!mesh_library.is_null()) mesh_library->unregister_owner(this); mesh_library = p_mesh_library; @@ -207,7 +188,6 @@ void GridMap::set_mesh_library(const Ref<MeshLibrary> &p_mesh_library) { } Ref<MeshLibrary> GridMap::get_mesh_library() const { - return mesh_library; } @@ -218,23 +198,19 @@ void GridMap::set_cell_size(const Vector3 &p_size) { emit_signal("cell_size_changed", cell_size); } Vector3 GridMap::get_cell_size() const { - return cell_size; } void GridMap::set_octant_size(int p_size) { - ERR_FAIL_COND(p_size == 0); octant_size = p_size; _recreate_octant_data(); } int GridMap::get_octant_size() const { - return octant_size; } void GridMap::set_center_x(bool p_enable) { - center_x = p_enable; _recreate_octant_data(); } @@ -244,7 +220,6 @@ bool GridMap::get_center_x() const { } void GridMap::set_center_y(bool p_enable) { - center_y = p_enable; _recreate_octant_data(); } @@ -254,7 +229,6 @@ bool GridMap::get_center_y() const { } void GridMap::set_center_z(bool p_enable) { - center_z = p_enable; _recreate_octant_data(); } @@ -264,7 +238,6 @@ bool GridMap::get_center_z() const { } void GridMap::set_cell_item(int p_x, int p_y, int p_z, int p_item, int p_rot) { - if (baked_meshes.size() && !recreating_octants) { //if you set a cell item, baked meshes go good bye clear_baked_meshes(); @@ -313,7 +286,6 @@ void GridMap::set_cell_item(int p_x, int p_y, int p_z, int p_item, int p_rot) { SceneTree *st = SceneTree::get_singleton(); if (st && st->is_debugging_collisions_hint()) { - g->collision_debug = RenderingServer::get_singleton()->mesh_create(); g->collision_debug_instance = RenderingServer::get_singleton()->instance_create(); RenderingServer::get_singleton()->instance_set_base(g->collision_debug_instance, g->collision_debug); @@ -340,7 +312,6 @@ void GridMap::set_cell_item(int p_x, int p_y, int p_z, int p_item, int p_rot) { } int GridMap::get_cell_item(int p_x, int p_y, int p_z) const { - ERR_FAIL_INDEX_V(ABS(p_x), 1 << 20, INVALID_CELL_ITEM); ERR_FAIL_INDEX_V(ABS(p_y), 1 << 20, INVALID_CELL_ITEM); ERR_FAIL_INDEX_V(ABS(p_z), 1 << 20, INVALID_CELL_ITEM); @@ -356,7 +327,6 @@ int GridMap::get_cell_item(int p_x, int p_y, int p_z) const { } int GridMap::get_cell_item_orientation(int p_x, int p_y, int p_z) const { - ERR_FAIL_INDEX_V(ABS(p_x), 1 << 20, -1); ERR_FAIL_INDEX_V(ABS(p_y), 1 << 20, -1); ERR_FAIL_INDEX_V(ABS(p_z), 1 << 20, -1); @@ -389,7 +359,6 @@ Vector3 GridMap::map_to_world(int p_x, int p_y, int p_z) const { } void GridMap::_octant_transform(const OctantKey &p_key) { - ERR_FAIL_COND(!octant_map.has(p_key)); Octant &g = *octant_map[p_key]; PhysicsServer3D::get_singleton()->body_set_state(g.static_body, PhysicsServer3D::BODY_STATE_TRANSFORM, get_global_transform()); @@ -414,7 +383,6 @@ bool GridMap::_octant_update(const OctantKey &p_key) { //erase body shapes debug if (g.collision_debug.is_valid()) { - RS::get_singleton()->mesh_clear(g.collision_debug); } @@ -427,7 +395,6 @@ bool GridMap::_octant_update(const OctantKey &p_key) { //erase multimeshes for (int i = 0; i < g.multimesh_instances.size(); i++) { - RS::get_singleton()->free(g.multimesh_instances[i].instance); RS::get_singleton()->free(g.multimesh_instances[i].multimesh); } @@ -450,7 +417,6 @@ bool GridMap::_octant_update(const OctantKey &p_key) { Map<int, List<Pair<Transform, IndexKey>>> multimesh_items; for (Set<IndexKey>::Element *E = g.cells.front(); E; E = E->next()) { - ERR_CONTINUE(!cell_map.has(E->get())); const Cell &c = cell_map[E->get()]; @@ -509,7 +475,6 @@ bool GridMap::_octant_update(const OctantKey &p_key) { //update multimeshes, only if not baked if (baked_meshes.size() == 0) { - for (Map<int, List<Pair<Transform, IndexKey>>>::Element *E = multimesh_items.front(); E; E = E->next()) { Octant::MultimeshInstance mmi; @@ -548,7 +513,6 @@ bool GridMap::_octant_update(const OctantKey &p_key) { } if (col_debug.size()) { - Array arr; arr.resize(RS::ARRAY_MAX); arr[RS::ARRAY_VERTEX] = col_debug; @@ -573,7 +537,6 @@ void GridMap::_reset_physic_bodies_collision_filters() { } void GridMap::_octant_enter_world(const OctantKey &p_key) { - ERR_FAIL_COND(!octant_map.has(p_key)); Octant &g = *octant_map[p_key]; PhysicsServer3D::get_singleton()->body_set_state(g.static_body, PhysicsServer3D::BODY_STATE_TRANSFORM, get_global_transform()); @@ -591,7 +554,6 @@ 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().region.is_valid() == false) { Ref<NavigationMesh> nm = mesh_library->get_item_navmesh(cell_map[F->key()].item); if (nm.is_valid()) { @@ -607,14 +569,12 @@ void GridMap::_octant_enter_world(const OctantKey &p_key) { } void GridMap::_octant_exit_world(const OctantKey &p_key) { - ERR_FAIL_COND(!octant_map.has(p_key)); Octant &g = *octant_map[p_key]; PhysicsServer3D::get_singleton()->body_set_state(g.static_body, PhysicsServer3D::BODY_STATE_TRANSFORM, get_global_transform()); PhysicsServer3D::get_singleton()->body_set_space(g.static_body, RID()); if (g.collision_debug_instance.is_valid()) { - RS::get_singleton()->instance_set_scenario(g.collision_debug_instance, RID()); } @@ -624,7 +584,6 @@ 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().region.is_valid()) { NavigationServer3D::get_singleton()->free(F->get().region); F->get().region = RID(); @@ -634,7 +593,6 @@ void GridMap::_octant_exit_world(const OctantKey &p_key) { } void GridMap::_octant_clean_up(const OctantKey &p_key) { - ERR_FAIL_COND(!octant_map.has(p_key)); Octant &g = *octant_map[p_key]; @@ -654,7 +612,6 @@ void GridMap::_octant_clean_up(const OctantKey &p_key) { //erase multimeshes for (int i = 0; i < g.multimesh_instances.size(); i++) { - RS::get_singleton()->free(g.multimesh_instances[i].instance); RS::get_singleton()->free(g.multimesh_instances[i].multimesh); } @@ -662,11 +619,8 @@ void GridMap::_octant_clean_up(const OctantKey &p_key) { } void GridMap::_notification(int p_what) { - switch (p_what) { - case NOTIFICATION_ENTER_WORLD: { - Node3D *c = this; while (c) { navigation = Object::cast_to<Navigation3D>(c); @@ -690,7 +644,6 @@ void GridMap::_notification(int p_what) { } break; case NOTIFICATION_TRANSFORM_CHANGED: { - Transform new_xform = get_global_transform(); if (new_xform == last_transform) break; @@ -707,7 +660,6 @@ void GridMap::_notification(int p_what) { } break; case NOTIFICATION_EXIT_WORLD: { - for (Map<OctantKey, Octant *>::Element *E = octant_map.front(); E; E = E->next()) { _octant_exit_world(E->key()); } @@ -744,7 +696,6 @@ void GridMap::_update_visibility() { } void GridMap::_queue_octants_dirty() { - if (awaiting_update) return; @@ -753,19 +704,16 @@ void GridMap::_queue_octants_dirty() { } void GridMap::_recreate_octant_data() { - recreating_octants = true; Map<IndexKey, Cell> cell_copy = cell_map; _clear_internal(); for (Map<IndexKey, Cell>::Element *E = cell_copy.front(); E; E = E->next()) { - set_cell_item(E->key().x, E->key().y, E->key().z, E->get().item, E->get().rot); } recreating_octants = false; } void GridMap::_clear_internal() { - for (Map<OctantKey, Octant *>::Element *E = octant_map.front(); E; E = E->next()) { if (is_inside_world()) _octant_exit_world(E->key()); @@ -779,24 +727,20 @@ void GridMap::_clear_internal() { } void GridMap::clear() { - _clear_internal(); clear_baked_meshes(); } void GridMap::resource_changed(const RES &p_res) { - _recreate_octant_data(); } void GridMap::_update_octants_callback() { - if (!awaiting_update) return; List<OctantKey> to_delete; for (Map<OctantKey, Octant *>::Element *E = octant_map.front(); E; E = E->next()) { - if (_octant_update(E->key())) { to_delete.push_back(E->key()); } @@ -812,7 +756,6 @@ void GridMap::_update_octants_callback() { } void GridMap::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_collision_layer", "layer"), &GridMap::set_collision_layer); ClassDB::bind_method(D_METHOD("get_collision_layer"), &GridMap::get_collision_layer); @@ -885,7 +828,6 @@ void GridMap::_bind_methods() { } void GridMap::set_clip(bool p_enabled, bool p_clip_above, int p_floor, Vector3::Axis p_axis) { - if (!p_enabled && !clip) return; if (clip && p_enabled && clip_floor == p_floor && p_clip_above == clip_above && p_axis == clip_axis) @@ -898,7 +840,6 @@ void GridMap::set_clip(bool p_enabled, bool p_clip_above, int p_floor, Vector3:: //make it all update for (Map<OctantKey, Octant *>::Element *E = octant_map.front(); E; E = E->next()) { - Octant *g = E->get(); g->dirty = true; } @@ -907,18 +848,15 @@ void GridMap::set_clip(bool p_enabled, bool p_clip_above, int p_floor, Vector3:: } void GridMap::set_cell_scale(float p_scale) { - cell_scale = p_scale; _recreate_octant_data(); } float GridMap::get_cell_scale() const { - return cell_scale; } Array GridMap::get_used_cells() const { - Array a; a.resize(cell_map.size()); int i = 0; @@ -931,7 +869,6 @@ Array GridMap::get_used_cells() const { } Array GridMap::get_meshes() { - if (mesh_library.is_null()) return Array(); @@ -939,7 +876,6 @@ Array GridMap::get_meshes() { Array meshes; for (Map<IndexKey, Cell>::Element *E = cell_map.front(); E; E = E->next()) { - int id = E->get().item; if (!mesh_library->has_item(id)) continue; @@ -973,7 +909,6 @@ Vector3 GridMap::_get_offset() const { } void GridMap::clear_baked_meshes() { - for (int i = 0; i < baked_meshes.size(); i++) { RS::get_singleton()->free(baked_meshes[i].instance); } @@ -983,7 +918,6 @@ void GridMap::clear_baked_meshes() { } void GridMap::make_baked_meshes(bool p_gen_lightmap_uv, float p_lightmap_uv_texel_size) { - if (!mesh_library.is_valid()) return; @@ -991,7 +925,6 @@ void GridMap::make_baked_meshes(bool p_gen_lightmap_uv, float p_lightmap_uv_texe Map<OctantKey, Map<Ref<Material>, Ref<SurfaceTool>>> surface_map; for (Map<IndexKey, Cell>::Element *E = cell_map.front(); E; E = E->next()) { - IndexKey key = E->key(); int item = E->get().item; @@ -1023,7 +956,6 @@ void GridMap::make_baked_meshes(bool p_gen_lightmap_uv, float p_lightmap_uv_texe Map<Ref<Material>, Ref<SurfaceTool>> &mat_map = surface_map[ok]; for (int i = 0; i < mesh->get_surface_count(); i++) { - if (mesh->surface_get_primitive_type(i) != Mesh::PRIMITIVE_TRIANGLES) continue; @@ -1041,7 +973,6 @@ void GridMap::make_baked_meshes(bool p_gen_lightmap_uv, float p_lightmap_uv_texe } for (Map<OctantKey, Map<Ref<Material>, Ref<SurfaceTool>>>::Element *E = surface_map.front(); E; E = E->next()) { - Ref<ArrayMesh> mesh; mesh.instance(); for (Map<Ref<Material>, Ref<SurfaceTool>>::Element *F = E->get().front(); F; F = F->next()) { @@ -1068,7 +999,6 @@ void GridMap::make_baked_meshes(bool p_gen_lightmap_uv, float p_lightmap_uv_texe } Array GridMap::get_bake_meshes() { - if (!baked_meshes.size()) { make_baked_meshes(true); } @@ -1083,13 +1013,11 @@ Array GridMap::get_bake_meshes() { } RID GridMap::get_bake_mesh_instance(int p_idx) { - ERR_FAIL_INDEX_V(p_idx, baked_meshes.size(), RID()); return baked_meshes[p_idx].instance; } GridMap::GridMap() { - collision_layer = 1; collision_mask = 1; @@ -1113,7 +1041,6 @@ GridMap::GridMap() { } GridMap::~GridMap() { - if (!mesh_library.is_null()) mesh_library->unregister_owner(this); diff --git a/modules/gridmap/grid_map.h b/modules/gridmap/grid_map.h index 3f3da09fe9..9eb9aee7d1 100644 --- a/modules/gridmap/grid_map.h +++ b/modules/gridmap/grid_map.h @@ -40,7 +40,6 @@ //should scale better with hardware that supports instancing class GridMap : public Node3D { - GDCLASS(GridMap, Node3D); enum { @@ -49,7 +48,6 @@ class GridMap : public Node3D { }; union IndexKey { - struct { int16_t x; int16_t y; @@ -58,7 +56,6 @@ class GridMap : public Node3D { uint64_t key; _FORCE_INLINE_ bool operator<(const IndexKey &p_key) const { - return key < p_key.key; } @@ -69,7 +66,6 @@ class GridMap : public Node3D { * @brief A Cell is a single cell in the cube map space; it is defined by its coordinates and the populating Item, identified by int id. */ union Cell { - struct { unsigned int item : 16; unsigned int rot : 5; @@ -89,7 +85,6 @@ class GridMap : public Node3D { * A GridMap can have multiple Octants. */ struct Octant { - struct NavMesh { RID region; Transform xform; @@ -118,7 +113,6 @@ class GridMap : public Node3D { }; union OctantKey { - struct { int16_t x; int16_t y; @@ -129,7 +123,6 @@ class GridMap : public Node3D { uint64_t key; _FORCE_INLINE_ bool operator<(const OctantKey &p_key) const { - return key < p_key.key; } @@ -165,7 +158,6 @@ class GridMap : public Node3D { void _recreate_octant_data(); struct BakeLight { - RS::LightType type; Vector3 pos; Vector3 dir; @@ -173,7 +165,6 @@ class GridMap : public Node3D { }; _FORCE_INLINE_ Vector3 _octant_get_offset(const OctantKey &p_key) const { - return Vector3(p_key.x, p_key.y, p_key.z) * cell_size * octant_size; } diff --git a/modules/gridmap/grid_map_editor_plugin.cpp b/modules/gridmap/grid_map_editor_plugin.cpp index fc545430f5..e8f7d09bb2 100644 --- a/modules/gridmap/grid_map_editor_plugin.cpp +++ b/modules/gridmap/grid_map_editor_plugin.cpp @@ -40,13 +40,11 @@ #include "scene/main/window.h" void GridMapEditor::_node_removed(Node *p_node) { - if (p_node == node) node = nullptr; } void GridMapEditor::_configure() { - if (!node) return; @@ -54,9 +52,7 @@ void GridMapEditor::_configure() { } void GridMapEditor::_menu_option(int p_option) { - switch (p_option) { - case MENU_OPTION_PREV_LEVEL: { floor->set_value(floor->get_value() - 1); } break; @@ -66,7 +62,6 @@ void GridMapEditor::_menu_option(int p_option) { } break; case MENU_OPTION_LOCK_VIEW: { - int index = options->get_popup()->get_item_index(MENU_OPTION_LOCK_VIEW); lock_view = !options->get_popup()->is_item_checked(index); @@ -75,10 +70,8 @@ void GridMapEditor::_menu_option(int p_option) { case MENU_OPTION_CLIP_DISABLED: case MENU_OPTION_CLIP_ABOVE: case MENU_OPTION_CLIP_BELOW: { - clip_mode = ClipMode(p_option - MENU_OPTION_CLIP_DISABLED); for (int i = 0; i < 3; i++) { - int index = options->get_popup()->get_item_index(MENU_OPTION_CLIP_DISABLED + i); options->get_popup()->set_item_checked(index, i == clip_mode); } @@ -88,7 +81,6 @@ void GridMapEditor::_menu_option(int p_option) { case MENU_OPTION_X_AXIS: case MENU_OPTION_Y_AXIS: case MENU_OPTION_Z_AXIS: { - int new_axis = p_option - MENU_OPTION_X_AXIS; for (int i = 0; i < 3; i++) { int idx = options->get_popup()->get_item_index(MENU_OPTION_X_AXIS + i); @@ -114,10 +106,8 @@ void GridMapEditor::_menu_option(int p_option) { } break; case MENU_OPTION_CURSOR_ROTATE_Y: { - Basis r; if (input_action == INPUT_PASTE) { - r.set_orthogonal_index(paste_indicator.orientation); r.rotate(Vector3(0, 1, 0), -Math_PI / 2.0); paste_indicator.orientation = r.get_orthogonal_index(); @@ -131,10 +121,8 @@ void GridMapEditor::_menu_option(int p_option) { _update_cursor_transform(); } break; case MENU_OPTION_CURSOR_ROTATE_X: { - Basis r; if (input_action == INPUT_PASTE) { - r.set_orthogonal_index(paste_indicator.orientation); r.rotate(Vector3(1, 0, 0), -Math_PI / 2.0); paste_indicator.orientation = r.get_orthogonal_index(); @@ -148,10 +136,8 @@ void GridMapEditor::_menu_option(int p_option) { _update_cursor_transform(); } break; case MENU_OPTION_CURSOR_ROTATE_Z: { - Basis r; if (input_action == INPUT_PASTE) { - r.set_orthogonal_index(paste_indicator.orientation); r.rotate(Vector3(0, 0, 1), -Math_PI / 2.0); paste_indicator.orientation = r.get_orthogonal_index(); @@ -165,10 +151,8 @@ void GridMapEditor::_menu_option(int p_option) { _update_cursor_transform(); } break; case MENU_OPTION_CURSOR_BACK_ROTATE_Y: { - Basis r; if (input_action == INPUT_PASTE) { - r.set_orthogonal_index(paste_indicator.orientation); r.rotate(Vector3(0, 1, 0), Math_PI / 2.0); paste_indicator.orientation = r.get_orthogonal_index(); @@ -182,10 +166,8 @@ void GridMapEditor::_menu_option(int p_option) { _update_cursor_transform(); } break; case MENU_OPTION_CURSOR_BACK_ROTATE_X: { - Basis r; if (input_action == INPUT_PASTE) { - r.set_orthogonal_index(paste_indicator.orientation); r.rotate(Vector3(1, 0, 0), Math_PI / 2.0); paste_indicator.orientation = r.get_orthogonal_index(); @@ -199,10 +181,8 @@ void GridMapEditor::_menu_option(int p_option) { _update_cursor_transform(); } break; case MENU_OPTION_CURSOR_BACK_ROTATE_Z: { - Basis r; if (input_action == INPUT_PASTE) { - r.set_orthogonal_index(paste_indicator.orientation); r.rotate(Vector3(0, 0, 1), Math_PI / 2.0); paste_indicator.orientation = r.get_orthogonal_index(); @@ -216,9 +196,7 @@ void GridMapEditor::_menu_option(int p_option) { _update_cursor_transform(); } break; case MENU_OPTION_CURSOR_CLEAR_ROTATION: { - if (input_action == INPUT_PASTE) { - paste_indicator.orientation = 0; _update_paste_indicator(); break; @@ -273,7 +251,6 @@ void GridMapEditor::_menu_option(int p_option) { } void GridMapEditor::_update_cursor_transform() { - cursor_transform = Transform(); cursor_transform.origin = cursor_origin; cursor_transform.basis.set_orthogonal_index(cursor_rot); @@ -291,7 +268,6 @@ void GridMapEditor::_update_selection_transform() { xf_zero.basis.set_zero(); if (!selection.active) { - RenderingServer::get_singleton()->instance_set_transform(selection_instance, xf_zero); for (int i = 0; i < 3; i++) { RenderingServer::get_singleton()->instance_set_transform(selection_level_instance[i], xf_zero); @@ -309,7 +285,6 @@ void GridMapEditor::_update_selection_transform() { if (i != edit_axis || (edit_floor[edit_axis] < selection.begin[edit_axis]) || (edit_floor[edit_axis] > selection.end[edit_axis] + 1)) { RenderingServer::get_singleton()->instance_set_transform(selection_level_instance[i], xf_zero); } else { - Vector3 scale = (selection.end - selection.begin + Vector3(1, 1, 1)); scale[edit_axis] = 1.0; Vector3 pos = selection.begin; @@ -328,7 +303,6 @@ void GridMapEditor::_update_selection_transform() { } void GridMapEditor::_validate_selection() { - if (!selection.active) return; selection.begin = selection.click; @@ -345,7 +319,6 @@ void GridMapEditor::_validate_selection() { } void GridMapEditor::_set_selection(bool p_active, const Vector3 &p_begin, const Vector3 &p_end) { - selection.active = p_active; selection.begin = p_begin; selection.end = p_end; @@ -363,7 +336,6 @@ void GridMapEditor::_set_selection(bool p_active, const Vector3 &p_begin, const } bool GridMapEditor::do_input_action(Camera3D *p_camera, const Point2 &p_point, bool p_click) { - if (!spatial_editor) return false; @@ -394,7 +366,6 @@ bool GridMapEditor::do_input_action(Camera3D *p_camera, const Point2 &p_point, b // Make sure the intersection is inside the frustum planes, to avoid // Painting on invisible regions. for (int i = 0; i < planes.size(); i++) { - Plane fp = local_xform.xform(planes[i]); if (fp.is_point_over(inters)) return false; @@ -404,11 +375,9 @@ bool GridMapEditor::do_input_action(Camera3D *p_camera, const Point2 &p_point, b float cell_size[3] = { node->get_cell_size().x, node->get_cell_size().y, node->get_cell_size().z }; for (int i = 0; i < 3; i++) { - if (i == edit_axis) cell[i] = edit_floor[i]; else { - cell[i] = inters[i] / node->get_cell_size()[i]; if (inters[i] < 0) cell[i] -= 1; // Compensate negative. @@ -419,7 +388,6 @@ bool GridMapEditor::do_input_action(Camera3D *p_camera, const Point2 &p_point, b RS::get_singleton()->instance_set_transform(grid_instance[edit_axis], node->get_global_transform() * edit_grid_xform); if (cursor_instance.is_valid()) { - cursor_origin = (Vector3(cell[0], cell[1], cell[2]) + Vector3(0.5 * node->get_center_x(), 0.5 * node->get_center_y(), 0.5 * node->get_center_z())) * node->get_cell_size(); cursor_visible = true; @@ -431,12 +399,10 @@ bool GridMapEditor::do_input_action(Camera3D *p_camera, const Point2 &p_point, b } if (input_action == INPUT_PASTE) { - paste_indicator.current = Vector3(cell[0], cell[1], cell[2]); _update_paste_indicator(); } else if (input_action == INPUT_SELECT) { - selection.current = Vector3(cell[0], cell[1], cell[2]); if (p_click) selection.click = selection.current; @@ -445,7 +411,6 @@ bool GridMapEditor::do_input_action(Camera3D *p_camera, const Point2 &p_point, b return true; } else if (input_action == INPUT_PICK) { - int item = node->get_cell_item(cell[0], cell[1], cell[2]); if (item >= 0) { selected_palette = item; @@ -481,17 +446,13 @@ bool GridMapEditor::do_input_action(Camera3D *p_camera, const Point2 &p_point, b } void GridMapEditor::_delete_selection() { - if (!selection.active) return; undo_redo->create_action(TTR("GridMap Delete Selection")); for (int i = selection.begin.x; i <= selection.end.x; i++) { - for (int j = selection.begin.y; j <= selection.end.y; j++) { - for (int k = selection.begin.z; k <= selection.end.z; k++) { - undo_redo->add_do_method(node, "set_cell_item", i, j, k, GridMap::INVALID_CELL_ITEM); undo_redo->add_undo_method(node, "set_cell_item", i, j, k, node->get_cell_item(i, j, k), node->get_cell_item_orientation(i, j, k)); } @@ -503,17 +464,13 @@ void GridMapEditor::_delete_selection() { } void GridMapEditor::_fill_selection() { - if (!selection.active) return; undo_redo->create_action(TTR("GridMap Fill Selection")); for (int i = selection.begin.x; i <= selection.end.x; i++) { - for (int j = selection.begin.y; j <= selection.end.y; j++) { - for (int k = selection.begin.z; k <= selection.end.z; k++) { - undo_redo->add_do_method(node, "set_cell_item", i, j, k, selected_palette, cursor_rot); undo_redo->add_undo_method(node, "set_cell_item", i, j, k, node->get_cell_item(i, j, k), node->get_cell_item_orientation(i, j, k)); } @@ -525,9 +482,7 @@ void GridMapEditor::_fill_selection() { } void GridMapEditor::_clear_clipboard_data() { - for (List<ClipboardItem>::Element *E = clipboard_items.front(); E; E = E->next()) { - RenderingServer::get_singleton()->free(E->get().instance); } @@ -535,17 +490,13 @@ void GridMapEditor::_clear_clipboard_data() { } void GridMapEditor::_set_clipboard_data() { - _clear_clipboard_data(); Ref<MeshLibrary> meshLibrary = node->get_mesh_library(); for (int i = selection.begin.x; i <= selection.end.x; i++) { - for (int j = selection.begin.y; j <= selection.end.y; j++) { - for (int k = selection.begin.z; k <= selection.end.z; k++) { - int itm = node->get_cell_item(i, j, k); if (itm == GridMap::INVALID_CELL_ITEM) continue; @@ -565,9 +516,7 @@ void GridMapEditor::_set_clipboard_data() { } void GridMapEditor::_update_paste_indicator() { - if (input_action != INPUT_PASTE) { - Transform xf; xf.basis.set_zero(); RenderingServer::get_singleton()->instance_set_transform(paste_instance, xf); @@ -587,7 +536,6 @@ void GridMapEditor::_update_paste_indicator() { RenderingServer::get_singleton()->instance_set_transform(paste_instance, node->get_global_transform() * xf); for (List<ClipboardItem>::Element *E = clipboard_items.front(); E; E = E->next()) { - ClipboardItem &item = E->get(); xf = Transform(); @@ -604,7 +552,6 @@ void GridMapEditor::_update_paste_indicator() { } void GridMapEditor::_do_paste() { - int idx = options->get_popup()->get_item_index(MENU_OPTION_PASTE_SELECTS); bool reselect = options->get_popup()->is_item_checked(idx); @@ -615,7 +562,6 @@ void GridMapEditor::_do_paste() { undo_redo->create_action(TTR("GridMap Paste Selection")); for (List<ClipboardItem>::Element *E = clipboard_items.front(); E; E = E->next()) { - ClipboardItem &item = E->get(); Vector3 pos = rot.xform(item.grid_offset) + paste_indicator.begin + ofs; @@ -629,7 +575,6 @@ void GridMapEditor::_do_paste() { } if (reselect) { - undo_redo->add_do_method(this, "_set_selection", true, paste_indicator.begin + ofs, paste_indicator.end + ofs); undo_redo->add_undo_method(this, "_set_selection", selection.active, selection.begin, selection.end); } @@ -647,7 +592,6 @@ bool GridMapEditor::forward_spatial_input_event(Camera3D *p_camera, const Ref<In Ref<InputEventMouseButton> mb = p_event; if (mb.is_valid()) { - if (mb->get_button_index() == BUTTON_WHEEL_UP && (mb->get_command() || mb->get_shift())) { if (mb->is_pressed()) floor->set_value(floor->get_value() + mb->get_factor()); @@ -664,7 +608,6 @@ bool GridMapEditor::forward_spatial_input_event(Camera3D *p_camera, const Ref<In if ((nav_scheme == Node3DEditorViewport::NAVIGATION_MAYA || nav_scheme == Node3DEditorViewport::NAVIGATION_MODO) && mb->get_alt()) { input_action = INPUT_NONE; } else if (mb->get_button_index() == BUTTON_LEFT) { - bool can_edit = (node && node->get_mesh_library().is_valid()); if (input_action == INPUT_PASTE) { _do_paste(); @@ -698,18 +641,14 @@ bool GridMapEditor::forward_spatial_input_event(Camera3D *p_camera, const Ref<In return do_input_action(p_camera, Point2(mb->get_position().x, mb->get_position().y), true); } else { - if ((mb->get_button_index() == BUTTON_RIGHT && input_action == INPUT_ERASE) || (mb->get_button_index() == BUTTON_LEFT && input_action == INPUT_PAINT)) { - if (set_items.size()) { undo_redo->create_action(TTR("GridMap Paint")); for (List<SetItem>::Element *E = set_items.front(); E; E = E->next()) { - const SetItem &si = E->get(); undo_redo->add_do_method(node, "set_cell_item", si.pos.x, si.pos.y, si.pos.z, si.new_value, si.new_orientation); } for (List<SetItem>::Element *E = set_items.back(); E; E = E->prev()) { - const SetItem &si = E->get(); undo_redo->add_undo_method(node, "set_cell_item", si.pos.x, si.pos.y, si.pos.z, si.old_value, si.old_orientation); } @@ -722,7 +661,6 @@ bool GridMapEditor::forward_spatial_input_event(Camera3D *p_camera, const Ref<In } if (mb->get_button_index() == BUTTON_LEFT && input_action == INPUT_SELECT) { - undo_redo->create_action("GridMap Selection"); undo_redo->add_do_method(this, "_set_selection", selection.active, selection.begin, selection.end); undo_redo->add_undo_method(this, "_set_selection", last_selection.active, last_selection.begin, last_selection.end); @@ -730,7 +668,6 @@ bool GridMapEditor::forward_spatial_input_event(Camera3D *p_camera, const Ref<In } if (mb->get_button_index() == BUTTON_LEFT && input_action != INPUT_NONE) { - set_items.clear(); input_action = INPUT_NONE; return true; @@ -745,7 +682,6 @@ bool GridMapEditor::forward_spatial_input_event(Camera3D *p_camera, const Ref<In Ref<InputEventMouseMotion> mm = p_event; if (mm.is_valid()) { - return do_input_action(p_camera, mm->get_position(), false); } @@ -754,7 +690,6 @@ bool GridMapEditor::forward_spatial_input_event(Camera3D *p_camera, const Ref<In if (k.is_valid()) { if (k->is_pressed()) { if (k->get_keycode() == KEY_ESCAPE) { - if (input_action == INPUT_PASTE) { _clear_clipboard_data(); input_action = INPUT_NONE; @@ -773,7 +708,6 @@ bool GridMapEditor::forward_spatial_input_event(Camera3D *p_camera, const Ref<In } if (k->get_shift() && selection.active && input_action != INPUT_PASTE) { - if (k->get_keycode() == options->get_popup()->get_item_accelerator(options->get_popup()->get_item_index(MENU_OPTION_PREV_LEVEL))) { selection.click[edit_axis]--; _validate_selection(); @@ -790,7 +724,6 @@ bool GridMapEditor::forward_spatial_input_event(Camera3D *p_camera, const Ref<In Ref<InputEventPanGesture> pan_gesture = p_event; if (pan_gesture.is_valid()) { - if (pan_gesture->get_alt() && (pan_gesture->get_command() || pan_gesture->get_shift())) { const real_t delta = pan_gesture->get_delta().y * 0.5; accumulated_floor_delta += delta; @@ -811,7 +744,6 @@ bool GridMapEditor::forward_spatial_input_event(Camera3D *p_camera, const Ref<In } struct _CGMEItemSort { - String name; int id; _FORCE_INLINE_ bool operator<(const _CGMEItemSort &r_it) const { return name < r_it.name; } @@ -840,11 +772,9 @@ void GridMapEditor::_text_changed(const String &p_text) { } void GridMapEditor::_sbox_input(const Ref<InputEvent> &p_ie) { - const Ref<InputEventKey> k = p_ie; if (k.is_valid() && (k->get_keycode() == KEY_UP || k->get_keycode() == KEY_DOWN || k->get_keycode() == KEY_PAGEUP || k->get_keycode() == KEY_PAGEDOWN)) { - // Forward the key input to the ItemList so it can be scrolled mesh_library_palette->call("_gui_input", k); search_box->accept_event(); @@ -852,12 +782,10 @@ void GridMapEditor::_sbox_input(const Ref<InputEvent> &p_ie) { } void GridMapEditor::_mesh_library_palette_input(const Ref<InputEvent> &p_ie) { - const Ref<InputEventMouseButton> mb = p_ie; // Zoom in/out using Ctrl + mouse wheel if (mb.is_valid() && mb->is_pressed() && mb->get_command()) { - if (mb->is_pressed() && mb->get_button_index() == BUTTON_WHEEL_UP) { size_slider->set_value(size_slider->get_value() + 0.2); } @@ -911,7 +839,6 @@ void GridMapEditor::update_palette() { List<_CGMEItemSort> il; for (int i = 0; i < ids.size(); i++) { - _CGMEItemSort is; is.id = ids[i]; is.name = mesh_library->get_item_name(ids[i]); @@ -993,7 +920,6 @@ void GridMapEditor::edit(GridMap *p_gridmap) { } void GridMapEditor::_update_clip() { - node->set_meta("_editor_clip_", clip_mode); if (clip_mode == CLIP_DISABLED) node->set_clip(false); @@ -1002,7 +928,6 @@ void GridMapEditor::_update_clip() { } void GridMapEditor::update_grid() { - grid_xform.origin.x -= 1; // Force update in hackish way. grid_ofs[edit_axis] = edit_floor[edit_axis] * node->get_cell_size()[edit_axis]; @@ -1031,7 +956,6 @@ void GridMapEditor::_draw_grids(const Vector3 &cell_size) { Vector<Color> grid_colors[3]; for (int i = 0; i < 3; i++) { - Vector3 axis; axis[i] = 1; Vector3 axis_n1; @@ -1040,9 +964,7 @@ void GridMapEditor::_draw_grids(const Vector3 &cell_size) { axis_n2[(i + 2) % 3] = cell_size[(i + 2) % 3]; for (int j = -GRID_CURSOR_SIZE; j <= GRID_CURSOR_SIZE; j++) { - for (int k = -GRID_CURSOR_SIZE; k <= GRID_CURSOR_SIZE; k++) { - Vector3 p = axis_n1 * j + axis_n2 * k; float trans = Math::pow(MAX(0, 1.0 - (Vector2(j, k).length() / GRID_CURSOR_SIZE)), 2); @@ -1074,14 +996,11 @@ void GridMapEditor::_draw_grids(const Vector3 &cell_size) { } void GridMapEditor::_notification(int p_what) { - switch (p_what) { - case NOTIFICATION_ENTER_TREE: { get_tree()->connect("node_removed", callable_mp(this, &GridMapEditor::_node_removed)); mesh_library_palette->connect("item_selected", callable_mp(this, &GridMapEditor::_item_selected_cbk)); for (int i = 0; i < 3; i++) { - grid[i] = RS::get_singleton()->mesh_create(); grid_instance[i] = RS::get_singleton()->instance_create2(grid[i], get_tree()->get_root()->get_world_3d()->get_scenario()); selection_level_instance[i] = RenderingServer::get_singleton()->instance_create2(selection_level_mesh[i], get_tree()->get_root()->get_world_3d()->get_scenario()); @@ -1099,7 +1018,6 @@ void GridMapEditor::_notification(int p_what) { _clear_clipboard_data(); for (int i = 0; i < 3; i++) { - RS::get_singleton()->free(grid_instance[i]); RS::get_singleton()->free(grid[i]); grid_instance[i] = RID(); @@ -1122,7 +1040,6 @@ void GridMapEditor::_notification(int p_what) { if (xf != grid_xform) { for (int i = 0; i < 3; i++) { - RS::get_singleton()->instance_set_transform(grid_instance[i], xf * edit_grid_xform); } grid_xform = xf; @@ -1132,7 +1049,6 @@ void GridMapEditor::_notification(int p_what) { update_palette(); if (lock_view) { - EditorNode *editor = Object::cast_to<EditorNode>(get_tree()->get_root()->get_child(0)); Plane p; @@ -1163,11 +1079,9 @@ void GridMapEditor::_update_cursor_instance() { cursor_instance = RID(); if (selected_palette >= 0) { - if (node && !node->get_mesh_library().is_null()) { Ref<Mesh> mesh = node->get_mesh_library()->get_item_mesh(selected_palette); if (!mesh.is_null() && mesh->get_rid().is_valid()) { - cursor_instance = RenderingServer::get_singleton()->instance_create2(mesh->get_rid(), get_tree()->get_root()->get_world_3d()->get_scenario()); RenderingServer::get_singleton()->instance_set_transform(cursor_instance, cursor_transform); } @@ -1182,7 +1096,6 @@ void GridMapEditor::_item_selected_cbk(int idx) { } void GridMapEditor::_floor_changed(float p_value) { - if (updating) return; @@ -1198,13 +1111,11 @@ void GridMapEditor::_floor_mouse_exited() { } void GridMapEditor::_bind_methods() { - ClassDB::bind_method("_configure", &GridMapEditor::_configure); ClassDB::bind_method("_set_selection", &GridMapEditor::_set_selection); } GridMapEditor::GridMapEditor(EditorNode *p_editor) { - input_action = INPUT_NONE; editor = p_editor; undo_redo = p_editor->get_undo_redo(); @@ -1364,18 +1275,15 @@ GridMapEditor::GridMapEditor(EditorNode *p_editor) { Vector<Vector3> square[3]; for (int i = 0; i < 6; i++) { - Vector3 face_points[4]; for (int j = 0; j < 4; j++) { - float v[3]; v[0] = 1.0; v[1] = 1 - 2 * ((j >> 1) & 1); v[2] = v[1] * (1 - 2 * (j & 1)); for (int k = 0; k < 3; k++) { - if (i < 3) face_points[j][(i + k) % 3] = v[k]; else @@ -1393,7 +1301,6 @@ GridMapEditor::GridMapEditor(EditorNode *p_editor) { } for (int i = 0; i < 12; i++) { - AABB base(Vector3(0, 0, 0), Vector3(1, 1, 1)); Vector3 a, b; base.get_edge(i, a, b); @@ -1404,7 +1311,6 @@ GridMapEditor::GridMapEditor(EditorNode *p_editor) { for (int i = 0; i < 3; i++) { Vector3 points[4]; for (int j = 0; j < 4; j++) { - static const bool orderx[4] = { false, true, true, false }; static const bool ordery[4] = { false, false, true, true }; @@ -1420,7 +1326,6 @@ GridMapEditor::GridMapEditor(EditorNode *p_editor) { } for (int j = 0; j < 4; j++) { - Vector3 ofs; ofs[i] += 0.01; square[i].push_back(points[j] - ofs); @@ -1487,11 +1392,9 @@ GridMapEditor::GridMapEditor(EditorNode *p_editor) { } GridMapEditor::~GridMapEditor() { - _clear_clipboard_data(); for (int i = 0; i < 3; i++) { - if (grid[i].is_valid()) RenderingServer::get_singleton()->free(grid[i]); if (grid_instance[i].is_valid()) @@ -1514,9 +1417,7 @@ GridMapEditor::~GridMapEditor() { } void GridMapEditorPlugin::_notification(int p_what) { - if (p_what == EditorSettings::NOTIFICATION_EDITOR_SETTINGS_CHANGED) { - switch ((int)EditorSettings::get_singleton()->get("editors/grid_map/editor_side")) { case 0: { // Left. Node3DEditor::get_singleton()->get_palette_split()->move_child(grid_map_editor, 0); @@ -1529,23 +1430,19 @@ void GridMapEditorPlugin::_notification(int p_what) { } void GridMapEditorPlugin::edit(Object *p_object) { - grid_map_editor->edit(Object::cast_to<GridMap>(p_object)); } bool GridMapEditorPlugin::handles(Object *p_object) const { - return p_object->is_class("GridMap"); } void GridMapEditorPlugin::make_visible(bool p_visible) { - if (p_visible) { grid_map_editor->show(); grid_map_editor->spatial_editor_hb->show(); grid_map_editor->set_process(true); } else { - grid_map_editor->spatial_editor_hb->hide(); grid_map_editor->hide(); grid_map_editor->edit(nullptr); @@ -1554,7 +1451,6 @@ void GridMapEditorPlugin::make_visible(bool p_visible) { } GridMapEditorPlugin::GridMapEditorPlugin(EditorNode *p_node) { - editor = p_node; EDITOR_DEF("editors/grid_map/editor_side", 1); diff --git a/modules/gridmap/grid_map_editor_plugin.h b/modules/gridmap/grid_map_editor_plugin.h index fd880e8b7b..19eea18965 100644 --- a/modules/gridmap/grid_map_editor_plugin.h +++ b/modules/gridmap/grid_map_editor_plugin.h @@ -85,7 +85,6 @@ class GridMapEditor : public VBoxContainer { Label *spin_box_label; struct SetItem { - Vector3 pos; int new_value; int new_orientation; @@ -133,7 +132,6 @@ class GridMapEditor : public VBoxContainer { bool updating; struct Selection { - Vector3 click; Vector3 current; Vector3 begin; @@ -143,7 +141,6 @@ class GridMapEditor : public VBoxContainer { Selection last_selection; struct PasteIndicator { - Vector3 click; Vector3 current; Vector3 begin; @@ -191,7 +188,6 @@ class GridMapEditor : public VBoxContainer { Node3DEditorPlugin *spatial_editor; struct AreaDisplay { - RID mesh; RID instance; }; @@ -251,7 +247,6 @@ public: }; class GridMapEditorPlugin : public EditorPlugin { - GDCLASS(GridMapEditorPlugin, EditorPlugin); GridMapEditor *grid_map_editor; diff --git a/modules/gridmap/register_types.cpp b/modules/gridmap/register_types.cpp index afd51945ab..906e506b62 100644 --- a/modules/gridmap/register_types.cpp +++ b/modules/gridmap/register_types.cpp @@ -36,7 +36,6 @@ #endif void register_gridmap_types() { - #ifndef _3D_DISABLED ClassDB::register_class<GridMap>(); #ifdef TOOLS_ENABLED |