From 884eeaef54009e54a96c2ba26affe4a7fe98476a Mon Sep 17 00:00:00 2001 From: miku-666 <74728189+NessieHax@users.noreply.github.com> Date: Sun, 29 Oct 2023 12:16:29 +0100 Subject: [PATCH] Updated SkinPreview to use SkinRenderer control and use it when double clicking a skin file --- .../SkinPreview.Designer.cs | 4 +- .../Forms/Skins-And-Textures/SkinPreview.cs | 37 ++++++++----------- PCK-Studio/MainForm.Designer.cs | 11 +----- PCK-Studio/MainForm.cs | 19 +++++----- PCK-Studio/PckStudio.csproj | 5 +-- PCK-Studio/Resources/shader/skinFragment.glsl | 4 +- 6 files changed, 30 insertions(+), 50 deletions(-) diff --git a/PCK-Studio/Forms/Skins-And-Textures/SkinPreview.Designer.cs b/PCK-Studio/Forms/Skins-And-Textures/SkinPreview.Designer.cs index f1fa7241..9b5752fc 100644 --- a/PCK-Studio/Forms/Skins-And-Textures/SkinPreview.Designer.cs +++ b/PCK-Studio/Forms/Skins-And-Textures/SkinPreview.Designer.cs @@ -31,7 +31,7 @@ namespace PckStudio.Forms { this.components = new System.ComponentModel.Container(); System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(SkinPreview)); - this.ModelView = new PckStudio.Rendering.Renderer3D(); + this.ModelView = new PckStudio.Rendering.SkinRenderer(); this.SuspendLayout(); // // ModelView @@ -63,6 +63,6 @@ namespace PckStudio.Forms #endregion - private PckStudio.Rendering.Renderer3D ModelView; + private PckStudio.Rendering.SkinRenderer ModelView; } } \ No newline at end of file diff --git a/PCK-Studio/Forms/Skins-And-Textures/SkinPreview.cs b/PCK-Studio/Forms/Skins-And-Textures/SkinPreview.cs index 5a2370a5..4334f2ca 100644 --- a/PCK-Studio/Forms/Skins-And-Textures/SkinPreview.cs +++ b/PCK-Studio/Forms/Skins-And-Textures/SkinPreview.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.Drawing; using System.Windows.Forms; using PckStudio.Internal; @@ -8,34 +9,26 @@ namespace PckStudio.Forms { public partial class SkinPreview : Form { - Image Texture; + public SkinANIM ANIM { get; set; } - public SkinPreview(Image texture, SkinANIM anim) + private Image _texture; + + public SkinPreview() { InitializeComponent(); - Texture = texture; - - //ModelView.ShowHead = !anim.GetFlag(SkinAnimFlag.HEAD_DISABLED); - //ModelView.ShowHeadOverlay = !anim.GetFlag(SkinAnimFlag.HEAD_OVERLAY_DISABLED); - //ModelView.ShowBody = !anim.GetFlag(SkinAnimFlag.BODY_DISABLED); - //ModelView.ShowBodyOverlay = !anim.GetFlag(SkinAnimFlag.BODY_OVERLAY_DISABLED); - - //ModelView.ShowLeftArm = !anim.GetFlag(SkinAnimFlag.LEFT_ARM_DISABLED); - //ModelView.ShowLeftArmOverlay = !anim.GetFlag(SkinAnimFlag.LEFT_ARM_OVERLAY_DISABLED); - //ModelView.ShowRightArm = !anim.GetFlag(SkinAnimFlag.RIGHT_ARM_DISABLED); - //ModelView.ShowRightArmOverlay = !anim.GetFlag(SkinAnimFlag.RIGHT_ARM_OVERLAY_DISABLED); - - //ModelView.ShowLeftLeg = !anim.GetFlag(SkinAnimFlag.LEFT_LEG_DISABLED); - //ModelView.ShowLeftLegOverlay = !anim.GetFlag(SkinAnimFlag.LEFT_LEG_OVERLAY_DISABLED); - //ModelView.ShowRightLeg = !anim.GetFlag(SkinAnimFlag.RIGHT_LEG_DISABLED); - //ModelView.ShowRightLegOverlay = !anim.GetFlag(SkinAnimFlag.RIGHT_LEG_OVERLAY_DISABLED); } - private void SkinPreview_Load(object sender, EventArgs e) => RenderModel(Texture); - - public void RenderModel(Image source) + public SkinPreview(Image texture, IEnumerable modelData) + : this() { - //ModelView.Texture = source as Bitmap; + _texture = texture; + ModelView.ModelData.AddRange(modelData); + } + + private void SkinPreview_Load(object sender, EventArgs e) + { + ModelView.ANIM = ANIM; + ModelView.Texture = _texture as Bitmap; } } } diff --git a/PCK-Studio/MainForm.Designer.cs b/PCK-Studio/MainForm.Designer.cs index 84c5d271..94e00784 100644 --- a/PCK-Studio/MainForm.Designer.cs +++ b/PCK-Studio/MainForm.Designer.cs @@ -146,7 +146,6 @@ this.imageList = new System.Windows.Forms.ImageList(this.components); this.previewPictureBox = new PckStudio.ToolboxItems.InterpolationPictureBox(); this.LittleEndianCheckBox = new MetroFramework.Controls.MetroCheckBox(); - this.skinRenderer3DToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); logoPictureBox = new System.Windows.Forms.PictureBox(); toolStripSeparator1 = new System.Windows.Forms.ToolStripSeparator(); ((System.ComponentModel.ISupportInitialize)(logoPictureBox)).BeginInit(); @@ -570,8 +569,7 @@ this.miscToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { this.addCustomPackImageToolStripMenuItem, this.openPckManagerToolStripMenuItem, - this.convertMusicFilesToolStripMenuItem, - this.skinRenderer3DToolStripMenuItem}); + this.convertMusicFilesToolStripMenuItem}); this.miscToolStripMenuItem.ForeColor = System.Drawing.Color.Silver; this.miscToolStripMenuItem.Name = "miscToolStripMenuItem"; resources.ApplyResources(this.miscToolStripMenuItem, "miscToolStripMenuItem"); @@ -1094,12 +1092,6 @@ this.LittleEndianCheckBox.Theme = MetroFramework.MetroThemeStyle.Dark; this.LittleEndianCheckBox.UseSelectable = true; // - // skinRenderer3DToolStripMenuItem - // - this.skinRenderer3DToolStripMenuItem.Name = "skinRenderer3DToolStripMenuItem"; - resources.ApplyResources(this.skinRenderer3DToolStripMenuItem, "skinRenderer3DToolStripMenuItem"); - this.skinRenderer3DToolStripMenuItem.Click += new System.EventHandler(this.skinRenderer3DToolStripMenuItem_Click); - // // MainForm // this.ApplyImageInvert = true; @@ -1250,7 +1242,6 @@ private System.Windows.Forms.ToolStripMenuItem forMattNLContributorToolStripMenuItem; private System.Windows.Forms.ToolStripMenuItem settingsToolStripMenuItem; private System.Windows.Forms.ToolStripMenuItem checkForUpdatesToolStripMenuItem; - private System.Windows.Forms.ToolStripMenuItem skinRenderer3DToolStripMenuItem; } } diff --git a/PCK-Studio/MainForm.cs b/PCK-Studio/MainForm.cs index 1e974d40..6d2e91cb 100644 --- a/PCK-Studio/MainForm.cs +++ b/PCK-Studio/MainForm.cs @@ -427,6 +427,11 @@ namespace PckStudio public void HandleSkinFile(PckFileData file) { + var renderForm = new SkinPreview(file.GetTexture(), file.Properties.GetProperties("BOX").Select(kv => SkinBOX.FromString(kv.Value))); + renderForm.ANIM = file.Properties.GetPropertyValue("ANIM", SkinANIM.FromString); + renderForm.ShowDialog(); + return; + if (file.Properties.HasProperty("BOX")) { using generateModel generate = new generateModel(file); @@ -439,10 +444,10 @@ namespace PckStudio return; } - var img = file.GetTexture(); - using var skinViewer = new SkinPreview(img, file.Properties.GetPropertyValue("ANIM", SkinANIM.FromString)); - skinViewer.ShowDialog(this); - } + var skinPreview = new SkinPreview(file.GetTexture(), file.Properties.GetProperties("BOX").Select(kv => SkinBOX.FromString(kv.Value))); + skinPreview.ANIM = file.Properties.GetPropertyValue("ANIM", SkinANIM.FromString); + skinPreview.ShowDialog(); + } public void HandleModelsFile(PckFileData file) { @@ -2278,11 +2283,5 @@ namespace PckStudio } MessageBox.Show("Already up to date.", "No update available"); } - - private void skinRenderer3DToolStripMenuItem_Click(object sender, EventArgs e) - { - var gl = new TestGL(); - gl.Show(); - } } } \ No newline at end of file diff --git a/PCK-Studio/PckStudio.csproj b/PCK-Studio/PckStudio.csproj index f181fb8a..e0ad7924 100644 --- a/PCK-Studio/PckStudio.csproj +++ b/PCK-Studio/PckStudio.csproj @@ -87,7 +87,7 @@ - PckStudio.Forms.TestGL + PckStudio.Program @@ -558,9 +558,6 @@ TextureAtlasEditor.cs - - TestGL.cs - MainForm.cs Designer diff --git a/PCK-Studio/Resources/shader/skinFragment.glsl b/PCK-Studio/Resources/shader/skinFragment.glsl index fdd6d42c..2776f3c6 100644 --- a/PCK-Studio/Resources/shader/skinFragment.glsl +++ b/PCK-Studio/Resources/shader/skinFragment.glsl @@ -3,11 +3,11 @@ layout(location = 0) out vec4 color; uniform sampler2D u_Texture; +uniform vec2 u_TexScale; in vec2 v_TexCoord; void main() { - vec4 texColor = texture(u_Texture, v_TexCoord); - color = texColor; + color = texture(u_Texture, v_TexCoord * u_TexScale); }; \ No newline at end of file