@@ -263,6 +263,24 @@ Array GridMap::get_collision_shapes() const {
263263
264264 return shapes;
265265}
266+
267+ RID GridMap::get_physics_body_from_octant_coord (const Vector3i &p_octant_coords) const {
268+ OctantKey octantkey;
269+ octantkey.x = p_octant_coords.x ;
270+ octantkey.y = p_octant_coords.y ;
271+ octantkey.z = p_octant_coords.z ;
272+
273+ const HashMap<OctantKey, Octant *, OctantKey>::ConstIterator octant_kv = octant_map.find (octantkey);
274+
275+ if (!octant_kv) {
276+ return RID ();
277+ }
278+
279+ Octant *g = octant_kv->value ;
280+ RID body_rid = g->static_body ;
281+
282+ return body_rid;
283+ }
266284#endif // PHYSICS_3D_DISABLED
267285
268286void GridMap::set_bake_navigation (bool p_bake_navigation) {
@@ -1731,7 +1749,34 @@ void GridMap::navmesh_parse_source_geometry(const Ref<NavigationMesh> &p_navigat
17311749 }
17321750#ifndef PHYSICS_3D_DISABLED
17331751 else if ((parsed_geometry_type == NavigationMesh::PARSED_GEOMETRY_STATIC_COLLIDERS || parsed_geometry_type == NavigationMesh::PARSED_GEOMETRY_BOTH ) && (gridmap->get_collision_layer () & parsed_collision_mask)) {
1734- Array shapes = gridmap->get_collision_shapes ();
1752+ Array shapes;
1753+
1754+ // If we have a baking AABB set we can skip wasting time on parsing the entire GridMap.
1755+ AABB baking_aabb = p_navigation_mesh->get_filter_baking_aabb ();
1756+ if (baking_aabb.has_volume ()) {
1757+ Vector3 baking_aabb_offset = p_navigation_mesh->get_filter_baking_aabb_offset ();
1758+ baking_aabb.position = baking_aabb.position + baking_aabb_offset;
1759+
1760+ const TypedArray<Vector3i> octant_coords = gridmap->get_used_octants_in_bounds (baking_aabb);
1761+ for (const Vector3i octant_coord : octant_coords) {
1762+ RID body = gridmap->get_physics_body_from_octant_coord (octant_coord);
1763+ if (body.is_null ()) {
1764+ continue ;
1765+ }
1766+ const Transform3D body_xform = PhysicsServer3D::get_singleton ()->body_get_state (body, PhysicsServer3D::BODY_STATE_TRANSFORM );
1767+ int nshapes = PhysicsServer3D::get_singleton ()->body_get_shape_count (body);
1768+ for (int i = 0 ; i < nshapes; i++) {
1769+ RID shape = PhysicsServer3D::get_singleton ()->body_get_shape (body, i);
1770+ Transform3D shape_xform = PhysicsServer3D::get_singleton ()->body_get_shape_transform (body, i);
1771+ Transform3D xform = body_xform * shape_xform;
1772+ shapes.push_back (xform);
1773+ shapes.push_back (shape);
1774+ }
1775+ }
1776+ } else {
1777+ shapes = gridmap->get_collision_shapes ();
1778+ }
1779+
17351780 for (int i = 0 ; i < shapes.size (); i += 2 ) {
17361781 RID shape = shapes[i + 1 ];
17371782 PhysicsServer3D::ShapeType type = PhysicsServer3D::get_singleton ()->shape_get_type (shape);
0 commit comments