// Shave and a Haircut // (c) 2019 Epic Games // US Patent 6720962 /* change */ // after 1.71 void make_spline_normals( void ); static void init_hair( void ); //char shaveversion=0; #include static int Jexists( void *fname ); static void collect_guides( void ); static int firstloadguv = 1; static char * MYfgets2( char *s, int size, FILE * fp ) { char c; ///int x; char *save = s; while( size > 0 && fread( &c, 1, 1, fp ) == 1 ) { switch ( c ) { case '\x0d': *s++ = '\n'; *s++ = '\0'; return ( save ); case '\x0a': *s++ = '\n'; *s++ = '\0'; return ( save ); default: *s++ = c; --size; break; } } // sprintf(s,"\n"); return ( NULL ); } static char * MYfgets( char *s, int size, FILE * fp ) { char *save; #ifdef _MAC save = MYfgets2( s, size, fp ); if( strlen( s ) < 2 ) while( ( strlen( s ) < 2 ) && ( save != NULL ) ) save = MYfgets2( s, size, fp ); #endif #ifndef MAC if( !feof( fp ) ) save = fgets( s, size, fp ); else save = NULL; #endif return ( save ); } void mkbounds( void ); void checkforzero( void ) { int i; int x; if( 0 == 1 ) // wow SLOW if( Gdynamics_mode != 1 ) for( x = 0; x < totalverts; x++ ) { float d; d = Distance( hair[x].resthv[2], hair[x].resthv[1] ); hair[x].restlength = d; //resthair[x].restlength=d; } if( 0 == 1 ) // wow SLOW for( x = 0; x < Stotalverts; x++ ) { float d; d = Distance( Shair[x].hv[2], Shair[x].hv[1] ); Shair[x].restlength = d; Sresthair[x].restlength = d; } reset_faces( ); { int nd = 0; // Gnodraw = 1; for( i = 0; i < 5; i++ ) if( total_slgfaces[i] > 0 ) { int y; int x; float tl = 0; if( i != 4 ) for( y = 0; y < total_slgfaces[i]; y++ ) { int tt = 0; for( x = face_start[slgfaces[i][y]]; x < face_end[slgfaces[i][y]]; x++ ) { if( total_slgfaces[i] > 0 ) if( hair[facelist[x]].restlength > 0 ) tt += 1; } if( tt > 2 ) tl += 1.0f; } if( i == 4 ) if( total_slgfaces[i] > 0 ) for( y = 0; y < total_slgfaces[i]; y++ ) { tl += 1.0f; // if (Shair[slgfaces[i][y]].restlength>.0001) tl+=1.0f; } if( tl > 0 ) Gnodraw = 0; if( tl < 2.0f ) { // nd=1; // total_slgfaces[i]=0; // LOCAL_CNT[i]=0; // LOCAL_PASSES[i]=1; } } } } void reset_faces( void ) { int i, slg; int q; for( q = 0; q < totalgroups; q++ ) { group_stat[q] = 1; group_enable[q] = 0; if( ( group_names[q][0] == 'b' ) && ( group_names[q][1] == 'e' ) && ( group_names[q][2] == 'a' ) && ( group_names[q][3] == 'r' ) && ( group_names[q][4] == 'd' ) ) { beard = q; group_enable[q] = 1; group_stat[q] = 0; } if( ( group_names[q][0] == 's' ) && ( group_names[q][1] == 'k' ) && ( group_names[q][2] == 'u' ) && ( group_names[q][3] == 'l' ) ) { skull_sphere = q; group_enable[q] = 2; //2 group_stat[q] = 1; //2 } if( ( group_names[q][0] == 'h' ) && ( group_names[q][1] == 'a' ) && ( group_names[q][2] == 'i' ) && ( group_names[q][3] == 'r' ) ) { head = q; group_enable[q] = 1; group_stat[q] = 0; } if( ( group_names[q][0] == 'e' ) && ( group_names[q][1] == 'y' ) && ( group_names[q][2] == 'e' ) && ( group_names[q][3] == 'b' ) && ( group_names[q][4] == 'r' ) ) { eyebrow = q; group_enable[q] = 1; group_stat[q] = 0; } if( ( group_names[q][0] == 'e' ) && ( group_names[q][1] == 'y' ) && ( group_names[q][2] == 'e' ) && ( group_names[q][3] == 'l' ) && ( group_names[q][4] == 'a' ) ) { eyelash = q; group_enable[q] = 1; group_stat[q] = 0; } if( ( group_names[q][0] == 's' ) && ( group_names[q][1] == 'p' ) && ( group_names[q][2] == 'l' ) && ( group_names[q][3] == 'i' ) && ( group_names[q][4] == 'n' ) ) { splines = q; group_enable[q] = 1; group_stat[q] = 0; } } //q // if( totalfaces > 0 ) { for( i = 0; i < 5; i++ ) { total_slgfaces[i] = 0; } if( head == -1 ) { LOCAL_CNT[0] = 0; LOCAL_PASSES[0] = 1; } if( beard == -1 ) { LOCAL_CNT[1] = 0; LOCAL_PASSES[1] = 1; } if( eyebrow == -1 ) { LOCAL_CNT[2] = 0; LOCAL_PASSES[2] = 1; } if( eyelash == -1 ) { LOCAL_CNT[3] = 0; LOCAL_PASSES[3] = 1; } if( splines == -1 ) { LOCAL_CNT[4] = 0; LOCAL_PASSES[4] = 1; } if( GMetaNurb > 0 ) if( 0 == 1 ) for( i = 0; i < Stotalfaces; i++ ) { slg = -1; if( Smtlgroup[i] == head ) slg = 0; if( Smtlgroup[i] == beard ) slg = 1; if( Smtlgroup[i] == eyebrow ) slg = 2; if( Smtlgroup[i] == eyelash ) slg = 3; if( Smtlgroup[i] == splines ) slg = 4; if( slg >= 0 ) { int ii; float trl = 0; int xx; int yy; slgfaces[slg][total_slgfaces[slg]] = i; ii = Sdominant_faceID[i]; if( ii >= 0 ) for( xx = Dface_start[ii]; xx < Dface_end[ii]; xx++ ) { if( Dtag[Dfacelist[xx]] ) { yy = Dlink[Dfacelist[xx]]; trl += hair[yy].restlength; } } if( trl > 0 ) total_slgfaces[slg]++; } } //if (GMetaNurb==0) { total_slgfaces[0] = 0; total_slgfaces[1] = 0; total_slgfaces[2] = 0; total_slgfaces[3] = 0; total_slgfaces[4] = 0; for( i = 0; i < totalfaces; i++ ) { slg = -1; if( head != -1 ) if( mtlgroup[i] == head ) slg = 0; if( beard != -1 ) if( mtlgroup[i] == beard ) slg = 1; if( eyebrow != -1 ) if( mtlgroup[i] == eyebrow ) slg = 2; if( eyelash != -1 ) if( mtlgroup[i] == eyelash ) slg = 3; if( splines != -1 ) if( mtlgroup[i] == splines ) slg = 4; if( ( skull_sphere == -1 ) || ( slg != skull_sphere ) ) if( slg == 0 ) { // int xx; float trl = 0.0f; // for (xx=face_start[i];xx0) { slgfaces[slg][total_slgfaces[slg]] = i; total_slgfaces[slg]++; } } } total_slgfaces[4] = total_splines; for( i = 0; i < total_splines; i++ ) slgfaces[4][i] = i; } for( i = 0; i < 5; i++ ) { // int y; // int x; float tl = 0; if( total_slgfaces[i] == 0 ) { LOCAL_CNT[i] = 0; LOCAL_SHADCNT[i] = 0; // LOCAL_PASSES[i]=0; } } if( ( LOCAL_CNT[0] > LOCAL_CNT[1] ) && ( LOCAL_CNT[0] > LOCAL_CNT[2] ) && ( LOCAL_CNT[0] > LOCAL_CNT[3] ) && ( LOCAL_CNT[0] > LOCAL_CNT[4] ) ) { Gslg=0; } if( ( LOCAL_SHADCNT[0] > LOCAL_SHADCNT[1] ) && ( LOCAL_SHADCNT[0] > LOCAL_SHADCNT[2] ) && ( LOCAL_SHADCNT[0] > LOCAL_SHADCNT[3] ) && ( LOCAL_SHADCNT[0] > LOCAL_SHADCNT[4] ) ) { Gslg=0; } if( ( LOCAL_CNT[1] > LOCAL_CNT[0] ) && ( LOCAL_CNT[1] > LOCAL_CNT[2] ) && ( LOCAL_CNT[1] > LOCAL_CNT[3] ) && ( LOCAL_CNT[1] > LOCAL_CNT[4] ) ) { Gslg=1; } if( ( LOCAL_CNT[2] > LOCAL_CNT[1] ) && ( LOCAL_CNT[2] > LOCAL_CNT[0] ) && ( LOCAL_CNT[2] > LOCAL_CNT[3] ) && ( LOCAL_CNT[2] > LOCAL_CNT[4] ) ) { Gslg=2; } if( ( LOCAL_CNT[3] > LOCAL_CNT[1] ) && ( LOCAL_CNT[3] > LOCAL_CNT[2] ) && ( LOCAL_CNT[3] > LOCAL_CNT[0] ) && ( LOCAL_CNT[3] > LOCAL_CNT[4] ) ) { Gslg=3; } if( ( LOCAL_CNT[4] > LOCAL_CNT[1] ) && ( LOCAL_CNT[4] > LOCAL_CNT[2] ) && ( LOCAL_CNT[4] > LOCAL_CNT[3] ) && ( LOCAL_CNT[4] > LOCAL_CNT[0] ) ) { Gslg=4; } if( ( LOCAL_SHADCNT[4] > LOCAL_SHADCNT[1] ) && ( LOCAL_SHADCNT[4] > LOCAL_SHADCNT[2] ) && ( LOCAL_SHADCNT[4] > LOCAL_SHADCNT[3] ) && ( LOCAL_SHADCNT[4] > LOCAL_SHADCNT[0] ) ) { Gslg=4; } } } static int chka( unsigned char i ) { int ret = 0; if( i == 'a' ) ret = 1; return ( ret ); } static int chkh( unsigned char i ) { int ret = 0; if( i == 'h' ) ret = 1; return ( ret ); } static int chke( unsigned char i ) { int ret = 0; if( i == 'e' ) ret = 1; return ( ret ); } static int chkspc( char i ) { int ret = 0; if( i == ' ' ) ret = 1; return ( ret ); } static void nullify_maps( void ) { int x; for( x = 0; x < 5; x++ ) { lenmap[x].width = 0; colmap[x].width = 0; densemap[x].width = 0; colmap[x].r = NULL; colmap[x].g = NULL; colmap[x].b = NULL; colmap[x].a = NULL; lenmap[x].r = NULL; lenmap[x].g = NULL; lenmap[x].b = NULL; lenmap[x].a = NULL; densemap[x].r = NULL; densemap[x].g = NULL; densemap[x].b = NULL; densemap[x].a = NULL; } } static void free_maps( void ) { int x; for( x = 0; x < 5; x++ ) { lenmap[x].width = 0; lenmap[x].name[0] = 0; colmap[x].width = 0; colmap[x].name[0] = 0; densemap[x].name[0] = 0; densemap[x].width = 0; colmap[x].r = NULL; colmap[x].g = NULL; colmap[x].b = NULL; colmap[x].a = NULL; lenmap[x].r = NULL; lenmap[x].g = NULL; lenmap[x].b = NULL; lenmap[x].a = NULL; densemap[x].r = NULL; densemap[x].g = NULL; densemap[x].b = NULL; densemap[x].a = NULL; } } static void MYfread( void *indata, int sz, int rep, void *fpointer ) { FILE *fp = NULL; MEMFILE *fpp = NULL; if( RW_CONTEXT == RW_DISK ) { fp = ( FILE * ) fpointer; if( sz > 0 ) fread( indata, sz, rep, fp ); if( sz == 4 ) SHAVE_SWAB( indata ); } if( RW_CONTEXT != RW_DISK ) { unsigned int ind; fpp = ( MEMFILE * ) fpointer; if( RW_CONTEXT == RW_LOCAL ) if( fpp->size > 0 ) { memcpy( ( char * ) indata, fpp->data + ( unsigned long ) fpp->pos, sz ); if( sz == 4 ) SHAVE_SWAB( indata ); fpp->pos += ( unsigned long ) sz; } if( GLOBAL_VERBOSE ) if( fpp->pos > fpp->size ) printf( "read past end\n" ); } } static void MYreset( MEMFILE * fp ) { fp->pos = 0; // return(fp); } static void MYfseek( void *indata, long offset, int seekType ) { if( RW_CONTEXT == RW_DISK ) fseek( ( FILE * ) indata, offset, seekType ); else { MEMFILE *fpp = ( MEMFILE * ) indata; switch ( seekType ) { case SEEK_SET: fpp->pos = offset; break; case SEEK_CUR: fpp->pos += offset; break; case SEEK_END: fpp->pos = fpp->size + offset; break; } if( fpp->pos < 0 ) fpp->pos = 0; else if( fpp->pos >= fpp->size ) fpp->pos = fpp->size; } } static long MYftell( void *indata ) { long pos; if( RW_CONTEXT == RW_DISK ) pos = ftell( ( FILE * ) indata ); else pos = ( ( MEMFILE * ) indata )->pos; return pos; } void *MYfopen( void *indata, CHNG *parms ) { // void *ret; MEMFILE *mf; FILE *ff; if( RW_CONTEXT == RW_DISK ) { CHNG* path = ( CHNG * )indata; #ifdef DOUNICODE ff = ( FILE * ) _wfopen( path , parms ); #else ff = ( FILE * ) fopen( path, parms ); #endif return ( ff ); } else { mf = ( MEMFILE * ) indata; mf->pos = 0; //SHAVEID=mf->ID; return ( mf ); } } static void MYfclose( void *indata ) { FILE *ff; MEMFILE *mf; if( RW_CONTEXT == RW_DISK ) { ff = ( FILE * ) indata; fclose( ff ); } else { mf = ( MEMFILE * ) indata; if( RW_CONTEXT == RW_RESIZE ) mf->size = mf->pos; mf->pos = 0; } } static void MYfwrite( void *indata, int sz, int rep, void *fpointer ) { MEMFILE *fpp = NULL; FILE *fp = NULL; if( RW_CONTEXT == RW_DISK ) { unsigned int ind; fp = ( FILE * ) fpointer; if( sz == 4 ) SHAVE_SWAB( indata ); if( sz > 0 ) fwrite( indata, sz, rep, fp ); if( sz == 4 ) SHAVE_SWAB( indata ); } if( RW_CONTEXT != RW_DISK ) { unsigned int ind; fpp = ( MEMFILE * ) fpointer; if( RW_CONTEXT == RW_LOCAL ) { if( sz == 4 ) SHAVE_SWAB( indata ); memcpy( fpp->data + ( unsigned long ) fpp->pos, ( char * ) indata, sz ); if( sz == 4 ) SHAVE_SWAB( indata ); } fpp->pos += ( unsigned long ) sz; if( RW_CONTEXT == RW_RESIZE ) fpp->size = fpp->pos; if( RW_CONTEXT == RW_LOCAL ) if( fpp->pos > fpp->size ) if( GLOBAL_VERBOSE ) printf( "written past end\n" ); } } static int slcheck( void ) { return ( 1 ); } #ifdef BROKEN //static int //slcheck( void ) //{ // return ( 1 ); //} #endif #ifndef SOFTIMAGE #ifdef NOTBROKEN #include static int slcheck( void ) { return 1; } #endif #endif #ifdef SOFTIMAGE //static int //slcheck( void ) //{ // return ( 1 ); //} #endif static int gpexist( char *tmp ) { int x; int ret; ret = -1; for( x = 0; x < totalgroups; x++ ) { if( strcmp( tmp, group_names[x] ) == 0 ) ret = x; } return ( ret ); } static void hide( void ) { int x, y; for( x = 0; x < totalverts; x++ ) { if( hair[x].select[0] ) { hair[x].hide = 1; for( y = 0; y < 15; y++ ) hair[x].select[y] = 0; } } for( x = 0; x < total_splines; x++ ) { if( Shair[x].select[0] ) { Shair[x].hide = 1; for( y = 0; y < 15; y++ ) Shair[x].select[y] = 0; } } } static void unhide( void ) { int x, y; for( x = 0; x < totalverts; x++ ) { if( hair[x].hide ) for( y = 0; y < 15; y++ ) { hair[x].select[y] = 0; hair[x].hide = 0; } } for( x = 0; x < total_splines; x++ ) { if( Shair[x].hide ) for( y = 0; y < 15; y++ ) { Shair[x].select[y] = 0; Shair[x].hide = 0; } } } static void lwsave_single( char name[555] ) { } static void Dregroup_nosplines( void ) { int x; int y; splines = -1; for( x = 0; x < Dtotalverts; x++ ) { Dtag[x] = 0; } for( x = 0; x < Dtotalfaces; x++ ) if( ( Dface_end[x] - Dface_start[x] ) > 2 ) for( y = Dface_start[x]; y < Dface_end[x]; y++ ) Dtag[Dfacelist[y]] = 1; } static void Dregroup( void ) { int f, x; int q; skull_sphere = -1; head = -1; beard = -1; eyebrow = -1; eyelash = -1; splines = -1; for( x = 0; x < Dtotalverts; x++ ) { Dtag[x] = 0; Dvertgroup[x] = -999; } for( q = 0; q < totalgroups; q++ ) { group_stat[q] = 1; group_enable[q] = 0; if( ( group_names[q][0] == 'b' ) && ( group_names[q][1] == 'e' ) && ( group_names[q][2] == 'a' ) && ( group_names[q][3] == 'r' ) && ( group_names[q][4] == 'd' ) ) { beard = q; group_enable[q] = 1; group_stat[q] = 0; } if( ( group_names[q][0] == 's' ) && ( group_names[q][1] == 'k' ) && ( group_names[q][2] == 'u' ) && ( group_names[q][3] == 'l' ) ) { skull_sphere = q; group_enable[q] = 2; group_stat[q] = 1; } if( ( group_names[q][0] == 'h' ) && ( group_names[q][1] == 'a' ) && ( group_names[q][2] == 'i' ) && ( group_names[q][3] == 'r' ) ) { head = q; group_enable[q] = 1; group_stat[q] = 0; } if( ( group_names[q][0] == 'e' ) && ( group_names[q][1] == 'y' ) && ( group_names[q][2] == 'e' ) && ( group_names[q][3] == 'b' ) && ( group_names[q][4] == 'r' ) ) { eyebrow = q; group_enable[q] = 1; group_stat[q] = 0; } if( ( group_names[q][0] == 'e' ) && ( group_names[q][1] == 'y' ) && ( group_names[q][2] == 'e' ) && ( group_names[q][3] == 'l' ) && ( group_names[q][4] == 'a' ) ) { eyelash = q; group_enable[q] = 1; group_stat[q] = 0; } if( ( group_names[q][0] == 's' ) && ( group_names[q][1] == 'p' ) && ( group_names[q][2] == 'l' ) && ( group_names[q][3] == 'i' ) && ( group_names[q][4] == 'n' ) ) { splines = q; group_enable[q] = 1; group_stat[q] = 0; } } //q for( f = 0; f < Dtotalfaces; f++ ) { // for (x=Dface_start[f];x= 0 ) for( f = 0; f < Dtotalfaces; f++ ) { if( ( Dmtlgroup[f] == skull_sphere ) ) for( x = Dface_start[f]; x < Dface_end[f]; x++ ) { Dvertgroup[Dfacelist[x]] = Dmtlgroup[f]; Dtag[Dfacelist[x]] = 1; } } if( eyebrow >= 0 ) for( f = 0; f < Dtotalfaces; f++ ) { if( ( Dmtlgroup[f] == eyebrow ) ) for( x = Dface_start[f]; x < Dface_end[f]; x++ ) { Dvertgroup[Dfacelist[x]] = Dmtlgroup[f]; Dtag[Dfacelist[x]] = 1; } } if( eyelash >= 0 ) for( f = 0; f < Dtotalfaces; f++ ) { if( ( Dmtlgroup[f] == eyelash ) ) for( x = Dface_start[f]; x < Dface_end[f]; x++ ) { Dvertgroup[Dfacelist[x]] = Dmtlgroup[f]; Dtag[Dfacelist[x]] = 1; } } if( splines >= 0 ) for( f = 0; f < Dtotalfaces; f++ ) { if( ( Dmtlgroup[f] == splines ) ) for( x = Dface_start[f]; x < Dface_end[f]; x++ ) { Dvertgroup[Dfacelist[x]] = Dmtlgroup[f]; // if (x==Dface_start[f]) Dtag[Dfacelist[x]] = 1; } } if( beard >= 0 ) for( f = 0; f < Dtotalfaces; f++ ) { if( ( Dmtlgroup[f] == beard ) ) for( x = Dface_start[f]; x < Dface_end[f]; x++ ) { Dvertgroup[Dfacelist[x]] = Dmtlgroup[f]; Dtag[Dfacelist[x]] = 1; } } if( head >= 0 ) for( f = 0; f < Dtotalfaces; f++ ) { if( ( Dmtlgroup[f] == head ) ) for( x = Dface_start[f]; x < Dface_end[f]; x++ ) { Dvertgroup[Dfacelist[x]] = Dmtlgroup[f]; Dtag[Dfacelist[x]] = 1; } } } static void reorg( void ) { int x; int y, q; int dvt = 0, dft = 0, dfl = 0; totalverts = 0; totalfaces = 0; totalfverts = 0; for( x = 0; x < Dtotalverts; x++ ) Dtag[x] = 0; Dregroup( ); skull_sphere = -1; head = -1; beard = -1; eyelash = -1; eyebrow = -1; colorlock = -1; splines = -1; for( q = 0; q < totalgroups; q++ ) { if( ( group_names[q][0] == 'b' ) && ( group_names[q][1] == 'e' ) && ( group_names[q][2] == 'a' ) && ( group_names[q][3] == 'r' ) && ( group_names[q][4] == 'd' ) ) { beard = q; // group_enable[q]=1; } if( ( group_names[q][0] == 'c' ) && ( group_names[q][1] == 'o' ) && ( group_names[q][2] == 'l' ) && ( group_names[q][3] == 'o' ) && ( group_names[q][4] == 'r' ) && ( group_names[q][5] == 'l' ) && ( group_names[q][6] == 'o' ) && ( group_names[q][7] == 'c' ) && ( group_names[q][8] == 'k' ) ) { colorlock = q; // printf ("we got colorlock %d\n",q); // group_enable[q]=1; } if( ( group_names[q][0] == 's' ) && ( group_names[q][1] == 'k' ) && ( group_names[q][2] == 'u' ) && ( group_names[q][3] == 'l' ) ) { skull_sphere = q; // group_enable[q]=2; } if( ( group_names[q][0] == 's' ) && ( group_names[q][1] == 'p' ) && ( group_names[q][2] == 'l' ) && ( group_names[q][3] == 'i' ) && ( group_names[q][4] == 'n' ) ) { splines = q; // group_enable[q]=2; // group_stat[q]=0; } if( ( group_names[q][0] == 'h' ) && ( group_names[q][1] == 'a' ) && ( group_names[q][2] == 'i' ) && ( group_names[q][3] == 'r' ) ) { head = q; // group_enable[q]=1; } if( ( group_names[q][0] == 'e' ) && ( group_names[q][1] == 'y' ) && ( group_names[q][2] == 'e' ) && ( group_names[q][3] == 'b' ) && ( group_names[q][4] == 'r' ) ) { eyebrow = q; // group_enable[q]=1; } if( ( group_names[q][0] == 'e' ) && ( group_names[q][1] == 'y' ) && ( group_names[q][2] == 'e' ) && ( group_names[q][3] == 'l' ) && ( group_names[q][4] == 'a' ) ) { eyelash = q; // group_enable[q]=1; } } //q for( x = 0; x < Dtotalfaces; x++ ) { if( ( ( Dmtlgroup[x] == head ) && ( head >= 0 ) ) || ( ( Dmtlgroup[x] == eyelash ) && ( eyelash >= 0 ) ) || ( ( Dmtlgroup[x] == beard ) && ( beard >= 0 ) ) || ( ( Dmtlgroup[x] == eyebrow ) && ( eyebrow >= 0 ) ) || ( ( Dmtlgroup[x] == splines ) && ( splines >= 0 ) ) || ( ( Dmtlgroup[x] == skull_sphere ) && ( skull_sphere >= 0 ) ) ) { int qq; for( qq = Dface_start[x]; qq < Dface_end[x]; qq++ ) { // if(! ((Dmtlgroup[x]==splines)&&(splines!= -1))) Dtag[Dfacelist[qq]] = 1; // else // if(qq==Dface_start[x]) // Dtag[Dfacelist[qq]]=1; } } } // printf ("scanning verts\n"); for( x = 0; x < Dtotalverts; x++ ) { if( Dtag[x] == 1 ) dvt++; } // printf("scanning faces\n"); for( x = 0; x < Dtotalfaces; x++ ) { int ct = 0; for( y = Dface_start[x]; y < Dface_end[x]; y++ ) { if( Dtag[Dfacelist[y]] ) ct++; } // test!! if ((ct==3)||((Dmtlgroup[x]==splines)&&(Dmtlgroup[x]!= -1))) if( ( ( Dmtlgroup[x] == head ) && ( head >= 0 ) ) || ( ( Dmtlgroup[x] == splines ) && ( splines >= 0 ) ) || ( ( Dmtlgroup[x] == skull_sphere ) && ( skull_sphere >= 0 ) ) ) // if ((ct==3)||(Dmtlgroup[x]==splines)) // if ((tc==3)||(Dmtlgroup[x]==splines)) // if (tc==Dface_end[x]-Dface_start[x]) { dft++; dfl += Dface_end[x] - Dface_start[x]; } } // printf ("freeing memory\n"); freeverts( ); // printf ("allocating memory %d %d\n",dvt,dft); LORESallocvert( dvt, dft, dfl ); // printf ("collecting verts\n"); totalverts = 0; for( x = 0; x < Dtotalverts; x++ ) { if( Dtag[x] == 1 ) { v[totalverts] = Dv[x]; tagvert[totalverts] = 0; Dlink[x] = totalverts; vlink[totalverts] = x; totalverts++; } } // printf ("collecting fverts\n"); totalfverts = 0; // for (x=0;x= 0 ) ) || ( ( Dmtlgroup[x] == splines ) && ( splines >= 0 ) ) || ( ( Dmtlgroup[x] == skull_sphere ) && ( skull_sphere >= 0 ) ) ) { face_start[totalfaces] = totalfverts; face_link[totalfaces] = x; //link to D face number for( y = Dface_start[x]; y < Dface_end[x]; y++ ) { // crash facelist[totalfverts] = Dlink[Dfacelist[y]]; Dflink[y] = totalfverts; mtlgroup[totalfaces] = Dmtlgroup[x]; // vertgroup[facelist[totalfverts]]= // Dvertgroup[Dfacelist[y]]; totalfverts++; } face_end[totalfaces] = totalfverts; totalfaces++; } // if (ct==Dface_end[x]-Dface_start[x]) { // face_start[totalfaces]=Dflink[Dface_start[x]]; // face_end[totalfaces]=Dflink[Dface_end[x]]; // mtlgroup[totalfaces]=Dmtlgroup[x]; // totalfaces++; } // problem } // printf("faces %d verts %d fverts %d mtl %d",totalfaces,totalverts,totalfverts,totalgroups); // Dmake_normals(); //if (RW_CONTEXT==RW_DISK) // make_normals(); { int i; int slg; for( i = 0; i < 5; i++ ) total_slgfaces[i] = 0; for( i = 0; i < totalfaces; i++ ) { slg = -1; if( head >= 0 ) if( mtlgroup[i] == head ) slg = 0; if( beard >= 0 ) if( mtlgroup[i] == beard ) slg = 1; if( eyebrow >= 0 ) if( mtlgroup[i] == eyebrow ) slg = 2; if( eyelash >= 0 ) if( mtlgroup[i] == eyelash ) slg = 3; if( splines >= 0 ) if( mtlgroup[i] == splines ) slg = 4; if( slg >= 0 ) { // int xx; float trl = 0.0f; slgfaces[slg][total_slgfaces[slg]] = i; // for (xx=face_start[i];xx0) total_slgfaces[slg]++; } } // hm /* for (i=0;i<5;i++) if (total_slgfaces[i]>0) slgfaces[i][total_slgfaces[i]]=slgfaces[i][total_slgfaces[i]-1]; */ for( i = 0; i < totalfaces; i++ ) { slg = -1; if( mtlgroup[i] == head ) slg = 0; if( mtlgroup[i] == beard ) slg = 1; if( mtlgroup[i] == eyebrow ) slg = 2; if( mtlgroup[i] == eyelash ) slg = 3; if( mtlgroup[i] == splines ) slg = 4; if( slg >= 0 ) { int xx; for( xx = face_start[i]; xx < face_end[i]; xx++ ) { int g; g = facelist[xx]; hair[g].pid = i; // resthair[g].pid=i; // thishair[g].pid=i; // lasthair[g].pid=i; hair[g].vid = g; // resthair[g].vid=g; // thishair[g].vid=g; // lasthair[g].vid=g; } } } } for( x = 0; x < totalfaces; x++ ) { float big = 0; int y; // int mtl; for( y = face_start[x]; y < face_end[x]; y++ ) { int g; g = facelist[y]; if( hair[g].restlength > 0 ) if( ( hair[g].mtl == head ) || ( hair[g].mtl == eyelash ) || ( hair[g].mtl == eyebrow ) || ( hair[g].mtl == splines ) || ( hair[g].mtl == beard ) ) { hair[g].pid = x; // resthair[g].pid=x; } } } } static void Dallocvert( void ) { int x; int tl, tfv, tf, tverts; int rDtotalverts; int rDtotalfaces; int rDtotalfverts; int rDtotallines; rDtotalverts = Dtotalverts; rDtotalfaces = Dtotalfaces; rDtotalfverts = Dtotalfverts; rDtotallines = Dtotallines; tl = Dtotallines + total_splines; tf = Dtotalfaces; tverts = Dtotalverts; tfv = Dtotalfverts; if( tl < 0 ) tl = 0; if( tf < 0 ) tf = 0; if( tverts < 0 ) tverts = 0; if( tfv < 0 ) tf = 0; Dfreeverts( ); Dtotalverts = rDtotalverts; Dtotalfaces = rDtotalfaces; Dtotalfverts = rDtotalfverts; Dtotallines = rDtotallines; //fprintf (stdout,"allocating Dverts %d %d %d\n",tl,tf,tfv); tfv += 100; tverts += 100; tf += 100; //Dtotalverts*=6;Dtotalfverts*=6; //Dtotalfaces*=6;Dtotallines*=6; tl += 1; tverts += total_splines * 255; tverts += 1; if( tl > 0 ) { tf += 100; tfv += 400; } //if (tf!=0) //D2UTface_link=(int *) malloc (tf*sizeof(int)); for( x = 0; x < 5; x++ ) { slgfaces[x] = ( int * ) malloc( tfv * sizeof( int ) ); total_slgfaces[x] = 0; } guide2vert = ( int * ) malloc( tverts * sizeof( int ) ); vert2guide = ( int * ) malloc( tverts * sizeof( int ) ); vlink = ( int * ) malloc( tverts * sizeof( int ) ); face_link = ( int * ) malloc( tf * sizeof( int ) ); D2UTface_link = ( int * ) malloc( tf * 2 * sizeof( int ) ); // Ducord = ( float * )malloc( tverts * 3 * sizeof( float ) ); // Dvcord = ( float * )malloc( tverts * 3 * sizeof( float ) ); Drvcolor = ( float * ) malloc( tverts * sizeof( float ) ); Dgvcolor = ( float * ) malloc( tverts * sizeof( float ) ); Dbvcolor = ( float * ) malloc( tverts * sizeof( float ) ); RDrvcolor = ( float * ) malloc( tverts * sizeof( float ) ); RDgvcolor = ( float * ) malloc( tverts * sizeof( float ) ); RDbvcolor = ( float * ) malloc( tverts * sizeof( float ) ); Drv = ( VERT * ) malloc( tverts * sizeof( VERT ) ); Dvn = ( VERT * ) malloc( tverts * sizeof( VERT ) ); Dline_start = ( int * ) malloc( tl * sizeof( int ) ); Dflink = ( int * ) malloc( tfv * sizeof( int ) + 3 * tl * sizeof( int ) ); Dfacelist = ( int * ) malloc( 2 * tfv * sizeof( int ) + 3 * tl * sizeof( int ) ); Dface_start = ( int * ) malloc( tf * sizeof( int ) + ( tl ) * sizeof( int ) ); Dface_end = ( int * ) malloc( tf * sizeof( int ) + ( tl ) * sizeof( int ) ); Dface_norm = ( VERT * ) malloc( tf * sizeof( VERT ) + ( tl ) * sizeof( VERT ) ); ///// Dvertgroup = ( int * ) malloc( tverts * sizeof( int ) ); Dlink = ( int * ) malloc( tverts * sizeof( int ) * 2 + ( tl ) * sizeof( int ) ); Dtag = ( int * ) malloc( tverts * sizeof( int ) ); Dmtlgroup = ( int * ) malloc( tf * sizeof( int ) + ( tl ) * sizeof( int ) ); DUTmtlgroup = ( int * ) malloc( tf * sizeof( int ) + ( tl ) * sizeof( int ) ); Duvfacelist = ( int * ) malloc( tfv * sizeof( int ) + ( tl * 2 ) * sizeof( int ) ); Duvface_start = ( int * ) malloc( tf * sizeof( int ) + ( tl ) * sizeof( int ) ); Duvface_end = ( int * ) malloc( tf * sizeof( int ) + ( tl ) * sizeof( int ) ); //if (DUTtotalfaces==0) DUTtotalfaces=tf; //if (DUTtotalfverts==0) DUTtotalfverts=tfv; DUTfacelist = ( int * ) malloc( ( 4 * tfv + 600 ) * sizeof( int ) + ( tl ) * sizeof( int ) ); DUTface_start = ( int * ) malloc( tf * sizeof( int ) + ( tl ) * sizeof( int ) ); DUTface_end = ( int * ) malloc( tf * sizeof( int ) + ( tl ) * sizeof( int ) ); DUTofaceID = ( int * ) malloc( tf * sizeof( int ) + ( tl ) * sizeof( int ) ); Dv = ( VERT * ) malloc( tverts * sizeof( VERT ) ); if( Dv == NULL ) { fprintf (stdout, "allocation failed! Dallocverts\n");fflush(stdout); Glow_mem = 1; Dfreeverts( ); Dtotalverts = 0; tf = 0; tfv = 0; tl = 0; tverts = 0; DRAW_STATUS( "Not Enough Memory for this object" ); } for( x = 0; x < tf; x++ ) D2UTface_link[x] = -1; for( x = 0; x < Dtotalverts; x++ ) { RDrvcolor[x] = 255; RDgvcolor[x] = 255; RDbvcolor[x] = 255; Dtag[x] = 0; // Dvertgroup[x]=0; } //Dtotalverts*=6;Dtotalfverts*=6; //printf("dtotalverts = %d\n",Dtotalverts); } static void Dfreeverts( void ) { //fprintf (stdout,"Dfreeverts\n");fflush(stdout); if (face_link) free( face_link ); face_link=NULL; if (vert2guide) free(vert2guide); vert2guide = NULL; if (guide2vert) free(guide2vert); guide2vert = NULL; if (vlink) free(vlink); vlink = NULL; if (face_link) free(face_link); face_link = NULL; if( Dface_equation != NULL ) free( Dface_equation ); Dface_equation = NULL; if( D2UTface_link != NULL ) free( D2UTface_link ); D2UTface_link = NULL; if( Dline_start != NULL ) free( Dline_start ); Dline_start=NULL; if (DUTofaceID) free( DUTofaceID ); DUTofaceID=NULL; if (DUTmtlgroup) free( DUTmtlgroup ); DUTmtlgroup=NULL; if (DUTface_start) free( DUTface_start ); DUTface_start=NULL; if (DUTface_end) free( DUTface_end ); DUTface_end=NULL; if (DUTfacelist) free( DUTfacelist ); DUTfacelist=NULL; if (Drvcolor) free( Drvcolor ); Drvcolor=NULL; if (Dgvcolor) free( Dgvcolor ); Dgvcolor=NULL; if (Dbvcolor) free( Dbvcolor ); Dbvcolor=NULL; if (RDrvcolor) free( RDrvcolor ); RDrvcolor=NULL; if (RDgvcolor) free( RDgvcolor ); RDgvcolor=NULL; if (RDbvcolor) free( RDbvcolor ); RDbvcolor=NULL; if (Dv) free( Dv ); Dv = NULL; if (vlink) free( vlink ); vlink=NULL; if (Dface_norm) free( Dface_norm ); Dface_norm=NULL; if (Drv) free( Drv ); Drv=NULL; if (Dfacelist) free( Dfacelist ); Dfacelist=NULL; if (Dface_start) free( Dface_start ); Dface_start=NULL; if (Dface_end) free( Dface_end ); Dface_end=NULL; if (Duvfacelist) free( Duvfacelist ); Duvfacelist=NULL; if (Duvface_start) free( Duvface_start ); Duvface_start=NULL; if (Duvface_end) free( Duvface_end ); Duvface_end=NULL; if (Dvertgroup) free( Dvertgroup ); Dvertgroup=NULL; if (Dlink) free( Dlink ); Dlink=NULL; if (Dflink) free( Dflink ); Dflink=NULL; if (Dmtlgroup) free( Dmtlgroup ); Dmtlgroup=NULL; if (Dvn) free( Dvn ); Dvn=NULL; if (Dtag) free( Dtag ); Dtag=NULL; if (slgfaces[0]) free( slgfaces[0] ); slgfaces[0]=NULL; if (slgfaces[1]) free( slgfaces[1] ); slgfaces[1]=NULL; if (slgfaces[2]) free( slgfaces[2] ); slgfaces[2]=NULL; if (slgfaces[3]) free( slgfaces[3] ); slgfaces[3]=NULL; if (slgfaces[4]) free( slgfaces[4] ); slgfaces[4]=NULL; total_slgfaces[0] = 0; total_slgfaces[1] = 0; total_slgfaces[2] = 0; total_slgfaces[3] = 0; total_slgfaces[4] = 0; slgfaces[0] = NULL; slgfaces[1] = NULL; slgfaces[2] = NULL; slgfaces[3] = NULL; slgfaces[4] = NULL; Dvn = NULL; Dv = NULL; Dface_norm = NULL; if (vert2guide) free( vert2guide ); vert2guide=NULL; if (guide2vert) free( guide2vert ); guide2vert=NULL; freeverts( ); free_splines( ); free_extra( ); free_freeze( ); clear_uvsets( ); Guv_totalsets = 0; Dtotalverts = 0; Dtotalfaces = 0; Dtotalfverts = 0; Dtotallines = 0; Gtotal_splinelocks= 0; free_depth( ); free_maps( ); if( COLLISION_METHOD == 1 ) freevox( ); if( Dv != NULL ) clear_uvsets( ); } static void Dinitverts( void ) { face_link=NULL; vert2guide = NULL; guide2vert = NULL; vlink = NULL; face_link = NULL; Dface_equation = NULL; D2UTface_link = NULL; Dline_start=NULL; DUTofaceID=NULL; DUTmtlgroup=NULL; DUTface_start=NULL; DUTface_end=NULL; DUTfacelist=NULL; Drvcolor=NULL; Dgvcolor=NULL; Dbvcolor=NULL; RDrvcolor=NULL; RDgvcolor=NULL; RDbvcolor=NULL; Dv = NULL; vlink=NULL; Dface_norm=NULL; Drv=NULL; Dfacelist=NULL; Dface_start=NULL; Dface_end=NULL; Duvfacelist=NULL; Duvface_start=NULL; Duvface_end=NULL; Dvertgroup=NULL; Dlink=NULL; Dflink=NULL; Dmtlgroup=NULL; Dvn=NULL; Dtag=NULL; slgfaces[0]=NULL; slgfaces[1]=NULL; slgfaces[2]=NULL; slgfaces[3]=NULL; slgfaces[4]=NULL; total_slgfaces[0] = 0; total_slgfaces[1] = 0; total_slgfaces[2] = 0; total_slgfaces[3] = 0; total_slgfaces[4] = 0; slgfaces[0] = NULL; slgfaces[1] = NULL; slgfaces[2] = NULL; slgfaces[3] = NULL; slgfaces[4] = NULL; Dvn = NULL; Dv = NULL; Dface_norm = NULL; vert2guide=NULL; guide2vert=NULL; // freeverts( ); // free_splines( ); // free_extra( ); // free_freeze( ); // clear_uvsets( ); // Guv_totalsets = 0; Dtotalverts = 0; Dtotalfaces = 0; Dtotalfverts = 0; Dtotallines = 0; Gtotal_splinelocks= 0; init_splines(); init_uvsets(); initvox(); // free_depth( ); // free_maps( ); // if( COLLISION_METHOD == 1 ) // freevox( ); // if( Dv != NULL ) // clear_uvsets( ); } static void regroup( void ) { int f, x; for( f = 0; f < totalfaces; f++ ) { if( group_stat[mtlgroup[f]] == 0 ) { for( x = face_start[f]; x < face_end[f]; x++ ) vertgroup[facelist[x]] = mtlgroup[f]; } } for( f = 0; f < totalfaces; f++ ) { if( group_stat[mtlgroup[f]] == 0 ) { if( mtlgroup[f] == skull_sphere ) for( x = face_start[f]; x < face_end[f]; x++ ) { vertgroup[facelist[x]] = mtlgroup[f]; hair[facelist[x]].mtl = mtlgroup[f]; } } } if( eyelash >= 0 ) for( f = 0; f < totalfaces; f++ ) { if( group_stat[mtlgroup[f]] == 0 ) { if( mtlgroup[f] == eyelash ) for( x = face_start[f]; x < face_end[f]; x++ ) { vertgroup[facelist[x]] = mtlgroup[f]; hair[facelist[x]].mtl = mtlgroup[f]; } } } if( splines >= 0 ) for( f = 0; f < totalfaces; f++ ) { if( group_stat[mtlgroup[f]] == 0 ) { if( mtlgroup[f] == splines ) for( x = face_start[f]; x < face_end[f]; x++ ) { vertgroup[facelist[x]] = mtlgroup[f]; hair[facelist[x]].mtl = mtlgroup[f]; } } } if( eyebrow >= 0 ) for( f = 0; f < totalfaces; f++ ) { if( group_stat[mtlgroup[f]] == 0 ) { if( mtlgroup[f] == eyebrow ) for( x = face_start[f]; x < face_end[f]; x++ ) { vertgroup[facelist[x]] = mtlgroup[f]; hair[facelist[x]].mtl = mtlgroup[f]; } } } if( beard >= 0 ) for( f = 0; f < totalfaces; f++ ) { if( group_stat[mtlgroup[f]] == 0 ) { if( mtlgroup[f] == beard ) for( x = face_start[f]; x < face_end[f]; x++ ) { vertgroup[facelist[x]] = mtlgroup[f]; hair[facelist[x]].mtl = mtlgroup[f]; } } } if( head >= 0 ) for( f = 0; f < totalfaces; f++ ) { if( group_stat[mtlgroup[f]] == 0 ) { if( mtlgroup[f] == head ) for( x = face_start[f]; x < face_end[f]; x++ ) { vertgroup[facelist[x]] = mtlgroup[f]; hair[facelist[x]].mtl = mtlgroup[f]; } } } if( skull_sphere >= 0 ) for( f = 0; f < totalfaces; f++ ) { // if (group_stat[mtlgroup[f]]==0) { if( mtlgroup[f] == skull_sphere ) for( x = face_start[f]; x < face_end[f]; x++ ) { vertgroup[facelist[x]] = mtlgroup[f]; hair[facelist[x]].mtl = mtlgroup[f]; } } } } static int bound( VERT a, VERT b, float delt ) { float d2; int ret = 0; d2 = delt; if( fabs( b.x - a.x ) < d2 ) if( fabs( b.y - a.y ) < d2 ) if( fabs( b.z - a.z ) < d2 ) ret = 1; return ( ret ); } static void getobj( CHNG *name ) /* load neutral model */ { //0 FILE *fp = NULL; int old_totalverts; int Dold_totalverts; char *stat; int tuv = 0; char tmp[1555]; char tmpst[1555]; CHNG tmpname[1555]; int x, y, tf = 0, tl = 0; char statline[255]; int current_total = 0; Glow_mem = 0; current_group = -1; //current_group=0; totalgroups = 0; Dold_totalverts = Dtotalverts; old_totalverts = totalverts; if( old_totalverts == 0 ) old_totalverts = -1; totalverts = 0; current_total = 0; totalfverts = 0; totalfaces = 0; lsSHAVEID = -1; Dfreeverts( ); freeverts( ); // SNfree( ); Dtotallines = 0; Dtotalverts = 0; Dtotalfverts = 0; Dtotalfaces = 0; Dtotalverts = 0; Dtotalfverts = 0; Dtotalfaces = 0; Dtotalfaces = 0; Dtotalverts = 0; Dtotalfverts = 0; Duvtotalfverts = 0; totalgroups = 0; DUTtotalfverts = 0; DUTtotalfaces = 0; total_splines = 0; RW_CONTEXT = RW_DISK; freeze_texl = 1; freeze_texg = 0; // global if( freeze.textoggle ) { freeze.textoggle = 1; //local freeze_texl = 0; freeze_texg = 1; } GMetaNurb = 0; scanobj( name ); // sprintf( tmp, "%s", name ); // printf ("name = %s\n",tmp); // printf ("Dtotalverts = %d\n",Dtotalverts); Dallocvert( ); Dtotallines = 0; Dtotalverts = 0; Dtotalfverts = 0; Dtotalfaces = 0; Dtotalverts = 0; Dtotalfverts = 0; Dtotalfaces = 0; Dtotalfaces = 0; Dtotalverts = 0; Dtotalfverts = 0; Duvtotalfverts = 0; totalgroups = 0; DUTtotalfverts = 0; DUTtotalfaces = 0; total_splines = 0; totalverts = 0; // problem?? // sprintf( tmp, "%s", name ); /* printf ("name = %s\n",tmp); */ // sprintf( statline, "Loading %s.", name ); // DRAW_STATUS( statline ); ////RW_CONTEXT=RW_DISK // fp=MYfopen(tmp,"r"); // fp=fopen(tmp,"r"); //fp = ( FILE * ) MYfopen( name, L"r" ); #ifdef DOUNICODE swprintf( tmpname, L"%s", name ); fp = ( FILE * ) MYfopen( tmpname, L"r" ); #else sprintf( tmpname, "%s", name ); fp = ( FILE * ) MYfopen( tmpname, "r" ); #endif if( fp == NULL ) { // DRAW_STATUS( "couldn't open obj file!\n" ); //for (x=0;x<100000;x++) { float aa; aa=cos(x);} } // for (x=0;x new group :", tmp9 ); DRAW_STATUS( statline ); // Sleep(2000); } if( gpexist( tmp9 ) != -1 ) { current_group = gpexist( tmp9 ); } /* printf ("current group = %d\n",current_group); */ } } if( current_group >= 0 ) if( tmp[0] == 'f' ) /* it's a face */ { char buf[1500] = "f -1/24/-3 \t49/5/6 \t7/8/9"; // char buf [100] = "f 1 2 3 4 5"; // char buf [100] = "f -11/99 2/88 3/77 4/66 5/33"; // char buf [100] = "f -11//99 2//88 3//77 4//66 5//33"; int tmpfl[500]; int tmpuv[500]; int tmpflc = 0; char *s; int i, slashCount, beenHereBefore = 0, x = 0; // int points [500]; // Max number of points in a face. // int uvs [500]; // Max number of UVs in a face. int normals[500]; // Max number of Normals in a face. int numVertex = 0; // Dface_start[Dtotalfaces]=Dtotalfverts; { int ii; for( ii = 0; ii < 500; ii++ ) tmpuv[ii] = 0; for( ii = 0; ii < 500; ii++ ) tmpfl[ii] = 0; } sprintf( buf, "%s", tmp ); /* Chew off the "f" */ strtok( buf, " \t" ); /* * Read junk until next SPACE character. Keep going until EOL. */ while( s = strtok( NULL, " \t\n" ) ) { /* * Count the number of Slashes in a vertex description. Do this only for the first vertex. */ if( !beenHereBefore ) { for( i = 0, slashCount = 0; i < ( int ) strlen( s ); i++ ) { if( s[i] == '/' ) slashCount++; } beenHereBefore = 1; } /* * The first number is always a vertex. (slashCount >= 0) */ // points [numVertex] = atoi (s); tmpfl[numVertex] = atoi( s ); tmpflc = numVertex; /* * We got one slash. Point and texture (U). */ if( slashCount == 1 ) { // char tmps[255]; while( *s != '/' ) s++; s++; // uvs[numVertex] = atoi (s); tmpuv[numVertex] = atoi( s ); } /* * We got 2 slashes. Point and texture (U) and Normal. */ if( slashCount == 2 ) { while( *s != '/' ) s++; s++; // uvs[numVertex] = atoi (s); tmpuv[numVertex] = atoi( s ); if( *s != '/' ) //uvs[numVertex] = atoi (s); tmpuv[numVertex] = atoi( s ); while( *s != '/' ) s++; s++; if( *s != '/' ) normals[numVertex] = atoi( s ); } tmpflc = numVertex; if( tmpfl[tmpflc] > 0 ) { tmpfl[tmpflc]--; } if( tmpuv[tmpflc] > 0 ) { tmpuv[tmpflc]--; } if( tmpfl[tmpflc] < 0 ) tmpfl[tmpflc] = Dtotalverts + tmpfl[tmpflc]; if( tmpuv[tmpflc] < 0 ) tmpuv[tmpflc] = ttv + tmpuv[tmpflc]; numVertex++; } tmpflc = numVertex; sprintf( tmpst, "%06s", group_names[current_group] ); if( strcmp( "spline", tmpst ) != 0 ) // (group_names[current_group][0]!='s')&& // (group_names[current_group][1]!='p')&& // (group_names[current_group][2]!='l')&& // (group_names[current_group][3]!='i')&& // (group_names[current_group][4]!='n') // ) { if( tmpflc > 2 ) { DUTface_start[DUTtotalfaces] = DUTtotalfverts; for( x = 0; x < tmpflc; x++ ) { DUTfacelist[DUTtotalfverts] = tmpfl[x]; //-Dtotalfverts+DUTtotalfverts; DUTtotalfverts++; } //// DUTofaceID[DUTtotalfaces]=Dtotalfaces-1; DUTmtlgroup[DUTtotalfaces] = current_group; DUTface_end[DUTtotalfaces] = DUTtotalfverts; D2UTface_link[Dtotalfaces] = DUTtotalfaces; DUTtotalfaces++; } if( tmpflc >= 3 ) { D2UTface_link[Dtotalfaces] = DUTtotalfaces - 1; Duvface_start[Dtotalfaces] = Dtotalfverts; Dface_start[Dtotalfaces] = Dtotalfverts; for( x = 2; x >= 0; x-- ) { Dfacelist[Dtotalfverts] = tmpfl[x]; Dtotalfverts++; Duvfacelist[Duvtotalfverts] = tmpuv[x]; Duvtotalfverts++; } Dface_end[Dtotalfaces] = Dtotalfverts; Duvface_end[Dtotalfaces] = Duvtotalfverts; /* assign vertex groups */ Dmtlgroup[Dtotalfaces] = current_group; // if (Dface_start[Dtotalfaces]!=Dface_end[Dtotalfaces]) for( x = Dface_start[Dtotalfaces]; x < Dface_end[Dtotalfaces]; x++ ) { int qqq; qqq = Dfacelist[x]; Dvertgroup[qqq] = current_group; Dmtlgroup[Dtotalfaces] = current_group; group_enable[Dvertgroup[Dfacelist[Dface_start[Dtotalfaces]]]] = 1; } if( Dface_end[Dtotalfaces] == Dface_start[Dtotalfaces] ) printf( "0 vert face!\n" ); D2UTface_link[Dtotalfaces] = DUTtotalfaces - 1; if( Dface_end[Dtotalfaces] != Dface_start[Dtotalfaces] ) Dtotalfaces++; } /* totalfverts++; */ if( tmpflc > 3 ) { int xx; for( x = 2; x < tmpflc - 1; x++ ) { Dface_start[Dtotalfaces] = Dtotalfverts; Duvface_start[Dtotalfaces] = Duvtotalfverts; Dfacelist[Dtotalfverts] = tmpfl[x + 1]; Dtotalfverts++; Dfacelist[Dtotalfverts] = tmpfl[x]; Dtotalfverts++; Dfacelist[Dtotalfverts] = tmpfl[0]; Dtotalfverts++; Duvfacelist[Duvtotalfverts] = tmpuv[x + 1]; Duvtotalfverts++; Duvfacelist[Duvtotalfverts] = tmpuv[x]; Duvtotalfverts++; Duvfacelist[Duvtotalfverts] = tmpuv[0]; Duvtotalfverts++; Duvface_end[Dtotalfaces] = Duvtotalfverts; Dface_end[Dtotalfaces] = Dtotalfverts; /* assign vertex groups */ Dmtlgroup[Dtotalfaces] = current_group; // if (Dface_start[Dtotalfaces]!=Dface_end[totalfaces]) for( xx = Dface_start[Dtotalfaces]; xx < Dface_end[Dtotalfaces]; xx++ ) { int qqq; qqq = Dfacelist[xx]; Dvertgroup[qqq] = current_group; Dmtlgroup[Dtotalfaces] = current_group; group_enable[Dvertgroup[Dfacelist[Dface_start[Dtotalfaces]]]] = 1; } // if (Dface_end[Dtotalfaces]==Dface_start[Dtotalfaces]) printf("0 vert face!\n"); // if (Dface_end[Dtotalfaces]!=Dface_start[Dtotalfaces]) Dtotalfaces++; D2UTface_link[Dtotalfaces] = DUTtotalfaces - 1; Dtotalfaces++; } } // // now lets add the untriangulated face } //if (0==1) else // it's a spline if( tmpflc > 2 ) { int zz; int xx; DRAW_STATUS( "spline" ); // for (xx=0;xx<1000000;xx++) zz=(int)cos(xx); Dface_start[Dtotalfaces] = Dtotalfverts; DUTface_start[DUTtotalfaces] = DUTtotalfverts; for( zz = 0; zz < tmpflc; zz++ ) { Dfacelist[Dtotalfverts] = tmpfl[zz]; DUTfacelist[DUTtotalfverts] = tmpfl[zz]; Dtotalfverts++; DUTtotalfverts++; } Dface_end[Dtotalfaces] = Dtotalfverts; DUTface_end[DUTtotalfaces] = DUTtotalfverts; Dmtlgroup[Dtotalfaces] = current_group; DUTmtlgroup[DUTtotalfaces] = current_group; if( Dface_start[Dtotalfaces] != Dface_end[totalfaces] ) for( xx = Dface_start[Dtotalfaces]; xx < Dface_end[Dtotalfaces]; xx++ ) { int qqq; qqq = Dfacelist[xx]; Dvertgroup[qqq] = current_group; DUTmtlgroup[DUTtotalfaces] = current_group; Dmtlgroup[Dtotalfaces] = current_group; group_enable[Dvertgroup[Dfacelist[Dface_start[Dtotalfaces]]]] = 1; } D2UTface_link[Dtotalfaces] = DUTtotalfaces; // what is this it? // D2UTface_link[Dtotalfaces]= -2; // it's a spline so there's no lookup? DUTtotalfaces++; Dtotalfaces++; } // its a spline } if( current_group >= 0 ) if( tmp[0] == 'l' ) /* it's a line */ { char buf[1500] = "f -1/24/-3 \t49/5/6 \t7/8/9"; // char buf [100] = "f 1 2 3 4 5"; // char buf [100] = "f -11/99 2/88 3/77 4/66 5/33"; // char buf [100] = "f -11//99 2//88 3//77 4//66 5//33"; int tmpfl[500]; int tmpuv[500]; int tmpflc = 0; char *s; int i, slashCount, beenHereBefore = 0, x = 0; // int points [500]; // Max number of points in a face. // int uvs [500]; // Max number of UVs in a face. int normals[500]; // Max number of Normals in a face. int numVertex = 0; // Dface_start[Dtotalfaces]=Dtotalfverts; { int ii; for( ii = 0; ii < 500; ii++ ) tmpuv[ii] = 0; for( ii = 0; ii < 500; ii++ ) tmpfl[ii] = 0; } sprintf( buf, "%s", tmp ); /* Chew off the "f" */ strtok( buf, " \t" ); /* * Read junk until next SPACE character. Keep going until EOL. */ while( s = strtok( NULL, " \t\n" ) ) { /* * Count the number of Slashes in a vertex description. Do this only for the first vertex. */ if( !beenHereBefore ) { for( i = 0, slashCount = 0; i < ( int ) strlen( s ); i++ ) { if( s[i] == '/' ) slashCount++; } beenHereBefore = 1; } /* * The first number is always a vertex. (slashCount >= 0) */ // points [numVertex] = atoi (s); tmpfl[numVertex] = atoi( s ); tmpflc = numVertex; /* * We got one slash. Point and texture (U). */ if( slashCount == 1 ) { // char tmps[255]; while( *s != '/' ) s++; s++; // uvs[numVertex] = atoi (s); tmpuv[numVertex] = atoi( s ); } /* * We got 2 slashes. Point and texture (U) and Normal. */ if( slashCount == 2 ) { while( *s != '/' ) s++; s++; // uvs[numVertex] = atoi (s); tmpuv[numVertex] = atoi( s ); if( *s != '/' ) //uvs[numVertex] = atoi (s); tmpuv[numVertex] = atoi( s ); while( *s != '/' ) s++; s++; if( *s != '/' ) normals[numVertex] = atoi( s ); } tmpflc = numVertex; if( tmpfl[tmpflc] > 0 ) { tmpfl[tmpflc]--; } if( tmpuv[tmpflc] > 0 ) { tmpuv[tmpflc]--; } if( tmpfl[tmpflc] < 0 ) tmpfl[tmpflc] = Dtotalverts + tmpfl[tmpflc]; if( tmpuv[tmpflc] < 0 ) tmpuv[tmpflc] = ttv + tmpuv[tmpflc]; numVertex++; } tmpflc = numVertex; sprintf( tmpst, "%06s", group_names[current_group] ); // if (strcmp(tmp,"spline")==0) if( tmpflc > 1 ) // more than 2 sides for( x = 0; x < tmpflc - 1; x += 2 ) { Dline_start[Dtotallines] = tmpfl[x]; Dtotallines++; } } } /* printf ("totalverts = %d totalfaces = %d totalfverts = %d\n",totalverts,totalfaces,totalfverts); */ // sprintf (statline,"totalverts = %d totalfaces = %d totalfverts = %d version %c",Dtotalverts,Dtotalfaces,Dtotalfverts,shaveversion); // DRAW_STATUS(statline); MYfclose( fp ); // fclose(fp); } reset_rest( ); // DRAW_STATUS(statline); old_totalverts = Dtotalverts; mkbounds( ); for( x = 0; x < Dtotalverts; x++ ) Drv[x] = Dv[x]; //if (shaveversion2<='m') // Dregroup( ); //else Dregroup2( ); // fish_chains( ); //if (shaveversion<='m') // reorg( ); // extract the faces //else reorg2( ); //make_splines(); #ifndef SOFTIMAGE for( x = 0; x < totalverts; x++ ) { for( y = 0; y < 15; y++ ) { hair[x].select[y] = 0; // resthair[x].select[y]=0; } if( hair[x].mtl != skull_sphere ) { // resthair[x].select[0]=1; // resthair[x].select[14]=1; hair[x].select[0] = 1; hair[x].select[14] = 1; } } if( total_splines > 0 ) for( x = 0; x < total_splines; x++ ) { { Sresthair[x].select[0] = 1; Sresthair[x].select[14] = 1; Shair[x].select[0] = 1; Shair[x].select[14] = 1; } } #endif center_select( ); if( 0 == 1 ) // flipping the faces here !!! if( flip_norms == 1 ) { int buffi[555]; int z; for( x = 0; x < Dtotalfaces; x++ ) if( Dface_end[x] - Dface_start[x] >= 2 ) { z = 0; for( y = Dface_start[x]; y < Dface_end[x]; y++ ) { buffi[z] = Dfacelist[y]; z++; } z = Dface_end[x] - 1 - Dface_start[x]; for( y = Dface_start[x]; y < Dface_end[x]; y++ ) { Dfacelist[y] = buffi[z]; z--; } } for( x = 0; x < totalfaces; x++ ) if( face_end[x] - face_start[x] >= 2 ) { z = 0; for( y = face_start[x]; y < face_end[x]; y++ ) { buffi[z] = facelist[y]; z++; } z = face_end[x] - 1 - face_start[x]; for( y = face_start[x]; y < face_end[x]; y++ ) { facelist[y] = buffi[z]; z--; } } for( x = 0; x < DUTtotalfaces; x++ ) if( DUTface_end[x] - DUTface_start[x] >= 2 ) { z = 0; for( y = DUTface_start[x]; y < DUTface_end[x]; y++ ) { buffi[z] = DUTfacelist[y]; z++; } z = DUTface_end[x] - DUTface_start[x] - 1; for( y = DUTface_start[x]; y < DUTface_end[x]; y++ ) { DUTfacelist[y] = buffi[z]; z--; } } } //if (RW_CONTEXT==RW_DISK) // Dmake_normals(); // Dflip_normals(); //if (shaveversions<='m') // init_hair( ); //else init_hair2( ); reset_dynamics( ); #ifndef SOFTIMAGE for( x = 0; x < totalverts; x++ ) { if( hair[x].mtl != skull_sphere ) for( y = 0; y < 15; y++ ) { hair[x].select[y] = 0; // resthair[x].select[y]=0; } if( hair[x].mtl != skull_sphere ) { // resthair[x].select[0]=1; // resthair[x].select[14]=1; } } if( total_splines > 0 ) for( x = 0; x < total_splines; x++ ) { { Sresthair[x].select[0] = 1; Sresthair[x].select[14] = 1; Shair[x].select[0] = 1; Shair[x].select[14] = 1; } } for( x = 0; x < totalverts; x++ ) { hair[x].select[0] = 1; hair[x].select[14] = 1; } #endif center_select( ); DRAW_STATUS( "centered view" ); DRAW_STATUS( "backing up rest position" ); //#ifndef SOFTIMAGE for( x = 0; x < totalverts; x++ ) hair[x].splitgroup = 0; if( total_splines > 0 ) for( x = 0; x < total_splines; x++ ) Shair[x].splitgroup = 0; if( total_splines > 0 ) for( x = 0; x < total_splines; x++ ) Shair[x].splitmerge = 0; for( x = 0; x < total_splines; x++ ) Sresthair[x].splitmerge = 0; totalsplits = 1; //#endif for( x = 0; x < totalverts; x++ ) for( y = 0; y < 15; y++ ) hair[x].resthv[y] = hair[x].hv[y]; DRAW_STATUS( "re-centering" ); center_select( ); DRAW_STATUS( "resetting dynamics" ); reset_dynamics( ); DRAW_STATUS( "making normals" ); make_normals( ); DRAW_STATUS( "bakcking up normals" ); for( x = 0; x < totalverts; x++ ) vnrest[x] = vn[x]; DRAW_STATUS( "done loading/grooming" ); make_splines2( ); //printf("totalverts = %d\n",totalverts); reset_faces( ); collect_guides( ); // set_defaults(); } static void Mgetobj( CHNG *name ) /* load neutral model */ { //0 FILE *fp = NULL; int old_totalverts; int Dold_totalverts; char *stat; int tuv = 0; char tmp[1555]; char tmpst[1555]; int x, y, tf = 0, tl = 0; char statline[255]; int current_total = 0; current_group = -1; //current_group=0; totalgroups = 0; Dold_totalverts = Dtotalverts; old_totalverts = totalverts; if( old_totalverts == 0 ) old_totalverts = -1; totalverts = 0; current_total = 0; totalfverts = 0; totalfaces = 0; Dfreeverts( ); lsSHAVEID = -1; freeverts( ); // SNfree( ); Dtotallines = 0; Dtotalverts = 0; Dtotalfverts = 0; Dtotalfaces = 0; Dtotalverts = 0; Dtotalfverts = 0; Dtotalfaces = 0; Dtotalfaces = 0; Dtotalverts = 0; Dtotalfverts = 0; Duvtotalfverts = 0; totalgroups = 0; DUTtotalfverts = 0; DUTtotalfaces = 0; total_splines = 0; RW_CONTEXT = RW_DISK; freeze_texl = 1; freeze_texg = 0; // global if( freeze.textoggle ) { freeze.textoggle = 1; //local freeze_texl = 0; freeze_texg = 1; } // SNfree( ); GMetaNurb = 0; scanobj( name ); sprintf( tmp, "%s", name ); // printf ("name = %s\n",tmp); Dallocvert( ); Dtotallines = 0; Dtotalverts = 0; Dtotalfverts = 0; Dtotalfaces = 0; Dtotalverts = 0; Dtotalfverts = 0; Dtotalfaces = 0; Dtotalfaces = 0; Dtotalverts = 0; Dtotalfverts = 0; Duvtotalfverts = 0; totalgroups = 0; DUTtotalfverts = 0; DUTtotalfaces = 0; total_splines = 0; totalverts = 0; // problem?? //sprintf( tmp, "%s", name ); /* printf ("name = %s\n",tmp); */ // sprintf( statline, "Loading %s.", name ); //DRAW_STATUS( statline ); // fp=MYfopen(tmp,"r"); // fp=fopen(tmp,"r"); #ifdef DOUNICODE fp = ( FILE * ) MYfopen( name, L"r" ); #else fp = ( FILE * ) MYfopen( name, "r" ); #endif if( fp == NULL ) { DRAW_STATUS( "couldn't open obj file!\n" ); //for (x=0;x<100000;x++) { float aa; aa=cos(x);} } // for (x=0;x new group :", tmp9 ); DRAW_STATUS( statline ); // Sleep(2000); } if( gpexist( tmp9 ) != -1 ) { current_group = gpexist( tmp9 ); } /* printf ("current group = %d\n",current_group); */ } } if( current_group >= 0 ) if( tmp[0] == 'f' ) /* it's a face */ { char buf[1500] = "f -1/24/-3 \t49/5/6 \t7/8/9"; // char buf [100] = "f 1 2 3 4 5"; // char buf [100] = "f -11/99 2/88 3/77 4/66 5/33"; // char buf [100] = "f -11//99 2//88 3//77 4//66 5//33"; int tmpfl[500]; int tmpuv[500]; int tmpflc = 0; char *s; int i, slashCount, beenHereBefore = 0, x = 0; // int points [500]; // Max number of points in a face. // int uvs [500]; // Max number of UVs in a face. int normals[500]; // Max number of Normals in a face. int numVertex = 0; // Dface_start[Dtotalfaces]=Dtotalfverts; { int ii; for( ii = 0; ii < 500; ii++ ) tmpuv[ii] = 0; for( ii = 0; ii < 500; ii++ ) tmpfl[ii] = 0; } sprintf( buf, "%s", tmp ); /* Chew off the "f" */ strtok( buf, " \t" ); /* * Read junk until next SPACE character. Keep going until EOL. */ while( s = strtok( NULL, " \t\n" ) ) { /* * Count the number of Slashes in a vertex description. Do this only for the first vertex. */ if( !beenHereBefore ) { for( i = 0, slashCount = 0; i < ( int ) strlen( s ); i++ ) { if( s[i] == '/' ) slashCount++; } beenHereBefore = 1; } /* * The first number is always a vertex. (slashCount >= 0) */ // points [numVertex] = atoi (s); tmpfl[numVertex] = atoi( s ); tmpflc = numVertex; /* * We got one slash. Point and texture (U). */ if( slashCount == 1 ) { // char tmps[255]; while( *s != '/' ) s++; s++; // uvs[numVertex] = atoi (s); tmpuv[numVertex] = atoi( s ); } /* * We got 2 slashes. Point and texture (U) and Normal. */ if( slashCount == 2 ) { while( *s != '/' ) s++; s++; // uvs[numVertex] = atoi (s); tmpuv[numVertex] = atoi( s ); if( *s != '/' ) //uvs[numVertex] = atoi (s); tmpuv[numVertex] = atoi( s ); while( *s != '/' ) s++; s++; if( *s != '/' ) normals[numVertex] = atoi( s ); } tmpflc = numVertex; if( tmpfl[tmpflc] > 0 ) { tmpfl[tmpflc]--; } if( tmpuv[tmpflc] > 0 ) { tmpuv[tmpflc]--; } if( tmpfl[tmpflc] < 0 ) tmpfl[tmpflc] = Dtotalverts + tmpfl[tmpflc]; if( tmpuv[tmpflc] < 0 ) tmpuv[tmpflc] = ttv + tmpuv[tmpflc]; numVertex++; } tmpflc = numVertex; sprintf( tmpst, "%06s", group_names[current_group] ); if( strcmp( "spline", tmpst ) != 0 ) // (group_names[current_group][0]!='s')&& // (group_names[current_group][1]!='p')&& // (group_names[current_group][2]!='l')&& // (group_names[current_group][3]!='i')&& // (group_names[current_group][4]!='n') // ) { if( tmpflc > 2 ) { DUTface_start[DUTtotalfaces] = DUTtotalfverts; for( x = 0; x < tmpflc; x++ ) { DUTfacelist[DUTtotalfverts] = tmpfl[x]; //-Dtotalfverts+DUTtotalfverts; DUTtotalfverts++; } //// DUTofaceID[DUTtotalfaces]=Dtotalfaces-1; DUTmtlgroup[DUTtotalfaces] = current_group; DUTface_end[DUTtotalfaces] = DUTtotalfverts; DUTtotalfaces++; } if( tmpflc >= 3 ) { D2UTface_link[Dtotalfaces] = DUTtotalfaces - 1; Duvface_start[Dtotalfaces] = Dtotalfverts; Dface_start[Dtotalfaces] = Dtotalfverts; for( x = 2; x >= 0; x-- ) { Dfacelist[Dtotalfverts] = tmpfl[x]; Dtotalfverts++; Duvfacelist[Duvtotalfverts] = tmpuv[x]; Duvtotalfverts++; } Dface_end[Dtotalfaces] = Dtotalfverts; Duvface_end[Dtotalfaces] = Duvtotalfverts; /* assign vertex groups */ Dmtlgroup[Dtotalfaces] = current_group; // if (Dface_start[Dtotalfaces]!=Dface_end[Dtotalfaces]) for( x = Dface_start[Dtotalfaces]; x < Dface_end[Dtotalfaces]; x++ ) { int qqq; qqq = Dfacelist[x]; Dvertgroup[qqq] = current_group; Dmtlgroup[Dtotalfaces] = current_group; group_enable[Dvertgroup[Dfacelist[Dface_start[Dtotalfaces]]]] = 1; } //if (Dface_end[Dtotalfaces]==Dface_start[Dtotalfaces]) printf("0 vert face!\n"); D2UTface_link[Dtotalfaces] = DUTtotalfaces - 1; if( Dface_end[Dtotalfaces] != Dface_start[Dtotalfaces] ) Dtotalfaces++; } /* totalfverts++; */ if( tmpflc > 3 ) { int xx; for( x = 2; x < tmpflc - 1; x++ ) { Dface_start[Dtotalfaces] = Dtotalfverts; Duvface_start[Dtotalfaces] = Duvtotalfverts; Dfacelist[Dtotalfverts] = tmpfl[x + 1]; Dtotalfverts++; Dfacelist[Dtotalfverts] = tmpfl[x]; Dtotalfverts++; Dfacelist[Dtotalfverts] = tmpfl[0]; Dtotalfverts++; Duvfacelist[Duvtotalfverts] = tmpuv[x + 1]; Duvtotalfverts++; Duvfacelist[Duvtotalfverts] = tmpuv[x]; Duvtotalfverts++; Duvfacelist[Duvtotalfverts] = tmpuv[0]; Duvtotalfverts++; Duvface_end[Dtotalfaces] = Duvtotalfverts; Dface_end[Dtotalfaces] = Dtotalfverts; /* assign vertex groups */ Dmtlgroup[Dtotalfaces] = current_group; // if (Dface_start[Dtotalfaces]!=Dface_end[totalfaces]) for( xx = Dface_start[Dtotalfaces]; xx < Dface_end[Dtotalfaces]; xx++ ) { int qqq; qqq = Dfacelist[xx]; Dvertgroup[qqq] = current_group; Dmtlgroup[Dtotalfaces] = current_group; group_enable[Dvertgroup[Dfacelist[Dface_start[Dtotalfaces]]]] = 1; } // if (Dface_end[Dtotalfaces]==Dface_start[Dtotalfaces]) printf("0 vert face!\n"); // if (Dface_end[Dtotalfaces]!=Dface_start[Dtotalfaces]) Dtotalfaces++; D2UTface_link[Dtotalfaces] = DUTtotalfaces - 1; Dtotalfaces++; } } // // now lets add the untriangulated face } //if (0==1) else // it's a spline if( tmpflc > 2 ) { int zz; int xx; DRAW_STATUS( "spline" ); // for (xx=0;xx<1000000;xx++) zz=(int)cos(xx); Dface_start[Dtotalfaces] = Dtotalfverts; DUTface_start[DUTtotalfaces] = DUTtotalfverts; for( zz = 0; zz < tmpflc; zz++ ) { Dfacelist[Dtotalfverts] = tmpfl[zz]; DUTfacelist[DUTtotalfverts] = tmpfl[zz]; Dtotalfverts++; DUTtotalfverts++; } Dface_end[Dtotalfaces] = Dtotalfverts; DUTface_end[DUTtotalfaces] = DUTtotalfverts; Dmtlgroup[Dtotalfaces] = current_group; DUTmtlgroup[DUTtotalfaces] = current_group; if( Dface_start[Dtotalfaces] != Dface_end[totalfaces] ) for( xx = Dface_start[Dtotalfaces]; xx < Dface_end[Dtotalfaces]; xx++ ) { int qqq; qqq = Dfacelist[xx]; Dvertgroup[qqq] = current_group; DUTmtlgroup[DUTtotalfaces] = current_group; Dmtlgroup[Dtotalfaces] = current_group; group_enable[Dvertgroup[Dfacelist[Dface_start[Dtotalfaces]]]] = 1; } D2UTface_link[Dtotalfaces] = DUTtotalfaces; // D2UTface_link[Dtotalfaces]= -2; // it's a spline so there's no lookup? DUTtotalfaces++; Dtotalfaces++; } // its a spline } if( current_group >= 0 ) if( tmp[0] == 'l' ) /* it's a line */ { char buf[1500] = "f -1/24/-3 \t49/5/6 \t7/8/9"; // char buf [100] = "f 1 2 3 4 5"; // char buf [100] = "f -11/99 2/88 3/77 4/66 5/33"; // char buf [100] = "f -11//99 2//88 3//77 4//66 5//33"; int tmpfl[500]; int tmpuv[500]; int tmpflc = 0; char *s; int i, slashCount, beenHereBefore = 0, x = 0; // int points [500]; // Max number of points in a face. // int uvs [500]; // Max number of UVs in a face. int normals[500]; // Max number of Normals in a face. int numVertex = 0; // Dface_start[Dtotalfaces]=Dtotalfverts; { int ii; for( ii = 0; ii < 500; ii++ ) tmpuv[ii] = 0; for( ii = 0; ii < 500; ii++ ) tmpfl[ii] = 0; } sprintf( buf, "%s", tmp ); /* Chew off the "f" */ strtok( buf, " \t" ); /* * Read junk until next SPACE character. Keep going until EOL. */ while( s = strtok( NULL, " \t\n" ) ) { /* * Count the number of Slashes in a vertex description. Do this only for the first vertex. */ if( !beenHereBefore ) { for( i = 0, slashCount = 0; i < ( int ) strlen( s ); i++ ) { if( s[i] == '/' ) slashCount++; } beenHereBefore = 1; } /* * The first number is always a vertex. (slashCount >= 0) */ // points [numVertex] = atoi (s); tmpfl[numVertex] = atoi( s ); tmpflc = numVertex; /* * We got one slash. Point and texture (U). */ if( slashCount == 1 ) { // char tmps[255]; while( *s != '/' ) s++; s++; // uvs[numVertex] = atoi (s); tmpuv[numVertex] = atoi( s ); } /* * We got 2 slashes. Point and texture (U) and Normal. */ if( slashCount == 2 ) { while( *s != '/' ) s++; s++; // uvs[numVertex] = atoi (s); tmpuv[numVertex] = atoi( s ); if( *s != '/' ) //uvs[numVertex] = atoi (s); tmpuv[numVertex] = atoi( s ); while( *s != '/' ) s++; s++; if( *s != '/' ) normals[numVertex] = atoi( s ); } tmpflc = numVertex; if( tmpfl[tmpflc] > 0 ) { tmpfl[tmpflc]--; } if( tmpuv[tmpflc] > 0 ) { tmpuv[tmpflc]--; } if( tmpfl[tmpflc] < 0 ) tmpfl[tmpflc] = Dtotalverts + tmpfl[tmpflc]; if( tmpuv[tmpflc] < 0 ) tmpuv[tmpflc] = ttv + tmpuv[tmpflc]; numVertex++; } tmpflc = numVertex; sprintf( tmpst, "%06s", group_names[current_group] ); // if (strcmp(tmp,"spline")==0) if( tmpflc > 1 ) // more than 2 sides for( x = 0; x < tmpflc - 1; x += 2 ) { Dline_start[Dtotallines] = tmpfl[x]; Dtotallines++; } } } /* printf ("totalverts = %d totalfaces = %d totalfverts = %d\n",totalverts,totalfaces,totalfverts); */ // sprintf (statline,"totalverts = %d totalfaces = %d totalfverts = %d version %c",Dtotalverts,Dtotalfaces,Dtotalfverts,shaveversion); // DRAW_STATUS(statline); MYfclose( fp ); // fclose(fp); } // DRAW_STATUS(statline); old_totalverts = Dtotalverts; mkbounds( ); for( x = 0; x < Dtotalverts; x++ ) Drv[x] = Dv[x]; Dregroup( ); // fish_chains( ); reorg( ); // extract the faces //make_splines(); #ifndef SOFTIMAGE for( x = 0; x < totalverts; x++ ) { for( y = 0; y < 15; y++ ) { hair[x].select[y] = 0; // resthair[x].select[y]=0; } if( hair[x].mtl != skull_sphere ) { // resthair[x].select[0]=1; // resthair[x].select[14]=1; hair[x].select[0] = 1; hair[x].select[14] = 1; } } if( total_splines > 0 ) for( x = 0; x < total_splines; x++ ) { { Sresthair[x].select[0] = 1; Sresthair[x].select[14] = 1; Shair[x].select[0] = 1; Shair[x].select[14] = 1; } } #endif center_select( ); Dmake_normals( ); // Dflip_normals(); init_hair( ); reset_dynamics( ); #ifndef SOFTIMAGE for( x = 0; x < totalverts; x++ ) { if( hair[x].mtl != skull_sphere ) for( y = 0; y < 15; y++ ) { hair[x].select[y] = 0; // resthair[x].select[y]=0; } if( hair[x].mtl != skull_sphere ) { // resthair[x].select[0]=1; // resthair[x].select[14]=1; } } if( total_splines > 0 ) for( x = 0; x < total_splines; x++ ) { { Sresthair[x].select[0] = 1; Sresthair[x].select[14] = 1; Shair[x].select[0] = 1; Shair[x].select[14] = 1; } } for( x = 0; x < totalverts; x++ ) { hair[x].select[0] = 1; hair[x].select[14] = 1; } #endif center_select( ); DRAW_STATUS( "centered view" ); DRAW_STATUS( "backing up rest position" ); //#ifndef SOFTIMAGE for( x = 0; x < totalverts; x++ ) hair[x].splitgroup = 0; if( total_splines > 0 ) for( x = 0; x < total_splines; x++ ) Shair[x].splitgroup = 0; totalsplits = 1; //#endif for( x = 0; x < totalverts; x++ ) for( y = 0; y < 15; y++ ) hair[x].resthv[y] = hair[x].hv[y]; DRAW_STATUS( "re-centering" ); center_select( ); DRAW_STATUS( "resetting dynamics" ); reset_dynamics( ); DRAW_STATUS( "making normals" ); make_normals( ); DRAW_STATUS( "bakcking up normals" ); for( x = 0; x < totalverts; x++ ) vnrest[x] = vn[x]; DRAW_STATUS( "done loading/grooming" ); //printf("totalverts = %d\n",totalverts); reset_faces( ); collect_guides( ); } static void getmorph( CHNG *name ) /* load neutral model */ { FILE *fp = NULL; int old_totalverts; char *stat; CHNG tmp[255]; int x, tf = 0; char statline[255]; int current_total = 0; old_totalverts = totalverts; if( old_totalverts == 0 ) old_totalverts = -1; current_total = 0; freeze_texl = 1; freeze_texg = 0; // global if( freeze.textoggle ) { freeze.textoggle = 1; //local freeze_texl = 0; freeze_texg = 1; } // sprintf( tmp, "%s", name ); /* printf ("name = %s\n",tmp); */ // sprintf( statline, "Loading %s.", name ); DRAW_STATUS( statline ); #ifdef DOUNICODE fp = ( FILE * ) MYfopen( name, L"r" ); #else fp = ( FILE * ) MYfopen( name, "r" ); #endif if( fp ) { stat = MYfgets( tmp, 1255, fp ); // while (stat!=NULL) while( !feof( fp ) ) { // char *tmp2; if( ( tmp[0] == 'v' ) && ( tmp[1] != 'n' ) && ( tmp[1] != 't' ) && ( tmp[1] != 'c' ) ) /* it's a vertex */ { current_total++; } if( tmp[0] == 'f' ) { tf++; } stat = MYfgets( tmp, 1255, fp ); } MYfclose( fp ); } // sprintf( tmp, "%s", name ); /* printf ("name = %s\n",tmp); */ // sprintf( statline, "Loading %s.", name ); // DRAW_STATUS( statline ); #ifdef DOUNICODE fp = ( FILE * ) MYfopen( name, L"r" ); #else fp = ( FILE * ) MYfopen( name, "r" ); #endif if( current_total != Dtotalverts ) { DRAW_STATUS( "error: point count doesn't match." ); sprintf( statline, "error: point count doesn't match." ); } // for (x=0;x 0 ) { BOUNDX = 1000000; BOUNDY = 1000000; BOUNDZ = 1000000; BOUND1X = -1000000; BOUND1Y = -1000000; BOUND1Z = -1000000; if( total_splines == 0 ) if( totalverts > 0 ) for( x = 0; x < totalverts; x++ ) if( ( ( head >= 0 ) && ( hair[x].mtl == head ) ) || ( ( splines >= 0 ) && ( hair[x].mtl == splines ) ) ) if( hair[x].restlength > 0 ) for( y = 0; y < 15; y++ ) if( hair[x].select[y] ) { #ifndef NOLIB if( hair[x].noisev[y].x > BOUND1X ) BOUND1X = hair[x].noisev[y].x; if( hair[x].noisev[y].y > BOUND1Y ) BOUND1Y = hair[x].noisev[y].y; if( hair[x].noisev[y].z > BOUND1Z ) BOUND1Z = hair[x].noisev[y].z; if( hair[x].noisev[y].x < BOUNDX ) BOUNDX = hair[x].noisev[y].x; if( hair[x].noisev[y].y < BOUNDY ) BOUNDY = hair[x].noisev[y].y; if( hair[x].noisev[y].z < BOUNDZ ) BOUNDZ = hair[x].noisev[y].z; #endif } if( total_splines > 0 ) for( x = 0; x < total_splines; x++ ) for( y = 0; y < 15; y++ ) { if( Sresthair[x].noisev[y].x > BOUND1X ) BOUND1X = Sresthair[x].hv[y].x; if( Sresthair[x].noisev[y].y > BOUND1Y ) BOUND1Y = Sresthair[x].hv[y].y; if( Sresthair[x].noisev[y].z > BOUND1Z ) BOUND1Z = Sresthair[x].hv[y].z; if( Sresthair[x].noisev[y].x < BOUNDX ) BOUNDX = Sresthair[x].hv[y].x; if( Sresthair[x].noisev[y].y < BOUNDY ) BOUNDY = Sresthair[x].hv[y].y; if( Sresthair[x].noisev[y].z < BOUNDZ ) BOUNDZ = Sresthair[x].hv[y].z; } { float big = 0; if( ( BOUND1X - BOUNDX ) > big ) big = BOUND1X - BOUNDX; if( ( BOUND1Y - BOUNDY ) > big ) big = BOUND1Y - BOUNDY; if( ( BOUND1Z - BOUNDZ ) > big ) big = BOUND1Z - BOUNDZ; } { float dx, dy, dz; dx = BOUND1X - BOUNDX; dy = BOUND1Y - BOUNDY; dz = BOUND1Z - BOUNDZ; BOUNDLENGTH = fsqrt( dx * dx + dy * dy + dz * dz ); restBOUNDLENGTH = BOUNDLENGTH; } } } { float big = 0; } cam_panx = -( BOUND1X + BOUNDX ) / 2.0f; cam_pany = -( BOUND1Y + BOUNDY ) / 2.0f; cam_panz = -( BOUND1Z + BOUNDZ ) / 2.0f; { float dx, dy, dz; dx = BOUND1X - BOUNDX; dy = BOUND1Y - BOUNDY; dz = BOUND1Z - BOUNDZ; BOUNDLENGTH = sqrt( dx * dx + dy * dy + dz * dz ); restBOUNDLENGTH = sqrt( dx * dx + dy * dy + dz * dz ); cam_scale = -( 2.0 / BOUNDLENGTH ) * 1.25; } mkbounds( ); } } static void center_select( void ) { int x; int y; int selnone = 1; int gotface = 0; selnone = 1; refresh_OGL = 1; center_selectNOLIB( ); } static void center_all( void ) { // int x; // int y; int selnone = 1; // mkbounds2(); { int x; int y = 0; restBOUNDLENGTH = 0; BOUNDLENGTH = 0; if( Dtotalverts > 0 ) { BOUNDX = 1000000; BOUNDY = 1000000; BOUNDZ = 1000000; BOUND1X = -1000000; BOUND1Y = -1000000; BOUND1Z = -1000000; for( x = 0; x < Dtotalverts; x++ ) for( y = 0; y < 15; y++ ) { if( Drv[x].x > BOUND1X ) BOUND1X = Drv[x].x; if( Drv[x].y > BOUND1Y ) BOUND1Y = Drv[x].y; if( Drv[x].z > BOUND1Z ) BOUND1Z = Drv[x].z; if( Drv[x].x < BOUNDX ) BOUNDX = Drv[x].x; if( Drv[x].y < BOUNDY ) BOUNDY = Drv[x].y; if( Drv[x].z < BOUNDZ ) BOUNDZ = Drv[x].z; } if( totalverts > 0 ) for( x = 0; x < totalverts; x++ ) if( ( ( head >= 0 ) && ( hair[x].mtl == head ) ) || ( ( splines >= 0 ) && ( hair[x].mtl == splines ) ) ) if( hair[x].restlength > 0 ) for( y = 0; y < 15; y++ ) { if( hair[x].noisev[y].x > BOUND1X ) BOUND1X = hair[x].noisev[y].x; if( hair[x].noisev[y].y > BOUND1Y ) BOUND1Y = hair[x].noisev[y].y; if( hair[x].noisev[y].z > BOUND1Z ) BOUND1Z = hair[x].noisev[y].z; if( hair[x].noisev[y].x < BOUNDX ) BOUNDX = hair[x].noisev[y].x; if( hair[x].noisev[y].y < BOUNDY ) BOUNDY = hair[x].noisev[y].y; if( hair[x].noisev[y].z < BOUNDZ ) BOUNDZ = hair[x].noisev[y].z; } if( total_splines > 0 ) for( x = 0; x < total_splines; x++ ) for( y = 0; y < 15; y++ ) { if( Sresthair[x].noisev[y].x > BOUND1X ) BOUND1X = Sresthair[x].noisev[y].x; if( Sresthair[x].noisev[y].y > BOUND1Y ) BOUND1Y = Sresthair[x].noisev[y].y; if( Sresthair[x].noisev[y].z > BOUND1Z ) BOUND1Z = Sresthair[x].noisev[y].z; if( Sresthair[x].noisev[y].x < BOUNDX ) BOUNDX = Sresthair[x].noisev[y].x; if( Sresthair[x].noisev[y].y < BOUNDY ) BOUNDY = Sresthair[x].noisev[y].y; if( Sresthair[x].noisev[y].z < BOUNDZ ) BOUNDZ = Sresthair[x].noisev[y].z; } { float big = 0; if( ( BOUND1X - BOUNDX ) > big ) big = BOUND1X - BOUNDX; if( ( BOUND1Y - BOUNDY ) > big ) big = BOUND1Y - BOUNDY; if( ( BOUND1Z - BOUNDZ ) > big ) big = BOUND1Z - BOUNDZ; } { float dx, dy, dz; dx = BOUND1X - BOUNDX; dy = BOUND1Y - BOUNDY; dz = BOUND1Z - BOUNDZ; // BOUNDLENGTH = fsqrt( dx * dx + dy * dy + dz * dz ); // restBOUNDLENGTH = BOUNDLENGTH; } } } refresh_OGL = 1; cam_panx = -( BOUND1X + BOUNDX ) / 2.0f; cam_pany = -( BOUND1Y + BOUNDY ) / 2.0f; cam_panz = -( BOUND1Z + BOUNDZ ) / 2.0f; { float dx, dy, dz; dx = BOUND1X - BOUNDX; dy = BOUND1Y - BOUNDY; dz = BOUND1Z - BOUNDZ; BOUNDLENGTH = sqrt( dx * dx + dy * dy + dz * dz ); // restBOUNDLENGTH=sqrt(dx*dx+dy*dy+dz*dz); } { float big = 0; cam_scale = -( 2.0 / BOUNDLENGTH ) * 1.25; } mkbounds( ); } static void gethair( CHNG name[500] ) /* load neutral model */ //char *name; { FILE *fp = NULL; int old_totalverts; char *stat; CHNG tmp[755]; int x, y, tf = 0; char statline[255]; int current_total = 0; testvar = 0; old_totalverts = totalverts; if( old_totalverts == 0 ) old_totalverts = -1; totalverts = 0; current_total = 0; totalfverts = 0; totalfaces = 0; totalgroups = 0; // sprintf( tmp, "%s", name ); /* printf ("name = %s\n",tmp); */ // sprintf (statline,"Loading %s.",name); // DRAW_STATUS(statline); #ifdef DOUNICODE fp = ( FILE * ) MYfopen( name, L"r" ); #else fp = ( FILE * ) MYfopen( name, "r" ); #endif if( fp ) { stat = MYfgets( tmp, 1255, fp ); // while (stat!=NULL) while( !feof( fp ) ) { // char *tmp2; if( ( tmp[0] == 'v' ) && ( tmp[1] != 'n' ) && ( tmp[1] != 't' ) ) /* it's a vertex */ { current_total++; } if( tmp[0] == 'f' ) { tf++; } stat = MYfgets( tmp, 1255, fp ); } MYfclose( fp ); } freeverts( ); //if (current_total!=old_totalverts) /////////// allocvert(current_total,tf); // sprintf( tmp, "%s", name ); // printf ("name = %s\n",tmp); // sprintf( statline, "Loading %s.", name ); // DRAW_STATUS( statline ); #ifdef DOUNICODE fp = ( FILE * ) MYfopen( tmp, L"r" ); #else fp = ( FILE * ) MYfopen( tmp, "r" ); #endif // for (x=0;x new group :", tmp9 ); DRAW_STATUS( statline ); } if( gpexist( tmp9 ) != -1 ) { current_group = gpexist( tmp9 ); } /* printf ("current group = %d\n",current_group); */ } } // if (current_total!=old_totalverts) if( tmp[0] == 'f' ) /* it's a face */ { /* stat=MYfgets(tmp,1255,fp); for SI objs */ tmp2 = strtok( tmp, WHT ); tmp2 = strtok( NULL, WHT ); /* not for SI */ face_start[totalfaces] = totalfverts; while( tmp2 != NULL ) { if( tmp2 != NULL ) { facelist[totalfverts] = atoi( tmp2 ); if( facelist[totalfverts] < 1 ) { facelist[totalfverts] = totalverts + facelist[totalfverts]; } if( facelist[totalfverts] > 0 ) { facelist[totalfverts]--; } } totalfverts++; /* this is for SI .objs */ tmp2 = strtok( NULL, WHT ); } /* totalfverts++; */ face_end[totalfaces] = totalfverts; /* assign vertex groups */ mtlgroup[totalfaces] = current_group; if( face_start[totalfaces] != face_end[totalfaces] ) for( x = face_start[totalfaces]; x < face_end[totalfaces]; x++ ) { int qqq; qqq = facelist[x]; vertgroup[qqq] = current_group; group_enable[vertgroup[facelist[face_start[totalfaces]]]] = 1; } // if (face_end[totalfaces]==face_start[totalfaces]) printf("0 vert face!\n"); if( face_end[totalfaces] != face_start[totalfaces] ) totalfaces++; } } /* printf ("totalverts = %d totalfaces = %d totalfverts = %d\n",totalverts,totalfaces,totalfverts); */ sprintf( statline, "totalverts = %d totalfaces = %d totalfverts = %d", totalverts, totalfaces, totalfverts ); DRAW_STATUS( statline ); MYfclose( fp ); } DRAW_STATUS( statline ); make_normals( ); { int q, fv, en; for( q = 0; q < totalfaces; q++ ) for( fv = face_start[q]; fv < face_end[q]; fv++ ) { int g; en = 1; g = facelist[fv]; { hair[g].restlength = distance( hair[g].hv[0], hair[g].hv[1] ); // hair[g].mtl=mtlgroup[q]; // hair[g].hv[0]=v[g]; } } for( q = 0; q < totalgroups; q++ ) group_stat[q] = 0; } reset_hair( ); center_select( ); for( x = 0; x < totalverts; x++ ) vnrest[x] = vn[x]; for( x = 0; x < totalverts; x++ ) for( y = 0; y < 15; y++ ) { hair[x].resthv[y] = hair[x].hv[y]; // back up hairverts } // reset_dynamics(); } static void texture_bounds( void ) { int x; //int y; for( x = 0; x < 5; x++ ) { colmap[x].bound1.x = 100000000; colmap[x].bound1.y = 100000000; colmap[x].bound1.z = 100000000; colmap[x].bound2.x = -100000000; colmap[x].bound2.y = -100000000; colmap[x].bound2.z = -100000000; lenmap[x].bound1.x = 100000000; lenmap[x].bound1.y = 100000000; lenmap[x].bound1.z = 100000000; lenmap[x].bound2.x = -100000000; lenmap[x].bound2.y = -100000000; lenmap[x].bound2.z = -100000000; densemap[x].bound1.x = 100000000; densemap[x].bound1.y = 100000000; densemap[x].bound1.z = 100000000; densemap[x].bound2.x = -100000000; densemap[x].bound2.y = -100000000; densemap[x].bound2.z = -100000000; } for( x = 0; x < totalverts; x++ ) { if( hair[x].mtl == head ) { if( densemap[0].bound1.x > hair[x].noisev[0].x ) densemap[0].bound1.x = hair[x].noisev[0].x; if( densemap[0].bound1.y > hair[x].noisev[0].y ) densemap[0].bound1.y = hair[x].noisev[0].y; if( densemap[0].bound1.z > hair[x].noisev[0].z ) densemap[0].bound1.z = hair[x].noisev[0].z; if( densemap[0].bound2.x < hair[x].noisev[0].x ) densemap[0].bound2.x = hair[x].noisev[0].x; if( densemap[0].bound2.y < hair[x].noisev[0].y ) densemap[0].bound2.y = hair[x].noisev[0].y; if( densemap[0].bound2.z < hair[x].noisev[0].z ) densemap[0].bound2.z = hair[x].noisev[0].z; } if( hair[x].mtl == beard ) { if( densemap[1].bound1.x > hair[x].noisev[0].x ) densemap[1].bound1.x = hair[x].noisev[0].x; if( densemap[1].bound1.y > hair[x].noisev[0].y ) densemap[1].bound1.y = hair[x].noisev[0].y; if( densemap[1].bound1.z > hair[x].noisev[0].z ) densemap[1].bound1.z = hair[x].noisev[0].z; if( densemap[1].bound2.x < hair[x].noisev[0].x ) densemap[1].bound2.x = hair[x].noisev[0].x; if( densemap[1].bound2.y < hair[x].noisev[0].y ) densemap[1].bound2.y = hair[x].noisev[0].y; if( densemap[1].bound2.z < hair[x].noisev[0].z ) densemap[1].bound2.z = hair[x].noisev[0].z; } if( hair[x].mtl == eyebrow ) { if( densemap[2].bound1.x > hair[x].noisev[0].x ) densemap[2].bound1.x = hair[x].noisev[0].x; if( densemap[2].bound1.y > hair[x].noisev[0].y ) densemap[2].bound1.y = hair[x].noisev[0].y; if( densemap[2].bound1.z > hair[x].noisev[0].z ) densemap[2].bound1.z = hair[x].noisev[0].z; if( densemap[2].bound2.x < hair[x].noisev[0].x ) densemap[2].bound2.x = hair[x].noisev[0].x; if( densemap[2].bound2.y < hair[x].noisev[0].y ) densemap[2].bound2.y = hair[x].noisev[0].y; if( densemap[2].bound2.z < hair[x].noisev[0].z ) densemap[2].bound2.z = hair[x].noisev[0].z; } if( hair[x].mtl == eyelash ) { if( densemap[3].bound1.x > hair[x].noisev[0].x ) densemap[3].bound1.x = hair[x].noisev[0].x; if( densemap[3].bound1.y > hair[x].noisev[0].y ) densemap[3].bound1.y = hair[x].noisev[0].y; if( densemap[3].bound1.z > hair[x].noisev[0].z ) densemap[3].bound1.z = hair[x].noisev[0].z; if( densemap[3].bound2.x < hair[x].noisev[0].x ) densemap[3].bound2.x = hair[x].noisev[0].x; if( densemap[3].bound2.y < hair[x].noisev[0].y ) densemap[3].bound2.y = hair[x].noisev[0].y; if( densemap[3].bound2.z < hair[x].noisev[0].z ) densemap[3].bound2.z = hair[x].noisev[0].z; } if( hair[x].mtl == splines ) { if( densemap[4].bound1.x > hair[x].noisev[0].x ) densemap[4].bound1.x = hair[x].noisev[0].x; if( densemap[4].bound1.y > hair[x].noisev[0].y ) densemap[4].bound1.y = hair[x].noisev[0].y; if( densemap[4].bound1.z > hair[x].noisev[0].z ) densemap[4].bound1.z = hair[x].noisev[0].z; if( densemap[4].bound2.x < hair[x].noisev[0].x ) densemap[4].bound2.x = hair[x].noisev[0].x; if( densemap[4].bound2.y < hair[x].noisev[0].y ) densemap[4].bound2.y = hair[x].noisev[0].y; if( densemap[4].bound2.z < hair[x].noisev[0].z ) densemap[4].bound2.z = hair[x].noisev[0].z; } } for( x = 0; x < 5; x++ ) { colmap[x].bound1 = densemap[x].bound1; colmap[x].bound2 = densemap[x].bound2; lenmap[x].bound1 = densemap[x].bound1; lenmap[x].bound2 = densemap[x].bound2; } } static void write_hair( void *fname ) { //char tmp[255]; //int tmpi; //float tmpf; void *fp = NULL; int x, y; int isit = 0; int tmpmetanurb; int shaveversion2 = 0; tmpmetanurb = GMetaNurb; if( GMetaNurb > 0 ) metaunfixchains( ); if( RW_CONTEXT != RW_DISK ) fname = ( MEMFILE * ) fname; if( RW_CONTEXT == RW_DISK ) fname = ( CHNG * ) fname; if( RW_CONTEXT == RW_DISK ) { reset_rest( ); printf( "Dtotalverts = %d\n", Dtotalverts ); printf( "total_splines = %d\n", total_splines ); } if( RW_CONTEXT == RW_DISK ) reset_noisespace( ); // for skulls f (totalverts>0) // if( totalverts > 0 ) if( Dtotalverts > 0 ) { #ifdef DOUNICODE fp = MYfopen( fname, L"wb" ); #else fp = MYfopen( fname, "wb" ); #endif } // for skulls if (totalverts>0) // if (slcheck()) // if( totalverts > 0 ) if( Dtotalverts > 0 ) { { char v1, v2, v3; v1 = 'z'; v2 = 'y'; #ifndef EXTERNAL_COLLISION v3 = 'v'; #endif #ifdef EXTERNAL_COLLISION v3 = 'v'; #endif shaveversion2 = v3; #ifdef onethree MYfwrite( &v1, 1, 1, fp ); MYfwrite( &v2, 1, 1, fp ); #endif //if (shaveversion2>='g') if( v2 == 'y' ) MYfwrite( &v3, 1, 1, fp ); { int qq; char dum = 0; #ifdef MAX3D // for (qq=0;qq<100;qq++) // MYfwrite (&dum,1,1,fp); #endif // if (RW_CONTEXT==RW_DISK) // if (MAXMODE==1) // { // for (qq=0;qq<100;qq++) // MYfwrite (&dum,1,1,fp); // } } MYfwrite( &Dtotalverts, 4, 1, fp ); MYfwrite( &Dtotalfaces, 4, 1, fp ); MYfwrite( &Dtotalfverts, 4, 1, fp ); // MYfwrite(&Dtotallines,4,1,fp); /// as of version k } if( shaveversion2 <= 'k' ) for( x = 0; x < Dtotalverts; x++ ) { int bb; MYfwrite( &Dvertgroup[x], 4, 1, fp ); // if( totalverts > 0 ) if( Dtag[x] == 1 ) { int bb; bb = Dlink[x]; MYfwrite( &hair[bb].splitgroup, 4, 1, fp ); MYfwrite( &hair[bb].splitmerge, 4, 1, fp ); } if( ( Dtag[x] != 1 ) || ( totalverts == 0 ) ) { int junki; junki = 0; MYfwrite( &junki, 4, 1, fp ); // splitgroup fake MYfwrite( &junki, 4, 1, fp ); // splitgroup fake } for( y = 0; y < 15; y++ ) { if( Dtag[x] ) { bb = Dlink[x]; // if (y>0) { MYfwrite( &hair[bb].resthv[y].x, 4, 1, fp ); MYfwrite( &hair[bb].resthv[y].y, 4, 1, fp ); MYfwrite( &hair[bb].resthv[y].z, 4, 1, fp ); } // if (y==0) // { // MYfwrite(&Dv[x].x,4,1,fp); // MYfwrite(&Dv[x].y,4,1,fp); // MYfwrite(&Dv[x].z,4,1,fp); // } #ifdef onethree MYfwrite( &hair[bb].pfID[y], 4, 1, fp ); #endif } // dtag if( ( Dtag[x] == 0 ) ) { int aa = -1; MYfwrite( &Drv[x].x, 4, 1, fp ); MYfwrite( &Drv[x].y, 4, 1, fp ); MYfwrite( &Drv[x].z, 4, 1, fp ); #ifdef onethree MYfwrite( &aa, 4, 1, fp ); #endif } } //y } //x if( shaveversion2 >= 'l' ) { // if( totalverts > 0 ) for( x = 0; x < Dtotalverts; x++ ) { int bb; MYfwrite( &Dvertgroup[x], 4, 1, fp ); MYfwrite( &Dtag[x], 4, 1, fp ); MYfwrite( &Dlink[x], 4, 1, fp ); MYfwrite( &Drv[x].x, 4, 1, fp ); MYfwrite( &Drv[x].y, 4, 1, fp ); MYfwrite( &Drv[x].z, 4, 1, fp ); if( Dtag[x] == 1 ) { int bb; bb = Dlink[x]; MYfwrite( &hair[bb].mtl, 4, 1, fp ); vertgroup[bb] = hair[bb].mtl; MYfwrite( &hair[bb].splitgroup, 4, 1, fp ); MYfwrite( &hair[bb].splitmerge, 4, 1, fp ); for( y = 0; y < 15; y++ ) { bb = Dlink[x]; { MYfwrite( &hair[bb].resthv[y].x, 4, 1, fp ); MYfwrite( &hair[bb].resthv[y].y, 4, 1, fp ); MYfwrite( &hair[bb].resthv[y].z, 4, 1, fp ); } MYfwrite( &hair[bb].pfID[y], 4, 1, fp ); } } } //x } for( x = 0; x < Dtotalfverts; x++ ) { MYfwrite( &Dfacelist[x], 4, 1, fp ); } for( x = 0; x < Dtotalfaces; x++ ) { MYfwrite( &Dmtlgroup[x], 4, 1, fp ); MYfwrite( &Dface_start[x], 4, 1, fp ); MYfwrite( &Dface_end[x], 4, 1, fp ); } for( y = 0; y < 5; y++ ) for( x = 0; x < 22; x++ ) { MYfwrite( &sliders[x][y].value, 4, 1, fp ); } { int junk; MYfwrite( &junk, 4, 1, fp ); // passes - OBSOLETE MYfwrite( &junk, 4, 1, fp ); // HAIRCOUNT - OBSOLETE } for( x = 0; x < 5; x++ ) { int l; l = strlen( colmap[x].name ); MYfwrite( &l, 4, 1, fp ); MYfwrite( &colmap[x].name, l, 1, fp ); MYfwrite( &colmap[x].flags, 4, 1, fp ); } for( x = 0; x < 5; x++ ) { int l; l = strlen( densemap[x].name ); MYfwrite( &l, 4, 1, fp ); MYfwrite( &densemap[x].name, l, 1, fp ); // if (isit) MYfwrite( &densemap[x].flags, 4, 1, fp ); } for( x = 0; x < 5; x++ ) { int l; l = strlen( lenmap[x].name ); MYfwrite( &l, 4, 1, fp ); MYfwrite( &lenmap[x].name, l, 1, fp ); // if (isit) MYfwrite( &lenmap[x].flags, 4, 1, fp ); } MYfwrite( &totalgroups, 4, 1, fp ); { // FILE *dgg; // dgg=MYfopen("surfnames.txt","w"); for( x = 0; x < totalgroups; x++ ) { int l; int xx; l = strlen( group_names[x] ); // fprintf (dgg,"%d %d %s\n",x,l,group_names[x]); MYfwrite( &l, 4, 1, fp ); for( xx = 0; xx < l; xx++ ) MYfwrite( &group_names[x][xx], 1, 1, fp ); } // MYfclose(dgg); } //#ifdef thisit mkbounds( ); weight_polys( ); texture_bounds( ); //#endif // fp=MYfopen(fname,"wb"); MYfwrite( &freeze.totalverts, 4, 1, fp ); MYfwrite( &freeze.totalfaces, 4, 1, fp ); MYfwrite( &freeze.totalfverts, 4, 1, fp ); if( freeze.totalverts > 0 ) { for( x = 0; x < freeze.totalverts; x++ ) { // int r,g,b; // int flag; MYfwrite( &freeze.v[x].x, 4, 1, fp ); MYfwrite( &freeze.v[x].y, 4, 1, fp ); MYfwrite( &freeze.v[x].z, 4, 1, fp ); MYfwrite( &freeze.Rrvcolor[x], 4, 1, fp ); MYfwrite( &freeze.Rgvcolor[x], 4, 1, fp ); MYfwrite( &freeze.Rbvcolor[x], 4, 1, fp ); } for( x = 0; x < freeze.totalfverts; x++ ) { MYfwrite( &freeze.facelist[x], 4, 1, fp ); } for( x = 0; x < freeze.totalfaces; x++ ) { int cll; MYfwrite( &freeze.mtlgroup[x], 4, 1, fp ); MYfwrite( &freeze.face_start[x], 4, 1, fp ); MYfwrite( &freeze.face_end[x], 4, 1, fp ); cll = 0; if( freeze.colorlock[x] >= 0 ) cll = 1; MYfwrite( &cll, 4, 1, fp ); } MYfwrite( &freeze.textoggle, 4, 1, fp ); } for( y = 0; y < 5; y++ ) for( x = 22; x < 24; x++ ) // wiggles { MYfwrite( &sliders[x][y].value, 4, 1, fp ); } { int ti; int total_sliders = 30; MYfwrite( &total_sliders, 4, 1, fp ); // total sliders for( x = 0; x < total_sliders; x++ ) { // ti = sliders[x][0].paint; ti=1; MYfwrite( &ti, 4, 1, fp ); // empty/full ? if( ti > 0 ) for( y = 0; y < totalverts; y++ ) { MYfwrite( &hair[y].slider[x], 4, 1, fp ); // slider contents } } } for( y = 0; y < 5; y++ ) for( x = 0; x < 30; x++ ) { MYfwrite( &sliders[x][y].value, 4, 1, fp ); } for( y = 0; y < 5; y++ ) { MYfwrite( &LOCAL_PASSES[y], 4, 1, fp ); MYfwrite( &LOCAL_CNT[y], 4, 1, fp ); } // version j for( x = 0; x < total_splines; x++ ) for( y = 0; y < 15; y++ ) MYfwrite( &Shair[x].pfID[y], 4, 1, fp ); for( x = 0; x < total_splines; x++ ) { MYfwrite( &Shair[x].splitgroup, 4, 1, fp ); MYfwrite( &Shair[x].splitmerge, 4, 1, fp ); } for( y = 0; y < 5; y++ ) // make a nice clean write of all the sliders for( x = 0; x < 30; x++ ) { // float junkf; MYfwrite( &sliders[x][y].value, 4, 1, fp ); } // gravity MYfwrite( &sliders[0][5].value, 4, 1, fp ); //if (v2=='l') if( 0 == 1 ) /// this was only in version l !! if( RW_CONTEXT != RW_DISK ) { // state machine int bb; for( bb = 0; bb < totalverts; bb++ ) for( y = 0; y < 15; y++ ) { MYfwrite( &hair[bb].resthv[y].x, 4, 1, fp ); MYfwrite( &hair[bb].resthv[y].y, 4, 1, fp ); MYfwrite( &hair[bb].resthv[y].z, 4, 1, fp ); MYfwrite( &hair[bb].hv[y].x, 4, 1, fp ); MYfwrite( &hair[bb].hv[y].y, 4, 1, fp ); MYfwrite( &hair[bb].hv[y].z, 4, 1, fp ); MYfwrite( &hair[bb].lasthv[y].x, 4, 1, fp ); MYfwrite( &hair[bb].lasthv[y].y, 4, 1, fp ); MYfwrite( &hair[bb].lasthv[y].z, 4, 1, fp ); MYfwrite( &hair[bb].velocity[y].x, 4, 1, fp ); MYfwrite( &hair[bb].velocity[y].y, 4, 1, fp ); MYfwrite( &hair[bb].velocity[y].z, 4, 1, fp ); } for( bb = 0; bb < total_splines; bb++ ) for( y = 0; y < 15; y++ ) { MYfwrite( &Shair[bb].hv[y].x, 4, 1, fp ); MYfwrite( &Shair[bb].hv[y].y, 4, 1, fp ); MYfwrite( &Shair[bb].hv[y].z, 4, 1, fp ); MYfwrite( &Sthishair[bb].hv[y].x, 4, 1, fp ); MYfwrite( &Sthishair[bb].hv[y].y, 4, 1, fp ); MYfwrite( &Sthishair[bb].hv[y].z, 4, 1, fp ); MYfwrite( &Sresthair[bb].hv[y].x, 4, 1, fp ); MYfwrite( &Sresthair[bb].hv[y].y, 4, 1, fp ); MYfwrite( &Sresthair[bb].hv[y].z, 4, 1, fp ); MYfwrite( &Slasthair[bb].hv[y].x, 4, 1, fp ); MYfwrite( &Slasthair[bb].hv[y].y, 4, 1, fp ); MYfwrite( &Slasthair[bb].hv[y].z, 4, 1, fp ); MYfwrite( &Shairvelocity[bb].hv[y].x, 4, 1, fp ); MYfwrite( &Shairvelocity[bb].hv[y].y, 4, 1, fp ); MYfwrite( &Shairvelocity[bb].hv[y].z, 4, 1, fp ); } } // version m for( x = 0; x < Dtotalverts; x++ ) { int junki = 1; MYfwrite( &junki, 4, 1, fp ); // MYfwrite(&D2UTface_link[x],4,1,fp); } // version n // MYfwrite(&GMetaNurb,4,1,fp); MYfwrite( &DUTtotalfaces, 4, 1, fp ); MYfwrite( &DUTtotalfverts, 4, 1, fp ); for( x = 0; x < DUTtotalfverts; x++ ) { MYfwrite( &DUTfacelist[x], 4, 1, fp ); } for( x = 0; x < DUTtotalfaces; x++ ) { MYfwrite( &DUTface_start[x], 4, 1, fp ); MYfwrite( &DUTface_end[x], 4, 1, fp ); } // version O // if( totalverts > 0 ) for( x = 0; x < totalverts; x++ ) { for( y = 0; y < 15; y++ ) MYfwrite( &hair[x].select[y], 4, 1, fp ); } if( 0 == 1 ) if( Stotalverts > 0 ) for( x = 0; x < Stotalverts; x++ ) { for( y = 0; y < 15; y++ ) MYfwrite( &Shair[x].select[y], 4, 1, fp ); } // version P for( y = 0; y < 5; y++ ) // we've got some new sliders here for( x = 30; x < 40; x++ ) { // float junkf; MYfwrite( &sliders[x][y].value, 4, 1, fp ); } { int ti; int total_sliders = 40; MYfwrite( &total_sliders, 4, 1, fp ); // total sliders for( x = 30; x < total_sliders; x++ ) { // ti = sliders[x][0].paint; ti=1; MYfwrite( &ti, 4, 1, fp ); // empty/full ? if( ti > 0 ) for( y = 0; y < totalverts; y++ ) { MYfwrite( &hair[y].slider[x], 4, 1, fp ); // slider contents } } } // version q for( y = 0; y < 5; y++ ) // we've got some new sliders here { // float junkf; MYfwrite( &Ganim_dir[y].x, 4, 1, fp ); MYfwrite( &Ganim_dir[y].y, 4, 1, fp ); MYfwrite( &Ganim_dir[y].z, 4, 1, fp ); } // version r for( y = 0; y < totalfaces; y++ ) // we've got some new sliders here { MYfwrite( &face_link[y], 4, 1, fp ); } for( x = 0; x < Dtotalfaces; x++ ) { MYfwrite( &D2UTface_link[x], 4, 1, fp ); } // version s for( y = 0; y < 5; y++ ) // we've got some new sliders here { MYfwrite( &Gsurface_collide[y], 4, 1, fp ); } // version t // for (y=0;y<5;y++) // we've got some new sliders here { MYfwrite( &COLLISION_METHOD, 4, 1, fp ); } // version u if( total_splines > 0 ) for( x = 0; x < total_splines; x++ ) { for( y = 0; y < 15; y++ ) MYfwrite( &Shair[x].select[y], 4, 1, fp ); } // version v for( y = 0; y < 5; y++ ) { MYfwrite( &LOCAL_SEGS[y], 4, 1, fp ); } //if (shaveversion>='x') { int xx; for( xx = 0; xx < totalverts; xx++ ) { MYfwrite( &hair[xx].uu, 4, 1, fp ); MYfwrite( &hair[xx].vv, 4, 1, fp ); } for( xx = 0; xx < total_splines; xx++ ) { MYfwrite( &Sresthair[xx].uu, 4, 1, fp ); MYfwrite( &Sresthair[xx].vv, 4, 1, fp ); } } //if (shaveversion2>='a') { int xx, y; for( xx = 0; xx < totalverts; xx++ ) for( y = 0; y < 15; y++ ) { MYfwrite( &hair[xx].noisev[y].x, 4, 1, fp ); MYfwrite( &hair[xx].noisev[y].y, 4, 1, fp ); MYfwrite( &hair[xx].noisev[y].z, 4, 1, fp ); } for( xx = 0; xx < total_splines; xx++ ) for( y = 0; y < 15; y++ ) { MYfwrite( &Sresthair[xx].noisev[y].x, 4, 1, fp ); MYfwrite( &Sresthair[xx].noisev[y].y, 4, 1, fp ); MYfwrite( &Sresthair[xx].noisev[y].z, 4, 1, fp ); } } //if (shaveversion2>='e') { for( y = 0; y < 5; y++ ) for( x = 40; x < 41; x++ ) { MYfwrite( &sliders[x][y].value, 4, 1, fp ); } } //if (shaveversion2>='f') { for( y = 0; y < 5; y++ ) for( x = 41; x < 45; x++ ) { MYfwrite( &sliders[x][y].value, 4, 1, fp ); } } //if (shaveversion3>='h') // MYfwrite(&Gbacklighting,4,1,fp); for( y = 0; y < 5; y++ ) { MYfwrite( &LOCAL_SHADCNT[y], 4, 1, fp ); } //if (shaveversion3>='i') { MYfwrite( &Guv_totalsets, 4, 1, fp ); for( x = 0; x < Guv_totalsets; x++ ) { MYfwrite( &Guv_sets[x].totalverts, 4, 1, fp ); MYfwrite( &Guv_sets[x].totalfverts, 4, 1, fp ); MYfwrite( &Guv_sets[x].totalfaces, 4, 1, fp ); for( y = 0; y < Guv_sets[x].totalverts; y++ ) { MYfwrite( &Guv_sets[x].v[y].x, 4, 1, fp ); MYfwrite( &Guv_sets[x].v[y].y, 4, 1, fp ); MYfwrite( &Guv_sets[x].v[y].z, 4, 1, fp ); } for( y = 0; y < Guv_sets[x].totalfverts; y++ ) MYfwrite( &Guv_sets[x].facelist[y], 4, 1, fp ); for( y = 0; y < Guv_sets[x].totalfaces; y++ ) { MYfwrite( &Guv_sets[x].face_start[y], 4, 1, fp ); MYfwrite( &Guv_sets[x].face_end[y], 4, 1, fp ); } } } //if (shaveversion3>='j') for( x = 0; x < 45; x++ ) MYfwrite( &x, 4, 1, fp ); //if (shaveversion3>='k') { int xx, y; for( xx = 0; xx < totalverts; xx++ ) MYfwrite( &hair[xx].restlength, 4, 1, fp ); for( xx = 0; xx < total_splines; xx++ ) { MYfwrite( &Sresthair[xx].restlength, 4, 1, fp ); } } //if (shaveversion3>='m') { int vers = 0; vers = 1; // softimage #ifdef MAYA3D vers = 2; #endif #ifdef MAX3D vers = 3; #endif #ifdef C4D vers = 4; #endif MYfwrite( &vers, 4, 1, fp ); } // if( shaveversion2 >= 'p' ) { int qq; for( qq = 0; qq < totalverts; qq++ ) { int hide; hide = hair[qq].hide; MYfwrite( &hide, 4, 1, fp ); } for( qq = 0; qq < total_splines; qq++ ) { int hide; hide = Shair[qq].hide; MYfwrite( &hide, 4, 1, fp ); } } // if( shaveversion2 >= 'q' ) { MYfwrite( &Gspec_tint.x, 4, 1, fp ); MYfwrite( &Gspec_tint.y, 4, 1, fp ); MYfwrite( &Gspec_tint.z, 4, 1, fp ); } //if (shaveversion2>= 'r') if (totalverts>0) { int qq; MYfwrite( &Gtotal_splinelocks, 4, 1, fp ); if (Gtotal_splinelocks>0) for( qq = 0; qq < totalverts; qq++ ) { int id; float w; id = hair[qq].Bid1; MYfwrite( &id, 4, 1, fp ); id = hair[qq].Bid2; MYfwrite( &id, 4, 1, fp ); id = hair[qq].Bid3; MYfwrite( &id, 4, 1, fp ); w = hair[qq].bw1; MYfwrite( &w, 4, 1, fp ); w = hair[qq].bw2; MYfwrite( &w, 4, 1, fp ); w = hair[qq].bw3; MYfwrite( &w, 4, 1, fp ); } } //if (shaveversion2>= 's') { int qq; // MYfwrite( &Gsquirrel, 4, 1, fp ); for( y = 0; y < 5; y++ ) for( x = 45; x < 50; x++ ) { MYfwrite( &sliders[x][y].value, 4, 1, fp ); } for( x = 0; x < 50; x++ ) MYfwrite( &Guv_link[x], 4, 1, fp ); } //if (shaveversion2>= 't') { int qq; // MYfwrite( &Gsquirrel, 4, 1, fp ); for( y = 0; y < 5; y++ ) for( x = 50; x < 60; x++ ) { MYfwrite( &sliders[x][y].value, 4, 1, fp ); } for( x = 50; x < 60; x++ ) MYfwrite( &Guv_link[x], 4, 1, fp ); } if (shaveversion2>= 'v') // 6.0 adds 10 channels { int ii; ii=(int)SHAVEID; MYfwrite( &ii, 4, 1, fp ); } if (shaveversion2>= 'v') // 6.0 adds 10 channels { MYfwrite( &Gspec_tint2.x, 4, 1, fp ); MYfwrite( &Gspec_tint2.y, 4, 1, fp ); MYfwrite( &Gspec_tint2.z, 4, 1, fp ); } if( Dtotalverts > 0 ) MYfclose( fp ); } if( Dtotalverts == 0 ) DRAW_STATUS( "Didn't save, workspace is EMPTY!" ); GMetaNurb = tmpmetanurb; if( tmpmetanurb > 0 ) metanurb( tmpmetanurb ); collect_guides( ); } static void write_state( CHNG *fname ) { //char tmp[255]; //int tmpi; //float tmpf; FILE *fp = NULL; int x, y; int fversion = 0; #ifdef DOUNICODE fp = MYfopen( fname, L"wb" ); #else fp = MYfopen( fname, "wb" ); #endif if( fp != NULL ) { MYfwrite( &fversion, 4, 1, fp ); MYfwrite( &fversion, 4, 1, fp ); // we're going to output it twice to make sure there's no mistake MYfwrite( &totalverts, 4, 1, fp ); MYfwrite( &totalfaces, 4, 1, fp ); MYfwrite( &totalfverts, 4, 1, fp ); MYfwrite( &total_splines, 4, 1, fp ); for( x = 0; x < totalverts; x++ ) if( hair[x].restlength > 0.0f ) if( hair[x].mtl == head ) { MYfwrite( &hair[x].mtl, 4, 1, fp ); for( y = 0; y < 15; y++ ) { MYfwrite( &hair[x].hv[y].x, 4, 1, fp ); MYfwrite( &hair[x].hv[y].y, 4, 1, fp ); MYfwrite( &hair[x].hv[y].z, 4, 1, fp ); // MYfwrite(&hairvelocity[x].hv[y].x,4,1,fp); // MYfwrite(&hairvelocity[x].hv[y].y,4,1,fp); // MYfwrite(&hairvelocity[x].hv[y].z,4,1,fp); MYfwrite( &hair[x].lasthv[y].x, 4, 1, fp ); MYfwrite( &hair[x].lasthv[y].y, 4, 1, fp ); MYfwrite( &hair[x].lasthv[y].z, 4, 1, fp ); } } for( x = 0; x < total_splines; x++ ) if( Shair[x].restlength > 0 ) { MYfwrite( &Shair[x].mtl, 4, 1, fp ); for( y = 0; y < 15; y++ ) { MYfwrite( &Shair[x].hv[y].x, 4, 1, fp ); MYfwrite( &Shair[x].hv[y].y, 4, 1, fp ); MYfwrite( &Shair[x].hv[y].z, 4, 1, fp ); // MYfwrite(&hairvelocity[x].hv[y].x,4,1,fp); // MYfwrite(&hairvelocity[x].hv[y].y,4,1,fp); // MYfwrite(&hairvelocity[x].hv[y].z,4,1,fp); MYfwrite( &Slasthair[x].hv[y].x, 4, 1, fp ); MYfwrite( &Slasthair[x].hv[y].y, 4, 1, fp ); MYfwrite( &Slasthair[x].hv[y].z, 4, 1, fp ); } } MYfwrite( &totalgroups, 4, 1, fp ); fclose( fp ); } else printf( "couldn't write out statfile %s\n", fname ); } static void fish_hair( void *fp ) { //char tmp[255]; //int tmpi; //float tmpf; int x, y; char shaveversion2 = 0; int huh = 0; if( RW_CONTEXT == RW_DISK ) { fp = ( FILE * ) fp; } else { fp = ( MEMFILE * ) fp; } //dg=MYfopen("zzz.txt","w"); if( fp ) { //if (Dtotalverts>0) Dfreeverts( ); if( ( shaveversion >= 'a' ) ) { char junkc; MYfread( &junkc, 1, 1, fp ); // version 'z' MYfread( &junkc, 1, 1, fp ); // version 'a' if( junkc >= 'y' ) MYfread( &junkc, 1, 1, fp ); // version2 'a' if( junkc >= 'g' ) { int qq; char dum; #ifdef MAX3D // for (qq=0;qq<100;qq++) // MYfread (&dum,1,1,fp); #endif } shaveversion2 = junkc; } MYfread( &Dtotalverts, 4, 1, fp ); MYfread( &Dtotalfaces, 4, 1, fp ); MYfread( &Dtotalfverts, 4, 1, fp ); if( shaveversion <= 'm' ) DUTtotalfverts = Dtotalfverts; if( shaveversion <= 'm' ) DUTtotalfaces = Dtotalfaces; //if (shaveversion>='k'); // MYfread(&Dtotallines,4,1,fp); Dallocvert( ); if( shaveversion2 >= 'l' ) { // if (totalverts>0) for( x = 0; x < Dtotalverts; x++ ) { int bb; MYfread( &Dvertgroup[x], 4, 1, fp ); MYfread( &Dtag[x], 4, 1, fp ); MYfread( &Dlink[x], 4, 1, fp ); MYfread( &Drv[x].x, 4, 1, fp ); MYfread( &Drv[x].y, 4, 1, fp ); MYfread( &Drv[x].z, 4, 1, fp ); Dv[x] = Drv[x]; if( Dtag[x] == 1 ) { int bb; int junki; bb = Dlink[x]; MYfread( &junki, 4, 1, fp ); MYfread( &junki, 4, 1, fp ); MYfread( &junki, 4, 1, fp ); for( y = 0; y < 15; y++ ) { float junkf; bb = Dlink[x]; MYfread( &junkf, 4, 1, fp ); MYfread( &junkf, 4, 1, fp ); MYfread( &junkf, 4, 1, fp ); MYfread( &junkf, 4, 1, fp ); } } } //x } if( shaveversion2 < 'l' ) for( x = 0; x < Dtotalverts; x++ ) { MYfread( &Dvertgroup[x], 4, 1, fp ); if( shaveversion >= 'd' ) { // int bb; { int junki; MYfread( &junki, 4, 1, fp ); // splitgroup MYfread( &junki, 4, 1, fp ); // merge flag } } for( y = 0; y < 15; y++ ) { float junk; int aa; if( y == 0 ) { MYfread( &Dv[x].x, 4, 1, fp ); MYfread( &Dv[x].y, 4, 1, fp ); MYfread( &Dv[x].z, 4, 1, fp ); Drv[x] = Dv[x]; if( shaveversion >= 'a' ) MYfread( &aa, 4, 1, fp ); } else { MYfread( &junk, 4, 1, fp ); MYfread( &junk, 4, 1, fp ); MYfread( &junk, 4, 1, fp ); if( shaveversion >= 'a' ) MYfread( &aa, 4, 1, fp ); } // if (dg) fprintf(dg," %f %f %f",hair[x].hv[y].x, // hair[x].hv[y].y, // hair[x].hv[y].z); } } //printf ("got verts"); for( x = 0; x < Dtotalfverts; x++ ) { MYfread( &Dfacelist[x], 4, 1, fp ); if( shaveversion <= 'm' ) DUTfacelist[x] = Dfacelist[x]; // if (dg) fprintf (dg,"%d\n",facelist[x]); } for( x = 0; x < Dtotalfaces; x++ ) { int tmpi; // char tmps[255]; MYfread( &tmpi, 4, 1, fp ); // sprintf (tmps,"Dmtlgroup[%d]= %d \n",x,tmpi); // DRAW_STATUS(tmps); if (tmpi>6) tmpi=6; Dmtlgroup[x] = tmpi; if( Dmtlgroup[x] + 1 > totalgroups ) totalgroups = Dmtlgroup[x] + 1; group_enable[Dmtlgroup[x]] = 1; group_stat[Dmtlgroup[x]] = 1; MYfread( &Dface_start[x], 4, 1, fp ); MYfread( &Dface_end[x], 4, 1, fp ); if( shaveversion <= 'm' ) DUTface_start[x] = Dface_start[x]; if( shaveversion <= 'm' ) DUTface_end[x] = Dface_start[x]; } for( y = 0; y < 5; y++ ) for( x = 0; x < 22; x++ ) { float junkf; // if (y!=4) // why would I only be interested in splines here? MYfread( &sliders[x][y].value, 4, 1, fp ); // if (y==4) // MYfread(&junkf,4,1,fp); } gravity = sliders[0][5].value; { int junk; MYfread( &junk, 4, 1, fp ); // PASSES - obsolete MYfread( &junk, 4, 1, fp ); // haircount - obsolete } //// if (PASSES>6) PASSES=6; // PASSES=4; for( x = 0; x < 5; x++ ) { int l; int junki; char junks[255]; MYfread( &l, 4, 1, fp ); MYfread( &junks, l, 1, fp ); MYfread( &junki, 4, 1, fp ); } for( x = 0; x < 5; x++ ) { int l; int junki; char junks[255]; MYfread( &l, 4, 1, fp ); MYfread( &junks, l, 1, fp ); MYfread( &junki, 4, 1, fp ); } if( shaveversion >= 'c' ) for( x = 0; x < 5; x++ ) { int l; int junki; char junks[255]; MYfread( &l, 4, 1, fp ); MYfread( &junks, l, 1, fp ); MYfread( &junki, 4, 1, fp ); } { // FILE *dgg; // int ji; // dgg=MYfopen("fishgroups.txt","w"); MYfread( &totalgroups, 4, 1, fp ); // totalgroups // fprintf (dgg,"totalgroups %d\n",totalgroups); for( x = 0; x < totalgroups; x++ ) { int l; int xx; MYfread( &l, 4, 1, fp ); for( xx = 0; xx < l; xx++ ) MYfread( &group_names[x][xx], 1, 1, fp ); // fprintf (dgg,"%d %d %s\n",x,l,group_names[x]); } // MYfclose(dgg); } } if( totalgroups > 0 ) if( shaveversion2 < 'n' ) reorg( ); else reorg2( ); MYfclose( fp ); // if (!chksl()) Dtotalverts=0; //if (dg) MYfclose(dg); //clean_hair(); } static void free_freeze( void ); static void read_animated_targa( char filename[255], TGABUFF * tbuff ); static void read_hair( void *fname ) { //char tmp[255]; //int tmpi; //float tmpf; void *fp; int x, y; int huh = 0; int xx = 0; int BADFILE = 0; char shaveversion2; int do34 = 0; Gtotal_splinelocks=0; GnodeID=0; free_clumping(); totalskulls = 0; totalsplits = 1; DEGENERATE_OBJECT = 0; if( total_splines > 0 ) free_splines( ); // SNfree( ); Dfreeverts( ); freeverts( ); free_maps( ); set_defaults( ); clear_uvsets( ); if( RW_CONTEXT == RW_DISK ) { fname = ( CHNG * ) fname; // TEXCACHEMODE = 0; } shaveversion2 = 'a'; ///if (freeze.totalverts>0) free_freeze( ); /////if (totalverts>0) { freeverts( ); Dfreeverts( ); } { // check for version #ifdef DOUNICODE fp = MYfopen( fname, L"rb" ); #else fp = MYfopen( fname, "rb" ); #endif } //if (fp) if( fp ) { MYfread( &shaveversion, 1, 1, fp ); if( shaveversion != 'z' ) BADFILE = 1; MYfread( &shaveversion, 1, 1, fp ); if( shaveversion == 'y' ) #ifndef EXTERNAL_COLLISION MYfread( &shaveversion2, 1, 1, fp ); // if( shaveversion2 > 'v' ) // BADFILE = 1; #endif #ifdef EXTERNAL_COLLISION MYfread( &shaveversion2, 1, 1, fp ); // if( shaveversion2 > 'v' ) // BADFILE = 1; #endif MYfclose( fp ); } // do34=0; //if (shaveversion2<'m') do34=1; //if (do34==1) //{ //read_hair34(fname); //return; //} // if (do34==0) if( BADFILE == 0 ) { // while (1==1) { } #ifdef LIB //if (slcheck()) // fp=MYfopen(fname,"rb"); #ifdef DOUNICODE fp = MYfopen( fname, L"rb" ); #else fp = MYfopen( fname, "rb" ); #endif free_maps( ); #endif if( fp ) // if (shaveversion2<='m') fish_hair( fp ); // else // fish_hair2( fp ); #ifdef LIB //if (slcheck()) // fp=MYfopen(fname,"rb"); #ifdef DOUNICODE fp = ( FILE * ) MYfopen( fname, L"rb" ); #else fp = ( FILE * ) MYfopen( fname, "rb" ); #endif free_maps( ); #endif ///dg=MYfopen("zzz.txt","w"); if( fp ) { int junki; float junkf; //// char junkc; // totalsplits = 1; if( ( shaveversion >= 'a' ) ) { char junkc; MYfread( &junkc, 1, 1, fp ); MYfread( &junkc, 1, 1, fp ); if( junkc >= 'y' ) MYfread( &junkc, 1, 1, fp ); if( junkc >= 'g' ) { int qq; char dum; #ifdef MAX3D // for (qq=0;qq<100;qq++) // MYfread (&dum,1,1,fp); #endif } } MYfread( &junki, 4, 1, fp ); MYfread( &junki, 4, 1, fp ); MYfread( &junki, 4, 1, fp ); //if (shaveversion>='k'); // MYfread(&junki,4,1,fp); // totallines // printf("totalverts %d\n",totalverts); if( shaveversion2 >= 'l' ) { // if( totalverts > 0 ) for( x = 0; x < Dtotalverts; x++ ) { int bb; MYfread( &Dvertgroup[x], 4, 1, fp ); MYfread( &Dtag[x], 4, 1, fp ); MYfread( &Dlink[x], 4, 1, fp ); MYfread( &Drv[x].x, 4, 1, fp ); MYfread( &Drv[x].y, 4, 1, fp ); MYfread( &Drv[x].z, 4, 1, fp ); Dv[x] = Drv[x]; if( totalverts > 0 ) if( Dtag[x] == 1 ) { int bb; bb = Dlink[x]; MYfread( &hair[bb].mtl, 4, 1, fp ); vertgroup[bb] = hair[bb].mtl; hair[bb].slgroup = vertgroup[bb]; MYfread( &hair[bb].splitgroup, 4, 1, fp ); MYfread( &hair[bb].splitmerge, 4, 1, fp ); if( ( hair[bb].splitgroup + 1 ) > totalsplits ) totalsplits = hair[bb].splitgroup + 1; for( y = 0; y < 15; y++ ) { bb = Dlink[x]; { MYfread( &hair[bb].resthv[y].x, 4, 1, fp ); MYfread( &hair[bb].resthv[y].y, 4, 1, fp ); MYfread( &hair[bb].resthv[y].z, 4, 1, fp ); } hair[bb].noisev[y] = hair[bb].resthv[y]; hair[bb].hv[y] = hair[bb].resthv[y]; MYfread( &hair[bb].pfID[y], 4, 1, fp ); } // v[bb] = hair[bb].resthv[0]; v[bb] = Drv[x]; neutral[Dlink[x]] = v[Dlink[x]]; } if( totalverts == 0 ) // this should be impossible if( Dtag[x] == 1 ) { int bb; MYfread( &bb, 4, 1, fp ); MYfread( &bb, 4, 1, fp ); MYfread( &bb, 4, 1, fp ); for( y = 0; y < 15; y++ ) { { MYfread( &bb, 4, 1, fp ); MYfread( &bb, 4, 1, fp ); MYfread( &bb, 4, 1, fp ); } MYfread( &bb, 4, 1, fp ); } } } //x } if( shaveversion2 <= 'k' ) for( x = 0; x < Dtotalverts; x++ ) { if( Dtag[x] ) { int bb; bb = Dlink[x]; MYfread( &hair[bb].mtl, 4, 1, fp ); vertgroup[bb] = hair[bb].mtl; hair[bb].slgroup = vertgroup[bb]; if( shaveversion >= 'd' ) { MYfread( &hair[bb].splitgroup, 4, 1, fp ); MYfread( &hair[bb].splitmerge, 4, 1, fp ); if( ( hair[bb].splitgroup + 1 ) > totalsplits ) totalsplits = hair[bb].splitgroup + 1; } for( y = 0; y < 15; y++ ) { MYfread( &hair[bb].resthv[y].x, 4, 1, fp ); MYfread( &hair[bb].resthv[y].y, 4, 1, fp ); MYfread( &hair[bb].resthv[y].z, 4, 1, fp ); if( shaveversion >= 'a' ) MYfread( &hair[bb].pfID[y], 4, 1, fp ); hair[bb].noisev[y] = hair[bb].resthv[y]; hair[bb].hv[y] = hair[bb].resthv[y]; } if( shaveversion < 'd' ) { totalsplits = 1; hair[bb].splitmerge = 0; hair[bb].splitgroup = 0; } } else { MYfread( &junki, 4, 1, fp ); for( y = 0; y < 15; y++ ) { MYfread( &junkf, 4, 1, fp ); MYfread( &junkf, 4, 1, fp ); MYfread( &junkf, 4, 1, fp ); if( shaveversion >= 'a' ) MYfread( &junkf, 4, 1, fp ); } if( shaveversion >= 'd' ) { MYfread( &junki, 4, 1, fp ); // splitgroup MYfread( &junki, 4, 1, fp ); // splitmerge } } if( Dtag[x] ) neutral[Dlink[x]] = v[Dlink[x]]; } //x for( x = 0; x < Dtotalfverts; x++ ) { MYfread( &junki, 4, 1, fp ); } for( x = 0; x < Dtotalfaces; x++ ) { MYfread( &junki, 4, 1, fp ); MYfread( &junki, 4, 1, fp ); MYfread( &junki, 4, 1, fp ); } for( y = 0; y < 5; y++ ) for( x = 0; x < 22; x++ ) { float junkf; // if (y!=4) MYfread( &sliders[x][y].value, 4, 1, fp ); // if (y==4) // why am I not interested in splines here? // MYfread(&junkf,4,1,fp); } gravity = sliders[0][5].value; { int P; int haircount; MYfread( &P, 4, 1, fp ); MYfread( &haircount, 4, 1, fp ); // for (x=0;x<4;x++) LOCAL_PASSES[x]=P; // for (x=0;x<4;x++) LOCAL_CNT[x]=haircount/4; } //// if (PASSES>6) PASSES=6; //PASSES=4; for( x = 0; x < 5; x++ ) { int l; MYfread( &l, 4, 1, fp ); MYfread( &colmap[x].name, l, 1, fp ); MYfread( &colmap[x].flags, 4, 1, fp ); if( Gmaps_active == 1 ) if( strlen( colmap[x].name ) ) { char tmpn[255]; // colmap[x].name[l]=NULL; sprintf( tmpn, "%s", colmap[x].name ); read_animated_targa( tmpn, &colmap[x] ); } } for( x = 0; x < 5; x++ ) { int l; MYfread( &l, 4, 1, fp ); MYfread( &densemap[x].name, l, 1, fp ); MYfread( &densemap[x].flags, 4, 1, fp ); if( Gmaps_active == 1 ) if( strlen( densemap[x].name ) ) read_animated_targa( densemap[x].name, &densemap[x] ); } if( shaveversion >= 'c' ) for( x = 0; x < 5; x++ ) { int l; MYfread( &l, 4, 1, fp ); MYfread( &lenmap[x].name, l, 1, fp ); MYfread( &lenmap[x].flags, 4, 1, fp ); if( Gmaps_active == 1 ) if( strlen( lenmap[x].name ) ) read_animated_targa( lenmap[x].name, &lenmap[x] ); } MYfread( &totalgroups, 4, 1, fp ); { // FILE *dgg; // dgg=MYfopen("groups.txt","w"); // fprintf (dgg,"totalgroups %d\n",totalgroups); for( x = 0; x < totalgroups; x++ ) { int l; int xx; // int yy; MYfread( &l, 4, 1, fp ); // fprintf (dgg,"namelen = %d\n",l); for( xx = 0; xx < l; xx++ ) MYfread( &group_names[x][xx], 1, 1, fp ); group_names[x][l] = 0; // for (yy=0;yy= 'e' ) { //if (freeze.totalverts>0) free_freeze( ); MYfread( &freeze.totalverts, 4, 1, fp ); MYfread( &freeze.totalfaces, 4, 1, fp ); MYfread( &freeze.totalfverts, 4, 1, fp ); freeze.haircount = 0; if( freeze.totalverts > 0 ) { alloc_freeze( ); for( x = 0; x < freeze.totalfaces; x++ ) freeze.colorlock[x] = -1; for( x = 0; x < freeze.totalverts; x++ ) { MYfread( &freeze.v[x].x, 4, 1, fp ); MYfread( &freeze.v[x].y, 4, 1, fp ); MYfread( &freeze.v[x].z, 4, 1, fp ); MYfread( &freeze.Rrvcolor[x], 4, 1, fp ); MYfread( &freeze.Rgvcolor[x], 4, 1, fp ); MYfread( &freeze.Rbvcolor[x], 4, 1, fp ); // freeze.Rrvcolor[x]=100; } for( x = 0; x < freeze.totalfverts; x++ ) { MYfread( &freeze.facelist[x], 4, 1, fp ); } for( x = 0; x < freeze.totalfaces; x++ ) { MYfread( &freeze.mtlgroup[x], 4, 1, fp ); MYfread( &freeze.face_start[x], 4, 1, fp ); MYfread( &freeze.face_end[x], 4, 1, fp ); MYfread( &freeze.colorlock[x], 4, 1, fp ); // printf ("reading colorlock[%d] = %d\n",x,freeze.colorlock[x]); } MYfread( &freeze.textoggle, 4, 1, fp ); freeze_texl = 1; freeze_texg = 0; // global if( freeze.textoggle ) { freeze.textoggle = 1; //local freeze_texl = 0; freeze_texg = 1; } scale_freeze( ); } if( shaveversion >= 'f' ) for( y = 0; y < 5; y++ ) for( x = 22; x < 24; x++ ) // wiggles { float junkf; // if (y!=4) MYfread( &sliders[x][y].value, 4, 1, fp ); // if (y==4) why am i not reading this? // MYfread(&junkf,4,1,fp); } if( shaveversion >= 'g' ) { // get weights int ti; int total_sliders = 30; MYfread( &total_sliders, 4, 1, fp ); // total sliders for( x = 0; x < total_sliders; x++ ) { // ti = sliders[x][0].paint; MYfread( &ti, 4, 1, fp ); // empty/full ? // sliders[x][0].paint = ti; // sliders[x][1].paint = ti; // sliders[x][2].paint = ti; // sliders[x][3].paint = ti; if( ti > 0 ) for( y = 0; y < totalverts; y++ ) { MYfread( &hair[y].slider[x], 4, 1, fp ); // slider contents } } } if( shaveversion >= 'h' ) for( y = 0; y < 5; y++ ) for( x = 0; x < 30; x++ ) // wiggles { float junkf; //if (y!=4) MYfread( &sliders[x][y].value, 4, 1, fp ); //if (y==4) why am i not reading this // MYfread(&junkf,4,1,fp); } if( shaveversion >= 'i' ) for( y = 0; y < 5; y++ ) { MYfread( &LOCAL_PASSES[y], 4, 1, fp ); MYfread( &LOCAL_CNT[y], 4, 1, fp ); } if( shaveversion >= 'j' ) { // free_splines(); // char tmp[255]; //if (RW_CONTEX!=RW_DISK) if( shaveversion2 >= 'n' ) make_splines2( ); else make_splines( ); if( shaveversion2 >= 'n' ) if( splines >= 0 ) { // FIXME: For the hair-flickering problem when dynamics is on, // I tried to not reset the noise-space here since it didn't // in the previous version of the hair library. // // Without these calls it fixes the problem of hair-dynamics, // but I'm wary of changing Joe's code especially since the // last time I did it introduced bugs. // // In addition, another way to fix the bug is to avoid the call // to XSISHAVE_flush_state() in SwitchShaveContext(), and that's // the change Joe suggested (i.e. getting rid of flush_state()) // and it did fix the dynamics hair movement problem, so that's // the one I'm applying. // // I'm only writing this comments to document other routes // I explored in case we need to revisit the problem in the // future. // // So, to be brief, let's keep these resets below active until // we find that we really need to remove them for a good reason // against Joe's advice. It's his code after all, he knows best. // // Pierre Baillargeon, Innobec, 19 october 2006. reset_rest( ); reset_noisespace( ); } //if (RW_CONTEX==RW_DISK) alloc_splines(total_splines); for( x = 0; x < total_splines; x++ ) for( y = 0; y < 15; y++ ) { MYfread( &Shair[x].pfID[y], 4, 1, fp ); Shair[x].pfID[y] = -1; // do we want to lock splines - ever? // there does appear to be a bug where this keeps getting set to 0 // Sresthair[x].pfID[y]=Shair[x].pfID[y]; Shair[x].select[y] = 1; Sresthair[x].select[y] = 1; // Shair[x].pfID[y]= -1; // if (Shair[x].pfID[y]>=0) {printf("pfID came in as %d %d %d!!\n",Shair[x].pfID[y],x,y);} // Shair[x].noisev[y]=Shair[x].hv[y]; // Sresthair[x].noisev[y]=Shair[x].hv[y]; // Sresthair[x] = Shair[x]; } for( x = 0; x < total_splines; x++ ) { MYfread( &Shair[x].splitgroup, 4, 1, fp ); if( shaveversion >= 'k' ) MYfread( &Shair[x].splitmerge, 4, 1, fp ); Sresthair[x] = Shair[x]; if( Shair[x].splitgroup + 1 > totalsplits ) totalsplits = Shair[x].splitgroup + 1; } if( 0 == 1 ) for( x = 0; x < total_splines; x++ ) { Shair[x].restlength = Distance( Shair[x].hv[1], Shair[x].hv[2] ); Sresthair[x].restlength = Shair[x].restlength; } for( y = 0; y < 5; y++ ) for( x = 0; x < 30; x++ ) { // float junkf; MYfread( &sliders[x][y].value, 4, 1, fp ); } } if( shaveversion >= 'l' ) MYfread( &sliders[0][5].value, 4, 1, fp ); if( shaveversion == 'l' ) if( RW_CONTEXT != RW_DISK ) { // state machine int bb; for( bb = 0; bb < totalverts; bb++ ) for( y = 0; y < 15; y++ ) { BASEHAIR dummyhair; MYfread( &dummyhair.hv[y].x, 4, 1, fp ); MYfread( &dummyhair.hv[y].y, 4, 1, fp ); MYfread( &dummyhair.hv[y].z, 4, 1, fp ); MYfread( &dummyhair.hv[y].x, 4, 1, fp ); MYfread( &dummyhair.hv[y].y, 4, 1, fp ); MYfread( &dummyhair.hv[y].z, 4, 1, fp ); MYfread( &dummyhair.hv[y].x, 4, 1, fp ); MYfread( &dummyhair.hv[y].y, 4, 1, fp ); MYfread( &dummyhair.hv[y].z, 4, 1, fp ); MYfread( &dummyhair.hv[y].x, 4, 1, fp ); MYfread( &dummyhair.hv[y].y, 4, 1, fp ); MYfread( &dummyhair.hv[y].z, 4, 1, fp ); } for( bb = 0; bb < total_splines; bb++ ) for( y = 0; y < 15; y++ ) { BASEHAIR dummyhair; MYfread( &dummyhair.hv[y].x, 4, 1, fp ); MYfread( &dummyhair.hv[y].y, 4, 1, fp ); MYfread( &dummyhair.hv[y].z, 4, 1, fp ); MYfread( &dummyhair.hv[y].x, 4, 1, fp ); MYfread( &dummyhair.hv[y].y, 4, 1, fp ); MYfread( &dummyhair.hv[y].z, 4, 1, fp ); MYfread( &dummyhair.hv[y].x, 4, 1, fp ); MYfread( &dummyhair.hv[y].y, 4, 1, fp ); MYfread( &dummyhair.hv[y].z, 4, 1, fp ); MYfread( &dummyhair.hv[y].x, 4, 1, fp ); MYfread( &dummyhair.hv[y].y, 4, 1, fp ); MYfread( &dummyhair.hv[y].z, 4, 1, fp ); MYfread( &dummyhair.hv[y].x, 4, 1, fp ); MYfread( &dummyhair.hv[y].y, 4, 1, fp ); MYfread( &dummyhair.hv[y].z, 4, 1, fp ); } } if( shaveversion >= 'm' ) for( x = 0; x < Dtotalverts; x++ ) { int junki; MYfread( &junki, 4, 1, fp ); } if( shaveversion >= 'n' ) { // MYfread(&GMetaNurb,4,1,fp); MYfread( &DUTtotalfaces, 4, 1, fp ); MYfread( &DUTtotalfverts, 4, 1, fp ); for( x = 0; x < DUTtotalfverts; x++ ) { MYfread( &DUTfacelist[x], 4, 1, fp ); } for( x = 0; x < DUTtotalfaces; x++ ) { MYfread( &DUTface_start[x], 4, 1, fp ); MYfread( &DUTface_end[x], 4, 1, fp ); } } if( shaveversion >= 'o' ) { for( x = 0; x < totalverts; x++ ) { int junki; for( y = 0; y < 15; y++ ) //MYfread(&junki,4,1,fp); MYfread( &hair[x].select[y], 4, 1, fp ); } if( 0 == 1 ) for( x = 0; x < Stotalverts; x++ ) { for( y = 0; y < 15; y++ ) MYfread( &Shair[x].select[y], 4, 1, fp ); } } if( shaveversion >= 'p' ) { for( y = 0; y < 5; y++ ) // make a nice clean write of all the sliders for( x = 30; x < 40; x++ ) { // float junkf; MYfread( &sliders[x][y].value, 4, 1, fp ); } { // get weights int ti; int total_sliders = 40; MYfread( &total_sliders, 4, 1, fp ); // total sliders for( x = 30; x < total_sliders; x++ ) { // ti = sliders[x][0].paint; MYfread( &ti, 4, 1, fp ); // empty/full ? // sliders[x][0].paint = ti; // sliders[x][1].paint = ti; // sliders[x][2].paint = ti; // sliders[x][3].paint = ti; // sliders[x][y].value=ti; if( ti > 0 ) for( y = 0; y < totalverts; y++ ) { MYfread( &hair[y].slider[x], 4, 1, fp ); // slider contents } } } } for( y = 0; y < 5; y++ ) { Ganim_dir[y].x = 0.0f; Ganim_dir[y].y = 1.0f; Ganim_dir[y].z = 0.0f; } if( shaveversion >= 'q' ) { // version q for( y = 0; y < 5; y++ ) // we've got some new sliders here { // float junkf; MYfread( &Ganim_dir[y].x, 4, 1, fp ); MYfread( &Ganim_dir[y].y, 4, 1, fp ); MYfread( &Ganim_dir[y].z, 4, 1, fp ); } } // version r if( shaveversion >= 'r' ) { for( y = 0; y < totalfaces; y++ ) // we've got some new sliders here { MYfread( &face_link[y], 4, 1, fp ); } for( x = 0; x < Dtotalfaces; x++ ) { MYfread( &D2UTface_link[x], 4, 1, fp ); } } if( shaveversion >= 's' ) { DOCOLLIDE = 0; for( y = 0; y < 5; y++ ) // we've got some new sliders here { MYfread( &Gsurface_collide[y], 4, 1, fp ); if( Gsurface_collide[y] > 0 ) DOCOLLIDE = 1; } } if( shaveversion >= 't' ) { // version t // for (y=0;y<5;y++) // we've got some new sliders here { MYfread( &COLLISION_METHOD, 4, 1, fp ); } } if( shaveversion >= 'u' ) for( x = 0; x < total_splines; x++ ) { int junki; for( y = 0; y < 15; y++ ) MYfread( &junki, 4, 1, fp ); // MYfread(&Shair[x].select[y],4,1,fp); } if( shaveversion >= 'v' ) for( y = 0; y < 5; y++ ) { MYfread( &LOCAL_SEGS[y], 4, 1, fp ); } else for( y = 0; y < 5; y++ ) { LOCAL_SEGS[y] = 56; } // version w if( shaveversion == 'w' ) { if( firstloadguv == 1 ) { int tq; // Ganim_dir[0]=0.0f; // Ganim_dir[1]=1.0f; // Ganim_dir[2]=0.0f; init_geomWF( &Guv ); Gdontinterp = 0; //joejoe for( tq = 0; tq < 5; tq++ ) //joejoe Gsurface_collide[tq] = 1; } firstloadguv = 0; free_geomWF( &Guv ); MYfread( &Guv.totalverts, 4, 1, fp ); MYfread( &Guv.totalfaces, 4, 1, fp ); MYfread( &Guv.totalfverts, 4, 1, fp ); alloc_geomWF( &Guv ); if( ( Guv.totalverts == Dtotalverts ) && ( Guv.totalfaces == Dtotalfaces ) && ( Guv.totalfverts == Dtotalfverts ) ) for( y = 0; y < Guv.totalverts; y++ ) { MYfread( &Guv.uv[y].x, 4, 1, fp ); MYfread( &Guv.uv[y].y, 4, 1, fp ); MYfread( &Guv.uv[y].z, 4, 1, fp ); } for( y = 0; y < Guv.totalfverts; y++ ) { MYfread( &Guv.facelist[y], 4, 1, fp ); } for( y = 0; y < Guv.totalfaces; y++ ) { MYfread( &Guv.face_start[y], 4, 1, fp ); MYfread( &Guv.face_end[y], 4, 1, fp ); } if( ( Guv.totalverts > 0 ) || ( Guv.totalfaces > 0 ) || ( Guv.totalfverts > 0 ) ) if( !( ( Guv.totalverts == Dtotalverts ) && ( Guv.totalfaces == Dtotalfaces ) && ( Guv.totalfverts == Dtotalfverts ) ) ) free_geomWF( &Guv ); // turn it off because it doesn't match } if( shaveversion >= 'x' ) { for( xx = 0; xx < totalverts; xx++ ) { MYfread( &hair[xx].uu, 4, 1, fp ); MYfread( &hair[xx].vv, 4, 1, fp ); // hair[xx].uu=hair[xx].uu; // hair[xx].vv=hair[xx].vv; } for( xx = 0; xx < total_splines; xx++ ) { MYfread( &Sresthair[xx].uu, 4, 1, fp ); MYfread( &Sresthair[xx].vv, 4, 1, fp ); Shair[xx].uu = Sresthair[xx].uu; Shair[xx].vv = Sresthair[xx].vv; } } if( shaveversion2 >= 'b' ) { int xx, y; for( xx = 0; xx < totalverts; xx++ ) for( y = 0; y < 15; y++ ) { MYfread( &hair[xx].noisev[y].x, 4, 1, fp ); MYfread( &hair[xx].noisev[y].y, 4, 1, fp ); MYfread( &hair[xx].noisev[y].z, 4, 1, fp ); // hair[xx].noisev[y]=hair[xx].noisev[y]; // hair[xx].noisev[y]=hair[xx].noisev[y]; // lasthair[xx].noisev[y]=resthair[xx].noisev[y]; } for( xx = 0; xx < total_splines; xx++ ) for( y = 0; y < 15; y++ ) { float dum; // MYfread( &dum, 4, 1, fp ); // MYfread( &dum, 4, 1, fp ); // MYfread( &dum, 4, 1, fp ); MYfread( &Sresthair[xx].noisev[y].x, 4, 1, fp ); MYfread( &Sresthair[xx].noisev[y].y, 4, 1, fp ); MYfread( &Sresthair[xx].noisev[y].z, 4, 1, fp ); //#ifdef we_really_dont_need_cache_this_crap Shair[xx].noisev[y] = Sresthair[xx].noisev[y]; Sthishair[xx].noisev[y] = Sresthair[xx].noisev[y]; Slasthair[xx].noisev[y] = Sresthair[xx].noisev[y]; //#ifdef crap // if (RW_CONTEXT==RW_DISK) { Shair[xx].hv[y] = Shair[xx].noisev[y]; Shair[xx].resthv[y] = Shair[xx].noisev[y]; Sresthair[xx].hv[y] = Shair[xx].noisev[y]; Sresthair[xx].resthv[y] = Shair[x].noisev[y]; Sthishair[xx].hv[y] = Shair[xx].noisev[y]; Slasthair[xx].hv[y] = Shair[xx].noisev[y]; } //#endif //#endif } } if( shaveversion2 >= 'e' ) { for( y = 0; y < 5; y++ ) for( x = 40; x < 41; x++ ) { MYfread( &sliders[x][y].value, 4, 1, fp ); } } if( shaveversion2 >= 'f' ) { for( y = 0; y < 5; y++ ) for( x = 41; x < 45; x++ ) { MYfread( &sliders[x][y].value, 4, 1, fp ); } } //if (shaveversion2>='h') // MYfread(&Gbacklighting,4,1,fp); if( shaveversion2 >= 'h' ) for( y = 0; y < 5; y++ ) { MYfread( &LOCAL_SHADCNT[y], 4, 1, fp ); } if( shaveversion2 >= 'i' ) { MYfread( &Guv_totalsets, 4, 1, fp ); for( x = 0; x < Guv_totalsets; x++ ) { MYfread( &Guv_sets[x].totalverts, 4, 1, fp ); MYfread( &Guv_sets[x].totalfverts, 4, 1, fp ); MYfread( &Guv_sets[x].totalfaces, 4, 1, fp ); alloc_geomWF( &Guv_sets[x] ); for( y = 0; y < Guv_sets[x].totalverts; y++ ) { MYfread( &Guv_sets[x].v[y].x, 4, 1, fp ); MYfread( &Guv_sets[x].v[y].y, 4, 1, fp ); MYfread( &Guv_sets[x].v[y].z, 4, 1, fp ); } for( y = 0; y < Guv_sets[x].totalfverts; y++ ) MYfread( &Guv_sets[x].facelist[y], 4, 1, fp ); for( y = 0; y < Guv_sets[x].totalfaces; y++ ) { MYfread( &Guv_sets[x].face_start[y], 4, 1, fp ); MYfread( &Guv_sets[x].face_end[y], 4, 1, fp ); } } } if( shaveversion2 >= 'j' ) { for( x = 0; x < 45; x++ ) MYfread( &Guv_link[x], 4, 1, fp ); } if( shaveversion2 == 'k' ) { // The actual version that Joe gave us that defines version 'zyk' of // the shave MEMFILE reads something entirely different from the // CVS version he gave us. From disassembly it seems to be reading // some slider values which currently are dead pointers. No idea why // he did that. for( xx = 0; xx < 5; xx++ ) { for( x = 0; x < 45; x++ ) { int dummy; MYfread( &dummy, 4, 1, fp ); } } // Need to recalc rest length: for( xx = 0; xx < totalverts; xx++ ) { int y; float smalll = 1000000000; for( y = 5; y < 8; y++ ) { float dd; dd = distance( hair[xx].resthv[y], hair[xx].resthv[y + 1] ); if( dd < smalll ) smalll = dd; hair[xx].restlength = smalll; if( hair[xx].restlength < .000001 ) hair[xx].restlength = 0; } } for( xx = 0; xx < total_splines; xx++ ) { int y; float smalll = 10000; for( y = 5; y < 8; y++ ) { float dd; dd = distance( Sresthair[xx].hv[y], Sresthair[xx].hv[y + 1] ); if( dd < smalll ) smalll = dd; Sresthair[xx].restlength = smalll; if( Sresthair[xx].restlength < .000001 ) Sresthair[xx].restlength = 0; } } } // Later revisions are correct for this. if( shaveversion2 > 'k' ) { int xx, y; for( xx = 0; xx < totalverts; xx++ ) MYfread( &hair[xx].restlength, 4, 1, fp ); for( xx = 0; xx < total_splines; xx++ ) { MYfread( &Sresthair[xx].restlength, 4, 1, fp ); Shair[xx].restlength = Sresthair[xx].restlength; } } if( shaveversion2 >= 'm' ) { int vers = 0, vers1; vers = 1; // softimage #ifdef MAYA3D vers = 2; #endif #ifdef MAX3D vers = 3; #endif #ifdef C4D vers = 4; #endif MYfread( &vers1, 4, 1, fp ); if( vers != vers1 ) SHAVEclear_scene( ); // from another version of shave! } if( shaveversion2 >= 'p' ) { int qq; for( qq = 0; qq < totalverts; qq++ ) { int hide; MYfread( &hide, 4, 1, fp ); hair[qq].hide = hide; } for( qq = 0; qq < total_splines; qq++ ) { int hide; MYfread( &hide, 4, 1, fp ); Shair[qq].hide = hide; } } if( shaveversion2 >= 'q' ) { MYfread( &Gspec_tint.x, 4, 1, fp ); MYfread( &Gspec_tint.y, 4, 1, fp ); MYfread( &Gspec_tint.z, 4, 1, fp ); } if (shaveversion2>= 'r') if (totalverts>0) { int qq; MYfread( &Gtotal_splinelocks, 4, 1, fp ); if (Gtotal_splinelocks>0) for( qq = 0; qq < totalverts; qq++ ) { int id; float w; MYfread( &hair[qq].Bid1, 4, 1, fp ); MYfread( &hair[qq].Bid2, 4, 1, fp ); MYfread( &hair[qq].Bid3, 4, 1, fp ); MYfread( &hair[qq].bw1, 4, 1, fp ); MYfread( &hair[qq].bw2, 4, 1, fp ); MYfread( &hair[qq].bw3, 4, 1, fp ); } } if (shaveversion2>= 's') { int qq; // MYfread( &Gsquirrel, 4, 1, fp ); // fprintf (stdout,"Gsquirrel = %d\n", Gsquirrel);fflush(stdout); } if (shaveversion2>= 's') { int qq; // MYfwrite( &Gsquirrel, 4, 1, fp ); for( y = 0; y < 5; y++ ) for( x = 45; x < 50; x++ ) { MYfread( &sliders[x][y].value, 4, 1, fp ); } for( x = 0; x < 50; x++ ) MYfread( &Guv_link[x], 4, 1, fp ); for (x=0;x= 't') // 6.0 adds 10 channels { int qq; // MYfwrite( &Gsquirrel, 4, 1, fp ); for( y = 0; y < 5; y++ ) for( x = 50; x < 60; x++ ) { MYfread( &sliders[x][y].value, 4, 1, fp ); } for( x = 50; x < 60; x++ ) MYfread( &Guv_link[x], 4, 1, fp ); for (x=0;x= 'u') if (shaveversion2>= 'u') // 6.0 adds 10 channels { int tmpi; MYfread( &tmpi, 4, 1, fp ); // don't read SHAVEID=(unsigned long) tmpi; } if( shaveversion2 >= 'v' ) { MYfread( &Gspec_tint2.x, 4, 1, fp ); MYfread( &Gspec_tint2.y, 4, 1, fp ); MYfread( &Gspec_tint2.z, 4, 1, fp ); } gravity = sliders[0][5].value; for( y = 0; y < 5; y++ ) if( Gsurface_collide[y] == 1 ) DOCOLLIDE = 1; if( skull_sphere == -1 ) DOCOLLIDE = 0; make_normals( ); } if( fp ) { //restBOUNDLENGTH=BOUNDLENGTH; initbounds( ); make_normals( ); //if (0==1) if( shaveversion2 <= 'j' ) if( Gdynamics_mode != 1 ) if( ( LOCAL_CNT[4] > 0 ) || ( LOCAL_SHADCNT[4] > 0 ) ) { int q, fv, en; // if (0==1) // what the hell is this??? // for (q=0;q 0 ) || ( LOCAL_SHADCNT[0] > 0 ) ) { int q, fv, en; // if (0==1) // what the hell is this??? // for (q=0;q0) freeverts( ); // if (total_splines>0) free_splines( ); // if (Dtotalverts>0) Dfreeverts( ); } checkforzero( ); init_noise( ); reset_faces( ); checkforzero( ); // mkbounds( ); // texture_bounds( ); // weight_polys( ); collect_guides( ); reset_dynamics( ); // ??? for( x = 0; x < total_splines; x++ ) memcpy( &Sresthair[x], &Shair[x], sizeof( BASEHAIR ) ); if( splines >= 0 ) { freeverts( ); for( x = 0; x < Dtotalverts; x++ ) Dtag[x] = 0; } if( shaveversion2 <= 'm' ) { restructure_hair( ); for( x = 0; x < total_splines; x++ ) { for( y = 0; y < 15; y++ ) Shair[x].select[y] = 1; memcpy( &Sresthair[x], &Shair[x], sizeof( BASEHAIR ) ); } } if( shaveversion2 < 'o' ) flip_instances( ); if( RW_CONTEXT == RW_DISK ) reset_rest( ); if( RW_CONTEXT == RW_DISK ) reset_noisespace( ); if( RW_CONTEXT == RW_DISK ) for( x = 0; x < total_splines; x++ ) { for( y = 0; y < 15; y++ ) Shair[x].select[y] = 1; memcpy( &Sresthair[x], &Shair[x], sizeof( BASEHAIR ) ); } // if( RW_CONTEXT == RW_DISK ) // reset_rest( ); // mkbounds(); // if( RW_CONTEXT == RW_DISK ) // reset_noisespace( ); if( RW_CONTEXT == RW_DISK ) if( splines >= 0 ) make_spline_normals( ); //mkHandles(); { float qt = 0.0f; for( x = 0; x < totalverts; x++ ) { qt += hair[x].restlength; } for( x = 0; x < total_splines; x++ ) { qt += Shair[x].restlength; } genON = 0; if( qt > 0.0f ) genON = 1; } mkbounds( ); texture_bounds( ); make_normals( ); mkHandles( ); Smake_restlengths( ); weight_polys( ); // if (undo) {free( undo );undo=NULL;undo_totalverts=0;} last_totalverts = totalverts; //if (undo) //if ((lsSHAVEID!=SHAVEID)||(totalverts!=last_totalverts)) //clear_undo(); //if (Sundo) //if ((lsSHAVEID!=SHAVEID)||(total_splines!=last_total_splines)) //clear_undo(); // if (undo) // { // if (lsSHAVEID!=SHAVEID) // {free( undo );undo=NULL;undo_totalverts=0;} // // } // if (Sundo) // { // // if (lsSHAVEID!=SHAVEID) // {free( Sundo );Sundo=NULL;Sundo_totalverts=0;} // // } // kd_free(Gkd); // if (!Gkd) // if (Gclumps>3) // if (TILEMODE==0) init_clumping(); // refreshing the clumping - not sure we need to do this every frame //clear_uvsets(); lsSHAVEID = SHAVEID; } void SHAVEfree_clump(void); void SHAVEinit_clump(void); void SHAVEfree_clump(void) { //if (Gindex) //free(Gindex); //kd_free(Gkd); } static void read_state( CHNG *fname ) { //char tmp[255]; //int tmpi; //float tmpf; FILE *fp = NULL; //=NULL; //FILE *dg;//=NULL; //VERT *backup; int x, y; int trys = 0; int ex = 0; int xx; int i; int doit = 1; //if (ex==1) { #ifdef DOUNICODE fp = ( FILE * ) MYfopen( fname, L"rb" ); #else fp = ( FILE * ) MYfopen( fname, "rb" ); #endif if( fp ) { int junki, junki1, junki2; int tempcount; int tempcountsplines; int fversion = -1; MYfread( &junki1, 4, 1, fp ); MYfread( &junki2, 4, 1, fp ); if( junki1 == junki2 ) { MYfread( &tempcount, 4, 1, fp ); MYfread( &junki, 4, 1, fp ); fversion = junki1; } else tempcount = junki1; MYfread( &junki, 4, 1, fp ); MYfread( &tempcountsplines, 4, 1, fp ); if( tempcount != totalverts ) printf( "%s doesn't match node vertcounts: ignoring file\n", fname ); if( tempcount == totalverts ) for( x = 0; x < totalverts; x++ ) { doit = 1; if( fversion >= 0 ) if( hair[x].restlength == 0.0f ) doit = 0; if( doit ) { int junki; MYfread( &junki, 4, 1, fp ); for( y = 0; y < 15; y++ ) { MYfread( &hair[x].hv[y].x, 4, 1, fp ); MYfread( &hair[x].hv[y].y, 4, 1, fp ); MYfread( &hair[x].hv[y].z, 4, 1, fp ); hair[x].velocity[y].x = 0; hair[x].velocity[y].y = 0; hair[x].velocity[y].z = 0; MYfread( &hair[x].lasthv[y].x, 4, 1, fp ); MYfread( &hair[x].lasthv[y].y, 4, 1, fp ); MYfread( &hair[x].lasthv[y].z, 4, 1, fp ); hair[x].velocity[y].x = hair[x].hv[y].x - hair[x].lasthv[y].x; hair[x].velocity[y].y = hair[x].hv[y].y - hair[x].lasthv[y].y; hair[x].velocity[y].z = hair[x].hv[y].z - hair[x].lasthv[y].z; } } } //printf ("total_splines = %d\n",total_splines); if( tempcountsplines == total_splines ) for( x = 0; x < total_splines; x++ ) { doit = 1; if( fversion >= 0 ) if( Shair[x].restlength == 0.0f ) doit = 0; if( doit ) { int junki; MYfread( &junki, 4, 1, fp ); for( y = 0; y < 15; y++ ) { MYfread( &Shair[x].hv[y].x, 4, 1, fp ); MYfread( &Shair[x].hv[y].y, 4, 1, fp ); MYfread( &Shair[x].hv[y].z, 4, 1, fp ); Sthishair[x].hv[y] = Shair[x].hv[y]; Shairvelocity[x].hv[y].x = 0; Shairvelocity[x].hv[y].y = 0; Shairvelocity[x].hv[y].z = 0; MYfread( &Slasthair[x].hv[y].x, 4, 1, fp ); MYfread( &Slasthair[x].hv[y].y, 4, 1, fp ); MYfread( &Slasthair[x].hv[y].z, 4, 1, fp ); Shair[x].velocity[y].x = Sthishair[x].hv[y].x - Slasthair[x].hv[y].x; Shair[x].velocity[y].y = Sthishair[x].hv[y].y - Slasthair[x].hv[y].y; Shair[x].velocity[y].z = Sthishair[x].hv[y].z - Slasthair[x].hv[y].z; Slasthair[x].noisev[y] = Sresthair[x].noisev[y]; Sthishair[x].noisev[y] = Sresthair[x].noisev[y]; Shair[x].noisev[y] = Sresthair[x].noisev[y]; } } } if( fp ) MYfclose( fp ); } // if (fp) // else // printf( "couldn't read stat %s\n", fname ); } // if ex for (x=0;x 0 ) { Tfacelist[Ttotalfverts]--; } } Ttotalfverts++; /* this is for SI .objs */ tmp2 = strtok( NULL, WHT ); } /* totalfverts++; */ Tface_end[Ttotalfaces] = Ttotalfverts; /* assign vertex groups */ Tmtlgroup[Ttotalfaces] = Tcurrent_group; // if (Tface_end[Ttotalfaces]==Tface_start[Ttotalfaces]) printf("0 vert face!\n"); if( Tface_end[Ttotalfaces] != Tface_start[Ttotalfaces] ) Ttotalfaces++; } } /* printf ("totalverts = %d totalfaces = %d totalfverts = %d\n",totalverts,totalfaces,totalfverts); */ sprintf( statline, "totalverts = %d totalfaces = %d totalfverts = %d", tv, Ttotalfaces, Ttotalfverts ); DRAW_STATUS( statline ); MYfclose( fp ); } DRAW_STATUS( statline ); if( xplant ) { Nfree( xplant ); Nfree( Tface_start ); Nfree( Tface_end ); Nfree( Tfacelist ); Nfree( Tmtlgroup ); } } static void write_inst( CHNG fname[500] ) { //char tmp[255]; //int tmpi; //float tmpf; FILE *fp = NULL; int x; int hc = 0; int hc2 = 0; //float spanx=100000,spanz=10000,spanx1=0,spanz1=0; mkbounds( ); weight_polys( ); texture_bounds( ); //for (x=0;xspanx1) spanx1=Dv[x].x; // if (Dv[x].xspanz1) spanz1=Dv[x].z; // if (Dv[x].z= 0 ) if( Dmtlgroup[x] == colorlock ) cll = 1; MYfwrite( &cll, 4, 1, fp ); } MYfwrite( &freeze.textoggle, 4, 1, fp ); MYfclose( fp ); } static void free_freeze( void ) { if( freeze.uv ); free( freeze.uv ); freeze.uv=NULL; if( freeze.colorlock ); free( freeze.colorlock ); freeze.colorlock=NULL; if( freeze.face_start ); free( freeze.face_start ); freeze.face_start=NULL; if( freeze.face_end ); free( freeze.face_end ); freeze.face_end=NULL; if (freeze.facelist) free( freeze.facelist ); freeze.facelist=NULL; if (freeze.mtlgroup) free( freeze.mtlgroup ); freeze.mtlgroup=NULL; if (freeze.envelope) free( freeze.envelope ); freeze.envelope=NULL; if (freeze.v) free( freeze.v ); freeze.v=NULL; if (freeze.velocity) free( freeze.velocity ); freeze.velocity=NULL; if (freeze.vn) free( freeze.vn ); freeze.vn=NULL; freeze.totalverts = 0; freeze.totalfaces = 0; freeze.totalfverts = 0; if (freeze.h) free( freeze.h ); freeze.h=NULL; if (freezetmp.v) free( freezetmp.v ); freezetmp.v=NULL; if (freezetmp.velocity) free( freezetmp.velocity ); freezetmp.velocity=NULL; if (freezetmp.vn) free( freezetmp.vn ); freezetmp.vn=NULL; if (freezetmp.rvcolor) free( freezetmp.rvcolor ); freezetmp.rvcolor=NULL; if (freezetmp.gvcolor) free( freezetmp.gvcolor ); freezetmp.gvcolor=NULL; if (freezetmp.bvcolor) free( freezetmp.bvcolor ); freezetmp.bvcolor=NULL; if (freezetmp.Rrvcolor) free( freezetmp.Rrvcolor ); freezetmp.Rrvcolor=NULL; if (freezetmp.Rgvcolor) free( freezetmp.Rgvcolor ); freezetmp.Rgvcolor=NULL; if (freezetmp.Rbvcolor) free( freezetmp.Rbvcolor ); freezetmp.Rbvcolor=NULL; if (freezetmp1.v) free( freezetmp1.v ); freezetmp1.v=NULL; if (freezetmp1.velocity) free( freezetmp1.velocity ); freezetmp1.velocity=NULL; if (freezetmp1.vn) free( freezetmp1.vn ); freezetmp1.vn=NULL; if (freezetmp1.rvcolor) free( freezetmp1.rvcolor ); freezetmp1.rvcolor=NULL; if (freezetmp1.gvcolor) free( freezetmp1.gvcolor ); freezetmp1.gvcolor=NULL; if (freezetmp1.bvcolor) free( freezetmp1.bvcolor ); freezetmp1.bvcolor=NULL; if (freezetmp1.Rrvcolor) free( freezetmp1.Rrvcolor ); freezetmp1.Rrvcolor=NULL; if (freezetmp1.Rgvcolor) free( freezetmp1.Rgvcolor ); freezetmp1.Rgvcolor=NULL; if (freezetmp1.Rbvcolor) free( freezetmp1.Rbvcolor ); freezetmp1.Rbvcolor=NULL; if( freezetmp2.v ); free( freezetmp2.v ); freezetmp2.v=NULL; if (freezetmp2.velocity) free( freezetmp2.velocity ); freezetmp2.velocity=NULL; if (freezetmp2.vn) free( freezetmp2.vn ); freezetmp2.vn=NULL; if (freezetmp2.rvcolor) free( freezetmp2.rvcolor ); freezetmp2.rvcolor=NULL; if (freezetmp2.gvcolor) free( freezetmp2.gvcolor ); freezetmp2.gvcolor=NULL; if (freezetmp2.bvcolor) free( freezetmp2.bvcolor ); freezetmp2.bvcolor=NULL; if (freezetmp2.Rrvcolor) free( freezetmp2.Rrvcolor ); freezetmp2.Rrvcolor=NULL; if (freezetmp2.Rgvcolor) free( freezetmp2.Rgvcolor ); freezetmp2.Rgvcolor=NULL; if (freezetmp2.Rbvcolor) free( freezetmp2.Rbvcolor ); freezetmp2.Rbvcolor=NULL; if( freeze.rvcolor ); free( freeze.rvcolor ); freeze.rvcolor=NULL; if (freeze.gvcolor) free( freeze.gvcolor ); freeze.gvcolor=NULL; if (freeze.bvcolor) free( freeze.bvcolor ); freeze.bvcolor=NULL; if (freeze.Rrvcolor) free( freeze.Rrvcolor ); freeze.Rrvcolor=NULL; if (freeze.Rgvcolor) free( freeze.Rgvcolor ); freeze.Rgvcolor=NULL; if (freeze.Rbvcolor) free( freeze.Rbvcolor ); freeze.Rbvcolor=NULL; if (freezetmp.h) free( freezetmp.h ); freezetmp.h=NULL; if (freezetmp1.h) free( freezetmp1.h ); freezetmp1.h=NULL; if (freezetmp2.h) free( freezetmp2.h ); freezetmp2.h=NULL; freeze.totalverts = 0; freeze.haircount = 0; } static void alloc_freeze( void ) { int x; freeze.v = NULL; freeze.uv = NULL; freeze.vn = NULL; freeze.facelist = NULL; freeze.colorlock = NULL; freeze.face_start = NULL; freeze.face_end = NULL; freeze.mtlgroup = NULL; freeze.envelope = NULL; freeze.rvcolor = NULL; freeze.gvcolor = NULL; freeze.bvcolor = NULL; freeze.Rrvcolor = NULL; freeze.Rgvcolor = NULL; freeze.Rbvcolor = NULL; freezetmp.rvcolor = NULL; freezetmp.gvcolor = NULL; freezetmp.bvcolor = NULL; freezetmp.Rrvcolor = NULL; freezetmp.Rgvcolor = NULL; freezetmp.Rbvcolor = NULL; freezetmp1.rvcolor = NULL; freezetmp1.gvcolor = NULL; freezetmp1.bvcolor = NULL; freezetmp1.Rrvcolor = NULL; freezetmp1.Rgvcolor = NULL; freezetmp1.Rbvcolor = NULL; freezetmp2.rvcolor = NULL; freezetmp2.gvcolor = NULL; freezetmp2.bvcolor = NULL; freezetmp2.Rrvcolor = NULL; freezetmp2.Rgvcolor = NULL; freezetmp2.Rbvcolor = NULL; freezetmp.v = NULL; freezetmp.velocity = NULL; freezetmp1.v = NULL; freezetmp1.velocity = NULL; freezetmp2.v = NULL; freezetmp2.velocity = NULL; freezetmp.vn = NULL; freezetmp1.vn = NULL; freezetmp2.vn = NULL; freeze.velocity = NULL; freeze.v = NULL; if( freeze.totalverts > 0 ) { freeze.textoggle = 1; freeze.uv = ( VERT * ) malloc( freeze.totalverts * 4 * sizeof( VERT ) ); freeze.vn = ( VERT * ) malloc( freeze.totalverts * sizeof( VERT ) ); freeze.facelist = ( int * ) malloc( freeze.totalfverts * sizeof( int ) ); freeze.colorlock = ( int * ) malloc( freeze.totalfaces * sizeof( int ) ); freeze.face_start = ( int * ) malloc( freeze.totalfaces * sizeof( int ) ); freeze.face_end = ( int * ) malloc( freeze.totalfaces * sizeof( int ) ); freeze.mtlgroup = ( int * ) malloc( freeze.totalfaces * sizeof( int ) ); freeze.envelope = ( ENVELOPETYPE * ) malloc( freeze.totalverts * sizeof( ENVELOPETYPE ) ); freeze.rvcolor = ( float * ) malloc( freeze.totalverts * sizeof( float ) ); freeze.gvcolor = ( float * ) malloc( freeze.totalverts * sizeof( float ) ); freeze.bvcolor = ( float * ) malloc( freeze.totalverts * sizeof( float ) ); freeze.Rrvcolor = ( float * ) malloc( freeze.totalverts * sizeof( float ) ); freeze.Rgvcolor = ( float * ) malloc( freeze.totalverts * sizeof( float ) ); freeze.Rbvcolor = ( float * ) malloc( freeze.totalverts * sizeof( float ) ); freezetmp.rvcolor = ( float * ) malloc( freeze.totalverts * sizeof( float ) ); freezetmp.gvcolor = ( float * ) malloc( freeze.totalverts * sizeof( float ) ); freezetmp.bvcolor = ( float * ) malloc( freeze.totalverts * sizeof( float ) ); freezetmp.Rrvcolor = ( float * ) malloc( freeze.totalverts * sizeof( float ) ); freezetmp.Rgvcolor = ( float * ) malloc( freeze.totalverts * sizeof( float ) ); freezetmp.Rbvcolor = ( float * ) malloc( freeze.totalverts * sizeof( float ) ); freezetmp1.rvcolor = ( float * ) malloc( freeze.totalverts * sizeof( float ) ); freezetmp1.gvcolor = ( float * ) malloc( freeze.totalverts * sizeof( float ) ); freezetmp1.bvcolor = ( float * ) malloc( freeze.totalverts * sizeof( float ) ); freezetmp1.Rrvcolor = ( float * ) malloc( freeze.totalverts * sizeof( float ) ); freezetmp1.Rgvcolor = ( float * ) malloc( freeze.totalverts * sizeof( float ) ); freezetmp1.Rbvcolor = ( float * ) malloc( freeze.totalverts * sizeof( float ) ); freezetmp2.rvcolor = ( float * ) malloc( freeze.totalverts * sizeof( float ) ); freezetmp2.gvcolor = ( float * ) malloc( freeze.totalverts * sizeof( float ) ); freezetmp2.bvcolor = ( float * ) malloc( freeze.totalverts * sizeof( float ) ); freezetmp2.Rrvcolor = ( float * ) malloc( freeze.totalverts * sizeof( float ) ); freezetmp2.Rgvcolor = ( float * ) malloc( freeze.totalverts * sizeof( float ) ); freezetmp2.Rbvcolor = ( float * ) malloc( freeze.totalverts * sizeof( float ) ); //for (x=0;x0) free_freeze( ); MYfread( &freeze.totalverts, 4, 1, fp ); MYfread( &freeze.totalfaces, 4, 1, fp ); MYfread( &freeze.totalfverts, 4, 1, fp ); freeze.haircount = 0; alloc_freeze( ); for( x = 0; x < freeze.totalfaces; x++ ) freeze.colorlock[x] = -1; for( x = 0; x < freeze.totalverts; x++ ) { MYfread( &freeze.v[x].x, 4, 1, fp ); MYfread( &freeze.v[x].y, 4, 1, fp ); MYfread( &freeze.v[x].z, 4, 1, fp ); MYfread( &freeze.Rrvcolor[x], 4, 1, fp ); MYfread( &freeze.Rgvcolor[x], 4, 1, fp ); MYfread( &freeze.Rbvcolor[x], 4, 1, fp ); } for( x = 0; x < freeze.totalfverts; x++ ) { MYfread( &freeze.facelist[x], 4, 1, fp ); } for( x = 0; x < freeze.totalfaces; x++ ) { MYfread( &freeze.mtlgroup[x], 4, 1, fp ); MYfread( &freeze.face_start[x], 4, 1, fp ); MYfread( &freeze.face_end[x], 4, 1, fp ); MYfread( &freeze.colorlock[x], 4, 1, fp ); // printf ("freeze.colorlock[%d] = %d\n",freeze.colorlock[x]); } MYfread( &freeze.textoggle, 4, 1, fp ); freeze_texl = 1; freeze_texg = 0; // global if( freeze.textoggle ) { freeze.textoggle = 1; //local freeze_texl = 0; freeze_texg = 1; } MYfclose( fp ); scale_freeze( ); { char statline[255]; sprintf( statline, "instance : tv = %d th = %d ", freeze.totalverts, freeze.haircount ); DRAW_STATUS( statline ); } } static void flip_instances( void ) { int tmp[400]; int total = 0; int x, y; for( x = 0; x < freeze.totalfaces; x++ ) { total = 0; for( y = freeze.face_end[x] - 1; y >= freeze.face_start[x]; y-- ) { tmp[total] = freeze.facelist[y]; total++; } total = 0; for( y = freeze.face_start[x]; y < freeze.face_end[x]; y++ ) { tmp[total] = freeze.facelist[y]; total++; } } } static void set_inst( WFTYPE * wf ) { FILE *fp = NULL; int x; int tfl = 0; // fp = ( FILE * ) MYfopen( fname, "rb" ); //if (freeze.totalverts>0) free_freeze( ); // MYfread( &freeze.totalverts, 4, 1, fp ); // MYfread( &freeze.totalfaces, 4, 1, fp ); // MYfread( &freeze.totalfverts, 4, 1, fp ); freeze.totalverts = wf->totalverts; freeze.totalfverts = wf->totalfverts; freeze.totalfaces = wf->totalfaces; freeze.haircount = 0; alloc_freeze( ); for( x = 0; x < freeze.totalfaces; x++ ) freeze.colorlock[x] = 1; for( x = 0; x < freeze.totalverts; x++ ) { freeze.v[x] = wf->v[x]; freeze.Rrvcolor[x] = wf->color[x].x; freeze.Rgvcolor[x] = wf->color[x].y; freeze.Rbvcolor[x] = wf->color[x].z; } //flip faces tfl = 0; //#ifdef crap for( x = 0; x < wf->totalfaces; x++ ) { int y; freeze.mtlgroup[x] = 0; freeze.face_start[x] = tfl; for( y = wf->face_start[x]; y < wf->face_end[x]; y++ ) { freeze.facelist[tfl] = wf->facelist[y]; tfl++; } freeze.face_end[x] = tfl; // freeze.facelist[x]=wf->facelist[x]; // MYfread( &freeze.facelist[x], 4, 1, fp ); } for( x = 0; x < freeze.totalfaces; x++ ) { //++ freeze.mtlgroup[x]=0; // MYfread( &freeze.mtlgroup[x], 4, 1, fp ); //++ freeze.face_start[x]=wf->face_start[x]; //++ freeze.face_end[x]=wf->face_end[x]; // MYfread( &freeze.face_start[x], 4, 1, fp ); // MYfread( &freeze.face_end[x], 4, 1, fp ); // MYfread( &freeze.colorlock[x], 4, 1, fp ); // printf ("freeze.colorlock[%d] = %d\n",freeze.colorlock[x]); } //#endif // MYfread( &freeze.textoggle, 4, 1, fp ); freeze.textoggle = 1; freeze_texl = 1; freeze_texg = 0; // global if( freeze.textoggle ) { freeze.textoggle = 1; //local freeze_texl = 0; freeze_texg = 1; } // MYfclose( fp ); scale_freeze( ); // { // char statline[255]; // // sprintf( statline, "instance : tv = %d th = %d ", freeze.totalverts, // freeze.haircount ); // DRAW_STATUS( statline ); // } } static void store_inst( WFTYPE * wf ) { FILE *fp = NULL; int x; // fp = ( FILE * ) MYfopen( fname, "rb" ); //if (freeze.totalverts>0) // free_freeze( ); // MYfread( &freeze.totalverts, 4, 1, fp ); // MYfread( &freeze.totalfaces, 4, 1, fp ); // MYfread( &freeze.totalfverts, 4, 1, fp ); // if (wf->v!=NULL) free_geomWF(wf); wf->totalverts = freeze.totalverts; wf->totalfaces = freeze.totalfaces; wf->totalfverts = freeze.totalfverts; alloc_geomWF( wf ); for( x = 0; x < freeze.totalverts; x++ ) { wf->v[x] = freeze.v[x]; wf->color[x].x = freeze.Rrvcolor[x]; wf->color[x].y = freeze.Rgvcolor[x]; wf->color[x].z = freeze.Rbvcolor[x]; } for( x = 0; x < freeze.totalfverts; x++ ) { wf->facelist[x] = freeze.facelist[x]; // MYfread( &freeze.facelist[x], 4, 1, fp ); } for( x = 0; x < freeze.totalfaces; x++ ) { // freeze.mtlgroup[x]=0; // MYfread( &freeze.mtlgroup[x], 4, 1, fp ); wf->face_start[x] = freeze.face_start[x]; wf->face_end[x] = freeze.face_end[x]; // MYfread( &freeze.face_start[x], 4, 1, fp ); // MYfread( &freeze.face_end[x], 4, 1, fp ); // MYfread( &freeze.colorlock[x], 4, 1, fp ); // printf ("freeze.colorlock[%d] = %d\n",freeze.colorlock[x]); } // MYfread( &freeze.textoggle, 4, 1, fp ); // freeze.textoggle=1; // freeze_texl = 1; // freeze_texg = 0; // global // if( freeze.textoggle ) { // freeze.textoggle = 1; //local // freeze_texl = 0; // freeze_texg = 1; } // MYfclose( fp ); // scale_freeze( ); // { // char statline[255]; // // sprintf( statline, "instance : tv = %d th = %d ", freeze.totalverts, // freeze.haircount ); // DRAW_STATUS( statline ); // } } static void read_state_machine( MEMFILE * fp ) { int y; int x; char nodevers = 0; fp->pos = 0; #ifdef DOUNICODE fp = ( MEMFILE * ) MYfopen( fp, L"r" ); #else fp = ( MEMFILE * ) MYfopen( fp, "r" ); #endif MYfread( &nodevers, 1, 1, fp ); if( nodevers == 'b' ) { MYfread( &nodevers, 1, 1, fp ); } else { nodevers = 0; fp->pos = 0; } if( RW_CONTEXT != RW_DISK ) { // state machine int bb; if( nodevers >= 'a' ) for( bb = 0; bb < Dtotalverts; bb++ ) { MYfread( &Dv[bb].x, 4, 1, fp ); MYfread( &Dv[bb].y, 4, 1, fp ); MYfread( &Dv[bb].z, 4, 1, fp ); } if( totalverts > 0 ) for( bb = 0; bb < totalverts; bb++ ) { // if ((hair[bb].select[0])||(Gdynamics_mode!=0)) for( y = 0; y < 15; y++ ) { VERT dummy; MYfread( &hair[bb].hv[y].x, 4, 1, fp ); MYfread( &hair[bb].hv[y].y, 4, 1, fp ); MYfread( &hair[bb].hv[y].z, 4, 1, fp ); MYfread( &hair[bb].lasthv[y].x, 4, 1, fp ); MYfread( &hair[bb].lasthv[y].y, 4, 1, fp ); MYfread( &hair[bb].lasthv[y].z, 4, 1, fp ); MYfread( &hair[bb].velocity[y].x, 4, 1, fp ); MYfread( &hair[bb].velocity[y].y, 4, 1, fp ); MYfread( &hair[bb].velocity[y].z, 4, 1, fp ); //thishair[bb].noisev[y]=resthair[bb].noisev[y]; //lasthair[bb].noisev[y]=resthair[bb].noisev[y]; //hair[bb].noisev[y]=resthair[bb].noisev[y]; } // else fp->pos+=4*9*15; } if( total_splines > 0 ) for( bb = 0; bb < total_splines; bb++ ) for( y = 0; y < 15; y++ ) { MYfread( &Slasthair[bb].hv[y].x, 4, 1, fp ); MYfread( &Slasthair[bb].hv[y].y, 4, 1, fp ); MYfread( &Slasthair[bb].hv[y].z, 4, 1, fp ); MYfread( &Sthishair[bb].hv[y].x, 4, 1, fp ); MYfread( &Sthishair[bb].hv[y].y, 4, 1, fp ); MYfread( &Sthishair[bb].hv[y].z, 4, 1, fp ); MYfread( &Shairvelocity[bb].hv[y].x, 4, 1, fp ); MYfread( &Shairvelocity[bb].hv[y].y, 4, 1, fp ); MYfread( &Shairvelocity[bb].hv[y].z, 4, 1, fp ); Sthishair[bb].noisev[y] = Sresthair[bb].noisev[y]; Slasthair[bb].noisev[y] = Sresthair[bb].noisev[y]; Shair[bb].noisev[y] = Sresthair[bb].noisev[y]; } } collect_guides( ); if( RW_CONTEXT == RW_RESIZE ) fp->size = fp->pos; for( x = 0; x < totalverts; x++ ) v[x] = hair[x].hv[0]; for (x=0;xpos = 0; if( RW_CONTEXT != RW_DISK ) { // state machine int bb; #ifdef DOUNICODE fp = ( MEMFILE * ) MYfopen( fp, L"w" ); #else fp = ( MEMFILE * ) MYfopen( fp, "w" ); #endif if( Dtotalverts > 0 ) { nodevers = 'b'; MYfwrite( &nodevers, 1, 1, fp ); nodevers = 'a'; MYfwrite( &nodevers, 1, 1, fp ); } for( bb = 0; bb < Dtotalverts; bb++ ) { MYfwrite( &Dv[bb].x, 4, 1, fp ); MYfwrite( &Dv[bb].y, 4, 1, fp ); MYfwrite( &Dv[bb].z, 4, 1, fp ); } if( totalverts > 0 ) for( bb = 0; bb < totalverts; bb++ ) { // if ((hair[bb].select[0])||(Gdynamics_mode!=0)) for( y = 0; y < 15; y++ ) { MYfwrite( &hair[bb].hv[y].x, 4, 1, fp ); MYfwrite( &hair[bb].hv[y].y, 4, 1, fp ); MYfwrite( &hair[bb].hv[y].z, 4, 1, fp ); MYfwrite( &hair[bb].lasthv[y].x, 4, 1, fp ); MYfwrite( &hair[bb].lasthv[y].y, 4, 1, fp ); MYfwrite( &hair[bb].lasthv[y].z, 4, 1, fp ); MYfwrite( &hair[bb].velocity[y].x, 4, 1, fp ); MYfwrite( &hair[bb].velocity[y].y, 4, 1, fp ); MYfwrite( &hair[bb].velocity[y].z, 4, 1, fp ); } // else fp->pos+=4*9*15; } if( total_splines > 0 ) for( bb = 0; bb < total_splines; bb++ ) { for( y = 0; y < 15; y++ ) { MYfwrite( &Slasthair[bb].hv[y].x, 4, 1, fp ); MYfwrite( &Slasthair[bb].hv[y].y, 4, 1, fp ); MYfwrite( &Slasthair[bb].hv[y].z, 4, 1, fp ); MYfwrite( &Sthishair[bb].hv[y].x, 4, 1, fp ); MYfwrite( &Sthishair[bb].hv[y].y, 4, 1, fp ); MYfwrite( &Sthishair[bb].hv[y].z, 4, 1, fp ); MYfwrite( &Shairvelocity[bb].hv[y].x, 4, 1, fp ); MYfwrite( &Shairvelocity[bb].hv[y].y, 4, 1, fp ); MYfwrite( &Shairvelocity[bb].hv[y].z, 4, 1, fp ); } } //MYfclose(fp); } if( RW_CONTEXT == RW_RESIZE ) fp->size = fp->pos; fp->time=gt; } void alloc_geom( FREEZETYPE * geom ) { geom->v = NULL; if( geom->totalverts > 0 ) { geom->uv = ( VERT * ) malloc( geom->totalverts * sizeof( VERT ) ); geom->vn = ( VERT * ) malloc( geom->totalverts * sizeof( VERT ) ); geom->facelist = ( int * ) malloc( geom->totalfverts * sizeof( int ) ); geom->colorlock = ( int * ) malloc( geom->totalfaces * sizeof( int ) ); geom->face_start = ( int * ) malloc( geom->totalfaces * sizeof( int ) ); geom->face_end = ( int * ) malloc( geom->totalfaces * sizeof( int ) ); geom->mtlgroup = ( int * ) malloc( geom->totalfaces * sizeof( int ) ); geom->envelope = ( ENVELOPETYPE * ) malloc( geom->totalverts * sizeof( ENVELOPETYPE ) ); geom->rvcolor = ( float * ) malloc( geom->totalverts * sizeof( float ) ); geom->gvcolor = ( float * ) malloc( geom->totalverts * sizeof( float ) ); geom->bvcolor = ( float * ) malloc( geom->totalverts * sizeof( float ) ); geom->Rrvcolor = ( float * ) malloc( geom->totalverts * sizeof( float ) ); geom->Rgvcolor = ( float * ) malloc( geom->totalverts * sizeof( float ) ); geom->Rbvcolor = ( float * ) malloc( geom->totalverts * sizeof( float ) ); if( geom->haircount > 0 ) //for (x=0;xhaircount;x++) if( 0 == 1 ) { geom->h = ( RENDERHAIR * ) malloc( geom->haircount * sizeof( RENDERHAIR ) ); } geom->velocity = ( VERT * ) malloc( geom->totalverts * sizeof( VERT ) ); geom->v = ( VERT * ) malloc( geom->totalverts * sizeof( VERT ) ); if( geom->totalverts > 0 ) if( geom->v == NULL ) { DRAW_STATUS( "Out of memory" ); Glow_mem = 1; free_geom( geom ); } } } void save_geomWF( WFTYPE * geom, CHNG *filename ) { int x, y; FILE *fp = NULL; RW_CONTEXT = RW_DISK; #ifdef DOUNICODE fp = fopen( filename, L"w" ); #else fp = fopen( filename, "w" ); #endif for( x = 0; x < geom->totalverts; x++ ) fprintf( fp, "v %f %f %f\n", geom->v[x].x, geom->v[x].y, geom->v[x].z ); for( x = 0; x < geom->totalfaces; x++ ) { fprintf( fp, "f " ); for( y = geom->face_start[x]; y < geom->face_end[x]; y++ ) { fprintf( fp, "%d ", geom->facelist[y] + 1 ); } fprintf( fp, "\n" ); } fclose( fp ); } void write_stack_object( CHNG *filename ) { int x, y; FILE *fp = NULL; RW_CONTEXT = RW_DISK; #ifdef DOUNICODE fp = fopen( filename, L"w" ); #else fp = fopen( filename, "w" ); #endif for( x = 0; x < totalverts; x++ ) fprintf( fp, "v %f %f %f\n", v[x].x, v[x].y, v[x].z ); for( x = 0; x < totalfaces; x++ ) { fprintf( fp, "f " ); for( y = face_start[x]; y < face_end[x]; y++ ) { fprintf( fp, "%d ", facelist[y] + 1 ); } fprintf( fp, "\n" ); } fclose( fp ); } void alloc_geomWF( WFTYPE * geom ) { int x; int tv, tfv, tf; tv = geom->totalverts; tfv = geom->totalfverts; tf = geom->totalfaces; //geom->v=(VERT *) malloc (geom->totalverts*sizeof(VERT)); if( tv > 0 ) { geom->alpha = ( float * ) malloc( tv * sizeof( float ) ); if (tv>tfv) geom->uv = ( VERT * ) malloc( tv * sizeof( VERT ) ); else geom->uv = ( VERT * ) malloc( tfv * sizeof( VERT ) ); geom->v = ( VERT * ) malloc( tv * sizeof( VERT ) ); geom->vn = ( VERT * ) malloc( tv * sizeof( VERT ) ); geom->color = ( VERT * ) malloc( tv * sizeof( VERT ) ); geom->velocity = ( VERT * ) malloc( tv * sizeof( VERT ) ); } else { geom->v = NULL; geom->uv = NULL; geom->color = NULL; geom->velocity = NULL; geom->vn = NULL; geom->alpha = NULL; } if( tf > 0 ) { geom->index = (int *) malloc (tf * sizeof (int)); geom->face_start = ( int * ) malloc( tf * sizeof( int ) ); geom->face_end = ( int * ) malloc( tf * sizeof( int ) ); geom->id = ( int * ) malloc( tf * sizeof( int ) ); geom->r1 = ( float * ) malloc( tf * sizeof( float ) ); geom->r2 = ( float * ) malloc( tf * sizeof( float ) ); //geom->mtlgroup=(int *) malloc (geom->totalfaces*sizeof(int)); } else { geom->face_start = NULL; geom->face_end = NULL; geom->id = NULL; geom->r1 = NULL; geom->r2= NULL; geom->index=NULL; } // if (geom->totalfverts>0) //else geom->facelist=NULL; if( tfv > 0 ) geom->facelist = ( int * ) malloc( tfv * sizeof( int ) ); else geom->facelist = NULL; if( geom->v != NULL ) for( x = 0; x < geom->totalverts; x++ ) { VERT zero; zero.x = 0.0f; zero.y = 0.0f; zero.z = 0.0f; geom->v[x] = zero; geom->velocity[x] = zero; geom->uv[x] = zero; geom->color[x] = zero; geom->vn[x] = zero; geom->alpha[x] = 1.0f; } if( geom->facelist != NULL ) for( x = 0; x < tfv; x++ ) geom->facelist[x] = 0; if( geom->face_start != NULL ) for( x = 0; x < tf; x++ ) { geom->index[x]=0; geom->face_start[x] = 0; geom->face_end[x] = 0; geom->id[x]=0; geom->r1[x]=0.0f; geom->r2[x]=0.0f; } if( geom->totalverts > 0 ) if( geom->v == NULL ) { Glow_mem = 1; DRAW_STATUS( "Out of memory" ); //printf ("ran out of memory allocating some geometry .. \n"); // fflush(stdout); free_geomWF( geom ); init_geomWF( geom ); } } void free_geom( FREEZETYPE * geom ) { // int x; // int y; // if( geom->totalverts > 0 ) { free( geom->uv ); free( geom->colorlock ); free( geom->face_start ); free( geom->face_end ); free( geom->facelist ); free( geom->mtlgroup ); free( geom->envelope ); free( geom->v ); free( geom->velocity ); free( geom->vn ); free( geom->rvcolor ); free( geom->gvcolor ); free( geom->bvcolor ); free( geom->Rrvcolor ); free( geom->Rgvcolor ); free( geom->Rbvcolor ); } { { if( geom->h ) free( geom->h ); } } geom->totalverts = 0; geom->haircount = 0; } void init_geomWF( WFTYPE * geom ) { geom->totalverts = 0; geom->totalfverts = 0; geom->totalfaces = 0; geom->index=NULL; geom->facelist = NULL; geom->face_start = NULL; geom->face_end = NULL; geom->facelist = NULL; geom->color = NULL; geom->v = NULL; geom->velocity = NULL; geom->uv = NULL; geom->vn = NULL; geom->alpha = NULL; geom->id = NULL; geom->r1 = NULL; geom->r2 = NULL; } void copy_geomWF( WFTYPE * dest, WFTYPE * source ) { int x; if( dest->v != NULL ) free_geomWF( dest ); dest->totalfaces = source->totalfaces; dest->totalverts = source->totalverts; dest->totalfverts = source->totalfverts; alloc_geomWF( dest ); for( x = 0; x < dest->totalverts; x++ ) { dest->alpha[x] = source->alpha[x]; dest->v[x] = source->v[x]; dest->uv[x] = source->uv[x]; dest->vn[x] = source->vn[x]; dest->color[x] = source->color[x]; dest->velocity[x] = source->velocity[x]; } for( x = 0; x < dest->totalfverts; x++ ) dest->facelist[x] = source->facelist[x]; for( x = 0; x < dest->totalfaces; x++ ) { dest->index[x]=source->index[x]; dest->face_start[x] = source->face_start[x]; dest->face_end[x] = source->face_end[x]; dest->id[x] = source->id[x]; dest->r1[x] = source->r1[x]; dest->r2[x] = source->r2[x]; } } void free_MEMFILE( MEMFILE * mf ) { if( mf->size > 0 ) { if( mf->data != NULL ) free( mf->data ); mf->data = NULL; mf->pos = 0; mf->size = 0; // mf->time = 0; } } void init_MEMFILE( MEMFILE * mf, long ID ) { mf->data = NULL; mf->pos = 0; mf->size = 0; mf->ID = ID; mf->time = 0; } void alloc_MEMFILE( MEMFILE * mf ) { int x; // if (mf->data!=NULL) mf->data = ( char * ) malloc( mf->size * sizeof( char ) ); for( x = 0; x < mf->size; x++ ) mf->data[x] = 0; } void copy_MEMFILE( MEMFILE * out, MEMFILE * in ) { int x; if( out->data != NULL ) { free( out->data ); out->data = NULL; } out->data = ( char * ) malloc( in->size * sizeof( char ) ); if( out->data != NULL ) if( in->data != NULL ) //for (x=0;xsize;x++) out->data[x]=in->data[x]; memcpy( out->data, in->data, in->size * sizeof( char ) ); out->size = in->size; out->pos = 0; out->time = in->time; //out->ID= you'll want to set this } void free_geomWF( WFTYPE * geom ) { // int x; // int y; // if( geom->v != NULL ) // if( geom->totalverts ) { { if (geom->alpha) free( geom->alpha ); if (geom->uv) free( geom->uv ); if (geom->vn) free( geom->vn ); if (geom->r1) free( geom->r1 ); if (geom->r2) free( geom->r2 ); //Nfree(geom->mtlgroup); if (geom->v) free( geom->v ); if (geom->velocity) free( geom->velocity ); if (geom->color) free( geom->color ); if (geom->index) free(geom->index); geom->alpha=NULL; geom->uv=NULL; geom->vn=NULL; geom->v=NULL; geom->velocity=NULL; geom->color=NULL; geom->r1=NULL; geom->r2=NULL; geom->index=NULL; } } /// if( geom->totalfaces ) { if (geom->face_start) free( geom->face_start ); geom->face_start=NULL; if (geom->face_end) free( geom->face_end ); geom->face_end=NULL; if (geom->id) free( geom->id ); geom->id=NULL; geom->index=NULL; } // if( geom->totalfverts ) { if (geom->facelist) free( geom->facelist ); geom->facelist=NULL; } geom->v = NULL; geom->alpha = NULL; geom->uv = NULL; geom->color = NULL; geom->velocity = NULL; geom->vn = NULL; geom->face_start = NULL; geom->face_end = NULL; geom->facelist = NULL; geom->r1=NULL; geom->r2=NULL; geom->id = NULL; geom->totalverts = 0; geom->totalfaces = 0; geom->totalfverts = 0; } void MAYAgetobj( CHNG *name, WFTYPE * wfdata ) { //0 int itsaspline = 0; FILE *fp = NULL; char *stat; int tuv = 0; char tmp[655]; char current_group_name[555]; // char tmpst[255]; int tf = 0, tl = 0; char statline[655]; int TMPtotalverts; int TMPtotalfverts; int TMPtotalfaces; int ttv = 0; TMPtotalverts = 0; TMPtotalfverts = 0; TMPtotalfaces = 0; RW_CONTEXT = RW_DISK; // sprintf( tmp, "%s", name ); /* printf ("name = %s\n",tmp); */ #ifdef DOUNICODE fp = ( FILE * ) MYfopen( name, L"r" ); #else fp = ( FILE * ) MYfopen( name, "r" ); #endif if( fp ) { // 1 if( wfdata->totalverts != 0 ) { free_geomWF( wfdata ); } wfdata->totalverts = 0; wfdata->totalfaces = 0; wfdata->totalfverts = 0; // stat=MYfgets(tmp,1255,fp); stat = "tmp"; // sprintf(stat,"start\n"); // while (stat!=NULL) while( stat != NULL ) { // char *tmp2; stat = MYfgets( tmp, 555, fp ); if( ( tmp[0] == 'v' ) && ( tmp[1] != 'n' ) && ( tmp[1] != 't' ) && ( tmp[1] != 'c' ) ) /* it's a vertex */ { wfdata->totalverts++; } if( tmp[0] == 'f' ) { int qq = 0; int sp = 0; wfdata->totalfaces++; // no we need to count fverts for( qq = 0; qq < ( int ) strlen( tmp ); qq++ ) if( tmp[qq] == 32 ) sp++; wfdata->totalfverts += sp + 2; } if( tmp[0] == 'l' ) { wfdata->totalfaces++; } } fclose( fp ); } // if (wfdata->totalverts<500) wfdata->totalverts=500; // if (wfdata->totalfaces<500) wfdata->totalfaces=500; wfdata->totalfverts = wfdata->totalfverts * 4; wfdata->totalfaces = wfdata->totalfverts; //wfdata->totalfverts+=100; //printf("wfdata.totalfverts = %d\n",wfdata->totalfverts); alloc_geomWF( wfdata ); wfdata->totalverts = 0; wfdata->totalfaces = 0; wfdata->totalfverts = 0; // sprintf( tmp, "%s", name ); /* printf ("name = %s\n",tmp); */ // sprintf( statline, "Loading %s.", name ); // DRAW_STATUS( statline ); #ifdef DOUNICODE fp = ( FILE * ) MYfopen( name, L"r" ); #else fp = ( FILE * ) MYfopen( name, "r" ); #endif // for (x=0;xv[wfdata->totalverts].x = atof( tmp2 ); } tmp2 = strtok( NULL, WHT ); if( tmp2 != NULL ) { wfdata->v[wfdata->totalverts].y = atof( tmp2 ); } tmp2 = strtok( NULL, WHT ); if( tmp2 != NULL ) { wfdata->v[wfdata->totalverts].z = atof( tmp2 ); } } wfdata->totalverts++; } /* surface grouping? */ if( tmp[0] == 'u' ) /* start a new group */ { char *tmp9; tmp9 = strtok( tmp, WHT ); tmp9 = strtok( NULL, WHT ); sprintf( current_group_name, "%s", tmp9 ); } if( ( tmp[0] == 'f' ) || ( tmp[0] == 'l' ) ) /* it's a face */ { char buf[1500] = "f -1/24/-3 \t49/5/6 \t7/8/9"; // char buf [100] = "f 1 2 3 4 5"; // char buf [100] = "f -11/99 2/88 3/77 4/66 5/33"; // char buf [100] = "f -11//99 2//88 3//77 4//66 5//33"; int tmpfl[500]; int tmpuv[500]; int tmpflc = 0; char *s; int i, slashCount, beenHereBefore = 0, x = 0; // int points [500]; // Max number of points in a face. // int uvs [500]; // Max number of UVs in a face. int normals[500]; // Max number of Normals in a face. int numVertex = 0; // Dface_start[Dtotalfaces]=Dtotalfverts; { int ii; for( ii = 0; ii < 500; ii++ ) tmpuv[ii] = 0; for( ii = 0; ii < 500; ii++ ) tmpfl[ii] = 0; } sprintf( buf, "%s", tmp ); /* Chew off the "f" */ strtok( buf, " \t" ); /* * Read junk until next SPACE character. Keep going until EOL. */ while( s = strtok( NULL, " \t\n" ) ) { /* * Count the number of Slashes in a vertex description. Do this only for the first vertex. */ if( !beenHereBefore ) { for( i = 0, slashCount = 0; i < ( int ) strlen( s ); i++ ) { if( s[i] == '/' ) slashCount++; } beenHereBefore = 1; } /* * The first number is always a vertex. (slashCount >= 0) */ // points [numVertex] = atoi (s); tmpfl[numVertex] = atoi( s ); tmpflc = numVertex; /* * We got one slash. Point and texture (U). */ if( slashCount == 1 ) { // char tmps[255]; while( *s != '/' ) s++; s++; // uvs[numVertex] = atoi (s); tmpuv[numVertex] = atoi( s ); } /* * We got 2 slashes. Point and texture (U) and Normal. */ if( slashCount == 2 ) { while( *s != '/' ) s++; s++; // uvs[numVertex] = atoi (s); tmpuv[numVertex] = atoi( s ); if( *s != '/' ) //uvs[numVertex] = atoi (s); tmpuv[numVertex] = atoi( s ); while( *s != '/' ) s++; s++; if( *s != '/' ) normals[numVertex] = atoi( s ); } tmpflc = numVertex; if( tmpfl[tmpflc] > 0 ) { tmpfl[tmpflc]--; } if( tmpuv[tmpflc] > 0 ) { tmpuv[tmpflc]--; } if( tmpfl[tmpflc] < 0 ) tmpfl[tmpflc] = Dtotalverts + tmpfl[tmpflc]; if( tmpuv[tmpflc] < 0 ) tmpuv[tmpflc] = ttv + tmpuv[tmpflc]; numVertex++; } tmpflc = numVertex; { itsaspline = 0; if( strcmp( current_group_name, "spline" ) == 0 ) { itsaspline = 1; } //+++ if( ( tmpflc == 3 ) || ( itsaspline ) ) { wfdata->face_start[wfdata->totalfaces] = wfdata->totalfverts; for( x = 0; x < tmpflc; x++ ) { wfdata->facelist[wfdata->totalfverts] = tmpfl[x]; wfdata->totalfverts++; } wfdata->face_end[wfdata->totalfaces] = wfdata->totalfverts; wfdata->totalfaces++; /* totalfverts++; */ } // #ifdef dowereallywanttotriangulate if( ( tmpflc > 3 ) && ( !itsaspline ) ) { // int qq, int aa; for( aa = 1; aa < tmpflc - 1; aa++ ) { int q1, q2, q3; q1 = 0; q2 = aa; if( q2 >= tmpflc ) q2 -= tmpflc; q3 = aa + 1; if( q3 >= tmpflc ) q3 -= tmpflc; wfdata->face_start[wfdata->totalfaces] = wfdata->totalfverts; wfdata->facelist[wfdata->totalfverts] = tmpfl[q1]; wfdata->totalfverts++; wfdata->facelist[wfdata->totalfverts] = tmpfl[q2]; wfdata->totalfverts++; wfdata->facelist[wfdata->totalfverts] = tmpfl[q3]; wfdata->totalfverts++; wfdata->face_end[wfdata->totalfaces] = wfdata->totalfverts; wfdata->totalfaces++; } /* totalfverts++; */ } // #endif } } } } if( fp ) fclose( fp ); } static void scanobj( CHNG *name ) /* load neutral model */ { //0 FILE *fp = NULL; int old_totalverts; int Dold_totalverts; char *stat; int tuv = 0; // CHNG tmp[1555]; CHNG tmpname[1555]; char tmp[1555]; char tmpst[1555]; int x, y, tf = 0, tl = 0; char statline[255]; int current_total = 0; current_group = -1; //current_group=0; totalgroups = 0; Dold_totalverts = Dtotalverts; old_totalverts = totalverts; if( old_totalverts == 0 ) old_totalverts = -1; totalverts = 0; current_total = 0; totalfverts = 0; totalfaces = 0; totalverts = 0; current_total = 0; totalfverts = 0; totalfaces = 0; Dtotallines = 0; Dtotalverts = 0; Dtotalfverts = 0; Dtotalfaces = 0; Dtotalverts = 0; Dtotalfverts = 0; Dtotalfaces = 0; Dtotalfaces = 0; Dtotalverts = 0; Dtotalfverts = 0; Duvtotalfverts = 0; totalgroups = 0; DUTtotalfverts = 0; DUTtotalfaces = 0; total_splines = 0; freeze_texl = 1; freeze_texg = 0; // global if( freeze.textoggle ) { freeze.textoggle = 1; //local freeze_texl = 0; freeze_texg = 1; } //fp = ( FILE * ) MYfopen( name, L"r" ); #ifdef DOUNICODE swprintf( tmpname, L"%s", name ); fp = ( FILE * ) MYfopen( tmpname, L"r" ); #else sprintf( tmpname, "%s", name ); fp = ( FILE * ) MYfopen( tmpname, "r" ); #endif //////////////////// // fp=fopen(tmp,"r"); if( fp == NULL ) { int aa; DRAW_STATUS( "Can't open File!" ); for( x = 0; x < 100; x++ ) { aa = ( int ) cos( x ); } } if( fp == NULL ) { int aa; DRAW_STATUS( "Can't open File!" ); for( x = 0; x < 100; x++ ) { aa = ( int ) cos( x ); } } if( fp != NULL ) { // 1 stat = MYfgets( tmp, 1255, fp ); sprintf( statline, "Loading %s.", name ); DRAW_STATUS( statline ); //sprintf( tmp, "%s", name ); no need /* printf ("name = %s\n",tmp); */ sprintf( statline, "Loading %s.", name ); DRAW_STATUS( statline ); // fp=MYfopen(tmp,"r"); // fp=(FILE *)MYfopen(tmp,"r"); // fp=fopen(tmp,"r"); if( fp == NULL ) { DRAW_STATUS( "couldn't open obj file!\n" ); //for (x=0;x<100000;x++) { float aa; aa=cos(x);} //printf ("couldn't open obj file\n"); } // for (x=0;x new group :", tmp9 ); DRAW_STATUS( statline ); // Sleep(2000); } if( gpexist( tmp9 ) != -1 ) { current_group = gpexist( tmp9 ); } /* printf ("current group = %d\n",current_group); */ } } if( current_group >= 0 ) if( tmp[0] == 'f' ) /* it's a face */ { char buf[1500] = "f -1/24/-3 \t49/5/6 \t7/8/9"; // char buf [100] = "f 1 2 3 4 5"; // char buf [100] = "f -11/99 2/88 3/77 4/66 5/33"; // char buf [100] = "f -11//99 2//88 3//77 4//66 5//33"; int tmpfl[500]; int tmpuv[500]; int tmpflc = 0; char *s; int i, slashCount, beenHereBefore = 0, x = 0; // int points [500]; // Max number of points in a face. // int uvs [500]; // Max number of UVs in a face. int normals[500]; // Max number of Normals in a face. int numVertex = 0; // Dface_start[Dtotalfaces]=Dtotalfverts; { int ii; for( ii = 0; ii < 500; ii++ ) tmpuv[ii] = 0; for( ii = 0; ii < 500; ii++ ) tmpfl[ii] = 0; } sprintf( buf, "%s", tmp ); /* Chew off the "f" */ strtok( buf, " \t" ); /* * Read junk until next SPACE character. Keep going until EOL. */ while( s = strtok( NULL, " \t\n" ) ) { /* * Count the number of Slashes in a vertex description. Do this only for the first vertex. */ if( !beenHereBefore ) { for( i = 0, slashCount = 0; i < ( int ) strlen( s ); i++ ) { if( s[i] == '/' ) slashCount++; } beenHereBefore = 1; } /* * The first number is always a vertex. (slashCount >= 0) */ // points [numVertex] = atoi (s); tmpfl[numVertex] = atoi( s ); tmpflc = numVertex; /* * We got one slash. Point and texture (U). */ if( slashCount == 1 ) { // char tmps[255]; while( *s != '/' ) s++; s++; // uvs[numVertex] = atoi (s); tmpuv[numVertex] = atoi( s ); } /* * We got 2 slashes. Point and texture (U) and Normal. */ if( slashCount == 2 ) { while( *s != '/' ) s++; s++; // uvs[numVertex] = atoi (s); tmpuv[numVertex] = atoi( s ); if( *s != '/' ) //uvs[numVertex] = atoi (s); tmpuv[numVertex] = atoi( s ); while( *s != '/' ) s++; s++; if( *s != '/' ) normals[numVertex] = atoi( s ); } tmpflc = numVertex; if( tmpfl[tmpflc] > 0 ) { tmpfl[tmpflc]--; } if( tmpuv[tmpflc] > 0 ) { tmpuv[tmpflc]--; } if( tmpfl[tmpflc] < 0 ) tmpfl[tmpflc] = Dtotalverts + tmpfl[tmpflc]; if( tmpuv[tmpflc] < 0 ) tmpuv[tmpflc] = ttv + tmpuv[tmpflc]; numVertex++; } tmpflc = numVertex; sprintf( tmpst, "%06s", group_names[current_group] ); if( strcmp( "spline", tmpst ) != 0 ) // (group_names[current_group][0]!='s')&& // (group_names[current_group][1]!='p')&& // (group_names[current_group][2]!='l')&& // (group_names[current_group][3]!='i')&& // (group_names[current_group][4]!='n') // ) { if( tmpflc >= 3 ) { for( x = 2; x >= 0; x-- ) { Dtotalfverts++; Duvtotalfverts++; } Dtotalfaces++; } /* totalfverts++; */ if( tmpflc > 3 ) { int xx; for( x = 2; x < tmpflc - 1; x++ ) { Dtotalfverts++; Dtotalfverts++; Dtotalfverts++; Duvtotalfverts++; Duvtotalfverts++; Duvtotalfverts++; Dtotalfaces++; } } // // now lets add the untriangulated face for( x = 0; x < tmpflc; x++ ) { DUTtotalfverts++; } DUTtotalfaces++; } //if (0==1) else // it's a spline if( tmpflc > 2 ) { int zz; int xx; DRAW_STATUS( "spline" ); // for (xx=0;xx<1000000;xx++) zz=(int)cos(xx); for( zz = 0; zz < tmpflc; zz++ ) { Dtotalfverts++; DUTtotalfverts++; } Dtotalfaces++; DUTtotalfaces++; } // its a spline } if( current_group >= 0 ) if( tmp[0] == 'l' ) /* it's a line */ { char buf[1500] = "f -1/24/-3 \t49/5/6 \t7/8/9"; // char buf [100] = "f 1 2 3 4 5"; // char buf [100] = "f -11/99 2/88 3/77 4/66 5/33"; // char buf [100] = "f -11//99 2//88 3//77 4//66 5//33"; int tmpfl[500]; int tmpuv[500]; int tmpflc = 0; char *s; int i, slashCount, beenHereBefore = 0, x = 0; // int points [500]; // Max number of points in a face. // int uvs [500]; // Max number of UVs in a face. int normals[500]; // Max number of Normals in a face. int numVertex = 0; // Dface_start[Dtotalfaces]=Dtotalfverts; { int ii; for( ii = 0; ii < 500; ii++ ) tmpuv[ii] = 0; for( ii = 0; ii < 500; ii++ ) tmpfl[ii] = 0; } sprintf( buf, "%s", tmp ); /* Chew off the "f" */ strtok( buf, " \t" ); /* * Read junk until next SPACE character. Keep going until EOL. */ while( s = strtok( NULL, " \t\n" ) ) { /* * Count the number of Slashes in a vertex description. Do this only for the first vertex. */ if( !beenHereBefore ) { for( i = 0, slashCount = 0; i < ( int ) strlen( s ); i++ ) { if( s[i] == '/' ) slashCount++; } beenHereBefore = 1; } /* * The first number is always a vertex. (slashCount >= 0) */ // points [numVertex] = atoi (s); tmpfl[numVertex] = atoi( s ); tmpflc = numVertex; /* * We got one slash. Point and texture (U). */ if( slashCount == 1 ) { // char tmps[255]; while( *s != '/' ) s++; s++; // uvs[numVertex] = atoi (s); tmpuv[numVertex] = atoi( s ); } /* * We got 2 slashes. Point and texture (U) and Normal. */ if( slashCount == 2 ) { while( *s != '/' ) s++; s++; // uvs[numVertex] = atoi (s); tmpuv[numVertex] = atoi( s ); if( *s != '/' ) //uvs[numVertex] = atoi (s); tmpuv[numVertex] = atoi( s ); while( *s != '/' ) s++; s++; if( *s != '/' ) normals[numVertex] = atoi( s ); } tmpflc = numVertex; if( tmpfl[tmpflc] > 0 ) { tmpfl[tmpflc]--; } if( tmpuv[tmpflc] > 0 ) { tmpuv[tmpflc]--; } if( tmpfl[tmpflc] < 0 ) tmpfl[tmpflc] = Dtotalverts + tmpfl[tmpflc]; if( tmpuv[tmpflc] < 0 ) tmpuv[tmpflc] = ttv + tmpuv[tmpflc]; numVertex++; } tmpflc = numVertex; sprintf( tmpst, "%06s", group_names[current_group] ); // if (strcmp(tmp,"spline")==0) if( tmpflc > 1 ) // more than 2 sides for( x = 0; x < tmpflc - 1; x += 2 ) { Dtotallines++; } } } /* printf ("totalverts = %d totalfaces = %d totalfverts = %d\n",totalverts,totalfaces,totalfverts); */ // sprintf (statline,"totalverts = %d totalfaces = %d totalfverts = %d version %c",Dtotalverts,Dtotalfaces,Dtotalfverts,shaveversion); // DRAW_STATUS(statline); // fclose(fp); } MYfclose( fp ); } } static void collect_guides( void ) { int x, y, z; totalguides = 0; //#ifdef SOFTIMAGE for( x = 0; x < totalverts; x++ ) { if( ( ( hair[x].mtl == head ) && ( head >= 0 ) ) || ( ( hair[x].mtl == beard ) && ( beard >= 0 ) ) || ( ( hair[x].mtl == eyebrow ) && ( eyebrow >= 0 ) ) || ( ( hair[x].mtl == eyelash ) && ( eyelash >= 0 ) ) ) { vert2guide[x] = totalguides; guide2vert[totalguides] = x; totalguides++; } } for( x = 0; x < total_splines; x++ ) { { vert2guide[x] = totalguides; guide2vert[totalguides] = x; totalguides++; } } //#endif } static void read_hairFAST2( void *fname ) { int x, y; for( x = 0; x < Dtotalverts; x++ ) Dv[x] = Drv[x]; for( x = 0; x < totalverts; x++ ) { for( y = 0; y < 15; y++ ) { hair[x].hv[y] = hair[x].resthv[y]; hair[x].lasthv[y] = hair[x].hv[y]; // thishair[x].hv[y]=resthair[x].hv[y]; hair[x].noisev[y] = hair[x].hv[y]; // resthair[x].noisev[y]=hair[x].hv[y]; } v[x] = hair[x].hv[0]; } init_noise( ); collect_guides( ); reset_dynamics( ); // ??? } static void write_hairFAST( MEMFILE * fname ) { //char tmp[255]; //int tmpi; //float tmpf; MEMFILE *fp = NULL; int x, y; int isit = 0; int shaveversion2 = 0; int tmpmetanurb; tmpmetanurb = GMetaNurb; if( GMetaNurb > 0 ) metaunfixchains( ); //if (RW_CONTEXT!=RW_DISK) fname=(MEMFILE *) fname; //if (RW_CONTEXT==RW_DISK) fname=(char *) fname; //if (RW_CONTEXT==RW_DISK) reset_noisespace(); // for skulls f (totalverts>0) if( totalverts > 0 ) if( Dtotalverts > 0 ) { #ifdef DOUNICODE fp = (MEMFILE*)MYfopen( fname, L"wb" ); #else fp = (MEMFILE*)MYfopen( fname, "wb" ); #endif } // for skulls if (totalverts>0) // if (slcheck()) if( totalverts > 0 ) if( Dtotalverts > 0 ) { { char v1, v2, v3; v1 = 'z'; v2 = 'y'; #ifndef EXTERNAL_COLLISION v3 = 'm'; #endif #ifdef EXTERNAL_COLLISION v3 = 'm'; #endif shaveversion2 = v3; #ifdef onethree MYfwrite( &v1, 1, 1, fp ); MYfwrite( &v2, 1, 1, fp ); #endif //if (shaveversion2>='g') if( v2 == 'y' ) MYfwrite( &v3, 1, 1, fp ); { int qq; char dum = 0; #ifdef MAX3D // for (qq=0;qq<100;qq++) // MYfwrite (&dum,1,1,fp); #endif // if (RW_CONTEXT==RW_DISK) // if (MAXMODE==1) // { // for (qq=0;qq<100;qq++) // MYfwrite (&dum,1,1,fp); // } } MYfwrite( &Dtotalverts, 4, 1, fp ); MYfwrite( &Dtotalfaces, 4, 1, fp ); MYfwrite( &Dtotalfverts, 4, 1, fp ); // MYfwrite(&Dtotallines,4,1,fp); /// as of version k } if( shaveversion2 <= 'k' ) for( x = 0; x < Dtotalverts; x++ ) { int bb; MYfwrite( &Dvertgroup[x], 4, 1, fp ); if( Dtag[x] == 1 ) { int bb; bb = Dlink[x]; MYfwrite( &hair[bb].splitgroup, 4, 1, fp ); MYfwrite( &hair[bb].splitmerge, 4, 1, fp ); } if( Dtag[x] != 1 ) { int junki; junki = 0; MYfwrite( &junki, 4, 1, fp ); // splitgroup fake MYfwrite( &junki, 4, 1, fp ); // splitgroup fake } for( y = 0; y < 15; y++ ) { if( Dtag[x] ) { bb = Dlink[x]; // if (y>0) { MYfwrite( &hair[bb].resthv[y].x, 4, 1, fp ); MYfwrite( &hair[bb].resthv[y].y, 4, 1, fp ); MYfwrite( &hair[bb].resthv[y].z, 4, 1, fp ); } // if (y==0) // { // MYfwrite(&Dv[x].x,4,1,fp); // MYfwrite(&Dv[x].y,4,1,fp); // MYfwrite(&Dv[x].z,4,1,fp); // } #ifdef onethree MYfwrite( &hair[bb].pfID[y], 4, 1, fp ); #endif } // dtag if( ( Dtag[x] == 0 ) ) { int aa = -1; MYfwrite( &Dv[x].x, 4, 1, fp ); MYfwrite( &Dv[x].y, 4, 1, fp ); MYfwrite( &Dv[x].z, 4, 1, fp ); #ifdef onethree MYfwrite( &aa, 4, 1, fp ); #endif } } //y } //x if( shaveversion2 >= 'l' ) { if( totalverts > 0 ) for( x = 0; x < Dtotalverts; x++ ) { int bb; MYfwrite( &Dvertgroup[x], 4, 1, fp ); MYfwrite( &Dtag[x], 4, 1, fp ); MYfwrite( &Dlink[x], 4, 1, fp ); MYfwrite( &Drv[x].x, 4, 1, fp ); MYfwrite( &Drv[x].y, 4, 1, fp ); MYfwrite( &Drv[x].z, 4, 1, fp ); if( Dtag[x] == 1 ) { int bb; bb = Dlink[x]; MYfwrite( &hair[bb].mtl, 4, 1, fp ); vertgroup[bb] = hair[bb].mtl; hair[bb].slgroup = vertgroup[bb]; MYfwrite( &hair[bb].splitgroup, 4, 1, fp ); MYfwrite( &hair[bb].splitmerge, 4, 1, fp ); for( y = 0; y < 15; y++ ) { bb = Dlink[x]; { MYfwrite( &hair[bb].resthv[y].x, 4, 1, fp ); MYfwrite( &hair[bb].resthv[y].y, 4, 1, fp ); MYfwrite( &hair[bb].resthv[y].z, 4, 1, fp ); } MYfwrite( &hair[bb].pfID[y], 4, 1, fp ); } } } //x } for( x = 0; x < Dtotalfverts; x++ ) { MYfwrite( &Dfacelist[x], 4, 1, fp ); } for( x = 0; x < Dtotalfaces; x++ ) { MYfwrite( &Dmtlgroup[x], 4, 1, fp ); MYfwrite( &Dface_start[x], 4, 1, fp ); MYfwrite( &Dface_end[x], 4, 1, fp ); } for( y = 0; y < 5; y++ ) for( x = 0; x < 22; x++ ) { MYfwrite( &sliders[x][y].value, 4, 1, fp ); } { int junk; MYfwrite( &junk, 4, 1, fp ); // passes - OBSOLETE MYfwrite( &junk, 4, 1, fp ); // HAIRCOUNT - OBSOLETE } for( x = 0; x < 5; x++ ) { int l; l = strlen( colmap[x].name ); MYfwrite( &l, 4, 1, fp ); MYfwrite( &colmap[x].name, l, 1, fp ); MYfwrite( &colmap[x].flags, 4, 1, fp ); } for( x = 0; x < 5; x++ ) { int l; l = strlen( densemap[x].name ); MYfwrite( &l, 4, 1, fp ); MYfwrite( &densemap[x].name, l, 1, fp ); // if (isit) MYfwrite( &densemap[x].flags, 4, 1, fp ); } for( x = 0; x < 5; x++ ) { int l; l = strlen( lenmap[x].name ); MYfwrite( &l, 4, 1, fp ); MYfwrite( &lenmap[x].name, l, 1, fp ); // if (isit) MYfwrite( &lenmap[x].flags, 4, 1, fp ); } MYfwrite( &totalgroups, 4, 1, fp ); { // FILE *dgg; // dgg=MYfopen("surfnames.txt","w"); for( x = 0; x < totalgroups; x++ ) { int l; int xx; l = strlen( group_names[x] ); // fprintf (dgg,"%d %d %s\n",x,l,group_names[x]); MYfwrite( &l, 4, 1, fp ); for( xx = 0; xx < l; xx++ ) MYfwrite( &group_names[x][xx], 1, 1, fp ); } // MYfclose(dgg); } //#ifdef thisit // mkbounds(); // weight_polys(); // texture_bounds(); //#endif // fp=MYfopen(fname,"wb"); MYfwrite( &freeze.totalverts, 4, 1, fp ); MYfwrite( &freeze.totalfaces, 4, 1, fp ); MYfwrite( &freeze.totalfverts, 4, 1, fp ); if( freeze.totalverts > 0 ) { for( x = 0; x < freeze.totalverts; x++ ) { // int r,g,b; // int flag; MYfwrite( &freeze.v[x].x, 4, 1, fp ); MYfwrite( &freeze.v[x].y, 4, 1, fp ); MYfwrite( &freeze.v[x].z, 4, 1, fp ); MYfwrite( &freeze.Rrvcolor[x], 4, 1, fp ); MYfwrite( &freeze.Rgvcolor[x], 4, 1, fp ); MYfwrite( &freeze.Rbvcolor[x], 4, 1, fp ); } for( x = 0; x < freeze.totalfverts; x++ ) { MYfwrite( &freeze.facelist[x], 4, 1, fp ); } for( x = 0; x < freeze.totalfaces; x++ ) { int cll; MYfwrite( &freeze.mtlgroup[x], 4, 1, fp ); MYfwrite( &freeze.face_start[x], 4, 1, fp ); MYfwrite( &freeze.face_end[x], 4, 1, fp ); cll = 0; if( freeze.colorlock[x] >= 0 ) cll = 1; MYfwrite( &cll, 4, 1, fp ); } MYfwrite( &freeze.textoggle, 4, 1, fp ); } for( y = 0; y < 5; y++ ) for( x = 22; x < 24; x++ ) // wiggles { MYfwrite( &sliders[x][y].value, 4, 1, fp ); } { int ti; int total_sliders = 30; MYfwrite( &total_sliders, 4, 1, fp ); // total sliders for( x = 0; x < total_sliders; x++ ) { // ti = sliders[x][0].paint; ti=1; MYfwrite( &ti, 4, 1, fp ); // empty/full ? if( ti > 0 ) for( y = 0; y < totalverts; y++ ) { MYfwrite( &hair[y].slider[x], 4, 1, fp ); // slider contents } } } for( y = 0; y < 5; y++ ) for( x = 0; x < 30; x++ ) { MYfwrite( &sliders[x][y].value, 4, 1, fp ); } for( y = 0; y < 5; y++ ) { MYfwrite( &LOCAL_PASSES[y], 4, 1, fp ); MYfwrite( &LOCAL_CNT[y], 4, 1, fp ); } // version j for( x = 0; x < total_splines; x++ ) for( y = 0; y < 15; y++ ) MYfwrite( &Shair[x].pfID[y], 4, 1, fp ); for( x = 0; x < total_splines; x++ ) { MYfwrite( &Shair[x].splitgroup, 4, 1, fp ); MYfwrite( &Shair[x].splitmerge, 4, 1, fp ); } for( y = 0; y < 5; y++ ) // make a nice clean write of all the sliders for( x = 0; x < 30; x++ ) { // float junkf; MYfwrite( &sliders[x][y].value, 4, 1, fp ); } // gravity MYfwrite( &sliders[0][5].value, 4, 1, fp ); //if (v2=='l') // version m for( x = 0; x < Dtotalverts; x++ ) { int junki = 1; MYfwrite( &junki, 4, 1, fp ); // MYfwrite(&D2UTface_link[x],4,1,fp); } // version n // MYfwrite(&GMetaNurb,4,1,fp); MYfwrite( &DUTtotalfaces, 4, 1, fp ); MYfwrite( &DUTtotalfverts, 4, 1, fp ); for( x = 0; x < DUTtotalfverts; x++ ) { MYfwrite( &DUTfacelist[x], 4, 1, fp ); } for( x = 0; x < DUTtotalfaces; x++ ) { MYfwrite( &DUTface_start[x], 4, 1, fp ); MYfwrite( &DUTface_end[x], 4, 1, fp ); } // version O if( totalverts > 0 ) for( x = 0; x < totalverts; x++ ) { for( y = 0; y < 15; y++ ) MYfwrite( &hair[x].select[y], 4, 1, fp ); } if( 0 == 1 ) if( Stotalverts > 0 ) for( x = 0; x < Stotalverts; x++ ) { for( y = 0; y < 15; y++ ) MYfwrite( &Shair[x].select[y], 4, 1, fp ); } // version P for( y = 0; y < 5; y++ ) // we've got some new sliders here for( x = 30; x < 40; x++ ) { // float junkf; MYfwrite( &sliders[x][y].value, 4, 1, fp ); } { int ti; int total_sliders = 40; MYfwrite( &total_sliders, 4, 1, fp ); // total sliders for( x = 30; x < total_sliders; x++ ) { // ti = sliders[x][0].paint; ti=1; MYfwrite( &ti, 4, 1, fp ); // empty/full ? if( ti > 0 ) for( y = 0; y < totalverts; y++ ) { MYfwrite( &hair[y].slider[x], 4, 1, fp ); // slider contents } } } // version q for( y = 0; y < 5; y++ ) // we've got some new sliders here { // float junkf; MYfwrite( &Ganim_dir[y].x, 4, 1, fp ); MYfwrite( &Ganim_dir[y].y, 4, 1, fp ); MYfwrite( &Ganim_dir[y].z, 4, 1, fp ); } // version r for( y = 0; y < totalfaces; y++ ) // we've got some new sliders here { MYfwrite( &face_link[y], 4, 1, fp ); } for( x = 0; x < Dtotalfaces; x++ ) { MYfwrite( &D2UTface_link[x], 4, 1, fp ); } // version s for( y = 0; y < 5; y++ ) // we've got some new sliders here { MYfwrite( &Gsurface_collide[y], 4, 1, fp ); } // version t // for (y=0;y<5;y++) // we've got some new sliders here { MYfwrite( &COLLISION_METHOD, 4, 1, fp ); } // version u if( total_splines > 0 ) for( x = 0; x < total_splines; x++ ) { for( y = 0; y < 15; y++ ) MYfwrite( &Shair[x].select[y], 4, 1, fp ); } // version v for( y = 0; y < 5; y++ ) { MYfwrite( &LOCAL_SEGS[y], 4, 1, fp ); } //if (shaveversion>='x') { int xx; for( xx = 0; xx < totalverts; xx++ ) { MYfwrite( &hair[xx].uu, 4, 1, fp ); MYfwrite( &hair[xx].vv, 4, 1, fp ); } for( xx = 0; xx < total_splines; xx++ ) { MYfwrite( &Sresthair[xx].uu, 4, 1, fp ); MYfwrite( &Sresthair[xx].vv, 4, 1, fp ); } } //if (shaveversion2>='a') { int xx, y; for( xx = 0; xx < totalverts; xx++ ) for( y = 0; y < 15; y++ ) { MYfwrite( &hair[xx].noisev[y].x, 4, 1, fp ); MYfwrite( &hair[xx].noisev[y].y, 4, 1, fp ); MYfwrite( &hair[xx].noisev[y].z, 4, 1, fp ); } for( xx = 0; xx < total_splines; xx++ ) for( y = 0; y < 15; y++ ) { MYfwrite( &Sresthair[xx].noisev[y].x, 4, 1, fp ); MYfwrite( &Sresthair[xx].noisev[y].y, 4, 1, fp ); MYfwrite( &Sresthair[xx].noisev[y].z, 4, 1, fp ); } } //if (shaveversion2>='e') { for( y = 0; y < 5; y++ ) for( x = 40; x < 41; x++ ) { MYfwrite( &sliders[x][y].value, 4, 1, fp ); } } //if (shaveversion2>='f') { for( y = 0; y < 5; y++ ) for( x = 41; x < 45; x++ ) { MYfwrite( &sliders[x][y].value, 4, 1, fp ); } } //if (shaveversion3>='h') for( y = 0; y < 5; y++ ) { MYfwrite( &LOCAL_SHADCNT[y], 4, 1, fp ); } //if (shaveversion3>='h') // MYfwrite(&Gbacklighting,4,1,fp); //if (shaveversion3>='i') { MYfwrite( &Guv_totalsets, 4, 1, fp ); for( x = 0; x < Guv_totalsets; x++ ) { MYfwrite( &Guv_sets[x].totalverts, 4, 1, fp ); MYfwrite( &Guv_sets[x].totalfverts, 4, 1, fp ); MYfwrite( &Guv_sets[x].totalfaces, 4, 1, fp ); for( y = 0; y < Guv_sets[x].totalverts; y++ ) { MYfwrite( &Guv_sets[x].v[y].x, 4, 1, fp ); MYfwrite( &Guv_sets[x].v[y].y, 4, 1, fp ); MYfwrite( &Guv_sets[x].v[y].z, 4, 1, fp ); } for( y = 0; y < Guv_sets[x].totalfverts; y++ ) MYfwrite( &Guv_sets[x].facelist[y], 4, 1, fp ); for( y = 0; y < Guv_sets[x].totalfaces; y++ ) { MYfwrite( &Guv_sets[x].face_start[y], 4, 1, fp ); MYfwrite( &Guv_sets[x].face_end[y], 4, 1, fp ); } } } //if (shaveversion3>='j') for( x = 0; x < 45; x++ ) MYfwrite( &x, 4, 1, fp ); //if (shaveversion3>='k') { int xx, y; for( xx = 0; xx < totalverts; xx++ ) MYfwrite( &hair[xx].restlength, 4, 1, fp ); for( xx = 0; xx < total_splines; xx++ ) { MYfwrite( &Sresthair[xx].restlength, 4, 1, fp ); } } //if (shaveversion3>='m') { int vers = 0; vers = 1; // softimage #ifdef MAYA3D vers = 2; #endif #ifdef MAX3D vers = 3; #endif #ifdef C4D vers = 4; #endif MYfwrite( &vers, 4, 1, fp ); } if( Dtotalverts > 0 ) MYfclose( fp ); } if( Dtotalverts == 0 ) DRAW_STATUS( "Didn't save, workspace is EMPTY!" ); GMetaNurb = tmpmetanurb; if( tmpmetanurb > 0 ) metanurb( tmpmetanurb ); // collect_guides(); } static void read_hairFAST( MEMFILE * fname ) { //char tmp[255]; //int tmpi; //float tmpf; MEMFILE *fp; int x, y; int huh = 0; int xx = 0; int BADFILE = 0; char shaveversion2; shaveversion2 = 'a'; if( totalverts > 0 ) if( Dtotalverts > 0 ) { fp = ( MEMFILE * ) MYfopen( fname, "rb" ); ///dg=MYfopen("zzz.txt","w"); if( fp ) { int junki; float junkf; // char junkc; totalsplits = 1; if( ( shaveversion >= 'a' ) ) { char junkc; // MYfread(&junkc,1,1,fp); // MYfread(&junkc,1,1,fp); // if (junkc>='y') // MYfread(&junkc,1,1,fp); MYfread( &shaveversion, 1, 1, fp ); if( shaveversion != 'z' ) BADFILE = 1; MYfread( &shaveversion, 1, 1, fp ); if( shaveversion == 'y' ) #ifndef EXTERNAL_COLLISION MYfread( &shaveversion2, 1, 1, fp ); if( shaveversion2 > 'm' ) BADFILE = 1; #endif #ifdef EXTERNAL_COLLISION MYfread( &shaveversion2, 1, 1, fp ); if( shaveversion2 > 'm' ) BADFILE = 1; #endif //if (junkc>='g') if( shaveversion2 >= 'g' ) // don't increment this { int qq; char dum; #ifdef MAX3D // for (qq=0;qq<100;qq++) // MYfread (&dum,1,1,fp); #endif } } MYfread( &junki, 4, 1, fp ); MYfread( &junki, 4, 1, fp ); MYfread( &junki, 4, 1, fp ); //if (shaveversion>='k'); // MYfread(&junki,4,1,fp); // totallines // printf("totalverts %d\n",totalverts); if( shaveversion2 >= 'l' ) { if( totalverts > 0 ) for( x = 0; x < Dtotalverts; x++ ) { int bb; MYfread( &Dvertgroup[x], 4, 1, fp ); MYfread( &Dtag[x], 4, 1, fp ); MYfread( &Dlink[x], 4, 1, fp ); MYfread( &Drv[x].x, 4, 1, fp ); MYfread( &Drv[x].y, 4, 1, fp ); MYfread( &Drv[x].z, 4, 1, fp ); Dv[x] = Drv[x]; if( Dtag[x] == 1 ) { int bb; bb = Dlink[x]; MYfread( &hair[bb].mtl, 4, 1, fp ); vertgroup[bb] = hair[bb].mtl; hair[bb].slgroup = vertgroup[bb]; MYfread( &hair[bb].splitgroup, 4, 1, fp ); MYfread( &hair[bb].splitmerge, 4, 1, fp ); for( y = 0; y < 15; y++ ) { bb = Dlink[x]; { MYfread( &hair[bb].resthv[y].x, 4, 1, fp ); MYfread( &hair[bb].resthv[y].y, 4, 1, fp ); MYfread( &hair[bb].resthv[y].z, 4, 1, fp ); } //hair[bb].noisev[y]=hair[bb].resthv[y]; hair[bb].hv[y] = hair[bb].resthv[y]; MYfread( &hair[bb].pfID[y], 4, 1, fp ); } v[bb] = hair[bb].resthv[0]; neutral[Dlink[x]] = v[Dlink[x]]; } } //x } if( shaveversion2 < 'l' ) { for( x = 0; x < Dtotalverts; x++ ) { if( Dtag[x] ) { int bb; bb = Dlink[x]; MYfread( &hair[bb].mtl, 4, 1, fp ); vertgroup[bb] = hair[bb].mtl; hair[bb].slgroup = vertgroup[bb]; if( shaveversion >= 'd' ) { MYfread( &hair[bb].splitgroup, 4, 1, fp ); MYfread( &hair[bb].splitmerge, 4, 1, fp ); if( ( hair[bb].splitgroup + 1 ) > totalsplits ) totalsplits = hair[bb].splitgroup + 1; } for( y = 0; y < 15; y++ ) { MYfread( &hair[bb].resthv[y].x, 4, 1, fp ); MYfread( &hair[bb].resthv[y].y, 4, 1, fp ); MYfread( &hair[bb].resthv[y].z, 4, 1, fp ); if( shaveversion >= 'a' ) MYfread( &hair[bb].pfID[y], 4, 1, fp ); hair[bb].hv[y] = hair[bb].resthv[y]; //hair[bb].noisev[y]=hair[bb].hv[y]; } if( shaveversion < 'd' ) { totalsplits = 1; hair[bb].splitmerge = 0; hair[bb].splitgroup = 0; } } else { MYfread( &junki, 4, 1, fp ); for( y = 0; y < 15; y++ ) { MYfread( &junkf, 4, 1, fp ); MYfread( &junkf, 4, 1, fp ); MYfread( &junkf, 4, 1, fp ); if( shaveversion >= 'a' ) MYfread( &junkf, 4, 1, fp ); } if( shaveversion >= 'd' ) { MYfread( &junki, 4, 1, fp ); // splitgroup MYfread( &junki, 4, 1, fp ); // splitmerge } } if( Dtag[x] ) neutral[Dlink[x]] = v[Dlink[x]]; } //x } // for (x=0;xpos += Dtotalfverts * 4; fp->pos += Dtotalfaces * 4; fp->pos += Dtotalfaces * 4; fp->pos += Dtotalfaces * 4; // for (x=0;x6) PASSES=6; //PASSES=4; for( x = 0; x < 5; x++ ) { int l; MYfread( &l, 4, 1, fp ); MYfread( &colmap[x].name, l, 1, fp ); MYfread( &colmap[x].flags, 4, 1, fp ); if( Gmaps_active == 1 ) if( strlen( colmap[x].name ) ) { char tmpn[255]; // colmap[x].name[l]=NULL; sprintf( tmpn, "%s", colmap[x].name ); read_animated_targa( tmpn, &colmap[x] ); } } for( x = 0; x < 5; x++ ) { int l; MYfread( &l, 4, 1, fp ); MYfread( &densemap[x].name, l, 1, fp ); MYfread( &densemap[x].flags, 4, 1, fp ); if( Gmaps_active == 1 ) if( strlen( densemap[x].name ) ) read_animated_targa( densemap[x].name, &densemap[x] ); } if( shaveversion >= 'c' ) for( x = 0; x < 5; x++ ) { int l; MYfread( &l, 4, 1, fp ); MYfread( &lenmap[x].name, l, 1, fp ); MYfread( &lenmap[x].flags, 4, 1, fp ); if( Gmaps_active == 1 ) if( strlen( lenmap[x].name ) ) read_animated_targa( lenmap[x].name, &lenmap[x] ); } MYfread( &totalgroups, 4, 1, fp ); { // FILE *dgg; // dgg=MYfopen("groups.txt","w"); // fprintf (dgg,"totalgroups %d\n",totalgroups); for( x = 0; x < totalgroups; x++ ) { int l; int xx; // int yy; MYfread( &l, 4, 1, fp ); // fprintf (dgg,"namelen = %d\n",l); for( xx = 0; xx < l; xx++ ) MYfread( &group_names[x][xx], 1, 1, fp ); group_names[x][l] = 0; // for (yy=0;yy= 'e' ) { //if (freeze.totalverts>0) free_freeze( ); MYfread( &freeze.totalverts, 4, 1, fp ); MYfread( &freeze.totalfaces, 4, 1, fp ); MYfread( &freeze.totalfverts, 4, 1, fp ); freeze.haircount = 0; if( freeze.totalverts > 0 ) { alloc_freeze( ); for( x = 0; x < freeze.totalfaces; x++ ) freeze.colorlock[x] = -1; for( x = 0; x < freeze.totalverts; x++ ) { MYfread( &freeze.v[x].x, 4, 1, fp ); MYfread( &freeze.v[x].y, 4, 1, fp ); MYfread( &freeze.v[x].z, 4, 1, fp ); MYfread( &freeze.Rrvcolor[x], 4, 1, fp ); MYfread( &freeze.Rgvcolor[x], 4, 1, fp ); MYfread( &freeze.Rbvcolor[x], 4, 1, fp ); // freeze.Rrvcolor[x]=100; } for( x = 0; x < freeze.totalfverts; x++ ) { MYfread( &freeze.facelist[x], 4, 1, fp ); } for( x = 0; x < freeze.totalfaces; x++ ) { MYfread( &freeze.mtlgroup[x], 4, 1, fp ); MYfread( &freeze.face_start[x], 4, 1, fp ); MYfread( &freeze.face_end[x], 4, 1, fp ); MYfread( &freeze.colorlock[x], 4, 1, fp ); // printf ("reading colorlock[%d] = %d\n",x,freeze.colorlock[x]); } MYfread( &freeze.textoggle, 4, 1, fp ); freeze_texl = 1; freeze_texg = 0; // global if( freeze.textoggle ) { freeze.textoggle = 1; //local freeze_texl = 0; freeze_texg = 1; } scale_freeze( ); } if( shaveversion >= 'f' ) for( y = 0; y < 5; y++ ) for( x = 22; x < 24; x++ ) // wiggles { float junkf; // if (y!=4) MYfread( &sliders[x][y].value, 4, 1, fp ); // if (y==4) why am i not reading this? // MYfread(&junkf,4,1,fp); } if( shaveversion >= 'g' ) { // get weights int ti; int total_sliders = 30; MYfread( &total_sliders, 4, 1, fp ); // total sliders for( x = 0; x < total_sliders; x++ ) { // ti = sliders[x][0].paint; ti=1; MYfread( &ti, 4, 1, fp ); // empty/full ? // sliders[x][0].paint = ti; // sliders[x][1].paint = ti; // sliders[x][2].paint = ti; // sliders[x][3].paint = ti; if( ti > 0 ) for( y = 0; y < totalverts; y++ ) { MYfread( &hair[y].slider[x], 4, 1, fp ); // slider contents } } } if( shaveversion >= 'h' ) for( y = 0; y < 5; y++ ) for( x = 0; x < 30; x++ ) // wiggles { float junkf; //if (y!=4) MYfread( &sliders[x][y].value, 4, 1, fp ); //if (y==4) why am i not reading this // MYfread(&junkf,4,1,fp); } if( shaveversion >= 'i' ) for( y = 0; y < 5; y++ ) { MYfread( &LOCAL_PASSES[y], 4, 1, fp ); MYfread( &LOCAL_CNT[y], 4, 1, fp ); } if( shaveversion >= 'j' ) { // free_splines(); // char tmp[255]; make_splines( ); for( x = 0; x < total_splines; x++ ) for( y = 0; y < 15; y++ ) { MYfread( &Shair[x].pfID[y], 4, 1, fp ); // Shair[x].noisev[y]=Shair[x].hv[y]; // Sresthair[x].noisev[y]=Shair[x].hv[y]; Sresthair[x] = Shair[x]; } for( x = 0; x < total_splines; x++ ) { MYfread( &Shair[x].splitgroup, 4, 1, fp ); if( shaveversion >= 'k' ) MYfread( &Shair[x].splitmerge, 4, 1, fp ); Sresthair[x] = Shair[x]; } if( Gdynamics_mode != 1 ) for( x = 0; x < total_splines; x++ ) { Shair[x].restlength = Distance( Shair[x].hv[1], Shair[x].hv[2] ); Sresthair[x].restlength = Shair[x].restlength; } for( y = 0; y < 5; y++ ) for( x = 0; x < 30; x++ ) { // float junkf; MYfread( &sliders[x][y].value, 4, 1, fp ); } } if( shaveversion >= 'l' ) MYfread( &sliders[0][5].value, 4, 1, fp ); if( shaveversion == 'l' ) if( RW_CONTEXT != RW_DISK ) { // state machine int bb; for( bb = 0; bb < totalverts; bb++ ) for( y = 0; y < 15; y++ ) { BASEHAIR dummyhair; MYfread( &dummyhair.hv[y].x, 4, 1, fp ); MYfread( &dummyhair.hv[y].y, 4, 1, fp ); MYfread( &dummyhair.hv[y].z, 4, 1, fp ); MYfread( &dummyhair.hv[y].x, 4, 1, fp ); MYfread( &dummyhair.hv[y].y, 4, 1, fp ); MYfread( &dummyhair.hv[y].z, 4, 1, fp ); MYfread( &dummyhair.hv[y].x, 4, 1, fp ); MYfread( &dummyhair.hv[y].y, 4, 1, fp ); MYfread( &dummyhair.hv[y].z, 4, 1, fp ); MYfread( &dummyhair.hv[y].x, 4, 1, fp ); MYfread( &dummyhair.hv[y].y, 4, 1, fp ); MYfread( &dummyhair.hv[y].z, 4, 1, fp ); } for( bb = 0; bb < total_splines; bb++ ) for( y = 0; y < 15; y++ ) { BASEHAIR dummyhair; MYfread( &dummyhair.hv[y].x, 4, 1, fp ); MYfread( &dummyhair.hv[y].y, 4, 1, fp ); MYfread( &dummyhair.hv[y].z, 4, 1, fp ); MYfread( &dummyhair.hv[y].x, 4, 1, fp ); MYfread( &dummyhair.hv[y].y, 4, 1, fp ); MYfread( &dummyhair.hv[y].z, 4, 1, fp ); MYfread( &dummyhair.hv[y].x, 4, 1, fp ); MYfread( &dummyhair.hv[y].y, 4, 1, fp ); MYfread( &dummyhair.hv[y].z, 4, 1, fp ); MYfread( &dummyhair.hv[y].x, 4, 1, fp ); MYfread( &dummyhair.hv[y].y, 4, 1, fp ); MYfread( &dummyhair.hv[y].z, 4, 1, fp ); MYfread( &dummyhair.hv[y].x, 4, 1, fp ); MYfread( &dummyhair.hv[y].y, 4, 1, fp ); MYfread( &dummyhair.hv[y].z, 4, 1, fp ); } } if( shaveversion >= 'm' ) for( x = 0; x < Dtotalverts; x++ ) { int junki; MYfread( &junki, 4, 1, fp ); } if( shaveversion >= 'n' ) { // MYfread(&GMetaNurb,4,1,fp); MYfread( &DUTtotalfaces, 4, 1, fp ); MYfread( &DUTtotalfverts, 4, 1, fp ); fp->pos += DUTtotalfverts * 4; fp->pos += DUTtotalfaces * 4; fp->pos += DUTtotalfaces * 4; // for (x=0;x= 'o' ) { for( x = 0; x < totalverts; x++ ) { int junki; for( y = 0; y < 15; y++ ) //MYfread(&junki,4,1,fp); MYfread( &hair[x].select[y], 4, 1, fp ); } if( 0 == 1 ) for( x = 0; x < Stotalverts; x++ ) { for( y = 0; y < 15; y++ ) MYfread( &Shair[x].select[y], 4, 1, fp ); } } for( y = 0; y < 5; y++ ) // make a nice clean write of all the sliders for( x = 30; x < 40; x++ ) { // float junkf; sliders[x][y].value = 0; // clear 'em out if this is old } for( x = 0; x < 5; x++ ) sliders[30][x].value = sliders[1][x].value; for( x = 0; x < 5; x++ ) sliders[31][x].value = sliders[1][x].value; for( x = 0; x < 5; x++ ) sliders[34][x].value = sliders[3][x].value; for( x = 0; x < 5; x++ ) sliders[35][x].value = sliders[3][x].value; if( shaveversion >= 'p' ) { for( y = 0; y < 5; y++ ) // make a nice clean write of all the sliders for( x = 30; x < 40; x++ ) { // float junkf; MYfread( &sliders[x][y].value, 4, 1, fp ); } { // get weights int ti; int total_sliders = 40; MYfread( &total_sliders, 4, 1, fp ); // total sliders for( x = 30; x < total_sliders; x++ ) { // ti = sliders[x][0].paint; ti=1; MYfread( &ti, 4, 1, fp ); // empty/full ? // sliders[x][0].paint = ti; // sliders[x][1].paint = ti; // sliders[x][2].paint = ti; // sliders[x][3].paint = ti; if( ti > 0 ) for( y = 0; y < totalverts; y++ ) { MYfread( &hair[y].slider[x], 4, 1, fp ); // slider contents } } } } for( y = 0; y < 5; y++ ) { Ganim_dir[y].x = 0.0f; Ganim_dir[y].y = 1.0f; Ganim_dir[y].z = 0.0f; } if( shaveversion >= 'q' ) { // version q for( y = 0; y < 5; y++ ) // we've got some new sliders here { // float junkf; MYfread( &Ganim_dir[y].x, 4, 1, fp ); MYfread( &Ganim_dir[y].y, 4, 1, fp ); MYfread( &Ganim_dir[y].z, 4, 1, fp ); } } // version r if( shaveversion >= 'r' ) { // for (y=0;ypos += totalfaces * 4; fp->pos += Dtotalfaces * 4; // for (x=0;x= 's' ) { DOCOLLIDE = 0; for( y = 0; y < 5; y++ ) // we've got some new sliders here { MYfread( &Gsurface_collide[y], 4, 1, fp ); if( Gsurface_collide[y] > 0 ) DOCOLLIDE = 1; if( skull_sphere == -1 ) DOCOLLIDE = 0; } } if( shaveversion >= 't' ) { // version t // for (y=0;y<5;y++) // we've got some new sliders here { MYfread( &COLLISION_METHOD, 4, 1, fp ); } } if( shaveversion >= 'u' ) for( x = 0; x < total_splines; x++ ) { int junki; for( y = 0; y < 15; y++ ) MYfread( &junki, 4, 1, fp ); // MYfread(&Shair[x].select[y],4,1,fp); } if( shaveversion >= 'v' ) for( y = 0; y < 5; y++ ) { MYfread( &LOCAL_SEGS[y], 4, 1, fp ); } else for( y = 0; y < 5; y++ ) { LOCAL_SEGS[y] = 56; } // version w if( shaveversion == 'w' ) { if( firstloadguv == 1 ) { int tq; // Ganim_dir[0]=0.0f; // Ganim_dir[1]=1.0f; // Ganim_dir[2]=0.0f; init_geomWF( &Guv ); Gdontinterp = 0; //joejoe for( tq = 0; tq < 5; tq++ ) //joejoe Gsurface_collide[tq] = 1; } firstloadguv = 0; free_geomWF( &Guv ); MYfread( &Guv.totalverts, 4, 1, fp ); MYfread( &Guv.totalfaces, 4, 1, fp ); MYfread( &Guv.totalfverts, 4, 1, fp ); alloc_geomWF( &Guv ); if( ( Guv.totalverts == Dtotalverts ) && ( Guv.totalfaces == Dtotalfaces ) && ( Guv.totalfverts == Dtotalfverts ) ) for( y = 0; y < Guv.totalverts; y++ ) { MYfread( &Guv.uv[y].x, 4, 1, fp ); MYfread( &Guv.uv[y].y, 4, 1, fp ); MYfread( &Guv.uv[y].z, 4, 1, fp ); } for( y = 0; y < Guv.totalfverts; y++ ) { MYfread( &Guv.facelist[y], 4, 1, fp ); } for( y = 0; y < Guv.totalfaces; y++ ) { MYfread( &Guv.face_start[y], 4, 1, fp ); MYfread( &Guv.face_end[y], 4, 1, fp ); } if( ( Guv.totalverts > 0 ) || ( Guv.totalfaces > 0 ) || ( Guv.totalfverts > 0 ) ) if( !( ( Guv.totalverts == Dtotalverts ) && ( Guv.totalfaces == Dtotalfaces ) && ( Guv.totalfverts == Dtotalfverts ) ) ) free_geomWF( &Guv ); // turn it off because it doesn't match } if( shaveversion >= 'x' ) { for( xx = 0; xx < totalverts; xx++ ) { MYfread( &hair[xx].uu, 4, 1, fp ); MYfread( &hair[xx].vv, 4, 1, fp ); // hair[xx].uu=resthair[xx].uu; // hair[xx].vv=resthair[xx].vv; } for( xx = 0; xx < total_splines; xx++ ) { MYfread( &Sresthair[xx].uu, 4, 1, fp ); MYfread( &Sresthair[xx].vv, 4, 1, fp ); Shair[xx].uu = Sresthair[xx].uu; Shair[xx].vv = Sresthair[xx].vv; } } if( shaveversion2 >= 'b' ) { int xx, y; for( xx = 0; xx < totalverts; xx++ ) for( y = 0; y < 15; y++ ) { MYfread( &hair[xx].noisev[y].x, 4, 1, fp ); MYfread( &hair[xx].noisev[y].y, 4, 1, fp ); MYfread( &hair[xx].noisev[y].z, 4, 1, fp ); // hair[xx].noisev[y]=resthair[xx].noisev[y]; // thishair[xx].noisev[y]=resthair[xx].noisev[y]; // lasthair[xx].noisev[y]=resthair[xx].noisev[y]; } for( xx = 0; xx < total_splines; xx++ ) for( y = 0; y < 15; y++ ) { MYfread( &Sresthair[xx].noisev[y].x, 4, 1, fp ); MYfread( &Sresthair[xx].noisev[y].y, 4, 1, fp ); MYfread( &Sresthair[xx].noisev[y].z, 4, 1, fp ); Shair[xx].noisev[y] = Sresthair[xx].noisev[y]; Sthishair[xx].noisev[y] = Sresthair[xx].noisev[y]; Slasthair[xx].noisev[y] = Sresthair[xx].noisev[y]; } } if( shaveversion2 >= 'e' ) { for( y = 0; y < 5; y++ ) for( x = 40; x < 41; x++ ) { MYfread( &sliders[x][y].value, 4, 1, fp ); } } if( shaveversion2 >= 'f' ) { for( y = 0; y < 5; y++ ) for( x = 41; x < 45; x++ ) { MYfread( &sliders[x][y].value, 4, 1, fp ); } } //if (shaveversion2>='h') // MYfread(&Gbacklighting,4,1,fp); if( shaveversion2 >= 'h' ) for( y = 0; y < 5; y++ ) { MYfread( &LOCAL_SHADCNT[y], 4, 1, fp ); } if( shaveversion2 >= 'i' ) { MYfread( &Guv_totalsets, 4, 1, fp ); for( x = 0; x < Guv_totalsets; x++ ) { MYfread( &Guv_sets[x].totalverts, 4, 1, fp ); MYfread( &Guv_sets[x].totalfverts, 4, 1, fp ); MYfread( &Guv_sets[x].totalfaces, 4, 1, fp ); for( y = 0; y < Guv_sets[x].totalverts; y++ ) { MYfread( &Guv_sets[x].v[y].x, 4, 1, fp ); MYfread( &Guv_sets[x].v[y].y, 4, 1, fp ); MYfread( &Guv_sets[x].v[y].z, 4, 1, fp ); } for( y = 0; y < Guv_sets[x].totalfverts; y++ ) MYfread( &Guv_sets[x].facelist[y], 4, 1, fp ); for( y = 0; y < Guv_sets[x].totalfaces; y++ ) { MYfread( &Guv_sets[x].face_start[y], 4, 1, fp ); MYfread( &Guv_sets[x].face_end[y], 4, 1, fp ); } } } if( shaveversion2 >= 'j' ) for( x = 0; x < 45; x++ ) MYfread( &Guv_link[x], 4, 1, fp ); if( shaveversion2 >= 'k' ) { int xx, y; for( xx = 0; xx < totalverts; xx++ ) MYfread( &hair[xx].restlength, 4, 1, fp ); for( xx = 0; xx < total_splines; xx++ ) { MYfread( &Sresthair[xx].restlength, 4, 1, fp ); } } if( shaveversion2 >= 'm' ) { int vers = 0, vers1; vers = 1; // softimage #ifdef MAYA3D vers = 2; #endif #ifdef MAX3D vers = 3; #endif #ifdef C4D vers = 4; #endif MYfread( &vers1, 4, 1, fp ); if( vers != vers1 ) SHAVEclear_scene( ); // from another version of shave! } gravity = sliders[0][5].value; for( y = 0; y < 5; y++ ) if( Gsurface_collide[y] == 1 ) DOCOLLIDE = 1; if( skull_sphere == -1 ) DOCOLLIDE = 0; make_normals( ); } if( fp ) { //restBOUNDLENGTH=BOUNDLENGTH; initbounds( ); make_normals( ); if( shaveversion2 < 'k' ) if( Gdynamics_mode != 1 ) if( ( LOCAL_CNT[4] > 0 ) || ( LOCAL_SHADCNT[4] > 0 ) ) // if (LOCAL_CNT[4]>0) { int q, fv, en; // if (0==1) // what the hell is this??? // for (q=0;q 0 ) || ( LOCAL_SHADCNT[0] > 0 ) ) if( Gdynamics_mode != 1 ) //if (0==1) // if (LOCAL_CNT[0]>0) { int q, fv, en; // if (0==1) // what the hell is this??? // for (q=0;q 0 ) { // fc=(VERT *) malloc(Dtotalfaces*sizeof(VERT)); { // FILE *fp; //fp=fopen("c:\\test.txt","w"); Dmake_normals( ); for( x = 0; x < total_splines; x++ ) { int mind, my = 0; int yy = 0; mind = 1000000.0f; // this would be much more efficient with voxels, but we're just loading the GUI for( yy = 0; yy < Dtotalverts; yy++ ) { if( Dvertgroup[yy] >= 0 ) if( ( Dvertgroup[yy] != splines ) ) { a = Shair[x].hv[0]; b = Drv[yy]; d = Distance( a, b ); if( d < mind ) { mind = d; my = yy; } } } //fprintf (fp,"norm [ %d ] = %f %f %f\n",x,Dface_norm[my].x,Dface_norm[my].y,Dface_norm[my].z); Shair[x].norm = Dvn[my]; //Shair[x].pid=my; //Sresthair[x].pid=my; Sresthair[x].norm = Dvn[my]; Sthishair[x].norm = Dvn[my]; Slasthair[x].norm = Dvn[my]; } // fclose(fp); } //free(fc); } } // finish static void Dregroup2( void ) { int f, x; int q; skull_sphere = -1; head = -1; beard = -1; eyebrow = -1; eyelash = -1; splines = -1; for( x = 0; x < Dtotalverts; x++ ) { Dtag[x] = 0; Dvertgroup[x] = -999; } for( q = 0; q < totalgroups; q++ ) { group_stat[q] = 1; group_enable[q] = 0; if( ( group_names[q][0] == 'b' ) && ( group_names[q][1] == 'e' ) && ( group_names[q][2] == 'a' ) && ( group_names[q][3] == 'r' ) && ( group_names[q][4] == 'd' ) ) { beard = q; group_enable[q] = 1; group_stat[q] = 0; } if( ( group_names[q][0] == 's' ) && ( group_names[q][1] == 'k' ) && ( group_names[q][2] == 'u' ) && ( group_names[q][3] == 'l' ) ) { skull_sphere = q; group_enable[q] = 2; group_stat[q] = 1; } if( ( group_names[q][0] == 'h' ) && ( group_names[q][1] == 'a' ) && ( group_names[q][2] == 'i' ) && ( group_names[q][3] == 'r' ) ) { head = q; group_enable[q] = 1; group_stat[q] = 0; } if( ( group_names[q][0] == 'e' ) && ( group_names[q][1] == 'y' ) && ( group_names[q][2] == 'e' ) && ( group_names[q][3] == 'b' ) && ( group_names[q][4] == 'r' ) ) { eyebrow = q; group_enable[q] = 1; group_stat[q] = 0; } if( ( group_names[q][0] == 'e' ) && ( group_names[q][1] == 'y' ) && ( group_names[q][2] == 'e' ) && ( group_names[q][3] == 'l' ) && ( group_names[q][4] == 'a' ) ) { eyelash = q; group_enable[q] = 1; group_stat[q] = 0; } if( ( group_names[q][0] == 's' ) && ( group_names[q][1] == 'p' ) && ( group_names[q][2] == 'l' ) && ( group_names[q][3] == 'i' ) && ( group_names[q][4] == 'n' ) ) { splines = q; group_enable[q] = 1; group_stat[q] = 0; } } //q for( f = 0; f < Dtotalfaces; f++ ) { // for (x=Dface_start[f];x= 0 ) for( f = 0; f < Dtotalfaces; f++ ) { if( ( Dmtlgroup[f] == skull_sphere ) ) for( x = Dface_start[f]; x < Dface_end[f]; x++ ) { Dvertgroup[Dfacelist[x]] = Dmtlgroup[f]; // Dtag[Dfacelist[x]] = 1; } } if( eyebrow >= 0 ) for( f = 0; f < Dtotalfaces; f++ ) { if( ( Dmtlgroup[f] == eyebrow ) ) for( x = Dface_start[f]; x < Dface_end[f]; x++ ) { Dvertgroup[Dfacelist[x]] = Dmtlgroup[f]; Dtag[Dfacelist[x]] = 1; } } if( eyelash >= 0 ) for( f = 0; f < Dtotalfaces; f++ ) { if( ( Dmtlgroup[f] == eyelash ) ) for( x = Dface_start[f]; x < Dface_end[f]; x++ ) { Dvertgroup[Dfacelist[x]] = Dmtlgroup[f]; Dtag[Dfacelist[x]] = 1; } } if( splines >= 0 ) for( f = 0; f < Dtotalfaces; f++ ) { if( ( Dmtlgroup[f] == splines ) ) for( x = Dface_start[f]; x < Dface_end[f]; x++ ) { Dvertgroup[Dfacelist[x]] = Dmtlgroup[f]; // if (x==Dface_start[f]) // Dtag[Dfacelist[x]] = 1; } } if( beard >= 0 ) for( f = 0; f < Dtotalfaces; f++ ) { if( ( Dmtlgroup[f] == beard ) ) for( x = Dface_start[f]; x < Dface_end[f]; x++ ) { Dvertgroup[Dfacelist[x]] = Dmtlgroup[f]; Dtag[Dfacelist[x]] = 1; } } if( head >= 0 ) for( f = 0; f < Dtotalfaces; f++ ) { if( ( Dmtlgroup[f] == head ) ) for( x = Dface_start[f]; x < Dface_end[f]; x++ ) { Dvertgroup[Dfacelist[x]] = Dmtlgroup[f]; Dtag[Dfacelist[x]] = 1; } } } static void reorg2( void ) { int x; int y, q; int dvt = 0, dft = 0, dfl = 0; totalverts = 0; totalfaces = 0; totalfverts = 0; for( x = 0; x < Dtotalverts; x++ ) Dtag[x] = 0; Dregroup2( ); skull_sphere = -1; head = -1; beard = -1; eyelash = -1; eyebrow = -1; colorlock = -1; splines = -1; for( q = 0; q < totalgroups; q++ ) { if( ( group_names[q][0] == 'b' ) && ( group_names[q][1] == 'e' ) && ( group_names[q][2] == 'a' ) && ( group_names[q][3] == 'r' ) && ( group_names[q][4] == 'd' ) ) { beard = q; // group_enable[q]=1; } if( ( group_names[q][0] == 'c' ) && ( group_names[q][1] == 'o' ) && ( group_names[q][2] == 'l' ) && ( group_names[q][3] == 'o' ) && ( group_names[q][4] == 'r' ) && ( group_names[q][5] == 'l' ) && ( group_names[q][6] == 'o' ) && ( group_names[q][7] == 'c' ) && ( group_names[q][8] == 'k' ) ) { colorlock = q; // printf ("we got colorlock %d\n",q); // group_enable[q]=1; } if( ( group_names[q][0] == 's' ) && ( group_names[q][1] == 'k' ) && ( group_names[q][2] == 'u' ) && ( group_names[q][3] == 'l' ) ) { skull_sphere = q; // group_enable[q]=2; } if( ( group_names[q][0] == 's' ) && ( group_names[q][1] == 'p' ) && ( group_names[q][2] == 'l' ) && ( group_names[q][3] == 'i' ) && ( group_names[q][4] == 'n' ) ) { splines = q; // group_enable[q]=2; // group_stat[q]=0; } if( ( group_names[q][0] == 'h' ) && ( group_names[q][1] == 'a' ) && ( group_names[q][2] == 'i' ) && ( group_names[q][3] == 'r' ) ) { head = q; // group_enable[q]=1; } if( ( group_names[q][0] == 'e' ) && ( group_names[q][1] == 'y' ) && ( group_names[q][2] == 'e' ) && ( group_names[q][3] == 'b' ) && ( group_names[q][4] == 'r' ) ) { eyebrow = q; // group_enable[q]=1; } if( ( group_names[q][0] == 'e' ) && ( group_names[q][1] == 'y' ) && ( group_names[q][2] == 'e' ) && ( group_names[q][3] == 'l' ) && ( group_names[q][4] == 'a' ) ) { eyelash = q; // group_enable[q]=1; } } //q { for( x = 0; x < Dtotalfaces; x++ ) { if( ( ( Dmtlgroup[x] == head ) && ( head >= 0 ) ) || ( ( Dmtlgroup[x] == eyelash ) && ( eyelash >= 0 ) ) || ( ( Dmtlgroup[x] == beard ) && ( beard >= 0 ) ) || ( ( Dmtlgroup[x] == eyebrow ) && ( eyebrow >= 0 ) ) ) // || ( ( Dmtlgroup[x] == splines ) && ( splines >= 0 ) ) // || ( ( Dmtlgroup[x] == skull_sphere ) && ( skull_sphere >= 0 ) ) ) { int qq; for( qq = Dface_start[x]; qq < Dface_end[x]; qq++ ) { // if(! ((Dmtlgroup[x]==splines)&&(splines!= -1))) Dtag[Dfacelist[qq]] = 1; // else // if(qq==Dface_start[x]) // Dtag[Dfacelist[qq]]=1; } } } } // printf ("scanning verts\n"); for( x = 0; x < Dtotalverts; x++ ) { if( Dtag[x] == 1 ) dvt++; } // printf("scanning faces\n"); { for( x = 0; x < Dtotalfaces; x++ ) { int ct = 0; for( y = Dface_start[x]; y < Dface_end[x]; y++ ) { if( Dtag[Dfacelist[y]] ) ct++; } // test!! if ((ct==3)||((Dmtlgroup[x]==splines)&&(Dmtlgroup[x]!= -1))) if( ( ( Dmtlgroup[x] == head ) && ( head >= 0 ) ) ) // ( ( Dmtlgroup[x] == splines ) && ( splines >= 0 ) ) || // ( ( Dmtlgroup[x] == skull_sphere ) && ( skull_sphere >= 0 ) ) ) // if ((ct==3)||(Dmtlgroup[x]==splines)) // if ((tc==3)||(Dmtlgroup[x]==splines)) // if (tc==Dface_end[x]-Dface_start[x]) { dft++; dfl += Dface_end[x] - Dface_start[x]; } } } // printf ("freeing memory\n"); freeverts( ); // printf ("allocating memory %d %d\n",dvt,dft); LORESallocvert( dvt, dft, dfl ); // printf ("collecting verts\n"); totalverts = 0; for( x = 0; x < Dtotalverts; x++ ) { if( Dtag[x] == 1 ) { v[totalverts] = Dv[x]; tagvert[totalverts] = 0; Dlink[x] = totalverts; vlink[totalverts] = x; totalverts++; } } // printf ("collecting fverts\n"); totalfverts = 0; // for (x=0;x= 0 ) ) ) // ( ( Dmtlgroup[x] == splines ) && ( splines >= 0 ) ) || // ( ( Dmtlgroup[x] == skull_sphere ) && ( skull_sphere >= 0 ) ) ) { face_start[totalfaces] = totalfverts; face_link[totalfaces] = x; //link to D face number for( y = Dface_start[x]; y < Dface_end[x]; y++ ) { // crash facelist[totalfverts] = Dlink[Dfacelist[y]]; Dflink[y] = totalfverts; mtlgroup[totalfaces] = Dmtlgroup[x]; // vertgroup[facelist[totalfverts]]= // Dvertgroup[Dfacelist[y]]; totalfverts++; } face_end[totalfaces] = totalfverts; totalfaces++; } // if (ct==Dface_end[x]-Dface_start[x]) { // face_start[totalfaces]=Dflink[Dface_start[x]]; // face_end[totalfaces]=Dflink[Dface_end[x]]; // mtlgroup[totalfaces]=Dmtlgroup[x]; // totalfaces++; } // problem } // printf("faces %d verts %d fverts %d mtl %d",totalfaces,totalverts,totalfverts,totalgroups); // Dmake_normals(); //if (RW_CONTEXT==RW_DISK) // make_normals(); { int i; int slg; for( i = 0; i < 5; i++ ) total_slgfaces[i] = 0; for( i = 0; i < totalfaces; i++ ) { slg = -1; if( head >= 0 ) if( mtlgroup[i] == head ) slg = 0; if( beard >= 0 ) if( mtlgroup[i] == beard ) slg = 1; if( eyebrow >= 0 ) if( mtlgroup[i] == eyebrow ) slg = 2; if( eyelash >= 0 ) if( mtlgroup[i] == eyelash ) slg = 3; if( splines >= 0 ) if( mtlgroup[i] == splines ) slg = 4; Gslg=slg; if( slg >= 0 ) { // int xx; float trl = 0.0f; slgfaces[slg][total_slgfaces[slg]] = i; // for (xx=face_start[i];xx0) total_slgfaces[slg]++; } } total_slgfaces[4] = total_splines; for( i = 0; i < total_splines; i++ ) slgfaces[4][i] = i; // hm /* for (i=0;i<5;i++) if (total_slgfaces[i]>0) slgfaces[i][total_slgfaces[i]]=slgfaces[i][total_slgfaces[i]-1]; */ for( i = 0; i < totalfaces; i++ ) { slg = -1; if( mtlgroup[i] == head ) slg = 0; if( mtlgroup[i] == beard ) slg = 1; if( mtlgroup[i] == eyebrow ) slg = 2; if( mtlgroup[i] == eyelash ) slg = 3; if( mtlgroup[i] == splines ) slg = 4; if( slg >= 0 ) { int xx; Gslg=slg; for( xx = face_start[i]; xx < face_end[i]; xx++ ) { int g; g = facelist[xx]; hair[g].pid = i; hair[g].mtl = mtlgroup[i]; vertgroup[g] = mtlgroup[i]; // resthair[g].pid=i; // thishair[g].pid=i; // lasthair[g].pid=i; hair[g].vid = g; // resthair[g].vid=g; // thishair[g].vid=g; // lasthair[g].vid=g; } } } } for( x = 0; x < totalfaces; x++ ) { float big = 0; int y; // int mtl; for( y = face_start[x]; y < face_end[x]; y++ ) { int g; g = facelist[y]; if( hair[g].restlength > 0 ) if( ( hair[g].mtl == head ) || ( hair[g].mtl == eyelash ) || ( hair[g].mtl == eyebrow ) || ( hair[g].mtl == splines ) || ( hair[g].mtl == beard ) ) { hair[g].pid = x; // resthair[g].pid=x; } } } } void restructure_hair( void ) { int x, q; int xx = 0, tv = 0, tf = 0, tfl = 0; int y; // WFTYPE wf2; BASEHAIR *gcache = NULL; SHAVENODE sn; SHAVEPARMS shavep; // MAYAfetch_node( &sn.restMEM, &sn.statMEM, &sn.shavep ); // memcpy (&shavep,&sn.shavep, sizeof (SHAVEPARMS)); // SHAVEinit_node(&sn,SHAVEID); //qqq MAYAfetch_parms( &shavep ); if( head >= 0 ) if( totalverts > 0 ) { for( x = 0; x < totalverts; x++ ) { if( head >= 0 ) if( hair[x].mtl == head ) { // wf->face_start[tf]=tfl; for( y = 0; y < 15; y++ ) { // wf->v[tv]=hair[x].resthv[y]; tv++; // wf->facelist[tfl]=tfl; tfl++; } // wf->face_end[tf]=tfl; tf++; } } if( tv ) { gcache = ( BASEHAIR * ) malloc( tv * sizeof( BASEHAIR ) ); tv = 0; for( x = 0; x < totalverts; x++ ) { if( head >= 0 ) if( hair[x].mtl == head ) { memcpy( &gcache[tv], &hair[x], sizeof( BASEHAIR ) ); tv++; } } } //if (abs(x - y) > 0.000001) freeverts( ); reorg2( ); // this necessary? init_hair2( ); /// ok now lets copy those guides .. for( x = 0; x < totalverts; x++ ) { for( q = 0; q < tv; q++ ) { if( fabs( hair[x].hv[0].x - gcache[q].hv[0].x ) < 0.00001 ) if( fabs( hair[x].hv[0].y - gcache[q].hv[0].y ) < 0.00001 ) if( fabs( hair[x].hv[0].z - gcache[q].hv[0].z ) < 0.00001 ) { memcpy( &hair[x], &gcache[q], sizeof( BASEHAIR ) ); q = tv; } } } //qqq MAYAset_parms( &shavep ); if( splines >= 0 ) { freeverts( ); make_splines2( ); } for( x = 0; x < total_splines; x++ ) memcpy( &Sresthair[x], &Shair[x], sizeof( BASEHAIR ) ); reset_rest( ); reset_noisespace( ); if( tv > 0 ) free( gcache ); } }