summaryrefslogtreecommitdiff
path: root/src/examples/evas
diff options
context:
space:
mode:
Diffstat (limited to 'src/examples/evas')
-rw-r--r--src/examples/evas/README32
-rw-r--r--src/examples/evas/evas-3d-aabb.c237
-rw-r--r--src/examples/evas/evas-3d-blending.c312
-rw-r--r--src/examples/evas/evas-3d-colorpick.c415
-rw-r--r--src/examples/evas/evas-3d-cube-rotate.c285
-rw-r--r--src/examples/evas/evas-3d-cube.c262
-rw-r--r--src/examples/evas/evas-3d-cube2.c258
-rw-r--r--src/examples/evas/evas-3d-eet.c210
-rw-r--r--src/examples/evas/evas-3d-fog.c238
-rw-r--r--src/examples/evas/evas-3d-frustum.c446
-rw-r--r--src/examples/evas/evas-3d-hull.c465
-rw-r--r--src/examples/evas/evas-3d-md2.c176
-rw-r--r--src/examples/evas/evas-3d-mmap-set.c260
-rw-r--r--src/examples/evas/evas-3d-obj.c239
-rw-r--r--src/examples/evas/evas-3d-parallax-occlusion.c264
-rw-r--r--src/examples/evas/evas-3d-pick.c189
-rw-r--r--src/examples/evas/evas-3d-ply.c235
-rw-r--r--src/examples/evas/evas-3d-proxy.c262
-rw-r--r--src/examples/evas/evas-3d-shadows.c689
-rw-r--r--src/examples/evas/evas-3d-static-lod.c280
-rw-r--r--src/examples/evas/meson.build21
-rw-r--r--src/examples/evas/resources/models/NoNormal_NoUVs_Colors.ply67
-rw-r--r--src/examples/evas/resources/models/NoNormal_NoUVs_NoColors.ply60
-rw-r--r--src/examples/evas/resources/models/NoNormal_UVs_Colors.ply143
-rw-r--r--src/examples/evas/resources/models/NoNormal_UVs_NoColors.ply140
-rw-r--r--src/examples/evas/resources/models/Normal_NoUVs_Colors.ply144
-rw-r--r--src/examples/evas/resources/models/Normal_NoUVs_NoColors.ply141
-rw-r--r--src/examples/evas/resources/models/Normal_UVs_Colors.ply146
-rw-r--r--src/examples/evas/resources/models/Normal_UVs_NoColors.ply143
-rw-r--r--src/examples/evas/resources/models/convex_hull/column.ply521
-rw-r--r--src/examples/evas/resources/models/convex_hull/column_blender_ch.ply295
-rw-r--r--src/examples/evas/resources/models/convex_hull/column_blender_ch_test.ply164
-rw-r--r--src/examples/evas/resources/models/convex_hull/cube_blender_ch.ply43
-rw-r--r--src/examples/evas/resources/models/convex_hull/cube_blender_ch_test.ply24
-rw-r--r--src/examples/evas/resources/models/convex_hull/eagle_blender_ch.ply306
-rw-r--r--src/examples/evas/resources/models/convex_hull/eagle_blender_ch_test.ply124
-rw-r--r--src/examples/evas/resources/models/convex_hull/home_blender_ch.obj40
-rw-r--r--src/examples/evas/resources/models/convex_hull/home_blender_ch_test.ply35
-rw-r--r--src/examples/evas/resources/models/convex_hull/plain.ply846
-rw-r--r--src/examples/evas/resources/models/convex_hull/plain_blender_ch.ply18
-rw-r--r--src/examples/evas/resources/models/convex_hull/plain_blender_ch_test.ply15
-rw-r--r--src/examples/evas/resources/models/convex_hull/sonic_blender_ch.ply659
-rw-r--r--src/examples/evas/resources/models/convex_hull/sonic_blender_ch_test.ply260
-rw-r--r--src/examples/evas/resources/models/convex_hull/sphere_blender_ch.ply469
-rw-r--r--src/examples/evas/resources/models/convex_hull/sphere_blender_ch_test.ply194
-rw-r--r--src/examples/evas/resources/models/convex_hull/torus_blender_ch.ply12313
-rw-r--r--src/examples/evas/resources/models/convex_hull/torus_blender_ch_test.ply2556
-rw-r--r--src/examples/evas/resources/models/lod/iso_sphere0.obj3208
-rw-r--r--src/examples/evas/resources/models/lod/iso_sphere1.obj1608
-rw-r--r--src/examples/evas/resources/models/lod/iso_sphere2.obj808
-rw-r--r--src/examples/evas/resources/models/mesh_for_mmap.eetbin19495 -> 0 bytes
-rw-r--r--src/examples/evas/resources/models/mesh_for_mmap.md2bin3400 -> 0 bytes
-rw-r--r--src/examples/evas/resources/models/mesh_for_mmap.obj639
-rw-r--r--src/examples/evas/resources/models/mesh_for_mmap.ply401
-rw-r--r--src/examples/evas/resources/models/sonic.md2bin660576 -> 0 bytes
-rw-r--r--src/examples/evas/resources/models/sweet_home.obj107
-rw-r--r--src/examples/evas/resources/models/sweet_home_only_vertex_coords.obj40
-rw-r--r--src/examples/evas/resources/models/sweet_home_without_normals.obj96
-rw-r--r--src/examples/evas/resources/models/sweet_home_without_tex_coords.obj55
-rw-r--r--src/examples/evas/shooter/assets/images/brick-stone.jpgbin30416 -> 0 bytes
-rw-r--r--src/examples/evas/shooter/assets/images/brick-stone_n.jpgbin23490 -> 0 bytes
-rw-r--r--src/examples/evas/shooter/assets/images/bricks.jpgbin90039 -> 0 bytes
-rw-r--r--src/examples/evas/shooter/assets/images/bricks_n.jpgbin34584 -> 0 bytes
-rw-r--r--src/examples/evas/shooter/assets/images/eagle.pngbin35011 -> 0 bytes
-rw-r--r--src/examples/evas/shooter/assets/images/gazebo.pngbin113938 -> 0 bytes
-rw-r--r--src/examples/evas/shooter/assets/images/gazebo_b_n.pngbin148096 -> 0 bytes
-rw-r--r--src/examples/evas/shooter/assets/images/gazebo_t.pngbin119501 -> 0 bytes
-rw-r--r--src/examples/evas/shooter/assets/images/gazebo_t_n.pngbin128640 -> 0 bytes
-rw-r--r--src/examples/evas/shooter/assets/images/gazebo_t_t.pngbin121842 -> 0 bytes
-rw-r--r--src/examples/evas/shooter/assets/images/snake.pngbin76100 -> 0 bytes
-rw-r--r--src/examples/evas/shooter/assets/images/snake_n.pngbin79061 -> 0 bytes
-rw-r--r--src/examples/evas/shooter/assets/images/soldier.pngbin113272 -> 0 bytes
-rw-r--r--src/examples/evas/shooter/assets/images/warrior.pngbin118574 -> 0 bytes
-rw-r--r--src/examples/evas/shooter/assets/models/eagle.md2bin196728 -> 0 bytes
-rw-r--r--src/examples/evas/shooter/assets/models/gazebo_b.md2bin153476 -> 0 bytes
-rw-r--r--src/examples/evas/shooter/assets/models/gazebo_t.md2bin154756 -> 0 bytes
-rw-r--r--src/examples/evas/shooter/assets/models/snake.md2bin270584 -> 0 bytes
-rw-r--r--src/examples/evas/shooter/assets/models/soldier.md2bin591280 -> 0 bytes
-rw-r--r--src/examples/evas/shooter/assets/models/soldier_jump.md2bin518676 -> 0 bytes
-rw-r--r--src/examples/evas/shooter/assets/models/tommy.ply3558
-rw-r--r--src/examples/evas/shooter/assets/models/warrior.md2bin130276 -> 0 bytes
-rw-r--r--src/examples/evas/shooter/evas-3d-shooter-header.c359
-rw-r--r--src/examples/evas/shooter/evas-3d-shooter-header.h196
-rw-r--r--src/examples/evas/shooter/evas-3d-shooter-macros.h242
-rw-r--r--src/examples/evas/shooter/evas-3d-shooter.c1186
-rw-r--r--src/examples/evas/shooter/meson.build5
86 files changed, 0 insertions, 38149 deletions
diff --git a/src/examples/evas/README b/src/examples/evas/README
index 6933808678..87aa4fe38a 100644
--- a/src/examples/evas/README
+++ b/src/examples/evas/README
@@ -71,35 +71,3 @@ evas-map-aa-eo.c - Eo API
71evas-vg-simple.c - Introduction to vector graphics 71evas-vg-simple.c - Introduction to vector graphics
72evas-vg-batman.c - Animated vector graphics 72evas-vg-batman.c - Animated vector graphics
73evas-vg-json.c - Play Lottie files 73evas-vg-json.c - Play Lottie files
74
75
76== 3D Graphics - Basics ==
77
78 evas-gl.c - Introduction to GL in Evas
79 evas-3d-cube.c - Introduction to meshes for 3D objects
80 evas-3d-cube-rotate.c - Introduction to events for 3D objects
81 evas-3d-proxy.c - Introduction to textures for 3D objects
82 evas-3d-shadows.c - Introduction to lighting and anti-aliasing
83
84
85== 3D Graphics - File formats ==
86
87 evas-3d-eet.c - eet file format
88 evas-3d-md2.c - md2 file format
89 evas-3d-obj.c - obj file format
90 evas-3d-ply.c - ply file format
91 evas-3d-mmap-set.c - Import meshes from various file formats
92
93
94== 3D Graphics - Advanced Topics ==
95
96 evas-3d-aabb.c - Axis aligned bounding boxes
97 evas-3d-blending.c - Blending modes
98 evas-3d-pick.c - Picking nodes and meshes by screen coordinates
99 evas-3d-colorpick.c - Picking nodes and meshes by color
100 evas-3d-cube2.c - Animation
101 evas-3d-fog.c - Fog effect
102 evas-3d-static-lod.c - Static LOD techniques
103 evas-3d-frustum.c - Frustrum culling
104 evas-3d-hull.c - Convex hull models and comparison with Blender
105 evas-3d-parallax-occlusion.c - Parallax occlusion shading and texture animation
diff --git a/src/examples/evas/evas-3d-aabb.c b/src/examples/evas/evas-3d-aabb.c
deleted file mode 100644
index 99e3b98cce..0000000000
--- a/src/examples/evas/evas-3d-aabb.c
+++ /dev/null
@@ -1,237 +0,0 @@
1/**
2 * Example of getting and drawing an axis-aligned bounding box in Evas-3D.
3 *
4 * @see _redraw_aabb();
5 * Rotate axes (keys 1-4) for model and bounding box view from another angle.
6 *
7 * @verbatim
8 * gcc -o evas-3d-aabb evas-3d-aabb.c `pkg-config --libs --cflags efl evas ecore ecore-evas eo` -lm
9 * @endverbatim
10 */
11
12#ifdef HAVE_CONFIG_H
13#include "config.h"
14#else
15#define PACKAGE_EXAMPLES_DIR "."
16#define EFL_BETA_API_SUPPORT
17#endif
18
19#include <Eo.h>
20#include <Evas.h>
21#include <Ecore.h>
22#include <Ecore_Evas.h>
23#include "evas-common.h"
24
25#define WIDTH 400
26#define HEIGHT 400
27
28static const char *model_path = PACKAGE_EXAMPLES_DIR EVAS_MODEL_FOLDER "/sonic.md2";
29static const char *image_path = PACKAGE_EXAMPLES_DIR EVAS_IMAGE_FOLDER "/sonic.png";
30
31Ecore_Evas *ecore_evas = NULL;
32Evas *evas = NULL;
33Eo *background = NULL;
34Eo *image = NULL;
35Eo *cube = NULL;
36Eo *scene = NULL;
37Eo *root_node = NULL;
38Eo *camera_node = NULL;
39Eo *light_node = NULL;
40Eo *camera = NULL;
41Eo *mesh_node = NULL;
42Eo *mesh_box_node = NULL;
43Eo *mesh = NULL;
44Eo *mesh_box = NULL;
45Eo *material_box = NULL;
46Eo *material = NULL;
47Eo *texture = NULL;
48Eo *light = NULL;
49
50static Eina_Bool
51_redraw_aabb();
52
53static Eina_Bool
54_animate_scene(void *data)
55{
56 static int frame = 0;
57
58 evas_canvas3d_node_mesh_frame_set((Evas_Canvas3D_Node *)data, mesh, frame);
59
60 _redraw_aabb();
61
62 frame += 32;
63
64 if (frame > 256 * 50) frame = 0;
65
66 return EINA_TRUE;
67}
68
69static void
70_on_delete(Ecore_Evas *ee EINA_UNUSED)
71{
72 ecore_main_loop_quit();
73}
74
75static void
76_on_key_down(void *data, Evas *e EINA_UNUSED, Evas_Object *eo EINA_UNUSED, void *event_info)
77{
78 Evas_Event_Key_Down *ev = event_info;
79 Evas_Canvas3D_Node *node = (Evas_Canvas3D_Node *)data;
80
81 switch(atoi(ev->key))
82 {
83 case 1:
84 {
85 evas_canvas3d_node_orientation_angle_axis_set(node, 90, 1.0, 0.0, 0.0);
86 break;
87 }
88 case 2:
89 {
90 evas_canvas3d_node_orientation_angle_axis_set(node, 90, 0.0, 1.0, 0.0);
91 break;
92 }
93 case 3:
94 {
95 evas_canvas3d_node_orientation_angle_axis_set(node, 90, 0.0, 0.0, 1.0);
96 break;
97 }
98 case 4:
99 {
100 evas_canvas3d_node_orientation_angle_axis_set(node, 90, 1.0, 1.0, 0.0);
101 break;
102 }
103 }
104}
105
106static void
107_on_canvas_resize(Ecore_Evas *ee)
108{
109 int w, h;
110
111 ecore_evas_geometry_get(ee, NULL, NULL, &w, &h);
112 efl_gfx_entity_size_set(background, EINA_SIZE2D(w, h));
113 efl_gfx_entity_size_set(image, EINA_SIZE2D(w, h));
114}
115
116static Eina_Bool
117_redraw_aabb()
118{
119 Evas_Real x0, y0, z0, x1, y1, z1;
120
121 evas_canvas3d_node_bounding_box_get(mesh_node, &x0, &y0, &z0, &x1, &y1, &z1);
122 evas_canvas3d_node_position_set(mesh_box_node, (x0 + x1)/2, (y0 + y1)/2, (z0 + z1)/2);
123 evas_canvas3d_node_scale_set(mesh_box_node, x1 - x0, y1 - y0, z1 - z0);
124
125 return EINA_TRUE;
126}
127
128int
129main(void)
130{
131 if (!ecore_evas_init()) return 0;
132
133 ecore_evas = ecore_evas_new("opengl_x11", 10, 10, WIDTH, HEIGHT, NULL);
134
135 if (!ecore_evas) return 0;
136
137 ecore_evas_callback_delete_request_set(ecore_evas, _on_delete);
138 ecore_evas_callback_resize_set(ecore_evas, _on_canvas_resize);
139 ecore_evas_show(ecore_evas);
140
141 evas = ecore_evas_get(ecore_evas);
142
143 scene = efl_add(EVAS_CANVAS3D_SCENE_CLASS, evas);
144
145 root_node = efl_add(EVAS_CANVAS3D_NODE_CLASS, evas, evas_canvas3d_node_type_set(efl_added, EVAS_CANVAS3D_NODE_TYPE_NODE));
146
147 camera = efl_add(EVAS_CANVAS3D_CAMERA_CLASS, evas);
148 evas_canvas3d_camera_projection_perspective_set(camera, 60.0, 1.0, 1.0, 500.0);
149
150 camera_node =
151 efl_add(EVAS_CANVAS3D_NODE_CLASS, evas, evas_canvas3d_node_type_set(efl_added, EVAS_CANVAS3D_NODE_TYPE_CAMERA));
152 evas_canvas3d_node_camera_set(camera_node, camera);
153 evas_canvas3d_node_member_add(root_node, camera_node);
154 evas_canvas3d_node_position_set(camera_node, 100.0, 50.0, 20.0);
155 evas_canvas3d_node_look_at_set(camera_node, EVAS_CANVAS3D_SPACE_PARENT, 0.0, 0.0, 20.0, EVAS_CANVAS3D_SPACE_PARENT, 0.0, 0.0, 1.0);
156 light = efl_add(EVAS_CANVAS3D_LIGHT_CLASS, evas);
157 evas_canvas3d_light_ambient_set(light, 1.0, 1.0, 1.0, 1.0);
158 evas_canvas3d_light_diffuse_set(light, 1.0, 1.0, 1.0, 1.0);
159 evas_canvas3d_light_specular_set(light, 1.0, 1.0, 1.0, 1.0);
160 evas_canvas3d_light_directional_set(light, EINA_TRUE);
161
162 light_node =
163 efl_add(EVAS_CANVAS3D_NODE_CLASS, evas, evas_canvas3d_node_type_set(efl_added, EVAS_CANVAS3D_NODE_TYPE_LIGHT));
164 evas_canvas3d_node_light_set(light_node, light);
165 evas_canvas3d_node_position_set(light_node, 1000.0, 0.0, 1000.0);
166 evas_canvas3d_node_look_at_set(light_node, EVAS_CANVAS3D_SPACE_PARENT, 0.0, 0.0, 0.0, EVAS_CANVAS3D_SPACE_PARENT, 0.0, 1.0, 0.0);
167 evas_canvas3d_node_member_add(root_node, light_node);
168
169 mesh = efl_add(EVAS_CANVAS3D_MESH_CLASS, evas);
170 material = efl_add(EVAS_CANVAS3D_MATERIAL_CLASS, evas);
171
172 efl_file_simple_load(mesh, model_path, NULL);
173 evas_canvas3d_mesh_frame_material_set(mesh, 0, material);
174 evas_canvas3d_mesh_shader_mode_set(mesh, EVAS_CANVAS3D_SHADER_MODE_PHONG);
175
176 texture = efl_add(EVAS_CANVAS3D_TEXTURE_CLASS, evas);
177 efl_file_simple_load(texture, image_path, NULL);
178 evas_canvas3d_texture_filter_set(texture, EVAS_CANVAS3D_TEXTURE_FILTER_NEAREST, EVAS_CANVAS3D_TEXTURE_FILTER_NEAREST);
179 evas_canvas3d_texture_wrap_set(texture, EVAS_CANVAS3D_WRAP_MODE_REPEAT, EVAS_CANVAS3D_WRAP_MODE_REPEAT);
180 evas_canvas3d_material_texture_set(material, EVAS_CANVAS3D_MATERIAL_ATTRIB_DIFFUSE, texture);
181 evas_canvas3d_material_enable_set(material, EVAS_CANVAS3D_MATERIAL_ATTRIB_AMBIENT, EINA_TRUE);
182 evas_canvas3d_material_enable_set(material, EVAS_CANVAS3D_MATERIAL_ATTRIB_DIFFUSE, EINA_TRUE);
183 evas_canvas3d_material_enable_set(material, EVAS_CANVAS3D_MATERIAL_ATTRIB_SPECULAR, EINA_TRUE);
184 evas_canvas3d_material_enable_set(material, EVAS_CANVAS3D_MATERIAL_ATTRIB_NORMAL, EINA_TRUE);
185 evas_canvas3d_material_color_set(material, EVAS_CANVAS3D_MATERIAL_ATTRIB_AMBIENT, 0.01, 0.01, 0.01, 1.0);
186 evas_canvas3d_material_color_set(material, EVAS_CANVAS3D_MATERIAL_ATTRIB_DIFFUSE, 1.0, 1.0, 1.0, 1.0);
187 evas_canvas3d_material_color_set(material, EVAS_CANVAS3D_MATERIAL_ATTRIB_SPECULAR, 1.0, 1.0, 1.0, 1.0);
188 evas_canvas3d_material_shininess_set(material, 50.0);
189
190 mesh_node = efl_add(EVAS_CANVAS3D_NODE_CLASS, evas, evas_canvas3d_node_type_set(efl_added, EVAS_CANVAS3D_NODE_TYPE_MESH));
191 mesh_box_node = efl_add(EVAS_CANVAS3D_NODE_CLASS, evas, evas_canvas3d_node_type_set(efl_added, EVAS_CANVAS3D_NODE_TYPE_MESH));
192
193 material_box = efl_add(EVAS_CANVAS3D_MATERIAL_CLASS, evas);
194 evas_canvas3d_material_enable_set(material_box, EVAS_CANVAS3D_MATERIAL_ATTRIB_DIFFUSE, EINA_TRUE);
195
196 cube = efl_add(EVAS_CANVAS3D_PRIMITIVE_CLASS, evas);
197 evas_canvas3d_primitive_form_set(cube, EVAS_CANVAS3D_MESH_PRIMITIVE_CUBE);
198
199 mesh_box = efl_add(EVAS_CANVAS3D_MESH_CLASS, evas);
200 evas_canvas3d_mesh_from_primitive_set(mesh_box, 0, cube);
201 evas_canvas3d_mesh_vertex_assembly_set(mesh_box, EVAS_CANVAS3D_VERTEX_ASSEMBLY_LINES);
202 evas_canvas3d_mesh_shader_mode_set(mesh_box, EVAS_CANVAS3D_SHADER_MODE_VERTEX_COLOR);
203 evas_canvas3d_mesh_frame_material_set(mesh_box, 0, material_box);
204 _redraw_aabb();
205
206 evas_canvas3d_node_member_add(root_node, mesh_box_node);
207 evas_canvas3d_node_mesh_add(mesh_box_node, mesh_box);
208
209 evas_canvas3d_node_member_add(root_node, mesh_node);
210 evas_canvas3d_node_mesh_add(mesh_node, mesh);
211
212 evas_canvas3d_scene_root_node_set(scene, root_node);
213 evas_canvas3d_scene_camera_node_set(scene, camera_node);
214 evas_canvas3d_scene_size_set(scene, WIDTH, HEIGHT);
215
216 background = efl_add(EFL_CANVAS_RECTANGLE_CLASS, evas);
217 efl_gfx_color_set(background, 0, 0, 0, 255);
218 efl_gfx_entity_size_set(background, EINA_SIZE2D(WIDTH, HEIGHT));
219 efl_gfx_entity_visible_set(background, EINA_TRUE);
220
221 image = efl_add(EFL_CANVAS_SCENE3D_CLASS, evas);
222 efl_gfx_entity_size_set(image, EINA_SIZE2D(WIDTH, HEIGHT));
223 efl_gfx_entity_visible_set(image, EINA_TRUE);
224 evas_object_focus_set(image, EINA_TRUE);
225 efl_canvas_scene3d_set(image, scene);
226
227 evas_object_event_callback_add(image, EVAS_CALLBACK_KEY_DOWN, _on_key_down, mesh_node);
228
229 ecore_timer_add(0.01, _animate_scene, mesh_node);
230
231 ecore_main_loop_begin();
232
233 ecore_evas_free(ecore_evas);
234 ecore_evas_shutdown();
235
236 return 0;
237}
diff --git a/src/examples/evas/evas-3d-blending.c b/src/examples/evas/evas-3d-blending.c
deleted file mode 100644
index 066961af72..0000000000
--- a/src/examples/evas/evas-3d-blending.c
+++ /dev/null
@@ -1,312 +0,0 @@
1/**
2 * Example of different blending modes in Evas-3D.
3 *
4 * Press "Up" or "Down" key for change source blending factor.
5 * Press "Left" or "Right" for change destination blending factors.
6 * For more details see https://www.opengl.org/sdk/docs/man2/xhtml/glBlendFunc.xml
7 *
8 * @verbatim
9 * gcc -o evas-3d-blending evas-3d-blending.c `pkg-config --libs --cflags efl evas ecore ecore-evas eo` -lm
10 * @endverbatim
11 */
12
13#ifdef HAVE_CONFIG_H
14#include "config.h"
15#else
16#define EFL_BETA_API_SUPPORT
17#endif
18
19#include <Eo.h>
20#include <Evas.h>
21#include <Ecore.h>
22#include <Ecore_Evas.h>
23
24#define WIDTH 1024
25#define HEIGHT 1024
26
27static const char *blend_func_names[] =
28{
29 /**< The scale factors for color components is (0, 0, 0, 0)*/
30 "EVAS_CANVAS3D_BLEND_FUNC_ZERO",
31 /**< The scale factors for color components is (1, 1, 1, 1)*/
32 "EVAS_CANVAS3D_BLEND_FUNC_ONE",
33 /**< The scale factors for color components is (Rs/kR, Gs/kG, Bs/kB, As/kA)*/
34 "EVAS_CANVAS3D_BLEND_FUNC_SRC_COLOR",
35 /**< The scale factors for color components is (1, 1, 1, 1) - (Rs/kR, Gs/kG, Bs/kB, As/kA)*/
36 "EVAS_CANVAS3D_BLEND_FUNC_ONE_MINUS_SRC_COLOR",
37 /**< The scale factors for color components is (Rd/kR, Gd/kG, Bd/kB, Ad/kA)*/
38 "EVAS_CANVAS3D_BLEND_FUNC_DST_COLOR",
39 /**< The scale factors for color components is (1, 1, 1, 1) - (Rd/kR, Gd/kG, Bd/kB, Ad/kA)*/
40 "EVAS_CANVAS3D_BLEND_FUNC_ONE_MINUS_DST_COLOR",
41 /**< The scale factors for color components is (As/kA, As/kA, As/kA, As/kA)*/
42 "EVAS_CANVAS3D_BLEND_FUNC_SRC_ALPHA",
43 /**< The scale factors for color components is (1, 1, 1, 1) - (As/kA, As/kA, As/kA, As/kA)*/
44 "EVAS_CANVAS3D_BLEND_FUNC_ONE_MINUS_SRC_ALPHA",
45 /**< The scale factors for color components is (Ad/kA, Ad/kA, Ad/kA, Ad/kA)*/
46 "EVAS_CANVAS3D_BLEND_FUNC_DST_ALPHA",
47 /**< The scale factors for color components is (1, 1, 1, 1) - (Ad/kA, Ad/kA, Ad/kA, Ad/kA)*/
48 "EVAS_CANVAS3D_BLEND_FUNC_ONE_MINUS_DST_ALPHA",
49 /**< The scale factors for color components is (Rc, Gc, Bc, Ac)*/
50 "EVAS_CANVAS3D_BLEND_FUNC_CONSTANT_COLOR",
51 /**< The scale factors for color components is (1, 1, 1, 1) - (Rc, Gc, Bc, Ac)*/
52 "EVAS_CANVAS3D_BLEND_FUNC_ONE_MINUS_CONSTANT_COLOR",
53 /**< The scale factors for color components is (Ac, Ac, Ac, Ac)*/
54 "EVAS_CANVAS3D_BLEND_FUNC_CONSTANT_ALPHA",
55 /**< The scale factors for color components is (1, 1, 1, 1) - (Ac, Ac, Ac, Ac)*/
56 "EVAS_CANVAS3D_BLEND_FUNC_ONE_MINUS_CONSTANT_ALPHA",
57 /**< The scale factors for color components is (i, i, i, 1) where i = min(As, kA, Ad)/kA*/
58 "EVAS_CANVAS3D_BLEND_FUNC_SRC_ALPHA_SATURATE",
59};
60
61typedef struct _Scene_Data
62{
63 Eo *scene;
64 Eo *root_node;
65 Eo *camera_node;
66 Eo *light_node;
67 Eo *mesh_node;
68 Eo *mesh_node1;
69
70 Eo *camera;
71 Eo *light;
72 Eo *mesh;
73 Eo *mesh1;
74 Eo *sphere;
75 Eo *material;
76 Eo *material1;
77} Scene_Data;
78
79Evas *evas = NULL;
80Eo *background = NULL;
81Eo *image = NULL;
82
83int func1 = EVAS_CANVAS3D_BLEND_FUNC_SRC_ALPHA;
84int func2 = EVAS_CANVAS3D_BLEND_FUNC_ONE_MINUS_SRC_ALPHA;
85
86static void
87_on_key_down(void *data, Evas *e EINA_UNUSED, Evas_Object *eo EINA_UNUSED, void *event_info)
88{
89 Scene_Data *scene = (Scene_Data *)data;
90 Evas_Event_Key_Down *ev = event_info;
91
92 if (!strcmp("Up", ev->key))
93 func1++;
94 if (!strcmp("Down", ev->key))
95 func1--;
96 if (!strcmp("Left", ev->key))
97 func2++;
98 if (!strcmp("Right", ev->key))
99 func2--;
100
101 if(func1 < EVAS_CANVAS3D_BLEND_FUNC_ZERO)
102 func1 = EVAS_CANVAS3D_BLEND_FUNC_SRC_ALPHA_SATURATE;
103 if(func1 > EVAS_CANVAS3D_BLEND_FUNC_SRC_ALPHA_SATURATE)
104 func1 = EVAS_CANVAS3D_BLEND_FUNC_ZERO;
105
106 if(func2 < EVAS_CANVAS3D_BLEND_FUNC_ZERO)
107 func2 = EVAS_CANVAS3D_BLEND_FUNC_SRC_ALPHA_SATURATE;
108 if(func2 > EVAS_CANVAS3D_BLEND_FUNC_SRC_ALPHA_SATURATE)
109 func2 = EVAS_CANVAS3D_BLEND_FUNC_ZERO;
110 evas_canvas3d_mesh_blending_func_set(scene->mesh1, func1, func2);
111 printf("sfactor = %s, dfactor = %s\n", blend_func_names[func1], blend_func_names[func2]);
112}
113
114static void
115_on_delete(Ecore_Evas *ee EINA_UNUSED)
116{
117 ecore_main_loop_quit();
118}
119
120static void
121_on_canvas_resize(Ecore_Evas *ee)
122{
123 int w, h;
124
125 ecore_evas_geometry_get(ee, NULL, NULL, &w, &h);
126
127 evas_object_resize(background, w, h);
128 efl_gfx_entity_size_set(background, EINA_SIZE2D(w, h));
129 efl_gfx_entity_size_set(image, EINA_SIZE2D(w, h));
130}
131
132static Eina_Bool
133_animate_scene(void *data)
134{
135 static float angle = 0.0f;
136 Scene_Data *scene = (Scene_Data *)data;
137
138 angle += 0.02;
139
140 evas_canvas3d_node_position_set(scene->mesh_node, 3 * sin(angle), 0.0, 3 * cos(angle));
141
142 if (angle > 2 * M_PI) angle = 0;
143
144 return EINA_TRUE;
145}
146
147static void
148_camera_setup(Scene_Data *data)
149{
150 data->camera = efl_add(EVAS_CANVAS3D_CAMERA_CLASS, evas);
151
152 evas_canvas3d_camera_projection_perspective_set(data->camera, 60.0, 1.0, 2.0, 50.0);
153
154 data->camera_node =
155 efl_add(EVAS_CANVAS3D_NODE_CLASS, evas, evas_canvas3d_node_type_set(efl_added, EVAS_CANVAS3D_NODE_TYPE_CAMERA));
156
157 evas_canvas3d_node_camera_set(data->camera_node, data->camera);
158 evas_canvas3d_node_position_set(data->camera_node, 0.0, 0.0, 10.0);
159 evas_canvas3d_node_look_at_set(data->camera_node, EVAS_CANVAS3D_SPACE_PARENT, 0.0, 0.0, 0.0, EVAS_CANVAS3D_SPACE_PARENT, 0.0, 1.0, 0.0);
160
161 evas_canvas3d_node_member_add(data->root_node, data->camera_node);
162}
163
164static void
165_light_setup(Scene_Data *data)
166{
167 data->light = efl_add(EVAS_CANVAS3D_LIGHT_CLASS, evas);
168 evas_canvas3d_light_ambient_set(data->light, 0.2, 0.2, 0.2, 1.0);
169 evas_canvas3d_light_diffuse_set(data->light, 1.0, 1.0, 1.0, 1.0);
170 evas_canvas3d_light_specular_set(data->light, 1.0, 1.0, 1.0, 1.0);
171
172 data->light_node =
173 efl_add(EVAS_CANVAS3D_NODE_CLASS, evas, evas_canvas3d_node_type_set(efl_added, EVAS_CANVAS3D_NODE_TYPE_LIGHT));
174 evas_canvas3d_node_light_set(data->light_node, data->light);
175 evas_canvas3d_node_position_set(data->light_node, 0.0, 0.0, 10.0);
176 evas_canvas3d_node_look_at_set(data->light_node, EVAS_CANVAS3D_SPACE_PARENT, 0.0, 0.0, 0.0, EVAS_CANVAS3D_SPACE_PARENT, 0.0, 1.0, 0.0);
177 evas_canvas3d_node_member_add(data->root_node, data->light_node);
178}
179
180static void
181_set_ball(Eo *mesh, Eo *sphere, Evas_Canvas3D_Material *material)
182{
183 evas_canvas3d_mesh_from_primitive_set(mesh, 0, sphere);
184 evas_canvas3d_mesh_frame_material_set(mesh, 0, material);
185 evas_canvas3d_mesh_shader_mode_set(mesh, EVAS_CANVAS3D_SHADER_MODE_PHONG);
186}
187
188static void
189_mesh_setup(Scene_Data *data)
190{
191 data->material = efl_add(EVAS_CANVAS3D_MATERIAL_CLASS, evas);
192
193 evas_canvas3d_material_enable_set(data->material, EVAS_CANVAS3D_MATERIAL_ATTRIB_AMBIENT, EINA_TRUE);
194 evas_canvas3d_material_enable_set(data->material, EVAS_CANVAS3D_MATERIAL_ATTRIB_DIFFUSE, EINA_TRUE);
195 evas_canvas3d_material_enable_set(data->material, EVAS_CANVAS3D_MATERIAL_ATTRIB_SPECULAR, EINA_TRUE);
196 evas_canvas3d_material_color_set(data->material, EVAS_CANVAS3D_MATERIAL_ATTRIB_AMBIENT, 1.0, 0.2, 0.2, 0.2);
197 evas_canvas3d_material_color_set(data->material, EVAS_CANVAS3D_MATERIAL_ATTRIB_DIFFUSE, 1.0, 0.0, 0.0, 0.2);
198 evas_canvas3d_material_color_set(data->material, EVAS_CANVAS3D_MATERIAL_ATTRIB_SPECULAR, 1.0, 1.0, 1.0, 0.2);
199 evas_canvas3d_material_shininess_set(data->material, 100.0);
200
201 data->material1 = efl_add(EVAS_CANVAS3D_MATERIAL_CLASS, evas);
202
203 evas_canvas3d_material_enable_set(data->material1, EVAS_CANVAS3D_MATERIAL_ATTRIB_AMBIENT, EINA_TRUE);
204 evas_canvas3d_material_enable_set(data->material1, EVAS_CANVAS3D_MATERIAL_ATTRIB_DIFFUSE, EINA_TRUE);
205 evas_canvas3d_material_enable_set(data->material1, EVAS_CANVAS3D_MATERIAL_ATTRIB_SPECULAR, EINA_TRUE);
206 evas_canvas3d_material_color_set(data->material1, EVAS_CANVAS3D_MATERIAL_ATTRIB_AMBIENT, 0.0, 0.2, 0.2, 0.2);
207 evas_canvas3d_material_color_set(data->material1, EVAS_CANVAS3D_MATERIAL_ATTRIB_DIFFUSE, 0.0, 0.0, 1.0, 0.2);
208 evas_canvas3d_material_color_set(data->material1, EVAS_CANVAS3D_MATERIAL_ATTRIB_SPECULAR, 1.0, 1.0, 1.0, 0.2);
209 evas_canvas3d_material_shininess_set(data->material1, 100.0);
210
211 data->sphere = efl_add(EVAS_CANVAS3D_PRIMITIVE_CLASS, evas);
212 evas_canvas3d_primitive_form_set(data->sphere, EVAS_CANVAS3D_MESH_PRIMITIVE_SPHERE);
213 evas_canvas3d_primitive_precision_set(data->sphere, 50);
214
215 data->mesh = efl_add(EVAS_CANVAS3D_MESH_CLASS, evas);
216 data->mesh1 = efl_add(EVAS_CANVAS3D_MESH_CLASS, evas);
217
218 _set_ball(data->mesh, data->sphere, data->material);
219 _set_ball(data->mesh1, data->sphere, data->material1);
220
221 data->mesh_node =
222 efl_add(EVAS_CANVAS3D_NODE_CLASS, evas, evas_canvas3d_node_type_set(efl_added, EVAS_CANVAS3D_NODE_TYPE_MESH));
223
224 evas_canvas3d_node_member_add(data->root_node, data->mesh_node);
225 evas_canvas3d_node_mesh_add(data->mesh_node, data->mesh);
226
227 data->mesh_node1 =
228 efl_add(EVAS_CANVAS3D_NODE_CLASS, evas, evas_canvas3d_node_type_set(efl_added, EVAS_CANVAS3D_NODE_TYPE_MESH));
229
230 evas_canvas3d_node_member_add(data->root_node, data->mesh_node1);
231 evas_canvas3d_node_mesh_add(data->mesh_node1, data->mesh1);
232
233 evas_canvas3d_mesh_blending_enable_set(data->mesh1, EINA_TRUE);
234 evas_canvas3d_mesh_blending_func_set(data->mesh1, func1, func2);
235
236 evas_canvas3d_node_scale_set(data->mesh_node, 2.0, 2.0, 2.0);
237
238 evas_canvas3d_node_scale_set(data->mesh_node1, 5.0, 5.0, 5.0);
239}
240
241static void
242_scene_setup(Scene_Data *data)
243{
244 data->scene = efl_add(EVAS_CANVAS3D_SCENE_CLASS, evas);
245
246 evas_canvas3d_scene_size_set(data->scene, WIDTH, HEIGHT);
247 evas_canvas3d_scene_background_color_set(data->scene, 0.5, 0.5, 0.5, 1);
248
249 data->root_node =
250 efl_add(EVAS_CANVAS3D_NODE_CLASS, evas, evas_canvas3d_node_type_set(efl_added, EVAS_CANVAS3D_NODE_TYPE_NODE));
251
252 _camera_setup(data);
253 _light_setup(data);
254 _mesh_setup(data);
255
256 evas_canvas3d_scene_root_node_set(data->scene, data->root_node);
257 evas_canvas3d_scene_camera_node_set(data->scene, data->camera_node);
258}
259
260int
261main(void)
262{
263 Scene_Data data;
264 Ecore_Animator *anim;
265 Ecore_Evas *ecore_evas = NULL;
266
267 if (!ecore_evas_init()) return 0;
268
269 putenv("ECORE_EVAS_ENGINE=opengl_x11");
270 ecore_evas = ecore_evas_new(NULL, 0, 0, WIDTH, HEIGHT, NULL);
271
272 if (!ecore_evas) return 0;
273
274 ecore_evas_callback_delete_request_set(ecore_evas, _on_delete);
275 ecore_evas_callback_resize_set(ecore_evas, _on_canvas_resize);
276 ecore_evas_show(ecore_evas);
277
278 evas = ecore_evas_get(ecore_evas);
279
280 _scene_setup(&data);
281
282 /* Add a background rectangle object. */
283 background = evas_object_rectangle_add(evas);
284 evas_object_color_set(background, 0, 0, 0, 255);
285 evas_object_move(background, 0, 0);
286 evas_object_resize(background, WIDTH, HEIGHT);
287 evas_object_show(background);
288
289 /* Add an image object for 3D scene rendering. */
290 image = efl_add(EFL_CANVAS_SCENE3D_CLASS, evas);
291 evas_object_move(image, 0, 0);
292 evas_object_resize(image, WIDTH, HEIGHT);
293 evas_object_show(image);
294 evas_object_focus_set(image, EINA_TRUE);
295
296 /* Set the image object as render target for 3D scene. */
297 efl_canvas_scene3d_set(image, data.scene);
298
299 /* Add animation timer callback. */
300 ecore_animator_frametime_set(0.008);
301 anim = ecore_animator_add(_animate_scene, &data);
302
303 evas_object_event_callback_add(image, EVAS_CALLBACK_KEY_DOWN, _on_key_down, &data);
304 /* Enter main loop. */
305 ecore_main_loop_begin();
306
307 ecore_evas_free(ecore_evas);
308 ecore_evas_shutdown();
309 ecore_animator_del(anim);
310
311 return 0;
312}
diff --git a/src/examples/evas/evas-3d-colorpick.c b/src/examples/evas/evas-3d-colorpick.c
deleted file mode 100644
index 138ceb089a..0000000000
--- a/src/examples/evas/evas-3d-colorpick.c
+++ /dev/null
@@ -1,415 +0,0 @@
1/**
2 * Example of finding nodes by color or geometry in an Evas-3D scene.
3 *
4 * Enable color pick mode of meshes and scene objects.
5 * Click (left for color pick, right for geometry pick) on 3D object and see
6 * in terminal time response of the found node.
7 * Use key UP/DOWN for changing z coordinate of camera
8 * Use key LEFT/RIGHT for scale each node
9 * Use shortcut parameters of commandline: r - rows of objects, c - columns of objects,
10 * p - precision of the spheres, t - path for a texture.
11 *
12 * @verbatim
13 * gcc -o evas-3d-colorpick evas-3d-colorpick.c `pkg-config --libs --cflags evas ecore ecore-evas eo eina efl` -lm
14 * @endverbatim
15 */
16
17#ifdef HAVE_CONFIG_H
18#include "config.h"
19#else
20#define PACKAGE_EXAMPLES_DIR "."
21#define EFL_BETA_API_SUPPORT
22#endif
23
24#include <Eo.h>
25#include <Evas.h>
26#include <Ecore.h>
27#include <Ecore_Evas.h>
28#include <Ecore_Getopt.h>
29#include <math.h>
30#include "evas-common.h"
31
32#define WIDTH 800
33#define HEIGHT 600
34
35#define INIT_SCALE 7.5
36#define BIG_SCALE 10.0
37#define SMALL_SCALE 5.0
38#define SCALE_UNIT 0.5
39#define VEC_3(value) value, value, value
40
41static const char *image_path = PACKAGE_EXAMPLES_DIR EVAS_IMAGE_FOLDER "/wood.jpg";
42
43Ecore_Evas *ecore_evas = NULL;
44Evas *evas = NULL;
45Evas_Object *image = NULL, *bg = NULL;
46
47static const
48Ecore_Getopt optdesc = {
49 "",
50 NULL,
51 "0.0",
52 "",
53 "",
54 "Example mesh color pick mechanism",
55 0,
56 {
57 ECORE_GETOPT_STORE_INT('r', "row", "Rows of spheres"),
58 ECORE_GETOPT_STORE_INT('c', "column", "Columns of spheres"),
59 ECORE_GETOPT_STORE_INT('p', "precision", "Precision of spheres"),
60 ECORE_GETOPT_STORE_STR('t', "texture", "Name of texture"),
61 ECORE_GETOPT_HELP('h', "help"),
62 ECORE_GETOPT_SENTINEL
63 }
64};
65
66typedef struct _Object
67{
68 Eo *primitive;
69 Eo *node;
70 Eo *mesh;
71 Eo *material;
72 Eo *texture;
73
74 Evas_Real speed;
75 Ecore_Timer *animate;
76 Eina_Bool (*sphere_init)(void *sphere, const char *texture);
77 Eina_Bool (*sphere_animate)(void *data);
78
79} Test_object;
80
81typedef struct _Scene
82{
83 Eo *camera;
84 Eo *light;
85 Eo *scene;
86 Eo *root_node;
87 Eo *camera_node;
88 Eo *light_node;
89
90 int row;
91 int col;
92 int precision;
93
94 Eina_List *spheres;
95
96 Eina_Bool (*scene_init)(const char *texture);
97
98} Scene_Data;
99
100Scene_Data globalscene;
101
102static void
103_on_delete(Ecore_Evas *ee EINA_UNUSED)
104{
105 Eina_List *l;
106 Test_object * item;
107 EINA_LIST_FOREACH(globalscene.spheres, l, item)
108 {
109 free(item);
110 }
111 eina_list_free(globalscene.spheres);
112
113 ecore_main_loop_quit();
114}
115
116static void
117_on_canvas_resize(Ecore_Evas *ee)
118{
119 int w, h;
120
121 ecore_evas_geometry_get(ee, NULL, NULL, &w, &h);
122 efl_gfx_entity_size_set(bg, EINA_SIZE2D(w, h));
123 efl_gfx_entity_size_set(image, EINA_SIZE2D(w, h));
124}
125
126static Eina_Bool
127_animate_sphere(void *data)
128{
129 static int angle = 0.0;
130 Eo *n = (Eo*)(((Test_object *)data)->node);
131 Evas_Real s = ((Test_object *)data)->speed;
132
133 evas_canvas3d_node_orientation_angle_axis_set(n, angle, s, s - 1, s + 1);
134 angle++;
135 if (angle > 360) angle = 0.0;
136
137 return EINA_TRUE;
138}
139
140void _recalculate_position()
141{
142 int i = 0, j = 0, count = 0;
143 Evas_Real x1, y1, shiftx = 0, shifty = 0;
144 Test_object *m;
145
146 evas_canvas3d_object_update(((Test_object *)eina_list_nth(globalscene.spheres, 0))->node);
147 evas_canvas3d_node_bounding_box_get(((Test_object *)eina_list_nth(globalscene.spheres, 0))->node, NULL, NULL, NULL, &x1, &y1, NULL);
148
149 for (i = 0; i < globalscene.row; ++i)
150 {
151 shiftx = (i * 2 - globalscene.row) * x1;
152 for(j = 0; j < globalscene.col; ++j)
153 {
154 shifty = (j * 2 - globalscene.col) * y1;
155 m = (Test_object *)eina_list_nth(globalscene.spheres, count);
156 evas_canvas3d_node_position_set(m->node, shifty, 0.0, shiftx);
157 count++;
158 }
159 }
160}
161
162static void
163_on_key_down(void *data EINA_UNUSED, Evas *e EINA_UNUSED,
164 Evas_Object *eo EINA_UNUSED, void *event_info)
165{
166 Evas_Event_Key_Down *ev = event_info;
167 Evas_Real x, y, z;
168 Eina_List *l;
169 Test_object * item;
170
171 if (!strcmp(ev->key, "Down"))
172 {
173 evas_canvas3d_node_position_get(globalscene.camera_node, EVAS_CANVAS3D_SPACE_PARENT, &x, &y, &z);
174 evas_canvas3d_node_position_set(globalscene.camera_node, x, y, (z - 5));
175 }
176 else if (!strcmp(ev->key, "Up"))
177 {
178 evas_canvas3d_node_position_get(globalscene.camera_node, EVAS_CANVAS3D_SPACE_PARENT, &x, &y, &z);
179 evas_canvas3d_node_position_set(globalscene.camera_node, x, y, (z + 5));
180 }
181 else if (!strcmp(ev->key, "Left"))
182 {
183 evas_canvas3d_node_scale_get(((Test_object *)eina_list_nth(globalscene.spheres, 0))->node, EVAS_CANVAS3D_SPACE_PARENT, &x, &y, &z);
184 EINA_LIST_FOREACH(globalscene.spheres, l, item)
185 {
186 evas_canvas3d_node_scale_set(item->node, (x - SCALE_UNIT), (y - SCALE_UNIT), (z - SCALE_UNIT));
187 }
188 _recalculate_position();
189 }
190 else if (!strcmp(ev->key, "Right"))
191 {
192 evas_canvas3d_node_scale_get(((Test_object *)eina_list_nth(globalscene.spheres, 0))->node, EVAS_CANVAS3D_SPACE_PARENT, &x, &y, &z);
193 EINA_LIST_FOREACH(globalscene.spheres, l, item)
194 {
195 evas_canvas3d_node_scale_set(item->node, (x + SCALE_UNIT), (y + SCALE_UNIT), (z + SCALE_UNIT));
196 }
197 _recalculate_position();
198 }
199 else
200 printf("Down, Up for position of camera; Left, Right for scale of each node");
201}
202
203static void
204_on_mouse_down(void *data EINA_UNUSED, Evas *e EINA_UNUSED, Evas_Object *eo EINA_UNUSED, void *event_info)
205{
206 Evas_Event_Mouse_Down *ev = event_info;
207 Evas_Canvas3D_Node *n;
208 Evas_Canvas3D_Mesh *m;
209 Evas_Real s, t;
210 clock_t time;
211 float diff_sec;
212
213 time = clock();
214 Eina_Bool flag;
215 if (ev->button == 1)
216 {
217 evas_canvas3d_scene_color_pick_enable_set(globalscene.scene, EINA_TRUE);
218 flag = evas_canvas3d_scene_pick(globalscene.scene, ev->canvas.x, ev->canvas.y, &n, &m, NULL, NULL);
219 time = clock() - time;
220 diff_sec = ((float)time) / CLOCKS_PER_SEC / 10;
221 if (flag)
222 {
223 printf("Boom! Time expended for color pick: %2.7f .\n", diff_sec);
224 evas_canvas3d_node_scale_set(n, VEC_3(SMALL_SCALE));
225 }
226 }
227 else
228 {
229 evas_canvas3d_scene_color_pick_enable_set(globalscene.scene, EINA_FALSE);
230 flag = evas_canvas3d_scene_pick(globalscene.scene, ev->canvas.x, ev->canvas.y, &n, &m, &s, &t);
231 time = clock() - time;
232 diff_sec = ((float)time) / CLOCKS_PER_SEC / 10;
233 if (flag)
234 {
235 printf("Boom! Time expended for geometry pick: %2.7f .\n", diff_sec);
236 evas_canvas3d_node_scale_set(n, VEC_3(BIG_SCALE));
237 }
238 }
239}
240
241Eina_Bool
242_init_sphere(void *this, const char *texture)
243{
244 Test_object *sphere = (Test_object *)this;
245
246 sphere->primitive = efl_add(EVAS_CANVAS3D_PRIMITIVE_CLASS, evas);
247 sphere->mesh = efl_add(EVAS_CANVAS3D_MESH_CLASS, evas);
248 sphere->material = efl_add(EVAS_CANVAS3D_MATERIAL_CLASS, evas);
249 evas_canvas3d_primitive_form_set(sphere->primitive, EVAS_CANVAS3D_MESH_PRIMITIVE_SPHERE);
250 evas_canvas3d_primitive_precision_set(sphere->primitive, 50);
251 evas_canvas3d_mesh_from_primitive_set(sphere->mesh, 0, sphere->primitive);
252 evas_canvas3d_mesh_frame_material_set(sphere->mesh, 0, sphere->material);
253 evas_canvas3d_mesh_shader_mode_set(sphere->mesh, EVAS_CANVAS3D_SHADER_MODE_PHONG);
254
255 evas_canvas3d_mesh_color_pick_enable_set(sphere->mesh, EINA_TRUE);
256
257 sphere->texture = efl_add(EVAS_CANVAS3D_TEXTURE_CLASS, evas);
258 efl_file_simple_load(sphere->texture, texture, NULL);
259 evas_canvas3d_texture_filter_set(sphere->texture, EVAS_CANVAS3D_TEXTURE_FILTER_NEAREST, EVAS_CANVAS3D_TEXTURE_FILTER_NEAREST);
260 evas_canvas3d_texture_wrap_set(sphere->texture, EVAS_CANVAS3D_WRAP_MODE_REPEAT, EVAS_CANVAS3D_WRAP_MODE_REPEAT);
261 evas_canvas3d_material_texture_set(sphere->material, EVAS_CANVAS3D_MATERIAL_ATTRIB_DIFFUSE, sphere->texture);
262 evas_canvas3d_material_enable_set(sphere->material, EVAS_CANVAS3D_MATERIAL_ATTRIB_AMBIENT, EINA_TRUE);
263 evas_canvas3d_material_enable_set(sphere->material, EVAS_CANVAS3D_MATERIAL_ATTRIB_DIFFUSE, EINA_TRUE);
264 evas_canvas3d_material_enable_set(sphere->material, EVAS_CANVAS3D_MATERIAL_ATTRIB_SPECULAR, EINA_TRUE);
265 evas_canvas3d_material_enable_set(sphere->material, EVAS_CANVAS3D_MATERIAL_ATTRIB_NORMAL, EINA_TRUE);
266 evas_canvas3d_material_color_set(sphere->material, EVAS_CANVAS3D_MATERIAL_ATTRIB_AMBIENT, 0.01, 0.01, 0.01, 1.0);
267 evas_canvas3d_material_color_set(sphere->material, EVAS_CANVAS3D_MATERIAL_ATTRIB_DIFFUSE, 1.0, 1.0, 1.0, 1.0);
268 evas_canvas3d_material_color_set(sphere->material, EVAS_CANVAS3D_MATERIAL_ATTRIB_SPECULAR, 1.0, 1.0, 1.0, 1.0);
269 evas_canvas3d_material_shininess_set(sphere->material, 50.0);
270
271 return EINA_TRUE;
272}
273
274Eina_Bool
275_init_scene(const char *texture)
276{
277 int i = 0;
278 Evas_Real tmp;
279 Test_object *m;
280
281 globalscene.scene = efl_add(EVAS_CANVAS3D_SCENE_CLASS, evas);
282
283 globalscene.root_node = efl_add(EVAS_CANVAS3D_NODE_CLASS, evas, evas_canvas3d_node_type_set(efl_added, EVAS_CANVAS3D_NODE_TYPE_NODE));
284
285 globalscene.camera = efl_add(EVAS_CANVAS3D_CAMERA_CLASS, evas);
286 evas_canvas3d_camera_projection_perspective_set(globalscene.camera, 30.0, 1.0, 1.0, 1000.0);
287
288 globalscene.camera_node =
289 efl_add(EVAS_CANVAS3D_NODE_CLASS, evas, evas_canvas3d_node_type_set(efl_added, EVAS_CANVAS3D_NODE_TYPE_CAMERA));
290 evas_canvas3d_node_camera_set(globalscene.camera_node, globalscene.camera);
291 evas_canvas3d_node_member_add(globalscene.root_node, globalscene.camera_node);
292 evas_canvas3d_node_position_set(globalscene.camera_node, 0.0, 30.0, 800.0);
293 evas_canvas3d_node_look_at_set(globalscene.camera_node, EVAS_CANVAS3D_SPACE_PARENT, 0.0, 0.0, -1000.0, EVAS_CANVAS3D_SPACE_PARENT, 0.0, 1.0, 0.0);
294 globalscene.light = efl_add(EVAS_CANVAS3D_LIGHT_CLASS, evas);
295 evas_canvas3d_light_ambient_set(globalscene.light, 1.0, 1.0, 1.0, 1.0);
296 evas_canvas3d_light_diffuse_set(globalscene.light, 1.0, 1.0, 1.0, 1.0);
297 evas_canvas3d_light_specular_set(globalscene.light, 1.0, 1.0, 1.0, 1.0);
298 evas_canvas3d_light_directional_set(globalscene.light, EINA_TRUE);
299
300 globalscene.light_node =
301 efl_add(EVAS_CANVAS3D_NODE_CLASS, evas, evas_canvas3d_node_type_set(efl_added, EVAS_CANVAS3D_NODE_TYPE_LIGHT));
302 evas_canvas3d_node_light_set(globalscene.light_node, globalscene.light);
303 evas_canvas3d_node_position_set(globalscene.light_node, 100.0, 50.0, 300.0);
304 evas_canvas3d_node_look_at_set(globalscene.light_node, EVAS_CANVAS3D_SPACE_PARENT, 0.0, 0.0, 0.0, EVAS_CANVAS3D_SPACE_PARENT, 1.0, 1.0, 1.0);
305 evas_canvas3d_node_member_add(globalscene.root_node, globalscene.light_node);
306
307 tmp = 0.01;
308 for (i = 0; i < globalscene.col * globalscene.row; i++)
309 {
310 Test_object *spheretmp;
311
312 m = malloc(sizeof(Test_object));
313 m->sphere_init = _init_sphere;
314 if (!i)
315 m->sphere_init(m, texture);
316 else
317 {
318 spheretmp = (Test_object *)eina_list_nth(globalscene.spheres, 0);
319 m->mesh = spheretmp->mesh;
320 m->material = spheretmp->material;
321 m->texture = spheretmp->texture;
322 }
323 m->node = efl_add(EVAS_CANVAS3D_NODE_CLASS, evas, evas_canvas3d_node_type_set(efl_added, EVAS_CANVAS3D_NODE_TYPE_MESH));
324 m->speed = tmp;
325 m->sphere_animate = _animate_sphere;
326 m->animate = ecore_timer_add(m->speed, m->sphere_animate, m);
327 evas_canvas3d_node_member_add(globalscene.root_node, m->node);
328 evas_canvas3d_node_mesh_add(m->node, m->mesh);
329 evas_canvas3d_node_scale_set(m->node, VEC_3(INIT_SCALE));
330 globalscene.spheres = eina_list_append(globalscene.spheres, m);
331 tmp += 0.01;
332 }
333
334 _recalculate_position();
335
336 evas_canvas3d_scene_root_node_set(globalscene.scene, globalscene.root_node);
337 evas_canvas3d_scene_camera_node_set(globalscene.scene, globalscene.camera_node);
338 evas_canvas3d_scene_size_set(globalscene.scene, WIDTH, HEIGHT);
339
340 return EINA_TRUE;
341}
342
343int main(int argc, char **argv)
344{
345 int row = 0, col = 0, precision = 0;
346 char *texture = NULL;
347 Eina_Bool r;
348
349 Ecore_Getopt_Value values[] = {
350 ECORE_GETOPT_VALUE_INT(row),
351 ECORE_GETOPT_VALUE_INT(col),
352 ECORE_GETOPT_VALUE_INT(precision),
353 ECORE_GETOPT_VALUE_STR(texture),
354 ECORE_GETOPT_VALUE_NONE
355 };
356
357 if (!ecore_evas_init()) return 0;
358 if (!ecore_init()) return 0;
359
360 ecore_getopt_parse(&optdesc, values, argc, argv);
361
362 if (!row) row = 2;
363 if (!col) col = 5;
364 if (!precision) precision = 30;
365 if (!texture) texture = (char *)image_path;
366
367 printf("row - %d, col - %d, precision of spheres - %d, texture - %s\n",
368 row, col, precision, texture);
369
370 ecore_evas = ecore_evas_new("opengl_x11", 10, 10, WIDTH, HEIGHT, NULL);
371
372 if (!ecore_evas) return 0;
373
374 ecore_evas_callback_delete_request_set(ecore_evas, _on_delete);
375 ecore_evas_callback_resize_set(ecore_evas, _on_canvas_resize);
376 ecore_evas_show(ecore_evas);
377
378 evas = ecore_evas_get(ecore_evas);
379
380 bg = evas_object_rectangle_add(evas);
381 evas_object_color_set(bg, 100, 100, 100, 255);
382 evas_object_move(bg, 0, 0);
383 evas_object_resize(bg, WIDTH, HEIGHT);
384 evas_object_show(bg);
385
386 globalscene.scene_init = _init_scene;
387 globalscene.row = row;
388 globalscene.col = col;
389 globalscene.precision = precision;
390 globalscene.scene_init(texture);
391
392 image = efl_add(EFL_CANVAS_SCENE3D_CLASS, evas);
393
394 efl_gfx_entity_size_set(image, EINA_SIZE2D(WIDTH, HEIGHT));
395 efl_gfx_entity_visible_set(image, EINA_TRUE);
396 evas_object_focus_set(image, EINA_TRUE);
397 efl_canvas_scene3d_set(image, globalscene.scene);
398
399 r = evas_object_key_grab(image, "Down", 0, 0, EINA_TRUE);
400 r = evas_object_key_grab(image, "Up", 0, 0, EINA_TRUE);
401 r = evas_object_key_grab(image, "Left", 0, 0, EINA_TRUE);
402 r = evas_object_key_grab(image, "Right", 0, 0, EINA_TRUE);
403
404 (void) r;
405
406 evas_object_event_callback_add(image, EVAS_CALLBACK_MOUSE_DOWN, _on_mouse_down, NULL);
407 evas_object_event_callback_add(image, EVAS_CALLBACK_KEY_DOWN, _on_key_down, NULL);
408
409 ecore_main_loop_begin();
410
411 ecore_evas_free(ecore_evas);
412 ecore_evas_shutdown();
413
414 return 0;
415}
diff --git a/src/examples/evas/evas-3d-cube-rotate.c b/src/examples/evas/evas-3d-cube-rotate.c
deleted file mode 100644
index d5b89b3037..0000000000
--- a/src/examples/evas/evas-3d-cube-rotate.c
+++ /dev/null
@@ -1,285 +0,0 @@
1/**
2 * Example of using mouse callback events for node rotation in Evas-3D.
3 *
4 * After clicking the mouse on cube callbacks began to emit automatically,
5 * depending on mouse's position change the cube rotates with a certain
6 * speed while mouse is still on the cube, also rotation slows down when
7 * leaving the boundaries of the cube, all this goes on while the mouse
8 * is pressed. Note, that rotation is taking place around one axis only.
9 *
10 * @verbatim
11 * gcc -o evas-3d-cube-rotate evas-3d-cube-rotate.c -g `pkg-config --libs --cflags evas ecore ecore-evas eo` -lm
12 * @endverbatim
13 */
14
15#ifdef HAVE_CONFIG_H
16#include "config.h"
17#else
18#define EFL_BETA_API_SUPPORT
19#endif
20
21#include <Ecore.h>
22#include <Ecore_Evas.h>
23#include <Evas.h>
24#include <Eo.h>
25
26#define WIDTH 400
27#define HEIGHT 400
28
29typedef struct _Scene_Data
30{
31 Eo *scene;
32 Eo *root_node;
33 Eo *camera_node;
34 Eo *light_node;
35 Eo *mesh_node;
36
37 Eo *camera;
38 Eo *light;
39 Eo *cube;
40 Eo *mesh;
41 Eo *material;
42 float angle;
43 Evas_Coord mouse_old_x;
44 int mouse_diff_x;
45 int mouse_indicator;
46} Scene_Data;
47
48Eo *scene = NULL;
49Ecore_Evas *ecore_evas = NULL;
50Evas *evas = NULL;
51Eo *background = NULL;
52Eo *image = NULL;
53static float angle = 0.0f;
54float d_angle = 0.5;
55
56static void
57_on_delete(Ecore_Evas *ee EINA_UNUSED)
58{
59 ecore_main_loop_quit();
60}
61
62static void
63_on_canvas_resize(Ecore_Evas *ee)
64{
65 int w, h;
66
67 ecore_evas_geometry_get(ee, NULL, NULL, &w, &h);
68
69 evas_object_resize(background, w, h);
70 evas_object_resize(image, w, h);
71 evas_object_move(image, 0, 0);
72}
73
74static Eina_Bool
75_continue_scene(void *data)
76{
77 Scene_Data *d = (Scene_Data *)data;
78
79 if (d->mouse_indicator == 1)
80 {
81 evas_event_feed_mouse_down(evas, 1, EVAS_BUTTON_NONE, 0, &data);
82 }
83
84 return EINA_TRUE;
85}
86
87static void
88_rotate_x_reload(Evas_Canvas3D_Scene *eo_scene, Evas_Event_Mouse_Down *ev, Evas_Canvas3D_Node *node, Evas_Canvas3D_Mesh *mesh,
89 float *angle_diff, Evas_Coord *mouse_coord)
90{
91 Evas_Canvas3D_Node *n = NULL;
92 Evas_Canvas3D_Mesh *m = NULL;
93 Evas_Real s, t;
94 int mouse_diff;
95
96 evas_canvas3d_scene_pick(eo_scene, ev->canvas.x, ev->canvas.y, &n, &m, &s, &t);
97
98 if ((n == node) && (m == mesh))
99 {
100 mouse_diff = ev->canvas.x - (*mouse_coord);
101 *mouse_coord = ev->canvas.x;
102 *angle_diff = (mouse_diff)/4;
103 }
104 else
105 {
106 if (*angle_diff > 2)
107 (*angle_diff)-=1;
108 else if (*angle_diff >0)
109 (*angle_diff)-=0.25;
110 else if(*angle_diff < -2)
111 (*angle_diff)+=1;
112 else if (*angle_diff <0)
113 (*angle_diff)+=0.25;
114 }
115}
116
117static void
118_play_scene(void *data, Evas *_evas EINA_UNUSED, Evas_Object *eo EINA_UNUSED, void *event_info)
119{
120 Evas_Event_Mouse_Down *ev = event_info;
121 Scene_Data *d = (Scene_Data *)data;
122
123 _rotate_x_reload(scene, ev, d->mesh_node, d->mesh, &d->angle, &d->mouse_old_x);
124
125 /* Run this cycle only once to avoid the callback tree. */
126 if (d->mouse_indicator == 0)
127 ecore_timer_add(0.016, _continue_scene, data);
128
129 d->mouse_indicator = 1;
130}
131
132static void
133_stop_scene(void *data, Evas *_evas EINA_UNUSED, Evas_Object *eo EINA_UNUSED, void *event_info EINA_UNUSED)
134{
135 Scene_Data *d = (Scene_Data *)data;
136
137 d->angle = 0.0;
138 d->mouse_indicator = 2;
139}
140
141static Eina_Bool
142_animate_scene(void *data)
143{
144 Scene_Data *sc = (Scene_Data *)data;
145
146 angle += sc->angle;
147
148 evas_canvas3d_node_orientation_angle_axis_set(sc->mesh_node, angle, 0, 1.0, 0.0);
149
150 return EINA_TRUE;
151}
152
153static void
154_camera_setup(Scene_Data *data)
155{
156 data->camera = efl_add(EVAS_CANVAS3D_CAMERA_CLASS, evas);
157 evas_canvas3d_camera_projection_perspective_set(data->camera, 20.0, 1.0, 2.0, 50.0);
158
159 data->camera_node = efl_add(EVAS_CANVAS3D_NODE_CLASS, evas, evas_canvas3d_node_type_set(efl_added, EVAS_CANVAS3D_NODE_TYPE_CAMERA));
160 evas_canvas3d_node_camera_set(data->camera_node, data->camera);
161 evas_canvas3d_node_position_set(data->camera_node, 3.0, 3.0, 10.0);
162 evas_canvas3d_node_look_at_set(data->camera_node, EVAS_CANVAS3D_SPACE_PARENT, 0.0, 0.0, 0.0, EVAS_CANVAS3D_SPACE_PARENT, 0.0, 1.0, 0.0);
163
164 evas_canvas3d_node_member_add(data->root_node, data->camera_node);
165}
166
167static void
168_light_setup(Scene_Data *data)
169{
170 data->light = efl_add(EVAS_CANVAS3D_LIGHT_CLASS, evas);
171
172 evas_canvas3d_light_ambient_set(data->light, 0.2, 0.2, 0.2, 1.0);
173 evas_canvas3d_light_diffuse_set(data->light, 1.0, 1.0, 1.0, 1.0);
174 evas_canvas3d_light_specular_set(data->light, 1.0, 1.0, 1.0, 1.0);
175
176 data->light_node = efl_add(EVAS_CANVAS3D_NODE_CLASS, evas, evas_canvas3d_node_type_set(efl_added, EVAS_CANVAS3D_NODE_TYPE_LIGHT));
177
178 evas_canvas3d_node_light_set(data->light_node, data->light);
179 evas_canvas3d_node_position_set(data->light_node, 5.0, 5.0, 10.0);
180 evas_canvas3d_node_look_at_set(data->light_node, EVAS_CANVAS3D_SPACE_PARENT, 0.0, 0.0, 0.0, EVAS_CANVAS3D_SPACE_PARENT, 0.0, 1.0, 0.0);
181
182 evas_canvas3d_node_member_add(data->root_node, data->light_node);
183}
184
185static void
186_mesh_setup(Scene_Data *data)
187{
188 /* Setup material. */
189 data->material = efl_add(EVAS_CANVAS3D_MATERIAL_CLASS, evas);
190
191 evas_canvas3d_material_enable_set(data->material, EVAS_CANVAS3D_MATERIAL_ATTRIB_AMBIENT, EINA_TRUE);
192 evas_canvas3d_material_enable_set(data->material, EVAS_CANVAS3D_MATERIAL_ATTRIB_DIFFUSE, EINA_TRUE);
193 evas_canvas3d_material_enable_set(data->material, EVAS_CANVAS3D_MATERIAL_ATTRIB_SPECULAR, EINA_TRUE);
194 evas_canvas3d_material_color_set(data->material, EVAS_CANVAS3D_MATERIAL_ATTRIB_AMBIENT, 0.2, 0.2, 0.2, 1.0);
195 evas_canvas3d_material_color_set(data->material, EVAS_CANVAS3D_MATERIAL_ATTRIB_DIFFUSE, 0.8, 0.8, 0.8, 1.0);
196 evas_canvas3d_material_color_set(data->material, EVAS_CANVAS3D_MATERIAL_ATTRIB_SPECULAR, 1.0, 1.0, 1.0, 1.0);
197 evas_canvas3d_material_shininess_set(data->material, 100.0);
198
199 /* Setup primitive */
200 data->cube = efl_add(EVAS_CANVAS3D_PRIMITIVE_CLASS, evas);
201 evas_canvas3d_primitive_form_set(data->cube, EVAS_CANVAS3D_MESH_PRIMITIVE_CUBE);
202
203 /* Setup mesh. */
204 data->mesh = efl_add(EVAS_CANVAS3D_MESH_CLASS, evas);
205 evas_canvas3d_mesh_from_primitive_set(data->mesh, 0, data->cube);
206 evas_canvas3d_mesh_shader_mode_set(data->mesh, EVAS_CANVAS3D_SHADER_MODE_PHONG);
207 evas_canvas3d_mesh_frame_material_set(data->mesh, 0, data->material);
208
209 data->mesh_node = efl_add(EVAS_CANVAS3D_NODE_CLASS, evas, evas_canvas3d_node_type_set(efl_added, EVAS_CANVAS3D_NODE_TYPE_MESH));
210 evas_canvas3d_node_member_add(data->root_node, data->mesh_node);
211 evas_canvas3d_node_mesh_add(data->mesh_node, data->mesh);
212}
213
214static void
215_scene_setup(Scene_Data *data)
216{
217 scene = efl_add(EVAS_CANVAS3D_SCENE_CLASS, evas);
218 data->root_node = efl_add(EVAS_CANVAS3D_NODE_CLASS, evas, evas_canvas3d_node_type_set(efl_added, EVAS_CANVAS3D_NODE_TYPE_NODE));
219
220 evas_canvas3d_scene_size_set(scene, WIDTH, HEIGHT);
221 evas_canvas3d_scene_background_color_set(scene, 0.0, 0.0, 0.0, 0.0);
222
223 _camera_setup(data);
224 _light_setup(data);
225 _mesh_setup(data);
226
227 evas_canvas3d_scene_root_node_set(scene, data->root_node);
228 evas_canvas3d_scene_camera_node_set(scene, data->camera_node);
229
230 data->mouse_old_x = 0;
231 data->mouse_diff_x = 0;
232 data->mouse_indicator = 0;
233}
234
235int
236main(void)
237{
238 Scene_Data data;
239
240 if (!ecore_evas_init()) return 0;
241
242 ecore_evas = ecore_evas_new("opengl_x11", 10, 10, WIDTH, HEIGHT, NULL);
243
244 if (!ecore_evas) return 0;
245
246 ecore_evas_callback_delete_request_set(ecore_evas, _on_delete);
247 ecore_evas_callback_resize_set(ecore_evas, _on_canvas_resize);
248 ecore_evas_show(ecore_evas);
249
250 evas = ecore_evas_get(ecore_evas);
251
252 memset(&data, 0, sizeof(Scene_Data));
253 _scene_setup(&data);
254
255 /* Add a background rectangle object. */
256 background = evas_object_rectangle_add(evas);
257 evas_object_color_set(background, 0, 0, 0, 255);
258 evas_object_move(background, 0, 0);
259 evas_object_resize(background, WIDTH, HEIGHT);
260 evas_object_show(background);
261
262 /* Add an image object for 3D scene rendering. */
263 image = efl_add(EFL_CANVAS_SCENE3D_CLASS, evas);
264 efl_gfx_entity_geometry_set(image, EINA_RECT(0, 0, WIDTH, HEIGHT));
265 evas_object_show(image);
266
267 /* Set the image object as render target for 3D scene. */
268 efl_canvas_scene3d_set(image, scene);
269
270 evas_object_focus_set(image, EINA_TRUE);
271
272 evas_object_event_callback_add(image, EVAS_CALLBACK_MOUSE_DOWN, _play_scene, &data);
273 evas_object_event_callback_add(image, EVAS_CALLBACK_MOUSE_UP, _stop_scene, &data);
274
275 /* Add animation timer callback. */
276 ecore_timer_add(0.016, _animate_scene, &data);
277
278 /* Enter main loop. */
279 ecore_main_loop_begin();
280
281 ecore_evas_free(ecore_evas);
282 ecore_evas_shutdown();
283
284 return 0;
285}
diff --git a/src/examples/evas/evas-3d-cube.c b/src/examples/evas/evas-3d-cube.c
deleted file mode 100644
index 50c3034342..0000000000
--- a/src/examples/evas/evas-3d-cube.c
+++ /dev/null
@@ -1,262 +0,0 @@
1/**
2 * Example of creating simple meshes in Evas-3D.
3 *
4 * This example is the best to start introduction to usage of Evas-3D.
5 *
6 * @verbatim
7 * gcc -o evas-3d-cube evas-3d-cube.c `pkg-config --libs --cflags efl evas ecore ecore-evas eo`
8 * @endverbatim
9 */
10
11#ifdef HAVE_CONFIG_H
12#include "config.h"
13#else
14#define EFL_BETA_API_SUPPORT
15#endif
16
17#include <Eo.h>
18#include <Evas.h>
19#include <Ecore.h>
20#include <Ecore_Evas.h>
21
22#define WIDTH 400
23#define HEIGHT 400
24
25typedef struct _Scene_Data
26{
27 Eo *scene;
28 Eo *root_node;
29 Eo *camera_node;
30 Eo *light_node;
31 Eo *mesh_node;
32
33 Eo *camera;
34 Eo *light;
35 Eo *mesh;
36 Eo *material;
37} Scene_Data;
38
39static Ecore_Evas *ecore_evas = NULL;
40static Evas *evas = NULL;
41static Eo *background = NULL;
42static Eo *image = NULL;
43
44static const float cube_vertices[] =
45{
46 /* Front */
47 -1.0, 1.0, 1.0, 0.0, 0.0, 1.0, 1.0, 0.0, 0.0, 1.0, 0.0, 1.0,
48 1.0, 1.0, 1.0, 0.0, 0.0, 1.0, 1.0, 0.0, 0.0, 1.0, 1.0, 1.0,
49 -1.0, -1.0, 1.0, 0.0, 0.0, 1.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0,
50 1.0, -1.0, 1.0, 0.0, 0.0, 1.0, 1.0, 0.0, 0.0, 1.0, 1.0, 0.0,
51
52 /* Back */
53 1.0, 1.0, -1.0, 0.0, 0.0, -1.0, 0.0, 0.0, 1.0, 1.0, 0.0, 1.0,
54 -1.0, 1.0, -1.0, 0.0, 0.0, -1.0, 0.0, 0.0, 1.0, 1.0, 1.0, 1.0,
55 1.0, -1.0, -1.0, 0.0, 0.0, -1.0, 0.0, 0.0, 1.0, 1.0, 0.0, 0.0,
56 -1.0, -1.0, -1.0, 0.0, 0.0, -1.0, 0.0, 0.0, 1.0, 1.0, 1.0, 0.0,
57
58 /* Left */
59 -1.0, 1.0, -1.0, -1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0,
60 -1.0, 1.0, 1.0, -1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 1.0, 1.0, 1.0,
61 -1.0, -1.0, -1.0, -1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 1.0, 0.0, 0.0,
62 -1.0, -1.0, 1.0, -1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 1.0, 1.0, 0.0,
63
64 /* Right */
65 1.0, 1.0, 1.0, 1.0, 0.0, 0.0, 1.0, 1.0, 0.0, 1.0, 0.0, 1.0,
66 1.0, 1.0, -1.0, 1.0, 0.0, 0.0, 1.0, 1.0, 0.0, 1.0, 1.0, 1.0,
67 1.0, -1.0, 1.0, 1.0, 0.0, 0.0, 1.0, 1.0, 0.0, 1.0, 0.0, 0.0,
68 1.0, -1.0, -1.0, 1.0, 0.0, 0.0, 1.0, 1.0, 0.0, 1.0, 1.0, 0.0,
69
70 /* Top */
71 -1.0, 1.0, -1.0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 1.0, 0.0, 1.0,
72 1.0, 1.0, -1.0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 1.0, 1.0, 1.0,
73 -1.0, 1.0, 1.0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 1.0, 0.0, 0.0,
74 1.0, 1.0, 1.0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 1.0, 1.0, 0.0,
75
76 /* Bottom */
77 1.0, -1.0, -1.0, 0.0, -1.0, 0.0, 0.0, 1.0, 1.0, 1.0, 0.0, 1.0,
78 -1.0, -1.0, -1.0, 0.0, -1.0, 0.0, 0.0, 1.0, 1.0, 1.0, 1.0, 1.0,
79 1.0, -1.0, 1.0, 0.0, -1.0, 0.0, 0.0, 1.0, 1.0, 1.0, 0.0, 0.0,
80 -1.0, -1.0, 1.0, 0.0, -1.0, 0.0, 0.0, 1.0, 1.0, 1.0, 1.0, 0.0,
81};
82
83static const unsigned short cube_indices[] =
84{
85 /* Front */
86 0, 1, 2, 2, 1, 3,
87
88 /* Back */
89 4, 5, 6, 6, 5, 7,
90
91 /* Left */
92 8, 9, 10, 10, 9, 11,
93
94 /* Right */
95 12, 13, 14, 14, 13, 15,
96
97 /* Top */
98 16, 17, 18, 18, 17, 19,
99
100 /* Bottom */
101 20, 21, 22, 22, 21, 23
102};
103
104static void
105_on_delete(Ecore_Evas *ee EINA_UNUSED)
106{
107 ecore_main_loop_quit();
108}
109
110static void
111_on_canvas_resize(Ecore_Evas *ee)
112{
113 int w, h;
114
115 ecore_evas_geometry_get(ee, NULL, NULL, &w, &h);
116 efl_gfx_entity_size_set(background, EINA_SIZE2D(w, h));
117 efl_gfx_entity_size_set(image, EINA_SIZE2D(w, h));
118}
119
120static Eina_Bool
121_animate_scene(void *data)
122{
123 static float angle = 0.0f;
124 Scene_Data *scene = (Scene_Data *)data;
125
126 angle += 0.5;
127
128 evas_canvas3d_node_orientation_angle_axis_set(scene->mesh_node, angle, 1.0, 1.0, 1.0);
129
130 /* Rotate */
131 if (angle > 360.0) angle -= 360.0f;
132
133 return EINA_TRUE;
134}
135
136static void
137_camera_setup(Scene_Data *data)
138{
139 data->camera = efl_add(EVAS_CANVAS3D_CAMERA_CLASS, evas);
140
141 evas_canvas3d_camera_projection_perspective_set(data->camera, 60.0, 1.0, 2.0, 50.0);
142
143 data->camera_node =
144 efl_add(EVAS_CANVAS3D_NODE_CLASS, evas, evas_canvas3d_node_type_set(efl_added, EVAS_CANVAS3D_NODE_TYPE_CAMERA));
145 evas_canvas3d_node_camera_set(data->camera_node, data->camera);
146 evas_canvas3d_node_position_set(data->camera_node, 0.0, 0.0, 10.0);
147 evas_canvas3d_node_look_at_set(data->camera_node, EVAS_CANVAS3D_SPACE_PARENT, 0.0, 0.0, 0.0, EVAS_CANVAS3D_SPACE_PARENT, 0.0, 1.0, 0.0);
148 evas_canvas3d_node_member_add(data->root_node, data->camera_node);
149}
150
151static void
152_light_setup(Scene_Data *data)
153{
154 data->light = efl_add(EVAS_CANVAS3D_LIGHT_CLASS, evas);
155 evas_canvas3d_light_ambient_set(data->light, 0.2, 0.2, 0.2, 1.0);
156 evas_canvas3d_light_diffuse_set(data->light, 1.0, 1.0, 1.0, 1.0);
157 evas_canvas3d_light_specular_set(data->light, 1.0, 1.0, 1.0, 1.0);
158
159 data->light_node =
160 efl_add(EVAS_CANVAS3D_NODE_CLASS, evas, evas_canvas3d_node_type_set(efl_added, EVAS_CANVAS3D_NODE_TYPE_LIGHT));
161 evas_canvas3d_node_light_set(data->light_node, data->light);
162 evas_canvas3d_node_position_set(data->light_node, 0.0, 0.0, 10.0);
163 evas_canvas3d_node_look_at_set(data->light_node, EVAS_CANVAS3D_SPACE_PARENT, 0.0, 0.0, 0.0, EVAS_CANVAS3D_SPACE_PARENT, 0.0, 1.0, 0.0);
164 evas_canvas3d_node_member_add(data->root_node, data->light_node);
165}
166static void
167_mesh_setup(Scene_Data *data)
168{
169 /* Setup material. */
170 data->material = efl_add(EVAS_CANVAS3D_MATERIAL_CLASS, evas);
171
172 evas_canvas3d_material_enable_set(data->material, EVAS_CANVAS3D_MATERIAL_ATTRIB_AMBIENT, EINA_TRUE);
173 evas_canvas3d_material_enable_set(data->material, EVAS_CANVAS3D_MATERIAL_ATTRIB_DIFFUSE, EINA_TRUE);
174 evas_canvas3d_material_enable_set(data->material, EVAS_CANVAS3D_MATERIAL_ATTRIB_SPECULAR, EINA_TRUE);
175 evas_canvas3d_material_color_set(data->material, EVAS_CANVAS3D_MATERIAL_ATTRIB_AMBIENT, 0.2, 0.2, 0.2, 1.0);
176 evas_canvas3d_material_color_set(data->material, EVAS_CANVAS3D_MATERIAL_ATTRIB_DIFFUSE, 0.8, 0.8, 0.8, 1.0);
177 evas_canvas3d_material_color_set(data->material, EVAS_CANVAS3D_MATERIAL_ATTRIB_SPECULAR, 1.0, 1.0, 1.0, 1.0);
178 evas_canvas3d_material_shininess_set(data->material, 100.0);
179
180 /* Setup mesh. */
181 data->mesh = efl_add(EVAS_CANVAS3D_MESH_CLASS, evas);
182 evas_canvas3d_mesh_vertex_count_set(data->mesh, 24);
183 evas_canvas3d_mesh_frame_add(data->mesh, 0);
184 evas_canvas3d_mesh_frame_vertex_data_set(data->mesh, 0, EVAS_CANVAS3D_VERTEX_ATTRIB_POSITION, 12 * sizeof(float), &cube_vertices[ 0]);
185 evas_canvas3d_mesh_frame_vertex_data_set(data->mesh, 0, EVAS_CANVAS3D_VERTEX_ATTRIB_NORMAL, 12 * sizeof(float), &cube_vertices[ 3]);
186 evas_canvas3d_mesh_frame_vertex_data_set(data->mesh, 0, EVAS_CANVAS3D_VERTEX_ATTRIB_COLOR, 12 * sizeof(float), &cube_vertices[ 6]);
187 evas_canvas3d_mesh_frame_vertex_data_set(data->mesh, 0, EVAS_CANVAS3D_VERTEX_ATTRIB_TEXCOORD, 12 * sizeof(float), &cube_vertices[10]);
188 evas_canvas3d_mesh_index_data_set(data->mesh, EVAS_CANVAS3D_INDEX_FORMAT_UNSIGNED_SHORT, 36, &cube_indices[0]);
189 evas_canvas3d_mesh_vertex_assembly_set(data->mesh, EVAS_CANVAS3D_VERTEX_ASSEMBLY_TRIANGLES);
190 evas_canvas3d_mesh_shader_mode_set(data->mesh, EVAS_CANVAS3D_SHADER_MODE_PHONG);
191 evas_canvas3d_mesh_frame_material_set(data->mesh, 0, data->material);
192
193 data->mesh_node =
194 efl_add(EVAS_CANVAS3D_NODE_CLASS, evas, evas_canvas3d_node_type_set(efl_added, EVAS_CANVAS3D_NODE_TYPE_MESH));
195 evas_canvas3d_node_member_add(data->root_node, data->mesh_node);
196 evas_canvas3d_node_mesh_add(data->mesh_node, data->mesh);
197}
198
199static void
200_scene_setup(Scene_Data *data)
201{
202 data->scene = efl_add(EVAS_CANVAS3D_SCENE_CLASS, evas);
203 evas_canvas3d_scene_size_set(data->scene, WIDTH, HEIGHT);
204 evas_canvas3d_scene_background_color_set(data->scene, 0.0, 0.0, 0.0, 0.0);
205
206 data->root_node =
207 efl_add(EVAS_CANVAS3D_NODE_CLASS, evas, evas_canvas3d_node_type_set(efl_added, EVAS_CANVAS3D_NODE_TYPE_NODE));
208
209 _camera_setup(data);
210 _light_setup(data);
211 _mesh_setup(data);
212
213 evas_canvas3d_scene_root_node_set(data->scene, data->root_node);
214 evas_canvas3d_scene_camera_node_set(data->scene, data->camera_node);
215}
216
217int
218main(void)
219{
220 // Unless Evas 3D supports Software renderer, we force use of the gl backend.
221 putenv("ECORE_EVAS_ENGINE=opengl_x11");
222
223 Scene_Data data;
224
225 if (!ecore_evas_init()) return 0;
226
227 ecore_evas = ecore_evas_new(NULL, 10, 10, WIDTH, HEIGHT, NULL);
228 if (!ecore_evas) return 0;
229
230 ecore_evas_callback_delete_request_set(ecore_evas, _on_delete);
231 ecore_evas_callback_resize_set(ecore_evas, _on_canvas_resize);
232 ecore_evas_show(ecore_evas);
233
234 evas = ecore_evas_get(ecore_evas);
235
236 _scene_setup(&data);
237
238 /* Add a background rectangle object. */
239 background = efl_add(EFL_CANVAS_RECTANGLE_CLASS, evas);
240 efl_gfx_color_set(background, 0, 0, 0, 255);
241 efl_gfx_entity_size_set(background, EINA_SIZE2D(WIDTH, HEIGHT));
242 efl_gfx_entity_visible_set(background, EINA_TRUE);
243
244 /* Add an image object for 3D scene rendering. */
245 image = efl_add(EFL_CANVAS_SCENE3D_CLASS, evas);
246 efl_gfx_entity_size_set(image, EINA_SIZE2D(WIDTH, HEIGHT));
247 efl_gfx_entity_visible_set(image, EINA_TRUE);
248
249 /* Set the image object as render target for 3D scene. */
250 efl_canvas_scene3d_set(image, data.scene);
251
252 /* Add animation timer callback. */
253 ecore_timer_add(0.016, _animate_scene, &data);
254
255 /* Enter main loop. */
256 ecore_main_loop_begin();
257
258 ecore_evas_free(ecore_evas);
259 ecore_evas_shutdown();
260
261 return 0;
262}
diff --git a/src/examples/evas/evas-3d-cube2.c b/src/examples/evas/evas-3d-cube2.c
deleted file mode 100644
index 026b90a5a0..0000000000
--- a/src/examples/evas/evas-3d-cube2.c
+++ /dev/null
@@ -1,258 +0,0 @@
1/**
2 * Example of frame interpolation animation with normal mapping in Evas 3D.
3 *
4 * @verbatim
5 * gcc -o evas-3d-cube2 evas-3d-cube2.c `pkg-config --libs --cflags efl evas ecore ecore-evas eo` -lm
6 * @endverbatim
7 */
8
9#ifdef HAVE_CONFIG_H
10#include "config.h"
11#else
12#define PACKAGE_EXAMPLES_DIR "."
13#define EFL_BETA_API_SUPPORT
14#endif
15
16#include <Eo.h>
17#include <Evas.h>
18#include <Ecore.h>
19#include <Ecore_Evas.h>
20#include "evas-common.h"
21
22#define WIDTH 400
23#define HEIGHT 400
24
25static const char *normal_map_path = PACKAGE_EXAMPLES_DIR EVAS_IMAGE_FOLDER "/normal_lego.png";
26
27typedef struct _Scene_Data
28{
29 Eo *scene;
30 Eo *root_node;
31 Eo *camera_node;
32 Eo *light_node;
33 Eo *mesh_node;
34
35 Eo *camera;
36 Eo *light;
37 Eo *cube;
38 Eo *mesh;
39 Eo *material0;
40 Eo *material1;
41
42 Eo *texture0;
43 Eo *texture1;
44 Eo *texture_normal;
45} Scene_Data;
46
47static Ecore_Evas *ecore_evas = NULL;
48static Evas *evas = NULL;
49static Eo *background = NULL;
50static Eo *image = NULL;
51
52static const unsigned int pixels0[] =
53{
54 0xff0000ff, 0xff0000ff, 0xffff0000, 0xffff0000,
55 0xff0000ff, 0xff0000ff, 0xffff0000, 0xffff0000,
56 0xff00ff00, 0xff00ff00, 0xff000000, 0xff000000,
57 0xff00ff00, 0xff00ff00, 0xff000000, 0xff000000,
58};
59
60static const unsigned int pixels1[] =
61{
62 0xffff0000, 0xffff0000, 0xff00ff00, 0xff00ff00,
63 0xffff0000, 0xffff0000, 0xff00ff00, 0xff00ff00,
64 0xff0000ff, 0xff0000ff, 0xffffffff, 0xffffffff,
65 0xff0000ff, 0xff0000ff, 0xffffffff, 0xffffffff,
66};
67
68static void
69_on_delete(Ecore_Evas *ee EINA_UNUSED)
70{
71 ecore_main_loop_quit();
72}
73
74static void
75_on_canvas_resize(Ecore_Evas *ee)
76{
77 int w, h;
78
79 ecore_evas_geometry_get(ee, NULL, NULL, &w, &h);
80 efl_gfx_entity_size_set(background, EINA_SIZE2D(w, h));
81 efl_gfx_entity_size_set(image, EINA_SIZE2D(w, h));
82}
83
84static Eina_Bool
85_animate_scene(void *data)
86{
87 static float angle = 0.0f;
88 static int frame = 0;
89 static int inc = 1;
90 Scene_Data *scene = (Scene_Data *)data;
91
92 angle += 0.2;
93
94 evas_canvas3d_node_orientation_angle_axis_set(scene->mesh_node, angle, 1.0, 1.0, 1.0);
95
96 /* Rotate */
97 if (angle > 360.0) angle -= 360.0f;
98
99 frame += inc;
100
101 if (frame >= 20) inc = -1;
102 else if (frame <= 0) inc = 1;
103
104 evas_canvas3d_node_mesh_frame_set(scene->mesh_node, scene->mesh, frame);
105
106 return EINA_TRUE;
107}
108
109static void
110_camera_setup(Scene_Data *data)
111{
112 data->camera = efl_add(EVAS_CANVAS3D_CAMERA_CLASS, evas);
113 evas_canvas3d_camera_projection_perspective_set(data->camera, 60.0, 1.0, 2.0, 50.0);
114
115 data->camera_node =
116 efl_add(EVAS_CANVAS3D_NODE_CLASS, evas, evas_canvas3d_node_type_set(efl_added, EVAS_CANVAS3D_NODE_TYPE_CAMERA));
117 evas_canvas3d_node_camera_set(data->camera_node, data->camera);
118 evas_canvas3d_node_position_set(data->camera_node, 0.0, 0.0, 3.0);
119 evas_canvas3d_node_look_at_set(data->camera_node, EVAS_CANVAS3D_SPACE_PARENT, 0.0, 0.0, 0.0, EVAS_CANVAS3D_SPACE_PARENT, 0.0, 1.0, 0.0);
120 evas_canvas3d_node_member_add(data->root_node, data->camera_node);
121}
122
123static void
124_light_setup(Scene_Data *data)
125{
126 data->light = efl_add(EVAS_CANVAS3D_LIGHT_CLASS, evas);
127 evas_canvas3d_light_ambient_set(data->light, 0.2, 0.2, 0.2, 1.0);
128 evas_canvas3d_light_diffuse_set(data->light, 1.0, 1.0, 1.0, 1.0);
129 evas_canvas3d_light_specular_set(data->light, 1.0, 1.0, 1.0, 1.0);
130
131 data->light_node =
132 efl_add(EVAS_CANVAS3D_NODE_CLASS, evas, evas_canvas3d_node_type_set(efl_added, EVAS_CANVAS3D_NODE_TYPE_LIGHT));
133 evas_canvas3d_node_light_set(data->light_node, data->light);
134 evas_canvas3d_node_position_set(data->light_node, 0.0, 0.0, 10.0);
135 evas_canvas3d_node_look_at_set(data->light_node, EVAS_CANVAS3D_SPACE_PARENT, 0.0, 0.0, 0.0, EVAS_CANVAS3D_SPACE_PARENT, 0.0, 1.0, 0.0);
136 evas_canvas3d_node_member_add(data->root_node, data->light_node);
137}
138
139static void
140_mesh_setup(Scene_Data *data)
141{
142 /* Setup material. */
143 data->material0 = efl_add(EVAS_CANVAS3D_MATERIAL_CLASS, evas);
144 data->material1 = efl_add(EVAS_CANVAS3D_MATERIAL_CLASS, evas);
145
146 evas_canvas3d_material_enable_set(data->material0, EVAS_CANVAS3D_MATERIAL_ATTRIB_AMBIENT, EINA_TRUE);
147 evas_canvas3d_material_enable_set(data->material0, EVAS_CANVAS3D_MATERIAL_ATTRIB_DIFFUSE, EINA_TRUE);
148 evas_canvas3d_material_enable_set(data->material0, EVAS_CANVAS3D_MATERIAL_ATTRIB_SPECULAR, EINA_TRUE);
149 evas_canvas3d_material_enable_set(data->material0, EVAS_CANVAS3D_MATERIAL_ATTRIB_NORMAL, EINA_TRUE);
150 evas_canvas3d_material_color_set(data->material0, EVAS_CANVAS3D_MATERIAL_ATTRIB_AMBIENT, 0.2, 0.2, 0.2, 1.0);
151 evas_canvas3d_material_color_set(data->material0, EVAS_CANVAS3D_MATERIAL_ATTRIB_DIFFUSE, 0.8, 0.8, 0.8, 1.0);
152 evas_canvas3d_material_color_set(data->material0, EVAS_CANVAS3D_MATERIAL_ATTRIB_SPECULAR, 1.0, 1.0, 1.0, 1.0);
153 evas_canvas3d_material_shininess_set(data->material0, 100.0);
154
155 evas_canvas3d_material_enable_set(data->material1, EVAS_CANVAS3D_MATERIAL_ATTRIB_AMBIENT, EINA_TRUE);
156 evas_canvas3d_material_enable_set(data->material1, EVAS_CANVAS3D_MATERIAL_ATTRIB_DIFFUSE, EINA_TRUE);
157 evas_canvas3d_material_enable_set(data->material1, EVAS_CANVAS3D_MATERIAL_ATTRIB_SPECULAR, EINA_TRUE);
158 evas_canvas3d_material_enable_set(data->material1, EVAS_CANVAS3D_MATERIAL_ATTRIB_NORMAL, EINA_TRUE);
159 evas_canvas3d_material_color_set(data->material1, EVAS_CANVAS3D_MATERIAL_ATTRIB_AMBIENT, 0.2, 0.2, 0.2, 1.0);
160 evas_canvas3d_material_color_set(data->material1, EVAS_CANVAS3D_MATERIAL_ATTRIB_DIFFUSE, 0.8, 0.8, 0.8, 1.0);
161 evas_canvas3d_material_color_set(data->material1, EVAS_CANVAS3D_MATERIAL_ATTRIB_SPECULAR, 1.0, 1.0, 1.0, 1.0);
162 evas_canvas3d_material_shininess_set(data->material1, 100.0);
163
164 data->texture0 = efl_add(EVAS_CANVAS3D_TEXTURE_CLASS, evas);
165 data->texture1 = efl_add(EVAS_CANVAS3D_TEXTURE_CLASS, evas);
166 data->texture_normal = efl_add(EVAS_CANVAS3D_TEXTURE_CLASS, evas);
167
168 evas_canvas3d_texture_data_set(data->texture0, EVAS_COLORSPACE_ARGB8888, 4, 4, &pixels0[0]);
169 evas_canvas3d_texture_data_set(data->texture1, EVAS_COLORSPACE_ARGB8888, 4, 4, &pixels1[0]);
170 efl_file_simple_load(data->texture_normal, normal_map_path, NULL);
171
172 evas_canvas3d_material_texture_set(data->material0, EVAS_CANVAS3D_MATERIAL_ATTRIB_DIFFUSE, data->texture0);
173 evas_canvas3d_material_texture_set(data->material1, EVAS_CANVAS3D_MATERIAL_ATTRIB_DIFFUSE, data->texture1);
174 evas_canvas3d_material_texture_set(data->material1, EVAS_CANVAS3D_MATERIAL_ATTRIB_NORMAL, data->texture_normal);
175
176 /* Set data of primitive */
177 data->cube = efl_add(EVAS_CANVAS3D_PRIMITIVE_CLASS, evas);
178 evas_canvas3d_primitive_form_set(data->cube, EVAS_CANVAS3D_MESH_PRIMITIVE_CUBE);
179
180 /* Setup mesh. */
181 data->mesh = efl_add(EVAS_CANVAS3D_MESH_CLASS, evas);
182 evas_canvas3d_mesh_from_primitive_set(data->mesh, 0, data->cube);
183 evas_canvas3d_mesh_frame_material_set(data->mesh, 0, data->material0);
184 evas_canvas3d_mesh_frame_add(data->mesh, 20);
185 evas_canvas3d_mesh_frame_material_set(data->mesh, 20, data->material1);
186 evas_canvas3d_mesh_shader_mode_set(data->mesh, EVAS_CANVAS3D_SHADER_MODE_NORMAL_MAP);
187
188 data->mesh_node =
189 efl_add(EVAS_CANVAS3D_NODE_CLASS, evas, evas_canvas3d_node_type_set(efl_added, EVAS_CANVAS3D_NODE_TYPE_MESH));
190 evas_canvas3d_node_member_add(data->root_node, data->mesh_node);
191 evas_canvas3d_node_mesh_add(data->mesh_node, data->mesh);
192}
193
194static void
195_scene_setup(Scene_Data *data)
196{
197 data->scene = efl_add(EVAS_CANVAS3D_SCENE_CLASS, evas);
198 evas_canvas3d_scene_size_set(data->scene, WIDTH, HEIGHT);
199 evas_canvas3d_scene_background_color_set(data->scene, 0.0, 0.0, 0.0, 0.0);
200
201 data->root_node =
202 efl_add(EVAS_CANVAS3D_NODE_CLASS, evas, evas_canvas3d_node_type_set(efl_added, EVAS_CANVAS3D_NODE_TYPE_NODE));
203
204 _camera_setup(data);
205 _light_setup(data);
206 _mesh_setup(data);
207
208 evas_canvas3d_scene_root_node_set(data->scene, data->root_node);
209 evas_canvas3d_scene_camera_node_set(data->scene, data->camera_node);
210}
211
212int
213main(void)
214{
215 // Unless Evas 3D supports Software renderer, we force use of the gl backend.
216 putenv("ECORE_EVAS_ENGINE=opengl_x11");
217
218 Scene_Data data;
219
220 if (!ecore_evas_init()) return 0;
221
222 ecore_evas = ecore_evas_new(NULL, 10, 10, WIDTH, HEIGHT, NULL);
223
224 if (!ecore_evas) return 0;
225
226 ecore_evas_callback_delete_request_set(ecore_evas, _on_delete);
227 ecore_evas_callback_resize_set(ecore_evas, _on_canvas_resize);
228 ecore_evas_show(ecore_evas);
229
230 evas = ecore_evas_get(ecore_evas);
231
232 _scene_setup(&data);
233
234 /* Add a background rectangle object. */
235 background = efl_add(EFL_CANVAS_RECTANGLE_CLASS, evas);
236 efl_gfx_color_set(background, 0, 0, 0, 255);
237 efl_gfx_entity_size_set(background, EINA_SIZE2D(WIDTH, HEIGHT));
238 efl_gfx_entity_visible_set(background, EINA_TRUE);
239
240 /* Add an image object for 3D scene rendering. */
241 image = efl_add(EFL_CANVAS_SCENE3D_CLASS, evas);
242 efl_gfx_entity_size_set(image, EINA_SIZE2D(WIDTH, HEIGHT));
243 efl_gfx_entity_visible_set(image, EINA_TRUE);
244
245 /* Set the image object as render target for 3D scene. */
246 efl_canvas_scene3d_set(image, data.scene);
247
248 /* Add animation timer callback. */
249 ecore_timer_add(0.01, _animate_scene, &data);
250
251 /* Enter main loop. */
252 ecore_main_loop_begin();
253
254 ecore_evas_free(ecore_evas);
255 ecore_evas_shutdown();
256
257 return 0;
258}
diff --git a/src/examples/evas/evas-3d-eet.c b/src/examples/evas/evas-3d-eet.c
deleted file mode 100644
index 0272de7db2..0000000000
--- a/src/examples/evas/evas-3d-eet.c
+++ /dev/null
@@ -1,210 +0,0 @@
1/**
2 * Example of .eet file format import/export in Evas-3D.
3 *
4 * Take mesh from md2.
5 * Set material to it.
6 * Show it in left side.
7 * Save the first frame of this mesh to eet. (static only)
8 * Take result to another mesh from eet.
9 * Show it in right side.
10 *
11 * @verbatim
12 * gcc -o evas-3d-eet evas-3d-eet.c `pkg-config --libs --cflags efl eina evas ecore ecore-evas ecore-file eo`
13 * @endverbatim
14 */
15
16#ifdef HAVE_CONFIG_H
17#include "config.h"
18#else
19#define PACKAGE_EXAMPLES_DIR "."
20#define EFL_BETA_API_SUPPORT
21#endif
22
23#include <Eo.h>
24#include <Evas.h>
25#include <Ecore.h>
26#include <Ecore_Evas.h>
27#include <Ecore_File.h>
28#include "evas-common.h"
29
30#define WIDTH 1024
31#define HEIGHT 1024
32
33static const char *input_model_path = PACKAGE_EXAMPLES_DIR EVAS_MODEL_FOLDER "/sonic.md2";
34static const char *output_model_path = PACKAGE_EXAMPLES_DIR EVAS_SAVED_FILES "/saved_Sonic_EET.eet";
35
36Ecore_Evas *ecore_evas = NULL;
37Evas *evas = NULL;
38Eo *background = NULL;
39Eo *image = NULL;
40Eo *scene = NULL;
41Eo *root_node = NULL;
42Eo *camera_node = NULL;
43Eo *light_node = NULL;
44Eo *camera = NULL;
45Eo *mesh_node = NULL;
46Eo *mesh = NULL;
47Eo *mesh_node2 = NULL;
48Eo *mesh2 = NULL;
49Eo *material = NULL;
50Eo *light = NULL;
51
52static float angle = 0;
53
54static Eina_Bool
55_animate_eet(void *data)
56{
57 angle += 0.5;
58
59 evas_canvas3d_node_orientation_angle_axis_set((Evas_Canvas3D_Node *)data, angle, 1.0, 1.0, 1.0);
60
61 /* Rotate */
62 if (angle > 360.0) angle -= 360.0f;
63
64 return EINA_TRUE;
65}
66
67static Eina_Bool
68_animate_md2(void *data)
69{
70 static int frame = 0;
71
72 evas_canvas3d_node_mesh_frame_set((Evas_Canvas3D_Node *)data, mesh, frame);
73
74 frame += 32;
75
76 if (frame > 256 * 50) frame = 0;
77
78 return EINA_TRUE;
79}
80
81static void
82_on_delete(Ecore_Evas *ee EINA_UNUSED)
83{
84 ecore_main_loop_quit();
85}
86
87static void
88_on_canvas_resize(Ecore_Evas *ee)
89{
90 int w, h;
91
92 ecore_evas_geometry_get(ee, NULL, NULL, &w, &h);
93 efl_gfx_entity_size_set(background, EINA_SIZE2D(w, h));
94 efl_gfx_entity_size_set(image, EINA_SIZE2D(w, h));
95}
96
97int
98main(void)
99{
100 // Unless Evas 3D supports Software renderer, we force use of the gl backend.
101 putenv("ECORE_EVAS_ENGINE=opengl_x11");
102
103 if (!ecore_evas_init()) return 0;
104
105 ecore_evas = ecore_evas_new(NULL, 10, 10, WIDTH, HEIGHT, NULL);
106
107 if (!ecore_evas) return 0;
108
109 ecore_evas_callback_delete_request_set(ecore_evas, _on_delete);
110 ecore_evas_callback_resize_set(ecore_evas, _on_canvas_resize);
111 ecore_evas_show(ecore_evas);
112
113 evas = ecore_evas_get(ecore_evas);
114
115 /* Add a scene object .*/
116 scene = efl_add(EVAS_CANVAS3D_SCENE_CLASS, evas);
117
118 /* Add the root node for the scene. */
119 root_node = efl_add(EVAS_CANVAS3D_NODE_CLASS, evas, evas_canvas3d_node_type_set(efl_added, EVAS_CANVAS3D_NODE_TYPE_NODE));
120
121 /* Add the camera. */
122 camera = efl_add(EVAS_CANVAS3D_CAMERA_CLASS, evas);
123 evas_canvas3d_camera_projection_perspective_set(camera, 60.0, 1.0, 1.0, 500.0);
124
125 camera_node = efl_add(EVAS_CANVAS3D_NODE_CLASS, evas, evas_canvas3d_node_type_set(efl_added, EVAS_CANVAS3D_NODE_TYPE_CAMERA));
126 evas_canvas3d_node_camera_set(camera_node, camera);
127 evas_canvas3d_node_member_add(root_node, camera_node);
128 evas_canvas3d_node_position_set(camera_node, 200.0, 0.0, 40.0);
129 evas_canvas3d_node_look_at_set(camera_node, EVAS_CANVAS3D_SPACE_PARENT, 0.0, 0.0, 20.0, EVAS_CANVAS3D_SPACE_PARENT, 0.0, 0.0, 1.0);
130 /* Add the light. */
131 light = efl_add(EVAS_CANVAS3D_LIGHT_CLASS, evas);
132 evas_canvas3d_light_ambient_set(light, 1.0, 1.0, 1.0, 1.0);
133 evas_canvas3d_light_diffuse_set(light, 1.0, 1.0, 1.0, 1.0);
134 evas_canvas3d_light_specular_set(light, 1.0, 1.0, 1.0, 1.0);
135 evas_canvas3d_light_directional_set(light, EINA_TRUE);
136
137 light_node = efl_add(EVAS_CANVAS3D_NODE_CLASS, evas, evas_canvas3d_node_type_set(efl_added, EVAS_CANVAS3D_NODE_TYPE_LIGHT));
138 evas_canvas3d_node_light_set(light_node, light);
139 evas_canvas3d_node_position_set(light_node, 1000.0, 0.0, 1000.0);
140 evas_canvas3d_node_look_at_set(light_node, EVAS_CANVAS3D_SPACE_PARENT, 0.0, 0.0, 0.0, EVAS_CANVAS3D_SPACE_PARENT, 0.0, 1.0, 0.0);
141 evas_canvas3d_node_member_add(root_node, light_node);
142
143 /* Add the meshes. */
144 mesh = efl_add(EVAS_CANVAS3D_MESH_CLASS, evas);
145 mesh2 = efl_add(EVAS_CANVAS3D_MESH_CLASS, evas);
146 material = efl_add(EVAS_CANVAS3D_MATERIAL_CLASS, evas);
147
148 efl_file_simple_load(mesh, input_model_path, NULL);
149 evas_canvas3d_mesh_frame_material_set(mesh, 0, material);
150 evas_canvas3d_mesh_shader_mode_set(mesh, EVAS_CANVAS3D_SHADER_MODE_PHONG);
151
152 evas_canvas3d_material_enable_set(material, EVAS_CANVAS3D_MATERIAL_ATTRIB_AMBIENT, EINA_TRUE);
153 evas_canvas3d_material_enable_set(material, EVAS_CANVAS3D_MATERIAL_ATTRIB_DIFFUSE, EINA_TRUE);
154 evas_canvas3d_material_enable_set(material, EVAS_CANVAS3D_MATERIAL_ATTRIB_SPECULAR, EINA_TRUE);
155 evas_canvas3d_material_enable_set(material, EVAS_CANVAS3D_MATERIAL_ATTRIB_NORMAL, EINA_TRUE);
156 evas_canvas3d_material_color_set(material, EVAS_CANVAS3D_MATERIAL_ATTRIB_AMBIENT, 0.50, 0.50, 0.00, 0.30);
157 evas_canvas3d_material_color_set(material, EVAS_CANVAS3D_MATERIAL_ATTRIB_DIFFUSE, 0.00, 0.50, 0.50, 0.30);
158 evas_canvas3d_material_color_set(material, EVAS_CANVAS3D_MATERIAL_ATTRIB_SPECULAR, 0.50, 0.00, 0.50, 0.30);
159 evas_canvas3d_material_shininess_set(material, 50.0);
160
161 if (!ecore_file_mkpath(PACKAGE_EXAMPLES_DIR EVAS_SAVED_FILES))
162 fprintf(stderr, "Failed to create folder %s\n\n",
163 PACKAGE_EXAMPLES_DIR EVAS_SAVED_FILES);
164
165 efl_file_save(mesh, output_model_path, NULL, NULL);
166
167 efl_file_simple_load(mesh2, output_model_path, NULL);
168 evas_canvas3d_mesh_shader_mode_set(mesh2, EVAS_CANVAS3D_SHADER_MODE_PHONG);
169
170 mesh_node = efl_add(EVAS_CANVAS3D_NODE_CLASS, evas, evas_canvas3d_node_type_set(efl_added, EVAS_CANVAS3D_NODE_TYPE_MESH));
171
172 evas_canvas3d_node_member_add(root_node, mesh_node);
173 evas_canvas3d_node_mesh_add(mesh_node, mesh);
174 evas_canvas3d_node_position_set(mesh_node, 0.0, -40.0, 0.0);
175
176 mesh_node2 = efl_add(EVAS_CANVAS3D_NODE_CLASS, evas, evas_canvas3d_node_type_set(efl_added, EVAS_CANVAS3D_NODE_TYPE_MESH));
177 evas_canvas3d_node_member_add(root_node, mesh_node2);
178 evas_canvas3d_node_mesh_add(mesh_node2, mesh2);
179 evas_canvas3d_node_position_set(mesh_node2, 0.0, 40.0, 0.0);
180
181 /* Set up scene. */
182 evas_canvas3d_scene_root_node_set(scene, root_node);
183 evas_canvas3d_scene_camera_node_set(scene, camera_node);
184 evas_canvas3d_scene_size_set(scene, WIDTH, HEIGHT);
185
186 /* Add a background rectangle object. */
187 background = efl_add(EFL_CANVAS_RECTANGLE_CLASS, evas);
188 efl_gfx_color_set(background, 0, 0, 0, 255);
189 efl_gfx_entity_size_set(background, EINA_SIZE2D(WIDTH, HEIGHT));
190 efl_gfx_entity_visible_set(background, EINA_TRUE);
191
192 /* Add an image object for 3D scene rendering. */
193 image = efl_add(EFL_CANVAS_SCENE3D_CLASS, evas);
194 efl_gfx_entity_size_set(image, EINA_SIZE2D(WIDTH, HEIGHT));
195 efl_gfx_entity_visible_set(image, EINA_TRUE);
196
197 /* Set the image object as render target for 3D scene. */
198 efl_canvas_scene3d_set(image, scene);
199
200 ecore_timer_add(0.01, _animate_md2, mesh_node);
201 ecore_timer_add(0.01, _animate_eet, mesh_node2);
202
203 /* Enter main loop. */
204 ecore_main_loop_begin();
205
206 ecore_evas_free(ecore_evas);
207 ecore_evas_shutdown();
208
209 return 0;
210}
diff --git a/src/examples/evas/evas-3d-fog.c b/src/examples/evas/evas-3d-fog.c
deleted file mode 100644
index ec27d632c2..0000000000
--- a/src/examples/evas/evas-3d-fog.c
+++ /dev/null
@@ -1,238 +0,0 @@
1/**
2 * Example of applying a fog effect in Evas-3D.
3 *
4 * @verbatim
5 * gcc -o evas-3d-fog evas-3d-fog.c `pkg-config --libs --cflags efl evas ecore ecore-evas eo` -lm
6 * @endverbatim
7 */
8
9#ifdef HAVE_CONFIG_H
10#include "config.h"
11#else
12#define EFL_BETA_API_SUPPORT
13#endif
14
15#include <math.h>
16#include <Eo.h>
17#include <Evas.h>
18#include <Ecore.h>
19#include <Ecore_Evas.h>
20
21#define WIDTH 1024
22#define HEIGHT 1024
23#define FOG_COLOR 0.5, 0.5, 0.5
24#define FOG_FACTOR 0.2
25
26typedef struct _Scene_Data
27{
28 Eo *scene;
29 Eo *root_node;
30 Eo *camera_node;
31 Eo *light_node;
32 Eo *mesh_node;
33 Eo *mesh_node1;
34 Eo *animation_node;
35 Eo *sphere;
36
37 Eo *camera;
38 Eo *light;
39 Eo *mesh;
40 Eo *mesh1;
41 Eo *material;
42} Scene_Data;
43
44Ecore_Evas *ecore_evas = NULL;
45Evas *evas = NULL;
46Eo *background = NULL;
47Eo *image = NULL;
48
49static void
50_on_delete(Ecore_Evas *ee EINA_UNUSED)
51{
52 ecore_main_loop_quit();
53}
54
55static void
56_on_canvas_resize(Ecore_Evas *ee)
57{
58 int w, h;
59
60 ecore_evas_geometry_get(ee, NULL, NULL, &w, &h);
61
62 evas_object_resize(background, w, h);
63 efl_gfx_entity_size_set(background, EINA_SIZE2D(w, h));
64 efl_gfx_entity_size_set(image, EINA_SIZE2D(w, h));
65}
66
67static Eina_Bool
68_animate_scene(void *data)
69{
70 static float angle = 0.0f;
71 Scene_Data *scene = (Scene_Data *)data;
72
73 angle += 0.5;
74
75 evas_canvas3d_node_orientation_angle_axis_set(scene->animation_node, angle, 0.0, 1.0, 0.0);
76
77 if (angle > 360.0) angle -= 360.0f;
78
79 return EINA_TRUE;
80}
81
82static void
83_camera_setup(Scene_Data *data)
84{
85 data->camera = efl_add(EVAS_CANVAS3D_CAMERA_CLASS, evas);
86
87 evas_canvas3d_camera_projection_perspective_set(data->camera, 60.0, 1.0, 2.0, 50.0);
88
89 data->camera_node =
90 efl_add(EVAS_CANVAS3D_NODE_CLASS, evas, evas_canvas3d_node_type_set(efl_added, EVAS_CANVAS3D_NODE_TYPE_CAMERA));
91
92 evas_canvas3d_node_camera_set(data->camera_node, data->camera);
93 evas_canvas3d_node_position_set(data->camera_node, 0.0, 0.0, 7.0);
94 evas_canvas3d_node_look_at_set(data->camera_node, EVAS_CANVAS3D_SPACE_PARENT, 0.0, 0.0, 0.0, EVAS_CANVAS3D_SPACE_PARENT, 0.0, 1.0, 0.0);
95
96 evas_canvas3d_node_member_add(data->root_node, data->camera_node);
97}
98
99static void
100_light_setup(Scene_Data *data)
101{
102 data->light = efl_add(EVAS_CANVAS3D_LIGHT_CLASS, evas);
103 evas_canvas3d_light_ambient_set(data->light, 0.2, 0.2, 0.2, 1.0);
104 evas_canvas3d_light_diffuse_set(data->light, 1.0, 1.0, 1.0, 1.0);
105 evas_canvas3d_light_specular_set(data->light, 1.0, 1.0, 1.0, 1.0);
106
107 data->light_node =
108 efl_add(EVAS_CANVAS3D_NODE_CLASS, evas, evas_canvas3d_node_type_set(efl_added, EVAS_CANVAS3D_NODE_TYPE_LIGHT));
109 evas_canvas3d_node_light_set(data->light_node, data->light);
110 evas_canvas3d_node_position_set(data->light_node, 0.0, 0.0, 10.0);
111 evas_canvas3d_node_look_at_set(data->light_node, EVAS_CANVAS3D_SPACE_PARENT, 0.0, 0.0, 0.0, EVAS_CANVAS3D_SPACE_PARENT, 0.0, 1.0, 0.0);
112 evas_canvas3d_node_member_add(data->root_node, data->light_node);
113}
114
115static void
116_set_ball(Eo *mesh, Eo *sphere, Evas_Canvas3D_Material *material)
117{
118 evas_canvas3d_mesh_from_primitive_set(mesh, 0, sphere);
119 evas_canvas3d_mesh_shader_mode_set(mesh, EVAS_CANVAS3D_SHADER_MODE_PHONG);
120 evas_canvas3d_mesh_frame_material_set(mesh, 0, material);
121}
122
123static void
124_mesh_setup(Scene_Data *data)
125{
126 data->material = efl_add(EVAS_CANVAS3D_MATERIAL_CLASS, evas);
127
128 evas_canvas3d_material_enable_set(data->material, EVAS_CANVAS3D_MATERIAL_ATTRIB_AMBIENT, EINA_TRUE);
129 evas_canvas3d_material_enable_set(data->material, EVAS_CANVAS3D_MATERIAL_ATTRIB_DIFFUSE, EINA_TRUE);
130 evas_canvas3d_material_enable_set(data->material, EVAS_CANVAS3D_MATERIAL_ATTRIB_SPECULAR, EINA_TRUE);
131 evas_canvas3d_material_color_set(data->material, EVAS_CANVAS3D_MATERIAL_ATTRIB_AMBIENT, 0.2, 0.2, 0.2, 1.0);
132 evas_canvas3d_material_color_set(data->material, EVAS_CANVAS3D_MATERIAL_ATTRIB_DIFFUSE, 0.8, 0.8, 0.8, 1.0);
133 evas_canvas3d_material_color_set(data->material, EVAS_CANVAS3D_MATERIAL_ATTRIB_SPECULAR, 1.0, 1.0, 1.0, 1.0);
134 evas_canvas3d_material_shininess_set(data->material, 100.0);
135
136 data->sphere = efl_add(EVAS_CANVAS3D_PRIMITIVE_CLASS, evas);
137 evas_canvas3d_primitive_form_set(data->sphere, EVAS_CANVAS3D_MESH_PRIMITIVE_SPHERE);
138 evas_canvas3d_primitive_precision_set(data->sphere, 50);
139
140 data->mesh = efl_add(EVAS_CANVAS3D_MESH_CLASS, evas);
141 data->mesh1 = efl_add(EVAS_CANVAS3D_MESH_CLASS, evas);
142
143 _set_ball(data->mesh, data->sphere, data->material);
144 _set_ball(data->mesh1, data->sphere, data->material);
145
146 data->animation_node =
147 efl_add(EVAS_CANVAS3D_NODE_CLASS, evas, evas_canvas3d_node_type_set(efl_added, EVAS_CANVAS3D_NODE_TYPE_NODE));
148
149 data->mesh_node =
150 efl_add(EVAS_CANVAS3D_NODE_CLASS, evas, evas_canvas3d_node_type_set(efl_added, EVAS_CANVAS3D_NODE_TYPE_MESH));
151
152 evas_canvas3d_node_member_add(data->animation_node, data->mesh_node);
153 evas_canvas3d_node_member_add(data->root_node, data->animation_node);
154 evas_canvas3d_node_mesh_add(data->mesh_node, data->mesh);
155 evas_canvas3d_node_position_set(data->mesh_node, 0.0, 0.0, 3.0);
156
157 data->mesh_node1 =
158 efl_add(EVAS_CANVAS3D_NODE_CLASS, evas, evas_canvas3d_node_type_set(efl_added, EVAS_CANVAS3D_NODE_TYPE_MESH));
159
160 evas_canvas3d_node_member_add(data->root_node, data->mesh_node1);
161 evas_canvas3d_node_mesh_add(data->mesh_node1, data->mesh1);
162 evas_canvas3d_node_scale_set(data->mesh_node1, 3, 3, 3);
163
164 evas_canvas3d_mesh_fog_enable_set(data->mesh, EINA_TRUE);
165 evas_canvas3d_mesh_fog_color_set(data->mesh, FOG_COLOR, FOG_FACTOR);
166 evas_canvas3d_mesh_fog_enable_set(data->mesh1, EINA_TRUE);
167 evas_canvas3d_mesh_fog_color_set(data->mesh1, FOG_COLOR, FOG_FACTOR);
168}
169
170static void
171_scene_setup(Scene_Data *data)
172{
173 data->scene = efl_add(EVAS_CANVAS3D_SCENE_CLASS, evas);
174
175 evas_canvas3d_scene_size_set(data->scene, WIDTH, HEIGHT);
176 evas_canvas3d_scene_background_color_set(data->scene, FOG_COLOR, 1);
177
178 data->root_node =
179 efl_add(EVAS_CANVAS3D_NODE_CLASS, evas, evas_canvas3d_node_type_set(efl_added, EVAS_CANVAS3D_NODE_TYPE_NODE));
180
181 _camera_setup(data);
182 _light_setup(data);
183 _mesh_setup(data);
184
185 evas_canvas3d_scene_root_node_set(data->scene, data->root_node);
186 evas_canvas3d_scene_camera_node_set(data->scene, data->camera_node);
187}
188
189int
190main(void)
191{
192 // Unless Evas 3D supports Software renderer, we force use of the gl backend.
193 putenv("ECORE_EVAS_ENGINE=opengl_x11");
194 Scene_Data data;
195 Ecore_Animator *anim;
196
197 if (!ecore_evas_init()) return 0;
198
199 ecore_evas = ecore_evas_new("opengl_x11", 10, 10, WIDTH, HEIGHT, NULL);
200
201 if (!ecore_evas) return 0;
202
203 ecore_evas_callback_delete_request_set(ecore_evas, _on_delete);
204 ecore_evas_callback_resize_set(ecore_evas, _on_canvas_resize);
205 ecore_evas_show(ecore_evas);
206
207 evas = ecore_evas_get(ecore_evas);
208
209 _scene_setup(&data);
210
211 /* Add a background rectangle object. */
212 background = efl_add(EFL_CANVAS_RECTANGLE_CLASS, evas);
213 efl_gfx_color_set(background, 0, 0, 0, 255);
214 efl_gfx_entity_size_set(background, EINA_SIZE2D(WIDTH, HEIGHT));
215 efl_gfx_entity_visible_set(background, EINA_TRUE);
216
217 /* Add an image object for 3D scene rendering. */
218 image = efl_add(EFL_CANVAS_SCENE3D_CLASS, evas);
219
220 efl_gfx_entity_size_set(image, EINA_SIZE2D(WIDTH, HEIGHT));
221 efl_gfx_entity_visible_set(image, EINA_TRUE);
222
223 /* Set the image object as render target for 3D scene. */
224 efl_canvas_scene3d_set(image, data.scene);
225
226 /* Add animation timer callback. */
227 ecore_animator_frametime_set(0.008);
228 anim = ecore_animator_add(_animate_scene, &data);
229
230 /* Enter main loop. */
231 ecore_main_loop_begin();
232
233 ecore_evas_free(ecore_evas);
234 ecore_evas_shutdown();
235 ecore_animator_del(anim);
236
237 return 0;
238}
diff --git a/src/examples/evas/evas-3d-frustum.c b/src/examples/evas/evas-3d-frustum.c
deleted file mode 100644
index 2d693fc83a..0000000000
--- a/src/examples/evas/evas-3d-frustum.c
+++ /dev/null
@@ -1,446 +0,0 @@
1/**
2 * Example of frustum culling in Evas-3D.
3 *
4 * Use 'w'/'s' key to move far frustum plane from/to the camera.
5 * Use 't'/'g' key to move near frustum plane from/to the camera.
6 * Use '1'/'2' key to set camera to the first/second position.
7 * Use '3'/'4'/'5' key to set bounding sphere/aabb/central point mode.
8 * Use 'i', 'k', 'j', 'l', 'u' and 'o' keys to move mesh node (model) in 3D.
9 * Use 'z', 'x', 'c', 'Z', 'X' and 'C' keys to change scaling constants of mesh (model).
10 * See in terminal output value distance to far plane of frustum and value of visibility of node
11 * @see evas_canvas3d_camera_node_visible_get.
12 *
13 * @verbatim
14 * gcc -o evas-3d-frustum evas-3d-frustum.c `pkg-config --libs --cflags efl evas ecore ecore-evas eo` -lm
15 * @endverbatim
16 */
17
18#ifdef HAVE_CONFIG_H
19#include "config.h"
20#else
21#define PACKAGE_EXAMPLES_DIR "."
22#define EFL_BETA_API_SUPPORT
23#endif
24
25#include <Ecore.h>
26#include <Ecore_Evas.h>
27#include <Evas.h>
28#include <Eo.h>
29#include <math.h>
30#include "evas-common.h"
31
32#define WIDTH 800
33#define HEIGHT 600
34
35static const char *texture_path = PACKAGE_EXAMPLES_DIR EVAS_IMAGE_FOLDER "/sweet_home_reversed.png";
36static const char *mesh_path = PACKAGE_EXAMPLES_DIR EVAS_MODEL_FOLDER "/sweet_home.obj";
37
38typedef struct _Scene_Data
39{
40 Eo *root_node;
41 Eo *camera_node;
42 Eo *light_node;
43 Eo *mesh_node_model;
44 Eo *mesh_node;
45 Eo *scene;
46 Eo *camera;
47 Eo *light;
48 Eo *mesh_model;
49 Eo *sphere;
50 Eo *cube;
51 Eo *mesh_sphere;
52 Eo *mesh_aabb;
53 Eo *material_model;
54 Eo *material;
55 Eo *texture_model;
56} Scene_Data;
57
58Evas *evas;
59Evas_Object *background,*image;
60Evas_Real obj_x = 0.0, obj_y = 0.0, obj_z = 0.0, obj_sc_x = 10.0, obj_sc_y = 10.0, obj_sc_z = 10.0;
61Evas_Real fleft = -5, fright = 5, fbottom = -5, fup = 5, fnear = 20, ffar = 1000;
62Evas_Real radius = 0;
63Evas_Canvas3D_Frustum_Mode key = EVAS_CANVAS3D_FRUSTUM_MODE_AABB;
64
65static void
66_show_help()
67{
68 printf("Press 'w'/'s' key to move far frustum plane from/to the camera\n");
69 printf("Press 't'/'g' key to move near frustum plane from/to the camera\n");
70 printf("Press '1'/'2' key to set camera to the first/second position\n");
71 printf("Press '3'/'4'/'5' key to set bounding sphere/aabb/central point mode\n");
72 printf("Press 'i', 'k', 'j', 'l', 'u' and 'o' keys to move mesh node in 3D\n");
73 printf("Press 'z', 'x', 'c', 'Z', 'X' and 'C' keys to change scaling constants of mesh\n");
74}
75
76static void
77_on_delete(Ecore_Evas *ee EINA_UNUSED)
78{
79 ecore_main_loop_quit();
80}
81
82static void
83_on_canvas_resize(Ecore_Evas *ee)
84{
85 int w, h;
86
87 ecore_evas_geometry_get(ee, NULL, NULL, &w, &h);
88
89 evas_object_resize(background, w, h);
90 evas_object_resize(image, w, h);
91 evas_object_move(image, 0, 0);
92}
93
94static Eina_Bool
95_redraw_bounding_object(void *data)
96{
97 Evas_Real px, py, pz, sx, sy, sz;
98 Evas_Real x0, y0, z0, x1, y1, z1, rad;
99 Scene_Data *scene = (Scene_Data *)data;
100 Eo *current_mesh;
101 Eina_List *meshes = NULL, *l;
102
103 meshes = (Eina_List *)evas_canvas3d_node_mesh_list_get(scene->mesh_node);
104 EINA_LIST_FOREACH(meshes, l, current_mesh)
105 {
106 evas_canvas3d_node_mesh_del(scene->mesh_node, current_mesh);
107 }
108
109 switch (key)
110 {
111 case EVAS_CANVAS3D_FRUSTUM_MODE_BSPHERE:
112 {
113 evas_canvas3d_node_bounding_sphere_get(scene->mesh_node_model, &x0, &y0, &z0, &rad);
114 current_mesh = scene->mesh_sphere;
115 px = x0;
116 py = y0;
117 pz = z0;
118 sx = sy = sz = 2.0 * rad;
119 break;
120 }
121 case EVAS_CANVAS3D_FRUSTUM_MODE_AABB:
122 {
123 evas_canvas3d_node_bounding_box_get(scene->mesh_node_model, &x0, &y0, &z0, &x1, &y1, &z1);
124 current_mesh = scene->mesh_aabb;
125 px = (x1 + x0) / 2;
126 py = (y1 + y0) / 2;
127 pz = (z1 + z0) / 2;
128 sx = x1 - x0;
129 sy = y1 - y0;
130 sz = z1 - z0;
131 break;
132 }
133 case EVAS_CANVAS3D_FRUSTUM_MODE_CENTRAL_POINT:
134 {
135 evas_canvas3d_node_bounding_sphere_get(scene->mesh_node_model, &x0, &y0, &z0, &rad);
136 current_mesh = scene->mesh_sphere;
137 px = x0;
138 py = y0;
139 pz = z0;
140 sx = sy = sz = 0.1 * rad;
141 break;
142 }
143 default:
144 return ECORE_CALLBACK_RENEW;
145 }
146
147 evas_canvas3d_node_mesh_add(scene->mesh_node, current_mesh);
148 evas_canvas3d_node_position_set(scene->mesh_node, px, py, pz);
149 evas_canvas3d_node_scale_set(scene->mesh_node, sx, sy, sz);
150
151 return ECORE_CALLBACK_RENEW;
152}
153
154static void
155_on_key_down(void *data, Evas *e EINA_UNUSED, Evas_Object *eo EINA_UNUSED, void *event_info)
156{
157 Scene_Data *scene = (Scene_Data *)data;
158 Evas_Event_Key_Down *ev = event_info;
159 Eina_Bool frustum;
160
161 if (!strcmp("w", ev->key))
162 {
163 ffar += 20;
164 evas_canvas3d_camera_projection_frustum_set(scene->camera, fleft, fright, fbottom, fup, fnear, ffar);
165 }
166 else if(!strcmp("s", ev->key))
167 {
168 ffar -= 20;
169 evas_canvas3d_camera_projection_frustum_set(scene->camera, fleft, fright, fbottom, fup, fnear, ffar);
170 }
171 else if(!strcmp("t", ev->key))
172 {
173 fnear += 2;
174 evas_canvas3d_camera_projection_frustum_set(scene->camera, fleft, fright, fbottom, fup, fnear, ffar);
175 }
176 else if(!strcmp("g", ev->key))
177 {
178 fnear -= 2;
179 evas_canvas3d_camera_projection_frustum_set(scene->camera, fleft, fright, fbottom, fup, fnear, ffar);
180 }
181 else if(!strcmp("i", ev->key))
182 {
183 obj_y++;
184 evas_canvas3d_node_position_set(scene->mesh_node_model, obj_x, obj_y, obj_z);
185 }
186 else if(!strcmp("k", ev->key))
187 {
188 obj_y--;
189 evas_canvas3d_node_position_set(scene->mesh_node_model, obj_x, obj_y, obj_z);
190 }
191 else if(!strcmp("o", ev->key))
192 {
193 obj_z++;
194 evas_canvas3d_node_position_set(scene->mesh_node_model, obj_x, obj_y, obj_z);
195 }
196 else if(!strcmp("u", ev->key))
197 {
198 obj_z--;
199 evas_canvas3d_node_position_set(scene->mesh_node_model, obj_x, obj_y, obj_z);
200 }
201 else if(!strcmp("l", ev->key))
202 {
203 obj_x++;
204 evas_canvas3d_node_position_set(scene->mesh_node_model, obj_x, obj_y, obj_z);
205 }
206 else if(!strcmp("j", ev->key))
207 {
208 obj_x--;
209 evas_canvas3d_node_position_set(scene->mesh_node_model, obj_x, obj_y, obj_z);
210 }
211 else if(!strcmp("z", ev->key))
212 {
213 obj_sc_y+=0.02;
214 evas_canvas3d_node_scale_set(scene->mesh_node_model, obj_sc_x, obj_sc_y, obj_sc_z);
215 }
216 else if(!strcmp("Z", ev->key))
217 {
218 obj_sc_y-=0.02;
219 evas_canvas3d_node_scale_set(scene->mesh_node_model, obj_sc_x, obj_sc_y, obj_sc_z);
220 }
221 else if(!strcmp("x", ev->key))
222 {
223 obj_sc_z+=0.02;
224 evas_canvas3d_node_scale_set(scene->mesh_node_model, obj_sc_x, obj_sc_y, obj_sc_z);
225 }
226 else if(!strcmp("X", ev->key))
227 {
228 obj_sc_z-=0.02;
229 evas_canvas3d_node_scale_set(scene->mesh_node_model, obj_sc_x, obj_sc_y, obj_sc_z);
230 }
231 else if(!strcmp("c", ev->key))
232 {
233 obj_sc_x+=0.02;
234 evas_canvas3d_node_scale_set(scene->mesh_node_model, obj_sc_x, obj_sc_y, obj_sc_z);
235 }
236 else if(!strcmp("C", ev->key))
237 {
238 obj_sc_x-=0.02;
239 evas_canvas3d_node_scale_set(scene->mesh_node_model, obj_sc_x, obj_sc_y, obj_sc_z);
240 }
241 else if(!strcmp("Return", ev->key))
242 {
243 evas_canvas3d_camera_projection_frustum_set(scene->camera, fleft, fright, fbottom, fup, fnear, ffar);
244 }
245 else if (!strcmp("1", ev->key))
246 {
247 evas_canvas3d_node_position_set(scene->camera_node, 0.0, 0.0, 300.0);
248 evas_canvas3d_node_look_at_set(scene->camera_node, EVAS_CANVAS3D_SPACE_PARENT, 0.0, 0.0, 0.0, EVAS_CANVAS3D_SPACE_PARENT, 0.0, 1.0, 0.0);
249 printf("Changed position and view of camera\n");
250 }
251 else if (!strcmp("2", ev->key))
252 {
253 evas_canvas3d_node_position_set(scene->camera_node, 300.0, 300.0, 300.0);
254 evas_canvas3d_node_look_at_set(scene->camera_node, EVAS_CANVAS3D_SPACE_PARENT, 0.0, 0.0, 0.0, EVAS_CANVAS3D_SPACE_PARENT, 0.0, 1.0, 0.0);
255 printf("Changed position and view of camera\n");
256 }
257 else if (!strcmp("3", ev->key))
258 {
259 key = EVAS_CANVAS3D_FRUSTUM_MODE_BSPHERE;
260 }
261 else if (!strcmp("4", ev->key))
262 {
263 key = EVAS_CANVAS3D_FRUSTUM_MODE_AABB;
264 }
265 else if (!strcmp("5", ev->key))
266 {
267 key = EVAS_CANVAS3D_FRUSTUM_MODE_CENTRAL_POINT;
268 }
269 else
270 {
271 _show_help();
272 }
273
274 _redraw_bounding_object(data);
275 frustum = evas_canvas3d_camera_node_visible_get(scene->camera, scene->camera_node, scene->mesh_node_model, key);
276 printf("far - %f frustum - %d radius - %f\n", ffar, frustum, radius);
277}
278
279static void
280_camera_setup(Scene_Data *data)
281{
282 data->camera = efl_add(EVAS_CANVAS3D_CAMERA_CLASS, evas);
283 data->camera_node = efl_add(EVAS_CANVAS3D_NODE_CLASS, evas, evas_canvas3d_node_type_set(efl_added, EVAS_CANVAS3D_NODE_TYPE_CAMERA));
284 evas_canvas3d_node_camera_set(data->camera_node, data->camera);
285 evas_canvas3d_node_position_set(data->camera_node, 0.0, 0.0, 300.0);
286 evas_canvas3d_node_look_at_set(data->camera_node, EVAS_CANVAS3D_SPACE_PARENT, 0.0, 0.0, 0.0, EVAS_CANVAS3D_SPACE_PARENT, 0.0, 1.0, 0.0);
287
288 evas_canvas3d_camera_projection_frustum_set(data->camera, fleft, fright, fbottom, fup, fnear, ffar);
289
290 evas_canvas3d_node_member_add(data->root_node, data->camera_node);
291}
292
293static void
294_light_setup(Scene_Data *data)
295{
296 data->light = efl_add(EVAS_CANVAS3D_LIGHT_CLASS, evas);
297 evas_canvas3d_light_ambient_set(data->light, 0.2, 0.2, 0.2, 1.0);
298 evas_canvas3d_light_diffuse_set(data->light, 1.0, 1.0, 1.0, 1.0);
299 evas_canvas3d_light_specular_set(data->light, 1.0, 1.0, 1.0, 1.0);
300
301 data->light_node = efl_add(EVAS_CANVAS3D_NODE_CLASS, evas, evas_canvas3d_node_type_set(efl_added, EVAS_CANVAS3D_NODE_TYPE_LIGHT));
302 evas_canvas3d_node_light_set(data->light_node, data->light);
303 evas_canvas3d_node_position_set(data->light_node, 0.0, 0.0, 200.0);
304 evas_canvas3d_node_look_at_set(data->light_node, EVAS_CANVAS3D_SPACE_PARENT, 0.0, 0.0, 0.0, EVAS_CANVAS3D_SPACE_PARENT, 0.0, 0.0, 1.0);
305
306 evas_canvas3d_node_member_add(data->root_node, data->light_node);
307}
308
309static void
310_mesh_setup(Scene_Data *data)
311{
312 data->material = efl_add(EVAS_CANVAS3D_MATERIAL_CLASS, evas);
313
314 evas_canvas3d_material_enable_set(data->material, EVAS_CANVAS3D_MATERIAL_ATTRIB_AMBIENT, EINA_TRUE);
315 evas_canvas3d_material_enable_set(data->material, EVAS_CANVAS3D_MATERIAL_ATTRIB_DIFFUSE, EINA_TRUE);
316 evas_canvas3d_material_enable_set(data->material, EVAS_CANVAS3D_MATERIAL_ATTRIB_SPECULAR, EINA_TRUE);
317 evas_canvas3d_material_color_set(data->material, EVAS_CANVAS3D_MATERIAL_ATTRIB_AMBIENT, 0.2, 0.2, 0.2, 1.0);
318 evas_canvas3d_material_color_set(data->material, EVAS_CANVAS3D_MATERIAL_ATTRIB_DIFFUSE, 0.8, 0.8, 0.8, 1.0);
319 evas_canvas3d_material_color_set(data->material, EVAS_CANVAS3D_MATERIAL_ATTRIB_SPECULAR, 1.0, 1.0, 1.0, 1.0);
320 evas_canvas3d_material_shininess_set(data->material, 100.0);
321
322 data->cube = efl_add(EVAS_CANVAS3D_PRIMITIVE_CLASS, evas);
323 evas_canvas3d_primitive_form_set(data->cube, EVAS_CANVAS3D_MESH_PRIMITIVE_CUBE);
324
325 data->sphere = efl_add(EVAS_CANVAS3D_PRIMITIVE_CLASS, evas);
326 evas_canvas3d_primitive_form_set(data->sphere, EVAS_CANVAS3D_MESH_PRIMITIVE_SPHERE);
327 evas_canvas3d_primitive_precision_set(data->sphere, 20);
328
329 data->mesh_aabb = efl_add(EVAS_CANVAS3D_MESH_CLASS, evas);
330 evas_canvas3d_mesh_from_primitive_set(data->mesh_aabb, 0, data->cube);
331 evas_canvas3d_mesh_vertex_assembly_set(data->mesh_aabb, EVAS_CANVAS3D_VERTEX_ASSEMBLY_LINES);
332 evas_canvas3d_mesh_shader_mode_set(data->mesh_aabb, EVAS_CANVAS3D_SHADER_MODE_DIFFUSE);
333 evas_canvas3d_mesh_frame_material_set(data->mesh_aabb, 0, data->material);
334
335 data->mesh_sphere = efl_add(EVAS_CANVAS3D_MESH_CLASS, evas);
336 evas_canvas3d_mesh_from_primitive_set(data->mesh_sphere, 0, data->sphere);
337 evas_canvas3d_mesh_vertex_assembly_set(data->mesh_sphere, EVAS_CANVAS3D_VERTEX_ASSEMBLY_LINES);
338 evas_canvas3d_mesh_shader_mode_set(data->mesh_sphere, EVAS_CANVAS3D_SHADER_MODE_DIFFUSE);
339 evas_canvas3d_mesh_frame_material_set(data->mesh_sphere, 0, data->material);
340
341 data->mesh_node =
342 efl_add(EVAS_CANVAS3D_NODE_CLASS, evas, evas_canvas3d_node_type_set(efl_added, EVAS_CANVAS3D_NODE_TYPE_MESH));
343 evas_canvas3d_node_member_add(data->root_node, data->mesh_node);
344 evas_canvas3d_node_mesh_add(data->mesh_node, data->mesh_aabb);
345}
346
347static void
348_mesh_setup_model(Scene_Data *data)
349{
350 data->mesh_model = efl_add(EVAS_CANVAS3D_MESH_CLASS, evas);
351 data->material_model = efl_add(EVAS_CANVAS3D_MATERIAL_CLASS, evas);
352 data->texture_model = efl_add(EVAS_CANVAS3D_TEXTURE_CLASS, evas);
353
354 efl_file_simple_load(data->texture_model, texture_path, NULL);
355 evas_canvas3d_texture_filter_set(data->texture_model, EVAS_CANVAS3D_TEXTURE_FILTER_NEAREST, EVAS_CANVAS3D_TEXTURE_FILTER_NEAREST);
356 evas_canvas3d_texture_wrap_set(data->texture_model, EVAS_CANVAS3D_WRAP_MODE_REPEAT, EVAS_CANVAS3D_WRAP_MODE_REPEAT);
357
358 evas_canvas3d_material_enable_set(data->material_model, EVAS_CANVAS3D_MATERIAL_ATTRIB_NORMAL, EINA_TRUE);
359 evas_canvas3d_material_enable_set(data->material_model, EVAS_CANVAS3D_MATERIAL_ATTRIB_AMBIENT, EINA_TRUE);
360 evas_canvas3d_material_enable_set(data->material_model, EVAS_CANVAS3D_MATERIAL_ATTRIB_DIFFUSE, EINA_TRUE);
361 evas_canvas3d_material_enable_set(data->material_model, EVAS_CANVAS3D_MATERIAL_ATTRIB_SPECULAR, EINA_TRUE);
362 evas_canvas3d_material_enable_set(data->material_model, EVAS_CANVAS3D_MATERIAL_ATTRIB_NORMAL, EINA_TRUE);
363 evas_canvas3d_material_color_set(data->material_model, EVAS_CANVAS3D_MATERIAL_ATTRIB_AMBIENT, 0.01, 0.01, 0.01, 1.0);
364 evas_canvas3d_material_color_set(data->material_model, EVAS_CANVAS3D_MATERIAL_ATTRIB_DIFFUSE, 1.0, 1.0, 1.0, 1.0);
365 evas_canvas3d_material_color_set(data->material_model, EVAS_CANVAS3D_MATERIAL_ATTRIB_SPECULAR, 1.0, 1.0, 1.0, 1.0);
366 evas_canvas3d_material_texture_set(data->material_model, EVAS_CANVAS3D_MATERIAL_ATTRIB_DIFFUSE, data->texture_model);
367 evas_canvas3d_material_shininess_set(data->material_model, 100.0);
368
369 efl_file_simple_load(data->mesh_model, mesh_path, NULL);
370 evas_canvas3d_mesh_frame_material_set(data->mesh_model, 0, data->material_model);
371 evas_canvas3d_mesh_shader_mode_set(data->mesh_model, EVAS_CANVAS3D_SHADER_MODE_DIFFUSE);
372}
373
374static void
375_scene_setup(Scene_Data *data)
376{
377 data->scene = efl_add(EVAS_CANVAS3D_SCENE_CLASS, evas);
378
379 data->root_node = efl_add(EVAS_CANVAS3D_NODE_CLASS, evas, evas_canvas3d_node_type_set(efl_added, EVAS_CANVAS3D_NODE_TYPE_NODE));
380
381 _light_setup(data);
382 _mesh_setup_model(data);
383 _camera_setup(data);
384
385 data->mesh_node_model = efl_add(EVAS_CANVAS3D_NODE_CLASS, evas, evas_canvas3d_node_type_set(efl_added, EVAS_CANVAS3D_NODE_TYPE_MESH));
386 evas_canvas3d_node_position_set(data->mesh_node_model, obj_x, obj_y, obj_z);
387 evas_canvas3d_node_orientation_angle_axis_set(data->mesh_node_model, -90, 1.0, 0.0, 0.0);
388 evas_canvas3d_node_scale_set(data->mesh_node_model, obj_sc_x, obj_sc_y, obj_sc_z);
389 evas_canvas3d_node_member_add(data->root_node, data->mesh_node_model);
390 evas_canvas3d_node_mesh_add(data->mesh_node_model, data->mesh_model);
391
392 _mesh_setup(data);
393
394 evas_canvas3d_scene_size_set(data->scene, WIDTH, HEIGHT);
395 evas_canvas3d_scene_background_color_set(data->scene, 0.5, 0.5, 0.5, 0.0);
396 evas_canvas3d_scene_root_node_set(data->scene, data->root_node);
397 evas_canvas3d_scene_camera_node_set(data->scene, data->camera_node);
398}
399
400int
401main(void)
402{
403 Scene_Data data;
404 Ecore_Evas *ecore_evas = NULL;
405
406 if (!ecore_evas_init()) return 0;
407
408 putenv("ECORE_EVAS_ENGINE=opengl_x11");
409 ecore_evas = ecore_evas_new("opengl_x11", 0, 0, WIDTH, HEIGHT, NULL);
410
411 if (!ecore_evas) return 0;
412
413 ecore_evas_callback_delete_request_set(ecore_evas, _on_delete);
414 ecore_evas_callback_resize_set(ecore_evas, _on_canvas_resize);
415 ecore_evas_show(ecore_evas);
416
417 evas = ecore_evas_get(ecore_evas);
418
419 _scene_setup(&data);
420
421 background = evas_object_rectangle_add(evas);
422
423 evas_object_color_set(background, 0, 0, 0, 255);
424 evas_object_move(background, 0, 0);
425 evas_object_resize(background, WIDTH, HEIGHT);
426 evas_object_show(background);
427
428 image = efl_add(EFL_CANVAS_SCENE3D_CLASS, evas);
429 evas_object_move(image, 0, 0);
430 evas_object_resize(image, WIDTH, HEIGHT);
431 evas_object_show(image);
432
433 evas_object_focus_set(image, EINA_TRUE);
434 efl_canvas_scene3d_set(image, data.scene);
435
436 _redraw_bounding_object(&data);
437 _show_help();
438
439 evas_object_event_callback_add(image, EVAS_CALLBACK_KEY_DOWN, _on_key_down, &data);
440 ecore_main_loop_begin();
441
442 ecore_evas_free(ecore_evas);
443 ecore_evas_shutdown();
444
445 return 0;
446}
diff --git a/src/examples/evas/evas-3d-hull.c b/src/examples/evas/evas-3d-hull.c
deleted file mode 100644
index a5c39752d2..0000000000
--- a/src/examples/evas/evas-3d-hull.c
+++ /dev/null
@@ -1,465 +0,0 @@
1/**
2 * Example to test convex hull models made in Evas-3D vs. Blender.
3 *
4 * The first model (from the right side) is the original model, the
5 * second one is a convex hull made in Evas-3D, and the third one is a
6 * convex hull made in Blender.
7 *
8 * Press "Right" or "Left" to switch models, the result of test (vertex count)
9 * will be printed in console window.
10 *
11 * @verbatim
12 * gcc -o evas-3d-hull evas-3d-hull.c -g `pkg-config --libs --cflags efl evas ecore ecore-evas eo eina` -lm
13 * @endverbatim
14 */
15
16#ifdef HAVE_CONFIG_H
17#include "config.h"
18#else
19#define PACKAGE_EXAMPLES_DIR "."
20#define EFL_BETA_API_SUPPORT
21#endif
22
23#include <Eo.h>
24#include <Evas.h>
25#include <Ecore.h>
26#include <Ecore_Evas.h>
27#include "evas-common.h"
28
29#define WIDTH 1024
30#define HEIGHT 1024
31#define TESTS_COUNT 8
32#define SCALE_SPHERE 2.0
33#define SCALE_TORUS 2.7
34#define SCALE_HOME 0.7
35#define SCALE_SONIC 0.08
36#define SCALE_EAGLE 0.06
37
38typedef struct _Scene_Data
39{
40 Eo *scene;
41 Eo *root_node;
42 Eo *camera_node;
43 Eo *light_node;
44 Eo *mesh_node;
45 Eo *mesh_node_convex_hull;
46 Eo *mesh_node_blender;
47
48 Eo *camera;
49 Eo *light;
50 Eo *mesh_sphere;
51 Eo *mesh_torus;
52 Eo *mesh_cube;
53 Eo *mesh_plain;
54 Eo *mesh_column;
55 Eo *mesh_home;
56 Eo *mesh_sonic;
57 Eo *mesh_eagle;
58 Eo *mesh_sphere_ch;
59 Eo *mesh_torus_ch;
60 Eo *mesh_cube_ch;
61 Eo *mesh_plain_ch;
62 Eo *mesh_column_ch;
63 Eo *mesh_home_ch;
64 Eo *mesh_sonic_ch;
65 Eo *mesh_eagle_ch;
66 Eo *mesh_blender_sphere;
67 Eo *mesh_blender_torus;
68 Eo *mesh_blender_cube;
69 Eo *mesh_blender_plain;
70 Eo *mesh_blender_column;
71 Eo *mesh_blender_home;
72 Eo *mesh_blender_sonic;
73 Eo *mesh_blender_eagle;
74 Eo *mesh_blender_test_sphere;
75 Eo *mesh_blender_test_torus;
76 Eo *mesh_blender_test_cube;
77 Eo *mesh_blender_test_plain;
78 Eo *mesh_blender_test_column;
79 Eo *mesh_blender_test_home;
80 Eo *mesh_blender_test_sonic;
81 Eo *mesh_blender_test_eagle;
82 Eo *material;
83} Scene_Data;
84
85int rr;
86
87#define MODEL_MESH_INIT(name, model, shade) \
88 data->mesh_##name = efl_add(EVAS_CANVAS3D_MESH_CLASS, evas); \
89 efl_file_simple_load(data->mesh_##name, model, NULL); \
90 evas_canvas3d_mesh_vertex_assembly_set(data->mesh_##name, EVAS_CANVAS3D_VERTEX_ASSEMBLY_TRIANGLES); \
91 evas_canvas3d_mesh_shader_mode_set(data->mesh_##name, EVAS_CANVAS3D_SHADER_MODE_##shade); \
92 evas_canvas3d_mesh_frame_material_set(data->mesh_##name, 0, data->material);
93
94#define CONVEX_HULL_MESH_INIT(name) \
95 vert = eina_inarray_new(sizeof(float), 1); \
96 ind = eina_inarray_new(sizeof(unsigned short int), 1);\
97 evas_canvas3d_mesh_convex_hull_data_get(data->mesh_##name, 0, vert, ind); \
98 vertex = (float*) vert->members;\
99 index = ind->members;\
100 data->mesh_##name##_ch = efl_add(EVAS_CANVAS3D_MESH_CLASS, evas); \
101 evas_canvas3d_mesh_vertex_count_set(data->mesh_##name##_ch, (vert->len / 10)); \
102 evas_canvas3d_mesh_frame_add(data->mesh_##name##_ch, 0); \
103 evas_canvas3d_mesh_frame_vertex_data_copy_set(data->mesh_##name##_ch, 0, EVAS_CANVAS3D_VERTEX_ATTRIB_POSITION, \
104 10 * sizeof(float), &vertex[ 0]); \
105 evas_canvas3d_mesh_frame_vertex_data_copy_set(data->mesh_##name##_ch, 0, EVAS_CANVAS3D_VERTEX_ATTRIB_NORMAL, \
106 10 * sizeof(float), &vertex[ 3]); \
107 evas_canvas3d_mesh_frame_vertex_data_copy_set(data->mesh_##name##_ch, 0, EVAS_CANVAS3D_VERTEX_ATTRIB_COLOR, \
108 10 * sizeof(float), &vertex[ 6]); \
109 evas_canvas3d_mesh_index_data_copy_set(data->mesh_##name##_ch, EVAS_CANVAS3D_INDEX_FORMAT_UNSIGNED_SHORT, \
110 ind->len, &index[0]); \
111 evas_canvas3d_mesh_vertex_assembly_set(data->mesh_##name##_ch, EVAS_CANVAS3D_VERTEX_ASSEMBLY_TRIANGLES); \
112 evas_canvas3d_mesh_shader_mode_set(data->mesh_##name##_ch, EVAS_CANVAS3D_SHADER_MODE_VERTEX_COLOR); \
113 evas_canvas3d_mesh_frame_material_set(data->mesh_##name##_ch, 0, data->material); \
114 free(vert); \
115 free(ind);
116
117#define SWITCH_MESH(index, name, scale) \
118 case index: \
119 { \
120 list = evas_canvas3d_node_mesh_list_get(scene->mesh_node); \
121 mesh = eina_list_nth(list, 0); \
122 evas_canvas3d_node_mesh_del(scene->mesh_node, mesh); \
123 evas_canvas3d_node_mesh_add(scene->mesh_node, scene->mesh_##name); \
124 evas_canvas3d_node_scale_set(scene->mesh_node, scale, scale, scale); \
125 list = evas_canvas3d_node_mesh_list_get(scene->mesh_node_convex_hull); \
126 mesh = eina_list_nth(list, 0); \
127 evas_canvas3d_node_mesh_del(scene->mesh_node_convex_hull, mesh); \
128 evas_canvas3d_node_mesh_add(scene->mesh_node_convex_hull, scene->mesh_##name##_ch); \
129 evas_canvas3d_node_scale_set(scene->mesh_node_convex_hull, scale, scale, scale); \
130 list = evas_canvas3d_node_mesh_list_get(scene->mesh_node_blender); \
131 mesh = eina_list_nth(list, 0); \
132 evas_canvas3d_node_mesh_del(scene->mesh_node_blender, mesh); \
133 evas_canvas3d_node_mesh_add(scene->mesh_node_blender, scene->mesh_blender_##name); \
134 evas_canvas3d_node_scale_set(scene->mesh_node_blender, scale, scale, scale); \
135 _print_result(scene->mesh_##name##_ch, scene->mesh_blender_test_##name); \
136 break; \
137 }
138
139static const char *home = PACKAGE_EXAMPLES_DIR EVAS_MODEL_FOLDER "/sweet_home_without_tex_coords.obj";
140static const char *sonic = PACKAGE_EXAMPLES_DIR EVAS_MODEL_FOLDER "/sonic.md2";
141static const char *eagle = PACKAGE_EXAMPLES_DIR "/shooter/assets/models/eagle.md2";
142
143static const char *column = PACKAGE_EXAMPLES_DIR EVAS_CONVEX_HULL_FOLDER "/column.ply";
144static const char *plain = PACKAGE_EXAMPLES_DIR EVAS_CONVEX_HULL_FOLDER "/plain.ply";
145static const char *plain_ch = PACKAGE_EXAMPLES_DIR EVAS_CONVEX_HULL_FOLDER "/plain_blender_ch.ply";
146static const char *sphere_ch = PACKAGE_EXAMPLES_DIR EVAS_CONVEX_HULL_FOLDER "/sphere_blender_ch.ply";
147static const char *torus_ch = PACKAGE_EXAMPLES_DIR EVAS_CONVEX_HULL_FOLDER "/torus_blender_ch.ply";
148static const char *cube_ch = PACKAGE_EXAMPLES_DIR EVAS_CONVEX_HULL_FOLDER "/cube_blender_ch.ply";
149static const char *column_ch = PACKAGE_EXAMPLES_DIR EVAS_CONVEX_HULL_FOLDER "/column_blender_ch.ply";
150static const char *home_ch = PACKAGE_EXAMPLES_DIR EVAS_CONVEX_HULL_FOLDER "/home_blender_ch.obj";
151static const char *sonic_ch = PACKAGE_EXAMPLES_DIR EVAS_CONVEX_HULL_FOLDER "/sonic_blender_ch.ply";
152static const char *eagle_ch = PACKAGE_EXAMPLES_DIR EVAS_CONVEX_HULL_FOLDER "/eagle_blender_ch.ply";
153static const char *plain_test = PACKAGE_EXAMPLES_DIR EVAS_CONVEX_HULL_FOLDER "/plain_blender_ch_test.ply";
154static const char *sphere_test = PACKAGE_EXAMPLES_DIR EVAS_CONVEX_HULL_FOLDER "/sphere_blender_ch_test.ply";
155static const char *torus_test = PACKAGE_EXAMPLES_DIR EVAS_CONVEX_HULL_FOLDER "/torus_blender_ch_test.ply";
156static const char *cube_test = PACKAGE_EXAMPLES_DIR EVAS_CONVEX_HULL_FOLDER "/cube_blender_ch_test.ply";
157static const char *column_test = PACKAGE_EXAMPLES_DIR EVAS_CONVEX_HULL_FOLDER "/column_blender_ch_test.ply";
158static const char *home_test = PACKAGE_EXAMPLES_DIR EVAS_CONVEX_HULL_FOLDER "/home_blender_ch_test.ply";
159static const char *sonic_test = PACKAGE_EXAMPLES_DIR EVAS_CONVEX_HULL_FOLDER "/sonic_blender_ch_test.ply";
160static const char *eagle_test = PACKAGE_EXAMPLES_DIR EVAS_CONVEX_HULL_FOLDER "/eagle_blender_ch_test.ply";
161
162static Ecore_Evas *ecore_evas = NULL;
163static Evas *evas = NULL;
164static Eo *background = NULL;
165static Eo *image = NULL;
166static int next_model = 0;
167
168static void
169_print_result(Evas_Canvas3D_Mesh *mesh, Evas_Canvas3D_Mesh *convex_mesh)
170{
171 int v_count = 0;
172 v_count = evas_canvas3d_mesh_vertex_count_get(mesh);
173
174 printf("Vertex count is %d for convex hull\n",
175 v_count);
176
177 v_count = evas_canvas3d_mesh_vertex_count_get(convex_mesh);
178
179 printf("Vertex count is %d for blender convex hull\n\n",
180 v_count);
181
182 return;
183}
184
185static void
186_on_delete(Ecore_Evas *ee EINA_UNUSED)
187{
188 ecore_main_loop_quit();
189}
190
191static void
192_on_canvas_resize(Ecore_Evas *ee)
193{
194 int w, h;
195
196 ecore_evas_geometry_get(ee, NULL, NULL, &w, &h);
197 efl_gfx_entity_size_set(background, EINA_SIZE2D(w, h));
198 efl_gfx_entity_size_set(image, EINA_SIZE2D(w, h));
199}
200
201static Eina_Bool
202_animate_scene(void *data)
203{
204 static float angle = 0.0f;
205 Scene_Data *scene = (Scene_Data *)data;
206
207 angle += 0.5;
208 if (angle >= 360.0)
209 angle = 0.0;
210
211 evas_canvas3d_node_orientation_angle_axis_set(scene->mesh_node, angle, 1.0, 1.0, 1.0);
212
213 evas_canvas3d_node_orientation_angle_axis_set(scene->mesh_node_convex_hull, angle, 1.0, 1.0, 1.0);
214
215 evas_canvas3d_node_orientation_angle_axis_set(scene->mesh_node_blender, angle, 1.0, 1.0, 1.0);
216
217 return EINA_TRUE;
218}
219
220static void
221_key_down(void *data,
222 Evas *e EINA_UNUSED,
223 Evas_Object *eo EINA_UNUSED,
224 void *event_info)
225{
226 const Eina_List *list = NULL;
227 Eo *mesh = NULL;
228 Evas_Event_Key_Down *ev = event_info;
229 Scene_Data *scene = (Scene_Data *)data;
230
231 if (!strcmp(ev->key, "Right"))
232 next_model++;
233 else if (!strcmp(ev->key, "Left"))
234 next_model--;
235
236 if (next_model == -1)
237 next_model = TESTS_COUNT - 1;
238 else if (next_model == TESTS_COUNT)
239 next_model = 0;
240
241 switch (next_model)
242 {
243 SWITCH_MESH(0, sphere, SCALE_SPHERE)
244 SWITCH_MESH(1, torus, SCALE_TORUS)
245 SWITCH_MESH(2, cube, 1.0)
246 SWITCH_MESH(3, plain, 1.0)
247 SWITCH_MESH(4, column, 1.0)
248 SWITCH_MESH(5, home, SCALE_HOME)
249 SWITCH_MESH(6, sonic, SCALE_SONIC)
250 SWITCH_MESH(7, eagle, SCALE_EAGLE)
251 default:
252 break;
253 }
254}
255
256static void
257_camera_setup(Scene_Data *data)
258{
259 data->camera = efl_add(EVAS_CANVAS3D_CAMERA_CLASS, evas);
260
261 evas_canvas3d_camera_projection_perspective_set(data->camera, 60.0, 1.0, 2.0, 50.0);
262
263 data->camera_node =
264 efl_add(EVAS_CANVAS3D_NODE_CLASS, evas, evas_canvas3d_node_type_set(efl_added, EVAS_CANVAS3D_NODE_TYPE_CAMERA));
265 evas_canvas3d_node_camera_set(data->camera_node, data->camera);
266 evas_canvas3d_node_position_set(data->camera_node, 0.0, 0.0, 10.0);
267 evas_canvas3d_node_look_at_set(data->camera_node, EVAS_CANVAS3D_SPACE_PARENT, 0.0, 0.0, 0.0, EVAS_CANVAS3D_SPACE_PARENT, 0.0, 1.0, 0.0);
268 evas_canvas3d_node_member_add(data->root_node, data->camera_node);
269}
270
271static void
272_light_setup(Scene_Data *data)
273{
274 data->light = efl_add(EVAS_CANVAS3D_LIGHT_CLASS, evas);
275 evas_canvas3d_light_ambient_set(data->light, 0.2, 0.2, 0.2, 1.0);
276 evas_canvas3d_light_diffuse_set(data->light, 1.0, 1.0, 1.0, 1.0);
277 evas_canvas3d_light_specular_set(data->light, 1.0, 1.0, 1.0, 1.0);
278
279 data->light_node =
280 efl_add(EVAS_CANVAS3D_NODE_CLASS, evas, evas_canvas3d_node_type_set(efl_added, EVAS_CANVAS3D_NODE_TYPE_LIGHT));
281 evas_canvas3d_node_light_set(data->light_node, data->light);
282 evas_canvas3d_node_position_set(data->light_node, 0.0, 0.0, 10.0);
283 evas_canvas3d_node_look_at_set(data->light_node, EVAS_CANVAS3D_SPACE_PARENT, 0.0, 0.0, 0.0, EVAS_CANVAS3D_SPACE_PARENT, 0.0, 1.0, 0.0);
284 evas_canvas3d_node_member_add(data->root_node, data->light_node);
285}
286
287static void
288_mesh_setup(Scene_Data *data)
289{
290 Eina_Inarray *vert, *ind;
291 float *vertex;
292 unsigned short int *index;
293 Eo *primitive = NULL;
294 /* Setup material. */
295
296 data->material = efl_add(EVAS_CANVAS3D_MATERIAL_CLASS, evas);
297 evas_canvas3d_material_enable_set(data->material, EVAS_CANVAS3D_MATERIAL_ATTRIB_AMBIENT, EINA_TRUE);
298 evas_canvas3d_material_enable_set(data->material, EVAS_CANVAS3D_MATERIAL_ATTRIB_DIFFUSE, EINA_TRUE);
299 evas_canvas3d_material_enable_set(data->material, EVAS_CANVAS3D_MATERIAL_ATTRIB_SPECULAR, EINA_TRUE);
300 evas_canvas3d_material_color_set(data->material, EVAS_CANVAS3D_MATERIAL_ATTRIB_AMBIENT, 0.2, 0.2, 0.2, 1.0);
301 evas_canvas3d_material_color_set(data->material, EVAS_CANVAS3D_MATERIAL_ATTRIB_DIFFUSE, 0.8, 0.8, 0.8, 1.0);
302 evas_canvas3d_material_color_set(data->material, EVAS_CANVAS3D_MATERIAL_ATTRIB_SPECULAR, 1.0, 1.0, 1.0, 1.0);
303 evas_canvas3d_material_shininess_set(data->material, 100.0);
304
305 /* Setup mesh sphere */
306 primitive = efl_add(EVAS_CANVAS3D_PRIMITIVE_CLASS, evas);
307 evas_canvas3d_primitive_form_set(primitive, EVAS_CANVAS3D_MESH_PRIMITIVE_SPHERE);
308 evas_canvas3d_primitive_precision_set(primitive, 10);
309 data->mesh_sphere = efl_add(EVAS_CANVAS3D_MESH_CLASS, evas);
310 evas_canvas3d_mesh_from_primitive_set(data->mesh_sphere, 0, primitive);
311 evas_canvas3d_mesh_vertex_assembly_set(data->mesh_sphere, EVAS_CANVAS3D_VERTEX_ASSEMBLY_TRIANGLES);
312 evas_canvas3d_mesh_shader_mode_set(data->mesh_sphere, EVAS_CANVAS3D_SHADER_MODE_PHONG);
313 evas_canvas3d_mesh_frame_material_set(data->mesh_sphere, 0, data->material);
314
315 /* Setup mesh torus */
316 data->mesh_torus = efl_add(EVAS_CANVAS3D_MESH_CLASS, evas);
317 evas_canvas3d_primitive_form_set(primitive, EVAS_CANVAS3D_MESH_PRIMITIVE_TORUS);
318 evas_canvas3d_primitive_precision_set(primitive, 50);
319 evas_canvas3d_mesh_from_primitive_set(data->mesh_torus, 0, primitive);
320 evas_canvas3d_mesh_vertex_assembly_set(data->mesh_torus, EVAS_CANVAS3D_VERTEX_ASSEMBLY_TRIANGLES);
321 evas_canvas3d_mesh_shader_mode_set(data->mesh_torus, EVAS_CANVAS3D_SHADER_MODE_PHONG);
322 evas_canvas3d_mesh_frame_material_set(data->mesh_torus, 0, data->material);
323
324 /* Setup mesh cube */
325 data->mesh_cube = efl_add(EVAS_CANVAS3D_MESH_CLASS, evas);
326 evas_canvas3d_primitive_form_set(primitive, EVAS_CANVAS3D_MESH_PRIMITIVE_CUBE);
327 evas_canvas3d_primitive_precision_set(primitive, 50);
328 evas_canvas3d_mesh_from_primitive_set(data->mesh_cube, 0, primitive);
329 evas_canvas3d_mesh_vertex_assembly_set(data->mesh_cube, EVAS_CANVAS3D_VERTEX_ASSEMBLY_TRIANGLES);
330 evas_canvas3d_mesh_shader_mode_set(data->mesh_cube, EVAS_CANVAS3D_SHADER_MODE_PHONG);
331 evas_canvas3d_mesh_frame_material_set(data->mesh_cube, 0, data->material);
332
333 MODEL_MESH_INIT(plain, plain, PHONG)
334 MODEL_MESH_INIT(column, column, PHONG)
335 MODEL_MESH_INIT(home, home, PHONG)
336 MODEL_MESH_INIT(sonic, sonic, PHONG)
337 MODEL_MESH_INIT(eagle, eagle, PHONG)
338
339 MODEL_MESH_INIT(blender_sphere, sphere_ch, PHONG)
340 MODEL_MESH_INIT(blender_torus, torus_ch, PHONG)
341 MODEL_MESH_INIT(blender_cube, cube_ch, PHONG)
342 MODEL_MESH_INIT(blender_plain, plain_ch, PHONG)
343 MODEL_MESH_INIT(blender_column, column_ch, PHONG)
344 MODEL_MESH_INIT(blender_home, home_ch, PHONG)
345 MODEL_MESH_INIT(blender_eagle, eagle_ch, PHONG)
346 MODEL_MESH_INIT(blender_sonic, sonic_ch, PHONG)
347
348 MODEL_MESH_INIT(blender_test_sphere, sphere_test, DIFFUSE)
349 MODEL_MESH_INIT(blender_test_torus, torus_test, DIFFUSE)
350 MODEL_MESH_INIT(blender_test_cube, cube_test, DIFFUSE)
351 MODEL_MESH_INIT(blender_test_plain, plain_test, DIFFUSE)
352 MODEL_MESH_INIT(blender_test_column, column_test, DIFFUSE)
353 MODEL_MESH_INIT(blender_test_home, home_test, DIFFUSE)
354 MODEL_MESH_INIT(blender_test_eagle, eagle_test, DIFFUSE)
355 MODEL_MESH_INIT(blender_test_sonic, sonic_test, DIFFUSE)
356
357 data->mesh_node =
358 efl_add(EVAS_CANVAS3D_NODE_CLASS, evas, evas_canvas3d_node_type_set(efl_added, EVAS_CANVAS3D_NODE_TYPE_MESH));
359 evas_canvas3d_node_member_add(data->root_node, data->mesh_node);
360 evas_canvas3d_node_mesh_add(data->mesh_node, data->mesh_sphere);
361 evas_canvas3d_node_scale_set(data->mesh_node, SCALE_SPHERE, SCALE_SPHERE, SCALE_SPHERE);
362 evas_canvas3d_node_position_set(data->mesh_node, 3.0, 0.0, 0.0);
363
364 CONVEX_HULL_MESH_INIT(sphere)
365 CONVEX_HULL_MESH_INIT(torus)
366 CONVEX_HULL_MESH_INIT(cube)
367 CONVEX_HULL_MESH_INIT(plain)
368 CONVEX_HULL_MESH_INIT(column)
369 CONVEX_HULL_MESH_INIT(home)
370 CONVEX_HULL_MESH_INIT(sonic)
371 CONVEX_HULL_MESH_INIT(eagle)
372
373 _print_result(data->mesh_sphere_ch, data->mesh_blender_test_sphere);
374
375 data->mesh_node_convex_hull =
376 efl_add(EVAS_CANVAS3D_NODE_CLASS, evas, evas_canvas3d_node_type_set(efl_added, EVAS_CANVAS3D_NODE_TYPE_MESH));
377 evas_canvas3d_node_member_add(data->root_node, data->mesh_node_convex_hull);
378 evas_canvas3d_node_position_set(data->mesh_node_convex_hull, 0.0, 0.0, 0.0);
379 evas_canvas3d_node_scale_set(data->mesh_node_convex_hull, SCALE_SPHERE, SCALE_SPHERE, SCALE_SPHERE);
380 evas_canvas3d_node_mesh_add(data->mesh_node_convex_hull, data->mesh_sphere_ch);
381
382 data->mesh_node_blender =
383 efl_add(EVAS_CANVAS3D_NODE_CLASS, evas, evas_canvas3d_node_type_set(efl_added, EVAS_CANVAS3D_NODE_TYPE_MESH));
384 evas_canvas3d_node_member_add(data->root_node, data->mesh_node_blender);
385 evas_canvas3d_node_position_set(data->mesh_node_blender, -3.0, 0.0, 0.0);
386 evas_canvas3d_node_scale_set(data->mesh_node_blender, SCALE_SPHERE, SCALE_SPHERE, SCALE_SPHERE);
387 evas_canvas3d_node_mesh_add(data->mesh_node_blender, data->mesh_blender_sphere);
388}
389
390static void
391_scene_setup(Scene_Data *data)
392{
393 data->scene = efl_add(EVAS_CANVAS3D_SCENE_CLASS, evas);
394 evas_canvas3d_scene_size_set(data->scene, WIDTH, HEIGHT);
395 evas_canvas3d_scene_background_color_set(data->scene, 0.0, 0.0, 0.0, 0.0);
396
397 data->root_node =
398 efl_add(EVAS_CANVAS3D_NODE_CLASS, evas, evas_canvas3d_node_type_set(efl_added, EVAS_CANVAS3D_NODE_TYPE_NODE));
399
400 _camera_setup(data);
401 _light_setup(data);
402 _mesh_setup(data);
403
404 evas_canvas3d_scene_root_node_set(data->scene, data->root_node);
405 evas_canvas3d_scene_camera_node_set(data->scene, data->camera_node);
406}
407
408int
409main(void)
410{
411 Ecore_Animator *anim;
412 Scene_Data data;
413
414 // Unless Evas 3D supports Software renderer, we force use of the gl backend.
415 putenv("ECORE_EVAS_ENGINE=opengl_x11");
416
417 if (!ecore_evas_init()) return 0;
418
419 printf("Loading 3d meshes. Press Left or Right to switch between models.\n");
420
421 ecore_evas = ecore_evas_new(NULL, 10, 10, WIDTH, HEIGHT, NULL);
422 if (!ecore_evas) return 0;
423
424 ecore_evas_callback_delete_request_set(ecore_evas, _on_delete);
425 ecore_evas_callback_resize_set(ecore_evas, _on_canvas_resize);
426 ecore_evas_show(ecore_evas);
427
428 evas = ecore_evas_get(ecore_evas);
429
430 _scene_setup(&data);
431
432 /* Add a background rectangle object. */
433 background = efl_add(EFL_CANVAS_RECTANGLE_CLASS, evas);
434 efl_gfx_color_set(background, 0, 0, 0, 255);
435 efl_gfx_entity_size_set(background, EINA_SIZE2D(WIDTH, HEIGHT));
436 efl_gfx_entity_visible_set(background, EINA_TRUE);
437
438 /* Add an image object for 3D scene rendering. */
439 image = efl_add(EFL_CANVAS_SCENE3D_CLASS, evas);
440 efl_gfx_entity_size_set(image, EINA_SIZE2D(WIDTH, HEIGHT));
441 efl_gfx_entity_visible_set(image, EINA_TRUE);
442
443 evas_object_show(image),
444 evas_object_focus_set(image, EINA_TRUE);
445
446 /* Set the image object as render target for 3D scene. */
447 efl_canvas_scene3d_set(image, data.scene);
448
449 evas_object_event_callback_add(image, EVAS_CALLBACK_KEY_DOWN, _key_down, &data);
450
451 /* Add animator. */
452 ecore_animator_frametime_set(0.008);
453 anim = ecore_animator_add(_animate_scene, &data);
454
455 /* Enter main loop. */
456 ecore_main_loop_begin();
457 ecore_animator_del(anim);
458
459 ecore_evas_free(ecore_evas);
460 ecore_evas_shutdown();
461
462 return 0;
463}
464
465
diff --git a/src/examples/evas/evas-3d-md2.c b/src/examples/evas/evas-3d-md2.c
deleted file mode 100644
index a4edb28833..0000000000
--- a/src/examples/evas/evas-3d-md2.c
+++ /dev/null
@@ -1,176 +0,0 @@
1/**
2 * Example of .md2 file format import in Evas-3D.
3 *
4 * @verbatim
5 * gcc -o evas-3d-md2 evas-3d-md2.c `pkg-config --libs --cflags efl evas ecore ecore-evas eo`
6 * @endverbatim
7 */
8
9#ifdef HAVE_CONFIG_H
10#include "config.h"
11#else
12#define PACKAGE_EXAMPLES_DIR "."
13#define EFL_BETA_API_SUPPORT
14#endif
15
16#include <Eo.h>
17#include <Evas.h>
18#include <Ecore.h>
19#include <Ecore_Evas.h>
20#include "evas-common.h"
21
22#define WIDTH 400
23#define HEIGHT 400
24
25static const char *model_path = PACKAGE_EXAMPLES_DIR EVAS_MODEL_FOLDER "/sonic.md2";
26static const char *image_path = PACKAGE_EXAMPLES_DIR EVAS_IMAGE_FOLDER "/sonic.png";
27
28Ecore_Evas *ecore_evas = NULL;
29Evas *evas = NULL;
30Eo *background = NULL;
31Eo *image = NULL;
32
33Eo *scene = NULL;
34Eo *root_node = NULL;
35Eo *camera_node = NULL;
36Eo *light_node = NULL;
37Eo *camera = NULL;
38Eo *mesh_node = NULL;
39Eo *mesh = NULL;
40Eo *material = NULL;
41Eo *texture = NULL;
42Eo *light = NULL;
43
44static Eina_Bool
45_animate_scene(void *data)
46{
47 static int frame = 0;
48
49 evas_canvas3d_node_mesh_frame_set((Evas_Canvas3D_Node *)data, mesh, frame);
50
51 frame += 32;
52
53 if (frame > 256 * 50) frame = 0;
54
55 return EINA_TRUE;
56}
57
58static void
59_on_delete(Ecore_Evas *ee EINA_UNUSED)
60{
61 ecore_main_loop_quit();
62}
63
64static void
65_on_canvas_resize(Ecore_Evas *ee)
66{
67 int w, h;
68
69 ecore_evas_geometry_get(ee, NULL, NULL, &w, &h);
70 efl_gfx_entity_size_set(background, EINA_SIZE2D(w, h));
71 efl_gfx_entity_size_set(image, EINA_SIZE2D(w, h));
72}
73
74int
75main(void)
76{
77 // Unless Evas 3D supports Software renderer, we force use of the gl backend.
78 putenv("ECORE_EVAS_ENGINE=opengl_x11");
79
80 if (!ecore_evas_init()) return 0;
81
82 ecore_evas = ecore_evas_new(NULL, 10, 10, WIDTH, HEIGHT, NULL);
83
84 if (!ecore_evas) return 0;
85
86 ecore_evas_callback_delete_request_set(ecore_evas, _on_delete);
87 ecore_evas_callback_resize_set(ecore_evas, _on_canvas_resize);
88 ecore_evas_show(ecore_evas);
89
90 evas = ecore_evas_get(ecore_evas);
91
92 /* Add a scene object .*/
93 scene = efl_add(EVAS_CANVAS3D_SCENE_CLASS, evas);
94
95 /* Add the root node for the scene. */
96 root_node = efl_add(EVAS_CANVAS3D_NODE_CLASS, evas, evas_canvas3d_node_type_set(efl_added, EVAS_CANVAS3D_NODE_TYPE_NODE));
97
98 /* Add the camera. */
99 camera = efl_add(EVAS_CANVAS3D_CAMERA_CLASS, evas);
100 evas_canvas3d_camera_projection_perspective_set(camera, 60.0, 1.0, 1.0, 500.0);
101
102 camera_node =
103 efl_add(EVAS_CANVAS3D_NODE_CLASS, evas, evas_canvas3d_node_type_set(efl_added, EVAS_CANVAS3D_NODE_TYPE_CAMERA));
104 evas_canvas3d_node_camera_set(camera_node, camera);
105 evas_canvas3d_node_member_add(root_node, camera_node);
106 evas_canvas3d_node_position_set(camera_node, 100.0, 0.0, 20.0);
107 evas_canvas3d_node_look_at_set(camera_node, EVAS_CANVAS3D_SPACE_PARENT, 0.0, 0.0, 20.0, EVAS_CANVAS3D_SPACE_PARENT, 0.0, 0.0, 1.0);
108 /* Add the light. */
109 light = efl_add(EVAS_CANVAS3D_LIGHT_CLASS, evas);
110 evas_canvas3d_light_ambient_set(light, 1.0, 1.0, 1.0, 1.0);
111 evas_canvas3d_light_diffuse_set(light, 1.0, 1.0, 1.0, 1.0);
112 evas_canvas3d_light_specular_set(light, 1.0, 1.0, 1.0, 1.0);
113 evas_canvas3d_light_directional_set(light, EINA_TRUE);
114
115 light_node =
116 efl_add(EVAS_CANVAS3D_NODE_CLASS, evas, evas_canvas3d_node_type_set(efl_added, EVAS_CANVAS3D_NODE_TYPE_LIGHT));
117 evas_canvas3d_node_light_set(light_node, light);
118 evas_canvas3d_node_position_set(light_node, 1000.0, 0.0, 1000.0);
119 evas_canvas3d_node_look_at_set(light_node, EVAS_CANVAS3D_SPACE_PARENT, 0.0, 0.0, 0.0, EVAS_CANVAS3D_SPACE_PARENT, 0.0, 1.0, 0.0);
120 evas_canvas3d_node_member_add(root_node, light_node);
121
122 /* Add the mesh. */
123 mesh = efl_add(EVAS_CANVAS3D_MESH_CLASS, evas);
124 material = efl_add(EVAS_CANVAS3D_MATERIAL_CLASS, evas);
125
126 efl_file_simple_load(mesh, model_path, NULL);
127 evas_canvas3d_mesh_frame_material_set(mesh, 0, material);
128 evas_canvas3d_mesh_shader_mode_set(mesh, EVAS_CANVAS3D_SHADER_MODE_PHONG);
129
130 texture = efl_add(EVAS_CANVAS3D_TEXTURE_CLASS, evas);
131 efl_file_simple_load(texture, image_path, NULL);
132 evas_canvas3d_texture_filter_set(texture, EVAS_CANVAS3D_TEXTURE_FILTER_NEAREST, EVAS_CANVAS3D_TEXTURE_FILTER_NEAREST);
133 evas_canvas3d_texture_wrap_set(texture, EVAS_CANVAS3D_WRAP_MODE_REPEAT, EVAS_CANVAS3D_WRAP_MODE_REPEAT);
134 evas_canvas3d_material_texture_set(material, EVAS_CANVAS3D_MATERIAL_ATTRIB_DIFFUSE, texture);
135 evas_canvas3d_material_enable_set(material, EVAS_CANVAS3D_MATERIAL_ATTRIB_AMBIENT, EINA_TRUE);
136 evas_canvas3d_material_enable_set(material, EVAS_CANVAS3D_MATERIAL_ATTRIB_DIFFUSE, EINA_TRUE);
137 evas_canvas3d_material_enable_set(material, EVAS_CANVAS3D_MATERIAL_ATTRIB_SPECULAR, EINA_TRUE);
138 evas_canvas3d_material_enable_set(material, EVAS_CANVAS3D_MATERIAL_ATTRIB_NORMAL, EINA_TRUE);
139 evas_canvas3d_material_color_set(material, EVAS_CANVAS3D_MATERIAL_ATTRIB_AMBIENT, 0.01, 0.01, 0.01, 1.0);
140 evas_canvas3d_material_color_set(material, EVAS_CANVAS3D_MATERIAL_ATTRIB_DIFFUSE, 1.0, 1.0, 1.0, 1.0);
141 evas_canvas3d_material_color_set(material, EVAS_CANVAS3D_MATERIAL_ATTRIB_SPECULAR, 1.0, 1.0, 1.0, 1.0);
142 evas_canvas3d_material_shininess_set(material, 50.0);
143
144 mesh_node = efl_add(EVAS_CANVAS3D_NODE_CLASS, evas, evas_canvas3d_node_type_set(efl_added, EVAS_CANVAS3D_NODE_TYPE_MESH));
145 evas_canvas3d_node_member_add(root_node, mesh_node);
146 evas_canvas3d_node_mesh_add(mesh_node, mesh);
147
148 /* Set up scene. */
149 evas_canvas3d_scene_root_node_set(scene, root_node);
150 evas_canvas3d_scene_camera_node_set(scene, camera_node);
151 evas_canvas3d_scene_size_set(scene, WIDTH, HEIGHT);
152
153 /* Add a background rectangle object. */
154 background = efl_add(EFL_CANVAS_RECTANGLE_CLASS, evas);
155 efl_gfx_color_set(background, 0, 0, 0, 255);
156 efl_gfx_entity_size_set(background, EINA_SIZE2D(WIDTH, HEIGHT));
157 efl_gfx_entity_visible_set(background, EINA_TRUE);
158
159 /* Add an image object for 3D scene rendering. */
160 image = efl_add(EFL_CANVAS_SCENE3D_CLASS, evas);
161 efl_gfx_entity_size_set(image, EINA_SIZE2D(WIDTH, HEIGHT));
162 efl_gfx_entity_visible_set(image, EINA_TRUE);
163
164 /* Set the image object as render target for 3D scene. */
165 efl_canvas_scene3d_set(image, scene);
166
167 ecore_timer_add(0.01, _animate_scene, mesh_node);
168
169 /* Enter main loop. */
170 ecore_main_loop_begin();
171
172 ecore_evas_free(ecore_evas);
173 ecore_evas_shutdown();
174
175 return 0;
176}
diff --git a/src/examples/evas/evas-3d-mmap-set.c b/src/examples/evas/evas-3d-mmap-set.c
deleted file mode 100644
index 7da515aa61..0000000000
--- a/src/examples/evas/evas-3d-mmap-set.c
+++ /dev/null
@@ -1,260 +0,0 @@
1/**
2 * Example of mmap import in Evas-3D.
3 *
4 * Open files to Eina_Files.
5 * Read meshes from Eina_Files.
6 * Show the results.
7 *
8 * @verbatim
9 * gcc -o evas-3d-mmap-set evas-3d-mmap-set.c `pkg-config --libs --cflags efl evas ecore ecore-evas eina eo` -lm
10 * @endverbatim
11 */
12
13#ifdef HAVE_CONFIG_H
14#include "config.h"
15#else
16#define PACKAGE_EXAMPLES_DIR "."
17#define EFL_BETA_API_SUPPORT
18#endif
19
20#include <Eo.h>
21#include <Evas.h>
22#include <Ecore.h>
23#include <Ecore_Evas.h>
24#include "evas-common.h"
25
26#include <math.h>
27
28#define WIDTH 1000
29#define HEIGHT 1000
30
31#define LOAD_AND_ADD_MESH(extention, number) \
32 snprintf(buffer, PATH_MAX, "%s%s", template_path, #extention); \
33 extention##_file = eina_file_open(buffer , 0); \
34 mesh_##extention = efl_add(EVAS_CANVAS3D_MESH_CLASS, evas); \
35 efl_file_simple_mmap_load(mesh_##extention, extention##_file, NULL); \
36 evas_canvas3d_mesh_frame_material_set(mesh_##extention, 0, material); \
37 evas_canvas3d_mesh_shader_mode_set(mesh_##extention, EVAS_CANVAS3D_SHADER_MODE_PHONG); \
38 node_##extention = efl_add(EVAS_CANVAS3D_NODE_CLASS, evas, evas_canvas3d_node_type_set(efl_added, EVAS_CANVAS3D_NODE_TYPE_MESH)); \
39 evas_canvas3d_node_member_add(root_node, node_##extention); \
40 evas_canvas3d_node_mesh_add(node_##extention, mesh_##extention); \
41 evas_canvas3d_node_position_set(node_##extention, initial_node_data[number * 10], \
42 initial_node_data[number * 10 + 1], \
43 initial_node_data[number * 10 + 2]); \
44 evas_canvas3d_node_scale_set(node_##extention, initial_node_data[number * 10 + 3], \
45 initial_node_data[number * 10 + 4], \
46 initial_node_data[number * 10 + 5]); \
47 evas_canvas3d_node_orientation_angle_axis_set(node_##extention, initial_node_data[number * 10 + 6], \
48 initial_node_data[number * 10 + 7], \
49 initial_node_data[number * 10 + 8], \
50 initial_node_data[number * 10 + 9]);\
51 ecore_timer_add(0.01, _animate_##extention, node_##extention);
52
53static const char *template_path = PACKAGE_EXAMPLES_DIR EVAS_MODEL_FOLDER "/mesh_for_mmap.";
54
55Ecore_Evas *ecore_evas = NULL;
56Evas *evas = NULL;
57Eo *background = NULL;
58Eo *image = NULL;
59
60Eo *scene = NULL;
61Eo *root_node = NULL;
62Eo *camera_node = NULL;
63Eo *light_node = NULL;
64Eo *camera = NULL;
65Eo *material = NULL;
66Eo *light = NULL;
67
68Eo *node_obj = NULL, *node_ply = NULL, *node_eet = NULL, *node_md2 = NULL;
69Eo *mesh_obj = NULL, *mesh_ply = NULL, *mesh_eet = NULL, *mesh_md2 = NULL;
70
71static float obj_animation_parameter = 1.0;
72static float ply_animation_parameter = 180.0;
73static float eet_animation_parameter = 0.0;
74static float md2_animation_parameter = 0.0;
75
76static float obj_animation_velocity = 1.0;
77static float ply_animation_velocity = 1.0;
78static float eet_animation_velocity = 1.0;
79static float md2_animation_velocity = 1.0;
80
81static const float initial_node_data[] =
82 /*position scale rotation*/
83{
84 /*obj*/
85 3.0, 3.0, 0.0, 1.0, 1.0, 1.0, 0.0, 1.0, 0.0, 0.0,
86 /*ply*/
87 -3.0, 3.0, 0.0, 1.0, 1.0, 1.0, 0.0, 1.0, 0.0, 0.0,
88 /*eet*/
89 3.0, -3.0, 0.0, 1.0, 1.0, 1.0, 0.0, 1.0, 0.0, 0.0,
90 /*md2*/
91 -3.0, -3.0, 0.0, 0.001, 0.001, 0.001, 180.0, 0.0, 1.0, 0.0
92};
93
94static Eina_Bool
95_animate_obj(void *data)
96{
97 obj_animation_parameter += obj_animation_velocity;
98 float oap = obj_animation_parameter/200;
99
100 evas_canvas3d_node_scale_set((Evas_Canvas3D_Node *)data, oap, oap, oap);
101 evas_canvas3d_node_orientation_angle_axis_set((Evas_Canvas3D_Node *)data, obj_animation_parameter, 0.0, 1.0, 0.0);
102
103 if (obj_animation_parameter >= 360.0 || obj_animation_parameter <= 0.0)
104 obj_animation_velocity *= -1.0;
105
106 return EINA_TRUE;
107}
108
109static Eina_Bool
110_animate_eet(void *data)
111{
112 eet_animation_parameter += eet_animation_velocity;
113
114 evas_canvas3d_node_orientation_angle_axis_set((Evas_Canvas3D_Node *)data, eet_animation_parameter, 1.0, 0.0, 0.0);
115 eet_animation_velocity = sin(eet_animation_parameter / 180 * M_PI) + 1.1;
116
117 return EINA_TRUE;
118}
119
120static Eina_Bool
121_animate_ply(void *data)
122{
123 ply_animation_parameter += ply_animation_velocity;
124
125 evas_canvas3d_node_orientation_angle_axis_set((Evas_Canvas3D_Node *)data, ply_animation_parameter, 1.0, 0.0, 0.0);
126
127 if (ply_animation_parameter > 360.0) ply_animation_parameter -= 180.0f;
128
129 return EINA_TRUE;
130}
131
132static Eina_Bool
133_animate_md2(void *data)
134{
135 md2_animation_parameter += md2_animation_velocity;
136
137 evas_canvas3d_node_mesh_frame_set((Evas_Canvas3D_Node *)data, mesh_md2, md2_animation_parameter);
138
139 if (md2_animation_parameter >= 360.0 || md2_animation_parameter <= 0.0)
140 md2_animation_velocity *= -1.0;
141
142 return EINA_TRUE;
143}
144
145static void
146_on_delete(Ecore_Evas *ee EINA_UNUSED)
147{
148 ecore_main_loop_quit();
149}
150
151static void
152_on_canvas_resize(Ecore_Evas *ee)
153{
154 int w, h;
155
156 ecore_evas_geometry_get(ee, NULL, NULL, &w, &h);
157 efl_gfx_entity_size_set(background, EINA_SIZE2D(w, h));
158 efl_gfx_entity_size_set(image, EINA_SIZE2D(w, h));
159}
160
161int
162main(void)
163{
164 char buffer[PATH_MAX];
165 Eina_File *obj_file, *ply_file, *eet_file, *md2_file;
166
167 // Unless Evas 3D supports Software renderer, we force use of the gl backend.
168 putenv("ECORE_EVAS_ENGINE=opengl_x11");
169
170 if (!ecore_evas_init()) return 0;
171
172 ecore_evas = ecore_evas_new(NULL, 10, 10, WIDTH, HEIGHT, NULL);
173
174 if (!ecore_evas) return 0;
175
176 ecore_evas_callback_delete_request_set(ecore_evas, _on_delete);
177 ecore_evas_callback_resize_set(ecore_evas, _on_canvas_resize);
178 ecore_evas_show(ecore_evas);
179
180 evas = ecore_evas_get(ecore_evas);
181
182 /* Add a scene object .*/
183 scene = efl_add(EVAS_CANVAS3D_SCENE_CLASS, evas);
184
185 /* Add the root node for the scene. */
186 root_node = efl_add(EVAS_CANVAS3D_NODE_CLASS, evas, evas_canvas3d_node_type_set(efl_added, EVAS_CANVAS3D_NODE_TYPE_NODE));
187
188 /* Add the camera. */
189 camera = efl_add(EVAS_CANVAS3D_CAMERA_CLASS, evas);
190 evas_canvas3d_camera_projection_perspective_set(camera, 10.0, 1.0, 1.0, 500.0);
191
192 camera_node =
193 efl_add(EVAS_CANVAS3D_NODE_CLASS, evas, evas_canvas3d_node_type_set(efl_added, EVAS_CANVAS3D_NODE_TYPE_CAMERA));
194 evas_canvas3d_node_camera_set(camera_node, camera);
195 evas_canvas3d_node_member_add(root_node, camera_node);
196 evas_canvas3d_node_position_set(camera_node, 0.0, 0.0, 100.0);
197 evas_canvas3d_node_look_at_set(camera_node, EVAS_CANVAS3D_SPACE_PARENT, 0.0, 0.0, 0.0, EVAS_CANVAS3D_SPACE_PARENT, 0.0, 1.0, 0.0);
198 /* Add the light. */
199 light = efl_add(EVAS_CANVAS3D_LIGHT_CLASS, evas);
200 evas_canvas3d_light_ambient_set(light, 1.0, 1.0, 1.0, 1.0);
201 evas_canvas3d_light_diffuse_set(light, 1.0, 1.0, 1.0, 1.0);
202 evas_canvas3d_light_specular_set(light, 1.0, 1.0, 1.0, 1.0);
203 evas_canvas3d_light_directional_set(light, EINA_TRUE);
204
205 light_node =
206 efl_add(EVAS_CANVAS3D_NODE_CLASS, evas, evas_canvas3d_node_type_set(efl_added, EVAS_CANVAS3D_NODE_TYPE_LIGHT));
207 evas_canvas3d_node_light_set(light_node, light);
208 evas_canvas3d_node_position_set(light_node, 1.0, 0.0, 100.0);
209 evas_canvas3d_node_look_at_set(light_node, EVAS_CANVAS3D_SPACE_PARENT, 0.0, 0.0, 0.0, EVAS_CANVAS3D_SPACE_PARENT, 0.0, 1.0, 0.0);
210 evas_canvas3d_node_member_add(root_node, light_node);
211
212 material = efl_add(EVAS_CANVAS3D_MATERIAL_CLASS, evas);
213
214 evas_canvas3d_material_enable_set(material, EVAS_CANVAS3D_MATERIAL_ATTRIB_AMBIENT, EINA_TRUE);
215 evas_canvas3d_material_enable_set(material, EVAS_CANVAS3D_MATERIAL_ATTRIB_DIFFUSE, EINA_TRUE);
216 evas_canvas3d_material_enable_set(material, EVAS_CANVAS3D_MATERIAL_ATTRIB_SPECULAR, EINA_TRUE);
217 evas_canvas3d_material_enable_set(material, EVAS_CANVAS3D_MATERIAL_ATTRIB_NORMAL, EINA_TRUE);
218 evas_canvas3d_material_color_set(material, EVAS_CANVAS3D_MATERIAL_ATTRIB_AMBIENT, 0.01, 0.01, 0.01, 1.0);
219 evas_canvas3d_material_color_set(material, EVAS_CANVAS3D_MATERIAL_ATTRIB_DIFFUSE, 1.0, 1.0, 0.0, 1.0);
220 evas_canvas3d_material_color_set(material, EVAS_CANVAS3D_MATERIAL_ATTRIB_SPECULAR, 0.5, 0.0, 1.0, 1.0);
221 evas_canvas3d_material_shininess_set(material, 50.0);
222
223 /* Add the meshes */
224 LOAD_AND_ADD_MESH(obj, 0);
225 LOAD_AND_ADD_MESH(eet, 1);