Jump to content

Viewport xform Python expression


woodenduck

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

 

 

 

Link to comment
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
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...