Ejemplo n.º 1
0
        private float be_fast_work(RecastContext ctx, NavMesh navMesh)
        {
            var navMeshQuery = ctx.CreateNavMeshQuery(navMesh);

            const int N         = 10000;
            var       NRan      = 0;
            var       stopwatch = Stopwatch.StartNew();

            stopwatch.Stop();
            for (var i = 0; i < N; i++)
            {
                var pointA = FindRandomPointSafer(ctx, navMeshQuery);
                var pointB = FindRandomPointSafer(ctx, navMeshQuery);
                var result = FindPathSafer(pointA, pointB, ctx, navMeshQuery, stopwatch);
                if (Success(result.status))
                {
                    var smoothResult = ctx.FindSmoothPath(navMeshQuery, navMesh, result, pointA, pointB);

                    if (!PartialResult(result.status))
                    {
                        Assert.GreaterOrEqual(smoothResult.pathCount, result.pathCount,
                                              $"smoothResult.pathCount [{smoothResult.pathCount}] < result.pathCount [{result.pathCount}]. PointA = {pointA}, PointB={pointB}");
                    }
                }
                NRan++;
            }

            float avg = (float)stopwatch.ElapsedMilliseconds / NRan;

            Console.WriteLine($"\nAverage time (ms) for {NRan} run(s): {avg}");
            return(avg);
        }
Ejemplo n.º 2
0
        public void handle_partial_result()
        {
            using (var ctx = new RecastContext())
            {
                var navMesh      = LoadNavMeshBinFile(ctx);
                var navMeshQuery = ctx.CreateNavMeshQuery(navMesh);

                var stopwatch = Stopwatch.StartNew();
                var pointA    = new PolyPointResult
                {
                    status  = 1073741824,
                    point   = new[] { -373.413f, 107.4798f, -271.1656f },
                    polyRef = 281474994536448
                };
                var pointB = new PolyPointResult
                {
                    status  = 1073741824,
                    point   = new[] { -370.4435f, 100.7469f, -221.2217f },
                    polyRef = 281475063742464
                };
                var result       = FindPathSafer(pointA, pointB, ctx, navMeshQuery, stopwatch);
                var smoothResult = ctx.FindSmoothPath(navMeshQuery, navMesh, result, pointA, pointB);

                Assert.AreEqual(5, result.pathCount);
                Assert.True(PartialResult(result.status));
                Assert.AreEqual(3, smoothResult.pathCount);
            }
        }
Ejemplo n.º 3
0
 public void find_random_point()
 {
     using (var ctx = new RecastContext())
     {
         var navMesh      = CreateNavMesh(ctx);
         var navMeshQuery = ctx.CreateNavMeshQuery(navMesh);
         var result       = ctx.FindRandomPoint(navMeshQuery);
         Assert.IsTrue(Success(result.status));
         Assert.AreEqual(result.point.Length, 3);
     }
 }
Ejemplo n.º 4
0
 public void find_path()
 {
     using (var ctx = new RecastContext())
     {
         var navMesh      = CreateNavMesh(ctx);
         var navMeshQuery = ctx.CreateNavMeshQuery(navMesh);
         var pointA       = FindRandomPointSafer(ctx, navMeshQuery);
         var pointB       = FindRandomPointSafer(ctx, navMeshQuery);
         var result       = FindPathSafer(pointA, pointB, ctx, navMeshQuery);
         Assert.IsTrue(Success(result.status));
     }
 }
Ejemplo n.º 5
0
        /// <summary>
        /// Initialize a new DefaultMeshNavigator given a mesh file and halfExtents parameters.
        /// </summary>
        /// <param name="navMeshFile">Mesh file</param>
        /// <param name="halfExtents">Half extents</param>
        /// <exception cref="Exception">Throws an exception if the mesh file cannot be loaded.</exception>
        public DefaultMeshNavigator(string navMeshFile, float[] halfExtents)
        {
            _ctx     = new RecastContext();
            _navMesh = _ctx.LoadTiledNavMeshBinFile(navMeshFile);

            if (_navMesh.IsInvalid)
            {
                throw new Exception("Failed to load nav mesh");
            }

            _navMeshQuery = _ctx.CreateNavMeshQuery(_navMesh);
            _halfExtents  = halfExtents;
        }
Ejemplo n.º 6
0
        public void find_nearest_poly()
        {
            using (var ctx = new RecastContext()) {
                var navMesh = CreateNavMesh(ctx);

                var navMeshQuery = ctx.CreateNavMeshQuery(navMesh);

                var point       = new float[] { -575f, -69.1874f, 54f };
                var halfExtents = new float[] { 10.0f, 10.0f, 10.0f };
                var result      = ctx.FindNearestPoly(navMeshQuery, point, halfExtents);
                Assert.AreEqual(result.polyRef, 281474976711211L);
            }
        }
Ejemplo n.º 7
0
 public void create_navmesh_query()
 {
     using (var ctx = new RecastContext())
     {
         var mesh           = GetInputGeom(ctx);
         var chf            = ctx.CreateCompactHeightfield(_config, mesh);
         var polyMesh       = ctx.CreatePolyMesh(_config, chf);
         var polyMeshDetail = ctx.CreatePolyMeshDetail(_config, polyMesh, chf);
         var navMeshData    = ctx.CreateNavMeshData(_config, polyMeshDetail, polyMesh, mesh, 0, 0,
                                                    BuildSettings.agentHeight, BuildSettings.agentRadius, BuildSettings.agentMaxClimb);
         var navMesh      = ctx.CreateNavMesh(navMeshData);
         var navMeshQuery = ctx.CreateNavMeshQuery(navMesh);
         Assert.IsNotNull(navMeshQuery);
     }
 }
Ejemplo n.º 8
0
        public void find_nearest_poly_fail()
        {
            using (var ctx = new RecastContext())
            {
                var navMesh      = CreateNavMesh(ctx);
                var navMeshQuery = ctx.CreateNavMeshQuery(navMesh);

                var point       = new float[] { -5750.0f, -6900.1874f, 5400.0f };
                var halfExtents = new float[] { 10.0f, 10.0f, 10.0f };
                var result      = ctx.FindNearestPoly(navMeshQuery, point, halfExtents);

                Assert.IsFalse(Success(result.status));
                Assert.AreEqual(result.polyRef, 0);
                Assert.AreEqual(result.point[0], 0);
                Assert.AreEqual(result.point[1], 0);
                Assert.AreEqual(result.point[2], 0);
            }
        }
Ejemplo n.º 9
0
        public void find_smooth_path()
        {
            using (var ctx = new RecastContext())
            {
                var navMesh      = CreateNavMesh(ctx);
                var navMeshQuery = ctx.CreateNavMeshQuery(navMesh);
                var pointA       = FindRandomPointSafer(ctx, navMeshQuery);
                var pointB       = FindRandomPointSafer(ctx, navMeshQuery);

                var result = FindPathSafer(pointA, pointB, ctx, navMeshQuery);
                Assert.IsTrue(Success(result.status));

                var smoothResult = ctx.FindSmoothPath(navMeshQuery, navMesh, result, pointA, pointB);
                Assert.IsNotNull(smoothResult);
                Assert.GreaterOrEqual(smoothResult.pathCount, result.pathCount);
                Assert.AreEqual(3 * Constants.MaxSmoothPathLength, smoothResult.path.Length);
                Assert.IsTrue(smoothResult.pathCount < Constants.MaxSmoothPathLength * 3);
                Assert.AreEqual(smoothResult.path[0], pointA.point[0], 0.00001);
                Assert.AreEqual(smoothResult.path[1], pointA.point[1], 0.00001);
                Assert.AreEqual(smoothResult.path[2], pointA.point[2], 0.00001);
            }
        }
Ejemplo n.º 10
0
        public void disposes_work()
        {
            var ctx            = new RecastContext();
            var mesh           = GetInputGeom(ctx);
            var chf            = ctx.CreateCompactHeightfield(_config, mesh);
            var polyMesh       = ctx.CreatePolyMesh(_config, chf);
            var polyMeshDetail = ctx.CreatePolyMeshDetail(_config, polyMesh, chf);
            var navMeshData    = ctx.CreateNavMeshData(_config, polyMeshDetail, polyMesh, mesh, 0, 0,
                                                       BuildSettings.agentHeight, BuildSettings.agentRadius, BuildSettings.agentMaxClimb);
            var navMesh      = ctx.CreateNavMesh(navMeshData);
            var navMeshQuery = ctx.CreateNavMeshQuery(navMesh);

            Assert.IsNotNull(navMeshQuery);

            navMeshQuery.Dispose();
            navMesh.Dispose();
            polyMeshDetail.Dispose();
            polyMesh.Dispose();
            chf.Dispose();
            mesh.Dispose();
            ctx.Dispose();
        }