Support reading WTB textures.
This commit is contained in:
parent
4b330c475b
commit
ca1b62e45e
@ -12,6 +12,7 @@ using FirstPlugin.Forms;
|
||||
using Syroot.Maths;
|
||||
using SharpYaml.Serialization;
|
||||
using FirstPlugin;
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace LayoutBXLYT
|
||||
{
|
||||
@ -859,15 +860,18 @@ namespace LayoutBXLYT
|
||||
|
||||
public ushort MaterialIndex { get; set; }
|
||||
|
||||
public Material GetMaterial()
|
||||
[TypeConverter(typeof(ExpandableObjectConverter))]
|
||||
public Material Material
|
||||
{
|
||||
return ParentLayout.MaterialList.Materials[MaterialIndex];
|
||||
get
|
||||
{
|
||||
return ParentLayout.MaterialList.Materials[MaterialIndex];
|
||||
}
|
||||
}
|
||||
|
||||
public string GetTexture(int index)
|
||||
{
|
||||
var mat = GetMaterial();
|
||||
return ParentLayout.TextureList.Textures[mat.TextureMaps[index].ID];
|
||||
return ParentLayout.TextureList.Textures[Material.TextureMaps[index].ID];
|
||||
}
|
||||
|
||||
private BFLYT.Header ParentLayout;
|
||||
@ -924,6 +928,7 @@ namespace LayoutBXLYT
|
||||
private byte _flags1;
|
||||
private byte _flags2;
|
||||
|
||||
[DisplayName("Is Visable"), CategoryAttribute("Flags")]
|
||||
public bool Visible
|
||||
{
|
||||
get { return (_flags1 & 0x1) == 0x1; }
|
||||
@ -935,6 +940,7 @@ namespace LayoutBXLYT
|
||||
}
|
||||
}
|
||||
|
||||
[DisplayName("Influence Alpha"), CategoryAttribute("Alpha")]
|
||||
public bool InfluenceAlpha
|
||||
{
|
||||
get { return (_flags1 & 0x2) == 0x2; }
|
||||
@ -947,6 +953,10 @@ namespace LayoutBXLYT
|
||||
}
|
||||
}
|
||||
|
||||
[DisplayName("Alpha"), CategoryAttribute("Alpha")]
|
||||
public byte Alpha { get; set; }
|
||||
|
||||
[DisplayName("Origin X"), CategoryAttribute("Origin")]
|
||||
public OriginX originX
|
||||
{
|
||||
get { return (OriginX)((_flags2 & 0xC0) >> 6); }
|
||||
@ -957,6 +967,7 @@ namespace LayoutBXLYT
|
||||
}
|
||||
}
|
||||
|
||||
[DisplayName("Origin Y"), CategoryAttribute("Origin")]
|
||||
public OriginY originY
|
||||
{
|
||||
get { return (OriginY)((_flags2 & 0x30) >> 4); }
|
||||
@ -967,6 +978,7 @@ namespace LayoutBXLYT
|
||||
}
|
||||
}
|
||||
|
||||
[Browsable(false)]
|
||||
public OriginX ParentOriginX
|
||||
{
|
||||
get { return (OriginX)((_flags2 & 0xC) >> 2); }
|
||||
@ -977,6 +989,7 @@ namespace LayoutBXLYT
|
||||
}
|
||||
}
|
||||
|
||||
[Browsable(false)]
|
||||
public OriginY ParentOriginY
|
||||
{
|
||||
get { return (OriginY)((_flags2 & 0x3)); }
|
||||
@ -987,9 +1000,10 @@ namespace LayoutBXLYT
|
||||
}
|
||||
}
|
||||
|
||||
public byte Alpha { get; set; }
|
||||
[DisplayName("Parts Flag"), CategoryAttribute("Flags")]
|
||||
public byte PaneMagFlags { get; set; }
|
||||
|
||||
[DisplayName("User Data"), CategoryAttribute("User Data")]
|
||||
public string UserDataInfo { get; set; }
|
||||
|
||||
public PAN1() : base()
|
||||
@ -1027,6 +1041,7 @@ namespace LayoutBXLYT
|
||||
writer.Write(Height);
|
||||
}
|
||||
|
||||
[Browsable(false)]
|
||||
public bool ParentVisibility
|
||||
{
|
||||
get
|
||||
@ -1078,13 +1093,20 @@ namespace LayoutBXLYT
|
||||
|
||||
public class Material
|
||||
{
|
||||
[DisplayName("Name"), CategoryAttribute("General")]
|
||||
public string Name { get; set; }
|
||||
|
||||
[DisplayName("Fore Color"), CategoryAttribute("Color")]
|
||||
public STColor8 ForeColor { get; set; }
|
||||
|
||||
[DisplayName("Back Color"), CategoryAttribute("Color")]
|
||||
public STColor8 BackColor { get; set; }
|
||||
|
||||
public List<TextureRef> TextureMaps { get; set; }
|
||||
public List<TextureTransform> TextureTransforms { get; set; }
|
||||
[DisplayName("Texture Maps"), CategoryAttribute("Texture")]
|
||||
public TextureRef[] TextureMaps { get; set; }
|
||||
|
||||
[DisplayName("Texture Transforms"), CategoryAttribute("Texture")]
|
||||
public TextureTransform[] TextureTransforms { get; set; }
|
||||
|
||||
private uint flags;
|
||||
private int unknown;
|
||||
@ -1100,17 +1122,14 @@ namespace LayoutBXLYT
|
||||
|
||||
public Material()
|
||||
{
|
||||
TextureMaps = new List<TextureRef>();
|
||||
TextureTransforms = new List<TextureTransform>();
|
||||
TextureMaps = new TextureRef[0];
|
||||
TextureTransforms = new TextureTransform[0];
|
||||
}
|
||||
|
||||
public Material(FileReader reader, Header header) : base()
|
||||
{
|
||||
ParentLayout = header;
|
||||
|
||||
TextureMaps = new List<TextureRef>();
|
||||
TextureTransforms = new List<TextureTransform>();
|
||||
|
||||
Name = reader.ReadString(0x1C).Replace("\0", string.Empty);
|
||||
if (header.VersionMajor >= 8)
|
||||
{
|
||||
@ -1126,15 +1145,16 @@ namespace LayoutBXLYT
|
||||
flags = reader.ReadUInt32();
|
||||
}
|
||||
|
||||
Console.WriteLine($"VersionMajor " + header.VersionMajor);
|
||||
|
||||
uint texCount = Convert.ToUInt32(flags & 3);
|
||||
uint mtxCount = Convert.ToUInt32(flags >> 2) & 3;
|
||||
for (int i = 0; i < texCount; i++)
|
||||
TextureMaps.Add(new TextureRef(reader));
|
||||
|
||||
TextureMaps = new TextureRef[texCount];
|
||||
for (int i = 0; i < texCount; i++)
|
||||
TextureMaps[i] = new TextureRef(reader, header);
|
||||
|
||||
TextureTransforms = new TextureTransform[mtxCount];
|
||||
for (int i = 0; i < mtxCount; i++)
|
||||
TextureTransforms.Add(new TextureTransform(reader));
|
||||
TextureTransforms[i] = new TextureTransform(reader);
|
||||
}
|
||||
|
||||
public void Write(FileWriter writer, Header header)
|
||||
@ -1154,10 +1174,10 @@ namespace LayoutBXLYT
|
||||
writer.Write(flags);
|
||||
}
|
||||
|
||||
for (int i = 0; i < TextureMaps.Count; i++)
|
||||
for (int i = 0; i < TextureMaps.Length; i++)
|
||||
TextureMaps[i].Write(writer);
|
||||
|
||||
for (int i = 0; i < TextureTransforms.Count; i++)
|
||||
for (int i = 0; i < TextureTransforms.Length; i++)
|
||||
TextureTransforms[i].Write(writer);
|
||||
}
|
||||
}
|
||||
@ -1187,6 +1207,7 @@ namespace LayoutBXLYT
|
||||
|
||||
public class TextureRef
|
||||
{
|
||||
public string Name { get; set; }
|
||||
public short ID;
|
||||
byte flag1;
|
||||
byte flag2;
|
||||
@ -1213,10 +1234,13 @@ namespace LayoutBXLYT
|
||||
|
||||
public TextureRef() {}
|
||||
|
||||
public TextureRef(FileReader reader) {
|
||||
public TextureRef(FileReader reader, BFLYT.Header header) {
|
||||
ID = reader.ReadInt16();
|
||||
flag1 = reader.ReadByte();
|
||||
flag2 = reader.ReadByte();
|
||||
|
||||
if (header.Textures.Count > 0 && ID != -1)
|
||||
Name = header.Textures[ID];
|
||||
}
|
||||
|
||||
public void Write(FileWriter writer)
|
||||
@ -1331,11 +1355,19 @@ namespace LayoutBXLYT
|
||||
{
|
||||
public bool DrawFromCenter { get; set; }
|
||||
|
||||
[DisplayName("Canvas Width"), CategoryAttribute("Layout")]
|
||||
public float Width { get; set; }
|
||||
|
||||
[DisplayName("Canvas Height"), CategoryAttribute("Layout")]
|
||||
public float Height { get; set; }
|
||||
|
||||
[DisplayName("Max Parts Width"), CategoryAttribute("Layout")]
|
||||
public float MaxPartsWidth { get; set; }
|
||||
|
||||
[DisplayName("Max Parts Height"), CategoryAttribute("Layout")]
|
||||
public float MaxPartsHeight { get; set; }
|
||||
|
||||
[DisplayName("Layout Name"), CategoryAttribute("Layout")]
|
||||
public string Name { get; set; }
|
||||
|
||||
public LYT1()
|
||||
|
@ -12,367 +12,7 @@ namespace LayoutBXLYT
|
||||
{
|
||||
public static string ToXml(BFLYT.Header header)
|
||||
{
|
||||
XmlRoot root = new XmlRoot();
|
||||
root.head = new Head();
|
||||
root.body = new Body();
|
||||
root.body.lyt = new Layout();
|
||||
|
||||
var generator = new Generator();
|
||||
root.head.generator = generator;
|
||||
generator.name = "ST";
|
||||
generator.version = "1.0"
|
||||
;
|
||||
var create = new Create();
|
||||
root.head.create = create;
|
||||
create.date = DateTime.Now.ToString("yyyy-MM-ddThh:mm:ss");
|
||||
|
||||
var layout = new Layout();
|
||||
root.body.lyt = layout;
|
||||
|
||||
List<Pane> panes = new List<Pane>();
|
||||
layout.paneSet = panes;
|
||||
|
||||
layout.paneHierarchy.paneTree = new List<PaneTree>();
|
||||
var paneTreeRoot = new PaneTree() { name = header.RootPane.Name };
|
||||
LoadPaneTree(header.RootPane, paneTreeRoot);
|
||||
layout.paneHierarchy.paneTree.Add(paneTreeRoot);
|
||||
|
||||
var screenSettings = new ScreenSettings();
|
||||
screenSettings.layoutSize.x = header.LayoutInfo.Width.ToString();
|
||||
screenSettings.layoutSize.y = header.LayoutInfo.Height.ToString();
|
||||
if (header.LayoutInfo.DrawFromCenter)
|
||||
screenSettings.origin = "Normal";
|
||||
else
|
||||
screenSettings.origin = "Classic";
|
||||
|
||||
screenSettings.backGround.color.r = 169;
|
||||
screenSettings.backGround.color.g = 169;
|
||||
screenSettings.backGround.color.b = 169;
|
||||
screenSettings.backGround.color.a = 255;
|
||||
|
||||
screenSettings.grid = new Grid();
|
||||
screenSettings.grid.color.r = 128;
|
||||
screenSettings.grid.color.g = 128;
|
||||
screenSettings.grid.color.b = 128;
|
||||
screenSettings.grid.color.a = 128;
|
||||
|
||||
layout.screenSetting = screenSettings;
|
||||
|
||||
layout.metrics.totalPaneCount = header.TotalPaneCount();
|
||||
|
||||
int i = 0;
|
||||
foreach (var pane in header.GetPanes())
|
||||
{
|
||||
if (i > 0) //Skip root
|
||||
{
|
||||
var basePane = new Pane();
|
||||
basePane.name = pane.Name;
|
||||
if (pane is BFLYT.PIC1)
|
||||
basePane.kind = "Picture";
|
||||
else if (pane is BFLYT.TXT1)
|
||||
basePane.kind = "TextBox";
|
||||
else if (pane is BFLYT.WND1)
|
||||
basePane.kind = "Window";
|
||||
else if (pane is BFLYT.PRT1)
|
||||
basePane.kind = "Parts";
|
||||
else
|
||||
basePane.kind = "Null";
|
||||
|
||||
basePane.translate.x = pane.Translate.X.ToString();
|
||||
basePane.translate.y = pane.Translate.Y.ToString();
|
||||
basePane.translate.z = pane.Translate.Z.ToString();
|
||||
basePane.rotate.x = pane.Rotate.X.ToString();
|
||||
basePane.rotate.y = pane.Rotate.Y.ToString();
|
||||
basePane.rotate.z = pane.Rotate.Z.ToString();
|
||||
basePane.scale.x = pane.Scale.X.ToString();
|
||||
basePane.scale.y = pane.Scale.Y.ToString();
|
||||
basePane.size.x = pane.Width.ToString();
|
||||
basePane.size.y = pane.Height.ToString();
|
||||
basePane.influencedAlpha = pane.InfluenceAlpha;
|
||||
basePane.basePositionType.x = $"{pane.originX.ToString()}";
|
||||
basePane.basePositionType.y = $"{pane.originY.ToString()}";
|
||||
basePane.parentRelativePositionType.x = $"{pane.ParentOriginX}";
|
||||
basePane.parentRelativePositionType.y = $"{pane.ParentOriginY}";
|
||||
|
||||
panes.Add(basePane);
|
||||
}
|
||||
|
||||
i++;
|
||||
}
|
||||
|
||||
|
||||
XmlWriterSettings settings = new XmlWriterSettings
|
||||
{
|
||||
Encoding = Encoding.UTF8,
|
||||
Indent = true,
|
||||
IndentChars = " ",
|
||||
};
|
||||
|
||||
|
||||
XmlSerializerNamespaces ns = new XmlSerializerNamespaces();
|
||||
ns.Add("", "");
|
||||
|
||||
XmlDocument doc = new XmlDocument();
|
||||
XmlDeclaration xmldecl = doc.CreateXmlDeclaration("1.0", null, null);
|
||||
xmldecl.Encoding = "UTF-8";
|
||||
xmldecl.Standalone = "yes";
|
||||
|
||||
var stringWriter = new StringWriter();
|
||||
XmlSerializer serializer = new XmlSerializer(typeof(XmlRoot));
|
||||
XmlWriter output = XmlWriter.Create(stringWriter, settings);
|
||||
serializer.Serialize(output, root, ns);
|
||||
return stringWriter.ToString();
|
||||
}
|
||||
|
||||
private static void LoadPaneTree(BasePane parentPane, PaneTree paneEntry)
|
||||
{
|
||||
if (parentPane.Childern != null && parentPane.Childern.Count > 0)
|
||||
paneEntry.paneTree = new List<PaneTree>();
|
||||
foreach (var child in parentPane.Childern)
|
||||
{
|
||||
var paneTreeChild = new PaneTree() { name = child.Name };
|
||||
paneEntry.paneTree.Add(paneTreeChild);
|
||||
LoadPaneTree(child, paneTreeChild);
|
||||
}
|
||||
}
|
||||
|
||||
[XmlRootAttribute("nw4f_layout")]
|
||||
public class XmlRoot
|
||||
{
|
||||
[XmlAttribute]
|
||||
public string version = "1.5.16";
|
||||
|
||||
public Head head = new Head();
|
||||
public Body body = new Body();
|
||||
}
|
||||
|
||||
public class Head
|
||||
{
|
||||
public Create create = new Create();
|
||||
public Title title = new Title();
|
||||
public Comment comment = new Comment();
|
||||
public Generator generator = new Generator();
|
||||
}
|
||||
|
||||
public class Comment
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public class Title
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public class Create
|
||||
{
|
||||
[XmlAttribute]
|
||||
public string user = "";
|
||||
|
||||
[XmlAttribute]
|
||||
public string host = "";
|
||||
|
||||
[XmlAttribute]
|
||||
public string date = "";
|
||||
|
||||
[XmlAttribute]
|
||||
public string source = "";
|
||||
}
|
||||
|
||||
public class Generator
|
||||
{
|
||||
[XmlAttribute]
|
||||
public string name = "";
|
||||
|
||||
[XmlAttribute]
|
||||
public string version = "";
|
||||
}
|
||||
|
||||
public class Body {
|
||||
public Layout lyt = new Layout();
|
||||
}
|
||||
|
||||
public class Layout {
|
||||
[XmlArrayItem("pane")]
|
||||
public List<Pane> paneSet = new List<Pane>();
|
||||
public PaneHiearchy paneHierarchy = new PaneHiearchy();
|
||||
public Groups groupSet = new Groups();
|
||||
public ScreenSettings screenSetting = new ScreenSettings();
|
||||
public FontFile fontFile;
|
||||
public Metrics metrics = new Metrics();
|
||||
public UserData userData = new UserData();
|
||||
}
|
||||
|
||||
public class FontFile
|
||||
{
|
||||
[XmlAttribute]
|
||||
public string path = "";
|
||||
|
||||
[XmlAttribute]
|
||||
public string name = "";
|
||||
}
|
||||
|
||||
public class Pane
|
||||
{
|
||||
[XmlAttribute]
|
||||
public string kind = "";
|
||||
|
||||
[XmlAttribute]
|
||||
public string name = "";
|
||||
|
||||
[XmlAttribute]
|
||||
public bool influencedAlpha;
|
||||
|
||||
public Comment comment = new Comment();
|
||||
public Vector2 basePositionType = new Vector2();
|
||||
public Vector2 parentRelativePositionType = new Vector2();
|
||||
public Vector3 translate = new Vector3();
|
||||
public Vector3 rotate = new Vector3();
|
||||
public Vector2 scale = new Vector2();
|
||||
public Vector2 size = new Vector2();
|
||||
public UserDataPane userData = new UserDataPane();
|
||||
}
|
||||
|
||||
public class UserDataPane
|
||||
{
|
||||
[XmlElement("string")]
|
||||
public XmlString UserString = new XmlString();
|
||||
}
|
||||
|
||||
public class XmlString
|
||||
{
|
||||
[XmlAttribute]
|
||||
public string name = "";
|
||||
}
|
||||
|
||||
public class TextboxPane : Pane
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public class PaneHiearchy
|
||||
{
|
||||
public List<PaneTree> paneTree = new List<PaneTree>();
|
||||
}
|
||||
|
||||
public class PaneTree
|
||||
{
|
||||
[XmlAttribute]
|
||||
public string name = "";
|
||||
|
||||
[XmlArrayItem("paneTree")]
|
||||
public List<PaneTree> paneTree;
|
||||
}
|
||||
|
||||
public class Groups
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public class ScreenSettings
|
||||
{
|
||||
[XmlAttribute]
|
||||
public string origin = "Normal";
|
||||
|
||||
public Vector2 layoutSize = new Vector2();
|
||||
public Background backGround = new Background();
|
||||
public Grid grid = new Grid();
|
||||
}
|
||||
|
||||
public class Background
|
||||
{
|
||||
public ColorRGBA color = new ColorRGBA();
|
||||
}
|
||||
|
||||
public class Grid
|
||||
{
|
||||
[XmlAttribute]
|
||||
public float thickLineInterval = 40;
|
||||
|
||||
[XmlAttribute]
|
||||
public float thinDivisionNum = 4;
|
||||
|
||||
[XmlAttribute]
|
||||
public bool visible = true;
|
||||
|
||||
[XmlAttribute]
|
||||
public string moveMethod = "None";
|
||||
|
||||
public ColorRGBA color = new ColorRGBA();
|
||||
}
|
||||
|
||||
public class Metrics
|
||||
{
|
||||
public int totalPaneCount = 0;
|
||||
public int totalPixelCount = 0;
|
||||
}
|
||||
|
||||
public class UserData
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public class Vector2
|
||||
{
|
||||
[XmlAttribute]
|
||||
public string x = "";
|
||||
|
||||
[XmlAttribute]
|
||||
public string y = "";
|
||||
}
|
||||
|
||||
public class Vector3
|
||||
{
|
||||
[XmlAttribute]
|
||||
public string x = "";
|
||||
|
||||
[XmlAttribute]
|
||||
public string y = "";
|
||||
|
||||
[XmlAttribute]
|
||||
public string z = "";
|
||||
}
|
||||
|
||||
public class Vector4
|
||||
{
|
||||
[XmlAttribute]
|
||||
public string x = "";
|
||||
|
||||
[XmlAttribute]
|
||||
public string y = "";
|
||||
|
||||
[XmlAttribute]
|
||||
public string z = "";
|
||||
|
||||
[XmlAttribute]
|
||||
public string w = "";
|
||||
}
|
||||
|
||||
public class ColorRGB
|
||||
{
|
||||
[XmlAttribute]
|
||||
public int r = 0;
|
||||
|
||||
[XmlAttribute]
|
||||
public int g = 0;
|
||||
|
||||
[XmlAttribute]
|
||||
public int b = 0;
|
||||
}
|
||||
|
||||
public class ColorRGBA
|
||||
{
|
||||
[XmlAttribute]
|
||||
public int r = 0;
|
||||
|
||||
[XmlAttribute]
|
||||
public int g = 0;
|
||||
|
||||
[XmlAttribute]
|
||||
public int b = 0;
|
||||
|
||||
[XmlAttribute]
|
||||
public int a = 0;
|
||||
return "";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -7,30 +7,52 @@ using Syroot.Maths;
|
||||
using Toolbox.Library.IO;
|
||||
using Toolbox.Library;
|
||||
using WeifenLuo.WinFormsUI.Docking;
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace LayoutBXLYT
|
||||
{
|
||||
public class BasePane : SectionCommon
|
||||
{
|
||||
[Browsable(false)]
|
||||
public bool DisplayInEditor { get; set; } = true;
|
||||
|
||||
[DisplayName("Name"), CategoryAttribute("Pane")]
|
||||
public string Name { get; set; }
|
||||
|
||||
[DisplayName("Translate"), CategoryAttribute("Pane")]
|
||||
public Vector3F Translate { get; set; }
|
||||
|
||||
[DisplayName("Rotate"), CategoryAttribute("Pane")]
|
||||
public Vector3F Rotate { get; set; }
|
||||
|
||||
[DisplayName("Scale"), CategoryAttribute("Pane")]
|
||||
public Vector2F Scale { get; set; }
|
||||
|
||||
[DisplayName("Width"), CategoryAttribute("Pane")]
|
||||
public float Width { get; set; }
|
||||
|
||||
[DisplayName("Width"), CategoryAttribute("Pane")]
|
||||
public float Height { get; set; }
|
||||
|
||||
[DisplayName("Origin X"), CategoryAttribute("Origin")]
|
||||
public virtual OriginX originX { get; set; }
|
||||
|
||||
[DisplayName("Origin X"), CategoryAttribute("Origin")]
|
||||
public virtual OriginY originY { get; set; }
|
||||
|
||||
[Browsable(false)]
|
||||
public virtual OriginX ParentOriginX { get; set; }
|
||||
|
||||
[Browsable(false)]
|
||||
public virtual OriginY ParentOriginY { get; set; }
|
||||
|
||||
[Browsable(false)]
|
||||
public BasePane Parent { get; set; }
|
||||
|
||||
[Browsable(false)]
|
||||
public List<BasePane> Childern { get; set; } = new List<BasePane>();
|
||||
|
||||
[Browsable(false)]
|
||||
public bool HasChildern
|
||||
{
|
||||
get { return Childern.Count > 0; }
|
||||
|
@ -1273,6 +1273,10 @@ namespace FirstPlugin
|
||||
throw new Exception($"Cannot convert format {texFormat}");
|
||||
}
|
||||
}
|
||||
public static TEX_FORMAT ConvertFormat(uint surfaceFormat)
|
||||
{
|
||||
return ConvertFormat((SurfaceFormat)surfaceFormat);
|
||||
}
|
||||
|
||||
public static TEX_FORMAT ConvertFormat(SurfaceFormat surfaceFormat)
|
||||
{
|
||||
@ -1340,6 +1344,7 @@ namespace FirstPlugin
|
||||
case SurfaceFormat.ASTC_8x6_UNORM: return TEX_FORMAT.ASTC_8x6_UNORM;
|
||||
case SurfaceFormat.ASTC_8x8_SRGB: return TEX_FORMAT.ASTC_8x8_SRGB;
|
||||
case SurfaceFormat.ASTC_8x8_UNORM: return TEX_FORMAT.ASTC_8x8_UNORM;
|
||||
|
||||
case SurfaceFormat.Invalid: throw new Exception("Invalid Format");
|
||||
default:
|
||||
throw new Exception($"Cannot convert format {surfaceFormat}");
|
||||
|
248
File_Format_Library/FileFormats/Texture/WTB.cs
Normal file
248
File_Format_Library/FileFormats/Texture/WTB.cs
Normal file
@ -0,0 +1,248 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Toolbox;
|
||||
using System.Windows.Forms;
|
||||
using Toolbox.Library;
|
||||
using Toolbox.Library.IO;
|
||||
using Toolbox.Library.Forms;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace FirstPlugin
|
||||
{
|
||||
public class WTB : TreeNodeFile, IFileFormat, ILeaveOpenOnLoad
|
||||
{
|
||||
public FileType FileType { get; set; } = FileType.Image;
|
||||
|
||||
public bool CanSave { get; set; }
|
||||
public string[] Description { get; set; } = new string[] { "WTA Texture" };
|
||||
public string[] Extension { get; set; } = new string[] { "*.wta" };
|
||||
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 Toolbox.Library.IO.FileReader(stream, true))
|
||||
{
|
||||
return reader.CheckSignature(3, "WTB");
|
||||
}
|
||||
}
|
||||
|
||||
public List<STGenericTexture> IconTextureList
|
||||
{
|
||||
get
|
||||
{
|
||||
List<STGenericTexture> textures = new List<STGenericTexture>();
|
||||
foreach (STGenericTexture node in Nodes)
|
||||
textures.Add(node);
|
||||
|
||||
return textures;
|
||||
}
|
||||
set { }
|
||||
}
|
||||
|
||||
public Type[] Types
|
||||
{
|
||||
get
|
||||
{
|
||||
List<Type> types = new List<Type>();
|
||||
return types.ToArray();
|
||||
}
|
||||
}
|
||||
|
||||
public void Load(System.IO.Stream stream)
|
||||
{
|
||||
Text = FileName;
|
||||
|
||||
using (var reader = new FileReader(stream, true))
|
||||
{
|
||||
reader.SetByteOrder(false);
|
||||
|
||||
uint magic = reader.ReadUInt32();
|
||||
uint version = reader.ReadUInt32();
|
||||
uint numTextures = reader.ReadUInt32();
|
||||
|
||||
uint dataOffsetTable = reader.ReadUInt32();
|
||||
uint dataSizeTable = reader.ReadUInt32();
|
||||
uint unkTable = reader.ReadUInt32();
|
||||
uint unk2Table = reader.ReadUInt32();
|
||||
uint textureInfoTable = reader.ReadUInt32();
|
||||
|
||||
List<TextureEntry> entries = new List<TextureEntry>();
|
||||
for (int i = 0; i < numTextures; i++)
|
||||
{
|
||||
TextureEntry tex = new TextureEntry();
|
||||
|
||||
//Get data offset
|
||||
reader.SeekBegin(dataOffsetTable + (i * 4));
|
||||
tex.DataOffset = reader.ReadUInt32();
|
||||
|
||||
//Get data size
|
||||
reader.SeekBegin(dataSizeTable + (i * 4));
|
||||
tex.DataSize = reader.ReadUInt32();
|
||||
|
||||
//Get tex info
|
||||
reader.SeekBegin(textureInfoTable + (i * 56));
|
||||
tex.Info = reader.ReadStruct<TextureInfo>();
|
||||
entries.Add(tex);
|
||||
Nodes.Add(new TextureWrapper(tex) { Text = $"Texture {i}" });
|
||||
}
|
||||
|
||||
string fileData = FilePath.Replace("wta", "wtp");
|
||||
if (System.IO.File.Exists(fileData))
|
||||
{
|
||||
using (var readerData = new FileReader(fileData))
|
||||
{
|
||||
for (int i = 0; i < numTextures; i++)
|
||||
{
|
||||
readerData.SeekBegin(entries[i].DataOffset);
|
||||
entries[i].ImageData = readerData.ReadBytes((int)entries[i].DataSize);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential, Pack = 1)]
|
||||
public class TextureInfo
|
||||
{
|
||||
public Magic Magic = "XT1 ";
|
||||
public uint unknown;
|
||||
public uint ImageSize;
|
||||
public uint Padding;
|
||||
public uint Format;
|
||||
public uint MipCount;
|
||||
public uint unknown2;
|
||||
public uint unknown3;
|
||||
public uint Width;
|
||||
public uint Height;
|
||||
public uint Depth;
|
||||
public uint unknown4;
|
||||
public uint unknown5;
|
||||
public uint unknown6;
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential, Pack = 1)]
|
||||
public class TextureEntry
|
||||
{
|
||||
public uint DataOffset;
|
||||
public uint DataSize;
|
||||
|
||||
public TextureInfo Info;
|
||||
|
||||
public string SourceFile;
|
||||
|
||||
public byte[] ImageData;
|
||||
}
|
||||
|
||||
public void Unload()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public void Save(System.IO.Stream stream)
|
||||
{
|
||||
}
|
||||
|
||||
public class TextureWrapper : STGenericTexture
|
||||
{
|
||||
public TextureEntry Texture;
|
||||
|
||||
public TextureWrapper(TextureEntry tex)
|
||||
{
|
||||
Texture = tex;
|
||||
Width = tex.Info.Width;
|
||||
Height = tex.Info.Height;
|
||||
Depth = tex.Info.Depth;
|
||||
ArrayCount = 1;
|
||||
MipCount = tex.Info.MipCount;
|
||||
if (Formats.ContainsKey(tex.Info.Format))
|
||||
Format = Formats[tex.Info.Format];
|
||||
}
|
||||
|
||||
private Dictionary<uint, TEX_FORMAT> Formats = new Dictionary<uint, TEX_FORMAT>()
|
||||
{
|
||||
{0x01, TEX_FORMAT.R8G8_UNORM},
|
||||
{0x0d, TEX_FORMAT.R9G9B9E5_SHAREDEXP},
|
||||
{0x1a, TEX_FORMAT.BC1_UNORM},
|
||||
{0x1b, TEX_FORMAT.BC2_UNORM},
|
||||
{0x1c, TEX_FORMAT.BC3_UNORM},
|
||||
{0x1d, TEX_FORMAT.BC4_UNORM},
|
||||
{0x1e, TEX_FORMAT.BC5_UNORM},
|
||||
{0x2d, TEX_FORMAT.ASTC_4x4_UNORM},
|
||||
{0x2e, TEX_FORMAT.ASTC_5x4_UNORM},
|
||||
{0x2f, TEX_FORMAT.ASTC_5x5_UNORM},
|
||||
{0x30, TEX_FORMAT.ASTC_6x5_UNORM},
|
||||
{0x31, TEX_FORMAT.ASTC_6x6_UNORM},
|
||||
{0x32, TEX_FORMAT.ASTC_8x5_UNORM},
|
||||
{0x33, TEX_FORMAT.ASTC_8x6_UNORM},
|
||||
{0x34, TEX_FORMAT.ASTC_8x8_UNORM},
|
||||
{0x35, TEX_FORMAT.ASTC_10x5_UNORM},
|
||||
{0x36, TEX_FORMAT.ASTC_10x6_UNORM},
|
||||
{0x37, TEX_FORMAT.ASTC_10x8_UNORM},
|
||||
{0x38, TEX_FORMAT.ASTC_10x10_UNORM},
|
||||
{0x39, TEX_FORMAT.ASTC_12x10_UNORM},
|
||||
{0x3a, TEX_FORMAT.ASTC_12x12_UNORM},
|
||||
{0x3b, TEX_FORMAT.B5G5R5A1_UNORM},
|
||||
|
||||
};
|
||||
|
||||
public override bool CanEdit { get; set; } = false;
|
||||
|
||||
public override TEX_FORMAT[] SupportedFormats
|
||||
{
|
||||
get
|
||||
{
|
||||
return new TEX_FORMAT[]
|
||||
{
|
||||
TEX_FORMAT.B5G6R5_UNORM,
|
||||
TEX_FORMAT.R8G8_UNORM,
|
||||
TEX_FORMAT.B5G5R5A1_UNORM,
|
||||
TEX_FORMAT.B4G4R4A4_UNORM,
|
||||
TEX_FORMAT.LA8,
|
||||
TEX_FORMAT.HIL08,
|
||||
TEX_FORMAT.L8,
|
||||
TEX_FORMAT.A8_UNORM,
|
||||
TEX_FORMAT.LA4,
|
||||
TEX_FORMAT.A4,
|
||||
TEX_FORMAT.ETC1_UNORM,
|
||||
TEX_FORMAT.ETC1_A4,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public override void SetImageData(System.Drawing.Bitmap bitmap, int ArrayLevel)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public override byte[] GetImageData(int ArrayLevel = 0, int MipLevel = 0)
|
||||
{
|
||||
return TegraX1Swizzle.GetImageData(this, Texture.ImageData, ArrayLevel, MipLevel, 1);
|
||||
}
|
||||
|
||||
|
||||
public override void OnClick(TreeView treeView)
|
||||
{
|
||||
UpdateEditor();
|
||||
}
|
||||
|
||||
private void UpdateEditor()
|
||||
{
|
||||
ImageEditorBase editor = (ImageEditorBase)LibraryGUI.GetActiveContent(typeof(ImageEditorBase));
|
||||
if (editor == null)
|
||||
{
|
||||
editor = new ImageEditorBase();
|
||||
editor.Dock = DockStyle.Fill;
|
||||
LibraryGUI.LoadEditor(editor);
|
||||
}
|
||||
|
||||
editor.LoadProperties(GenericProperties);
|
||||
editor.LoadImage(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -312,6 +312,7 @@
|
||||
<Compile Include="FileFormats\Texture\TPL.cs" />
|
||||
<Compile Include="FileFormats\Rom\GCDisk.cs" />
|
||||
<Compile Include="FileFormats\Texture\BTI.cs" />
|
||||
<Compile Include="FileFormats\Texture\WTB.cs" />
|
||||
<Compile Include="GL\BMD_Renderer.cs" />
|
||||
<Compile Include="GL\CMB_Renderer.cs" />
|
||||
<Compile Include="GL\GXToOpenGL.cs" />
|
||||
|
@ -94,6 +94,9 @@ namespace LayoutBXLYT
|
||||
GL.Enable(EnableCap.Blend);
|
||||
GL.BlendFunc(BlendingFactor.SrcAlpha, BlendingFactor.OneMinusSrcAlpha);
|
||||
|
||||
GL.Enable(EnableCap.Texture2D);
|
||||
GL.BindTexture(TextureTarget.Texture2D, 0);
|
||||
|
||||
DrawRootPane(LayoutFile.RootPane);
|
||||
DrawGrid();
|
||||
DrawXyLines();
|
||||
@ -196,6 +199,7 @@ namespace LayoutBXLYT
|
||||
DrawRectangle(pane.CreateRectangle(), TexCoords, Colors);
|
||||
}
|
||||
|
||||
int texId = 1;
|
||||
private void DrawPicturePane(BCLYT.PIC1 pane)
|
||||
{
|
||||
Vector2[] TexCoords = new Vector2[] {
|
||||
@ -212,8 +216,6 @@ namespace LayoutBXLYT
|
||||
pane.ColorBottomLeft.Color,
|
||||
};
|
||||
|
||||
GL.Enable(EnableCap.Texture2D);
|
||||
|
||||
if (pane.TexCoords.Length > 0)
|
||||
{
|
||||
var mat = pane.GetMaterial();
|
||||
@ -253,17 +255,17 @@ namespace LayoutBXLYT
|
||||
pane.ColorBottomLeft.Color,
|
||||
};
|
||||
|
||||
GL.Enable(EnableCap.Texture2D);
|
||||
|
||||
if (pane.TexCoords.Length > 0)
|
||||
{
|
||||
var mat = pane.GetMaterial();
|
||||
var mat = pane.Material;
|
||||
string textureMap0 = "";
|
||||
if (mat.TextureMaps.Count > 0)
|
||||
if (mat.TextureMaps.Length > 0)
|
||||
textureMap0 = mat.GetTexture(0);
|
||||
|
||||
if (Textures.ContainsKey(textureMap0))
|
||||
{
|
||||
BindGLTexture(mat.TextureMaps[0], Textures[textureMap0]);
|
||||
}
|
||||
|
||||
TexCoords = new Vector2[] {
|
||||
pane.TexCoords[0].TopLeft.ToTKVector2(),
|
||||
@ -275,7 +277,7 @@ namespace LayoutBXLYT
|
||||
|
||||
DrawRectangle(pane.CreateRectangle(), TexCoords, Colors, false);
|
||||
|
||||
GL.BindTexture(TextureTarget.Texture2D, 0);
|
||||
GL.BindTexture(TextureTarget.Texture2D, 0);
|
||||
}
|
||||
|
||||
public void DrawRectangle(CustomRectangle rect, Vector2[] texCoords, Color[] colors, bool useLines = true)
|
||||
@ -318,13 +320,11 @@ namespace LayoutBXLYT
|
||||
if (!texture.RenderableTex.GLInitialized)
|
||||
return;
|
||||
|
||||
// GL.ActiveTexture(TextureUnit.Texture0 + texid);
|
||||
GL.BindTexture(TextureTarget.Texture2D, texture.RenderableTex.TexID);
|
||||
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapS, ConvertTextureWrap(tex.WrapModeU));
|
||||
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapT, ConvertTextureWrap(tex.WrapModeV));
|
||||
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, ConvertMagFilterMode(tex.MaxFilterMode));
|
||||
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, ConvertMinFilterMode(tex.MinFilterMode));
|
||||
GL.TexParameter(TextureTarget.Texture2D, (TextureParameterName)ExtTextureFilterAnisotropic.TextureMaxAnisotropyExt, 0.0f);
|
||||
}
|
||||
|
||||
private static int ConvertTextureWrap(BFLYT.TextureRef.WrapMode wrapMode)
|
||||
@ -484,7 +484,6 @@ namespace LayoutBXLYT
|
||||
GL.End();
|
||||
GL.Color3(Color.Transparent);
|
||||
GL.PopAttrib();
|
||||
GL.Enable(EnableCap.Texture2D);
|
||||
GL.PopMatrix();
|
||||
}
|
||||
|
||||
|
@ -379,6 +379,7 @@ namespace FirstPlugin
|
||||
Formats.Add(typeof(CTR.NCCH.RomFS));
|
||||
Formats.Add(typeof(DKCTF.MSBT));
|
||||
Formats.Add(typeof(DKCTF.PAK));
|
||||
Formats.Add(typeof(WTB));
|
||||
|
||||
// Formats.Add(typeof(MSBP));
|
||||
// Formats.Add(typeof(BFGRP));
|
||||
|
@ -188,6 +188,9 @@ namespace Toolbox.Library
|
||||
writer.Write(IntTo3Bytes((int)Height));
|
||||
writer.Write(IntTo3Bytes((int)Depth));
|
||||
writer.Write(DataBlock);
|
||||
|
||||
writer.Close();
|
||||
writer.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -188,6 +188,8 @@ namespace Toolbox.Library
|
||||
//
|
||||
public List<Surface> GetSurfaces(int ArrayIndexStart = 0, bool GetAllSurfaces = true, int GetSurfaceAmount = 1)
|
||||
{
|
||||
|
||||
|
||||
if (GetAllSurfaces)
|
||||
GetSurfaceAmount = (int)ArrayCount;
|
||||
|
||||
@ -859,6 +861,8 @@ namespace Toolbox.Library
|
||||
atsc.BlockDimZ = (byte)GetBlockDepth(Format);
|
||||
atsc.DataBlock = Utils.CombineByteArray(surfaces[0].mipmaps.ToArray());
|
||||
|
||||
Console.WriteLine("DataBlock " + atsc.DataBlock.Length);
|
||||
|
||||
atsc.Save(new FileStream(FileName, FileMode.Create, FileAccess.ReadWrite));
|
||||
}
|
||||
public void SaveTGA(string FileName, bool ExportSurfaceLevel = false,
|
||||
|
Loading…
Reference in New Issue
Block a user