aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src/others/mimesh/libg3d-0.0.8/plugins/import/imp_maya/imp_maya_obj.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/others/mimesh/libg3d-0.0.8/plugins/import/imp_maya/imp_maya_obj.c')
-rw-r--r--src/others/mimesh/libg3d-0.0.8/plugins/import/imp_maya/imp_maya_obj.c110
1 files changed, 110 insertions, 0 deletions
diff --git a/src/others/mimesh/libg3d-0.0.8/plugins/import/imp_maya/imp_maya_obj.c b/src/others/mimesh/libg3d-0.0.8/plugins/import/imp_maya/imp_maya_obj.c
new file mode 100644
index 0000000..d55bc71
--- /dev/null
+++ b/src/others/mimesh/libg3d-0.0.8/plugins/import/imp_maya/imp_maya_obj.c
@@ -0,0 +1,110 @@
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 <string.h>
23
24#include <g3d/model.h>
25
26#include "imp_maya_obj.h"
27
28MayaObject *maya_obj_new(void)
29{
30 MayaObject *obj;
31
32 obj = g_new0(MayaObject, 1);
33 obj->vars = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free);
34
35 return obj;
36}
37
38void maya_obj_free(MayaObject *obj)
39{
40 g_hash_table_destroy(obj->vars);
41 if(obj->name) g_free(obj->name);
42 g_free(obj);
43}
44
45G3DObject *maya_obj_to_g3d(MayaObject *obj)
46{
47 G3DObject *object;
48
49 object = g_new0(G3DObject, 1);
50 object->name = obj->name ? g_strdup(obj->name) : "(unnamed)";
51
52 return object;
53}
54
55static G3DObject *get_by_path(G3DModel *model, gchar *path)
56{
57 gchar **parts, **partp;
58 G3DObject *object = NULL;
59 GSList *olist;
60
61 partp = parts = g_strsplit(path, "|", 0);
62 olist = model->objects;
63 while(*partp)
64 {
65 while(olist)
66 {
67 object = (G3DObject *)olist->data;
68
69 if(strcmp(object->name, *partp) == 0) break;
70
71 olist = olist->next;
72 object = NULL;
73 }
74
75 if(object == NULL) return NULL;
76
77 partp ++;
78 olist = object->objects;
79 }
80
81 g_strfreev(parts);
82
83 return object;
84}
85
86gboolean maya_obj_add_to_tree(MayaObject *obj, G3DModel *model,
87 G3DObject *object)
88{
89 G3DObject *parent = NULL;
90
91 if(obj->parent)
92 {
93 if(*(obj->parent) == '|')
94 parent = get_by_path(model, obj->parent + 1);
95 else
96 parent = g3d_model_get_object_by_name(model, obj->parent);
97
98 if(parent == NULL)
99 g_warning(
100 "[Maya] maya_obj_add_to_tree: parent object '%s' not found",
101 obj->parent);
102 }
103
104 if(parent != NULL)
105 parent->objects = g_slist_append(parent->objects, object);
106 else
107 model->objects = g_slist_append(model->objects, object);
108
109 return TRUE;
110}