[Bf-blender-cvs] [28dd3da1727] collada: Refactor: Moved unrelated class methods to collada_utils

Gaia Clary noreply at git.blender.org
Tue Apr 17 22:38:18 CEST 2018


Commit: 28dd3da172783f6a50495ef0725792e8d1f57e47
Author: Gaia Clary
Date:   Tue Apr 17 14:10:59 2018 +0200
Branches: collada
https://developer.blender.org/rB28dd3da172783f6a50495ef0725792e8d1f57e47

Refactor: Moved unrelated class methods to collada_utils

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

M	source/blender/collada/AnimationExporter.cpp
M	source/blender/collada/BCAnimationSampler.cpp
M	source/blender/collada/BCAnimationSampler.h
M	source/blender/collada/BCSampleData.h
M	source/blender/collada/collada_utils.cpp
M	source/blender/collada/collada_utils.h

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

diff --git a/source/blender/collada/AnimationExporter.cpp b/source/blender/collada/AnimationExporter.cpp
index 4f1a1e653b1..54099e131ae 100644
--- a/source/blender/collada/AnimationExporter.cpp
+++ b/source/blender/collada/AnimationExporter.cpp
@@ -81,7 +81,7 @@ void AnimationExporter::close_animation_container(bool has_container)
 int AnimationExporter::exportAnimations(Scene *sce)
 {
 	LinkNode &export_set = *this->export_settings->export_set;
-	bool has_anim_data = BCAnimationSampler::has_animations(sce, export_set);
+	bool has_anim_data = bc_has_animations(sce, export_set);
 	int animation_count = 0;
 	if (has_anim_data) {
 
diff --git a/source/blender/collada/BCAnimationSampler.cpp b/source/blender/collada/BCAnimationSampler.cpp
index 4cee7a7b1eb..bf6c118631c 100644
--- a/source/blender/collada/BCAnimationSampler.cpp
+++ b/source/blender/collada/BCAnimationSampler.cpp
@@ -289,7 +289,7 @@ void BCAnimationSampler::get_animated_from_export_set(std::set<Object *> &animat
 	LinkNode *node;
 	for (node = &export_set; node; node = node->next) {
 		Object *cob = (Object *)node->link;
-		if (has_animations(cob)) {
+		if (bc_has_animations(cob)) {
 			animated_objects.insert(cob);
 		}
 		else {
@@ -301,29 +301,6 @@ void BCAnimationSampler::get_animated_from_export_set(std::set<Object *> &animat
 	find_depending_animated(animated_objects, candidates);
 }
 
-bool BCAnimationSampler::is_animated(BCMatrixSampleMap &values) const
-{
-	static float MIN_DISTANCE = 0.00001;
-
-	if (values.size() < 2)
-		return false; // need at least 2 entries to be not flat
-
-	BCMatrixSampleMap::iterator it;
-	const BCMatrix *refmat = NULL;
-	for (it = values.begin(); it != values.end(); ++it) {
-		const BCMatrix *matrix = it->second;
-
-		if (refmat == NULL) {
-			refmat = matrix;
-			continue;
-		}
-
-		if (!matrix->in_range(*refmat, MIN_DISTANCE))
-			return true;
-	}
-	return false;
-}
-
 void BCAnimationSampler::get_object_frames(BCFrames &frames, Object *ob)
 {
 	sample_data.get_frames(ob, frames);
@@ -337,13 +314,13 @@ void BCAnimationSampler::get_bone_frames(BCFrames &frames, Object *ob, Bone *bon
 bool BCAnimationSampler::get_bone_samples(BCMatrixSampleMap &samples, Object *ob, Bone *bone)
 {
 	sample_data.get_matrices(ob, bone, samples);
-	return is_animated(samples);
+	return bc_is_animated(samples);
 }
 
 bool BCAnimationSampler::get_object_samples(BCMatrixSampleMap &samples, Object *ob)
 {
 	sample_data.get_matrices(ob, samples);
-	return is_animated(samples);
+	return bc_is_animated(samples);
 }
 
 #if 0
@@ -520,42 +497,6 @@ void BCAnimationSampler::initialize_curves(BCAnimationCurveMap &curves, Object *
 	}
 }
 
-bool BCAnimationSampler::has_animations(Object *ob)
-{
-	/* Check for object,lamp and camera transform animations */
-	if ((bc_getSceneObjectAction(ob) && bc_getSceneObjectAction(ob)->curves.first) ||
-		(bc_getSceneLampAction(ob) && bc_getSceneLampAction(ob)->curves.first) ||
-		(bc_getSceneCameraAction(ob) && bc_getSceneCameraAction(ob)->curves.first))
-		return true;
-
-	//Check Material Effect parameter animations.
-	for (int a = 0; a < ob->totcol; a++) {
-		Material *ma = give_current_material(ob, a + 1);
-		if (!ma) continue;
-		if (ma->adt && ma->adt->action && ma->adt->action->curves.first)
-			return true;
-	}
-
-	Key *key = BKE_key_from_object(ob);
-	if ((key && key->adt && key->adt->action) && key->adt->action->curves.first)
-		return true;
-
-	return false;
-}
-
-
-bool BCAnimationSampler::has_animations(Scene *sce, LinkNode &export_set)
-{
-	LinkNode *node;
-
-	for (node = &export_set; node; node = node->next) {
-		Object *ob = (Object *)node->link;
-
-		if (has_animations(ob))
-			return true;
-	}
-	return false;
-}
 /* ==================================================================== */
 
 BCSample &BCSampleFrame::add(Object *ob)
diff --git a/source/blender/collada/BCAnimationSampler.h b/source/blender/collada/BCAnimationSampler.h
index 5fa78a24762..2794bb7721c 100644
--- a/source/blender/collada/BCAnimationSampler.h
+++ b/source/blender/collada/BCAnimationSampler.h
@@ -94,20 +94,27 @@ typedef std::map<int, BCSampleFrame> BCSampleFrameMap;
 class BCSampleFrameContainer {
 
 	/*
-	An Animation is made of multiple FCurve where each FCurve can have multiple
-	keyframes. When we want to export the animation we
-	first need to resample it fully to resolve things like:
-
-	- animations by constraints
-	- animations by drivers
-	- resampled animations
-
-	For this purpose we need to step through the entire animation and
-	then sample each frame that contains at least one keyFrame or 
-	sampleFrame. Then for each frame we have to store the transform
-	information for all exported objects.
-
-	This is HERE! The BCSampleFrames object stores a map of BCSampleFrame objects with the timline frame as key.
+	* The BCSampleFrameContainer stores a map of BCSampleFrame objects
+	* with the timeline frame as key.
+	*
+	* Some details on the purpose:
+	* An Animation is made of multiple FCurves where each FCurve can 
+	* have multiple keyframes. When we want to export the animation we
+	* also can decide whether we want to export the keyframes or a set
+	* of sample frames at equidistant locations (sample period). 
+	* In any case we must resample first need to resample it fully 
+	* to resolve things like:
+	*
+	* - animations by constraints
+	* - animations by drivers
+	*
+	* For this purpose we need to step through the entire animation and
+	* then sample each frame that contains at least one keyFrame or 
+	* sampleFrame. Then for each frame we have to store the transform
+	* information for all exported objects in a BCSampleframe
+	*
+	* The entire set of BCSampleframes is finally collected into 
+	* a BCSampleframneContainer
 	*/
 
 private:
@@ -162,10 +169,7 @@ public:
 		bool keep_keyframes,
 		BC_export_animation_type export_animation_type);
 
-	bool is_animated(BCMatrixSampleMap &values) const;
-
 	BCAnimationCurveMap *get_curves(Object *ob);
-
 	void get_object_frames(BCFrames &frames, Object *ob);
 	bool get_object_samples(BCMatrixSampleMap &samples, Object *ob);
 	void get_bone_frames(BCFrames &frames, Object *ob, Bone *bone);
@@ -175,9 +179,6 @@ public:
 	static void find_depending_animated(std::set<Object *> &animated_objects, std::set<Object *> &candidates);
 	static bool is_animated_by_constraint(Object *ob, ListBase *conlist, std::set<Object *> &animated_objects);
 
-	static bool has_animations(Scene *sce, LinkNode &node);
-	static bool has_animations(Object *ob);
-
 };
 
 #endif
\ No newline at end of file
diff --git a/source/blender/collada/BCSampleData.h b/source/blender/collada/BCSampleData.h
index 28d2c12f1bf..ce9c849deb4 100644
--- a/source/blender/collada/BCSampleData.h
+++ b/source/blender/collada/BCSampleData.h
@@ -29,7 +29,6 @@
 #include <string>
 #include <map>
 #include <algorithm>
-#include "collada_utils.h"
 
 extern "C"
 {
@@ -41,6 +40,8 @@ extern "C"
 #include "DNA_camera_types.h"
 }
 
+typedef float(Matrix)[4][4];
+
 class BCMatrix {
 
 private:
@@ -70,6 +71,7 @@ public:
 	const bool in_range(const BCMatrix &other, float distance) const;
 	static void sanitize(Matrix &matrix, int precision);
 	static void transpose(Matrix &matrix);
+
 };
 
 typedef std::map<Bone *, BCMatrix *> BCBoneMatrixMap;
diff --git a/source/blender/collada/collada_utils.cpp b/source/blender/collada/collada_utils.cpp
index f736fd18ef2..eaab2773082 100644
--- a/source/blender/collada/collada_utils.cpp
+++ b/source/blender/collada/collada_utils.cpp
@@ -37,6 +37,7 @@
 extern "C" {
 #include "DNA_modifier_types.h"
 #include "DNA_customdata_types.h"
+#include "DNA_key_types.h"
 #include "DNA_object_types.h"
 #include "DNA_constraint_types.h"
 #include "DNA_mesh_types.h"
@@ -51,6 +52,8 @@ extern "C" {
 #include "BKE_customdata.h"
 #include "BKE_constraint.h"
 #include "BKE_depsgraph.h"
+#include "BKE_key.h"
+#include "BKE_material.h"
 #include "BKE_object.h"
 #include "BKE_global.h"
 #include "BKE_mesh.h"
@@ -985,6 +988,66 @@ bool bc_bone_matrix_local_get(Object *ob, Bone *bone, Matrix &mat, bool for_open
 	return true;
 }
 
+bool bc_is_animated(BCMatrixSampleMap &values)
+{
+	static float MIN_DISTANCE = 0.00001;
+
+	if (values.size() < 2)
+		return false; // need at least 2 entries to be not flat
+
+	BCMatrixSampleMap::iterator it;
+	const BCMatrix *refmat = NULL;
+	for (it = values.begin(); it != values.end(); ++it) {
+		const BCMatrix *matrix = it->second;
+
+		if (refmat == NULL) {
+			refmat = matrix;
+			continue;
+		}
+
+		if (!matrix->in_range(*refmat, MIN_DISTANCE))
+			return true;
+	}
+	return false;
+}
+
+bool bc_has_animations(Object *ob)
+{
+	/* Check for object,lamp and camera transform animations */
+	if ((bc_getSceneObjectAction(ob) && bc_getSceneObjectAction(ob)->curves.first) ||
+		(bc_getSceneLampAction(ob) && bc_getSceneLampAction(ob)->curves.first) ||
+		(bc_getSceneCameraAction(ob) && bc_getSceneCameraAction(ob)->curves.first))
+		return true;
+
+	//Check Material Effect parameter animations.
+	for (int a = 0; a < ob->totcol; a++) {
+		Material *ma = give_current_material(ob, a + 1);
+		if (!ma) continue;
+		if (ma->adt && ma->adt->action && ma->adt->action->curves.first)
+			return true;
+	}
+
+	Key *key = BKE_key_from_object(ob);
+	if ((key && key->adt && key->adt->action) && key->adt->action->curves.first)
+		return true;
+
+	return false;
+}
+
+
+bool bc_has_animations(Scene *sce, LinkNode &export_set)
+{
+	LinkNode *node;
+
+	for (node = &export_set; node; node = node->next) {
+		Object *ob = (Object *)node->link;
+
+		if (bc_has_animations(ob))
+			return true;
+	}
+	return false;
+}
+
 /**
 * Check if custom information about bind matrix exists and modify the from_mat
 * accordingly.
diff --git a/source/blender/collada/collada_utils.h b/source/blender/collada/collada_utils.h
index 32ad0e81df2..9599dbe9dcb 100644
--- a/source/blender/collada/collada_utils.h
+++ b/source/blender/collada/collada_utils.h
@@ -65,10 +65,10 @@ extern "C" {
 #include "ImportSettings.h"
 #include "ExportSettings.h"
 #include "collada_internal.h"
+#include "BCSampleData.h"
 
 typedef std::map<COLLADAFW::TextureMapId, std::vector<MTex *> > TexIndexTextureArrayMap;
 typedef std::set<Object *> BCObjectSet;
-typedef float(Matrix)[4][4];
 
 extern Main

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list