1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
|
/**
* This example is a testing example, first model (from the right side) is
* original model, the second one is convex hull maden in evas-3d,
* the third one is convex hull maden in blender.
*
* Press "Right" or "Left" to switch models, the result of test (vertex count)
* will be printed in console window.
*
* @verbatim
* gcc -o evas-3d-hull evas-3d-hull.c -g `pkg-config --libs --cflags efl evas ecore ecore-evas eo eina` -lm
* @endverbatim
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#else
#define PACKAGE_EXAMPLES_DIR "."
#define EFL_EO_API_SUPPORT
#define EFL_BETA_API_SUPPORT
#endif
#include <Eo.h>
#include <Evas.h>
#include <Ecore.h>
#include <Ecore_Evas.h>
#include "evas-common.h"
#define WIDTH 1024
#define HEIGHT 1024
#define TESTS_COUNT 8
#define SCALE_SPHERE 2.0
#define SCALE_TORUS 2.7
#define SCALE_HOME 0.7
#define SCALE_SONIC 0.08
#define SCALE_EAGLE 0.06
typedef struct _Scene_Data
{
Eo *scene;
Eo *root_node;
Eo *camera_node;
Eo *light_node;
Eo *mesh_node;
Eo *mesh_node_convex_hull;
Eo *mesh_node_blender;
Eo *camera;
Eo *light;
Eo *mesh_sphere;
Eo *mesh_torus;
Eo *mesh_cube;
Eo *mesh_plain;
Eo *mesh_column;
Eo *mesh_home;
Eo *mesh_sonic;
Eo *mesh_eagle;
Eo *mesh_sphere_ch;
Eo *mesh_torus_ch;
Eo *mesh_cube_ch;
Eo *mesh_plain_ch;
Eo *mesh_column_ch;
Eo *mesh_home_ch;
Eo *mesh_sonic_ch;
Eo *mesh_eagle_ch;
Eo *mesh_blender_sphere;
Eo *mesh_blender_torus;
Eo *mesh_blender_cube;
Eo *mesh_blender_plain;
Eo *mesh_blender_column;
Eo *mesh_blender_home;
Eo *mesh_blender_sonic;
Eo *mesh_blender_eagle;
Eo *mesh_blender_test_sphere;
Eo *mesh_blender_test_torus;
Eo *mesh_blender_test_cube;
Eo *mesh_blender_test_plain;
Eo *mesh_blender_test_column;
Eo *mesh_blender_test_home;
Eo *mesh_blender_test_sonic;
Eo *mesh_blender_test_eagle;
Eo *material;
} Scene_Data;
int rr;
#define MODEL_MESH_INIT(name, model, shade) \
data->mesh_##name = eo_add(EVAS_CANVAS3D_MESH_CLASS, evas); \
eo_do(data->mesh_##name, \
efl_file_set(model, NULL), \
evas_canvas3d_mesh_vertex_assembly_set(EVAS_CANVAS3D_VERTEX_ASSEMBLY_TRIANGLES), \
evas_canvas3d_mesh_shade_mode_set(EVAS_CANVAS3D_SHADE_MODE_##shade), \
evas_canvas3d_mesh_frame_material_set(0, data->material));
#define CONVEX_HULL_MESH_INIT(name) \
vert = eina_inarray_new(sizeof(float), 1); \
ind = eina_inarray_new(sizeof(unsigned short int), 1);\
eo_do(data->mesh_##name, \
evas_canvas3d_mesh_convex_hull_data_get(0, vert, ind)); \
vertex = (float*) vert->members;\
index = ind->members;\
data->mesh_##name##_ch = eo_add(EVAS_CANVAS3D_MESH_CLASS, evas); \
eo_do(data->mesh_##name##_ch, \
evas_canvas3d_mesh_vertex_count_set((vert->len / 10)), \
evas_canvas3d_mesh_frame_add(0), \
evas_canvas3d_mesh_frame_vertex_data_copy_set(0, EVAS_CANVAS3D_VERTEX_ATTRIB_POSITION, \
10 * sizeof(float), &vertex[ 0]), \
evas_canvas3d_mesh_frame_vertex_data_copy_set(0, EVAS_CANVAS3D_VERTEX_ATTRIB_NORMAL, \
10 * sizeof(float), &vertex[ 3]), \
evas_canvas3d_mesh_frame_vertex_data_copy_set(0, EVAS_CANVAS3D_VERTEX_ATTRIB_COLOR, \
10 * sizeof(float), &vertex[ 6]), \
evas_canvas3d_mesh_index_data_copy_set(EVAS_CANVAS3D_INDEX_FORMAT_UNSIGNED_SHORT, \
ind->len, &index[0]), \
evas_canvas3d_mesh_vertex_assembly_set(EVAS_CANVAS3D_VERTEX_ASSEMBLY_TRIANGLES), \
evas_canvas3d_mesh_shade_mode_set(EVAS_CANVAS3D_SHADE_MODE_VERTEX_COLOR), \
evas_canvas3d_mesh_frame_material_set(0, data->material)); \
free(vert); \
free(ind);
#define SWITCH_MESH(index, name, scale) \
case index: \
{ \
eo_do(scene->mesh_node, list = evas_canvas3d_node_mesh_list_get()); \
mesh = eina_list_nth(list, 0); \
eo_do(scene->mesh_node, \
evas_canvas3d_node_mesh_del(mesh), \
evas_canvas3d_node_mesh_add(scene->mesh_##name), \
evas_canvas3d_node_scale_set(scale, scale, scale)); \
eo_do(scene->mesh_node_convex_hull, list = evas_canvas3d_node_mesh_list_get()); \
mesh = eina_list_nth(list, 0); \
eo_do(scene->mesh_node_convex_hull, \
evas_canvas3d_node_mesh_del(mesh), \
evas_canvas3d_node_mesh_add(scene->mesh_##name##_ch), \
evas_canvas3d_node_scale_set(scale, scale, scale)); \
eo_do(scene->mesh_node_blender, list = evas_canvas3d_node_mesh_list_get()); \
mesh = eina_list_nth(list, 0); \
eo_do(scene->mesh_node_blender, \
evas_canvas3d_node_mesh_del(mesh), \
evas_canvas3d_node_mesh_add(scene->mesh_blender_##name), \
evas_canvas3d_node_scale_set(scale, scale, scale)); \
_print_result(scene->mesh_##name##_ch, scene->mesh_blender_test_##name); \
break; \
}
static const char *home = PACKAGE_EXAMPLES_DIR EVAS_MODEL_FOLDER "/sweet_home_without_tex_coords.obj";
static const char *sonic = PACKAGE_EXAMPLES_DIR EVAS_MODEL_FOLDER "/sonic.md2";
static const char *eagle = PACKAGE_EXAMPLES_DIR "/shooter/assets/models/eagle.md2";
static const char *column = PACKAGE_EXAMPLES_DIR EVAS_CONVEX_HULL_FOLDER "/column.ply";
static const char *plain = PACKAGE_EXAMPLES_DIR EVAS_CONVEX_HULL_FOLDER "/plain.ply";
static const char *plain_ch = PACKAGE_EXAMPLES_DIR EVAS_CONVEX_HULL_FOLDER "/plain_blender_ch.ply";
static const char *sphere_ch = PACKAGE_EXAMPLES_DIR EVAS_CONVEX_HULL_FOLDER "/sphere_blender_ch.ply";
static const char *torus_ch = PACKAGE_EXAMPLES_DIR EVAS_CONVEX_HULL_FOLDER "/torus_blender_ch.ply";
static const char *cube_ch = PACKAGE_EXAMPLES_DIR EVAS_CONVEX_HULL_FOLDER "/cube_blender_ch.ply";
static const char *column_ch = PACKAGE_EXAMPLES_DIR EVAS_CONVEX_HULL_FOLDER "/column_blender_ch.ply";
static const char *home_ch = PACKAGE_EXAMPLES_DIR EVAS_CONVEX_HULL_FOLDER "/home_blender_ch.obj";
static const char *sonic_ch = PACKAGE_EXAMPLES_DIR EVAS_CONVEX_HULL_FOLDER "/sonic_blender_ch.ply";
static const char *eagle_ch = PACKAGE_EXAMPLES_DIR EVAS_CONVEX_HULL_FOLDER "/eagle_blender_ch.ply";
static const char *plain_test = PACKAGE_EXAMPLES_DIR EVAS_CONVEX_HULL_FOLDER "/plain_blender_ch_test.ply";
static const char *sphere_test = PACKAGE_EXAMPLES_DIR EVAS_CONVEX_HULL_FOLDER "/sphere_blender_ch_test.ply";
static const char *torus_test = PACKAGE_EXAMPLES_DIR EVAS_CONVEX_HULL_FOLDER "/torus_blender_ch_test.ply";
static const char *cube_test = PACKAGE_EXAMPLES_DIR EVAS_CONVEX_HULL_FOLDER "/cube_blender_ch_test.ply";
static const char *column_test = PACKAGE_EXAMPLES_DIR EVAS_CONVEX_HULL_FOLDER "/column_blender_ch_test.ply";
static const char *home_test = PACKAGE_EXAMPLES_DIR EVAS_CONVEX_HULL_FOLDER "/home_blender_ch_test.ply";
static const char *sonic_test = PACKAGE_EXAMPLES_DIR EVAS_CONVEX_HULL_FOLDER "/sonic_blender_ch_test.ply";
static const char *eagle_test = PACKAGE_EXAMPLES_DIR EVAS_CONVEX_HULL_FOLDER "/eagle_blender_ch_test.ply";
static Ecore_Evas *ecore_evas = NULL;
static Evas *evas = NULL;
static Eo *background = NULL;
static Eo *image = NULL;
static int next_model = 0;
static void
_print_result(Evas_Canvas3D_Mesh *mesh, Evas_Canvas3D_Mesh *convex_mesh)
{
int v_count = 0;
eo_do(mesh, v_count = evas_canvas3d_mesh_vertex_count_get());
printf("Vertex count is %d for convex hull\n",
v_count);
eo_do(convex_mesh, v_count = evas_canvas3d_mesh_vertex_count_get());
printf("Vertex count is %d for blender convex hull\n\n",
v_count);
return;
}
static void
_on_delete(Ecore_Evas *ee EINA_UNUSED)
{
ecore_main_loop_quit();
}
static void
_on_canvas_resize(Ecore_Evas *ee)
{
int w, h;
ecore_evas_geometry_get(ee, NULL, NULL, &w, &h);
eo_do(background, efl_gfx_size_set(w, h));
eo_do(image, efl_gfx_size_set(w, h));
}
static Eina_Bool
_animate_scene(void *data)
{
static float angle = 0.0f;
Scene_Data *scene = (Scene_Data *)data;
angle += 0.5;
if (angle >= 360.0)
angle = 0.0;
eo_do(scene->mesh_node,
evas_canvas3d_node_orientation_angle_axis_set(angle, 1.0, 1.0, 1.0));
eo_do(scene->mesh_node_convex_hull,
evas_canvas3d_node_orientation_angle_axis_set(angle, 1.0, 1.0, 1.0));
eo_do(scene->mesh_node_blender,
evas_canvas3d_node_orientation_angle_axis_set(angle, 1.0, 1.0, 1.0));
return EINA_TRUE;
}
static void
_key_down(void *data,
Evas *e EINA_UNUSED,
Evas_Object *eo EINA_UNUSED,
void *event_info)
{
const Eina_List *list = NULL;
Eo *mesh = NULL;
Evas_Event_Key_Down *ev = event_info;
Scene_Data *scene = (Scene_Data *)data;
if (!strcmp(ev->key, "Right"))
next_model++;
else if (!strcmp(ev->key, "Left"))
next_model--;
if (next_model == -1)
next_model = TESTS_COUNT - 1;
else if (next_model == TESTS_COUNT)
next_model = 0;
switch (next_model)
{
SWITCH_MESH(0, sphere, SCALE_SPHERE)
SWITCH_MESH(1, torus, SCALE_TORUS)
SWITCH_MESH(2, cube, 1.0)
SWITCH_MESH(3, plain, 1.0)
SWITCH_MESH(4, column, 1.0)
SWITCH_MESH(5, home, SCALE_HOME)
SWITCH_MESH(6, sonic, SCALE_SONIC)
SWITCH_MESH(7, eagle, SCALE_EAGLE)
default:
break;
}
}
static void
_camera_setup(Scene_Data *data)
{
data->camera = eo_add(EVAS_CANVAS3D_CAMERA_CLASS, evas);
eo_do(data->camera,
evas_canvas3d_camera_projection_perspective_set(60.0, 1.0, 2.0, 50.0));
data->camera_node =
eo_add(EVAS_CANVAS3D_NODE_CLASS, evas,
evas_canvas3d_node_constructor(EVAS_CANVAS3D_NODE_TYPE_CAMERA));
eo_do(data->camera_node,
evas_canvas3d_node_camera_set(data->camera),
evas_canvas3d_node_position_set(0.0, 0.0, 10.0),
evas_canvas3d_node_look_at_set(EVAS_CANVAS3D_SPACE_PARENT, 0.0, 0.0, 0.0,
EVAS_CANVAS3D_SPACE_PARENT, 0.0, 1.0, 0.0));
eo_do(data->root_node, evas_canvas3d_node_member_add(data->camera_node));
}
static void
_light_setup(Scene_Data *data)
{
data->light = eo_add(EVAS_CANVAS3D_LIGHT_CLASS, evas);
eo_do(data->light,
evas_canvas3d_light_ambient_set(0.2, 0.2, 0.2, 1.0),
evas_canvas3d_light_diffuse_set(1.0, 1.0, 1.0, 1.0),
evas_canvas3d_light_specular_set(1.0, 1.0, 1.0, 1.0));
data->light_node =
eo_add(EVAS_CANVAS3D_NODE_CLASS, evas,
evas_canvas3d_node_constructor(EVAS_CANVAS3D_NODE_TYPE_LIGHT));
eo_do(data->light_node,
evas_canvas3d_node_light_set(data->light),
evas_canvas3d_node_position_set(0.0, 0.0, 10.0),
evas_canvas3d_node_look_at_set(EVAS_CANVAS3D_SPACE_PARENT, 0.0, 0.0, 0.0,
EVAS_CANVAS3D_SPACE_PARENT, 0.0, 1.0, 0.0));
eo_do(data->root_node, evas_canvas3d_node_member_add(data->light_node));
}
static void
_mesh_setup(Scene_Data *data)
{
Eina_Inarray *vert, *ind;
float *vertex;
unsigned short int *index;
int i = 0;
Eo *primitive = NULL;
/* Setup material. */
data->material = eo_add(EVAS_CANVAS3D_MATERIAL_CLASS, evas);
eo_do(data->material,
evas_canvas3d_material_enable_set(EVAS_CANVAS3D_MATERIAL_ATTRIB_AMBIENT, EINA_TRUE),
evas_canvas3d_material_enable_set(EVAS_CANVAS3D_MATERIAL_ATTRIB_DIFFUSE, EINA_TRUE),
evas_canvas3d_material_enable_set(EVAS_CANVAS3D_MATERIAL_ATTRIB_SPECULAR, EINA_TRUE),
evas_canvas3d_material_color_set(EVAS_CANVAS3D_MATERIAL_ATTRIB_AMBIENT, 0.2, 0.2, 0.2, 1.0),
evas_canvas3d_material_color_set(EVAS_CANVAS3D_MATERIAL_ATTRIB_DIFFUSE, 0.8, 0.8, 0.8, 1.0),
evas_canvas3d_material_color_set(EVAS_CANVAS3D_MATERIAL_ATTRIB_SPECULAR, 1.0, 1.0, 1.0, 1.0),
evas_canvas3d_material_shininess_set(100.0));
/* Setup mesh sphere */
primitive = eo_add(EVAS_CANVAS3D_PRIMITIVE_CLASS, evas);
eo_do(primitive,
evas_canvas3d_primitive_form_set(EVAS_CANVAS3D_MESH_PRIMITIVE_SPHERE),
evas_canvas3d_primitive_precision_set(10));
data->mesh_sphere = eo_add(EVAS_CANVAS3D_MESH_CLASS, evas);
eo_do(data->mesh_sphere, evas_canvas3d_mesh_from_primitive_set(0, primitive));
eo_do(data->mesh_sphere,
evas_canvas3d_mesh_vertex_assembly_set(EVAS_CANVAS3D_VERTEX_ASSEMBLY_TRIANGLES),
evas_canvas3d_mesh_shade_mode_set(EVAS_CANVAS3D_SHADE_MODE_PHONG),
evas_canvas3d_mesh_frame_material_set(0, data->material));
/* Setup mesh torus */
data->mesh_torus = eo_add(EVAS_CANVAS3D_MESH_CLASS, evas);
eo_do(primitive,
evas_canvas3d_primitive_form_set(EVAS_CANVAS3D_MESH_PRIMITIVE_TORUS),
evas_canvas3d_primitive_precision_set(50));
eo_do(data->mesh_torus, evas_canvas3d_mesh_from_primitive_set(0, primitive));
eo_do(data->mesh_torus,
evas_canvas3d_mesh_vertex_assembly_set(EVAS_CANVAS3D_VERTEX_ASSEMBLY_TRIANGLES),
evas_canvas3d_mesh_shade_mode_set(EVAS_CANVAS3D_SHADE_MODE_PHONG),
evas_canvas3d_mesh_frame_material_set(0, data->material));
/* Setup mesh cube */
data->mesh_cube = eo_add(EVAS_CANVAS3D_MESH_CLASS, evas);
eo_do(primitive,
evas_canvas3d_primitive_form_set(EVAS_CANVAS3D_MESH_PRIMITIVE_CUBE),
evas_canvas3d_primitive_precision_set(50));
eo_do(data->mesh_cube, evas_canvas3d_mesh_from_primitive_set(0, primitive));
eo_do(data->mesh_cube,
evas_canvas3d_mesh_vertex_assembly_set(EVAS_CANVAS3D_VERTEX_ASSEMBLY_TRIANGLES),
evas_canvas3d_mesh_shade_mode_set(EVAS_CANVAS3D_SHADE_MODE_PHONG),
evas_canvas3d_mesh_frame_material_set(0, data->material));
MODEL_MESH_INIT(plain, plain, PHONG)
MODEL_MESH_INIT(column, column, PHONG)
MODEL_MESH_INIT(home, home, PHONG)
MODEL_MESH_INIT(sonic, sonic, PHONG)
MODEL_MESH_INIT(eagle, eagle, PHONG)
MODEL_MESH_INIT(blender_sphere, sphere_ch, PHONG)
MODEL_MESH_INIT(blender_torus, torus_ch, PHONG)
MODEL_MESH_INIT(blender_cube, cube_ch, PHONG)
MODEL_MESH_INIT(blender_plain, plain_ch, PHONG)
MODEL_MESH_INIT(blender_column, column_ch, PHONG)
MODEL_MESH_INIT(blender_home, home_ch, PHONG)
MODEL_MESH_INIT(blender_eagle, eagle_ch, PHONG)
MODEL_MESH_INIT(blender_sonic, sonic_ch, PHONG)
MODEL_MESH_INIT(blender_test_sphere, sphere_test, DIFFUSE)
MODEL_MESH_INIT(blender_test_torus, torus_test, DIFFUSE)
MODEL_MESH_INIT(blender_test_cube, cube_test, DIFFUSE)
MODEL_MESH_INIT(blender_test_plain, plain_test, DIFFUSE)
MODEL_MESH_INIT(blender_test_column, column_test, DIFFUSE)
MODEL_MESH_INIT(blender_test_home, home_test, DIFFUSE)
MODEL_MESH_INIT(blender_test_eagle, eagle_test, DIFFUSE)
MODEL_MESH_INIT(blender_test_sonic, sonic_test, DIFFUSE)
data->mesh_node =
eo_add(EVAS_CANVAS3D_NODE_CLASS, evas,
evas_canvas3d_node_constructor(EVAS_CANVAS3D_NODE_TYPE_MESH));
eo_do(data->root_node, evas_canvas3d_node_member_add(data->mesh_node));
eo_do(data->mesh_node,
evas_canvas3d_node_mesh_add(data->mesh_sphere),
evas_canvas3d_node_scale_set(SCALE_SPHERE, SCALE_SPHERE, SCALE_SPHERE),
evas_canvas3d_node_position_set(3.0, 0.0, 0.0));
CONVEX_HULL_MESH_INIT(sphere)
CONVEX_HULL_MESH_INIT(torus)
CONVEX_HULL_MESH_INIT(cube)
CONVEX_HULL_MESH_INIT(plain)
CONVEX_HULL_MESH_INIT(column)
CONVEX_HULL_MESH_INIT(home)
CONVEX_HULL_MESH_INIT(sonic)
CONVEX_HULL_MESH_INIT(eagle)
_print_result(data->mesh_sphere_ch, data->mesh_blender_test_sphere);
data->mesh_node_convex_hull =
eo_add(EVAS_CANVAS3D_NODE_CLASS, evas,
evas_canvas3d_node_constructor(EVAS_CANVAS3D_NODE_TYPE_MESH));
eo_do(data->root_node, evas_canvas3d_node_member_add(data->mesh_node_convex_hull));
eo_do(data->mesh_node_convex_hull,
evas_canvas3d_node_position_set(0.0, 0.0, 0.0),
evas_canvas3d_node_scale_set(SCALE_SPHERE, SCALE_SPHERE, SCALE_SPHERE),
evas_canvas3d_node_mesh_add(data->mesh_sphere_ch));
data->mesh_node_blender =
eo_add(EVAS_CANVAS3D_NODE_CLASS, evas,
evas_canvas3d_node_constructor(EVAS_CANVAS3D_NODE_TYPE_MESH));
eo_do(data->root_node, evas_canvas3d_node_member_add(data->mesh_node_blender));
eo_do(data->mesh_node_blender,
evas_canvas3d_node_position_set(-3.0, 0.0, 0.0),
evas_canvas3d_node_scale_set(SCALE_SPHERE, SCALE_SPHERE, SCALE_SPHERE),
evas_canvas3d_node_mesh_add(data->mesh_blender_sphere));
}
static void
_scene_setup(Scene_Data *data)
{
data->scene = eo_add(EVAS_CANVAS3D_SCENE_CLASS, evas);
eo_do(data->scene,
evas_canvas3d_scene_size_set(WIDTH, HEIGHT);
evas_canvas3d_scene_background_color_set(0.0, 0.0, 0.0, 0.0));
data->root_node =
eo_add(EVAS_CANVAS3D_NODE_CLASS, evas,
evas_canvas3d_node_constructor(EVAS_CANVAS3D_NODE_TYPE_NODE));
_camera_setup(data);
_light_setup(data);
_mesh_setup(data);
eo_do(data->scene,
evas_canvas3d_scene_root_node_set(data->root_node),
evas_canvas3d_scene_camera_node_set(data->camera_node));
}
int
main(void)
{
Ecore_Animator *anim;
Scene_Data data;
//Unless Evas 3D supports Software renderer, we set gl backened forcely.
setenv("ECORE_EVAS_ENGINE", "opengl_x11", 1);
int stride_pos;
if (!ecore_evas_init()) return 0;
printf("Loading 3d meshes. Press Left or Right to switch between models.\n");
ecore_evas = ecore_evas_new(NULL, 10, 10, WIDTH, HEIGHT, NULL);
if (!ecore_evas) return 0;
ecore_evas_callback_delete_request_set(ecore_evas, _on_delete);
ecore_evas_callback_resize_set(ecore_evas, _on_canvas_resize);
ecore_evas_show(ecore_evas);
evas = ecore_evas_get(ecore_evas);
_scene_setup(&data);
/* Add a background rectangle objects. */
background = eo_add(EVAS_RECTANGLE_CLASS, evas);
eo_do(background,
efl_gfx_color_set(0, 0, 0, 255),
efl_gfx_size_set(WIDTH, HEIGHT),
efl_gfx_visible_set(EINA_TRUE));
/* Add an image object for 3D scene rendering. */
image = evas_object_image_filled_add(evas);
eo_do(image,
efl_gfx_size_set(WIDTH, HEIGHT),
efl_gfx_visible_set(EINA_TRUE));
evas_object_show(image),
evas_object_focus_set(image, EINA_TRUE);
/* Set the image object as render target for 3D scene. */
eo_do(image, evas_obj_image_scene_set(data.scene));
evas_object_event_callback_add(image, EVAS_CALLBACK_KEY_DOWN, _key_down, &data);
/* Add animator. */
ecore_animator_frametime_set(0.008);
anim = ecore_animator_add(_animate_scene, &data);
/* Enter main loop. */
ecore_main_loop_begin();
ecore_animator_del(anim);
ecore_evas_free(ecore_evas);
ecore_evas_shutdown();
return 0;
}
|