Model_save_load. Step 8. Entry points to modules is Eina_File. Model_Common_Loader is deleted.
This commit is contained in:
parent
dbf100eb8e
commit
0346ad1a71
|
@ -7,68 +7,28 @@
|
|||
#include "evas_common_private.h"
|
||||
#include "evas_private.h"
|
||||
|
||||
static inline void
|
||||
_model_common_loader_fini(Model_Common_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
|
||||
_model_common_loader_init(Model_Common_Loader *loader, const char *file)
|
||||
{
|
||||
Eina_File *tmp_file = eina_file_open(file, 0);
|
||||
memset(loader, 0x00, sizeof(Model_Common_Loader));
|
||||
|
||||
/* Open given file. */
|
||||
loader->file = eina_file_dup(tmp_file);
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
eina_file_close(tmp_file);
|
||||
return EINA_TRUE;
|
||||
|
||||
error:
|
||||
eina_file_close(tmp_file);
|
||||
_model_common_loader_fini(loader);
|
||||
return EINA_FALSE;
|
||||
}
|
||||
|
||||
void
|
||||
evas_common_load_model_to_file(Evas_3D_Mesh *model, const char *file)
|
||||
{
|
||||
char *p;
|
||||
char *loader_type = NULL;
|
||||
Model_Common_Loader *loader = malloc(sizeof(Model_Common_Loader));
|
||||
|
||||
if (!_model_common_loader_init(loader, file))
|
||||
Eina_File *tmp_file = eina_file_open(file, 0);
|
||||
Eina_File *e_file = eina_file_dup(tmp_file);
|
||||
|
||||
if (e_file == NULL)
|
||||
{
|
||||
ERR("Failed to open file %s\n", file);
|
||||
eina_file_close(tmp_file);
|
||||
eina_file_close(e_file);
|
||||
e_file = NULL;
|
||||
file = NULL;
|
||||
ERR("Failed to initialize loader.");
|
||||
return;
|
||||
}
|
||||
|
||||
eina_file_close(tmp_file);
|
||||
|
||||
p = strrchr(file, '.');
|
||||
if (p)
|
||||
{
|
||||
|
@ -76,7 +36,7 @@ evas_common_load_model_to_file(Evas_3D_Mesh *model, const char *file)
|
|||
#define CHECK_EXTENTION_BY_FILE_NAME(extention) \
|
||||
if (!strcasecmp(p, #extention)) \
|
||||
{ \
|
||||
evas_model_load_file_##extention(model, loader); \
|
||||
evas_model_load_file_##extention(model, e_file); \
|
||||
loader_type = #extention; \
|
||||
}
|
||||
CHECK_EXTENTION_BY_FILE_NAME(eet)
|
||||
|
@ -87,7 +47,6 @@ evas_common_load_model_to_file(Evas_3D_Mesh *model, const char *file)
|
|||
}
|
||||
if (!loader_type) ERR("Invalid mesh file type.");
|
||||
|
||||
_model_common_loader_fini(loader);
|
||||
free(loader);
|
||||
eina_file_close(e_file);
|
||||
e_file = NULL;
|
||||
}
|
||||
|
||||
|
|
|
@ -158,14 +158,6 @@ struct _Evas_3D_File_Eet
|
|||
Evas_3D_Header_Eet *header;
|
||||
};//contain mesh data and information about mesh size
|
||||
|
||||
typedef struct _Model_Common_Loader Model_Common_Loader;
|
||||
|
||||
struct _Model_Common_Loader
|
||||
{
|
||||
Eina_File *file;
|
||||
char *map;
|
||||
};
|
||||
|
||||
typedef Eina_Bool (*Evas_3D_Node_Func)(Evas_3D_Node *, void *data);
|
||||
|
||||
|
||||
|
@ -1647,10 +1639,10 @@ void _evas_3d_eet_file_free(void);
|
|||
/* Temporary save/load functions */
|
||||
void evas_common_load_model_to_file(Evas_3D_Mesh *model, const char *file);
|
||||
void evas_common_save_model_to_file(Evas_3D_Mesh *model, const char *file, Evas_3D_Mesh_Frame *f);
|
||||
void evas_model_load_file_eet(Evas_3D_Mesh *mesh, Model_Common_Loader *loader);
|
||||
void evas_model_load_file_md2(Evas_3D_Mesh *mesh, Model_Common_Loader *loader);
|
||||
void evas_model_load_file_obj(Evas_3D_Mesh *mesh, Model_Common_Loader *loader);
|
||||
void evas_model_load_file_ply(Evas_3D_Mesh *mesh, Model_Common_Loader *loader);
|
||||
void evas_model_load_file_eet(Evas_3D_Mesh *mesh, Eina_File *file);
|
||||
void evas_model_load_file_md2(Evas_3D_Mesh *mesh, Eina_File *file);
|
||||
void evas_model_load_file_obj(Evas_3D_Mesh *mesh, Eina_File *file);
|
||||
void evas_model_load_file_ply(Evas_3D_Mesh *mesh, Eina_File *file);
|
||||
void evas_model_save_file_eet(Evas_3D_Mesh *mesh, const char *file, Evas_3D_Mesh_Frame *f);
|
||||
void evas_model_save_file_obj(Evas_3D_Mesh *mesh, const char *file, Evas_3D_Mesh_Frame *f);
|
||||
void evas_model_save_file_ply(Evas_3D_Mesh *mesh, const char *file, Evas_3D_Mesh_Frame *f);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue