summaryrefslogtreecommitdiff
path: root/src/modules/evas/model_loaders
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
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')
-rw-r--r--src/modules/evas/model_loaders/eet/evas_model_load_eet.c5
-rw-r--r--src/modules/evas/model_loaders/md2/evas_model_load_md2.c77
-rw-r--r--src/modules/evas/model_loaders/obj/evas_model_load_obj.c73
-rw-r--r--src/modules/evas/model_loaders/ply/evas_model_load_ply.c70
4 files changed, 35 insertions, 190 deletions
diff --git a/src/modules/evas/model_loaders/eet/evas_model_load_eet.c b/src/modules/evas/model_loaders/eet/evas_model_load_eet.c
index fadd6aa..572e085 100644
--- a/src/modules/evas/model_loaders/eet/evas_model_load_eet.c
+++ b/src/modules/evas/model_loaders/eet/evas_model_load_eet.c
@@ -104,12 +104,12 @@ _set_material_to_mesh_from_eet_file(Evas_3D_Mesh *mesh,
104} 104}
105 105
106void 106void
107evas_model_load_file_eet(Evas_3D_Mesh *mesh, const char *file) 107evas_model_load_file_eet(Evas_3D_Mesh *mesh, Model_Common_Loader *loader)
108{ 108{
109 Eet_File *ef; 109 Eet_File *ef;
110 110
111 _evas_3d_eet_file_init(); 111 _evas_3d_eet_file_init();
112 ef = eet_open(file, EET_FILE_MODE_READ); 112 ef = eet_open(eina_file_filename_get(loader->file), EET_FILE_MODE_READ);
113 eet_file = eet_data_read(ef, 113 eet_file = eet_data_read(ef,
114 _file_descriptor, 114 _file_descriptor,
115 EVAS_3D_FILE_CACHE_FILE_ENTRY); 115 EVAS_3D_FILE_CACHE_FILE_ENTRY);
@@ -129,3 +129,4 @@ evas_model_load_file_eet(Evas_3D_Mesh *mesh, const char *file)
129 _evas_3d_eet_file_free(); 129 _evas_3d_eet_file_free();
130} 130}
131 131
132
diff --git a/src/modules/evas/model_loaders/md2/evas_model_load_md2.c b/src/modules/evas/model_loaders/md2/evas_model_load_md2.c
index 11d2845..a7fddc7 100644
--- a/src/modules/evas/model_loaders/md2/evas_model_load_md2.c
+++ b/src/modules/evas/model_loaders/md2/evas_model_load_md2.c
@@ -67,23 +67,22 @@ struct PACKED _MD2_Texcoord
67 67
68typedef struct _MD2_Loader 68typedef struct _MD2_Loader
69{ 69{
70 Eina_File *file; 70 Model_Common_Loader *common_loader;
71 char *map; 71 int size;
72 int size;
73 72
74 int skin_width; 73 int skin_width;
75 int skin_height; 74 int skin_height;
76 75
77 int frame_count; 76 int frame_count;
78 int frame_size; 77 int frame_size;
79 char *frames; 78 char *frames;
80 79
81 int vertex_count; 80 int vertex_count;
82 int triangle_count; 81 int triangle_count;
83 int texcoord_count; 82 int texcoord_count;
84 83
85 MD2_Triangle *triangles; 84 MD2_Triangle *triangles;
86 MD2_Texcoord *texcoords; 85 MD2_Texcoord *texcoords;
87} MD2_Loader; 86} MD2_Loader;
88 87
89static const float normal_table[162][3] = 88static const float normal_table[162][3] =
@@ -252,52 +251,22 @@ static const float normal_table[162][3] =
252 {-0.688191f, -0.587785f, -0.425325f}, 251 {-0.688191f, -0.587785f, -0.425325f},
253}; 252};
254 253
255static inline void
256_md2_loader_fini(MD2_Loader *loader)
257{
258 if (loader->map)
259 {
260 eina_file_map_free(loader->file, loader->map);
261 loader->map = NULL;
262 }
263
264 if (loader->file)
265 {
266 eina_file_close(loader->file);
267 loader->file = NULL;
268 }
269}
270
271static inline Eina_Bool 254static inline Eina_Bool
272_md2_loader_init(MD2_Loader *loader, const char *file) 255_md2_loader_init(MD2_Loader *loader, Model_Common_Loader *common_loader)
273{ 256{
274 MD2_Header header; 257 MD2_Header header;
275 258
276 memset(loader, 0x00, sizeof(MD2_Loader)); 259 memset(loader, 0x00, sizeof(MD2_Loader));
277 260 loader->common_loader = common_loader;
278 /* Open given file. */
279 loader->file = eina_file_open(file, 0);
280
281 if (loader->file == NULL)
282 {
283 ERR("Failed to open file %s\n", file);
284 goto error;
285 }
286 261
287 /* Check file size. We require a file larger than MD2 header size. */ 262 /* Check file size. We require a file larger than MD2 header size. */
288 loader->size = eina_file_size_get(loader->file); 263 loader->size = eina_file_size_get(loader->common_loader->file);
289 264
290 if (loader->size < (int)sizeof(MD2_Header)) 265 if (loader->size < (int)sizeof(MD2_Header))
291 goto error; 266 goto error;
292 267
293 /* Map the file. */
294 loader->map = eina_file_map_all(loader->file, EINA_FILE_SEQUENTIAL);
295
296 if (loader->map == NULL)
297 goto error;
298
299 /* Read header. */ 268 /* Read header. */
300 memcpy(&header, loader->map, sizeof(MD2_Header)); 269 memcpy(&header, loader->common_loader->map, sizeof(MD2_Header));
301 270
302 /* Check identity */ 271 /* Check identity */
303 if (header.magic != MD2_MAGIC_NUMBER || header.version != MD2_VERSION) 272 if (header.magic != MD2_MAGIC_NUMBER || header.version != MD2_VERSION)
@@ -327,23 +296,22 @@ _md2_loader_init(MD2_Loader *loader, const char *file)
327 296
328 loader->frame_count = header.frame_count; 297 loader->frame_count = header.frame_count;
329 loader->frame_size = header.frame_size; 298 loader->frame_size = header.frame_size;
330 loader->frames = loader->map + header.offset_frames; 299 loader->frames = loader->common_loader->map + header.offset_frames;
331 300
332 loader->vertex_count = header.vertex_count; 301 loader->vertex_count = header.vertex_count;
333 loader->triangle_count = header.triangle_count; 302 loader->triangle_count = header.triangle_count;
334 loader->texcoord_count = header.texcoord_count; 303 loader->texcoord_count = header.texcoord_count;
335 304
336 loader->triangles = (MD2_Triangle *)(loader->map + header.offset_triangles); 305 loader->triangles = (MD2_Triangle *)(loader->common_loader->map + header.offset_triangles);
337 loader->texcoords = (MD2_Texcoord *)(loader->map + header.offset_texcoords); 306 loader->texcoords = (MD2_Texcoord *)(loader->common_loader->map + header.offset_texcoords);
338 return EINA_TRUE; 307 return EINA_TRUE;
339 308
340error: 309error:
341 _md2_loader_fini(loader);
342 return EINA_FALSE; 310 return EINA_FALSE;
343} 311}
344 312
345void 313void
346evas_model_load_file_md2(Evas_3D_Mesh *mesh, const char *file) 314evas_model_load_file_md2(Evas_3D_Mesh *mesh, Model_Common_Loader *common_loader)
347{ 315{
348 MD2_Loader loader; 316 MD2_Loader loader;
349 int i, j, k; 317 int i, j, k;
@@ -353,7 +321,7 @@ evas_model_load_file_md2(Evas_3D_Mesh *mesh, const char *file)
353 Evas_3D_Mesh_Data *pd; 321 Evas_3D_Mesh_Data *pd;
354 322
355 /* Initialize MD2 loader (Open file and read MD2 head ant etc) */ 323 /* Initialize MD2 loader (Open file and read MD2 head ant etc) */
356 if (!_md2_loader_init(&loader, file)) 324 if (!_md2_loader_init(&loader, common_loader))
357 { 325 {
358 ERR("Failed to initialize MD2 loader."); 326 ERR("Failed to initialize MD2 loader.");
359 return; 327 return;
@@ -441,6 +409,5 @@ evas_model_load_file_md2(Evas_3D_Mesh *mesh, const char *file)
441 ERR("Axis-Aligned Bounding Box wasn't added in frame %d ", f); 409 ERR("Axis-Aligned Bounding Box wasn't added in frame %d ", f);
442 } 410 }
443 } 411 }
444
445 _md2_loader_fini(&loader);
446} 412}
413
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
diff --git a/src/modules/evas/model_loaders/ply/evas_model_load_ply.c b/src/modules/evas/model_loaders/ply/evas_model_load_ply.c
index 45e28a0..246f7cd 100644
--- a/src/modules/evas/model_loaders/ply/evas_model_load_ply.c
+++ b/src/modules/evas/model_loaders/ply/evas_model_load_ply.c
@@ -24,58 +24,6 @@ struct _PLY_Header
24 Eina_Bool existence_of_colors; 24 Eina_Bool existence_of_colors;
25}; 25};
26 26
27typedef struct _PLY_Loader
28{
29 Eina_File *file;
30 char *map;
31} PLY_Loader;
32
33static inline void
34_ply_loader_fini(PLY_Loader *loader)
35{
36 if (loader->map)
37 {
38 eina_file_map_free(loader->file, loader->map);
39 loader->map = NULL;
40 }
41
42 if (loader->file)
43 {
44 eina_file_close(loader->file);
45 loader->file = NULL;
46 }
47}
48
49static inline Eina_Bool
50_ply_loader_init(PLY_Loader *loader, const char *file)
51{
52 memset(loader, 0x00, sizeof(PLY_Loader));
53
54 /* Open given file. */
55 loader->file = eina_file_open(file, 0);
56
57 if (loader->file == NULL)
58 {
59 ERR("Failed to open file %s\n", file);
60 goto error;
61 }
62
63 /* Map the file. */
64 loader->map = eina_file_map_all(loader->file, EINA_FILE_SEQUENTIAL);
65
66 if (loader->map == NULL)
67 {
68 ERR("Failed to create map from file %s\n", file);
69 goto error;
70 }
71
72 return EINA_TRUE;
73
74error:
75 _ply_loader_fini(loader);
76 return EINA_FALSE;
77}
78
79/* create new header */ 27/* create new header */
80static inline PLY_Header 28static inline PLY_Header
81_new_ply_header() 29_new_ply_header()
@@ -230,7 +178,7 @@ _read_header(char *map)//Check properties of mesh in .ply file.
230} 178}
231 179
232void 180void
233evas_model_load_file_ply(Evas_3D_Mesh *mesh, const char *file) 181evas_model_load_file_ply(Evas_3D_Mesh *mesh, Model_Common_Loader *loader)
234{ 182{
235 Evas_3D_Mesh_Data *pd; 183 Evas_3D_Mesh_Data *pd;
236 int i = 0, j = 0, k = 0, count_of_triangles_in_line = 0; 184 int i = 0, j = 0, k = 0, count_of_triangles_in_line = 0;
@@ -241,16 +189,8 @@ evas_model_load_file_ply(Evas_3D_Mesh *mesh, const char *file)
241 float *_vertices_ply = NULL, *_normals_ply = NULL; 189 float *_vertices_ply = NULL, *_normals_ply = NULL;
242 float *_tex_coords_ply = NULL, *_colors_ply = NULL; 190 float *_tex_coords_ply = NULL, *_colors_ply = NULL;
243 char **helping_pointer; 191 char **helping_pointer;
244 PLY_Loader loader;
245 192
246 /* Initialize PLY loader */ 193 header = _read_header(loader->map);
247 if (!_ply_loader_init(&loader, file))
248 {
249 ERR("Failed to initialize PLY loader.");
250 return;
251 }
252
253 header = _read_header(loader.map);
254 194
255 if (!header.existence_of_geometries) 195 if (!header.existence_of_geometries)
256 { 196 {
@@ -258,7 +198,7 @@ evas_model_load_file_ply(Evas_3D_Mesh *mesh, const char *file)
258 return; 198 return;
259 } 199 }
260 200
261 helping_pointer = eina_str_split(loader.map, "end_header\n", 0); 201 helping_pointer = eina_str_split(loader->map, "end_header\n", 0);
262 202
263 if (helping_pointer == NULL) 203 if (helping_pointer == NULL)
264 { 204 {
@@ -284,7 +224,6 @@ evas_model_load_file_ply(Evas_3D_Mesh *mesh, const char *file)
284 (_triangles == NULL)) 224 (_triangles == NULL))
285 { 225 {
286 ERR("Allocate memory is failed."); 226 ERR("Allocate memory is failed.");
287 _ply_loader_fini(&loader);
288 free(_vertices_ply); 227 free(_vertices_ply);
289 free(_normals_ply); 228 free(_normals_ply);
290 free(_tex_coords_ply); 229 free(_tex_coords_ply);
@@ -430,6 +369,5 @@ evas_model_load_file_ply(Evas_3D_Mesh *mesh, const char *file)
430 { 369 {
431 ERR("Axis-Aligned Bounding Box wan't added in frame %d ", 0); 370 ERR("Axis-Aligned Bounding Box wan't added in frame %d ", 0);
432 } 371 }
433
434 _ply_loader_fini(&loader);
435} 372}
373