models: save embeded image
This commit is contained in:
parent
4d56576871
commit
b2d58ee171
|
@ -285,11 +285,12 @@ Mod_LoadModel_MDL(const char *mod_name, const void *buffer, int modfilelen,
|
||||||
void *extradata;
|
void *extradata;
|
||||||
dmdxmesh_t *mesh_nodes;
|
dmdxmesh_t *mesh_nodes;
|
||||||
|
|
||||||
|
|
||||||
/* local copy of all values */
|
/* local copy of all values */
|
||||||
int skinwidth, skinheight, framesize;
|
int skinwidth, skinheight, framesize;
|
||||||
int num_meshes, 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,
|
||||||
int ofs_meshes, ofs_skins, ofs_st, ofs_tris, ofs_frames, ofs_glcmds, ofs_end;
|
num_frames;
|
||||||
|
int ofs_meshes, ofs_skins, ofs_st, ofs_tris, ofs_frames, ofs_glcmds,
|
||||||
|
ofs_imgbit, ofs_end;
|
||||||
|
|
||||||
pinmodel = (mdl_header_t *)buffer;
|
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_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);
|
||||||
ofs_frames = ofs_glcmds + num_glcmds * sizeof(int);
|
ofs_frames = ofs_glcmds + num_glcmds * sizeof(int);
|
||||||
|
ofs_imgbit = ofs_frames + framesize * num_frames;
|
||||||
/* one less as single vertx in frame by default */
|
/* 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 */
|
/* validate */
|
||||||
if (skinheight > MAX_LBM_HEIGHT)
|
if (skinheight > MAX_LBM_HEIGHT)
|
||||||
|
@ -368,13 +370,6 @@ Mod_LoadModel_MDL(const char *mod_name, const void *buffer, int modfilelen,
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (modfilelen < ofs_end)
|
|
||||||
{
|
|
||||||
R_Printf(PRINT_ALL, "%s: model %s is too big.",
|
|
||||||
__func__, mod_name);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
*numskins = num_skins;
|
*numskins = num_skins;
|
||||||
extradata = Hunk_Begin(ofs_end + Q_max(*numskins, MAX_MD2SKINS) * sizeof(struct image_s *));
|
extradata = Hunk_Begin(ofs_end + Q_max(*numskins, MAX_MD2SKINS) * sizeof(struct image_s *));
|
||||||
pheader = Hunk_Alloc(ofs_end);
|
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_st = num_st;
|
||||||
pheader->num_tris = num_tris;
|
pheader->num_tris = num_tris;
|
||||||
pheader->num_glcmds = num_glcmds;
|
pheader->num_glcmds = num_glcmds;
|
||||||
|
pheader->num_imgbit = 8;
|
||||||
pheader->num_frames = num_frames;
|
pheader->num_frames = num_frames;
|
||||||
|
|
||||||
pheader->ofs_meshes = ofs_meshes;
|
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_tris = ofs_tris;
|
||||||
pheader->ofs_frames = ofs_frames;
|
pheader->ofs_frames = ofs_frames;
|
||||||
pheader->ofs_glcmds = ofs_glcmds;
|
pheader->ofs_glcmds = ofs_glcmds;
|
||||||
|
pheader->ofs_imgbit = ofs_imgbit;
|
||||||
pheader->ofs_end = ofs_end;
|
pheader->ofs_end = ofs_end;
|
||||||
|
|
||||||
/* create single mesh */
|
/* create single mesh */
|
||||||
|
@ -436,7 +433,11 @@ Mod_LoadModel_MDL(const char *mod_name, const void *buffer, int modfilelen,
|
||||||
return NULL;
|
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;
|
curr_pos += skinwidth * skinheight;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -265,6 +265,7 @@ typedef struct
|
||||||
int num_glcmds; /* dwords in strip/fan command list */
|
int num_glcmds; /* dwords in strip/fan command list */
|
||||||
int num_frames;
|
int num_frames;
|
||||||
int num_meshes;
|
int num_meshes;
|
||||||
|
int num_imgbit; /* image format of embeded images */
|
||||||
|
|
||||||
int ofs_skins; /* each skin is a MAX_SKINNAME string */
|
int ofs_skins; /* each skin is a MAX_SKINNAME string */
|
||||||
int ofs_st; /* byte offset from start for stverts */
|
int ofs_st; /* byte offset from start for stverts */
|
||||||
|
@ -272,6 +273,7 @@ typedef struct
|
||||||
int ofs_frames; /* offset for first frame */
|
int ofs_frames; /* offset for first frame */
|
||||||
int ofs_glcmds;
|
int ofs_glcmds;
|
||||||
int ofs_meshes;
|
int ofs_meshes;
|
||||||
|
int ofs_imgbit; /* offest of embeded image */
|
||||||
int ofs_end; /* end of file */
|
int ofs_end; /* end of file */
|
||||||
} dmdx_t;
|
} dmdx_t;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue