Merge branch 'master' into blender2.8
authorCampbell Barton <ideasman42@gmail.com>
Fri, 7 Dec 2018 06:11:28 +0000 (17:11 +1100)
committerCampbell Barton <ideasman42@gmail.com>
Fri, 7 Dec 2018 06:11:28 +0000 (17:11 +1100)
1  2 
source/blender/editors/transform/transform_conversions.c

@@@ -1734,231 -1614,225 +1734,227 @@@ static void createTransCurveVerts(Trans
                                }
                        }
                }
 -      }
 -      /* note: in prop mode we need at least 1 selected */
 -      if (countsel == 0) return;
 +              /* note: in prop mode we need at least 1 selected */
 +              if (countsel == 0) {
 +                      tc->data_len = 0;
 +                      continue;
 +              }
  
 -      if (is_prop_edit) t->total = count;
 -      else t->total = countsel;
 -      t->data = MEM_callocN(t->total * sizeof(TransData), "TransObData(Curve EditMode)");
 +              if (is_prop_edit) tc->data_len = count;
 +              else tc->data_len = countsel;
 +              tc->data = MEM_callocN(tc->data_len * sizeof(TransData), "TransObData(Curve EditMode)");
  
 -      transform_around_single_fallback(t);
 +              transform_around_single_fallback(t);
  
 -      copy_m3_m4(mtx, t->obedit->obmat);
 -      pseudoinverse_m3_m3(smtx, mtx, PSEUDOINVERSE_EPSILON);
 +              copy_m3_m4(mtx, tc->obedit->obmat);
 +              pseudoinverse_m3_m3(smtx, mtx, PSEUDOINVERSE_EPSILON);
  
 -      td = t->data;
 -      for (nu = nurbs->first; nu; nu = nu->next) {
 -              if (nu->type == CU_BEZIER) {
 -                      TransData *head, *tail;
 -                      head = tail = td;
 -                      for (a = 0, bezt = nu->bezt; a < nu->pntsu; a++, bezt++) {
 -                              if (bezt->hide == 0) {
 -                                      TransDataCurveHandleFlags *hdata = NULL;
 -                                      float axismtx[3][3];
 +              td = tc->data;
 +              for (nu = nurbs->first; nu; nu = nu->next) {
 +                      if (nu->type == CU_BEZIER) {
 +                              TransData *head, *tail;
 +                              head = tail = td;
 +                              for (a = 0, bezt = nu->bezt; a < nu->pntsu; a++, bezt++) {
 +                                      if (bezt->hide == 0) {
 +                                              TransDataCurveHandleFlags *hdata = NULL;
 +                                              float axismtx[3][3];
  
 -                                      if (t->around == V3D_AROUND_LOCAL_ORIGINS) {
 -                                              float normal[3], plane[3];
 +                                              if (t->around == V3D_AROUND_LOCAL_ORIGINS) {
 +                                                      float normal[3], plane[3];
  
 -                                              BKE_nurb_bezt_calc_normal(nu, bezt, normal);
 -                                              BKE_nurb_bezt_calc_plane(nu, bezt, plane);
 +                                                      BKE_nurb_bezt_calc_normal(nu, bezt, normal);
 +                                                      BKE_nurb_bezt_calc_plane(nu, bezt, plane);
  
 -                                              if (createSpaceNormalTangent(axismtx, normal, plane)) {
 -                                                      /* pass */
 -                                              }
 -                                              else {
 -                                                      normalize_v3(normal);
 -                                                      axis_dominant_v3_to_m3(axismtx, normal);
 -                                                      invert_m3(axismtx);
 +                                                      if (createSpaceNormalTangent(axismtx, normal, plane)) {
 +                                                              /* pass */
 +                                                      }
 +                                                      else {
 +                                                              normalize_v3(normal);
 +                                                              axis_dominant_v3_to_m3(axismtx, normal);
 +                                                              invert_m3(axismtx);
 +                                                      }
                                                }
 -                                      }
  
 -                                      /* Elements that will be transform (not always a match to selection). */
 -                                      const int bezt_tx = bezt_select_to_transform_triple_flag(bezt, hide_handles);
 +                                              /* Elements that will be transform (not always a match to selection). */
 +                                              const int bezt_tx = bezt_select_to_transform_triple_flag(bezt, hide_handles);
 +
 +                                              if (is_prop_edit || bezt_tx & SEL_F1) {
 +                                                      copy_v3_v3(td->iloc, bezt->vec[0]);
 +                                                      td->loc = bezt->vec[0];
 +                                                      copy_v3_v3(td->center, bezt->vec[(hide_handles ||
 +                                                                                        (t->around == V3D_AROUND_LOCAL_ORIGINS) ||
 +                                                                                        (bezt->f2 & SELECT)) ? 1 : 0]);
 +                                                      if (hide_handles) {
 +                                                              if (bezt->f2 & SELECT) td->flag = TD_SELECTED;
 +                                                              else td->flag = 0;
 +                                                      }
 +                                                      else {
 +                                                              if (bezt->f1 & SELECT) td->flag = TD_SELECTED;
 +                                                              else td->flag = 0;
 +                                                      }
 +                                                      td->ext = NULL;
 +                                                      td->val = NULL;
  
 -                                      if (is_prop_edit || bezt_tx & SEL_F1) {
 -                                              copy_v3_v3(td->iloc, bezt->vec[0]);
 -                                              td->loc = bezt->vec[0];
 -                                              copy_v3_v3(td->center, bezt->vec[(hide_handles ||
 -                                                                                (t->around == V3D_AROUND_LOCAL_ORIGINS) ||
 -                                                                                (bezt->f2 & SELECT)) ? 1 : 0]);
 -                                              if (hide_handles) {
 -                                                      if (bezt->f2 & SELECT) td->flag = TD_SELECTED;
 -                                                      else td->flag = 0;
 -                                              }
 -                                              else {
 -                                                      if (bezt->f1 & SELECT) td->flag = TD_SELECTED;
 -                                                      else td->flag = 0;
 -                                              }
 -                                              td->ext = NULL;
 -                                              td->val = NULL;
 +                                                      hdata = initTransDataCurveHandles(td, bezt);
  
 -                                              hdata = initTransDataCurveHandles(td, bezt);
 +                                                      copy_m3_m3(td->smtx, smtx);
 +                                                      copy_m3_m3(td->mtx, mtx);
 +                                                      if (t->around == V3D_AROUND_LOCAL_ORIGINS) {
 +                                                              copy_m3_m3(td->axismtx, axismtx);
 +                                                      }
  
 -                                              copy_m3_m3(td->smtx, smtx);
 -                                              copy_m3_m3(td->mtx, mtx);
 -                                              if (t->around == V3D_AROUND_LOCAL_ORIGINS) {
 -                                                      copy_m3_m3(td->axismtx, axismtx);
 +                                                      td++;
-                                                       count++;
 +                                                      tail++;
                                                }
  
 -                                              td++;
 -                                              tail++;
 -                                      }
 +                                              /* This is the Curve Point, the other two are handles */
 +                                              if (is_prop_edit || bezt_tx & SEL_F2) {
 +                                                      copy_v3_v3(td->iloc, bezt->vec[1]);
 +                                                      td->loc = bezt->vec[1];
 +                                                      copy_v3_v3(td->center, td->loc);
 +                                                      if (bezt->f2 & SELECT) td->flag = TD_SELECTED;
 +                                                      else td->flag = 0;
 +                                                      td->ext = NULL;
  
 -                                      /* This is the Curve Point, the other two are handles */
 -                                      if (is_prop_edit || bezt_tx & SEL_F2) {
 -                                              copy_v3_v3(td->iloc, bezt->vec[1]);
 -                                              td->loc = bezt->vec[1];
 -                                              copy_v3_v3(td->center, td->loc);
 -                                              if (bezt->f2 & SELECT) td->flag = TD_SELECTED;
 -                                              else td->flag = 0;
 -                                              td->ext = NULL;
 +                                                      if (t->mode == TFM_CURVE_SHRINKFATTEN) { /* || t->mode==TFM_RESIZE) {*/ /* TODO - make points scale */
 +                                                              td->val = &(bezt->radius);
 +                                                              td->ival = bezt->radius;
 +                                                      }
 +                                                      else if (t->mode == TFM_TILT) {
 +                                                              td->val = &(bezt->alfa);
 +                                                              td->ival = bezt->alfa;
 +                                                      }
 +                                                      else {
 +                                                              td->val = NULL;
 +                                                      }
  
 -                                              if (t->mode == TFM_CURVE_SHRINKFATTEN) { /* || t->mode==TFM_RESIZE) {*/ /* TODO - make points scale */
 -                                                      td->val = &(bezt->radius);
 -                                                      td->ival = bezt->radius;
 -                                              }
 -                                              else if (t->mode == TFM_TILT) {
 -                                                      td->val = &(bezt->alfa);
 -                                                      td->ival = bezt->alfa;
 -                                              }
 -                                              else {
 -                                                      td->val = NULL;
 -                                              }
 +                                                      copy_m3_m3(td->smtx, smtx);
 +                                                      copy_m3_m3(td->mtx, mtx);
 +                                                      if (t->around == V3D_AROUND_LOCAL_ORIGINS) {
 +                                                              copy_m3_m3(td->axismtx, axismtx);
 +                                                      }
  
 -                                              copy_m3_m3(td->smtx, smtx);
 -                                              copy_m3_m3(td->mtx, mtx);
 -                                              if (t->around == V3D_AROUND_LOCAL_ORIGINS) {
 -                                                      copy_m3_m3(td->axismtx, axismtx);
 +                                                      if ((bezt_tx & SEL_F1) == 0 && (bezt_tx & SEL_F3) == 0)
 +                                                              /* If the middle is selected but the sides arnt, this is needed */
 +                                                              if (hdata == NULL) { /* if the handle was not saved by the previous handle */
 +                                                                      hdata = initTransDataCurveHandles(td, bezt);
 +                                                              }
 +
 +                                                      td++;
-                                                       count++;
 +                                                      tail++;
                                                }
 +                                              if (is_prop_edit || bezt_tx & SEL_F3) {
 +                                                      copy_v3_v3(td->iloc, bezt->vec[2]);
 +                                                      td->loc = bezt->vec[2];
 +                                                      copy_v3_v3(td->center, bezt->vec[(hide_handles ||
 +                                                                                        (t->around == V3D_AROUND_LOCAL_ORIGINS) ||
 +                                                                                        (bezt->f2 & SELECT)) ? 1 : 2]);
 +                                                      if (hide_handles) {
 +                                                              if (bezt->f2 & SELECT) td->flag = TD_SELECTED;
 +                                                              else td->flag = 0;
 +                                                      }
 +                                                      else {
 +                                                              if (bezt->f3 & SELECT) td->flag = TD_SELECTED;
 +                                                              else td->flag = 0;
 +                                                      }
 +                                                      td->ext = NULL;
 +                                                      td->val = NULL;
  
 -                                              if ((bezt_tx & SEL_F1) == 0 && (bezt_tx & SEL_F3) == 0)
 -                                                      /* If the middle is selected but the sides arnt, this is needed */
                                                        if (hdata == NULL) { /* if the handle was not saved by the previous handle */
                                                                hdata = initTransDataCurveHandles(td, bezt);
                                                        }
  
 -                                              td++;
 -                                              tail++;
 -                                      }
 -                                      if (is_prop_edit || bezt_tx & SEL_F3) {
 -                                              copy_v3_v3(td->iloc, bezt->vec[2]);
 -                                              td->loc = bezt->vec[2];
 -                                              copy_v3_v3(td->center, bezt->vec[(hide_handles ||
 -                                                                                (t->around == V3D_AROUND_LOCAL_ORIGINS) ||
 -                                                                                (bezt->f2 & SELECT)) ? 1 : 2]);
 -                                              if (hide_handles) {
 -                                                      if (bezt->f2 & SELECT) td->flag = TD_SELECTED;
 -                                                      else td->flag = 0;
 -                                              }
 -                                              else {
 -                                                      if (bezt->f3 & SELECT) td->flag = TD_SELECTED;
 -                                                      else td->flag = 0;
 -                                              }
 -                                              td->ext = NULL;
 -                                              td->val = NULL;
 -
 -                                              if (hdata == NULL) { /* if the handle was not saved by the previous handle */
 -                                                      hdata = initTransDataCurveHandles(td, bezt);
 -                                              }
 +                                                      copy_m3_m3(td->smtx, smtx);
 +                                                      copy_m3_m3(td->mtx, mtx);
 +                                                      if (t->around == V3D_AROUND_LOCAL_ORIGINS) {
 +                                                              copy_m3_m3(td->axismtx, axismtx);
 +                                                      }
  
 -                                              copy_m3_m3(td->smtx, smtx);
 -                                              copy_m3_m3(td->mtx, mtx);
 -                                              if (t->around == V3D_AROUND_LOCAL_ORIGINS) {
 -                                                      copy_m3_m3(td->axismtx, axismtx);
 +                                                      td++;
-                                                       count++;
 +                                                      tail++;
                                                }
  
 -                                              td++;
 -                                              tail++;
 +                                              (void)hdata;  /* quiet warning */
 +                                      }
 +                                      else if (is_prop_edit && head != tail) {
 +                                              calc_distanceCurveVerts(head, tail - 1);
 +                                              head = tail;
                                        }
 -
 -                                      (void)hdata;  /* quiet warning */
                                }
 -                              else if (is_prop_edit && head != tail) {
 +                              if (is_prop_edit && head != tail)
                                        calc_distanceCurveVerts(head, tail - 1);
 -                                      head = tail;
 -                              }
 -                      }
 -                      if (is_prop_edit && head != tail)
 -                              calc_distanceCurveVerts(head, tail - 1);
  
 -                      /* TODO - in the case of tilt and radius we can also avoid allocating the initTransDataCurveHandles
 -                       * but for now just don't change handle types */
 -                      if (ELEM(t->mode, TFM_CURVE_SHRINKFATTEN, TFM_TILT, TFM_DUMMY) == 0) {
 -                              /* sets the handles based on their selection, do this after the data is copied to the TransData */
 -                              BKE_nurb_handles_test(nu, !hide_handles);
 +                              /* TODO - in the case of tilt and radius we can also avoid allocating the initTransDataCurveHandles
 +                               * but for now just don't change handle types */
 +                              if (ELEM(t->mode, TFM_CURVE_SHRINKFATTEN, TFM_TILT, TFM_DUMMY) == 0) {
 +                                      /* sets the handles based on their selection, do this after the data is copied to the TransData */
 +                                      BKE_nurb_handles_test(nu, !hide_handles);
 +                              }
                        }
 -              }
 -              else {
 -                      TransData *head, *tail;
 -                      head = tail = td;
 -                      for (a = nu->pntsu * nu->pntsv, bp = nu->bp; a > 0; a--, bp++) {
 -                              if (bp->hide == 0) {
 -                                      if (is_prop_edit || (bp->f1 & SELECT)) {
 -                                              float axismtx[3][3];
 -
 -                                              if (t->around == V3D_AROUND_LOCAL_ORIGINS) {
 -                                                      if (nu->pntsv == 1) {
 -                                                              float normal[3], plane[3];
 -
 -                                                              BKE_nurb_bpoint_calc_normal(nu, bp, normal);
 -                                                              BKE_nurb_bpoint_calc_plane(nu, bp, plane);
 -
 -                                                              if (createSpaceNormalTangent(axismtx, normal, plane)) {
 -                                                                      /* pass */
 -                                                              }
 -                                                              else {
 -                                                                      normalize_v3(normal);
 -                                                                      axis_dominant_v3_to_m3(axismtx, normal);
 -                                                                      invert_m3(axismtx);
 +                      else {
 +                              TransData *head, *tail;
 +                              head = tail = td;
 +                              for (a = nu->pntsu * nu->pntsv, bp = nu->bp; a > 0; a--, bp++) {
 +                                      if (bp->hide == 0) {
 +                                              if (is_prop_edit || (bp->f1 & SELECT)) {
 +                                                      float axismtx[3][3];
 +
 +                                                      if (t->around == V3D_AROUND_LOCAL_ORIGINS) {
 +                                                              if (nu->pntsv == 1) {
 +                                                                      float normal[3], plane[3];
 +
 +                                                                      BKE_nurb_bpoint_calc_normal(nu, bp, normal);
 +                                                                      BKE_nurb_bpoint_calc_plane(nu, bp, plane);
 +
 +                                                                      if (createSpaceNormalTangent(axismtx, normal, plane)) {
 +                                                                              /* pass */
 +                                                                      }
 +                                                                      else {
 +                                                                              normalize_v3(normal);
 +                                                                              axis_dominant_v3_to_m3(axismtx, normal);
 +                                                                              invert_m3(axismtx);
 +                                                                      }
                                                                }
                                                        }
 -                                              }
  
 -                                              copy_v3_v3(td->iloc, bp->vec);
 -                                              td->loc = bp->vec;
 -                                              copy_v3_v3(td->center, td->loc);
 -                                              if (bp->f1 & SELECT) td->flag = TD_SELECTED;
 -                                              else td->flag = 0;
 -                                              td->ext = NULL;
 +                                                      copy_v3_v3(td->iloc, bp->vec);
 +                                                      td->loc = bp->vec;
 +                                                      copy_v3_v3(td->center, td->loc);
 +                                                      if (bp->f1 & SELECT) td->flag = TD_SELECTED;
 +                                                      else td->flag = 0;
 +                                                      td->ext = NULL;
  
 -                                              if (t->mode == TFM_CURVE_SHRINKFATTEN || t->mode == TFM_RESIZE) {
 -                                                      td->val = &(bp->radius);
 -                                                      td->ival = bp->radius;
 -                                              }
 -                                              else {
 -                                                      td->val = &(bp->alfa);
 -                                                      td->ival = bp->alfa;
 -                                              }
 +                                                      if (t->mode == TFM_CURVE_SHRINKFATTEN || t->mode == TFM_RESIZE) {
 +                                                              td->val = &(bp->radius);
 +                                                              td->ival = bp->radius;
 +                                                      }
 +                                                      else {
 +                                                              td->val = &(bp->alfa);
 +                                                              td->ival = bp->alfa;
 +                                                      }
  
 -                                              copy_m3_m3(td->smtx, smtx);
 -                                              copy_m3_m3(td->mtx, mtx);
 -                                              if (t->around == V3D_AROUND_LOCAL_ORIGINS) {
 -                                                      if (nu->pntsv == 1) {
 -                                                              copy_m3_m3(td->axismtx, axismtx);
 +                                                      copy_m3_m3(td->smtx, smtx);
 +                                                      copy_m3_m3(td->mtx, mtx);
 +                                                      if (t->around == V3D_AROUND_LOCAL_ORIGINS) {
 +                                                              if (nu->pntsv == 1) {
 +                                                                      copy_m3_m3(td->axismtx, axismtx);
 +                                                              }
                                                        }
 -                                              }
  
 -                                              td++;
 -                                              tail++;
 +                                                      td++;
-                                                       count++;
 +                                                      tail++;
 +                                              }
 +                                      }
 +                                      else if (is_prop_edit && head != tail) {
 +                                              calc_distanceCurveVerts(head, tail - 1);
 +                                              head = tail;
                                        }
                                }
 -                              else if (is_prop_edit && head != tail) {
 +                              if (is_prop_edit && head != tail)
                                        calc_distanceCurveVerts(head, tail - 1);
 -                                      head = tail;
 -                              }
                        }
 -                      if (is_prop_edit && head != tail)
 -                              calc_distanceCurveVerts(head, tail - 1);
                }
        }
 -
  #undef SEL_F1
  #undef SEL_F2
  #undef SEL_F3
  
  static void createTransLatticeVerts(TransInfo *t)
  {
 -      Lattice *latt = ((Lattice *)t->obedit->data)->editlatt->latt;
 -      TransData *td = NULL;
 -      BPoint *bp;
 -      float mtx[3][3], smtx[3][3];
 -      int a;
 -      int count = 0, countsel = 0;
 -      const bool is_prop_edit = (t->flag & T_PROP_EDIT) != 0;
 +      FOREACH_TRANS_DATA_CONTAINER (t, tc) {
  
 -      bp = latt->def;
 -      a  = latt->pntsu * latt->pntsv * latt->pntsw;
 -      while (a--) {
 -              if (bp->hide == 0) {
 -                      if (bp->f1 & SELECT) countsel++;
 -                      if (is_prop_edit) count++;
 +              Lattice *latt = ((Lattice *)tc->obedit->data)->editlatt->latt;
 +              TransData *td = NULL;
 +              BPoint *bp;
 +              float mtx[3][3], smtx[3][3];
 +              int a;
 +              int count = 0, countsel = 0;
 +              const bool is_prop_edit = (t->flag & T_PROP_EDIT) != 0;
 +
 +              bp = latt->def;
 +              a  = latt->pntsu * latt->pntsv * latt->pntsw;
 +              while (a--) {
 +                      if (bp->hide == 0) {
 +                              if (bp->f1 & SELECT) countsel++;
 +                              if (is_prop_edit) count++;
 +                      }
 +                      bp++;
                }
 -              bp++;
 -      }
  
 -      /* note: in prop mode we need at least 1 selected */
 -      if (countsel == 0) return;
 +              /* note: in prop mode we need at least 1 selected */
 +              if (countsel == 0) return;
  
 -      if (is_prop_edit) t->total = count;
 -      else t->total = countsel;
 -      t->data = MEM_callocN(t->total * sizeof(TransData), "TransObData(Lattice EditMode)");
 +              if (is_prop_edit) tc->data_len = count;
 +              else tc->data_len = countsel;
 +              tc->data = MEM_callocN(tc->data_len * sizeof(TransData), "TransObData(Lattice EditMode)");
  
 -      copy_m3_m4(mtx, t->obedit->obmat);
 -      pseudoinverse_m3_m3(smtx, mtx, PSEUDOINVERSE_EPSILON);
 +              copy_m3_m4(mtx, tc->obedit->obmat);
 +              pseudoinverse_m3_m3(smtx, mtx, PSEUDOINVERSE_EPSILON);
  
 -      td = t->data;
 -      bp = latt->def;
 -      a  = latt->pntsu * latt->pntsv * latt->pntsw;
 -      while (a--) {
 -              if (is_prop_edit || (bp->f1 & SELECT)) {
 -                      if (bp->hide == 0) {
 -                              copy_v3_v3(td->iloc, bp->vec);
 -                              td->loc = bp->vec;
 -                              copy_v3_v3(td->center, td->loc);
 -                              if (bp->f1 & SELECT) {
 -                                      td->flag = TD_SELECTED;
 -                              }
 -                              else {
 -                                      td->flag = 0;
 -                              }
 -                              copy_m3_m3(td->smtx, smtx);
 -                              copy_m3_m3(td->mtx, mtx);
 +              td = tc->data;
 +              bp = latt->def;
 +              a  = latt->pntsu * latt->pntsv * latt->pntsw;
 +              while (a--) {
 +                      if (is_prop_edit || (bp->f1 & SELECT)) {
 +                              if (bp->hide == 0) {
 +                                      copy_v3_v3(td->iloc, bp->vec);
 +                                      td->loc = bp->vec;
 +                                      copy_v3_v3(td->center, td->loc);
 +                                      if (bp->f1 & SELECT) {
 +                                              td->flag = TD_SELECTED;
 +                                      }
 +                                      else {
 +                                              td->flag = 0;
 +                                      }
 +                                      copy_m3_m3(td->smtx, smtx);
 +                                      copy_m3_m3(td->mtx, mtx);
  
 -                              td->ext = NULL;
 -                              td->val = NULL;
 +                                      td->ext = NULL;
 +                                      td->val = NULL;
  
 -                              td++;
 +                                      td++;
-                                       count++;
 +                              }
                        }
 +                      bp++;
                }
 -              bp++;
        }
  }