Adding support for Matrix Transformation export
[blender.git] / source / blender / collada / collada.cpp
1 /*
2  * ***** BEGIN GPL LICENSE BLOCK *****
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version 2
7  * of the License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software Foundation,
16  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17  *
18  * Contributor(s): Chingiz Dyussenov, Arystanbek Dyussenov.
19  *
20  * ***** END GPL LICENSE BLOCK *****
21  */
22
23 /** \file blender/collada/collada.cpp
24  *  \ingroup collada
25  */
26
27
28 /* COLLADABU_ASSERT, may be able to remove later */
29 #include "COLLADABUPlatform.h"
30
31 #include "DocumentExporter.h"
32 #include "DocumentImporter.h"
33 #include "ExportSettings.h"
34 #include "ImportSettings.h"
35
36 extern "C"
37 {
38 #include "BKE_scene.h"
39 #include "BKE_context.h"
40
41 /* make dummy file */
42 #include "BLI_fileops.h"
43 #include "BLI_linklist.h"
44
45 int collada_import(bContext *C,
46                                    const char *filepath,
47                                    int import_units,
48                                    int find_chains,
49                                    int auto_connect,
50                                    int fix_orientation,
51                                    int min_chain_length,
52                                    int keep_bind_info)
53 {
54
55         ImportSettings import_settings;
56         import_settings.filepath         = (char *)filepath;
57         import_settings.import_units     = import_units != 0;
58         import_settings.auto_connect     = auto_connect != 0;
59         import_settings.find_chains      = find_chains != 0;
60         import_settings.fix_orientation  = fix_orientation != 0;
61         import_settings.min_chain_length = min_chain_length;
62         import_settings.keep_bind_info = keep_bind_info !=0;
63
64         DocumentImporter imp(C, &import_settings);
65         if (imp.import()) return 1;
66
67         return 0;
68 }
69
70 int collada_export(Scene *sce,
71                    const char *filepath,
72
73                    int apply_modifiers,
74                                    BC_export_mesh_type export_mesh_type,
75
76                    int selected,
77                    int include_children,
78                    int include_armatures,
79                                    int include_shapekeys,
80                    int deform_bones_only,
81                                    int include_animations,
82                    int sampling_rate,
83
84                                    int active_uv_only,
85                                    BC_export_texture_type export_texture_type,
86                                    int use_texture_copies,
87
88                    int triangulate,
89                                    int use_object_instantiation,
90                                    int use_blender_profile,
91                                    int sort_by_name,
92                                    BC_export_transformation_type export_transformation_type,
93                                    int open_sim,
94                                    int limit_precision,
95                                    int keep_bind_info)
96 {
97         ExportSettings export_settings;
98
99         export_settings.filepath                 = (char *)filepath;
100
101         export_settings.apply_modifiers          = apply_modifiers != 0;
102         export_settings.export_mesh_type         = export_mesh_type;
103         export_settings.selected                 = selected          != 0;
104         export_settings.include_children         = include_children  != 0;
105         export_settings.include_armatures        = include_armatures != 0;
106         export_settings.include_shapekeys        = include_shapekeys != 0;
107         export_settings.deform_bones_only        = deform_bones_only != 0;
108         export_settings.include_animations       = include_animations;
109         export_settings.sampling_rate = sampling_rate;
110
111         export_settings.active_uv_only           = active_uv_only != 0;
112         export_settings.export_texture_type      = export_texture_type;
113         export_settings.use_texture_copies       = use_texture_copies != 0;
114
115         export_settings.triangulate                = triangulate != 0;
116         export_settings.use_object_instantiation   = use_object_instantiation != 0;
117         export_settings.use_blender_profile        = use_blender_profile != 0;
118         export_settings.sort_by_name               = sort_by_name != 0;
119         export_settings.export_transformation_type = export_transformation_type;
120         export_settings.open_sim                   = open_sim != 0;
121         export_settings.limit_precision = limit_precision != 0;
122         export_settings.keep_bind_info = keep_bind_info !=0;
123
124         int includeFilter = OB_REL_NONE;
125         if (export_settings.include_armatures) includeFilter |= OB_REL_MOD_ARMATURE;
126         if (export_settings.include_children) includeFilter |= OB_REL_CHILDREN_RECURSIVE;
127
128         eObjectSet objectSet = (export_settings.selected) ? OB_SET_SELECTED : OB_SET_ALL;
129         export_settings.export_set = BKE_object_relational_superset(sce, objectSet, (eObRelationTypes)includeFilter);
130         int export_count = BLI_linklist_count(export_settings.export_set);
131
132         if (export_count == 0) {
133                 if (export_settings.selected) {
134                         fprintf(stderr, "Collada: Found no objects to export.\nPlease ensure that all objects which shall be exported are also visible in the 3D Viewport.\n");
135                 }
136                 else {
137                         fprintf(stderr, "Collada: Your scene seems to be empty. No Objects will be exported.\n");
138                 }
139         }
140         else {
141                 if (export_settings.sort_by_name)
142                         bc_bubble_sort_by_Object_name(export_settings.export_set);
143         }
144
145         DocumentExporter exporter(&export_settings);
146         int status = exporter.exportCurrentScene(sce);
147
148         BLI_linklist_free(export_settings.export_set, NULL);
149
150         return (status) ? -1:export_count;
151 }
152
153 /* end extern C */
154 }