[Bf-blender-cvs] [1c17b2d] temp-sybren-poselib: WIP pose library stuff

Sybren A. Stüvel noreply at git.blender.org
Wed Sep 28 17:57:33 CEST 2016


Commit: 1c17b2dff84f11f800dd7bf6dd521e1a81e9f874
Author: Sybren A. Stüvel
Date:   Wed Sep 28 17:57:16 2016 +0200
Branches: temp-sybren-poselib
https://developer.blender.org/rB1c17b2dff84f11f800dd7bf6dd521e1a81e9f874

WIP pose library stuff

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

A	release/scripts/startup/bl_operators/poselib.py
M	release/scripts/startup/bl_ui/properties_data_armature.py
M	source/blender/blenkernel/intern/anim_sys.c
M	source/blender/editors/armature/pose_lib.c
M	source/blender/editors/armature/pose_transform.c

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

diff --git a/release/scripts/startup/bl_operators/poselib.py b/release/scripts/startup/bl_operators/poselib.py
new file mode 100644
index 0000000..7b550df
--- /dev/null
+++ b/release/scripts/startup/bl_operators/poselib.py
@@ -0,0 +1,78 @@
+# ##### BEGIN GPL LICENSE BLOCK #####
+#
+#  This program is free software; you can redistribute it and/or
+#  modify it under the terms of the GNU General Public License
+#  as published by the Free Software Foundation; either version 2
+#  of the License, or (at your option) any later version.
+#
+#  This program is distributed in the hope that it will be useful,
+#  but WITHOUT ANY WARRANTY; without even the implied warranty of
+#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#  GNU General Public License for more details.
+#
+#  You should have received a copy of the GNU General Public License
+#  along with this program; if not, write to the Free Software Foundation,
+#  Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+# ##### END GPL LICENSE BLOCK #####
+
+# <pep8-80 compliant>
+
+if "bpy" in locals():
+    from importlib import reload
+    if "anim_utils" in locals():
+        reload(anim_utils)
+    del reload
+
+
+import bpy
+from bpy.types import Operator
+from bpy.props import (
+        IntProperty,
+        BoolProperty,
+        EnumProperty,
+        StringProperty,
+        )
+
+
+class POSELIB_OT_render_previews(Operator):
+    "Renders a preview image for each pose in the pose library"
+
+    bl_idname = "poselib.render_previews"
+    bl_label = "Render pose previews"
+
+    render_method = EnumProperty(
+        items=[
+            ('OPENGL', 'OpenGL render', 'Use the OpenGL viewport render'),
+            ('FULL', 'Full render', 'Use the same render engine as the scene'),
+        ],
+        default='OPENGL'
+    )
+
+    plib_index = 0
+
+    @classmethod
+    def poll(cls, context):
+        """Running only makes sense if there are any poses in the library."""
+        plib = context.object and context.object.pose_library
+        return bool(plib and plib.pose_markers)
+
+    def execute(self, context):
+        plib = context.object.pose_library
+
+        if self.plib_index >= len(plib.pose_markers):
+            return {'FINISHED'}
+
+        self.render_pose(self.plib_index)
+        self.plib_index += 1
+
+        return {'RUNNING_MODAL'}
+
+    def render_pose(self, plib_index):
+        bpy.ops.poselib.apply_pose(pose_index=plib_index)
+
+    def invoke(self, context, event):
+        wm = context.window_manager
+        wm.modal_handler_add(self)
+        self.plib_index = 0
+        return {'RUNNING_MODAL'}
diff --git a/release/scripts/startup/bl_ui/properties_data_armature.py b/release/scripts/startup/bl_ui/properties_data_armature.py
index 8261f0c..fef384b 100644
--- a/release/scripts/startup/bl_ui/properties_data_armature.py
+++ b/release/scripts/startup/bl_ui/properties_data_armature.py
@@ -205,6 +205,7 @@ class DATA_PT_pose_library(ArmatureButtonsPanel, Panel):
                 col.operator("poselib.pose_move", icon='TRIA_UP', text="").direction = 'UP'
                 col.operator("poselib.pose_move", icon='TRIA_DOWN', text="").direction = 'DOWN'
 
+            row.operator("poselib.render_previews")
 
 # TODO: this panel will soon be deprecated too
 class DATA_PT_ghost(ArmatureButtonsPanel, Panel):
diff --git a/source/blender/blenkernel/intern/anim_sys.c b/source/blender/blenkernel/intern/anim_sys.c
index e3764ad..b41030e 100644
--- a/source/blender/blenkernel/intern/anim_sys.c
+++ b/source/blender/blenkernel/intern/anim_sys.c
@@ -59,6 +59,7 @@
 #include "BKE_animsys.h"
 #include "BKE_action.h"
 #include "BKE_context.h"
+#include "BKE_deform.h"
 #include "BKE_depsgraph.h"
 #include "BKE_fcurve.h"
 #include "BKE_nla.h"
diff --git a/source/blender/editors/armature/pose_lib.c b/source/blender/editors/armature/pose_lib.c
index 9309592..a0b483c 100644
--- a/source/blender/editors/armature/pose_lib.c
+++ b/source/blender/editors/armature/pose_lib.c
@@ -45,6 +45,7 @@
 #include "BKE_animsys.h"
 #include "BKE_action.h"
 #include "BKE_armature.h"
+#include "BKE_deform.h"
 #include "BKE_depsgraph.h"
 #include "BKE_global.h"
 #include "BKE_idprop.h"
@@ -866,7 +867,8 @@ enum {
 /* defines for tPoseLib_PreviewData->flag values */
 enum {
 	PL_PREVIEW_FIRSTTIME    = (1 << 0),
-	PL_PREVIEW_SHOWORIGINAL = (1 << 1)
+	PL_PREVIEW_SHOWORIGINAL = (1 << 1),
+	PL_PREVIEW_APPLY_FLIPPED = (1 << 2),
 };
 
 /* ---------------------------- */
@@ -966,11 +968,13 @@ static void poselib_apply_pose(tPoseLib_PreviewData *pld)
 	bPoseChannel *pchan;
 	bAction *act = pld->act;
 	bActionGroup *agrp;
-	
+	bool flip = pld->flag & PL_PREVIEW_APPLY_FLIPPED;
+
 	KeyframeEditData ked = {{NULL}};
 	KeyframeEditFunc group_ok_cb;
 	int frame = 1;
-	
+	char name[MAXBONENAME];
+
 	/* get the frame */
 	if (pld->marker)
 		frame = pld->marker->frame;
@@ -989,8 +993,12 @@ static void poselib_apply_pose(tPoseLib_PreviewData *pld)
 		/* check if group has any keyframes */
 		if (ANIM_animchanneldata_keyframes_loop(&ked, NULL, agrp, ALE_GROUP, NULL, group_ok_cb, NULL)) {
 			/* has keyframe on this frame, so try to get a PoseChannel with this name */
-			pchan = BKE_pose_channel_find_name(pose, agrp->name);
-			
+			if (flip)
+				BKE_deform_flip_side_name(name, agrp->name, false);
+			else
+				BLI_strncpy(name, agrp->name, sizeof(name));
+			pchan = BKE_pose_channel_find_name(pose, name);
+
 			if (pchan) {
 				bool ok = 0;
 				
diff --git a/source/blender/editors/armature/pose_transform.c b/source/blender/editors/armature/pose_transform.c
index b645f1f..d5c9cc5 100644
--- a/source/blender/editors/armature/pose_transform.c
+++ b/source/blender/editors/armature/pose_transform.c
@@ -269,6 +269,39 @@ static void set_pose_keys(Object *ob)
 	}
 }
 
+static void flip_pose_channel(bPoseChannel *pchan)
+{
+	pchan->loc[0] *= -1;
+
+	pchan->curveInX *= -1;
+	pchan->curveOutX *= -1;
+	pchan->roll1 *= -1; // XXX?
+	pchan->roll2 *= -1; // XXX?
+
+	/* has to be done as eulers... */
+	if (pchan->rotmode > 0) {
+		pchan->eul[1] *= -1;
+		pchan->eul[2] *= -1;
+	}
+	else if (pchan->rotmode == ROT_MODE_AXISANGLE) {
+		float eul[3];
+
+		axis_angle_to_eulO(eul, EULER_ORDER_DEFAULT, pchan->rotAxis, pchan->rotAngle);
+		eul[1] *= -1;
+		eul[2] *= -1;
+		eulO_to_axis_angle(pchan->rotAxis, &pchan->rotAngle, eul, EULER_ORDER_DEFAULT);
+	}
+	else {
+		float eul[3];
+
+		normalize_qt(pchan->quat);
+		quat_to_eul(eul, pchan->quat);
+		eul[1] *= -1;
+		eul[2] *= -1;
+		eul_to_quat(pchan->quat, eul);
+	}
+}
+
 /**
  * Perform paste pose, for a single bone.
  *
@@ -357,39 +390,8 @@ static bPoseChannel *pose_bone_do_paste(Object *ob, bPoseChannel *chan, const bo
 		pchan->scaleIn = chan->scaleIn;
 		pchan->scaleOut = chan->scaleOut;
 		
-		/* paste flipped pose? */
-		if (flip) {
-			pchan->loc[0] *= -1;
-			
-			pchan->curveInX *= -1;
-			pchan->curveOutX *= -1;
-			pchan->roll1 *= -1; // XXX?
-			pchan->roll2 *= -1; // XXX?
-			
-			/* has to be done as eulers... */
-			if (pchan->rotmode > 0) {
-				pchan->eul[1] *= -1;
-				pchan->eul[2] *= -1;
-			}
-			else if (pchan->rotmode == ROT_MODE_AXISANGLE) {
-				float eul[3];
-				
-				axis_angle_to_eulO(eul, EULER_ORDER_DEFAULT, pchan->rotAxis, pchan->rotAngle);
-				eul[1] *= -1;
-				eul[2] *= -1;
-				eulO_to_axis_angle(pchan->rotAxis, &pchan->rotAngle, eul, EULER_ORDER_DEFAULT);
-			}
-			else {
-				float eul[3];
-				
-				normalize_qt(pchan->quat);
-				quat_to_eul(eul, pchan->quat);
-				eul[1] *= -1;
-				eul[2] *= -1;
-				eul_to_quat(pchan->quat, eul);
-			}
-		}
-		
+		if (flip) flip_pose_channel(pchan);
+
 		/* ID properties */
 		if (chan->prop) {
 			if (pchan->prop) {




More information about the Bf-blender-cvs mailing list