merge from master
[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 #include "collada.h"
36
37 extern "C"
38 {
39 #include "BKE_scene.h"
40 #include "BKE_context.h"
41 #include "DEG_depsgraph.h"
42
43 /* make dummy file */
44 #include "BLI_fileops.h"
45 #include "BLI_linklist.h"
46
47 int collada_import(bContext *C,
48                                    const char *filepath,
49                                    int import_units,
50                                    int find_chains,
51                                    int auto_connect,
52                                    int fix_orientation,
53                                    int min_chain_length,
54                                    int keep_bind_info)
55 {
56
57         ImportSettings import_settings;
58         import_settings.filepath         = (char *)filepath;
59         import_settings.import_units     = import_units != 0;
60         import_settings.auto_connect     = auto_connect != 0;
61         import_settings.find_chains      = find_chains != 0;
62         import_settings.fix_orientation  = fix_orientation != 0;
63         import_settings.min_chain_length = min_chain_length;
64         import_settings.keep_bind_info = keep_bind_info !=0;
65
66         DocumentImporter imp(C, &import_settings);
67         if (imp.import()) return 1;
68
69         return 0;
70 }
71
72 int collada_export(
73         EvaluationContext *eval_ctx,
74         Scene *sce,
75         const char *filepath,
76
77         int apply_modifiers,
78         BC_export_mesh_type export_mesh_type,
79
80         int selected,
81         int include_children,
82         int include_armatures,
83         int include_shapekeys,
84         int deform_bones_only,
85         int include_animations,
86         int sampling_rate,
87
88         int active_uv_only,
89         int include_material_textures,
90         int use_texture_copies,
91
92         int triangulate,
93         int use_object_instantiation,
94         int use_blender_profile,
95         int sort_by_name,
96         BC_export_transformation_type export_transformation_type,
97         int open_sim,
98         int limit_precision,
99         int keep_bind_info)
100 {
101         ExportSettings export_settings;
102
103         ViewLayer *view_layer = eval_ctx->view_layer;
104
105         export_settings.filepath                 = (char *)filepath;
106
107         export_settings.apply_modifiers          = apply_modifiers != 0;
108         export_settings.export_mesh_type         = export_mesh_type;
109         export_settings.selected                 = selected          != 0;
110         export_settings.include_children         = include_children  != 0;
111         export_settings.include_armatures        = include_armatures != 0;
112         export_settings.include_shapekeys        = include_shapekeys != 0;
113         export_settings.deform_bones_only        = deform_bones_only != 0;
114         export_settings.include_animations       = include_animations;
115         export_settings.sampling_rate = sampling_rate;
116
117         export_settings.active_uv_only           = active_uv_only != 0;
118         export_settings.include_material_textures= include_material_textures != 0;
119         export_settings.use_texture_copies       = use_texture_copies != 0;
120
121         export_settings.triangulate                = triangulate != 0;
122         export_settings.use_object_instantiation   = use_object_instantiation != 0;
123         export_settings.use_blender_profile        = use_blender_profile != 0;
124         export_settings.sort_by_name               = sort_by_name != 0;
125         export_settings.export_transformation_type = export_transformation_type;
126         export_settings.open_sim                   = open_sim != 0;
127         export_settings.limit_precision = limit_precision != 0;
128         export_settings.keep_bind_info = keep_bind_info !=0;
129
130         int includeFilter = OB_REL_NONE;
131         if (export_settings.include_armatures) includeFilter |= OB_REL_MOD_ARMATURE;
132         if (export_settings.include_children) includeFilter |= OB_REL_CHILDREN_RECURSIVE;
133
134         eObjectSet objectSet = (export_settings.selected) ? OB_SET_SELECTED : OB_SET_ALL;
135         export_settings.export_set = BKE_object_relational_superset(view_layer, objectSet, (eObRelationTypes)includeFilter);
136
137         int export_count = BLI_linklist_count(export_settings.export_set);
138
139         if (export_count == 0) {
140                 if (export_settings.selected) {
141                         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");
142                 }
143                 else {
144                         fprintf(stderr, "Collada: Your scene seems to be empty. No Objects will be exported.\n");
145                 }
146         }
147         else {
148                 if (export_settings.sort_by_name)
149                         bc_bubble_sort_by_Object_name(export_settings.export_set);
150         }
151
152         DocumentExporter exporter(&export_settings);
153         int status = exporter.exportCurrentScene(eval_ctx, sce);
154
155         BLI_linklist_free(export_settings.export_set, NULL);
156
157         return (status) ? -1:export_count;
158 }
159
160 /* end extern C */
161 }