models: model always has one mesh at least

This commit is contained in:
Denis Pauk 2023-12-27 01:37:17 +02:00
parent 531dc2f872
commit 3e7bd79c5b
4 changed files with 69 additions and 103 deletions

View file

@ -283,11 +283,13 @@ Mod_LoadModel_MDL(const char *mod_name, const void *buffer, int modfilelen,
int version; int version;
dmdx_t *pheader; dmdx_t *pheader;
void *extradata; void *extradata;
dmdxmesh_t *mesh_nodes;
/* local copy of all values */ /* local copy of all values */
int skinwidth, skinheight, framesize; int skinwidth, skinheight, framesize;
int num_skins, num_xyz, num_st, num_tris, num_glcmds, num_frames; int num_meshes, num_skins, num_xyz, num_st, num_tris, num_glcmds, num_frames;
int ofs_skins, ofs_st, ofs_tris, ofs_frames, ofs_glcmds, ofs_end; int ofs_meshes, ofs_skins, ofs_st, ofs_tris, ofs_frames, ofs_glcmds, ofs_end;
pinmodel = (mdl_header_t *)buffer; pinmodel = (mdl_header_t *)buffer;
@ -300,6 +302,7 @@ Mod_LoadModel_MDL(const char *mod_name, const void *buffer, int modfilelen,
} }
/* generate all offsets and sizes */ /* generate all offsets and sizes */
num_meshes = 1;
num_skins = LittleLong(pinmodel->num_skins); num_skins = LittleLong(pinmodel->num_skins);
skinwidth = LittleLong(pinmodel->skinwidth); skinwidth = LittleLong(pinmodel->skinwidth);
skinheight = LittleLong(pinmodel->skinheight); skinheight = LittleLong(pinmodel->skinheight);
@ -313,7 +316,8 @@ Mod_LoadModel_MDL(const char *mod_name, const void *buffer, int modfilelen,
num_frames = LittleLong(pinmodel->num_frames); num_frames = LittleLong(pinmodel->num_frames);
framesize = sizeof(daliasframe_t) + sizeof (dtrivertx_t) * (num_xyz - 1); framesize = sizeof(daliasframe_t) + sizeof (dtrivertx_t) * (num_xyz - 1);
ofs_skins = sizeof(*pheader); // just skip header and go ofs_meshes = sizeof(*pheader); // just skip header and go
ofs_skins = ofs_meshes + num_meshes * sizeof(dmdxmesh_t);
ofs_st = ofs_skins + num_skins * MAX_SKINNAME; ofs_st = ofs_skins + num_skins * MAX_SKINNAME;
ofs_tris = ofs_st + num_st * sizeof(dstvert_t); ofs_tris = ofs_st + num_st * sizeof(dstvert_t);
ofs_glcmds = ofs_tris + num_tris * sizeof(dtriangle_t); ofs_glcmds = ofs_tris + num_tris * sizeof(dtriangle_t);
@ -381,6 +385,7 @@ Mod_LoadModel_MDL(const char *mod_name, const void *buffer, int modfilelen,
pheader->skinheight = skinheight; pheader->skinheight = skinheight;
pheader->framesize = framesize; pheader->framesize = framesize;
pheader->num_meshes = num_meshes;
pheader->num_skins = num_skins; pheader->num_skins = num_skins;
pheader->num_xyz = num_xyz; pheader->num_xyz = num_xyz;
pheader->num_st = num_st; pheader->num_st = num_st;
@ -388,6 +393,7 @@ Mod_LoadModel_MDL(const char *mod_name, const void *buffer, int modfilelen,
pheader->num_glcmds = num_glcmds; pheader->num_glcmds = num_glcmds;
pheader->num_frames = num_frames; pheader->num_frames = num_frames;
pheader->ofs_meshes = ofs_meshes;
pheader->ofs_skins = ofs_skins; pheader->ofs_skins = ofs_skins;
pheader->ofs_st = ofs_st; pheader->ofs_st = ofs_st;
pheader->ofs_tris = ofs_tris; pheader->ofs_tris = ofs_tris;
@ -395,6 +401,11 @@ Mod_LoadModel_MDL(const char *mod_name, const void *buffer, int modfilelen,
pheader->ofs_glcmds = ofs_glcmds; pheader->ofs_glcmds = ofs_glcmds;
pheader->ofs_end = ofs_end; pheader->ofs_end = ofs_end;
/* create single mesh */
mesh_nodes = (dmdxmesh_t *)((char *)pheader + pheader->ofs_meshes);
mesh_nodes[0].start = 0;
mesh_nodes[0].num = num_glcmds;
{ {
int i; int i;
const byte *curr_pos; const byte *curr_pos;
@ -410,7 +421,7 @@ Mod_LoadModel_MDL(const char *mod_name, const void *buffer, int modfilelen,
char *out_pos; char *out_pos;
int skin_type; int skin_type;
out_pos = (char*)pheader + sizeof(*pheader); out_pos = (char*)pheader + pheader->ofs_skins;
snprintf(out_pos + MAX_SKINNAME * i, MAX_SKINNAME, "%s#%d.tga", mod_name, i); snprintf(out_pos + MAX_SKINNAME * i, MAX_SKINNAME, "%s#%d.tga", mod_name, i);
/* skip type / int */ /* skip type / int */
@ -588,12 +599,13 @@ Mod_LoadModel_MD2(const char *mod_name, const void *buffer, int modfilelen,
dmdx_t *pheader; dmdx_t *pheader;
dtriangle_t *pintri; dtriangle_t *pintri;
dstvert_t *pinst; dstvert_t *pinst;
dmdxmesh_t *mesh_nodes;
int *pincmd, header_diff; int *pincmd, header_diff;
void *extradata; void *extradata;
int i; int i;
/* fix for offset */ /* fix for offset */
header_diff = sizeof(*pheader) - sizeof(pinmodel); header_diff = sizeof(*pheader) - sizeof(pinmodel) + sizeof(dmdxmesh_t);
if (modfilelen < sizeof(pinmodel)) if (modfilelen < sizeof(pinmodel))
{ {
@ -639,21 +651,26 @@ Mod_LoadModel_MD2(const char *mod_name, const void *buffer, int modfilelen,
pheader->skinheight = pinmodel.skinheight; pheader->skinheight = pinmodel.skinheight;
pheader->framesize = pinmodel.framesize; pheader->framesize = pinmodel.framesize;
pheader->num_meshes = 1;
pheader->num_skins = pinmodel.num_skins; pheader->num_skins = pinmodel.num_skins;
pheader->num_xyz = pinmodel.num_xyz; pheader->num_xyz = pinmodel.num_xyz;
pheader->num_st = pinmodel.num_st; pheader->num_st = pinmodel.num_st;
pheader->num_tris = pinmodel.num_tris; pheader->num_tris = pinmodel.num_tris;
pheader->num_glcmds = pinmodel.num_glcmds; pheader->num_glcmds = pinmodel.num_glcmds;
pheader->num_frames = pinmodel.num_frames; pheader->num_frames = pinmodel.num_frames;
pheader->num_meshes = 0;
pheader->ofs_skins = header_diff + pinmodel.ofs_skins; pheader->ofs_meshes = sizeof(*pheader); // just skip header and go
pheader->ofs_st = header_diff + pinmodel.ofs_st; pheader->ofs_skins = pheader->ofs_meshes + pheader->num_meshes * sizeof(dmdxmesh_t);
pheader->ofs_tris = header_diff + pinmodel.ofs_tris; pheader->ofs_st = pheader->ofs_skins + pheader->num_skins * MAX_SKINNAME;
pheader->ofs_frames = header_diff + pinmodel.ofs_frames; pheader->ofs_tris = pheader->ofs_st + pheader->num_st * sizeof(dstvert_t);
pheader->ofs_glcmds = header_diff + pinmodel.ofs_glcmds; pheader->ofs_glcmds = pheader->ofs_tris + pheader->num_tris * sizeof(dtriangle_t);
pheader->ofs_meshes = 0; pheader->ofs_frames = pheader->ofs_glcmds + pheader->num_glcmds * sizeof(int);
pheader->ofs_end = header_diff + pinmodel.ofs_end; pheader->ofs_end = pheader->ofs_frames + pheader->framesize * pheader->num_frames;
/* create single mesh */
mesh_nodes = (dmdxmesh_t *)((char *)pheader + pheader->ofs_meshes);
mesh_nodes[0].start = 0;
mesh_nodes[0].num = pheader->num_glcmds;
if (pheader->skinheight > MAX_LBM_HEIGHT) if (pheader->skinheight > MAX_LBM_HEIGHT)
{ {
@ -1041,6 +1058,7 @@ Mod_LoadModel_DKM(const char *mod_name, const void *buffer, int modfilelen,
dmdx_t dmdxheader, *pheader = NULL; dmdx_t dmdxheader, *pheader = NULL;
dkm_header_t header = {0}; dkm_header_t header = {0};
void *extradata = NULL; void *extradata = NULL;
dmdxmesh_t *mesh_nodes;
int i; int i;
if (sizeof(dkm_header_t) > modfilelen) if (sizeof(dkm_header_t) > modfilelen)
@ -1088,6 +1106,7 @@ Mod_LoadModel_DKM(const char *mod_name, const void *buffer, int modfilelen,
dmdxheader.framesize += header.num_xyz * sizeof(dtrivertx_t); dmdxheader.framesize += header.num_xyz * sizeof(dtrivertx_t);
} }
dmdxheader.num_meshes = 1;
dmdxheader.num_skins = header.num_skins; dmdxheader.num_skins = header.num_skins;
dmdxheader.num_xyz = header.num_xyz; dmdxheader.num_xyz = header.num_xyz;
dmdxheader.num_st = header.num_st; dmdxheader.num_st = header.num_st;
@ -1096,7 +1115,8 @@ Mod_LoadModel_DKM(const char *mod_name, const void *buffer, int modfilelen,
dmdxheader.num_frames = header.num_frames; dmdxheader.num_frames = header.num_frames;
/* just skip header */ /* just skip header */
dmdxheader.ofs_skins = sizeof(dmdxheader); dmdxheader.ofs_meshes = sizeof(dmdxheader);
dmdxheader.ofs_skins = dmdxheader.ofs_meshes + dmdxheader.num_meshes * sizeof(dmdxmesh_t);
dmdxheader.ofs_st = dmdxheader.ofs_skins + dmdxheader.num_skins * MAX_SKINNAME; dmdxheader.ofs_st = dmdxheader.ofs_skins + dmdxheader.num_skins * MAX_SKINNAME;
dmdxheader.ofs_tris = dmdxheader.ofs_st + dmdxheader.num_st * sizeof(dstvert_t); dmdxheader.ofs_tris = dmdxheader.ofs_st + dmdxheader.num_st * sizeof(dstvert_t);
dmdxheader.ofs_frames = dmdxheader.ofs_tris + dmdxheader.num_tris * sizeof(dtriangle_t); dmdxheader.ofs_frames = dmdxheader.ofs_tris + dmdxheader.num_tris * sizeof(dtriangle_t);
@ -1110,6 +1130,11 @@ Mod_LoadModel_DKM(const char *mod_name, const void *buffer, int modfilelen,
memcpy(pheader, &dmdxheader, sizeof(dmdxheader)); memcpy(pheader, &dmdxheader, sizeof(dmdxheader));
/* create single mesh */
mesh_nodes = (dmdxmesh_t *)((char *)pheader + pheader->ofs_meshes);
mesh_nodes[0].start = 0;
mesh_nodes[0].num = pheader->num_glcmds;
memcpy ((byte*)pheader + pheader->ofs_skins, (byte *)buffer + header.ofs_skins, memcpy ((byte*)pheader + pheader->ofs_skins, (byte *)buffer + header.ofs_skins,
pheader->num_skins * MAX_SKINNAME); pheader->num_skins * MAX_SKINNAME);
Mod_LoadSTvertList (pheader, Mod_LoadSTvertList (pheader,

View file

@ -246,22 +246,12 @@ R_DrawAliasFrameLerp(entity_t *currententity, dmdx_t *paliashdr, float backlerp)
num_mesh_nodes = paliashdr->num_meshes; num_mesh_nodes = paliashdr->num_meshes;
mesh_nodes = (dmdxmesh_t *)((char*)paliashdr + paliashdr->ofs_meshes); mesh_nodes = (dmdxmesh_t *)((char*)paliashdr + paliashdr->ofs_meshes);
if (num_mesh_nodes > 0) for (i = 0; i < num_mesh_nodes; i++)
{
int i;
for (i = 0; i < num_mesh_nodes; i++)
{
R_DrawAliasDrawCommands(currententity,
order + mesh_nodes[i].start,
order + Q_min(
paliashdr->num_glcmds, mesh_nodes[i].start + mesh_nodes[i].num),
alpha, verts);
}
}
else
{ {
R_DrawAliasDrawCommands(currententity, R_DrawAliasDrawCommands(currententity,
order, order + paliashdr->num_glcmds, order + mesh_nodes[i].start,
order + Q_min(paliashdr->num_glcmds,
mesh_nodes[i].start + mesh_nodes[i].num),
alpha, verts); alpha, verts);
} }
@ -357,9 +347,8 @@ R_DrawAliasShadowCommand(entity_t *currententity, int *order, int *order_end,
static void static void
R_DrawAliasShadow(entity_t *currententity, dmdx_t *paliashdr, int posenum) R_DrawAliasShadow(entity_t *currententity, dmdx_t *paliashdr, int posenum)
{ {
int *order; int *order, i, num_mesh_nodes;
float height = 0, lheight; float height = 0, lheight;
int num_mesh_nodes;
dmdxmesh_t *mesh_nodes; dmdxmesh_t *mesh_nodes;
lheight = currententity->origin[2] - lightspot[2]; lheight = currententity->origin[2] - lightspot[2];
@ -377,21 +366,12 @@ R_DrawAliasShadow(entity_t *currententity, dmdx_t *paliashdr, int posenum)
num_mesh_nodes = paliashdr->num_meshes; num_mesh_nodes = paliashdr->num_meshes;
mesh_nodes = (dmdxmesh_t *)((char*)paliashdr + paliashdr->ofs_meshes); mesh_nodes = (dmdxmesh_t *)((char*)paliashdr + paliashdr->ofs_meshes);
if (num_mesh_nodes > 0) for (i = 0; i < num_mesh_nodes; i++)
{
int i;
for (i = 0; i < num_mesh_nodes; i++)
{
R_DrawAliasShadowCommand(currententity,
order + mesh_nodes[i].start,
order + Q_min(paliashdr->num_glcmds, mesh_nodes[i].start + mesh_nodes[i].num),
height, lheight);
}
}
else
{ {
R_DrawAliasShadowCommand(currententity, R_DrawAliasShadowCommand(currententity,
order, order + paliashdr->num_glcmds, order + mesh_nodes[i].start,
order + Q_min(paliashdr->num_glcmds,
mesh_nodes[i].start + mesh_nodes[i].num),
height, lheight); height, lheight);
} }

View file

@ -300,22 +300,12 @@ DrawAliasFrameLerp(dmdx_t *paliashdr, entity_t* entity, vec3_t shadelight)
num_mesh_nodes = paliashdr->num_meshes; num_mesh_nodes = paliashdr->num_meshes;
mesh_nodes = (dmdxmesh_t *)((char*)paliashdr + paliashdr->ofs_meshes); mesh_nodes = (dmdxmesh_t *)((char*)paliashdr + paliashdr->ofs_meshes);
if (num_mesh_nodes > 0) for (i = 0; i < num_mesh_nodes; i++)
{
int i;
for (i = 0; i < num_mesh_nodes; i++)
{
DrawAliasFrameLerpCommands(paliashdr, entity, shadelight,
order + mesh_nodes[i].start,
order + Q_min(paliashdr->num_glcmds,
mesh_nodes[i].start + mesh_nodes[i].num),
shadedots, alpha, colorOnly, verts);
}
}
else
{ {
DrawAliasFrameLerpCommands(paliashdr, entity, shadelight, DrawAliasFrameLerpCommands(paliashdr, entity, shadelight,
order, order + paliashdr->num_glcmds, order + mesh_nodes[i].start,
order + Q_min(paliashdr->num_glcmds,
mesh_nodes[i].start + mesh_nodes[i].num),
shadedots, alpha, colorOnly, verts); shadedots, alpha, colorOnly, verts);
} }
} }
@ -431,7 +421,7 @@ DrawAliasShadowCommands(int *order, int *order_end, vec3_t shadevector,
static void static void
DrawAliasShadow(gl3_shadowinfo_t* shadowInfo) DrawAliasShadow(gl3_shadowinfo_t* shadowInfo)
{ {
int *order; int *order, i;
float height = 0, lheight; float height = 0, lheight;
int num_mesh_nodes; int num_mesh_nodes;
dmdxmesh_t *mesh_nodes; dmdxmesh_t *mesh_nodes;
@ -450,7 +440,6 @@ DrawAliasShadow(gl3_shadowinfo_t* shadowInfo)
float frontlerp = 1.0f - backlerp; float frontlerp = 1.0f - backlerp;
vec3_t move, delta, vectors[3]; vec3_t move, delta, vectors[3];
vec3_t frontv, backv; vec3_t frontv, backv;
int i;
frame = (daliasframe_t *)((byte *)paliashdr + paliashdr->ofs_frames frame = (daliasframe_t *)((byte *)paliashdr + paliashdr->ofs_frames
+ entity->frame * paliashdr->framesize); + entity->frame * paliashdr->framesize);
@ -490,22 +479,13 @@ DrawAliasShadow(gl3_shadowinfo_t* shadowInfo)
num_mesh_nodes = paliashdr->num_meshes; num_mesh_nodes = paliashdr->num_meshes;
mesh_nodes = (dmdxmesh_t *)((char*)paliashdr + paliashdr->ofs_meshes); mesh_nodes = (dmdxmesh_t *)((char*)paliashdr + paliashdr->ofs_meshes);
if (num_mesh_nodes > 0) for (i = 0; i < num_mesh_nodes; i++)
{
int i;
for (i = 0; i < num_mesh_nodes; i++)
{
DrawAliasShadowCommands(
order + mesh_nodes[i].start,
order + Q_min(paliashdr->num_glcmds,
mesh_nodes[i].start + mesh_nodes[i].num),
shadevector, height, lheight);
}
}
else
{ {
DrawAliasShadowCommands( DrawAliasShadowCommands(
order, order + paliashdr->num_glcmds, shadevector, height, lheight); order + mesh_nodes[i].start,
order + Q_min(paliashdr->num_glcmds,
mesh_nodes[i].start + mesh_nodes[i].num),
shadevector, height, lheight);
} }
} }

View file

@ -486,23 +486,13 @@ Vk_DrawAliasFrameLerp(entity_t *currententity, dmdx_t *paliashdr, float backlerp
num_mesh_nodes = paliashdr->num_meshes; num_mesh_nodes = paliashdr->num_meshes;
mesh_nodes = (dmdxmesh_t *)((char*)paliashdr + paliashdr->ofs_meshes); mesh_nodes = (dmdxmesh_t *)((char*)paliashdr + paliashdr->ofs_meshes);
if (num_mesh_nodes > 0) for (i = 0; i < num_mesh_nodes; i++)
{
int i;
for (i = 0; i < num_mesh_nodes; i++)
{
Vk_DrawAliasFrameLerpCommands(currententity,
order + mesh_nodes[i].start,
order + Q_min(paliashdr->num_glcmds,
mesh_nodes[i].start + mesh_nodes[i].num),
alpha, skin,
modelMatrix, leftHandOffset, translucentIdx, verts);
}
}
else
{ {
Vk_DrawAliasFrameLerpCommands(currententity, Vk_DrawAliasFrameLerpCommands(currententity,
order, order + paliashdr->num_glcmds, alpha, skin, order + mesh_nodes[i].start,
order + Q_min(paliashdr->num_glcmds,
mesh_nodes[i].start + mesh_nodes[i].num),
alpha, skin,
modelMatrix, leftHandOffset, translucentIdx, verts); modelMatrix, leftHandOffset, translucentIdx, verts);
} }
} }
@ -1031,7 +1021,7 @@ R_DrawAliasModel(entity_t *currententity, const model_t *currentmodel)
if (vk_shadows->value && !(currententity->flags & (RF_TRANSLUCENT | RF_WEAPONMODEL))) if (vk_shadows->value && !(currententity->flags & (RF_TRANSLUCENT | RF_WEAPONMODEL)))
{ {
int num_mesh_nodes; int num_mesh_nodes, i;
dmdxmesh_t *mesh_nodes; dmdxmesh_t *mesh_nodes;
float model[16]; float model[16];
int *order; int *order;
@ -1044,21 +1034,12 @@ R_DrawAliasModel(entity_t *currententity, const model_t *currentmodel)
num_mesh_nodes = paliashdr->num_meshes; num_mesh_nodes = paliashdr->num_meshes;
mesh_nodes = (dmdxmesh_t *)((char*)paliashdr + paliashdr->ofs_meshes); mesh_nodes = (dmdxmesh_t *)((char*)paliashdr + paliashdr->ofs_meshes);
if (num_mesh_nodes > 0) for (i = 0; i < num_mesh_nodes; i++)
{ {
int i; Vk_DrawAliasShadow (
for (i = 0; i < num_mesh_nodes; i++) order + mesh_nodes[i].start,
{ order + Q_min(paliashdr->num_glcmds,
Vk_DrawAliasShadow ( mesh_nodes[i].start + mesh_nodes[i].num),
order + mesh_nodes[i].start,
order + Q_min(paliashdr->num_glcmds,
mesh_nodes[i].start + mesh_nodes[i].num),
currententity->frame, model, currententity);
}
}
else
{
Vk_DrawAliasShadow (order, order + paliashdr->num_glcmds,
currententity->frame, model, currententity); currententity->frame, model, currententity);
} }
} }