/* Reading OBJ files. */ #ifndef obj_H #define obj_H #include #include /* This module does NOT make common assumptions is that faces are 3 or 4 in size or that all vertices are declared always before than the normals. The data is read as a stream, rather than loading it all in memory. TO DO: do not support materials, parameter space vertices (free form geometry), smooth shading. */ typedef struct obj_vertex_t { float x, y, z, w; } obj_vertex_t; typedef struct obj_texture_coord_t { float u, v, w; } obj_texture_coord_t; typedef struct obj_normal_t{ float x, y, z; } obj_normal_t; typedef enum obj_face_components_t { OBJ_HAS_ONLY_VERTEX = 0, OBJ_HAS_NORMAL = 1, OBJ_HAS_TEXTURE = 2 } obj_face_components_t; typedef struct obj_face_desc_t{ size_t n_indices; obj_face_components_t components; } obj_face_desc_t; typedef struct obj_format_t{ obj_vertex_t* vertices; obj_texture_coord_t* textures; obj_normal_t* normals; int* face_indices; obj_face_desc_t* face_descs; } obj_format_t; void obj_create(obj_format_t* obj); /* Allocates memory for {triangle_count} in a previous allocated struct* {obj} */ void obj_destroy(obj_format_t const* obj); /* destroy the object {obj}. */ void obj_write(obj_format_t const* obj, FILE* out, int binary); /* Writed in the {out} file the obj file format described by {obj} with binary description if {binary} > 0. */ int obj_read(obj_format_t* obj, FILE* in); /* Read the {in} obj file and populates {obj}. If the file cannot be read or understand, the {obj->vertices} will be null after this functions returns. */ #endif