Houdini - Procedural Modeling Tips! - Finding Curvature

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
howdy guys handypixel here and in this video we are going to go through the process of learning how to detect curvature and more specifically curvature long road so i want to be able to find the outside and inside turn so i can place things specifically in this example i'm placing the guard rails here on the outside of the turn and these signs on the inside of the turn this is really useful because now we have a full procedural system in terms of placing these things along the appropriate part of the road so as the road changes and the curvature changes you can see that the guardrails are updating and the sign placement is updating and so really crucial procedural modeling tip to uh to learn when you're making stuff for like houdini engine and stuff like that so with that let's actually take a look at how you hook this up all right let's kick this off by dropping down a geometry node and i'm going to call this finding uh curvature like so i'm going to hit enter to dive inside and then i'm going to go and create a curve this curve will give us basically the the basis for which we want to uh find the curvature for something like you know when you're working on roads and stuff like that in houdini uh this is very very handy so just created a curve turn on grid snapping and just a really rough curve just to test this out and hit escape to get out of edit mode there i'm going to drop down a resample node and we are then going to resample this at a length of one and i'm going to set this to subdivision curves just to make it a little bit smoother so more road like like so and then i'm going to go and add my curve directions to this so if you haven't seen the uh other video about hooking up curved directions i highly recommend you watch it because i'm just going to use my preset for this i really just want to cover finding coverage in this particular video alright so i'm going to select my preset you can also pause the video and copy it from there with that done i'm going to drop down a sweep node and we are going to set this guy to um the ribbon for the server shape and i'm going to set the width to something like four and i'm going to set my columns to one now you're going to notice that the sweep node is going to produce some really wonky geometry there and that's because our curvatures aren't actually producing any proper directions and that's because in their sample node we need to go and turn on the tangent attribute and our curve u attribute i'm going to go and change the tangent attribute name to capital n and what that does is it actually produces flow normals or normals that follow the direction of the curve so currently it's really hard to see if you hit d on the keyboard we can go into the guides here and increase our normal you can see that we're getting these flow normals here you can make it even easier to see if you drop down an add note and we feed that guy in there like so and we just say delete geometry we keep the points turn on the blue display flag now you can see the normals for each one of those points there so it's pointing in the direction that the curve is flowing basically so let's get rid of this add node here and now we have uh some geometry uh to work with this is great so what i'm going to do is just pump this guy over here and we'll just say you know something like out road cool at this point now all we want to do is drop down a measure node and just take a look at you know the basics of producing curvature here so i'm gonna put in the measure node there and we're going to set this to element type of points this is very important for this particular technique here to find the curvature we're going to then set the measure to curvature and i always use the gaussian filter there and so now to view the actual results here i just hit enter with the measure node selected and you can see that we're getting red for the outside and blue for the inside so really really cool way of quickly getting curvature especially when you're working on things like roads you'll notice that we're actually getting red though at the ends here so we're gonna have to write a little bit of vexico to take care of that particular thing so let's keep moving forward now that we've got our curvature value uh we can actually start to work with that value so just so you know the attribute is called curvature and you can see if you have the geometry spreadsheet open over here that it has put that attribute onto each one of those points all right so that's what we're viewing right here so i'm going to actually hit escape over here in the scene view to get out of the edit mode for the measure note there and i want to split this up now into two curves so i'm going to use add node for that i'm going to delete geometry keep points go to by group and we'll say skip every nth point now you can also get you know the horizontal curves if you will uh if you do groups of endpoint set in this case i want to put stuff on the outsides of the road here and um yeah so i want these particular curves like so so we can now go and visualize this ourselves drop down a wrangle node i'm just going to call this curvature colors like so and we are going to go and assign our own colors to these so let's go and write a little bit of code here so i'm going to say at cd which is just the attribute for color is equal to zero so you can just set it to black by default and then i'm going to do if that curvature so we say f at curvature like so if that curvature value is greater than zero then i want to set it to red so i'm going to say at cd is equal to one zero zero or red rgb right so there you go so now you can start to see we're getting some colors now for the outside turns which is super cool so i'm just going to copy this little snippet of code here and we're going to paste this so i'm going to say if you're less than zero then we are going to be green like so all right so now we've got all of our coverage colors super cool we also do need to take care of these little end pieces here so let's do that up here here's a really slick way to do this i'm going to do so basically my goal is to find these points first now there's something very unique about these particular points let me actually comment this out up here something unique about these particular points is that they only have one neighbor right a neighbor being a neighboring point that they're connected to if you look at every other single point here has two neighbors next to it so we can actually look for that and that's what i'm going to do here so we're going to just do int num nays now that's just a variable name i'm assigning it you can call it whatever you want we want to use that neighbor count effects function there we want to get the information from the first input there or this guy right here and we want to do at pt num for the point number there you go [Music] all right so if our num nays is equal to one all right that means we only have one neighbor i'm going to just put your curvature value to zero there you go so now it's just black all right beautiful so with that done uh now i want to be able to determine like how much of the actual inside and outside curve i want to keep all right so to do this i need to cur convert this to a line or use the convert line node uh i don't need the rest length attribute i tend to turn it off just so i don't have a lot of attributes in my geometry spreadsheet you can leave it on if you want though so i'm going to do attribute promote now so we're going to then go from points to primitive so i want to take that curvature attribute from the point and put it onto the primitive that way i can then feed that into a wrangle node and remove stuff based off some rules right so i'm going to do attribute wrangle node and we're going to then go and rename this to say remove prims like so because that's exactly what i want to do in this wrangle node and then i want to go and find or i want to create a new um parameter here called min curvature so let's just create a new variable first and then do a channel float or flip channel call this min curvature as well just for the label there we go and i'm gonna hit this little button right here to actually expose it and then we're going to go over here we're going to say if the absolute value let's put that inside the parenthesis here so if the absolute value of f at curvature is less than the min curvature then we want to remove the primitive so we're going to say remove prim and zero for the first input at premnum for the prim number and one to remove all the associated points all right so now nothing is going to happen because we have our main curvature set to zero here so we just increase this slider right here we can start to remove stuff so you can see if we were to template our road piece here now we're getting just the portions where we want to start placing assets so if this were like a race track you know you'd have like bumpers on the inside and you'd have you know the guardrails or you know a fence or something like that on the outside all right cool so uh remember apparently these particular curves are still um all separated out so we need to fuse these guys back together so let's do a fuse and poly path it's a good technique right there to get your curves back into a single curve so now when i turn on the display flag you can see that we have single parameters here perfect at this point we pretty much have all the data that we need except for all of our directions so we need to go and produce all of our normal directions so we have you know the flow of the curve from the original curve that indicates the direction of the road and then also all the directions that face outwards from the road as well so we can place stuff out there all right so let's take care of that let's do um this here and what we need to do actually to do this appropriately is we need to assign the original primitive number to this so if we come all the way back up to the top here to our add node and we turn on our print numbers you can see that we have the zero and one well we need to actually record that or at least stash it somewhere so i'm going to go and drop down a wrangle node and i'm going to call this a set id and to do this i'm just going to run over the primitives and say i at id so we're going to make a new integer attribute that will live on the the points itself so you'll be able to see in the geometry spreadsheet i'm going to give it the prim and we're going to yeah leave it on the the primitives there cool so with that done and we actually need to spell this correctly supreme num there we go cool so now that we've got that on the primitives we need to promote it down to the points because it'll get destroyed when it goes through this convert line node and so we just do an attribute promote here and drop that down like so and we'll say we want to go from primitives to point and we want to transfer that or promote that id attribute so if we pump that through and go down to our last node here the split node you can see that this id is now in the points and it survived all this processing right here cool so now we can split on that so i can say if the id here is equal to zero so we're gonna say at id is equal to zero and we need to set that to points so there you go so we've got one half on one side and the other half on the other side so now we need to develop our normals the ones that are facing away from each other so i always call these the away facing normals like so and i'm going to pump that guy into there and this is actually relatively simple to do we just didn't get the position from the other side right if i were to drop down a null node over here and take a look at the point numbers over here so let's turn on our point numbers here really quick so we have 0 1 2 3 4 all the way up to 18 there and we have the same ordering of the sorting over here on the same side so that way that is why this is going to basically work because i can just grab the position from the other side so i'm going to call this other pause and this is going to be equal to point and 1 for the second incoming geometry there i want to get the p attribute the position attribute and we're going to do at pt num because the point numbers match on both sides all right and we need to make sure that we spell correctly there we go and then finally we're going to say at n is equal to normalize and we're going to normalize the vector that is created by subtracting the current position of the point from the other position so we say other pause and there you go so now we have normals that are facing outwards and if we just duplicate this by holding down alt and left clicking and dragging and then i'm going to hold down y on the keyboard to cut the wires if we just swap the inputs here we now have the opposite effect so we can just grab these two guys and then hold down alt left click and drag to create a merge node you can see now we have the normals pointing outwards like so this is really useful because then what we can do is we can use a peak node here turn off the recompute point normals and this allows us to then peak it outwards from the road so we can place stuff out there very cool all right so with that we also need to produce uh the flow normal and that's uh relatively simple as well because we actually get that value up here so this is coming in from there so if i turn on my normals you can see that we actually have the flow number up here and so really in this uh curveders let's actually put in a new vector attribute called forward so v at f wd for forward and that's equal to at n for now so i'm just stashing it on the points there and basically the reason why i did that is because now they actually survive all the way through the graph right so i have this forward vector here and we can actually visualize that so if i were to drop down a visualize node by hitting x on the keyboard we can go and visualize this guy so we can go and set the class to point and we're going to look at the forward attribute it needs to be type of marker and a vector for the style you can see that we now have our flow normal all right so we know that both sides are flowing in the same direction it's just that this is the outside turn and that's the inside turn cool so now we got all the that information all set let's just split it out into outside and inside curves there and uh to do that i'm gonna do at cd.r is uh greater than zero and set this to points and that leaves me with just the outside turn so you can drop down a null node here and we'll say outside curves and inside curves and there you go so let's just uh merge these guys together there we go and uh let's put down the color for this so it's more like road like here and we'll just do something like a dark color here and just template that by holding down control and hitting the template flag and then just hitting the display flag and now you can see if i turn off all my components here we have the inside and outside curves so that's how you find curvature really useful technique for procedure modeling i use it uh quite often so i hope you guys really enjoyed that thanks so much
Info
Channel: Indie-Pixel
Views: 4,214
Rating: 5 out of 5
Keywords: Houdini, Procedural Modeling, Houdini 18, Houdini 18.5
Id: pWewn4qGK-4
Channel Id: undefined
Length: 15min 40sec (940 seconds)
Published: Mon May 31 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.