Path: blob/master/scene/resources/2d/navigation_polygon.h
21884 views
/**************************************************************************/1/* navigation_polygon.h */2/**************************************************************************/3/* This file is part of: */4/* GODOT ENGINE */5/* https://godotengine.org */6/**************************************************************************/7/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */8/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */9/* */10/* Permission is hereby granted, free of charge, to any person obtaining */11/* a copy of this software and associated documentation files (the */12/* "Software"), to deal in the Software without restriction, including */13/* without limitation the rights to use, copy, modify, merge, publish, */14/* distribute, sublicense, and/or sell copies of the Software, and to */15/* permit persons to whom the Software is furnished to do so, subject to */16/* the following conditions: */17/* */18/* The above copyright notice and this permission notice shall be */19/* included in all copies or substantial portions of the Software. */20/* */21/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */22/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */23/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */24/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */25/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */26/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */27/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */28/**************************************************************************/2930#pragma once3132#include "scene/2d/node_2d.h"33#include "scene/resources/navigation_mesh.h"34#include "servers/navigation_2d/navigation_constants_2d.h"3536class NavigationPolygon : public Resource {37GDCLASS(NavigationPolygon, Resource);38RWLock rwlock;3940Vector<Vector2> vertices;41Vector<Vector<int>> polygons;42Vector<Vector<Vector2>> outlines;4344mutable Rect2 item_rect;45mutable bool rect_cache_dirty = true;4647Mutex navigation_mesh_generation;48// Navigation mesh49Ref<NavigationMesh> navigation_mesh;5051real_t cell_size = NavigationDefaults2D::NAV_MESH_CELL_SIZE;52real_t border_size = 0.0f;5354Rect2 baking_rect;55Vector2 baking_rect_offset;5657protected:58static void _bind_methods();59void _validate_property(PropertyInfo &p_property) const;6061void _set_polygons(const TypedArray<Vector<int32_t>> &p_array);62TypedArray<Vector<int32_t>> _get_polygons() const;6364void _set_outlines(const TypedArray<Vector<Vector2>> &p_array);65TypedArray<Vector<Vector2>> _get_outlines() const;6667public:68#ifdef DEBUG_ENABLED69Rect2 _edit_get_rect() const;70bool _edit_is_selected_on_click(const Point2 &p_point, double p_tolerance) const;71#endif // DEBUG_ENABLED7273enum SamplePartitionType {74SAMPLE_PARTITION_CONVEX_PARTITION = 0,75SAMPLE_PARTITION_TRIANGULATE,76SAMPLE_PARTITION_MAX77};7879enum ParsedGeometryType {80PARSED_GEOMETRY_MESH_INSTANCES = 0,81PARSED_GEOMETRY_STATIC_COLLIDERS,82PARSED_GEOMETRY_BOTH,83PARSED_GEOMETRY_MAX84};8586enum SourceGeometryMode {87SOURCE_GEOMETRY_ROOT_NODE_CHILDREN = 0,88SOURCE_GEOMETRY_GROUPS_WITH_CHILDREN,89SOURCE_GEOMETRY_GROUPS_EXPLICIT,90SOURCE_GEOMETRY_MAX91};9293real_t agent_radius = 10.0f;9495SamplePartitionType partition_type = SAMPLE_PARTITION_CONVEX_PARTITION;96ParsedGeometryType parsed_geometry_type = PARSED_GEOMETRY_BOTH;97uint32_t parsed_collision_mask = 0xFFFFFFFF;9899SourceGeometryMode source_geometry_mode = SOURCE_GEOMETRY_ROOT_NODE_CHILDREN;100StringName source_geometry_group_name = "navigation_polygon_source_geometry_group";101102void set_vertices(const Vector<Vector2> &p_vertices);103Vector<Vector2> get_vertices() const;104105void add_polygon(const Vector<int> &p_polygon);106int get_polygon_count() const;107108void add_outline(const Vector<Vector2> &p_outline);109void add_outline_at_index(const Vector<Vector2> &p_outline, int p_index);110void set_outline(int p_idx, const Vector<Vector2> &p_outline);111Vector<Vector2> get_outline(int p_idx) const;112void remove_outline(int p_idx);113int get_outline_count() const;114void set_outlines(const Vector<Vector<Vector2>> &p_outlines);115Vector<Vector<Vector2>> get_outlines() const;116117void clear_outlines();118#ifndef DISABLE_DEPRECATED119void make_polygons_from_outlines();120#endif // DISABLE_DEPRECATED121122void set_polygons(const Vector<Vector<int>> &p_polygons);123Vector<Vector<int>> get_polygons() const;124Vector<int> get_polygon(int p_idx);125void clear_polygons();126127void set_sample_partition_type(SamplePartitionType p_value);128SamplePartitionType get_sample_partition_type() const;129130void set_parsed_geometry_type(ParsedGeometryType p_geometry_type);131ParsedGeometryType get_parsed_geometry_type() const;132133void set_parsed_collision_mask(uint32_t p_mask);134uint32_t get_parsed_collision_mask() const;135136void set_parsed_collision_mask_value(int p_layer_number, bool p_value);137bool get_parsed_collision_mask_value(int p_layer_number) const;138139void set_source_geometry_mode(SourceGeometryMode p_geometry_mode);140SourceGeometryMode get_source_geometry_mode() const;141142void set_source_geometry_group_name(const StringName &p_group_name);143StringName get_source_geometry_group_name() const;144145void set_agent_radius(real_t p_value);146real_t get_agent_radius() const;147148Ref<NavigationMesh> get_navigation_mesh();149150void set_cell_size(real_t p_cell_size);151real_t get_cell_size() const;152153void set_border_size(real_t p_value);154real_t get_border_size() const;155156void set_baking_rect(const Rect2 &p_rect);157Rect2 get_baking_rect() const;158159void set_baking_rect_offset(const Vector2 &p_rect_offset);160Vector2 get_baking_rect_offset() const;161162void clear();163164void set_data(const Vector<Vector2> &p_vertices, const Vector<Vector<int>> &p_polygons);165void set_data(const Vector<Vector2> &p_vertices, const Vector<Vector<int>> &p_polygons, const Vector<Vector<Vector2>> &p_outlines);166void get_data(Vector<Vector2> &r_vertices, Vector<Vector<int>> &r_polygons);167void get_data(Vector<Vector2> &r_vertices, Vector<Vector<int>> &r_polygons, Vector<Vector<Vector2>> &r_outlines);168};169170VARIANT_ENUM_CAST(NavigationPolygon::SamplePartitionType);171VARIANT_ENUM_CAST(NavigationPolygon::ParsedGeometryType);172VARIANT_ENUM_CAST(NavigationPolygon::SourceGeometryMode);173174175