ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/common/objutil.h
Revision: 2.2
Committed: Thu Apr 2 20:44:15 2020 UTC (4 years, 1 month ago) by greg
Content type: text/plain
Branch: MAIN
Changes since 2.1: +4 -1 lines
Log Message:
Added -x option to robjutil to transform .OBJ files

File Contents

# Content
1 /* RCSid $Id: objutil.h,v 2.1 2020/03/30 18:28:35 greg Exp $ */
2 /*
3 * Declarations for .OBJ file utility
4 *
5 * Include after <stdio.h>
6 *
7 * Created by Greg Ward on Wed Feb 11 2004.
8 */
9
10 #ifndef _OBJUTIL_H_
11 #define _OBJUTIL_H_
12
13 #ifndef DUP_CHECK_REVERSE
14 #define DUP_CHECK_REVERSE 1 /* eliminate flipped duplicates */
15 #endif
16 #ifndef POPEN_SUPPORT
17 #define POPEN_SUPPORT 1 /* support "!command" i/o */
18 #endif
19 /* face flags */
20 #define FACE_SELECTED 01
21 #define FACE_DEGENERATE 02
22 #define FACE_DUPLICATE 04
23
24 struct Face; /* forward declaration */
25
26 typedef struct {
27 int vid; /* vertex id */
28 int tid; /* texture id */
29 int nid; /* normal id */
30 struct Face *fnext; /* next in vertex face list */
31 } VertEnt;
32
33 /* Structure to hold face and its vertex references */
34 typedef struct Face {
35 struct Face *next; /* next face in main list */
36 short flags; /* face selected, etc */
37 short nv; /* number of vertices */
38 short grp; /* group/object index */
39 short mat; /* material index */
40 /* in cases where the same vertex appears twice, first has link */
41 VertEnt v[3]; /* vertex list (extends struct) */
42 } Face;
43
44 /* Structure to hold vertex */
45 typedef struct {
46 double p[3]; /* 3-D position */
47 Face *vflist; /* linked face list (no repeats) */
48 } Vertex;
49
50 /* Structure to hold texture coordinate */
51 typedef struct {
52 float u, v; /* 2-D local texture coordinate */
53 } TexCoord;
54
55 /* Array to hold surface normal */
56 typedef float Normal[3];
57
58 /* Structure to hold a loaded .OBJ file */
59 typedef struct {
60 char **descr; /* descriptive comments */
61 int ndescr; /* number of comments */
62 char **grpname; /* object/group name list */
63 int ngrps; /* number of group names */
64 int lastgrp; /* last group seen */
65 char **matname; /* material name list */
66 int nmats; /* number of materials */
67 int lastmat; /* last material seen */
68 Vertex *vert; /* vertex array */
69 int nverts; /* number of vertices */
70 TexCoord *tex; /* texture coordinate array */
71 int ntex; /* number of texture coord's */
72 Normal *norm; /* surface normal array */
73 int nnorms; /* number of surface normals */
74 Face *flist; /* linked face list */
75 int nfaces; /* count of faces */
76 } Scene;
77
78 #ifdef __cplusplus
79 extern "C" {
80 #endif
81
82 /* Allocate a new scene holder */
83 Scene * newScene(void);
84
85 /* Add a .OBJ file to a scene */
86 Scene * loadOBJ(Scene *sc, const char *fspec);
87
88 /* Duplicate a scene */
89 Scene * dupScene(const Scene *sc);
90
91 /* Transform entire scene */
92 int xfmScene(Scene *sc, const char *xfm);
93
94 /* Add a descriptive comment */
95 void addComment(Scene *sc, const char *comment);
96
97 /* Clear comments */
98 void clearComments(Scene *sc);
99
100 /* Write a .OBJ file, return # faces written or -1 on error */
101 int toOBJ(Scene *sc, FILE *fp);
102 int writeOBJ(Scene *sc, const char *fspec);
103
104 /* Convert indicated faces to Radiance, return # written or -1 on error */
105 int toRadiance(Scene *sc, FILE *fp, int flreq, int flexc);
106 int writeRadiance(Scene *sc, const char *fspec,
107 int flreq, int flexc);
108
109 /* Compute face area (and normal) */
110 double faceArea(const Scene *sc, const Face *f, Normal nrm);
111
112 /* Eliminate duplicate vertices, return # joined */
113 int coalesceVertices(Scene *sc, double eps);
114
115 /* Identify duplicate faces */
116 int findDuplicateFaces(Scene *sc);
117
118 /* Delete indicated faces, return # deleted */
119 int deleteFaces(Scene *sc, int flreq, int flexc);
120
121 /* Clear face selection */
122 void clearSelection(Scene *sc, int set);
123
124 /* Invert face selection */
125 void invertSelection(Scene *sc);
126
127 /* Count number of faces selected */
128 int numberSelected(Scene *sc);
129
130 /* Select faces by object name (modifies current) */
131 void selectGroup(Scene *sc, const char *gname, int invert);
132
133 /* Select faces by material name (modifies current) */
134 void selectMaterial(Scene *sc, const char *mname, int invert);
135
136 /* Execute callback on indicated faces */
137 int foreachFace(Scene *sc, int (*cb)(Scene *, Face *, void *),
138 int flreq, int flexc, void *c_data);
139
140 /* Remove texture coordinates from the indicated faces */
141 int removeTexture(Scene *sc, int flreq, int flexc);
142
143 /* Remove surface normals from the indicated faces */
144 int removeNormals(Scene *sc, int flreq, int flexc);
145
146 /* Change group for the indicated faces */
147 int changeGroup(Scene *sc, const char *gname,
148 int flreq, int flexc);
149
150 /* Change material for the indicated faces */
151 int changeMaterial(Scene *sc, const char *mname,
152 int flreq, int flexc);
153
154 /* Grab texture coord's/normals from another object via ray tracing */
155 #define GET_TEXTURE 01
156 #define GET_NORMALS 02
157 int traceSurface(Scene *sc, int flreq, int flexc,
158 const char *oct, int what);
159
160 /* Free a scene */
161 void freeScene(Scene *sc);
162
163 /* Find an existing name in a list of names */
164 int findName(const char *nm, const char **nmlist, int n);
165
166 /* Verbose mode global */
167 extern int verbose;
168
169 extern char *emalloc(unsigned int n);
170 extern char *ecalloc(unsigned int ne, unsigned int n);
171 extern char *erealloc(char *cp, unsigned int n);
172 extern void efree(char *cp);
173
174 #define CHUNKSIZ 128 /* object allocation chunk size */
175
176 #define chunk_alloc(typ, arr, nold) \
177 ((nold)%CHUNKSIZ ? (arr) : \
178 (typ *)erealloc((char *)(arr), sizeof(typ)*((nold)+CHUNKSIZ)))
179
180 #ifdef __cplusplus
181 }
182 #endif
183
184 #endif /* ! _OBJUTIL_H_ */