--- ray/src/common/objutil.h 2020/05/01 18:55:34 2.5 +++ ray/src/common/objutil.h 2021/04/07 03:02:00 2.14 @@ -1,4 +1,4 @@ -/* RCSid $Id: objutil.h,v 2.5 2020/05/01 18:55:34 greg Exp $ */ +/* RCSid $Id: objutil.h,v 2.14 2021/04/07 03:02:00 greg Exp $ */ /* * Declarations for .OBJ file utility * @@ -10,6 +10,10 @@ #ifndef _OBJUTIL_H_ #define _OBJUTIL_H_ +#ifdef __cplusplus +extern "C" { +#endif + #ifndef DUP_CHECK_REVERSE #define DUP_CHECK_REVERSE 1 /* eliminate flipped duplicates */ #endif @@ -17,12 +21,17 @@ #define POPEN_SUPPORT 1 /* support "!command" i/o */ #endif /* face flags */ -#define FACE_SELECTED 01 -#define FACE_DEGENERATE 02 -#define FACE_DUPLICATE 04 +#define FACE_DEGENERATE 01 +#define FACE_DUPLICATE 02 +#define FACE_SELECTED 04 +#define FACE_CUSTOM(n) (FACE_SELECTED<<(n)) +#define FACE_RESERVED (1<<15) struct Face; /* forward declaration */ +typedef int VNDX[3]; /* vertex indices (point,map,normal) */ + +/* Structure to hold vertex indices and link back to face list */ typedef struct { int vid; /* vertex id */ int tid; /* texture id */ @@ -75,19 +84,18 @@ typedef struct { int nfaces; /* count of faces */ } Scene; -#ifdef __cplusplus -extern "C" { -#endif - /* Allocate a new scene holder */ Scene * newScene(void); /* Add a .OBJ file to a scene */ Scene * loadOBJ(Scene *sc, const char *fspec); -/* Duplicate a scene */ -Scene * dupScene(const Scene *sc); +/* Duplicate a scene, optionally selecting faces */ +Scene * dupScene(const Scene *sc, int flreq, int flexc); +/* Add one scene to another, not checking for redundancies */ +int addScene(Scene *scdst, const Scene *scsrc); + /* Transform entire scene */ int xfScene(Scene *sc, int xac, char *xav[]); int xfmScene(Scene *sc, const char *xfm); @@ -95,6 +103,9 @@ int xfmScene(Scene *sc, const char *xfm); /* Add a descriptive comment */ void addComment(Scene *sc, const char *comment); +/* Find index for comment containing the given string (starting from n) */ +int findComment(Scene *sc, const char *match, int n); + /* Clear comments */ void clearComments(Scene *sc); @@ -152,21 +163,30 @@ int changeGroup(Scene *sc, const char *gname, int changeMaterial(Scene *sc, const char *mname, int flreq, int flexc); -/* Add a vertex to our scene */ +/* Add a vertex to our scene, returning index */ int addVertex(Scene *sc, double x, double y, double z); -/* Add a texture coordinate to our scene */ +/* Add a texture coordinate to our scene, returning index */ int addTexture(Scene *sc, double u, double v); -/* Add a surface normal to our scene */ +/* Add a surface normal to our scene, returning index */ int addNormal(Scene *sc, double xn, double yn, double zn); -/* Set current (last) group */ +/* Set current group (sc->lastgrp) to given ID */ void setGroup(Scene *sc, const char *nm); -/* Set current (last) material */ +/* Set current material (sc->lastmat) to given ID */ void setMaterial(Scene *sc, const char *nm); +/* Add a new face to our scene, using current group and material */ +Face * addFace(Scene *sc, VNDX vid[], int nv); + +/* Convert all faces with > 3 vertices to triangles */ +int triangulateScene(Scene *sc); + +/* Delete unreferenced vertices, normals, texture coords */ +void deleteUnreferenced(Scene *sc); + /* Free a scene */ void freeScene(Scene *sc); @@ -179,7 +199,10 @@ extern int verbose; extern char *emalloc(unsigned int n); extern char *ecalloc(unsigned int ne, unsigned int n); extern char *erealloc(char *cp, unsigned int n); -extern void efree(char *cp); +extern void efree(char *cp); + +#define getGroupID(sc,nm) findName(nm, (const char **)(sc)->grpname, (sc)->ngrps) +#define getMaterialID(sc,nm) findName(nm, (const char **)(sc)->matname, (sc)->nmats) #define CHUNKSIZ 128 /* object allocation chunk size */