2016-06-18 12:46:12 +00:00
/*************************************************************************/
/* navigation_mesh.cpp */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
2017-08-27 12:16:55 +00:00
/* https://godotengine.org */
2016-06-18 12:46:12 +00:00
/*************************************************************************/
2021-01-01 19:13:46 +00:00
/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
2016-06-18 12:46:12 +00:00
/* */
/* 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. */
/*************************************************************************/
2018-01-04 23:50:27 +00:00
2014-08-02 01:10:38 +00:00
# include "navigation_mesh.h"
2017-03-05 15:44:50 +00:00
void NavigationMesh : : create_from_mesh ( const Ref < Mesh > & p_mesh ) {
2021-03-03 10:29:30 +00:00
ERR_FAIL_COND ( p_mesh . is_null ( ) ) ;
2020-02-17 21:06:54 +00:00
vertices = Vector < Vector3 > ( ) ;
2014-08-02 01:10:38 +00:00
clear_polygons ( ) ;
2017-03-05 15:44:50 +00:00
for ( int i = 0 ; i < p_mesh - > get_surface_count ( ) ; i + + ) {
2020-05-14 14:41:43 +00:00
if ( p_mesh - > surface_get_primitive_type ( i ) ! = Mesh : : PRIMITIVE_TRIANGLES ) {
2014-08-02 01:10:38 +00:00
continue ;
2020-05-14 14:41:43 +00:00
}
2014-08-02 01:10:38 +00:00
Array arr = p_mesh - > surface_get_arrays ( i ) ;
2020-02-17 21:06:54 +00:00
Vector < Vector3 > varr = arr [ Mesh : : ARRAY_VERTEX ] ;
Vector < int > iarr = arr [ Mesh : : ARRAY_INDEX ] ;
2020-05-14 14:41:43 +00:00
if ( varr . size ( ) = = 0 | | iarr . size ( ) = = 0 ) {
2014-08-02 01:10:38 +00:00
continue ;
2020-05-14 14:41:43 +00:00
}
2014-08-02 01:10:38 +00:00
int from = vertices . size ( ) ;
vertices . append_array ( varr ) ;
int rlen = iarr . size ( ) ;
2020-02-17 21:06:54 +00:00
const int * r = iarr . ptr ( ) ;
2014-08-02 01:10:38 +00:00
2017-03-05 15:44:50 +00:00
for ( int j = 0 ; j < rlen ; j + = 3 ) {
2014-08-02 01:10:38 +00:00
Vector < int > vi ;
vi . resize ( 3 ) ;
2018-07-25 01:11:03 +00:00
vi . write [ 0 ] = r [ j + 0 ] + from ;
vi . write [ 1 ] = r [ j + 1 ] + from ;
vi . write [ 2 ] = r [ j + 2 ] + from ;
2014-08-02 01:10:38 +00:00
add_polygon ( vi ) ;
}
}
}
2021-08-11 08:23:14 +00:00
void NavigationMesh : : set_sample_partition_type ( SamplePartitionType p_value ) {
ERR_FAIL_INDEX ( p_value , SAMPLE_PARTITION_MAX ) ;
partition_type = p_value ;
2017-02-28 12:10:29 +00:00
}
2021-08-11 08:23:14 +00:00
NavigationMesh : : SamplePartitionType NavigationMesh : : get_sample_partition_type ( ) const {
return partition_type ;
2017-02-28 12:10:29 +00:00
}
2021-08-11 08:23:14 +00:00
void NavigationMesh : : set_parsed_geometry_type ( ParsedGeometryType p_value ) {
ERR_FAIL_INDEX ( p_value , PARSED_GEOMETRY_MAX ) ;
parsed_geometry_type = p_value ;
2021-02-10 20:18:45 +00:00
notify_property_list_changed ( ) ;
2019-05-23 06:37:58 +00:00
}
2021-08-11 08:23:14 +00:00
NavigationMesh : : ParsedGeometryType NavigationMesh : : get_parsed_geometry_type ( ) const {
2019-05-23 06:37:58 +00:00
return parsed_geometry_type ;
}
void NavigationMesh : : set_collision_mask ( uint32_t p_mask ) {
collision_mask = p_mask ;
}
uint32_t NavigationMesh : : get_collision_mask ( ) const {
return collision_mask ;
}
2021-08-11 23:01:38 +00:00
void NavigationMesh : : set_collision_mask_value ( int p_layer_number , bool p_value ) {
ERR_FAIL_COND_MSG ( p_layer_number < 1 , " Collision layer number must be between 1 and 32 inclusive. " ) ;
ERR_FAIL_COND_MSG ( p_layer_number > 32 , " Collision layer number must be between 1 and 32 inclusive. " ) ;
2019-05-23 06:37:58 +00:00
uint32_t mask = get_collision_mask ( ) ;
2020-05-14 14:41:43 +00:00
if ( p_value ) {
2021-08-11 23:01:38 +00:00
mask | = 1 < < ( p_layer_number - 1 ) ;
2020-05-14 14:41:43 +00:00
} else {
2021-08-11 23:01:38 +00:00
mask & = ~ ( 1 < < ( p_layer_number - 1 ) ) ;
2020-05-14 14:41:43 +00:00
}
2019-05-23 06:37:58 +00:00
set_collision_mask ( mask ) ;
}
2021-08-11 23:01:38 +00:00
bool NavigationMesh : : get_collision_mask_value ( int p_layer_number ) const {
ERR_FAIL_COND_V_MSG ( p_layer_number < 1 , false , " Collision layer number must be between 1 and 32 inclusive. " ) ;
ERR_FAIL_COND_V_MSG ( p_layer_number > 32 , false , " Collision layer number must be between 1 and 32 inclusive. " ) ;
return get_collision_mask ( ) & ( 1 < < ( p_layer_number - 1 ) ) ;
2019-05-23 06:37:58 +00:00
}
2021-08-11 08:23:14 +00:00
void NavigationMesh : : set_source_geometry_mode ( SourceGeometryMode p_geometry_mode ) {
2019-10-16 09:33:47 +00:00
ERR_FAIL_INDEX ( p_geometry_mode , SOURCE_GEOMETRY_MAX ) ;
2021-08-11 08:23:14 +00:00
source_geometry_mode = p_geometry_mode ;
2021-02-10 20:18:45 +00:00
notify_property_list_changed ( ) ;
2019-10-16 09:33:47 +00:00
}
2021-08-11 08:23:14 +00:00
NavigationMesh : : SourceGeometryMode NavigationMesh : : get_source_geometry_mode ( ) const {
2019-10-16 09:33:47 +00:00
return source_geometry_mode ;
}
void NavigationMesh : : set_source_group_name ( StringName p_group_name ) {
source_group_name = p_group_name ;
}
StringName NavigationMesh : : get_source_group_name ( ) const {
return source_group_name ;
}
2017-02-28 12:10:29 +00:00
void NavigationMesh : : set_cell_size ( float p_value ) {
2021-08-11 08:23:14 +00:00
ERR_FAIL_COND ( p_value < = 0 ) ;
2017-02-28 12:10:29 +00:00
cell_size = p_value ;
}
float NavigationMesh : : get_cell_size ( ) const {
return cell_size ;
}
void NavigationMesh : : set_cell_height ( float p_value ) {
2021-08-11 08:23:14 +00:00
ERR_FAIL_COND ( p_value < = 0 ) ;
2017-02-28 12:10:29 +00:00
cell_height = p_value ;
}
float NavigationMesh : : get_cell_height ( ) const {
return cell_height ;
}
void NavigationMesh : : set_agent_height ( float p_value ) {
2021-08-11 08:23:14 +00:00
ERR_FAIL_COND ( p_value < 0 ) ;
2017-02-28 12:10:29 +00:00
agent_height = p_value ;
}
float NavigationMesh : : get_agent_height ( ) const {
return agent_height ;
}
void NavigationMesh : : set_agent_radius ( float p_value ) {
2021-08-11 08:23:14 +00:00
ERR_FAIL_COND ( p_value < 0 ) ;
2017-02-28 12:10:29 +00:00
agent_radius = p_value ;
}
float NavigationMesh : : get_agent_radius ( ) {
return agent_radius ;
}
void NavigationMesh : : set_agent_max_climb ( float p_value ) {
2021-08-11 08:23:14 +00:00
ERR_FAIL_COND ( p_value < 0 ) ;
2017-02-28 12:10:29 +00:00
agent_max_climb = p_value ;
}
float NavigationMesh : : get_agent_max_climb ( ) const {
return agent_max_climb ;
}
void NavigationMesh : : set_agent_max_slope ( float p_value ) {
2021-08-11 08:23:14 +00:00
ERR_FAIL_COND ( p_value < 0 | | p_value > 90 ) ;
2017-02-28 12:10:29 +00:00
agent_max_slope = p_value ;
}
float NavigationMesh : : get_agent_max_slope ( ) const {
return agent_max_slope ;
}
void NavigationMesh : : set_region_min_size ( float p_value ) {
2021-08-11 08:23:14 +00:00
ERR_FAIL_COND ( p_value < 0 ) ;
2017-02-28 12:10:29 +00:00
region_min_size = p_value ;
}
float NavigationMesh : : get_region_min_size ( ) const {
return region_min_size ;
}
void NavigationMesh : : set_region_merge_size ( float p_value ) {
2021-08-11 08:23:14 +00:00
ERR_FAIL_COND ( p_value < 0 ) ;
2017-02-28 12:10:29 +00:00
region_merge_size = p_value ;
}
float NavigationMesh : : get_region_merge_size ( ) const {
return region_merge_size ;
}
void NavigationMesh : : set_edge_max_length ( float p_value ) {
2021-08-11 08:23:14 +00:00
ERR_FAIL_COND ( p_value < 0 ) ;
2017-02-28 12:10:29 +00:00
edge_max_length = p_value ;
}
float NavigationMesh : : get_edge_max_length ( ) const {
return edge_max_length ;
}
void NavigationMesh : : set_edge_max_error ( float p_value ) {
2021-08-11 08:23:14 +00:00
ERR_FAIL_COND ( p_value < 0 ) ;
2017-02-28 12:10:29 +00:00
edge_max_error = p_value ;
}
float NavigationMesh : : get_edge_max_error ( ) const {
return edge_max_error ;
}
void NavigationMesh : : set_verts_per_poly ( float p_value ) {
2021-08-11 08:23:14 +00:00
ERR_FAIL_COND ( p_value < 3 ) ;
2017-02-28 12:10:29 +00:00
verts_per_poly = p_value ;
}
float NavigationMesh : : get_verts_per_poly ( ) const {
return verts_per_poly ;
}
void NavigationMesh : : set_detail_sample_distance ( float p_value ) {
2021-08-11 08:23:14 +00:00
ERR_FAIL_COND ( p_value < 0 ) ;
2017-02-28 12:10:29 +00:00
detail_sample_distance = p_value ;
}
float NavigationMesh : : get_detail_sample_distance ( ) const {
return detail_sample_distance ;
}
void NavigationMesh : : set_detail_sample_max_error ( float p_value ) {
2021-08-11 08:23:14 +00:00
ERR_FAIL_COND ( p_value < 0 ) ;
2017-02-28 12:10:29 +00:00
detail_sample_max_error = p_value ;
}
float NavigationMesh : : get_detail_sample_max_error ( ) const {
return detail_sample_max_error ;
}
void NavigationMesh : : set_filter_low_hanging_obstacles ( bool p_value ) {
filter_low_hanging_obstacles = p_value ;
}
bool NavigationMesh : : get_filter_low_hanging_obstacles ( ) const {
return filter_low_hanging_obstacles ;
}
void NavigationMesh : : set_filter_ledge_spans ( bool p_value ) {
filter_ledge_spans = p_value ;
}
bool NavigationMesh : : get_filter_ledge_spans ( ) const {
return filter_ledge_spans ;
}
void NavigationMesh : : set_filter_walkable_low_height_spans ( bool p_value ) {
filter_walkable_low_height_spans = p_value ;
}
bool NavigationMesh : : get_filter_walkable_low_height_spans ( ) const {
return filter_walkable_low_height_spans ;
}
2020-02-17 21:06:54 +00:00
void NavigationMesh : : set_vertices ( const Vector < Vector3 > & p_vertices ) {
2017-03-05 15:44:50 +00:00
vertices = p_vertices ;
2021-02-10 20:18:45 +00:00
notify_property_list_changed ( ) ;
2014-08-02 01:10:38 +00:00
}
2020-02-17 21:06:54 +00:00
Vector < Vector3 > NavigationMesh : : get_vertices ( ) const {
2014-08-02 01:10:38 +00:00
return vertices ;
}
2017-03-05 15:44:50 +00:00
void NavigationMesh : : _set_polygons ( const Array & p_array ) {
2014-08-02 01:10:38 +00:00
polygons . resize ( p_array . size ( ) ) ;
2017-03-05 15:44:50 +00:00
for ( int i = 0 ; i < p_array . size ( ) ; i + + ) {
2018-07-25 01:11:03 +00:00
polygons . write [ i ] . indices = p_array [ i ] ;
2014-08-02 01:10:38 +00:00
}
2021-02-10 20:18:45 +00:00
notify_property_list_changed ( ) ;
2014-08-02 01:10:38 +00:00
}
Array NavigationMesh : : _get_polygons ( ) const {
Array ret ;
ret . resize ( polygons . size ( ) ) ;
2017-03-05 15:44:50 +00:00
for ( int i = 0 ; i < ret . size ( ) ; i + + ) {
ret [ i ] = polygons [ i ] . indices ;
2014-08-02 01:10:38 +00:00
}
return ret ;
}
2017-03-05 15:44:50 +00:00
void NavigationMesh : : add_polygon ( const Vector < int > & p_polygon ) {
2014-08-02 01:10:38 +00:00
Polygon polygon ;
2017-03-05 15:44:50 +00:00
polygon . indices = p_polygon ;
2014-08-02 01:10:38 +00:00
polygons . push_back ( polygon ) ;
2021-02-10 20:18:45 +00:00
notify_property_list_changed ( ) ;
2014-08-02 01:10:38 +00:00
}
2020-05-14 12:29:06 +00:00
2017-03-05 15:44:50 +00:00
int NavigationMesh : : get_polygon_count ( ) const {
2014-08-02 01:10:38 +00:00
return polygons . size ( ) ;
}
2020-05-14 12:29:06 +00:00
2017-03-05 15:44:50 +00:00
Vector < int > NavigationMesh : : get_polygon ( int p_idx ) {
ERR_FAIL_INDEX_V ( p_idx , polygons . size ( ) , Vector < int > ( ) ) ;
2014-08-02 01:10:38 +00:00
return polygons [ p_idx ] . indices ;
}
2020-05-14 12:29:06 +00:00
2017-03-05 15:44:50 +00:00
void NavigationMesh : : clear_polygons ( ) {
2014-08-02 01:10:38 +00:00
polygons . clear ( ) ;
}
2015-09-20 16:03:46 +00:00
Ref < Mesh > NavigationMesh : : get_debug_mesh ( ) {
2020-05-14 14:41:43 +00:00
if ( debug_mesh . is_valid ( ) ) {
2015-09-20 16:03:46 +00:00
return debug_mesh ;
2020-05-14 14:41:43 +00:00
}
2015-09-20 16:03:46 +00:00
2020-02-17 21:06:54 +00:00
Vector < Vector3 > vertices = get_vertices ( ) ;
const Vector3 * vr = vertices . ptr ( ) ;
2015-09-20 16:03:46 +00:00
List < Face3 > faces ;
2017-03-05 15:44:50 +00:00
for ( int i = 0 ; i < get_polygon_count ( ) ; i + + ) {
2015-09-20 16:03:46 +00:00
Vector < int > p = get_polygon ( i ) ;
2017-03-05 15:44:50 +00:00
for ( int j = 2 ; j < p . size ( ) ; j + + ) {
2015-09-20 16:03:46 +00:00
Face3 f ;
2017-03-05 15:44:50 +00:00
f . vertex [ 0 ] = vr [ p [ 0 ] ] ;
f . vertex [ 1 ] = vr [ p [ j - 1 ] ] ;
f . vertex [ 2 ] = vr [ p [ j ] ] ;
2015-09-20 16:03:46 +00:00
faces . push_back ( f ) ;
}
}
2017-03-05 15:44:50 +00:00
Map < _EdgeKey , bool > edge_map ;
2020-02-17 21:06:54 +00:00
Vector < Vector3 > tmeshfaces ;
2017-03-05 15:44:50 +00:00
tmeshfaces . resize ( faces . size ( ) * 3 ) ;
2015-09-20 16:03:46 +00:00
{
2020-02-17 21:06:54 +00:00
Vector3 * tw = tmeshfaces . ptrw ( ) ;
2017-03-05 15:44:50 +00:00
int tidx = 0 ;
2015-09-20 16:03:46 +00:00
2021-07-24 13:46:25 +00:00
for ( const Face3 & f : faces ) {
2017-03-05 15:44:50 +00:00
for ( int j = 0 ; j < 3 ; j + + ) {
tw [ tidx + + ] = f . vertex [ j ] ;
2015-09-20 16:03:46 +00:00
_EdgeKey ek ;
2017-06-30 18:47:17 +00:00
ek . from = f . vertex [ j ] . snapped ( Vector3 ( CMP_EPSILON , CMP_EPSILON , CMP_EPSILON ) ) ;
ek . to = f . vertex [ ( j + 1 ) % 3 ] . snapped ( Vector3 ( CMP_EPSILON , CMP_EPSILON , CMP_EPSILON ) ) ;
2020-05-14 14:41:43 +00:00
if ( ek . from < ek . to ) {
2017-03-05 15:44:50 +00:00
SWAP ( ek . from , ek . to ) ;
2020-05-14 14:41:43 +00:00
}
2015-09-20 16:03:46 +00:00
2019-02-12 20:10:08 +00:00
Map < _EdgeKey , bool > : : Element * F = edge_map . find ( ek ) ;
2015-09-20 16:03:46 +00:00
2019-02-12 20:10:08 +00:00
if ( F ) {
F - > get ( ) = false ;
2015-09-20 16:03:46 +00:00
} else {
2017-03-05 15:44:50 +00:00
edge_map [ ek ] = true ;
2015-09-20 16:03:46 +00:00
}
}
}
}
List < Vector3 > lines ;
2017-03-05 15:44:50 +00:00
for ( Map < _EdgeKey , bool > : : Element * E = edge_map . front ( ) ; E ; E = E - > next ( ) ) {
2015-09-20 16:03:46 +00:00
if ( E - > get ( ) ) {
lines . push_back ( E - > key ( ) . from ) ;
lines . push_back ( E - > key ( ) . to ) ;
}
}
2020-02-17 21:06:54 +00:00
Vector < Vector3 > varr ;
2015-09-20 16:03:46 +00:00
varr . resize ( lines . size ( ) ) ;
{
2020-02-17 21:06:54 +00:00
Vector3 * w = varr . ptrw ( ) ;
2017-03-05 15:44:50 +00:00
int idx = 0 ;
2021-07-24 13:46:25 +00:00
for ( const Vector3 & E : lines ) {
2021-07-16 03:45:57 +00:00
w [ idx + + ] = E ;
2015-09-20 16:03:46 +00:00
}
}
2017-06-07 21:18:55 +00:00
debug_mesh = Ref < ArrayMesh > ( memnew ( ArrayMesh ) ) ;
2015-09-20 16:03:46 +00:00
Array arr ;
arr . resize ( Mesh : : ARRAY_MAX ) ;
2017-03-05 15:44:50 +00:00
arr [ Mesh : : ARRAY_VERTEX ] = varr ;
2015-09-20 16:03:46 +00:00
2017-03-05 15:44:50 +00:00
debug_mesh - > add_surface_from_arrays ( Mesh : : PRIMITIVE_LINES , arr ) ;
2015-09-20 16:03:46 +00:00
return debug_mesh ;
}
2014-08-02 01:10:38 +00:00
void NavigationMesh : : _bind_methods ( ) {
2017-02-28 12:10:29 +00:00
ClassDB : : bind_method ( D_METHOD ( " set_sample_partition_type " , " sample_partition_type " ) , & NavigationMesh : : set_sample_partition_type ) ;
ClassDB : : bind_method ( D_METHOD ( " get_sample_partition_type " ) , & NavigationMesh : : get_sample_partition_type ) ;
2019-05-23 06:37:58 +00:00
ClassDB : : bind_method ( D_METHOD ( " set_parsed_geometry_type " , " geometry_type " ) , & NavigationMesh : : set_parsed_geometry_type ) ;
ClassDB : : bind_method ( D_METHOD ( " get_parsed_geometry_type " ) , & NavigationMesh : : get_parsed_geometry_type ) ;
ClassDB : : bind_method ( D_METHOD ( " set_collision_mask " , " mask " ) , & NavigationMesh : : set_collision_mask ) ;
ClassDB : : bind_method ( D_METHOD ( " get_collision_mask " ) , & NavigationMesh : : get_collision_mask ) ;
2021-08-11 23:01:38 +00:00
ClassDB : : bind_method ( D_METHOD ( " set_collision_mask_value " , " layer_number " , " value " ) , & NavigationMesh : : set_collision_mask_value ) ;
ClassDB : : bind_method ( D_METHOD ( " get_collision_mask_value " , " layer_number " ) , & NavigationMesh : : get_collision_mask_value ) ;
2019-05-23 06:37:58 +00:00
2019-10-16 09:33:47 +00:00
ClassDB : : bind_method ( D_METHOD ( " set_source_geometry_mode " , " mask " ) , & NavigationMesh : : set_source_geometry_mode ) ;
ClassDB : : bind_method ( D_METHOD ( " get_source_geometry_mode " ) , & NavigationMesh : : get_source_geometry_mode ) ;
ClassDB : : bind_method ( D_METHOD ( " set_source_group_name " , " mask " ) , & NavigationMesh : : set_source_group_name ) ;
ClassDB : : bind_method ( D_METHOD ( " get_source_group_name " ) , & NavigationMesh : : get_source_group_name ) ;
2017-02-28 12:10:29 +00:00
ClassDB : : bind_method ( D_METHOD ( " set_cell_size " , " cell_size " ) , & NavigationMesh : : set_cell_size ) ;
ClassDB : : bind_method ( D_METHOD ( " get_cell_size " ) , & NavigationMesh : : get_cell_size ) ;
ClassDB : : bind_method ( D_METHOD ( " set_cell_height " , " cell_height " ) , & NavigationMesh : : set_cell_height ) ;
ClassDB : : bind_method ( D_METHOD ( " get_cell_height " ) , & NavigationMesh : : get_cell_height ) ;
ClassDB : : bind_method ( D_METHOD ( " set_agent_height " , " agent_height " ) , & NavigationMesh : : set_agent_height ) ;
ClassDB : : bind_method ( D_METHOD ( " get_agent_height " ) , & NavigationMesh : : get_agent_height ) ;
ClassDB : : bind_method ( D_METHOD ( " set_agent_radius " , " agent_radius " ) , & NavigationMesh : : set_agent_radius ) ;
ClassDB : : bind_method ( D_METHOD ( " get_agent_radius " ) , & NavigationMesh : : get_agent_radius ) ;
ClassDB : : bind_method ( D_METHOD ( " set_agent_max_climb " , " agent_max_climb " ) , & NavigationMesh : : set_agent_max_climb ) ;
ClassDB : : bind_method ( D_METHOD ( " get_agent_max_climb " ) , & NavigationMesh : : get_agent_max_climb ) ;
ClassDB : : bind_method ( D_METHOD ( " set_agent_max_slope " , " agent_max_slope " ) , & NavigationMesh : : set_agent_max_slope ) ;
ClassDB : : bind_method ( D_METHOD ( " get_agent_max_slope " ) , & NavigationMesh : : get_agent_max_slope ) ;
ClassDB : : bind_method ( D_METHOD ( " set_region_min_size " , " region_min_size " ) , & NavigationMesh : : set_region_min_size ) ;
ClassDB : : bind_method ( D_METHOD ( " get_region_min_size " ) , & NavigationMesh : : get_region_min_size ) ;
ClassDB : : bind_method ( D_METHOD ( " set_region_merge_size " , " region_merge_size " ) , & NavigationMesh : : set_region_merge_size ) ;
ClassDB : : bind_method ( D_METHOD ( " get_region_merge_size " ) , & NavigationMesh : : get_region_merge_size ) ;
ClassDB : : bind_method ( D_METHOD ( " set_edge_max_length " , " edge_max_length " ) , & NavigationMesh : : set_edge_max_length ) ;
ClassDB : : bind_method ( D_METHOD ( " get_edge_max_length " ) , & NavigationMesh : : get_edge_max_length ) ;
ClassDB : : bind_method ( D_METHOD ( " set_edge_max_error " , " edge_max_error " ) , & NavigationMesh : : set_edge_max_error ) ;
ClassDB : : bind_method ( D_METHOD ( " get_edge_max_error " ) , & NavigationMesh : : get_edge_max_error ) ;
ClassDB : : bind_method ( D_METHOD ( " set_verts_per_poly " , " verts_per_poly " ) , & NavigationMesh : : set_verts_per_poly ) ;
ClassDB : : bind_method ( D_METHOD ( " get_verts_per_poly " ) , & NavigationMesh : : get_verts_per_poly ) ;
ClassDB : : bind_method ( D_METHOD ( " set_detail_sample_distance " , " detail_sample_dist " ) , & NavigationMesh : : set_detail_sample_distance ) ;
ClassDB : : bind_method ( D_METHOD ( " get_detail_sample_distance " ) , & NavigationMesh : : get_detail_sample_distance ) ;
ClassDB : : bind_method ( D_METHOD ( " set_detail_sample_max_error " , " detail_sample_max_error " ) , & NavigationMesh : : set_detail_sample_max_error ) ;
ClassDB : : bind_method ( D_METHOD ( " get_detail_sample_max_error " ) , & NavigationMesh : : get_detail_sample_max_error ) ;
ClassDB : : bind_method ( D_METHOD ( " set_filter_low_hanging_obstacles " , " filter_low_hanging_obstacles " ) , & NavigationMesh : : set_filter_low_hanging_obstacles ) ;
ClassDB : : bind_method ( D_METHOD ( " get_filter_low_hanging_obstacles " ) , & NavigationMesh : : get_filter_low_hanging_obstacles ) ;
ClassDB : : bind_method ( D_METHOD ( " set_filter_ledge_spans " , " filter_ledge_spans " ) , & NavigationMesh : : set_filter_ledge_spans ) ;
ClassDB : : bind_method ( D_METHOD ( " get_filter_ledge_spans " ) , & NavigationMesh : : get_filter_ledge_spans ) ;
ClassDB : : bind_method ( D_METHOD ( " set_filter_walkable_low_height_spans " , " filter_walkable_low_height_spans " ) , & NavigationMesh : : set_filter_walkable_low_height_spans ) ;
ClassDB : : bind_method ( D_METHOD ( " get_filter_walkable_low_height_spans " ) , & NavigationMesh : : get_filter_walkable_low_height_spans ) ;
2014-08-02 01:10:38 +00:00
2017-03-05 15:44:50 +00:00
ClassDB : : bind_method ( D_METHOD ( " set_vertices " , " vertices " ) , & NavigationMesh : : set_vertices ) ;
ClassDB : : bind_method ( D_METHOD ( " get_vertices " ) , & NavigationMesh : : get_vertices ) ;
2014-08-02 01:10:38 +00:00
2017-03-05 15:44:50 +00:00
ClassDB : : bind_method ( D_METHOD ( " add_polygon " , " polygon " ) , & NavigationMesh : : add_polygon ) ;
ClassDB : : bind_method ( D_METHOD ( " get_polygon_count " ) , & NavigationMesh : : get_polygon_count ) ;
ClassDB : : bind_method ( D_METHOD ( " get_polygon " , " idx " ) , & NavigationMesh : : get_polygon ) ;
ClassDB : : bind_method ( D_METHOD ( " clear_polygons " ) , & NavigationMesh : : clear_polygons ) ;
2014-08-02 01:10:38 +00:00
2017-08-13 18:13:48 +00:00
ClassDB : : bind_method ( D_METHOD ( " create_from_mesh " , " mesh " ) , & NavigationMesh : : create_from_mesh ) ;
2017-03-05 15:44:50 +00:00
ClassDB : : bind_method ( D_METHOD ( " _set_polygons " , " polygons " ) , & NavigationMesh : : _set_polygons ) ;
ClassDB : : bind_method ( D_METHOD ( " _get_polygons " ) , & NavigationMesh : : _get_polygons ) ;
2014-08-02 01:10:38 +00:00
2020-02-17 21:06:54 +00:00
ADD_PROPERTY ( PropertyInfo ( Variant : : PACKED_VECTOR3_ARRAY , " vertices " , PROPERTY_HINT_NONE , " " , PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_INTERNAL ) , " set_vertices " , " get_vertices " ) ;
2018-01-11 22:35:12 +00:00
ADD_PROPERTY ( PropertyInfo ( Variant : : ARRAY , " polygons " , PROPERTY_HINT_NONE , " " , PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_INTERNAL ) , " _set_polygons " , " _get_polygons " ) ;
2017-02-28 12:10:29 +00:00
ADD_PROPERTY ( PropertyInfo ( Variant : : INT , " sample_partition_type/sample_partition_type " , PROPERTY_HINT_ENUM , " Watershed,Monotone,Layers " ) , " set_sample_partition_type " , " get_sample_partition_type " ) ;
2019-05-23 06:37:58 +00:00
ADD_PROPERTY ( PropertyInfo ( Variant : : INT , " geometry/parsed_geometry_type " , PROPERTY_HINT_ENUM , " Mesh Instances,Static Colliders,Both " ) , " set_parsed_geometry_type " , " get_parsed_geometry_type " ) ;
ADD_PROPERTY ( PropertyInfo ( Variant : : INT , " geometry/collision_mask " , PROPERTY_HINT_LAYERS_3D_PHYSICS ) , " set_collision_mask " , " get_collision_mask " ) ;
2019-10-16 09:33:47 +00:00
ADD_PROPERTY ( PropertyInfo ( Variant : : INT , " geometry/source_geometry_mode " , PROPERTY_HINT_ENUM , " Navmesh Children, Group With Children, Group Explicit " ) , " set_source_geometry_mode " , " get_source_geometry_mode " ) ;
ADD_PROPERTY ( PropertyInfo ( Variant : : STRING , " geometry/source_group_name " ) , " set_source_group_name " , " get_source_group_name " ) ;
2017-02-28 12:10:29 +00:00
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-24 18:20:53 +00:00
ADD_PROPERTY ( PropertyInfo ( Variant : : FLOAT , " cell/size " , PROPERTY_HINT_RANGE , " 0.1,1.0,0.01,or_greater " ) , " set_cell_size " , " get_cell_size " ) ;
ADD_PROPERTY ( PropertyInfo ( Variant : : FLOAT , " cell/height " , PROPERTY_HINT_RANGE , " 0.1,1.0,0.01,or_greater " ) , " set_cell_height " , " get_cell_height " ) ;
ADD_PROPERTY ( PropertyInfo ( Variant : : FLOAT , " agent/height " , PROPERTY_HINT_RANGE , " 0.1,5.0,0.01,or_greater " ) , " set_agent_height " , " get_agent_height " ) ;
ADD_PROPERTY ( PropertyInfo ( Variant : : FLOAT , " agent/radius " , PROPERTY_HINT_RANGE , " 0.1,5.0,0.01,or_greater " ) , " set_agent_radius " , " get_agent_radius " ) ;
ADD_PROPERTY ( PropertyInfo ( Variant : : FLOAT , " agent/max_climb " , PROPERTY_HINT_RANGE , " 0.1,5.0,0.01,or_greater " ) , " set_agent_max_climb " , " get_agent_max_climb " ) ;
ADD_PROPERTY ( PropertyInfo ( Variant : : FLOAT , " agent/max_slope " , PROPERTY_HINT_RANGE , " 0.0,90.0,0.1 " ) , " set_agent_max_slope " , " get_agent_max_slope " ) ;
ADD_PROPERTY ( PropertyInfo ( Variant : : FLOAT , " region/min_size " , PROPERTY_HINT_RANGE , " 0.0,150.0,0.01,or_greater " ) , " set_region_min_size " , " get_region_min_size " ) ;
ADD_PROPERTY ( PropertyInfo ( Variant : : FLOAT , " region/merge_size " , PROPERTY_HINT_RANGE , " 0.0,150.0,0.01,or_greater " ) , " set_region_merge_size " , " get_region_merge_size " ) ;
ADD_PROPERTY ( PropertyInfo ( Variant : : FLOAT , " edge/max_length " , PROPERTY_HINT_RANGE , " 0.0,50.0,0.01,or_greater " ) , " set_edge_max_length " , " get_edge_max_length " ) ;
ADD_PROPERTY ( PropertyInfo ( Variant : : FLOAT , " edge/max_error " , PROPERTY_HINT_RANGE , " 0.1,3.0,0.01,or_greater " ) , " set_edge_max_error " , " get_edge_max_error " ) ;
ADD_PROPERTY ( PropertyInfo ( Variant : : FLOAT , " polygon/verts_per_poly " , PROPERTY_HINT_RANGE , " 3.0,12.0,1.0,or_greater " ) , " set_verts_per_poly " , " get_verts_per_poly " ) ;
ADD_PROPERTY ( PropertyInfo ( Variant : : FLOAT , " detail/sample_distance " , PROPERTY_HINT_RANGE , " 0.0,16.0,0.01,or_greater " ) , " set_detail_sample_distance " , " get_detail_sample_distance " ) ;
ADD_PROPERTY ( PropertyInfo ( Variant : : FLOAT , " detail/sample_max_error " , PROPERTY_HINT_RANGE , " 0.0,16.0,0.01,or_greater " ) , " set_detail_sample_max_error " , " get_detail_sample_max_error " ) ;
2017-02-28 12:10:29 +00:00
ADD_PROPERTY ( PropertyInfo ( Variant : : BOOL , " filter/low_hanging_obstacles " ) , " set_filter_low_hanging_obstacles " , " get_filter_low_hanging_obstacles " ) ;
ADD_PROPERTY ( PropertyInfo ( Variant : : BOOL , " filter/ledge_spans " ) , " set_filter_ledge_spans " , " get_filter_ledge_spans " ) ;
ADD_PROPERTY ( PropertyInfo ( Variant : : BOOL , " filter/filter_walkable_low_height_spans " ) , " set_filter_walkable_low_height_spans " , " get_filter_walkable_low_height_spans " ) ;
2021-08-11 08:23:14 +00:00
BIND_ENUM_CONSTANT ( SAMPLE_PARTITION_WATERSHED ) ;
BIND_ENUM_CONSTANT ( SAMPLE_PARTITION_MONOTONE ) ;
BIND_ENUM_CONSTANT ( SAMPLE_PARTITION_LAYERS ) ;
BIND_ENUM_CONSTANT ( SAMPLE_PARTITION_MAX ) ;
BIND_ENUM_CONSTANT ( PARSED_GEOMETRY_MESH_INSTANCES ) ;
BIND_ENUM_CONSTANT ( PARSED_GEOMETRY_STATIC_COLLIDERS ) ;
BIND_ENUM_CONSTANT ( PARSED_GEOMETRY_BOTH ) ;
BIND_ENUM_CONSTANT ( PARSED_GEOMETRY_MAX ) ;
BIND_ENUM_CONSTANT ( SOURCE_GEOMETRY_NAVMESH_CHILDREN ) ;
BIND_ENUM_CONSTANT ( SOURCE_GEOMETRY_GROUPS_WITH_CHILDREN ) ;
BIND_ENUM_CONSTANT ( SOURCE_GEOMETRY_GROUPS_EXPLICIT ) ;
BIND_ENUM_CONSTANT ( SOURCE_GEOMETRY_MAX ) ;
2014-08-02 01:10:38 +00:00
}
2019-05-23 06:37:58 +00:00
void NavigationMesh : : _validate_property ( PropertyInfo & property ) const {
if ( property . name = = " geometry/collision_mask " ) {
if ( parsed_geometry_type = = PARSED_GEOMETRY_MESH_INSTANCES ) {
2021-07-01 01:24:34 +00:00
property . usage = PROPERTY_USAGE_NONE ;
2019-05-23 06:37:58 +00:00
return ;
}
}
2019-10-16 09:33:47 +00:00
if ( property . name = = " geometry/source_group_name " ) {
if ( source_geometry_mode = = SOURCE_GEOMETRY_NAVMESH_CHILDREN ) {
2021-07-01 01:24:34 +00:00
property . usage = PROPERTY_USAGE_NONE ;
2019-10-16 09:33:47 +00:00
return ;
}
}
2019-05-23 06:37:58 +00:00
}
2021-02-09 17:24:36 +00:00
NavigationMesh : : NavigationMesh ( ) { }