summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBogdan Devichev <b.devichev@samsung.com>2014-11-28 18:48:35 +0200
committerBogdan Devichev <b.devichev@samsung.com>2014-12-05 11:11:09 +0200
commit8b1d380ba5629545d6561a4d69af41bb52fb36c6 (patch)
tree9b67ac188afa0be821a92f2bb0e2c4093eff89d9
parent42562b3ddf4552de7ef002e19e816165bfe9301e (diff)
Model_save_load. Step 5. Test cases are changed according to changes of API in step 4. Specific logic in obj_saver is removed for standardization of API.
-rw-r--r--src/examples/evas/evas-3d-obj.c2
-rw-r--r--src/modules/evas/model_savers/obj/evas_model_save_obj.c39
-rw-r--r--src/tests/evas/evas_test_mesh.c17
3 files changed, 34 insertions, 24 deletions
diff --git a/src/examples/evas/evas-3d-obj.c b/src/examples/evas/evas-3d-obj.c
index 2634502355..d19a36db91 100644
--- a/src/examples/evas/evas-3d-obj.c
+++ b/src/examples/evas/evas-3d-obj.c
@@ -159,7 +159,7 @@ main(void)
159 1.0, 1.0, 1.0, 1.0), 159 1.0, 1.0, 1.0, 1.0),
160 evas_3d_material_shininess_set(50.0)); 160 evas_3d_material_shininess_set(50.0));
161 161
162 eo_do(mesh, evas_3d_mesh_save("saved_man", NULL)); 162 eo_do(mesh, evas_3d_mesh_save("saved_man.obj", NULL));
163 163
164 mesh_node = eo_add(EVAS_3D_NODE_CLASS, evas, 164 mesh_node = eo_add(EVAS_3D_NODE_CLASS, evas,
165 evas_3d_node_constructor(EVAS_3D_NODE_TYPE_MESH)); 165 evas_3d_node_constructor(EVAS_3D_NODE_TYPE_MESH));
diff --git a/src/modules/evas/model_savers/obj/evas_model_save_obj.c b/src/modules/evas/model_savers/obj/evas_model_save_obj.c
index 35773e304f..1cc7e8a744 100644
--- a/src/modules/evas/model_savers/obj/evas_model_save_obj.c
+++ b/src/modules/evas/model_savers/obj/evas_model_save_obj.c
@@ -9,17 +9,11 @@
9#include "evas_private.h" 9#include "evas_private.h"
10 10
11#define OPEN_FILE(extension)\ 11#define OPEN_FILE(extension)\
12 int length=strlen(file);\
13 char * extension = "."#extension;\
14 char * _##extension##_file_name = (char *)malloc(length+4);\
15 strcpy(_##extension##_file_name,file);\
16 strcpy(_##extension##_file_name+length,extension);\
17 FILE * _##extension##_file = fopen(_##extension##_file_name, "w+");\ 12 FILE * _##extension##_file = fopen(_##extension##_file_name, "w+");\
18 free(_##extension##_file_name);
19 13
20#define SAVE_GEOMETRICS(a, format)\ 14#define SAVE_GEOMETRICS(a, format)\
21 vb = &f->vertices[a];\ 15 vb = &f->vertices[a];\
22 fprintf(_obj_file, "o %s\n",file);\ 16 fprintf(_obj_file, "o %s\n",_obj_file_name);\
23 if (vb->data == NULL)\ 17 if (vb->data == NULL)\
24 {\ 18 {\
25 ERR("Reading of geometrics is failed.");\ 19 ERR("Reading of geometrics is failed.");\
@@ -34,7 +28,7 @@
34 } 28 }
35 29
36static void 30static void
37_save_mesh(Evas_3D_Mesh_Data *pd, const char *file, Evas_3D_Mesh_Frame *f) 31_save_mesh(Evas_3D_Mesh_Data *pd, const char *_obj_file_name, Evas_3D_Mesh_Frame *f)
38{ 32{
39 Evas_3D_Vertex_Buffer *vb; 33 Evas_3D_Vertex_Buffer *vb;
40 time_t current_time; 34 time_t current_time;
@@ -45,7 +39,7 @@ _save_mesh(Evas_3D_Mesh_Data *pd, const char *file, Evas_3D_Mesh_Frame *f)
45 OPEN_FILE(obj) 39 OPEN_FILE(obj)
46 if (!_obj_file) 40 if (!_obj_file)
47 { 41 {
48 ERR("File open '%s' for save failed", file); 42 ERR("File open '%s' for save failed", _obj_file_name);
49 return; 43 return;
50 } 44 }
51 fprintf(_obj_file, "# Evas_3D saver OBJ v0.03 \n");//_obj_file created in macro 45 fprintf(_obj_file, "# Evas_3D saver OBJ v0.03 \n");//_obj_file created in macro
@@ -69,7 +63,7 @@ _save_mesh(Evas_3D_Mesh_Data *pd, const char *file, Evas_3D_Mesh_Frame *f)
69 } 63 }
70 64
71 fprintf(_obj_file,"# Current time is %s \n", c_time_string); 65 fprintf(_obj_file,"# Current time is %s \n", c_time_string);
72 fprintf(_obj_file,"mtllib %s.mtl \n\n", file); 66 fprintf(_obj_file,"mtllib %s.mtl \n\n", _obj_file_name);
73 67
74 /* Adding geometrics to file. */ 68 /* Adding geometrics to file. */
75 if (f == NULL) 69 if (f == NULL)
@@ -95,14 +89,14 @@ _save_mesh(Evas_3D_Mesh_Data *pd, const char *file, Evas_3D_Mesh_Frame *f)
95} 89}
96 90
97static void 91static void
98_save_material(Evas_3D_Mesh_Data *pd EINA_UNUSED, const char *file, Evas_3D_Mesh_Frame *f) 92_save_material(Evas_3D_Mesh_Data *pd EINA_UNUSED, const char *_mtl_file_name, Evas_3D_Mesh_Frame *f)
99{ 93{
100 Evas_3D_Material_Data *mat = eo_data_scope_get(f->material, EVAS_3D_MATERIAL_CLASS); 94 Evas_3D_Material_Data *mat = eo_data_scope_get(f->material, EVAS_3D_MATERIAL_CLASS);
101 95
102 OPEN_FILE(mtl) 96 OPEN_FILE(mtl)
103 if (!_mtl_file) 97 if (!_mtl_file)
104 { 98 {
105 ERR("File open '%s' for save failed", file); 99 ERR("File open '%s' for save failed", _mtl_file_name);
106 return; 100 return;
107 } 101 }
108 fprintf(_mtl_file, "# Evas_3D saver OBJ v0.03 \n");//_mtl_file created in macro 102 fprintf(_mtl_file, "# Evas_3D saver OBJ v0.03 \n");//_mtl_file created in macro
@@ -129,9 +123,24 @@ _save_material(Evas_3D_Mesh_Data *pd EINA_UNUSED, const char *file, Evas_3D_Mesh
129} 123}
130 124
131void 125void
132evas_model_save_file_obj(Evas_3D_Mesh *mesh, const char *file, Evas_3D_Mesh_Frame *f) 126evas_model_save_file_obj(Evas_3D_Mesh *mesh, const char *_obj_file_name, Evas_3D_Mesh_Frame *f)
133{ 127{
128 int len;
129 char *without_extention, *_mtl_extension, *_mtl_file_name;
130
131 len = strlen(_obj_file_name);
132 without_extention = (char*)malloc((len - 4) * sizeof(char));
133 _mtl_extension = ".mtl";
134 _mtl_file_name = (char *)malloc(len * sizeof(char));
135
136 memcpy(without_extention, _obj_file_name, len-4);
137 strcpy(_mtl_file_name, without_extention);
138 strcpy(_mtl_file_name + len - 4, _mtl_extension);
139
134 Evas_3D_Mesh_Data *pd = eo_data_scope_get(mesh, EVAS_3D_MESH_CLASS); 140 Evas_3D_Mesh_Data *pd = eo_data_scope_get(mesh, EVAS_3D_MESH_CLASS);
135 _save_mesh(pd, file, f); 141 _save_mesh(pd, _obj_file_name, f);
136 _save_material(pd, file, f); 142 _save_material(pd, _mtl_file_name, f);
143
144 free(without_extention);
145 free(_mtl_file_name);
137} 146}
diff --git a/src/tests/evas/evas_test_mesh.c b/src/tests/evas/evas_test_mesh.c
index 7bfa61381c..dde1dd348f 100644
--- a/src/tests/evas/evas_test_mesh.c
+++ b/src/tests/evas/evas_test_mesh.c
@@ -34,7 +34,7 @@
34 src2 += f2->vertices[a].element_count; \ 34 src2 += f2->vertices[a].element_count; \
35 } 35 }
36 36
37#define CHECK_MESHES_IN_FOLDER(folder, type, type_to_check) \ 37#define CHECK_MESHES_IN_FOLDER(folder, ext) \
38 it = eina_file_direct_ls(folder); \ 38 it = eina_file_direct_ls(folder); \
39 EINA_ITERATOR_FOREACH(it, file) \ 39 EINA_ITERATOR_FOREACH(it, file) \
40 { \ 40 { \
@@ -42,9 +42,10 @@
42 mesh2 = eo_add(EVAS_3D_MESH_CLASS, e); \ 42 mesh2 = eo_add(EVAS_3D_MESH_CLASS, e); \
43 fail_if(mesh == NULL); \ 43 fail_if(mesh == NULL); \
44 fail_if(mesh2 == NULL); \ 44 fail_if(mesh2 == NULL); \
45 eo_do(mesh, evas_3d_mesh_file_set(type, file->path, NULL)); \ 45 snprintf(buffer, PATH_MAX, "%s", ext); \
46 eo_do(mesh, evas_3d_mesh_save(type_to_check, buffer, NULL)); \ 46 eo_do(mesh, evas_3d_mesh_file_set(file->path, NULL)); \
47 eo_do(mesh2, evas_3d_mesh_file_set(type_to_check, buffer, NULL)); \ 47 eo_do(mesh, evas_3d_mesh_save(buffer, NULL)); \
48 eo_do(mesh2, evas_3d_mesh_file_set(buffer, NULL)); \
48 res = _compare_meshes(mesh, mesh2); \ 49 res = _compare_meshes(mesh, mesh2); \
49 fail_if(res == 1); \ 50 fail_if(res == 1); \
50 eo_del(mesh2); \ 51 eo_del(mesh2); \
@@ -111,10 +112,10 @@ START_TEST(evas_object_mesh_loader_saver)
111 112
112 snprintf(buffer, PATH_MAX, "%s", tmp); 113 snprintf(buffer, PATH_MAX, "%s", tmp);
113 114
114 CHECK_MESHES_IN_FOLDER(TESTS_OBJ_MESH_DIR, EVAS_3D_MESH_FILE_TYPE_OBJ, EVAS_3D_MESH_FILE_TYPE_EET) 115 CHECK_MESHES_IN_FOLDER(TESTS_OBJ_MESH_DIR, ".eet")
115 CHECK_MESHES_IN_FOLDER(TESTS_MD2_MESH_DIR, EVAS_3D_MESH_FILE_TYPE_MD2, EVAS_3D_MESH_FILE_TYPE_EET) 116 CHECK_MESHES_IN_FOLDER(TESTS_MD2_MESH_DIR, ".eet")
116 CHECK_MESHES_IN_FOLDER(TESTS_PLY_MESH_DIR, EVAS_3D_MESH_FILE_TYPE_PLY, EVAS_3D_MESH_FILE_TYPE_EET) 117 CHECK_MESHES_IN_FOLDER(TESTS_PLY_MESH_DIR, ".eet")
117 CHECK_MESHES_IN_FOLDER(TESTS_PLY_MESH_DIR, EVAS_3D_MESH_FILE_TYPE_PLY, EVAS_3D_MESH_FILE_TYPE_PLY) 118 CHECK_MESHES_IN_FOLDER(TESTS_PLY_MESH_DIR, ".ply")
118 119
119 eina_iterator_free(it); 120 eina_iterator_free(it);
120 121