[Bf-blender-cvs] [45584c1d9c0] collada: Refactopr Collada: Changed BCValueMap to contain Values+curve handles

Gaia Clary noreply at git.blender.org
Thu Apr 19 18:56:33 CEST 2018


Commit: 45584c1d9c03e31e3fc5922ecddff68614747bd3
Author: Gaia Clary
Date:   Thu Apr 19 18:41:59 2018 +0200
Branches: collada
https://developer.blender.org/rB45584c1d9c03e31e3fc5922ecddff68614747bd3

Refactopr Collada: Changed BCValueMap to contain Values+curve handles

This makes it easiuer to later construct the export curves.
This may later be removed again in favor of storing the data
within the FCurves themself. (I am still somewhat undecided here)

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

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

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

diff --git a/source/blender/collada/AnimationExporter.cpp b/source/blender/collada/AnimationExporter.cpp
index 1c2c30868b9..b093311f99a 100644
--- a/source/blender/collada/AnimationExporter.cpp
+++ b/source/blender/collada/AnimationExporter.cpp
@@ -285,7 +285,7 @@ BCAnimationCurve *AnimationExporter::get_modified_export_curve(Object *ob, BCAni
 		BCValueMap::const_iterator vit;
 		for (vit = lens_values.begin(); vit != lens_values.end(); ++vit) {
 			int frame = vit->first;
-			float lens_value = vit->second;
+			float lens_value = vit->second.get_value();
 
 			float sensor_value;
 			if (sensor_curve) {
@@ -295,7 +295,7 @@ BCAnimationCurve *AnimationExporter::get_modified_export_curve(Object *ob, BCAni
 				sensor_value = ((Camera *)ob->data)->sensor_x;
 			}
 			float value = RAD2DEGF(focallength_to_fov(lens_value, sensor_value));
-			mcurve->add_value(value, frame, /*modify_curve=*/true);
+			mcurve->add_value(value, frame);
 		}
 		mcurve->clean_handles(); // to reset the handles
 	}
diff --git a/source/blender/collada/AnimationExporter.h b/source/blender/collada/AnimationExporter.h
index cce0a517092..4a364fd5f2e 100644
--- a/source/blender/collada/AnimationExporter.h
+++ b/source/blender/collada/AnimationExporter.h
@@ -140,7 +140,7 @@ private:
 		std::string name,
 		std::string target,
 		std::string axis,
-		const BCAnimationCurve &curve);
+		BCAnimationCurve &curve);
 
 	/* call to the low level collada exporter */
 	void export_collada_matrix_animation(
@@ -188,7 +188,7 @@ private:
 	int get_point_in_curve(BCBezTriple &bezt, COLLADASW::InputSemantic::Semantics semantic, bool is_angle, float *values);
 	int get_point_in_curve(const BCAnimationCurve &curve, float sample_frame, COLLADASW::InputSemantic::Semantics semantic, bool is_angle, float *values);
 
-	std::string collada_tangent_from_curve(COLLADASW::InputSemantic::Semantics semantic, const BCAnimationCurve &curve, std::vector<float>frames, const std::string& anim_id, const std::string axis_name);
+	std::string collada_tangent_from_curve(COLLADASW::InputSemantic::Semantics semantic, BCAnimationCurve &curve, const std::string& anim_id, const std::string axis_name);
 	std::string collada_interpolation_source(const BCAnimationCurve &curve, const std::string& anim_id, std::string axis_name, bool *has_tangents);
 		
 	std::string get_axis_name(std::string channel, int id);
diff --git a/source/blender/collada/BCAnimationCurve.cpp b/source/blender/collada/BCAnimationCurve.cpp
index 9c2ca7f9aa6..47bb0e1d60e 100644
--- a/source/blender/collada/BCAnimationCurve.cpp
+++ b/source/blender/collada/BCAnimationCurve.cpp
@@ -306,7 +306,7 @@ FCurve *BCAnimationCurve::get_edit_fcurve()
 void BCAnimationCurve::clean_handles()
 {
 	if (fcurve == NULL)
-		return;
+		fcurve = get_edit_fcurve();
 
 	/* Keep old bezt data for copy)*/
 	BezTriple *old_bezts = fcurve->bezt;
@@ -314,8 +314,6 @@ void BCAnimationCurve::clean_handles()
 	fcurve->bezt = NULL;
 	fcurve->totvert = 0;
 
-	/* now insert first keyframe, as it should be ok */
-
 	for (int i = 0; i < totvert; i++) {
 		BezTriple *bezt = &old_bezts[i];
 		float x = bezt->vec[1][0];
@@ -352,12 +350,12 @@ const bool BCAnimationCurve::is_rotation_curve() const
 
 const float BCAnimationCurve::get_value(const float frame)
 {
-	float eval = 0;
+	float eval;
 
 	BCValueMap::iterator it = samples.find(frame);
 	if (it != samples.end()) {
-		eval = it->second;
-		return eval;
+		BCKeyPoint &keypoint = it->second;
+		eval = keypoint.get_value();
 	}
 
 	FCurve *fcu = get_fcurve();
@@ -400,32 +398,20 @@ void BCAnimationCurve::adjust_range(const int frame_index)
 void BCAnimationCurve::add_value(const float val, const int frame_index)
 {
 	FCurve *fcu = get_edit_fcurve();
-	if (fcu) {
-		const float eval = evaluate_fcurve(fcu, frame_index);
-
-		/*
-		* This is a bit tricky here. We actually only insert a keyframe into the FCurve
-		* Preserving the current value. Then we add the frame index and the "true" value
-		* into a separate value_map <frame, value>
-		*
-		* Reason: we need the Fcurve handles later when we want to export the values as a Bezier curve
-		* You can call the method fix_modified_curve() when all curve points have been added
-		*/
-		int key_index = insert_vert_fcurve(
-			fcu, 
-			frame_index, 
-			(modify_curve) ? val:eval, 
-			BEZT_IPO_BEZ, 
-			INSERTKEY_NO_USERPREF);
+	fcu->auto_smoothing = FCURVE_SMOOTH_CONT_ACCEL;
+	int key_index = insert_vert_fcurve(
+		fcu, 
+		frame_index, val, 
+		BEZT_KEYTYPE_KEYFRAME,
+		0);
 
-		samples[frame_index] = val;
+	samples[frame_index] = BCKeyPoint(fcu->bezt[key_index]);
 
-		if (samples.size() == 1) {
-			init_range(eval);
-		}
-		else {
-			update_range(eval);
-		}
+	if (samples.size() == 1) {
+		init_range(val);
+	}
+	else {
+		update_range(val);
 	}
 }
 
@@ -574,7 +560,7 @@ void BCAnimationCurve::get_sampled_values(BCValues &values) const
 	else if (samples.size() > 0) {
 		BCValueMap::const_iterator it;
 		for (it = samples.begin(); it != samples.end(); ++it) {
-			const float val = it->second;
+			const float val = it->second.get_value();
 			values.push_back(val);
 		}
 	}
diff --git a/source/blender/collada/BCAnimationCurve.h b/source/blender/collada/BCAnimationCurve.h
index 2f15bced4af..0444edb57ba 100644
--- a/source/blender/collada/BCAnimationCurve.h
+++ b/source/blender/collada/BCAnimationCurve.h
@@ -46,7 +46,6 @@ typedef std::set<float> BCFrameSet;
 typedef std::vector<float> BCFrames;
 typedef std::vector<float> BCValues;
 typedef std::vector<float> BCTimes;
-typedef std::map<int, float> BCValueMap;
 
 typedef enum BC_animation_type {
 	BC_ANIMATION_TYPE_OBJECT,
@@ -158,6 +157,7 @@ public:
 
 };
 
+typedef std::map<int, BCKeyPoint> BCValueMap;
 
 class BCAnimationCurve {
 private:



More information about the Bf-blender-cvs mailing list