summaryrefslogtreecommitdiff
path: root/modules/gridmap
diff options
context:
space:
mode:
Diffstat (limited to 'modules/gridmap')
-rw-r--r--modules/gridmap/config.py2
-rw-r--r--modules/gridmap/doc_classes/GridMap.xml11
-rw-r--r--modules/gridmap/grid_map.cpp110
-rw-r--r--modules/gridmap/grid_map.h16
-rw-r--r--modules/gridmap/grid_map_editor_plugin.cpp107
-rw-r--r--modules/gridmap/grid_map_editor_plugin.h7
-rw-r--r--modules/gridmap/icons/GridMap.svg2
-rw-r--r--modules/gridmap/register_types.cpp2
8 files changed, 141 insertions, 116 deletions
diff --git a/modules/gridmap/config.py b/modules/gridmap/config.py
index a6319fe1ea..720401b92d 100644
--- a/modules/gridmap/config.py
+++ b/modules/gridmap/config.py
@@ -1,5 +1,5 @@
def can_build(env, platform):
- return True
+ return not env["disable_3d"]
def configure(env):
diff --git a/modules/gridmap/doc_classes/GridMap.xml b/modules/gridmap/doc_classes/GridMap.xml
index 134aadb75e..a2c8e8eabf 100644
--- a/modules/gridmap/doc_classes/GridMap.xml
+++ b/modules/gridmap/doc_classes/GridMap.xml
@@ -41,6 +41,7 @@
<return type="Array">
</return>
<description>
+ Returns an array of [ArrayMesh]es and [Transform3D] references of all bake meshes that exist within the current GridMap.
</description>
</method>
<method name="get_cell_item" qualifiers="const">
@@ -83,7 +84,7 @@
<return type="Array">
</return>
<description>
- Returns an array of [Transform] and [Mesh] references corresponding to the non-empty cells in the grid. The transforms are specified in world space.
+ Returns an array of [Transform3D] and [Mesh] references corresponding to the non-empty cells in the grid. The transforms are specified in world space.
</description>
</method>
<method name="get_used_cells" qualifiers="const">
@@ -183,6 +184,9 @@
</method>
</methods>
<members>
+ <member name="bake_navigation" type="bool" setter="set_bake_navigation" getter="is_baking_navigation" default="false">
+ If [code]true[/code], this GridMap bakes a navigation region.
+ </member>
<member name="cell_center_x" type="bool" setter="set_center_x" getter="get_center_x" default="true">
If [code]true[/code], grid items are centered on the X axis.
</member>
@@ -199,7 +203,7 @@
The scale of the cell items.
This does not affect the size of the grid cells themselves, only the items in them. This can be used to make cell items overlap their neighbors.
</member>
- <member name="cell_size" type="Vector3" setter="set_cell_size" getter="get_cell_size" default="Vector3( 2, 2, 2 )">
+ <member name="cell_size" type="Vector3" setter="set_cell_size" getter="get_cell_size" default="Vector3(2, 2, 2)">
The dimensions of the grid's cells.
This does not affect the size of the meshes. See [member cell_scale].
</member>
@@ -213,6 +217,9 @@
<member name="mesh_library" type="MeshLibrary" setter="set_mesh_library" getter="get_mesh_library">
The assigned [MeshLibrary].
</member>
+ <member name="navigation_layers" type="int" setter="set_navigation_layers" getter="get_navigation_layers" default="1">
+ The navigation layers the GridMap generates its navigable regions in.
+ </member>
</members>
<signals>
<signal name="cell_size_changed">
diff --git a/modules/gridmap/grid_map.cpp b/modules/gridmap/grid_map.cpp
index e7c252dc53..0cd41133f1 100644
--- a/modules/gridmap/grid_map.cpp
+++ b/modules/gridmap/grid_map.cpp
@@ -152,6 +152,7 @@ uint32_t GridMap::get_collision_mask() const {
}
void GridMap::set_collision_mask_bit(int p_bit, bool p_value) {
+ ERR_FAIL_INDEX_MSG(p_bit, 32, "Collision mask bit must be between 0 and 31 inclusive.");
uint32_t mask = get_collision_mask();
if (p_value) {
mask |= 1 << p_bit;
@@ -162,23 +163,44 @@ void GridMap::set_collision_mask_bit(int p_bit, bool p_value) {
}
bool GridMap::get_collision_mask_bit(int p_bit) const {
+ ERR_FAIL_INDEX_V_MSG(p_bit, 32, false, "Collision mask bit must be between 0 and 31 inclusive.");
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();
+ ERR_FAIL_INDEX_MSG(p_bit, 32, "Collision layer bit must be between 0 and 31 inclusive.");
+ uint32_t layer = get_collision_layer();
if (p_value) {
- mask |= 1 << p_bit;
+ layer |= 1 << p_bit;
} else {
- mask &= ~(1 << p_bit);
+ layer &= ~(1 << p_bit);
}
- set_collision_layer(mask);
+ set_collision_layer(layer);
}
bool GridMap::get_collision_layer_bit(int p_bit) const {
+ ERR_FAIL_INDEX_V_MSG(p_bit, 32, false, "Collision layer bit must be between 0 and 31 inclusive.");
return get_collision_layer() & (1 << p_bit);
}
+void GridMap::set_bake_navigation(bool p_bake_navigation) {
+ bake_navigation = p_bake_navigation;
+ _recreate_octant_data();
+}
+
+bool GridMap::is_baking_navigation() {
+ return bake_navigation;
+}
+
+void GridMap::set_navigation_layers(uint32_t p_layers) {
+ navigation_layers = p_layers;
+ _recreate_octant_data();
+}
+
+uint32_t GridMap::get_navigation_layers() {
+ return navigation_layers;
+}
+
void GridMap::set_mesh_library(const Ref<MeshLibrary> &p_mesh_library) {
if (!mesh_library.is_null()) {
mesh_library->unregister_owner(this);
@@ -199,7 +221,7 @@ void GridMap::set_cell_size(const Vector3 &p_size) {
ERR_FAIL_COND(p_size.x < 0.001 || p_size.y < 0.001 || p_size.z < 0.001);
cell_size = p_size;
_recreate_octant_data();
- emit_signal("cell_size_changed", cell_size);
+ emit_signal(SNAME("cell_size_changed"), cell_size);
}
Vector3 GridMap::get_cell_size() const {
@@ -424,7 +446,7 @@ bool GridMap::_octant_update(const OctantKey &p_key) {
* and set said multimesh bounding box to one containing all cells which have this item
*/
- Map<int, List<Pair<Transform, IndexKey>>> multimesh_items;
+ Map<int, List<Pair<Transform3D, IndexKey>>> multimesh_items;
for (Set<IndexKey>::Element *E = g.cells.front(); E; E = E->next()) {
ERR_CONTINUE(!cell_map.has(E->get()));
@@ -437,7 +459,7 @@ bool GridMap::_octant_update(const OctantKey &p_key) {
Vector3 cellpos = Vector3(E->get().x, E->get().y, E->get().z);
Vector3 ofs = _get_offset();
- Transform xform;
+ Transform3D xform;
xform.basis.set_orthogonal_index(c.rot);
xform.set_origin(cellpos * cell_size + ofs);
@@ -445,10 +467,10 @@ bool GridMap::_octant_update(const OctantKey &p_key) {
if (baked_meshes.size() == 0) {
if (mesh_library->get_item_mesh(c.item).is_valid()) {
if (!multimesh_items.has(c.item)) {
- multimesh_items[c.item] = List<Pair<Transform, IndexKey>>();
+ multimesh_items[c.item] = List<Pair<Transform3D, IndexKey>>();
}
- Pair<Transform, IndexKey> p;
+ Pair<Transform3D, IndexKey> p;
p.first = xform;
p.second = E->get();
multimesh_items[c.item].push_back(p);
@@ -474,20 +496,22 @@ bool GridMap::_octant_update(const OctantKey &p_key) {
Octant::NavMesh nm;
nm.xform = xform * mesh_library->get_item_navmesh_transform(c.item);
- if (navigation) {
+ if (bake_navigation) {
RID region = NavigationServer3D::get_singleton()->region_create();
+ NavigationServer3D::get_singleton()->region_set_layers(region, navigation_layers);
NavigationServer3D::get_singleton()->region_set_navmesh(region, navmesh);
- NavigationServer3D::get_singleton()->region_set_transform(region, navigation->get_global_transform() * nm.xform);
- NavigationServer3D::get_singleton()->region_set_map(region, navigation->get_rid());
+ NavigationServer3D::get_singleton()->region_set_transform(region, get_global_transform() * mesh_library->get_item_navmesh_transform(c.item));
+ NavigationServer3D::get_singleton()->region_set_map(region, get_world_3d()->get_navigation_map());
nm.region = region;
}
+
g.navmesh_ids[E->get()] = nm;
}
}
//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()) {
+ for (Map<int, List<Pair<Transform3D, IndexKey>>>::Element *E = multimesh_items.front(); E; E = E->next()) {
Octant::MultimeshInstance mmi;
RID mm = RS::get_singleton()->multimesh_create();
@@ -495,7 +519,7 @@ bool GridMap::_octant_update(const OctantKey &p_key) {
RS::get_singleton()->multimesh_set_mesh(mm, mesh_library->get_item_mesh(E->key())->get_rid());
int idx = 0;
- for (List<Pair<Transform, IndexKey>>::Element *F = E->get().front(); F; F = F->next()) {
+ for (List<Pair<Transform3D, IndexKey>>::Element *F = E->get().front(); F; F = F->next()) {
RS::get_singleton()->multimesh_instance_set_transform(mm, idx, F->get().first);
#ifdef TOOLS_ENABLED
@@ -564,15 +588,17 @@ void GridMap::_octant_enter_world(const OctantKey &p_key) {
RS::get_singleton()->instance_set_transform(g.multimesh_instances[i].instance, get_global_transform());
}
- if (navigation && mesh_library.is_valid()) {
+ if (bake_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()) {
RID region = NavigationServer3D::get_singleton()->region_create();
+ NavigationServer3D::get_singleton()->region_set_layers(region, navigation_layers);
NavigationServer3D::get_singleton()->region_set_navmesh(region, nm);
- NavigationServer3D::get_singleton()->region_set_transform(region, navigation->get_global_transform() * F->get().xform);
- NavigationServer3D::get_singleton()->region_set_map(region, navigation->get_rid());
+ NavigationServer3D::get_singleton()->region_set_transform(region, get_global_transform() * F->get().xform);
+ NavigationServer3D::get_singleton()->region_set_map(region, get_world_3d()->get_navigation_map());
+
F->get().region = region;
}
}
@@ -594,12 +620,10 @@ void GridMap::_octant_exit_world(const OctantKey &p_key) {
RS::get_singleton()->instance_set_scenario(g.multimesh_instances[i].instance, RID());
}
- 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();
- }
+ 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();
}
}
}
@@ -635,16 +659,6 @@ 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);
- if (navigation) {
- break;
- }
-
- c = Object::cast_to<Node3D>(c->get_parent());
- }
-
last_transform = get_global_transform();
for (Map<OctantKey, Octant *>::Element *E = octant_map.front(); E; E = E->next()) {
@@ -658,7 +672,7 @@ void GridMap::_notification(int p_what) {
} break;
case NOTIFICATION_TRANSFORM_CHANGED: {
- Transform new_xform = get_global_transform();
+ Transform3D new_xform = get_global_transform();
if (new_xform == last_transform) {
break;
}
@@ -672,15 +686,12 @@ void GridMap::_notification(int p_what) {
for (int i = 0; i < baked_meshes.size(); i++) {
RS::get_singleton()->instance_set_transform(baked_meshes[i].instance, get_global_transform());
}
-
} break;
case NOTIFICATION_EXIT_WORLD: {
for (Map<OctantKey, Octant *>::Element *E = octant_map.front(); E; E = E->next()) {
_octant_exit_world(E->key());
}
- navigation = nullptr;
-
//_queue_octants_dirty(MAP_DIRTY_INSTANCES|MAP_DIRTY_TRANSFORMS);
//_update_octants_callback();
//_update_area_instances();
@@ -707,6 +718,10 @@ void GridMap::_update_visibility() {
RS::get_singleton()->instance_set_visible(mi.instance, is_visible_in_tree());
}
}
+
+ for (int i = 0; i < baked_meshes.size(); i++) {
+ RS::get_singleton()->instance_set_visible(baked_meshes[i].instance, is_visible_in_tree());
+ }
}
void GridMap::_queue_octants_dirty() {
@@ -765,7 +780,7 @@ void GridMap::_update_octants_callback() {
while (to_delete.front()) {
octant_map.erase(to_delete.front()->get());
- to_delete.pop_back();
+ to_delete.pop_front();
}
_update_visibility();
@@ -785,6 +800,12 @@ void GridMap::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_collision_layer_bit", "bit", "value"), &GridMap::set_collision_layer_bit);
ClassDB::bind_method(D_METHOD("get_collision_layer_bit", "bit"), &GridMap::get_collision_layer_bit);
+ ClassDB::bind_method(D_METHOD("set_bake_navigation", "bake_navigation"), &GridMap::set_bake_navigation);
+ ClassDB::bind_method(D_METHOD("is_baking_navigation"), &GridMap::is_baking_navigation);
+
+ ClassDB::bind_method(D_METHOD("set_navigation_layers", "layers"), &GridMap::set_navigation_layers);
+ ClassDB::bind_method(D_METHOD("get_navigation_layers"), &GridMap::get_navigation_layers);
+
ClassDB::bind_method(D_METHOD("set_mesh_library", "mesh_library"), &GridMap::set_mesh_library);
ClassDB::bind_method(D_METHOD("get_mesh_library"), &GridMap::get_mesh_library);
@@ -838,6 +859,9 @@ void GridMap::_bind_methods() {
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");
+ ADD_GROUP("Navigation", "");
+ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "bake_navigation"), "set_bake_navigation", "is_baking_navigation");
+ ADD_PROPERTY(PropertyInfo(Variant::INT, "navigation_layers", PROPERTY_HINT_LAYERS_3D_NAVIGATION), "set_navigation_layers", "get_navigation_layers");
BIND_CONSTANT(INVALID_CELL_ITEM);
@@ -909,7 +933,7 @@ Array GridMap::get_meshes() {
Vector3 cellpos = Vector3(ik.x, ik.y, ik.z);
- Transform xform;
+ Transform3D xform;
xform.basis.set_orthogonal_index(E->get().rot);
@@ -963,7 +987,7 @@ void GridMap::make_baked_meshes(bool p_gen_lightmap_uv, float p_lightmap_uv_texe
Vector3 cellpos = Vector3(key.x, key.y, key.z);
Vector3 ofs = _get_offset();
- Transform xform;
+ Transform3D xform;
xform.basis.set_orthogonal_index(E->get().rot);
xform.set_origin(cellpos * cell_size + ofs);
@@ -988,7 +1012,7 @@ void GridMap::make_baked_meshes(bool p_gen_lightmap_uv, float p_lightmap_uv_texe
Ref<Material> surf_mat = mesh->surface_get_material(i);
if (!mat_map.has(surf_mat)) {
Ref<SurfaceTool> st;
- st.instance();
+ st.instantiate();
st->begin(Mesh::PRIMITIVE_TRIANGLES);
st->set_material(surf_mat);
mat_map[surf_mat] = st;
@@ -1000,7 +1024,7 @@ 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();
+ mesh.instantiate();
for (Map<Ref<Material>, Ref<SurfaceTool>>::Element *F = E->get().front(); F; F = F->next()) {
F->get()->commit(mesh);
}
@@ -1032,7 +1056,7 @@ Array GridMap::get_bake_meshes() {
Array arr;
for (int i = 0; i < baked_meshes.size(); i++) {
arr.push_back(baked_meshes[i].mesh);
- arr.push_back(Transform());
+ arr.push_back(Transform3D());
}
return arr;
diff --git a/modules/gridmap/grid_map.h b/modules/gridmap/grid_map.h
index e5ec4bb602..8cd82e1f4c 100644
--- a/modules/gridmap/grid_map.h
+++ b/modules/gridmap/grid_map.h
@@ -31,7 +31,6 @@
#ifndef GRID_MAP_H
#define GRID_MAP_H
-#include "scene/3d/navigation_3d.h"
#include "scene/3d/node_3d.h"
#include "scene/resources/mesh_library.h"
#include "scene/resources/multimesh.h"
@@ -90,7 +89,7 @@ class GridMap : public Node3D {
struct Octant {
struct NavMesh {
RID region;
- Transform xform;
+ Transform3D xform;
};
struct MultimeshInstance {
@@ -98,7 +97,7 @@ class GridMap : public Node3D {
RID multimesh;
struct Item {
int index = 0;
- Transform transform;
+ Transform3D transform;
IndexKey key;
};
@@ -135,8 +134,10 @@ class GridMap : public Node3D {
uint32_t collision_layer = 1;
uint32_t collision_mask = 1;
+ bool bake_navigation = false;
+ uint32_t navigation_layers = 1;
- Transform last_transform;
+ Transform3D last_transform;
bool _in_tree = false;
Vector3 cell_size = Vector3(2, 2, 2);
@@ -145,7 +146,6 @@ class GridMap : public Node3D {
bool center_y = true;
bool center_z = true;
float cell_scale = 1.0;
- Navigation3D *navigation = nullptr;
bool clip = false;
bool clip_above = true;
@@ -223,6 +223,12 @@ public:
void set_collision_mask_bit(int p_bit, bool p_value);
bool get_collision_mask_bit(int p_bit) const;
+ void set_bake_navigation(bool p_bake_navigation);
+ bool is_baking_navigation();
+
+ void set_navigation_layers(uint32_t p_layers);
+ uint32_t get_navigation_layers();
+
void set_mesh_library(const Ref<MeshLibrary> &p_mesh_library);
Ref<MeshLibrary> get_mesh_library() const;
diff --git a/modules/gridmap/grid_map_editor_plugin.cpp b/modules/gridmap/grid_map_editor_plugin.cpp
index da9cdb9bc5..046f8c0adb 100644
--- a/modules/gridmap/grid_map_editor_plugin.cpp
+++ b/modules/gridmap/grid_map_editor_plugin.cpp
@@ -62,12 +62,6 @@ void GridMapEditor::_menu_option(int p_option) {
floor->set_value(floor->get_value() + 1);
} 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);
-
- options->get_popup()->set_item_checked(index, lock_view);
- } break;
case MENU_OPTION_CLIP_DISABLED:
case MENU_OPTION_CLIP_ABOVE:
case MENU_OPTION_CLIP_BELOW: {
@@ -255,7 +249,7 @@ void GridMapEditor::_menu_option(int p_option) {
}
void GridMapEditor::_update_cursor_transform() {
- cursor_transform = Transform();
+ cursor_transform = Transform3D();
cursor_transform.origin = cursor_origin;
cursor_transform.basis.set_orthogonal_index(cursor_rot);
cursor_transform.basis *= node->get_cell_scale();
@@ -268,7 +262,7 @@ void GridMapEditor::_update_cursor_transform() {
}
void GridMapEditor::_update_selection_transform() {
- Transform xf_zero;
+ Transform3D xf_zero;
xf_zero.basis.set_zero();
if (!selection.active) {
@@ -279,7 +273,7 @@ void GridMapEditor::_update_selection_transform() {
return;
}
- Transform xf;
+ Transform3D xf;
xf.scale((Vector3(1, 1, 1) + (selection.end - selection.begin)) * node->get_cell_size());
xf.origin = selection.begin * node->get_cell_size();
@@ -297,7 +291,7 @@ void GridMapEditor::_update_selection_transform() {
scale *= node->get_cell_size();
position *= node->get_cell_size();
- Transform xf2;
+ Transform3D xf2;
xf2.basis.scale(scale);
xf2.origin = position;
@@ -362,7 +356,7 @@ bool GridMapEditor::do_input_action(Camera3D *p_camera, const Point2 &p_point, b
Camera3D *camera = p_camera;
Vector3 from = camera->project_ray_origin(p_point);
Vector3 normal = camera->project_ray_normal(p_point);
- Transform local_xform = node->get_global_transform().affine_inverse();
+ Transform3D local_xform = node->get_global_transform().affine_inverse();
Vector<Plane> planes = camera->get_frustum();
from = local_xform.xform(from);
normal = local_xform.basis.xform(normal).normalized();
@@ -386,13 +380,13 @@ bool GridMapEditor::do_input_action(Camera3D *p_camera, const Point2 &p_point, b
}
int cell[3];
- float cell_size[3] = { node->get_cell_size().x, node->get_cell_size().y, node->get_cell_size().z };
+ Vector3 cell_size = node->get_cell_size();
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];
+ cell[i] = inters[i] / cell_size[i];
if (inters[i] < 0) {
cell[i] -= 1; // Compensate negative.
}
@@ -436,6 +430,7 @@ bool GridMapEditor::do_input_action(Camera3D *p_camera, const Point2 &p_point, b
}
return true;
}
+
if (input_action == INPUT_PAINT) {
SetItem si;
si.position = Vector3i(cell[0], cell[1], cell[2]);
@@ -539,15 +534,15 @@ void GridMapEditor::_set_clipboard_data() {
void GridMapEditor::_update_paste_indicator() {
if (input_action != INPUT_PASTE) {
- Transform xf;
+ Transform3D xf;
xf.basis.set_zero();
RenderingServer::get_singleton()->instance_set_transform(paste_instance, xf);
return;
}
- Vector3 center = 0.5 * Vector3(float(node->get_center_x()), float(node->get_center_y()), float(node->get_center_z()));
+ Vector3 center = 0.5 * Vector3(real_t(node->get_center_x()), real_t(node->get_center_y()), real_t(node->get_center_z()));
Vector3 scale = (Vector3(1, 1, 1) + (paste_indicator.end - paste_indicator.begin)) * node->get_cell_size();
- Transform xf;
+ Transform3D xf;
xf.scale(scale);
xf.origin = (paste_indicator.begin + (paste_indicator.current - paste_indicator.click) + center) * node->get_cell_size();
Basis rot;
@@ -560,7 +555,7 @@ void GridMapEditor::_update_paste_indicator() {
for (List<ClipboardItem>::Element *E = clipboard_items.front(); E; E = E->next()) {
ClipboardItem &item = E->get();
- xf = Transform();
+ xf = Transform3D();
xf.origin = (paste_indicator.begin + (paste_indicator.current - paste_indicator.click) + center) * node->get_cell_size();
xf.basis = rot * xf.basis;
xf.translate(item.grid_offset * node->get_cell_size());
@@ -614,13 +609,13 @@ 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->get_button_index() == MOUSE_BUTTON_WHEEL_UP && (mb->is_command_pressed() || mb->is_shift_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())) {
+ } else if (mb->get_button_index() == MOUSE_BUTTON_WHEEL_DOWN && (mb->is_command_pressed() || mb->is_shift_pressed())) {
if (mb->is_pressed()) {
floor->set_value(floor->get_value() - mb->get_factor());
}
@@ -629,24 +624,24 @@ bool GridMapEditor::forward_spatial_input_event(Camera3D *p_camera, const Ref<In
if (mb->is_pressed()) {
Node3DEditorViewport::NavigationScheme nav_scheme = (Node3DEditorViewport::NavigationScheme)EditorSettings::get_singleton()->get("editors/3d/navigation/navigation_scheme").operator int();
- if ((nav_scheme == Node3DEditorViewport::NAVIGATION_MAYA || nav_scheme == Node3DEditorViewport::NAVIGATION_MODO) && mb->get_alt()) {
+ if ((nav_scheme == Node3DEditorViewport::NAVIGATION_MAYA || nav_scheme == Node3DEditorViewport::NAVIGATION_MODO) && mb->is_alt_pressed()) {
input_action = INPUT_NONE;
- } else if (mb->get_button_index() == BUTTON_LEFT) {
+ } else if (mb->get_button_index() == MOUSE_BUTTON_LEFT) {
bool can_edit = (node && node->get_mesh_library().is_valid());
if (input_action == INPUT_PASTE) {
_do_paste();
input_action = INPUT_NONE;
_update_paste_indicator();
- } else if (mb->get_shift() && can_edit) {
+ } else if (mb->is_shift_pressed() && can_edit) {
input_action = INPUT_SELECT;
last_selection = selection;
- } else if (mb->get_command() && can_edit) {
+ } else if (mb->is_command_pressed() && can_edit) {
input_action = INPUT_PICK;
} else {
input_action = INPUT_PAINT;
set_items.clear();
}
- } else if (mb->get_button_index() == BUTTON_RIGHT) {
+ } else if (mb->get_button_index() == MOUSE_BUTTON_RIGHT) {
if (input_action == INPUT_PASTE) {
_clear_clipboard_data();
input_action = INPUT_NONE;
@@ -665,7 +660,7 @@ 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 ((mb->get_button_index() == MOUSE_BUTTON_RIGHT && input_action == INPUT_ERASE) || (mb->get_button_index() == MOUSE_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()) {
@@ -684,19 +679,19 @@ bool GridMapEditor::forward_spatial_input_event(Camera3D *p_camera, const Ref<In
return set_items.size() > 0;
}
- if (mb->get_button_index() == BUTTON_LEFT && input_action == INPUT_SELECT) {
+ if (mb->get_button_index() == MOUSE_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);
undo_redo->commit_action();
}
- if (mb->get_button_index() == BUTTON_LEFT && input_action != INPUT_NONE) {
+ if (mb->get_button_index() == MOUSE_BUTTON_LEFT && input_action != INPUT_NONE) {
set_items.clear();
input_action = INPUT_NONE;
return true;
}
- if (mb->get_button_index() == BUTTON_RIGHT && (input_action == INPUT_ERASE || input_action == INPUT_PASTE)) {
+ if (mb->get_button_index() == MOUSE_BUTTON_RIGHT && (input_action == INPUT_ERASE || input_action == INPUT_PASTE)) {
input_action = INPUT_NONE;
return true;
}
@@ -731,7 +726,7 @@ bool GridMapEditor::forward_spatial_input_event(Camera3D *p_camera, const Ref<In
}
}
- if (k->get_shift() && selection.active && input_action != INPUT_PASTE) {
+ if (k->is_shift_pressed() && 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();
@@ -748,7 +743,7 @@ 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())) {
+ if (pan_gesture->is_alt_pressed() && (pan_gesture->is_command_pressed() || pan_gesture->is_shift_pressed())) {
const real_t delta = pan_gesture->get_delta().y * 0.5;
accumulated_floor_delta += delta;
int step = 0;
@@ -809,12 +804,12 @@ 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) {
+ if (mb.is_valid() && mb->is_pressed() && mb->is_command_pressed()) {
+ if (mb->is_pressed() && mb->get_button_index() == MOUSE_BUTTON_WHEEL_UP) {
size_slider->set_value(size_slider->get_value() + 0.2);
}
- if (mb->is_pressed() && mb->get_button_index() == BUTTON_WHEEL_DOWN) {
+ if (mb->is_pressed() && mb->get_button_index() == MOUSE_BUTTON_WHEEL_DOWN) {
size_slider->set_value(size_slider->get_value() - 0.2);
}
}
@@ -1067,7 +1062,7 @@ void GridMapEditor::_notification(int p_what) {
return;
}
- Transform xf = node->get_global_transform();
+ Transform3D xf = node->get_global_transform();
if (xf != grid_xform) {
for (int i = 0; i < 3; i++) {
@@ -1079,25 +1074,21 @@ void GridMapEditor::_notification(int p_what) {
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;
- p.normal[edit_axis] = 1.0;
- p.d = edit_floor[edit_axis] * node->get_cell_size()[edit_axis];
- p = node->get_transform().xform(p); // plane to snap
-
- Node3DEditorPlugin *sep = Object::cast_to<Node3DEditorPlugin>(editor->get_editor_plugin_screen());
- if (sep) {
- sep->snap_cursor_to_plane(p);
- }
- }
} break;
case NOTIFICATION_THEME_CHANGED: {
- options->set_icon(get_theme_icon("GridMap", "EditorIcons"));
- search_box->set_right_icon(get_theme_icon("Search", "EditorIcons"));
+ options->set_icon(get_theme_icon(SNAME("GridMap"), SNAME("EditorIcons")));
+ search_box->set_right_icon(get_theme_icon(SNAME("Search"), SNAME("EditorIcons")));
+ } break;
+
+ case NOTIFICATION_APPLICATION_FOCUS_OUT: {
+ if (input_action == INPUT_PAINT) {
+ // Simulate mouse released event to stop drawing when editor focus exists.
+ Ref<InputEventMouseButton> release;
+ release.instantiate();
+ release->set_button_index(MOUSE_BUTTON_LEFT);
+ forward_spatial_input_event(nullptr, release);
+ }
} break;
}
}
@@ -1186,8 +1177,6 @@ GridMapEditor::GridMapEditor(EditorNode *p_editor) {
spatial_editor_hb->hide();
options->set_text(TTR("Grid Map"));
- options->get_popup()->add_check_item(TTR("Snap View"), MENU_OPTION_LOCK_VIEW);
- options->get_popup()->add_separator();
options->get_popup()->add_item(TTR("Previous Floor"), MENU_OPTION_PREV_LEVEL, KEY_Q);
options->get_popup()->add_item(TTR("Next Floor"), MENU_OPTION_NEXT_LEVEL, KEY_E);
options->get_popup()->add_separator();
@@ -1250,7 +1239,7 @@ GridMapEditor::GridMapEditor(EditorNode *p_editor) {
mode_thumbnail->set_flat(true);
mode_thumbnail->set_toggle_mode(true);
mode_thumbnail->set_pressed(true);
- mode_thumbnail->set_icon(p_editor->get_gui_base()->get_theme_icon("FileThumbnail", "EditorIcons"));
+ mode_thumbnail->set_icon(p_editor->get_gui_base()->get_theme_icon(SNAME("FileThumbnail"), SNAME("EditorIcons")));
hb->add_child(mode_thumbnail);
mode_thumbnail->connect("pressed", callable_mp(this, &GridMapEditor::_set_display_mode), varray(DISPLAY_THUMBNAIL));
@@ -1258,7 +1247,7 @@ GridMapEditor::GridMapEditor(EditorNode *p_editor) {
mode_list->set_flat(true);
mode_list->set_toggle_mode(true);
mode_list->set_pressed(false);
- mode_list->set_icon(p_editor->get_gui_base()->get_theme_icon("FileList", "EditorIcons"));
+ mode_list->set_icon(p_editor->get_gui_base()->get_theme_icon(SNAME("FileList"), SNAME("EditorIcons")));
hb->add_child(mode_list);
mode_list->connect("pressed", callable_mp(this, &GridMapEditor::_set_display_mode), varray(DISPLAY_LIST));
@@ -1282,7 +1271,7 @@ GridMapEditor::GridMapEditor(EditorNode *p_editor) {
info_message->set_text(TTR("Give a MeshLibrary resource to this GridMap to use its meshes."));
info_message->set_valign(Label::VALIGN_CENTER);
info_message->set_align(Label::ALIGN_CENTER);
- info_message->set_autowrap(true);
+ info_message->set_autowrap_mode(Label::AUTOWRAP_WORD_SMART);
info_message->set_custom_minimum_size(Size2(100 * EDSCALE, 0));
info_message->set_anchors_and_offsets_preset(PRESET_WIDE, PRESET_MODE_KEEP_SIZE, 8 * EDSCALE);
mesh_library_palette->add_child(info_message);
@@ -1367,7 +1356,7 @@ GridMapEditor::GridMapEditor(EditorNode *p_editor) {
Array d;
d.resize(RS::ARRAY_MAX);
- inner_mat.instance();
+ inner_mat.instantiate();
inner_mat->set_albedo(Color(0.7, 0.7, 1.0, 0.2));
inner_mat->set_shading_mode(StandardMaterial3D::SHADING_MODE_UNSHADED);
inner_mat->set_transparency(StandardMaterial3D::TRANSPARENCY_ALPHA);
@@ -1376,14 +1365,14 @@ GridMapEditor::GridMapEditor(EditorNode *p_editor) {
RenderingServer::get_singleton()->mesh_add_surface_from_arrays(selection_mesh, RS::PRIMITIVE_TRIANGLES, d);
RenderingServer::get_singleton()->mesh_surface_set_material(selection_mesh, 0, inner_mat->get_rid());
- outer_mat.instance();
+ outer_mat.instantiate();
outer_mat->set_albedo(Color(0.7, 0.7, 1.0, 0.8));
outer_mat->set_on_top_of_alpha();
outer_mat->set_shading_mode(StandardMaterial3D::SHADING_MODE_UNSHADED);
outer_mat->set_transparency(StandardMaterial3D::TRANSPARENCY_ALPHA);
- selection_floor_mat.instance();
+ selection_floor_mat.instantiate();
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_shading_mode(StandardMaterial3D::SHADING_MODE_UNSHADED);
@@ -1410,7 +1399,7 @@ GridMapEditor::GridMapEditor(EditorNode *p_editor) {
_set_selection(false);
- indicator_mat.instance();
+ indicator_mat.instantiate();
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);
diff --git a/modules/gridmap/grid_map_editor_plugin.h b/modules/gridmap/grid_map_editor_plugin.h
index 6c7f0bedf6..4bc849e071 100644
--- a/modules/gridmap/grid_map_editor_plugin.h
+++ b/modules/gridmap/grid_map_editor_plugin.h
@@ -94,9 +94,8 @@ class GridMapEditor : public VBoxContainer {
MeshLibrary *last_mesh_library;
ClipMode clip_mode = CLIP_DISABLED;
- bool lock_view = false;
- Transform grid_xform;
- Transform edit_grid_xform;
+ Transform3D grid_xform;
+ Transform3D edit_grid_xform;
Vector3::Axis edit_axis;
int edit_floor[3];
Vector3 grid_ofs;
@@ -146,7 +145,7 @@ class GridMapEditor : public VBoxContainer {
PasteIndicator paste_indicator;
bool cursor_visible = false;
- Transform cursor_transform;
+ Transform3D cursor_transform;
Vector3 cursor_origin;
diff --git a/modules/gridmap/icons/GridMap.svg b/modules/gridmap/icons/GridMap.svg
index 7a36fd888c..e208257855 100644
--- a/modules/gridmap/icons/GridMap.svg
+++ b/modules/gridmap/icons/GridMap.svg
@@ -1 +1 @@
-<svg height="16" viewBox="0 0 16 16" width="16" xmlns="http://www.w3.org/2000/svg"><path d="m8 1-6 3v8l6 3 6-3v-2l-2-1-4 2-2-1v-4l2-1v-2l2-1zm4 2-2 1v2l2 1 2-1v-2z" fill="#fc9c9c" fill-opacity=".99608"/></svg>
+<svg height="16" viewBox="0 0 16 16" width="16" xmlns="http://www.w3.org/2000/svg"><path d="m8 1-6 3v8l6 3 6-3v-2l-2-1-4 2-2-1v-4l2-1v-2l2-1zm4 2-2 1v2l2 1 2-1v-2z" fill="#fc7f7f" fill-opacity=".99608"/></svg>
diff --git a/modules/gridmap/register_types.cpp b/modules/gridmap/register_types.cpp
index 5680664213..85739d202e 100644
--- a/modules/gridmap/register_types.cpp
+++ b/modules/gridmap/register_types.cpp
@@ -37,7 +37,7 @@
void register_gridmap_types() {
#ifndef _3D_DISABLED
- ClassDB::register_class<GridMap>();
+ GDREGISTER_CLASS(GridMap);
#ifdef TOOLS_ENABLED
EditorPlugins::add_by_type<GridMapEditorPlugin>();
#endif