2019-06-02 20:08:10 +02:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2019-06-13 23:31:35 +02:00
|
|
|
|
using System.IO;
|
2019-06-02 20:08:10 +02:00
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using Switch_Toolbox;
|
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
using Switch_Toolbox.Library;
|
2019-06-13 23:31:35 +02:00
|
|
|
|
using Switch_Toolbox.Library.IO;
|
2019-06-02 20:08:10 +02:00
|
|
|
|
|
|
|
|
|
namespace FirstPlugin
|
|
|
|
|
{
|
|
|
|
|
public class GFBMDL : TreeNodeFile, IFileFormat
|
|
|
|
|
{
|
|
|
|
|
public FileType FileType { get; set; } = FileType.Model;
|
|
|
|
|
|
|
|
|
|
public bool CanSave { get; set; }
|
|
|
|
|
public string[] Description { get; set; } = new string[] { "Graphic Model" };
|
|
|
|
|
public string[] Extension { get; set; } = new string[] { "*.gfbmdl" };
|
|
|
|
|
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))
|
|
|
|
|
{
|
|
|
|
|
reader.ByteOrder = Syroot.BinaryData.ByteOrder.BigEndian;
|
|
|
|
|
|
|
|
|
|
bool IsMatch = reader.ReadUInt32() == 0x20000000;
|
|
|
|
|
reader.Position = 0;
|
|
|
|
|
|
|
|
|
|
return IsMatch;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Type[] Types
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
List<Type> types = new List<Type>();
|
|
|
|
|
return types.ToArray();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-06-13 23:31:35 +02:00
|
|
|
|
public Header header;
|
|
|
|
|
|
2019-06-02 20:08:10 +02:00
|
|
|
|
public void Load(System.IO.Stream stream)
|
|
|
|
|
{
|
2019-06-13 23:31:35 +02:00
|
|
|
|
header = new Header();
|
|
|
|
|
header.Read(new FileReader(stream));
|
2019-06-02 20:08:10 +02:00
|
|
|
|
}
|
|
|
|
|
public void Unload()
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
public byte[] Save()
|
|
|
|
|
{
|
2019-06-13 23:31:35 +02:00
|
|
|
|
var mem = new System.IO.MemoryStream();
|
|
|
|
|
header.Write(new FileWriter(mem));
|
|
|
|
|
return mem.ToArray();
|
2019-06-02 20:08:10 +02:00
|
|
|
|
}
|
2019-06-02 22:15:33 +02:00
|
|
|
|
|
2019-06-13 23:31:35 +02:00
|
|
|
|
public class Header
|
|
|
|
|
{
|
|
|
|
|
public uint Version { get; set; }
|
|
|
|
|
public float[] Boundings { get; set; }
|
|
|
|
|
public List<string> TextureMaps = new List<string>();
|
|
|
|
|
public List<string> Materials = new List<string>();
|
|
|
|
|
|
|
|
|
|
public void Read(FileReader reader)
|
|
|
|
|
{
|
|
|
|
|
reader.SetByteOrder(false);
|
|
|
|
|
|
|
|
|
|
Version = reader.ReadUInt32();
|
|
|
|
|
Boundings = reader.ReadSingles(9);
|
|
|
|
|
long TextureOffset = reader.ReadOffset(true, typeof(uint));
|
|
|
|
|
long MaterialOffset = reader.ReadOffset(true, typeof(uint));
|
|
|
|
|
long UnknownOffset = reader.ReadOffset(true, typeof(uint));
|
|
|
|
|
long Unknown2Offset = reader.ReadOffset(true, typeof(uint));
|
|
|
|
|
long ShaderOffset = reader.ReadOffset(true, typeof(uint));
|
|
|
|
|
long VisGroupOffset = reader.ReadOffset(true, typeof(uint));
|
|
|
|
|
long BoneDataOffset = reader.ReadOffset(true, typeof(uint));
|
2019-06-02 22:15:33 +02:00
|
|
|
|
|
2019-06-13 23:31:35 +02:00
|
|
|
|
if (TextureOffset != 0)
|
|
|
|
|
{
|
|
|
|
|
reader.Seek(TextureOffset, SeekOrigin.Begin);
|
|
|
|
|
uint Count = reader.ReadUInt32();
|
|
|
|
|
TextureMaps = reader.ReadNameOffsets(Count, true, typeof(uint), true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach (var tex in TextureMaps)
|
|
|
|
|
Console.WriteLine("TEXNAME " + tex);
|
|
|
|
|
|
|
|
|
|
if (MaterialOffset != 0)
|
|
|
|
|
{
|
|
|
|
|
reader.Seek(MaterialOffset, SeekOrigin.Begin);
|
|
|
|
|
uint Count = reader.ReadUInt32();
|
|
|
|
|
Materials = reader.ReadNameOffsets(Count, true, typeof(uint));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Write(FileWriter writer)
|
|
|
|
|
{
|
|
|
|
|
writer.Write(Version);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class Bone
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class Material
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
2019-06-02 20:08:10 +02:00
|
|
|
|
}
|
|
|
|
|
}
|