[Bf-blender-cvs] [0731b88ddbb] master: refactor collada: Added utility functions bc_string_before() and bc_string_after()

Gaia Clary noreply at git.blender.org
Sun Jun 2 23:02:00 CEST 2019


Commit: 0731b88ddbbef2ca53c45b93e58c39d4ec1ce1b3
Author: Gaia Clary
Date:   Sun Jun 2 19:02:38 2019 +0200
Branches: master
https://developer.blender.org/rB0731b88ddbbef2ca53c45b93e58c39d4ec1ce1b3

refactor collada: Added utility functions bc_string_before() and bc_string_after()

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

M	source/blender/collada/BCAnimationCurve.cpp
M	source/blender/collada/collada_utils.h

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

diff --git a/source/blender/collada/BCAnimationCurve.cpp b/source/blender/collada/BCAnimationCurve.cpp
index 3ba2570ac42..57aa2f1bf29 100644
--- a/source/blender/collada/BCAnimationCurve.cpp
+++ b/source/blender/collada/BCAnimationCurve.cpp
@@ -132,7 +132,31 @@ const bool BCAnimationCurve::is_of_animation_type(BC_animation_type type) const
 const std::string BCAnimationCurve::get_channel_target() const
 {
   const std::string path = curve_key.get_path();
-  return bc_string_after(path, '.');
+
+  if (bc_startswith(path, "pose.bones")) {
+    return bc_string_after(path, "pose.bones");
+  }
+  return bc_string_after(path, ".");
+}
+
+const std::string BCAnimationCurve::get_channel_type() const
+{
+  const std::string channel = get_channel_target();
+  return bc_string_after(channel, ".");
+}
+
+const std::string BCAnimationCurve::get_channel_posebone() const
+{
+  const std::string channel = get_channel_target();
+  std::string pose_bone_name = bc_string_before(channel, ".");
+  if (pose_bone_name == channel) {
+    pose_bone_name = "";
+  }
+  else {
+    pose_bone_name = bc_string_after(pose_bone_name, "\"[");
+    pose_bone_name = bc_string_before(pose_bone_name, "]\"");
+  }
+  return pose_bone_name;
 }
 
 const std::string BCAnimationCurve::get_animation_name(Object *ob) const
diff --git a/source/blender/collada/collada_utils.h b/source/blender/collada/collada_utils.h
index 2b74d8ee3ad..dca8f414e5a 100644
--- a/source/blender/collada/collada_utils.h
+++ b/source/blender/collada/collada_utils.h
@@ -160,11 +160,20 @@ extern int bc_get_active_UVLayer(Object *ob);
 
 std::string bc_find_bonename_in_path(std::string path, std::string probe);
 
-inline std::string bc_string_after(const std::string &s, const char c)
+inline std::string bc_string_after(const std::string &s, const std::string probe)
 {
-  size_t i = s.rfind(c, s.length());
+  size_t i = s.rfind(probe);
   if (i != std::string::npos) {
-    return (s.substr(i + 1, s.length() - i));
+    return (s.substr(i + probe.length(), s.length() - i));
+  }
+  return (s);
+}
+
+inline std::string bc_string_before(const std::string &s, const std::string probe)
+{
+  size_t i = s.find(probe);
+  if (i != std::string::npos) {
+    return s.substr(0, i);
   }
   return (s);
 }
@@ -177,6 +186,14 @@ inline bool bc_startswith(std::string const &value, std::string const &starting)
   return (value.substr(0, starting.size()) == starting);
 }
 
+inline bool bc_endswith(const std::string &value, const std::string &ending)
+{
+  if (ending.size() > value.size())
+    return false;
+
+  return value.compare(value.size() - ending.size(), ending.size(), ending) == 0;
+}
+
 #if 0 /* UNUSED */
 inline bool bc_endswith(std::string const &value, std::string const &ending)
 {



More information about the Bf-blender-cvs mailing list