From d3bf7368c42b32bc8dbd6c2ef83ad0c4913d02ed Mon Sep 17 00:00:00 2001 From: Denis Pauk Date: Wed, 5 Jun 2024 22:59:46 +0300 Subject: [PATCH] models: add models normal fix If model has only zero notmal, update model with normal recalculate. --- src/client/refresh/files/mesh.c | 2 +- src/client/refresh/files/models.c | 21 +++++++++++++++++++-- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/src/client/refresh/files/mesh.c b/src/client/refresh/files/mesh.c index 9f59da0e..e0a7eae0 100644 --- a/src/client/refresh/files/mesh.c +++ b/src/client/refresh/files/mesh.c @@ -83,7 +83,7 @@ R_ConvertNormalMDL(byte in_normal, signed char *normal) const float *norm; int n; - norm = r_avertexnormals[in_normal]; + norm = r_avertexnormals[in_normal % NUMVERTEXNORMALS]; for (n = 0; n < 3; n ++) { diff --git a/src/client/refresh/files/models.c b/src/client/refresh/files/models.c index b0cd3b56..32225314 100644 --- a/src/client/refresh/files/models.c +++ b/src/client/refresh/files/models.c @@ -129,9 +129,10 @@ Mod_LoadFrames Load the Quake2 md2 default format frames ================= */ -static void +static qboolean Mod_LoadFrames_MD2(dmdx_t *pheader, byte *src, size_t inframesize, vec3_t translate) { + qboolean normalfix = true; int i; for (i=0 ; i < pheader->num_frames ; i++) @@ -156,10 +157,19 @@ Mod_LoadFrames_MD2(dmdx_t *pheader, byte *src, size_t inframesize, vec3_t transl for (j=0; j < pheader->num_xyz; j ++) { Mod_LoadFrames_VertMD2(poutframe->verts + j, pinframe->verts[j].v); + + if (pinframe->verts[j].lightnormalindex) + { + /* normal is set? */ + normalfix = false; + } + R_ConvertNormalMDL(pinframe->verts[j].lightnormalindex, poutframe->verts[j].normal); } } + + return normalfix; } /* @@ -1847,6 +1857,7 @@ Mod_LoadModel_MD2(const char *mod_name, const void *buffer, int modfilelen, const dtriangle_t *pintri; dmdxmesh_t *mesh_nodes; const dstvert_t *pinst; + qboolean normalfix; const int *pincmd; dmdl_t pinmodel; dmdx_t *pheader; @@ -1988,7 +1999,7 @@ Mod_LoadModel_MD2(const char *mod_name, const void *buffer, int modfilelen, // // load the frames // - Mod_LoadFrames_MD2(pheader, (byte *)buffer + pinmodel.ofs_frames, + normalfix = Mod_LoadFrames_MD2(pheader, (byte *)buffer + pinmodel.ofs_frames, pinmodel.framesize, translate); // @@ -2001,6 +2012,12 @@ Mod_LoadModel_MD2(const char *mod_name, const void *buffer, int modfilelen, memcpy((char *)pheader + pheader->ofs_skins, (char *)buffer + pinmodel.ofs_skins, pheader->num_skins * MAX_SKINNAME); + if (normalfix) + { + /* look like normals is zero, lets fix it */ + Mod_LoadFixNormals(pheader); + } + Mod_LoadFixImages(mod_name, pheader, false); *type = mod_alias;