Commit: 1824e2bddfc58729557b99847186546f39646c92
Author: Gaia Clary
Date:   Tue Apr 17 22:32:23 2018 +0200
Branches: collada
https://developer.blender.org/rB1824e2bddfc58729557b99847186546f39646c92

Fix Collada: Keep existing FCurves available in Sampler

The FCurves are needed when we export Keyframes. In that case
we want to preserve the tangent data. Hence we want to keep
the original FCurves available while exporting.

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

M       source/blender/collada/AnimationExporter.cpp
M       source/blender/collada/BCAnimationCurve.cpp
M       source/blender/collada/BCAnimationCurve.h
M       source/blender/collada/BCAnimationSampler.cpp

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

diff --git a/source/blender/collada/AnimationExporter.cpp 
b/source/blender/collada/AnimationExporter.cpp
index 009b7c8a160..1c2c30868b9 100644
--- a/source/blender/collada/AnimationExporter.cpp
+++ b/source/blender/collada/AnimationExporter.cpp
@@ -270,7 +270,7 @@ BCAnimationCurve 
*AnimationExporter::get_modified_export_curve(Object *ob, BCAni
                /* Create an xfov curve */
 
                BCCurveKey key(BC_ANIMATION_TYPE_CAMERA, "xfov", 0);
-               mcurve = new BCAnimationCurve(ob, key);
+               mcurve = new BCAnimationCurve(key, ob);
 
                // now tricky part: transform the fcurve
                const BCValueMap &lens_values = curve.get_value_map();
diff --git a/source/blender/collada/BCAnimationCurve.cpp 
b/source/blender/collada/BCAnimationCurve.cpp
index 9b46c72c8fa..686ba0b5469 100644
--- a/source/blender/collada/BCAnimationCurve.cpp
+++ b/source/blender/collada/BCAnimationCurve.cpp
@@ -34,10 +34,10 @@ BCAnimationCurve::BCAnimationCurve()
 
 BCAnimationCurve::BCAnimationCurve(const BCAnimationCurve &other)
 {
-       this->fcurve = other.fcurve;
-       this->samples = other.samples;
        this->min = other.min;
        this->max = other.max;
+       this->fcurve = other.fcurve;
+       this->samples = other.samples;
        this->curve_key = other.curve_key;
        this->curve_is_local_copy = false;
        this->id_ptr = other.id_ptr;
@@ -47,12 +47,26 @@ BCAnimationCurve::BCAnimationCurve(const BCAnimationCurve 
&other)
        get_edit_fcurve();
 }
 
-BCAnimationCurve::BCAnimationCurve(Object *ob, const BCCurveKey &key)
+BCAnimationCurve::BCAnimationCurve(BCCurveKey key, Object *ob, FCurve *fcu)
+{
+       this->min = 0;
+       this->max = 0;
+       this->curve_key = key;
+       this->fcurve = fcu;
+       this->curve_is_local_copy = false;
+       init_pointer_rna(ob);
+}
+
+BCAnimationCurve::BCAnimationCurve(const BCCurveKey &key, Object *ob)
 {
        this->curve_key = key;
        this->fcurve = NULL;
        this->curve_is_local_copy = false;
+       init_pointer_rna(ob);
+}
 
+void BCAnimationCurve::init_pointer_rna(Object *ob)
+{
        switch (this->curve_key.get_animation_type()) {
        case BC_ANIMATION_TYPE_BONE:
        {
@@ -353,6 +367,36 @@ const float BCAnimationCurve::get_value(const float frame)
        return eval; // TODO: handle case where neither sample nor fcu exist
 }
 
+void BCAnimationCurve::update_range(float val)
+{
+       if (val < min) {
+                       min = val;
+       }
+       if (val > max) {
+               max = val;
+       }
+}
+
+void BCAnimationCurve::init_range(float val)
+{
+       min = max = val;
+}
+
+void BCAnimationCurve::adjust_range(const int frame_index)
+{
+       if (fcurve && fcurve->totvert > 1) {
+               const float eval = evaluate_fcurve(fcurve, frame_index);
+
+               int first_frame = fcurve->bezt[0].vec[1][0];
+               if (first_frame == frame_index) {
+                       init_range(eval);
+               }
+               else {
+                       update_range(eval);
+               }
+       }
+}
+
 void BCAnimationCurve::add_value(const float val, const int frame_index, bool 
modify_curve)
 {
        FCurve *fcu = get_edit_fcurve();
@@ -376,13 +420,11 @@ void BCAnimationCurve::add_value(const float val, const 
int frame_index, bool mo
 
                samples[frame_index] = val;
 
-               if (samples.size() == 1)
-                       min = max = val;
+               if (samples.size() == 1) {
+                       init_range(eval);
+               }
                else {
-                       if (val < min)
-                               min = val;
-                       if (val > max)
-                               max = val;
+                       update_range(eval);
                }
        }
 }
diff --git a/source/blender/collada/BCAnimationCurve.h 
b/source/blender/collada/BCAnimationCurve.h
index f1ca48a1b38..8041f433c9c 100644
--- a/source/blender/collada/BCAnimationCurve.h
+++ b/source/blender/collada/BCAnimationCurve.h
@@ -103,15 +103,18 @@ private:
        bool curve_is_local_copy = false;
        FCurve *fcurve;
        PointerRNA id_ptr;
-
+       void init_pointer_rna(Object *ob);
        void delete_fcurve(FCurve *fcu);
        FCurve *create_fcurve(int array_index, const char *rna_path);
        void create_bezt(float frame, float output);
+       void update_range(float val);
+       void init_range(float val);
 
 public:
        BCAnimationCurve();
        BCAnimationCurve(const BCAnimationCurve &other);
-       BCAnimationCurve(Object *ob, const BCCurveKey &key);
+       BCAnimationCurve(const BCCurveKey &key, Object *ob);
+       BCAnimationCurve(BCCurveKey key, Object *ob, FCurve *fcu);
        ~BCAnimationCurve();
 
        const bool is_of_animation_type(BC_animation_type type) const;
@@ -120,6 +123,7 @@ public:
        const bool is_transform_curve() const;
        const bool is_rotation_curve() const;
        bool is_keyframe(int frame);
+       void adjust_range(int frame);
 
        const std::string get_animation_name(Object *ob) const; /* xxx: this is 
collada specific */
        const std::string get_channel_target() const;
diff --git a/source/blender/collada/BCAnimationSampler.cpp 
b/source/blender/collada/BCAnimationSampler.cpp
index 2ae4912892e..c082c3b8471 100644
--- a/source/blender/collada/BCAnimationSampler.cpp
+++ b/source/blender/collada/BCAnimationSampler.cpp
@@ -137,7 +137,7 @@ void 
BCAnimationSampler::check_property_is_animated(BCAnimation &animation, floa
                        BCCurveKey key(BC_ANIMATION_TYPE_OBJECT, data_path, 
array_index);
                        BCAnimationCurveMap::iterator it = 
animation.curve_map.find(key);
                        if (it == animation.curve_map.end()) {
-                               animation.curve_map[key] = new 
BCAnimationCurve(animation.reference, key);
+                               animation.curve_map[key] = new 
BCAnimationCurve(key, animation.reference);
                        }
                }
        }
@@ -375,7 +375,7 @@ void BCAnimationSampler::generate_transform(
 {
        BCAnimationCurveMap::const_iterator it = curves.find(key);
        if (it == curves.end()) {
-               curves[key] = new BCAnimationCurve(ob, key);
+               curves[key] = new BCAnimationCurve(key, ob);
        }
 }
 
@@ -442,7 +442,7 @@ void 
BCAnimationSampler::initialize_curves(BCAnimationCurveMap &curves, Object *
 
                        /* Adding action curves on object */
                        BCCurveKey key(object_type, fcu->rna_path, 
fcu->array_index);
-                       curves[key] = new BCAnimationCurve(ob, key);
+                       curves[key] = new BCAnimationCurve(key, ob, fcu);
                }
        }
 
@@ -471,7 +471,7 @@ void 
BCAnimationSampler::initialize_curves(BCAnimationCurveMap &curves, Object *
                FCurve *fcu = (FCurve *)action->curves.first;
                for (; fcu; fcu = fcu->next) {
                        BCCurveKey key(object_type, fcu->rna_path, 
fcu->array_index);
-                       curves[key] = new BCAnimationCurve(ob, key);
+                       curves[key] = new BCAnimationCurve(key, ob, fcu);
                }
        }
 
@@ -487,7 +487,7 @@ void 
BCAnimationSampler::initialize_curves(BCAnimationCurveMap &curves, Object *
                                FCurve *fcu = (FCurve *)action->curves.first;
                                for (; fcu; fcu = fcu->next) {
                                        BCCurveKey key(object_type, 
fcu->rna_path, fcu->array_index, a);
-                                       curves[key] = new BCAnimationCurve(ob, 
key);
+                                       curves[key] = new BCAnimationCurve(key, 
ob, fcu);
                                }
                        }
                }

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
https://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to