summaryrefslogtreecommitdiff
path: root/src/lib/evas/common/evas_model_load.c
blob: 0598d31e211af09a6984007b4079486bf4bd443d (plain) (blame)
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
#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_to_file(Evas_3D_Mesh *model, const char *file)
{
   char *p;
   char *loader_type = NULL;

   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)
     {
        p++;
#define CHECK_EXTENTION_BY_FILE_NAME(extention)                \
        if (!strcasecmp(p, #extention))                        \
          {                                                    \
             evas_model_load_file_##extention(model, e_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.");

   eina_file_close(e_file);
   e_file = NULL;
}