1
0
mirror of synced 2025-02-25 14:34:47 +01:00

Cleanup file location a bit. Fix LM3 faces for certain formats

This commit is contained in:
KillzXGaming 2019-11-02 19:35:08 -04:00
parent 1472c4e112
commit d54c835bc4
16 changed files with 119 additions and 45 deletions

View File

@ -200,6 +200,40 @@ namespace FirstPlugin.LuigisMansion.DarkMoon
currentModel.BufferStart = chunkEntry.Entry.ChunkOffset; currentModel.BufferStart = chunkEntry.Entry.ChunkOffset;
currentModel.BufferSize = chunkEntry.Entry.ChunkSize; currentModel.BufferSize = chunkEntry.Entry.ChunkSize;
break; break;
case SubDataType.BoneData:
if (chunk.ChunkSize > 0x40 && currentModel.Skeleton == null)
{
using (var boneReader = new FileReader(chunkEntry.FileData))
{
currentModel.Skeleton = new STSkeleton();
DrawableContainer.Drawables.Add(currentModel.Skeleton);
uint numBones = chunk.ChunkSize / 68;
for (int i = 0; i < numBones; i++)
{
boneReader.SeekBegin(i * 68);
STBone bone = new STBone(currentModel.Skeleton);
bone.position = new float[3] { 0, 0, 0 };
bone.rotation = new float[4] { 0, 0, 0, 1 };
bone.scale = new float[3] { 0.2f, 0.2f, 0.2f };
boneReader.SeekBegin(52 + (i * 68));
var Position = new OpenTK.Vector3(boneReader.ReadSingle(), boneReader.ReadSingle(), boneReader.ReadSingle());
Position = OpenTK.Vector3.TransformPosition(Position, OpenTK.Matrix4.CreateRotationX(OpenTK.MathHelper.DegreesToRadians(90)));
bone.position[0] = Position.X;
bone.position[2] = Position.Y;
bone.position[1] = Position.Z;
bone.RotationType = STBone.BoneRotationType.Euler;
currentModel.Skeleton.bones.Add(bone);
}
currentModel.Skeleton.reset();
currentModel.Skeleton.update();
}
}
break;
case SubDataType.VertexStartPointers: case SubDataType.VertexStartPointers:
using (var vtxPtrReader = new FileReader(chunkEntry.FileData)) using (var vtxPtrReader = new FileReader(chunkEntry.FileData))
{ {

View File

@ -32,6 +32,7 @@ namespace FirstPlugin.LuigisMansion.DarkMoon
VertexStartPointers = 0x1201B004, VertexStartPointers = 0x1201B004,
ModelTransform = 0x1301B001, //Matrix4x4. 0x40 in size ModelTransform = 0x1301B001, //Matrix4x4. 0x40 in size
MeshBuffers = 0x1301B005, //vertex and index buffer MeshBuffers = 0x1301B005, //vertex and index buffer
BoneData = 0x1201B102,
MaterialName = 0x1201B333, MaterialName = 0x1201B333,
MeshIndexTable = 0x1201B007, MeshIndexTable = 0x1201B007,
MessageData = 0x12027020, MessageData = 0x12027020,

View File

@ -68,6 +68,8 @@ namespace FirstPlugin.LuigisMansion.DarkMoon
public List<LM2_Mesh> Meshes = new List<LM2_Mesh>(); public List<LM2_Mesh> Meshes = new List<LM2_Mesh>();
public List<uint> VertexBufferPointers = new List<uint>(); public List<uint> VertexBufferPointers = new List<uint>();
public STSkeleton Skeleton;
public uint BufferStart; public uint BufferStart;
public uint BufferSize; public uint BufferSize;

View File

@ -44,7 +44,7 @@ namespace FirstPlugin.LuigisMansion3
//Load the first chunk table //Load the first chunk table
//These point to sections which usually have magic and a hash //These point to sections which usually have magic and a hash
//The chunk table afterwards contains the data itself //The chunk table afterwards contains the data itself
while (tableReader.ReadUInt16() == ChunkInfoIdenfier) while (!tableReader.EndOfStream && tableReader.ReadUInt16() == ChunkInfoIdenfier)
{ {
tableReader.ReadUInt16(); tableReader.ReadUInt16();
@ -62,8 +62,6 @@ namespace FirstPlugin.LuigisMansion3
//This increases by 2 each chunk info, however the starting value is not 0 //This increases by 2 each chunk info, however the starting value is not 0
//Note the last entry does not have this //Note the last entry does not have this
entry.Unknown3 = tableReader.ReadUInt32(); entry.Unknown3 = tableReader.ReadUInt32();
Console.WriteLine("ChunkOffset " + entry.ChunkOffset);
} }
if (ChunkEntries.Count > 0) if (ChunkEntries.Count > 0)

View File

@ -272,14 +272,16 @@ namespace FirstPlugin.LuigisMansion3
currentTexture.Index = ImageHeaderIndex; currentTexture.Index = ImageHeaderIndex;
currentTexture.Read(textureReader); currentTexture.Read(textureReader);
if (DebugMode) if (DebugMode)
currentTexture.Text = $"Texture {ImageHeaderIndex} {currentTexture.TexFormat.ToString("X")} {currentTexture.Unknown.ToString("X")}"; currentTexture.Text = $"Texture {ImageHeaderIndex} {currentTexture.Unknown} {currentTexture.Unknown2} {currentTexture.Unknown3.ToString("X")}";
else else
currentTexture.Text = $"Texture {currentTexture.ID2.ToString("X")}"; currentTexture.Text = $"Texture {currentTexture.ID2.ToString("X")}";
if (HashNames.ContainsKey(currentTexture.ID2)) if (HashNames.ContainsKey(currentTexture.ID2))
currentTexture.Text = HashNames[currentTexture.ID2]; currentTexture.Text = HashNames[currentTexture.ID2];
textureFolder.Nodes.Add(currentTexture); textureFolder.Nodes.Add(currentTexture);
Renderer.TextureList.Add(currentTexture); if (!Renderer.TextureList.ContainsKey(currentTexture.ID2.ToString("x")))
Renderer.TextureList.Add(currentTexture.ID2.ToString("x"), currentTexture);
TextureHashes.Add(currentTexture.ID2); TextureHashes.Add(currentTexture.ID2);
@ -360,7 +362,7 @@ namespace FirstPlugin.LuigisMansion3
case SubDataType.BoneData: case SubDataType.BoneData:
if (chunk.ChunkSize > 0x40 && currentModel.Skeleton == null) if (chunk.ChunkSize > 0x40 && currentModel.Skeleton == null)
{ {
/* chunkEntry.DataFile = File052Data; chunkEntry.DataFile = File052Data;
using (var boneReader = new FileReader(chunkEntry.FileData)) using (var boneReader = new FileReader(chunkEntry.FileData))
{ {
currentModel.Skeleton = new STSkeleton(); currentModel.Skeleton = new STSkeleton();
@ -389,7 +391,7 @@ namespace FirstPlugin.LuigisMansion3
currentModel.Skeleton.reset(); currentModel.Skeleton.reset();
currentModel.Skeleton.update(); currentModel.Skeleton.update();
}*/ }
} }
break; break;
case (SubDataType)0x5012: case (SubDataType)0x5012:
@ -421,7 +423,7 @@ namespace FirstPlugin.LuigisMansion3
foreach (var model in modelFolder.Nodes) foreach (var model in modelFolder.Nodes)
{ {
((LM3_Model)currentModel).ModelInfo.Read(new FileReader( ((LM3_Model)currentModel).ModelInfo.Read(new FileReader(
currentModel.ModelInfo.Data), currentModel.Meshes, TextureHashes); currentModel.ModelInfo.Data), currentModel, currentModel.Meshes, TextureHashes);
} }
if (havokFolder.Nodes.Count > 0) if (havokFolder.Nodes.Count > 0)
@ -532,7 +534,7 @@ namespace FirstPlugin.LuigisMansion3
{ {
if (Entry.ChunkSize == 0) if (Entry.ChunkSize == 0)
return new System.IO.MemoryStream(); return new System.IO.MemoryStream();
else if (Entry.ChunkOffset + Entry.ChunkSize < DataFile?.Length) else if (Entry.ChunkOffset + Entry.ChunkSize <= DataFile?.Length)
return new SubStream(DataFile, Entry.ChunkOffset, Entry.ChunkSize); return new SubStream(DataFile, Entry.ChunkOffset, Entry.ChunkSize);
else else
return new System.IO.MemoryStream(); return new System.IO.MemoryStream();
@ -670,7 +672,7 @@ namespace FirstPlugin.LuigisMansion3
} }
else if (DecompressedSize == 0) else if (DecompressedSize == 0)
return new System.IO.MemoryStream(); return new System.IO.MemoryStream();
else if (Offset + DecompressedSize < reader.BaseStream.Length) else if (Offset + DecompressedSize <= reader.BaseStream.Length)
return new SubStream(reader.BaseStream, Offset, DecompressedSize); return new SubStream(reader.BaseStream, Offset, DecompressedSize);
} }
} }

View File

@ -24,8 +24,6 @@ namespace FirstPlugin.LuigisMansion3
public enum IndexFormat : ushort public enum IndexFormat : ushort
{ {
Index_16 = 0x0, Index_16 = 0x0,
Index_32 = 0x1,
Index_32_ = 0x2,
Index_8 = 0x8000, Index_8 = 0x8000,
} }

View File

@ -63,6 +63,8 @@ namespace FirstPlugin.LuigisMansion3
public class LM3_Model : TreeNodeCustom, IContextMenuNode public class LM3_Model : TreeNodeCustom, IContextMenuNode
{ {
public List<uint> TextureHashes = new List<uint>();
public LM3_DICT DataDictionary; public LM3_DICT DataDictionary;
public LM3_ModelInfo ModelInfo; public LM3_ModelInfo ModelInfo;
public List<LM3_Mesh> Meshes = new List<LM3_Mesh>(); public List<LM3_Mesh> Meshes = new List<LM3_Mesh>();
@ -211,6 +213,24 @@ namespace FirstPlugin.LuigisMansion3
using (var reader = new FileReader(DataDictionary.GetFileBufferData())) using (var reader = new FileReader(DataDictionary.GetFileBufferData()))
{ {
TreeNode texturesList = new TreeNode("Texture Maps");
for (int t = 0; t < TextureHashes.Count; t++)
{
if (DataDictionary.Renderer.TextureList.ContainsKey(TextureHashes[t].ToString("x")))
{
var tex = DataDictionary.Renderer.TextureList[TextureHashes[t].ToString("x")];
texturesList.Nodes.Add(new TreeNode(tex.Text)
{
ImageKey = tex.ImageKey,
SelectedImageKey = tex.ImageKey,
Tag = tex
});
}
}
if (texturesList.Nodes.Count > 0)
Nodes.Add(texturesList);
for (int i = 0; i < Meshes.Count; i++) for (int i = 0; i < Meshes.Count; i++)
{ {
LM3_Mesh mesh = Meshes[i]; LM3_Mesh mesh = Meshes[i];
@ -226,6 +246,7 @@ namespace FirstPlugin.LuigisMansion3
RenderedMeshes.Add(genericObj); RenderedMeshes.Add(genericObj);
Nodes.Add(genericObj); Nodes.Add(genericObj);
DataDictionary.Renderer.Meshes.Add(genericObj); DataDictionary.Renderer.Meshes.Add(genericObj);
STGenericPolygonGroup polyGroup = new STGenericPolygonGroup(); STGenericPolygonGroup polyGroup = new STGenericPolygonGroup();
@ -265,10 +286,10 @@ namespace FirstPlugin.LuigisMansion3
for (int f = 0; f < mesh.IndexCount; f++) for (int f = 0; f < mesh.IndexCount; f++)
polyGroup.faces.Add(reader.ReadUInt16()); polyGroup.faces.Add(reader.ReadUInt16());
break; break;
case IndexFormat.Index_32: /* case IndexFormat.Index_32:
for (int f = 0; f < mesh.IndexCount; f++) for (int f = 0; f < mesh.IndexCount; f++)
polyGroup.faces.Add((int)reader.ReadUInt32()); polyGroup.faces.Add((int)reader.ReadUInt32());
break; break;*/
} }
Console.WriteLine($"Mesh {genericObj.Text} Format {formatInfo.Format} BufferLength {formatInfo.BufferLength}"); Console.WriteLine($"Mesh {genericObj.Text} Format {formatInfo.Format} BufferLength {formatInfo.BufferLength}");
@ -407,43 +428,43 @@ namespace FirstPlugin.LuigisMansion3
{ {
public byte[] Data; public byte[] Data;
public void Read(FileReader reader, List<LM3_Mesh> Meshes, List<uint> Hashes) public void Read(FileReader reader, LM3_Model model, List<LM3_Mesh> Meshes, List<uint> Hashes)
{ {
List<uint> ModelTexHashes = new List<uint>(); uint meshSize = (uint)(reader.BaseStream.Length / Meshes.Count);
//Read entire section till i find a matching texture hash
while (!reader.EndOfStream && reader.Position < reader.BaseStream.Length - 4) while (!reader.EndOfStream && reader.Position < reader.BaseStream.Length - 4)
{ {
uint HashIDCheck = reader.ReadUInt32(); uint HashIDCheck = reader.ReadUInt32();
if (Hashes.Contains(HashIDCheck)) if (Hashes.Contains(HashIDCheck))
{ {
using (reader.TemporarySeek(8, System.IO.SeekOrigin.Current)) if (!model.TextureHashes.Contains(HashIDCheck))
model.TextureHashes.Add(HashIDCheck);
}
}
/* for (int i = 0; i < Meshes.Count; i++)
{
reader.SeekBegin(i * meshSize);
while (!reader.EndOfStream && reader.Position < reader.BaseStream.Length - 4)
{
uint HashIDCheck = reader.ReadUInt32();
if (Hashes.Contains(HashIDCheck))
{ {
uint unk = reader.ReadUInt32(); Console.WriteLine("HashCheck " + HashIDCheck);
if (unk == 0xF880BD9F) Meshes[i].Material = new LM3_Material();
var texUnit = 1;
Meshes[i].Material.TextureMaps.Add(new STGenericMatTexture()
{ {
ModelTexHashes.Add(HashIDCheck); textureUnit = texUnit++,
} Type = STGenericMatTexture.TextureType.Diffuse,
Name = HashIDCheck.ToString("x"),
});
break;
} }
} }
} }*/
for (int i = 0; i < Meshes.Count; i++)
{
if (ModelTexHashes.Count > i)
{
uint TextureHashID = ModelTexHashes[i];
Meshes[i].Material = new LM3_Material();
var texUnit = 1;
Meshes[i].Material.TextureMaps.Add(new STGenericMatTexture()
{
textureUnit = texUnit++,
Type = STGenericMatTexture.TextureType.Diffuse,
Name = TextureHashID.ToString("x"),
});
}
}
} }
} }
@ -570,6 +591,9 @@ namespace FirstPlugin.LuigisMansion3
IndexStartOffset = reader.ReadUInt32(); IndexStartOffset = reader.ReadUInt32();
IndexCount = reader.ReadUInt16(); IndexCount = reader.ReadUInt16();
IndexFormat = reader.ReadEnum<IndexFormat>(false); IndexFormat = reader.ReadEnum<IndexFormat>(false);
if (IndexFormat != (IndexFormat)0x8000 && IndexFormat != 0)
IndexFormat = IndexFormat.Index_16;
VertexCount = reader.ReadUInt32(); VertexCount = reader.ReadUInt32();
reader.ReadUInt32(); //unknown reader.ReadUInt32(); //unknown
BufferPtrOffset = reader.ReadUInt16(); //I believe this might be for the buffer pointers. It shifts by 4 for each mesh BufferPtrOffset = reader.ReadUInt16(); //I believe this might be for the buffer pointers. It shifts by 4 for each mesh

View File

@ -101,7 +101,7 @@ namespace FirstPlugin.LuigisMansion3
Console.WriteLine("Unknown Format!" + TexFormat.ToString("X")); Console.WriteLine("Unknown Format!" + TexFormat.ToString("X"));
} }
MipCount = 1; MipCount = numMips;
ArrayCount = numArray; ArrayCount = numArray;
properties = new POWEProperties(); properties = new POWEProperties();

View File

@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace FirstPlugin.PunchOutWii
{
public class PO_DICT
{
}
}

View File

@ -14,7 +14,7 @@ namespace FirstPlugin.LuigisMansion3
{ {
public class LM3_Renderer : GenericModelRenderer public class LM3_Renderer : GenericModelRenderer
{ {
public List<TexturePOWE> TextureList = new List<TexturePOWE>(); public Dictionary<string, TexturePOWE> TextureList = new Dictionary<string, TexturePOWE>();
public override void OnRender(GLControl control) public override void OnRender(GLControl control)
{ {
@ -27,12 +27,11 @@ namespace FirstPlugin.LuigisMansion3
GL.BindTexture(TextureTarget.Texture2D, RenderTools.defaultTex.RenderableTex.TexID); GL.BindTexture(TextureTarget.Texture2D, RenderTools.defaultTex.RenderableTex.TexID);
string activeTex = tex.Name; string activeTex = tex.Name;
foreach (var texture in TextureList) foreach (var texture in TextureList)
{ {
if (texture.ID2.ToString("x") == tex.Name) if (TextureList.ContainsKey(tex.Name))
{ {
BindGLTexture(tex, shader, texture); BindGLTexture(tex, shader, TextureList[tex.Name]);
return tex.textureUnit + 1; return tex.textureUnit + 1;
} }
} }

View File

@ -222,6 +222,9 @@ namespace Toolbox.Library.Forms
((TreeNodeCustom)node).OnClick(treeViewCustom1); ((TreeNodeCustom)node).OnClick(treeViewCustom1);
} }
if (node.Tag != null && node.Tag is TreeNodeCustom)
((TreeNodeCustom)node.Tag).OnClick(treeViewCustom1);
//Check if it is renderable for updating the viewport //Check if it is renderable for updating the viewport
if (IsRenderable(node)) if (IsRenderable(node))
{ {