Welcome to mirror list, hosted at ThFree Co, Russian Federation.

DocumentImporter.h « collada « io « blender « source - git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 63faaca471164bc2596770a50d50a7b3aa6ba6ef (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
/*
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 */

/** \file
 * \ingroup collada
 */

#pragma once

#include "COLLADAFWColor.h"
#include "COLLADAFWController.h"
#include "COLLADAFWEffect.h"
#include "COLLADAFWEffectCommon.h"
#include "COLLADAFWIWriter.h"
#include "COLLADAFWImage.h"
#include "COLLADAFWInstanceGeometry.h"
#include "COLLADAFWMaterial.h"
#include "COLLADAFWMorphController.h"
#include "COLLADAFWSkinController.h"

#include "BKE_constraint.h"
#include "BKE_object.h"

#include "AnimationImporter.h"
#include "ArmatureImporter.h"
#include "ControllerExporter.h"
#include "ImportSettings.h"
#include "MeshImporter.h"
#include "TransformReader.h"

struct bContext;

/** Importer class. */
class DocumentImporter : COLLADAFW::IWriter {
 public:
  /** Enumeration to denote the stage of import */
  enum ImportStage {
    Fetching_Scene_data,      /* First pass to collect all data except controller */
    Fetching_Controller_data, /* Second pass to collect controller data */
  };
  /** Constructor */
  DocumentImporter(bContext *C, const ImportSettings *import_settings);

  /** Destructor */
  ~DocumentImporter();

  /** Function called by blender UI */
  bool import();

  /** these should not be here */
  Object *create_camera_object(COLLADAFW::InstanceCamera *, Scene *);
  Object *create_light_object(COLLADAFW::InstanceLight *, Scene *);
  Object *create_instance_node(Object *, COLLADAFW::Node *, COLLADAFW::Node *, Scene *, bool);
  /**
   * To create constraints off node <extra> tags. Assumes only constraint data in
   * current <extra> with blender profile.
   */
  void create_constraints(ExtraTags *et, Object *ob);
  std::vector<Object *> *write_node(COLLADAFW::Node *, COLLADAFW::Node *, Scene *, Object *, bool);
  void write_profile_COMMON(COLLADAFW::EffectCommon *, Material *);

  void translate_anim_recursive(COLLADAFW::Node *, COLLADAFW::Node *, Object *);

  /**
   * This method will be called if an error in the loading process occurred and the loader cannot
   * continue to load. The writer should undo all operations that have been performed.
   * \param errorMessage: A message containing information about the error that occurred.
   */
  void cancel(const COLLADAFW::String &errorMessage);

  /** This is the method called. The writer hast to prepare to receive data. */
  void start();

  /**
   * This method is called after the last write* method.
   * No other methods will be called after this.
   */
  void finish();

  /**
   * When this method is called, the writer must write the global document asset.
   * \return The writer should return true, if writing succeeded, false otherwise.
   */
  bool writeGlobalAsset(const COLLADAFW::FileInfo *);
  /**
   * If the imported file was made with Blender, return the Blender version used,
   * otherwise return an empty std::string
   */
  std::string get_import_version(const COLLADAFW::FileInfo *asset);

  /**
   * When this method is called, the writer must write the scene.
   * \return The writer should return true, if writing succeeded, false otherwise.
   */
  bool writeScene(const COLLADAFW::Scene *);

  /**
   * When this method is called, the writer must write the entire visual scene.
   * Return The writer should return true, if writing succeeded, false otherwise.
   */
  bool writeVisualScene(const COLLADAFW::VisualScene *);

  /**
   * When this method is called, the writer must handle all nodes contained in the
   * library nodes.
   * \return The writer should return true, if writing succeeded, false otherwise.
   */
  bool writeLibraryNodes(const COLLADAFW::LibraryNodes *);

  /**
   * This function is called only for animations that pass COLLADAFW::validate.
   */
  bool writeAnimation(const COLLADAFW::Animation *);

  /**
   * Called on post-process stage after writeVisualScenes.
   */
  bool writeAnimationList(const COLLADAFW::AnimationList *);

#if WITH_OPENCOLLADA_ANIMATION_CLIP
  /* Please enable this when building with Collada 1.6.65 or newer (also in DocumentImporter.cpp)
   */
  bool writeAnimationClip(const COLLADAFW::AnimationClip *animationClip);
#endif

  /**
   * When this method is called, the writer must write the geometry.
   * \return The writer should return true, if writing succeeded, false otherwise.
   */
  bool writeGeometry(const COLLADAFW::Geometry *);

  /**
   * When this method is called, the writer must write the material.
   * \return The writer should return true, if writing succeeded, false otherwise.
   */
  bool writeMaterial(const COLLADAFW::Material *);

  /**
   * When this method is called, the writer must write the effect.
   * \return The writer should return true, if writing succeeded, false otherwise.
   */
  bool writeEffect(const COLLADAFW::Effect *);

  /**
   * When this method is called, the writer must write the camera.
   * \return The writer should return true, if writing succeeded, false otherwise.
   */
  bool writeCamera(const COLLADAFW::Camera *);

  /**
   * When this method is called, the writer must write the image.
   * \return The writer should return true, if writing succeeded, false otherwise.
   */
  bool writeImage(const COLLADAFW::Image *);

  /**
   * When this method is called, the writer must write the light.
   * \return The writer should return true, if writing succeeded, false otherwise.
   */
  bool writeLight(const COLLADAFW::Light *);

  /**
   * When this method is called, the writer must write the skin controller data.
   * \return The writer should return true, if writing succeeded, false otherwise.
   */
  bool writeSkinControllerData(const COLLADAFW::SkinControllerData *);

  /** This is called on post-process, before writeVisualScenes. */
  bool writeController(const COLLADAFW::Controller *);

  bool writeFormulas(const COLLADAFW::Formulas *);

  bool writeKinematicsScene(const COLLADAFW::KinematicsScene *);

  /** Add element and data for UniqueId */
  bool addExtraTags(const COLLADAFW::UniqueId &uid, ExtraTags *extra_tags);
  /** Get an existing #ExtraTags for uid */
  ExtraTags *getExtraTags(const COLLADAFW::UniqueId &uid);

  bool is_armature(COLLADAFW::Node *node);

 private:
  const ImportSettings *import_settings;

  /** Current import stage we're in. */
  ImportStage mImportStage;

  bContext *mContext;
  ViewLayer *view_layer;

  UnitConverter unit_converter;
  ArmatureImporter armature_importer;
  MeshImporter mesh_importer;
  AnimationImporter anim_importer;

  /** TagsMap typedef for uid_tags_map. */
  typedef std::map<std::string, ExtraTags *> TagsMap;
  /** Tags map of unique id as a string and ExtraTags instance. */
  TagsMap uid_tags_map;

  UidImageMap uid_image_map;
  std::map<COLLADAFW::UniqueId, Material *> uid_material_map;
  std::map<COLLADAFW::UniqueId, Material *> uid_effect_map;
  std::map<COLLADAFW::UniqueId, Camera *> uid_camera_map;
  std::map<COLLADAFW::UniqueId, Light *> uid_light_map;
  std::map<Material *, TexIndexTextureArrayMap> material_texture_mapping_map;
  std::multimap<COLLADAFW::UniqueId, Object *> object_map;
  std::map<COLLADAFW::UniqueId, COLLADAFW::Node *> node_map;
  std::vector<const COLLADAFW::VisualScene *> vscenes;
  std::vector<Object *> libnode_ob;

  std::map<COLLADAFW::UniqueId, COLLADAFW::Node *>
      root_map; /* find root joint by child joint uid, for bone tree evaluation during resampling
                 */
  std::map<COLLADAFW::UniqueId, const COLLADAFW::Object *> FW_object_map;

  std::string import_from_version;

  void report_unknown_reference(const COLLADAFW::Node &node, const std::string object_type);
};