diff options
Diffstat (limited to 'src/others/mimesh/libg3d-0.0.8/plugins/import/imp_iob/imp_iob.c')
-rw-r--r-- | src/others/mimesh/libg3d-0.0.8/plugins/import/imp_iob/imp_iob.c | 98 |
1 files changed, 98 insertions, 0 deletions
diff --git a/src/others/mimesh/libg3d-0.0.8/plugins/import/imp_iob/imp_iob.c b/src/others/mimesh/libg3d-0.0.8/plugins/import/imp_iob/imp_iob.c new file mode 100644 index 0000000..1c4ce17 --- /dev/null +++ b/src/others/mimesh/libg3d-0.0.8/plugins/import/imp_iob/imp_iob.c | |||
@@ -0,0 +1,98 @@ | |||
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 <stdio.h> | ||
24 | #include <string.h> | ||
25 | |||
26 | #include <glib.h> | ||
27 | |||
28 | #include <g3d/types.h> | ||
29 | #include <g3d/context.h> | ||
30 | #include <g3d/model.h> | ||
31 | #include <g3d/material.h> | ||
32 | #include <g3d/stream.h> | ||
33 | #include <g3d/iff.h> | ||
34 | #include <g3d/matrix.h> | ||
35 | |||
36 | #include "imp_iob_chunks.h" | ||
37 | |||
38 | EAPI | ||
39 | gboolean plugin_load_model_from_stream(G3DContext *context, G3DStream *stream, | ||
40 | G3DModel *model, gpointer user_data) | ||
41 | { | ||
42 | G3DIffGlobal *global; | ||
43 | G3DIffLocal *local; | ||
44 | guint32 id; | ||
45 | gsize len; | ||
46 | G3DMatrix rmatrix[16]; | ||
47 | |||
48 | if(!g3d_iff_check(stream, &id, &len) || | ||
49 | (id != G3D_IFF_MKID('T','D','D','D'))) { | ||
50 | g_warning("file is not an .iob (TDDD) file %s", stream->uri); | ||
51 | return FALSE; | ||
52 | } | ||
53 | |||
54 | local = g_new0(G3DIffLocal, 1); | ||
55 | global = g_new0(G3DIffGlobal, 1); | ||
56 | |||
57 | global->context = context; | ||
58 | global->model = model; | ||
59 | global->stream = stream; | ||
60 | |||
61 | local->parent_id = id; | ||
62 | local->nb = len; | ||
63 | |||
64 | g3d_iff_read_ctnr(global, local, iob_chunks, G3D_IFF_PAD2); | ||
65 | |||
66 | g3d_matrix_identity(rmatrix); | ||
67 | g3d_matrix_rotate_xyz(G_PI * -90.0 / 180, 0.0, 0.0, rmatrix); | ||
68 | g3d_model_transform(model, rmatrix); | ||
69 | |||
70 | g_free(local); | ||
71 | g_free(global); | ||
72 | |||
73 | return TRUE; | ||
74 | } | ||
75 | |||
76 | EAPI | ||
77 | char *plugin_description(void) | ||
78 | { | ||
79 | return g_strdup("Impulse Turbo Silver / Imagine models."); | ||
80 | } | ||
81 | |||
82 | EAPI | ||
83 | char **plugin_extensions(void) | ||
84 | { | ||
85 | return g_strsplit("iob", ":", 0); | ||
86 | } | ||
87 | |||
88 | |||
89 | /*****************************************************************************/ | ||
90 | /* IOB specific */ | ||
91 | /*****************************************************************************/ | ||
92 | |||
93 | G3DFloat iob_read_fract(G3DStream *stream) | ||
94 | { | ||
95 | gint32 i = g3d_stream_read_int32_be(stream); | ||
96 | return (G3DFloat)(i / 0xFFFF); | ||
97 | } | ||
98 | |||