Add support for LM3DS GAR
This commit is contained in:
parent
11ebded46b
commit
231a6ee9c6
Binary file not shown.
@ -212,6 +212,12 @@ namespace FirstPlugin
|
||||
if (index == 0)
|
||||
matTexture.Type = STGenericMatTexture.TextureType.Diffuse;
|
||||
|
||||
if (tex.TextureIndex < Renderer.TextureList.Count && tex.TextureIndex > 0)
|
||||
{
|
||||
matTexture.Name = Renderer.TextureList[tex.TextureIndex].Text;
|
||||
material.Nodes.Add(matTexture.Name);
|
||||
}
|
||||
|
||||
index++;
|
||||
}
|
||||
}
|
||||
@ -300,7 +306,7 @@ namespace FirstPlugin
|
||||
|
||||
bool HasWeights = shape.Primatives[0].SkinningMode == SkinningMode.SMOOTH_SKINNING;
|
||||
|
||||
/* if (shape.BoneIndices.VertexData != null && HasSkinning && shape.BoneIndices.VertexData.Length > v)
|
||||
/* if (shape.BoneIndices.VertexData != null && HasSkinning && shape.BoneIndices.VertexData.Length > v)
|
||||
{
|
||||
var BoneIndices = shape.BoneIndices.VertexData[v];
|
||||
for (int j = 0; j < shape.boneDimension; j++)
|
||||
@ -1203,6 +1209,8 @@ namespace FirstPlugin
|
||||
{
|
||||
reader.SeekBegin(pos + 0xC + (i * materialSize));
|
||||
|
||||
Console.WriteLine("MAT " + i);
|
||||
|
||||
Material mat = new Material();
|
||||
mat.Read(reader, header, this);
|
||||
Materials.Add(mat);
|
||||
@ -1376,7 +1384,7 @@ namespace FirstPlugin
|
||||
|
||||
reader.SeekBegin(pos + 0x130);
|
||||
AlphaTestEnable = reader.ReadBoolean();
|
||||
AlphaTestReference = reader.ReadByte() / 255.0f;
|
||||
AlphaTestReference = reader.ReadByte() / 0xFF;
|
||||
AlphaTestFunction = (AlphaFunction)reader.ReadUInt16();
|
||||
|
||||
DepthTestEnable = reader.ReadBoolean();
|
||||
@ -1399,13 +1407,13 @@ namespace FirstPlugin
|
||||
|
||||
reader.SeekBegin(pos + 0x13C);
|
||||
|
||||
BlendingFactorSrcRGB = (BlendingFactor)reader.ReadUInt16();
|
||||
BlendingFactorDestRGB = (BlendingFactor)reader.ReadUInt16();
|
||||
BlendingFactorSrcAlpha = (BlendingFactor)reader.ReadUInt16();
|
||||
BlendingFactorDestAlpha = (BlendingFactor)reader.ReadUInt16();
|
||||
|
||||
reader.SeekBegin(pos + 0x144);
|
||||
|
||||
BlendingFactorSrcAlpha = (BlendingFactor)reader.ReadUInt16();
|
||||
BlendingFactorDestAlpha = (BlendingFactor)reader.ReadUInt16();
|
||||
BlendingFactorSrcRGB = (BlendingFactor)reader.ReadUInt16();
|
||||
BlendingFactorDestRGB = (BlendingFactor)reader.ReadUInt16();
|
||||
|
||||
// BlendingFunctionAlpha = (AlphaFunction)reader.ReadUInt16();
|
||||
|
||||
@ -1417,6 +1425,27 @@ namespace FirstPlugin
|
||||
BlendColorA = reader.ReadSingle();
|
||||
|
||||
IsTransparent = BlendEnaled;
|
||||
|
||||
Console.WriteLine(ToString());
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.Append($"----------------------------------------------------\n");
|
||||
sb.Append($"AlphaTest {AlphaTestEnable} {AlphaTestFunction} {AlphaTestReference}\n");
|
||||
sb.Append($"DepthTest {DepthTestEnable} {DepthTestFunction} DepthWrite {DepthTestFunction}\n");
|
||||
|
||||
sb.Append($"BlendingFactorSrcRGB {BlendingFactorSrcRGB}\n");
|
||||
sb.Append($"BlendingFactorDestRGB {BlendingFactorDestRGB}\n");
|
||||
sb.Append($"BlendingFactorSrcAlpha {BlendingFactorSrcAlpha}\n");
|
||||
sb.Append($"BlendingFactorDestAlpha {BlendingFactorDestAlpha}\n");
|
||||
sb.Append($"BlendEnaled {BlendEnaled}\n");
|
||||
sb.Append($"----------------------------------------------------\n");
|
||||
|
||||
sb.AppendLine();
|
||||
|
||||
return sb.ToString();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -10,7 +10,7 @@ using Toolbox.Library.IO;
|
||||
|
||||
namespace FirstPlugin
|
||||
{
|
||||
public class ZAR : IArchiveFile, IFileFormat
|
||||
public class GAR : IArchiveFile, IFileFormat
|
||||
{
|
||||
public FileType FileType { get; set; } = FileType.Archive;
|
||||
|
||||
@ -76,8 +76,8 @@ namespace FirstPlugin
|
||||
public uint DataOffset;
|
||||
public string Codename;
|
||||
|
||||
public List<FileGroup> FileGroups = new List<FileGroup>();
|
||||
public List<GarFileInfo> GarFileInfos = new List<GarFileInfo>();
|
||||
public List<IFileGroup> FileGroups = new List<IFileGroup>();
|
||||
public List<IFileInfo> GarFileInfos = new List<IFileInfo>();
|
||||
|
||||
public void Read(FileReader reader, List<FileEntry> files)
|
||||
{
|
||||
@ -112,16 +112,45 @@ namespace FirstPlugin
|
||||
break;
|
||||
case "agora\0\0\0":
|
||||
case "SYSTEM\0\0":
|
||||
ReadGrezzoArchive(reader, files);
|
||||
ReadSystemGrezzoArchive(reader, files);
|
||||
break;
|
||||
default:
|
||||
throw new Exception($"Unexpected codename! {Codename}");
|
||||
}
|
||||
}
|
||||
|
||||
private void ReadGrezzoArchive(FileReader reader, List<FileEntry> files)
|
||||
private void ReadSystemGrezzoArchive(FileReader reader, List<FileEntry> files)
|
||||
{
|
||||
|
||||
reader.SeekBegin(FileGroupOffset);
|
||||
for (int i = 0; i < FileGroupCount; i++)
|
||||
{
|
||||
FileGroups.Add(new SystemFileGroup(reader));
|
||||
reader.Align(0x20);
|
||||
}
|
||||
|
||||
reader.BaseStream.Position = FileGroups.Min(x => ((SystemFileGroup)x).SubTableOffset);
|
||||
byte[] entries = reader.ReadBytes((int)FileInfoOffset - (int)reader.BaseStream.Position);
|
||||
|
||||
reader.SeekBegin(FileInfoOffset);
|
||||
for (int i = 0; i < FileGroupCount; i++)
|
||||
{
|
||||
for (int f = 0; f < ((SystemFileGroup)FileGroups[i]).FileCount; f++)
|
||||
{
|
||||
GarFileInfos.Add(new SystemGarFileInfo(reader));
|
||||
((SystemGarFileInfo)GarFileInfos.Last()).ext = ((SystemFileGroup)FileGroups[i]).Name;
|
||||
}
|
||||
}
|
||||
|
||||
reader.SeekBegin(DataOffset);
|
||||
for (int i = 0; i < GarFileInfos.Count; i++)
|
||||
{
|
||||
var info = (SystemGarFileInfo)GarFileInfos[i];
|
||||
files.Add(new FileEntry()
|
||||
{
|
||||
FileName = $"{info.Name}.{info.ext}",
|
||||
FileData = reader.getSection(info.FileOffset, info.FileSize)
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private void ReadZeldaArchive(FileReader reader, List<FileEntry> files)
|
||||
@ -131,14 +160,16 @@ namespace FirstPlugin
|
||||
FileGroups.Add(new FileGroup(reader));
|
||||
|
||||
for (int i = 0; i < FileGroupCount; i++)
|
||||
FileGroups[i].Ids = reader.ReadInt32s((int)FileGroups[i].FileCount);
|
||||
((FileGroup)FileGroups[i]).Ids = reader.ReadInt32s((int)((FileGroup)FileGroups[i]).FileCount);
|
||||
|
||||
|
||||
reader.SeekBegin(FileInfoOffset);
|
||||
for (int i = 0; i < FileGroupCount; i++)
|
||||
{
|
||||
for (int f = 0; f < FileGroups[i].FileCount; f++)
|
||||
for (int f = 0; f < ((FileGroup)FileGroups[i]).FileCount; f++)
|
||||
{
|
||||
GarFileInfos.Add(new GarFileInfo(reader));
|
||||
}
|
||||
}
|
||||
|
||||
reader.SeekBegin(DataOffset);
|
||||
@ -147,13 +178,23 @@ namespace FirstPlugin
|
||||
{
|
||||
files.Add(new FileEntry()
|
||||
{
|
||||
FileName = GarFileInfos[i].FileName,
|
||||
FileData = reader.getSection(Offsets[i], GarFileInfos[i].FileSize)
|
||||
FileName = ((GarFileInfo)GarFileInfos[i]).FileName,
|
||||
FileData = reader.getSection(Offsets[i], ((GarFileInfo)GarFileInfos[i]).FileSize)
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public class FileGroup
|
||||
public interface IFileGroup
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public interface IFileInfo
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public class FileGroup : IFileGroup
|
||||
{
|
||||
public uint FileCount;
|
||||
public uint DataOffset;
|
||||
@ -166,11 +207,31 @@ namespace FirstPlugin
|
||||
FileCount = reader.ReadUInt32();
|
||||
DataOffset = reader.ReadUInt32();
|
||||
InfoOffset = reader.ReadUInt32();
|
||||
reader.ReadUInt32();
|
||||
reader.ReadUInt32(); //padding
|
||||
}
|
||||
}
|
||||
|
||||
public class ZarFileInfo
|
||||
public class SystemFileGroup : IFileGroup
|
||||
{
|
||||
public uint FileCount;
|
||||
public uint Unknown;
|
||||
public uint InfoOffset;
|
||||
public string Name;
|
||||
public uint SubTableOffset;
|
||||
|
||||
public int[] Ids;
|
||||
|
||||
public SystemFileGroup(FileReader reader)
|
||||
{
|
||||
FileCount = reader.ReadUInt32();
|
||||
Unknown = reader.ReadUInt32();
|
||||
InfoOffset = reader.ReadUInt32();
|
||||
Name = reader.LoadString(false, typeof(uint));
|
||||
SubTableOffset = reader.ReadUInt32();
|
||||
}
|
||||
}
|
||||
|
||||
public class ZarFileInfo : IFileInfo
|
||||
{
|
||||
public uint FileSize;
|
||||
public string FileName;
|
||||
@ -182,7 +243,7 @@ namespace FirstPlugin
|
||||
}
|
||||
}
|
||||
|
||||
public class GarFileInfo
|
||||
public class GarFileInfo : IFileInfo
|
||||
{
|
||||
public uint FileSize;
|
||||
public string FileName;
|
||||
@ -195,6 +256,23 @@ namespace FirstPlugin
|
||||
FileName = reader.LoadString(false, typeof(uint));
|
||||
}
|
||||
}
|
||||
|
||||
public class SystemGarFileInfo : IFileInfo
|
||||
{
|
||||
public uint FileSize;
|
||||
public uint FileOffset;
|
||||
public string FileName;
|
||||
public string Name;
|
||||
public string ext;
|
||||
|
||||
public SystemGarFileInfo(FileReader reader)
|
||||
{
|
||||
FileSize = reader.ReadUInt32();
|
||||
FileOffset = reader.ReadUInt32();
|
||||
Name = reader.LoadString(false, typeof(uint));
|
||||
reader.ReadUInt32();//padding
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void Unload()
|
@ -229,7 +229,7 @@
|
||||
<Compile Include="FileFormats\Archives\TMPK.cs" />
|
||||
<Compile Include="FileFormats\Archives\U8.cs" />
|
||||
<Compile Include="FileFormats\Grezzo\CMB.cs" />
|
||||
<Compile Include="FileFormats\Grezzo\ZAR.cs" />
|
||||
<Compile Include="FileFormats\Grezzo\GAR.cs" />
|
||||
<Compile Include="FileFormats\Grezzo\ZSI.cs" />
|
||||
<Compile Include="FileFormats\Audio\Archives\BARS.cs" />
|
||||
<Compile Include="FileFormats\Audio\BARSLIST.cs" />
|
||||
|
@ -19,7 +19,10 @@ namespace FirstPlugin
|
||||
|
||||
public override void OnRender(GLControl control)
|
||||
{
|
||||
|
||||
GL.Enable(EnableCap.AlphaTest);
|
||||
GL.AlphaFunc(AlphaFunction.Gequal, 0.1f);
|
||||
GL.Enable(EnableCap.Blend);
|
||||
GL.BlendFunc(BlendingFactor.SrcAlpha, BlendingFactor.OneMinusSrcAlpha);
|
||||
}
|
||||
|
||||
public override void DrawModels(ShaderProgram shader, GL_ControlModern control)
|
||||
@ -53,12 +56,14 @@ namespace FirstPlugin
|
||||
{
|
||||
var bmdMaterial = (BMDMaterialWrapper)mat;
|
||||
|
||||
//This is only for translucency
|
||||
//Todo figure out how bmd determines transparent materials
|
||||
shader.SetBoolToInt("isTransparent", bmdMaterial.isTransparent);
|
||||
|
||||
GXToOpenGL.SetBlendState(bmdMaterial.Material.BMode);
|
||||
GXToOpenGL.SetCullState(bmdMaterial.Material.CullMode);
|
||||
GXToOpenGL.SetDepthState(bmdMaterial.Material.ZMode, false);
|
||||
GXToOpenGL.SetDitherEnabled(bmdMaterial.Material.Dither);
|
||||
// GXToOpenGL.SetDepthState(bmdMaterial.Material.ZMode, false);
|
||||
// GXToOpenGL.SetDitherEnabled(bmdMaterial.Material.Dither);
|
||||
}
|
||||
|
||||
public override int BindTexture(STGenericMatTexture tex, ShaderProgram shader)
|
||||
|
@ -52,18 +52,49 @@ namespace FirstPlugin
|
||||
|
||||
public override void OnRender(GLControl control)
|
||||
{
|
||||
|
||||
GL.Enable(EnableCap.AlphaTest);
|
||||
GL.AlphaFunc(AlphaFunction.Gequal, 0.1f);
|
||||
GL.Enable(EnableCap.Blend);
|
||||
GL.BlendFunc(BlendingFactor.SrcAlpha, BlendingFactor.OneMinusSrcAlpha);
|
||||
}
|
||||
|
||||
public override void DrawModels(ShaderProgram shader, GL_ControlModern control)
|
||||
{
|
||||
shader.EnableVertexAttributes();
|
||||
|
||||
List<STGenericObject> opaque = new List<STGenericObject>();
|
||||
List<STGenericObject> transparent = new List<STGenericObject>();
|
||||
|
||||
for (int m = 0; m < Meshes.Count; m++)
|
||||
{
|
||||
if (((CMB.CMBMaterialWrapper)Meshes[m].GetMaterial()).Material.IsTransparent)
|
||||
transparent.Add(Meshes[m]);
|
||||
else
|
||||
opaque.Add(Meshes[m]);
|
||||
}
|
||||
|
||||
for (int m = 0; m < transparent.Count; m++)
|
||||
{
|
||||
DrawModel(control, Skeleton, transparent[m].GetMaterial(), transparent[m], shader);
|
||||
}
|
||||
|
||||
for (int m = 0; m < opaque.Count; m++)
|
||||
{
|
||||
DrawModel(control, Skeleton, opaque[m].GetMaterial(), opaque[m], shader);
|
||||
}
|
||||
|
||||
shader.DisableVertexAttributes();
|
||||
}
|
||||
|
||||
public override void SetRenderData(STGenericMaterial mat, ShaderProgram shader, STGenericObject m)
|
||||
{
|
||||
var cmbMaterial = ((CMB.CMBMaterialWrapper)mat).Material;
|
||||
|
||||
shader.SetBoolToInt("isTransparent", cmbMaterial.IsTransparent);
|
||||
shader.SetBoolToInt("isTransparent", cmbMaterial.BlendEnaled);
|
||||
|
||||
GL.Enable(EnableCap.Blend);
|
||||
GL.BlendFunc(cmbMaterial.BlendingFactorSrcAlpha, cmbMaterial.BlendingFactorDestAlpha);
|
||||
GL.BlendColor(cmbMaterial.BlendColorR, cmbMaterial.BlendColorG, cmbMaterial.BlendColorB, cmbMaterial.BlendColorA);
|
||||
GL.BlendColor(1.0f, 1.0f, 1.0f, cmbMaterial.BlendColorA);
|
||||
if (cmbMaterial.AlphaTestEnable)
|
||||
GL.Enable(EnableCap.AlphaTest);
|
||||
else
|
||||
|
@ -352,7 +352,7 @@ namespace FirstPlugin
|
||||
Formats.Add(typeof(BFTTF));
|
||||
Formats.Add(typeof(PACx30XL));
|
||||
Formats.Add(typeof(BinGzArchive));
|
||||
Formats.Add(typeof(ZAR));
|
||||
Formats.Add(typeof(GAR));
|
||||
Formats.Add(typeof(CTXB));
|
||||
Formats.Add(typeof(G1T));
|
||||
Formats.Add(typeof(BFLYT));
|
||||
|
@ -425,7 +425,7 @@ namespace Toolbox.Library.Rendering
|
||||
SetVertexAttributes(m, shader);
|
||||
SetTextureUniforms(Material, m, shader);
|
||||
|
||||
if (m.IsSelected)
|
||||
if (m.IsSelected || m.GetMaterial().IsSelected)
|
||||
{
|
||||
DrawModelSelection(group, shader);
|
||||
}
|
||||
|
Binary file not shown.
Binary file not shown.
@ -67,7 +67,7 @@ uniform samplerCube irradianceMap;
|
||||
uniform samplerCube specularIbl;
|
||||
uniform sampler2D brdfLUT;
|
||||
|
||||
int isTransparent;
|
||||
uniform int isTransparent;
|
||||
|
||||
out vec4 fragColor;
|
||||
|
||||
@ -142,6 +142,7 @@ void main()
|
||||
// Global brightness adjustment.
|
||||
// fragColor.rgb *= 1.5;
|
||||
|
||||
fragColor.a = 1;
|
||||
if (isTransparent == 1)
|
||||
{
|
||||
fragColor.a = alpha;
|
||||
|
Loading…
x
Reference in New Issue
Block a user