3dgfx code, untested
[metatoy] / src / 3dgfx / mesh.h
1 #ifndef MESH_H_
2 #define MESH_H_
3
4 #include "3dgfx.h"
5 /*#include "image.h"*/
6 #include "inttypes.h"
7
8 struct g3d_material {
9         float r, g, b, a;
10         float sr, sg, sb, shin;
11
12         /*struct image *texmap, *envmap;*/
13         char *name;
14 };
15
16 struct g3d_mesh {
17         int prim;
18         struct g3d_vertex *varr;
19         uint16_t *iarr;
20         int vcount, icount;
21         char *name;
22
23         struct g3d_material *mtl;
24 };
25
26 void init_g3dmtl(struct g3d_material *mtl);
27
28 int init_mesh(struct g3d_mesh *mesh, int prim, int num_verts, int num_idx);
29
30 void free_mesh(struct g3d_mesh *mesh);
31 void destroy_mesh(struct g3d_mesh *mesh);
32
33 int copy_mesh(struct g3d_mesh *dest, struct g3d_mesh *src);
34
35 /* takes pointer to a dynamic array (dynarr_*) and populates it */
36 #define load_meshes(mesharr, fname) load_meshes_impl(&(mesharr), fname)
37 int load_meshes_impl(struct g3d_mesh **mesh, const char *fname);
38 /* TODO: idx -1 -> merge all meshes into one? */
39 int load_mesh(struct g3d_mesh *mesh, const char *fname, int idx);
40 int load_named_mesh(struct g3d_mesh *mesh, const char *fname, const char *mname);
41 int save_mesh(struct g3d_mesh *mesh, const char *fname);
42 struct g3d_mesh *find_mesh(struct g3d_mesh *meshes, const char *mname);
43
44 void zsort_mesh(struct g3d_mesh *mesh);
45 void draw_mesh(struct g3d_mesh *mesh);
46
47 void apply_mesh_xform(struct g3d_mesh *mesh, const float *xform);
48 int append_mesh(struct g3d_mesh *ma, struct g3d_mesh *mb);
49 int indexify_mesh(struct g3d_mesh *mesh);
50
51 void normalize_mesh_normals(struct g3d_mesh *mesh);
52
53 void calc_mesh_centroid(struct g3d_mesh *mesh, float *cent);
54
55 int gen_sphere_mesh(struct g3d_mesh *mesh, float rad, int usub, int vsub);
56 int gen_plane_mesh(struct g3d_mesh *mesh, float width, float height, int usub, int vsub);
57 int gen_cube_mesh(struct g3d_mesh *mesh, float sz, int sub);
58 int gen_torus_mesh(struct g3d_mesh *mesh, float rad, float ringrad, int usub, int vsub);
59
60 #endif  /* MESH_H_ */