goat3d

view src/goat3d.h @ 40:a5c5cec3cb88

- added mesh attribute and face append functions - added Int4 constructor - continued the blender exporter - fixed a bug in clean_filename which made it produce unterminated strings - renamed clean_filename to goat3d_clean_filename and made it extern - added call to goat3d_clean_filename in the mesh XML export code to cleanup ctm filenames
author John Tsiombikas <nuclear@member.fsf.org>
date Sun, 13 Oct 2013 10:14:19 +0300
parents 4deb0b12fe14
children da3f335e0069
line source
1 #ifndef GOAT3D_H_
2 #define GOAT3D_H_
4 #include <stdio.h>
5 #include <stdlib.h>
7 #define GOAT3D_MAT_ATTR_DIFFUSE "diffuse"
8 #define GOAT3D_MAT_ATTR_SPECULAR "specular"
9 #define GOAT3D_MAT_ATTR_SHININESS "shininess"
10 #define GOAT3D_MAT_ATTR_NORMAL "normal"
11 #define GOAT3D_MAT_ATTR_BUMP "bump"
12 #define GOAT3D_MAT_ATTR_REFLECTION "reflection"
13 #define GOAT3D_MAT_ATTR_TRANSMISSION "transmission"
14 #define GOAT3D_MAT_ATTR_IOR "ior"
15 #define GOAT3D_MAT_ATTR_ALPHA "alpha"
17 enum goat3d_mesh_attrib {
18 GOAT3D_MESH_ATTR_VERTEX,
19 GOAT3D_MESH_ATTR_NORMAL,
20 GOAT3D_MESH_ATTR_TANGENT,
21 GOAT3D_MESH_ATTR_TEXCOORD,
22 GOAT3D_MESH_ATTR_SKIN_WEIGHT,
23 GOAT3D_MESH_ATTR_SKIN_MATRIX,
24 GOAT3D_MESH_ATTR_COLOR,
26 NUM_GOAT3D_MESH_ATTRIBS
27 };
29 enum goat3d_node_type {
30 GOAT3D_NODE_NULL,
31 GOAT3D_NODE_MESH,
32 GOAT3D_NODE_LIGHT,
33 GOAT3D_NODE_CAMERA
34 };
36 /* immediate mode mesh construction primitive type */
37 enum goat3d_im_primitive {
38 GOAT3D_TRIANGLES,
39 GOAT3D_QUADS
40 };
43 enum goat3d_option {
44 GOAT3D_OPT_SAVEXML, /* save in XML format */
46 NUM_GOAT3D_OPTIONS
47 };
49 struct goat3d;
50 struct goat3d_material;
51 struct goat3d_mesh;
52 struct goat3d_light;
53 struct goat3d_camera;
54 struct goat3d_node;
56 struct goat3d_io {
57 void *cls; /* closure data */
59 long (*read)(void *buf, size_t bytes, void *uptr);
60 long (*write)(const void *buf, size_t bytes, void *uptr);
61 long (*seek)(long offs, int whence, void *uptr);
62 };
64 #ifdef __cplusplus
65 extern "C" {
66 #endif
68 /* construction/destruction */
69 struct goat3d *goat3d_create(void);
70 void goat3d_free(struct goat3d *g);
72 void goat3d_setopt(struct goat3d *g, enum goat3d_option opt, int val);
73 int goat3d_getopt(const struct goat3d *g, enum goat3d_option opt);
75 /* load/save */
76 int goat3d_load(struct goat3d *g, const char *fname);
77 int goat3d_save(const struct goat3d *g, const char *fname);
79 int goat3d_load_file(struct goat3d *g, FILE *fp);
80 int goat3d_save_file(const struct goat3d *g, FILE *fp);
82 int goat3d_load_io(struct goat3d *g, struct goat3d_io *io);
83 int goat3d_save_io(const struct goat3d *g, struct goat3d_io *io);
85 /* misc scene properties */
86 int goat3d_set_name(struct goat3d *g, const char *name);
87 const char *goat3d_get_name(const struct goat3d *g);
89 void goat3d_set_ambient(struct goat3d *g, const float *ambient);
90 void goat3d_set_ambient3f(struct goat3d *g, float ar, float ag, float ab);
91 const float *goat3d_get_ambient(const struct goat3d *g);
93 /* materials */
94 void goat3d_add_mtl(struct goat3d *g, struct goat3d_material *mtl);
96 struct goat3d_material *goat3d_create_mtl(void);
97 void goat3d_destroy_mtl(struct goat3d_material *mtl);
99 void goat3d_set_mtl_name(struct goat3d_material *mtl, const char *name);
100 const char *goat3d_get_mtl_name(const struct goat3d_material *mtl);
102 void goat3d_set_mtl_attrib(struct goat3d_material *mtl, const char *attrib, const float *val);
103 void goat3d_set_mtl_attrib1f(struct goat3d_material *mtl, const char *attrib, float val);
104 void goat3d_set_mtl_attrib3f(struct goat3d_material *mtl, const char *attrib, float r, float g, float b);
105 void goat3d_set_mtl_attrib4f(struct goat3d_material *mtl, const char *attrib, float r, float g, float b, float a);
106 const float *goat3d_get_mtl_attrib(struct goat3d_material *mtl, const char *attrib);
108 void goat3d_set_mtl_attrib_map(struct goat3d_material *mtl, const char *attrib, const char *mapname);
109 const char *goat3d_get_mtl_attrib_map(struct goat3d_material *mtl, const char *attrib);
111 /* meshes */
112 void goat3d_add_mesh(struct goat3d *g, struct goat3d_mesh *mesh);
113 int goat3d_get_mesh_count(struct goat3d *g);
114 struct goat3d_mesh *goat3d_get_mesh(struct goat3d *g, int idx);
115 struct goat3d_mesh *goat3d_get_mesh_by_name(struct goat3d *g, const char *name);
117 struct goat3d_mesh *goat3d_create_mesh(void);
118 void goat3d_destroy_mesh(struct goat3d_mesh *mesh);
120 void goat3d_set_mesh_name(struct goat3d_mesh *mesh, const char *name);
121 const char *goat3d_get_mesh_name(const struct goat3d_mesh *mesh);
123 void goat3d_set_mesh_mtl(struct goat3d_mesh *mesh, struct goat3d_material *mtl);
124 struct goat3d_material *goat3d_get_mesh_mtl(struct goat3d_mesh *mesh);
126 int goat3d_get_mesh_attrib_count(struct goat3d_mesh *mesh, enum goat3d_mesh_attrib attrib);
127 int goat3d_get_mesh_face_count(struct goat3d_mesh *mesh);
129 /* sets all the data for a single vertex attribute array in one go.
130 * vnum is the number of *vertices* to be set, not the number of floats, ints or whatever
131 * data is expected to be something different depending on the attribute:
132 * - GOAT3D_MESH_ATTR_VERTEX - 3 floats per vertex
133 * - GOAT3D_MESH_ATTR_NORMAL - 3 floats per vertex
134 * - GOAT3D_MESH_ATTR_TANGENT - 3 floats per vertex
135 * - GOAT3D_MESH_ATTR_TEXCOORD - 2 floats per vertex
136 * - GOAT3D_MESH_ATTR_SKIN_WEIGHT - 4 floats per vertex
137 * - GOAT3D_MESH_ATTR_SKIN_MATRIX - 4 ints per vertex
138 * - GOAT3D_MESH_ATTR_COLOR - 4 floats per vertex
139 */
140 void goat3d_set_mesh_attribs(struct goat3d_mesh *mesh, enum goat3d_mesh_attrib attrib,
141 const void *data, int vnum);
142 void goat3d_add_mesh_attrib1f(struct goat3d_mesh *mesh, enum goat3d_mesh_attrib attrib, float val);
143 void goat3d_add_mesh_attrib3f(struct goat3d_mesh *mesh, enum goat3d_mesh_attrib attrib,
144 float x, float y, float z);
145 void goat3d_add_mesh_attrib4f(struct goat3d_mesh *mesh, enum goat3d_mesh_attrib attrib,
146 float x, float y, float z, float w);
147 /* returns a pointer to the beginning of the requested mesh attribute array */
148 void *goat3d_get_mesh_attribs(struct goat3d_mesh *mesh, enum goat3d_mesh_attrib attrib);
149 /* returns a pointer to the requested mesh attribute */
150 void *goat3d_get_mesh_attrib(struct goat3d_mesh *mesh, enum goat3d_mesh_attrib attrib, int idx);
152 /* sets all the faces in one go. data is an array of 3 int vertex indices per face */
153 void goat3d_set_mesh_faces(struct goat3d_mesh *mesh, const int *data, int fnum);
154 void goat3d_add_mesh_face(struct goat3d_mesh *mesh, int a, int b, int c);
155 /* returns a pointer to the beginning of the face index array */
156 int *goat3d_get_mesh_faces(struct goat3d_mesh *mesh);
157 /* returns a pointer to a face index */
158 int *goat3d_get_mesh_face(struct goat3d_mesh *mesh, int idx);
160 /* immediate mode OpenGL-like interface for setting mesh data
161 * NOTE: using this interface will result in no vertex sharing between faces
162 * NOTE2: the immedate mode interface is not thread-safe, either use locks, or don't
163 * use it at all in multithreaded situations.
164 */
165 void goat3d_begin(struct goat3d_mesh *mesh, enum goat3d_im_primitive prim);
166 void goat3d_end(void);
167 void goat3d_vertex3f(float x, float y, float z);
168 void goat3d_normal3f(float x, float y, float z);
169 void goat3d_tangent3f(float x, float y, float z);
170 void goat3d_texcoord2f(float x, float y);
171 void goat3d_skin_weight4f(float x, float y, float z, float w);
172 void goat3d_skin_matrix4i(int x, int y, int z, int w);
173 void goat3d_color3f(float x, float y, float z);
174 void goat3d_color4f(float x, float y, float z, float w);
176 /* lights */
177 void goat3d_add_light(struct goat3d *g, struct goat3d_light *lt);
178 int goat3d_get_light_count(struct goat3d *g);
179 struct goat3d_light *goat3d_get_light(struct goat3d *g, int idx);
180 struct goat3d_light *goat3d_get_light_by_name(struct goat3d *g, const char *name);
182 struct goat3d_light *goat3d_create_light(void);
183 void goat3d_destroy_light(struct goat3d_light *lt);
185 /* cameras */
186 void goat3d_add_camera(struct goat3d *g, struct goat3d_camera *cam);
187 int goat3d_get_camera_count(struct goat3d *g);
188 struct goat3d_camera *goat3d_get_camera(struct goat3d *g, int idx);
189 struct goat3d_camera *goat3d_get_camera_by_name(struct goat3d *g, const char *name);
191 struct goat3d_camera *goat3d_create_camera(void);
192 void goat3d_destroy_camera(struct goat3d_camera *cam);
194 /* nodes */
195 void goat3d_add_node(struct goat3d *g, struct goat3d_node *node);
196 int goat3d_get_node_count(struct goat3d *g);
197 struct goat3d_node *goat3d_get_node(struct goat3d *g, int idx);
198 struct goat3d_node *goat3d_get_node_by_name(struct goat3d *g, const char *name);
200 struct goat3d_node *goat3d_create_node(void);
201 void goat3d_destroy_node(struct goat3d_node *node);
203 void goat3d_set_node_name(struct goat3d_node *node, const char *name);
204 const char *goat3d_get_node_name(const struct goat3d_node *node);
206 void goat3d_set_node_object(struct goat3d_node *node, enum goat3d_node_type type, void *obj);
207 void *goat3d_get_node_object(const struct goat3d_node *node);
208 enum goat3d_node_type goat3d_get_node_type(const struct goat3d_node *node);
210 void goat3d_add_node_child(struct goat3d_node *node, struct goat3d_node *child);
211 int goat3d_get_node_child_count(const struct goat3d_node *node);
212 struct goat3d_node *goat3d_get_node_child(const struct goat3d_node *node, int idx);
214 void goat3d_set_node_position(struct goat3d_node *node, float x, float y, float z, long tmsec);
215 void goat3d_set_node_rotation(struct goat3d_node *node, float qx, float qy, float qz, float qw, long tmsec);
216 void goat3d_set_node_scaling(struct goat3d_node *node, float sx, float sy, float sz, long tmsec);
217 void goat3d_set_node_pivot(struct goat3d_node *node, float px, float py, float pz);
219 void goat3d_get_node_position(const struct goat3d_node *node, float *xptr, float *yptr, float *zptr, long tmsec);
220 void goat3d_get_node_rotation(const struct goat3d_node *node, float *xptr, float *yptr, float *zptr, float *wptr, long tmsec);
221 void goat3d_get_node_scaling(const struct goat3d_node *node, float *xptr, float *yptr, float *zptr, long tmsec);
222 void goat3d_get_node_pivot(const struct goat3d_node *node, float *xptr, float *yptr, float *zptr);
224 void goat3d_get_node_matrix(const struct goat3d_node *node, float *matrix, long tmsec);
226 #ifdef __cplusplus
227 }
228 #endif
230 #endif /* GOAT3D_H_ */