Blender  V2.93
collada.cpp
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  */
16 
21 /* COLLADABU_ASSERT, may be able to remove later */
22 #include "COLLADABUPlatform.h"
23 
24 #include "DocumentExporter.h"
25 #include "DocumentImporter.h"
26 #include "ExportSettings.h"
27 #include "ImportSettings.h"
28 #include "collada.h"
29 
30 #include "BKE_context.h"
31 #include "BKE_scene.h"
32 #include "DEG_depsgraph.h"
33 #include "DEG_depsgraph_query.h"
34 
35 /* make dummy file */
36 #include "BLI_fileops.h"
37 #include "BLI_linklist.h"
38 
39 extern "C" {
40 
41 static void print_import_header(ImportSettings &import_settings)
42 {
43  fprintf(stderr, "+-- Collada Import parameters------\n");
44  fprintf(stderr, "| input file : %s\n", import_settings.filepath);
45  fprintf(stderr, "| use units : %s\n", (import_settings.import_units) ? "yes" : "no");
46  fprintf(stderr, "| autoconnect : %s\n", (import_settings.auto_connect) ? "yes" : "no");
47  fprintf(stderr, "+-- Armature Import parameters ----\n");
48  fprintf(stderr, "| find bone chains: %s\n", (import_settings.find_chains) ? "yes" : "no");
49  fprintf(stderr, "| min chain len : %d\n", import_settings.min_chain_length);
50  fprintf(stderr, "| fix orientation : %s\n", (import_settings.fix_orientation) ? "yes" : "no");
51  fprintf(stderr, "| keep bind info : %s\n", (import_settings.keep_bind_info) ? "yes" : "no");
52 }
53 
54 static void print_import_footer(int status)
55 {
56  fprintf(stderr, "+----------------------------------\n");
57  fprintf(stderr, "| Collada Import : %s\n", (status) ? "OK" : "FAIL");
58  fprintf(stderr, "+----------------------------------\n");
59 }
60 
61 int collada_import(bContext *C, ImportSettings *import_settings)
62 {
63  print_import_header(*import_settings);
64  DocumentImporter imp(C, import_settings);
65  int status = imp.import() ? 1 : 0;
66  print_import_footer(status);
67 
68  return status;
69 }
70 
71 int collada_export(bContext *C, ExportSettings *export_settings)
72 {
73  BlenderContext blender_context(C);
74  ViewLayer *view_layer = blender_context.get_view_layer();
75 
76  int includeFilter = OB_REL_NONE;
77  if (export_settings->include_armatures) {
78  includeFilter |= OB_REL_MOD_ARMATURE;
79  }
80  if (export_settings->include_children) {
81  includeFilter |= OB_REL_CHILDREN_RECURSIVE;
82  }
83 
84  /* Fetch the complete set of exported objects
85  * ATTENTION: Invisible objects will not be exported
86  */
87  eObjectSet objectSet = (export_settings->selected) ? OB_SET_SELECTED : OB_SET_ALL;
88  export_settings->export_set = BKE_object_relational_superset(
89  view_layer, objectSet, (eObRelationTypes)includeFilter);
90 
91  int export_count = BLI_linklist_count(export_settings->export_set);
92 
93  if (export_count == 0) {
94  if (export_settings->selected) {
95  fprintf(stderr,
96  "Collada: Found no objects to export.\nPlease ensure that all objects which shall "
97  "be exported are also visible in the 3D Viewport.\n");
98  }
99  else {
100  fprintf(stderr, "Collada: Your scene seems to be empty. No Objects will be exported.\n");
101  }
102  }
103  else {
104  if (export_settings->sort_by_name) {
105  bc_bubble_sort_by_Object_name(export_settings->export_set);
106  }
107  }
108 
109  DocumentExporter exporter(blender_context, export_settings);
110  int status = exporter.exportCurrentScene();
111 
112  BLI_linklist_free(export_settings->export_set, nullptr);
113 
114  return (status) ? -1 : export_count;
115 }
116 
117 /* end extern C */
118 }
eObRelationTypes
Definition: BKE_object.h:382
@ OB_REL_MOD_ARMATURE
Definition: BKE_object.h:388
@ OB_REL_CHILDREN_RECURSIVE
Definition: BKE_object.h:387
@ OB_REL_NONE
Definition: BKE_object.h:383
eObjectSet
Definition: BKE_object.h:393
@ OB_SET_SELECTED
Definition: BKE_object.h:394
@ OB_SET_ALL
Definition: BKE_object.h:396
struct LinkNode * BKE_object_relational_superset(struct ViewLayer *view_layer, eObjectSet objectSet, eObRelationTypes includeFilter)
Definition: object.c:5167
File and directory operations.
#define C
Definition: RandGen.cpp:39
int collada_import(bContext *C, ImportSettings *import_settings)
Definition: collada.cpp:61
static void print_import_footer(int status)
Definition: collada.cpp:54
static void print_import_header(ImportSettings &import_settings)
Definition: collada.cpp:41
int collada_export(bContext *C, ExportSettings *export_settings)
Definition: collada.cpp:71
void bc_bubble_sort_by_Object_name(LinkNode *export_set)
LinkNode * export_set