You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-05 12:10:55 +00:00
Remove Navigation2D/3D nodes, and move the navigation map to the world resource
This commit is contained in:
@@ -179,6 +179,15 @@ bool GridMap::get_collision_layer_bit(int p_bit) const {
|
||||
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_mesh_library(const Ref<MeshLibrary> &p_mesh_library) {
|
||||
if (!mesh_library.is_null()) {
|
||||
mesh_library->unregister_owner(this);
|
||||
@@ -474,13 +483,14 @@ 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_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;
|
||||
}
|
||||
}
|
||||
@@ -564,15 +574,16 @@ 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_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 +605,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 +644,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()) {
|
||||
@@ -679,8 +678,6 @@ void GridMap::_notification(int p_what) {
|
||||
_octant_exit_world(E->key());
|
||||
}
|
||||
|
||||
navigation = nullptr;
|
||||
|
||||
//_queue_octants_dirty(MAP_DIRTY_INSTANCES|MAP_DIRTY_TRANSFORMS);
|
||||
//_update_octants_callback();
|
||||
//_update_area_instances();
|
||||
@@ -785,6 +782,9 @@ 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_mesh_library", "mesh_library"), &GridMap::set_mesh_library);
|
||||
ClassDB::bind_method(D_METHOD("get_mesh_library"), &GridMap::get_mesh_library);
|
||||
|
||||
@@ -838,6 +838,8 @@ 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");
|
||||
|
||||
BIND_CONSTANT(INVALID_CELL_ITEM);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user