public void ReadBackgroundTextures() { var location = ToolboxUpdater.GetApplicationFilePath(); Assert.IsNotNull(location, "Space Engineers should be installed on developer machine"); Assert.IsTrue(Directory.Exists(location), "Filepath should exist on developer machine"); var contentPath = ToolboxUpdater.GetApplicationContentPath(); var backgroundPath = Path.Combine(contentPath, @"Textures\BackgroundCube\Final\BackgroundCube.dds"); Assert.IsTrue(File.Exists(backgroundPath), "Filepath should exist on developer machine"); var backgroundBmp = TexUtil.CreateBitmap(backgroundPath, 0, -1, -1); ImageTextureUtil.WriteImage(backgroundBmp, @".\TestOutput\BackgroundCube0_Full.png"); backgroundBmp = TexUtil.CreateBitmap(backgroundPath, 1, 1024, 1024); ImageTextureUtil.WriteImage(backgroundBmp, @".\TestOutput\BackgroundCube1_1024.png"); backgroundBmp = TexUtil.CreateBitmap(backgroundPath, 2, 512, 512); ImageTextureUtil.WriteImage(backgroundBmp, @".\TestOutput\BackgroundCube2_512.png"); backgroundBmp = TexUtil.CreateBitmap(backgroundPath, 3, 128, 128); ImageTextureUtil.WriteImage(backgroundBmp, @".\TestOutput\BackgroundCube3_128.png"); backgroundBmp = TexUtil.CreateBitmap(backgroundPath, 4, 64, 64); ImageTextureUtil.WriteImage(backgroundBmp, @".\TestOutput\BackgroundCube4_64.png"); backgroundBmp = TexUtil.CreateBitmap(backgroundPath, 5, 32, 32); ImageTextureUtil.WriteImage(backgroundBmp, @".\TestOutput\BackgroundCube5_32.png"); }
private static string GetTextureToBase64(string filename, int width, int height, bool ignoreAlpha = false) { using (Stream stream = MyFileSystem.OpenRead(filename)) { return(ImageTextureUtil.GetTextureToBase64(stream, filename, width, height, ignoreAlpha)); } }
public void CreateMenuTextures() { SpaceEngineersCore.LoadDefinitions(); var location = ToolboxUpdater.GetApplicationFilePath(); Assert.IsNotNull(location, "Space Engineers should be installed on developer machine"); Assert.IsTrue(Directory.Exists(location), "Filepath should exist on developer machine"); var contentPath = ToolboxUpdater.GetApplicationContentPath(); var smallBlockLandingGear = SpaceEngineersApi.GetDefinition(new MyObjectBuilderType(typeof(MyObjectBuilder_LandingGear)), "SmallBlockLandingGear"); var smallBlockLandingGearPath = Path.Combine(contentPath, smallBlockLandingGear.Icons.First()); Assert.IsTrue(File.Exists(smallBlockLandingGearPath), "Filepath should exist on developer machine"); Assert.IsTrue(smallBlockLandingGear is MyObjectBuilder_CubeBlockDefinition, "Type should match"); var smallBlockLandingGearBmp = TexUtil.CreateBitmap(smallBlockLandingGearPath); var gridItemPath = Path.Combine(contentPath, @"Textures\GUI\Controls\grid_item.dds"); Assert.IsTrue(File.Exists(gridItemPath), "Filepath should exist on developer machine"); var gridBmp = TexUtil.CreateBitmap(gridItemPath); var bmp = ImageTextureUtil.MergeImages(gridBmp, smallBlockLandingGearBmp, Brushes.Black); ImageTextureUtil.WriteImage(bmp, @".\TestOutput\Menu_SmallBlockLandingGear.png"); }
private void LoadTextureAndExport(string textureFilePath) { string name = Path.GetFileNameWithoutExtension(textureFilePath); var textureFilePathBmp = TexUtil.CreateBitmap(textureFilePath); File.Copy(textureFilePath, Path.Combine(_path, name + ".dds"), true); ImageTextureUtil.WriteImage(textureFilePathBmp, Path.Combine(_path, name + ".png")); }
public void LoadAllCubeTextures() { var files = Directory.GetFiles(Path.Combine(ToolboxUpdater.GetApplicationContentPath(), @"Textures\Models\Cubes"), "*.dds"); foreach (var filename in files) { var outputFilename = Path.Combine(@".\TestOutput", Path.GetFileNameWithoutExtension(filename) + ".png"); var imageBitmap = TestLoadTexture(filename); ImageTextureUtil.WriteImage(imageBitmap, outputFilename); } }
public void CreateBackgroundPreview() { const int size = 128; const bool ignoreAlpha = true; var location = ToolboxUpdater.GetApplicationFilePath(); Assert.IsNotNull(location, "Space Engineers should be installed on developer machine"); Assert.IsTrue(Directory.Exists(location), "Filepath should exist on developer machine"); var contentPath = ToolboxUpdater.GetApplicationContentPath(); var backgroundPath = Path.Combine(contentPath, @"Textures\BackgroundCube\Final\BackgroundCube.dds"); Assert.IsTrue(File.Exists(backgroundPath), "Filepath should exist on developer machine"); var result = new Bitmap(size * 4, size * 3); using (var graphics = Graphics.FromImage(result)) { //set the resize quality modes to high quality graphics.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality; graphics.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic; graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality; if (ignoreAlpha) { graphics.FillRectangle(Brushes.Black, size * 2, size * 1, size, size); graphics.FillRectangle(Brushes.Black, size * 0, size * 1, size, size); graphics.FillRectangle(Brushes.Black, size * 1, size * 0, size, size); graphics.FillRectangle(Brushes.Black, size * 1, size * 2, size, size); graphics.FillRectangle(Brushes.Black, size * 1, size * 1, size, size); graphics.FillRectangle(Brushes.Black, size * 3, size * 1, size, size); } graphics.DrawImage(TexUtil.CreateBitmap(backgroundPath, 0, size, size, ignoreAlpha), size * 2, size * 1, size, size); graphics.DrawImage(TexUtil.CreateBitmap(backgroundPath, 1, size, size, ignoreAlpha), size * 0, size * 1, size, size); graphics.DrawImage(TexUtil.CreateBitmap(backgroundPath, 2, size, size, ignoreAlpha), size * 1, size * 0, size, size); graphics.DrawImage(TexUtil.CreateBitmap(backgroundPath, 3, size, size, ignoreAlpha), size * 1, size * 2, size, size); graphics.DrawImage(TexUtil.CreateBitmap(backgroundPath, 4, size, size, ignoreAlpha), size * 1, size * 1, size, size); graphics.DrawImage(TexUtil.CreateBitmap(backgroundPath, 5, size, size, ignoreAlpha), size * 3, size * 1, size, size); // Approximate position of local Sun and light source. graphics.FillEllipse(Brushes.White, size * 1 + (int)(size * 0.7), size * 2 + (int)(size * 0.93), (int)(size * 0.06), (int)(size * 0.06)); } ImageTextureUtil.WriteImage(result, string.Format(@".\TestOutput\BackgroundCube_{0}.png", size)); }
private void TestLoadTextureAndExport(string textureFilePath, bool ignoreAlpha = false) { Assert.IsTrue(File.Exists(textureFilePath), $"Filepath {textureFilePath} should exist on developer machine."); string name = Path.GetFileNameWithoutExtension(textureFilePath) + (ignoreAlpha ? "_alpha" : ""); Bitmap textureFilePathBmp; using (var stream = File.OpenRead(textureFilePath)) { textureFilePathBmp = TexUtil.CreateBitmap(stream, textureFilePath, ignoreAlpha: ignoreAlpha); } Assert.IsNotNull(textureFilePathBmp, $"Texture for {name} should not be null."); File.Copy(textureFilePath, Path.Combine(_path, name + ".dds"), true); ImageTextureUtil.WriteImage(textureFilePathBmp, Path.Combine(_path, name + ".png")); }
public void GenerateHtmlReport(string filename) { var stringWriter = new StringWriter(); // Put HtmlTextWriter in using block because it needs to call Dispose. using (var writer = new HtmlTextWriter(stringWriter)) { #region header writer.BeginDocument("Component Item Report", @" body { background-color: #E6E6FA } h1 { font-family: Arial, Helvetica, sans-serif; } table { background-color: #FFFFFF; } table tr td { font-family: Arial, Helvetica, sans-serif; font-size: small; line-height: normal; color: #000000; } table thead td { background-color: #BABDD6; font-weight: bold; Color: #000000; } td.right { text-align: right; }"); #endregion #region Cubes writer.RenderElement(HtmlTextWriterTag.H1, "Cubes"); writer.BeginTable("1", "3", "0", new[] { "Icon", "Name", "Type Id", "Sub Type Id", "Cube Size", "Accessible", "Size (W×H×D)", "Mass (Kg)", "Build Time (h:m:s)" }); foreach (var asset in CubeAssets) { writer.RenderBeginTag(HtmlTextWriterTag.Tr); writer.RenderBeginTag(HtmlTextWriterTag.Td); if (asset.TextureFile != null && File.Exists(asset.TextureFile)) { writer.AddAttribute(HtmlTextWriterAttribute.Src, "data:image/png;base64," + ImageTextureUtil.GetTextureToBase64(asset.TextureFile, 32, 32)); writer.AddAttribute(HtmlTextWriterAttribute.Width, "32"); writer.AddAttribute(HtmlTextWriterAttribute.Height, "32"); writer.AddAttribute(HtmlTextWriterAttribute.Alt, Path.GetFileNameWithoutExtension(asset.TextureFile)); writer.RenderBeginTag(HtmlTextWriterTag.Img); writer.RenderEndTag(); } writer.RenderEndTag(); // Td writer.RenderElement(HtmlTextWriterTag.Td, asset.FriendlyName); writer.RenderElement(HtmlTextWriterTag.Td, asset.TypeId); writer.RenderElement(HtmlTextWriterTag.Td, asset.SubtypeId); writer.RenderElement(HtmlTextWriterTag.Td, asset.CubeSize); writer.RenderElement(HtmlTextWriterTag.Td, new EnumToResouceConverter().Convert(asset.Accessible, typeof(string), null, CultureInfo.CurrentUICulture)); writer.RenderElement(HtmlTextWriterTag.Td, "{0}×{1}×{2}", asset.Size.Width, asset.Size.Height, asset.Size.Depth); writer.AddAttribute(HtmlTextWriterAttribute.Class, "right"); writer.RenderElement(HtmlTextWriterTag.Td, "{0:#,##0.00}", asset.Mass); writer.AddAttribute(HtmlTextWriterAttribute.Class, "right"); writer.RenderElement(HtmlTextWriterTag.Td, "{0:hh\\:mm\\:ss\\.ff}", asset.Time); writer.RenderEndTag(); // Tr } writer.RenderEndTag(); // Table #endregion #region Components writer.RenderElement(HtmlTextWriterTag.H1, "Components"); writer.BeginTable("1", "3", "0", new[] { "Icon", "Name", "Type Id", "Sub Type Id", "Accessible", "Mass (Kg)", "Volume (L)", "Build Time (h:m:s)" }); foreach (var asset in ComponentAssets) { writer.RenderBeginTag(HtmlTextWriterTag.Tr); writer.RenderBeginTag(HtmlTextWriterTag.Td); if (asset.TextureFile != null && File.Exists(asset.TextureFile)) { writer.AddAttribute(HtmlTextWriterAttribute.Src, "data:image/png;base64," + ImageTextureUtil.GetTextureToBase64(asset.TextureFile, 32, 32)); writer.AddAttribute(HtmlTextWriterAttribute.Width, "32"); writer.AddAttribute(HtmlTextWriterAttribute.Height, "32"); writer.AddAttribute(HtmlTextWriterAttribute.Alt, Path.GetFileNameWithoutExtension(asset.TextureFile)); writer.RenderBeginTag(HtmlTextWriterTag.Img); writer.RenderEndTag(); } writer.RenderEndTag(); // Td writer.RenderElement(HtmlTextWriterTag.Td, asset.FriendlyName); writer.RenderElement(HtmlTextWriterTag.Td, asset.TypeId); writer.RenderElement(HtmlTextWriterTag.Td, asset.SubtypeId); writer.RenderElement(HtmlTextWriterTag.Td, new EnumToResouceConverter().Convert(asset.Accessible, typeof(string), null, CultureInfo.CurrentUICulture)); writer.AddAttribute(HtmlTextWriterAttribute.Class, "right"); writer.RenderElement(HtmlTextWriterTag.Td, "{0:#,##0.00}", asset.Mass); writer.AddAttribute(HtmlTextWriterAttribute.Class, "right"); writer.RenderElement(HtmlTextWriterTag.Td, "{0:#,##0.00}", asset.Volume); writer.AddAttribute(HtmlTextWriterAttribute.Class, "right"); writer.RenderElement(HtmlTextWriterTag.Td, "{0:hh\\:mm\\:ss\\.ff}", asset.Time); writer.RenderEndTag(); // Tr } writer.RenderEndTag(); // Table #endregion #region Items writer.RenderElement(HtmlTextWriterTag.H1, "Items"); writer.BeginTable("1", "3", "0", new[] { "Icon", "Name", "Type Id", "Sub Type Id", "Accessible", "Mass (Kg)", "Volume (L)", "Build Time (h:m:s)" }); foreach (var asset in ItemAssets) { writer.RenderBeginTag(HtmlTextWriterTag.Tr); writer.RenderBeginTag(HtmlTextWriterTag.Td); if (asset.TextureFile != null && File.Exists(asset.TextureFile)) { writer.AddAttribute(HtmlTextWriterAttribute.Src, "data:image/png;base64," + ImageTextureUtil.GetTextureToBase64(asset.TextureFile, 32, 32)); writer.AddAttribute(HtmlTextWriterAttribute.Width, "32"); writer.AddAttribute(HtmlTextWriterAttribute.Height, "32"); writer.AddAttribute(HtmlTextWriterAttribute.Alt, Path.GetFileNameWithoutExtension(asset.TextureFile)); writer.RenderBeginTag(HtmlTextWriterTag.Img); writer.RenderEndTag(); } writer.RenderEndTag(); // Td writer.RenderElement(HtmlTextWriterTag.Td, asset.FriendlyName); writer.RenderElement(HtmlTextWriterTag.Td, asset.TypeId); writer.RenderElement(HtmlTextWriterTag.Td, asset.SubtypeId); writer.RenderElement(HtmlTextWriterTag.Td, new EnumToResouceConverter().Convert(asset.Accessible, typeof(string), null, CultureInfo.CurrentUICulture)); writer.AddAttribute(HtmlTextWriterAttribute.Class, "right"); writer.RenderElement(HtmlTextWriterTag.Td, "{0:#,##0.00}", asset.Mass); writer.AddAttribute(HtmlTextWriterAttribute.Class, "right"); writer.RenderElement(HtmlTextWriterTag.Td, "{0:#,##0.00}", asset.Volume); writer.AddAttribute(HtmlTextWriterAttribute.Class, "right"); writer.RenderElement(HtmlTextWriterTag.Td, "{0:hh\\:mm\\:ss\\.ff}", asset.Time); writer.RenderEndTag(); // Tr } writer.RenderEndTag(); // Table #endregion #region Materials writer.RenderElement(HtmlTextWriterTag.H1, "Materials"); writer.BeginTable("1", "3", "0", new[] { "Texture", "Name", "Ore Name", "Rare", "Mined Ore Ratio" }); foreach (var asset in MaterialAssets) { writer.RenderBeginTag(HtmlTextWriterTag.Tr); writer.RenderBeginTag(HtmlTextWriterTag.Td); if (asset.TextureFile != null && File.Exists(asset.TextureFile)) { writer.AddAttribute(HtmlTextWriterAttribute.Src, "data:image/png;base64," + ImageTextureUtil.GetTextureToBase64(asset.TextureFile, 32, 32, true)); writer.AddAttribute(HtmlTextWriterAttribute.Width, "32"); writer.AddAttribute(HtmlTextWriterAttribute.Height, "32"); writer.AddAttribute(HtmlTextWriterAttribute.Alt, Path.GetFileNameWithoutExtension(asset.TextureFile)); writer.RenderBeginTag(HtmlTextWriterTag.Img); writer.RenderEndTag(); } writer.RenderEndTag(); // Td writer.RenderElement(HtmlTextWriterTag.Td, asset.Name); writer.RenderElement(HtmlTextWriterTag.Td, asset.OreName); writer.RenderElement(HtmlTextWriterTag.Td, new EnumToResouceConverter().Convert(asset.IsRare, typeof(string), null, CultureInfo.CurrentUICulture)); writer.RenderElement(HtmlTextWriterTag.Td, "{0:#,##0.00}", asset.MineOreRatio); writer.RenderEndTag(); // Tr } writer.RenderEndTag(); // Table #endregion #region footer writer.EndDocument(); #endregion } // Write to disk. File.WriteAllText(filename, stringWriter.ToString()); }
public void LoadComponentTextures() { SpaceEngineersCore.LoadDefinitions(); var location = ToolboxUpdater.GetApplicationFilePath(); Assert.IsNotNull(location, "Space Engineers should be installed on developer machine"); Assert.IsTrue(Directory.Exists(location), "Filepath should exist on developer machine"); var contentPath = ToolboxUpdater.GetApplicationContentPath(); var magnesiumOre = SpaceEngineersApi.GetDefinition(SpaceEngineersTypes.Ore, "Magnesium"); var magnesiumOrePath = Path.Combine(contentPath, magnesiumOre.Icons.First()); Assert.IsTrue(File.Exists(magnesiumOrePath), "Filepath should exist on developer machine"); Assert.IsTrue(magnesiumOre is MyObjectBuilder_PhysicalItemDefinition, "Type should match"); var magnesiumOreBmp = TexUtil.CreateBitmap(magnesiumOrePath); ImageTextureUtil.WriteImage(magnesiumOreBmp, @".\TestOutput\Magnesium_Ore.png"); var goldIngot = SpaceEngineersApi.GetDefinition(SpaceEngineersTypes.Ingot, "Gold"); var goldIngotPath = Path.Combine(contentPath, goldIngot.Icons.First()); Assert.IsTrue(File.Exists(goldIngotPath), "Filepath should exist on developer machine"); Assert.IsTrue(goldIngot is MyObjectBuilder_PhysicalItemDefinition, "Type should match"); var goldIngotBmp = TexUtil.CreateBitmap(goldIngotPath); ImageTextureUtil.WriteImage(goldIngotBmp, @".\TestOutput\Gold_Ingot.png"); var ammoMagazine = SpaceEngineersApi.GetDefinition(SpaceEngineersTypes.AmmoMagazine, "NATO_5p56x45mm"); var ammoMagazinePath = Path.Combine(contentPath, ammoMagazine.Icons.First()); Assert.IsTrue(File.Exists(ammoMagazinePath), "Filepath should exist on developer machine"); Assert.IsTrue(ammoMagazine is MyObjectBuilder_AmmoMagazineDefinition, "Type should match"); var ammoMagazineBmp = TexUtil.CreateBitmap(ammoMagazinePath); ImageTextureUtil.WriteImage(ammoMagazineBmp, @".\TestOutput\NATO_5p56x45mm.png"); var steelPlate = SpaceEngineersApi.GetDefinition(SpaceEngineersTypes.Component, "SteelPlate"); var steelPlatePath = Path.Combine(contentPath, steelPlate.Icons.First()); Assert.IsTrue(File.Exists(steelPlatePath), "Filepath should exist on developer machine"); Assert.IsTrue(steelPlate is MyObjectBuilder_ComponentDefinition, "Type should match"); var steelPlateBmp = TexUtil.CreateBitmap(steelPlatePath); ImageTextureUtil.WriteImage(steelPlateBmp, @".\TestOutput\SteelPlate.png"); var smallBlockLandingGear = SpaceEngineersApi.GetDefinition(new MyObjectBuilderType(typeof(MyObjectBuilder_LandingGear)), "SmallBlockLandingGear"); var smallBlockLandingGearPath = Path.Combine(contentPath, smallBlockLandingGear.Icons.First()); Assert.IsTrue(File.Exists(smallBlockLandingGearPath), "Filepath should exist on developer machine"); Assert.IsTrue(smallBlockLandingGear is MyObjectBuilder_CubeBlockDefinition, "Type should match"); var smallBlockLandingGearBmp = TexUtil.CreateBitmap(smallBlockLandingGearPath); ImageTextureUtil.WriteImage(smallBlockLandingGearBmp, @".\TestOutput\SmallBlockLandingGear.png"); var gridItemPath = Path.Combine(contentPath, @"Textures\GUI\Controls\grid_item.dds"); Assert.IsTrue(File.Exists(gridItemPath), "Filepath should exist on developer machine"); var gridBmp = TexUtil.CreateBitmap(gridItemPath); ImageTextureUtil.WriteImage(gridBmp, @".\TestOutput\grid_item.png"); var sunPath = Path.Combine(contentPath, @"Textures\BackgroundCube\Prerender\Sun.dds"); Assert.IsTrue(File.Exists(sunPath), "Filepath should exist on developer machine"); var sunBmp = TexUtil.CreateBitmap(sunPath); ImageTextureUtil.WriteImage(sunBmp, @".\TestOutput\sun.png"); var goldPath = Path.Combine(contentPath, @"Textures\Voxels\Gold_01_ForAxisXZ_de.dds"); Assert.IsTrue(File.Exists(goldPath), "Filepath should exist on developer machine"); var goldBmp = TexUtil.CreateBitmap(goldPath); ImageTextureUtil.WriteImage(goldBmp, @".\TestOutput\gold.png"); var siliconPath = Path.Combine(contentPath, @"Textures\Voxels\Silicon_01_ForAxisXZ_de.dds"); Assert.IsTrue(File.Exists(siliconPath), "Filepath should exist on developer machine"); var siliconBmp = TexUtil.CreateBitmap(siliconPath); ImageTextureUtil.WriteImage(siliconBmp, @".\TestOutput\silicon.png"); var platinumPath = Path.Combine(contentPath, @"Textures\Voxels\Platinum_01_ForAxisXZ_de.dds"); Assert.IsTrue(File.Exists(platinumPath), "Filepath should exist on developer machine"); var platinumBmp = TexUtil.CreateBitmap(platinumPath); ImageTextureUtil.WriteImage(platinumBmp, @".\TestOutput\platinum.png"); var medicalDiffuseEmissivePath = Path.Combine(contentPath, @"Textures\Models\Cubes\large_medical_room_de.dds"); Assert.IsTrue(File.Exists(medicalDiffuseEmissivePath), "Filepath should exist on developer machine"); var medicalDiffuseEmissiveBmp = TexUtil.CreateBitmap(medicalDiffuseEmissivePath); ImageTextureUtil.WriteImage(medicalDiffuseEmissiveBmp, @".\TestOutput\large_medical_room_de.png"); medicalDiffuseEmissiveBmp = TexUtil.CreateBitmap(medicalDiffuseEmissivePath, true); ImageTextureUtil.WriteImage(medicalDiffuseEmissiveBmp, @".\TestOutput\large_medical_room.png"); var astronautMaskEmissivePath = Path.Combine(contentPath, @"Textures\Models\Characters\Astronaut\Astronaut_me.dds"); Assert.IsTrue(File.Exists(astronautMaskEmissivePath), "Filepath should exist on developer machine"); var astronautMaskEmissiveBmp = TexUtil.CreateBitmap(astronautMaskEmissivePath); ImageTextureUtil.WriteImage(astronautMaskEmissiveBmp, @".\TestOutput\Astronaut_me.png"); astronautMaskEmissiveBmp = TexUtil.CreateBitmap(astronautMaskEmissivePath, true); ImageTextureUtil.WriteImage(astronautMaskEmissiveBmp, @".\TestOutput\Astronaut_me2.png"); var astronautNormalSpecularPath = Path.Combine(contentPath, @"Textures\Models\Characters\Astronaut\Astronaut_ns.dds"); Assert.IsTrue(File.Exists(astronautNormalSpecularPath), "Filepath should exist on developer machine"); var astronautNormalSpecularBmp = TexUtil.CreateBitmap(astronautNormalSpecularPath); ImageTextureUtil.WriteImage(astronautNormalSpecularBmp, @".\TestOutput\Astronaut_ns.png"); astronautNormalSpecularBmp = TexUtil.CreateBitmap(astronautNormalSpecularPath, true); ImageTextureUtil.WriteImage(astronautNormalSpecularBmp, @".\TestOutput\Astronaut_ns2.png"); }
public void PixelEffectTextures() { SpaceEngineersCore.LoadDefinitions(); var location = ToolboxUpdater.GetApplicationFilePath(); Assert.IsNotNull(location, "Space Engineers should be installed on developer machine"); Assert.IsTrue(Directory.Exists(location), "Filepath should exist on developer machine"); var contentPath = ToolboxUpdater.GetApplicationContentPath(); // ---- var medicalDiffuseEmissivePath = Path.Combine(contentPath, @"Textures\Models\Cubes\large_medical_room_de.dds"); Assert.IsTrue(File.Exists(medicalDiffuseEmissivePath), "Filepath should exist on developer machine"); var medicalDiffuseEmissiveBmp = TexUtil.CreateBitmap(medicalDiffuseEmissivePath); ImageTextureUtil.WriteImage(medicalDiffuseEmissiveBmp, @".\TestOutput\large_medical_room_de.png"); var medicalDiffuseEmissiveBmp2 = TexUtil.CreateBitmap(medicalDiffuseEmissivePath, true); ImageTextureUtil.WriteImage(medicalDiffuseEmissiveBmp2, @".\TestOutput\large_medical_room_de_full.png"); IPixelEffect effect = new AlphaPixelEffect(); var medicalDiffuseEmissiveAlphaBmp = effect.Quantize(medicalDiffuseEmissiveBmp); ImageTextureUtil.WriteImage(medicalDiffuseEmissiveAlphaBmp, @".\TestOutput\large_medical_room_de_alpha.png"); effect = new EmissivePixelEffect(0); var medicalNormalSpecularEmissiveBmp = effect.Quantize(medicalDiffuseEmissiveBmp); ImageTextureUtil.WriteImage(medicalNormalSpecularEmissiveBmp, @".\TestOutput\large_medical_room_emissive.png"); var defaultImage = SEToolbox.ImageLibrary.ImageTextureUtil.CreateImage(medicalDiffuseEmissivePath, false, new EmissivePixelEffect(0)); // ---- var largeThrustDiffuseEmissivePath = Path.Combine(contentPath, @"Textures\Models\Cubes\large_thrust_large_me.dds"); Assert.IsTrue(File.Exists(largeThrustDiffuseEmissivePath), "Filepath should exist on developer machine"); var largeThrustDiffuseEmissiveBmp = TexUtil.CreateBitmap(largeThrustDiffuseEmissivePath); ImageTextureUtil.WriteImage(largeThrustDiffuseEmissiveBmp, @".\TestOutput\large_thrust_large_me.png"); var largeThrustDiffuseEmissiveBmp2 = TexUtil.CreateBitmap(largeThrustDiffuseEmissivePath, true); ImageTextureUtil.WriteImage(largeThrustDiffuseEmissiveBmp2, @".\TestOutput\large_thrust_large_me_full.png"); effect = new AlphaPixelEffect(); var largeThrustDiffuseEmissiveAlphaBmp = effect.Quantize(largeThrustDiffuseEmissiveBmp); ImageTextureUtil.WriteImage(largeThrustDiffuseEmissiveAlphaBmp, @".\TestOutput\large_thrust_large_me_alpha.png"); effect = new EmissivePixelEffect(0); var largeThrustNormalSpecularEmissiveBmp = effect.Quantize(largeThrustDiffuseEmissiveBmp); ImageTextureUtil.WriteImage(largeThrustNormalSpecularEmissiveBmp, @".\TestOutput\large_thrust_large_me_emissive.png"); // ---- var astronautMaskEmissivePath = Path.Combine(contentPath, @"Textures\Models\Characters\Astronaut\Astronaut_me.dds"); Assert.IsTrue(File.Exists(astronautMaskEmissivePath), "Filepath should exist on developer machine"); var astronautMaskEmissiveBmp = TexUtil.CreateBitmap(astronautMaskEmissivePath); ImageTextureUtil.WriteImage(astronautMaskEmissiveBmp, @".\TestOutput\Astronaut_me.png"); effect = new AlphaPixelEffect(); var astronautMaskEmissiveAlphaBmp = effect.Quantize(astronautMaskEmissiveBmp); ImageTextureUtil.WriteImage(astronautMaskEmissiveAlphaBmp, @".\TestOutput\Astronaut_me_alpha.png"); var astronautMaskEmissiveBmp2 = TexUtil.CreateBitmap(astronautMaskEmissivePath, true); ImageTextureUtil.WriteImage(astronautMaskEmissiveBmp2, @".\TestOutput\Astronaut_me_full.png"); effect = new EmissivePixelEffect(255); var astronautNormalSpecularEmissiveBmp = effect.Quantize(astronautMaskEmissiveBmp); ImageTextureUtil.WriteImage(astronautNormalSpecularEmissiveBmp, @".\TestOutput\Astronaut_me_emissive.png"); // ---- var astronautNormalSpecularPath = Path.Combine(contentPath, @"Textures\Models\Characters\Astronaut\Astronaut_ns.dds"); Assert.IsTrue(File.Exists(astronautNormalSpecularPath), "Filepath should exist on developer machine"); var astronautNormalSpecularBmp = TexUtil.CreateBitmap(astronautNormalSpecularPath); ImageTextureUtil.WriteImage(astronautNormalSpecularBmp, @".\TestOutput\Astronaut_ns.png"); }
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { if (value == null) { return(null); } if (!(value is string)) { throw new NotSupportedException(string.Format("{0} cannot convert from {1}.", GetType().FullName, value.GetType().FullName)); } var sizeParameter = parameter as string; var sizeArray = sizeParameter?.Split(','); int width = -1; int height = -1; bool noAlpha = false; if (sizeArray.Length > 0) { int.TryParse(sizeArray[0], out width); } if (sizeArray.Length > 1) { int.TryParse(sizeArray[1], out height); } if (sizeArray.Length > 2) { noAlpha = sizeArray[2].Equals("noalpha", StringComparison.OrdinalIgnoreCase); } var filename = (string)value; var extension = Path.GetExtension(filename).ToLower(); var name = filename; if (width != -1 && height != -1) { name += string.Format(",{0},{1}", width, height); } if (Cache.ContainsKey(name)) { return(Cache[name]); } if (extension == ".png") { try { // TODO: rescale the bitmap to specified width/height. var bitmapImage = new BitmapImage(); using (Stream textureStream = MyFileSystem.OpenRead(filename)) { var bitmap = (Bitmap)Image.FromStream(textureStream, true); using (var ms = new MemoryStream()) { bitmap.Save(ms, System.Drawing.Imaging.ImageFormat.Png); bitmapImage.BeginInit(); bitmapImage.StreamSource = ms; bitmapImage.CacheOption = BitmapCacheOption.OnLoad; bitmapImage.EndInit(); } } Cache.Add(name, bitmapImage); return(bitmapImage); } catch { return(null); } } if (extension == ".dds") { ImageSource image; using (Stream textureStream = MyFileSystem.OpenRead(filename)) { image = ImageTextureUtil.CreateImage(textureStream, 0, width, height, noAlpha); } Cache.Add(name, image); return(image); } return(null); }
public void LoadComponentTextures() { var location = ToolboxUpdater.GetApplicationFilePath(); Assert.IsNotNull(location, "Space Engineers should be installed on developer machine"); Assert.IsTrue(Directory.Exists(location), "Filepath should exist on developer machine"); var contentPath = ToolboxUpdater.GetApplicationContentPath(); //var ExplosivesComponentPath = Path.GetFullPath(@".\TestAssets\ExplosivesComponent.dds"); //var ExplosivesComponentBmp = TexUtil.CreateBitmap(ExplosivesComponentPath); //File.Copy(ExplosivesComponentPath, Path.Combine(_path, "ExplosivesComponent.dds"), true); //ImageTextureUtil.WriteImage(ExplosivesComponentBmp, Path.Combine(_path, @"ExplosivesComponent.png")); LoadTextureAndExport(@"C:\Program Files (x86)\Steam\steamapps\common\SpaceEngineers\Content\Textures\Models\Cubes\DoorBlock_cm.dds"); LoadTextureAndExport(Path.GetFullPath(@".\TestAssets\ExplosivesComponent.dds")); var magnesiumOre = MyDefinitionManager.Static.GetDefinition(SpaceEngineersTypes.Ore, "Magnesium"); var magnesiumOrePath = Path.Combine(contentPath, magnesiumOre.Icons.First()); Assert.IsTrue(File.Exists(magnesiumOrePath), "Filepath should exist on developer machine"); Assert.IsTrue(magnesiumOre is MyPhysicalItemDefinition, "Type should match"); var magnesiumOreBmp = TexUtil.CreateBitmap(magnesiumOrePath); var str = Path.GetFullPath(Path.Combine(_path, "Magnesium_Ore.dds")); File.Copy(magnesiumOrePath, Path.Combine(_path, "Magnesium_Ore.dds"), true); ImageTextureUtil.WriteImage(magnesiumOreBmp, Path.Combine(_path, @"Magnesium_Ore.png")); return; var goldIngot = MyDefinitionManager.Static.GetDefinition(SpaceEngineersTypes.Ingot, "Gold"); var goldIngotPath = Path.Combine(contentPath, goldIngot.Icons.First()); Assert.IsTrue(File.Exists(goldIngotPath), "Filepath should exist on developer machine"); Assert.IsTrue(goldIngot is MyPhysicalItemDefinition, "Type should match"); var goldIngotBmp = TexUtil.CreateBitmap(goldIngotPath); ImageTextureUtil.WriteImage(goldIngotBmp, @".\TestOutput\Gold_Ingot.png"); var ammoMagazine = MyDefinitionManager.Static.GetDefinition(SpaceEngineersTypes.AmmoMagazine, "NATO_5p56x45mm"); var ammoMagazinePath = Path.Combine(contentPath, ammoMagazine.Icons.First()); Assert.IsTrue(File.Exists(ammoMagazinePath), "Filepath should exist on developer machine"); Assert.IsTrue(ammoMagazine is MyAmmoMagazineDefinition, "Type should match"); var ammoMagazineBmp = TexUtil.CreateBitmap(ammoMagazinePath); ImageTextureUtil.WriteImage(ammoMagazineBmp, @".\TestOutput\NATO_5p56x45mm.png"); var steelPlate = MyDefinitionManager.Static.GetDefinition(SpaceEngineersTypes.Component, "SteelPlate"); var steelPlatePath = Path.Combine(contentPath, steelPlate.Icons.First()); Assert.IsTrue(File.Exists(steelPlatePath), "Filepath should exist on developer machine"); Assert.IsTrue(steelPlate is MyComponentDefinition, "Type should match"); var steelPlateBmp = TexUtil.CreateBitmap(steelPlatePath); ImageTextureUtil.WriteImage(steelPlateBmp, @".\TestOutput\SteelPlate.png"); var smallBlockLandingGear = MyDefinitionManager.Static.GetDefinition(new MyObjectBuilderType(typeof(MyObjectBuilder_LandingGear)), "SmallBlockLandingGear"); var smallBlockLandingGearPath = Path.Combine(contentPath, smallBlockLandingGear.Icons.First()); Assert.IsTrue(File.Exists(smallBlockLandingGearPath), "Filepath should exist on developer machine"); Assert.IsTrue(smallBlockLandingGear is MyCubeBlockDefinition, "Type should match"); var smallBlockLandingGearBmp = TexUtil.CreateBitmap(smallBlockLandingGearPath); ImageTextureUtil.WriteImage(smallBlockLandingGearBmp, @".\TestOutput\SmallBlockLandingGear.png"); var gridItemPath = Path.Combine(contentPath, @"Textures\GUI\Controls\grid_item.dds"); Assert.IsTrue(File.Exists(gridItemPath), "Filepath should exist on developer machine"); var gridBmp = TexUtil.CreateBitmap(gridItemPath); ImageTextureUtil.WriteImage(gridBmp, @".\TestOutput\grid_item.png"); var sunPath = Path.Combine(contentPath, @"Textures\BackgroundCube\Prerender\Sun.dds"); Assert.IsTrue(File.Exists(sunPath), "Filepath should exist on developer machine"); var sunBmp = TexUtil.CreateBitmap(sunPath); ImageTextureUtil.WriteImage(sunBmp, @".\TestOutput\sun.png"); var goldPath = Path.Combine(contentPath, @"Textures\Voxels\Gold_01_ForAxisXZ_cm.dds"); Assert.IsTrue(File.Exists(goldPath), "Filepath should exist on developer machine"); var goldBmp = TexUtil.CreateBitmap(goldPath); ImageTextureUtil.WriteImage(goldBmp, @".\TestOutput\gold.png"); var siliconPath = Path.Combine(contentPath, @"Textures\Voxels\Silicon_01_ForAxisXZ_cm.dds"); Assert.IsTrue(File.Exists(siliconPath), "Filepath should exist on developer machine"); var siliconBmp = TexUtil.CreateBitmap(siliconPath); ImageTextureUtil.WriteImage(siliconBmp, @".\TestOutput\silicon.png"); var platinumPath = Path.Combine(contentPath, @"Textures\Voxels\Platinum_01_ForAxisXZ_cm.dds"); Assert.IsTrue(File.Exists(platinumPath), "Filepath should exist on developer machine"); var platinumBmp = TexUtil.CreateBitmap(platinumPath); ImageTextureUtil.WriteImage(platinumBmp, @".\TestOutput\platinum.png"); var medicalMetallicPath = Path.Combine(contentPath, @"Textures\Models\Cubes\large_medical_room_cm.dds"); Assert.IsTrue(File.Exists(medicalMetallicPath), "Filepath should exist on developer machine"); var medicalMetallicBmp = TexUtil.CreateBitmap(medicalMetallicPath); ImageTextureUtil.WriteImage(medicalMetallicBmp, @".\TestOutput\large_medical_room_cm.png"); medicalMetallicBmp = TexUtil.CreateBitmap(medicalMetallicPath, true); ImageTextureUtil.WriteImage(medicalMetallicBmp, @".\TestOutput\large_medical_room.png"); var astronautMetallicPath = Path.Combine(contentPath, @"Textures\Models\Characters\Astronaut\Astronaut_cm.dds"); Assert.IsTrue(File.Exists(astronautMetallicPath), "Filepath should exist on developer machine"); var astronautMetallicBmp = TexUtil.CreateBitmap(astronautMetallicPath); ImageTextureUtil.WriteImage(astronautMetallicBmp, @".\TestOutput\Astronaut_cm.png"); astronautMetallicBmp = TexUtil.CreateBitmap(astronautMetallicPath, true); ImageTextureUtil.WriteImage(astronautMetallicBmp, @".\TestOutput\Astronaut_me2.png"); var astronautNormalGlossPath = Path.Combine(contentPath, @"Textures\Models\Characters\Astronaut\Astronaut_ng.dds"); Assert.IsTrue(File.Exists(astronautNormalGlossPath), "Filepath should exist on developer machine"); var astronautNormalGlossBmp = TexUtil.CreateBitmap(astronautNormalGlossPath); ImageTextureUtil.WriteImage(astronautNormalGlossBmp, @".\TestOutput\Astronaut_ng.png"); astronautNormalGlossBmp = TexUtil.CreateBitmap(astronautNormalGlossPath, true); ImageTextureUtil.WriteImage(astronautNormalGlossBmp, @".\TestOutput\Astronaut_ng2.png"); }