diff options
Diffstat (limited to 'src/others/mimesh/libg3d-0.0.8/plugins/import/imp_ldraw/imp_ldraw.c')
-rw-r--r-- | src/others/mimesh/libg3d-0.0.8/plugins/import/imp_ldraw/imp_ldraw.c | 112 |
1 files changed, 112 insertions, 0 deletions
diff --git a/src/others/mimesh/libg3d-0.0.8/plugins/import/imp_ldraw/imp_ldraw.c b/src/others/mimesh/libg3d-0.0.8/plugins/import/imp_ldraw/imp_ldraw.c new file mode 100644 index 0000000..09a013d --- /dev/null +++ b/src/others/mimesh/libg3d-0.0.8/plugins/import/imp_ldraw/imp_ldraw.c | |||
@@ -0,0 +1,112 @@ | |||
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 <stdio.h> | ||
25 | |||
26 | #include <g3d/types.h> | ||
27 | #include <g3d/stream.h> | ||
28 | #include <g3d/matrix.h> | ||
29 | #include <g3d/object.h> | ||
30 | |||
31 | #include "imp_ldraw_types.h" | ||
32 | #include "imp_ldraw_part.h" | ||
33 | #include "imp_ldraw_library.h" | ||
34 | #include "imp_ldraw_mpd.h" | ||
35 | |||
36 | static gboolean ldraw_load_simple(G3DStream *stream, G3DModel *model, | ||
37 | LDrawLibrary *lib); | ||
38 | |||
39 | |||
40 | EAPI | ||
41 | gpointer plugin_init(G3DContext *context) | ||
42 | { | ||
43 | return ldraw_library_init(); | ||
44 | } | ||
45 | |||
46 | EAPI | ||
47 | void plugin_cleanup(gpointer user_data) | ||
48 | { | ||
49 | LDrawLibrary *lib = user_data; | ||
50 | |||
51 | ldraw_library_cleanup(lib); | ||
52 | } | ||
53 | |||
54 | EAPI | ||
55 | gboolean plugin_load_model_from_stream(G3DContext *context, G3DStream *stream, | ||
56 | G3DModel *model, gpointer user_data) | ||
57 | { | ||
58 | LDrawLibrary *lib = user_data; | ||
59 | |||
60 | g_return_val_if_fail(lib != NULL, FALSE); | ||
61 | if(lib->libdir == NULL) { | ||
62 | g_warning("LDraw: library not found, please set LDRAWDIR"); | ||
63 | return FALSE; | ||
64 | } | ||
65 | |||
66 | lib->context = context; | ||
67 | |||
68 | if(g_ascii_strcasecmp(stream->uri + strlen(stream->uri) - 4, ".mpd") == 0) | ||
69 | return ldraw_mpd_load(stream, model, lib); | ||
70 | else | ||
71 | return ldraw_load_simple(stream, model, lib); | ||
72 | |||
73 | return TRUE; | ||
74 | } | ||
75 | |||
76 | EAPI | ||
77 | gchar *plugin_description(void) | ||
78 | { | ||
79 | return g_strdup("LDraw models."); | ||
80 | } | ||
81 | |||
82 | EAPI | ||
83 | gchar **plugin_extensions(void) | ||
84 | { | ||
85 | return g_strsplit("ldr:mpd:dat", ":", 0); | ||
86 | } | ||
87 | |||
88 | /*****************************************************************************/ | ||
89 | |||
90 | static gboolean ldraw_load_simple(G3DStream *stream, G3DModel *model, | ||
91 | LDrawLibrary *lib) | ||
92 | { | ||
93 | LDrawPart *part; | ||
94 | G3DObject *object; | ||
95 | G3DFloat m[16]; | ||
96 | |||
97 | part = g_new0(LDrawPart, 1); | ||
98 | part->name = g_path_get_basename(stream->uri); | ||
99 | part->stream = stream; | ||
100 | part->master = TRUE; | ||
101 | |||
102 | object = ldraw_part_get_object(part, lib); | ||
103 | if(object == NULL) | ||
104 | return FALSE; | ||
105 | |||
106 | g3d_matrix_identity(m); | ||
107 | g3d_matrix_rotate_xyz(0.0, 0.0, G_PI, m); | ||
108 | g3d_object_transform(object, m); | ||
109 | model->objects = g_slist_append(model->objects, object); | ||
110 | return TRUE; | ||
111 | } | ||
112 | |||