aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src/extantz/Evas_3D_demo.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/extantz/Evas_3D_demo.c')
-rw-r--r--src/extantz/Evas_3D_demo.c354
1 files changed, 267 insertions, 87 deletions
diff --git a/src/extantz/Evas_3D_demo.c b/src/extantz/Evas_3D_demo.c
index 371bba7..2d3d46e 100644
--- a/src/extantz/Evas_3D_demo.c
+++ b/src/extantz/Evas_3D_demo.c
@@ -232,17 +232,14 @@ _sphere_init(int precision)
232 } 232 }
233} 233}
234 234
235Eina_Bool _animate_scene(globals *ourGlobals) 235static void _animateCube(ExtantzStuffs *stuffs)
236{ 236{
237 static float angle = 0.0f; 237 static float angle = 0.0f;
238 static float earthAngle = 0.0f;
239 static int frame = 0; 238 static int frame = 0;
240 static int inc = 1; 239 static int inc = 1;
241 static int sonicFrame = 0; 240 Evas_3D_Mesh *m;
242 241
243 Scene_Data *scene = ourGlobals->scene; 242 eina_accessor_data_get(stuffs->aMesh, 0, (void **) &m);
244
245 // Animate cube.
246 angle += 0.5; 243 angle += 0.5;
247 if (angle > 360.0) angle -= 360.0f; 244 if (angle > 360.0) angle -= 360.0f;
248 245
@@ -250,10 +247,24 @@ Eina_Bool _animate_scene(globals *ourGlobals)
250 if (frame >= 20) inc = -1; 247 if (frame >= 20) inc = -1;
251 else if (frame <= 0) inc = 1; 248 else if (frame <= 0) inc = 1;
252 249
253 eo_do(scene->mesh_node, 250 eo_do(stuffs->mesh_node,
254 evas_3d_node_orientation_angle_axis_set(angle, 1.0, 1.0, 1.0), 251 evas_3d_node_orientation_angle_axis_set(angle, 1.0, 1.0, 1.0),
255 evas_3d_node_mesh_frame_set(scene->mesh, frame) 252 evas_3d_node_mesh_frame_set(m, frame)
256 ); 253 );
254}
255
256Eina_Bool _animate_scene(globals *ourGlobals)
257{
258 static float earthAngle = 0.0f;
259 static int sonicFrame = 0;
260 ExtantzStuffs *e;
261
262 Scene_Data *scene = ourGlobals->scene;
263
264 EINA_CLIST_FOR_EACH_ENTRY(e, &ourGlobals->stuffs, ExtantzStuffs, node)
265 {
266 if (e->animateStuffs) e->animateStuffs(e);
267 }
257 268
258 // Animate sonic. 269 // Animate sonic.
259 sonicFrame += 32; 270 sonicFrame += 32;
@@ -266,88 +277,12 @@ Eina_Bool _animate_scene(globals *ourGlobals)
266 earthAngle += 0.3; 277 earthAngle += 0.3;
267 if (earthAngle > 360.0) earthAngle -= 360.0f; 278 if (earthAngle > 360.0) earthAngle -= 360.0f;
268 eo_do(scene->mesh3_node, 279 eo_do(scene->mesh3_node,
269 evas_3d_node_orientation_angle_axis_set(angle, 0.0, 1.0, 0.0) 280 evas_3d_node_orientation_angle_axis_set(earthAngle, 0.0, 1.0, 0.0)
270 ); 281 );
271 282
272 return EINA_TRUE; 283 return EINA_TRUE;
273} 284}
274 285
275static void _cube_setup(globals *ourGlobals, Scene_Data *scene)
276{
277 char buf[PATH_MAX];
278
279 // Setup cube materials.
280 scene->texture0 = eo_add(EVAS_3D_TEXTURE_CLASS, ourGlobals->evas,
281 evas_3d_texture_data_set(EVAS_3D_COLOR_FORMAT_RGBA, EVAS_3D_PIXEL_FORMAT_8888, 4, 4, &pixels0[0])
282 );
283
284 scene->texture1 = eo_add(EVAS_3D_TEXTURE_CLASS, ourGlobals->evas,
285 evas_3d_texture_data_set(EVAS_3D_COLOR_FORMAT_RGBA, EVAS_3D_PIXEL_FORMAT_8888, 4, 4, &pixels1[0])
286 );
287
288 snprintf(buf, sizeof(buf), "%s/normal_lego.png", prefix_data_get());
289 scene->texture_normal = eo_add(EVAS_3D_TEXTURE_CLASS, ourGlobals->evas,
290 evas_3d_texture_file_set(buf, NULL)
291 );
292
293 scene->material0 = eo_add(EVAS_3D_MATERIAL_CLASS, ourGlobals->evas,
294 evas_3d_material_enable_set(EVAS_3D_MATERIAL_AMBIENT, EINA_TRUE),
295 evas_3d_material_enable_set(EVAS_3D_MATERIAL_DIFFUSE, EINA_TRUE),
296 evas_3d_material_enable_set(EVAS_3D_MATERIAL_SPECULAR, EINA_TRUE),
297 evas_3d_material_enable_set(EVAS_3D_MATERIAL_NORMAL, EINA_TRUE),
298
299 evas_3d_material_color_set(EVAS_3D_MATERIAL_AMBIENT, 0.2, 0.2, 0.2, 1.0),
300 evas_3d_material_color_set(EVAS_3D_MATERIAL_DIFFUSE, 0.8, 0.8, 0.8, 1.0),
301 evas_3d_material_color_set(EVAS_3D_MATERIAL_SPECULAR, 1.0, 1.0, 1.0, 1.0),
302 evas_3d_material_shininess_set(100.0),
303 evas_3d_material_texture_set(EVAS_3D_MATERIAL_DIFFUSE, scene->texture0)
304 );
305
306 scene->material1 = eo_add(EVAS_3D_MATERIAL_CLASS, ourGlobals->evas,
307 evas_3d_material_enable_set(EVAS_3D_MATERIAL_AMBIENT, EINA_TRUE),
308 evas_3d_material_enable_set(EVAS_3D_MATERIAL_DIFFUSE, EINA_TRUE),
309 evas_3d_material_enable_set(EVAS_3D_MATERIAL_SPECULAR, EINA_TRUE),
310 evas_3d_material_enable_set(EVAS_3D_MATERIAL_NORMAL, EINA_TRUE),
311
312 evas_3d_material_color_set(EVAS_3D_MATERIAL_AMBIENT, 0.2, 0.2, 0.2, 1.0),
313 evas_3d_material_color_set(EVAS_3D_MATERIAL_DIFFUSE, 0.8, 0.8, 0.8, 1.0),
314 evas_3d_material_color_set(EVAS_3D_MATERIAL_SPECULAR, 1.0, 1.0, 1.0, 1.0),
315 evas_3d_material_shininess_set(100.0),
316
317 evas_3d_material_texture_set(EVAS_3D_MATERIAL_DIFFUSE, scene->texture1),
318 evas_3d_material_texture_set(EVAS_3D_MATERIAL_NORMAL, scene->texture_normal)
319 );
320
321 // Setup CUBE mesh.
322 scene->mesh = eo_add(EVAS_3D_MESH_CLASS, ourGlobals->evas,
323 evas_3d_mesh_vertex_count_set(24),
324 evas_3d_mesh_frame_add(0),
325
326 evas_3d_mesh_frame_vertex_data_set(0, EVAS_3D_VERTEX_POSITION, 12 * sizeof(float), &cube_vertices[ 0]),
327 evas_3d_mesh_frame_vertex_data_set(0, EVAS_3D_VERTEX_NORMAL, 12 * sizeof(float), &cube_vertices[ 3]),
328 evas_3d_mesh_frame_vertex_data_set(0, EVAS_3D_VERTEX_COLOR, 12 * sizeof(float), &cube_vertices[ 6]),
329 evas_3d_mesh_frame_vertex_data_set(0, EVAS_3D_VERTEX_TEXCOORD, 12 * sizeof(float), &cube_vertices[10]),
330
331 evas_3d_mesh_index_data_set(EVAS_3D_INDEX_FORMAT_UNSIGNED_SHORT, 36, &cube_indices[0]),
332 evas_3d_mesh_vertex_assembly_set(EVAS_3D_VERTEX_ASSEMBLY_TRIANGLES),
333
334 evas_3d_mesh_shade_mode_set(EVAS_3D_SHADE_MODE_NORMAL_MAP),
335
336 evas_3d_mesh_frame_material_set(0, scene->material0),
337
338 evas_3d_mesh_frame_add(20),
339 evas_3d_mesh_frame_material_set(20, scene->material1)
340 );
341
342 scene->mesh_node = eo_add_custom(EVAS_3D_NODE_CLASS, ourGlobals->evas, evas_3d_node_constructor(EVAS_3D_NODE_TYPE_MESH),
343 eo_key_data_set("Name", "cube", NULL),
344 evas_3d_node_position_set(0.0, 4.0, 10.0),
345 evas_3d_node_mesh_add(scene->mesh)
346 );
347
348 eo_do(scene->root_node, evas_3d_node_member_add(scene->mesh_node));
349}
350
351static void _sonic_setup(globals *ourGlobals, Scene_Data *scene) 286static void _sonic_setup(globals *ourGlobals, Scene_Data *scene)
352{ 287{
353 char buf[PATH_MAX]; 288 char buf[PATH_MAX];
@@ -443,12 +378,257 @@ static void _earth_setup(globals *ourGlobals, Scene_Data *scene)
443 eo_do(scene->root_node, evas_3d_node_member_add(scene->mesh3_node)); 378 eo_do(scene->root_node, evas_3d_node_member_add(scene->mesh3_node));
444} 379}
445 380
381/* For now lets just pretend we got stuffs sent from our love.
382
383Stuffs =
384{
385 name = "Test sim",
386 description = 'onefangs test SledjHamr sim.',
387-- owner = '12345678-1234-4321-abcd-0123456789ab',
388 details =
389 {
390 stuffs =
391 {
392 Mesh =
393 {
394 fileName = 'onefang%27s%20test%20bed.omg',
395 pos = {0.0, 4.0, 10.0},
396 size = {1.0, 1.0, 1.0},
397 rot = {1.0, 0.0, 0.0, 0.0},
398 },
399 Mesh =
400 {
401 fileName = 'sonic.omg',
402 pos = {0.0, 0.0, 0.0},
403 size = {1.0, 1.0, 1.0},
404 rot = {-0.7071067811865475, 0.0, 0.0, 0.7071067811865475},
405 },
406 Mesh =
407 {
408 fileName = 'earth.omg',
409 pos = {0.0, 0.0, 0.0},
410 size = {1.0, 1.0, 1.0},
411 rot = {1.0, 0.0, 0.0, 0.0},
412 },
413 },
414 },
415}
416
417
418Stuffs =
419{
420 name = "onefang's test bed",
421 description = 'Just a pretend bed with MLP scripts for testing SledjHamr.',
422-- owner = '12345678-1234-4321-abcd-0123456789ab',
423 details =
424 {
425 Mesh =
426 {
427 kind = 'cube',
428 materials = {'normal_lego.png'},
429 },
430 },
431}
432
433
434Stuffs =
435{
436 name = "onefang's left testicle",
437 description = 'Just a pretend world for testing SledjHamr.',
438-- owner = '12345678-1234-4321-abcd-0123456789ab',
439 details =
440 {
441 Mesh =
442 {
443 kind = 'sphere',
444-- insert prim parameters here
445 materials = {'EarthDiffuse.png'},
446 },
447 },
448}
449
450
451Stuffs =
452{
453 name = "Sonic the bed hog.",
454 description = 'Just a pretend avatar for testing SledjHamr.',
455-- owner = '12345678-1234-4321-abcd-0123456789ab',
456 details =
457 {
458 Mesh =
459 {
460 fileName = 'sonic.md2',
461 materials = {'sonic.png'},
462 },
463 },
464}
465
466*/
467
468void stuffs_setup(ExtantzStuffs *stuffs, globals *ourGlobals, Scene_Data *scene, int fake)
469{
470 char buf[PATH_MAX];
471 Material *m;
472 Evas_3D_Texture *t, *t1, *ti;
473 Evas_3D_Material *mi, *mj;
474 Evas_3D_Mesh *me;
475
476 // TODO - using Eina arrays of any sort seems a bit heavy, might be better to just count and realloc?
477 stuffs->materials = eina_array_new(3);
478 stuffs->mesh = eina_array_new(3);
479 stuffs->textures = eina_array_new(3);
480 stuffs->aMaterial = eina_array_accessor_new(stuffs->materials);
481 stuffs->aMesh = eina_array_accessor_new(stuffs->mesh);
482 stuffs->aTexture = eina_array_accessor_new(stuffs->textures);
483
484// TODO - These examples just don't fit neatly into anything I can whip up quickly as a data format.
485// So just fake it for now, and expand the data format later.
486
487 // Textures
488 if (1 == fake)
489 {
490 t = eo_add(EVAS_3D_TEXTURE_CLASS, ourGlobals->evas,
491 evas_3d_texture_data_set(EVAS_3D_COLOR_FORMAT_RGBA, EVAS_3D_PIXEL_FORMAT_8888, 4, 4, &pixels0[0])
492 );
493 eina_array_push(stuffs->textures, t);
494
495 t1 = eo_add(EVAS_3D_TEXTURE_CLASS, ourGlobals->evas,
496 evas_3d_texture_data_set(EVAS_3D_COLOR_FORMAT_RGBA, EVAS_3D_PIXEL_FORMAT_8888, 4, 4, &pixels1[0])
497 );
498 eina_array_push(stuffs->textures, t1);
499 }
500 else if (2 == fake)
501 {
502 }
503 else if (3 == fake)
504 {
505 }
506
507 EINA_INARRAY_FOREACH(stuffs->stuffs.details.mesh->materials, m)
508 {
509 snprintf(buf, sizeof(buf), "%s/%s", prefix_data_get(), m->texture);
510 ti = eo_add(EVAS_3D_TEXTURE_CLASS, ourGlobals->evas, evas_3d_texture_file_set(buf, NULL));
511 eina_array_push(stuffs->textures, ti);
512 }
513
514 // Materials.
515 if (1 == fake)
516 {
517 eina_accessor_data_get(stuffs->aTexture, 0, (void **) &t);
518 mi = eo_add(EVAS_3D_MATERIAL_CLASS, ourGlobals->evas,
519 evas_3d_material_enable_set(EVAS_3D_MATERIAL_AMBIENT, EINA_TRUE),
520 evas_3d_material_enable_set(EVAS_3D_MATERIAL_DIFFUSE, EINA_TRUE),
521 evas_3d_material_enable_set(EVAS_3D_MATERIAL_SPECULAR, EINA_TRUE),
522 evas_3d_material_enable_set(EVAS_3D_MATERIAL_NORMAL, EINA_TRUE),
523
524 evas_3d_material_color_set(EVAS_3D_MATERIAL_AMBIENT, 0.2, 0.2, 0.2, 1.0),
525 evas_3d_material_color_set(EVAS_3D_MATERIAL_DIFFUSE, 0.8, 0.8, 0.8, 1.0),
526 evas_3d_material_color_set(EVAS_3D_MATERIAL_SPECULAR, 1.0, 1.0, 1.0, 1.0),
527 evas_3d_material_shininess_set(100.0),
528 evas_3d_material_texture_set(EVAS_3D_MATERIAL_DIFFUSE, t)
529 );
530 eina_array_push(stuffs->materials, mi);
531
532 eina_accessor_data_get(stuffs->aTexture, 1, (void **) &t1);
533 eina_accessor_data_get(stuffs->aTexture, 2, (void **) &ti);
534 mj = eo_add(EVAS_3D_MATERIAL_CLASS, ourGlobals->evas,
535 evas_3d_material_enable_set(EVAS_3D_MATERIAL_AMBIENT, EINA_TRUE),
536 evas_3d_material_enable_set(EVAS_3D_MATERIAL_DIFFUSE, EINA_TRUE),
537 evas_3d_material_enable_set(EVAS_3D_MATERIAL_SPECULAR, EINA_TRUE),
538 evas_3d_material_enable_set(EVAS_3D_MATERIAL_NORMAL, EINA_TRUE),
539
540 evas_3d_material_color_set(EVAS_3D_MATERIAL_AMBIENT, 0.2, 0.2, 0.2, 1.0),
541 evas_3d_material_color_set(EVAS_3D_MATERIAL_DIFFUSE, 0.8, 0.8, 0.8, 1.0),
542 evas_3d_material_color_set(EVAS_3D_MATERIAL_SPECULAR, 1.0, 1.0, 1.0, 1.0),
543 evas_3d_material_shininess_set(100.0),
544
545 evas_3d_material_texture_set(EVAS_3D_MATERIAL_DIFFUSE, t1),
546 evas_3d_material_texture_set(EVAS_3D_MATERIAL_NORMAL, ti)
547 );
548 eina_array_push(stuffs->materials, mj);
549 }
550 else if (2 == fake)
551 {
552 }
553 else if (3 == fake)
554 {
555 }
556
557 // Meshes
558 // TODO - Write real generic cube and sphere stuff later.
559 if (MT_CUBE == stuffs->stuffs.details.mesh->type)
560 {
561 eina_accessor_data_get(stuffs->aMaterial, 0, (void **) &mi);
562 eina_accessor_data_get(stuffs->aMaterial, 1, (void **) &mj);
563 me = eo_add(EVAS_3D_MESH_CLASS, ourGlobals->evas,
564 evas_3d_mesh_vertex_count_set(24),
565 evas_3d_mesh_frame_add(0),
566
567 evas_3d_mesh_frame_vertex_data_set(0, EVAS_3D_VERTEX_POSITION, 12 * sizeof(float), &cube_vertices[ 0]),
568 evas_3d_mesh_frame_vertex_data_set(0, EVAS_3D_VERTEX_NORMAL, 12 * sizeof(float), &cube_vertices[ 3]),
569 evas_3d_mesh_frame_vertex_data_set(0, EVAS_3D_VERTEX_COLOR, 12 * sizeof(float), &cube_vertices[ 6]),
570 evas_3d_mesh_frame_vertex_data_set(0, EVAS_3D_VERTEX_TEXCOORD, 12 * sizeof(float), &cube_vertices[10]),
571
572 evas_3d_mesh_index_data_set(EVAS_3D_INDEX_FORMAT_UNSIGNED_SHORT, 36, &cube_indices[0]),
573 evas_3d_mesh_vertex_assembly_set(EVAS_3D_VERTEX_ASSEMBLY_TRIANGLES),
574
575 evas_3d_mesh_shade_mode_set(EVAS_3D_SHADE_MODE_NORMAL_MAP),
576
577 evas_3d_mesh_frame_material_set(0, mi),
578
579 evas_3d_mesh_frame_add(20),
580 evas_3d_mesh_frame_material_set(20, mj)
581 );
582 eina_array_push(stuffs->mesh, me);
583 stuffs->animateStuffs = (aniStuffs) _animateCube;
584 }
585 else if (MT_CUBE == stuffs->stuffs.details.mesh->type)
586 {
587 }
588 else
589 {
590 }
591
592 eina_accessor_data_get(stuffs->aMesh, 0, (void **) &me);
593 stuffs->mesh_node = eo_add_custom(EVAS_3D_NODE_CLASS, ourGlobals->evas, evas_3d_node_constructor(EVAS_3D_NODE_TYPE_MESH),
594 eo_key_data_set("Name", stuffs->stuffs.name, NULL),
595 evas_3d_node_position_set(stuffs->stuffs.details.mesh->pos.x, stuffs->stuffs.details.mesh->pos.y, stuffs->stuffs.details.mesh->pos.z),
596 evas_3d_node_mesh_add(me)
597 );
598
599 eo_do(scene->root_node, evas_3d_node_member_add(stuffs->mesh_node));
600 eina_clist_add_head(&(ourGlobals->stuffs), &(stuffs->node));
601}
602
603Material bedMat;
604Mesh bedMesh;
605ExtantzStuffs eStuffs;
446 606
447void Evas_3D_Demo_add(globals *ourGlobals) 607void Evas_3D_Demo_add(globals *ourGlobals)
448{ 608{
609
610 bedMat.face = -1; // face -1 means "all of them I think".
611 bedMat.type = TT_NORMAL;
612 sprintf(bedMat.texture, "normal_lego.png");
613
614 sprintf(bedMesh.fileName, "onefang%%27s%%20test%%20bed.omg");
615 bedMesh.type = MT_CUBE;
616 bedMesh.pos.x = 0.0; bedMesh.pos.y = 4.0; bedMesh.pos.z = 10.0;
617 bedMesh.rot.x = 1.0; bedMesh.rot.y = 0.0; bedMesh.rot.z = 0.0; bedMesh.rot.w = 0.0;
618 bedMesh.materials = eina_inarray_new(sizeof(Material), 1);
619 bedMesh.materials = eina_inarray_new(sizeof(Mesh), 1);
620 eina_inarray_push(bedMesh.materials, &bedMat);
621
622 sprintf(eStuffs.stuffs.UUID, FAKE_UUID);
623 sprintf(eStuffs.stuffs.name, "onefang's test bed");
624 sprintf(eStuffs.stuffs.description, "Just a pretend bed with MLP scripts for testing SledjHamr.");
625 sprintf(eStuffs.stuffs.owner, "12345678-1234-4321-abcd-0123456789ab");
626 eStuffs.stuffs.details.mesh = &bedMesh;
627
449 ourGlobals->scene = scenriAdd(ourGlobals->win); 628 ourGlobals->scene = scenriAdd(ourGlobals->win);
450 629
451 _cube_setup(ourGlobals, ourGlobals->scene); 630 stuffs_setup(&eStuffs, ourGlobals, ourGlobals->scene, 1);
631
452 _sonic_setup(ourGlobals, ourGlobals->scene); 632 _sonic_setup(ourGlobals, ourGlobals->scene);
453 _earth_setup(ourGlobals, ourGlobals->scene); 633 _earth_setup(ourGlobals, ourGlobals->scene);
454} 634}