ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/common/mesh.h
Revision: 2.5
Committed: Fri Jun 6 16:38:47 2003 UTC (20 years, 10 months ago) by schorsch
Content type: text/plain
Branch: MAIN
Changes since 2.4: +12 -20 lines
Log Message:
*** empty log message ***

File Contents

# User Rev Content
1 schorsch 2.5 /* RCSid $Id: mesh.h,v 2.4 2003/05/13 17:58:32 greg Exp $ */
2 greg 2.1 /*
3     * Header for compact triangle mesh geometry
4     *
5     * Include after standard.h, object.h and octree.h
6     */
7 schorsch 2.5 #ifndef _RAD_MESH_H_
8     #define _RAD_MESH_H_
9     #ifdef __cplusplus
10     extern "C" {
11     #endif
12 greg 2.1
13     #include "copyright.h"
14    
15 greg 2.3 #include "lookup.h"
16    
17 greg 2.1 #ifndef uint4
18     #define uint4 unsigned int4
19     #endif
20     #ifndef BYTE
21     #define BYTE unsigned char
22     #endif
23    
24     /*
25     * Vertex space is minimized without compromising accuracy by using a
26     * 4-byte unsigned int to indicate position in the enclosing octree cube.
27     * The same trick is used for any local (u,v) coordinates, whose limits
28     * are recorded separately in the parent MESH structure. The uvlimit's
29     * in the MESH structure are set such that (0,0) is out of range, so
30     * we use this to indicate an unspecified local coordinate.
31     * A vertex normal, if specified, is stored in a single 4-byte
32     * integer using the codec in dircode.c. The encodedir() function
33     * never generates 0, so we can use this for unspecified normals.
34     *
35     * Vertex ID's are encoded using the bottom 8 bits of a 4-byte integer
36 greg 2.2 * to index a vertex in a patch indicated by the 22 bits above (8-29).
37     * For triangle ID's, the top 22 bits (10-31) indicate the patch, and
38     * the bit 9 (0x200) indicates whether the triangle joins patches.
39 greg 2.1 * If not, then the bottom 9 bits index into the local PTri array.
40 greg 2.2 * If it's a joiner, then the 8th bit indicates whether the triangle joins
41 greg 2.1 * two patches, in which case the bottom 8 bits index the PJoin2 array.
42     * Otherwise, the bottom 8 bits index the PJoin1 array.
43     *
44     * These shenanigans minimize vertex reference memory requirements
45     * in compiled mesh structures, where the octree leaves contain sets
46     * of triangle ID's rather than the more usual objects. It seems like
47     * a lot of effort, but it can reduce mesh storage by a factor of 3
48     * or more. This is important, as the whole point is to model very
49     * complicated geometry with this structure, and memory is the main
50 greg 2.3 * limitation.
51 greg 2.1 */
52    
53     /* A triangle mesh patch */
54     typedef struct {
55     uint4 (*xyz)[3]; /* up to 256 patch vertices */
56     int4 *norm; /* vertex normals */
57     uint4 (*uv)[2]; /* vertex local coordinates */
58     struct PTri {
59     BYTE v1, v2, v3; /* local vertices */
60     } *tri; /* local triangles */
61 greg 2.3 short solemat; /* sole material */
62     int2 *trimat; /* or local material indices */
63 greg 2.1 struct PJoin1 {
64     int4 v1j; /* non-local vertex */
65 greg 2.3 int2 mat; /* material index */
66 greg 2.1 BYTE v2, v3; /* local vertices */
67     } *j1tri; /* joiner triangles */
68     struct PJoin2 {
69     int4 v1j, v2j; /* non-local vertices */
70 greg 2.3 int2 mat; /* material index */
71 greg 2.1 BYTE v3; /* local vertex */
72     } *j2tri; /* double joiner triangles */
73     short nverts; /* vertex count */
74     short ntris; /* triangle count */
75     short nj1tris; /* joiner triangle count */
76     short nj2tris; /* double joiner triangle count */
77     } MESHPATCH;
78    
79     /* A loaded mesh */
80     typedef struct mesh {
81     char *name; /* mesh file name */
82     int nref; /* reference count */
83     int ldflags; /* what we've loaded */
84     CUBE mcube; /* bounds and octree */
85     FLOAT uvlim[2][2]; /* local coordinate extrema */
86 greg 2.3 OBJECT mat0; /* base material index */
87     OBJECT nmats; /* number of materials */
88 greg 2.1 MESHPATCH *patch; /* mesh patch list */
89     int npatches; /* number of mesh patches */
90 greg 2.3 OBJREC *pseudo; /* mesh pseudo objects */
91     LUTAB lut; /* vertex lookup table */
92 greg 2.1 struct mesh *next; /* next mesh in list */
93     } MESH;
94    
95     /* A mesh instance */
96     typedef struct {
97     FULLXF x; /* forward and backward transforms */
98     MESH *msh; /* mesh object reference */
99     } MESHINST;
100    
101     /* vertex flags */
102     #define MT_V 01
103     #define MT_N 02
104     #define MT_UV 04
105     #define MT_ALL 07
106    
107     /* A mesh vertex */
108     typedef struct {
109     int fl; /* setting flags */
110     FVECT v; /* vertex location */
111     FVECT n; /* vertex normal */
112     FLOAT uv[2]; /* local coordinates */
113     } MESHVERT;
114    
115     /* mesh format identifier */
116     #define MESHFMT "Radiance_tmesh"
117     /* magic number for mesh files */
118 greg 2.3 #define MESHMAGIC ( 1 *MAXOBJSIZ+311) /* increment first value */
119 greg 2.1
120    
121     extern MESH *getmesh(char *mname, int flags);
122     extern MESHINST *getmeshinst(OBJREC *o, int flags);
123 greg 2.3 extern int getmeshtrivid(int4 tvid[3], OBJECT *mo,
124     MESH *mp, OBJECT ti);
125 greg 2.1 extern int getmeshvert(MESHVERT *vp, MESH *mp, int4 vid, int what);
126 greg 2.3 extern int getmeshtri(MESHVERT tv[3], OBJECT *mo,
127     MESH *mp, OBJECT ti, int what);
128     extern OBJREC *getmeshpseudo(MESH *mp, OBJECT mo);
129 greg 2.1 extern int4 addmeshvert(MESH *mp, MESHVERT *vp);
130 greg 2.3 extern OBJECT addmeshtri(MESH *mp, MESHVERT tv[3], OBJECT mo);
131     extern char *checkmesh(MESH *mp);
132 greg 2.1 extern void printmeshstats(MESH *ms, FILE *fp);
133     extern void freemesh(MESH *ms);
134     extern void freemeshinst(OBJREC *o);
135     extern void readmesh(MESH *mp, char *path, int flags);
136     extern void writemesh(MESH *mp, FILE *fp);
137    
138 schorsch 2.5
139     #ifdef __cplusplus
140     }
141     #endif
142     #endif /* _RAD_MESH_H_ */
143