Skip to content
This repository has been archived by the owner on Aug 20, 2024. It is now read-only.

Commit

Permalink
snap nodes to collider
Browse files Browse the repository at this point in the history
  • Loading branch information
malytomas committed Feb 12, 2024
1 parent fca8efb commit cfa36dc
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 45 deletions.
2 changes: 1 addition & 1 deletion externals/cage
Submodule cage updated 41 files
+17 −13 sources/include/cage-core/any.h
+1 −1 sources/include/cage-core/entities.h
+0 −2 sources/include/cage-core/entitiesVisitor.h
+6 −3 sources/include/cage-core/events.h
+10 −0 sources/include/cage-core/networkGinnel.h
+2 −0 sources/include/cage-core/networkSteam.h
+7 −2 sources/include/cage-core/networkTcp.h
+3 −2 sources/include/cage-core/networkWebsocket.h
+1 −1 sources/include/cage-core/typeIndex.h
+2 −1 sources/include/cage-engine/core.h
+4 −38 sources/include/cage-engine/guiBuilder.h
+8 −8 sources/include/cage-engine/guiComponents.h
+214 −207 sources/include/cage-engine/inputs.h
+1 −1 sources/include/cage-engine/window.h
+1 −0 sources/include/cage-simple/engine.h
+34 −2 sources/libcore/cage-core.natvis
+17 −2 sources/libcore/events.cpp
+17 −0 sources/libcore/network/ginnel.cpp
+9 −0 sources/libcore/network/steam.cpp
+6 −9 sources/libcore/network/tcp.cpp
+2 −8 sources/libcore/network/websocket.cpp
+3 −1 sources/libcore/profiling.cpp
+31 −25 sources/libengine/gui/events.cpp
+0 −11 sources/libengine/gui/gui.cpp
+1 −1 sources/libengine/gui/guiBuilder.cpp
+0 −20 sources/libengine/gui/items.cpp
+13 −19 sources/libengine/gui/private.h
+1 −1 sources/libengine/gui/tooltips.cpp
+14 −7 sources/libengine/gui/widgets/input.cpp
+0 −2 sources/libengine/gui/widgets/label.cpp
+0 −314 sources/libengine/inputs.cpp
+21 −6 sources/libengine/virtualReality/openxr.cpp
+5 −5 sources/libengine/window/gamepad.cpp
+153 −127 sources/libengine/window/window.cpp
+7 −0 sources/libsimple/externs.cpp
+22 −17 sources/libsimple/fpsCamera.cpp
+12 −12 sources/libsimple/fullscreenSwitcher.cpp
+6 −1 sources/libsimple/gameloop.cpp
+4 −4 sources/libsimple/guiInWorld.cpp
+4 −4 sources/libsimple/statisticsGui.cpp
+1 −11 sources/test-core/installConsistentPaths.cpp
32 changes: 9 additions & 23 deletions sources/generator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ namespace unnatural
Holder<Mesh> meshGenerateBaseWater();
Holder<Mesh> meshGenerateBaseNavigation();
Holder<PointerRange<Holder<Mesh>>> meshSplit(const Holder<Mesh> &mesh);
void meshSimplifyNavmesh(Holder<Mesh> &mesh);
void meshSimplifyCollider(Holder<Mesh> &mesh);
void meshSimplifyNavmesh(Holder<Mesh> &mesh, const Mesh *collider);
void meshSimplifyRender(Holder<Mesh> &mesh);
uint32 meshUnwrap(const Holder<Mesh> &mesh);
void meshSaveDebug(const Holder<Mesh> &mesh, const String &path);
Expand Down Expand Up @@ -92,37 +92,23 @@ namespace unnatural
struct NavmeshProcessor
{
Holder<AsyncTask> taskRef;
Holder<Mesh> base;

void taskNavmesh(uint32)
void processEntry(uint32)
{
Holder<Mesh> navmesh = base->copy();
meshSimplifyNavmesh(navmesh);
Holder<Mesh> navmesh = meshGenerateBaseNavigation();
if (configDebugSaveIntermediate)
meshSaveDebug(navmesh, pathJoin(debugDirectory, "navMeshBase.glb"));
Holder<Mesh> collider = navmesh->copy();
meshSimplifyCollider(collider);
meshSaveCollider(collider);
meshSimplifyNavmesh(navmesh, +collider);
CAGE_LOG(SeverityEnum::Info, "generator", Stringizer() + "navmesh tiles: " + navmesh->verticesCount());
generateTileProperties(navmesh);
meshSaveNavigation(navmesh);
generateStartingPositions();
generateDoodads();
}

void taskCollider(uint32)
{
Holder<Mesh> collider = base->copy();
meshSimplifyCollider(collider);
meshSaveCollider(collider);
}

void processEntry(uint32)
{
base = meshGenerateBaseNavigation();
if (configDebugSaveIntermediate)
meshSaveDebug(base, pathJoin(debugDirectory, "navMeshBase.glb"));
Holder<AsyncTask> tn = tasksRunAsync("navmesh", Delegate<void(uint32)>().bind<NavmeshProcessor, &NavmeshProcessor::taskNavmesh>(this));
Holder<AsyncTask> tc = tasksRunAsync("collider", Delegate<void(uint32)>().bind<NavmeshProcessor, &NavmeshProcessor::taskCollider>(this));
tn->wait();
tc->wait();
}

NavmeshProcessor() { taskRef = tasksRunAsync("navmesh", Delegate<void(uint32)>().bind<NavmeshProcessor, &NavmeshProcessor::processEntry>(this)); }

void wait() { taskRef->wait(); }
Expand Down
46 changes: 26 additions & 20 deletions sources/meshGeneration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,18 +106,42 @@ namespace unnatural
return poly;
}

void meshSimplifyNavmesh(Holder<Mesh> &mesh)
void meshSimplifyCollider(Holder<Mesh> &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<Mesh> 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> &mesh, const Mesh *collider)
{
CAGE_LOG(SeverityEnum::Info, "generator", "regularizing navigation mesh");

if (configNavmeshOptimize)
{
unnatural::NavmeshOptimizeConfig cfg;
cfg.navigation = +mesh;
Holder<Collider> 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
{
Expand All @@ -128,24 +152,6 @@ namespace unnatural
}
}

void meshSimplifyCollider(Holder<Mesh> &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<Mesh> 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> &mesh)
{
CAGE_LOG(SeverityEnum::Info, "generator", "simplifying render mesh");
Expand Down

0 comments on commit cfa36dc

Please sign in to comment.