Browse Source

utils: mdldec: add separate directories creation for sequences and textures.

pull/2/head
Andrey Akhmichin 1 year ago committed by Alibek Omarov
parent
commit
dabed4f9eb
  1. 14
      utils/mdldec/qc.c
  2. 33
      utils/mdldec/smd.c
  3. 2
      utils/mdldec/smd.h
  4. 31
      utils/mdldec/texture.c
  5. 2
      utils/mdldec/texture.h

14
utils/mdldec/qc.c

@ -22,6 +22,8 @@ GNU General Public License for more details.
#include "version.h" #include "version.h"
#include "mdldec.h" #include "mdldec.h"
#include "utils.h" #include "utils.h"
#include "smd.h"
#include "texture.h"
#include "qc.h" #include "qc.h"
static char **activity_names; static char **activity_names;
@ -62,7 +64,7 @@ qboolean LoadActivityList( const char *appname )
if( !fp ) if( !fp )
{ {
fputs( "ERROR: Can't open file " ACTIVITIES_FILE ".\n", stderr ); fputs( "ERROR: Couldn't open file " ACTIVITIES_FILE ".\n", stderr );
return false; return false;
} }
} }
@ -474,11 +476,11 @@ static void WriteSequenceInfo( FILE *fp )
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\"" DEFAULT_SEQUENCEPATH "%s_blend%02i\"\n", seqdesc->label, j + 1 );
} }
else else
{ {
fprintf( fp, "\t\"%s\"\n", seqdesc->label ); fprintf( fp, "\t\"" DEFAULT_SEQUENCEPATH "%s\"\n", seqdesc->label );
} }
if( seqdesc->activity ) if( seqdesc->activity )
@ -565,7 +567,7 @@ void WriteQCScript( void )
if( len == -1 ) if( len == -1 )
{ {
fprintf( stderr, "ERROR: Destination path is too long. Can't write %s.qc\n", modelfile ); fprintf( stderr, "ERROR: Destination path is too long. Couldn't write %s.qc\n", modelfile );
return; return;
} }
@ -573,7 +575,7 @@ void WriteQCScript( void )
if( !fp ) if( !fp )
{ {
fprintf( stderr, "ERROR: Can't write %s\n", filename ); fprintf( stderr, "ERROR: Couldn't write %s\n", filename );
return; return;
} }
@ -594,7 +596,7 @@ void WriteQCScript( void )
fprintf( fp, "$modelname \"%s.mdl\"\n", modelfile ); fprintf( fp, "$modelname \"%s.mdl\"\n", modelfile );
fputs( "$cd \".\"\n", fp ); fputs( "$cd \".\"\n", fp );
fputs( "$cdtexture \".\"\n", fp ); fputs( "$cdtexture \"./" DEFAULT_TEXTUREPATH "\"\n", fp );
fputs( "$cliptotextures\n", fp ); fputs( "$cliptotextures\n", fp );
fputs( "$scale 1.0\n", fp ); fputs( "$scale 1.0\n", fp );
fputs( "\n", fp ); fputs( "\n", fp );

33
utils/mdldec/smd.c

@ -23,6 +23,7 @@ GNU General Public License for more details.
#include "studio.h" #include "studio.h"
#include "mdldec.h" #include "mdldec.h"
#include "smd.h" #include "smd.h"
#include "utils.h"
static matrix3x4 *bonetransform; static matrix3x4 *bonetransform;
static matrix3x4 *worldtransform; static matrix3x4 *worldtransform;
@ -520,7 +521,7 @@ static void WriteReferences( void )
if( len == -1 ) if( len == -1 )
{ {
fprintf( stderr, "ERROR: Destination path is too long. Can't write %s.smd\n", model->name ); fprintf( stderr, "ERROR: Destination path is too long. Couldn't write %s.smd\n", model->name );
goto _fail; goto _fail;
} }
@ -528,7 +529,7 @@ static void WriteReferences( void )
if( !fp ) if( !fp )
{ {
fprintf( stderr, "ERROR: Can't write %s\n", filename ); fprintf( stderr, "ERROR: Couldn't write %s\n", filename );
goto _fail; goto _fail;
} }
@ -559,31 +560,41 @@ WriteSequences
static void WriteSequences( void ) static void WriteSequences( void )
{ {
int i, j; int i, j;
int len; int len, namelen, emptyplace;
FILE *fp; FILE *fp;
char filename[MAX_SYSPATH]; char path[MAX_SYSPATH];
mstudioseqdesc_t *seqdesc = (mstudioseqdesc_t *)( (byte *)model_hdr + model_hdr->seqindex ); mstudioseqdesc_t *seqdesc = (mstudioseqdesc_t *)( (byte *)model_hdr + model_hdr->seqindex );
len = Q_snprintf( path, MAX_SYSPATH, "%s" DEFAULT_SEQUENCEPATH, destdir );
if( len == -1 || !MakeDirectory( path ))
{
fputs( "ERROR: Destination path is too long or write permission denied. Couldn't create directory for sequences\n", stderr );
return;
}
emptyplace = MAX_SYSPATH - len;
for( i = 0; i < model_hdr->numseq; ++i, ++seqdesc ) for( i = 0; i < model_hdr->numseq; ++i, ++seqdesc )
{ {
for( j = 0; j < seqdesc->numblends; j++ ) for( j = 0; j < seqdesc->numblends; j++ )
{ {
if( seqdesc->numblends == 1 ) if( seqdesc->numblends == 1 )
len = Q_snprintf( filename, MAX_SYSPATH, "%s%s.smd", destdir, seqdesc->label ); namelen = Q_snprintf( &path[len], emptyplace, "%s.smd", seqdesc->label );
else else
len = Q_snprintf( filename, MAX_SYSPATH, "%s%s_blend%02i.smd", destdir, seqdesc->label, j + 1 ); namelen = Q_snprintf( &path[len], emptyplace, "%s_blend%02i.smd", seqdesc->label, j + 1 );
if( len == -1 ) if( namelen == -1 )
{ {
fprintf( stderr, "ERROR: Destination path is too long. Can't write %s.smd\n", seqdesc->label ); fprintf( stderr, "ERROR: Destination path is too long. Couldn't write %s.smd\n", seqdesc->label );
return; return;
} }
fp = fopen( filename, "w" ); fp = fopen( path, "w" );
if( !fp ) if( !fp )
{ {
fprintf( stderr, "ERROR: Can't write %s\n", filename ); fprintf( stderr, "ERROR: Couldn't write %s\n", path );
return; return;
} }
@ -594,7 +605,7 @@ static void WriteSequences( void )
fclose( fp ); fclose( fp );
printf( "Sequence: %s\n", filename ); printf( "Sequence: %s\n", path );
} }
} }
} }

2
utils/mdldec/smd.h

@ -16,6 +16,8 @@ GNU General Public License for more details.
#ifndef SMD_H #ifndef SMD_H
#define SMD_H #define SMD_H
#define DEFAULT_SEQUENCEPATH "anims/"
void WriteSMD( void ); void WriteSMD( void );
#endif // SMD_H #endif // SMD_H

31
utils/mdldec/texture.c

@ -23,6 +23,7 @@ GNU General Public License for more details.
#include "img_tga.h" #include "img_tga.h"
#include "mdldec.h" #include "mdldec.h"
#include "texture.h" #include "texture.h"
#include "utils.h"
/* /*
============ ============
@ -130,27 +131,37 @@ WriteTextures
*/ */
void WriteTextures( void ) void WriteTextures( void )
{ {
int i, len; int i, len, namelen, emptyplace;
FILE *fp; FILE *fp;
mstudiotexture_t *texture = (mstudiotexture_t *)( (byte *)texture_hdr + texture_hdr->textureindex ); mstudiotexture_t *texture = (mstudiotexture_t *)( (byte *)texture_hdr + texture_hdr->textureindex );
char filename[MAX_SYSPATH]; char path[MAX_SYSPATH];
len = Q_snprintf( path, MAX_SYSPATH, "%s" DEFAULT_TEXTUREPATH, destdir );
if( len == -1 || !MakeDirectory( path ))
{
fputs( "ERROR: Destination path is too long or write permission denied. Couldn't create directory for textures\n", stderr );
return;
}
emptyplace = MAX_SYSPATH - len;
for( i = 0; i < texture_hdr->numtextures; ++i, ++texture ) for( i = 0; i < texture_hdr->numtextures; ++i, ++texture )
{ {
len = Q_snprintf( filename, MAX_SYSPATH, "%s%s", destdir, texture->name ); namelen = Q_strncpy( &path[len], texture->name, emptyplace );
if( len == -1 ) if( emptyplace - namelen < 0 )
{ {
fprintf( stderr, "ERROR: Destination path is too long. Can't write %s\n", texture->name ); fprintf( stderr, "ERROR: Destination path is too long. Couldn't write %s\n", texture->name );
continue; return;
} }
fp = fopen( filename, "wb" ); fp = fopen( path, "wb" );
if( !fp ) if( !fp )
{ {
fprintf( stderr, "ERROR: Can't write texture file %s\n", filename ); fprintf( stderr, "ERROR: Couldn't write texture file %s\n", path );
continue; return;
} }
if( !Q_stricmp( COM_FileExtension( texture->name ), "tga" )) if( !Q_stricmp( COM_FileExtension( texture->name ), "tga" ))
@ -160,7 +171,7 @@ void WriteTextures( void )
fclose( fp ); fclose( fp );
printf( "Texture: %s\n", filename ); printf( "Texture: %s\n", path );
} }
} }

2
utils/mdldec/texture.h

@ -16,6 +16,8 @@ GNU General Public License for more details.
#ifndef TEXTURE_H #ifndef TEXTURE_H
#define TEXTURE_H #define TEXTURE_H
#define DEFAULT_TEXTUREPATH "textures/"
void WriteTextures( void ); void WriteTextures( void );
#endif // TEXTURE_H #endif // TEXTURE_H

Loading…
Cancel
Save