diff options
Diffstat (limited to 'src/others/mimesh/libg3d-0.0.8/plugins/import/imp_dae/imp_dae.c')
-rw-r--r-- | src/others/mimesh/libg3d-0.0.8/plugins/import/imp_dae/imp_dae.c | 126 |
1 files changed, 126 insertions, 0 deletions
diff --git a/src/others/mimesh/libg3d-0.0.8/plugins/import/imp_dae/imp_dae.c b/src/others/mimesh/libg3d-0.0.8/plugins/import/imp_dae/imp_dae.c new file mode 100644 index 0000000..c478d6e --- /dev/null +++ b/src/others/mimesh/libg3d-0.0.8/plugins/import/imp_dae/imp_dae.c | |||
@@ -0,0 +1,126 @@ | |||
1 | /* $Id$ */ | ||
2 | |||
3 | /* | ||
4 | libg3d - 3D object loading library | ||
5 | |||
6 | Copyright (C) 2005-2009 Markus Dahms <mad@automagically.de> | ||
7 | |||
8 | This library is free software; you can redistribute it and/or | ||
9 | modify it under the terms of the GNU Lesser General Public | ||
10 | License as published by the Free Software Foundation; either | ||
11 | version 2.1 of the License, or (at your option) any later version. | ||
12 | |||
13 | This library is distributed in the hope that it will be useful, | ||
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
16 | Lesser General Public License for more details. | ||
17 | |||
18 | You should have received a copy of the GNU Lesser General Public | ||
19 | License along with this library; if not, write to the Free Software | ||
20 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | ||
21 | */ | ||
22 | |||
23 | #include <string.h> | ||
24 | #include <locale.h> | ||
25 | |||
26 | #include <libxml/parser.h> | ||
27 | #include <libxml/tree.h> | ||
28 | |||
29 | #include <g3d/stream.h> | ||
30 | #include <g3d/types.h> | ||
31 | |||
32 | #include "imp_dae_xml.h" | ||
33 | #include "imp_dae_library.h" | ||
34 | #include "imp_dae_cb.h" | ||
35 | |||
36 | static int dae_input_read_cb(gpointer ctx, gchar *buffer, gint len) | ||
37 | { | ||
38 | return g3d_stream_read((G3DStream *)ctx, buffer, len); | ||
39 | } | ||
40 | |||
41 | static gboolean dae_load_scene(G3DContext *context, G3DStream *stream, | ||
42 | G3DModel *model, DaeLibrary *lib, xmlDocPtr xmldoc); | ||
43 | |||
44 | /*****************************************************************************/ | ||
45 | |||
46 | EAPI | ||
47 | gboolean plugin_load_model_from_stream(G3DContext *context, G3DStream *stream, | ||
48 | G3DModel *model, gpointer user_data) | ||
49 | { | ||
50 | xmlDocPtr xmldoc; | ||
51 | DaeLibrary *lib; | ||
52 | gboolean retval = FALSE; | ||
53 | |||
54 | setlocale(LC_NUMERIC, "C"); | ||
55 | xmlInitParser(); | ||
56 | |||
57 | xmldoc = xmlReadIO(dae_input_read_cb, NULL, stream, stream->uri, NULL, 0); | ||
58 | if(xmldoc) { | ||
59 | lib = dae_library_load(xmldoc); | ||
60 | retval = dae_load_scene(context, stream, model, lib, xmldoc); | ||
61 | |||
62 | dae_library_cleanup(lib); | ||
63 | xmlFreeDoc(xmldoc); | ||
64 | } | ||
65 | |||
66 | xmlCleanupParser(); | ||
67 | return retval; | ||
68 | } | ||
69 | |||
70 | EAPI | ||
71 | gchar *plugin_description(void) | ||
72 | { | ||
73 | return g_strdup("COLLADA models."); | ||
74 | } | ||
75 | |||
76 | EAPI | ||
77 | gchar **plugin_extensions(void) | ||
78 | { | ||
79 | return g_strsplit("dae", ":", 0); | ||
80 | } | ||
81 | |||
82 | /*****************************************************************************/ | ||
83 | /* COLLADA specific stuff */ | ||
84 | |||
85 | static gboolean dae_load_scene(G3DContext *context, G3DStream *stream, | ||
86 | G3DModel *model, DaeLibrary *lib, xmlDocPtr xmldoc) | ||
87 | { | ||
88 | DaeGlobalData *global; | ||
89 | DaeLocalData *local; | ||
90 | xmlNodePtr scenenode, node = NULL, instance = NULL; | ||
91 | gchar *name; | ||
92 | |||
93 | scenenode = dae_xml_get_child_by_tagname( | ||
94 | xmlDocGetRootElement(xmldoc), "scene"); | ||
95 | |||
96 | if(scenenode == NULL) { | ||
97 | g_warning("DAE: could not get scene node"); | ||
98 | return FALSE; | ||
99 | } | ||
100 | |||
101 | global = g_new0(DaeGlobalData, 1); | ||
102 | global->context = context; | ||
103 | global->stream = stream; | ||
104 | global->model = model; | ||
105 | global->xmldoc = xmldoc; | ||
106 | global->lib = lib; | ||
107 | |||
108 | while(dae_xml_next_child(lib, scenenode, &node, &instance, &name)) { | ||
109 | #if DEBUG > 2 | ||
110 | g_debug("DAE: got node %s", name); | ||
111 | #endif | ||
112 | if(strcmp(name, "visual_scene") == 0) { | ||
113 | local = g_new0(DaeLocalData, 1); | ||
114 | local->node = node; | ||
115 | local->instance = instance; | ||
116 | local->parent = scenenode; | ||
117 | dae_cb_visual_scene(global, local); | ||
118 | g_free(local); | ||
119 | } | ||
120 | g_free(name); | ||
121 | } | ||
122 | |||
123 | g_free(global); | ||
124 | |||
125 | return TRUE; | ||
126 | } | ||