| On this page | |
| Inheritance |
|
概要 ¶
A hou.ViewerHandleContext stores the state associated with a running viewer handle. It contains information about the handle’s gadgets (see hou.GadgetContext) as well as the handle itself, including its parameters. Viewer handle implementations can access their context instance through the handle_context data member.
The context also manages the drawable objects used by 2D viewer handles (for example, the sidefx_transform2d handle). This allows the context to render drawables and provide picking services on them.
メソッド ¶
isParameterEnabled(parm_name)
→ bool
parm_name
指定したパラメータ名が有効ならTrueを返します。
通常では、この戻り値は、このパラメータに依存する機能を有効または無効(非表示)にするといったハンドルの実装に使用します。
scaleFactor(ref_position)
→ double
このメソッドは、ズームイン/ズームアウトした時にハンドルガジェットのスケールサイズを一定に保つのに使用できるスケール係数を返します。
通常では、scaleFactorはonDrawSetupで使用します。
ref_position
スケール係数の計算に使用される(ハンドル関連の)参照位置。 ここには、(存在すれば)ハンドルのピボット位置などのハンドル関連の位置を指定します。 これを省略した場合、参照位置は(0,0,0)です。
scaleValue()
→ double
ハンドルスケールのプリファレンス値を返します。
ハンドルスケールは、現在のビューポートサイズに比例して計算され、これを使用することで、ハンドルガジェットを好みのサイズまでスケールさせることができます。
通常では、onDrawSetupからscaleValueをコールします。
handleScaleValue(ref_position=None)
→ double
Returns the computed scaling factor for the current handle within the active Houdini viewport. Although Houdini automatically scales drawables to maintain a consistent display size across different zoom levels, this value is crucial for COP Python handle implementations. It allows for adjusting the display size of drawables, particularly to compensate for the handle’s own scaling when interactively dragging elements.
ref_position
A reference position (related to the handle) used for computing the scale value. This is likely a drawable position or any other relevant position. If omitted, the reference position is (0,0,0).
This code snippet demonstrates how to use handleScaleValue() in a COP python handle.
import hou import drawable2d as d2d MY_LINE_DRAWABLE = "line" MY_MARKER_DRAWABLE = "marker" TX = "tx" TY = "ty" def __init__(self, **kwargs): self.__dict__.update(kwargs) self._line = None self._marker = None # handle dragger self._dragger = d2d.Dragger2D(self.scene_viewer) def onActivate(self, kwargs): # Drawables creation omitted for brievity pass def onMouseEvent(self, kwargs): """ Drags a marker position and update the line point #2 with the new position. """ ui_event = kwargs["ui_event"] reason = ui_event.reason() if reason == hou.uiEventReason.Changed: # End the current drag operation on mouse up self._dragger.endDrag() return True if not self._dragger.update(kwargs, self._marker): return False drawable_name = self.handle_context.name() consumed = True if reason == hou.uiEventReason.Start: if drawable_name == MY_MARKER_DRAWABLE: self._dragger.startDrag(p1=self.handle_parms[TX], p2=self.handle_parms[TY], transform_mode=d2d.Drawable2D.TransformMode.PARAMS) elif reason in [hou.uiEventReason.Active, hou.uiEventReason.Changed]: if drawable_name == MY_MARKER_DRAWABLE: # Drag the drawable self._dragger.dragXY() # Change the drawable positions dx, dy = self._dragger.delta() delta = hou.Vector3(dx,dy,0) # Adjust the delta with the handle scaling factor handle_scale = self.handle_context.handleScaleValue(delta) delta /= handle_scale dx = delta[0] dy = delta[1] su.addToDrawablePos(self._marker, dx, dy) su.addToDrawablePoint(self._line, 1, dx, dy) return consumed ...
objectWorldTransform()
→ [Hom:hou.Matrix4]
ハンドルの親オブジェクトのワールド空間トランスフォームを返します。
objectLocalTransform()
→ [Hom:hou.Matrix4]
ハンドルの親オブジェクトのローカル空間トランスフォームを返します。
draw(draw_handle)
Render the handle’s drawables in the viewport. This method is invoked during the Python Handle’s onDraw event to draw all registered drawables.
Note
This method is currently supported only for 2D viewer handles.
draw_handle
An opaque identifier provided by Houdini for rendering. The value is
passed to the Python Handle’s onDraw callback and must be forwarded
unchanged to this draw method.
setDrawOrder(drawable_names)
Defines the draw order for the handle’s drawables. The same order is applied when picking, but iterated front to back so the visually topmost drawable is tested first.
Note
This method is currently supported only for 2D viewer handles.
drawable_names
A partial or complete list of drawable names specifying the order from back to front (the first name is drawn first, farthest back; the last name is drawn last, on top).
Any drawables not included in the list are drawn in their creation order and placed behind all listed drawables.
Methods from hou.GadgetContext ¶
name()
→ string
アクティブなDrawableの名前を返します。 Drawableは、それが選択された時、または、マウスがそのDrawable上にある(ロケートされている)時にアクティブになります。
label()
→ string
アクティブなDrawableラベル名。
gadget()
→ string
name()と同様。
gadgetLabel()
→ string
label()と同様。
component1()
→ int
アクティブなガジェットジオメトリのコンポーネントID。 このIDは、ポリゴン、ポリゴン頂点、ラインジオメトリの始点のどれかを指します。 アクティブなガジェットがなければ-1を返します。
Note
このメソッドは、hou.Drawable2Dオブジェクトには適用されません。
component2()
→ int
アクティブなガジェットジオメトリのコンポーネントID。 返されるIDは、典型的にはラインジオメトリの終点を指します。 ラインジオメトリが選択されていない場合やロケートされていない場合またはアクティブなガジェットがない場合は-1を返します。
Note
このメソッドは、hou.Drawable2Dオブジェクトには適用されません。
isDrawing()
→ bool
ハンドルが描画ステート(Drawableが選択もロケートもされていないことを意味します)の場合はTrueを返します。
isPicking()
→ bool
Drawableが選択されている場合はTrueを返します。
isLocating()
→ bool
Drawableがロケートされている場合はTrueを返します。
isLocated(drawable_name)
→ bool
指定したDrawableがロケートされている場合はTrueを返します。
drawable_name
テストするDrawableの名前。
isPicked(drawable_name)
→ bool
指定したDrawableが選択されている場合はTrueを返します。
drawable_name
テストするDrawableの名前。
| See also |