5 #include "cgmath/cgmath.h"
13 CMESH_ATTR_BONEWEIGHTS,
27 void cmesh_set_attrib_sdrloc(int attr, int loc);
28 int cmesh_get_attrib_sdrloc(int attr);
29 void cmesh_clear_attrib_sdrloc(void);
32 struct cmesh *cmesh_alloc(void);
33 void cmesh_free(struct cmesh *cm);
35 int cmesh_init(struct cmesh *cm);
36 void cmesh_destroy(struct cmesh *cm);
38 void cmesh_clear(struct cmesh *cm);
39 int cmesh_clone(struct cmesh *cmdest, const struct cmesh *cmsrc);
41 int cmesh_set_name(struct cmesh *cm, const char *name);
42 const char *cmesh_name(const struct cmesh *cm);
44 int cmesh_has_attrib(const struct cmesh *cm, int attr);
45 int cmesh_indexed(const struct cmesh *cm);
47 /* vdata can be 0, in which case only memory is allocated
48 * returns pointer to the attribute array
50 float *cmesh_set_attrib(struct cmesh *cm, int attr, int nelem, unsigned int num,
52 float *cmesh_attrib(struct cmesh *cm, int attr); /* invalidates VBO */
53 const float *cmesh_attrib_ro(const struct cmesh *cm, int attr); /* doesn't invalidate */
54 float *cmesh_attrib_at(struct cmesh *cm, int attr, int idx);
55 const float *cmesh_attrib_at_ro(const struct cmesh *cm, int attr, int idx);
56 int cmesh_attrib_count(const struct cmesh *cm, int attr);
57 int cmesh_attrib_nelem(const struct cmesh *cm, int attr);
58 int cmesh_push_attrib(struct cmesh *cm, int attr, float *v);
59 int cmesh_push_attrib1f(struct cmesh *cm, int attr, float x);
60 int cmesh_push_attrib2f(struct cmesh *cm, int attr, float x, float y);
61 int cmesh_push_attrib3f(struct cmesh *cm, int attr, float x, float y, float z);
62 int cmesh_push_attrib4f(struct cmesh *cm, int attr, float x, float y, float z, float w);
64 /* indices can be 0, in which case only memory is allocated
65 * returns pointer to the index array
67 unsigned int *cmesh_set_index(struct cmesh *cm, int num, const unsigned int *indices);
68 unsigned int *cmesh_index(struct cmesh *cm); /* invalidates IBO */
69 const unsigned int *cmesh_index_ro(const struct cmesh *cm); /* doesn't invalidate */
70 int cmesh_index_count(const struct cmesh *cm);
71 int cmesh_push_index(struct cmesh *cm, unsigned int idx);
73 int cmesh_poly_count(const struct cmesh *cm);
75 /* attr can be -1 to invalidate all attributes */
76 void cmesh_invalidate_vbo(struct cmesh *cm, int attr);
77 void cmesh_invalidate_ibo(struct cmesh *cm);
79 int cmesh_append(struct cmesh *cmdest, const struct cmesh *cmsrc);
82 void cmesh_clear_submeshes(struct cmesh *cm);
83 /* a submesh is defined as a consecutive range of faces */
84 int cmesh_submesh(struct cmesh *cm, const char *name, int fstart, int fcount);
85 int cmesh_remove_submesh(struct cmesh *cm, int idx);
86 int cmesh_find_submesh(const struct cmesh *cm, const char *name);
87 int cmesh_submesh_count(const struct cmesh *cm);
88 int cmesh_clone_submesh(struct cmesh *cmdest, const struct cmesh *cm, int subidx);
90 /* immediate-mode style mesh construction interface */
91 int cmesh_vertex(struct cmesh *cm, float x, float y, float z);
92 void cmesh_normal(struct cmesh *cm, float nx, float ny, float nz);
93 void cmesh_tangent(struct cmesh *cm, float tx, float ty, float tz);
94 void cmesh_texcoord(struct cmesh *cm, float u, float v, float w);
95 void cmesh_boneweights(struct cmesh *cm, float w1, float w2, float w3, float w4);
96 void cmesh_boneidx(struct cmesh *cm, int idx1, int idx2, int idx3, int idx4);
98 /* dir_xform can be null, in which case it's calculated from xform */
99 void cmesh_apply_xform(struct cmesh *cm, float *xform, float *dir_xform);
101 void cmesh_flip(struct cmesh *cm); /* flip faces (winding) and normals */
102 void cmesh_flip_faces(struct cmesh *cm);
103 void cmesh_flip_normals(struct cmesh *cm);
105 int cmesh_explode(struct cmesh *cm); /* undo all vertex sharing */
107 /* this is only guaranteed to work on an exploded mesh */
108 void cmesh_calc_face_normals(struct cmesh *cm);
110 void cmesh_draw(const struct cmesh *cm);
111 void cmesh_draw_range(const struct cmesh *cm, int start, int count);
112 void cmesh_draw_submesh(const struct cmesh *cm, int subidx); /* XXX only for indexed meshes currently */
113 void cmesh_draw_wire(const struct cmesh *cm, float linesz);
114 void cmesh_draw_vertices(const struct cmesh *cm, float ptsz);
115 void cmesh_draw_normals(const struct cmesh *cm, float len);
116 void cmesh_draw_tangents(const struct cmesh *cm, float len);
118 /* get the bounding box in local space. The result will be cached and subsequent
119 * calls will return the same box. The cache gets invalidated by any functions that
120 * can affect the vertex data
122 void cmesh_aabbox(const struct cmesh *cm, cgm_vec3 *vmin, cgm_vec3 *vmax);
124 /* get the bounding sphere in local space. The result will be cached ... see above */
125 float cmesh_bsphere(const struct cmesh *cm, cgm_vec3 *center, float *rad);
127 /* texture coordinate manipulation */
128 void cmesh_texcoord_apply_xform(struct cmesh *cm, float *xform);
129 void cmesh_texcoord_gen_plane(struct cmesh *cm, cgm_vec3 *norm, cgm_vec3 *tang);
130 void cmesh_texcoord_gen_box(struct cmesh *cm);
131 void cmesh_texcoord_gen_cylinder(struct cmesh *cm);
134 int cmesh_load(struct cmesh *cm, const char *fname);
136 int cmesh_dump(const struct cmesh *cm, const char *fname);
137 int cmesh_dump_file(const struct cmesh *cm, FILE *fp);
138 int cmesh_dump_obj(const struct cmesh *cm, const char *fname);
139 int cmesh_dump_obj_file(const struct cmesh *cm, FILE *fp, int voffs);
146 #endif /* CMESH_H_ */