UV Constrain to bounds not constraining when scaling UV's #50398

Closed
opened 2017-01-09 12:55:26 +01:00 by Alex · 17 comments

System: MacOS 10.12

Blender Version: 2.78a

Short description of error
UV's are able to be scaled beyond bounds in 'constrain to bounds mode' when pivot point is set to 2D cursor, and positioned on an edge.
This issue can also be reproduced on the x axis as well, it seems to be dependent on where the 2D cursor is placed within the UV workspace.

Exact steps for others to reproduce the error

Try to scale to the y axis

Screen Shot 2017-01-09 at 10.05.57 pm.png

Screen Shot 2017-01-09 at 10.06.07 pm.png

System: MacOS 10.12 Blender Version: 2.78a **Short description of error** UV's are able to be scaled beyond bounds in 'constrain to bounds mode' when pivot point is set to 2D cursor, and positioned on an edge. This issue can also be reproduced on the x axis as well, it seems to be dependent on where the 2D cursor is placed within the UV workspace. **Exact steps for others to reproduce the error** - Open: [UV_Constrain_to_bounds_bug.blend](https://archive.blender.org/developer/F431173/UV_Constrain_to_bounds_bug.blend) - Go to UV editor # Try to scale to the y axis ![Screen Shot 2017-01-09 at 10.05.57 pm.png](https://archive.blender.org/developer/F430506/Screen_Shot_2017-01-09_at_10.05.57_pm.png) ![Screen Shot 2017-01-09 at 10.06.07 pm.png](https://archive.blender.org/developer/F430504/Screen_Shot_2017-01-09_at_10.06.07_pm.png)
Author

Changed status to: 'Open'

Changed status to: 'Open'
Author

Added subscriber: @Alexandermitchell

Added subscriber: @Alexandermitchell

#58703 was marked as duplicate of this issue

#58703 was marked as duplicate of this issue
Alex changed title from UV Constrain to bounds not constrining when scaling UV's to UV Constrain to bounds not constraining when scaling UV's 2017-01-09 12:55:54 +01:00
Member

Added subscriber: @lichtwerk

Added subscriber: @lichtwerk
Member

first note: seems to only happen when 2d cursor is exactly on the bounds (or outside)
Will check logic in clipUVTransform() when time permits [could take some time though due to dayjob... so if somebody wants to jump in....]

first note: seems to only happen when 2d cursor is exactly on the bounds (or outside) Will check logic in `clipUVTransform()` when time permits [could take some time though due to dayjob... so if somebody wants to jump in....]

Added subscriber: @greasyblend

Added subscriber: @greasyblend

Added subscriber: @JKVargas

Added subscriber: @JKVargas

Can I get this task?

Can I get this task?
Philipp Oeser self-assigned this 2017-01-28 09:03:15 +01:00
Member

I had a look at this just yesterday and have this working mostly already, only have to iron out a cornercase...
So assigning this to me [as I can finish it up this weekend] and hope you didnt already work on this.
If you already solved this though in the meantime feel free to comandeer back...

I had a look at this just yesterday and have this working mostly already, only have to iron out a cornercase... So assigning this to me [as I can finish it up this weekend] and hope you didnt already work on this. If you already solved this though in the meantime feel free to comandeer back...
Philipp Oeser removed their assignment 2017-01-30 19:49:00 +01:00
Member

Hi there,
unfortunately I didnt find the time to finish/clean this up (and I am not sure when I will find time) so I'm just pasting a very rough diff for others to pick up.... P440: #50398 rough



diff --git a/source/blender/editors/transform/transform.c b/source/blender/editors/transform/transform.c
--- a/source/blender/editors/transform/transform.c
+++ b/source/blender/editors/transform/transform.c
@@ -3453,6 +3453,8 @@ static void applyResize(TransInfo *t, const int mval[2])
 	
 	/* evil hack - redo resize if cliping needed */
 	if (t->flag & T_CLIP_UV && clipUVTransform(t, t->values, 1)) {
+		headerResize(t, t->values, str);
+
 		size_to_mat3(mat, t->values);
 		
 		if (t->con.applySize)
diff --git a/source/blender/editors/transform/transform_conversions.c b/source/blender/editors/transform/transform_conversions.c
--- a/source/blender/editors/transform/transform_conversions.c
+++ b/source/blender/editors/transform/transform_conversions.c
@@ -2955,46 +2955,107 @@ bool clipUVTransform(TransInfo *t, float vec- [x], const bool resize)
 {
 	TransData *td;
 	int a;
-	bool clipx = true, clipy = true;
-	float min- [x], max[2];
+	bool clipx = false, clipy = false;
+	bool sclipx- [x], sclipy[2];
+	float min- [x], max- [x], median- [x], scale_compensate- [x][2];
 
+	sclipx- [x] = sclipx- [x] = sclipy- [x] = sclipy- [x] = false;
+	scale_compensate- [x]- [x] = scale_compensate- [x]- [x] = scale_compensate- [x]- [x] = scale_compensate- [x]- [x] = 1.0f;
+	median- [x] = median- [x] = 0.0f;
 	min- [x] = min- [x] = 0.0f;
 	max- [x] = t->aspect[0];
 	max- [x] = t->aspect[1];
 
 	for (a = 0, td = t->data; a < t->total; a++, td++) {
 		minmax_v2v2_v2(min, max, td->loc);
+		add_v2_v2(median, td->iloc);
 	}
+	mul_v2_fl(median, (1.0f / (float)t->total));
+
+	// still need to solve the case when scaling vec- [x] or vec- [x] is negative and cursor is outside of bounds
 
 	if (resize) {
-		if (min- [x] < 0.0f && t->center- [x] > 0.0f && t->center- [x] < t->aspect- [x] * 0.5f)
-			vec- [x] *= t->center- [x] / (t->center- [x] - min[0]);
-		else if (max- [x] > t->aspect- [x] && t->center- [x] < t->aspect[0])
-			vec- [x] *= (t->center- [x] - t->aspect- [x]) / (t->center- [x] - max[0]);
-		else
-			clipx = 0;
+		if (median- [x] < 0.0f || median- [x] > t->aspect- [x] || median- [x] < 0.0f || median- [x] > t->aspect[1]) {
+			return false;
+		}
 
-		if (min- [x] < 0.0f && t->center- [x] > 0.0f && t->center- [x] < t->aspect- [x] * 0.5f)
-			vec- [x] *= t->center- [x] / (t->center- [x] - min[1]);
-		else if (max- [x] > t->aspect- [x] && t->center- [x] < t->aspect[1])
-			vec- [x] *= (t->center- [x] - t->aspect- [x]) / (t->center- [x] - max[1]);
-		else
-			clipy = 0;
+		if (min- [x] < 0.0f) {
+			/* could run into devide by zero? */
+			scale_compensate- [x]- [x] = t->center- [x] / (t->center- [x] - min[0]);
+			sclipx- [x] = true;
+		}
+		if (max- [x] > t->aspect[0]) {
+			scale_compensate- [x]- [x] = (t->center- [x] - t->aspect- [x]) / (t->center- [x] - max[0]);
+			sclipx- [x] = true;
+		}
+		if (sclipx- [x] || sclipx[1]) {
+			if (sclipx- [x] && !sclipx[1]) {
+				vec- [x] *= scale_compensate- [x][0];
+			}
+			else if (sclipx- [x] && !sclipx[0]) {
+				vec- [x] *= scale_compensate- [x][1];
+			}
+			else {
+				if ((abs(1.0f - scale_compensate- [x]- [x]) > abs(1.0f - scale_compensate- [x]- [x])) && sclipx[0]) {
+					vec- [x] *= scale_compensate- [x][0];
+				}
+				else {
+					vec- [x] *= scale_compensate- [x][1];
+				}
+			}
+			clipx = true;
+		}
+
+		if (min- [x] < 0.0f) {
+			scale_compensate- [x]- [x] = t->center- [x] / (t->center- [x] - min[1]);
+			sclipy- [x] = true;
+		}
+		if (max- [x] > t->aspect[1]) {
+			scale_compensate- [x]- [x] = (t->center- [x] - t->aspect- [x]) / (t->center- [x] - max[1]);
+			sclipy- [x] = true;
+		}
+		if (sclipy- [x] || sclipy[1]) {
+			if (sclipy- [x] && !sclipy[1]) {
+				vec- [x] *= scale_compensate- [x][0];
+			}
+			else if (sclipy- [x] && !sclipy[0]) {
+				vec- [x] *= scale_compensate- [x][1];
+			}
+			else {
+				if ((abs(1.0f - scale_compensate- [x]- [x]) > abs(1.0f - scale_compensate- [x]- [x])) && sclipy[0]) {
+					vec- [x] *= scale_compensate- [x][0];
+				}
+				else {
+					vec- [x] *= scale_compensate- [x][1];
+				}
+			}
+			clipy = true;
+		}
+
+		/* just idea to keep scaling uniform in aspect
+		if (sclipx- [x] || sclipx- [x] || sclipy- [x] || sclipy[1]) {
+			mul_v2_fl(vec, min_ffff(scale_compensate- [x]- [x], scale_compensate- [x]- [x], scale_compensate- [x]- [x], scale_compensate- [x][1]));
+		}
+		*/
 	}
 	else {
-		if (min- [x] < 0.0f)
+		if (min- [x] < 0.0f) {
 			vec- [x] -= min[0];
-		else if (max- [x] > t->aspect[0])
+			clipx = true;
+		}
+		else if (max- [x] > t->aspect[0]) {
 			vec- [x] -= max- [x] - t->aspect[0];
-		else
-			clipx = 0;
+			clipx = true;
+		}
 
-		if (min- [x] < 0.0f)
+		if (min- [x] < 0.0f) {
 			vec- [x] -= min[1];
-		else if (max- [x] > t->aspect[1])
+			clipy = true;
+		}
+		if (max- [x] > t->aspect[1]) {
 			vec- [x] -= max- [x] - t->aspect[1];
-		else
-			clipy = 0;
+			clipy = true;
+		}
 	}
 
 	return (clipx || clipy);

This just tries to solve a couple of issues I found with the clipping code:

  • clip minx/miny not working (if center/cursor is 'in right side')
  • clip doesnt allow for cursor being outside of UV bounds (or directly on the bounds like in this report) [the paste allows for this]
  • when scaling and runnning into clipmax first, then scale further and run into clipmin after --> pop to clipmin
  • also wasnt sure if it is a good idea to scale further on other axis after running into one clipping border [making the scale non-uniform in aspect] - which is the case in current code. There is a small snippet in the paste that could prevent this

This is obviously very rough and could propably be simplified [its more like working pseudo code...]

Hi there, unfortunately I didnt find the time to finish/clean this up (and I am not sure when I will find time) so I'm just pasting a very rough diff for others to pick up.... [P440: #50398 rough](https://archive.blender.org/developer/P440.txt) ``` diff --git a/source/blender/editors/transform/transform.c b/source/blender/editors/transform/transform.c --- a/source/blender/editors/transform/transform.c +++ b/source/blender/editors/transform/transform.c @@ -3453,6 +3453,8 @@ static void applyResize(TransInfo *t, const int mval[2]) /* evil hack - redo resize if cliping needed */ if (t->flag & T_CLIP_UV && clipUVTransform(t, t->values, 1)) { + headerResize(t, t->values, str); + size_to_mat3(mat, t->values); if (t->con.applySize) diff --git a/source/blender/editors/transform/transform_conversions.c b/source/blender/editors/transform/transform_conversions.c --- a/source/blender/editors/transform/transform_conversions.c +++ b/source/blender/editors/transform/transform_conversions.c @@ -2955,46 +2955,107 @@ bool clipUVTransform(TransInfo *t, float vec- [x], const bool resize) { TransData *td; int a; - bool clipx = true, clipy = true; - float min- [x], max[2]; + bool clipx = false, clipy = false; + bool sclipx- [x], sclipy[2]; + float min- [x], max- [x], median- [x], scale_compensate- [x][2]; + sclipx- [x] = sclipx- [x] = sclipy- [x] = sclipy- [x] = false; + scale_compensate- [x]- [x] = scale_compensate- [x]- [x] = scale_compensate- [x]- [x] = scale_compensate- [x]- [x] = 1.0f; + median- [x] = median- [x] = 0.0f; min- [x] = min- [x] = 0.0f; max- [x] = t->aspect[0]; max- [x] = t->aspect[1]; for (a = 0, td = t->data; a < t->total; a++, td++) { minmax_v2v2_v2(min, max, td->loc); + add_v2_v2(median, td->iloc); } + mul_v2_fl(median, (1.0f / (float)t->total)); + + // still need to solve the case when scaling vec- [x] or vec- [x] is negative and cursor is outside of bounds if (resize) { - if (min- [x] < 0.0f && t->center- [x] > 0.0f && t->center- [x] < t->aspect- [x] * 0.5f) - vec- [x] *= t->center- [x] / (t->center- [x] - min[0]); - else if (max- [x] > t->aspect- [x] && t->center- [x] < t->aspect[0]) - vec- [x] *= (t->center- [x] - t->aspect- [x]) / (t->center- [x] - max[0]); - else - clipx = 0; + if (median- [x] < 0.0f || median- [x] > t->aspect- [x] || median- [x] < 0.0f || median- [x] > t->aspect[1]) { + return false; + } - if (min- [x] < 0.0f && t->center- [x] > 0.0f && t->center- [x] < t->aspect- [x] * 0.5f) - vec- [x] *= t->center- [x] / (t->center- [x] - min[1]); - else if (max- [x] > t->aspect- [x] && t->center- [x] < t->aspect[1]) - vec- [x] *= (t->center- [x] - t->aspect- [x]) / (t->center- [x] - max[1]); - else - clipy = 0; + if (min- [x] < 0.0f) { + /* could run into devide by zero? */ + scale_compensate- [x]- [x] = t->center- [x] / (t->center- [x] - min[0]); + sclipx- [x] = true; + } + if (max- [x] > t->aspect[0]) { + scale_compensate- [x]- [x] = (t->center- [x] - t->aspect- [x]) / (t->center- [x] - max[0]); + sclipx- [x] = true; + } + if (sclipx- [x] || sclipx[1]) { + if (sclipx- [x] && !sclipx[1]) { + vec- [x] *= scale_compensate- [x][0]; + } + else if (sclipx- [x] && !sclipx[0]) { + vec- [x] *= scale_compensate- [x][1]; + } + else { + if ((abs(1.0f - scale_compensate- [x]- [x]) > abs(1.0f - scale_compensate- [x]- [x])) && sclipx[0]) { + vec- [x] *= scale_compensate- [x][0]; + } + else { + vec- [x] *= scale_compensate- [x][1]; + } + } + clipx = true; + } + + if (min- [x] < 0.0f) { + scale_compensate- [x]- [x] = t->center- [x] / (t->center- [x] - min[1]); + sclipy- [x] = true; + } + if (max- [x] > t->aspect[1]) { + scale_compensate- [x]- [x] = (t->center- [x] - t->aspect- [x]) / (t->center- [x] - max[1]); + sclipy- [x] = true; + } + if (sclipy- [x] || sclipy[1]) { + if (sclipy- [x] && !sclipy[1]) { + vec- [x] *= scale_compensate- [x][0]; + } + else if (sclipy- [x] && !sclipy[0]) { + vec- [x] *= scale_compensate- [x][1]; + } + else { + if ((abs(1.0f - scale_compensate- [x]- [x]) > abs(1.0f - scale_compensate- [x]- [x])) && sclipy[0]) { + vec- [x] *= scale_compensate- [x][0]; + } + else { + vec- [x] *= scale_compensate- [x][1]; + } + } + clipy = true; + } + + /* just idea to keep scaling uniform in aspect + if (sclipx- [x] || sclipx- [x] || sclipy- [x] || sclipy[1]) { + mul_v2_fl(vec, min_ffff(scale_compensate- [x]- [x], scale_compensate- [x]- [x], scale_compensate- [x]- [x], scale_compensate- [x][1])); + } + */ } else { - if (min- [x] < 0.0f) + if (min- [x] < 0.0f) { vec- [x] -= min[0]; - else if (max- [x] > t->aspect[0]) + clipx = true; + } + else if (max- [x] > t->aspect[0]) { vec- [x] -= max- [x] - t->aspect[0]; - else - clipx = 0; + clipx = true; + } - if (min- [x] < 0.0f) + if (min- [x] < 0.0f) { vec- [x] -= min[1]; - else if (max- [x] > t->aspect[1]) + clipy = true; + } + if (max- [x] > t->aspect[1]) { vec- [x] -= max- [x] - t->aspect[1]; - else - clipy = 0; + clipy = true; + } } return (clipx || clipy); ``` This just tries to solve a couple of issues I found with the clipping code: - clip minx/miny not working (if center/cursor is 'in right side') - clip doesnt allow for cursor being outside of UV bounds (or directly on the bounds like in this report) [the paste allows for this] - when scaling and runnning into clipmax first, then scale further and run into clipmin after --> pop to clipmin - also wasnt sure if it is a good idea to scale further on other axis after running into one clipping border [making the scale non-uniform in aspect] - which is the case in current code. There is a small snippet in the paste that could prevent this This is obviously very rough and could propably be simplified [its more like working pseudo code...]
Author

Wow Philipp! Really fantastic start.

In regard to non-uniform scaling (changing scaling aspect ratio) - maybe this could be a menu item? As I can think of usage cases where I may want to achieve both.

Thanks.

Wow Philipp! Really fantastic start. In regard to non-uniform scaling (changing scaling aspect ratio) - maybe this could be a menu item? As I can think of usage cases where I may want to achieve both. Thanks.
Member

Added subscribers: @Jakuba, @JacquesLucke

Added subscribers: @Jakuba, @JacquesLucke
Alan Troth self-assigned this 2020-07-28 23:12:42 +02:00

Added subscriber: @Chris_Blackbourn

Added subscriber: @Chris_Blackbourn
[D14882](https://archive.blender.org/developer/D14882)

The proper fix for the last few bugs requires operating on the min/max pre-transform, not post-transform, which is a more invasive change. There will also be a bit of design input required to resolve the last few edge cases when we get around to making that change.

Also, is there a related task for Rotation? The fix for rotation is a bit more complicated and will need some design input because we might want "wall kicks" instead (see: https://tetris.fandom.com/wiki/SRS )

The proper fix for the last few bugs requires operating on the min/max **pre-transform**, not **post-transform**, which is a more invasive change. There will also be a bit of design input required to resolve the last few edge cases when we get around to making that change. Also, is there a related task for Rotation? The fix for rotation is a bit more complicated and will need some design input because we might want "wall kicks" instead (see: https://tetris.fandom.com/wiki/SRS )

This issue was referenced by bc256a4507

This issue was referenced by bc256a4507702a28b825d7784c074e040058fb46

Changed status from 'Confirmed' to: 'Resolved'

Changed status from 'Confirmed' to: 'Resolved'
Sign in to join this conversation.
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset Browser
Interest
Asset Browser Project Overview
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
EEVEE & Viewport
Interest
Freestyle
Interest
Geometry Nodes
Interest
Grease Pencil
Interest
ID Management
Interest
Images & Movies
Interest
Import Export
Interest
Line Art
Interest
Masking
Interest
Metal
Interest
Modeling
Interest
Modifiers
Interest
Motion Tracking
Interest
Nodes & Physics
Interest
OpenGL
Interest
Overlay
Interest
Overrides
Interest
Performance
Interest
Physics
Interest
Pipeline, Assets & IO
Interest
Platforms, Builds & Tests
Interest
Python API
Interest
Render & Cycles
Interest
Render Pipeline
Interest
Sculpt, Paint & Texture
Interest
Text Editor
Interest
Translations
Interest
Triaging
Interest
Undo
Interest
USD
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Interest
Video Sequencer
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Blender 2.8 Project
Legacy
Milestone 1: Basic, Local Asset Browser
Legacy
OpenGL Error
Meta
Good First Issue
Meta
Papercut
Meta
Retrospective
Meta
Security
Module
Animation & Rigging
Module
Core
Module
Development Management
Module
EEVEE & Viewport
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline, Assets & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Priority
High
Priority
Low
Priority
Normal
Priority
Unbreak Now!
Status
Archived
Status
Confirmed
Status
Duplicate
Status
Needs Info from Developers
Status
Needs Information from User
Status
Needs Triage
Status
Resolved
Type
Bug
Type
Design
Type
Known Issue
Type
Patch
Type
Report
Type
To Do
No Milestone
No project
No Assignees
7 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender#50398
No description provided.