Jump to content
noumiere

Orient of a point in a line

Recommended Posts

I have a snippet that scatters points on a grid and for each point, creates a unit vector Line comprised of two points that point at an object (in this case, a point).

Everything works fine until I add the 'orient' attribute to the system. For some reason, it treats the rotation of all points as one and the axis is at the scene center.

What I'm trying to do is have each point have it's own local rotation so that if I copy a geo to these points, they will aim at that object instead of staying upright.

I've attached the scene file

Thanks!

line_Orient_v03.hip

Share this post


Link to post
Share on other sites

Hi noumiere,

What I would do is create an orientation matrix(I'd prefer vops). If you use the vector you created pointing at your target: 
vector p = point(1, "P", 0);
v@N = normalize(p - @P);
I added it to the normal in this case.

Take the cross product of an up vector {0,1,0} and @N. And normalize it. That's our X vector.
Now do another cross product of our normal and our newly created X vector. Normalize it. That's our Z vector.
The normalized @N is our Y vector.

Add these into a "vector to matrix3". Take that result into a "matrix3 to Quaternion" and that result is our orientation. If you're using vops(like me); bind export "orient" as a vector4 attribute. Your cubes or lines should be pointing at the target while having control of their local orientation. Your line node direction might have to be changed to -1, depending on what you're after.

I can upload a hipfile later tonight if needed.

Share this post


Link to post
Share on other sites
Posted (edited)

Thanks a lot for the reply, Joachim. I have tried to implement what you said in a Point Vop and have attached it to the file. For some reason , the second point in the line does not seem to be oriented.

Do you have any idea why? Could I be that my VOPs is incorrect?

Thanks

line_Orient_v04.hip

Edited by noumiere
spelling

Share this post


Link to post
Share on other sites

Hi! Vops looks correct, the problem is that the target point you're creating doesn't really inherit the orientation. You could create the orientation again and point it back to the origin point, but that seems unnecessary. What I would do is change your approach to creating that second point. Easiest way I can think of is to not create a new point at all. Instead move the origin point along the normal @P += @N*chf("distance_mult");. And merge that moved point back with the original. You can use an "add" node to create the line between the points if necessary. And if you resample all points should point the same direction.

Share this post


Link to post
Share on other sites

Hey Joachim, your explanation made a lot of sense! I implemented your suggestions and removed the second point, instead I merged in the initial point. The issue arises with the Normals for the merged point, or maybe I'm not sure of where in the stream I should resample?

 

line_Orient_Vector.hip

Share this post


Link to post
Share on other sites
Posted (edited)

starting from: line_Orient_Vector.hip

 

you could add Attribute Transfer to the between scatter and merge to copy the normals from input2 (attributewrangle3). It works as long as the distance between the two points is less than the minimum distance of two scattered points. Otherwise you have to tie the two points together in a way, for example sharing the same value for an attribute, the resample each line. See attached file

line_Orient_Vector.fixed.hipnc

 

Also, see vex function https://www.sidefx.com/docs/houdini/vex/functions/lookat.html, which does that for you already

Edited by AntoineSfx

Share this post


Link to post
Share on other sites

Hi noumiere,

Looks like you merged the plain scattered points with the points that has the new normals. The scattered points won't really have any normal or orientation, so it won't give you the expected result. What you're after(as far as I understand it), is to have the same normal and orientation for all of your points. Which means that when we create our copy with the offset along the normal, we need those to have the same attributes.

The only things I would change with your setup is the order; after the scatter do the wrangle and pointvop. Remove the line which offsets the points: @P += @N*chf("distance_mult");.

Now create another wrangle after all these and add the offset line. This wrangle will create the copy we're after. Merge the output of this second wrangle with the output of the node before it. Now both copies of the points should have the same attributes. And finally copy to points.

The line and resample is not necessary. It only proves that the setup works properly and allows you to add as many boxes with the correct orientation as you'd like.

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

×