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

Fix vertex increase from assimp's tans/bitans (calculate with ST)

This commit is contained in:
KillzXGaming 2019-07-30 15:38:42 -04:00
parent c4ac54acd0
commit 8afae95e2c
11 changed files with 152 additions and 40 deletions

Binary file not shown.

View File

@ -67,7 +67,7 @@ namespace FirstPlugin
public void ConvertFromString(string text) public void ConvertFromString(string text)
{ {
if (aampFileV1 != null) if (aampFileV1 != null)
AampYamlConverter.ToAamp(aampFileV1); AampYamlConverter.ToAamp(aampFileV1, text);
} }
#endregion #endregion

View File

@ -193,11 +193,11 @@ namespace Bfres.Structs
if (texture != null && texture.MipCount == 1) if (texture != null && texture.MipCount == 1)
ReplaceTexture(FileName, Format, texture.MipCount); ReplaceTexture(FileName, Format, texture.MipCount);
else else
ReplaceTexture(FileName, Format, 0, null, false, false, false, texture.SwizzlePattern); ReplaceTexture(FileName, Format, 0, null, false, false, false);
} }
public void ReplaceTexture(string FileName, TEX_FORMAT DefaultFormat = TEX_FORMAT.UNKNOWN, uint MipMapCount = 0, TEX_FORMAT[] SupportedFormats = null, public void ReplaceTexture(string FileName, TEX_FORMAT DefaultFormat = TEX_FORMAT.UNKNOWN, uint MipMapCount = 0, TEX_FORMAT[] SupportedFormats = null,
bool IsSwizzleReadOnly = false, bool IsTileModeReadOnly = false, bool IsFormatReadOnly = false, uint SwizzlePattern = 0) bool IsSwizzleReadOnly = false, bool IsTileModeReadOnly = false, bool IsFormatReadOnly = false)
{ {
string ext = System.IO.Path.GetExtension(FileName); string ext = System.IO.Path.GetExtension(FileName);
ext = ext.ToLower(); ext = ext.ToLower();
@ -216,7 +216,6 @@ namespace Bfres.Structs
GTXImporterSettings setting = SetImporterSettings(FileName, DefaultFormat); GTXImporterSettings setting = SetImporterSettings(FileName, DefaultFormat);
setting.MipSwizzle = Tex2Swizzle; setting.MipSwizzle = Tex2Swizzle;
setting.SwizzlePattern = SwizzlePattern;
GTXTextureImporter importer = new GTXTextureImporter(); GTXTextureImporter importer = new GTXTextureImporter();

View File

@ -380,7 +380,7 @@ namespace FirstPlugin
public override void Replace(string FileName) public override void Replace(string FileName)
{ {
Bfres.Structs.FTEX ftex = new Bfres.Structs.FTEX(); Bfres.Structs.FTEX ftex = new Bfres.Structs.FTEX();
ftex.ReplaceTexture(FileName, Format, 1, SupportedFormats, true, true, false, SwizzlePattern); ftex.ReplaceTexture(FileName, Format, 1, SupportedFormats, true, true, false);
if (ftex.texture != null) if (ftex.texture != null)
{ {
TextureTGLP.Format = (ushort)ConvertToGx2(ftex.Format); TextureTGLP.Format = (ushort)ConvertToGx2(ftex.Format);

View File

@ -61,7 +61,76 @@ namespace FirstPlugin
else else
reader.ByteOrder = Syroot.BinaryData.ByteOrder.BigEndian; reader.ByteOrder = Syroot.BinaryData.ByteOrder.BigEndian;
string Version = reader.ReadString(4); uint Version = reader.ReadUInt32();
uint FileSize = reader.ReadUInt32();
uint firstChunkOffset = reader.ReadUInt32();
uint padding = reader.ReadUInt32();
uint numChunks = reader.ReadUInt32();
switch (Version)
{
case 0x30303334:break;
case 0x30303335: break;
case 0x30303336: break;
case 0x30303337: break;
default: break;
}
reader.SeekBegin(firstChunkOffset);
for (int i =0; i < numChunks; i++)
{
long chunkPos = reader.Position;
string chunkMagic = reader.ReadString(4, Encoding.ASCII);
uint version = reader.ReadUInt32();
uint chunkSize = reader.ReadUInt32();
if (chunkMagic == "G1MF")
{
}
else if (chunkMagic == "G1MS")
{
}
else if (chunkMagic == "G1MM")
{
}
else if (chunkMagic == "G1MG")
{
}
else if (chunkMagic == "COLL")
{
}
else if (chunkMagic == "HAIR")
{
}
else if (chunkMagic == "NUNO")
{
}
else if (chunkMagic == "NUNS")
{
}
else if (chunkMagic == "NUNV")
{
}
else if (chunkMagic == "EXTR")
{
}
else
{
}
reader.SeekBegin(chunkPos + chunkSize);
}
} }
} }
} }

View File

@ -133,22 +133,37 @@ namespace FirstPlugin
switch (format) switch (format)
{ {
case 0x5F: case 0x00: //ABGR
case 0x01: case 0x01: //BGRA 32 bit (no mip maps)
case 0x02: //RGBA 32 bit
case 0x09: case 0x09:
tex.Format = TEX_FORMAT.R8G8B8A8_UNORM; tex.Format = TEX_FORMAT.R8G8B8A8_UNORM;
break; break;
case 0x06: case 0x06:
case 0x59: //Switch case 0x10: //PC and xbox (swizzled)
case 0x60: //Wii U case 0x59:
case 0x60: //Swizzled
tex.Format = TEX_FORMAT.BC1_UNORM; tex.Format = TEX_FORMAT.BC1_UNORM;
break; break;
case 0x12: case 0x7:
case 0x8: case 0x8:
case 0x5B: //Switch case 0x12: //PC and xbox (swizzled)
case 0x62: //Wii U case 0x5B:
case 0x62: //bc1 swizzled
tex.Format = TEX_FORMAT.BC3_UNORM; tex.Format = TEX_FORMAT.BC3_UNORM;
break; break;
case 0x5C:
tex.Format = TEX_FORMAT.BC4_UNORM;
break;
case 0x5D: //DXT5 swizzled or ATI2
tex.Format = TEX_FORMAT.BC5_UNORM;
break;
case 0x5E:
tex.Format = TEX_FORMAT.BC6H_UF16; //Uses cubemaps
break;
case 0x5F:
tex.Format = TEX_FORMAT.BC7_UNORM;
break;
default: default:
throw new Exception("Unsupported format! " + format.ToString("x")); throw new Exception("Unsupported format! " + format.ToString("x"));
} }

View File

@ -7,6 +7,10 @@ using Aampv1 = AampV1Library;
using Aampv2 = AampV2Library; using Aampv2 = AampV2Library;
using System.IO; using System.IO;
using Syroot.Maths; using Syroot.Maths;
using SharpYaml;
using SharpYaml.Events;
using SharpYaml.Serialization;
using SharpYaml.Serialization.Serializers;
namespace FirstPlugin namespace FirstPlugin
{ {
@ -24,6 +28,13 @@ namespace FirstPlugin
public class AampYamlConverter public class AampYamlConverter
{ {
public class YamlAamp
{
public const string Identifier = "!aamp";
public string version { get; set; }
}
#region V1 AAMP #region V1 AAMP
public static string ToYaml(Aampv1.AampFile aampFile) public static string ToYaml(Aampv1.AampFile aampFile)
@ -133,9 +144,46 @@ namespace FirstPlugin
return curveStr; return curveStr;
} }
public static void ToAamp(Aampv1.AampFile aampFile) //I could've used a yaml parser, but incase i need to change it up to look nicer and support leo's aamp layout, do it manually
public static void ToAamp(Aampv1.AampFile aampFile, string text)
{ {
byte[] TextData = Encoding.Unicode.GetBytes(text);
StreamReader t = new StreamReader(new MemoryStream(TextData), Encoding.GetEncoding(932));
var yaml = new YamlStream();
yaml.Load(new StringReader(text));
/* var mapping = (YamlMappingNode)yaml.Documents[0].RootNode;
foreach (var item in mapping.AllNodes)
{
Console.WriteLine("n " + item);
}*/
/* byte[] TextData = Encoding.Unicode.GetBytes(text);
StreamReader t = new StreamReader(new MemoryStream(TextData), Encoding.GetEncoding(932));
using (var reader = new StringReader(t.ReadToEnd()))
{
string AampCheck = reader.ReadLine();
if (AampCheck != "!aamp")
throw new Exception($"Expected !aamp got {AampCheck} at line 0");
string VersionCheck = reader.ReadLine();
string num = GetProperty(VersionCheck);
if (num == "1")
{
}
}*/
}
public static void ParseList(StringReader reader)
{
}
public static string GetProperty(string line)
{
if (line.Contains(":"))
return line.Split(':')[1].Replace(string.Empty, "");
return line;
} }
#endregion #endregion

View File

@ -30,7 +30,6 @@
{ {
this.generateNormalsChk = new Toolbox.Library.Forms.STCheckBox(); this.generateNormalsChk = new Toolbox.Library.Forms.STCheckBox();
this.smoothNormalsChk = new Toolbox.Library.Forms.STCheckBox(); this.smoothNormalsChk = new Toolbox.Library.Forms.STCheckBox();
this.generateTansBitansChk = new Toolbox.Library.Forms.STCheckBox();
this.flipUVsChk = new Toolbox.Library.Forms.STCheckBox(); this.flipUVsChk = new Toolbox.Library.Forms.STCheckBox();
this.limtBoneWeightChk = new Toolbox.Library.Forms.STCheckBox(); this.limtBoneWeightChk = new Toolbox.Library.Forms.STCheckBox();
this.numericUpDown1 = new System.Windows.Forms.NumericUpDown(); this.numericUpDown1 = new System.Windows.Forms.NumericUpDown();
@ -62,13 +61,11 @@
this.contentContainer.Controls.Add(this.numericUpDown1); this.contentContainer.Controls.Add(this.numericUpDown1);
this.contentContainer.Controls.Add(this.limtBoneWeightChk); this.contentContainer.Controls.Add(this.limtBoneWeightChk);
this.contentContainer.Controls.Add(this.flipUVsChk); this.contentContainer.Controls.Add(this.flipUVsChk);
this.contentContainer.Controls.Add(this.generateTansBitansChk);
this.contentContainer.Controls.Add(this.smoothNormalsChk); this.contentContainer.Controls.Add(this.smoothNormalsChk);
this.contentContainer.Controls.Add(this.generateNormalsChk); this.contentContainer.Controls.Add(this.generateNormalsChk);
this.contentContainer.Size = new System.Drawing.Size(290, 336); this.contentContainer.Size = new System.Drawing.Size(290, 336);
this.contentContainer.Controls.SetChildIndex(this.generateNormalsChk, 0); this.contentContainer.Controls.SetChildIndex(this.generateNormalsChk, 0);
this.contentContainer.Controls.SetChildIndex(this.smoothNormalsChk, 0); this.contentContainer.Controls.SetChildIndex(this.smoothNormalsChk, 0);
this.contentContainer.Controls.SetChildIndex(this.generateTansBitansChk, 0);
this.contentContainer.Controls.SetChildIndex(this.flipUVsChk, 0); this.contentContainer.Controls.SetChildIndex(this.flipUVsChk, 0);
this.contentContainer.Controls.SetChildIndex(this.limtBoneWeightChk, 0); this.contentContainer.Controls.SetChildIndex(this.limtBoneWeightChk, 0);
this.contentContainer.Controls.SetChildIndex(this.numericUpDown1, 0); this.contentContainer.Controls.SetChildIndex(this.numericUpDown1, 0);
@ -106,26 +103,13 @@
this.smoothNormalsChk.Text = "Smooth Normals"; this.smoothNormalsChk.Text = "Smooth Normals";
this.smoothNormalsChk.UseVisualStyleBackColor = true; this.smoothNormalsChk.UseVisualStyleBackColor = true;
// //
// generateTansBitansChk
//
this.generateTansBitansChk.AutoSize = true;
this.generateTansBitansChk.Checked = true;
this.generateTansBitansChk.CheckState = System.Windows.Forms.CheckState.Checked;
this.generateTansBitansChk.ForeColor = System.Drawing.Color.White;
this.generateTansBitansChk.Location = new System.Drawing.Point(9, 134);
this.generateTansBitansChk.Name = "generateTansBitansChk";
this.generateTansBitansChk.Size = new System.Drawing.Size(173, 17);
this.generateTansBitansChk.TabIndex = 2;
this.generateTansBitansChk.Text = "Generate Tangents/Bitangents";
this.generateTansBitansChk.UseVisualStyleBackColor = true;
//
// flipUVsChk // flipUVsChk
// //
this.flipUVsChk.AutoSize = true; this.flipUVsChk.AutoSize = true;
this.flipUVsChk.Checked = true; this.flipUVsChk.Checked = true;
this.flipUVsChk.CheckState = System.Windows.Forms.CheckState.Checked; this.flipUVsChk.CheckState = System.Windows.Forms.CheckState.Checked;
this.flipUVsChk.ForeColor = System.Drawing.Color.White; this.flipUVsChk.ForeColor = System.Drawing.Color.White;
this.flipUVsChk.Location = new System.Drawing.Point(9, 157); this.flipUVsChk.Location = new System.Drawing.Point(9, 134);
this.flipUVsChk.Name = "flipUVsChk"; this.flipUVsChk.Name = "flipUVsChk";
this.flipUVsChk.Size = new System.Drawing.Size(65, 17); this.flipUVsChk.Size = new System.Drawing.Size(65, 17);
this.flipUVsChk.TabIndex = 3; this.flipUVsChk.TabIndex = 3;
@ -138,7 +122,7 @@
this.limtBoneWeightChk.Checked = true; this.limtBoneWeightChk.Checked = true;
this.limtBoneWeightChk.CheckState = System.Windows.Forms.CheckState.Checked; this.limtBoneWeightChk.CheckState = System.Windows.Forms.CheckState.Checked;
this.limtBoneWeightChk.ForeColor = System.Drawing.Color.White; this.limtBoneWeightChk.ForeColor = System.Drawing.Color.White;
this.limtBoneWeightChk.Location = new System.Drawing.Point(9, 180); this.limtBoneWeightChk.Location = new System.Drawing.Point(9, 157);
this.limtBoneWeightChk.Name = "limtBoneWeightChk"; this.limtBoneWeightChk.Name = "limtBoneWeightChk";
this.limtBoneWeightChk.Size = new System.Drawing.Size(113, 17); this.limtBoneWeightChk.Size = new System.Drawing.Size(113, 17);
this.limtBoneWeightChk.TabIndex = 5; this.limtBoneWeightChk.TabIndex = 5;
@ -152,7 +136,7 @@
this.numericUpDown1.BorderStyle = System.Windows.Forms.BorderStyle.None; this.numericUpDown1.BorderStyle = System.Windows.Forms.BorderStyle.None;
this.numericUpDown1.Enabled = false; this.numericUpDown1.Enabled = false;
this.numericUpDown1.ForeColor = System.Drawing.Color.White; this.numericUpDown1.ForeColor = System.Drawing.Color.White;
this.numericUpDown1.Location = new System.Drawing.Point(132, 179); this.numericUpDown1.Location = new System.Drawing.Point(132, 156);
this.numericUpDown1.Maximum = new decimal(new int[] { this.numericUpDown1.Maximum = new decimal(new int[] {
4, 4,
0, 0,
@ -171,7 +155,7 @@
// //
this.preTransformVerticesChk.AutoSize = true; this.preTransformVerticesChk.AutoSize = true;
this.preTransformVerticesChk.ForeColor = System.Drawing.Color.White; this.preTransformVerticesChk.ForeColor = System.Drawing.Color.White;
this.preTransformVerticesChk.Location = new System.Drawing.Point(9, 203); this.preTransformVerticesChk.Location = new System.Drawing.Point(9, 180);
this.preTransformVerticesChk.Name = "preTransformVerticesChk"; this.preTransformVerticesChk.Name = "preTransformVerticesChk";
this.preTransformVerticesChk.Size = new System.Drawing.Size(130, 17); this.preTransformVerticesChk.Size = new System.Drawing.Size(130, 17);
this.preTransformVerticesChk.TabIndex = 7; this.preTransformVerticesChk.TabIndex = 7;
@ -184,7 +168,7 @@
this.triangulateChk.Checked = true; this.triangulateChk.Checked = true;
this.triangulateChk.CheckState = System.Windows.Forms.CheckState.Checked; this.triangulateChk.CheckState = System.Windows.Forms.CheckState.Checked;
this.triangulateChk.ForeColor = System.Drawing.Color.White; this.triangulateChk.ForeColor = System.Drawing.Color.White;
this.triangulateChk.Location = new System.Drawing.Point(9, 226); this.triangulateChk.Location = new System.Drawing.Point(9, 203);
this.triangulateChk.Name = "triangulateChk"; this.triangulateChk.Name = "triangulateChk";
this.triangulateChk.Size = new System.Drawing.Size(79, 17); this.triangulateChk.Size = new System.Drawing.Size(79, 17);
this.triangulateChk.TabIndex = 8; this.triangulateChk.TabIndex = 8;
@ -197,7 +181,7 @@
this.joinDupedVertsSk.Checked = true; this.joinDupedVertsSk.Checked = true;
this.joinDupedVertsSk.CheckState = System.Windows.Forms.CheckState.Checked; this.joinDupedVertsSk.CheckState = System.Windows.Forms.CheckState.Checked;
this.joinDupedVertsSk.ForeColor = System.Drawing.Color.White; this.joinDupedVertsSk.ForeColor = System.Drawing.Color.White;
this.joinDupedVertsSk.Location = new System.Drawing.Point(9, 249); this.joinDupedVertsSk.Location = new System.Drawing.Point(9, 226);
this.joinDupedVertsSk.Name = "joinDupedVertsSk"; this.joinDupedVertsSk.Name = "joinDupedVertsSk";
this.joinDupedVertsSk.Size = new System.Drawing.Size(121, 17); this.joinDupedVertsSk.Size = new System.Drawing.Size(121, 17);
this.joinDupedVertsSk.TabIndex = 9; this.joinDupedVertsSk.TabIndex = 9;
@ -208,7 +192,7 @@
// //
this.leftHandedChk.AutoSize = true; this.leftHandedChk.AutoSize = true;
this.leftHandedChk.ForeColor = System.Drawing.Color.White; this.leftHandedChk.ForeColor = System.Drawing.Color.White;
this.leftHandedChk.Location = new System.Drawing.Point(9, 272); this.leftHandedChk.Location = new System.Drawing.Point(9, 249);
this.leftHandedChk.Name = "leftHandedChk"; this.leftHandedChk.Name = "leftHandedChk";
this.leftHandedChk.Size = new System.Drawing.Size(109, 17); this.leftHandedChk.Size = new System.Drawing.Size(109, 17);
this.leftHandedChk.TabIndex = 10; this.leftHandedChk.TabIndex = 10;
@ -309,7 +293,6 @@
private Toolbox.Library.Forms.STCheckBox generateNormalsChk; private Toolbox.Library.Forms.STCheckBox generateNormalsChk;
private Toolbox.Library.Forms.STCheckBox smoothNormalsChk; private Toolbox.Library.Forms.STCheckBox smoothNormalsChk;
private Toolbox.Library.Forms.STCheckBox generateTansBitansChk;
private Toolbox.Library.Forms.STCheckBox flipUVsChk; private Toolbox.Library.Forms.STCheckBox flipUVsChk;
private Toolbox.Library.Forms.STCheckBox limtBoneWeightChk; private Toolbox.Library.Forms.STCheckBox limtBoneWeightChk;
private System.Windows.Forms.NumericUpDown numericUpDown1; private System.Windows.Forms.NumericUpDown numericUpDown1;

View File

@ -39,8 +39,6 @@ namespace Toolbox.Library.Forms
Flags |= PostProcessSteps.GenerateNormals; Flags |= PostProcessSteps.GenerateNormals;
if (smoothNormalsChk.Checked) if (smoothNormalsChk.Checked)
Flags |= PostProcessSteps.GenerateSmoothNormals; Flags |= PostProcessSteps.GenerateSmoothNormals;
if (generateTansBitansChk.Checked)
Flags |= PostProcessSteps.CalculateTangentSpace;
if (flipUVsChk.Checked) if (flipUVsChk.Checked)
Flags |= PostProcessSteps.FlipUVs; Flags |= PostProcessSteps.FlipUVs;
if (limtBoneWeightChk.Checked) if (limtBoneWeightChk.Checked)