Blender Geometry Nodes Tutorial - Distributing Exact Numbers of Points on Faces

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hi my name is Mike hitz from delving designs and in this blender tutorial we're going to look at how to create this node group for Distributing the exact number of points that we want onto a mesh whatever we type in here that's the number of points that we're going to see on our spreadsheet that are perfectly randomly distributed uh the difference between this and the normal distribute points on faces node if I view this is that there is a a difference between the density and the number of points that we get and sometimes whilst this can be you know you can just dial it in on times it can be quite difficult to get the exact number of points that you might want um and so that's what we're going to do by creating this node group here so let's start a new file so let's delete everything and we're going to add in a suzan monkey um to distribute our points on let's go to Geometry nodes click new and I'm going to add a rewrite node um and just contrl G to add that into a group now I can select this and with control X I can just delete it scale these up a bit and let's name our inputs so going to be points coming out and in we're going to have mesh now if we look at the distribute points on faes node and add that here what this is actually doing is saying that for every square meter of every face add this many points so you can see that like if I start scaling this up this number is not linear so if I scale it by two we go from 125 to 500 if I scale it by five we go from 120 to 3,000 so depending on the size of your mesh um this might not be very helpful and you'll want a way to control this so that's what we're going to do um as I said UND do that add that group input back in that I accidentally just deleted there we go um as I said there's a relationship between the number of faces and the size of those faces and then the number of points so what we can do is using those attributes that we know we can do some maths to figure out what the density is roughly going to be and then we can delete anyone uh any extra points afterwards so first of all we want to find out how many faces there are and if we use the domain size node mode that gives us a really nice then we can find out how many points edges or faces or face Corners that are in a mesh we can also find out how many instances we have in say collection so let's go back to mesh and we're going to want our face count we also wanted to find the area because that's what this density is working off of so we can do that with an attribute statistic node and we're going to want a float because it's going to be an area on the face domain because areas are obviously faces type in area into the attributes let's duplicate our group input and let's add a new input make this an integer and we're going to rename this as number of points points uh let's actually Tab out of our group and hook this up to our um outside group as well so we've got the value here I accidentally just deleted my geometry nodes didn't want to do that let's add geometry nodes modifier back in and add that back on there we go let's go back into our group so what we want to do is we're going to take our number of points we're going to divide by the number of faces and then we're going to divide that by the mean so the average area of the faces and if we just press contrl h we can collapse our nodes just to make this a little bit easier let's full screen our node tree for the minute let's make this a little bit more more readable there we go the next thing that we want to do for this is that so at the moment this is a no if I just put put this into my density as is at the moment and start typing in so 10 gives us 12 so that's not too bad 100 gives us 9 9,000 127 so that's not too bad 5,000 um what I am going to do though is I'm just going to add one more math node and I'm going to run it through what's called a ceiling which is just going to round it up to the nearest integer um because I want to make sure that the number of points is great currently when it's going in here is greater than the number of points that I'm trying to generate so let's just let's frame all this up with control J and we're just going to call this um density calculation the next thing that we want to do is on our group input let's add in um the selection and Seed values to our group input because we basically want this node group to replicate the distribute points on faces including the normal and rotation outputs which we're going to come to in a second so let's add these onto our group inputs so for the normal and the rotation we could just plug them straight into our group output but we're going to be doing some uh further stuff um after here which will completely mess up the indexes of these so instead what I'm going to do is actually store these as attributes on the point domain so I'm going to store them as a vector I'm going to call this one to caps lock off point normal and it's going to be the normal duplicate another one this is going to be Point rotation we can just hook these up so now what we want to do is to delete the extra vertices that have been generated so to do this you can just add delete geometry so obviously that's going to delete everything we want to take our group in inut let control h to unhide it we want to take our number of points greater than or equal to we need to flip this round and add the index so we're looking at whether or not the index so the number effectively the number of points that we currently have is greater than or equal to the number of points that we want so if it is we can just delete them so now we have the correct number you will however though start to see a problem especially when we use really big numbers um and let's actually just set the point radius so that we can maybe see this a little bit better let's subdivide it and apply that bit difficult to see on the suzan monkey um but the issue that if we go in delete this meh and maybe change it to a UV sphere we might see it a little bit better add 50,000 points so this is actually working pretty well um the issue that you might arise and it's a bit difficult to see on times with these let's add 100,000 is the say it's a bit difficult to see on here but what what can happen sometimes is that when you're deleting geometry from an index the index is are running in a sequential manner so in fact let's drop this down to say 50 here we go you can see it a bit better here that you can see there's this like slice that's being taken out and that's because our indexes if I view them here is that you know this is maybe zero this is one this is two this is three four and so on and it's going you know all the way around and up and over and because they are sequential um what's is when you're deleting them they are being deleted in a sequential order which can lead to this sort of a banding effect where you've got this slice being cut out so what we're going to do is actually Shuffle these indexes or randomize the indexes um the way that I've seen people do this previously is by using the the random value node um but that's not enti enely correct because part of the problem with it is that the random value node randomization in CG or like mathematics is never purely is never really random um and so you end up with indexes that are duplicated uh which isn't exactly what we want so what we're going to do is we're actually going to shuffle them similar to how you might shuffle a deck of cards and to do this really simple we're going to take our ometry uh in between our attributes and our delete geometry we're going to separate the geometry we're going to join the selection and the inverted back up and our selection this is now going to be a random value but it's going to be a probability so we're now taking 50% ra a random 50% of our points were split splitting them and then we're joining them back together and what that's doing is it's basically taking half of these indexes and dumping them to the bottom so if I view this on the viewer node nothing changes visually but if you look at the position data of the spreadsheet all of these positions are now getting updated so we can actually Chuck this into a group as well with contrl G let's hook this up here and rename uh inputs again it's going to be points and we're just going to add the seed to the input we can name this as Shuffle that's what I was looking for thinking Shuffle index we can now just join the like uh join these together and do a do it a couple of times just change the seed on each one and now you'll see that gets rid of that banding issue finally um let's add our Point radius onto our group inputs radius and then the final thing that we want to do is to add these attributes to the outputs so that we can access them outside of the group so off of here oh I'm just going to add a new named attribute it's going to be a vector and I'm just going to copy this name paste it here duplicate it copy the rotation and then I can hook these up to here and it might outputs I can name this one as normal and this one as rotation so let's just frame these up a little bit and make this bit more neater so this one is going to be our um distri points these are our Shuffle indices this is going to be our clamp points and then we've got our set point radius which we can leave I will leave this node tree just on the screen for a second if you do want to take a screenshot of it um to be able to replicate yourself and now if we go back out of here name our group distribute exact points we now have a node that we can append into any other project that we might be using and we can now set the exact number of points and this is isn't going to change whether we scale our mesh up scale that MH way down it's going to be the exact same number of points regardless so yeah I hope that was useful for you um if you liked this video please do give it a big thumbs up and hope to see you in the next one thanks
Info
Channel: Delving Designs
Views: 1,553
Rating: undefined out of 5
Keywords:
Id: AgFFgvUY4Dw
Channel Id: undefined
Length: 15min 52sec (952 seconds)
Published: Mon Feb 05 2024
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.