[Bf-blender-cvs] [83e1aac75d3] collada: Refator: Collada: replaced BCSampleKey by Object*

Gaia Clary noreply at git.blender.org
Wed Mar 28 21:31:20 CEST 2018


Commit: 83e1aac75d36f62e1502fb0b428494fe30d03c8c
Author: Gaia Clary
Date:   Sun Mar 25 13:01:14 2018 +0200
Branches: collada
https://developer.blender.org/rB83e1aac75d36f62e1502fb0b428494fe30d03c8c

Refator: Collada: replaced BCSampleKey by Object*

After doing some simplifications BCSampleKey has
degraded to alwasy be ob->id.name So i replaced the key
by the object pointer itself.

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

M	source/blender/collada/BCAnimationCurveContainer.cpp
M	source/blender/collada/BCAnimationCurveContainer.h
M	source/blender/collada/BCSampleData.h

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

diff --git a/source/blender/collada/BCAnimationCurveContainer.cpp b/source/blender/collada/BCAnimationCurveContainer.cpp
index b1e80a36c10..2137c27b72f 100644
--- a/source/blender/collada/BCAnimationCurveContainer.cpp
+++ b/source/blender/collada/BCAnimationCurveContainer.cpp
@@ -403,14 +403,12 @@ bool BCAnimationSampler::is_flat_line(std::vector<float> &values) const
 
 void BCAnimationSampler::get_frame_set(BCFrames &frames, Object *ob)
 {
-	BCSampleKey key(ob);
-	sample_data.get_frames(key, frames);
+	sample_data.get_frames(ob, frames);
 }
 
 void BCAnimationSampler::get_frame_set(BCFrames &frames, Object *ob, Bone *bone)
 {
-	BCSampleKey key(ob, bone);
-	sample_data.get_frames(key, frames);
+	sample_data.get_frames(ob, bone, frames);
 }
 
 void BCAnimationSampler::get_frame_set(BCFrames &frames, Object *ob, const BCAnimationCurve &curve)
@@ -426,15 +424,13 @@ bool BCAnimationSampler::get_samples(BCMatrixSampleMap &samples, Object *ob, Bon
 
 bool BCAnimationSampler::get_samples(BCFrameSampleMap &samples, Object *ob)
 {
-	const BCSampleKey key(ob);
-	sample_data.get_matrices(key, samples);
+	sample_data.get_matrices(ob, samples);
 	return is_flat_line(samples);
 }
 
 bool BCAnimationSampler::get_samples(BCMatrixSampleMap &samples, Object *ob)
 {
-	const BCSampleKey key(ob);
-	sample_data.get_matrices(key, samples);
+	sample_data.get_matrices(ob, samples);
 	return is_flat_line(samples);
 }
 
@@ -647,50 +643,42 @@ bool BCAnimationSampler::has_animations(Scene *sce, LinkNode *export_set)
 BCSample &BCSampleFrame::add(Object *ob, Matrix &mat)
 {
 	BCSample *sample = new BCSample(mat);
-	sampleMap[BCSampleKey(ob)] = sample;
+	sampleMap[ob] = sample;
 	return *sample;
 }
 
 /* Add a new Bone to this map with the given Matrix*/
 BCSample &BCSampleFrame::add(Object *ob, Bone *bone, Matrix &mat)
 {
-	BCSample *sample = new BCSample(mat);
-	sampleMap[BCSampleKey(ob, bone)] = sample;
+	BCSample *sample = sampleMap[ob];
+	sample->set_bone(bone, mat);
 	return *sample;
 }
 
 /* Get the matrix for the given key, returns Unity when the key does not exist */
-const BCSample &BCSampleFrame::get_sample(const BCSampleKey key) const
+const BCSample *BCSampleFrame::get_sample(Object *ob) const
 {
-	BCSampleKeysMap::const_iterator it = sampleMap.find(key);
+	BCSampleKeysMap::const_iterator it = sampleMap.find(ob);
 	if (it == sampleMap.end()) {
-		return UNIT_SAMPLE;
+		return nullptr;
 	}
-	return *it->second;
+	return it->second;
 }
 
-const BCMatrix &BCSampleFrame::get_sample_matrix(const BCSampleKey key) const
+const BCMatrix *BCSampleFrame::get_sample_matrix(Object *ob) const
 {
-	BCSampleKeysMap::const_iterator it = sampleMap.find(key);
+	BCSampleKeysMap::const_iterator it = sampleMap.find(ob);
 	if (it == sampleMap.end()) {
-		return UNIT_MATRIX;
+		return nullptr;
 	}
 	BCSample *sample = it->second;
-	return *sample->get_sampled_matrix();
-}
-
-/* Get the matrix for the given Object, returns Unity when the Objewct is not sampled */
-const BCSample &BCSampleFrame::get_sample(Object *ob) const
-{
-	const BCSampleKey key(ob);
-	return get_sample(key);
+	return sample->get_sampled_matrix();
 }
 
 /* Get the matrix for the given Bone, returns Unity when the Objewct is not sampled */
 const BCMatrix *BCSampleFrame::get_sample_matrix(Object *ob, Bone *bone) const
 {
-	const BCSampleKey key(ob);
-	BCSampleKeysMap::const_iterator it = sampleMap.find(key);
+	BCSampleKeysMap::const_iterator it = sampleMap.find(ob);
 	if (it == sampleMap.end()) {
 		return nullptr;
 	}
@@ -701,16 +689,9 @@ const BCMatrix *BCSampleFrame::get_sample_matrix(Object *ob, Bone *bone) const
 }
 
 /* Check if the key is in this BCSampleFrame */
-const bool BCSampleFrame::contains(const BCSampleKey &key) const
-{
-	return sampleMap.find(key) != sampleMap.end();
-}
-
-/* Check if the Object is in this BCSampleFrame */
 const bool BCSampleFrame::contains(Object *ob) const
 {
-	const BCSampleKey key(ob);
-	return contains(key);
+	return sampleMap.find(ob) != sampleMap.end();
 }
 
 /* Check if the Bone is in this BCSampleFrame */
@@ -766,42 +747,55 @@ const int BCSampleFrames::get_frames(std::vector<int> &frames) const
 	return frames.size();
 }
 
-const int BCSampleFrames::get_frames(BCSampleKey &key, BCFrames &frames) const
+const int BCSampleFrames::get_frames(Object *ob, BCFrames &frames) const
+{
+	frames.clear(); // safety;
+	BCSampleFrameMap::const_iterator it;
+	for (it = sample_frames.begin(); it != sample_frames.end(); ++it) {
+		const BCSampleFrame &frame = it->second;
+		if (frame.contains(ob)) {
+			frames.push_back(it->first);
+		}
+	}
+	return frames.size();
+}
+
+const int BCSampleFrames::get_frames(Object *ob, Bone *bone, BCFrames &frames) const
 {
 	frames.clear(); // safety;
 	BCSampleFrameMap::const_iterator it;
 	for (it = sample_frames.begin(); it != sample_frames.end(); ++it) {
 		const BCSampleFrame &frame = it->second;
-		if (frame.contains(key)) {
+		if (frame.contains(ob, bone)) {
 			frames.push_back(it->first);
 		}
 	}
 	return frames.size();
 }
 
-const int BCSampleFrames::get_matrices(const BCSampleKey &key, BCFrameSampleMap &samples) const
+const int BCSampleFrames::get_matrices(Object *ob, BCFrameSampleMap &samples) const
 {
 	samples.clear(); // safety;
 	BCSampleFrameMap::const_iterator it;
 	for (it = sample_frames.begin(); it != sample_frames.end(); ++it) {
 		const BCSampleFrame &frame = it->second;
-		if (frame.contains(key)) {
-			const BCSample &matrix = frame.get_sample(key);
-			samples[it->first] = &matrix;
+		const BCSample *sample = frame.get_sample(ob);
+		if (sample) {
+			samples[it->first] = sample;
 		}
 	}
 	return samples.size();
 }
 
-const int BCSampleFrames::get_matrices(const BCSampleKey &key, BCMatrixSampleMap &samples) const
+const int BCSampleFrames::get_matrices(Object *ob, BCMatrixSampleMap &samples) const
 {
 	samples.clear(); // safety;
 	BCSampleFrameMap::const_iterator it;
 	for (it = sample_frames.begin(); it != sample_frames.end(); ++it) {
 		const BCSampleFrame &frame = it->second;
-		if (frame.contains(key)) {
-			const BCMatrix &matrix = frame.get_sample_matrix(key);
-			samples[it->first] = &matrix;
+		const BCMatrix *sample = frame.get_sample_matrix(ob);
+		if (sample) {
+			samples[it->first] = sample;
 		}
 	}
 	return samples.size();
diff --git a/source/blender/collada/BCAnimationCurveContainer.h b/source/blender/collada/BCAnimationCurveContainer.h
index b31ceddb7ef..7d86c55fe57 100644
--- a/source/blender/collada/BCAnimationCurveContainer.h
+++ b/source/blender/collada/BCAnimationCurveContainer.h
@@ -86,16 +86,15 @@ public:
 	/* Get the matrix for the given Object, returns Unity when the Objewct is not sampled */
 	/* Get the matrix for the given Bone, returns Unity when the Object is not sampled */
 	/* Get the matrix for the given Material, returns Unity when the Object is not sampled */
-	const BCSample &get_sample(const BCSampleKey key) const;
-	const BCMatrix &get_sample_matrix(const BCSampleKey key) const;
-	const BCSample &get_sample(Object *ob) const;
+	const BCSample *get_sample(Object *ob) const;
+	const BCMatrix *get_sample_matrix(Object *ob) const;
 	const BCMatrix *get_sample_matrix(Object *ob, Bone *bone) const;
 
 	/* Check if the key is in this BCSampleFrame */
 	/* Check if the Object is in this BCSampleFrame */
 	/* Check if the Bone is in this BCSampleFrame */
 	/* Check if the Material is in this BCSampleFrame */
-	const bool contains(const BCSampleKey &key) const;
+	const bool contains(const Object *ob) const;
 	const bool contains(Object *ob) const;
 	const bool contains(Object *ob, Bone *bone) const;
 
@@ -159,9 +158,10 @@ public:
 
 	/* Return a list of all frames that need to be sampled */
 	const int get_frames(std::vector<int> &frames) const;
-	const int get_frames(BCSampleKey &key, BCFrames &frames) const;
-	const int get_matrices(const BCSampleKey &key, BCFrameSampleMap &matrices) const;
-	const int get_matrices(const BCSampleKey &key, BCMatrixSampleMap &matrices) const;
+	const int get_frames(Object *ob, BCFrames &frames) const;
+	const int get_frames(Object *ob, Bone *bone, BCFrames &frames) const;
+	const int get_matrices(Object *ob, BCFrameSampleMap &matrices) const;
+	const int get_matrices(Object *ob, BCMatrixSampleMap &matrices) const;
 	const int get_matrices(Object *ob, Bone *bone, BCMatrixSampleMap &bones) const;
 };
 
diff --git a/source/blender/collada/BCSampleData.h b/source/blender/collada/BCSampleData.h
index 733b5473921..14b146136ea 100644
--- a/source/blender/collada/BCSampleData.h
+++ b/source/blender/collada/BCSampleData.h
@@ -39,7 +39,7 @@ extern "C"
 
 /*
  * The list of currently supported animation types
- * TODO: Maybe this can be made more general
+ * TODO: Maybe this can be made more general.
 */
 typedef enum BC_animation_transform_type {
 
@@ -74,45 +74,6 @@ typedef enum BC_animation_transform_type {
 
 } BC_animation_transform_type;
 
-class BCSampleKey {
-
-	/*
-	Whenever an Object or a bone is sampled
-	somewhere in the timeline we need to record the
-	local matrix for the Object or the bone. This information is then
-	stored in a BCSamplesMap with a key of type BCSampleKey.
-
-	The main purpose of this class is to have a nice way to define the keys.
-	Of course we just could feed in strings, but this looks more clean to me.
-	*/
-
-private:
-
-	std::string key; // like the rna string in fcurves but with object name prepended
-
-public:
-
-	BCSampleKey(const std::string key)
-	{
-		this->key = key;
-	}
-
-	BCSampleKey(const Object *ob)
-	{
-		this->key = std::string(ob->id.name);
-	}
-
-	BCSampleKey(const Object *ob, Bone *bone)
-	{
-		this->key = std::string(ob->id.name) + ".pose.bones[" + std::string(bone->name) + "]";
-	}
-
-	const bool operator<(const BCSampleKey &other) const
-	{
-		return this->key < other.key;
-	}
-
-};
 
 class BCMaterial {
 public:



More information about the Bf-blender-cvs mailing list