Commit: ec52b7dbb6ef2c73b05b615729ac561210816305
Author: Rohan Rathi
Date:   Sat Mar 31 19:43:39 2018 +0530
Branches: soc-2017-normal-tools
https://developer.blender.org/rBec52b7dbb6ef2c73b05b615729ac561210816305

Merge branch 'master' into soc-2017-normal-tools

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



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

diff --cc source/blender/editors/mesh/editmesh_tools.c
index e70fd431a6a,2d7ddc7d9c1..3a900cfdcae
--- a/source/blender/editors/mesh/editmesh_tools.c
+++ b/source/blender/editors/mesh/editmesh_tools.c
@@@ -5992,1368 -6297,6 +6303,1370 @@@ void MESH_OT_mark_freestyle_face(wmOper
        RNA_def_property_flag(prop, PROP_SKIP_SAVE);
  }
  
- #endif
+ /** \} */
+ 
+ #endif  /* WITH_FREESTYLE */
 +
 +/********************** Loop normals editing tools modal map. 
**********************/
 +
 +/* NOTE: these defines are saved in keymap files, do not change values but 
just add new ones */
 +/* NOTE: We could add more here, like e.g. a switch between local or global 
coordinates of target,
 + *       use numinput to type in explicit vector values... */
 +enum {
 +      /* Generic commands. */
 +      EDBM_CLNOR_MODAL_CANCEL                   = 1,
 +      EDBM_CLNOR_MODAL_CONFIRM                  = 2,
 +
 +      /* Point To operator. */
 +      EDBM_CLNOR_MODAL_POINTTO_RESET            = 101,
 +      EDBM_CLNOR_MODAL_POINTTO_INVERT           = 102,
 +      EDBM_CLNOR_MODAL_POINTTO_SPHERIZE         = 103,
 +      EDBM_CLNOR_MODAL_POINTTO_ALIGN            = 104,
 +
 +      EDBM_CLNOR_MODAL_POINTTO_USE_MOUSE        = 110,
 +      EDBM_CLNOR_MODAL_POINTTO_USE_PIVOT        = 111,
 +      EDBM_CLNOR_MODAL_POINTTO_USE_OBJECT       = 112,
 +      EDBM_CLNOR_MODAL_POINTTO_SET_USE_3DCURSOR = 113,
 +      EDBM_CLNOR_MODAL_POINTTO_SET_USE_SELECTED = 114,
 +};
 +
 +/* called in transform_ops.c, on each regeneration of keymaps */
 +wmKeyMap *point_normals_modal_keymap(wmKeyConfig *keyconf)
 +{
 +      static const EnumPropertyItem modal_items[] = {
 +              {EDBM_CLNOR_MODAL_CANCEL, "CANCEL", 0, "Cancel", ""},
 +              {EDBM_CLNOR_MODAL_CONFIRM, "CONFIRM", 0, "Confirm", ""},
 +
 +              /* Point To operator. */
 +              {EDBM_CLNOR_MODAL_POINTTO_RESET, "RESET", 0, "Reset", "Reset 
normals to initial ones"},
 +              {EDBM_CLNOR_MODAL_POINTTO_INVERT, "INVERT", 0, "Invert", 
"Toggle inversion of affected normals"},
 +              {EDBM_CLNOR_MODAL_POINTTO_SPHERIZE, "SPHERIZE", 0, "Spherize", 
"Interpolate between new and original normals"},
 +              {EDBM_CLNOR_MODAL_POINTTO_ALIGN, "ALIGN", 0, "Align", "Make all 
affected normals parallel"},
 +
 +              {EDBM_CLNOR_MODAL_POINTTO_USE_MOUSE, "USE_MOUSE", 0, "Use 
Mouse", "Follow mouse cursor position"},
 +              {EDBM_CLNOR_MODAL_POINTTO_USE_PIVOT, "USE_PIVOT", 0, "Use 
Pivot",
 +               "Use current rotation/scaling pivot point coordinates"},
 +              {EDBM_CLNOR_MODAL_POINTTO_USE_OBJECT, "USE_OBJECT", 0, "Use 
Object", "Use current edited object's location"},
 +              {EDBM_CLNOR_MODAL_POINTTO_SET_USE_3DCURSOR, "SET_USE_3DCURSOR", 
0, "Set and Use 3D Cursor",
 +               "Set new 3D cursor position and use it"},
 +              {EDBM_CLNOR_MODAL_POINTTO_SET_USE_SELECTED, "SET_USE_SELECTED", 
0, "Select and Use Mesh Item",
 +               "Select new active mesh element and use its location"},
 +              {0, NULL, 0, NULL, NULL}
 +      };
 +      static const char *keymap_name = "Custom Normals Modal Map";
 +
 +      wmKeyMap *keymap = WM_modalkeymap_get(keyconf, keymap_name);
 +
 +      /* We only need to add map once */
 +      if (keymap && keymap->modal_items)
 +              return NULL;
 +
 +      keymap = WM_modalkeymap_add(keyconf, keymap_name, modal_items);
 +
 +      /* Generic items for modal map. */
 +      WM_modalkeymap_add_item(keymap, ESCKEY,     KM_PRESS, KM_ANY,     0, 
EDBM_CLNOR_MODAL_CANCEL);
 +      WM_modalkeymap_add_item(keymap, RIGHTMOUSE, KM_PRESS, KM_NOTHING, 0, 
EDBM_CLNOR_MODAL_CANCEL);
 +
 +      WM_modalkeymap_add_item(keymap, RETKEY,     KM_PRESS, KM_ANY,     0, 
EDBM_CLNOR_MODAL_CONFIRM);
 +      WM_modalkeymap_add_item(keymap, PADENTER,   KM_PRESS, KM_ANY,     0, 
EDBM_CLNOR_MODAL_CONFIRM);
 +      WM_modalkeymap_add_item(keymap, LEFTMOUSE,  KM_PRESS, KM_NOTHING, 0, 
EDBM_CLNOR_MODAL_CONFIRM);
 +
 +      /* Point To items for modal map */
 +      WM_modalkeymap_add_item(keymap, RKEY,       KM_PRESS, KM_NOTHING, 0, 
EDBM_CLNOR_MODAL_POINTTO_RESET);
 +      WM_modalkeymap_add_item(keymap, IKEY,       KM_PRESS, KM_NOTHING, 0, 
EDBM_CLNOR_MODAL_POINTTO_INVERT);
 +      WM_modalkeymap_add_item(keymap, SKEY,       KM_PRESS, KM_NOTHING, 0, 
EDBM_CLNOR_MODAL_POINTTO_SPHERIZE);
 +      WM_modalkeymap_add_item(keymap, AKEY,       KM_PRESS, KM_NOTHING, 0, 
EDBM_CLNOR_MODAL_POINTTO_ALIGN);
 +
 +      WM_modalkeymap_add_item(keymap, MKEY,       KM_PRESS, KM_NOTHING, 0, 
EDBM_CLNOR_MODAL_POINTTO_USE_MOUSE);
 +      WM_modalkeymap_add_item(keymap, LKEY,       KM_PRESS, KM_NOTHING, 0, 
EDBM_CLNOR_MODAL_POINTTO_USE_PIVOT);
 +      WM_modalkeymap_add_item(keymap, OKEY,       KM_PRESS, KM_NOTHING, 0, 
EDBM_CLNOR_MODAL_POINTTO_USE_OBJECT);
 +
 +      WM_modalkeymap_add_item(keymap, LEFTMOUSE,  KM_CLICK, KM_CTRL,    0, 
EDBM_CLNOR_MODAL_POINTTO_SET_USE_3DCURSOR);
 +      WM_modalkeymap_add_item(keymap, RIGHTMOUSE, KM_CLICK, KM_CTRL,    0, 
EDBM_CLNOR_MODAL_POINTTO_SET_USE_SELECTED);
 +
 +      WM_modalkeymap_assign(keymap, "MESH_OT_point_normals");
 +
 +      return keymap;
 +}
 +
 +#define CLNORS_VALID_VEC_LEN (1e-4f)
 +
 +/********************** 'Point to' Loop Normals **********************/
 +
 +enum {
 +      EDBM_CLNOR_POINTTO_MODE_COORDINATES = 1,
 +      EDBM_CLNOR_POINTTO_MODE_MOUSE = 2,
 +};
 +
 +static EnumPropertyItem clnors_pointto_mode_items[] = {
 +      {EDBM_CLNOR_POINTTO_MODE_COORDINATES, "COORDINATES", 0, "Coordinates",
 +                                            "Use static coordinates (defined 
by various means)"},
 +      {EDBM_CLNOR_POINTTO_MODE_MOUSE, "MOUSE", 0, "Mouse", "Follow mouse 
cursor"},
 +      {0, NULL, 0, NULL, NULL}
 +};
 +
 +/* Initialize loop normal data */
 +static int point_normals_init(bContext *C, wmOperator *op, const wmEvent 
*UNUSED(event))
 +{
 +      Object *obedit = CTX_data_edit_object(C);
 +      BMEditMesh *em = BKE_editmesh_from_object(obedit);
 +      BMesh *bm = em->bm;
 +
 +      BKE_editmesh_lnorspace_update(em);
 +      BMLoopNorEditDataArray *lnors_ed_arr = 
BM_loop_normal_editdata_array_init(bm);
 +
 +      op->customdata = lnors_ed_arr;
 +
 +      return lnors_ed_arr->totloop;
 +}
 +
 +static void point_normals_free(bContext *C, wmOperator *op)
 +{
 +      BMLoopNorEditDataArray *lnors_ed_arr = op->customdata;
 +      BM_loop_normal_editdata_array_free(lnors_ed_arr);
 +      op->customdata = NULL;
 +      ED_area_headerprint(CTX_wm_area(C), NULL);
 +}
 +
 +static void point_normals_update_header(bContext *C, wmOperator *op)
 +{
 +      char header[UI_MAX_DRAW_STR];
 +      char buf[UI_MAX_DRAW_STR];
 +
 +      char *p = buf;
 +      int available_len = sizeof(buf);
 +
 +#define WM_MODALKEY(_id) \
 +      WM_modalkeymap_operator_items_to_string_buf(op->type, (_id), true, 
UI_MAX_SHORTCUT_STR, &available_len, &p)
 +
 +      BLI_snprintf(header, sizeof(header), IFACE_("%s: confirm, %s: cancel, "
 +                                                  "%s: point to mouse (%s), 
%s: point to Pivot, "
 +                                                  "%s: point to object 
origin, %s: reset normals, "
 +                                                  "%s: set & point to 3D 
cursor, %s: select & point to mesh item, "
 +                                                  "%s: invert normals (%s), 
%s: spherize (%s), %s: align (%s)"),
 +                   WM_MODALKEY(EDBM_CLNOR_MODAL_CONFIRM), 
WM_MODALKEY(EDBM_CLNOR_MODAL_CANCEL),
 +                   WM_MODALKEY(EDBM_CLNOR_MODAL_POINTTO_USE_MOUSE),
 +                   WM_bool_as_string(RNA_enum_get(op->ptr, "mode") == 
EDBM_CLNOR_POINTTO_MODE_MOUSE),
 +                   WM_MODALKEY(EDBM_CLNOR_MODAL_POINTTO_USE_PIVOT), 
WM_MODALKEY(EDBM_CLNOR_MODAL_POINTTO_USE_OBJECT),
 +                   WM_MODALKEY(EDBM_CLNOR_MODAL_POINTTO_RESET), 
WM_MODALKEY(EDBM_CLNOR_MODAL_POINTTO_SET_USE_3DCURSOR),
 +                   WM_MODALKEY(EDBM_CLNOR_MODAL_POINTTO_SET_USE_SELECTED),
 +                   WM_MODALKEY(EDBM_CLNOR_MODAL_POINTTO_INVERT), 
WM_bool_as_string(RNA_boolean_get(op->ptr, "invert")),
 +                   WM_MODALKEY(EDBM_CLNOR_MODAL_POINTTO_SPHERIZE), 
WM_bool_as_string(RNA_boolean_get(op->ptr, "spherize")),
 +                   WM_MODALKEY(EDBM_CLNOR_MODAL_POINTTO_ALIGN), 
WM_bool_as_string(RNA_boolean_get(op->ptr, "align")));
 +
 +#undef WM_MODALKEY
 +
 +      ED_area_headerprint(CTX_wm_area(C), header);
 +}
 +
 +/* TODO move that to generic function in BMesh? */
 +static void bmesh_selected_verts_center_calc(BMesh *bm, float *r_center)
 +{
 +      BMVert *v;
 +      BMIter viter;
 +      int i = 0;
 +
 +      zero_v3(r_center);
 +      BM_ITER_MESH(v, &viter, bm, BM_VERTS_OF_MESH) {
 +              if (BM_elem_flag_test(v, BM_ELEM_SELECT)) {
 +                      add_v3_v3(r_center, v->co);
 +                      i++;
 +              }
 +      }
 +      mul_v3_fl(r_center, 1.0f / (float)i);
 +}
 +
 +static void point_normals_apply(bContext *C, wmOperator *op, float target[3], 
const bool do_reset)
 +{
 +      Object *obedit = CTX_data_edit_object(C);
 +      BMesh *bm = BKE_editmesh_from_object(obedit)->bm;
 +      BMLoopNorEditDataArray *lnors_ed_arr = op->customdata;
 +
 +      const bool do_invert = RNA_boolean_get(op->ptr, "invert");
 +      const bool do_spherize = RNA_boolean_get(op->ptr, "spherize");
 +      const bool do_align = RNA_boolean_get(op->ptr, "align");
 +      float center[3];
 +
 +      if (do_align && !do_reset) {
 +              bmesh_selected_verts_center_calc(bm, center);
 +      }
 +
 +      sub_v3_v3(target, obedit->loc);  /* Move target to local coordinates. */
 +
 +      BMLoopNorEditData *lnor_ed = lnors_ed_arr->lnor_editdata;
 +      for (int i = 0; i < lnors_ed_arr->totloop; i++, lnor_ed++) {
 +              if (do_reset) {
 +                      copy_v3_v3(lnor_ed->nloc, lnor_ed->niloc);
 +              }
 +              else if (do_spherize) {
 +                      /* Note that this is *not* real spherical 
interpolation. Probably good enough in this case though? */
 +                      const float strength = RNA_float_get(op->ptr, 
"spherize_strength");
 +                      float spherized_normal[3];
 +
 +                      sub_v3_v3v3(spherized_normal, target, lnor_ed->loc);
 +                      normalize_v3(spherized_normal);  /* otherwise, 
multiplication by strength is meaningless... */
 +                      mul_v3_fl(spherized_normal, strength);
 +                      mul_v3_v3fl(lnor_ed->nloc, lnor_ed->niloc, 1.0f - 
strength);
 +                      add_v3_v3(lnor_ed->nloc, spherized_normal);
 +              }
 +              else if (do_align) {
 +                      sub_v3_v3v3(lnor_ed->nloc, target, center);
 +              }
 +              else {
 +                      sub_v3_v3v3(lnor_ed->nloc, target, lnor_ed->loc);
 +              }
 +
 +              if (do_invert && !do_reset) {
 +                      negate_v3(lnor_ed->nloc);
 +              }
 +              if (normalize_v3(lnor_ed->nloc) >= CLNORS_VALID_VEC_LEN) {
 +                      BKE_lnor_space_custom_normal_to_data(
 +                                  
bm->lnor_spacearr->lspacearr[lnor_ed->loop_index], lnor_ed->nloc, 
lnor_ed->clnors_data);
 +              }
 +      }
 +}
 +
 +static int edbm_point_normals_modal(bContext *C, wmOperator *op, const 
wmEvent *event)
 +{
 

@@ Diff output truncated at 10240 characters. @@

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
https://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to