Skip to content
0.2.0-dev Download ZIP
122 lines ·4.5 KB Raw
1/**************************************************************************/
2/* navigation_region_3d.h */
3/**************************************************************************/
4/* This file is part of: */
5/* GODOT ENGINE */
6/* https://godotengine.org */
7/**************************************************************************/
8/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
9/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
10/* */
11/* Permission is hereby granted, free of charge, to any person obtaining */
12/* a copy of this software and associated documentation files (the */
13/* "Software"), to deal in the Software without restriction, including */
14/* without limitation the rights to use, copy, modify, merge, publish, */
15/* distribute, sublicense, and/or sell copies of the Software, and to */
16/* permit persons to whom the Software is furnished to do so, subject to */
17/* the following conditions: */
18/* */
19/* The above copyright notice and this permission notice shall be */
20/* included in all copies or substantial portions of the Software. */
21/* */
22/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
23/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
24/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
25/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
26/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
27/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
28/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
29/**************************************************************************/
30
31#pragma once
32
33#include "scene/3d/node_3d.h"
34#include "scene/resources/navigation_mesh.h"
35
36class NavigationRegion3D : public Node3D {
37 GDCLASS(NavigationRegion3D, Node3D);
38
39 bool enabled = true;
40 bool use_edge_connections = true;
41
42 RID region;
43 RID map_override;
44 uint32_t navigation_layers = 1;
45 real_t enter_cost = 0.0;
46 real_t travel_cost = 1.0;
47 Ref<NavigationMesh> navigation_mesh;
48
49 void _navigation_mesh_changed();
50
51 AABB bounds;
52
53#ifdef DEBUG_ENABLED
54 RID debug_instance;
55 RID debug_edge_connections_instance;
56 Ref<ArrayMesh> debug_mesh;
57 Ref<ArrayMesh> debug_edge_connections_mesh;
58
59private:
60 void _update_debug_mesh();
61 void _update_debug_edge_connections_mesh();
62 void _navigation_map_changed(RID p_map);
63 void _navigation_debug_changed();
64#endif // DEBUG_ENABLED
65
66protected:
67 void _notification(int p_what);
68 static void _bind_methods();
69
70#ifndef DISABLE_DEPRECATED
71 bool _set(const StringName &p_name, const Variant &p_value);
72 bool _get(const StringName &p_name, Variant &r_ret) const;
73#endif // DISABLE_DEPRECATED
74
75public:
76 RID get_rid() const;
77
78 void set_enabled(bool p_enabled);
79 bool is_enabled() const;
80
81 void set_navigation_map(RID p_navigation_map);
82 RID get_navigation_map() const;
83
84 void set_use_edge_connections(bool p_enabled);
85 bool get_use_edge_connections() const;
86
87 void set_navigation_layers(uint32_t p_navigation_layers);
88 uint32_t get_navigation_layers() const;
89
90 void set_navigation_layer_value(int p_layer_number, bool p_value);
91 bool get_navigation_layer_value(int p_layer_number) const;
92
93 RID get_region_rid() const;
94
95 void set_enter_cost(real_t p_enter_cost);
96 real_t get_enter_cost() const;
97
98 void set_travel_cost(real_t p_travel_cost);
99 real_t get_travel_cost() const;
100
101 void set_navigation_mesh(const Ref<NavigationMesh> &p_navigation_mesh);
102 Ref<NavigationMesh> get_navigation_mesh() const;
103
104 /// Bakes the navigation mesh; once done, automatically
105 /// sets the new navigation mesh and emits a signal
106 void bake_navigation_mesh(bool p_on_thread);
107 void _bake_finished();
108 bool is_baking() const;
109
110 PackedStringArray get_configuration_warnings() const override;
111
112 AABB get_bounds() const { return bounds; }
113
114 NavigationRegion3D();
115 ~NavigationRegion3D();
116
117private:
118 void _update_bounds();
119 void _region_enter_navigation_map();
120 void _region_exit_navigation_map();
121 void _region_update_transform();
122};