Blender 3.0 Fields: Hexagon Grid Node

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey everybody johnny here if there's one thing i'm a sucker for it's hexagons it must be because i'm such a fan of science fiction or something but i just can't get enough of them quite a while ago i did a video about tessellating patterns and i wanted to revisit that idea and make an even more procedural grid of hexagons once i got into it i found it got a lot more complicated than i was expecting i'm going to show you the path i took through this and maybe give you some ideas about how you can do projects in geometry nodes in the future as well starting with the new geometry node tree i'm going to add a curved primitive circle and then i'm immediately going to group it i'm going to cut all the links and i'm going to start from here this way everything i do will be contained within this node group i'll go ahead and plug it into the output and we're ready to go since i'm making hexagons let's take the resolution down to six now in my old video i used an actual grid mesh to put my hexagons on but since that video came out we got the mesh grid primitive so we're going to use that instead i want a hexagon to show up on every point of this grid so to do that i'm going to use an instance on points node and plug in my hexagon as my instance these are currently too big so i'm going to shrink them down a bit some things that i'm going to want in my final node group are the number of rows and columns and the radius of my hexagons so let's go ahead and drag those to my group input vertices x which come along this way will become my columns vertices y will become my rows when i created this node group i had already gotten an entry for radius so i'll go ahead and plug that into my hexagon radius keeping our nodes well named can also help out in the future so let's change curved circle to something better with this selected i'll press f2 and name this hexagon now i know that this note is generating my hexagon coming over to my side panel i'm going to get rid of the resolution socket and move the radius down i'm going to hit tab to go out of my node and reduce the radius now we could drag the size x and y to our input and then calculate those by hand every time we want to use this node but that's not why i'm doing this so we're going to have to calculate our size x and y and with our radius and a little math we should be able to do that so for our simple hexagon we have our radius and here we have our minimal radius the minimal radius is also known as an apothem so we'll label this a generally speaking if you go to the wikipedia page for a shape like a hexagon you're going to find the formulas for things like the a value based on the r value in this case we find out that a is equal to the cosine 30 times r it goes a little something like this since a hexagon is actually six equilateral triangles this red line is also the same distance of r and each side is also the length of r so this little segment here is actually r over 2. again since this is an equilateral triangle each one of these angles is 60. and so that means this angle is 30. so since the cosine of an angle is equal to the adjacent side over the hypotenuse we can rearrange that formula to a equals cosine 30r now i'm going to squeeze my grid down just a little bit and we can see that from center point to center point of each hexagon is 2a and that the total distance from the center point to the center point which will be the points of our grid is the number of rows minus one times two a so we'll take the green line once to there and twice to there and that gets us from the bottom to the third hexagon so let's go ahead and implement what we've got now in our geometry nodes the first thing we want to calculate is this a value so let's go ahead and add cosine 30. if i add a math node i'll add a math node and choose cosine please note that the value of the trigonometric nodes are in radians not in degrees and this 30 here is 30 degrees you can calculate 30 degrees in radians by hand or if you duplicate this node and change the mode to 2 radians it converts from degrees to radians so here i'll enter 30 degrees and plug that into this so now i've plugged in 30 degrees to radians into my cosine next i want to multiply that by r so i'll put my mode to multiply bring my radius bring my cosine 30. so the output of this multiply is my a value i'm going to go ahead and grab these three nodes and group them together the input was the radius i'll connect up my output and i'll call that a and then i'll tab out of this node in addition i'm going to change the name of this node to a so now we have our a variable calculated and hidden behind this node as long as we feed it the radius it's going to give us the right value the next thing we needed was the distance from here to here that was 2 times a so we'll add a math multiply node plug in our a and change the bottom to 2. so now this represents the green line here clicking on this node and hitting f2 i'm going to call this 2a and now to get the overall height i want to multiply 2a by the rows minus one so if i duplicate this node set it to subtract bring in my y value which is my rows and subtract one i'll name this rows minus one i'll add a math node set it to multiply and put these two here and this should be my size y if i tab out of my node and change my radius my x size should stay the same but my y size should now change accordingly which it does i'm going to group these three nodes together but leave the a out of it so that i can reuse that again later and i'll name this one y size the next thing we need to worry about is moving every alternating row up before we squish them together left to right if you've watched my video on using row and column selections this next part will be familiar if i take the output of my grid node and add in a geometry set position node i can change the y offset but that changes all of the hexagons at the same time i want to select just the second row to use to do that i'm going to use the indices of the points of the grid node and do some math on them to get a selection i'll do input index then utility math and divide my index by the number of rows next i'll round this number down these two nodes have this effect the points in the first column go zero one two since i have three rows this number they become zero point three three three and point six six six when i do a floor operation on all of those they all become zero the next column becomes 1 1.3333 1.6666 and when i floor them they all become one and that continues on for each row if i take that output and use the modulo operator with a value of two for all of my even columns all of the indices will change to zero and for all of my odd columns all of the indices will be one and that's the selection i'm looking for so i'll plug that into selection here and now when i change the y you notice that only the odd number column moves if you want a much more in-depth explanation of how that works make sure to check out my video for now though i'm going to go ahead and group these together and call that my column selection we want to offset we want to offset the odd rows up the value of a so we'll add a vector combine x y z and put the a value in the y socket and then plug that into the offset that looks good so now let's get our x size if i go ahead and shrink this let's take a look at what we've got first off we have our radius in this direction and also in this direction so the distance from the center point of this hexagon to this hexagon isn't immediately clear however we can deduce it pretty quickly we know that this blue line is the value of r and we know that the bottom edge of this hexagon is also r and if we cut this from the center point that means that this is one half of r it also means that this is one half of r and because this is one half of r that means that this is also one half of r so the distance in the x axis from the center point of this hexagon to this one is three halves r because we have a half a half and a half times r and then the same way that it was with the y size the entire y size is the distance between two centers times the number of columns minus one let's jump into our nodes and do that let's take our r value and multiply it by three halves i'll do a math node multiply connect it to r and multiply it by 1.5 which is three halves then i need the number of columns minus one so i'll do subtract one and take my x vertices which is my columns and plug it in here i'll take these two values and multiply them together and then i'll plug this into my x size as you can see that tightened up the spacing on my hexagons there's now no longer any gap whatsoever if i tab out of this node now and change my x and y vertices or change my radius you see that it stays together perfectly i'll go ahead and group these three together and call this the x size now there is one more feature that i'd like to add to this and that's the ability to add a resizable gap between all of my hexagons i'll need a float input for my gap so i'll go ahead and add one here i'll tab out and set this to 0.1 now if we think about the gap in our y direction all we're really doing is leaving the hexagons the same size but increasing the overall y size since the distance between hexagons was 2a we can just add the gap in with the 2a before multiplying so if we go into our y size node we'll add an input for gap we'll plug gap into it and then go back in here we had our 2a we'll add a math node and so now we have 2a plus gap and immediately you can see that we've got a nice gap in the y direction we'll tab out and we'll go to our x size we'll add in an input for the gap and we're going to add that to where we multiplied three halves times r while i'm in this node i'm also going to clean up these input names this top one was the radius and this middle one was the columns and now i'll plug my gap into my x size node we're almost to where we need to be except let's take a closer look in here now that we've added a gap our odd columns are no longer going up high enough the center line is still even with the top of the preceding hexagon instead of between the two hexagons all that means is we need to raise them up half the distance of the gap so that they even up to here to do that i'll add a math node and set it to divide by two and bring in the gap then i'll add another math node add it to the a value and half the gap and now this is aligned in the center here i'm going to grab these three bottom nodes and group them together and call them the odd column offset now i'm just going to do a little bit of cleanup all right back out on our top level we now have full control at rows and columns change our radius and change our gap one thing to note is because we used an instance on points each one of these is a separate hexagon curve instance this isn't one giant curve if that's what you're expecting to come out of your node group you could add an instances realize instances node and now this will be one giant combined curve rather than instances now i'll just add a curved line curve to mesh and plug these in and there we go this one got a lot more complicated than i was expecting i hope you learned something along the way and i hope this inspires you to make something awesome so until next time i'll catch you later
Info
Channel: Johnny Matthews
Views: 1,303
Rating: undefined out of 5
Keywords:
Id: 8wHXxhIe-aU
Channel Id: undefined
Length: 13min 25sec (805 seconds)
Published: Thu Nov 18 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.