@@ -18,7 +18,7 @@ def __init__(self, x, y, texture_data):
1818 self .texture_data = texture_data
1919
2020class TextureAtlas :
21- def __init__ (self , name , width , height , max_width , max_height , margin = 1 , square = True ):
21+ def __init__ (self , name , width , height , max_width , max_height , margin = 1 , square = True , output_scale = 1.0 ):
2222 self .name = name
2323 self .width = width
2424 self .height = height
@@ -28,12 +28,13 @@ def __init__(self, name, width, height, max_width, max_height, margin=1, square=
2828 self .square = square
2929 self .texture_slots = []
3030 self .create_new_slot (self .margin , self .margin )
31+ self .output_scale = output_scale
3132
3233 def create_new_slot (self , x , y ):
3334 texture_slot = TextureSlot (x , y , None )
3435 self .texture_slots .append (texture_slot )
35- # self.texture_slots = sorted(self.texture_slots, key=lambda slot: slot.x, reverse=True)
36- # self.texture_slots = sorted(self.texture_slots, key=lambda slot: slot.y, reverse=False)
36+ self .texture_slots = sorted (self .texture_slots , key = lambda slot : slot .x , reverse = True )
37+ self .texture_slots = sorted (self .texture_slots , key = lambda slot : slot .y , reverse = False )
3738 return texture_slot
3839
3940 def cleanup_slots (self ):
@@ -70,22 +71,7 @@ def get_texture_bounds(obj, output_scale):
7071
7172 bounds_rel = [bottom_left_x , bottom_left_y , top_right_x , top_right_y ]
7273 bounds_px = [img_size [0 ] * bottom_left_x , img_size [1 ] * bottom_left_y , img_size [0 ] * top_right_x , img_size [1 ] * top_right_y ]
73- # top_left_x = 1.0
74- # top_left_y = 1.0
75- # bottom_right_x = 0.0
76- # bottom_right_y = 0.0
77- # for uv in uvs:
78- # if uv.uv[0] < top_left_x:
79- # top_left_x = uv.uv[0]
80- # if uv.uv[1] < top_left_y:
81- # top_left_y = uv.uv[1]
82- # if uv.uv[0] > bottom_right_x:
83- # bottom_right_x = uv.uv[0]
84- # if uv.uv[1] > bottom_right_y:
85- # bottom_right_y = uv.uv[1]
86-
87- # bounds_rel = [top_left_x, top_left_y, bottom_right_x, bottom_right_y]
88- # bounds_px = [img_size[0] * top_left_x, img_size[1] * top_left_y, img_size[0] * bottom_right_x, img_size[1] * bottom_right_y]
74+
8975 for i ,value in enumerate (bounds_px ):
9076 bounds_px [i ] = int (bounds_px [i ] * output_scale )
9177 width = (bounds_px [2 ] - bounds_px [0 ])
@@ -143,14 +129,13 @@ def texture_intersects_others(texture_data, texture_slot, atlas_data):
143129 for line_b in lines_b :
144130 i = intersect_line_line_2d (line_a [0 ], line_a [1 ], line_b [0 ], line_b [1 ])
145131 if i != None :
146- print (texture_data .texture_object .name , " -- " , "(" , texture_slot .x , "," , texture_slot .y ,")" , "w: " , texture_data .width , "h: " , texture_data .height ,"-->" ,slot .texture_data .texture_object .name , " -- " , "(" , slot .x , "," , slot .y ,")" , "w: " , slot .texture_data .width , "h: " , slot .texture_data .height )
147132 return True
148133
149134 return False
150135
151136 @staticmethod
152137 def create_texture_atlas_data (texture_data_list , atlas_name , width , height , max_width , max_height , margin = 0 , square = True , output_scale = 1.0 ):
153- atlas_data = TextureAtlas (atlas_name , width , height , max_width , max_height , margin , square )
138+ atlas_data = TextureAtlas (atlas_name , width , height , max_width , max_height , margin , square , output_scale )
154139 objects = []
155140 for texture_data in texture_data_list :
156141 objects .append (texture_data .texture_object )
@@ -177,8 +162,8 @@ def create_texture_atlas_data(texture_data_list, atlas_name, width, height, max_
177162 atlas_data .width *= 2
178163
179164 if atlas_data .width >= atlas_data .max_width and atlas_data .height >= atlas_data .max_height :
180- output_scale *= 0.95
181- texture_data_list = TextureAtlasGenerator .get_sorted_texture_data (objects , output_scale )
165+ atlas_data . output_scale *= 0.95
166+ texture_data_list = TextureAtlasGenerator .get_sorted_texture_data (objects , atlas_data . output_scale )
182167 print ("Max Atlas size of " , atlas_data .width ,"x" ,atlas_data .height ," reached. Decreasing texture size and restarting generation." )
183168 else :
184169 print ("Current Atlas size of " , atlas_data .width ,"x" ,atlas_data .height ," is to small. Increasing Atlas size and restarting generation." )
@@ -187,7 +172,6 @@ def create_texture_atlas_data(texture_data_list, atlas_name, width, height, max_
187172 if restart_generation :
188173 break
189174 if not tex_intersects_other :
190- print (texture_data .texture_object .name , " -- " , "(" , texture_slot .x , "," , texture_slot .y ,")" , "width: " , texture_data .width , "height: " , texture_data .height )
191175 texture_slot .texture_data = texture_data
192176 x1 = texture_slot .x + texture_data .width
193177 y1 = texture_slot .y
0 commit comments