int nr_poly=0; LPDIRECT3DVERTEXBUFFER8 g_pVB=0; char *LoadFile( char *filename, DWORD *size ) { char *buffer; DWORD filelength; FILE *fp; fp = fopen( filename, "rb" ); if( fp ) { fseek( fp, 0, SEEK_END); filelength = ftell(fp); if( size ) *size = filelength; fseek( fp, 0, SEEK_SET); buffer = (char*)malloc( filelength+2 ); buffer[filelength] = 0; buffer[filelength+1] = 0; fread( buffer, filelength, 1, fp ); fclose( fp ); return buffer; } return 0; } struct CUSTOMVERTEX2 { float x,y,z; float xn,yn,zn; DWORD color; FLOAT tu, tv; // The texture coordinates }; #define D3DFVF_CUSTOMVERTEX2 (D3DFVF_XYZ|D3DFVF_NORMAL|D3DFVF_DIFFUSE|D3DFVF_TEX1) int ASE_GetIntValue( char *meshdata, char *keyword, int index ) { char work[256]; if( index < 0 ) strcpy( work, keyword); else sprintf(work, "%s%%5u", keyword, index ); char *temp = strstr(meshdata, work ); if( temp ) { temp += strlen(work)+1; return atoi(temp ); } return -1; } struct vertex3d { float x,y,z; }; struct face { int a,b,c; }; int ASE_GetVertexValue( CUSTOMVERTEX2 *p, char *meshdata, char *keyword, int index ) { char work[256]; sprintf(work, "%s%5u", keyword, index ); char *temp = strstr(meshdata, work ); if( temp ) { temp += strlen(work)+1; sscanf(temp,"%f\t%f\t%f",&p->x,&p->y,&p->z); return 1; } return -1; } int ASE_GetVertexNormalValue( CUSTOMVERTEX2 *p, char *meshdata, char *keyword, int index ) { char work[256]; sprintf(work, "%s %u", keyword, index ); char *temp = strstr(meshdata, work ); if( temp ) { temp += strlen(work)+1; sscanf(temp,"%f\t%f\t%f",&p->xn,&p->yn,&p->zn); p->tu=0; p->tv=0; return 1; } return -1; } int ASE_GetFaceValue( struct face *f, char *meshdata, char *keyword, int index ) { char work[256]; if( index < 0 ) strcpy( work, keyword); else sprintf(work, "%s%5u", keyword, index ); char *temp = strstr(meshdata, work ); if( temp ) { temp = strstr( temp, "A:"); temp += 2; f->a = atoi(temp); temp = strstr( temp, "B:"); temp += 2; f->b = atoi(temp); temp = strstr( temp, "C:"); temp += 2; f->c = atoi(temp); return 1; } return -1; } float xrot=0, yrot=0, zrot=0; #include "3DOBJ.H" char LoadMesh(char *filename, DWORD col) { struct CUSTOMVERTEX2 *p3d; struct face *faces; struct CUSTOMVERTEX2 *p; int tt=0; int flags=0; char *meshbuffer = (char*)LOGO_3D; if( !meshbuffer ) return 0; int nr_vertex = ASE_GetIntValue(meshbuffer, "*MESH_NUMVERTEX",-1 ); int nr_face = ASE_GetIntValue(meshbuffer, "*MESH_NUMFACES",-1 ); nr_poly = nr_face; p3d = new CUSTOMVERTEX2[ nr_vertex ]; faces = new struct face[ nr_face ]; for( int t=0; t < nr_vertex; ++t ) ASE_GetVertexValue( &p3d[t],meshbuffer,"*MESH_VERTEX",t ); for( t=0; t < nr_face; ++t ) ASE_GetFaceValue( &faces[t],meshbuffer,"*MESH_FACE",t ); for( int t=0; t < nr_vertex; ++t ) ASE_GetVertexNormalValue( &p3d[t],meshbuffer,"*MESH_VERTEXNORMAL",t ); p = (struct CUSTOMVERTEX2*)malloc( (nr_face*3) * sizeof(struct CUSTOMVERTEX2)); for( t =0; tCreateVertexBuffer( nr_face*3*sizeof(CUSTOMVERTEX2),D3DUSAGE_WRITEONLY, D3DFVF_CUSTOMVERTEX2,D3DPOOL_DEFAULT, &g_pVB ) ) ) return (char)E_FAIL; CUSTOMVERTEX2* pVertices; if( FAILED( g_pVB->Lock( 0, 0, (BYTE**)&pVertices, 0 ) ) ) return (char)E_FAIL; memcpy( pVertices, p, nr_face*3*sizeof(CUSTOMVERTEX2) ); g_pVB->Unlock(); delete faces; delete p3d; return 1; }