summaryrefslogtreecommitdiff
path: root/src/lib/evas/common3d
diff options
context:
space:
mode:
authorBogdan Devichev <b.devichev@samsung.com>2015-11-09 14:44:36 -0800
committerCedric BAIL <cedric@osg.samsung.com>2015-11-09 15:27:26 -0800
commitf416f5adde537ec55f513230ef4907d0cd67f0cd (patch)
tree5f8f44c6a05fe357b30d5f02513c04b99e91f834 /src/lib/evas/common3d
parent3d77f55f910a844b45019238ed458bf62e6c1c20 (diff)
evas: move model save/load from common to common3d.
Summary: Move model save/load to common3d. Here also will be common algorithms and structures which will be used in all loaders and savers. See task https://phab.enlightenment.org/T2713. Reviewers: cedric, Hermet, raster, Oleksander Subscribers: cedric Differential Revision: https://phab.enlightenment.org/D3030 Signed-off-by: Cedric BAIL <cedric@osg.samsung.com>
Diffstat (limited to 'src/lib/evas/common3d')
-rw-r--r--src/lib/evas/common3d/save_load/evas_model_load.c82
-rw-r--r--src/lib/evas/common3d/save_load/evas_model_save.c34
2 files changed, 116 insertions, 0 deletions
diff --git a/src/lib/evas/common3d/save_load/evas_model_load.c b/src/lib/evas/common3d/save_load/evas_model_load.c
new file mode 100644
index 0000000000..f7c21ccc40
--- /dev/null
+++ b/src/lib/evas/common3d/save_load/evas_model_load.c
@@ -0,0 +1,82 @@
1#ifdef HAVE_CONFIG_H
2# include "config.h"
3#endif
4
5#include "evas_options.h"
6
7#include "evas_common_private.h"
8#include "evas_private.h"
9
10void
11_evas_common_load_model(Evas_Canvas3D_Mesh *model,
12 Eina_File *file,
13 const char *file_path)
14{
15 char *p;
16 char *loader_type = NULL;
17
18 p = strrchr(file_path, '.');
19 if (p)
20 {
21 p++;
22#define CHECK_EXTENTION_BY_FILE_NAME(extention) \
23 if (!strcasecmp(p, #extention)) \
24 { \
25 evas_model_load_file_##extention(model, file); \
26 loader_type = #extention; \
27 }
28 CHECK_EXTENTION_BY_FILE_NAME(eet)
29 CHECK_EXTENTION_BY_FILE_NAME(md2)
30 CHECK_EXTENTION_BY_FILE_NAME(obj)
31 CHECK_EXTENTION_BY_FILE_NAME(ply)
32#undef CHECK_EXTENTION_BY_FILE_NAME
33 }
34 if (!loader_type) ERR("Invalid mesh file type.");
35}
36
37void
38evas_common_load_model_from_file(Evas_Canvas3D_Mesh *model, const char *file)
39{
40 Eina_File *tmp_file = eina_file_open(file, 0);
41
42 if (tmp_file == NULL)
43 {
44 ERR("Failed to open file %s\n", file);
45 ERR("Failed to initialize loader.");
46 return;
47 }
48
49 Eina_File *e_file = eina_file_dup(tmp_file);
50
51 if (e_file == NULL)
52 {
53 eina_file_close(tmp_file);
54 file = NULL;
55 ERR("Failed to initialize loader.");
56 return;
57 }
58
59 eina_file_close(tmp_file);
60
61 _evas_common_load_model(model, e_file, file);
62
63 eina_file_close(e_file);
64 e_file = NULL;
65}
66
67void
68evas_common_load_model_from_eina_file(Evas_Canvas3D_Mesh *model, const Eina_File *file)
69{
70 Eina_File *e_file = eina_file_dup(file);
71
72 if (e_file == NULL)
73 {
74 ERR("Failed to initialize loader.");
75 return;
76 }
77
78 _evas_common_load_model(model, e_file, eina_file_filename_get(e_file));
79
80 eina_file_close(e_file);
81 e_file = NULL;
82}
diff --git a/src/lib/evas/common3d/save_load/evas_model_save.c b/src/lib/evas/common3d/save_load/evas_model_save.c
new file mode 100644
index 0000000000..caf72ca400
--- /dev/null
+++ b/src/lib/evas/common3d/save_load/evas_model_save.c
@@ -0,0 +1,34 @@
1#ifdef HAVE_CONFIG_H
2# include "config.h"
3#endif
4
5#include "evas_options.h"
6
7#include "evas_common_private.h"
8#include "evas_private.h"
9
10void
11evas_common_save_model_to_file(const Evas_Canvas3D_Mesh *model,
12 const char *file,
13 Evas_Canvas3D_Mesh_Frame *f)
14{
15 char *p;
16 char *saver = NULL;
17
18 p = strrchr(file, '.');
19 if (p)
20 {
21 p++;
22#define CHECK_EXTENTION_BY_FILE_NAME(extention) \
23 if (!strcasecmp(p, #extention)) \
24 { \
25 evas_model_save_file_##extention(model, file, f); \
26 saver = #extention; \
27 }
28 CHECK_EXTENTION_BY_FILE_NAME(eet)
29 CHECK_EXTENTION_BY_FILE_NAME(obj)
30 CHECK_EXTENTION_BY_FILE_NAME(ply)
31#undef CHECK_EXTENTION_BY_FILE_NAME
32 }
33 if (!saver) ERR("Invalid mesh file type.");
34}