private bool BuildSingleTile() { TileBuildData tdata = mBuild.BuildData; NMGenConfig config = mBuild.Config; InputGeometry geom = mBuild.InputGeom; mContext.ResetLog(); /* * Design note: * * Not using the build task since it doesn't provide enough progress * feedback for a single tile. * */ // Create the NMGen builder. IncrementalBuilder builder = IncrementalBuilder.Create(config.GetConfig() , config.ResultOptions , geom , mBuild.NMGenProcessors); if (builder == null) { mContext.PostError("Unexpected failure creating NMGen builder.", mBuild); tdata.SetAsFailed(0, 0); return(false); } else if (builder.IsFinished) { if (builder.State == NMGenState.NoResult) { mContext.PostError("NMGen build did not produce a result. (Early exit.)" , builder.GetMessages(), mBuild); tdata.SetAsFailed(0, 0); return(false); } else { mContext.PostError("Unexpected NMGen builder completion." , builder.GetMessages(), mBuild); tdata.SetAsFailed(0, 0); return(false); } } mBuild.BuildData.SetAsInProgress(0, 0); // Run the NMGen builder. while (!builder.IsFinished) { if (EditorUtility.DisplayCancelableProgressBar("Build Single Tile Mesh" , IncrementalBuilder.ToLabel(builder.State) , IncrementalBuilder.ToProgress(builder.State))) { return(false); } builder.Build(); } // Handle NMGen failures. mContext.Log(builder.GetMessages()); // Single tile build. So go ahead an record. switch (builder.State) { case NMGenState.Aborted: mContext.PostError("NMGen build failed.", mBuild); tdata.SetAsFailed(0, 0); return(false); case NMGenState.NoResult: mContext.PostError("NMGen build did not produce a result.", mBuild); tdata.SetAsFailed(0, 0); return(false); } mContext.Log(string.Format("Completed NMGen build: {0} polygons." , builder.Result.PolyMesh.PolyCount) , mBuild); // Build the tile. NMGenAssets result = builder.Result; if (result.DetailMesh == null) { Debug.LogError("result.DetailMesh ==null!"); } NavmeshTileBuildData tbd = org.critterai.nmbuild.NMBuild.GetBuildData( mContext, 0, 0 , result.PolyMesh.GetData(false), result.DetailMesh.GetData(false) , mBuild.Connections , (config.BuildFlags & NMGenBuildFlag.BVTreeEnabled) != 0); if (tbd == null) { // No need to log the error. The above method takes care of that. tdata.SetAsFailed(0, 0); return(false); } NavmeshTileData td = NavmeshTileData.Create(tbd); if (td.Size == 0) { mContext.PostError( "Could not create {0} object. Cause unknown." + typeof(NavmeshTileData) , mBuild); tdata.SetAsFailed(0, 0); return(false); } // Finalize the tile. tdata.SetWorkingData(0, 0, result.PolyMesh, result.DetailMesh); tdata.SetWorkingData(0, 0, td, tbd.PolyCount); mContext.PostTrace("Completed single tile build.", mBuild); return(true); }
public bool QueueTask(int tx, int tz, int priority, BuildContext logger) { // Check for existing task and purge it. NavmeshBuild build = Build; if (!build) { return(false); } TileBuildData tdata = build.BuildData; if (build.TileSetDefinition == null && (tx > 0 || tz > 0)) { logger.LogError("Tile build requested, but no tile set found.", this); return(false); } if (AbortRequest(tx, tz, "Overriden by new task.")) { tdata.ClearUnbaked(tx, tz); logger.LogWarning(string.Format( "Existing build task overridden by new task. ({0}, {1})" , tx, tz), this); } IncrementalBuilder builder; NMGenConfig config = build.Config; if (build.TileSetDefinition == null) { InputGeometry geom = build.InputGeom; if (geom == null) { logger.LogError("Input geometry not available.", this); tdata.SetAsFailed(tx, tz); return(false); } builder = IncrementalBuilder.Create(config.GetConfig() , config.ResultOptions , geom , build.NMGenProcessors); } else { builder = IncrementalBuilder.Create(tx, tz , config.ResultOptions , build.TileSetDefinition , build.NMGenProcessors); } if (builder == null) { logger.LogError(string.Format("Tile set did not produce a builder. Tile: ({0},{1})" , tx, tz) , this); return(false); } NMGenTask task = NMGenTask.Create(builder, priority); if (!mTaskProcessor.QueueTask(task)) { logger.LogError(string.Format("Processor rejected task. Tile: ({0},{1})" , tx, tz), this); return(false); } mNMGenTasks.Add(task); tdata.SetAsQueued(tx, tz); return(true); }