[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [19194] branches/nurbs/blender/source/ blender/src/editcurve.c: Another patch from Laurynas.

Emmanuel Stone emmanuel.stone at gmail.com
Thu Mar 5 00:20:23 CET 2009


Revision: 19194
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=19194
Author:   eman
Date:     2009-03-05 00:20:23 +0100 (Thu, 05 Mar 2009)

Log Message:
-----------
Another patch from Laurynas.
Direction selection removed before splitting curve.
Changed knot recalculation after cp deletion. There were problems with knottype == 9
Fixed knot for spin.

Modified Paths:
--------------
    branches/nurbs/blender/source/blender/src/editcurve.c

Modified: branches/nurbs/blender/source/blender/src/editcurve.c
===================================================================
--- branches/nurbs/blender/source/blender/src/editcurve.c	2009-03-04 19:40:08 UTC (rev 19193)
+++ branches/nurbs/blender/source/blender/src/editcurve.c	2009-03-04 23:20:23 UTC (rev 19194)
@@ -633,6 +633,31 @@
 	}
 }
 
+void removeDeletedKnot(int cp, float* knots, int pnts, int order, short cyclic) {
+	int i;
+	float step, last;
+	if (cyclic) {
+		//just fixes knots in cycle to be correct
+		if (pnts == order) order--;
+		for (i = 0; i < 2 * order - 1; i++)
+			knots[pnts + i] = knots[pnts - 1] + knots[i + 1] - knots[0];
+	} else if (pnts == order) {
+		//shifts knot vector to the left by one position
+		order--;
+		pnts--;
+		step = knots[0] - knots[1];
+		for (i = 0; i < pnts + order; i++)
+			knots [i] = knots[i + 1] + step;
+	} else {
+		//enshures last knot to retain same multiplicity
+		pnts--;
+		i = pnts + order;
+		while (knots[i] == knots[i - 1]) i--;
+		last = knots[i - 1];
+		while (i < pnts + order) knots[i++] = last;
+	}
+}
+
 void deleteflagNurb(short flag)
 {
 	Nurb *nu, *next;
@@ -687,15 +712,15 @@
 					if((bp->f1 & flag)==0) {
 						memcpy(bpn, bp, nu->pntsu*sizeof(BPoint));
 						bpn+= nu->pntsu;
-					}
+					} else
+						removeDeletedKnot(b, nu -> knotsv, nu -> pntsv, nu -> orderv, nu -> knottypev == 0);
 					bp+= nu->pntsu;
 				}
 				nu->pntsv= newv;
 				MEM_freeN(nu->bp);
 				nu->bp= newbp;
 				clamp_nurb_order_v(nu);
-
-				makeknots(nu, 2, nu->flagv>>1);
+				//makeknots(nu, 2, nu->flagv>>1);
 			}
 			else {
 				/* is the nurb in V direction selected */
@@ -724,7 +749,8 @@
 							if((bp->f1 & flag)==0) {
 								*bpn= *bp;
 								bpn++;
-							}
+							} else
+								removeDeletedKnot(a, nu -> knotsu, nu -> pntsu, nu -> orderu, nu -> knottypeu == 0);
 						}
 					}
 					MEM_freeN(nu->bp);
@@ -741,7 +767,7 @@
 						nu->pntsu= newu;
 						clamp_nurb_order_u(nu);
 					}
-					makeknots(nu, 1, nu->flagu>>1);
+					//makeknots(nu, 1, nu->flagu>>1);
 				}
 			}
 		}
@@ -749,7 +775,7 @@
 	}
 }
 
-void setExtudedKnot(float* knots, int pnts, int order, short fromEnd) {
+void setExtrudedKnot(float* knots, int pnts, int order, short fromEnd) {
 	int step = 1;
 	if (fromEnd) {
 		step = -step;
@@ -809,7 +835,7 @@
 				}
 				nu -> pntsv++;
 				
-				setExtudedKnot(nu -> knotsv, nu -> pntsv, nu -> orderv, !shift);
+				setExtrudedKnot(nu -> knotsv, nu -> pntsv, nu -> orderv, !shift);
 				// resize nurbana's buffers
 				NRB_SizeChanged(nu->nurbanaPtr,nu->pntsu,nu->pntsv);
 			}
@@ -833,7 +859,7 @@
 					bp += nu -> pntsu;
 					bpn += nu -> pntsu;
 				}
-				setExtudedKnot(nu -> knotsu, nu -> pntsu, nu -> orderu, !shift);
+				setExtrudedKnot(nu -> knotsu, nu -> pntsu, nu -> orderu, !shift);
 				// resize nurbana's buffers
 				NRB_SizeChanged(nu->nurbanaPtr, nu->pntsu, nu->pntsv);
 			}
@@ -2228,7 +2254,9 @@
 		if(!nu->nurbanaPtr)
 			return;
 		
-		uv = selectDirection(nu, mvalo, mval, &sizeU, &sizeV, &size, &bufferU, &bufferV, &buffer, &canceled);
+		if (nu -> pntsv > 1)
+			uv = selectDirection(nu, mvalo, mval, &sizeU, &sizeV, &size, &bufferU, &bufferV, &buffer, &canceled);
+		else uv = 0;
 		
 		if (uv) {
 			cyclic = nu -> flagv &= CU_CYCLIC;
@@ -2368,7 +2396,7 @@
 			void* nu2Ptr = NULL;
 			if (!cyclic) {
 				nu2 = (Nurb*)MEM_callocN(sizeof(Nurb), "SplitedNurb");
-				nu2 -> type = 4;
+				nu2 -> type = nu -> type;
 				nu2 -> resolu = nu -> resolu;
 				nu2 -> resolv = nu -> resolv;
 				nu2 -> orderu = nu -> orderu;
@@ -2386,6 +2414,18 @@
 				nu2Ptr = nu2 -> nurbanaPtr;
 			}
 		    NRB_splitBuffer(tmpBuffer, inserted, nu -> nurbanaPtr, nu2Ptr, splitKnot, newLength, k, uv, frstLen, scndLen);
+		    if (nu -> pntsv == 1) {
+		    	int i;
+		    	BPoint *cp = nu -> bp + nu -> pntsu - 1;
+		    	//set radius and weight values for added cp's
+		    	for (i = inserted; i >= 0; i--, cp--)
+		    		cp -> radius = cp -> weight = 1.0;
+		    	//set radius and weight values for newly created curve
+		    	if (nu2)
+					for (i = 0, cp = nu2 -> bp; i < nu2 -> pntsu; i++, cp++)
+						cp -> radius = cp -> weight = 1.0;
+		    }
+		    	
 		}
 		choosing = 1;
 		canceled = 0;
@@ -3443,7 +3483,7 @@
 			if(isNurbsel(nu)) {
 				nu->orderv= 4;
 				nu->flagv |= CU_CYCLIC;
-				makeknots(nu, 2, nu->flagv>>1);
+				makeknots(nu, 2, 0);
 			}
 		}
 	}
@@ -3550,7 +3590,7 @@
 
 		if(bp) {
 			nu->pntsu++;
-			setExtudedKnot(nu -> knotsu, nu -> pntsu, nu -> orderu, bp == newbp - 1);
+			setExtrudedKnot(nu -> knotsu, nu -> pntsu, nu -> orderu, bp == newbp - 1);
 			//makeknots(nu, 1, nu->flagu>>1);
 			NRB_SizeChanged(nu->nurbanaPtr,nu->pntsu,nu->pntsv);
 			if(mode=='e') {
@@ -4348,6 +4388,7 @@
 						nu->pntsu--;
 						a--;
 						event= 1;
+						removeDeletedKnot(a, nu->knotsu, nu->pntsu, nu->orderu, nu->knottypeu == 0);
 					}
 					else {
 						bp++;
@@ -4366,7 +4407,7 @@
 						clamp_nurb_order_u(nu);
 					}*/
 				}
-				makeknots(nu, 1, nu->flagu>>1);
+				//makeknots(nu, 1, nu->flagu>>1);
 			}
 			nu= next;
 		}





More information about the Bf-blender-cvs mailing list