Debian Codegraph @

scene/resources/2d/navigation_mesh_source_geometry_data_2d.h

raw symbols SCIP
1 /**************************************************************************/
2 /* navigation_mesh_source_geometry_data_2d.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 "core/io/resource.h"
34 #include "core/os/rw_lock.h"
35
36 class NavigationMeshSourceGeometryData2D : public Resource {
37 friend class NavMeshGenerator2D;
38
39 GDCLASS(NavigationMeshSourceGeometryData2D, Resource);
40 RWLock geometry_rwlock;
41
42 Vector<Vector<Vector2>> traversable_outlines;
43 Vector<Vector<Vector2>> obstruction_outlines;
44
45 Rect2 bounds;
46 bool bounds_dirty = true;
47
48 public:
49 struct ProjectedObstruction;
50
51 private:
52 Vector<ProjectedObstruction> _projected_obstructions;
53
54 protected:
55 bool _set(const StringName &p_name, const Variant &p_value);
56 bool _get(const StringName &p_name, Variant &r_ret) const;
57 static void _bind_methods();
58
59 public:
60 struct ProjectedObstruction {
61 static inline uint32_t VERSION = 1; // Increase when format changes so we can detect outdated formats and provide compatibility.
62
63 Vector<float> vertices;
64 bool carve = false;
65 };
66
67 void _set_traversable_outlines(const Vector<Vector<Vector2>> &p_traversable_outlines);
68 const Vector<Vector<Vector2>> &_get_traversable_outlines() const;
69
70 void _set_obstruction_outlines(const Vector<Vector<Vector2>> &p_obstruction_outlines);
71 const Vector<Vector<Vector2>> &_get_obstruction_outlines() const;
72
73 void _add_traversable_outline(const Vector<Vector2> &p_shape_outline);
74 void _add_obstruction_outline(const Vector<Vector2> &p_shape_outline);
75
76 // kept root node transform here on the geometry data
77 // if we add this transform to all exposed functions we need to break comp on all functions later
78 // when navmesh changes from global transform to relative to navregion
79 // but if it stays here we can just remove it and change the internal functions only
80 Transform2D root_node_transform;
81
82 void set_traversable_outlines(const TypedArray<Vector<Vector2>> &p_traversable_outlines);
83 TypedArray<Vector<Vector2>> get_traversable_outlines() const;
84
85 void set_obstruction_outlines(const TypedArray<Vector<Vector2>> &p_obstruction_outlines);
86 TypedArray<Vector<Vector2>> get_obstruction_outlines() const;
87
88 void append_traversable_outlines(const TypedArray<Vector<Vector2>> &p_traversable_outlines);
89 void append_obstruction_outlines(const TypedArray<Vector<Vector2>> &p_obstruction_outlines);
90
91 void add_traversable_outline(const PackedVector2Array &p_shape_outline);
92 void add_obstruction_outline(const PackedVector2Array &p_shape_outline);
93
94 bool has_data();
95 void clear();
96 void clear_projected_obstructions();
97
98 void add_projected_obstruction(const Vector<Vector2> &p_vertices, bool p_carve);
99 Vector<ProjectedObstruction> _get_projected_obstructions() const;
100
101 void set_projected_obstructions(const Array &p_array);
102 Array get_projected_obstructions() const;
103
104 void merge(const Ref<NavigationMeshSourceGeometryData2D> &p_other_geometry);
105
106 void set_data(const Vector<Vector<Vector2>> &p_traversable_outlines, const Vector<Vector<Vector2>> &p_obstruction_outlines, Vector<ProjectedObstruction> &p_projected_obstructions);
107 void get_data(Vector<Vector<Vector2>> &r_traversable_outlines, Vector<Vector<Vector2>> &r_obstruction_outlines, Vector<ProjectedObstruction> &r_projected_obstructions);
108
109 Rect2 get_bounds();
110
111 ~NavigationMeshSourceGeometryData2D() { clear(); }
112 };