Collada exporter update
authorGaia Clary <gaia.clary@machinimatrix.org>
Thu, 23 May 2019 10:17:17 +0000 (12:17 +0200)
committerGaia Clary <gaia.clary@machinimatrix.org>
Thu, 23 May 2019 10:29:20 +0000 (12:29 +0200)
Added new feature: Collada: global axis rotation upon export (UI)

The new feature allows to specify the target rest coordinate system upon export.
This allows for example to export a character that is in Blender orientation (Y forward)
to match the Secondlife orientation where (-X forward)

- Refactor:Added new utility methods to collada_utils
           Made BCMatrix class more powerfull
           moved Blender related structures into new BlenderContext class
           added class wrapper to encapsulate ExportSettings structure
           Added blender context getters to ExportSettings
           added access methods to BlenderContext into ExportSettings class
           Moved class BCMatrix into BlenderContext
           moved utility functions from collada_util into BlenderContext
           replace own function for parenting by a call to ED_object_parent_set()

- Cleanup: removed obsolete parameters from methods
           renamed parameters for better understanding
           cleanup whitespace and indentation
           removed obsolete comments

36 files changed:
source/blender/collada/AnimationClipExporter.h
source/blender/collada/AnimationExporter.cpp
source/blender/collada/AnimationExporter.h
source/blender/collada/ArmatureExporter.cpp
source/blender/collada/ArmatureExporter.h
source/blender/collada/BCAnimationSampler.cpp
source/blender/collada/BCAnimationSampler.h
source/blender/collada/BCSampleData.cpp
source/blender/collada/BCSampleData.h
source/blender/collada/BlenderContext.cpp
source/blender/collada/BlenderContext.h
source/blender/collada/CameraExporter.cpp
source/blender/collada/CameraExporter.h
source/blender/collada/ControllerExporter.cpp
source/blender/collada/ControllerExporter.h
source/blender/collada/DocumentExporter.cpp
source/blender/collada/DocumentExporter.h
source/blender/collada/DocumentImporter.cpp
source/blender/collada/EffectExporter.cpp
source/blender/collada/EffectExporter.h
source/blender/collada/ExportSettings.h
source/blender/collada/GeometryExporter.cpp
source/blender/collada/GeometryExporter.h
source/blender/collada/ImageExporter.cpp
source/blender/collada/ImageExporter.h
source/blender/collada/LightExporter.cpp
source/blender/collada/LightExporter.h
source/blender/collada/MaterialExporter.cpp
source/blender/collada/MaterialExporter.h
source/blender/collada/SceneExporter.cpp
source/blender/collada/SceneExporter.h
source/blender/collada/TransformWriter.cpp
source/blender/collada/TransformWriter.h
source/blender/collada/collada_utils.cpp
source/blender/collada/collada_utils.h
source/blender/editors/io/io_collada.c

index 6d67ab7c406a669d0cab056b246f0abf041653c4..ead894dc9410757387b6dc38527e6bbe07e7ccd6 100644 (file)
@@ -25,13 +25,13 @@ class AnimationClipExporter : COLLADASW::LibraryAnimationClips {
   Depsgraph *depsgraph;
   Scene *scene;
   COLLADASW::StreamWriter *sw;
   Depsgraph *depsgraph;
   Scene *scene;
   COLLADASW::StreamWriter *sw;
-  const ExportSettings *export_settings;
+  BCExportSettings &export_settings;
   std::vector<std::vector<std::string>> anim_meta;
 
  public:
   AnimationClipExporter(Depsgraph *depsgraph,
                         COLLADASW::StreamWriter *sw,
   std::vector<std::vector<std::string>> anim_meta;
 
  public:
   AnimationClipExporter(Depsgraph *depsgraph,
                         COLLADASW::StreamWriter *sw,
-                        const ExportSettings *export_settings,
+                        BCExportSettings &export_settings,
                         std::vector<std::vector<std::string>> anim_meta)
       : COLLADASW::LibraryAnimationClips(sw),
         depsgraph(depsgraph),
                         std::vector<std::vector<std::string>> anim_meta)
       : COLLADASW::LibraryAnimationClips(sw),
         depsgraph(depsgraph),
index eaa1626f7d80e4152a3e4eb38b0138f1699d411a..edd74886541e4b394bef39e4a5d2e2bad0b42597 100644 (file)
@@ -77,9 +77,9 @@ void AnimationExporter::close_animation_container(bool has_container)
 
 bool AnimationExporter::exportAnimations()
 {
 
 bool AnimationExporter::exportAnimations()
 {
-  Scene *sce = blender_context.get_scene();
+  Scene *sce = export_settings.get_scene();
 
 
-  LinkNode *export_set = this->export_settings->export_set;
+  LinkNode *export_set = this->export_settings.get_export_set();
   bool has_anim_data = bc_has_animations(sce, export_set);
   int animation_count = 0;
   if (has_anim_data) {
   bool has_anim_data = bc_has_animations(sce, export_set);
   int animation_count = 0;
   if (has_anim_data) {
@@ -87,14 +87,10 @@ bool AnimationExporter::exportAnimations()
     BCObjectSet animated_subset;
     BCAnimationSampler::get_animated_from_export_set(animated_subset, *export_set);
     animation_count = animated_subset.size();
     BCObjectSet animated_subset;
     BCAnimationSampler::get_animated_from_export_set(animated_subset, *export_set);
     animation_count = animated_subset.size();
-    BCAnimationSampler animation_sampler(blender_context, animated_subset);
+    BCAnimationSampler animation_sampler(export_settings, animated_subset);
 
     try {
 
     try {
-      animation_sampler.sample_scene(export_settings->sampling_rate,
-                                     /*keyframe_at_end = */ true,
-                                     export_settings->open_sim,
-                                     export_settings->keep_keyframes,
-                                     export_settings->export_animation_type);
+      animation_sampler.sample_scene(export_settings, /*keyframe_at_end = */ true);
 
       openLibrary();
 
 
       openLibrary();
 
@@ -137,7 +133,7 @@ void AnimationExporter::exportAnimation(Object *ob, BCAnimationSampler &sampler)
    * Note: For Armatures the skeletal animation has already been exported (see above)
    * However Armatures also can have Object animation.
    */
    * Note: For Armatures the skeletal animation has already been exported (see above)
    * However Armatures also can have Object animation.
    */
-  bool export_as_matrix = this->export_settings->export_transformation_type ==
+  bool export_as_matrix = this->export_settings.get_export_transformation_type() ==
                           BC_TRANSFORMATION_TYPE_MATRIX;
 
   if (export_as_matrix) {
                           BC_TRANSFORMATION_TYPE_MATRIX;
 
   if (export_as_matrix) {
@@ -178,7 +174,7 @@ void AnimationExporter::export_curve_animation_set(Object *ob,
                                                    bool export_as_matrix)
 {
   BCAnimationCurveMap *curves = sampler.get_curves(ob);
                                                    bool export_as_matrix)
 {
   BCAnimationCurveMap *curves = sampler.get_curves(ob);
-  bool keep_flat_curves = this->export_settings->keep_flat_curves;
+  bool keep_flat_curves = this->export_settings.get_keep_flat_curves();
 
   BCAnimationCurveMap::iterator it;
   for (it = curves->begin(); it != curves->end(); ++it) {
 
   BCAnimationCurveMap::iterator it;
   for (it = curves->begin(); it != curves->end(); ++it) {
@@ -215,7 +211,7 @@ void AnimationExporter::export_curve_animation_set(Object *ob,
 
 void AnimationExporter::export_matrix_animation(Object *ob, BCAnimationSampler &sampler)
 {
 
 void AnimationExporter::export_matrix_animation(Object *ob, BCAnimationSampler &sampler)
 {
-  bool keep_flat_curves = this->export_settings->keep_flat_curves;
+  bool keep_flat_curves = this->export_settings.get_keep_flat_curves();
 
   std::vector<float> frames;
   sampler.get_object_frames(frames, ob);
 
   std::vector<float> frames;
   sampler.get_object_frames(frames, ob);
@@ -232,17 +228,31 @@ void AnimationExporter::export_matrix_animation(Object *ob, BCAnimationSampler &
 
       std::string target = translate_id(name) + '/' + channel_type;
 
 
       std::string target = translate_id(name) + '/' + channel_type;
 
-      export_collada_matrix_animation(id, name, target, frames, samples);
+      BC_global_rotation_type global_rotation_type = get_global_rotation_type(ob);
+      export_collada_matrix_animation(
+          id, name, target, frames, samples, global_rotation_type, ob->parentinv);
     }
   }
 }
 
     }
   }
 }
 
+BC_global_rotation_type AnimationExporter::get_global_rotation_type(Object *ob)
+{
+  bool is_export_root = this->export_settings.is_export_root(ob);
+  if (!is_export_root) {
+    return BC_NO_ROTATION;
+  }
+
+  bool apply_global_rotation = this->export_settings.get_apply_global_orientation();
+
+  return (apply_global_rotation) ? BC_DATA_ROTATION : BC_OBJECT_ROTATION;
+}
+
 /* Write bone animations in transform matrix sources. */
 void AnimationExporter::export_bone_animations_recursive(Object *ob,
                                                          Bone *bone,
                                                          BCAnimationSampler &sampler)
 {
 /* Write bone animations in transform matrix sources. */
 void AnimationExporter::export_bone_animations_recursive(Object *ob,
                                                          Bone *bone,
                                                          BCAnimationSampler &sampler)
 {
-  bool keep_flat_curves = this->export_settings->keep_flat_curves;
+  bool keep_flat_curves = this->export_settings.get_keep_flat_curves();
 
   std::vector<float> frames;
   sampler.get_bone_frames(frames, ob, bone);
 
   std::vector<float> frames;
   sampler.get_bone_frames(frames, ob, bone);
@@ -347,7 +357,9 @@ void AnimationExporter::export_curve_animation(Object *ob, BCAnimationCurve &cur
     collada_target += "/" + get_collada_sid(curve, axis);
   }
 
     collada_target += "/" + get_collada_sid(curve, axis);
   }
 
-  export_collada_curve_animation(id, curve_name, collada_target, axis, curve);
+  BC_global_rotation_type global_rotation_type = get_global_rotation_type(ob);
+  export_collada_curve_animation(
+      id, curve_name, collada_target, axis, curve, global_rotation_type);
 }
 
 void AnimationExporter::export_bone_animation(Object *ob,
 }
 
 void AnimationExporter::export_bone_animation(Object *ob,
@@ -361,7 +373,9 @@ void AnimationExporter::export_bone_animation(Object *ob,
   std::string id = bc_get_action_id(id_name(action), name, bone_name, "pose_matrix");
   std::string target = translate_id(id_name(ob) + "_" + bone_name) + "/transform";
 
   std::string id = bc_get_action_id(id_name(action), name, bone_name, "pose_matrix");
   std::string target = translate_id(id_name(ob) + "_" + bone_name) + "/transform";
 
-  export_collada_matrix_animation(id, name, target, frames, samples);
+  BC_global_rotation_type global_rotation_type = get_global_rotation_type(ob);
+  export_collada_matrix_animation(
+      id, name, target, frames, samples, global_rotation_type, ob->parentinv);
 }
 
 bool AnimationExporter::is_bone_deform_group(Bone *bone)
 }
 
 bool AnimationExporter::is_bone_deform_group(Bone *bone)
@@ -383,11 +397,13 @@ bool AnimationExporter::is_bone_deform_group(Bone *bone)
   return false;
 }
 
   return false;
 }
 
-void AnimationExporter::export_collada_curve_animation(std::string id,
-                                                       std::string name,
-                                                       std::string collada_target,
-                                                       std::string axis,
-                                                       BCAnimationCurve &curve)
+void AnimationExporter::export_collada_curve_animation(
+    std::string id,
+    std::string name,
+    std::string collada_target,
+    std::string axis,
+    BCAnimationCurve &curve,
+    BC_global_rotation_type global_rotation_type)
 {
   BCFrames frames;
   BCValues values;
 {
   BCFrames frames;
   BCValues values;
@@ -408,7 +424,7 @@ void AnimationExporter::export_collada_curve_animation(std::string id,
 
   bool has_tangents = false;
   std::string interpolation_id;
 
   bool has_tangents = false;
   std::string interpolation_id;
-  if (this->export_settings->keep_smooth_curves)
+  if (this->export_settings.get_keep_smooth_curves())
     interpolation_id = collada_interpolation_source(curve, id, axis, &has_tangents);
   else
     interpolation_id = collada_linear_interpolation_source(frames.size(), id);
     interpolation_id = collada_interpolation_source(curve, id, axis, &has_tangents);
   else
     interpolation_id = collada_linear_interpolation_source(frames.size(), id);
@@ -444,11 +460,14 @@ void AnimationExporter::export_collada_curve_animation(std::string id,
   closeAnimation();
 }
 
   closeAnimation();
 }
 
-void AnimationExporter::export_collada_matrix_animation(std::string id,
-                                                        std::string name,
-                                                        std::string target,
-                                                        BCFrames &frames,
-                                                        BCMatrixSampleMap &samples)
+void AnimationExporter::export_collada_matrix_animation(
+    std::string id,
+    std::string name,
+    std::string target,
+    BCFrames &frames,
+    BCMatrixSampleMap &samples,
+    BC_global_rotation_type global_rotation_type,
+    Matrix &parentinv)
 {
   fprintf(
       stdout, "Export animation matrix %s (%d control points)\n", id.c_str(), int(frames.size()));
 {
   fprintf(
       stdout, "Export animation matrix %s (%d control points)\n", id.c_str(), int(frames.size()));
@@ -457,7 +476,7 @@ void AnimationExporter::export_collada_matrix_animation(std::string id,
 
   std::string input_id = collada_source_from_values(
       BC_SOURCE_TYPE_TIMEFRAME, COLLADASW::InputSemantic::INPUT, frames, id, "");
 
   std::string input_id = collada_source_from_values(
       BC_SOURCE_TYPE_TIMEFRAME, COLLADASW::InputSemantic::INPUT, frames, id, "");
-  std::string output_id = collada_source_from_values(samples, id);
+  std::string output_id = collada_source_from_values(samples, id, global_rotation_type, parentinv);
   std::string interpolation_id = collada_linear_interpolation_source(frames.size(), id);
 
   std::string sampler_id = std::string(id) + SAMPLER_ID_SUFFIX;
   std::string interpolation_id = collada_linear_interpolation_source(frames.size(), id);
 
   std::string sampler_id = std::string(id) + SAMPLER_ID_SUFFIX;
@@ -540,7 +559,8 @@ std::string AnimationExporter::collada_tangent_from_curve(
     const std::string &anim_id,
     std::string axis_name)
 {
     const std::string &anim_id,
     std::string axis_name)
 {
-  Scene *scene = blender_context.get_scene();
+  Scene *scene = this->export_settings.get_scene();
+
   std::string channel = curve.get_channel_target();
 
   const std::string source_id = anim_id + get_semantic_suffix(semantic);
   std::string channel = curve.get_channel_target();
 
   const std::string source_id = anim_id + get_semantic_suffix(semantic);
@@ -585,6 +605,7 @@ std::string AnimationExporter::collada_source_from_values(
     const std::string &anim_id,
     const std::string axis_name)
 {
     const std::string &anim_id,
     const std::string axis_name)
 {
+  BlenderContext &blender_context = this->export_settings.get_blender_context();
   Scene *scene = blender_context.get_scene();
   /* T can be float, int or double */
 
   Scene *scene = blender_context.get_scene();
   /* T can be float, int or double */
 
@@ -623,11 +644,14 @@ std::string AnimationExporter::collada_source_from_values(
   return source_id;
 }
 
   return source_id;
 }
 
-/**
- * Create a collada matrix source for a set of samples.
+/*
+ * Create a collada matrix source for a set of samples
  */
  */
-std::string AnimationExporter::collada_source_from_values(BCMatrixSampleMap &samples,
-                                                          const std::string &anim_id)
+std::string AnimationExporter::collada_source_from_values(
+    BCMatrixSampleMap &samples,
+    const std::string &anim_id,
+    BC_global_rotation_type global_rotation_type,
+    Matrix &parentinv)
 {
   COLLADASW::InputSemantic::Semantics semantic = COLLADASW::InputSemantic::OUTPUT;
   std::string source_id = anim_id + get_semantic_suffix(semantic);
 {
   COLLADASW::InputSemantic::Semantics semantic = COLLADASW::InputSemantic::OUTPUT;
   std::string source_id = anim_id + get_semantic_suffix(semantic);
@@ -645,11 +669,18 @@ std::string AnimationExporter::collada_source_from_values(BCMatrixSampleMap &sam
 
   BCMatrixSampleMap::iterator it;
   /* could be made configurable */
 
   BCMatrixSampleMap::iterator it;
   /* could be made configurable */
-  int precision = (this->export_settings->limit_precision) ? 6 : -1;
+  int precision = (this->export_settings.get_limit_precision()) ? 6 : -1;
   for (it = samples.begin(); it != samples.end(); it++) {
   for (it = samples.begin(); it != samples.end(); it++) {
-    const BCMatrix *sample = it->second;
-    double daemat[4][4];
-    sample->get_matrix(daemat, true, precision);
+    BCMatrix sample = BCMatrix(*it->second);
+    BCMatrix global_transform = this->export_settings.get_global_transform();
+    DMatrix daemat;
+    if (this->export_settings.get_apply_global_orientation()) {
+      sample.apply_transform(global_transform);
+    }
+    else {
+      sample.add_transform(global_transform);
+    }
+    sample.get_matrix(daemat, true, precision);
     source.appendValues(daemat);
   }
 
     source.appendValues(daemat);
   }
 
index 71d7d14a1123161debedc211fcea11f4d9e72488..27474cc2b5871dd9dccbcf809b08f2f42dac5412 100644 (file)
@@ -86,20 +86,22 @@ typedef enum BC_animation_source_type {
   BC_SOURCE_TYPE_TIMEFRAME,
 } BC_animation_source_type;
 
   BC_SOURCE_TYPE_TIMEFRAME,
 } BC_animation_source_type;
 
+typedef enum BC_global_rotation_type {
+  BC_NO_ROTATION,
+  BC_OBJECT_ROTATION,
+  BC_DATA_ROTATION
+} BC_global_rotation_type;
+
 class AnimationExporter : COLLADASW::LibraryAnimations {
  private:
 class AnimationExporter : COLLADASW::LibraryAnimations {
  private:
-  BlenderContext &blender_context;
   COLLADASW::StreamWriter *sw;
   COLLADASW::StreamWriter *sw;
-  const ExportSettings *export_settings;
+  BCExportSettings &export_settings;
+
+  BC_global_rotation_type get_global_rotation_type(Object *ob);
 
  public:
 
  public:
-  AnimationExporter(BlenderContext &blender_context,
-                    COLLADASW::StreamWriter *sw,
-                    const ExportSettings *export_settings)
-      : COLLADASW::LibraryAnimations(sw),
-        blender_context(blender_context),
-        sw(sw),
-        export_settings(export_settings)
+  AnimationExporter(COLLADASW::StreamWriter *sw, BCExportSettings &export_settings)
+      : COLLADASW::LibraryAnimations(sw), sw(sw), export_settings(export_settings)
   {
   }
 
   {
   }
 
@@ -176,14 +178,17 @@ class AnimationExporter : COLLADASW::LibraryAnimations {
                                       std::string name,
                                       std::string target,
                                       std::string axis,
                                       std::string name,
                                       std::string target,
                                       std::string axis,
-                                      BCAnimationCurve &curve);
+                                      BCAnimationCurve &curve,
+                                      BC_global_rotation_type global_rotation_type);
 
   /* call to the low level collada exporter */
   void export_collada_matrix_animation(std::string id,
                                        std::string name,
                                        std::string target,
                                        BCFrames &frames,
 
   /* call to the low level collada exporter */
   void export_collada_matrix_animation(std::string id,
                                        std::string name,
                                        std::string target,
                                        BCFrames &frames,
-                                       BCMatrixSampleMap &outmats);
+                                       BCMatrixSampleMap &outmats,
+                                       BC_global_rotation_type global_rotation_type,
+                                       Matrix &parentinv);
 
   BCAnimationCurve *get_modified_export_curve(Object *ob,
                                               BCAnimationCurve &curve,
 
   BCAnimationCurve *get_modified_export_curve(Object *ob,
                                               BCAnimationCurve &curve,
@@ -202,7 +207,10 @@ class AnimationExporter : COLLADASW::LibraryAnimations {
                                          const std::string axis_name);
 
   /* Output sources (matrix data) */
                                          const std::string axis_name);
 
   /* Output sources (matrix data) */
-  std::string collada_source_from_values(BCMatrixSampleMap &samples, const std::string &anim_id);
+  std::string collada_source_from_values(BCMatrixSampleMap &samples,
+                                         const std::string &anim_id,
+                                         BC_global_rotation_type global_rotation_type,
+                                         Matrix &parentinv);
 
   /* Interpolation sources */
   std::string collada_linear_interpolation_source(int tot, const std::string &anim_id);
 
   /* Interpolation sources */
   std::string collada_linear_interpolation_source(int tot, const std::string &anim_id);
index be50b255f1358a09278c5510cb0f7af3c56b421c..6dfe69158923635789b6f4b9f7a6c3137b0642ad 100644 (file)
@@ -43,8 +43,6 @@ extern "C" {
 #include "ArmatureExporter.h"
 #include "SceneExporter.h"
 
 #include "ArmatureExporter.h"
 #include "SceneExporter.h"
 
-#include "collada_utils.h"
-
 // write bone nodes
 void ArmatureExporter::add_armature_bones(Object *ob_arm,
                                           ViewLayer *view_layer,
 // write bone nodes
 void ArmatureExporter::add_armature_bones(Object *ob_arm,
                                           ViewLayer *view_layer,
@@ -62,10 +60,7 @@ void ArmatureExporter::add_armature_bones(Object *ob_arm,
   }
 
   for (Bone *bone = (Bone *)armature->bonebase.first; bone; bone = bone->next) {
   }
 
   for (Bone *bone = (Bone *)armature->bonebase.first; bone; bone = bone->next) {
-    // start from root bones
-    if (!bone->parent) {
-      add_bone_node(bone, ob_arm, se, child_objects);
-    }
+    add_bone_node(bone, ob_arm, se, child_objects);
   }
 
   if (!is_edited) {
   }
 
   if (!is_edited) {
@@ -77,7 +72,7 @@ void ArmatureExporter::write_bone_URLs(COLLADASW::InstanceController &ins,
                                        Object *ob_arm,
                                        Bone *bone)
 {
                                        Object *ob_arm,
                                        Bone *bone)
 {
-  if (bc_is_root_bone(bone, this->export_settings->deform_bones_only)) {
+  if (bc_is_root_bone(bone, this->export_settings.get_deform_bones_only())) {
     std::string joint_id = translate_id(id_name(ob_arm) + "_" + bone->name);
     ins.addSkeleton(COLLADABU::URI(COLLADABU::Utils::EMPTY_STRING, joint_id));
   }
     std::string joint_id = translate_id(id_name(ob_arm) + "_" + bone->name);
     ins.addSkeleton(COLLADABU::URI(COLLADABU::Utils::EMPTY_STRING, joint_id));
   }
@@ -109,7 +104,7 @@ bool ArmatureExporter::add_instance_controller(Object *ob)
   }
 
   InstanceWriter::add_material_bindings(
   }
 
   InstanceWriter::add_material_bindings(
-      ins.getBindMaterial(), ob, this->export_settings->active_uv_only);
+      ins.getBindMaterial(), ob, this->export_settings.get_active_uv_only());
 
   ins.add();
   return true;
 
   ins.add();
   return true;
@@ -157,7 +152,7 @@ void ArmatureExporter::add_bone_node(Bone *bone,
                                      SceneExporter *se,
                                      std::vector<Object *> &child_objects)
 {
                                      SceneExporter *se,
                                      std::vector<Object *> &child_objects)
 {
-  if (!(this->export_settings->deform_bones_only && bone->flag & BONE_NO_DEFORM)) {
+  if (can_export(bone)) {
     std::string node_id = translate_id(id_name(ob_arm) + "_" + bone->name);
     std::string node_name = std::string(bone->name);
     std::string node_sid = get_joint_sid(bone);
     std::string node_id = translate_id(id_name(ob_arm) + "_" + bone->name);
     std::string node_name = std::string(bone->name);
     std::string node_sid = get_joint_sid(bone);
@@ -169,8 +164,8 @@ void ArmatureExporter::add_bone_node(Bone *bone,
     node.setNodeName(node_name);
     node.setNodeSid(node_sid);
 
     node.setNodeName(node_name);
     node.setNodeSid(node_sid);
 
-    if (this->export_settings->use_blender_profile) {
-      if (bone->parent) {
+    if (this->export_settings.get_use_blender_profile()) {
+      if (!is_export_root(bone)) {
         if (bone->flag & BONE_CONNECTED) {
           node.addExtraTechniqueParameter("blender", "connect", true);
         }
         if (bone->flag & BONE_CONNECTED) {
           node.addExtraTechniqueParameter("blender", "connect", true);
         }
@@ -184,9 +179,19 @@ void ArmatureExporter::add_bone_node(Bone *bone,
         node.addExtraTechniqueParameter("blender", "roll", ebone->roll);
       }
       if (bc_is_leaf_bone(bone)) {
         node.addExtraTechniqueParameter("blender", "roll", ebone->roll);
       }
       if (bc_is_leaf_bone(bone)) {
-        node.addExtraTechniqueParameter("blender", "tip_x", bone->arm_tail[0] - bone->arm_head[0]);
-        node.addExtraTechniqueParameter("blender", "tip_y", bone->arm_tail[1] - bone->arm_head[1]);
-        node.addExtraTechniqueParameter("blender", "tip_z", bone->arm_tail[2] - bone->arm_head[2]);
+        Vector head, tail;
+        const BCMatrix &global_transform = this->export_settings.get_global_transform();
+        if (this->export_settings.get_apply_global_orientation()) {
+          bc_add_global_transform(head, bone->arm_head, global_transform);
+          bc_add_global_transform(tail, bone->arm_tail, global_transform);
+        }
+        else {
+          copy_v3_v3(head, bone->arm_head);
+          copy_v3_v3(tail, bone->arm_tail);
+        }
+        node.addExtraTechniqueParameter("blender", "tip_x", tail[0] - head[0]);
+        node.addExtraTechniqueParameter("blender", "tip_y", tail[1] - head[1]);
+        node.addExtraTechniqueParameter("blender", "tip_z", tail[2] - head[2]);
       }
     }
 
       }
     }
 
@@ -195,12 +200,13 @@ void ArmatureExporter::add_bone_node(Bone *bone,
     add_bone_transform(ob_arm, bone, node);
 
     // Write nodes of childobjects, remove written objects from list
     add_bone_transform(ob_arm, bone, node);
 
     // Write nodes of childobjects, remove written objects from list
-    std::vector<Object *>::iterator i = child_objects.begin();
+    std::vector<Object *>::iterator iter = child_objects.begin();
 
 
-    while (i != child_objects.end()) {
-      if ((*i)->partype == PARBONE && STREQ((*i)->parsubstr, bone->name)) {
+    while (iter != child_objects.end()) {
+      Object *ob = *iter;
+      if (ob->partype == PARBONE && STREQ(ob->parsubstr, bone->name)) {
         float backup_parinv[4][4];
         float backup_parinv[4][4];
-        copy_m4_m4(backup_parinv, (*i)->parentinv);
+        copy_m4_m4(backup_parinv, ob->parentinv);
 
         // crude, temporary change to parentinv
         // so transform gets exported correctly.
 
         // crude, temporary change to parentinv
         // so transform gets exported correctly.
@@ -208,28 +214,28 @@ void ArmatureExporter::add_bone_node(Bone *bone,
         // Add bone tail- translation... don't know why
         // bone parenting is against the tail of a bone
         // and not it's head, seems arbitrary.
         // Add bone tail- translation... don't know why
         // bone parenting is against the tail of a bone
         // and not it's head, seems arbitrary.
-        (*i)->parentinv[3][1] += bone->length;
+        ob->parentinv[3][1] += bone->length;
 
         // OPEN_SIM_COMPATIBILITY
         // TODO: when such objects are animated as
         // single matrix the tweak must be applied
         // to the result.
 
         // OPEN_SIM_COMPATIBILITY
         // TODO: when such objects are animated as
         // single matrix the tweak must be applied
         // to the result.
-        if (export_settings->open_sim) {
+        if (export_settings.get_open_sim()) {
           // tweak objects parentinverse to match compatibility
           float temp[4][4];
 
           copy_m4_m4(temp, bone->arm_mat);
           temp[3][0] = temp[3][1] = temp[3][2] = 0.0f;
 
           // tweak objects parentinverse to match compatibility
           float temp[4][4];
 
           copy_m4_m4(temp, bone->arm_mat);
           temp[3][0] = temp[3][1] = temp[3][2] = 0.0f;
 
-          mul_m4_m4m4((*i)->parentinv, temp, (*i)->parentinv);
+          mul_m4_m4m4(ob->parentinv, temp, ob->parentinv);
         }
 
         }
 
-        se->writeNodes(*i);
-        copy_m4_m4((*i)->parentinv, backup_parinv);
-        i = child_objects.erase(i);
+        se->writeNode(ob);
+        copy_m4_m4(ob->parentinv, backup_parinv);
+        iter = child_objects.erase(iter);
       }
       else
       }
       else
-        i++;
+        iter++;
     }
 
     for (Bone *child = (Bone *)bone->childbase.first; child; child = child->next) {
     }
 
     for (Bone *child = (Bone *)bone->childbase.first; child; child = child->next) {
@@ -244,6 +250,18 @@ void ArmatureExporter::add_bone_node(Bone *bone,
   }
 }
 
   }
 }
 
+bool ArmatureExporter::is_export_root(Bone *bone)
+{
+  Bone *entry = bone->parent;
+  while (entry) {
+    if (can_export(entry)) {
+      return false;
+    }
+    entry = entry->parent;
+  }
+  return can_export(bone);
+}
+
 void ArmatureExporter::add_bone_transform(Object *ob_arm, Bone *bone, COLLADASW::Node &node)
 {
   // bPoseChannel *pchan = BKE_pose_channel_find_name(ob_arm->pose, bone->name);
 void ArmatureExporter::add_bone_transform(Object *ob_arm, Bone *bone, COLLADASW::Node &node)
 {
   // bPoseChannel *pchan = BKE_pose_channel_find_name(ob_arm->pose, bone->name);
@@ -260,49 +278,47 @@ void ArmatureExporter::add_bone_transform(Object *ob_arm, Bone *bone, COLLADASW:
 
     bc_create_restpose_mat(this->export_settings, bone, bone_rest_mat, bone->arm_mat, true);
 
 
     bc_create_restpose_mat(this->export_settings, bone, bone_rest_mat, bone->arm_mat, true);
 
-    if (bone->parent) {
-      /* Get bone-space matrix from parent pose. */
-#if 0
-      bPoseChannel *parchan = BKE_pose_channel_find_name(ob_arm->pose, bone->parent->name);
-      float invpar[4][4];
-      invert_m4_m4(invpar, parchan->pose_mat);
-      mul_m4_m4m4(mat, invpar, pchan->pose_mat);
-#endif
-      float invpar[4][4];
+    if (is_export_root(bone)) {
+      copy_m4_m4(mat, bone_rest_mat);
+    }
+    else {
+      Matrix parent_inverse;
       bc_create_restpose_mat(
           this->export_settings, bone->parent, parent_rest_mat, bone->parent->arm_mat, true);
 
       bc_create_restpose_mat(
           this->export_settings, bone->parent, parent_rest_mat, bone->parent->arm_mat, true);
 
-      invert_m4_m4(invpar, parent_rest_mat);
-      mul_m4_m4m4(mat, invpar, bone_rest_mat);
-    }
-    else {
-      copy_m4_m4(mat, bone_rest_mat);
+      invert_m4_m4(parent_inverse, parent_rest_mat);
+      mul_m4_m4m4(mat, parent_inverse, bone_rest_mat);
     }
 
     // OPEN_SIM_COMPATIBILITY
     }
 
     // OPEN_SIM_COMPATIBILITY
-    if (export_settings->open_sim) {
+    
+    if (export_settings.get_open_sim()) {
       // Remove rotations vs armature from transform
       // parent_rest_rot * mat * irest_rot
       // Remove rotations vs armature from transform
       // parent_rest_rot * mat * irest_rot
-      float temp[4][4];
-      copy_m4_m4(temp, bone_rest_mat);
-      temp[3][0] = temp[3][1] = temp[3][2] = 0.0f;
-      invert_m4(temp);
+      Matrix workmat;
+      copy_m4_m4(workmat, bone_rest_mat);
+
+      workmat[3][0] = workmat[3][1] = workmat[3][2] = 0.0f;
+      invert_m4(workmat);
 
 
-      mul_m4_m4m4(mat, mat, temp);
+      mul_m4_m4m4(mat, mat, workmat);
 
 
-      if (bone->parent) {
-        copy_m4_m4(temp, parent_rest_mat);
-        temp[3][0] = temp[3][1] = temp[3][2] = 0.0f;
+      if (!is_export_root(bone)) {
+        copy_m4_m4(workmat, parent_rest_mat);
+        workmat[3][0] = workmat[3][1] = workmat[3][2] = 0.0f;
+
+        mul_m4_m4m4(mat, workmat, mat);
 
 
-        mul_m4_m4m4(mat, temp, mat);
       }
     }
       }
     }
+    
   }
 
   }
 
-  if (this->export_settings->limit_precision)
+  if (this->export_settings.get_limit_precision()) {
     bc_sanitize_mat(mat, LIMITTED_PRECISION);
     bc_sanitize_mat(mat, LIMITTED_PRECISION);
+  }
 
 
-  TransformWriter::add_node_transform(node, mat, NULL);
+  TransformWriter::add_node_transform(node, mat, NULL, this->export_settings);
 }
 
 std::string ArmatureExporter::get_controller_id(Object *ob_arm, Object *ob)
 }
 
 std::string ArmatureExporter::get_controller_id(Object *ob_arm, Object *ob)
index 6ef6007960e808e8edcde9ce7dfea823f528f6a8..da6d6f79ef5a9fe1f98759a56e17a1681e9cbc93 100644 (file)
@@ -56,7 +56,7 @@ class ArmatureExporter : public COLLADASW::LibraryControllers,
   // we make controller ids then?
   ArmatureExporter(BlenderContext &blender_context,
                    COLLADASW::StreamWriter *sw,
   // we make controller ids then?
   ArmatureExporter(BlenderContext &blender_context,
                    COLLADASW::StreamWriter *sw,
-                   const ExportSettings *export_settings)
+                   BCExportSettings &export_settings)
       : COLLADASW::LibraryControllers(sw),
         blender_context(blender_context),
         export_settings(export_settings)
       : COLLADASW::LibraryControllers(sw),
         blender_context(blender_context),
         export_settings(export_settings)
@@ -72,7 +72,7 @@ class ArmatureExporter : public COLLADASW::LibraryControllers,
 
  private:
   BlenderContext &blender_context;
 
  private:
   BlenderContext &blender_context;
-  const ExportSettings *export_settings;
+  BCExportSettings &export_settings;
 
 #if 0
   std::vector<Object *> written_armatures;
 
 #if 0
   std::vector<Object *> written_armatures;
@@ -91,6 +91,12 @@ class ArmatureExporter : public COLLADASW::LibraryControllers,
                      SceneExporter *se,
                      std::vector<Object *> &child_objects);
 
                      SceneExporter *se,
                      std::vector<Object *> &child_objects);
 
+  inline bool can_export(Bone *bone)
+  {
+    return !(export_settings.get_deform_bones_only() && bone->flag & BONE_NO_DEFORM);
+  }
+
+  bool is_export_root(Bone *bone);
   void add_bone_transform(Object *ob_arm, Bone *bone, COLLADASW::Node &node);
 
   std::string get_controller_id(Object *ob_arm, Object *ob);
   void add_bone_transform(Object *ob_arm, Bone *bone, COLLADASW::Node &node);
 
   std::string get_controller_id(Object *ob_arm, Object *ob);
index ee574e2968ba35bbeef2085161bf101d1adbfe9f..7b0c6c41a013aa987ea28cf0eeee0e458f114fad 100644 (file)
@@ -44,8 +44,8 @@ extern "C" {
 static std::string EMPTY_STRING;
 static BCAnimationCurveMap BCEmptyAnimationCurves;
 
 static std::string EMPTY_STRING;
 static BCAnimationCurveMap BCEmptyAnimationCurves;
 
-BCAnimationSampler::BCAnimationSampler(BlenderContext &blender_context, BCObjectSet &object_set)
-    : blender_context(blender_context)
+BCAnimationSampler::BCAnimationSampler(BCExportSettings &export_settings, BCObjectSet &object_set)
+    : export_settings(export_settings)
 {
   BCObjectSet::iterator it;
   for (it = object_set.begin(); it != object_set.end(); ++it) {
 {
   BCObjectSet::iterator it;
   for (it = object_set.begin(); it != object_set.end(); ++it) {
@@ -65,6 +65,7 @@ BCAnimationSampler::~BCAnimationSampler()
 
 void BCAnimationSampler::add_object(Object *ob)
 {
 
 void BCAnimationSampler::add_object(Object *ob)
 {
+  BlenderContext blender_context = export_settings.get_blender_context();
   BCAnimation *animation = new BCAnimation(blender_context.get_context(), ob);
   objects[ob] = animation;
 
   BCAnimation *animation = new BCAnimation(blender_context.get_context(), ob);
   objects[ob] = animation;
 
@@ -156,6 +157,10 @@ void BCAnimationSampler::update_animation_curves(BCAnimation &animation,
 BCSample &BCAnimationSampler::sample_object(Object *ob, int frame_index, bool for_opensim)
 {
   BCSample &ob_sample = sample_data.add(ob, frame_index);
 BCSample &BCAnimationSampler::sample_object(Object *ob, int frame_index, bool for_opensim)
 {
   BCSample &ob_sample = sample_data.add(ob, frame_index);
+  //if (export_settings.get_apply_global_orientation()) {
+  //  const BCMatrix &global_transform = export_settings.get_global_transform();
+  //  ob_sample.get_matrix(global_transform);
+  //}
 
   if (ob->type == OB_ARMATURE) {
     bPoseChannel *pchan;
 
   if (ob->type == OB_ARMATURE) {
     bPoseChannel *pchan;
@@ -163,6 +168,7 @@ BCSample &BCAnimationSampler::sample_object(Object *ob, int frame_index, bool fo
       Bone *bone = pchan->bone;
       Matrix bmat;
       if (bc_bone_matrix_local_get(ob, bone, bmat, for_opensim)) {
       Bone *bone = pchan->bone;
       Matrix bmat;
       if (bc_bone_matrix_local_get(ob, bone, bmat, for_opensim)) {
+
         ob_sample.add_bone_matrix(bone, bmat);
       }
     }
         ob_sample.add_bone_matrix(bone, bmat);
       }
     }
@@ -170,12 +176,14 @@ BCSample &BCAnimationSampler::sample_object(Object *ob, int frame_index, bool fo
   return ob_sample;
 }
 
   return ob_sample;
 }
 
-void BCAnimationSampler::sample_scene(int sampling_rate,
-                                      int keyframe_at_end,
-                                      bool for_opensim,
-                                      bool keep_keyframes,
-                                      BC_export_animation_type export_animation_type)
+void BCAnimationSampler::sample_scene(BCExportSettings &export_settings, bool keyframe_at_end)
 {
 {
+  BlenderContext blender_context = export_settings.get_blender_context();
+  int sampling_rate = export_settings.get_sampling_rate();
+  bool for_opensim = export_settings.get_open_sim();
+  bool keep_keyframes = export_settings.get_keep_keyframes();
+  BC_export_animation_type export_animation_type = export_settings.get_export_animation_type();
+
   Scene *scene = blender_context.get_scene();
   BCFrameSet scene_sample_frames;
   get_sample_frames(scene_sample_frames, sampling_rate, keyframe_at_end, scene);
   Scene *scene = blender_context.get_scene();
   BCFrameSet scene_sample_frames;
   get_sample_frames(scene_sample_frames, sampling_rate, keyframe_at_end, scene);
index 9544c6be91691cbd5351c93c3675597061d796ce..e8d2ab56ae7aa02f8efbd16cc15d05690efcac92 100644 (file)
@@ -147,7 +147,7 @@ class BCSampleFrameContainer {
 
 class BCAnimationSampler {
  private:
 
 class BCAnimationSampler {
  private:
-  BlenderContext &blender_context;
+  BCExportSettings &export_settings;
   BCSampleFrameContainer sample_data;
   BCAnimationObjectMap objects;
 
   BCSampleFrameContainer sample_data;
   BCAnimationObjectMap objects;
 
@@ -169,16 +169,12 @@ class BCAnimationSampler {
       BCAnimation &animation, float *ref, float *val, std::string data_path, int length);
 
  public:
       BCAnimation &animation, float *ref, float *val, std::string data_path, int length);
 
  public:
-  BCAnimationSampler(BlenderContext &blender_context, BCObjectSet &animated_subset);
+  BCAnimationSampler(BCExportSettings &export_settings, BCObjectSet &animated_subset);
   ~BCAnimationSampler();
 
   void add_object(Object *ob);
 
   ~BCAnimationSampler();
 
   void add_object(Object *ob);
 
-  void sample_scene(int sampling_rate,
-                    int keyframe_at_end,
-                    bool for_opensim,
-                    bool keep_keyframes,
-                    BC_export_animation_type export_animation_type);
+  void sample_scene(BCExportSettings &export_settings, bool keyframe_at_end);
 
   BCAnimationCurveMap *get_curves(Object *ob);
   void get_object_frames(BCFrames &frames, Object *ob);
 
   BCAnimationCurveMap *get_curves(Object *ob);
   void get_object_frames(BCFrames &frames, Object *ob);
index 868526928b010d5cc8112252dacfeaff03aa5715..cf3668a08af63d08c7b035f39df24cc46b968d80 100644 (file)
 #include "BCSampleData.h"
 #include "collada_utils.h"
 
 #include "BCSampleData.h"
 #include "collada_utils.h"
 
-BCSample::BCSample(Object *ob) : obmat(ob)
-{
-}
-
 BCSample::~BCSample()
 {
   BCBoneMatrixMap::iterator it;
 BCSample::~BCSample()
 {
   BCBoneMatrixMap::iterator it;
@@ -43,6 +39,11 @@ void BCSample::add_bone_matrix(Bone *bone, Matrix &mat)
   bonemats[bone] = matrix;
 }
 
   bonemats[bone] = matrix;
 }
 
+BCMatrix::BCMatrix(const BCMatrix &mat)
+{
+  set_transform(mat.matrix);
+}
+
 BCMatrix::BCMatrix(Matrix &mat)
 {
   set_transform(mat);
 BCMatrix::BCMatrix(Matrix &mat)
 {
   set_transform(mat);
@@ -53,11 +54,68 @@ BCMatrix::BCMatrix(Object *ob)
   set_transform(ob);
 }
 
   set_transform(ob);
 }
 
-void BCMatrix::set_transform(Matrix &mat)
+BCMatrix::BCMatrix()
 {
 {
-  copy_m4_m4(matrix, mat);
-  mat4_decompose(this->loc, this->q, this->size, mat);
-  quat_to_eul(this->rot, this->q);
+  unit();
+}
+
+BCMatrix::BCMatrix(BC_global_forward_axis global_forward_axis, BC_global_up_axis global_up_axis)
+{
+  float mrot[3][3];
+  float mat[4][4];
+  mat3_from_axis_conversion(
+      BC_DEFAULT_FORWARD, BC_DEFAULT_UP, global_forward_axis, global_up_axis, mrot);
+
+  transpose_m3(mrot); // TODO: Verify that mat3_from_axis_conversion() returns a transposed matrix
+  copy_m4_m3(mat, mrot);
+  set_transform(mat);
+}
+
+void BCMatrix::add_transform(const Matrix &mat, bool inverse)
+{
+  add_transform(this->matrix, mat, this->matrix, inverse);
+}
+
+void BCMatrix::add_transform(const BCMatrix &mat, bool inverse)
+{
+  add_transform(this->matrix, mat.matrix, this->matrix, inverse);
+}
+
+void BCMatrix::apply_transform(const BCMatrix &mat, bool inverse)
+{
+  apply_transform(this->matrix, mat.matrix, this->matrix, inverse);
+}
+
+void BCMatrix::add_transform(Matrix &to, const Matrix &transform, const Matrix &from, bool inverse)
+{
+  if (inverse) {
+    Matrix globinv;
+    invert_m4_m4(globinv, transform);
+    add_transform(to, globinv, from, /*inverse=*/false);
+  }
+  else {
+    mul_m4_m4m4(to, transform, from);
+  }
+}
+
+void BCMatrix::apply_transform(Matrix &to, const Matrix &transform, const Matrix &from, bool inverse)
+{
+  Matrix globinv;
+  invert_m4_m4(globinv, transform);
+  if (inverse) {
+    add_transform(to, globinv, from, /*inverse=*/false);
+  }
+  else {
+    mul_m4_m4m4(to, transform, from);
+    mul_m4_m4m4(to, to, globinv);
+  }
+}
+
+void BCMatrix::add_inverted_transform(Matrix &to, const Matrix &transform, const Matrix &from)
+{
+  Matrix workmat;
+  invert_m4_m4(workmat, transform);
+  mul_m4_m4m4(to, workmat, from);
 }
 
 void BCMatrix::set_transform(Object *ob)
 }
 
 void BCMatrix::set_transform(Object *ob)
@@ -71,6 +129,13 @@ void BCMatrix::set_transform(Object *ob)
   quat_to_compatible_eul(this->rot, ob->rot, this->q);
 }
 
   quat_to_compatible_eul(this->rot, ob->rot, this->q);
 }
 
+void BCMatrix::set_transform(Matrix &mat)
+{
+  copy_m4_m4(matrix, mat);
+  mat4_decompose(this->loc, this->q, this->size, mat);
+  quat_to_eul(this->rot, this->q);
+}
+
 const BCMatrix *BCSample::get_matrix(Bone *bone) const
 {
   BCBoneMatrixMap::const_iterator it = bonemats.find(bone);
 const BCMatrix *BCSample::get_matrix(Bone *bone) const
 {
   BCBoneMatrixMap::const_iterator it = bonemats.find(bone);
@@ -126,12 +191,28 @@ void BCMatrix::sanitize(Matrix &mat, int precision)
 
 void BCMatrix::unit()
 {
 
 void BCMatrix::unit()
 {
-  unit_m4(matrix);
+  unit_m4(this->matrix);
+  mat4_decompose(this->loc, this->q, this->size, this->matrix);
+  quat_to_eul(this->rot, this->q);
 }
 
 /* We need double here because the OpenCollada API needs it.
  * precision = -1 indicates to not limit the precision. */
 }
 
 /* We need double here because the OpenCollada API needs it.
  * precision = -1 indicates to not limit the precision. */
-void BCMatrix::get_matrix(double (&mat)[4][4], const bool transposed, const int precision) const
+void BCMatrix::get_matrix(DMatrix &mat, const bool transposed, const int precision) const
+{
+  for (int i = 0; i < 4; i++)
+    for (int j = 0; j < 4; j++) {
+      float val = (transposed) ? matrix[j][i] : matrix[i][j];
+      if (precision >= 0)
+        val = floor((val * pow(10, precision) + 0.5)) / pow(10, precision);
+      mat[i][j] = val;
+    }
+}
+
+void BCMatrix::get_matrix(Matrix &mat,
+                          const bool transposed,
+                          const int precision,
+                          const bool inverted) const
 {
   for (int i = 0; i < 4; i++)
     for (int j = 0; j < 4; j++) {
 {
   for (int i = 0; i < 4; i++)
     for (int j = 0; j < 4; j++) {
@@ -140,6 +221,10 @@ void BCMatrix::get_matrix(double (&mat)[4][4], const bool transposed, const int
         val = floor((val * pow(10, precision) + 0.5)) / pow(10, precision);
       mat[i][j] = val;
     }
         val = floor((val * pow(10, precision) + 0.5)) / pow(10, precision);
       mat[i][j] = val;
     }
+
+  if (inverted) {
+    invert_m4(mat);
+  }
 }
 
 const bool BCMatrix::in_range(const BCMatrix &other, float distance) const
 }
 
 const bool BCMatrix::in_range(const BCMatrix &other, float distance) const
index 9cb56c95e0f9c9363b3576b0a0bf3b9243688675..709bd3e59ef28842ba0b88aef1eb11d3eb16a95b 100644 (file)
@@ -24,6 +24,8 @@
 #include <map>
 #include <algorithm>
 
 #include <map>
 #include <algorithm>
 
+#include "ExportSettings.h"
+
 extern "C" {
 #include "BKE_object.h"
 #include "BLI_math_rotation.h"
 extern "C" {
 #include "BKE_object.h"
 #include "BLI_math_rotation.h"
@@ -34,40 +36,6 @@ extern "C" {
 #include "DNA_camera_types.h"
 }
 
 #include "DNA_camera_types.h"
 }
 
-typedef float(Matrix)[4][4];
-
-class BCMatrix {
-
- private:
-  mutable float matrix[4][4];
-  mutable float size[3];
-  mutable float rot[3];
-  mutable float loc[3];
-  mutable float q[4];
-
-  void unit();
-  void copy(Matrix &r, Matrix &a);
-  void set_transform(Object *ob);
-  void set_transform(Matrix &mat);
-
- public:
-  float (&location() const)[3];
-  float (&rotation() const)[3];
-  float (&scale() const)[3];
-  float (&quat() const)[4];
-
-  BCMatrix(Matrix &mat);
-  BCMatrix(Object *ob);
-
-  void get_matrix(double (&mat)[4][4],
-                  const bool transposed = false,
-                  const int precision = -1) const;
-
-  const bool in_range(const BCMatrix &other, float distance) const;
-  static void sanitize(Matrix &matrix, int precision);
-  static void transpose(Matrix &matrix);
-};
-
 typedef std::map<Bone *, BCMatrix *> BCBoneMatrixMap;
 
 class BCSample {
 typedef std::map<Bone *, BCMatrix *> BCBoneMatrixMap;
 
 class BCSample {
@@ -76,7 +44,10 @@ class BCSample {
   BCBoneMatrixMap bonemats; /* For Armature animation */
 
  public:
   BCBoneMatrixMap bonemats; /* For Armature animation */
 
  public:
-  BCSample(Object *ob);
+  BCSample(Object *ob) : obmat(ob)
+  {
+  }
+
   ~BCSample();
 
   void add_bone_matrix(Bone *bone, Matrix &mat);
   ~BCSample();
 
   void add_bone_matrix(Bone *bone, Matrix &mat);
index 384f235e00cb7962fede872fb931c54fb20459de..709f84c3f772575dafc10bcfb45684c020c9c52c 100644 (file)
  * \ingroup collada
  */
 
  * \ingroup collada
  */
 
+#include <vector>
+
 #include "BlenderContext.h"
 #include "BKE_scene.h"
 
 #include "BlenderContext.h"
 #include "BKE_scene.h"
 
+bool bc_is_base_node(LinkNode *export_set, Object *ob, ViewLayer *view_layer)
+{
+  Object *root = bc_get_highest_exported_ancestor_or_self(export_set, ob, view_layer);
+  return (root == ob);
+}
+
+/**
+ * Returns the highest selected ancestor
+ * returns NULL if no ancestor is selected
+ * IMPORTANT: This function expects that all exported objects have set:
+ * ob->id.tag & LIB_TAG_DOIT
+ */
+Object *bc_get_highest_exported_ancestor_or_self(LinkNode *export_set,
+                                                 Object *ob,
+                                                 ViewLayer *view_layer)
+{
+  Object *ancestor = ob;
+  while (ob->parent) {
+    if (bc_is_in_Export_set(export_set, ob->parent, view_layer)) {
+      ancestor = ob->parent;
+    }
+    ob = ob->parent;
+  }
+  return ancestor;
+}
+
+void bc_get_children(std::vector<Object *> &child_set, Object *ob, ViewLayer *view_layer)
+{
+  Base *base;
+  for (base = (Base *)view_layer->object_bases.first; base; base = base->next) {
+    Object *cob = base->object;
+    if (cob->parent == ob) {
+      switch (ob->type) {
+        case OB_MESH:
+        case OB_CAMERA:
+        case OB_LAMP:
+        case OB_EMPTY:
+        case OB_ARMATURE:
+          child_set.push_back(cob);
+        default:
+          break;
+      }
+    }
+  }
+}
+
+bool bc_is_in_Export_set(LinkNode *export_set, Object *ob, ViewLayer *view_layer)
+{
+  bool to_export = (BLI_linklist_index(export_set, ob) != -1);
+
+  if (!to_export) {
+    /* Mark this object as to_export even if it is not in the
+    export list, but it contains children to export */
+
+    std::vector<Object *> children;
+    bc_get_children(children, ob, view_layer);
+    for (int i = 0; i < children.size(); i++) {
+      if (bc_is_in_Export_set(export_set, children[i], view_layer)) {
+        to_export = true;
+        break;
+      }
+    }
+  }
+  return to_export;
+}
+
+int bc_is_marked(Object *ob)
+{
+  return ob && (ob->id.tag & LIB_TAG_DOIT);
+}
+
+void bc_remove_mark(Object *ob)
+{
+  ob->id.tag &= ~LIB_TAG_DOIT;
+}
+
+void bc_set_mark(Object *ob)
+{
+  ob->id.tag |= LIB_TAG_DOIT;
+}
+
 BlenderContext::BlenderContext(bContext *C)
 {
   context = C;
 BlenderContext::BlenderContext(bContext *C)
 {
   context = C;
index f79f3a52507e86e8bdec0fcef86946a56d13e4ba..da0384eba8b8415a805df2211438531e62926dc1 100644 (file)
 #ifndef __BLENDERCONTEXT_H__
 #define __BLENDERCONTEXT_H__
 
 #ifndef __BLENDERCONTEXT_H__
 #define __BLENDERCONTEXT_H__
 
+#ifdef __cplusplus
+
 extern "C" {
 extern "C" {
+#endif
+
 #include "DNA_object_types.h"
 #include "DNA_object_types.h"
+#include "BLI_linklist.h"
 #include "BKE_context.h"
 #include "BKE_main.h"
 #include "DEG_depsgraph.h"
 #include "DEG_depsgraph_query.h"
 #include "BKE_context.h"
 #include "BKE_main.h"
 #include "DEG_depsgraph.h"
 #include "DEG_depsgraph_query.h"
+#include "DNA_layer_types.h"
+
+typedef float(Vector)[3];
+typedef float(Matrix)[4][4];
+typedef double(DMatrix)[4][4];
+
+typedef enum BC_global_forward_axis {
+  BC_GLOBAL_FORWARD_X = 0,
+  BC_GLOBAL_FORWARD_Y = 1,
+  BC_GLOBAL_FORWARD_Z = 2,
+  BC_GLOBAL_FORWARD_MINUS_X = 3,
+  BC_GLOBAL_FORWARD_MINUS_Y = 4,
+  BC_GLOBAL_FORWARD_MINUS_Z = 5
+} BC_global_forward_axis;
+
+typedef enum BC_global_up_axis {
+  BC_GLOBAL_UP_X = 0,
+  BC_GLOBAL_UP_Y = 1,
+  BC_GLOBAL_UP_Z = 2,
+  BC_GLOBAL_UP_MINUS_X = 3,
+  BC_GLOBAL_UP_MINUS_Y = 4,
+  BC_GLOBAL_UP_MINUS_Z = 5
+} BC_global_up_axis;
+
+static const BC_global_forward_axis BC_DEFAULT_FORWARD = BC_GLOBAL_FORWARD_Y;
+static const BC_global_up_axis BC_DEFAULT_UP = BC_GLOBAL_UP_Z;
+
+bool bc_is_in_Export_set(LinkNode *export_set, Object *ob, ViewLayer *view_layer);
+bool bc_is_base_node(LinkNode *export_set, Object *ob, ViewLayer *view_layer);
+Object *bc_get_highest_exported_ancestor_or_self(LinkNode *export_set,
+                                                 Object *ob,
+                                                 ViewLayer *view_layer);
+int bc_is_marked(Object *ob);
+void bc_remove_mark(Object *ob);
+void bc_set_mark(Object *ob);
+
+#ifdef __cplusplus
 }
 
 }
 
+class BCMatrix {
+
+ private:
+  mutable float matrix[4][4];
+  mutable float size[3];
+  mutable float rot[3];
+  mutable float loc[3];
+  mutable float q[4];
+
+  void unit();
+  void copy(Matrix &r, Matrix &a);
+
+ public:
+  float (&location() const)[3];
+  float (&rotation() const)[3];
+  float (&scale() const)[3];
+  float (&quat() const)[4];
+
+  BCMatrix(BC_global_forward_axis global_forward_axis, BC_global_up_axis global_up_axis);
+  BCMatrix(const BCMatrix &mat);
+  BCMatrix(Matrix &mat);
+  BCMatrix(Object *ob);
+  BCMatrix();
+
+  void get_matrix(DMatrix &matrix, const bool transposed = false, const int precision = -1) const;
+  void get_matrix(Matrix &matrix,
+                  const bool transposed = false,
+                  const int precision = -1,
+                  const bool inverted = false) const;
+  void set_transform(Object *ob);
+  void set_transform(Matrix &mat);
+  void add_transform(Matrix &to,
+                     const Matrix &transform,
+                     const Matrix &from,
+                     const bool inverted = false);
+  void apply_transform(Matrix &to,
+                     const Matrix &transform,
+                     const Matrix &from,
+                     const bool inverted = false);
+  void add_inverted_transform(Matrix &to, const Matrix &transform, const Matrix &from);
+  void add_transform(const Matrix &matrix, const bool inverted = false);
+  void add_transform(const BCMatrix &matrix, const bool inverted = false);
+  void apply_transform(const BCMatrix &matrix, const bool inverted = false);
+
+  const bool in_range(const BCMatrix &other, float distance) const;
+  static void sanitize(Matrix &matrix, int precision);
+  static void transpose(Matrix &matrix);
+};
+
 class BlenderContext {
  private:
   bContext *context;
 class BlenderContext {
  private:
   bContext *context;
@@ -47,5 +138,6 @@ class BlenderContext {
   ViewLayer *get_view_layer();
   Main *get_main();
 };
   ViewLayer *get_view_layer();
   Main *get_main();
 };
+#endif
 
 #endif
 
 #endif
index a46ee74be91d74e88f5ac5058e08f6e8540b3288..74862c44270aaa9bb8abb0628a6eeb4bc23e43c8 100644 (file)
@@ -29,8 +29,7 @@ extern "C" {
 
 #include "collada_internal.h"
 
 
 #include "collada_internal.h"
 
-CamerasExporter::CamerasExporter(COLLADASW::StreamWriter *sw,
-                                 const ExportSettings *export_settings)
+CamerasExporter::CamerasExporter(COLLADASW::StreamWriter *sw, BCExportSettings &export_settings)
     : COLLADASW::LibraryCameras(sw), export_settings(export_settings)
 {
 }
     : COLLADASW::LibraryCameras(sw), export_settings(export_settings)
 {
 }
@@ -52,7 +51,7 @@ void CamerasExporter::exportCameras(Scene *sce)
 {
   openLibrary();
 
 {
   openLibrary();
 
-  forEachCameraObjectInExportSet(sce, *this, this->export_settings->export_set);
+  forEachCameraObjectInExportSet(sce, *this, this->export_settings.get_export_set());
 
   closeLibrary();
 }
 
   closeLibrary();
 }
index 0a90fc017e8f5287eaddb29e9d7e34d61bc3adf7..04bcc4a5dad47cf1779c0bafdbae672db81f922e 100644 (file)
@@ -34,13 +34,13 @@ extern "C" {
 
 class CamerasExporter : COLLADASW::LibraryCameras {
  public:
 
 class CamerasExporter : COLLADASW::LibraryCameras {
  public:
-  CamerasExporter(COLLADASW::StreamWriter *sw, const ExportSettings *export_settings);
+  CamerasExporter(COLLADASW::StreamWriter *sw, BCExportSettings &export_settings);
   void exportCameras(Scene *sce);
   void operator()(Object *ob, Scene *sce);
 
  private:
   bool exportBlenderProfile(COLLADASW::Camera &cla, Camera *cam);
   void exportCameras(Scene *sce);
   void operator()(Object *ob, Scene *sce);
 
  private:
   bool exportBlenderProfile(COLLADASW::Camera &cla, Camera *cam);
-  const ExportSettings *export_settings;
+  BCExportSettings &export_settings;
 };
 
 #endif
 };
 
 #endif
index c79a4e1a1f7e2464ab67098acbf7c4b2cc2a4b55..adea9fd672af7b8721166cca4a26e60c435214e5 100644 (file)
@@ -57,7 +57,7 @@ void ControllerExporter::write_bone_URLs(COLLADASW::InstanceController &ins,
                                          Object *ob_arm,
                                          Bone *bone)
 {
                                          Object *ob_arm,
                                          Bone *bone)
 {
-  if (bc_is_root_bone(bone, this->export_settings->deform_bones_only)) {
+  if (bc_is_root_bone(bone, this->export_settings.get_deform_bones_only())) {
     std::string node_id = translate_id(id_name(ob_arm) + "_" + bone->name);
     ins.addSkeleton(COLLADABU::URI(COLLADABU::Utils::EMPTY_STRING, node_id));
   }
     std::string node_id = translate_id(id_name(ob_arm) + "_" + bone->name);
     ins.addSkeleton(COLLADABU::URI(COLLADABU::Utils::EMPTY_STRING, node_id));
   }
@@ -89,7 +89,7 @@ bool ControllerExporter::add_instance_controller(Object *ob)
   }
 
   InstanceWriter::add_material_bindings(
   }
 
   InstanceWriter::add_material_bindings(
-      ins.getBindMaterial(), ob, this->export_settings->active_uv_only);
+      ins.getBindMaterial(), ob, this->export_settings.get_active_uv_only());
 
   ins.add();
   return true;
 
   ins.add();
   return true;
@@ -102,7 +102,7 @@ void ControllerExporter::export_controllers()
 
   GeometryFunctor gf;
   gf.forEachMeshObjectInExportSet<ControllerExporter>(
 
   GeometryFunctor gf;
   gf.forEachMeshObjectInExportSet<ControllerExporter>(
-      sce, *this, this->export_settings->export_set);
+      sce, *this, this->export_settings.get_export_set());
 
   closeLibrary();
 }
 
   closeLibrary();
 }
@@ -115,7 +115,7 @@ void ControllerExporter::operator()(Object *ob)
   if (ob_arm) {
     export_skin_controller(ob, ob_arm);
   }
   if (ob_arm) {
     export_skin_controller(ob, ob_arm);
   }
-  if (key && this->export_settings->include_shapekeys) {
+  if (key && this->export_settings.get_include_shapekeys()) {
     export_morph_controller(ob, key);
   }
 }
     export_morph_controller(ob, key);
   }
 }
@@ -189,7 +189,7 @@ void ControllerExporter::export_skin_controller(Object *ob, Object *ob_arm)
   } MDeformWeight;
 #endif
 
   } MDeformWeight;
 #endif
 
-  bool use_instantiation = this->export_settings->use_object_instantiation;
+  bool use_instantiation = this->export_settings.get_use_object_instantiation();
   Mesh *me;
 
   if (((Mesh *)ob->data)->dvert == NULL) {
   Mesh *me;
 
   if (((Mesh *)ob->data)->dvert == NULL) {
@@ -198,9 +198,9 @@ void ControllerExporter::export_skin_controller(Object *ob, Object *ob_arm)
 
   me = bc_get_mesh_copy(blender_context,
                         ob,
 
   me = bc_get_mesh_copy(blender_context,
                         ob,
-                        this->export_settings->export_mesh_type,
-                        this->export_settings->apply_modifiers,
-                        this->export_settings->triangulate);
+                        this->export_settings.get_export_mesh_type(),
+                        this->export_settings.get_apply_modifiers(),
+                        this->export_settings.get_triangulate());
 
   std::string controller_name = id_name(ob_arm);
   std::string controller_id = get_controller_id(ob_arm, ob);
 
   std::string controller_name = id_name(ob_arm);
   std::string controller_id = get_controller_id(ob_arm, ob);
@@ -297,14 +297,14 @@ void ControllerExporter::export_skin_controller(Object *ob, Object *ob_arm)
 
 void ControllerExporter::export_morph_controller(Object *ob, Key *key)
 {
 
 void ControllerExporter::export_morph_controller(Object *ob, Key *key)
 {
-  bool use_instantiation = this->export_settings->use_object_instantiation;
+  bool use_instantiation = this->export_settings.get_use_object_instantiation();
   Mesh *me;
 
   me = bc_get_mesh_copy(blender_context,
                         ob,
   Mesh *me;
 
   me = bc_get_mesh_copy(blender_context,
                         ob,
-                        this->export_settings->export_mesh_type,
-                        this->export_settings->apply_modifiers,
-                        this->export_settings->triangulate);
+                        this->export_settings.get_export_mesh_type(),
+                        this->export_settings.get_apply_modifiers(),
+                        this->export_settings.get_triangulate());
 
   std::string controller_name = id_name(ob) + "-morph";
   std::string controller_id = get_controller_id(key, ob);
 
   std::string controller_name = id_name(ob) + "-morph";
   std::string controller_id = get_controller_id(key, ob);
@@ -431,9 +431,16 @@ void ControllerExporter::add_bind_shape_mat(Object *ob)
   float f_obmat[4][4];
   BKE_object_matrix_local_get(ob, f_obmat);
 
   float f_obmat[4][4];
   BKE_object_matrix_local_get(ob, f_obmat);
 
+  if (export_settings.get_apply_global_orientation()) {
+    // do nothing, rotation is going to be applied to the Data
+  }
+  else {
+    bc_add_global_transform(f_obmat, export_settings.get_global_transform());
+  }
+
   // UnitConverter::mat4_to_dae_double(bind_mat, ob->obmat);
   UnitConverter::mat4_to_dae_double(bind_mat, f_obmat);
   // UnitConverter::mat4_to_dae_double(bind_mat, ob->obmat);
   UnitConverter::mat4_to_dae_double(bind_mat, f_obmat);
-  if (this->export_settings->limit_precision)
+  if (this->export_settings.get_limit_precision())
     bc_sanitize_mat(bind_mat, LIMITTED_PRECISION);
 
   addBindShapeTransform(bind_mat);
     bc_sanitize_mat(bind_mat, LIMITTED_PRECISION);
 
   addBindShapeTransform(bind_mat);
@@ -532,8 +539,7 @@ std::string ControllerExporter::add_inv_bind_mats_source(Object *ob_arm,
             this->export_settings, pchan->bone, bind_mat, pchan->bone->arm_mat, true);
 
         /* SL/OPEN_SIM COMPATIBILITY */
             this->export_settings, pchan->bone, bind_mat, pchan->bone->arm_mat, true);
 
         /* SL/OPEN_SIM COMPATIBILITY */
-        if (export_settings->open_sim) {
-
+        if (export_settings.get_open_sim()) {
           float loc[3];
           float rot[3] = {0, 0, 0};
           float scale[3];
           float loc[3];
           float rot[3] = {0, 0, 0};
           float scale[3];
@@ -547,9 +553,13 @@ std::string ControllerExporter::add_inv_bind_mats_source(Object *ob_arm,
       /* make world-space matrix (bind_mat is armature-space) */
       mul_m4_m4m4(world, ob_arm->obmat, bind_mat);
 
       /* make world-space matrix (bind_mat is armature-space) */
       mul_m4_m4m4(world, ob_arm->obmat, bind_mat);
 
+      if (export_settings.get_apply_global_orientation()) {
+        bc_apply_global_transform(world, export_settings.get_global_transform());
+      }
+
       invert_m4_m4(mat, world);
       UnitConverter::mat4_to_dae(inv_bind_mat, mat);
       invert_m4_m4(mat, world);
       UnitConverter::mat4_to_dae(inv_bind_mat, mat);
-      if (this->export_settings->limit_precision)
+      if (this->export_settings.get_limit_precision())
         bc_sanitize_mat(inv_bind_mat, LIMITTED_PRECISION);
       source.appendValues(inv_bind_mat);
     }
         bc_sanitize_mat(inv_bind_mat, LIMITTED_PRECISION);
       source.appendValues(inv_bind_mat);
     }
index 38d85cb7ebcb4240ed332e0c1f8d4240fde3c02c..200f8431f62919bcce5562b3afdb5dc82614a8f4 100644 (file)
@@ -53,13 +53,17 @@ class SceneExporter;
 class ControllerExporter : public COLLADASW::LibraryControllers,
                            protected TransformWriter,
                            protected InstanceWriter {
 class ControllerExporter : public COLLADASW::LibraryControllers,
                            protected TransformWriter,
                            protected InstanceWriter {
+ private:
+  BlenderContext &blender_context;
+  BCExportSettings export_settings;
+
  public:
   // XXX exporter writes wrong data for shared armatures.  A separate
   // controller should be written for each armature-mesh binding how do
   // we make controller ids then?
   ControllerExporter(BlenderContext &blender_context,
                      COLLADASW::StreamWriter *sw,
  public:
   // XXX exporter writes wrong data for shared armatures.  A separate
   // controller should be written for each armature-mesh binding how do
   // we make controller ids then?
   ControllerExporter(BlenderContext &blender_context,
                      COLLADASW::StreamWriter *sw,
-                     const ExportSettings *export_settings)
+                     BCExportSettings &export_settings)
       : COLLADASW::LibraryControllers(sw),
         blender_context(blender_context),
         export_settings(export_settings)
       : COLLADASW::LibraryControllers(sw),
         blender_context(blender_context),
         export_settings(export_settings)
@@ -75,9 +79,6 @@ class ControllerExporter : public COLLADASW::LibraryControllers,
   void operator()(Object *ob);
 
  private:
   void operator()(Object *ob);
 
  private:
-  BlenderContext &blender_context;
-  const ExportSettings *export_settings;
-
 #if 0
   std::vector<Object *> written_armatures;
 
 #if 0
   std::vector<Object *> written_armatures;
 
index c8202eb3cf608c60b1be95fb9b56e9b03f0c1e22..f9232851fbb612bcb5337b6de1a59e20561f5f17 100644 (file)
@@ -146,9 +146,9 @@ char *bc_CustomData_get_active_layer_name(const CustomData *data, int type)
   return data->layers[layer_index].name;
 }
 
   return data->layers[layer_index].name;
 }
 
-DocumentExporter::DocumentExporter(BlenderContext &blender_context,
-                                   const ExportSettings *export_settings)
-    : blender_context(blender_context), export_settings(export_settings)
+DocumentExporter::DocumentExporter(BlenderContext &blender_context, ExportSettings *exportSettings)
+    : blender_context(blender_context),
+      export_settings(BCExportSettings(exportSettings, blender_context))
 {
 }
 
 {
 }
 
@@ -262,7 +262,7 @@ int DocumentExporter::exportCurrentScene()
   asset.getContributor().mAuthoringTool = version_buf;
   asset.add();
 
   asset.getContributor().mAuthoringTool = version_buf;
   asset.add();
 
-  LinkNode *export_set = this->export_settings->export_set;
+  LinkNode *export_set = this->export_settings.get_export_set();
   // <library_cameras>
   if (bc_has_object_type(export_set, OB_CAMERA)) {
     CamerasExporter ce(writer, this->export_settings);
   // <library_cameras>
   if (bc_has_object_type(export_set, OB_CAMERA)) {
     CamerasExporter ce(writer, this->export_settings);
@@ -296,7 +296,8 @@ int DocumentExporter::exportCurrentScene()
   // <library_controllers>
   ArmatureExporter arm_exporter(blender_context, writer, this->export_settings);
   ControllerExporter controller_exporter(blender_context, writer, this->export_settings);
   // <library_controllers>
   ArmatureExporter arm_exporter(blender_context, writer, this->export_settings);
   ControllerExporter controller_exporter(blender_context, writer, this->export_settings);
-  if (bc_has_object_type(export_set, OB_ARMATURE) || this->export_settings->include_shapekeys) {
+  if (bc_has_object_type(export_set, OB_ARMATURE) ||
+      this->export_settings.get_include_shapekeys()) {
     controller_exporter.export_controllers();
   }
 
     controller_exporter.export_controllers();
   }
 
@@ -304,9 +305,9 @@ int DocumentExporter::exportCurrentScene()
 
   SceneExporter se(blender_context, writer, &arm_exporter, this->export_settings);
 
 
   SceneExporter se(blender_context, writer, &arm_exporter, this->export_settings);
 
-  if (this->export_settings->include_animations) {
+  if (this->export_settings.get_include_animations()) {
     // <library_animations>
     // <library_animations>
-    AnimationExporter ae(blender_context, writer, this->export_settings);
+    AnimationExporter ae(writer, this->export_settings);
     ae.exportAnimations();
   }
 
     ae.exportAnimations();
   }
 
@@ -322,10 +323,10 @@ int DocumentExporter::exportCurrentScene()
   delete writer;
 
   // Finally move the created document into place
   delete writer;
 
   // Finally move the created document into place
-  fprintf(stdout, "Collada export to: %s\n", this->export_settings->filepath);
-  int status = BLI_rename(native_filename.c_str(), this->export_settings->filepath);
+  fprintf(stdout, "Collada export to: %s\n", this->export_settings.get_filepath());
+  int status = BLI_rename(native_filename.c_str(), this->export_settings.get_filepath());
   if (status != 0) {
   if (status != 0) {
-    status = BLI_copy(native_filename.c_str(), this->export_settings->filepath);
+    status = BLI_copy(native_filename.c_str(), this->export_settings.get_filepath());
     BLI_delete(native_filename.c_str(), false, false);
   }
   return status;
     BLI_delete(native_filename.c_str(), false, false);
   }
   return status;
index a5608d13a71f54d99b2d9dd66d4c4350a9e5a5ae..70722ae601e78d7b14ad25211fde54c7e067644a 100644 (file)
@@ -31,13 +31,13 @@ extern "C" {
 
 class DocumentExporter {
  public:
 
 class DocumentExporter {
  public:
-  DocumentExporter(BlenderContext &blender_context, const ExportSettings *export_settings);
+  DocumentExporter(BlenderContext &blender_context, ExportSettings *export_settings);
   int exportCurrentScene();
   void exportScenes(const char *filename);
 
  private:
   BlenderContext &blender_context;
   int exportCurrentScene();
   void exportScenes(const char *filename);
 
  private:
   BlenderContext &blender_context;
-  const ExportSettings *export_settings;
+  BCExportSettings export_settings;
   KeyImageMap key_image_map;
 };
 
   KeyImageMap key_image_map;
 };
 
index 3aceebe04227710bf557d8504ba6a85a99d7331f..60813fb951c9e151e3073112099ef117805be7c5 100644 (file)
@@ -1125,7 +1125,6 @@ bool DocumentImporter::writeAnimation(const COLLADAFW::Animation *anim)
   if (mImportStage == Fetching_Controller_data)
     return true;
 
   if (mImportStage == Fetching_Controller_data)
     return true;
 
-  /* return true; */
   return anim_importer.write_animation(anim);
 }
 
   return anim_importer.write_animation(anim);
 }
 
index a6e75ba41a9bc3a0f4ef02eb858b995c55bbfbff..61603226dfd75f0be52caba8a3821b78f5a5b44f 100644 (file)
@@ -53,7 +53,7 @@ static std::string getActiveUVLayerName(Object *ob)
 }
 
 EffectsExporter::EffectsExporter(COLLADASW::StreamWriter *sw,
 }
 
 EffectsExporter::EffectsExporter(COLLADASW::StreamWriter *sw,
-                                 const ExportSettings *export_settings,
+                                 BCExportSettings &export_settings,
                                  KeyImageMap &key_image_map)
     : COLLADASW::LibraryEffects(sw), export_settings(export_settings), key_image_map(key_image_map)
 {
                                  KeyImageMap &key_image_map)
     : COLLADASW::LibraryEffects(sw), export_settings(export_settings), key_image_map(key_image_map)
 {
@@ -84,7 +84,8 @@ void EffectsExporter::exportEffects(bContext *C, Scene *sce)
     this->scene = sce;
     openLibrary();
     MaterialFunctor mf;
     this->scene = sce;
     openLibrary();
     MaterialFunctor mf;
-    mf.forEachMaterialInExportSet<EffectsExporter>(sce, *this, this->export_settings->export_set);
+    mf.forEachMaterialInExportSet<EffectsExporter>(
+        sce, *this, this->export_settings.get_export_set());
 
     closeLibrary();
   }
 
     closeLibrary();
   }
index 25df2d7eb89d6f89b5c1d1482bc3f7f14ffe18ba..75511800081567a28d996c45292906c49aeb6f6e 100644 (file)
@@ -40,7 +40,7 @@
 class EffectsExporter : COLLADASW::LibraryEffects {
  public:
   EffectsExporter(COLLADASW::StreamWriter *sw,
 class EffectsExporter : COLLADASW::LibraryEffects {
  public:
   EffectsExporter(COLLADASW::StreamWriter *sw,
-                  const ExportSettings *export_settings,
+                  BCExportSettings &export_settings,
                   KeyImageMap &key_image_map);
   void exportEffects(bContext *C, Scene *sce);
 
                   KeyImageMap &key_image_map);
   void exportEffects(bContext *C, Scene *sce);
 
@@ -73,7 +73,7 @@ class EffectsExporter : COLLADASW::LibraryEffects {
 
   bool hasEffects(Scene *sce);
 
 
   bool hasEffects(Scene *sce);
 
-  const ExportSettings *export_settings;
+  BCExportSettings &export_settings;
   KeyImageMap &key_image_map;
   Scene *scene;
   bContext *mContext;
   KeyImageMap &key_image_map;
   Scene *scene;
   bContext *mContext;
index a362b72be0099c2d5c04cb5429ccbae32fa52d7a..7112aeadb2ae9952ec8e556d1efb560ba53a2911 100644 (file)
 #define __EXPORTSETTINGS_H__
 
 #ifdef __cplusplus
 #define __EXPORTSETTINGS_H__
 
 #ifdef __cplusplus
+#  include <vector>
+
 extern "C" {
 #endif
 
 #include "BLI_linklist.h"
 extern "C" {
 #endif
 
 #include "BLI_linklist.h"
+#include "BlenderContext.h"
 
 typedef enum BC_export_mesh_type {
   BC_MESH_TYPE_VIEW,
 
 typedef enum BC_export_mesh_type {
   BC_MESH_TYPE_VIEW,
@@ -52,6 +55,10 @@ typedef enum BC_ui_export_section {
 
 typedef struct ExportSettings {
   bool apply_modifiers;
 
 typedef struct ExportSettings {
   bool apply_modifiers;
+  BC_global_forward_axis global_forward;
+  BC_global_up_axis global_up;
+  bool apply_global_orientation;
+
   BC_export_mesh_type export_mesh_type;
 
   bool selected;
   BC_export_mesh_type export_mesh_type;
 
   bool selected;
@@ -86,6 +93,196 @@ typedef struct ExportSettings {
 
 #ifdef __cplusplus
 }
 
 #ifdef __cplusplus
 }
+
+void bc_get_children(std::vector<Object *> &child_set, Object *ob, ViewLayer *view_layer);
+
+class BCExportSettings {
+
+ private:
+  const ExportSettings &export_settings;
+  BlenderContext &blender_context;
+  const BCMatrix global_transform;
+
+ public:
+  BCExportSettings(ExportSettings *exportSettings, BlenderContext &blenderContext)
+      : export_settings(*exportSettings),
+        blender_context(blenderContext),
+        global_transform(BCMatrix(exportSettings->global_forward, exportSettings->global_up))
+
+  {
+  }
+
+  const BCMatrix &get_global_transform()
+  {
+    return global_transform;
+  }
+
+  bool get_apply_modifiers()
+  {
+    return export_settings.apply_modifiers;
+  }
+
+  BC_global_forward_axis get_global_forward()
+  {
+    return export_settings.global_forward;
+  }
+
+  BC_global_up_axis get_global_up()
+  {
+    return export_settings.global_up;
+  }
+
+  bool get_apply_global_orientation()
+  {
+    return export_settings.apply_global_orientation;
+  }
+
+  BC_export_mesh_type get_export_mesh_type()
+  {
+    return export_settings.export_mesh_type;
+  }
+
+  bool get_selected()
+  {
+    return export_settings.selected;
+  }
+
+  bool get_include_children()
+  {
+    return export_settings.include_children;
+  }
+
+  bool get_include_armatures()
+  {
+    return export_settings.include_armatures;
+  }
+
+  bool get_include_shapekeys()
+  {
+    return export_settings.include_shapekeys;
+  }
+
+  bool get_deform_bones_only()
+  {
+    return export_settings.deform_bones_only;
+  }
+
+  bool get_include_animations()
+  {
+    return export_settings.include_animations;
+  }
+
+  bool get_include_all_actions()
+  {
+    return export_settings.include_all_actions;
+  }
+
+  int get_sampling_rate()
+  {
+    return export_settings.sampling_rate;
+  }
+
+  bool get_keep_smooth_curves()
+  {
+    return export_settings.keep_smooth_curves;
+  }
+
+  bool get_keep_keyframes()
+  {
+    return export_settings.keep_keyframes;
+  }
+
+  bool get_keep_flat_curves()
+  {
+    return export_settings.keep_flat_curves;
+  }
+
+  bool get_active_uv_only()
+  {
+    return export_settings.active_uv_only;
+  }
+
+  BC_export_animation_type get_export_animation_type()
+  {
+    return export_settings.export_animation_type;
+  }
+
+  bool get_use_texture_copies()
+  {
+    return export_settings.use_texture_copies;
+  }
+
+  bool get_triangulate()
+  {
+    return export_settings.triangulate;
+  }
+
+  bool get_use_object_instantiation()
+  {
+    return export_settings.use_object_instantiation;
+  }
+
+  bool get_use_blender_profile()
+  {
+    return export_settings.use_blender_profile;
+  }
+
+  bool get_sort_by_name()
+  {
+    return export_settings.sort_by_name;
+  }
+
+  BC_export_transformation_type get_export_transformation_type()
+  {
+    return export_settings.export_transformation_type;
+  }
+
+  bool get_open_sim()
+  {
+    return export_settings.open_sim;
+  }
+
+  bool get_limit_precision()
+  {
+    return export_settings.limit_precision;
+  }
+
+  bool get_keep_bind_info()
+  {
+    return export_settings.keep_bind_info;
+  }
+
+  char *get_filepath()
+  {
+    return export_settings.filepath;
+  }
+
+  LinkNode *get_export_set()
+  {
+    return export_settings.export_set;
+  }
+
+  BlenderContext &get_blender_context()
+  {
+    return blender_context;
+  }
+
+  Scene *get_scene()
+  {
+    return blender_context.get_scene();
+  }
+
+  ViewLayer *get_view_layer()
+  {
+    return blender_context.get_view_layer();
+  }
+
+  bool is_export_root(Object *ob)
+  {
+    return bc_is_base_node(get_export_set(), ob, get_view_layer());
+  }
+};
+
 #endif
 
 #endif
 #endif
 
 #endif
index bda6fec70a8e93a4fbcf28ee0ab17ca8293ad7be..5125a9a0562896400f7c51f18b136d83e0847bef 100644 (file)
@@ -48,19 +48,20 @@ void GeometryExporter::exportGeom()
   openLibrary();
 
   GeometryFunctor gf;
   openLibrary();
 
   GeometryFunctor gf;
-  gf.forEachMeshObjectInExportSet<GeometryExporter>(sce, *this, this->export_settings->export_set);
+  gf.forEachMeshObjectInExportSet<GeometryExporter>(
+      sce, *this, this->export_settings.get_export_set());
 
   closeLibrary();
 }
 
 void GeometryExporter::operator()(Object *ob)
 {
 
   closeLibrary();
 }
 
 void GeometryExporter::operator()(Object *ob)
 {
-  bool use_instantiation = this->export_settings->use_object_instantiation;
+  bool use_instantiation = this->export_settings.get_use_object_instantiation();
   Mesh *me = bc_get_mesh_copy(blender_context,
                               ob,
   Mesh *me = bc_get_mesh_copy(blender_context,
                               ob,
-                              this->export_settings->export_mesh_type,
-                              this->export_settings->apply_modifiers,
-                              this->export_settings->triangulate);
+                              this->export_settings.get_export_mesh_type(),
+                              this->export_settings.get_apply_modifiers(),
+                              this->export_settings.get_triangulate());
 
   std::string geom_id = get_geometry_id(ob, use_instantiation);
   std::vector<Normal> nor;
 
   std::string geom_id = get_geometry_id(ob, use_instantiation);
   std::vector<Normal> nor;
@@ -128,7 +129,7 @@ void GeometryExporter::operator()(Object *ob)
 
   closeGeometry();
 
 
   closeGeometry();
 
-  if (this->export_settings->include_shapekeys) {
+  if (this->export_settings.get_include_shapekeys()) {
     Key *key = BKE_key_from_object(ob);
     if (key) {
       KeyBlock *kb = (KeyBlock *)key->block.first;
     Key *key = BKE_key_from_object(ob);
     if (key) {
       KeyBlock *kb = (KeyBlock *)key->block.first;
@@ -380,14 +381,14 @@ void GeometryExporter::create_mesh_primitive_list(short material_index,
   int active_uv_index = CustomData_get_active_layer_index(&me->ldata, CD_MLOOPUV);
   for (int i = 0; i < num_layers; i++) {
     int layer_index = CustomData_get_layer_index_n(&me->ldata, CD_MLOOPUV, i);
   int active_uv_index = CustomData_get_active_layer_index(&me->ldata, CD_MLOOPUV);
   for (int i = 0; i < num_layers; i++) {
     int layer_index = CustomData_get_layer_index_n(&me->ldata, CD_MLOOPUV, i);
-    if (!this->export_settings->active_uv_only || layer_index == active_uv_index) {
+    if (!this->export_settings.get_active_uv_only() || layer_index == active_uv_index) {
 
       // char *name = CustomData_get_layer_name(&me->ldata, CD_MLOOPUV, i);
       COLLADASW::Input texcoord_input(
           COLLADASW::InputSemantic::TEXCOORD,
 
       // char *name = CustomData_get_layer_name(&me->ldata, CD_MLOOPUV, i);
       COLLADASW::Input texcoord_input(
           COLLADASW::InputSemantic::TEXCOORD,
-          makeUrl(makeTexcoordSourceId(geom_id, i, this->export_settings->active_uv_only)),
+          makeUrl(makeTexcoordSourceId(geom_id, i, this->export_settings.get_active_uv_only())),
           2,  // this is only until we have optimized UV sets
           2,  // this is only until we have optimized UV sets
-          (this->export_settings->active_uv_only) ? 0 : layer_index - 1 /* set (0,1,2,...) */
+          (this->export_settings.get_active_uv_only()) ? 0 : layer_index - 1 /* set (0,1,2,...) */
       );
       til.push_back(texcoord_input);
     }
       );
       til.push_back(texcoord_input);
     }
@@ -466,7 +467,14 @@ void GeometryExporter::createVertsSource(std::string geom_id, Mesh *me)
   /* appends data to <float_array> */
   int i = 0;
   for (i = 0; i < totverts; i++) {
   /* appends data to <float_array> */
   int i = 0;
   for (i = 0; i < totverts; i++) {
-    source.appendValues(verts[i].co[0], verts[i].co[1], verts[i].co[2]);
+    Vector co;
+    if (export_settings.get_apply_global_orientation()) {
+      bc_add_global_transform(co, verts[i].co, export_settings.get_global_transform());
+    }
+    else {
+      copy_v3_v3(co, verts[i].co);
+    }
+    source.appendValues(co[0], co[1], co[2]);
   }
 
   source.finish();
   }
 
   source.finish();
@@ -547,12 +555,12 @@ void GeometryExporter::createTexcoordsSource(std::string geom_id, Mesh *me)
   int active_uv_index = CustomData_get_active_layer_index(&me->ldata, CD_MLOOPUV);
   for (int a = 0; a < num_layers; a++) {
     int layer_index = CustomData_get_layer_index_n(&me->ldata, CD_MLOOPUV, a);
   int active_uv_index = CustomData_get_active_layer_index(&me->ldata, CD_MLOOPUV);
   for (int a = 0; a < num_layers; a++) {
     int layer_index = CustomData_get_layer_index_n(&me->ldata, CD_MLOOPUV, a);
-    if (!this->export_settings->active_uv_only || layer_index == active_uv_index) {
+    if (!this->export_settings.get_active_uv_only() || layer_index == active_uv_index) {
       MLoopUV *mloops = (MLoopUV *)CustomData_get_layer_n(&me->ldata, CD_MLOOPUV, a);
 
       COLLADASW::FloatSourceF source(mSW);
       std::string layer_id = makeTexcoordSourceId(
       MLoopUV *mloops = (MLoopUV *)CustomData_get_layer_n(&me->ldata, CD_MLOOPUV, a);
 
       COLLADASW::FloatSourceF source(mSW);
       std::string layer_id = makeTexcoordSourceId(
-          geom_id, a, this->export_settings->active_uv_only);
+          geom_id, a, this->export_settings.get_active_uv_only());
       source.setId(layer_id);
       source.setArrayId(layer_id + ARRAY_ID_SUFFIX);
 
       source.setId(layer_id);
       source.setArrayId(layer_id + ARRAY_ID_SUFFIX);
 
@@ -606,7 +614,12 @@ void GeometryExporter::createNormalsSource(std::string geom_id, Mesh *me, std::v
   std::vector<Normal>::iterator it;
   for (it = nor.begin(); it != nor.end(); it++) {
     Normal &n = *it;
   std::vector<Normal>::iterator it;
   for (it = nor.begin(); it != nor.end(); it++) {
     Normal &n = *it;
-    source.appendValues(n.x, n.y, n.z);
+
+    Vector no{n.x, n.y, n.z};
+    if (export_settings.get_apply_global_orientation()) {
+      bc_add_global_transform(no, export_settings.get_global_transform());
+    }
+    source.appendValues(no[0], no[1], no[2]);
   }
 
   source.finish();
   }
 
   source.finish();
index 976059b09252109fecb9edb06b2d22b59faa85ad..7262784db8219b1acae3a1b1a835c5434f70ae56 100644 (file)
@@ -41,8 +41,6 @@
 
 struct Depsgraph;
 
 
 struct Depsgraph;
 
-extern Object *bc_get_highest_selected_ancestor_or_self(Object *ob);
-
 class Normal {
  public:
   float x;
 class Normal {
  public:
   float x;
@@ -66,7 +64,7 @@ class GeometryExporter : COLLADASW::LibraryGeometries {
   /* TODO: optimize UV sets by making indexed list with duplicates removed */
   GeometryExporter(BlenderContext &blender_context,
                    COLLADASW::StreamWriter *sw,
   /* TODO: optimize UV sets by making indexed list with duplicates removed */
   GeometryExporter(BlenderContext &blender_context,
                    COLLADASW::StreamWriter *sw,
-                   const ExportSettings *export_settings)
+                   BCExportSettings &export_settings)
       : COLLADASW::LibraryGeometries(sw),
         blender_context(blender_context),
         export_settings(export_settings)
       : COLLADASW::LibraryGeometries(sw),
         blender_context(blender_context),
         export_settings(export_settings)
@@ -122,7 +120,7 @@ class GeometryExporter : COLLADASW::LibraryGeometries {
  private:
   std::set<std::string> exportedGeometry;
   BlenderContext &blender_context;
  private:
   std::set<std::string> exportedGeometry;
   BlenderContext &blender_context;
-  const ExportSettings *export_settings;
+  BCExportSettings &export_settings;
 
   Mesh *get_mesh(Scene *sce, Object *ob, int apply_modifiers);
 };
 
   Mesh *get_mesh(Scene *sce, Object *ob, int apply_modifiers);
 };
index b606799efde3276c9f81d0c31679f5da6e718768..71201c8a55cdf7e64be404db0c1991c893681d62 100644 (file)
@@ -43,7 +43,7 @@ extern "C" {
 #include "MaterialExporter.h"
 
 ImagesExporter::ImagesExporter(COLLADASW::StreamWriter *sw,
 #include "MaterialExporter.h"
 
 ImagesExporter::ImagesExporter(COLLADASW::StreamWriter *sw,
-                               const ExportSettings *export_settings,
+                               BCExportSettings &export_settings,
                                KeyImageMap &key_image_map)
     : COLLADASW::LibraryImages(sw), export_settings(export_settings), key_image_map(key_image_map)
 {
                                KeyImageMap &key_image_map)
     : COLLADASW::LibraryImages(sw), export_settings(export_settings), key_image_map(key_image_map)
 {
@@ -76,7 +76,7 @@ void ImagesExporter::export_UV_Image(Image *image, bool use_copies)
   char export_file[FILE_MAX];
 
   /* Destination folder for exported assets */
   char export_file[FILE_MAX];
 
   /* Destination folder for exported assets */
-  BLI_split_dir_part(this->export_settings->filepath, export_dir, sizeof(export_dir));
+  BLI_split_dir_part(this->export_settings.get_filepath(), export_dir, sizeof(export_dir));
 
   if (is_generated || is_dirty || use_copies || is_packed) {
 
 
   if (is_generated || is_dirty || use_copies || is_packed) {
 
@@ -152,7 +152,7 @@ void ImagesExporter::export_UV_Image(Image *image, bool use_copies)
 
 void ImagesExporter::exportImages(Scene *sce)
 {
 
 void ImagesExporter::exportImages(Scene *sce)
 {
-  bool use_texture_copies = this->export_settings->use_texture_copies;
+  bool use_texture_copies = this->export_settings.get_use_texture_copies();
   openLibrary();
 
   KeyImageMap::iterator iter;
   openLibrary();
 
   KeyImageMap::iterator iter;
index ac0c1d5c976e183395294f76db33735e4be47c14..b72d2709382184bc8a2b0f7371783245ae898f43 100644 (file)
 class ImagesExporter : COLLADASW::LibraryImages {
  public:
   ImagesExporter(COLLADASW::StreamWriter *sw,
 class ImagesExporter : COLLADASW::LibraryImages {
  public:
   ImagesExporter(COLLADASW::StreamWriter *sw,
-                 const ExportSettings *export_settings,
+                 BCExportSettings &export_settings,
                  KeyImageMap &key_image_map);
   void exportImages(Scene *sce);
 
  private:
                  KeyImageMap &key_image_map);
   void exportImages(Scene *sce);
 
  private:
-  const ExportSettings *export_settings;
+  BCExportSettings &export_settings;
   KeyImageMap &key_image_map;
   void export_UV_Image(Image *image, bool use_texture_copies);
 };
   KeyImageMap &key_image_map;
   void export_UV_Image(Image *image, bool use_texture_copies);
 };
index 39721b2eb3cba6759b11758c8e07d58ad3a82128..463981ceefa97f02c5c1010375d35b49c6eb53b5 100644 (file)
@@ -41,7 +41,7 @@ void forEachLightObjectInExportSet(Scene *sce, Functor &f, LinkNode *export_set)
   }
 }
 
   }
 }
 
-LightsExporter::LightsExporter(COLLADASW::StreamWriter *sw, const ExportSettings *export_settings)
+LightsExporter::LightsExporter(COLLADASW::StreamWriter *sw, BCExportSettings &export_settings)
     : COLLADASW::LibraryLights(sw), export_settings(export_settings)
 {
 }
     : COLLADASW::LibraryLights(sw), export_settings(export_settings)
 {
 }
@@ -50,7 +50,7 @@ void LightsExporter::exportLights(Scene *sce)
 {
   openLibrary();
 
 {
   openLibrary();
 
-  forEachLightObjectInExportSet(sce, *this, this->export_settings->export_set);
+  forEachLightObjectInExportSet(sce, *this, this->export_settings.get_export_set());
 
   closeLibrary();
 }
 
   closeLibrary();
 }
index fc468f1f4a3ae1f102c2427940be1d536278a012..045ccfe1ce8eb7df9fe1afb51aecc35bf50e0b7f 100644 (file)
 
 class LightsExporter : COLLADASW::LibraryLights {
  public:
 
 class LightsExporter : COLLADASW::LibraryLights {
  public:
-  LightsExporter(COLLADASW::StreamWriter *sw, const ExportSettings *export_settings);
+  LightsExporter(COLLADASW::StreamWriter *sw, BCExportSettings &export_settings);
   void exportLights(Scene *sce);
   void operator()(Object *ob);
 
  private:
   bool exportBlenderProfile(COLLADASW::Light &cla, Light *la);
   void exportLights(Scene *sce);
   void operator()(Object *ob);
 
  private:
   bool exportBlenderProfile(COLLADASW::Light &cla, Light *la);
-  const ExportSettings *export_settings;
+  BCExportSettings &export_settings;
 };
 
 #endif
 };
 
 #endif
index e071712b20d589e5b7cef3bb3c4dc751919dff48..8bf7a220c4a66324c622e49feaf6ba1cf48f8c2d 100644 (file)
@@ -23,7 +23,7 @@
 #include "collada_internal.h"
 
 MaterialsExporter::MaterialsExporter(COLLADASW::StreamWriter *sw,
 #include "collada_internal.h"
 
 MaterialsExporter::MaterialsExporter(COLLADASW::StreamWriter *sw,
-                                     const ExportSettings *export_settings)
+                                     BCExportSettings &export_settings)
     : COLLADASW::LibraryMaterials(sw), export_settings(export_settings)
 {
   /* pass */
     : COLLADASW::LibraryMaterials(sw), export_settings(export_settings)
 {
   /* pass */
@@ -36,7 +36,7 @@ void MaterialsExporter::exportMaterials(Scene *sce)
 
     MaterialFunctor mf;
     mf.forEachMaterialInExportSet<MaterialsExporter>(
 
     MaterialFunctor mf;
     mf.forEachMaterialInExportSet<MaterialsExporter>(
-        sce, *this, this->export_settings->export_set);
+        sce, *this, this->export_settings.get_export_set());
 
     closeLibrary();
   }
 
     closeLibrary();
   }
@@ -45,7 +45,7 @@ void MaterialsExporter::exportMaterials(Scene *sce)
 bool MaterialsExporter::hasMaterials(Scene *sce)
 {
   LinkNode *node;
 bool MaterialsExporter::hasMaterials(Scene *sce)
 {
   LinkNode *node;
-  for (node = this->export_settings->export_set; node; node = node->next) {
+  for (node = this->export_settings.get_export_set(); node; node = node->next) {
     Object *ob = (Object *)node->link;
     int a;
     for (a = 0; a < ob->totcol; a++) {
     Object *ob = (Object *)node->link;
     int a;
     for (a = 0; a < ob->totcol; a++) {
index d47a001596db5597b0759754ca58de9b6475e1e5..027fba1f8eff2228252945f7729bfe97962b1c1b 100644 (file)
@@ -41,13 +41,13 @@ extern "C" {
 
 class MaterialsExporter : COLLADASW::LibraryMaterials {
  public:
 
 class MaterialsExporter : COLLADASW::LibraryMaterials {
  public:
-  MaterialsExporter(COLLADASW::StreamWriter *sw, const ExportSettings *export_settings);
+  MaterialsExporter(COLLADASW::StreamWriter *sw, BCExportSettings &export_settings);
   void exportMaterials(Scene *sce);
   void operator()(Material *ma, Object *ob);
 
  private:
   bool hasMaterials(Scene *sce);
   void exportMaterials(Scene *sce);
   void operator()(Material *ma, Object *ob);
 
  private:
   bool hasMaterials(Scene *sce);
-  const ExportSettings *export_settings;
+  BCExportSettings &export_settings;
 };
 
 // used in forEachMaterialInScene
 };
 
 // used in forEachMaterialInScene
index 8017790572f6c3f194e192c6d2384833e2c13172..22b2eed79d394e6f98283f93ff617752c78d8151 100644 (file)
@@ -23,10 +23,12 @@ extern "C" {
 #include "BKE_collection.h"
 #include "BKE_object.h"
 #include "BLI_listbase.h"
 #include "BKE_collection.h"
 #include "BKE_object.h"
 #include "BLI_listbase.h"
+#include "BKE_library.h"
 }
 
 #include "SceneExporter.h"
 #include "collada_utils.h"
 }
 
 #include "SceneExporter.h"
 #include "collada_utils.h"
+#include "BCSampleData.h"
 
 void SceneExporter::exportScene()
 {
 
 void SceneExporter::exportScene()
 {
@@ -43,18 +45,18 @@ void SceneExporter::exportScene()
 void SceneExporter::exportHierarchy()
 {
   LinkNode *node;
 void SceneExporter::exportHierarchy()
 {
   LinkNode *node;
-  std::vector<Object *> base_objects;
+  ColladaBaseNodes base_objects;
 
   /* Ensure all objects in the export_set are marked */
 
   /* Ensure all objects in the export_set are marked */
-  for (node = this->export_settings->export_set; node; node = node->next) {
+  for (node = this->export_settings.get_export_set(); node; node = node->next) {
     Object *ob = (Object *)node->link;
     ob->id.tag |= LIB_TAG_DOIT;
   }
 
   /* Now find all exportable base objects (highest in export hierarchy) */
     Object *ob = (Object *)node->link;
     ob->id.tag |= LIB_TAG_DOIT;
   }
 
   /* Now find all exportable base objects (highest in export hierarchy) */
-  for (node = this->export_settings->export_set; node; node = node->next) {
+  for (node = this->export_settings.get_export_set(); node; node = node->next) {
     Object *ob = (Object *)node->link;
     Object *ob = (Object *)node->link;
-    if (bc_is_base_node(this->export_settings->export_set, ob)) {
+    if (this->export_settings.is_export_root(ob)) {
       switch (ob->type) {
         case OB_MESH:
         case OB_CAMERA:
       switch (ob->type) {
         case OB_MESH:
         case OB_CAMERA:
@@ -62,7 +64,7 @@ void SceneExporter::exportHierarchy()
         case OB_EMPTY:
         case OB_GPENCIL:
         case OB_ARMATURE:
         case OB_EMPTY:
         case OB_GPENCIL:
         case OB_ARMATURE:
-          base_objects.push_back(ob);
+          base_objects.add(ob);
           break;
       }
     }
           break;
       }
     }
@@ -70,10 +72,10 @@ void SceneExporter::exportHierarchy()
 
   /* And now export the base objects: */
   for (int index = 0; index < base_objects.size(); index++) {
 
   /* And now export the base objects: */
   for (int index = 0; index < base_objects.size(); index++) {
-    Object *ob = base_objects[index];
+    Object *ob = base_objects.get(index);
+    writeNode(ob);
     if (bc_is_marked(ob)) {
       bc_remove_mark(ob);
     if (bc_is_marked(ob)) {
       bc_remove_mark(ob);
-      writeNodes(ob);
     }
   }
 }
     }
   }
 }
@@ -88,30 +90,31 @@ void SceneExporter::writeNodeList(std::vector<Object *> &child_objects, Object *
    * the hidden elements are exported as well. */
   for (int i = 0; i < child_objects.size(); ++i) {
     Object *child = child_objects[i];
    * the hidden elements are exported as well. */
   for (int i = 0; i < child_objects.size(); ++i) {
     Object *child = child_objects[i];
+    writeNode(child);
     if (bc_is_marked(child)) {
       bc_remove_mark(child);
     if (bc_is_marked(child)) {
       bc_remove_mark(child);
-      writeNodes(child);
     }
   }
 }
 
     }
   }
 }
 
-void SceneExporter::writeNodes(Object *ob)
+void SceneExporter::writeNode(Object *ob)
 {
   ViewLayer *view_layer = blender_context.get_view_layer();
 
   std::vector<Object *> child_objects;
   bc_get_children(child_objects, ob, view_layer);
 {
   ViewLayer *view_layer = blender_context.get_view_layer();
 
   std::vector<Object *> child_objects;
   bc_get_children(child_objects, ob, view_layer);
-  bool can_export = bc_is_in_Export_set(this->export_settings->export_set, ob, view_layer);
+  bool can_export = bc_is_in_Export_set(this->export_settings.get_export_set(), ob, view_layer);
 
   /* Add associated armature first if available */
   bool armature_exported = false;
   Object *ob_arm = bc_get_assigned_armature(ob);
 
   if (ob_arm != NULL) {
 
   /* Add associated armature first if available */
   bool armature_exported = false;
   Object *ob_arm = bc_get_assigned_armature(ob);
 
   if (ob_arm != NULL) {
-    armature_exported = bc_is_in_Export_set(this->export_settings->export_set, ob_arm, view_layer);
+    armature_exported = bc_is_in_Export_set(
+        this->export_settings.get_export_set(), ob_arm, view_layer);
     if (armature_exported && bc_is_marked(ob_arm)) {
     if (armature_exported && bc_is_marked(ob_arm)) {
+      writeNode(ob_arm);
       bc_remove_mark(ob_arm);
       bc_remove_mark(ob_arm);
-      writeNodes(ob_arm);
       armature_exported = true;
     }
   }
       armature_exported = true;
     }
   }
@@ -123,16 +126,12 @@ void SceneExporter::writeNodes(Object *ob)
     colladaNode.setType(COLLADASW::Node::NODE);
 
     colladaNode.start();
     colladaNode.setType(COLLADASW::Node::NODE);
 
     colladaNode.start();
-
     if (ob->type == OB_MESH && armature_exported) {
       /* for skinned mesh we write obmat in <bind_shape_matrix> */
       TransformWriter::add_node_transform_identity(colladaNode);
     }
     else {
     if (ob->type == OB_MESH && armature_exported) {
       /* for skinned mesh we write obmat in <bind_shape_matrix> */
       TransformWriter::add_node_transform_identity(colladaNode);
     }
     else {
-      TransformWriter::add_node_transform_ob(colladaNode,
-                                             ob,
-                                             this->export_settings->export_transformation_type,
-                                             this->export_settings->limit_precision);
+      TransformWriter::add_node_transform_ob(colladaNode, ob, this->export_settings);
     }
 
     /* <instance_geometry> */
     }
 
     /* <instance_geometry> */
@@ -143,12 +142,12 @@ void SceneExporter::writeNodes(Object *ob)
       }
       if (!instance_controller_created) {
         COLLADASW::InstanceGeometry instGeom(mSW);
       }
       if (!instance_controller_created) {
         COLLADASW::InstanceGeometry instGeom(mSW);
-        instGeom.setUrl(
-            COLLADASW::URI(COLLADABU::Utils::EMPTY_STRING,
-                           get_geometry_id(ob, this->export_settings->use_object_instantiation)));
+        instGeom.setUrl(COLLADASW::URI(
+            COLLADABU::Utils::EMPTY_STRING,
+            get_geometry_id(ob, this->export_settings.get_use_object_instantiation())));
         instGeom.setName(encode_xml(id_name(ob)));
         InstanceWriter::add_material_bindings(
         instGeom.setName(encode_xml(id_name(ob)));
         InstanceWriter::add_material_bindings(
-            instGeom.getBindMaterial(), ob, this->export_settings->active_uv_only);
+            instGeom.getBindMaterial(), ob, this->export_settings.get_active_uv_only());
         instGeom.add();
       }
     }
         instGeom.add();
       }
     }
@@ -232,7 +231,11 @@ void SceneExporter::writeNodes(Object *ob)
         }
       }
     }
         }
       }
     }
+    bc_remove_mark(ob);
     writeNodeList(child_objects, ob);
     colladaNode.end();
   }
     writeNodeList(child_objects, ob);
     colladaNode.end();
   }
+  else {
+    writeNodeList(child_objects, ob);
+  }
 }
 }
index dc0a0c3e2adb721a874bd7746c41ef7261f930cc..a61d045ad5d9f1b01e5c7e746f11adddd1731a93 100644 (file)
@@ -82,9 +82,10 @@ extern "C" {
 #include "COLLADASWBaseInputElement.h"
 
 #include "ArmatureExporter.h"
 #include "COLLADASWBaseInputElement.h"
 
 #include "ArmatureExporter.h"
-
 #include "ExportSettings.h"
 
 #include "ExportSettings.h"
 
+extern void bc_get_children(std::vector<Object *> &child_set, Object *ob, ViewLayer *view_layer);
+
 class SceneExporter : COLLADASW::LibraryVisualScenes,
                       protected TransformWriter,
                       protected InstanceWriter {
 class SceneExporter : COLLADASW::LibraryVisualScenes,
                       protected TransformWriter,
                       protected InstanceWriter {
@@ -92,7 +93,7 @@ class SceneExporter : COLLADASW::LibraryVisualScenes,
   SceneExporter(BlenderContext &blender_context,
                 COLLADASW::StreamWriter *sw,
                 ArmatureExporter *arm,
   SceneExporter(BlenderContext &blender_context,
                 COLLADASW::StreamWriter *sw,
                 ArmatureExporter *arm,
-                const ExportSettings *export_settings)
+                BCExportSettings &export_settings)
       : COLLADASW::LibraryVisualScenes(sw),
         blender_context(blender_context),
         arm_exporter(arm),
       : COLLADASW::LibraryVisualScenes(sw),
         blender_context(blender_context),
         arm_exporter(arm),
@@ -106,11 +107,11 @@ class SceneExporter : COLLADASW::LibraryVisualScenes,
   BlenderContext &blender_context;
   friend class ArmatureExporter;
   ArmatureExporter *arm_exporter;
   BlenderContext &blender_context;
   friend class ArmatureExporter;
   ArmatureExporter *arm_exporter;
-  const ExportSettings *export_settings;
+  BCExportSettings &export_settings;
 
   void exportHierarchy();
   void writeNodeList(std::vector<Object *> &child_objects, Object *parent);
 
   void exportHierarchy();
   void writeNodeList(std::vector<Object *> &child_objects, Object *parent);
-  void writeNodes(Object *ob);
+  void writeNode(Object *ob);
 };
 
 #endif
 };
 
 #endif
index 2ab9105976e5a37011b839b26e1ca01052cfc5b4..0cbb8c65cf1a5c63bbad66641ce096233df91d4f 100644 (file)
 void TransformWriter::add_node_transform(COLLADASW::Node &node,
                                          float mat[4][4],
                                          float parent_mat[4][4],
 void TransformWriter::add_node_transform(COLLADASW::Node &node,
                                          float mat[4][4],
                                          float parent_mat[4][4],
-                                         bool limit_precision)
+                                         BCExportSettings &export_settings
+       )
 {
 {
+  // bool limit_precision = export_settings.limit_precision;
   float loc[3], rot[3], scale[3];
   float local[4][4];
 
   float loc[3], rot[3], scale[3];
   float local[4][4];
 
@@ -42,67 +44,48 @@ void TransformWriter::add_node_transform(COLLADASW::Node &node,
     copy_m4_m4(local, mat);
   }
 
     copy_m4_m4(local, mat);
   }
 
+  if (export_settings.get_apply_global_orientation()) {
+    bc_apply_global_transform(local, export_settings.get_global_transform());
+  }
+
   double dmat[4][4];
   UnitConverter *converter = new UnitConverter();
   converter->mat4_to_dae_double(dmat, local);
   delete converter;
 
   double dmat[4][4];
   UnitConverter *converter = new UnitConverter();
   converter->mat4_to_dae_double(dmat, local);
   delete converter;
 
-  bc_decompose(local, loc, rot, NULL, scale);
-
   if (node.getType() == COLLADASW::Node::JOINT) {
     // XXX Why are joints handled differently ?
   if (node.getType() == COLLADASW::Node::JOINT) {
     // XXX Why are joints handled differently ?
+       // GC: I believe this is a mistake. Here we might want to 
+       // export according to how the transformation type
+       // is set, see add_node_transform_ob()
     node.addMatrix("transform", dmat);
   }
   else {
     node.addMatrix("transform", dmat);
   }
   else {
+    bc_decompose(local, loc, rot, NULL, scale);
     add_transform(node, loc, rot, scale);
   }
 }
 
 void TransformWriter::add_node_transform_ob(COLLADASW::Node &node,
                                             Object *ob,
     add_transform(node, loc, rot, scale);
   }
 }
 
 void TransformWriter::add_node_transform_ob(COLLADASW::Node &node,
                                             Object *ob,
-                                            BC_export_transformation_type transformation_type,
-                                            bool limit_precision)
+                                            BCExportSettings &export_settings)
 {
 {
-#if 0
-  float rot[3], loc[3], scale[3];
-
-  if (ob->parent) {
-    float C[4][4], tmat[4][4], imat[4][4], mat[4][4];
-
-    // factor out scale from obmat
-
-    copy_v3_v3(scale, ob->scale);
-
-    ob->scale[0] = ob->scale[1] = ob->scale[2] = 1.0f;
-    BKE_object_to_mat4(ob, C);
-    copy_v3_v3(ob->scale, scale);
-
-    mul_m4_series(tmat, ob->parent->obmat, ob->parentinv, C);
-
-    // calculate local mat
-
-    invert_m4_m4(imat, ob->parent->obmat);
-    mul_m4_m4m4(mat, imat, tmat);
+  BC_export_transformation_type transformation_type =
+      export_settings.get_export_transformation_type();
+  bool limit_precision = export_settings.get_limit_precision();
 
 
-    // done
+  /* Export the local Matrix (relative to the object parent,
+   * be it an object, bone or vertex(-tices)). */
+  Matrix f_obmat;
+  BKE_object_matrix_local_get(ob, f_obmat);
 
 
-    mat4_to_eul(rot, mat);
-    copy_v3_v3(loc, mat[3]);
+  if (export_settings.get_apply_global_orientation()) {
+    bc_apply_global_transform(f_obmat, export_settings.get_global_transform());
   }
   else {
   }
   else {
-    copy_v3_v3(loc, ob->loc);
-    copy_v3_v3(rot, ob->rot);
-    copy_v3_v3(scale, ob->scale);
+    bc_add_global_transform(f_obmat, export_settings.get_global_transform());
   }
 
   }
 
-  add_transform(node, loc, rot, scale);
-#endif
-
-  /* Export the local Matrix (relative to the object parent,
-   * be it an object, bone or vertex(-tices)). */
-  float f_obmat[4][4];
-  BKE_object_matrix_local_get(ob, f_obmat);
-
   switch (transformation_type) {
     case BC_TRANSFORMATION_TYPE_MATRIX: {
       UnitConverter converter;
   switch (transformation_type) {
     case BC_TRANSFORMATION_TYPE_MATRIX: {
       UnitConverter converter;
index 22ba0716cfe78cf9e94739273ebf292f8f9ee872..63f563ad58ea2ca50112ad4cd05ee8b41cfb7ae9 100644 (file)
@@ -34,12 +34,9 @@ class TransformWriter {
   void add_node_transform(COLLADASW::Node &node,
                           float mat[4][4],
                           float parent_mat[4][4],
   void add_node_transform(COLLADASW::Node &node,
                           float mat[4][4],
                           float parent_mat[4][4],
-                          bool limit_precision = false);
+                          BCExportSettings &export_settings);
 
 
-  void add_node_transform_ob(COLLADASW::Node &node,
-                             Object *ob,
-                             BC_export_transformation_type transformation_type,
-                             bool limit_precision = false);
+  void add_node_transform_ob(COLLADASW::Node &node, Object *ob, BCExportSettings &export_settings);
 
   void add_node_transform_identity(COLLADASW::Node &node);
 
 
   void add_node_transform_identity(COLLADASW::Node &node);
 
index c0e3ab2ca4754d32788d9ec10c3415109b03b92b..9e8896c2b9feba77d58bbde1c95d61ba1de0f118 100644 (file)
@@ -60,6 +60,7 @@ extern "C" {
 #include "ED_armature.h"
 #include "ED_screen.h"
 #include "ED_node.h"
 #include "ED_armature.h"
 #include "ED_screen.h"
 #include "ED_node.h"
+#include "ED_object.h"
 
 #include "MEM_guardedalloc.h"
 
 
 #include "MEM_guardedalloc.h"
 
@@ -104,26 +105,6 @@ int bc_test_parent_loop(Object *par, Object *ob)
   return bc_test_parent_loop(par->parent, ob);
 }
 
   return bc_test_parent_loop(par->parent, ob);
 }
 
-void bc_get_children(std::vector<Object *> &child_set, Object *ob, ViewLayer *view_layer)
-{
-  Base *base;
-  for (base = (Base *)view_layer->object_bases.first; base; base = base->next) {
-    Object *cob = base->object;
-    if (cob->parent == ob) {
-      switch (ob->type) {
-        case OB_MESH:
-        case OB_CAMERA:
-        case OB_LAMP:
-        case OB_EMPTY:
-        case OB_ARMATURE:
-          child_set.push_back(cob);
-        default:
-          break;
-      }
-    }
-  }
-}
-
 bool bc_validateConstraints(bConstraint *con)
 {
   const bConstraintTypeInfo *cti = BKE_constraint_typeinfo_get(con);
 bool bc_validateConstraints(bConstraint *con)
 {
   const bConstraintTypeInfo *cti = BKE_constraint_typeinfo_get(con);
@@ -146,43 +127,19 @@ bool bc_validateConstraints(bConstraint *con)
   return true;
 }
 
   return true;
 }
 
-/* a shortened version of parent_set_exec()
- * if is_parent_space is true then ob->obmat will be multiplied by par->obmat before parenting */
-int bc_set_parent(Object *ob, Object *par, bContext *C, bool is_parent_space)
+bool bc_set_parent(Object *ob, Object *par, bContext *C, bool is_parent_space)
 {
 {
-  Object workob;
-  Depsgraph *depsgraph = CTX_data_depsgraph(C);
-  Scene *sce = CTX_data_scene(C);
-
-  if (!par || bc_test_parent_loop(par, ob))
-    return false;
-
-  ob->parent = par;
-  ob->partype = PAROBJECT;
+  Scene *scene = CTX_data_scene(C);
+  int partype = PAR_OBJECT;
+  const bool xmirror = false;
+  const bool keep_transform = false;
 
 
-  ob->parsubstr[0] = 0;
-
-  if (is_parent_space) {
-    float mat[4][4];
-    /* calc par->obmat */
-    BKE_object_where_is_calc(depsgraph, sce, par);
-
-    /* move child obmat into world space */
-    mul_m4_m4m4(mat, par->obmat, ob->obmat);
-    copy_m4_m4(ob->obmat, mat);
+  if (par && is_parent_space) {
+    mul_m4_m4m4(ob->obmat, par->obmat, ob->obmat);
   }
 
   }
 
-  /* apply child obmat (i.e. decompose it into rot/loc/size) */
-  BKE_object_apply_mat4(ob, ob->obmat, 0, 0);
-
-  /* compute parentinv */
-  BKE_object_workob_calc_parent(depsgraph, sce, ob, &workob);
-  invert_m4_m4(ob->parentinv, workob.obmat);
-
-  DEG_id_tag_update(&ob->id, ID_RECALC_TRANSFORM | ID_RECALC_GEOMETRY);
-  DEG_id_tag_update(&par->id, ID_RECALC_TRANSFORM);
-
-  return true;
+  bool ok = ED_object_parent_set(NULL, C, scene, ob, par, partype, xmirror, keep_transform, NULL);
+  return ok;
 }
 
 std::vector<bAction *> bc_getSceneActions(const bContext *C, Object *ob, bool all_actions)
 }
 
 std::vector<bAction *> bc_getSceneActions(const bContext *C, Object *ob, bool all_actions)
@@ -309,49 +266,6 @@ Object *bc_get_assigned_armature(Object *ob)
   return ob_arm;
 }
 
   return ob_arm;
 }
 
-/**
- * Returns the highest selected ancestor
- * returns NULL if no ancestor is selected
- * IMPORTANT: This function expects that all exported objects have set:
- * ob->id.tag & LIB_TAG_DOIT
- */
-Object *bc_get_highest_selected_ancestor_or_self(LinkNode *export_set, Object *ob)
-
-{
-  Object *ancestor = ob;
-  while (ob->parent && bc_is_marked(ob->parent)) {
-    ob = ob->parent;
-    ancestor = ob;
-  }
-  return ancestor;
-}
-
-bool bc_is_base_node(LinkNode *export_set, Object *ob)
-{
-  Object *root = bc_get_highest_selected_ancestor_or_self(export_set, ob);
-  return (root == ob);
-}
-
-bool bc_is_in_Export_set(LinkNode *export_set, Object *ob, ViewLayer *view_layer)
-{
-  bool to_export = (BLI_linklist_index(export_set, ob) != -1);
-
-  if (!to_export) {
-    /* Mark this object as to_export even if it is not in the
-     * export list, but it contains children to export. */
-
-    std::vector<Object *> children;
-    bc_get_children(children, ob, view_layer);
-    for (int i = 0; i < children.size(); i++) {
-      if (bc_is_in_Export_set(export_set, children[i], view_layer)) {
-        to_export = true;
-        break;
-      }
-    }
-  }
-  return to_export;
-}
-
 bool bc_has_object_type(LinkNode *export_set, short obtype)
 {
   LinkNode *node;
 bool bc_has_object_type(LinkNode *export_set, short obtype)
 {
   LinkNode *node;
@@ -366,21 +280,6 @@ bool bc_has_object_type(LinkNode *export_set, short obtype)
   return false;
 }
 
   return false;
 }
 
-int bc_is_marked(Object *ob)
-{
-  return ob && (ob->id.tag & LIB_TAG_DOIT);
-}
-
-void bc_remove_mark(Object *ob)
-{
-  ob->id.tag &= ~LIB_TAG_DOIT;
-}
-
-void bc_set_mark(Object *ob)
-{
-  ob->id.tag |= LIB_TAG_DOIT;
-}
-
 /* Use bubble sort algorithm for sorting the export set */
 void bc_bubble_sort_by_Object_name(LinkNode *export_set)
 {
 /* Use bubble sort algorithm for sorting the export set */
 void bc_bubble_sort_by_Object_name(LinkNode *export_set)
 {
@@ -1040,13 +939,61 @@ bool bc_has_animations(Scene *sce, LinkNode *export_set)
   return false;
 }
 
   return false;
 }
 
+void bc_add_global_transform(Matrix &to_mat,
+                             const Matrix &from_mat,
+                             const BCMatrix &global_transform,
+                             const bool invert)
+{
+  copy_m4_m4(to_mat, from_mat);
+  bc_add_global_transform(to_mat, global_transform, invert);
+}
+
+void bc_add_global_transform(Vector &to_vec,
+                             const Vector &from_vec,
+                             const BCMatrix &global_transform,
+                             const bool invert)
+{
+  copy_v3_v3(to_vec, from_vec);
+  bc_add_global_transform(to_vec, global_transform, invert);
+}
+
+void bc_add_global_transform(Matrix &to_mat, const BCMatrix &global_transform, const bool invert)
+{
+  BCMatrix mat(to_mat);
+  mat.add_transform(global_transform, invert);
+  mat.get_matrix(to_mat);
+}
+
+void bc_add_global_transform(Vector &to_vec, const BCMatrix &global_transform, const bool invert)
+{
+  Matrix mat;
+  Vector from_vec;
+  copy_v3_v3(from_vec, to_vec);
+  global_transform.get_matrix(mat, false, 6, invert);
+  mul_v3_m4v3(to_vec, mat, from_vec);
+}
+
+void bc_apply_global_transform(Matrix &to_mat, const BCMatrix &global_transform, const bool invert)
+{
+  BCMatrix mat(to_mat);
+  mat.apply_transform(global_transform, invert);
+  mat.get_matrix(to_mat);
+}
+
+void bc_apply_global_transform(Vector &to_vec, const BCMatrix &global_transform, const bool invert)
+{
+  Matrix transform;
+  global_transform.get_matrix(transform);
+  mul_v3_m4v3(to_vec, transform, to_vec);
+}
+
 /**
  * Check if custom information about bind matrix exists and modify the from_mat
  * accordingly.
  *
  * Note: This is old style for Blender <= 2.78 only kept for compatibility
  */
 /**
  * Check if custom information about bind matrix exists and modify the from_mat
  * accordingly.
  *
  * Note: This is old style for Blender <= 2.78 only kept for compatibility
  */
-void bc_create_restpose_mat(const ExportSettings *export_settings,
+void bc_create_restpose_mat(BCExportSettings &export_settings,
                             Bone *bone,
                             float to_mat[4][4],
                             float from_mat[4][4],
                             Bone *bone,
                             float to_mat[4][4],
                             float from_mat[4][4],
@@ -1057,9 +1004,9 @@ void bc_create_restpose_mat(const ExportSettings *export_settings,
   float scale[3];
   static const float V0[3] = {0, 0, 0};
 
   float scale[3];
   static const float V0[3] = {0, 0, 0};
 
-  if (!has_custom_props(bone, export_settings->keep_bind_info, "restpose_loc") &&
-      !has_custom_props(bone, export_settings->keep_bind_info, "restpose_rot") &&
-      !has_custom_props(bone, export_settings->keep_bind_info, "restpose_scale")) {
+  if (!has_custom_props(bone, export_settings.get_keep_bind_info(), "restpose_loc") &&
+      !has_custom_props(bone, export_settings.get_keep_bind_info(), "restpose_rot") &&
+      !has_custom_props(bone, export_settings.get_keep_bind_info(), "restpose_scale")) {
     /* No need */
     copy_m4_m4(to_mat, from_mat);
     return;
     /* No need */
     copy_m4_m4(to_mat, from_mat);
     return;
@@ -1068,7 +1015,7 @@ void bc_create_restpose_mat(const ExportSettings *export_settings,
   bc_decompose(from_mat, loc, rot, NULL, scale);
   loc_eulO_size_to_mat4(to_mat, loc, rot, scale, 6);
 
   bc_decompose(from_mat, loc, rot, NULL, scale);
   loc_eulO_size_to_mat4(to_mat, loc, rot, scale, 6);
 
-  if (export_settings->keep_bind_info) {
+  if (export_settings.get_keep_bind_info()) {
     bc_get_property_vector(bone, "restpose_loc", loc, loc);
 
     if (use_local_space && bone->parent) {
     bc_get_property_vector(bone, "restpose_loc", loc, loc);
 
     if (use_local_space && bone->parent) {
@@ -1084,7 +1031,7 @@ void bc_create_restpose_mat(const ExportSettings *export_settings,
     }
   }
 
     }
   }
 
-  if (export_settings->keep_bind_info) {
+  if (export_settings.get_keep_bind_info()) {
     if (bc_get_IDProperty(bone, "restpose_rot_x"))
       rot[0] = DEG2RADF(bc_get_property(bone, "restpose_rot_x", 0));
     if (bc_get_IDProperty(bone, "restpose_rot_y"))
     if (bc_get_IDProperty(bone, "restpose_rot_x"))
       rot[0] = DEG2RADF(bc_get_property(bone, "restpose_rot_x", 0));
     if (bc_get_IDProperty(bone, "restpose_rot_y"))
@@ -1093,7 +1040,7 @@ void bc_create_restpose_mat(const ExportSettings *export_settings,
       rot[2] = DEG2RADF(bc_get_property(bone, "restpose_rot_z", 0));
   }
 
       rot[2] = DEG2RADF(bc_get_property(bone, "restpose_rot_z", 0));
   }
 
-  if (export_settings->keep_bind_info) {
+  if (export_settings.get_keep_bind_info()) {
     bc_get_property_vector(bone, "restpose_scale", scale, scale);
   }
 
     bc_get_property_vector(bone, "restpose_scale", scale, scale);
   }
 
index 522aeb1ad1e1997055c7cd4b60459429a54e97e4..810b905619369fb723ee205d09019a20fa6e76fc 100644 (file)
@@ -133,10 +133,9 @@ std::string bc_get_action_id(std::string action_name,
 extern float bc_get_float_value(const COLLADAFW::FloatOrDoubleArray &array, unsigned int index);
 extern int bc_test_parent_loop(Object *par, Object *ob);
 
 extern float bc_get_float_value(const COLLADAFW::FloatOrDoubleArray &array, unsigned int index);
 extern int bc_test_parent_loop(Object *par, Object *ob);
 
-extern void bc_get_children(std::vector<Object *> &child_set, Object *ob, ViewLayer *view_layer);
 extern bool bc_validateConstraints(bConstraint *con);
 
 extern bool bc_validateConstraints(bConstraint *con);
 
-extern int bc_set_parent(Object *ob, Object *par, bContext *C, bool is_parent_space = true);
+bool bc_set_parent(Object *ob, Object *par, bContext *C, bool is_parent_space = true);
 extern Object *bc_add_object(
     Main *bmain, Scene *scene, ViewLayer *view_layer, int type, const char *name);
 extern Mesh *bc_get_mesh_copy(BlenderContext &blender_context,
 extern Object *bc_add_object(
     Main *bmain, Scene *scene, ViewLayer *view_layer, int type, const char *name);
 extern Mesh *bc_get_mesh_copy(BlenderContext &blender_context,
@@ -146,15 +145,8 @@ extern Mesh *bc_get_mesh_copy(BlenderContext &blender_context,
                               bool triangulate);
 
 extern Object *bc_get_assigned_armature(Object *ob);
                               bool triangulate);
 
 extern Object *bc_get_assigned_armature(Object *ob);
-extern Object *bc_get_highest_selected_ancestor_or_self(LinkNode *export_set, Object *ob);
-extern bool bc_is_base_node(LinkNode *export_set, Object *ob);
-extern bool bc_is_in_Export_set(LinkNode *export_set, Object *ob, ViewLayer *view_layer);
 extern bool bc_has_object_type(LinkNode *export_set, short obtype);
 
 extern bool bc_has_object_type(LinkNode *export_set, short obtype);
 
-extern int bc_is_marked(Object *ob);
-extern void bc_remove_mark(Object *ob);
-extern void bc_set_mark(Object *ob);
-
 extern char *bc_CustomData_get_layer_name(const CustomData *data, int type, int n);
 extern char *bc_CustomData_get_active_layer_name(const CustomData *data, int type);
 
 extern char *bc_CustomData_get_layer_name(const CustomData *data, int type, int n);
 extern char *bc_CustomData_get_active_layer_name(const CustomData *data, int type);
 
@@ -238,11 +230,58 @@ extern bool bc_is_animated(BCMatrixSampleMap &values);
 extern bool bc_has_animations(Scene *sce, LinkNode *node);
 extern bool bc_has_animations(Object *ob);
 
 extern bool bc_has_animations(Scene *sce, LinkNode *node);
 extern bool bc_has_animations(Object *ob);
 
-extern void bc_create_restpose_mat(const ExportSettings *export_settings,
-                                   Bone *bone,
-                                   float to_mat[4][4],
-                                   float world[4][4],
-                                   bool use_local_space);
+extern void bc_add_global_transform(Matrix &to_mat,
+                                    const Matrix &from_mat,
+                                    const BCMatrix &global_transform,
+                                    const bool invert = false);
+extern void bc_add_global_transform(Vector &to_vec,
+                                    const Vector &from_vec,
+                                    const BCMatrix &global_transform,
+                                    const bool invert = false);
+extern void bc_add_global_transform(Vector &to_vec,
+                                    const BCMatrix &global_transform,
+                                    const bool invert = false);
+extern void bc_add_global_transform(Matrix &to_mat,
+                                    const BCMatrix &global_transform,
+                                    const bool invert = false);
+extern void bc_apply_global_transform(Matrix &to_mat,
+                                      const BCMatrix &global_transform,
+                                      const bool invert = false);
+extern void bc_apply_global_transform(Vector &to_vec,
+                                      const BCMatrix &global_transform,
+                                      const bool invert = false);
+extern void bc_create_restpose_mat(BCExportSettings &export_settings,
+                                          Bone *bone,
+                                          float to_mat[4][4],
+                                          float from_mat[4][4],
+                                          bool use_local_space);
+
+class ColladaBaseNodes {
+ private:
+  std::vector<Object *> base_objects;
+
+ public:
+  void add(Object *ob)
+  {
+    base_objects.push_back(ob);
+  }
+
+  bool contains(Object *ob)
+  {
+    std::vector<Object *>::iterator it = std::find(base_objects.begin(), base_objects.end(), ob);
+    return (it != base_objects.end());
+  }
+
+  int size()
+  {
+    return base_objects.size();
+  }
+
+  Object *get(int index)
+  {
+    return base_objects[index];
+  }
+};
 
 class BCPolygonNormalsIndices {
   std::vector<unsigned int> normal_indices;
 
 class BCPolygonNormalsIndices {
   std::vector<unsigned int> normal_indices;
@@ -293,7 +332,7 @@ class BoneExtended {
   bool has_roll();
   float get_roll();
 
   bool has_roll();
   float get_roll();
 
-  void set_tail(float *vec);
+  void set_tail(float vec[]);
   float *get_tail();
   bool has_tail();
 
   float *get_tail();
   bool has_tail();
 
index 9796bf89cf39cb97575296779971391a336828e8..aa0c2b58468856a8f71537389c5a824775293e46 100644 (file)
@@ -81,6 +81,9 @@ static int wm_collada_export_exec(bContext *C, wmOperator *op)
 {
   char filepath[FILE_MAX];
   int apply_modifiers;
 {
   char filepath[FILE_MAX];
   int apply_modifiers;
+  int global_forward;
+  int global_up;
+  int apply_global_orientation;
   int export_mesh_type;
   int selected;
   int include_children;
   int export_mesh_type;
   int selected;
   int include_children;
@@ -140,6 +143,10 @@ static int wm_collada_export_exec(bContext *C, wmOperator *op)
   /* Options panel */
   apply_modifiers = RNA_boolean_get(op->ptr, "apply_modifiers");
   export_mesh_type = RNA_enum_get(op->ptr, "export_mesh_type_selection");
   /* Options panel */
   apply_modifiers = RNA_boolean_get(op->ptr, "apply_modifiers");
   export_mesh_type = RNA_enum_get(op->ptr, "export_mesh_type_selection");
+  global_forward = RNA_enum_get(op->ptr, "export_global_forward_selection");
+  global_up = RNA_enum_get(op->ptr, "export_global_up_selection");
+  apply_global_orientation = RNA_boolean_get(op->ptr, "apply_global_orientation");
+
   selected = RNA_boolean_get(op->ptr, "selected");
   include_children = RNA_boolean_get(op->ptr, "include_children");
   include_armatures = RNA_boolean_get(op->ptr, "include_armatures");
   selected = RNA_boolean_get(op->ptr, "selected");
   include_children = RNA_boolean_get(op->ptr, "include_children");
   include_armatures = RNA_boolean_get(op->ptr, "include_armatures");
@@ -181,6 +188,11 @@ static int wm_collada_export_exec(bContext *C, wmOperator *op)
   export_settings.filepath = filepath;
 
   export_settings.apply_modifiers = apply_modifiers != 0;
   export_settings.filepath = filepath;
 
   export_settings.apply_modifiers = apply_modifiers != 0;
+  export_settings.global_forward = global_forward;
+  export_settings.global_up = global_up;
+  export_settings.apply_global_orientation = apply_global_orientation != 0;
+
+  export_settings.export_mesh_type = export_mesh_type;
   export_settings.export_mesh_type = export_mesh_type;
   export_settings.selected = selected != 0;
   export_settings.include_children = include_children != 0;
   export_settings.export_mesh_type = export_mesh_type;
   export_settings.selected = selected != 0;
   export_settings.include_children = include_children != 0;
@@ -250,7 +262,7 @@ static int wm_collada_export_exec(bContext *C, wmOperator *op)
 
 static void uiCollada_exportSettings(uiLayout *layout, PointerRNA *imfptr)
 {
 
 static void uiCollada_exportSettings(uiLayout *layout, PointerRNA *imfptr)
 {
-  uiLayout *box, *row, *col, *split;
+  uiLayout *bbox, *box, *row, *col, *split;
   bool include_animations = RNA_boolean_get(imfptr, "include_animations");
   int ui_section = RNA_enum_get(imfptr, "prop_bc_export_ui_section");
 
   bool include_animations = RNA_boolean_get(imfptr, "include_animations");
   int ui_section = RNA_enum_get(imfptr, "prop_bc_export_ui_section");
 
@@ -272,6 +284,18 @@ static void uiCollada_exportSettings(uiLayout *layout, PointerRNA *imfptr)
     /* Export Data options */
     /* =================== */
 
     /* Export Data options */
     /* =================== */
 
+    bbox = uiLayoutBox(layout);
+    row = uiLayoutRow(bbox, false);
+    uiItemL(row, IFACE_("Global Orientation:"), ICON_ORIENTATION_GLOBAL);
+    row = uiLayoutRow(bbox, false);
+    uiItemR(row, imfptr, "export_global_forward_selection", 0, "", ICON_NONE);
+
+    row = uiLayoutRow(bbox, false);
+    uiItemR(row, imfptr, "export_global_up_selection", 0, "", ICON_NONE);
+
+    row = uiLayoutRow(bbox, false);
+    uiItemR(row, imfptr, "apply_global_orientation", 0, NULL, ICON_NONE);
+
     row = uiLayoutRow(box, false);
     uiItemR(row, imfptr, "selected", 0, NULL, ICON_NONE);
 
     row = uiLayoutRow(box, false);
     uiItemR(row, imfptr, "selected", 0, NULL, ICON_NONE);
 
@@ -287,6 +311,8 @@ static void uiCollada_exportSettings(uiLayout *layout, PointerRNA *imfptr)
     uiItemR(row, imfptr, "include_shapekeys", 0, NULL, ICON_NONE);
     uiLayoutSetEnabled(row, RNA_boolean_get(imfptr, "selected"));
 
     uiItemR(row, imfptr, "include_shapekeys", 0, NULL, ICON_NONE);
     uiLayoutSetEnabled(row, RNA_boolean_get(imfptr, "selected"));
 
+    row = uiLayoutRow(box, false);
+
     /* Texture options */
     box = uiLayoutBox(layout);
     row = uiLayoutRow(box, false);
     /* Texture options */
     box = uiLayoutBox(layout);
     row = uiLayoutRow(box, false);
@@ -418,6 +444,26 @@ void WM_OT_collada_export(wmOperatorType *ot)
       {0, NULL, 0, NULL, NULL},
   };
 
       {0, NULL, 0, NULL, NULL},
   };
 
+  static const EnumPropertyItem prop_bc_export_global_forward[] = {
+      {BC_GLOBAL_FORWARD_X, "X", 0, "X Forward", "Global Forward is positive X Axis"},
+      {BC_GLOBAL_FORWARD_Y, "Y", 0, "Y Forward", "Global Forward is positive Y Axis"},
+      {BC_GLOBAL_FORWARD_Z, "Z", 0, "Z Forward", "Global Forward is positive Z Axis"},
+      {BC_GLOBAL_FORWARD_MINUS_X, "-X", 0, "-X Forward", "Global Forward is negative X Axis"},
+      {BC_GLOBAL_FORWARD_MINUS_Y, "-Y", 0, "-Y Forward", "Global Forward is negative Y Axis"},
+      {BC_GLOBAL_FORWARD_MINUS_Z, "-Z", 0, "-Z Forward", "Global Forward is negative Z Axis"},
+      {0, NULL, 0, NULL, NULL},
+  };
+
+  static const EnumPropertyItem prop_bc_export_global_up[] = {
+      {BC_GLOBAL_UP_X, "X", 0, "X Up", "Global UP is positive X Axis"},
+      {BC_GLOBAL_UP_Y, "Y", 0, "Y Up", "Global UP is positive Y Axis"},
+      {BC_GLOBAL_UP_Z, "Z", 0, "Z Up", "Global UP is positive Z Axis"},
+      {BC_GLOBAL_UP_MINUS_X, "-X", 0, "-X Up", "Global UP is negative X Axis"},
+      {BC_GLOBAL_UP_MINUS_Y, "-Y", 0, "-Y Up", "Global UP is negative Y Axis"},
+      {BC_GLOBAL_UP_MINUS_Z, "-Z", 0, "-Z Up", "Global UP is negative Z Axis"},
+      {0, NULL, 0, NULL, NULL},
+  };
+
   static const EnumPropertyItem prop_bc_export_transformation_type[] = {
       {BC_TRANSFORMATION_TYPE_MATRIX,
        "matrix",
   static const EnumPropertyItem prop_bc_export_transformation_type[] = {
       {BC_TRANSFORMATION_TYPE_MATRIX,
        "matrix",
@@ -503,6 +549,29 @@ void WM_OT_collada_export(wmOperatorType *ot)
                "Resolution",
                "Modifier resolution for export");
 
                "Resolution",
                "Modifier resolution for export");
 
+  RNA_def_enum(func,
+               "export_global_forward_selection",
+               prop_bc_export_global_forward,
+               BC_DEFAULT_FORWARD,
+               "Global Forward Axis",
+               "Global Forward axis for export");
+
+  RNA_def_enum(func,
+               "export_global_up_selection",
+               prop_bc_export_global_up,
+               BC_DEFAULT_UP,
+               "Global Up Axis",
+               "Global Up axis for export");
+
+  RNA_def_boolean(func, "", false, "Selection Only", "Export only selected elements");
+
+  RNA_def_boolean(func,
+                  "apply_global_orientation",
+                  false,
+                  "Apply Global Orientation",
+                  "enabled: Rotate all root objects to match the global orientation "
+                  "settings.\ndisabled: set global orientation in Collada assets");
+
   RNA_def_boolean(func, "selected", false, "Selection Only", "Export only selected elements");
 
   RNA_def_boolean(func,
   RNA_def_boolean(func, "selected", false, "Selection Only", "Export only selected elements");
 
   RNA_def_boolean(func,