GP: Improve center object in viewport when press .

Before when press . (view_select) the object was centered at the dummy, but now it's centered with the strokes bounding box size.

Also fixed some problems in edit mode when the object origin was not in view origin.
This commit is contained in:
Antonioya
2018-10-09 16:55:13 +02:00
parent 5cb633ce3f
commit 90e360c39f
3 changed files with 32 additions and 9 deletions

View File

@@ -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]);

View File

@@ -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;

View File

@@ -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);