Python Viewer State GeometryDrawable in OBJ context

   2020   4   1
User Avatar
Member
161 posts
Joined: May 2015
Offline
Hello everybody,

I am starting to learn about python viewer states and I am trying to use the hou.GeometryDrawable in a OBJ context but with no success. Is it possible that it is not supported in that context? I do have success with hou.SimpleDrawable, but I would like to use more advanced possibilities of hou.GeometryDrawable.

Here is the simple example that I am trying (the SimpleDrawable will display, but not the GeometryDrawable):
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

		# Drawable for drawing the polygon under the cursor.
		self.geo_drawable = hou.GeometryDrawable(self.scene_viewer,
			hou.drawableGeometryType.Face,
			"geo_drawable",
			params = {
				"style": hou.drawableGeometryFaceStyle.Plain,
				"color1": (0.0,1.0,0.0,1.0) }
		)

		self.simple_drawable = hou.SimpleDrawable(self.scene_viewer, hou.Geometry(), "simple_drawable")

	def show(self, visible):
		self.geo_drawable.show(visible)
		self.simple_drawable.show(visible)

	def onEnter(self, kwargs):
		sops = hou.sopNodeTypeCategory()
		box = sops.nodeVerb("box")
		box.setParms({"scale": 0.25})

		geo = hou.Geometry()
		temp = hou.Geometry()

		for x in (-0.5, 0.5):
			for y in (-0.5, 0.5):
				for z in (-0.5, 0.5):
					box.setParms({
						"t": hou.Vector3(x, y, z)
					})
					box.execute(temp, [])
					geo.merge(temp)

		# update the drawable
		self.geo_drawable.setGeometry(geo)
		self.simple_drawable.setGeometry(geo)
		self.simple_drawable.enable(True)

		self.show(True)

	def onResume(self, kwargs):
		self.show(True)

	def onInterrupt(self,kwargs):
		self.show(False)

	def onDraw( self, kwargs ):
		""" This callback is used for rendering the drawables
		"""
		handle = kwargs["draw_handle"]
		self.geo_drawable.draw(handle)

def createViewerStateTemplate():
	""" Mandatory entry point to create and return the viewer state
		template to register. """

	state_typename = "obj_geo_drawable"
	state_label = "obj_geo_drawable"
	state_cat = hou.objNodeTypeCategory()

	template = hou.ViewerStateTemplate(state_typename, state_label, state_cat)
	template.bindFactory(State)
	template.bindIcon("MISC_python")

	return template

Any help or info would be greatly appreciated
Thanks in advance!
User Avatar
Staff
396 posts
Joined: Feb. 2018
Offline
It's currently not possible to use a geometry drtawable in the obj context. This problem has already been logged.
User Avatar
Member
161 posts
Joined: May 2015
Offline
All right, thank you for the info @mabelzile
User Avatar
Staff
396 posts
Joined: Feb. 2018
Offline
Actually, the problem has been fixed, you should be able to use geometry drawables in the OBJ context with tomorrow's H18.5 daily build.
Edited by mabelzile - Oct. 29, 2020 12:24:05
User Avatar
Member
161 posts
Joined: May 2015
Offline
Merci @mabelzile! I tested with latest daily build and it works It does exactly what I need Thank you so much!
  • Quick Links