Path: blob/master/modules/navigation_3d/nav_region_3d.h
10277 views
/**************************************************************************/1/* nav_region_3d.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 "nav_base_3d.h"33#include "nav_utils_3d.h"3435#include "core/os/rw_lock.h"36#include "scene/resources/navigation_mesh.h"3738#include "3d/nav_region_iteration_3d.h"3940class NavRegion3D : public NavBase3D {41RWLock region_rwlock;4243NavMap3D *map = nullptr;44Transform3D transform;45bool enabled = true;4647bool use_edge_connections = true;4849AABB bounds;5051Ref<NavigationMesh> navmesh;5253Nav3D::PerformanceData performance_data;5455uint32_t iteration_id = 0;5657SelfList<NavRegion3D> sync_dirty_request_list_element;58mutable RWLock iteration_rwlock;59Ref<NavRegionIteration3D> iteration;6061NavRegionIterationBuild3D iteration_build;62bool use_async_iterations = true;63SelfList<NavRegion3D> async_list_element;64WorkerThreadPool::TaskID iteration_build_thread_task_id = WorkerThreadPool::INVALID_TASK_ID;65static void _build_iteration_threaded(void *p_arg);6667bool iteration_dirty = true;68bool iteration_building = false;69bool iteration_ready = false;7071void _build_iteration();72void _sync_iteration();7374public:75NavRegion3D();76~NavRegion3D();7778uint32_t get_iteration_id() const { return iteration_id; }7980void scratch_polygons();8182void set_enabled(bool p_enabled);83bool get_enabled() const { return enabled; }8485void set_map(NavMap3D *p_map);86NavMap3D *get_map() const {87return map;88}8990virtual void set_use_edge_connections(bool p_enabled) override;91virtual bool get_use_edge_connections() const override { return use_edge_connections; }9293void set_transform(Transform3D transform);94const Transform3D &get_transform() const {95return transform;96}9798void set_navigation_mesh(Ref<NavigationMesh> p_navigation_mesh);99Ref<NavigationMesh> get_navigation_mesh() const { return navmesh; }100101LocalVector<Nav3D::Polygon> const &get_polygons() const;102103Vector3 get_closest_point_to_segment(const Vector3 &p_from, const Vector3 &p_to, bool p_use_collision) const;104Nav3D::ClosestPointQueryResult get_closest_point_info(const Vector3 &p_point) const;105Vector3 get_random_point(uint32_t p_navigation_layers, bool p_uniformly) const;106107real_t get_surface_area() const;108AABB get_bounds() const;109110// NavBase properties.111virtual void set_navigation_layers(uint32_t p_navigation_layers) override;112virtual void set_enter_cost(real_t p_enter_cost) override;113virtual void set_travel_cost(real_t p_travel_cost) override;114virtual void set_owner_id(ObjectID p_owner_id) override;115116bool sync();117void request_sync();118void cancel_sync_request();119120void sync_async_tasks();121void request_async_thread_join();122void cancel_async_thread_join();123124Ref<NavRegionIteration3D> get_iteration();125126// Performance Monitor127int get_pm_polygon_count() const { return performance_data.pm_polygon_count; }128int get_pm_edge_count() const { return performance_data.pm_edge_count; }129int get_pm_edge_merge_count() const { return performance_data.pm_edge_merge_count; }130131void set_use_async_iterations(bool p_enabled);132bool get_use_async_iterations() const;133};134135136