[Bf-blender-cvs] [4b7596ec914] master: fix T59743: Collada exporter: Add option for exporting flat curves

Gaia Clary noreply at git.blender.org
Sat Jan 5 21:52:54 CET 2019


Commit: 4b7596ec914e9d748b23831db736ef89eb879886
Author: Gaia Clary
Date:   Sat Jan 5 21:36:28 2019 +0100
Branches: master
https://developer.blender.org/rB4b7596ec914e9d748b23831db736ef89eb879886

fix T59743: Collada exporter: Add option for exporting flat curves

The Collada exporter suppresses the export of flat animation curves
to optimize the animation (in fact to make the exported file smaller).

But sometimes it is important to also have the flat curves exported
because they may be needed to define an initial transformation to
a fixed location - like translating the weapon from the ground floor
to the back of the model in the report.

I added a new option "all keyed curves" which is disabled by default
but when enabled it also exports flat curves.

feedback is very welcome

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

M	source/blender/collada/AnimationExporter.cpp
M	source/blender/collada/ExportSettings.h
M	source/blender/editors/io/io_collada.c

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

diff --git a/source/blender/collada/AnimationExporter.cpp b/source/blender/collada/AnimationExporter.cpp
index 69a25ac7a82..f6d9bee4563 100644
--- a/source/blender/collada/AnimationExporter.cpp
+++ b/source/blender/collada/AnimationExporter.cpp
@@ -148,6 +148,7 @@ void AnimationExporter::exportAnimation(Object *ob, BCAnimationSampler &sampler)
 	 * However Armatures also can have Object animation.
 	 */
 	bool export_as_matrix = this->export_settings->export_transformation_type == BC_TRANSFORMATION_TYPE_MATRIX;
+
 	if (export_as_matrix) {
 		export_matrix_animation(ob, sampler); // export all transform_curves as one single matrix animation
 	}
@@ -184,6 +185,7 @@ void AnimationExporter::exportAnimation(Object *ob, BCAnimationSampler &sampler)
 void AnimationExporter::export_curve_animation_set(Object *ob, BCAnimationSampler &sampler, bool export_as_matrix)
 {
 	BCAnimationCurveMap *curves = sampler.get_curves(ob);
+	bool keep_flat_curves = this->export_settings->keep_flat_curves;
 
 	BCAnimationCurveMap::iterator it;
 	for (it = curves->begin(); it != curves->end(); ++it) {
@@ -205,7 +207,7 @@ void AnimationExporter::export_curve_animation_set(Object *ob, BCAnimationSample
 			continue;
 		}
 
-		if (!curve.is_animated()) {
+		if (!keep_flat_curves && !curve.is_animated()) {
 			continue;
 		}
 
@@ -222,12 +224,14 @@ void AnimationExporter::export_curve_animation_set(Object *ob, BCAnimationSample
 
 void AnimationExporter::export_matrix_animation(Object *ob, BCAnimationSampler &sampler)
 {
+	bool keep_flat_curves = this->export_settings->keep_flat_curves;
+
 	std::vector<float> frames;
 	sampler.get_object_frames(frames, ob);
 	if (frames.size() > 0) {
 		BCMatrixSampleMap samples;
 		bool is_animated = sampler.get_object_samples(samples, ob);
-		if (is_animated) {
+		if (keep_flat_curves || is_animated) {
 			bAction *action = bc_getSceneObjectAction(ob);
 			std::string name = encode_xml(id_name(ob));
 			std::string action_name = (action == NULL) ? name + "-action" : id_name(action);
@@ -245,13 +249,15 @@ void AnimationExporter::export_matrix_animation(Object *ob, BCAnimationSampler &
 //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;
+
 	std::vector<float> frames;
 	sampler.get_bone_frames(frames, ob, bone);
 
 	if (frames.size()) {
 		BCMatrixSampleMap samples;
 		bool is_animated = sampler.get_bone_samples(samples, ob, bone);
-		if (is_animated) {
+		if (keep_flat_curves || is_animated) {
 			export_bone_animation(ob, bone, frames, samples);
 		}
 	}
diff --git a/source/blender/collada/ExportSettings.h b/source/blender/collada/ExportSettings.h
index 3b4397a6093..fa4f0ccb2e1 100644
--- a/source/blender/collada/ExportSettings.h
+++ b/source/blender/collada/ExportSettings.h
@@ -71,6 +71,7 @@ typedef struct ExportSettings {
 	int sampling_rate;
 	bool keep_smooth_curves;
 	bool keep_keyframes;
+	bool keep_flat_curves;
 
 	bool active_uv_only;
 	BC_export_animation_type export_animation_type;
diff --git a/source/blender/editors/io/io_collada.c b/source/blender/editors/io/io_collada.c
index 08dcde6da62..635ef60e3df 100644
--- a/source/blender/editors/io/io_collada.c
+++ b/source/blender/editors/io/io_collada.c
@@ -98,6 +98,7 @@ static int wm_collada_export_exec(bContext *C, wmOperator *op)
 	int sampling_rate;
 	int keep_smooth_curves;
 	int keep_keyframes;
+	int keep_flat_curves;
 
 	int export_animation_type;
 	int use_texture_copies;
@@ -157,6 +158,7 @@ static int wm_collada_export_exec(bContext *C, wmOperator *op)
 	sampling_rate            = (sample_animations) ? RNA_int_get(op->ptr, "sampling_rate") : 0;
 	keep_smooth_curves       = RNA_boolean_get(op->ptr, "keep_smooth_curves");
 	keep_keyframes           = RNA_boolean_get(op->ptr, "keep_keyframes");
+	keep_flat_curves         = RNA_boolean_get(op->ptr, "keep_flat_curves");
 
 	deform_bones_only        = RNA_boolean_get(op->ptr, "deform_bones_only");
 
@@ -195,6 +197,7 @@ static int wm_collada_export_exec(bContext *C, wmOperator *op)
 	export_settings.include_all_actions = include_all_actions != 0;
 	export_settings.sampling_rate = sampling_rate;
 	export_settings.keep_keyframes = keep_keyframes != 0 || sampling_rate < 1;
+	export_settings.keep_flat_curves = keep_flat_curves != 0;
 
 	export_settings.active_uv_only = active_uv_only != 0;
 	export_settings.export_animation_type = export_animation_type;
@@ -357,6 +360,9 @@ static void uiCollada_exportSettings(uiLayout *layout, PointerRNA *imfptr)
 		uiItemR(row, imfptr, "keep_keyframes", 0, NULL, ICON_NONE);
 		uiLayoutSetEnabled(row, sampling && include_animations);
 
+		row = uiLayoutColumn(box, false);
+		uiItemR(row, imfptr, "keep_flat_curves", 0, NULL, ICON_NONE);
+
 		row = uiLayoutRow(box, false);
 		uiItemR(row, imfptr, "include_all_actions", 0, NULL, ICON_NONE);
 		uiLayoutSetEnabled(row, include_animations);
@@ -502,7 +508,10 @@ void WM_OT_collada_export(wmOperatorType *ot)
 	                "is the unity matrix, otherwise you may end up with odd results)");
 
 	RNA_def_boolean(func, "keep_keyframes", 0, "Keep Keyframes",
-	                "Use existing keyframes as additional sample points (this helps when you want to keep manual tweaks)");
+		"Use existing keyframes as additional sample points (this helps when you want to keep manual tweaks)");
+
+	RNA_def_boolean(func, "keep_flat_curves", 0, "All keyed curves",
+		"Export also curves which have only one key or are totally flat");
 
 	RNA_def_boolean(func, "active_uv_only", 0, "Only Selected UV Map",
 	                "Export only the selected UV Map");



More information about the Bf-blender-cvs mailing list