Path: blob/master/scene/resources/2d/navigation_polygon.h
9898 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/navigation_globals.h"3536class NavigationPolygon : public Resource {37GDCLASS(NavigationPolygon, Resource);38RWLock rwlock;3940Vector<Vector2> vertices;41Vector<Vector<int>> polygons;42Vector<Vector<Vector2>> outlines;43Vector<Vector<Vector2>> baked_outlines;4445mutable Rect2 item_rect;46mutable bool rect_cache_dirty = true;4748Mutex navigation_mesh_generation;49// Navigation mesh50Ref<NavigationMesh> navigation_mesh;5152real_t cell_size = NavigationDefaults2D::NAV_MESH_CELL_SIZE;53real_t border_size = 0.0f;5455Rect2 baking_rect;56Vector2 baking_rect_offset;5758protected:59static void _bind_methods();60void _validate_property(PropertyInfo &p_property) const;6162void _set_polygons(const TypedArray<Vector<int32_t>> &p_array);63TypedArray<Vector<int32_t>> _get_polygons() const;6465void _set_outlines(const TypedArray<Vector<Vector2>> &p_array);66TypedArray<Vector<Vector2>> _get_outlines() const;6768public:69#ifdef DEBUG_ENABLED70Rect2 _edit_get_rect() const;71bool _edit_is_selected_on_click(const Point2 &p_point, double p_tolerance) const;72#endif // DEBUG_ENABLED7374enum SamplePartitionType {75SAMPLE_PARTITION_CONVEX_PARTITION = 0,76SAMPLE_PARTITION_TRIANGULATE,77SAMPLE_PARTITION_MAX78};7980enum ParsedGeometryType {81PARSED_GEOMETRY_MESH_INSTANCES = 0,82PARSED_GEOMETRY_STATIC_COLLIDERS,83PARSED_GEOMETRY_BOTH,84PARSED_GEOMETRY_MAX85};8687enum SourceGeometryMode {88SOURCE_GEOMETRY_ROOT_NODE_CHILDREN = 0,89SOURCE_GEOMETRY_GROUPS_WITH_CHILDREN,90SOURCE_GEOMETRY_GROUPS_EXPLICIT,91SOURCE_GEOMETRY_MAX92};9394real_t agent_radius = 10.0f;9596SamplePartitionType partition_type = SAMPLE_PARTITION_CONVEX_PARTITION;97ParsedGeometryType parsed_geometry_type = PARSED_GEOMETRY_BOTH;98uint32_t parsed_collision_mask = 0xFFFFFFFF;99100SourceGeometryMode source_geometry_mode = SOURCE_GEOMETRY_ROOT_NODE_CHILDREN;101StringName source_geometry_group_name = "navigation_polygon_source_geometry_group";102103void set_vertices(const Vector<Vector2> &p_vertices);104Vector<Vector2> get_vertices() const;105106void add_polygon(const Vector<int> &p_polygon);107int get_polygon_count() const;108109void add_outline(const Vector<Vector2> &p_outline);110void add_outline_at_index(const Vector<Vector2> &p_outline, int p_index);111void set_outline(int p_idx, const Vector<Vector2> &p_outline);112Vector<Vector2> get_outline(int p_idx) const;113void remove_outline(int p_idx);114int get_outline_count() const;115void set_outlines(const Vector<Vector<Vector2>> &p_outlines);116Vector<Vector<Vector2>> get_outlines() const;117118void clear_outlines();119#ifndef DISABLE_DEPRECATED120void make_polygons_from_outlines();121#endif // DISABLE_DEPRECATED122123void set_polygons(const Vector<Vector<int>> &p_polygons);124Vector<Vector<int>> get_polygons() const;125Vector<int> get_polygon(int p_idx);126void clear_polygons();127128void set_sample_partition_type(SamplePartitionType p_value);129SamplePartitionType get_sample_partition_type() const;130131void set_parsed_geometry_type(ParsedGeometryType p_geometry_type);132ParsedGeometryType get_parsed_geometry_type() const;133134void set_parsed_collision_mask(uint32_t p_mask);135uint32_t get_parsed_collision_mask() const;136137void set_parsed_collision_mask_value(int p_layer_number, bool p_value);138bool get_parsed_collision_mask_value(int p_layer_number) const;139140void set_source_geometry_mode(SourceGeometryMode p_geometry_mode);141SourceGeometryMode get_source_geometry_mode() const;142143void set_source_geometry_group_name(const StringName &p_group_name);144StringName get_source_geometry_group_name() const;145146void set_agent_radius(real_t p_value);147real_t get_agent_radius() const;148149Ref<NavigationMesh> get_navigation_mesh();150151void set_cell_size(real_t p_cell_size);152real_t get_cell_size() const;153154void set_border_size(real_t p_value);155real_t get_border_size() const;156157void set_baking_rect(const Rect2 &p_rect);158Rect2 get_baking_rect() const;159160void set_baking_rect_offset(const Vector2 &p_rect_offset);161Vector2 get_baking_rect_offset() const;162163void clear();164165void set_data(const Vector<Vector2> &p_vertices, const Vector<Vector<int>> &p_polygons);166void set_data(const Vector<Vector2> &p_vertices, const Vector<Vector<int>> &p_polygons, const Vector<Vector<Vector2>> &p_outlines);167void get_data(Vector<Vector2> &r_vertices, Vector<Vector<int>> &r_polygons);168void get_data(Vector<Vector2> &r_vertices, Vector<Vector<int>> &r_polygons, Vector<Vector<Vector2>> &r_outlines);169};170171VARIANT_ENUM_CAST(NavigationPolygon::SamplePartitionType);172VARIANT_ENUM_CAST(NavigationPolygon::ParsedGeometryType);173VARIANT_ENUM_CAST(NavigationPolygon::SourceGeometryMode);174175176