diff --git a/Switch_Toolbox_Library/Forms/Editors/UV/UVEditor.Designer.cs b/Switch_Toolbox_Library/Forms/Editors/UV/UVEditor.Designer.cs index 05a7109c..8702edcd 100644 --- a/Switch_Toolbox_Library/Forms/Editors/UV/UVEditor.Designer.cs +++ b/Switch_Toolbox_Library/Forms/Editors/UV/UVEditor.Designer.cs @@ -36,10 +36,11 @@ this.stLabel3 = new Toolbox.Library.Forms.STLabel(); this.scaleXUD = new Toolbox.Library.Forms.NumericUpDownFloat(); this.stPanel1 = new Toolbox.Library.Forms.STPanel(); - this.stComboBox1 = new Toolbox.Library.Forms.STComboBox(); + this.drawableContainerCB = new Toolbox.Library.Forms.STComboBox(); + this.meshesCB = new Toolbox.Library.Forms.STComboBox(); this.barSlider1 = new ColorSlider.ColorSlider(); this.stLabel2 = new Toolbox.Library.Forms.STLabel(); - this.comboBox2 = new Toolbox.Library.Forms.STComboBox(); + this.textureCB = new Toolbox.Library.Forms.STComboBox(); this.comboBox1 = new Toolbox.Library.Forms.STComboBox(); this.stLabel1 = new Toolbox.Library.Forms.STLabel(); this.btnApplyTransform = new Toolbox.Library.Forms.STButton(); @@ -187,10 +188,11 @@ // // stPanel1 // - this.stPanel1.Controls.Add(this.stComboBox1); + this.stPanel1.Controls.Add(this.drawableContainerCB); + this.stPanel1.Controls.Add(this.meshesCB); this.stPanel1.Controls.Add(this.barSlider1); this.stPanel1.Controls.Add(this.stLabel2); - this.stPanel1.Controls.Add(this.comboBox2); + this.stPanel1.Controls.Add(this.textureCB); this.stPanel1.Controls.Add(this.comboBox1); this.stPanel1.Controls.Add(this.stLabel1); this.stPanel1.Dock = System.Windows.Forms.DockStyle.Top; @@ -199,20 +201,35 @@ this.stPanel1.Size = new System.Drawing.Size(605, 70); this.stPanel1.TabIndex = 1; // - // stComboBox1 + // drawableContainerCB // - this.stComboBox1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) + this.drawableContainerCB.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); - this.stComboBox1.BorderColor = System.Drawing.Color.Empty; - this.stComboBox1.BorderStyle = System.Windows.Forms.ButtonBorderStyle.Solid; - this.stComboBox1.ButtonColor = System.Drawing.Color.Empty; - this.stComboBox1.FormattingEnabled = true; - this.stComboBox1.Location = new System.Drawing.Point(290, 7); - this.stComboBox1.Name = "stComboBox1"; - this.stComboBox1.ReadOnly = true; - this.stComboBox1.Size = new System.Drawing.Size(166, 21); - this.stComboBox1.TabIndex = 19; - this.stComboBox1.SelectedIndexChanged += new System.EventHandler(this.stComboBox1_SelectedIndexChanged); + this.drawableContainerCB.BorderColor = System.Drawing.Color.Empty; + this.drawableContainerCB.BorderStyle = System.Windows.Forms.ButtonBorderStyle.Solid; + this.drawableContainerCB.ButtonColor = System.Drawing.Color.Empty; + this.drawableContainerCB.FormattingEnabled = true; + this.drawableContainerCB.Location = new System.Drawing.Point(294, 7); + this.drawableContainerCB.Name = "drawableContainerCB"; + this.drawableContainerCB.ReadOnly = true; + this.drawableContainerCB.Size = new System.Drawing.Size(146, 21); + this.drawableContainerCB.TabIndex = 20; + this.drawableContainerCB.SelectedIndexChanged += new System.EventHandler(this.drawableContainerCB_SelectedIndexChanged); + // + // meshesCB + // + this.meshesCB.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.meshesCB.BorderColor = System.Drawing.Color.Empty; + this.meshesCB.BorderStyle = System.Windows.Forms.ButtonBorderStyle.Solid; + this.meshesCB.ButtonColor = System.Drawing.Color.Empty; + this.meshesCB.FormattingEnabled = true; + this.meshesCB.Location = new System.Drawing.Point(294, 34); + this.meshesCB.Name = "meshesCB"; + this.meshesCB.ReadOnly = true; + this.meshesCB.Size = new System.Drawing.Size(146, 21); + this.meshesCB.TabIndex = 19; + this.meshesCB.SelectedIndexChanged += new System.EventHandler(this.meshesCB_SelectedIndexChanged); // // barSlider1 // @@ -257,20 +274,20 @@ this.stLabel2.TabIndex = 2; this.stLabel2.Text = "Brightness"; // - // comboBox2 + // textureCB // - this.comboBox2.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) + this.textureCB.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); - this.comboBox2.BorderColor = System.Drawing.Color.Empty; - this.comboBox2.BorderStyle = System.Windows.Forms.ButtonBorderStyle.Solid; - this.comboBox2.ButtonColor = System.Drawing.Color.Empty; - this.comboBox2.FormattingEnabled = true; - this.comboBox2.Location = new System.Drawing.Point(290, 34); - this.comboBox2.Name = "comboBox2"; - this.comboBox2.ReadOnly = true; - this.comboBox2.Size = new System.Drawing.Size(166, 21); - this.comboBox2.TabIndex = 5; - this.comboBox2.SelectedIndexChanged += new System.EventHandler(this.comboBox2_SelectedIndexChanged); + this.textureCB.BorderColor = System.Drawing.Color.Empty; + this.textureCB.BorderStyle = System.Windows.Forms.ButtonBorderStyle.Solid; + this.textureCB.ButtonColor = System.Drawing.Color.Empty; + this.textureCB.FormattingEnabled = true; + this.textureCB.Location = new System.Drawing.Point(446, 34); + this.textureCB.Name = "textureCB"; + this.textureCB.ReadOnly = true; + this.textureCB.Size = new System.Drawing.Size(156, 21); + this.textureCB.TabIndex = 5; + this.textureCB.SelectedIndexChanged += new System.EventHandler(this.comboBox2_SelectedIndexChanged); // // comboBox1 // @@ -379,7 +396,7 @@ private STLabel stLabel1; private Toolbox.Library.Forms.STComboBox comboBox1; private OpenTK.GLControl gL_ControlLegacy2D1; - private Toolbox.Library.Forms.STComboBox comboBox2; + private Toolbox.Library.Forms.STComboBox textureCB; private STLabel stLabel2; private NumericUpDownFloat scaleXUD; private STLabel stLabel3; @@ -390,9 +407,10 @@ private ColorSlider.ColorSlider barSlider1; private STButton btnApplyTransform; private STPanel stPanel2; - private STComboBox stComboBox1; + private STComboBox meshesCB; private System.Windows.Forms.Splitter splitter1; private STPanel stPanel3; private STButton stButton1; + private STComboBox drawableContainerCB; } } \ No newline at end of file diff --git a/Switch_Toolbox_Library/Forms/Editors/UV/UVEditor.cs b/Switch_Toolbox_Library/Forms/Editors/UV/UVEditor.cs index 62b05bcc..e3b0edb1 100644 --- a/Switch_Toolbox_Library/Forms/Editors/UV/UVEditor.cs +++ b/Switch_Toolbox_Library/Forms/Editors/UV/UVEditor.cs @@ -50,6 +50,7 @@ namespace Toolbox.Library.Forms public int UvChannelIndex = 0; public List Objects = new List(); + public List Containers = new List(); public List ActiveObjects { @@ -73,6 +74,16 @@ namespace Toolbox.Library.Forms public STGenericMaterial ActiveMaterial; + public void ResetContainerList() + { + for (int i =0; i < Containers.Count; i++) + { + drawableContainerCB.Items.Add(Containers[i].Name); + } + + drawableContainerCB.SelectedIndex = 0; + } + bool IsSRTLoaded = false; public void Reset() { @@ -85,18 +96,18 @@ namespace Toolbox.Library.Forms IsSRTLoaded = false; - stComboBox1.Items.Clear(); + meshesCB.Items.Clear(); if (RenderTools.defaultTex != null) texid = RenderTools.defaultTex.RenderableTex.TexID; foreach (var mat in Materials) { - stComboBox1.Items.Add(mat.Text); + meshesCB.Items.Add(mat.Text); } - if (stComboBox1.Items.Count > 0) - stComboBox1.SelectedIndex = 0; + if (meshesCB.Items.Count > 0) + meshesCB.SelectedIndex = 0; } public int texid; @@ -279,8 +290,8 @@ namespace Toolbox.Library.Forms //This usually won't be seen unless the textures aren't repeating much DrawBackdrop(); - float PlaneScaleX = 0.5f; - float PlaneScaleY = 0.5f; + float PlaneScaleX = gL_ControlLegacy2D1.Width / 512; + float PlaneScaleY = gL_ControlLegacy2D1.Height / 512; if (activeTexture.Width != 0 && activeTexture.Height != 0) { @@ -288,8 +299,6 @@ namespace Toolbox.Library.Forms PlaneScaleY = (float)gL_ControlLegacy2D1.Height / (float)activeTexture.Height; } - - //Now do the plane with uvs GL.PushMatrix(); GL.Scale(PlaneScaleY * ZoomValue, -PlaneScaleX * ZoomValue, 1); @@ -315,6 +324,7 @@ namespace Toolbox.Library.Forms if (ActiveObjects.Count > 0) DrawUVs(ActiveObjects); + GL.UseProgram(0); GL.PopMatrix(); gL_ControlLegacy2D1.SwapBuffers(); @@ -355,6 +365,7 @@ namespace Toolbox.Library.Forms GL.Vertex2(Positions[2]); GL.TexCoord2(TexCoords[3]); GL.Vertex2(Positions[3]); + GL.End(); } private void DrawBackdrop() { @@ -406,9 +417,9 @@ namespace Toolbox.Library.Forms private void comboBox2_SelectedIndexChanged(object sender, EventArgs e) { - if (comboBox2.SelectedIndex >= 0) + if (textureCB.SelectedIndex >= 0) { - activeTexture = ChannelTextures[comboBox2.SelectedIndex]; + activeTexture = ChannelTextures[textureCB.SelectedIndex]; UvChannelIndex = activeTexture.UvChannelIndex; scaleXUD.Value = (decimal)activeTexture.UVScale.X; @@ -479,22 +490,22 @@ namespace Toolbox.Library.Forms gL_ControlLegacy2D1.Invalidate(); } - private void stComboBox1_SelectedIndexChanged(object sender, EventArgs e) + private void meshesCB_SelectedIndexChanged(object sender, EventArgs e) { - if (stComboBox1.SelectedIndex >= 0) + if (meshesCB.SelectedIndex >= 0) { - ActiveMaterial = Materials[stComboBox1.SelectedIndex]; + ActiveMaterial = Materials[meshesCB.SelectedIndex]; ChannelTextures.Clear(); Textures.Clear(); - comboBox2.Items.Clear(); + textureCB.Items.Clear(); foreach (var texMap in ActiveMaterial.TextureMaps) { var texture = texMap.GetTexture(); if (texture != null && !Textures.Contains(texture)) { - comboBox2.Items.Add(texture.Text); + textureCB.Items.Add(texture.Text); Textures.Add(texture); ActiveTexture tex = new ActiveTexture(); @@ -508,7 +519,7 @@ namespace Toolbox.Library.Forms } } - comboBox2.SelectedIndex = 0; + textureCB.SelectedIndex = 0; } } @@ -521,5 +532,42 @@ namespace Toolbox.Library.Forms { } + + private void drawableContainerCB_SelectedIndexChanged(object sender, EventArgs e) + { + if (drawableContainerCB.SelectedIndex >= 0) + { + int index = drawableContainerCB.SelectedIndex; + DrawableContainer container = Containers[index]; + + Materials.Clear(); + Textures.Clear(); + Objects.Clear(); + + for (int i = 0; i < container.Drawables.Count; i++) + { + if (container.Drawables[i] is IMeshContainer && container.Drawables[i].Visible) + { + for (int m = 0; m < ((IMeshContainer)container.Drawables[i]).Meshes.Count; m++) + { + var mesh = ((IMeshContainer)container.Drawables[i]).Meshes[m]; + if (mesh.GetMaterial() != null) + { + Objects.Add(mesh); + var mat = mesh.GetMaterial(); + if (!Materials.Contains(mat)) + { + Materials.Add(mat); + } + } + } + } + } + + Reset(); + Refresh(); + gL_ControlLegacy2D1.Invalidate(); + } + } } } \ No newline at end of file diff --git a/Switch_Toolbox_Library/Forms/Editors/UV/UVEditorForm.cs b/Switch_Toolbox_Library/Forms/Editors/UV/UVEditorForm.cs index 8dea9f81..53566029 100644 --- a/Switch_Toolbox_Library/Forms/Editors/UV/UVEditorForm.cs +++ b/Switch_Toolbox_Library/Forms/Editors/UV/UVEditorForm.cs @@ -17,27 +17,15 @@ namespace Toolbox.Library.Forms InitializeComponent(); } - public void LoadEditor(List Meshes) + public void LoadEditor(List Drawables) { uvEditor1.Materials.Clear(); uvEditor1.Textures.Clear(); uvEditor1.Objects.Clear(); + uvEditor1.Containers.Clear(); - for (int i = 0; i < Meshes.Count; i++) - { - if (Meshes[i].GetMaterial() != null) - { - var mat = Meshes[i].GetMaterial(); - if (!uvEditor1.Materials.Contains(mat)) - { - uvEditor1.Materials.Add(mat); - } - } - } - - uvEditor1.Objects = Meshes; - uvEditor1.Reset(); - uvEditor1.Refresh(); + uvEditor1.Containers.AddRange(Drawables); + uvEditor1.ResetContainerList(); } } } diff --git a/Switch_Toolbox_Library/Forms/Viewport.cs b/Switch_Toolbox_Library/Forms/Viewport.cs index 5f8a5350..353a2cbd 100644 --- a/Switch_Toolbox_Library/Forms/Viewport.cs +++ b/Switch_Toolbox_Library/Forms/Viewport.cs @@ -597,25 +597,9 @@ namespace Toolbox.Library var containers = GetActiveContainers(); if (containers.Count == 0) return; - List meshes = new List(); - foreach (var container in containers) - { - for (int i = 0; i < container.Drawables.Count; i++) - { - if (container.Drawables[i] is IMeshContainer && container.Drawables[i].Visible) - { - for (int m = 0; m < ((IMeshContainer)container.Drawables[i]).Meshes.Count; m++) - meshes.Add(((IMeshContainer)container.Drawables[i]).Meshes[m]); - } - } - } - - if (meshes.Count > 0) - { - UVEditorForm uvEditor1 = new UVEditorForm(); - uvEditor1.LoadEditor(meshes); - uvEditor1.Show(this); - } + UVEditorForm uvEditor1 = new UVEditorForm(); + uvEditor1.LoadEditor(containers); + uvEditor1.Show(this); } public GLControl GetActiveControl()