[Bf-blender-cvs] [2fe1e9dc0fb] collada: Added separate functions to get curve data for sampling and keyframes

Gaia Clary noreply at git.blender.org
Wed Mar 28 21:30:57 CEST 2018


Commit: 2fe1e9dc0fbd0502e9e2cffade9f6e20fefc9b53
Author: Gaia Clary
Date:   Fri Mar 23 09:50:18 2018 +0100
Branches: collada
https://developer.blender.org/rB2fe1e9dc0fbd0502e9e2cffade9f6e20fefc9b53

Added separate functions to get curve data for sampling and keyframes

For Materials, Camera, Lamp actions it turned out that the sampler
can not sample the data at the moment. So for those curves i need
to get the data from the original curves for now. I Added a getter
that would retreive the data from the FCurve instead from the sampled
data if no sampled data is available. This will change (wip)

Known limitation: the Material,Lamp,Camera actions are always
exported with linear interpolation (wip)

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

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

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

diff --git a/source/blender/collada/AnimationExporter.cpp b/source/blender/collada/AnimationExporter.cpp
index 7c1b1b33c6a..ec28b9d7127 100644
--- a/source/blender/collada/AnimationExporter.cpp
+++ b/source/blender/collada/AnimationExporter.cpp
@@ -471,8 +471,8 @@ void AnimationExporter::export_collada_curve_animation(
 {
 	BCFrames frames;
 	BCValues values;
-	curve.get_frames(frames);
-	curve.get_values(values);
+	curve.get_sampled_frames(frames);
+	curve.get_sampled_values(values);
 
 	fprintf(stdout, "Export animation curve %s (%d control points)\n", id.c_str(), int(frames.size()));
 	openAnimation(id, name);
@@ -717,7 +717,7 @@ std::string AnimationExporter::create_tangent_from_curve(COLLADASW::InputSemanti
 	source.prepareToAppendValues();
 
 	std::vector<float> values;
-	curve.get_values(values);
+	curve.get_sampled_values(values);
 
 	const FCurve *fcu = curve.get_fcurve(); // need this to get the original tangents
 
@@ -867,7 +867,7 @@ std::string AnimationExporter::create_interpolation_source(const BCAnimationCurv
 
 	const FCurve *fcu = curve.get_fcurve();
 	std::vector<float>frames;
-	curve.get_frames(frames);
+	curve.get_sampled_frames(frames);
 
 	for (unsigned int i = 0; i < curve.size(); i++) {
 		float frame = frames[i];
diff --git a/source/blender/collada/BCAnimationCurve.cpp b/source/blender/collada/BCAnimationCurve.cpp
index b95b6526577..53454043357 100644
--- a/source/blender/collada/BCAnimationCurve.cpp
+++ b/source/blender/collada/BCAnimationCurve.cpp
@@ -173,6 +173,7 @@ const std::string BCAnimationCurve::get_sid(const std::string axis_name) const
 	BC_animation_transform_type tm_type = get_transform_type();
 	std::map<BC_animation_transform_type, std::string>::iterator name_it = BC_ANIMATION_NAME_FROM_TYPE.find(tm_type);
 	tm_name = name_it->second;
+
 	if (axis_name != "")
 		tm_name += '.' + axis_name;
 
@@ -428,15 +429,35 @@ Return the frames of the sampled curve;
 Note: If the curve was not sampled, the
 returned vector is empty
 */
-void BCAnimationCurve::get_frames(BCFrames &frames) const
+
+void BCAnimationCurve::get_key_frames(BCFrames &frames) const
 {
-	BCValueMap::const_iterator it;
-	for (it = samples.begin(); it != samples.end(); ++it) {
-		frames.push_back(it->first);
+	if (fcurve) {
+		for (int i = 0; i < fcurve->totvert; i++) {
+			const float val = fcurve->bezt[i].vec[1][0];
+			frames.push_back(val);
+		}
 	}
 }
 
-void BCAnimationCurve::get_frames(BCFrameSet &frames) const
+void BCAnimationCurve::get_sampled_frames(BCFrames &frames, bool fallback) const
+{
+	frames.clear();
+	if (samples.size() == 0 && fallback) {
+		return get_key_frames(frames);
+	}
+	else if (samples.size() > 0) {
+		BCValueMap::const_iterator it;
+		for (it = samples.begin(); it != samples.end(); ++it) {
+			//float val = evaluate_fcurve(fcurve, *it);
+			const int val = it->first;
+			frames.push_back(val);
+		}
+	}
+}
+
+
+void BCAnimationCurve::get_sampled_frames(BCFrameSet &frames) const
 {
 	BCValueMap::const_iterator it;
 		for (it = samples.begin(); it != samples.end(); ++it) {
@@ -464,16 +485,33 @@ Return the ctimes of the sampled curve;
 Note: If the curve was not sampled, the
 returned vector is empty
 */
-void BCAnimationCurve::get_values(BCValues &values) const
+void BCAnimationCurve::get_key_values(BCValues &values) const
 {
-	BCValueMap::const_iterator it;
+	if (fcurve) {
+		for (int i = 0; i < fcurve->totvert; i++) {
+			const float val = fcurve->bezt[i].vec[1][1];
+			values.push_back(val);
+		}
+	}
+}
+
+void BCAnimationCurve::get_sampled_values(BCValues &values, bool fallback) const
+{
+	values.clear();
+	if (samples.size() == 0 && fallback) {
+		return get_key_values(values);
+	}
+	else if (samples.size() > 0) {
+		BCValueMap::const_iterator it;
 		for (it = samples.begin(); it != samples.end(); ++it) {
 			//float val = evaluate_fcurve(fcurve, *it);
 			const float val = it->second;
 			values.push_back(val);
 		}
+	}
 }
 
+
 bool BCAnimationCurve::is_flat()
 {
 	static float MIN_DISTANCE = 0.00001;
diff --git a/source/blender/collada/BCAnimationCurve.h b/source/blender/collada/BCAnimationCurve.h
index ce685b3d24a..4782cd61176 100644
--- a/source/blender/collada/BCAnimationCurve.h
+++ b/source/blender/collada/BCAnimationCurve.h
@@ -180,8 +180,7 @@ public:
 	Note: If the curve was not sampled, the
 	returned vector is empty
 	*/
-	void get_frames(BCFrames &frames) const;
-	void get_frames(BCFrameSet &frames) const;
+	void get_sampled_frames(BCFrameSet &frames) const;
 
 	/*
 	Return the ctimes of the sampled curve;
@@ -195,7 +194,10 @@ public:
 	Note: If the curve was not sampled, the
 	returned vector is empty
 	*/
-	void get_values(BCValues &values) const;
+	void get_key_values(BCValues &values) const;
+	void get_sampled_values(BCValues &values, bool fallback = true) const;
+	void get_key_frames(BCFrames &frames) const;
+	void get_sampled_frames(BCFrames &frames, bool fallback = true) const;
 	bool is_flat();
 	bool is_rot() const;
 	bool is_keyframe(int frame);
diff --git a/source/blender/collada/BCAnimationCurveContainer.cpp b/source/blender/collada/BCAnimationCurveContainer.cpp
index 269cb036248..f96552efce2 100644
--- a/source/blender/collada/BCAnimationCurveContainer.cpp
+++ b/source/blender/collada/BCAnimationCurveContainer.cpp
@@ -380,7 +380,7 @@ void BCAnimationSampler::get_frame_set(BCFrames &frames, Object *ob, Bone *bone)
 
 void BCAnimationSampler::get_frame_set(BCFrames &frames, Object *ob, const BCAnimationCurve &curve)
 {
-	curve.get_frames(frames); // TODO: get frames from curve...
+	curve.get_sampled_frames(frames);
 }
 
 bool BCAnimationSampler::get_matrix_set(BCMatrixMap &matrices, Object *ob, Bone *bone)
@@ -455,7 +455,7 @@ void BCAnimationSampler::add_value_set(
 const bool BCAnimationSampler::get_value_set(BCValues &values, BCFrames &frames, BCAnimationCurve &curve)
 {
 	values.clear();
-	curve.get_values(values);
+	curve.get_sampled_values(values);
 	return is_flat_line(values);
 }



More information about the Bf-blender-cvs mailing list