Passing (2D) polygons from Houdini to Python

   2844   4   0
User Avatar
Member
52 posts
Joined: March 2008
Offline
Passing polygons from Python to Houdini seems doable. For 2D polygons I do this:

#make an array of points
pnts=

#create, position and assemble points
foo=bar.createPoint()
foo.setPosition(p)
pnts.appent(foo)

#then create a polygon and add a vertex per point
bar.createPolygon()
bar.addVertex(foo)


However, I am not clear on what to do in the opposite direction. I need to be able to draw an arbitrary 2D polygon in Houdini, select it in the interface and pass its identity, its vertex order and its vertex positions to Python.

Can you please direct me to the right place in the documents or propose some pseudo-code? I do not see a getPosition function and am a little lost…

Sorry if this seems lazy but these are my first steps with all of this…

Thank you.
User Avatar
Member
52 posts
Joined: March 2008
Offline
May I nudge this topic in the hope fo a reply?

The discussion here [sidefx.com] seems relevant but I am struggling to re-implement or understand. Or to find references to vert.point().position() or similar in the docs.

By the way pasting the above into the docs's search throws an exception in Firefox.

Thank you again for any guidance…
User Avatar
Member
1908 posts
Joined: Nov. 2006
Offline
I'm really not sure what it is you are trying to get at.

Accessing geometry using Python is pretty straight forward. You have a hou.Geometry object which you can then access/modify to get your prims, points, attribute values, as well as create points, surfaces, polygons, attributes and so on. Methods on hou.Point give you stuff like position, hou.Prim gives you access to vertices, etc.

That thread is a discussion about getting the position of a primitive. Since primitives don't actually have position, the position is calculated by averaging the position of a face's vertices. vert is an instance of hou.Vertex which has a method point() that gets the actual point a vertex is attached to and then using the hou.Point you can get it's position.
Graham Thompson, Technical Artist @ Rockstar Games
User Avatar
Member
52 posts
Joined: March 2008
Offline
Thanks for the reply. I did manage what I had in mind as the first step. Here is the code:


def create_one_cell(self):

sel=hou.node(“/obj/curve_object1/curve1”)
geom=sel.geometry()
num_points=len(geom.points())

for i in range(num_points):
node=self.add_node()
point=geom.iterPoints()
pos=point.position()
x=pos
y=pos
node.set_pos((x,y))

for i in range(num_points):
wall=self.add_wall(self.nodes,self.nodes)

cell=self.add_cell(self.walls)
cell.calc_principle_axes()


I have some further questions however.

As you can see I am using an explicit node name. Which works if I have the relevant file opened in Houdini. What if I were to have two files opened with the same node present? I am not quite sure how Houdini decides what to read.

I'd like to make it more robust, tidy and flexible for further work.

Before I had two python modules: the cm_core that generated my geometry and cm_houdini that passed it into Houdini. Then in Houdini I had one custom node with some minimal interface to control the behavior. This was reasonably tidy. Now that I want to be passing some data back to my core module I am not sure how to organize things best.

I was thinking of providing my custom node with an optional input and collecting the name from there. Is that a good way to do it?

I would also like to be able to select some of the generated polygons in Houdini, procedurally or manually. I would then like to pass their IDs back to Python so that I could change their behavior there. Should I be doing it with existing nodes? Then which? Or again, custom ones?

Sorry if I continue sounding vague. I am yet to get my head around the program or the terminology. But step by step…
User Avatar
Member
52 posts
Joined: March 2008
Offline
Sorry about the bad formatting of the code, the forum's input box is messing up indents and long lines…
  • Quick Links