Index: source/blender/blenkernel/BKE_paint.h =================================================================== --- source/blender/blenkernel/BKE_paint.h (revision 45655) +++ source/blender/blenkernel/BKE_paint.h (working copy) @@ -103,6 +103,10 @@ struct SculptStroke *stroke; struct StrokeCache *cache; + + /* last paint/sculpt stroke location */ + int last_stroke_valid; + float last_stroke[3]; } SculptSession; void free_sculptsession(struct Object *ob); Index: source/blender/editors/include/ED_sculpt.h =================================================================== --- source/blender/editors/include/ED_sculpt.h (revision 45655) +++ source/blender/editors/include/ED_sculpt.h (working copy) @@ -42,6 +42,8 @@ void sculpt_get_redraw_planes(float planes[4][4], struct ARegion *ar, struct RegionView3D *rv3d, struct Object *ob); void ED_sculpt_force_update(struct bContext *C); +float *ED_sculpt_get_last_stroke(struct Object *ob); +int ED_sculpt_minmax(struct bContext *C, float *min, float *max); /* paint_ops.c */ void ED_operatortypes_paint(void); Index: source/blender/editors/sculpt_paint/sculpt.c =================================================================== --- source/blender/editors/sculpt_paint/sculpt.c (revision 45655) +++ source/blender/editors/sculpt_paint/sculpt.c (working copy) @@ -101,6 +101,26 @@ multires_force_update(ob); } +float *ED_sculpt_get_last_stroke(struct Object *ob) +{ + return (ob && ob->sculpt && ob->sculpt->last_stroke_valid) ? ob->sculpt->last_stroke : NULL; +} + +int ED_sculpt_minmax(bContext *C, float *min, float *max) +{ + Object *ob= CTX_data_active_object(C); + + if (ob && ob->sculpt && ob->sculpt->last_stroke_valid) { + copy_v3_v3(min, ob->sculpt->last_stroke); + copy_v3_v3(max, ob->sculpt->last_stroke); + + return 1; + } + else { + return 0; + } +} + /* Sculpt mode handles multires differently from regular meshes, but only if * it's the last modifier on the stack and it is not on the first level */ struct MultiresModifierData *sculpt_multires_active(Scene *scene, Object *ob) @@ -3475,6 +3495,11 @@ } } + /* update last stroke position */ + ob->sculpt->last_stroke_valid= 1; + copy_v3_v3(ob->sculpt->last_stroke, ss->cache->true_location); + mul_m4_v3(ob->obmat, ob->sculpt->last_stroke); + sculpt_cache_free(ss->cache); ss->cache = NULL; Index: source/blender/editors/space_view3d/view3d_edit.c =================================================================== --- source/blender/editors/space_view3d/view3d_edit.c (revision 45655) +++ source/blender/editors/space_view3d/view3d_edit.c (working copy) @@ -73,6 +73,7 @@ #include "ED_transform.h" #include "ED_mesh.h" #include "ED_view3d.h" +#include "ED_sculpt.h" #include "PIL_time.h" /* smoothview */ @@ -2196,6 +2197,10 @@ else if (ob && (ob->mode & OB_MODE_PARTICLE_EDIT)) { ok = PE_minmax(scene, min, max); } + else if (ob && (ob->mode & OB_MODE_SCULPT)) { + ok = ED_sculpt_minmax(C, min, max); + ok_dist = 0; /* don't zoom */ + } else { Base *base; for (base = FIRSTBASE; base; base = base->next) { @@ -2219,20 +2224,26 @@ sub_v3_v3v3(afm, max, min); size = MAX3(afm[0], afm[1], afm[2]); - if (!rv3d->is_persp) { - if (size < 0.0001f) { /* if its a sinble point. don't even re-scale */ - ok_dist = 0; + if (ok_dist) { + /* fix up zoom distance if needed */ + + if (rv3d->is_persp) { + if (size <= v3d->near * 1.5f) { + /* do not zoom closer than the near clipping plane */ + size = v3d->near * 1.5f; + } } - else { - /* perspective should be a bit farther away to look nice */ - size *= 0.7f; + else /* ortho */ { + if (size < 0.0001f) { + /* bounding box was a single point so do not zoom */ + ok_dist = 0; + } + else { + /* adjust zoom so it looks nicer */ + size *= 0.7f; + } } } - else { - if (size <= v3d->near * 1.5f) { - size = v3d->near * 1.5f; - } - } add_v3_v3v3(new_ofs, min, max); mul_v3_fl(new_ofs, -0.5f); @@ -2248,7 +2259,7 @@ if (rv3d->persp == RV3D_CAMOB && !ED_view3d_camera_lock_check(v3d, rv3d)) { rv3d->persp = RV3D_PERSP; - smooth_view(C, v3d, ar, v3d->camera, NULL, new_ofs, NULL, &new_dist, NULL); + smooth_view(C, v3d, ar, v3d->camera, NULL, new_ofs, NULL, ok_dist ? &new_dist : NULL, NULL); } else { smooth_view(C, v3d, ar, NULL, NULL, new_ofs, NULL, ok_dist ? &new_dist : NULL, NULL);