2626OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2727SOFTWARE. """
2828
29+ from typing import Match
2930from PIL import Image , ImageChops , ImageOps
3031import os
3132import sys
3839import shutil
3940
4041vtf_lib = VTFLib .VTFLib ()
41-
42- print ("FastValveMaterial (v1207 )\n " )
42+ version = "1208"
43+ print ("FastValveMaterial (v" + version + " )\n " )
4344
4445f = open ("config.md" , 'r' ) # Read the config file (Actual line - 1)
4546config = f .read ().splitlines ()
5253config_export_images = eval (config [17 ])
5354config_material_setup = config [19 ]
5455config_debug_messages = eval (config [21 ])
56+ config_print_config = eval (config [23 ])
57+ mat_count = int (0 )
5558
5659def debug (message ):
5760 if config_debug_messages :
@@ -114,8 +117,8 @@ def do_exponent(gIm): # Generate the exponent map
114117 os .remove (name + "_m.vtf" )
115118 debug ("[FVM] Exponent already exists!" )
116119
117- def convert_roughness_to_gloss (mIm ): # Inverts a roughness map "mIm" to get a glossiness map
118- return ImageOps .invert (mIm )
120+ def convert_roughness_to_gloss (im ): # Inverts a roughness map "mIm" to get a glossiness map
121+ return ImageOps .invert (im . convert ( 'RGB' ) )
119122
120123def do_normal (config_midtone , nIm , gIm ):
121124 finalNormal = nIm .convert ('RGBA' )
@@ -218,6 +221,7 @@ def do_material(mName): # Create a material with the given image names
218221 f .close ()
219222 shutil .move (mName + '.vmt' , "materials/" )
220223 except :
224+ os .remove (mName + ".vmt" )
221225 debug ("[FVM] Material already exists!" )
222226
223227def export_texture (texture , path , imageFormat = None ): # Exports an image to VTF using VTFLib
@@ -266,17 +270,17 @@ def export_texture(texture, path, imageFormat=None): # Exports an image to VTF u
266270 glossSt = config_path + "/" + str (check_for_valid_files (config_path , name , config_input_name_scheme [3 ] + "." + config_input_format ))
267271 metalSt = config_path + "/" + str (check_for_valid_files (config_path , name , config_input_name_scheme [4 ] + "." + config_input_format ))
268272 except FileNotFoundError :
269- debug ("[FVM] [ERROR] Program terminated with exit code -1:\n Couldn't locate files with correct naming scheme, throwing FileNotFoundError!" )
273+ debug ("[FVM] [ERROR] v" + version + " terminated with exit code -1:\n Couldn't locate files with correct naming scheme, throwing FileNotFoundError!" )
270274 sys .exit ()
271275
272- debug ("Color:\t \t " + colorSt )
276+ print ("Color:\t \t " + colorSt )
273277 if config_input_name_scheme [1 ] != '' :
274- debug ("Occlusion:\t " + aoSt )
278+ print ("Occlusion:\t " + aoSt )
275279 else :
276- debug ("Occlusion:\t " + "None given, ignoring!" )
277- debug ("Metalness:\t " + metalSt )
278- debug ("Normal:\t \t " + normalSt )
279- debug ("Glossiness:\t " + glossSt + "\n " )
280+ print ("Occlusion:\t " + "None given, ignoring!" )
281+ print ("Metalness:\t " + metalSt )
282+ print ("Normal:\t \t " + normalSt )
283+ print ("Glossiness:\t " + glossSt + "\n " )
280284
281285 colorImage = Image .open (colorSt )
282286 if config_input_name_scheme [1 ] != '' :
@@ -301,5 +305,9 @@ def export_texture(texture, path, imageFormat=None): # Exports an image to VTF u
301305 do_normal (config_midtone , normalImage , glossImage )
302306 do_material (name )
303307 print ("[FVM] Conversion for material '" + name + "' finished, files saved to '" + config_output_path + "'\n " )
308+ mat_count += 1
304309
305- debug ("[FVM] Program terminated with exit code 0" )
310+ debug ("[FVM] v" + version + " terminated with exit code 0: All conversions finished." )
311+ if (config_print_config ):
312+ debug ("Config file dump:" )
313+ debug (config )
0 commit comments