private static FixtureRendererConfiguration2?ParseRendererConfigurationFromXmlNode(XElement node) { // Create a NumberFormatInfo object for floats and set some of its properties. System.Globalization.NumberFormatInfo provider = new System.Globalization.NumberFormatInfo(); provider.NumberDecimalSeparator = "."; provider.NumberGroupSeparator = ""; provider.NumberGroupSizes = new int[] { 2 }; try { FixtureRendererConfiguration2 conf = new FixtureRendererConfiguration2(); if (node.Descendants("id").Count() > 0) { conf.Name = node.Descendants("id").First().Value; } else if (node.Descendants("pattern").Count() > 0) { conf.Name = node.Descendants("pattern").First().Value; } conf.Renderer = GetRendererType(node.Descendants("renderer").First().Value); conf.Color = new ImageMagick.MagickColor((node.Descendants("color").Count() > 0) ? node.Descendants("color").First().Value : "#FFF"); conf.Transparency = Convert.ToInt32((node.Descendants("transparency").Count() > 0) ? node.Descendants("transparency").First().Value : "0"); var lightElement = node.Descendants("light"); if (lightElement.Count() > 0) { var light = lightElement.First(); conf.HasLight = Convert.ToBoolean(light.Value); conf.LightMin = Convert.ToDouble(!string.IsNullOrEmpty(light.Attribute("min").Value) ? light.Attribute("min").Value : "0.6", provider); conf.LightMax = Convert.ToDouble(!string.IsNullOrEmpty(light.Attribute("max").Value) ? light.Attribute("max").Value : "1.0", provider); conf.LightVector = GetLightVector(string.IsNullOrEmpty(light.Attribute("direction").Value) ? light.Attribute("direction").Value : "1,1,-1"); } var shadowElement = node.Descendants("shadow"); if (shadowElement.Count() > 0) { var shadow = shadowElement.First(); conf.HasShadow = Convert.ToBoolean(shadow.Value); conf.ShadowColor = new ImageMagick.MagickColor((!string.IsNullOrEmpty(shadow.Attribute("color").Value)) ? shadow.Attribute("color").Value : "#000"); conf.ShadowOffsetX = Convert.ToInt32(!string.IsNullOrEmpty(shadow.Attribute("offset_x").Value) ? shadow.Attribute("offset_x").Value : "0"); conf.ShadowOffsetY = Convert.ToInt32(!string.IsNullOrEmpty(shadow.Attribute("offset_y").Value) ? shadow.Attribute("offset_y").Value : "0"); conf.ShadowSize = Convert.ToDouble(!string.IsNullOrEmpty(shadow.Attribute("size").Value) ? shadow.Attribute("size").Value : "1", provider); conf.ShadowTransparency = Convert.ToInt32(!string.IsNullOrEmpty(shadow.Attribute("transparency").Value) ? shadow.Attribute("transparency").Value : "75"); } if (!string.IsNullOrEmpty(node.Attribute("is_default").Value) && Convert.ToBoolean(node.Attribute("is_default").Value) == true) { defaultConfiguration = conf; } return(conf); } catch (Exception ex) { MainForm.Log("Error in fixtures XML", MainForm.LogLevel.error); MainForm.Log(ex.Message, MainForm.LogLevel.error); return(null); } }
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(); }
private static FixtureRendererConfiguration2? ParseRendererConfigurationFromXmlNode(XElement node) { // Create a NumberFormatInfo object for floats and set some of its properties. System.Globalization.NumberFormatInfo provider = new System.Globalization.NumberFormatInfo(); provider.NumberDecimalSeparator = "."; provider.NumberGroupSeparator = ""; provider.NumberGroupSizes = new int[] { 2 }; try { FixtureRendererConfiguration2 conf = new FixtureRendererConfiguration2(); if (node.Descendants("id").Count() > 0) { conf.Name = node.Descendants("id").First().Value; } else if(node.Descendants("pattern").Count() > 0) { conf.Name = node.Descendants("pattern").First().Value; } conf.Renderer = GetRendererType(node.Descendants("renderer").First().Value); conf.Color = new ImageMagick.MagickColor((node.Descendants("color").Count() > 0) ? node.Descendants("color").First().Value : "#FFF"); conf.Transparency = Convert.ToInt32((node.Descendants("transparency").Count() > 0) ? node.Descendants("transparency").First().Value : "0"); var lightElement = node.Descendants("light"); if (lightElement.Count() > 0) { var light = lightElement.First(); conf.HasLight = Convert.ToBoolean(light.Value); conf.LightMin = Convert.ToDouble(!string.IsNullOrEmpty(light.Attribute("min").Value) ? light.Attribute("min").Value : "0.6", provider); conf.LightMax = Convert.ToDouble(!string.IsNullOrEmpty(light.Attribute("max").Value) ? light.Attribute("max").Value : "1.0", provider); conf.LightVector = GetLightVector(string.IsNullOrEmpty(light.Attribute("direction").Value) ? light.Attribute("direction").Value : "1,1,-1"); } var shadowElement = node.Descendants("shadow"); if (shadowElement.Count() > 0) { var shadow = shadowElement.First(); conf.HasShadow = Convert.ToBoolean(shadow.Value); conf.ShadowColor = new ImageMagick.MagickColor((!string.IsNullOrEmpty(shadow.Attribute("color").Value)) ? shadow.Attribute("color").Value : "#000"); conf.ShadowOffsetX = Convert.ToInt32(!string.IsNullOrEmpty(shadow.Attribute("offset_x").Value) ? shadow.Attribute("offset_x").Value : "0"); conf.ShadowOffsetY = Convert.ToInt32(!string.IsNullOrEmpty(shadow.Attribute("offset_y").Value) ? shadow.Attribute("offset_y").Value : "0"); conf.ShadowSize = Convert.ToDouble(!string.IsNullOrEmpty(shadow.Attribute("size").Value) ? shadow.Attribute("size").Value : "1", provider); conf.ShadowTransparency = Convert.ToInt32(!string.IsNullOrEmpty(shadow.Attribute("transparency").Value) ? shadow.Attribute("transparency").Value : "75"); } if (!string.IsNullOrEmpty(node.Attribute("is_default").Value) && Convert.ToBoolean(node.Attribute("is_default").Value) == true) { defaultConfiguration = conf; } return conf; } catch(Exception ex) { MainForm.Log("Error in fixtures XML", MainForm.LogLevel.error); MainForm.Log(ex.Message, MainForm.LogLevel.error); return null; } }