Rewritten OBJ export to include outpath
This commit is contained in:
parent
f39c655670
commit
09f87160bb
41
obj.c
41
obj.c
@ -1,3 +1,6 @@
|
||||
/* MIT License - 2022 JackCarterSmith */
|
||||
/* Modified and cleaned version - 19/08/2022 */
|
||||
/* */
|
||||
/* Copyright (c) 2005,2013,2014 Robert Kooima */
|
||||
/* */
|
||||
/* Permission is hereby granted, free of charge, to any person obtaining a */
|
||||
@ -26,12 +29,8 @@
|
||||
#include <math.h>
|
||||
|
||||
#ifndef CONF_NO_GL
|
||||
#ifdef __APPLE__
|
||||
# include <OpenGL/gl3.h>
|
||||
#else
|
||||
#include <GL/glew.h>
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#define MAXSTR 1024
|
||||
|
||||
@ -399,12 +398,12 @@ static void read_image(obj *O, int mi, int ki, const char *line,
|
||||
|
||||
char pathname[MAXSTR];
|
||||
|
||||
char map[MAXSTR];
|
||||
char map[MAXSTR - 1];
|
||||
char val[MAXSTR];
|
||||
|
||||
const char *end;
|
||||
|
||||
memset(map, 0, MAXSTR);
|
||||
memset(map, 0, MAXSTR - 1);
|
||||
memset(val, 0, MAXSTR);
|
||||
|
||||
while (line[0] != '\0' && line[0] != '\r' && line[0] != '\n')
|
||||
@ -2437,12 +2436,36 @@ static void obj_write_obj(const obj *O, const char *obj,
|
||||
}
|
||||
}
|
||||
|
||||
void obj_write(const obj *O, const char *obj, const char *mtl, int prec)
|
||||
void obj_write(const obj *O, const char *obj, const char *mtl, const char *outPath, int prec)
|
||||
{
|
||||
char objPath[MAXSTR];
|
||||
char mtlPath[MAXSTR];
|
||||
|
||||
#ifdef _WIN32
|
||||
#define EXPORT_FORMAT "%s\\%s"
|
||||
#else
|
||||
#define EXPORT_FORMAT "%s/%s"
|
||||
#endif
|
||||
|
||||
assert(O);
|
||||
|
||||
if (obj) obj_write_obj(O, obj, mtl, prec);
|
||||
if (mtl) obj_write_mtl(O, mtl);
|
||||
if (obj) {
|
||||
if (outPath != NULL)
|
||||
sprintf_s(objPath, MAXSTR, EXPORT_FORMAT, outPath, obj);
|
||||
else
|
||||
sprintf_s(objPath, MAXSTR, "%s", obj);
|
||||
|
||||
obj_write_obj(O, objPath, mtl, prec);
|
||||
}
|
||||
|
||||
if (mtl) {
|
||||
if (outPath != NULL)
|
||||
sprintf_s(mtlPath, MAXSTR, EXPORT_FORMAT, outPath, mtl);
|
||||
else
|
||||
sprintf_s(mtlPath, MAXSTR, "%s", mtl);
|
||||
|
||||
obj_write_mtl(O, mtlPath);
|
||||
}
|
||||
}
|
||||
|
||||
/*============================================================================*/
|
||||
|
23
obj.h
23
obj.h
@ -1,3 +1,6 @@
|
||||
/* MIT License - 2022 JackCarterSmith */
|
||||
/* Modified and cleaned version - 19/08/2022 */
|
||||
/* */
|
||||
/* Copyright (c) 2005 Robert Kooima */
|
||||
/* */
|
||||
/* Permission is hereby granted, free of charge, to any person obtaining a */
|
||||
@ -72,17 +75,17 @@ void obj_del_surf(obj *, int);
|
||||
void obj_set_mtrl_name(obj *, int, const char *);
|
||||
void obj_set_mtrl_map (obj *, int, int, const char *);
|
||||
void obj_set_mtrl_opt (obj *, int, int, unsigned int);
|
||||
void obj_set_mtrl_c (obj *, int, int, const float *);
|
||||
void obj_set_mtrl_o (obj *, int, int, const float *);
|
||||
void obj_set_mtrl_s (obj *, int, int, const float *);
|
||||
void obj_set_mtrl_c (obj *, int, int, const float[4]);
|
||||
void obj_set_mtrl_o (obj *, int, int, const float[3]);
|
||||
void obj_set_mtrl_s (obj *, int, int, const float[3]);
|
||||
|
||||
void obj_set_vert_v(obj *, int, const float *);
|
||||
void obj_set_vert_t(obj *, int, const float *);
|
||||
void obj_set_vert_n(obj *, int, const float *);
|
||||
void obj_set_vert_u(obj *, int, const float *);
|
||||
void obj_set_vert_v(obj *, int, const float[3]);
|
||||
void obj_set_vert_t(obj *, int, const float[2]);
|
||||
void obj_set_vert_n(obj *, int, const float[3]);
|
||||
void obj_set_vert_u(obj *, int, const float[3]);
|
||||
|
||||
void obj_set_poly(obj *, int, int, const int *);
|
||||
void obj_set_line(obj *, int, int, const int *);
|
||||
void obj_set_poly(obj *, int, int, const int[3]);
|
||||
void obj_set_line(obj *, int, int, const int[2]);
|
||||
void obj_set_surf(obj *, int, int);
|
||||
|
||||
void obj_set_vert_loc(obj *, int, int, int, int);
|
||||
@ -123,7 +126,7 @@ void obj_sort(obj *, int);
|
||||
float obj_acmr(obj *, int);
|
||||
|
||||
void obj_bound(const obj *, float *);
|
||||
void obj_write(const obj *, const char *, const char *, int);
|
||||
void obj_write(const obj *, const char *, const char *, const char *, int);
|
||||
|
||||
/*======================================================================+=====*/
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user