Skip to content
This repository was archived by the owner on Mar 30, 2024. It is now read-only.

Commit 5438446

Browse files
committed
Fixed crash when gloss map didn't have alpha map
1 parent afedec3 commit 5438446

2 files changed

Lines changed: 23 additions & 13 deletions

File tree

FastValveMaterial.py

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2727
SOFTWARE. """
2828

29+
from typing import Match
2930
from PIL import Image, ImageChops, ImageOps
3031
import os
3132
import sys
@@ -38,8 +39,8 @@
3839
import shutil
3940

4041
vtf_lib = VTFLib.VTFLib()
41-
42-
print("FastValveMaterial (v1207)\n")
42+
version = "1208"
43+
print("FastValveMaterial (v"+version+")\n")
4344

4445
f = open("config.md", 'r') # Read the config file (Actual line - 1)
4546
config = f.read().splitlines()
@@ -52,6 +53,8 @@
5253
config_export_images = eval(config[17])
5354
config_material_setup = config[19]
5455
config_debug_messages = eval(config[21])
56+
config_print_config = eval(config[23])
57+
mat_count = int(0)
5558

5659
def 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

120123
def 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

223227
def 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:\nCouldn't locate files with correct naming scheme, throwing FileNotFoundError!")
273+
debug("[FVM] [ERROR] v"+version+" terminated with exit code -1:\nCouldn'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)

config.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,6 @@ False
1919
# Material setup ("gloss", "rough")
2020
rough
2121
# Print debug messages (False/True)
22-
True
22+
True
23+
# Print config file (False/True)
24+
False

0 commit comments

Comments
 (0)