diff options
Diffstat (limited to 'source/blender/blenkernel/intern/curve.c')
-rw-r--r-- | source/blender/blenkernel/intern/curve.c | 154 |
1 files changed, 128 insertions, 26 deletions
diff --git a/source/blender/blenkernel/intern/curve.c b/source/blender/blenkernel/intern/curve.c index 2f0c83507f0..5f5958f8893 100644 --- a/source/blender/blenkernel/intern/curve.c +++ b/source/blender/blenkernel/intern/curve.c @@ -46,6 +46,7 @@ #include "DNA_scene_types.h" #include "DNA_vfont_types.h" #include "DNA_meshdata_types.h" +#include "DNA_object_types.h" #include "BKE_animsys.h" #include "BKE_anim.h" @@ -59,6 +60,8 @@ #include "BKE_object.h" #include "BKE_utildefines.h" // VECCOPY +#include "ED_curve.h" + /* globals */ /* local */ @@ -105,13 +108,8 @@ void free_curve(Curve *cu) BLI_freelistN(&cu->bev); freedisplist(&cu->disp); BKE_free_editfont(cu); - - if(cu->editnurb) { - freeNurblist(cu->editnurb); - MEM_freeN(cu->editnurb); - cu->editnurb= NULL; - } + free_curve_editNurb(cu); unlink_curve(cu); BKE_free_animdata((ID *)cu); @@ -130,7 +128,7 @@ Curve *add_curve(char *name, int type) cu= alloc_libblock(&G.main->curve, ID_CU, name); cu->size[0]= cu->size[1]= cu->size[2]= 1.0; - cu->flag= CU_FRONT|CU_BACK|CU_PATH_RADIUS; + cu->flag= CU_FRONT|CU_BACK|CU_DEFORM_BOUNDS_OFF|CU_PATH_RADIUS; cu->pathlen= 100; cu->resolu= cu->resolv= 12; cu->width= 1.0; @@ -149,7 +147,7 @@ Curve *add_curve(char *name, int type) cu->vfont->id.us+=4; cu->str= MEM_mallocN(12, "str"); strcpy(cu->str, "Text"); - cu->pos= 4; + cu->len= cu->pos= 4; cu->strinfo= MEM_callocN(12*sizeof(CharInfo), "strinfo new"); cu->totbox= cu->actbox= 1; cu->tb= MEM_callocN(MAXTEXTBOX*sizeof(TextBox), "textbox"); @@ -280,7 +278,7 @@ void tex_space_curve(Curve *cu) { DispList *dl; BoundBox *bb; - float *fp, min[3], max[3], loc[3], size[3]; + float *fp, min[3], max[3]; int tot, doit= 0; if(cu->bb==NULL) cu->bb= MEM_callocN(sizeof(BoundBox), "boundbox"); @@ -307,20 +305,15 @@ void tex_space_curve(Curve *cu) min[0] = min[1] = min[2] = -1.0f; max[0] = max[1] = max[2] = 1.0f; } - - loc[0]= (min[0]+max[0])/2.0f; - loc[1]= (min[1]+max[1])/2.0f; - loc[2]= (min[2]+max[2])/2.0f; - - size[0]= (max[0]-min[0])/2.0f; - size[1]= (max[1]-min[1])/2.0f; - size[2]= (max[2]-min[2])/2.0f; boundbox_set_from_min_max(bb, min, max); if(cu->texflag & CU_AUTOSPACE) { - VECCOPY(cu->loc, loc); - VECCOPY(cu->size, size); + mid_v3_v3v3(cu->loc, min, max); + cu->size[0]= (max[0]-min[0])/2.0f; + cu->size[1]= (max[1]-min[1])/2.0f; + cu->size[2]= (max[2]-min[2])/2.0f; + cu->rot[0]= cu->rot[1]= cu->rot[2]= 0.0; if(cu->size[0]==0.0) cu->size[0]= 1.0; @@ -1230,6 +1223,8 @@ void makebevelcurve(Scene *scene, Object *ob, ListBase *disp, int forRender) // XXX if( ob == obedit && ob->type == OB_FONT ) return; if(cu->bevobj) { + if (cu->bevobj->type!=OB_CURVE) return; + bevcu= cu->bevobj->data; if(bevcu->ext1==0.0 && bevcu->ext2==0.0) { ListBase bevdisp= {NULL, NULL}; @@ -1579,7 +1574,7 @@ static void alfa_bezpart(BezTriple *prevbezt, BezTriple *bezt, Nurb *nu, float * for(a=0; a<resolu; a++, fac+= dfac) { if (tilt_array) { - if (nu->tilt_interp==3) { /* May as well support for tilt also 2.47 ease interp */ + if (nu->tilt_interp==KEY_CU_EASE) { /* May as well support for tilt also 2.47 ease interp */ *tilt_array = prevbezt->alfa + (bezt->alfa - prevbezt->alfa)*(3.0f*fac*fac - 2.0f*fac*fac*fac); } else { key_curve_position_weights(fac, t, nu->tilt_interp); @@ -1590,7 +1585,7 @@ static void alfa_bezpart(BezTriple *prevbezt, BezTriple *bezt, Nurb *nu, float * } if (radius_array) { - if (nu->radius_interp==3) { + if (nu->radius_interp==KEY_CU_EASE) { /* Support 2.47 ease interp * Note! - this only takes the 2 points into account, * giving much more localized results to changes in radius, sometimes you want that */ @@ -2009,8 +2004,10 @@ void makeBevelList(Object *ob) /* STEP 1: MAKE POLYS */ BLI_freelistN(&(cu->bev)); - if(cu->editnurb && ob->type!=OB_FONT) nu= cu->editnurb->first; - else nu= cu->nurb.first; + if(cu->editnurb && ob->type!=OB_FONT) { + ListBase *nurbs= ED_curve_editnurbs(cu); + nu= nurbs->first; + } else nu= cu->nurb.first; while(nu) { @@ -3000,7 +2997,7 @@ float (*curve_getKeyVertexCos(Curve *cu, ListBase *lb, float *key))[3] VECCOPY(co, key); co+=3; key+=3; VECCOPY(co, key); co+=3; key+=3; VECCOPY(co, key); co+=3; key+=3; - key++; /* skip tilt */ + key+=3; /* skip tilt */ } } else { @@ -3079,7 +3076,7 @@ int clamp_nurb_order_u( struct Nurb *nu ) nu->orderu= nu->pntsu; change= 1; } - if(((nu->flag & CU_NURB_CYCLIC)==0) && (nu->flagu & CU_NURB_BEZIER)) { + if(((nu->flagu & CU_NURB_CYCLIC)==0) && (nu->flagu & CU_NURB_BEZIER)) { CLAMP(nu->orderu, 3,4); change= 1; } @@ -3093,12 +3090,117 @@ int clamp_nurb_order_v( struct Nurb *nu) nu->orderv= nu->pntsv; change= 1; } - if(((nu->flag & CU_NURB_CYCLIC)==0) && (nu->flagv & CU_NURB_BEZIER)) { + if(((nu->flagv & CU_NURB_CYCLIC)==0) && (nu->flagv & CU_NURB_BEZIER)) { CLAMP(nu->orderv, 3,4); change= 1; } return change; } +/* Get edit nurbs or normal nurbs list */ +ListBase *BKE_curve_nurbs(Curve *cu) +{ + if (cu->editnurb) { + return ED_curve_editnurbs(cu); + } + + return &cu->nurb; +} + + +/* basic vertex data functions */ +int minmax_curve(Curve *cu, float min[3], float max[3]) +{ + ListBase *nurb_lb= BKE_curve_nurbs(cu); + Nurb *nu; + + for(nu= nurb_lb->first; nu; nu= nu->next) + minmaxNurb(nu, min, max); + + return (nurb_lb->first != NULL); +} + +int curve_center_median(Curve *cu, float cent[3]) +{ + ListBase *nurb_lb= BKE_curve_nurbs(cu); + Nurb *nu; + int total= 0; + zero_v3(cent); + for(nu= nurb_lb->first; nu; nu= nu->next) { + int i; + + if(nu->type == CU_BEZIER) { + BezTriple *bezt; + i= nu->pntsu; + total += i * 3; + for(bezt= nu->bezt; i--; bezt++) { + add_v3_v3(cent, bezt->vec[0]); + add_v3_v3(cent, bezt->vec[1]); + add_v3_v3(cent, bezt->vec[2]); + } + } + else { + BPoint *bp; + i= nu->pntsu*nu->pntsv; + total += i; + for(bp= nu->bp; i--; bp++) { + add_v3_v3(cent, bp->vec); + } + } + } + + mul_v3_fl(cent, 1.0f/(float)total); + + return (total != 0); +} + +int curve_center_bounds(Curve *cu, float cent[3]) +{ + float min[3], max[3]; + INIT_MINMAX(min, max); + if(minmax_curve(cu, min, max)) { + mid_v3_v3v3(cent, min, max); + return 1; + } + + return 0; +} + +void curve_translate(Curve *cu, float offset[3], int do_keys) +{ + ListBase *nurb_lb= BKE_curve_nurbs(cu); + Nurb *nu; + int i; + + for(nu= nurb_lb->first; nu; nu= nu->next) { + BezTriple *bezt; + BPoint *bp; + + if(nu->type == CU_BEZIER) { + i= nu->pntsu; + for(bezt= nu->bezt; i--; bezt++) { + add_v3_v3(bezt->vec[0], offset); + add_v3_v3(bezt->vec[1], offset); + add_v3_v3(bezt->vec[2], offset); + } + } + else { + i= nu->pntsu*nu->pntsv; + for(bp= nu->bp; i--; bp++) { + add_v3_v3(bp->vec, offset); + } + } + } + + if (do_keys && cu->key) { + KeyBlock *kb; + for (kb=cu->key->block.first; kb; kb=kb->next) { + float *fp= kb->data; + for (i= kb->totelem; i--; fp+=3) { + add_v3_v3(fp, offset); + } + } + } +} |