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