aboutsummaryrefslogtreecommitdiffstats
path: root/src/modules/evas/model_loaders
diff options
context:
space:
mode:
authorBogdan Devichev <b.devichev@samsung.com>2014-12-10 18:31:20 +0200
committerCedric BAIL <cedric@osg.samsung.com>2014-12-23 21:20:20 +0100
commit61aab62be0e17fd58405debbc0f6befae66e64c8 (patch)
tree04b0b3ed39562f702fc0686a3e9d044ab5977579 /src/modules/evas/model_loaders
parentevas: entry points to modules is new struct with Eina_file, not const char *f... (diff)
downloadefl-61aab62be0e17fd58405debbc0f6befae66e64c8.tar.gz
evas: entry points to modules is Eina_File. Model_Common_Loader is deleted.
Diffstat (limited to 'src/modules/evas/model_loaders')
-rw-r--r--src/modules/evas/model_loaders/eet/evas_model_load_eet.c4
-rw-r--r--src/modules/evas/model_loaders/md2/evas_model_load_md2.c33
-rw-r--r--src/modules/evas/model_loaders/obj/evas_model_load_obj.c28
-rw-r--r--src/modules/evas/model_loaders/ply/evas_model_load_ply.c22
4 files changed, 64 insertions, 23 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 572e085830..b393787b8f 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, Model_Common_Loader *loader)
+evas_model_load_file_eet(Evas_3D_Mesh *mesh, Eina_File *file)
{
Eet_File *ef;
_evas_3d_eet_file_init();
- ef = eet_open(eina_file_filename_get(loader->file), EET_FILE_MODE_READ);
+ ef = eet_open(eina_file_filename_get(file), EET_FILE_MODE_READ);
eet_file = eet_data_read(ef,
_file_descriptor,
EVAS_3D_FILE_CACHE_FILE_ENTRY);
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 a7fddc7ec3..98989abed1 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,7 +67,7 @@ struct PACKED _MD2_Texcoord
typedef struct _MD2_Loader
{
- Model_Common_Loader *common_loader;
+ char *map;
int size;
int skin_width;
@@ -252,21 +252,28 @@ static const float normal_table[162][3] =
};
static inline Eina_Bool
-_md2_loader_init(MD2_Loader *loader, Model_Common_Loader *common_loader)
+_md2_loader_init(MD2_Loader *loader, Eina_File *file)
{
MD2_Header header;
memset(loader, 0x00, sizeof(MD2_Loader));
- loader->common_loader = common_loader;
+
+ loader->map = eina_file_map_all(file, EINA_FILE_SEQUENTIAL);
+
+ if (loader->map == NULL)
+ {
+ ERR("Failed to create map from file %s\n", eina_file_filename_get(file));
+ goto error;
+ }
/* Check file size. We require a file larger than MD2 header size. */
- loader->size = eina_file_size_get(loader->common_loader->file);
+ loader->size = eina_file_size_get(file);
if (loader->size < (int)sizeof(MD2_Header))
goto error;
/* Read header. */
- memcpy(&header, loader->common_loader->map, sizeof(MD2_Header));
+ memcpy(&header, loader->map, sizeof(MD2_Header));
/* Check identity */
if (header.magic != MD2_MAGIC_NUMBER || header.version != MD2_VERSION)
@@ -296,14 +303,14 @@ _md2_loader_init(MD2_Loader *loader, Model_Common_Loader *common_loader)
loader->frame_count = header.frame_count;
loader->frame_size = header.frame_size;
- loader->frames = loader->common_loader->map + header.offset_frames;
+ loader->frames = 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->common_loader->map + header.offset_triangles);
- loader->texcoords = (MD2_Texcoord *)(loader->common_loader->map + header.offset_texcoords);
+ loader->triangles = (MD2_Triangle *)(loader->map + header.offset_triangles);
+ loader->texcoords = (MD2_Texcoord *)(loader->map + header.offset_texcoords);
return EINA_TRUE;
error:
@@ -311,7 +318,7 @@ error:
}
void
-evas_model_load_file_md2(Evas_3D_Mesh *mesh, Model_Common_Loader *common_loader)
+evas_model_load_file_md2(Evas_3D_Mesh *mesh, Eina_File *file)
{
MD2_Loader loader;
int i, j, k;
@@ -321,7 +328,7 @@ evas_model_load_file_md2(Evas_3D_Mesh *mesh, Model_Common_Loader *common_loader)
Evas_3D_Mesh_Data *pd;
/* Initialize MD2 loader (Open file and read MD2 head ant etc) */
- if (!_md2_loader_init(&loader, common_loader))
+ if (!_md2_loader_init(&loader, file))
{
ERR("Failed to initialize MD2 loader.");
return;
@@ -409,5 +416,11 @@ evas_model_load_file_md2(Evas_3D_Mesh *mesh, Model_Common_Loader *common_loader)
ERR("Axis-Aligned Bounding Box wasn't added in frame %d ", f);
}
}
+
+ if (loader.map)
+ {
+ eina_file_map_free(file, loader.map);
+ loader.map = NULL;
+ }
}
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 7c6869e52d..64c4eb9e58 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
@@ -83,11 +83,11 @@ _analyze_face_line(char * face_analyzer,
}
static inline OBJ_Counts
-_count_elements(Model_Common_Loader *loader)//count elements of mesh in .obj
+_count_elements(char *map)//count elements of mesh in .obj
{
OBJ_Counts counts = _new_count_elements();
- char * current = loader->map;
+ char *current = 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;
@@ -178,7 +178,7 @@ _count_elements(Model_Common_Loader *loader)//count elements of mesh in .obj
}
void
-evas_model_load_file_obj(Evas_3D_Mesh *mesh, Model_Common_Loader *loader)
+evas_model_load_file_obj(Evas_3D_Mesh *mesh, Eina_File *file)
{
long i;
OBJ_Counts counts;//count elements of mesh in .obj
@@ -188,9 +188,17 @@ evas_model_load_file_obj(Evas_3D_Mesh *mesh, Model_Common_Loader *loader)
float *pos, *nor, *tex;
int stride_pos, stride_nor, stride_tex;
int j, k;
- char * current;
+ char *current, *map;
- counts = _count_elements(loader);
+ map = eina_file_map_all(file, EINA_FILE_SEQUENTIAL);
+
+ if (map == NULL)
+ {
+ ERR("Failed to create map from file %s\n", eina_file_filename_get(file));
+ return;
+ }
+
+ counts = _count_elements(map);
float *_vertices_obj = malloc(counts._vertex_counter * 3 * sizeof(float));
float *_normales_obj = malloc(counts._normal_counter * 3 * sizeof(float));
@@ -198,7 +206,7 @@ evas_model_load_file_obj(Evas_3D_Mesh *mesh, Model_Common_Loader *loader)
/* 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 ((map == NULL) || (_vertices_obj == NULL) ||
(_normales_obj == NULL) || (_tex_coords_obj == NULL) || (_triangles == NULL))
{
ERR("Allocate memory is failed.");
@@ -209,7 +217,7 @@ evas_model_load_file_obj(Evas_3D_Mesh *mesh, Model_Common_Loader *loader)
return;
}
- current = loader->map;
+ current = map;
i = 0;
/* put data to arrays */
@@ -373,5 +381,11 @@ evas_model_load_file_obj(Evas_3D_Mesh *mesh, Model_Common_Loader *loader)
{
ERR("Axis-Aligned Bounding Box wan't added in frame %d ", 0);
}
+
+ if (map)
+ {
+ eina_file_map_free(file, map);
+ map = NULL;
+ }
}
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 246f7cd26e..0eac908dd8 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
@@ -178,19 +178,27 @@ _read_header(char *map)//Check properties of mesh in .ply file.
}
void
-evas_model_load_file_ply(Evas_3D_Mesh *mesh, Model_Common_Loader *loader)
+evas_model_load_file_ply(Evas_3D_Mesh *mesh, Eina_File *file)
{
Evas_3D_Mesh_Data *pd;
int i = 0, j = 0, k = 0, count_of_triangles_in_line = 0;
float *pos, *nor, *tex, *col;
int stride_pos, stride_nor, stride_tex, stride_col;
- char *current;
+ char *current, *map;
PLY_Header header;
float *_vertices_ply = NULL, *_normals_ply = NULL;
float *_tex_coords_ply = NULL, *_colors_ply = NULL;
char **helping_pointer;
- header = _read_header(loader->map);
+ map = eina_file_map_all(file, EINA_FILE_SEQUENTIAL);
+
+ if (map == NULL)
+ {
+ ERR("Failed to create map from file %s\n", eina_file_filename_get(file));
+ return;
+ }
+
+ header = _read_header(map);
if (!header.existence_of_geometries)
{
@@ -198,7 +206,7 @@ evas_model_load_file_ply(Evas_3D_Mesh *mesh, Model_Common_Loader *loader)
return;
}
- helping_pointer = eina_str_split(loader->map, "end_header\n", 0);
+ helping_pointer = eina_str_split(map, "end_header\n", 0);
if (helping_pointer == NULL)
{
@@ -369,5 +377,11 @@ evas_model_load_file_ply(Evas_3D_Mesh *mesh, Model_Common_Loader *loader)
{
ERR("Axis-Aligned Bounding Box wan't added in frame %d ", 0);
}
+
+ if (map)
+ {
+ eina_file_map_free(file, map);
+ map = NULL;
+ }
}