2022-03-17 22:57:56 +01:00
|
|
|
#ifndef NAVIGATION_POLYGON_H
|
|
|
|
#define NAVIGATION_POLYGON_H
|
2022-03-15 13:29:32 +01:00
|
|
|
/*************************************************************************/
|
|
|
|
/* navigation_polygon.h */
|
|
|
|
/*************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
|
|
|
/* https://godotengine.org */
|
|
|
|
/*************************************************************************/
|
|
|
|
/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
|
|
|
|
/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
|
|
|
|
/* */
|
|
|
|
/* 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. */
|
|
|
|
/*************************************************************************/
|
|
|
|
|
2022-08-17 13:45:14 +02:00
|
|
|
#include "core/object/resource.h"
|
2022-03-15 13:29:32 +01:00
|
|
|
#include "scene/2d/node_2d.h"
|
2022-03-16 20:29:43 +01:00
|
|
|
|
|
|
|
class NavigationMesh;
|
2022-03-15 13:29:32 +01:00
|
|
|
|
|
|
|
class NavigationPolygon : public Resource {
|
|
|
|
GDCLASS(NavigationPolygon, Resource);
|
|
|
|
|
2023-06-05 14:13:02 +02:00
|
|
|
public:
|
|
|
|
enum ParsedGeometryType {
|
|
|
|
PARSED_GEOMETRY_MESH_INSTANCES = 0,
|
|
|
|
PARSED_GEOMETRY_STATIC_COLLIDERS,
|
|
|
|
PARSED_GEOMETRY_BOTH,
|
|
|
|
PARSED_GEOMETRY_MAX
|
|
|
|
};
|
|
|
|
|
|
|
|
enum SourceGeometryMode {
|
|
|
|
SOURCE_GEOMETRY_ROOT_NODE_CHILDREN = 0,
|
|
|
|
SOURCE_GEOMETRY_GROUPS_WITH_CHILDREN,
|
|
|
|
SOURCE_GEOMETRY_GROUPS_EXPLICIT,
|
|
|
|
SOURCE_GEOMETRY_MAX
|
|
|
|
};
|
|
|
|
|
|
|
|
enum PolygonFillRule {
|
|
|
|
POLYGON_FILLRULE_EVENODD = 0,
|
|
|
|
POLYGON_FILLRULE_NONZERO,
|
|
|
|
POLYGON_FILLRULE_POSITIVE,
|
|
|
|
POLYGON_FILLRULE_NEGATIVE,
|
|
|
|
POLYGON_FILLRULE_MAX
|
|
|
|
};
|
|
|
|
|
|
|
|
enum OffsettingJoinType {
|
|
|
|
OFFSETTING_JOINTYPE_SQUARE = 0,
|
|
|
|
OFFSETTING_JOINTYPE_ROUND,
|
|
|
|
OFFSETTING_JOINTYPE_MITER,
|
|
|
|
OFFSETTING_JOINTYPE_MAX
|
|
|
|
};
|
|
|
|
|
2022-03-15 13:29:32 +01:00
|
|
|
public:
|
|
|
|
#ifdef TOOLS_ENABLED
|
|
|
|
Rect2 _edit_get_rect() const;
|
|
|
|
bool _edit_is_selected_on_click(const Point2 &p_point, double p_tolerance) const;
|
|
|
|
#endif
|
|
|
|
|
2023-06-05 14:13:02 +02:00
|
|
|
void set_parsed_geometry_type(ParsedGeometryType p_value);
|
|
|
|
ParsedGeometryType get_parsed_geometry_type() const;
|
|
|
|
|
|
|
|
void set_collision_mask(uint32_t p_mask);
|
|
|
|
uint32_t get_collision_mask() const;
|
|
|
|
|
|
|
|
void set_collision_mask_value(int p_layer_number, bool p_value);
|
|
|
|
bool get_collision_mask_value(int p_layer_number) const;
|
|
|
|
|
|
|
|
void set_source_geometry_mode(SourceGeometryMode p_geometry_mode);
|
|
|
|
SourceGeometryMode get_source_geometry_mode() const;
|
|
|
|
|
|
|
|
void set_source_group_name(StringName p_group_name);
|
|
|
|
StringName get_source_group_name() const;
|
|
|
|
|
|
|
|
void set_polygon_bake_fillrule(PolygonFillRule p_polygon_fillrule);
|
|
|
|
PolygonFillRule get_polygon_bake_fillrule() const;
|
|
|
|
|
|
|
|
void set_offsetting_jointype(OffsettingJoinType p_offsetting_jointype);
|
|
|
|
OffsettingJoinType get_offsetting_jointype() const;
|
|
|
|
|
|
|
|
void set_agent_radius(real_t p_value);
|
|
|
|
real_t get_agent_radius() const;
|
|
|
|
|
2022-03-15 13:29:32 +01:00
|
|
|
void set_vertices(const PoolVector<Vector2> &p_vertices);
|
|
|
|
PoolVector<Vector2> get_vertices() const;
|
|
|
|
|
|
|
|
void add_polygon(const Vector<int> &p_polygon);
|
2023-06-05 14:13:02 +02:00
|
|
|
Vector<int> get_polygon(int p_idx);
|
2022-03-15 13:29:32 +01:00
|
|
|
int get_polygon_count() const;
|
|
|
|
|
2023-06-05 14:13:02 +02:00
|
|
|
void clear_polygons();
|
|
|
|
void clear_outlines();
|
|
|
|
void clear_baked_outlines();
|
|
|
|
void clear();
|
|
|
|
void commit_changes();
|
|
|
|
|
2022-03-15 13:29:32 +01:00
|
|
|
void add_outline(const PoolVector<Vector2> &p_outline);
|
|
|
|
void add_outline_at_index(const PoolVector<Vector2> &p_outline, int p_index);
|
|
|
|
void set_outline(int p_idx, const PoolVector<Vector2> &p_outline);
|
|
|
|
PoolVector<Vector2> get_outline(int p_idx) const;
|
|
|
|
void remove_outline(int p_idx);
|
|
|
|
int get_outline_count() const;
|
|
|
|
|
|
|
|
void make_polygons_from_outlines();
|
|
|
|
|
2023-06-05 14:13:02 +02:00
|
|
|
RID get_rid() const;
|
2022-03-15 13:29:32 +01:00
|
|
|
|
2023-06-05 14:13:02 +02:00
|
|
|
Ref<NavigationMesh> get_navigation_mesh();
|
2022-03-15 13:29:32 +01:00
|
|
|
|
2023-06-05 14:13:02 +02:00
|
|
|
void set_polygons(const Vector<Vector<int>> &p_array);
|
|
|
|
Vector<Vector<int>> get_polygons() const;
|
|
|
|
|
|
|
|
void set_outlines(const Vector<PoolVector<Vector2>> &p_array);
|
|
|
|
Vector<PoolVector<Vector2>> get_outlines() const;
|
|
|
|
|
|
|
|
void set_baked_outlines(const Vector<PoolVector<Vector2>> &p_array);
|
|
|
|
Vector<PoolVector<Vector2>> get_baked_outlines() const;
|
2023-06-05 12:44:49 +02:00
|
|
|
|
|
|
|
void _set_polygons(const Array &p_array);
|
|
|
|
Array _get_polygons() const;
|
|
|
|
|
|
|
|
void _set_outlines(const Array &p_array);
|
|
|
|
Array _get_outlines() const;
|
|
|
|
|
2023-06-05 14:13:02 +02:00
|
|
|
void _set_baked_outlines(const Array &p_array);
|
|
|
|
Array _get_baked_outlines() const;
|
|
|
|
|
|
|
|
NavigationPolygon();
|
|
|
|
~NavigationPolygon();
|
|
|
|
|
|
|
|
protected:
|
|
|
|
void _validate_property(PropertyInfo &p_property) const;
|
2023-06-05 12:44:49 +02:00
|
|
|
static void _bind_methods();
|
|
|
|
|
|
|
|
private:
|
2023-06-05 14:13:02 +02:00
|
|
|
RID navmesh_rid;
|
|
|
|
|
|
|
|
real_t agent_radius;
|
|
|
|
|
|
|
|
ParsedGeometryType parsed_geometry_type;
|
|
|
|
uint32_t collision_mask;
|
|
|
|
|
|
|
|
SourceGeometryMode source_geometry_mode;
|
|
|
|
StringName source_group_name;
|
|
|
|
|
|
|
|
PolygonFillRule polygon_bake_fillrule;
|
|
|
|
OffsettingJoinType offsetting_jointype;
|
|
|
|
|
|
|
|
bool navigation_polygon_dirty;
|
|
|
|
|
2023-06-05 12:44:49 +02:00
|
|
|
PoolVector<Vector2> vertices;
|
2023-06-05 12:48:57 +02:00
|
|
|
Vector<Vector<int>> polygons;
|
2023-06-05 12:44:49 +02:00
|
|
|
Vector<PoolVector<Vector2>> outlines;
|
2023-06-05 14:13:02 +02:00
|
|
|
Vector<PoolVector<Vector2>> baked_outlines;
|
2023-06-05 12:44:49 +02:00
|
|
|
|
|
|
|
mutable Rect2 item_rect;
|
|
|
|
mutable bool rect_cache_dirty;
|
|
|
|
|
2023-06-05 14:13:02 +02:00
|
|
|
Ref<NavigationMesh> navigation_mesh;
|
2022-03-15 13:29:32 +01:00
|
|
|
};
|
|
|
|
|
2023-06-05 14:13:02 +02:00
|
|
|
VARIANT_ENUM_CAST(NavigationPolygon::ParsedGeometryType);
|
|
|
|
VARIANT_ENUM_CAST(NavigationPolygon::SourceGeometryMode);
|
|
|
|
VARIANT_ENUM_CAST(NavigationPolygon::PolygonFillRule);
|
|
|
|
VARIANT_ENUM_CAST(NavigationPolygon::OffsettingJoinType);
|
|
|
|
|
2022-03-15 13:29:32 +01:00
|
|
|
#endif // NAVIGATIONPOLYGON_H
|