Exemple #1
0
        // NavMesh generator
        private List <VertexPositionColor> LoadNavMeshTestData(H32Loader h32)
        {
            // TODO - configure nav dir - determine filename using worldid xml

            DateTime TIMER;
            var      floorLineVertices = new List <VertexPositionColor>();

            bool generate     = true;  //false;
            bool loadFromFile = false; //true;//true;
            bool saveToFile   = false; //true;
            //NavMeshBuilder.OPTION_PARALLEL_THREADS = 1;
            //NavMeshBuilder.OPTION_REMOVE_SMALL_GRAPHS = false;

            CompiledNavMeshSet compiledMeshSet = null;

            if (generate)
            {
                TIMER = DateTime.Now;
                h32.LoadIntoGeoSpace(m_geoSpace);
                Debug.WriteLine("h32.LoadIntoGeoSpace TIME: " + (DateTime.Now - TIMER));

                TIMER = DateTime.Now;
                m_geoSpace.BuildTree();
                m_geoSpace.Validate();
                Debug.WriteLine("BuildTree TIME: " + (DateTime.Now - TIMER));

                float startX = 90;       //133-120; //340 - 20;
                float endX   = 200;      //133+20; //360 + 20;
                float startY = 103 - 20; //220 - 20;
                float endY   = 120;      // 103+20; //240 + 20;

                int top = 400;
                int bot = 0;

                float step           = 1f;
                var   navMeshBuilder = new NavMeshBuilder(startX, startY, bot, endX, endY, top, step);

                TIMER           = DateTime.Now;
                compiledMeshSet = navMeshBuilder.ScanFloor(m_geoSpace);
                Debug.WriteLine("ScanFloor TIME: " + (DateTime.Now - TIMER));

                if (saveToFile)
                {
                    // File roundtrip test
                    using (var fs = File.OpenWrite("c:\\temp2\\300200000.nav"))
                        compiledMeshSet.Save(fs);
                }
            }

            if (loadFromFile)
            {
                using (var fs = File.OpenRead(@"c:\temp2\out\210020000.nav"))  //"c:\\temp2\\300200000.nav"))
                    compiledMeshSet = CompiledNavMeshSet.Load(fs);
            }

            Debug.WriteLine("Total estimated compiled mesh size in bytes: " + compiledMeshSet.GetEstimatedFileSizeInBytes());

            var compiledMesh = //compiledMeshSet.FindSubgraphUnderPointWithSnap(126, 66, 145+2, maxFall: 10);
                               //compiledMeshSet.FindSubgraphUnderPointWithSnap(2484, 2614, 300, maxFall: 20);
                               compiledMeshSet.FindSubgraphUnderPointWithSnap(110, 110, 300, maxFall: 2220);

            if (compiledMesh == null)
            {
                throw new InvalidOperationException("point was not over a floor");
            }

            m_tempCompiledNavMeshSet = compiledMeshSet;

            // DEBUG MARKERS

            //    floorLineVertices.Add(new VertexPositionColor(new Vector3(126, 65, 144.3f + 3), Color.Lime));
            //    floorLineVertices.Add(new VertexPositionColor(new Vector3(126, 65, 144.3f), Color.Lime));

            //    floorLineVertices.Add(new VertexPositionColor(new Vector3(127, 64, 145.09f + 3), Color.Red));
            //    floorLineVertices.Add(new VertexPositionColor(new Vector3(127, 64, 145.09f), Color.Red));

            //=============================================
            // TESTING COMPILED MESH GETNEIGHBOR

            //start...
            //    floorLineVertices.Add(new VertexPositionColor(new Vector3(133, 103, 150), Color.White));
            //  floorLineVertices.Add(new VertexPositionColor(new Vector3(133, 103, 144), Color.White));

            /*
             * var curNode = compiledMesh.FindFloorUnderPoint(132.9f, 102.9f, 149, 20);
             * Vector3 v = compiledMesh.WorldFromBlockIndex(curNode.blockIndex, 144);
             *
             * floorLineVertices.Add(new VertexPositionColor(v + new Vector3(0,0,5), Color.Lime));
             * floorLineVertices.Add(new VertexPositionColor(v, Color.Lime));
             *
             * curNode = compiledMesh.GetNeighbor(curNode, 0, 1);
             * v = compiledMesh.WorldFromBlockIndex(curNode.blockIndex, 144);
             * floorLineVertices.Add(new VertexPositionColor(v + new Vector3(0, 0, 5), Color.Cyan));
             * floorLineVertices.Add(new VertexPositionColor(v, Color.Lime));
             *
             * curNode = compiledMesh.GetNeighbor(curNode, 0, 1);
             * v = compiledMesh.WorldFromBlockIndex(curNode.blockIndex, 144);
             * floorLineVertices.Add(new VertexPositionColor(v + new Vector3(0, 0, 5), Color.Yellow));
             * floorLineVertices.Add(new VertexPositionColor(v, Color.Lime));
             *
             * curNode = compiledMesh.GetNeighbor(curNode, 1, 1);
             * v = compiledMesh.WorldFromBlockIndex(curNode.blockIndex, 144);
             * floorLineVertices.Add(new VertexPositionColor(v + new Vector3(0, 0, 5), Color.White));
             * floorLineVertices.Add(new VertexPositionColor(v, Color.Lime));
             */
            // END TEST
            //=============================================



            //=============================================
            // TEST A*

            //TestAStar(compiledMesh, new Vector3(141, 21, 145), new Vector3(140, 28, 144), 10, floorLineVertices);

            //TestAStar(compiledMesh, new Vector3(155, 56, 144), new Vector3(169, 23, 144), 10, floorLineVertices);

            //    TestAStar(compiledMesh, new Vector3(130, 101, 145), new Vector3(125, 106, 147), 10, floorLineVertices);
            // END A*
            //=============================================



            TIMER = DateTime.Now;
            for (int bY = 0; bY < compiledMesh.BlockHeight; bY++)
            {
                for (int bX = 0; bX < compiledMesh.BlockWidth; bX++)
                {
                    float x = compiledMesh.X1 + bX * compiledMesh.Step;
                    float y = compiledMesh.Y1 + bY * compiledMesh.Step;

                    compiledMesh.ForeachHeightAtXY(bX, bY,
                                                   (directionFlags, z) =>
                    {
                        /*Color xcolor = Color.Lime;
                         *
                         * //if (bX == 28 && bY == 0) Debugger.Break();
                         *
                         * if (y > 221 && y < 223 && x > 346 && x < 348)
                         *  xcolor = Color.White;
                         * else if (y > 221 && y < 223 && x > 347 && x < 349)
                         *  xcolor = Color.Blue;
                         * else if (y >= 221 && y <= 223 && x >= 346 && x <= 348)
                         *  xcolor = Color.Red;*/


                        // DRAW ELEVATION MARKER

                        /*    floorLineVertices.Add(new VertexPositionColor(new Vector3(x - 0.1f, y, z), xcolor));
                         *  floorLineVertices.Add(new VertexPositionColor(new Vector3(x, y + 0.1f, z), xcolor));
                         *
                         *  floorLineVertices.Add(new VertexPositionColor(new Vector3(x, y + 0.1f, z), xcolor));
                         *  floorLineVertices.Add(new VertexPositionColor(new Vector3(x + 0.1f, y, z), xcolor));
                         *
                         *  floorLineVertices.Add(new VertexPositionColor(new Vector3(x + 0.1f, y, z), xcolor));
                         *  floorLineVertices.Add(new VertexPositionColor(new Vector3(x, y - 0.1f, z), xcolor));
                         *
                         *  floorLineVertices.Add(new VertexPositionColor(new Vector3(x, y - 0.1f, z), xcolor));
                         *  floorLineVertices.Add(new VertexPositionColor(new Vector3(x - 0.1f, y, z), xcolor));
                         */

                        // EDGE CONNECTIONS
                        // draw lines through the compass points...

                        float halfstep = compiledMesh.Step;
                        float n;

                        n = compiledMesh.GetEdge(bX, bY, z, directionFlags, NavMeshUtil.DIRECTION_LEFT);
                        if (n >= 0)
                        {
                            var test = Color.Orange;
                            if (Math.Abs(z - n) >= 0.9f)
                            {
                                test = Color.Red;
                            }

                            floorLineVertices.Add(new VertexPositionColor(new Vector3(x, y, z), test));
                            floorLineVertices.Add(new VertexPositionColor(new Vector3(x - halfstep, y, n), test));
                        }
                        n = compiledMesh.GetEdge(bX, bY, z, directionFlags, NavMeshUtil.DIRECTION_TL);
                        if (n >= 0)
                        {
                            var test = Color.Orange;
                            if (Math.Abs(z - n) / (new Vector2(x, y) - new Vector2(x - halfstep, y + halfstep)).Length() >= 1.4f)
                            {
                                test = Color.Magenta;
                            }

                            floorLineVertices.Add(new VertexPositionColor(new Vector3(x, y, z), test));
                            floorLineVertices.Add(new VertexPositionColor(new Vector3(x - halfstep, y + halfstep, n), test));
                        }
                        n = compiledMesh.GetEdge(bX, bY, z, directionFlags, NavMeshUtil.DIRECTION_TOP);
                        if (n >= 0)
                        {
                            var test = Color.Orange;
                            if (Math.Abs(z - n) >= 0.9f)
                            {
                                test = Color.Red;
                            }

                            floorLineVertices.Add(new VertexPositionColor(new Vector3(x, y, z), test));
                            floorLineVertices.Add(new VertexPositionColor(new Vector3(x, y + halfstep, n), test));
                        }
                        n = compiledMesh.GetEdge(bX, bY, z, directionFlags, NavMeshUtil.DIRECTION_TR);
                        if (n >= 0)
                        {
                            var test = Color.Orange;
                            if (Math.Abs(z - n) / (new Vector2(x, y) - new Vector2(x + halfstep, y + halfstep)).Length() >= 1.4f)
                            {
                                test = Color.Purple;
                            }

                            floorLineVertices.Add(new VertexPositionColor(new Vector3(x, y, z), test));
                            floorLineVertices.Add(new VertexPositionColor(new Vector3(x + halfstep, y + halfstep, n), test));
                        }
                    });
                }
            }
            Debug.WriteLine("MESH ASSEMBLY TIME: " + (DateTime.Now - TIMER));
            return(floorLineVertices);
        }
Exemple #2
0
        // NavMesh generator
        private List <VertexPositionColor> LoadNavMeshTestData(H32Loader h32)
        {
            // TODO - configure nav dir - determine filename using worldid xml

            DateTime TIMER;
            bool     generate     = false;
            bool     loadFromFile = true;
            bool     saveToFile   = false;//true;
            //NavMeshBuilder.OPTION_PARALLEL_THREADS = 1;
            //NavMeshBuilder.OPTION_REMOVE_SMALL_GRAPHS = false;

            CompiledNavMeshSet compiledMeshSet = null;

            if (generate)
            {
                TIMER = DateTime.Now;
                h32.LoadIntoGeoSpace(m_geoSpace);
                Debug.WriteLine("h32.LoadIntoGeoSpace TIME: " + (DateTime.Now - TIMER));

                TIMER = DateTime.Now;
                m_geoSpace.BuildTree();
                m_geoSpace.Validate();
                Debug.WriteLine("BuildTree TIME: " + (DateTime.Now - TIMER));

                float startX = 90;       //133-120; //340 - 20;
                float endX   = 200;      //133+20; //360 + 20;
                float startY = 103 - 20; //220 - 20;
                float endY   = 120;      // 103+20; //240 + 20;

                int top = 400;
                int bot = 0;

                float step           = 1f;
                var   navMeshBuilder = new NavMeshBuilder(startX, startY, bot, endX, endY, top, step);

                TIMER           = DateTime.Now;
                compiledMeshSet = navMeshBuilder.ScanFloor(m_geoSpace);
                Debug.WriteLine("ScanFloor TIME: " + (DateTime.Now - TIMER));

                if (saveToFile)
                {
                    // File roundtrip test
                    using (var fs = File.OpenWrite("c:\\temp2\\300200000.nav"))
                        compiledMeshSet.Save(fs);
                }
            }

            if (loadFromFile)
            {
                using (var fs = File.OpenRead(@"c:\temp2\out\210020000.nav"))  //"c:\\temp2\\300200000.nav"))
                    compiledMeshSet = CompiledNavMeshSet.Load(fs);
            }

            Debug.WriteLine("Total estimated compiled mesh size in bytes: " + compiledMeshSet.GetEstimatedFileSizeInBytes());

            var compiledMesh = //compiledMeshSet.FindSubgraphUnderPointWithSnap(126, 66, 145+2, maxFall: 10);
                               //compiledMeshSet.FindSubgraphUnderPointWithSnap(2484, 2614, 300, maxFall: 20);
                               compiledMeshSet.FindSubgraphUnderPointWithSnap(110, 110, 300, maxFall: 2220);

            if (compiledMesh == null)
            {
                throw new InvalidOperationException("point was not over a floor");
            }

            m_tempCompiledNavMeshSet = compiledMeshSet;

            TIMER = DateTime.Now;
            var floorLineVertices = RenderFloorLines(compiledMesh, Vector3.Zero, 0);

            Debug.WriteLine("MESH ASSEMBLY TIME: " + (DateTime.Now - TIMER));

            return(floorLineVertices);
        }