/* ============== LoadScreen ============== */ void LoadScreen (char *name) { char *expanded; expanded = ExpandPathAndArchive (name); printf ("grabbing from %s...\n",expanded); LoadLBM (expanded, &byteimage, &lbmpalette); byteimagewidth = bmhd.w; byteimageheight = bmhd.h; }
void Cmd_Skin (void) { byte *palette; byte *pixels; int width, height; byte *cropped; int y; char name[1024], savename[1024]; int pcx = 0; GetToken (false); if (strstr(token, "pcx")) { pcx = 1; GetToken(false); } if (model.num_skins == MAX_MD2SKINS) Error ("model.num_skins == MAX_MD2SKINS"); if (g_skipmodel) return; if (!pcx) sprintf (name, "%s/%s.lbm", cdarchive, token); else sprintf (name, "%s/%s_src.pcx", cdarchive, token); strcpy (name, ExpandPathAndArchive( name ) ); // sprintf (name, "%s/%s.lbm", cddir, token); if (TokenAvailable()) { GetToken (false); sprintf (g_skins[model.num_skins], "%s.pcx", token); sprintf (savename, "%s%s.pcx", gamedir, g_skins[model.num_skins]); } else { sprintf (savename, "%s/%s.pcx", cddir, token); sprintf (g_skins[model.num_skins], "%s/%s.pcx", cdpartial, token); } if (!strcmp(name, savename)) Error ("attempt to overwrite source for %s", name); else printf("name %s %s\n", name, savename); model.num_skins++; if (g_skipmodel || g_release || g_archive) return; process_skin(name, savename); }
void Cmd_TextureMix() { miptex32_t *qtex32; char filename[1024]; int size; InitVars(); GetScriptToken (false); strcpy(root, token); RemoveExt(root); RemoveLeading(root); strcpy(filename, ExpandPathAndArchive(token)); if (SetVars(filename)) { // Create combined texture percent = ((TotalArea() * 100) / (out.w * out.h)); printf("Total area consumed : %d%%\n", percent); printf("Texture resolution : %dx%d pixels.\n", xcharsize, ycharsize); CreateMain(); // Save image as m32 sprintf (filename, "%spics/misc/%s.m32", gamedir, out.name); qtex32 = CreateMip32((unsigned *)outpixels, out.w, out.h, &size, false); qtex32->contents = 0; qtex32->value = 0; qtex32->scale_x = 1.0; qtex32->scale_y = 1.0; sprintf (qtex32->name, "misc/%s", out.name); printf ("\n\nwriting %s\n", filename); SaveFile (filename, (byte *)qtex32, size); free (qtex32); // Save out script file sprintf (filename, "%spics/misc/%s.fnt", gamedir, outscript); printf("Writing %s as script file\n", filename); if (!SaveScript(filename)) { printf("Unable to save output script.\n"); } } printf("Everythings groovy.\n"); Cleanup(); }
/* =============== Cmd_Load =============== */ void Cmd_Load (void) { char *name; GetToken (false); if (g_release) return; name = ExpandPathAndArchive(token); // load the image logprint ("loading %s\n", name); Load256Image (name, &byteimage, &lbmpalette, &byteimagewidth, &byteimageheight); RemapZero (byteimage, lbmpalette, byteimagewidth, byteimageheight); }
/* =============== GrabGlobals =============== */ void GrabGlobals( char *frame ){ char file1[1024]; char *framefile; frame_t *fr; framefile = FindFrameFile( frame ); sprintf( file1, "%s/%s", cdarchive, framefile ); ExpandPathAndArchive( file1 ); sprintf( file1, "%s/%s",cddir, framefile ); printf( "grabbing %s\n", file1 ); fr = &g_frames[model.num_frames - 1]; // last frame read in LoadGlobals( file1 ); }
/* ================= Cmd_Cluster ================= */ void Cmd_Cluster(){ char file1[1024]; GetScriptToken( false ); printf( "---------------------\n" ); sprintf( file1, "%s/%s", cdpartial, token ); printf( "%s\n", file1 ); ExpandPathAndArchive( file1 ); sprintf( file1, "%s/%s", cddir, token ); LoadClusters( file1, (int **)&clusters, (int *)&num_verts, jointed ); new_num_verts[0] = num_verts[0]; clustered = 1; }
/* ============== LoadScreenBMP ============== */ void LoadScreenBMP(char *pszName) { char *pszExpanded; char basename[64]; pszExpanded = ExpandPathAndArchive(pszName); printf("grabbing from %s...\n", pszExpanded); if (LoadBMP(pszExpanded, &byteimage, &lbmpalette)) Error ("Failed to load!", pszExpanded); if ( byteimage == NULL || lbmpalette == NULL ) Error("FAIL!",pszExpanded); byteimagewidth = bmhd.w; byteimageheight = bmhd.h; ExtractFileBase (token, basename); // Files that start with '$' have color (0,0,255) transparent, if ( basename[0] == '{' ) { // move to last palette entry. fTransparent255 = true; TransparentByteImage(); } }
int GetScriptInfo( char *name ) { FILE *fp; char buffer[256]; char tempbuff[256]; char delims[] = {" \t,\n"}; printf( "Opening script file %s.\n", name ); if ( fp = fopen( name, "r" ) ) { while ( fgets( buffer, 256, fp ) ) { if ( strncmp( buffer, "//", 2 ) && strncmp( buffer, "\n", 1 ) ) { strupr( buffer ); strcpy( tempbuff, buffer ); if ( strcmp( strtok( tempbuff, delims ), "OUTPUT" ) == 0 ) { strcpy( out.name, strtok( NULL, delims ) ); strlwr( out.name ); } strcpy( tempbuff, buffer ); if ( strcmp( strtok( tempbuff, delims ), "SOURCEDIR" ) == 0 ) { strcpy( tempbuff, strtok( NULL, delims ) ); strcpy( sourcedir, ExpandPathAndArchive( tempbuff ) ); } strcpy( tempbuff, buffer ); if ( strcmp( strtok( tempbuff, delims ), "DOSORT" ) == 0 ) { dosort = 1; } strcpy( tempbuff, buffer ); if ( strcmp( strtok( tempbuff, delims ), "XCHARSIZE" ) == 0 ) { xcharsize = strtol( strtok( NULL, delims ), NULL, 0 ); } strcpy( tempbuff, buffer ); if ( strcmp( strtok( tempbuff, delims ), "YCHARSIZE" ) == 0 ) { ycharsize = strtol( strtok( NULL, delims ), NULL, 0 ); } strcpy( tempbuff, buffer ); if ( strcmp( strtok( tempbuff, delims ), "OUTSCRIPT" ) == 0 ) { strcpy( outscript, strtok( NULL, delims ) ); strlwr( outscript ); } strcpy( tempbuff, buffer ); if ( strcmp( strtok( tempbuff, delims ), "OUTUSAGE" ) == 0 ) { strcpy( outusage, strtok( NULL, delims ) ); } strcpy( tempbuff, buffer ); if ( strcmp( strtok( tempbuff, delims ), "POS" ) == 0 ) { out.w = strtol( strtok( NULL, delims ), NULL, 0 ); out.h = strtol( strtok( NULL, delims ), NULL, 0 ); } strcpy( tempbuff, buffer ); if ( strcmp( strtok( tempbuff, delims ), "FILE" ) == 0 ) { strcpy( in[filenum].name, strtok( NULL, delims ) ); in[filenum].x = strtol( strtok( NULL, delims ), NULL, 0 ); in[filenum].y = strtol( strtok( NULL, delims ), NULL, 0 ); in[filenum].col = strtol( strtok( NULL, delims ), NULL, 0 ); filenum++; } } } fclose( fp ); return( true ); } else { printf( "ERROR : Could not open script file.\n" ); return( false ); } }
/* =============== Cmd_Skin Skins aren't actually stored in the file, only a reference is saved out to the header file. =============== */ void Cmd_Skin (void) { byte *palette; byte *pixels; int width, height; byte *cropped; int y; char name[1024], savename[1024]; GetScriptToken (false); if (model.num_skins == MAX_MD2SKINS) Error ("model.num_skins == MAX_MD2SKINS"); if (g_skipmodel) return; #if 1 sprintf (name, "%s/%s.pcx", cddir, token); sprintf (savename, "%s/!%s.pcx", g_outputDir, token); sprintf (g_skins[model.num_skins], "%s/!%s.pcx", cdpartial, token); #else sprintf (name, "%s/%s.lbm", cdarchive, token); strcpy (name, ExpandPathAndArchive( name ) ); // sprintf (name, "%s/%s.lbm", cddir, token); if (ScriptTokenAvailable()) { GetScriptToken (false); sprintf (g_skins[model.num_skins], "%s.pcx", token); sprintf (savename, "%s%s.pcx", g_outputDir, g_skins[model.num_skins]); } else { sprintf (savename, "%s/%s.pcx", g_outputDir, token); sprintf (g_skins[model.num_skins], "%s/%s.pcx", cdpartial, token); } #endif model.num_skins++; if (g_skipmodel || g_release || g_archive) return; // load the image printf ("loading %s\n", name); Load256Image (name, &pixels, &palette, &width, &height); // RemapZero (pixels, palette, width, height); // crop it to the proper size cropped = (byte *) SafeMalloc (model.skinwidth*model.skinheight, "Cmd_Skin"); for (y=0 ; y<model.skinheight ; y++) { memcpy (cropped+y*model.skinwidth, pixels+y*width, model.skinwidth); } // save off the new image printf ("saving %s\n", savename); CreatePath (savename); WritePCXfile (savename, cropped, model.skinwidth, model.skinheight, palette); free (pixels); free (palette); free (cropped); }
/* =============== GrabFrame =============== */ static void GrabFrame (char *frame) { triangle_t *ptri; int i, j; trivert_t *ptrivert; int num_tris; char file1[1024]; frame_t *fr; vertexnormals_t vnorms[MAX_VERTS]; int index_xyz; char *framefile; // the frame 'run1' will be looked for as either // run.1 or run1.tri, so the new alias sequence save // feature an be used framefile = FindFrameFile (frame); sprintf (file1, "%s/%s", cdarchive, framefile); ExpandPathAndArchive (file1); sprintf (file1, "%s/%s",cddir, framefile); printf ("grabbing %s ", file1); if (model.num_frames >= MAX_FRAMES) Error ("model.num_frames >= MAX_FRAMES"); fr = &g_frames[model.num_frames]; model.num_frames++; strcpy (fr->name, frame); // // load the frame // if (do3ds) Load3DSTriangleList (file1, &ptri, &num_tris, NULL, NULL); else LoadTriangleList (file1, &ptri, &num_tris, NULL, NULL); if (num_tris != model.num_tris) Error ("%s: number of triangles doesn't match base frame\n", file1); // // allocate storage for the frame's vertices // ptrivert = fr->v; for (i=0 ; i<model.num_xyz ; i++) { vnorms[i].numnormals = 0; VectorClear (vnorms[i].normalsum); } ClearBounds (fr->mins, fr->maxs); // // store the frame's vertices in the same order as the base. This assumes the // triangles and vertices in this frame are in exactly the same order as in the // base // for (i=0 ; i<num_tris ; i++) { vec3_t vtemp1, vtemp2, normal; float ftemp; VectorSubtract (ptri[i].verts[0], ptri[i].verts[1], vtemp1); VectorSubtract (ptri[i].verts[2], ptri[i].verts[1], vtemp2); CrossProduct (vtemp1, vtemp2, normal); VectorNormalize (normal, normal); // rotate the normal so the model faces down the positive x axis ftemp = normal[0]; normal[0] = -normal[1]; normal[1] = ftemp; for (j=0 ; j<3 ; j++) { index_xyz = triangles[i].index_xyz[j]; // rotate the vertices so the model faces down the positive x axis // also adjust the vertices to the desired origin ptrivert[index_xyz].v[0] = ((-ptri[i].verts[j][1]) * scale_up) + adjust[0]; ptrivert[index_xyz].v[1] = (ptri[i].verts[j][0] * scale_up) + adjust[1]; ptrivert[index_xyz].v[2] = (ptri[i].verts[j][2] * scale_up) + adjust[2]; AddPointToBounds (ptrivert[index_xyz].v, fr->mins, fr->maxs); VectorAdd (vnorms[index_xyz].normalsum, normal, vnorms[index_xyz].normalsum); vnorms[index_xyz].numnormals++; } } // // calculate the vertex normals, match them to the template list, and store the // index of the best match // for (i=0 ; i<model.num_xyz ; i++) { int j; vec3_t v; float maxdot; int maxdotindex; int c; c = vnorms[i].numnormals; if (!c) Error ("Vertex with no triangles attached"); VectorScale (vnorms[i].normalsum, 1.0/c, v); VectorNormalize (v, v); maxdot = -999999.0; maxdotindex = -1; for (j=0 ; j<NUMVERTEXNORMALS ; j++) { float dot; dot = DotProduct (v, avertexnormals[j]); if (dot > maxdot) { maxdot = dot; maxdotindex = j; } } ptrivert[i].lightnormalindex = maxdotindex; } free (ptri); }
/* ================= Cmd_Base ================= */ void Cmd_Base (void) { vec3_t base_xyz[MAX_VERTS]; triangle_t *ptri; int i, j, k; #if 1 #else int time1; #endif char file1[1024]; char file2[1024]; GetScriptToken (false); if (g_skipmodel || g_release || g_archive) return; printf ("---------------------\n"); #if 1 sprintf (file1, "%s/%s", cdpartial, token); printf ("%s ", file1); ExpandPathAndArchive (file1); sprintf (file1, "%s/%s", cddir, token); #else sprintf (file1, "%s/%s.%s", cdarchive, token, trifileext); printf ("%s\n", file1); ExpandPathAndArchive (file1); sprintf (file1, "%s/%s.%s", cddir, token, trifileext); time1 = FileTime (file1); if (time1 == -1) Error ("%s doesn't exist", file1); #endif // // load the base triangles // if (do3ds) Load3DSTriangleList (file1, &ptri, &model.num_tris, NULL, NULL); else LoadTriangleList (file1, &ptri, &model.num_tris, NULL, NULL); GetScriptToken (false); sprintf (file2, "%s/%s.pcx", cddir, token); // sprintf (trans_file, "%s/!%s_a.pcx", cddir, token); printf ("skin: %s\n", file2); Load256Image (file2, &BasePixels, &BasePalette, &BaseWidth, &BaseHeight); if (BaseWidth != SKINPAGE_WIDTH || BaseHeight != SKINPAGE_HEIGHT) { if (g_allow_newskin) { ScaleWidth = BaseWidth; ScaleHeight = BaseHeight; } else { Error("Invalid skin page size: (%d,%d) should be (%d,%d)", BaseWidth,BaseHeight,SKINPAGE_WIDTH,SKINPAGE_HEIGHT); } } else { ScaleWidth = (float)ExtractNumber(BasePixels, ENCODED_WIDTH_X, ENCODED_WIDTH_Y); ScaleHeight = (float)ExtractNumber(BasePixels, ENCODED_HEIGHT_X, ENCODED_HEIGHT_Y); } // // get the ST values // BuildST (ptri, model.num_tris,false); // // run through all the base triangles, storing each unique vertex in the // base vertex list and setting the indirect triangles to point to the base // vertices // for (i=0 ; i<model.num_tris ; i++) { for (j=0 ; j<3 ; j++) { // get the xyz index for (k=0 ; k<model.num_xyz ; k++) if (VectorCompare (ptri[i].verts[j], base_xyz[k])) break; // this vertex is already in the base vertex list if (k == model.num_xyz) { // new index VectorCopy (ptri[i].verts[j], base_xyz[model.num_xyz]); if(clustered) ReplaceClusterIndex(k, ptri[i].indicies[j], (int **)&clusters, (IntListNode_t **)&vertLists, (int *)&num_verts, (int *)&new_num_verts); model.num_xyz++; } triangles[i].index_xyz[j] = k; // get the st index for (k=0 ; k<model.num_st ; k++) if (triangle_st[i][j][0] == base_st[k].s && triangle_st[i][j][1] == base_st[k].t) break; // this vertex is already in the base vertex list if (k == model.num_st) { // new index base_st[model.num_st].s = triangle_st[i][j][0]; base_st[model.num_st].t = triangle_st[i][j][1]; model.num_st++; } triangles[i].index_st[j] = k; } } // build triangle strips / fans BuildGlCmds (); }
/* ================= Cmd_Base ================= */ void Cmd_Base (void) { triangle_t *ptri; int i, j, k; int time1; char file1[1024]; GetToken (false); if (g_skipmodel || g_release || g_archive) return; printf ("---------------------\n"); sprintf (file1, "%s/%s.%s", cdarchive, token, trifileext); printf ("%s\n", file1); ExpandPathAndArchive (file1); sprintf (file1, "%s/%s.%s", cddir, token, trifileext); time1 = FileTime (file1); if (time1 == -1) Error ("%s doesn't exist", file1); // // load the base triangles // if (do3ds) Load3DSTriangleList (file1, &ptri, &model.num_tris); else LoadTriangleList (file1, &ptri, &model.num_tris); // // get the ST values // BuildST (ptri, model.num_tris); // // run through all the base triangles, storing each unique vertex in the // base vertex list and setting the indirect triangles to point to the base // vertices // for (i=0 ; i<model.num_tris ; i++) { for (j=0 ; j<3 ; j++) { // get the xyz index for (k=0 ; k<model.num_xyz ; k++) if (VectorCompare (ptri[i].verts[j], base_xyz[k])) break; // this vertex is already in the base vertex list if (k == model.num_xyz) { // new index VectorCopy (ptri[i].verts[j], base_xyz[model.num_xyz]); model.num_xyz++; } triangles[i].index_xyz[j] = k; // get the st index for (k=0 ; k<model.num_st ; k++) if (triangle_st[i][j][0] == base_st[k].s && triangle_st[i][j][1] == base_st[k].t) break; // this vertex is already in the base vertex list if (k == model.num_st) { // new index base_st[model.num_st].s = triangle_st[i][j][0]; base_st[model.num_st].t = triangle_st[i][j][1]; model.num_st++; } triangles[i].index_st[j] = k; } } // build triangle strips / fans BuildGlCmds (); }