nuclear@0: #ifndef GOAT3D_H_ nuclear@0: #define GOAT3D_H_ nuclear@0: nuclear@0: #include nuclear@0: #include nuclear@0: nuclear@41: #ifdef WIN32 nuclear@41: #define GOAT3DAPI __declspec(dllexport) nuclear@41: #else nuclear@43: #define GOAT3DAPI nuclear@41: #endif nuclear@41: nuclear@15: #define GOAT3D_MAT_ATTR_DIFFUSE "diffuse" nuclear@15: #define GOAT3D_MAT_ATTR_SPECULAR "specular" nuclear@15: #define GOAT3D_MAT_ATTR_SHININESS "shininess" nuclear@15: #define GOAT3D_MAT_ATTR_NORMAL "normal" nuclear@15: #define GOAT3D_MAT_ATTR_BUMP "bump" nuclear@15: #define GOAT3D_MAT_ATTR_REFLECTION "reflection" nuclear@15: #define GOAT3D_MAT_ATTR_TRANSMISSION "transmission" nuclear@15: #define GOAT3D_MAT_ATTR_IOR "ior" nuclear@40: #define GOAT3D_MAT_ATTR_ALPHA "alpha" nuclear@15: nuclear@15: enum goat3d_mesh_attrib { nuclear@15: GOAT3D_MESH_ATTR_VERTEX, nuclear@15: GOAT3D_MESH_ATTR_NORMAL, nuclear@15: GOAT3D_MESH_ATTR_TANGENT, nuclear@15: GOAT3D_MESH_ATTR_TEXCOORD, nuclear@15: GOAT3D_MESH_ATTR_SKIN_WEIGHT, nuclear@15: GOAT3D_MESH_ATTR_SKIN_MATRIX, nuclear@15: GOAT3D_MESH_ATTR_COLOR, nuclear@15: nuclear@15: NUM_GOAT3D_MESH_ATTRIBS nuclear@15: }; nuclear@15: nuclear@25: enum goat3d_node_type { nuclear@26: GOAT3D_NODE_NULL, nuclear@25: GOAT3D_NODE_MESH, nuclear@25: GOAT3D_NODE_LIGHT, nuclear@25: GOAT3D_NODE_CAMERA nuclear@25: }; nuclear@25: nuclear@15: /* immediate mode mesh construction primitive type */ nuclear@15: enum goat3d_im_primitive { nuclear@15: GOAT3D_TRIANGLES, nuclear@15: GOAT3D_QUADS nuclear@15: }; nuclear@15: nuclear@15: nuclear@15: enum goat3d_option { nuclear@15: GOAT3D_OPT_SAVEXML, /* save in XML format */ nuclear@15: nuclear@15: NUM_GOAT3D_OPTIONS nuclear@15: }; nuclear@15: nuclear@0: struct goat3d; nuclear@15: struct goat3d_material; nuclear@15: struct goat3d_mesh; nuclear@15: struct goat3d_light; nuclear@15: struct goat3d_camera; nuclear@15: struct goat3d_node; nuclear@0: nuclear@0: struct goat3d_io { nuclear@0: void *cls; /* closure data */ nuclear@0: nuclear@11: long (*read)(void *buf, size_t bytes, void *uptr); nuclear@13: long (*write)(const void *buf, size_t bytes, void *uptr); nuclear@0: long (*seek)(long offs, int whence, void *uptr); nuclear@0: }; nuclear@0: nuclear@0: #ifdef __cplusplus nuclear@0: extern "C" { nuclear@0: #endif nuclear@0: nuclear@0: /* construction/destruction */ nuclear@41: GOAT3DAPI struct goat3d *goat3d_create(void); nuclear@41: GOAT3DAPI void goat3d_free(struct goat3d *g); nuclear@0: nuclear@41: GOAT3DAPI void goat3d_setopt(struct goat3d *g, enum goat3d_option opt, int val); nuclear@41: GOAT3DAPI int goat3d_getopt(const struct goat3d *g, enum goat3d_option opt); nuclear@15: nuclear@0: /* load/save */ nuclear@41: GOAT3DAPI int goat3d_load(struct goat3d *g, const char *fname); nuclear@41: GOAT3DAPI int goat3d_save(const struct goat3d *g, const char *fname); nuclear@0: nuclear@41: GOAT3DAPI int goat3d_load_file(struct goat3d *g, FILE *fp); nuclear@41: GOAT3DAPI int goat3d_save_file(const struct goat3d *g, FILE *fp); nuclear@0: nuclear@41: GOAT3DAPI int goat3d_load_io(struct goat3d *g, struct goat3d_io *io); nuclear@41: GOAT3DAPI int goat3d_save_io(const struct goat3d *g, struct goat3d_io *io); nuclear@0: nuclear@47: /* load/save animation files (g must already be loaded to load animations) */ nuclear@47: GOAT3DAPI int goat3d_load_anim(struct goat3d *g, const char *fname); nuclear@55: GOAT3DAPI int goat3d_save_anim(const struct goat3d *g, const char *fname); nuclear@47: nuclear@47: GOAT3DAPI int goat3d_load_anim_file(struct goat3d *g, FILE *fp); nuclear@55: GOAT3DAPI int goat3d_save_anim_file(const struct goat3d *g, FILE *fp); nuclear@47: nuclear@47: GOAT3DAPI int goat3d_load_anim_io(struct goat3d *g, struct goat3d_io *io); nuclear@55: GOAT3DAPI int goat3d_save_anim_io(const struct goat3d *g, struct goat3d_io *io); nuclear@47: nuclear@0: /* misc scene properties */ nuclear@41: GOAT3DAPI int goat3d_set_name(struct goat3d *g, const char *name); nuclear@41: GOAT3DAPI const char *goat3d_get_name(const struct goat3d *g); nuclear@0: nuclear@41: GOAT3DAPI void goat3d_set_ambient(struct goat3d *g, const float *ambient); nuclear@41: GOAT3DAPI void goat3d_set_ambient3f(struct goat3d *g, float ar, float ag, float ab); nuclear@41: GOAT3DAPI const float *goat3d_get_ambient(const struct goat3d *g); nuclear@0: nuclear@15: /* materials */ nuclear@41: GOAT3DAPI void goat3d_add_mtl(struct goat3d *g, struct goat3d_material *mtl); nuclear@27: nuclear@41: GOAT3DAPI struct goat3d_material *goat3d_create_mtl(void); nuclear@41: GOAT3DAPI void goat3d_destroy_mtl(struct goat3d_material *mtl); nuclear@0: nuclear@41: GOAT3DAPI void goat3d_set_mtl_name(struct goat3d_material *mtl, const char *name); nuclear@41: GOAT3DAPI const char *goat3d_get_mtl_name(const struct goat3d_material *mtl); nuclear@15: nuclear@41: GOAT3DAPI void goat3d_set_mtl_attrib(struct goat3d_material *mtl, const char *attrib, const float *val); nuclear@41: GOAT3DAPI void goat3d_set_mtl_attrib1f(struct goat3d_material *mtl, const char *attrib, float val); nuclear@41: GOAT3DAPI void goat3d_set_mtl_attrib3f(struct goat3d_material *mtl, const char *attrib, float r, float g, float b); nuclear@41: GOAT3DAPI void goat3d_set_mtl_attrib4f(struct goat3d_material *mtl, const char *attrib, float r, float g, float b, float a); nuclear@41: GOAT3DAPI const float *goat3d_get_mtl_attrib(struct goat3d_material *mtl, const char *attrib); nuclear@15: nuclear@41: GOAT3DAPI void goat3d_set_mtl_attrib_map(struct goat3d_material *mtl, const char *attrib, const char *mapname); nuclear@41: GOAT3DAPI const char *goat3d_get_mtl_attrib_map(struct goat3d_material *mtl, const char *attrib); nuclear@15: nuclear@27: /* meshes */ nuclear@41: GOAT3DAPI void goat3d_add_mesh(struct goat3d *g, struct goat3d_mesh *mesh); nuclear@41: GOAT3DAPI int goat3d_get_mesh_count(struct goat3d *g); nuclear@41: GOAT3DAPI struct goat3d_mesh *goat3d_get_mesh(struct goat3d *g, int idx); nuclear@41: GOAT3DAPI struct goat3d_mesh *goat3d_get_mesh_by_name(struct goat3d *g, const char *name); nuclear@15: nuclear@41: GOAT3DAPI struct goat3d_mesh *goat3d_create_mesh(void); nuclear@41: GOAT3DAPI void goat3d_destroy_mesh(struct goat3d_mesh *mesh); nuclear@15: nuclear@41: GOAT3DAPI void goat3d_set_mesh_name(struct goat3d_mesh *mesh, const char *name); nuclear@41: GOAT3DAPI const char *goat3d_get_mesh_name(const struct goat3d_mesh *mesh); nuclear@15: nuclear@41: GOAT3DAPI void goat3d_set_mesh_mtl(struct goat3d_mesh *mesh, struct goat3d_material *mtl); nuclear@41: GOAT3DAPI struct goat3d_material *goat3d_get_mesh_mtl(struct goat3d_mesh *mesh); nuclear@15: nuclear@41: GOAT3DAPI int goat3d_get_mesh_attrib_count(struct goat3d_mesh *mesh, enum goat3d_mesh_attrib attrib); nuclear@41: GOAT3DAPI int goat3d_get_mesh_face_count(struct goat3d_mesh *mesh); nuclear@15: nuclear@15: /* sets all the data for a single vertex attribute array in one go. nuclear@15: * vnum is the number of *vertices* to be set, not the number of floats, ints or whatever nuclear@15: * data is expected to be something different depending on the attribute: nuclear@15: * - GOAT3D_MESH_ATTR_VERTEX - 3 floats per vertex nuclear@15: * - GOAT3D_MESH_ATTR_NORMAL - 3 floats per vertex nuclear@15: * - GOAT3D_MESH_ATTR_TANGENT - 3 floats per vertex nuclear@15: * - GOAT3D_MESH_ATTR_TEXCOORD - 2 floats per vertex nuclear@15: * - GOAT3D_MESH_ATTR_SKIN_WEIGHT - 4 floats per vertex nuclear@15: * - GOAT3D_MESH_ATTR_SKIN_MATRIX - 4 ints per vertex nuclear@15: * - GOAT3D_MESH_ATTR_COLOR - 4 floats per vertex nuclear@15: */ nuclear@41: GOAT3DAPI void goat3d_set_mesh_attribs(struct goat3d_mesh *mesh, enum goat3d_mesh_attrib attrib, nuclear@40: const void *data, int vnum); nuclear@41: GOAT3DAPI void goat3d_add_mesh_attrib1f(struct goat3d_mesh *mesh, enum goat3d_mesh_attrib attrib, float val); nuclear@41: GOAT3DAPI void goat3d_add_mesh_attrib3f(struct goat3d_mesh *mesh, enum goat3d_mesh_attrib attrib, nuclear@47: float x, float y, float z); nuclear@41: GOAT3DAPI void goat3d_add_mesh_attrib4f(struct goat3d_mesh *mesh, enum goat3d_mesh_attrib attrib, nuclear@47: float x, float y, float z, float w); nuclear@15: /* returns a pointer to the beginning of the requested mesh attribute array */ nuclear@41: GOAT3DAPI void *goat3d_get_mesh_attribs(struct goat3d_mesh *mesh, enum goat3d_mesh_attrib attrib); nuclear@15: /* returns a pointer to the requested mesh attribute */ nuclear@41: GOAT3DAPI void *goat3d_get_mesh_attrib(struct goat3d_mesh *mesh, enum goat3d_mesh_attrib attrib, int idx); nuclear@15: nuclear@15: /* sets all the faces in one go. data is an array of 3 int vertex indices per face */ nuclear@41: GOAT3DAPI void goat3d_set_mesh_faces(struct goat3d_mesh *mesh, const int *data, int fnum); nuclear@41: GOAT3DAPI void goat3d_add_mesh_face(struct goat3d_mesh *mesh, int a, int b, int c); nuclear@15: /* returns a pointer to the beginning of the face index array */ nuclear@41: GOAT3DAPI int *goat3d_get_mesh_faces(struct goat3d_mesh *mesh); nuclear@15: /* returns a pointer to a face index */ nuclear@41: GOAT3DAPI int *goat3d_get_mesh_face(struct goat3d_mesh *mesh, int idx); nuclear@15: nuclear@15: /* immediate mode OpenGL-like interface for setting mesh data nuclear@15: * NOTE: using this interface will result in no vertex sharing between faces nuclear@15: * NOTE2: the immedate mode interface is not thread-safe, either use locks, or don't nuclear@15: * use it at all in multithreaded situations. nuclear@15: */ nuclear@41: GOAT3DAPI void goat3d_begin(struct goat3d_mesh *mesh, enum goat3d_im_primitive prim); nuclear@41: GOAT3DAPI void goat3d_end(void); nuclear@41: GOAT3DAPI void goat3d_vertex3f(float x, float y, float z); nuclear@41: GOAT3DAPI void goat3d_normal3f(float x, float y, float z); nuclear@41: GOAT3DAPI void goat3d_tangent3f(float x, float y, float z); nuclear@41: GOAT3DAPI void goat3d_texcoord2f(float x, float y); nuclear@41: GOAT3DAPI void goat3d_skin_weight4f(float x, float y, float z, float w); nuclear@41: GOAT3DAPI void goat3d_skin_matrix4i(int x, int y, int z, int w); nuclear@41: GOAT3DAPI void goat3d_color3f(float x, float y, float z); nuclear@41: GOAT3DAPI void goat3d_color4f(float x, float y, float z, float w); nuclear@15: nuclear@27: /* lights */ nuclear@41: GOAT3DAPI void goat3d_add_light(struct goat3d *g, struct goat3d_light *lt); nuclear@41: GOAT3DAPI int goat3d_get_light_count(struct goat3d *g); nuclear@41: GOAT3DAPI struct goat3d_light *goat3d_get_light(struct goat3d *g, int idx); nuclear@41: GOAT3DAPI struct goat3d_light *goat3d_get_light_by_name(struct goat3d *g, const char *name); nuclear@0: nuclear@41: GOAT3DAPI struct goat3d_light *goat3d_create_light(void); nuclear@41: GOAT3DAPI void goat3d_destroy_light(struct goat3d_light *lt); nuclear@27: nuclear@27: /* cameras */ nuclear@41: GOAT3DAPI void goat3d_add_camera(struct goat3d *g, struct goat3d_camera *cam); nuclear@41: GOAT3DAPI int goat3d_get_camera_count(struct goat3d *g); nuclear@41: GOAT3DAPI struct goat3d_camera *goat3d_get_camera(struct goat3d *g, int idx); nuclear@41: GOAT3DAPI struct goat3d_camera *goat3d_get_camera_by_name(struct goat3d *g, const char *name); nuclear@27: nuclear@41: GOAT3DAPI struct goat3d_camera *goat3d_create_camera(void); nuclear@41: GOAT3DAPI void goat3d_destroy_camera(struct goat3d_camera *cam); nuclear@19: nuclear@25: /* nodes */ nuclear@41: GOAT3DAPI void goat3d_add_node(struct goat3d *g, struct goat3d_node *node); nuclear@41: GOAT3DAPI int goat3d_get_node_count(struct goat3d *g); nuclear@41: GOAT3DAPI struct goat3d_node *goat3d_get_node(struct goat3d *g, int idx); nuclear@41: GOAT3DAPI struct goat3d_node *goat3d_get_node_by_name(struct goat3d *g, const char *name); nuclear@27: nuclear@41: GOAT3DAPI struct goat3d_node *goat3d_create_node(void); nuclear@41: GOAT3DAPI void goat3d_destroy_node(struct goat3d_node *node); nuclear@25: nuclear@41: GOAT3DAPI void goat3d_set_node_name(struct goat3d_node *node, const char *name); nuclear@41: GOAT3DAPI const char *goat3d_get_node_name(const struct goat3d_node *node); nuclear@25: nuclear@41: GOAT3DAPI void goat3d_set_node_object(struct goat3d_node *node, enum goat3d_node_type type, void *obj); nuclear@41: GOAT3DAPI void *goat3d_get_node_object(const struct goat3d_node *node); nuclear@41: GOAT3DAPI enum goat3d_node_type goat3d_get_node_type(const struct goat3d_node *node); nuclear@25: nuclear@41: GOAT3DAPI void goat3d_add_node_child(struct goat3d_node *node, struct goat3d_node *child); nuclear@41: GOAT3DAPI int goat3d_get_node_child_count(const struct goat3d_node *node); nuclear@41: GOAT3DAPI struct goat3d_node *goat3d_get_node_child(const struct goat3d_node *node, int idx); nuclear@47: GOAT3DAPI struct goat3d_node *goat3d_get_node_parent(const struct goat3d_node *node); nuclear@47: nuclear@47: GOAT3DAPI void goat3d_use_anim(struct goat3d_node *node, int idx); nuclear@47: GOAT3DAPI void goat3d_use_anims(struct goat3d_node *node, int aidx, int bidx, float t); nuclear@47: GOAT3DAPI void goat3d_use_anim_by_name(struct goat3d_node *node, const char *name); nuclear@47: GOAT3DAPI void goat3d_use_anims_by_name(struct goat3d_node *node, const char *aname, const char *bname, float t); nuclear@47: nuclear@47: GOAT3DAPI int goat3d_get_active_anim(struct goat3d_node *node, int which); nuclear@47: GOAT3DAPI float goat3d_get_active_anim_mix(struct goat3d_node *node); nuclear@47: nuclear@47: GOAT3DAPI int goat3d_get_anim_count(struct goat3d_node *node); nuclear@47: GOAT3DAPI void goat3d_add_anim(struct goat3d_node *root); nuclear@47: nuclear@47: GOAT3DAPI void goat3d_set_anim_name(struct goat3d_node *root, const char *name); nuclear@47: GOAT3DAPI const char *goat3d_get_anim_name(struct goat3d_node *node); nuclear@25: nuclear@41: GOAT3DAPI void goat3d_set_node_position(struct goat3d_node *node, float x, float y, float z, long tmsec); nuclear@41: GOAT3DAPI void goat3d_set_node_rotation(struct goat3d_node *node, float qx, float qy, float qz, float qw, long tmsec); nuclear@41: GOAT3DAPI void goat3d_set_node_scaling(struct goat3d_node *node, float sx, float sy, float sz, long tmsec); nuclear@41: GOAT3DAPI void goat3d_set_node_pivot(struct goat3d_node *node, float px, float py, float pz); nuclear@25: nuclear@41: GOAT3DAPI void goat3d_get_node_position(const struct goat3d_node *node, float *xptr, float *yptr, float *zptr, long tmsec); nuclear@41: GOAT3DAPI void goat3d_get_node_rotation(const struct goat3d_node *node, float *xptr, float *yptr, float *zptr, float *wptr, long tmsec); nuclear@41: GOAT3DAPI void goat3d_get_node_scaling(const struct goat3d_node *node, float *xptr, float *yptr, float *zptr, long tmsec); nuclear@41: GOAT3DAPI void goat3d_get_node_pivot(const struct goat3d_node *node, float *xptr, float *yptr, float *zptr); nuclear@25: nuclear@41: GOAT3DAPI void goat3d_get_node_matrix(const struct goat3d_node *node, float *matrix, long tmsec); nuclear@25: nuclear@0: #ifdef __cplusplus nuclear@0: } nuclear@0: #endif nuclear@0: nuclear@0: #endif /* GOAT3D_H_ */