More fixes

Many fixes to the enum data for switch bfres. Filter data can be edited properly.
UVs in UV editor can be transformed
This commit is contained in:
KillzXGaming 2019-04-11 18:05:15 -04:00
parent 3f510ce76b
commit 270d441dcc
21 changed files with 263 additions and 106 deletions

Binary file not shown.

View file

@ -0,0 +1,173 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Threading.Tasks;
using Switch_Toolbox;
using System.Windows.Forms;
using Switch_Toolbox.Library;
using Switch_Toolbox.Library.IO;
using Switch_Toolbox.Library.Forms;
namespace FirstPlugin
{
public class APAKFileInfo : ArchiveFileInfo
{
}
public class APAK : TreeNodeFile, IArchiveFile
{
public bool CanSave { get; set; }
public string[] Description { get; set; } = new string[] { "APAK" };
public string[] Extension { get; set; } = new string[] { "*.apak" };
public string FileName { get; set; }
public string FilePath { get; set; }
public IFileInfo IFileInfo { get; set; }
public bool Identify(System.IO.Stream stream)
{
using (var reader = new Switch_Toolbox.Library.IO.FileReader(stream, true))
{
return reader.CheckSignature(4, "APAK");
}
}
public Type[] Types
{
get
{
List<Type> types = new List<Type>();
return types.ToArray();
}
}
public IEnumerable<ArchiveFileInfo> Files { get; }
public bool CanAddFiles { get; set; } = true;
public bool CanRenameFiles { get; set; } = true;
public bool CanReplaceFiles { get; set; } = true;
public bool CanDeleteFiles { get; set; } = true;
public void Load(System.IO.Stream stream)
{
Text = FileName;
CanDelete = true;
using (var reader = new FileReader(stream))
{
reader.ByteOrder = Syroot.BinaryData.ByteOrder.BigEndian;
reader.ReadSignature(4, "APAK");
uint Version = reader.ReadUInt32();
uint FileCount = reader.ReadUInt32();
uint unk = reader.ReadUInt32();
uint unk2 = reader.ReadUInt32();
uint DataTotalSize = reader.ReadUInt32();
uint unk3 = reader.ReadUInt32();
for (int i = 0; i < FileCount; i++)
{
var info = new FileInfo(reader);
APAKFileInfo archive = new APAKFileInfo();
archive.FileData = new System.IO.MemoryStream(info.Data);
archive.Name = info.Text;
Nodes.Add(info);
}
}
}
public class FileInfo : TreeNodeCustom
{
public byte[] Data;
public FileInfo()
{
ContextMenu = new ContextMenu();
MenuItem export = new MenuItem("Export Raw Data");
ContextMenu.MenuItems.Add(export);
export.Click += Export;
}
private void Export(object sender, EventArgs args)
{
SaveFileDialog sfd = new SaveFileDialog();
sfd.FileName = Text;
sfd.DefaultExt = Path.GetExtension(Text);
sfd.Filter = "Raw Data (*.*)|*.*";
if (sfd.ShowDialog() == DialogResult.OK)
{
File.WriteAllBytes(sfd.FileName, Data);
}
}
public override void OnClick(TreeView treeview)
{
HexEditor editor = (HexEditor)LibraryGUI.Instance.GetActiveContent(typeof(HexEditor));
if (editor == null)
{
editor = new HexEditor();
LibraryGUI.Instance.LoadEditor(editor);
}
editor.Text = Text;
editor.Dock = DockStyle.Fill;
editor.LoadData(Data);
}
public FileInfo(FileReader reader)
{
long pos = reader.Position;
uint dataOffset = reader.ReadUInt32();
uint uncompressedSize = reader.ReadUInt32();
uint compressedSize = reader.ReadUInt32();
uint unk = reader.ReadUInt32();
uint unk2 = reader.ReadUInt32();
uint unk3 = reader.ReadUInt32();
uint unk4 = reader.ReadUInt32();
uint FileOffset = reader.ReadUInt32();
uint FileSize = reader.ReadUInt32();
uint padding = reader.ReadUInt32();
// reader.Seek(NameOffset, System.IO.SeekOrigin.Begin);
Text = reader.ReadString(Syroot.BinaryData.BinaryStringFormat.ZeroTerminated);
reader.Seek(dataOffset, System.IO.SeekOrigin.Begin);
Data = reader.ReadBytes((int)compressedSize);
reader.Seek(pos + 16, System.IO.SeekOrigin.Begin);
ContextMenu = new ContextMenu();
MenuItem export = new MenuItem("Export Raw Data");
ContextMenu.MenuItems.Add(export);
export.Click += Export;
}
}
public void Unload()
{
}
public byte[] Save()
{
return null;
}
public bool AddFile(ArchiveFileInfo archiveFileInfo)
{
return false;
}
public bool DeleteFile(ArchiveFileInfo archiveFileInfo)
{
return false;
}
}
}

View file

@ -553,7 +553,6 @@ namespace Bfres.Structs
}
public class SwitchSamplerInfo
{
public ResGFX.FilterMode FilterMode;
public ResGFX.TexClamp TexClampX;
public ResGFX.TexClamp TexClampY;
public ResGFX.TexClamp TexClampZ;

View file

@ -538,6 +538,11 @@ namespace FirstPlugin
m.HasLightMap = true;
texture.Type = MatTexture.TextureType.Light;
}
else if (texture.SamplerName == "_ao0")
{
texture.Type = MatTexture.TextureType.AO;
m.HasAmbientOcclusionMap = true;
}
}
else if (Runtime.activeGame == Runtime.ActiveGame.SMO)
{
@ -576,6 +581,11 @@ namespace FirstPlugin
texture.Type = MatTexture.TextureType.SubSurfaceScattering;
m.HasSubSurfaceScatteringMap = true;
}
else if (texture.SamplerName == "_ao0")
{
texture.Type = MatTexture.TextureType.AO;
m.HasAmbientOcclusionMap = true;
}
}
else
{
@ -635,6 +645,11 @@ namespace FirstPlugin
texture.Type = MatTexture.TextureType.SubSurfaceScattering;
m.HasSubSurfaceScatteringMap = true;
}
else if (texture.SamplerName == "_ao0")
{
texture.Type = MatTexture.TextureType.AO;
m.HasAmbientOcclusionMap = true;
}
}
texture.textureUnit = textureUnit++;

View file

@ -186,6 +186,7 @@
<ItemGroup>
<Compile Include="Config.cs" />
<Compile Include="FileFormats\AAMP\AAMP.cs" />
<Compile Include="FileFormats\Archives\APAK.cs" />
<Compile Include="FileFormats\Archives\TMPK.cs" />
<Compile Include="FileFormats\Audio\Archives\BARS.cs" />
<Compile Include="FileFormats\Audio\BARSLIST.cs" />

View file

@ -1 +1 @@
fb185deacd6b91f90d3d81f0920e25025a615d0b
a9478050cb84dea301afe57fdf9fb71912dcaa20

View file

@ -36,11 +36,12 @@
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.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.comboBox2 = new Switch_Toolbox.Library.Forms.STComboBox();
this.stLabel2 = new Switch_Toolbox.Library.Forms.STLabel();
((System.ComponentModel.ISupportInitialize)(this.scaleYUD)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.transYUD)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.transXUD)).BeginInit();
@ -181,6 +182,7 @@
//
// stPanel1
//
this.stPanel1.Controls.Add(this.btnApplyTransform);
this.stPanel1.Controls.Add(this.scaleYUD);
this.stPanel1.Controls.Add(this.barSlider1);
this.stPanel1.Controls.Add(this.transYUD);
@ -198,19 +200,38 @@
this.stPanel1.Size = new System.Drawing.Size(605, 70);
this.stPanel1.TabIndex = 1;
//
// 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);
//
// 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;
@ -234,9 +255,34 @@
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.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.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, 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)));
@ -246,6 +292,7 @@
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);
@ -260,28 +307,6 @@
this.stLabel1.TabIndex = 4;
this.stLabel1.Text = "Active Channel:";
//
// 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.Size = new System.Drawing.Size(166, 21);
this.comboBox2.TabIndex = 5;
this.comboBox2.SelectedIndexChanged += new System.EventHandler(this.comboBox2_SelectedIndexChanged);
//
// 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";
//
// UVEditor
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
@ -314,5 +339,6 @@
private NumericUpDownFloat transYUD;
private NumericUpDownFloat scaleYUD;
private BarSlider.BarSlider barSlider1;
private STButton btnApplyTransform;
}
}

View file

@ -423,13 +423,18 @@ namespace Switch_Toolbox.Library.Forms
private void OnNumbicValueSRT_ValueChanged(object sender, EventArgs e)
{
if (IsSRTLoaded)
}
private void btnApplyTransform_Click(object sender, EventArgs e)
{
foreach (var shape in ActiveObjects)
{
/* activeTexture.UVScale.X = (float)scaleXUD.Value;
activeTexture.UVScale.Y = (float)scaleYUD.Value;
activeTexture.UVTranslate.X = (float)transXUD.Value;
activeTexture.UVTranslate.Y = (float)transYUD.Value;
gL_ControlLegacy2D1.Invalidate();*/
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);
gL_ControlLegacy2D1.Invalidate();
}
}

View file

@ -186,6 +186,18 @@ namespace Switch_Toolbox.Library
v.uv0 = new Vector2(1 - v.uv0.X, v.uv0.Y);
}
}
public void TransformUVs(Vector2 Translate, Vector2 Scale, int Index)
{
foreach (Vertex v in vertices)
{
if (Index == 0)
v.uv0 = (v.uv0 * Scale) + Translate;
else if (Index == 1)
v.uv1 = (v.uv1 * Scale) + Translate;
else
v.uv2 = (v.uv2 * Scale) + Translate;
}
}
public void CalculateTangentBitangent(bool UseUVLayer2)
{
if (vertices.Count < 3)

View file

@ -2362,80 +2362,6 @@
Represents the type of primitives to draw.
</summary>
</member>
<member name="F:Syroot.NintenTools.NSW.Bfres.GFX.PrimitiveType.Points">
<summary>
Requires at least 1 element and 1 more to draw another primitive.
</summary>
</member>
<member name="F:Syroot.NintenTools.NSW.Bfres.GFX.PrimitiveType.Lines">
<summary>
Requires at least 2 elements and 2 more to draw another primitive.
</summary>
</member>
<member name="F:Syroot.NintenTools.NSW.Bfres.GFX.PrimitiveType.LineLoop">
<summary>
Requires at least 2 elements and 1 more to draw another primitive.
</summary>
</member>
<member name="F:Syroot.NintenTools.NSW.Bfres.GFX.PrimitiveType.Triangles">
<summary>
Requires at least 3 elements and 3 more to draw another primitive.
</summary>
</member>
<member name="F:Syroot.NintenTools.NSW.Bfres.GFX.PrimitiveType.LineStrip">
<summary>
Requires at least 2 elements and 1 more to draw another primitive.
</summary>
</member>
<member name="F:Syroot.NintenTools.NSW.Bfres.GFX.PrimitiveType.TriangleStrip">
<summary>
Requires at least 3 elements and 1 more to draw another primitive.
</summary>
</member>
<member name="F:Syroot.NintenTools.NSW.Bfres.GFX.PrimitiveType.TriangleFan">
<summary>
Requires at least 3 elements and 1 more to draw another primitive.
</summary>
</member>
<member name="F:Syroot.NintenTools.NSW.Bfres.GFX.PrimitiveType.Quads">
<summary>
Requires at least 4 elements and 4 more to draw another primitive.
</summary>
</member>
<member name="F:Syroot.NintenTools.NSW.Bfres.GFX.PrimitiveType.QuadStrip">
<summary>
Requires at least 4 elements and 2 more to draw another primitive.
</summary>
</member>
<member name="F:Syroot.NintenTools.NSW.Bfres.GFX.PrimitiveType.Polygon">
<summary>
Requires at least 4 elements and 4 more to draw another primitive.
</summary>
</member>
<member name="F:Syroot.NintenTools.NSW.Bfres.GFX.PrimitiveType.LinesAdjacency">
<summary>
Requires at least 4 elements and 4 more to draw another primitive.
</summary>
</member>
<member name="F:Syroot.NintenTools.NSW.Bfres.GFX.PrimitiveType.LineStripAdjacency">
<summary>
Requires at least 4 elements and 1 more to draw another primitive.
</summary>
</member>
<member name="F:Syroot.NintenTools.NSW.Bfres.GFX.PrimitiveType.TrianglesAdjacency">
<summary>
Requires at least 6 elements and 6 more to draw another primitive.
</summary>
</member>
<member name="F:Syroot.NintenTools.NSW.Bfres.GFX.PrimitiveType.TriangleStripAdjacency">
<summary>
Requires at least 6 elements and 2 more to draw another primitive.
</summary>
</member>
<member name="F:Syroot.NintenTools.NSW.Bfres.GFX.PrimitiveType.Patches">
<summary>
</summary>
</member>
<member name="T:Syroot.NintenTools.NSW.Bfres.GFX.TexBorderType">
<summary>
Represents type of border color to use.