1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
|
/* $Id$ */
/*
libg3d - 3D object loading library
Copyright (C) 2005-2009 Markus Dahms <mad@automagically.de>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <string.h>
#include <g3d/model.h>
#include "imp_maya_obj.h"
MayaObject *maya_obj_new(void)
{
MayaObject *obj;
obj = g_new0(MayaObject, 1);
obj->vars = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free);
return obj;
}
void maya_obj_free(MayaObject *obj)
{
g_hash_table_destroy(obj->vars);
if(obj->name) g_free(obj->name);
g_free(obj);
}
G3DObject *maya_obj_to_g3d(MayaObject *obj)
{
G3DObject *object;
object = g_new0(G3DObject, 1);
object->name = obj->name ? g_strdup(obj->name) : "(unnamed)";
return object;
}
static G3DObject *get_by_path(G3DModel *model, gchar *path)
{
gchar **parts, **partp;
G3DObject *object = NULL;
GSList *olist;
partp = parts = g_strsplit(path, "|", 0);
olist = model->objects;
while(*partp)
{
while(olist)
{
object = (G3DObject *)olist->data;
if(strcmp(object->name, *partp) == 0) break;
olist = olist->next;
object = NULL;
}
if(object == NULL) return NULL;
partp ++;
olist = object->objects;
}
g_strfreev(parts);
return object;
}
gboolean maya_obj_add_to_tree(MayaObject *obj, G3DModel *model,
G3DObject *object)
{
G3DObject *parent = NULL;
if(obj->parent)
{
if(*(obj->parent) == '|')
parent = get_by_path(model, obj->parent + 1);
else
parent = g3d_model_get_object_by_name(model, obj->parent);
if(parent == NULL)
g_warning(
"[Maya] maya_obj_add_to_tree: parent object '%s' not found",
obj->parent);
}
if(parent != NULL)
parent->objects = g_slist_append(parent->objects, object);
else
model->objects = g_slist_append(model->objects, object);
return TRUE;
}
|