Set normals to point at camera, VEX

   7114   11   0
User Avatar
Member
339 posts
Joined: 12月 2014
Offline
I've been using expression like this:
origin(“”,“../../cam1”, “TX”)-$TX

..in a point SOP to face normals in the direction of a camera, feels a little antiquated. Any tips on how I would go about this in VEX?
User Avatar
Member
2129 posts
Joined: 9月 2015
Offline
In point wrangle:

@N = normalize(chv("path_to_camera/camera_name/t") - @P);
User Avatar
Member
339 posts
Joined: 12月 2014
Offline
Thanks!
User Avatar
Member
2129 posts
Joined: 9月 2015
Offline
Actually, my suggestion is not very good….doing something like ‘extracting’ the cameras transform is a better idea me thinks…looking into it out of curiosity since I don't normally do something like this.

Maybe someone knows…vex solution, cracktransform?
Edited by BabaJ - 2019年6月5日 19:03:10
User Avatar
Member
2129 posts
Joined: 9月 2015
Offline
I am curious about this because I want to see by being selective of only a limited number of points having normals facing the camera,

perhaps there is some kind of effects that can be utilized indirect as a result from shading.

Once I get to playing around with cracktransform I will see if that is the function needed, or perhaps another ‘extraction’ method.

In this example the target points normals are only affected by the cameras translation values, not the resulting rotation of the camera around the object; Which hopefully can be done with some ‘extracted/cracked’ transform matrix.

Attachments:
Normal Follow Camera.hiplc (114.0 KB)

User Avatar
Member
2129 posts
Joined: 9月 2015
Offline
Ok…seems optransform function was the answer…or maybe not; close, but not quite there.
Edited by BabaJ - 2019年6月5日 19:42:13

Attachments:
Normal Follow Camera v2.hiplc (114.6 KB)

User Avatar
Member
2129 posts
Joined: 9月 2015
Offline
So..as far as doing it by vex..this seems to be the simplest.

The following if put in a point wrangle will have normals point at camera.

matrix Op_Matrix;

Op_Matrix = optransform('op:../../cam1/');
@N = (Op_Matrix * (@P - @P)) - @P;

Attachments:
Normal Follow Camera v3.hiplc (111.5 KB)

User Avatar
Member
339 posts
Joined: 12月 2014
Offline
I was just revisiting this too. It works for sure, but the local rotation around the z axis isn't ideal, so I'm looking at adding an up vector to fix that. I'm new to matrix transforms but I don't imagine it's too difficult
User Avatar
Member
339 posts
Joined: 12月 2014
Offline
Ok here's what seems to work best, set @orient instead of N, (cgwiki to the rescue again here http://www.tokeru.com/cgwiki/index.php?title=HoudiniVex#Convert_N_to_Orient_with_dihedral)

vector dir = normalize(chv('../../cam1/t') - @P);
vector up = {0,1,0};

matrix3 m = maketransform(dir,up);
@orient = quaternion(m);
Edited by AndyW - 2019年6月6日 10:43:14
User Avatar
Member
2129 posts
Joined: 9月 2015
Offline
Not sure what you were attempting to begin with.

At first you were wanting normals to point towards camera. Which worked with what I gave you last.

But you said you had issue with local z axis, but from what I see, no matter what the local z axis is the normals still point at the camera.

So I thought you meant if the camera orientation changes(the normals point at the camera, but the camera doesn't point at the object). Was this the issue?

But now your showing adding an @orient, but no normals.

Care to show a hip with your intended solution? - I think I missed what you wanted.

I was thinking if it's the camera to point at the object(not just normals at camera), just do the reverse. Use a cracktransform and lookat function for the camera.
User Avatar
Member
339 posts
Joined: 12月 2014
Offline
I guess I should've been more specific in that I didn't really need to deal with normals other than that being an easy way to rotate instanced or copied geometry. without an up vector the geometry tends to rotate weirdly around it's local z axis, setting an up vector and using @orient fixes that. I've never used cracktransform, I'll have to dig into that
User Avatar
Member
157 posts
Joined: 7月 2005
Offline
BabaJ
So..as far as doing it by vex..this seems to be the simplest.

The following if put in a point wrangle will have normals point at camera.

matrix Op_Matrix;

Op_Matrix = optransform('op:../../cam1/');
@N = (Op_Matrix * (@P - @P)) - @P;

So, here we are, five years later, and I was looking for a way to project points onto a plane so their locations matched when viewed from the same perspective camera.

Added normals using your code above, then used a ray sop to project the points onto the grid.

Worked like a charm. Thank you!
Floyd Gillis
  • Quick Links