Path: blob/master/modules/navigation_3d/3d/nav_mesh_generator_3d.h
11354 views
/**************************************************************************/1/* nav_mesh_generator_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 "core/object/class_db.h"33#include "core/object/worker_thread_pool.h"34#include "core/templates/rid_owner.h"35#include "servers/navigation_3d/navigation_server_3d.h"3637class Node;38class NavigationMesh;39class NavigationMeshSourceGeometryData3D;4041class NavMeshGenerator3D : public Object {42GDSOFTCLASS(NavMeshGenerator3D, Object);4344static NavMeshGenerator3D *singleton;4546static Mutex baking_navmesh_mutex;47static Mutex generator_task_mutex;4849static RWLock generator_parsers_rwlock;50static LocalVector<NavMeshGeometryParser3D *> generator_parsers;5152static bool use_threads;53static bool baking_use_multiple_threads;54static bool baking_use_high_priority_threads;5556public:57enum NavMeshBakeState {58BAKE_STATE_NONE,59BAKE_STATE_CONFIGURATION,60BAKE_STATE_CALC_GRID_SIZE,61BAKE_STATE_CREATE_HEIGHTFIELD,62BAKE_STATE_MARK_WALKABLE_TRIANGLES,63BAKE_STATE_CONSTRUCT_COMPACT_HEIGHTFIELD,64BAKE_STATE_ERODE_WALKABLE_AREA,65BAKE_STATE_SAMPLE_PARTITIONING,66BAKE_STATE_CREATING_CONTOURS,67BAKE_STATE_CREATING_POLYMESH,68BAKE_STATE_CONVERTING_NATIVE_NAVMESH,69BAKE_STATE_BAKE_CLEANUP,70BAKE_STATE_BAKE_FINISHED,71BAKE_STATE_MAX,72};7374private:75struct NavMeshGeneratorTask3D {76enum TaskStatus {77BAKING_STARTED,78BAKING_FINISHED,79BAKING_FAILED,80CALLBACK_DISPATCHED,81CALLBACK_FAILED,82};8384Ref<NavigationMesh> navigation_mesh;85Ref<NavigationMeshSourceGeometryData3D> source_geometry_data;86Callable callback;87WorkerThreadPool::TaskID thread_task_id = WorkerThreadPool::INVALID_TASK_ID;88NavMeshGeneratorTask3D::TaskStatus status = NavMeshGeneratorTask3D::TaskStatus::BAKING_STARTED;8990NavMeshBakeState bake_state = NavMeshBakeState::BAKE_STATE_NONE;91};9293static HashMap<WorkerThreadPool::TaskID, NavMeshGeneratorTask3D *> generator_tasks;9495static void generator_thread_bake(void *p_arg);9697static HashMap<Ref<NavigationMesh>, NavMeshGeneratorTask3D *> baking_navmeshes;9899static void generator_parse_geometry_node(const Ref<NavigationMesh> &p_navigation_mesh, Ref<NavigationMeshSourceGeometryData3D> p_source_geometry_data, Node *p_node, bool p_recurse_children);100static void generator_parse_source_geometry_data(const Ref<NavigationMesh> &p_navigation_mesh, Ref<NavigationMeshSourceGeometryData3D> p_source_geometry_data, Node *p_root_node);101static void generator_bake_from_source_geometry_data(NavMeshGeneratorTask3D *p_generator_task);102103static bool generator_emit_callback(const Callable &p_callback);104105public:106static NavMeshGenerator3D *get_singleton();107108static void sync();109static void cleanup();110static void finish();111112static void set_generator_parsers(LocalVector<NavMeshGeometryParser3D *> p_parsers);113114static void parse_source_geometry_data(Ref<NavigationMesh> p_navigation_mesh, Ref<NavigationMeshSourceGeometryData3D> p_source_geometry_data, Node *p_root_node, const Callable &p_callback = Callable());115static void bake_from_source_geometry_data(Ref<NavigationMesh> p_navigation_mesh, Ref<NavigationMeshSourceGeometryData3D> p_source_geometry_data, const Callable &p_callback = Callable());116static void bake_from_source_geometry_data_async(Ref<NavigationMesh> p_navigation_mesh, Ref<NavigationMeshSourceGeometryData3D> p_source_geometry_data, const Callable &p_callback = Callable());117static bool is_baking(Ref<NavigationMesh> p_navigation_mesh);118static String get_baking_state_msg(Ref<NavigationMesh> p_navigation_mesh);119120NavMeshGenerator3D();121~NavMeshGenerator3D();122};123124125