Skip to content

Commit

Permalink
support DAT 3D model files of other type (used by the game "Creation")
Browse files Browse the repository at this point in the history
  • Loading branch information
movAX13h committed Feb 12, 2023
1 parent 21a85c8 commit 2b51524
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions ObjectsConverter/ObjectDatFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ private static ObjectDatFile loadFromFile(string filename, ObjectDatFile file)
return file;
}

bool isAnimation = false;
byte[] bytes = File.ReadAllBytes(filename);

#region validate header
Expand Down Expand Up @@ -131,12 +132,13 @@ private static ObjectDatFile loadFromFile(string filename, ObjectDatFile file)
#endregion

#region 2 constants (05 and 01, same in all object files)
file.Error = "Constant 1 did not match!";
if (bytes[offset] != 5) return file;
file.Error = "Constant 1 is " + bytes[offset] + ", not 5 or 7!";
if (bytes[offset] != 5 && bytes[offset] != 7) return file;
if (bytes[offset] == 7) isAnimation = true;
offset++;

file.Error = "Constant 2 did not match!";
if (bytes[offset] != 1) return file;
file.Error = "Constant 2 is " + bytes[offset] + ", not 1, 4 or 20!";
if (bytes[offset] != 1 && bytes[offset] != 4 && bytes[offset] != 20) return file;
offset++;
#endregion

Expand Down Expand Up @@ -172,6 +174,15 @@ private static ObjectDatFile loadFromFile(string filename, ObjectDatFile file)
for(int i = 0; i < numTriangles; i++)
{
byte type = bytes[offset];

// Animations have some zeros before actual triangle data.
// I couldn't find a regularity in the number of bytes used.
while (isAnimation && type == 0)
{
offset++;
type = bytes[offset];
}

if (type != 5 && type != 4)
{
file.Error = "Triangle #" + (i+1) + "has unknown type " + type;
Expand Down

0 comments on commit 2b51524

Please sign in to comment.