[Bf-blender-cvs] [e3c8e879a96] soc-2021-knife-tools: Merge branch 'master' into soc-2021-knife-tools

Cian Jinks noreply at git.blender.org
Tue Aug 10 16:34:08 CEST 2021


Commit: e3c8e879a96b547b2a805e460c63446bed224bde
Author: Cian Jinks
Date:   Tue Aug 10 15:33:57 2021 +0100
Branches: soc-2021-knife-tools
https://developer.blender.org/rBe3c8e879a96b547b2a805e460c63446bed224bde

Merge branch 'master' into soc-2021-knife-tools

===================================================================



===================================================================

diff --cc source/blender/editors/mesh/editmesh_knife.c
index 37188af714b,3e3593d18fd..e710bc14c65
--- a/source/blender/editors/mesh/editmesh_knife.c
+++ b/source/blender/editors/mesh/editmesh_knife.c
@@@ -3941,94 -2629,28 +3941,95 @@@ static void knife_init_colors(KnifeColo
    colors->point_a[3] = 102;
  }
  
 +static void knife_switch_object(KnifeTool_OpData *kcd, Object *ob, int base_index)
 +{
 +  ED_view3d_viewcontext_init_object(&kcd->vc, ob);
 +  kcd->ob = kcd->vc.obedit;
 +  kcd->em = kcd->vc.em;
 +  invert_m4_m4_safe_ortho(kcd->ob_imat, kcd->ob->obmat);
 +  knife_pos_data_clear(&kcd->prev);
 +  /* Update base index. */
 +  kcd->base_index = base_index;
 +}
 +
 +/* Swap the current object based on which edge is nearest the cursor. */
 +static void knife_mouse_move(KnifeTool_OpData *kcd)
 +{
 +  Object *ob;
 +  BMFace *f;
 +  uint base_index;
 +  float dist = KMAXDIST;
 +
 +  float origin[3];
 +  float origin_ofs[3];
 +  float ray[3], ray_normal[3];
 +
 +  knife_input_ray_segment_world(kcd, kcd->curr.mval, 1.0f, origin, origin_ofs);
 +  sub_v3_v3v3(ray, origin_ofs, origin);
 +  normalize_v3_v3(ray_normal, ray);
 +  f = knife_bvh_raycast(kcd, origin, ray_normal, 0.0f, NULL, NULL, NULL, false, &base_index);
 +
 +  if (f && kcd->only_select && BM_elem_flag_test(f, BM_ELEM_SELECT) == 0) {
 +    f = NULL;
 +  }
 +
 +  kcd->curr.is_space = !f;
 +
 +  if (!f) {
 +    if (kcd->is_interactive) {
 +      ViewContext vc = kcd->vc;
 +      vc.mval[0] = (int)kcd->curr.mval[0];
 +      vc.mval[1] = (int)kcd->curr.mval[1];
 +      f = EDBM_face_find_nearest_ex(
 +          &vc, &dist, NULL, false, false, false, NULL, kcd->bases, kcd->bases_len, &base_index);
 +    }
 +  }
 +  if (f) {
 +    ob = kcd->bases[base_index]->object;
 +    if (kcd->ob != ob) {
 +      knife_switch_object(kcd, ob, base_index);
 +    }
 +  }
 +}
 +
- /* Called when modal loop selection gets set up... */
+ /* called when modal loop selection gets set up... */
 -static void knifetool_init(ViewContext *vc,
 +static void knifetool_init(bContext *C,
++                           ViewContext *vc,
                             KnifeTool_OpData *kcd,
                             const bool only_select,
                             const bool cut_through,
 +                           const float angle_snapping_increment,
                             const bool is_interactive)
  {
-   Scene *scene = CTX_data_scene(C);
-   Object *obedit = CTX_data_edit_object(C);
+   kcd->vc = *vc;
+ 
+   Scene *scene = vc->scene;
+   Object *obedit = vc->obedit;
  
 -  /* assign the drawing handle for drawing preview line... */
 +  /* Assign the drawing handle for drawing preview line... */
    kcd->scene = scene;
    kcd->ob = obedit;
-   kcd->region = CTX_wm_region(C);
+   kcd->region = vc->region;
  
    invert_m4_m4_safe_ortho(kcd->ob_imat, kcd->ob->obmat);
  
-   em_setup_viewcontext(C, &kcd->vc);
- 
    kcd->em = BKE_editmesh_from_object(kcd->ob);
  
 -  /* cut all the way through the mesh if use_occlude_geometry button not pushed */
 +  kcd->bases = BKE_view_layer_array_from_bases_in_edit_mode(
 +      CTX_data_view_layer(C), CTX_wm_view3d(C), &kcd->bases_len);
 +
 +  Object *ob;
 +  kcd->cagecos = MEM_callocN(sizeof(*kcd->cagecos) * kcd->bases_len, "knife cagecos");
 +  for (int i = 0; i < kcd->bases_len; i++) {
 +    ob = kcd->bases[i]->object;
 +    knifetool_init_cagecos(kcd, ob, i);
 +    if (ob == obedit) {
 +      kcd->base_index = i;
 +    }
 +  }
 +  knife_bvh_init(kcd);
 +
 +  /* Cut all the way through the mesh if use_occlude_geometry button not pushed. */
    kcd->is_interactive = is_interactive;
    kcd->cut_through = cut_through;
    kcd->only_select = only_select;
@@@ -4071,29 -2691,19 +4072,29 @@@
  
      knife_init_colors(&kcd->colors);
    }
 +
 +  kcd->axis_string[0] = ' ';
 +  kcd->axis_string[1] = '\0';
 +
 +  /* Initialise num input handling for angle snapping. */
 +  initNumInput(&kcd->num);
 +  kcd->num.idx_max = 0;
 +  kcd->num.val_flag[0] |= NUM_NO_NEGATIVE;
 +  kcd->num.unit_sys = scene->unit.system;
 +  kcd->num.unit_type[0] = B_UNIT_NONE;
  }
  
- /* Called when modal loop selection is done... */
- static void knifetool_exit_ex(bContext *C, KnifeTool_OpData *kcd)
+ /* called when modal loop selection is done... */
+ static void knifetool_exit_ex(KnifeTool_OpData *kcd)
  {
    if (!kcd) {
      return;
    }
  
    if (kcd->is_interactive) {
-     WM_cursor_modal_restore(CTX_wm_window(C));
+     WM_cursor_modal_restore(kcd->vc.win);
  
 -    /* deactivate the extra drawing stuff in 3D-View */
 +    /* Deactivate the extra drawing stuff in 3D-View. */
      ED_region_draw_cb_exit(kcd->region->type, kcd->draw_handle);
    }
  
@@@ -4131,17 -2732,13 +4132,17 @@@
      MEM_freeN(kcd->linehits);
    }
  
 -  /* destroy kcd itself */
 +  /* Free object bases. */
 +  MEM_freeN(kcd->bases);
 +
 +  /* Destroy kcd itself. */
    MEM_freeN(kcd);
  }
 +
- static void knifetool_exit(bContext *C, wmOperator *op)
+ static void knifetool_exit(wmOperator *op)
  {
    KnifeTool_OpData *kcd = op->customdata;
-   knifetool_exit_ex(C, kcd);
+   knifetool_exit_ex(kcd);
    op->customdata = NULL;
  }
  
@@@ -4647,38 -3065,29 +4648,41 @@@ static int knifetool_invoke(bContext *C
    const bool only_select = RNA_boolean_get(op->ptr, "only_selected");
    const bool cut_through = !RNA_boolean_get(op->ptr, "use_occlude_geometry");
    const bool wait_for_input = RNA_boolean_get(op->ptr, "wait_for_input");
 +  const float angle_snapping_increment = RAD2DEGF(
 +      RNA_float_get(op->ptr, "angle_snapping_increment"));
  
+   ViewContext vc;
    KnifeTool_OpData *kcd;
  
-   /* Alloc new customdata. */
-   kcd = op->customdata = MEM_callocN(sizeof(KnifeTool_OpData), __func__);
- 
-   knifetool_init(C, kcd, only_select, cut_through, angle_snapping_increment, true);
+   em_setup_viewcontext(C, &vc);
  
    if (only_select) {
 -    Object *obedit = CTX_data_edit_object(C);
 -    BMEditMesh *em = BKE_editmesh_from_object(obedit);
 -    if (em->bm->totfacesel == 0) {
 +    Object *obedit;
 +    bool faces_selected = false;
 +
 +    for (int b = 0; b < kcd->bases_len; b++) {
 +      obedit = kcd->bases[b]->object;
 +      knife_switch_object(kcd, obedit, b);
 +      if (kcd->em->bm->totfacesel != 0) {
 +        faces_selected = true;
 +      }
 +    }
 +
 +    if (!faces_selected) {
        BKE_report(op->reports, RPT_ERROR, "Selected faces required");
 +      knifetool_cancel(C, op);
        return OPERATOR_CANCELLED;
      }
    }
  
+   /* alloc new customdata */
+   kcd = op->customdata = MEM_callocN(sizeof(KnifeTool_OpData), __func__);
+ 
 -  knifetool_init(&vc, kcd, only_select, cut_through, true);
++  knifetool_init(C, &vc, kcd, only_select, cut_through, angle_snapping_increment, true);
+ 
    op->flag |= OP_IS_MODAL_CURSOR_REGION;
  
 -  /* add a modal handler for this operator - handles loop selection */
 +  /* Add a modal handler for this operator - handles loop selection. */
    WM_cursor_modal_set(CTX_wm_window(C), WM_CURSOR_KNIFE);
    WM_event_add_modal_handler(C, op);
  
@@@ -4769,7 -3168,7 +4773,7 @@@ static bool edbm_mesh_knife_point_isect
  /**
   * \param use_tag: When set, tag all faces inside the polylines.
   */
- void EDBM_mesh_knife(bContext *C, LinkNode *polys, bool use_tag, bool cut_through)
 -void EDBM_mesh_knife(ViewContext *vc, LinkNode *polys, bool use_tag, bool cut_through)
++void EDBM_mesh_knife(bContext *C, ViewContext *vc, LinkNode *polys, bool use_tag, bool cut_through)
  {
    KnifeTool_OpData *kcd;
  
@@@ -4781,7 -3179,7 +4785,7 @@@
  
      kcd = MEM_callocN(sizeof(KnifeTool_OpData), __func__);
  
-     knifetool_init(C, kcd, only_select, cut_through, angle_snapping_increment, is_interactive);
 -    knifetool_init(vc, kcd, only_select, cut_through, is_interactive);
++    knifetool_init(C, vc, kcd, only_select, cut_through, angle_snapping_increment, is_interactive);
  
      kcd->ignore_edge_snapping = true;
      kcd->ignore_vert_snapping = true;
diff --cc source/blender/editors/mesh/editmesh_knife_project.c
index 09b17acf56d,16661897e87..450f1d5ebee
--- a/source/blender/editors/mesh/editmesh_knife_project.c
+++ b/source/blender/editors/mesh/editmesh_knife_project.c
@@@ -137,8 -137,27 +137,27 @@@ static int knifeproject_exec(bContext *
    }
    CTX_DATA_END;
  
-   if (polys) {
-     EDBM_mesh_knife(C, polys, true, cut_through);
+   if (polys == NULL) {
+     BKE_report(op->reports,
+                RPT_ERROR,
+                "No other selected objects have wire or boundary edges to use for projection");
+     return OPERATOR_CANCELLED;
+   }
+ 
+   ViewContext vc;
+   em_setup_viewcontext(C, &vc);
+ 
+   /* TODO: Ideally meshes would occlude each other, currently they don't
+    * since each knife-project runs as a separate operation. */
+   uint objects_len;
+   Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
+       vc.view_layer, vc.v3d, &objects_len);
+   for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
+     Object *obedit = objects[ob_index];
+     ED_view3d_viewcontext_init_object(&vc, obedit);
+     BMEditMesh *em = BKE_editmesh_from_object(obedit);
+ 
 -    EDBM_mesh_knife(&vc, polys, true, cut_through);
++    EDBM_mesh_knife(C, &vc, polys, true, cut_through);
  
      /* select only tagged faces */
      BM_mesh_elem_hflag_disable_all(em->bm, BM_VERT | BM_EDGE | BM_FACE, BM_ELEM_SELECT, false);
diff --cc source/blender/editors/mesh/mesh_intern.h
index f25317e8e85,03c99e40d1e..abff3c70e67
--- a/source/blender/editors/mesh/mesh_intern.h
+++ b/source/blender/editors/mesh/mesh_intern.h
@@@ -150,7 -150,10 +150,11 @@@ void MESH_OT_face_split_by_edges(struc
  /* *** editmesh_knife.c *** */
  void MESH_OT_knife_tool(struct wmOperatorType *ot);
  void MESH_OT_knife_project(struct wmOperatorType *ot);
- void EDBM_mesh_knife(struct bContext *C, struct LinkNode *polys, bool use_tag, bool cut_through);
 -void EDBM_mesh_knife(struct ViewContext *vc,
++void EDBM_mesh_knife(struct bContext *C,
++                     struct ViewContext *vc,
+                      struct LinkNode *polys,
+                      bool use_tag,
+                      bool cut_through);
  
  struct wmKeyMap *knifetool_modal_keymap(struct wmKeyConfig *

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list