Editor Transform: New Snap Option Middle

Part of T66420

Reviewers: campbellbarton, brecht

Reviewed By: campbellbarton

Differential Revision: https://developer.blender.org/D5532
This commit is contained in:
Germano Cavalcante 2019-08-20 15:07:48 -03:00
parent 1876e18b1b
commit 58341242bf
Notes: blender-bot 2023-02-14 09:34:18 +01:00
Referenced by issue #66420, Snap Options: Midpoints and Perpendicular
8 changed files with 76 additions and 31 deletions

View File

@ -5290,6 +5290,11 @@
d="m 408.48148,452.0625 c -1.71014,0.0728 -3.32227,1.4838 -3.32227,3.9375 0,2.05278 1.07076,4.01178 2.38672,5.71289 1.31595,1.70111 2.90024,3.15481 4.03125,4.16016 0.0914,0.0816 0.20954,0.12673 0.33203,0.12695 h 0.5 c 0.12249,-2.2e-4 0.24064,-0.0454 0.33203,-0.12695 1.13101,-1.00535 2.7153,-2.45905 4.03125,-4.16016 1.31596,-1.70111 2.38672,-3.66011 2.38672,-5.71289 0,-2.4537 -1.61213,-3.86473 -3.32227,-3.9375 -1.52139,-0.0647 -3.0532,0.927 -3.67773,2.69727 -0.62453,-1.77027 -2.15634,-2.76201 -3.67773,-2.69727 z"
style="color:#000000;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:medium;line-height:normal;font-family:sans-serif;font-variant-ligatures:normal;font-variant-position:normal;font-variant-caps:normal;font-variant-numeric:normal;font-variant-alternates:normal;font-feature-settings:normal;text-indent:0;text-align:start;text-decoration:none;text-decoration-line:none;text-decoration-style:solid;text-decoration-color:#000000;letter-spacing:normal;word-spacing:normal;text-transform:none;writing-mode:lr-tb;direction:ltr;text-orientation:mixed;dominant-baseline:auto;baseline-shift:baseline;text-anchor:start;white-space:normal;shape-padding:0;clip-rule:nonzero;display:inline;overflow:visible;visibility:visible;opacity:1;isolation:auto;mix-blend-mode:normal;color-interpolation:sRGB;color-interpolation-filters:linearRGB;solid-color:#000000;solid-opacity:1;vector-effect:none;fill:#ffffff;fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:1;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;marker:none;paint-order:fill markers stroke;color-rendering:auto;image-rendering:auto;shape-rendering:auto;text-rendering:auto;enable-background:accumulate"
sodipodi:nodetypes="csccccccsccc" />
<path inkscape:connector-curvature="0" id="path4106" d="m 408.48148,452.0625 c -1.71014,0.0728 -3.32227,1.4838 -3.32227,3.9375 0,2.05278 1.07076,4.01178 2.38672,5.71289 1.31595,1.70111 2.90024,3.15481 4.03125,4.16016 0.0914,0.0816 0.20954,0.12673 0.33203,0.12695 h 0.5 c 0.12249,-2.2e-4 0.24064,-0.0454 0.33203,-0.12695 1.13101,-1.00535 2.7153,-2.45905 4.03125,-4.16016 1.31596,-1.70111 2.38672,-3.66011 2.38672,-5.71289 0,-2.4537 -1.61213,-3.86473 -3.32227,-3.9375 -1.52139,-0.0647 -3.0532,0.927 -3.67773,2.69727 -0.62453,-1.77027 -2.15634,-2.76201 -3.67773,-2.69727 z" style="color:#000000;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:medium;line-height:normal;font-family:sans-serif;font-variant-ligatures:normal;font-variant-position:normal;font-variant-caps:normal;font-variant-numeric:normal;font-variant-alternates:normal;font-feature-settings:normal;text-indent:0;text-align:start;text-decoration:none;text-decoration-line:none;text-decoration-style:solid;text-decoration-color:#000000;letter-spacing:normal;word-spacing:normal;text-transform:none;writing-mode:lr-tb;direction:ltr;text-orientation:mixed;dominant-baseline:auto;baseline-shift:baseline;text-anchor:start;white-space:normal;shape-padding:0;clip-rule:nonzero;display:inline;overflow:visible;visibility:visible;opacity:1;isolation:auto;mix-blend-mode:normal;color-interpolation:sRGB;color-interpolation-filters:linearRGB;solid-color:#000000;solid-opacity:1;vector-effect:none;fill:#ffffff;fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:1;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;marker:none;paint-order:fill markers stroke;color-rendering:auto;image-rendering:auto;shape-rendering:auto;text-rendering:auto;enable-background:accumulate" sodipodi:nodetypes="csccccccsccc" />
<g transform="translate(-105.008,-0.00105)" style="display:inline;fill:#ffffff;enable-background:new" inkscape:export-ydpi="96" inkscape:export-xdpi="96" inkscape:export-filename="C:\Users\Andrzej Ambroż\Desktop\mtrx.png" id="g22126-1">
<path style="color:#000000;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:medium;line-height:normal;font-family:sans-serif;font-variant-ligatures:normal;font-variant-position:normal;font-variant-caps:normal;font-variant-numeric:normal;font-variant-alternates:normal;font-feature-settings:normal;text-indent:0;text-align:start;text-decoration:none;text-decoration-line:none;text-decoration-style:solid;text-decoration-color:#000000;letter-spacing:normal;word-spacing:normal;text-transform:none;writing-mode:lr-tb;direction:ltr;text-orientation:mixed;dominant-baseline:auto;baseline-shift:baseline;text-anchor:start;white-space:normal;shape-padding:0;clip-rule:nonzero;display:inline;overflow:visible;visibility:visible;opacity:0.6;isolation:auto;mix-blend-mode:normal;color-interpolation:sRGB;color-interpolation-filters:linearRGB;solid-color:#000000;solid-opacity:1;vector-effect:none;fill:#ffffff;fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:1;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;marker:none;color-rendering:auto;image-rendering:auto;shape-rendering:auto;text-rendering:auto;enable-background:new" d="m 178.5,158 c -0.1326,3e-5 -0.25976,0.0527 -0.35352,0.14649 l -1.99219,1.99218 c -0.11574,0.11126 -0.14648,0.23321 -0.14648,0.35352 v 1.90729 h 1 l 0.008,-1.70825 L 178.70703,159 H 187 v 8.29297 l -2.70703,2.70508 -7.28522,-0.003 v -1.55553 l -1,-10e-4 v 2.06253 c 0.008,0.28778 0.21557,0.51105 0.50025,0.5 h 7.992 c 0.1326,-3e-5 0.25975,-0.0527 0.35351,-0.14648 l 3,-3 c 0.0938,-0.0938 0.14646,-0.22092 0.14649,-0.35352 v -9 c -3e-5,-0.27613 -0.22387,-0.49997 -0.5,-0.5 z" id="path22118-4" inkscape:connector-curvature="0" sodipodi:nodetypes="cccsccccccccccccccccccc" />
<path style="color:#000000;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:medium;line-height:normal;font-family:sans-serif;font-variant-ligatures:normal;font-variant-position:normal;font-variant-caps:normal;font-variant-numeric:normal;font-variant-alternates:normal;font-feature-settings:normal;text-indent:0;text-align:start;text-decoration:none;text-decoration-line:none;text-decoration-style:solid;text-decoration-color:#000000;letter-spacing:normal;word-spacing:normal;text-transform:none;writing-mode:lr-tb;direction:ltr;text-orientation:mixed;dominant-baseline:auto;baseline-shift:baseline;text-anchor:start;white-space:normal;shape-padding:0;clip-rule:nonzero;display:inline;overflow:visible;visibility:visible;opacity:1;isolation:auto;mix-blend-mode:normal;color-interpolation:sRGB;color-interpolation-filters:linearRGB;solid-color:#000000;solid-opacity:1;vector-effect:none;fill:#ffffff;fill-opacity:1;fill-rule:evenodd;stroke:none;stroke-width:1;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;marker:none;color-rendering:auto;image-rendering:auto;shape-rendering:auto;text-rendering:auto;enable-background:accumulate" d="m 174.5,163.36793 c -0.27613,3e-5 -0.49997,0.22387 -0.5,0.5 v 3 c 3e-5,0.27613 0.22387,0.49997 0.5,0.5 h 3 c 0.27613,-3e-5 0.49997,-0.22387 0.5,-0.5 v -3 c -3e-5,-0.27613 -0.22387,-0.49997 -0.5,-0.5 z" id="path22124-6" inkscape:connector-curvature="0" sodipodi:nodetypes="ccccccccc" />
</g>
</g>
<g inkscape:groupmode="layer" id="layer2" inkscape:label="EMPTY ICON TRACKING" style="display:none">
<g id="g16331" style="fill:#ffcc00">

Before

Width:  |  Height:  |  Size: 2.4 MiB

After

Width:  |  Height:  |  Size: 2.4 MiB

View File

@ -668,7 +668,7 @@ DEF_ICON(PARTICLE_PATH)
DEF_ICON_BLANK(669)
DEF_ICON_BLANK(670)
DEF_ICON_BLANK(671)
DEF_ICON_BLANK(672)
DEF_ICON(SNAP_MIDPOINT)
DEF_ICON(SNAP_OFF)
DEF_ICON(SNAP_ON)
DEF_ICON(SNAP_NORMAL)

View File

@ -998,7 +998,8 @@ static void CalcSnapGeometry(TransInfo *t, float *UNUSED(vec))
mval[0] = t->mval[0];
mval[1] = t->mval[1];
if (t->tsnap.mode & (SCE_SNAP_MODE_VERTEX | SCE_SNAP_MODE_EDGE | SCE_SNAP_MODE_FACE)) {
if (t->tsnap.mode & (SCE_SNAP_MODE_VERTEX | SCE_SNAP_MODE_EDGE | SCE_SNAP_MODE_FACE |
SCE_SNAP_MODE_EDGE_MIDPOINT)) {
zero_v3(no); /* objects won't set this */
found = snapObjectsTransform(t, mval, &dist_px, loc, no);
}

View File

@ -1260,7 +1260,7 @@ static short snap_mesh_polygon(SnapObjectContext *sctx,
const MPoly *mp = &((SnapObjectData_Mesh *)sod)->poly[*r_index];
const MLoop *ml = &treedata->loop[mp->loopstart];
if (snapdata->snap_to_flag & SCE_SNAP_MODE_EDGE) {
if (snapdata->snap_to_flag & (SCE_SNAP_MODE_EDGE | SCE_SNAP_MODE_EDGE_MIDPOINT)) {
elem = SCE_SNAP_MODE_EDGE;
BLI_assert(treedata->edge != NULL);
for (int i = mp->totloop; i--; ml++) {
@ -1297,7 +1297,7 @@ static short snap_mesh_polygon(SnapObjectContext *sctx,
BMFace *f = BM_face_at_index(em->bm, *r_index);
BMLoop *l_iter, *l_first;
l_iter = l_first = BM_FACE_FIRST_LOOP(f);
if (snapdata->snap_to_flag & SCE_SNAP_MODE_EDGE) {
if (snapdata->snap_to_flag & (SCE_SNAP_MODE_EDGE | SCE_SNAP_MODE_EDGE_MIDPOINT)) {
elem = SCE_SNAP_MODE_EDGE;
BM_mesh_elem_index_ensure(em->bm, BM_EDGE);
BM_mesh_elem_table_ensure(em->bm, BM_VERT | BM_EDGE);
@ -1420,19 +1420,45 @@ static short snap_mesh_edge_verts_mixed(SnapObjectContext *sctx,
&lambda)) {
/* do nothing */
}
else if (lambda < 0.25f || 0.75f < lambda) {
int v_id = lambda < 0.5f ? 0 : 1;
else {
if (snapdata->snap_to_flag & SCE_SNAP_MODE_VERTEX) {
if (lambda < 0.25f || 0.75f < lambda) {
int v_id = lambda < 0.5f ? 0 : 1;
if (test_projected_vert_dist(&neasrest_precalc,
NULL,
0,
nearest2d.is_persp,
v_pair[v_id],
&nearest.dist_sq,
nearest.co)) {
nearest.index = vindex[v_id];
nearest2d.copy_vert_no(vindex[v_id], nearest.no, nearest2d.userdata);
elem = SCE_SNAP_MODE_VERTEX;
if (test_projected_vert_dist(&neasrest_precalc,
NULL,
0,
nearest2d.is_persp,
v_pair[v_id],
&nearest.dist_sq,
nearest.co)) {
nearest.index = vindex[v_id];
nearest2d.copy_vert_no(vindex[v_id], nearest.no, nearest2d.userdata);
elem = SCE_SNAP_MODE_VERTEX;
}
}
}
if (snapdata->snap_to_flag & SCE_SNAP_MODE_EDGE_MIDPOINT) {
if (0.375f < lambda && lambda < 0.625f) {
float vmid[3];
mid_v3_v3v3(vmid, v_pair[0], v_pair[1]);
if (test_projected_vert_dist(&neasrest_precalc,
NULL,
0,
nearest2d.is_persp,
vmid,
&nearest.dist_sq,
nearest.co)) {
float v_nor[2][3];
nearest2d.copy_vert_no(vindex[0], v_nor[0], nearest2d.userdata);
nearest2d.copy_vert_no(vindex[1], v_nor[1], nearest2d.userdata);
mid_v3_v3v3(nearest.no, v_nor[0], v_nor[1]);
nearest.index = *r_index;
elem = SCE_SNAP_MODE_EDGE_MIDPOINT;
}
}
}
}
@ -1926,13 +1952,13 @@ static short snapMesh(SnapObjectContext *sctx,
{
BLI_assert(snapdata->snap_to_flag != SCE_SNAP_MODE_FACE);
if ((snapdata->snap_to_flag & ~SCE_SNAP_MODE_FACE) == SCE_SNAP_MODE_EDGE) {
if (me->totedge == 0) {
if ((snapdata->snap_to_flag & ~SCE_SNAP_MODE_FACE) == SCE_SNAP_MODE_VERTEX) {
if (me->totvert == 0) {
return 0;
}
}
else {
if (me->totvert == 0) {
if (me->totedge == 0) {
return 0;
}
}
@ -2066,7 +2092,7 @@ static short snapMesh(SnapObjectContext *sctx,
last_index = nearest.index;
}
if (snapdata->snap_to_flag & SCE_SNAP_MODE_EDGE) {
if (snapdata->snap_to_flag & (SCE_SNAP_MODE_EDGE | SCE_SNAP_MODE_EDGE_MIDPOINT)) {
if (bvhtree[0]) {
/* snap to loose edges */
BLI_bvhtree_find_nearest_projected(bvhtree[0],
@ -2164,13 +2190,13 @@ static short snapEditMesh(SnapObjectContext *sctx,
{
BLI_assert(snapdata->snap_to_flag != SCE_SNAP_MODE_FACE);
if ((snapdata->snap_to_flag & ~SCE_SNAP_MODE_FACE) == SCE_SNAP_MODE_EDGE) {
if (em->bm->totedge == 0) {
if ((snapdata->snap_to_flag & ~SCE_SNAP_MODE_FACE) == SCE_SNAP_MODE_VERTEX) {
if (em->bm->totvert == 0) {
return 0;
}
}
else {
if (em->bm->totvert == 0) {
if (em->bm->totedge == 0) {
return 0;
}
}
@ -2232,7 +2258,7 @@ static short snapEditMesh(SnapObjectContext *sctx,
}
}
if (snapdata->snap_to_flag & SCE_SNAP_MODE_EDGE) {
if (snapdata->snap_to_flag & (SCE_SNAP_MODE_EDGE | SCE_SNAP_MODE_EDGE_MIDPOINT)) {
if (sod->bvh_trees[1] == NULL) {
sod->bvh_trees[1] = BLI_memarena_calloc(sctx->cache.mem_arena, sizeof(**sod->bvh_trees));
}
@ -2304,7 +2330,8 @@ static short snapEditMesh(SnapObjectContext *sctx,
last_index = nearest.index;
}
if (treedata_edge && snapdata->snap_to_flag & SCE_SNAP_MODE_EDGE) {
if (treedata_edge &&
snapdata->snap_to_flag & (SCE_SNAP_MODE_EDGE | SCE_SNAP_MODE_EDGE_MIDPOINT)) {
BM_mesh_elem_table_ensure(em->bm, BM_EDGE | BM_VERT);
BLI_bvhtree_find_nearest_projected(treedata_edge->tree,
lpmat,
@ -2707,8 +2734,8 @@ static short transform_snap_context_project_view3d_mixed_impl(
Object **r_ob,
float r_obmat[4][4])
{
BLI_assert((snap_to_flag & (SCE_SNAP_MODE_VERTEX | SCE_SNAP_MODE_EDGE | SCE_SNAP_MODE_FACE)) !=
0);
BLI_assert((snap_to_flag & (SCE_SNAP_MODE_VERTEX | SCE_SNAP_MODE_EDGE | SCE_SNAP_MODE_FACE |
SCE_SNAP_MODE_EDGE_MIDPOINT)) != 0);
short retval = 0;
bool has_hit = false;
@ -2733,7 +2760,7 @@ static short transform_snap_context_project_view3d_mixed_impl(
ray_normal,
ray_start,
true)) {
return false;
return 0;
}
float dummy_ray_depth = BVH_RAYCAST_DIST_MAX;
@ -2746,7 +2773,7 @@ static short transform_snap_context_project_view3d_mixed_impl(
}
}
if (snap_to_flag & (SCE_SNAP_MODE_VERTEX | SCE_SNAP_MODE_EDGE)) {
if (snap_to_flag & (SCE_SNAP_MODE_VERTEX | SCE_SNAP_MODE_EDGE | SCE_SNAP_MODE_EDGE_MIDPOINT)) {
short elem;
float dist_px_tmp = *dist_px;
@ -2799,11 +2826,17 @@ static short transform_snap_context_project_view3d_mixed_impl(
retval = elem;
}
if ((retval == SCE_SNAP_MODE_EDGE) && (snapdata.snap_to_flag & SCE_SNAP_MODE_VERTEX)) {
retval = snap_mesh_edge_verts_mixed(
if ((retval == SCE_SNAP_MODE_EDGE) &&
(snap_to_flag & (SCE_SNAP_MODE_VERTEX | SCE_SNAP_MODE_EDGE_MIDPOINT))) {
elem = snap_mesh_edge_verts_mixed(
sctx, &snapdata, ob, obmat, *dist_px, &dist_px_tmp, loc, no, &index);
}
if (elem) {
retval = elem;
}
retval &= snap_to_flag;
*dist_px = dist_px_tmp;
}

View File

@ -2047,6 +2047,7 @@ enum {
#define SCE_SNAP_MODE_FACE (1 << 2)
#define SCE_SNAP_MODE_VOLUME (1 << 3)
#define SCE_SNAP_MODE_INCREMENT (1 << 4)
#define SCE_SNAP_MODE_EDGE_MIDPOINT (1 << 5)
/* ToolSettings.snap_node_mode */
#define SCE_SNAP_MODE_GRID (1 << 5)

View File

@ -167,6 +167,11 @@ const EnumPropertyItem rna_enum_snap_element_items[] = {
{SCE_SNAP_MODE_EDGE, "EDGE", ICON_SNAP_EDGE, "Edge", "Snap to edges"},
{SCE_SNAP_MODE_FACE, "FACE", ICON_SNAP_FACE, "Face", "Snap to faces"},
{SCE_SNAP_MODE_VOLUME, "VOLUME", ICON_SNAP_VOLUME, "Volume", "Snap to volume"},
{SCE_SNAP_MODE_EDGE_MIDPOINT,
"EDGE_MIDPOINT",
ICON_SNAP_MIDPOINT,
"Edge Center",
"Snap to the middle of edges"},
{0, NULL, 0, NULL, NULL},
};