[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [45670] trunk/blender/source/blender/ editors/uvedit/uvedit_ops.c: fix [#30967] Straighten X/Y in the UV/ Image Editor bug

Campbell Barton ideasman42 at gmail.com
Mon Apr 16 03:55:28 CEST 2012


Revision: 45670
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=45670
Author:   campbellbarton
Date:     2012-04-16 01:55:25 +0000 (Mon, 16 Apr 2012)
Log Message:
-----------
fix [#30967] Straighten X/Y in the UV/Image Editor bug
patch by Bastien Montagne, checked this works the same as 2.62.

Modified Paths:
--------------
    trunk/blender/source/blender/editors/uvedit/uvedit_ops.c

Modified: trunk/blender/source/blender/editors/uvedit/uvedit_ops.c
===================================================================
--- trunk/blender/source/blender/editors/uvedit/uvedit_ops.c	2012-04-16 01:18:02 UTC (rev 45669)
+++ trunk/blender/source/blender/editors/uvedit/uvedit_ops.c	2012-04-16 01:55:25 UTC (rev 45670)
@@ -1481,12 +1481,20 @@
 				/* we know the returns from these must be valid */
 				float *uv_start = uv_sel_co_from_eve(scene, ima, em, eve_line[0]);
 				float *uv_end   = uv_sel_co_from_eve(scene, ima, em, eve_line[BLI_array_count(eve_line) - 1]);
+				/* For t & u modes */
+				float a = 0.0f;
 
 				if (tool == 't') {
-					uv_start[0] = uv_end[0] = (uv_start[0] + uv_end[0]) * 0.5f;
+					if (uv_start[1] == uv_end[1])
+						tool = 's';
+					else
+						a = (uv_end[0] - uv_start[0]) / (uv_end[1] - uv_start[1]);
 				}
 				else if (tool == 'u') {
-					uv_start[1] = uv_end[1] = (uv_start[1] + uv_end[1]) * 0.5f;
+					if (uv_start[0] == uv_end[0])
+						tool = 's';
+					else
+						a = (uv_end[1] - uv_start[1]) / (uv_end[0] - uv_start[0]);
 				}
 
 				/* go over all verts except for endpoints */
@@ -1499,7 +1507,16 @@
 
 						if (uvedit_uv_selected(em, scene, l)) {
 							MLoopUV *luv = CustomData_bmesh_get(&em->bm->ldata, l->head.data, CD_MLOOPUV);
-							closest_to_line_segment_v2(luv->uv, luv->uv, uv_start, uv_end);
+							/* Projection of point (x, y) over line (x1, y1, x2, y2) along X axis:
+							 * new_y = (y2 - y1) / (x2 - x1) * (x - x1) + y1
+							 * Maybe this should be a BLI func? Or is it already existing?
+							 * Could use interp_v2_v2v2, but not sure it’s worth it here...*/
+							if (tool == 't')
+								luv->uv[0] = a * (luv->uv[1] - uv_start[1]) + uv_start[0];
+							else if (tool == 'u')
+								luv->uv[1] = a * (luv->uv[0] - uv_start[0]) + uv_start[1];
+							else
+								closest_to_line_segment_v2(luv->uv, luv->uv, uv_start, uv_end);
 						}
 					}
 				}




More information about the Bf-blender-cvs mailing list