diff options
Diffstat (limited to '')
-rw-r--r-- | src/others/mimesh/libg3d-0.0.8/plugins/import/imp_3dm/imp_3dm_object.c | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/src/others/mimesh/libg3d-0.0.8/plugins/import/imp_3dm/imp_3dm_object.c b/src/others/mimesh/libg3d-0.0.8/plugins/import/imp_3dm/imp_3dm_object.c new file mode 100644 index 0000000..0e280a8 --- /dev/null +++ b/src/others/mimesh/libg3d-0.0.8/plugins/import/imp_3dm/imp_3dm_object.c | |||
@@ -0,0 +1,80 @@ | |||
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 | #include <g3d/config.h> | ||
23 | |||
24 | #include <g3d/types.h> | ||
25 | #include <g3d/stream.h> | ||
26 | |||
27 | #include "imp_3dm_types.h" | ||
28 | |||
29 | static guint32 tdm_object_read_vector_data(G3DStream *stream, | ||
30 | G3DVector *vertex_data, guint32 vsize, guint32 vcount) | ||
31 | { | ||
32 | gsize nb = 0; | ||
33 | gint32 i, j; | ||
34 | |||
35 | for(i = 0; i < vcount; i ++) | ||
36 | for(j = 0; j < vsize; j ++) { | ||
37 | vertex_data[i * vsize + j] = g3d_stream_read_float_le(stream); | ||
38 | nb += 4; | ||
39 | } | ||
40 | return nb; | ||
41 | } | ||
42 | |||
43 | gboolean tdm_object_read_vertex_data_uncompressed(TdmGlobal *global, | ||
44 | TdmLocal *local) | ||
45 | { | ||
46 | TdmObjectRecord *obj = local->object; | ||
47 | |||
48 | local->len -= tdm_object_read_vector_data(global->stream, | ||
49 | obj->object->vertex_data, 3, obj->object->vertex_count); | ||
50 | return TRUE; | ||
51 | } | ||
52 | |||
53 | gboolean tdm_object_read_vertex_data_compressed(TdmGlobal *global, | ||
54 | TdmLocal *local) | ||
55 | { | ||
56 | #if HAVE_ZLIB | ||
57 | TdmObjectRecord *obj = local->object; | ||
58 | G3DStream *zstream; | ||
59 | guint32 csize; | ||
60 | |||
61 | g3d_stream_read_int32_le(global->stream); /* tcode */ | ||
62 | csize = g3d_stream_read_int32_le(global->stream) - 4; /* size */ | ||
63 | local->len -= 8; | ||
64 | |||
65 | zstream = g3d_stream_zlib_inflate_stream(global->stream, csize); | ||
66 | if(zstream) { | ||
67 | tdm_object_read_vector_data(zstream, | ||
68 | obj->object->vertex_data, 3, obj->object->vertex_count); | ||
69 | local->len -= csize; | ||
70 | g3d_stream_close(zstream); | ||
71 | /* CRC */ | ||
72 | g3d_stream_read_int32_le(global->stream); | ||
73 | local->len -= 4; | ||
74 | return TRUE; | ||
75 | }; | ||
76 | #else | ||
77 | g_warning("no zlib support, unable to read deflated data"); | ||
78 | #endif /* HAVE_ZLIB */ | ||
79 | return FALSE; | ||
80 | } | ||