@@ -349,6 +349,13 @@ bool AStar3D::_solve(Point *begin_point, Point *end_point, bool p_allow_partial_
349349 continue ;
350350 }
351351
352+ if (neighbor_filter_enabled) {
353+ bool filtered;
354+ if (GDVIRTUAL_CALL (_filter_neighbor, p->id , e->id , filtered) && filtered) {
355+ continue ;
356+ }
357+ }
358+
352359 real_t tentative_g_score = p->g_score + _compute_cost (p->id , e->id ) * e->weight_scale ;
353360
354361 bool new_point = false ;
@@ -524,6 +531,14 @@ Vector<int64_t> AStar3D::get_id_path(int64_t p_from_id, int64_t p_to_id, bool p_
524531 return path;
525532}
526533
534+ bool AStar3D::is_neighbor_filter_enabled () const {
535+ return neighbor_filter_enabled;
536+ }
537+
538+ void AStar3D::set_neighbor_filter_enabled (bool p_enabled) {
539+ neighbor_filter_enabled = p_enabled;
540+ }
541+
527542void AStar3D::set_point_disabled (int64_t p_id, bool p_disabled) {
528543 Point **p_entry = points.getptr (p_id);
529544 ERR_FAIL_COND_MSG (!p_entry, vformat (" Can't set if point is disabled. Point with id: %d doesn't exist." , p_id));
@@ -555,6 +570,9 @@ void AStar3D::_bind_methods() {
555570 ClassDB::bind_method (D_METHOD (" set_point_disabled" , " id" , " disabled" ), &AStar3D::set_point_disabled, DEFVAL (true ));
556571 ClassDB::bind_method (D_METHOD (" is_point_disabled" , " id" ), &AStar3D::is_point_disabled);
557572
573+ ClassDB::bind_method (D_METHOD (" set_neighbor_filter_enabled" , " enabled" ), &AStar3D::set_neighbor_filter_enabled);
574+ ClassDB::bind_method (D_METHOD (" is_neighbor_filter_enabled" ), &AStar3D::is_neighbor_filter_enabled);
575+
558576 ClassDB::bind_method (D_METHOD (" connect_points" , " id" , " to_id" , " bidirectional" ), &AStar3D::connect_points, DEFVAL (true ));
559577 ClassDB::bind_method (D_METHOD (" disconnect_points" , " id" , " to_id" , " bidirectional" ), &AStar3D::disconnect_points, DEFVAL (true ));
560578 ClassDB::bind_method (D_METHOD (" are_points_connected" , " id" , " to_id" , " bidirectional" ), &AStar3D::are_points_connected, DEFVAL (true ));
@@ -570,8 +588,11 @@ void AStar3D::_bind_methods() {
570588 ClassDB::bind_method (D_METHOD (" get_point_path" , " from_id" , " to_id" , " allow_partial_path" ), &AStar3D::get_point_path, DEFVAL (false ));
571589 ClassDB::bind_method (D_METHOD (" get_id_path" , " from_id" , " to_id" , " allow_partial_path" ), &AStar3D::get_id_path, DEFVAL (false ));
572590
591+ GDVIRTUAL_BIND (_filter_neighbor, " from_id" , " neighbor_id" )
573592 GDVIRTUAL_BIND (_estimate_cost, " from_id" , " end_id" )
574593 GDVIRTUAL_BIND (_compute_cost, " from_id" , " to_id" )
594+
595+ ADD_PROPERTY (PropertyInfo (Variant::BOOL, " neighbor_filter_enabled" ), " set_neighbor_filter_enabled" , " is_neighbor_filter_enabled" );
575596}
576597
577598AStar3D::~AStar3D () {
@@ -621,6 +642,14 @@ PackedInt64Array AStar2D::get_point_ids() {
621642 return astar.get_point_ids ();
622643}
623644
645+ bool AStar2D::is_neighbor_filter_enabled () const {
646+ return astar.neighbor_filter_enabled ;
647+ }
648+
649+ void AStar2D::set_neighbor_filter_enabled (bool p_enabled) {
650+ astar.neighbor_filter_enabled = p_enabled;
651+ }
652+
624653void AStar2D::set_point_disabled (int64_t p_id, bool p_disabled) {
625654 astar.set_point_disabled (p_id, p_disabled);
626655}
@@ -854,6 +883,13 @@ bool AStar2D::_solve(AStar3D::Point *begin_point, AStar3D::Point *end_point, boo
854883 continue ;
855884 }
856885
886+ if (astar.neighbor_filter_enabled ) {
887+ bool filtered;
888+ if (GDVIRTUAL_CALL (_filter_neighbor, p->id , e->id , filtered) && filtered) {
889+ continue ;
890+ }
891+ }
892+
857893 real_t tentative_g_score = p->g_score + _compute_cost (p->id , e->id ) * e->weight_scale ;
858894
859895 bool new_point = false ;
@@ -895,6 +931,9 @@ void AStar2D::_bind_methods() {
895931 ClassDB::bind_method (D_METHOD (" get_point_connections" , " id" ), &AStar2D::get_point_connections);
896932 ClassDB::bind_method (D_METHOD (" get_point_ids" ), &AStar2D::get_point_ids);
897933
934+ ClassDB::bind_method (D_METHOD (" set_neighbor_filter_enabled" , " enabled" ), &AStar2D::set_neighbor_filter_enabled);
935+ ClassDB::bind_method (D_METHOD (" is_neighbor_filter_enabled" ), &AStar2D::is_neighbor_filter_enabled);
936+
898937 ClassDB::bind_method (D_METHOD (" set_point_disabled" , " id" , " disabled" ), &AStar2D::set_point_disabled, DEFVAL (true ));
899938 ClassDB::bind_method (D_METHOD (" is_point_disabled" , " id" ), &AStar2D::is_point_disabled);
900939
@@ -913,6 +952,9 @@ void AStar2D::_bind_methods() {
913952 ClassDB::bind_method (D_METHOD (" get_point_path" , " from_id" , " to_id" , " allow_partial_path" ), &AStar2D::get_point_path, DEFVAL (false ));
914953 ClassDB::bind_method (D_METHOD (" get_id_path" , " from_id" , " to_id" , " allow_partial_path" ), &AStar2D::get_id_path, DEFVAL (false ));
915954
955+ GDVIRTUAL_BIND (_filter_neighbor, " from_id" , " neighbor_id" )
916956 GDVIRTUAL_BIND (_estimate_cost, " from_id" , " end_id" )
917957 GDVIRTUAL_BIND (_compute_cost, " from_id" , " to_id" )
958+
959+ ADD_PROPERTY (PropertyInfo (Variant::BOOL, " neighbor_filter_enabled" ), " set_neighbor_filter_enabled" , " is_neighbor_filter_enabled" );
918960}
0 commit comments