public void Start() { if (m_fixtures.Count == 0) { return; } MainForm.ProgressStartMarquee("Sorting fixtures ...."); // Create paths out of the rivers Dictionary <WaterConfiguration, System.Drawing.Drawing2D.GraphicsPath> riverPaths = new Dictionary <WaterConfiguration, System.Drawing.Drawing2D.GraphicsPath>(); foreach (WaterConfiguration rConf in rivers) { System.Drawing.Drawing2D.GraphicsPath riverPath = new System.Drawing.Drawing2D.GraphicsPath(); System.Drawing.PointF[] points = rConf.GetCoordinates().Select(c => new System.Drawing.PointF(Convert.ToSingle(c.X * zoneConfiguration.MapScale), Convert.ToSingle(c.Y * zoneConfiguration.MapScale))).ToArray(); riverPath.AddPolygon(points); riverPaths.Add(rConf, riverPath); } foreach (DrawableFixture model in m_fixtures) { // ignote the model if there are no polygons if (model.ProcessedPolygons.Count() == 0) { continue; } // UI options if (!DrawTrees && (model.IsTree || model.IsTreeCluster)) { continue; } if (!DrawFixtures && !(model.IsTree || model.IsTreeCluster)) { continue; } if (!DrawTreesAsImages && (model.IsTree || model.IsTreeCluster)) { model.RendererConf = FixtureRendererConfigurations.GetRendererById("TreeShaded"); } double modelCenterX = zoneConfiguration.ZoneCoordinateToMapCoordinate(model.FixtureRow.X); double modelCenterY = zoneConfiguration.ZoneCoordinateToMapCoordinate(model.FixtureRow.Y); // Check if on river or not int riverHeight = 0; foreach (KeyValuePair <WaterConfiguration, System.Drawing.Drawing2D.GraphicsPath> river in riverPaths) { if (river.Value.IsVisible(Convert.ToSingle(modelCenterX), Convert.ToSingle(modelCenterY))) { riverHeight = river.Key.Height; break; } } if (riverHeight == 0 || (riverHeight != 0 && model.FixtureRow.Z > riverHeight)) { m_fixturesAboveWater.Add(model); } else { m_fixturesUnderWater.Add(model); } } m_fixturesAboveWater = m_fixturesAboveWater.OrderBy(f => f.CanvasZ).ToList(); m_fixturesUnderWater = m_fixturesUnderWater.OrderBy(f => f.CanvasZ).ToList(); // Dispose all paths riverPaths.Select(d => d.Value).ToList().ForEach(r => r.Dispose()); MainForm.ProgressReset(); }
private void Draw(MagickImage map, List <DrawableFixture> fixtures) { MainForm.ProgressStart(string.Format("Drawing fixtures ({0}) ...", fixtures.Count)); Stopwatch timer = Stopwatch.StartNew(); using (MagickImage modelsOverlay = new MagickImage(MagickColors.Transparent, zoneConfiguration.TargetMapSize, zoneConfiguration.TargetMapSize)) { using (MagickImage treeOverlay = new MagickImage(MagickColors.Transparent, zoneConfiguration.TargetMapSize, zoneConfiguration.TargetMapSize)) { int processCounter = 0; foreach (DrawableFixture fixture in fixtures) { // Debug single models //if (fixture.FixtureRow.NifId != 408) //{ // continue; //} switch (fixture.RendererConf.Renderer) { case FixtureRenderererType.Shaded: DrawShaded((fixture.IsTree || fixture.IsTreeCluster) ? treeOverlay : modelsOverlay, fixture); break; case FixtureRenderererType.Flat: DrawFlat((fixture.IsTree || fixture.IsTreeCluster) ? treeOverlay : modelsOverlay, fixture); break; case FixtureRenderererType.Image: //DrawShaded((fixture.IsTree || fixture.IsTreeCluster) ? treeOverlay : modelsOverlay, fixture); DrawImage((fixture.IsTree || fixture.IsTreeCluster) ? treeOverlay : modelsOverlay, fixture); break; } int percent = 100 * processCounter / fixtures.Count(); MainForm.ProgressUpdate(percent); processCounter++; } MainForm.ProgressStartMarquee("Merging ..."); FixtureRendererConfiguration2 treeImagesRConf = FixtureRendererConfigurations.GetRendererById("TreeImage"); if (treeImagesRConf.HasShadow) { CastShadow( treeOverlay, treeImagesRConf.ShadowOffsetX, treeImagesRConf.ShadowOffsetY, treeImagesRConf.ShadowSize, new Percentage(100 - treeImagesRConf.ShadowTransparency), treeImagesRConf.ShadowColor, false ); } if (treeImagesRConf.Transparency != 0) { treeOverlay.Alpha(AlphaOption.Set); double divideValue = 100.0 / (100.0 - TreeTransparency); treeOverlay.Evaluate(Channels.Alpha, EvaluateOperator.Divide, divideValue); } map.Composite(modelsOverlay, 0, 0, CompositeOperator.SrcOver); map.Composite(treeOverlay, 0, 0, CompositeOperator.SrcOver); } } timer.Stop(); MainForm.Log(string.Format("Finished in {0} seconds.", timer.Elapsed.TotalSeconds), MainForm.LogLevel.success); MainForm.ProgressReset(); }