summaryrefslogtreecommitdiff
path: root/src/lib/evas/common/evas_model_load.c
blob: bef10ba28c568d2e5b139fc5651fa81d51e3bfe4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif

#include "evas_options.h"

#include "evas_common_private.h"
#include "evas_private.h"

void
_evas_common_load_model(Evas_3D_Mesh *model,
                        Eina_File *file,
                        const char *file_path)
{
   char *p;
   char *loader_type = NULL;

   p = strrchr(file_path, '.');
   if (p)
     {
        p++;
#define CHECK_EXTENTION_BY_FILE_NAME(extention)                \
        if (!strcasecmp(p, #extention))                        \
          {                                                    \
             evas_model_load_file_##extention(model, file);    \
             loader_type = #extention;                         \
          }
        CHECK_EXTENTION_BY_FILE_NAME(eet)
        CHECK_EXTENTION_BY_FILE_NAME(md2)
        CHECK_EXTENTION_BY_FILE_NAME(obj)
        CHECK_EXTENTION_BY_FILE_NAME(ply)
#undef CHECK_EXTENTION_BY_FILE_NAME
     }
   if (!loader_type) ERR("Invalid mesh file type.");
}

void
evas_common_load_model_from_file(Evas_3D_Mesh *model, const char *file)
{
   Eina_File *tmp_file = eina_file_open(file, 0);

   if (tmp_file == NULL)
     {
        ERR("Failed to open file %s\n", file);
        ERR("Failed to initialize loader.");
        return;
     }

   Eina_File *e_file = eina_file_dup(tmp_file);

   if (e_file == NULL)
     {
        eina_file_close(tmp_file);
        file = NULL;
        ERR("Failed to initialize loader.");
        return;
     }

   eina_file_close(tmp_file);

   _evas_common_load_model(model, e_file, file);

   eina_file_close(e_file);
   e_file = NULL;
}

void
evas_common_load_model_from_eina_file(Evas_3D_Mesh *model, Eina_File *file)
{
   Eina_File *e_file = eina_file_dup(file);

   if (e_file == NULL)
     {
        ERR("Failed to initialize loader.");
        return;
     }

   _evas_common_load_model(model, e_file, eina_file_filename_get(e_file));

   eina_file_close(e_file);
   e_file = NULL;
}