From: Matze B. <mat...@us...> - 2002-02-14 22:13:58
|
Update of /cvsroot/planeshift/planeshift/ase2spr In directory usw-pr-cvs1:/tmp/cvs-serv13018/ase2spr Modified Files: Makefile ase.cpp ase2spr.cpp ase2spr.h spr.cpp Log Message: ase2spr update Index: Makefile =================================================================== RCS file: /cvsroot/planeshift/planeshift/ase2spr/Makefile,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** Makefile 20 Dec 2001 13:58:35 -0000 1.2 --- Makefile 14 Feb 2002 22:13:55 -0000 1.3 *************** *** 1,5 **** OBJECTS = ase.o ase2spr.o spr.o GOAL = ase2spr ! CFLAGS = -Wall -I. -O2 $(GOAL): $(OBJECTS) --- 1,5 ---- OBJECTS = ase.o ase2spr.o spr.o GOAL = ase2spr ! CFLAGS = -Wall -I. -O2 -g3 $(GOAL): $(OBJECTS) Index: ase.cpp =================================================================== RCS file: /cvsroot/planeshift/planeshift/ase2spr/ase.cpp,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** ase.cpp 30 Sep 2001 12:37:03 -0000 1.3 --- ase.cpp 14 Feb 2002 22:13:55 -0000 1.4 *************** *** 23,325 **** */ - // converter.cpp: implementation of the converter class. - // - ////////////////////////////////////////////////////////////////////// - #include "ase2spr.h" ! /******************************************************************************/ ! [...1712 lines suppressed...] ! ! // XXX: What the hell is this good for? It's never used ! #if 0 ! /* ! Assign face vertex colors based on node colors. ! */ ! khi = MIN(num_face, MAX_FACE); ! for (iface = 0; iface < khi; iface++) { ! for (ivert = 0; ivert < 3; ivert++) { ! l = face[ivert][iface]; ! for (i = 0; i < 3; i++) { ! vertex_rgb[i][ivert][iface] = cor3_rgb[i][l]; ! } ! } } ! #endif } + /******************************************************************************/ Index: ase2spr.cpp =================================================================== RCS file: /cvsroot/planeshift/planeshift/ase2spr/ase2spr.cpp,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** ase2spr.cpp 7 Nov 2001 14:07:08 -0000 1.3 --- ase2spr.cpp 14 Feb 2002 22:13:55 -0000 1.4 *************** *** 22,294 **** * **/ ! int scale; // set to 1 if we need to scale the model float scalex; float scaley; float scalez; ! int main (int argc, char *argv[]) { ! if (argc < 3 || argc > 6) ! { ! printf("\nase2spr is a program to convert an ASE files (Exported from 3DSMAX)\n"); printf("to a Crystal Space spr file\n\n"); ! printf("syntax: ase2spr <asefile> <sprfile> or \n"); ! printf("syntax: ase2spr <asefile> <sprfile> <scalex> <scaley> <scalez> \n"); ! printf("for example: ase2spr enkidukai.ase enkidukai.spr\n\n"); ! printf("for example: ase2spr enkidukai.ase enkidukai.spr 0.1 0.1 0.1\n\n"); ! ! return 0; ! } ! ! // check if we need to scale the model ! if (argc > 3) { ! scale = 1; ! sscanf(argv[3], "%f",&scalex); ! sscanf(argv[4], "%f",&scaley); ! sscanf(argv[5], "%f",&scalez); ! } else ! scale = 0; ! ! // Convert an ASE file ! converter* filedata = new converter; ! ! //char * filein_name = "d:\\Luca\\enkidukai_w5.ase"; ! //char * fileout_name = "d:\\Luca\\test1.spr"; ! ! FILE *filein = fopen ( argv[1], "rb" ); ! ! // test if input file exists ! if (filein==NULL) ! { ! printf("The input file doesn't exists\n"); ! return 1; ! } ! filedata->ase_convert(filein, argv[2]); ! /* ! // WRITE AN SPR FILE ! FILE *fileout = fopen ( "d:\\Luca\\enkidukai_w4.spr", "w" ); ! filedata->spr_write(fileout); ! fclose(fileout); ! */ ! return 0; } ! converter::converter() : revnorm(FALSE) { ! // create log file ! logfile = fopen("ase2spr.log", "w"); ! // init number of lines ! num_text = 0; // clear data ! data_init ( ); } converter::~converter() { ! } // This functions is called at every frame! ! void converter::data_init ( ) { ! ! /******************************************************************************/ ! ! /* ! Purpose: ! ! DATA_INIT initializes the internal graphics data. ! ! Modified: ! ! 02 December 1998 ! ! Author: ! ! John Burkardt ! */ ! ! int i; ! int iface; ! int ivert; ! int j; ! int k; ! for ( i = 0; i < 3; i++ ) { ! for ( j = 0; j < MAX_COR3; j++ ) { ! cor3[i][j] = 0.0; ! temp_cor3[i][j] = 0.0; } - } ! for ( i = 0; i < 2; i++ ) { ! for ( j = 0; j < MAX_COR3; j++ ) { ! cor3_uv[i][j] = 0.0; ! temp_cor3_uv[i][j] = 0.0; } - } ! for ( i = 0; i < 3; i++ ) { ! for ( j = 0; j < MAX_COR3; j++ ) { ! cor3_normal[i][j] = 0.0; } - } ! for ( j = 0; j < MAX_COR3; j++ ) { ! cor3_rgb[0][j] = 0.299; ! cor3_rgb[1][j] = 0.587; ! cor3_rgb[2][j] = 0.114; ! } ! ! for ( iface = 0; iface < MAX_FACE; iface++ ) { ! for ( ivert = 0; ivert < MAX_ORDER; ivert++ ) { ! face[ivert][iface] = 0; } - } ! for ( iface = 0; iface < MAX_FACE; iface++ ) { ! face_flags[iface] = 6; ! } ! ! for ( iface = 0; iface < MAX_FACE; iface++ ) { ! for ( ivert = 0; ivert < MAX_ORDER; ivert++ ) { ! face_mat[ivert][iface] = 0; ! face_texnode[ivert][iface] = -1; } - } ! for ( iface = 0; iface < MAX_FACE; iface++ ) { ! for ( i = 0; i < 3; i++ ) { ! face_normal[i][iface] = 0; } - } - - for ( iface = 0; iface < MAX_FACE; iface++ ) { - face_object[iface] = -1; - } - - for ( iface = 0; iface < MAX_FACE; iface++ ) { - face_order[iface] = 0; - } - - for ( iface = 0; iface < MAX_FACE; iface++ ) { - face_smooth[iface] = 1; - } - - for ( i = 0; i < MAX_LINE; i++ ) { - line_dex[i] = -1; - } ! for ( i = 0; i < MAX_LINE; i++ ) { ! line_mat[i] = 0; ! } ! for ( j = 0; j < MAX_ORDER*MAX_FACE; j++ ) { ! for ( i = 0; i < 3; i++ ) { ! normal_temp[i][j] = 0; } - } ! num_color = 0; ! num_cor3 = 0; ! num_cor3_uv = 0; ! temp_num_cor3 = 0; ! temp_num_cor3_uv = 0; ! num_face = 0; ! num_line = 0; ! num_texmap = 0; ! strcpy ( object_name, "IVCON" ); ! for ( i = 0; i < 3; i++ ) { ! origin[i] = 0.0; ! } ! for ( i = 0; i < 3; i++ ) { ! pivot[i] = 0.0; ! } ! for ( j = 0; j < MAX_COLOR; j++ ) { ! rgbcolor[0][j] = 0.299; ! rgbcolor[1][j] = 0.587; ! rgbcolor[2][j] = 0.114; ! } ! for ( j = 0; j < MAX_TEXMAP; j++ ) { ! strcpy ( texmap_name[j], "null" ); ! } ! for ( i = 0; i < 4; i++ ) { ! for ( j = 0; j < 4; j++ ) { ! if ( i == j ) { ! transform_mat[i][j] = 1.0; ! } ! else { ! transform_mat[i][j] = 0.0; ! } } - } ! for ( iface = 0; iface < MAX_FACE; iface++ ) { ! for ( ivert = 0; ivert < MAX_ORDER; ivert++ ) { ! for ( i = 0; i < 3; i++ ) { ! vertex_normal[i][ivert][iface] = 0.0; ! } } - } ! for ( iface = 0; iface < MAX_FACE; iface++ ) { ! for ( ivert = 0; ivert < MAX_ORDER; ivert++ ) { ! for ( i = 0; i < 2; i++ ) { ! vertex_uv[i][ivert][iface] = 0.0; ! } } - } ! for ( iface = 0; iface < MAX_FACE; iface++ ) { ! for ( ivert = 0; ivert < MAX_ORDER; ivert++ ) { ! for ( i = 0; i < 2; i++ ) { ! face_uv[i][ivert][iface] = 0.0; ! } } - } ! for ( j = 0; j < 3; j++ ) { ! for ( k = 0; k < MAX_FACE; k++ ) { ! vertex_rgb[0][j][k] = 0.299; ! vertex_rgb[1][j][k] = 0.587; ! vertex_rgb[2][j][k] = 0.114; } - } ! if ( debug == TRUE ) { ! fprintf ( logfile, "\n" ); ! fprintf ( logfile, "DATA_INIT: Graphics data initialized.\n" ); ! } ! return; } ! void converter::scale_model (float x, float y, float z) { ! ! int j=0; ! for ( j = 0; j < num_cor3; j++ ) { ! cor3[0][j] = x * cor3[0][j]; ! cor3[1][j] = y * cor3[1][j]; ! cor3[2][j] = z * cor3[2][j]; } ! return; } --- 22,255 ---- * **/ ! bool scale; // set to 1 if we need to scale the model float scalex; float scaley; float scalez; ! int main(int argc, char *argv[]) { ! if (argc < 3 || argc > 6) { ! printf ! ("\nase2spr is a program to convert an ASE files (Exported from 3DSMAX)\n"); printf("to a Crystal Space spr file\n\n"); ! printf("syntax: ase2spr <asefile> <sprfile> or \n"); ! printf ! ("syntax: ase2spr <asefile> <sprfile> <scalex> <scaley> <scalez> \n"); ! printf("for example: ase2spr enkidukai.ase enkidukai.spr\n\n"); ! printf ! ("for example: ase2spr enkidukai.ase enkidukai.spr 0.1 0.1 0.1\n\n"); ! return 0; ! } ! // check if we need to scale the model ! if (argc > 3) { ! scale = true; ! sscanf(argv[3], "%f", &scalex); ! sscanf(argv[4], "%f", &scaley); ! sscanf(argv[5], "%f", &scalez); ! } else ! scale = false; + // Convert an ASE file + converter *filedata = new converter; ! //char * filein_name = "d:\\Luca\\enkidukai_w5.ase"; ! //char * fileout_name = "d:\\Luca\\test1.spr"; ! FILE *filein = fopen(argv[1], "rb"); ! // test if input file exists ! if (filein == NULL) { ! fprintf(stderr, "The input file doesn't exists\n"); ! return 1; ! } ! if (filedata->ase_convert(filein, argv[2])) { ! fprintf(stderr, "Error while converting file!\n"); ! return 1; ! } ! fclose(filein); ! delete filedata; + return 0; } ! converter::converter() ! : revnorm(false) { ! #ifdef DEBUG ! // create log file ! logfile = fopen("ase2spr.log", "w"); ! #else ! logfile = NULL; ! #endif ! // init number of lines ! num_text = 0; // clear data ! data_init(); } converter::~converter() { ! if (logfile) ! fclose(logfile); } // This functions is called at every frame! ! void converter::data_init() ! { ! int i; ! int iface; ! int ivert; ! int j; ! int k; ! for (i = 0; i < 3; i++) { ! for (j = 0; j < MAX_COR3; j++) { ! cor3[i][j] = 0.0; ! cor3_normal[i][j] = 0.0; ! temp_cor3[i][j] = 0.0; ! } } ! for (j = 0; j < MAX_COR3; j++) { ! cor3_rgb[0][j] = 0.299; ! cor3_rgb[1][j] = 0.587; ! cor3_rgb[2][j] = 0.114; } ! for (i = 0; i < 2; i++) { ! for (j = 0; j < MAX_COR3; j++) { ! cor3_uv[i][j] = 0.0; ! temp_cor3_uv[i][j] = 0.0; ! } } ! for (iface = 0; iface < MAX_FACE; iface++) { ! for (ivert = 0; ivert < MAX_ORDER; ivert++) { ! face[ivert][iface] = 0; ! face_mat[ivert][iface] = 0; ! face_texnode[ivert][iface] = -1; ! } } ! for (iface = 0; iface < MAX_FACE; iface++) { ! face_flags[iface] = 6; } ! for (iface = 0; iface < MAX_FACE; iface++) { ! for (i = 0; i < 3; i++) { ! face_normal[i][iface] = 0; ! } } ! for (iface = 0; iface < MAX_FACE; iface++) { ! face_object[iface] = -1; ! face_order[iface] = 0; ! face_smooth[iface] = 1; ! } ! for (i = 0; i < MAX_LINE; i++) { ! line_dex[i] = -1; ! line_mat[i] = 0; } ! for (j = 0; j < MAX_ORDER * MAX_FACE; j++) { ! for (i = 0; i < 3; i++) { ! normal_temp[i][j] = 0; ! } ! } ! num_color = 0; ! num_cor3 = 0; ! num_cor3_uv = 0; ! temp_num_cor3 = 0; ! temp_num_cor3_uv = 0; ! num_face = 0; ! num_line = 0; ! num_texmap = 0; ! strcpy(object_name, "IVCON"); ! for (i = 0; i < 3; i++) { ! origin[i] = 0.0; ! pivot[i] = 0.0; ! } ! for (j = 0; j < MAX_COLOR; j++) { ! rgbcolor[0][j] = 0.299; ! rgbcolor[1][j] = 0.587; ! rgbcolor[2][j] = 0.114; ! } ! for (j = 0; j < MAX_TEXMAP; j++) { ! strcpy(texmap_name[j], "null"); ! } ! for (i = 0; i < 4; i++) { ! for (j = 0; j < 4; j++) { ! if (i == j) { ! transform_mat[i][j] = 1.0; ! } else { ! transform_mat[i][j] = 0.0; ! } ! } } ! for (iface = 0; iface < MAX_FACE; iface++) { ! for (ivert = 0; ivert < MAX_ORDER; ivert++) { ! for (i = 0; i < 3; i++) { ! vertex_normal[i][ivert][iface] = 0.0; ! } ! } } ! for (iface = 0; iface < MAX_FACE; iface++) { ! for (ivert = 0; ivert < MAX_ORDER; ivert++) { ! for (i = 0; i < 2; i++) { ! vertex_uv[i][ivert][iface] = 0.0; ! } ! } } ! for (iface = 0; iface < MAX_FACE; iface++) { ! for (ivert = 0; ivert < MAX_ORDER; ivert++) { ! for (i = 0; i < 2; i++) { ! face_uv[i][ivert][iface] = 0.0; ! } ! } } ! for (j = 0; j < 3; j++) { ! for (k = 0; k < MAX_FACE; k++) { ! vertex_rgb[0][j][k] = 0.299; ! vertex_rgb[1][j][k] = 0.587; ! vertex_rgb[2][j][k] = 0.114; ! } } ! #ifdef DEBUG ! fprintf(logfile, "\n"); ! fprintf(logfile, "DATA_INIT: Graphics data initialized.\n"); ! #endif ! return; } ! void converter::scale_model(float x, float y, float z) ! { ! int j = 0; ! for (j = 0; j < num_cor3; j++) { ! cor3[0][j] = x * cor3[0][j]; ! cor3[1][j] = y * cor3[1][j]; ! cor3[2][j] = z * cor3[2][j]; } ! return; } Index: ase2spr.h =================================================================== RCS file: /cvsroot/planeshift/planeshift/ase2spr/ase2spr.h,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** ase2spr.h 25 Jul 2001 17:17:13 -0000 1.2 --- ase2spr.h 14 Feb 2002 22:13:55 -0000 1.3 *************** *** 19,23 **** */ - #ifndef __ASE2SPR_H__ #define __ASE2SPR_H__ --- 19,22 ---- *************** *** 39,60 **** // these numbers need to be adjusted ! #define MAX_COLOR 1000 ! #define MAX_COR3 5000 ! #define MAX_FACE 10000 ! #define MAX_INCHARS 256 ! #define MAX_LEVEL 10 ! #define MAX_LINE 1500 #define MAX_ORDER 10 ! #define MAX_TEXMAP 5 ! ! #ifndef FALSE ! #define FALSE 0 ! #endif ! #ifndef TRUE ! #define TRUE 1 ! #endif ! ! #define ERROR 0 ! #define SUCCESS 1 #define MAX(a,b) ( (a)>(b) ? (a) : (b) ) --- 38,50 ---- // these numbers need to be adjusted ! #define DEBUG ! #define MAX_COLOR 10000 ! #define MAX_COR3 10000 ! #define MAX_FACE 30000 ! #define MAX_INCHARS 1000 ! #define MAX_LEVEL 20 ! #define MAX_LINE 4000 #define MAX_ORDER 10 ! #define MAX_TEXMAP 10 #define MAX(a,b) ( (a)>(b) ? (a) : (b) ) *************** *** 119,199 **** public: ! FILE* logfile; ! ! int debug; ! char filein_name[81]; ! char fileout_name[81]; ! ! float cor3[3][MAX_COR3]; ! float cor3_normal[3][MAX_COR3]; ! float cor3_rgb[3][MAX_COR3]; ! float cor3_uv[2][MAX_COR3]; ! float temp_cor3[3][MAX_COR3]; ! float temp_cor3_uv[2][MAX_COR3]; ! ! int face[MAX_ORDER][MAX_FACE]; ! int face_flags[MAX_FACE]; ! int face_mat[MAX_ORDER][MAX_FACE]; ! int face_texnode[MAX_ORDER][MAX_FACE]; ! float face_normal[3][MAX_FACE]; ! int face_object[MAX_FACE]; ! int face_order[MAX_FACE]; ! int face_smooth[MAX_FACE]; ! char input[MAX_INCHARS]; ! char levnam[MAX_LEVEL][MAX_INCHARS]; ! int line_dex[MAX_LINE]; ! int line_mat[MAX_LINE]; ! int list[MAX_COR3]; ! char mat_name[81]; ! int max_order2; ! float normal_temp[3][MAX_ORDER*MAX_FACE]; ! ! char texmap_name[MAX_TEXMAP][81]; ! float transform_mat[4][4]; ! float vertex_normal[3][MAX_ORDER][MAX_FACE]; ! float vertex_uv[2][MAX_ORDER][MAX_FACE]; ! float face_uv[2][MAX_ORDER][MAX_FACE]; ! float vertex_rgb[3][MAX_ORDER][MAX_FACE]; ! ! int num_bad; ! int num_color; ! int num_comment; ! int num_cor3; ! int num_cor3_uv; ! int temp_num_cor3; ! int temp_num_cor3_uv; ! int num_dup; ! int num_face; ! int num_group; ! int num_line; ! int num_object; ! int num_texmap; ! int num_text; ! char object_name[81]; ! private: ! ! int i; ! int iarg; ! int icor3; ! int ierror; ! int iface; ! int ivert; ! int revnorm; ! ! int byte_swap; ! float origin[3]; ! float pivot[3]; ! float rgbcolor[3][MAX_COLOR]; ! char temp_name[81]; ! ! ! // functions public: ! ! void data_init ( void ); ! int ase_convert ( FILE *filein, char *fileout_name ); ! void scale_model (float x, float y, float z); }; --- 109,184 ---- public: + FILE* logfile; ! char filein_name[81]; ! char fileout_name[81]; ! ! float cor3[3][MAX_COR3]; ! float cor3_normal[3][MAX_COR3]; ! float cor3_rgb[3][MAX_COR3]; ! float cor3_uv[2][MAX_COR3]; ! float temp_cor3[3][MAX_COR3]; ! float temp_cor3_uv[3][MAX_COR3]; ! ! int face[MAX_ORDER][MAX_FACE]; ! int face_flags[MAX_FACE]; ! int face_mat[MAX_ORDER][MAX_FACE]; ! int face_texnode[MAX_ORDER][MAX_FACE]; ! float face_normal[3][MAX_FACE]; ! int face_object[MAX_FACE]; ! int face_order[MAX_FACE]; ! int face_smooth[MAX_FACE]; ! char input[MAX_INCHARS]; ! char levnam[MAX_LEVEL][MAX_INCHARS]; ! int line_dex[MAX_LINE]; ! int line_mat[MAX_LINE]; ! int list[MAX_COR3]; ! char mat_name[81]; ! int max_order2; ! float normal_temp[3][MAX_ORDER*MAX_FACE]; ! ! char texmap_name[MAX_TEXMAP][81]; ! float transform_mat[4][4]; ! float vertex_normal[3][MAX_ORDER][MAX_FACE]; ! float vertex_uv[2][MAX_ORDER][MAX_FACE]; ! float face_uv[2][MAX_ORDER][MAX_FACE]; ! float vertex_rgb[3][MAX_ORDER][MAX_FACE]; ! ! int num_bad; ! int num_color; ! int num_comment; ! int num_cor3; ! int num_cor3_uv; ! int temp_num_cor3; ! int temp_num_cor3_uv; ! int num_dup; ! int num_face; ! int num_group; ! int num_line; ! int num_object; ! int num_texmap; ! int num_text; ! char object_name[81]; ! private: ! int i; ! int iarg; ! int icor3; ! int ierror; ! int iface; ! int ivert; ! int revnorm; ! ! int byte_swap; ! float origin[3]; ! float pivot[3]; ! float rgbcolor[3][MAX_COLOR]; ! char temp_name[81]; ! // functions ! public: ! void data_init ( void ); ! int ase_convert ( FILE *filein, char *fileout_name ); ! void scale_model (float x, float y, float z); }; Index: spr.cpp =================================================================== RCS file: /cvsroot/planeshift/planeshift/ase2spr/spr.cpp,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** spr.cpp 7 Nov 2001 14:07:08 -0000 1.4 --- spr.cpp 14 Feb 2002 22:13:55 -0000 1.5 *************** *** 21,38 **** ////////////////////////////////////////////////////////////////////// - /* - Purpose: - - SPR_WRITE writes a standard CS SPR file. - - Modified: - - 12 April 2001 - - Author: - - Luca Pancallo - */ - #include <stdio.h> #include <stdlib.h> --- 21,24 ---- *************** *** 45,133 **** // Writes an SPR file with ONE frame ! int converter::spr_write ( FILE *fileout ) { ! ! spr_write_header(fileout); ! ! spr_write_frame (fileout,1); ! ! spr_write_footer (fileout,1); ! return SUCCESS; } - /* Write the header. */ ! int converter::spr_write_header ( FILE *fileout ) { ! ! char *name = "obj"; ! fprintf ( fileout, "MESHFACT '%s' (\n", name ); ! fprintf ( fileout, " PLUGIN ('crystalspace.mesh.loader.factory.sprite.3d')\n" ); ! fprintf ( fileout, " PARAMS (\n" ); ! fprintf ( fileout, " MATERIAL ('%sskin')\n", name ); ! return SUCCESS; } /* Write the FRAME block with any given number of frames. */ ! int converter::spr_write_frame ( FILE *fileout, int frameNumber ) { ! ! int line=0; ! int j, jj; ! ! char frameName[MAX_INCHARS]; ! char frameNumberStr[MAX_INCHARS]; ! ! strcpy (frameName, "stand"); ! snprintf (frameNumberStr, 10, "%d", frameNumber); ! strcat(frameName, frameNumberStr); ! ! fprintf ( fileout, "\n FRAME '"); ! fprintf ( fileout, frameName); ! fprintf ( fileout, "' ( \n\n" ); ! ! line = line + 3; ! ! // Scale model if requested ! if (scale) ! scale_model(scalex,scaley,scalez); ! ! ! // build a list of all the vertex needed for each face ! for ( j = 0; j < num_face; j++ ) { ! ! // for each face print 3 vertexes (THIS MUST BE OPTIMIZED!) ! for ( jj = 0; jj < 3; jj++ ) { ! // vertex on T face ! int vertex = face_uv[jj][0][j]; ! //fprintf ( fileout, " V (%f,%f,%f:%f,%f)\n", cor3[0][face[jj][j]], ! // cor3[1][face[jj][j]], cor3[2][face[jj][j]], vertex_uv[0][0][vertex], vertex_uv[1][0][vertex]); ! // invert y and z ! fprintf ( fileout, " V (%f,%f,%f:%f,%f)\n", cor3[0][face[jj][j]], ! cor3[2][face[jj][j]], cor3[1][face[jj][j]], vertex_uv[0][0][vertex], vertex_uv[1][0][vertex]); ! } ! } ! fprintf ( fileout, " \n\n\n\n"); ! /* OLD WAY! ! Write the FRAME vertexes. ! for ( j = 0; j < num_cor3; j++ ) { ! fprintf ( fileout, " V (%f,%f,%f:%f,%f)\n", cor3[0][j], ! cor3[1][j], cor3[2][j], vertex_uv[0][0][j], vertex_uv[1][0][j]); ! line = line + 1; ! } ! */ ! fprintf ( fileout, " )\n" ); ! return SUCCESS; } --- 31,95 ---- // Writes an SPR file with ONE frame ! int converter::spr_write(FILE * fileout) ! { ! spr_write_header(fileout); ! spr_write_frame(fileout, 1); ! spr_write_footer(fileout, 1); ! return 0; } /* Write the header. */ ! int converter::spr_write_header(FILE * fileout) ! { ! char *name = "obj"; ! fprintf(fileout, "MESHFACT '%s' (\n", name); ! fprintf(fileout, ! " PLUGIN ('crystalspace.mesh.loader.factory.sprite.3d')\n"); ! fprintf(fileout, " PARAMS (\n"); ! fprintf(fileout, " MATERIAL ('%sskin')\n", name); ! return 0; } + #define FRAMENAME "stand" /* Write the FRAME block with any given number of frames. */ ! int converter::spr_write_frame(FILE * fileout, int framenumber) ! { ! int line = 0; ! int j, jj; ! fprintf(fileout, " FRAME '%s%d' (\n\n", FRAMENAME, framenumber); ! //XXX: is this correct? ! line = line + 3; ! // Scale model if requested ! if (scale) ! scale_model(scalex, scaley, scalez); ! // build a list of all the vertex needed for each face ! for (j = 0; j < num_face; j++) { ! // for each face print 3 vertexes (THIS MUST BE OPTIMIZED!) ! for (jj = 0; jj < 3; jj++) { ! // vertex on T face ! int vertex = (int) face_uv[jj][0][j]; ! // invert y and z ! fprintf(fileout, " V (%f,%f,%f:%f,%f)\n", ! cor3[0][face[jj][j]], cor3[2][face[jj][j]], ! cor3[1][face[jj][j]], vertex_uv[0][0][vertex], ! vertex_uv[1][0][vertex]); ! } ! } ! fprintf(fileout, " )\n\n"); // FRAME ! return 0; } *************** *** 135,215 **** Write the action, triangles, closing parenthesis. */ ! int converter::spr_write_footer ( FILE *fileout, int numberOfFrames ) { ! ! int i1; ! int i2; ! int i3; ! int j; ! int line=0; ! char actionString[MAX_INCHARS]; ! char *actionType = "stand"; // action 'stand', 'run' ! char frameNumberStr[MAX_INCHARS]; ! /* ! Write the ACTION block. ! */ ! if (numberOfFrames==1) ! fprintf ( fileout, "\n ACTION 'stand' ( F ('stand1', 100) ) \n\n"); ! else { ! strcpy (actionString, "\n ACTION '"); ! strcat (actionString, actionType); ! strcat (actionString, "' ( "); ! fprintf ( fileout, actionString ); ! for ( j = 1; j <= numberOfFrames; j++ ) { ! strcpy (actionString,""); ! strcat (actionString, " F ('"); ! strcat (actionString, actionType); ! //itoa(j, frameNumberStr, 10); ! snprintf (frameNumberStr, 10, "%d", j); ! strcat(actionString, frameNumberStr); ! strcat (actionString, "', 100)"); ! fprintf ( fileout, actionString ); } ! strcpy (actionString, ") \n\n"); ! fprintf ( fileout, actionString ); ! } ! ! ! // Write the TRIANGLE block. ! int count = 0; ! for ( iface = 0; iface < num_face; iface++ ) { ! int vertex1 = face_uv[0][0][iface]; ! int vertex2 = face_uv[1][0][iface]; ! int vertex3 = face_uv[2][0][iface]; // invert vertex2 and vertex3 ! fprintf ( fileout, " TRIANGLE (%d,%d,%d)\n", count, count+2, count+1 ); ! count = count +3; ! line = line + 1; ! } ! ! /* OLD WAY! ! Write the TRIANGLE block. ! ! for ( iface = 0; iface < num_face; iface++ ) { ! ! i1 = face[0][iface]; ! i2 = face[1][iface]; ! i3 = face[2][iface]; ! ! if ( face_order[iface] == 3 ) { ! fprintf ( fileout, " TRIANGLE (%d,%d,%d)\n", i1, i2, i3 ); ! line = line + 1; } - else if ( face_order[iface] == 4 ) { - // 4 vertexes! How do we manage this? - fprintf ( fileout, "\n4 vertexes! How do we manage this?\n\n"); - } - } - */ ! /* ! Write the close block. ! */ ! ! fprintf ( fileout, " )\n"); ! fprintf ( fileout, ")\n"); ! return SUCCESS; } --- 97,136 ---- Write the action, triangles, closing parenthesis. */ ! int converter::spr_write_footer(FILE * fileout, int numberOfFrames) ! { ! int j; ! int line = 0; ! char *actionType = "stand"; // action 'stand', 'run' ! /* ! Write the ACTION block. ! */ ! if (numberOfFrames == 1) ! fprintf(fileout, " ACTION 'stand' ( F ('stand1', 100) ) \n\n"); ! else { ! fprintf(fileout, " ACTION '%s' (", actionType); ! for (j = 1; j <= numberOfFrames; j++) { ! fprintf(fileout, " F ('%s%d', 100)\n", actionType, j); } ! fprintf(fileout, " )\n\n"); ! } + // Write the TRIANGLE block. + int count = 0; + for (iface = 0; iface < num_face; iface++) { // invert vertex2 and vertex3 ! fprintf(fileout, " TRIANGLE (%d,%d,%d)\n", count, count+2, count+1); ! count = count + 3; ! line = line + 1; } ! /* ! Write the close block. ! */ ! fprintf(fileout, " )\n"); // PARAMS ! fprintf(fileout, ")\n"); // MESHFACT ! return 0; } + |