[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [12171] trunk/blender/source/blender: == IPO Editor Transform Refactor ==

Joshua Leung aligorith at gmail.com
Sun Sep 30 13:43:16 CEST 2007


Revision: 12171
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=12171
Author:   aligorith
Date:     2007-09-30 13:43:16 +0200 (Sun, 30 Sep 2007)

Log Message:
-----------
== IPO Editor Transform Refactor ==

As with the Action and NLA editors, I've refactored the transform code for the IPO editor to get rid of the special (and clunky) transform loop that had been created. The approach this time is closer to the one taken for the UV/Image editor.

What's New/Will-be-possible-in-the-future:
* Numeric input now works for the IPO editor
* Proportional Edit support for the IPO editor will eventually be added. 
* Rotation (hopefully), once some hotkeys have been remapped

Known Problems:
* If a keyframe moves past neighbouring keyframes and the transform gets cancelled, it doesn't get restored correctly. This problem is quite icky to resolve (I've got a large hack for this, but that currently segfaults randomly).
* When scaling, the dashed-line (helpline) is drawn from the wrong starting co-ordinates. This does not affect the actual scaling though
* Trying to scale BezTriples with autohandles still doesn't work if either of the handles haven't been transformed yet. This behaviour was already present prior to this commit.

Modified Paths:
--------------
    trunk/blender/source/blender/include/BSE_editipo.h
    trunk/blender/source/blender/include/transform.h
    trunk/blender/source/blender/src/editipo.c
    trunk/blender/source/blender/src/transform.c
    trunk/blender/source/blender/src/transform_conversions.c
    trunk/blender/source/blender/src/transform_generics.c

Modified: trunk/blender/source/blender/include/BSE_editipo.h
===================================================================
--- trunk/blender/source/blender/include/BSE_editipo.h	2007-09-30 08:28:15 UTC (rev 12170)
+++ trunk/blender/source/blender/include/BSE_editipo.h	2007-09-30 11:43:16 UTC (rev 12171)
@@ -44,6 +44,7 @@
 struct IpoKey;
 struct TransOb;
 struct Tex;
+struct TransInfo;
 
 void remake_object_ipos(struct Object *ob);
 char *getname_ac_ei(int nr);
@@ -138,12 +139,14 @@
 void movekey_obipo(int dir);
 void nextkey_ipo(int dir);
 void nextkey_obipo(int dir);
-void remake_ipo_transverts(struct TransVert *transmain, float *dvec, int tot);
-void transform_ipo(int mode);
 void filter_sampledata(float *data, int sfra, int efra);
 void sampledata_to_ipocurve(float *data, int sfra, int efra, struct IpoCurve *icu);
-void ipo_record(void);    
+void ipo_record(void); 
 
+void make_ipo_transdata(struct TransInfo *t);
+void remake_ipo_transdata(struct TransInfo *t);
+void transform_ipo(int mode);   
+
 void actstrip_map_ipo_keys(struct Object *ob, struct Ipo *ipo, short restore, short only_keys);
 
 void sethandles_ipo_keys(struct Ipo *ipo, int code);

Modified: trunk/blender/source/blender/include/transform.h
===================================================================
--- trunk/blender/source/blender/include/transform.h	2007-09-30 08:28:15 UTC (rev 12170)
+++ trunk/blender/source/blender/include/transform.h	2007-09-30 11:43:16 UTC (rev 12171)
@@ -265,9 +265,10 @@
 #define TD_NOTCONNECTED		8
 #define TD_SINGLESIZE		16	/* used for scaling of MetaElem->rad */
 #ifdef WITH_VERSE
-#define TD_VERSE_OBJECT		32
-#define TD_VERSE_VERT		64
+	#define TD_VERSE_OBJECT		32
+	#define TD_VERSE_VERT		64
 #endif
+#define TD_TIMEONLY			128
 
 /* transsnap->status */
 #define SNAP_ON			1
@@ -350,6 +351,7 @@
 
 /*********************** transform_conversions.c ********** */
 struct ListBase;
+void flushTransIpoData(TransInfo *t);
 void flushTransUVs(TransInfo *t);
 int clipUVTransform(TransInfo *t, float *vec, int resize);
 

Modified: trunk/blender/source/blender/src/editipo.c
===================================================================
--- trunk/blender/source/blender/src/editipo.c	2007-09-30 08:28:15 UTC (rev 12170)
+++ trunk/blender/source/blender/src/editipo.c	2007-09-30 11:43:16 UTC (rev 12171)
@@ -117,6 +117,7 @@
 
 #include "blendef.h"
 #include "mydevice.h"
+#include "transform.h"
 
 extern int ob_ar[];
 extern int ma_ar[];
@@ -4763,483 +4764,254 @@
 
 }
 /* **************************************************** */
+/* IPO TRANSFORM TOOLS 
+ * 
+ * Only the helper functions are stored here these days. They are here as
+ * there are heaps of ugly globals which the IPO editor relies on. 
+ * However, the actual transforms go through the transform system these days.
+ */
 
-
-void remake_ipo_transverts(TransVert *transmain, float *dvec, int tot)
+/* Helper function for make_ipo_transdata, which is reponsible for associating
+ * source data with transform data
+ */
+static void bezt_to_transdata (TransData *td, TransData2D *td2d, float *loc, float *cent, short selected, short onlytime)
 {
-	EditIpo *ei;
-	TransVert *tv;
-	BezTriple *bezt;
-	int a, b;
+	/* New location from td gets dumped onto the old-location of td2d, which then
+	 * gets copied to the actual data at td2d->loc2d (bezt->vec[n])
+	 *
+	 * Due to NLA scaling, we apply NLA scaling to some of the verts here,
+	 * and then that scaling will be undone after transform is done.
+	 */
 	
-	ei= G.sipo->editipo;
-	for(a=0; a<G.sipo->totipo; a++, ei++) {
+	if (NLA_IPO_SCALED) {
+		td2d->loc[0] = get_action_frame_inv(OBACT, loc[0]);
+		td2d->loc[1] = loc[1];
+		td2d->loc[2] = 0.0f;
+		td2d->loc2d = loc;
 		
-		if (ISPOIN(ei, flag & IPO_VISIBLE, icu)) {
-				
-			if(ei->icu->bezt) {
-				sort_time_ipocurve(ei->icu);
-			}
-		}
+		td->flag = 0;
+		td->loc = td2d->loc;
+		VECCOPY(td->center, cent);
+		VECCOPY(td->iloc, td->loc);
 	}
-
-	ei= G.sipo->editipo;
-	tv= transmain;
-	for(a=0; a<G.sipo->totipo; a++, ei++) {
+	else {
+		td2d->loc[0] = loc[0];
+		td2d->loc[1] = loc[1];
+		td2d->loc[2] = 0.0f;
+		td2d->loc2d = loc;
 		
-		if (ISPOIN(ei, flag & IPO_VISIBLE, icu)) {
-			if( (ei->flag & IPO_EDIT) || G.sipo->showkey) {
-				if(ei->icu->bezt) {
-					bezt= ei->icu->bezt;
-					b= ei->icu->totvert;
-					while(b--) {
-						if(ei->icu->ipo==IPO_BEZ) {
-							if(bezt->f1 & 1) {
-								tv->loc= bezt->vec[0];
-								tv++;
-							}
-							if(bezt->f3 & 1) {
-								tv->loc= bezt->vec[2];
-								tv++;
-							}
-						}
-						if(bezt->f2 & 1) {
-							tv->loc= bezt->vec[1];
-							tv++;
-						}
-						
-						bezt++;
-					}
-					testhandles_ipocurve(ei->icu);
-				}
-			}
-		}
+		td->flag = 0;
+		td->loc = td2d->loc;
+		VECCOPY(td->center, cent);
+		VECCOPY(td->iloc, td->loc);
 	}
+
+	memset(td->axismtx, 0, sizeof(td->axismtx));
+	td->axismtx[2][2] = 1.0f;
+
+	td->ext= NULL; td->tdi= NULL; td->val= NULL;
+
+	if (selected) {
+		td->flag |= TD_SELECTED;
+		td->dist= 0.0;
+	}
+	else
+		td->dist= MAXFLOAT;
 	
-	if(G.sipo->showkey) make_ipokey();
+	if (onlytime)
+		td->flag |= TD_TIMEONLY;
 	
-	if(dvec==0) return;
+	Mat3One(td->mtx);
+	Mat3One(td->smtx);
+}	
+ 
+/* This function is called by createTransIpoData and remake_ipo_transdata to
+ * create the TransData and TransData2D arrays for transform. The costly counting
+ * stage is only performed for createTransIpoData case, and is indicated by t->total==-1;
+ */
+void make_ipo_transdata (TransInfo *t)
+{
+	TransData *td = NULL;
+	TransData2D *td2d = NULL;
 	
-	tv= transmain;
-	for(a=0; a<tot; a++, tv++) {
-		if (NLA_IPO_SCALED) {
-			tv->oldloc[0] = get_action_frame_inv(OBACT, tv->loc[0]);
-			tv->oldloc[0]-= dvec[0];
-			tv->oldloc[0] = get_action_frame(OBACT, tv->oldloc[0]);
+	EditIpo *ei;
+	BezTriple *bezt;
+	int a, b;
+	
+	/* countsel and propmode are used for proportional edit, which is not yet available */
+	int count=0/*, countsel=0*/;
+	/*int propmode = t->flag & T_PROP_EDIT;*/
+	
+	/* count data and allocate memory (if needed) */
+	if (t->total == 0) {
+		/* count data first */
+		if (totipo_vertsel) {
+			/* we're probably in editmode, so only selected verts */
+			count= totipo_vertsel;
 		}
+		else if (totipo_edit==0 && totipo_sel!=0) {
+			/* we're not in editmode, so entire curves get moved */
+			ei= G.sipo->editipo;
+			for (a=0; a<G.sipo->totipo; a++, ei++) {
+				if (ISPOIN3(ei, flag & IPO_VISIBLE, flag & IPO_SELECT, icu)) {
+					if (ei->icu->bezt && ei->icu->ipo==IPO_BEZ)
+						count+= 3*ei->icu->totvert;
+					else 
+						count+= ei->icu->totvert;
+				}
+			}
+			if (count==0) return;
+		}
 		else {
-			tv->oldloc[0]= tv->loc[0]-dvec[0];
+			/* this case should not happen */
+			return;
 		}
-		tv->oldloc[1]= tv->loc[1]-dvec[1];
+		
+		/* memory allocation */
+		/*t->total= (propmode)? count: countsel;*/
+		t->total= count;
+		t->data= MEM_callocN(t->total*sizeof(TransData), "TransData (IPO Editor)");
+			/* for each 2d vert a 3d vector is allocated, so that they can be treated just as if they were 3d verts */
+		t->data2d= MEM_callocN(t->total*sizeof(TransData2D), "TransData2D (IPO Editor)");
 	}
-}
-
-#define CLAMP_OFF	0
-#define CLAMP_X		1
-#define CLAMP_Y		2
-
-void transform_ipo(int mode)
-{
-	EditIpo *ei;
-	BezTriple *bezt;
-	TransVert *transmain = NULL, *tv;
-	float dx, dy, dvec[2], min[3], max[3], vec[2], div, cent[2], size[2], sizefac;
-	int tot=0, a, b, firsttime=1, afbreek=0, dosort, clampAxis=CLAMP_OFF;
-	unsigned short event = 0;
-	short mval[2], val, xo, yo, xn, yn, xc, yc;
-	char str[64];
 	
-	if(G.sipo->ipo && G.sipo->ipo->id.lib) return;
-	if(G.sipo->editipo==0) return;
-	if(mode=='r') return;	/* from gesture */
+	td= t->data;
+	td2d= t->data2d;
 	
-	INIT_MINMAX(min, max);
-	
-	/* which vertices are involved */
-	get_status_editipo();
-	if(totipo_vertsel) {
-		tot= totipo_vertsel;
-		tv=transmain= MEM_callocN(tot*sizeof(TransVert), "transmain");
-		
+	/* add verts */
+	if (totipo_vertsel) {
+		/* we're probably in editmode, so only selected verts */
 		ei= G.sipo->editipo;
-		for(a=0; a<G.sipo->totipo; a++, ei++) {
-			
+		for (a=0; a<G.sipo->totipo; a++, ei++) {
+			/* only consider those curves that are visible and are being edited/used for showkeys */
 			if (ISPOIN(ei, flag & IPO_VISIBLE, icu)) {
-				if( (ei->flag & IPO_EDIT) || G.sipo->showkey) {
-
-				
-					if(ei->icu->bezt) {
+				if ( (ei->flag & IPO_EDIT) || G.sipo->showkey) {
+					if (ei->icu->bezt) {
 						bezt= ei->icu->bezt;
-						b= ei->icu->totvert;
-						while(b--) {
-							if(ei->icu->ipo==IPO_BEZ) {
-								if(bezt->f1 & 1) {
-									tv->loc= bezt->vec[0];
-									VECCOPY(tv->oldloc, tv->loc);
-									if(ei->disptype==IPO_DISPBITS) tv->flag= 1;
-									
-									/* we take the middle vertex */
-									DO_MINMAX2(bezt->vec[1], min, max);
-
-									tv++;
-								}
-								if(bezt->f3 & 1) {
-									tv->loc= bezt->vec[2];
-									VECCOPY(tv->oldloc, tv->loc);
-									if(ei->disptype==IPO_DISPBITS) tv->flag= 1;
-									
-									/* we take the middle vertex */
-									DO_MINMAX2(bezt->vec[1], min, max);
-
-									tv++;
-								}
+						
+						for (b=0; b < ei->icu->totvert; b++, bezt++) {
+							/* only include handles if selected, and interpolaton mode uses beztriples */
+							if (ei->icu->ipo==IPO_BEZ) {
+								if (bezt->f1 & 1)
+									bezt_to_transdata(td++, td2d++, bezt->vec[0], bezt->vec[1], 1, (ei->disptype==IPO_DISPBITS));
+								if (bezt->f3 & 1)
+									bezt_to_transdata(td++, td2d++, bezt->vec[2], bezt->vec[1], 1, (ei->disptype==IPO_DISPBITS));
 							}
-							if(bezt->f2 & 1) {
-								tv->loc= bezt->vec[1];
-								VECCOPY(tv->oldloc, tv->loc);
-								if(ei->disptype==IPO_DISPBITS) tv->flag= 1;
-								DO_MINMAX2(bezt->vec[1], min, max);
-								tv++;
+							
+							/* only include main vert if selected */
+							if (bezt->f2 & 1) {
+								bezt_to_transdata(td++, td2d++, bezt->vec[1], bezt->vec[1], 1, (ei->disptype==IPO_DISPBITS));
 							}
-							bezt++;
 						}
 					}
 				}
 			}
 		}
-		
 	}
-	else if(totipo_edit==0 && totipo_sel!=0) {
-		
+	else if (totipo_edit==0 && totipo_sel!=0) {
+		/* we're not in editmode, so entire curves get moved */
 		ei= G.sipo->editipo;
-		for(a=0; a<G.sipo->totipo; a++, ei++) {
+		for (a=0; a<G.sipo->totipo; a++, ei++) {
+			/* only include curves that are visible and selected */
 			if (ISPOIN3(ei, flag & IPO_VISIBLE, flag & IPO_SELECT, icu)) {
-				if(ei->icu->bezt && ei->icu->ipo==IPO_BEZ) tot+= 3*ei->icu->totvert;
-				else tot+= ei->icu->totvert;
-			}

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list