1
0
mirror of synced 2024-11-12 02:00:50 +01:00

Some improvements from yesterday. Start to improve uv editor.

Basic tex 3ds support
BC4 textures will be rendered grayscale in opengl (not using opengl decoder)
Fix a few format issues with 3ds
Mip total method is one function in STGeneric texture
Weight format default to floats again until i find a proper fix for the 888 unform format.
This commit is contained in:
KillzXGaming 2019-05-13 15:29:40 -04:00
parent d1d9619dcb
commit 67d1b6920a
37 changed files with 1444 additions and 183 deletions

Binary file not shown.

View File

@ -55,6 +55,7 @@ namespace FirstPlugin
AddNodeGroup(BcresFile.Data.Lookups, new BCRESGroupNode(BCRESGroupType.Lookups));
AddNodeGroup(BcresFile.Data.Shaders, new BCRESGroupNode(BCRESGroupType.Shaders));
AddNodeGroup(BcresFile.Data.Cameras, new BCRESGroupNode(BCRESGroupType.Cameras));
AddNodeGroup(BcresFile.Data.Lights, new BCRESGroupNode(BCRESGroupType.Lights));
AddNodeGroup(BcresFile.Data.Fogs, new BCRESGroupNode(BCRESGroupType.Fogs));
AddNodeGroup(BcresFile.Data.Scenes, new BCRESGroupNode(BCRESGroupType.Scenes));
AddNodeGroup(BcresFile.Data.SkeletalAnims, new BCRESGroupNode(BCRESGroupType.SkeletalAnim));

View File

@ -265,7 +265,7 @@ namespace FirstPlugin
{
if (anim is FMAA)
{
foreach (FMAA.MaterialAnimEntry mat in ((FSKA)anim).Nodes)
foreach (FMAA.MaterialAnimEntry mat in ((FMAA)anim).Nodes)
{
}

View File

@ -196,6 +196,25 @@ namespace Bfres.Structs
return ((BFRES)Parent.Parent.Parent.Parent).BFRESRender;
}
public bool IsNormalMapTexCoord2()
{
//for BOTW if it uses UV layer 2 for normal maps use second UV map
if (shaderassign.options.ContainsKey("uking_texture2_texcoord"))
{
float value = float.Parse(shaderassign.options["uking_texture2_texcoord"]);
return (value == 1);
}
//For 3D world
if (shaderassign.options.ContainsKey("cIsEnableNormalMap"))
{
float value = float.Parse(shaderassign.options["cIsEnableNormalMap"]);
return (value == 1);
}
return false;
}
public void SetActiveGame()
{
Runtime.activeGame = Runtime.ActiveGame.KSA;

View File

@ -153,7 +153,7 @@ namespace Bfres.Structs
{
return ((FMDL)Parent.Parent).GetResFileU();
}
public void UpdateVertexData()
public override void UpdateVertexData()
{
((FMDL)Parent.Parent).UpdateVertexData();
}
@ -444,11 +444,9 @@ namespace Bfres.Structs
{
bool UseUVLayer2 = false;
//for BOTW if it uses UV layer 2 for normal maps use second UV map
if (Parent != null && GetMaterial().shaderassign.options.ContainsKey("uking_texture2_texcoord"))
{
float value = float.Parse(GetMaterial().shaderassign.options["uking_texture2_texcoord"]);
UseUVLayer2 = (value == 1);
//check second UV layer
if (Parent != null) {
UseUVLayer2 = GetMaterial().IsNormalMapTexCoord2();
}
CalculateTangentBitangent(UseUVLayer2);

View File

@ -622,4 +622,46 @@ namespace FirstPlugin
}
}
}
public class CMAP
{
public uint CharacterCodeBegin { get; set; }
public uint CharacterCodeEnd { get; set; }
public Mapping MappingMethod { get; set; }
private ushort Padding;
public enum Mapping : ushort
{
Direct,
Table,
Scan,
}
public void Read(FileReader reader, FFNT header)
{
reader.ReadSignature(4, "CMAP ");
uint SectionSize = reader.ReadUInt32();
if (header.Version > 0x3000000)
{
CharacterCodeBegin = reader.ReadUInt32();
CharacterCodeEnd = reader.ReadUInt32();
MappingMethod = reader.ReadEnum<Mapping>(true);
Padding = reader.ReadUInt16();
}
else
{
CharacterCodeBegin = reader.ReadUInt16();
CharacterCodeEnd = reader.ReadUInt16();
MappingMethod = reader.ReadEnum<Mapping>(true);
Padding = reader.ReadUInt16();
}
uint NextMapOffset = reader.ReadUInt32();
if (NextMapOffset != 0)
{
reader.Seek(NextMapOffset - 8, SeekOrigin.Current);
}
}
}
}

View File

@ -0,0 +1,139 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Threading.Tasks;
using Switch_Toolbox;
using System.Windows.Forms;
using Switch_Toolbox.Library;
using Switch_Toolbox.Library.Forms;
using Switch_Toolbox.Library.IO;
namespace FirstPlugin
{
public class TEX3DS : STGenericTexture, IEditor<ImageEditorForm>, IFileFormat
{
public FileType FileType { get; set; } = FileType.Image;
public bool CanSave { get; set; }
public string[] Description { get; set; } = new string[] { "TEX (3DS)" };
public string[] Extension { get; set; } = new string[] { "*.tex" };
public string FileName { get; set; }
public string FilePath { get; set; }
public IFileInfo IFileInfo { get; set; }
public bool Identify(System.IO.Stream stream)
{
return (Utils.HasExtension(FileName, ".tex"));
}
public Type[] Types
{
get
{
List<Type> types = new List<Type>();
return types.ToArray();
}
}
public override bool CanEdit { get; set; } = false;
public override TEX_FORMAT[] SupportedFormats
{
get
{
return new TEX_FORMAT[]
{
TEX_FORMAT.B5G6R5_UNORM,
TEX_FORMAT.R8G8_UNORM,
TEX_FORMAT.B5G5R5A1_UNORM,
TEX_FORMAT.B4G4R4A4_UNORM,
TEX_FORMAT.LA8,
TEX_FORMAT.HIL08,
TEX_FORMAT.L8,
TEX_FORMAT.A8_UNORM,
TEX_FORMAT.LA4,
TEX_FORMAT.A4,
TEX_FORMAT.ETC1,
TEX_FORMAT.ETC1_A4,
};
}
}
public byte[] ImageData;
public ImageEditorForm OpenForm()
{
bool IsDialog = IFileInfo != null && IFileInfo.InArchive;
Properties prop = new Properties();
prop.Width = Width;
prop.Height = Height;
prop.Depth = Depth;
prop.MipCount = MipCount;
prop.ArrayCount = ArrayCount;
prop.ImageSize = (uint)ImageData.Length;
prop.Format = Format;
ImageEditorForm form = new ImageEditorForm(IsDialog);
form.editorBase.Text = Text;
form.editorBase.Dock = DockStyle.Fill;
// form.editorBase.AddFileContextEvent("Save", Save);
// form.editorBase.AddFileContextEvent("Replace", Replace);
form.editorBase.LoadProperties(prop);
form.editorBase.LoadImage(this);
return form;
}
public void Load(System.IO.Stream stream)
{
PlatformSwizzle = PlatformSwizzle.Platform_3DS;
CanSave = true;
using (var reader = new FileReader(stream))
{
Width = reader.ReadUInt32();
Height = reader.ReadUInt32();
byte FormatCtr = reader.ReadByte();
MipCount = reader.ReadByte();
ushort padding = reader.ReadUInt16();
Text = reader.ReadZeroTerminatedString();
Format = CTR_3DS.ConvertPICAToGenericFormat((CTR_3DS.PICASurfaceFormat)FormatCtr);
reader.Position = 0x80;
ImageData = reader.ReadBytes((int)reader.BaseStream.Length - 0x80);
}
}
public byte[] Save()
{
MemoryStream mem = new MemoryStream();
using (var writer = new FileWriter(mem))
{
writer.Write(Width);
writer.Write(Height);
writer.Write((byte)CTR_3DS.ConvertToPICAFormat(Format));
writer.Write((byte)MipCount);
writer.Write((ushort)0); //Padding
writer.WriteString(Text);
writer.Position = 0x80;
writer.Write(ImageData);
}
return mem.ToArray();
}
public override void SetImageData(System.Drawing.Bitmap bitmap, int ArrayLevel)
{
}
public override byte[] GetImageData(int ArrayLevel = 0, int MipLevel = 0)
{
return ImageData;
}
}
}

View File

@ -868,6 +868,8 @@ namespace FirstPlugin
//This uniform sets various maps for BOTW to use second UV channel
SetUniformData(mat, shader, "uking_texture2_texcoord");
SetUniformData(mat, shader, "cIsEnableNormalMap");
SetUniformData(mat, shader, "tex_mtx0");
//Sets shadow type

View File

@ -730,7 +730,7 @@
this.tabPageAdvanced.Location = new System.Drawing.Point(4, 25);
this.tabPageAdvanced.Name = "tabPageAdvanced";
this.tabPageAdvanced.Padding = new System.Windows.Forms.Padding(3);
this.tabPageAdvanced.Size = new System.Drawing.Size(192, 71);
this.tabPageAdvanced.Size = new System.Drawing.Size(530, 333);
this.tabPageAdvanced.TabIndex = 0;
this.tabPageAdvanced.Text = "Advanced Settings";
//
@ -747,7 +747,7 @@
this.stPanel1.Dock = System.Windows.Forms.DockStyle.Fill;
this.stPanel1.Location = new System.Drawing.Point(3, 3);
this.stPanel1.Name = "stPanel1";
this.stPanel1.Size = new System.Drawing.Size(186, 65);
this.stPanel1.Size = new System.Drawing.Size(524, 327);
this.stPanel1.TabIndex = 17;
//
// BfresModelImportSettings

View File

@ -235,7 +235,7 @@ namespace FirstPlugin
comboBoxFormatWeights.Items.Add(AttribFormat.Format_16_16_UNorm);
comboBoxFormatWeights.Items.Add(AttribFormat.Format_8_8_UNorm);
comboBoxFormatWeights.Items.Add(AttribFormat.Format_8_UNorm);
comboBoxFormatWeights.SelectedIndex = 2;
comboBoxFormatWeights.SelectedIndex = 0;
comboBoxFormatTangents.Items.Add(AttribFormat.Format_32_32_32_32_Single);
comboBoxFormatTangents.Items.Add(AttribFormat.Format_16_16_16_16_Single);

View File

@ -45,6 +45,7 @@
this.listViewCustom1 = new Switch_Toolbox.Library.Forms.ListViewCustom();
this.columnHeader1 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
this.stPanel7 = new Switch_Toolbox.Library.Forms.STPanel();
this.btnEditSamplers = new Switch_Toolbox.Library.Forms.STButton();
this.btnEditMaterial = new Switch_Toolbox.Library.Forms.STButton();
this.stLabel2 = new Switch_Toolbox.Library.Forms.STLabel();
this.pictureBoxCustom1 = new Switch_Toolbox.Library.Forms.PictureBoxCustom();
@ -65,7 +66,6 @@
this.stTextBox1 = new Switch_Toolbox.Library.Forms.STTextBox();
this.splitter4 = new System.Windows.Forms.Splitter();
this.splitter2 = new System.Windows.Forms.Splitter();
this.btnEditSamplers = new Switch_Toolbox.Library.Forms.STButton();
this.stPanel3.SuspendLayout();
this.stPanel5.SuspendLayout();
this.stPanel6.SuspendLayout();
@ -249,6 +249,17 @@
this.stPanel7.Size = new System.Drawing.Size(480, 834);
this.stPanel7.TabIndex = 14;
//
// btnEditSamplers
//
this.btnEditSamplers.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.btnEditSamplers.Location = new System.Drawing.Point(299, 41);
this.btnEditSamplers.Name = "btnEditSamplers";
this.btnEditSamplers.Size = new System.Drawing.Size(47, 23);
this.btnEditSamplers.TabIndex = 15;
this.btnEditSamplers.Text = "Edit";
this.btnEditSamplers.UseVisualStyleBackColor = false;
this.btnEditSamplers.Click += new System.EventHandler(this.stButton1_Click);
//
// btnEditMaterial
//
this.btnEditMaterial.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
@ -274,11 +285,10 @@
this.pictureBoxCustom1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.pictureBoxCustom1.BackColor = System.Drawing.Color.Empty;
this.pictureBoxCustom1.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("pictureBoxCustom1.BackgroundImage")));
this.pictureBoxCustom1.Location = new System.Drawing.Point(6, 102);
this.pictureBoxCustom1.Name = "pictureBoxCustom1";
this.pictureBoxCustom1.Size = new System.Drawing.Size(467, 506);
this.pictureBoxCustom1.Size = new System.Drawing.Size(467, 658);
this.pictureBoxCustom1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom;
this.pictureBoxCustom1.TabIndex = 0;
this.pictureBoxCustom1.TabStop = false;
@ -317,18 +327,18 @@
this.stPanel1.Controls.Add(this.currentFrameCounterUD);
this.stPanel1.Controls.Add(this.stPanel4);
this.stPanel1.Dock = System.Windows.Forms.DockStyle.Bottom;
this.stPanel1.Location = new System.Drawing.Point(0, 614);
this.stPanel1.Location = new System.Drawing.Point(0, 766);
this.stPanel1.Name = "stPanel1";
this.stPanel1.Size = new System.Drawing.Size(480, 220);
this.stPanel1.Size = new System.Drawing.Size(480, 68);
this.stPanel1.TabIndex = 1;
//
// loopChkBox
//
this.loopChkBox.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.loopChkBox.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.loopChkBox.AutoSize = true;
this.loopChkBox.Checked = true;
this.loopChkBox.CheckState = System.Windows.Forms.CheckState.Checked;
this.loopChkBox.Location = new System.Drawing.Point(367, 10);
this.loopChkBox.Location = new System.Drawing.Point(355, 11);
this.loopChkBox.Name = "loopChkBox";
this.loopChkBox.Size = new System.Drawing.Size(50, 17);
this.loopChkBox.TabIndex = 17;
@ -337,9 +347,8 @@
//
// animationTrackBar
//
this.animationTrackBar.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
this.animationTrackBar.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.animationTrackBar.BackColor = System.Drawing.Color.Empty;
this.animationTrackBar.BarInnerColor = System.Drawing.Color.FromArgb(((int)(((byte)(64)))), ((int)(((byte)(64)))), ((int)(((byte)(64)))));
this.animationTrackBar.BarPenColorBottom = System.Drawing.Color.FromArgb(((int)(((byte)(64)))), ((int)(((byte)(64)))), ((int)(((byte)(64)))));
this.animationTrackBar.BarPenColorTop = System.Drawing.Color.FromArgb(((int)(((byte)(64)))), ((int)(((byte)(64)))), ((int)(((byte)(64)))));
@ -350,7 +359,7 @@
this.animationTrackBar.Font = new System.Drawing.Font("Microsoft Sans Serif", 6F);
this.animationTrackBar.ForeColor = System.Drawing.Color.White;
this.animationTrackBar.LargeChange = ((uint)(5u));
this.animationTrackBar.Location = new System.Drawing.Point(16, 65);
this.animationTrackBar.Location = new System.Drawing.Point(6, 46);
this.animationTrackBar.Maximum = 1000;
this.animationTrackBar.MouseEffects = false;
this.animationTrackBar.Name = "animationTrackBar";
@ -358,7 +367,7 @@
this.animationTrackBar.ScaleSubDivisions = 5;
this.animationTrackBar.ShowDivisionsText = true;
this.animationTrackBar.ShowSmallScale = false;
this.animationTrackBar.Size = new System.Drawing.Size(459, 37);
this.animationTrackBar.Size = new System.Drawing.Size(456, 19);
this.animationTrackBar.SmallChange = ((uint)(1u));
this.animationTrackBar.TabIndex = 16;
this.animationTrackBar.Text = "colorSlider1";
@ -375,8 +384,8 @@
//
// maxFrameCounterUD
//
this.maxFrameCounterUD.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.maxFrameCounterUD.Location = new System.Drawing.Point(364, 33);
this.maxFrameCounterUD.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.maxFrameCounterUD.Location = new System.Drawing.Point(353, 28);
this.maxFrameCounterUD.Name = "maxFrameCounterUD";
this.maxFrameCounterUD.Size = new System.Drawing.Size(109, 20);
this.maxFrameCounterUD.TabIndex = 15;
@ -384,7 +393,8 @@
//
// currentFrameCounterUD
//
this.currentFrameCounterUD.Location = new System.Drawing.Point(16, 33);
this.currentFrameCounterUD.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.currentFrameCounterUD.Location = new System.Drawing.Point(9, 28);
this.currentFrameCounterUD.Name = "currentFrameCounterUD";
this.currentFrameCounterUD.Size = new System.Drawing.Size(109, 20);
this.currentFrameCounterUD.TabIndex = 14;
@ -392,16 +402,16 @@
//
// stPanel4
//
this.stPanel4.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
this.stPanel4.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.stPanel4.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(64)))), ((int)(((byte)(64)))), ((int)(((byte)(64)))));
this.stPanel4.Controls.Add(this.btnStop);
this.stPanel4.Controls.Add(this.btnForward1);
this.stPanel4.Controls.Add(this.btnPlay);
this.stPanel4.Controls.Add(this.btnBackward1);
this.stPanel4.Location = new System.Drawing.Point(135, 16);
this.stPanel4.Location = new System.Drawing.Point(123, 11);
this.stPanel4.Name = "stPanel4";
this.stPanel4.Size = new System.Drawing.Size(225, 45);
this.stPanel4.Size = new System.Drawing.Size(225, 37);
this.stPanel4.TabIndex = 13;
//
// btnStop
@ -411,9 +421,9 @@
this.btnStop.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
this.btnStop.FlatAppearance.BorderSize = 0;
this.btnStop.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.btnStop.Location = new System.Drawing.Point(160, 7);
this.btnStop.Location = new System.Drawing.Point(159, 6);
this.btnStop.Name = "btnStop";
this.btnStop.Size = new System.Drawing.Size(35, 35);
this.btnStop.Size = new System.Drawing.Size(35, 27);
this.btnStop.TabIndex = 3;
this.btnStop.UseVisualStyleBackColor = false;
this.btnStop.Click += new System.EventHandler(this.btnStop_Click);
@ -425,7 +435,7 @@
this.btnForward1.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.btnForward1.FlatAppearance.BorderSize = 0;
this.btnForward1.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.btnForward1.Location = new System.Drawing.Point(117, 15);
this.btnForward1.Location = new System.Drawing.Point(116, 10);
this.btnForward1.Name = "btnForward1";
this.btnForward1.Size = new System.Drawing.Size(23, 20);
this.btnForward1.TabIndex = 2;
@ -439,9 +449,9 @@
this.btnPlay.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
this.btnPlay.FlatAppearance.BorderSize = 0;
this.btnPlay.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.btnPlay.Location = new System.Drawing.Point(65, 8);
this.btnPlay.Location = new System.Drawing.Point(64, 6);
this.btnPlay.Name = "btnPlay";
this.btnPlay.Size = new System.Drawing.Size(35, 35);
this.btnPlay.Size = new System.Drawing.Size(35, 28);
this.btnPlay.TabIndex = 0;
this.btnPlay.UseVisualStyleBackColor = false;
this.btnPlay.Click += new System.EventHandler(this.btnPlay_Click);
@ -453,7 +463,7 @@
this.btnBackward1.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
this.btnBackward1.FlatAppearance.BorderSize = 0;
this.btnBackward1.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.btnBackward1.Location = new System.Drawing.Point(26, 15);
this.btnBackward1.Location = new System.Drawing.Point(25, 10);
this.btnBackward1.Name = "btnBackward1";
this.btnBackward1.Size = new System.Drawing.Size(20, 20);
this.btnBackward1.TabIndex = 1;
@ -505,17 +515,6 @@
this.splitter2.TabIndex = 8;
this.splitter2.TabStop = false;
//
// btnEditSamplers
//
this.btnEditSamplers.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.btnEditSamplers.Location = new System.Drawing.Point(299, 41);
this.btnEditSamplers.Name = "btnEditSamplers";
this.btnEditSamplers.Size = new System.Drawing.Size(47, 23);
this.btnEditSamplers.TabIndex = 15;
this.btnEditSamplers.Text = "Edit";
this.btnEditSamplers.UseVisualStyleBackColor = false;
this.btnEditSamplers.Click += new System.EventHandler(this.stButton1_Click);
//
// BfresTexturePatternEditor
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);

View File

@ -206,7 +206,10 @@ namespace FirstPlugin
if (ForceMipCount)
MipmapNum.Maximum = SelectedTexSettings.MipCount;
else
MipmapNum.Maximum = SelectedTexSettings.GetTotalMipCount() + 1;
{
MipmapNum.Maximum = STGenericTexture.GenerateTotalMipCount(
SelectedTexSettings.TexWidth, SelectedTexSettings.TexHeight) + 1;
}
MipmapNum.Value = SelectedTexSettings.MipCount;
}

View File

@ -140,7 +140,7 @@ namespace FirstPlugin
TexWidth = (uint)Image.Width;
TexHeight = (uint)Image.Height;
MipCount = (uint)GetTotalMipCount();
MipCount = (uint)STGenericTexture.GenerateTotalMipCount(TexWidth, TexHeight);
DecompressedData.Add(BitmapExtension.ImageToByte(Image));
@ -152,31 +152,6 @@ namespace FirstPlugin
}
public int GetTotalMipCount()
{
int MipmapNum = 0;
uint num = Math.Max(TexHeight, TexWidth);
int width = (int)TexWidth;
int height = (int)TexHeight;
while (true)
{
num >>= 1;
width = width / 2;
height = height / 2;
if (width <= 0 || height <= 0)
break;
if (num > 0)
++MipmapNum;
else
break;
}
return MipmapNum;
}
public byte[] GenerateMips(int SurfaceLevel = 0)
{
Bitmap Image = BitmapExtension.GetBitmap(DecompressedData[SurfaceLevel], (int)TexWidth, (int)TexHeight);

View File

@ -96,7 +96,7 @@ namespace FirstPlugin
TexWidth = (uint)Image.Width;
TexHeight = (uint)Image.Height;
MipCount = (uint)GetTotalMipCount();
MipCount = (uint)STGenericTexture.GenerateTotalMipCount(TexWidth, TexHeight);
DecompressedData.Add(BitmapExtension.ImageToByte(Image));
@ -107,31 +107,6 @@ namespace FirstPlugin
}
}
public int GetTotalMipCount()
{
int MipmapNum = 0;
uint num = Math.Max(TexHeight, TexWidth);
int width = (int)TexWidth;
int height = (int)TexHeight;
while (true)
{
num >>= 1;
width = width / 2;
height = height / 2;
if (width <= 0 || height <= 0)
break;
if (num > 0)
++MipmapNum;
else
break;
}
return MipmapNum;
}
public byte[] GenerateMips(int SurfaceLevel = 0)
{
Bitmap Image = BitmapExtension.GetBitmap(DecompressedData[SurfaceLevel], (int)TexWidth, (int)TexHeight);

View File

@ -216,7 +216,8 @@ namespace FirstPlugin
SetupSettings();
MipmapNum.Maximum = SelectedTexSettings.GetTotalMipCount() + 1;
MipmapNum.Maximum = STGenericTexture.GenerateTotalMipCount(
SelectedTexSettings.TexWidth, SelectedTexSettings.TexHeight) + 1;
//Force the mip counter to be the selected mip counter
//Some textures like bflim (used for UI) only have 1

View File

@ -158,11 +158,11 @@ namespace FirstPlugin
Formats.Add(typeof(NARC));
// Formats.Add(typeof(SDF));
Formats.Add(typeof(TMPK));
Formats.Add(typeof(TEX3DS));
Formats.Add(typeof(Turbo.Course_MapCamera_bin));
Formats.Add(typeof(Turbo.PartsBIN));
return Formats.ToArray();
}
#endregion

View File

@ -235,6 +235,7 @@
<Compile Include="FileFormats\BFRES\Bfres Structs\CurveHelper.cs" />
<Compile Include="FileFormats\BFRES\BFRES.cs" />
<Compile Include="FileFormats\Texture\NUT.cs" />
<Compile Include="FileFormats\Texture\TEX3DS.cs" />
<Compile Include="FileFormats\XLINK\XLINK.cs" />
<Compile Include="GL\BCRES_Render.cs" />
<Compile Include="GL\Helpers\DepthGLControl.cs" />

View File

@ -1 +1 @@
fec0b42dbf779a19a9fdd2e235388e00548ba5f7
d87d0dcd49f0581ca7d8c6ec700d22a2cb739172

View File

@ -37,11 +37,11 @@
this.scaleXUD = new Switch_Toolbox.Library.Forms.NumericUpDownFloat();
this.stPanel1 = new Switch_Toolbox.Library.Forms.STPanel();
this.btnApplyTransform = new Switch_Toolbox.Library.Forms.STButton();
this.barSlider1 = new BarSlider.BarSlider();
this.stLabel2 = new Switch_Toolbox.Library.Forms.STLabel();
this.comboBox2 = new Switch_Toolbox.Library.Forms.STComboBox();
this.comboBox1 = new Switch_Toolbox.Library.Forms.STComboBox();
this.stLabel1 = new Switch_Toolbox.Library.Forms.STLabel();
this.barSlider1 = new ColorSlider.ColorSlider();
((System.ComponentModel.ISupportInitialize)(this.scaleYUD)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.transYUD)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.transXUD)).BeginInit();
@ -182,9 +182,9 @@
//
// stPanel1
//
this.stPanel1.Controls.Add(this.barSlider1);
this.stPanel1.Controls.Add(this.btnApplyTransform);
this.stPanel1.Controls.Add(this.scaleYUD);
this.stPanel1.Controls.Add(this.barSlider1);
this.stPanel1.Controls.Add(this.transYUD);
this.stPanel1.Controls.Add(this.stLabel2);
this.stPanel1.Controls.Add(this.transXUD);
@ -211,58 +211,10 @@
this.btnApplyTransform.UseVisualStyleBackColor = false;
this.btnApplyTransform.Click += new System.EventHandler(this.btnApplyTransform_Click);
//
// barSlider1
//
this.barSlider1.ActiveEditColor = System.Drawing.Color.FromArgb(((int)(((byte)(40)))), ((int)(((byte)(40)))), ((int)(((byte)(40)))));
this.barSlider1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.barSlider1.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(70)))), ((int)(((byte)(77)))), ((int)(((byte)(95)))));
this.barSlider1.BarInnerColor = System.Drawing.Color.FromArgb(((int)(((byte)(80)))), ((int)(((byte)(80)))), ((int)(((byte)(80)))));
this.barSlider1.BarPenColorBottom = System.Drawing.Color.FromArgb(((int)(((byte)(80)))), ((int)(((byte)(80)))), ((int)(((byte)(80)))));
this.barSlider1.BarPenColorMiddle = System.Drawing.Color.Empty;
this.barSlider1.BarPenColorTop = System.Drawing.Color.FromArgb(((int)(((byte)(80)))), ((int)(((byte)(80)))), ((int)(((byte)(80)))));
this.barSlider1.BorderRoundRectSize = new System.Drawing.Size(8, 8);
this.barSlider1.DataType = null;
this.barSlider1.DrawSemitransparentThumb = false;
this.barSlider1.ElapsedInnerColor = System.Drawing.Color.FromArgb(((int)(((byte)(83)))), ((int)(((byte)(121)))), ((int)(((byte)(180)))));
this.barSlider1.ElapsedPenColorBottom = System.Drawing.Color.FromArgb(((int)(((byte)(83)))), ((int)(((byte)(121)))), ((int)(((byte)(180)))));
this.barSlider1.ElapsedPenColorMiddle = System.Drawing.Color.Empty;
this.barSlider1.ElapsedPenColorTop = System.Drawing.Color.FromArgb(((int)(((byte)(83)))), ((int)(((byte)(121)))), ((int)(((byte)(180)))));
this.barSlider1.Font = new System.Drawing.Font("Microsoft Sans Serif", 6F);
this.barSlider1.ForeColor = System.Drawing.Color.White;
this.barSlider1.IncrementAmount = 0.01F;
this.barSlider1.InputName = null;
this.barSlider1.LargeChange = 0.04F;
this.barSlider1.Location = new System.Drawing.Point(57, 6);
this.barSlider1.Maximum = 1F;
this.barSlider1.Minimum = 0F;
this.barSlider1.Name = "barSlider1";
this.barSlider1.Precision = 0.01F;
this.barSlider1.ScaleDivisions = 10;
this.barSlider1.ScaleSubDivisions = 5;
this.barSlider1.ShowDivisionsText = true;
this.barSlider1.ShowSmallScale = false;
this.barSlider1.Size = new System.Drawing.Size(227, 27);
this.barSlider1.SmallChange = 0.01F;
this.barSlider1.TabIndex = 6;
this.barSlider1.Text = "barSlider1";
this.barSlider1.ThumbInnerColor = System.Drawing.Color.FromArgb(((int)(((byte)(83)))), ((int)(((byte)(121)))), ((int)(((byte)(180)))));
this.barSlider1.ThumbOuterColor = System.Drawing.Color.FromArgb(((int)(((byte)(83)))), ((int)(((byte)(121)))), ((int)(((byte)(180)))));
this.barSlider1.ThumbPenColor = System.Drawing.Color.FromArgb(((int)(((byte)(83)))), ((int)(((byte)(121)))), ((int)(((byte)(180)))));
this.barSlider1.ThumbRoundRectSize = new System.Drawing.Size(1, 1);
this.barSlider1.ThumbSize = new System.Drawing.Size(1, 1);
this.barSlider1.TickAdd = 0F;
this.barSlider1.TickColor = System.Drawing.Color.White;
this.barSlider1.TickDivide = 0F;
this.barSlider1.TickStyle = System.Windows.Forms.TickStyle.None;
this.barSlider1.UseInterlapsedBar = true;
this.barSlider1.Value = 0.5F;
this.barSlider1.Scroll += new System.Windows.Forms.ScrollEventHandler(this.stTrackBar1_Scroll);
//
// stLabel2
//
this.stLabel2.AutoSize = true;
this.stLabel2.Location = new System.Drawing.Point(3, 13);
this.stLabel2.Location = new System.Drawing.Point(3, 7);
this.stLabel2.Name = "stLabel2";
this.stLabel2.Size = new System.Drawing.Size(56, 13);
this.stLabel2.TabIndex = 2;
@ -270,8 +222,7 @@
//
// comboBox2
//
this.comboBox2.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.comboBox2.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | 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;
@ -307,6 +258,40 @@
this.stLabel1.TabIndex = 4;
this.stLabel1.Text = "Active Channel:";
//
// barSlider1
//
this.barSlider1.BarInnerColor = System.Drawing.Color.FromArgb(((int)(((byte)(64)))), ((int)(((byte)(64)))), ((int)(((byte)(64)))));
this.barSlider1.BarPenColorBottom = System.Drawing.Color.FromArgb(((int)(((byte)(64)))), ((int)(((byte)(64)))), ((int)(((byte)(64)))));
this.barSlider1.BarPenColorTop = System.Drawing.Color.FromArgb(((int)(((byte)(64)))), ((int)(((byte)(64)))), ((int)(((byte)(64)))));
this.barSlider1.BorderRoundRectSize = new System.Drawing.Size(8, 8);
this.barSlider1.ElapsedInnerColor = System.Drawing.Color.FromArgb(((int)(((byte)(224)))), ((int)(((byte)(224)))), ((int)(((byte)(224)))));
this.barSlider1.ElapsedPenColorBottom = System.Drawing.Color.FromArgb(((int)(((byte)(224)))), ((int)(((byte)(224)))), ((int)(((byte)(224)))));
this.barSlider1.ElapsedPenColorTop = System.Drawing.Color.FromArgb(((int)(((byte)(224)))), ((int)(((byte)(224)))), ((int)(((byte)(224)))));
this.barSlider1.Font = new System.Drawing.Font("Microsoft Sans Serif", 6F);
this.barSlider1.ForeColor = System.Drawing.Color.White;
this.barSlider1.LargeChange = ((uint)(5u));
this.barSlider1.Location = new System.Drawing.Point(65, 7);
this.barSlider1.MouseEffects = false;
this.barSlider1.Name = "barSlider1";
this.barSlider1.ScaleDivisions = 10;
this.barSlider1.ScaleSubDivisions = 5;
this.barSlider1.ShowDivisionsText = true;
this.barSlider1.ShowSmallScale = false;
this.barSlider1.Size = new System.Drawing.Size(212, 19);
this.barSlider1.SmallChange = ((uint)(1u));
this.barSlider1.TabIndex = 18;
this.barSlider1.Text = "colorSlider1";
this.barSlider1.ThumbInnerColor = System.Drawing.Color.FromArgb(((int)(((byte)(224)))), ((int)(((byte)(224)))), ((int)(((byte)(224)))));
this.barSlider1.ThumbPenColor = System.Drawing.Color.Silver;
this.barSlider1.ThumbRoundRectSize = new System.Drawing.Size(8, 8);
this.barSlider1.ThumbSize = new System.Drawing.Size(8, 8);
this.barSlider1.TickAdd = 0F;
this.barSlider1.TickColor = System.Drawing.Color.White;
this.barSlider1.TickDivide = 0F;
this.barSlider1.TickStyle = System.Windows.Forms.TickStyle.None;
this.barSlider1.ValueChanged += new System.EventHandler(this.barSlider1_ValueChanged);
this.barSlider1.Scroll += new System.Windows.Forms.ScrollEventHandler(this.barSlider1_Scroll);
//
// UVEditor
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
@ -338,7 +323,7 @@
private NumericUpDownFloat transXUD;
private NumericUpDownFloat transYUD;
private NumericUpDownFloat scaleYUD;
private BarSlider.BarSlider barSlider1;
private STButton btnApplyTransform;
private ColorSlider.ColorSlider barSlider1;
}
}

View File

@ -23,7 +23,7 @@ namespace Switch_Toolbox.Library.Forms
comboBox1.Items.Add(2);
comboBox1.SelectedIndex = 0;
barSlider1.Value = 0;
barSlider1.Value = 50;
}
public class ActiveTexture
@ -55,7 +55,7 @@ namespace Switch_Toolbox.Library.Forms
bool IsSRTLoaded = false;
public void Reset()
{
barSlider1.Value = brightness;
barSlider1.Value = (int)(brightness * 100);
scaleXUD.Value = 1;
scaleYUD.Value = 1;
@ -101,7 +101,8 @@ namespace Switch_Toolbox.Library.Forms
Vector2 v2 = new Vector2(0);
Vector2 v3 = new Vector2(0);
if (UvChannelIndex == 0) {
if (UvChannelIndex == 0)
{
v1 = genericObject.vertices[f[v]].uv0;
v2 = genericObject.vertices[f[v + 1]].uv0;
v3 = genericObject.vertices[f[v + 2]].uv0;
@ -352,7 +353,9 @@ namespace Switch_Toolbox.Library.Forms
private void OnMouseWheel(object sender, System.Windows.Forms.MouseEventArgs e)
{
if (e.Delta > 0 && ZoomValue > 0) ZoomValue += 0.1f;
if (e.Delta < 0 && ZoomValue < 30 && ZoomValue > 0.1) ZoomValue -= 0.1f;
if (e.Delta < 0 && ZoomValue < 30 && ZoomValue > 0.2) ZoomValue -= 0.1f;
Console.WriteLine("ZoomValue " + ZoomValue);
gL_ControlLegacy2D1.Invalidate();
}
@ -417,12 +420,6 @@ namespace Switch_Toolbox.Library.Forms
}
}
private void stTrackBar1_Scroll(object sender, EventArgs e)
{
brightness = barSlider1.Value;
gL_ControlLegacy2D1.Invalidate();
}
private void OnNumbicValueSRT_ValueChanged(object sender, EventArgs e)
{
}
@ -435,6 +432,7 @@ namespace Switch_Toolbox.Library.Forms
Vector2 Translate = new Vector2((float)transXUD.Value, (float)transYUD.Value);
shape.TransformUVs(Translate, Scale, UvChannelIndex);
shape.UpdateVertexData();
}
scaleXUD.Value = 1;
@ -449,5 +447,16 @@ namespace Switch_Toolbox.Library.Forms
{
gL_ControlLegacy2D1.Invalidate();
}
private void barSlider1_Scroll(object sender, ScrollEventArgs e)
{
}
private void barSlider1_ValueChanged(object sender, EventArgs e)
{
brightness = (float)barSlider1.Value / 100;
gL_ControlLegacy2D1.Invalidate();
}
}
}

View File

@ -0,0 +1,328 @@
namespace Switch_Toolbox.Library.Forms.test
{
partial class UVEditor
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Component Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.gL_ControlLegacy2D1 = new OpenTK.GLControl();
this.scaleYUD = new Switch_Toolbox.Library.Forms.NumericUpDownFloat();
this.transYUD = new Switch_Toolbox.Library.Forms.NumericUpDownFloat();
this.transXUD = new Switch_Toolbox.Library.Forms.NumericUpDownFloat();
this.stLabel4 = new Switch_Toolbox.Library.Forms.STLabel();
this.stLabel3 = new Switch_Toolbox.Library.Forms.STLabel();
this.scaleXUD = new Switch_Toolbox.Library.Forms.NumericUpDownFloat();
this.stPanel1 = new Switch_Toolbox.Library.Forms.STPanel();
this.barSlider1 = new ColorSlider.ColorSlider();
this.btnApplyTransform = new Switch_Toolbox.Library.Forms.STButton();
this.stLabel2 = new Switch_Toolbox.Library.Forms.STLabel();
this.comboBox2 = new Switch_Toolbox.Library.Forms.STComboBox();
this.comboBox1 = new Switch_Toolbox.Library.Forms.STComboBox();
this.stLabel1 = new Switch_Toolbox.Library.Forms.STLabel();
((System.ComponentModel.ISupportInitialize)(this.scaleYUD)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.transYUD)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.transXUD)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.scaleXUD)).BeginInit();
this.stPanel1.SuspendLayout();
this.SuspendLayout();
//
// gL_ControlLegacy2D1
//
this.gL_ControlLegacy2D1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.gL_ControlLegacy2D1.BackColor = System.Drawing.Color.Black;
this.gL_ControlLegacy2D1.Location = new System.Drawing.Point(0, 70);
this.gL_ControlLegacy2D1.Name = "gL_ControlLegacy2D1";
this.gL_ControlLegacy2D1.Size = new System.Drawing.Size(605, 454);
this.gL_ControlLegacy2D1.TabIndex = 2;
this.gL_ControlLegacy2D1.VSync = false;
this.gL_ControlLegacy2D1.Paint += new System.Windows.Forms.PaintEventHandler(this.gL_ControlLegacy2D1_Paint);
this.gL_ControlLegacy2D1.MouseDown += new System.Windows.Forms.MouseEventHandler(this.gL_ControlLegacy2D1_MouseDown);
this.gL_ControlLegacy2D1.MouseMove += new System.Windows.Forms.MouseEventHandler(this.gL_ControlLegacy2D1_MouseMove);
this.gL_ControlLegacy2D1.MouseWheel += new System.Windows.Forms.MouseEventHandler(this.OnMouseWheel);
this.gL_ControlLegacy2D1.Resize += new System.EventHandler(this.gL_ControlLegacy2D1_Resize);
//
// scaleYUD
//
this.scaleYUD.DecimalPlaces = 5;
this.scaleYUD.Increment = new decimal(new int[] {
5,
0,
0,
196608});
this.scaleYUD.Location = new System.Drawing.Point(135, 43);
this.scaleYUD.Maximum = new decimal(new int[] {
1000000000,
0,
0,
0});
this.scaleYUD.Minimum = new decimal(new int[] {
100000000,
0,
0,
-2147483648});
this.scaleYUD.Name = "scaleYUD";
this.scaleYUD.Size = new System.Drawing.Size(64, 20);
this.scaleYUD.TabIndex = 8;
this.scaleYUD.ValueChanged += new System.EventHandler(this.OnNumbicValueSRT_ValueChanged);
//
// transYUD
//
this.transYUD.DecimalPlaces = 5;
this.transYUD.Increment = new decimal(new int[] {
5,
0,
0,
196608});
this.transYUD.Location = new System.Drawing.Point(360, 43);
this.transYUD.Maximum = new decimal(new int[] {
1000000000,
0,
0,
0});
this.transYUD.Minimum = new decimal(new int[] {
100000000,
0,
0,
-2147483648});
this.transYUD.Name = "transYUD";
this.transYUD.Size = new System.Drawing.Size(64, 20);
this.transYUD.TabIndex = 7;
this.transYUD.ValueChanged += new System.EventHandler(this.OnNumbicValueSRT_ValueChanged);
//
// transXUD
//
this.transXUD.DecimalPlaces = 5;
this.transXUD.Increment = new decimal(new int[] {
5,
0,
0,
196608});
this.transXUD.Location = new System.Drawing.Point(281, 43);
this.transXUD.Maximum = new decimal(new int[] {
1000000000,
0,
0,
0});
this.transXUD.Minimum = new decimal(new int[] {
100000000,
0,
0,
-2147483648});
this.transXUD.Name = "transXUD";
this.transXUD.Size = new System.Drawing.Size(64, 20);
this.transXUD.TabIndex = 6;
this.transXUD.ValueChanged += new System.EventHandler(this.OnNumbicValueSRT_ValueChanged);
//
// stLabel4
//
this.stLabel4.AutoSize = true;
this.stLabel4.Location = new System.Drawing.Point(205, 45);
this.stLabel4.Name = "stLabel4";
this.stLabel4.Size = new System.Drawing.Size(51, 13);
this.stLabel4.TabIndex = 5;
this.stLabel4.Text = "Translate";
//
// stLabel3
//
this.stLabel3.AutoSize = true;
this.stLabel3.Location = new System.Drawing.Point(25, 45);
this.stLabel3.Name = "stLabel3";
this.stLabel3.Size = new System.Drawing.Size(34, 13);
this.stLabel3.TabIndex = 4;
this.stLabel3.Text = "Scale";
//
// scaleXUD
//
this.scaleXUD.DecimalPlaces = 5;
this.scaleXUD.Increment = new decimal(new int[] {
5,
0,
0,
196608});
this.scaleXUD.Location = new System.Drawing.Point(65, 43);
this.scaleXUD.Maximum = new decimal(new int[] {
1000000000,
0,
0,
0});
this.scaleXUD.Minimum = new decimal(new int[] {
100000000,
0,
0,
-2147483648});
this.scaleXUD.Name = "scaleXUD";
this.scaleXUD.Size = new System.Drawing.Size(64, 20);
this.scaleXUD.TabIndex = 3;
this.scaleXUD.ValueChanged += new System.EventHandler(this.OnNumbicValueSRT_ValueChanged);
//
// stPanel1
//
this.stPanel1.Controls.Add(this.barSlider1);
this.stPanel1.Controls.Add(this.btnApplyTransform);
this.stPanel1.Controls.Add(this.scaleYUD);
this.stPanel1.Controls.Add(this.transYUD);
this.stPanel1.Controls.Add(this.stLabel2);
this.stPanel1.Controls.Add(this.transXUD);
this.stPanel1.Controls.Add(this.comboBox2);
this.stPanel1.Controls.Add(this.stLabel4);
this.stPanel1.Controls.Add(this.comboBox1);
this.stPanel1.Controls.Add(this.stLabel3);
this.stPanel1.Controls.Add(this.scaleXUD);
this.stPanel1.Controls.Add(this.stLabel1);
this.stPanel1.Dock = System.Windows.Forms.DockStyle.Top;
this.stPanel1.Location = new System.Drawing.Point(0, 0);
this.stPanel1.Name = "stPanel1";
this.stPanel1.Size = new System.Drawing.Size(605, 70);
this.stPanel1.TabIndex = 1;
//
// barSlider1
//
this.barSlider1.BarInnerColor = System.Drawing.Color.FromArgb(((int)(((byte)(64)))), ((int)(((byte)(64)))), ((int)(((byte)(64)))));
this.barSlider1.BarPenColorBottom = System.Drawing.Color.FromArgb(((int)(((byte)(64)))), ((int)(((byte)(64)))), ((int)(((byte)(64)))));
this.barSlider1.BarPenColorTop = System.Drawing.Color.FromArgb(((int)(((byte)(64)))), ((int)(((byte)(64)))), ((int)(((byte)(64)))));
this.barSlider1.BorderRoundRectSize = new System.Drawing.Size(8, 8);
this.barSlider1.ElapsedInnerColor = System.Drawing.Color.FromArgb(((int)(((byte)(224)))), ((int)(((byte)(224)))), ((int)(((byte)(224)))));
this.barSlider1.ElapsedPenColorBottom = System.Drawing.Color.FromArgb(((int)(((byte)(224)))), ((int)(((byte)(224)))), ((int)(((byte)(224)))));
this.barSlider1.ElapsedPenColorTop = System.Drawing.Color.FromArgb(((int)(((byte)(224)))), ((int)(((byte)(224)))), ((int)(((byte)(224)))));
this.barSlider1.Font = new System.Drawing.Font("Microsoft Sans Serif", 6F);
this.barSlider1.ForeColor = System.Drawing.Color.White;
this.barSlider1.LargeChange = ((uint)(5u));
this.barSlider1.Location = new System.Drawing.Point(56, 7);
this.barSlider1.MouseEffects = false;
this.barSlider1.Name = "barSlider1";
this.barSlider1.ScaleDivisions = 10;
this.barSlider1.ScaleSubDivisions = 5;
this.barSlider1.ShowDivisionsText = true;
this.barSlider1.ShowSmallScale = false;
this.barSlider1.Size = new System.Drawing.Size(160, 25);
this.barSlider1.SmallChange = ((uint)(1u));
this.barSlider1.TabIndex = 17;
this.barSlider1.Text = "colorSlider1";
this.barSlider1.ThumbInnerColor = System.Drawing.Color.FromArgb(((int)(((byte)(224)))), ((int)(((byte)(224)))), ((int)(((byte)(224)))));
this.barSlider1.ThumbPenColor = System.Drawing.Color.Silver;
this.barSlider1.ThumbRoundRectSize = new System.Drawing.Size(8, 8);
this.barSlider1.ThumbSize = new System.Drawing.Size(8, 8);
this.barSlider1.TickAdd = 0F;
this.barSlider1.TickColor = System.Drawing.Color.White;
this.barSlider1.TickDivide = 0F;
this.barSlider1.TickStyle = System.Windows.Forms.TickStyle.None;
this.barSlider1.Scroll += new System.Windows.Forms.ScrollEventHandler(this.barSlider1_Scroll);
//
// btnApplyTransform
//
this.btnApplyTransform.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.btnApplyTransform.Location = new System.Drawing.Point(430, 41);
this.btnApplyTransform.Name = "btnApplyTransform";
this.btnApplyTransform.Size = new System.Drawing.Size(119, 23);
this.btnApplyTransform.TabIndex = 9;
this.btnApplyTransform.Text = "Apply Transform";
this.btnApplyTransform.UseVisualStyleBackColor = false;
this.btnApplyTransform.Click += new System.EventHandler(this.btnApplyTransform_Click);
//
// stLabel2
//
this.stLabel2.AutoSize = true;
this.stLabel2.Location = new System.Drawing.Point(3, 13);
this.stLabel2.Name = "stLabel2";
this.stLabel2.Size = new System.Drawing.Size(56, 13);
this.stLabel2.TabIndex = 2;
this.stLabel2.Text = "Brightness";
//
// comboBox2
//
this.comboBox2.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | 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, 7);
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);
//
// comboBox1
//
this.comboBox1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.comboBox1.BorderColor = System.Drawing.Color.Empty;
this.comboBox1.BorderStyle = System.Windows.Forms.ButtonBorderStyle.Solid;
this.comboBox1.ButtonColor = System.Drawing.Color.Empty;
this.comboBox1.FormattingEnabled = true;
this.comboBox1.Location = new System.Drawing.Point(550, 7);
this.comboBox1.Name = "comboBox1";
this.comboBox1.ReadOnly = true;
this.comboBox1.Size = new System.Drawing.Size(52, 21);
this.comboBox1.TabIndex = 3;
this.comboBox1.SelectedIndexChanged += new System.EventHandler(this.comboBox1_SelectedIndexChanged);
//
// stLabel1
//
this.stLabel1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.stLabel1.AutoSize = true;
this.stLabel1.Location = new System.Drawing.Point(462, 10);
this.stLabel1.Name = "stLabel1";
this.stLabel1.Size = new System.Drawing.Size(82, 13);
this.stLabel1.TabIndex = 4;
this.stLabel1.Text = "Active Channel:";
//
// UVEditor
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.Controls.Add(this.gL_ControlLegacy2D1);
this.Controls.Add(this.stPanel1);
this.Name = "UVEditor";
this.Size = new System.Drawing.Size(605, 524);
((System.ComponentModel.ISupportInitialize)(this.scaleYUD)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.transYUD)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.transXUD)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.scaleXUD)).EndInit();
this.stPanel1.ResumeLayout(false);
this.stPanel1.PerformLayout();
this.ResumeLayout(false);
}
#endregion
private STPanel stPanel1;
private STLabel stLabel1;
private Switch_Toolbox.Library.Forms.STComboBox comboBox1;
private OpenTK.GLControl gL_ControlLegacy2D1;
private Switch_Toolbox.Library.Forms.STComboBox comboBox2;
private STLabel stLabel2;
private NumericUpDownFloat scaleXUD;
private STLabel stLabel3;
private STLabel stLabel4;
private NumericUpDownFloat transXUD;
private NumericUpDownFloat transYUD;
private NumericUpDownFloat scaleYUD;
private STButton btnApplyTransform;
private ColorSlider.ColorSlider barSlider1;
}
}

View File

@ -0,0 +1,532 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using OpenTK;
using OpenTK.Graphics.OpenGL;
namespace Switch_Toolbox.Library.Forms.test
{
public partial class UVEditor : UserControl
{
public UVEditor()
{
InitializeComponent();
comboBox1.Items.Add(0);
comboBox1.Items.Add(1);
comboBox1.Items.Add(2);
comboBox1.SelectedIndex = 0;
barSlider1.Value = 0;
}
public class ActiveTexture
{
public Vector2 UVScale = new Vector2(1);
public Vector2 UVTranslate = new Vector2(0);
public float UVRotate = 0;
public STGenericTexture texture;
public int UvChannelIndex;
public int mapMode = 0;
public int wrapModeS = 1;
public int wrapModeT = 1;
public int minFilter = 3;
public int magFilter = 2;
public int mipDetail = 6;
public uint texWidth = 0;
public uint texHeight = 0;
}
public ActiveTexture activeTexture = new ActiveTexture();
public int brightness = 50; //To see uv maps easier
public int UvChannelIndex = 0;
public STGenericMaterial ActiveMaterial;
public List<STGenericObject> ActiveObjects = new List<STGenericObject>();
public List<ActiveTexture> Textures = new List<ActiveTexture>();
bool IsSRTLoaded = false;
public void Reset()
{
barSlider1.Value = brightness;
scaleXUD.Value = 1;
scaleYUD.Value = 1;
transXUD.Value = 0;
transYUD.Value = 0;
IsSRTLoaded = false;
comboBox2.Items.Clear();
if (RenderTools.defaultTex != null)
texid = RenderTools.defaultTex.Id;
foreach (var item in Textures)
comboBox2.Items.Add(item.texture.Text);
if (comboBox2.Items.Count > 0)
comboBox2.SelectedIndex = 0;
}
public int texid;
public void DrawUVs(List<STGenericObject> genericObjects)
{
foreach (var genericObject in genericObjects)
{
int divisions = 4;
int lineWidth = 1;
Color uvColor = Color.LightGreen;
Color gridColor = Color.Black;
List<int> f = genericObject.lodMeshes[0].getDisplayFace();
for (int v = 0; v < genericObject.lodMeshes[0].displayFaceSize; v += 3)
{
if (genericObject.lodMeshes[0].displayFaceSize < 3 ||
genericObject.vertices.Count < 3)
return;
Vector2 v1 = new Vector2(0);
Vector2 v2 = new Vector2(0);
Vector2 v3 = new Vector2(0);
if (UvChannelIndex == 0)
{
v1 = genericObject.vertices[f[v]].uv0;
v2 = genericObject.vertices[f[v + 1]].uv0;
v3 = genericObject.vertices[f[v + 2]].uv0;
}
if (UvChannelIndex == 1)
{
v1 = genericObject.vertices[f[v]].uv1;
v2 = genericObject.vertices[f[v + 1]].uv1;
v3 = genericObject.vertices[f[v + 2]].uv1;
}
if (UvChannelIndex == 2)
{
v1 = genericObject.vertices[f[v]].uv2;
v2 = genericObject.vertices[f[v + 1]].uv2;
v3 = genericObject.vertices[f[v + 2]].uv2;
}
v1 = new Vector2(v1.X, 1 - v1.Y);
v2 = new Vector2(v2.X, 1 - v2.Y);
v3 = new Vector2(v3.X, 1 - v3.Y);
DrawUVTriangleAndGrid(v1, v2, v3, divisions, uvColor, lineWidth, gridColor);
}
}
}
private void DrawUVTriangleAndGrid(Vector2 v1, Vector2 v2, Vector2 v3, int divisions,
Color uvColor, int lineWidth, Color gridColor)
{
GL.UseProgram(0);
float bounds = 1;
Vector2 scaleUv = activeTexture.UVScale * new Vector2(2);
Vector2 transUv = activeTexture.UVTranslate - new Vector2(1f);
//Disable textures so they don't affect color
GL.Disable(EnableCap.Texture2D);
DrawUvTriangle(v1, v2, v3, uvColor, scaleUv, transUv);
// Draw Grid
GL.Color3(gridColor);
// DrawHorizontalGrid(divisions, bounds, scaleUv);
// DrawVerticalGrid(divisions, bounds, scaleUv);
}
private static void DrawUvTriangle(Vector2 v1, Vector2 v2, Vector2 v3, Color uvColor, Vector2 scaleUv, Vector2 transUv)
{
GL.Color3(uvColor);
GL.Begin(PrimitiveType.Lines);
GL.LineWidth(3);
GL.Vertex2(v1 * scaleUv + transUv);
GL.Vertex2(v2 * scaleUv + transUv);
GL.End();
GL.Begin(PrimitiveType.Lines);
GL.LineWidth(3);
GL.Vertex2(v2 * scaleUv + transUv);
GL.Vertex2(v3 * scaleUv + transUv);
GL.End();
GL.Begin(PrimitiveType.Lines);
GL.LineWidth(3);
GL.Vertex2(v3 * scaleUv + transUv);
GL.Vertex2(v1 * scaleUv + transUv);
GL.End();
}
private void SetupRendering(float lineWidth)
{
// Go to 2D
GL.Viewport(0, 0, gL_ControlLegacy2D1.Width, gL_ControlLegacy2D1.Height);
GL.MatrixMode(MatrixMode.Projection);
GL.PushMatrix();
GL.LoadIdentity();
float aspect = (float)gL_ControlLegacy2D1.Width / (float)gL_ControlLegacy2D1.Height;
GL.Ortho(-aspect, aspect, -1, 1, -1, 1);
GL.MatrixMode(MatrixMode.Modelview);
GL.PushMatrix();
GL.LoadIdentity();
GL.LineWidth(lineWidth);
// Draw over everything
GL.Disable(EnableCap.DepthTest);
GL.Disable(EnableCap.CullFace);
}
private static void DrawVerticalGrid(int divisions, float bounds, Vector2 scaleUv)
{
int verticalCount = divisions;
for (int i = 0; i < verticalCount * bounds; i++)
{
GL.Begin(PrimitiveType.Lines);
GL.Vertex2(new Vector2((1.0f / verticalCount) * i, -bounds) * scaleUv);
GL.Vertex2(new Vector2((1.0f / verticalCount) * i, bounds) * scaleUv);
GL.End();
}
}
private static void DrawHorizontalGrid(int divisions, float bounds, Vector2 scaleUv)
{
int horizontalCount = divisions;
for (int i = 0; i < horizontalCount * bounds; i++)
{
GL.Begin(PrimitiveType.Lines);
GL.Vertex2(new Vector2(-bounds, (1.0f / horizontalCount) * i) * scaleUv);
GL.Vertex2(new Vector2(bounds, (1.0f / horizontalCount) * i) * scaleUv);
GL.End();
}
}
int PlaneSize = 1;
float PosX;
float PosY;
float ZoomValue = 1;
Point MouseDownPos;
private float FindHCF(float m, float n)
{
float temp, remainder;
if (m < n)
{
temp = m;
m = n;
n = temp;
}
while (true)
{
remainder = m % n;
if (remainder == 0)
return n;
else
m = n;
n = remainder;
}
}
private void gL_ControlLegacy2D1_Paint(object sender, PaintEventArgs e)
{
if (ActiveObjects.Count <= 0 || ActiveMaterial == null || Runtime.OpenTKInitialized == false)
return;
gL_ControlLegacy2D1.MakeCurrent();
SetupRendering(1);
GL.ClearColor(System.Drawing.Color.FromArgb(40, 40, 40));
GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
GL.Disable(EnableCap.Texture2D);
//This usually won't be seen unless the textures aren't repeating much
DrawBackdrop();
float PlaneScaleX = 0.5f;
float PlaneScaleY = 0.5f;
float HalfWidth = (float)gL_ControlLegacy2D1.Width / 2.0f;
float HalfHeight = (float)gL_ControlLegacy2D1.Height / 2.0f;
if (activeTexture.texWidth != 0 && activeTexture.texHeight != 0)
{
PlaneScaleX = (float)gL_ControlLegacy2D1.Width / (float)activeTexture.texWidth;
PlaneScaleY = (float)gL_ControlLegacy2D1.Height / (float)activeTexture.texHeight;
}
//Now do the plane with uvs
GL.PushMatrix();
GL.Scale(PlaneScaleY * ZoomValue, -PlaneScaleX * ZoomValue, 1);
GL.Translate(PosX, PosY, 0);
GL.MatrixMode(MatrixMode.Modelview);
GL.LoadIdentity();
GL.MatrixMode(MatrixMode.Texture);
GL.LoadIdentity();
bool UseBackground = true;
if (UseBackground)
{
float BrightnessAmount = (float)brightness / 100f;
int brightnessScale = (int)(BrightnessAmount * 255);
GL.PushAttrib(AttribMask.TextureBit);
var background = new GenericBitmapTexture(Properties.Resources.CheckerBackground);
background.LoadOpenGLTexture();
//Draws a textured plan for our uvs to show on
GL.Enable(EnableCap.Texture2D);
GL.BindTexture(TextureTarget.Texture2D, background.RenderableTex.TexID);
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapS, (int)TextureWrapMode.Repeat);
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapT, (int)TextureWrapMode.Repeat);
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Nearest);
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Nearest);
GL.Begin(PrimitiveType.Quads);
// GL.Color3(brightnessScale, brightnessScale, brightnessScale);
GL.TexCoord2(0.0f, 0.0f);
GL.Vertex2(-HalfWidth, -HalfHeight);
GL.TexCoord2(PlaneScaleX, 0.0f);
GL.Vertex2(HalfWidth, -HalfHeight);
GL.TexCoord2(PlaneScaleX, PlaneScaleY);
GL.Vertex2(HalfWidth, HalfHeight);
GL.TexCoord2(0.0f, PlaneScaleY);
GL.Vertex2(-HalfWidth, HalfHeight);
GL.End();
GL.PopAttrib();
}
if (activeTexture.texture != null)
{
// DrawTexturedPlane(1, activeTexture.texWidth, activeTexture.texHeight);
}
GL.MatrixMode(MatrixMode.Modelview);
GL.LoadIdentity();
DrawUVs(ActiveObjects);
GL.PopMatrix();
gL_ControlLegacy2D1.SwapBuffers();
}
//Aspect ratio stuff from https://github.com/libertyernie/brawltools/blob/40d7431b1a01ef4a0411cd69e51411bd581e93e2/BrawlLib/System/Windows/Controls/TexCoordRenderer.cs
private void DrawTexturedPlane(float scale, uint TextureWidth, uint TextureHeight)
{
//Draws a textured plan for our uvs to show on
GL.Enable(EnableCap.Texture2D);
GL.BindTexture(TextureTarget.Texture2D, texid);
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapS, (float)STGenericMatTexture.wrapmode[activeTexture.wrapModeS]);
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapT, (float)STGenericMatTexture.wrapmode[activeTexture.wrapModeT]);
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)STGenericMatTexture.minfilter[activeTexture.minFilter]);
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)STGenericMatTexture.magfilter[activeTexture.magFilter]);
float HalfWidth = (float)gL_ControlLegacy2D1.Width / 2.0f;
float HalfHeight = (float)gL_ControlLegacy2D1.Height / 2.0f;
Vector2 scaleCenter = new Vector2(0.5f, 0.5f);
float[] texCoord = new float[8];
float tAspect = (float)TextureWidth / TextureHeight;
float wAspect = (float)gL_ControlLegacy2D1.Width / gL_ControlLegacy2D1.Height;
Vector2 topLeft = new Vector2();
Vector2 bottomRight = new Vector2();
float xCorrect = 1.0f, yCorrect = 1.0f;
if (tAspect > wAspect)
{
//Texture is wider, use horizontal fit
//X touches the edges of the window, Y has top and bottom padding
texCoord[0] = texCoord[6] = 0.0f;
texCoord[2] = texCoord[4] = 1.0f;
texCoord[1] = texCoord[3] = (yCorrect = tAspect / wAspect) / 2.0f + 0.5f;
texCoord[5] = texCoord[7] = 1.0f - texCoord[1];
bottomRight = new Vector2(HalfWidth, (((float)gL_ControlLegacy2D1.Height - ((float)gL_ControlLegacy2D1.Width /
TextureWidth * TextureHeight)) / (float)gL_ControlLegacy2D1.Height / 2.0f - 0.5f) *
(float)gL_ControlLegacy2D1.Height);
topLeft = new Vector2(-HalfHeight, -bottomRight.Y);
}
else
{
//Window is wider, use vertical fit
//Y touches the edges of the window, X has left and right padding
texCoord[1] = texCoord[3] = 1.0f;
texCoord[5] = texCoord[7] = 0.0f;
//X
texCoord[2] = texCoord[4] = (xCorrect = wAspect / tAspect) / 2.0f + 0.5f;
texCoord[0] = texCoord[6] = 1.0f - texCoord[2];
bottomRight = new Vector2(1.0f - (((float)gL_ControlLegacy2D1.Width -
((float)gL_ControlLegacy2D1.Height / TextureHeight * TextureWidth)) / gL_ControlLegacy2D1.Width / 2.0f - 0.5f) *
(float)gL_ControlLegacy2D1.Width, -HalfHeight);
topLeft = new Vector2(-bottomRight.X, HalfHeight);
}
GL.Begin(PrimitiveType.Quads);
GL.TexCoord2(texCoord[0], texCoord[1]);
GL.Vertex2(-HalfWidth, -HalfHeight);
GL.TexCoord2(texCoord[2], texCoord[3]);
GL.Vertex2(HalfWidth, -HalfHeight);
GL.TexCoord2(texCoord[4], texCoord[5]);
GL.Vertex2(HalfWidth, HalfHeight);
GL.TexCoord2(texCoord[6], texCoord[7]);
GL.Vertex2(-HalfWidth, HalfHeight);
GL.End();
}
private void DrawBackdrop()
{
//Background
GL.Begin(PrimitiveType.Quads);
GL.Color3(Color.FromArgb(40, 40, 40));
GL.TexCoord2(1, 1);
GL.Vertex2(PlaneSize, -PlaneSize);
GL.TexCoord2(0, 1);
GL.Vertex2(-PlaneSize, -PlaneSize);
GL.TexCoord2(0, 0);
GL.Vertex2(-PlaneSize, PlaneSize);
GL.TexCoord2(1, 0);
GL.Vertex2(PlaneSize, PlaneSize);
GL.End();
}
private void OnMouseWheel(object sender, System.Windows.Forms.MouseEventArgs e)
{
if (e.Delta > 0 && ZoomValue > 0) ZoomValue += 0.1f;
if (e.Delta < 0 && ZoomValue < 30 && ZoomValue > 0.1) ZoomValue -= 0.1f;
gL_ControlLegacy2D1.Invalidate();
}
private void gL_ControlLegacy2D1_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
MouseDownPos = MousePosition;
}
}
private void gL_ControlLegacy2D1_MouseMove(object sender, MouseEventArgs e)
{
if (e.Button != MouseButtons.Left)
return;
Point temp = Control.MousePosition;
Point res = new Point(MouseDownPos.X - temp.X, MouseDownPos.Y - temp.Y);
PosX -= res.X * 0.001f;
PosY -= res.Y * 0.001f;
gL_ControlLegacy2D1.Invalidate();
MouseDownPos = temp;
}
private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)
{
if (comboBox2.SelectedIndex >= 0)
{
activeTexture = Textures[comboBox2.SelectedIndex];
UvChannelIndex = activeTexture.UvChannelIndex;
scaleXUD.Value = (decimal)activeTexture.UVScale.X;
scaleYUD.Value = (decimal)activeTexture.UVScale.Y;
transXUD.Value = (decimal)activeTexture.UVTranslate.X;
transYUD.Value = (decimal)activeTexture.UVTranslate.Y;
var texture = activeTexture.texture;
if (texture.RenderableTex == null)
texture.LoadOpenGLTexture();
texid = texture.RenderableTex.TexID;
activeTexture.texWidth = texture.Width;
activeTexture.texHeight = texture.Height;
gL_ControlLegacy2D1.Invalidate();
IsSRTLoaded = true;
}
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
if (comboBox1.SelectedIndex >= 0)
{
UvChannelIndex = comboBox1.SelectedIndex;
gL_ControlLegacy2D1.Invalidate();
}
}
private void OnNumbicValueSRT_ValueChanged(object sender, EventArgs e)
{
}
private void btnApplyTransform_Click(object sender, EventArgs e)
{
foreach (var shape in ActiveObjects)
{
Vector2 Scale = new Vector2((float)scaleXUD.Value, (float)scaleYUD.Value);
Vector2 Translate = new Vector2((float)transXUD.Value, (float)transYUD.Value);
shape.TransformUVs(Translate, Scale, UvChannelIndex);
}
scaleXUD.Value = 1;
scaleYUD.Value = 1;
transXUD.Value = 0;
transYUD.Value = 0;
gL_ControlLegacy2D1.Invalidate();
}
private void gL_ControlLegacy2D1_Resize(object sender, EventArgs e)
{
gL_ControlLegacy2D1.Invalidate();
}
private void stTrackBar1_Scroll(object sender, ScrollEventArgs e)
{
}
private void barSlider1_Scroll(object sender, ScrollEventArgs e)
{
brightness = barSlider1.Value;
gL_ControlLegacy2D1.Invalidate();
}
}
}

View File

@ -0,0 +1,120 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View File

@ -0,0 +1,74 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Switch_Toolbox.Library
{
//
// A class which can create generic texture instances from bitmaps for usage in opengl and image editors.
//
public class GenericBitmapTexture : STGenericTexture
{
public override bool CanEdit { get; set; } = true;
public override TEX_FORMAT[] SupportedFormats
{
get
{
return new TEX_FORMAT[] { TEX_FORMAT.R8G8B8A8_UNORM };
}
}
public byte[] ImageData;
public GenericBitmapTexture(byte[] FileData, int width, int height)
{
Format = TEX_FORMAT.R8G8B8A8_UNORM;
Width = (uint)width;
Height = (uint)height;
ImageData = DDSCompressor.CompressBlock(FileData, width, height,
DDS.DXGI_FORMAT.DXGI_FORMAT_R8G8B8A8_UNORM_SRGB);
}
public GenericBitmapTexture(string FileName) {
LoadBitmap(new Bitmap(FileName));
}
public GenericBitmapTexture(Bitmap Image) {
LoadBitmap(Image);
}
private void LoadBitmap(Bitmap Image)
{
Image = BitmapExtension.SwapBlueRedChannels(Image);
Format = TEX_FORMAT.R8G8B8A8_UNORM;
Width = (uint)Image.Width;
Height = (uint)Image.Height;
MipCount = 1;
ImageData = GenerateMipsAndCompress(Image, Format);
if (ImageData == null || ImageData.Length <= 0)
throw new Exception("Image failed to encode!");
}
public override void SetImageData(Bitmap bitmap, int ArrayLevel)
{
byte[] Data = BitmapExtension.ImageToByte(bitmap);
Width = (uint)bitmap.Width;
Height = (uint)bitmap.Height;
ImageData = DDSCompressor.EncodePixelBlock(Data, bitmap.Width, bitmap.Width, DDS.DXGI_FORMAT.DXGI_FORMAT_R8G8B8A8_UNORM_SRGB);
}
public override byte[] GetImageData(int ArrayLevel = 0, int MipLevel = 0)
{
return ImageData;
}
}
}

View File

@ -18,6 +18,12 @@ namespace Switch_Toolbox.Library
}
//To update buffer data for opengl
public virtual void UpdateVertexData()
{
}
public bool HasPos;
public bool HasNrm;
public bool HasUv0;

View File

@ -728,6 +728,31 @@ namespace Switch_Toolbox.Library
return channels;
}
public static int GenerateTotalMipCount(uint Width, uint Height)
{
int MipmapNum = 0;
uint num = Math.Max(Width, Height);
int width = (int)Width;
int height = (int)Height;
while (true)
{
num >>= 1;
width = width / 2;
height = height / 2;
if (width <= 0 || height <= 0)
break;
if (num > 0)
++MipmapNum;
else
break;
}
return MipmapNum;
}
public static string SetNameFromPath(string path)
{

View File

@ -63,10 +63,20 @@ namespace Switch_Toolbox.Library.Rendering
pixelInternalFormat = PixelInternalFormat.CompressedRgbaS3tcDxt5Ext;
break;
case TEX_FORMAT.BC4_UNORM:
pixelInternalFormat = PixelInternalFormat.CompressedRedRgtc1;
break;
case TEX_FORMAT.BC4_SNORM:
pixelInternalFormat = PixelInternalFormat.CompressedSignedRedRgtc1;
//Convert to rgb to prevent red output
//While shaders could prevent this, converting is easier and works fine across all editors
data = STGenericTexture.DecodeBlock(data,
GenericTexture.Width,
GenericTexture.Height,
GenericTexture.Format,
GenericTexture.PlatformSwizzle);
pixelInternalFormat = PixelInternalFormat.Rgba;
pixelFormat = OpenTK.Graphics.OpenGL.PixelFormat.Rgba;
// pixelInternalFormat = PixelInternalFormat.CompressedRedRgtc1;
// pixelInternalFormat = PixelInternalFormat.CompressedSignedRedRgtc1;
break;
case TEX_FORMAT.BC5_SNORM:
pixelInternalFormat = PixelInternalFormat.CompressedRgRgtc2;

View File

@ -44,6 +44,11 @@ namespace Switch_Toolbox.Library.IO
return signature == Identifier;
}
public string ReadZeroTerminatedString()
{
return ReadString(BinaryStringFormat.ZeroTerminated);
}
/// <summary>
/// Checks the byte order mark to determine the endianness of the reader.
/// </summary>

View File

@ -408,6 +408,12 @@
<Compile Include="Forms\Editors\Animation\TimeLine.Designer.cs">
<DependentUpon>TimeLine.cs</DependentUpon>
</Compile>
<Compile Include="Forms\Editors\UV\UVEditor2.cs">
<SubType>UserControl</SubType>
</Compile>
<Compile Include="Forms\Editors\UV\UVEditor2.Designer.cs">
<DependentUpon>UVEditor2.cs</DependentUpon>
</Compile>
<Compile Include="Forms\Extensions\MDICustom.cs" />
<Compile Include="Forms\Editors\Object Editor\ObjectEditor.cs">
<SubType>Form</SubType>
@ -488,6 +494,7 @@
<Compile Include="Forms\Wpf\WpfTimeline.xaml.cs">
<DependentUpon>WpfTimeline.xaml</DependentUpon>
</Compile>
<Compile Include="Generics\GenericBitmapTexture.cs" />
<Compile Include="Generics\GenericMaterial.cs" />
<Compile Include="Generics\GenericMatTexture.cs" />
<Compile Include="Generics\GenericModel.cs" />
@ -770,6 +777,9 @@
<EmbeddedResource Include="Forms\Editors\UV\UVEditor.resx">
<DependentUpon>UVEditor.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Forms\Editors\UV\UVEditor2.resx">
<DependentUpon>UVEditor2.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Forms\GL\GLControl2D.resx">
<DependentUpon>GLControl2D.cs</DependentUpon>
</EmbeddedResource>

View File

@ -41,6 +41,7 @@ namespace Switch_Toolbox.Library
case PICASurfaceFormat.L8: return TEX_FORMAT.L8;
case PICASurfaceFormat.A8: return TEX_FORMAT.A8_UNORM;
case PICASurfaceFormat.LA4: return TEX_FORMAT.LA4;
case PICASurfaceFormat.L4: return TEX_FORMAT.L4;
case PICASurfaceFormat.A4: return TEX_FORMAT.A4;
case PICASurfaceFormat.ETC1: return TEX_FORMAT.ETC1;
case PICASurfaceFormat.ETC1A4: return TEX_FORMAT.ETC1_A4;

View File

@ -76,6 +76,7 @@ uniform float bake_calc_type;
uniform float enable_fresnel;
uniform float enable_emission;
uniform float cSpecularType;
uniform float cIsEnableNormalMap;
// Texture Map Toggles
uniform int HasDiffuse;
@ -165,7 +166,7 @@ void main()
int NormalMapUVIndex = 0;
if (uking_texture2_texcoord == 1)
if (uking_texture2_texcoord == 1 || cIsEnableNormalMap == 1)
NormalMapUVIndex = 1;
vec3 N = normal;