Added start and end bevel factor for curves, so now it's possible to make

a bevelled curve which isn't fully covered with a bevel.
This commit is contained in:
2012-05-04 17:04:20 +00:00
parent a9ecc86ec9
commit 72fa158724
7 changed files with 87 additions and 22 deletions

View File

@@ -173,9 +173,11 @@ class DATA_PT_geometry_curve(CurveButtonsPanel, Panel):
col.label(text="Bevel Object:")
col.prop(curve, "bevel_object", text="")
row = col.row()
row.active = (curve.bevel_object is not None)
row.prop(curve, "use_fill_caps")
col = layout.column(align=True)
col.active = (curve.bevel_object is not None)
col.prop(curve, "use_fill_caps")
col.prop(curve, "bevel_factor_start")
col.prop(curve, "bevel_factor_end")
class DATA_PT_pathanim(CurveButtonsPanelCurve, Panel):

View File

@@ -42,7 +42,7 @@ extern "C" {
* and keep comment above the defines.
* Use STRINGIFY() rather than defining with quotes */
#define BLENDER_VERSION 263
#define BLENDER_SUBVERSION 3
#define BLENDER_SUBVERSION 4
#define BLENDER_MINVERSION 250
#define BLENDER_MINSUBVERSION 0

View File

@@ -169,6 +169,8 @@ Curve *BKE_curve_add(const char *name, int type)
cu->smallcaps_scale= 0.75f;
cu->twist_mode= CU_TWIST_MINIMUM; // XXX: this one seems to be the best one in most cases, at least for curve deform...
cu->type= type;
cu->bevfac1= 0.0f;
cu->bevfac2= 1.0f;
cu->bb= unit_boundbox();

View File

@@ -1220,10 +1220,11 @@ static void rotateBevelPiece(Curve *cu, BevPoint *bevp, DispList *dlb, float wid
*data_r = data;
}
static void fillBevelCap(Curve *cu, Nurb *nu, BevPoint *bevp, DispList *dlb, float fac, float widfac, ListBase *dispbase)
static void fillBevelCap(Nurb *nu, DispList *dlb, float *prev_fp, ListBase *dispbase)
{
DispList *dl;
float *data;
int b;
dl= MEM_callocN(sizeof(DispList), "makeDispListbev2");
dl->verts= data= MEM_callocN(3*sizeof(float)*dlb->nr, "dlverts");
@@ -1239,7 +1240,8 @@ static void fillBevelCap(Curve *cu, Nurb *nu, BevPoint *bevp, DispList *dlb, flo
/* CU_2D conflicts with R_NOPUNOFLIP */
dl->rt= nu->flag & ~CU_2D;
rotateBevelPiece(cu, bevp, dlb, widfac, fac, &data);
for (b = 0; b < dlb->nr; b++, prev_fp += 3, data += 3)
copy_v3_v3(data, prev_fp);
BLI_addtail(dispbase, dl);
}
@@ -1332,9 +1334,26 @@ static void do_makeDispListCurveTypes(Scene *scene, Object *ob, ListBase *dispba
ListBase top_capbase = {NULL, NULL};
for (dlb=dlbev.first; dlb; dlb=dlb->next) {
int i, start, steps;
float bevfac1 = MIN2(cu->bevfac1, cu->bevfac2), bevfac2 = MAX2(cu->bevfac1, cu->bevfac2);
float firstblend = 0.0f, lastblend = 0.0f;
if (cu->bevfac1 - cu->bevfac2 == 0.0f)
continue;
start = (int)(bevfac1*(bl->nr-1));
steps = 2+(int)((bevfac2)*(bl->nr-1)) - start;
firstblend = 1.0f - ((float)bevfac1*(bl->nr-1) - (int)((float)bevfac1*(bl->nr-1)));
lastblend = (float)bevfac2*(bl->nr-1) - (int)((float)bevfac2*(bl->nr-1));
if (steps > bl->nr) {
steps = bl->nr;
lastblend = 1.0f;
}
/* for each part of the bevel use a separate displblock */
dl= MEM_callocN(sizeof(DispList), "makeDispListbev1");
dl->verts= data= MEM_callocN(3*sizeof(float)*dlb->nr*bl->nr, "dlverts");
dl->verts= data= MEM_callocN(3*sizeof(float)*dlb->nr*steps, "dlverts");
BLI_addtail(dispbase, dl);
dl->type= DL_SURF;
@@ -1342,8 +1361,8 @@ static void do_makeDispListCurveTypes(Scene *scene, Object *ob, ListBase *dispba
dl->flag= dlb->flag & (DL_FRONT_CURVE|DL_BACK_CURVE);
if (dlb->type==DL_POLY) dl->flag |= DL_CYCL_U;
if (bl->poly>=0) dl->flag |= DL_CYCL_V;
dl->parts= bl->nr;
dl->parts= steps;
dl->nr= dlb->nr;
dl->col= nu->mat_nr;
dl->charidx= nu->charidx;
@@ -1352,18 +1371,20 @@ static void do_makeDispListCurveTypes(Scene *scene, Object *ob, ListBase *dispba
/* CU_2D conflicts with R_NOPUNOFLIP */
dl->rt= nu->flag & ~CU_2D;
dl->bevelSplitFlag= MEM_callocN(sizeof(*dl->col2)*((bl->nr+0x1F)>>5), "bevelSplitFlag");
dl->bevelSplitFlag= MEM_callocN(sizeof(*dl->col2)*((steps+0x1F)>>5), "bevelSplitFlag");
/* for each point of poly make a bevel piece */
bevp= (BevPoint *)(bl+1);
for (a=0; a<bl->nr; a++, bevp++) {
bevp= (BevPoint *)(bl+1) + start;
for (i=start, a=0; a<steps; i++,bevp++,a++) {
float fac=1.0;
float *cur_data = data;
if (cu->taperobj==NULL) {
if ( (cu->bevobj!=NULL) || !((cu->flag & CU_FRONT) || (cu->flag & CU_BACK)) )
fac = bevp->radius;
}
else {
fac = calc_taper(scene, cu->taperobj, a, bl->nr);
fac = calc_taper(scene, cu->taperobj, i, bl->nr);
}
if (bevp->split_tag) {
@@ -1373,11 +1394,31 @@ static void do_makeDispListCurveTypes(Scene *scene, Object *ob, ListBase *dispba
/* rotate bevel piece and write in data */
rotateBevelPiece(cu, bevp, dlb, widfac, fac, &data);
if (a == 1 || a == steps - 1) {
float *cur_fp = cur_data, *prev_fp = cur_data - 3*dlb->nr;
int b;
for (b = 0; b < dlb->nr; b++, prev_fp += 3, cur_fp += 3) {
float cur[3], prev[3];
copy_v3_v3(cur, cur_fp);
copy_v3_v3(prev, prev_fp);
if (a == 1)
interp_v3_v3v3(prev, cur_fp, prev_fp, firstblend);
if (a == steps - 1)
interp_v3_v3v3(cur, prev_fp, cur_fp, lastblend);
copy_v3_v3(cur_fp, cur);
copy_v3_v3(prev_fp, prev);
}
}
if (cu->bevobj && (cu->flag & CU_FILL_CAPS)) {
if (a == 0)
fillBevelCap(cu, nu, bevp, dlb, fac, widfac, &bottom_capbase);
else if (a == bl->nr - 1)
fillBevelCap(cu, nu, bevp, dlb, fac, widfac, &top_capbase);
if (a == 1)
fillBevelCap(nu, dlb, cur_data - 3*dlb->nr, &bottom_capbase);
if (a == steps - 1)
fillBevelCap(nu, dlb, cur_data, &top_capbase);
}
}

View File

@@ -7390,17 +7390,16 @@ static void do_versions(FileData *fd, Library *lib, Main *main)
}
}
if (main->versionfile < 263 || (main->versionfile == 263 && main->subversionfile < 4))
{
Lamp *la;
Camera *cam;
Curve *cu;
for (la= main->lamp.first; la; la= la->id.next) {
if (la->shadow_frustum_size == 0.0)
la->shadow_frustum_size= 10.0f;
}
}
if (main->versionfile < 263 || (main->versionfile == 263 && main->subversionfile < 4))
{
Camera *cam;
for (cam = main->camera.first; cam; cam = cam->id.next) {
if (cam->flag & CAM_PANORAMA) {
@@ -7408,6 +7407,13 @@ static void do_versions(FileData *fd, Library *lib, Main *main)
cam->flag &= ~CAM_PANORAMA;
}
}
for(cu= main->curve.first; cu; cu= cu->id.next) {
if(cu->bevfac2 == 0.0f) {
cu->bevfac1 = 0.0f;
cu->bevfac2 = 1.0f;
}
}
}
/* WATCH IT!!!: pointers from libdata have not been converted yet here! */

View File

@@ -234,6 +234,8 @@ typedef struct Curve {
struct CharInfo *strinfo;
struct CharInfo curinfo;
float bevfac1, bevfac2;
} Curve;
/* **************** CURVE ********************* */

View File

@@ -1470,6 +1470,18 @@ static void rna_def_curve(BlenderRNA *brna)
RNA_def_property_ui_text(prop, "Materials", "");
RNA_def_property_srna(prop, "IDMaterials"); /* see rna_ID.c */
RNA_def_property_collection_funcs(prop, 0, NULL, NULL, NULL, NULL, NULL, NULL, "rna_IDMaterials_assign_int");
prop = RNA_def_property(srna, "bevel_factor_start", PROP_FLOAT, PROP_FACTOR);
RNA_def_property_float_sdna(prop, NULL, "bevfac1");
RNA_def_property_range(prop, 0, 1.0);
RNA_def_property_ui_text(prop, "Start Bevel Factor", "Factor that defines from where beveling of spline happens (0=from the very beginning, 1=from the very end)");
RNA_def_property_update(prop, 0, "rna_Curve_update_data");
prop = RNA_def_property(srna, "bevel_factor_end", PROP_FLOAT, PROP_FACTOR);
RNA_def_property_float_sdna(prop, NULL, "bevfac2");
RNA_def_property_range(prop, 0, 1.0);
RNA_def_property_ui_text(prop, "End Bevel Factor", "Factor that defines to where beveling of spline happens (0=to the very beginning, 1=to the very end)");
RNA_def_property_update(prop, 0, "rna_Curve_update_data");
}
static void rna_def_curve_nurb(BlenderRNA *brna)