Jump to content

Python Viewport NDC Transform


Kilian

Recommended Posts

Hey,

I am currently building an HDA with python viewer states and I want to display an image/grid in the upper left corner of the viewport.

This is what I currently use to move the grid to the current viewport postion.

viewport = hou.ui.curDesktop().paneTabOfType(hou.paneTabType.SceneViewer).curViewport()
cam = viewport.viewTransform()

hou.parmTuple('/obj/geo1/transform1/t').set(cam.extractTranslates())
hou.parmTuple('/obj/geo1/transform1/r').set(cam.extractRotates())

I also transform the grid in the negative z direction afterwards.

This results in the image beeing in the center of the viewport. But I'm not sure how I can move the image to the corner of the viewport and keep it in the correct postion when the viewport is beeing resized.

Maybe with the viewport.viewportToNDCTransform() or viewport.mapToWorld() methods. But I couldnt figure out how.

 

I found a promising vex based result here:https://youtu.be/7UuVhbTRcew?t=1890

string cam = chs("camera");
vector bb = relbbox(0,@P);
vector4 crop = chp("crop");

bb.x = fit(bb.x, 0, 1, crop.x, crop.y);
bb.y = fit(bb.y, 0, 1, crop.z, crop.w);
bb.z = chf("zoffset");

@P = fromNDC(cam,bb);

But this one requires a camera node and I'd rather have this logic in the python states if possible.

Thanks

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...