view src/goat3d.h @ 55:af1310ed212b

not done yet
author John Tsiombikas <nuclear@member.fsf.org>
date Sun, 19 Jan 2014 14:56:44 +0200
parents 498ca7ac7047
children 76d0f55f9d5f
line source
1 #ifndef GOAT3D_H_
2 #define GOAT3D_H_
4 #include <stdio.h>
5 #include <stdlib.h>
7 #ifdef WIN32
8 #define GOAT3DAPI __declspec(dllexport)
9 #else
10 #define GOAT3DAPI
11 #endif
13 #define GOAT3D_MAT_ATTR_DIFFUSE "diffuse"
14 #define GOAT3D_MAT_ATTR_SPECULAR "specular"
15 #define GOAT3D_MAT_ATTR_SHININESS "shininess"
16 #define GOAT3D_MAT_ATTR_NORMAL "normal"
17 #define GOAT3D_MAT_ATTR_BUMP "bump"
18 #define GOAT3D_MAT_ATTR_REFLECTION "reflection"
19 #define GOAT3D_MAT_ATTR_TRANSMISSION "transmission"
20 #define GOAT3D_MAT_ATTR_IOR "ior"
21 #define GOAT3D_MAT_ATTR_ALPHA "alpha"
23 enum goat3d_mesh_attrib {
33 };
35 enum goat3d_node_type {
40 };
42 /* immediate mode mesh construction primitive type */
43 enum goat3d_im_primitive {
46 };
49 enum goat3d_option {
50 GOAT3D_OPT_SAVEXML, /* save in XML format */
53 };
55 struct goat3d;
56 struct goat3d_material;
57 struct goat3d_mesh;
58 struct goat3d_light;
59 struct goat3d_camera;
60 struct goat3d_node;
62 struct goat3d_io {
63 void *cls; /* closure data */
65 long (*read)(void *buf, size_t bytes, void *uptr);
66 long (*write)(const void *buf, size_t bytes, void *uptr);
67 long (*seek)(long offs, int whence, void *uptr);
68 };
70 #ifdef __cplusplus
71 extern "C" {
72 #endif
74 /* construction/destruction */
75 GOAT3DAPI struct goat3d *goat3d_create(void);
76 GOAT3DAPI void goat3d_free(struct goat3d *g);
78 GOAT3DAPI void goat3d_setopt(struct goat3d *g, enum goat3d_option opt, int val);
79 GOAT3DAPI int goat3d_getopt(const struct goat3d *g, enum goat3d_option opt);
81 /* load/save */
82 GOAT3DAPI int goat3d_load(struct goat3d *g, const char *fname);
83 GOAT3DAPI int goat3d_save(const struct goat3d *g, const char *fname);
85 GOAT3DAPI int goat3d_load_file(struct goat3d *g, FILE *fp);
86 GOAT3DAPI int goat3d_save_file(const struct goat3d *g, FILE *fp);
88 GOAT3DAPI int goat3d_load_io(struct goat3d *g, struct goat3d_io *io);
89 GOAT3DAPI int goat3d_save_io(const struct goat3d *g, struct goat3d_io *io);
91 /* load/save animation files (g must already be loaded to load animations) */
92 GOAT3DAPI int goat3d_load_anim(struct goat3d *g, const char *fname);
93 GOAT3DAPI int goat3d_save_anim(const struct goat3d *g, const char *fname);
95 GOAT3DAPI int goat3d_load_anim_file(struct goat3d *g, FILE *fp);
96 GOAT3DAPI int goat3d_save_anim_file(const struct goat3d *g, FILE *fp);
98 GOAT3DAPI int goat3d_load_anim_io(struct goat3d *g, struct goat3d_io *io);
99 GOAT3DAPI int goat3d_save_anim_io(const struct goat3d *g, struct goat3d_io *io);
101 /* misc scene properties */
102 GOAT3DAPI int goat3d_set_name(struct goat3d *g, const char *name);
103 GOAT3DAPI const char *goat3d_get_name(const struct goat3d *g);
105 GOAT3DAPI void goat3d_set_ambient(struct goat3d *g, const float *ambient);
106 GOAT3DAPI void goat3d_set_ambient3f(struct goat3d *g, float ar, float ag, float ab);
107 GOAT3DAPI const float *goat3d_get_ambient(const struct goat3d *g);
109 /* materials */
110 GOAT3DAPI void goat3d_add_mtl(struct goat3d *g, struct goat3d_material *mtl);
112 GOAT3DAPI struct goat3d_material *goat3d_create_mtl(void);
113 GOAT3DAPI void goat3d_destroy_mtl(struct goat3d_material *mtl);
115 GOAT3DAPI void goat3d_set_mtl_name(struct goat3d_material *mtl, const char *name);
116 GOAT3DAPI const char *goat3d_get_mtl_name(const struct goat3d_material *mtl);
118 GOAT3DAPI void goat3d_set_mtl_attrib(struct goat3d_material *mtl, const char *attrib, const float *val);
119 GOAT3DAPI void goat3d_set_mtl_attrib1f(struct goat3d_material *mtl, const char *attrib, float val);
120 GOAT3DAPI void goat3d_set_mtl_attrib3f(struct goat3d_material *mtl, const char *attrib, float r, float g, float b);
121 GOAT3DAPI void goat3d_set_mtl_attrib4f(struct goat3d_material *mtl, const char *attrib, float r, float g, float b, float a);
122 GOAT3DAPI const float *goat3d_get_mtl_attrib(struct goat3d_material *mtl, const char *attrib);
124 GOAT3DAPI void goat3d_set_mtl_attrib_map(struct goat3d_material *mtl, const char *attrib, const char *mapname);
125 GOAT3DAPI const char *goat3d_get_mtl_attrib_map(struct goat3d_material *mtl, const char *attrib);
127 /* meshes */
128 GOAT3DAPI void goat3d_add_mesh(struct goat3d *g, struct goat3d_mesh *mesh);
129 GOAT3DAPI int goat3d_get_mesh_count(struct goat3d *g);
130 GOAT3DAPI struct goat3d_mesh *goat3d_get_mesh(struct goat3d *g, int idx);
131 GOAT3DAPI struct goat3d_mesh *goat3d_get_mesh_by_name(struct goat3d *g, const char *name);
133 GOAT3DAPI struct goat3d_mesh *goat3d_create_mesh(void);
134 GOAT3DAPI void goat3d_destroy_mesh(struct goat3d_mesh *mesh);
136 GOAT3DAPI void goat3d_set_mesh_name(struct goat3d_mesh *mesh, const char *name);
137 GOAT3DAPI const char *goat3d_get_mesh_name(const struct goat3d_mesh *mesh);
139 GOAT3DAPI void goat3d_set_mesh_mtl(struct goat3d_mesh *mesh, struct goat3d_material *mtl);
140 GOAT3DAPI struct goat3d_material *goat3d_get_mesh_mtl(struct goat3d_mesh *mesh);
142 GOAT3DAPI int goat3d_get_mesh_attrib_count(struct goat3d_mesh *mesh, enum goat3d_mesh_attrib attrib);
143 GOAT3DAPI int goat3d_get_mesh_face_count(struct goat3d_mesh *mesh);
145 /* sets all the data for a single vertex attribute array in one go.
146 * vnum is the number of *vertices* to be set, not the number of floats, ints or whatever
147 * data is expected to be something different depending on the attribute:
148 * - GOAT3D_MESH_ATTR_VERTEX - 3 floats per vertex
149 * - GOAT3D_MESH_ATTR_NORMAL - 3 floats per vertex
150 * - GOAT3D_MESH_ATTR_TANGENT - 3 floats per vertex
151 * - GOAT3D_MESH_ATTR_TEXCOORD - 2 floats per vertex
152 * - GOAT3D_MESH_ATTR_SKIN_WEIGHT - 4 floats per vertex
153 * - GOAT3D_MESH_ATTR_SKIN_MATRIX - 4 ints per vertex
154 * - GOAT3D_MESH_ATTR_COLOR - 4 floats per vertex
155 */
156 GOAT3DAPI void goat3d_set_mesh_attribs(struct goat3d_mesh *mesh, enum goat3d_mesh_attrib attrib,
157 const void *data, int vnum);
158 GOAT3DAPI void goat3d_add_mesh_attrib1f(struct goat3d_mesh *mesh, enum goat3d_mesh_attrib attrib, float val);
159 GOAT3DAPI void goat3d_add_mesh_attrib3f(struct goat3d_mesh *mesh, enum goat3d_mesh_attrib attrib,
160 float x, float y, float z);
161 GOAT3DAPI void goat3d_add_mesh_attrib4f(struct goat3d_mesh *mesh, enum goat3d_mesh_attrib attrib,
162 float x, float y, float z, float w);
163 /* returns a pointer to the beginning of the requested mesh attribute array */
164 GOAT3DAPI void *goat3d_get_mesh_attribs(struct goat3d_mesh *mesh, enum goat3d_mesh_attrib attrib);
165 /* returns a pointer to the requested mesh attribute */
166 GOAT3DAPI void *goat3d_get_mesh_attrib(struct goat3d_mesh *mesh, enum goat3d_mesh_attrib attrib, int idx);
168 /* sets all the faces in one go. data is an array of 3 int vertex indices per face */
169 GOAT3DAPI void goat3d_set_mesh_faces(struct goat3d_mesh *mesh, const int *data, int fnum);
170 GOAT3DAPI void goat3d_add_mesh_face(struct goat3d_mesh *mesh, int a, int b, int c);
171 /* returns a pointer to the beginning of the face index array */
172 GOAT3DAPI int *goat3d_get_mesh_faces(struct goat3d_mesh *mesh);
173 /* returns a pointer to a face index */
174 GOAT3DAPI int *goat3d_get_mesh_face(struct goat3d_mesh *mesh, int idx);
176 /* immediate mode OpenGL-like interface for setting mesh data
177 * NOTE: using this interface will result in no vertex sharing between faces
178 * NOTE2: the immedate mode interface is not thread-safe, either use locks, or don't
179 * use it at all in multithreaded situations.
180 */
181 GOAT3DAPI void goat3d_begin(struct goat3d_mesh *mesh, enum goat3d_im_primitive prim);
182 GOAT3DAPI void goat3d_end(void);
183 GOAT3DAPI void goat3d_vertex3f(float x, float y, float z);
184 GOAT3DAPI void goat3d_normal3f(float x, float y, float z);
185 GOAT3DAPI void goat3d_tangent3f(float x, float y, float z);
186 GOAT3DAPI void goat3d_texcoord2f(float x, float y);
187 GOAT3DAPI void goat3d_skin_weight4f(float x, float y, float z, float w);
188 GOAT3DAPI void goat3d_skin_matrix4i(int x, int y, int z, int w);
189 GOAT3DAPI void goat3d_color3f(float x, float y, float z);
190 GOAT3DAPI void goat3d_color4f(float x, float y, float z, float w);
192 /* lights */
193 GOAT3DAPI void goat3d_add_light(struct goat3d *g, struct goat3d_light *lt);
194 GOAT3DAPI int goat3d_get_light_count(struct goat3d *g);
195 GOAT3DAPI struct goat3d_light *goat3d_get_light(struct goat3d *g, int idx);
196 GOAT3DAPI struct goat3d_light *goat3d_get_light_by_name(struct goat3d *g, const char *name);
198 GOAT3DAPI struct goat3d_light *goat3d_create_light(void);
199 GOAT3DAPI void goat3d_destroy_light(struct goat3d_light *lt);
201 /* cameras */
202 GOAT3DAPI void goat3d_add_camera(struct goat3d *g, struct goat3d_camera *cam);
203 GOAT3DAPI int goat3d_get_camera_count(struct goat3d *g);
204 GOAT3DAPI struct goat3d_camera *goat3d_get_camera(struct goat3d *g, int idx);
205 GOAT3DAPI struct goat3d_camera *goat3d_get_camera_by_name(struct goat3d *g, const char *name);
207 GOAT3DAPI struct goat3d_camera *goat3d_create_camera(void);
208 GOAT3DAPI void goat3d_destroy_camera(struct goat3d_camera *cam);
210 /* nodes */
211 GOAT3DAPI void goat3d_add_node(struct goat3d *g, struct goat3d_node *node);
212 GOAT3DAPI int goat3d_get_node_count(struct goat3d *g);
213 GOAT3DAPI struct goat3d_node *goat3d_get_node(struct goat3d *g, int idx);
214 GOAT3DAPI struct goat3d_node *goat3d_get_node_by_name(struct goat3d *g, const char *name);
216 GOAT3DAPI struct goat3d_node *goat3d_create_node(void);
217 GOAT3DAPI void goat3d_destroy_node(struct goat3d_node *node);
219 GOAT3DAPI void goat3d_set_node_name(struct goat3d_node *node, const char *name);
220 GOAT3DAPI const char *goat3d_get_node_name(const struct goat3d_node *node);
222 GOAT3DAPI void goat3d_set_node_object(struct goat3d_node *node, enum goat3d_node_type type, void *obj);
223 GOAT3DAPI void *goat3d_get_node_object(const struct goat3d_node *node);
224 GOAT3DAPI enum goat3d_node_type goat3d_get_node_type(const struct goat3d_node *node);
226 GOAT3DAPI void goat3d_add_node_child(struct goat3d_node *node, struct goat3d_node *child);
227 GOAT3DAPI int goat3d_get_node_child_count(const struct goat3d_node *node);
228 GOAT3DAPI struct goat3d_node *goat3d_get_node_child(const struct goat3d_node *node, int idx);
229 GOAT3DAPI struct goat3d_node *goat3d_get_node_parent(const struct goat3d_node *node);
231 GOAT3DAPI void goat3d_use_anim(struct goat3d_node *node, int idx);
232 GOAT3DAPI void goat3d_use_anims(struct goat3d_node *node, int aidx, int bidx, float t);
233 GOAT3DAPI void goat3d_use_anim_by_name(struct goat3d_node *node, const char *name);
234 GOAT3DAPI void goat3d_use_anims_by_name(struct goat3d_node *node, const char *aname, const char *bname, float t);
236 GOAT3DAPI int goat3d_get_active_anim(struct goat3d_node *node, int which);
237 GOAT3DAPI float goat3d_get_active_anim_mix(struct goat3d_node *node);
239 GOAT3DAPI int goat3d_get_anim_count(struct goat3d_node *node);
240 GOAT3DAPI void goat3d_add_anim(struct goat3d_node *root);
242 GOAT3DAPI void goat3d_set_anim_name(struct goat3d_node *root, const char *name);
243 GOAT3DAPI const char *goat3d_get_anim_name(struct goat3d_node *node);
245 GOAT3DAPI void goat3d_set_node_position(struct goat3d_node *node, float x, float y, float z, long tmsec);
246 GOAT3DAPI void goat3d_set_node_rotation(struct goat3d_node *node, float qx, float qy, float qz, float qw, long tmsec);
247 GOAT3DAPI void goat3d_set_node_scaling(struct goat3d_node *node, float sx, float sy, float sz, long tmsec);
248 GOAT3DAPI void goat3d_set_node_pivot(struct goat3d_node *node, float px, float py, float pz);
250 GOAT3DAPI void goat3d_get_node_position(const struct goat3d_node *node, float *xptr, float *yptr, float *zptr, long tmsec);
251 GOAT3DAPI void goat3d_get_node_rotation(const struct goat3d_node *node, float *xptr, float *yptr, float *zptr, float *wptr, long tmsec);
252 GOAT3DAPI void goat3d_get_node_scaling(const struct goat3d_node *node, float *xptr, float *yptr, float *zptr, long tmsec);
253 GOAT3DAPI void goat3d_get_node_pivot(const struct goat3d_node *node, float *xptr, float *yptr, float *zptr);
255 GOAT3DAPI void goat3d_get_node_matrix(const struct goat3d_node *node, float *matrix, long tmsec);
257 #ifdef __cplusplus
258 }
259 #endif
261 #endif /* GOAT3D_H_ */