Blender  V3.3
DocumentImporter.cpp
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 
7 /* TODO:
8  * * name imported objects
9  * * import object rotation as euler */
10 
11 #include <algorithm> /* sort() */
12 #include <map>
13 #include <string>
14 
15 #include "COLLADAFWArrayPrimitiveType.h"
16 #include "COLLADAFWCamera.h"
17 #include "COLLADAFWColorOrTexture.h"
18 #include "COLLADAFWIndexList.h"
19 #include "COLLADAFWLibraryNodes.h"
20 #include "COLLADAFWLight.h"
21 #include "COLLADAFWMeshPrimitiveWithFaceVertexCount.h"
22 #include "COLLADAFWPolygons.h"
23 #include "COLLADAFWRoot.h"
24 #include "COLLADAFWSampler.h"
25 #include "COLLADAFWStableHeaders.h"
26 #include "COLLADAFWTypes.h"
27 #include "COLLADAFWVisualScene.h"
28 
29 #include "COLLADASaxFWLIExtraDataCallbackHandler.h"
30 #include "COLLADASaxFWLLoader.h"
31 
32 #include "MEM_guardedalloc.h"
33 
34 #include "BLI_fileops.h"
35 #include "BLI_listbase.h"
36 #include "BLI_math.h"
37 #include "BLI_string.h"
38 #include "BLI_utildefines.h"
39 
40 #include "BKE_camera.h"
41 #include "BKE_collection.h"
42 #include "BKE_fcurve.h"
43 #include "BKE_global.h"
44 #include "BKE_image.h"
45 #include "BKE_layer.h"
46 #include "BKE_lib_id.h"
47 #include "BKE_light.h"
48 #include "BKE_material.h"
49 #include "BKE_scene.h"
50 
51 #include "BLI_path_util.h"
52 
53 #include "DNA_camera_types.h"
54 #include "DNA_light_types.h"
55 
56 #include "RNA_access.h"
57 
58 #include "WM_api.h"
59 #include "WM_types.h"
60 
61 #include "DEG_depsgraph.h"
62 #include "DEG_depsgraph_build.h"
63 
64 #include "DocumentImporter.h"
65 #include "ErrorHandler.h"
66 #include "ExtraHandler.h"
67 #include "TransformReader.h"
68 
69 #include "Materials.h"
70 #include "collada_internal.h"
71 #include "collada_utils.h"
72 
73 /*
74  * COLLADA Importer limitations:
75  * - no multiple scene import, all objects are added to active scene
76  */
77 
78 // #define COLLADA_DEBUG
79 /* creates empties for each imported bone on layer 2, for debugging */
80 // #define ARMATURE_TEST
81 
83  : import_settings(import_settings),
84  mImportStage(Fetching_Scene_data),
85  mContext(C),
86  view_layer(CTX_data_view_layer(mContext)),
87  armature_importer(&unit_converter,
88  &mesh_importer,
91  view_layer,
92  import_settings),
93  mesh_importer(
94  &unit_converter, &armature_importer, CTX_data_main(C), CTX_data_scene(C), view_layer),
95  anim_importer(C, &unit_converter, &armature_importer, CTX_data_scene(C))
96 {
97 }
98 
100 {
101  TagsMap::iterator etit;
102  etit = uid_tags_map.begin();
103  while (etit != uid_tags_map.end()) {
104  delete etit->second;
105  etit++;
106  }
107 }
108 
110 {
111  ErrorHandler errorHandler;
112  COLLADASaxFWL::Loader loader(&errorHandler);
113  COLLADAFW::Root root(&loader, this);
114  ExtraHandler *ehandler = new ExtraHandler(this, &(this->anim_importer));
115 
116  loader.registerExtraDataCallbackHandler(ehandler);
117 
118  /* deselect all to select new objects */
120 
121  std::string mFilename = std::string(this->import_settings->filepath);
122  const std::string encodedFilename = bc_url_encode(mFilename);
123  if (!root.loadDocument(encodedFilename)) {
124  fprintf(stderr, "COLLADAFW::Root::loadDocument() returned false on 1st pass\n");
125  delete ehandler;
126  return false;
127  }
128 
129  if (errorHandler.hasError()) {
130  delete ehandler;
131  return false;
132  }
133 
135  mImportStage = Fetching_Controller_data;
136  COLLADASaxFWL::Loader loader2;
137  COLLADAFW::Root root2(&loader2, this);
138 
139  if (!root2.loadDocument(encodedFilename)) {
140  fprintf(stderr, "COLLADAFW::Root::loadDocument() returned false on 2nd pass\n");
141  delete ehandler;
142  return false;
143  }
144 
145  delete ehandler;
146 
147  return true;
148 }
149 
150 void DocumentImporter::cancel(const COLLADAFW::String &errorMessage)
151 {
152  /* TODO: if possible show error info
153  *
154  * Should we get rid of invisible Meshes that were created so far
155  * or maybe create objects at coordinate space origin?
156  *
157  * The latter sounds better. */
158 }
159 
161 {
162 }
163 
165 {
166  if (mImportStage == Fetching_Controller_data) {
167  return;
168  }
169 
170  Main *bmain = CTX_data_main(mContext);
171  /* TODO: create a new scene except the selected <visual_scene> -
172  * use current blender scene for it */
173  Scene *sce = CTX_data_scene(mContext);
174  unit_converter.calculate_scale(*sce);
175 
176  std::vector<Object *> *objects_to_scale = new std::vector<Object *>();
177 
179  std::vector<const COLLADAFW::VisualScene *>::iterator sit;
180  for (sit = vscenes.begin(); sit != vscenes.end(); sit++) {
181  PointerRNA sceneptr, unit_settings;
182  PropertyRNA *system, *scale;
183 
184  /* for scene unit settings: system, scale_length */
185 
186  RNA_id_pointer_create(&sce->id, &sceneptr);
187  unit_settings = RNA_pointer_get(&sceneptr, "unit_settings");
188  system = RNA_struct_find_property(&unit_settings, "system");
189  scale = RNA_struct_find_property(&unit_settings, "scale_length");
190 
191  if (this->import_settings->import_units) {
192 
193  switch (unit_converter.isMetricSystem()) {
195  RNA_property_enum_set(&unit_settings, system, USER_UNIT_METRIC);
196  break;
198  RNA_property_enum_set(&unit_settings, system, USER_UNIT_IMPERIAL);
199  break;
200  default:
201  RNA_property_enum_set(&unit_settings, system, USER_UNIT_NONE);
202  break;
203  }
204  float unit_factor = unit_converter.getLinearMeter();
205  RNA_property_float_set(&unit_settings, scale, unit_factor);
206  fprintf(stdout, "Collada: Adjusting Blender units to Importset units: %f.\n", unit_factor);
207  }
208 
209  /* Write nodes to scene */
210  fprintf(stderr, "+-- Import Scene --------\n");
211  const COLLADAFW::NodePointerArray &roots = (*sit)->getRootNodes();
212  for (unsigned int i = 0; i < roots.getCount(); i++) {
213  std::vector<Object *> *objects_done = write_node(roots[i], nullptr, sce, nullptr, false);
214  objects_to_scale->insert(
215  objects_to_scale->end(), objects_done->begin(), objects_done->end());
216  delete objects_done;
217  }
218  }
219 
220  mesh_importer.optimize_material_assignements();
221 
222  armature_importer.set_tags_map(this->uid_tags_map);
223  armature_importer.make_armatures(mContext, *objects_to_scale);
224  armature_importer.make_shape_keys(mContext);
225 
226 #if 0
227  armature_importer.fix_animation();
228 #endif
229 
230  for (const COLLADAFW::VisualScene *vscene : vscenes) {
231  const COLLADAFW::NodePointerArray &roots = vscene->getRootNodes();
232 
233  for (unsigned int i = 0; i < roots.getCount(); i++) {
234  translate_anim_recursive(roots[i], nullptr, nullptr);
235  }
236  }
237 
238  if (!libnode_ob.empty()) {
239 
240  fprintf(stderr, "| Cleanup: free %d library nodes\n", (int)libnode_ob.size());
241  /* free all library_nodes */
242  std::vector<Object *>::iterator it;
243  for (it = libnode_ob.begin(); it != libnode_ob.end(); it++) {
244  Object *ob = *it;
245  BKE_scene_collections_object_remove(bmain, sce, ob, true);
246  }
247  libnode_ob.clear();
248  }
249 
250  bc_match_scale(objects_to_scale, unit_converter, !this->import_settings->import_units);
251 
252  delete objects_to_scale;
253 
254  /* update scene */
257  WM_event_add_notifier(mContext, NC_OBJECT | ND_TRANSFORM, nullptr);
258 }
259 
261  COLLADAFW::Node *par = nullptr,
262  Object *parob = nullptr)
263 {
264  /* The split in T29246, root_map must point at actual root when
265  * calculating bones in apply_curves_as_matrix. - actual root is the root node.
266  * This has to do with inverse bind poses being world space
267  * (the sources for skinned bones' rest-poses) and the way
268  * non-skinning nodes have their "rest-pose" recursively calculated.
269  * XXX TODO: design issue, how to support unrelated joints taking
270  * part in skinning. */
271  if (par) { // && par->getType() == COLLADAFW::Node::JOINT) {
272  /* If par is root if there's no corresponding key in root_map. */
273  if (root_map.find(par->getUniqueId()) == root_map.end()) {
274  root_map[node->getUniqueId()] = node;
275  }
276  else {
277  root_map[node->getUniqueId()] = root_map[par->getUniqueId()];
278  }
279  }
280 
281 #if 0
282  COLLADAFW::Transformation::TransformationType types[] = {
283  COLLADAFW::Transformation::ROTATE,
284  COLLADAFW::Transformation::SCALE,
285  COLLADAFW::Transformation::TRANSLATE,
286  COLLADAFW::Transformation::MATRIX,
287  };
288 
289  Object *ob;
290 #endif
291  unsigned int i;
292 
293  if (node->getType() == COLLADAFW::Node::JOINT && par == nullptr) {
294  /* For Skeletons without root node we have to simulate the
295  * root node here and recursively enter the same function
296  * XXX: maybe this can be made more elegant. */
298  }
299  else {
300  anim_importer.translate_Animations(
301  node, root_map, object_map, FW_object_map, uid_material_map);
302  COLLADAFW::NodePointerArray &children = node->getChildNodes();
303  for (i = 0; i < children.getCount(); i++) {
304  translate_anim_recursive(children[i], node, nullptr);
305  }
306  }
307 }
308 
309 std::string DocumentImporter::get_import_version(const COLLADAFW::FileInfo *asset)
310 {
311  const char AUTORING_TOOL[] = "authoring_tool";
312  const std::string BLENDER("Blender ");
313  const COLLADAFW::FileInfo::ValuePairPointerArray &valuePairs = asset->getValuePairArray();
314  for (size_t i = 0, count = valuePairs.getCount(); i < count; i++) {
315  const COLLADAFW::FileInfo::ValuePair *valuePair = valuePairs[i];
316  const COLLADAFW::String &key = valuePair->first;
317  const COLLADAFW::String &value = valuePair->second;
318  if (key == AUTORING_TOOL) {
319  if (value.compare(0, BLENDER.length(), BLENDER) == 0) {
320  /* Was made with Blender, now get version string */
321  std::string v = value.substr(BLENDER.length());
322  std::string::size_type n = v.find(" ");
323  if (n > 0) {
324  return v.substr(0, n);
325  }
326  }
327  }
328  }
329  return "";
330 }
331 
332 bool DocumentImporter::writeGlobalAsset(const COLLADAFW::FileInfo *asset)
333 {
334  unit_converter.read_asset(asset);
335  import_from_version = get_import_version(asset);
336  anim_importer.set_import_from_version(import_from_version);
337  return true;
338 }
339 
341 {
342  /* XXX could store the scene id, but do nothing for now */
343  return true;
344 }
345 Object *DocumentImporter::create_camera_object(COLLADAFW::InstanceCamera *camera, Scene *sce)
346 {
347  const COLLADAFW::UniqueId &cam_uid = camera->getInstanciatedObjectId();
348  if (uid_camera_map.find(cam_uid) == uid_camera_map.end()) {
349  // fprintf(stderr, "Couldn't find camera by UID.\n");
350  return nullptr;
351  }
352 
353  Main *bmain = CTX_data_main(mContext);
354  Object *ob = bc_add_object(bmain, sce, view_layer, OB_CAMERA, nullptr);
355  Camera *cam = uid_camera_map[cam_uid];
356  Camera *old_cam = (Camera *)ob->data;
357  ob->data = cam;
358  BKE_id_free_us(bmain, old_cam);
359  return ob;
360 }
361 
362 Object *DocumentImporter::create_light_object(COLLADAFW::InstanceLight *lamp, Scene *sce)
363 {
364  const COLLADAFW::UniqueId &lamp_uid = lamp->getInstanciatedObjectId();
365  if (uid_light_map.find(lamp_uid) == uid_light_map.end()) {
366  fprintf(stderr, "Couldn't find light by UID.\n");
367  return nullptr;
368  }
369 
370  Main *bmain = CTX_data_main(mContext);
371  Object *ob = bc_add_object(bmain, sce, view_layer, OB_LAMP, nullptr);
372  Light *la = uid_light_map[lamp_uid];
373  Light *old_light = (Light *)ob->data;
374  ob->data = la;
375  BKE_id_free_us(bmain, old_light);
376  return ob;
377 }
378 
380  COLLADAFW::Node *source_node,
381  COLLADAFW::Node *instance_node,
382  Scene *sce,
383  bool is_library_node)
384 {
385  // fprintf(stderr, "create <instance_node> under node id=%s from node id=%s\n", instance_node ?
386  // instance_node->getOriginalId().c_str() : NULL, source_node ?
387  // source_node->getOriginalId().c_str() : NULL);
388 
389  Main *bmain = CTX_data_main(mContext);
390  Object *obn = (Object *)BKE_id_copy(bmain, &source_ob->id);
391  id_us_min(&obn->id);
393  BKE_collection_object_add_from(bmain, sce, source_ob, obn);
394 
395  if (instance_node) {
396  anim_importer.read_node_transform(instance_node, obn);
397  /* if we also have a source_node (always ;), take its
398  * transformation matrix and apply it to the newly instantiated
399  * object to account for node hierarchy transforms in `.dae`. */
400  if (source_node) {
401  COLLADABU::Math::Matrix4 mat4 = source_node->getTransformationMatrix();
402  COLLADABU::Math::Matrix4 bmat4 =
403  mat4.transpose(); /* transpose to get blender row-major order */
404  float mat[4][4];
405  for (int i = 0; i < 4; i++) {
406  for (int j = 0; j < 4; j++) {
407  mat[i][j] = bmat4[i][j];
408  }
409  }
410  /* calc new matrix and apply */
411  mul_m4_m4m4(obn->obmat, obn->obmat, mat);
412  BKE_object_apply_mat4(obn, obn->obmat, false, false);
413  }
414  }
415  else {
416  anim_importer.read_node_transform(source_node, obn);
417  }
418 
419  /*DAG_relations_tag_update(CTX_data_main(mContext));*/
420 
421  COLLADAFW::NodePointerArray &children = source_node->getChildNodes();
422  if (children.getCount()) {
423  for (unsigned int i = 0; i < children.getCount(); i++) {
424  COLLADAFW::Node *child_node = children[i];
425  const COLLADAFW::UniqueId &child_id = child_node->getUniqueId();
426  if (object_map.find(child_id) == object_map.end()) {
427  continue;
428  }
429  COLLADAFW::InstanceNodePointerArray &inodes = child_node->getInstanceNodes();
430  Object *new_child = nullptr;
431  if (inodes.getCount()) { /* \todo loop through instance nodes */
432  const COLLADAFW::UniqueId &id = inodes[0]->getInstanciatedObjectId();
433  fprintf(stderr, "Doing %d child nodes\n", (int)node_map.count(id));
434  new_child = create_instance_node(
435  object_map.find(id)->second, node_map[id], child_node, sce, is_library_node);
436  }
437  else {
438  new_child = create_instance_node(
439  object_map.find(child_id)->second, child_node, nullptr, sce, is_library_node);
440  }
441  bc_set_parent(new_child, obn, mContext, true);
442 
443  if (is_library_node) {
444  libnode_ob.push_back(new_child);
445  }
446  }
447  }
448 
449  return obn;
450 }
451 
453 {
454  if (et && et->isProfile("blender")) {
455  std::string name;
456  short type = 0;
457  et->setData("type", &type);
458  BKE_constraint_add_for_object(ob, "Test_con", type);
459  }
460 }
461 
462 void DocumentImporter::report_unknown_reference(const COLLADAFW::Node &node,
463  const std::string object_type)
464 {
465  std::string id = node.getOriginalId();
466  std::string name = node.getName();
467  fprintf(stderr,
468  "error: node id=\"%s\", name=\"%s\" refers to an undefined %s.\n",
469  id.c_str(),
470  name.c_str(),
471  object_type.c_str());
472 }
473 
474 std::vector<Object *> *DocumentImporter::write_node(COLLADAFW::Node *node,
475  COLLADAFW::Node *parent_node,
476  Scene *sce,
477  Object *par,
478  bool is_library_node)
479 {
480  Main *bmain = CTX_data_main(mContext);
481  Object *ob = nullptr;
482  bool is_joint = node->getType() == COLLADAFW::Node::JOINT;
483  bool read_transform = true;
484  std::string id = node->getOriginalId();
485  std::string name = node->getName();
486 
487  /* if node has child nodes write them */
488  COLLADAFW::NodePointerArray &child_nodes = node->getChildNodes();
489 
490  std::vector<Object *> *objects_done = new std::vector<Object *>();
491  std::vector<Object *> *root_objects = new std::vector<Object *>();
492 
493  fprintf(
494  stderr, "| %s id='%s', name='%s'\n", is_joint ? "JOINT" : "NODE ", id.c_str(), name.c_str());
495 
496  if (is_joint) {
497  if (parent_node == nullptr && !is_library_node) {
498  /* A Joint on root level is a skeleton without root node.
499  * Here we add the armature "on the fly": */
500  par = bc_add_object(bmain, sce, view_layer, OB_ARMATURE, std::string("Armature").c_str());
501  objects_done->push_back(par);
502  root_objects->push_back(par);
503  object_map.insert(std::pair<COLLADAFW::UniqueId, Object *>(node->getUniqueId(), par));
504  node_map[node->getUniqueId()] = node;
505  }
506  if (parent_node == nullptr || parent_node->getType() != COLLADAFW::Node::JOINT) {
507  armature_importer.add_root_joint(node, par);
508  }
509 
510  if (parent_node == nullptr) {
511  /* for skeletons without root node all has been done above.
512  * Skeletons with root node are handled further down. */
513  goto finally;
514  }
515  }
516  else {
517  COLLADAFW::InstanceGeometryPointerArray &geom = node->getInstanceGeometries();
518  COLLADAFW::InstanceCameraPointerArray &camera = node->getInstanceCameras();
519  COLLADAFW::InstanceLightPointerArray &lamp = node->getInstanceLights();
520  COLLADAFW::InstanceControllerPointerArray &controller = node->getInstanceControllers();
521  COLLADAFW::InstanceNodePointerArray &inst_node = node->getInstanceNodes();
522  size_t geom_done = 0;
523  size_t camera_done = 0;
524  size_t lamp_done = 0;
525  size_t controller_done = 0;
526  size_t inst_done = 0;
527 
528  /* XXX linking object with the first <instance_geometry>, though a node may have more of
529  * them... maybe join multiple <instance_...> meshes into 1, and link object with it? not
530  * sure... <instance_geometry> */
531  while (geom_done < geom.getCount()) {
532  ob = mesh_importer.create_mesh_object(node, geom[geom_done], false, uid_material_map);
533  if (ob == nullptr) {
534  report_unknown_reference(*node, "instance_mesh");
535  }
536  else {
537  objects_done->push_back(ob);
538  if (parent_node == nullptr) {
539  root_objects->push_back(ob);
540  }
541  }
542  geom_done++;
543  }
544  while (camera_done < camera.getCount()) {
545  ob = create_camera_object(camera[camera_done], sce);
546  if (ob == nullptr) {
547  report_unknown_reference(*node, "instance_camera");
548  }
549  else {
550  objects_done->push_back(ob);
551  if (parent_node == nullptr) {
552  root_objects->push_back(ob);
553  }
554  }
555  camera_done++;
556  }
557  while (lamp_done < lamp.getCount()) {
558  ob = create_light_object(lamp[lamp_done], sce);
559  if (ob == nullptr) {
560  report_unknown_reference(*node, "instance_light");
561  }
562  else {
563  objects_done->push_back(ob);
564  if (parent_node == nullptr) {
565  root_objects->push_back(ob);
566  }
567  }
568  lamp_done++;
569  }
570  while (controller_done < controller.getCount()) {
571  COLLADAFW::InstanceGeometry *geometry = (COLLADAFW::InstanceGeometry *)
572  controller[controller_done];
573  ob = mesh_importer.create_mesh_object(node, geometry, true, uid_material_map);
574  if (ob == nullptr) {
575  report_unknown_reference(*node, "instance_controller");
576  }
577  else {
578  objects_done->push_back(ob);
579  if (parent_node == nullptr) {
580  root_objects->push_back(ob);
581  }
582  }
583  controller_done++;
584  }
585  /* XXX instance_node is not supported yet */
586  while (inst_done < inst_node.getCount()) {
587  const COLLADAFW::UniqueId &node_id = inst_node[inst_done]->getInstanciatedObjectId();
588  if (object_map.find(node_id) == object_map.end()) {
589  fprintf(stderr,
590  "Cannot find object for node referenced by <instance_node name=\"%s\">.\n",
591  inst_node[inst_done]->getName().c_str());
592  ob = nullptr;
593  }
594  else {
595  std::pair<std::multimap<COLLADAFW::UniqueId, Object *>::iterator,
596  std::multimap<COLLADAFW::UniqueId, Object *>::iterator>
597  pair_iter = object_map.equal_range(node_id);
598  for (std::multimap<COLLADAFW::UniqueId, Object *>::iterator it2 = pair_iter.first;
599  it2 != pair_iter.second;
600  it2++) {
601  Object *source_ob = (Object *)it2->second;
602  COLLADAFW::Node *source_node = node_map[node_id];
603  ob = create_instance_node(source_ob, source_node, node, sce, is_library_node);
604  objects_done->push_back(ob);
605  if (parent_node == nullptr) {
606  root_objects->push_back(ob);
607  }
608  }
609  }
610  inst_done++;
611 
612  read_transform = false;
613  }
614 
615  /* if node is empty - create empty object
616  * XXX empty node may not mean it is empty object, not sure about this */
617  if ((geom_done + camera_done + lamp_done + controller_done + inst_done) < 1) {
618  /* Check if Object is armature, by checking if immediate child is a JOINT node. */
619  if (is_armature(node)) {
620  ob = bc_add_object(bmain, sce, view_layer, OB_ARMATURE, name.c_str());
621  }
622  else {
623  ob = bc_add_object(bmain, sce, view_layer, OB_EMPTY, nullptr);
624  }
625  objects_done->push_back(ob);
626  if (parent_node == nullptr) {
627  root_objects->push_back(ob);
628  }
629  }
630 
631  /* XXX: if there are multiple instances, only one is stored. */
632 
633  if (!ob) {
634  goto finally;
635  }
636 
637  for (Object *ob : *objects_done) {
638  std::string nodename = node->getName().empty() ? node->getOriginalId() : node->getName();
639  BKE_libblock_rename(bmain, &ob->id, (char *)nodename.c_str());
640  object_map.insert(std::pair<COLLADAFW::UniqueId, Object *>(node->getUniqueId(), ob));
641  node_map[node->getUniqueId()] = node;
642 
643  if (is_library_node) {
644  libnode_ob.push_back(ob);
645  }
646  }
647 
648  /* create_constraints(et,ob); */
649  }
650 
651  for (Object *ob : *objects_done) {
652  if (read_transform) {
653  anim_importer.read_node_transform(node, ob); /* overwrites location set earlier */
654  }
655 
656  if (!is_joint) {
657  if (par && ob) {
658  ob->parent = par;
659  ob->partype = PAROBJECT;
660  ob->parsubstr[0] = 0;
661 
662  // bc_set_parent(ob, par, mContext, false);
663  }
664  }
665  }
666 
667  if (objects_done->empty()) {
668  ob = nullptr;
669  }
670  else {
671  ob = *objects_done->begin();
672  }
673 
674  for (unsigned int i = 0; i < child_nodes.getCount(); i++) {
675  std::vector<Object *> *child_objects;
676  child_objects = write_node(child_nodes[i], node, sce, ob, is_library_node);
677  delete child_objects;
678  }
679 
680 finally:
681  delete objects_done;
682 
683  return root_objects;
684 }
685 
686 bool DocumentImporter::writeVisualScene(const COLLADAFW::VisualScene *visualScene)
687 {
688  if (mImportStage == Fetching_Controller_data) {
689  return true;
690  }
691 
692  /* This method called on post process after writeGeometry, writeMaterial, etc. */
693 
694  /* For each <node> in <visual_scene>:
695  * create an Object
696  * if Mesh (previously created in writeGeometry) to which <node> corresponds exists,
697  * link Object with that mesh.
698  *
699  * Update: since we cannot link a Mesh with Object in
700  * writeGeometry because <geometry> does not reference <node>,
701  * we link Objects with Meshes here.
702  */
703  vscenes.push_back(visualScene);
704 
705  return true;
706 }
707 
708 bool DocumentImporter::writeLibraryNodes(const COLLADAFW::LibraryNodes *libraryNodes)
709 {
710  if (mImportStage == Fetching_Controller_data) {
711  return true;
712  }
713 
714  Scene *sce = CTX_data_scene(mContext);
715 
716  const COLLADAFW::NodePointerArray &nodes = libraryNodes->getNodes();
717 
718  fprintf(stderr, "+-- Read Library nodes ----------\n");
719  for (unsigned int i = 0; i < nodes.getCount(); i++) {
720  std::vector<Object *> *child_objects;
721  child_objects = write_node(nodes[i], nullptr, sce, nullptr, true);
722  delete child_objects;
723  }
724  return true;
725 }
726 
727 bool DocumentImporter::writeGeometry(const COLLADAFW::Geometry *geom)
728 {
729  if (mImportStage == Fetching_Controller_data) {
730  return true;
731  }
732 
733  return mesh_importer.write_geometry(geom);
734 }
735 
737 {
738  if (mImportStage == Fetching_Controller_data) {
739  return true;
740  }
741 
742  Main *bmain = CTX_data_main(mContext);
743  const std::string &str_mat_id = cmat->getName().empty() ? cmat->getOriginalId() :
744  cmat->getName();
745  Material *ma = BKE_material_add(bmain, (char *)str_mat_id.c_str());
746  id_us_min(&ma->id);
747 
748  this->uid_effect_map[cmat->getInstantiatedEffect()] = ma;
749  this->uid_material_map[cmat->getUniqueId()] = ma;
750 
751  return true;
752 }
753 
754 void DocumentImporter::write_profile_COMMON(COLLADAFW::EffectCommon *ef, Material *ma)
755 {
756  MaterialNode matNode = MaterialNode(mContext, ef, ma, uid_image_map);
757 
758  /* Direct mapping to principled BSDF Shader */
759  matNode.set_diffuse(ef->getDiffuse());
760  matNode.set_emission(ef->getEmission());
761  matNode.set_ior(ef->getIndexOfRefraction());
762  matNode.set_alpha(ef->getOpaqueMode(), ef->getTransparent(), ef->getTransparency());
763 
764  /* following mapping still needs to be verified */
765 #if 0
766  /* needs rework to be done for 2.81 */
767  matNode.set_shininess(ef->getShininess());
768 #endif
769  matNode.set_reflectivity(ef->getReflectivity());
770 
771  /* not supported by principled BSDF */
772  matNode.set_ambient(ef->getAmbient());
773  matNode.set_specular(ef->getSpecular());
774  matNode.set_reflective(ef->getReflective());
775 
776  matNode.update_material_nodetree();
777 }
778 
780 {
781  if (mImportStage == Fetching_Controller_data) {
782  return true;
783  }
784 
785  const COLLADAFW::UniqueId &uid = effect->getUniqueId();
786 
787  if (uid_effect_map.find(uid) == uid_effect_map.end()) {
788  fprintf(stderr, "Couldn't find a material by UID.\n");
789  return true;
790  }
791 
792  Material *ma = uid_effect_map[uid];
793  std::map<COLLADAFW::UniqueId, Material *>::iterator iter;
794  for (iter = uid_material_map.begin(); iter != uid_material_map.end(); iter++) {
795  if (iter->second == ma) {
796  this->FW_object_map[iter->first] = effect;
797  break;
798  }
799  }
800  COLLADAFW::CommonEffectPointerArray common_efs = effect->getCommonEffects();
801  if (common_efs.getCount() < 1) {
802  fprintf(stderr, "Couldn't find <profile_COMMON>.\n");
803  return true;
804  }
805  /* XXX TODO: Take all <profile_common>s
806  * Currently only first <profile_common> is supported */
807  COLLADAFW::EffectCommon *ef = common_efs[0];
808  write_profile_COMMON(ef, ma);
809  this->FW_object_map[effect->getUniqueId()] = effect;
810 
811  return true;
812 }
813 
815 {
816  if (mImportStage == Fetching_Controller_data) {
817  return true;
818  }
819 
820  Main *bmain = CTX_data_main(mContext);
821  Camera *cam = nullptr;
822  std::string cam_id, cam_name;
823 
824  ExtraTags *et = getExtraTags(camera->getUniqueId());
825  cam_id = camera->getOriginalId();
826  cam_name = camera->getName();
827  if (cam_name.empty()) {
828  cam = (Camera *)BKE_camera_add(bmain, (char *)cam_id.c_str());
829  }
830  else {
831  cam = (Camera *)BKE_camera_add(bmain, (char *)cam_name.c_str());
832  }
833 
834  if (!cam) {
835  fprintf(stderr, "Cannot create camera.\n");
836  return true;
837  }
838 
839  if (et && et->isProfile("blender")) {
840  et->setData("shiftx", &(cam->shiftx));
841  et->setData("shifty", &(cam->shifty));
842  et->setData("dof_distance", &(cam->dof.focus_distance));
843  }
844  cam->clip_start = camera->getNearClippingPlane().getValue();
845  cam->clip_end = camera->getFarClippingPlane().getValue();
846 
847  COLLADAFW::Camera::CameraType type = camera->getCameraType();
848  switch (type) {
849  case COLLADAFW::Camera::ORTHOGRAPHIC: {
850  cam->type = CAM_ORTHO;
851  } break;
852  case COLLADAFW::Camera::PERSPECTIVE: {
853  cam->type = CAM_PERSP;
854  } break;
855  case COLLADAFW::Camera::UNDEFINED_CAMERATYPE: {
856  fprintf(stderr, "Current camera type is not supported.\n");
857  cam->type = CAM_PERSP;
858  } break;
859  }
860 
861  switch (camera->getDescriptionType()) {
862  case COLLADAFW::Camera::ASPECTRATIO_AND_Y: {
863  switch (cam->type) {
864  case CAM_ORTHO: {
865  double ymag = 2 * camera->getYMag().getValue();
866  double aspect = camera->getAspectRatio().getValue();
867  double xmag = aspect * ymag;
868  cam->ortho_scale = (float)xmag;
869  } break;
870  case CAM_PERSP:
871  default: {
872  double yfov = camera->getYFov().getValue();
873  double aspect = camera->getAspectRatio().getValue();
874 
875  /* NOTE: Needs more testing (As we currently have no official test data for this) */
876 
877  double xfov = 2.0f * atanf(aspect * tanf(DEG2RADF(yfov) * 0.5f));
878  cam->lens = fov_to_focallength(xfov, cam->sensor_x);
879  } break;
880  }
881  } break;
882  /* XXX correct way to do following four is probably to get also render
883  * size and determine proper settings from that somehow */
884  case COLLADAFW::Camera::ASPECTRATIO_AND_X:
885  case COLLADAFW::Camera::SINGLE_X:
886  case COLLADAFW::Camera::X_AND_Y: {
887  switch (cam->type) {
888  case CAM_ORTHO:
889  cam->ortho_scale = (float)camera->getXMag().getValue() * 2;
890  break;
891  case CAM_PERSP:
892  default: {
893  double x = camera->getXFov().getValue();
894  /* X is in degrees, cam->lens is in millimeters. */
895  cam->lens = fov_to_focallength(DEG2RADF(x), cam->sensor_x);
896  } break;
897  }
898  } break;
899  case COLLADAFW::Camera::SINGLE_Y: {
900  switch (cam->type) {
901  case CAM_ORTHO:
902  cam->ortho_scale = (float)camera->getYMag().getValue();
903  break;
904  case CAM_PERSP:
905  default: {
906  double yfov = camera->getYFov().getValue();
907  /* yfov is in degrees, cam->lens is in millimeters. */
908  cam->lens = fov_to_focallength(DEG2RADF(yfov), cam->sensor_x);
909  } break;
910  }
911  } break;
912  case COLLADAFW::Camera::UNDEFINED:
913  /* read nothing, use blender defaults. */
914  break;
915  }
916 
917  this->uid_camera_map[camera->getUniqueId()] = cam;
918  this->FW_object_map[camera->getUniqueId()] = camera;
919  /* XXX import camera options */
920  return true;
921 }
922 
924 {
925  if (mImportStage == Fetching_Controller_data) {
926  return true;
927  }
928 
929  const std::string &imagepath = image->getImageURI().toNativePath();
930 
931  char dir[FILE_MAX];
932  char absolute_path[FILE_MAX];
933  const char *workpath;
934 
935  BLI_split_dir_part(this->import_settings->filepath, dir, sizeof(dir));
936  BLI_join_dirfile(absolute_path, sizeof(absolute_path), dir, imagepath.c_str());
937  if (BLI_exists(absolute_path)) {
938  workpath = absolute_path;
939  }
940  else {
941  /* Maybe imagepath was already absolute ? */
942  if (!BLI_exists(imagepath.c_str())) {
943  fprintf(stderr, "|! Image not found: %s\n", imagepath.c_str());
944  return true;
945  }
946  workpath = imagepath.c_str();
947  }
948 
949  Image *ima = BKE_image_load_exists(CTX_data_main(mContext), workpath);
950  if (!ima) {
951  fprintf(stderr, "|! Cannot create image: %s\n", workpath);
952  return true;
953  }
954  this->uid_image_map[image->getUniqueId()] = ima;
955  fprintf(stderr, "| import Image: %s\n", workpath);
956  return true;
957 }
958 
960 {
961  if (mImportStage == Fetching_Controller_data) {
962  return true;
963  }
964 
965  Main *bmain = CTX_data_main(mContext);
966  Light *lamp = nullptr;
967  std::string la_id, la_name;
968 
969  ExtraTags *et = getExtraTags(light->getUniqueId());
970 #if 0
971  TagsMap::iterator etit;
972  ExtraTags *et = 0;
973  etit = uid_tags_map.find(light->getUniqueId().toAscii());
974  if (etit != uid_tags_map.end()) {
975  et = etit->second;
976  }
977 #endif
978 
979  la_id = light->getOriginalId();
980  la_name = light->getName();
981  if (la_name.empty()) {
982  lamp = (Light *)BKE_light_add(bmain, (char *)la_id.c_str());
983  }
984  else {
985  lamp = (Light *)BKE_light_add(bmain, (char *)la_name.c_str());
986  }
987 
988  if (!lamp) {
989  fprintf(stderr, "Cannot create light.\n");
990  return true;
991  }
992 
993  /* if we find an ExtraTags for this, use that instead. */
994  if (et && et->isProfile("blender")) {
995  et->setData("type", &(lamp->type));
996  et->setData("flag", &(lamp->flag));
997  et->setData("mode", &(lamp->mode));
998  et->setData("gamma", &(lamp->k));
999  et->setData("red", &(lamp->r));
1000  et->setData("green", &(lamp->g));
1001  et->setData("blue", &(lamp->b));
1002  et->setData("shadow_r", &(lamp->shdwr));
1003  et->setData("shadow_g", &(lamp->shdwg));
1004  et->setData("shadow_b", &(lamp->shdwb));
1005  et->setData("energy", &(lamp->energy));
1006  et->setData("dist", &(lamp->dist));
1007  et->setData("spotsize", &(lamp->spotsize));
1009  et->setData("spotblend", &(lamp->spotblend));
1010  et->setData("att1", &(lamp->att1));
1011  et->setData("att2", &(lamp->att2));
1012  et->setData("falloff_type", &(lamp->falloff_type));
1013  et->setData("clipsta", &(lamp->clipsta));
1014  et->setData("clipend", &(lamp->clipend));
1015  et->setData("bias", &(lamp->bias));
1016  et->setData("soft", &(lamp->soft));
1017  et->setData("bufsize", &(lamp->bufsize));
1018  et->setData("buffers", &(lamp->buffers));
1019  et->setData("area_shape", &(lamp->area_shape));
1020  et->setData("area_size", &(lamp->area_size));
1021  et->setData("area_sizey", &(lamp->area_sizey));
1022  et->setData("area_sizez", &(lamp->area_sizez));
1023  }
1024  else {
1025  float constatt = light->getConstantAttenuation().getValue();
1026  float linatt = light->getLinearAttenuation().getValue();
1027  float quadatt = light->getQuadraticAttenuation().getValue();
1028  float d = 25.0f;
1029  float att1 = 0.0f;
1030  float att2 = 0.0f;
1031  float e = 1.0f;
1032 
1033  if (light->getColor().isValid()) {
1034  COLLADAFW::Color col = light->getColor();
1035  lamp->r = col.getRed();
1036  lamp->g = col.getGreen();
1037  lamp->b = col.getBlue();
1038  }
1039 
1040  if (IS_EQ(linatt, 0.0f) && quadatt > 0.0f) {
1041  att2 = quadatt;
1042  d = sqrt(1.0f / quadatt);
1043  }
1044  /* linear light */
1045  else if (IS_EQ(quadatt, 0.0f) && linatt > 0.0f) {
1046  att1 = linatt;
1047  d = (1.0f / linatt);
1048  }
1049  else if (IS_EQ(constatt, 1.0f)) {
1050  att1 = 1.0f;
1051  }
1052  else {
1053  /* assuming point light (const att = 1.0); */
1054  att1 = 1.0f;
1055  }
1056 
1057  d *= (1.0f / unit_converter.getLinearMeter());
1058 
1059  lamp->energy = e;
1060  lamp->dist = d;
1061 
1062  switch (light->getLightType()) {
1063  case COLLADAFW::Light::AMBIENT_LIGHT: {
1064  lamp->type = LA_SUN; /* TODO: needs more thoughts. */
1065  } break;
1066  case COLLADAFW::Light::SPOT_LIGHT: {
1067  lamp->type = LA_SPOT;
1068  lamp->att1 = att1;
1069  lamp->att2 = att2;
1070  if (IS_EQ(att1, 0.0f) && att2 > 0) {
1072  }
1073  if (IS_EQ(att2, 0.0f) && att1 > 0) {
1075  }
1076  lamp->spotsize = DEG2RADF(light->getFallOffAngle().getValue());
1077  lamp->spotblend = light->getFallOffExponent().getValue();
1078  } break;
1079  case COLLADAFW::Light::DIRECTIONAL_LIGHT: {
1080  /* our sun is very strong, so pick a smaller energy level */
1081  lamp->type = LA_SUN;
1082  } break;
1083  case COLLADAFW::Light::POINT_LIGHT: {
1084  lamp->type = LA_LOCAL;
1085  lamp->att1 = att1;
1086  lamp->att2 = att2;
1087  if (IS_EQ(att1, 0.0f) && att2 > 0) {
1089  }
1090  if (IS_EQ(att2, 0.0f) && att1 > 0) {
1092  }
1093  } break;
1094  case COLLADAFW::Light::UNDEFINED: {
1095  fprintf(stderr, "Current light type is not supported.\n");
1096  lamp->type = LA_LOCAL;
1097  } break;
1098  }
1099  }
1100 
1101  this->uid_light_map[light->getUniqueId()] = lamp;
1102  this->FW_object_map[light->getUniqueId()] = light;
1103  return true;
1104 }
1105 
1106 bool DocumentImporter::writeAnimation(const COLLADAFW::Animation *anim)
1107 {
1108  if (mImportStage == Fetching_Controller_data) {
1109  return true;
1110  }
1111 
1112  return anim_importer.write_animation(anim);
1113 }
1114 
1115 bool DocumentImporter::writeAnimationList(const COLLADAFW::AnimationList *animationList)
1116 {
1117  if (mImportStage == Fetching_Controller_data) {
1118  return true;
1119  }
1120 
1121  /* return true; */
1122  return anim_importer.write_animation_list(animationList);
1123 }
1124 
1125 #if WITH_OPENCOLLADA_ANIMATION_CLIP
1126 bool DocumentImporter::writeAnimationClip(const COLLADAFW::AnimationClip *animationClip)
1127 {
1128  /* Since opencollada 1.6.68: called on post-process stage after writeVisualScenes. */
1129 
1130  if (mImportStage == Fetching_Controller_data) {
1131  return true;
1132  }
1133 
1134  return true;
1135  /* TODO: implement import of AnimationClips */
1136  // return animation_clip_importer.write_animation_clip(animationClip);
1137 }
1138 #endif
1139 
1140 bool DocumentImporter::writeSkinControllerData(const COLLADAFW::SkinControllerData *skin)
1141 {
1142  return armature_importer.write_skin_controller_data(skin);
1143 }
1144 
1145 bool DocumentImporter::writeController(const COLLADAFW::Controller *controller)
1146 {
1147  if (mImportStage == Fetching_Controller_data) {
1148  return true;
1149  }
1150 
1151  return armature_importer.write_controller(controller);
1152 }
1153 
1154 bool DocumentImporter::writeFormulas(const COLLADAFW::Formulas *formulas)
1155 {
1156  return true;
1157 }
1158 
1159 bool DocumentImporter::writeKinematicsScene(const COLLADAFW::KinematicsScene *kinematicsScene)
1160 {
1161  return true;
1162 }
1163 
1164 ExtraTags *DocumentImporter::getExtraTags(const COLLADAFW::UniqueId &uid)
1165 {
1166  if (uid_tags_map.find(uid.toAscii()) == uid_tags_map.end()) {
1167  return nullptr;
1168  }
1169  return uid_tags_map[uid.toAscii()];
1170 }
1171 
1172 bool DocumentImporter::addExtraTags(const COLLADAFW::UniqueId &uid, ExtraTags *extra_tags)
1173 {
1174  uid_tags_map[uid.toAscii()] = extra_tags;
1175  return true;
1176 }
1177 
1178 bool DocumentImporter::is_armature(COLLADAFW::Node *node)
1179 {
1180  COLLADAFW::NodePointerArray &child_nodes = node->getChildNodes();
1181  for (unsigned int i = 0; i < child_nodes.getCount(); i++) {
1182  if (child_nodes[i]->getType() == COLLADAFW::Node::JOINT) {
1183  return true;
1184  }
1185  }
1186 
1187  /* no child is JOINT */
1188  return false;
1189 }
typedef float(TangentPoint)[2]
Camera data-block and utility functions.
void * BKE_camera_add(struct Main *bmain, const char *name)
Definition: camera.c:203
void BKE_collection_object_add_from(struct Main *bmain, struct Scene *scene, struct Object *ob_src, struct Object *ob_dst)
Definition: collection.c:1148
bool BKE_scene_collections_object_remove(struct Main *bmain, struct Scene *scene, struct Object *object, bool free_us)
Definition: collection.c:1224
struct bConstraint * BKE_constraint_add_for_object(struct Object *ob, const char *name, short type)
Definition: constraint.c:5870
struct Scene * CTX_data_scene(const bContext *C)
Definition: context.c:1090
struct ViewLayer * CTX_data_view_layer(const bContext *C)
Definition: context.c:1100
struct Main * CTX_data_main(const bContext *C)
Definition: context.c:1074
struct Image * BKE_image_load_exists(struct Main *bmain, const char *filepath)
void BKE_view_layer_base_deselect_all(struct ViewLayer *view_layer)
Definition: layer.c:388
struct ID * BKE_id_copy(struct Main *bmain, const struct ID *id)
void BKE_libblock_rename(struct Main *bmain, struct ID *id, const char *name) ATTR_NONNULL()
Definition: lib_id.c:1832
void id_us_min(struct ID *id)
Definition: lib_id.c:313
void BKE_id_free_us(struct Main *bmain, void *idv) ATTR_NONNULL()
General operations, lookup, etc. for blender lights.
struct Light * BKE_light_add(struct Main *bmain, const char *name) ATTR_WARN_UNUSED_RESULT
Definition: light.c:203
General operations, lookup, etc. for materials.
struct Material * BKE_material_add(struct Main *bmain, const char *name)
Definition: material.c:289
void BKE_object_apply_mat4(struct Object *ob, const float mat[4][4], bool use_compat, bool use_parent)
Definition: object.cc:3575
sqrt(x)+1/max(0
File and directory operations.
int BLI_exists(const char *path) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
Definition: storage.c:314
void mul_m4_m4m4(float R[4][4], const float A[4][4], const float B[4][4])
Definition: math_matrix.c:259
#define DEG2RADF(_deg)
float fov_to_focallength(float fov, float sensor)
void BLI_split_dir_part(const char *string, char *dir, size_t dirlen)
Definition: path_util.c:1490
#define FILE_MAX
void BLI_join_dirfile(char *__restrict dst, size_t maxlen, const char *__restrict dir, const char *__restrict file) ATTR_NONNULL()
Definition: path_util.c:1531
#define IS_EQ(a, b)
void DEG_id_tag_update(struct ID *id, int flag)
void DEG_relations_tag_update(struct Main *bmain)
@ ID_RECALC_TRANSFORM
Definition: DNA_ID.h:771
@ ID_RECALC_COPY_ON_WRITE
Definition: DNA_ID.h:834
@ ID_RECALC_ANIMATION
Definition: DNA_ID.h:794
@ ID_RECALC_GEOMETRY
Definition: DNA_ID.h:791
struct Camera Camera
@ CAM_PERSP
@ CAM_ORTHO
struct Effect Effect
struct Image Image
struct Light Light
#define LA_SPOT
#define LA_SUN
#define LA_LOCAL
#define LA_FALLOFF_INVSQUARE
#define LA_FALLOFF_INVLINEAR
struct Material Material
@ OB_EMPTY
@ OB_CAMERA
@ OB_ARMATURE
@ OB_LAMP
@ PAROBJECT
#define USER_UNIT_METRIC
#define USER_UNIT_NONE
struct Scene Scene
#define USER_UNIT_IMPERIAL
static Controller * controller
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum type
Read Guarded memory(de)allocation.
in reality light always falls off quadratically Particle Retrieve the data of the particle that spawned the object for example to give variation to multiple instances of an object Point Retrieve information about points in a point cloud Retrieve the edges of an object as it appears to Cycles topology will always appear triangulated Convert a blackbody temperature to an RGB value Normal Generate a perturbed normal from an RGB normal map image Typically used for faking highly detailed surfaces Generate an OSL shader from a file or text data block Image Sample an image file as a texture Sky Generate a procedural sky texture Noise Generate fractal Perlin noise Wave Generate procedural bands or rings with noise Voronoi Generate Worley noise based on the distance to random points Typically used to generate textures such as or biological cells Brick Generate a procedural texture producing bricks Texture Retrieve multiple types of texture coordinates nTypically used as inputs for texture nodes Vector Convert a or normal between and object coordinate space Combine Create a color from its and value channels Color Retrieve a color or the default fallback if none is specified Separate Split a vector into its and Z components Generates normals with round corners and may slow down renders Vector Displace the surface along an arbitrary direction White Return a random value or color based on an input seed Float Map an input float to a curve and outputs a float value Separate Color
in reality light always falls off quadratically Particle Retrieve the data of the particle that spawned the object for example to give variation to multiple instances of an object Point Retrieve information about points in a point cloud Retrieve the edges of an object as it appears to Cycles topology will always appear triangulated Convert a blackbody temperature to an RGB value Normal Generate a perturbed normal from an RGB normal map image Typically used for faking highly detailed surfaces Generate an OSL shader from a file or text data block Image Sample an image file as a texture Sky Generate a procedural sky texture Noise Generate fractal Perlin noise Wave Generate procedural bands or rings with noise Voronoi Generate Worley noise based on the distance to random points Typically used to generate textures such as or biological cells Brick Generate a procedural texture producing bricks Texture Retrieve multiple types of texture coordinates nTypically used as inputs for texture nodes Vector Convert a or normal between camera
#define C
Definition: RandGen.cpp:25
#define ND_TRANSFORM
Definition: WM_types.h:405
#define NC_OBJECT
Definition: WM_types.h:329
ATTR_WARN_UNUSED_RESULT const BMVert const BMEdge * e
ATTR_WARN_UNUSED_RESULT const BMVert * v
int size_type
virtual const char * getName() const
Definition: btBox2dShape.h:301
void read_node_transform(COLLADAFW::Node *node, Object *ob)
bool write_animation_list(const COLLADAFW::AnimationList *animlist)
void translate_Animations(COLLADAFW::Node *Node, std::map< COLLADAFW::UniqueId, COLLADAFW::Node * > &root_map, std::multimap< COLLADAFW::UniqueId, Object * > &object_map, std::map< COLLADAFW::UniqueId, const COLLADAFW::Object * > FW_object_map, std::map< COLLADAFW::UniqueId, Material * > uid_material_map)
bool write_animation(const COLLADAFW::Animation *anim)
void set_import_from_version(std::string import_from_version)
void make_shape_keys(bContext *C)
void make_armatures(bContext *C, std::vector< Object * > &objects_to_scale)
bool write_skin_controller_data(const COLLADAFW::SkinControllerData *data)
bool write_controller(const COLLADAFW::Controller *controller)
void set_tags_map(TagsMap &tags_map)
void add_root_joint(COLLADAFW::Node *node, Object *parent)
void write_profile_COMMON(COLLADAFW::EffectCommon *, Material *)
std::vector< Object * > * write_node(COLLADAFW::Node *, COLLADAFW::Node *, Scene *, Object *, bool)
std::string get_import_version(const COLLADAFW::FileInfo *asset)
bool addExtraTags(const COLLADAFW::UniqueId &uid, ExtraTags *extra_tags)
Object * create_light_object(COLLADAFW::InstanceLight *, Scene *)
bool writeGeometry(const COLLADAFW::Geometry *)
bool writeKinematicsScene(const COLLADAFW::KinematicsScene *)
void cancel(const COLLADAFW::String &errorMessage)
bool writeEffect(const COLLADAFW::Effect *)
bool writeLibraryNodes(const COLLADAFW::LibraryNodes *)
bool writeFormulas(const COLLADAFW::Formulas *)
void translate_anim_recursive(COLLADAFW::Node *, COLLADAFW::Node *, Object *)
bool writeVisualScene(const COLLADAFW::VisualScene *)
bool writeScene(const COLLADAFW::Scene *)
Object * create_instance_node(Object *, COLLADAFW::Node *, COLLADAFW::Node *, Scene *, bool)
bool writeAnimationList(const COLLADAFW::AnimationList *)
bool writeAnimation(const COLLADAFW::Animation *)
bool writeController(const COLLADAFW::Controller *)
void create_constraints(ExtraTags *et, Object *ob)
DocumentImporter(bContext *C, const ImportSettings *import_settings)
bool writeImage(const COLLADAFW::Image *)
bool writeSkinControllerData(const COLLADAFW::SkinControllerData *)
bool writeCamera(const COLLADAFW::Camera *)
ExtraTags * getExtraTags(const COLLADAFW::UniqueId &uid)
bool writeLight(const COLLADAFW::Light *)
bool writeMaterial(const COLLADAFW::Material *)
Object * create_camera_object(COLLADAFW::InstanceCamera *, Scene *)
bool writeGlobalAsset(const COLLADAFW::FileInfo *)
bool is_armature(COLLADAFW::Node *node)
Handler class for parser errors.
Definition: ErrorHandler.h:18
bool hasError()
Definition: ErrorHandler.h:26
Handler class for <extra> data, through which different profiles can be handled.
Definition: ExtraHandler.h:24
Class for saving <extra> tags for a specific UniqueId.
Definition: ExtraTags.h:15
bool isProfile(std::string profile)
Definition: ExtraTags.cpp:23
bool setData(std::string tag, short *data)
Definition: ExtraTags.cpp:65
void set_reflectivity(COLLADAFW::FloatOrParam &val)
Definition: Materials.cpp:136
void set_shininess(COLLADAFW::FloatOrParam &val)
void set_specular(COLLADAFW::ColorOrTexture &cot)
Definition: Materials.cpp:374
void update_material_nodetree()
Definition: Materials.cpp:95
void set_ior(COLLADAFW::FloatOrParam &val)
Definition: Materials.cpp:158
void set_reflective(COLLADAFW::ColorOrTexture &cot)
Definition: Materials.cpp:306
void set_emission(COLLADAFW::ColorOrTexture &cot)
Definition: Materials.cpp:322
void set_alpha(COLLADAFW::EffectCommon::OpaqueMode mode, COLLADAFW::ColorOrTexture &cot, COLLADAFW::FloatOrParam &val)
Definition: Materials.cpp:172
void set_diffuse(COLLADAFW::ColorOrTexture &cot)
Definition: Materials.cpp:218
void set_ambient(COLLADAFW::ColorOrTexture &cot)
Definition: Materials.cpp:290
void optimize_material_assignements()
bool write_geometry(const COLLADAFW::Geometry *geom)
Object * create_mesh_object(COLLADAFW::Node *node, COLLADAFW::InstanceGeometry *geom, bool isController, std::map< COLLADAFW::UniqueId, Material * > &uid_material_map)
void read_asset(const COLLADAFW::FileInfo *asset)
void calculate_scale(Scene &sce)
UnitConverter::UnitSystem isMetricSystem(void)
float getLinearMeter(void)
bool bc_set_parent(Object *ob, Object *par, bContext *C, bool is_parent_space)
void bc_match_scale(Object *ob, UnitConverter &bc_unit, bool scale_to_scene)
std::string bc_url_encode(std::string data)
Object * bc_add_object(Main *bmain, Scene *scene, ViewLayer *view_layer, int type, const char *name)
#define tanf(x)
Definition: cuda/compat.h:104
OperationNode * node
Scene scene
Light lamp
depth_tx normal_tx diffuse_light_tx specular_light_tx volume_light_tx environment_tx ambient_occlusion_tx aov_value_tx in_weight_img image(1, GPU_R32F, Qualifier::WRITE, ImageType::FLOAT_2D_ARRAY, "out_weight_img") .image(3
uint col
int count
CameraType
Definition: kernel/types.h:466
static char ** types
Definition: makesdna.c:67
#define atanf(x)
Definition: metal/compat.h:223
PointerRNA RNA_pointer_get(PointerRNA *ptr, const char *name)
Definition: rna_access.c:5167
void RNA_id_pointer_create(ID *id, PointerRNA *r_ptr)
Definition: rna_access.c:112
void RNA_property_enum_set(PointerRNA *ptr, PropertyRNA *prop, int value)
Definition: rna_access.c:3421
PropertyRNA * RNA_struct_find_property(PointerRNA *ptr, const char *identifier)
Definition: rna_access.c:717
void RNA_property_float_set(PointerRNA *ptr, PropertyRNA *prop, float value)
Definition: rna_access.c:2790
float clip_end
float lens
float shiftx
float sensor_x
float clip_start
float shifty
struct CameraDOFSettings dof
float ortho_scale
float att2
float r
float energy
short bufsize
float dist
float clipend
float att1
float area_sizez
float soft
float area_sizey
float shdwg
short area_shape
float clipsta
float spotblend
float g
short falloff_type
float spotsize
float area_size
float k
float shdwr
float b
float shdwb
short type
float bias
short buffers
short flag
Definition: BKE_main.h:121
short partype
float obmat[4][4]
struct Object * parent
void * data
char parsubstr[64]
Definition: IMB_anim.h:71
void WM_event_add_notifier(const bContext *C, uint type, void *reference)