goat3d

annotate src/goat3d.h @ 67:8970ca3d55e0

merged
author John Tsiombikas <nuclear@member.fsf.org>
date Sat, 19 Apr 2014 08:01:37 +0300
parents dad392c710df 76d0f55f9d5f
children 9785847d52d4
rev   line source
nuclear@54 1 /*
nuclear@54 2 goat3d - 3D scene, character, and animation file format library.
nuclear@54 3 Copyright (C) 2013-2014 John Tsiombikas <nuclear@member.fsf.org>
nuclear@54 4
nuclear@54 5 This program is free software: you can redistribute it and/or modify
nuclear@54 6 it under the terms of the GNU Lesser General Public License as published by
nuclear@54 7 the Free Software Foundation, either version 3 of the License, or
nuclear@54 8 (at your option) any later version.
nuclear@54 9
nuclear@54 10 This program is distributed in the hope that it will be useful,
nuclear@54 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
nuclear@54 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
nuclear@54 13 GNU Lesser General Public License for more details.
nuclear@54 14
nuclear@54 15 You should have received a copy of the GNU Lesser General Public License
nuclear@54 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
nuclear@54 17 */
nuclear@0 18 #ifndef GOAT3D_H_
nuclear@0 19 #define GOAT3D_H_
nuclear@0 20
nuclear@0 21 #include <stdio.h>
nuclear@0 22 #include <stdlib.h>
nuclear@0 23
nuclear@41 24 #ifdef WIN32
nuclear@41 25 #define GOAT3DAPI __declspec(dllexport)
nuclear@41 26 #else
nuclear@43 27 #define GOAT3DAPI
nuclear@41 28 #endif
nuclear@41 29
nuclear@15 30 #define GOAT3D_MAT_ATTR_DIFFUSE "diffuse"
nuclear@15 31 #define GOAT3D_MAT_ATTR_SPECULAR "specular"
nuclear@15 32 #define GOAT3D_MAT_ATTR_SHININESS "shininess"
nuclear@15 33 #define GOAT3D_MAT_ATTR_NORMAL "normal"
nuclear@15 34 #define GOAT3D_MAT_ATTR_BUMP "bump"
nuclear@15 35 #define GOAT3D_MAT_ATTR_REFLECTION "reflection"
nuclear@15 36 #define GOAT3D_MAT_ATTR_TRANSMISSION "transmission"
nuclear@15 37 #define GOAT3D_MAT_ATTR_IOR "ior"
nuclear@40 38 #define GOAT3D_MAT_ATTR_ALPHA "alpha"
nuclear@15 39
nuclear@15 40 enum goat3d_mesh_attrib {
nuclear@15 41 GOAT3D_MESH_ATTR_VERTEX,
nuclear@15 42 GOAT3D_MESH_ATTR_NORMAL,
nuclear@15 43 GOAT3D_MESH_ATTR_TANGENT,
nuclear@15 44 GOAT3D_MESH_ATTR_TEXCOORD,
nuclear@15 45 GOAT3D_MESH_ATTR_SKIN_WEIGHT,
nuclear@15 46 GOAT3D_MESH_ATTR_SKIN_MATRIX,
nuclear@15 47 GOAT3D_MESH_ATTR_COLOR,
nuclear@15 48
nuclear@15 49 NUM_GOAT3D_MESH_ATTRIBS
nuclear@15 50 };
nuclear@15 51
nuclear@25 52 enum goat3d_node_type {
nuclear@26 53 GOAT3D_NODE_NULL,
nuclear@25 54 GOAT3D_NODE_MESH,
nuclear@25 55 GOAT3D_NODE_LIGHT,
nuclear@25 56 GOAT3D_NODE_CAMERA
nuclear@25 57 };
nuclear@25 58
nuclear@15 59 /* immediate mode mesh construction primitive type */
nuclear@15 60 enum goat3d_im_primitive {
nuclear@15 61 GOAT3D_TRIANGLES,
nuclear@15 62 GOAT3D_QUADS
nuclear@15 63 };
nuclear@15 64
nuclear@15 65
nuclear@15 66 enum goat3d_option {
nuclear@15 67 GOAT3D_OPT_SAVEXML, /* save in XML format */
nuclear@15 68
nuclear@15 69 NUM_GOAT3D_OPTIONS
nuclear@15 70 };
nuclear@15 71
nuclear@0 72 struct goat3d;
nuclear@15 73 struct goat3d_material;
nuclear@15 74 struct goat3d_mesh;
nuclear@15 75 struct goat3d_light;
nuclear@15 76 struct goat3d_camera;
nuclear@15 77 struct goat3d_node;
nuclear@0 78
nuclear@0 79 struct goat3d_io {
nuclear@0 80 void *cls; /* closure data */
nuclear@0 81
nuclear@11 82 long (*read)(void *buf, size_t bytes, void *uptr);
nuclear@13 83 long (*write)(const void *buf, size_t bytes, void *uptr);
nuclear@0 84 long (*seek)(long offs, int whence, void *uptr);
nuclear@0 85 };
nuclear@0 86
nuclear@0 87 #ifdef __cplusplus
nuclear@0 88 extern "C" {
nuclear@0 89 #endif
nuclear@0 90
nuclear@0 91 /* construction/destruction */
nuclear@41 92 GOAT3DAPI struct goat3d *goat3d_create(void);
nuclear@41 93 GOAT3DAPI void goat3d_free(struct goat3d *g);
nuclear@0 94
nuclear@41 95 GOAT3DAPI void goat3d_setopt(struct goat3d *g, enum goat3d_option opt, int val);
nuclear@41 96 GOAT3DAPI int goat3d_getopt(const struct goat3d *g, enum goat3d_option opt);
nuclear@15 97
nuclear@0 98 /* load/save */
nuclear@41 99 GOAT3DAPI int goat3d_load(struct goat3d *g, const char *fname);
nuclear@41 100 GOAT3DAPI int goat3d_save(const struct goat3d *g, const char *fname);
nuclear@0 101
nuclear@41 102 GOAT3DAPI int goat3d_load_file(struct goat3d *g, FILE *fp);
nuclear@41 103 GOAT3DAPI int goat3d_save_file(const struct goat3d *g, FILE *fp);
nuclear@0 104
nuclear@41 105 GOAT3DAPI int goat3d_load_io(struct goat3d *g, struct goat3d_io *io);
nuclear@41 106 GOAT3DAPI int goat3d_save_io(const struct goat3d *g, struct goat3d_io *io);
nuclear@0 107
nuclear@47 108 /* load/save animation files (g must already be loaded to load animations) */
nuclear@47 109 GOAT3DAPI int goat3d_load_anim(struct goat3d *g, const char *fname);
nuclear@55 110 GOAT3DAPI int goat3d_save_anim(const struct goat3d *g, const char *fname);
nuclear@47 111
nuclear@47 112 GOAT3DAPI int goat3d_load_anim_file(struct goat3d *g, FILE *fp);
nuclear@55 113 GOAT3DAPI int goat3d_save_anim_file(const struct goat3d *g, FILE *fp);
nuclear@47 114
nuclear@47 115 GOAT3DAPI int goat3d_load_anim_io(struct goat3d *g, struct goat3d_io *io);
nuclear@55 116 GOAT3DAPI int goat3d_save_anim_io(const struct goat3d *g, struct goat3d_io *io);
nuclear@47 117
nuclear@0 118 /* misc scene properties */
nuclear@41 119 GOAT3DAPI int goat3d_set_name(struct goat3d *g, const char *name);
nuclear@41 120 GOAT3DAPI const char *goat3d_get_name(const struct goat3d *g);
nuclear@0 121
nuclear@41 122 GOAT3DAPI void goat3d_set_ambient(struct goat3d *g, const float *ambient);
nuclear@41 123 GOAT3DAPI void goat3d_set_ambient3f(struct goat3d *g, float ar, float ag, float ab);
nuclear@41 124 GOAT3DAPI const float *goat3d_get_ambient(const struct goat3d *g);
nuclear@0 125
nuclear@15 126 /* materials */
nuclear@41 127 GOAT3DAPI void goat3d_add_mtl(struct goat3d *g, struct goat3d_material *mtl);
nuclear@57 128 GOAT3DAPI int goat3d_get_mtl_count(struct goat3d *g);
nuclear@57 129 GOAT3DAPI struct goat3d_material *goat3d_get_mtl(struct goat3d *g, int idx);
nuclear@57 130 GOAT3DAPI struct goat3d_material *goat3d_get_mtl_by_name(struct goat3d *g, const char *name);
nuclear@27 131
nuclear@41 132 GOAT3DAPI struct goat3d_material *goat3d_create_mtl(void);
nuclear@41 133 GOAT3DAPI void goat3d_destroy_mtl(struct goat3d_material *mtl);
nuclear@0 134
nuclear@41 135 GOAT3DAPI void goat3d_set_mtl_name(struct goat3d_material *mtl, const char *name);
nuclear@41 136 GOAT3DAPI const char *goat3d_get_mtl_name(const struct goat3d_material *mtl);
nuclear@15 137
nuclear@41 138 GOAT3DAPI void goat3d_set_mtl_attrib(struct goat3d_material *mtl, const char *attrib, const float *val);
nuclear@41 139 GOAT3DAPI void goat3d_set_mtl_attrib1f(struct goat3d_material *mtl, const char *attrib, float val);
nuclear@41 140 GOAT3DAPI void goat3d_set_mtl_attrib3f(struct goat3d_material *mtl, const char *attrib, float r, float g, float b);
nuclear@41 141 GOAT3DAPI void goat3d_set_mtl_attrib4f(struct goat3d_material *mtl, const char *attrib, float r, float g, float b, float a);
nuclear@41 142 GOAT3DAPI const float *goat3d_get_mtl_attrib(struct goat3d_material *mtl, const char *attrib);
nuclear@15 143
nuclear@41 144 GOAT3DAPI void goat3d_set_mtl_attrib_map(struct goat3d_material *mtl, const char *attrib, const char *mapname);
nuclear@41 145 GOAT3DAPI const char *goat3d_get_mtl_attrib_map(struct goat3d_material *mtl, const char *attrib);
nuclear@15 146
nuclear@27 147 /* meshes */
nuclear@41 148 GOAT3DAPI void goat3d_add_mesh(struct goat3d *g, struct goat3d_mesh *mesh);
nuclear@41 149 GOAT3DAPI int goat3d_get_mesh_count(struct goat3d *g);
nuclear@41 150 GOAT3DAPI struct goat3d_mesh *goat3d_get_mesh(struct goat3d *g, int idx);
nuclear@41 151 GOAT3DAPI struct goat3d_mesh *goat3d_get_mesh_by_name(struct goat3d *g, const char *name);
nuclear@15 152
nuclear@41 153 GOAT3DAPI struct goat3d_mesh *goat3d_create_mesh(void);
nuclear@41 154 GOAT3DAPI void goat3d_destroy_mesh(struct goat3d_mesh *mesh);
nuclear@15 155
nuclear@41 156 GOAT3DAPI void goat3d_set_mesh_name(struct goat3d_mesh *mesh, const char *name);
nuclear@41 157 GOAT3DAPI const char *goat3d_get_mesh_name(const struct goat3d_mesh *mesh);
nuclear@15 158
nuclear@41 159 GOAT3DAPI void goat3d_set_mesh_mtl(struct goat3d_mesh *mesh, struct goat3d_material *mtl);
nuclear@41 160 GOAT3DAPI struct goat3d_material *goat3d_get_mesh_mtl(struct goat3d_mesh *mesh);
nuclear@15 161
nuclear@41 162 GOAT3DAPI int goat3d_get_mesh_attrib_count(struct goat3d_mesh *mesh, enum goat3d_mesh_attrib attrib);
nuclear@41 163 GOAT3DAPI int goat3d_get_mesh_face_count(struct goat3d_mesh *mesh);
nuclear@15 164
nuclear@15 165 /* sets all the data for a single vertex attribute array in one go.
nuclear@15 166 * vnum is the number of *vertices* to be set, not the number of floats, ints or whatever
nuclear@15 167 * data is expected to be something different depending on the attribute:
nuclear@15 168 * - GOAT3D_MESH_ATTR_VERTEX - 3 floats per vertex
nuclear@15 169 * - GOAT3D_MESH_ATTR_NORMAL - 3 floats per vertex
nuclear@15 170 * - GOAT3D_MESH_ATTR_TANGENT - 3 floats per vertex
nuclear@15 171 * - GOAT3D_MESH_ATTR_TEXCOORD - 2 floats per vertex
nuclear@15 172 * - GOAT3D_MESH_ATTR_SKIN_WEIGHT - 4 floats per vertex
nuclear@15 173 * - GOAT3D_MESH_ATTR_SKIN_MATRIX - 4 ints per vertex
nuclear@15 174 * - GOAT3D_MESH_ATTR_COLOR - 4 floats per vertex
nuclear@15 175 */
nuclear@41 176 GOAT3DAPI void goat3d_set_mesh_attribs(struct goat3d_mesh *mesh, enum goat3d_mesh_attrib attrib,
nuclear@40 177 const void *data, int vnum);
nuclear@41 178 GOAT3DAPI void goat3d_add_mesh_attrib1f(struct goat3d_mesh *mesh, enum goat3d_mesh_attrib attrib, float val);
nuclear@57 179 GOAT3DAPI void goat3d_add_mesh_attrib2f(struct goat3d_mesh *mesh, enum goat3d_mesh_attrib attrib,
nuclear@57 180 float x, float y);
nuclear@41 181 GOAT3DAPI void goat3d_add_mesh_attrib3f(struct goat3d_mesh *mesh, enum goat3d_mesh_attrib attrib,
nuclear@47 182 float x, float y, float z);
nuclear@41 183 GOAT3DAPI void goat3d_add_mesh_attrib4f(struct goat3d_mesh *mesh, enum goat3d_mesh_attrib attrib,
nuclear@47 184 float x, float y, float z, float w);
nuclear@15 185 /* returns a pointer to the beginning of the requested mesh attribute array */
nuclear@41 186 GOAT3DAPI void *goat3d_get_mesh_attribs(struct goat3d_mesh *mesh, enum goat3d_mesh_attrib attrib);
nuclear@15 187 /* returns a pointer to the requested mesh attribute */
nuclear@41 188 GOAT3DAPI void *goat3d_get_mesh_attrib(struct goat3d_mesh *mesh, enum goat3d_mesh_attrib attrib, int idx);
nuclear@15 189
nuclear@15 190 /* sets all the faces in one go. data is an array of 3 int vertex indices per face */
nuclear@41 191 GOAT3DAPI void goat3d_set_mesh_faces(struct goat3d_mesh *mesh, const int *data, int fnum);
nuclear@41 192 GOAT3DAPI void goat3d_add_mesh_face(struct goat3d_mesh *mesh, int a, int b, int c);
nuclear@15 193 /* returns a pointer to the beginning of the face index array */
nuclear@41 194 GOAT3DAPI int *goat3d_get_mesh_faces(struct goat3d_mesh *mesh);
nuclear@15 195 /* returns a pointer to a face index */
nuclear@41 196 GOAT3DAPI int *goat3d_get_mesh_face(struct goat3d_mesh *mesh, int idx);
nuclear@15 197
nuclear@15 198 /* immediate mode OpenGL-like interface for setting mesh data
nuclear@15 199 * NOTE: using this interface will result in no vertex sharing between faces
nuclear@15 200 * NOTE2: the immedate mode interface is not thread-safe, either use locks, or don't
nuclear@15 201 * use it at all in multithreaded situations.
nuclear@15 202 */
nuclear@41 203 GOAT3DAPI void goat3d_begin(struct goat3d_mesh *mesh, enum goat3d_im_primitive prim);
nuclear@41 204 GOAT3DAPI void goat3d_end(void);
nuclear@41 205 GOAT3DAPI void goat3d_vertex3f(float x, float y, float z);
nuclear@41 206 GOAT3DAPI void goat3d_normal3f(float x, float y, float z);
nuclear@41 207 GOAT3DAPI void goat3d_tangent3f(float x, float y, float z);
nuclear@41 208 GOAT3DAPI void goat3d_texcoord2f(float x, float y);
nuclear@41 209 GOAT3DAPI void goat3d_skin_weight4f(float x, float y, float z, float w);
nuclear@41 210 GOAT3DAPI void goat3d_skin_matrix4i(int x, int y, int z, int w);
nuclear@41 211 GOAT3DAPI void goat3d_color3f(float x, float y, float z);
nuclear@41 212 GOAT3DAPI void goat3d_color4f(float x, float y, float z, float w);
nuclear@15 213
nuclear@27 214 /* lights */
nuclear@41 215 GOAT3DAPI void goat3d_add_light(struct goat3d *g, struct goat3d_light *lt);
nuclear@41 216 GOAT3DAPI int goat3d_get_light_count(struct goat3d *g);
nuclear@41 217 GOAT3DAPI struct goat3d_light *goat3d_get_light(struct goat3d *g, int idx);
nuclear@41 218 GOAT3DAPI struct goat3d_light *goat3d_get_light_by_name(struct goat3d *g, const char *name);
nuclear@0 219
nuclear@41 220 GOAT3DAPI struct goat3d_light *goat3d_create_light(void);
nuclear@41 221 GOAT3DAPI void goat3d_destroy_light(struct goat3d_light *lt);
nuclear@27 222
nuclear@27 223 /* cameras */
nuclear@41 224 GOAT3DAPI void goat3d_add_camera(struct goat3d *g, struct goat3d_camera *cam);
nuclear@41 225 GOAT3DAPI int goat3d_get_camera_count(struct goat3d *g);
nuclear@41 226 GOAT3DAPI struct goat3d_camera *goat3d_get_camera(struct goat3d *g, int idx);
nuclear@41 227 GOAT3DAPI struct goat3d_camera *goat3d_get_camera_by_name(struct goat3d *g, const char *name);
nuclear@27 228
nuclear@41 229 GOAT3DAPI struct goat3d_camera *goat3d_create_camera(void);
nuclear@41 230 GOAT3DAPI void goat3d_destroy_camera(struct goat3d_camera *cam);
nuclear@19 231
nuclear@25 232 /* nodes */
nuclear@41 233 GOAT3DAPI void goat3d_add_node(struct goat3d *g, struct goat3d_node *node);
nuclear@41 234 GOAT3DAPI int goat3d_get_node_count(struct goat3d *g);
nuclear@41 235 GOAT3DAPI struct goat3d_node *goat3d_get_node(struct goat3d *g, int idx);
nuclear@41 236 GOAT3DAPI struct goat3d_node *goat3d_get_node_by_name(struct goat3d *g, const char *name);
nuclear@27 237
nuclear@41 238 GOAT3DAPI struct goat3d_node *goat3d_create_node(void);
nuclear@41 239 GOAT3DAPI void goat3d_destroy_node(struct goat3d_node *node);
nuclear@25 240
nuclear@41 241 GOAT3DAPI void goat3d_set_node_name(struct goat3d_node *node, const char *name);
nuclear@41 242 GOAT3DAPI const char *goat3d_get_node_name(const struct goat3d_node *node);
nuclear@25 243
nuclear@41 244 GOAT3DAPI void goat3d_set_node_object(struct goat3d_node *node, enum goat3d_node_type type, void *obj);
nuclear@41 245 GOAT3DAPI void *goat3d_get_node_object(const struct goat3d_node *node);
nuclear@41 246 GOAT3DAPI enum goat3d_node_type goat3d_get_node_type(const struct goat3d_node *node);
nuclear@25 247
nuclear@41 248 GOAT3DAPI void goat3d_add_node_child(struct goat3d_node *node, struct goat3d_node *child);
nuclear@41 249 GOAT3DAPI int goat3d_get_node_child_count(const struct goat3d_node *node);
nuclear@41 250 GOAT3DAPI struct goat3d_node *goat3d_get_node_child(const struct goat3d_node *node, int idx);
nuclear@47 251 GOAT3DAPI struct goat3d_node *goat3d_get_node_parent(const struct goat3d_node *node);
nuclear@47 252
nuclear@47 253 GOAT3DAPI void goat3d_use_anim(struct goat3d_node *node, int idx);
nuclear@47 254 GOAT3DAPI void goat3d_use_anims(struct goat3d_node *node, int aidx, int bidx, float t);
nuclear@47 255 GOAT3DAPI void goat3d_use_anim_by_name(struct goat3d_node *node, const char *name);
nuclear@47 256 GOAT3DAPI void goat3d_use_anims_by_name(struct goat3d_node *node, const char *aname, const char *bname, float t);
nuclear@47 257
nuclear@47 258 GOAT3DAPI int goat3d_get_active_anim(struct goat3d_node *node, int which);
nuclear@47 259 GOAT3DAPI float goat3d_get_active_anim_mix(struct goat3d_node *node);
nuclear@47 260
nuclear@47 261 GOAT3DAPI int goat3d_get_anim_count(struct goat3d_node *node);
nuclear@47 262 GOAT3DAPI void goat3d_add_anim(struct goat3d_node *root);
nuclear@47 263
nuclear@47 264 GOAT3DAPI void goat3d_set_anim_name(struct goat3d_node *root, const char *name);
nuclear@47 265 GOAT3DAPI const char *goat3d_get_anim_name(struct goat3d_node *node);
nuclear@25 266
nuclear@41 267 GOAT3DAPI void goat3d_set_node_position(struct goat3d_node *node, float x, float y, float z, long tmsec);
nuclear@41 268 GOAT3DAPI void goat3d_set_node_rotation(struct goat3d_node *node, float qx, float qy, float qz, float qw, long tmsec);
nuclear@41 269 GOAT3DAPI void goat3d_set_node_scaling(struct goat3d_node *node, float sx, float sy, float sz, long tmsec);
nuclear@41 270 GOAT3DAPI void goat3d_set_node_pivot(struct goat3d_node *node, float px, float py, float pz);
nuclear@25 271
nuclear@41 272 GOAT3DAPI void goat3d_get_node_position(const struct goat3d_node *node, float *xptr, float *yptr, float *zptr, long tmsec);
nuclear@41 273 GOAT3DAPI void goat3d_get_node_rotation(const struct goat3d_node *node, float *xptr, float *yptr, float *zptr, float *wptr, long tmsec);
nuclear@41 274 GOAT3DAPI void goat3d_get_node_scaling(const struct goat3d_node *node, float *xptr, float *yptr, float *zptr, long tmsec);
nuclear@41 275 GOAT3DAPI void goat3d_get_node_pivot(const struct goat3d_node *node, float *xptr, float *yptr, float *zptr);
nuclear@25 276
nuclear@41 277 GOAT3DAPI void goat3d_get_node_matrix(const struct goat3d_node *node, float *matrix, long tmsec);
nuclear@25 278
nuclear@0 279 #ifdef __cplusplus
nuclear@0 280 }
nuclear@0 281 #endif
nuclear@0 282
nuclear@0 283 #endif /* GOAT3D_H_ */