diff options
author | Germano Cavalcante <germano.costa@ig.com.br> | 2016-05-11 12:59:02 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2016-05-11 13:20:25 +0300 |
commit | 67d2de882841f56c9cd35f0f0e7329b0c9190c97 (patch) | |
tree | 49778334fe1d4e71e19a62a5876a8d10e4a6e2ff /source/blender/editors/armature | |
parent | 4a135ad2b7886c3a4731f7db7ddce60af8068f32 (diff) |
Transform Volume rewrite/refactor
Take advantage of the efficiency provided by the snap_context.
Also fixes errors:
- volume snap fails based on view angle (T48394).
- multiple instances of dupli-objects break volume calculation.
Diffstat (limited to 'source/blender/editors/armature')
-rw-r--r-- | source/blender/editors/armature/editarmature_sketch.c | 125 |
1 files changed, 23 insertions, 102 deletions
diff --git a/source/blender/editors/armature/editarmature_sketch.c b/source/blender/editors/armature/editarmature_sketch.c index 508bbca53ca..7685829db9b 100644 --- a/source/blender/editors/armature/editarmature_sketch.c +++ b/source/blender/editors/armature/editarmature_sketch.c @@ -970,100 +970,30 @@ static int sk_getStrokeSnapPoint(bContext *C, SK_Point *pt, SK_Sketch *sketch, S ToolSettings *ts = CTX_data_tool_settings(C); int point_added = 0; - if (ts->snap_mode == SCE_SNAP_MODE_VOLUME) { - DepthPeel *p1, *p2; - float *last_p = NULL; - float dist = FLT_MAX; - float p[3] = {0}; - float size = 0; - float mvalf[2]; - - BLI_freelistN(&sketch->depth_peels); - BLI_listbase_clear(&sketch->depth_peels); - - mvalf[0] = dd->mval[0]; - mvalf[1] = dd->mval[1]; - peelObjectsContext(C, mvalf, SNAP_ALL, &sketch->depth_peels); - - if (stk->nb_points > 0 && stk->points[stk->nb_points - 1].type == PT_CONTINUOUS) { - last_p = stk->points[stk->nb_points - 1].p; - } - else if (LAST_SNAP_POINT_VALID) { - last_p = LAST_SNAP_POINT; - } - - - for (p1 = sketch->depth_peels.first; p1; p1 = p1->next) { - if (p1->flag == 0) { - float vec[3]; - float new_dist; - float new_size = 0; - - p2 = NULL; - p1->flag = 1; - - /* if peeling objects, take the first and last from each object */ - if (ts->snap_flag & SCE_SNAP_PEEL_OBJECT) { - DepthPeel *peel; - for (peel = p1->next; peel; peel = peel->next) { - if (peel->ob == p1->ob) { - peel->flag = 1; - p2 = peel; - } - } - } - /* otherwise, pair first with second and so on */ - else { - for (p2 = p1->next; p2 && p2->ob != p1->ob; p2 = p2->next) { - /* nothing to do here */ - } - } - - if (p2) { - p2->flag = 1; - - add_v3_v3v3(vec, p1->p, p2->p); - mul_v3_fl(vec, 0.5f); - new_size = len_v3v3(p1->p, p2->p); - } - else { - copy_v3_v3(vec, p1->p); - } - - if (last_p == NULL) { - copy_v3_v3(p, vec); - size = new_size; - dist = 0; - break; - } - - new_dist = len_v3v3(last_p, vec); + struct SnapObjectContext *snap_context = ED_transform_snap_object_context_create_view3d( + CTX_data_main(C), CTX_data_scene(C), 0, + CTX_wm_region(C), CTX_wm_view3d(C)); - if (new_dist < dist) { - copy_v3_v3(p, vec); - dist = new_dist; - size = new_size; - } - } - } + float mvalf[2] = {UNPACK2(dd->mval)}; + float r_loc[3], dummy_no[3]; - if (dist != FLT_MAX) { + if (ts->snap_mode == SCE_SNAP_MODE_VOLUME) { + float size; + if (peelObjectsSnapContext( + snap_context, mvalf, SNAP_ALL, + (ts->snap_flag & SCE_SNAP_PEEL_OBJECT) != 0, + r_loc, dummy_no, &size)) + { pt->type = dd->type; pt->mode = PT_SNAP; pt->size = size / 2; - copy_v3_v3(pt->p, p); + copy_v3_v3(pt->p, r_loc); point_added = 1; } - - //BLI_freelistN(&depth_peels); } else { SK_Stroke *snap_stk; - float vec[3]; - float no[3]; - float mval[2]; - int found = 0; float dist_px = SNAP_MIN_DISTANCE; // Use a user defined value here /* snap to strokes */ @@ -1082,37 +1012,28 @@ static int sk_getStrokeSnapPoint(bContext *C, SK_Point *pt, SK_Sketch *sketch, S point_added = 1; } } - - mval[0] = dd->mval[0]; - mval[1] = dd->mval[1]; /* try to snap to closer object */ { - struct SnapObjectContext *snap_context = ED_transform_snap_object_context_create_view3d( - CTX_data_main(C), CTX_data_scene(C), 0, - CTX_wm_region(C), CTX_wm_view3d(C)); - - found = ED_transform_snap_object_project_view3d( + if (ED_transform_snap_object_project_view3d( snap_context, &(const struct SnapObjectParams){ .snap_select = SNAP_NOT_SELECTED, .snap_to = ts->snap_mode, }, - mval, &dist_px, NULL, - vec, no); - - ED_transform_snap_object_context_destroy(snap_context); - } - - if (found == 1) { - pt->type = dd->type; - pt->mode = PT_SNAP; - copy_v3_v3(pt->p, vec); + mvalf, &dist_px, NULL, + r_loc, dummy_no)) + { + pt->type = dd->type; + pt->mode = PT_SNAP; + copy_v3_v3(pt->p, r_loc); - point_added = 1; + point_added = 1; + } } } + ED_transform_snap_object_context_destroy(snap_context); return point_added; } |