Fix T37509: regression in smart-uv island orientation

This commit is contained in:
Campbell Barton 2014-04-03 22:03:53 +11:00
parent 5770d691bb
commit 0ebade55fc
Notes: blender-bot 2023-02-14 11:34:38 +01:00
Referenced by issue #37509, Smart UV Project not working properly
Referenced by issue #37509, Smart UV Project not working properly
1 changed files with 17 additions and 6 deletions

View File

@ -232,17 +232,28 @@ def islandIntersectUvIsland(source, target, SourceOffset):
return 0 # NO INTERSECTION
def rotate_uvs(uv_points, angle):
if angle != 0.0:
mat = Matrix.Rotation(angle, 2)
for uv in uv_points:
uv[:] = mat * uv
def optiRotateUvIsland(faces):
uv_points = [uv for f in faces for uv in f.uv]
angle = geometry.box_fit_2d(uv_points)
if angle != 0.0:
mat = Matrix.Rotation(angle, 2)
i = 0 # count the serialized uv/vectors
for f in faces:
for j, k in enumerate(range(i, len(f.v) + i)):
f.uv[j][:] = mat * uv_points[k]
i += len(f.v)
rotate_uvs(uv_points, angle)
# orient them vertically (could be an option)
minx, miny, maxx, maxy = boundsIsland(faces)
w, h = maxx - minx, maxy - miny
if h < w:
from math import pi
angle = pi / 2.0
rotate_uvs(uv_points, angle)
# Takes an island list and tries to find concave, hollow areas to pack smaller islands into.