#ifndef WH_MODEL_H_aecb277c_ #define WH_MODEL_H_aecb277c_ #include /* * Model description uses these data types: * UINT An unsigned integer, a la "%u". * FLOAT A floating-point number, a la "%g". * XYZ Three whitespace-separated FLOATs: x, y, z. * RGB Three whitespace-separated FLOATs: r, g, b. * STR Text string. This consists of all non-whitespace * characters or quoted characters up to the next * unquoted whitespace (", ', and \ quoting can be * used). * CHAR Single nonblank character * * A model consists of four sections. The model begins with a format * identifier, then one number per section, giving the number of * entries in the sections: * * STR Format version ID, the string ModelV2 * UINT Number of materials * UINT Number of locations * UINT Number of points * UINT Number of triangles * UINT Number of objects * * This is followed by the data for the sections. Each section is a * stream of the appropriate number of entries; each entry conforms to * the description below. References from one section to another are * by number. * * Material definition: * STR Material name (cannot be zero-length) * RGB Self-luminosity colour of the material * RGB Diffuse reflective colour of the material * FLOAT Specularity exponent * FLOAT Specularity multiplier * * Location: * XYZ Location * * Point: * UINT Location number * CHAR Point type: * 's' Smooth surface internal point, normal follows * 'c' Corner/edge point, use triangle's normal * If 's': * XYZ Surface normal vector * If 'c': * (nothing) * * Triangle: * UINT Material number * UINT Point number of corner 1 * UINT Point number of corner 2 * UINT Point number of corner 3 * * Object: * UINT Number of triangles * UINT... That many triangle numbers * * The inx member of MATERIAL, LOCATION, POINT, TRIANGLE, and OBJECT is * the number that must be passed to get_material, get_location, etc, * to get that particular MATERIAL, LOCATION, etc. */ typedef struct xyz XYZ; typedef struct rgb RGB; typedef struct location LOCATION; typedef struct material MATERIAL; typedef struct point POINT; typedef struct triangle TRIANGLE; typedef struct model MODEL; typedef struct object OBJECT; struct xyz { double x; double y; double z; } ; struct rgb { double r; double g; double b; } ; struct location { int inx; XYZ l; } ; struct material { int inx; char *name; RGB selflum; RGB reflect; double spec_exp; double spec_mul; } ; struct point { int inx; int loc; unsigned char type; #define PT_UNSET '\0' #define PT_SURFACE 's' #define PT_CORNER 'c' XYZ normal; /* valid only for PT_SURFACE, scratch for PT_CORNER */ } ; struct triangle { int inx; int material; int corner[3]; } ; /* * load_model arranges for triangles to point to at least ntriangles * ints; save_model assumes it does so; free_model and del_object free * it. Various of the other calls make similar assumptions. Provided * client code ensures that triangles is freeable whenever free_model * is called and whenever object is called for the OBJECT in question, * and that triangles[0..ntriangles-1] is the correct list of triangle * numbers for the object whenever it calls into any of the other * entry points, it can do whatever it wants here. In particular, * client code may realloc it freely, or even free the provided vector * and point it at a non-freeable array provided care is taken to * reset it to something freeable (such as a nil pointer) before * deleting the object or freeing the model. * * The library modifies the triangle numbers whenever it has occasion * to renumber triangles, but otherwise does not follow the triangles * pointer except as mentioned above. Client code may even point * triangles to unwriteable memory provided it never gives the library * reason to renumber any of the listed triangles. */ struct object { int inx; int ntriangles; int *triangles; } ; extern MODEL *load_model(FILE *, void (*)(const char *)); extern MODEL *new_model(void); extern void save_model(MODEL *, FILE *); extern void free_model(MODEL *); extern int n_materials(MODEL *); extern int n_locations(MODEL *); extern int n_points(MODEL *); extern int n_triangles(MODEL *); extern int n_objects(MODEL *); extern MATERIAL *get_material(MODEL *, int); extern LOCATION *get_location(MODEL *, int); extern POINT *get_point(MODEL *, int); extern TRIANGLE *get_triangle(MODEL *, int); extern OBJECT *get_object(MODEL *, int); extern int new_material(MODEL *); extern int new_location(MODEL *); extern int new_point(MODEL *); extern int new_triangle(MODEL *); extern int new_object(MODEL *); extern int del_material(MODEL *, int); extern int del_location(MODEL *, int); extern int del_point(MODEL *, int); extern int del_triangle(MODEL *, int); extern int del_object(MODEL *, int); #endif