diff options
Diffstat (limited to 'editor/plugins')
-rw-r--r-- | editor/plugins/animation_tree_editor_plugin.cpp | 6 | ||||
-rw-r--r-- | editor/plugins/canvas_item_editor_plugin.cpp | 15 | ||||
-rw-r--r-- | editor/plugins/navigation_mesh_editor_plugin.cpp | 165 | ||||
-rw-r--r-- | editor/plugins/navigation_mesh_editor_plugin.h | 86 | ||||
-rw-r--r-- | editor/plugins/navigation_mesh_generator.cpp | 311 | ||||
-rw-r--r-- | editor/plugins/navigation_mesh_generator.h | 65 | ||||
-rw-r--r-- | editor/plugins/script_editor_plugin.cpp | 73 | ||||
-rw-r--r-- | editor/plugins/script_editor_plugin.h | 6 | ||||
-rw-r--r-- | editor/plugins/script_text_editor.cpp | 21 | ||||
-rw-r--r-- | editor/plugins/spatial_editor_plugin.cpp | 73 |
10 files changed, 790 insertions, 31 deletions
diff --git a/editor/plugins/animation_tree_editor_plugin.cpp b/editor/plugins/animation_tree_editor_plugin.cpp index 054124da8f..414b091475 100644 --- a/editor/plugins/animation_tree_editor_plugin.cpp +++ b/editor/plugins/animation_tree_editor_plugin.cpp @@ -476,7 +476,7 @@ void AnimationTreeEditor::_draw_node(const StringName &p_node) { Color font_color = get_color("font_color", "PopupMenu"); Color font_color_title = get_color("font_color_hover", "PopupMenu"); font_color_title.a *= 0.8; - Ref<Texture> slot_icon = get_icon("NodeRealSlot", "EditorIcons"); + Ref<Texture> slot_icon = get_icon("VisualShaderPort", "EditorIcons"); Size2 size = get_node_size(p_node); Point2 pos = anim_tree->node_get_pos(p_node); @@ -599,7 +599,7 @@ void AnimationTreeEditor::_draw_node(const StringName &p_node) { if (editable) { - Ref<Texture> arrow = get_icon("arrow", "Tree"); + Ref<Texture> arrow = get_icon("GuiDropdown", "EditorIcons"); Point2 arrow_ofs(w - arrow->get_width(), Math::floor((h - arrow->get_height()) / 2)); arrow->draw(ci, ofs + arrow_ofs); } @@ -671,7 +671,7 @@ Point2 AnimationTreeEditor::_get_slot_pos(const StringName &p_node_id, bool p_in Ref<StyleBox> style = get_stylebox("panel", "PopupMenu"); Ref<Font> font = get_font("font", "PopupMenu"); - Ref<Texture> slot_icon = get_icon("NodeRealSlot", "EditorIcons"); + Ref<Texture> slot_icon = get_icon("VisualShaderPort", "EditorIcons"); Size2 size = get_node_size(p_node_id); Point2 pos = anim_tree->node_get_pos(p_node_id); diff --git a/editor/plugins/canvas_item_editor_plugin.cpp b/editor/plugins/canvas_item_editor_plugin.cpp index 2b2358f3d0..ad01d0a31e 100644 --- a/editor/plugins/canvas_item_editor_plugin.cpp +++ b/editor/plugins/canvas_item_editor_plugin.cpp @@ -2301,19 +2301,24 @@ void CanvasItemEditor::_notification(int p_what) { Rect2 r = canvas_item->get_item_rect(); Transform2D xform = canvas_item->get_transform(); - float anchors[4]; - Vector2 pivot; + if (r != se->prev_rect || xform != se->prev_xform) { + viewport->update(); + se->prev_rect = r; + se->prev_xform = xform; + } + if (Object::cast_to<Control>(canvas_item)) { + float anchors[4]; + Vector2 pivot; + pivot = Object::cast_to<Control>(canvas_item)->get_pivot_offset(); anchors[MARGIN_LEFT] = Object::cast_to<Control>(canvas_item)->get_anchor(MARGIN_LEFT); anchors[MARGIN_RIGHT] = Object::cast_to<Control>(canvas_item)->get_anchor(MARGIN_RIGHT); anchors[MARGIN_TOP] = Object::cast_to<Control>(canvas_item)->get_anchor(MARGIN_TOP); anchors[MARGIN_BOTTOM] = Object::cast_to<Control>(canvas_item)->get_anchor(MARGIN_BOTTOM); - if (r != se->prev_rect || xform != se->prev_xform || pivot != se->prev_pivot || anchors[MARGIN_LEFT] != se->prev_anchors[MARGIN_LEFT] || anchors[MARGIN_RIGHT] != se->prev_anchors[MARGIN_RIGHT] || anchors[MARGIN_TOP] != se->prev_anchors[MARGIN_TOP] || anchors[MARGIN_BOTTOM] != se->prev_anchors[MARGIN_BOTTOM]) { + if (pivot != se->prev_pivot || anchors[MARGIN_LEFT] != se->prev_anchors[MARGIN_LEFT] || anchors[MARGIN_RIGHT] != se->prev_anchors[MARGIN_RIGHT] || anchors[MARGIN_TOP] != se->prev_anchors[MARGIN_TOP] || anchors[MARGIN_BOTTOM] != se->prev_anchors[MARGIN_BOTTOM]) { viewport->update(); - se->prev_rect = r; - se->prev_xform = xform; se->prev_pivot = pivot; se->prev_anchors[MARGIN_LEFT] = anchors[MARGIN_LEFT]; se->prev_anchors[MARGIN_RIGHT] = anchors[MARGIN_RIGHT]; diff --git a/editor/plugins/navigation_mesh_editor_plugin.cpp b/editor/plugins/navigation_mesh_editor_plugin.cpp new file mode 100644 index 0000000000..f0f5a62494 --- /dev/null +++ b/editor/plugins/navigation_mesh_editor_plugin.cpp @@ -0,0 +1,165 @@ +/*************************************************************************/ +/* navigation_mesh_editor_plugin.cpp */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ +#include "navigation_mesh_editor_plugin.h" +#include "io/marshalls.h" +#include "io/resource_saver.h" +#include "scene/3d/mesh_instance.h" +#include "scene/gui/box_container.h" + +#ifdef RECAST_ENABLED + +void NavigationMeshEditor::_node_removed(Node *p_node) { + + if (p_node == node) { + node = NULL; + + hide(); + } +} + +void NavigationMeshEditor::_notification(int p_option) { + + if (p_option == NOTIFICATION_ENTER_TREE) { + + button_bake->set_icon(get_icon("Bake", "EditorIcons")); + button_reset->set_icon(get_icon("Reload", "EditorIcons")); + } +} + +void NavigationMeshEditor::_bake_pressed() { + + ERR_FAIL_COND(!node); + const String conf_warning = node->get_configuration_warning(); + if (!conf_warning.empty()) { + err_dialog->set_text(conf_warning); + err_dialog->popup_centered_minsize(); + button_bake->set_pressed(false); + return; + } + + NavigationMeshGenerator::clear(node->get_navigation_mesh()); + NavigationMeshGenerator::bake(node->get_navigation_mesh(), node); + + if (node) { + node->update_gizmo(); + } +} + +void NavigationMeshEditor::_clear_pressed() { + + if (node) + NavigationMeshGenerator::clear(node->get_navigation_mesh()); + + button_bake->set_pressed(false); + bake_info->set_text(""); + + if (node) { + node->update_gizmo(); + } +} + +void NavigationMeshEditor::edit(NavigationMeshInstance *p_nav_mesh_instance) { + + if (p_nav_mesh_instance == NULL || node == p_nav_mesh_instance) { + return; + } + + node = p_nav_mesh_instance; +} + +void NavigationMeshEditor::_bind_methods() { + + ClassDB::bind_method("_bake_pressed", &NavigationMeshEditor::_bake_pressed); + ClassDB::bind_method("_clear_pressed", &NavigationMeshEditor::_clear_pressed); +} + +NavigationMeshEditor::NavigationMeshEditor() { + + bake_hbox = memnew(HBoxContainer); + button_bake = memnew(ToolButton); + button_bake->set_text(TTR("Bake!")); + button_bake->set_toggle_mode(true); + button_reset = memnew(Button); + button_bake->set_tooltip(TTR("Bake the navigation mesh.\n")); + + bake_info = memnew(Label); + bake_hbox->add_child(button_bake); + bake_hbox->add_child(button_reset); + bake_hbox->add_child(bake_info); + + err_dialog = memnew(AcceptDialog); + add_child(err_dialog); + node = NULL; + + button_bake->connect("pressed", this, "_bake_pressed"); + button_reset->connect("pressed", this, "_clear_pressed"); + button_reset->set_tooltip(TTR("Clear the navigation mesh.")); +} + +NavigationMeshEditor::~NavigationMeshEditor() { +} + +void NavigationMeshEditorPlugin::edit(Object *p_object) { + + navigation_mesh_editor->edit(Object::cast_to<NavigationMeshInstance>(p_object)); +} + +bool NavigationMeshEditorPlugin::handles(Object *p_object) const { + + return p_object->is_class("NavigationMeshInstance"); +} + +void NavigationMeshEditorPlugin::make_visible(bool p_visible) { + + if (p_visible) { + navigation_mesh_editor->show(); + navigation_mesh_editor->bake_hbox->show(); + } else { + + navigation_mesh_editor->hide(); + navigation_mesh_editor->bake_hbox->hide(); + navigation_mesh_editor->edit(NULL); + } +} + +NavigationMeshEditorPlugin::NavigationMeshEditorPlugin(EditorNode *p_node) { + + editor = p_node; + navigation_mesh_editor = memnew(NavigationMeshEditor); + editor->get_viewport()->add_child(navigation_mesh_editor); + add_control_to_container(CONTAINER_SPATIAL_EDITOR_MENU, navigation_mesh_editor->bake_hbox); + navigation_mesh_editor->hide(); + navigation_mesh_editor->bake_hbox->hide(); +} + +NavigationMeshEditorPlugin::~NavigationMeshEditorPlugin() { +} + +#endif // RECAST_ENABLED diff --git a/editor/plugins/navigation_mesh_editor_plugin.h b/editor/plugins/navigation_mesh_editor_plugin.h new file mode 100644 index 0000000000..3009e2addc --- /dev/null +++ b/editor/plugins/navigation_mesh_editor_plugin.h @@ -0,0 +1,86 @@ +/*************************************************************************/ +/* navigation_mesh_editor_plugin.h */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ +#ifndef NAVIGATION_MESH_GENERATOR_PLUGIN_H +#define NAVIGATION_MESH_GENERATOR_PLUGIN_H + +#ifdef RECAST_ENABLED + +#include "editor/editor_node.h" +#include "editor/editor_plugin.h" +#include "navigation_mesh_generator.h" + +class NavigationMeshEditor : public Control { + friend class NavigationMeshEditorPlugin; + + GDCLASS(NavigationMeshEditor, Control); + + AcceptDialog *err_dialog; + + HBoxContainer *bake_hbox; + Button *button_bake; + Button *button_reset; + Label *bake_info; + + NavigationMeshInstance *node; + + void _bake_pressed(); + void _clear_pressed(); + +protected: + void _node_removed(Node *p_node); + static void _bind_methods(); + void _notification(int p_what); + +public: + void edit(NavigationMeshInstance *p_nav_mesh_instance); + NavigationMeshEditor(); + ~NavigationMeshEditor(); +}; + +class NavigationMeshEditorPlugin : public EditorPlugin { + + GDCLASS(NavigationMeshEditorPlugin, EditorPlugin); + + NavigationMeshEditor *navigation_mesh_editor; + EditorNode *editor; + +public: + virtual String get_name() const { return "NavigationMesh"; } + bool has_main_screen() const { return false; } + virtual void edit(Object *p_node); + virtual bool handles(Object *p_node) const; + virtual void make_visible(bool p_visible); + + NavigationMeshEditorPlugin(EditorNode *p_node); + ~NavigationMeshEditorPlugin(); +}; + +#endif // RECAST_ENABLED +#endif // NAVIGATION_MESH_GENERATOR_PLUGIN_H diff --git a/editor/plugins/navigation_mesh_generator.cpp b/editor/plugins/navigation_mesh_generator.cpp new file mode 100644 index 0000000000..526db3a582 --- /dev/null +++ b/editor/plugins/navigation_mesh_generator.cpp @@ -0,0 +1,311 @@ +/*************************************************************************/ +/* navigation_mesh_generator.cpp */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ +#include "navigation_mesh_generator.h" + +#ifdef RECAST_ENABLED + +void NavigationMeshGenerator::_add_vertex(const Vector3 &p_vec3, Vector<float> &p_verticies) { + p_verticies.push_back(p_vec3.x); + p_verticies.push_back(p_vec3.y); + p_verticies.push_back(p_vec3.z); +} + +void NavigationMeshGenerator::_add_mesh(const Ref<Mesh> &p_mesh, const Transform &p_xform, Vector<float> &p_verticies, Vector<int> &p_indices) { + int current_vertex_count = p_verticies.size() / 3; + + for (int i = 0; i < p_mesh->get_surface_count(); i++) { + if (p_mesh->surface_get_primitive_type(i) != Mesh::PRIMITIVE_TRIANGLES) + continue; + + int index_count = 0; + if (p_mesh->surface_get_format(i) & Mesh::ARRAY_FORMAT_INDEX) { + index_count = p_mesh->surface_get_array_index_len(i); + } else { + index_count = p_mesh->surface_get_array_len(i); + } + + ERR_CONTINUE((index_count == 0 || (index_count % 3) != 0)); + + int face_count = index_count / 3; + + Array a = p_mesh->surface_get_arrays(i); + + PoolVector<Vector3> mesh_vertices = a[Mesh::ARRAY_VERTEX]; + PoolVector<Vector3>::Read vr = mesh_vertices.read(); + + if (p_mesh->surface_get_format(i) & Mesh::ARRAY_FORMAT_INDEX) { + + PoolVector<int> mesh_indices = a[Mesh::ARRAY_INDEX]; + PoolVector<int>::Read ir = mesh_indices.read(); + + for (int i = 0; i < mesh_vertices.size(); i++) { + _add_vertex(p_xform.xform(vr[i]), p_verticies); + } + + for (int i = 0; i < face_count; i++) { + // CCW + p_indices.push_back(current_vertex_count + (ir[i * 3 + 0])); + p_indices.push_back(current_vertex_count + (ir[i * 3 + 2])); + p_indices.push_back(current_vertex_count + (ir[i * 3 + 1])); + } + } else { + face_count = mesh_vertices.size() / 3; + for (int i = 0; i < face_count; i++) { + _add_vertex(p_xform.xform(vr[i * 3 + 0]), p_verticies); + _add_vertex(p_xform.xform(vr[i * 3 + 2]), p_verticies); + _add_vertex(p_xform.xform(vr[i * 3 + 1]), p_verticies); + + p_indices.push_back(current_vertex_count + (i * 3 + 0)); + p_indices.push_back(current_vertex_count + (i * 3 + 1)); + p_indices.push_back(current_vertex_count + (i * 3 + 2)); + } + } + } +} + +void NavigationMeshGenerator::_parse_geometry(const Transform &p_base_inverse, Node *p_node, Vector<float> &p_verticies, Vector<int> &p_indices) { + + if (Object::cast_to<MeshInstance>(p_node)) { + + MeshInstance *mesh_instance = Object::cast_to<MeshInstance>(p_node); + Ref<Mesh> mesh = mesh_instance->get_mesh(); + if (mesh.is_valid()) { + _add_mesh(mesh, p_base_inverse * mesh_instance->get_global_transform(), p_verticies, p_indices); + } + } + + for (int i = 0; i < p_node->get_child_count(); i++) { + _parse_geometry(p_base_inverse, p_node->get_child(i), p_verticies, p_indices); + } +} + +void NavigationMeshGenerator::_convert_detail_mesh_to_native_navigation_mesh(const rcPolyMeshDetail *p_detail_mesh, Ref<NavigationMesh> p_nav_mesh) { + + PoolVector<Vector3> nav_vertices; + + for (int i = 0; i < p_detail_mesh->nverts; i++) { + const float *v = &p_detail_mesh->verts[i * 3]; + nav_vertices.append(Vector3(v[0], v[1], v[2])); + } + p_nav_mesh->set_vertices(nav_vertices); + + for (int i = 0; i < p_detail_mesh->nmeshes; i++) { + const unsigned int *m = &p_detail_mesh->meshes[i * 4]; + const unsigned int bverts = m[0]; + const unsigned int btris = m[2]; + const unsigned int ntris = m[3]; + const unsigned char *tris = &p_detail_mesh->tris[btris * 4]; + for (unsigned int j = 0; j < ntris; j++) { + Vector<int> nav_indices; + nav_indices.resize(3); + nav_indices[0] = ((int)(bverts + tris[j * 4 + 0])); + nav_indices[1] = ((int)(bverts + tris[j * 4 + 1])); + nav_indices[2] = ((int)(bverts + tris[j * 4 + 2])); + p_nav_mesh->add_polygon(nav_indices); + } + } +} + +void NavigationMeshGenerator::_build_recast_navigation_mesh(Ref<NavigationMesh> p_nav_mesh, EditorProgress *ep, + rcHeightfield *hf, rcCompactHeightfield *chf, rcContourSet *cset, rcPolyMesh *poly_mesh, rcPolyMeshDetail *detail_mesh, + Vector<float> &verticies, Vector<int> &indices) { + rcContext ctx; + ep->step(TTR("Setting up Configuration..."), 1); + + const float *verts = verticies.ptr(); + const int nverts = verticies.size() / 3; + const int *tris = indices.ptr(); + const int ntris = indices.size() / 3; + + float bmin[3], bmax[3]; + rcCalcBounds(verts, nverts, bmin, bmax); + + rcConfig cfg; + memset(&cfg, 0, sizeof(cfg)); + + cfg.cs = p_nav_mesh->get_cell_size(); + cfg.ch = p_nav_mesh->get_cell_height(); + cfg.walkableSlopeAngle = p_nav_mesh->get_agent_max_slope(); + cfg.walkableHeight = (int)Math::ceil(p_nav_mesh->get_agent_height() / cfg.ch); + cfg.walkableClimb = (int)Math::floor(p_nav_mesh->get_agent_max_climb() / cfg.ch); + cfg.walkableRadius = (int)Math::ceil(p_nav_mesh->get_agent_radius() / cfg.cs); + cfg.maxEdgeLen = (int)(p_nav_mesh->get_edge_max_length() / p_nav_mesh->get_cell_size()); + cfg.maxSimplificationError = p_nav_mesh->get_edge_max_error(); + cfg.minRegionArea = (int)(p_nav_mesh->get_region_min_size() * p_nav_mesh->get_region_min_size()); + cfg.mergeRegionArea = (int)(p_nav_mesh->get_region_merge_size() * p_nav_mesh->get_region_merge_size()); + cfg.maxVertsPerPoly = (int)p_nav_mesh->get_verts_per_poly(); + cfg.detailSampleDist = p_nav_mesh->get_detail_sample_distance() < 0.9f ? 0 : p_nav_mesh->get_cell_size() * p_nav_mesh->get_detail_sample_distance(); + cfg.detailSampleMaxError = p_nav_mesh->get_cell_height() * p_nav_mesh->get_detail_sample_max_error(); + + cfg.bmin[0] = bmin[0]; + cfg.bmin[1] = bmin[1]; + cfg.bmin[2] = bmin[2]; + cfg.bmax[0] = bmax[0]; + cfg.bmax[1] = bmax[1]; + cfg.bmax[2] = bmax[2]; + + ep->step(TTR("Calculating grid size..."), 2); + rcCalcGridSize(cfg.bmin, cfg.bmax, cfg.cs, &cfg.width, &cfg.height); + + ep->step(TTR("Creating heightfield..."), 3); + hf = rcAllocHeightfield(); + + ERR_FAIL_COND(!hf); + ERR_FAIL_COND(!rcCreateHeightfield(&ctx, *hf, cfg.width, cfg.height, cfg.bmin, cfg.bmax, cfg.cs, cfg.ch)); + + ep->step(TTR("Marking walkable triangles..."), 4); + { + Vector<unsigned char> tri_areas; + tri_areas.resize(ntris); + + ERR_FAIL_COND(tri_areas.size() == 0); + + memset(tri_areas.ptr(), 0, ntris * sizeof(unsigned char)); + rcMarkWalkableTriangles(&ctx, cfg.walkableSlopeAngle, verts, nverts, tris, ntris, tri_areas.ptr()); + + ERR_FAIL_COND(!rcRasterizeTriangles(&ctx, verts, nverts, tris, tri_areas.ptr(), ntris, *hf, cfg.walkableClimb)); + } + + if (p_nav_mesh->get_filter_low_hanging_obstacles()) + rcFilterLowHangingWalkableObstacles(&ctx, cfg.walkableClimb, *hf); + if (p_nav_mesh->get_filter_ledge_spans()) + rcFilterLedgeSpans(&ctx, cfg.walkableHeight, cfg.walkableClimb, *hf); + if (p_nav_mesh->get_filter_walkable_low_height_spans()) + rcFilterWalkableLowHeightSpans(&ctx, cfg.walkableHeight, *hf); + + ep->step(TTR("Constructing compact heightfield..."), 5); + + chf = rcAllocCompactHeightfield(); + + ERR_FAIL_COND(!chf); + ERR_FAIL_COND(!rcBuildCompactHeightfield(&ctx, cfg.walkableHeight, cfg.walkableClimb, *hf, *chf)); + + rcFreeHeightField(hf); + hf = 0; + + ep->step(TTR("Eroding walkable area..."), 6); + ERR_FAIL_COND(!rcErodeWalkableArea(&ctx, cfg.walkableRadius, *chf)); + + ep->step(TTR("Partioning..."), 7); + if (p_nav_mesh->get_sample_partition_type() == NavigationMesh::SAMPLE_PARTITION_WATERSHED) { + ERR_FAIL_COND(!rcBuildDistanceField(&ctx, *chf)); + ERR_FAIL_COND(!rcBuildRegions(&ctx, *chf, 0, cfg.minRegionArea, cfg.mergeRegionArea)); + } else if (p_nav_mesh->get_sample_partition_type() == NavigationMesh::SAMPLE_PARTITION_MONOTONE) { + ERR_FAIL_COND(!rcBuildRegionsMonotone(&ctx, *chf, 0, cfg.minRegionArea, cfg.mergeRegionArea)); + } else { + ERR_FAIL_COND(!rcBuildLayerRegions(&ctx, *chf, 0, cfg.minRegionArea)); + } + + ep->step(TTR("Creating contours..."), 8); + + cset = rcAllocContourSet(); + + ERR_FAIL_COND(!cset); + ERR_FAIL_COND(!rcBuildContours(&ctx, *chf, cfg.maxSimplificationError, cfg.maxEdgeLen, *cset)); + + ep->step(TTR("Creating polymesh..."), 9); + + poly_mesh = rcAllocPolyMesh(); + ERR_FAIL_COND(!poly_mesh); + ERR_FAIL_COND(!rcBuildPolyMesh(&ctx, *cset, cfg.maxVertsPerPoly, *poly_mesh)); + + detail_mesh = rcAllocPolyMeshDetail(); + ERR_FAIL_COND(!detail_mesh); + ERR_FAIL_COND(!rcBuildPolyMeshDetail(&ctx, *poly_mesh, *chf, cfg.detailSampleDist, cfg.detailSampleMaxError, *detail_mesh)); + + rcFreeCompactHeightfield(chf); + chf = 0; + rcFreeContourSet(cset); + cset = 0; + + ep->step(TTR("Converting to native navigation mesh..."), 10); + + _convert_detail_mesh_to_native_navigation_mesh(detail_mesh, p_nav_mesh); + + rcFreePolyMesh(poly_mesh); + poly_mesh = 0; + rcFreePolyMeshDetail(detail_mesh); + detail_mesh = 0; +} + +void NavigationMeshGenerator::bake(Ref<NavigationMesh> p_nav_mesh, Node *p_node) { + + ERR_FAIL_COND(!p_nav_mesh.is_valid()); + + EditorProgress ep("bake", TTR("Navigation Mesh Generator Setup:"), 11); + ep.step(TTR("Parsing Geometry..."), 0); + + Vector<float> verticies; + Vector<int> indices; + + _parse_geometry(Object::cast_to<Spatial>(p_node)->get_global_transform().affine_inverse(), p_node, verticies, indices); + + if (verticies.size() > 0 && indices.size() > 0) { + + rcHeightfield *hf = NULL; + rcCompactHeightfield *chf = NULL; + rcContourSet *cset = NULL; + rcPolyMesh *poly_mesh = NULL; + rcPolyMeshDetail *detail_mesh = NULL; + + _build_recast_navigation_mesh(p_nav_mesh, &ep, hf, chf, cset, poly_mesh, detail_mesh, verticies, indices); + + if (hf) { + rcFreeHeightField(hf); + hf = 0; + } + if (chf) { + rcFreeCompactHeightfield(chf); + chf = 0; + } + if (cset) { + rcFreeContourSet(cset); + cset = 0; + } + if (poly_mesh) { + rcFreePolyMesh(poly_mesh); + poly_mesh = 0; + } + if (detail_mesh) { + rcFreePolyMeshDetail(detail_mesh); + detail_mesh = 0; + } + } + ep.step(TTR("Done!"), 11); +} + +void NavigationMeshGenerator::clear(Ref<NavigationMesh> p_nav_mesh) { + if (p_nav_mesh.is_valid()) { + p_nav_mesh->clear_polygons(); + p_nav_mesh->set_vertices(PoolVector<Vector3>()); + } +} + +#endif //RECAST_ENABLED diff --git a/editor/plugins/navigation_mesh_generator.h b/editor/plugins/navigation_mesh_generator.h new file mode 100644 index 0000000000..48e7dfe53f --- /dev/null +++ b/editor/plugins/navigation_mesh_generator.h @@ -0,0 +1,65 @@ +/*************************************************************************/ +/* navigation_mesh_generator.h */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ +#ifndef NAVIGATION_MESH_GENERATOR_H +#define NAVIGATION_MESH_GENERATOR_H + +#ifdef RECAST_ENABLED + +#include "editor/editor_node.h" +#include "editor/editor_settings.h" + +#include "scene/3d/mesh_instance.h" + +#include "scene/3d/navigation_mesh.h" + +#include "os/thread.h" +#include "scene/resources/shape.h" + +#include <Recast.h> + +class NavigationMeshGenerator { +protected: + static void _add_vertex(const Vector3 &p_vec3, Vector<float> &p_verticies); + static void _add_mesh(const Ref<Mesh> &p_mesh, const Transform &p_xform, Vector<float> &p_verticies, Vector<int> &p_indices); + static void _parse_geometry(const Transform &p_base_inverse, Node *p_node, Vector<float> &p_verticies, Vector<int> &p_indices); + + static void _convert_detail_mesh_to_native_navigation_mesh(const rcPolyMeshDetail *p_detail_mesh, Ref<NavigationMesh> p_nav_mesh); + static void _build_recast_navigation_mesh(Ref<NavigationMesh> p_nav_mesh, EditorProgress *ep, + rcHeightfield *hf, rcCompactHeightfield *chf, rcContourSet *cset, rcPolyMesh *poly_mesh, + rcPolyMeshDetail *detail_mesh, Vector<float> &verticies, Vector<int> &indices); + +public: + static void bake(Ref<NavigationMesh> p_nav_mesh, Node *p_base); + static void clear(Ref<NavigationMesh> p_nav_mesh); +}; + +#endif // RECAST_ENABLED + +#endif // NAVIGATION_MESH_GENERATOR_H diff --git a/editor/plugins/script_editor_plugin.cpp b/editor/plugins/script_editor_plugin.cpp index 6f03d086ca..44a9bc6d2e 100644 --- a/editor/plugins/script_editor_plugin.cpp +++ b/editor/plugins/script_editor_plugin.cpp @@ -421,8 +421,10 @@ void ScriptEditor::_go_to_tab(int p_idx) { _update_history_arrows(); _update_script_colors(); _update_members_overview(); + _update_help_overview(); _update_selected_editor_menu(); _update_members_overview_visibility(); + _update_help_overview_visibility(); } void ScriptEditor::_add_recent_script(String p_path) { @@ -555,6 +557,7 @@ void ScriptEditor::_close_tab(int p_idx, bool p_save) { _update_script_names(); _update_members_overview_visibility(); + _update_help_overview_visibility(); _save_layout(); } @@ -1110,6 +1113,7 @@ void ScriptEditor::_notification(int p_what) { editor->connect("resource_saved", this, "_res_saved_callback"); script_list->connect("item_selected", this, "_script_selected"); members_overview->connect("item_selected", this, "_members_overview_selected"); + help_overview->connect("item_selected", this, "_help_overview_selected"); script_split->connect("dragged", this, "_script_split_dragged"); autosave_timer->connect("timeout", this, "_autosave_scripts"); { @@ -1278,6 +1282,15 @@ void ScriptEditor::_members_overview_selected(int p_idx) { se->ensure_focus(); } +void ScriptEditor::_help_overview_selected(int p_idx) { + Node *current = tab_container->get_child(tab_container->get_current_tab()); + EditorHelp *se = Object::cast_to<EditorHelp>(current); + if (!se) { + return; + } + se->scroll_to_section(help_overview->get_item_metadata(p_idx)); +} + void ScriptEditor::_script_selected(int p_idx) { grab_focus_block = !Input::get_singleton()->is_mouse_button_pressed(1); //amazing hack, simply amazing @@ -1387,14 +1400,58 @@ void ScriptEditor::_update_members_overview() { } } +void ScriptEditor::_update_help_overview_visibility() { + + int selected = tab_container->get_current_tab(); + if (selected < 0 || selected >= tab_container->get_child_count()) + return; + + Node *current = tab_container->get_child(tab_container->get_current_tab()); + EditorHelp *se = Object::cast_to<EditorHelp>(current); + if (!se) { + help_overview->set_visible(false); + return; + } + + if (help_overview_enabled) { + help_overview->set_visible(true); + } else { + help_overview->set_visible(false); + } +} + +void ScriptEditor::_update_help_overview() { + + int selected = tab_container->get_current_tab(); + if (selected < 0 || selected >= tab_container->get_child_count()) + return; + + Node *current = tab_container->get_child(tab_container->get_current_tab()); + EditorHelp *se = Object::cast_to<EditorHelp>(current); + if (!se) { + return; + } + + help_overview->clear(); + + Vector<Pair<String, int> > sections = se->get_sections(); + for (int i = 0; i < sections.size(); i++) { + help_overview->add_item(sections[i].first); + help_overview->set_item_metadata(i, sections[i].second); + } +} + +void _help_overview_selected(int p_idx) { +} + void ScriptEditor::_update_script_colors() { bool script_temperature_enabled = EditorSettings::get_singleton()->get("text_editor/open_scripts/script_temperature_enabled"); bool highlight_current = EditorSettings::get_singleton()->get("text_editor/open_scripts/highlight_current_script"); int hist_size = EditorSettings::get_singleton()->get("text_editor/open_scripts/script_temperature_history_size"); - Color hot_color = EditorSettings::get_singleton()->get("text_editor/open_scripts/script_temperature_hot_color"); - Color cold_color = EditorSettings::get_singleton()->get("text_editor/open_scripts/script_temperature_cold_color"); + Color hot_color = get_color("accent_color", "Editor"); + Color cold_color = get_color("font_color", "Editor"); for (int i = 0; i < script_list->get_item_count(); i++) { @@ -1531,6 +1588,7 @@ void ScriptEditor::_update_script_names() { } _update_members_overview(); + _update_help_overview(); _update_script_colors(); } @@ -1785,7 +1843,9 @@ void ScriptEditor::_editor_settings_changed() { use_space_indentation = EditorSettings::get_singleton()->get("text_editor/indent/type"); members_overview_enabled = EditorSettings::get_singleton()->get("text_editor/open_scripts/show_members_overview"); + help_overview_enabled = EditorSettings::get_singleton()->get("text_editor/help/show_help_index"); _update_members_overview_visibility(); + _update_help_overview_visibility(); float autosave_time = EditorSettings::get_singleton()->get("text_editor/files/autosave_interval_secs"); if (autosave_time > 0) { @@ -2164,6 +2224,7 @@ void ScriptEditor::_bind_methods() { ClassDB::bind_method("_update_script_names", &ScriptEditor::_update_script_names); ClassDB::bind_method("_tree_changed", &ScriptEditor::_tree_changed); ClassDB::bind_method("_members_overview_selected", &ScriptEditor::_members_overview_selected); + ClassDB::bind_method("_help_overview_selected", &ScriptEditor::_help_overview_selected); ClassDB::bind_method("_script_selected", &ScriptEditor::_script_selected); ClassDB::bind_method("_script_created", &ScriptEditor::_script_created); ClassDB::bind_method("_script_split_dragged", &ScriptEditor::_script_split_dragged); @@ -2193,6 +2254,7 @@ ScriptEditor::ScriptEditor(EditorNode *p_editor) { pending_auto_reload = false; auto_reload_running_scripts = false; members_overview_enabled = true; + help_overview_enabled = true; editor = p_editor; VBoxContainer *main_container = memnew(VBoxContainer); @@ -2221,6 +2283,11 @@ ScriptEditor::ScriptEditor(EditorNode *p_editor) { members_overview->set_custom_minimum_size(Size2(0, 100)); //need to give a bit of limit to avoid it from disappearing members_overview->set_v_size_flags(SIZE_EXPAND_FILL); + help_overview = memnew(ItemList); + list_split->add_child(help_overview); + help_overview->set_custom_minimum_size(Size2(0, 100)); //need to give a bit of limit to avoid it from disappearing + help_overview->set_v_size_flags(SIZE_EXPAND_FILL); + tab_container = memnew(TabContainer); tab_container->set_tabs_visible(false); script_split->add_child(tab_container); @@ -2520,8 +2587,6 @@ ScriptEditorPlugin::ScriptEditorPlugin(EditorNode *p_node) { EDITOR_DEF("text_editor/open_scripts/script_temperature_enabled", true); EDITOR_DEF("text_editor/open_scripts/highlight_current_script", true); EDITOR_DEF("text_editor/open_scripts/script_temperature_history_size", 15); - EDITOR_DEF("text_editor/open_scripts/script_temperature_hot_color", Color::html("ed5e5e")); - EDITOR_DEF("text_editor/open_scripts/script_temperature_cold_color", Color(1, 1, 1, 0.3)); EDITOR_DEF("text_editor/open_scripts/current_script_background_color", Color(1, 1, 1, 0.5)); EDITOR_DEF("text_editor/open_scripts/group_help_pages", true); EditorSettings::get_singleton()->add_property_hint(PropertyInfo(Variant::INT, "text_editor/open_scripts/sort_scripts_by", PROPERTY_HINT_ENUM, "Name,Path")); diff --git a/editor/plugins/script_editor_plugin.h b/editor/plugins/script_editor_plugin.h index d2677c6a4a..03fc4da7ce 100644 --- a/editor/plugins/script_editor_plugin.h +++ b/editor/plugins/script_editor_plugin.h @@ -187,6 +187,8 @@ class ScriptEditor : public PanelContainer { HSplitContainer *script_split; ItemList *members_overview; bool members_overview_enabled; + ItemList *help_overview; + bool help_overview_enabled; VSplitContainer *list_split; TabContainer *tab_container; EditorFileDialog *file_dialog; @@ -294,6 +296,10 @@ class ScriptEditor : public PanelContainer { void _members_overview_selected(int p_idx); void _script_selected(int p_idx); + void _update_help_overview_visibility(); + void _update_help_overview(); + void _help_overview_selected(int p_idx); + void _find_scripts(Node *p_base, Node *p_current, Set<Ref<Script> > &used); void _tree_changed(); diff --git a/editor/plugins/script_text_editor.cpp b/editor/plugins/script_text_editor.cpp index 2192d3ac49..d2cb96bf3b 100644 --- a/editor/plugins/script_text_editor.cpp +++ b/editor/plugins/script_text_editor.cpp @@ -948,13 +948,26 @@ void ScriptTextEditor::_edit_option(int p_op) { if (tx->get_selection_to_column() == 0) end -= 1; + // Check if all lines in the selected block are commented + bool is_commented = true; + for (int i = begin; i <= end; i++) { + if (!tx->get_line(i).begins_with("#")) { + is_commented = false; + break; + } + } for (int i = begin; i <= end; i++) { String line_text = tx->get_line(i); - if (line_text.begins_with("#")) - line_text = line_text.substr(1, line_text.length()); - else - line_text = "#" + line_text; + if (line_text.strip_edges().empty()) { + line_text = "#"; + } else { + if (is_commented) { + line_text = line_text.substr(1, line_text.length()); + } else { + line_text = "#" + line_text; + } + } tx->set_line(i, line_text); } } else { diff --git a/editor/plugins/spatial_editor_plugin.cpp b/editor/plugins/spatial_editor_plugin.cpp index 93d12fd3d2..2c42150cee 100644 --- a/editor/plugins/spatial_editor_plugin.cpp +++ b/editor/plugins/spatial_editor_plugin.cpp @@ -76,18 +76,29 @@ void SpatialEditorViewport::_update_camera(float p_interp_delta) { } else camera->set_perspective(get_fov(), get_znear(), get_zfar()); - float inertia = EDITOR_DEF("editors/3d/orbit_inertia", 0.5); - inertia = MAX(0, inertia); + //when not being manipulated, move softly + float free_orbit_inertia = EDITOR_DEF("editors/3d/free_orbit_inertia", 0.15); + float free_translation_inertia = EDITOR_DEF("editors/3d/free_translation_inertia", 0.15); + //when being manipulated, move more quickly + float manip_orbit_inertia = EDITOR_DEF("editors/3d/manipulation_orbit_inertia", 0.075); + float manip_translation_inertia = EDITOR_DEF("editors/3d/manipulation_translation_inertia", 0.075); + + //determine if being manipulated + bool manipulated = (Input::get_singleton()->get_mouse_button_mask() & (2 | 4)) || Input::get_singleton()->is_key_pressed(KEY_SHIFT) || Input::get_singleton()->is_key_pressed(KEY_ALT) || Input::get_singleton()->is_key_pressed(KEY_CONTROL); + + float orbit_inertia = MAX(0.00001, manipulated ? manip_orbit_inertia : free_orbit_inertia); + float translation_inertia = MAX(0.0001, manipulated ? manip_translation_inertia : free_translation_inertia); Cursor old_camera_cursor = camera_cursor; camera_cursor = cursor; - camera_cursor.x_rot = Math::lerp(old_camera_cursor.x_rot, cursor.x_rot, p_interp_delta * (1 / inertia)); - camera_cursor.y_rot = Math::lerp(old_camera_cursor.y_rot, cursor.y_rot, p_interp_delta * (1 / inertia)); + camera_cursor.x_rot = Math::lerp(old_camera_cursor.x_rot, cursor.x_rot, MIN(1.f, p_interp_delta * (1 / orbit_inertia))); + camera_cursor.y_rot = Math::lerp(old_camera_cursor.y_rot, cursor.y_rot, MIN(1.f, p_interp_delta * (1 / orbit_inertia))); - bool disable_interp = (Input::get_singleton()->get_mouse_button_mask() & (2 | 4)) || Input::get_singleton()->is_key_pressed(KEY_SHIFT) || Input::get_singleton()->is_key_pressed(KEY_ALT) || Input::get_singleton()->is_key_pressed(KEY_CONTROL); + camera_cursor.pos = old_camera_cursor.pos.linear_interpolate(cursor.pos, MIN(1.f, p_interp_delta * (1 / translation_inertia))); + camera_cursor.distance = Math::lerp(old_camera_cursor.distance, cursor.distance, MIN(1.f, p_interp_delta * (1 / translation_inertia))); - if (p_interp_delta == 0 || disable_interp || is_freelook_active()) { + if (p_interp_delta == 0 || is_freelook_active()) { camera_cursor = cursor; } @@ -3696,18 +3707,50 @@ void SpatialEditor::_init_indicators() { origin_colors.push_back(Color(axis.x, axis.y, axis.z)); origin_points.push_back(axis * 4096); origin_points.push_back(axis * -4096); -#define ORIGIN_GRID_SIZE 25 +#define ORIGIN_GRID_SIZE 100 for (int j = -ORIGIN_GRID_SIZE; j <= ORIGIN_GRID_SIZE; j++) { - grid_colors[i].push_back(grid_color); - grid_colors[i].push_back(grid_color); - grid_colors[i].push_back(grid_color); - grid_colors[i].push_back(grid_color); - grid_points[i].push_back(axis_n1 * ORIGIN_GRID_SIZE + axis_n2 * j); - grid_points[i].push_back(-axis_n1 * ORIGIN_GRID_SIZE + axis_n2 * j); - grid_points[i].push_back(axis_n2 * ORIGIN_GRID_SIZE + axis_n1 * j); - grid_points[i].push_back(-axis_n2 * ORIGIN_GRID_SIZE + axis_n1 * j); + for (int k = -ORIGIN_GRID_SIZE; k <= ORIGIN_GRID_SIZE; k++) { + + Vector3 p = axis_n1 * j + axis_n2 * k; + float trans = Math::pow(MAX(0, 1.0 - (Vector2(j, k).length() / ORIGIN_GRID_SIZE)), 2); + + Vector3 pj = axis_n1 * (j + 1) + axis_n2 * k; + float transj = Math::pow(MAX(0, 1.0 - (Vector2(j + 1, k).length() / ORIGIN_GRID_SIZE)), 2); + + Vector3 pk = axis_n1 * j + axis_n2 * (k + 1); + float transk = Math::pow(MAX(0, 1.0 - (Vector2(j, k + 1).length() / ORIGIN_GRID_SIZE)), 2); + + Color trans_color = grid_color; + trans_color.a *= trans; + + Color transk_color = grid_color; + transk_color.a *= transk; + + Color transj_color = grid_color; + transj_color.a *= transj; + + if (j % 10 == 0 || k % 10 == 0) { + trans_color.a *= 2; + } + if ((k + 1) % 10 == 0) { + transk_color.a *= 2; + } + if ((j + 1) % 10 == 0) { + transj_color.a *= 2; + } + + grid_points[i].push_back(p); + grid_points[i].push_back(pk); + grid_colors[i].push_back(trans_color); + grid_colors[i].push_back(transk_color); + + grid_points[i].push_back(p); + grid_points[i].push_back(pj); + grid_colors[i].push_back(trans_color); + grid_colors[i].push_back(transj_color); + } } grid[i] = VisualServer::get_singleton()->mesh_create(); |