--- ray/src/common/mesh.h 2003/03/14 21:27:45 2.3 +++ ray/src/common/mesh.h 2012/11/06 01:04:23 2.15 @@ -1,19 +1,20 @@ -/* RCSid $Id: mesh.h,v 2.3 2003/03/14 21:27:45 greg Exp $ */ +/* RCSid $Id: mesh.h,v 2.15 2012/11/06 01:04:23 greg Exp $ */ /* * Header for compact triangle mesh geometry * * Include after standard.h, object.h and octree.h */ +#ifndef _RAD_MESH_H_ +#define _RAD_MESH_H_ -#include "copyright.h" - #include "lookup.h" -#ifndef uint4 -#define uint4 unsigned int4 +#ifdef __cplusplus +extern "C" { #endif -#ifndef BYTE -#define BYTE unsigned char + +#ifndef uby8 +#define uby8 unsigned char #endif /* @@ -29,10 +30,10 @@ * * Vertex ID's are encoded using the bottom 8 bits of a 4-byte integer * to index a vertex in a patch indicated by the 22 bits above (8-29). - * For triangle ID's, the top 22 bits (10-31) indicate the patch, and - * the bit 9 (0x200) indicates whether the triangle joins patches. + * For triangle ID's, the top 22 bits (10-31) indicate the parent patch, + * and the 10th bit (0x200) indicates whether the triangle joins patches. * If not, then the bottom 9 bits index into the local PTri array. - * If it's a joiner, then the 8th bit indicates whether the triangle joins + * If it's a joiner, then the 9th bit indicates whether the triangle joins * two patches, in which case the bottom 8 bits index the PJoin2 array. * Otherwise, the bottom 8 bits index the PJoin1 array. * @@ -42,31 +43,32 @@ * a lot of effort, but it can reduce mesh storage by a factor of 3 * or more. This is important, as the whole point is to model very * complicated geometry with this structure, and memory is the main - * limitation. + * limitation. (This representation is so efficient, that the octree + * structure ends up dominating memory for most compiled meshes.) */ /* A triangle mesh patch */ typedef struct { - uint4 (*xyz)[3]; /* up to 256 patch vertices */ - int4 *norm; /* vertex normals */ - uint4 (*uv)[2]; /* vertex local coordinates */ + uint32 (*xyz)[3]; /* up to 256 patch vertices */ + int32 *norm; /* vertex normals */ + uint32 (*uv)[2]; /* vertex local coordinates */ struct PTri { - BYTE v1, v2, v3; /* local vertices */ + uby8 v1, v2, v3; /* local vertices */ } *tri; /* local triangles */ short solemat; /* sole material */ - int2 *trimat; /* or local material indices */ + int16 *trimat; /* or local material indices */ struct PJoin1 { - int4 v1j; /* non-local vertex */ - int2 mat; /* material index */ - BYTE v2, v3; /* local vertices */ + int32 v1j; /* non-local vertex */ + int16 mat; /* material index */ + uby8 v2, v3; /* local vertices */ } *j1tri; /* joiner triangles */ struct PJoin2 { - int4 v1j, v2j; /* non-local vertices */ - int2 mat; /* material index */ - BYTE v3; /* local vertex */ + int32 v1j, v2j; /* non-local vertices */ + int16 mat; /* material index */ + uby8 v3; /* local vertex */ } *j2tri; /* double joiner triangles */ short nverts; /* vertex count */ - short ntris; /* triangle count */ + short ntris; /* local triangle count */ short nj1tris; /* joiner triangle count */ short nj2tris; /* double joiner triangle count */ } MESHPATCH; @@ -77,10 +79,10 @@ typedef struct mesh { int nref; /* reference count */ int ldflags; /* what we've loaded */ CUBE mcube; /* bounds and octree */ - FLOAT uvlim[2][2]; /* local coordinate extrema */ + RREAL uvlim[2][2]; /* local coordinate extrema */ OBJECT mat0; /* base material index */ OBJECT nmats; /* number of materials */ - MESHPATCH *patch; /* mesh patch list */ + MESHPATCH *patch; /* allocated mesh patch array */ int npatches; /* number of mesh patches */ OBJREC *pseudo; /* mesh pseudo objects */ LUTAB lut; /* vertex lookup table */ @@ -104,7 +106,7 @@ typedef struct { int fl; /* setting flags */ FVECT v; /* vertex location */ FVECT n; /* vertex normal */ - FLOAT uv[2]; /* local coordinates */ + RREAL uv[2]; /* local coordinates */ } MESHVERT; /* mesh format identifier */ @@ -112,34 +114,17 @@ typedef struct { /* magic number for mesh files */ #define MESHMAGIC ( 1 *MAXOBJSIZ+311) /* increment first value */ -#ifdef NOPROTO -extern MESH *getmesh(); -extern INSTANCE *getmeshinst(); -extern int getmeshtrivid(); -extern int getmeshvert(); -extern int getmeshtri(); -extern OBJREC *getmeshpseudo(); -extern int4 addmeshvert(); -extern OBJECT addmeshtri(); -extern char *checkmesh(); -extern void printmeshstats(); -extern void freemesh(); -extern void freemeshinst(); -extern void readmesh(); -extern void writemesh(); - -#else - extern MESH *getmesh(char *mname, int flags); extern MESHINST *getmeshinst(OBJREC *o, int flags); -extern int getmeshtrivid(int4 tvid[3], OBJECT *mo, +extern int nextmeshtri(OBJECT *tip, MESH *mp); +extern int getmeshtrivid(int32 tvid[3], OBJECT *mo, MESH *mp, OBJECT ti); -extern int getmeshvert(MESHVERT *vp, MESH *mp, int4 vid, int what); +extern int getmeshvert(MESHVERT *vp, MESH *mp, int32 vid, int what); extern int getmeshtri(MESHVERT tv[3], OBJECT *mo, MESH *mp, OBJECT ti, int what); extern OBJREC *getmeshpseudo(MESH *mp, OBJECT mo); -extern int4 addmeshvert(MESH *mp, MESHVERT *vp); +extern int32 addmeshvert(MESH *mp, MESHVERT *vp); extern OBJECT addmeshtri(MESH *mp, MESHVERT tv[3], OBJECT mo); extern char *checkmesh(MESH *mp); extern void printmeshstats(MESH *ms, FILE *fp); @@ -148,4 +133,8 @@ extern void freemeshinst(OBJREC *o); extern void readmesh(MESH *mp, char *path, int flags); extern void writemesh(MESH *mp, FILE *fp); -#endif /* NOPROTO */ + +#ifdef __cplusplus +} +#endif +#endif /* _RAD_MESH_H_ */