diff --git a/externals/cage b/externals/cage index 586b6e7..e960a30 160000 --- a/externals/cage +++ b/externals/cage @@ -1 +1 @@ -Subproject commit 586b6e75ad6a1da686c7ed751eefa510de9f353a +Subproject commit e960a3024738c87f447c63881d33c2de595a917c diff --git a/externals/libnavmesh b/externals/libnavmesh index 33e7843..69101da 160000 --- a/externals/libnavmesh +++ b/externals/libnavmesh @@ -1 +1 @@ -Subproject commit 33e78438d82dfee38c7b1fc70d4cad67e036be2f +Subproject commit 69101da7b6c2a8457c20d3ab4d64e46c2206d8bd diff --git a/sources/generator.cpp b/sources/generator.cpp index f467051..27a920d 100644 --- a/sources/generator.cpp +++ b/sources/generator.cpp @@ -21,8 +21,8 @@ namespace unnatural Holder meshGenerateBaseWater(); Holder meshGenerateBaseNavigation(); Holder>> meshSplit(const Holder &mesh); - void meshSimplifyNavmesh(Holder &mesh); void meshSimplifyCollider(Holder &mesh); + void meshSimplifyNavmesh(Holder &mesh, const Mesh *collider); void meshSimplifyRender(Holder &mesh); uint32 meshUnwrap(const Holder &mesh); void meshSaveDebug(const Holder &mesh, const String &path); @@ -92,12 +92,16 @@ namespace unnatural struct NavmeshProcessor { Holder taskRef; - Holder base; - void taskNavmesh(uint32) + void processEntry(uint32) { - Holder navmesh = base->copy(); - meshSimplifyNavmesh(navmesh); + Holder navmesh = meshGenerateBaseNavigation(); + if (configDebugSaveIntermediate) + meshSaveDebug(navmesh, pathJoin(debugDirectory, "navMeshBase.glb")); + Holder collider = navmesh->copy(); + meshSimplifyCollider(collider); + meshSaveCollider(collider); + meshSimplifyNavmesh(navmesh, +collider); CAGE_LOG(SeverityEnum::Info, "generator", Stringizer() + "navmesh tiles: " + navmesh->verticesCount()); generateTileProperties(navmesh); meshSaveNavigation(navmesh); @@ -105,24 +109,6 @@ namespace unnatural generateDoodads(); } - void taskCollider(uint32) - { - Holder collider = base->copy(); - meshSimplifyCollider(collider); - meshSaveCollider(collider); - } - - void processEntry(uint32) - { - base = meshGenerateBaseNavigation(); - if (configDebugSaveIntermediate) - meshSaveDebug(base, pathJoin(debugDirectory, "navMeshBase.glb")); - Holder tn = tasksRunAsync("navmesh", Delegate().bind(this)); - Holder tc = tasksRunAsync("collider", Delegate().bind(this)); - tn->wait(); - tc->wait(); - } - NavmeshProcessor() { taskRef = tasksRunAsync("navmesh", Delegate().bind(this)); } void wait() { taskRef->wait(); } diff --git a/sources/meshGeneration.cpp b/sources/meshGeneration.cpp index 1c82061..9b83120 100644 --- a/sources/meshGeneration.cpp +++ b/sources/meshGeneration.cpp @@ -106,18 +106,42 @@ namespace unnatural return poly; } - void meshSimplifyNavmesh(Holder &mesh) + void meshSimplifyCollider(Holder &mesh) + { + CAGE_LOG(SeverityEnum::Info, "generator", "simplifying collider mesh"); + + MeshSimplifyConfig cfg; + cfg.iterations = iterations; + cfg.minEdgeLength = 0.15 * tileSize; + cfg.maxEdgeLength = 3 * tileSize; + cfg.approximateError = 0.015 * tileSize; + Holder m = mesh->copy(); + meshSimplify(+m, cfg); + + if (m->indicesCount() <= mesh->indicesCount()) + mesh = std::move(m); + else + CAGE_LOG(SeverityEnum::Warning, "generator", Stringizer() + "the simplified collider mesh has more triangles than the original"); + } + + void meshSimplifyNavmesh(Holder &mesh, const Mesh *collider) { CAGE_LOG(SeverityEnum::Info, "generator", "regularizing navigation mesh"); if (configNavmeshOptimize) { unnatural::NavmeshOptimizeConfig cfg; + cfg.navigation = +mesh; + Holder c = newCollider(); + c->importMesh(collider); + c->optimize(); + c->rebuild(); + cfg.collider = +c; #ifdef CAGE_DEBUG cfg.iterations = 1; #endif cfg.tileSize = tileSize; - mesh = unnatural::navmeshOptimize(std::move(mesh), cfg); + mesh = unnatural::navmeshOptimize(cfg); } else { @@ -128,24 +152,6 @@ namespace unnatural } } - void meshSimplifyCollider(Holder &mesh) - { - CAGE_LOG(SeverityEnum::Info, "generator", "simplifying collider mesh"); - - MeshSimplifyConfig cfg; - cfg.iterations = iterations; - cfg.minEdgeLength = 0.15 * tileSize; - cfg.maxEdgeLength = 3 * tileSize; - cfg.approximateError = 0.015 * tileSize; - Holder m = mesh->copy(); - meshSimplify(+m, cfg); - - if (m->indicesCount() <= mesh->indicesCount()) - mesh = std::move(m); - else - CAGE_LOG(SeverityEnum::Warning, "generator", Stringizer() + "the simplified collider mesh has more triangles than the original"); - } - void meshSimplifyRender(Holder &mesh) { CAGE_LOG(SeverityEnum::Info, "generator", "simplifying render mesh");