Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStephen Swaney <sswaney@centurytel.net>2005-06-13 23:15:02 +0400
committerStephen Swaney <sswaney@centurytel.net>2005-06-13 23:15:02 +0400
commit769fa6252d90666768fc13a39eedecee12d8c0df (patch)
tree0fd2df014f63cf1e0112b7134f05d555f7a943d4 /source/blender/src
parentde567cd0cc5532d3a6aa521328230239fa082810 (diff)
Patch from Martin Poirier.
Misc bpy Curve fixes and updates, includes bugs #1687 and #2637
Diffstat (limited to 'source/blender/src')
-rw-r--r--source/blender/src/editcurve.c254
1 files changed, 131 insertions, 123 deletions
diff --git a/source/blender/src/editcurve.c b/source/blender/src/editcurve.c
index 360c9e62f45..b1b1dd8215d 100644
--- a/source/blender/src/editcurve.c
+++ b/source/blender/src/editcurve.c
@@ -1853,144 +1853,152 @@ void findselectedNurbvert(Nurb **nu, BezTriple **bezt, BPoint **bp)
}
}
-void setsplinetype(short type)
+int convertspline(short type, Nurb *nu)
{
- Nurb *nu;
BezTriple *bezt;
BPoint *bp;
int a, c, nr;
- if(type==CU_CARDINAL || type==CU_BSPLINE) {
- error("Not implemented yet");
- return;
+ if((nu->type & 7)==0) { /* Poly */
+ if(type==CU_BEZIER) { /* to Bezier with vecthandles */
+ nr= nu->pntsu;
+ bezt =
+ (BezTriple*)MEM_callocN(nr * sizeof(BezTriple), "setsplinetype2");
+ nu->bezt= bezt;
+ a= nr;
+ bp= nu->bp;
+ while(a--) {
+ VECCOPY(bezt->vec[1], bp->vec);
+ bezt->f1=bezt->f2=bezt->f3= bp->f1;
+ bezt->h1= bezt->h2= HD_VECT;
+ bp++;
+ bezt++;
+ }
+ MEM_freeN(nu->bp);
+ nu->bp= 0;
+ nu->pntsu= nr;
+ nu->type &= ~7;
+ nu->type |= 1;
+ calchandlesNurb(nu);
+ }
+ else if(type==4) { /* to Nurb */
+ nu->type &= ~7;
+ nu->type+= 4;
+ nu->orderu= 4;
+ nu->flagu &= 1;
+ nu->flagu += 4;
+ makeknots(nu, 1, nu->flagu>>1);
+ a= nu->pntsu*nu->pntsv;
+ bp= nu->bp;
+ while(a--) {
+ bp->vec[3]= 1.0;
+ bp++;
+ }
+ }
}
-
- nu= editNurb.first;
- while(nu) {
- if(isNurbsel(nu)) {
-
- if((nu->type & 7)==0) { /* Poly */
- if(type==CU_BEZIER) { /* to Bezier with vecthandles */
- nr= nu->pntsu;
- bezt =
- (BezTriple*)MEM_callocN(nr * sizeof(BezTriple), "setsplinetype2");
- nu->bezt= bezt;
- a= nr;
- bp= nu->bp;
- while(a--) {
- VECCOPY(bezt->vec[1], bp->vec);
- bezt->f1=bezt->f2=bezt->f3= bp->f1;
- bezt->h1= bezt->h2= HD_VECT;
- bp++;
- bezt++;
- }
- MEM_freeN(nu->bp);
- nu->bp= 0;
- nu->pntsu= nr;
- nu->type &= ~7;
- nu->type |= 1;
- calchandlesNurb(nu);
+ else if((nu->type & 7)==CU_BEZIER) { /* Bezier */
+ if(type==0 || type==4) { /* to Poly or Nurb */
+ nr= 3*nu->pntsu;
+ nu->bp = MEM_callocN(nr * sizeof(BPoint), "setsplinetype");
+ a= nu->pntsu;
+ bezt= nu->bezt;
+ bp= nu->bp;
+ while(a--) {
+ if(type==0 && bezt->h1==HD_VECT && bezt->h2==HD_VECT) {
+ /* vector handle becomes 1 poly vertice */
+ VECCOPY(bp->vec, bezt->vec[1]);
+ bp->vec[3]= 1.0;
+ bp->f1= bezt->f2;
+ nr-= 2;
+ bp++;
}
- else if(type==4) { /* to Nurb */
- nu->type &= ~7;
- nu->type+= 4;
- nu->orderu= 4;
- nu->flagu &= 1;
- nu->flagu += 4;
- makeknots(nu, 1, nu->flagu>>1);
- a= nu->pntsu*nu->pntsv;
- bp= nu->bp;
- while(a--) {
+ else {
+ for(c=0;c<3;c++) {
+ VECCOPY(bp->vec, bezt->vec[c]);
bp->vec[3]= 1.0;
+ if(c==0) bp->f1= bezt->f1;
+ else if(c==1) bp->f1= bezt->f2;
+ else bp->f1= bezt->f3;
bp++;
}
}
+ bezt++;
}
- else if((nu->type & 7)==CU_BEZIER) { /* Bezier */
- if(type==0 || type==4) { /* to Poly or Nurb */
- nr= 3*nu->pntsu;
- nu->bp = MEM_callocN(nr * sizeof(BPoint), "setsplinetype");
- a= nu->pntsu;
- bezt= nu->bezt;
- bp= nu->bp;
- while(a--) {
- if(type==0 && bezt->h1==HD_VECT && bezt->h2==HD_VECT) {
- /* vector handle becomes 1 poly vertice */
- VECCOPY(bp->vec, bezt->vec[1]);
- bp->vec[3]= 1.0;
- bp->f1= bezt->f2;
- nr-= 2;
- bp++;
- }
- else {
- for(c=0;c<3;c++) {
- VECCOPY(bp->vec, bezt->vec[c]);
- bp->vec[3]= 1.0;
- if(c==0) bp->f1= bezt->f1;
- else if(c==1) bp->f1= bezt->f2;
- else bp->f1= bezt->f3;
- bp++;
- }
- }
- bezt++;
- }
- MEM_freeN(nu->bezt);
- nu->bezt= 0;
- nu->pntsu= nr;
- nu->pntsv= 1;
- nu->orderu= 4;
- nu->orderv= 1;
- nu->type &= ~7;
- nu->type+= type;
- if(nu->flagu & 1) c= nu->orderu-1;
- else c= 0;
- if(type== 4) {
- nu->flagu &= 1;
- nu->flagu += 4;
- makeknots(nu, 1, nu->flagu>>1);
- }
- }
- }
- else if( (nu->type & 7)==CU_NURBS && G.obedit->type==OB_CURVE) {
- if(type==0) { /* to Poly */
- nu->type &= ~7;
- MEM_freeN(nu->knotsu);
- nu->knotsu= 0;
- if(nu->knotsv) MEM_freeN(nu->knotsv);
- nu->knotsv= 0;
- }
- else if(type==CU_BEZIER) { /* to Bezier */
- nr= nu->pntsu/3;
-
- if(nr<2) error("no conversion possible");
- else {
- bezt = MEM_callocN(nr * sizeof(BezTriple), "setsplinetype2");
- nu->bezt= bezt;
- a= nr;
- bp= nu->bp;
- while(a--) {
- VECCOPY(bezt->vec[0], bp->vec);
- bezt->f1= bp->f1;
- bp++;
- VECCOPY(bezt->vec[1], bp->vec);
- bezt->f2= bp->f1;
- bp++;
- VECCOPY(bezt->vec[2], bp->vec);
- bezt->f3= bp->f1;
- bp++;
- bezt++;
- }
- MEM_freeN(nu->bp);
- nu->bp= 0;
- MEM_freeN(nu->knotsu);
- nu->knotsu= 0;
- nu->pntsu= nr;
- nu->type &= ~7;
- nu->type+= 1;
- }
+ MEM_freeN(nu->bezt);
+ nu->bezt= 0;
+ nu->pntsu= nr;
+ nu->pntsv= 1;
+ nu->orderu= 4;
+ nu->orderv= 1;
+ nu->type &= ~7;
+ nu->type+= type;
+ if(nu->flagu & 1) c= nu->orderu-1;
+ else c= 0;
+ if(type== 4) {
+ nu->flagu &= 1;
+ nu->flagu += 4;
+ makeknots(nu, 1, nu->flagu>>1);
+ }
+ }
+ }
+ else if( (nu->type & 7)==CU_NURBS) {
+ if(type==0) { /* to Poly */
+ nu->type &= ~7;
+ MEM_freeN(nu->knotsu);
+ nu->knotsu= 0;
+ if(nu->knotsv) MEM_freeN(nu->knotsv);
+ nu->knotsv= 0;
+ }
+ else if(type==CU_BEZIER) { /* to Bezier */
+ nr= nu->pntsu/3;
+
+ if(nr<2)
+ return 1; /* conversion impossible */
+ else {
+ bezt = MEM_callocN(nr * sizeof(BezTriple), "setsplinetype2");
+ nu->bezt= bezt;
+ a= nr;
+ bp= nu->bp;
+ while(a--) {
+ VECCOPY(bezt->vec[0], bp->vec);
+ bezt->f1= bp->f1;
+ bp++;
+ VECCOPY(bezt->vec[1], bp->vec);
+ bezt->f2= bp->f1;
+ bp++;
+ VECCOPY(bezt->vec[2], bp->vec);
+ bezt->f3= bp->f1;
+ bp++;
+ bezt++;
}
+ MEM_freeN(nu->bp);
+ nu->bp= 0;
+ MEM_freeN(nu->knotsu);
+ nu->knotsu= 0;
+ nu->pntsu= nr;
+ nu->type &= ~7;
+ nu->type+= 1;
}
}
+ }
+ return 0;
+}
+
+void setsplinetype(short type)
+{
+ Nurb *nu;
+
+ if(type==CU_CARDINAL || type==CU_BSPLINE) {
+ error("Not implemented yet");
+ return;
+ }
+
+ nu= editNurb.first;
+ while(nu) {
+ if(isNurbsel(nu)) {
+ if (convertspline(type, nu))
+ error("no conversion possible");
+ }
nu= nu->next;
}
BIF_undo_push("Set spline type");