Transforming SOPs from Python shell

   2722   6   1
User Avatar
Member
47 posts
Joined: 12月 2016
Offline
Hello everyone,

I would like to be able to transform geometry inside a sop context from the python shell. A problem in doing this is that, while I can access the geometry of any sop with the sop.geometry() command, the Geometry object that this returns is read-only. I have heard it said that the only way to use python to access write-able geometry is from the Python Sop.


However, this is not ideal for me because I would like to apply 26 different transformations to a single sop, with the result being 26 new sops. I have the transformation matrices stored in an array. This array is ‘in’ the python shell. I don't want to have to create 26 new python sops then set each one's snippet to a string containing the all the code I would need to take the nth matrix and transform the geometry by it. I also don't want to create 26 transform nodes, and then extract the bits I need from each matrix and set the tx, ty, etc, parms on each node individually.

I don't want to do these things because
1) Its more work.
2) It hurts my brain to have to mash up a perfectly good transform matrix in order to feed it into some sop that is ultimately going to just reconstruct and apply the exact same transform matrix anyway. Its roundabout and physically hurts.

So I want to just apply the matrix directly to the points of the sop through the shell. I would also be fine if I could create a transform node and then just give the transform node the matrix directly. This seems like something houdini would be able to do. Is there anyway I could do this?
User Avatar
Member
1390 posts
Joined: 7月 2005
Offline
mbbuckley
(…)
So I want to just apply the matrix directly to the points of the sop through the shell. I would also be fine if I could create a transform node and then just give the transform node the matrix directly. This seems like something houdini would be able to do. Is there anyway I could do this?

You can't modify geometry outside the node which owns it. Period.

In your case, you could just multiply those 26 matrices by them self first, then create a single TransformSOP, and use hou.Matrix4.explode() [www.sidefx.com] to apply effective transformation to your geometry.
User Avatar
Member
47 posts
Joined: 12月 2016
Offline
Hey symek,

Thanks for your reply. I left an ambiguity in my description and you misunderstand me. I don't want 26 sops vertically but horizontally (not wired into each other). Still, your method makes the translation of the matrix into the transformSOP's parm values a little less painful. Would be nicer to have some kind of createTransformNodeFromMatrix() command.

However, I actually figured out an adequate way to do this.

I do use the PythonSOP and intitialize my list of matrices there. Then I make a new hou.Geometry object for each matrix. For each new hou.Geometry, I recreate all the geometry of the initial geo, and then I apply the geo.transform(matrix). Then I merge all the new geos into the initial one (thanks SideFX for the merge command).

This works for my purpose. I could probably do this with a few less lines of code once the transform() command for points is implemented.

The relevant part of my code if anyone cares:

newGeos = []
for m in matrices:
    newGeo = hou.Geometry()
    for p in geo.points():
        newp = newGeo.createPoint()
        newp.setPosition(p.position())
    newGeo.transform(m)
    newGeos.append(newGeo)
    
for g in newGeos:
    geo.merge(g)
    
User Avatar
スタッフ
747 posts
Joined: 10月 2012
Offline
If I'm understanding correctly, you could achieve this by using the Copy to Points SOP, and have 26 points in the second input with a ‘transform’ 4x4 matrix point attribute (http://www.sidefx.com/docs/houdini/copy/instanceattrs.html)
User Avatar
Member
47 posts
Joined: 12月 2016
Offline
cwhite,

Yes, I had considered transferring the transform matrix as an attribute on some carrier geometry, but that seemed like not the most elegant solution. I think it would be really cool to have some kind of python command that can just make a transform sop directly from a given matrix. Its a bit silly that doing something very fundamental in 3D graphics is not so straight forward.
User Avatar
Member
1390 posts
Joined: 7月 2005
Offline
mbbuckley
Hey symek,

Thanks for your reply. I left an ambiguity in my description and you misunderstand me.

Well, perhaps I should figure out myself that you must think of second one, more sensible option of applying 26 transformations

mbbuckley
cwhite,
Yes, I had considered transferring the transform matrix as an attribute on some carrier geometry, but that seemed like not the most elegant solution. I think it would be really cool to have some kind of python command that can just make a transform sop directly from a given matrix. Its a bit silly that doing something very fundamental in 3D graphics is not so straight forward.

Making such function is 5 lines of code. Not exactly a biggie, isn't it?

You're clearly trying to bend Houdini into programming environment, which is close to, but not exactly the same thing. Houdini tries to balance a couple of values in its design. It enables many nice features - being procedural & safe & interactive & performant at the same time. Pure programming doesn't allow that.

What cwhite proposes it is actually very elegant way in Houdini of dealing with multiply instances of a geometry with own transformation applied. It saves memory and CPU. It allows fast GPU handling of geometry and so on.

So making it more houdinish, you should create a point per geometry copy, create an 4x4 point attribute called transform and use CopyToPoints SOP to apply those you your geometry.
User Avatar
Member
47 posts
Joined: 12月 2016
Offline
Symek,

No, 5 lines of code is not a biggie. But 2 lines is better, and I am looking for the fastest possible way to do things.

You're absolutely right. I do basically think of Houdini as a programming environment. I realize its trying to also be user friendly, and safe and efficient. It must be all these things. But what I like about it is how easy it is to get low level with it.

You have a better understanding of the innards of houdini than I do, and I was not aware of the memory, cpu, and gpu advantages of cwhite's method. Perhaps that is a more elegant solution than I realized. I originally dismissed it because of having to create extra dummy geometry (no biggie, but in my mind it is a small waste) but perhaps this is something houdini is optimized for.
  • Quick Links