State Selectors#
Configuration du template#
import hou
import viewerstate.utils as su
class State(object):
def __init__(self, state_name, scene_viewer):
self.state_name = state_name
self.scene_viewer = scene_viewer
def onSelection(self, kwargs):
""" Called when a selector has selected something
"""
selection = kwargs["selection"]
state_parms = kwargs["state_parms"]
node = kwargs["node"]
geo = node.geometry()
sel = selection.selections()
selpts = sel[0].points(geo)
#print(selpts)
for pt in selpts:
print(pt.number())
# Must return True to accept the selection
return False
def onStopSelection(self, kwargs):
""" Called when a bound selector has been terminated
"""
state_parms = kwargs["state_parms"]
self.log(state_parms)
def createViewerStateTemplate():
""" Mandatory entry point to create and return the viewer state
template to register. """
state_typename = kwargs["type"].definition().sections()["DefaultState"].contents()
state_label = "Lightattach::1.0"
state_cat = hou.sopNodeTypeCategory()
template = hou.ViewerStateTemplate(state_typename, state_label, state_cat)
template.bindFactory(State)
template.bindIcon(kwargs["type"].icon())
template.bindGeometrySelector(
name="pointselect",
prompt="Select the points on which you want to attach light",
quick_select=False,
use_existing_selection=True,
geometry_types=[hou.geometryType.Points],
# primitive_types=hou.primType.Polygon,
allow_other_sops=False
)
return template
Contraindre les lumières#
import hou
import viewerstate.utils as su
class State(object):
def __init__(self, state_name, scene_viewer):
self.state_name = state_name
self.scene_viewer = scene_viewer
def onSelection(self, kwargs):
""" Called when a selector has selected something
"""
selection = kwargs["selection"]
state_parms = kwargs["state_parms"]
node = kwargs["node"]
obj = hou.node("/obj")
geo = node.geometry()
sel = selection.selections()
selpts = sel[0].points(geo)
#print(selpts)
path = node.path()
offset = node.parm("offsetY").path()
lgtlist=[]
for pt in selpts:
number = pt.number()
light = obj.createNode("hlight::2.0", str(node) + "_lgt_" + str(number))
lgtlist.append(light)
expX = f"point('{path}', {number}, 'P', 0)"
expY = f"point('{path}', {number}, 'P', 1)+ch({offset})"
expZ = f"point('{path}', {number}, 'P', 2)"
light.parm("tx").setExpression(expX)
light.parm("ty").setExpression(expY)
light.parm("tz").setExpression(expZ)
# collapse into subnet
subnet = obj.collapseIntoSubnet(lgtlist, str(node) + '_lgt')
subnet.layoutChildren()
# Must return True to accept the selection
return False
def onStopSelection(self, kwargs):
""" Called when a bound selector has been terminated
"""
state_parms = kwargs["state_parms"]
self.log(state_parms)
def createViewerStateTemplate():
""" Mandatory entry point to create and return the viewer state
template to register. """
state_typename = kwargs["type"].definition().sections()["DefaultState"].contents()
state_label = "Lightattach::1.0"
state_cat = hou.sopNodeTypeCategory()
template = hou.ViewerStateTemplate(state_typename, state_label, state_cat)
template.bindFactory(State)
template.bindIcon(kwargs["type"].icon())
template.bindGeometrySelector(
name="pointselect",
prompt="Select the points on which you want to attach light",
quick_select=False,
use_existing_selection=True,
geometry_types=[hou.geometryType.Points],
# primitive_types=hou.primType.Polygon,
secure_selection=hou.secureSelectionOption.Off,
allow_other_sops=False
)
return template