Jump to content

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

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

×