summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBogdan Devichev <b.devichev@samsung.com>2014-12-12 17:23:49 +0200
committerBogdan Devichev <b.devichev@samsung.com>2014-12-12 17:23:49 +0200
commitf7511410091cc97e2e98d17be77f616aaa061791 (patch)
tree39597e704df1685e4b955eec7133657d18f8b719
parent2b5dc25974f31b46116fcc189384ca953f7506bc (diff)
Model_save_load. Step 10. An _mmap version of the file_set is added.
-rw-r--r--src/examples/evas/evas-3d-mmap-set.c250
-rw-r--r--src/examples/evas/sonic.eetbin0 -> 132670 bytes
-rw-r--r--src/lib/evas/canvas/evas_3d_mesh.c14
-rw-r--r--src/lib/evas/canvas/evas_3d_mesh.eo15
-rw-r--r--src/lib/evas/common/evas_model_load.c60
-rw-r--r--src/lib/evas/include/evas_private.h3
-rw-r--r--src/tests/evas/evas_test_mesh.c5
7 files changed, 329 insertions, 18 deletions
diff --git a/src/examples/evas/evas-3d-mmap-set.c b/src/examples/evas/evas-3d-mmap-set.c
new file mode 100644
index 0000000000..b474e48cbd
--- /dev/null
+++ b/src/examples/evas/evas-3d-mmap-set.c
@@ -0,0 +1,250 @@
1/**
2* Simple Evas example illustrating import from mmap.
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 evas ecore ecore-evas eina eo`
10* @endverbatim
11*/
12//TODO This example will be cool in nearest future
13
14#define EFL_EO_API_SUPPORT
15#define EFL_BETA_API_SUPPORT
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
25Ecore_Evas *ecore_evas = NULL;
26Evas *evas = NULL;
27Eo *background = NULL;
28Eo *image = NULL;
29
30Eo *scene = NULL;
31Eo *root_node = NULL;
32Eo *camera_node = NULL;
33Eo *light_node = NULL;
34Eo *camera = NULL;
35Eo *mesh_node_obj = NULL;
36Eo *mesh_obj = NULL;
37Eo *mesh_node_ply = NULL;
38Eo *mesh_ply = NULL;
39Eo *mesh_node_eet = NULL;
40Eo *mesh_eet = NULL;
41Eo *mesh_node_md2 = NULL;
42Eo *mesh_md2 = NULL;
43Eo *material = NULL;
44Eo *light = NULL;
45
46static float angle = 0;
47
48static Eina_Bool
49_animate_scene(void *data)
50{
51 angle += 0.5;
52
53 eo_do((Evas_3D_Node *)data, evas_3d_node_orientation_angle_axis_set(angle, 1.0, 1.0, 1.0));
54
55 /* Rotate */
56 if (angle > 360.0) angle -= 360.0f;
57
58 return EINA_TRUE;
59}
60
61static void
62_on_delete(Ecore_Evas *ee EINA_UNUSED)
63{
64 ecore_main_loop_quit();
65}
66
67static void
68_on_canvas_resize(Ecore_Evas *ee)
69{
70 int w, h;
71
72 ecore_evas_geometry_get(ee, NULL, NULL, &w, &h);
73 eo_do(background, evas_obj_size_set(w, h));
74 eo_do(image, evas_obj_size_set(w, h));
75}
76
77int
78main(void)
79{
80 //Unless Evas 3D supports Software renderer, we set gl backened forcely.
81 setenv("ECORE_EVAS_ENGINE", "opengl_x11", 1);
82
83 if (!ecore_evas_init()) return 0;
84
85 ecore_evas = ecore_evas_new(NULL, 10, 10, WIDTH, HEIGHT, NULL);
86
87 if (!ecore_evas) return 0;
88
89 Eina_File *obj_file;
90 Eina_File *ply_file;
91 Eina_File *eet_file;
92 Eina_File *md2_file;
93
94 obj_file = eina_file_open("man_mesh.obj", 0);
95 ply_file = eina_file_open("ply_files/Normal_UVs_Colors.ply", 0);
96 eet_file = eina_file_open("sonic.eet", 0);
97 md2_file = eina_file_open("sonic.md2", 0);
98
99 ecore_evas_callback_delete_request_set(ecore_evas, _on_delete);
100 ecore_evas_callback_resize_set(ecore_evas, _on_canvas_resize);
101 ecore_evas_show(ecore_evas);
102
103 evas = ecore_evas_get(ecore_evas);
104
105 /* Add a scene object .*/
106 scene = eo_add(EVAS_3D_SCENE_CLASS, evas);
107
108 /* Add the root node for the scene. */
109 root_node = eo_add(EVAS_3D_NODE_CLASS, evas,
110 evas_3d_node_constructor(EVAS_3D_NODE_TYPE_NODE));
111
112 /* Add the camera. */
113 camera = eo_add(EVAS_3D_CAMERA_CLASS, evas);
114 eo_do(camera,
115 evas_3d_camera_projection_perspective_set(60.0, 1.0, 1.0, 500.0));
116
117 camera_node =
118 eo_add(EVAS_3D_NODE_CLASS, evas,
119 evas_3d_node_constructor(EVAS_3D_NODE_TYPE_CAMERA));
120 eo_do(camera_node,
121 evas_3d_node_camera_set(camera));
122 eo_do(root_node,
123 evas_3d_node_member_add(camera_node));
124 eo_do(camera_node,
125 evas_3d_node_position_set(100.0, 0.0, 20.0),
126 evas_3d_node_look_at_set(EVAS_3D_SPACE_PARENT, 0.0, 0.0, 20.0,
127 EVAS_3D_SPACE_PARENT, 0.0, 0.0, 1.0));
128 /* Add the light. */
129 light = eo_add(EVAS_3D_LIGHT_CLASS, evas);
130 eo_do(light,
131 evas_3d_light_ambient_set(1.0, 1.0, 1.0, 1.0),
132 evas_3d_light_diffuse_set(1.0, 1.0, 1.0, 1.0),
133 evas_3d_light_specular_set(1.0, 1.0, 1.0, 1.0),
134 evas_3d_light_directional_set(EINA_TRUE));
135
136 light_node =
137 eo_add(EVAS_3D_NODE_CLASS, evas,
138 evas_3d_node_constructor(EVAS_3D_NODE_TYPE_LIGHT));
139 eo_do(light_node,
140 evas_3d_node_light_set(light),
141 evas_3d_node_position_set(1000.0, 0.0, 1000.0),
142 evas_3d_node_look_at_set(EVAS_3D_SPACE_PARENT, 0.0, 0.0, 0.0,
143 EVAS_3D_SPACE_PARENT, 0.0, 1.0, 0.0));
144 eo_do(root_node,
145 evas_3d_node_member_add(light_node));
146
147 material = eo_add(EVAS_3D_MATERIAL_CLASS, evas);
148
149 /* Add the meshes. */
150 mesh_obj = eo_add(EVAS_3D_MESH_CLASS, evas);
151 mesh_ply = eo_add(EVAS_3D_MESH_CLASS, evas);
152 mesh_eet = eo_add(EVAS_3D_MESH_CLASS, evas);
153 mesh_md2 = eo_add(EVAS_3D_MESH_CLASS, evas);
154
155 eo_do(mesh_obj,
156 evas_3d_mesh_mmap_set(obj_file, NULL),
157 evas_3d_mesh_frame_material_set(0, material),
158 evas_3d_mesh_shade_mode_set(EVAS_3D_SHADE_MODE_PHONG));
159
160 eo_do(mesh_ply,
161 evas_3d_mesh_mmap_set(ply_file, NULL),
162 evas_3d_mesh_frame_material_set(0, material),
163 evas_3d_mesh_shade_mode_set(EVAS_3D_SHADE_MODE_PHONG));
164
165 eo_do(mesh_eet,
166 evas_3d_mesh_mmap_set(eet_file, NULL),
167 evas_3d_mesh_frame_material_set(0, material),
168 evas_3d_mesh_shade_mode_set(EVAS_3D_SHADE_MODE_PHONG));
169
170 eo_do(mesh_md2,
171 evas_3d_mesh_mmap_set(md2_file, NULL),
172 evas_3d_mesh_frame_material_set(0, material),
173 evas_3d_mesh_shade_mode_set(EVAS_3D_SHADE_MODE_PHONG));
174
175 eo_do(material,
176 evas_3d_material_enable_set(EVAS_3D_MATERIAL_AMBIENT, EINA_TRUE),
177 evas_3d_material_enable_set(EVAS_3D_MATERIAL_DIFFUSE, EINA_TRUE),
178 evas_3d_material_enable_set(EVAS_3D_MATERIAL_SPECULAR, EINA_TRUE),
179 evas_3d_material_enable_set(EVAS_3D_MATERIAL_NORMAL, EINA_TRUE),
180 evas_3d_material_color_set(EVAS_3D_MATERIAL_AMBIENT,
181 0.01, 0.01, 0.01, 1.0),
182 evas_3d_material_color_set(EVAS_3D_MATERIAL_DIFFUSE,
183 1.0, 1.0, 1.0, 1.0),
184 evas_3d_material_color_set(EVAS_3D_MATERIAL_SPECULAR,
185 1.0, 1.0, 1.0, 1.0),
186 evas_3d_material_shininess_set(50.0));
187
188 mesh_node_obj = eo_add(EVAS_3D_NODE_CLASS, evas,
189 evas_3d_node_constructor(EVAS_3D_NODE_TYPE_MESH));
190 mesh_node_ply = eo_add(EVAS_3D_NODE_CLASS, evas,
191 evas_3d_node_constructor(EVAS_3D_NODE_TYPE_MESH));
192 mesh_node_eet = eo_add(EVAS_3D_NODE_CLASS, evas,
193 evas_3d_node_constructor(EVAS_3D_NODE_TYPE_MESH));
194 mesh_node_md2 = eo_add(EVAS_3D_NODE_CLASS, evas,
195 evas_3d_node_constructor(EVAS_3D_NODE_TYPE_MESH));
196
197 eo_do(root_node, evas_3d_node_member_add(mesh_node_obj));
198 eo_do(root_node, evas_3d_node_member_add(mesh_node_ply));
199 eo_do(root_node, evas_3d_node_member_add(mesh_node_md2));
200 eo_do(root_node, evas_3d_node_member_add(mesh_node_eet));
201
202 eo_do(mesh_node_obj, evas_3d_node_mesh_add(mesh_obj),
203 evas_3d_node_position_set(0, -30, 0));
204 eo_do(mesh_node_ply, evas_3d_node_mesh_add(mesh_ply),
205 evas_3d_node_position_set(0, -10, 0));
206 eo_do(mesh_node_eet, evas_3d_node_mesh_add(mesh_eet),
207 evas_3d_node_position_set(0, 10, 0));
208 eo_do(mesh_node_md2, evas_3d_node_mesh_add(mesh_md2),
209 evas_3d_node_position_set(0, 30, 0));
210
211 /* Set up scene. */
212 eo_do(scene,
213 evas_3d_scene_root_node_set(root_node),
214 evas_3d_scene_camera_node_set(camera_node),
215 evas_3d_scene_size_set(WIDTH, HEIGHT));
216
217 /* Add a background rectangle objects. */
218 background = eo_add(EVAS_RECTANGLE_CLASS, evas);
219 eo_do(background,
220 evas_obj_color_set(0, 0, 0, 255),
221 evas_obj_size_set(WIDTH, HEIGHT),
222 evas_obj_visibility_set(EINA_TRUE));
223
224 /* Add an image object for 3D scene rendering. */
225 image = evas_object_image_filled_add(evas);
226 eo_do(image,
227 evas_obj_size_set(WIDTH, HEIGHT),
228 evas_obj_visibility_set(EINA_TRUE));
229
230 /* Set the image object as render target for 3D scene. */
231 eo_do(image, evas_obj_image_scene_set(scene));
232
233 ecore_timer_add(0.01, _animate_scene, mesh_node_obj);
234 ecore_timer_add(0.01, _animate_scene, mesh_node_ply);
235 ecore_timer_add(0.01, _animate_scene, mesh_node_eet);
236 ecore_timer_add(0.01, _animate_scene, mesh_node_md2);
237
238 /* Enter main loop. */
239 ecore_main_loop_begin();
240
241 ecore_evas_free(ecore_evas);
242 ecore_evas_shutdown();
243
244 eina_file_close(obj_file);
245 eina_file_close(ply_file);
246 eina_file_close(eet_file);
247 eina_file_close(md2_file);
248
249 return 0;
250}
diff --git a/src/examples/evas/sonic.eet b/src/examples/evas/sonic.eet
new file mode 100644
index 0000000000..e1fa9ef38c
--- /dev/null
+++ b/src/examples/evas/sonic.eet
Binary files differ
diff --git a/src/lib/evas/canvas/evas_3d_mesh.c b/src/lib/evas/canvas/evas_3d_mesh.c
index 36c38c3a72..2328293625 100644
--- a/src/lib/evas/canvas/evas_3d_mesh.c
+++ b/src/lib/evas/canvas/evas_3d_mesh.c
@@ -770,6 +770,18 @@ _evas_3d_mesh_fog_enable_get(Eo *obj EINA_UNUSED, Evas_3D_Mesh_Data *pd)
770} 770}
771 771
772EOLIAN static void 772EOLIAN static void
773_evas_3d_mesh_mmap_set(Eo *obj, Evas_3D_Mesh_Data *pd,
774 Eina_File *file, const char *key EINA_UNUSED)
775{
776 _mesh_fini(pd);
777 _mesh_init(pd);
778
779 if (file == NULL) return;
780
781 evas_common_load_model_from_eina_file(obj, file);
782}
783
784EOLIAN static void
773_evas_3d_mesh_file_set(Eo *obj, Evas_3D_Mesh_Data *pd, 785_evas_3d_mesh_file_set(Eo *obj, Evas_3D_Mesh_Data *pd,
774 const char *file, const char *key EINA_UNUSED) 786 const char *file, const char *key EINA_UNUSED)
775{ 787{
@@ -778,7 +790,7 @@ _evas_3d_mesh_file_set(Eo *obj, Evas_3D_Mesh_Data *pd,
778 790
779 if (file == NULL) return; 791 if (file == NULL) return;
780 792
781 evas_common_load_model_to_file(obj, file); 793 evas_common_load_model_from_file(obj, file);
782} 794}
783 795
784EOLIAN static void 796EOLIAN static void
diff --git a/src/lib/evas/canvas/evas_3d_mesh.eo b/src/lib/evas/canvas/evas_3d_mesh.eo
index f2b420aebb..0c79941b6a 100644
--- a/src/lib/evas/canvas/evas_3d_mesh.eo
+++ b/src/lib/evas/canvas/evas_3d_mesh.eo
@@ -4,6 +4,21 @@ class Evas_3D_Mesh (Evas_3D_Object, Evas.Common_Interface)
4 data: Evas_3D_Mesh_Data; 4 data: Evas_3D_Mesh_Data;
5 5
6 methods { 6 methods {
7 mmap_set {
8 /**
9 * Load mesh data from Eina_File.
10 *
11 * Loading a mesh from existing Eina_File is supported. Currently, only MD2, OBJ,
12 * PLY and EET file formats are supported.
13 *
14 * @ingroup Evas_3D_Mesh
15 */
16 params {
17 @in Eina_File* file; /*@ Eina_File with mesh data. */
18 @in const(char)* key; /*@ Key in the mesh file. */
19 }
20 }
21
7 file_set { 22 file_set {
8 /** 23 /**
9 * Load mesh data from file. 24 * Load mesh data from file.
diff --git a/src/lib/evas/common/evas_model_load.c b/src/lib/evas/common/evas_model_load.c
index 0598d31e21..e00290e315 100644
--- a/src/lib/evas/common/evas_model_load.c
+++ b/src/lib/evas/common/evas_model_load.c
@@ -8,11 +8,35 @@
8#include "evas_private.h" 8#include "evas_private.h"
9 9
10void 10void
11evas_common_load_model_to_file(Evas_3D_Mesh *model, const char *file) 11_evas_common_load_model(Evas_3D_Mesh *model,
12 Eina_File *file,
13 const char *file_path)
12{ 14{
13 char *p; 15 char *p;
14 char *loader_type = NULL; 16 char *loader_type = NULL;
15 17
18 p = strrchr(file_path, '.');
19 if (p)
20 {
21 p++;
22#define CHECK_EXTENTION_BY_FILE_NAME(extention) \
23 if (!strcasecmp(p, #extention)) \
24 { \
25 evas_model_load_file_##extention(model, file); \
26 loader_type = #extention; \
27 }
28 CHECK_EXTENTION_BY_FILE_NAME(eet)
29 CHECK_EXTENTION_BY_FILE_NAME(md2)
30 CHECK_EXTENTION_BY_FILE_NAME(obj)
31 CHECK_EXTENTION_BY_FILE_NAME(ply)
32#undef CHECK_EXTENTION_BY_FILE_NAME
33 }
34 if (!loader_type) ERR("Invalid mesh file type.");
35}
36
37void
38evas_common_load_model_from_file(Evas_3D_Mesh *model, const char *file)
39{
16 Eina_File *tmp_file = eina_file_open(file, 0); 40 Eina_File *tmp_file = eina_file_open(file, 0);
17 Eina_File *e_file = eina_file_dup(tmp_file); 41 Eina_File *e_file = eina_file_dup(tmp_file);
18 42
@@ -29,23 +53,27 @@ evas_common_load_model_to_file(Evas_3D_Mesh *model, const char *file)
29 53
30 eina_file_close(tmp_file); 54 eina_file_close(tmp_file);
31 55
32 p = strrchr(file, '.'); 56 _evas_common_load_model(model, e_file, file);
33 if (p) 57
58 eina_file_close(e_file);
59 e_file = NULL;
60}
61
62void
63evas_common_load_model_from_eina_file(Evas_3D_Mesh *model, Eina_File *file)
64{
65 Eina_File *e_file = eina_file_dup(file);
66
67 if (e_file == NULL)
34 { 68 {
35 p++; 69 ERR("Failed to open file %s\n", file);
36#define CHECK_EXTENTION_BY_FILE_NAME(extention) \ 70 eina_file_close(e_file);
37 if (!strcasecmp(p, #extention)) \ 71 e_file = NULL;
38 { \ 72 ERR("Failed to initialize loader.");
39 evas_model_load_file_##extention(model, e_file); \ 73 return;
40 loader_type = #extention; \
41 }
42 CHECK_EXTENTION_BY_FILE_NAME(eet)
43 CHECK_EXTENTION_BY_FILE_NAME(md2)
44 CHECK_EXTENTION_BY_FILE_NAME(obj)
45 CHECK_EXTENTION_BY_FILE_NAME(ply)
46#undef CHECK_EXTENTION_BY_FILE_NAME
47 } 74 }
48 if (!loader_type) ERR("Invalid mesh file type."); 75
76 _evas_common_load_model(model, e_file, eina_file_filename_get(e_file));
49 77
50 eina_file_close(e_file); 78 eina_file_close(e_file);
51 e_file = NULL; 79 e_file = NULL;
diff --git a/src/lib/evas/include/evas_private.h b/src/lib/evas/include/evas_private.h
index 411016da87..84299ebf4e 100644
--- a/src/lib/evas/include/evas_private.h
+++ b/src/lib/evas/include/evas_private.h
@@ -1637,7 +1637,8 @@ void _evas_3d_eet_descriptor_shutdown(void);
1637void _evas_3d_eet_file_free(void); 1637void _evas_3d_eet_file_free(void);
1638 1638
1639/* Temporary save/load functions */ 1639/* Temporary save/load functions */
1640void evas_common_load_model_to_file(Evas_3D_Mesh *model, const char *file); 1640void evas_common_load_model_from_file(Evas_3D_Mesh *model, const char *file);
1641void evas_common_load_model_from_eina_file(Evas_3D_Mesh *model, Eina_File *file);
1641void evas_common_save_model_to_file(Evas_3D_Mesh *model, const char *file, Evas_3D_Mesh_Frame *f); 1642void evas_common_save_model_to_file(Evas_3D_Mesh *model, const char *file, Evas_3D_Mesh_Frame *f);
1642void evas_model_load_file_eet(Evas_3D_Mesh *mesh, Eina_File *file); 1643void evas_model_load_file_eet(Evas_3D_Mesh *mesh, Eina_File *file);
1643void evas_model_load_file_md2(Evas_3D_Mesh *mesh, Eina_File *file); 1644void evas_model_load_file_md2(Evas_3D_Mesh *mesh, Eina_File *file);
diff --git a/src/tests/evas/evas_test_mesh.c b/src/tests/evas/evas_test_mesh.c
index dde1dd348f..51f601e4b1 100644
--- a/src/tests/evas/evas_test_mesh.c
+++ b/src/tests/evas/evas_test_mesh.c
@@ -48,6 +48,11 @@
48 eo_do(mesh2, evas_3d_mesh_file_set(buffer, NULL)); \ 48 eo_do(mesh2, evas_3d_mesh_file_set(buffer, NULL)); \
49 res = _compare_meshes(mesh, mesh2); \ 49 res = _compare_meshes(mesh, mesh2); \
50 fail_if(res == 1); \ 50 fail_if(res == 1); \
51 eo_do(mesh, evas_3d_mesh_mmap_set(eina_file_open(file->path, 0), NULL)); \
52 eo_do(mesh, evas_3d_mesh_save(buffer, NULL)); \
53 eo_do(mesh2, evas_3d_mesh_mmap_set(eina_file_open(buffer, 0), NULL)); \
54 res = _compare_meshes(mesh, mesh2); \
55 fail_if(res == 1); \
51 eo_del(mesh2); \ 56 eo_del(mesh2); \
52 eo_del(mesh); \ 57 eo_del(mesh); \
53 } 58 }