mirror of
https://github.com/KillzXGaming/Switch-Toolbox
synced 2024-11-26 22:40:27 +00:00
Save GMX files back
This commit is contained in:
parent
c73816048b
commit
4cef869688
7 changed files with 82 additions and 5 deletions
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -43,6 +43,8 @@ namespace FirstPlugin
|
||||||
|
|
||||||
public void Load(System.IO.Stream stream)
|
public void Load(System.IO.Stream stream)
|
||||||
{
|
{
|
||||||
|
CanSave = true;
|
||||||
|
|
||||||
GMXHeader = new Header();
|
GMXHeader = new Header();
|
||||||
GMXHeader.Read(new FileReader(stream));
|
GMXHeader.Read(new FileReader(stream));
|
||||||
for (int i = 0; i < GMXHeader.Meshes.Count; i++)
|
for (int i = 0; i < GMXHeader.Meshes.Count; i++)
|
||||||
|
@ -58,7 +60,9 @@ namespace FirstPlugin
|
||||||
}
|
}
|
||||||
public byte[] Save()
|
public byte[] Save()
|
||||||
{
|
{
|
||||||
return null;
|
var mem = new System.IO.MemoryStream();
|
||||||
|
GMXHeader.Write(new FileWriter(mem));
|
||||||
|
return mem.ToArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
public class Header
|
public class Header
|
||||||
|
@ -132,8 +136,28 @@ namespace FirstPlugin
|
||||||
|
|
||||||
public void Write(FileWriter writer)
|
public void Write(FileWriter writer)
|
||||||
{
|
{
|
||||||
|
PADX padding = new PADX();
|
||||||
|
|
||||||
writer.WriteSignature("GMX2");
|
writer.WriteSignature("GMX2");
|
||||||
writer.Write(HeaderSize);
|
writer.Write(HeaderSize);
|
||||||
|
for (int i = 0; i < Meshes.Count; i++)
|
||||||
|
{
|
||||||
|
//Write mesh header
|
||||||
|
padding.Write(writer, 16);
|
||||||
|
Meshes[i].Write(writer);
|
||||||
|
|
||||||
|
//Write Vertices
|
||||||
|
padding.Write(writer, 64);
|
||||||
|
Meshes[i].VertexGroup.Write(writer, Meshes[i]);
|
||||||
|
|
||||||
|
//Write Faces
|
||||||
|
padding.Write(writer, 16);
|
||||||
|
Meshes[i].IndexGroup.Write(writer);
|
||||||
|
|
||||||
|
//Write VMAPS
|
||||||
|
padding.Write(writer, 16);
|
||||||
|
Meshes[i].VMapGroup.Write(writer);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class VERT
|
public class VERT
|
||||||
|
@ -174,10 +198,28 @@ namespace FirstPlugin
|
||||||
throw new Exception($"Unsupported Vertex Size {mesh.VertexSize}");
|
throw new Exception($"Unsupported Vertex Size {mesh.VertexSize}");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Write(FileWriter writer)
|
public void Write(FileWriter writer, MESH mesh)
|
||||||
{
|
{
|
||||||
writer.WriteSignature("VERT");
|
writer.WriteSignature("VERT");
|
||||||
|
writer.Write(Vertices.Count * mesh.VertexSize);
|
||||||
|
for (int v = 0; v < mesh.VertexCount; v++)
|
||||||
|
{
|
||||||
|
if (mesh.VertexSize == 32)
|
||||||
|
{
|
||||||
|
writer.Write(Vertices[v].pos);
|
||||||
|
writer.Write(Vertices[v].nrm);
|
||||||
|
writer.Write(Vertices[v].uv0);
|
||||||
|
}
|
||||||
|
else if (mesh.VertexSize == 36)
|
||||||
|
{
|
||||||
|
writer.Write(0);
|
||||||
|
writer.Write(Vertices[v].pos);
|
||||||
|
writer.Write(Vertices[v].nrm);
|
||||||
|
writer.Write(Vertices[v].uv0);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
throw new Exception($"Unsupported Vertex Size {mesh.VertexSize}");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -283,10 +325,26 @@ namespace FirstPlugin
|
||||||
|
|
||||||
public void Write(FileWriter writer, uint Alignment)
|
public void Write(FileWriter writer, uint Alignment)
|
||||||
{
|
{
|
||||||
|
long pos = writer.Position;
|
||||||
writer.WriteSignature("PADX");
|
writer.WriteSignature("PADX");
|
||||||
writer.Write(Alignment - 8);
|
writer.Write(uint.MaxValue);
|
||||||
for (int i = 0; i < Alignment; i++)
|
Align(writer, (int)Alignment);
|
||||||
|
|
||||||
|
long endPos = writer.Position;
|
||||||
|
writer.Seek(pos + 4, System.IO.SeekOrigin.Begin);
|
||||||
|
writer.Write((uint)(endPos - pos));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void Align(FileWriter writer, int alignment)
|
||||||
|
{
|
||||||
|
var startPos = writer.Position;
|
||||||
|
long position = writer.Seek((-writer.Position % alignment + alignment) % alignment, System.IO.SeekOrigin.Current);
|
||||||
|
|
||||||
|
writer.Seek(startPos, System.IO.SeekOrigin.Begin);
|
||||||
|
while (writer.Position != position)
|
||||||
|
{
|
||||||
writer.Write(byte.MaxValue);
|
writer.Write(byte.MaxValue);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Binary file not shown.
Binary file not shown.
|
@ -81,5 +81,24 @@ namespace Switch_Toolbox.Library.IO
|
||||||
Write((uint)pos - (uint)RelativeOffsetPosition);
|
Write((uint)pos - (uint)RelativeOffsetPosition);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void Write(OpenTK.Vector2 v)
|
||||||
|
{
|
||||||
|
Write(v.X);
|
||||||
|
Write(v.Y);
|
||||||
|
}
|
||||||
|
public void Write(OpenTK.Vector3 v)
|
||||||
|
{
|
||||||
|
Write(v.X);
|
||||||
|
Write(v.Y);
|
||||||
|
Write(v.Z);
|
||||||
|
}
|
||||||
|
public void Write(OpenTK.Vector4 v)
|
||||||
|
{
|
||||||
|
Write(v.X);
|
||||||
|
Write(v.Y);
|
||||||
|
Write(v.Z);
|
||||||
|
Write(v.W);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue