summaryrefslogtreecommitdiff
path: root/src/modules/evas/model_loaders/obj
diff options
context:
space:
mode:
authorBogdan Devichev <b.devichev@samsung.com>2014-12-09 17:25:01 +0200
committerCedric BAIL <cedric@osg.samsung.com>2014-12-23 21:20:20 +0100
commit17baa3fa6f87227fdba4caaea5e5c2a39257f5bb (patch)
tree5e00a767a614736ea3072146869525ca7bf67a82 /src/modules/evas/model_loaders/obj
parente024f861e1aa3ffd74ea6a79ce480242930471dd (diff)
evas: entry points to modules is new struct with Eina_file, not const char *file.
Diffstat (limited to 'src/modules/evas/model_loaders/obj')
-rw-r--r--src/modules/evas/model_loaders/obj/evas_model_load_obj.c73
1 files changed, 6 insertions, 67 deletions
diff --git a/src/modules/evas/model_loaders/obj/evas_model_load_obj.c b/src/modules/evas/model_loaders/obj/evas_model_load_obj.c
index 359d299..7c6869e 100644
--- a/src/modules/evas/model_loaders/obj/evas_model_load_obj.c
+++ b/src/modules/evas/model_loaders/obj/evas_model_load_obj.c
@@ -38,58 +38,6 @@ struct _OBJ_Counts
38 Eina_Bool existence_of_tex_point; 38 Eina_Bool existence_of_tex_point;
39}; 39};
40 40
41typedef struct _OBJ_Loader
42{
43 Eina_File *file;
44 char *map;
45} OBJ_Loader;
46
47static inline void
48_obj_loader_fini(OBJ_Loader *loader)
49{
50 if (loader->map)
51 {
52 eina_file_map_free(loader->file, loader->map);
53 loader->map = NULL;
54 }
55
56 if (loader->file)
57 {
58 eina_file_close(loader->file);
59 loader->file = NULL;
60 }
61}
62
63static inline Eina_Bool
64_obj_loader_init(OBJ_Loader *loader, const char *file)
65{
66 memset(loader, 0x00, sizeof(OBJ_Loader));
67
68 /* Open given file. */
69 loader->file = eina_file_open(file, 0);
70
71 if (loader->file == NULL)
72 {
73 ERR("Failed to open file %s\n", file);
74 goto error;
75 }
76
77 /* Map the file. */
78 loader->map = eina_file_map_all(loader->file, EINA_FILE_SEQUENTIAL);
79
80 if (loader->map == NULL)
81 {
82 ERR("Failed to create map from file %s\n", file);
83 goto error;
84 }
85
86 return EINA_TRUE;
87
88error:
89 _obj_loader_fini(loader);
90 return EINA_FALSE;
91}
92
93/* create new counter */ 41/* create new counter */
94static inline OBJ_Counts 42static inline OBJ_Counts
95_new_count_elements() 43_new_count_elements()
@@ -135,11 +83,11 @@ _analyze_face_line(char * face_analyzer,
135} 83}
136 84
137static inline OBJ_Counts 85static inline OBJ_Counts
138_count_elements(OBJ_Loader loader)//count elements of mesh in .obj 86_count_elements(Model_Common_Loader *loader)//count elements of mesh in .obj
139{ 87{
140 OBJ_Counts counts = _new_count_elements(); 88 OBJ_Counts counts = _new_count_elements();
141 89
142 char * current = loader.map; 90 char * current = loader->map;
143 int polygon_checker = -2;//polygons with n vertices can be represented as n-2 triangles 91 int polygon_checker = -2;//polygons with n vertices can be represented as n-2 triangles
144 Eina_Bool will_check_next_char = EINA_FALSE; 92 Eina_Bool will_check_next_char = EINA_FALSE;
145 Eina_Bool first_char_is_v = EINA_FALSE; 93 Eina_Bool first_char_is_v = EINA_FALSE;
@@ -230,11 +178,10 @@ _count_elements(OBJ_Loader loader)//count elements of mesh in .obj
230} 178}
231 179
232void 180void
233evas_model_load_file_obj(Evas_3D_Mesh *mesh, const char *file) 181evas_model_load_file_obj(Evas_3D_Mesh *mesh, Model_Common_Loader *loader)
234{ 182{
235 long i; 183 long i;
236 OBJ_Counts counts;//count elements of mesh in .obj 184 OBJ_Counts counts;//count elements of mesh in .obj
237 OBJ_Loader loader;
238 Eina_Bool will_check_next_char = EINA_FALSE; 185 Eina_Bool will_check_next_char = EINA_FALSE;
239 Eina_Bool first_char_is_v = EINA_FALSE; 186 Eina_Bool first_char_is_v = EINA_FALSE;
240 Eina_Bool first_char_is_f = EINA_FALSE; 187 Eina_Bool first_char_is_f = EINA_FALSE;
@@ -243,13 +190,6 @@ evas_model_load_file_obj(Evas_3D_Mesh *mesh, const char *file)
243 int j, k; 190 int j, k;
244 char * current; 191 char * current;
245 192
246 /* Initialize PLY loader */
247 if (!_obj_loader_init(&loader, file))
248 {
249 ERR("Failed to initialize PLY loader.");
250 return;
251 }
252
253 counts = _count_elements(loader); 193 counts = _count_elements(loader);
254 194
255 float *_vertices_obj = malloc(counts._vertex_counter * 3 * sizeof(float)); 195 float *_vertices_obj = malloc(counts._vertex_counter * 3 * sizeof(float));
@@ -258,11 +198,10 @@ evas_model_load_file_obj(Evas_3D_Mesh *mesh, const char *file)
258 /* triangle has 3 points, every point has 3(vertix, texture and normal) coord */ 198 /* triangle has 3 points, every point has 3(vertix, texture and normal) coord */
259 int *_triangles = malloc(counts._triangles_counter * 9 * sizeof(int)); 199 int *_triangles = malloc(counts._triangles_counter * 9 * sizeof(int));
260 200
261 if ((loader.map == NULL) || (_vertices_obj == NULL) || 201 if ((loader->map == NULL) || (_vertices_obj == NULL) ||
262 (_normales_obj == NULL) || (_tex_coords_obj == NULL) || (_triangles == NULL)) 202 (_normales_obj == NULL) || (_tex_coords_obj == NULL) || (_triangles == NULL))
263 { 203 {
264 ERR("Allocate memory is failed."); 204 ERR("Allocate memory is failed.");
265 _obj_loader_fini(&loader);
266 free(_vertices_obj); 205 free(_vertices_obj);
267 free(_normales_obj); 206 free(_normales_obj);
268 free(_tex_coords_obj); 207 free(_tex_coords_obj);
@@ -270,7 +209,7 @@ evas_model_load_file_obj(Evas_3D_Mesh *mesh, const char *file)
270 return; 209 return;
271 } 210 }
272 211
273 current = loader.map; 212 current = loader->map;
274 i = 0; 213 i = 0;
275 214
276 /* put data to arrays */ 215 /* put data to arrays */
@@ -434,5 +373,5 @@ evas_model_load_file_obj(Evas_3D_Mesh *mesh, const char *file)
434 { 373 {
435 ERR("Axis-Aligned Bounding Box wan't added in frame %d ", 0); 374 ERR("Axis-Aligned Bounding Box wan't added in frame %d ", 0);
436 } 375 }
437 _obj_loader_fini(&loader);
438} 376}
377