5 #include <cgmath/cgmath.h>
14 CMESH_ATTR_BONEWEIGHTS,
24 void cmesh_set_attrib_sdrloc(int attr, int loc);
25 int cmesh_get_attrib_sdrloc(int attr);
26 void cmesh_clear_attrib_sdrloc(void);
29 struct cmesh *cmesh_alloc(void);
30 void cmesh_free(struct cmesh *cm);
32 int cmesh_init(struct cmesh *cm);
33 void cmesh_destroy(struct cmesh *cm);
35 void cmesh_clear(struct cmesh *cm);
36 int cmesh_clone(struct cmesh *cmdest, struct cmesh *cmsrc);
38 int cmesh_set_name(struct cmesh *cm, const char *name);
39 const char *cmesh_name(struct cmesh *cm);
41 int cmesh_has_attrib(struct cmesh *cm, int attr);
42 int cmesh_indexed(struct cmesh *cm);
44 /* vdata can be 0, in which case only memory is allocated
45 * returns pointer to the attribute array
47 float *cmesh_set_attrib(struct cmesh *cm, int attr, int nelem, unsigned int num,
49 float *cmesh_attrib(struct cmesh *cm, int attr); /* invalidates VBO */
50 const float *cmesh_attrib_ro(struct cmesh *cm, int attr); /* doesn't invalidate */
51 float *cmesh_attrib_at(struct cmesh *cm, int attr, int idx);
52 const float *cmesh_attrib_at_ro(struct cmesh *cm, int attr, int idx);
53 int cmesh_attrib_count(struct cmesh *cm, int attr);
54 int cmesh_push_attrib(struct cmesh *cm, int attr, float *v);
55 int cmesh_push_attrib1f(struct cmesh *cm, int attr, float x);
56 int cmesh_push_attrib2f(struct cmesh *cm, int attr, float x, float y);
57 int cmesh_push_attrib3f(struct cmesh *cm, int attr, float x, float y, float z);
58 int cmesh_push_attrib4f(struct cmesh *cm, int attr, float x, float y, float z, float w);
60 /* indices can be 0, in which case only memory is allocated
61 * returns pointer to the index array
63 unsigned int *cmesh_set_index(struct cmesh *cm, int num, const unsigned int *indices);
64 unsigned int *cmesh_index(struct cmesh *cm); /* invalidates IBO */
65 const unsigned int *cmesh_index_ro(struct cmesh *cm); /* doesn't invalidate */
66 int cmesh_index_count(struct cmesh *cm);
67 int cmesh_push_index(struct cmesh *cm, unsigned int idx);
69 int cmesh_poly_count(struct cmesh *cm);
71 /* attr can be -1 to invalidate all attributes */
72 void cmesh_invalidate_vbo(struct cmesh *cm, int attr);
73 void cmesh_invalidate_ibo(struct cmesh *cm);
75 int cmesh_append(struct cmesh *cmdest, struct cmesh *cmsrc);
77 /* immediate-mode style mesh construction interface */
78 int cmesh_vertex(struct cmesh *cm, float x, float y, float z);
79 void cmesh_normal(struct cmesh *cm, float nx, float ny, float nz);
80 void cmesh_tangent(struct cmesh *cm, float tx, float ty, float tz);
81 void cmesh_texcoord(struct cmesh *cm, float u, float v, float w);
82 void cmesh_boneweights(struct cmesh *cm, float w1, float w2, float w3, float w4);
83 void cmesh_boneidx(struct cmesh *cm, int idx1, int idx2, int idx3, int idx4);
85 /* dir_xform can be null, in which case it's calculated from xform */
86 void cmesh_apply_xform(struct cmesh *cm, float *xform, float *dir_xform);
88 void cmesh_flip(struct cmesh *cm); /* flip faces (winding) and normals */
89 void cmesh_flip_faces(struct cmesh *cm);
90 void cmesh_flip_normals(struct cmesh *cm);
92 int cmesh_explode(struct cmesh *cm); /* undo all vertex sharing */
94 /* this is only guaranteed to work on an exploded mesh */
95 void cmesh_calc_face_normals(struct cmesh *cm);
97 void cmesh_draw(struct cmesh *cm);
98 void cmesh_draw_wire(struct cmesh *cm, float linesz);
99 void cmesh_draw_vertices(struct cmesh *cm, float ptsz);
100 void cmesh_draw_normals(struct cmesh *cm, float len);
101 void cmesh_draw_tangents(struct cmesh *cm, float len);
103 /* get the bounding box in local space. The result will be cached and subsequent
104 * calls will return the same box. The cache gets invalidated by any functions that
105 * can affect the vertex data
107 void cmesh_aabbox(struct cmesh *cm, cgm_vec3 *vmin, cgm_vec3 *vmax);
109 /* get the bounding sphere in local space. The result will be cached ... see above */
110 float cmesh_bsphere(struct cmesh *cm, cgm_vec3 *center, float *rad);
112 /* texture coordinate manipulation */
113 void cmesh_texcoord_apply_xform(struct cmesh *cm, float *xform);
114 void cmesh_texcoord_gen_plane(struct cmesh *cm, cgm_vec3 *norm, cgm_vec3 *tang);
115 void cmesh_texcoord_gen_box(struct cmesh *cm);
116 void cmesh_texcoord_gen_cylinder(struct cmesh *cm);
119 int cmesh_load(struct cmesh *cm, const char *fname);
121 int cmesh_dump(struct cmesh *cm, const char *fname);
122 int cmesh_dump_file(struct cmesh *cm, FILE *fp);
123 int cmesh_dump_obj(struct cmesh *cm, const char *fname);
124 int cmesh_dump_obj_file(struct cmesh *cm, FILE *fp, int voffs);
128 #endif /* CMESH_H_ */