Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/source
diff options
context:
space:
mode:
authormano-wii <germano.costa@ig.com.br>2019-08-20 21:07:48 +0300
committermano-wii <germano.costa@ig.com.br>2019-08-20 21:07:48 +0300
commit58341242bf6b30392435130b242d2366ab03c1dd (patch)
tree29aa10a82d019779804008022037024c5286b3e4 /source
parent1876e18b1b8fd252f11e380da8ee80bb5e607a48 (diff)
Editor Transform: New Snap Option Middle
Part of T66420 Reviewers: campbellbarton, brecht Reviewed By: campbellbarton Differential Revision: https://developer.blender.org/D5532
Diffstat (limited to 'source')
-rw-r--r--source/blender/editors/include/UI_icons.h2
-rw-r--r--source/blender/editors/transform/transform_snap.c3
-rw-r--r--source/blender/editors/transform/transform_snap_object.c91
-rw-r--r--source/blender/makesdna/DNA_scene_types.h1
-rw-r--r--source/blender/makesrna/intern/rna_scene.c5
5 files changed, 71 insertions, 31 deletions
diff --git a/source/blender/editors/include/UI_icons.h b/source/blender/editors/include/UI_icons.h
index 03a49943ed3..bca0d8984c8 100644
--- a/source/blender/editors/include/UI_icons.h
+++ b/source/blender/editors/include/UI_icons.h
@@ -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)
diff --git a/source/blender/editors/transform/transform_snap.c b/source/blender/editors/transform/transform_snap.c
index dbcc6c1b04a..9d107527833 100644
--- a/source/blender/editors/transform/transform_snap.c
+++ b/source/blender/editors/transform/transform_snap.c
@@ -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);
}
diff --git a/source/blender/editors/transform/transform_snap_object.c b/source/blender/editors/transform/transform_snap_object.c
index 67bd107ab49..4943e538590 100644
--- a/source/blender/editors/transform/transform_snap_object.c
+++ b/source/blender/editors/transform/transform_snap_object.c
@@ -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;
}
diff --git a/source/blender/makesdna/DNA_scene_types.h b/source/blender/makesdna/DNA_scene_types.h
index 45159af306c..8cf7b82e1ca 100644
--- a/source/blender/makesdna/DNA_scene_types.h
+++ b/source/blender/makesdna/DNA_scene_types.h
@@ -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)
diff --git a/source/blender/makesrna/intern/rna_scene.c b/source/blender/makesrna/intern/rna_scene.c
index 45614668475..0da96a895a9 100644
--- a/source/blender/makesrna/intern/rna_scene.c
+++ b/source/blender/makesrna/intern/rna_scene.c
@@ -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},
};