2001-02-19 21:15:25 +00:00
|
|
|
/*
|
2002-08-25 14:25:38 +00:00
|
|
|
model_alias.c
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2002-08-25 14:25:38 +00:00
|
|
|
alias model loading and caching
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
Copyright (C) 1996-1997 Id Software, Inc.
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU General Public License
|
|
|
|
as published by the Free Software Foundation; either version 2
|
|
|
|
of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
|
|
|
|
See the GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to:
|
|
|
|
|
|
|
|
Free Software Foundation, Inc.
|
|
|
|
59 Temple Place - Suite 330
|
|
|
|
Boston, MA 02111-1307, USA
|
|
|
|
|
|
|
|
*/
|
|
|
|
// models are the only shared resource between a client and server running
|
|
|
|
// on the same machine.
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "config.h"
|
|
|
|
#endif
|
2003-01-15 15:31:36 +00:00
|
|
|
|
2001-02-19 21:15:25 +00:00
|
|
|
#ifdef HAVE_STRING_H
|
|
|
|
# include <string.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_STRINGS_H
|
|
|
|
# include <strings.h>
|
|
|
|
#endif
|
|
|
|
|
2001-03-27 20:33:07 +00:00
|
|
|
#include "QF/crc.h"
|
|
|
|
#include "QF/msg.h"
|
|
|
|
#include "QF/qendian.h"
|
2002-08-27 07:16:28 +00:00
|
|
|
#include "QF/quakefs.h"
|
2001-05-10 06:01:11 +00:00
|
|
|
#include "QF/sys.h"
|
|
|
|
|
2002-08-20 00:48:59 +00:00
|
|
|
#include "compat.h"
|
2001-05-10 06:01:11 +00:00
|
|
|
#include "d_iface.h"
|
2012-02-14 12:25:19 +00:00
|
|
|
#include "mod_internal.h"
|
2001-02-19 21:15:25 +00:00
|
|
|
#include "r_local.h"
|
|
|
|
|
2003-01-06 18:28:13 +00:00
|
|
|
static void *
|
2021-02-01 12:11:45 +00:00
|
|
|
Mod_LoadAllSkins (mod_alias_ctx_t *alias_ctx, int numskins,
|
|
|
|
daliasskintype_t *pskintype, int *pskinindex)
|
2001-11-21 19:13:53 +00:00
|
|
|
{
|
2021-02-01 12:11:45 +00:00
|
|
|
aliashdr_t *header = alias_ctx->header;
|
2001-11-21 19:13:53 +00:00
|
|
|
byte *skin;
|
2002-08-20 00:48:59 +00:00
|
|
|
float *poutskinintervals;
|
|
|
|
int groupskins, skinsize, gnum, snum, t;
|
2001-11-21 19:13:53 +00:00
|
|
|
daliasskingroup_t *pinskingroup;
|
|
|
|
daliasskininterval_t *pinskinintervals;
|
|
|
|
maliasskindesc_t *pskindesc;
|
|
|
|
maliasskingroup_t *paliasskingroup;
|
|
|
|
|
|
|
|
if (numskins < 1 || numskins > MAX_SKINS)
|
2002-05-14 06:12:29 +00:00
|
|
|
Sys_Error ("Mod_LoadAliasModel: Invalid # of skins: %d", numskins);
|
2001-11-21 19:13:53 +00:00
|
|
|
|
2021-02-01 12:11:45 +00:00
|
|
|
skinsize = header->mdl.skinwidth * header->mdl.skinheight;
|
2021-07-28 06:01:45 +00:00
|
|
|
pskindesc = Hunk_AllocName (0, numskins * sizeof (maliasskindesc_t),
|
2021-02-01 12:11:45 +00:00
|
|
|
alias_ctx->mod->name);
|
2001-11-21 19:13:53 +00:00
|
|
|
|
2021-02-01 12:11:45 +00:00
|
|
|
*pskinindex = (byte *) pskindesc - (byte *) header;
|
2001-11-21 19:13:53 +00:00
|
|
|
|
|
|
|
for (snum = 0; snum < numskins; snum++) {
|
|
|
|
pskindesc[snum].type = pskintype->type;
|
|
|
|
if (pskintype->type == ALIAS_SKIN_SINGLE) {
|
|
|
|
skin = (byte *) (pskintype + 1);
|
[model] Make alias skin loading a batch operation
Really, this won't make all that much difference because alias models
with more than one skin are quite rare, and those with animated skin
groups are even rarer. However, for those models that do have more than
one skin, it will allow for reduced allocation overheads, and when
supported (glsl, vulkan, maybe gl), loading all the skins into an array
texture (since all skins are the same size, though external skins may
vary), but that's not implemented yet, this just wraps the old one skin
at a time code.
2022-04-04 06:38:27 +00:00
|
|
|
mod_alias_skin_t askin = {
|
|
|
|
.skin_num = snum,
|
|
|
|
.group_num = -1,
|
|
|
|
.texels = skin,
|
|
|
|
.skindesc = &pskindesc[snum],
|
|
|
|
};
|
|
|
|
skin += skinsize;
|
|
|
|
DARRAY_APPEND (&alias_ctx->skins, askin);
|
2001-11-21 19:13:53 +00:00
|
|
|
} else {
|
|
|
|
pskintype++;
|
|
|
|
pinskingroup = (daliasskingroup_t *) pskintype;
|
|
|
|
groupskins = LittleLong (pinskingroup->numskins);
|
|
|
|
|
|
|
|
t = field_offset (maliasskingroup_t, skindescs[groupskins]);
|
2021-07-28 06:01:45 +00:00
|
|
|
paliasskingroup = Hunk_AllocName (0, t, alias_ctx->mod->name);
|
2001-11-21 19:13:53 +00:00
|
|
|
paliasskingroup->numskins = groupskins;
|
|
|
|
|
2021-02-01 12:11:45 +00:00
|
|
|
pskindesc[snum].skin = (byte *) paliasskingroup - (byte *) header;
|
2001-11-21 19:13:53 +00:00
|
|
|
|
|
|
|
pinskinintervals = (daliasskininterval_t *) (pinskingroup + 1);
|
2021-07-28 06:01:45 +00:00
|
|
|
poutskinintervals = Hunk_AllocName (0, groupskins * sizeof (float),
|
2021-02-01 12:11:45 +00:00
|
|
|
alias_ctx->mod->name);
|
2001-11-21 19:13:53 +00:00
|
|
|
paliasskingroup->intervals =
|
2021-02-01 12:11:45 +00:00
|
|
|
(byte *) poutskinintervals - (byte *) header;
|
2001-11-21 19:13:53 +00:00
|
|
|
for (gnum = 0; gnum < groupskins; gnum++) {
|
|
|
|
*poutskinintervals = LittleFloat (pinskinintervals->interval);
|
|
|
|
if (*poutskinintervals <= 0)
|
|
|
|
Sys_Error ("Mod_LoadAliasSkinGroup: interval<=0");
|
|
|
|
|
|
|
|
poutskinintervals++;
|
|
|
|
pinskinintervals++;
|
|
|
|
}
|
|
|
|
|
|
|
|
pskintype = (void *) pinskinintervals;
|
|
|
|
skin = (byte *) pskintype;
|
|
|
|
|
|
|
|
for (gnum = 0; gnum < groupskins; gnum++) {
|
|
|
|
paliasskingroup->skindescs[gnum].type = ALIAS_SKIN_SINGLE;
|
[model] Make alias skin loading a batch operation
Really, this won't make all that much difference because alias models
with more than one skin are quite rare, and those with animated skin
groups are even rarer. However, for those models that do have more than
one skin, it will allow for reduced allocation overheads, and when
supported (glsl, vulkan, maybe gl), loading all the skins into an array
texture (since all skins are the same size, though external skins may
vary), but that's not implemented yet, this just wraps the old one skin
at a time code.
2022-04-04 06:38:27 +00:00
|
|
|
mod_alias_skin_t askin = {
|
|
|
|
.skin_num = snum,
|
|
|
|
.group_num = gnum,
|
|
|
|
.texels = skin,
|
|
|
|
.skindesc = &paliasskingroup->skindescs[gnum],
|
|
|
|
};
|
|
|
|
skin += skinsize;
|
|
|
|
DARRAY_APPEND (&alias_ctx->skins, askin);
|
2001-11-21 19:13:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
pskintype = (daliasskintype_t *) skin;
|
|
|
|
}
|
[model] Make alias skin loading a batch operation
Really, this won't make all that much difference because alias models
with more than one skin are quite rare, and those with animated skin
groups are even rarer. However, for those models that do have more than
one skin, it will allow for reduced allocation overheads, and when
supported (glsl, vulkan, maybe gl), loading all the skins into an array
texture (since all skins are the same size, though external skins may
vary), but that's not implemented yet, this just wraps the old one skin
at a time code.
2022-04-04 06:38:27 +00:00
|
|
|
mod_funcs->Mod_LoadAllSkins (alias_ctx);
|
2001-11-21 19:13:53 +00:00
|
|
|
|
|
|
|
return pskintype;
|
|
|
|
}
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2021-02-01 05:39:00 +00:00
|
|
|
static void *
|
2021-02-01 12:11:45 +00:00
|
|
|
Mod_LoadAliasFrame (mod_alias_ctx_t *alias_ctx, void *pin, int *posenum,
|
2021-02-01 05:39:00 +00:00
|
|
|
maliasframedesc_t *frame, int extra)
|
2011-12-25 02:04:03 +00:00
|
|
|
{
|
2021-02-01 12:11:45 +00:00
|
|
|
aliashdr_t *header = alias_ctx->header;
|
2011-12-25 02:04:03 +00:00
|
|
|
daliasframe_t *pdaliasframe;
|
|
|
|
trivertx_t *pinframe;
|
|
|
|
|
|
|
|
pdaliasframe = (daliasframe_t *) pin;
|
|
|
|
|
2020-12-20 17:12:51 +00:00
|
|
|
memcpy (frame->name, pdaliasframe->name, sizeof (frame->name));
|
2011-12-25 02:04:03 +00:00
|
|
|
frame->name[sizeof (frame->name) - 1] = 0;
|
|
|
|
frame->firstpose = (*posenum);
|
|
|
|
frame->numposes = 1;
|
|
|
|
|
|
|
|
// byte values, don't worry about endianness
|
|
|
|
VectorCopy (pdaliasframe->bboxmin.v, frame->bboxmin.v);
|
|
|
|
VectorCopy (pdaliasframe->bboxmax.v, frame->bboxmax.v);
|
2021-02-01 12:11:45 +00:00
|
|
|
VectorCompMin (frame->bboxmin.v, alias_ctx->aliasbboxmins,
|
|
|
|
alias_ctx->aliasbboxmins);
|
|
|
|
VectorCompMax (frame->bboxmax.v, alias_ctx->aliasbboxmaxs,
|
|
|
|
alias_ctx->aliasbboxmaxs);
|
2011-12-25 02:04:03 +00:00
|
|
|
|
|
|
|
pinframe = (trivertx_t *) (pdaliasframe + 1);
|
|
|
|
|
2021-02-01 12:11:45 +00:00
|
|
|
DARRAY_APPEND (&alias_ctx->poseverts, pinframe);
|
2011-12-25 02:04:03 +00:00
|
|
|
(*posenum)++;
|
|
|
|
|
2021-02-01 12:11:45 +00:00
|
|
|
pinframe += header->mdl.numverts;
|
2011-12-25 02:04:03 +00:00
|
|
|
if (extra)
|
2021-02-01 12:11:45 +00:00
|
|
|
pinframe += header->mdl.numverts;
|
2011-12-25 02:04:03 +00:00
|
|
|
|
|
|
|
return pinframe;
|
|
|
|
}
|
|
|
|
|
2021-02-01 05:39:00 +00:00
|
|
|
static void *
|
2021-02-01 12:11:45 +00:00
|
|
|
Mod_LoadAliasGroup (mod_alias_ctx_t *alias_ctx, void *pin, int *posenum,
|
2021-02-01 05:39:00 +00:00
|
|
|
maliasframedesc_t *frame, int extra)
|
2011-12-25 02:04:03 +00:00
|
|
|
{
|
2021-02-01 12:11:45 +00:00
|
|
|
aliashdr_t *header = alias_ctx->header;
|
|
|
|
model_t *mod = alias_ctx->mod;
|
2011-12-25 02:04:03 +00:00
|
|
|
daliasgroup_t *pingroup;
|
|
|
|
daliasinterval_t *pin_intervals;
|
|
|
|
float *poutintervals;
|
|
|
|
int i, numframes;
|
|
|
|
maliasgroup_t *paliasgroup;
|
|
|
|
void *ptemp;
|
|
|
|
|
|
|
|
pingroup = (daliasgroup_t *) pin;
|
|
|
|
|
|
|
|
numframes = LittleLong (pingroup->numframes);
|
|
|
|
|
|
|
|
frame->firstpose = (*posenum);
|
|
|
|
frame->numposes = numframes;
|
|
|
|
|
2021-07-28 06:01:45 +00:00
|
|
|
paliasgroup = Hunk_AllocName (0, field_offset (maliasgroup_t,
|
|
|
|
frames[numframes]),
|
|
|
|
mod->name);
|
2011-12-25 02:04:03 +00:00
|
|
|
paliasgroup->numframes = numframes;
|
2021-02-01 12:11:45 +00:00
|
|
|
frame->frame = (byte *) paliasgroup - (byte *) header;
|
2011-12-25 02:04:03 +00:00
|
|
|
|
|
|
|
// these are byte values, so we don't have to worry about endianness
|
|
|
|
VectorCopy (pingroup->bboxmin.v, frame->bboxmin.v);
|
|
|
|
VectorCopy (pingroup->bboxmax.v, frame->bboxmax.v);
|
2021-02-01 12:11:45 +00:00
|
|
|
VectorCompMin (frame->bboxmin.v, alias_ctx->aliasbboxmins,
|
|
|
|
alias_ctx->aliasbboxmins);
|
|
|
|
VectorCompMax (frame->bboxmax.v, alias_ctx->aliasbboxmaxs,
|
|
|
|
alias_ctx->aliasbboxmaxs);
|
2011-12-25 02:04:03 +00:00
|
|
|
|
|
|
|
pin_intervals = (daliasinterval_t *) (pingroup + 1);
|
2021-07-28 06:01:45 +00:00
|
|
|
poutintervals = Hunk_AllocName (0, numframes * sizeof (float), mod->name);
|
2021-02-01 12:11:45 +00:00
|
|
|
paliasgroup->intervals = (byte *) poutintervals - (byte *) header;
|
2011-12-25 02:04:03 +00:00
|
|
|
frame->interval = LittleFloat (pin_intervals->interval);
|
|
|
|
for (i = 0; i < numframes; i++) {
|
|
|
|
*poutintervals = LittleFloat (pin_intervals->interval);
|
|
|
|
if (*poutintervals <= 0.0)
|
|
|
|
Sys_Error ("Mod_LoadAliasGroup: interval<=0");
|
|
|
|
poutintervals++;
|
|
|
|
pin_intervals++;
|
|
|
|
}
|
|
|
|
|
|
|
|
ptemp = (void *) pin_intervals;
|
|
|
|
for (i = 0; i < numframes; i++) {
|
|
|
|
maliasframedesc_t temp_frame;
|
2021-02-01 12:11:45 +00:00
|
|
|
ptemp = Mod_LoadAliasFrame (alias_ctx, ptemp, posenum, &temp_frame,
|
|
|
|
extra);
|
2011-12-25 02:04:03 +00:00
|
|
|
memcpy (&paliasgroup->frames[i], &temp_frame,
|
|
|
|
sizeof (paliasgroup->frames[i]));
|
|
|
|
}
|
|
|
|
|
|
|
|
return ptemp;
|
|
|
|
}
|
|
|
|
|
2001-02-19 21:15:25 +00:00
|
|
|
void
|
2001-08-31 12:22:45 +00:00
|
|
|
Mod_LoadAliasModel (model_t *mod, void *buffer, cache_allocator_t allocator)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2021-07-29 02:12:37 +00:00
|
|
|
size_t size, start, end, total;
|
|
|
|
int version, numframes, i, j;
|
2004-02-08 02:49:38 +00:00
|
|
|
int extra = 0; // extra precision bytes
|
|
|
|
void *mem;
|
2001-02-19 21:15:25 +00:00
|
|
|
dtriangle_t *pintriangles;
|
|
|
|
daliasframetype_t *pframetype;
|
|
|
|
daliasskintype_t *pskintype;
|
2002-08-25 14:25:38 +00:00
|
|
|
mdl_t *pinmodel, *pmodel;
|
2001-05-29 17:37:48 +00:00
|
|
|
unsigned short crc;
|
2002-08-25 14:25:38 +00:00
|
|
|
stvert_t *pinstverts;
|
2021-02-01 12:11:45 +00:00
|
|
|
mod_alias_ctx_t alias_ctx = {};
|
|
|
|
aliashdr_t *header;
|
|
|
|
|
|
|
|
alias_ctx.mod = mod;
|
|
|
|
//FIXME should be per batch rather than per model
|
|
|
|
DARRAY_INIT (&alias_ctx.poseverts, 256);
|
|
|
|
DARRAY_INIT (&alias_ctx.stverts, 256);
|
|
|
|
DARRAY_INIT (&alias_ctx.triangles, 256);
|
[model] Make alias skin loading a batch operation
Really, this won't make all that much difference because alias models
with more than one skin are quite rare, and those with animated skin
groups are even rarer. However, for those models that do have more than
one skin, it will allow for reduced allocation overheads, and when
supported (glsl, vulkan, maybe gl), loading all the skins into an array
texture (since all skins are the same size, though external skins may
vary), but that's not implemented yet, this just wraps the old one skin
at a time code.
2022-04-04 06:38:27 +00:00
|
|
|
DARRAY_INIT (&alias_ctx.skins, 256);
|
2001-12-30 02:30:26 +00:00
|
|
|
|
2004-02-08 02:49:38 +00:00
|
|
|
if (LittleLong (* (unsigned int *) buffer) == HEADER_MDL16)
|
|
|
|
extra = 1; // extra precision bytes
|
2001-12-30 02:30:26 +00:00
|
|
|
|
2001-05-29 17:37:48 +00:00
|
|
|
CRC_Init (&crc);
|
2003-08-11 06:05:07 +00:00
|
|
|
CRC_ProcessBlock (buffer, &crc, qfs_filesize);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2021-07-28 06:01:45 +00:00
|
|
|
start = Hunk_LowMark (0);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
pinmodel = (mdl_t *) buffer;
|
|
|
|
|
|
|
|
version = LittleLong (pinmodel->version);
|
2004-02-08 02:49:38 +00:00
|
|
|
if (version != ALIAS_VERSION_MDL)
|
2001-05-10 06:01:11 +00:00
|
|
|
Sys_Error ("%s has wrong version number (%i should be %i)",
|
2004-02-08 02:49:38 +00:00
|
|
|
mod->name, version, ALIAS_VERSION_MDL);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-07-22 05:40:34 +00:00
|
|
|
// allocate space for a working header, plus all the data except the
|
2022-05-13 10:38:46 +00:00
|
|
|
// frame data, skin and group info
|
2001-05-31 18:11:05 +00:00
|
|
|
size = field_offset (aliashdr_t, frames[LittleLong (pinmodel->numframes)]);
|
2021-07-28 06:01:45 +00:00
|
|
|
header = Hunk_AllocName (0, size, mod->name);
|
2021-02-01 12:11:45 +00:00
|
|
|
memset (header, 0, size);
|
|
|
|
alias_ctx.header = header;
|
|
|
|
pmodel = &header->mdl;
|
|
|
|
header->model = (byte *) pmodel - (byte *) header;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2021-02-01 12:11:45 +00:00
|
|
|
header->crc = crc;
|
2001-05-29 17:37:48 +00:00
|
|
|
|
2023-09-14 11:35:45 +00:00
|
|
|
mod->effects = LittleLong (pinmodel->flags);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-07-22 05:40:34 +00:00
|
|
|
// endian-adjust and copy the data, starting with the alias model header
|
2002-01-05 03:21:02 +00:00
|
|
|
pmodel->ident = LittleLong (pinmodel->ident);
|
2001-02-19 21:15:25 +00:00
|
|
|
pmodel->boundingradius = LittleFloat (pinmodel->boundingradius);
|
|
|
|
pmodel->numskins = LittleLong (pinmodel->numskins);
|
|
|
|
pmodel->skinwidth = LittleLong (pinmodel->skinwidth);
|
|
|
|
pmodel->skinheight = LittleLong (pinmodel->skinheight);
|
|
|
|
|
|
|
|
if (pmodel->skinheight > MAX_LBM_HEIGHT)
|
2001-05-10 06:01:11 +00:00
|
|
|
Sys_Error ("model %s has a skin taller than %d", mod->name,
|
2004-02-08 02:49:38 +00:00
|
|
|
MAX_LBM_HEIGHT);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2021-02-01 12:11:45 +00:00
|
|
|
DARRAY_RESIZE (&alias_ctx.poseverts, 0);
|
2001-02-19 21:15:25 +00:00
|
|
|
pmodel->numverts = LittleLong (pinmodel->numverts);
|
|
|
|
|
|
|
|
if (pmodel->numverts <= 0)
|
2001-05-10 06:01:11 +00:00
|
|
|
Sys_Error ("model %s has no vertices", mod->name);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2021-02-01 12:11:45 +00:00
|
|
|
DARRAY_RESIZE (&alias_ctx.stverts, pmodel->numverts);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
pmodel->numtris = LittleLong (pinmodel->numtris);
|
|
|
|
|
|
|
|
if (pmodel->numtris <= 0)
|
2001-05-10 06:01:11 +00:00
|
|
|
Sys_Error ("model %s has no triangles", mod->name);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2021-02-01 12:11:45 +00:00
|
|
|
DARRAY_RESIZE (&alias_ctx.triangles, pmodel->numtris);
|
2002-01-04 07:40:00 +00:00
|
|
|
|
2001-02-19 21:15:25 +00:00
|
|
|
pmodel->numframes = LittleLong (pinmodel->numframes);
|
|
|
|
numframes = pmodel->numframes;
|
|
|
|
if (numframes < 1)
|
2002-05-14 06:12:29 +00:00
|
|
|
Sys_Error ("Mod_LoadAliasModel: Invalid # of frames: %d", numframes);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
pmodel->size = LittleFloat (pinmodel->size) * ALIAS_BASE_SIZE_RATIO;
|
|
|
|
mod->synctype = LittleLong (pinmodel->synctype);
|
|
|
|
mod->numframes = pmodel->numframes;
|
|
|
|
|
|
|
|
for (i = 0; i < 3; i++) {
|
|
|
|
pmodel->scale[i] = LittleFloat (pinmodel->scale[i]);
|
|
|
|
pmodel->scale_origin[i] = LittleFloat (pinmodel->scale_origin[i]);
|
|
|
|
pmodel->eyeposition[i] = LittleFloat (pinmodel->eyeposition[i]);
|
|
|
|
}
|
|
|
|
|
2001-07-22 05:40:34 +00:00
|
|
|
// load the skins
|
2001-02-19 21:15:25 +00:00
|
|
|
pskintype = (daliasskintype_t *) &pinmodel[1];
|
2021-02-01 12:11:45 +00:00
|
|
|
pskintype = Mod_LoadAllSkins (&alias_ctx, header->mdl.numskins, pskintype,
|
|
|
|
&header->skindesc);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-07-22 05:40:34 +00:00
|
|
|
// load base s and t vertices
|
2001-02-19 21:15:25 +00:00
|
|
|
pinstverts = (stvert_t *) pskintype;
|
|
|
|
|
2021-02-01 12:11:45 +00:00
|
|
|
for (i = 0; i < header->mdl.numverts; i++) {
|
|
|
|
alias_ctx.stverts.a[i].onseam = LittleLong (pinstverts[i].onseam);
|
|
|
|
alias_ctx.stverts.a[i].s = LittleLong (pinstverts[i].s);
|
|
|
|
alias_ctx.stverts.a[i].t = LittleLong (pinstverts[i].t);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
2001-07-22 05:40:34 +00:00
|
|
|
// load triangle lists
|
2021-02-01 12:11:45 +00:00
|
|
|
pintriangles = (dtriangle_t *) &pinstverts[header->mdl.numverts];
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2021-02-01 12:11:45 +00:00
|
|
|
for (i = 0; i < header->mdl.numtris; i++) {
|
|
|
|
alias_ctx.triangles.a[i].facesfront =
|
|
|
|
LittleLong (pintriangles[i].facesfront);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
for (j = 0; j < 3; j++) {
|
2021-02-01 12:11:45 +00:00
|
|
|
alias_ctx.triangles.a[i].vertindex[j] =
|
2001-02-19 21:15:25 +00:00
|
|
|
LittleLong (pintriangles[i].vertindex[j]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-07-22 05:40:34 +00:00
|
|
|
// load the frames
|
2021-02-01 12:11:45 +00:00
|
|
|
int posenum = 0;
|
|
|
|
pframetype = (daliasframetype_t *) &pintriangles[header->mdl.numtris];
|
|
|
|
VectorSet (99999, 99999, 99999, alias_ctx.aliasbboxmins);
|
|
|
|
VectorSet (-99999, -99999, -99999, alias_ctx.aliasbboxmaxs);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
for (i = 0; i < numframes; i++) {
|
|
|
|
aliasframetype_t frametype;
|
|
|
|
|
|
|
|
frametype = LittleLong (pframetype->type);
|
2021-02-01 12:11:45 +00:00
|
|
|
header->frames[i].type = frametype;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
if (frametype == ALIAS_SINGLE) {
|
|
|
|
pframetype = (daliasframetype_t *)
|
2021-02-01 12:11:45 +00:00
|
|
|
Mod_LoadAliasFrame (&alias_ctx, pframetype + 1, &posenum,
|
|
|
|
&header->frames[i], extra);
|
2001-02-19 21:15:25 +00:00
|
|
|
} else {
|
|
|
|
pframetype = (daliasframetype_t *)
|
2021-02-01 12:11:45 +00:00
|
|
|
Mod_LoadAliasGroup (&alias_ctx, pframetype + 1, &posenum,
|
|
|
|
&header->frames[i], extra);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-01 12:11:45 +00:00
|
|
|
header->numposes = posenum;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
mod->type = mod_alias;
|
|
|
|
|
2021-02-01 12:11:45 +00:00
|
|
|
VectorCompMultAdd (header->mdl.scale_origin, header->mdl.scale,
|
|
|
|
alias_ctx.aliasbboxmins, mod->mins);
|
|
|
|
VectorCompMultAdd (header->mdl.scale_origin, header->mdl.scale,
|
|
|
|
alias_ctx.aliasbboxmaxs, mod->maxs);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2002-08-20 00:48:59 +00:00
|
|
|
mod->radius = RadiusFromBounds (mod->mins, mod->maxs);
|
|
|
|
|
2001-02-19 21:15:25 +00:00
|
|
|
// build the draw lists
|
2021-02-01 12:11:45 +00:00
|
|
|
m_funcs->Mod_MakeAliasModelDisplayLists (&alias_ctx, buffer,
|
2012-02-23 03:55:50 +00:00
|
|
|
qfs_filesize, extra);
|
2001-11-20 08:02:35 +00:00
|
|
|
|
2021-02-01 12:11:45 +00:00
|
|
|
if (m_funcs->Mod_FinalizeAliasModel) {
|
|
|
|
m_funcs->Mod_FinalizeAliasModel (&alias_ctx);
|
|
|
|
}
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2021-02-01 12:11:45 +00:00
|
|
|
if (m_funcs->Mod_LoadExternalSkins) {
|
|
|
|
m_funcs->Mod_LoadExternalSkins (&alias_ctx);
|
|
|
|
}
|
2003-12-28 05:25:06 +00:00
|
|
|
|
2001-07-22 05:40:34 +00:00
|
|
|
// move the complete, relocatable alias model to the cache
|
2012-02-23 03:55:50 +00:00
|
|
|
if (m_funcs->alias_cache) {
|
2021-07-28 06:01:45 +00:00
|
|
|
end = Hunk_LowMark (0);
|
2012-01-17 02:44:28 +00:00
|
|
|
total = end - start;
|
|
|
|
|
2021-02-01 05:39:00 +00:00
|
|
|
mem = allocator (&mod->cache, total, mod->name);
|
2012-01-17 02:44:28 +00:00
|
|
|
if (mem)
|
2021-02-01 12:11:45 +00:00
|
|
|
memcpy (mem, header, total);
|
2012-01-17 02:44:28 +00:00
|
|
|
|
2021-07-28 06:01:45 +00:00
|
|
|
Hunk_FreeToLowMark (0, start);
|
2012-01-17 02:44:28 +00:00
|
|
|
mod->aliashdr = 0;
|
|
|
|
} else {
|
2021-02-01 12:11:45 +00:00
|
|
|
mod->aliashdr = header;
|
2012-01-17 02:44:28 +00:00
|
|
|
}
|
2021-03-21 10:56:17 +00:00
|
|
|
DARRAY_CLEAR (&alias_ctx.poseverts);
|
|
|
|
DARRAY_CLEAR (&alias_ctx.stverts);
|
|
|
|
DARRAY_CLEAR (&alias_ctx.triangles);
|
[model] Make alias skin loading a batch operation
Really, this won't make all that much difference because alias models
with more than one skin are quite rare, and those with animated skin
groups are even rarer. However, for those models that do have more than
one skin, it will allow for reduced allocation overheads, and when
supported (glsl, vulkan, maybe gl), loading all the skins into an array
texture (since all skins are the same size, though external skins may
vary), but that's not implemented yet, this just wraps the old one skin
at a time code.
2022-04-04 06:38:27 +00:00
|
|
|
DARRAY_CLEAR (&alias_ctx.skins);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|