diff options
Diffstat (limited to 'modules/gridmap')
-rw-r--r-- | modules/gridmap/grid_map.cpp | 160 | ||||
-rw-r--r-- | modules/gridmap/grid_map.h | 9 | ||||
-rw-r--r-- | modules/gridmap/grid_map_editor_plugin.cpp | 227 | ||||
-rw-r--r-- | modules/gridmap/grid_map_editor_plugin.h | 5 | ||||
-rw-r--r-- | modules/gridmap/register_types.cpp | 1 |
5 files changed, 138 insertions, 264 deletions
diff --git a/modules/gridmap/grid_map.cpp b/modules/gridmap/grid_map.cpp index 0dbefbb39f..2975a97bfe 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++) { @@ -127,14 +118,14 @@ bool GridMap::_get(const StringName &p_name, Variant &r_ret) const { } r_ret = ret; - } else + } else { return false; + } return true; } 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,71 +134,65 @@ 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) + if (p_value) { mask |= 1 << p_bit; - else + } else { mask &= ~(1 << p_bit); + } set_collision_mask(mask); } 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) + if (p_value) { mask |= 1 << p_bit; - else + } else { mask &= ~(1 << p_bit); + } set_collision_layer(mask); } 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()) + if (!mesh_library.is_null()) { mesh_library->unregister_owner(this); + } mesh_library = p_mesh_library; - if (!mesh_library.is_null()) + if (!mesh_library.is_null()) { mesh_library->register_owner(this); + } _recreate_octant_data(); _change_notify("mesh_library"); } Ref<MeshLibrary> GridMap::get_mesh_library() const { - return mesh_library; } @@ -217,24 +202,22 @@ void GridMap::set_cell_size(const Vector3 &p_size) { _recreate_octant_data(); emit_signal("cell_size_changed", cell_size); } -Vector3 GridMap::get_cell_size() const { +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 { +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 +227,6 @@ bool GridMap::get_center_x() const { } void GridMap::set_center_y(bool p_enable) { - center_y = p_enable; _recreate_octant_data(); } @@ -254,7 +236,6 @@ bool GridMap::get_center_y() const { } void GridMap::set_center_z(bool p_enable) { - center_z = p_enable; _recreate_octant_data(); } @@ -264,7 +245,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 +293,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 +319,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); @@ -350,13 +328,13 @@ int GridMap::get_cell_item(int p_x, int p_y, int p_z) const { key.y = p_y; key.z = p_z; - if (!cell_map.has(key)) + if (!cell_map.has(key)) { return INVALID_CELL_ITEM; + } return cell_map[key].item; } 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); @@ -366,8 +344,9 @@ int GridMap::get_cell_item_orientation(int p_x, int p_y, int p_z) const { key.y = p_y; key.z = p_z; - if (!cell_map.has(key)) + if (!cell_map.has(key)) { return -1; + } return cell_map[key].rot; } @@ -389,7 +368,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()); @@ -406,15 +384,15 @@ void GridMap::_octant_transform(const OctantKey &p_key) { bool GridMap::_octant_update(const OctantKey &p_key) { ERR_FAIL_COND_V(!octant_map.has(p_key), false); Octant &g = *octant_map[p_key]; - if (!g.dirty) + if (!g.dirty) { return false; + } //erase body shapes PhysicsServer3D::get_singleton()->body_clear_shapes(g.static_body); //erase body shapes debug if (g.collision_debug.is_valid()) { - RS::get_singleton()->mesh_clear(g.collision_debug); } @@ -427,7 +405,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,12 +427,12 @@ 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()]; - if (!mesh_library.is_valid() || !mesh_library->has_item(c.item)) + if (!mesh_library.is_valid() || !mesh_library->has_item(c.item)) { continue; + } Vector3 cellpos = Vector3(E->get().x, E->get().y, E->get().z); Vector3 ofs = _get_offset(); @@ -482,8 +459,9 @@ bool GridMap::_octant_update(const OctantKey &p_key) { // add the item's shape at given xform to octant's static_body for (int i = 0; i < shapes.size(); i++) { // add the item's shape - if (!shapes[i].shape.is_valid()) + if (!shapes[i].shape.is_valid()) { continue; + } PhysicsServer3D::get_singleton()->body_add_shape(g.static_body, shapes[i].shape->get_rid(), xform * shapes[i].local_transform); if (g.collision_debug.is_valid()) { shapes.write[i].shape->add_vertices_to_array(col_debug, xform * shapes[i].local_transform); @@ -509,7 +487,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 +525,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 +549,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 +566,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 +581,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 +596,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,14 +605,15 @@ 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]; - if (g.collision_debug.is_valid()) + if (g.collision_debug.is_valid()) { RS::get_singleton()->free(g.collision_debug); - if (g.collision_debug_instance.is_valid()) + } + if (g.collision_debug_instance.is_valid()) { RS::get_singleton()->free(g.collision_debug_instance); + } PhysicsServer3D::get_singleton()->free(g.static_body); @@ -654,7 +626,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 +633,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,10 +658,10 @@ void GridMap::_notification(int p_what) { } break; case NOTIFICATION_TRANSFORM_CHANGED: { - Transform new_xform = get_global_transform(); - if (new_xform == last_transform) + if (new_xform == last_transform) { break; + } //update run for (Map<OctantKey, Octant *>::Element *E = octant_map.front(); E; E = E->next()) { _octant_transform(E->key()); @@ -707,7 +675,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()); } @@ -729,8 +696,9 @@ void GridMap::_notification(int p_what) { } void GridMap::_update_visibility() { - if (!is_inside_tree()) + if (!is_inside_tree()) { return; + } _change_notify("visible"); @@ -744,31 +712,29 @@ void GridMap::_update_visibility() { } void GridMap::_queue_octants_dirty() { - - if (awaiting_update) + if (awaiting_update) { return; + } MessageQueue::get_singleton()->push_call(this, "_update_octants_callback"); awaiting_update = true; } 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()) + if (is_inside_world()) { _octant_exit_world(E->key()); + } _octant_clean_up(E->key()); memdelete(E->get()); @@ -779,24 +745,21 @@ 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) + 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 +775,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,11 +847,12 @@ 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) + if (!p_enabled && !clip) { return; - if (clip && p_enabled && clip_floor == p_floor && p_clip_above == clip_above && p_axis == clip_axis) + } + if (clip && p_enabled && clip_floor == p_floor && p_clip_above == clip_above && p_axis == clip_axis) { return; + } clip = p_enabled; clip_floor = p_floor; @@ -898,7 +861,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 +869,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,21 +890,22 @@ Array GridMap::get_used_cells() const { } Array GridMap::get_meshes() { - - if (mesh_library.is_null()) + if (mesh_library.is_null()) { return Array(); + } Vector3 ofs = _get_offset(); 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)) + if (!mesh_library->has_item(id)) { continue; + } Ref<Mesh> mesh = mesh_library->get_item_mesh(id); - if (mesh.is_null()) + if (mesh.is_null()) { continue; + } IndexKey ik = E->key(); @@ -973,7 +933,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,24 +942,25 @@ 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()) + if (!mesh_library.is_valid()) { return; + } //generate 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; - if (!mesh_library->has_item(item)) + if (!mesh_library->has_item(item)) { continue; + } Ref<Mesh> mesh = mesh_library->get_item_mesh(item); - if (!mesh.is_valid()) + if (!mesh.is_valid()) { continue; + } Vector3 cellpos = Vector3(key.x, key.y, key.z); Vector3 ofs = _get_offset(); @@ -1023,9 +983,9 @@ 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) + if (mesh->surface_get_primitive_type(i) != Mesh::PRIMITIVE_TRIANGLES) { continue; + } Ref<Material> surf_mat = mesh->surface_get_material(i); if (!mat_map.has(surf_mat)) { @@ -1041,7 +1001,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 +1027,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 +1041,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,9 +1069,9 @@ GridMap::GridMap() { } GridMap::~GridMap() { - - if (!mesh_library.is_null()) + if (!mesh_library.is_null()) { mesh_library->unregister_owner(this); + } clear(); } 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 9abbac6a0b..2bae43510a 100644 --- a/modules/gridmap/grid_map_editor_plugin.cpp +++ b/modules/gridmap/grid_map_editor_plugin.cpp @@ -40,23 +40,21 @@ #include "scene/main/window.h" void GridMapEditor::_node_removed(Node *p_node) { - - if (p_node == node) + if (p_node == node) { node = nullptr; + } } void GridMapEditor::_configure() { - - if (!node) + if (!node) { return; + } update_grid(); } 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 +64,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 +72,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 +83,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 +108,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 +123,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 +138,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 +153,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 +168,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 +183,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 +198,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; @@ -235,8 +215,9 @@ void GridMapEditor::_menu_option(int p_option) { case MENU_OPTION_SELECTION_DUPLICATE: case MENU_OPTION_SELECTION_CUT: { - if (!(selection.active && input_action == INPUT_NONE)) + if (!(selection.active && input_action == INPUT_NONE)) { break; + } _set_clipboard_data(); @@ -253,15 +234,17 @@ void GridMapEditor::_menu_option(int p_option) { _update_paste_indicator(); } break; case MENU_OPTION_SELECTION_CLEAR: { - if (!selection.active) + if (!selection.active) { break; + } _delete_selection(); } break; case MENU_OPTION_SELECTION_FILL: { - if (!selection.active) + if (!selection.active) { return; + } _fill_selection(); @@ -273,7 +256,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 +273,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 +290,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,24 +308,26 @@ void GridMapEditor::_update_selection_transform() { } void GridMapEditor::_validate_selection() { - - if (!selection.active) + if (!selection.active) { return; + } selection.begin = selection.click; selection.end = selection.current; - if (selection.begin.x > selection.end.x) + if (selection.begin.x > selection.end.x) { SWAP(selection.begin.x, selection.end.x); - if (selection.begin.y > selection.end.y) + } + if (selection.begin.y > selection.end.y) { SWAP(selection.begin.y, selection.end.y); - if (selection.begin.z > selection.end.z) + } + if (selection.begin.z > selection.end.z) { SWAP(selection.begin.z, selection.end.z); + } _update_selection_transform(); } 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,17 +345,20 @@ 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) + if (!spatial_editor) { return false; + } - if (selected_palette < 0 && input_action != INPUT_PICK && input_action != INPUT_SELECT && input_action != INPUT_PASTE) + if (selected_palette < 0 && input_action != INPUT_PICK && input_action != INPUT_SELECT && input_action != INPUT_PASTE) { return false; + } Ref<MeshLibrary> mesh_library = node->get_mesh_library(); - if (mesh_library.is_null()) + if (mesh_library.is_null()) { return false; - if (input_action != INPUT_PICK && input_action != INPUT_SELECT && input_action != INPUT_PASTE && !mesh_library->has_item(selected_palette)) + } + if (input_action != INPUT_PICK && input_action != INPUT_SELECT && input_action != INPUT_PASTE && !mesh_library->has_item(selected_palette)) { return false; + } Camera3D *camera = p_camera; Vector3 from = camera->project_ray_origin(p_point); @@ -388,30 +373,30 @@ bool GridMapEditor::do_input_action(Camera3D *p_camera, const Point2 &p_point, b p.d = edit_floor[edit_axis] * node->get_cell_size()[edit_axis]; Vector3 inters; - if (!p.intersects_segment(from, from + normal * settings_pick_distance->get_value(), &inters)) + if (!p.intersects_segment(from, from + normal * settings_pick_distance->get_value(), &inters)) { return false; + } // 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)) + if (fp.is_point_over(inters)) { return false; + } } int cell[3]; 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) + if (i == edit_axis) { cell[i] = edit_floor[i]; - else { - + } else { cell[i] = inters[i] / node->get_cell_size()[i]; - if (inters[i] < 0) + if (inters[i] < 0) { cell[i] -= 1; // Compensate negative. + } grid_ofs[i] = cell[i] * cell_size[i]; } } @@ -419,7 +404,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,21 +415,19 @@ 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) + if (p_click) { selection.click = selection.current; + } selection.active = true; _validate_selection(); 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 +463,14 @@ bool GridMapEditor::do_input_action(Camera3D *p_camera, const Point2 &p_point, b } void GridMapEditor::_delete_selection() { - - if (!selection.active) + 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 +482,14 @@ void GridMapEditor::_delete_selection() { } void GridMapEditor::_fill_selection() { - - if (!selection.active) + 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 +501,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,20 +509,17 @@ 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) + if (itm == GridMap::INVALID_CELL_ITEM) { continue; + } Ref<Mesh> mesh = meshLibrary->get_item_mesh(itm); @@ -565,9 +536,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 +556,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 +572,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 +582,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 +595,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,15 +612,16 @@ 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()) + if (mb->is_pressed()) { floor->set_value(floor->get_value() + mb->get_factor()); + } return true; // Eaten. } else if (mb->get_button_index() == BUTTON_WHEEL_DOWN && (mb->get_command() || mb->get_shift())) { - if (mb->is_pressed()) + if (mb->is_pressed()) { floor->set_value(floor->get_value() - mb->get_factor()); + } return true; } @@ -664,7 +630,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 +663,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 +683,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 +690,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 +704,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 +712,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 +730,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 +746,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 +766,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 +794,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 +804,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 +861,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]); @@ -932,8 +881,9 @@ void GridMapEditor::update_palette() { name = "#" + itos(id); } - if (filter != "" && !filter.is_subsequence_ofi(name)) + if (filter != "" && !filter.is_subsequence_ofi(name)) { continue; + } mesh_library_palette->add_item(""); if (!preview.is_null()) { @@ -954,8 +904,9 @@ void GridMapEditor::update_palette() { } void GridMapEditor::edit(GridMap *p_gridmap) { - if (!p_gridmap && node) + if (!p_gridmap && node) { node->disconnect("cell_size_changed", callable_mp(this, &GridMapEditor::_draw_grids)); + } node = p_gridmap; @@ -993,16 +944,15 @@ void GridMapEditor::edit(GridMap *p_gridmap) { } void GridMapEditor::_update_clip() { - node->set_meta("_editor_clip_", clip_mode); - if (clip_mode == CLIP_DISABLED) + if (clip_mode == CLIP_DISABLED) { node->set_clip(false); - else + } else { node->set_clip(true, clip_mode == CLIP_ABOVE, edit_floor[edit_axis], edit_axis); + } } 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 +981,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 +989,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 +1021,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 +1043,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,17 +1065,16 @@ 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; } Ref<MeshLibrary> cgmt = node->get_mesh_library(); - if (cgmt.operator->() != last_mesh_library) + if (cgmt.operator->() != last_mesh_library) { update_palette(); + } if (lock_view) { - EditorNode *editor = Object::cast_to<EditorNode>(get_tree()->get_root()->get_child(0)); Plane p; @@ -1141,8 +1083,9 @@ void GridMapEditor::_notification(int p_what) { p = node->get_transform().xform(p); // plane to snap Node3DEditorPlugin *sep = Object::cast_to<Node3DEditorPlugin>(editor->get_editor_plugin_screen()); - if (sep) + if (sep) { sep->snap_cursor_to_plane(p); + } } } break; @@ -1158,16 +1101,15 @@ void GridMapEditor::_update_cursor_instance() { return; } - if (cursor_instance.is_valid()) + if (cursor_instance.is_valid()) { RenderingServer::get_singleton()->free(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,9 +1124,9 @@ void GridMapEditor::_item_selected_cbk(int idx) { } void GridMapEditor::_floor_changed(float p_value) { - - if (updating) + if (updating) { return; + } edit_floor[edit_axis] = p_value; node->set_meta("_editor_floor_", Vector3(edit_floor[0], edit_floor[1], edit_floor[2])); @@ -1198,13 +1140,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,22 +1304,20 @@ 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) + if (i < 3) { face_points[j][(i + k) % 3] = v[k]; - else + } else { face_points[3 - j][(i + k) % 3] = -v[k]; + } } } @@ -1393,7 +1331,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,9 +1341,8 @@ 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] = { 0, 1, 1, 0 }; - static const bool ordery[4] = { 0, 0, 1, 1 }; + static const bool orderx[4] = { false, true, true, false }; + static const bool ordery[4] = { false, false, true, true }; Vector3 sp; if (orderx[j]) { @@ -1420,7 +1356,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,36 +1422,39 @@ GridMapEditor::GridMapEditor(EditorNode *p_editor) { } GridMapEditor::~GridMapEditor() { - _clear_clipboard_data(); for (int i = 0; i < 3; i++) { - - if (grid[i].is_valid()) + if (grid[i].is_valid()) { RenderingServer::get_singleton()->free(grid[i]); - if (grid_instance[i].is_valid()) + } + if (grid_instance[i].is_valid()) { RenderingServer::get_singleton()->free(grid_instance[i]); - if (cursor_instance.is_valid()) + } + if (cursor_instance.is_valid()) { RenderingServer::get_singleton()->free(cursor_instance); - if (selection_level_instance[i].is_valid()) + } + if (selection_level_instance[i].is_valid()) { RenderingServer::get_singleton()->free(selection_level_instance[i]); - if (selection_level_mesh[i].is_valid()) + } + if (selection_level_mesh[i].is_valid()) { RenderingServer::get_singleton()->free(selection_level_mesh[i]); + } } RenderingServer::get_singleton()->free(selection_mesh); - if (selection_instance.is_valid()) + if (selection_instance.is_valid()) { RenderingServer::get_singleton()->free(selection_instance); + } RenderingServer::get_singleton()->free(paste_mesh); - if (paste_instance.is_valid()) + if (paste_instance.is_valid()) { RenderingServer::get_singleton()->free(paste_instance); + } } 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 +1467,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 +1488,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 |