Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions src/Parsec/Shaiya/3dc/_3dc.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ namespace Parsec.Shaiya._3dc;
/// </summary>
public sealed class _3dc : FileBase
{
/// <summary>
/// Some mob files store TGA name.
/// </summary>
public string Icon { get; set; } = "";

/// <summary>
/// List of bones linked to this 3d model. Although a model might be linked to a few bones (for example boots models), the
/// 3DC file contains the definitions for all the bones in the whole skeleton.
Expand All @@ -30,22 +35,26 @@ public sealed class _3dc : FileBase
/// </summary>
public List<MeshFace> Faces { get; set; } = new();

private const int Ep6Flag = 444;

[JsonIgnore]
public override string Extension => "3DC";

protected override void Read(SBinaryReader binaryReader)
{
var version = binaryReader.ReadInt32();
var versionOrTGALength = binaryReader.ReadInt32();
Episode = Episode.EP5;

if (version == 444)
if (versionOrTGALength == Ep6Flag)
{
Episode = Episode.EP6;
}

// Vertex instances expect the episode to be set on the serialization options
binaryReader.SerializationOptions.Episode = Episode;

if (versionOrTGALength > 0 && versionOrTGALength != Ep6Flag)
Icon = binaryReader.ReadString(versionOrTGALength);
Bones = binaryReader.ReadList<_3dcBone>().ToList();
Vertices = binaryReader.ReadList<_3dcVertex>().ToList();
Faces = binaryReader.ReadList<MeshFace>().ToList();
Expand All @@ -57,13 +66,16 @@ protected override void Write(SBinaryWriter binaryWriter)

if (Episode >= Episode.EP6)
{
version = 444;
version = Ep6Flag;
}

// Vertex instances expect the episode to be set on the serialization options
binaryWriter.SerializationOptions.Episode = Episode;

binaryWriter.Write(version);
if (string.IsNullOrEmpty(Icon) || version == Ep6Flag)
binaryWriter.Write(version);
else
binaryWriter.Write(Icon);
binaryWriter.Write(Bones.ToSerializable());
binaryWriter.Write(Vertices.ToSerializable());
binaryWriter.Write(Faces.ToSerializable());
Expand Down
3 changes: 3 additions & 0 deletions tests/Parsec.Tests/Parsec.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
</ItemGroup>

<ItemGroup>
<None Update="Shaiya\3DC\mob_rend_01_a.3DC">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="Shaiya\EFT\Monster.EFT">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
Expand Down
1 change: 1 addition & 0 deletions tests/Parsec.Tests/Shaiya/3DC/_3DCTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ public void _3DCReadWriteEP6Test()
[InlineData("vehicle_El_06.3DC")]
[InlineData("WhiteWing.3DC")]
[InlineData("Wing_01.3DC")]
[InlineData("mob_rend_01_a.3dc")]
public void _3DCMultipleReadWriteTest(string fileName)
{
var filePath = $"Shaiya/3DC/{fileName}";
Expand Down
Binary file added tests/Parsec.Tests/Shaiya/3DC/mob_rend_01_a.3dc
Binary file not shown.
Loading