4 |
|
* |
5 |
|
* Include after standard.h, object.h and octree.h |
6 |
|
*/ |
7 |
+ |
#ifndef _RAD_MESH_H_ |
8 |
+ |
#define _RAD_MESH_H_ |
9 |
+ |
#ifdef __cplusplus |
10 |
+ |
extern "C" { |
11 |
+ |
#endif |
12 |
|
|
13 |
< |
#include "copyright.h" |
13 |
> |
#include "lookup.h" |
14 |
|
|
10 |
– |
#ifndef uint4 |
11 |
– |
#define uint4 unsigned int4 |
12 |
– |
#endif |
15 |
|
#ifndef BYTE |
16 |
|
#define BYTE unsigned char |
17 |
|
#endif |
28 |
|
* never generates 0, so we can use this for unspecified normals. |
29 |
|
* |
30 |
|
* Vertex ID's are encoded using the bottom 8 bits of a 4-byte integer |
31 |
< |
* to index a vertex in a patch indicated by the 20 bits above (9-29). |
32 |
< |
* For triangle ID's, the top 10 bits (11-31) indicate the patch, and |
33 |
< |
* the 10th bit indicates whether the triangle joins patches. |
31 |
> |
* to index a vertex in a patch indicated by the 22 bits above (8-29). |
32 |
> |
* For triangle ID's, the top 22 bits (10-31) indicate the patch, and |
33 |
> |
* the bit 9 (0x200) indicates whether the triangle joins patches. |
34 |
|
* If not, then the bottom 9 bits index into the local PTri array. |
35 |
< |
* If it's a joiner, then the 9th bit indicates whether the triangle joins |
35 |
> |
* If it's a joiner, then the 8th bit indicates whether the triangle joins |
36 |
|
* two patches, in which case the bottom 8 bits index the PJoin2 array. |
37 |
|
* Otherwise, the bottom 8 bits index the PJoin1 array. |
38 |
|
* |
42 |
|
* a lot of effort, but it can reduce mesh storage by a factor of 3 |
43 |
|
* or more. This is important, as the whole point is to model very |
44 |
|
* complicated geometry with this structure, and memory is the main |
45 |
< |
* limitation. (We also optimize intersection tests for triangles.) |
45 |
> |
* limitation. |
46 |
|
*/ |
47 |
|
|
48 |
|
/* A triangle mesh patch */ |
49 |
|
typedef struct { |
50 |
< |
uint4 (*xyz)[3]; /* up to 256 patch vertices */ |
51 |
< |
int4 *norm; /* vertex normals */ |
52 |
< |
uint4 (*uv)[2]; /* vertex local coordinates */ |
50 |
> |
uint32 (*xyz)[3]; /* up to 256 patch vertices */ |
51 |
> |
int32 *norm; /* vertex normals */ |
52 |
> |
uint32 (*uv)[2]; /* vertex local coordinates */ |
53 |
|
struct PTri { |
54 |
|
BYTE v1, v2, v3; /* local vertices */ |
55 |
|
} *tri; /* local triangles */ |
56 |
+ |
short solemat; /* sole material */ |
57 |
+ |
int16 *trimat; /* or local material indices */ |
58 |
|
struct PJoin1 { |
59 |
< |
int4 v1j; /* non-local vertex */ |
59 |
> |
int32 v1j; /* non-local vertex */ |
60 |
> |
int16 mat; /* material index */ |
61 |
|
BYTE v2, v3; /* local vertices */ |
62 |
|
} *j1tri; /* joiner triangles */ |
63 |
|
struct PJoin2 { |
64 |
< |
int4 v1j, v2j; /* non-local vertices */ |
64 |
> |
int32 v1j, v2j; /* non-local vertices */ |
65 |
> |
int16 mat; /* material index */ |
66 |
|
BYTE v3; /* local vertex */ |
67 |
|
} *j2tri; /* double joiner triangles */ |
68 |
|
short nverts; /* vertex count */ |
77 |
|
int nref; /* reference count */ |
78 |
|
int ldflags; /* what we've loaded */ |
79 |
|
CUBE mcube; /* bounds and octree */ |
80 |
< |
FLOAT uvlim[2][2]; /* local coordinate extrema */ |
80 |
> |
RREAL uvlim[2][2]; /* local coordinate extrema */ |
81 |
> |
OBJECT mat0; /* base material index */ |
82 |
> |
OBJECT nmats; /* number of materials */ |
83 |
|
MESHPATCH *patch; /* mesh patch list */ |
84 |
|
int npatches; /* number of mesh patches */ |
85 |
< |
char *cdata; /* opaque client data pointer */ |
85 |
> |
OBJREC *pseudo; /* mesh pseudo objects */ |
86 |
> |
LUTAB lut; /* vertex lookup table */ |
87 |
|
struct mesh *next; /* next mesh in list */ |
88 |
|
} MESH; |
89 |
|
|
104 |
|
int fl; /* setting flags */ |
105 |
|
FVECT v; /* vertex location */ |
106 |
|
FVECT n; /* vertex normal */ |
107 |
< |
FLOAT uv[2]; /* local coordinates */ |
107 |
> |
RREAL uv[2]; /* local coordinates */ |
108 |
|
} MESHVERT; |
109 |
|
|
110 |
|
/* mesh format identifier */ |
111 |
|
#define MESHFMT "Radiance_tmesh" |
112 |
|
/* magic number for mesh files */ |
113 |
< |
#define MESHMAGIC ( 0 *MAXOBJSIZ+311) /* increment first value */ |
113 |
> |
#define MESHMAGIC ( 1 *MAXOBJSIZ+311) /* increment first value */ |
114 |
|
|
106 |
– |
#ifdef NOPROTO |
115 |
|
|
108 |
– |
extern MESH *getmesh(); |
109 |
– |
extern INSTANCE *getmeshinst(); |
110 |
– |
extern int getmeshtrivid(); |
111 |
– |
extern int getmeshvert(); |
112 |
– |
extern int getmeshtri(); |
113 |
– |
extern int4 addmeshvert(); |
114 |
– |
extern OBJECT addmeshtri(); |
115 |
– |
extern void printmeshstats(); |
116 |
– |
extern void freemesh(); |
117 |
– |
extern void freemeshinst(); |
118 |
– |
extern void readmesh(); |
119 |
– |
extern void writemesh(); |
120 |
– |
|
121 |
– |
#else |
122 |
– |
|
116 |
|
extern MESH *getmesh(char *mname, int flags); |
117 |
|
extern MESHINST *getmeshinst(OBJREC *o, int flags); |
118 |
< |
extern int getmeshtrivid(int4 tvid[3], MESH *mp, OBJECT ti); |
119 |
< |
extern int getmeshvert(MESHVERT *vp, MESH *mp, int4 vid, int what); |
120 |
< |
extern int getmeshtri(MESHVERT tv[3], MESH *mp, OBJECT ti, int what); |
121 |
< |
extern int4 addmeshvert(MESH *mp, MESHVERT *vp); |
122 |
< |
extern OBJECT addmeshtri(MESH *mp, MESHVERT tv[3]); |
118 |
> |
extern int getmeshtrivid(int32 tvid[3], OBJECT *mo, |
119 |
> |
MESH *mp, OBJECT ti); |
120 |
> |
extern int getmeshvert(MESHVERT *vp, MESH *mp, int32 vid, int what); |
121 |
> |
extern int getmeshtri(MESHVERT tv[3], OBJECT *mo, |
122 |
> |
MESH *mp, OBJECT ti, int what); |
123 |
> |
extern OBJREC *getmeshpseudo(MESH *mp, OBJECT mo); |
124 |
> |
extern int32 addmeshvert(MESH *mp, MESHVERT *vp); |
125 |
> |
extern OBJECT addmeshtri(MESH *mp, MESHVERT tv[3], OBJECT mo); |
126 |
> |
extern char *checkmesh(MESH *mp); |
127 |
|
extern void printmeshstats(MESH *ms, FILE *fp); |
128 |
|
extern void freemesh(MESH *ms); |
129 |
|
extern void freemeshinst(OBJREC *o); |
130 |
|
extern void readmesh(MESH *mp, char *path, int flags); |
131 |
|
extern void writemesh(MESH *mp, FILE *fp); |
132 |
|
|
133 |
< |
#endif /* NOPROTO */ |
133 |
> |
|
134 |
> |
#ifdef __cplusplus |
135 |
> |
} |
136 |
> |
#endif |
137 |
> |
#endif /* _RAD_MESH_H_ */ |
138 |
> |
|