Skip to content

Commit

Permalink
Remove support for MD3 model version 2038
Browse files Browse the repository at this point in the history
This was a non-standard extension to the MD3 format. Revert this comment to re-enable support.
  • Loading branch information
Lactozilla committed Mar 12, 2024
1 parent e627a0a commit 44d092a
Showing 1 changed file with 13 additions and 26 deletions.
39 changes: 13 additions & 26 deletions source/Engine/ResourceTypes/ModelFormats/MD3Model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
class MD3Model {
public:
static Sint32 Version;
static bool UseUVKeyframes;
static Sint32 DataEndOffset;
static vector<string> MaterialNames;
};
Expand All @@ -19,8 +18,7 @@ class MD3Model {

#define MD3_MODEL_MAGIC 0x49445033 // IDP3

#define MD3_BASE_VERSION 15
#define MD3_EXTRA_VERSION 2038
#define MD3_VERSION 15

#define MD3_XYZ_SCALE (1.0 / 64)

Expand All @@ -31,7 +29,6 @@ class MD3Model {
#define MAX_QPATH 64

Sint32 MD3Model::Version;
bool MD3Model::UseUVKeyframes;
Sint32 MD3Model::DataEndOffset;
vector<string> MD3Model::MaterialNames;

Expand Down Expand Up @@ -165,24 +162,16 @@ PUBLIC STATIC Mesh* MD3Model::ReadSurface(IModel* model, Stream* stream, size_t

stream->Seek(surfaceDataOffset + stDataOffset);

if (UseUVKeyframes) {
for (Sint32 i = 0; i < frameCount; i++) {
ReadUVs(uv, vertexCount, stream);
uv += vertexCount;
}
}
else {
ReadUVs(uv, vertexCount, stream);

// Copy the values to other frames
for (Sint32 i = 0; i < vertexCount; i++) {
Vector2* uvA = &mesh->UVBuffer[i];

for (Sint32 j = 1; j < frameCount; j++) {
Vector2* uvB = &mesh->UVBuffer[i + (vertexCount * j)];
uvB->X = uvA->X;
uvB->Y = uvA->X;
}
ReadUVs(uv, vertexCount, stream);

// Copy the values to other frames
for (Sint32 i = 0; i < vertexCount; i++) {
Vector2* uvA = &mesh->UVBuffer[i];

for (Sint32 j = 1; j < frameCount; j++) {
Vector2* uvB = &mesh->UVBuffer[i + (vertexCount * j)];
uvB->X = uvA->X;
uvB->Y = uvA->X;
}
}

Expand Down Expand Up @@ -220,13 +209,11 @@ PUBLIC STATIC bool MD3Model::Convert(IModel* model, Stream* stream, const char*

Version = stream->ReadInt32();

if (Version != MD3_BASE_VERSION && Version != MD3_EXTRA_VERSION) {
Log::Print(Log::LOG_ERROR, "Unknown MD3 model version!");
if (Version != MD3_VERSION) {
Log::Print(Log::LOG_ERROR, "Unsupported MD3 model version!");
return false;
}

UseUVKeyframes = Version == MD3_EXTRA_VERSION;

char name[MAX_QPATH + 1];
memset(name, '\0', sizeof name);
stream->ReadBytes(name, MAX_QPATH);
Expand Down

0 comments on commit 44d092a

Please sign in to comment.