diff --git a/PCK-Studio/Forms/Skins-And-Textures/CustomSkinEditor.Designer.cs b/PCK-Studio/Forms/Editor/CustomSkinEditor.Designer.cs similarity index 99% rename from PCK-Studio/Forms/Skins-And-Textures/CustomSkinEditor.Designer.cs rename to PCK-Studio/Forms/Editor/CustomSkinEditor.Designer.cs index c6067df2..b7074008 100644 --- a/PCK-Studio/Forms/Skins-And-Textures/CustomSkinEditor.Designer.cs +++ b/PCK-Studio/Forms/Editor/CustomSkinEditor.Designer.cs @@ -1,4 +1,4 @@ -namespace PckStudio.Forms +namespace PckStudio.Forms.Editor { partial class CustomSkinEditor { @@ -60,13 +60,13 @@ this.clampToViewCheckbox = new MetroFramework.Controls.MetroCheckBox(); this.captureScreenshotButton = new MetroFramework.Controls.MetroButton(); this.showToolsCheckBox = new MetroFramework.Controls.MetroCheckBox(); - this.renderer3D1 = new PckStudio.Rendering.SkinRenderer(); - this.uvPictureBox = new PckStudio.ToolboxItems.InterpolationPictureBox(); this.skinNameLabel = new MetroFramework.Controls.MetroLabel(); this.metroTabControl1 = new MetroFramework.Controls.MetroTabControl(); this.skinPartsTabPage = new System.Windows.Forms.TabPage(); this.skinOffsetsTabPage = new System.Windows.Forms.TabPage(); this.offsetListBox = new System.Windows.Forms.ListBox(); + this.renderer3D1 = new PckStudio.Rendering.SkinRenderer(); + this.uvPictureBox = new PckStudio.ToolboxItems.InterpolationPictureBox(); label5 = new System.Windows.Forms.Label(); label3 = new System.Windows.Forms.Label(); label7 = new System.Windows.Forms.Label(); @@ -80,10 +80,10 @@ ((System.ComponentModel.ISupportInitialize)(this.PosZUpDown)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.PosYUpDown)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.PosXUpDown)).BeginInit(); - ((System.ComponentModel.ISupportInitialize)(this.uvPictureBox)).BeginInit(); this.metroTabControl1.SuspendLayout(); this.skinPartsTabPage.SuspendLayout(); this.skinOffsetsTabPage.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.uvPictureBox)).BeginInit(); this.SuspendLayout(); // // label5 @@ -314,6 +314,7 @@ resources.ApplyResources(this.skinPartListBox, "skinPartListBox"); this.skinPartListBox.FormattingEnabled = true; this.skinPartListBox.Name = "skinPartListBox"; + this.skinPartListBox.Tag = ""; this.skinPartListBox.SelectedIndexChanged += new System.EventHandler(this.skinPartListBox_SelectedIndexChanged); this.skinPartListBox.DoubleClick += new System.EventHandler(this.skinPartListBox_DoubleClick); // @@ -341,25 +342,6 @@ this.showToolsCheckBox.Theme = MetroFramework.MetroThemeStyle.Dark; this.showToolsCheckBox.UseSelectable = true; // - // renderer3D1 - // - resources.ApplyResources(this.renderer3D1, "renderer3D1"); - this.renderer3D1.BackColor = System.Drawing.Color.DimGray; - this.renderer3D1.ClampModel = false; - this.renderer3D1.Name = "renderer3D1"; - this.renderer3D1.RefreshRate = 50; - this.renderer3D1.Texture = null; - this.renderer3D1.VSync = true; - this.renderer3D1.TextureChanging += new System.EventHandler(this.renderer3D1_TextureChanging); - // - // uvPictureBox - // - resources.ApplyResources(this.uvPictureBox, "uvPictureBox"); - this.uvPictureBox.BackgroundInterpolationMode = System.Drawing.Drawing2D.InterpolationMode.NearestNeighbor; - this.uvPictureBox.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.NearestNeighbor; - this.uvPictureBox.Name = "uvPictureBox"; - this.uvPictureBox.TabStop = false; - // // skinNameLabel // resources.ApplyResources(this.skinNameLabel, "skinNameLabel"); @@ -395,6 +377,24 @@ this.offsetListBox.FormattingEnabled = true; this.offsetListBox.Name = "offsetListBox"; // + // renderer3D1 + // + resources.ApplyResources(this.renderer3D1, "renderer3D1"); + this.renderer3D1.BackColor = System.Drawing.Color.DimGray; + this.renderer3D1.ClampModel = false; + this.renderer3D1.Name = "renderer3D1"; + this.renderer3D1.RefreshRate = 50; + this.renderer3D1.Texture = null; + this.renderer3D1.VSync = true; + // + // uvPictureBox + // + resources.ApplyResources(this.uvPictureBox, "uvPictureBox"); + this.uvPictureBox.BackgroundInterpolationMode = System.Drawing.Drawing2D.InterpolationMode.NearestNeighbor; + this.uvPictureBox.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.NearestNeighbor; + this.uvPictureBox.Name = "uvPictureBox"; + this.uvPictureBox.TabStop = false; + // // CustomSkinEditor // resources.ApplyResources(this, "$this"); @@ -404,10 +404,10 @@ this.Controls.Add(this.showToolsCheckBox); this.Controls.Add(this.captureScreenshotButton); this.Controls.Add(this.clampToViewCheckbox); - this.Controls.Add(this.renderer3D1); this.Controls.Add(this.PosZUpDown); this.Controls.Add(this.PosYUpDown); this.Controls.Add(this.PosXUpDown); + this.Controls.Add(this.renderer3D1); this.Controls.Add(this.TextureYUpDown); this.Controls.Add(this.TextureXUpDown); this.Controls.Add(this.SizeZUpDown); @@ -440,10 +440,10 @@ ((System.ComponentModel.ISupportInitialize)(this.PosZUpDown)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.PosYUpDown)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.PosXUpDown)).EndInit(); - ((System.ComponentModel.ISupportInitialize)(this.uvPictureBox)).EndInit(); this.metroTabControl1.ResumeLayout(false); this.skinPartsTabPage.ResumeLayout(false); this.skinOffsetsTabPage.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)(this.uvPictureBox)).EndInit(); this.ResumeLayout(false); this.PerformLayout(); diff --git a/PCK-Studio/Forms/Skins-And-Textures/CustomSkinEditor.cs b/PCK-Studio/Forms/Editor/CustomSkinEditor.cs similarity index 74% rename from PCK-Studio/Forms/Skins-And-Textures/CustomSkinEditor.cs rename to PCK-Studio/Forms/Editor/CustomSkinEditor.cs index 10cfe673..2d55577f 100644 --- a/PCK-Studio/Forms/Skins-And-Textures/CustomSkinEditor.cs +++ b/PCK-Studio/Forms/Editor/CustomSkinEditor.cs @@ -14,9 +14,10 @@ using OMI.Formats.Pck; using PckStudio.Internal; using PckStudio.Extensions; -using PckStudio.Forms.Editor; +using PckStudio.IO.CSMB; +using PckStudio.FileFormats; -namespace PckStudio.Forms +namespace PckStudio.Forms.Editor { public partial class CustomSkinEditor : MetroForm { @@ -35,11 +36,24 @@ namespace PckStudio.Forms PixelOffsetMode = PixelOffsetMode.HighQuality, }; - public CustomSkinEditor(PckFileData file) + private CustomSkinEditor() { InitializeComponent(); + } + public CustomSkinEditor(PckFileData file) : this() + { _file = file; + + if (DesignMode) + return; + renderer3D1.RefreshRate = 50; + renderer3D1.Texture = null; + renderer3D1.VSync = true; + renderer3D1.TextureChanging += new System.EventHandler(renderer3D1_TextureChanging); + renderer3D1.InitializeGL(); + + Controls.Add(renderer3D1); rng = new Random(); if (_file.Size > 0) { @@ -156,28 +170,32 @@ namespace PckStudio.Forms private void importCustomSkinButton_Click(object sender, EventArgs e) { OpenFileDialog openFileDialog = new OpenFileDialog(); - openFileDialog.Filter = "Custom Skin Model File | *.CSM"; - openFileDialog.Title = "Select Custom Skin Model File"; + openFileDialog.Filter = "Custom Skin Model File (*.csm,*.CSM)|*.csm;*.CSM|Custom Skin Model Binary File (*.csmb)|*.csmb"; + openFileDialog.Title = "Select File"; if (MessageBox.Show("Import custom model project file? Your current work will be lost!", "", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1) == DialogResult.Yes && openFileDialog.ShowDialog() == DialogResult.OK) { - renderer3D1.ModelData.Clear(); - StreamReader reader = new StreamReader(openFileDialog.FileName); - while (!reader.EndOfStream) + string fileExtension = Path.GetExtension(openFileDialog.FileName); + if (fileExtension == ".csmb") { - reader.ReadLine(); - string part = reader.ReadLine(); - reader.ReadLine(); - var PosX = reader.ReadLine(); - var PosY = reader.ReadLine(); - var PosZ = reader.ReadLine(); - var SizeX = reader.ReadLine(); - var SizeY = reader.ReadLine(); - var SizeZ = reader.ReadLine(); - var UvX = reader.ReadLine(); - var UvY = reader.ReadLine(); - renderer3D1.ModelData.Add(SkinBOX.FromString($"{part} {PosX} {PosY} {PosZ} {SizeX} {SizeY} {SizeZ} {UvX} {UvY}")); + var reader = new CSMBFileReader(); + CSMBFile csmbFile = reader.FromFile(openFileDialog.FileName); + LoadCsmb(csmbFile); } - skinPartListBindingSource.ResetBindings(false); + } + } + + private void LoadCsmb(CSMBFile csmbFile) + { + renderer3D1.ModelData.Clear(); + foreach (var part in csmbFile.Parts) + { + renderer3D1.ModelData.Add(part); + } + + renderer3D1.ResetOffsets(); + foreach (var offset in csmbFile.Offsets) + { + renderer3D1.SetPartOffset(offset); } } @@ -201,70 +219,22 @@ namespace PckStudio.Forms private void generateModel_FormClosing(object sender, FormClosingEventArgs e) { - /*if (MessageBox.Show("You done here?", "", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.No) - { - e.Cancel = true; - return; - } - e.Cancel = false;*/ + } + // TODO: re-implement comletely private void OpenJSONButton_Click(object sender, EventArgs e) { OpenFileDialog openFileDialog = new OpenFileDialog(); openFileDialog.Filter = "JSON Model File | *.JSON"; openFileDialog.Title = "Select JSON Model File"; - if (MessageBox.Show("Import custom model project file? Your current work will be lost!", "", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1) == DialogResult.Yes && openFileDialog.ShowDialog() == DialogResult.OK) + if (MessageBox.Show( + "Import custom model project file? Your current work will be lost!", "", + MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1) == DialogResult.Yes && + openFileDialog.ShowDialog() == DialogResult.OK) { - //listViewBoxes.Items.Clear(); - string str1 = JSONToCSM(File.ReadAllText(openFileDialog.FileName)); - int x = 0; - foreach (string str2 in str1.Split("\n\r".ToCharArray(), StringSplitOptions.RemoveEmptyEntries)) - ++x; - int y = x / 11; - ListView listView = new ListView(); - int num3 = 0; - do - { - listView.Items.Add("BOX"); - ++num3; - } - while (num3 < y); - - - foreach (ListViewItem current in listView.Items) - { - ListViewItem listViewItem = new ListViewItem(); - int num4 = 0; - foreach (string text in str1.Split("\n\r".ToCharArray(), StringSplitOptions.RemoveEmptyEntries)) - { - ++num4; - if (num4 == 1 + 11 * current.Index) - listViewItem.Text = text; - else if (num4 == 2 + 11 * current.Index) - listViewItem.Tag = text; - else if (num4 == 4 + 11 * current.Index) - listViewItem.SubItems.Add(text); - else if (num4 == 5 + 11 * current.Index) - listViewItem.SubItems.Add(text); - else if (num4 == 6 + 11 * current.Index) - listViewItem.SubItems.Add(text); - else if (num4 == 7 + 11 * current.Index) - listViewItem.SubItems.Add(text); - else if (num4 == 8 + 11 * current.Index) - listViewItem.SubItems.Add(text); - else if (num4 == 9 + 11 * current.Index) - listViewItem.SubItems.Add(text); - else if (num4 == 10 + 11 * current.Index) - listViewItem.SubItems.Add(text); - else if (num4 == 11 + 11 * current.Index) - { - listViewItem.SubItems.Add(text); - } - } - } + } - } [Obsolete("Will be removed")] @@ -321,13 +291,13 @@ namespace PckStudio.Forms private void skinPartListBox_SelectedIndexChanged(object sender, EventArgs e) { + int scale = 4; if (skinPartListBox.SelectedItem is SkinBOX box) { - int scale = 3; uvPictureBox.Image = new Bitmap(uvPictureBox.BackgroundImage.Width * scale, uvPictureBox.BackgroundImage.Height * scale); using (Graphics g = Graphics.FromImage(uvPictureBox.Image)) { - float penWidth = uvPictureBox.BackgroundImage.Width / renderer3D1.TextureSize.Width + uvPictureBox.BackgroundImage.Height / renderer3D1.TextureSize.Height / 2f; + float penWidth = ((uvPictureBox.BackgroundImage.Width / renderer3D1.TextureSize.Width) + (uvPictureBox.BackgroundImage.Height / renderer3D1.TextureSize.Height)) / 2f; GraphicsPath graphicsPath = box.GetUVGraphicsPath( new System.Numerics.Vector2( scale * renderer3D1.TillingFactor.X * uvPictureBox.BackgroundImage.Width, diff --git a/PCK-Studio/Forms/Skins-And-Textures/CustomSkinEditor.ja.resx b/PCK-Studio/Forms/Editor/CustomSkinEditor.ja.resx similarity index 100% rename from PCK-Studio/Forms/Skins-And-Textures/CustomSkinEditor.ja.resx rename to PCK-Studio/Forms/Editor/CustomSkinEditor.ja.resx diff --git a/PCK-Studio/Forms/Skins-And-Textures/CustomSkinEditor.resx b/PCK-Studio/Forms/Editor/CustomSkinEditor.resx similarity index 99% rename from PCK-Studio/Forms/Skins-And-Textures/CustomSkinEditor.resx rename to PCK-Studio/Forms/Editor/CustomSkinEditor.resx index f40bbef0..cce6f060 100644 --- a/PCK-Studio/Forms/Skins-And-Textures/CustomSkinEditor.resx +++ b/PCK-Studio/Forms/Editor/CustomSkinEditor.resx @@ -763,7 +763,7 @@ $this - 7 + 6 Top, Right @@ -790,7 +790,7 @@ $this - 8 + 7 Top, Right @@ -817,7 +817,7 @@ $this - 9 + 8 Fill @@ -930,63 +930,6 @@ 3 - - Top, Bottom, Left, Right - - - 194, 59 - - - 427, 492 - - - 0 - - - renderer3D1 - - - PckStudio.Rendering.SkinRenderer, PCK-Studio, Version=7.0.0.0, Culture=neutral, PublicKeyToken=null - - - $this - - - 6 - - - Top, Right - - - Zoom - - - NoControl - - - 627, 59 - - - 250, 250 - - - Zoom - - - 112 - - - uvPictureBox - - - PckStudio.ToolboxItems.InterpolationPictureBox, PCK-Studio, Version=7.0.0.0, Culture=neutral, PublicKeyToken=null - - - $this - - - 28 - Bottom, Left @@ -1108,7 +1051,7 @@ 4, 38 - 157, 440 + 157, 450 1 @@ -1135,7 +1078,7 @@ 0, 0 - 157, 440 + 157, 450 0 @@ -1152,6 +1095,63 @@ 0 + + Top, Bottom, Left, Right + + + 194, 63 + + + 424, 484 + + + 167 + + + renderer3D1 + + + PckStudio.Rendering.SkinRenderer, PCK-Studio, Version=7.0.0.0, Culture=neutral, PublicKeyToken=null + + + $this + + + 9 + + + Top, Right + + + Zoom + + + NoControl + + + 627, 59 + + + 250, 250 + + + Zoom + + + 112 + + + uvPictureBox + + + PckStudio.ToolboxItems.InterpolationPictureBox, PCK-Studio, Version=7.0.0.0, Culture=neutral, PublicKeyToken=null + + + $this + + + 28 + True @@ -3670,6 +3670,9 @@ AP//AAA= + + NoControl + 900, 600 @@ -3677,7 +3680,7 @@ CenterParent - Custom Model Editor + Custom Skin Editor createToolStripMenuItem diff --git a/PCK-Studio/PckStudio.csproj b/PCK-Studio/PckStudio.csproj index 2394456f..7458640d 100644 --- a/PCK-Studio/PckStudio.csproj +++ b/PCK-Studio/PckStudio.csproj @@ -402,10 +402,10 @@ MainForm.cs - + Form - + CustomSkinEditor.cs @@ -577,10 +577,10 @@ MainForm.cs Designer - + CustomSkinEditor.cs - + CustomSkinEditor.cs Designer diff --git a/PCK-Studio/Rendering/Renderer3D.cs b/PCK-Studio/Rendering/Renderer3D.cs index 3b8bb796..fef45773 100644 --- a/PCK-Studio/Rendering/Renderer3D.cs +++ b/PCK-Studio/Rendering/Renderer3D.cs @@ -59,6 +59,7 @@ namespace PckStudio.Rendering RefreshRate = refreshRate; timer.Tick += TimerTick; timer.Start(); + timer.Enabled = !DesignMode; VSync = true; } @@ -71,9 +72,13 @@ namespace PckStudio.Rendering protected override void OnResize(EventArgs e) { base.OnResize(e); - Camera.Update(AspectRatio); - Camera.ViewportSize = Size; + if (DesignMode) + return; + if (Camera is not null) + { + Camera.ViewportSize = ClientSize; + Camera.Update(AspectRatio); + } } } -} - +} diff --git a/PCK-Studio/Rendering/SkinRenderer.cs b/PCK-Studio/Rendering/SkinRenderer.cs index b15b5a42..bbc96af5 100644 --- a/PCK-Studio/Rendering/SkinRenderer.cs +++ b/PCK-Studio/Rendering/SkinRenderer.cs @@ -34,6 +34,7 @@ using System.IO; using PckStudio.Rendering.Camera; using PckStudio.Rendering.Texture; using PckStudio.Rendering.Shader; +using System.Linq; namespace PckStudio.Rendering { @@ -72,6 +73,7 @@ namespace PckStudio.Rendering remove => Events.RemoveHandler(nameof(TextureChanging), value); } + [Browsable(false)] public SkinANIM ANIM { get => _anim; @@ -79,8 +81,11 @@ namespace PckStudio.Rendering { _anim = value; OnANIMUpdate(); - MakeCurrent(); - UploadMeshData(); + if (initialized) + { + MakeCurrent(); + UploadMeshData(); + } } } @@ -204,6 +209,7 @@ namespace PckStudio.Rendering new Vector4( 1.0f, -1.0f, 1.0f, 0.0f), new Vector4(-1.0f, 1.0f, 0.0f, 1.0f), }; + private bool initialized = false; public SkinRenderer() : base() { @@ -259,17 +265,22 @@ namespace PckStudio.Rendering InitializeCamera(); InitializeComponent(); - MakeCurrent(); - InitializeShaders(); - InitializeFramebuffer(); - UploadMeshData(); - + ANIM ??= new SkinANIM(SkinAnimMask.RESOLUTION_64x64); OnTimerTick = AnimationTick; ModelData = new ObservableCollection(); ModelData.CollectionChanged += ModelData_CollectionChanged; } + public void InitializeGL() + { + MakeCurrent(); + InitializeShaders(); + InitializeFramebuffer(); + UploadMeshData(); + initialized = true; + } + // TODO: calculate CameraDistance based on model size private const float DefaultCameraDistance = 64f; private void InitializeCamera() @@ -323,9 +334,6 @@ namespace PckStudio.Rendering private void InitializeShaders() { - if (DesignMode) - return; - MakeCurrent(); Trace.TraceInformation(GL.GetString(StringName.Version)); @@ -435,37 +443,37 @@ namespace PckStudio.Rendering private void InitializeFramebuffer() { - framebuffer = new FrameBuffer(); - framebuffer.Bind(); - framebufferTexture = new Texture2D(0); - framebufferTexture.PixelFormat = OpenTK.Graphics.OpenGL.PixelFormat.Rgb; - framebufferTexture.InternalPixelFormat = PixelInternalFormat.Rgb; - framebufferTexture.SetSize(Size); - framebufferTexture.WrapS = TextureWrapMode.ClampToEdge; - framebufferTexture.WrapT = TextureWrapMode.ClampToEdge; - framebufferTexture.MinFilter = TextureMinFilter.Nearest; - framebufferTexture.MagFilter = TextureMagFilter.Nearest; + framebuffer = new FrameBuffer(); + framebuffer.Bind(); + framebufferTexture = new Texture2D(0); + framebufferTexture.PixelFormat = OpenTK.Graphics.OpenGL.PixelFormat.Rgb; + framebufferTexture.InternalPixelFormat = PixelInternalFormat.Rgb; + framebufferTexture.SetSize(Size); + framebufferTexture.WrapS = TextureWrapMode.ClampToEdge; + framebufferTexture.WrapT = TextureWrapMode.ClampToEdge; + framebufferTexture.MinFilter = TextureMinFilter.Nearest; + framebufferTexture.MagFilter = TextureMagFilter.Nearest; - framebufferTexture.AttachToFramebuffer(framebuffer, FramebufferAttachment.ColorAttachment0); + framebufferTexture.AttachToFramebuffer(framebuffer, FramebufferAttachment.ColorAttachment0); - framebufferVAO = new VertexArray(); - VertexBuffer vertexBuffer = new VertexBuffer(rectVertices, rectVertices.Length * Vector4.SizeInBytes); - VertexBufferLayout layout = new VertexBufferLayout(); - layout.Add(4); - framebufferVAO.AddBuffer(vertexBuffer, layout); + framebufferVAO = new VertexArray(); + VertexBuffer vertexBuffer = new VertexBuffer(rectVertices, rectVertices.Length * Vector4.SizeInBytes); + VertexBufferLayout layout = new VertexBufferLayout(); + layout.Add(4); + framebufferVAO.AddBuffer(vertexBuffer, layout); - int rbo = GL.GenRenderbuffer(); - GL.BindRenderbuffer(RenderbufferTarget.Renderbuffer, rbo); - GL.RenderbufferStorage(RenderbufferTarget.Renderbuffer, RenderbufferStorage.Depth24Stencil8, Size.Width, Size.Height); - GL.FramebufferRenderbuffer(FramebufferTarget.Framebuffer, FramebufferAttachment.DepthStencilAttachment, RenderbufferTarget.Renderbuffer, rbo); + int rbo = GL.GenRenderbuffer(); + GL.BindRenderbuffer(RenderbufferTarget.Renderbuffer, rbo); + GL.RenderbufferStorage(RenderbufferTarget.Renderbuffer, RenderbufferStorage.Depth24Stencil8, Size.Width, Size.Height); + GL.FramebufferRenderbuffer(FramebufferTarget.Framebuffer, FramebufferAttachment.DepthStencilAttachment, RenderbufferTarget.Renderbuffer, rbo); - FramebufferErrorCode status = GL.CheckFramebufferStatus(FramebufferTarget.Framebuffer); - if (status != FramebufferErrorCode.FramebufferComplete) - { - Debug.Fail(""); - } - framebuffer.Unbind(); + FramebufferErrorCode status = GL.CheckFramebufferStatus(FramebufferTarget.Framebuffer); + if (status != FramebufferErrorCode.FramebufferComplete) + { + Debug.Fail(""); } + framebuffer.Unbind(); + } private void UploadMeshData() @@ -496,6 +504,14 @@ namespace PckStudio.Rendering return partOffset.ContainsKey(name) ? partOffset[name] : 0f; } + internal void ResetOffsets() + { + foreach (var key in partOffset.Keys.ToList()) + { + partOffset[key] = 0f; + } + } + private void ModelData_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e) { // TODO: dont re-initialize everytime.. @@ -624,28 +640,29 @@ namespace PckStudio.Rendering protected override void OnResize(EventArgs e) { base.OnResize(e); - if (!IsHandleCreated) + if (!IsHandleCreated || DesignMode) return; MakeCurrent(); + if (framebuffer is not null) { - framebuffer.Bind(); - - framebufferTexture.Bind(); - framebufferTexture.SetSize(Size); - framebufferTexture.Unbind(); + framebuffer.Bind(); - int rbo = GL.GenRenderbuffer(); - GL.BindRenderbuffer(RenderbufferTarget.Renderbuffer, rbo); - GL.RenderbufferStorage(RenderbufferTarget.Renderbuffer, RenderbufferStorage.Depth24Stencil8, Size.Width, Size.Height); - GL.FramebufferRenderbuffer(FramebufferTarget.Framebuffer, FramebufferAttachment.DepthStencilAttachment, RenderbufferTarget.Renderbuffer, rbo); - - FramebufferErrorCode status = GL.CheckFramebufferStatus(FramebufferTarget.Framebuffer); - if (status != FramebufferErrorCode.FramebufferComplete) - { - Debug.Fail(""); + framebufferTexture.Bind(); + framebufferTexture.SetSize(Size); + framebufferTexture.Unbind(); + + int rbo = GL.GenRenderbuffer(); + GL.BindRenderbuffer(RenderbufferTarget.Renderbuffer, rbo); + GL.RenderbufferStorage(RenderbufferTarget.Renderbuffer, RenderbufferStorage.Depth24Stencil8, Size.Width, Size.Height); + GL.FramebufferRenderbuffer(FramebufferTarget.Framebuffer, FramebufferAttachment.DepthStencilAttachment, RenderbufferTarget.Renderbuffer, rbo); + + FramebufferErrorCode status = GL.CheckFramebufferStatus(FramebufferTarget.Framebuffer); + if (status != FramebufferErrorCode.FramebufferComplete) + { + Debug.Fail(""); + } + framebuffer.Unbind(); } - framebuffer.Unbind(); - } } @@ -668,72 +685,72 @@ namespace PckStudio.Rendering // Render (custom) skin { - var viewProjection = Camera.GetViewProjection(); - _skinShader.Bind(); - _skinShader.SetUniformMat4("u_ViewProjection", ref viewProjection); - _skinShader.SetUniform2("u_TexSize", new Vector2(TextureSize.Width, TextureSize.Height)); + var viewProjection = Camera.GetViewProjection(); + _skinShader.Bind(); + _skinShader.SetUniformMat4("u_ViewProjection", ref viewProjection); + _skinShader.SetUniform2("u_TexSize", new Vector2(TextureSize.Width, TextureSize.Height)); skinTexture.Bind(); - GL.Enable(EnableCap.Texture2D); // Enable textures + GL.Enable(EnableCap.Texture2D); // Enable textures - GL.DepthFunc(DepthFunction.Lequal); // Enable correct Z Drawings - GL.DepthMask(true); + GL.DepthFunc(DepthFunction.Lequal); // Enable correct Z Drawings + GL.DepthMask(true); - GL.Enable(EnableCap.Blend); - GL.BlendFunc(BlendingFactor.SrcAlpha, BlendingFactor.OneMinusSrcAlpha); + GL.Enable(EnableCap.Blend); + GL.BlendFunc(BlendingFactor.SrcAlpha, BlendingFactor.OneMinusSrcAlpha); - GL.Enable(EnableCap.AlphaTest); // Enable transparent - GL.AlphaFunc(AlphaFunction.Greater, 0.4f); + GL.Enable(EnableCap.AlphaTest); // Enable transparent + GL.AlphaFunc(AlphaFunction.Greater, 0.4f); - GL.PolygonMode(MaterialFace.FrontAndBack, showWireFrame ? PolygonMode.Line : PolygonMode.Fill); + GL.PolygonMode(MaterialFace.FrontAndBack, showWireFrame ? PolygonMode.Line : PolygonMode.Fill); - Matrix4 modelMatrix = Matrix4.CreateTranslation(0f, 4f, 0f) * // <- model rotation pivot point - Matrix4.CreateFromAxisAngle(-Vector3.UnitX, MathHelper.DegreesToRadians(GlobalModelRotation.X)) * - Matrix4.CreateFromAxisAngle( Vector3.UnitY, MathHelper.DegreesToRadians(GlobalModelRotation.Y)); + Matrix4 modelMatrix = Matrix4.CreateTranslation(0f, 4f, 0f) * // <- model rotation pivot point + Matrix4.CreateFromAxisAngle(-Vector3.UnitX, MathHelper.DegreesToRadians(GlobalModelRotation.X)) * + Matrix4.CreateFromAxisAngle(Vector3.UnitY, MathHelper.DegreesToRadians(GlobalModelRotation.Y)); if (ANIM.GetFlag(SkinAnimFlag.DINNERBONE)) { modelMatrix *= Matrix4.CreateRotationZ(MathHelper.DegreesToRadians(-180f)); } - var legRightMatrix = Matrix4.Identity; - var legLeftMatrix = Matrix4.Identity; - var armRightMatrix = Matrix4.Identity; - var armLeftMatrix = Matrix4.Identity; - - if (!ANIM.GetFlag(SkinAnimFlag.STATIC_ARMS)) - { - armRightMatrix = Matrix4.CreateRotationX(MathHelper.DegreesToRadians(animationCurrentRotationAngle)); + var legRightMatrix = Matrix4.Identity; + var legLeftMatrix = Matrix4.Identity; + var armRightMatrix = Matrix4.Identity; + var armLeftMatrix = Matrix4.Identity; + + if (!ANIM.GetFlag(SkinAnimFlag.STATIC_ARMS)) + { + armRightMatrix = Matrix4.CreateRotationX(MathHelper.DegreesToRadians(animationCurrentRotationAngle)); armLeftMatrix = Matrix4.CreateRotationX(MathHelper.DegreesToRadians((ANIM.GetFlag(SkinAnimFlag.SYNCED_ARMS) ? 1f : -1f) * animationCurrentRotationAngle)); - } + } - if (!ANIM.GetFlag(SkinAnimFlag.STATIC_LEGS)) - { + if (!ANIM.GetFlag(SkinAnimFlag.STATIC_LEGS)) + { legRightMatrix = Matrix4.CreateRotationX(MathHelper.DegreesToRadians((ANIM.GetFlag(SkinAnimFlag.SYNCED_LEGS) ? 1f : -1f) * animationCurrentRotationAngle)); legLeftMatrix = Matrix4.CreateRotationX(MathHelper.DegreesToRadians(animationCurrentRotationAngle)); - } + } - if (ANIM.GetFlag(SkinAnimFlag.ZOMBIE_ARMS)) - { - var rotation = Matrix4.CreateRotationX(MathHelper.DegreesToRadians(-90f)); - armRightMatrix = rotation; - armLeftMatrix = rotation; - } + if (ANIM.GetFlag(SkinAnimFlag.ZOMBIE_ARMS)) + { + var rotation = Matrix4.CreateRotationX(MathHelper.DegreesToRadians(-90f)); + armRightMatrix = rotation; + armLeftMatrix = rotation; + } - if (ANIM.GetFlag(SkinAnimFlag.STATUE_OF_LIBERTY)) - { - armRightMatrix = Matrix4.CreateRotationX(MathHelper.DegreesToRadians(-180f)); - armLeftMatrix = Matrix4.CreateRotationX(0f); - } + if (ANIM.GetFlag(SkinAnimFlag.STATUE_OF_LIBERTY)) + { + armRightMatrix = Matrix4.CreateRotationX(MathHelper.DegreesToRadians(-180f)); + armLeftMatrix = Matrix4.CreateRotationX(0f); + } bool slimModel = ANIM.GetFlag(SkinAnimFlag.SLIM_MODEL); RenderBodyPart(new Vector3(0f, 0f, 0f), new Vector3(0f), HeadMatrix, modelMatrix, "HEAD", "HEADWEAR"); RenderBodyPart(new Vector3(0f, 0f, 0f), new Vector3(0f), BodyMatrix, modelMatrix, "BODY", "JACKET"); RenderBodyPart(new Vector3(4f, 2f, 0f), new Vector3(slimModel ? -4f : -5f, -2f, 0f), RightArmMatrix * armRightMatrix, modelMatrix, "ARM0", "SLEEVE0"); RenderBodyPart(new Vector3(-4f, 2f, 0f), new Vector3(5f, -2f, 0f), LeftArmMatrix * armLeftMatrix, modelMatrix, "ARM1", "SLEEVE1"); - RenderBodyPart(new Vector3(0f, 12f, 0f), new Vector3(-2f, -12f, 0f), RightLegMatrix * legRightMatrix, modelMatrix, "LEG0", "PANTS0"); + RenderBodyPart(new Vector3(0f, 12f, 0f), new Vector3(-2f, -12f, 0f), RightLegMatrix * legRightMatrix, modelMatrix, "LEG0", "PANTS0"); RenderBodyPart(new Vector3(0f, 12f, 0f), new Vector3(2f, -12f, 0f), LeftLegMatrix * legLeftMatrix, modelMatrix, "LEG1", "PANTS1"); }