mirror of
https://github.com/Relintai/pandemonium_engine.git
synced 2025-01-13 14:21:11 +01:00
Fix and finally enable PandemoniumNavigationMeshGenerator.
This commit is contained in:
parent
26ff340d47
commit
2296bf693a
@ -7,42 +7,45 @@ env_navigation_mesh_generator = env_modules.Clone()
|
|||||||
|
|
||||||
# Thirdparty source files
|
# Thirdparty source files
|
||||||
|
|
||||||
thirdparty_obj = []
|
#thirdparty_obj = []
|
||||||
|
|
||||||
# Recast Thirdparty source files
|
# Recast Thirdparty source files
|
||||||
if env["builtin_recastnavigation"]:
|
if env["builtin_recast"]:
|
||||||
thirdparty_dir = "#thirdparty/recastnavigation/Recast/"
|
thirdparty_dir = "#thirdparty/recastnavigation/Recast/"
|
||||||
thirdparty_sources = [
|
|
||||||
"Source/Recast.cpp",
|
#thirdparty_sources = [
|
||||||
"Source/RecastAlloc.cpp",
|
# "Source/Recast.cpp",
|
||||||
"Source/RecastArea.cpp",
|
# "Source/RecastAlloc.cpp",
|
||||||
"Source/RecastAssert.cpp",
|
# "Source/RecastArea.cpp",
|
||||||
"Source/RecastContour.cpp",
|
# "Source/RecastAssert.cpp",
|
||||||
"Source/RecastFilter.cpp",
|
# "Source/RecastContour.cpp",
|
||||||
"Source/RecastLayers.cpp",
|
# "Source/RecastFilter.cpp",
|
||||||
"Source/RecastMesh.cpp",
|
# "Source/RecastLayers.cpp",
|
||||||
"Source/RecastMeshDetail.cpp",
|
# "Source/RecastMesh.cpp",
|
||||||
"Source/RecastRasterization.cpp",
|
# "Source/RecastMeshDetail.cpp",
|
||||||
"Source/RecastRegion.cpp",
|
# "Source/RecastRasterization.cpp",
|
||||||
]
|
# "Source/RecastRegion.cpp",
|
||||||
thirdparty_sources = [thirdparty_dir + file for file in thirdparty_sources]
|
#]
|
||||||
|
#thirdparty_sources = [thirdparty_dir + file for file in thirdparty_sources]
|
||||||
|
|
||||||
env_navigation_mesh_generator.Prepend(CPPPATH=[thirdparty_dir + "Include"])
|
env_navigation_mesh_generator.Prepend(CPPPATH=[thirdparty_dir + "Include"])
|
||||||
|
|
||||||
env_thirdparty = env_navigation_mesh_generator.Clone()
|
#env_thirdparty = env_navigation_mesh_generator.Clone()
|
||||||
env_thirdparty.disable_warnings()
|
#env_thirdparty.disable_warnings()
|
||||||
env_thirdparty.add_source_files(thirdparty_obj, thirdparty_sources)
|
#env_thirdparty.add_source_files(thirdparty_obj, thirdparty_sources)
|
||||||
|
|
||||||
env.modules_sources += thirdparty_obj
|
#env.modules_sources += thirdparty_obj
|
||||||
|
|
||||||
# Godot source files
|
# Godot source files
|
||||||
|
|
||||||
module_obj = []
|
module_obj = []
|
||||||
|
|
||||||
env_navigation_mesh_generator.add_source_files(module_obj, "*.cpp")
|
env_navigation_mesh_generator.add_source_files(module_obj, "*.cpp")
|
||||||
if env.editor_build:
|
|
||||||
env_navigation_mesh_generator.add_source_files(module_obj, "editor/*.cpp")
|
#if env.editor_build:
|
||||||
|
# env_navigation_mesh_generator.add_source_files(module_obj, "editor/*.cpp")
|
||||||
|
|
||||||
env.modules_sources += module_obj
|
env.modules_sources += module_obj
|
||||||
|
|
||||||
# Needed to force rebuilding the module files when the thirdparty library is updated.
|
# Needed to force rebuilding the module files when the thirdparty library is updated.
|
||||||
env.Depends(module_obj, thirdparty_obj)
|
#env.Depends(module_obj, thirdparty_obj)
|
||||||
|
@ -1,8 +1,9 @@
|
|||||||
|
|
||||||
|
|
||||||
def can_build(env, platform):
|
def can_build(env, platform):
|
||||||
#return True
|
env.module_add_dependencies("navigation_mesh_generator", ["navigation"], False)
|
||||||
return False
|
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
def configure(env):
|
def configure(env):
|
||||||
|
@ -200,7 +200,7 @@ void PandemoniumNavigationMeshGenerator::_process_2d_parse_tasks() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void PandemoniumNavigationMeshGenerator::_process_2d_bake_cleanup_tasks() {
|
void PandemoniumNavigationMeshGenerator::_process_2d_bake_cleanup_tasks() {
|
||||||
for (int i = 0; i < _2d_running_jobs.size(); ++i) {
|
for (uint32_t i = 0; i < _2d_running_jobs.size(); ++i) {
|
||||||
Ref<NavigationGeneratorTask2D> &e = _2d_running_jobs[i];
|
Ref<NavigationGeneratorTask2D> &e = _2d_running_jobs[i];
|
||||||
|
|
||||||
if (e->get_complete()) {
|
if (e->get_complete()) {
|
||||||
@ -298,8 +298,8 @@ void PandemoniumNavigationMeshGenerator::_static_parse_2d_source_geometry_data(R
|
|||||||
p_source_geometry_data->clear();
|
p_source_geometry_data->clear();
|
||||||
p_source_geometry_data->root_node_transform = root_node_transform;
|
p_source_geometry_data->root_node_transform = root_node_transform;
|
||||||
|
|
||||||
for (Node *E : parse_nodes) {
|
for (List<Node *>::Element *E = parse_nodes.front(); E; E = E->next()) {
|
||||||
_static_parse_2d_geometry_node(p_navigation_polygon, E, p_source_geometry_data, recurse_children, p_geometry_2d_parsers);
|
_static_parse_2d_geometry_node(p_navigation_polygon, E->get(), p_source_geometry_data, recurse_children, p_geometry_2d_parsers);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -608,7 +608,7 @@ void PandemoniumNavigationMeshGenerator::_process_3d_parse_tasks() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void PandemoniumNavigationMeshGenerator::_process_3d_bake_cleanup_tasks() {
|
void PandemoniumNavigationMeshGenerator::_process_3d_bake_cleanup_tasks() {
|
||||||
for (int i = 0; i < _3d_running_jobs.size(); ++i) {
|
for (uint32_t i = 0; i < _3d_running_jobs.size(); ++i) {
|
||||||
Ref<NavigationGeneratorTask3D> &e = _3d_running_jobs[i];
|
Ref<NavigationGeneratorTask3D> &e = _3d_running_jobs[i];
|
||||||
|
|
||||||
if (e->get_complete()) {
|
if (e->get_complete()) {
|
||||||
@ -629,8 +629,8 @@ void PandemoniumNavigationMeshGenerator::_static_bake_3d_from_source_geometry_da
|
|||||||
}
|
}
|
||||||
|
|
||||||
#ifndef _3D_DISABLED
|
#ifndef _3D_DISABLED
|
||||||
const Vector<float> vertices = p_source_geometry_data->get_vertices();
|
PoolRealArray vertices = p_source_geometry_data->get_vertices();
|
||||||
const Vector<int> indices = p_source_geometry_data->get_indices();
|
PoolIntArray indices = p_source_geometry_data->get_indices();
|
||||||
|
|
||||||
if (vertices.size() < 3 || indices.size() < 3) {
|
if (vertices.size() < 3 || indices.size() < 3) {
|
||||||
return;
|
return;
|
||||||
@ -648,9 +648,11 @@ void PandemoniumNavigationMeshGenerator::_static_bake_3d_from_source_geometry_da
|
|||||||
|
|
||||||
bake_state = "Setting up Configuration..."; // step #1
|
bake_state = "Setting up Configuration..."; // step #1
|
||||||
|
|
||||||
const float *verts = vertices.ptr();
|
PoolRealArray::Read vertices_read = vertices.read();
|
||||||
|
PoolIntArray::Read indices_read = indices.read();
|
||||||
|
const float *verts = vertices_read.ptr();
|
||||||
const int nverts = vertices.size() / 3;
|
const int nverts = vertices.size() / 3;
|
||||||
const int *tris = indices.ptr();
|
const int *tris = indices_read.ptr();
|
||||||
const int ntris = indices.size() / 3;
|
const int ntris = indices.size() / 3;
|
||||||
|
|
||||||
float bmin[3], bmax[3];
|
float bmin[3], bmax[3];
|
||||||
@ -669,7 +671,7 @@ void PandemoniumNavigationMeshGenerator::_static_bake_3d_from_source_geometry_da
|
|||||||
cfg.maxSimplificationError = p_navigation_mesh->get_edge_max_error();
|
cfg.maxSimplificationError = p_navigation_mesh->get_edge_max_error();
|
||||||
cfg.minRegionArea = (int)(p_navigation_mesh->get_region_min_size() * p_navigation_mesh->get_region_min_size());
|
cfg.minRegionArea = (int)(p_navigation_mesh->get_region_min_size() * p_navigation_mesh->get_region_min_size());
|
||||||
cfg.mergeRegionArea = (int)(p_navigation_mesh->get_region_merge_size() * p_navigation_mesh->get_region_merge_size());
|
cfg.mergeRegionArea = (int)(p_navigation_mesh->get_region_merge_size() * p_navigation_mesh->get_region_merge_size());
|
||||||
cfg.maxVertsPerPoly = (int)p_navigation_mesh->get_vertices_per_polygon();
|
cfg.maxVertsPerPoly = (int)p_navigation_mesh->get_verts_per_poly();
|
||||||
cfg.detailSampleDist = MAX(p_navigation_mesh->get_cell_size() * p_navigation_mesh->get_detail_sample_distance(), 0.1f);
|
cfg.detailSampleDist = MAX(p_navigation_mesh->get_cell_size() * p_navigation_mesh->get_detail_sample_distance(), 0.1f);
|
||||||
cfg.detailSampleMaxError = p_navigation_mesh->get_cell_height() * p_navigation_mesh->get_detail_sample_max_error();
|
cfg.detailSampleMaxError = p_navigation_mesh->get_cell_height() * p_navigation_mesh->get_detail_sample_max_error();
|
||||||
|
|
||||||
@ -681,7 +683,7 @@ void PandemoniumNavigationMeshGenerator::_static_bake_3d_from_source_geometry_da
|
|||||||
cfg.bmax[2] = bmax[2];
|
cfg.bmax[2] = bmax[2];
|
||||||
|
|
||||||
AABB baking_aabb = p_navigation_mesh->get_filter_baking_aabb();
|
AABB baking_aabb = p_navigation_mesh->get_filter_baking_aabb();
|
||||||
if (baking_aabb.has_volume()) {
|
if (!baking_aabb.has_no_volume()) {
|
||||||
Vector3 baking_aabb_offset = p_navigation_mesh->get_filter_baking_aabb_offset();
|
Vector3 baking_aabb_offset = p_navigation_mesh->get_filter_baking_aabb_offset();
|
||||||
cfg.bmin[0] = baking_aabb.position[0] + baking_aabb_offset.x;
|
cfg.bmin[0] = baking_aabb.position[0] + baking_aabb_offset.x;
|
||||||
cfg.bmin[1] = baking_aabb.position[1] + baking_aabb_offset.y;
|
cfg.bmin[1] = baking_aabb.position[1] + baking_aabb_offset.y;
|
||||||
@ -775,7 +777,7 @@ void PandemoniumNavigationMeshGenerator::_static_bake_3d_from_source_geometry_da
|
|||||||
|
|
||||||
bake_state = "Converting to native navigation mesh..."; // step #10
|
bake_state = "Converting to native navigation mesh..."; // step #10
|
||||||
|
|
||||||
Vector<Vector3> new_navigation_mesh_vertices;
|
PoolVector<Vector3> new_navigation_mesh_vertices;
|
||||||
Vector<Vector<int>> new_navigation_mesh_polygons;
|
Vector<Vector<int>> new_navigation_mesh_polygons;
|
||||||
|
|
||||||
for (int i = 0; i < detail_mesh->nverts; i++) {
|
for (int i = 0; i < detail_mesh->nverts; i++) {
|
||||||
@ -801,7 +803,7 @@ void PandemoniumNavigationMeshGenerator::_static_bake_3d_from_source_geometry_da
|
|||||||
}
|
}
|
||||||
|
|
||||||
p_navigation_mesh->set_vertices(new_navigation_mesh_vertices);
|
p_navigation_mesh->set_vertices(new_navigation_mesh_vertices);
|
||||||
p_navigation_mesh->internal_set_polygons(new_navigation_mesh_polygons);
|
p_navigation_mesh->set_polygons(new_navigation_mesh_polygons);
|
||||||
|
|
||||||
bake_state = "Cleanup..."; // step #11
|
bake_state = "Cleanup..."; // step #11
|
||||||
|
|
||||||
@ -831,11 +833,11 @@ void PandemoniumNavigationMeshGenerator::_static_bake_3d_from_source_geometry_da
|
|||||||
}
|
}
|
||||||
|
|
||||||
void PandemoniumNavigationMeshGenerator::parse_and_bake_3d(Ref<NavigationMesh> p_navigation_mesh, Node *p_root_node, Ref<FuncRef> p_callback) {
|
void PandemoniumNavigationMeshGenerator::parse_and_bake_3d(Ref<NavigationMesh> p_navigation_mesh, Node *p_root_node, Ref<FuncRef> p_callback) {
|
||||||
ERR_FAIL_COND_MSG(baking_navmeshes.find(p_navigation_mesh) >= 0, "NavigationMesh was already added to baking queue. Wait for current bake task to finish.");
|
ERR_FAIL_COND_MSG(_baking_navmeshes.find(p_navigation_mesh) >= 0, "NavigationMesh was already added to baking queue. Wait for current bake task to finish.");
|
||||||
ERR_FAIL_COND_MSG(p_root_node == nullptr, "avigationMesh requires a valid root node.");
|
ERR_FAIL_COND_MSG(p_root_node == nullptr, "avigationMesh requires a valid root node.");
|
||||||
|
|
||||||
_generator_mutex.lock();
|
_generator_mutex.lock();
|
||||||
baking_navmeshes.push_back(p_navigation_mesh);
|
_baking_navmeshes.push_back(p_navigation_mesh);
|
||||||
_generator_mutex.unlock();
|
_generator_mutex.unlock();
|
||||||
|
|
||||||
Ref<NavigationGeneratorTask3D> navigation_generator_task;
|
Ref<NavigationGeneratorTask3D> navigation_generator_task;
|
||||||
@ -882,7 +884,7 @@ Ref<NavigationMeshSourceGeometryData3D> PandemoniumNavigationMeshGenerator::pars
|
|||||||
|
|
||||||
Ref<NavigationMeshSourceGeometryData3D> source_geometry_data = Ref<NavigationMeshSourceGeometryData3D>(memnew(NavigationMeshSourceGeometryData3D));
|
Ref<NavigationMeshSourceGeometryData3D> source_geometry_data = Ref<NavigationMeshSourceGeometryData3D>(memnew(NavigationMeshSourceGeometryData3D));
|
||||||
|
|
||||||
_static_parse_3d_source_geometry_data(p_navigation_mesh, p_root_node, source_geometry_data, geometry_3d_parsers);
|
_static_parse_3d_source_geometry_data(p_navigation_mesh, p_root_node, source_geometry_data, _geometry_3d_parsers);
|
||||||
|
|
||||||
return source_geometry_data;
|
return source_geometry_data;
|
||||||
};
|
};
|
||||||
@ -942,8 +944,8 @@ void PandemoniumNavigationMeshGenerator::_static_parse_3d_source_geometry_data(R
|
|||||||
p_source_geometry_data->clear();
|
p_source_geometry_data->clear();
|
||||||
p_source_geometry_data->root_node_transform = root_node_transform;
|
p_source_geometry_data->root_node_transform = root_node_transform;
|
||||||
|
|
||||||
for (Node *E : parse_nodes) {
|
for (List<Node *>::Element *E = parse_nodes.front(); E; E = E->next()) {
|
||||||
_static_parse_3d_geometry_node(p_navigation_mesh, E, p_source_geometry_data, recurse_children, p_geometry_3d_parsers);
|
_static_parse_3d_geometry_node(p_navigation_mesh, E->get(), p_source_geometry_data, recurse_children, p_geometry_3d_parsers);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif // _3D_DISABLED
|
#endif // _3D_DISABLED
|
||||||
|
@ -45,6 +45,8 @@ class NavigationMeshSourceGeometryData3D;
|
|||||||
class NavigationGeometryParser3D;
|
class NavigationGeometryParser3D;
|
||||||
|
|
||||||
class PandemoniumNavigationMeshGenerator : public NavigationMeshGenerator {
|
class PandemoniumNavigationMeshGenerator : public NavigationMeshGenerator {
|
||||||
|
GDCLASS(PandemoniumNavigationMeshGenerator, NavigationMeshGenerator);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// ======= TASKS =======
|
// ======= TASKS =======
|
||||||
|
|
||||||
@ -145,6 +147,9 @@ public:
|
|||||||
virtual bool is_navigation_mesh_baking(Ref<NavigationMesh> p_navigation_mesh) const;
|
virtual bool is_navigation_mesh_baking(Ref<NavigationMesh> p_navigation_mesh) const;
|
||||||
#endif // _3D_DISABLED
|
#endif // _3D_DISABLED
|
||||||
|
|
||||||
|
PandemoniumNavigationMeshGenerator();
|
||||||
|
~PandemoniumNavigationMeshGenerator();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void _process_2d_tasks();
|
void _process_2d_tasks();
|
||||||
void _process_2d_parse_tasks();
|
void _process_2d_parse_tasks();
|
||||||
@ -156,9 +161,6 @@ private:
|
|||||||
void _process_3d_bake_cleanup_tasks();
|
void _process_3d_bake_cleanup_tasks();
|
||||||
#endif // _3D_DISABLED
|
#endif // _3D_DISABLED
|
||||||
|
|
||||||
PandemoniumNavigationMeshGenerator();
|
|
||||||
~PandemoniumNavigationMeshGenerator();
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Mutex _generator_mutex;
|
Mutex _generator_mutex;
|
||||||
|
|
||||||
|
@ -618,7 +618,7 @@ void NavigationMesh::_bind_methods() {
|
|||||||
BIND_ENUM_CONSTANT(PARSED_GEOMETRY_BOTH);
|
BIND_ENUM_CONSTANT(PARSED_GEOMETRY_BOTH);
|
||||||
BIND_ENUM_CONSTANT(PARSED_GEOMETRY_MAX);
|
BIND_ENUM_CONSTANT(PARSED_GEOMETRY_MAX);
|
||||||
|
|
||||||
BIND_ENUM_CONSTANT(SOURCE_GEOMETRY_NAVMESH_CHILDREN);
|
BIND_ENUM_CONSTANT(SOURCE_GEOMETRY_ROOT_NODE_CHILDREN);
|
||||||
BIND_ENUM_CONSTANT(SOURCE_GEOMETRY_GROUPS_WITH_CHILDREN);
|
BIND_ENUM_CONSTANT(SOURCE_GEOMETRY_GROUPS_WITH_CHILDREN);
|
||||||
BIND_ENUM_CONSTANT(SOURCE_GEOMETRY_GROUPS_EXPLICIT);
|
BIND_ENUM_CONSTANT(SOURCE_GEOMETRY_GROUPS_EXPLICIT);
|
||||||
BIND_ENUM_CONSTANT(SOURCE_GEOMETRY_MAX);
|
BIND_ENUM_CONSTANT(SOURCE_GEOMETRY_MAX);
|
||||||
@ -633,7 +633,7 @@ void NavigationMesh::_validate_property(PropertyInfo &property) const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (property.name == "geometry/source_group_name") {
|
if (property.name == "geometry/source_group_name") {
|
||||||
if (source_geometry_mode == SOURCE_GEOMETRY_NAVMESH_CHILDREN) {
|
if (source_geometry_mode == SOURCE_GEOMETRY_ROOT_NODE_CHILDREN) {
|
||||||
property.usage = 0;
|
property.usage = 0;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -658,7 +658,7 @@ NavigationMesh::NavigationMesh() {
|
|||||||
partition_type = SAMPLE_PARTITION_WATERSHED;
|
partition_type = SAMPLE_PARTITION_WATERSHED;
|
||||||
parsed_geometry_type = PARSED_GEOMETRY_MESH_INSTANCES;
|
parsed_geometry_type = PARSED_GEOMETRY_MESH_INSTANCES;
|
||||||
collision_mask = 0xFFFFFFFF;
|
collision_mask = 0xFFFFFFFF;
|
||||||
source_geometry_mode = SOURCE_GEOMETRY_NAVMESH_CHILDREN;
|
source_geometry_mode = SOURCE_GEOMETRY_ROOT_NODE_CHILDREN;
|
||||||
source_group_name = "navmesh";
|
source_group_name = "navmesh";
|
||||||
filter_low_hanging_obstacles = false;
|
filter_low_hanging_obstacles = false;
|
||||||
filter_ledge_spans = false;
|
filter_ledge_spans = false;
|
||||||
|
@ -56,7 +56,7 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
enum SourceGeometryMode {
|
enum SourceGeometryMode {
|
||||||
SOURCE_GEOMETRY_NAVMESH_CHILDREN = 0,
|
SOURCE_GEOMETRY_ROOT_NODE_CHILDREN = 0,
|
||||||
SOURCE_GEOMETRY_GROUPS_WITH_CHILDREN,
|
SOURCE_GEOMETRY_GROUPS_WITH_CHILDREN,
|
||||||
SOURCE_GEOMETRY_GROUPS_EXPLICIT,
|
SOURCE_GEOMETRY_GROUPS_EXPLICIT,
|
||||||
SOURCE_GEOMETRY_MAX
|
SOURCE_GEOMETRY_MAX
|
||||||
|
Loading…
Reference in New Issue
Block a user