fixed crash in mergetextures

This commit is contained in:
Killergnom
2025-01-25 23:16:01 +01:00
parent 2c9d8068ca
commit 9420ce921c
6 changed files with 57 additions and 46 deletions

View File

@@ -65,6 +65,8 @@ def process_textures(input_files):
material_count = len(textures)
print(f"Detected {material_count} Materials to process.")
failed_converts = 0
# Process each material group
for index, (material, files) in enumerate(textures.items()):
@@ -77,7 +79,6 @@ def process_textures(input_files):
mask_file = files.get('Mask')
missing_files = []
failed_converts = 0
# Check for required textures
if not basecolor_file:
@@ -86,15 +87,19 @@ def process_textures(input_files):
missing_files.append('Normal')
if not (rma_file or orm_file):
missing_files.append('RMA or ORM')
# Report missing files if any
# Report missing files if any
if missing_files:
print(f"({index+1}/{material_count}) Skipping {material}: missing {', '.join(missing_files)}")
print(f"({index + 1}/{material_count}) Skipping {material}: missing {', '.join(missing_files)}")
failed_converts += 1
else:
# Convert to BCR/NMO format
convert_to_bcr_nmo(material, basecolor_file, normal_file, rma_file, orm_file, emissive_file, opacity_file, mask_file, output_folder)
print(f"({index+1}/{material_count}) {material}: Successfully converted.")
# Convert to BCR/NMO format and track success or failure
if convert_to_bcr_nmo(material, basecolor_file, normal_file, rma_file, orm_file, emissive_file, opacity_file, mask_file, output_folder):
print(f"({index + 1}/{material_count}) {material}: Successfully converted.")
else:
failed_converts += 1 # Increment counter here if conversion fails
print(f"({index + 1}/{material_count}) Skipping {material}: input file sizes do not match.")
print(f"+++{material_count - failed_converts} of {material_count} materials successfully converted+++")
time.sleep(3)
@@ -106,6 +111,8 @@ def convert_to_bcr_nmo(material, basecolor_file, normal_file, rma_file, orm_file
if rma_file:
rma_img = Image.open(rma_file).convert('RGBA')
if not (basecolor_img.size == normal_img.size == rma_img.size):
return False
# BCR conversion
bcr_img = Image.merge('RGBA', (basecolor_img.split()[0], basecolor_img.split()[1], basecolor_img.split()[2], rma_img.split()[0])) # Use Roughness (Alpha from RMA/ORM)
bcr_img.save(os.path.join(output_folder, f"{material}_BCR.png"))
@@ -114,6 +121,8 @@ def convert_to_bcr_nmo(material, basecolor_file, normal_file, rma_file, orm_file
nmo_img.save(os.path.join(output_folder, f"{material}_NMO.png"))
elif orm_file:
rma_img = Image.open(orm_file).convert('RGBA')
if not (basecolor_img.size == normal_img.size == rma_img.size):
return False
# BCR conversion
bcr_img = Image.merge('RGBA', (basecolor_img.split()[0], basecolor_img.split()[1], basecolor_img.split()[2], rma_img.split()[1])) # Use Roughness (Alpha from RMA/ORM)
bcr_img.save(os.path.join(output_folder, f"{material}_BCR.png"))
@@ -132,6 +141,8 @@ def convert_to_bcr_nmo(material, basecolor_file, normal_file, rma_file, orm_file
if mask_file:
mask_img = Image.open(mask_file).convert('L')
mask_img.save(os.path.join(output_folder, f"{material}_MASK.png"))
return True
if __name__ == "__main__":
if len(sys.argv) < 2:
print("Usage: drag and drop texture files onto the script")