Path: blob/master/modules/navigation_3d/3d/nav_mesh_generator_3d.h
10278 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_server_3d.h"3637class Node;38class NavigationMesh;39class NavigationMeshSourceGeometryData3D;4041class NavMeshGenerator3D : public Object {42static NavMeshGenerator3D *singleton;4344static Mutex baking_navmesh_mutex;45static Mutex generator_task_mutex;4647static RWLock generator_parsers_rwlock;48static LocalVector<NavMeshGeometryParser3D *> generator_parsers;4950static bool use_threads;51static bool baking_use_multiple_threads;52static bool baking_use_high_priority_threads;5354public:55enum NavMeshBakeState {56BAKE_STATE_NONE,57BAKE_STATE_CONFIGURATION,58BAKE_STATE_CALC_GRID_SIZE,59BAKE_STATE_CREATE_HEIGHTFIELD,60BAKE_STATE_MARK_WALKABLE_TRIANGLES,61BAKE_STATE_CONSTRUCT_COMPACT_HEIGHTFIELD,62BAKE_STATE_ERODE_WALKABLE_AREA,63BAKE_STATE_SAMPLE_PARTITIONING,64BAKE_STATE_CREATING_CONTOURS,65BAKE_STATE_CREATING_POLYMESH,66BAKE_STATE_CONVERTING_NATIVE_NAVMESH,67BAKE_STATE_BAKE_CLEANUP,68BAKE_STATE_BAKE_FINISHED,69BAKE_STATE_MAX,70};7172private:73struct NavMeshGeneratorTask3D {74enum TaskStatus {75BAKING_STARTED,76BAKING_FINISHED,77BAKING_FAILED,78CALLBACK_DISPATCHED,79CALLBACK_FAILED,80};8182Ref<NavigationMesh> navigation_mesh;83Ref<NavigationMeshSourceGeometryData3D> source_geometry_data;84Callable callback;85WorkerThreadPool::TaskID thread_task_id = WorkerThreadPool::INVALID_TASK_ID;86NavMeshGeneratorTask3D::TaskStatus status = NavMeshGeneratorTask3D::TaskStatus::BAKING_STARTED;8788NavMeshBakeState bake_state = NavMeshBakeState::BAKE_STATE_NONE;89};9091static HashMap<WorkerThreadPool::TaskID, NavMeshGeneratorTask3D *> generator_tasks;9293static void generator_thread_bake(void *p_arg);9495static HashMap<Ref<NavigationMesh>, NavMeshGeneratorTask3D *> baking_navmeshes;9697static void generator_parse_geometry_node(const Ref<NavigationMesh> &p_navigation_mesh, Ref<NavigationMeshSourceGeometryData3D> p_source_geometry_data, Node *p_node, bool p_recurse_children);98static void generator_parse_source_geometry_data(const Ref<NavigationMesh> &p_navigation_mesh, Ref<NavigationMeshSourceGeometryData3D> p_source_geometry_data, Node *p_root_node);99static void generator_bake_from_source_geometry_data(NavMeshGeneratorTask3D *p_generator_task);100101static bool generator_emit_callback(const Callable &p_callback);102103public:104static NavMeshGenerator3D *get_singleton();105106static void sync();107static void cleanup();108static void finish();109110static void set_generator_parsers(LocalVector<NavMeshGeometryParser3D *> p_parsers);111112static 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());113static void bake_from_source_geometry_data(Ref<NavigationMesh> p_navigation_mesh, Ref<NavigationMeshSourceGeometryData3D> p_source_geometry_data, const Callable &p_callback = Callable());114static void bake_from_source_geometry_data_async(Ref<NavigationMesh> p_navigation_mesh, Ref<NavigationMeshSourceGeometryData3D> p_source_geometry_data, const Callable &p_callback = Callable());115static bool is_baking(Ref<NavigationMesh> p_navigation_mesh);116static String get_baking_state_msg(Ref<NavigationMesh> p_navigation_mesh);117118NavMeshGenerator3D();119~NavMeshGenerator3D();120};121122123