26 #include "../../shared/ufotypes.h"
27 #include "../../common/mem.h"
28 #include "../../shared/shared.h"
29 #include "../../common/filesys.h"
30 #include "../../shared/typedefs.h"
31 #include "../../common/mem.h"
33 #include "../../client/renderer/r_gl.h"
34 #include "../../client/renderer/r_material.h"
35 #include "../../client/renderer/r_image.h"
36 #include "../../client/renderer/r_model.h"
37 #include "../../client/renderer/r_state.h"
38 #include "../../shared/images.h"
39 #include "../../common/common.h"
80 static void Exit (
int exitCode)
89 char out_buffer[4096];
92 va_start(argptr, format);
93 Q_vsnprintf(out_buffer,
sizeof(out_buffer), format, argptr);
96 printf(
"%s", out_buffer);
102 char outBuffer[4096];
105 va_start(argptr, fmt);
106 Q_vsnprintf(outBuffer,
sizeof(outBuffer), fmt, argptr);
119 if (len >=
sizeof(image->
name))
127 image->
width = width;
132 if (len >= 4 && image->
name[len - 4] ==
'.') {
133 image->
name[len - 4] =
'\0';
134 Com_Printf(
"Image with extension: '%s'\n", name);
146 if (!pname || !pname[0])
154 SDL_FreeSurface(surf);
161 Com_Printf(
" \\ - could not load skin '%s'\n", pname);
175 static char msg[1024];
177 va_start(argptr, fmt);
181 fprintf(stderr,
"Error: %s\n", msg);
231 int32_t numIndexes, numVerts;
233 Com_Printf(
" \\ - writing to file '%s'\n", fileName);
238 Com_Printf(
" \\ - can not open '%s' for writing\n", fileName);
244 FS_Write(&version,
sizeof(version), &f);
248 FS_Write(&numVerts,
sizeof(numVerts), &f);
249 FS_Write(&numIndexes,
sizeof(numIndexes), &f);
260 int cntCalculated = 0;
265 Q_strcat(mdxFileName,
sizeof(mdxFileName),
".mdx");
288 return cntCalculated;
294 int cntCalculated, cntAll;
298 cntAll = cntCalculated = 0;
314 Com_Printf(
" -skinfix fix skins for md2 models\n");
315 Com_Printf(
" -glcmds remove the unused glcmds from md2 models\n");
316 Com_Printf(
" -check perform general checks for all the models\n");
317 Com_Printf(
" -skinedit <filename> edit skin of a model\n");
318 Com_Printf(
" -skinnum <filename> edit the skin numbers of a model\n");
319 Com_Printf(
" -info <filename> show model information\n");
320 Com_Printf(
" -overwrite overwrite existing mdx files\n");
321 Com_Printf(
" -s <float> sets the smoothness value for normal-smoothing (in the range -1.0 to 1.0)\n");
322 Com_Printf(
" -f <filename> build tangentspace for the specified model file\n");
323 Com_Printf(
" -v --verbose print debug messages\n");
324 Com_Printf(
" -h --help show this help screen\n");
339 for (i = 1; i < argc; i++) {
340 if (
Q_streq(argv[i],
"-overwrite")) {
342 }
else if (
Q_streq(argv[i],
"-f") && (i + 1 < argc)) {
344 }
else if (
Q_streq(argv[i],
"-s") && (i + 1 < argc)) {
345 config.
smoothness = strtod(argv[++i],
nullptr);
350 }
else if (
Q_streq(argv[i],
"-mdx")) {
352 }
else if (
Q_streq(argv[i],
"-glcmds")) {
354 }
else if (
Q_streq(argv[i],
"-skinfix")) {
356 }
else if (
Q_streq(argv[i],
"-check")) {
358 }
else if (
Q_streq(argv[i],
"-info")) {
366 }
else if (
Q_streq(argv[i],
"-skinedit")) {
374 }
else if (
Q_streq(argv[i],
"-skinnum")) {
382 }
else if (
Q_streq(argv[i],
"-v") ||
Q_streq(argv[i],
"--verbose")) {
384 }
else if (
Q_streq(argv[i],
"-h") ||
Q_streq(argv[i],
"--help")) {
388 Com_Printf(
"Parameters unknown. Try --help.\n");
417 worker(buf, fileName, modfilelen, userData);
421 if (!
Q_strcasecmp(fileName + strlen(fileName) - 4,
".obj"))
422 worker(buf, fileName, modfilelen, userData);
430 static void MD2SkinFix (
const byte* buf,
const char* fileName,
int bufSize,
void* userData)
433 byte* model =
nullptr;
440 for (
int i = 0;
i < numSkins;
i++) {
441 const char* extension;
452 if (extension !=
nullptr)
460 const char* fixedPath;
461 if (model ==
nullptr) {
470 if (extension !=
nullptr) {
478 Com_Printf(
" \\ - skin %i: changed path to '%s'\n",
i + 1, path);
480 Com_Printf(
" \\ - could not load the skin with the new path\n");
482 memcpy(skinPath, path,
sizeof(path));
486 if (model !=
nullptr) {
492 static void MD2Check (
const byte* buf,
const char* fileName,
int bufSize,
void* userData)
494 bool headline =
false;
502 for (
int i = 0;
i < numSkins;
i++) {
503 const char* extension;
514 if (extension !=
nullptr)
522 Com_Printf(
" \\ - skin %i: %s - %i errors/warnings\n",
i + 1, name, errors);
524 Com_Printf(
" \\ - skin contains full path\n");
525 if (extension !=
nullptr)
526 Com_Printf(
" \\ - skin contains extension '%s'\n", extension);
528 Com_Printf(
" \\ - could not load the skin\n");
535 const char* fileName;
536 const char* pattern =
"**.md2";
590 int main (
int argc,
char** argv)
memPool_t * vid_imagePool
static void UM_Parameter(int argc, char **argv)
Parameter parsing.
memPool_t * com_fileSysPool
const char * FS_NextFileFromFileList(const char *files)
Returns the next file that is found in the virtual filesystem identified by the given file pattern...
static void ModelCheck(void)
int Q_vsnprintf(char *str, size_t size, const char *format, va_list ap)
Safe (null terminating) vsnprintf implementation.
void MD2SkinEdit(const byte *buf, const char *fileName, int bufSize, void *userData)
int FS_CheckFile(const char *fmt,...)
Just returns the filelength and -1 if the file wasn't found.
static void PrecalcNormalsAndTangentsBatch(const char *pattern)
char inputName[MAX_QPATH]
QGL_EXTERN GLint GLenum type
image_t * R_AliasModelGetSkin(const char *modelFileName, const char *skin)
const char * Com_SkipPath(const char *pathname)
Returns just the filename from a given path.
int FS_OpenFile(const char *filename, qFILE *file, filemode_t mode)
Finds and opens the file in the search path.
void R_LoadObjModel(model_t *mod, byte *buffer, int bufSize)
const char * Com_GetExtension(const char *path)
void Com_Printf(const char *format,...)
bool Com_sprintf(char *dest, size_t size, const char *fmt,...)
copies formatted string with buffer-size checking
void Com_StripExtension(const char *in, char *out, const size_t size)
Removes the file extension from a filename.
GLfloat * vertex_array_3d
int main(int argc, char **argv)
int FS_LoadFile(const char *path, byte **buffer)
Filenames are relative to the quake search path.
void MD2SkinNum(const byte *buf, const char *fileName, int bufSize, void *userData)
void R_ReallocateStateArrays(int size)
Reallocate arrays of GL primitives if needed.
int FS_BuildFileList(const char *fileList)
Build a filelist.
GLshort * vertex_array_2d
void MD2Info(const byte *buf, const char *fileName, int bufSize, void *userData)
#define Mem_SafeReAlloc(ptr, size)
void Q_strncpyz(char *dest, const char *src, size_t destsize)
Safe strncpy that ensures a trailing zero.
gltexunit_t * active_texunit
void Com_Error(int code, const char *fmt,...)
static void GLCmdsRemove(void)
static void UM_DefaultParameter(void)
static model_t * LoadModel(const char *name)
Loads in a model for the given name.
void R_ModCalcUniqueNormalsAndTangents(mAliasMesh_t *mesh, int nFrames, float smoothness)
Calculates normals and tangents for all frames and does vertex merging based on smoothness.
static void WriteToFile(const model_t *mod, const mAliasMesh_t *mesh, const char *fileName)
memPool_t * com_genericPool
void R_ReallocateTexunitArray(gltexunit_t *texunit, int size)
Reallocate texcoord array of the specified texunit, if needed.
texunits maintain multitexture state
static void Exit(int exitCode) __attribute__((__noreturn__))
void FS_InitFilesystem(bool writeToHomeDir)
GLfloat * next_vertex_array_3d
SDL_Surface * Img_LoadImage(char const *name)
Loads the specified image from the game filesystem and populates the provided SDL_Surface.
#define Mem_CreatePool(name)
int FS_WriteFile(const void *buffer, size_t len, const char *filename)
static modelConfig_t config
void R_ModLoadAliasMD2Model(model_t *mod, byte *buffer, int bufSize, bool loadNormals)
Load MD2 models from file.
#define Q_strcasecmp(a, b)
void MD2GLCmdsRemove(const byte *buf, const char *fileName, int bufSize, void *userData)
void Com_DPrintf(int level, const char *fmt,...)
static void MD2Visitor(modelWorker_t worker, void *userData)
static void ModelWorker(modelWorker_t worker, const char *fileName, void *userData)
The caller has to ensure that the model is from the expected format.
void R_ModLoadAliasMD3Model(model_t *mod, byte *buffer, int bufSize)
Load MD3 models from file.
const GLuint *typedef void(APIENTRY *GenRenderbuffersEXT_t)(GLsizei
struct modelConfig_s modelConfig_t
memPool_t * vid_lightPool
the glcmd format: a positive integer starts a tristrip command, followed by that many vertex structur...
image_t * R_LoadImageData(const char *name, const byte *pic, int width, int height, imagetype_t type)
Creates a new image from RGBA data. Stores it in the gltextures array and also uploads it...
QGL_EXTERN GLuint GLchar GLuint * len
void MD2HeaderCheck(const dMD2Model_t *md2, const char *fileName, int bufSize)
static int PrecalcNormalsAndTangents(const char *filename)
static void MD2Check(const byte *buf, const char *fileName, int bufSize, void *userData)
QGL_EXTERN GLuint GLsizei GLsizei GLint GLenum GLchar * name
static void SkinFix(void)
void Q_strcat(char *dest, size_t destsize, const char *format,...)
Safely (without overflowing the destination buffer) concatenates two strings.
GLfloat * next_normal_array
GLfloat * next_tangent_array
#define Mem_PoolAllocType(type, pool)
static void MD2SkinFix(const byte *buf, const char *fileName, int bufSize, void *userData)
QGL_EXTERN GLuint GLsizei bufSize
#define Mem_Dup(type, in, n)
image_t * R_FindImage(const char *pname, imagetype_t type)
Finds or loads the given image.
void(* modelWorker_t)(const byte *buf, const char *fileName, int bufSize, void *userData)
memPool_t * vid_modelPool
void format(__printf__, 1, 2)))
void FS_FreeFile(void *buffer)
int FS_Write(const void *buffer, int len, qFILE *f)
Properly handles partial writes.