diff options
Diffstat (limited to 'scene/resources')
-rw-r--r-- | scene/resources/world_2d.cpp | 23 | ||||
-rw-r--r-- | scene/resources/world_2d.h | 6 | ||||
-rw-r--r-- | scene/resources/world_3d.cpp | 13 | ||||
-rw-r--r-- | scene/resources/world_3d.h | 2 |
4 files changed, 38 insertions, 6 deletions
diff --git a/scene/resources/world_2d.cpp b/scene/resources/world_2d.cpp index 156c7d0576..a064ade362 100644 --- a/scene/resources/world_2d.cpp +++ b/scene/resources/world_2d.cpp @@ -34,6 +34,7 @@ #include "scene/2d/camera_2d.h" #include "scene/2d/visibility_notifier_2d.h" #include "scene/main/window.h" +#include "servers/navigation_server_2d.h" #include "servers/physics_server_2d.h" #include "servers/rendering_server.h" @@ -315,14 +316,18 @@ void World2D::_update() { indexer->_update(); } -RID World2D::get_canvas() { +RID World2D::get_canvas() const { return canvas; } -RID World2D::get_space() { +RID World2D::get_space() const { return space; } +RID World2D::get_navigation_map() const { + return navigation_map; +} + void World2D::get_viewport_list(List<Viewport *> *r_viewports) { for (Map<Viewport *, SpatialIndexer2D::ViewportData>::Element *E = indexer->viewports.front(); E; E = E->next()) { r_viewports->push_back(E->key()); @@ -332,11 +337,13 @@ void World2D::get_viewport_list(List<Viewport *> *r_viewports) { void World2D::_bind_methods() { ClassDB::bind_method(D_METHOD("get_canvas"), &World2D::get_canvas); ClassDB::bind_method(D_METHOD("get_space"), &World2D::get_space); + ClassDB::bind_method(D_METHOD("get_navigation_map"), &World2D::get_navigation_map); ClassDB::bind_method(D_METHOD("get_direct_space_state"), &World2D::get_direct_space_state); ADD_PROPERTY(PropertyInfo(Variant::RID, "canvas", PROPERTY_HINT_NONE, "", 0), "", "get_canvas"); ADD_PROPERTY(PropertyInfo(Variant::RID, "space", PROPERTY_HINT_NONE, "", 0), "", "get_space"); + ADD_PROPERTY(PropertyInfo(Variant::RID, "navigation_map", PROPERTY_HINT_NONE, "", 0), "", "get_navigation_map"); ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "direct_space_state", PROPERTY_HINT_RESOURCE_TYPE, "PhysicsDirectSpaceState2D", 0), "", "get_direct_space_state"); } @@ -346,9 +353,9 @@ PhysicsDirectSpaceState2D *World2D::get_direct_space_state() { World2D::World2D() { canvas = RenderingServer::get_singleton()->canvas_create(); - space = PhysicsServer2D::get_singleton()->space_create(); - //set space2D to be more friendly with pixels than meters, by adjusting some constants + // Create and configure space2D to be more friendly with pixels than meters + space = PhysicsServer2D::get_singleton()->space_create(); PhysicsServer2D::get_singleton()->space_set_active(space, true); PhysicsServer2D::get_singleton()->area_set_param(space, PhysicsServer2D::AREA_PARAM_GRAVITY, GLOBAL_DEF("physics/2d/default_gravity", 98)); PhysicsServer2D::get_singleton()->area_set_param(space, PhysicsServer2D::AREA_PARAM_GRAVITY_VECTOR, GLOBAL_DEF("physics/2d/default_gravity_vector", Vector2(0, 1))); @@ -356,11 +363,19 @@ World2D::World2D() { ProjectSettings::get_singleton()->set_custom_property_info("physics/2d/default_linear_damp", PropertyInfo(Variant::FLOAT, "physics/2d/default_linear_damp", PROPERTY_HINT_RANGE, "-1,100,0.001,or_greater")); PhysicsServer2D::get_singleton()->area_set_param(space, PhysicsServer2D::AREA_PARAM_ANGULAR_DAMP, GLOBAL_DEF("physics/2d/default_angular_damp", 1.0)); ProjectSettings::get_singleton()->set_custom_property_info("physics/2d/default_angular_damp", PropertyInfo(Variant::FLOAT, "physics/2d/default_angular_damp", PROPERTY_HINT_RANGE, "-1,100,0.001,or_greater")); + + // Create and configure the navigation_map to be more friendly with pixels than meters. + navigation_map = NavigationServer2D::get_singleton()->map_create(); + NavigationServer2D::get_singleton()->map_set_active(navigation_map, true); + NavigationServer2D::get_singleton()->map_set_cell_size(navigation_map, GLOBAL_DEF("navigation/2d/default_cell_size", 10)); + NavigationServer2D::get_singleton()->map_set_edge_connection_margin(navigation_map, GLOBAL_DEF("navigation/2d/default_edge_connection_margin", 100)); + indexer = memnew(SpatialIndexer2D); } World2D::~World2D() { RenderingServer::get_singleton()->free(canvas); PhysicsServer2D::get_singleton()->free(space); + NavigationServer2D::get_singleton()->free(navigation_map); memdelete(indexer); } diff --git a/scene/resources/world_2d.h b/scene/resources/world_2d.h index ae13367421..38abf3d7ad 100644 --- a/scene/resources/world_2d.h +++ b/scene/resources/world_2d.h @@ -44,6 +44,7 @@ class World2D : public Resource { RID canvas; RID space; + RID navigation_map; SpatialIndexer2D *indexer; @@ -63,8 +64,9 @@ protected: void _update(); public: - RID get_canvas(); - RID get_space(); + RID get_canvas() const; + RID get_space() const; + RID get_navigation_map() const; PhysicsDirectSpaceState2D *get_direct_space_state(); diff --git a/scene/resources/world_3d.cpp b/scene/resources/world_3d.cpp index 9c0317454b..0e9f7a6cf2 100644 --- a/scene/resources/world_3d.cpp +++ b/scene/resources/world_3d.cpp @@ -35,6 +35,7 @@ #include "scene/3d/camera_3d.h" #include "scene/3d/visibility_notifier_3d.h" #include "scene/scene_string_names.h" +#include "servers/navigation_server_3d.h" struct SpatialIndexer { Octree<VisibilityNotifier3D> octree; @@ -243,6 +244,10 @@ RID World3D::get_space() const { return space; } +RID World3D::get_navigation_map() const { + return navigation_map; +} + RID World3D::get_scenario() const { return scenario; } @@ -310,6 +315,7 @@ void World3D::get_camera_list(List<Camera3D *> *r_cameras) { void World3D::_bind_methods() { ClassDB::bind_method(D_METHOD("get_space"), &World3D::get_space); + ClassDB::bind_method(D_METHOD("get_navigation_map"), &World3D::get_navigation_map); ClassDB::bind_method(D_METHOD("get_scenario"), &World3D::get_scenario); ClassDB::bind_method(D_METHOD("set_environment", "env"), &World3D::set_environment); ClassDB::bind_method(D_METHOD("get_environment"), &World3D::get_environment); @@ -322,6 +328,7 @@ void World3D::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "fallback_environment", PROPERTY_HINT_RESOURCE_TYPE, "Environment"), "set_fallback_environment", "get_fallback_environment"); ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "camera_effects", PROPERTY_HINT_RESOURCE_TYPE, "CameraEffects"), "set_camera_effects", "get_camera_effects"); ADD_PROPERTY(PropertyInfo(Variant::RID, "space", PROPERTY_HINT_NONE, "", 0), "", "get_space"); + ADD_PROPERTY(PropertyInfo(Variant::RID, "navigation_map", PROPERTY_HINT_NONE, "", 0), "", "get_navigation_map"); ADD_PROPERTY(PropertyInfo(Variant::RID, "scenario", PROPERTY_HINT_NONE, "", 0), "", "get_scenario"); ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "direct_space_state", PROPERTY_HINT_RESOURCE_TYPE, "PhysicsDirectSpaceState3D", 0), "", "get_direct_space_state"); } @@ -338,6 +345,11 @@ World3D::World3D() { PhysicsServer3D::get_singleton()->area_set_param(space, PhysicsServer3D::AREA_PARAM_ANGULAR_DAMP, GLOBAL_DEF("physics/3d/default_angular_damp", 0.1)); ProjectSettings::get_singleton()->set_custom_property_info("physics/3d/default_angular_damp", PropertyInfo(Variant::FLOAT, "physics/3d/default_angular_damp", PROPERTY_HINT_RANGE, "-1,100,0.001,or_greater")); + navigation_map = NavigationServer3D::get_singleton()->map_create(); + NavigationServer3D::get_singleton()->map_set_active(navigation_map, true); + NavigationServer3D::get_singleton()->map_set_cell_size(navigation_map, GLOBAL_DEF("navigation/3d/default_cell_size", 0.3)); + NavigationServer3D::get_singleton()->map_set_edge_connection_margin(navigation_map, GLOBAL_DEF("navigation/3d/default_edge_connection_margin", 5.0)); // Five meters, depends a lot on the agent's radius + #ifdef _3D_DISABLED indexer = nullptr; #else @@ -348,6 +360,7 @@ World3D::World3D() { World3D::~World3D() { PhysicsServer3D::get_singleton()->free(space); RenderingServer::get_singleton()->free(scenario); + NavigationServer3D::get_singleton()->free(navigation_map); #ifndef _3D_DISABLED memdelete(indexer); diff --git a/scene/resources/world_3d.h b/scene/resources/world_3d.h index 3d6c33997e..4e2717a2bb 100644 --- a/scene/resources/world_3d.h +++ b/scene/resources/world_3d.h @@ -46,6 +46,7 @@ class World3D : public Resource { private: RID space; + RID navigation_map; RID scenario; SpatialIndexer *indexer; Ref<Environment> environment; @@ -70,6 +71,7 @@ protected: public: RID get_space() const; + RID get_navigation_map() const; RID get_scenario() const; void set_environment(const Ref<Environment> &p_environment); |