diff options
author | David Walter Seikel | 2014-05-30 02:13:48 +1000 |
---|---|---|
committer | David Walter Seikel | 2014-05-30 02:13:48 +1000 |
commit | d2178bf76792650ee598ee45114e1c20d18bb936 (patch) | |
tree | 94ade909fe608fdf88f12ca801c791a4f988a866 /src/extantz/scenri.c | |
parent | Half arsed generic stuffs creation. (diff) | |
download | SledjHamr-d2178bf76792650ee598ee45114e1c20d18bb936.zip SledjHamr-d2178bf76792650ee598ee45114e1c20d18bb936.tar.gz SledjHamr-d2178bf76792650ee598ee45114e1c20d18bb936.tar.bz2 SledjHamr-d2178bf76792650ee598ee45114e1c20d18bb936.tar.xz |
Slightly less half arsed stuffs creation.
Diffstat (limited to 'src/extantz/scenri.c')
-rw-r--r-- | src/extantz/scenri.c | 456 |
1 files changed, 456 insertions, 0 deletions
diff --git a/src/extantz/scenri.c b/src/extantz/scenri.c index 7395582..4ebc64a 100644 --- a/src/extantz/scenri.c +++ b/src/extantz/scenri.c | |||
@@ -1,5 +1,18 @@ | |||
1 | #include "extantz.h" | 1 | #include "extantz.h" |
2 | 2 | ||
3 | |||
4 | Eina_Bool animateScene(globals *ourGlobals) | ||
5 | { | ||
6 | ExtantzStuffs *e; | ||
7 | |||
8 | EINA_CLIST_FOR_EACH_ENTRY(e, &ourGlobals->stuffs, ExtantzStuffs, node) | ||
9 | { | ||
10 | if (e->animateStuffs) e->animateStuffs(e); | ||
11 | } | ||
12 | |||
13 | return EINA_TRUE; | ||
14 | } | ||
15 | |||
3 | static void _on_mouse_move(void *data, Evas *e EINA_UNUSED, Evas_Object *o, void *einfo) | 16 | static void _on_mouse_move(void *data, Evas *e EINA_UNUSED, Evas_Object *o, void *einfo) |
4 | { | 17 | { |
5 | Scene_Data *scene = data; | 18 | Scene_Data *scene = data; |
@@ -159,3 +172,446 @@ void scenriDel(Scene_Data *scene) | |||
159 | // eo_unref(scene->root_node); | 172 | // eo_unref(scene->root_node); |
160 | free(scene); | 173 | free(scene); |
161 | } | 174 | } |
175 | |||
176 | |||
177 | static const float cube_vertices[] = | ||
178 | { | ||
179 | /* Front */ | ||
180 | -1.0, 1.0, 1.0, 0.0, 0.0, 1.0, 1.0, 0.0, 0.0, 1.0, 0.0, 1.0, | ||
181 | 1.0, 1.0, 1.0, 0.0, 0.0, 1.0, 1.0, 0.0, 0.0, 1.0, 1.0, 1.0, | ||
182 | -1.0, -1.0, 1.0, 0.0, 0.0, 1.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0, | ||
183 | 1.0, -1.0, 1.0, 0.0, 0.0, 1.0, 1.0, 0.0, 0.0, 1.0, 1.0, 0.0, | ||
184 | |||
185 | /* Back */ | ||
186 | 1.0, 1.0, -1.0, 0.0, 0.0, -1.0, 0.0, 0.0, 1.0, 1.0, 0.0, 1.0, | ||
187 | -1.0, 1.0, -1.0, 0.0, 0.0, -1.0, 0.0, 0.0, 1.0, 1.0, 1.0, 1.0, | ||
188 | 1.0, -1.0, -1.0, 0.0, 0.0, -1.0, 0.0, 0.0, 1.0, 1.0, 0.0, 0.0, | ||
189 | -1.0, -1.0, -1.0, 0.0, 0.0, -1.0, 0.0, 0.0, 1.0, 1.0, 1.0, 0.0, | ||
190 | |||
191 | /* Left */ | ||
192 | -1.0, 1.0, -1.0, -1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0, | ||
193 | -1.0, 1.0, 1.0, -1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 1.0, 1.0, 1.0, | ||
194 | -1.0, -1.0, -1.0, -1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 1.0, 0.0, 0.0, | ||
195 | -1.0, -1.0, 1.0, -1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 1.0, 1.0, 0.0, | ||
196 | |||
197 | /* Right */ | ||
198 | 1.0, 1.0, 1.0, 1.0, 0.0, 0.0, 1.0, 1.0, 0.0, 1.0, 0.0, 1.0, | ||
199 | 1.0, 1.0, -1.0, 1.0, 0.0, 0.0, 1.0, 1.0, 0.0, 1.0, 1.0, 1.0, | ||
200 | 1.0, -1.0, 1.0, 1.0, 0.0, 0.0, 1.0, 1.0, 0.0, 1.0, 0.0, 0.0, | ||
201 | 1.0, -1.0, -1.0, 1.0, 0.0, 0.0, 1.0, 1.0, 0.0, 1.0, 1.0, 0.0, | ||
202 | |||
203 | /* Top */ | ||
204 | -1.0, 1.0, -1.0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 1.0, 0.0, 1.0, | ||
205 | 1.0, 1.0, -1.0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 1.0, 1.0, 1.0, | ||
206 | -1.0, 1.0, 1.0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 1.0, 0.0, 0.0, | ||
207 | 1.0, 1.0, 1.0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 1.0, 1.0, 0.0, | ||
208 | |||
209 | /* Bottom */ | ||
210 | 1.0, -1.0, -1.0, 0.0, -1.0, 0.0, 0.0, 1.0, 1.0, 1.0, 0.0, 1.0, | ||
211 | -1.0, -1.0, -1.0, 0.0, -1.0, 0.0, 0.0, 1.0, 1.0, 1.0, 1.0, 1.0, | ||
212 | 1.0, -1.0, 1.0, 0.0, -1.0, 0.0, 0.0, 1.0, 1.0, 1.0, 0.0, 0.0, | ||
213 | -1.0, -1.0, 1.0, 0.0, -1.0, 0.0, 0.0, 1.0, 1.0, 1.0, 1.0, 0.0, | ||
214 | }; | ||
215 | |||
216 | static const unsigned short cube_indices[] = | ||
217 | { | ||
218 | /* Front */ | ||
219 | 0, 1, 2, 2, 1, 3, | ||
220 | |||
221 | /* Back */ | ||
222 | 4, 5, 6, 6, 5, 7, | ||
223 | |||
224 | /* Left */ | ||
225 | 8, 9, 10, 10, 9, 11, | ||
226 | |||
227 | /* Right */ | ||
228 | 12, 13, 14, 14, 13, 15, | ||
229 | |||
230 | /* Top */ | ||
231 | 16, 17, 18, 18, 17, 19, | ||
232 | |||
233 | /* Bottom */ | ||
234 | 20, 21, 22, 22, 21, 23 | ||
235 | }; | ||
236 | |||
237 | static const unsigned int pixels0[] = | ||
238 | { | ||
239 | 0xff0000ff, 0xff0000ff, 0xffff0000, 0xffff0000, | ||
240 | 0xff0000ff, 0xff0000ff, 0xffff0000, 0xffff0000, | ||
241 | 0xff00ff00, 0xff00ff00, 0xff000000, 0xff000000, | ||
242 | 0xff00ff00, 0xff00ff00, 0xff000000, 0xff000000, | ||
243 | }; | ||
244 | |||
245 | static const unsigned int pixels1[] = | ||
246 | { | ||
247 | 0xffff0000, 0xffff0000, 0xff00ff00, 0xff00ff00, | ||
248 | 0xffff0000, 0xffff0000, 0xff00ff00, 0xff00ff00, | ||
249 | 0xff0000ff, 0xff0000ff, 0xffffffff, 0xffffffff, | ||
250 | 0xff0000ff, 0xff0000ff, 0xffffffff, 0xffffffff, | ||
251 | }; | ||
252 | |||
253 | |||
254 | static int vertex_count = 0; | ||
255 | static vertex *sphere_vertices = NULL; | ||
256 | |||
257 | static int index_count = 0; | ||
258 | static unsigned short *sphere_indices = NULL; | ||
259 | |||
260 | static inline vec3 | ||
261 | _normalize(const vec3 *v) | ||
262 | { | ||
263 | double l = sqrt(v->x * v->x + v->y * v->y + v->z * v->z); | ||
264 | vec3 vec; | ||
265 | |||
266 | vec.x = v->x / l; | ||
267 | vec.y = v->y / l; | ||
268 | vec.z = v->z / l; | ||
269 | |||
270 | return vec; | ||
271 | } | ||
272 | |||
273 | |||
274 | static void _sphere_init(int precision) | ||
275 | { | ||
276 | int i, j; | ||
277 | unsigned short *index; | ||
278 | |||
279 | vertex_count = (precision + 1) * (precision + 1); | ||
280 | index_count = precision * precision * 6; | ||
281 | |||
282 | /* Allocate buffer. */ | ||
283 | sphere_vertices = malloc(sizeof(vertex) * vertex_count); | ||
284 | sphere_indices = malloc(sizeof(unsigned short) * index_count); | ||
285 | |||
286 | for (i = 0; i <= precision; i++) | ||
287 | { | ||
288 | double lati = (M_PI * (double)i) / (double)precision; | ||
289 | double y = cos(lati); | ||
290 | double r = fabs(sin(lati)); | ||
291 | |||
292 | for (j = 0; j <= precision; j++) | ||
293 | { | ||
294 | double longi = (M_PI * 2.0 * j) / precision; | ||
295 | vertex *v = &sphere_vertices[i * (precision + 1) + j]; | ||
296 | |||
297 | if (j == 0 || j == precision) | ||
298 | v->position.x = 0.0; | ||
299 | else | ||
300 | v->position.x = r * sin(longi); | ||
301 | |||
302 | v->position.y = y; | ||
303 | |||
304 | if (j == 0 || j == precision) | ||
305 | v->position.z = r; | ||
306 | else | ||
307 | v->position.z = r * cos(longi); | ||
308 | |||
309 | v->normal = v->position; | ||
310 | |||
311 | if (v->position.x > 0.0) | ||
312 | { | ||
313 | v->tangent.x = -v->normal.y; | ||
314 | v->tangent.y = v->normal.x; | ||
315 | v->tangent.z = v->normal.z; | ||
316 | } | ||
317 | else | ||
318 | { | ||
319 | v->tangent.x = v->normal.y; | ||
320 | v->tangent.y = -v->normal.x; | ||
321 | v->tangent.z = v->normal.z; | ||
322 | } | ||
323 | |||
324 | v->color.x = v->position.x; | ||
325 | v->color.y = v->position.y; | ||
326 | v->color.z = v->position.z; | ||
327 | v->color.w = 1.0; | ||
328 | |||
329 | if (j == precision) | ||
330 | v->texcoord.x = 1.0; | ||
331 | else if (j == 0) | ||
332 | v->texcoord.x = 0.0; | ||
333 | else | ||
334 | v->texcoord.x = (double)j / (double)precision; | ||
335 | |||
336 | if (i == precision) | ||
337 | v->texcoord.y = 1.0; | ||
338 | else if (i == 0) | ||
339 | v->texcoord.y = 0.0; | ||
340 | else | ||
341 | v->texcoord.y = 1.0 - (double)i / (double)precision; | ||
342 | } | ||
343 | } | ||
344 | |||
345 | index = &sphere_indices[0]; | ||
346 | |||
347 | for (i = 0; i < precision; i++) | ||
348 | { | ||
349 | for (j = 0; j < precision; j++) | ||
350 | { | ||
351 | *index++ = i * (precision + 1) + j; | ||
352 | *index++ = i * (precision + 1) + j + 1; | ||
353 | *index++ = (i + 1) * (precision + 1) + j; | ||
354 | |||
355 | *index++ = (i + 1) * (precision + 1) + j; | ||
356 | *index++ = i * (precision + 1) + j + 1; | ||
357 | *index++ = (i + 1) * (precision + 1) + j + 1; | ||
358 | } | ||
359 | } | ||
360 | |||
361 | for (i = 0; i < index_count; i += 3) | ||
362 | { | ||
363 | vertex *v0 = &sphere_vertices[sphere_indices[i + 0]]; | ||
364 | vertex *v1 = &sphere_vertices[sphere_indices[i + 1]]; | ||
365 | vertex *v2 = &sphere_vertices[sphere_indices[i + 2]]; | ||
366 | |||
367 | vec3 e1, e2; | ||
368 | float du1, du2, dv1, dv2, f; | ||
369 | vec3 tangent; | ||
370 | |||
371 | e1.x = v1->position.x - v0->position.x; | ||
372 | e1.y = v1->position.y - v0->position.y; | ||
373 | e1.z = v1->position.z - v0->position.z; | ||
374 | |||
375 | e2.x = v2->position.x - v0->position.x; | ||
376 | e2.y = v2->position.y - v0->position.y; | ||
377 | e2.z = v2->position.z - v0->position.z; | ||
378 | |||
379 | du1 = v1->texcoord.x - v0->texcoord.x; | ||
380 | dv1 = v1->texcoord.y - v0->texcoord.y; | ||
381 | |||
382 | du2 = v2->texcoord.x - v0->texcoord.x; | ||
383 | dv2 = v2->texcoord.y - v0->texcoord.y; | ||
384 | |||
385 | f = 1.0 / (du1 * dv2 - du2 * dv1); | ||
386 | |||
387 | tangent.x = f * (dv2 * e1.x - dv1 * e2.x); | ||
388 | tangent.y = f * (dv2 * e1.y - dv1 * e2.y); | ||
389 | tangent.z = f * (dv2 * e1.z - dv1 * e2.z); | ||
390 | |||
391 | v0->tangent = tangent; | ||
392 | } | ||
393 | |||
394 | for (i = 0; i <= precision; i++) | ||
395 | { | ||
396 | for (j = 0; j <= precision; j++) | ||
397 | { | ||
398 | if (j == precision) | ||
399 | { | ||
400 | vertex *v = &sphere_vertices[i * (precision + 1) + j]; | ||
401 | v->tangent = sphere_vertices[i * (precision + 1)].tangent; | ||
402 | } | ||
403 | } | ||
404 | } | ||
405 | } | ||
406 | |||
407 | |||
408 | void stuffsSetup(ExtantzStuffs *stuffs, globals *ourGlobals, Scene_Data *scene, int fake) | ||
409 | { | ||
410 | char buf[PATH_MAX]; | ||
411 | Material *m; | ||
412 | Evas_3D_Texture *t, *t1, *ti; | ||
413 | Evas_3D_Material *mi, *mj; | ||
414 | Evas_3D_Mesh *me; | ||
415 | |||
416 | // TODO - These examples just don't fit neatly into anything I can whip up quickly as a data format. | ||
417 | // So just fake it for now, and expand the data format later. | ||
418 | |||
419 | // Textures | ||
420 | if (1 == fake) | ||
421 | { | ||
422 | t = eo_add(EVAS_3D_TEXTURE_CLASS, ourGlobals->evas, | ||
423 | evas_3d_texture_data_set(EVAS_3D_COLOR_FORMAT_RGBA, EVAS_3D_PIXEL_FORMAT_8888, 4, 4, &pixels0[0]) | ||
424 | ); | ||
425 | eina_array_push(stuffs->textures, t); | ||
426 | |||
427 | t1 = eo_add(EVAS_3D_TEXTURE_CLASS, ourGlobals->evas, | ||
428 | evas_3d_texture_data_set(EVAS_3D_COLOR_FORMAT_RGBA, EVAS_3D_PIXEL_FORMAT_8888, 4, 4, &pixels1[0]) | ||
429 | ); | ||
430 | eina_array_push(stuffs->textures, t1); | ||
431 | } | ||
432 | |||
433 | EINA_INARRAY_FOREACH(stuffs->stuffs.details.mesh->materials, m) | ||
434 | { | ||
435 | snprintf(buf, sizeof(buf), "%s/%s", prefix_data_get(), m->texture); | ||
436 | ti = eo_add(EVAS_3D_TEXTURE_CLASS, ourGlobals->evas, | ||
437 | evas_3d_texture_file_set(buf, NULL), | ||
438 | evas_3d_texture_filter_set(EVAS_3D_TEXTURE_FILTER_LINEAR, EVAS_3D_TEXTURE_FILTER_LINEAR), // Only for sphere originally. | ||
439 | evas_3d_texture_filter_set(EVAS_3D_TEXTURE_FILTER_NEAREST, EVAS_3D_TEXTURE_FILTER_NEAREST), // Only for sonic originally. | ||
440 | evas_3d_texture_wrap_set(EVAS_3D_WRAP_MODE_REPEAT, EVAS_3D_WRAP_MODE_REPEAT) | ||
441 | ); | ||
442 | eina_array_push(stuffs->textures, ti); | ||
443 | } | ||
444 | |||
445 | // Materials. | ||
446 | if (1 == fake) | ||
447 | { | ||
448 | eina_accessor_data_get(stuffs->aTexture, 0, (void **) &t); | ||
449 | mi = eo_add(EVAS_3D_MATERIAL_CLASS, ourGlobals->evas, | ||
450 | evas_3d_material_enable_set(EVAS_3D_MATERIAL_AMBIENT, EINA_TRUE), | ||
451 | evas_3d_material_enable_set(EVAS_3D_MATERIAL_DIFFUSE, EINA_TRUE), | ||
452 | evas_3d_material_enable_set(EVAS_3D_MATERIAL_SPECULAR, EINA_TRUE), | ||
453 | evas_3d_material_enable_set(EVAS_3D_MATERIAL_NORMAL, EINA_TRUE), | ||
454 | |||
455 | evas_3d_material_color_set(EVAS_3D_MATERIAL_AMBIENT, 0.2, 0.2, 0.2, 1.0), | ||
456 | evas_3d_material_color_set(EVAS_3D_MATERIAL_DIFFUSE, 0.8, 0.8, 0.8, 1.0), | ||
457 | evas_3d_material_color_set(EVAS_3D_MATERIAL_SPECULAR, 1.0, 1.0, 1.0, 1.0), | ||
458 | evas_3d_material_shininess_set(100.0), | ||
459 | evas_3d_material_texture_set(EVAS_3D_MATERIAL_DIFFUSE, t) | ||
460 | ); | ||
461 | eina_array_push(stuffs->materials, mi); | ||
462 | |||
463 | eina_accessor_data_get(stuffs->aTexture, 1, (void **) &t1); | ||
464 | eina_accessor_data_get(stuffs->aTexture, 2, (void **) &ti); | ||
465 | mj = eo_add(EVAS_3D_MATERIAL_CLASS, ourGlobals->evas, | ||
466 | evas_3d_material_enable_set(EVAS_3D_MATERIAL_AMBIENT, EINA_TRUE), | ||
467 | evas_3d_material_enable_set(EVAS_3D_MATERIAL_DIFFUSE, EINA_TRUE), | ||
468 | evas_3d_material_enable_set(EVAS_3D_MATERIAL_SPECULAR, EINA_TRUE), | ||
469 | evas_3d_material_enable_set(EVAS_3D_MATERIAL_NORMAL, EINA_TRUE), | ||
470 | |||
471 | evas_3d_material_color_set(EVAS_3D_MATERIAL_AMBIENT, 0.2, 0.2, 0.2, 1.0), | ||
472 | evas_3d_material_color_set(EVAS_3D_MATERIAL_DIFFUSE, 0.8, 0.8, 0.8, 1.0), | ||
473 | evas_3d_material_color_set(EVAS_3D_MATERIAL_SPECULAR, 1.0, 1.0, 1.0, 1.0), | ||
474 | evas_3d_material_shininess_set(100.0), | ||
475 | |||
476 | evas_3d_material_texture_set(EVAS_3D_MATERIAL_DIFFUSE, t1), | ||
477 | evas_3d_material_texture_set(EVAS_3D_MATERIAL_NORMAL, ti) | ||
478 | ); | ||
479 | eina_array_push(stuffs->materials, mj); | ||
480 | } | ||
481 | else | ||
482 | { | ||
483 | eina_accessor_data_get(stuffs->aTexture, 0, (void **) &t); | ||
484 | mi = eo_add(EVAS_3D_MATERIAL_CLASS, ourGlobals->evas, | ||
485 | evas_3d_material_texture_set(EVAS_3D_MATERIAL_DIFFUSE, t), | ||
486 | |||
487 | evas_3d_material_enable_set(EVAS_3D_MATERIAL_AMBIENT, EINA_TRUE), | ||
488 | evas_3d_material_enable_set(EVAS_3D_MATERIAL_DIFFUSE, EINA_TRUE), | ||
489 | evas_3d_material_enable_set(EVAS_3D_MATERIAL_SPECULAR, EINA_TRUE), | ||
490 | evas_3d_material_enable_set(EVAS_3D_MATERIAL_NORMAL, EINA_TRUE), // Not for sphere originally. | ||
491 | |||
492 | evas_3d_material_color_set(EVAS_3D_MATERIAL_AMBIENT, 0.01, 0.01, 0.01, 1.0), | ||
493 | evas_3d_material_color_set(EVAS_3D_MATERIAL_DIFFUSE, 1.0, 1.0, 1.0, 1.0), | ||
494 | evas_3d_material_color_set(EVAS_3D_MATERIAL_SPECULAR, 1.0, 1.0, 1.0, 1.0), | ||
495 | evas_3d_material_shininess_set(50.0) | ||
496 | ); | ||
497 | eina_array_push(stuffs->materials, mi); | ||
498 | } | ||
499 | |||
500 | // Meshes | ||
501 | // TODO - Write real generic cube and sphere stuff later. | ||
502 | if (MT_CUBE == stuffs->stuffs.details.mesh->type) | ||
503 | { | ||
504 | eina_accessor_data_get(stuffs->aMaterial, 0, (void **) &mi); | ||
505 | eina_accessor_data_get(stuffs->aMaterial, 1, (void **) &mj); | ||
506 | me = eo_add(EVAS_3D_MESH_CLASS, ourGlobals->evas, | ||
507 | evas_3d_mesh_vertex_count_set(24), | ||
508 | evas_3d_mesh_frame_add(0), | ||
509 | |||
510 | evas_3d_mesh_frame_vertex_data_set(0, EVAS_3D_VERTEX_POSITION, 12 * sizeof(float), &cube_vertices[ 0]), | ||
511 | evas_3d_mesh_frame_vertex_data_set(0, EVAS_3D_VERTEX_NORMAL, 12 * sizeof(float), &cube_vertices[ 3]), | ||
512 | evas_3d_mesh_frame_vertex_data_set(0, EVAS_3D_VERTEX_COLOR, 12 * sizeof(float), &cube_vertices[ 6]), | ||
513 | evas_3d_mesh_frame_vertex_data_set(0, EVAS_3D_VERTEX_TEXCOORD, 12 * sizeof(float), &cube_vertices[10]), | ||
514 | |||
515 | evas_3d_mesh_index_data_set(EVAS_3D_INDEX_FORMAT_UNSIGNED_SHORT, 36, &cube_indices[0]), | ||
516 | evas_3d_mesh_vertex_assembly_set(EVAS_3D_VERTEX_ASSEMBLY_TRIANGLES), | ||
517 | |||
518 | evas_3d_mesh_shade_mode_set(EVAS_3D_SHADE_MODE_NORMAL_MAP), | ||
519 | |||
520 | evas_3d_mesh_frame_material_set(0, mi), | ||
521 | |||
522 | evas_3d_mesh_frame_add(20), | ||
523 | evas_3d_mesh_frame_material_set(20, mj) | ||
524 | ); | ||
525 | eina_array_push(stuffs->mesh, me); | ||
526 | } | ||
527 | else if (MT_SPHERE == stuffs->stuffs.details.mesh->type) | ||
528 | { | ||
529 | _sphere_init(100); | ||
530 | |||
531 | eina_accessor_data_get(stuffs->aMaterial, 0, (void **) &mi); | ||
532 | me = eo_add(EVAS_3D_MESH_CLASS, ourGlobals->evas, | ||
533 | evas_3d_mesh_vertex_count_set(vertex_count), | ||
534 | evas_3d_mesh_frame_add(0), | ||
535 | evas_3d_mesh_frame_vertex_data_set(0, EVAS_3D_VERTEX_POSITION, sizeof(vertex), &sphere_vertices[0].position), | ||
536 | evas_3d_mesh_frame_vertex_data_set(0, EVAS_3D_VERTEX_NORMAL, sizeof(vertex), &sphere_vertices[0].normal), | ||
537 | evas_3d_mesh_frame_vertex_data_set(0, EVAS_3D_VERTEX_TANGENT, sizeof(vertex), &sphere_vertices[0].tangent), | ||
538 | evas_3d_mesh_frame_vertex_data_set(0, EVAS_3D_VERTEX_COLOR, sizeof(vertex), &sphere_vertices[0].color), | ||
539 | evas_3d_mesh_frame_vertex_data_set(0, EVAS_3D_VERTEX_TEXCOORD, sizeof(vertex), &sphere_vertices[0].texcoord), | ||
540 | |||
541 | evas_3d_mesh_index_data_set(EVAS_3D_INDEX_FORMAT_UNSIGNED_SHORT, index_count, &sphere_indices[0]), | ||
542 | evas_3d_mesh_vertex_assembly_set(EVAS_3D_VERTEX_ASSEMBLY_TRIANGLES), | ||
543 | evas_3d_mesh_frame_material_set(0, mi), | ||
544 | |||
545 | evas_3d_mesh_shade_mode_set(EVAS_3D_SHADE_MODE_DIFFUSE) | ||
546 | ); | ||
547 | eina_array_push(stuffs->mesh, me); | ||
548 | } | ||
549 | else | ||
550 | { | ||
551 | eina_accessor_data_get(stuffs->aMaterial, 0, (void **) &mi); | ||
552 | snprintf(buf, sizeof(buf), "%s/%s", prefix_data_get(), stuffs->stuffs.details.mesh->fileName); | ||
553 | me = eo_add(EVAS_3D_MESH_CLASS, ourGlobals->evas, | ||
554 | evas_3d_mesh_file_set(EVAS_3D_MESH_FILE_TYPE_MD2, buf, NULL), | ||
555 | evas_3d_mesh_frame_material_set(0, mi), | ||
556 | evas_3d_mesh_shade_mode_set(EVAS_3D_SHADE_MODE_PHONG) | ||
557 | ); | ||
558 | eina_array_push(stuffs->mesh, me); | ||
559 | } | ||
560 | |||
561 | eina_accessor_data_get(stuffs->aMesh, 0, (void **) &me); | ||
562 | stuffs->mesh_node = eo_add_custom(EVAS_3D_NODE_CLASS, ourGlobals->evas, evas_3d_node_constructor(EVAS_3D_NODE_TYPE_MESH), | ||
563 | eo_key_data_set("Name", stuffs->stuffs.name, NULL), | ||
564 | evas_3d_node_position_set(stuffs->stuffs.details.mesh->pos.x, stuffs->stuffs.details.mesh->pos.y, stuffs->stuffs.details.mesh->pos.z), | ||
565 | evas_3d_node_orientation_set(stuffs->stuffs.details.mesh->rot.x, stuffs->stuffs.details.mesh->rot.y, stuffs->stuffs.details.mesh->rot.z, stuffs->stuffs.details.mesh->rot.w), | ||
566 | evas_3d_node_mesh_add(me) | ||
567 | ); | ||
568 | |||
569 | eo_do(scene->root_node, evas_3d_node_member_add(stuffs->mesh_node)); | ||
570 | eina_clist_add_head(&(ourGlobals->stuffs), &(stuffs->node)); | ||
571 | } | ||
572 | |||
573 | ExtantzStuffs *addStuffs(char *uuid, char *name, char *description, char *owner, | ||
574 | char *file, MeshType type, float px, float py, float pz, float rx, float ry, float rz, float rw) | ||
575 | { | ||
576 | ExtantzStuffs *result = calloc(1, sizeof(ExtantzStuffs)); | ||
577 | |||
578 | // TODO - using Eina arrays of any sort seems a bit heavy, might be better to just count and realloc? | ||
579 | result->materials = eina_array_new(3); | ||
580 | result->mesh = eina_array_new(3); | ||
581 | result->textures = eina_array_new(3); | ||
582 | result->aMaterial = eina_array_accessor_new(result->materials); | ||
583 | result->aMesh = eina_array_accessor_new(result->mesh); | ||
584 | result->aTexture = eina_array_accessor_new(result->textures); | ||
585 | result->stuffs.details.mesh = calloc(1, sizeof(Mesh)); | ||
586 | result->stuffs.details.mesh->materials = eina_inarray_new(sizeof(Material), 1); | ||
587 | result->stuffs.details.mesh->parts = eina_inarray_new(sizeof(Mesh), 1); | ||
588 | |||
589 | strcpy(result->stuffs.UUID, uuid); | ||
590 | strcpy(result->stuffs.name, name); | ||
591 | strcpy(result->stuffs.description, description); | ||
592 | strcpy(result->stuffs.owner, owner); | ||
593 | |||
594 | strcpy(result->stuffs.details.mesh->fileName, file); | ||
595 | result->stuffs.details.mesh->type = type; | ||
596 | result->stuffs.details.mesh->pos.x = px; result->stuffs.details.mesh->pos.y = py; result->stuffs.details.mesh->pos.z = pz; | ||
597 | result->stuffs.details.mesh->rot.x = rx; result->stuffs.details.mesh->rot.y = ry; result->stuffs.details.mesh->rot.z = rz; result->stuffs.details.mesh->rot.w = rw; | ||
598 | |||
599 | return result; | ||
600 | } | ||
601 | |||
602 | void addMaterial(ExtantzStuffs *e, int face, TextureType type, char *file) | ||
603 | { | ||
604 | Material *result = calloc(1, sizeof(Material)); | ||
605 | |||
606 | // face -1 means "all of them I think". | ||
607 | result->face = face; | ||
608 | result->type = type; | ||
609 | strcpy(result->texture, file); | ||
610 | eina_inarray_push(e->stuffs.details.mesh->materials, result); | ||
611 | } | ||
612 | |||
613 | void Evas_3D_Demo_fini(globals *ourGlobals) | ||
614 | { | ||
615 | free(sphere_vertices); | ||
616 | free(sphere_indices); | ||
617 | } | ||