I'll show you how to implement a gradient picker like Substance Designer in Houdini that Ando announced at the PySide Study Group the other day. Introduction of Ando's gradation picker, commentary article
When actually used, the gradation picked up by the picker is applied to the lamp parameters as shown in the figure below. In the figure below, the image is loaded into the network editor, but you can get the color anywhere on the screen.
% HOMEDRIVE %% HOMEPATH% \ Documents \ houdini version \ scripts \ python
and it will be recognized automatically (create it if it doesn't exist).-** When implementing on HDA ** Go to the HDA ** Type Properties **> ** Scripts tab ** and change the ** Event Handler ** to ** Python Module **. This will activate the Python code field on the right, where you can enter the code __ to apply the gradient to the __ramp parameters below.
-** When implementing in the parameter of the existing node ** Click ** Windows **> ** Python Source Editor ** in the Houdini menu to launch the Python Source Editor and enter the code ** to apply the gradient to the ** ramp parameters below in the code entry field.
# -*- coding: utf-8 -*-
import hou
from PySide2.QtCore import Qt
from gradationPicker import ColorPick
class _GCProtector(object):
widgets = []
def rampColorPicker(parm, threshold=0.05):
def setRampColor(colors):
#The argument colors are[Gradient position,color]List containing
curveKeys = []
curveValues = []
#Divide the two-dimensional list into two parts, curveKeys and curveValues.
for pos, color in colors:
curveKeys.append(pos)
#2 because the color space of PySide is sRGB and Houdini is linear.Square and convert
curveValues.append([(ch / 255.0) ** 2.2 for ch in color])
linears = [hou.rampBasis.Linear] * len(colors)
ramp = hou.Ramp(linears, curveKeys, curveValues)
parm.set(ramp)
picker = ColorPick()
#Displayed in the foreground so that the focus does not shift
picker.setWindowFlags(Qt.WindowStaysOnTopHint)
#Set a threshold for how much color difference is identified
picker.threshold = threshold
#Make the picker's main window fill the screen
picker.showFullScreen()
#Execute a function when the mouse is released
picker.getGradation.connect(setRampColor)
#Processing to avoid freeing memory and disappearing immediately when displayed normally
_GCProtector.widgets.append(picker)
-** For HDA **
hou.phm().rampColorPicker(kwargs['node'].parm('ramp'), threshold=0.05)
-** For nodes that already exist **
hou.session.rampColorPicker(kwargs['node'].parm('ramp'), threshold=0.05)
parm ('ramp')
to the name of the target lamp parameter.
The lower the threshold value, the higher the accuracy, but the more keys there are.If you want to set an icon for a button, enter BUTTONS_secondary_colors in the Button Icon field and an icon like that will be added.
Now when you press the button, you'll be in gradient picker mode, so drag and pick a color.
That's how to implement a gradient picker in Houdini. PySide can do many things and is fun. By the way, by modifying the gradation picker, you can also create a function to write the curve of the lamp parameter by hand as shown below.
Recommended Posts