Skip to content

Commit

Permalink
restored common files (alshaders ui utilities)
Browse files Browse the repository at this point in the history
  • Loading branch information
jonahf committed Jul 24, 2018
1 parent 78bb960 commit 8ba78c7
Show file tree
Hide file tree
Showing 3 changed files with 132 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -72,16 +72,20 @@ message("AETemplates will be installed to: \n\t${AE_INSTALL_DIR}")
message("SPDL will be installed to: \n\t${SPDL_INSTALL_DIR}")
message("Katana Args will be installed to: \n\t${ARGS_INSTALL_DIR}")

# Include common files
include_directories(common)
include_directories(${CMAKE_SOURCE_DIR})

# Set the list of subdirectories to recurse into to find stuff to build
set(SUBDIRECTORIES
cryptomatte
common
)

# define shader build function
function(build_shader)
foreach(SHADER ${ARGV})
set(SRC ${SHADER}.cpp ../common/alUtil.cpp ../common/Color.cpp)
set(UI ${CMAKE_CURRENT_SOURCE_DIR}/${SHADER}.ui)
set(MTD ${CMAKE_CURRENT_BINARY_DIR}/${SHADER}.mtd)
set(AE ${CMAKE_CURRENT_BINARY_DIR}/${SHADER}Template.py)
Expand Down
3 changes: 3 additions & 0 deletions common/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
set(UI alShaders.py)

install(FILES ${UI} DESTINATION ${AE_INSTALL_DIR})
125 changes: 125 additions & 0 deletions common/alShaders.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
import pymel.core as pm
from mtoa.ui.ae.shaderTemplate import ShaderAETemplate

UI = {
'float': pm.attrFieldSliderGrp,
'rgb': pm.attrColorSliderGrp,
}

class Param:
name = ''
label = ''
annotation = ''
ptype = ''
presets = None
precision = 4

def __init__(self, n, l, a, p, presets=None, precision=4):
self.name = n
self.label = l
self.annotation = a
self.ptype = p
self.presets = presets
self.precision = precision

def setPresetFlt(ctrl, value):
attr = pm.attrFieldSliderGrp(ctrl, query=True, attribute=True)
pm.setAttr(attr, value)

def setPresetRgb(ctrl, value):
attr = pm.attrColorSliderGrp(ctrl, query=True, attribute=True)
pm.setAttr(attr + 'R', value[0])
pm.setAttr(attr + 'G', value[1])
pm.setAttr(attr + 'B', value[2])

class alShadersTemplate(ShaderAETemplate):

def customCreateFlt(self, attr):
# print "creating %s" % attr
pname = attr.split('.')[-1]
ptype = self.params[pname].ptype
plabel = self.params[pname].label
pann = self.params[pname].annotation
presets = self.params[pname].presets
precision = self.params[pname].precision
controlName = pname + 'Ctrl'
l = plabel
if presets is not None:
l += ' <span>&#8801;</span>' # fix unicode problem in Windows using html
pm.attrFieldSliderGrp(controlName, attribute=attr, label=l, annotation=pann, precision=precision)
if presets is not None:
# pm.attrFieldSliderGrp(controlName, edit=True)
# pm.popupMenu()
# for k in sorted(presets, key=presets.get):
# pm.menuItem(label=k, command=pm.Callback(setPresetFlt, controlName, presets[k]))
attrChildren = pm.layout(controlName, query=True, childArray=True)
pm.popupMenu(button=1, parent=attrChildren[0])
for k in sorted(presets, key=presets.get):
pm.menuItem(label=k, command=pm.Callback(setPresetFlt, controlName, presets[k]))


def customUpdateFlt(self, attr):
# print "updating attr %s" % attr
pname = attr.split('.')[-1]
ptype = self.params[pname].ptype
controlName = pname + 'Ctrl'
pm.attrFieldSliderGrp(controlName, edit=True, attribute=attr)

def customCreateRgb(self, attr):
pname = attr.split('.')[-1]
ptype = self.params[pname].ptype
plabel = self.params[pname].label
pann = self.params[pname].annotation
presets = self.params[pname].presets
controlName = pname + 'Ctrl'

l = plabel
if presets is not None:
l += ' <span>&#8801;</span>' # fix unicode problem in Windows using html
pm.attrColorSliderGrp(controlName, attribute=attr, label=l, annotation=pann)
if presets is not None:
# pm.attrColorSliderGrp(controlName, edit=True)
# pm.popupMenu()
attrChildren = pm.layout(controlName, query=True, childArray=True)
pm.popupMenu(button=1, parent=attrChildren[0])
for k in sorted(presets):
pm.menuItem(label=k, command=pm.Callback(setPresetRgb, controlName, presets[k]))

def customUpdateRgb(self, attr):
pname = attr.split('.')[-1]
ptype = self.params[pname].ptype
controlName = pname + 'Ctrl'
pm.attrColorSliderGrp(controlName, edit=True, attribute=attr)

def addCustomFlt(self, param):
self.addCustom(param, self.customCreateFlt, self.customUpdateFlt)

def addCustomRgb(self, param):
self.addCustom(param, self.customCreateRgb, self.customUpdateRgb)

def addRemapControls(self):
self.beginLayout('Remap', collapse=True)
self.addControl('RMPinputMin', label='Input min')
self.addControl('RMPinputMax', label='Input max')

self.beginLayout('Contrast', collapse=False)
self.addControl('RMPcontrast', label='Contrast')
self.addControl('RMPcontrastPivot', label='Pivot')
self.endLayout() # end Contrast

self.beginLayout('Bias and gain', collapse=False)
self.addControl('RMPbias', label='Bias')
self.addControl('RMPgain', label='Gain')
self.endLayout() # end Bias and gain

self.addControl('RMPoutputMin', label='Output min')
self.addControl('RMPoutputMax', label='Output max')

self.beginLayout('Clamp', collapse=False)
self.addControl('RMPclampEnable', label='Enable')
self.addControl('RMPthreshold', label='Expand')
self.addControl('RMPclampMin', label='Min')
self.addControl('RMPclampMax', label='Max')
self.endLayout() # end Clamp

self.endLayout() # end Remap

0 comments on commit 8ba78c7

Please sign in to comment.