Commit: 291247680cdc329ec61a3eaa98c3136382662344 Author: Hans Goudey Date: Thu Jun 27 17:16:16 2019 -0400 Branches: soc-2019-bevel-profiles https://developer.blender.org/rB291247680cdc329ec61a3eaa98c3136382662344
Custom bevel profiles: Merged calculate_profile and calculate_profile_custom. Now that I'm using the custom profile for all bevel cases, I don't need to have separate code that uses the custom bevel profiles, so I only need one function. This also changes the "reversed" parameter to flip the order of the calculated profile so it doesn't have to be done later with get_profile_point indices. =================================================================== M source/blender/bmesh/tools/bmesh_bevel.c =================================================================== diff --git a/source/blender/bmesh/tools/bmesh_bevel.c b/source/blender/bmesh/tools/bmesh_bevel.c index bb1f4c31845..a690bb521bd 100644 --- a/source/blender/bmesh/tools/bmesh_bevel.c +++ b/source/blender/bmesh/tools/bmesh_bevel.c @@ -61,7 +61,7 @@ #define DEBUG_CUSTOM_PROFILE_ORIGINAL 0 #define DEBUG_CUSTOM_PROFILE_WELD 0 #define DEBUG_CUSTOM_PROFILE_ADJ 1 -#define DEBUG_CUSTOM_PROFILE_ORIENTATION 0 +#define DEBUG_CUSTOM_PROFILE_ORIENTATION 1 #if DEBUG_CUSTOM_PROFILE_ORIENTATION extern void DRW_debug_sphere(const float center[3], const float radius, const float color[4]); @@ -1654,15 +1654,14 @@ static void get_profile_point(BevelParams *bp, const Profile *pro, int i, int n, } } -/* This does the same thing as the regular calculate profile function, but it uses the - * custom profile points instead of the normal ones. Eventually, when the custom and normal - * profile spacings are merged, this function will be redundant, but for now, I will call this - * function in certain cases where I am working on the custom profile. This also checks for - * is_profile_start and flips the profile if it isn't the start of the boundary */ -/* HANS-TODO: Get rid of this function when all custom profile cases are completed */ -/* HANS-TODO: Change the reverse case so that I don't have to sample the points backwards in - * get_profile_point. This would simplify the rest of the code a lot */ -static void calculate_profile_custom(BevelParams *bp, BoundVert *bndv, bool reversed) +/* Calculate the actual coordinate values for bndv's profile. + * This is only needed if bp->seg > 1. + * Allocate the space for them if that hasn't been done already. + * If bp->seg is not a power of 2, also need to calculate + * the coordinate values for the power of 2 >= bp->seg, + * because the ADJ pattern needs power-of-2 boundaries + * during construction. */ +static void calculate_profile(BevelParams *bp, BoundVert *bndv, bool reversed) { int i, k, ns; const double *xvals, *yvals; @@ -1711,7 +1710,7 @@ static void calculate_profile_custom(BevelParams *bp, BoundVert *bndv, bool reve xvals = bp->pro_spacing.xvals_2; yvals = bp->pro_spacing.yvals_2; prof_co = pro->prof_co_2; - } + } /* HANS-TODO: Why this assert? */ BLI_assert((r == PRO_LINE_R || (xvals != NULL && yvals != NULL)) && prof_co != NULL); @@ -1727,10 +1726,10 @@ static void calculate_profile_custom(BevelParams *bp, BoundVert *bndv, bool reve if (map_ok) { if (reversed) { #if DEBUG_CUSTOM_PROFILE_ORIENTATION - printf("Using reversed custom profile orientation\n"); + printf("(reversed)\n"); #endif - p[0] = (float)yvals[k]; - p[1] = (float)xvals[k]; + p[0] = (float)yvals[ns - k]; + p[1] = (float)xvals[ns - k]; } else { p[0] = (float)xvals[k]; @@ -1763,102 +1762,6 @@ static void calculate_profile_custom(BevelParams *bp, BoundVert *bndv, bool reve } } -/* Calculate the actual coordinate values for bndv's profile. - * This is only needed if bp->seg > 1. - * Allocate the space for them if that hasn't been done already. - * If bp->seg is not a power of 2, also need to calculate - * the coordinate values for the power of 2 >= bp->seg, - * because the ADJ pattern needs power-of-2 boundaries - * during construction. */ -static void calculate_profile(BevelParams *bp, BoundVert *bndv) -{ - int i, k, ns; - const double *xvals, *yvals; - float co[3], co2[3], p[3], m[4][4]; - float *prof_co, *prof_co_k; - float r; - bool need_2, map_ok; - Profile *pro = &bndv->profile; - - if (bp->seg == 1) { - return; - } - - need_2 = bp->seg != bp->pro_spacing.seg_2; - if (!pro->prof_co) { - pro->prof_co = (float *)BLI_memarena_alloc(bp->mem_arena, - ((size_t)bp->seg + 1) * 3 * sizeof(float)); - if (need_2) { - pro->prof_co_2 = (float *)BLI_memarena_alloc( - bp->mem_arena, ((size_t)bp->pro_spacing.seg_2 + 1) * 3 * sizeof(float)); - } - else { - pro->prof_co_2 = pro->prof_co; - } - } - r = pro->super_r; - if (r == PRO_LINE_R) { - map_ok = false; - } - else { - map_ok = make_unit_square_map(pro->coa, pro->midco, pro->cob, m); - } - /* The first iteration is the nseg case, the second is the seg_2 case if it's needed */ - for (i = 0; i < 2; i++) { - if (i == 0) { - ns = bp->seg; - xvals = bp->pro_spacing.xvals; - yvals = bp->pro_spacing.yvals; - prof_co = pro->prof_co; - } - else { - if (!need_2) { - break; /* shares coords with pro->prof_co */ - } - ns = bp->pro_spacing.seg_2; - xvals = bp->pro_spacing.xvals_2; - yvals = bp->pro_spacing.yvals_2; - prof_co = pro->prof_co_2; - } - /* HANS-TODO: Why this assert? */ - BLI_assert((r == PRO_LINE_R || (xvals != NULL && yvals != NULL)) && prof_co != NULL); - - /* Iterate over the vertices along the boundary arc */ - for (k = 0; k <= ns; k++) { - if (k == 0) { - copy_v3_v3(co, pro->coa); - } - else if (k == ns) { - copy_v3_v3(co, pro->cob); - } - else { - if (map_ok) { - p[0] = (float)xvals[k]; - p[1] = (float)yvals[k]; - p[2] = 0.0f; - mul_v3_m4v3(co, m, p); - } - else { - interp_v3_v3v3(co, pro->coa, pro->cob, (float)k / (float)ns); - } - } - /* project co onto final profile plane */ - prof_co_k = prof_co + 3 * k; /* Each coord takes up 3 spaces */ - if (!is_zero_v3(pro->proj_dir)) { - add_v3_v3v3(co2, co, pro->proj_dir); - /* pro->plane_co and pro->plane_no are built in "set_profile_params" */ - if (!isect_line_plane_v3(prof_co_k, co, co2, pro->plane_co, pro->plane_no)) { - /* shouldn't happen */ - copy_v3_v3(prof_co_k, co); - } - } - else { - copy_v3_v3(prof_co_k, co); - } - } - } -} - /* Snap a direction co to a superellipsoid with parameter super_r. * For square profiles, midline says whether or not to snap to both planes. * @@ -2370,19 +2273,6 @@ static bool eh_on_plane(EdgeHalf *e) return false; } -/* Same thing as below, but the profiles are calculated with the custom profile spacing data - * HANS-TODO: Remove this when all of the cases are resolved */ -static void calculate_vm_profiles_custom(BevelParams *bp, BevVert *bv, VMesh *vm) -{ - BoundVert *v; - - v = vm->boundstart; - do { - set_profile_params(bp, bv, v); - calculate_profile_custom(bp, v, false); /* HANS-TODO: Possibly choose whether to reverse here */ - } while ((v = v->next) != vm->boundstart); -} - /* Calculate the profiles for all the BoundVerts of VMesh vm */ static void calculate_vm_profiles(BevelParams *bp, BevVert *bv, VMesh *vm) { @@ -2391,7 +2281,8 @@ static void calculate_vm_profiles(BevelParams *bp, BevVert *bv, VMesh *vm) v = vm->boundstart; do { set_profile_params(bp, bv, v); - calculate_profile(bp, v); + /* We probably don't know to orientation at this point, so don't reverse the profiles */ + calculate_profile(bp, v, false); } while ((v = v->next) != vm->boundstart); } @@ -2418,12 +2309,7 @@ static void build_boundary_vertex_only(BevelParams *bp, BevVert *bv, bool constr } } while ((e = e->next) != efirst); - if (bp->use_custom_profile){ - calculate_vm_profiles_custom(bp, bv, vm); - } - else { - calculate_vm_profiles(bp, bv, vm); - } + calculate_vm_profiles(bp, bv, vm); if (construct) { set_bound_vert_seams(bv, bp->mark_seam, bp->mark_sharp); @@ -2538,24 +2424,14 @@ static void build_boundary_terminal_edge(BevelParams *bp, } } } - if (!bp->use_custom_profile) { - calculate_vm_profiles(bp, bv, vm); - } - else { - calculate_vm_profiles_custom(bp, bv, vm); /* HANS-TODO: Change when all cases are converted */ - } + calculate_vm_profiles(bp, bv, vm); if (bv->edgecount >= 3) { /* special case: snap profile to plane of adjacent two edges */ v = vm->boundstart; BLI_assert(v->ebev != NULL); move_profile_plane(v, bv->v); - if (!bp->use_custom_profile) { - calculate_profile(bp, v); - } - else { - calculate_profile_custom(bp, v, false); /* HANS-TODO: Change back when all cases are converted */ - } + calculate_profile(bp, v, false); } if (construct) { @@ -2895,12 +2771,7 @@ static void build_boundary(BevelParams *bp, BevVert *bv, bool construct) adjust_miter_coords(bp, bv, emiter); } - if (bp->use_custom_profile) { - calculate_vm_profiles_custom(bp, bv, vm); - } - else { - calculate_vm_profiles(bp, bv, vm); - } + calculate_vm_profiles(bp, bv, vm); if (construct) { set_bound_vert_seams(bv, bp->mark_seam, bp->mark_sharp); @@ -3244,7 +3115,7 @@ static EdgeHalf *next_edgehalf_bev(BevelParams *bp, return next_edge; } #if DEBUG_CUSTOM_PROFILE_ORIENTATION -static void debug_RPO_draw_sphere(BevelParams* bp, BMEdge* e) { +static void debug_RPO_edge_draw_sphere(BevelParams* bp, BMEdge* e) { float debug_color_1[4]; debug_color_1[0] = 1.0; debug_color_1[1] = 0.0; @@ -3324,8 +3195,8 @@ static void regularize_profile_orientation(BevelParams *bp, BMEdge *bme) /* Mark the correct BoundVert as the start of the newly visited profile * The direction of the BoundVert along the path switches every time because their directions * are relative to the BevVert they're connected to. So the right and left are BoundVerts - * would also switch every EdgeHalf, and all I need to do is switch which BoundVert I make - * the profile's start every time. */ + * would also switch every EdgeHalf, and all we need to do is switch which BoundVert I mark as + * the profile's start each time. */ edgehalf->rightv->is_profile_start = toward_bv; edgehalf->leftv->is_profile_start = !toward_bv; #if DEBUG_CUSTOM_PROFILE_ORIENTATION @@ -3356,7 +3227,8 @@ static void regularize_profile_orientation(BevelParams *bp, BMEdge *bme) } edgehalf->visited_custom = true; - /* Mark the correct BoundVert as the start of the newly visited profile */ + /* Mark the corr @@ Diff output truncated at 10240 characters. @@ _______________________________________________ Bf-blender-cvs mailing list Bf-blender-cvs@blender.org https://lists.blender.org/mailman/listinfo/bf-blender-cvs