Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //THE SCAN INTERNAL FOR RECASTGENERATOR.cs
- public override IEnumerable<Progress> ScanInternal()
- {
- //public override void ScanInternal (OnScanStatus statusCallback) {
- AstarProfiler.Reset ();
- AstarProfiler.StartProfile ("Base Scan");
- //AstarProfiler.InitializeFastProfile (new string[] {"Rasterize", "Rasterize Inner 1", "Rasterize Inner 2", "Rasterize Inner 3"});
- TriangleMeshNode.SetNavmeshHolder (AstarPath.active.astarData.GetGraphIndex (this), this);
- //THIS WAS ScanTiledNavmesh //////////////////////////////////////////////////////////////
- #if ASTARDEBUG
- System.Console.WriteLine ("Recast Graph -- Collecting Meshes");
- #endif
- //----
- //Voxel grid size
- int gw = (int)(forcedBounds.size.x / cellSize + 0.5f);
- int gd = (int)(forcedBounds.size.z / cellSize + 0.5f);
- if (!useTiles)
- {
- tileSizeX = gw;
- tileSizeZ = gd;
- }
- else
- {
- tileSizeX = editorTileSize;
- tileSizeZ = editorTileSize;
- }
- //Number of tiles
- int tw = (gw + tileSizeX - 1) / tileSizeX;
- int td = (gd + tileSizeZ - 1) / tileSizeZ;
- tileXCount = tw;
- tileZCount = td;
- if (tileXCount * tileZCount > TileIndexMask + 1)
- {
- throw new System.Exception("Too many tiles (" + (tileXCount * tileZCount) + ") maximum is " + (TileIndexMask + 1) +
- "\nTry disabling ASTAR_RECAST_LARGER_TILES under the 'Optimizations' tab in the A* inspector.");
- }
- tiles = new NavmeshTile[tileXCount * tileZCount];
- #if ASTARDEBUG
- System.Console.WriteLine ("Recast Graph -- Creating Voxel Base");
- #endif
- // If this is true, just fill the graph with empty tiles
- if (scanEmptyGraph)
- {
- for (int z = 0; z < td; z++)
- {
- for (int x = 0; x < tw; x++)
- {
- tiles[z * tileXCount + x] = NewEmptyTile(x, z);
- }
- }
- yield break;
- }
- AstarProfiler.StartProfile("Finding Meshes");
- List<ExtraMesh> extraMeshes;
- #if !NETFX_CORE || UNITY_EDITOR
- System.Console.WriteLine("Collecting Meshes");
- #endif
- CollectMeshes(out extraMeshes, forcedBounds);
- AstarProfiler.EndProfile("Finding Meshes");
- // A walkableClimb higher than walkableHeight can cause issues when generating the navmesh since then it can in some cases
- // Both be valid for a character to walk under an obstacle and climb up on top of it (and that cannot be handled with navmesh without links)
- // The editor scripts also enforce this but we enforce it here too just to be sure
- walkableClimb = Mathf.Min(walkableClimb, walkableHeight);
- //Create the voxelizer and set all settings
- var vox = new Voxelize(cellHeight, cellSize, walkableClimb, walkableHeight, maxSlope);
- vox.inputExtraMeshes = extraMeshes;
- vox.maxEdgeLength = maxEdgeLength;
- int lastInfoCallback = -1;
- var watch = System.Diagnostics.Stopwatch.StartNew();
- //Generate all tiles
- for (int z = 0; z < td; z++)
- {
- for (int x = 0; x < tw; x++)
- {
- int tileNum = z * tileXCount + x;
- #if !NETFX_CORE || UNITY_EDITOR
- System.Console.WriteLine("Generating Tile #" + (tileNum) + " of " + td * tw);
- #endif
- //Call statusCallback only 10 times since it is very slow in the editor
- if (/*statusCallback != null&&*/ (tileNum * 10 / tiles.Length > lastInfoCallback || watch.ElapsedMilliseconds > 20)) //that was milliseconds 2000
- {
- lastInfoCallback = tileNum * 10 / tiles.Length;
- watch.Reset();
- watch.Start();
- //statusCallback(new Progress(AstarMath.MapToRange(0.1f, 0.9f, tileNum / (float)tiles.Length), "Building Tile " + tileNum + "/" + tiles.Length));
- yield return new Progress(AstarMath.MapToRange(0.1f, 0.9f, tileNum / (float)tiles.Length), "Building Tile " + tileNum + "/" + tiles.Length);
- }
- BuildTileMesh(vox, x, z);
- }
- }
- #if !NETFX_CORE
- System.Console.WriteLine("Assigning Graph Indices");
- #endif
- //if (statusCallback != null) statusCallback(new Progress(0.9f, "Connecting tiles"));
- yield return new Progress(0.9f, "Getting Nodes");
- //Assign graph index to nodes
- uint graphIndex = (uint)AstarPath.active.astarData.GetGraphIndex(this);
- GraphNodeDelegateCancelable del = delegate(GraphNode n)
- {
- n.GraphIndex = graphIndex;
- return true; //this is an inline delegate so the return true is for the method 'del'
- };
- GetNodes(del);
- for (int z = 0; z < td; z++)
- {
- if (z % 5 == 0) yield return new Progress(Mathf.Lerp(0.91f, 0.99f, z / (float)td), "Connecting tiles");
- for (int x = 0; x < tw; x++)
- {
- #if !NETFX_CORE
- System.Console.WriteLine("Connecing Tile #" + (z * tileXCount + x) + " of " + td * tw);
- #endif
- if (x < tw - 1) ConnectTiles(tiles[x + z * tileXCount], tiles[x + 1 + z * tileXCount]);
- if (z < td - 1) ConnectTiles(tiles[x + z * tileXCount], tiles[x + (z + 1) * tileXCount]);
- }
- }
- AstarProfiler.PrintResults();
- #if !NETFX_CORE
- System.Console.WriteLine("Finished AStar Connecting");
- #endif
- #if DEBUG_REPLAY
- DebugReplay.WriteToFile ();
- #endif
- AstarProfiler.PrintFastResults();
- //END THIS WAS ScanTiledNavmesh //////////////////////////////////////////////////////////////
- yield break;
- }
- //protected void ScanTiledNavmesh(OnScanStatus statusCallback)
- //{
- // ScanAllTiles(statusCallback);
- //}
- //protected void ScanAllTiles(OnScanStatus statusCallback)
- //{
- //this has been moved to ScanInternal()
- //}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement