diff --git a/src/Parsec/Shaiya/Dg/Dg.cs b/src/Parsec/Shaiya/Dg/Dg.cs index be15f25..8c16e6c 100644 --- a/src/Parsec/Shaiya/Dg/Dg.cs +++ b/src/Parsec/Shaiya/Dg/Dg.cs @@ -13,7 +13,7 @@ public class Dg : FileBase public int UnknownInt32 { get; set; } - public List Nodes { get; set; } = new(); + public List Nodes { get; set; } = new(); public override string Extension => "dg"; @@ -25,6 +25,11 @@ protected override void Read(SBinaryReader binaryReader) while (true) { + if (binaryReader.Position == binaryReader.StreamLength) + { + break; + } + // When value is 1, node data follows, otherwise node reading must be skipped var value = binaryReader.ReadInt32(); @@ -33,10 +38,9 @@ protected override void Read(SBinaryReader binaryReader) var node = binaryReader.Read(); Nodes.Add(node); } - - if (binaryReader.Position == binaryReader.StreamLength) + else { - break; + Nodes.Add(null); } } } @@ -49,6 +53,12 @@ protected override void Write(SBinaryWriter binaryWriter) foreach (var node in Nodes) { + if (node == null) + { + binaryWriter.Write(0); + continue; + } + binaryWriter.Write(1); binaryWriter.Write(node); } diff --git a/src/Parsec/Shaiya/Dg/DgMesh.cs b/src/Parsec/Shaiya/Dg/DgMesh.cs index 85b3318..c5bde92 100644 --- a/src/Parsec/Shaiya/Dg/DgMesh.cs +++ b/src/Parsec/Shaiya/Dg/DgMesh.cs @@ -9,14 +9,14 @@ public class DgMesh : ISerializable { public AlphaBlendingMode AlphaBlendingMode { get; set; } - public List Vertices { get; set; } = new(); + public List Vertices { get; set; } = new(); public List Faces { get; set; } = new(); public void Read(SBinaryReader binaryReader) { AlphaBlendingMode = (AlphaBlendingMode)binaryReader.ReadInt32(); - Vertices = binaryReader.ReadList().ToList(); + Vertices = binaryReader.ReadList().ToList(); Faces = binaryReader.ReadList().ToList(); } diff --git a/src/Parsec/Shaiya/Dg/DgSegmentVertex.cs b/src/Parsec/Shaiya/Dg/DgMeshVertex.cs similarity index 70% rename from src/Parsec/Shaiya/Dg/DgSegmentVertex.cs rename to src/Parsec/Shaiya/Dg/DgMeshVertex.cs index f7f1015..cc2d82b 100644 --- a/src/Parsec/Shaiya/Dg/DgSegmentVertex.cs +++ b/src/Parsec/Shaiya/Dg/DgMeshVertex.cs @@ -4,7 +4,7 @@ namespace Parsec.Shaiya.Dg; -public class DgSegmentVertex : ISerializable +public class DgMeshVertex : ISerializable { /// /// Vertex coordinates in the 3D space @@ -24,20 +24,20 @@ public class DgSegmentVertex : ISerializable /// /// Texture mapping /// - public Vector2 UV { get; set; } + public Vector2 TextureUV { get; set; } - public float Unknown1 { get; set; } - - public float Unknown2 { get; set; } + /// + /// Lightmap mapping + /// + public Vector2 LightmapUV { get; set; } public void Read(SBinaryReader binaryReader) { Coordinates = binaryReader.Read(); Normal = binaryReader.Read(); BoneId = binaryReader.ReadInt32(); - UV = binaryReader.Read(); - Unknown1 = binaryReader.ReadSingle(); - Unknown2 = binaryReader.ReadSingle(); + TextureUV = binaryReader.Read(); + LightmapUV = binaryReader.Read(); } public void Write(SBinaryWriter binaryWriter) @@ -45,8 +45,7 @@ public void Write(SBinaryWriter binaryWriter) binaryWriter.Write(Coordinates); binaryWriter.Write(Normal); binaryWriter.Write(BoneId); - binaryWriter.Write(UV); - binaryWriter.Write(Unknown1); - binaryWriter.Write(Unknown2); + binaryWriter.Write(TextureUV); + binaryWriter.Write(LightmapUV); } }