Skip to content

Commit

Permalink
feat(Dg): add LightmapUV
Browse files Browse the repository at this point in the history
  • Loading branch information
matigramirez committed Dec 19, 2023
1 parent 28fa0e9 commit 26519d5
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 17 deletions.
18 changes: 14 additions & 4 deletions src/Parsec/Shaiya/Dg/Dg.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class Dg : FileBase

public int UnknownInt32 { get; set; }

public List<DgNode> Nodes { get; set; } = new();
public List<DgNode?> Nodes { get; set; } = new();

public override string Extension => "dg";

Expand All @@ -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();

Expand All @@ -33,10 +38,9 @@ protected override void Read(SBinaryReader binaryReader)
var node = binaryReader.Read<DgNode>();
Nodes.Add(node);
}

if (binaryReader.Position == binaryReader.StreamLength)
else
{
break;
Nodes.Add(null);
}
}
}
Expand All @@ -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);
}
Expand Down
4 changes: 2 additions & 2 deletions src/Parsec/Shaiya/Dg/DgMesh.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ public class DgMesh : ISerializable
{
public AlphaBlendingMode AlphaBlendingMode { get; set; }

public List<DgSegmentVertex> Vertices { get; set; } = new();
public List<DgMeshVertex> Vertices { get; set; } = new();

public List<MeshFace> Faces { get; set; } = new();

public void Read(SBinaryReader binaryReader)
{
AlphaBlendingMode = (AlphaBlendingMode)binaryReader.ReadInt32();
Vertices = binaryReader.ReadList<DgSegmentVertex>().ToList();
Vertices = binaryReader.ReadList<DgMeshVertex>().ToList();
Faces = binaryReader.ReadList<MeshFace>().ToList();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Parsec.Shaiya.Dg;

public class DgSegmentVertex : ISerializable
public class DgMeshVertex : ISerializable
{
/// <summary>
/// Vertex coordinates in the 3D space
Expand All @@ -24,29 +24,28 @@ public class DgSegmentVertex : ISerializable
/// <summary>
/// Texture mapping
/// </summary>
public Vector2 UV { get; set; }
public Vector2 TextureUV { get; set; }

public float Unknown1 { get; set; }

public float Unknown2 { get; set; }
/// <summary>
/// Lightmap mapping
/// </summary>
public Vector2 LightmapUV { get; set; }

public void Read(SBinaryReader binaryReader)
{
Coordinates = binaryReader.Read<Vector3>();
Normal = binaryReader.Read<Vector3>();
BoneId = binaryReader.ReadInt32();
UV = binaryReader.Read<Vector2>();
Unknown1 = binaryReader.ReadSingle();
Unknown2 = binaryReader.ReadSingle();
TextureUV = binaryReader.Read<Vector2>();
LightmapUV = binaryReader.Read<Vector2>();
}

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);
}
}

0 comments on commit 26519d5

Please sign in to comment.