// Use this for initialization public void Build() { List <Triangle3> triangles = new List <Triangle3>(); // Get all the triangle provider components attached to this game object var triangleProviders = GetComponents <NavigationTriangleProvider>(); foreach (var triangleProvider in triangleProviders) { triangleProvider.AddNavTriangles(triangles); } if (triangles.Count == 0) { // No geometry exists. Cannot create Debug.Log("No geometry has been added to the nav mesh"); return; } //use the default generation settings var settings = SharpNav.NavMeshGenerationSettings.Default; settings.AgentHeight = agentHeight; settings.AgentRadius = agentRadius; settings.MaxClimb = agentClimbHeight; settings.CellSize = cellSize; navMesh = SharpNav.NavMesh.Generate(triangles, settings, out polyMesh, out polyMeshDetail); SharpNav.TiledNavMesh tiledMesh = navMesh; navMeshQuery = new SharpNav.NavMeshQuery(tiledMesh, 2048); crowd = new Crowd(maxCrowdAgents, agentRadius, ref tiledMesh); BuildVisualization(); }
static void TestNavmesh(SharpNav.TiledNavMesh tmesh) { // Azeroth 28 28 / Deathknell (wow-style coordinates) // Outside church: 1843,734 1604,214 94,55994 // Inside church: 1844,074 1642,581 97,62832 // Outside spawn: 1672,226 1662,989 139,2343 // Inside spawn: 1665,264 1678,277 120,5302 // Outside cave: 2051,3 1807,121 102,5225 // Inside cave: 2082,813 1950,718 98,04765 // Outside house: 1861,465 1582,03 92,79533 // Upstairs house: 1859,929 1560,804 99,07755 var query = new SharpNav.NavMeshQuery(tmesh, 65535); var extents = new SharpNav.Vector3(2.5f, 2.5f, 2.5f); // WoW(X, Y, Z) -> SharpNav(Y, Z, X) -- or so I think :-----D var posStart = new SharpNav.Vector3(1662.9f, 139.2f, 1672.2f); // Outside spawn var posEnd = new SharpNav.Vector3(1678.3f, 120.5f, 1665.3f); // Inside spawn SharpNav.Vector3 aStartPos; int snRef; if (!query.FindNearestPoly(ref posStart, ref extents, out snRef, out aStartPos)) { Console.WriteLine("No start poly"); } //SharpNav.Vector3 rPos; //int rRef; //if (!query.FindRandomPoint(out rRef, out rPos)) // Console.WriteLine("No end poly"); SharpNav.Vector3 aEndPos; int enRef; if (!query.FindNearestPoly(ref posEnd, ref extents, out enRef, out aEndPos)) { Console.WriteLine("No end poly"); } var path = new List <int>(); if (!query.FindPath(snRef, enRef, ref aStartPos, ref aEndPos, path)) { Console.WriteLine("No path"); } //if (!query.FindStraightPath(posStart, posEnd, path.ToArray(), path.Count)) // return; }
public Zone(uint id, string zoneName, ushort regionId, string classPath, ushort bgmDay, ushort bgmNight, ushort bgmBattle, bool isIsolated, bool isInn, bool canRideChocobo, bool canStealth, bool isInstanceRaid, bool loadNavMesh = false) : base(id, zoneName, regionId, classPath, bgmDay, bgmNight, bgmBattle, isIsolated, isInn, canRideChocobo, canStealth, isInstanceRaid) { if (loadNavMesh) { try { tiledNavMesh = utils.NavmeshUtils.LoadNavmesh(tiledNavMesh, zoneName + ".snb"); navMeshQuery = new SharpNav.NavMeshQuery(tiledNavMesh, 100); if (tiledNavMesh != null && tiledNavMesh.Tiles[0].PolyCount > 0) { Program.Log.Info($"Loaded navmesh for {zoneName}"); } } catch (Exception e) { Program.Log.Error(e.Message); } } }