// // Export // private void Button_Export_Click(object sender, EventArgs e) { try { FolderBrowserDialog folderDialog = new FolderBrowserDialog(); if (folderDialog.ShowDialog() != DialogResult.OK) { UpdateStatus("No output folder selected", SystemIcons.Error); return; } UpdateStatus("Preparing to export", 0, InputFiles.Count * 3); foreach (string file in InputFiles) { // import UpdateStatus($"Loading {file}", true); using (ImageMagick.MagickImage img = new ImageMagick.MagickImage(file)) { // convert UpdateStatus($"Converting {file}", true); if (checkBox_Resize.Checked) { img.Resize((int)numericUpDown_ResizeX.Value, (int)numericUpDown_ResizeY.Value); } if (checkBox_AlphaMask.Checked) { ImageMagick.IPixelCollection pixels = img.GetPixels(); int width = img.Width; int height = img.Height; for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { ImageMagick.MagickColor pixelColor = pixels[x, y].ToColor(); pixels[x, y].Set(new ushort[] { pixelColor.A, pixelColor.A, pixelColor.A, ushort.MaxValue }); } } } // export string exportPath = $@"{folderDialog.SelectedPath}{Path.DirectorySeparatorChar}{Path.GetFileName(file)}"; if (checkBox_ChangeFormat.Checked && comboBox_ExportFormat.SelectedItem != null) { exportPath = Path.ChangeExtension(exportPath, (comboBox_ExportFormat.SelectedItem as FormatComboBoxItem).Extension()); } UpdateStatus($"Exporting \"{file}\"", true); img.Write(exportPath); } } UpdateStatus($"Exported {InputFiles.Count} files", 0); } catch (Exception ex) { UpdateStatus(ex.Message, SystemIcons.Error); } }
public FixtureRendererConfiguration2(string name) { Name = name; Renderer = FixtureRenderererType.Shaded; Color = new ImageMagick.MagickColor("#FFF"); Transparency = 0; HasLight = true; LightMin = 0.6; LightMax = 1.0; LightVector = new SharpDX.Vector3(1f, 1f, -1f); HasShadow = true; ShadowColor = new ImageMagick.MagickColor("#000"); ShadowOffsetX = 0; ShadowOffsetY = 0; ShadowSize = 1.0; ShadowTransparency = 75; }
private void GenerateCanvas() { if (ProcessedPolygons.Count() == 0) return; var vectors = ProcessedPolygons.SelectMany(p => p.Vectors); double minX = vectors.Min(p => p.X); double maxX = vectors.Max(p => p.X); double minY = vectors.Min(p => p.Y); double maxY = vectors.Max(p => p.Y); // Get the canvas size double minXProduct = (minX < 0) ? minX * -1 : minX; double maxXProduct = (maxX < 0) ? maxX * -1 : maxX; double minYProduct = (minY < 0) ? minY * -1 : minY; double maxYProduct = (maxY < 0) ? maxY * -1 : maxY; CanvasWidth = Convert.ToInt32((minXProduct < maxXProduct) ? maxXProduct * 2f : minXProduct * 2f); CanvasHeight = Convert.ToInt32((minYProduct < maxYProduct) ? maxYProduct * 2f : minYProduct * 2f); // Contains all polygons List<DrawableElement> drawlist = new List<DrawableElement>(); foreach (Polygon poly in ProcessedPolygons) { Vector3 n = Vector3.Normalize(GetNormal(poly.P1, poly.P2, poly.P3)); // backface cull if (n[2] < 0) continue; // shade double ndotl = RendererConf.LightVector[0] * n[0] + RendererConf.LightVector[1] * n[1] + RendererConf.LightVector[2] * n[2]; if (ndotl > 0) ndotl = 0; // Lightning must be between 0 and 1, its multiplied with RGB and that must return a ushort double lighting = RendererConf.LightMin - (RendererConf.LightMax - RendererConf.LightMin) * ndotl; if (lighting < 0) lighting = 0; else if (lighting > 1) lighting = 1; List<ImageMagick.Coordinate> coordinates = new List<ImageMagick.Coordinate>(); foreach (Vector3 vector in poly.Vectors) { coordinates.Add(new ImageMagick.Coordinate(CanvasWidth / 2 + vector.X, CanvasHeight / 2 - vector.Y)); } // We want to draw the vectors in z-order double maxZ = poly.Vectors.Max(p => p.Z); drawlist.Add(new DrawableElement(maxZ, lighting, coordinates)); } DrawableElements = drawlist.OrderBy(o => o.order); CanvasX = Convert.ToInt32(ZoneConf.ZoneCoordinateToMapCoordinate(FixtureRow.X) - CanvasWidth / 2d); CanvasY = Convert.ToInt32(ZoneConf.ZoneCoordinateToMapCoordinate(FixtureRow.Y) - CanvasHeight / 2d); ModelColor = RendererConf.Color; ModelTransparency = RendererConf.Transparency; }