0

I am trying to scale UVs. I have the percentage of the 0-1 UV space that the current UV shell takes up and the percentage that I need the shell to take up. What is the best way to do that?

I have tried using pm.polyEditUVs() but I can't come up with a formula to convert the percentages to proper scale values.

If I am being vague please tell me and I will try to be more specific.

EDIT:

I apologize, my question was incomplete.

The scale values in pm.polyEditUVs() don't scale by area, they scale using U and V values independently.

If it was scaling by area then dividing the old by the new would produce the proper scale values but here it does not. For example:

A = 1.0 #Normalized percentage of the total UV area our UVs currently occupy.
B = 0.25  #Normalized percentage of the total UV area we want our UVs to occupy.

#If we could scale the area directly using a single number then the following would work.
ScaleValue = B\A
0.25 = 0.25\1.0

However if we plug that value into the scaleU and scaleV keyword args in pm.polyEditUVs() then you are reducing the area on an exponential scale rather than a linear.

#continuing with the previous example
#for the sake of ease of predictability regarding the math I am assuming our UVs are a square for this example, however U and V will rarely be the same value.
U = 1.0 #linear distance  actual value (percentage value would be 100% (1.0))
V = 1.0 #linear distance. actual value (percentage value would be 100% (1.0))
Area = 1*1 #actual area value. (percentage value would be 100% (1.0))

newU = U * scaleValue
0.25 = 1.0 * 0.25

newV = V * scaleValue
0.25 = 1.0 * 0.25

newArea = newU * newV
0.0625 = 0.25 * 0.25

The end result, rather than making the area 25% of the original size actually made it 6.25% of the original size. How do we take into account that extra order of magnitude?

I apologize for the pedantic nature of this example but I wanted to make sure my example was clear, if it isn't I will add more.

TheBeardedBerry
  • 1,636
  • 5
  • 20
  • 30

2 Answers2

1

If the goal is to go from a certain % of UV space to a different %, just scale by the ratio of the current % to the desired %. If you current area is 45 % of the uv space and you'd like it to be 90%, you'd scale by 90/45 = by 2. If you're currently at 75 % and want to be at 25%, scale by 25/75, or .33333.

theodox
  • 12,028
  • 3
  • 23
  • 36
  • I apologize, I realized that I didn't properly explain my question. Its been updated. – TheBeardedBerry Nov 17 '13 at 09:44
  • If you want to make a 1,1 rectangle to a .5, .5 rectangle , you are scaling the area down to 25% of its original value. If you want to scale the 1,1 rectangle to 50% of it's areas, you'd need to take the square root of the scale factor: in that case, sqrt(.5) = .707 – theodox Nov 18 '13 at 19:49
  • Thank you, looking at this in retrospect it's incredibly simple. I must have been staring at my code for too long. – TheBeardedBerry Nov 19 '13 at 03:19
0

From wikipedia:

Precentage is a number or ratio expressed as a fraction of 100. ... For example, 45% (read as "forty-five percent") is equal to 45/100, or 0.45.

So per definition ten percent is 0.10 units a so the scale of ten percent is 0.10.

joojaa
  • 4,354
  • 1
  • 27
  • 45