diff options
Diffstat (limited to 'modules/gridmap')
-rw-r--r-- | modules/gridmap/doc_classes/GridMap.xml | 119 | ||||
-rw-r--r-- | modules/gridmap/grid_map.cpp | 61 | ||||
-rw-r--r-- | modules/gridmap/grid_map.h | 3 | ||||
-rw-r--r-- | modules/gridmap/grid_map_editor_plugin.cpp | 60 | ||||
-rw-r--r-- | modules/gridmap/grid_map_editor_plugin.h | 3 | ||||
-rw-r--r-- | modules/gridmap/register_types.cpp | 1 | ||||
-rw-r--r-- | modules/gridmap/register_types.h | 1 |
7 files changed, 87 insertions, 161 deletions
diff --git a/modules/gridmap/doc_classes/GridMap.xml b/modules/gridmap/doc_classes/GridMap.xml index c30c6d77b9..bb652f3bdf 100644 --- a/modules/gridmap/doc_classes/GridMap.xml +++ b/modules/gridmap/doc_classes/GridMap.xml @@ -1,5 +1,5 @@ <?xml version="1.0" encoding="UTF-8" ?> -<class name="GridMap" inherits="Spatial" category="Core" version="3.0-beta"> +<class name="GridMap" inherits="Spatial" category="Core" version="3.1"> <brief_description> Node for 3D tile-based maps. </brief_description> @@ -10,6 +10,7 @@ A GridMap is split into a sparse collection of octants for efficient rendering and physics processing. Every octant has the same dimensions and can contain several cells. </description> <tutorials> + http://docs.godotengine.org/en/3.0/tutorials/3d/using_gridmaps.html </tutorials> <demos> </demos> @@ -67,34 +68,6 @@ The orientation of the cell at the grid-based X, Y and Z coordinates. -1 is retuned if the cell is empty. </description> </method> - <method name="get_cell_size" qualifiers="const"> - <return type="Vector3"> - </return> - <description> - The dimensions of the grid's cells. - </description> - </method> - <method name="get_center_x" qualifiers="const"> - <return type="bool"> - </return> - <description> - Returns whether or not grid items are centered on the X axis. - </description> - </method> - <method name="get_center_y" qualifiers="const"> - <return type="bool"> - </return> - <description> - Returns whether or not grid items are centered on the Y axis. - </description> - </method> - <method name="get_center_z" qualifiers="const"> - <return type="bool"> - </return> - <description> - Returns whether or not grid items are centered on the Z axis. - </description> - </method> <method name="get_collision_layer_bit" qualifiers="const"> <return type="bool"> </return> @@ -118,20 +91,6 @@ Array of [Transform] and [Mesh] references corresponding to the non empty cells in the grid. The transforms are specified in world space. </description> </method> - <method name="get_octant_size" qualifiers="const"> - <return type="int"> - </return> - <description> - The size of each octant measured in number of cells. This applies to all three axis. - </description> - </method> - <method name="get_theme" qualifiers="const"> - <return type="MeshLibrary"> - </return> - <description> - The assigned [MeshLibrary]. - </description> - </method> <method name="get_used_cells" qualifiers="const"> <return type="Array"> </return> @@ -188,42 +147,6 @@ Optionally, the item's orientation can be passed. </description> </method> - <method name="set_cell_size"> - <return type="void"> - </return> - <argument index="0" name="size" type="Vector3"> - </argument> - <description> - Sets the height, width and depth of the grid's cells. - </description> - </method> - <method name="set_center_x"> - <return type="void"> - </return> - <argument index="0" name="enable" type="bool"> - </argument> - <description> - Set grid items to be centered on the X axis. By default it is enabled. - </description> - </method> - <method name="set_center_y"> - <return type="void"> - </return> - <argument index="0" name="enable" type="bool"> - </argument> - <description> - Set grid items to be centered on the Y axis. By default it is enabled. - </description> - </method> - <method name="set_center_z"> - <return type="void"> - </return> - <argument index="0" name="enable" type="bool"> - </argument> - <description> - Set grid items to be centered on the Z axis. By default it is enabled. - </description> - </method> <method name="set_clip"> <return type="void"> </return> @@ -258,24 +181,6 @@ <description> </description> </method> - <method name="set_octant_size"> - <return type="void"> - </return> - <argument index="0" name="size" type="int"> - </argument> - <description> - Sets the size for each octant measured in number of cells. This applies to all three axis. - </description> - </method> - <method name="set_theme"> - <return type="void"> - </return> - <argument index="0" name="theme" type="MeshLibrary"> - </argument> - <description> - Sets the collection of meshes for the map. - </description> - </method> <method name="world_to_map" qualifiers="const"> <return type="Vector3"> </return> @@ -286,10 +191,30 @@ </method> </methods> <members> + <member name="cell_center_x" type="bool" setter="set_center_x" getter="get_center_x"> + If [code]true[/code] grid items are centered on the X axis. + </member> + <member name="cell_center_y" type="bool" setter="set_center_y" getter="get_center_y"> + If [code]true[/code] grid items are centered on the Y axis. + </member> + <member name="cell_center_z" type="bool" setter="set_center_z" getter="get_center_z"> + If [code]true[/code] grid items are centered on the Z axis. + </member> + <member name="cell_octant_size" type="int" setter="set_octant_size" getter="get_octant_size"> + The size of each octant measured in number of cells. This applies to all three axis. + </member> + <member name="cell_scale" type="float" setter="set_cell_scale" getter="get_cell_scale"> + </member> + <member name="cell_size" type="Vector3" setter="set_cell_size" getter="get_cell_size"> + The dimensions of the grid's cells. + </member> <member name="collision_layer" type="int" setter="set_collision_layer" getter="get_collision_layer"> </member> <member name="collision_mask" type="int" setter="set_collision_mask" getter="get_collision_mask"> </member> + <member name="theme" type="MeshLibrary" setter="set_theme" getter="get_theme"> + The assigned [MeshLibrary]. + </member> </members> <constants> <constant name="INVALID_CELL_ITEM" value="-1"> diff --git a/modules/gridmap/grid_map.cpp b/modules/gridmap/grid_map.cpp index 9a03bc410a..234a59e516 100644 --- a/modules/gridmap/grid_map.cpp +++ b/modules/gridmap/grid_map.cpp @@ -27,6 +27,7 @@ /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ + #include "grid_map.h" #include "message_queue.h" #include "scene/3d/light.h" @@ -42,28 +43,7 @@ bool GridMap::_set(const StringName &p_name, const Variant &p_value) { String name = p_name; - if (name == "theme") { - - set_theme(p_value); - } else if (name == "cell_size") { - if (p_value.get_type() == Variant::INT || p_value.get_type() == Variant::REAL) { - //compatibility - float cs = p_value; - set_cell_size(Vector3(cs, cs, cs)); - } else { - set_cell_size(p_value); - } - } else if (name == "cell_octant_size") { - set_octant_size(p_value); - } else if (name == "cell_center_x") { - set_center_x(p_value); - } else if (name == "cell_center_y") { - set_center_y(p_value); - } else if (name == "cell_center_z") { - set_center_z(p_value); - } else if (name == "cell_scale") { - set_cell_scale(p_value); - /* } else if (name=="cells") { + /* } else if (name=="cells") { PoolVector<int> cells = p_value; int amount=cells.size(); PoolVector<int>::Read r = cells.read(); @@ -80,7 +60,7 @@ bool GridMap::_set(const StringName &p_name, const Variant &p_value) { } _recreate_octant_data();*/ - } else if (name == "data") { + if (name == "data") { Dictionary d = p_value; @@ -133,21 +113,7 @@ bool GridMap::_get(const StringName &p_name, Variant &r_ret) const { String name = p_name; - if (name == "theme") { - r_ret = get_theme(); - } else if (name == "cell_size") { - r_ret = get_cell_size(); - } else if (name == "cell_octant_size") { - r_ret = get_octant_size(); - } else if (name == "cell_center_x") { - r_ret = get_center_x(); - } else if (name == "cell_center_y") { - r_ret = get_center_y(); - } else if (name == "cell_center_z") { - r_ret = get_center_z(); - } else if (name == "cell_scale") { - r_ret = cell_scale; - } else if (name == "data") { + if (name == "data") { Dictionary d; @@ -183,14 +149,6 @@ bool GridMap::_get(const StringName &p_name, Variant &r_ret) const { void GridMap::_get_property_list(List<PropertyInfo> *p_list) const { - p_list->push_back(PropertyInfo(Variant::OBJECT, "theme", PROPERTY_HINT_RESOURCE_TYPE, "MeshLibrary")); - p_list->push_back(PropertyInfo(Variant::NIL, "Cell", PROPERTY_HINT_NONE, "cell_", PROPERTY_USAGE_GROUP)); - p_list->push_back(PropertyInfo(Variant::VECTOR3, "cell_size")); - p_list->push_back(PropertyInfo(Variant::INT, "cell_octant_size", PROPERTY_HINT_RANGE, "1,1024,1")); - p_list->push_back(PropertyInfo(Variant::BOOL, "cell_center_x")); - p_list->push_back(PropertyInfo(Variant::BOOL, "cell_center_y")); - p_list->push_back(PropertyInfo(Variant::BOOL, "cell_center_z")); - p_list->push_back(PropertyInfo(Variant::REAL, "cell_scale")); if (baked_meshes.size()) { p_list->push_back(PropertyInfo(Variant::ARRAY, "baked_meshes", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_STORAGE)); } @@ -894,6 +852,9 @@ void GridMap::_bind_methods() { ClassDB::bind_method(D_METHOD("set_cell_size", "size"), &GridMap::set_cell_size); ClassDB::bind_method(D_METHOD("get_cell_size"), &GridMap::get_cell_size); + ClassDB::bind_method(D_METHOD("set_cell_scale", "scale"), &GridMap::set_cell_scale); + ClassDB::bind_method(D_METHOD("get_cell_scale"), &GridMap::get_cell_scale); + ClassDB::bind_method(D_METHOD("set_octant_size", "size"), &GridMap::set_octant_size); ClassDB::bind_method(D_METHOD("get_octant_size"), &GridMap::get_octant_size); @@ -928,6 +889,14 @@ void GridMap::_bind_methods() { ClassDB::bind_method(D_METHOD("clear_baked_meshes"), &GridMap::clear_baked_meshes); ClassDB::bind_method(D_METHOD("make_baked_meshes", "gen_lightmap_uv", "lightmap_uv_texel_size"), &GridMap::make_baked_meshes, DEFVAL(false), DEFVAL(0.1)); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "theme", PROPERTY_HINT_RESOURCE_TYPE, "MeshLibrary"), "set_theme", "get_theme"); + ADD_GROUP("Cell", "cell_"); + ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "cell_size"), "set_cell_size", "get_cell_size"); + ADD_PROPERTY(PropertyInfo(Variant::INT, "cell_octant_size", PROPERTY_HINT_RANGE, "1,1024,1"), "set_octant_size", "get_octant_size"); + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "cell_center_x"), "set_center_x", "get_center_x"); + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "cell_center_y"), "set_center_y", "get_center_y"); + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "cell_center_z"), "set_center_z", "get_center_z"); + ADD_PROPERTY(PropertyInfo(Variant::REAL, "cell_scale"), "set_cell_scale", "get_cell_scale"); ADD_GROUP("Collision", "collision_"); ADD_PROPERTY(PropertyInfo(Variant::INT, "collision_layer", PROPERTY_HINT_LAYERS_3D_PHYSICS), "set_collision_layer", "get_collision_layer"); ADD_PROPERTY(PropertyInfo(Variant::INT, "collision_mask", PROPERTY_HINT_LAYERS_3D_PHYSICS), "set_collision_mask", "get_collision_mask"); diff --git a/modules/gridmap/grid_map.h b/modules/gridmap/grid_map.h index 7b97fe3183..ed36751fc8 100644 --- a/modules/gridmap/grid_map.h +++ b/modules/gridmap/grid_map.h @@ -27,6 +27,7 @@ /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ + #ifndef GRID_MAP_H #define GRID_MAP_H @@ -246,7 +247,7 @@ public: int get_cell_item(int p_x, int p_y, int p_z) const; int get_cell_item_orientation(int p_x, int p_y, int p_z) const; - Vector3 world_to_map(const Vector3 &p_pos) const; + Vector3 world_to_map(const Vector3 &p_world_pos) const; Vector3 map_to_world(int p_x, int p_y, int p_z) const; void set_clip(bool p_enabled, bool p_clip_above = true, int p_floor = 0, Vector3::Axis p_axis = Vector3::AXIS_X); diff --git a/modules/gridmap/grid_map_editor_plugin.cpp b/modules/gridmap/grid_map_editor_plugin.cpp index dc7dbb0b0d..4b96824dca 100644 --- a/modules/gridmap/grid_map_editor_plugin.cpp +++ b/modules/gridmap/grid_map_editor_plugin.cpp @@ -27,6 +27,7 @@ /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ + #include "grid_map_editor_plugin.h" #include "editor/editor_scale.h" #include "editor/editor_settings.h" @@ -98,6 +99,20 @@ void GridMapEditor::_menu_option(int p_option) { int idx = options->get_popup()->get_item_index(MENU_OPTION_X_AXIS + i); options->get_popup()->set_item_checked(idx, i == new_axis); } + + if (edit_axis != new_axis) { + int item1 = options->get_popup()->get_item_index(MENU_OPTION_NEXT_LEVEL); + int item2 = options->get_popup()->get_item_index(MENU_OPTION_PREV_LEVEL); + if (edit_axis == Vector3::AXIS_Y) { + options->get_popup()->set_item_text(item1, TTR("Next Plane")); + options->get_popup()->set_item_text(item2, TTR("Previous Plane")); + spin_box_label->set_text(TTR("Plane:")); + } else if (new_axis == Vector3::AXIS_Y) { + options->get_popup()->set_item_text(item1, TTR("Next Floor")); + options->get_popup()->set_item_text(item2, TTR("Previous Floor")); + spin_box_label->set_text(TTR("Floor:")); + } + } edit_axis = Vector3::Axis(new_axis); update_grid(); _update_clip(); @@ -626,12 +641,21 @@ bool GridMapEditor::forward_spatial_input_event(Camera *p_camera, const Ref<Inpu Ref<InputEventPanGesture> pan_gesture = p_event; if (pan_gesture.is_valid()) { - if (pan_gesture->get_command() || pan_gesture->get_shift()) { - const real_t delta = pan_gesture->get_delta().y; - floor->set_value(floor->get_value() + SGN(delta)); + 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; + int step = 0; + if (ABS(accumulated_floor_delta) > 1.0) { + step = SGN(accumulated_floor_delta); + accumulated_floor_delta -= step; + } + if (step) { + floor->set_value(floor->get_value() + step); + } return true; } } + accumulated_floor_delta = 0.0; return false; } @@ -755,7 +779,7 @@ void GridMapEditor::edit(GridMap *p_gridmap) { set_process(true); - Vector3 edited_floor = p_gridmap->get_meta("_editor_floor_"); + Vector3 edited_floor = p_gridmap->has_meta("_editor_floor_") ? p_gridmap->get_meta("_editor_floor_") : Variant(); clip_mode = p_gridmap->has_meta("_editor_clip_") ? ClipMode(p_gridmap->get_meta("_editor_clip_").operator int()) : CLIP_DISABLED; for (int i = 0; i < 3; i++) { @@ -997,9 +1021,9 @@ GridMapEditor::GridMapEditor(EditorNode *p_editor) { spatial_editor_hb->set_alignment(BoxContainer::ALIGN_END); SpatialEditor::get_singleton()->add_control_to_menu_panel(spatial_editor_hb); - Label *fl = memnew(Label); - fl->set_text(TTR("Floor:")); - spatial_editor_hb->add_child(fl); + spin_box_label = memnew(Label); + spin_box_label->set_text(TTR("Floor:")); + spatial_editor_hb->add_child(spin_box_label); floor = memnew(SpinBox); floor->set_min(-32767); @@ -1022,14 +1046,14 @@ GridMapEditor::GridMapEditor(EditorNode *p_editor) { 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(); - options->get_popup()->add_check_item(TTR("Clip Disabled"), MENU_OPTION_CLIP_DISABLED); + options->get_popup()->add_radio_check_item(TTR("Clip Disabled"), MENU_OPTION_CLIP_DISABLED); options->get_popup()->set_item_checked(options->get_popup()->get_item_index(MENU_OPTION_CLIP_DISABLED), true); - options->get_popup()->add_check_item(TTR("Clip Above"), MENU_OPTION_CLIP_ABOVE); - options->get_popup()->add_check_item(TTR("Clip Below"), MENU_OPTION_CLIP_BELOW); + options->get_popup()->add_radio_check_item(TTR("Clip Above"), MENU_OPTION_CLIP_ABOVE); + options->get_popup()->add_radio_check_item(TTR("Clip Below"), MENU_OPTION_CLIP_BELOW); options->get_popup()->add_separator(); - options->get_popup()->add_check_item(TTR("Edit X Axis"), MENU_OPTION_X_AXIS, KEY_Z); - options->get_popup()->add_check_item(TTR("Edit Y Axis"), MENU_OPTION_Y_AXIS, KEY_X); - options->get_popup()->add_check_item(TTR("Edit Z Axis"), MENU_OPTION_Z_AXIS, KEY_C); + options->get_popup()->add_radio_check_item(TTR("Edit X Axis"), MENU_OPTION_X_AXIS, KEY_Z); + options->get_popup()->add_radio_check_item(TTR("Edit Y Axis"), MENU_OPTION_Y_AXIS, KEY_X); + options->get_popup()->add_radio_check_item(TTR("Edit Z Axis"), MENU_OPTION_Z_AXIS, KEY_C); options->get_popup()->set_item_checked(options->get_popup()->get_item_index(MENU_OPTION_Y_AXIS), true); options->get_popup()->add_separator(); options->get_popup()->add_item(TTR("Cursor Rotate X"), MENU_OPTION_CURSOR_ROTATE_X, KEY_A); @@ -1130,9 +1154,9 @@ GridMapEditor::GridMapEditor(EditorNode *p_editor) { for (int k = 0; k < 3; k++) { if (i < 3) - face_points[j][(i + k) % 3] = v[k] * (i >= 3 ? -1 : 1); + face_points[j][(i + k) % 3] = v[k]; else - face_points[3 - j][(i + k) % 3] = v[k] * (i >= 3 ? -1 : 1); + face_points[3 - j][(i + k) % 3] = -v[k]; } } @@ -1232,6 +1256,7 @@ GridMapEditor::GridMapEditor(EditorNode *p_editor) { selection.active = false; updating = false; + accumulated_floor_delta = 0.0; } GridMapEditor::~GridMapEditor() { @@ -1244,9 +1269,10 @@ GridMapEditor::~GridMapEditor() { VisualServer::get_singleton()->free(grid_instance[i]); if (cursor_instance.is_valid()) VisualServer::get_singleton()->free(cursor_instance); - if (selection_level_instance[i].is_valid()) { + if (selection_level_instance[i].is_valid()) VisualServer::get_singleton()->free(selection_level_instance[i]); - } + if (selection_level_mesh[i].is_valid()) + VisualServer::get_singleton()->free(selection_level_mesh[i]); } VisualServer::get_singleton()->free(selection_mesh); diff --git a/modules/gridmap/grid_map_editor_plugin.h b/modules/gridmap/grid_map_editor_plugin.h index a49b44e7a2..f79d9aefa0 100644 --- a/modules/gridmap/grid_map_editor_plugin.h +++ b/modules/gridmap/grid_map_editor_plugin.h @@ -27,6 +27,7 @@ /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ + #ifndef GRID_MAP_EDITOR_PLUGIN_H #define GRID_MAP_EDITOR_PLUGIN_H @@ -75,12 +76,14 @@ class GridMapEditor : public VBoxContainer { Panel *panel; MenuButton *options; SpinBox *floor; + double accumulated_floor_delta; ToolButton *mode_thumbnail; ToolButton *mode_list; HBoxContainer *spatial_editor_hb; ConfirmationDialog *settings_dialog; VBoxContainer *settings_vbc; SpinBox *settings_pick_distance; + Label *spin_box_label; struct SetItem { diff --git a/modules/gridmap/register_types.cpp b/modules/gridmap/register_types.cpp index 23a8d16497..a3ceea10af 100644 --- a/modules/gridmap/register_types.cpp +++ b/modules/gridmap/register_types.cpp @@ -27,6 +27,7 @@ /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ + #include "register_types.h" #ifndef _3D_DISABLED #include "class_db.h" diff --git a/modules/gridmap/register_types.h b/modules/gridmap/register_types.h index 0e19f1ce8d..4ff107bec8 100644 --- a/modules/gridmap/register_types.h +++ b/modules/gridmap/register_types.h @@ -27,5 +27,6 @@ /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ + void register_gridmap_types(); void unregister_gridmap_types(); |