On this page | |
Inheritence |
|
Overview
You can attach geometry to a viewer in a Drawable object, causing the geometry to appear in the viewer even though the geometry is not actually part of the scene. This is useful to show guide geometry in a custom Python state.
hou.SimpleDrawable
basic support is ideal for simple guide geometries. For an advanced API for creating
and drawing guide geometries, see hou.GeometryDrawable and hou.GeometryDrawableGroup.
import hou # Create an empty geometry object geo = hou.Geometry() # Get the verb from the Box node box_verb = hou.sopNodeTypeCategory().nodeVerb("box") # Set the verb's parameters box_verb.setParms({ "t": hou.Vector3(0.5, 0.5, -0.5), "scale": 0.5, }) # Execute the verb and put its output in the Geometry object box_verb.execute(geo, []) # Grab a reference to the viewer scene_viewer = hou.ui.paneTabOfType(hou.paneTabType.SceneViewer) # Create a Drawable object drawable = hou.SimpleDrawable(scene_viewer, geo, "my_guide") # Set the Drawable display mode as wireframe (this is the default) drawable.setDisplayMode(hou.drawableDisplayMode.WireframeMode) # Enable and show the drawable geometry drawable.enable(True) drawable.show(True) # Tumble the view to see the geometry
import hou # Create a geometry from the Sphere node sphere_verb = hou.sopNodeTypeCategory().nodeVerb("sphere") geo = hou.Geometry() sphere_verb.execute(geo, []) # Add color and alpha attributes to the sphere color_attrib = geo.addAttrib(hou.attribType.Prim, "Cd", (1.0, 1.0, 1.0)) alpha_attrib = geo.addAttrib(hou.attribType.Prim, "Alpha", 1.0) color = hou.Color(1.0, 0.0, 0.0) for prim in geo.prims(): prim.setAttribValue(color_attrib, color.rgb()) prim.setAttribValue(alpha_attrib, 0.7) # Create a Drawable object scene_viewer = hou.ui.paneTabOfType(hou.paneTabType.SceneViewer) drawable = hou.SimpleDrawable(scene_viewer, geo, "my_sphere") # Set the Drawable display mode with the current viewport shading mode drawable.setDisplayMode(hou.drawableDisplayMode.CurrentViewportMode) # Set the size of the sphere drawable.setTransform(hou.hmath.buildScale(0.5, 0.5, 0.5)) drawable.enable(True) drawable.show(True)
Tips and notes
-
The SimpleDrawable object keeps a reference to the Geometry object you pass. You can change the Geometry object’s contents and the next time the viewer redraws it will draw the new contents.
-
When you create the SimpleDrawable object, it is disabled and hidden. You need to call
enable(True)
and thenshow(True)
for the geometry to appear. -
Even after they are activated and shown, SimpleDrawable geometry does not appear in the viewer until the next redraw (for example, when the user changes the view).
You can force an individual viewport to redraw using hou.GeometryViewport.draw().
scene_viewer.curViewport().draw()
-
You can generate the contents of a Geometry object from scratch using verbs, or grab a copy of the output of a SOP node using hou.SopNode.geometry().
-
You can also use hou.drawablePrimitive to specify a
built-in
shape to generate the content of a SimpleDrawable object. -
enabling
/disabling
a drawable may cause performances issues if performed too often, especially with large geometries. It’s good practice to useshow
instead ofenable
for hiding and showing a drawable. -
It’s also good practice to
disable
drawables when they are not actively used in a viewer. -
Add a Vertex or Point uv attribute to the
hou.SimpleDrawable
geometry to draw in the UV view:sops = hou.sopNodeTypeCategory() verb = sops.nodeVerb("sphere") verb.setParms(parms) geo = hou.Geometry() verb.execute(geo, []) # add uv vertex attribute to the drawable. geo.addAttrib(hou.attribType.Vertex, "uv", (0,0)) # add color and alpha attributes color_attrib = geo.addAttrib(hou.attribType.Prim, "Cd", (1.0, 1.0, 1.0)) for prim in geo.prims(): prim.setAttribValue(color_attrib, StrokeCursor.COLOR.rgb()) # create a wireframe brush brush = hou.SimpleDrawable(self.scene_viewer, geo, '%s_%s' % (self.state_name, "sphere")) brush.setDisplayMode(hou.drawableDisplayMode.WireframeMode)
Methods
__init__(scene_viewer, geometry, name)
Creates a drawable object for drawing a geometry in a viewport. The new drawable is hidden and disabled by default.
scene_viewer
A hou.SceneViewer reference to the viewer the guide geometry will appear in.
geometry
Either a hou.Geometry object containing the geometry to draw, or a hou.drawablePrimitive value specifying a shape to draw.
name
A string to identify this drawable object. This should be unique across all drawables in the current session.
In a custom state, you can base the SimpleDrawable’s name on the state name to try to ensure uniqueness. For example:
class MyState(object): def __init__(self, state_name, scene_viewer): self.state_name = state_name self.scene_viewer = scene_viewer geo = hou.Geometry() verb = hou.sopNodeTypeCategory().nodeVerb("box") verb.execute(geo, []) self._box = hou.SimpleDrawable( self.scene_viewer, geo, # Use the state name as the basis for the drawable's name self.state_name + "_box" )
enable(self,value)
Enables or disables the drawing of the geometry. This method is typically called first for the show
method to take effect.
value
True
to enable or False
to disable the drawing.
enabled(self,value)
→ bool
Returns True if the drawable is enabled or not.
setDisplayMode(mode)
Sets the display mode of the geometry.
mode
A hou.drawableDisplayMode value.
displayMode()
: → hou.drawableDisplayMode
Returns the display mode of the geometry.
setXray(value)
Sets the xray rendering flag on the drawable.
value
True
to enable or False
to disable xray rendering.
isXray()
: → /hom/hou/bool
Returns True if the drawable will render with xray rendering.
setShowMaterials(value)
Enables or disables materials for the drawable. The drawable geometry must have a valid shop_materialpath attribute.
value
True
to enable or False
to disable materials.
isShowMaterials()
: → /hom/hou/bool
Returns True if the drawable is drawn with materials.
setCastShadows(value)
Enables or disables the shadow casting flag for the drawable.
value
True
to enable or False
to disable shadow casting.
isCastShadows()
: → /hom/hou/bool
Returns True if the drawable is set to cast shadows.
setWireframeColor(color)
Updates the color of the geometry when the drawable display mode is set to hou.drawableDisplayMode.WireframeMode. The change will appear the next time the viewer redraws.
color
A hou.Color value to specify the primitive color.
setGeometry(geometry)
Sets the drawable with a new geometry. The changes will appear the next time the viewer redraws.
geometry
A hou.Geometry object.
geometry()
: → hou.Geometry
Returns the drawable’s geometry object. The returned geometry is read-only
.
Methods from hou.Drawable
name()
The name of this drawable.
label()
The label of this drawable.
setLabel(label)
Set the label for this drawable.
show(value)
Displays or hides the element attached to this drawable in the viewport. The element will appear the next time the viewer redraws.
value
True
to show the element or False
to hide it.
visible()
→ bool
Returns True if the drawable is visible or not.
setTransform(xform)
Sets the transform matrix of the element attached to this drawable. The changes will appear the next time the viewer redraws.
xform
A hou.Matrix4 transformation matrix to set the element’s translation, rotation, and scale.
transform()
: → hou.Matrix4
Returns the transform matrix of the element attached to the drawable.
See also |