[Bf-blender-cvs] [3f58e82805d] collada: Refactor Collada: Removed obsolete BCKeyPoint class
Gaia Clary
noreply at git.blender.org
Thu Apr 19 22:24:32 CEST 2018
Commit: 3f58e82805d95f00c0c914b8d52639969e112f10
Author: Gaia Clary
Date: Thu Apr 19 21:48:55 2018 +0200
Branches: collada
https://developer.blender.org/rB3f58e82805d95f00c0c914b8d52639969e112f10
Refactor Collada: Removed obsolete BCKeyPoint class
Also simplified the way how the AnimationSampler
stores its sampled data.
After some experimenting i decided to use FCurves as
intermediate storage for exported animation curves.
This looks a lot cleaner to me now because now i no
longer have duplicate storage locations.
Also the handling of curve handles is now pretty much straight
forward and no longer needs any extra calculations.
===================================================================
M source/blender/collada/AnimationExporter.cpp
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 34f7df12eae..0763e3fa345 100644
--- a/source/blender/collada/AnimationExporter.cpp
+++ b/source/blender/collada/AnimationExporter.cpp
@@ -277,7 +277,8 @@ BCAnimationCurve *AnimationExporter::get_modified_export_curve(Object *ob, BCAni
mcurve = new BCAnimationCurve(key, ob);
// now tricky part: transform the fcurve
- const BCValueMap &lens_values = curve.get_value_map();
+ BCValueMap lens_values;
+ curve.get_value_map(lens_values);
BCAnimationCurve *sensor_curve = NULL;
BCCurveKey sensor_key(BC_ANIMATION_TYPE_CAMERA, "sensor_width", 0);
@@ -289,7 +290,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.get_value();
+ float lens_value = vit->second;
float sensor_value;
if (sensor_curve) {
@@ -383,8 +384,8 @@ void AnimationExporter::export_collada_curve_animation(
{
BCFrames frames;
BCValues values;
- curve.get_sampled_frames(frames);
- curve.get_sampled_values(values);
+ curve.get_frames(frames);
+ curve.get_values(values);
std::string channel_target = curve.get_channel_target();
fprintf(stdout, "Export animation curve %s (%d control points)\n", id.c_str(), int(frames.size()));
@@ -509,51 +510,6 @@ void AnimationExporter::add_source_parameters(COLLADASW::SourceBase::ParameterNa
}
}
-/*
-Use this when the curve has different keyframes than the underlaying FCurve.
-This can happen when the curve contains sample points. However
-currently the BCAnimationSampler makes sure that sampled points
-are added to the FCurve, hence this function will always find a matching
-keyframe;
-*/
-int AnimationExporter::get_point_in_curve(const BCAnimationCurve &curve, float val, COLLADASW::InputSemantic::Semantics semantic, bool is_angle, float *values)
-{
- const FCurve *fcu = curve.get_fcurve();
- int lower_index = curve.closest_index_below(val);
- return get_point_in_curve(BCBezTriple(fcu->bezt[lower_index]), semantic, is_angle, values);
-}
-
-
-int AnimationExporter::get_point_in_curve(BCBezTriple &bezt, COLLADASW::InputSemantic::Semantics semantic, bool is_angle, float *values)
-{
- int length;
- switch (semantic) {
- case COLLADASW::InputSemantic::INPUT:
- length = 1;
- values[0] = bezt.get_time(scene);
- break;
- case COLLADASW::InputSemantic::OUTPUT:
- length = 1;
- values[0] = (is_angle) ? bezt.get_angle() : bezt.get_value();
- break;
-
- case COLLADASW::InputSemantic::IN_TANGENT:
- length = 2;
- bezt.get_in_tangent(scene, values, is_angle);
- break;
-
- case COLLADASW::InputSemantic::OUT_TANGENT:
- length = 2;
- bezt.get_out_tangent(scene, values, is_angle);
- break;
-
- default:
- length = 0;
- break;
- }
- return length;
-}
-
std::string AnimationExporter::collada_tangent_from_curve(COLLADASW::InputSemantic::Semantics semantic, BCAnimationCurve &curve, const std::string& anim_id, std::string axis_name)
{
std::string channel = curve.get_channel_target();
@@ -574,30 +530,14 @@ std::string AnimationExporter::collada_tangent_from_curve(COLLADASW::InputSemant
source.prepareToAppendValues();
- BCValueMap &value_map = curve.get_value_map();
- BCValueMap::iterator it;
- for (it = value_map.begin(); it != value_map.end(); ++it) {
-
- int frame_index = it->first;
- BCKeyPoint &point = it->second;
- float sampled_time;
- float sampled_val;
+ const FCurve *fcu = curve.get_fcurve();
+ int tangent = (semantic == COLLADASW::InputSemantic::IN_TANGENT) ? 0 : 2;
- if (point.has_handles()) {
+ for (int i = 0; i < fcu->totvert; ++i) {
+ BezTriple &bezt = fcu->bezt[i];
- if (semantic == COLLADASW::InputSemantic::IN_TANGENT) {
- sampled_val = point.get_in_tangent()[1];
- sampled_time = point.get_in_tangent()[0];
- }
- else {
- sampled_val = point.get_out_tangent()[1];
- sampled_time = point.get_out_tangent()[0];
- }
- }
- else {
- sampled_val = point.get_value();
- sampled_time = point.get_frame();
- }
+ float sampled_time = bezt.vec[tangent][0];
+ float sampled_val = bezt.vec[tangent][1];
if (is_angle) {
sampled_val = RAD2DEGF(sampled_val);
@@ -709,7 +649,7 @@ std::string AnimationExporter::collada_interpolation_source(const BCAnimationCur
const FCurve *fcu = curve.get_fcurve();
std::vector<float>frames;
- curve.get_sampled_frames(frames);
+ curve.get_frames(frames);
for (unsigned int i = 0; i < curve.sample_count(); i++) {
float frame = frames[i];
diff --git a/source/blender/collada/BCAnimationCurve.cpp b/source/blender/collada/BCAnimationCurve.cpp
index 47bb0e1d60e..add6cdede8a 100644
--- a/source/blender/collada/BCAnimationCurve.cpp
+++ b/source/blender/collada/BCAnimationCurve.cpp
@@ -37,7 +37,6 @@ BCAnimationCurve::BCAnimationCurve(const BCAnimationCurve &other)
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;
@@ -220,7 +219,9 @@ const std::string BCAnimationCurve::get_rna_path() const
const int BCAnimationCurve::sample_count() const
{
- return samples.size();
+ if (fcurve == NULL)
+ return 0;
+ return fcurve->totvert;
}
const int BCAnimationCurve::closest_index_above(const float sample_frame, const int start_at) const
@@ -274,7 +275,7 @@ const int BCAnimationCurve::get_interpolation_type(float sample_frame) const
return fcurve->bezt[index].ipo;
}
-FCurve *BCAnimationCurve::get_fcurve() const
+const FCurve *BCAnimationCurve::get_fcurve() const
{
return fcurve;
}
@@ -282,22 +283,16 @@ FCurve *BCAnimationCurve::get_fcurve() const
FCurve *BCAnimationCurve::get_edit_fcurve()
{
if (!curve_is_local_copy) {
+ const int index = curve_key.get_array_index();
+ const std::string &path = curve_key.get_path();
+ fcurve = create_fcurve(index, path.c_str());
- if (fcurve) {
- fcurve = copy_fcurve(fcurve);
- //fprintf(stderr, "Copy to temporary fcurve %s (for editing)\n", fcurve->rna_path);
- }
- else {
- const int index = curve_key.get_array_index();
- const std::string &path = curve_key.get_path();
- fcurve = create_fcurve(index, path.c_str());
- //fprintf(stderr, "Create temporary fcurve %s (for editing)\n", fcurve->rna_path);
- }
-
- /* Replacing the pointer here is OK because the original value
+ /* Caution here:
+ Replacing the pointer here is OK only because the original value
of FCurve was a const pointer into Blender territory. We do not
- touch that! We use the local copy to prepare for export.
+ touch that! We use the local copy to prepare data for export.
*/
+
curve_is_local_copy = true;
}
return fcurve;
@@ -350,19 +345,10 @@ const bool BCAnimationCurve::is_rotation_curve() const
const float BCAnimationCurve::get_value(const float frame)
{
- float eval;
-
- BCValueMap::iterator it = samples.find(frame);
- if (it != samples.end()) {
- BCKeyPoint &keypoint = it->second;
- eval = keypoint.get_value();
- }
-
- FCurve *fcu = get_fcurve();
- if (fcu) {
- eval = evaluate_fcurve(fcu, frame);
+ if (fcurve) {
+ return evaluate_fcurve(fcurve, frame);
}
- return eval; // TODO: handle case where neither sample nor fcu exist
+ return 0; // TODO: handle case where neither sample nor fcu exist
}
void BCAnimationCurve::update_range(float val)
@@ -405,9 +391,7 @@ void BCAnimationCurve::add_value(const float val, const int frame_index)
BEZT_KEYTYPE_KEYFRAME,
0);
- samples[frame_index] = BCKeyPoint(fcu->bezt[key_index]);
-
- if (samples.size() == 1) {
+ if (fcu->totvert == 1) {
init_range(val);
}
else {
@@ -504,63 +488,37 @@ bool BCAnimationCurve::add_value_from_rna(const int frame_index)
return true;
}
-/*
-Return the frames of the sampled curve;
-Note: If the curve was not sampled, the
-returned vector is empty
-*/
-
-void BCAnimationCurve::get_key_frames(BCFrames &frames) const
+void BCAnimationCurve::get_value_map(BCValueMap &value_map)
{
- if (fcurve) {
- for (int i = 0; i < fcurve->totvert; i++) {
- const float val = fcurve->bezt[i].vec[1][0];
- frames.push_back(val);
- }
+ value_map.clear();
+ if (fcurve == NULL) {
+ return;
}
-}
-void BCAnimationCurve::get_sampled_frames(BCFrames &frames) const
-{
- frames.clear();
- if (samples.size() == 0) {
- 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);
- }
+ for (int i = 0; i < fcurve->totvert; i++) {
+ const float frame = fcurve->bezt[i].vec[1][0];
+ const float val = fcurve->bezt[i].vec[1][1];
+ value_map[frame] = val;
}
}
-void BCAnimationCurve::get_key_values(BCValues &values) const
+void BCAnimationCurve::get_frames(BCFrames &frames) const
{
+ frames.clear();
if (fcurve) {
for (int i = 0; i < fcurve->totvert; i++) {
- const float val = fcurve->bezt[i].vec[1][1];
- values.push_back(val);
+ const float val = fcurve->bezt[i].vec[1][0];
+ frames.push_back(val);
}
}
}
-BCValueMap &BCAnimationCurve::get_value_map()
-{
- return samples;
-}
-
-void BCAnimationCurve::get_sampled_values(BCValues &values) const
+void BCAnimationCurve::get_values(BCValues &values) const
{
values.clear();
- if (samples.size() == 0) {
- get_key_values(values);
- }
- else if (samples.size() > 0) {
- BCValueMap::const_iterator it;
- for (it = samples.begin(); it != samples.end(); ++it) {
- const float val = it->second.get_value();
+ if (fcurve) {
+ for (int i = 0; i < fcurve->totvert; i++) {
+ const float val = fcurve->bezt[i].vec[1][1];
values.push_back(val);
}
}
diff --git a/source/blender/collada/BCAnimationCurve.h b/source/blender/collada/BCAnimationCurve.h
index 0444edb57ba..45b2a44337a 100644
--- a/source/blender/collada/BCAnimationCurve.h
+++ b/source/blender/collada/BCAnimationCurve.h
@@ -46,6 +46,7 @@ typedef std::set<float> BCFrameSet;
typedef std::vector<float> BCFrames;
typedef std::ve
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list