[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [33510] trunk/blender/source/blender: Curves CV animation

Sergey Sharybin g.ulairi at gmail.com
Mon Dec 6 18:20:22 CET 2010


Revision: 33510
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=33510
Author:   nazgul
Date:     2010-12-06 18:20:22 +0100 (Mon, 06 Dec 2010)

Log Message:
-----------
Curves CV animation
===================

Update fcurves RNA pathes after making changes to curve topology, so
animation will no longer lost after edit and wouldn't lead to crash.

Will be very useful for RotoBezier addon.

Also NodeKeyIndex renamed to CVNodeIndex due to node is an entity from
another module and better not used in others.

Modified Paths:
--------------
    trunk/blender/source/blender/editors/curve/editcurve.c
    trunk/blender/source/blender/editors/include/ED_curve.h
    trunk/blender/source/blender/makesdna/DNA_curve_types.h

Modified: trunk/blender/source/blender/editors/curve/editcurve.c
===================================================================
--- trunk/blender/source/blender/editors/curve/editcurve.c	2010-12-06 17:02:49 UTC (rev 33509)
+++ trunk/blender/source/blender/editors/curve/editcurve.c	2010-12-06 17:20:22 UTC (rev 33510)
@@ -40,6 +40,7 @@
 #include "DNA_key_types.h"
 #include "DNA_object_types.h"
 #include "DNA_scene_types.h"
+#include "DNA_anim_types.h"
 
 #include "MEM_guardedalloc.h"
 
@@ -58,6 +59,7 @@
 #include "BKE_library.h"
 #include "BKE_main.h"
 #include "BKE_report.h"
+#include "BKE_animsys.h"
 
 #include "WM_api.h"
 #include "WM_types.h"
@@ -85,9 +87,11 @@
 
 /* Definitions needed for shape keys */
 typedef struct {
-	void *origNode;
-	int index;
-} NodeKeyIndex;
+	void *orig_cv;
+	int key_index, nu_index, pt_index;
+	int switched;
+	Nurb *orig_nu;
+} CVKeyIndex;
 
 void selectend_nurb(Object *obedit, short selfirst, short doswap, short selstatus);
 static void select_adjacent_cp(ListBase *editnurb, short next, short cont, short selstatus);
@@ -271,17 +275,21 @@
 
 /* ********************* Shape keys *************** */
 
-static NodeKeyIndex *init_nodeKeyIndex(void *node, int index)
+static CVKeyIndex *init_cvKeyIndex(void *cv, int key_index, int nu_index, int pt_index, Nurb *orig_nu)
 {
-	NodeKeyIndex *nodeIndex = MEM_callocN(sizeof(NodeKeyIndex), "init_nodeKeyIndex");
+	CVKeyIndex *cvIndex = MEM_callocN(sizeof(CVKeyIndex), "init_cvKeyIndex");
 
-	nodeIndex->origNode= node;
-	nodeIndex->index= index;
+	cvIndex->orig_cv= cv;
+	cvIndex->key_index= key_index;
+	cvIndex->nu_index= nu_index;
+	cvIndex->pt_index= pt_index;
+	cvIndex->switched= 0;
+	cvIndex->orig_nu= orig_nu;
 
-	return nodeIndex;
+	return cvIndex;
 }
 
-static void free_nodeKeyIndex(NodeKeyIndex *pointIndex)
+static void free_cvKeyIndex(CVKeyIndex *pointIndex)
 {
 	MEM_freeN(pointIndex);
 }
@@ -293,8 +301,11 @@
 	GHash *gh;
 	BezTriple *bezt, *origbezt;
 	BPoint *bp, *origbp;
-	int a, keyindex= 0;
+	CVKeyIndex *keyIndex;
+	int a, key_index= 0, nu_index= 0, pt_index= 0;
 
+	if(editnurb->keyindex) return;
+
 	gh= BLI_ghash_new(BLI_ghashutil_ptrhash, BLI_ghashutil_ptrcmp, "editNurb keyIndex");
 
 	while (orignu) {
@@ -302,26 +313,33 @@
 			a= orignu->pntsu;
 			bezt= nu->bezt;
 			origbezt= orignu->bezt;
+			pt_index= 0;
 			while (a--) {
-				BLI_ghash_insert(gh, bezt, init_nodeKeyIndex(origbezt, keyindex));
-				keyindex+= 12;
+				keyIndex= init_cvKeyIndex(origbezt, key_index, nu_index, pt_index, orignu);
+				BLI_ghash_insert(gh, bezt, keyIndex);
+				key_index+= 12;
 				bezt++;
 				origbezt++;
+				pt_index++;
 			}
 		} else {
 			a= orignu->pntsu * orignu->pntsv;
 			bp= nu->bp;
 			origbp= orignu->bp;
+			pt_index= 0;
 			while (a--) {
-				BLI_ghash_insert(gh, bp, init_nodeKeyIndex(origbp, keyindex));
-				keyindex+= 4;
+				keyIndex= init_cvKeyIndex(origbp, key_index, nu_index, pt_index, orignu);
+				BLI_ghash_insert(gh, bp, keyIndex);
+				key_index+= 4;
 				bp++;
 				origbp++;
+				pt_index++;
 			}
 		}
 
 		nu= nu->next;
 		orignu= orignu->next;
+		nu_index++;
 	}
 
 	editnurb->keyindex= gh;
@@ -332,64 +350,65 @@
 	if (!editnurb->keyindex) {
 		return;
 	}
-	BLI_ghash_free(editnurb->keyindex, NULL, (GHashValFreeFP)free_nodeKeyIndex);
+	BLI_ghash_free(editnurb->keyindex, NULL, (GHashValFreeFP)free_cvKeyIndex);
+	editnurb->keyindex= NULL;
 }
 
-static NodeKeyIndex *getNodeKeyIndex(EditNurb *editnurb, void *node)
+static CVKeyIndex *getCVKeyIndex(EditNurb *editnurb, void *cv)
 {
-	return BLI_ghash_lookup(editnurb->keyindex, node);
+	return BLI_ghash_lookup(editnurb->keyindex, cv);
 }
 
-static BezTriple *getKeyIndexOrig_bezt(EditNurb *editnurb, void *node)
+static BezTriple *getKeyIndexOrig_bezt(EditNurb *editnurb, BezTriple *bezt)
 {
-	NodeKeyIndex *index= getNodeKeyIndex(editnurb, node);
+	CVKeyIndex *index= getCVKeyIndex(editnurb, bezt);
 
 	if (!index) {
 		return NULL;
 	}
 
-	return (BezTriple*)index->origNode;
+	return (BezTriple*)index->orig_cv;
 }
 
-static BPoint *getKeyIndexOrig_bp(EditNurb *editnurb, void *node)
+static BPoint *getKeyIndexOrig_bp(EditNurb *editnurb, BPoint *bp)
 {
-	NodeKeyIndex *index= getNodeKeyIndex(editnurb, node);
+	CVKeyIndex *index= getCVKeyIndex(editnurb, bp);
 
 	if (!index) {
 		return NULL;
 	}
 
-	return (BPoint*)index->origNode;
+	return (BPoint*)index->orig_cv;
 }
 
-static int getKeyIndexOrig_index(EditNurb *editnurb, void *node)
+static int getKeyIndexOrig_keyIndex(EditNurb *editnurb, void *cv)
 {
-	NodeKeyIndex *index= getNodeKeyIndex(editnurb, node);
+	CVKeyIndex *index= getCVKeyIndex(editnurb, cv);
 
 	if (!index) {
 		return -1;
 	}
 
-	return index->index;
+	return index->key_index;
 }
 
-static void keyIndex_delNode(EditNurb *editnurb, void *node)
+static void keyIndex_delCV(EditNurb *editnurb, void *cv)
 {
 	if (!editnurb->keyindex) {
 		return;
 	}
 
-	BLI_ghash_remove(editnurb->keyindex, node, NULL, (GHashValFreeFP)free_nodeKeyIndex);
+	BLI_ghash_remove(editnurb->keyindex, cv, NULL, (GHashValFreeFP)free_cvKeyIndex);
 }
 
 static void keyIndex_delBezt(EditNurb *editnurb, BezTriple *bezt)
 {
-	keyIndex_delNode(editnurb, bezt);
+	keyIndex_delCV(editnurb, bezt);
 }
 
 static void keyIndex_delBP(EditNurb *editnurb, BPoint *bp)
 {
-	keyIndex_delNode(editnurb, bp);
+	keyIndex_delCV(editnurb, bp);
 }
 
 static void keyIndex_delNurb(EditNurb *editnurb, Nurb *nu)
@@ -405,7 +424,7 @@
 		a= nu->pntsu;
 
 		while (a--) {
-			BLI_ghash_remove(editnurb->keyindex, bezt, NULL, (GHashValFreeFP)free_nodeKeyIndex);
+			BLI_ghash_remove(editnurb->keyindex, bezt, NULL, (GHashValFreeFP)free_cvKeyIndex);
 			++bezt;
 		}
 	} else {
@@ -413,7 +432,7 @@
 		a= nu->pntsu * nu->pntsv;
 
 		while (a--) {
-			BLI_ghash_remove(editnurb->keyindex, bp, NULL, (GHashValFreeFP)free_nodeKeyIndex);
+			BLI_ghash_remove(editnurb->keyindex, bp, NULL, (GHashValFreeFP)free_cvKeyIndex);
 			++bp;
 		}
 	}
@@ -430,11 +449,11 @@
 	}
 }
 
-static void keyIndex_updateNode(EditNurb *editnurb, char *node,
-	char *newnode, int count, int size, int search)
+static void keyIndex_updateCV(EditNurb *editnurb, char *cv,
+	char *newcv, int count, int size, int search)
 {
 	int i;
-	NodeKeyIndex *index;
+	CVKeyIndex *index;
 
 	if (editnurb->keyindex == NULL) {
 		/* No shape keys - updating not needed */
@@ -443,34 +462,34 @@
 
 	for (i = 0; i < count; i++) {
 		for (;;) {
-			index= getNodeKeyIndex(editnurb, node);
+			index= getCVKeyIndex(editnurb, cv);
 			if (!search || index) {
 				break;
 			}
-			node += size;
+			cv += size;
 		}
 
-		BLI_ghash_remove(editnurb->keyindex, node, NULL, NULL);
+		BLI_ghash_remove(editnurb->keyindex, cv, NULL, NULL);
 
 		if (index) {
-			BLI_ghash_insert(editnurb->keyindex, newnode, index);
+			BLI_ghash_insert(editnurb->keyindex, newcv, index);
 		}
 
-		newnode += size;
-		node += size;
+		newcv += size;
+		cv += size;
 	}
 }
 
 static void keyIndex_updateBezt(EditNurb *editnurb, BezTriple *bezt,
 	BezTriple *newbezt, int count, int search)
 {
-	keyIndex_updateNode(editnurb, (char*)bezt, (char*)newbezt, count, sizeof(BezTriple), search);
+	keyIndex_updateCV(editnurb, (char*)bezt, (char*)newbezt, count, sizeof(BezTriple), search);
 }
 
 static void keyIndex_updateBP(EditNurb *editnurb, BPoint *bp,
 	BPoint *newbp, int count, int search)
 {
-	keyIndex_updateNode(editnurb, (char*)bp, (char*)newbp, count, sizeof(BPoint), search);
+	keyIndex_updateCV(editnurb, (char*)bp, (char*)newbp, count, sizeof(BPoint), search);
 }
 
 static void keyIndex_updateNurb(EditNurb *editnurb, Nurb *nu, Nurb *newnu)
@@ -484,8 +503,8 @@
 
 static void keyIndex_swap(EditNurb *editnurb, void *a, void *b)
 {
-	NodeKeyIndex *index1= getNodeKeyIndex(editnurb, a);
-	NodeKeyIndex *index2= getNodeKeyIndex(editnurb, b);
+	CVKeyIndex *index1= getCVKeyIndex(editnurb, a);
+	CVKeyIndex *index2= getCVKeyIndex(editnurb, b);
 
 	BLI_ghash_remove(editnurb->keyindex, a, NULL, NULL);
 	BLI_ghash_remove(editnurb->keyindex, b, NULL, NULL);
@@ -497,6 +516,7 @@
 static void keyIndex_switchDirection(EditNurb *editnurb, Nurb *nu)
 {
 	int a;
+	CVKeyIndex *index1, *index2;
 
 	if (nu->bezt) {
 		BezTriple *bezt1, *bezt2;
@@ -511,8 +531,21 @@
 		a/=2;
 
 		while (a--) {
+			index1= getCVKeyIndex(editnurb, bezt1);
+			index2= getCVKeyIndex(editnurb, bezt2);
+
+			if(index1) {
+				index1->switched= !index1->switched;
+				//index1->pt_index= index1->orig_nu->pntsu - (index1->pt_index + 1);
+			}
+
 			if (bezt1 != bezt2) {
 				keyIndex_swap(editnurb, bezt1, bezt2);
+
+				if(index2) {
+					index2->switched= !index2->switched;
+					//index2->pt_index= index2->orig_nu->pntsu - (index2->pt_index + 1);
+				}
 			}
 
 			bezt1++;
@@ -527,7 +560,20 @@
 			bp2= bp1+(a-1);
 			a/= 2;
 			while(bp1!=bp2 && a>0) {
+				index1= getCVKeyIndex(editnurb, bp1);
+				index2= getCVKeyIndex(editnurb, bp2);
+
+				if(index1) {
+					index1->switched= !index1->switched;
+					index1->pt_index= index1->orig_nu->pntsu - (index1->pt_index + 1);
+				}
+
 				if (bp1 != bp2) {
+					if(index2) {
+						index2->switched= !index2->switched;
+						index2->pt_index= index2->orig_nu->pntsu - (index2->pt_index + 1);
+					}
+
 					keyIndex_swap(editnurb, bp1, bp2);
 				}
 
@@ -546,7 +592,20 @@
 				a/= 2;
 
 				while(bp1!=bp2 && a>0) {
+					index1= getCVKeyIndex(editnurb, bp1);
+					index2= getCVKeyIndex(editnurb, bp2);
+
+					if(index1) {
+						index1->switched= !index1->switched;
+						index1->pt_index= index1->orig_nu->pntsu*index1->orig_nu->pntsv - (index1->pt_index + 1);
+					}
+
 					if (bp1 != bp2) {
+						if(index2) {
+							index2->switched= !index2->switched;
+							index2->pt_index= index2->orig_nu->pntsu*index2->orig_nu->pntsv - (index2->pt_index + 1);
+						}
+
 						keyIndex_swap(editnurb, bp1, bp2);
 					}
 
@@ -619,7 +678,8 @@
 	}
 
 	keyIndex_switchDirection(editnurb, nu);
-	switch_keys_direction(cu, nu);
+	if(cu->key)
+		switch_keys_direction(cu, nu);
 }
 
 static GHash *dupli_keyIndexHash(GHash *keyindex)
@@ -632,13 +692,13 @@
 	for(hashIter = BLI_ghashIterator_new(keyindex);
 				   !BLI_ghashIterator_isDone(hashIter);
 				   BLI_ghashIterator_step(hashIter)) {
-		void *node = BLI_ghashIterator_getKey(hashIter);
-		NodeKeyIndex *index = BLI_ghashIterator_getValue(hashIter);
-		NodeKeyIndex *newIndex = MEM_callocN(sizeof(NodeKeyIndex), "dupli_keyIndexHash index");
+		void *cv = BLI_ghashIterator_getKey(hashIter);
+		CVKeyIndex *index = BLI_ghashIterator_getValue(hashIter);
+		CVKeyIndex *newIndex = MEM_callocN(sizeof(CVKeyIndex), "dupli_keyIndexHash index");
 
-		memcpy(newIndex, index, sizeof(NodeKeyIndex));

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list