Rename any instance of scene layer or render layer in code with view layer
[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(const EvaluationContext *eval_ctx,
71                    Scene *sce,
72                    ViewLayer *view_layer,
73                    const char *filepath,
74
75                    int apply_modifiers,
76                                    BC_export_mesh_type export_mesh_type,
77
78                    int selected,
79                    int include_children,
80                    int include_armatures,
81                                    int include_shapekeys,
82                    int deform_bones_only,
83
84                                    int active_uv_only,
85                                    int include_material_textures,
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
109         export_settings.active_uv_only           = active_uv_only != 0;
110         export_settings.include_material_textures= include_material_textures != 0;
111         export_settings.use_texture_copies       = use_texture_copies != 0;
112
113         export_settings.triangulate                = triangulate != 0;
114         export_settings.use_object_instantiation   = use_object_instantiation != 0;
115         export_settings.use_blender_profile        = use_blender_profile != 0;
116         export_settings.sort_by_name               = sort_by_name != 0;
117         export_settings.export_transformation_type = export_transformation_type;
118         export_settings.open_sim                   = open_sim != 0;
119         export_settings.limit_precision = limit_precision != 0;
120         export_settings.keep_bind_info = keep_bind_info !=0;
121
122         int includeFilter = OB_REL_NONE;
123         if (export_settings.include_armatures) includeFilter |= OB_REL_MOD_ARMATURE;
124         if (export_settings.include_children) includeFilter |= OB_REL_CHILDREN_RECURSIVE;
125
126         eObjectSet objectSet = (export_settings.selected) ? OB_SET_SELECTED : OB_SET_ALL;
127         export_settings.export_set = BKE_object_relational_superset(view_layer, objectSet, (eObRelationTypes)includeFilter);
128         int export_count = BLI_linklist_count(export_settings.export_set);
129
130         if (export_count == 0) {
131                 if (export_settings.selected) {
132                         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");
133                 }
134                 else {
135                         fprintf(stderr, "Collada: Your scene seems to be empty. No Objects will be exported.\n");
136                 }
137         }
138         else {
139                 if (export_settings.sort_by_name)
140                         bc_bubble_sort_by_Object_name(export_settings.export_set);
141         }
142
143         DocumentExporter exporter(&export_settings);
144         int status = exporter.exportCurrentScene(eval_ctx, sce);
145
146         BLI_linklist_free(export_settings.export_set, NULL);
147
148         return (status) ? -1:export_count;
149 }
150
151 /* end extern C */
152 }