Jump to content
BoulderFoot

Normal Direction

Recommended Posts

Hi guys

I'm fairly new to Houdini (3 months now) coming from Maya, and I have to admit, I quite like the way Houdini thinks. The procedural method of being able to do things is amazing. I'm currently in the process of creating an oval race track procedurally, but need a little bit of help with fixing my normal direction on a curve.

I'm creating a curve from the inner edge of the oval track, and I want to use the points on that curve to place floodlights. The direction of the normals of those points would determine the direction the lights face. I'm also using a resample node to help procedurally adjust the amount of lights along the track.

As you can see, the current normal direction is the best that I can get with my limited knowledge of Houdini and VEX. I've used a Point Wrangle and inside the Point Wrangle I used the VEXpression:

v@N = normalize(v@P);

The problem I have is that the normals at for instance points B and C are not the average angle between it's neighbouring points. In my mind what I think I should be doing (and I could be wrong so your suggestions would be much appreciated) is to get the vector between points B to A, and B to C, calculate the angle between those two vectors, and divide that by 2. Is that the way to do that or is there a better/more efficient way?

Your help and feedback would be much appreciated.

Normals_Direction.jpg

Curve_Normals.hip

Share this post


Link to post
Share on other sites

In yours, the normals are being calculated by subtracting the center of the object from the point position (@N=@P - (0,0,0)). Instead, you want to attach a Polyframe node, set the Style to First Edge, uncheck Normal Name and Tangent Name, check Bitangent Name and set to N. This will calculate the tangent as you expect. That will cause unexpected results with your end points so clean those up with a wrangle with the end point numbers in the group field:

@N=normalize(@P-(0,0,0));

Since they're just vectors, you can also directly manipulate Normals in fun ways. Attached script has a simple example of the ever helpful lerp function and another one using the point function. It's a bit more involved as you'd need to loop that over an array of points to do multiple ponts. 

Hope it helps, Kevin

Normals.hiplc

 

Share this post


Link to post
Share on other sites

You can create and average direction vectors along the ellipse like this:

// POINT NEIGHBOURS
int pt_last = @numpt - 1;
int pt_next = (@ptnum + 1) % pt_last;
int pt_prev = (@ptnum != 0) ? (@ptnum - 1) : pt_last;

// DIRECTIONS
vector dir_next = normalize( @P - point(0, 'P', pt_next) );
vector dir_prev = normalize( @P - point(0, 'P', pt_prev) );
vector dir_avg  = normalize(dir_next + dir_prev);

// NORMALS
v@N = dir_avg;

avg_dirs.hipnc

Edited by konstantin magnus
  • Like 1

Share this post


Link to post
Share on other sites

Wow, it seems like for Houdini it's not a question about "IF it can be done", but "how many different ways can it be done?".

@kev2: Thanks for your suggestion. The Polyframe option seems very interesting. It almost did what I need it to do. Some of the normals it calculated halfway through the end circles (not at the end points) didn't seem to calculate the angle correctly. It is however a very cool node, glad I got to play with it.
As for the lerp function, I'll have to play with it some more but it seems like it will return the average between 2 values that it is being fed and then blend between those results depending on the last amount argument that it is supplied with.

@konstantin magnus: Thank you so much. That code is getting me 99% there! I noticed a few of the points running along the straight part of the curve tend to not have any vector showing. I am assuming it is because the angle between the previous point and the next is 180 degrees and the vector calculation doesn't know in which direction to point it in. Looking at your code I'll see if I can do a test for 180 degrees and then force the vector into one direction if that point meets the test result. And because the amount of lights being placed on this ellipse can be updated procedurally, I need to make sure I can fix those normals programmatically.

I will let you guys know what the final verdict was. Thanks again for all your help.

Share this post


Link to post
Share on other sites

tangentuPoly.thumb.png.791d4c311d47c7b94a5c8f9a3671cf70.png

 

Also, be aware that the tangent at a point of a polygon is really .. undefined, because  ... differential calculus.

So it's up to you to define what you want at the point; whether it's the average of the two limit tangents, the weighted average, the bisector, and so on

A curve is really a sequence of points which are a weighted average of the points of the hull. You can transfer the tangent of the curve obtained by building an interpolating curve on your polygon, which is basically a way of averaging the tangent over a number of points, depending on how the curve itself is built (2 choices in Resample, but you can make your own if you want), and which kernel parameters you use to transfer the tangent back (in Attribute Transfer)

Edited by AntoineSfx

Share this post


Link to post
Share on other sites

@AntoineSfx: Thanks for the tip about having to define my own tangent. I realized that it seems to be a extremely flexible thing this whole point system used in Houdini. Having used Maya for many years it's taking me some time to wrap my head around this whole point thing, but it's starting to make sense, and I realize just how powerful it is.

So I finally got this working with the help of one of the more advanced Houdini users at work. I'm still wrapping my head around it but what he did was to add a tangentu attribute to the Tangent Attribute on the Resample node. Pumped that into an Attribute Wrangle node with the following VEXpression:

v@up = {0,1,0};
v@N = cross(v@up, v@tangentu);

Voila! No more points with missing vectors, and as I increase or decrease the amount of points in the Resample node, they update correctly without any issues. I'll include my hip file here if anybody else wants to play with it.

Big thank you to everyone who pitched in with ideas/suggestions. It is much appreciated.

Race_Track.hip

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

×