GP: Add calculation of center for transformation by stroke (WIP)
authorAntonioya <blendergit@gmail.com>
Tue, 18 Dec 2018 21:56:23 +0000 (22:56 +0100)
committerAntonioya <blendergit@gmail.com>
Tue, 18 Dec 2018 21:56:40 +0000 (22:56 +0100)
source/blender/editors/transform/transform_conversions.c

index 0184e7543053c957aa62e986f0cbe243904c9ac2..3576406ee0b7697cbcee4bbd54c587f40c541de2 100644 (file)
@@ -8204,6 +8204,33 @@ void flushTransPaintCurve(TransInfo *t)
        }
 }
 
+static void createTransGPencil_center_get(
+       bGPDstroke *gps, const bool is_prop_edit, float r_center[3])
+{
+       bGPDspoint *pt;
+       int i;
+
+       zero_v3(r_center);
+       int tot_sel = 0;
+       for (i = 0, pt = gps->points; i < gps->totpoints; i++, pt++) {
+               bool point_ok;
+               if (is_prop_edit) {
+                       point_ok = true;
+               }
+               else {
+                       /* Only selected points in selected strokes */
+                       point_ok = (pt->flag & GP_SPOINT_SELECT) != 0;
+               }
+               if (point_ok) {
+                       add_v3_v3(r_center, &pt->x);
+                       tot_sel++;
+               }
+       }
+
+       if (tot_sel > 0) {
+               mul_v3_fl(r_center, 1.0f / tot_sel);
+       }
+}
 
 static void createTransGPencil(bContext *C, TransInfo *t)
 {
@@ -8407,6 +8434,10 @@ static void createTransGPencil(bContext *C, TransInfo *t)
                                                        /* save falloff factor */
                                                        gps->runtime.multi_frame_falloff = falloff;
 
+                                                       /* calculate stroke center */
+                                                       float center[3];
+                                                       createTransGPencil_center_get(gps, is_prop_edit, &center[0]);
+
                                                        /* add all necessary points... */
                                                        for (i = 0, pt = gps->points; i < gps->totpoints; i++, pt++) {
                                                                bool point_ok;
@@ -8424,7 +8455,7 @@ static void createTransGPencil(bContext *C, TransInfo *t)
                                                                /* do point... */
                                                                if (point_ok) {
                                                                        copy_v3_v3(td->iloc, &pt->x);
-                                                                       copy_v3_v3(td->center, &pt->x); // XXX: what about  t->around == local?
+                                                                       copy_v3_v3(td->center, center);
 
                                                                        td->loc = &pt->x;