aboutsummaryrefslogtreecommitdiffstats
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
parentevas: ply_loader and obj_loader work with Eina_File. (diff)
downloadefl-17baa3fa6f87227fdba4caaea5e5c2a39257f5bb.tar.gz
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 fadd6aacd9..572e085830 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,
}
void
-evas_model_load_file_eet(Evas_3D_Mesh *mesh, const char *file)
+evas_model_load_file_eet(Evas_3D_Mesh *mesh, Model_Common_Loader *loader)
{
Eet_File *ef;
_evas_3d_eet_file_init();
- ef = eet_open(file, EET_FILE_MODE_READ);
+ ef = eet_open(eina_file_filename_get(loader->file), EET_FILE_MODE_READ);
eet_file = eet_data_read(ef,
_file_descriptor,
EVAS_3D_FILE_CACHE_FILE_ENTRY);
@@ -129,3 +129,4 @@ evas_model_load_file_eet(Evas_3D_Mesh *mesh, const char *file)
_evas_3d_eet_file_free();
}
+
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 11d28451f5..a7fddc7ec3 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
typedef struct _MD2_Loader
{
- Eina_File *file;
- char *map;
- int size;
+ Model_Common_Loader *common_loader;
+ int size;
- int skin_width;
- int skin_height;
+ int skin_width;
+ int skin_height;
- int frame_count;
- int frame_size;
- char *frames;
+ int frame_count;
+ int frame_size;
+ char *frames;
- int vertex_count;
- int triangle_count;
- int texcoord_count;
+ int vertex_count;
+ int triangle_count;
+ int texcoord_count;
- MD2_Triangle *triangles;
- MD2_Texcoord *texcoords;
+ MD2_Triangle *triangles;
+ MD2_Texcoord *texcoords;
} MD2_Loader;
static const float normal_table[162][3] =
@@ -252,52 +251,22 @@ static const float normal_table[162][3] =
{-0.688191f, -0.587785f, -0.425325f},
};
-static inline void
-_md2_loader_fini(MD2_Loader *loader)
-{
- if (loader->map)
- {
- eina_file_map_free(loader->file, loader->map);
- loader->map = NULL;
- }
-
- if (loader->file)
- {
- eina_file_close(loader->file);
- loader->file = NULL;
- }
-}
-
static inline Eina_Bool
-_md2_loader_init(MD2_Loader *loader, const char *file)
+_md2_loader_init(MD2_Loader *loader, Model_Common_Loader *common_loader)
{
MD2_Header header;
memset(loader, 0x00, sizeof(MD2_Loader));
-
- /* Open given file. */
- loader->file = eina_file_open(file, 0);
-
- if (loader->file == NULL)
- {
- ERR("Failed to open file %s\n", file);
- goto error;
- }
+ loader->common_loader = common_loader;
/* Check file size. We require a file larger than MD2 header size. */
- loader->size = eina_file_size_get(loader->file);
+ loader->size = eina_file_size_get(loader->common_loader->file);
if (loader->size < (int)sizeof(MD2_Header))
goto error;
- /* Map the file. */
- loader->map = eina_file_map_all(loader->file, EINA_FILE_SEQUENTIAL);
-
- if (loader->map == NULL)
- goto error;
-
/* Read header. */
- memcpy(&header, loader->map, sizeof(MD2_Header));
+ memcpy(&header, loader->common_loader->map, sizeof(MD2_Header));
/* Check identity */
if (header.magic != MD2_MAGIC_NUMBER || header.version != MD2_VERSION)
@@ -327,23 +296,22 @@ _md2_loader_init(MD2_Loader *loader, const char *file)
loader->frame_count = header.frame_count;
loader->frame_size = header.frame_size;
- loader->frames = loader->map + header.offset_frames;
+ loader->frames = loader->common_loader->map + header.offset_frames;
loader->vertex_count = header.vertex_count;
loader->triangle_count = header.triangle_count;
loader->texcoord_count = header.texcoord_count;
- loader->triangles = (MD2_Triangle *)(loader->map + header.offset_triangles);
- loader->texcoords = (MD2_Texcoord *)(loader->map + header.offset_texcoords);
+ loader->triangles = (MD2_Triangle *)(loader->common_loader->map + header.offset_triangles);
+ loader->texcoords = (MD2_Texcoord *)(loader->common_loader->map + header.offset_texcoords);
return EINA_TRUE;
error:
- _md2_loader_fini(loader);
return EINA_FALSE;
}
void
-evas_model_load_file_md2(Evas_3D_Mesh *mesh, const char *file)
+evas_model_load_file_md2(Evas_3D_Mesh *mesh, Model_Common_Loader *common_loader)
{
MD2_Loader loader;
int i, j, k;
@@ -353,7 +321,7 @@ evas_model_load_file_md2(Evas_3D_Mesh *mesh, const char *file)
Evas_3D_Mesh_Data *pd;
/* Initialize MD2 loader (Open file and read MD2 head ant etc) */
- if (!_md2_loader_init(&loader, file))
+ if (!_md2_loader_init(&loader, common_loader))
{
ERR("Failed to initialize MD2 loader.");
return;
@@ -441,6 +409,5 @@ evas_model_load_file_md2(Evas_3D_Mesh *mesh, const char *file)
ERR("Axis-Aligned Bounding Box wasn't added in frame %d ", f);
}
}
-
- _md2_loader_fini(&loader);
}
+
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 359d29904e..7c6869e52d 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
Eina_Bool existence_of_tex_point;
};
-typedef struct _OBJ_Loader
-{
- Eina_File *file;
- char *map;
-} OBJ_Loader;
-
-static inline void
-_obj_loader_fini(OBJ_Loader *loader)
-{
- if (loader->map)
- {
- eina_file_map_free(loader->file, loader->map);
- loader->map = NULL;
- }
-
- if (loader->file)
- {
- eina_file_close(loader->file);
- loader->file = NULL;
- }
-}
-
-static inline Eina_Bool
-_obj_loader_init(OBJ_Loader *loader, const char *file)
-{
- memset(loader, 0x00, sizeof(OBJ_Loader));
-
- /* Open given file. */
- loader->file = eina_file_open(file, 0);
-
- if (loader->file == NULL)
- {
- ERR("Failed to open file %s\n", file);
- goto error;
- }
-
- /* Map the file. */
- loader->map = eina_file_map_all(loader->file, EINA_FILE_SEQUENTIAL);
-
- if (loader->map == NULL)
- {
- ERR("Failed to create map from file %s\n", file);
- goto error;
- }
-
- return EINA_TRUE;
-
-error:
- _obj_loader_fini(loader);
- return EINA_FALSE;
-}
-
/* create new counter */
static inline OBJ_Counts
_new_count_elements()
@@ -135,11 +83,11 @@ _analyze_face_line(char * face_analyzer,
}
static inline OBJ_Counts
-_count_elements(OBJ_Loader loader)//count elements of mesh in .obj
+_count_elements(Model_Common_Loader *loader)//count elements of mesh in .obj
{
OBJ_Counts counts = _new_count_elements();
- char * current = loader.map;
+ char * current = loader->map;
int polygon_checker = -2;//polygons with n vertices can be represented as n-2 triangles
Eina_Bool will_check_next_char = EINA_FALSE;
Eina_Bool first_char_is_v = EINA_FALSE;
@@ -230,11 +178,10 @@ _count_elements(OBJ_Loader loader)//count elements of mesh in .obj
}
void
-evas_model_load_file_obj(Evas_3D_Mesh *mesh, const char *file)
+evas_model_load_file_obj(Evas_3D_Mesh *mesh, Model_Common_Loader *loader)
{
long i;
OBJ_Counts counts;//count elements of mesh in .obj
- OBJ_Loader loader;
Eina_Bool will_check_next_char = EINA_FALSE;
Eina_Bool first_char_is_v = EINA_FALSE;
Eina_Bool first_char_is_f = EINA_FALSE;
@@ -243,13 +190,6 @@ evas_model_load_file_obj(Evas_3D_Mesh *mesh, const char *file)
int j, k;
char * current;
- /* Initialize PLY loader */
- if (!_obj_loader_init(&loader, file))
- {
- ERR("Failed to initialize PLY loader.");
- return;
- }
-
counts = _count_elements(loader);
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)
/* triangle has 3 points, every point has 3(vertix, texture and normal) coord */
int *_triangles = malloc(counts._triangles_counter * 9 * sizeof(int));
- if ((loader.map == NULL) || (_vertices_obj == NULL) ||
+ if ((loader->map == NULL) || (_vertices_obj == NULL) ||
(_normales_obj == NULL) || (_tex_coords_obj == NULL) || (_triangles == NULL))
{
ERR("Allocate memory is failed.");
- _obj_loader_fini(&loader);
free(_vertices_obj);
free(_normales_obj);
free(_tex_coords_obj);
@@ -270,7 +209,7 @@ evas_model_load_file_obj(Evas_3D_Mesh *mesh, const char *file)
return;
}
- current = loader.map;
+ current = loader->map;
i = 0;
/* put data to arrays */
@@ -434,5 +373,5 @@ evas_model_load_file_obj(Evas_3D_Mesh *mesh, const char *file)
{
ERR("Axis-Aligned Bounding Box wan't added in frame %d ", 0);
}
- _obj_loader_fini(&loader);
}
+
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 45e28a0de3..246f7cd26e 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
Eina_Bool existence_of_colors;
};
-typedef struct _PLY_Loader
-{
- Eina_File *file;
- char *map;
-} PLY_Loader;
-
-static inline void
-_ply_loader_fini(PLY_Loader *loader)
-{
- if (loader->map)
- {
- eina_file_map_free(loader->file, loader->map);
- loader->map = NULL;
- }
-
- if (loader->file)
- {
- eina_file_close(loader->file);
- loader->file = NULL;
- }
-}
-
-static inline Eina_Bool
-_ply_loader_init(PLY_Loader *loader, const char *file)
-{
- memset(loader, 0x00, sizeof(PLY_Loader));
-
- /* Open given file. */
- loader->file = eina_file_open(file, 0);
-
- if (loader->file == NULL)
- {
- ERR("Failed to open file %s\n", file);
- goto error;
- }
-
- /* Map the file. */
- loader->map = eina_file_map_all(loader->file, EINA_FILE_SEQUENTIAL);
-
- if (loader->map == NULL)
- {
- ERR("Failed to create map from file %s\n", file);
- goto error;
- }
-
- return EINA_TRUE;
-
-error:
- _ply_loader_fini(loader);
- return EINA_FALSE;
-}
-
/* create new header */
static inline PLY_Header
_new_ply_header()
@@ -230,7 +178,7 @@ _read_header(char *map)//Check properties of mesh in .ply file.
}
void
-evas_model_load_file_ply(Evas_3D_Mesh *mesh, const char *file)
+evas_model_load_file_ply(Evas_3D_Mesh *mesh, Model_Common_Loader *loader)
{
Evas_3D_Mesh_Data *pd;
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)
float *_vertices_ply = NULL, *_normals_ply = NULL;
float *_tex_coords_ply = NULL, *_colors_ply = NULL;
char **helping_pointer;
- PLY_Loader loader;
- /* Initialize PLY loader */
- if (!_ply_loader_init(&loader, file))
- {
- ERR("Failed to initialize PLY loader.");
- return;
- }
-
- header = _read_header(loader.map);
+ header = _read_header(loader->map);
if (!header.existence_of_geometries)
{
@@ -258,7 +198,7 @@ evas_model_load_file_ply(Evas_3D_Mesh *mesh, const char *file)
return;
}
- helping_pointer = eina_str_split(loader.map, "end_header\n", 0);
+ helping_pointer = eina_str_split(loader->map, "end_header\n", 0);
if (helping_pointer == NULL)
{
@@ -284,7 +224,6 @@ evas_model_load_file_ply(Evas_3D_Mesh *mesh, const char *file)
(_triangles == NULL))
{
ERR("Allocate memory is failed.");
- _ply_loader_fini(&loader);
free(_vertices_ply);
free(_normals_ply);
free(_tex_coords_ply);
@@ -430,6 +369,5 @@ evas_model_load_file_ply(Evas_3D_Mesh *mesh, const char *file)
{
ERR("Axis-Aligned Bounding Box wan't added in frame %d ", 0);
}
-
- _ply_loader_fini(&loader);
}
+