Jump to content
Sign in to follow this  
woodenduck

Viewport xform Python expression

Recommended Posts

Hi, 

I have created a geo node who's world transforms are matched to those of the current viewport, using the following Python.

import toolutils 

viewer = toolutils.sceneViewer() 
viewport = viewer.curViewport() 
xform = viewport.viewTransform()

obj = hou.node("/obj").createNode("geo")

obj.setWorldTransform(xform)
 

So far so good...

Now I want to set these values with Python parameter expressions on the object so that the transforms are updated when the viewport is tumbled. The problem I'm facing is when I try to access the individual components of the xform matrix to set as the object parm I get "the Matrix4 object is not iterable"...???

Any ideas how I can dynamically link an objects transforms to those of the viewport?

Thanks for any tips, 

WD

 

 

 

Share this post


Link to post
Share on other sites

You'd need to extract translation & rotation from that matrix,

Like, for tx:

import toolutils 
viewer = toolutils.sceneViewer() 
viewport = viewer.curViewport() 
xform = viewport.viewTransform()
return xform.extractTranslates()[0]

for ry:

import toolutils 
viewer = toolutils.sceneViewer() 
viewport = viewer.curViewport() 
xform = viewport.viewTransform()
return xform.extractRotates()[1]

etc.

  • Like 1

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×