World coordinates of an object inside a SOP

   829   11   0
User Avatar
Member
158 posts
Joined: Nov. 2015
Offline
Hi,

There is a Python tool that will export a .jsx script with camera and null locations that I can then import into After Effects.
https://vimeo.com/186204479 [vimeo.com]

What I’m wanting to do is be able to ‘link’ the x,y,z of a null in the root OBJ level to the world position of a sphere (or point or some other object) inside a geometry SOP.

This will allow me to export the null objects into After Effects and then attach video clips of fire or other items and have the After Effects camera match my Houdini camera.

How would I get the ‘world’ position of an object inside a geometry SOP into a null object outside that geometry SOP?

Thanks,

Jim
Reel Inpsirations
Houdini Work in Progress [vimeo.com]
User Avatar
Staff
2989 posts
Joined: July 2005
Offline
make a new Shelf Tool
in the Script tab put:

# get the geo Object
geoObject = hou.selectedNodes()
geoObjectName = geoObject[0].name()
netparent = geoObject[0].parent()

# get geo and bbox center
geo = geoObject[0].displayNode().geometry()
bbox = geo.boundingBox()
center = bbox.center()

# make null
null = netparent.createNode("null", geoObjectName+"_null")
null.moveToGoodPosition()
# put null at location of center
null.parmTuple("t").set(center)
Michael Goldfarb | www.odforce.net
Senior Technical Director
SideFX
www.sidefx.com
User Avatar
Member
158 posts
Joined: Nov. 2015
Offline
Very cool.
So, let's say I create an attribute on my geometry that is unique. Maybe it is a name “fire” or even an attribute called “fire” that has a value of 1 in it.

How would I then ‘loop’ through all my geometry SOPS and create nulls for each object that has the “fire” attribute?

I'm thinking there may be more than one per SOP.

Thanks!

Jim
Reel Inpsirations
Houdini Work in Progress [vimeo.com]
User Avatar
Staff
2989 posts
Joined: July 2005
Offline
might be best to get our terms right:

there are Geometry Objects
and then there are Surface Operators and ‘geometry’ inside Geometry Objects.

so are you asking about multiple Geometry Objects that may or may not contain ‘geometry’ with an attribute called ‘fire’
or are you asking about one Geometry Object that has multiple pieces of geometry with the attribute?
Michael Goldfarb | www.odforce.net
Senior Technical Director
SideFX
www.sidefx.com
User Avatar
Member
158 posts
Joined: Nov. 2015
Offline
Both I think. Here's an example.

Attachments:
fire_nulls.hip (169.8 KB)

Reel Inpsirations
Houdini Work in Progress [vimeo.com]
User Avatar
Staff
2989 posts
Joined: July 2005
Offline
ah - so you want an Object Level null at the locations of each sphere with a fire of 1?

I'm sure it can be done - not by me a just a few minutes - let me give it a think.
Michael Goldfarb | www.odforce.net
Senior Technical Director
SideFX
www.sidefx.com
User Avatar
Member
158 posts
Joined: Nov. 2015
Offline
Yep. I need to be able to ‘import’ those null objects into After Effects for compositing.

Cinema 4D works really well with After Effects, but I have a hard time using C4D anymore now that I've gone procedural!

But I still use After Effects :-)
Reel Inpsirations
Houdini Work in Progress [vimeo.com]
User Avatar
Member
3173 posts
Joined: July 2007
Offline
select desired objects and run this perhaps?

root = hou.node("/obj")
sel = hou.selectedNodes()

subnet = root.createNode("subnet", "MyFireNulls")

for node in sel:
    if node.type().nameWithCategory() == "Object/geo":
        sop = node.displayNode() # or use .renderNode() if you want
        geo = sop.geometry()
        if geo.findPointAttrib('fire'):
            trn = node.worldTransform()
            for point in geo.points():
                fire = point.attribValue('fire')
                if fire == 1.0:
                    null = subnet.createNode('null', "Fire_%s_point%s" %( node.name(), point.number()))
                    null.parmTuple('t').set( point.position()*trn )
subnet.layoutChildren()

not considering animation
not taking into account any orientation or scale on points (like N, up, orient, rot, scale, pscale attribs)
all can be of course added
Edited by tamte - Dec. 6, 2017 21:45:19
Tomas Slancik
FX Supervisor
Method Studios, NY
User Avatar
Staff
2989 posts
Joined: July 2005
Offline
HA!
came in this morning to finish this up and you beat me to it
thanks Tomas
Michael Goldfarb | www.odforce.net
Senior Technical Director
SideFX
www.sidefx.com
User Avatar
Member
158 posts
Joined: Nov. 2015
Offline
Sweet, thanks!

Now to figure out the code and what it's doing so I can learn!

So, this line is creating a matrix 4 variable of the world coordinates of the object.
trn = node.worldTransform()

Trying to figure out what this line does.
I'm guessing it somehow ‘transforms’ the null to the world coordinates of our matrix4 variable trn by multiplying it with the current point position of the null (which should be at the origin if I'm not mistaken)
Not sure how the parmTuple works and why the ('t') parameter is there. Could not find any documentation on that.
null.parmTuple('t').set( point.position()*trn )

This should work great and Houdini is AWESOME!!!
So are the staff at SideFX for helping me with this.

Jim
Reel Inpsirations
Houdini Work in Progress [vimeo.com]
User Avatar
Member
3173 posts
Joined: July 2007
Offline
regarding this line
null.parmTuple('t').set( point.position()*trn )

- null object (like any object) has vector parameter Translate, which if you hover over you can say says tx ty tz
so as a parameter tuple its called ‘t’, with actual parameters ‘tx’ ‘ty’ ‘tz’
therefore calling null.parmTuple('t').set() will simply set the values of Translate parameter tuple on the null
- point.position() is local space position of your point within the object
- trn (or node.worldTransform()) is transform matrix holding the world space transform of the object that contains your point
- point.position()*trn transforms local space point position to the world space using objects transform
Edited by tamte - Dec. 8, 2017 13:18:47
Tomas Slancik
FX Supervisor
Method Studios, NY
User Avatar
Member
158 posts
Joined: Nov. 2015
Offline
Thanks Tomas,

That helps and makes a lot of sense.

Still learning the 3D and Houdini/Python/Vex syntax.
Coming from database/pascal/actionscript programming.

Jim
Reel Inpsirations
Houdini Work in Progress [vimeo.com]
  • Quick Links