From 00a48d4b4aed1ed41c09724376f9732b9ee42297 Mon Sep 17 00:00:00 2001 From: KillzXGaming Date: Fri, 28 Feb 2020 16:52:24 -0500 Subject: [PATCH] Some adjustments --- .../FileFormats/Assimp/Assimp.cs | 10 ++- .../Forms/Custom/STButtonToggle.cs | 89 +++++++++++++++++++ Switch_Toolbox_Library/IO/Colors/STColor.cs | 5 ++ Switch_Toolbox_Library/IO/STFileLoader.cs | 2 + .../Interfaces/FileFormatting/IArchiveFile.cs | 2 +- .../Gamecube/Decode_Gamecube.cs | 34 +++++++ Switch_Toolbox_Library/Toolbox_Library.csproj | 3 + Toolbox/Shader/LevelEditor/ProbeSphere.frag | 33 +------ 8 files changed, 142 insertions(+), 36 deletions(-) create mode 100644 Switch_Toolbox_Library/Forms/Custom/STButtonToggle.cs diff --git a/Switch_Toolbox_Library/FileFormats/Assimp/Assimp.cs b/Switch_Toolbox_Library/FileFormats/Assimp/Assimp.cs index e8c33636..3e34b451 100644 --- a/Switch_Toolbox_Library/FileFormats/Assimp/Assimp.cs +++ b/Switch_Toolbox_Library/FileFormats/Assimp/Assimp.cs @@ -20,6 +20,8 @@ namespace Toolbox.Library public bool RotateSkeleton = false; public float RotateSkeletonAmount = 90; + static bool isDae; + public Scene scene; public List objects = new List(); @@ -73,8 +75,10 @@ namespace Toolbox.Library scene = Importer.ImportFile(FileName, settings.GetFlags()); - if (Utils.GetExtension(FileName) == ".dae") + if (Utils.GetExtension(FileName) == ".dae") { GetRealNodeNames(FileName); + isDae = true; + } STConsole.WriteLine($"UnitScale {UnitScale}"); @@ -733,9 +737,9 @@ namespace Toolbox.Library vert.uv2 = new Vector2(msh.TextureCoordinateChannels[2][v].X, msh.TextureCoordinateChannels[2][v].Y); if (msh.HasTangentBasis) vert.tan = new Vector4(msh.Tangents[v].X, msh.Tangents[v].Y, msh.Tangents[v].Z, 1); - if (msh.HasVertexColors(0)) + if (msh.HasVertexColors(0) && !isDae) vert.col = new Vector4(msh.VertexColorChannels[0][v].R, msh.VertexColorChannels[0][v].G, msh.VertexColorChannels[0][v].B, msh.VertexColorChannels[0][v].A); - if (msh.HasVertexColors(1)) + if (msh.HasVertexColors(1) && !isDae) vert.col2 = new Vector4(msh.VertexColorChannels[1][v].R, msh.VertexColorChannels[1][v].G, msh.VertexColorChannels[1][v].B, msh.VertexColorChannels[1][v].A); if (msh.HasTangentBasis) vert.bitan = new Vector4(msh.BiTangents[v].X, msh.BiTangents[v].Y, msh.BiTangents[v].Z, 1); diff --git a/Switch_Toolbox_Library/Forms/Custom/STButtonToggle.cs b/Switch_Toolbox_Library/Forms/Custom/STButtonToggle.cs new file mode 100644 index 00000000..639d66a5 --- /dev/null +++ b/Switch_Toolbox_Library/Forms/Custom/STButtonToggle.cs @@ -0,0 +1,89 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; +using Toolbox.Library.IO; +using System.Drawing; +using System.Drawing.Drawing2D; + +namespace Toolbox.Library.Forms +{ + public class STButtonToggle : STPanel + { + private bool check; + public bool Checked + { + get { return check; } + set { + check = value; + this.Refresh(); + } + } + + public string PropertyText { get; set; } + + public Color BtnBackColor + { + get + { + if (Checked) + return FormThemes.BaseTheme.CheckBoxEnabledBackColor; + else + return FormThemes.BaseTheme.CheckBoxBackColor; + } + } + + public Color BtnForeColor + { + get + { + if (Checked) + return FormThemes.BaseTheme.FormForeColor; + else + return FormThemes.BaseTheme.DisabledItemColor; + } + } + + protected override void OnPaint(PaintEventArgs e) + { + base.OnPaint(e); + + Rectangle r = e.ClipRectangle; + if (r.Width <= 0 || r.Height <= 0) + return; + + Color c1 = BtnBackColor; + Color c2 = BtnBackColor.Darken(20); + LinearGradientBrush br = new LinearGradientBrush(r, c1, c2, 90, true); + + ColorBlend cb = new ColorBlend(); + cb.Positions = new[] { 0.0f, 1.0f }; + cb.Colors = new[] { c1, c2 }; + br.InterpolationColors = cb; + + SolidBrush br2 = new SolidBrush(BtnForeColor); + + int tx2 = ClientSize.Width / 2; + int ty2 = ClientSize.Height / 2 - 6; + + e.Graphics.FillRectangle(br, r); + + StringFormat sf = new StringFormat(); + sf.LineAlignment = StringAlignment.Center; + sf.Alignment = StringAlignment.Center; + e.Graphics.DrawString(PropertyText, this.Font, br2, ClientRectangle, sf); + } + + protected override void OnMouseClick(MouseEventArgs e) + { + base.OnMouseClick(e); + + if (Checked) + Checked = false; + else + Checked = true; + } + } +} diff --git a/Switch_Toolbox_Library/IO/Colors/STColor.cs b/Switch_Toolbox_Library/IO/Colors/STColor.cs index a7323ad5..3ab3e064 100644 --- a/Switch_Toolbox_Library/IO/Colors/STColor.cs +++ b/Switch_Toolbox_Library/IO/Colors/STColor.cs @@ -60,6 +60,11 @@ namespace Toolbox.Library return col; } + public OpenTK.Vector4 ToVector4() + { + return new OpenTK.Vector4(R,G,B,A); + } + public STColor(Color color) { R = color.R / 255f; diff --git a/Switch_Toolbox_Library/IO/STFileLoader.cs b/Switch_Toolbox_Library/IO/STFileLoader.cs index a220a43a..f1cc277a 100644 --- a/Switch_Toolbox_Library/IO/STFileLoader.cs +++ b/Switch_Toolbox_Library/IO/STFileLoader.cs @@ -76,6 +76,8 @@ namespace Toolbox.Library.IO if (fileFormat.Identify(stream) && fileFormat.GetType() == type) { fileFormat.IFileInfo = new IFileInfo(); + fileFormat.FileName = Path.GetFileName(FileName); + fileFormat.FilePath = FileName; return OpenFileFormat(stream, FileName); } } diff --git a/Switch_Toolbox_Library/Interfaces/FileFormatting/IArchiveFile.cs b/Switch_Toolbox_Library/Interfaces/FileFormatting/IArchiveFile.cs index e4a7c731..ae3c2b34 100644 --- a/Switch_Toolbox_Library/Interfaces/FileFormatting/IArchiveFile.cs +++ b/Switch_Toolbox_Library/Interfaces/FileFormatting/IArchiveFile.cs @@ -99,7 +99,7 @@ namespace Toolbox.Library else { return STFileLoader.OpenFileFormat(new MemoryStream(FileData), - IOExtensions.RemoveIllegaleFolderNameCharacters( FileName), false, true); + IOExtensions.RemoveIllegaleFolderNameCharacters(FileName), false, true); } } diff --git a/Switch_Toolbox_Library/Texture Decoding/Gamecube/Decode_Gamecube.cs b/Switch_Toolbox_Library/Texture Decoding/Gamecube/Decode_Gamecube.cs index be84e379..b540f15a 100644 --- a/Switch_Toolbox_Library/Texture Decoding/Gamecube/Decode_Gamecube.cs +++ b/Switch_Toolbox_Library/Texture Decoding/Gamecube/Decode_Gamecube.cs @@ -1142,6 +1142,40 @@ namespace Toolbox.Library break; } } + + public static Tuple, ushort[]> GenerateMipList(byte[] uncompressedData, uint TexWidth, uint TexHeight, + uint MipCount, TextureFormats Format, PaletteFormats PaletteFormat) + { + Bitmap Image = BitmapExtension.GetBitmap(uncompressedData, (int)TexWidth, (int)TexHeight); + return GenerateMipList(Image, TexWidth, TexHeight, MipCount, Format, PaletteFormat); + } + + public static Tuple, ushort[]> GenerateMipList(Bitmap Image, uint TexWidth, uint TexHeight, + uint MipCount, TextureFormats Format, PaletteFormats PaletteFormat) + { + ushort[] paletteData = new ushort[0]; + + List mipmaps = new List(); + for (int mipLevel = 0; mipLevel < MipCount; mipLevel++) + { + int MipWidth = Math.Max(1, (int)TexWidth >> mipLevel); + int MipHeight = Math.Max(1, (int)TexHeight >> mipLevel); + + if (mipLevel != 0) + Image = BitmapExtension.Resize(Image, MipWidth, MipHeight); + + var EncodedData = Decode_Gamecube.EncodeData(BitmapExtension.ImageToByte(Image), Format, PaletteFormat, MipWidth, MipHeight); + + mipmaps.Add(EncodedData.Item1); + + if (mipLevel == 0) //Set palette data once + paletteData = EncodedData.Item2; + } + Image.Dispose(); + + return Tuple.Create(mipmaps, paletteData); + } + #endregion } } diff --git a/Switch_Toolbox_Library/Toolbox_Library.csproj b/Switch_Toolbox_Library/Toolbox_Library.csproj index 19e1ac8b..52eede1a 100644 --- a/Switch_Toolbox_Library/Toolbox_Library.csproj +++ b/Switch_Toolbox_Library/Toolbox_Library.csproj @@ -296,6 +296,9 @@ Component + + Component + Component diff --git a/Toolbox/Shader/LevelEditor/ProbeSphere.frag b/Toolbox/Shader/LevelEditor/ProbeSphere.frag index 8f3eaa22..983aa31c 100644 --- a/Toolbox/Shader/LevelEditor/ProbeSphere.frag +++ b/Toolbox/Shader/LevelEditor/ProbeSphere.frag @@ -43,39 +43,8 @@ vec3 CalculateIrradiance() ); } -vec3 aglSH2Rgb( vec3 normal, - vec4 sh00, - vec4 sh01, - vec4 sh02, - vec4 sh10, - vec4 sh11, - vec4 sh12, - vec4 sh2 ) -{ - vec4 normal4 = vec4( normal.x, normal.y, normal.z, 1.0 ); - - vec3 x0; - x0.r = dot( sh00, normal4 ); - x0.g = dot( sh01, normal4 ); - x0.b = dot( sh02, normal4 ); - - vec4 v_b = normal4.xyzz * normal4.yzzx; - vec3 x1; - x1.r = dot( sh10, v_b ); - x1.g = dot( sh11, v_b ); - x1.b = dot( sh12, v_b ); - - float v_c = normal4.x * normal4.x - normal4.y * normal4.y; - vec3 x2 = sh2.rgb * v_c; - - return max( ( x0 + x1 + x2 ), 0.0 ); -} - void main() { - vec3 irr = aglSH2Rgb(vec3(1,1,1), - coefficent0,coefficent1,coefficent2, - coefficent3,coefficent4,coefficent5,coefficent6); - // irr = CalculateIrradiance(); + vec3 irr = CalculateIrradiance(); FragColor = vec4(irr, 1.0); } \ No newline at end of file