Revision: 18135
          
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=18135
Author:   aligorith
Date:     2008-12-29 02:19:25 +0100 (Mon, 29 Dec 2008)

Log Message:
-----------
2.5 - Action Editor / Animation Stuff:

* Brought back clean (OKEY), sample (Shift-OKEY), and delete (XKEY/DELKEY) 
tools for the Action Editor. 
Currently clean uses a predefined threshold (as a rna-prop, though it's still 
lacking the popup to set this when it is called)

* Added new file for 'destructive' keyframe operations/tools. 

* Got keyframing.c compiling. Now, some of these tools need to be operatorised. 
Also, the API there might change when enough of the system is stable for 
RNA-IPO work to take place (so that it can be tested).

Modified Paths:
--------------
    branches/blender2.5/blender/source/blender/blenkernel/BKE_action.h
    branches/blender2.5/blender/source/blender/blenkernel/intern/action.c
    branches/blender2.5/blender/source/blender/editors/animation/anim_deps.c
    
branches/blender2.5/blender/source/blender/editors/animation/keyframes_edit.c
    branches/blender2.5/blender/source/blender/editors/animation/keyframing.c
    branches/blender2.5/blender/source/blender/editors/include/ED_anim_api.h
    
branches/blender2.5/blender/source/blender/editors/include/ED_keyframes_edit.h
    branches/blender2.5/blender/source/blender/editors/include/ED_keyframing.h
    
branches/blender2.5/blender/source/blender/editors/space_action/action_edit_keyframes.c
    
branches/blender2.5/blender/source/blender/editors/space_action/action_header.c
    
branches/blender2.5/blender/source/blender/editors/space_action/action_intern.h
    branches/blender2.5/blender/source/blender/editors/space_action/action_ops.c
    
branches/blender2.5/blender/source/blender/editors/space_action/action_select.c
    
branches/blender2.5/blender/source/blender/editors/space_outliner/space_outliner.c
    branches/blender2.5/blender/source/blender/makesdna/DNA_userdef_types.h

Added Paths:
-----------
    
branches/blender2.5/blender/source/blender/editors/animation/keyframes_general.c

Modified: branches/blender2.5/blender/source/blender/blenkernel/BKE_action.h
===================================================================
--- branches/blender2.5/blender/source/blender/blenkernel/BKE_action.h  
2008-12-29 00:55:23 UTC (rev 18134)
+++ branches/blender2.5/blender/source/blender/blenkernel/BKE_action.h  
2008-12-29 01:19:25 UTC (rev 18135)
@@ -51,6 +51,7 @@
 extern "C" {
 #endif
 
+struct bAction *add_empty_action(const char name[]);
        
 /**
  * Removes and deallocates all channels from a pose.

Modified: branches/blender2.5/blender/source/blender/blenkernel/intern/action.c
===================================================================
--- branches/blender2.5/blender/source/blender/blenkernel/intern/action.c       
2008-12-29 00:55:23 UTC (rev 18134)
+++ branches/blender2.5/blender/source/blender/blenkernel/intern/action.c       
2008-12-29 01:19:25 UTC (rev 18135)
@@ -81,6 +81,17 @@
 
 /* ***************** Library data level operations on action ************** */
 
+bAction *add_empty_action(const char name[])
+{
+       bAction *act;
+       
+       act= alloc_libblock(&G.main->action, ID_AC, name);
+       act->id.flag |= LIB_FAKEUSER;
+       act->id.us++;
+       
+       return act;
+}      
+
 static void make_local_action_channels(bAction *act)
 {
        bActionChannel *chan;

Modified: 
branches/blender2.5/blender/source/blender/editors/animation/anim_deps.c
===================================================================
--- branches/blender2.5/blender/source/blender/editors/animation/anim_deps.c    
2008-12-29 00:55:23 UTC (rev 18134)
+++ branches/blender2.5/blender/source/blender/editors/animation/anim_deps.c    
2008-12-29 01:19:25 UTC (rev 18135)
@@ -73,7 +73,7 @@
 
 /* generic update flush, reads from context Screen (layers) and scene */
 /* this is for compliancy, later it can do all windows etc */
-void ED_anim_dag_flush_update(bContext *C)
+void ED_anim_dag_flush_update(const bContext *C)
 {
        Scene *scene= CTX_data_scene(C);
        bScreen *screen= CTX_wm_screen(C);

Modified: 
branches/blender2.5/blender/source/blender/editors/animation/keyframes_edit.c
===================================================================
--- 
branches/blender2.5/blender/source/blender/editors/animation/keyframes_edit.c   
    2008-12-29 00:55:23 UTC (rev 18134)
+++ 
branches/blender2.5/blender/source/blender/editors/animation/keyframes_edit.c   
    2008-12-29 01:19:25 UTC (rev 18135)
@@ -17,8 +17,7 @@
  * along with this program; if not, write to the Free Software Foundation,
  * Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
+ * The Original Code is Copyright (C) 2008 Blender Foundation
  *
  * Contributor(s): Joshua Leung
  *
@@ -30,6 +29,8 @@
 #include <math.h>
 #include <float.h>
 
+#include "MEM_guardedalloc.h"
+
 #include "BLI_blenlib.h"
 #include "BLI_arithb.h"
 

Added: 
branches/blender2.5/blender/source/blender/editors/animation/keyframes_general.c
===================================================================
--- 
branches/blender2.5/blender/source/blender/editors/animation/keyframes_general.c
                            (rev 0)
+++ 
branches/blender2.5/blender/source/blender/editors/animation/keyframes_general.c
    2008-12-29 01:19:25 UTC (rev 18135)
@@ -0,0 +1,364 @@
+/**
+ * $Id: 
+ *
+ * ***** 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., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ *
+ * The Original Code is Copyright (C) 2008 Blender Foundation
+ * All rights reserved.
+ *
+ * Contributor(s): Joshua Leung
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+#include <stdlib.h>
+#include <string.h>
+#include <math.h>
+#include <float.h>
+
+#include "MEM_guardedalloc.h"
+
+#include "BLI_blenlib.h"
+#include "BLI_arithb.h"
+
+#include "DNA_action_types.h"
+#include "DNA_curve_types.h"
+#include "DNA_ipo_types.h"
+#include "DNA_key_types.h"
+#include "DNA_object_types.h"
+#include "DNA_space_types.h"
+#include "DNA_scene_types.h"
+
+#include "BKE_action.h"
+#include "BKE_ipo.h"
+#include "BKE_key.h"
+#include "BKE_utildefines.h"
+
+#include "ED_anim_api.h"
+#include "ED_keyframing.h"
+#include "ED_keyframes_edit.h"
+
+/* This file contains code for various keyframe-editing tools which are 
'destructive'
+ * (i.e. they will modify the order of the keyframes, and change the size of 
the array).
+ * While some of these tools may eventually be moved out into blenkernel, for 
now, it is
+ * fine to have these calls here.
+ * 
+ * There are also a few tools here which cannot be easily coded for in the 
other system (yet).
+ * These may also be moved around at some point, but for now, they 
+ *
+ * - Joshua Leung, Dec 2008
+ */
+ 
+/* **************************************************** */
+
+/* Only delete the nominated keyframe from provided ipo-curve. 
+ * Not recommended to be used many times successively. For that
+ * there is delete_ipo_keys(). 
+ */
+void delete_icu_key(IpoCurve *icu, int index, short do_recalc)
+{
+       /* firstly check that index is valid */
+       if (index < 0) 
+               index *= -1;
+       if (icu == NULL) 
+               return;
+       if (index >= icu->totvert)
+               return;
+       
+       /*      Delete this key */
+       memmove(&icu->bezt[index], &icu->bezt[index+1], 
sizeof(BezTriple)*(icu->totvert-index-1));
+       icu->totvert--;
+       
+       /* recalc handles - only if it won't cause problems */
+       if (do_recalc)
+               calchandles_ipocurve(icu);
+}
+
+/* Delete selected keyframes in given IPO block */
+void delete_ipo_keys(Ipo *ipo)
+{
+       IpoCurve *icu, *next;
+       int i;
+       
+       if (ipo == NULL)
+               return;
+       
+       for (icu= ipo->curve.first; icu; icu= next) {
+               /* store pointer to next ipo-curve, as we may delete the 
current one */
+               next = icu->next;
+               
+               /* Delete selected BezTriples */
+               for (i=0; i<icu->totvert; i++) {
+                       if (icu->bezt[i].f2 & SELECT) {
+                               memmove(&icu->bezt[i], &icu->bezt[i+1], 
sizeof(BezTriple)*(icu->totvert-i-1));
+                               icu->totvert--;
+                               i--;
+                       }
+               }
+               
+               /* Only delete if there isn't an ipo-driver still hanging 
around on an empty curve */
+               if ((icu->totvert==0) && (icu->driver==NULL)) {
+                       BLI_remlink(&ipo->curve, icu);
+                       free_ipo_curve(icu);
+               }
+       }
+}
+
+/* ---------------- */
+
+/* duplicate selected keyframes for the given IPO block */
+void duplicate_ipo_keys(Ipo *ipo)
+{
+       IpoCurve *icu;
+       BezTriple *newbezt;
+       int i;
+
+       if (ipo == NULL)
+               return;
+
+       for (icu= ipo->curve.first; icu; icu= icu->next) {
+               for (i=0; i<icu->totvert; i++) {
+                       /* If a key is selected */
+                       if (icu->bezt[i].f2 & SELECT) {
+                               /* Expand the list */
+                               newbezt = MEM_callocN(sizeof(BezTriple) * 
(icu->totvert+1), "beztriple");
+                               
+                               memcpy(newbezt, icu->bezt, sizeof(BezTriple) * 
(i+1));
+                               memcpy(newbezt+i+1, icu->bezt+i, 
sizeof(BezTriple));
+                               memcpy(newbezt+i+2, icu->bezt+i+1, sizeof 
(BezTriple) *(icu->totvert-(i+1)));
+                               icu->totvert++;
+                               
+                               /* reassign pointers... (free old, and add new) 
*/
+                               MEM_freeN(icu->bezt);
+                               icu->bezt=newbezt;
+                               
+                               /* Unselect the current key*/
+                               BEZ_DESEL(&icu->bezt[i]);
+                               i++;
+                               
+                               /* Select the copied key */
+                               BEZ_SEL(&icu->bezt[i]);
+                       }
+               }
+       }
+}
+
+/* **************************************************** */
+/* Various Tools */
+
+/* Basic IPO-Curve 'cleanup' function that removes 'double points' and 
unnecessary keyframes on linear-segments only */
+void clean_ipo_curve(IpoCurve *icu, float thresh)
+{
+       BezTriple *old_bezts, *bezt, *beztn;
+       BezTriple *lastb;
+       int totCount, i;
+       
+       /* check if any points  */
+       if ((icu == NULL) || (icu->totvert <= 1)) 
+               return;
+       
+       /* make a copy of the old BezTriples, and clear IPO curve */
+       old_bezts = icu->bezt;
+       totCount = icu->totvert;        
+       icu->bezt = NULL;
+       icu->totvert = 0;
+       
+       /* now insert first keyframe, as it should be ok */
+       bezt = old_bezts;
+       insert_vert_icu(icu, bezt->vec[1][0], bezt->vec[1][1], 0);
+       
+       /* Loop through BezTriples, comparing them. Skip any that do 
+        * not fit the criteria for "ok" points.
+        */
+       for (i=1; i<totCount; i++) {    
+               float prev[2], cur[2], next[2];
+               
+               /* get BezTriples and their values */
+               if (i < (totCount - 1)) {
+                       beztn = (old_bezts + (i+1));
+                       next[0]= beztn->vec[1][0]; next[1]= beztn->vec[1][1];
+               }
+               else {
+                       beztn = NULL;
+                       next[0] = next[1] = 0.0f;
+               }
+               lastb= (icu->bezt + (icu->totvert - 1));
+               bezt= (old_bezts + i);
+               
+               /* get references for quicker access */
+               prev[0] = lastb->vec[1][0]; prev[1] = lastb->vec[1][1];
+               cur[0] = bezt->vec[1][0]; cur[1] = bezt->vec[1][1];
+               
+               /* check if current bezt occurs at same time as last ok */
+               if (IS_EQT(cur[0], prev[0], thresh)) {
+                       /* If there is a next beztriple, and if occurs at the 
same time, only insert 
+                        * if there is a considerable distance between the 
points, and also if the 
+                        * current is further away than the next one is to the 
previous.
+                        */
+                       if (beztn && (IS_EQT(cur[0], next[0], thresh)) && 
+                               (IS_EQT(next[1], prev[1], thresh)==0)) 
+                       {
+                               /* only add if current is further away from 
previous */
+                               if (cur[1] > next[1]) {
+                                       if (IS_EQT(cur[1], prev[1], thresh) == 
0) {
+                                               /* add new keyframe */
+                                               insert_vert_icu(icu, cur[0], 
cur[1], 0);
+                                       }
+                               }
+                       }
+                       else {
+                               /* only add if values are a considerable 
distance apart */
+                               if (IS_EQT(cur[1], prev[1], thresh) == 0) {
+                                       /* add new keyframe */
+                                       insert_vert_icu(icu, cur[0], cur[1], 0);
+                               }
+                       }
+               }
+               else {
+                       /* checks required are dependent on whether this is 
last keyframe or not */
+                       if (beztn) {
+                               /* does current have same value as previous and 
next? */
+                               if (IS_EQT(cur[1], prev[1], thresh) == 0) {
+                                       /* add new keyframe*/
+                                       insert_vert_icu(icu, cur[0], cur[1], 0);
+                               }
+                               else if (IS_EQT(cur[1], next[1], thresh) == 0) {
+                                       /* add new keyframe */
+                                       insert_vert_icu(icu, cur[0], cur[1], 0);
+                               }
+                       }
+                       else {  
+                               /* add if value doesn't equal that of previous 
*/

@@ Diff output truncated at 10240 characters. @@

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to