Merge branch 'master' into blender2.8
authorCampbell Barton <ideasman42@gmail.com>
Tue, 13 Nov 2018 03:24:41 +0000 (14:24 +1100)
committerCampbell Barton <ideasman42@gmail.com>
Tue, 13 Nov 2018 03:25:36 +0000 (14:25 +1100)
16 files changed:
1  2 
source/blender/blenkernel/BKE_brush.h
source/blender/blenkernel/BKE_curve.h
source/blender/blenkernel/BKE_gpencil.h
source/blender/blenkernel/intern/brush.c
source/blender/blenkernel/intern/curve.c
source/blender/blenkernel/intern/gpencil.c
source/blender/editors/curve/editcurve.c
source/blender/editors/curve/editcurve_add.c
source/blender/editors/object/object_transform.c
source/blender/editors/sculpt_paint/paint_image_2d.c
source/blender/editors/sculpt_paint/paint_image_proj.c
source/blender/editors/sculpt_paint/paint_vertex.c
source/blender/editors/sculpt_paint/sculpt.c
source/blender/editors/space_view3d/view3d_buttons.c
source/blender/editors/transform/transform_generics.c
source/blender/editors/util/ed_transverts.c

Simple merge
Simple merge
index 14c4e8fec3236f8e32350b8f158d562a3a823d7d,92e16f02e2510a87e254332f4747ac8d85561a67..3b8df66668a7417bb80dcf564b288994e3409a79
@@@ -139,44 -103,20 +139,44 @@@ struct bGPDlayer *BKE_gpencil_layer_get
  void BKE_gpencil_layer_setactive(struct bGPdata *gpd, struct bGPDlayer *active);
  void BKE_gpencil_layer_delete(struct bGPdata *gpd, struct bGPDlayer *gpl);
  
 -struct bGPDbrush *BKE_gpencil_brush_getactive(struct ToolSettings *ts);
 -void BKE_gpencil_brush_setactive(struct ToolSettings *ts, struct bGPDbrush *active);
 -void BKE_gpencil_brush_delete(struct ToolSettings *ts, struct bGPDbrush *brush);
 -
 -struct bGPDpalette *BKE_gpencil_palette_getactive(struct bGPdata *gpd);
 -void BKE_gpencil_palette_setactive(struct bGPdata *gpd, struct bGPDpalette *active);
 -void BKE_gpencil_palette_delete(struct bGPdata *gpd, struct bGPDpalette *palette);
 -void BKE_gpencil_palette_change_strokes(struct bGPdata *gpd);
 -
 -struct bGPDpalettecolor *BKE_gpencil_palettecolor_getactive(struct bGPDpalette *palette);
 -void BKE_gpencil_palettecolor_setactive(struct bGPDpalette *palette, struct bGPDpalettecolor *active);
 -void BKE_gpencil_palettecolor_delete(struct bGPDpalette *palette, struct bGPDpalettecolor *palcolor);
 -struct bGPDpalettecolor *BKE_gpencil_palettecolor_getbyname(struct bGPDpalette *palette, char *name);
 -void BKE_gpencil_palettecolor_changename(struct bGPdata *gpd, char *oldname, const char *newname);
 -void BKE_gpencil_palettecolor_delete_strokes(struct bGPdata *gpd, char *name);
 +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]);
 +bool BKE_gpencil_stroke_select_check(
 +      const struct bGPDstroke *gps);
 +
 +struct BoundBox *BKE_gpencil_boundbox_get(struct Object *ob);
- void BKE_gpencil_centroid_3D(struct bGPdata *gpd, float r_centroid[3]);
++void BKE_gpencil_centroid_3d(struct bGPdata *gpd, float r_centroid[3]);
 +
 +/* vertex groups */
 +void BKE_gpencil_dvert_ensure(struct bGPDstroke *gps);
 +void BKE_gpencil_vgroup_remove(struct Object *ob, struct bDeformGroup *defgroup);
 +void BKE_gpencil_stroke_weights_duplicate(struct bGPDstroke *gps_src, struct bGPDstroke *gps_dst);
 +
 +/* GPencil geometry evaluation */
 +void BKE_gpencil_eval_geometry(struct Depsgraph *depsgraph, struct bGPdata *gpd);
 +
 +/* stroke geometry utilities */
 +void BKE_gpencil_stroke_normal(const struct bGPDstroke *gps, float r_normal[3]);
 +void BKE_gpencil_simplify_stroke(struct bGPDstroke *gps, float factor);
 +void BKE_gpencil_simplify_fixed(struct bGPDstroke *gps);
 +void BKE_gpencil_subdivide(struct bGPDstroke *gps, int level, int flag);
 +
 +void BKE_gpencil_transform(struct bGPdata *gpd, float mat[4][4]);
 +
 +bool BKE_gpencil_smooth_stroke(struct bGPDstroke *gps, int i, float inf);
 +bool BKE_gpencil_smooth_stroke_strength(struct bGPDstroke *gps, int point_index, float influence);
 +bool BKE_gpencil_smooth_stroke_thickness(struct bGPDstroke *gps, int point_index, float influence);
 +bool BKE_gpencil_smooth_stroke_uv(struct bGPDstroke *gps, int point_index, float influence);
 +
 +void BKE_gpencil_get_range_selected(struct bGPDlayer *gpl, int *r_initframe, int *r_endframe);
 +float BKE_gpencil_multiframe_falloff_calc(struct bGPDframe *gpf, int actnum, int f_init, int f_end, struct CurveMapping *cur_falloff);
  
  #endif /*  __BKE_GPENCIL_H__ */
index ed551b1c109c85953447e1f7dd76db55ffb79dcb,e89508fd6c0f8fd9b5cc46ba9ccad2c1aeade66b..9c398182bb6aeeedf9556ef605ea8941fc0d34e5
@@@ -1037,227 -1106,138 +1037,227 @@@ void BKE_gpencil_layer_delete(bGPdata *
        BLI_freelinkN(&gpd->layers, gpl);
  }
  
 -/* ************************************************** */
 -/* get the active gp-brush for editing */
 -bGPDbrush *BKE_gpencil_brush_getactive(ToolSettings *ts)
 +Material *BKE_gpencil_get_material_from_brush(Brush *brush)
  {
 -      bGPDbrush *brush;
 +      Material *ma = NULL;
  
 -      /* error checking */
 -      if (ELEM(NULL, ts, ts->gp_brushes.first)) {
 -              return NULL;
 +      if ((brush != NULL) && (brush->gpencil_settings != NULL) &&
 +          (brush->gpencil_settings->material != NULL))
 +      {
 +              ma = brush->gpencil_settings->material;
        }
  
 -      /* loop over brushes until found (assume only one active) */
 -      for (brush = ts->gp_brushes.first; brush; brush = brush->next) {
 -              if (brush->flag & GP_BRUSH_ACTIVE) {
 -                      return brush;
 +      return ma;
 +}
 +
 +/* Get active color, and add all default settings if we don't find anything */
 +Material *BKE_gpencil_material_ensure(Main *bmain, Object *ob)
 +{
 +      Material *ma = NULL;
 +
 +      /* sanity checks */
 +      if (ELEM(NULL, bmain, ob))
 +              return NULL;
 +
 +      ma = give_current_material(ob, ob->actcol);
 +      if (ma == NULL) {
 +              if (ob->totcol == 0) {
 +                      BKE_object_material_slot_add(bmain, ob);
                }
 +              ma = BKE_material_add_gpencil(bmain, DATA_("Material"));
 +              assign_material(bmain, ob, ma, ob->totcol, BKE_MAT_ASSIGN_USERPREF);
 +      }
 +      else if (ma->gp_style == NULL) {
 +              BKE_material_init_gpencil_settings(ma);
        }
  
 -      /* no active brush found */
 -      return NULL;
 +      return ma;
  }
  
 -/* set the active gp-brush */
 -void BKE_gpencil_brush_setactive(ToolSettings *ts, bGPDbrush *active)
 +/* ************************************************** */
 +/* GP Object - Boundbox Support */
 +
 +/**
 + * Get min/max coordinate bounds for single stroke
 + * \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])
  {
 -      bGPDbrush *brush;
 +      const bGPDspoint *pt;
 +      int i;
 +      bool changed = false;
  
 -      /* error checking */
 -      if (ELEM(NULL, ts, ts->gp_brushes.first, active)) {
 -              return;
 -      }
 +      if (ELEM(NULL, gps, r_min, r_max))
 +              return false;
  
 -      /* loop over brushes deactivating all */
 -      for (brush = ts->gp_brushes.first; brush; brush = brush->next) {
 -              brush->flag &= ~GP_BRUSH_ACTIVE;
 +      for (i = 0, pt = gps->points; i < gps->totpoints; i++, pt++) {
 +              if ((use_select == false) || (pt->flag & GP_SPOINT_SELECT)) {
 +                      minmax_v3v3_v3(r_min, r_max, &pt->x);
 +                      changed = true;
 +              }
        }
 -
 -      /* set as active one */
 -      active->flag |= GP_BRUSH_ACTIVE;
 +      return changed;
  }
  
 -/* delete the active gp-brush */
 -void BKE_gpencil_brush_delete(ToolSettings *ts, bGPDbrush *brush)
 +/* get min/max bounds of all strokes in GP datablock */
 +bool BKE_gpencil_data_minmax(Object *ob, const bGPdata *gpd, float r_min[3], float r_max[3])
  {
 -      /* error checking */
 -      if (ELEM(NULL, ts, brush)) {
 -              return;
 -      }
 +      float bmat[3][3];
 +      bool changed = false;
 +
 +      INIT_MINMAX(r_min, r_max);
 +
 +      if (gpd == NULL)
 +              return changed;
 +
 +      for (bGPDlayer *gpl = gpd->layers.first; gpl; gpl = gpl->next) {
 +              bGPDframe *gpf = gpl->actframe;
  
 -      /* free curves */
 -      if (brush->cur_sensitivity) {
 -              curvemapping_free(brush->cur_sensitivity);
 +              if (gpf != NULL) {
 +                      for (bGPDstroke *gps = gpf->strokes.first; gps; gps = gps->next) {
 +                              changed = BKE_gpencil_stroke_minmax(gps, false, r_min, r_max);
 +                      }
 +              }
        }
 -      if (brush->cur_strength) {
 -              curvemapping_free(brush->cur_strength);
 +
 +      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]);
        }
 -      if (brush->cur_jitter) {
 -              curvemapping_free(brush->cur_jitter);
 +
 +      return changed;
 +}
 +
 +bool BKE_gpencil_stroke_select_check(
 +        const bGPDstroke *gps)
 +{
 +      const bGPDspoint *pt;
 +      int i;
 +      for (i = 0, pt = gps->points; i < gps->totpoints; i++, pt++) {
 +              if (pt->flag & GP_SPOINT_SELECT) {
 +                      return true;
 +              }
        }
- void BKE_gpencil_centroid_3D(bGPdata *gpd, float r_centroid[3])
 +      return false;
 +}
 +
 +/* compute center of bounding box */
++void BKE_gpencil_centroid_3d(bGPdata *gpd, float r_centroid[3])
 +{
 +      float min[3], max[3], tot[3];
 +
 +      BKE_gpencil_data_minmax(NULL, gpd, min, max);
  
 -      /* free */
 -      BLI_freelinkN(&ts->gp_brushes, brush);
 +      add_v3_v3v3(tot, min, max);
 +      mul_v3_v3fl(r_centroid, tot, 0.5f);
  }
  
 -/* ************************************************** */
 -/* get the active gp-palette for editing */
 -bGPDpalette *BKE_gpencil_palette_getactive(bGPdata *gpd)
 +
 +/* create bounding box values */
 +static void boundbox_gpencil(Object *ob)
  {
 -      bGPDpalette *palette;
 +      BoundBox *bb;
 +      bGPdata *gpd;
 +      float min[3], max[3];
  
 -      /* error checking */
 -      if (ELEM(NULL, gpd, gpd->palettes.first)) {
 -              return NULL;
 +      if (ob->bb == NULL) {
 +              ob->bb = MEM_callocN(sizeof(BoundBox), "GPencil boundbox");
        }
  
 -      /* loop over palettes until found (assume only one active) */
 -      for (palette = gpd->palettes.first; palette; palette = palette->next) {
 -              if (palette->flag & PL_PALETTE_ACTIVE)
 -                      return palette;
 -      }
 +      bb  = ob->bb;
 +      gpd = ob->data;
  
 -      /* no active palette found */
 -      return NULL;
 +      BKE_gpencil_data_minmax(NULL, gpd, min, max);
 +      BKE_boundbox_init_from_minmax(bb, min, max);
 +
 +      bb->flag &= ~BOUNDBOX_DIRTY;
  }
  
 -/* set the active gp-palette */
 -void BKE_gpencil_palette_setactive(bGPdata *gpd, bGPDpalette *active)
 +/* get bounding box */
 +BoundBox *BKE_gpencil_boundbox_get(Object *ob)
  {
 -      bGPDpalette *palette;
 +      bGPdata *gpd;
  
 -      /* error checking */
 -      if (ELEM(NULL, gpd, gpd->palettes.first, active)) {
 -              return;
 -      }
 +      if (ELEM(NULL, ob, ob->data))
 +              return NULL;
  
 -      /* loop over palettes deactivating all */
 -      for (palette = gpd->palettes.first; palette; palette = palette->next) {
 -              palette->flag &= ~PL_PALETTE_ACTIVE;
 +      gpd = ob->data;
 +      if ((ob->bb) && ((ob->bb->flag & BOUNDBOX_DIRTY) == 0) &&
 +          ((gpd->flag & GP_DATA_CACHE_IS_DIRTY) == 0))
 +      {
 +              return ob->bb;
        }
  
 -      /* set as active one */
 -      active->flag |= PL_PALETTE_ACTIVE;
 -      /* force color recalc */
 -      BKE_gpencil_palette_change_strokes(gpd);
 +      boundbox_gpencil(ob);
 +
 +      return ob->bb;
  }
  
 -/* delete the active gp-palette */
 -void BKE_gpencil_palette_delete(bGPdata *gpd, bGPDpalette *palette)
 +/* ************************************************** */
 +/* Apply Transforms */
 +
 +void BKE_gpencil_transform(bGPdata *gpd, float mat[4][4])
  {
 -      /* error checking */
 -      if (ELEM(NULL, gpd, palette)) {
 +      if (gpd == NULL)
                return;
 +
 +      for (bGPDlayer *gpl = gpd->layers.first; gpl; gpl = gpl->next) {
 +              /* FIXME: For now, we just skip parented layers.
 +               * Otherwise, we have to update each frame to find
 +               * the current parent position/effects.
 +               */
 +              if (gpl->parent) {
 +                      continue;
 +              }
 +
 +              for (bGPDframe *gpf = gpl->frames.first; gpf; gpf = gpf->next) {
 +                      for (bGPDstroke *gps = gpf->strokes.first; gps; gps = gps->next) {
 +                              bGPDspoint *pt;
 +                              int i;
 +
 +                              for (pt = gps->points, i = 0; i < gps->totpoints; pt++, i++) {
 +                                      mul_m4_v3(mat, &pt->x);
 +                              }
 +
 +                              /* TODO: Do we need to do this? distortion may mean we need to re-triangulate */
 +                              gps->flag |= GP_STROKE_RECALC_CACHES;
 +                              gps->tot_triangles = 0;
 +                      }
 +              }
        }
  
 -      /* free colors */
 -      free_gpencil_colors(palette);
 -      BLI_freelinkN(&gpd->palettes, palette);
 -      /* force color recalc */
 -      BKE_gpencil_palette_change_strokes(gpd);
  }
  
 -/* Set all strokes to recalc the palette color */
 -void BKE_gpencil_palette_change_strokes(bGPdata *gpd)
 -{
 -      bGPDlayer *gpl;
 -      bGPDframe *gpf;
 -      bGPDstroke *gps;
 +/* ************************************************** */
 +/* GP Object - Vertex Groups */
  
 -      for (gpl = gpd->layers.first; gpl; gpl = gpl->next) {
 -              for (gpf = gpl->frames.first; gpf; gpf = gpf->next) {
 -                      for (gps = gpf->strokes.first; gps; gps = gps->next) {
 -                              gps->flag |= GP_STROKE_RECALC_COLOR;
 +/* remove a vertex group */
 +void BKE_gpencil_vgroup_remove(Object *ob, bDeformGroup *defgroup)
 +{
 +      bGPdata *gpd = ob->data;
 +      MDeformVert *dvert = NULL;
 +      const int def_nr = BLI_findindex(&ob->defbase, defgroup);
 +
 +      /* Remove points data */
 +      if (gpd) {
 +              for (bGPDlayer *gpl = gpd->layers.first; gpl; gpl = gpl->next) {
 +                      for (bGPDframe *gpf = gpl->frames.first; gpf; gpf = gpf->next) {
 +                              for (bGPDstroke *gps = gpf->strokes.first; gps; gps = gps->next) {
 +                                      if (gps->dvert != NULL) {
 +                                              for (int i = 0; i < gps->totpoints; i++) {
 +                                                      dvert = &gps->dvert[i];
 +                                                      MDeformWeight *dw = defvert_find_index(dvert, def_nr);
 +                                                      if (dw != NULL) {
 +                                                              defvert_remove_group(dvert, dw);
 +                                                      }
 +                                              }
 +                                      }
 +                              }
                        }
                }
        }
index b105102fa6c15bfd0e0c340f796895ed117e8c7c,fab2396b05a33c0e67998af5590a5804bd944ffd..6de96aa30adfecc24c98d5df9bfa36bbb69fe8c8
@@@ -1094,69 -1044,6 +1094,69 @@@ static int object_origin_set_exec(bCont
                                lt->id.tag |= LIB_TAG_DOIT;
                                do_inverse_offset = true;
                        }
-                                               BKE_gpencil_centroid_3D(gpd, gpcenter);
 +                      else if (ob->type == OB_GPENCIL) {
 +                              bGPdata *gpd = ob->data;
 +                              float gpcenter[3];
 +                              if (gpd) {
 +                                      if (centermode == ORIGIN_TO_GEOMETRY) {
 +                                              zero_v3(gpcenter);
++                                              BKE_gpencil_centroid_3d(gpd, gpcenter);
 +                                              add_v3_v3(gpcenter, ob->obmat[3]);
 +                                      }
 +                                      if (centermode == ORIGIN_TO_CURSOR) {
 +                                              copy_v3_v3(gpcenter, cursor);
 +                                      }
 +                                      if ((centermode == ORIGIN_TO_GEOMETRY) || (centermode == ORIGIN_TO_CURSOR)) {
 +                                              bGPDspoint *pt;
 +                                              float imat[3][3], bmat[3][3];
 +                                              float offset_global[3];
 +                                              float offset_local[3];
 +                                              int i;
 +
 +                                              sub_v3_v3v3(offset_global, gpcenter, ob->obmat[3]);
 +                                              copy_m3_m4(bmat, obact->obmat);
 +                                              invert_m3_m3(imat, bmat);
 +                                              mul_m3_v3(imat, offset_global);
 +                                              mul_v3_m3v3(offset_local, imat, offset_global);
 +
 +                                              float diff_mat[4][4];
 +                                              float inverse_diff_mat[4][4];
 +
 +                                              /* recalculate all strokes (all layers are considered without evaluating lock attributtes) */
 +                                              for (bGPDlayer *gpl = gpd->layers.first; gpl; gpl = gpl->next) {
 +                                                      /* calculate difference matrix */
 +                                                      ED_gpencil_parent_location(depsgraph, obact, gpd, gpl, diff_mat);
 +                                                      /* undo matrix */
 +                                                      invert_m4_m4(inverse_diff_mat, diff_mat);
 +                                                      for (bGPDframe *gpf = gpl->frames.first; gpf; gpf = gpf->next) {
 +                                                              for (bGPDstroke *gps = gpf->strokes.first; gps; gps = gps->next) {
 +                                                                      /* skip strokes that are invalid for current view */
 +                                                                      if (ED_gpencil_stroke_can_use(C, gps) == false)
 +                                                                              continue;
 +
 +                                                                      for (i = 0, pt = gps->points; i < gps->totpoints; i++, pt++) {
 +                                                                              float mpt[3];
 +                                                                              mul_v3_m4v3(mpt, inverse_diff_mat, &pt->x);
 +                                                                              sub_v3_v3(mpt, offset_local);
 +                                                                              mul_v3_m4v3(&pt->x, diff_mat, mpt);
 +                                                                      }
 +                                                              }
 +                                                      }
 +                                              }
 +                                              DEG_id_tag_update(&gpd->id, OB_RECALC_OB | OB_RECALC_DATA);
 +
 +                                              tot_change++;
 +                                              if (centermode == ORIGIN_TO_GEOMETRY) {
 +                                                      copy_v3_v3(ob->loc, gpcenter);
 +                                              }
 +                                              ob->id.tag |= LIB_TAG_DOIT;
 +                                              do_inverse_offset = true;
 +                                      }
 +                                      else {
 +                                              BKE_report(op->reports, RPT_WARNING, "Grease Pencil Object does not support this set origin option");
 +                                      }
 +                              }
 +                      }
  
                        /* offset other selected objects */
                        if (do_inverse_offset && (centermode != GEOMETRY_TO_ORIGIN)) {
index 5cc98e52da2b50efc846c463c090e5d18cfba54d,2dc8bf66225d1c10780f5dc9b18c4dc5163673e9..579dbad706cf20d8861aa174090e567711510481
@@@ -768,26 -749,20 +768,26 @@@ static void recalcData_objects(TransInf
                                applyProject(t);
                        }
  
 -                      DAG_id_tag_update(t->obedit->data, 0);  /* sets recalc flags */
 +                      FOREACH_TRANS_DATA_CONTAINER (t, tc) {
 +                              Curve *cu = tc->obedit->data;
 +                              ListBase *nurbs = BKE_curve_editNurbs_get(cu);
 +                              Nurb *nu = nurbs->first;
 +
 +                              DEG_id_tag_update(tc->obedit->data, 0);  /* sets recalc flags */
  
 -                      if (t->state == TRANS_CANCEL) {
 -                              while (nu) {
 -                                      BKE_nurb_handles_calc(nu); /* Cant do testhandlesNurb here, it messes up the h1 and h2 flags */
 -                                      nu = nu->next;
 +                              if (t->state == TRANS_CANCEL) {
 +                                      while (nu) {
 +                                              BKE_nurb_handles_calc(nu); /* Cant do testhandlesNurb here, it messes up the h1 and h2 flags */
 +                                              nu = nu->next;
 +                                      }
                                }
 -                      }
 -                      else {
 -                              /* Normal updating */
 -                              while (nu) {
 -                                      BKE_nurb_test_2d(nu);
 -                                      BKE_nurb_handles_calc(nu);
 -                                      nu = nu->next;
 +                              else {
 +                                      /* Normal updating */
 +                                      while (nu) {
-                                               BKE_nurb_test2D(nu);
++                                              BKE_nurb_test_2d(nu);
 +                                              BKE_nurb_handles_calc(nu);
 +                                              nu = nu->next;
 +                                      }
                                }
                        }
                }