Inheritance |
|
You will typically implement drag operations in the viewer handle onMouseEvent
handler. The example
below demonstrates how to translate the geometry bound to a viewer handle by dragging the handle’s pivot.
import hou def __init__(self, **kwargs): self.__dict__.update(kwargs) #creates the handle dragger self.handle_dragger = hou.ViewerHandleDragger("dragger") def onMouseEvent( self, kwargs ): """ Called when a gadget is being picked and dragged. """ # The handle context containing pick/locate info on the active gadget hcontext = self.handle_context # The handle parameters hparms = kwargs["handle_parms"] # Tegular mouse event info ui_event = kwargs["ui_event"] reason = ui_event.reason() if hcontext.gadget() == Handle.GADGET_PIVOT: # The pivot is used by the user to move the handle. if reason == hou.uiEventReason.Start: # Get the current translation values from the handle # parameters handle_pos = hou.Vector3(hparms["tx"]["value"], hparms["ty"]["value"], hparms["tz"]["value"]) # Start the handle translate from the current handle pivot position. self.handle_dragger.startDrag(ui_event, handle_pos) elif reason == hou.uiEventReason.Changed or reason == hou.uiEventReason.Active: # drag the bound geometry interactively (while the LMB is down). drag_values = self.handle_dragger.drag(ui_event) # Update the handle parameters with the delta position returned by # the dragger. hparms["tx"]["value"] += drag_values["delta_position"][0] hparms["ty"]["value"] += drag_values["delta_position"][1] hparms["tz"]["value"] += drag_values["delta_position"][2] # Set the handle transform matrix self.xform = hu.updateTransform(self.xform, t=[hparms["tx"]["value"], hparms["ty"]["value"], hparms["tz"]["value"]]) if reason == hou.uiEventReason.Changed: # We are done, exit the drag. self.handle_dragger.endDrag() # Consume the event return True return False
Methods ¶
__init__(name)
Creates a viewer handle dragger object.
name
A name to identify the dragger.
Methods from hou.ViewerDragger ¶
startDrag(ui_event, start_pos)
Enables the dragger for moving the mouse anywhere in the viewport from a specific position.
NOTE
When invoking startDrag
from onMouseIndirectEvent with , the dragger computes the
handle position relative to the world-space position under the mouse.
ui_event
A hou.ViewerEvent object holding UI event information. This is typically the object
Houdini passes to a python handle or python state’s onMouseEvent
.
start_pos
A hou.Vector3 object describing the start position of the drag operation. For instance, this could be a python handle pivot.
startDragAcrossFloor(ui_event, start_pos, mouse_offset)
This method enables the dragger to move the mouse along the construction plane or the viewport reference plane grid.
ui_event
A hou.ViewerEvent object holding UI event information. This is the object Houdini
passes to the python handle onMouseEvent
handler.
start_pos
A hou.Vector3 object describing the start position of the drag operation.
startDragAlongLine(ui_event, line_origin, line_dir)
Configures the dragger to move the mouse along a line defined with a start point and a direction vector. When the line is picked and the mouse is moving, the dragger will constrain the mouse movement in the direction of the line.
ui_event
A hou.ViewerEvent object holding UI event information. This is the object Houdini passes
to the python handle onMouseEvent
handler.
line_origin
A hou.Vector3 object to define the start position of the line.
line_dir
A hou.Vector3 object to define the direction the line is pointing.
startDragAlongPlane(ui_event, plane_point, plane_normal)
Configures the dragger to move the mouse along a plane defined with an origin point and a normal
vector. When the LMB
is down and the mouse is moving, the dragger will constrain the mouse
position to the plane.
ui_event
A hou.ViewerEvent object holding UI event information. This is the object Houdini passes
to the python handle onMouseEvent
handler.
plane_point
A hou.Vector3 object defining a point on the plane.
plane_normal
A hou.Vector3 object to define the plane normal.
startDragRotate(ui_event, center_pos, radius, rotate_axis, orient)
Configures the dragger to drag a “ring” around an axis.
ui_event
A hou.ViewerEvent object holding UI event information. This is the object Houdini
passes to the python handle onMouseEvent
handler.
center_pos
A hou.Vector3 object representing the center of the rotation.
radius
The radius of the rotation ring.
rotate_axis
A hou.Vector3 vector representing the axis of rotation. This is typically a normalized vector used as the rotation plane normal.
orient
A hou.Matrix3 object representing the orientation matrix of the axis.
drag(ui_event)
→ (dictionary)
Performs a drag operation based on the start
method previously called. Raises
hou.OperationFailed if the dragger was not initialized with a start
method.
Call this method when the mouse is being dragged. All dragger operations are done in world space
and can perform snapping (except for rotation
) if the dialog has the option enabled.
The method returns a dictionary containing the resulting values for these operations: XYZ Drag, Drag Across Floor, Drag Along Line, Drag Along Plane:
Value |
Description |
---|---|
|
A hou.Vector3 vector representing the delta mouse position related to the drag start position. |
|
A hou.Vector3 vector representing the absolute mouse position in world coordinates. |
This dictionary is returned for the Drag Rotate operation:
Value |
Description |
---|---|
|
A hou.Vector3 vector representing the delta angle in radians related to the rotation start position. |
|
A hou.Vector3 vector representing the total angle in radians related to the rotation start position. |
|
A hou.Vector3 vector representing the rotation ring absolute position related to the rotation start position. |
|
A hou.Matrix3 matrix representing the delta rotation matrix related to the |
endDrag()
Ends the current drag operation by releasing any drag cache and other settings performed by the dragger.
valid()
→ bool
Returns True if the dragger is ready to use or False otherwise. One of the dragger start
methods
must be called first to make a dragger usable.
name()
→ str
Returns the name of the dragger.
position()
→ hou.Vector3
Returns the absolute mouse position of the current drag operation. The returned value is relevant for these operations: XYZ Drag, Drag Across Floor, Drag Along Line, Drag Along Plane.
startPosition()
→ hou.Vector3
Returns the start position used for configuring the current drag operation. For the Drag Rotate operation, the returned value refers to the center of rotation.
startDirection()
→ hou.Vector3
Returns the start direction used for configuring the current drag operation.
For the Drag Rotate operation, the returned value refers to the direction vector “pointing ray” corresponding to the hou.ViewerEvent's mouse coordinates in screen space.
startRotatePosition()
→ hou.Vector3
Returns the start position on the rotation ring for the Drag Rotate operation.
enableModifierKeys(enable)
Set whether this dragger uses modifier keys to change the dragging behavior. When enabled, the Ctrl+Shift
modifier key combo will restrict the XYZ drag to 45 degree axes in screen space, and if a construction plane is active, the Shift
modifier key is used to change the distance from the dragger to the contruction plane.
See also |