 Howdy guys, IndiePixel here, and in this video I wanted to show you another procedural modeling tip that really comes up quite often. I get tons and tons of questions about individuals having problems with the directions on their curves and how to use the directions in the sweep node and how to use it in the copy to points node. And so I wanted to make a whole video about just generating the curve directions that are so important when you're doing procedural modeling. And so what we're going to do in this video is we're going to go through and I'm going to show you how to produce this particular curve here that has all the proper directions for when you're using things like the sweep node or even when you're doing your own like skinning and copy to points. These are very, very important and learning how to control these particular vectors or directions inside of Houdini for your procedural models for Houdini engine or whatever you're doing inside Houdini is very crucial to producing proper procedural modeling along curves. So let's take a look. So let's dive into learning a little bit about the curve direction. So I'm going to call this new geocontainer curve directions like so we're going to jump inside by hitting enter. You can also double click. Now let's create a curve that we can work with. So we don't need to get all fancy with this or anything like that. I am actually going to go into my top view by hitting space bar two and I'm going to turn on my snapping. Now you notice that the grid numbers aren't on. I've noticed it's bug with Houdini if you just toggle in and out they come back. So I'm going to zoom back in here and let's just create some crazy curve like that. You can always go and select these points by moving around. Click on them. Then move them around. There we go. Very cool. All right. So I'm going to hit space bar one on the keyboard and hit enter again. I'm going to actually move these guys up and down a little bit here because we want to make sure that our curve directions actually follow the curve when it goes up and down like that. So I want to make proper curve directions. It's really useful when you start using the sweep node or you're using the copy to points node. It actually comes in handy so much. That's why it's a good thing to have in your toolbox. All right. So with that done, let's go and drop down a resample node, handy resample node. And I'm going to resample this to a length of one. But for every one meter or one unit here inside of Houdini, we're going to get a point along the curve. So let's actually switch this over to subdivision curve so we get something that's kind of smooth like so. All right. Very cool. All right. So to get these curve directions created, let's go and drop down an attribute wrangled node. Now you don't have to do with an attribute wrangled node. You could do it with a point bop node. I'm just more comfortable with Vex. And so you're more welcome to do it in a point bop. I might actually show that here once I finish the Vex version. So I'm going to call this guy curve dirs. And let's dive inside of our Vex code here. So the way this works is we need actually to generate a direction normal that actually follows the curve here. And to do that, it's really easy to go into the resample node here and turn on the tangent attribute and just type in capital N that stands for normal. You might not be able to see it. It's really tiny just because the curve is really big. You can make those guys bigger if you just hit D on the keyboard with your mouse over the scene view here and you can actually increase the size. You can see that we now have a normal or a vector direction or a line, if you will, that is following the direction of the curve as it turns and twists and stuff. All right. So we want to use that as our base. Okay. So the way this works is we need to create a normal that is actually flat in the y direction. So we'll try to step through this just to make it easier to understand. So I'm going to call this vector flat norm. That's what I usually call it. And this is going to be equal to the current normal. So we're just initializing it now to this current flow direction normal. And then we want to go and say flat normal dot y is equal to zero. Not flat it out. Now, we can actually go and view this here. If we were to turn this into a attribute currently, this particular variable right here is just a local variable, right? So turning it into an attribute that we can actually use, we need to put a V and then an at symbol in front of it. So it's a vector. That's what the V stands for. And the at symbol turns it into an attribute that gets then put onto the geometry spreadsheet here. So you have it here in the geometry spreadsheet. And then we can go and visualize it. If you select the attribute wrangle node and then X on the keyboard, you will create a visualize node there. And then we can go and visualize that flat norm. So I'm doing this just so you guys can see what we're doing the whole time here. And it currently exists on the point. So you need to set the class to points. The marker needs to be set, or the type needs to be set to marker. And then the style needs to be set to a vector. So you can see now we've taken our original normal that's following the curve and we've flattened it out in y. All right. So this is the first step into getting these guys working here. All right. Now that we've flattened it out, we actually need to go and normalize it. So we need to say flat norm is equal to normalize flat norm. And the reason why we're doing this is we want to keep all of our vectors in a zero to one range. And I need to go and put the at symbol in front of here because it is an attribute. Like so. There we go. All right. So now we're normalized. And we're really just doing that. So all of our vectors have a length of one. It just makes it easier when you're you're not going to incur any sort of errors or anything like that when you're doing any of the operations we're going to do here in just a second. All right. So now we've got this particular vector in place. We want to develop the right vector. So we want to develop a vector that actually points outwards from the curve. All right. And so to do that, we just say v at right. Again, we're making it an attribute so we can visualize it. And then I'm going to do the cross product of the vector. So zero, one, zero. So that's literally a vector pointing up in why here in space. All right. So it's just a standard vector pointing upwards. And then we want to put in the flat norm for this. So the cross product will give you a a vector that is perpendicular to two vectors. Right. So in this case, I'm taking the vector and this flat vector. And what it'll do is it'll give us a right vector. All right. So it'll be perpendicular. So one thing you can do in these visualized notes is you can add other visualized markers in here. And so if you hit this little duplicate button here and then in the drop down, you'll see you have a second version here. What we can do now is we can look at the right vector. So I'm going to do right. And we need to make sure we turn it on. All right. So now we have that perpendicular vector. All right. So hopefully that makes sense. We have one vector that's pointing with the direction of the curve. And then we have the up vector and we're taking the cross product of that. And that gives us this perpendicular vector towards it. So now if we look, you can see we have a nice vector that's pointing always outwards from the curve. It's very useful in many situations. All right. So then the last vector that we need is the up vector. So I'm going to say V add up is equal to the cross product. Of at n. So remember at n is our actual flow direction normal. And then we also want to do at right. So I'll give us a perpendicular vector that points perpendicular to the curve. So it'll point upwards. All right. So let's add another one of these guys. Let's go to number three here and I'm going to set this one up and make sure to set it to active. And there you go. You can color cut these two. So if you come into the marker color and just change it to green, let's go to the right and let's change this kind of red. The common colors for these guys. And let's go to the first one and let's just turn it off now. So now we've got all the vectors that we need for curves. So when you pump this into a sweep node and this just comes up, you know, so many times when I'm creating my courses and I get questions about, you know, issues with curves and stuff like that. And the sweep node, not creating a proper sweep. It's usually usually comes down to these curved directions. So you can see now our geometry is falling along very nicely. You know, the sweep node does try to to produce that type of geometry by default, but you're going to run into a lot of situations where it doesn't. And so generating these curve directions will always get you this result. It's always a good idea. So, you know, once you get this all typed out, you can come up here to this little cog wheel up here and go save preset. You can see I already have one here. Go save, save, save preset and then just call this curve underscore there. And then just say save preset and it sets it to your Houdini user pref file, which is inside of your documents, Houdini folder. All right. Hope you guys enjoyed that. So for those of you who want to see the point about node version. So let's drop down a point about node here. And let's just do the same process so you can see, you know, how you would do it without Bex, right? So we need to go and dive inside. So the first thing we have to do is we need to go and break up our normal here. So what I need to do is go and drop down a vector to float node and we're going to pump in the normal there. And then we need to do another float to vector and just pump in the X and the Z because we want our Y value to be zero. So if I were to put this into the normal now here and take a look at my normal, as you can see, we get that same results that we saw with the flat norm. Right. So that's our flat normal right there. So then all we really need to do is create a constant here. So it's to create a constant value. And this allows us to create that world up vector. So we need to set that up right here. So this guy right here is the equivalent of setting up this constant value. So we're going to go and create the vector and initialize it to zero one zero. Right. So now we have that up vector. So we need to take the cross product now. And so there's a note for that. We just take the cross product and we just want to match the Vexka that we wrote. So I'm going to pump this guy in for the first element there. And this is for the second element. So now we have our right vector. All right. So now you have the right vector here. Pretty cool. But I don't want to actually override my normals. I want to keep the original normal that we have. And so we don't really need this geometry output note. So what I'm going to do is create a new bind export. This is how you create attributes with the point Bob node. So we're going to bind export, meaning we're going to bind it to the geometry. So for every point, we're going to bind it, export it so that way we can see it in the geometry spreadsheet. And so what we need to do is set the type to a vector. And we're going to give it a name of right. And once we do that, you can see we have this vector attribute here now on each one of those points. Pretty cool. And let's go jump up now and take a look at the rest. All we need to do now is take the current normal and the right vector and do a cross product with that to create the attribute. So I'm going to dive back into the point Bob node. So there's our right vector here. There's our original normal right here. So all we really need to do is do another cross product. And we're going to do our normal for the first input here. And we're going to do our cross product with our right vector. And that becomes now our up vector. So if I pump this in, you can see now we have our vector going. All right, so not really a lot of notes, but if you prefer to do it in a visual programming way rather than with effects, that is how you would do it. All right, so last thing we really need to do here is drop down another bind, export node and bind and export this guy to the points. Call it up for the attribute name and we will then make it a vector. And at this point, I'm just going to cut that wire. We can get rid of this geometry output. No, we don't need it because we're just bind exporting right here. So that is the only output from this particular point Bob node. So if we pump in our point Bob node in our visualized node, we should get the same exact result. And so if I were to just switch between these two, we get the same result. And look at that. We're actually getting this actually proves why you should normalize your vectors. So watch as I switch these guys, the lengths of the vectors are different. And that will affect your procedural modeling. And so we need to go and actually normalize this flattened factor here. So when you drop down a normalized node and just run that through like so. There we go. So now if I switch these guys out, you don't see any difference. It is exactly the same. So that's how you do it with code. And that is how you do it with a point pop. All right, I hope you guys enjoyed that. Thanks so much. So now let's take a look at a practical example of using these curved directions. So one really great example here is a little tool I made to create roller coasters. And this makes, you know, heavy use of a curve. And so you need all the curve directions, you know, worked out, especially when you want to do things like the banking and when you want to make sure that like in this case, when I make this loop here, you want to make sure that the tracks, you know, are actually upside down. And so understanding how to create your curved directions is very important when you're doing these procedural models for Houdini engine and Houdini in general. So any sort of procedural modeling task, you're going to encounter these particular direction vectors. And so hopefully it helps to see, you know, how you could apply what you just learned throughout this video. If you're interested in more quick tips and tricks or, you know, full courses and stuff, check out my Patreon page. It's at patreon.com forward slash any pixel. Thanks so much.