Skip to content

Commit

Permalink
Add Normal and Color support to TMF meshes
Browse files Browse the repository at this point in the history
  • Loading branch information
BigBang1112 committed Dec 30, 2024
1 parent 61ad2aa commit 214a150
Showing 1 changed file with 21 additions and 23 deletions.
44 changes: 21 additions & 23 deletions Src/GBX.NET/Engines/Plug/CPlugVisual3D.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,37 +115,34 @@ private static void WriteTangents(GbxWriter w, int tangentsCount, byte[]? tangen
}
}

public readonly record struct Vertex(Vec3 Position, Vec3? Normal, Vec3? U02, float? U03, int? U04, Vec3? U05, int? U06, Vec4? U07, float? U08, int? U09)
public readonly record struct Vertex(Vec3 Position, Vec3? Normal, Vec3? U02, float? U03, Vec4? Color, float? U08, int? U09)
{
public static Vertex Read(GbxReader r, bool u01, bool u02, bool u03, bool u04, bool isSprite)
{
var pos = r.ReadVec3();
var vertU01 = default(int?);
var vertU02 = default(Vec3?);
var vertU03 = default(int?);
var vertU04 = default(Vec4?);
var normal = default(Vec3?);
var color = default(Vec4?);

if (u01)
{
if (u03)
{
vertU01 = r.ReadInt32();
}
else
{
vertU02 = r.ReadVec3();
}
normal = u03 ? r.ReadVec3_10b() : r.ReadVec3();
}

if (u02)
{
if (u04)
{
vertU03 = r.ReadInt32();
var colorInt = r.ReadInt32();
color = new Vec4(
(colorInt >> 0x10 & 0xFF) / 255f,
(colorInt >> 8 & 0xFF) / 255f,
(colorInt & 0xFF) / 255f,
(colorInt >> 0x18 & 0xFF) / 255f
);
}
else
{
vertU04 = r.ReadVec4();
color = r.ReadVec4();
}
}

Expand All @@ -161,10 +158,8 @@ public static Vertex Read(GbxReader r, bool u01, bool u02, bool u03, bool u04, b
return new Vertex
{
Position = pos,
U04 = vertU01,
U05 = vertU02,
U06 = vertU03,
U07 = vertU04,
Normal = normal,
Color = color,
U08 = vertU05,
U09 = vertU06,
};
Expand All @@ -178,23 +173,26 @@ public void Write(GbxWriter w, bool u01, bool u02, bool u03, bool u04, bool isSp
{
if (u03)
{
w.Write(U04.GetValueOrDefault());
w.WriteVec3_10b(Normal.GetValueOrDefault());
}
else
{
w.Write(U05.GetValueOrDefault());
w.Write(Normal.GetValueOrDefault());
}
}

if (u02)
{
if (u04)
{
w.Write(U06.GetValueOrDefault());
w.Write((int)(Color.GetValueOrDefault().X * 255) << 0x10
| (int)(Color.GetValueOrDefault().Y * 255) << 8
| (int)(Color.GetValueOrDefault().Z * 255)
| (int)(Color.GetValueOrDefault().W * 255) << 0x18);
}
else
{
w.Write(U07.GetValueOrDefault());
w.Write(Color.GetValueOrDefault());
}
}

Expand Down

0 comments on commit 214a150

Please sign in to comment.