models: save embeded image

This commit is contained in:
Denis Pauk 2023-12-28 08:46:45 +02:00
parent 4d56576871
commit b2d58ee171
2 changed files with 24 additions and 21 deletions

View File

@ -285,11 +285,12 @@ Mod_LoadModel_MDL(const char *mod_name, const void *buffer, int modfilelen,
void *extradata;
dmdxmesh_t *mesh_nodes;
/* local copy of all values */
int skinwidth, skinheight, framesize;
int num_meshes, num_skins, num_xyz, num_st, num_tris, num_glcmds, num_frames;
int ofs_meshes, ofs_skins, ofs_st, ofs_tris, ofs_frames, ofs_glcmds, ofs_end;
int num_meshes, num_skins, num_xyz, num_st, num_tris, num_glcmds,
num_frames;
int ofs_meshes, ofs_skins, ofs_st, ofs_tris, ofs_frames, ofs_glcmds,
ofs_imgbit, ofs_end;
pinmodel = (mdl_header_t *)buffer;
@ -322,8 +323,9 @@ Mod_LoadModel_MDL(const char *mod_name, const void *buffer, int modfilelen,
ofs_tris = ofs_st + num_st * sizeof(dstvert_t);
ofs_glcmds = ofs_tris + num_tris * sizeof(dtriangle_t);
ofs_frames = ofs_glcmds + num_glcmds * sizeof(int);
ofs_imgbit = ofs_frames + framesize * num_frames;
/* one less as single vertx in frame by default */
ofs_end = ofs_frames + framesize * num_frames;
ofs_end = ofs_imgbit + (skinwidth * skinheight * num_skins);
/* validate */
if (skinheight > MAX_LBM_HEIGHT)
@ -368,13 +370,6 @@ Mod_LoadModel_MDL(const char *mod_name, const void *buffer, int modfilelen,
return NULL;
}
if (modfilelen < ofs_end)
{
R_Printf(PRINT_ALL, "%s: model %s is too big.",
__func__, mod_name);
return NULL;
}
*numskins = num_skins;
extradata = Hunk_Begin(ofs_end + Q_max(*numskins, MAX_MD2SKINS) * sizeof(struct image_s *));
pheader = Hunk_Alloc(ofs_end);
@ -391,6 +386,7 @@ Mod_LoadModel_MDL(const char *mod_name, const void *buffer, int modfilelen,
pheader->num_st = num_st;
pheader->num_tris = num_tris;
pheader->num_glcmds = num_glcmds;
pheader->num_imgbit = 8;
pheader->num_frames = num_frames;
pheader->ofs_meshes = ofs_meshes;
@ -399,6 +395,7 @@ Mod_LoadModel_MDL(const char *mod_name, const void *buffer, int modfilelen,
pheader->ofs_tris = ofs_tris;
pheader->ofs_frames = ofs_frames;
pheader->ofs_glcmds = ofs_glcmds;
pheader->ofs_imgbit = ofs_imgbit;
pheader->ofs_end = ofs_end;
/* create single mesh */
@ -436,7 +433,11 @@ Mod_LoadModel_MDL(const char *mod_name, const void *buffer, int modfilelen,
return NULL;
}
/* skip 8bit image */
/* copy 8bit image */
memcpy((byte*)pheader + pheader->ofs_imgbit +
(skinwidth * skinheight * i),
curr_pos,
skinwidth * skinheight);
curr_pos += skinwidth * skinheight;
}

View File

@ -265,6 +265,7 @@ typedef struct
int num_glcmds; /* dwords in strip/fan command list */
int num_frames;
int num_meshes;
int num_imgbit; /* image format of embeded images */
int ofs_skins; /* each skin is a MAX_SKINNAME string */
int ofs_st; /* byte offset from start for stverts */
@ -272,6 +273,7 @@ typedef struct
int ofs_frames; /* offset for first frame */
int ofs_glcmds;
int ofs_meshes;
int ofs_imgbit; /* offest of embeded image */
int ofs_end; /* end of file */
} dmdx_t;