@@ -71,6 +71,7 @@ def build_atlases_hades(source_dir, target_dir, deppth2_pack=True, include_hulls
7171 hulls = {}
7272 namemap = {}
7373 scaleRatioMap = {}
74+ manifestHulls = {}
7475
7576 temp_dir = tempfile .mkdtemp ()
7677 temp_name_mapping = {}
@@ -87,6 +88,7 @@ def build_atlases_hades(source_dir, target_dir, deppth2_pack=True, include_hulls
8788 namemap [rel_path ] = str (file_path )
8889
8990 scaleRatioMap [rel_path ] = get_scale_ratio (file_path )
91+ manifestHulls [rel_path ] = get_hull_from_manifest (file_path )
9092
9193 # Create temporary images with unique names for PyTexturePacker to not override when creating the json file
9294 for rel_path , original_path in namemap .items ():
@@ -120,7 +122,7 @@ def build_atlases_hades(source_dir, target_dir, deppth2_pack=True, include_hulls
120122 with open (f'{ basename } { index } .json' , 'w' ) as f :
121123 json .dump (original_data , f , indent = 2 )
122124
123- atlases .append (transform_atlas (target_dir , basename , f'{ basename } { index } .json' , namemap , hulls , source_dir , manifest_paths , scaleRatioMap = scaleRatioMap ))
125+ atlases .append (transform_atlas (target_dir , basename , f'{ basename } { index } .json' , namemap , hulls , source_dir , manifest_paths , scaleRatioMap = scaleRatioMap , manifestHulls = manifestHulls ))
124126 os .remove (f'{ basename } { index } .json' )
125127 index += 1
126128
@@ -161,7 +163,15 @@ def get_scale_ratio(path):
161163 return image_manifest .get ("scaleRatio" , default_scale )
162164 return default_scale
163165
164- @requires ('scipy.spatial' )
166+ def get_hull_from_manifest (path ):
167+ default_hull = []
168+ image_manifest_path = os .path .splitext (path )[0 ] + ".json"
169+ if os .path .exists (image_manifest_path ):
170+ with open (image_manifest_path , 'r' ) as f :
171+ image_manifest = json .load (f )
172+ return image_manifest .get ("hull" , default_hull )
173+ return default_hull
174+
165175def get_hull_points (path ):
166176 try :
167177 import scipy .spatial
@@ -200,7 +210,7 @@ def find_files(source_dir):
200210 file_list .append (path )
201211 return file_list
202212
203- def transform_atlas (target_dir , basename , filename , namemap , hulls = {}, source_dir = '' , manifest_paths = [], scaleRatioMap = {}):
213+ def transform_atlas (target_dir , basename , filename , namemap , hulls = {}, source_dir = '' , manifest_paths = [], scaleRatioMap = {}, manifestHulls = [] ):
204214 with open (filename ) as f :
205215 ptp_atlas = json .load (f )
206216 frames = ptp_atlas ['frames' ]
@@ -231,6 +241,8 @@ def transform_atlas(target_dir, basename, filename, namemap, hulls={}, source_di
231241 subatlas ['isMip' ] = False
232242 subatlas ['isAlpha8' ] = False
233243 subatlas ['hull' ] = transform_hull (hulls .get (texture_name , []), subatlas ['topLeft' ], (subatlas ['rect' ]['width' ], subatlas ['rect' ]['height' ]))
244+ if len (subatlas ['hull' ]) == 0 :
245+ subatlas ['hull' ] = manifestHulls .get (texture_name , [])
234246 atlas .subAtlases .append (subatlas )
235247
236248 atlas .export_file (f'{ os .path .splitext (filename )[0 ]} .atlas.json' )
0 commit comments