Browse Source

utils: mdldec: small optimizations.

pull/2/head
Andrey Akhmichin 12 months ago committed by Alibek Omarov
parent
commit
fc55a685e3
  1. 20
      utils/mdldec/mdldec.c
  2. 76
      utils/mdldec/qc.c
  3. 79
      utils/mdldec/smd.c
  4. 18
      utils/mdldec/texture.c

20
utils/mdldec/mdldec.c

@ -41,21 +41,17 @@ static void SequenceNameFix( void )
{ {
int i, j, counter; int i, j, counter;
qboolean hasduplicates = false; qboolean hasduplicates = false;
mstudioseqdesc_t *seqdesc, *seqdesc1; mstudioseqdesc_t *seqdesc = (mstudioseqdesc_t *)( (byte *)model_hdr + model_hdr->seqindex ), *seqdesc1;
for( i = 0; i < model_hdr->numseq; i++ ) for( i = 0; i < model_hdr->numseq; ++i, ++seqdesc )
{ {
seqdesc = (mstudioseqdesc_t *)( (byte *)model_hdr + model_hdr->seqindex ) + i;
counter = 1; counter = 1;
for( j = 0; j < model_hdr->numseq; j++ ) seqdesc1 = (mstudioseqdesc_t *)( (byte *)model_hdr + model_hdr->seqindex );
{
seqdesc1 = (mstudioseqdesc_t *)( (byte *)model_hdr + model_hdr->seqindex ) + j;
for( j = 0; j < model_hdr->numseq; ++j, ++seqdesc1 )
if( j != i && !Q_strncmp( seqdesc1->label, seqdesc->label, sizeof( seqdesc1->label ) ) ) if( j != i && !Q_strncmp( seqdesc1->label, seqdesc->label, sizeof( seqdesc1->label ) ) )
Q_snprintf( seqdesc1->label, sizeof( seqdesc1->label ), "%s_%i", seqdesc1->label, ++counter ); Q_snprintf( seqdesc1->label, sizeof( seqdesc1->label ), "%s_%i", seqdesc1->label, ++counter );
}
if( counter > 1 ) if( counter > 1 )
{ {
@ -79,15 +75,11 @@ BoneNameFix
static void BoneNameFix( void ) static void BoneNameFix( void )
{ {
int i, counter = 0; int i, counter = 0;
mstudiobone_t *bone; mstudiobone_t *bone = (mstudiobone_t *)( (byte *)model_hdr + model_hdr->boneindex );
for( i = 0; i < model_hdr->numbones; i++ )
{
bone = (mstudiobone_t *)( (byte *)model_hdr + model_hdr->boneindex ) + i;
for( i = 0; i < model_hdr->numbones; ++i, ++bone )
if( bone->name[0] == '\0' ) if( bone->name[0] == '\0' )
Q_snprintf( bone->name, sizeof( bone->name ), "MDLDEC_Bone%i", ++counter ); Q_snprintf( bone->name, sizeof( bone->name ), "MDLDEC_Bone%i", ++counter );
}
if( counter ) if( counter )
printf( "WARNING: Gived name to %i unnamed bone(s).\n", counter ); printf( "WARNING: Gived name to %i unnamed bone(s).\n", counter );

76
utils/mdldec/qc.c

@ -249,7 +249,7 @@ WriteSkinFamilyInfo
static void WriteSkinFamilyInfo( FILE *fp ) static void WriteSkinFamilyInfo( FILE *fp )
{ {
int i, j, k; int i, j, k;
short *skinref, index; short *skinref, *index;
mstudiotexture_t *texture; mstudiotexture_t *texture;
if( texture_hdr->numskinfamilies < 2 ) if( texture_hdr->numskinfamilies < 2 )
@ -260,23 +260,22 @@ static void WriteSkinFamilyInfo( FILE *fp )
fputs( "$texturegroup \"skinfamilies\"\n{\n", fp ); fputs( "$texturegroup \"skinfamilies\"\n{\n", fp );
skinref = (short *)( (byte *)texture_hdr + texture_hdr->skinindex ); skinref = (short *)( (byte *)texture_hdr + texture_hdr->skinindex );
texture = (mstudiotexture_t *)( (byte *)texture_hdr + texture_hdr->textureindex );
for( i = 0; i < texture_hdr->numskinfamilies; ++i ) for( i = 0; i < texture_hdr->numskinfamilies; ++i )
{ {
fputs( "\t{\n", fp ); fputs( "\t{\n", fp );
for( j = 0; j < texture_hdr->numskinref; ++j ) index = skinref + i * texture_hdr->numskinref;
{
index = *( skinref + i * texture_hdr->numskinref + j );
for( j = 0; j < texture_hdr->numskinref; ++j, ++index )
{
for( k = 0; k < texture_hdr->numskinfamilies; ++k ) for( k = 0; k < texture_hdr->numskinfamilies; ++k )
{ {
if( index == *( skinref + k * texture_hdr->numskinref + j ) ) if( *index == *( skinref + k * texture_hdr->numskinref + j ) )
continue; continue;
texture = (mstudiotexture_t *)( (byte *)texture_hdr + texture_hdr->textureindex ) + index; fprintf( fp, "\t\t\"%s\"\n", texture[*index].name );
fprintf( fp, "\t\t\"%s\"\n", texture->name );
break; break;
} }
} }
@ -301,15 +300,13 @@ static void WriteAttachmentInfo( FILE *fp )
if( !model_hdr->numattachments ) if( !model_hdr->numattachments )
return; return;
fprintf( fp, "// %i attachment%s\n", model_hdr->numattachments, model_hdr->numattachments > 1 ? "s" : "" ); attachment = (mstudioattachment_t *)( (byte *)model_hdr + model_hdr->attachmentindex );
bone = (mstudiobone_t *)( (byte *)model_hdr + model_hdr->boneindex );
for( i = 0; i < model_hdr->numattachments; ++i ) fprintf( fp, "// %i attachment%s\n", model_hdr->numattachments, model_hdr->numattachments > 1 ? "s" : "" );
{
attachment = (mstudioattachment_t *)( (byte *)model_hdr + model_hdr->attachmentindex ) + i;
bone = (mstudiobone_t *)( (byte *)model_hdr + model_hdr->boneindex ) + attachment->bone;
fprintf( fp, "$attachment %i \"%s\" %f %f %f\n", i, bone->name, attachment->org[0], attachment->org[1], attachment->org[2] ); for( i = 0; i < model_hdr->numattachments; ++i, ++attachment )
} fprintf( fp, "$attachment %i \"%s\" %f %f %f\n", i, bone[attachment->bone].name, attachment->org[0], attachment->org[1], attachment->org[2] );
fputs( "\n", fp ); fputs( "\n", fp );
} }
@ -322,20 +319,18 @@ WriteBodyGroupInfo
static void WriteBodyGroupInfo( FILE *fp ) static void WriteBodyGroupInfo( FILE *fp )
{ {
int i, j; int i, j;
mstudiobodyparts_t *bodypart; mstudiobodyparts_t *bodypart = (mstudiobodyparts_t *) ( (byte *)model_hdr + model_hdr->bodypartindex );
mstudiomodel_t *model; mstudiomodel_t *model;
char modelname[64]; char modelname[64];
fprintf( fp, "// %i reference mesh%s\n", model_hdr->numbodyparts, model_hdr->numbodyparts > 1 ? "es" : "" ); fprintf( fp, "// %i reference mesh%s\n", model_hdr->numbodyparts, model_hdr->numbodyparts > 1 ? "es" : "" );
for( i = 0; i < model_hdr->numbodyparts; ++i ) for( i = 0; i < model_hdr->numbodyparts; ++i, ++bodypart )
{ {
bodypart = (mstudiobodyparts_t *) ( (byte *)model_hdr + model_hdr->bodypartindex ) + i; model = (mstudiomodel_t *)( (byte *)model_hdr + bodypart->modelindex );
if( bodypart->nummodels == 1 ) if( bodypart->nummodels == 1 )
{ {
model = (mstudiomodel_t *)( (byte *)model_hdr + bodypart->modelindex );
COM_FileBase( model->name, modelname, sizeof( modelname )); COM_FileBase( model->name, modelname, sizeof( modelname ));
fprintf( fp, "$body \"%s\" \"%s\"\n", bodypart->name, modelname ); fprintf( fp, "$body \"%s\" \"%s\"\n", bodypart->name, modelname );
@ -346,10 +341,8 @@ static void WriteBodyGroupInfo( FILE *fp )
fputs( "{\n", fp ); fputs( "{\n", fp );
for( j = 0; j < bodypart->nummodels; ++j ) for( j = 0; j < bodypart->nummodels; ++j, ++model )
{ {
model = (mstudiomodel_t *)( (byte *)model_hdr + bodypart->modelindex ) + j;
if( !Q_strncmp( model->name, "blank", 5 ) ) if( !Q_strncmp( model->name, "blank", 5 ) )
{ {
fputs( "\tblank\n", fp ); fputs( "\tblank\n", fp );
@ -382,13 +375,13 @@ static void WriteControllerInfo( FILE *fp )
if( !model_hdr->numbonecontrollers ) if( !model_hdr->numbonecontrollers )
return; return;
bonecontroller = (mstudiobonecontroller_t *)( (byte *)model_hdr + model_hdr->bonecontrollerindex );
bone = (mstudiobone_t *)( (byte *)model_hdr + model_hdr->boneindex );
fprintf( fp, "// %i bone controller%s\n", model_hdr->numbonecontrollers, model_hdr->numbonecontrollers > 1 ? "s" : "" ); fprintf( fp, "// %i bone controller%s\n", model_hdr->numbonecontrollers, model_hdr->numbonecontrollers > 1 ? "s" : "" );
for( i = 0; i < model_hdr->numbonecontrollers; ++i ) for( i = 0; i < model_hdr->numbonecontrollers; ++i, ++bonecontroller )
{ {
bonecontroller = (mstudiobonecontroller_t *)( (byte *)model_hdr + model_hdr->bonecontrollerindex ) + i;
bone = (mstudiobone_t *)( (byte *)model_hdr + model_hdr->boneindex ) + bonecontroller->bone;
GetMotionTypeString( bonecontroller->type & ~STUDIO_RLOOP, motion_types, sizeof( motion_types ), false ); GetMotionTypeString( bonecontroller->type & ~STUDIO_RLOOP, motion_types, sizeof( motion_types ), false );
fputs( "$controller ", fp ); fputs( "$controller ", fp );
@ -399,7 +392,7 @@ static void WriteControllerInfo( FILE *fp )
fprintf( fp, "%i", bonecontroller->index ); fprintf( fp, "%i", bonecontroller->index );
fprintf( fp, " \"%s\" %s %f %f\n", fprintf( fp, " \"%s\" %s %f %f\n",
bone->name, motion_types, bone[bonecontroller->bone].name, motion_types,
bonecontroller->start, bonecontroller->end ); bonecontroller->start, bonecontroller->end );
} }
@ -420,18 +413,16 @@ static void WriteHitBoxInfo( FILE *fp )
if( !model_hdr->numhitboxes ) if( !model_hdr->numhitboxes )
return; return;
fprintf( fp, "// %i hit box%s\n", model_hdr->numhitboxes, model_hdr->numhitboxes > 1 ? "es" : "" ); hitbox = (mstudiobbox_t *)( (byte *)model_hdr + model_hdr->hitboxindex );
bone = (mstudiobone_t *)( (byte *)model_hdr + model_hdr->boneindex );
for( i = 0; i < model_hdr->numhitboxes; i++ ) fprintf( fp, "// %i hit box%s\n", model_hdr->numhitboxes, model_hdr->numhitboxes > 1 ? "es" : "" );
{
hitbox = (mstudiobbox_t *)( (byte *)model_hdr + model_hdr->hitboxindex ) + i;
bone = (mstudiobone_t *)( (byte *)model_hdr + model_hdr->boneindex ) + hitbox->bone;
for( i = 0; i < model_hdr->numhitboxes; ++i, ++hitbox )
fprintf( fp, "$hbox %i \"%s\" %f %f %f %f %f %f\n", fprintf( fp, "$hbox %i \"%s\" %f %f %f %f %f %f\n",
hitbox->group, bone->name, hitbox->group, bone[hitbox->bone].name,
hitbox->bbmin[0], hitbox->bbmin[1], hitbox->bbmin[2], hitbox->bbmin[0], hitbox->bbmin[1], hitbox->bbmin[2],
hitbox->bbmax[0], hitbox->bbmax[1], hitbox->bbmax[2] ); hitbox->bbmax[0], hitbox->bbmax[1], hitbox->bbmax[2] );
}
fputs( "\n", fp ); fputs( "\n", fp );
} }
@ -477,20 +468,19 @@ static void WriteSequenceInfo( FILE *fp )
if( model_hdr->numseq > 0 ) if( model_hdr->numseq > 0 )
fprintf( fp, "// %i animation sequence%s\n", model_hdr->numseq, model_hdr->numseq > 1 ? "s" : "" ); fprintf( fp, "// %i animation sequence%s\n", model_hdr->numseq, model_hdr->numseq > 1 ? "s" : "" );
else return;
for( i = 0; i < model_hdr->numseq; ++i ) seqdesc = (mstudioseqdesc_t *)( (byte *)model_hdr + model_hdr->seqindex );
{
seqdesc = (mstudioseqdesc_t *)( (byte *)model_hdr + model_hdr->seqindex ) + i;
for( i = 0; i < model_hdr->numseq; ++i, ++seqdesc )
{
fprintf( fp, "$sequence \"%s\" {\n", seqdesc->label ); fprintf( fp, "$sequence \"%s\" {\n", seqdesc->label );
if( seqdesc->numblends > 1 ) if( seqdesc->numblends > 1 )
{ {
for( j = 0; j < seqdesc->numblends; j++ ) for( j = 0; j < seqdesc->numblends; j++ )
{
fprintf( fp, "\t\"%s_blend%02i\"\n", seqdesc->label, j + 1 ); fprintf( fp, "\t\"%s_blend%02i\"\n", seqdesc->label, j + 1 );
} }
}
else else
{ {
fprintf( fp, "\t\"%s\"\n", seqdesc->label ); fprintf( fp, "\t\"%s\"\n", seqdesc->label );
@ -524,10 +514,10 @@ static void WriteSequenceInfo( FILE *fp )
printf( "WARNING: Something wrong with blending type for sequence: %s\n", seqdesc->label ); printf( "WARNING: Something wrong with blending type for sequence: %s\n", seqdesc->label );
} }
for( j = 0; j < seqdesc->numevents; j++ ) event = (mstudioevent_t *)( (byte *)model_hdr + seqdesc->eventindex );
{
event = (mstudioevent_t *)( (byte *)model_hdr + seqdesc->eventindex ) + j;
for( j = 0; j < seqdesc->numevents; ++j, ++event )
{
fprintf( fp, "\t{ event %i %i", event->event, event->frame ); fprintf( fp, "\t{ event %i %i", event->event, event->frame );
if( event->options[0] != '\0' ) if( event->options[0] != '\0' )

79
utils/mdldec/smd.c

@ -53,14 +53,12 @@ FillBoneTransformMatrices
static void FillBoneTransformMatrices( void ) static void FillBoneTransformMatrices( void )
{ {
int i; int i;
mstudiobone_t *bone; mstudiobone_t *bone = (mstudiobone_t *)( (byte *)model_hdr + model_hdr->boneindex );
matrix3x4 bonematrix; matrix3x4 bonematrix;
vec4_t q; vec4_t q;
for( i = 0; i < model_hdr->numbones; i++ ) for( i = 0; i < model_hdr->numbones; ++i, ++bone )
{ {
bone = (mstudiobone_t *)( (byte *)model_hdr + model_hdr->boneindex ) + i;
AngleQuaternion( &bone->value[3], q, true ); AngleQuaternion( &bone->value[3], q, true );
Matrix3x4_FromOriginQuat( bonematrix, q, bone->value ); Matrix3x4_FromOriginQuat( bonematrix, q, bone->value );
@ -84,7 +82,7 @@ static void FillWorldTransformMatrices( void )
int i; int i;
mstudioboneinfo_t *boneinfo = (mstudioboneinfo_t *)( (byte *)model_hdr + model_hdr->boneindex + model_hdr->numbones * sizeof( mstudiobone_t ) ); mstudioboneinfo_t *boneinfo = (mstudioboneinfo_t *)( (byte *)model_hdr + model_hdr->boneindex + model_hdr->numbones * sizeof( mstudiobone_t ) );
for( i = 0; i < model_hdr->numbones; i++, boneinfo++ ) for( i = 0; i < model_hdr->numbones; ++i, ++boneinfo )
Matrix3x4_ConcatTransforms( worldtransform[i], bonetransform[i], boneinfo->poseToBone ); Matrix3x4_ConcatTransforms( worldtransform[i], bonetransform[i], boneinfo->poseToBone );
} }
@ -186,16 +184,12 @@ WriteNodes
static void WriteNodes( FILE *fp ) static void WriteNodes( FILE *fp )
{ {
int i; int i;
mstudiobone_t *bone; mstudiobone_t *bone = (mstudiobone_t *)( (byte *)model_hdr + model_hdr->boneindex );
fputs( "nodes\n", fp ); fputs( "nodes\n", fp );
for( i = 0; i < model_hdr->numbones; i++ ) for( i = 0; i < model_hdr->numbones; ++i, ++bone )
{
bone = (mstudiobone_t *)( (byte *)model_hdr + model_hdr->boneindex ) + i;
fprintf( fp, "%3i \"%s\" %i\n", i, bone->name, bone->parent ); fprintf( fp, "%3i \"%s\" %i\n", i, bone->name, bone->parent );
}
fputs( "end\n", fp ); fputs( "end\n", fp );
} }
@ -208,15 +202,13 @@ WriteSkeleton
static void WriteSkeleton( FILE *fp ) static void WriteSkeleton( FILE *fp )
{ {
int i, j; int i, j;
mstudiobone_t *bone; mstudiobone_t *bone = (mstudiobone_t *)( (byte *)model_hdr + model_hdr->boneindex );
fputs( "skeleton\n", fp ); fputs( "skeleton\n", fp );
fputs( "time 0\n", fp ); fputs( "time 0\n", fp );
for( i = 0; i < model_hdr->numbones; i++ ) for( i = 0; i < model_hdr->numbones; ++i, ++bone )
{ {
bone = (mstudiobone_t *)( (byte *)model_hdr + model_hdr->boneindex ) + i;
fprintf( fp, "%3i", i ); fprintf( fp, "%3i", i );
for( j = 0; j < 6; j++ ) for( j = 0; j < 6; j++ )
@ -235,7 +227,7 @@ WriteTriangleInfo
*/ */
static void WriteTriangleInfo( FILE *fp, mstudiomodel_t *model, mstudiotexture_t *texture, mstudiotrivert_t **triverts, qboolean isevenstrip ) static void WriteTriangleInfo( FILE *fp, mstudiomodel_t *model, mstudiotexture_t *texture, mstudiotrivert_t **triverts, qboolean isevenstrip )
{ {
int i, j, k, l, indices[3]; int i, j, k, l, index;
int vert_index; int vert_index;
int norm_index; int norm_index;
int bone_index; int bone_index;
@ -249,19 +241,6 @@ static void WriteTriangleInfo( FILE *fp, mstudiomodel_t *model, mstudiotexture_t
matrix3x4 bonematrix[MAXSTUDIOBONEWEIGHTS], skinmatrix, *pskinmatrix; matrix3x4 bonematrix[MAXSTUDIOBONEWEIGHTS], skinmatrix, *pskinmatrix;
mstudioboneweight_t *studioboneweights; mstudioboneweight_t *studioboneweights;
if( isevenstrip )
{
indices[0] = 1;
indices[1] = 2;
indices[2] = 0;
}
else
{
indices[0] = 0;
indices[1] = 1;
indices[2] = 2;
}
vertbone = ( (byte *)model_hdr + model->vertinfoindex ); vertbone = ( (byte *)model_hdr + model->vertinfoindex );
studioverts = (vec3_t *)( (byte *)model_hdr + model->vertindex ); studioverts = (vec3_t *)( (byte *)model_hdr + model->vertindex );
studionorms = (vec3_t *)( (byte *)model_hdr + model->normindex ); studionorms = (vec3_t *)( (byte *)model_hdr + model->normindex );
@ -274,14 +253,15 @@ static void WriteTriangleInfo( FILE *fp, mstudiomodel_t *model, mstudiotexture_t
for( i = 0; i < 3; i++ ) for( i = 0; i < 3; i++ )
{ {
vert_index = triverts[indices[i]]->vertindex; index = isevenstrip ? ( i + 1 ) % 3 : i;
norm_index = triverts[indices[i]]->normindex; vert_index = triverts[index]->vertindex;
norm_index = triverts[index]->normindex;
bone_index = vertbone[vert_index]; bone_index = vertbone[vert_index];
if( model_hdr->flags & STUDIO_HAS_BONEWEIGHTS ) if( model_hdr->flags & STUDIO_HAS_BONEWEIGHTS )
{ {
valid_bones = 0, totalweight = 0; valid_bones = 0, totalweight = 0;
memset(skinmatrix, 0, sizeof(matrix3x4)); memset( skinmatrix, 0, sizeof( matrix3x4 ) );
for( j = 0; j < MAXSTUDIOBONEWEIGHTS; ++j ) for( j = 0; j < MAXSTUDIOBONEWEIGHTS; ++j )
if( studioboneweights[vert_index].bone[j] != -1 ) if( studioboneweights[vert_index].bone[j] != -1 )
@ -315,13 +295,13 @@ static void WriteTriangleInfo( FILE *fp, mstudiomodel_t *model, mstudiotexture_t
if( texture->flags & STUDIO_NF_UV_COORDS ) if( texture->flags & STUDIO_NF_UV_COORDS )
{ {
u = HalfToFloat( triverts[indices[i]]->s ); u = HalfToFloat( triverts[index]->s );
v = -HalfToFloat( triverts[indices[i]]->t ); v = -HalfToFloat( triverts[index]->t );
} }
else else
{ {
u = ( triverts[indices[i]]->s + 1.0f ) * s; u = ( triverts[index]->s + 1.0f ) * s;
v = 1.0f - triverts[indices[i]]->t * t; v = 1.0f - triverts[index]->t * t;
} }
fprintf( fp, "%3i %f %f %f %f %f %f %f %f", fprintf( fp, "%3i %f %f %f %f %f %f %f %f",
@ -354,16 +334,15 @@ WriteTriangles
static void WriteTriangles( FILE *fp, mstudiomodel_t *model ) static void WriteTriangles( FILE *fp, mstudiomodel_t *model )
{ {
int i, j, k; int i, j, k;
mstudiomesh_t *mesh; mstudiomesh_t *mesh = (mstudiomesh_t *)( (byte *)model_hdr + model->meshindex );
mstudiotexture_t *texture; mstudiotexture_t *texture;
mstudiotrivert_t *triverts[3]; mstudiotrivert_t *triverts[3];
short *tricmds; short *tricmds;
fputs( "triangles\n", fp ); fputs( "triangles\n", fp );
for( i = 0; i < model->nummesh; i++ ) for( i = 0; i < model->nummesh; ++i, ++mesh )
{ {
mesh = (mstudiomesh_t *)( (byte *)model_hdr + model->meshindex ) + i;
tricmds = (short *)( (byte *)model_hdr + mesh->triindex ); tricmds = (short *)( (byte *)model_hdr + mesh->triindex );
texture = (mstudiotexture_t *)( (byte *)texture_hdr + texture_hdr->textureindex ) + mesh->skinref; texture = (mstudiotexture_t *)( (byte *)texture_hdr + texture_hdr->textureindex ) + mesh->skinref;
@ -450,14 +429,12 @@ static void WriteFrameInfo( FILE *fp, mstudioanim_t *anim, mstudioseqdesc_t *seq
int i, j; int i, j;
float scale; float scale;
vec_t motion[6]; // x, y, z, xr, yr, zr vec_t motion[6]; // x, y, z, xr, yr, zr
mstudiobone_t *bone; mstudiobone_t *bone = (mstudiobone_t *)( (byte *)model_hdr + model_hdr->boneindex );
fprintf( fp, "time %i\n", frame ); fprintf( fp, "time %i\n", frame );
for( i = 0; i < model_hdr->numbones; i++, anim++ ) for( i = 0; i < model_hdr->numbones; ++i, ++anim, ++bone )
{ {
bone = (mstudiobone_t *)( (byte *)model_hdr + model_hdr->boneindex ) + i;
CalcBonePosition( anim, bone, motion, frame ); CalcBonePosition( anim, bone, motion, frame );
if( bone->parent == -1 ) if( bone->parent == -1 )
@ -529,14 +506,14 @@ static void WriteReferences( void )
FillWorldTransformMatrices(); FillWorldTransformMatrices();
} }
for( i = 0; i < model_hdr->numbodyparts; i++ ) bodypart = (mstudiobodyparts_t *)( (byte *)model_hdr + model_hdr->bodypartindex );
{
bodypart = (mstudiobodyparts_t *)( (byte *)model_hdr + model_hdr->bodypartindex ) + i;
for( j = 0; j < bodypart->nummodels; j++ ) for( i = 0; i < model_hdr->numbodyparts; ++i, ++bodypart )
{ {
model = (mstudiomodel_t *)( (byte *)model_hdr + bodypart->modelindex ) + j; model = (mstudiomodel_t *)( (byte *)model_hdr + bodypart->modelindex );
for( j = 0; j < bodypart->nummodels; ++j, ++model )
{
if( !Q_strncmp( model->name, "blank", 5 ) ) if( !Q_strncmp( model->name, "blank", 5 ) )
continue; continue;
@ -588,12 +565,10 @@ static void WriteSequences( void )
int len; int len;
FILE *fp; FILE *fp;
char filename[MAX_SYSPATH]; char filename[MAX_SYSPATH];
mstudioseqdesc_t *seqdesc; mstudioseqdesc_t *seqdesc = (mstudioseqdesc_t *)( (byte *)model_hdr + model_hdr->seqindex );
for( i = 0; i < model_hdr->numseq; i++ ) for( i = 0; i < model_hdr->numseq; ++i, ++seqdesc )
{ {
seqdesc = (mstudioseqdesc_t *)( (byte *)model_hdr + model_hdr->seqindex ) + i;
for( j = 0; j < seqdesc->numblends; j++ ) for( j = 0; j < seqdesc->numblends; j++ )
{ {
if( seqdesc->numblends == 1 ) if( seqdesc->numblends == 1 )

18
utils/mdldec/texture.c

@ -33,7 +33,7 @@ static void WriteBMP( mstudiotexture_t *texture )
int i, len; int i, len;
FILE *fp; FILE *fp;
const byte *p; const byte *p;
byte *palette, *pic, *buf; byte *palette, *pic;
char filename[MAX_SYSPATH], texturename[64]; char filename[MAX_SYSPATH], texturename[64];
rgba_t rgba_palette[256]; rgba_t rgba_palette[256];
bmp_t bmp_hdr = {0,}; bmp_t bmp_hdr = {0,};
@ -87,23 +87,17 @@ static void WriteBMP( mstudiotexture_t *texture )
fwrite( rgba_palette, sizeof( rgba_palette ), 1, fp ); fwrite( rgba_palette, sizeof( rgba_palette ), 1, fp );
buf = malloc( texture_size );
p = pic; p = pic;
p += ( bmp_hdr.height - 1 ) * bmp_hdr.width; p += ( bmp_hdr.height - 1 ) * bmp_hdr.width;
for( i = 0; i < bmp_hdr.height; i++ ) for( i = 0; i < bmp_hdr.height; i++ )
{ {
memcpy( buf + bmp_hdr.width * i, p, bmp_hdr.width ); fwrite( p, bmp_hdr.width, 1, fp );
p -= bmp_hdr.width; p -= bmp_hdr.width;
} }
fwrite( buf, texture_size, 1, fp );
fclose( fp ); fclose( fp );
free( buf );
printf( "Texture: %s\n", filename ); printf( "Texture: %s\n", filename );
} }
@ -115,13 +109,9 @@ WriteTextures
void WriteTextures( void ) void WriteTextures( void )
{ {
int i; int i;
mstudiotexture_t *texture; mstudiotexture_t *texture = (mstudiotexture_t *)( (byte *)texture_hdr + texture_hdr->textureindex );
for( i = 0; i < texture_hdr->numtextures; i++ )
{
texture = (mstudiotexture_t *)( (byte *)texture_hdr + texture_hdr->textureindex ) + i;
for( i = 0; i < texture_hdr->numtextures; ++i, ++texture )
WriteBMP( texture ); WriteBMP( texture );
}
} }

Loading…
Cancel
Save