26 lines
1.3 KiB
Python
26 lines
1.3 KiB
Python
"""Convert supplied glossiness data to roughness; configure GPU-ready imports."""
|
|
from pathlib import Path
|
|
from PIL import Image, ImageOps
|
|
import re
|
|
|
|
ROOT = Path(__file__).resolve().parents[1]
|
|
DIRECTORY = ROOT / 'assets/textures/operators'
|
|
for source in DIRECTORY.glob('*_Glossiness.png'):
|
|
destination = source.with_name(source.name.replace('_Glossiness', '_Roughness'))
|
|
if not destination.exists():
|
|
# Linear data channel conversion: roughness = 1 - glossiness, no gamma.
|
|
with Image.open(source) as image:
|
|
ImageOps.invert(image.getchannel('R') if 'R' in image.getbands() else image.convert('L')).save(destination)
|
|
for source in DIRECTORY.glob('*.png'):
|
|
metadata = source.with_suffix('.png.import')
|
|
if not metadata.exists():
|
|
continue # Run again after Godot creates the first import record.
|
|
content = metadata.read_text(encoding='utf-8')
|
|
params = {'compress/mode': '2', 'mipmaps/generate': 'true',
|
|
'compress/normal_map': '1' if '_Normal' in source.name else '2',
|
|
'process/hdr_as_srgb': 'false', 'process/size_limit': '4096'}
|
|
for key, value in params.items():
|
|
content = re.sub(r'^' + re.escape(key) + r'=.*$', key + '=' + value, content, flags=re.M)
|
|
metadata.write_text(content, encoding='utf-8')
|
|
print('Operator texture maps ready')
|