[Bf-blender-cvs] [6be9d19951e] master: Collada exporter update

Gaia Clary noreply at git.blender.org
Thu May 23 12:29:29 CEST 2019


Commit: 6be9d19951ed460829d379aa90953b14a9f281f2
Author: Gaia Clary
Date:   Thu May 23 12:17:17 2019 +0200
Branches: master
https://developer.blender.org/rB6be9d19951ed460829d379aa90953b14a9f281f2

Collada exporter update

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

===================================================================

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

===================================================================

diff --git a/source/blender/collada/AnimationClipExporter.h b/source/blender/collada/AnimationClipExporter.h
index 6d67ab7c406..ead894dc941 100644
--- a/source/blender/collada/AnimationClipExporter.h
+++ b/source/blender/collada/AnimationClipExporter.h
@@ -25,13 +25,13 @@ class AnimationClipExporter : COLLADASW::LibraryAnimationClips {
   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,
-                        const ExportSettings *export_settings,
+                        BCExportSettings &export_settings,
                         std::vector<std::vector<std::string>> anim_meta)
       : COLLADASW::LibraryAnimationClips(sw),
         depsgraph(depsgraph),
diff --git a/source/blender/collada/AnimationExporter.cpp b/source/blender/collada/AnimationExporter.cpp
index eaa1626f7d8..edd74886541 100644
--- a/source/blender/collada/AnimationExporter.cpp
+++ b/source/blender/collada/AnimationExporter.cpp
@@ -77,9 +77,9 @@ void AnimationExporter::close_animation_container(bool has_container)
 
 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) {
@@ -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();
-    BCAnimationSampler animation_sampler(blender_context, animated_subset);
+    BCAnimationSampler animation_sampler(export_settings, animated_subset);
 
     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();
 
@@ -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.
    */
-  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) {
@@ -178,7 +174,7 @@ void AnimationExporter::export_curve_animation_set(Object *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) {
@@ -215,7 +211,7 @@ void AnimationExporter::export_curve_animation_set(Object *ob,
 
 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);
@@ -232,17 +228,31 @@ void AnimationExporter::export_matrix_animation(Object *ob, BCAnimationSampler &
 
       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)
 {
-  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);
@@ -347,7 +357,9 @@ void AnimationExporter::export_curve_animation(Object *ob, BCAnimationCurve &cur
     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,
@@ -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";
 
-  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)
@@ -383,11 +397,13 @@ bool AnimationExporter::is_bone_deform_group(Bone *bone)
   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;
@@ -408,7 +424,7 @@ void AnimationExporter::export_collada_curve_animation(std::string 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);
@@ -444,11 +460,14 @@ void AnimationExporter::export_collada_curve_animation(std::string id,
   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()));
@@ -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 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;
@@ -540,7 +559,8 @@ std::string AnimationExporter::collada_tangent_from_curve(
     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);
@@ -585,6 +605,7 @@ std::string AnimationExporter::collada_source_from_values(
     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 */
 
@@ -623,11 +644,14 @@ std::string AnimationExporter::collada_source_from_values(
   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)

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list