[Bf-blender-cvs] [01a9d374a7a] collada: Refactor Collada: Moved static class functions to collada_utils
Gaia Clary
noreply at git.blender.org
Tue Apr 17 13:06:33 CEST 2018
Commit: 01a9d374a7a3d6e24da49fa09abafa12a68416cd
Author: Gaia Clary
Date: Tue Apr 17 13:03:37 2018 +0200
Branches: collada
https://developer.blender.org/rB01a9d374a7a3d6e24da49fa09abafa12a68416cd
Refactor Collada: Moved static class functions to collada_utils
Reason: The functions had nothing to do with the class
===================================================================
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/BCAnimationSampler.cpp b/source/blender/collada/BCAnimationSampler.cpp
index eb56731f5fb..fe72780b883 100644
--- a/source/blender/collada/BCAnimationSampler.cpp
+++ b/source/blender/collada/BCAnimationSampler.cpp
@@ -30,6 +30,7 @@
#include "ExportSettings.h"
#include "BCAnimationCurve.h"
#include "BCAnimationSampler.h"
+#include "collada_utils.h"
extern "C" {
#include "BKE_action.h"
@@ -216,7 +217,7 @@ void BCAnimationSampler::sample_scene(
for (pchan = (bPoseChannel *)ob->pose->chanbase.first; pchan; pchan = pchan->next) {
Bone *bone = pchan->bone;
Matrix bmat;
- if (bone_matrix_local_get(ob, bone, bmat, for_opensim)) {
+ if (bc_bone_matrix_local_get(ob, bone, bmat, for_opensim)) {
ob_sample.add_bone_matrix(bone, bmat);
}
}
@@ -226,27 +227,6 @@ void BCAnimationSampler::sample_scene(
}
}
-void BCAnimationSampler::enable_fcurves(bAction *act, char *bone_name)
-{
- FCurve *fcu;
- char prefix[200];
-
- if (bone_name)
- BLI_snprintf(prefix, sizeof(prefix), "pose.bones[\"%s\"]", bone_name);
-
- for (fcu = (FCurve *)act->curves.first; fcu; fcu = fcu->next) {
- if (bone_name) {
- if (STREQLEN(fcu->rna_path, prefix, strlen(prefix)))
- fcu->flag &= ~FCURVE_DISABLED;
- else
- fcu->flag |= FCURVE_DISABLED;
- }
- else {
- fcu->flag &= ~FCURVE_DISABLED;
- }
- }
-}
-
bool BCAnimationSampler::is_animated_by_constraint(Object *ob, ListBase *conlist, std::set<Object *> &animated_objects)
{
bConstraint *con;
@@ -321,52 +301,6 @@ void BCAnimationSampler::get_animated_from_export_set(std::set<Object *> &animat
find_depending_animated(animated_objects, candidates);
}
-bool BCAnimationSampler::bone_matrix_local_get(Object *ob, Bone *bone, Matrix &mat, bool for_opensim)
-{
-
- /* Ok, lets be super cautious and check if the bone exists */
- bPose *pose = ob->pose;
- bPoseChannel *pchan = BKE_pose_channel_find_name(pose, bone->name);
- if (!pchan) {
- return false;
- }
-
- bAction *action = bc_getSceneObjectAction(ob);
- bPoseChannel *parchan = pchan->parent;
-
- enable_fcurves(action, bone->name);
- float ipar[4][4];
-
- if (bone->parent) {
- invert_m4_m4(ipar, parchan->pose_mat);
- mul_m4_m4m4(mat, ipar, pchan->pose_mat);
- }
- else
- copy_m4_m4(mat, pchan->pose_mat);
-
- /* OPEN_SIM_COMPATIBILITY
- * AFAIK animation to second life is via BVH, but no
- * reason to not have the collada-animation be correct
- */
- if (for_opensim) {
- float temp[4][4];
- copy_m4_m4(temp, bone->arm_mat);
- temp[3][0] = temp[3][1] = temp[3][2] = 0.0f;
- invert_m4(temp);
-
- mul_m4_m4m4(mat, mat, temp);
-
- if (bone->parent) {
- copy_m4_m4(temp, bone->parent->arm_mat);
- temp[3][0] = temp[3][1] = temp[3][2] = 0.0f;
-
- mul_m4_m4m4(mat, temp, mat);
- }
- }
- enable_fcurves(action, NULL);
- return true;
-}
-
bool BCAnimationSampler::is_animated(BCMatrixSampleMap &values) const
{
static float MIN_DISTANCE = 0.00001;
diff --git a/source/blender/collada/BCAnimationSampler.h b/source/blender/collada/BCAnimationSampler.h
index e14e640ba3c..e048403dfcc 100644
--- a/source/blender/collada/BCAnimationSampler.h
+++ b/source/blender/collada/BCAnimationSampler.h
@@ -28,6 +28,7 @@
#include "BCAnimationCurve.h"
#include "BCSampleData.h"
+#include "collada_utils.h"
extern "C" {
#include "BKE_action.h"
@@ -160,10 +161,6 @@ private:
void update_animation_curves(BCAnimation &animation, Object *ob, int frame_index);
void check_property_is_animated(BCAnimation &animation, float *ref, float *val, std::string data_path, int length);
- /* Helper methods */
- static void enable_fcurves(bAction *act, char *bone_name);
- static bool bone_matrix_local_get(Object *ob, Bone *bone, Matrix &mat, bool for_opensim);
-
public:
BCAnimationSampler();
diff --git a/source/blender/collada/BCSampleData.h b/source/blender/collada/BCSampleData.h
index 2a469b1274e..7cadd487a28 100644
--- a/source/blender/collada/BCSampleData.h
+++ b/source/blender/collada/BCSampleData.h
@@ -29,6 +29,7 @@
#include <string>
#include <map>
#include <algorithm>
+#include "collada_utils.h"
extern "C"
{
@@ -40,8 +41,6 @@ extern "C"
#include "DNA_camera_types.h"
}
-typedef float(Matrix)[4][4];
-
class BCMatrix {
private:
diff --git a/source/blender/collada/collada_utils.cpp b/source/blender/collada/collada_utils.cpp
index a6e1572d7f8..f736fd18ef2 100644
--- a/source/blender/collada/collada_utils.cpp
+++ b/source/blender/collada/collada_utils.cpp
@@ -46,6 +46,7 @@ extern "C" {
#include "BLI_math.h"
#include "BLI_linklist.h"
+#include "BKE_action.h"
#include "BKE_context.h"
#include "BKE_customdata.h"
#include "BKE_constraint.h"
@@ -917,6 +918,73 @@ static bool has_custom_props(Bone *bone, bool enabled, std::string key)
}
+void bc_enable_fcurves(bAction *act, char *bone_name)
+{
+ FCurve *fcu;
+ char prefix[200];
+
+ if (bone_name)
+ BLI_snprintf(prefix, sizeof(prefix), "pose.bones[\"%s\"]", bone_name);
+
+ for (fcu = (FCurve *)act->curves.first; fcu; fcu = fcu->next) {
+ if (bone_name) {
+ if (STREQLEN(fcu->rna_path, prefix, strlen(prefix)))
+ fcu->flag &= ~FCURVE_DISABLED;
+ else
+ fcu->flag |= FCURVE_DISABLED;
+ }
+ else {
+ fcu->flag &= ~FCURVE_DISABLED;
+ }
+ }
+}
+
+bool bc_bone_matrix_local_get(Object *ob, Bone *bone, Matrix &mat, bool for_opensim)
+{
+
+ /* Ok, lets be super cautious and check if the bone exists */
+ bPose *pose = ob->pose;
+ bPoseChannel *pchan = BKE_pose_channel_find_name(pose, bone->name);
+ if (!pchan) {
+ return false;
+ }
+
+ bAction *action = bc_getSceneObjectAction(ob);
+ bPoseChannel *parchan = pchan->parent;
+
+ bc_enable_fcurves(action, bone->name);
+ float ipar[4][4];
+
+ if (bone->parent) {
+ invert_m4_m4(ipar, parchan->pose_mat);
+ mul_m4_m4m4(mat, ipar, pchan->pose_mat);
+ }
+ else
+ copy_m4_m4(mat, pchan->pose_mat);
+
+ /* OPEN_SIM_COMPATIBILITY
+ * AFAIK animation to second life is via BVH, but no
+ * reason to not have the collada-animation be correct
+ */
+ if (for_opensim) {
+ float temp[4][4];
+ copy_m4_m4(temp, bone->arm_mat);
+ temp[3][0] = temp[3][1] = temp[3][2] = 0.0f;
+ invert_m4(temp);
+
+ mul_m4_m4m4(mat, mat, temp);
+
+ if (bone->parent) {
+ copy_m4_m4(temp, bone->parent->arm_mat);
+ temp[3][0] = temp[3][1] = temp[3][2] = 0.0f;
+
+ mul_m4_m4m4(mat, temp, mat);
+ }
+ }
+ bc_enable_fcurves(action, NULL);
+ return true;
+}
+
/**
* 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 9ee6b91f67f..32ad0e81df2 100644
--- a/source/blender/collada/collada_utils.h
+++ b/source/blender/collada/collada_utils.h
@@ -68,6 +68,7 @@ extern "C" {
typedef std::map<COLLADAFW::TextureMapId, std::vector<MTex *> > TexIndexTextureArrayMap;
typedef std::set<Object *> BCObjectSet;
+typedef float(Matrix)[4][4];
extern Main *bc_get_main();
extern EvaluationContext *bc_get_evaluation_context();
@@ -204,6 +205,9 @@ extern float bc_get_property(Bone *bone, std::string key, float def);
extern void bc_get_property_vector(Bone *bone, std::string key, float val[3], const float def[3]);
extern bool bc_get_property_matrix(Bone *bone, std::string key, float mat[4][4]);
+extern void bc_enable_fcurves(bAction *act, char *bone_name);
+extern bool bc_bone_matrix_local_get(Object *ob, Bone *bone, Matrix &mat, bool for_opensim);
+
extern void bc_create_restpose_mat(const ExportSettings *export_settings, Bone *bone, float to_mat[4][4], float world[4][4], bool use_local_space);
extern std::string bc_get_active_uvlayer_name(Object *ob);
More information about the Bf-blender-cvs
mailing list