Skip to content

Commit

Permalink
fix for aspect ratio bug
Browse files Browse the repository at this point in the history
bug happened when there are only horizontal or vertical aspects on an atlas. Causing it to not but able to find a good starting spot
  • Loading branch information
leukbaars authored Jul 18, 2020
1 parent d3e88d0 commit 2302baf
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 11 deletions.
42 changes: 31 additions & 11 deletions DUV_HotSpot.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,28 +207,48 @@ def execute(self, context):

if is_rect is False:
#calulate ratio empty vs full
size = size / DUV_Utils.get_uv_ratio(context)
sizeratio = DUV_Utils.get_uv_ratio(context)
#prevent divide by 0:
if sizeratio == 0:
sizeratio = 1.0
size = size / sizeratio



if aspect > 1:
aspect = round(aspect)
else:
aspect = 1/(round(1/aspect))

#print(aspect)

#ASPECT LOWER THAN 1.0 = TALL
#ASPECT HIGHER THAN 1.0 = WIDE

#find closest aspect ratio in list

#2 variations depending on tall or wide

index = 0
templength = abs(atlas[0].aspect-aspect)
templength = abs(atlas[0].posaspect-aspect)
tempindex = 0
for number in atlas:
testlength = abs(number.aspect-aspect)
if testlength < templength:
templength = testlength
tempindex = index
index += 1

#wide:
if aspect >= 1.0:
for number in atlas:
testlength = abs(number.posaspect-aspect)
if testlength < templength:
templength = testlength
tempindex = index
index += 1

#tall:
if aspect < 1.0:
templength = abs((atlas[0].posaspect)-(1/aspect))
for number in atlas:
testlength = abs((number.posaspect)-(1/aspect))
if testlength < templength:
templength = testlength
tempindex = index
index += 1

#NOW MAKE LIST OF ASPECTS!
flipped = False
Expand All @@ -238,7 +258,7 @@ def execute(self, context):
aspectbucket.append(r)
if r.aspect == 1/atlas[tempindex].aspect:
aspectbucket.append(r)

#find closest size in bucket:
index = 0

Expand Down
6 changes: 6 additions & 0 deletions DUV_Utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,12 +122,17 @@ def read_atlas(context):
aspect = round(aspect)
else:
aspect = 1/(round(1/aspect))
#aspect = 1/aspect
posaspect = aspect
if posaspect < 1.0:
posaspect = 1/posaspect
#calculate size
size = face.calc_area()
size = float('%.2g' % size) #round to 2 significant digits


new_subrect.aspect = aspect
new_subrect.posaspect = posaspect
new_subrect.size = size
atlas.append(new_subrect)
return atlas
Expand Down Expand Up @@ -466,6 +471,7 @@ def square_fit(context):

class subrect:
aspect = int()
posaspect = int()
size = float()
uvcoord = list()

Expand Down

0 comments on commit 2302baf

Please sign in to comment.