Attribute fixes for bfres and gmx

This commit is contained in:
KillzXGaming 2019-07-15 15:41:02 -04:00
parent b50d8925e4
commit ea26ebc82f
14 changed files with 97 additions and 34 deletions

Binary file not shown.

View file

@ -10,7 +10,7 @@ using Switch_Toolbox.Library.IO;
namespace FirstPlugin
{
public class RARC : IArchiveFile, IFileFormat, IDirectoryContainer
public class RARC : IArchiveFile, IFileFormat, IDirectoryContainer, IContextMenuNode
{
public FileType FileType { get; set; } = FileType.Archive;
@ -60,8 +60,29 @@ namespace FirstPlugin
private uint HeaderSize = 32;
private uint Unknown = 256;
public ToolStripItem[] GetContextMenuItems()
{
List<ToolStripItem> Items = new List<ToolStripItem>();
Items.Add(new ToolStripMenuItem("Save", null, SaveAction, Keys.Control | Keys.S));
return Items.ToArray();
}
private void SaveAction(object sender, EventArgs args)
{
SaveFileDialog sfd = new SaveFileDialog();
sfd.Filter = Utils.GetAllFilters(this);
sfd.FileName = FileName;
if (sfd.ShowDialog() == DialogResult.OK)
{
STFileSaver.SaveFileFormat(this, sfd.FileName);
}
}
public void Load(System.IO.Stream stream)
{
CanSave = true;
using (var reader = new FileReader(stream))
{
reader.ByteOrder = Syroot.BinaryData.ByteOrder.BigEndian;
@ -143,7 +164,7 @@ namespace FirstPlugin
public int GetTotalCount()
{
int count = 0;
foreach (var dir in Directories)
foreach (var dir in Nodes)
GetTotalCount(dir, count);
return count;
}
@ -151,7 +172,7 @@ namespace FirstPlugin
public int GetFileCount()
{
int count = 0;
foreach (var dir in Directories)
foreach (var dir in Nodes)
GetFileCount(dir, count);
return count;
}
@ -159,7 +180,7 @@ namespace FirstPlugin
public int GetDirectoryCount()
{
int count = 0;
foreach (var dir in Directories)
foreach (var dir in Nodes)
GetDirectoryCount(dir, count);
return count;
}
@ -168,8 +189,11 @@ namespace FirstPlugin
{
count++;
foreach (var c in ((DirectoryEntry)node).nodes)
return GetDirectoryCount(c, count);
if (node is DirectoryEntry)
{
foreach (var c in ((DirectoryEntry)node).nodes)
return GetTotalCount(c, count);
}
return count;
}
@ -180,8 +204,11 @@ namespace FirstPlugin
if (node is FileEntry)
count++;
foreach (var c in ((DirectoryEntry)node).nodes)
return GetDirectoryCount(c, count);
if (node is DirectoryEntry)
{
foreach (var c in ((DirectoryEntry)node).nodes)
return GetFileCount(c, count);
}
return count;
}
@ -189,10 +216,12 @@ namespace FirstPlugin
private int GetDirectoryCount(INode node, int count)
{
if (node is DirectoryEntry)
{
count++;
foreach (var c in ((DirectoryEntry)node).nodes)
return GetDirectoryCount(c, count);
foreach (var c in ((DirectoryEntry)node).nodes)
return GetDirectoryCount(c, count);
}
return count;
}
@ -206,6 +235,7 @@ namespace FirstPlugin
writer.Write(uint.MaxValue); //FileSize
writer.Write(HeaderSize);
writer.Write(uint.MaxValue); //DataOffset
writer.Write(uint.MaxValue); //File Size
writer.Write(uint.MaxValue); //End of file
writer.Seek(8); //padding
@ -223,15 +253,22 @@ namespace FirstPlugin
writer.Write(0); //padding
//Write directory Offset
WriteOffset(writer, 0x4, InfoPos);
WriteOffset(writer, 4, InfoPos);
for (int dir = 0; dir < Directories.Length; dir++)
{
Directories[dir].Write(writer);
}
writer.Seek(16); //Add padding after directories
//Write the node offset
WriteOffset(writer, 12, InfoPos);
for (int dir = 0; dir < Directories.Length; dir++)
{
for (int n = 0; n < Directories[dir].NodeCount; n++)
{
}
}
//Write file size
@ -251,7 +288,7 @@ namespace FirstPlugin
long Position = writer.Position;
using (writer.TemporarySeek(RelativePosition + Target, System.IO.SeekOrigin.Begin))
{
writer.Write((uint)Position);
writer.Write((uint)(Position - RelativePosition));
}
}

View file

@ -166,16 +166,15 @@ namespace FirstPlugin
int vertexID = 0;
int packetID = 0;
foreach (var att in curShape.Descriptor.Attributes)
shpWrapper.Nodes.Add($"Attribute {att.Key} {att.Value.Item1}");
foreach (SuperBMDLib.Geometry.Packet pack in curShape.Packets)
{
var packetNode = new TreeNode($"Packet {packetID++}");
shpWrapper.Nodes.Add(packetNode);
int primID = 0;
foreach (SuperBMDLib.Geometry.Primitive prim in pack.Primitives)
{
var primitiveNode = new TreeNode($"Primitive {prim.PrimitiveType}");
packetNode.Nodes.Add(primitiveNode);
List<SuperBMDLib.Geometry.Vertex> triVertices = J3DUtility.PrimitiveToTriangles(prim);
for (int triIndex = 0; triIndex < triVertices.Count; triIndex += 3)
{
@ -184,12 +183,6 @@ namespace FirstPlugin
for (int triVertIndex = 0; triVertIndex < 3; triVertIndex++)
{
SuperBMDLib.Geometry.Vertex vert = triVertices[triIndex + triVertIndex];
if (triVertIndex == 0)
{
foreach (var att in curShape.Descriptor.Attributes)
primitiveNode.Nodes.Add($"Attribute {att.Key} {att.Value.Item1}");
}
Vertex vertex = new Vertex();
vertex.pos = VertexAttributes.Positions[(int)vert.GetAttributeIndex(GXVertexAttribute.Position)];
@ -247,7 +240,11 @@ namespace FirstPlugin
vertexID++;
}
}
primID++;
}
packetID++;
}
}

View file

@ -22,7 +22,7 @@ namespace FirstPlugin
public FileType FileType { get; set; } = FileType.Collision;
public bool CanSave { get; set; }
public string[] Description { get; set; } = new string[] { "KCL" };
public string[] Description { get; set; } = new string[] { "WiiU/Switch Collision" };
public string[] Extension { get; set; } = new string[] { "*.kcl" };
public string FileName { get; set; }
public string FilePath { get; set; }

View file

@ -323,14 +323,23 @@ namespace FirstPlugin
for (int v = 0; v < mesh.VertexCount; v++)
{
Vertex vert = new Vertex();
uint Unknown = reader.ReadUInt32(); //Bone index?
vert.pos = reader.ReadVec3();
vert.nrm = reader.ReadVec3();
vert.uv0 = reader.ReadVec2();
if (mesh.Unknown1 != 0)
{
uint Unknown = reader.ReadUInt32(); //Bone index?
vert.pos = reader.ReadVec3();
vert.nrm = reader.ReadVec3();
vert.uv0 = reader.ReadVec2();
Unknowns.Add(Unknown);
}
else
{
vert.pos = reader.ReadVec3();
vert.nrm = reader.ReadVec3();
vert.col = ColorUtility.ToVector4(reader.ReadBytes(4));
vert.uv0 = reader.ReadVec2();
}
Vertices.Add(vert);
Unknowns.Add(Unknown);
}
}
else if (mesh.VertexSize == 40)
@ -338,11 +347,29 @@ namespace FirstPlugin
for (int v = 0; v < mesh.VertexCount; v++)
{
Vertex vert = new Vertex();
uint Unknown = reader.ReadUInt32(); //Bone index?
if (mesh.Unknown1 != 0)
{
uint Unknown = reader.ReadUInt32(); //Bone index?
vert.pos = reader.ReadVec3();
vert.nrm = reader.ReadVec3();
vert.col = ColorUtility.ToVector4(reader.ReadBytes(4));
vert.uv0 = reader.ReadVec2();
}
else
throw new Exception($"Unsupported Vertex Size {mesh.VertexSize}");
Vertices.Add(vert);
}
}
else if (mesh.VertexSize == 44)
{
for (int v = 0; v < mesh.VertexCount; v++)
{
Vertex vert = new Vertex();
vert.pos = reader.ReadVec3();
vert.nrm = reader.ReadVec3();
var Color0 = reader.ReadBytes(4);
vert.col = ColorUtility.ToVector4(Color0);
vert.col = ColorUtility.ToVector4(reader.ReadBytes(4));
vert.uv0 = reader.ReadVec2();
vert.uv1 = reader.ReadVec2();
Vertices.Add(vert);

View file

@ -239,6 +239,8 @@ namespace Switch_Toolbox.Library.IO
return STLibraryCompression.GZIP.Compress(data);
case CompressionType.Zlib:
return STLibraryCompression.ZLIB.Compress(data, 2);
case CompressionType.None:
return data;
default:
MessageBox.Show($"Compression Type {CompressionType} not supported!!");
break;

Binary file not shown.

Binary file not shown.