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