From d570f0905fce0c57667d3bd3dea65fae30974f02 Mon Sep 17 00:00:00 2001 From: Seth Galbraith Date: Sun, 30 Dec 2001 02:30:26 +0000 Subject: [PATCH] high precision model loading --- include/QF/model.h | 6 +++--- include/QF/modelgen.h | 4 ++++ libs/models/alias/gl_mesh.c | 18 +++++++++++++---- libs/models/alias/gl_model_alias.c | 16 +++++++++++---- libs/models/alias/model_alias.c | 11 ++++++++--- libs/models/alias/sw_model_alias.c | 31 ++++++++++++++++++++++++------ libs/models/model.c | 1 + 7 files changed, 67 insertions(+), 20 deletions(-) diff --git a/include/QF/model.h b/include/QF/model.h index 960c435c6..a6b057dd4 100644 --- a/include/QF/model.h +++ b/include/QF/model.h @@ -462,12 +462,12 @@ int Mod_CalcFullbright (byte *in, byte *out, int pixels); int Mod_Fullbright (byte * skin, int width, int height, char *name); -void *Mod_LoadAliasFrame (void *pin, int *posenum, maliasframedesc_t *frame); -void *Mod_LoadAliasGroup (void *pin, int *posenum, maliasframedesc_t *frame); +void *Mod_LoadAliasFrame (void *pin, int *posenum, maliasframedesc_t *frame, int extra); +void *Mod_LoadAliasGroup (void *pin, int *posenum, maliasframedesc_t *frame, int extra); void *Mod_LoadSkin (byte *skin, int skinsize, int snum, int gnum, qboolean group, maliasskindesc_t *skindesc); void Mod_MakeAliasModelDisplayLists (model_t *m, aliashdr_t *hdr, void *_m, - int _s); + int _s, int extra); void Mod_FinalizeAliasModel (model_t *m, aliashdr_t *hdr); void Mod_SpriteLoadTexture (mspriteframe_t *pspriteframe, int framenum); diff --git a/include/QF/modelgen.h b/include/QF/modelgen.h index f17df7dec..3aa04ff48 100644 --- a/include/QF/modelgen.h +++ b/include/QF/modelgen.h @@ -126,4 +126,8 @@ typedef struct { #define IDPOLYHEADER (('O'<<24)+('P'<<16)+('D'<<8)+'I') // little-endian "IDPO" + +// special header indicating 16 bit vertices - little-endian "MD16" +#define POLYHEADER16 (('6'<<24)+('1'<<16)+('D'<<8)+'M') + #endif // _MODELGEN_H diff --git a/libs/models/alias/gl_mesh.c b/libs/models/alias/gl_mesh.c index 903fd9f64..0d7180fab 100644 --- a/libs/models/alias/gl_mesh.c +++ b/libs/models/alias/gl_mesh.c @@ -342,7 +342,7 @@ BuildTris (void) } void -Mod_MakeAliasModelDisplayLists (model_t *m, aliashdr_t *hdr, void *_m, int _s) +Mod_MakeAliasModelDisplayLists (model_t *m, aliashdr_t *hdr, void *_m, int _s, int extra) { int i, j; int *cmds; @@ -489,11 +489,21 @@ Mod_MakeAliasModelDisplayLists (model_t *m, aliashdr_t *hdr, void *_m, int _s) paliashdr->commands = (byte *) cmds - (byte *) paliashdr; memcpy (cmds, commands, numcommands * sizeof (int)); - verts = Hunk_Alloc (paliashdr->numposes * paliashdr->poseverts - + if (extra) + verts = Hunk_Alloc (paliashdr->numposes * paliashdr->poseverts + * sizeof (trivertx_t) * 2); + else + verts = Hunk_Alloc (paliashdr->numposes * paliashdr->poseverts * sizeof (trivertx_t)); + paliashdr->posedata = (byte *) verts - (byte *) paliashdr; + for (i = 0; i < paliashdr->numposes; i++) + { for (j = 0; j < numorder; j++) - *verts++ = poseverts[i][vertexorder[j]]; + *verts++ = poseverts[i][vertexorder[j]]; + if (extra) + for (j = 0; j < numorder; j++) + *verts++ = poseverts[i][vertexorder[j] + hdr->mdl.numverts]; + } } diff --git a/libs/models/alias/gl_model_alias.c b/libs/models/alias/gl_model_alias.c index 40441498d..af44ec22e 100644 --- a/libs/models/alias/gl_model_alias.c +++ b/libs/models/alias/gl_model_alias.c @@ -182,7 +182,7 @@ Mod_LoadSkin (byte * skin, int skinsize, int snum, int gnum, qboolean group, } void * -Mod_LoadAliasFrame (void *pin, int *posenum, maliasframedesc_t *frame) +Mod_LoadAliasFrame (void *pin, int *posenum, maliasframedesc_t *frame, int extra) { trivertx_t *pinframe; int i; @@ -205,13 +205,16 @@ Mod_LoadAliasFrame (void *pin, int *posenum, maliasframedesc_t *frame) poseverts[(*posenum)] = pinframe; (*posenum)++; - pinframe += pheader->mdl.numverts; + if (extra) + pinframe += pheader->mdl.numverts * 2; + else + pinframe += pheader->mdl.numverts; return (void *) pinframe; } void * -Mod_LoadAliasGroup (void *pin, int *posenum, maliasframedesc_t *frame) +Mod_LoadAliasGroup (void *pin, int *posenum, maliasframedesc_t *frame, int extra) { daliasgroup_t *pingroup; int i, numframes; @@ -242,7 +245,12 @@ Mod_LoadAliasGroup (void *pin, int *posenum, maliasframedesc_t *frame) for (i = 0; i < numframes; i++) { poseverts[(*posenum)] = (trivertx_t *) ((daliasframe_t *) ptemp + 1); (*posenum)++; - ptemp = (trivertx_t *) ((daliasframe_t *) ptemp + 1) + pheader->mdl.numverts; + if (extra) + ptemp = (trivertx_t *) ((daliasframe_t *) ptemp + 1) + + pheader->mdl.numverts * 2; + else + ptemp = (trivertx_t *) ((daliasframe_t *) ptemp + 1) + + pheader->mdl.numverts; } return ptemp; } diff --git a/libs/models/alias/model_alias.c b/libs/models/alias/model_alias.c index 886cf6dfe..74e7a333f 100644 --- a/libs/models/alias/model_alias.c +++ b/libs/models/alias/model_alias.c @@ -151,6 +151,11 @@ Mod_LoadAliasModel (model_t *mod, void *buffer, cache_allocator_t allocator) unsigned short crc; void *mem; + int extra = 0; // extra precision bytes + + if (LittleLong (*(unsigned int *) buffer) == POLYHEADER16) + extra = 1; // extra precision bytes + CRC_Init (&crc); for (len = com_filesize, p = buffer; len; len--, p++) CRC_ProcessByte (&crc, *p); @@ -253,11 +258,11 @@ Mod_LoadAliasModel (model_t *mod, void *buffer, cache_allocator_t allocator) if (frametype == ALIAS_SINGLE) { pframetype = (daliasframetype_t *) Mod_LoadAliasFrame (pframetype + 1, &posenum, - &pheader->frames[i]); + &pheader->frames[i], extra); } else { pframetype = (daliasframetype_t *) Mod_LoadAliasGroup (pframetype + 1, &posenum, - &pheader->frames[i]); + &pheader->frames[i], extra); } } @@ -270,7 +275,7 @@ Mod_LoadAliasModel (model_t *mod, void *buffer, cache_allocator_t allocator) mod->maxs[0] = mod->maxs[1] = mod->maxs[2] = 16; // build the draw lists - Mod_MakeAliasModelDisplayLists (mod, pheader, buffer, com_filesize); + Mod_MakeAliasModelDisplayLists (mod, pheader, buffer, com_filesize, extra); Mod_FinalizeAliasModel (mod, pheader); diff --git a/libs/models/alias/sw_model_alias.c b/libs/models/alias/sw_model_alias.c index 1cf1c6959..fa193d0d4 100644 --- a/libs/models/alias/sw_model_alias.c +++ b/libs/models/alias/sw_model_alias.c @@ -73,7 +73,7 @@ Mod_LoadSkin (byte *skin, int skinsize, int snum, int gnum, } void -Mod_MakeAliasModelDisplayLists (model_t *m, aliashdr_t *hdr, void *_m, int _s) +Mod_MakeAliasModelDisplayLists (model_t *m, aliashdr_t *hdr, void *_m, int _s, int extra) { int i, j; stvert_t *pstverts; @@ -104,7 +104,7 @@ Mod_MakeAliasModelDisplayLists (model_t *m, aliashdr_t *hdr, void *_m, int _s) } void * -Mod_LoadAliasFrame (void *pin, int *posenum, maliasframedesc_t *frame) +Mod_LoadAliasFrame (void *pin, int *posenum, maliasframedesc_t *frame, int extra) { trivertx_t *pframe, *pinframe; int i, j; @@ -121,7 +121,12 @@ Mod_LoadAliasFrame (void *pin, int *posenum, maliasframedesc_t *frame) } pinframe = (trivertx_t *) (pdaliasframe + 1); - pframe = Hunk_AllocName (pheader->mdl.numverts * sizeof (*pframe), + + if (extra) + pframe = Hunk_AllocName (pheader->mdl.numverts * sizeof (*pframe) * 2, + loadname); + else + pframe = Hunk_AllocName (pheader->mdl.numverts * sizeof (*pframe), loadname); frame->frame = (byte *) pframe - (byte *) pheader; @@ -137,13 +142,27 @@ Mod_LoadAliasFrame (void *pin, int *posenum, maliasframedesc_t *frame) } } - pinframe += pheader->mdl.numverts; + if (extra) + { + for (j = pheader->mdl.numverts; j < pheader->mdl.numverts * 2; j++) + { + int k; + for (k = 0; k < 3; k++) + pframe[j].v[k] = pinframe[j].v[k]; + } + } + + if (extra) + pinframe += pheader->mdl.numverts * 2; + else + pinframe += pheader->mdl.numverts; + return (void *) pinframe; } void * -Mod_LoadAliasGroup (void *pin, int *posenum, maliasframedesc_t *frame) +Mod_LoadAliasGroup (void *pin, int *posenum, maliasframedesc_t *frame, int extra) { daliasgroup_t *pingroup; maliasgroup_t *paliasgroup; @@ -187,7 +206,7 @@ Mod_LoadAliasGroup (void *pin, int *posenum, maliasframedesc_t *frame) for (i = 0; i < numframes; i++) { maliasframedesc_t temp_frame; - ptemp = Mod_LoadAliasFrame (ptemp, &i, &temp_frame); + ptemp = Mod_LoadAliasFrame (ptemp, &i, &temp_frame, extra); memcpy (&paliasgroup->frames[i], &temp_frame, sizeof(paliasgroup->frames[i])); } diff --git a/libs/models/model.c b/libs/models/model.c index 317bcd207..d70959446 100644 --- a/libs/models/model.c +++ b/libs/models/model.c @@ -215,6 +215,7 @@ Mod_RealLoadModel (model_t *mod, qboolean crash, cache_allocator_t allocator) switch (LittleLong (*(unsigned int *) buf)) { case IDPOLYHEADER: + case POLYHEADER16: Mod_LoadAliasModel (mod, buf, allocator); break;