diff options
-rw-r--r-- | source/blender/blenkernel/BKE_gpencil.h | 3 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/gpencil.c | 27 | ||||
-rw-r--r-- | source/blender/editors/space_view3d/view3d_edit.c | 11 |
3 files changed, 32 insertions, 9 deletions
diff --git a/source/blender/blenkernel/BKE_gpencil.h b/source/blender/blenkernel/BKE_gpencil.h index 058e42bd261..8ab088eff02 100644 --- a/source/blender/blenkernel/BKE_gpencil.h +++ b/source/blender/blenkernel/BKE_gpencil.h @@ -143,6 +143,9 @@ struct Material *BKE_gpencil_get_material_from_brush(struct Brush *brush); struct Material *BKE_gpencil_material_ensure(struct Main *bmain, struct Object *ob); /* object boundbox */ +bool BKE_gpencil_data_minmax( + struct Object *ob, const struct bGPdata *gpd, + float r_min[3], float r_max[3]); bool BKE_gpencil_stroke_minmax( const struct bGPDstroke *gps, const bool use_select, float r_min[3], float r_max[3]); diff --git a/source/blender/blenkernel/intern/gpencil.c b/source/blender/blenkernel/intern/gpencil.c index ae78dd8d175..559d4ef3bef 100644 --- a/source/blender/blenkernel/intern/gpencil.c +++ b/source/blender/blenkernel/intern/gpencil.c @@ -1088,8 +1088,8 @@ Material *BKE_gpencil_material_ensure(Main *bmain, Object *ob) * \return Returns whether we found any selected points */ bool BKE_gpencil_stroke_minmax( - const bGPDstroke *gps, const bool use_select, - float r_min[3], float r_max[3]) + const bGPDstroke *gps, const bool use_select, + float r_min[3], float r_max[3]) { const bGPDspoint *pt; int i; @@ -1108,22 +1108,35 @@ bool BKE_gpencil_stroke_minmax( } /* get min/max bounds of all strokes in GP datablock */ -static void gpencil_minmax(bGPdata *gpd, float r_min[3], float r_max[3]) +bool BKE_gpencil_data_minmax(Object *ob, const bGPdata *gpd, float r_min[3], float r_max[3]) { + float bmat[3][3]; + bool changed = false; + INIT_MINMAX(r_min, r_max); if (gpd == NULL) - return; + return changed; for (bGPDlayer *gpl = gpd->layers.first; gpl; gpl = gpl->next) { bGPDframe *gpf = gpl->actframe; if (gpf != NULL) { for (bGPDstroke *gps = gpf->strokes.first; gps; gps = gps->next) { - BKE_gpencil_stroke_minmax(gps, false, r_min, r_max); + changed = BKE_gpencil_stroke_minmax(gps, false, r_min, r_max); } } } + + if ((changed) && (ob)) { + copy_m3_m4(bmat, ob->obmat); + mul_m3_v3(bmat, r_min); + add_v3_v3(r_min, ob->obmat[3]); + mul_m3_v3(bmat, r_max); + add_v3_v3(r_max, ob->obmat[3]); + } + + return changed; } /* compute center of bounding box */ @@ -1131,7 +1144,7 @@ void BKE_gpencil_centroid_3D(bGPdata *gpd, float r_centroid[3]) { float min[3], max[3], tot[3]; - gpencil_minmax(gpd, min, max); + BKE_gpencil_data_minmax(NULL, gpd, min, max); add_v3_v3v3(tot, min, max); mul_v3_v3fl(r_centroid, tot, 0.5f); @@ -1152,7 +1165,7 @@ static void boundbox_gpencil(Object *ob) bb = ob->bb; gpd = ob->data; - gpencil_minmax(gpd, min, max); + BKE_gpencil_data_minmax(NULL, gpd, min, max); BKE_boundbox_init_from_minmax(bb, min, max); bb->flag &= ~BOUNDBOX_DIRTY; diff --git a/source/blender/editors/space_view3d/view3d_edit.c b/source/blender/editors/space_view3d/view3d_edit.c index e710d7b2d2a..84136f657ef 100644 --- a/source/blender/editors/space_view3d/view3d_edit.c +++ b/source/blender/editors/space_view3d/view3d_edit.c @@ -2825,7 +2825,7 @@ static int viewselected_exec(bContext *C, wmOperator *op) const int smooth_viewtx = WM_operator_smooth_viewtx_get(op); INIT_MINMAX(min, max); - if (is_gp_edit || is_face_map) { + if (is_face_map) { ob_eval = NULL; } @@ -2845,7 +2845,6 @@ static int viewselected_exec(bContext *C, wmOperator *op) } if (is_gp_edit) { - /* TODO(sergey): Check on this after gpencil merge. */ CTX_DATA_BEGIN(C, bGPDstroke *, gps, editable_gpencil_strokes) { /* we're only interested in selected points here... */ @@ -2854,6 +2853,14 @@ static int viewselected_exec(bContext *C, wmOperator *op) } } CTX_DATA_END; + + if ((ob_eval) && (ok)) { + add_v3_v3(min, ob_eval->obmat[3]); + add_v3_v3(max, ob_eval->obmat[3]); + } + } + else if (ob_eval && (ob_eval->type == OB_GPENCIL)) { + ok |= BKE_gpencil_data_minmax(ob_eval, gpd, min, max); } else if (is_face_map) { ok = WM_gizmomap_minmax(ar->gizmo_map, true, true, min, max); |