Skip to content

Commit

Permalink
From 9f2b77fa42ad27d56de76346101df1ac6ee04b97 Mon Sep 17 00:00:00 2001
Browse files Browse the repository at this point in the history
From: Andrey Nazarov <[email protected]>
Date: Tue, 31 Aug 2021 10:23:34 +0300
Subject: [PATCH 362/396] Calculate MD3 model bounds on load.

Fixes NVIDIA#211.
  • Loading branch information
Paril committed Dec 10, 2021
1 parent 5461369 commit 2180271
Showing 1 changed file with 20 additions and 5 deletions.
25 changes: 20 additions & 5 deletions src/refresh/vkpt/models.c
Original file line number Diff line number Diff line change
Expand Up @@ -554,6 +554,7 @@ static int MOD_LoadMD3Mesh(model_t *model, maliasmesh_t *mesh,
dst_tc = mesh->tex_coords;
for (int frame = 0; frame < header.num_frames; frame++)
{
maliasframe_t *f = &model->frames[frame];
src_tc = (dmd3coord_t *)(rawdata + header.ofs_tcs);

for (i = 0; i < header.num_verts; i++)
Expand All @@ -574,6 +575,11 @@ static int MOD_LoadMD3Mesh(model_t *model, maliasmesh_t *mesh,
(*dst_tc)[0] = LittleFloat(src_tc->st[0]);
(*dst_tc)[1] = LittleFloat(src_tc->st[1]);

for (int k = 0; k < 3; k++) {
f->bounds[0][k] = min(f->bounds[0][k], (*dst_vert)[k]);
f->bounds[1][k] = max(f->bounds[1][k], (*dst_vert)[k]);
}

src_vert++; dst_vert++; dst_norm++;
src_tc++; dst_tc++;
}
Expand Down Expand Up @@ -651,9 +657,7 @@ int MOD_LoadMD3_RTX(model_t *model, const void *rawdata, size_t length, const ch
LittleVector(src_frame->translate, dst_frame->translate);
VectorSet(dst_frame->scale, MD3_XYZ_SCALE, MD3_XYZ_SCALE, MD3_XYZ_SCALE);

LittleVector(src_frame->mins, dst_frame->bounds[0]);
LittleVector(src_frame->maxs, dst_frame->bounds[1]);
dst_frame->radius = LittleFloat(src_frame->radius);
ClearBounds(dst_frame->bounds[0], dst_frame->bounds[1]);

src_frame++; dst_frame++;
}
Expand All @@ -669,8 +673,19 @@ int MOD_LoadMD3_RTX(model_t *model, const void *rawdata, size_t length, const ch
remaining -= offset;
}

//if (strstr(model->name, "v_blast"))
// export_obj_frames(model, "export/v_blast_%d.obj");
// calculate frame bounds
dst_frame = model->frames;
for (i = 0; i < header.num_frames; i++) {
VectorScale(dst_frame->bounds[0], MD3_XYZ_SCALE, dst_frame->bounds[0]);
VectorScale(dst_frame->bounds[1], MD3_XYZ_SCALE, dst_frame->bounds[1]);

dst_frame->radius = RadiusFromBounds(dst_frame->bounds[0], dst_frame->bounds[1]);

VectorAdd(dst_frame->bounds[0], dst_frame->translate, dst_frame->bounds[0]);
VectorAdd(dst_frame->bounds[1], dst_frame->translate, dst_frame->bounds[1]);

dst_frame++;
}

extract_model_lights(model);

Expand Down

0 comments on commit 2180271

Please sign in to comment.