From f0593ea8e8daa7f1e8f3b25f240cda020025698c Mon Sep 17 00:00:00 2001 From: Ton Roosendaal Date: Thu, 17 Nov 2005 12:24:29 +0000 Subject: [PATCH] Bug in SoftBody for Curve/Surface: in some cases the edge spring array was not initialized, like when adding a SoftBody to Object in EditMode. --- source/blender/blenkernel/intern/softbody.c | 91 +++++++++++---------- 1 file changed, 49 insertions(+), 42 deletions(-) diff --git a/source/blender/blenkernel/intern/softbody.c b/source/blender/blenkernel/intern/softbody.c index 11bacfd8683..418751839ec 100644 --- a/source/blender/blenkernel/intern/softbody.c +++ b/source/blender/blenkernel/intern/softbody.c @@ -1089,7 +1089,14 @@ static void curve_surf_to_softbody(Object *ob, int *rcs) { Curve *cu= ob->data; SoftBody *sb; - int totvert, totspring = 0; + BodyPoint *bp; + BodySpring *bs; + Nurb *nu; + BezTriple *bezt; + BPoint *bpnt; + float goalfac; + int a, curindex=0; + int totvert, totspring = 0, setgoal=0; totvert= count_curveverts(&cu->nurb); @@ -1102,60 +1109,60 @@ static void curve_surf_to_softbody(Object *ob, int *rcs) /* renew ends with ob->soft with points and edges, also checks & makes ob->soft */ renew_softbody(ob, totvert, totspring, rcs); sb= ob->soft; /* can be created in renew_softbody() */ + + /* set vars now */ + goalfac= ABS(sb->maxgoal - sb->mingoal); + bp= sb->bpoint; + bs= sb->bspring; /* weights from bpoints, same code used as for mesh vertices */ - if((ob->softflag & OB_SB_GOAL) && sb->vertgroup) { - BodyPoint *bp= sb->bpoint; - BodySpring *bs= sb->bspring; - Nurb *nu; - BezTriple *bezt; - BPoint *bpnt; - float goalfac= ABS(sb->maxgoal - sb->mingoal); - int a, curindex=0; + if((ob->softflag & OB_SB_GOAL) && sb->vertgroup) + setgoal= 1; - for(nu= cu->nurb.first; nu; nu= nu->next) { - if(nu->bezt) { - for(bezt=nu->bezt, a=0; apntsu; a++, bezt++, bp++, curindex+=3) { + for(nu= cu->nurb.first; nu; nu= nu->next) { + if(nu->bezt) { + for(bezt=nu->bezt, a=0; apntsu; a++, bezt++, bp+=3, curindex+=3) { + if(setgoal) { bp->goal= sb->mingoal + bezt->weight*goalfac; /* a little ad hoc changing the goal control to be less *sharp* */ bp->goal = (float)pow(bp->goal, 4.0f); + /* all three triples */ - bp++; - bp->goal= (bp-1)->goal; - bp++; - bp->goal= (bp-1)->goal; - - if(totspring) { - if(a>0) { - bs->v1= curindex-1; - bs->v2= curindex; - bs->strength= 1.0; - bs++; - } - bs->v1= curindex; - bs->v2= curindex+1; - bs->strength= 1.0; - bs++; - - bs->v1= curindex+1; - bs->v2= curindex+2; - bs->strength= 1.0; - bs++; - } + (bp+1)->goal= bp->goal; + (bp+2)->goal= bp->goal; } - } - else { - for(bpnt=nu->bp, a=0; apntsu*nu->pntsv; a++, bpnt++, bp++, curindex++) { - bp->goal= sb->mingoal + bpnt->weight*goalfac; - /* a little ad hoc changing the goal control to be less *sharp* */ - bp->goal = (float)pow(bp->goal, 4.0f); - - if(totspring && a>0) { + + if(totspring) { + if(a>0) { bs->v1= curindex-1; bs->v2= curindex; bs->strength= 1.0; bs++; } + bs->v1= curindex; + bs->v2= curindex+1; + bs->strength= 1.0; + bs++; + + bs->v1= curindex+1; + bs->v2= curindex+2; + bs->strength= 1.0; + bs++; + } + } + } + else { + for(bpnt=nu->bp, a=0; apntsu*nu->pntsv; a++, bpnt++, bp++, curindex++) { + if(setgoal) { + bp->goal= sb->mingoal + bpnt->weight*goalfac; + /* a little ad hoc changing the goal control to be less *sharp* */ + bp->goal = (float)pow(bp->goal, 4.0f); + } + if(totspring && a>0) { + bs->v1= curindex-1; + bs->v2= curindex; + bs->strength= 1.0; + bs++; } } }