Blender  V3.3
collada.cpp
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 
7 /* COLLADABU_ASSERT, may be able to remove later */
8 #include "COLLADABUPlatform.h"
9 
10 #include "DocumentExporter.h"
11 #include "DocumentImporter.h"
12 #include "ExportSettings.h"
13 #include "ImportSettings.h"
14 #include "collada.h"
15 
16 #include "BKE_context.h"
17 #include "BKE_scene.h"
18 #include "DEG_depsgraph.h"
19 #include "DEG_depsgraph_query.h"
20 
21 /* make dummy file */
22 #include "BLI_fileops.h"
23 #include "BLI_linklist.h"
24 
25 extern "C" {
26 
27 static void print_import_header(ImportSettings &import_settings)
28 {
29  fprintf(stderr, "+-- Collada Import parameters------\n");
30  fprintf(stderr, "| input file : %s\n", import_settings.filepath);
31  fprintf(stderr, "| use units : %s\n", (import_settings.import_units) ? "yes" : "no");
32  fprintf(stderr, "| autoconnect : %s\n", (import_settings.auto_connect) ? "yes" : "no");
33  fprintf(stderr, "+-- Armature Import parameters ----\n");
34  fprintf(stderr, "| find bone chains: %s\n", (import_settings.find_chains) ? "yes" : "no");
35  fprintf(stderr, "| min chain len : %d\n", import_settings.min_chain_length);
36  fprintf(stderr, "| fix orientation : %s\n", (import_settings.fix_orientation) ? "yes" : "no");
37  fprintf(stderr, "| keep bind info : %s\n", (import_settings.keep_bind_info) ? "yes" : "no");
38 }
39 
40 static void print_import_footer(int status)
41 {
42  fprintf(stderr, "+----------------------------------\n");
43  fprintf(stderr, "| Collada Import : %s\n", (status) ? "OK" : "FAIL");
44  fprintf(stderr, "+----------------------------------\n");
45 }
46 
47 int collada_import(bContext *C, ImportSettings *import_settings)
48 {
49  print_import_header(*import_settings);
50  DocumentImporter imp(C, import_settings);
51  int status = imp.import() ? 1 : 0;
52  print_import_footer(status);
53 
54  return status;
55 }
56 
57 int collada_export(bContext *C, ExportSettings *export_settings)
58 {
59  BlenderContext blender_context(C);
60  ViewLayer *view_layer = blender_context.get_view_layer();
61 
62  int includeFilter = OB_REL_NONE;
63  if (export_settings->include_armatures) {
64  includeFilter |= OB_REL_MOD_ARMATURE;
65  }
66  if (export_settings->include_children) {
67  includeFilter |= OB_REL_CHILDREN_RECURSIVE;
68  }
69 
70  /* Fetch the complete set of exported objects
71  * ATTENTION: Invisible objects will not be exported
72  */
73  eObjectSet objectSet = (export_settings->selected) ? OB_SET_SELECTED : OB_SET_ALL;
74  export_settings->export_set = BKE_object_relational_superset(
75  view_layer, objectSet, (eObRelationTypes)includeFilter);
76 
77  int export_count = BLI_linklist_count(export_settings->export_set);
78 
79  if (export_count == 0) {
80  if (export_settings->selected) {
81  fprintf(stderr,
82  "Collada: Found no objects to export.\nPlease ensure that all objects which shall "
83  "be exported are also visible in the 3D Viewport.\n");
84  }
85  else {
86  fprintf(stderr, "Collada: Your scene seems to be empty. No Objects will be exported.\n");
87  }
88  }
89  else {
90  if (export_settings->sort_by_name) {
91  bc_bubble_sort_by_Object_name(export_settings->export_set);
92  }
93  }
94 
95  DocumentExporter exporter(blender_context, export_settings);
96  int status = exporter.exportCurrentScene();
97 
98  BLI_linklist_free(export_settings->export_set, nullptr);
99 
100  return (status) ? -1 : export_count;
101 }
102 
103 /* end extern C */
104 }
eObRelationTypes
Definition: BKE_object.h:603
@ OB_REL_MOD_ARMATURE
Definition: BKE_object.h:609
@ OB_REL_CHILDREN_RECURSIVE
Definition: BKE_object.h:608
@ OB_REL_NONE
Definition: BKE_object.h:604
eObjectSet
Definition: BKE_object.h:613
@ OB_SET_SELECTED
Definition: BKE_object.h:614
@ OB_SET_ALL
Definition: BKE_object.h:616
struct LinkNode * BKE_object_relational_superset(struct ViewLayer *view_layer, eObjectSet objectSet, eObRelationTypes includeFilter)
Definition: object.cc:5157
File and directory operations.
#define C
Definition: RandGen.cpp:25
int collada_import(bContext *C, ImportSettings *import_settings)
Definition: collada.cpp:47
static void print_import_footer(int status)
Definition: collada.cpp:40
static void print_import_header(ImportSettings &import_settings)
Definition: collada.cpp:27
int collada_export(bContext *C, ExportSettings *export_settings)
Definition: collada.cpp:57
void bc_bubble_sort_by_Object_name(LinkNode *export_set)
LinkNode * export_set