Skip to content

Instantly share code, notes, and snippets.

@Schlechtwetterfront
Last active December 25, 2015 01:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Schlechtwetterfront/6896696 to your computer and use it in GitHub Desktop.
Save Schlechtwetterfront/6896696 to your computer and use it in GitHub Desktop.
This is a small python script to speed up texturing using Marmoset Toolbag. After dropping either the Gloss map or the Specular map on a .bat file this script will find the respective other map and then proceed to copy the Gloss map to the Specular map's alpha channel. Only tested with .tga files. It should work with other files which have alpha…
python gloss.py %1
exit
# Gloss Map to Spec Alpha
# Code Copyright (C) Benedikt Schatz 2013
# GNU General Public License http://www.gnu.org/licenses/.
# Usage:
# Drag and drop either the specular map (has to end in 's', 'spec' or 'specular' before the extension) or
# the gloss map (has to end in 'g' or 'gloss') onto the .bat file. If you have your .py files as executables
# it might be possible to directly drop the .tga files onto the .py.
# Requires:
# Python 2.6 +
# PIL (Python Imaging Library)
import sys
import os
import glob
import Image
ENDINGS_SPEC = ('s', 'spec', 'specular')
ENDINGS_GLOSS = ('g', 'gloss')
def get_spec_map(gloss_map_sans_end):
for filename in glob.glob('{0}*'.format(gloss_map_sans_end)):
sans_ext, ext = os.path.splitext(filename)
if sans_ext.split('_')[-1] in ENDINGS_SPEC:
return filename
print 'Failed to find spec map for {0}'.format(gloss_map_sans_end)
def get_gloss_map(spec_sans_end):
for filename in glob.glob('{0}*'.format(spec_sans_end)):
sans_ext, ext = os.path.splitext(filename)
if sans_ext.split('_')[-1] in ENDINGS_GLOSS:
return filename
print 'Failed to find gloss map for {0}'.format(spec_sans_end)
def set_spec_alpha(gloss, spec):
print gloss, spec
glossmap = Image.open(gloss)
glossmap.load()
specmap = Image.open(spec)
gloss_layer = glossmap.split()[0]
specmap.putalpha(gloss_layer)
specmap.save(spec)
def main():
if len(sys.argv) < 2:
return
_, filename = os.path.split(sys.argv[1])
sans_extension, _ = os.path.splitext(filename)
ending = sans_extension.split('_')[-1]
sans_ending = ending[:-1]
ending = ending[-1]
print ending
if ending in ENDINGS_SPEC:
gloss_map = get_gloss_map(sans_ending)
spec_map = filename
elif ending in ENDINGS_GLOSS:
spec_map = get_spec_map(sans_ending)
gloss_map = filename
else:
return
if (not spec_map) or (not gloss_map):
return
set_spec_alpha(gloss_map, spec_map)
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment