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
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2018-05-13 07:56:51 +0300
committerCampbell Barton <ideasman42@gmail.com>2018-05-13 07:56:51 +0300
commit59c6487e9314dd43003af1a018fc092b041e7e10 (patch)
treede8cc7dd06b875d174cb79cad7558874c8bffa5e /source/blender/editors/transform/transform_snap.c
parent7a56d31af3523081e33a67d7aea11314c37c7104 (diff)
parentb99d064e9142b2e9d790731f4c4c6c107ca43696 (diff)
Merge branch 'master' into blender2.8
Diffstat (limited to 'source/blender/editors/transform/transform_snap.c')
-rw-r--r--source/blender/editors/transform/transform_snap.c150
1 files changed, 75 insertions, 75 deletions
diff --git a/source/blender/editors/transform/transform_snap.c b/source/blender/editors/transform/transform_snap.c
index 7eff1b33acc..681f955087a 100644
--- a/source/blender/editors/transform/transform_snap.c
+++ b/source/blender/editors/transform/transform_snap.c
@@ -114,12 +114,12 @@ static NodeBorder snapNodeBorder(int snap_node_mode);
int BIF_snappingSupported(Object *obedit)
{
int status = 0;
-
+
/* only support object mesh, armature, curves */
if (obedit == NULL || ELEM(obedit->type, OB_MESH, OB_ARMATURE, OB_CURVE, OB_LATTICE, OB_MBALL)) {
status = 1;
}
-
+
return status;
}
#endif
@@ -139,19 +139,19 @@ bool activeSnap(TransInfo *t)
void drawSnapping(const struct bContext *C, TransInfo *t)
{
unsigned char col[4], selectedCol[4], activeCol[4];
-
+
if (!activeSnap(t))
return;
-
+
UI_GetThemeColor3ubv(TH_TRANSFORM, col);
col[3] = 128;
-
+
UI_GetThemeColor3ubv(TH_SELECT, selectedCol);
selectedCol[3] = 128;
-
+
UI_GetThemeColor3ubv(TH_ACTIVE, activeCol);
activeCol[3] = 192;
-
+
if (t->spacetype == SPACE_VIEW3D) {
if (validSnap(t)) {
TransSnapPoint *p;
@@ -159,11 +159,11 @@ void drawSnapping(const struct bContext *C, TransInfo *t)
RegionView3D *rv3d = CTX_wm_region_view3d(C);
float imat[4][4];
float size;
-
+
glDisable(GL_DEPTH_TEST);
-
+
size = 2.5f * UI_GetThemeValuef(TH_VERTEX_SIZE);
-
+
invert_m4_m4(imat, rv3d->viewmat);
unsigned int pos = GWN_vertformat_attr_add(immVertexFormat(), "pos", GWN_COMP_F32, 3, GWN_FETCH_FLOAT);
@@ -177,20 +177,20 @@ void drawSnapping(const struct bContext *C, TransInfo *t)
else {
immUniformColor4ubv(col);
}
-
+
imm_drawcircball(p->co, ED_view3d_pixel_size(rv3d, p->co) * size * 0.75f, imat, pos);
}
-
+
if (t->tsnap.status & POINT_INIT) {
immUniformColor4ubv(activeCol);
-
+
imm_drawcircball(t->tsnap.snapPoint, ED_view3d_pixel_size(rv3d, t->tsnap.snapPoint) * size, imat, pos);
}
-
+
/* draw normal if needed */
if (usingSnappingNormal(t) && validSnappingNormal(t)) {
immUniformColor4ubv(activeCol);
-
+
immBegin(GWN_PRIM_LINES, 2);
immVertex3f(pos, t->tsnap.snapPoint[0], t->tsnap.snapPoint[1], t->tsnap.snapPoint[2]);
immVertex3f(pos, t->tsnap.snapPoint[0] + t->tsnap.snapNormal[0],
@@ -216,11 +216,11 @@ void drawSnapping(const struct bContext *C, TransInfo *t)
ARegion *ar = CTX_wm_region(C);
TransSnapPoint *p;
float size;
-
+
size = 2.5f * UI_GetThemeValuef(TH_VERTEX_SIZE);
-
+
glEnable(GL_BLEND);
-
+
unsigned int pos = GWN_vertformat_attr_add(immVertexFormat(), "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
@@ -232,13 +232,13 @@ void drawSnapping(const struct bContext *C, TransInfo *t)
else {
immUniformColor4ubv(col);
}
-
+
ED_node_draw_snap(&ar->v2d, p->co, size, 0, pos);
}
-
+
if (t->tsnap.status & POINT_INIT) {
immUniformColor4ubv(activeCol);
-
+
ED_node_draw_snap(&ar->v2d, t->tsnap.snapPoint, size, t->tsnap.snapNodeBorder, pos);
}
@@ -264,7 +264,7 @@ eRedrawFlag handleSnapping(TransInfo *t, const wmEvent *event)
if (event->type == MOUSEMOVE) {
status |= updateSelectedSnapPoint(t);
}
-
+
return status;
}
@@ -345,14 +345,14 @@ void applyGridAbsolute(TransInfo *t)
float grid_size = 0.0f;
GearsType grid_action;
int i;
-
+
if (!(activeSnap(t) && (ELEM(t->tsnap.mode, SCE_SNAP_MODE_INCREMENT, SCE_SNAP_MODE_GRID))))
return;
-
+
grid_action = BIG_GEARS;
if (t->modifiers & MOD_PRECISION)
grid_action = SMALL_GEARS;
-
+
switch (grid_action) {
case NO_GEARS: grid_size = t->snap_spatial[0]; break;
case BIG_GEARS: grid_size = t->snap_spatial[1]; break;
@@ -361,7 +361,7 @@ void applyGridAbsolute(TransInfo *t)
/* early exit on unusable grid size */
if (grid_size == 0.0f)
return;
-
+
FOREACH_TRANS_DATA_CONTAINER(t, tc) {
TransData *td;
@@ -404,21 +404,21 @@ void applySnapping(TransInfo *t, float *vec)
/* project is not applied this way */
if (t->tsnap.project)
return;
-
+
if (t->tsnap.status & SNAP_FORCED) {
t->tsnap.targetSnap(t);
-
+
t->tsnap.applySnap(t, vec);
}
else if (!ELEM(t->tsnap.mode, SCE_SNAP_MODE_INCREMENT, SCE_SNAP_MODE_GRID) && activeSnap(t)) {
double current = PIL_check_seconds_timer();
-
+
// Time base quirky code to go around findnearest slowness
/* !TODO! add exception for object mode, no need to slow it down then */
if (current - t->tsnap.last >= 0.01) {
t->tsnap.calcSnap(t, vec);
t->tsnap.targetSnap(t);
-
+
t->tsnap.last = current;
}
if (validSnap(t)) {
@@ -441,7 +441,7 @@ void resetSnapping(TransInfo *t)
t->tsnap.snapNormal[0] = 0;
t->tsnap.snapNormal[1] = 0;
t->tsnap.snapNormal[2] = 0;
-
+
t->tsnap.snapNodeBorder = 0;
}
@@ -457,7 +457,7 @@ bool validSnappingNormal(TransInfo *t)
return true;
}
}
-
+
return false;
}
@@ -501,20 +501,20 @@ static void initSnappingMode(TransInfo *t)
if (t->spacetype == SPACE_NODE) {
/* force project off when not supported */
t->tsnap.project = 0;
-
+
t->tsnap.mode = ts->snap_node_mode;
}
else if (t->spacetype == SPACE_IMAGE) {
/* force project off when not supported */
t->tsnap.project = 0;
-
+
t->tsnap.mode = ts->snap_uv_mode;
}
else {
/* force project off when not supported */
if (ts->snap_mode != SCE_SNAP_MODE_FACE)
t->tsnap.project = 0;
-
+
t->tsnap.mode = ts->snap_mode;
}
@@ -556,7 +556,7 @@ static void initSnappingMode(TransInfo *t)
}
else if (t->spacetype == SPACE_NODE) {
setSnappingCallback(t);
-
+
if (t->tsnap.applySnap != NULL) {
t->tsnap.modeSelect = SNAP_NOT_SELECTED;
}
@@ -593,9 +593,9 @@ void initSnapping(TransInfo *t, wmOperator *op)
{
ToolSettings *ts = t->settings;
short snap_target = t->settings->snap_target;
-
+
resetSnapping(t);
-
+
/* if snap property exists */
if (op && RNA_struct_find_property(op->ptr, "snap") && RNA_struct_property_is_set(op->ptr, "snap")) {
if (RNA_boolean_get(op->ptr, "snap")) {
@@ -604,12 +604,12 @@ void initSnapping(TransInfo *t, wmOperator *op)
if (RNA_struct_property_is_set(op->ptr, "snap_target")) {
snap_target = RNA_enum_get(op->ptr, "snap_target");
}
-
+
if (RNA_struct_property_is_set(op->ptr, "snap_point")) {
RNA_float_get_array(op->ptr, "snap_point", t->tsnap.snapPoint);
t->tsnap.status |= SNAP_FORCED | POINT_INIT;
}
-
+
/* snap align only defined in specific cases */
if (RNA_struct_find_property(op->ptr, "snap_align")) {
t->tsnap.align = RNA_boolean_get(op->ptr, "snap_align");
@@ -644,7 +644,7 @@ void initSnapping(TransInfo *t, wmOperator *op)
t->tsnap.snap_spatial_grid = ((t->settings->snap_flag & SCE_SNAP_ABS_GRID) != 0);
}
}
-
+
t->tsnap.target = snap_target;
initSnappingMode(t);
@@ -863,24 +863,24 @@ static float RotationBetween(
sub_v3_v3v3(start, p1, t->center_global);
sub_v3_v3v3(end, p2, t->center_global);
-
+
// Angle around a constraint axis (error prone, will need debug)
if (t->con.applyRot != NULL && (t->con.mode & CON_APPLY)) {
float axis[3], tmp[3];
-
+
t->con.applyRot(t, NULL, NULL, axis, NULL);
project_v3_v3v3(tmp, end, axis);
sub_v3_v3v3(end, end, tmp);
-
+
project_v3_v3v3(tmp, start, axis);
sub_v3_v3v3(start, start, tmp);
-
+
normalize_v3(end);
normalize_v3(start);
-
+
cross_v3_v3v3(tmp, start, end);
-
+
if (dot_v3v3(tmp, axis) < 0.0f)
angle = -acosf(dot_v3v3(start, end));
else
@@ -888,22 +888,22 @@ static float RotationBetween(
}
else {
float mtx[3][3];
-
+
copy_m3_m4(mtx, t->viewmat);
mul_m3_v3(mtx, end);
mul_m3_v3(mtx, start);
-
+
angle = atan2f(start[1], start[0]) - atan2f(end[1], end[0]);
}
-
+
if (angle > (float)M_PI) {
angle = angle - 2 * (float)M_PI;
}
else if (angle < -((float)M_PI)) {
angle = 2.0f * (float)M_PI + angle;
}
-
+
return angle;
}
@@ -920,7 +920,7 @@ static float ResizeBetween(TransInfo *t, const float p1[3], const float p2[3])
}
project_v3_v3v3(d1, d1, d2);
-
+
len_d1 = len_v3(d1);
/* Use 'invalid' dist when `center == p1` (after projecting),
@@ -944,10 +944,10 @@ static void CalcSnapGeometry(TransInfo *t, float *UNUSED(vec))
float mval[2];
bool found = false;
float dist_px = SNAP_MIN_DISTANCE; // Use a user defined value here
-
+
mval[0] = t->mval[0];
mval[1] = t->mval[1];
-
+
if (t->tsnap.mode == SCE_SNAP_MODE_VOLUME) {
found = peelObjectsTransform(
t, mval,
@@ -960,7 +960,7 @@ static void CalcSnapGeometry(TransInfo *t, float *UNUSED(vec))
t, mval, &dist_px,
loc, no);
}
-
+
if (found == true) {
copy_v3_v3(t->tsnap.snapPoint, loc);
copy_v3_v3(t->tsnap.snapNormal, no);
@@ -975,7 +975,7 @@ static void CalcSnapGeometry(TransInfo *t, float *UNUSED(vec))
/* same as above but for UV's */
Image *ima = ED_space_image(t->sa->spacedata.first);
float co[2];
-
+
UI_view2d_region_to_view(&t->ar->v2d, t->mval[0], t->mval[1], &co[0], &co[1]);
if (ED_uvedit_nearest_uv(t->scene, TRANS_DATA_CONTAINER_FIRST_EVIL(t)->obedit, ima, co, t->tsnap.snapPoint)) {
@@ -992,11 +992,11 @@ static void CalcSnapGeometry(TransInfo *t, float *UNUSED(vec))
float loc[2];
float dist_px = SNAP_MIN_DISTANCE; // Use a user defined value here
char node_border;
-
+
if (snapNodesTransform(t, t->mval, loc, &dist_px, &node_border)) {
copy_v2_v2(t->tsnap.snapPoint, loc);
t->tsnap.snapNodeBorder = node_border;
-
+
t->tsnap.status |= POINT_INIT;
}
else {
@@ -1014,7 +1014,7 @@ static void TargetSnapOffset(TransInfo *t, TransData *td)
char border = t->tsnap.snapNodeBorder;
float width = BLI_rctf_size_x(&node->totr);
float height = BLI_rctf_size_y(&node->totr);
-
+
#ifdef USE_NODE_CENTER
if (border & NODE_LEFT)
t->tsnap.snapTarget[0] -= 0.5f * width;
@@ -1043,7 +1043,7 @@ static void TargetSnapCenter(TransInfo *t)
if ((t->tsnap.status & TARGET_INIT) == 0) {
copy_v3_v3(t->tsnap.snapTarget, t->center_global);
TargetSnapOffset(t, NULL);
-
+
t->tsnap.status |= TARGET_INIT;
}
}
@@ -1094,9 +1094,9 @@ static void TargetSnapMedian(TransInfo *t)
}
mul_v3_fl(t->tsnap.snapTarget, 1.0 / i_accum);
-
+
TargetSnapOffset(t, NULL);
-
+
t->tsnap.status |= TARGET_INIT;
}
}
@@ -1107,7 +1107,7 @@ static void TargetSnapClosest(TransInfo *t)
if (t->tsnap.status & POINT_INIT) {
float dist_closest = 0.0f;
TransData *closest = NULL;
-
+
/* Object mode */
if (t->flag & T_OBJECT) {
int i;
@@ -1183,9 +1183,9 @@ static void TargetSnapClosest(TransInfo *t)
}
}
}
-
+
TargetSnapOffset(t, closest);
-
+
t->tsnap.status |= TARGET_INIT;
}
}
@@ -1330,9 +1330,9 @@ static bool snapNode(
bool retval = false;
rcti totr;
int new_dist;
-
+
UI_view2d_view_to_region_rcti(v2d, &node->totr, &totr);
-
+
if (border & NODE_LEFT) {
new_dist = abs(totr.xmin - mval[0]);
if (new_dist < *r_dist_px) {
@@ -1342,7 +1342,7 @@ static bool snapNode(
retval = true;
}
}
-
+
if (border & NODE_RIGHT) {
new_dist = abs(totr.xmax - mval[0]);
if (new_dist < *r_dist_px) {
@@ -1352,7 +1352,7 @@ static bool snapNode(
retval = true;
}
}
-
+
if (border & NODE_BOTTOM) {
new_dist = abs(totr.ymin - mval[1]);
if (new_dist < *r_dist_px) {
@@ -1362,7 +1362,7 @@ static bool snapNode(
retval = true;
}
}
-
+
if (border & NODE_TOP) {
new_dist = abs(totr.ymax - mval[1]);
if (new_dist < *r_dist_px) {
@@ -1372,7 +1372,7 @@ static bool snapNode(
retval = true;
}
}
-
+
return retval;
}
@@ -1384,15 +1384,15 @@ static bool snapNodes(
bNodeTree *ntree = snode->edittree;
bNode *node;
bool retval = false;
-
+
*r_node_border = 0;
-
+
for (node = ntree->nodes.first; node; node = node->next) {
if (snapNodeTest(&ar->v2d, node, snap_select)) {
retval |= snapNode(ts, snode, ar, node, mval, r_loc, r_dist_px, r_node_border);
}
}
-
+
return retval;
}
@@ -1417,7 +1417,7 @@ void snapGridIncrementAction(TransInfo *t, float *val, GearsType action)
fac[NO_GEARS] = t->snap[0];
fac[BIG_GEARS] = t->snap[1];
fac[SMALL_GEARS] = t->snap[2];
-
+
applyGridIncrement(t, val, t->idx_max, fac, action);
}